Annotation of Net2/arch/i386/boot/start.s, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Ported to boot 386BSD by Julian Elischer ([email protected]) Sept 1992
                      3:  *
                      4:  * Mach Operating System
                      5:  * Copyright (c) 1992, 1991 Carnegie Mellon University
                      6:  * All Rights Reserved.
                      7:  * 
                      8:  * Permission to use, copy, modify and distribute this software and its
                      9:  * documentation is hereby granted, provided that both the copyright
                     10:  * notice and this permission notice appear in all copies of the
                     11:  * software, derivative works or modified versions, and any portions
                     12:  * thereof, and that both notices appear in supporting documentation.
                     13:  * 
                     14:  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
                     15:  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
                     16:  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
                     17:  * 
                     18:  * Carnegie Mellon requests users of this software to return to
                     19:  * 
                     20:  *  Software Distribution Coordinator  or  [email protected]
                     21:  *  School of Computer Science
                     22:  *  Carnegie Mellon University
                     23:  *  Pittsburgh PA 15213-3890
                     24:  * 
                     25:  * any improvements or extensions that they make and grant Carnegie Mellon
                     26:  * the rights to redistribute these changes.
                     27:  */
                     28: 
                     29: /*
                     30:  * HISTORY
1.1.1.2 ! root       31:  * start.S,v
        !            32: Revision 1.2  1993/07/11  12:02:24  andrew
        !            33: Fixes from bde, including support for loading @ any MB boundary (e.g. a
        !            34: kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead
        !            35: buffering to speed booting from floppies.  Also works with aha174x
        !            36: controllers in enhanced mode.
        !            37: 
        !            38:  *
        !            39:  * 93/07/06  bde
        !            40:  *     Restored BOOTSEG to 0x9000 for distribution.  It should be decided
        !            41:  *     at boot time to locate the bootstrap immediately underneath the
        !            42:  *     debugger or whatever is in high memory.  This isn't safe yet,
        !            43:  *     because it might make the read-ahead buffer might lie across a 64K
        !            44:  *     DMA boundary.
        !            45:  *
        !            46:  * 93/07/03  bde
        !            47:  *     Some floppy BIOS's can only handle reads of one track, so a LOADSZ
        !            48:  *     of 16 doesn't work.  15 will do for now.
        !            49:  *
        !            50:  * 93/06/29  bde
        !            51:  *     LOADSZ is 16, not 14.  The BIOS can handle a minimum of one floppy
        !            52:  *     cylinder so it can always handle 16 sectors starting at head 0,
        !            53:  *     sector 1.
        !            54:  *
        !            55:  * 93/06/28  bde
        !            56:  *     Changed addr16's to addr32's.  One before a useless "xor %ecx, %ecx"
        !            57:  *     did nothing (removed both prefix and xor).
        !            58:  *
        !            59:  *     Initialize head = %dh = 0 for floppy case.
        !            60:  *
        !            61:  *     Fixed #ifdef DEBUG ... #endif that split data32; jmp load.  If
        !            62:  *     DEBUG is defined then the jmp doesn't get prefixed.  This is fatal
        !            63:  *     iff the jmp is long.  Usually the jmp will be short and the prefix
        !            64:  *     unnecessary.  But it is more likely to be necessary if DEBUG is
        !            65:  *     defined.
        !            66:  *
        !            67:  * 93/06/27  bde
        !            68:  *     Removed bogus Int 21.  There is no Int 21 BIOS call.  The drive
        !            69:  *     number is passed to here in %dl and the Int 21 is at best a nop.
        !            70:  *     Some BIOS's treat Int 21 as a stray hardware interrupt and shut
        !            71:  *     down all in-service interrupts.  This should not be a problem
        !            72:  *     because this are not an interrupt handler so there are no
        !            73:  *     in-service interrupts, but ...
        !            74:  *
        !            75:  *     Fixed fd/hd decision.  "%dl ge 0x80" (signed comparison) was always
        !            76:  *     true, so fd's were treated as hd's.  This was not a problem because
        !            77:  *     the boot block has a partition table.
        !            78:  *
        !            79:  *     Reduced BOOTSEG and added breakpoint so that debugger can look at
        !            80:  *     this.  Having a fixed boot address is bad because some machines don't
        !            81:  *     have 640K and others have debuggers and/or BIOS stuff in high memory.
1.1       root       82:  *
1.1.1.2 ! root       83:  * 93/04/30  bde
        !            84:  *     Commented out "<leading white space> # %".  It's not C, and gcc-2's
        !            85:  *     cpp doesn't allow it.  "# identifier" isn't C either but works for now.
        !            86:  *
        !            87:  *     Use $ EXT instead of $EXT to avoid broken DOLLARS_IN_IDENTIFIERS stuff
        !            88:  *     in gcc-2.3.3.  (Bug is still in gcc-2.4.5 but is avoided by using .S
        !            89:  *     files.)
        !            90:  *
        !            91: Revision 1.1  1993/03/21  18:08:42  cgd
        !            92: after 0.2.2 "stable" patches applied
        !            93: 
1.1       root       94:  * Revision 2.2  92/04/04  11:36:29  rpd
                     95:  *     Fix Intel Copyright as per B. Davies authorization.
                     96:  *     [92/04/03            rvb]
                     97:  *     Need to zero dh on hd path; at least for an adaptec card.
                     98:  *     [92/01/14            rvb]
                     99:  * 
                    100:  *     From 2.5 boot:
                    101:  *     Flush digit printing.
                    102:  *     Fuse floppy and hd boot by using Int 21 to tell
                    103:  *     boot type (slightly dubious since Int 21 is DOS
                    104:  *     not BIOS)
                    105:  *     [92/03/30            mg32]
                    106:  * 
                    107:  * Revision 2.2  91/04/02  14:42:04  mbj
                    108:  *     Fix the BIG boot bug.  We had missed a necessary data
                    109:  *     before a xor that was clearing a register used later
                    110:  *     as an index register.
                    111:  *     [91/03/01            rvb]
                    112:  *     Remember floppy type for swapgeneric
                    113:  *     Add Intel copyright
                    114:  *     [90/02/09            rvb]
                    115:  * 
                    116:  */
                    117:  
                    118: 
                    119: /*
                    120:   Copyright 1988, 1989, 1990, 1991, 1992 
                    121:    by Intel Corporation, Santa Clara, California.
                    122: 
                    123:                 All Rights Reserved
                    124: 
                    125: Permission to use, copy, modify, and distribute this software and
                    126: its documentation for any purpose and without fee is hereby
                    127: granted, provided that the above copyright notice appears in all
                    128: copies and that both the copyright notice and this permission notice
                    129: appear in supporting documentation, and that the name of Intel
                    130: not be used in advertising or publicity pertaining to distribution
                    131: of the software without specific, written prior permission.
                    132: 
                    133: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
                    134: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
                    135: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
                    136: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
                    137: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
                    138: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
                    139: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                    140: */
                    141: #include       "asm.h"
                    142: 
                    143:        .file   "start.s"
                    144: 
