[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[3] | 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 | ;
|
---|
[150] | 10 | ; FindDPT_ForNewDriveToDSDI
|
---|
[3] | 11 | ; Parameters:
|
---|
| 12 | ; DS: RAMVARS segment
|
---|
| 13 | ; Returns:
|
---|
| 14 | ; DS:DI: Ptr to first unused DPT
|
---|
| 15 | ; Corrupts registers:
|
---|
[150] | 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:
|
---|
[3] | 36 | ; Nothing
|
---|
| 37 | ;--------------------------------------------------------------------
|
---|
| 38 | ALIGN JUMP_ALIGN
|
---|
[150] | 39 | FindDPT_ForDriveNumber:
|
---|
| 40 | push dx
|
---|
[161] | 41 | xchg di, ax ; Save the contents of AX in DI
|
---|
[3] | 42 |
|
---|
[150] | 43 | mov al, LARGEST_DPT_SIZE
|
---|
| 44 | sub dl, [RAMVARS.bFirstDrv]
|
---|
| 45 | mul dl
|
---|
| 46 | add ax, BYTE RAMVARS_size
|
---|
[3] | 47 |
|
---|
[161] | 48 | xchg di, ax ; Restore AX and put result in DI
|
---|
[150] | 49 | pop dx
|
---|
| 50 | ret
|
---|
| 51 |
|
---|
[3] | 52 | ;--------------------------------------------------------------------
|
---|
| 53 | ; Finds Disk Parameter Table for
|
---|
| 54 | ; Master or Slave drive at wanted port.
|
---|
| 55 | ;
|
---|
[150] | 56 | ; FindDPT_ToDSDIForIdeMasterAtPortDX
|
---|
| 57 | ; FindDPT_ToDSDIForIdeSlaveAtPortDX
|
---|
[3] | 58 | ; Parameters:
|
---|
| 59 | ; DX: IDE Base Port address
|
---|
| 60 | ; DS: RAMVARS segment
|
---|
| 61 | ; Returns:
|
---|
| 62 | ; DL: Drive number (if DPT found)
|
---|
| 63 | ; DS:DI: Ptr to DPT
|
---|
| 64 | ; CF: Set if wanted DPT found
|
---|
| 65 | ; Cleared if DPT not found
|
---|
| 66 | ; Corrupts registers:
|
---|
[150] | 67 | ; SI
|
---|
[200] | 68 | ;
|
---|
| 69 | ; Converted to macros since there is only once call site for each of these
|
---|
| 70 | ;
|
---|
[3] | 71 | ;--------------------------------------------------------------------
|
---|
[200] | 72 |
|
---|
| 73 | %macro FindDPT_ToDSDIForIdeMasterAtPortDX 0
|
---|
[152] | 74 | mov si, IterateToMasterAtPortCallback
|
---|
[200] | 75 | call IterateAllDPTs
|
---|
| 76 | %endmacro
|
---|
[3] | 77 |
|
---|
[200] | 78 | %macro FindDPT_ToDSDIForIdeSlaveAtPortDX 0
|
---|
[152] | 79 | mov si, IterateToSlaveAtPortCallback
|
---|
[200] | 80 | call IterateAllDPTs
|
---|
| 81 | %endmacro
|
---|
[3] | 82 |
|
---|
[200] | 83 |
|
---|
[3] | 84 | ;--------------------------------------------------------------------
|
---|
| 85 | ; Iteration callback for finding DPT using
|
---|
| 86 | ; IDE base port for Master or Slave drive.
|
---|
| 87 | ;
|
---|
[152] | 88 | ; IterateToSlaveAtPortCallback
|
---|
| 89 | ; IterateToMasterAtPortCallback
|
---|
[3] | 90 | ; Parameters:
|
---|
[150] | 91 | ; CH: Drive number
|
---|
[3] | 92 | ; DX: IDE Base Port address
|
---|
| 93 | ; DS:DI: Ptr to DPT to examine
|
---|
| 94 | ; Returns:
|
---|
| 95 | ; DL: Drive number if correct DPT
|
---|
| 96 | ; CF: Set if wanted DPT found
|
---|
| 97 | ; Cleared if wrong DPT
|
---|
| 98 | ; Corrupts registers:
|
---|
| 99 | ; Nothing
|
---|
| 100 | ;--------------------------------------------------------------------
|
---|
| 101 | ALIGN JUMP_ALIGN
|
---|
[152] | 102 | IterateToSlaveAtPortCallback:
|
---|
[158] | 103 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE ; Clears CF
|
---|
[150] | 104 | jnz SHORT CompareBasePortAddress
|
---|
| 105 | ret ; Wrong DPT
|
---|
[3] | 106 |
|
---|
| 107 | ALIGN JUMP_ALIGN
|
---|
[152] | 108 | IterateToMasterAtPortCallback:
|
---|
[158] | 109 | test BYTE [di+DPT.bFlagsLow], FLGL_DPT_SLAVE
|
---|
[150] | 110 | jnz SHORT ReturnWrongDPT ; Return if slave drive
|
---|
[3] | 111 |
|
---|
[150] | 112 | CompareBasePortAddress:
|
---|
[3] | 113 | push bx
|
---|
[150] | 114 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset] ; CS:BX now points to IDEVARS
|
---|
| 115 | cmp dx, [cs:bx+IDEVARS.wPort] ; Wanted port?
|
---|
[3] | 116 | pop bx
|
---|
[150] | 117 | jne SHORT ReturnWrongDPT
|
---|
| 118 | mov dl, ch ; Return drive number in DL
|
---|
[200] | 119 |
|
---|
| 120 | ReturnRightDPT:
|
---|
[150] | 121 | stc ; Set CF since wanted DPT
|
---|
[3] | 122 | ret
|
---|
[152] | 123 |
|
---|
| 124 |
|
---|
| 125 | ;--------------------------------------------------------------------
|
---|
[233] | 126 | ; IterateToDptWithFlagsHighInBL
|
---|
[152] | 127 | ; Parameters:
|
---|
| 128 | ; DS:DI: Ptr to DPT to examine
|
---|
[233] | 129 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
[152] | 130 | ; Returns:
|
---|
| 131 | ; CF: Set if wanted DPT found
|
---|
| 132 | ; Cleared if wrong DPT
|
---|
| 133 | ; Corrupts registers:
|
---|
| 134 | ; Nothing
|
---|
| 135 | ;--------------------------------------------------------------------
|
---|
| 136 | ALIGN JUMP_ALIGN
|
---|
[233] | 137 | IterateToDptWithFlagsHighInBL:
|
---|
| 138 | test BYTE [di+DPT.bFlagsHigh], bl ; Clears CF (but we need the clc
|
---|
| 139 | ; below anyway for callers above)
|
---|
[200] | 140 | jnz SHORT ReturnRightDPT
|
---|
| 141 |
|
---|
[150] | 142 | ReturnWrongDPT:
|
---|
[152] | 143 | clc ; Clear CF since wrong DPT
|
---|
[3] | 144 | ret
|
---|
| 145 |
|
---|
| 146 | ;--------------------------------------------------------------------
|
---|
[233] | 147 | ; FindDPT_ToDSDIforSerialDevice
|
---|
[161] | 148 | ; Parameters:
|
---|
| 149 | ; DS: RAMVARS segment
|
---|
| 150 | ; Returns:
|
---|
| 151 | ; DS:DI: Ptr to DPT
|
---|
| 152 | ; CF: Set if wanted DPT found
|
---|
| 153 | ; Cleared if DPT not found
|
---|
| 154 | ; Corrupts registers:
|
---|
[203] | 155 | ; SI
|
---|
[161] | 156 | ;--------------------------------------------------------------------
|
---|
[233] | 157 | ALIGN JUMP_ALIGN
|
---|
| 158 | FindDPT_ToDSDIforSerialDevice:
|
---|
| 159 | mov bl, FLGH_DPT_SERIAL_DEVICE
|
---|
| 160 | ; fall-through
|
---|
| 161 |
|
---|
| 162 | ;--------------------------------------------------------------------
|
---|
| 163 | ; FindDPT_ToDSDIforFlagsHigh
|
---|
| 164 | ; Parameters:
|
---|
| 165 | ; DS: RAMVARS segment
|
---|
| 166 | ; BL: Bit(s) to test in DPT.bFlagsHigh
|
---|
| 167 | ; Returns:
|
---|
| 168 | ; DS:DI: Ptr to DPT
|
---|
| 169 | ; CF: Set if wanted DPT found
|
---|
| 170 | ; Cleared if DPT not found
|
---|
| 171 | ; Corrupts registers:
|
---|
| 172 | ; SI
|
---|
| 173 | ;--------------------------------------------------------------------
|
---|
[161] | 174 | ALIGN JUMP_ALIGN
|
---|
[233] | 175 | FindDPT_ToDSDIforFlagsHighInBL:
|
---|
| 176 | mov si, IterateToDptWithFlagsHighInBL
|
---|
[161] | 177 | ; Fall to IterateAllDPTs
|
---|
| 178 |
|
---|
| 179 | ;--------------------------------------------------------------------
|
---|
[3] | 180 | ; Iterates all Disk Parameter Tables.
|
---|
| 181 | ;
|
---|
[150] | 182 | ; IterateAllDPTs
|
---|
[3] | 183 | ; Parameters:
|
---|
[152] | 184 | ; AX,BX,DX: Parameters to callback function
|
---|
| 185 | ; CS:SI: Ptr to callback function
|
---|
| 186 | ; DS: RAMVARS segment
|
---|
[3] | 187 | ; Returns:
|
---|
[152] | 188 | ; DS:DI: Ptr to wanted DPT (if found)
|
---|
| 189 | ; CF: Set if wanted DPT found
|
---|
[200] | 190 | ; Cleared if DPT not found, or no DPTs present
|
---|
[3] | 191 | ; Corrupts registers:
|
---|
[150] | 192 | ; Nothing unless corrupted by callback function
|
---|
[3] | 193 | ;--------------------------------------------------------------------
|
---|
| 194 | ALIGN JUMP_ALIGN
|
---|
[150] | 195 | IterateAllDPTs:
|
---|
[3] | 196 | push cx
|
---|
[150] | 197 | mov cx, [RAMVARS.wDrvCntAndFirst]
|
---|
[200] | 198 | jcxz .NotFound ; Return if no drives
|
---|
[152] | 199 | mov di, RAMVARS_size ; Point DS:DI to first DPT
|
---|
[3] | 200 | ALIGN JUMP_ALIGN
|
---|
| 201 | .LoopWhileDPTsLeft:
|
---|
| 202 | call si ; Is wanted DPT?
|
---|
[150] | 203 | jc SHORT .AllDptsIterated ; If so, return
|
---|
| 204 | inc ch ; Increment drive number
|
---|
| 205 | add di, BYTE LARGEST_DPT_SIZE ; Point to next DPT
|
---|
| 206 | dec cl ; Decrement drives left
|
---|
| 207 | jnz SHORT .LoopWhileDPTsLeft
|
---|
[200] | 208 | .NotFound:
|
---|
[3] | 209 | clc ; Clear CF since DPT not found
|
---|
| 210 | ALIGN JUMP_ALIGN
|
---|
[150] | 211 | .AllDptsIterated:
|
---|
[3] | 212 | pop cx
|
---|
| 213 | ret
|
---|