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?
JamesM tutorial question
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
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.
http://www.jamesmolloy.co.uk/tutorial_h ... sking.html
Look for: 9.3. Creating a new stack.
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...
JamesM should be ashamed of himself...
"Sufficiently advanced stupidity is indistinguishable from malice."
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.
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 )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.