This is the sub-category of HardWare pages about power management (shutting down, reboot, and things like that)
How do i shutdown/reboot my computer ?
there are several methods for rebooting, including
- load a 0-sized IDT and issue an interrupt (that'll triple fault and reset)
- the 'pulse RESET line from 8042 controller', which should be documented at
OsDever
void reboot()
{
volatile unsigned char good = 0x02;
while ((good & 0x02) != 0)
good = inport(0x64);
outport(0x64, 0xFE);
frz();
}
If you like extremely commented code ;-) see below on this page -- Marcio
In order to shutdown the system, you need to use the APM/ACPI (preferably calling the BIOS). There should be code for that in The Mobius.
Using INT15h (according to Tim's code which appears to be Menuet code)
- disconnect interface (ax=5304, bx=0)
- connect real mode interface (ax=5301,bx=0)
- enable power management (ax=5308, cx=bx=1)
- enable device power management(ax=530D, cx=bx=1)
- engage power management (ax=530f,cx=bx=1)
- driver version (ax=530E, bx=0, cx=102)
- set power state(ax=5307, bx=1, cx=3)
What is APM / ACPI ?
Included from APM
APM (Advanced Power Management) is a PowerManagement standard, developed by Intel and Microsoft, which allows the operating system to control the amount of power sent to devices. ACPI replaces APM as the main power management system for operating systems, mainly because SMP and APM do not mix well.
APM is mainly used by calling 32bit functions through to the BIOS, however, some BIOSes are buggy, a disadvantage of such a method, and is one of the main reasons why ACPI has succeded. However, APM is much simpler to implement in an operating system.
APM information is given in the DMI table.
Official document by Intel and Microsoft describing the APM standard.
I don't know whether the above document is 100% legal, so if someone can enlighten me.. it'd be appreciated -- DennisCgc
Included from ACPI
ACPI
ACPI (Advanced Configuration and Power Interface) is a PowerManagement and configuration standard for the PC, developed by Intel, Microsoft and Toshiba. ACPI allows the operating system to control the amount of power each device is given (allowing it to put certain devices on standby or power-off for example). It is also used to control and/or check thermal zones (temperature sensors, fan speeds, etc), battery levels, PCI IRQ routing, CPUs, NUMA domains and many other things.
Implementing ACPI
Information about ACPI is stored in the BIOS's memory (for those systems that support ACPI of course).
There are 2 main parts to ACPI. The first part is the tables used by the OS for configuration during boot (these include things like how many CPUs, APIC details, NUMA memory ranges, etc). The second part is the run time ACPI environment, which consists of AML code (a platform independant OOP language that comes from the BIOS and devices) and the ACPI SMM (System Management Mode) code.
To begin using ACPI, the operating system must look for the RSDP (Root System Description Pointer). This is covered in RSDP because it is too verbose to put here.
If the RSDP is found and the verification is valid, it contains a pointer to the RSDT (Root System Description Table) and for newer versions of ACPI (ACPI 2.0 and later) there is an additional XSDT (eXtended System Desciption Table). Both the RSDT and the XSDT contain pointers to other tables. The only real difference between the RSDT and the XSDT is that the XSDT contains 64 bit pointer instead of 32 bit pointers.
For the run time part of ACPI the main table to detect is the FADT (Fixed ACPI Description Table) as this contains information needed to enable ACPI.
Switching to ACPI Mode
On some PCs, this is already done for you if....
- the smi command field in the FADT is 0
- the ACPI enable and ACPI disable fields in the FADT are both 0
Otherwise, write the value of the ACPI Enable field into the register number pointed to by the smi command field, like so:
outb(fadt->smi_cmd,fadt->acpi_enable);
Linux waits 3 seconds for the hardware to change modes.
- Alternative code for reboot()
typedef unsigned char uchar;
typedef uchar byte;
/* keyboard interface IO port: data and control
READ: status port
WRITE: control register */
#define KBRD_INTRFC 0x64
/* keyboard interface bits */
#define KBRD_BIT_KDATA 0 /* keyboard data is in buffer (output buffer is empty) (bit 0) */
#define KBRD_BIT_UDATA 1 /* user data is in buffer (command buffer is empty) (bit 1) */
#define KBRD_IO 0x60 /* keyboard IO port */
#define KBRD_RESET 0xFE /* reset CPU command */
#define bit(n) (1<<(n)) /* Set bit n to 1 */
/* Check if bit n in flags is set */
#define check_flag(flags, n) ((flags) & bit(n))
void reboot()
{
byte temp;
asm volatile ("CLI"); /* disable all interrupts */
/* Clear all keyboard buffers (output and command buffers) */
do
{
temp = inb(KBRD_INTRFC); /* empty user data */
if (check_flag(temp, KBRD_BIT_KDATA) != 0)
inb(KBRD_IO); /* empty keyboard data */
} while (check_flag(temp, KBRD_BIT_UDATA) != 0);
outb(KBRD_INTRFC, KBRD_RESET); /* pulse CPU reset line */
asm volatile ("HLT"); /* if that didn't work, halt the CPU */
}
Those pages link to PowerManagement:

Category: