Changeset 148 in xtideuniversalbios for trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
- Timestamp:
- Mar 19, 2011, 8:09:41 PM (13 years ago)
- google:author:
- aitotat
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm
r90 r148 4 4 ; Section containing code 5 5 SECTION .text 6 7 ;--------------------------------------------------------------------8 ; Macro that prints drive and function number.9 ; Used only for debugging.10 ;11 ; DEBUG_PRINT_DRIVE_AND_FUNCTION12 ; Parameters:13 ; AH: INT 13h function number14 ; DL: Drive number15 ; Returns:16 ; Nothing17 ; Corrupts registers:18 ; Nothing19 ;--------------------------------------------------------------------20 %macro DEBUG_PRINT_DRIVE_AND_FUNCTION 021 push dx22 push ax23 mov al, dl24 call Print_IntHexW25 pop ax26 pop dx27 %endmacro28 29 6 30 7 ;-------------------------------------------------------------------- … … 32 9 ; Jumps to specific function defined in AH. 33 10 ; 34 ; Int13h_Jump 11 ; Note to developers: Do not make recursive INT 13h calls! 12 ; 13 ; Int13h_DiskFunctionsHandler 35 14 ; Parameters: 36 15 ; AH: Bios function 37 16 ; DL: Drive number 17 ; Other: Depends on function 18 ; Returns: 19 ; Depends on function 20 ;-------------------------------------------------------------------- 21 ALIGN JUMP_ALIGN 22 Int13h_DiskFunctionsHandler: 23 sti ; Enable interrupts 24 SAVE_AND_GET_INTPACK_TO_SSBP 25 26 call RamVars_GetSegmentToDS 27 call DriveXlate_ToOrBack 28 mov [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl 29 call RamVars_IsFunctionHandledByThisBIOS 30 jnc SHORT Int13h_DirectCallToAnotherBios 31 call FindDPT_ForDriveNumber ; DS:DI now points to DPT 32 33 ; Jump to correct BIOS function 34 JumpToBiosFunctionInAH: 35 cmp ah, 25h ; Valid BIOS function? 36 ja SHORT Int13h_UnsupportedFunction 37 eMOVZX bx, ah 38 shl bx, 1 39 jmp [cs:bx+g_rgw13hFuncJump] ; Jump to BIOS function 40 41 42 ;-------------------------------------------------------------------- 43 ; Int13h_UnsupportedFunction 44 ; Int13h_DirectCallToAnotherBios 45 ; Parameters: 46 ; DL: Translated drive number 47 ; DS: RAMVARS segment 48 ; SS:BP: Ptr to INTPACK 49 ; BX, DI: Corrupted on Int13h_DiskFunctionsHandler 50 ; Other: Function specific INT 13h parameters 38 51 ; Returns: 39 52 ; Depends on function … … 42 55 ;-------------------------------------------------------------------- 43 56 ALIGN JUMP_ALIGN 44 Int13h_DiskFunctions: 45 ; Save registers 46 sti ; Enable interrupts 47 push ds ; Store DS 48 push di ; Store DI 49 50 ;DEBUG_PRINT_DRIVE_AND_FUNCTION 57 Int13h_UnsupportedFunction: 58 Int13h_DirectCallToAnotherBios: 59 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler 60 mov bx, [bp+INTPACK.bx] 61 mov di, [bp+INTPACK.di] 62 mov ds, [bp+INTPACK.ds] 63 push WORD [bp+INTPACK.flags] 64 popf 65 push bp 66 mov bp, [bp+INTPACK.bp] 67 int BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants 68 69 ; Store returned values to INTPACK 70 pop bp ; Standard INT 13h functions never uses BP as return register 71 %ifdef USE_386 72 mov [bp+INTPACK.gs], gs 73 mov [bp+INTPACK.fs], fs 74 %endif 75 mov [bp+INTPACK.es], es 76 mov [bp+INTPACK.ds], ds 77 mov [bp+INTPACK.di], di 78 mov [bp+INTPACK.si], si 79 mov [bp+INTPACK.bx], bx 80 mov [bp+INTPACK.dh], dh 81 mov [bp+INTPACK.cx], cx 82 mov [bp+INTPACK.ax], ax 83 pushf 84 pop WORD [bp+INTPACK.flags] 51 85 call RamVars_GetSegmentToDS 52 call DriveXlate_WhenEnteringInt13h 53 call RamVars_IsFunctionHandledByThisBIOS 54 jnc SHORT Int13h_DirectCallToAnotherBios 55 ;DEBUG_PRINT_DRIVE_AND_FUNCTION 56 57 ; Jump to correct BIOS function 58 cmp ah, 25h ; Valid BIOS function? 59 ja SHORT Int13h_UnsupportedFunction 60 mov di, ax 61 %ifndef USE_186 ; This uses 9 bytes less and is about 5 cycles faster 62 mov al, ah ; Copy bits in AH to AL and then 63 shl al, 1 ; shift them "back" 1 step 64 and al, 7Eh ; AND them (clears the MSB) 65 cbw ; Clear AH using sign extension 66 xchg di, ax ; and finally swap DI with AX 67 %else 68 eSHR_IM di, 7 ; Shift function to DI... 69 and di, BYTE 7Eh ; ...and prepare for word lookup 70 %endif 71 jmp [cs:di+g_rgw13hFuncJump] ; Jump to BIOS function 72 73 74 ;-------------------------------------------------------------------- 75 ; Directs call to another INT13h function whose pointer is 76 ; stored to RAMVARS. 77 ; 78 ; Int13h_DirectCallToAnotherBios 79 ; Parameters: 80 ; AH: Bios function 86 cmp dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv] 87 je SHORT .ExchangeInt13hHandlers 88 mov [bp+INTPACK.dl], dl ; Something is returned in DL 89 ALIGN JUMP_ALIGN 90 .ExchangeInt13hHandlers: 91 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler 92 ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH 93 94 95 ;-------------------------------------------------------------------- 96 ; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH 97 ; Int13h_ReturnFromHandlerWithoutStoringErrorCode 98 ; Parameters: 99 ; AH: BIOS Error code 100 ; SS:BP: Ptr to INTPACK 101 ; Returns: 102 ; All registers are loaded from INTPACK 103 ;-------------------------------------------------------------------- 104 ALIGN JUMP_ALIGN 105 Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH: 106 call HError_SetErrorCodeToBdaAndToIntpackInSSBPfromAH 107 Int13h_ReturnFromHandlerWithoutStoringErrorCode: 108 or WORD [bp+INTPACK.flags], FLG_FLAGS_IF ; Return with interrupts enabled 109 mov sp, bp ; Now we can exit anytime 110 RESTORE_INTPACK_FROM_SSBP 111 112 113 ;-------------------------------------------------------------------- 114 ; Int13h_CallPreviousInt13hHandler 115 ; Parameters: 116 ; AH: INT 13h function to call 81 117 ; DL: Drive number 82 118 ; DS: RAMVARS segment 83 ; DI: Corrupted84 ; Stack from top to down:85 ; Original DI86 ; Original DS87 119 ; Returns: 88 120 ; Depends on function 89 121 ; Corrupts registers: 90 ; Flags 91 ;-------------------------------------------------------------------- 92 ALIGN JUMP_ALIGN 93 Int13h_UnsupportedFunction: 94 Int13h_DirectCallToAnotherBios: 95 ; Temporarily store original DI and DS from stack to RAMVARS 96 pop WORD [RAMVARS.wI13hDI] 97 pop WORD [RAMVARS.wI13hDS] 98 99 ; Special return processing required if target function 100 ; returns something in DL 101 mov di, Int13h_ReturnFromAnotherBiosWithValueInDL 102 call DriveXlate_DoesFunctionReturnSomethingInDL 103 jc SHORT .PushIretAddress 104 add di, BYTE Int13h_ReturnFromAnotherBios - Int13h_ReturnFromAnotherBiosWithValueInDL 105 .PushIretAddress: 106 pushf ; Push FLAGS to simulate INT 107 push cs ; Push return segment 108 push di ; Push return offset 109 110 ; "Return" to another INT 13h with original DI and DS 111 push WORD [RAMVARS.fpOldI13h+2] ; Segment 112 push WORD [RAMVARS.fpOldI13h] ; Offset 113 lds di, [RAMVARS.dwI13DIDS] 114 cli ; Disable interrupts as INT would 115 retf 116 117 118 ;-------------------------------------------------------------------- 119 ; Int13h_CallPreviousInt13hHandler 120 ; Parameters: 121 ; AH: Bios function 122 ; BX, DI, ES 123 ;-------------------------------------------------------------------- 124 ALIGN JUMP_ALIGN 125 Int13h_CallPreviousInt13hHandler: 126 push di 127 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler 128 int BIOS_DISK_INTERRUPT_13h 129 call ExchangeCurrentInt13hHandlerWithOldInt13hHandler 130 pop di 131 ret 132 133 134 ;-------------------------------------------------------------------- 135 ; ExchangeCurrentInt13hHandlerWithOldInt13hHandler 136 ; Parameters: 122 137 ; DS: RAMVARS segment 123 ; Other: Depends on function to call 124 ; Returns: 125 ; Depends on function to call 138 ; Returns: 139 ; Nothing 126 140 ; Corrupts registers: 127 ; Nothing 128 ;-------------------------------------------------------------------- 129 ALIGN JUMP_ALIGN 130 Int13h_CallPreviousInt13hHandler: 131 pushf ; Push flags to simulate INT 132 cli ; Disable interrupts since INT does that 133 call FAR [RAMVARS.fpOldI13h] 134 sti 141 ; DI 142 ;-------------------------------------------------------------------- 143 ALIGN JUMP_ALIGN 144 ExchangeCurrentInt13hHandlerWithOldInt13hHandler: 145 push es 146 LOAD_BDA_SEGMENT_TO es, di 147 mov di, [RAMVARS.fpOldI13h] 148 xchg di, [es:BIOS_DISK_INTERRUPT_13h*4] 149 mov [RAMVARS.fpOldI13h], di 150 mov di, [RAMVARS.fpOldI13h+2] 151 xchg di, [es:BIOS_DISK_INTERRUPT_13h*4+2] 152 mov [RAMVARS.fpOldI13h+2], di 153 pop es 135 154 ret 136 155 137 138 ;--------------------------------------------------------------------139 ; Int13h_ReturnFromAnotherBiosWithValueInDL140 ; Int13h_ReturnFromAnotherBios141 ; Parameters:142 ; AH: Error code143 ; DL: Drive number (only on Int13h_ReturnFromAnotherBios)144 ; CF: Error status145 ; Returns:146 ; Depends on function147 ; Corrupts registers:148 ; Nothing (not even FLAGS)149 ;--------------------------------------------------------------------150 ALIGN JUMP_ALIGN151 Int13h_ReturnFromAnotherBiosWithValueInDL:152 push ds153 push di154 pushf ; Store return flags155 call RamVars_GetSegmentToDS156 call DriveXlate_WhenLeavingInt13hWithReturnValueInDL157 jmp SHORT Int13h_Leave158 159 ALIGN JUMP_ALIGN160 Int13h_ReturnFromAnotherBios:161 push ds162 push di163 pushf ; Store return flags164 call RamVars_GetSegmentToDS165 call DriveXlate_WhenLeavingInt13h166 jmp SHORT Int13h_Leave167 168 169 ;--------------------------------------------------------------------170 ; Returns from any BIOS function implemented by this BIOS.171 ;172 ; Int13h_ReturnWithValueInDL173 ; Int13h_PopXRegsAndReturn174 ; Int13h_PopDiDsAndReturn175 ; Parameters:176 ; DL: Drive number (not Int13h_ReturnWithoutSwappingDrives)177 ; DS: RAMVARS segment178 ; Returns:179 ; Depends on function180 ; Corrupts registers:181 ; Nothing (not even FLAGS)182 ;--------------------------------------------------------------------183 ALIGN JUMP_ALIGN184 Int13h_ReturnWithValueInDL:185 pushf186 call DriveXlate_WhenLeavingInt13hWithReturnValueInDL187 jmp SHORT Int13h_LeaveAfterStoringErrorCodeToBDA188 189 ALIGN JUMP_ALIGN190 Int13h_PopXRegsAndReturn:191 pop bx ; Pop old AX to BX192 mov al, bl ; Restore AL193 pop bx194 pop cx195 pop dx196 ; Fall to Int13h_PopDiDsAndReturn197 198 ALIGN JUMP_ALIGN199 Int13h_PopDiDsAndReturn:200 pushf201 call DriveXlate_WhenLeavingInt13h202 ; Fall to Int13h_LeaveAfterStoringErrorCodeToBDA203 204 Int13h_LeaveAfterStoringErrorCodeToBDA:205 LOAD_BDA_SEGMENT_TO ds, di206 mov [BDA.bHDStatus], ah207 ; Fall to Int13h_Leave208 209 Int13h_Leave:210 popf211 pop di212 pop ds213 retf 2214 156 215 157
Note: See TracChangeset
for help on using the changeset viewer.