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

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

Changes to XTIDE Universal BIOS:

  • AH=0h (Reset) should now work but our drives are no longer reset if DL belongs to foreign drive.
File size: 6.5 KB
Line 
1; Project name  :   XTIDE Universal BIOS
2; Description   :   Int 13h function AH=0h, Disk Controller Reset.
3
4; Section containing code
5SECTION .text
6
7;--------------------------------------------------------------------
8; Int 13h function AH=0h, Disk Controller Reset.
9;
10; Note: We handle all AH=0h calls, even for drives handled by other
11; BIOSes!
12;
13; AH0h_HandlerForDiskControllerReset
14;   Parameters:
15;       DL:     Translated Drive number (ignored so all drives are reset)
16;               If bit 7 is set all hard disks and floppy disks reset.
17;       DS:DI:  Ptr to DPT (only if DL is our drive)
18;       SS:BP:  Ptr to IDEPACK
19;   Returns with INTPACK:
20;       AH:     Int 13h return status (from drive requested in DL)
21;       CF:     0 if succesfull, 1 if error
22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24AH0h_HandlerForDiskControllerReset:
25    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
26    call    ResetFloppyDrivesWithInt40h
27
28%ifdef MODULE_SERIAL_FLOPPY
29;
30; "Reset" emulatd serial floppy drives, if any.  There is nothing to actually do for this reset,
31; but record the proper error return code if one of these floppy drives is the drive requested.
32;
33    call    RamVars_UnpackFlopCntAndFirstToAL
34    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
35                                                        ; Either AH has success code (flop drives are present)
36                                                        ; or it doesn't matter because we won't match drive ffh
37
38    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
39
40    adc     dl, al                                      ; second drive (CF set) if present
41                                                        ; If no drive is present, this will result in ffh which 
42                                                        ; won't match a drive
43    call    BackupErrorCodeFromTheRequestedDriveToBH
44    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
45    call    BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
46%endif
47
48    test    bl, bl                                      ; If we were called with a floppy disk, then we are done,
49    jns     SHORT .SkipHardDiskReset                    ; don't do hard disks.
50       
51    call    ResetForeignHardDisks
52
53    ; Resetting our hard disks will modify dl and bl such that this call must be the last in the list
54    call    GetDriveNumberForForeignHardDiskHandlerToDL ; Load DPT for our drive
55    jc      SHORT .SkipHardDiskReset                    ; Our drive not requested so let's not reset them
56    call    ResetHardDisksHandledByOurBIOS         
57
58.SkipHardDiskReset:
59    mov     ah, bh
60    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
61
62
63;--------------------------------------------------------------------
64; ResetFloppyDrivesWithInt40h
65;   Parameters:
66;       BL:     Requested drive (DL when entering AH=00h)
67;   Returns:
68;       BH:     Error code from requested drive (if available)
69;   Corrupts registers:
70;       AX, DL, DI
71;--------------------------------------------------------------------
72ResetFloppyDrivesWithInt40h:
73    call    GetDriveNumberForForeignHardDiskHandlerToDL
74    and     dl, 7Fh                     ; Clear hard disk bit
75    xor     ah, ah                      ; Disk Controller Reset
76    int     BIOS_DISKETTE_INTERRUPT_40h
77    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
78
79
80;--------------------------------------------------------------------
81; ResetForeignHardDisks
82;   Parameters:
83;       BL:     Requested drive (DL when entering AH=00h)
84;       DS:     RAMVARS segment
85;   Returns:
86;       BH:     Error code from requested drive (if available)
87;   Corrupts registers:
88;       AX, DL, DI
89;--------------------------------------------------------------------
90ResetForeignHardDisks:
91    call    GetDriveNumberForForeignHardDiskHandlerToDL
92    xor     ah, ah                      ; Disk Controller Reset
93    call    Int13h_CallPreviousInt13hHandler
94;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
95
96
97;--------------------------------------------------------------------
98; BackupErrorCodeFromTheRequestedDriveToBH
99;   Parameters:
100;       AH:     Error code from the last resetted drive
101;       DL:     Drive last resetted
102;       BL:     Requested drive (DL when entering AH=00h)
103;   Returns:
104;       BH:     Backuped error code
105;   Corrupts registers:
106;       Nothing
107;--------------------------------------------------------------------
108BackupErrorCodeFromTheRequestedDriveToBH:
109    cmp     dl, bl              ; Requested drive?
110    eCMOVE  bh, ah
111    ret
112
113
114;--------------------------------------------------------------------
115; GetDriveNumberForForeignHardDiskHandlerToDL
116;   Parameters:
117;       BL:     Requested drive (DL when entering AH=00h)
118;       DS:     RAMVARS segment
119;   Returns:
120;       DS:DI:  Ptr to DPT if our drive
121;       DL:     BL if foreign drive
122;               80h if our drive
123;       CF:     Set if foreign drive
124;               Cleared if our drive
125;   Corrupts registers:
126;       (DI)
127;--------------------------------------------------------------------
128GetDriveNumberForForeignHardDiskHandlerToDL:
129    mov     dl, bl
130    call    FindDPT_ForDriveNumberInDL
131    jc      SHORT .ReturnWithForeignDriveInDL
132    mov     dl, 80h             ; First possible Hard Disk should be safe value
133.ReturnWithForeignDriveInDL:
134    ret
135
136
137;--------------------------------------------------------------------
138; AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization
139;   Parameters:
140;       DS:     RAMVARS segment
141;       SS:BP:  Ptr to IDEPACK
142;   Returns:
143;       Nothing
144;   Corrupts registers:
145;       AX, BX, CX, DX, SI, DI
146;--------------------------------------------------------------------
147AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization:
148    mov     bl, [RAMVARS.bFirstDrv]
149    call    GetDriveNumberForForeignHardDiskHandlerToDL
150    ; Fall to ResetHardDisksHandledByOurBIOS
151
152;--------------------------------------------------------------------
153; ResetHardDisksHandledByOurBIOS
154;   Parameters:
155;       BL:     Requested drive (DL when entering AH=00h)
156;       DS:DI:  Ptr to DPT for requested drive
157;       SS:BP:  Ptr to IDEPACK
158;   Returns:
159;       BH:     Error code from requested drive (if available)
160;   Corrupts registers:
161;       AX, CX, DX, SI, DI
162;--------------------------------------------------------------------
163ResetHardDisksHandledByOurBIOS:
164    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for cmp with dl
165    mov     dl, ROMVARS.ideVars0                        ; starting Idevars offset
166
167    call    RamVars_GetIdeControllerCountToCX           ; get count of ide controllers
168    jcxz    .done                                       ; just in case bIdeCnt is zero (shouldn't be)
169.loop:
170    call    FindDPT_ForIdevarsOffsetInDL                ; look for the first drive on this controller, if any
171    jc      .notFound
172
173    call    AHDh_ResetDrive                             ; reset master and slave on that controller
174    call    BackupErrorCodeFromTheRequestedDriveToBH    ; save error code if same controller as drive from entry
175
176.notFound:
177    add     dl, IDEVARS_size                            ; move Idevars pointer forward
178    loop    .loop
179
180.done:
181    ret
Note: See TracBrowser for help on using the repository browser.