Annotation of Net2/arch/i386/stand/fdbootblk.c, revision 1.1.1.5

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:  *
1.1.1.5 ! root       36:  *     from: @(#)fdbootblk.c   7.2 (Berkeley) 5/4/91
        !            37:  *     fdbootblk.c,v 1.4 1993/05/22 08:02:15 cgd Exp
1.1       root       38:  */
                     39: 
                     40: /*
                     41:  * fdbootblk.s:
                     42:  *     Written 10/6/90 by William F. Jolitz
                     43:  *     Initial block boot for AT/386 with typical stupid NEC controller
                     44:  *
                     45:  *     Goal is to read in sucessive 7.5Kbytes of bootstrap to
                     46:  *     execute.
                     47:  *
                     48:  *     No attempt is made to handle disk errors.
1.1.1.4   root       49:  *
                     50:  * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
                     51:  * --------------------         -----   ----------------------
                     52:  * CURRENT PATCH LEVEL:         1       00073
                     53:  * --------------------         -----   ----------------------
                     54:  *
                     55:  * 22 Jan 93   Frank Maclachlan        Fixed NOP's to read correct register
                     56:  *
1.1       root       57:  */
                     58: /*#include "/sys/i386/isa/isa.h"
                     59: #include "/sys/i386/isa/fdreg.h"*/
1.1.1.3   root       60: #define        NOP     inb     $0x84,%al
1.1       root       61: #define BIOSRELOC      0x7c00
1.1.1.3   root       62: #define        start   RELOC+0x400
1.1       root       63: 
1.1.1.3   root       64:        /* mumbo-jumbo to pacify DOS, in the hope of getting diskcopy to work */
                     65:        jmp 1f
1.1.1.5 ! root       66:        .asciz "NetBSD "
1.1.1.3   root       67:        .byte 1                 # sectors per allocation
                     68:        .word 15                # additional sectors for bootstrap
                     69:        .word 0                 # number of DOS fat sectors
                     70:        .word 0                 # number of DOS rootdir entries
                     71:        .byte 0xf0              # media descriptor
                     72:        .word 0                 # number of sectors per a DOS fat entry
                     73:        .word 18                # number of sectors per track
                     74:        .word 2                 # number of heads
                     75:        .long 0                 # number of hidden sectors
                     76:        .long 2880-18           # logical sectors per volume
                     77:        .byte 0                 # physical drive
                     78:        .byte 0x29              # ?
                     79:        .long 137               # binary id
                     80:        .ascii "Release 0.1"    # volume label
                     81:        .space 5
                     82: 1:
1.1       root       83:        /* step 0 force descriptors to bottom of address space */
1.1.1.3   root       84:        
                     85:        cli
                     86:        .byte 0xb8,0x30,0x00    /* mov $0x30,%ax */
                     87:        mov %ax, %ss
                     88:        .byte 0xbc,0x00,0x01    /* mov $0x100,%sp */
1.1       root       89: 
                     90:        xorl    %eax,%eax
                     91:        movl    %ax,%ds
                     92:        movl    %ax,%es
                     93: 
1.1.1.3   root       94:        /* obtain BIOS parameters for hard disk XXX */
                     95:        movb    $0x9f,%ah        /* write to 0x9ff00  XXX */
                     96:        movb    $0xf0,%al
                     97:        mov     %ax,%es
                     98:        xor     %edi,%edi
                     99: 
                    100:        .byte 0xf, 0xb4, 0x36 ; .word  0x41*4   /* lfs 0x41*4, %si */
                    101:        xorb    %ch,%ch
                    102:        movb    $0x10,%cl
                    103:        fs
                    104:        rep
                    105:        movsb
                    106: 
                    107:        .byte 0xf, 0xb4, 0x36 ; .word  0x46*4   /* lfs 0x46*4, %si */
                    108:        xorb    %ch,%ch
                    109:        movb    $0x10,%cl
                    110:        fs
                    111:        rep
                    112:        movsb
                    113: 
                    114:        xorl    %eax,%eax
                    115:        movl    %ax,%es
                    116: 
1.1       root      117:        /* step 1 load new descriptor table */
                    118: 
1.1.1.3   root      119:        .byte 0x2E,0x0F,1,0x16 /* word aword cs lgdt GDTptr */
                    120:        .word   BIOSRELOC+0xa4  #GDTptr
1.1       root      121: 
                    122:        /* step 2 turn on protected mode */
                    123: 
                    124:        smsw    %ax
                    125:        orb     $1,%al
                    126:        lmsw    %ax
                    127:        jmp     1f
                    128:        nop
                    129: 
                    130:        /* step 3  reload segment descriptors */
                    131: 
                    132:  1:
                    133:        xorl    %eax,%eax
                    134:        movb    $0x10,%al
                    135:        movl    %ax,%ds
                    136:        movl    %ax,%es
                    137:        movl    %ax,%ss
                    138:        word
1.1.1.3   root      139:        ljmp    $0x8,$ BIOSRELOC+0xb3   /* would be nice if .-RELOC+0x7c00 worked */
1.1       root      140: 
                    141:  /* Global Descriptor Table contains three descriptors:
                    142:   * 0x00: Null: not used
                    143:   * 0x08: Code: code segment starts at 0 and extents for 4 gigabytes
                    144:   * 0x10: Data: data segment starts at 0 and extends for 4 gigabytes
                    145:   *            (overlays code)
                    146:   */
                    147: GDT:
                    148: NullDesc:      .word   0,0,0,0 # null descriptor - not used
                    149: CodeDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    150:        .byte   0,0,0   # base at 0: (bits 23:0)
                    151:        .byte   0x9f    # present/priv level 0/code/conforming/readable
                    152:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    153:        .byte   0       # base at 0: (bits 31:24)
                    154: DataDesc:      .word   0xFFFF  # limit at maximum: (bits 15:0)
                    155:        .byte   0,0,0   # base at 0: (bits 23:0)
                    156:        .byte   0x93    # present/priv level 0/data/expand-up/writeable
                    157:        .byte   0xcf    # page granular/default 32-bit/limit(bits 19:16)
                    158:        .byte   0       # base at 0: (bits 31:24)
                    159: 
                    160: /* Global Descriptor Table pointer
                    161:  *  contains 6-byte pointer information for LGDT
                    162:  */
                    163: GDTptr:        .word   0x17    # limit to three 8 byte selectors(null,code,data)
1.1.1.3   root      164:        .long   BIOSRELOC+0x8c  # GDT -- arrgh, gas again!
1.1       root      165: readcmd: .byte 0xe6,0,0,0,0,2,18,0x1b,0xff
                    166: 
                    167:        /* step 4 relocate to final bootstrap address. */
                    168: reloc:
                    169:        movl    $ BIOSRELOC,%esi
                    170:        movl    $ RELOC,%edi
                    171:        movl    $512,%ecx
                    172:        rep
                    173:        movsb
1.1.1.3   root      174:        movl    $0xa0000, %esp
1.1       root      175:        pushl   $dodisk
                    176:        ret
                    177: 
                    178:        /* step 5 load remaining 15 sectors off disk */
                    179: dodisk:
1.1.1.3   root      180:        movl    $ RELOC+0x200, %edi
                    181:        xorl    %ebx, %ebx
                    182:        incb    %bl # shl $1,%bl
1.1       root      183:        incb    %bl
                    184:        movb    $0x20,%al       # do a eoi
                    185:        outb    %al,$0x20
                    186: 
                    187:        NOP
1.1.1.4   root      188:        movb    $0xbf,%al       # enable floppy interrupt, mask out rest
1.1       root      189:        outb    %al,$0x21
                    190:        NOP
                    191:  8:
                    192:        movb    %bl,readcmd+4
                    193:        movl    %edi,%ecx
                    194: 
                    195:        /* Set read/write bytes */
                    196:        xorl    %edx,%edx
1.1.1.4   root      197:        movb    $0x0c,%dl       # outb(0xC,junk); outb(0xB,0x46);
                    198:        outb    %al,%dx         # reset DMA controller first/last flip-flop
1.1       root      199:        NOP
                    200:        decb    %dx
1.1.1.4   root      201:        movb    $0x46,%al       # single mode, write mem, chan 2
                    202:        outb    %al,%dx         # output DMA controller mode byte
1.1       root      203: 
                    204:        /* Send start address */
                    205:        movb    $0x04,%dl       # outb(0x4, addr);
                    206:        movb    %cl,%al
                    207:        outb    %al,%dx
                    208:        NOP
                    209:        movb    %ch,%al         # outb(0x4, addr>>8);
                    210:        outb    %al,%dx
                    211:        NOP
                    212:        rorl    $8,%ecx         # outb(0x81, addr>>16);
                    213:        movb    %ch,%al
                    214:        outb    %al,$0x81
                    215:        NOP
                    216: 
                    217:        /* Send count */
                    218:        movb    $0x05,%dl       # outb(0x5, 0);
                    219:        xorl    %eax,%eax
                    220:        outb    %al,%dx
                    221:        NOP
                    222:        movb    $2,%al          # outb(0x5,2);
                    223:        outb    %al,%dx
                    224:        NOP
                    225: 
                    226:        /* set channel 2 */
1.1.1.3   root      227:        movb    $2,%al          # outb(0x0A,2);
1.1       root      228:        outb    %al,$0x0A
                    229:        NOP
                    230: 
                    231:        /* issue read command to fdc */
                    232:        movw    $0x3f4,%dx
                    233:        movl    $readcmd,%esi
                    234:        xorl    %ecx,%ecx
                    235:        movb    $9,%cl
                    236: 
1.1.1.3   root      237:  2:    NOP
                    238:        inb     %dx,%al
1.1       root      239:        testb   $0x80,%al
                    240:        jz 2b
                    241: 
                    242:        incb    %dx
1.1.1.3   root      243:        NOP
1.1       root      244:        movl    (%esi),%al
                    245:        outb    %al,%dx
                    246:        NOP
                    247:        incl    %esi
                    248:        decb    %dx
                    249:        loop     2b
                    250: 
                    251:        /* watch the icu looking for an interrupt signalling completion */
                    252:        xorl    %edx,%edx
                    253:        movb    $0x20,%dl
1.1.1.3   root      254:  2:
                    255:        NOP
                    256:        movb    $0xc,%al
1.1       root      257:        outb    %al,%dx
                    258:        NOP
                    259:        inb     %dx,%al
                    260:        andb    $0x7f,%al
                    261:        cmpb    $6,%al
                    262:        jne     2b
1.1.1.3   root      263:        NOP
1.1       root      264:        movb    $0x20,%al       # do a eoi
                    265:        outb    %al,%dx
                    266:        NOP
                    267: 
                    268:        movl    $0x3f4,%edx
                    269:        xorl    %ecx,%ecx
                    270:        movb    $7,%cl
1.1.1.3   root      271:  2:
1.1       root      272:        NOP
1.1.1.3   root      273:        inb     %dx,%al
1.1       root      274:        andb    $0xC0,%al
                    275:        cmpb    $0xc0,%al
                    276:        jne     2b
                    277:        incb    %dx
                    278:        inb     %dx,%al
                    279:        decb    %dx
                    280:        loop    2b
                    281: 
                    282:        /* extract the status bytes after the read. must we do this? */
                    283:        addw    $0x200,%edi     # next addr to load to
                    284:        incb    %bl
1.1.1.2   root      285:        cmpb    $15,%bl
1.1       root      286:        jle     8b
                    287:        
                    288:        /* for clever bootstrap, dig out boot unit and cylinder */
                    289:        pushl   $0
                    290:        pushl   $0
                    291:        
                    292:        /* fd controller is major device 2 */
                    293:        pushl   $2      /* dev */
                    294: 
                    295:        /* sorry, no flags at this point! */
                    296: 
1.1.1.3   root      297:        movl $ start, %eax
                    298:        call %eax       /* main (dev, unit, off) */
1.1       root      299: 
                    300: ebootblkcode:
                    301: 
                    302:        /* remaining space usable for a disk label */
                    303:        
1.1.1.3   root      304:        .org    0x1fe
1.1       root      305:        .word   0xaa55          /* signature -- used by BIOS ROM */
                    306: 
                    307: 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.