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

Last change on this file since 23 was 23, checked in by aitotat, 14 years ago

Booting is now possible from hard disks if floppy controller reset fails.
AH=00h, Disk Controller Reset now returns error code for the requested drive only.

File size: 5.9 KB
RevLine 
[3]1; File name     :   AH0h_HReset.asm
2; Project name  :   IDE BIOS
3; Created date  :   27.9.2007
[23]4; Last update   :   1.7.2010
[3]5; Author        :   Tomi Tilli
6; Description   :   Int 13h function AH=0h, Disk Controller Reset.
7
8RETRIES_IF_RESET_FAILS      EQU     3
9TIMEOUT_BEFORE_RESET_RETRY  EQU     5       ; System timer ticks
10
11; Section containing code
12SECTION .text
13
14;--------------------------------------------------------------------
15; Int 13h function AH=0h, Disk Controller Reset.
16;
17; AH0h_HandlerForDiskControllerReset
18;   Parameters:
19;       AH:     Bios function 0h
20;       DL:     Drive number (ignored so all drives are reset)
21;               If bit 7 is set all hard disks and floppy disks reset.
22;   Parameters loaded by Int13h_Jump:
23;       DS:     RAMVARS segment
24;   Returns:
[23]25;       AH:     Int 13h return status (from drive requested in DL)
[3]26;       CF:     0 if succesfull, 1 if error
27;       IF:     1
28;   Corrupts registers:
29;       Flags
30;--------------------------------------------------------------------
31ALIGN JUMP_ALIGN
32AH0h_HandlerForDiskControllerReset:
33    push    dx
34    push    cx
35    push    bx
36    push    ax
37
[23]38    eMOVZX  bx, dl                      ; Copy requested drive to BL, zero BH to assume no errors
39    call    AH0h_ResetFloppyDrivesWithInt40h
40    test    bl, 80h                     ; Reset hard disks too?
41    jz      SHORT .Return
42    call    AH0h_ResetForeignHardDisks
43    call    AH0h_ResetAllOurControllers
44ALIGN JUMP_ALIGN
45.Return:
46    mov     ah, bh                      ; Copy error code to AH
47    xor     al, al                      ; Zero AL...
48    sub     al, ah                      ; ...and set CF if error
49    jmp     Int13h_PopXRegsAndReturn
[3]50
51
52;--------------------------------------------------------------------
[23]53; AH0h_ResetFloppyDrivesWithInt40h
[3]54;   Parameters:
[23]55;       BL:     Requested drive (DL when entering AH=00h)
56;       DL:     Drive number
57;   Returns:
58;       BH:     Error code from requested drive (if available)
59;   Corrupts registers:
60;       AX, DL
61;--------------------------------------------------------------------   
62ALIGN JUMP_ALIGN
63AH0h_ResetFloppyDrivesWithInt40h:
64    xor     ax, ax                      ; Disk Controller Reset
65    and     dl, 7Fh                     ; Clear bit 7
66    int     INTV_FLOPPY_FUNC
67    jmp     SHORT AH0h_BackupErrorCodeFromTheRequestedDriveToBH
68
69
70;--------------------------------------------------------------------
71; AH0h_ResetForeignHardDisks
72;   Parameters:
73;       BL:     Requested drive (DL when entering AH=00h)
[3]74;       DS:     RAMVARS segment
75;   Returns:
[23]76;       BH:     Error code from requested drive (if available)
[3]77;   Corrupts registers:
[23]78;       AX, DL
79;--------------------------------------------------------------------   
80ALIGN JUMP_ALIGN
81AH0h_ResetForeignHardDisks:
82    mov     cl, [RAMVARS.bFirstDrv]     ; Load number of first our drive
83    and     cx, BYTE 7Fh                ; CX = number of drives to reset
84    jz      SHORT .Return
85    mov     dl, 80h                     ; Start resetting from drive 80h
86ALIGN JUMP_ALIGN
87.DriveResetLoop:
88    mov     ah, 0Dh                     ; Reset Hard Disk (Alternate reset)
89    pushf                               ; Push flags to simulate INT
90    cli                                 ; Disable interrupts since INT does that
91    call    FAR [RAMVARS.fpOldI13h]
92    sti                                 ; Make sure interrupts are enabled again (some BIOSes fails to enable it)
93    call    AH0h_BackupErrorCodeFromTheRequestedDriveToBH
94    inc     dx                          ; Next drive to reset
95    loop    .DriveResetLoop
96ALIGN JUMP_ALIGN
97.Return:
98    ret
99
100
[3]101;--------------------------------------------------------------------
[23]102; AH0h_ResetAllOurControllers
103;   Parameters:
104;       BL:     Requested drive (DL when entering AH=00h)
105;       DS:     RAMVARS segment
106;   Returns:
107;       BH:     Error code from requested drive (if available)
108;   Corrupts registers:
109;       AX, CX, DX, DI
110;--------------------------------------------------------------------
[3]111ALIGN JUMP_ALIGN
[23]112AH0h_ResetAllOurControllers:
113    push    si
114    mov     si, ROMVARS.ideVars0            ; Load offset to first IDEVARS
[3]115    call    Initialize_GetIdeControllerCountToCX
116ALIGN JUMP_ALIGN
117.ResetLoop:
[23]118    call    AH0h_ResetIdevarsControllerMasterAndSlaveDrives
119    add     si, BYTE IDEVARS_size
[3]120    loop    .ResetLoop
121.Return:
[23]122    pop     si
[3]123    ret
124
125
126;--------------------------------------------------------------------
[23]127; AH0h_ResetIdevarsControllerMasterAndSlaveDrives
[3]128;   Parameters:
[23]129;       BL:     Requested drive (DL when entering AH=00h)
130;       CS:SI:  Ptr to IDEVARS
[3]131;       DS:     RAMVARS segment
132;   Returns:
[23]133;       BH:     Error code from requested drive (if available)
[3]134;   Corrupts registers:
[23]135;       AX, DX, DI
[3]136;--------------------------------------------------------------------
137ALIGN JUMP_ALIGN
[23]138AH0h_ResetIdevarsControllerMasterAndSlaveDrives:
139    mov     dx, [cs:si+IDEVARS.wPort]
[3]140    call    FindDPT_ForIdeMasterAtPort      ; Find master drive to DL
141    jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
142    call    FindDPT_ForIdeSlaveAtPort       ; Find slave if master not present
143    jc      SHORT AH0h_ResetMasterAndSlaveDriveWithRetries
144    ret
145
146;--------------------------------------------------------------------
147; AH0h_ResetMasterAndSlaveDriveWithRetries
148;   Parameters:
[23]149;       BL:     Requested drive (DL when entering AH=00h)
[3]150;       DL:     Drive number for master or slave drive
[23]151;       DS:     RAMVARS segment
[3]152;   Returns:
[23]153;       BH:     Error code from requested drive (if available)
[3]154;   Corrupts registers:
[23]155;       AX, DI
[3]156;--------------------------------------------------------------------
157ALIGN JUMP_ALIGN
158AH0h_ResetMasterAndSlaveDriveWithRetries:
[23]159    push    dx
[3]160    push    cx
161    push    bx
[23]162    mov     di, RETRIES_IF_RESET_FAILS
[3]163ALIGN JUMP_ALIGN
164.RetryLoop:
165    call    AHDh_ResetDrive
[23]166    jnc     SHORT .Return               ; Jump if successful
[3]167    mov     cx, TIMEOUT_BEFORE_RESET_RETRY
168    call    SoftDelay_TimerTicks
[23]169    dec     di
170    jnz     SHORT .RetryLoop
[3]171ALIGN JUMP_ALIGN
172.Return:
173    pop     bx
174    pop     cx
[23]175    pop     dx
176    ; Fall to AH0h_BackupErrorCodeFromTheRequestedDriveToBH
[3]177
178;--------------------------------------------------------------------
[23]179; AH0h_BackupErrorCodeFromTheRequestedDriveToBH
[3]180;   Parameters:
[23]181;       AH:     Error code from the last resetted drive
182;       DL:     Drive last resetted
183;       BL:     Requested drive (DL when entering AH=00h)
[3]184;   Returns:
[23]185;       BH:     Backuped error code
[3]186;   Corrupts registers:
187;       Nothing
188;--------------------------------------------------------------------
189ALIGN JUMP_ALIGN
[23]190AH0h_BackupErrorCodeFromTheRequestedDriveToBH:
191    cmp     dl, bl                      ; Requested drive?
192    jne     SHORT .Return
193    mov     bh, ah
194ALIGN JUMP_ALIGN
195.Return:
[3]196    ret
Note: See TracBrowser for help on using the repository browser.