Page 1 of 1
shut down option
Posted: Mon Feb 25, 2008 2:09 pm
by vishal
for the turn off option in my os are the statments
cli
hlt
enough or do i need to do anything more??
i just store kernel and some programs on the ram.i am working on 16 bit real mode and coding in assembly language.
Posted: Mon Feb 25, 2008 2:21 pm
by Dex
Do you mean to holt your OS (as in sleep) or turn the PC off ?.
For turning off , most coders reboot, first Printing a mesage "Please remove disk from A: drive and press anykey to reboot"
eg:
Code: Select all
ReBootMe:
DB 0EAh ; Machine language to jump to address FFFF:0000 (reboot)
DW 0000h
DW 0FFFFh ; No return required we're rebooting!
jmp $ ; Just incase ;-)
Posted: Mon Feb 25, 2008 7:12 pm
by Jef
or you can use this in PMode:
Code: Select all
mov al, 0FEh
out 64h, al ;this cause a soft reset
but if you want to turn off (via code) the power supply unit ?
Posted: Tue Feb 26, 2008 2:11 am
by vishal
i have given the user another option for reboot.
after the user selects the os to turn off the computer
i have to
1) cli
2) hlt
3) turn off the power supply
do i need to do anything more/less to turn off the computer?
and how do i turn off the power supply via code ?
i am coding in assembly language (16 bit real mode)
Posted: Tue Feb 26, 2008 2:27 am
by JamesM
I believe it's to do with ACPI, but I'm no expert on it so I'll wait for someone more suited to chip in.
Posted: Tue Feb 26, 2008 4:22 am
by ~
Maybe this:
Using APM 1.2 (I have tried it in an AMD64 3000+ in a 2 year old motherboard and worked):
Code: Select all
;***remove this if your are using real/unreal mode***
xor eax,eax
mov cr0,eax
;***to here***
mov ax,5301h
xor bx,bx
int 15h
mov ax,530Eh
mov cx,0102h
int 15h
mov ax,5307h
mov bl,0001h
mov cx,0003h
int 15h
;***system will shutdown, or else there was a error***
Error:
http://www.osdev.org/phpBB2/viewtopic.p ... c&start=13
Posted: Tue Feb 26, 2008 7:26 am
by Emil
~ wrote:Maybe this:
Using APM 1.2 (I have tried it in an AMD64 3000+ in a 2 year old motherboard and worked):
Code: Select all
;***remove this if your are using real/unreal mode***
xor eax,eax
mov cr0,eax
;***to here***
mov ax,5301h
xor bx,bx
int 15h
mov ax,530Eh
mov cx,0102h
int 15h
mov ax,5307h
mov bl,0001h
mov cx,0003h
int 15h
;***system will shutdown, or else there was a error***
Error:
http://www.osdev.org/phpBB2/viewtopic.p ... c&start=13
But you need to make sure you don't overwrite the real mode IVT while you are in PMODE if you want this to work. That obviously does not apply to the OP as he is creating a real mode OS.
Posted: Tue Feb 26, 2008 9:42 am
by Dex
First you do not do the cli or hlt, here is the code from DexOS that shuts down
Code: Select all
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 [PowerManagmentVersion],ax
mov ax,5301h ; Do a real mode connection
mov bx,0 ; device = BIOS
int 15h
jnc .NoConnectionError
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
jmp ReBoot ; reboot
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
Posted: Tue Feb 26, 2008 12:07 pm
by lukem95
yeah i've hear ACPI is the way to do it.
you will need PCI implemented, and then need to go about reading the ACPI specification for further detail
Posted: Tue Feb 26, 2008 12:27 pm
by StephanvanSchaik
If you want to shutdown you have 4 methods you can use in total...
1. Try to shutdown with ACPI.
2. Try to shutdown with APM.
3. Ehm forgot this one... (Should be a hack or something, I don't remember, but there's always the search function

)
4. There's no way to shutdown the PC, just display a message like "You can now turn off your computer.".
If I am right MenuetOS has some code to shutdown properly via APM if I remember well or it was some other operating system.
You can check the wiki and google is your friend.
Regards, Stephan J.R. van Schaik.