1.1.1.2 ! root      145: BOOTSEG                =       0x9000  # boot will be loaded here (below 640K)
1.1       root      146: BOOTSTACK      =       0xe000  # boot stack
                    147: SIGNATURE      =       0xaa55
1.1.1.2 ! root      148: LOADSZ         =       15      # size of unix boot
1.1       root      149: PARTSTART      =       0x1be   # starting address of partition table
                    150: NUMPART                =       4       # number of partitions in partition table
                    151: PARTSZ         =       16      # each partition table entry is 16 bytes
                    152: BSDPART                =       0xA5    # value of boot_ind, means bootable partition
                    153: BOOTABLE       =       0x80    # value of boot_ind, means bootable partition
                    154: 
                    155:        .text   
                    156: 
                    157: ENTRY(boot1)
1.1.1.2 ! root      158:        # start (aka boot1) is loaded at 0x0:0x7c00 but we want 0x7c0:0
        !           159:        # ljmp to the next instruction to adjust %cs
1.1       root      160:        data32
                    161:        ljmp $0x7c0, $start
                    162: 
                    163: start:
                    164:        # set up %ds
                    165:        mov     %cs, %ax
                    166:        mov     %ax, %ds
                    167: 
                    168:        # set up %ss and %esp
                    169:        data32
                    170:        mov     $BOOTSEG, %eax
                    171:        mov     %ax, %ss
                    172:        data32
                    173:        mov     $BOOTSTACK, %esp
                    174: 
                    175:        /*** set up %es, (where we will load boot2 to) ***/
                    176:        mov     %ax, %es
                    177: 
                    178: #ifdef DEBUG
                    179:        data32
                    180:        mov     $one, %esi
                    181:        data32
                    182:        call    message
                    183: #endif
                    184: 
