[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 2 | ; Description : Functions for finding Disk Parameter Table.
|
---|
| 3 |
|
---|
[376] | 4 | ;
|
---|
[526] | 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 7 | ;
|
---|
| 8 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 9 | ; it under the terms of the GNU General Public License as published by
|
---|
| 10 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 11 | ; (at your option) any later version.
|
---|
[526] | 12 | ;
|
---|
[376] | 13 | ; This program is distributed in the hope that it will be useful,
|
---|
| 14 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 15 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
[526] | 16 | ; GNU General Public License for more details.
|
---|
[376] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[526] | 18 | ;
|
---|
[376] | 19 |
|
---|
[3] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
| 23 | ;--------------------------------------------------------------------
|
---|
[262] | 24 | ; Checks if drive is handled by this BIOS, and return DPT pointer.
|
---|
[3] | 25 | ;
|
---|
[294] | 26 | ; FindDPT_ForDriveNumberInDL
|
---|
[3] | 27 | ; Parameters:
|
---|
[262] | 28 | ; DL: Drive number
|
---|
[3] | 29 | ; DS: RAMVARS segment
|
---|
| 30 | ; Returns:
|
---|
[262] | 31 | ; CF: Cleared if drive is handled by this BIOS
|
---|
| 32 | ; Set if drive belongs to some other BIOS
|
---|
| 33 | ; DI: DPT Pointer if drive is handled by this BIOS
|
---|
| 34 | ; Zero if drive belongs to some other BIOS
|
---|
[3] | 35 | ; Corrupts registers:
|
---|
[262] | 36 | ; Nothing
|
---|
[150] | 37 | ;--------------------------------------------------------------------
|
---|
| 38 | ALIGN JUMP_ALIGN
|
---|
[294] | 39 | FindDPT_ForDriveNumberInDL:
|
---|
[262] | 40 | xchg di, ax ; Save the contents of AX in DI
|
---|
| 41 |
|
---|
[294] | 42 | ;
|
---|
[262] | 43 | ; Check Our Hard Disks
|
---|
| 44 | ;
|
---|
[433] | 45 | mov ax, [RAMVARS.wFirstDrvAndCount] ; Drive count to AH, First number to AL
|
---|
[262] | 46 | add ah, al ; One past last drive to AH
|
---|
| 47 |
|
---|
[258] | 48 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
[262] | 49 | cmp dl, ah ; Above last supported?
|
---|
| 50 | jae SHORT .HardDiskNotHandledByThisBIOS
|
---|
[294] | 51 |
|
---|
[262] | 52 | cmp dl, al ; Below first supported?
|
---|
| 53 | jae SHORT .CalcDPTForDriveNumber
|
---|
| 54 |
|
---|
[294] | 55 | ALIGN JUMP_ALIGN
|
---|
| 56 | .HardDiskNotHandledByThisBIOS:
|
---|
[262] | 57 | ;
|
---|
| 58 | ; Check Our Floppy Disks
|
---|
[294] | 59 | ;
|
---|
[262] | 60 | call RamVars_UnpackFlopCntAndFirstToAL
|
---|
| 61 | js SHORT .DiskIsNotHandledByThisBIOS
|
---|
[294] | 62 |
|
---|
[277] | 63 | cbw ; Always 0h (no floppy drive covered above)
|
---|
| 64 | adc ah, al ; Add in first drive number and number of drives
|
---|
| 65 |
|
---|
[262] | 66 | cmp ah, dl ; Check second drive if two, first drive if only one
|
---|
| 67 | jz SHORT .CalcDPTForDriveNumber
|
---|
| 68 | cmp al, dl ; Check first drive in all cases, redundant but OK to repeat
|
---|
[294] | 69 | jnz SHORT .DiskIsNotHandledByThisBIOS
|
---|
[262] | 70 | %else
|
---|
[294] | 71 | cmp dl, ah ; Above last supported?
|
---|
[262] | 72 | jae SHORT .DiskIsNotHandledByThisBIOS
|
---|
[294] | 73 |
|
---|
[262] | 74 | cmp dl, al ; Below first supported?
|
---|
[294] | 75 | jb SHORT .DiskIsNotHandledByThisBIOS
|
---|
[258] | 76 | %endif
|
---|
[262] | 77 | ; fall-through to CalcDPTForDriveNumber
|
---|
[150] | 78 |
|
---|
| 79 | ;--------------------------------------------------------------------
|
---|
| 80 | ; Finds Disk Parameter Table for drive number.
|
---|
[294] | 81 | ; Not intended to be called except by FindDPT_ForDriveNumberInDL
|
---|
[150] | 82 | ;
|
---|
[262] | 83 | ; CalcDPTForDriveNumber
|
---|
[150] | 84 | ; Parameters:
|
---|
| 85 | ; DL: Drive number
|
---|
| 86 | ; DS: RAMVARS segment
|
---|
[294] | 87 | ; DI: Saved copy of AX from entry at FindDPT_ForDriveNumberInDL
|
---|
[150] | 88 | ; Returns:
|
---|
| 89 | ; DS:DI: Ptr to DPT
|
---|
[262] | 90 | ; CF: Clear
|
---|
[150] | 91 | ; Corrupts registers:
|
---|
[3] | 92 | ; Nothing
|
---|
| 93 | ;--------------------------------------------------------------------
|
---|
| 94 | ALIGN JUMP_ALIGN
|
---|
[262] | 95 | .CalcDPTForDriveNumber:
|
---|
[150] | 96 | push dx
|
---|
[3] | 97 |
|
---|
[258] | 98 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
[433] | 99 | mov ax, [RAMVARS.wFirstDrvAndCount]
|
---|
[294] | 100 |
|
---|
[258] | 101 | test dl, dl
|
---|
| 102 | js .harddisk
|
---|
| 103 |
|
---|
| 104 | call RamVars_UnpackFlopCntAndFirstToAL
|
---|
| 105 | add dl, ah ; add in end of hard disk DPT list, floppies start immediately after
|
---|
[294] | 106 |
|
---|
| 107 | ALIGN JUMP_ALIGN
|
---|
[258] | 108 | .harddisk:
|
---|
| 109 | sub dl, al ; subtract off beginning of either hard disk or floppy list (as appropriate)
|
---|
| 110 | %else
|
---|
| 111 | sub dl, [RAMVARS.bFirstDrv] ; subtract off beginning of hard disk list
|
---|
| 112 | %endif
|
---|
[262] | 113 |
|
---|
[294] | 114 | .CalcDPTForNewDrive:
|
---|
[150] | 115 | mov al, LARGEST_DPT_SIZE
|
---|
[294] | 116 |
|
---|
[150] | 117 | mul dl
|
---|
[522] | 118 | add ax, RAMVARS_size ; Clears CF (will not overflow)
|
---|
[3] | 119 |
|
---|
[150] | 120 | pop dx
|
---|
[262] | 121 |
|
---|
| 122 | xchg di, ax ; Restore AX from entry at FindDPT_ForDriveNumber, put DPT pointer in DI
|
---|
[150] | 123 | ret
|
---|
| 124 |
|
---|
[294] | 125 | ALIGN JUMP_ALIGN
|
---|
| 126 | .DiskIsNotHandledByThisBIOS:
|
---|
[259] | 127 | ;
|
---|
[262] | 128 | ; Drive not found...
|
---|
| 129 | ;
|
---|
| 130 | xor ax, ax ; Clear DPT pointer
|
---|
[294] | 131 | stc ; Is not supported by our BIOS
|
---|
| 132 |
|
---|
[262] | 133 | xchg di, ax ; Restore AX from save at top
|
---|
[259] | 134 | ret
|
---|
| 135 |
|
---|
[271] | 136 |
|
---|
[259] | 137 | ;--------------------------------------------------------------------
|
---|
[521] | 138 | ; FindDPT_MasterOrSingleForIdevarsOffsetInDL
|
---|
[271] | 139 | ; Parameters:
|
---|
| 140 | ; DL: Offset to IDEVARS to search for
|
---|
| 141 | ; DS: RAMVARS segment
|
---|
| 142 | ; Returns:
|
---|
| 143 | ; DS:DI: Ptr to first DPT with same IDEVARS as in DL
|
---|
| 144 | ; CF: Clear if wanted DPT found
|
---|
| 145 | ; Set if DPT not found, or no DPTs present
|
---|
| 146 | ; Corrupts registers:
|
---|
| 147 | ; SI
|
---|
| 148 | ;--------------------------------------------------------------------
|
---|
[521] | 149 | FindDPT_MasterOrSingleForIdevarsOffsetInDL:
|
---|
[271] | 150 | mov si, IterateFindFirstDPTforIdevars ; iteration routine (see below)
|
---|
| 151 | jmp SHORT FindDPT_IterateAllDPTs ; look for the first drive on this controller, if any
|
---|
| 152 |
|
---|
| 153 | ;--------------------------------------------------------------------
|
---|
[521] | 154 | ; FindDPT_SlaveForIdevarsOffsetInDL
|
---|
| 155 | ; Parameters:
|
---|
| 156 | ; DL: Offset to IDEVARS to search for
|
---|
| 157 | ; DS: RAMVARS segment
|
---|
| 158 | ; Returns:
|
---|
| 159 | ; DS:DI: Ptr to second DPT with same IDEVARS as in DL
|
---|
| 160 | ; CF: Clear if wanted DPT found
|
---|
| 161 | ; Set if DPT not found, or no DPTs present
|
---|
| 162 | ; Corrupts registers:
|
---|
| 163 | ; SI
|
---|
| 164 | ;--------------------------------------------------------------------
|
---|
| 165 | FindDPT_SlaveForIdevarsOffsetInDL:
|
---|
| 166 | mov si, IterateFindSecondDPTforIdevars ; iteration routine (see below)
|
---|
| 167 | jmp SHORT FindDPT_IterateAllDPTs ; look for the second drive on this controller, if any
|
---|
| 168 |
|
---|
| 169 | ;--------------------------------------------------------------------
|
---|
| 170 | ; Iteration routines for FindDPT_MasterOrSingleForIdevarsOffsetInDL and
|
---|
| 171 | ; FindDPT_SlaveForIdevarsOffsetInDL, for use with IterateAllDPTs
|
---|
[294] | 172 | ;
|
---|
[271] | 173 | ; Returns when DPT is found on the controller with Idevars offset in DL
|
---|
| 174 | ;
|
---|
[521] | 175 | ; IterateFindSecondDPTforIdevars
|
---|
[271] | 176 | ; IterateFindFirstDPTforIdevars
|
---|
| 177 | ; DL: Offset to IDEVARS to search from DPTs
|
---|
[524] | 178 | ; SI: Offset to this callback function
|
---|
[271] | 179 | ; DS:DI: Ptr to DPT to examine
|
---|
| 180 | ; Returns:
|
---|
| 181 | ; CF: Clear if wanted DPT found
|
---|
| 182 | ; Set if wrong DPT
|
---|
| 183 | ;--------------------------------------------------------------------
|
---|
[521] | 184 | IterateFindSecondDPTforIdevars:
|
---|
| 185 | call IterateFindFirstDPTforIdevars
|
---|
[524] | 186 | jc SHORT .WrongController
|
---|
| 187 | mov si, IterateFindFirstDPTforIdevars
|
---|
| 188 | .WrongController:
|
---|
| 189 | stc
|
---|
| 190 | ret
|
---|
[521] | 191 |
|
---|
[294] | 192 | IterateFindFirstDPTforIdevars:
|
---|
[271] | 193 | cmp dl, [di+DPT.bIdevarsOffset] ; Clears CF if matched
|
---|
| 194 | je .done
|
---|
| 195 | stc ; Set CF for not found
|
---|
[294] | 196 | .done:
|
---|
[271] | 197 | ret
|
---|
| 198 |
|
---|
| 199 |
|
---|
| 200 | ;--------------------------------------------------------------------
|
---|
[262] | 201 | ; Finds pointer to first unused Disk Parameter Table.
|
---|
| 202 | ; Should only be used before DetectDrives is complete (not valid after this time).
|
---|
[3] | 203 | ;
|
---|
[262] | 204 | ; FindDPT_ForNewDriveToDSDI
|
---|
[3] | 205 | ; Parameters:
|
---|
| 206 | ; DS: RAMVARS segment
|
---|
| 207 | ; Returns:
|
---|
[262] | 208 | ; DS:DI: Ptr to first unused DPT
|
---|
[3] | 209 | ; Corrupts registers:
|
---|
[262] | 210 | ; AX
|
---|
[3] | 211 | ;--------------------------------------------------------------------
|
---|
[262] | 212 | ALIGN JUMP_ALIGN
|
---|
| 213 | FindDPT_ForNewDriveToDSDI:
|
---|
| 214 | push dx
|
---|
[294] | 215 |
|
---|
[262] | 216 | %ifdef MODULE_SERIAL_FLOPPY
|
---|
| 217 | mov dx, [RAMVARS.wDrvCntAndFlopCnt]
|
---|
| 218 | add dl, dh
|
---|
| 219 | %else
|
---|
| 220 | mov dl, [RAMVARS.bDrvCnt]
|
---|
| 221 | %endif
|
---|
[294] | 222 |
|
---|
[262] | 223 | jmp short FindDPT_ForDriveNumberInDL.CalcDPTForNewDrive
|
---|
[3] | 224 |
|
---|
[152] | 225 | ;--------------------------------------------------------------------
|
---|
[233] | 226 | ; IterateToDptWithFlagsHighInBL
|
---|
[152] | 227 | ; Parameters:
|
---|
| 228 | ; DS:DI: Ptr to DPT to examine
|
---|
[294] | 229 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
[152] | 230 | ; Returns:
|
---|
[262] | 231 | ; CF: Clear if wanted DPT found
|
---|
| 232 | ; Set if wrong DPT
|
---|
[152] | 233 | ; Corrupts registers:
|
---|
| 234 | ; Nothing
|
---|
| 235 | ;--------------------------------------------------------------------
|
---|
| 236 | ALIGN JUMP_ALIGN
|
---|
[294] | 237 | IterateToDptWithFlagsHighInBL:
|
---|
| 238 | test [di+DPT.bFlagsHigh], bl ; Clears CF
|
---|
[262] | 239 | jnz SHORT .ReturnRightDPT
|
---|
| 240 | stc
|
---|
[294] | 241 | .ReturnRightDPT:
|
---|
[3] | 242 | ret
|
---|
| 243 |
|
---|
| 244 | ;--------------------------------------------------------------------
|
---|
[233] | 245 | ; FindDPT_ToDSDIforSerialDevice
|
---|
[161] | 246 | ; Parameters:
|
---|
| 247 | ; DS: RAMVARS segment
|
---|
| 248 | ; Returns:
|
---|
| 249 | ; DS:DI: Ptr to DPT
|
---|
| 250 | ; CF: Set if wanted DPT found
|
---|
| 251 | ; Cleared if DPT not found
|
---|
| 252 | ; Corrupts registers:
|
---|
[203] | 253 | ; SI
|
---|
[161] | 254 | ;--------------------------------------------------------------------
|
---|
[265] | 255 | %ifdef MODULE_SERIAL
|
---|
[294] | 256 | ALIGN JUMP_ALIGN
|
---|
| 257 | FindDPT_ToDSDIforSerialDevice:
|
---|
[233] | 258 | mov bl, FLGH_DPT_SERIAL_DEVICE
|
---|
| 259 | ; fall-through
|
---|
[265] | 260 | %endif
|
---|
[294] | 261 |
|
---|
[233] | 262 | ;--------------------------------------------------------------------
|
---|
| 263 | ; FindDPT_ToDSDIforFlagsHigh
|
---|
| 264 | ; Parameters:
|
---|
| 265 | ; DS: RAMVARS segment
|
---|
| 266 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
| 267 | ; Returns:
|
---|
| 268 | ; DS:DI: Ptr to DPT
|
---|
| 269 | ; CF: Set if wanted DPT found
|
---|
| 270 | ; Cleared if DPT not found
|
---|
| 271 | ; Corrupts registers:
|
---|
| 272 | ; SI
|
---|
| 273 | ;--------------------------------------------------------------------
|
---|
[526] | 274 | %ifdef MODULE_IRQ
|
---|
[161] | 275 | ALIGN JUMP_ALIGN
|
---|
[526] | 276 | FindDPT_ToDSDIforFlagsHighInBL:
|
---|
[489] | 277 | %endif
|
---|
[233] | 278 | mov si, IterateToDptWithFlagsHighInBL
|
---|
[161] | 279 | ; Fall to IterateAllDPTs
|
---|
| 280 |
|
---|
| 281 | ;--------------------------------------------------------------------
|
---|
[3] | 282 | ; Iterates all Disk Parameter Tables.
|
---|
| 283 | ;
|
---|
[271] | 284 | ; FindDPT_IterateAllDPTs
|
---|
[3] | 285 | ; Parameters:
|
---|
[152] | 286 | ; AX,BX,DX: Parameters to callback function
|
---|
| 287 | ; CS:SI: Ptr to callback function
|
---|
[262] | 288 | ; Callback routine should return CF=clear if found
|
---|
[152] | 289 | ; DS: RAMVARS segment
|
---|
[3] | 290 | ; Returns:
|
---|
[152] | 291 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
[258] | 292 | ; If not found, points to first empty DPT
|
---|
[262] | 293 | ; CF: Clear if wanted DPT found
|
---|
| 294 | ; Set if DPT not found, or no DPTs present
|
---|
[3] | 295 | ; Corrupts registers:
|
---|
[150] | 296 | ; Nothing unless corrupted by callback function
|
---|
[3] | 297 | ;--------------------------------------------------------------------
|
---|
| 298 | ALIGN JUMP_ALIGN
|
---|
[271] | 299 | FindDPT_IterateAllDPTs:
|
---|
[3] | 300 | push cx
|
---|
[258] | 301 |
|
---|
| 302 | mov di, RAMVARS_size ; Point DS:DI to first DPT
|
---|
[294] | 303 | eMOVZX cx, [RAMVARS.bDrvCnt]
|
---|
[262] | 304 | jcxz .NotFound ; Return if no drives
|
---|
[294] | 305 |
|
---|
[3] | 306 | ALIGN JUMP_ALIGN
|
---|
| 307 | .LoopWhileDPTsLeft:
|
---|
| 308 | call si ; Is wanted DPT?
|
---|
[262] | 309 | jnc SHORT .Found ; If so, return
|
---|
| 310 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
|
---|
[258] | 311 | loop .LoopWhileDPTsLeft
|
---|
[262] | 312 |
|
---|
[3] | 313 | ALIGN JUMP_ALIGN
|
---|
[262] | 314 | .NotFound:
|
---|
| 315 | stc
|
---|
| 316 |
|
---|
| 317 | ALIGN JUMP_ALIGN
|
---|
| 318 | .Found:
|
---|
[3] | 319 | pop cx
|
---|
| 320 | ret
|
---|