[90] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[3] | 2 | ; Description : Int 13h BIOS functions (Floppy and Hard disk). |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
| 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; Int 13h software interrupt handler. |
---|
| 9 | ; Jumps to specific function defined in AH. |
---|
| 10 | ; |
---|
[148] | 11 | ; Note to developers: Do not make recursive INT 13h calls! |
---|
| 12 | ; |
---|
| 13 | ; Int13h_DiskFunctionsHandler |
---|
[3] | 14 | ; Parameters: |
---|
| 15 | ; AH: Bios function |
---|
| 16 | ; DL: Drive number |
---|
[148] | 17 | ; Other: Depends on function |
---|
[3] | 18 | ; Returns: |
---|
| 19 | ; Depends on function |
---|
| 20 | ;-------------------------------------------------------------------- |
---|
| 21 | ALIGN JUMP_ALIGN |
---|
[148] | 22 | Int13h_DiskFunctionsHandler: |
---|
[3] | 23 | sti ; Enable interrupts |
---|
[150] | 24 | cld ; String instructions to increment pointers |
---|
[155] | 25 | CREATE_FRAME_INTPACK_TO_SSBP EXTRA_BYTES_FOR_INTPACK |
---|
[3] | 26 | |
---|
| 27 | call RamVars_GetSegmentToDS |
---|
[148] | 28 | call DriveXlate_ToOrBack |
---|
| 29 | mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl |
---|
[3] | 30 | call RamVars_IsFunctionHandledByThisBIOS |
---|
[258] | 31 | jc SHORT Int13h_DirectCallToAnotherBios |
---|
| 32 | |
---|
[148] | 33 | call FindDPT_ForDriveNumber ; DS:DI now points to DPT |
---|
[3] | 34 | |
---|
| 35 | ; Jump to correct BIOS function |
---|
[148] | 36 | eMOVZX bx, ah |
---|
| 37 | shl bx, 1 |
---|
[165] | 38 | cmp ah, 25h ; Possible EBIOS function? |
---|
[176] | 39 | %ifdef MODULE_EBIOS |
---|
[165] | 40 | ja SHORT .JumpToEbiosFunction |
---|
[176] | 41 | %else |
---|
| 42 | ja SHORT Int13h_UnsupportedFunction |
---|
| 43 | %endif |
---|
[148] | 44 | jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function |
---|
[3] | 45 | |
---|
[176] | 46 | %ifdef MODULE_EBIOS |
---|
[165] | 47 | ; Jump to correct EBIOS function |
---|
| 48 | ALIGN JUMP_ALIGN |
---|
| 49 | .JumpToEbiosFunction: |
---|
[167] | 50 | test BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA |
---|
| 51 | jz SHORT Int13h_UnsupportedFunction ; No eINT 13h for CHS drives |
---|
| 52 | cmp ah, 48h |
---|
[165] | 53 | ja SHORT Int13h_UnsupportedFunction |
---|
[181] | 54 | sub bl, 41h<<1 ; BX = Offset to eINT 13h jump table |
---|
| 55 | jb SHORT Int13h_UnsupportedFunction |
---|
[165] | 56 | jmp [cs:bx+g_rgwEbiosFunctionJumpTable] |
---|
[176] | 57 | %endif |
---|
[3] | 58 | |
---|
[260] | 59 | |
---|
[3] | 60 | ;-------------------------------------------------------------------- |
---|
[148] | 61 | ; Int13h_UnsupportedFunction |
---|
[3] | 62 | ; Int13h_DirectCallToAnotherBios |
---|
| 63 | ; Parameters: |
---|
[148] | 64 | ; DL: Translated drive number |
---|
[3] | 65 | ; DS: RAMVARS segment |
---|
[150] | 66 | ; SS:BP: Ptr to IDEPACK |
---|
[148] | 67 | ; BX, DI: Corrupted on Int13h_DiskFunctionsHandler |
---|
[161] | 68 | ; Other: Function specific INT 13h parameters |
---|
[3] | 69 | ; Returns: |
---|
| 70 | ; Depends on function |
---|
| 71 | ; Corrupts registers: |
---|
| 72 | ; Flags |
---|
| 73 | ;-------------------------------------------------------------------- |
---|
| 74 | ALIGN JUMP_ALIGN |
---|
| 75 | Int13h_UnsupportedFunction: |
---|
| 76 | Int13h_DirectCallToAnotherBios: |
---|
[148] | 77 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
[150] | 78 | mov bx, [bp+IDEPACK.intpack+INTPACK.bx] |
---|
| 79 | mov di, [bp+IDEPACK.intpack+INTPACK.di] |
---|
| 80 | mov ds, [bp+IDEPACK.intpack+INTPACK.ds] |
---|
| 81 | push WORD [bp+IDEPACK.intpack+INTPACK.flags] |
---|
[148] | 82 | popf |
---|
| 83 | push bp |
---|
[150] | 84 | mov bp, [bp+IDEPACK.intpack+INTPACK.bp] |
---|
[148] | 85 | int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants |
---|
[3] | 86 | |
---|
[148] | 87 | ; Store returned values to INTPACK |
---|
| 88 | pop bp ; Standard INT 13h functions never uses BP as return register |
---|
| 89 | %ifdef USE_386 |
---|
[150] | 90 | mov [bp+IDEPACK.intpack+INTPACK.gs], gs |
---|
| 91 | mov [bp+IDEPACK.intpack+INTPACK.fs], fs |
---|
[148] | 92 | %endif |
---|
[150] | 93 | mov [bp+IDEPACK.intpack+INTPACK.es], es |
---|
| 94 | mov [bp+IDEPACK.intpack+INTPACK.ds], ds |
---|
| 95 | mov [bp+IDEPACK.intpack+INTPACK.di], di |
---|
| 96 | mov [bp+IDEPACK.intpack+INTPACK.si], si |
---|
| 97 | mov [bp+IDEPACK.intpack+INTPACK.bx], bx |
---|
| 98 | mov [bp+IDEPACK.intpack+INTPACK.dh], dh |
---|
| 99 | mov [bp+IDEPACK.intpack+INTPACK.cx], cx |
---|
| 100 | mov [bp+IDEPACK.intpack+INTPACK.ax], ax |
---|
[148] | 101 | pushf |
---|
[150] | 102 | pop WORD [bp+IDEPACK.intpack+INTPACK.flags] |
---|
[148] | 103 | call RamVars_GetSegmentToDS |
---|
| 104 | cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] |
---|
| 105 | je SHORT .ExchangeInt13hHandlers |
---|
[150] | 106 | mov [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL |
---|
[148] | 107 | ALIGN JUMP_ALIGN |
---|
| 108 | .ExchangeInt13hHandlers: |
---|
[249] | 109 | %ifdef USE_186 |
---|
| 110 | push Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 111 | jmp SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
| 112 | %else |
---|
[148] | 113 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
[249] | 114 | jmp SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 115 | %endif |
---|
[3] | 116 | |
---|
[260] | 117 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 118 | ;-------------------------------------------------------------------- |
---|
| 119 | ; Int13h_ReturnSuccessForFloppy |
---|
| 120 | ; |
---|
| 121 | ; Some operations, such as format of a floppy disk track, should just |
---|
| 122 | ; return success, while for hard disks it should be treated as unsupported. |
---|
| 123 | ;-------------------------------------------------------------------- |
---|
| 124 | ALIGN JUMP_ALIGN |
---|
| 125 | Int13h_ReturnSuccessForFloppy: |
---|
| 126 | test dl, dl |
---|
| 127 | js short Int13h_UnsupportedFunction |
---|
| 128 | mov ah, 0 |
---|
| 129 | jmp short Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 130 | %endif |
---|
[3] | 131 | |
---|
| 132 | ;-------------------------------------------------------------------- |
---|
[249] | 133 | ; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL |
---|
| 134 | ; Parameters: |
---|
| 135 | ; AH: BIOS Error code |
---|
| 136 | ; CL: Number of sectors actually transferred |
---|
| 137 | ; SS:BP: Ptr to IDEPACK |
---|
| 138 | ; Returns: |
---|
| 139 | ; All registers are loaded from INTPACK |
---|
| 140 | ;-------------------------------------------------------------------- |
---|
| 141 | ALIGN JUMP_ALIGN |
---|
| 142 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL: |
---|
| 143 | mov [bp+IDEPACK.intpack+INTPACK.al], cl |
---|
| 144 | ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 145 | |
---|
| 146 | ;-------------------------------------------------------------------- |
---|
[148] | 147 | ; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH |
---|
| 148 | ; Int13h_ReturnFromHandlerWithoutStoringErrorCode |
---|
[32] | 149 | ; Parameters: |
---|
[148] | 150 | ; AH: BIOS Error code |
---|
[150] | 151 | ; SS:BP: Ptr to IDEPACK |
---|
[32] | 152 | ; Returns: |
---|
[148] | 153 | ; All registers are loaded from INTPACK |
---|
[32] | 154 | ;-------------------------------------------------------------------- |
---|
| 155 | ALIGN JUMP_ALIGN |
---|
[148] | 156 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH: |
---|
[258] | 157 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 158 | mov al, [bp+IDEPACK.intpack+INTPACK.dl] |
---|
| 159 | Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber: |
---|
| 160 | call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber |
---|
| 161 | %else |
---|
[150] | 162 | call Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH |
---|
[258] | 163 | %endif |
---|
[148] | 164 | Int13h_ReturnFromHandlerWithoutStoringErrorCode: |
---|
[150] | 165 | or WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled |
---|
[148] | 166 | mov sp, bp ; Now we can exit anytime |
---|
[155] | 167 | RESTORE_FRAME_INTPACK_FROM_SSBP EXTRA_BYTES_FOR_INTPACK |
---|
[32] | 168 | |
---|
| 169 | |
---|
| 170 | ;-------------------------------------------------------------------- |
---|
[148] | 171 | ; Int13h_CallPreviousInt13hHandler |
---|
[3] | 172 | ; Parameters: |
---|
[148] | 173 | ; AH: INT 13h function to call |
---|
| 174 | ; DL: Drive number |
---|
| 175 | ; DS: RAMVARS segment |
---|
[3] | 176 | ; Returns: |
---|
| 177 | ; Depends on function |
---|
[258] | 178 | ; NOTE: ES:DI needs to be returned from the previous interrupt |
---|
| 179 | ; handler, for floppy DPT in function 08h |
---|
[3] | 180 | ; Corrupts registers: |
---|
[258] | 181 | ; None |
---|
[3] | 182 | ;-------------------------------------------------------------------- |
---|
| 183 | ALIGN JUMP_ALIGN |
---|
[148] | 184 | Int13h_CallPreviousInt13hHandler: |
---|
| 185 | call ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
| 186 | int BIOS_DISK_INTERRUPT_13h |
---|
[258] | 187 | ;;; fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
[35] | 188 | |
---|
[3] | 189 | ;-------------------------------------------------------------------- |
---|
[148] | 190 | ; ExchangeCurrentInt13hHandlerWithOldInt13hHandler |
---|
[3] | 191 | ; Parameters: |
---|
| 192 | ; DS: RAMVARS segment |
---|
| 193 | ; Returns: |
---|
[148] | 194 | ; Nothing |
---|
[3] | 195 | ; Corrupts registers: |
---|
[258] | 196 | ; Nothing |
---|
| 197 | ; Note: Flags are preserved |
---|
[3] | 198 | ;-------------------------------------------------------------------- |
---|
| 199 | ALIGN JUMP_ALIGN |
---|
[148] | 200 | ExchangeCurrentInt13hHandlerWithOldInt13hHandler: |
---|
| 201 | push es |
---|
[258] | 202 | push si |
---|
| 203 | LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO es, si |
---|
| 204 | mov si, [RAMVARS.fpOldI13h] |
---|
[150] | 205 | cli |
---|
[258] | 206 | xchg si, [es:BIOS_DISK_INTERRUPT_13h*4] |
---|
| 207 | mov [RAMVARS.fpOldI13h], si |
---|
| 208 | mov si, [RAMVARS.fpOldI13h+2] |
---|
| 209 | xchg si, [es:BIOS_DISK_INTERRUPT_13h*4+2] |
---|
[181] | 210 | sti |
---|
[258] | 211 | mov [RAMVARS.fpOldI13h+2], si |
---|
| 212 | pop si |
---|
[148] | 213 | pop es |
---|
| 214 | ret |
---|
[28] | 215 | |
---|
[35] | 216 | |
---|
[150] | 217 | ;-------------------------------------------------------------------- |
---|
| 218 | ; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH |
---|
| 219 | ; Int13h_SetErrorCodeToIntpackInSSBPfromAH |
---|
| 220 | ; Parameters: |
---|
| 221 | ; AH: BIOS error code (00h = no error) |
---|
| 222 | ; SS:BP: Ptr to IDEPACK |
---|
| 223 | ; Returns: |
---|
| 224 | ; SS:BP: Ptr to IDEPACK with error condition set |
---|
| 225 | ; Corrupts registers: |
---|
| 226 | ; DS, DI |
---|
| 227 | ;-------------------------------------------------------------------- |
---|
| 228 | ALIGN JUMP_ALIGN |
---|
[258] | 229 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 230 | Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber: |
---|
| 231 | ; Store error code to BDA |
---|
| 232 | mov bx, BDA.bHDLastSt |
---|
| 233 | test al, al |
---|
| 234 | js .HardDisk |
---|
| 235 | mov bl, BDA.bFDRetST & 0xff |
---|
| 236 | .HardDisk: |
---|
| 237 | LOAD_BDA_SEGMENT_TO ds, di |
---|
| 238 | mov [bx], ah |
---|
| 239 | %else |
---|
[150] | 240 | Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH: |
---|
| 241 | ; Store error code to BDA |
---|
[258] | 242 | LOAD_BDA_SEGMENT_TO ds, di |
---|
[150] | 243 | mov [BDA.bHDLastSt], ah |
---|
[258] | 244 | %endif |
---|
[35] | 245 | |
---|
[150] | 246 | ; Store error code to INTPACK |
---|
| 247 | Int13h_SetErrorCodeToIntpackInSSBPfromAH: |
---|
| 248 | mov [bp+IDEPACK.intpack+INTPACK.ah], ah |
---|
| 249 | test ah, ah |
---|
| 250 | jnz SHORT .SetCFtoIntpack |
---|
| 251 | and BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF |
---|
| 252 | ret |
---|
| 253 | .SetCFtoIntpack: |
---|
| 254 | or BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF |
---|
| 255 | ret |
---|
| 256 | |
---|
| 257 | |
---|
[3] | 258 | ; Jump table for correct BIOS function |
---|
| 259 | ALIGN WORD_ALIGN |
---|
| 260 | g_rgw13hFuncJump: |
---|
| 261 | dw AH0h_HandlerForDiskControllerReset ; 00h, Disk Controller Reset (All) |
---|
| 262 | dw AH1h_HandlerForReadDiskStatus ; 01h, Read Disk Status (All) |
---|
| 263 | dw AH2h_HandlerForReadDiskSectors ; 02h, Read Disk Sectors (All) |
---|
| 264 | dw AH3h_HandlerForWriteDiskSectors ; 03h, Write Disk Sectors (All) |
---|
| 265 | dw AH4h_HandlerForVerifyDiskSectors ; 04h, Verify Disk Sectors (All) |
---|
[260] | 266 | %ifdef MODULE_SERIAL_FLOPPY |
---|
| 267 | dw Int13h_ReturnSuccessForFloppy ; 05h, Format Disk Track (XT, AT, EISA) |
---|
| 268 | %else |
---|
[90] | 269 | dw Int13h_UnsupportedFunction ; 05h, Format Disk Track (XT, AT, EISA) |
---|
[260] | 270 | %endif |
---|
[3] | 271 | dw Int13h_UnsupportedFunction ; 06h, Format Disk Track with Bad Sectors (XT) |
---|
| 272 | dw Int13h_UnsupportedFunction ; 07h, Format Multiple Cylinders (XT) |
---|
| 273 | dw AH8h_HandlerForReadDiskDriveParameters ; 08h, Read Disk Drive Parameters (All) |
---|
| 274 | dw AH9h_HandlerForInitializeDriveParameters ; 09h, Initialize Drive Parameters (All) |
---|
| 275 | dw Int13h_UnsupportedFunction ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA) |
---|
| 276 | dw Int13h_UnsupportedFunction ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA) |
---|
| 277 | dw AHCh_HandlerForSeek ; 0Ch, Seek (All) |
---|
| 278 | dw AHDh_HandlerForResetHardDisk ; 0Dh, Alternate Disk Reset (All) |
---|
| 279 | dw Int13h_UnsupportedFunction ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2) |
---|
| 280 | dw Int13h_UnsupportedFunction ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2) |
---|
| 281 | dw AH10h_HandlerForCheckDriveReady ; 10h, Check Drive Ready (All) |
---|
| 282 | dw AH11h_HandlerForRecalibrate ; 11h, Recalibrate (All) |
---|
| 283 | dw Int13h_UnsupportedFunction ; 12h, Controller RAM Diagnostic (XT) |
---|
| 284 | dw Int13h_UnsupportedFunction ; 13h, Drive Diagnostic (XT) |
---|
[90] | 285 | dw Int13h_UnsupportedFunction ; 14h, Controller Internal Diagnostic (All) |
---|
[3] | 286 | dw AH15h_HandlerForReadDiskDriveSize ; 15h, Read Disk Drive Size (AT+) |
---|
[161] | 287 | dw Int13h_UnsupportedFunction ; 16h, |
---|
| 288 | dw Int13h_UnsupportedFunction ; 17h, |
---|
| 289 | dw Int13h_UnsupportedFunction ; 18h, |
---|
[3] | 290 | dw Int13h_UnsupportedFunction ; 19h, Park Heads (PS/2) |
---|
| 291 | dw Int13h_UnsupportedFunction ; 1Ah, Format ESDI Drive (PS/2) |
---|
| 292 | dw Int13h_UnsupportedFunction ; 1Bh, Get ESDI Manufacturing Header (PS/2) |
---|
| 293 | dw Int13h_UnsupportedFunction ; 1Ch, ESDI Special Functions (PS/2) |
---|
[161] | 294 | dw Int13h_UnsupportedFunction ; 1Dh, |
---|
| 295 | dw Int13h_UnsupportedFunction ; 1Eh, |
---|
| 296 | dw Int13h_UnsupportedFunction ; 1Fh, |
---|
| 297 | dw Int13h_UnsupportedFunction ; 20h, |
---|
[3] | 298 | dw Int13h_UnsupportedFunction ; 21h, Read Disk Sectors, Multiple Blocks (PS/1) |
---|
| 299 | dw Int13h_UnsupportedFunction ; 22h, Write Disk Sectors, Multiple Blocks (PS/1) |
---|
| 300 | dw AH23h_HandlerForSetControllerFeatures ; 23h, Set Controller Features Register (PS/1) |
---|
| 301 | dw AH24h_HandlerForSetMultipleBlocks ; 24h, Set Multiple Blocks (PS/1) |
---|
| 302 | dw AH25h_HandlerForGetDriveInformation ; 25h, Get Drive Information (PS/1) |
---|
[165] | 303 | |
---|
[176] | 304 | %ifdef MODULE_EBIOS |
---|
[165] | 305 | g_rgwEbiosFunctionJumpTable: |
---|
| 306 | dw AH41h_HandlerForCheckIfExtensionsPresent ; 41h, Check if Extensions Present (EBIOS)* |
---|
| 307 | dw AH42h_HandlerForExtendedReadSectors ; 42h, Extended Read Sectors (EBIOS)* |
---|
| 308 | dw AH43h_HandlerForExtendedWriteSectors ; 43h, Extended Write Sectors (EBIOS)* |
---|
| 309 | dw AH44h_HandlerForExtendedVerifySectors ; 44h, Extended Verify Sectors (EBIOS)* |
---|
| 310 | dw Int13h_UnsupportedFunction ; 45h, Lock and Unlock Drive (EBIOS)*** |
---|
| 311 | dw Int13h_UnsupportedFunction ; 46h, Eject Media Request (EBIOS)*** |
---|
| 312 | dw AH47h_HandlerForExtendedSeek ; 47h, Extended Seek (EBIOS)* |
---|
| 313 | dw AH48h_HandlerForGetExtendedDriveParameters ; 48h, Get Extended Drive Parameters (EBIOS)* |
---|
[150] | 314 | ; dw Int13h_UnsupportedFunction ; 49h, Get Extended Disk Change Status (EBIOS)*** |
---|
[3] | 315 | ; dw Int13h_UnsupportedFunction ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM) |
---|
| 316 | ; dw Int13h_UnsupportedFunction ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM) |
---|
| 317 | ; dw Int13h_UnsupportedFunction ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM) |
---|
| 318 | ; dw Int13h_UnsupportedFunction ; 4Dh, Return Boot Catalog (Bootable CD-ROM) |
---|
[150] | 319 | ; dw Int13h_UnsupportedFunction ; 4Eh, Set Hardware Configuration (EBIOS)** |
---|
| 320 | ; |
---|
| 321 | ; * = Enhanced Drive Access Support (minimum required EBIOS functions) |
---|
| 322 | ; ** = Enhanced Disk Drive (EDD) Support |
---|
| 323 | ; *** = Drive Locking and Ejecting Support |
---|
[181] | 324 | %endif |
---|