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

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

More fun with resets: It turns out to be important to reset our drives too, if for not other reason then to have the proper return code set for xlat'd drives (consider the case that we reset foreign drives with dl=80h, and at the same time we have one of our drives mapped to 80h). Fixed bug with polarity of ther iteration routine in ahDh for the return value for ah9h. Update signature in Configurator.

File size: 6.4 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 (or Null if foreign 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 to be idevars offset based instead of drive number based, 
54    ; such that this call must be the last in the list of reset routines called.
55    ;
56    ; This needs to happen after ResetForeignHardDisks, as that call may have set the error code for 80h,
57    ; and we need to override that value if we are xlate'd into 80h with one of our drives.
58    ;
59    call    ResetHardDisksHandledByOurBIOS         
60
61.SkipHardDiskReset:
62    mov     ah, bh
63    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
64
65
66;--------------------------------------------------------------------
67; ResetFloppyDrivesWithInt40h
68;   Parameters:
69;       BL:     Requested drive (DL when entering AH=00h)
70;   Returns:
71;       BH:     Error code from requested drive (if available)
72;   Corrupts registers:
73;       AX, DL, DI
74;--------------------------------------------------------------------
75ResetFloppyDrivesWithInt40h:
76    call    GetDriveNumberForForeignHardDiskHandlerToDL
77    and     dl, 7Fh                     ; Clear hard disk bit
78    xor     ah, ah                      ; Disk Controller Reset
79    int     BIOS_DISKETTE_INTERRUPT_40h
80    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
81
82
83;--------------------------------------------------------------------
84; ResetForeignHardDisks
85;   Parameters:
86;       BL:     Requested drive (DL when entering AH=00h)
87;       DS:     RAMVARS segment
88;   Returns:
89;       BH:     Error code from requested drive (if available)
90;   Corrupts registers:
91;       AX, DL, DI
92;--------------------------------------------------------------------
93ResetForeignHardDisks:
94    call    GetDriveNumberForForeignHardDiskHandlerToDL
95    xor     ah, ah                      ; Disk Controller Reset
96    call    Int13h_CallPreviousInt13hHandler
97;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
98
99
100;--------------------------------------------------------------------
101; BackupErrorCodeFromTheRequestedDriveToBH
102;   Parameters:
103;       AH:     Error code from the last resetted drive
104;       DL:     Drive last resetted
105;       BL:     Requested drive (DL when entering AH=00h)
106;   Returns:
107;       BH:     Backuped error code
108;   Corrupts registers:
109;       Nothing
110;--------------------------------------------------------------------
111BackupErrorCodeFromTheRequestedDriveToBH:
112    cmp     dl, bl              ; Requested drive?
113    eCMOVE  bh, ah
114    ret
115
116
117;--------------------------------------------------------------------
118; GetDriveNumberForForeignHardDiskHandlerToDL
119;   Parameters:
120;       BL:     Requested drive (DL when entering AH=00h)
121;       DS:     RAMVARS segment
122;   Returns:
123;       DS:DI:  Ptr to DPT if our drive (or Null if foreign drive)
124;       DL:     BL if foreign drive
125;               80h if our drive
126;--------------------------------------------------------------------
127GetDriveNumberForForeignHardDiskHandlerToDL:
128    mov     dl, bl
129    test    di, di
130    jz      SHORT .Return
131    mov     dl, 80h             ; First possible Hard Disk should be safe value
132.Return:
133    ret
134
135AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
136
137;--------------------------------------------------------------------
138; ResetHardDisksHandledByOurBIOS
139;   Parameters:
140;       DS:DI:  Ptr to DPT for requested drive
141;               If DPT pointer is not available, or error result in BH won't be used anyway, 
142;               enter through .ErrorCodeNotUsed.
143;       SS:BP:  Ptr to IDEPACK
144;   Returns:
145;       BH:     Error code from requested drive (if available)
146;   Corrupts registers:
147;       AX, BX, CX, DX, SI, DI
148;--------------------------------------------------------------------
149ResetHardDisksHandledByOurBIOS:
150    mov     bl, 0                                       ; Assume Null IdevarsOffset for now, assuming foreign drive
151    test    di, di
152    jz      .ErrorCodeNotUsed
153    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for cmp with dl
154       
155.ErrorCodeNotUsed:                                      ; BH will be garbage on exit if thie entry point is used, 
156                                                        ; but reset of all drives will still happen
157
158    mov     dl, ROMVARS.ideVars0                        ; starting Idevars offset
159
160    call    RamVars_GetIdeControllerCountToCX           ; get count of ide controllers
161    jcxz    .done                                       ; just in case bIdeCnt is zero (shouldn't be)
162.loop:
163    call    FindDPT_ForIdevarsOffsetInDL                ; look for the first drive on this controller, if any
164    jc      .notFound
165
166    call    AHDh_ResetDrive                             ; reset master and slave on that controller
167    call    BackupErrorCodeFromTheRequestedDriveToBH    ; save error code if same controller as drive from entry
168
169.notFound:
170    add     dl, IDEVARS_size                            ; move Idevars pointer forward
171    loop    .loop
172
173.done:
174    ret
Note: See TracBrowser for help on using the repository browser.