1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

power down

Discussion in 'PC Hardware' started by Allan Adler, Oct 19, 2007.

  1. Allan Adler

    Allan Adler Guest

    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 <>
    * 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.
     
    Allan Adler, Oct 19, 2007
    #1
    1. Advertising

  2. Allan Adler

    Keith Beef Guest

    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.
     
    Keith Beef, Oct 25, 2007
    #2
    1. Advertising

  3. 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.
     
    J de Boyne Pollard, Oct 25, 2007
    #3
  4. Allan Adler

    Allan Adler Guest

    J de Boyne Pollard <> 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 <>
    * 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.
     
    Allan Adler, Oct 28, 2007
    #4
  5. Allan Adler

    Arno Wagner Guest

    Previously Allan Adler <> wrote:
    > J de Boyne Pollard <> 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
     
    Arno Wagner, Oct 28, 2007
    #5
  6. Allan Adler

    Allan Adler Guest

    Arno Wagner <> writes:

    > Previously Allan Adler <> 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 <>
    * 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.
     
    Allan Adler, Oct 29, 2007
    #6
  7. Allan Adler

    Allan Adler Guest

    Allan Adler <> 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 <>
    * 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.
     
    Allan Adler, Oct 29, 2007
    #7
  8. Allan Adler

    Arno Wagner Guest

    Previously Allan Adler <> wrote:
    > Arno Wagner <> writes:


    >> Previously Allan Adler <> 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/2005-September/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
     
    Arno Wagner, Oct 29, 2007
    #8
  9. Allan Adler

    Allan Adler Guest

    Arno Wagner <> writes:

    > Previously Allan Adler <> 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/2005-September/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 <>
    * 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.
     
    Allan Adler, Oct 30, 2007
    #9
  10. 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.deBoynePollard/FGA/volume-boot-
    block-oem-name-field.html>
    <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/bios-parameter-
    block.html>
    <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/determining-
    filesystem-type.html#PartitionTypes> (see the discussion for MBR type
    0x0A)
     
    J de Boyne Pollard, Oct 30, 2007
    #10
  11. Windows FASTFAT code is available in the WDK, but nevertheless I would not
    omit anything (including the x86 JMP opcode and 0x55 aa at the end) from the
    FAT boot sector.

    --
    Maxim Shatskih, Windows DDK MVP
    StorageCraft Corporation

    http://www.storagecraft.com

    "J de Boyne Pollard" <> wrote in message
    news:...
    > 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.deBoynePollard/FGA/volume-boot-
    > block-oem-name-field.html>
    > <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/bios-parameter-
    > block.html>
    > <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/determining-
    > filesystem-type.html#PartitionTypes> (see the discussion for MBR type
    > 0x0A)
    >
     
    Maxim S. Shatskih, Oct 30, 2007
    #11
  12. Allan Adler

    Arno Wagner Guest

    In comp.sys.ibm.pc.hardware.misc J de Boyne Pollard <> wrote:
    > 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.


    No OS is being booted here....

    Arno
     
    Arno Wagner, Oct 30, 2007
    #12
  13. Allan Adler

    Arno Wagner Guest

    In comp.sys.ibm.pc.hardware.misc Maxim S. Shatskih <> wrote:
    > Windows FASTFAT code is available in the WDK, but nevertheless I would not
    > omit anything (including the x86 JMP opcode and 0x55 aa at the end) from the
    > FAT boot sector.


    No OS is being booted here...

    Arno
     
    Arno Wagner, Oct 30, 2007
    #13
  14. JdeBP> The "traditional geometry information" are an OEM
    JdeBP> Name field and a BIOS Parameter Block, which
    JdeBP> latter contains more than just geometry information.
    JdeBP> Omit the OEM Name field, or use your own name in
    JdeBP> it, and many operating systems will make
    JdeBP> assumptions about the filesystem format that are
    JdeBP> likely to be erroneous. Omit the BPB and there
    JdeBP> is a risk that Windows NT version 5 will decide
    JdeBP> that the volume is corrupt.
    JdeBP>
    JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/volume-
    boot-block-oem-name-field.html>
    JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/bios-
    parameter-block.html>
    JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/
    determining-filesystem-type.html#PartitionTypes> (see the discussion
    for MBR type 0x0A)

    AW> No OS is being booted here....

    Wrong. The operating system used to run the tools used to develop the
    code is being booted, for one. You have no reason for believing that
    the disc will never be in a drive when an operating system is booted,
    or that it will never be accessed by any version of MS-DOS, PC-DOS, DR-
    DOS, OS/2, Windows NT, or Linux.
     
    J de Boyne Pollard, Oct 30, 2007
    #14
  15. Allan Adler

    Arno Wagner Guest

    In comp.sys.ibm.pc.hardware.misc J de Boyne Pollard <> wrote:
    > JdeBP> The "traditional geometry information" are an OEM
    > JdeBP> Name field and a BIOS Parameter Block, which
    > JdeBP> latter contains more than just geometry information.
    > JdeBP> Omit the OEM Name field, or use your own name in
    > JdeBP> it, and many operating systems will make
    > JdeBP> assumptions about the filesystem format that are
    > JdeBP> likely to be erroneous. Omit the BPB and there
    > JdeBP> is a risk that Windows NT version 5 will decide
    > JdeBP> that the volume is corrupt.
    > JdeBP>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/volume-
    > boot-block-oem-name-field.html>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/bios-
    > parameter-block.html>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/
    > determining-filesystem-type.html#PartitionTypes> (see the discussion
    > for MBR type 0x0A)


    > AW> No OS is being booted here....


    > Wrong. The operating system used to run the tools used to develop the
    > code is being booted, for one. You have no reason for believing that
    > the disc will never be in a drive when an operating system is booted,
    > or that it will never be accessed by any version of MS-DOS, PC-DOS, DR-
    > DOS, OS/2, Windows NT, or Linux.


    The intended purpose of these modification is not for booting an OS.
    Also modern OSes do not execute the bootsector of an inserted
    disk. And in addition, it does not matter at all, since it is not a
    problem if an OS thinks this disk is unformatted.

    Instructions before you cry "Wrong!":

    1. Read what the discussion is about
    2. Make sure you understand what the discussion is about
    3. If still appropriate, cry "Wrong!" or say seomething more
    polite.

    Arno
     
    Arno Wagner, Oct 30, 2007
    #15
  16. Allan Adler

    Guest

    On Oct 30, 3:02 pm, J de Boyne Pollard <>
    wrote:
    > JdeBP> The "traditional geometry information" are an OEM
    > JdeBP> Name field and a BIOS Parameter Block, which
    > JdeBP> latter contains more than just geometry information.
    > JdeBP> Omit the OEM Name field, or use your own name in
    > JdeBP> it, and many operating systems will make
    > JdeBP> assumptions about the filesystem format that are
    > JdeBP> likely to be erroneous. Omit the BPB and there
    > JdeBP> is a risk that Windows NT version 5 will decide
    > JdeBP> that the volume is corrupt.
    > JdeBP>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/volume-
    > boot-block-oem-name-field.html>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/bios-
    > parameter-block.html>
    > JdeBP> <URL:http://homepages.tesco.net./~J.deBoynePollard/FGA/
    > determining-filesystem-type.html#PartitionTypes> (see the discussion
    > for MBR type 0x0A)
    >
    > AW> No OS is being booted here....
    >
    > Wrong. The operating system used to run the tools used to develop the
    > code is being booted, for one. You have no reason for believing that
    > the disc will never be in a drive when an operating system is booted,
    > or that it will never be accessed by any version of MS-DOS, PC-DOS, DR-
    > DOS, OS/2, Windows NT, or Linux.


    The simple workaround is to write the bootstrap to a reformatted
    floppy.

    For the BPB, it can be zero..

    ;8:39 PM 10/20/2004 modified for nasm, bootstat.asm
    ;
    ;nasm
    ;-f bin -l bootstat.lst -o bootstat.bin bootstat.nsm
    ; [map all bootstat.map]
    ;
    ;;Rombios loads this to 0000:7C00, DL==boot drv.
    ;
    ; C:\DEBUG.EXE BOOTSTAT.BIN ;writes a bootsector
    ; -W 100 0 0 1 ;to a formatted diskette
    ; -Q ;-note- may need to reformat the
    ; C:\ ; test diskette first if a prior
    ; ; bootstrap was installed.

    lf EQU 00AH ;ASCII LINE FEED
    cr EQU 00DH ;ASCII CARRIAGE RETURN

    [BITS 16]
    section .text ;;.cseg
    ;
    jmp short start
    nop
    myname0 db 'BOOTSTATVAL',0 ;;trashed by vol checker
    ;;
    TIMES 3Eh-($-$$) db 0 ;space for DPB, none implemented.
    ;;
    myname db 'BOOTSTATVAL',0 ;;
    start:
    ....
    If read by win98 a msg box displays:
    'The disk in drive A: is not formatted. Do you want to format it now?'
    Just say no if you don't what to.

    Nasm version for the Original Poster:

    ;;PAGEWIDTH 80
    ;;TITLE 'DIAGNOSTIC BOOTSTRAP'
    [MAP BOOTSTAT.MAP]
    ;;===================================================55
    ;; Program Name: bootstat.nsm By:
    ;; Last Update: 03 JUN 2006 Init: 20 OCT 2004
    ;; Version: 0.0.1
    ;; Desc: Dump Initial 32 bit Register Values
    ;;
    ;; SubrLst: //Code Labels meant for Global Use.
    ;; EndSubrLst:
    ;;
    ;; ExternLst: //Code Labels refer to another module.
    ;; EndExternLst:
    ;;
    ;; GlobalLst: //Data Labels meant for Global Use.
    ;; EndGlobalLst:
    ;;
    ;; Reqd NFN: //List of Included Function Libs.
    ;; EndReqd NFN:
    ;;===================================================55
    ;;---------------------------------------------------55
    ;8:39 PM 10/20/2004 modified for nasm, bootstat.asm
    ;
    ;nasm
    ;-f bin -l bootstat.lst -o bootstat.bin bootstat.nsm
    ; [map all bootstat.map]
    ;
    ;;Rombios loads this to 0000:7C00, DL==boot drv.
    ;
    ; C:\DEBUG.EXE BOOTSTAT.BIN ;writes a bootsector
    ; -W 100 0 0 1 ;to a formatted diskette
    ; -Q ;-note- may need to reformat the
    ; C:\ ; test diskette first if a prior
    ; ; bootstrap was installed.

    lf EQU 00AH ;ASCII LINE FEED
    cr EQU 00DH ;ASCII CARRIAGE RETURN

    [BITS 16]
    section .text ;;.cseg
    ;
    jmp short start
    nop
    myname0 db 'BOOTSTATVAL',0 ;;trashed by vol checker
    ;;
    TIMES 3Eh-($-$$) db 0 ;space for DPB, none implemented.
    ;;
    myname db 'BOOTSTATVAL',0 ;;
    start:
    cli ;;
    mov [oeax+7C00h],EAX ;add bias of runtime offset
    mov [oebx+7C00h],EBX ; so the correct memory
    mov [oecx+7C00h],ECX ; reference is made by the
    mov [oedx+7C00h],EDX ; assembler. Later in code
    mov [oesi+7C00h],ESI ; resegment DS:=0 to 07C0h
    mov [oedi+7C00h],EDI ; so that the bias is 0h.
    mov [oebp+7C00h],EBP
    mov [oesp+7C00h],ESP
    mov AX,ES
    mov [oes+7C00h],AX
    mov AX,DS
    mov [ods+7C00h],AX
    mov AX,CS ; cs:=0
    mov DS,AX ; set ds := 0
    mov [ocs+7C00h],AX
    mov BX,SS
    mov [oss+7C00h],BX
    mov BX,FS
    mov [ofs+7C00h],BX
    mov BX,GS
    mov [ogs+7C00h],BX
    ;; test stack location by seeding value.
    ;; mov dx,1234h
    ;; push dx ;;!!warning: unbalanced stk!!
    mov SS,AX
    mov SP,7C00h
    sti ;; enable maskable interrupts
    ;; ds:si source element, err msg.
    ;; Add Bias of load offset.
    ;;
    mov si,msg1+7c00h
    cld
    lodsb ;; load AL with byte of str.
    call print_str_zr
    call newline
    call display_regs

    ;;--------------------
    ;;halt::
    stophere:
    xor ah,ah
    int 16h ;; await keypress
    int 19h ;; warm boot, ctrl-alt-del
    jmp stophere ;; should not execute.

    ;;--------------------
    ;; Subroutines.
    ;;--------------------
    ;; Print String ZR terminated.
    ;; SI -> src str
    print_str_zr:
    call putc ;;console_out 1 character.
    lodsb
    test al,al ;; ck for null termination
    jnz print_str_zr ;; loop thru msg...
    ;; and then ret.
    ret
    ;;--------------------
    ;;
    put_space:
    push ax
    mov al,20h
    call putc
    pop ax
    ret
    ;;--------------------
    ;; int10h ah=0Eh, al=chr
    putc:
    push ax
    push bx
    push dx

    mov bx,0007h ;;mode
    mov ah,0Eh ;;tty
    int 10h

    pop dx
    pop bx
    pop ax
    ret
    ;--------------------
    newline:
    push ax
    mov al, 13
    call putc
    mov al, 10
    call putc
    pop ax
    ret
    ;--------------------
    ;;-------------------
    showax: ;;display AX val as hex
    push cx
    mov cx,4
    jmp eloop
    showeax: ;;display EAX val as hex
    push cx
    mov cx,8
    eloop:
    rol eax, 4
    push eax
    and al, 0Fh
    cmp al, 0Ah
    sbb al, 69h
    das
    call putc
    pop eax
    loop eloop
    pop cx
    ret
    ;-------------------
    ;-------------------
    display_regs:
    mov ax,[word ocs+7C00h]
    call showax
    call put_space
    mov ax,[word ods+7C00h]
    call showax
    call put_space
    mov ax,[word oes+7C00h]
    call showax
    call put_space
    mov ax,[word oss+7C00h]
    call showax
    call put_space
    mov ax,[word ofs+7C00h]
    call showax
    call put_space
    mov ax,[word ogs+7C00h]
    call showax
    call newline
    ;;Extended
    mov eax,[dword oeax+7C00h]
    call showeax
    call put_space
    mov eax,[dword oebx+7C00h]
    call showeax
    call put_space
    mov eax,[dword oecx+7C00h]
    call showeax
    call put_space
    mov eax,[dword oedx+7C00h]
    call showeax
    call put_space
    mov eax,[dword oesi+7C00h]
    call showeax
    call put_space
    mov eax,[dword oedi+7C00h]
    call showeax
    call put_space
    mov eax,[dword oesp+7C00h]
    call showeax
    call put_space
    mov eax,[dword oebp+7C00h]
    call showeax
    call put_space
    call newline
    ret
    ;-------------------
    ;-------------------
    ; Data ;small model
    testd dw 1234h
    oesp dd 0
    oebp dd 0
    oeax dd 0
    oebx dd 0
    oecx dd 0
    oedx dd 0
    oesi dd 0
    oedi dd 0
    ocs dw 0
    ods dw 0
    oss dw 0
    oes dw 0
    ogs dw 0
    ofs dw 0

    msg1 db cr,lf,' BootStat V.0.0.1 -nasm bld.',cr,lf,0
    TIMES 510-($-$$) DB 0
    dw 0xAA55

    ;--eof--

    Actually, ending the boot sector with 0xAA55 is not required for a
    floppy boot sector. Remove it and try it for yourself.

    Steve
     
    , Oct 30, 2007
    #16
  17. Allan Adler

    Allan Adler Guest

    Allan Adler <> writes:

    > 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 found Krishnakumar's 3-part article on writing your own toy operating
    system, which is quite lucid.
    --
    Ignorantly,
    Allan Adler <>
    * 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.
     
    Allan Adler, Oct 30, 2007
    #17
  18. Allan Adler

    Allan Adler Guest

    writes:

    > Actually, ending the boot sector with 0xAA55 is not required for a
    > floppy boot sector. Remove it and try it for yourself.


    Thanks for this observation and for the programs. I'd like to see this
    fact documented before trying it. Even though the machine is expendable,
    it would be a nuisance to have to reinstall the stuff that is presently
    on it, in case anything went wrong.

    I was able to find some of the int 0x15 functions in ebios-um.pdf but
    not all of them. One that is used in the btmgr code is int 0x15 with
    AX = 5380. Googling
    int 0x15 AX=5380
    led me to a pdf file for the PenKey 6100 computer which does discuss
    int 0x15 with AX=5380, but requires BH=0x1D, whereas the btmgr code
    has BH=0x8c.

    As nearly as I can tell, the 600 or so page pdf file ACPIspec30.pdf
    has a lot of information about the APM system itself but nothing about
    the individual interrupts. If I'm wrong about that, I'd like to know where
    to find this information in it.
    --
    Ignorantly,
    Allan Adler <>
    * 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.
     
    Allan Adler, Oct 31, 2007
    #18
  19. AW> No OS is being booted here....

    JdeBP> Wrong. The operating system used to run the tools used
    JdeBP> to develop the code is being booted, for one. You have
    JdeBP> no reason for believing that the disc will never be in a
    JdeBP> drive when an operating system is booted, or that it will
    JdeBP> never be accessed by any version of MS-DOS, PC-DOS,
    JdeBP> DR-DOS, OS/2, Windows NT, or Linux.

    AW> The intended purpose of these modification is not for booting an
    OS.

    Irrelevant. The cautions still apply.

    AW> Also modern OSes do not execute the bootsector of an
    AW> inserted disk.

    Irrelevant. The operating system will read the OEM Name and the BPB
    and act upon them.

    AW> And in addition, it does not matter at all, since it is not a
    AW> problem if an OS thinks this disk is unformatted.

    You didn't read what was written. The operating system will decide
    that the volume is _corrupt_.

    AW> Instructions before you cry "Wrong!":
    AW>
    AW> 1. Read what the discussion is about
    AW> 2. Make sure you understand what the discussion is about
    AW> 3. If still appropriate, cry "Wrong!"

    Indeed. I suggest that you follow your own instructions. You haven't
    thus far.
     
    J de Boyne Pollard, Oct 31, 2007
    #19
  20. Allan Adler

    Arno Wagner Guest

    In comp.sys.ibm.pc.hardware.misc J de Boyne Pollard <> wrote:
    > AW> No OS is being booted here....


    > JdeBP> Wrong. The operating system used to run the tools used
    > JdeBP> to develop the code is being booted, for one. You have
    > JdeBP> no reason for believing that the disc will never be in a
    > JdeBP> drive when an operating system is booted, or that it will
    > JdeBP> never be accessed by any version of MS-DOS, PC-DOS,
    > JdeBP> DR-DOS, OS/2, Windows NT, or Linux.


    > AW> The intended purpose of these modification is not for booting an
    > OS.


    > Irrelevant. The cautions still apply.


    > AW> Also modern OSes do not execute the bootsector of an
    > AW> inserted disk.


    > Irrelevant. The operating system will read the OEM Name and the BPB
    > and act upon them.


    > AW> And in addition, it does not matter at all, since it is not a
    > AW> problem if an OS thinks this disk is unformatted.


    > You didn't read what was written. The operating system will decide
    > that the volume is _corrupt_.



    Again, so what? This is not an issue and it will have no negative
    impact. What is your fixation with the OS having to be able to
    read the volume information?


    > AW> Instructions before you cry "Wrong!":
    > AW>
    > AW> 1. Read what the discussion is about
    > AW> 2. Make sure you understand what the discussion is about
    > AW> 3. If still appropriate, cry "Wrong!"


    > Indeed. I suggest that you follow your own instructions. You haven't
    > thus far.



    True, I have not cried "Wrong!".

    Arno
     
    Arno Wagner, Oct 31, 2007
    #20
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eNo
    Replies:
    1
    Views:
    306
  2. Roger Blake
    Replies:
    3
    Views:
    932
    Ernie
    Jul 3, 2003
  3. B
    Replies:
    0
    Views:
    399
  4. Newbie Supreme
    Replies:
    4
    Views:
    430
  5. David Tudor
    Replies:
    0
    Views:
    412
    David Tudor
    Jan 11, 2012
Loading...

Share This Page