1 | ; File name : FindDPT.asm
|
---|
2 | ; Project name : IDE BIOS
|
---|
3 | ; Created date : 14.3.2010
|
---|
4 | ; Last update : 12.4.2010
|
---|
5 | ; Author : Tomi Tilli
|
---|
6 | ; Description : Functions for finding Disk Parameter Table.
|
---|
7 |
|
---|
8 | ; Section containing code
|
---|
9 | SECTION .text
|
---|
10 |
|
---|
11 | ;--------------------------------------------------------------------
|
---|
12 | ; Finds pointer to first unused Disk Parameter Table.
|
---|
13 | ;
|
---|
14 | ; FindDPT_ForNewDrive
|
---|
15 | ; Parameters:
|
---|
16 | ; DS: RAMVARS segment
|
---|
17 | ; Returns:
|
---|
18 | ; DS:DI: Ptr to first unused DPT
|
---|
19 | ; Corrupts registers:
|
---|
20 | ; Nothing
|
---|
21 | ;--------------------------------------------------------------------
|
---|
22 | ALIGN JUMP_ALIGN
|
---|
23 | FindDPT_ForNewDrive:
|
---|
24 | push si
|
---|
25 | mov si, FindDPT_ReturnWrongDPT
|
---|
26 | jmp SHORT FindDPT_StartIterationAndReturnAfterDone
|
---|
27 |
|
---|
28 |
|
---|
29 | ;--------------------------------------------------------------------
|
---|
30 | ; Finds Disk Parameter Table for
|
---|
31 | ; Master or Slave drive at wanted port.
|
---|
32 | ;
|
---|
33 | ; FindDPT_ForIdeSlaveAtPort
|
---|
34 | ; FindDPT_ForIdeMasterAtPort
|
---|
35 | ; Parameters:
|
---|
36 | ; DX: IDE Base Port address
|
---|
37 | ; DS: RAMVARS segment
|
---|
38 | ; Returns:
|
---|
39 | ; DL: Drive number (if DPT found)
|
---|
40 | ; DS:DI: Ptr to DPT
|
---|
41 | ; CF: Set if wanted DPT found
|
---|
42 | ; Cleared if DPT not found
|
---|
43 | ; Corrupts registers:
|
---|
44 | ; Nothing
|
---|
45 | ;--------------------------------------------------------------------
|
---|
46 | ALIGN JUMP_ALIGN
|
---|
47 | FindDPT_ForIdeSlaveAtPort:
|
---|
48 | push si
|
---|
49 | mov si, FindDPT_IterateToSlaveAtPortCallback
|
---|
50 | jmp SHORT FindDPT_StartIterationAndReturnAfterDone
|
---|
51 |
|
---|
52 | ALIGN JUMP_ALIGN
|
---|
53 | FindDPT_ForIdeMasterAtPort:
|
---|
54 | push si
|
---|
55 | mov si, FindDPT_IterateToMasterAtPortCallback
|
---|
56 | jmp SHORT FindDPT_StartIterationAndReturnAfterDone
|
---|
57 |
|
---|
58 | ;--------------------------------------------------------------------
|
---|
59 | ; Iteration callback for finding DPT using
|
---|
60 | ; IDE base port for Master or Slave drive.
|
---|
61 | ;
|
---|
62 | ; FindDPT_IterateToSlaveAtPortCallback
|
---|
63 | ; FindDPT_IterateToMasterAtPortCallback
|
---|
64 | ; Parameters:
|
---|
65 | ; DX: IDE Base Port address
|
---|
66 | ; DS:DI: Ptr to DPT to examine
|
---|
67 | ; Returns:
|
---|
68 | ; DL: Drive number if correct DPT
|
---|
69 | ; CF: Set if wanted DPT found
|
---|
70 | ; Cleared if wrong DPT
|
---|
71 | ; Corrupts registers:
|
---|
72 | ; Nothing
|
---|
73 | ;--------------------------------------------------------------------
|
---|
74 | ALIGN JUMP_ALIGN
|
---|
75 | FindDPT_IterateToSlaveAtPortCallback:
|
---|
76 | test BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_DRV
|
---|
77 | jnz SHORT FindDPT_IterateToMasterOrSlaveAtPortCallback
|
---|
78 | jmp SHORT FindDPT_ReturnWrongDPT ; Return if master drive
|
---|
79 |
|
---|
80 | ALIGN JUMP_ALIGN
|
---|
81 | FindDPT_IterateToMasterAtPortCallback:
|
---|
82 | test BYTE [di+DPT.bDrvSel], FLG_IDE_DRVHD_DRV
|
---|
83 | jnz SHORT FindDPT_ReturnWrongDPT ; Return if slave drive
|
---|
84 |
|
---|
85 | ; If BIOS partitioned, ignore all but first partition
|
---|
86 | ALIGN JUMP_ALIGN
|
---|
87 | FindDPT_IterateToMasterOrSlaveAtPortCallback:
|
---|
88 | test BYTE [di+DPT.bFlags], FLG_DPT_PARTITION
|
---|
89 | jz SHORT .CompareBasePortAddress
|
---|
90 | test BYTE [di+DPT.bFlags], FLG_DPT_FIRSTPART
|
---|
91 | jz SHORT FindDPT_ReturnWrongDPT
|
---|
92 | ALIGN JUMP_ALIGN
|
---|
93 | .CompareBasePortAddress:
|
---|
94 | push bx
|
---|
95 | eMOVZX bx, BYTE [di+DPT.bIdeOff] ; CS:BX now points to IDEVARS
|
---|
96 | cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
|
---|
97 | pop bx
|
---|
98 | jne SHORT FindDPT_ReturnWrongDPT
|
---|
99 | mov dl, [di+DPT.bDrvNum] ; Load drive number
|
---|
100 | stc ; Set CF since wanted DPT
|
---|
101 | ret
|
---|
102 |
|
---|
103 |
|
---|
104 | ;--------------------------------------------------------------------
|
---|
105 | ; Finds Disk Parameter Table for drive number.
|
---|
106 | ; IDE Base Port address will be stored to RAMVARS if correct DPT is found.
|
---|
107 | ;
|
---|
108 | ; FindDPT_ForDriveNumber
|
---|
109 | ; Parameters:
|
---|
110 | ; DL: Drive number
|
---|
111 | ; DS: RAMVARS segment
|
---|
112 | ; Returns:
|
---|
113 | ; DS:DI: Ptr to DPT
|
---|
114 | ; CF: Set if wanted DPT found
|
---|
115 | ; Cleared if DPT not found
|
---|
116 | ; Corrupts registers:
|
---|
117 | ; Nothing
|
---|
118 | ;--------------------------------------------------------------------
|
---|
119 | ALIGN JUMP_ALIGN
|
---|
120 | FindDPT_ForDriveNumber:
|
---|
121 | push si
|
---|
122 | mov si, FindDPT_IterateToDriveNumberCallback
|
---|
123 | FindDPT_StartIterationAndReturnAfterDone:
|
---|
124 | call FindDPT_IterateAllDPTs
|
---|
125 | pop si
|
---|
126 | ret
|
---|
127 |
|
---|
128 | ;--------------------------------------------------------------------
|
---|
129 | ; Iteration callback for finding DPT for drive number.
|
---|
130 | ;
|
---|
131 | ; FindDPT_IterateToDriveNumberCallback
|
---|
132 | ; Parameters:
|
---|
133 | ; DL: Drive number to search for
|
---|
134 | ; DS:DI: Ptr to DPT to examine
|
---|
135 | ; Returns:
|
---|
136 | ; CF: Set if wanted DPT found
|
---|
137 | ; Cleared if wrong DPT
|
---|
138 | ; Corrupts registers:
|
---|
139 | ; Nothing
|
---|
140 | ;--------------------------------------------------------------------
|
---|
141 | ALIGN JUMP_ALIGN
|
---|
142 | FindDPT_IterateToDriveNumberCallback:
|
---|
143 | cmp dl, [di+DPT.bDrvNum] ; Wanted DPT found?
|
---|
144 | je SHORT FindDPT_RightDriveNumber ; If so, return
|
---|
145 | FindDPT_ReturnWrongDPT:
|
---|
146 | clc ; Clear CF since wrong DPT
|
---|
147 | ret
|
---|
148 | ALIGN JUMP_ALIGN
|
---|
149 | FindDPT_RightDriveNumber:
|
---|
150 | push bx
|
---|
151 | eMOVZX bx, BYTE [di+DPT.bIdeOff] ; CS:BX now points to IDEVARS
|
---|
152 | mov bx, [cs:bx+IDEVARS.wPort] ; Load IDE Base Port address...
|
---|
153 | mov [RAMVARS.wIdeBase], bx ; ...and store it to RAMVARS
|
---|
154 | pop bx
|
---|
155 | stc
|
---|
156 | ret
|
---|
157 |
|
---|
158 |
|
---|
159 | ;--------------------------------------------------------------------
|
---|
160 | ; Iterates all Disk Parameter Tables.
|
---|
161 | ;
|
---|
162 | ; FindDPT_IterateAllDPTs
|
---|
163 | ; Parameters:
|
---|
164 | ; BX,DX: Parameters to callback function
|
---|
165 | ; CS:SI: Ptr to callback function
|
---|
166 | ; DS: RAMVARS segment
|
---|
167 | ; Returns:
|
---|
168 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
169 | ; CF: Set if wanted DPT found
|
---|
170 | ; Cleared if DPT not found
|
---|
171 | ; Corrupts registers:
|
---|
172 | ; Nothing, unless corrupted by callback function
|
---|
173 | ;--------------------------------------------------------------------
|
---|
174 | ALIGN JUMP_ALIGN
|
---|
175 | FindDPT_IterateAllDPTs:
|
---|
176 | push ax
|
---|
177 | push cx
|
---|
178 | call FindDPT_PointToFirstDPT ; Point DS:DI to first DPT
|
---|
179 | eMOVZX cx, BYTE [RAMVARS.bDrvCnt] ; Load number of drives
|
---|
180 | xor ax, ax ; Zero AX for DPT size and clear CF
|
---|
181 | jcxz .Return ; Return if no drives
|
---|
182 | ALIGN JUMP_ALIGN
|
---|
183 | .LoopWhileDPTsLeft:
|
---|
184 | call si ; Is wanted DPT?
|
---|
185 | jc SHORT .Return ; If so, return
|
---|
186 | mov al, [di+DPT.bSize] ; Load DPT size to AX
|
---|
187 | add di, ax ; Point to next DPT
|
---|
188 | loop .LoopWhileDPTsLeft ; Check next DPT
|
---|
189 | clc ; Clear CF since DPT not found
|
---|
190 | ALIGN JUMP_ALIGN
|
---|
191 | .Return:
|
---|
192 | pop cx
|
---|
193 | pop ax
|
---|
194 | ret
|
---|
195 |
|
---|
196 |
|
---|
197 | ;--------------------------------------------------------------------
|
---|
198 | ; Sets DI to point to first Disk Parameter Table.
|
---|
199 | ;
|
---|
200 | ; FindDPT_PointToFirstDPT
|
---|
201 | ; Parameters:
|
---|
202 | ; Nothing
|
---|
203 | ; Returns:
|
---|
204 | ; DI: Offset to first DPT (even if unused)
|
---|
205 | ; Corrupts registers:
|
---|
206 | ; Nothing
|
---|
207 | ;--------------------------------------------------------------------
|
---|
208 | ALIGN JUMP_ALIGN
|
---|
209 | FindDPT_PointToFirstDPT:
|
---|
210 | mov di, RAMVARS_size
|
---|
211 | test BYTE [cs:ROMVARS.wFlags], FLG_ROMVARS_FULLMODE
|
---|
212 | jz SHORT .Return ; RAMVARS used (top of interrupt vectors)
|
---|
213 | add di, BYTE FULLRAMVARS_size-RAMVARS_size ; FULLRAMVARS used (top of base memory)
|
---|
214 | ALIGN JUMP_ALIGN
|
---|
215 | .Return:
|
---|
216 | ret
|
---|