1 | ; Project name : XTIDE Universal BIOS
|
---|
2 | ; Description : Functions for finding Disk Parameter Table.
|
---|
3 |
|
---|
4 | ; Section containing code
|
---|
5 | SECTION .text
|
---|
6 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; Finds pointer to first unused Disk Parameter Table.
|
---|
9 | ;
|
---|
10 | ; FindDPT_ForNewDriveToDSDI
|
---|
11 | ; Parameters:
|
---|
12 | ; DS: RAMVARS segment
|
---|
13 | ; Returns:
|
---|
14 | ; DS:DI: Ptr to first unused DPT
|
---|
15 | ; Corrupts registers:
|
---|
16 | ; DL
|
---|
17 | ;--------------------------------------------------------------------
|
---|
18 | ALIGN JUMP_ALIGN
|
---|
19 | FindDPT_ForNewDriveToDSDI:
|
---|
20 | mov dl, [RAMVARS.bFirstDrv]
|
---|
21 | add dl, [RAMVARS.bDrvCnt]
|
---|
22 | ; Fall to FindDPT_ForDriveNumber
|
---|
23 |
|
---|
24 |
|
---|
25 | ;--------------------------------------------------------------------
|
---|
26 | ; Finds Disk Parameter Table for drive number.
|
---|
27 | ; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
|
---|
28 | ;
|
---|
29 | ; FindDPT_ForDriveNumber
|
---|
30 | ; Parameters:
|
---|
31 | ; DL: Drive number
|
---|
32 | ; DS: RAMVARS segment
|
---|
33 | ; Returns:
|
---|
34 | ; DS:DI: Ptr to DPT
|
---|
35 | ; Corrupts registers:
|
---|
36 | ; Nothing
|
---|
37 | ;--------------------------------------------------------------------
|
---|
38 | ALIGN JUMP_ALIGN
|
---|
39 | FindDPT_ForDriveNumber:
|
---|
40 | push dx
|
---|
41 | push ax
|
---|
42 |
|
---|
43 | mov al, LARGEST_DPT_SIZE
|
---|
44 | sub dl, [RAMVARS.bFirstDrv]
|
---|
45 | mul dl
|
---|
46 | add ax, BYTE RAMVARS_size
|
---|
47 | xchg di, ax
|
---|
48 |
|
---|
49 | pop ax
|
---|
50 | pop dx
|
---|
51 | ret
|
---|
52 |
|
---|
53 |
|
---|
54 | ;--------------------------------------------------------------------
|
---|
55 | ; Finds Disk Parameter Table for
|
---|
56 | ; Master or Slave drive at wanted port.
|
---|
57 | ;
|
---|
58 | ; FindDPT_ToDSDIForIdeMasterAtPortDX
|
---|
59 | ; FindDPT_ToDSDIForIdeSlaveAtPortDX
|
---|
60 | ; Parameters:
|
---|
61 | ; DX: IDE Base Port address
|
---|
62 | ; DS: RAMVARS segment
|
---|
63 | ; Returns:
|
---|
64 | ; DL: Drive number (if DPT found)
|
---|
65 | ; DS:DI: Ptr to DPT
|
---|
66 | ; CF: Set if wanted DPT found
|
---|
67 | ; Cleared if DPT not found
|
---|
68 | ; Corrupts registers:
|
---|
69 | ; SI
|
---|
70 | ;--------------------------------------------------------------------
|
---|
71 | ALIGN JUMP_ALIGN
|
---|
72 | FindDPT_ToDSDIForIdeMasterAtPortDX:
|
---|
73 | mov si, IterateToMasterAtPortCallback
|
---|
74 | jmp SHORT IterateAllDPTs
|
---|
75 |
|
---|
76 | ALIGN JUMP_ALIGN
|
---|
77 | FindDPT_ToDSDIForIdeSlaveAtPortDX:
|
---|
78 | mov si, IterateToSlaveAtPortCallback
|
---|
79 | jmp SHORT IterateAllDPTs
|
---|
80 |
|
---|
81 | ;--------------------------------------------------------------------
|
---|
82 | ; Iteration callback for finding DPT using
|
---|
83 | ; IDE base port for Master or Slave drive.
|
---|
84 | ;
|
---|
85 | ; IterateToSlaveAtPortCallback
|
---|
86 | ; IterateToMasterAtPortCallback
|
---|
87 | ; Parameters:
|
---|
88 | ; CH: Drive number
|
---|
89 | ; DX: IDE Base Port address
|
---|
90 | ; DS:DI: Ptr to DPT to examine
|
---|
91 | ; Returns:
|
---|
92 | ; DL: Drive number if correct DPT
|
---|
93 | ; CF: Set if wanted DPT found
|
---|
94 | ; Cleared if wrong DPT
|
---|
95 | ; Corrupts registers:
|
---|
96 | ; Nothing
|
---|
97 | ;--------------------------------------------------------------------
|
---|
98 | ALIGN JUMP_ALIGN
|
---|
99 | IterateToSlaveAtPortCallback:
|
---|
100 | test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE ; Clears CF
|
---|
101 | jnz SHORT CompareBasePortAddress
|
---|
102 | ret ; Wrong DPT
|
---|
103 |
|
---|
104 | ALIGN JUMP_ALIGN
|
---|
105 | IterateToMasterAtPortCallback:
|
---|
106 | test BYTE [di+DPT.wFlags], FLG_DPT_SLAVE
|
---|
107 | jnz SHORT ReturnWrongDPT ; Return if slave drive
|
---|
108 |
|
---|
109 | CompareBasePortAddress:
|
---|
110 | push bx
|
---|
111 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
|
---|
112 | cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
|
---|
113 | pop bx
|
---|
114 | jne SHORT ReturnWrongDPT
|
---|
115 | mov dl, ch ; Return drive number in DL
|
---|
116 | stc ; Set CF since wanted DPT
|
---|
117 | ret
|
---|
118 |
|
---|
119 |
|
---|
120 | ;--------------------------------------------------------------------
|
---|
121 | ; FindDPT_ToDSDIforInterruptInService
|
---|
122 | ; Parameters:
|
---|
123 | ; DS: RAMVARS segment
|
---|
124 | ; Returns:
|
---|
125 | ; DS:DI: Ptr to DPT
|
---|
126 | ; CF: Set if wanted DPT found
|
---|
127 | ; Cleared if DPT not found
|
---|
128 | ; Corrupts registers:
|
---|
129 | ; SI
|
---|
130 | ;--------------------------------------------------------------------
|
---|
131 | ALIGN JUMP_ALIGN
|
---|
132 | FindDPT_ToDSDIforInterruptInService:
|
---|
133 | mov si, IterateToDptWithInterruptInServiceFlagSet
|
---|
134 | jmp SHORT IterateAllDPTs
|
---|
135 |
|
---|
136 | ;--------------------------------------------------------------------
|
---|
137 | ; IterateToDptWithInterruptInServiceFlagSet
|
---|
138 | ; Parameters:
|
---|
139 | ; DS:DI: Ptr to DPT to examine
|
---|
140 | ; Returns:
|
---|
141 | ; CF: Set if wanted DPT found
|
---|
142 | ; Cleared if wrong DPT
|
---|
143 | ; Corrupts registers:
|
---|
144 | ; Nothing
|
---|
145 | ;--------------------------------------------------------------------
|
---|
146 | ALIGN JUMP_ALIGN
|
---|
147 | IterateToDptWithInterruptInServiceFlagSet:
|
---|
148 | test WORD [di+DPT.wFlags], FLG_DPT_INTERRUPT_IN_SERVICE
|
---|
149 | jz SHORT ReturnWrongDPT
|
---|
150 | stc ; Set CF since wanted DPT
|
---|
151 | ret
|
---|
152 | ReturnWrongDPT:
|
---|
153 | clc ; Clear CF since wrong DPT
|
---|
154 | ret
|
---|
155 |
|
---|
156 |
|
---|
157 | ;--------------------------------------------------------------------
|
---|
158 | ; Iterates all Disk Parameter Tables.
|
---|
159 | ;
|
---|
160 | ; IterateAllDPTs
|
---|
161 | ; Parameters:
|
---|
162 | ; AX,BX,DX: Parameters to callback function
|
---|
163 | ; CS:SI: Ptr to callback function
|
---|
164 | ; DS: RAMVARS segment
|
---|
165 | ; Returns:
|
---|
166 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
167 | ; CF: Set if wanted DPT found
|
---|
168 | ; Cleared if DPT not found
|
---|
169 | ; Corrupts registers:
|
---|
170 | ; Nothing unless corrupted by callback function
|
---|
171 | ;--------------------------------------------------------------------
|
---|
172 | ALIGN JUMP_ALIGN
|
---|
173 | IterateAllDPTs:
|
---|
174 | push cx
|
---|
175 | mov cx, [RAMVARS.wDrvCntAndFirst]
|
---|
176 | jcxz .AllDptsIterated ; Return if no drives
|
---|
177 | mov di, RAMVARS_size ; Point DS:DI to first DPT
|
---|
178 | ALIGN JUMP_ALIGN
|
---|
179 | .LoopWhileDPTsLeft:
|
---|
180 | call si ; Is wanted DPT?
|
---|
181 | jc SHORT .AllDptsIterated ; If so, return
|
---|
182 | inc ch ; Increment drive number
|
---|
183 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
|
---|
184 | dec cl ; Decrement drives left
|
---|
185 | jnz SHORT .LoopWhileDPTsLeft
|
---|
186 | clc ; Clear CF since DPT not found
|
---|
187 | ALIGN JUMP_ALIGN
|
---|
188 | .AllDptsIterated:
|
---|
189 | pop cx
|
---|
190 | ret
|
---|