1.1.1.2 ! root      185:        # bootstrap passes us drive number in %dl
1.1       root      186:        cmpb    $0x80, %dl
                    187:        data32
1.1.1.2 ! root      188:        jae     hd
1.1       root      189: 
                    190: fd:
                    191: #      reset the disk system
                    192: #ifdef DEBUG
                    193:        data32
                    194:        mov     $two, %esi
                    195:        data32
                    196:        call    message
                    197: #endif
                    198:        movb    $0x0, %ah
                    199:        int     $0x13
                    200:        data32
                    201:        mov     $0x0001, %ecx   # cyl 0, sector 1
1.1.1.2 ! root      202:        movb    $0, %dh         # head
1.1       root      203: #ifdef DEBUG
                    204:        data32
                    205:        mov     $three, %esi
                    206:        data32
                    207:        call    message
                    208: #endif
1.1.1.2 ! root      209:        data32
        !           210:        jmp     load
1.1       root      211: 
                    212: hd:    /**** load sector 0 into the BOOTSEG ****/
                    213: #ifdef DEBUG
                    214:        data32
                    215:        mov     $four, %esi
                    216:        data32
                    217:        call    message
                    218: #endif
                    219:        data32
                    220:        mov     $0x0201, %eax
                    221:        xor     %ebx, %ebx      # %bx = 0
                    222:        data32
                    223:        mov     $0x0001, %ecx
                    224: #ifdef DEBUG
                    225:        data32
                    226:        mov     $five, %esi
                    227:        data32
                    228:        call    message
                    229: #endif
                    230:        data32
                    231:        andl    $0xff, %edx
                    232:        /*mov   $0x0080, %edx*/
                    233:        int     $0x13
                    234:        data32
                    235:        jb      read_error
                    236: 
1.1.1.2 ! root      237:        /***# find the first 386BSD partition *****/
1.1       root      238:        data32
                    239:        mov     $PARTSTART, %ebx
                    240:        data32
                    241:        mov     $NUMPART, %ecx
                    242: again:
1.1.1.2 ! root      243:        addr32
1.1       root      244:        movb    %es:4(%ebx), %al
                    245:        cmpb    $BSDPART, %al
                    246:        data32
                    247:        je      found
                    248:        data32
                    249:        add     $PARTSZ, %ebx
                    250:        data32
                    251:        loop    again
                    252:        data32
                    253:        mov     $enoboot, %esi
                    254:        data32
                    255:        jmp     err_stop
                    256: 
                    257: 
                    258: /*
                    259: # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
                    260: #       Call with       %ah = 0x2
                    261: #                       %al = number of sectors
                    262: #                       %ch = cylinder
                    263: #                       %cl = sector
                    264: #                       %dh = head
                    265: #                       %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
                    266: #                       %es:%bx = segment:offset of buffer
                    267: #       Return:
                    268: #                       %al = 0x0 on success; err code on failure
                    269: */
                    270: 
                    271: found:
1.1.1.2 ! root      272:        addr32
1.1       root      273:        movb    %es:1(%ebx), %dh /* head */
1.1.1.2 ! root      274:        addr32
        !           275:        movl    %es:2(%ebx), %ecx /*sect, cyl (+ 2 bytes junk in top word) */
