Page 1 of 1

End of the kernel

Posted: Thu Sep 18, 2003 11:00 pm
by SDS
At the moment I am trying to find out the address of the end of the kernel (so I can know where in memory I cannot overwrite) and I am completely baffled as to how to let the kernel know how large it is :S

I'v been trying putting symbols in a link script - but when I try and access them in the C code (as extern variables) they just read as 0, and I cannot work out how to actually access the symbols added but the linker. Can anyone give me an idea how to do this (I've been trying to work it out for a few days)

RE:End of the kernel

Posted: Thu Sep 18, 2003 11:00 pm
by Legend
I guess you want to take their address then instead of their value ...
(If it is already so, sorry, it is not clear from your post ...)

RE:End of the kernel

Posted: Thu Sep 18, 2003 11:00 pm
by SDS
I've been trying to access the value of a symbol added by the linker which is set to "." which supposedly should set it at the address at that point. I'll try accessing the address of this variable, but I don't think that will nescessarily be at the end of the kernel.....

RE:End of the kernel

Posted: Wed Sep 24, 2003 11:00 pm
by bubach
isn“t it the kernel start adress+size of kernel?
it should be easy to figure out, or am i wrong?

RE:End of the kernel

Posted: Wed Oct 01, 2003 11:00 pm
by SDS
I would have thoughgt that too ... but how does the kernel how big it is without you telling it?

RE:End of the kernel

Posted: Thu Oct 02, 2003 11:00 pm
by Chris Giese
/* defined in linker script: */
extern char g_code[]; /* start of code = start of kernel */
extern char g_end[]; /* end of BSS = end of kernel */

...

kprintf("Kernel is %u bytes\n", (unsigned)(g_end - g_code));

RE:End of the kernel

Posted: Thu Oct 02, 2003 11:00 pm
by Dangamoose
Firstly, i dont know C, only asm. Second i've already done all this so take a look at my os if necessary. download.ac-os.co.uk

Look inside start.asm, towards the end of the file and in the script.ld file.

By putting
somevariable = .;
in the linker script makes a variable at that location. It DOES NOT assign the variable to the end location. You must lea the variable and you have the end address.
Do this for the base too. Take the end from the base gives you the size of the kernel.
You also need to put the details in the linker script in the right place for it to work right. The '.' in the linker script means the current location.
variable = .; puts a variable at that current location.

If you're not totally with me, read my code.

Dangamoose.