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.
octavio

Re:Shutdown code??

Post by octavio »

This is a copy of the solar post , i meant the complete code of
the boot sector you wrote to make a test.
viral

Re:Shutdown code??

Post by viral »

Code: Select all

[BITS 16]      
[ORG 0x7C00]   

 mov ax,0x0000   
 mov ds,ax   
 mov si, HelloWorld   
 call PutStr   


; Shutdown when RETURN pressed
Not_CR:
    mov ah,0 
    int 0x16                        
    cmp al,0x0D
    jne Not_CR 

;;////////////  SHUT DOWN CODE//////////////
   mov ax, 5300h
   mov bx, 0
   int 15h
   jc fin
   test cx, 1
   jz fin
   push ax
   mov ax, 5301h
   mov bx, 0
   int 15h
   pop cx
   jnc forward
   cmp ah, 2
   jne fin
   forward:
   mov ax, 530eh
   mov bx, 0
   int 15h
   mov ax, 5307h
   mov bx, 1
   mov cx, 3
   int 15h
   jc fin
   ret
   fin:
   mov si, ErrorMsg    
   call PutStr      
;;///////////////////////////////////////////

jmp $   ; Never ending loop

PutStr:      
    mov ah,0x0E   
    mov bh,0x00   
    mov bl,0x07   

   .nextchar:   
    lodsb      
    or al,al   

    jz .return   

    int 0x10   
    jmp .nextchar   
   .return:   
    ret      


HelloWorld db 'Hello World',13,10,0
ErrorMsg db 'Function is not supported', 13, 10, 0
times 510-($-$$) db 0   
dw 0xAA55      

dc0d32

Re:Shutdown code??

Post by dc0d32 »

maybe you should refer to the Ralf Brown's Interrupt list
dc0d32

Re:Shutdown code??

Post by dc0d32 »

octavio wrote: search in RBIL for explanations.
osbios

Re:Shutdown code??

Post by osbios »

This code works for me:

Code: Select all

 ;ATX shutdown
 mov ax,0x5301
 xor bx,bx
 int 0x15

 mov ax,0x530e
 xor bx,bx
 mov cx,01
 int 0x15

 mov ax,0x530f
 mov bx,1
 mov cx,bx
 int 0x15

 mov ax,0x5308
 mov bx,1
 mov cx,bx
 int 0x15

 mov ax,0x5307
 mov bx,1
 mov cx,3
 int 0x15
 
 hlt   ;no atx? then stop!
 jmp $ ;do you know the hlt bug? :)
viral

Re:Shutdown code??

Post by viral »

hello...
I have refered Ralph Brown's Interrupt List... The code is giving me error:
(86h) => Advance Power Management not present.

But windows is working nicely..!!
dc0d32

Re:Shutdown code??

Post by dc0d32 »

Brendan wrote: BTW Windows probably uses ACPI instead (i.e. does a transition to the "S5 Soft Off" state using values from the "\_S5" object in the ASL/AML namespace).
octavio

Re:Shutdown code??

Post by octavio »

Viral, your code works on my computer, so the problem is that your computer uses another method.Not a problem for windows or linux, they have one GB of drivers.
viral

Re:Shutdown code??

Post by viral »

Hello...
So there is problem with my PC only.. As this code is working in others.. Its giving me error (APM not present).
Is there any other way of doing this?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Shutdown code??

Post by Brendan »

Hi,
viral wrote: So there is problem with my PC only.. As this code is working in others.. Its giving me error (APM not present).
Is there any other way of doing this?
I see four choices you could make:
  • - use ACPI if it's present
    - use APM if it's present
    - use a chipset driver if it's present
    - display a message and loop forever
To be honest, they all seem like good chioces to me...

For example:

Code: Select all

shutdown {
   if( ACPI_supported == YES ) attempt_ACPI_shutdown();
   if( APM_supported == YES ) attempt_APM_shutdown();
   if( chipset_driver_present == YES ) attempt_chipset_shutdown();
   printf("\n\nYou can turn the computer off now!\n");
   for(;;) {}
}
Of course "display a message and loop forever" is the only option that is guaranteed to work on all computers...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
viral

Re:Shutdown code??

Post by viral »

hi..
So I have to go for ACPI and chipset driver... But how ??? I dont know interrupts that'll do that work? What part of Ralph Brown's Int List I have to study for this?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Shutdown code??

Post by Brendan »

Hi,
viral wrote: So I have to go for ACPI and chipset driver... But how ??? I dont know interrupts that'll do that work? What part of Ralph Brown's Int List I have to study for this?
For ACPI, there's tables that your OS can search for that provides information needed by an "ACPI OS" to boot. This information includes some "AML" ("ACPI Machine Language"), which is byte-code for an interpretted OOP language that the OS uses after boot. There are no interrupts, I/O ports, BIOS functions, etc - see the ACPI specification/s for details.

For chipset drivers, each chipset is different and you'd need to look at the datasheets/manuals for each specific chipset. Ralph Brown's lists aren't useful for this either.

Even though you'll eventually need to look at ACPI and/or chipset drivers, both of these options aren't easy and you don't need to do them now. As an example, after about 5 years of work (with many developers and help from Intel ) Linux almost has ACPI working, and Linux doesn't have much in the way of chipset drivers (a few options when you configure the kernel for a few chipsets, but not much else).

For now, I'd do something lke this:

Code: Select all

shutdown {
//  if( ACPI_supported == YES ) attempt_ACPI_shutdown();
  if( APM_supported == YES ) attempt_APM_shutdown();
//  if( chipset_driver_present == YES ) attempt_chipset_shutdown();
  printf("\n\nYou can turn the computer off now!\n");
  for(;;) {}
}
Then, later on when you're adding ACPI support and/or adding a generic interface for chipset drivers you can uncomment the lines above.

For now, I'd recommend having a quick look at the ACPI specification and browsing through the chipset datasheets/manuals for an Intel chipset, but I wouldn't worry about writing any code for them until you've got a web browser, word-processor, native compiler/tools, etc...


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply