Shutting Down and Restarting 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.
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Post by ~ »

XCHG wrote:Oh you can also restart the PC by setting Bit#0 in keyboard’s microcontroller output port. First you have to poll Port 0x64 and see if Bit#0 is zero and then go on if yes. Then send the command 0xD1 to Port 0x64 and poll the same port and wait until Bit#0 is zero again just like you did at the first step. Now send the command 0x01 to Port 0x60 and the PC will be restarted. Here is the code that I wrote:

Code: Select all

  @@__WaitInputEmpty:
    IN      AL , 0x64
    TEST    AL , 0x01
    JNE     @@__WaitInputEmpty
  MOV     AL , 0xD1
  OUT     0x64 , AL
  @@__WaitAgain:
    IN      AL , 0x64
    TEST    AL , 0x01
    JNE     @@__WaitAgain
  MOV     AL , 0x01
  OUT     0x60 , AL
Hope that it helps.
Would that work in a multicore/multiprocessor system (i.e., would it leave the machine in a predictable state)?
Kieran
Member
Member
Posts: 54
Joined: Mon Apr 11, 2005 11:00 pm

Post by Kieran »

What a great piece of code, this should be placed into the Wiki
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Post by Zenith »

It is on the wiki, though pretty hidden...
http://www.osdev.org/wiki/Keyboard_Controller

You didn't have to resurrect a year-old thread if you had looked harder...
"Sufficiently advanced stupidity is indistinguishable from malice."
User avatar
CmpXchg
Member
Member
Posts: 61
Joined: Mon Apr 28, 2008 12:14 pm
Location: Petrozavodsk, Russia during school months, Vänersborg Sweden in the summertime

Post by CmpXchg »

Well, talking about shutdown, things ain't so sad.
Using the datasheet, I figured out how to shutdown my own PC via motherboard registers:

Code: Select all

%define	pcidev(dev,func)	(dev<<3)+func
...
;get I/O base
	call	pci_read_config_dword,pcidev(17,0),88h

;if pci_read returned, say, 4001h, adding 3 gives 4004h,
;which corresponds to I/O offset 4.
	add	ax,3

;do the magic;)
	mov	dx,ax
	in	ax,dx
	or	ah,00101000b
	and	ah,11111110b
	out	dx,ax
;the system should now go down ;) the next instruction is never executed, put hlt just in case
	hlt
If you also happen to have a VIA VT82x chipset, you could test it on your machine. PS: I wonder if there's a universal way, is it possible to shutdown from within Protected Mode?
Post Reply