Suppose I'm writing my own mbr
section and I want to run some C code where. To do so I need firstly initialize stack and after that call C code. I did that in a way like this
boot.S
file:
.code16
.section .bootstrap_stack #initializing stack here
stack_bottom:
.skip 16384
stack_top:
.text
.global _start
_start:
cli
movl $stack_top, %esp
call kmain
loop:
jmp loop
In my C code I have function kmain
.
My linker.ld
file looks like this:
OUTPUT_FORMAT(binary)
OUTPUT_ARCH(i8086)
ENTRY(_start)
SECTIONS
{
. = 0x7C00;
.text : { *(.text) }
.sig : AT(0x7DFE)
{
SHORT(0xaa55);
}
}
So the question is where in memory section .bootstrap_stack
placed? I dont tell linker script anything about it. But if I do then the size of output file is more than 512 bytes and I can't use it as mbr
. Why after this C stack works correctly?