shutdown code

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
Ninja Rider

shutdown code

Post by Ninja Rider »

im going to search for it but would anybody know how to shutdown a computer using assembly coding.
Crazed123

Re:shutdown code

Post 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.
bluecode

Re:shutdown code

Post 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).
Cjmovie

Re:shutdown code

Post 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
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:shutdown code

Post 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 ...
Ninja Rider

Re:shutdown code

Post 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.
AR

Re:shutdown code

Post 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)
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:shutdown code

Post 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.
Warrior

Re:shutdown code

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:shutdown code

Post 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.
Kemp

Re:shutdown code

Post 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).
JoeKayzA

Re:shutdown code

Post 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
Post Reply