Annotation of Net2/arch/i386/boot/bios.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:  * bios.S,v
        !            32: Revision 1.2  1993/07/11  12:02:20  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/06/28  bde
        !            40:  *     Guess the disk size when the BIOS doesn't support the diskinfo
        !            41:  *     interrupt.
        !            42:  *
        !            43:  *     Change biosread() interface.  Sector count and io address are now
        !            44:  *     args.
1.1       root       45:  *
1.1.1.2 ! root       46:  *     Change all data16's to data32's.
        !            47:  *
        !            48: Revision 1.1  1993/03/21  18:08:23  cgd
        !            49: after 0.2.2 "stable" patches applied
        !            50: 
1.1       root       51:  * Revision 2.2  92/04/04  11:34:26  rpd
                     52:  *     Fix Intel Copyright as per B. Davies authorization.
                     53:  *     [92/04/03            rvb]
                     54:  *     From 2.5 version
                     55:  *     [92/03/30            mg32]
                     56:  * 
                     57:  * Revision 2.2  91/04/02  14:35:21  mbj
                     58:  *     Add Intel copyright
                     59:  *     [90/02/09            rvb]
                     60:  * 
                     61:  */
                     62: 
                     63: 
                     64: /*
                     65:   Copyright 1988, 1989, 1990, 1991, 1992 
                     66:    by Intel Corporation, Santa Clara, California.
                     67: 
                     68:                 All Rights Reserved
                     69: 
                     70: Permission to use, copy, modify, and distribute this software and
                     71: its documentation for any purpose and without fee is hereby
                     72: granted, provided that the above copyright notice appears in all
                     73: copies and that both the copyright notice and this permission notice
                     74: appear in supporting documentation, and that the name of Intel
                     75: not be used in advertising or publicity pertaining to distribution
                     76: of the software without specific, written prior permission.
                     77: 
                     78: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
                     79: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
                     80: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
                     81: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
                     82: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
                     83: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
                     84: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     85: */
                     86: 
                     87:        .file   "bios.s"
                     88: 
                     89: #include "asm.h"
                     90:        .text
                     91: 
                     92: /*
1.1.1.2 ! root       93: # biosread(dev, cyl, head, sec, nsec, offset)
        !            94: #      Read "nsec" sectors from disk to offset "offset" in boot segment
1.1       root       95: # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
                     96: #      Call with       %ah = 0x2
                     97: #                      %al = number of sectors
                     98: #                      %ch = cylinder
                     99: #                      %cl = sector
                    100: #                      %dh = head
                    101: #                      %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
                    102: #                      %es:%bx = segment:offset of buffer
                    103: #      Return:         
                    104: #                      %al = 0x0 on success; err code on failure
                    105: */
                    106: 
                    107: ENTRY(biosread)
                    108:        push    %ebp
                    109:        mov     %esp, %ebp
                    110: 
                    111:        push    %ebx
                    112:        push    %ecx
                    113:        push    %edx
                    114:        push    %es
                    115: 
                    116:        movb    0x10(%ebp), %dh
                    117:        movw    0x0c(%ebp), %cx
                    118:        xchgb   %ch, %cl        # cylinder; the highest 2 bits of cyl is in %cl
                    119:        rorb    $2, %cl
                    120:        movb    0x14(%ebp), %al
                    121:        orb     %al, %cl
                    122:        incb    %cl             # sector; sec starts from 1, not 0
                    123:        movb    0x8(%ebp), %dl  # device
1.1.1.2 ! root      124:        movl    0x1c(%ebp), %ebx        # offset
1.1       root      125:                                # prot_to_real will set %es to BOOTSEG
                    126: 
                    127:        call    EXT(prot_to_real)       # enter real mode
                    128:        movb    $0x2, %ah       # subfunction
1.1.1.2 ! root      129:        addr32
        !           130:        movb    0x18(%ebp), %al # number of sectors
1.1       root      131: 
                    132:        sti
                    133:        int     $0x13
                    134:        cli
                    135: 
