HN2new | past | comments | ask | show | jobs | submitlogin

There's a slight problem in this tutorial in that it assumes ESP (the stack pointer) will be defined by the boot loader to point to an appropriate location for the stack. However, the Multiboot standard states that ESP is undefined [1], and that the OS should set up its own stack as soon as it needs one (here the CALL instruction uses the stack, and the compiled C code may well too).

An easy way to solve this is to reserve some bytes in the .bss section of the executable for the stack by adding a new section in the assembly file:

  [section .bss align=16]
    resb 8192
    stack_end:
Then before you make use of the stack (between `cli` and `call kmain` would be appropriate in this case), you need to set the stack pointer:

  mov esp, stack_end
[1]: https://www.gnu.org/software/grub/manual/multiboot/multiboot...


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: