Fariya H Disha
Fariya H Disha

Reputation: 21

How does a computer internally shut down when we click on the shut down option? Is there also something with binary system?

For example how a printer prints a page? CPU transfers binary 8 bit codes to printer than... so like this what happens with the computer internally when we start or shut down it?

Upvotes: 2

Views: 469

Answers (1)

Margaret Bloom
Margaret Bloom

Reputation: 44116

The original AT computers used the AT PSU which had only a mechanical switch to turn the power on and off:

An early microcomputer power supply was either fully on or off, controlled by the mechanical line-voltage switch, [...]. These power supplies were generally not capable of power saving modes such as standby or "soft off", or scheduled turn-on power controls.

and thus were not powered off by the software.

In the 1994 the ATX PSU become popular, such PSU introduced a pin called Power ON (henceforth PWON) that is pulled to +5V and that must be pulled down by the motherboard to activate the PSU1.

Since PWON is an electrical signal, the motherboard can implement different kinds of logic to switch the power on and off.

A front panel switch was introduced first, it was the only way to switch on/off the PC

Windows 95, Turn off screen

A "soft-off" mode was then introduced, this mode leaves some low-powered rails on for different devices to stay active and trigger a wake-up by pulling PWON down.
For example: Wake-on-LAN, Wake-on-ring, RTC alarm.

Until the introduction of APM the software could not switch off the PC in a standard way.

APM, however, has been lately superseded by ACPI which is a very complex system.

It is not hard to image what could it take to power off a PC, thanks to the PWON signal, all that is needed is to tell the chip attached to it to release it back to +5V.
There is not a standard way to do this, but the very purpose of ACPI is to overcome the differences among manufacturers.

In particular, ACPI defines that in order to power down the system, put it into state S5, the software need to perform a fixed sequence of steps.
All the information can be found in the DSDT (Differential System Descriptor Table) and the FACP (Fixed ACPI descriptor table) tables exposed by the ACPI.

The first step is invoking a method called \_S5._PTS that in my system does nothing:

Method (PTS, 1, NotSerialized)
{
    If (Arg0) {}
}

This gives the motherboard designer a chance to perform complex operations since this method is written by them.

The other step is fixed, it the actual step that turns the PC down, and it consists in writing a value into a register.
The register of interest (actually there are two, but we don't discuss it here) is PM1a_CNT, in my system is advertised as

[0ACh 0172  12]           PM1A Control Block : [Generic Address Structure]
[0ACh 0172   1]                     Space ID : 01 [SystemIO]
[0ADh 0173   1]                    Bit Width : 10
[0AEh 0174   1]                   Bit Offset : 00
[0AFh 0175   1]         Encoded Access Width : 02 [Word Access:16]
[0B0h 0176   8]                      Address : 0000000000001804

that tell us that it is located at 1804h in the IO space2.

The value to write into this register is called SLP_TYPa and it is located in the _S5 object, for my system:

Name (_S5, Package (0x04)  // _S5_: S5 System State
{
    0x07, 
    Zero, 
    Zero, 
    Zero
})

SLP_TYPa is the first number, 07h.
Before writing this number into PM1a_CNT, we need to shift it left by 10 and set its bit13, so the actual value to write is 3c00h.

To turn the power down I just need to write 3c00h to the port 1804h3:

mov ax, 3c00h
mov dx, 1804h
out dx, ax

1 You can use a paper clip to short PWON (green) to GND (black) and turn the PSU ON when not connected to a PC.
2 My system is an x86, x86s have two address spaces: IO and memory.
3 Granted ACPI is enabled (writing 0a0h to 0b2h will enable ACPI in my system).

Upvotes: 18

Related Questions