OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Apr 19, 2024 11:34 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: BIOS Int 13/02h hangs the bootloader
PostPosted: Sun Jan 28, 2018 4:42 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 1108
PaulAche wrote:
The only thing I'm struggling with is understanding how you got the linear address range from 0x9000. If I remember correctly, I can get the linear address by SS * 16 + SP. That would make the address range start at (0h * 16h) + 9000h = 0x90000 (20-bit value). How did you get the upper range value 0x9FFFF?


If SS is 0x9000, then SS * 16 = 0x90000. Add to that SP, which is 0 through 0xFFFF.


Top
 Profile  
 
 Post subject: Re: [Solved] BIOS Int 13/02h hangs the bootloader
PostPosted: Mon Feb 05, 2018 12:24 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 692
It should also be noted (maybe I missed it) that if you set SS:SP to 0x9000:0x0000 and you do a push only the offset changes. After the first push the address of SS:SP is 0x9000;0xFFFE (0-2 = 0xFFFE). Some mistakenly believe that with PUSH the segment AND offset are changed. That isn't the case. 0x9000:0x0000-2 does not equal 0x8FFF:0x000E (physical address 0x8FFFE). This means that the stack will always wrap at 0 and end up at the top of the 64kb segment.


Top
 Profile  
 
 Post subject: Re: BIOS Int 13/02h hangs the bootloader
PostPosted: Tue Feb 06, 2018 3:13 am 
Offline
Member
Member

Joined: Wed Mar 09, 2011 3:55 am
Posts: 509
PaulAche wrote:

Your explanation makes perfect sense! The only thing I'm struggling with is understanding how you got the linear address range from 0x9000. If I remember correctly, I can get the linear address by SS * 16 + SP. That would make the address range start at (0h * 16h) + 9000h = 0x90000 (20-bit value). How did you get the upper range value 0x9FFFF?


OK, first of all, SS * 16 + SP is right, but your calculation as written doesn't follow that, you do SP * 22 + SS (but you ended up with the same answer as if you'd written the correct calculation, which means you at least did the correct calculation, but if you're thinking one thing, writing another, and doing the first thing, you're bound to confuse yourself and others).

The first mistake is that you switched SS and SP around. The next is that you used the decimal digits for 16, but postfixed it with "h", which makes it hexadecimal 0x16, which is decimal 22. You should write either "16" or "0x10" or "10h". Also, try to stay consistent with what convention you use for notating hexadecimal, you're using "0xNNNN" in some places, and "NNNNh" in others.

Anyways, the lowest value SP can have is 0, the highest it can have is 0xffff (though you'll want to keep it 16-bit aligned in 16-bit code, and 32-bit aligned in 32-bit code, so the highest you'll generally see in practice is 0xfffe). So (0x9000 * 0x10) + 0x0 = 90000 and (0x9000 * 10) + 0xffff = 9ffff.

With SP at 0x0, if you push ax (for example) to the stack, the CPU will decrement the stack pointer by two, to 0xfffe, and then write the two bytes of ax to 0xfffe and 0xffff. When you execute pop ax, it will read the bytes at 0xfffe and 0xffff into ax, then increment the stack pointer back to 0x0.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 112 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