OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Jun 24, 2019 5:50 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: How to shut down the PC in real mode if APM is not present?
PostPosted: Mon Jan 21, 2019 2:02 pm 
Offline

Joined: Wed Jul 27, 2016 5:37 am
Posts: 9
Hi, on my (real) PC, I boot my OS and perform the APM installation check (INT 0x15, AX=0x5300, BX=0x0), but the BIOS returns the error "APM not present" (CF set, AH=0x86). If APM v1.2 was present, I could shut down my PC from real mode by calling INT 0x15, AX=0x5307, BX=0x1, CX=0x3.

But how can I shut down the PC without APM and without using ACPI? The problem why I cannot use ACPI is that the RSDP says that the addresses of the RSDT and the XSDT are above 0x10FFEF, so I cannot access them in real mode, can I? And an answer like "you cannot shut down from real mode, you must enable protected mode first" seems very unsatisfying. Why would they make it so complicated?

Thank you for your help!


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Mon Jan 21, 2019 2:40 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 425
You can enter protected mode or you can enter unreal mode which is effectively real mode where the cache descriptors for the data segments contain a 4GiB limit rather than a 64KiB one. You can read more about that here: https://wiki.osdev.org/Unreal_Mode . After you are in unreal mode you can use 32-bit addressing modes with effective addresses greater than 64KiB.

As for why it is complicated? Probably because putting those tables in low memory would have wasted valuable space when in real mode, and it was probably anticipated that code in the future would likely be running in protected mode so it wouldn't be an issue. For those still running in real mode you simply have to jump through a hurdle to access them. By today's standards such code is relatively simple.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Mon Jan 21, 2019 3:24 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 1548
Kolodez wrote:
But how can I shut down the PC without APM and without using ACPI?

If you're lucky, there's public documentation for the chipset, and the documentation includes the procedure to shut down.

Kolodez wrote:
The problem why I cannot use ACPI is that the RSDP says that the addresses of the RSDT and the XSDT are above 0x10FFEF, so I cannot access them in real mode, can I?

Indeed you can't. Unreal mode is a possibility, but I'm not sure if there's anything funny like interactions with SMM that won't work properly.

Kolodez wrote:
And an answer like "you cannot shut down from real mode, you must enable protected mode first" seems very unsatisfying. Why would they make it so complicated?

Real mode is obsolete; it's been obsolete for at least 20 years. Requiring you to enable protected mode first is not complicated when you're already using protected mode.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Mon Jan 21, 2019 3:58 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 425
Just my personal opinion: I doubt there are any funny interactions with SMM and unreal mode. I haven't encountered such issues myself. When transitioning into SMM the segment-descriptor cache registers are saved (and later restored upon exit) along with all the more visible CPU state. If SMM hadn't been reliable enough back in 1990 it would have broken much of the code (including DOS/himem.sys) that was relying on unreal mode to work.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Tue Jan 22, 2019 1:11 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 205
Kolodez wrote:
Hi, on my (real) PC, I boot my OS and perform the APM installation check (INT 0x15, AX=0x5300, BX=0x0), but the BIOS returns the error "APM not present" (CF set, AH=0x86). If APM v1.2 was present, I could shut down my PC from real mode by calling INT 0x15, AX=0x5307, BX=0x1, CX=0x3.

But how can I shut down the PC without APM and without using ACPI? The problem why I cannot use ACPI is that the RSDP says that the addresses of the RSDT and the XSDT are above 0x10FFEF, so I cannot access them in real mode, can I? And an answer like "you cannot shut down from real mode, you must enable protected mode first" seems very unsatisfying. Why would they make it so complicated?

Thank you for your help!

I would understand your objection if it was about long mode (which requires setting up paging, which admittedly is a bit of a hurdle to overcome). But protected mode? Set up a GDT, load it, set the PM bit, long jump, done. Literally 5 instructions and 24 bytes of data. And then you can even use 32-bit assembly, which allows you to use all registers as pointer registers (16-bit mode only allows you to use BX, BP, SI, and DI, and the some of one of the former two and one of the latter two).

No, the complicated part is parsing enough of the ACPI tables to send the system into S5 state.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Tue Jan 22, 2019 1:54 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 965
nullplan wrote:
16-bit mode only allows you to use BX, BP, SI, and DI, and the some of one of the former two and one of the latter two


You can use 32-bit regs (if you have them) in 16-bit mode as long as you don't try to access anything outside segment boundaries (which you can move, which is what unreal mode is all about).


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Tue Jan 22, 2019 9:15 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 205
alexfru wrote:
You can use 32-bit regs (if you have them) in 16-bit mode as long as you don't try to access anything outside segment boundaries (which you can move, which is what unreal mode is all about).

You're missing the point. In 16-bit mode, you might be able to use EAX, but you can't use EAX as a pointer. Because the SIB byte encoding was only introduced with 32-bit mode.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Tue Jan 22, 2019 11:14 pm 
Offline
Member
Member

Joined: Tue Mar 04, 2014 5:27 am
Posts: 965
nullplan wrote:
alexfru wrote:
You can use 32-bit regs (if you have them) in 16-bit mode as long as you don't try to access anything outside segment boundaries (which you can move, which is what unreal mode is all about).

You're missing the point. In 16-bit mode, you might be able to use EAX, but you can't use EAX as a pointer. Because the SIB byte encoding was only introduced with 32-bit mode.

The address size override prefix will do.


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Wed Jan 23, 2019 12:47 pm 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 205
alexfru wrote:
The address size override prefix will do.


:shock: :shock: :shock: I just tried it out. And it works. 67h actually turns on 32-bit address decoding, with SIB byte and everything. I'm still in shock. :shock: :shock: :shock:


Top
 Profile  
 
 Post subject: Re: How to shut down the PC in real mode if APM is not prese
PostPosted: Wed Jan 23, 2019 1:28 pm 
Offline
Member
Member

Joined: Fri Aug 26, 2016 1:41 pm
Posts: 425
It better work because the entire idea of unreal mode would be rather useless without the ability to use 32-bit addressing.


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

All times are UTC - 6 hours


Who is online

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