[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Command and port direction functions for different device types.
|
---|
| 3 |
|
---|
| 4 | ; Section containing code
|
---|
| 5 | SECTION .text
|
---|
| 6 |
|
---|
[238] | 7 |
|
---|
[294] | 8 | %macro TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE 1
|
---|
[238] | 9 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
| 10 | jnz SHORT %1
|
---|
| 11 | %endmacro
|
---|
| 12 |
|
---|
| 13 | %macro CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE 1
|
---|
[268] | 14 | xchg ax, bx
|
---|
[238] | 15 | eMOVZX bx, [di+DPT.bIdevarsOffset]
|
---|
| 16 | cmp BYTE [cs:bx+IDEVARS.bDevice], DEVICE_JRIDE_ISA
|
---|
[268] | 17 | xchg bx, ax ; Restore BX
|
---|
[238] | 18 | je SHORT %1
|
---|
| 19 | %endmacro
|
---|
| 20 |
|
---|
| 21 | %macro CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF 2
|
---|
| 22 | cmp BYTE [cs:bp+IDEVARS.bDevice], %1
|
---|
| 23 | je SHORT %2
|
---|
| 24 | %endmacro
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 |
|
---|
[150] | 28 | ;--------------------------------------------------------------------
|
---|
| 29 | ; Device_FinalizeDPT
|
---|
| 30 | ; Parameters:
|
---|
| 31 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 32 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 33 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[150] | 34 | ; Returns:
|
---|
| 35 | ; Nothing
|
---|
| 36 | ; Corrupts registers:
|
---|
| 37 | ; AX, BX, CX, DX
|
---|
| 38 | ;--------------------------------------------------------------------
|
---|
[181] | 39 | %ifdef MODULE_SERIAL
|
---|
[150] | 40 | Device_FinalizeDPT:
|
---|
[258] | 41 | ; needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
|
---|
| 42 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
|
---|
[150] | 43 | jmp IdeDPT_Finalize
|
---|
[294] | 44 | .FinalizeDptForSerialPortDevice:
|
---|
[181] | 45 | jmp SerialDPT_Finalize
|
---|
[238] | 46 |
|
---|
| 47 | %else ; IDE or JR-IDE/ISA
|
---|
[181] | 48 | Device_FinalizeDPT EQU IdeDPT_Finalize
|
---|
[175] | 49 | %endif
|
---|
[150] | 50 |
|
---|
[181] | 51 |
|
---|
[150] | 52 | ;--------------------------------------------------------------------
|
---|
| 53 | ; Device_ResetMasterAndSlaveController
|
---|
| 54 | ; Parameters:
|
---|
| 55 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 56 | ; Returns:
|
---|
| 57 | ; AH: INT 13h Error Code
|
---|
| 58 | ; CF: Cleared if success, Set if error
|
---|
| 59 | ; Corrupts registers:
|
---|
| 60 | ; AL, BX, CX, DX
|
---|
| 61 | ;--------------------------------------------------------------------
|
---|
[238] | 62 | %ifdef MODULE_JRIDE
|
---|
| 63 | %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
|
---|
| 64 | Device_ResetMasterAndSlaveController:
|
---|
[294] | 65 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[238] | 66 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
|
---|
| 67 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
| 68 |
|
---|
| 69 | %else ; IDE + JR-IDE/ISA
|
---|
| 70 | Device_ResetMasterAndSlaveController:
|
---|
| 71 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
|
---|
| 72 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
| 73 | %endif
|
---|
| 74 |
|
---|
| 75 | %elifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 76 | Device_ResetMasterAndSlaveController:
|
---|
[294] | 77 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[181] | 78 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
[238] | 79 |
|
---|
| 80 | %else ; IDE
|
---|
[181] | 81 | Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
|
---|
[175] | 82 | %endif
|
---|
[150] | 83 |
|
---|
[238] | 84 | %ifdef MODULE_JRIDE
|
---|
| 85 | .ResetJrIDE:
|
---|
| 86 | jmp MemIdeCommand_ResetMasterAndSlaveController
|
---|
| 87 | %endif
|
---|
[150] | 88 |
|
---|
[238] | 89 |
|
---|
[150] | 90 | ;--------------------------------------------------------------------
|
---|
| 91 | ; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 92 | ; Parameters:
|
---|
| 93 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
| 94 | ; DS: Segment to RAMVARS
|
---|
[218] | 95 | ; ES:SI: Ptr to normalized buffer to receive 512-byte IDE Information
|
---|
[150] | 96 | ; CS:BP: Ptr to IDEVARS
|
---|
| 97 | ; Returns:
|
---|
| 98 | ; AH: INT 13h Error Code
|
---|
| 99 | ; CF: Cleared if success, Set if error
|
---|
| 100 | ; Corrupts registers:
|
---|
| 101 | ; AL, BL, CX, DX, SI, DI, ES
|
---|
| 102 | ;--------------------------------------------------------------------
|
---|
[238] | 103 | %ifdef MODULE_JRIDE
|
---|
| 104 | %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
|
---|
| 105 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
| 106 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
|
---|
| 107 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
|
---|
| 108 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 109 |
|
---|
| 110 | %else ; IDE + JR-IDE/ISA
|
---|
| 111 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
| 112 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
|
---|
| 113 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 114 | %endif
|
---|
| 115 |
|
---|
| 116 | %elifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 117 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
[238] | 118 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
|
---|
[150] | 119 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[181] | 120 |
|
---|
[238] | 121 | %else ; IDE
|
---|
| 122 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH EQU IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 123 | %endif
|
---|
| 124 |
|
---|
| 125 | %ifdef MODULE_JRIDE
|
---|
| 126 | .IdentifyDriveFromJrIde:
|
---|
| 127 | jmp MemIdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 128 | %endif
|
---|
| 129 |
|
---|
| 130 | %ifdef MODULE_SERIAL
|
---|
[150] | 131 | .IdentifyDriveFromSerialPort:
|
---|
| 132 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[175] | 133 | %endif
|
---|
[150] | 134 |
|
---|
[181] | 135 |
|
---|
[150] | 136 | ;--------------------------------------------------------------------
|
---|
| 137 | ; Device_OutputCommandWithParameters
|
---|
| 138 | ; Parameters:
|
---|
| 139 | ; BH: Default system timer ticks for timeout (can be ignored)
|
---|
| 140 | ; BL: IDE Status Register bit to poll after command
|
---|
[218] | 141 | ; ES:SI: Ptr to normalized buffer (for data transfer commands)
|
---|
[150] | 142 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 143 | ; SS:BP: Ptr to IDEPACK
|
---|
| 144 | ; Returns:
|
---|
| 145 | ; AH: INT 13h Error Code
|
---|
[249] | 146 | ; CX: Number of successfully transferred sectors (for transfer commands)
|
---|
[150] | 147 | ; CF: Cleared if success, Set if error
|
---|
| 148 | ; Corrupts registers:
|
---|
[249] | 149 | ; AL, BX, (CX), DX, (ES:SI for data transfer commands)
|
---|
[150] | 150 | ;--------------------------------------------------------------------
|
---|
[238] | 151 | %ifdef MODULE_JRIDE
|
---|
| 152 | %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
|
---|
| 153 | Device_OutputCommandWithParameters:
|
---|
[294] | 154 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
|
---|
[238] | 155 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
|
---|
| 156 | jmp IdeCommand_OutputWithParameters
|
---|
| 157 |
|
---|
| 158 | %else ; IDE + JR-IDE/ISA
|
---|
| 159 | Device_OutputCommandWithParameters:
|
---|
| 160 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
|
---|
| 161 | jmp IdeCommand_OutputWithParameters
|
---|
| 162 | %endif
|
---|
| 163 |
|
---|
| 164 | %elifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 165 | Device_OutputCommandWithParameters:
|
---|
[294] | 166 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
|
---|
[150] | 167 | jmp IdeCommand_OutputWithParameters
|
---|
[181] | 168 |
|
---|
[238] | 169 | %else ; IDE
|
---|
| 170 | Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
|
---|
| 171 | %endif
|
---|
| 172 |
|
---|
| 173 | %ifdef MODULE_JRIDE
|
---|
[150] | 174 | ALIGN JUMP_ALIGN
|
---|
[238] | 175 | .OutputCommandToJrIDE:
|
---|
| 176 | jmp MemIdeCommand_OutputWithParameters
|
---|
| 177 | %endif
|
---|
| 178 |
|
---|
| 179 | %ifdef MODULE_SERIAL
|
---|
| 180 | ALIGN JUMP_ALIGN
|
---|
[150] | 181 | .OutputCommandToSerialPort:
|
---|
| 182 | jmp SerialCommand_OutputWithParameters
|
---|
[175] | 183 | %endif
|
---|
[150] | 184 |
|
---|
[181] | 185 |
|
---|
[150] | 186 | ;--------------------------------------------------------------------
|
---|
| 187 | ; Device_SelectDrive
|
---|
| 188 | ; Parameters:
|
---|
| 189 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 190 | ; SS:BP: Ptr to IDEPACK
|
---|
| 191 | ; Returns:
|
---|
| 192 | ; AH: INT 13h Error Code
|
---|
| 193 | ; CF: Cleared if success, Set if error
|
---|
| 194 | ; Corrupts registers:
|
---|
| 195 | ; AL, BX, CX, DX
|
---|
| 196 | ;--------------------------------------------------------------------
|
---|
[238] | 197 | %ifdef MODULE_JRIDE
|
---|
| 198 | %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
|
---|
| 199 | Device_SelectDrive:
|
---|
[294] | 200 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[238] | 201 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
|
---|
| 202 | jmp IdeCommand_SelectDrive
|
---|
| 203 |
|
---|
| 204 | %else ; IDE + JR-IDE/ISA
|
---|
| 205 | Device_SelectDrive:
|
---|
| 206 | CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
|
---|
| 207 | jmp IdeCommand_SelectDrive
|
---|
| 208 | %endif
|
---|
| 209 |
|
---|
| 210 | %elifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 211 | Device_SelectDrive:
|
---|
[294] | 212 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[150] | 213 | jmp IdeCommand_SelectDrive
|
---|
[181] | 214 |
|
---|
[238] | 215 | %else ; IDE
|
---|
| 216 | Device_SelectDrive EQU IdeCommand_SelectDrive
|
---|
| 217 | %endif
|
---|
| 218 |
|
---|
| 219 | %ifdef MODULE_JRIDE
|
---|
| 220 | ALIGN JUMP_ALIGN
|
---|
| 221 | .SelectJrIdeDrive:
|
---|
| 222 | jmp MemIdeCommand_SelectDrive
|
---|
| 223 | %endif
|
---|
| 224 |
|
---|
| 225 | %ifdef MODULE_SERIAL
|
---|
| 226 | ALIGN JUMP_ALIGN
|
---|
[150] | 227 | ReturnSuccessForSerialPort:
|
---|
| 228 | xor ax, ax
|
---|
| 229 | ret
|
---|
[175] | 230 | %endif
|
---|