⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bios.asm

📁 assembly source code that explain how to develop bios.enjoy.
💻 ASM
📖 第 1 页 / 共 5 页
字号:
        MOV     DX,3D8h                         ; Load Color Graphic port
        OUT     DX,AL                           ;  ...no video display
        MOV     DX,3B8h                         ; Load Monochrome port
        INC     AL                              ;  ...no video display
        OUT     DX,AL                           ;  ...write it out
        MOV     AL,10011001b                    ; Program 8255 PIA chip
        OUT     63h,AL                          ;  ...Ports A & C, inputs
        MOV     AL,10100101b                    ; Set (non)turbo mode
        OUT     61h,AL                          ;  ...on main board

        MOV     AL,01010100b                    ; ic 8253 inits memory refresh
        OUT     43h,AL                          ;  ...chan 1 pulses ic 8237 to
        MOV     AL,12h                          ;  ...dma every 12h clock ticks
        OUT     41h,AL                          ;  ...64K done in 1 millisecond
        MOV     AL,01000000b                    ; Latch value 12h in 8253 clock
        OUT     43h,AL                          ;  ...chip channel 1 counter

IC8237: MOV     AL,0                            ; Do some initialization
        OUT     81h,AL                          ;  ...dma page reg, chan 2
        OUT     82h,AL                          ;  ...dma page reg, chan 3
        OUT     83h,AL                          ;  ...dma page reg, chan 0,1
        OUT     0Dh,AL                          ; Stop DMA on 8237 chip
        MOV     AL,01011000b                    ; Refresh auto-init dummy read
        OUT     0Bh,AL                          ;   ...on channel 0 of DMA chip
        MOV     AL,01000001b                    ; Block verify
        OUT     0Bh,AL                          ;   ...on channel 1 of DMA chip
        MOV     AL,01000010b                    ; Block verify
        OUT     0Bh,AL                          ;   ...on channel 2 of DMA chip
        MOV     AL,01000011b                    ; Block verify
        OUT     0Bh,AL                          ;   ...on channel 3 of DMA chip
        MOV     AL,0FFh                         ; Refresh byte count
        OUT     1,AL                            ;   ...send lo order
        OUT     1,AL                            ;   ...send hi order
        MOV     AL,0                            ; Initialize 8237 command reg
        OUT     8,AL                            ;   ...with zero
        OUT     0Ah,AL                          ; Enable DMA on all channels
        MOV     AL,00110110b                    ; Set up 8253 timer chip
        OUT     43h,AL                          ;   ...chan 0 is time of day
        MOV     AL,0                            ; Request a divide by
        OUT     40h,AL                          ;   ...65536 decimal
        OUT     40h,AL                          ;   ...0000h or 18.2 tick/sec
        MOV     DX,213h                         ; Expansion unit port
        MOV     AL,1                            ;  ...enable it
        OUT     DX,AL                           ;  ...do the enable
        MOV     AX,40h                          ; Get bios impure segment
        MOV     DS,AX                           ;  ...into DS register
        MOV     SI,DS:72h                       ; Save reset flag in SI reg
        XOR     AX,AX                           ;  ...cause memory check
        MOV     BP,AX                           ;  ...will clobber the flag
        MOV     BX,AX                           ; Start at segment 0000h
        MOV     DX,55AAh                        ;  ...get pattern
        CLD                                     ; Strings auto-increment

MEMSIZ: XOR     DI,DI                           ; Location XXXX:0
        MOV     ES,BX                           ;  ...load segment
        MOV     ES:[DI],DX                      ;  ...write pattern
        CMP     DX,ES:[DI]                      ;  ...compare
        JNZ     MEM_ND                          ;  ...failed, memory end
        MOV     CX,2000h                        ; Else zero 16 kilobytes
        REPZ    STOSW                           ;  ...with instruction
        ADD     BH,4                            ;  ...get next 16K bytes
ifdef   MAX_MEMORY
        CMP     BH,MAX_MEMORY SHR 2             ; Found max legal user ram?
else
        CMP     BH,0A0h                         ; Found max legal IBM ram?
endif
        JNZ     MEMSIZ                          ;  ...no, then check more

