Page Frame Allocation - where does my kernel reside?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
miskat
Posts: 3
Joined: Sun Oct 25, 2015 8:18 am

Page Frame Allocation - where does my kernel reside?

Post 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 ;)
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

Your elf files tell you how big the various sections are, so you know how much memory the kernel uses.
miskat
Posts: 3
Joined: Sun Oct 25, 2015 8:18 am

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

Post 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?
kenod
Posts: 22
Joined: Fri Sep 25, 2015 5:30 am
Libera.chat IRC: kenod

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

Post 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.
miskat
Posts: 3
Joined: Sun Oct 25, 2015 8:18 am

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

Post by miskat »

Thank you. You really helped me alot!
Post Reply