1.1.1.2 ! root      136:        mov     %eax, %ebx      # save return value (actually movw %ax, %bx)
1.1       root      137: 
1.1.1.2 ! root      138:        data32
1.1       root      139:        call    EXT(real_to_prot) # back to protected mode
                    140: 
                    141:        xor     %eax, %eax
                    142:        movb    %bh, %al        # return value in %ax
                    143: 
                    144:        pop     %es
                    145:        pop     %edx
                    146:        pop     %ecx
                    147:        pop     %ebx
                    148:        pop     %ebp
                    149: 
                    150:        ret
                    151: 
                    152: 
                    153: /*
                    154: # putc(ch)
                    155: # BIOS call "INT 10H Function 0Eh" to write character to console
                    156: #      Call with       %ah = 0x0e
                    157: #                      %al = character
                    158: #                      %bh = page
                    159: #                      %bl = foreground color ( graphics modes)
                    160: */
                    161: 
                    162: 
                    163: ENTRY(putc)
                    164:        push    %ebp
                    165:        mov     %esp, %ebp
                    166:        push    %ebx
                    167:        push    %ecx
                    168: 
                    169:        movb    0x8(%ebp), %cl
                    170: 
                    171:        call    EXT(prot_to_real)
                    172: 
1.1.1.2 ! root      173:        data32
1.1       root      174:        mov     $0x1, %ebx      # %bh=0, %bl=1 (blue)
                    175:        movb    $0xe, %ah
                    176:        movb    %cl, %al
                    177:        sti
                    178:        int     $0x10           # display a byte
                    179:        cli
                    180: 
1.1.1.2 ! root      181:        data32
1.1       root      182:        call    EXT(real_to_prot)
                    183: 
                    184:        pop     %ecx
                    185:        pop     %ebx
                    186:        pop     %ebp
                    187:        ret
                    188: 
                    189: 
                    190: /*
                    191: # getc()
                    192: # BIOS call "INT 16H Function 00H" to read character from keyboard
                    193: #      Call with       %ah = 0x0
                    194: #      Return:         %ah = keyboard scan code
                    195: #                      %al = ASCII character
                    196: */
                    197: 
                    198: ENTRY(getc)
                    199:        push    %ebp
                    200:        mov     %esp, %ebp
                    201:        push    %ebx            # save %ebx
                    202: 
                    203:        call    EXT(prot_to_real)
                    204: 
                    205:        movb    $0x0, %ah
                    206:        sti
                    207:        int     $0x16
                    208:        cli
                    209: 
                    210:        movb    %al, %bl        # real_to_prot uses %eax
                    211: 
1.1.1.2 ! root      212:        data32
1.1       root      213:        call    EXT(real_to_prot)
                    214: 
                    215:        xor     %eax, %eax
                    216:        movb    %bl, %al
                    217: 
                    218:        pop     %ebx
                    219:        pop     %ebp
                    220:        ret
                    221: /*
                    222: # ischar()
                    223: #       if there is a character pending, return it; otherwise return 0
                    224: # BIOS call "INT 16H Function 01H" to check whether a character is pending
                    225: #      Call with       %ah = 0x1
                    226: #      Return:
                    227: #              If key waiting to be input:
                    228: #                      %ah = keyboard scan code
                    229: #                      %al = ASCII character
                    230: #                      Zero flag = clear
                    231: #              else
                    232: #                      Zero flag = set
                    233: */
                    234: ENTRY(ischar)
                    235:        push    %ebp
                    236:        mov     %esp, %ebp
                    237:        push    %ebx
                    238: 
                    239:        call    EXT(prot_to_real)               # enter real mode
                    240: 
                    241:        xor     %ebx, %ebx
                    242:        movb    $0x1, %ah
                    243:        sti
                    244:        int     $0x16
                    245:        cli
1.1.1.2 ! root      246:        data32
1.1       root      247:        jz      nochar
                    248:        movb    %al, %bl
                    249: 
                    250: nochar:
