Hello everyone. I'm back with another question. I am stuck in memory management because I can't find out how large the kernel image is, where it ends and where it begins in memory. Is it possible to find out 1) the size of the kernel dynamically, 2) the beginning address of where GRUB loads your kernel, and 3) (if not 1) where the kernel "image" ends in memory? There is a "load_end_addr" member of the multiboot header specification, but that is for the header - GRUB doesn't pass that to the kernel.
Any help would be appreciated, thanks.
What address does GRUB load my kernel to?
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Re: What address does GRUB load my kernel to?
The header that your kernel uses, is what is used by GRUB to load your kernel. So it includes the information about your kernel embedded into the header by the linker at compile time. So you should use it.
-
- Posts: 5
- Joined: Sat Apr 11, 2009 12:56 am
Re: What address does GRUB load my kernel to?
So what are safe values to use for this header? I mean, how can I find the length of my kernel? (and can this be done dynamically?) Am I supposed to choose am arbitrary number (such as 1MB) that I know for sure my kernel would fit in?salil_bhagurkar wrote:The header that your kernel uses, is what is used by GRUB to load your kernel. So it includes the information about your kernel embedded into the header by the linker at compile time. So you should use it.
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: What address does GRUB load my kernel to?
The easiest way to determine the size and location of your kernel is to define them as symbols in your linker script. For example, your linker script might look like this:
To access these symbols from your C(++) code, you can do something like this:
Code: Select all
// other stuff
. = 0x100000;
kernelStart = .;
// put your kernel sections here, i.e. code, data and bss
kernelEnd = .;
// more other stuff
Code: Select all
extern long kernelStart;
extern long kernelEnd;
printf("Kernel area: %x - %x, size: %d\n", &kernelStart, &kernelEnd, (unsigned long)&kernelEnd - (unsigned long)&kernelStart);
Re: What address does GRUB load my kernel to?
You could get some reference about linker script from following.
http://www.nacad.ufrj.br/sgi/860-0247-0 ... ripts.html
http://www.nacad.ufrj.br/sgi/860-0247-0 ... ripts.html
Re: What address does GRUB load my kernel to?
It is fairly standard to get GRUB to load your kernel at 0x100000 - 1MB.
-
- Posts: 5
- Joined: Sat Apr 11, 2009 12:56 am
Re: What address does GRUB load my kernel to?
Thank you very much!XenOS wrote:The easiest way to determine the size and location of your kernel is to define them as symbols in your linker script. For example, your linker script might look like this: