Page 1 of 1
kerel size grub
Posted: Tue Apr 27, 2010 4:21 pm
by psnix
how can i get size of kernel from grub?
i'm use multiboot and i can pass it to kernel. but i can not found any thing about kernel size in it.
Re: kerel size grub
Posted: Tue Apr 27, 2010 5:11 pm
by neon
Hello,
If loadEndAddr and loadAddr are set in your multiboot header then the size is simply the difference between them. If they are not set, you may need to have to figure it out youself: If you are using GCC with LD, you can define a start and end symbol in the linker script and use that to find the size of your kernel. Or, have the kernel parse its headers to obtain its size.
Re: kerel size grub
Posted: Wed Apr 28, 2010 12:48 am
by psnix
If you are using GCC with LD, you can define a start and end symbol in the linker script and use that to find the size of your kernel. Or, have the kernel parse its headers to obtain its size.
how can i do this?
can i use elf section of multiboot_info?
Re: kerel size grub
Posted: Wed Apr 28, 2010 1:25 am
by gerryg400
pswin,
Add something like " kernel_end = . ; " to the end of the SECTIONS parts of your linker script
Code: Select all
SECTIONS
{
OTHER SECTIONS GO HERE
kernel_end = . ;
}
Then you can then use the address of kernel_end to work out the kernel size.
- gerryg400
Re: kerel size grub
Posted: Wed Apr 28, 2010 4:06 pm
by psnix
i do this:
entry.s
Code: Select all
start:
; Load multiboot information:
push end
push start
push ebx
; Execute the kernel:
cli ; Disable interrupts.
call kmain ; call our main() function.
hlt ; halt system
and in main.c:
Code: Select all
int kmain( multiboot_info_t *mbi,size_t kstart,size_t kend)
...
printf("kernel size is: %d", kend - 0x100000);
my kenel binary size is 24kb but it retun just 20.5kb
y?
and what is wrong?
Re: kerel size grub
Posted: Wed Apr 28, 2010 4:56 pm
by NickJohnson
Part of the kernel executable is taken up by a header that describes how to load the kernel into memory, which is used by the bootloader. This header is not itself loaded, so it doesn't take up any space: this leads to a slightly (~4 KB depending) smaller in-memory kernel image than on-disk kernel image.