Bona Fide OS Developer
View unanswered posts | View active topics It is currently Thu Mar 28, 2024 8:46 am



Post new topic Reply to topic  [ 5 posts ] 
 Shutdown computer 
Author Message

Joined: Thu Dec 23, 2010 1:12 pm
Posts: 9
Post 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.


Thu Dec 23, 2010 1:24 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post 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)

_________________
Charles Timko
push %esp ;Musings of a computer addict


Tue Dec 28, 2010 2:52 am
Profile WWW

Joined: Thu Dec 23, 2010 1:12 pm
Posts: 9
Post 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.


Thu Dec 30, 2010 4:50 pm
Profile

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post 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.

_________________
Charles Timko
push %esp ;Musings of a computer addict


Mon Jan 03, 2011 6:55 pm
Profile WWW

Joined: Wed Oct 14, 2009 9:39 am
Posts: 198
Location: United States
Post 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

_________________
Charles Timko
push %esp ;Musings of a computer addict


Mon Jan 03, 2011 7:50 pm
Profile WWW
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 


Who is online

Users browsing this forum: No registered users and 31 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin and tweaked by the BF Team.