Page 1 of 1
Real mode bare bones and the stack
Posted: Tue May 06, 2014 8:03 am
by YanivSB
Hi,
I'm new to this forum and I hope I'm posting according to the rules.
I tried finding an answer for this but couldn't see one.
In the real mode assembly bear bones:
http://wiki.osdev.org/Real_mode_assembly_bare_bones
there is a use of the call instruction, meaning it is using the stack.
However, in the original bare bones tutorial:
http://wiki.osdev.org/Bare_bones
It says that the esp points at anything and using it may cause harm. So why is it ok to use it in the first tutorial without setting it up first? Does it have something to do with GRUB being present in Bare bones?
Thanks!
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 8:12 am
by sortie
These two tutorials are fully unrelated and take place in two different environments (the real mode tutorial is basically a bootloader, while the regular bare bones tutorial is a multiboot kernel loaded by GRUB). Things are different in those two environments. You need to think critically.
It may well be a bug in the Real Mode Bare Bones tutorial that it doesn't set up its own stack pointer and trusts the BIOS to set up a stack.
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 8:23 am
by Octocontrabass
Indeed, that is a bug in the tutorial. The BIOS stack is not guaranteed to be large enough for anything but the default IRQ handlers. In particular, extended int 0x13 functions are likely to cause problems if the stack is too small.
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 10:10 am
by YanivSB
Thanks!
Just to be sure I get it - both tutorials run in real mode. The difference is that on of them runs after the BIOS, which leaves the system in a certain state, while the other runs after GRUB, which leaves the system in an other state. Both of them have no guarantee regarding the stack state. Is this correct? Say I want to find out about how the BIOS leaves the system, how will I go about it?
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 10:22 am
by Octocontrabass
GRUB leaves the CPU in protected mode, not real mode.
The BIOS is much less predictable than GRUB, but most will leave the system in real mode with a small stack set up, the drive number for int 0x13 in DL, and CS:IP pointing to either 0000:7C00 or 07C0:0000.
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 10:30 am
by sortie
Octocontrabass: The multiboot specification leaves the stack unspecified.
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 10:52 am
by Octocontrabass
Sortie: Yes, I forgot to mention that part. Proofreading is difficult from my phone.
GRUB leaves the system according to the multiboot specification. Multiboot doesn't specify how the stack should be set up, so GRUB doesn't set one up for you.
Re: Real mode bare bones and the stack
Posted: Tue May 06, 2014 11:09 am
by YanivSB
Oh, got it. Thank you all!