Motherboard Forums


Reply
 
 
Allan Adler
Guest
Posts: n/a
 
      10-19-2007, 10:29 AM
It is my understanding that power down is controlled by the BIOS.
I learned about this when a PC got into a state where it was impossible
to turn it off with the on/off switch because it had never gotten to
the point in booting where it loaded the BIOS. It's since been fixed.

I'd like to write an assembly language program that shuts off the computer.
I've looked at books that discuss interrupts and the BIOS but none of them
list power down in the index. I looked through lists of interrupts and didn't
see this one.

So, how does one do it?
--
Ignorantly,
Allan Adler <(E-Mail Removed)>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
 
Reply With Quote
 
 
 
 
Keith Beef
Guest
Posts: n/a
 
      10-25-2007, 02:59 AM
On Fri, 19 Oct 2007 06:29:35 -0400, Allan Adler wrote:

> It is my understanding that power down is controlled by the BIOS.
> I learned about this when a PC got into a state where it was impossible
> to turn it off with the on/off switch because it had never gotten to
> the point in booting where it loaded the BIOS. It's since been fixed.
>
> I'd like to write an assembly language program that shuts off the computer.
> I've looked at books that discuss interrupts and the BIOS but none of them
> list power down in the index. I looked through lists of interrupts and didn't
> see this one.
>
> So, how does one do it?


I don't know how you do it, but clearly it can be done...

I remember a few years ago, that my Linux box built round an Abit BP6 (two
Celeron CPUs rated at 400MHz but overclocked to 600MHz, IIRR) would not
power down when I told it to (shutdown -h now) until I found out that I
needed to boot with a special option like "noapic", or similar.

After I added that to the bootloader, it would power down whenever I told
it to.

Maybe you could look at the source code for shutdown, and figure out from
there how it's done.

Try googling for information about APCI and APIC, for more clues.

Beef.
 
Reply With Quote
 
 
 
 
J de Boyne Pollard
Guest
Posts: n/a
 
      10-25-2007, 02:37 PM
AA> It is my understanding that power down is controlled by the BIOS.

It's controlled by circuitry on the motherboard that signals the power
supply unit through a line on the power connector. This circuitry is
in turn controllable from software via chipset registers. These
registers vary according to chipset. The firmware, which has intimate
knowledge of the chipset, knows exactly which registers to poke.

AA> I'd like to write an assembly language program that shuts off the
computer.

Firrwares export interfaces so that other softwares can control system
power states by invoking firmware functions. What you need to read
about are Advanced Power Management and the Advanced Configuration and
Power Interface. Bear in mind that operating systems are the intended
users of these interfaces, not the applications programs that run on
top of them.

 
Reply With Quote
 
Allan Adler
Guest
Posts: n/a
 
      10-28-2007, 12:01 PM
J de Boyne Pollard <(E-Mail Removed)> writes:

> AA> It is my understanding that power down is controlled by the BIOS.
>
> It's controlled by circuitry on the motherboard that signals the power
> supply unit through a line on the power connector. This circuitry is
> in turn controllable from software via chipset registers. These
> registers vary according to chipset. The firmware, which has intimate
> knowledge of the chipset, knows exactly which registers to poke.


In the particular computer I am interested in doing this on, the CPU
is an AMD K6 processor and the chipset is an old VIA VT82585 chipset.
Does that help?

> AA> I'd like to write an assembly language program that shuts off the
> computer.
>
> Firrwares export interfaces so that other softwares can control system
> power states by invoking firmware functions. What you need to read
> about are Advanced Power Management and the Advanced Configuration and
> Power Interface. Bear in mind that operating systems are the intended
> users of these interfaces, not the applications programs that run on
> top of them.


Thanks for the lucid explanations. I found Wikipedia articles for both
APM and ACPI.

Some time ago, someone suggested some floppies with boot managers on them,
maybe including Smart Boot Manager. I vaguely recall that one of the options
it offered (if that is the one) was powering down the PC. So, maybe if I
can find documented source code for one of these boot managers, it will
have the secret of how to do this.

OK, I just went to http://btmgr.sourceforge.net/download.html
and downloaded btmgr-3.7-1.tar.gz and untarred it and looked in
the source files. The file utils.asm contains the following:

;================================================= ============================
; power_off ---- turn the power off
;input:
; none
;output:
; never return if successful.
; cf = 1 on error.
;================================================= ============================
power_off:
pusha
call check_apm_bios
jc .end

mov ax, 0x5301
xor bx, bx
int 0x15
jc .end

mov ax, 0x5380
mov bh, 0x8c
int 0x15

mov ax, 0x40
mov bx, 0xd8
push ds
mov ds, ax
or byte [ds:bx], 0x10
pop ds

mov ax, 0x5307
mov bx, 1
mov cx, 3
int 0x15

..end:
popa
ret


;================================================= ============================
; check_apm_bios ---- check if the apm bios present
; output:
; cf = 1 error, cf = 0 ok
;================================================= ============================
check_apm_bios:
pusha
mov ax, 0x5300
xor bx, bx
int 0x15 ; check if apm present
jc .end
cmp bx, 0x504D
jnz .none
test cx, 1
jnz .end
..none:
stc
..end:
popa
ret


