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

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

Changes to XTIDE Universal BIOS:

  • Minor size optimizations.
  • Tried to minimize the time spent with interrupts disabled in IdeIrq.asm and Int13h.asm
File size: 11.1 KB
RevLine 
[90]1; Project name  :   XTIDE Universal BIOS
[3]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;
[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;--------------------------------------------------------------------
21ALIGN JUMP_ALIGN
[148]22Int13h_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
31    jnc     SHORT Int13h_DirectCallToAnotherBios
[148]32    call    FindDPT_ForDriveNumber      ; DS:DI now points to DPT
[3]33
34    ; Jump to correct BIOS function
35    cmp     ah, 25h                     ; Valid BIOS function?
36    ja      SHORT Int13h_UnsupportedFunction
[148]37    eMOVZX  bx, ah
38    shl     bx, 1
39    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
[3]40
41
42;--------------------------------------------------------------------
[148]43; Int13h_UnsupportedFunction
[3]44; Int13h_DirectCallToAnotherBios
45;   Parameters:
[148]46;       DL:     Translated drive number
[3]47;       DS:     RAMVARS segment
[150]48;       SS:BP:  Ptr to IDEPACK
[148]49;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]50;       Other:  Function specific INT 13h parameters
[3]51;   Returns:
52;       Depends on function
53;   Corrupts registers:
54;       Flags
55;--------------------------------------------------------------------
56ALIGN JUMP_ALIGN
57Int13h_UnsupportedFunction:
58Int13h_DirectCallToAnotherBios:
[148]59    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[150]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]
[148]64    popf
65    push    bp
[150]66    mov     bp, [bp+IDEPACK.intpack+INTPACK.bp]
[148]67    int     BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
[3]68
[148]69    ; Store returned values to INTPACK
70    pop     bp  ; Standard INT 13h functions never uses BP as return register
71%ifdef USE_386
[150]72    mov     [bp+IDEPACK.intpack+INTPACK.gs], gs
73    mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]74%endif
[150]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
[148]83    pushf
[150]84    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]85    call    RamVars_GetSegmentToDS
86    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]
87    je      SHORT .ExchangeInt13hHandlers
[150]88    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl     ; Something is returned in DL
[148]89ALIGN JUMP_ALIGN
90.ExchangeInt13hHandlers:
91    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
92    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[3]93
94
95;--------------------------------------------------------------------
[148]96; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
97; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]98;   Parameters:
[148]99;       AH:     BIOS Error code
[150]100;       SS:BP:  Ptr to IDEPACK
[32]101;   Returns:
[148]102;       All registers are loaded from INTPACK
[32]103;--------------------------------------------------------------------
104ALIGN JUMP_ALIGN
[148]105Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[150]106    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[148]107Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[150]108    or      WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF   ; Return with interrupts enabled
[148]109    mov     sp, bp                                  ; Now we can exit anytime
[155]110    RESTORE_FRAME_INTPACK_FROM_SSBP     EXTRA_BYTES_FOR_INTPACK
[32]111
112
113;--------------------------------------------------------------------
[148]114; Int13h_CallPreviousInt13hHandler
[3]115;   Parameters:
[148]116;       AH:     INT 13h function to call
117;       DL:     Drive number
118;       DS:     RAMVARS segment
[3]119;   Returns:
120;       Depends on function
121;   Corrupts registers:
[148]122;       BX, DI, ES
[3]123;--------------------------------------------------------------------
124ALIGN JUMP_ALIGN
[148]125Int13h_CallPreviousInt13hHandler:
[3]126    push    di
[148]127    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
128    int     BIOS_DISK_INTERRUPT_13h
129    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
130    pop     di
131    ret
[35]132
[3]133
134;--------------------------------------------------------------------
[148]135; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[3]136;   Parameters:
137;       DS:     RAMVARS segment
138;   Returns:
[148]139;       Nothing
[3]140;   Corrupts registers:
[148]141;       DI
[3]142;--------------------------------------------------------------------
143ALIGN JUMP_ALIGN
[148]144ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
145    push    es
146    LOAD_BDA_SEGMENT_TO es, di
147    mov     di, [RAMVARS.fpOldI13h]
[150]148    cli
[148]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
[161]154    sti
[148]155    pop     es
156    ret
[28]157
[35]158
[150]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
[35]175
[150]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
[3]188; Jump table for correct BIOS function
189ALIGN WORD_ALIGN
190g_rgw13hFuncJump:
191    dw  AH0h_HandlerForDiskControllerReset              ; 00h, Disk Controller Reset (All)
192    dw  AH1h_HandlerForReadDiskStatus                   ; 01h, Read Disk Status (All)
193    dw  AH2h_HandlerForReadDiskSectors                  ; 02h, Read Disk Sectors (All)
194    dw  AH3h_HandlerForWriteDiskSectors                 ; 03h, Write Disk Sectors (All)
195    dw  AH4h_HandlerForVerifyDiskSectors                ; 04h, Verify Disk Sectors (All)
[90]196    dw  Int13h_UnsupportedFunction                      ; 05h, Format Disk Track (XT, AT, EISA)
[3]197    dw  Int13h_UnsupportedFunction                      ; 06h, Format Disk Track with Bad Sectors (XT)
198    dw  Int13h_UnsupportedFunction                      ; 07h, Format Multiple Cylinders (XT)
199    dw  AH8h_HandlerForReadDiskDriveParameters          ; 08h, Read Disk Drive Parameters (All)
200    dw  AH9h_HandlerForInitializeDriveParameters        ; 09h, Initialize Drive Parameters (All)
201    dw  Int13h_UnsupportedFunction                      ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
202    dw  Int13h_UnsupportedFunction                      ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
203    dw  AHCh_HandlerForSeek                             ; 0Ch, Seek (All)
204    dw  AHDh_HandlerForResetHardDisk                    ; 0Dh, Alternate Disk Reset (All)
205    dw  Int13h_UnsupportedFunction                      ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
206    dw  Int13h_UnsupportedFunction                      ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
207    dw  AH10h_HandlerForCheckDriveReady                 ; 10h, Check Drive Ready (All)
208    dw  AH11h_HandlerForRecalibrate                     ; 11h, Recalibrate (All)
209    dw  Int13h_UnsupportedFunction                      ; 12h, Controller RAM Diagnostic (XT)
210    dw  Int13h_UnsupportedFunction                      ; 13h, Drive Diagnostic (XT)
[90]211    dw  Int13h_UnsupportedFunction                      ; 14h, Controller Internal Diagnostic (All)
[3]212    dw  AH15h_HandlerForReadDiskDriveSize               ; 15h, Read Disk Drive Size (AT+)
[161]213    dw  Int13h_UnsupportedFunction                      ; 16h,
214    dw  Int13h_UnsupportedFunction                      ; 17h,
215    dw  Int13h_UnsupportedFunction                      ; 18h,
[3]216    dw  Int13h_UnsupportedFunction                      ; 19h, Park Heads (PS/2)
217    dw  Int13h_UnsupportedFunction                      ; 1Ah, Format ESDI Drive (PS/2)
218    dw  Int13h_UnsupportedFunction                      ; 1Bh, Get ESDI Manufacturing Header (PS/2)
219    dw  Int13h_UnsupportedFunction                      ; 1Ch, ESDI Special Functions (PS/2)
[161]220    dw  Int13h_UnsupportedFunction                      ; 1Dh,
221    dw  Int13h_UnsupportedFunction                      ; 1Eh,
222    dw  Int13h_UnsupportedFunction                      ; 1Fh,
223    dw  Int13h_UnsupportedFunction                      ; 20h,
[3]224    dw  Int13h_UnsupportedFunction                      ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
225    dw  Int13h_UnsupportedFunction                      ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
226    dw  AH23h_HandlerForSetControllerFeatures           ; 23h, Set Controller Features Register (PS/1)
227    dw  AH24h_HandlerForSetMultipleBlocks               ; 24h, Set Multiple Blocks (PS/1)
228    dw  AH25h_HandlerForGetDriveInformation             ; 25h, Get Drive Information (PS/1)
[161]229;   dw  Int13h_UnsupportedFunction                      ; 26h,
230;   dw  Int13h_UnsupportedFunction                      ; 27h,
231;   dw  Int13h_UnsupportedFunction                      ; 28h,
232;   dw  Int13h_UnsupportedFunction                      ; 29h,
233;   dw  Int13h_UnsupportedFunction                      ; 2Ah,
234;   dw  Int13h_UnsupportedFunction                      ; 2Bh,
235;   dw  Int13h_UnsupportedFunction                      ; 2Ch,
236;   dw  Int13h_UnsupportedFunction                      ; 2Dh,
237;   dw  Int13h_UnsupportedFunction                      ; 2Eh,
238;   dw  Int13h_UnsupportedFunction                      ; 2Fh,
239;   dw  Int13h_UnsupportedFunction                      ; 30h,
240;   dw  Int13h_UnsupportedFunction                      ; 31h,
241;   dw  Int13h_UnsupportedFunction                      ; 32h,
242;   dw  Int13h_UnsupportedFunction                      ; 33h,
243;   dw  Int13h_UnsupportedFunction                      ; 34h,
244;   dw  Int13h_UnsupportedFunction                      ; 35h,
245;   dw  Int13h_UnsupportedFunction                      ; 36h,
246;   dw  Int13h_UnsupportedFunction                      ; 37h,
247;   dw  Int13h_UnsupportedFunction                      ; 38h,
248;   dw  Int13h_UnsupportedFunction                      ; 39h,
249;   dw  Int13h_UnsupportedFunction                      ; 3Ah,
250;   dw  Int13h_UnsupportedFunction                      ; 3Bh,
251;   dw  Int13h_UnsupportedFunction                      ; 3Ch,
252;   dw  Int13h_UnsupportedFunction                      ; 3Dh,
253;   dw  Int13h_UnsupportedFunction                      ; 3Eh,
254;   dw  Int13h_UnsupportedFunction                      ; 3Fh,
255;   dw  Int13h_UnsupportedFunction                      ; 40h,
[150]256;   dw  Int13h_UnsupportedFunction                      ; 41h, Check if Extensions Present (EBIOS)*
257;   dw  Int13h_UnsupportedFunction                      ; 42h, Extended Read Sectors (EBIOS)*
258;   dw  Int13h_UnsupportedFunction                      ; 43h, Extended Write Sectors (EBIOS)*
259;   dw  Int13h_UnsupportedFunction                      ; 44h, Extended Verify Sectors (EBIOS)*
260;   dw  Int13h_UnsupportedFunction                      ; 45h, Lock and Unlock Drive (EBIOS)***
261;   dw  Int13h_UnsupportedFunction                      ; 46h, Eject Media Request (EBIOS)***
262;   dw  Int13h_UnsupportedFunction                      ; 47h, Extended Seek (EBIOS)*
263;   dw  Int13h_UnsupportedFunction                      ; 48h, Get Extended Drive Parameters (EBIOS)*
264;   dw  Int13h_UnsupportedFunction                      ; 49h, Get Extended Disk Change Status (EBIOS)***
[3]265;   dw  Int13h_UnsupportedFunction                      ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
266;   dw  Int13h_UnsupportedFunction                      ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
267;   dw  Int13h_UnsupportedFunction                      ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
268;   dw  Int13h_UnsupportedFunction                      ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
[150]269;   dw  Int13h_UnsupportedFunction                      ; 4Eh, Set Hardware Configuration (EBIOS)**
270;
271;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
272;  ** = Enhanced Disk Drive (EDD) Support
273; *** = Drive Locking and Ejecting Support
Note: See TracBrowser for help on using the repository browser.