Page 1 of 1

Page Frame Allocation - where does my kernel reside?

Posted: Sun Oct 25, 2015 8:27 am
by miskat
I'm currently setting up page frame allocation. For that purpose i got a memory map from grub.
It gave me 2 usable chunks of memory
base 0x0 length 0x9fc00
base 0x100000 length 0x7efe000
but my kernel's code & data is inside of the second chunk.
My question is: how do i know which space is "occupied"? So how to find out how much memory my kernels code&data use?
Of course i could reserve an arbitrary amount of memory "just to be sure" but what if my kernel ever exceeds this point?
To solve this i would need a pointer to "the end" of my kernel. How to do this?

Thanks in advance. Every advice is welcome ;)

Re: Page Frame Allocation - where does my kernel reside?

Posted: Sun Oct 25, 2015 8:51 am
by iansjack
Your elf files tell you how big the various sections are, so you know how much memory the kernel uses.

Re: Page Frame Allocation - where does my kernel reside?

Posted: Sun Oct 25, 2015 9:04 am
by miskat
Thank you, i haven't thought about this.
I'll have a look inside the specification :)

Does GRUB load my ELF directly at 0x100000?

Re: Page Frame Allocation - where does my kernel reside?

Posted: Sun Oct 25, 2015 9:30 am
by kenod
For a pointer to the end of your code place

Code: Select all

endkernel = .;
at the end of the .bss section of your linker script. If you then use

Code: Select all

extern uint32_t endkernel;
uint32_t end_pointer = &endkernel
you get a pointer to the end of your kernel.
P.S.
This is explained in more detail at the wiki (http://wiki.osdev.org/Writing_A_Page_Frame_Allocator).
P.P.S.
Don't use the article for your actual allocator, it is basically a stub.

Re: Page Frame Allocation - where does my kernel reside?

Posted: Sun Oct 25, 2015 9:35 am
by miskat
Thank you. You really helped me alot!