8000 minix/boot/boothead.s at v3.1.4 · lgqgood/minix · GitHub
[go: up one dir, main page]

Skip to content
  • Latest commit

     

    History

    History
    executable file
    ·
    1516 lines (1412 loc) · 38.8 KB

    boothead.s

    File metadata and controls

    executable file
    ·
    1516 lines (1412 loc) · 38.8 KB
    je finish
    cmpb ah, #0x03 ! Disk write protected?
    je finish
    dec di ! Do we allow another reset?
    jl finish ! No, report the error
    xorb ah, ah ! Code for a reset (0)
    int 0x13
    jnc more ! Succesful reset, try request again
    finish: movb al, ah
    xorb ah, ah ! ax = error number
    badopen:pop es
    pop di
    pop si
    pop bp
    ret
    .data
    .align 4
    ! Extended read/write commands require a parameter packet.
    ext_rw:
    .data1 0x10 ! Length of extended r/w packet
    .data1 0 ! Reserved
    .data2 0 ! Blocks to transfer (to be filled in)
    .data2 0 ! Buffer address offset (tbfi)
    .data2 0 ! Buffer address segment (tbfi)
    .data4 0 ! Starting block number low 32 bits (tbfi)
    .data4 0 ! Starting block number high 32 bits
    .text
    ! int getch(void);
    ! Read a character from the keyboard, and check for an expired timer.
    ! A carriage return is changed into a linefeed for UNIX compatibility.
    .define _getch
    _getch:
    xor ax, ax
    xchg ax, unchar ! Ungotten character?
    test ax, ax
    jnz gotch
    getch:
    ! hlt ! Play dead until interrupted (see pause())
    movb ah, #0x01 ! Keyboard status
    int 0x16
    jz 0f ! Nothing typed
    xorb ah, ah ! Read character from keyboard
    int 0x16
    jmp press ! Keypress
    0: mov dx, line ! Serial line?
    test dx, dx
    jz 0f
    add dx, #5 ! Line Status Register
    inb dx
    testb al, #0x01 ! Data Ready?
    jz 0f
    mov dx, line
    !add dx, 0 ! Receive Buffer Register
    inb dx ! Get character
    jmp press
    0: call _expired ! Timer expired?
    test ax, ax
    jz getch
    mov ax, #ESC ! Return ESC
    ret
    press:
    cmpb al, #0x0D ! Carriage return?
    jnz nocr
    movb al, #0x0A ! Change to linefeed
    nocr: cmpb al, #ESC ! Escape typed?
    jne noesc
    inc escape ! Set flag
    noesc: xorb ah, ah ! ax = al
    gotch: ret
    ! int ungetch(void);
    ! Return a character to undo a getch().
    .define _ungetch
    _ungetch:
    mov bx, sp
    mov ax, 2(bx)
    mov unchar, ax
    ret
    ! int escape(void);
    ! True if ESC has been typed.
    .define _escape
    _escape:
    movb ah, #0x01 ! Keyboard status
    int 0x16
    jz escflg ! Keypress?
    cmpb al, #ESC ! Escape typed?
    jne escflg
    xorb ah, ah ! Discard the escape
    int 0x16
    inc escape ! Set flag
    escflg: xor ax, ax
    xchg ax, escape ! Escape typed flag
    ret
    ! int putch(int c);
    ! Write a character in teletype mode. The putk synonym is
    ! for the kernel printf function that uses it.
    ! Newlines are automatically preceded by a carriage return.
    !
    .define _putch, _putk
    _putch:
    _putk: mov bx, sp
    movb al, 2(bx) ! al = character to be printed
    testb al, al ! Kernel printf adds a null char to flush queue
    jz nulch
    cmpb al, #0x0A ! al = newline?
    jnz putc
    movb al, #0x0D
    call putc ! putc('\r')
    movb al, #0x0A ! Restore the '\n' and print it
    putc: movb ah, #0x0E ! Print character in teletype mode
    mov bx, #0x0001 ! Page 0, foreground color
    int 0x10
    mov bx, line ! Serial line?
    test bx, bx
    jz nulch
    push ax ! Save character to print
    call _get_tick ! Current clock tick counter
    mov cx, ax
    add cx, #2 ! Don't want to see it count twice
    1: lea dx, 5(bx) ! Line Status Register
    inb dx
    testb al, #0x20 ! Transmitter Holding Register Empty?
    jnz 0f
    call _get_tick
    cmp ax, cx ! Clock ticked more than once?
    jne 1b
    0: pop ax ! Restore character to print
    mov dx, bx ! Transmit Holding Register
    outb dx ! Send character down the serial line
    nulch: ret
    ! void pause(void);
    ! Wait for an interrupt using the HLT instruction. This either saves
    ! power, or tells an x86 emulator that nothing is happening right now.
    .define _pause
    _pause:
    ! hlt
    ret
    ! void set_mode(unsigned mode);
    ! void clear_screen(void);
    ! Set video mode / clear the screen.
    .define _set_mode, _clear_screen
    _set_mode:
    mov bx, sp
    mov ax, 2(bx) ! Video mode
    cmp ax, cur_vid_mode
    je modeok ! Mode already as requested?
    mov cur_vid_mode, ax
    _clear_screen:
    xor ax, ax
    mov es, ax ! es = Vector segment
    mov ax, cur_vid_mode
    movb ch, ah ! Copy of the special flags
    andb ah, #0x0F ! Test bits 8-11, clear special flags
    jnz xvesa ! VESA extended mode?
    int 0x10 ! Reset video (ah = 0)
    jmp md_480
    xvesa: mov bx, ax ! bx = extended mode
    mov ax, #0x4F02 ! Reset video
    int 0x10
    md_480: ! Basic video mode is set, now build on it
    testb ch, #0x20 ! 480 scan lines requested?
    jz md_14pt
    mov dx, #0x3CC ! Get CRTC port
    inb dx
    movb dl, #0xD4
    testb al, #1 ! Mono or color?
    jnz 0f
    movb dl, #0xB4
    0: mov ax, #0x110C ! Vertical sync end (also unlocks CR0-7)
    call out2
    mov ax, #0x060B ! Vertical total
    call out2
    mov ax, #0x073E ! (Vertical) overflow
    call out2
    mov ax, #0x10EA ! Vertical sync start
    call out2
    mov ax, #0x12DF ! Vertical display end
    call out2
    mov ax, #0x15E7 ! Vertical blank start
    call out2
    mov ax, #0x1604 ! Vertical blank end
    call out2
    push dx
    movb dl, #0xCC ! Misc output register (read)
    inb dx
    movb dl, #0xC2 ! (write)
    andb al, #0x0D ! Preserve clock select bits and color bit
    orb al, #0xE2 ! Set correct sync polarity
    outb dx
    pop dx ! Index register still in dx
    md_14pt:
    testb ch, #0x40 ! 9x14 point font requested?
    jz md_8pt
    mov ax, #0x1111 ! Load ROM 9 by 14 font
    xorb bl, bl ! Load block 0
    int 0x10
    testb ch, #0x20 ! 480 scan lines?
    jz md_8pt
    mov ax, #0x12DB ! VGA vertical display end
    call out2
    eseg movb 0x0484, #33 ! Tell BIOS the last line number
    md_8pt:
    testb ch, #0x80 ! 8x8 point font requested?
    jz setcur
    mov ax, #0x1112 ! Load ROM 8 by 8 font
    xorb bl, bl ! Load block 0
    int 0x10
    testb ch, #0x20 ! 480 scan lines?
    jz setcur
    mov ax, #0x12DF ! VGA vertical display end
    call out2
    eseg movb 0x0484, #59 ! Tell BIOS the last line number
    setcur:
    xor dx, dx ! dl = column = 0, dh = row = 0
    xorb bh, bh ! Page 0
    movb ah, #0x02 ! Set cursor position
    int 0x10
    push ss
    pop es ! Restore es
    modeok: ret
    ! Out to the usual [index, data] port pair that are common for VGA devices
    ! dx = port, ah = index, al = data.
    out2:
    push dx
    push ax
    movb al, ah
    outb dx ! Set index
    inc dx
    pop ax
    outb dx ! Send data
    pop dx
    ret
    restore_video: ! To restore the video mode on exit
    mov ax, old_vid_mode
    push ax
    call _set_mode
    pop ax
    ret
    ! void serial_init(int line)
    ! Initialize copying console I/O to a serial line.
    .define _serial_init
    _serial_init:
    mov bx, sp
    mov dx, 2(bx) ! Line number
    mov line, #0
    test dx, dx ! Off if line number < 0
    js 0f
    push ds
    xor ax, ax
    mov ds, ax ! Vector and BIOS data segment
    mov bx, dx ! Line number
    shl bx, #1 ! Word offset
    mov bx, 0x0400(bx) ! I/O port for the given line
    pop ds
    mov line, bx ! Remember I/O port
    serial_init:
    mov bx, line
    test bx, bx ! I/O port must be nonzero
    jz 0f
    mov ax, #0x00E3 ! 9600 N-8-1
    int 0x14 ! Initialize serial line dx
    lea dx, 4(bx) ! Modem Control Register
    movb al, #0x0B ! DTR, RTS, OUT2
    outb dx
    0: ret
    ! u32_t get_tick(void);
    ! Return the current value of the clock tick counter. This counter
    ! increments 18.2 times per second. Poll it to do delays. Does not
    ! work on the original PC, but works on the PC/XT.
    .define _get_tick
    _get_tick:
    push cx
    xorb ah, ah ! Code for get tick count
    int 0x1A
    mov ax, dx
    mov dx, cx ! dx:ax = cx:dx = tick count
    pop cx
    ret
    ! Functions used to obtain info about the hardware. Boot uses this information
    ! itself, but will also pass them on to a pure 386 kernel, because one can't
    ! make BIOS calls from protected mode. The video type could probably be
    ! determined by the kernel too by looking at the hardware, but there is a small
    ! chance on errors that the monitor allows you to correct by setting variables.
    .define _get_bus ! returns type of system bus
    .define _get_video ! returns type of display
    ! u16_t get_bus(void)
    ! Return type of system bus, in order: XT, AT, MCA.
    _get_bus:
    call _getprocessor
    xor dx, dx ! Assume XT
    cmp ax, #286 ! An AT has at least a 286
    jb got_bus
    inc dx ! Assume AT
    movb ah, #0xC0 ! Code for get configuration
    int 0x15
    jc got_bus ! Carry clear and ah = 00 if supported
    testb ah, ah
    jne got_bus
    eseg
    movb al, 5(bx) ! Load feature byte #1
    inc dx ! Assume MCA
    testb al, #0x02 ! Test bit 1 - "bus is Micro Channel"
    jnz got_bus
    dec dx ! Assume AT
    testb al, #0x40 ! Test bit 6 - "2nd 8259 installed"
    jnz got_bus
    dec dx ! It is an XT
    got_bus:
    push ds
    pop es ! Restore es
    mov ax, dx ! Return bus code
    mov bus, ax ! Keep bus code, A20 handler likes to know
    ret
    ! u16_t get_video(void)
    ! Return type of display, in order: MDA, CGA, mono EGA, color EGA,
    ! mono VGA, color VGA.
    _get_video:
    mov ax, #0x1A00 ! Function 1A returns display code
    int 0x10 ! al = 1A if supported
    cmpb al, #0x1A
    jnz no_dc ! No display code function supported
    mov ax, #2
    cmpb bl, #5 ! Is it a monochrome EGA?
    jz got_video
    inc ax
    cmpb bl, #4 ! Is it a color EGA?
    jz got_video
    inc ax
    cmpb bl, #7 ! Is it a monochrome VGA?
    jz got_video
    inc ax
    cmpb bl, #8 ! Is it a color VGA?
    jz got_video
    no_dc: movb ah, #0x12 ! Get information about the EGA
    movb bl, #0x10
    int 0x10
    cmpb bl, #0x10 ! Did it come back as 0x10? (No EGA)
    jz no_ega
    mov ax, #2
    cmpb bh, #1 ! Is it monochrome?
    jz got_video
    inc ax
    jmp got_video
    no_ega: int 0x11 ! Get bit pattern for equipment
    and ax, #0x30 ! Isolate color/mono field
    sub ax, #0x30
    jz got_video ! Is it an MDA?
    mov ax, #1 ! No it's CGA
    got_video:
    ret
    ! Functions to leave the boot monitor.
    .define _bootstrap ! Call another bootstrap
    .define _minix ! Call Minix
    ! void _bootstrap(int device, struct part_entry *entry)
    ! Call another bootstrap routine to boot MS-DOS for instance. (No real
    ! need for that anymore, now that you can format floppies under Minix).
    ! The bootstrap must have been loaded at BOOTSEG from "device".
    _bootstrap:
    call restore_video
    mov bx, sp
    movb dl, 2(bx) ! Device to boot from
    mov si, 4(bx) ! ds:si = partition table entry
    xor ax, ax
    mov es, ax ! Vector segment
    mov di, #BUFFER ! es:di = buffer in low core
    mov cx, #PENTRYSIZE ! cx = size of partition table entry
    rep movsb ! Copy the entry to low core
    mov si, #BUFFER ! es:si = partition table entry
    mov ds, ax ! Some bootstraps need zero segment registers
    cli
    mov ss, ax
    mov sp, #BOOTOFF ! This should do it
    sti
    jmpf BOOTOFF, 0 ! Back to where the BIOS loads the boot code
    0