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

Last change on this file since 596 was 596, checked in by krille_n_, 6 years ago

Changes:

  • Made changes to HotkeyBar.asm to give the Boot Menu and Hotkey Bar a more consistent look. It will probably seem a bit strange at first to people used to the classic theme.
  • Added the missing parts of USE_NEC_V that should have been committed with the rest in r593.
  • Removed DEFINES_ALL_FEATURES from the BIOS makefile. It didn't work anymore and never really made sense anyway. Added all the official builds to 'make unused' instead which actually uncovered some unused code in the Tiny build.
  • XTIDECFG will no longer load color themes from unrecognized versions of the BIOS.
  • Other fixes in comments and some minor optimizations.
File size: 16.4 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%ifdef CLD_NEEDED
100    cld                                 ; String instructions to increment pointers
101%endif
102    ePUSHA
103    push    ds
104    push    es
105%ifdef USE_386
106;   push    fs
107;   push    gs
108%endif
109    sub     sp, BYTE SIZE_OF_IDEPACK_WITHOUT_INTPACK
110    mov     bp, sp
111    call    RamVars_GetSegmentToDS
112
113%ifdef MODULE_DRIVEXLATE
114    call    DriveXlate_ToOrBack
115%endif
116    call    FindDPT_ForDriveNumberInDL  ; DS:DI points to our DPT, or NULL if not our drive
117    jc      SHORT .NotOurDrive          ; DPT not found so this is not one of our drives
118
119.OurFunction:
120    ; Jump to correct BIOS function
121    eMOVZX  bx, ah
122    eSHL_IM bx, 1
123    cmp     ah, 25h                     ; Possible EBIOS function?
124%ifndef MODULE_EBIOS
125    ja      SHORT UnsupportedFunction
126    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
127
128%else ; If using MODULE_EBIOS
129    ja      SHORT .JumpToEbiosFunction
130    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
131
132ALIGN JUMP_ALIGN
133.JumpToEbiosFunction:
134    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA
135    jz      SHORT UnsupportedFunction   ; No eINT 13h for CHS drives
136    sub     bl, 41h<<1                  ; BX = Offset to eINT 13h jump table
137    jb      SHORT UnsupportedFunction
138    cmp     ah, 48h
139    ja      SHORT UnsupportedFunction
140    jmp     [cs:bx+g_rgwEbiosFunctionJumpTable]
141%endif  ; MODULE_EBIOS
142
143
144ALIGN JUMP_ALIGN
145.NotOurDrive:
146    test    ah, ah
147    jz      SHORT .OurFunction          ; We handle all function 0h requests (resets)
148
149%ifndef MODULE_SERIAL_FLOPPY
150; Without floppy support, we handle only hard disk traffic for function 08h.
151    test    dl, dl
152    jns     SHORT Int13h_DirectCallToAnotherBios
153%endif
154; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
155    cmp     ah, GET_DRIVE_PARAMETERS
156    je      SHORT .OurFunction
157    ; Fall to Int13h_DirectCallToAnotherBios
158
159
160;--------------------------------------------------------------------
161; UnsupportedFunction
162; Int13h_DirectCallToAnotherBios
163;   Parameters:
164;       DL:     Translated drive number
165;       DS:     RAMVARS segment
166;       SS:BP:  Ptr to IDEPACK
167;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
168;       Other:  Function specific INT 13h parameters
169;   Returns:
170;       Depends on function
171;   Corrupts registers:
172;       Flags
173;--------------------------------------------------------------------
174ALIGN JUMP_ALIGN
175UnsupportedFunction:
176Int13h_DirectCallToAnotherBios:
177%ifdef MODULE_DRIVEXLATE
178    ; Disable drive number translations in case of recursive INT 13h calls
179    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
180    push    WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
181    call    DriveXlate_Reset            ; No translation
182%endif
183
184    push    bp                          ; Store offset to IDEPACK (SS:SP now points it)
185
186    ; Simulate INT by pushing flags and return address
187    push    WORD [bp+IDEPACK.intpack+INTPACK.flags]
188%if 0
189    ; No standard INT 13h function uses FLAGS as parameters so no need to restore them
190    popf
191    pushf
192%endif
193    push    cs
194    ePUSH_T di, .ReturnFromAnotherBios  ; Can not corrupt flags
195
196    ; Push old INT 13h handler and restore registers
197%ifdef USE_386
198    push    DWORD [RAMVARS.fpOldI13h]
199%else
200    push    WORD [RAMVARS.fpOldI13h+2]
201    push    WORD [RAMVARS.fpOldI13h]
202%endif
203    mov     bx, [bp+IDEPACK.intpack+INTPACK.bx]
204    mov     di, [bp+IDEPACK.intpack+INTPACK.di]
205    mov     ds, [bp+IDEPACK.intpack+INTPACK.ds]
206    mov     bp, [bp+IDEPACK.intpack+INTPACK.bp]
207    retf                                ; "Return" to old INT 13h
208.ReturnFromAnotherBios:
209
210%if 0
211    ; We need to restore our pointer to IDEPACK but we cannot corrupt any register
212    push    ax                          ; Dummy WORD
213    cli
214    xchg    bp, sp
215    mov     [bp], sp                    ; Replace dummy WORD with returned BP
216    mov     sp, [bp+2]                  ; Load offset to IDEPACK
217    xchg    sp, bp
218    sti                                 ; We would have set IF anyway when exiting INT 13h
219    pop     WORD [bp+IDEPACK.intpack+INTPACK.bp]
220%endif
221    ; Actually we can corrupt BP since no standard INT 13h function uses it as return
222    ; register. Above code is kept here just in case if there is some non-standard function.
223    ; POP BP below also belongs to the above code.
224    pop     bp                          ; Clean IDEPACK offset from stack
225
226    ; Store remaining returned values to INTPACK
227%ifdef USE_386
228; We do not use GS or FS at the moment
229;   mov     [bp+IDEPACK.intpack+INTPACK.gs], gs
230;   mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
231%endif
232    mov     [bp+IDEPACK.intpack+INTPACK.es], es
233    mov     [bp+IDEPACK.intpack+INTPACK.ds], ds
234    mov     [bp+IDEPACK.intpack+INTPACK.di], di
235    mov     [bp+IDEPACK.intpack+INTPACK.si], si
236    mov     [bp+IDEPACK.intpack+INTPACK.bx], bx
237%ifdef MODULE_DRIVEXLATE
238    mov     [bp+IDEPACK.intpack+INTPACK.dh], dh
239%else
240    mov     [bp+IDEPACK.intpack+INTPACK.dx], dx
241%endif
242    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
243    mov     [bp+IDEPACK.intpack+INTPACK.ax], ax
244    pushf
245    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
246    call    RamVars_GetSegmentToDS
247
248%ifdef MODULE_DRIVEXLATE
249    ; Restore drive number translation back to what it was
250    pop     WORD [RAMVARS.xlateVars+XLATEVARS.wFDandHDswap]
251    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]    ; DL is still drive number?
252    je      SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
253    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
254%endif
255    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
256
257
258%ifdef MODULE_SERIAL_FLOPPY
259;--------------------------------------------------------------------
260; Int13h_ReturnSuccessForFloppy
261;
262; Some operations, such as format of a floppy disk track, should just
263; return success, while for hard disks it should be treated as unsupported.
264;--------------------------------------------------------------------
265ALIGN JUMP_ALIGN
266Int13h_ReturnSuccessForFloppy:
267    test    dl, dl
268    js      SHORT UnsupportedFunction
269    xor     ah, ah
270    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
271%endif
272
273
274;--------------------------------------------------------------------
275; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
276;   Parameters:
277;       AH:     BIOS Error code
278;       CL:     Number of sectors actually transferred
279;       SS:BP:  Ptr to IDEPACK
280;   Returns:
281;       All registers are loaded from INTPACK
282;--------------------------------------------------------------------
283ALIGN JUMP_ALIGN
284Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
285    mov     [bp+IDEPACK.intpack+INTPACK.al], cl
286    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
287
288
289;--------------------------------------------------------------------
290; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
291; Int13h_ReturnFromHandlerWithoutStoringErrorCode
292;   Parameters:
293;       AH:     BIOS Error code
294;       SS:BP:  Ptr to IDEPACK
295;   Returns:
296;       All registers are loaded from INTPACK
297;--------------------------------------------------------------------
298ALIGN JUMP_ALIGN
299Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
300%ifdef MODULE_SERIAL_FLOPPY
301    mov     al, [bp+IDEPACK.intpack+INTPACK.dl]
302Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
303    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
304
305%else
306    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
307%endif
308
309Int13h_ReturnFromHandlerWithoutStoringErrorCode:
310    ; Always return with interrupts enabled since there are programs that rely
311    ; on INT 13h to enable interrupts.
312    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
313
314    lea     sp, [bp+SIZE_OF_IDEPACK_WITHOUT_INTPACK]
315%ifdef USE_386
316;   pop     gs
317;   pop     fs
318%endif
319    pop     es
320    pop     ds
321    ePOPA
322    iret
323
324
325;--------------------------------------------------------------------
326; Int13h_CallPreviousInt13hHandler
327;   Parameters:
328;       AH:     INT 13h function to call
329;       DL:     Drive number
330;       DS:     RAMVARS segment
331;   Returns:
332;       Depends on function
333;       NOTE: ES:DI needs to be returned from the previous interrupt
334;             handler, for floppy DPT in function 08h
335;   Corrupts registers:
336;       None
337;--------------------------------------------------------------------
338ALIGN JUMP_ALIGN
339Int13h_CallPreviousInt13hHandler:
340    pushf                       ; Simulate INT by pushing flags
341    call    FAR [RAMVARS.fpOldI13h]
342    ret
343
344
345;--------------------------------------------------------------------
346; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
347; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
348; Int13h_SetErrorCodeToIntpackInSSBPfromAH
349;   Parameters:
350;       AH:     BIOS error code (00h = no error)
351;       SS:BP:  Ptr to IDEPACK
352;   Returns:
353;       SS:BP:  Ptr to IDEPACK with error condition set
354;   Corrupts registers:
355;       DS, BX, DI
356;--------------------------------------------------------------------
357ALIGN JUMP_ALIGN
358%ifdef MODULE_SERIAL_FLOPPY
359Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
360    ; Store error code to BDA
361    mov     bx, BDA.bHDLastSt
362    test    al, al
363    js      SHORT .HardDisk
364    mov     bl, BDA.bFDRetST & 0xff
365.HardDisk:
366    LOAD_BDA_SEGMENT_TO ds, di
367    mov     [bx], ah
368    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
369
370%else
371Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
372    ; Store error code to BDA
373    LOAD_BDA_SEGMENT_TO ds, di
374    mov     [BDA.bHDLastSt], ah
375    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
376%endif
377
378    ; Store error code to INTPACK
379Int13h_SetErrorCodeToIntpackInSSBPfromAH:
380    mov     [bp+IDEPACK.intpack+INTPACK.ah], ah
381    test    ah, ah
382    jnz     SHORT .SetCFtoIntpack
383    and     BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
384    ret
385.SetCFtoIntpack:
386    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
387    ret
388
389
390; Jump table for correct BIOS function
391ALIGN WORD_ALIGN
392g_rgw13hFuncJump:
393    dw  AH0h_HandlerForDiskControllerReset          ; 00h, Disk Controller Reset (All)
394    dw  AH1h_HandlerForReadDiskStatus               ; 01h, Read Disk Status (All)
395    dw  AH2h_HandlerForReadDiskSectors              ; 02h, Read Disk Sectors (All)
396    dw  AH3h_HandlerForWriteDiskSectors             ; 03h, Write Disk Sectors (All)
397    dw  AH4h_HandlerForVerifyDiskSectors            ; 04h, Verify Disk Sectors (All)
398%ifdef MODULE_SERIAL_FLOPPY
399    dw  Int13h_ReturnSuccessForFloppy               ; 05h, Format Disk Track (XT, AT, EISA)
400%else
401    dw  UnsupportedFunction                         ; 05h, Format Disk Track (XT, AT, EISA)
402%endif
403    dw  UnsupportedFunction                         ; 06h, Format Disk Track with Bad Sectors (XT)
404    dw  UnsupportedFunction                         ; 07h, Format Multiple Cylinders (XT)
405    dw  AH8h_HandlerForReadDiskDriveParameters      ; 08h, Read Disk Drive Parameters (All)
406    dw  AH9h_HandlerForInitializeDriveParameters    ; 09h, Initialize Drive Parameters (All)
407    dw  UnsupportedFunction                         ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
408    dw  UnsupportedFunction                         ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
409    dw  AHCh_HandlerForSeek                         ; 0Ch, Seek (All)
410    dw  AH9h_HandlerForInitializeDriveParameters    ; 0Dh, Alternate Disk Reset (All)
411    dw  UnsupportedFunction                         ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
412    dw  UnsupportedFunction                         ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
413    dw  AH10h_HandlerForCheckDriveReady             ; 10h, Check Drive Ready (All)
414    dw  AH11h_HandlerForRecalibrate                 ; 11h, Recalibrate (All)
415    dw  UnsupportedFunction                         ; 12h, Controller RAM Diagnostic (XT)
416    dw  UnsupportedFunction                         ; 13h, Drive Diagnostic (XT)
417    dw  AH10h_HandlerForCheckDriveReady             ; 14h, Controller Internal Diagnostic (All)
418    dw  AH15h_HandlerForReadDiskDriveSize           ; 15h, Read Disk Drive Size (AT+)
419    dw  UnsupportedFunction                         ; 16h,
420    dw  UnsupportedFunction                         ; 17h,
421    dw  UnsupportedFunction                         ; 18h,
422    dw  UnsupportedFunction                         ; 19h, Park Heads (PS/2)
423    dw  UnsupportedFunction                         ; 1Ah, Format ESDI Drive (PS/2)
424    dw  UnsupportedFunction                         ; 1Bh, Get ESDI Manufacturing Header (PS/2)
425    dw  UnsupportedFunction                         ; 1Ch, ESDI Special Functions (PS/2)
426    dw  UnsupportedFunction                         ; 1Dh,
427%ifdef MODULE_8BIT_IDE_ADVANCED
428    dw  AH1Eh_HandlerForXTCFfeatures                ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
429%else
430    dw  UnsupportedFunction                         ; 1Eh,
431%endif
432    dw  UnsupportedFunction                         ; 1Fh,
433    dw  UnsupportedFunction                         ; 20h,
434    dw  UnsupportedFunction                         ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
435    dw  UnsupportedFunction                         ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
436    dw  AH23h_HandlerForSetControllerFeatures       ; 23h, Set Controller Features Register (PS/1)
437    dw  AH24h_HandlerForSetMultipleBlocks           ; 24h, Set Multiple Blocks (PS/1)
438    dw  AH25h_HandlerForGetDriveInformation         ; 25h, Get Drive Information (PS/1)
439
440%ifdef MODULE_EBIOS
441g_rgwEbiosFunctionJumpTable:
442    dw  AH41h_HandlerForCheckIfExtensionsPresent    ; 41h, Check if Extensions Present (EBIOS)*
443    dw  AH42h_HandlerForExtendedReadSectors         ; 42h, Extended Read Sectors (EBIOS)*
444    dw  AH43h_HandlerForExtendedWriteSectors        ; 43h, Extended Write Sectors (EBIOS)*
445    dw  AH44h_HandlerForExtendedVerifySectors       ; 44h, Extended Verify Sectors (EBIOS)*
446    dw  UnsupportedFunction                         ; 45h, Lock and Unlock Drive (EBIOS)***
447    dw  UnsupportedFunction                         ; 46h, Eject Media Request (EBIOS)***
448    dw  AH47h_HandlerForExtendedSeek                ; 47h, Extended Seek (EBIOS)*
449    dw  AH48h_HandlerForGetExtendedDriveParameters  ; 48h, Get Extended Drive Parameters (EBIOS)*
450;   dw  UnsupportedFunction                         ; 49h, Get Extended Disk Change Status (EBIOS)***
451;   dw  UnsupportedFunction                         ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
452;   dw  UnsupportedFunction                         ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
453;   dw  UnsupportedFunction                         ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
454;   dw  UnsupportedFunction                         ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
455;   dw  UnsupportedFunction                         ; 4Eh, Set Hardware Configuration (EBIOS)**
456;
457;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
458;  ** = Enhanced Disk Drive (EDD) Support
459; *** = Drive Locking and Ejecting Support
460%endif
Note: See TracBrowser for help on using the repository browser.