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