Page 1 of 1
multiboot structures
Posted: Tue Jun 15, 2004 5:57 pm
by northfuse
is there any way through the multiboot structures (I use grub) to find out the size of the kernel image? it would really help me in setting up a memory manager (so I don't write over the kernel image ;D) thanks
Re:multiboot structures
Posted: Tue Jun 15, 2004 10:27 pm
by Guest
you could do that with the use of your linker script, which is a much better way to find the kernel size at runtime.
you will have to use variables in your linker script to do this. IIRC this has been discussed here in detail sometime previously. HTH
Re:multiboot structures
Posted: Fri Jun 18, 2004 11:07 pm
by Nairou
Can you give an example? A search isn't turning up much.
Re:multiboot structures
Posted: Sat Jun 19, 2004 3:10 am
by Neuromancer
Imagine u have this linker script:
Code: Select all
ENTRY (_loader)
SECTIONS
{
. = 0x00100000;
_start = .;
.text :
{
*(.text)
*(.rodata)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss :
{
_sbss = .;
*(COMMON)
*(.bss)
_ebss = .;
}
_end = .;
}
In you code use can get the size of the kernel easily:
Code: Select all
extern void _start, _end;
unsigned int kernelGetSize(void) {
return (unsigned int)&_end - (unsigned int)&_start;
}
Remember to add the 'extern' statement to say the compiler that _start and _end are located outside this source file.
Compile your kernel with the '-T <linker script>' flag.
Re:multiboot structures
Posted: Sat Jun 19, 2004 1:07 pm
by Nairou
So does that return the size of the kernel as it exists on file, or the size of the block of memory the kernel occupies once it has been fully loaded by the bootloader?
Re:multiboot structures
Posted: Sat Jun 19, 2004 2:46 pm
by Neuromancer
It gives you the effective RAM memory used by the kernel.