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

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

Removed align directives for initalization code and added define for align in boot-time calls to the assembly library (defaulting to 1), resulting in a significant savings for the AT and 386 builds. Fixed a bug with switch command line handling in the serial server. Put in CR characters in licesnse.txt, so that it properly displays on Windows. In the configurator, added default values for user supplied CHS and LBA values, defaulting to values within range when those features are enabled. Updated the copyright message in the configurator as the literal word Copyright is important.

File size: 6.7 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 successful, 1 if error
22;--------------------------------------------------------------------
23AH0h_HandlerForDiskControllerReset:
24    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
25    call    ResetFloppyDrivesWithInt40h
26
27%ifdef MODULE_SERIAL_FLOPPY
28;
29; "Reset" emulated serial floppy drives, if any.  There is nothing to actually do for this reset,
30; but record the proper error return code if one of these floppy drives is the drive requested.
31;
32    call    RamVars_UnpackFlopCntAndFirstToAL
33    cbw                                                 ; Clears AH (there are flop drives) or ffh (there are not)
34                                                        ; Either AH has success code (flop drives are present)
35                                                        ; or it doesn't matter because we won't match drive ffh
36
37    cwd                                                 ; clears DX (there are flop drives) or ffffh (there are not)
38
39    adc     dl, al                                      ; second drive (CF set) if present
40                                                        ; If no drive is present, this will result in ffh which
41                                                        ; won't match a drive
42    call    BackupErrorCodeFromTheRequestedDriveToBH
43    mov     dl, al                                      ; We may end up doing the first drive twice (if there is
44    call    BackupErrorCodeFromTheRequestedDriveToBH    ; only one drive), but doing it again is not harmful.
45%endif
46
47    test    bl, bl                                      ; If we were called with a floppy disk, then we are done,
48    jns     SHORT .SkipHardDiskReset                    ; don't do hard disks.
49
50    call    ResetForeignHardDisks
51
52    ; Resetting our hard disks will modify dl and bl to be idevars offset based instead of drive number based,
53    ; such that this call must be the last in the list of reset routines called.
54    ;
55    ; This needs to happen after ResetForeignHardDisks, as that call may have set the error code for 80h,
56    ; and we need to override that value if we are xlate'd into 80h with one of our drives.
57    ;
58    call    ResetHardDisksHandledByOurBIOS
59
60.SkipHardDiskReset:
61    mov     ah, bh
62    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
63
64
65;--------------------------------------------------------------------
66; ResetFloppyDrivesWithInt40h
67;   Parameters:
68;       BL:     Requested drive (DL when entering AH=00h)
69;   Returns:
70;       BH:     Error code from requested drive (if available)
71;   Corrupts registers:
72;       AX, DL, DI
73;--------------------------------------------------------------------
74ResetFloppyDrivesWithInt40h:
75    call    GetDriveNumberForForeignHardDiskHandlerToDL
76    and     dl, 7Fh                     ; Clear hard disk bit
77    xor     ah, ah                      ; Disk Controller Reset
78    int     BIOS_DISKETTE_INTERRUPT_40h
79    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
80
81
82;--------------------------------------------------------------------
83; ResetForeignHardDisks
84;   Parameters:
85;       BL:     Requested drive (DL when entering AH=00h)
86;       DS:     RAMVARS segment
87;   Returns:
88;       BH:     Error code from requested drive (if available)
89;   Corrupts registers:
90;       AX, DL, DI
91;--------------------------------------------------------------------
92ResetForeignHardDisks:
93    call    GetDriveNumberForForeignHardDiskHandlerToDL
94    xor     ah, ah                      ; Disk Controller Reset
95    call    Int13h_CallPreviousInt13hHandler
96;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
97
98
99;--------------------------------------------------------------------
100; BackupErrorCodeFromTheRequestedDriveToBH
101;   Parameters:
102;       AH:     Error code from the last resetted drive
103;       DL:     Drive last resetted
104;       BL:     Requested drive (DL when entering AH=00h)
105;   Returns:
106;       BH:     Backuped error code
107;   Corrupts registers:
108;       Nothing
109;--------------------------------------------------------------------
110BackupErrorCodeFromTheRequestedDriveToBH:
111    cmp     dl, bl              ; Requested drive?
112    eCMOVE  bh, ah
113    ret
114
115
116;--------------------------------------------------------------------
117; GetDriveNumberForForeignHardDiskHandlerToDL
118;   Parameters:
119;       BL:     Requested drive (DL when entering AH=00h)
120;       DS:     RAMVARS segment
121;   Returns:
122;       DS:DI:  Ptr to DPT if our drive (or Null if foreign drive)
123;       DL:     BL if foreign drive
124;               80h if our drive
125;--------------------------------------------------------------------
126GetDriveNumberForForeignHardDiskHandlerToDL:
127    mov     dl, bl
128    test    di, di
129    jz      SHORT .Return
130    mov     dl, 80h             ; First possible Hard Disk should be safe value
131.Return:
132    ret
133
134AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
135
136;--------------------------------------------------------------------
137; ResetHardDisksHandledByOurBIOS
138;   Parameters:
139;       DS:DI:  Ptr to DPT for requested drive
140;               If DPT pointer is not available, or error result in BH won't be used anyway,
141;               enter through .ErrorCodeNotUsed.
142;       SS:BP:  Ptr to IDEPACK
143;   Returns:
144;       BH:     Error code from requested drive (if available)
145;   Corrupts registers:
146;       AX, BX, CX, DX, SI, DI
147;--------------------------------------------------------------------
148ResetHardDisksHandledByOurBIOS:
149    xor     bl, bl                                      ; Assume Null IdevarsOffset for now, assuming foreign drive
150    test    di, di
151    jz      .ErrorCodeNotUsed
152    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for cmp with dl
153
154.ErrorCodeNotUsed:                                      ; BH will be garbage on exit if this entry point is used,
155                                                        ; but reset of all drives will still happen
156
157    mov     dl, ROMVARS.ideVars0                        ; starting Idevars offset
158
159    ; Get count of ALL Idevars structures, not just the ones that are configured.  This may seem odd, 
160    ; but it catches the .ideVarsSerialAuto structure, which would not be scanned if the count from
161    ; RamVars_GetIdeControllerCountToCX was used.  Unused controllers won't make a difference, since no DPT
162    ; will point to them.  Performance isn't an issue, as this is a reset operation.
163    ;
164    mov     cx, (ROMVARS.ideVarsEnd - ROMVARS.ideVarsBegin) / IDEVARS_size
165
166.loop:
167    call    FindDPT_ForIdevarsOffsetInDL                ; look for the first drive on this controller, if any
168    jc      .notFound
169
170    call    AHDh_ResetDrive                             ; reset master and slave on that controller
171    call    BackupErrorCodeFromTheRequestedDriveToBH    ; save error code if same controller as drive from entry
172
173.notFound:
174    add     dl, IDEVARS_size                            ; move Idevars pointer forward
175    loop    .loop
176
177.done:
178    ret
Note: See TracBrowser for help on using the repository browser.