MEM_ND: MOV     DS:72h,SI                       ; Save pointer
        XOR     AX,AX
        MOV     ES,AX                           ; ES = vector segment
        MOV     AX,80h
        MOV     SS,AX                           ; Set up temporary stack at
        MOV     SP,100h                         ;  0080:0100 for memory check
        PUSH    BP
        PUSH    BX
        MOV     BP,2
        CALL    MEMTST                          ; Memory check ES:0 - ES:0400
        POP     AX
        MOV     CL,6
        SHR     AX,CL
        MOV     DS:13h,AX
        POP     AX
        JNB     MEM_01
        OR      AL,ER_MEM                       ; Show vector area bad

MEM_01: MOV     DS:15h,AL                       ; Save IPL error code
        XOR     AX,AX
        PUSH    AX
        PUSH    AX
        PUSH    AX
        PUSH    AX
        PUSH    AX
        MOV     AX,30h                          ; Set up IBM-compatible stack
        MOV     SS,AX                           ;  ...segment 0030h
        MOV     SP,100h                         ;  ...offset  0100h
        PUSH    DS
        MOV     BX,0E000h                       ; Check BIOS eprom
        PUSH    CS
        POP     DS                              ;  ...at F000:E000
        MOV     AH,1
        CALL    CHKSUM                          ;  ...for valid checksum
        POP     DS                              ;  ...restore impure<-DS
        JZ      IC8259
        OR      Byte ptr DS:15h,ER_BIOS         ; Checksum error BIOS eprom

IC8259: CLI                                     ; Init interrupt controller
        MOV     AL,13h
        OUT     20h,AL
        MOV     AL,8
        OUT     21h,AL
        MOV     AL,9
        OUT     21h,AL
        MOV     AL,0FFh
        OUT     21h,AL
        PUSH    DS
        XOR     AX,AX                           ; 8 nonsense vectors begin table
        MOV     ES,AX                           ;  ...at segment 0000h
        PUSH    CS
        POP     DS
        MOV     CX,8                            ; Vectors 00h - 07h unused
        XOR     DI,DI                           ;  ...we start at vec 00h

LO_VEC: MOV     AX,offset IGNORE                ; Nonsense interrupt from RSX
        STOSW
        MOV     AX,CS                           ;  ...bios ROM segment
        STOSW
        LOOP    LO_VEC

        MOV     SI,offset VECTORS               ; SI --> Vector address table
        MOV     CX,18h                          ;  ... vectors 08h - 1Fh busy

HI_VEC: MOVSW                                   ; Get INTERRUPT bios ROM offset
        MOV     AX,CS
        STOSW                                   ;  ...INTERRUPT bios ROM segment
        LOOP    HI_VEC

        MOV     AX,0F600h                       ; AX --> Rom basic segment
        MOV     DS,AX                           ; DS -->  "    "     "
        XOR     BX,BX                           ; BX  =  Rom basic offset
        MOV     AH,4                            ; Four basic roms to check

        MOV     BP,SP                           ; Save the stack pointer
        PUSH    CS                              ;  ...push code segment
        MOV     DX,offset SKIP                  ; Save the code offset
        PUSH    DX                              ;  ...for RAM_PATCH subroutine
        MOV     DX,0EA90h                       ; Mov DX,'NOP,JMP_FAR'
        PUSH    DX                              ;  ...save it on stack
        MOV     DX,0178Bh                       ; Mov DX,'MOV DX,[BX]'
        PUSH    DX                              ;  ...save it on stack
        PUSH    SS                              ; Save stack segment
        MOV     DX,SP                           ;  ...get the stack offset
        ADD     DX,02h                          ;  ...calculate xfer addr.
        PUSH    DX                              ;  ...save it on the stack
;
        RETF                                    ; Test for BASIC rom
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       MOV     DX,[BX]                         ; Executes off the stack ;
;       JMPF    0F000h,SKIP                     ;       ...in RAM space  ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SKIP:   MOV     SP,BP                           ; Restore the stack pointer
        CMP     DL,DH                           ;  ...compare 1st and 2nd byte
        JE      kosher                          ;  ...perfection.  No piracy

