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

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

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 15.9 KB
RevLine 
[90]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Int 13h BIOS functions (Floppy and Hard disk).
3
[376]4;
[445]5; XTIDE Universal BIOS and Associated Tools
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]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.
[445]12;
[376]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
[445]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]18;
[376]19
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h software interrupt handler.
[417]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:
[525]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
[417]42    push    di
43    call    RamVars_GetSegmentToDS
44
45    ; Store entry registers to RAMVARS
[525]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
[417]52    mov     [RAMVARS.fpInt13hEntryStack], sp
53    mov     [RAMVARS.fpInt13hEntryStack+2], ss
54
55    ; Load new stack and restore DS and DI
[525]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
[417]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
[525]71    cli
[417]72    mov     sp, [ss:RAMVARS.fpInt13hEntryStack]
73    mov     ss, [ss:RAMVARS.fpInt13hEntryStack+2]
[525]74    sti
[417]75%endif
76    retf    2           ; Skip FLAGS from stack
77%endif ; RELOCATE_INT13H_STACK
78
79
80;--------------------------------------------------------------------
81; Int 13h software interrupt handler.
[3]82; Jumps to specific function defined in AH.
83;
[148]84; Note to developers: Do not make recursive INT 13h calls!
85;
86; Int13h_DiskFunctionsHandler
[3]87;   Parameters:
88;       AH:     Bios function
89;       DL:     Drive number
[148]90;       Other:  Depends on function
[3]91;   Returns:
92;       Depends on function
93;--------------------------------------------------------------------
94ALIGN JUMP_ALIGN
[148]95Int13h_DiskFunctionsHandler:
[525]96%ifndef RELOCATE_INT13H_STACK
[3]97    sti                                 ; Enable interrupts
[525]98%endif
[150]99    cld                                 ; String instructions to increment pointers
[443]100    CREATE_FRAME_INTPACK_TO_SSBP    SIZE_OF_IDEPACK_WITHOUT_INTPACK
[3]101    call    RamVars_GetSegmentToDS
[294]102
[493]103%ifdef MODULE_DRIVEXLATE
[148]104    call    DriveXlate_ToOrBack
[414]105    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
[395]106%endif
[322]107    call    FindDPT_ForDriveNumberInDL  ; DS:DI points to our DPT, or NULL if not our drive
108    jc      SHORT .NotOurDrive          ; DPT not found so this is not one of our drives
[258]109
[294]110.OurFunction:
[3]111    ; Jump to correct BIOS function
[148]112    eMOVZX  bx, ah
[445]113    eSHL_IM bx, 1
[165]114    cmp     ah, 25h                     ; Possible EBIOS function?
[417]115%ifndef MODULE_EBIOS
116    ja      SHORT UnsupportedFunction
117    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
118
119%else ; If using MODULE_EBIOS
[165]120    ja      SHORT .JumpToEbiosFunction
[148]121    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
[3]122
[165]123ALIGN JUMP_ALIGN
124.JumpToEbiosFunction:
[421]125    test    BYTE [di+DPT.bFlagsLow], FLGL_DPT_LBA_AND_EBIOS_SUPPORTED
[417]126    jz      SHORT UnsupportedFunction   ; No eINT 13h for CHS drives
[322]127    sub     bl, 41h<<1                  ; BX = Offset to eINT 13h jump table
[417]128    jb      SHORT UnsupportedFunction
[167]129    cmp     ah, 48h
[417]130    ja      SHORT UnsupportedFunction
[165]131    jmp     [cs:bx+g_rgwEbiosFunctionJumpTable]
[417]132%endif  ; MODULE_EBIOS
[3]133
[417]134
[322]135ALIGN JUMP_ALIGN
136.NotOurDrive:
137    test    ah, ah
138    jz      SHORT .OurFunction          ; We handle all function 0h requests (resets)
[260]139
[322]140%ifndef MODULE_SERIAL_FLOPPY
141; Without floppy support, we handle only hard disk traffic for function 08h.
142    test    dl, dl
143    jns     SHORT Int13h_DirectCallToAnotherBios
144%endif
145; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
146    cmp     ah, 8
147    je      SHORT .OurFunction
148    ; Fall to Int13h_DirectCallToAnotherBios
149
[417]150
[3]151;--------------------------------------------------------------------
[417]152; UnsupportedFunction
[3]153; Int13h_DirectCallToAnotherBios
154;   Parameters:
[148]155;       DL:     Translated drive number
[3]156;       DS:     RAMVARS segment
[150]157;       SS:BP:  Ptr to IDEPACK
[148]158;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]159;       Other:  Function specific INT 13h parameters
[3]160;   Returns:
161;       Depends on function
162;   Corrupts registers:
163;       Flags
164;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
[417]166UnsupportedFunction:
[3]167Int13h_DirectCallToAnotherBios:
[148]168    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[150]169    mov     bx, [bp+IDEPACK.intpack+INTPACK.bx]
170    mov     di, [bp+IDEPACK.intpack+INTPACK.di]
171    mov     ds, [bp+IDEPACK.intpack+INTPACK.ds]
172    push    WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]173    popf
174    push    bp
[150]175    mov     bp, [bp+IDEPACK.intpack+INTPACK.bp]
[148]176    int     BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
[3]177
[148]178    ; Store returned values to INTPACK
179    pop     bp  ; Standard INT 13h functions never uses BP as return register
180%ifdef USE_386
[322]181;   mov     [bp+IDEPACK.intpack+INTPACK.gs], gs
182;   mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]183%endif
[150]184    mov     [bp+IDEPACK.intpack+INTPACK.es], es
185    mov     [bp+IDEPACK.intpack+INTPACK.ds], ds
186    mov     [bp+IDEPACK.intpack+INTPACK.di], di
187    mov     [bp+IDEPACK.intpack+INTPACK.si], si
188    mov     [bp+IDEPACK.intpack+INTPACK.bx], bx
[493]189%ifdef MODULE_DRIVEXLATE
[150]190    mov     [bp+IDEPACK.intpack+INTPACK.dh], dh
[414]191%else
192    mov     [bp+IDEPACK.intpack+INTPACK.dx], dx
193%endif
[150]194    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
195    mov     [bp+IDEPACK.intpack+INTPACK.ax], ax
[148]196    pushf
[150]197    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]198    call    RamVars_GetSegmentToDS
[414]199
[493]200%ifdef MODULE_DRIVEXLATE
[414]201    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]    ; DL is still drive number?
[148]202    je      SHORT .ExchangeInt13hHandlers
[414]203    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
[148]204ALIGN JUMP_ALIGN
205.ExchangeInt13hHandlers:
[414]206%endif
207
[249]208%ifdef USE_186
209    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
210    jmp     SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
211%else
[148]212    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[249]213    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
214%endif
[3]215
[417]216
[260]217%ifdef MODULE_SERIAL_FLOPPY
218;--------------------------------------------------------------------
219; Int13h_ReturnSuccessForFloppy
220;
221; Some operations, such as format of a floppy disk track, should just
222; return success, while for hard disks it should be treated as unsupported.
223;--------------------------------------------------------------------
224ALIGN JUMP_ALIGN
225Int13h_ReturnSuccessForFloppy:
226    test    dl, dl
[417]227    js      SHORT UnsupportedFunction
[294]228    xor     ah, ah
[417]229    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[260]230%endif
[3]231
[417]232
[3]233;--------------------------------------------------------------------
[249]234; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
235;   Parameters:
236;       AH:     BIOS Error code
237;       CL:     Number of sectors actually transferred
238;       SS:BP:  Ptr to IDEPACK
239;   Returns:
240;       All registers are loaded from INTPACK
241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
243Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
244    mov     [bp+IDEPACK.intpack+INTPACK.al], cl
245    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
246
[417]247
[249]248;--------------------------------------------------------------------
[148]249; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
250; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]251;   Parameters:
[148]252;       AH:     BIOS Error code
[417]253;       DS:     RAMVARS segment
[150]254;       SS:BP:  Ptr to IDEPACK
[32]255;   Returns:
[148]256;       All registers are loaded from INTPACK
[32]257;--------------------------------------------------------------------
258ALIGN JUMP_ALIGN
[148]259Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[258]260%ifdef MODULE_SERIAL_FLOPPY
261    mov     al, [bp+IDEPACK.intpack+INTPACK.dl]
[294]262Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
[258]263    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
[414]264
[258]265%else
[150]266    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[258]267%endif
[414]268
[148]269Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[417]270    ; Always return with interrupts enabled since there are programs that rely
271    ; on INT 13h to enable interrupts.
272    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags+1], (FLG_FLAGS_IF>>8)
273    mov     sp, bp  ; This makes possible to exit anytime, no matter what is on stack
[443]274    RESTORE_FRAME_INTPACK_FROM_SSBP     SIZE_OF_IDEPACK_WITHOUT_INTPACK
[32]275
276
277;--------------------------------------------------------------------
[148]278; Int13h_CallPreviousInt13hHandler
[3]279;   Parameters:
[148]280;       AH:     INT 13h function to call
281;       DL:     Drive number
282;       DS:     RAMVARS segment
[3]283;   Returns:
284;       Depends on function
[294]285;       NOTE: ES:DI needs to be returned from the previous interrupt
[258]286;             handler, for floppy DPT in function 08h
[3]287;   Corrupts registers:
[258]288;       None
[3]289;--------------------------------------------------------------------
290ALIGN JUMP_ALIGN
[148]291Int13h_CallPreviousInt13hHandler:
292    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
293    int     BIOS_DISK_INTERRUPT_13h
[258]294;;;  fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[35]295
[3]296;--------------------------------------------------------------------
[148]297; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[3]298;   Parameters:
299;       DS:     RAMVARS segment
300;   Returns:
[148]301;       Nothing
[3]302;   Corrupts registers:
[258]303;       Nothing
304;       Note: Flags are preserved
[3]305;--------------------------------------------------------------------
306ALIGN JUMP_ALIGN
[148]307ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
308    push    es
[258]309    push    si
310    LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO  es, si
311    mov     si, [RAMVARS.fpOldI13h]
[150]312    cli
[258]313    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4]
314    mov     [RAMVARS.fpOldI13h], si
315    mov     si, [RAMVARS.fpOldI13h+2]
316    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
[181]317    sti
[258]318    mov     [RAMVARS.fpOldI13h+2], si
319    pop     si
[148]320    pop     es
321    ret
[28]322
[35]323
[150]324;--------------------------------------------------------------------
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, DI
334;--------------------------------------------------------------------
335ALIGN JUMP_ALIGN
[258]336%ifdef MODULE_SERIAL_FLOPPY
337Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
338    ; Store error code to BDA
339    mov     bx, BDA.bHDLastSt
340    test    al, al
[414]341    js      SHORT .HardDisk
[258]342    mov     bl, BDA.bFDRetST & 0xff
343.HardDisk:
344    LOAD_BDA_SEGMENT_TO ds, di
[294]345    mov     [bx], ah
[417]346    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
347
[258]348%else
[150]349Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
350    ; Store error code to BDA
[294]351    LOAD_BDA_SEGMENT_TO ds, di
[150]352    mov     [BDA.bHDLastSt], ah
[417]353    ; Fall to Int13h_SetErrorCodeToIntpackInSSBPfromAH
[258]354%endif
[35]355
[150]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
[3]368; Jump table for correct BIOS function
369ALIGN WORD_ALIGN
370g_rgw13hFuncJump:
[417]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)
[260]376%ifdef MODULE_SERIAL_FLOPPY
[417]377    dw  Int13h_ReturnSuccessForFloppy               ; 05h, Format Disk Track (XT, AT, EISA)
[260]378%else
[417]379    dw  UnsupportedFunction                         ; 05h, Format Disk Track (XT, AT, EISA)
[260]380%endif
[417]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)
[507]388    dw  AH9h_HandlerForInitializeDriveParameters    ; 0Dh, Alternate Disk Reset (All)
[417]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  UnsupportedFunction                         ; 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,
[493]405%ifdef MODULE_8BIT_IDE_ADVANCED
[471]406    dw  AH1Eh_HandlerForXTCFfeatures                ; 1Eh, Lo-tech XT-CF features (XTIDE Universal BIOS)
407%else
[525]408    dw  UnsupportedFunction                         ; 1Eh,
[471]409%endif
[417]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)
[165]417
[176]418%ifdef MODULE_EBIOS
[165]419g_rgwEbiosFunctionJumpTable:
[417]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)**
[150]434;
435;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
436;  ** = Enhanced Disk Drive (EDD) Support
437; *** = Drive Locking and Ejecting Support
[181]438%endif
Note: See TracBrowser for help on using the repository browser.