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

Last change on this file since 414 was 414, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • MEMPIOVARS no longer overflow when not building MODULE_EBIOS.
File size: 13.9 KB
RevLine 
[90]1; Project name  :   XTIDE Universal BIOS
[3]2; Description   :   Int 13h BIOS functions (Floppy and Hard disk).
3
[376]4;
5; XTIDE Universal BIOS and Associated Tools 
6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 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
[3]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
24; Int 13h software interrupt handler.
25; Jumps to specific function defined in AH.
26;
[148]27; Note to developers: Do not make recursive INT 13h calls!
28;
29; Int13h_DiskFunctionsHandler
[3]30;   Parameters:
31;       AH:     Bios function
32;       DL:     Drive number
[148]33;       Other:  Depends on function
[3]34;   Returns:
35;       Depends on function
36;--------------------------------------------------------------------
37ALIGN JUMP_ALIGN
[148]38Int13h_DiskFunctionsHandler:
[3]39    sti                                 ; Enable interrupts
[150]40    cld                                 ; String instructions to increment pointers
[155]41    CREATE_FRAME_INTPACK_TO_SSBP    EXTRA_BYTES_FOR_INTPACK
[3]42
43    call    RamVars_GetSegmentToDS
[294]44
[395]45%ifdef MODULE_HOTKEYS
[148]46    call    DriveXlate_ToOrBack
[414]47    mov     [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv], dl
[395]48%endif
[294]49
[322]50    call    FindDPT_ForDriveNumberInDL  ; DS:DI points to our DPT, or NULL if not our drive
51    jc      SHORT .NotOurDrive          ; DPT not found so this is not one of our drives
[258]52
[294]53.OurFunction:
[3]54    ; Jump to correct BIOS function
[148]55    eMOVZX  bx, ah
56    shl     bx, 1
[165]57    cmp     ah, 25h                     ; Possible EBIOS function?
[176]58%ifdef MODULE_EBIOS
[165]59    ja      SHORT .JumpToEbiosFunction
[176]60%else
61    ja      SHORT Int13h_UnsupportedFunction
62%endif
[148]63    jmp     [cs:bx+g_rgw13hFuncJump]    ; Jump to BIOS function
[3]64
[176]65%ifdef MODULE_EBIOS
[165]66    ; Jump to correct EBIOS function
67ALIGN JUMP_ALIGN
68.JumpToEbiosFunction:
[167]69    test    BYTE [di+DPT.bFlagsLow], FLG_DRVNHEAD_LBA
70    jz      SHORT Int13h_UnsupportedFunction    ; No eINT 13h for CHS drives
[322]71    sub     bl, 41h<<1                  ; BX = Offset to eINT 13h jump table
72    jb      SHORT Int13h_UnsupportedFunction
[167]73    cmp     ah, 48h
[165]74    ja      SHORT Int13h_UnsupportedFunction
75    jmp     [cs:bx+g_rgwEbiosFunctionJumpTable]
[176]76%endif
[3]77
[322]78ALIGN JUMP_ALIGN
79.NotOurDrive:
80    test    ah, ah
81    jz      SHORT .OurFunction          ; We handle all function 0h requests (resets)
[260]82
[322]83%ifndef MODULE_SERIAL_FLOPPY
84; Without floppy support, we handle only hard disk traffic for function 08h.
85    test    dl, dl
86    jns     SHORT Int13h_DirectCallToAnotherBios
87%endif
88; With floppy support, we handle all traffic for function 08h, as we need to wrap both hard disk and floppy drive counts.
89    cmp     ah, 8
90    je      SHORT .OurFunction
91    ; Fall to Int13h_DirectCallToAnotherBios
92
[3]93;--------------------------------------------------------------------
[148]94; Int13h_UnsupportedFunction
[3]95; Int13h_DirectCallToAnotherBios
96;   Parameters:
[148]97;       DL:     Translated drive number
[3]98;       DS:     RAMVARS segment
[150]99;       SS:BP:  Ptr to IDEPACK
[148]100;       BX, DI: Corrupted on Int13h_DiskFunctionsHandler
[161]101;       Other:  Function specific INT 13h parameters
[3]102;   Returns:
103;       Depends on function
104;   Corrupts registers:
105;       Flags
106;--------------------------------------------------------------------
107ALIGN JUMP_ALIGN
108Int13h_UnsupportedFunction:
109Int13h_DirectCallToAnotherBios:
[148]110    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[150]111    mov     bx, [bp+IDEPACK.intpack+INTPACK.bx]
112    mov     di, [bp+IDEPACK.intpack+INTPACK.di]
113    mov     ds, [bp+IDEPACK.intpack+INTPACK.ds]
114    push    WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]115    popf
116    push    bp
[150]117    mov     bp, [bp+IDEPACK.intpack+INTPACK.bp]
[148]118    int     BIOS_DISK_INTERRUPT_13h ; Can safely do as much recursion as it wants
[3]119
[148]120    ; Store returned values to INTPACK
121    pop     bp  ; Standard INT 13h functions never uses BP as return register
122%ifdef USE_386
[322]123;   mov     [bp+IDEPACK.intpack+INTPACK.gs], gs
124;   mov     [bp+IDEPACK.intpack+INTPACK.fs], fs
[148]125%endif
[150]126    mov     [bp+IDEPACK.intpack+INTPACK.es], es
127    mov     [bp+IDEPACK.intpack+INTPACK.ds], ds
128    mov     [bp+IDEPACK.intpack+INTPACK.di], di
129    mov     [bp+IDEPACK.intpack+INTPACK.si], si
130    mov     [bp+IDEPACK.intpack+INTPACK.bx], bx
[414]131%ifdef MODULE_HOTKEYS
[150]132    mov     [bp+IDEPACK.intpack+INTPACK.dh], dh
[414]133%else
134    mov     [bp+IDEPACK.intpack+INTPACK.dx], dx
135%endif
[150]136    mov     [bp+IDEPACK.intpack+INTPACK.cx], cx
137    mov     [bp+IDEPACK.intpack+INTPACK.ax], ax
[148]138    pushf
[150]139    pop     WORD [bp+IDEPACK.intpack+INTPACK.flags]
[148]140    call    RamVars_GetSegmentToDS
[414]141
142%ifdef MODULE_HOTKEYS
143    cmp     dl, [RAMVARS.xlateVars+XLATEVARS.bXlatedDrv]    ; DL is still drive number?
[148]144    je      SHORT .ExchangeInt13hHandlers
[414]145    mov     [bp+IDEPACK.intpack+INTPACK.dl], dl ; Something is returned in DL
[148]146ALIGN JUMP_ALIGN
147.ExchangeInt13hHandlers:
[414]148%endif
149
[249]150%ifdef USE_186
151    push    Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
152    jmp     SHORT ExchangeCurrentInt13hHandlerWithOldInt13hHandler
153%else
[148]154    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[249]155    jmp     SHORT Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
156%endif
[3]157
[260]158%ifdef MODULE_SERIAL_FLOPPY
159;--------------------------------------------------------------------
160; Int13h_ReturnSuccessForFloppy
161;
162; Some operations, such as format of a floppy disk track, should just
163; return success, while for hard disks it should be treated as unsupported.
164;--------------------------------------------------------------------
165ALIGN JUMP_ALIGN
166Int13h_ReturnSuccessForFloppy:
167    test    dl, dl
168    js      short Int13h_UnsupportedFunction
[294]169    xor     ah, ah
[260]170    jmp     short Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
171%endif
[3]172
173;--------------------------------------------------------------------
[249]174; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL
175;   Parameters:
176;       AH:     BIOS Error code
177;       CL:     Number of sectors actually transferred
178;       SS:BP:  Ptr to IDEPACK
179;   Returns:
180;       All registers are loaded from INTPACK
181;--------------------------------------------------------------------
182ALIGN JUMP_ALIGN
183Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAHandTransferredSectorsFromCL:
184    mov     [bp+IDEPACK.intpack+INTPACK.al], cl
185    ; Fall to Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
186
187;--------------------------------------------------------------------
[148]188; Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
189; Int13h_ReturnFromHandlerWithoutStoringErrorCode
[32]190;   Parameters:
[148]191;       AH:     BIOS Error code
[150]192;       SS:BP:  Ptr to IDEPACK
[32]193;   Returns:
[148]194;       All registers are loaded from INTPACK
[32]195;--------------------------------------------------------------------
196ALIGN JUMP_ALIGN
[148]197Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH:
[258]198%ifdef MODULE_SERIAL_FLOPPY
199    mov     al, [bp+IDEPACK.intpack+INTPACK.dl]
[294]200Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH_ALHasDriveNumber:
[258]201    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber
[414]202
[258]203%else
[150]204    call    Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
[258]205%endif
[414]206
[148]207Int13h_ReturnFromHandlerWithoutStoringErrorCode:
[150]208    or      WORD [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_IF   ; Return with interrupts enabled
[148]209    mov     sp, bp                                  ; Now we can exit anytime
[155]210    RESTORE_FRAME_INTPACK_FROM_SSBP     EXTRA_BYTES_FOR_INTPACK
[32]211
212
213;--------------------------------------------------------------------
[148]214; Int13h_CallPreviousInt13hHandler
[3]215;   Parameters:
[148]216;       AH:     INT 13h function to call
217;       DL:     Drive number
218;       DS:     RAMVARS segment
[3]219;   Returns:
220;       Depends on function
[294]221;       NOTE: ES:DI needs to be returned from the previous interrupt
[258]222;             handler, for floppy DPT in function 08h
[3]223;   Corrupts registers:
[258]224;       None
[3]225;--------------------------------------------------------------------
226ALIGN JUMP_ALIGN
[148]227Int13h_CallPreviousInt13hHandler:
228    call    ExchangeCurrentInt13hHandlerWithOldInt13hHandler
229    int     BIOS_DISK_INTERRUPT_13h
[258]230;;;  fall-through to ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[35]231
[3]232;--------------------------------------------------------------------
[148]233; ExchangeCurrentInt13hHandlerWithOldInt13hHandler
[3]234;   Parameters:
235;       DS:     RAMVARS segment
236;   Returns:
[148]237;       Nothing
[3]238;   Corrupts registers:
[258]239;       Nothing
240;       Note: Flags are preserved
[3]241;--------------------------------------------------------------------
242ALIGN JUMP_ALIGN
[148]243ExchangeCurrentInt13hHandlerWithOldInt13hHandler:
244    push    es
[258]245    push    si
246    LOAD_BDA_SEGMENT_PRESERVE_FLAGS_TO  es, si
247    mov     si, [RAMVARS.fpOldI13h]
[150]248    cli
[258]249    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4]
250    mov     [RAMVARS.fpOldI13h], si
251    mov     si, [RAMVARS.fpOldI13h+2]
252    xchg    si, [es:BIOS_DISK_INTERRUPT_13h*4+2]
[181]253    sti
[258]254    mov     [RAMVARS.fpOldI13h+2], si
255    pop     si
[148]256    pop     es
257    ret
[28]258
[35]259
[150]260;--------------------------------------------------------------------
261; Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH
262; Int13h_SetErrorCodeToIntpackInSSBPfromAH
263;   Parameters:
264;       AH:     BIOS error code (00h = no error)
265;       SS:BP:  Ptr to IDEPACK
266;   Returns:
267;       SS:BP:  Ptr to IDEPACK with error condition set
268;   Corrupts registers:
269;       DS, DI
270;--------------------------------------------------------------------
271ALIGN JUMP_ALIGN
[258]272%ifdef MODULE_SERIAL_FLOPPY
273Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH_ALHasDriveNumber:
274    ; Store error code to BDA
275    mov     bx, BDA.bHDLastSt
276    test    al, al
[414]277    js      SHORT .HardDisk
[258]278    mov     bl, BDA.bFDRetST & 0xff
279.HardDisk:
280    LOAD_BDA_SEGMENT_TO ds, di
[294]281    mov     [bx], ah
[258]282%else
[150]283Int13h_SetErrorCodeToBdaAndToIntpackInSSBPfromAH:
284    ; Store error code to BDA
[294]285    LOAD_BDA_SEGMENT_TO ds, di
[150]286    mov     [BDA.bHDLastSt], ah
[258]287%endif
[35]288
[150]289    ; Store error code to INTPACK
290Int13h_SetErrorCodeToIntpackInSSBPfromAH:
291    mov     [bp+IDEPACK.intpack+INTPACK.ah], ah
292    test    ah, ah
293    jnz     SHORT .SetCFtoIntpack
294    and     BYTE [bp+IDEPACK.intpack+INTPACK.flags], ~FLG_FLAGS_CF
295    ret
296.SetCFtoIntpack:
297    or      BYTE [bp+IDEPACK.intpack+INTPACK.flags], FLG_FLAGS_CF
298    ret
299
300
[3]301; Jump table for correct BIOS function
302ALIGN WORD_ALIGN
303g_rgw13hFuncJump:
304    dw  AH0h_HandlerForDiskControllerReset              ; 00h, Disk Controller Reset (All)
305    dw  AH1h_HandlerForReadDiskStatus                   ; 01h, Read Disk Status (All)
306    dw  AH2h_HandlerForReadDiskSectors                  ; 02h, Read Disk Sectors (All)
307    dw  AH3h_HandlerForWriteDiskSectors                 ; 03h, Write Disk Sectors (All)
308    dw  AH4h_HandlerForVerifyDiskSectors                ; 04h, Verify Disk Sectors (All)
[260]309%ifdef MODULE_SERIAL_FLOPPY
310    dw  Int13h_ReturnSuccessForFloppy                   ; 05h, Format Disk Track (XT, AT, EISA)
311%else
[90]312    dw  Int13h_UnsupportedFunction                      ; 05h, Format Disk Track (XT, AT, EISA)
[260]313%endif
[3]314    dw  Int13h_UnsupportedFunction                      ; 06h, Format Disk Track with Bad Sectors (XT)
315    dw  Int13h_UnsupportedFunction                      ; 07h, Format Multiple Cylinders (XT)
316    dw  AH8h_HandlerForReadDiskDriveParameters          ; 08h, Read Disk Drive Parameters (All)
317    dw  AH9h_HandlerForInitializeDriveParameters        ; 09h, Initialize Drive Parameters (All)
318    dw  Int13h_UnsupportedFunction                      ; 0Ah, Read Disk Sectors with ECC (XT, AT, EISA)
319    dw  Int13h_UnsupportedFunction                      ; 0Bh, Write Disk Sectors with ECC (XT, AT, EISA)
320    dw  AHCh_HandlerForSeek                             ; 0Ch, Seek (All)
321    dw  AHDh_HandlerForResetHardDisk                    ; 0Dh, Alternate Disk Reset (All)
322    dw  Int13h_UnsupportedFunction                      ; 0Eh, Read Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
323    dw  Int13h_UnsupportedFunction                      ; 0Fh, Write Sector Buffer (XT, PS/1), ESDI Undocumented Diagnostic (PS/2)
324    dw  AH10h_HandlerForCheckDriveReady                 ; 10h, Check Drive Ready (All)
325    dw  AH11h_HandlerForRecalibrate                     ; 11h, Recalibrate (All)
326    dw  Int13h_UnsupportedFunction                      ; 12h, Controller RAM Diagnostic (XT)
327    dw  Int13h_UnsupportedFunction                      ; 13h, Drive Diagnostic (XT)
[90]328    dw  Int13h_UnsupportedFunction                      ; 14h, Controller Internal Diagnostic (All)
[3]329    dw  AH15h_HandlerForReadDiskDriveSize               ; 15h, Read Disk Drive Size (AT+)
[161]330    dw  Int13h_UnsupportedFunction                      ; 16h,
331    dw  Int13h_UnsupportedFunction                      ; 17h,
332    dw  Int13h_UnsupportedFunction                      ; 18h,
[3]333    dw  Int13h_UnsupportedFunction                      ; 19h, Park Heads (PS/2)
334    dw  Int13h_UnsupportedFunction                      ; 1Ah, Format ESDI Drive (PS/2)
335    dw  Int13h_UnsupportedFunction                      ; 1Bh, Get ESDI Manufacturing Header (PS/2)
336    dw  Int13h_UnsupportedFunction                      ; 1Ch, ESDI Special Functions (PS/2)
[161]337    dw  Int13h_UnsupportedFunction                      ; 1Dh,
338    dw  Int13h_UnsupportedFunction                      ; 1Eh,
339    dw  Int13h_UnsupportedFunction                      ; 1Fh,
340    dw  Int13h_UnsupportedFunction                      ; 20h,
[3]341    dw  Int13h_UnsupportedFunction                      ; 21h, Read Disk Sectors, Multiple Blocks (PS/1)
342    dw  Int13h_UnsupportedFunction                      ; 22h, Write Disk Sectors, Multiple Blocks (PS/1)
343    dw  AH23h_HandlerForSetControllerFeatures           ; 23h, Set Controller Features Register (PS/1)
344    dw  AH24h_HandlerForSetMultipleBlocks               ; 24h, Set Multiple Blocks (PS/1)
345    dw  AH25h_HandlerForGetDriveInformation             ; 25h, Get Drive Information (PS/1)
[165]346
[176]347%ifdef MODULE_EBIOS
[165]348g_rgwEbiosFunctionJumpTable:
349    dw  AH41h_HandlerForCheckIfExtensionsPresent        ; 41h, Check if Extensions Present (EBIOS)*
350    dw  AH42h_HandlerForExtendedReadSectors             ; 42h, Extended Read Sectors (EBIOS)*
351    dw  AH43h_HandlerForExtendedWriteSectors            ; 43h, Extended Write Sectors (EBIOS)*
352    dw  AH44h_HandlerForExtendedVerifySectors           ; 44h, Extended Verify Sectors (EBIOS)*
353    dw  Int13h_UnsupportedFunction                      ; 45h, Lock and Unlock Drive (EBIOS)***
354    dw  Int13h_UnsupportedFunction                      ; 46h, Eject Media Request (EBIOS)***
355    dw  AH47h_HandlerForExtendedSeek                    ; 47h, Extended Seek (EBIOS)*
356    dw  AH48h_HandlerForGetExtendedDriveParameters      ; 48h, Get Extended Drive Parameters (EBIOS)*
[150]357;   dw  Int13h_UnsupportedFunction                      ; 49h, Get Extended Disk Change Status (EBIOS)***
[3]358;   dw  Int13h_UnsupportedFunction                      ; 4Ah, Initiate Disk Emulation (Bootable CD-ROM)
359;   dw  Int13h_UnsupportedFunction                      ; 4Bh, Terminate Disk Emulation (Bootable CD-ROM)
360;   dw  Int13h_UnsupportedFunction                      ; 4Ch, Initiate Disk Emulation and Boot (Bootable CD-ROM)
361;   dw  Int13h_UnsupportedFunction                      ; 4Dh, Return Boot Catalog (Bootable CD-ROM)
[150]362;   dw  Int13h_UnsupportedFunction                      ; 4Eh, Set Hardware Configuration (EBIOS)**
363;
364;   * = Enhanced Drive Access Support (minimum required EBIOS functions)
365;  ** = Enhanced Disk Drive (EDD) Support
366; *** = Drive Locking and Ejecting Support
[181]367%endif
Note: See TracBrowser for help on using the repository browser.