B_ROM:  CALL    CHKSUM                          ; Scan for BASIC roms
        JNZ     kosher                          ;  ...bad basic rom
        DEC     AH                              ; Continue
        JNZ     B_ROM                           ;  ...yes, more

        POP     DS                              ; Else valid  basic
        MOV     DI,60h                          ;  ...install basic

        XOR     AX,AX                           ;  ...zero  BASIC interrupt
        STOSW                                   ;  ...offset
        MOV     AX,0F600h                       ;  ...F600h BASIC interrupt
        STOSW                                   ;  ...segment

        PUSH    DS
kosher: POP     DS                              ; Setup special low vectors
        MOV     Word ptr ES:8,offset int_2      ;  ...NMI interrupt
        MOV     Word ptr ES:14h,offset int_5    ;  ...print screen interrupt
        MOV     Word ptr ES:7Ch,0               ; No special graphics chars.
        MOV     Word ptr ES:7Eh,0               ;  ...so zero vector 1Fh
        MOV     DX,61h
        IN      AL,DX                           ; Read machine flags
        OR      AL,00110000b                    ;  ...clear old parity error
        OUT     DX,AL                           ; Write them back to reset
        AND     AL,11001111b                    ;  ...enable parity
        OUT     DX,AL                           ; Write back, parity enabled
        MOV     AL,80h                          ;  ...allow NMI interrupts
        OUT     0A0h,AL
        MOV     AX,0000000000110000b            ; Assume monochrome video
        MOV     DS:10h,AX                       ;  ...card has been installed
        INT     10h                             ;  ...initialize if present
        MOV     AX,0000000000100000b            ; Assume color/graphics video
        MOV     DS:10h,AX                       ;  ...card has been installed
        INT     10h                             ;  ...initialize if present
        IN      AL,62h                          ; Get memory size (64K bytes)
        AND     AL,00001111b                    ;  ...in bits 2,3 lo nibble
        MOV     AH,AL                           ; Save memory size nibble
        MOV     AL,10101101b
        OUT     61h,AL
        IN      AL,62h                          ; Get no. of floppies (0-3)
        MOV     CL,4                            ;  ...and init. video mode
        SHL     AL,CL                           ;  ...shift in hi nibble
        OR      AL,AH
        MOV     AH,0
        MOV     DS:10h,AX                       ; Start building Equipment Flag
        AND     AL,00110000b                    ;  ...if video card, mode set
        JNZ     LE232                           ;  ...found video interface
        MOV     AX,offset DUMMY                 ; No hardware, DUMMY: becomes
        MOV     ES:40h,AX                       ;  ...INT_10 video service
        JMP     short   LE235

LE232:  CALL    V_INIT                          ; Setup video

LE235:  MOV     AL,00001000b                    ; Read low switches
        OUT     61h,AL
        MOV     CX,2956h

WAIT_1: LOOP    WAIT_1
        MOV     AL,11001000b                    ; Keyboard acknowledge
        OUT     61h,AL                          ;  ...send the request
        XOR     AL,10000000b                    ; Toggle to enable
        OUT     61h,AL                          ;  ...send key enable
        MOV     AX,1Eh                          ; Offset to buffer start
        MOV     DS:1Ah,AX                       ; Buffer head pointer
        MOV     DS:1Ch,AX                       ; Buffer tail pointer
        MOV     DS:80h,AX                       ; Buffer start
        ADD     AX,20h                          ;  ...size
        MOV     DS:82h,AX                       ; Buffer end
        JMP     short   V_CONT

FAO:    MOV     DL,AL                           ; Formatted ascii output

FAO_1:  MOV     AX,BX                           ; Get position for
        CALL    LOCATE                          ;  ...cursor routine
        PUSH    SI                              ; Get string address
        CALL    PRINT                           ;  ...print string
        MOV     AX,ES:[BP+0]                    ; Get port # to print
        CALL    BIGNUM                          ;  ...four digits
        POP     SI                              ; Restore string address
        INC     BP                              ;  ...Address of port
        INC     BP                              ;  ...is two bytes long
        INC     BH                              ;  ...down one line
        DEC     DL                              ; Decrement device count
        JNZ     FAO_1                           ; ...back for more
        RET

K_BYTE: CLC                                     ; Say no error
        MOV     AL,DL                           ;  ...size "checked"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -