Kernel binary end address
Posted: Sun Aug 24, 2008 7:45 am
I am having a bit of trouble with my mm code. And the culprit is "end" that is defined by the ld script. It does seem to point to about the right address however when I use end + 4 byte as a base for my memory management it crashes.
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.
Here is my linker scriptIn my start.asm file I allocate some space for the stack:
PS yes when I set placement_address I do take into account that there is a temporary stack at "end". it's just that nothing less than 1MB seems to work.
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