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

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

Corrected a bug where the initial pointer to idevars0 was not properly set.

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