Annotation of Net2/arch/i386/stand/wdbootblk.c, revision 1.1.1.2

1.1       root        1: /*-
                      2:  * Copyright (c) 1990 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * William Jolitz.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  *
                     36:  *     @(#)wdbootblk.c 7.1 (Berkeley) 4/28/91
                     37:  */
                     38: 
                     39: /*
                     40:  * wdbootblk.s:
                     41:  *     Written 7/6/90 by William F. Jolitz
                     42:  *     Initial block boot for AT/386 with typical Western Digital
                     43:  *     WD 1002-WA2 (or upwards compatable). Works either as
                     44:  *     first and sole partition bootstrap, or as loaded by a
                     45:  *     earlier BIOS boot when on an inner partition of the disk.
                     46:  *
                     47:  *     Goal is to read in sucessive 7.5Kbytes of bootstrap to
                     48:  *     execute.
                     49:  *
                     50:  *     No attempt is made to handle disk errors.
                     51:  */
                     52: #include "i386/isa/isa.h"
                     53: #include "i386/isa/wdreg.h"
1.1.1.2 ! root       54: #define        NOP     inb $0x84,%al
1.1       root       55: #define BIOSRELOC      0x7c00
1.1.1.2 ! root       56: #define start          RELOC+0x400
1.1       root       57: 
                     58:        /* step 0 force descriptors to bottom of address space */
1.1.1.2 ! root       59:        
        !            60:        cli
        !            61:        .byte 0xb8,0x30,0x00    /* mov $0x30,%ax */
        !            62:        mov %ax, %ss
        !            63:        .byte 0xbc,0x00,0x01    /* mov $0x100,%sp */
1.1       root       64: 
                     65:        xorl    %eax,%eax
                     66:        movl    %ax,%ds
                     67:        movl    %ax,%es
                     68: 
1.1.1.2 ! root       69:        /* obtain BIOS parameters for hard disk XXX */
        !            70:        movb    $0x9f,%ah        /* write to 0x9ff00  XXX */
        !            71:        movb    $0xf0,%al
        !            72:        mov     %ax,%es
        !            73:        xor     %edi,%edi
        !            74: 
        !            75:        .byte 0xf, 0xb4, 0x36 ; .word  0x41*4   /* lfs 0x41*4, %si */
        !            76:        xorb    %ch,%ch
        !            77:        movb    $0x10,%cl
        !            78:        fs
        !            79:        rep
        !            80:        movsb
        !            81: 
        !            82:        .byte 0xf, 0xb4, 0x36 ; .word  0x46*4   /* lfs 0x46*4, %si */
        !            83:        xorb    %ch,%ch
        !            84:        movb    $0x10,%cl
        !            85:        fs
        !            86:        rep
        !            87:        movsb
        !            88: 
        !            89:        xorl    %eax,%eax
        !            90:        movl    %ax,%es
        !            91: 
1.1       root       92:        /* step 1 load new descriptor table */
                     93: 
1.1.1.2 ! root       94:        .byte 0x3E,0x0F,1,0x16
        !            95:        .word   BIOSRELOC+0x6e  #GDTptr
1.1       root       96:        # word aword cs lgdt GDTptr
                     97: 
                     98:        /* step 2 turn on protected mode */
                     99: 
                    100:        smsw    %ax
                    101:        orb     $1,%al
                    102:        lmsw    %ax
                    103:        jmp     1f
                    104:        nop
                    105: 
                    106:        /* step 3  reload segment descriptors */
                    107: 
                    108: 1:
                    109:        xorl    %eax,%eax
                    110:        movb    $0x10,%al
                    111:        movl    %ax,%ds
                    112:        movl    %ax,%es
                    113:        movl    %ax,%ss
                    114:        word
1.1.1.2 ! root      115:        ljmp    $0x8,$ BIOSRELOC+0x74   /* would be nice if .-RELOC+0x7c00 worked */
1.1       root      116: 
                    117:  /* Global Descriptor Table contains three descriptors:
                    118:   * 0x00: Null: not used
                    119:   * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
                    120:   * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
                    121:   *            (overlays code)
                    122:   */
                    123: GDT:
                    124: NullDesc:      .word   0,0,0,0 # null descriptor - not used
                    125: CodeDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    126:        .byte   0,0,0   # base at 0: (bits 23:0)
                    127:        .byte   0x9f    # present/priv level 0/code/conforming/readable
                    128:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    129:        .byte   0       # base at 0: (bits 31:24)
                    130: DataDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    131:        .byte   0,0,0   # base at 0: (bits 23:0)
                    132:        .byte   0x93    # present/priv level 0/data/expand-up/writeable
                    133:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    134:        .byte   0       # base at 0: (bits 31:24)
                    135: 
                    136: /* Global Descriptor Table pointer
                    137:  *  contains 6-byte pointer information for LGDT
                    138:  */
                    139: GDTptr:        .word   0x17    # limit to three 8 byte selectors(null,code,data)
