OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 16, 2024 9:01 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 8:03 am 
Offline

Joined: Tue May 06, 2014 7:56 am
Posts: 3
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!


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 8:12 am 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
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.


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 8:23 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
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.


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 10:10 am 
Offline

Joined: Tue May 06, 2014 7:56 am
Posts: 3
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?


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 10:22 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
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.


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 10:30 am 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
Octocontrabass: The multiboot specification leaves the stack unspecified.


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 10:52 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5134
Sortie: Yes, I forgot to mention that part. Proofreading is difficult from my phone. #-o

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.


Top
 Profile  
 
 Post subject: Re: Real mode bare bones and the stack
PostPosted: Tue May 06, 2014 11:09 am 
Offline

Joined: Tue May 06, 2014 7:56 am
Posts: 3
Oh, got it. Thank you all!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 33 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group