Page 1 of 1
shutdown code
Posted: Wed Sep 21, 2005 2:26 pm
by Ninja Rider
im going to search for it but would anybody know how to shutdown a computer using assembly coding.
Re:shutdown code
Posted: Wed Sep 21, 2005 2:36 pm
by Crazed123
If you mean to just stop the CPU, the "hlt" instruction will work. If you mean something more complicated you'll need ACPI or APM support, which I don't know too much about right now.
Re:shutdown code
Posted: Wed Sep 21, 2005 4:41 pm
by bluecode
hi,
I found following code:
Code: Select all
GLOBAL _Shutdown
_Shutdown:
mov ax,5301h ;activate real-mode APM interface
xor bx,bx
int 15h
mov ax,530eh ;Select APM version
xor bx,bx
mov cx,0102h ;v1.2
int 15h
mov ax,530fh ;Activate APM for every devices
mov bx,0001h ;ID 1=everyl devices
mov cx,0001h ;1=engage
int 15h
mov ax,5308h ;Atomatically activate APM for every devices
mov bx,0001h ;ID 1=every device
mov cx,0001h ;1=enable
int 15h
mov ax,5307h ;set device state
mov bx,0001h ;ID 1=every device
mov cx,0003h ;status 3=Shutdown
int 15h
I didn't test it. I only translated the comments from German into English. I didn't write this code.
That said, it seems to work only in real-mode with APM (at least version 1.2).
Re:shutdown code
Posted: Thu Sep 22, 2005 6:21 am
by Cjmovie
I'm going to assume that that's becuase the interrupts are BIOS calls.
A note for Ninja Rider: If your OS runs in protected mode, your best chance of using this code is to write a V8086 handler. This at the same time will allow you to use BIOS to change graphics modes, do VESA graphics stuff, etc.
I beleive....
http://www.osdev.org/osfaq2/index.php/W ... %20mode%3F
Re:shutdown code
Posted: Thu Sep 22, 2005 7:07 am
by Pype.Clicker
Note that i haven't tried ACPI nor APM myself so far, but i'm not so sure it's a good idea to shutdown from virtual mode. I'd rather switch back to realmode for this ...
Re:shutdown code
Posted: Thu Sep 22, 2005 8:22 am
by Ninja Rider
well i havn't even gotten into virtual mode yet still using real mode. i believe the int 15h above is a bios interrupt myself. i was just wondering because i know windows can turn of the computer and i was wondering how they did it.
Re:shutdown code
Posted: Thu Sep 22, 2005 8:26 am
by AR
Can't say for certain but 98 should use APM, 2000+ uses ACPI, it falls back on APM but tries to avoid it (There are some comments in the APM Driver description file [C:\Windows\inf] that states that APM is unreliable and should only be used if the user explicitly enables it IIRC)
Re:shutdown code
Posted: Sat Oct 01, 2005 3:04 am
by Pype.Clicker
many hobby OS can turn your computer down just aswell. The Mobius just is one of them that i use to use as example.
Re:shutdown code
Posted: Sat Oct 01, 2005 10:23 am
by Warrior
Is it possible to program the shutdown button to send a message to the OS telling it it's shutting down and allowing the OS time to save whatever it's doing instead of it being so unexpected?
Re:shutdown code
Posted: Sat Oct 01, 2005 10:59 am
by Pype.Clicker
yep, i think this is possible. I'm not 100% sure of _how_ to achieve this, though, and i think that it will require you to install your own "system management mode" software, rather than the BIOS's one.
Re:shutdown code
Posted: Sat Oct 01, 2005 2:24 pm
by Kemp
I know windows did this, dunno about linux (I think so). Basically when you press the power button it'll act as if you chose Start -> Turn off computer -> Shutdown (if the various settings are right).
Re:shutdown code
Posted: Sat Oct 01, 2005 2:43 pm
by JoeKayzA
Linux and Windows do this with ACPI, AFAIK. Pressing the button triggers an ACPI event, which the system then reacts to, I don't know more details about it however, the docs should help (although I heard that ACPI is a hell to implement properly).
Never heard about power button notification through APM, btw.
cheers Joe