1.1.1.2 ! root      251:        data32
1.1       root      252:        call    EXT(real_to_prot)
                    253: 
                    254:        xor     %eax, %eax
                    255:        movb    %bl, %al
                    256: 
                    257:        pop     %ebx
                    258:        pop     %ebp
                    259:        ret
                    260: 
                    261: /*
                    262: #
                    263: # get_diskinfo():  return a word that represents the
                    264: #      max number of sectors and  heads and drives for this device
                    265: #
                    266: */
                    267: 
                    268: ENTRY(get_diskinfo)
                    269:        push    %ebp
                    270:        mov     %esp, %ebp
                    271:        push    %es
                    272:        push    %ebx
                    273:        push    %ecx
                    274:        push    %edx
                    275: 
                    276:        movb    0x8(%ebp), %dl          # diskinfo(drive #)
                    277:        call    EXT(prot_to_real)       # enter real mode
                    278: 
                    279:        movb    $0x8, %ah               # ask for disk info
                    280: 
                    281:        sti
                    282:        int     $0x13
                    283:        cli
                    284: 
1.1.1.2 ! root      285:        jnc     ok
        !           286:        /*
        !           287:         * Urk.  Call failed.  It is not supported for floppies by old BIOS's.
        !           288:         * Guess it's a 15-sector floppy.  Initialize all the registers for
        !           289:         * documentation, although we only need head and sector counts.
        !           290:         */
        !           291:        subb    %ah, %ah                # %ax = 0
        !           292:        movb    %al, %al
        !           293:        movb    %ah, %bh                # %bh = 0
        !           294:        movb    $2, %bl                 # %bl bits 0-3 = drive type, 2 = 1.2M
        !           295:        movb    $79, %ch                # max track
        !           296:        movb    $15, %cl                # max sector
        !           297:        movb    $1, %dh                 # max head
        !           298:        movb    $1, %dl                 # # floppy drives installed
        !           299:        # es:di = parameter table
        !           300:        # carry = 0
        !           301: ok:
        !           302: 
        !           303:        data32
1.1       root      304:        call    EXT(real_to_prot)       # back to protected mode
                    305: 
                    306:        xor     %eax, %eax
                    307: 
                    308:        /*form a longword representing all this gunk*/
1.1.1.2 ! root      309:        movb    %dh, %ah                # max head
1.1       root      310:        andb    $0x3f, %cl              # mask of cylinder gunk
1.1.1.2 ! root      311:        movb    %cl, %al                # max sector (and # sectors)
1.1       root      312: 
                    313:        pop     %edx
                    314:        pop     %ecx
                    315:        pop     %ebx
                    316:        pop     %es
                    317:        pop     %ebp
                    318:        ret
                    319: 
                    320: /*
                    321: #
                    322: # memsize(i) :  return the memory size in KB. i == 0 for conventional memory,
                    323: #              i == 1 for extended memory
                    324: #      BIOS call "INT 12H" to get conventional memory size
                    325: #      BIOS call "INT 15H, AH=88H" to get extended memory size
                    326: #              Both have the return value in AX.
                    327: #
                    328: */
                    329: 
                    330: ENTRY(memsize)
                    331:        push    %ebp
                    332:        mov     %esp, %ebp
                    333:        push    %ebx
                    334: 
                    335:        mov     8(%ebp), %ebx
                    336: 
                    337:        call    EXT(prot_to_real)               # enter real mode
                    338: 
                    339:        cmpb    $0x1, %bl
1.1.1.2 ! root      340:        data32
1.1       root      341:        je      xext
                    342:        
                    343:        sti
                    344:        int     $0x12
                    345:        cli
1.1.1.2 ! root      346:        data32
1.1       root      347:        jmp     xdone
                    348: 
                    349: xext:  movb    $0x88, %ah
                    350:        sti
                    351:        int     $0x15
                    352:        cli
                    353: 
                    354: xdone:
                    355:        mov     %eax, %ebx
                    356: 
1.1.1.2 ! root      357:        data32
1.1       root      358:        call    EXT(real_to_prot)
                    359: 
                    360:        mov     %ebx, %eax
                    361:        pop     %ebx
                    362:        pop     %ebp
                    363:        ret

unix.superglobalmegacorp.com

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