I'll have to look at it carefully, but in a nutshell it appears that
one can turn off the power using interrupt 0x15 provided there is
BIOS support for it. I'll see what Gilluwe's The Undocumented PC
says about that.

The next question is this: suppose I take a floppy disk and write this
code to the beginning of the boot sector and then set the PC to boot from
the floppy and boot. Will the machine start up, run through POST and then
shut itself off, assuming it has the APM support?
--
Ignorantly,
Allan Adler <(E-Mail Removed)>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
 
Reply With Quote
 
Arno Wagner
Guest
Posts: n/a
 
      10-28-2007, 02:56 PM
Previously Allan Adler <(E-Mail Removed)> wrote:
> J de Boyne Pollard <(E-Mail Removed)> writes:


[...]

> The next question is this: suppose I take a floppy disk and write this
> code to the beginning of the boot sector and then set the PC to boot from
> the floppy and boot. Will the machine start up, run through POST and then
> shut itself off, assuming it has the APM support?


It should, as the boot code in the boot-sector is justloaded into
RAM and then control is given to it. Hoiwever just writing it there
is not enough. You need to give the bootsector a correct checksum
in addition, or it will not be booted. May also need other things
to be accepted by the BIOS. Easisest thing yould probably be to
modify exiting boot code.

Arno
 
Reply With Quote
 
Allan Adler
Guest
Posts: n/a
 
      10-29-2007, 02:06 AM
Arno Wagner <(E-Mail Removed)> writes:

> Previously Allan Adler <(E-Mail Removed)> wrote:
> The next question is this: suppose I take a floppy disk and write this
> > code to the beginning of the boot sector and then set the PC to boot from
> > the floppy and boot. Will the machine start up, run through POST and then
> > shut itself off, assuming it has the APM support?

>
> It should, as the boot code in the boot-sector is justloaded into
> RAM and then control is given to it. Hoiwever just writing it there
> is not enough. You need to give the bootsector a correct checksum
> in addition, or it will not be booted. May also need other things
> to be accepted by the BIOS. Easisest thing yould probably be to
> modify exiting boot code.


Thanks for the caveats. Where can I find a complete list of conditions
that a bootsesctor has to satisfy to be loadable?

I looked at Gilluwe's book, The Undocumented PC, to inform myself about
int 0x15. It has it, but all instances of it in the code I quoted have
AH=0x53 and that particular case is not discussed in Gilluwe's book.
Where would I read about it?
--
Ignorantly,
Allan Adler <(E-Mail Removed)>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
 
Reply With Quote
 
Allan Adler
Guest
Posts: n/a
 
      10-29-2007, 02:59 AM
Allan Adler <(E-Mail Removed)> writes:

> I looked at Gilluwe's book, The Undocumented PC, to inform myself about
> int 0x15. It has it, but all instances of it in the code I quoted have
> AH=0x53 and that particular case is not discussed in Gilluwe's book.
> Where would I read about it?


I found a document online entitled EBIOS-UM.PDF which has some information.
With AH=0x53, int 0x15 is just the Advanced Power Management (APM) service.
Some details of it are provided, based on the value in AL. That should be
adequate to make sense of the code for power off that I quoted.

The question about what exactly I have to do to a floppy bootsector to run
just that code remains.
--
Ignorantly,
Allan Adler <(E-Mail Removed)>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
 
Reply With Quote
 
Arno Wagner
Guest
Posts: n/a
 
      10-29-2007, 03:17 AM
Previously Allan Adler <(E-Mail Removed)> wrote:
> Arno Wagner <(E-Mail Removed)> writes:


>> Previously Allan Adler <(E-Mail Removed)> wrote:
>> The next question is this: suppose I take a floppy disk and write this
>> > code to the beginning of the boot sector and then set the PC to boot from
>> > the floppy and boot. Will the machine start up, run through POST and then
>> > shut itself off, assuming it has the APM support?

>>
>> It should, as the boot code in the boot-sector is justloaded into
>> RAM and then control is given to it. Hoiwever just writing it there
>> is not enough. You need to give the bootsector a correct checksum
>> in addition, or it will not be booted. May also need other things
>> to be accepted by the BIOS. Easisest thing yould probably be to
>> modify exiting boot code.


> Thanks for the caveats. Where can I find a complete list of conditions
> that a bootsesctor has to satisfy to be loadable?


Hmm. Come to think of it, discussion of boot-sector virsuses
would probably be the easiest source. After all that is the
predominat misuse of bootsectors. I have analysed one of these
ages ago.

Ok, looking this up, it seems there actually does not need to
be a checksum. Having 0xAA55 in the last word seems to be enough.
Also it seems everything else is optional. The traditional geometry
information is not stored at the beginning, but rather "jumped over"
by a jump at the beginning of the bootsector. That likely menas it
can be completely omitted.

I also found this neat example here:

http://gok.customer.netspace.net.au/resources/

UNIOS at the top. Seems this is a "Hello, World" for the
bootsector. It has the 0xAA55 at the end, but no other
special form. Should be a good starting point!

