kerel size grub

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
psnix
Member
Member
Posts: 50
Joined: Fri Oct 24, 2008 12:34 pm

kerel size grub

Post 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.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: kerel size grub

Post 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.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
psnix
Member
Member
Posts: 50
Joined: Fri Oct 24, 2008 12:34 pm

Re: kerel size grub

Post 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?
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: kerel size grub

Post 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
If a trainstation is where trains stop, what is a workstation ?
psnix
Member
Member
Posts: 50
Joined: Fri Oct 24, 2008 12:34 pm

Re: kerel size grub

Post 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?
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: kerel size grub

Post 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.
Post Reply