1.1.1.2 ! root      140:        .long   BIOSRELOC+0x56  # GDT -- arrgh, gas again!
1.1       root      141: 
                    142:        /* step 4 relocate to final bootstrap address. */
                    143: reloc:
                    144:        movl    $ BIOSRELOC,%esi
                    145:        movl    $ RELOC,%edi
                    146:        movl    $512,%ecx
                    147:        rep
                    148:        movsb
1.1.1.2 ! root      149:        movl    $0xa0000, %esp
1.1       root      150:        pushl   $dodisk
                    151:        ret
                    152: 
                    153:        /* step 5 load remaining 15 sectors off disk */
                    154: dodisk:
                    155:        movl    $ IO_WD1+wd_seccnt,%edx
                    156:        movb    $ 15,%al
                    157:        outb    %al,%dx
                    158:        NOP
                    159:        movl    $ IO_WD1+wd_sector,%edx
                    160:        movb    $ 2,%al
                    161:        outb    %al,%dx
                    162:        NOP
                    163:        #outb(wdc+wd_cyl_lo, (cyloffset & 0xff));
                    164:        #outb(wdc+wd_cyl_hi, (cyloffset >> 8));
                    165:        #outb(wdc+wd_sdh, WDSD_IBM | (unit << 4));
                    166: 
                    167:        movl    $ IO_WD1+wd_command,%edx
                    168:        movb    $ WDCC_READ,%al
                    169:        outb    %al,%dx
                    170:        NOP
                    171:        cld
                    172: 
                    173:        /* check to make sure controller is not busy and we have data ready */
                    174: readblk:
                    175:        movl    $ IO_WD1+wd_status,%edx
                    176:        NOP
1.1.1.2 ! root      177:        inb     %dx,%al
1.1       root      178:        testb   $ WDCS_BUSY,%al
                    179:        jnz readblk
                    180:        testb   $ WDCS_DRQ,%al
                    181:        jz readblk
                    182: 
                    183:        /* read a block into final position in memory */
                    184: 
                    185:        movl    $ IO_WD1+wd_data,%edx
                    186:        movl    $ 256,%ecx
                    187:        .byte 0x66,0xf2,0x6d    # rep insw
                    188:        NOP
                    189: 
                    190:        /* need more blocks to be read in? */
                    191: 
                    192:        cmpl    $ RELOC+16*512-1,%edi
                    193:        jl      readblk
                    194: 
                    195:        /* for clever bootstrap, dig out boot unit and cylinder */
                    196:        
                    197:        movl    $ IO_WD1+wd_cyl_lo,%edx
                    198:        inb     %dx,%al
                    199:        xorl    %ecx,%ecx
                    200:        movb    %al,%cl
                    201:        incl    %edx
                    202:        NOP
1.1.1.2 ! root      203:        inb     %dx,%al         /* cyl_hi */
1.1       root      204:        movb    %al,%ch
                    205:        pushl   %ecx            /* cyloffset */
                    206: 
                    207:        incl    %edx
                    208:        xorl    %eax,%eax
1.1.1.2 ! root      209:        NOP
1.1       root      210:        inb     %dx,%al         /* sdh */
                    211:        andb    $0x10,%al       /* isolate unit # bit */
                    212:        shrb    $4,%al
                    213:        pushl   %eax            /* unit */
                    214: 
                    215:        /* wd controller is major device 0 */
                    216:        xorl    %eax,%eax
                    217:        pushl   %eax            /* bootdev */
                    218: 
                    219:        /* sorry, no flags at this point! */
                    220: 
1.1.1.2 ! root      221:        movl    $ start, %eax
        !           222:        call    %eax /* main (dev, unit, offset) */
1.1       root      223: 
                    224: ebootblkcode:
                    225: 
                    226:        /* remaining space usable for a disk label */
                    227:        
1.1.1.2 ! root      228:        .org    0x1fe
1.1       root      229:        .word   0xaa55          /* signature -- used by BIOS ROM */
                    230: 
                    231: ebootblk:                      /* MUST BE EXACTLY 0x200 BIG FOR SURE */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.