Page 1 of 1

End of the kernel [solved]

Posted: Sat Mar 21, 2009 4:46 pm
by Srowen
i need to know where my kernel end. I read that a good solution is to set up a symbol with the linker script.
If i understood correctly, i tell the linker to set up some memory with a symbol that i decide at the end of the kernel, so i'll search it and where i found it is the end of the kernel. This is correctly? and how can i do this? i use the follow linker script:

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(4096);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(4096);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(4096);
  }
  end = .;
}
thank's for the answers and sorry for my bad english.. i hope you understand..

Re: End of the kernel

Posted: Sat Mar 21, 2009 5:32 pm
by Wilkie
The linker script will define symbols that you can access in your application. I'm not sure what language you are using, but in C you simply use an extern to access it like you would any other externally defined symbol.

In this case, it is the symbol "end". The symbol is the value of the code there. Kinda weird, but to use the symbol:

Code: Select all

extern char end;
And then:

Code: Select all

char* endOfKernel = &end;
Links:
GNU LD Linker Script Manual

Re: End of the kernel

Posted: Sun Mar 22, 2009 4:48 am
by Srowen
thank's... perfect!

Re: End of the kernel [solved]

Posted: Sun Mar 22, 2009 8:57 pm
by leledumbo
Is char big enough to hold it? AFAIK the symbol is a pointer and you need a variable as big as native machine registers, otherwise you'll get incomplete address.

Re: End of the kernel [solved]

Posted: Sun Mar 22, 2009 11:38 pm
by JohnnyTheDon
char isn't holding the pointer. Its just the type of the pointer. Symbol addresses are always the size of the native pointer size.