how can i shut down computer through programming.
is there some port and what should i write there.
how to shut down
Re:how to shut down
If you mean make it safe to turn off then nothing. Just make sure that all disk accesses are finished.
If you mean turn the computer off yourself, you need to program the API (IIRC). You can do this either through the BIOS but you'd have to be in real mode OR through programming it directly. Really I wouldn't recommend bothering to begin with as there are much more important things.
Pete
If you mean turn the computer off yourself, you need to program the API (IIRC). You can do this either through the BIOS but you'd have to be in real mode OR through programming it directly. Really I wouldn't recommend bothering to begin with as there are much more important things.
Pete
Re:how to shut down
One way is through APM. (Another is through ACPI, but that's a millon times more work.)
If you're using real mode, it's easy: just a few calls to INT 15h. If you're using protected mode, you'll still need to call INT 15h, which means you'll need a V86 monitor in place.
A V86 monitor, and APM poweroff code, are both demonstrated in the Mobius source code. See http://www.themobius.co.uk/sdk/.
If you're using real mode, it's easy: just a few calls to INT 15h. If you're using protected mode, you'll still need to call INT 15h, which means you'll need a V86 monitor in place.
A V86 monitor, and APM poweroff code, are both demonstrated in the Mobius source code. See http://www.themobius.co.uk/sdk/.
Re:how to shut down
AFAIK, there is no hardware standard for automatic shutdown, but there is a standard Automated Power Management (APM) BIOS which most systems built after 1997 or so support; newer systems should also support the ACPI standard, which is inculsive of but broader than the older APM system. According to RBIL, there are APM BIOS functions for 16-bit pmode and 32-bit pmode as well as for real mode, which are called through int 0x15. See here for more details.
Note that to use the 32-bit functions, you would have save the real-mode IVT before going into p-mode, extract the interrupt vector for INT 15, and use it for your own function calls (additional details on how to call the 32-bit BIOS are to be found on the relevant page in RBIL). This is not a simple matter, and tackling it too soon is sure to cause trouble. You might want to review reply #3
in this thread for more details on how nterrupts work first.
You also have to make sure that the shut down function is only called after all other system operations have been shut down. It is particularly important that nothing is being written to disk when the shutdown occurs, as that could corrupt the filesystem.
Furthermore, it helps to keep in mind that the APM functions cover not only shutdown, but also other aspects of power management such as sleep modes.
You may want to review the following threads:
Shut Down!
Reboot and Shutdown (Unfortunately, the sample code I'd attached on this thread has since been taken off the server, and my own copy was lost some time ago along with the backups. If anyone has a copy, I'd appreciate it if you could send it to me...)
Shutdown - ATX
who know about 0fh of cmos?
Shutdown PC
APCI
Where can I find APM documentation?
Also, you may want to review how it is handled in other hobbyist OSes; IIRC, Mobius has some APM support.
I haven't looked into the issues around ACPI in detail, so I may have some facts wrong. C&CW.
Note that to use the 32-bit functions, you would have save the real-mode IVT before going into p-mode, extract the interrupt vector for INT 15, and use it for your own function calls (additional details on how to call the 32-bit BIOS are to be found on the relevant page in RBIL). This is not a simple matter, and tackling it too soon is sure to cause trouble. You might want to review reply #3
in this thread for more details on how nterrupts work first.
You also have to make sure that the shut down function is only called after all other system operations have been shut down. It is particularly important that nothing is being written to disk when the shutdown occurs, as that could corrupt the filesystem.
Furthermore, it helps to keep in mind that the APM functions cover not only shutdown, but also other aspects of power management such as sleep modes.
You may want to review the following threads:
Shut Down!
Reboot and Shutdown (Unfortunately, the sample code I'd attached on this thread has since been taken off the server, and my own copy was lost some time ago along with the backups. If anyone has a copy, I'd appreciate it if you could send it to me...)
Shutdown - ATX
who know about 0fh of cmos?
Shutdown PC
APCI
Where can I find APM documentation?
Also, you may want to review how it is handled in other hobbyist OSes; IIRC, Mobius has some APM support.
I haven't looked into the issues around ACPI in detail, so I may have some facts wrong. C&CW.
Re:how to shut down
Hi,
APM would be good except AFAIK it doesn't support software control of the power button.
If you press the power button in WindowsXP it does a proper shutdown, closing down applications etc before cutting the power.
Can APM support that? Or do you require ACPI to have software control over the power button.
APM would be good except AFAIK it doesn't support software control of the power button.
If you press the power button in WindowsXP it does a proper shutdown, closing down applications etc before cutting the power.
Can APM support that? Or do you require ACPI to have software control over the power button.
Re:how to shut down
Unless I'm mistaking, the power button takes you to SMM. That code (which is usually not replaced by hobbyist OSes) runs in a realmode-like environment, and is usually used for system management things, such as shutting down etc.tom1000000 wrote: Hi,
APM would be good except AFAIK it doesn't support software control of the power button.
If you press the power button in WindowsXP it does a proper shutdown, closing down applications etc before cutting the power.
Can APM support that? Or do you require ACPI to have software control over the power button.
How you turn off the computer this way I don't know.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:how to shut down
chances are that the system polls the reason why SMM has been entered and discovers it is due to the power-off button pressed. It will then leave a message to the OS and return to normal 'protected' mode.
From then, the kernel can discover the message from SMM, and schedule everything in order to shutdown the system (just as if you launched a 'shutdown' system command).
Once everything is cleaned, you return to real/virtual mode and asks the BIOS to turn off the system's power for you ...
From then, the kernel can discover the message from SMM, and schedule everything in order to shutdown the system (just as if you launched a 'shutdown' system command).
Once everything is cleaned, you return to real/virtual mode and asks the BIOS to turn off the system's power for you ...
Re:how to shut down
k, thanks didn't think about going back to real mode...Pype.Clicker wrote: chances are that the system polls the reason why SMM has been entered and discovers it is due to the power-off button pressed. It will then leave a message to the OS and return to normal 'protected' mode.
From then, the kernel can discover the message from SMM, and schedule everything in order to shutdown the system (just as if you launched a 'shutdown' system command).
Once everything is cleaned, you return to real/virtual mode and asks the BIOS to turn off the system's power for you ...
Do you know exactly which memory regions you must backup (except for those provided by 0xE820)?