End of the kernel [solved]

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
Srowen
Member
Member
Posts: 60
Joined: Thu Feb 26, 2009 2:31 pm
Location: Genova, ITALY

End of the kernel [solved]

Post 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..
Last edited by Srowen on Sun Mar 22, 2009 4:48 am, edited 1 time in total.
User avatar
Wilkie
Member
Member
Posts: 44
Joined: Tue Aug 26, 2008 10:02 pm
Location: Land of the Dead
Contact:

Re: End of the kernel

Post 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
Srowen
Member
Member
Posts: 60
Joined: Thu Feb 26, 2009 2:31 pm
Location: Genova, ITALY

Re: End of the kernel

Post by Srowen »

thank's... perfect!
leledumbo
Member
Member
Posts: 103
Joined: Wed Apr 23, 2008 8:46 pm

Re: End of the kernel [solved]

Post 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.
JohnnyTheDon
Member
Member
Posts: 524
Joined: Sun Nov 09, 2008 2:55 am
Location: Pennsylvania, USA

Re: End of the kernel [solved]

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