Bona Fide OS Development
http://forums.osdever.net/

Shutdown computer
http://forums.osdever.net/viewtopic.php?f=4&t=863
Page 1 of 1

Author:  jflanagan987 [ Thu Dec 23, 2010 1:24 pm ]
Post subject:  Shutdown computer

Does anyone know how to shutdown/reboot the computer in nasm or c? I've found a way to do it in real mode but it only seems to work on certain bioses. It requires the use of bios interrupts so it wouldn't work in protected mode. I think it is something to do with acpi.

Author:  ctimko [ Tue Dec 28, 2010 2:52 am ]
Post subject:  Re: Shutdown computer

In order to properly shutdown the computer you need to touch the ACPI and bring the system into G3 - Global State 3 (Hardware off). The ACPI specification is here: http://www.acpi.info/DOWNLOADS/ACPIspec40a.pdf
I have been reading it on and off, and I guess I will get down to reading it completely in a week or so and then I should have a more definite answer and actual code. :-D I have just been too busy with other projects to look at it right now (and I have to get my kernel re-programmed again :-P)

Author:  jflanagan987 [ Thu Dec 30, 2010 4:50 pm ]
Post subject:  Re: Shutdown computer

Thanks for the code, mamk. I'll try editing my kernel code the next time I log onto my computer(i am sending this from amazon kindle). I will also have a look at the acpi documentation.

Author:  ctimko [ Mon Jan 03, 2011 6:55 pm ]
Post subject:  Re: Shutdown computer

Ok, so some words of knowledge.

The ACPI controls the different power states. First and foremost is the working state of the system, specified as G0. When you want to shut down the system you have to get it the G2 state. G1 is sleeping/hibernating/etc that consists of 3 states as well S0-S2. G2 is soft-off (only changes back to G0 under restart). G3 is mechanical off (only reachable via a power button and can only be moved to G0 from a button).

So in order to get from G0 to G2, you need to do the following:
- Get the PM1a_EVT_BLK and PM1b_EVT_BLK values (4bytes wide each) at offsets 56 and 60 respectively.
Read 4.7.1 (ACPI Register Summary). You will need to write a driver to access the general ACPI.

As of right now I can't find the actual Register information, all I know is that the information is located within one of the descriptor tables you have to define, so there is a LOT of code that is needed that would take more than just a few lines to truly be able to control the power of the system (short of sending the CPU into a Triple Fault resulting in an error-based restart). So I will keep reading this spec and working up its entire structure to get us some good code for shutting down.

Note: you might be able to get to G3 with software if you define a fake Lid (like a laptop) and on shutdown raise the event of the lid closing and it will transition to the state you have set inside of the Lid register.

Author:  ctimko [ Mon Jan 03, 2011 7:50 pm ]
Post subject:  Re: Shutdown computer

Also FYI, the code provided above for restart(), I am going to explain it so if anyone is curious about it.

First the good variable to check to see if the Keyboard is done doing what it is doing (this is done reading from the 0x64 which is the command port). Now you can write to 0x64 (which is what that code is doing) and doing so will execute a specific command. 0xFE is the CPU reset command. More information and controls are defined here: http://www.win.tue.nl/~aeb/linux/kbd/sc ... html#kccaf

Page 1 of 1 All times are UTC - 6 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/