Hi Dave :-)

> I'd like to be able to detect that the power button on the computer
 > has been pressed while running freedos. (Also this would apply to the
 > powerdown event from the QEMU emulator)
> 
> I know there is a power management utility from Eric but it doesn't
 > seem to monitor for the power button.

The power button can indeed be switched between being a power button
and just generating an ACPI event. You can get the ACPI specs from
their page, but try to read only the most suitable details... ;-).

Even the ACPI 1.0 specs already were 400 pages back in 1999, now you
have the ACPI 4.0 specs here: www.acpi.info/DOWNLOADS/ACPIspec40.pdf

You can have either one or two buttons for power and sleep, see the
PWRBTN and PWR_BUTTON things... You can read out PWRBTN_STS in the
PM1 STS register and decide whether or not it creates an event via
PWRBTN_EN in the PM1 EN register. If the user presses the button,
the bit is set. If the event is enabled, a special interrupt then
is generated. Unless you have a fully ACPI operating system, this
will just tell the BIOS to do whatever you selected in BIOS / CMOS
setup: Either power off or suspend or hibernate your computer. The
latter two will only work if your BIOS has a sufficiently "deep"
understanding of how to hibernate and wake up all your hardware.

If you keep the button pressed for several seconds, you always do
get a power off in hardware. This is for the case that your ACPI
setup is messed up or your ACPI driver crashed :-).

You can do very fancy things with ACPI, in particular you can read
the DSDT to learn how the BIOS suggests you to treat all details
of your hardware power management in all situations, but of course
you could also just disable the event (PWRBTN_EN) and poll the bit
of PWRBRN_STS from time to time to detect a power button press, do
some shutdown stuff then, and use state transition as shown in the
FDAPM POWEROFF and PUREOFF to then actually switch off electricity.

Still, FDAPM takes quite some effort to flush caches etc etc but in
the end it is just that: A few I/O commands on the ACPI port, the
power supply gets a signal and switches off. The BIOS or mainboard
do not really care whether you cleanly shut down all components. Of
course it is somehow more polite if you do ;-). The I/O thing is in
principle sending the right SLP_TYP value to PM1 CNT... Three bits,
so 8 values are possible. Which is which is defined in ACPI tables,
for example in _S5 and _S4 sections. You could also try manually,
but take care to avoid states with fan off and CPU on, and do not
confuse power off with suspend to RAM ;-). A Wattmeter for your
AC socket is a good idea. Be prepared to use the override if you
get stuck in unpleasant state: Keep the button pressed to poweroff.

Your computer may also have a separate button for sleep, which can
be standby, suspend or hibernate depending on your OS and / or the
abilities of your hardware. If you do have it, it is definitely a
good target for experiments as you can play with polling the sleep
button without having to mess up the power button :-). You could
for example make a tool which just shuts down DOS and does a plain
poweroff when a sleep button press is detected. Nobody tells you
that the sleep button actually has to do anything sleep related.

I think this should help to get you started - even FDAPM does some
touching of the PWRBTN bits. While FDAPM updates the bits to make
sure that the power button does have effect, you can update them
in the opposite direction to make sure that the button only sets a
flag bit without causing actual power off itself :-).

Eric

PS: Sometimes you may want to manipulate SCI_EN to switch between
BIOS oriented and operating system oriented ACPI modes, but it is
often sufficient to leave things as they are. After all, the BIOS
does nice things for you such as throttling fans per temperature.



------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
Freedos-user mailing list
Freedos-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-user

Reply via email to