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

Last change on this file since 568 was 568, checked in by krille_n_@…, 9 years ago

Changes:

  • SerDrive: Using named pipe mode (serdrive -p) now works under Windows XP/2000/Server 2003.
  • checksum.pl: Added a compatibility fix for 3Com 3C503 cards.
  • XTIDECFG will now scan every possible segment address to find and load the BIOS and/or its settings from EEPROM. This should simplify things for people using combined option ROMs.
  • Fixed a bug from r521 in BootSector.asm where the BIOS would not display a timeout error if it failed to load the boot sector from harddrive.
  • Fixed a bug from r541 in CompatibleDPT.asm where CompatibleDPT_CreateDeviceParameterTableExtensionToESBXfromDPTinDSSI would generate an invalid checksum in the DPTE.
  • Optimizations and other fixes.
File size: 16.2 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h BIOS functions (Floppy and Hard disk).
3
4;
5; XTIDE Universal BIOS and Associated Tools
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
12;
13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16; GNU General Public License for more details.
17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
18;
19
20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h software interrupt handler.
25; This handler changes stack to top of stolen conventional memory
26; and then calls the actual INT 13h handler (Int13h_DiskFunctionsHandler).
27;
28; Int13h_DiskFunctionsHandlerWithStackChange
29;   Parameters:
30;       AH:     Bios function
31;       DL:     Drive number
32;       Other:  Depends on function
33;   Returns:
34;       Depends on function
35;--------------------------------------------------------------------
36%ifdef RELOCATE_INT13H_STACK
37ALIGN JUMP_ALIGN
38Int13h_DiskFunctionsHandlerWithStackChange:
39    sti         ; Enable interrupts
40    ; TODO: Maybe we need to save Flags (DF) as well?
41    push    ds  ; Save DS:DI on the original stack
42    push    di
43    call    RamVars_GetSegmentToDS
44
45    ; Store entry registers to RAMVARS
46%ifdef USE_386
47    pop     DWORD [RAMVARS.dwStackChangeDSDI]
48%else
49    pop     WORD [RAMVARS.wStackChangeDI]   ; Pop DS:DI to the top of what
50    pop     WORD [RAMVARS.wStackChangeDS]   ; is to become the new stack
51%endif
52    mov     [RAMVARS.fpInt13hEntryStack], sp
53    mov     [RAMVARS.fpInt13hEntryStack+2], ss
54
55    ; Load new stack and restore DS and DI
56    mov     di, ds      ; We can save 2 bytes by using PUSH/POP but it's slower
57    mov     ss, di      ; No need to wrap with CLI/STI since this is for AT only (286+)
58    mov     sp, RAMVARS.rgbTopOfStack-4
59    pop     di          ; DI before stack change
60    pop     ds          ; DS before stack change
61
62    ; Call INT 13h
63    pushf
64    push    cs
65    call    Int13h_DiskFunctionsHandler
66
67    ; Restore stack (we must not corrupt FLAGS!)
68%ifdef USE_386
69    lss     sp, [ss:RAMVARS.fpInt13hEntryStack]
70%else
71    cli
72    mov     sp, [ss:RAMVARS.fpInt13hEntryStack]
73    mov     ss, [ss:RAMVARS.fpInt13hEntryStack+2]
74    sti
75%endif
76    retf    2           ; Skip FLAGS from stack
77%endif ; RELOCATE_INT13H_STACK
78
79
80;--------------------------------------------------------------------
81; Int 13h software interrupt handler.
82; Jumps to specific function defined in AH.
83;
84; Note to developers: Do not make recursive INT 13h calls!
85;
86; Int13h_DiskFunctionsHandler
87;   Parameters:
88;       AH:     Bios function
89;       DL:     Drive number
90;       Other:  Depends on function
91;   Returns:
92;       Depends on function
93;--------------------------------------------------------------------
94ALIGN JUMP_ALIGN
95Int13h_DiskFunctionsHandler:
96%ifndef RELOCATE_INT13H_STACK
97    sti                                 ; Enable interrupts
98%endif
99    cld                                 ; String instructions to increment pointers
100    CREATE_FRAME_INTPACK_TO_SSBP    SIZE_OF_IDEPACK_WITHOUT_INTPACK
101    call    RamVars_GetSegmentToDS
102
103%ifdef MODULE_DRIVEXLATE
104    call    DriveXlate_ToOrBack
105%endif
106    call    FindDPT_ForDriveNumberInDL  ; DS:DI points to our DPT, or NULL if not our drive
107    jc      SHORT .NotOurDrive          ; DPT not found so this is not one of our drives
108
109.OurFunction:
110    ; Jump to correct BIOS function
111    eMOVZX  bx, ah
112    eSHL_IM bx, 1
113    cmp     ah, 25h                     ; Possible EBIOS function?
114%ifndef MODULE_EBIOS
115    ja      SHORT UnsupportedFunction
116    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
117
118%else ; If using MODULE_EBIOS
119    ja      SHORT .JumpToEbiosFunction
120    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
121
122ALIGN JUMP_ALIGN
123.JumpToEbiosFunction:
124    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
125    jz      SHORT UnsupportedFunction   ; No eINT 13h for CHS drives
126    sub     bl, 41h<<1                  ; BX = Offset to eINT 13h jump table
127    jb      SHORT UnsupportedFunction
128    cmp     ah, 48h
129    ja      SHORT UnsupportedFunction
130    jmp     [cs:bx+g_rgwEbiosFunctionJumpTable]
131%endif  ; MODULE_EBIOS
132
133
134ALIGN JUMP_ALIGN
135.NotOurDrive:
136    test    ah, ah
137    jz      SHORT .OurFunction          ; We handle all function 0h requests (resets)
138
139%ifndef MODULE_SERIAL_FLOPPY
140; Without floppy support, we handle only hard disk traffic for function 08h.
141    test    dl, dl
142    jns     SHORT Int13h_DirectCallToAnotherBios
143%endif
144; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
145    cmp     ah, GET_DRIVE_PARAMETERS
146    je      SHORT .OurFunction
147    ; Fall to Int13h_DirectCallToAnotherBios
148
149
150;--------------------------------------------------------------------
151; UnsupportedFunction
152; Int13h_DirectCallToAnotherBios
153;   Parameters:
154;       DL:     Translated drive number
155;       DS:     RAMVARS segment
156;       SS:BP:  Ptr to IDEPACK
157;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
158;       Other:  Function specific INT 13h parameters
159;   Returns:
160;       Depends on function
161;   Corrupts registers:
162;       Flags
163;--------------------------------------------------------------------
164ALIGN JUMP_ALIGN
165UnsupportedFunction:
166Int13h_DirectCallToAnotherBios:
167%ifdef MODULE_DRIVEXLATE
168    ; Disable drive number translations in case of recursive INT 13h calls
169    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
170    push    WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
171    call    DriveXlate_Reset            ; No translation
172%endif
173
174    push    bp                          ; Store offset to IDEPACK (SS:SP now points it)
175
176    ; Simulate INT by pushing flags and return address
177    push    WORD [bp+IDEPACK.intpack+INTPACK.flags]
178%if 0
179    ; No standard INT 13h function uses FLAGS as parameters so no need to restore them
180    popf
181    pushf
182%endif
183    push    cs
184    ePUSH_T di, .ReturnFromAnotherBios  ; Can not corrupt flags
185
186    ; Push old INT 13h handler and restore registers
187    push    WORD [RAMVARS.fpOldI13h+2]
188    push    WORD [RAMVARS.fpOldI13h]
189    mov     bx, [bp+IDEPACK.intpack+INTPACK.bx]
190    mov     di, [bp+IDEPACK.intpack+INTPACK.di]
191    mov     ds, [bp+IDEPACK.intpack+INTPACK.ds]
192    mov     bp, [bp+IDEPACK.intpack+INTPACK.bp]
193    retf                                ; "Return" to old INT 13h
194.ReturnFromAnotherBios:
195
196%if 0
197    ; We need to restore our pointer to IDEPACK but we cannot corrupt any register
198    push    ax                          ; Dummy WORD
199    cli
200    xchg    bp, sp
201    mov     [bp], sp                    ; Replace dummy WORD with returned BP
202    mov     sp, [bp+2]                  ; Load offset to IDEPACK
203    xchg    sp, bp
204    sti                                 ; We would have set IF anyway when exiting INT 13h
205    pop     WORD [bp+IDEPACK.intpack+INTPACK.bp]
206%endif
207    ; Actually we can corrupt BP since no standard INT 13h function uses it as return
208    ; register. Above code is kept here just in case if there is some non-standard function.
209    ; POP BP below also belongs to the above code.
210    pop     bp                          ; Clean IDEPACK offset from stack
211
212    ; Store remaining returned values to INTPACK
213%ifdef USE_386
214; We do not use GS or FS at the moment
215;   mov     [bp+IDEPACK.intpack+INTPACK.gs], gs
216;   mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
217%endif
218    mov     [bp+IDEPACK.intpack+INTPACK.es], es
219    mov     [bp+IDEPACK.intpack+INTPACK.ds], ds
220    mov     [bp+IDEPACK.intpack+INTPACK.di], di
221    mov     [bp+IDEPACK.intpack+INTPACK.si], si
222    mov     [bp+IDEPACK.intpack+INTPACK.bx], bx
223%ifdef MODULE_DRIVEXLATE
224    mov     [bp+IDEPACK.intpack+INTPACK.dh], dh
225%else
226    mov     [bp+IDEPACK.intpack+INTPACK.dx], dx
227%endif
228    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
229    mov     [bp+IDEPACK.intpack+INTPACK.ax], ax
230    pushf
231    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
232    call    RamVars_GetSegmentToDS
233
234%ifdef MODULE_DRIVEXLATE
235    ; Restore drive number translation back to what it was
236    pop     WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
237    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]    ; DL is still drive number?
238    je      SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
239    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
240%endif
241    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
242
243
244%ifdef MODULE_SERIAL_FLOPPY
245;--------------------------------------------------------------------
246; Int13h_ReturnSuccessForFloppy
247;
248; Some operations, such as format of a floppy disk track, should just
249; return success, while for hard disks it should be treated as unsupported.
250;--------------------------------------------------------------------
251ALIGN JUMP_ALIGN
252Int13h_ReturnSuccessForFloppy:
253    test    dl, dl
254    js      SHORT UnsupportedFunction
255    xor     ah, ah
256    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
257%endif
258
259
260;--------------------------------------------------------------------
261; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
262;   Parameters:
263;       AH:     BIOS Error code
264;       CL:     Number of sectors actually transferred
265;       SS:BP:  Ptr to IDEPACK
266;   Returns:
267;       All registers are loaded from INTPACK
268;--------------------------------------------------------------------
269ALIGN JUMP_ALIGN
270Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
271    mov     [bp+IDEPACK.intpack+INTPACK.al], cl
272    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
273
274
275;--------------------------------------------------------------------
276; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
277; Int13h_ReturnFromHandlerWithoutStoringErrorCode
278;   Parameters:
279;       AH:     BIOS Error code
280;       SS:BP:  Ptr to IDEPACK
281;   Returns:
282;       All registers are loaded from INTPACK
283;--------------------------------------------------------------------
284ALIGN JUMP_ALIGN
285Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
286%ifdef MODULE_SERIAL_FLOPPY
287    mov     al, [bp+IDEPACK.intpack+INTPACK.dl]
288Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
289    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
290
291%else
292    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
293%endif
294
295Int13h_ReturnFromHandlerWithoutStoringErrorCode:
296    ; Always return with interrupts enabled since there are programs that rely
297    ; on INT 13h to enable interrupts.
298    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
299    mov     sp, bp  ; This makes possible to exit anytime, no matter what is on stack
300    RESTORE_FRAME_INTPACK_FROM_SSBP     SIZE_OF_IDEPACK_WITHOUT_INTPACK
301
302
303;--------------------------------------------------------------------
304; Int13h_CallPreviousInt13hHandler
305;   Parameters:
306;       AH:     INT 13h function to call
307;       DL:     Drive number
308;       DS:     RAMVARS segment
309;   Returns:
310;       Depends on function
311;       NOTE: ES:DI needs to be returned from the previous interrupt
312;             handler, for floppy DPT in function 08h
313;   Corrupts registers:
314;       None
315;--------------------------------------------------------------------
316ALIGN JUMP_ALIGN
317Int13h_CallPreviousInt13hHandler:
318    pushf                       ; Simulate INT by pushing flags
319    call far [RAMVARS.fpOldI13h]
320    ret
321
322
323;--------------------------------------------------------------------
324; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
325; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
326; Int13h_SetErrorCodeToIntpackInSSBPfromAH
327;   Parameters:
328;       AH:     BIOS error code (00h = no error)
329;       SS:BP:  Ptr to IDEPACK
330;   Returns:
331;       SS:BP:  Ptr to IDEPACK with error condition set
332;   Corrupts registers:
333;       DS, BX, DI
334;--------------------------------------------------------------------
335ALIGN JUMP_ALIGN
336%ifdef MODULE_SERIAL_FLOPPY
337Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
338    ; Store error code to BDA
339    mov     bx, BDA.bHDLastSt
340    test    al, al
341    js      SHORT .HardDisk
342    mov     bl, BDA.bFDRetST & 0xff
343.HardDisk:
344    LOAD_BDA_SEGMENT_TO ds, di
345    mov     [bx], ah
346    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
347
348%else
349Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
350    ; Store error code to BDA
351    LOAD_BDA_SEGMENT_TO ds, di
352    mov     [BDA.bHDLastSt], ah
353    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
354%endif
355
356    ; Store error code to INTPACK
357Int13h_SetErrorCodeToIntpackInSSBPfromAH:
358    mov     [bp+IDEPACK.intpack+INTPACK.ah], ah
359    test    ah, ah
360    jnz     SHORT .SetCFtoIntpack
361    and     BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
362    ret
363.SetCFtoIntpack:
364    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
365    ret
366
367
368; Jump table for correct BIOS function
369ALIGN WORD_ALIGN
370g_rgw13hFuncJump:
371    dw  AH0h_HandlerForDiskControllerReset          ; 00h, Disk Controller Reset (All)
372    dw  AH1h_HandlerForReadDiskStatus               ; 01h, Read Disk Status (All)
373    dw  AH2h_HandlerForReadDiskSectors              ; 02h, Read Disk Sectors (All)
374    dw  AH3h_HandlerForWriteDiskSectors             ; 03h, Write Disk Sectors (All)
375    dw  AH4h_HandlerForVerifyDiskSectors            ; 04h, Verify Disk Sectors (All)
376%ifdef MODULE_SERIAL_FLOPPY
377    dw  Int13h_ReturnSuccessForFloppy               ; 05h, Format Disk Track (XT, AT, EISA)
378%else
379    dw  UnsupportedFunction                         ; 05h, Format Disk Track (XT, AT, EISA)
380%endif
381    dw  UnsupportedFunction                         ; 06h, Format Disk Track with Bad Sectors (XT)
382    dw  UnsupportedFunction                         ; 07h, Format Multiple Cylinders (XT)
383    dw  AH8h_HandlerForReadDiskDriveParameters      ; 08h, Read Disk Drive Parameters (All)
384    dw  AH9h_HandlerForInitializeDriveParameters    ; 09h, Initialize Drive Parameters (All)
385    dw  UnsupportedFunction                         ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
386    dw  UnsupportedFunction                         ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
387    dw  AHCh_HandlerForSeek                         ; 0Ch, Seek (All)
388    dw  AH9h_HandlerForInitializeDriveParameters    ; 0Dh, Alternate Disk Reset (All)
389    dw  UnsupportedFunction                         ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
390    dw  UnsupportedFunction                         ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
391    dw  AH10h_HandlerForCheckDriveReady             ; 10h, Check Drive Ready (All)
392    dw  AH11h_HandlerForRecalibrate                 ; 11h, Recalibrate (All)
393    dw  UnsupportedFunction                         ; 12h, Controller RAM Diagnostic (XT)
394    dw  UnsupportedFunction                         ; 13h, Drive Diagnostic (XT)
395    dw  AH10h_HandlerForCheckDriveReady             ; 14h, Controller Internal Diagnostic (All)
396    dw  AH15h_HandlerForReadDiskDriveSize           ; 15h, Read Disk Drive Size (AT+)
397    dw  UnsupportedFunction                         ; 16h,
398    dw  UnsupportedFunction                         ; 17h,
399    dw  UnsupportedFunction                         ; 18h,
400    dw  UnsupportedFunction                         ; 19h, Park Heads (PS/2)
401    dw  UnsupportedFunction                         ; 1Ah, Format ESDI Drive (PS/2)
402    dw  UnsupportedFunction                         ; 1Bh, Get ESDI Manufacturing Header (PS/2)
403    dw  UnsupportedFunction                         ; 1Ch, ESDI Special Functions (PS/2)
404    dw  UnsupportedFunction                         ; 1Dh,
405%ifdef MODULE_8BIT_IDE_ADVANCED
406    dw  AH1Eh_HandlerForXTCFfeatures                ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
407%else
408    dw  UnsupportedFunction                         ; 1Eh,
409%endif
410    dw  UnsupportedFunction                         ; 1Fh,
411    dw  UnsupportedFunction                         ; 20h,
412    dw  UnsupportedFunction                         ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
413    dw  UnsupportedFunction                         ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
414    dw  AH23h_HandlerForSetControllerFeatures       ; 23h, Set Controller Features Register (PS/1)
415    dw  AH24h_HandlerForSetMultipleBlocks           ; 24h, Set Multiple Blocks (PS/1)
416    dw  AH25h_HandlerForGetDriveInformation         ; 25h, Get Drive Information (PS/1)
417
418%ifdef MODULE_EBIOS
419g_rgwEbiosFunctionJumpTable:
420    dw  AH41h_HandlerForCheckIfExtensionsPresent    ; 41h, Check if Extensions Present (EBIOS)*
421    dw  AH42h_HandlerForExtendedReadSectors         ; 42h, Extended Read Sectors (EBIOS)*
422    dw  AH43h_HandlerForExtendedWriteSectors        ; 43h, Extended Write Sectors (EBIOS)*
423    dw  AH44h_HandlerForExtendedVerifySectors       ; 44h, Extended Verify Sectors (EBIOS)*
424    dw  UnsupportedFunction                         ; 45h, Lock and Unlock Drive (EBIOS)***
425    dw  UnsupportedFunction                         ; 46h, Eject Media Request (EBIOS)***
426    dw  AH47h_HandlerForExtendedSeek                ; 47h, Extended Seek (EBIOS)*
427    dw  AH48h_HandlerForGetExtendedDriveParameters  ; 48h, Get Extended Drive Parameters (EBIOS)*
428;   dw  UnsupportedFunction                         ; 49h, Get Extended Disk Change Status (EBIOS)***
429;   dw  UnsupportedFunction                         ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
430;   dw  UnsupportedFunction                         ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
431;   dw  UnsupportedFunction                         ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
432;   dw  UnsupportedFunction                         ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
433;   dw  UnsupportedFunction                         ; 4Eh, Set Hardware Configuration (EBIOS)**
434;
435;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
436;  ** = Enhanced Disk Drive (EDD) Support
437; *** = Drive Locking and Ejecting Support
438%endif
Note: See TracBrowser for help on using the repository browser.