FreeDOS POWER thoughts?

Update- Eric adds:

Hi, I think you can update technote 190, telling that POWER is pretty complete now (current version only talks about lowlevel/midlevel functions existing).

Although, the UNIDLECHECK code still is not there. It would be the idea to use it to idle the CPU even when the program does not wait for keypresses, based on some heuristics and a timer tick handler - the SKETCH of the code is there, but OTHERS have to fill it with life if they want FDAPM to save even more power than in APMDOS mode (this is a call for contributions...).


Eric Auer posted this comment to the FreeDOS mailing list. It's long, but has some good APM info for those programmers interested in such things:

Hi, I remind that we wanted to improve the POWER driver, which ought to have 3 modes:

I found some useful code snippet on the LadSoft page (went there because David released a new debugger, as mentioned on FreeDOS.org: by the way, FreeDOS debug also supports 32bit code, but is generally smaller and simpler, more MS DOSish, compared to LadSofts): http://members.tripod.com/~ladsoft/dos/pwm.txt

This explains how to APM-powerdown a PC. Of course, POWER would not turn the PC off, but the general idea is similar:

Check the RBIL to know more details:

Other useful things on LadSoft:

Devices: 0 BIOS 1 all 1fff all display 2ff all disks 3ff all parports 4ff all comports 5ff all network (APM 1.1+) 6ff all PCMCIA (1.1+) ...

States: 0 on (not for device 1!?) 1 standby 2 suspend 3 off (APM 1.1+ if dev. 1) ...

Standby for example is often exited by IRQ, and to avoid nesting, you should be carefull if entering it from an IRQ. My APM, for example, is configured to wake up from most events, even soundcard IRQs, from that state. All kinds of low power / off states might return to where you called them just as if the int 15.5307... call IRETed. Especially after power off, you usually just reboot on powering on again, however.

Int 15.5308.bx=(1 means all in APM 1.1+, ffff same for APM 1.0).cx=0/1 dis/en
Disable/Enable APM: This is -imho- enough for 2 of the 3 modes of POWER already.

Int 15.530f is the corresponding disengage / engage...

In APM 1.2+ you also have a programmable resume timer (15.5311 etc.) various resume conditions and configuration, auto power off timer, calendar events, *CPU SPEED MODE* (int 15.5380.bh=0c get divider to CL and mode to BL / int 15.5380.bh=0d.cl=divider (1,2,4,8).bl=mode?) and other stuff.

Other standard calls:

Other CPU speed stuff: AMI PCI BIOS int 15.da01.cl=0/1/2 set low/high/get speed, get returns to AH, working is similar to Ctrl Alt Gray+/- ... (int 15.da92 gets CPU type / speed to AL=stepping AH=model BL=family x, as in 80x86), CX=speed in BCD MHz, only returns FSB speed it seems)

Int 16.f0.xx is Compaq 386 CPU speed set (0=6, 1=8, 2=16 MHz, 3/8/9 special). (int 16.f1 reads to AL on this boards, if AL=9, percent returned in CX) ...

Int 1f.fb.bl=0/1 get/set speed AL (0 fast 1 slow) on C&T SuperState BIOS, ...

Those are all "cpu speed" things and common APM things that a quick RBIL browsing gave to me, which you should do.

Florian Xaver adds:

Aitor Santamaria Merino apm library is avaiable at http://www.apmlib.at.tf/ (for Borlandc/TurboC, DJGPP, Pascal) now. (i deleted the seal.de.vu page, since i don't use it anymore).

It seems that Eric has since built upon Aitor's APM lib, and created a new FreeDOS POWER utility ...

Eric writes, again:

Hi all, I started writing the POWER driver which would allow FreeDOS to: Enter standby / suspend / power off mode, Reboot hot / warm / cold, Lock CPU to busy state, Enable BIOS APM, Add DOS busy-checking to help BIOS APM, Go into HLT and/or APM IDLE mode when waiting for keyboard input/..., Show APM and POWER status, like battery information.

I currently have > 1000 lines of NASM code, but the central part of "parse command line and call midlevel functions as appropriate" is missing. I provide midlevel functions like "reboot type AX" or "enter mode AX" and so on. I also have the status reporting stuff done. Basic interrupt handlers are also present.

If you do not compile with -DUNIDLECHECK, far less interrupts are hooked, and only int 16 / 28 / 2a "idle" calls are used to detect "idle" state. WITH the -D..., you enable several other int hooks which try to detect when the system is busy in DOS sense. You need this to reach A D V modes apart from MAX. Not that important if you ask me: I think most useful things are HLT / CPU idle on IDLE, without further DOS BUSY checks, and the ability to show status / reboot / power down and the like.

As I need to get some real life again (weekend!), I would be very happy if OTHER programmers could contribute code and/or check my design for flaws. If you want to compile the current version, you first have to hardcode some action calls: As said, the command line PARSER is missing, but all the midlevel "library" functions are already waiting for work :-).

http://www.coli.uni-sb.de/~eric/stuff/soft/specials/ - fdapm.zip

This project is based on APMlib by Aitor, what-gets-hooked check by me on MS POWER, reading docs of a few Windows / Linux power savers, reading lots of RBIL docs (int 15.53xx, int 2f.54xx), and other factors that I forgot to mention.