Bran's Kernel Development Tutorial Known Bugs

Revision as of 06:42, 26 September 2015 by osdev>Catnikita255 (→‎Does not use Cross-Compiler: Code is not linking, but compiling fine.)

Several sources - including this Wiki - point to Bran's Kernel Development Tutorial as a starting point. This is all well, but there are some issues with that tutorial that usually make people appear on the forum and asking all the same questions again. This article is meant to preempt those questions, like a "Bran's FAQ" if you like.

As soon as I add strings, things go wrong.

The linker script from Bran's tutorial does not add the rodata sections to the binary, which is where the compiler puts static strings. Use this one instead:

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata*)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}

If you still have problems, you may need to change the output format of the nasm command in the build.bat to make an ELF file instead of a.out.

timer_wait never returns

The provided method to wait a number of timer ticks never returns because the timer_ticks variable is not defined as volatile. Changing its definition to volatile unsigned int timer_ticks = 0; will make the timer_wait() function work.

Also, instead of busy waiting, the processor could be put into sleep in order to save power. It can be done like this:

void timer_wait(int ticks)
{
    unsigned int eticks;

    eticks = timer_ticks + ticks;
    while(timer_ticks < eticks) 
    {
        __asm__ __volatile__ ("sti//hlt//cli");
    }
}

Does not use Cross-Compiler

Bran's Kernel Tutorial uses DJGPP and NASM (standard install) on windows.
To allow the code to link on a cross-compiler you must first remove all leading underscores from Global and External ASM Labels.

References