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

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

Changes to XTIDE Universal BIOS:

  • Short timeouts for drive detection work again.
  • All drives are now reset before booting (instead of XTIDE Universal BIOS controlled drives only).
  • Windows 98 now works without tricks (Floppy Drive accesses are redirected from INT 13h to 40h).
File size: 6.6 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h function AH=0h, Disk Controller Reset.
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 function AH=0h, Disk Controller Reset.
25;
26; Note: We handle all AH=0h calls, even for drives handled by other
27; BIOSes!
28;
29; AH0h_HandlerForDiskControllerReset
30;   Parameters:
31;       DL:     Translated Drive number (ignored so all drives are reset)
32;               If bit 7 is set all hard disks and floppy disks reset.
33;       DS:DI:  Ptr to DPT (or Null if foreign drive)
34;       SS:BP:  Ptr to IDEPACK
35;   Returns with INTPACK:
36;       AH:     Int 13h return status (from drive requested in DL)
37;       CF:     0 if successful, 1 if error
38;--------------------------------------------------------------------
39AH0h_HandlerForDiskControllerReset:
40    ; Reset foreign Floppy and Hard Drives (those handled by other BIOSes)
41    eMOVZX  bx, dl                                      ; Copy requested drive to BL and zero BH to assume no errors
42
43    xor     ah, ah                                      ; Disk Controller Reset
44    call    Int13h_CallPreviousInt13hHandler            ; Reset floppy drives only or floppy drives and foreign hard disks
45    call    BackupErrorCodeFromTheRequestedDriveToBH
46
47%ifdef MODULE_SERIAL_FLOPPY
48;
49; "Reset" emulated serial floppy drives, if any.  There is nothing to actually do for this reset,
50; but record the proper error return code if one of these floppy drives is the drive requested.
51;
52    call    RamVars_UnpackFlopCntAndFirstToAL
53    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
54                                                        ; Either AH has success code (flop drives are present)
55                                                        ; or it doesn't matter because we won't match drive ffh
56
57    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
58
59    adc     dl, al                                      ; second drive (CF set) if present
60                                                        ; If no drive is present, this will result in ffh which
61                                                        ; won't match a drive
62    call    BackupErrorCodeFromTheRequestedDriveToBH
63    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
64    call    BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
65%endif
66    test    bl, bl                                      ; If we were called with a floppy disk, then we are done,
67    jns     SHORT .SkipHardDiskReset                    ; don't do hard disks.
68
69    ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
70    ; such that this call must be the last in the list of reset routines called.
71    ;
72    ; This needs to happen after ResetForeignDrives, as that call may have set the error code for 80h,
73    ; and we need to override that value if we are xlate'd into 80h with one of our drives.
74    ;
75    call    ResetHardDisksHandledByOurBIOS
76
77.SkipHardDiskReset:
78    mov     ah, bh
79    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
80
81
82;--------------------------------------------------------------------
83; BackupErrorCodeFromTheRequestedDriveToBH
84;   Parameters:
85;       AH:     Error code from the last resetted drive
86;       DL:     Drive last resetted
87;       BL:     Requested drive (DL when entering AH=00h)
88;   Returns:
89;       BH:     Backuped error code
90;   Corrupts registers:
91;       Nothing
92;--------------------------------------------------------------------
93BackupErrorCodeFromTheRequestedDriveToBH:
94    cmp     dl, bl              ; Requested drive?
95    eCMOVE  bh, ah
96    ret
97
98
99;--------------------------------------------------------------------
100; ResetHardDisksHandledByOurBIOS
101;   Parameters:
102;       BL:     Requested drive (DL when entering AH=00h)
103;       DS:DI:  Ptr to DPT for requested drive
104;               If DPT pointer is not available, or error result in BH won't be used anyway,
105;               enter through .ErrorCodeNotUsed.
106;       SS:BP:  Ptr to IDEPACK
107;   Returns:
108;       BH:     Error code from requested drive (if available)
109;   Corrupts registers:
110;       AX, BX, CX, DX, SI, DI
111;--------------------------------------------------------------------
112ResetHardDisksHandledByOurBIOS:
113    xor     bl, bl                                      ; Assume Null IdevarsOffset for now, assuming foreign drive
114    test    di, di
115    jz      SHORT .ErrorCodeNotUsed
116    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for cmp with dl
117.ErrorCodeNotUsed:                                      ; BH will be garbage on exit if this entry point is used,
118                                                        ; but reset of all drives will still happen
119    mov     dl, ROMVARS.ideVars0                        ; starting Idevars offset
120
121    ; Get count of ALL Idevars structures, not just the ones that are configured.  This may seem odd,
122    ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from
123    ; RamVars_GetIdeControllerCountToCX was used.  Unused controllers won't make a difference, since no DPT
124    ; will point to them.  Performance isn't an issue, as this is a reset operation.
125    ;
126    mov     cx, NUMBER_OF_IDEVARS
127
128.loop:
129    call    FindDPT_MasterOrSingleForIdevarsOffsetInDL
130    jc      SHORT .ControllerNotAvailable
131
132    ; Reset controller (both Master and Slave Drive). We ignore error codes
133    ; here since initialization is the one that matters.
134    push    cx
135    push    dx
136    push    bx
137%ifdef MODULE_IRQ
138    call    Interrupts_UnmaskInterruptControllerForDriveInDSDI
139%endif
140    call    Device_ResetMasterAndSlaveController
141%ifdef MODULE_ADVANCED_ATA
142    call    AdvAtaInit_InitializeControllerForDPTinDSDI
143%endif
144    pop     bx
145    pop     dx
146
147    ; Initialize Master Drive
148    call    AH9h_InitializeDriveForUse                  ; Initialize Master drive
149    call    BackupErrorCodeFromTheRequestedDriveToBH
150
151    ; Initialize Slave Drive
152    call    FindDPT_SlaveForIdevarsOffsetInDL
153    jc      SHORT .SlaveDriveNotAvailable
154    call    AH9h_InitializeDriveForUse
155    ; Here we have a small problem. Since DL now has offset to IDEVARS, it will be the same
156    ; for both Master and Slave Drive. We simply ignore error from slave drive reset since most
157    ; systems do not have slave drives at all and it is unlikely that AH=00h would be called for
158    ; specific drive anyway. AH=Dh is for that.
159
160.SlaveDriveNotAvailable:
161    pop     cx
162.ControllerNotAvailable:
163    add     dl, IDEVARS_size                            ; move Idevars pointer forward
164    loop    .loop
165    ret
Note: See TracBrowser for help on using the repository browser.