flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Power Off Question

Author
Thread Post new topic Reply to topic
grimpirate



Joined: 25 Oct 2006
Posts: 3
grimpirate
I'm curious if anyone can refer me to a URL or explain how exactly it is that I can achieve a soft power down in assembly code. Like is there a certain interrupt I should call? Some special value I need to place into memory? A particular opcode? Any help is appreciated.
Post 25 Oct 2006, 02:28
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
Post 25 Oct 2006, 12:33
View user's profile Send private message Visit poster's website Reply with quote
grimpirate



Joined: 25 Oct 2006
Posts: 3
grimpirate
Thx alot Octavio, that really helps and I actually put the interrupt in there and got it to work Very Happy So here it is for the sake of helping someone else out who might need it.
Code:
boot_start      equ     0x7c00

jmp boot_code
nop

times   59      db      0xff

boot_code:
mov     si,     boot_start + message
mov     ah,     0x0e
mov     bx,     0x07
@@:
lodsb
or      al,     al
jz      @f
int     0x10
jmp     @b
@@:
mov     ah,     0x00
int     0x16
mov     ax,     0x5307
mov     bx,     0x0001
mov     cx,     0x0003
int     0x15

message db      'Hello World!', 13, 10
        db      'Press any key to shut down computer...', 0

times   510 - $         db      0
db      0x55, 0xaa    

NOTE: My code isn't as well done as Octavio's his actually checks that the Interrupt exists and is functional. I don't quite understand all of it, but I figure that's what it's doing.
Post 26 Oct 2006, 06:22
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
Here's what I'm using from a PM OS:

Code:
PowerManagmentVersion dw 0
NoPowerManagment      db 'No power management functionality',10,13,0
ErrorMessage          db 'Power management error',10,13,0
WrongVersion          db 'Need APM version 1.1 or better',10,13,0

PowerDown:

   mov ax,5300h                     ; See if APM available
   mov bx,0                         ; device = BIOS
   int 15h
   mov si,NoPowerManagment
   jc .Error
   cmp ax,101h                      ; See if version 1.1 or greater
   mov dx,WrongVersion
   jc .Error
   mov [PowerManagementVersion],ax
   mov ax,5301h                     ; Do a real mode connection
   mov bx,0                         ; device = BIOS
   int 15h
   jnc .NoConectionError
   cmp ah,2                         ; Pass if already connected
   mov si,ErrorMessage              ; else error
   jnz .Error

.NoConnectionError:

   mov ax,530eh                     ; Enable latest version of APM
   mov bx,0                         ; device = BIOS
   mov cx,[PowerManagmentVersion]   ; version
   int 15h
   mov si,ErrorMessage
   jc .Error
   mov ax,530dh                     ; Now engage and enable CPU management
   mov bx,1                         ; device = all
   mov cx,1                         ; enable
   int 15h
   mov si,ErrorMessage
   jc .Error
   mov ax,530fh
   mov bx,1                         ; device = ALL
   mov cx,1                         ; enable
   int 15h
   mov si,ErrorMessage
   jc .Error
   mov ax,5307h                     ; Do the power down
   mov bx,1                         ; device = ALL
   mov cx,3                         ; mode = OFF
   int 15h                          ; shutdown CPU
   mov si,ErrorMessage

.Error:

   call PrintString
   ret

    
Post 26 Oct 2006, 12:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.