shut down option

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
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

shut down option

Post 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.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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 ;-)
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Post 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 ?
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
vishal
Posts: 17
Joined: Sun Nov 11, 2007 3:30 pm

Post 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)
Last edited by vishal on Tue Feb 26, 2008 3:10 am, edited 1 time in total.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

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

Post 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
Emil
Posts: 3
Joined: Sat Jan 26, 2008 7:56 am
Location: Reykjavik, Iceland

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

Code: Select all

/* world's last mistake in C */
if(code = CODE_RED) {
    launch_missles();
}
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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

User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post 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
~ Lukem95 [ Cake ]
Release: 0.08b
Image
StephanvanSchaik
Member
Member
Posts: 127
Joined: Sat Sep 29, 2007 5:43 pm
Location: Amsterdam, The Netherlands

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