> I looked at Gilluwe's book, The Undocumented PC, to inform myself about
> int 0x15. It has it, but all instances of it in the code I quoted have
> AH=0x53 and that particular case is not discussed in Gilluwe's book.
> Where would I read about it?


First, you could just try it and see what it does.

Here is an example of its usage:
http://syslinux.zytor.com/archives/2...er/005883.html

It seems this is APM. A specification for the APM BIOS is available
here:

http://www.microsoft.com/whdc/archive/amp_12.mspx

It seems to kave the information you need, but since it is RTF and
I currently have OpenOffice uninstalled, I can only read it
via rtf2latex, which garbles it pretty bad. But there are
calls with AH-0x53 dicumented in there.

Arno
 
Reply With Quote
 
Allan Adler
Guest
Posts: n/a
 
      10-30-2007, 03:59 AM
Arno Wagner <(E-Mail Removed)> writes:

> Previously Allan Adler <(E-Mail Removed)> wrote:
> > Where can I find a complete list of conditions
> > that a bootsesctor has to satisfy to be loadable?


> it seems there actually does not need to be a checksum. Having 0xAA55 in the
> last word seems to be enough. Also it seems everything else is optional. The
> traditional geometry information is not stored at the beginning, but rather
> "jumped over" by a jump at the beginning of the bootsector. That likely
> means it can be completely omitted.


Sounds that way. Thanks for all the helpful information in your posting.

There is an interrupt mentioned in Gilluwe in which 0xAA55 is important.
I'll take another look at it.

> I also found this neat example here:
> http://gok.customer.netspace.net.au/resources/
> UNIOS at the top. Seems this is a "Hello, World" for the
> bootsector. It has the 0xAA55 at the end, but no other
> special form. Should be a good starting point!


Yes, that example is very illuminating. The 0xAA55 is in a particular place,
namely byte 511, not at the end of the actual code. Also, the Makefile
contains all details of how to create the bootsector and write it to
the floppy.

> > I looked at Gilluwe's book, The Undocumented PC, to inform myself about
> > int 0x15. It has it, but all instances of it in the code I quoted have
> > AH=0x53 and that particular case is not discussed in Gilluwe's book.
> > Where would I read about it?

>
> First, you could just try it and see what it does.


I could but I don't know the effects of doing it wrong, which might include
reformatting the HD.

> Here is an example of its usage:
> http://syslinux.zytor.com/archives/2...er/005883.html
>
> It seems this is APM. A specification for the APM BIOS is available
> here:
> http://www.microsoft.com/whdc/archive/amp_12.mspx
> It seems to kave the information you need, but since it is RTF and
> I currently have OpenOffice uninstalled, I can only read it
> via rtf2latex, which garbles it pretty bad. But there are
> calls with AH-0x53 dicumented in there.


My browser showed enough of the page to tell me what the title of the
document is. I can't read rtf either but I googled
acpi pdf
and pdf versions came right up, e.g.
http://www.acpi.info/DOWNLOADS/ACPIspec30.pdf
--
Ignorantly,
Allan Adler <(E-Mail Removed)>
* Disclaimer: I am a guest and *not* a member of the MIT CSAIL. My actions and
* comments do not reflect in any way on MIT. Also, I am nowhere near Boston.
 
Reply With Quote
 
J de Boyne Pollard
Guest
Posts: n/a
 
      10-30-2007, 11:48 AM
AW> The traditional geometry information is not stored at
AW> the beginning, but rather "jumped over" by a jump
AW> at the beginning of the bootsector. That likely
AW> menas it can be completely omitted.

The "traditional geometry information" are an OEM Name field and a
BIOS Parameter Block, which latter contains more than just geometry
information. Omit the OEM Name field, or use your own name in it, and
many operating systems will make assumptions about the filesystem
format that are likely to be erroneous. Omit the BPB and there is a
risk that Windows NT version 5 will decide that the volume is
corrupt.

<URL:http://homepages.tesco.net./~J.deBoy...A/volume-boot-
block-oem-name-field.html>
<URL:http://homepages.tesco.net./~J.deBoy...ios-parameter-
block.html>
<URL:http://homepages.tesco.net./~J.deBoy...A/determining-
filesystem-type.html#PartitionTypes> (see the discussion for MBR type
0x0A)

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
420r Power-up issue - will only come up when keyboard power buttoncontinually held down. David Tudor Sun Hardware 0 01-11-2012 12:02 PM
Laptop fell, now power-up goes to instant power-down; any hope? Newbie Supreme Laptops 4 05-08-2007 03:10 AM
KG7-RAID or Power Supply Problem, computer shuts down few second after power up. Please Help! B Hardware 0 01-22-2004 12:46 AM
UPDATE: NF7-S won't power-up after power-down eNo Abit 1 09-11-2003 05:36 PM
K7SEM doesn't power down with power switch Roger Blake ECS 3 07-03-2003 07:16 AM


All times are GMT. The time now is 07:08 AM.


Welcome!
Welcome to Motherboard Point
 

Advertisment