End 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
SDS

End of the kernel

Post 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)
Legend

RE:End of the kernel

Post 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 ...)
SDS

RE:End of the kernel

Post 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.....
User avatar
bubach
Member
Member
Posts: 1224
Joined: Sat Oct 23, 2004 11:00 pm
Location: Sweden
Contact:

RE:End of the kernel

Post by bubach »

isn´t it the kernel start adress+size of kernel?
it should be easy to figure out, or am i wrong?
"Simplicity is the ultimate sophistication."
http://bos.asmhackers.net/ - GitHub
SDS

RE:End of the kernel

Post by SDS »

I would have thoughgt that too ... but how does the kernel how big it is without you telling it?
Chris Giese

RE:End of the kernel

Post 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));
Dangamoose

RE:End of the kernel

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