Determining the size of the kernel

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
deadmopo3
Posts: 4
Joined: Sat Feb 17, 2007 5:40 pm

Determining the size of the kernel

Post by deadmopo3 »

Hello,

Having been involved into OS development for almost a week now, I have finally reached the memory management part )
Parts present (thanks to the well-known tutorial) : GDT, IDT, IRQ0-1, simple shell, bootloader - GRUB.
The question is : how can I locate the start and the end of the kernel?
Linker source:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000; /* 1 mb */
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    . = ALIGN(0x1000);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(0x1000);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(0x1000);
  }
  end = .;
}
Is there a way to pass variables from linker to kernel? Would x=phys+SIZEOF(.text)+SIZEOF(.data)+SIZEOF(.bss) contain the address of the end of the kernel part?
xsix
Member
Member
Posts: 59
Joined: Tue Oct 24, 2006 10:52 am

Post by xsix »

just on the last line on kernel.asm add KERNEL_END: and after ORG add KERNEL_START, so just mov eax, KERNEL_START mov ebx, KERNEL_END and sub ebx, eax and EBX contains size of the kernel in bytes
User avatar
deadmutex
Member
Member
Posts: 85
Joined: Wed Sep 28, 2005 11:00 pm

Post by deadmutex »

the start of your kernel is at "code" and the end is at "end"

In C you would get the values like this:

Code: Select all

extern char code[];
extern char end[];
and to access them you would do something like:

Code: Select all

void *kStart = &code;
void *kEnd = &end;
In ASM you would just import "code" and "end"

EDIT: Hmm... not really sure if this will work for a binary...
deadmopo3
Posts: 4
Joined: Sat Feb 17, 2007 5:40 pm

Post by deadmopo3 »

Thanks for the replies.
Figured out how to get size: simply pushed 'end' before calling main() so that I could access it as an argument.
User avatar
os64dev
Member
Member
Posts: 553
Joined: Sat Jan 27, 2007 3:21 pm
Location: Best, Netherlands

Post by os64dev »

i hope you keep to the convention/prototype of main int main(int argc, char * argv[]), though it strictly not required it is nicer and deadmutex his method should also do the trick then again if it works it works.
Author of COBOS
Post Reply