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

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"
                     54: #define        NOP     jmp 1f ; nop ; 1:
                     55: #define BIOSRELOC      0x7c00
                     56: #define start          0x70400
                     57: 
                     58:        /* step 0 force descriptors to bottom of address space */
                     59: 
                     60:        .byte 0xfa,0xb8,0x30,0x00,0x8e,0xd0,0xbc,0x00,0x01 #ll fb
                     61: 
                     62:        xorl    %eax,%eax
                     63:        movl    %ax,%ds
                     64:        movl    %ax,%es
                     65: 
                     66:        /* step 1 load new descriptor table */
                     67: 
                     68:        .byte 0x2E,0x0F,1,0x16
                     69:        .word   BIOSRELOC+0x4a  #GDTptr
                     70:        # word aword cs lgdt GDTptr
                     71: 
                     72:        /* step 2 turn on protected mode */
                     73: 
                     74:        smsw    %ax
                     75:        orb     $1,%al
                     76:        lmsw    %ax
                     77:        jmp     1f
                     78:        nop
                     79: 
                     80:        /* step 3  reload segment descriptors */
                     81: 
                     82: 1:
                     83:        xorl    %eax,%eax
                     84:        movb    $0x10,%al
                     85:        movl    %ax,%ds
                     86:        movl    %ax,%es
                     87:        movl    %ax,%ss
                     88:        word
                     89:        ljmp    $0x8,$ BIOSRELOC+0x50   /* would be nice if .-RELOC+0x7c00 worked */
                     90: 
                     91:  /* Global Descriptor Table contains three descriptors:
                     92:   * 0x00: Null: not used
                     93:   * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
                     94:   * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
                     95:   *            (overlays code)
                     96:   */
                     97: GDT:
                     98: NullDesc:      .word   0,0,0,0 # null descriptor - not used
                     99: CodeDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    100:        .byte   0,0,0   # base at 0: (bits 23:0)
                    101:        .byte   0x9f    # present/priv level 0/code/conforming/readable
                    102:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    103:        .byte   0       # base at 0: (bits 31:24)
                    104: DataDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    105:        .byte   0,0,0   # base at 0: (bits 23:0)
                    106:        .byte   0x93    # present/priv level 0/data/expand-up/writeable
                    107:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    108:        .byte   0       # base at 0: (bits 31:24)
                    109: 
                    110: /* Global Descriptor Table pointer
                    111:  *  contains 6-byte pointer information for LGDT
                    112:  */
                    113: GDTptr:        .word   0x17    # limit to three 8 byte selectors(null,code,data)
                    114:        .long   BIOSRELOC+0x32  # GDT -- arrgh, gas again!
                    115: 
                    116:        /* step 4 relocate to final bootstrap address. */
                    117: reloc:
                    118:        movl    $ BIOSRELOC,%esi
                    119:        movl    $ RELOC,%edi
                    120:        movl    $512,%ecx
                    121:        rep
                    122:        movsb
                    123:  movl $0x60000,%esp
                    124:        pushl   $dodisk
                    125:        ret
                    126: 
                    127:        /* step 5 load remaining 15 sectors off disk */
                    128: dodisk:
                    129:        movl    $ IO_WD1+wd_seccnt,%edx
                    130:        movb    $ 15,%al
                    131:        outb    %al,%dx
                    132:        NOP
                    133:        movl    $ IO_WD1+wd_sector,%edx
                    134:        movb    $ 2,%al
                    135:        outb    %al,%dx
                    136:        NOP
                    137:        #outb(wdc+wd_cyl_lo, (cyloffset & 0xff));
                    138:        #outb(wdc+wd_cyl_hi, (cyloffset >> 8));
                    139:        #outb(wdc+wd_sdh, WDSD_IBM | (unit << 4));
                    140: 
                    141:        movl    $ IO_WD1+wd_command,%edx
                    142:        movb    $ WDCC_READ,%al
                    143:        outb    %al,%dx
                    144:        NOP
                    145:        cld
                    146: 
                    147:        /* check to make sure controller is not busy and we have data ready */
                    148: readblk:
                    149:        movl    $ IO_WD1+wd_status,%edx
                    150:        inb     %dx,%al
                    151:        NOP
                    152:        testb   $ WDCS_BUSY,%al
                    153:        jnz readblk
                    154:        testb   $ WDCS_DRQ,%al
                    155:        jz readblk
                    156: 
                    157:        /* read a block into final position in memory */
                    158: 
                    159:        movl    $ IO_WD1+wd_data,%edx
                    160:        movl    $ 256,%ecx
                    161:        .byte 0x66,0xf2,0x6d    # rep insw
                    162:        NOP
                    163: 
                    164:        /* need more blocks to be read in? */
                    165: 
                    166:        cmpl    $ RELOC+16*512-1,%edi
                    167:        jl      readblk
                    168: 
                    169:        /* for clever bootstrap, dig out boot unit and cylinder */
                    170:        
                    171:        movl    $ IO_WD1+wd_cyl_lo,%edx
                    172:        inb     %dx,%al
                    173:        NOP
                    174:        xorl    %ecx,%ecx
                    175:        movb    %al,%cl
                    176:        incl    %edx
                    177:        inb     %dx,%al         /* cyl_hi */
                    178:        NOP
                    179:        movb    %al,%ch
                    180:        pushl   %ecx            /* cyloffset */
                    181: 
                    182:        incl    %edx
                    183:        xorl    %eax,%eax
                    184:        inb     %dx,%al         /* sdh */
                    185:        andb    $0x10,%al       /* isolate unit # bit */
                    186:        shrb    $4,%al
                    187:        pushl   %eax            /* unit */
                    188: 
                    189:        /* wd controller is major device 0 */
                    190:        xorl    %eax,%eax
                    191:        pushl   %eax            /* bootdev */
                    192: 
                    193:        /* sorry, no flags at this point! */
                    194: 
                    195:        pushl   $ start
                    196:        ret     /* main (dev, unit, offset) */
                    197: 
                    198: ebootblkcode:
                    199: 
                    200:        /* remaining space usable for a disk label */
                    201:        
                    202:        .space  510-223         /* would be nice if .space 512-2-. worked */
                    203:        .word   0xaa55          /* signature -- used by BIOS ROM */
                    204: 
                    205: 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.