1 | ; Project name : XTIDE Universal BIOS |
---|
2 | ; Description : Int 13h function AH=25h, Get Drive Information. |
---|
3 | |
---|
4 | ; Section containing code |
---|
5 | SECTION .text |
---|
6 | |
---|
7 | ;-------------------------------------------------------------------- |
---|
8 | ; Int 13h function AH=25h, Get Drive Information. |
---|
9 | ; |
---|
10 | ; AH25h_HandlerForGetDriveInformation |
---|
11 | ; Parameters: |
---|
12 | ; AH: Bios function 25h |
---|
13 | ; DL: Drive number |
---|
14 | ; ES:BX: Ptr to buffer to receive 512-byte drive information |
---|
15 | ; Parameters loaded by Int13h_Jump: |
---|
16 | ; DS: RAMVARS segment |
---|
17 | ; Returns: |
---|
18 | ; ES:BX: Ptr to 512-byte buffer to receive drive Information |
---|
19 | ; AH: Int 13h return status |
---|
20 | ; CF: 0 if succesfull, 1 if error |
---|
21 | ; IF: 1 |
---|
22 | ; Corrupts registers: |
---|
23 | ; Flags |
---|
24 | ;-------------------------------------------------------------------- |
---|
25 | ALIGN JUMP_ALIGN |
---|
26 | AH25h_HandlerForGetDriveInformation: |
---|
27 | push dx |
---|
28 | push cx |
---|
29 | push bx |
---|
30 | push ax |
---|
31 | push es |
---|
32 | |
---|
33 | ; Wait until previously selected drive is ready |
---|
34 | call FindDPT_ForDriveNumber ; DS:DI now points to DPT |
---|
35 | call HDrvSel_SelectDriveAndDisableIRQ |
---|
36 | jc SHORT .Return ; Return if error |
---|
37 | |
---|
38 | ; Get drive information |
---|
39 | call HPIO_NormalizeDataPointer |
---|
40 | push bx |
---|
41 | mov dx, [RAMVARS.wIdeBase] ; Load base port address |
---|
42 | eMOVZX bx, BYTE [di+DPT.bIdeOff] ; Load offset to IDEVARS |
---|
43 | mov bl, [cs:bx+IDEVARS.bBusType]; Load bus type to BL |
---|
44 | mov bh, [di+DPT.bDrvSel] ; Load drive sel byte to BH |
---|
45 | pop di ; Pop buffer offset to DI |
---|
46 | call AH25h_GetDriveInfo ; Get drive information |
---|
47 | .Return: |
---|
48 | pop es |
---|
49 | jmp Int13h_PopXRegsAndReturn |
---|
50 | |
---|
51 | |
---|
52 | ;-------------------------------------------------------------------- |
---|
53 | ; Gets drive information using Identify Device command. |
---|
54 | ; |
---|
55 | ; AH25h_GetDriveInfo |
---|
56 | ; Parameters: |
---|
57 | ; BH: Drive Select byte for Drive and Head Select Register |
---|
58 | ; BL: Bus type |
---|
59 | ; DX: IDE Controller base port address |
---|
60 | ; DS: Segment to RAMVARS |
---|
61 | ; ES:DI: Ptr to buffer to receive 512 byte drive information |
---|
62 | ; Returns: |
---|
63 | ; AH: Int 13h return status (will be stored to BDA) |
---|
64 | ; CF: 0 if succesfull, 1 if error |
---|
65 | ; Corrupts registers: |
---|
66 | ; AL, CX |
---|
67 | ;-------------------------------------------------------------------- |
---|
68 | ALIGN JUMP_ALIGN |
---|
69 | AH25h_GetDriveInfo: |
---|
70 | push di |
---|
71 | push dx |
---|
72 | push bx |
---|
73 | |
---|
74 | ; Select Master or Slave drive. |
---|
75 | ; DO NOT WAIT UNTIL CURRENTLY SELECTED IS READY! |
---|
76 | ; It makes slave drive detection impossible if master is not present. |
---|
77 | mov [RAMVARS.wIdeBase], dx ; Store IDE Base port to RAMVARS |
---|
78 | add dx, BYTE REG_IDE_DRVHD ; DX to Drive and Head Sel Register |
---|
79 | mov al, bh ; Drive Select byte to AL |
---|
80 | out dx, al ; Select Master or Slave drive |
---|
81 | sub dx, BYTE REG_IDE_DRVHD ; Back to IDE Base port |
---|
82 | call AH25h_GetDriveDetectionTimeoutValue |
---|
83 | call HStatus_WaitRdy ; Wait until ready to accept commands |
---|
84 | jc SHORT .Return ; Return if error |
---|
85 | |
---|
86 | ; Output command |
---|
87 | mov al, HCMD_ID_DEV ; Load Identify Device command to AL |
---|
88 | out dx, al ; Output command |
---|
89 | call HStatus_WaitDrqDefTime ; Wait until ready to transfer (no IRQ!) |
---|
90 | jc SHORT .Return ; Return if error |
---|
91 | |
---|
92 | ; Transfer data |
---|
93 | sub dx, BYTE REGR_IDE_ST ; DX to IDE Data Reg |
---|
94 | xor bh, bh ; BX now contains bus type |
---|
95 | mov cx, 256 ; Transfer 256 words (single sector) |
---|
96 | cld ; INSW to increment DI |
---|
97 | call [cs:bx+g_rgfnPioRead] ; Read ID sector |
---|
98 | call HStatus_WaitRdyDefTime ; Wait until drive ready |
---|
99 | |
---|
100 | ; Return |
---|
101 | .Return: |
---|
102 | pop bx |
---|
103 | pop dx |
---|
104 | pop di |
---|
105 | ret |
---|
106 | |
---|
107 | |
---|
108 | ;-------------------------------------------------------------------- |
---|
109 | ; Returns timeout value for drive detection. |
---|
110 | ; Long timeout is required for detecing first drive to make sure it is |
---|
111 | ; ready after power-on (ATA specification says up to 31 seconds). |
---|
112 | ; Short timeout is used for additional drives to prevent long boot time |
---|
113 | ; when drive has failed or it is not present. |
---|
114 | ; |
---|
115 | ; AH25h_GetDriveDetectionTimeoutValue |
---|
116 | ; Parameters: |
---|
117 | ; DS: Segment to RAMVARS |
---|
118 | ; Returns: |
---|
119 | ; CL: Timeout value |
---|
120 | ; Corrupts registers: |
---|
121 | ; Nothing |
---|
122 | ;-------------------------------------------------------------------- |
---|
123 | ALIGN JUMP_ALIGN |
---|
124 | AH25h_GetDriveDetectionTimeoutValue: |
---|
125 | cmp BYTE [RAMVARS.bDrvCnt], 0 ; Detecting first drive? |
---|
126 | je SHORT .GetLongDelayForInitialDetection |
---|
127 | mov cl, B_TIMEOUT_DRVINFO ; Load short timeout |
---|
128 | ret |
---|
129 | ALIGN JUMP_ALIGN |
---|
130 | .GetLongDelayForInitialDetection: |
---|
131 | mov cl, B_TIMEOUT_RESET ; Load long timeout |
---|
132 | ret |
---|