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

Shutdown code??

Post by viral »

hello...
I want to implement "turn off" command like windows os.
The ATX should be turned off after executing this command. I was going through Tim's code of Mobiues.. but not getting anything..
can anyone help me with a piece of code or steps to follow..... Thanks in advance...
octavio

Re:Shutdown code??

Post by octavio »

run the code with octasm for dos and the computer will power
off, search in RBIL for explanations.

Code: Select all

LANG OCTASM,0.1
\OCTASM.SYM
{
ax=5300h bx=0 int 15h jc fin
test cx,1 jz fin
push ax ax=5301h bx=0 int 15h
pop cx jnc >1
cmp ah,2 jne fin
# ax=530eh bx=0 int 15h
ax=5307h bx=1 cx=3 int 15h jc fin
ret
#fin
prn("%nb %13 function not supported")
ret
}

User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Shutdown code??

Post by Solar »

Ah, yet another assembler around, and with lib dependencies, even. ;-) Let's see if I can do the Intel equivalent:

Code: Select all

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:
prn("function not supported")
ret
Any of the Intel / NASM coders around is invited to correct me, I suck at ASM. ;)
Every good solution is obvious once you've found it.
viral

Re:Shutdown code??

Post by viral »

hello....
thanks for that.. but my OS is in protected mode. So how can i call int 15h ?
Is it so that i have to switch first from PMode -> Real mode and than call this interrupt?
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 »

most indeed do get back to realmode first and then shutdown. That's not terribly hard, though, as long as you have a way to allocate memory below 1MB, getting back to realmode is sensibly simpler than setting up pmode (and iirc, in that case, you even do not need to bother to reset IRQs setup or whatever): just reset PG and PM bits of CR0, far jump and voil? :P
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:hello....
thanks for that.. but my OS is in protected mode. So how can i call int 15h ?
Is it so that i have to switch first from PMode -> Real mode and than call this interrupt?
The APM specification includes a real mode interface, a 16 bit protected mode interface and a 32 bit protected mode interface. Both of the protected mode interfaces were optional in early versions of the specification, but became mandatory in APM version 1.2 (February 1996).

It would be possible to use one of the protected mode interfaces to shutdown the computer without going to real mode first on almost all modern computers.

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


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 »

Hello...
@Brenden: Sorry but not getting anything.. Can you try to elaborate yourself please...

@Pype: I havent try to switch in real mode.. I guess the steps are:

1. Load our Shutdown code in memory < 1 mb (jumphere:)
2. Reset PM & PG bit
3. Jump to new location below 1 mb(goto jumphere;)
4. Just wait & watch....

And one more question.. Is bochs emulate shutdown of pc?
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 »

viral wrote:
And one more question.. Is bochs emulate shutdown of pc?
haven't tried so far ... what about getting a disk image of The Mobius and finding out ?
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:@Brenden: Sorry but not getting anything.. Can you try to elaborate yourself please...
For the APM functions, there's protected mode interfaces (similar to the protected mode interface for VBE video). To use them, you need to detect if any of the protected mode interfaces are supported and enable the protected mode interface you want to use during boot (i.e. in real mode). Then you set up some GDT entries for the protected mode interface and can use them to access APM functions directly from protected mode without switching back to real mode at all. It's been a long time since I've looked at the APM Specification though - it'd be best to download it and have a look...

For ACPI, welcome to hell! ;)
viral wrote:@Pype: I havent try to switch in real mode.. I guess the steps are:
More completely, the "recommended" steps would be:
  • 1. Load your shutdown code in memory < 1 mb (jumphere:)
    2. Load "real mode compatible" segments (16 bit protected mode segments with limit = 64 KB)
    3. Reset PM & PG bit
    4. Far jump to new location below 1 mb (which reloads CS)
    5. Load real mode segments for data segments and stack
    6. Set SP to something
In addition, you may need to restore the real mode IVT by doing "LIDT" with a base address of 0x00000000 and a limit of 1023 or higher.
viral wrote:And one more question.. Is bochs emulate shutdown of pc?
Bochs does (should).... :)


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 »

Hello...
I tried above code.. What i did. I made a small "Hello world" bootloader and tried to shutdown after printing hello world. But it is giving error "Function Not Supported". Now why is it so?
My PC is P4 1.7Ghz, Intel 845GLLY. Windows is properly shut down... so is there something else i have to see ?
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 »

wrong API version ? or maybe your PC only supports ACPI and not APM ... I'd say the "power & batteries" settings on your control panel should tell what is used by windows ...
dc0d32

Re:Shutdown code??

Post by dc0d32 »

viral wrote: it is giving error "Function Not Supported". Now why is it so?
whos givin that error? probably bochs... did u tyr on a real machine?
viral

Re:Shutdown code??

Post by viral »

whos givin that error? probably bochs... did u tyr on a real machine?
The code give posted by Solar is giving this error.

I think my PC doesnt support that int. Is there any other way getting around it?
octavio

Re:Shutdown code??

Post by octavio »

post your code, perhaps you did some mistake. Is rare that a modern computer don?t support this.
viral

Re:Shutdown code??

Post by viral »

Code: Select all

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:
prn("function not supported")
ret
Post Reply