41

Although I don't know this for sure, I'm pretty sure that holding the power button on all computers will force them to shutdown after varying lengths of time. This is particularly useful if the computer freezes, or some other error necessitates a total reboot.

What I'm interested in is whether this force-shutdown mechanism is hardcoded into the computers underlying firmware? Or whether this is built into the computer on a hardware level. If the mechanism was firmware, then it is logical to assume that a CPU-level error would prevent this mechanism from properly triggering, which leads me to believe this is a hardware function.

To summarise: Is the universal (I assume) force-shutdown mechanism built in at a hardware or firmware level? And can someone elaborate on the mechanisms nature, variants and general history.

  • 7
    @EJP Wrong. See my answer :) – DavidPostill Apr 2 '17 at 11:11
  • 2
    On some of the custom devices I've worked with that also have a soft power button and are battery powered (making a hard power cycle difficult for a user), we explicitly add a separate microcontroller or timer+logic circuits (or a dedicated section on an FPGA) to handle power when the firmware is sufficiently complex to allow for a hard power off if there's a firmware bug that locks it. – Jason C Apr 2 '17 at 13:42
  • 4
    Most statements with "all" are wrong. – Paŭlo Ebermann Apr 2 '17 at 17:23
  • 2
    If all else fails there is a further fully hardware backup solution involving a thick black cord at the back with a 3 pin connector, removing this will also force shutdown. – Darren H Apr 3 '17 at 7:54
  • 3
    @DarrenH not on a laptop with a non-removable battery. Flattenting the battery would work but mine has 10+ hours life (for example) – Chris H Apr 3 '17 at 8:04
45

Is the universal force-shutdown mechanism built in at a hardware or firmware level?

Both the motherboard (hardware) and the BIOS (firmware) are involved in the process.

The actual switching of the power (on and off) is done by circuits on the motherboard. The circuits are triggered to change state by a momentary short circuit of two points in the circuit. That is done by the front panel push button. A short-term connection of that button is enough. The motherboard circuit also has a second and third function it can do.

The BIOS usually is set so that, if the circuit is already on the ON state and the momentary contact is kept closed for at least 4 seconds, one of two actions will be carried out. Either the system will shut down right away (like turning off a switch), or the motherboard will enter the "sleep" state and wait to be re-awakened. Which of these two options is done is something you set in the BIOS Setup screens.**

This is the reason that the motherboard is never entirely "Off" in most operating situations. Even when it is "Off", there is a small portion of it devoted to checking for inputs from a few sources (like the front push button, some USB devices and maybe a modem) so that it can respond by turning power on to the entire system. The way to really shut down all power is either to pull out the power cord, or to use the physical switch mounted on the back of the PSU to switch it off.

Source How (does the) power button work?


The modern switches don't contain any magic. In fact, they are less complicated and expensive than real physical on/off switches.

These switches are just inputs to a micro-controller. The micro controller can tell when you push the button, and the rest is policy encoded in the firmware to decide what to do about it. The power is usually switched with transistors. This means the button itself doesn't have to handle high voltage or high current, so there are a lot more options to make it and for it to be small. It could be a membrane switch, for example, which you'd never use to switch wall power.

This does mean that a little bit of the device is usually on, at least enough to power the micro-controller. However, modern micro-controllers can take such tiny amounts of power when doing nothing but waiting for a switch signal that this power is irrelevant in most cases.

In some cases, the button actually causes the micro to get powered up when pressed, which then turns on some transistors or a relay or something to keep the power on. When you press the button to turn the device off, the micro shuts down everything, including itself.

Source How do these modern power buttons on devices work answer by Olin Lathrop

  • 1
    To clarify, is the power button handled directly by the main CPU like most BIOS code or does the firmware that handle the power button run on a microcontroller like the second part of your answer? – slebetman Apr 3 '17 at 1:30
  • 3
    I believe it's both: pressing the button generates an ACPI event for the CPU, but there's also a non-main CPU monitoring it to implement true forced shutdown if it's held down with no response from the CPU. Otherwise you could end up in a situation where interrupts are off and ACPI is disabled, and be unable to force shutdown. – pjc50 Apr 3 '17 at 9:32
6

Is the universal (I assume) force-shutdown mechanism built in at a hardware or firmware level?

Without looking for references, there is a pretty simple logic here: they must work on the hardware level because they work with no CPU in the socket.

Sure, the PC won't do all that much then, but you can still technically power it on; if your mainboard has the capability to give you messages (by beeps or a small 2-digit code) you will probably get the "bad CPU / no CPU" code. You also will be able to power it off with a long-press, which is the important part here.

Also, keep in mind that in all cases where the system is in a deeply non-sane state (i.e., in single-user mode / linux kernel panic / BSOD etc.) and for all intents and purposes at a dead end, the power button still works (at least the long-press).

Note that "hardware level" is a pretty broad term already; i.e., there could easily be anything from a few transistors up to a small dedicated µC with a few bits of NVRAM around (which would keep the values configured by the BIOS, for example on the behaviour of the short-press), which most people would still call "hardware".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.