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
RevLine 
[128]1; Project name  :   XTIDE Universal BIOS
[3]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;
[271]10; Note: We handle all AH=0h calls, even for drives handled by other
11; BIOSes!
12;
[3]13; AH0h_HandlerForDiskControllerReset
14;   Parameters:
[148]15;       DL:     Translated Drive number (ignored so all drives are reset)
[3]16;               If bit 7 is set all hard disks and floppy disks reset.
[275]17;       DS:DI:  Ptr to DPT (or Null if foreign drive)
[150]18;       SS:BP:  Ptr to IDEPACK
19;   Returns with INTPACK:
[23]20;       AH:     Int 13h return status (from drive requested in DL)
[3]21;       CF:     0 if succesfull, 1 if error
22;--------------------------------------------------------------------
23ALIGN JUMP_ALIGN
24AH0h_HandlerForDiskControllerReset:
[23]25    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
[26]26    call    ResetFloppyDrivesWithInt40h
[259]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       
[26]51    call    ResetForeignHardDisks
[264]52
[275]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    ;
[282]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    ;
[271]59    call    ResetHardDisksHandledByOurBIOS         
[264]60
[26]61.SkipHardDiskReset:
[148]62    mov     ah, bh
63    jmp     Int13h_ReturnFromHandlerAfterStoringErrorCodeFromAH
[3]64
65
66;--------------------------------------------------------------------
[26]67; ResetFloppyDrivesWithInt40h
[3]68;   Parameters:
[23]69;       BL:     Requested drive (DL when entering AH=00h)
70;   Returns:
71;       BH:     Error code from requested drive (if available)
72;   Corrupts registers:
[27]73;       AX, DL, DI
[128]74;--------------------------------------------------------------------
[26]75ResetFloppyDrivesWithInt40h:
[271]76    call    GetDriveNumberForForeignHardDiskHandlerToDL
[27]77    and     dl, 7Fh                     ; Clear hard disk bit
[26]78    xor     ah, ah                      ; Disk Controller Reset
[148]79    int     BIOS_DISKETTE_INTERRUPT_40h
[26]80    jmp     SHORT BackupErrorCodeFromTheRequestedDriveToBH
[23]81
82
83;--------------------------------------------------------------------
[26]84; ResetForeignHardDisks
[23]85;   Parameters:
86;       BL:     Requested drive (DL when entering AH=00h)
[3]87;       DS:     RAMVARS segment
88;   Returns:
[23]89;       BH:     Error code from requested drive (if available)
[3]90;   Corrupts registers:
[27]91;       AX, DL, DI
[128]92;--------------------------------------------------------------------
[26]93ResetForeignHardDisks:
[271]94    call    GetDriveNumberForForeignHardDiskHandlerToDL
[27]95    xor     ah, ah                      ; Disk Controller Reset
[32]96    call    Int13h_CallPreviousInt13hHandler
[258]97;;; fall-through to BackupErrorCodeFromTheRequestedDriveToBH
[23]98
[26]99
[3]100;--------------------------------------------------------------------
[258]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
[271]116
[258]117;--------------------------------------------------------------------
[271]118; GetDriveNumberForForeignHardDiskHandlerToDL
[27]119;   Parameters:
120;       BL:     Requested drive (DL when entering AH=00h)
121;       DS:     RAMVARS segment
122;   Returns:
[275]123;       DS:DI:  Ptr to DPT if our drive (or Null if foreign drive)
[27]124;       DL:     BL if foreign drive
125;               80h if our drive
[128]126;--------------------------------------------------------------------
[271]127GetDriveNumberForForeignHardDiskHandlerToDL:
[27]128    mov     dl, bl
[275]129    test    di, di
130    jz      SHORT .Return
[271]131    mov     dl, 80h             ; First possible Hard Disk should be safe value
[275]132.Return:
[27]133    ret
134
[275]135AH0h_ResetAllOurHardDisksAtTheEndOfDriveInitialization equ ResetHardDisksHandledByOurBIOS.ErrorCodeNotUsed
[27]136
137;--------------------------------------------------------------------
[271]138; ResetHardDisksHandledByOurBIOS
139;   Parameters:
140;       DS:DI:  Ptr to DPT for requested drive
[282]141;               If DPT pointer is not available, or error result in BH won't be used anyway, 
142;               enter through .ErrorCodeNotUsed.
[271]143;       SS:BP:  Ptr to IDEPACK
144;   Returns:
[23]145;       BH:     Error code from requested drive (if available)
146;   Corrupts registers:
[275]147;       AX, BX, CX, DX, SI, DI
[23]148;--------------------------------------------------------------------
[271]149ResetHardDisksHandledByOurBIOS:
[282]150    mov     bl, 0                                       ; Assume Null IdevarsOffset for now, assuming foreign drive
151    test    di, di
152    jz      .ErrorCodeNotUsed
[264]153    mov     bl, [di+DPT.bIdevarsOffset]                 ; replace drive number with Idevars pointer for cmp with dl
[282]154       
155.ErrorCodeNotUsed:                                      ; BH will be garbage on exit if thie entry point is used, 
[275]156                                                        ; but reset of all drives will still happen
157
[264]158    mov     dl, ROMVARS.ideVars0                        ; starting Idevars offset
159
[271]160    call    RamVars_GetIdeControllerCountToCX           ; get count of ide controllers
[264]161    jcxz    .done                                       ; just in case bIdeCnt is zero (shouldn't be)
[262]162.loop:
[271]163    call    FindDPT_ForIdevarsOffsetInDL                ; look for the first drive on this controller, if any
[262]164    jc      .notFound
[264]165
[262]166    call    AHDh_ResetDrive                             ; reset master and slave on that controller
[264]167    call    BackupErrorCodeFromTheRequestedDriveToBH    ; save error code if same controller as drive from entry
168
[262]169.notFound:
[264]170    add     dl, IDEVARS_size                            ; move Idevars pointer forward
171    loop    .loop
172
173.done:
[259]174    ret
Note: See TracBrowser for help on using the repository browser.