source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Handlers/Int13h.asm @ 155

Last change on this file since 155 was 155, checked in by aitotat, 13 years ago

Changes to XTIDE Universal BIOS:

  • AH=4h again uses VERIFY command (copy-pasting had changed it to WRITE).
  • Timeout should now work on all overflow situations.
  • Cleaned code a bit.
File size: 11.1 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h BIOS functions (Floppy and Hard disk).
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h software interrupt handler.
9; Jumps to specific function defined in AH.
10;
11; Note to developers: Do not make recursive INT 13h calls!
12;
13; Int13h_DiskFunctionsHandler
14;   Parameters:
15;       AH:     Bios function
16;       DL:     Drive number
17;       Other:  Depends on function
18;   Returns:
19;       Depends on function
20;--------------------------------------------------------------------
21ALIGN JUMP_ALIGN
22Int13h_DiskFunctionsHandler:
23    sti                                 ; Enable interrupts
24    cld                                 ; String instructions to increment pointers
25    CREATE_FRAME_INTPACK_TO_SSBP    EXTRA_BYTES_FOR_INTPACK
26
27    call    RamVars_GetSegmentToDS
28    call    DriveXlate_ToOrBack
29    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
30    call    RamVars_IsFunctionHandledByThisBIOS
31    jnc     SHORT Int13h_DirectCallToAnotherBios
32    call    FindDPT_ForDriveNumber      ; DS:DI now points to DPT
33
34    ; Jump to correct BIOS function
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 IDEPACK
49;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
50;       Other:  Function specific INT 13h parameters 
51;   Returns:
52;       Depends on function
53;   Corrupts registers:
54;       Flags
55;--------------------------------------------------------------------
56ALIGN JUMP_ALIGN
57Int13h_UnsupportedFunction:
58Int13h_DirectCallToAnotherBios:
59    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
60    mov     bx, [bp+IDEPACK.intpack+INTPACK.bx]
61    mov     di, [bp+IDEPACK.intpack+INTPACK.di]
62    mov     ds, [bp+IDEPACK.intpack+INTPACK.ds]
63    push    WORD [bp+IDEPACK.intpack+INTPACK.flags]
64    popf
65    push    bp
66    mov     bp, [bp+IDEPACK.intpack+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+IDEPACK.intpack+INTPACK.gs], gs
73    mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
74%endif
75    mov     [bp+IDEPACK.intpack+INTPACK.es], es
76    mov     [bp+IDEPACK.intpack+INTPACK.ds], ds
77    mov     [bp+IDEPACK.intpack+INTPACK.di], di
78    mov     [bp+IDEPACK.intpack+INTPACK.si], si
79    mov     [bp+IDEPACK.intpack+INTPACK.bx], bx
80    mov     [bp+IDEPACK.intpack+INTPACK.dh], dh
81    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
82    mov     [bp+IDEPACK.intpack+INTPACK.ax], ax
83    pushf
84    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
85    call    RamVars_GetSegmentToDS
86    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
87    je      SHORT .ExchangeInt13hHandlers
88    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl     ; Something is returned in DL
89ALIGN 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 IDEPACK
101;   Returns:
102;       All registers are loaded from INTPACK
103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
105Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
106    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
107Int13h_ReturnFromHandlerWithoutStoringErrorCode:
108    or      WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF   ; Return with interrupts enabled
109    mov     sp, bp                                  ; Now we can exit anytime
110    RESTORE_FRAME_INTPACK_FROM_SSBP     EXTRA_BYTES_FOR_INTPACK
111
112
113;--------------------------------------------------------------------
114; Int13h_CallPreviousInt13hHandler
115;   Parameters:
116;       AH:     INT 13h function to call
117;       DL:     Drive number
118;       DS:     RAMVARS segment
119;   Returns:
120;       Depends on function
121;   Corrupts registers:
122;       BX, DI, ES
123;--------------------------------------------------------------------
124ALIGN JUMP_ALIGN
125Int13h_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:
137;       DS:     RAMVARS segment
138;   Returns:
139;       Nothing
140;   Corrupts registers:
141;       DI
142;--------------------------------------------------------------------
143ALIGN JUMP_ALIGN
144ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
145    push    es
146    LOAD_BDA_SEGMENT_TO es, di
147    mov     di, [RAMVARS.fpOldI13h]
148    cli
149    xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4]
150    mov     [RAMVARS.fpOldI13h], di
151    mov     di, [RAMVARS.fpOldI13h+2]
152    xchg    di, [es:BIOS_DISK_INTERRUPT_13h*4+2]
153    mov     [RAMVARS.fpOldI13h+2], di
154    pop     es
155    sti
156    ret
157
158
159;--------------------------------------------------------------------
160; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
161; Int13h_SetErrorCodeToIntpackInSSBPfromAH
162;   Parameters:
163;       AH:     BIOS error code (00h = no error)
164;       SS:BP:  Ptr to IDEPACK
165;   Returns:
166;       SS:BP:  Ptr to IDEPACK with error condition set
167;   Corrupts registers:
168;       DS, DI
169;--------------------------------------------------------------------
170ALIGN JUMP_ALIGN
171Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
172    ; Store error code to BDA
173    LOAD_BDA_SEGMENT_TO ds, di
174    mov     [BDA.bHDLastSt], ah
175
176    ; Store error code to INTPACK
177Int13h_SetErrorCodeToIntpackInSSBPfromAH:
178    mov     [bp+IDEPACK.intpack+INTPACK.ah], ah
179    test    ah, ah
180    jnz     SHORT .SetCFtoIntpack
181    and     BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
182    ret
183.SetCFtoIntpack:
184    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
185    ret
186
187
188
189; Jump table for correct BIOS function
190ALIGN WORD_ALIGN
191g_rgw13hFuncJump:
192    dw  AH0h_HandlerForDiskControllerReset              ; 00h, Disk Controller Reset (All)
193    dw  AH1h_HandlerForReadDiskStatus                   ; 01h, Read Disk Status (All)
194    dw  AH2h_HandlerForReadDiskSectors                  ; 02h, Read Disk Sectors (All)
195    dw  AH3h_HandlerForWriteDiskSectors                 ; 03h, Write Disk Sectors (All)
196    dw  AH4h_HandlerForVerifyDiskSectors                ; 04h, Verify Disk Sectors (All)
197    dw  Int13h_UnsupportedFunction                      ; 05h, Format Disk Track (XT, AT, EISA)
198    dw  Int13h_UnsupportedFunction                      ; 06h, Format Disk Track with Bad Sectors (XT)
199    dw  Int13h_UnsupportedFunction                      ; 07h, Format Multiple Cylinders (XT)
200    dw  AH8h_HandlerForReadDiskDriveParameters          ; 08h, Read Disk Drive Parameters (All)
201    dw  AH9h_HandlerForInitializeDriveParameters        ; 09h, Initialize Drive Parameters (All)
202    dw  Int13h_UnsupportedFunction                      ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
203    dw  Int13h_UnsupportedFunction                      ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
204    dw  AHCh_HandlerForSeek                             ; 0Ch, Seek (All)
205    dw  AHDh_HandlerForResetHardDisk                    ; 0Dh, Alternate Disk Reset (All)
206    dw  Int13h_UnsupportedFunction                      ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
207    dw  Int13h_UnsupportedFunction                      ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
208    dw  AH10h_HandlerForCheckDriveReady                 ; 10h, Check Drive Ready (All)
209    dw  AH11h_HandlerForRecalibrate                     ; 11h, Recalibrate (All)
210    dw  Int13h_UnsupportedFunction                      ; 12h, Controller RAM Diagnostic (XT)
211    dw  Int13h_UnsupportedFunction                      ; 13h, Drive Diagnostic (XT)
212    dw  Int13h_UnsupportedFunction                      ; 14h, Controller Internal Diagnostic (All)
213    dw  AH15h_HandlerForReadDiskDriveSize               ; 15h, Read Disk Drive Size (AT+)
214    dw  Int13h_UnsupportedFunction                      ; 16h, 
215    dw  Int13h_UnsupportedFunction                      ; 17h, 
216    dw  Int13h_UnsupportedFunction                      ; 18h, 
217    dw  Int13h_UnsupportedFunction                      ; 19h, Park Heads (PS/2)
218    dw  Int13h_UnsupportedFunction                      ; 1Ah, Format ESDI Drive (PS/2)
219    dw  Int13h_UnsupportedFunction                      ; 1Bh, Get ESDI Manufacturing Header (PS/2)
220    dw  Int13h_UnsupportedFunction                      ; 1Ch, ESDI Special Functions (PS/2)
221    dw  Int13h_UnsupportedFunction                      ; 1Dh, 
222    dw  Int13h_UnsupportedFunction                      ; 1Eh, 
223    dw  Int13h_UnsupportedFunction                      ; 1Fh, 
224    dw  Int13h_UnsupportedFunction                      ; 20h, 
225    dw  Int13h_UnsupportedFunction                      ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
226    dw  Int13h_UnsupportedFunction                      ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
227    dw  AH23h_HandlerForSetControllerFeatures           ; 23h, Set Controller Features Register (PS/1)
228    dw  AH24h_HandlerForSetMultipleBlocks               ; 24h, Set Multiple Blocks (PS/1)
229    dw  AH25h_HandlerForGetDriveInformation             ; 25h, Get Drive Information (PS/1)
230;   dw  Int13h_UnsupportedFunction                      ; 26h, 
231;   dw  Int13h_UnsupportedFunction                      ; 27h, 
232;   dw  Int13h_UnsupportedFunction                      ; 28h, 
233;   dw  Int13h_UnsupportedFunction                      ; 29h, 
234;   dw  Int13h_UnsupportedFunction                      ; 2Ah, 
235;   dw  Int13h_UnsupportedFunction                      ; 2Bh, 
236;   dw  Int13h_UnsupportedFunction                      ; 2Ch, 
237;   dw  Int13h_UnsupportedFunction                      ; 2Dh, 
238;   dw  Int13h_UnsupportedFunction                      ; 2Eh, 
239;   dw  Int13h_UnsupportedFunction                      ; 2Fh, 
240;   dw  Int13h_UnsupportedFunction                      ; 30h, 
241;   dw  Int13h_UnsupportedFunction                      ; 31h, 
242;   dw  Int13h_UnsupportedFunction                      ; 32h, 
243;   dw  Int13h_UnsupportedFunction                      ; 33h, 
244;   dw  Int13h_UnsupportedFunction                      ; 34h, 
245;   dw  Int13h_UnsupportedFunction                      ; 35h, 
246;   dw  Int13h_UnsupportedFunction                      ; 36h, 
247;   dw  Int13h_UnsupportedFunction                      ; 37h, 
248;   dw  Int13h_UnsupportedFunction                      ; 38h, 
249;   dw  Int13h_UnsupportedFunction                      ; 39h, 
250;   dw  Int13h_UnsupportedFunction                      ; 3Ah, 
251;   dw  Int13h_UnsupportedFunction                      ; 3Bh, 
252;   dw  Int13h_UnsupportedFunction                      ; 3Ch, 
253;   dw  Int13h_UnsupportedFunction                      ; 3Dh, 
254;   dw  Int13h_UnsupportedFunction                      ; 3Eh, 
255;   dw  Int13h_UnsupportedFunction                      ; 3Fh, 
256;   dw  Int13h_UnsupportedFunction                      ; 40h, 
257;   dw  Int13h_UnsupportedFunction                      ; 41h, Check if Extensions Present (EBIOS)*
258;   dw  Int13h_UnsupportedFunction                      ; 42h, Extended Read Sectors (EBIOS)*
259;   dw  Int13h_UnsupportedFunction                      ; 43h, Extended Write Sectors (EBIOS)*
260;   dw  Int13h_UnsupportedFunction                      ; 44h, Extended Verify Sectors (EBIOS)*
261;   dw  Int13h_UnsupportedFunction                      ; 45h, Lock and Unlock Drive (EBIOS)***
262;   dw  Int13h_UnsupportedFunction                      ; 46h, Eject Media Request (EBIOS)***
263;   dw  Int13h_UnsupportedFunction                      ; 47h, Extended Seek (EBIOS)*
264;   dw  Int13h_UnsupportedFunction                      ; 48h, Get Extended Drive Parameters (EBIOS)*
265;   dw  Int13h_UnsupportedFunction                      ; 49h, Get Extended Disk Change Status (EBIOS)***
266;   dw  Int13h_UnsupportedFunction                      ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
267;   dw  Int13h_UnsupportedFunction                      ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
268;   dw  Int13h_UnsupportedFunction                      ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
269;   dw  Int13h_UnsupportedFunction                      ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
270;   dw  Int13h_UnsupportedFunction                      ; 4Eh, Set Hardware Configuration (EBIOS)**
271;
272;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
273;  ** = Enhanced Disk Drive (EDD) Support
274; *** = Drive Locking and Ejecting Support
Note: See TracBrowser for help on using the repository browser.