How can a computer restart itself? After it's off, how does it tell itself to come back on again? What kind of software is it that can do this?
migrated from stackoverflow.com Jun 8 '11 at 19:07
This question came from our site for professional and enthusiast programmers.
tl;dr: power states in your computer are controlled by an implementation of ACPI (advanced configuration and power interface). At the end of a shutdown process, your operating system sets an ACPI command indicating that the computer should reboot. In response, the motherboard resets all components using their respective reset commands or lines, and then follows the bootstrap process. The motherboard never actually turns off, it only resets various components and then behaves as if the power button has just been pressed.
Long and rambling but (in my opinion) more interesting answer:
Soft Power and how it works
In the olden days (well, okay, to a college student like me the '90s was a long time ago), we had AT (Advanced Technology) motherboards with AT power management. The AT power system was very, very simple. The power button on your computer was a hardware toggle (probably in the back of the case) and your 120vac input went right through it. It physically turned the power to your power supply on and off, and when this switch was in the Off position everything in your computer was completely dead (this made the CMOS battery very important, because without it there was no power supply to keep the hardware clock ticking). Because the power switch was a physical mechanism, there was no software way to turn power on and off. Windows would show the famous "It is now safe to turn off your computer" message because, although everything was parked and ready to turn off, it was not possible for the OS to actually flip the power switch. This configuration was sometimes referred to as hard power, because it's all hardware.
Nowadays things are different, because of the wonders of ATX motherboards and ATX power (that's Advanced Technology eXtended if you're keeping track). Along with a number of other advances (mini-DIN PS/2, anyone?), ATX brought soft power. Soft power means that power to the computer can be controlled by software. This brought a few import changes:
So, your power switch no longer "turns on" the computer. Instead, it's connected to your motherboard's basic controllers, which detect that the button has been pressed and execute a number of steps to ready the system, including lighting up PS_ON so that power will be available. The power button isn't the only way to trigger the startup process, devices on your expansion bus can also do so. This is important because your ethernet network adapters actually stay on when your computer is off and look for a very specific packet often referred to as the "Magic packet." If they detect this packet addressed to their MAC address, they will trigger the startup process. This is how "Wake-on-LAN" (WoL) works. The clock can also initiate a boot (most BIOS allow you to set a time that the computer should boot each day), and USB and FireWire devices can trigger a boot, although I'm not aware of any implementation of this.
Understanding Power Control
Well, I explain the Soft Power thing both because I think it's interesting (always a key reason that I explain things) and because it allows you to understand how the power and running/off state of your computer are all controlled by software. In most current computers, this software system is an implementation of the Advanced Configuration and Power Interface, or ACPI. ACPI is a standardized, unified system allowing software to control your computer's power system. You may have heard of the ACPI power states. The basic mechanism of power control is these "power states", your operating system switches through power modes by preparing for the switch (the shutdown/hibernate processes that occur prior to power actually flipping off), and then commanding the motherboard to switch power states. The power states look like this:
How reset actually happens
You'll notice that reboot is not one of these states. So what actually happens when your computer when it reboots? The answer may be surprising, because from a power management perspective it's almost nothing. There is an ACPI reset command. When you tell your operating system to reboot, it follows its normal shutdown process (stops all your processes, performs a bit of maintenance, dismounts your file systems, etc), and then as a final step, instead of sending the machine to power state G2 (as it would if you had simply told it to Shut Down) it sets the Reset command. This is generally referred to as the "Reset register", because like most of the ACPI interface it's just an address that a specific value should be written to in order to request a reset. I'll quote the 2.0 specification on what it does:
So, when the reset register is set, a few things happen in sequence.
The end effect of these two steps (which actually break down in to a lot more steps) is that it looks to everything just like the computer just booted, but the power was actually on the whole time. This means less time required to shut down and start up (since you don't have to wait for the power supply to become ready), and importantly allows the bootup to be initiated by the operating system shutting down. This means that another startup trigger doesn't need to be used (WoL etc), and allows you to use Reboot as an effective way to reset the system remotely, when you don't have a way to trigger boot.
That was a long answer. But hey, hopefully you know more about computer power management now. I certainly learned some things researching this.
I don't have time right now to do thorough research, but here's a starting point:
Chips usually don't turn off and then turn on. Instead, there's a reset line which will bring processor in so-called reset state when usually all memory is cleared and processor looks like it's just been powered on. While that pin is held high (or low, depending on the processor), the processor is in reset. Once the pin is released, it will continue booting normally, just as if it was turned on for the first time. The point of this is that there's no power cut itself.
So how does this scale to larger systems like modern PCs? Well modern computers are made out of computers which are sometimes made out of computers themselves. So when you set computer to reset, "computers" which make the computer will start saving their states (if the reset is controlled), or just have their reset pins pulled.
Some processors and microcontrollers (which are miniature self-contained computers, usually 20 years behind the modern desktop computers) can reset themselves using internal switches. As I said, once the signal which generates reset is gone, the computer will start up. So the premise in the question isn't completely right. Computer doesn't know when to turn on. In know when it needs to be "off" or in reset and when the signal which keeps it there is gone, it will turn on.
This behavior may look strange on modern computer which can be set to turn on at specific time or over network and so on. As I said computers are made of computers. So while the main processor may be off, there could be numerous other chips and microcontrollers inside which are on. The most obvious case is the real-time clock which is often battery powered. It can then turn on other chips which will turn on other chips and the chain reaction goes until the whole computer is on. On today's computers, there's a PSU line called +5 VDC Standby Voltage. It provides around 50 mW power to various devices that are on when computer is "off".
A little bit of trivia: Reset pin on Intel 386 EX processor is pin number 110.
On Intel i7-900 it's land number AL39.
I hope that someone will be able to provide an answer which will explain how things work from the high level point of view, since it's quite complicated system.
This blog post describes how Linux triggers a reboot.
It frobs an I/O location which pulls a data line low which tells the CPU that it should stop whatever it's doing and start running code from a certain location in the BIOS.
Back in the old days before power management, computers could still restart themselves, of course. (Anybody remember when a frozen program meant you had to use Ctrl+Alt+Delete to reboot the computer?)
On my old 486, the assembly language command
A Google search for JMP FFFF:0000 reveals many interesting pages about this.
There is also a thing named the watchdog. This device serves as a dead-man's switch. The computer has to signal to the watchdog every say minute that it is still alive. When the computer crashes, e.g. by running into an endless loop, it will fail to signal to the watchdog it is still running as intended, on which occasion the watchdog will perform a hardware reset. This was demonstrated in the popular tv series of the terminator, where a robot was knocked out by a high voltage power surge. it would reset itself in 2 minutes.
Back on the old IBM PC-1 the keyboard controller, oddly enough, handled reboot. IBM embedded a small microprocessor to handle the keyboard, and it had some spare I/O lines, so they used one of the lines to drive the reset line of the main CPU. A command sent to the keyboard controller would result in the CPU being reset as if power had just been switched on.
I'm guessing this tradition continued well into the "AT" era, and there may be vestiges of it remaining in ACPI today.
Added: There's an interesting detail about the above reset scheme. During the early boot sequence the code looked for a particular pattern in RAM that might have been set by the previously executing code. If this code was present some of the POST (power-on self-test) diagnostics were skipped. The pattern would only be present on a "warm" boot.
protected by nhinkle♦ Jun 9 '11 at 17:14
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site.
Would you like to answer one of these unanswered questions instead?