Page 1 of 1
JamesM tutorial question
Posted: Sun Apr 13, 2008 3:53 pm
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?
Posted: Sun Apr 13, 2008 4:50 pm
by Brynet-Inc
This is the page, He describes his evil doings..
http://www.jamesmolloy.co.uk/tutorial_h ... sking.html
Look for:
9.3. Creating a new stack.
Posted: Sun Apr 13, 2008 5:43 pm
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...
Posted: Sun Apr 13, 2008 7:23 pm
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.
Posted: Mon Apr 14, 2008 1:22 am
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
)