[90] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Int 19h BIOS functions (Boot Strap Loader).
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
| 7 | B_READ_RETRY_TIMES EQU 3 ; Number of times to retry
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | ;--------------------------------------------------------------------
|
---|
| 11 | ; Boots if boot sector is successfully read from the drive.
|
---|
| 12 | ;
|
---|
| 13 | ; Int19h_TryToLoadBootSectorFromDL
|
---|
| 14 | ; Parameters:
|
---|
| 15 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 16 | ; DS: RAMVARS segment
|
---|
| 17 | ; Returns:
|
---|
| 18 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 19 | ; CF: Set if boot sector loaded succesfully
|
---|
| 20 | ; Cleared if failed to load boot sector
|
---|
| 21 | ; Corrupts registers:
|
---|
| 22 | ; AX, CX, DH, DI, (DL if failed to read boot sector)
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
| 24 | ALIGN JUMP_ALIGN
|
---|
| 25 | Int19h_TryToLoadBootSectorFromDL:
|
---|
| 26 | call BootPrint_TryToBootFromDL
|
---|
| 27 | call Int19h_LoadFirstSectorFromDL
|
---|
| 28 | jc SHORT .FailedToLoadFirstSector
|
---|
[61] | 29 |
|
---|
| 30 | test dl, 80h
|
---|
| 31 | jz SHORT .AlwaysBootFromFloppyDriveForBooterGames
|
---|
[3] | 32 | cmp WORD [es:bx+510], 0AA55h ; Valid boot sector?
|
---|
[61] | 33 | jne SHORT .FirstHardDiskSectorNotBootable
|
---|
| 34 | .AlwaysBootFromFloppyDriveForBooterGames:
|
---|
[3] | 35 | call BootPrint_BootSectorLoaded
|
---|
| 36 | stc
|
---|
| 37 | ret
|
---|
| 38 | .FailedToLoadFirstSector:
|
---|
| 39 | call BootPrint_FailedToLoadFirstSector
|
---|
| 40 | clc
|
---|
| 41 | ret
|
---|
[61] | 42 | .FirstHardDiskSectorNotBootable:
|
---|
[3] | 43 | call BootPrint_FirstSectorNotBootable
|
---|
| 44 | clc
|
---|
| 45 | ret
|
---|
| 46 |
|
---|
| 47 | ;--------------------------------------------------------------------
|
---|
| 48 | ; Reads first sector (boot sector) from drive DL.
|
---|
| 49 | ;
|
---|
| 50 | ; Int19h_LoadFirstSectorFromDL
|
---|
| 51 | ; Parameters:
|
---|
| 52 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 53 | ; Returns:
|
---|
| 54 | ; AH: INT 13h error code
|
---|
| 55 | ; ES:BX: Ptr to boot sector (if successfull)
|
---|
| 56 | ; CF: Cleared if read successfull
|
---|
| 57 | ; Set if any error
|
---|
| 58 | ; Corrupts registers:
|
---|
| 59 | ; AL, CX, DH, DI
|
---|
| 60 | ;--------------------------------------------------------------------
|
---|
| 61 | ALIGN JUMP_ALIGN
|
---|
| 62 | Int19h_LoadFirstSectorFromDL:
|
---|
| 63 | LOAD_BDA_SEGMENT_TO es, bx ; ES:BX now points to...
|
---|
| 64 | mov bx, BOOTVARS.rgbBootSect ; ...boot sector location
|
---|
| 65 | mov di, B_READ_RETRY_TIMES ; Retry counter
|
---|
| 66 | ALIGN JUMP_ALIGN
|
---|
| 67 | .ReadRetryLoop:
|
---|
[28] | 68 | call .ResetBootDriveFromDL
|
---|
| 69 | call .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 70 | jnc SHORT .Return
|
---|
| 71 | dec di ; Decrement retry counter
|
---|
| 72 | jnz SHORT .ReadRetryLoop ; Loop while retries left
|
---|
| 73 | ALIGN JUMP_ALIGN
|
---|
| 74 | .Return:
|
---|
| 75 | ret
|
---|
| 76 |
|
---|
| 77 | ;--------------------------------------------------------------------
|
---|
[28] | 78 | ; .ResetBootDriveFromDL
|
---|
[3] | 79 | ; Parameters:
|
---|
| 80 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 81 | ; Returns:
|
---|
| 82 | ; AH: INT 13h error code
|
---|
| 83 | ; CF: Cleared if read successfull
|
---|
| 84 | ; Set if any error
|
---|
| 85 | ; Corrupts registers:
|
---|
[28] | 86 | ; AL
|
---|
[3] | 87 | ;--------------------------------------------------------------------
|
---|
| 88 | ALIGN JUMP_ALIGN
|
---|
[28] | 89 | .ResetBootDriveFromDL:
|
---|
| 90 | xor ax, ax ; AH=0h, Disk Controller Reset
|
---|
| 91 | test dl, 80h ; Floppy drive?
|
---|
| 92 | jz SHORT .ResetDriveFromDL ; If so, jump to reset
|
---|
| 93 | mov ah, 0Dh ; AH=Dh, Reset Hard Disk (Alternate reset)
|
---|
| 94 | .ResetDriveFromDL:
|
---|
[3] | 95 | int INTV_DISK_FUNC
|
---|
| 96 | ret
|
---|
| 97 |
|
---|
| 98 | ;--------------------------------------------------------------------
|
---|
[28] | 99 | ; Reads first sector (boot sector) from drive DL to ES:BX.
|
---|
[3] | 100 | ;
|
---|
[28] | 101 | ; .LoadFirstSectorFromDLtoESBX
|
---|
[3] | 102 | ; Parameters:
|
---|
| 103 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
[28] | 104 | ; ES:BX: Destination buffer for boot sector
|
---|
[3] | 105 | ; Returns:
|
---|
[28] | 106 | ; AH: INT 13h error code
|
---|
| 107 | ; ES:BX: Ptr to boot sector
|
---|
| 108 | ; CF: Cleared if read successfull
|
---|
| 109 | ; Set if any error
|
---|
[3] | 110 | ; Corrupts registers:
|
---|
[28] | 111 | ; AL, CX, DH
|
---|
[3] | 112 | ;--------------------------------------------------------------------
|
---|
| 113 | ALIGN JUMP_ALIGN
|
---|
[28] | 114 | .LoadFirstSectorFromDLtoESBX:
|
---|
| 115 | mov ax, 0201h ; Read 1 sector
|
---|
| 116 | mov cx, 1 ; Cylinder 0, Sector 1
|
---|
| 117 | xor dh, dh ; Head 0
|
---|
[3] | 118 | int INTV_DISK_FUNC
|
---|
| 119 | ret
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | ;--------------------------------------------------------------------
|
---|
| 123 | ; Jumps to boot sector pointed by ES:BX.
|
---|
| 124 | ;
|
---|
| 125 | ; Int19h_JumpToBootSector
|
---|
| 126 | ; Parameters:
|
---|
| 127 | ; DL: Drive to boot from (translated, 00h or 80h)
|
---|
| 128 | ; ES:BX: Ptr to boot sector
|
---|
| 129 | ; Returns:
|
---|
| 130 | ; Never returns
|
---|
| 131 | ;--------------------------------------------------------------------
|
---|
| 132 | ALIGN JUMP_ALIGN
|
---|
| 133 | Int19h_JumpToBootSector:
|
---|
| 134 | push es ; Push boot sector segment
|
---|
| 135 | push bx ; Push boot sector offset
|
---|
| 136 | call Int19h_ClearSegmentsForBoot
|
---|
| 137 | xor dh, dh ; Device supported by INT 13h
|
---|
| 138 | retf
|
---|
| 139 |
|
---|
| 140 | ;--------------------------------------------------------------------
|
---|
| 141 | ; Clears DS and ES registers to zero.
|
---|
| 142 | ;
|
---|
| 143 | ; Int19h_ClearSegmentsForBoot
|
---|
| 144 | ; Parameters:
|
---|
| 145 | ; Nothing
|
---|
| 146 | ; Returns:
|
---|
| 147 | ; DS=ES: Zero
|
---|
| 148 | ; Corrupts registers:
|
---|
| 149 | ; AX
|
---|
| 150 | ;--------------------------------------------------------------------
|
---|
| 151 | ALIGN JUMP_ALIGN
|
---|
| 152 | Int19h_ClearSegmentsForBoot:
|
---|
| 153 | xor ax, ax
|
---|
| 154 | mov ds, ax
|
---|
| 155 | mov es, ax
|
---|
| 156 | ret
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | ;--------------------------------------------------------------------
|
---|
| 160 | ; Calls INT 18h (ROM Basic or Boot Failure). Called after booting from
|
---|
| 161 | ; floppy drive or hard disk fails.
|
---|
| 162 | ;
|
---|
| 163 | ; Int19h_BootFailure
|
---|
| 164 | ; Parameters:
|
---|
| 165 | ; Nothing
|
---|
| 166 | ; Returns:
|
---|
| 167 | ; Should never return (but might)
|
---|
| 168 | ;--------------------------------------------------------------------
|
---|
| 169 | ALIGN JUMP_ALIGN
|
---|
| 170 | Int19h_BootFailure:
|
---|
| 171 | call Int19h_ClearSegmentsForBoot
|
---|
| 172 | int INTV_BOOT_FAILURE
|
---|
| 173 | ret
|
---|