Page 1 of 2
Shutdown code??
Posted: Mon Apr 24, 2006 12:33 am
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...
Re:Shutdown code??
Posted: Mon Apr 24, 2006 6:51 am
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
}
Re:Shutdown code??
Posted: Mon Apr 24, 2006 7:20 am
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.
Re:Shutdown code??
Posted: Mon Apr 24, 2006 8:34 am
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?
Re:Shutdown code??
Posted: Mon Apr 24, 2006 9:06 am
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?
Re:Shutdown code??
Posted: Mon Apr 24, 2006 9:48 pm
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
Re:Shutdown code??
Posted: Tue Apr 25, 2006 12:32 am
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?
Re:Shutdown code??
Posted: Tue Apr 25, 2006 12:39 am
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 ?
Re:Shutdown code??
Posted: Tue Apr 25, 2006 2:03 am
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
Re:Shutdown code??
Posted: Tue Apr 25, 2006 3:57 am
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 ?
Re:Shutdown code??
Posted: Tue Apr 25, 2006 4:02 am
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 ...
Re:Shutdown code??
Posted: Tue Apr 25, 2006 10:00 am
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?
Re:Shutdown code??
Posted: Wed Apr 26, 2006 12:07 am
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?
Re:Shutdown code??
Posted: Wed Apr 26, 2006 1:29 am
by octavio
post your code, perhaps you did some mistake. Is rare that a modern computer don?t support this.
Re:Shutdown code??
Posted: Wed Apr 26, 2006 1:36 am
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