Page 1 of 1
How to shut down the PC in real mode if APM is not present?
Posted: Mon Jan 21, 2019 2:02 pm
by Kolodez
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!
Re: How to shut down the PC in real mode if APM is not prese
Posted: Mon Jan 21, 2019 2:40 pm
by MichaelPetch
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Mon Jan 21, 2019 3:24 pm
by Octocontrabass
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Mon Jan 21, 2019 3:58 pm
by MichaelPetch
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Tue Jan 22, 2019 1:11 pm
by nullplan
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Tue Jan 22, 2019 1:54 pm
by alexfru
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).
Re: How to shut down the PC in real mode if APM is not prese
Posted: Tue Jan 22, 2019 9:15 pm
by nullplan
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Tue Jan 22, 2019 11:14 pm
by alexfru
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.
Re: How to shut down the PC in real mode if APM is not prese
Posted: Wed Jan 23, 2019 12:47 pm
by nullplan
Re: How to shut down the PC in real mode if APM is not prese
Posted: Wed Jan 23, 2019 1:28 pm
by MichaelPetch
It better work because the entire idea of unreal mode would be rather useless without the ability to use 32-bit addressing.