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