Mixing 32bit and 16bit code (comming down into real mode)
Posted: Wed Apr 16, 2008 12:41 pm
This is a beginner question on multiple levels, so bear with me.
My goal is to use APM to properly shut down the computer. My plan was to briefly jump out of protected mode into real mode, enable the real mode APM interface, and then set the power state for all devices to off, effectively shutting down the computer.
My problem is not with the APM code, rather I am having a problem coming down into real mode. I know next to nothing about real mode (I let GRUB boot my kernel into protected mode) so it is highly possible that I'm doing everything completely wrong.
First question, will this code safely bring me down into real mode or do I need to do more?
My second question is if I need to do anything special after returning from this function, or even if I can return from it (being that all instructions after "mov cr0,eax" need to be 16bit AFAIK). As you can see, I'm really lost. Help is much appreciated.
My goal is to use APM to properly shut down the computer. My plan was to briefly jump out of protected mode into real mode, enable the real mode APM interface, and then set the power state for all devices to off, effectively shutting down the computer.
My problem is not with the APM code, rather I am having a problem coming down into real mode. I know next to nothing about real mode (I let GRUB boot my kernel into protected mode) so it is highly possible that I'm doing everything completely wrong.
First question, will this code safely bring me down into real mode or do I need to do more?
Code: Select all
enter_real_mode:
cli ;**switch to real mode**
mov eax,cr0 ;get the cr0 regester
and eax,0x7ffffffe ;disable protected mode
mov cr0,eax ;set the new cr0 regester
sti
ret