1.1       root      276: 
                    277: load:
                    278:        movb    $0x2, %ah       /* function 2 */
                    279:        movb    $LOADSZ, %al    /* number of blocks */
                    280:        xor     %ebx, %ebx      /* %bx = 0, put it at 0 in the BOOTSEG */
                    281:        int     $0x13
                    282:        data32
                    283:        jb      read_error
                    284: 
                    285:        # ljmp to the second stage boot loader (boot2).
                    286:        # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used
                    287:        # as an internal buffer "intbuf".
                    288: 
                    289: #ifdef DEBUG
                    290:        data32
                    291:        mov     $six, %esi
                    292:        data32
                    293:        call    message
                    294: #endif
                    295:        data32
1.1.1.2 ! root      296:        ljmp    $BOOTSEG, $ EXT(boot2)
1.1       root      297: 
                    298: #
                    299: #      read_error
                    300: #
                    301: 
                    302: read_error:
                    303:        data32
                    304:        mov     $eread, %esi
                    305: err_stop:
                    306:        data32
                    307:        call    message
                    308:        data32
                    309:        jmp     stop
                    310: 
                    311: #
                    312: #      message: write the error message in %ds:%esi to console
                    313: #
                    314: 
                    315: message:
1.1.1.2 ! root      316: /*
1.1       root      317:        # Use BIOS "int 10H Function 0Eh" to write character in teletype mode
                    318:        #       %ah = 0xe       %al = character
                    319:        #       %bh = page      %bl = foreground color (graphics modes)
1.1.1.2 ! root      320: */
1.1       root      321: 
                    322:        data32
                    323:        push    %eax
                    324:        data32
                    325:        push    %ebx
                    326:        data32
                    327:        mov     $0x0001, %ebx
                    328:        cld
                    329: 
                    330: nextb:
                    331:        lodsb                   # load a byte into %al
                    332:        cmpb    $0x0, %al
                    333:        data32
                    334:        je      done
                    335:        movb    $0xe, %ah
                    336:        int     $0x10           # display a byte
                    337:        data32
                    338:        jmp     nextb
                    339: done:
                    340:        data32
                    341:        pop     %ebx
                    342:        data32
                    343:        pop     %eax
                    344:        data32
                    345:        ret
                    346: 
                    347: stop:  hlt
                    348:        data32
                    349:        jmp     stop            # halt doesnt actually halt forever
                    350: 
                    351: /* error messages */
                    352: 
                    353: #ifdef DEBUG
                    354: one:   String          "1\r\n\0"
                    355: two:   String          "2\r\n\0"
                    356: three: String          "3\r\n\0"
                    357: four:  String          "4\r\n\0"
                    358: five:  String          "5\r\n\0"
                    359: six:   String          "6\r\n\0"
                    360: seven: String          "7\r\n\0"
                    361: #endif DEBUG
                    362: eread: String          "Read error\r\n\0"
                    363: enoboot: String                "No bootable partition\r\n\0"
                    364: endofcode:
                    365: /* throw in a partition in case we are block0 as well */
1.1.1.2 ! root      366: /* flag, head, sec, cyl, typ, ehead, esect, ecyl, start, len */
1.1       root      367:        . = EXT(boot1) + PARTSTART
                    368:        .byte 0x0,0,0,0,0,0,0,0
                    369:        .long 0,0
                    370:        .byte 0x0,0,0,0,0,0,0,0
                    371:        .long 0,0
                    372:        .byte 0x0,0,0,0,0,0,0,0
                    373:        .long 0,0
                    374:        .byte BOOTABLE,0,1,0,BSDPART,255,255,255
                    375:        .long 0,50000
                    376: /* the last 2 bytes in the sector 0 contain the signature */
                    377:        . = EXT(boot1) + 0x1fe
                    378:        .value  SIGNATURE
                    379: ENTRY(disklabel)
                    380:        . = EXT(boot1) + 0x400  

unix.superglobalmegacorp.com

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