JamesM tutorial question

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
froseph
Posts: 3
Joined: Sun Apr 13, 2008 3:05 pm

JamesM tutorial question

Post by froseph »

Reading through the JamesM tutorial found at http://www.jamesmolloy.co.uk/tutorial_h ... nesis.html. I don't seem to see where the stack is created. According to the multboot spec found here
esp is not initialized when grub transfers control over to the kernel. All of the other grub boot code I've seen sets up esp to point the beginning of the stack. Is there something that I am missing?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

This is the page, He describes his evil doings.. 8)

http://www.jamesmolloy.co.uk/tutorial_h ... sking.html

Look for: 9.3. Creating a new stack.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post by Zenith »

However, I'd recommend pointing esp to your own stack as, like the OP said, it's not 'proper' to use the stack without setting ESP to one you've set up. The method described in the tutorial just pushes the address of the stack onto the stack(??), which like the Multiboot spec says may not be safe to use. It's also easier since you yourself know the exact location of your stack.

JamesM should be ashamed of himself... 8)
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Yes -- grub loads your OS in upper memory. All of low memory is available immediately. Just set ESP to 0x80000 as soon as grub transfers control to your app, or something like that. You can later create a nice special stack buffer and move ESP to there -- but it's nice to have it properly initialized through the entire sequence of bootup.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

I, in section 9.3 wrote:Currently, we have been using an undefined stack. What does that mean? well, GRUB leaves us, stack-wise, in an undefined state. The stack pointer could be anywhere. In all practical situations, GRUB's default stack location is large enough for our startup code to run without problems. However, it is in lower memory (somewhere around 0x7000 physical), which causes us problems as it'll be 'linked' instead of 'copied' when a page directory is changed (because the area from 0x0 - approx 0x150000 is mapped in the kernel_directory). So, we really need to move the stack.
You're quite right, it is naughty. But it was done for simplicity, and the code will work under all normal circumstances (unless you try and stress test it before getting to section 9, that is ;) )
Post Reply