Shutting down the computer

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
srg_13

Shutting down the computer

Post by srg_13 »

Hi,
How can you turn off a computer from protected mode in C?

Thanks,

Stephen
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Shutting down the computer

Post by Brendan »

Hi,
Stephen wrote:How can you turn off a computer from protected mode in C?
There's 3 options - APM, ACPI and direct hardware/IO instructions.

For APM there's a protected mode interface (16 bit and/or 32 bit) that's supported by some BIOSs, but not all. This option probably can't be done with C alone.

ACPI is an overcomplicated mess, requiring an interpretter for it's own OOP language (AML). It should be possible to do this all in C though.

Direct hardware/IO depends on the motherboard/chipset, so you'd heaps of "motherboard drivers" - one for each motherboard.

Then there's computers that lack the needed hardware, and therefore don't have any method of turning the power off (e.g. Pentium and older computers).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
srg_13

Re:Shutting down the computer

Post by srg_13 »

Brendan wrote:For APM there's a protected mode interface (16 bit and/or 32 bit) that's supported by some BIOSs, but not all. This option probably can't be done with C alone.
Thats ok, I can use NASM code as well.
aladdin

Re:Shutting down the computer

Post by aladdin »

There is also the "Power button" method witch work on all computers ;)
smiddy

Re:Shutting down the computer

Post by smiddy »

aladdin wrote: There is also the "Power button" method witch work on all computers ;)
Yeah, but the trick is to get the software to push the button. ;D
AR

Re:Shutting down the computer

Post by AR »

You can also reprogram what that button does using ACPI (not sure about APM) so it could open the painting program or some other weird thing instead...
GLneo

Re:Shutting down the computer

Post by GLneo »

hi,

if it helps anyone here is a reboot :)

Code: Select all

void reboot() 
{
    volatile unsigned char good = 0x02;
    while ((good & 0x02) != 0)
        good = inportb(0x64);
    outportb(0x64, 0xFE);
    for(;;);
}
srg_13

Re:Shutting down the computer

Post by srg_13 »

Thanks, but I already have a reboot. I was kinda hoping that it would be that simple to shut down the computer ;)

-Stephen
Post Reply