I have followed kernel tutorials here : http://www.osdever.net/bkerndev/index.php and tutorial on memory paging/allocation here: http://www.jamesmolloy.co.uk/tutorial_h ... aging.html I have a good grasp of what is going on. But getting confused as to where *is* the real safe end of the kernel binary
And the only fix I found was by just adding roughly 1MB to it. then all works OK. I don't understand what is wrong with it.
Code: Select all
// end is defined in the linker script.
extern uint32 end asm("end");
uint32 placement_address = (uint32)&end + 0x100000; // anything less and will start crashing
Code: Select all
OUTPUT_FORMAT("elf32-i386")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
.text phys : AT(phys)
{
code = .;
*(.text)
*(.rodata)
. = ALIGN(4096);
}
.data : AT(phys + (data - code))
{
data = .;
start_ctors = .;
*(.ctor*)
end_ctors = .;
start_dtors = .;
*(.dtor*)
end_dtors = .;
*(.data)
. = ALIGN(4096);
}
.bss : AT(phys + (bss - code))
{
bss = .;
*(.bss)
. = ALIGN(4096);
}
end = .;
}
Code: Select all
; set up a stack
; first set a temporary and then call kmalloc
; to get more
mov esp, end ; place a temporary cache at the end
add esp, 0x100 ; allow 256 bytes
push 0 ; no physical address
push 0 ; no align
push 0x20000 ; allocate 128kb of stack
extern _kmalloc_int
call _kmalloc_int
mov esp, eax
add esp, 0x1FFFF ; stack grows down!
... run kmain after that