[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Command and port direction functions for different device types.
|
---|
[526] | 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
|
---|
| 16 | ; GNU General Public License for more details.
|
---|
[526] | 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[376] | 18 | ;
|
---|
[526] | 19 |
|
---|
[150] | 20 | ; Section containing code
|
---|
| 21 | SECTION .text
|
---|
| 22 |
|
---|
[238] | 23 |
|
---|
[294] | 24 | %macro TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE 1
|
---|
[238] | 25 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
| 26 | jnz SHORT %1
|
---|
| 27 | %endmacro
|
---|
| 28 |
|
---|
| 29 | %macro CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF 2
|
---|
| 30 | cmp BYTE [cs:bp+IDEVARS.bDevice], %1
|
---|
| 31 | je SHORT %2
|
---|
| 32 | %endmacro
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
[150] | 36 | ;--------------------------------------------------------------------
|
---|
| 37 | ; Device_FinalizeDPT
|
---|
| 38 | ; Parameters:
|
---|
| 39 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
| 40 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
[160] | 41 | ; CS:BP: Ptr to IDEVARS for the controller
|
---|
[150] | 42 | ; Returns:
|
---|
| 43 | ; Nothing
|
---|
| 44 | ; Corrupts registers:
|
---|
| 45 | ; AX, BX, CX, DX
|
---|
| 46 | ;--------------------------------------------------------------------
|
---|
[400] | 47 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 48 | Device_FinalizeDPT:
|
---|
[568] | 49 | ; Needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
|
---|
| 50 | cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
|
---|
| 51 | %ifdef USE_386
|
---|
| 52 | jne IdeDPT_Finalize
|
---|
| 53 | jmp SerialDPT_Finalize
|
---|
[621] | 54 | %else ; ~USE_386
|
---|
[568] | 55 | je SHORT .FinalizeDptForSerialPortDevice
|
---|
[150] | 56 | jmp IdeDPT_Finalize
|
---|
[294] | 57 | .FinalizeDptForSerialPortDevice:
|
---|
[181] | 58 | jmp SerialDPT_Finalize
|
---|
[568] | 59 | %endif
|
---|
[238] | 60 |
|
---|
[400] | 61 | %else ; IDE
|
---|
| 62 | Device_FinalizeDPT EQU IdeDPT_Finalize
|
---|
[175] | 63 | %endif
|
---|
[150] | 64 |
|
---|
[181] | 65 |
|
---|
[150] | 66 | ;--------------------------------------------------------------------
|
---|
[507] | 67 | ; Device_ResetMasterAndSlaveController
|
---|
| 68 | ; Parameters:
|
---|
| 69 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 70 | ; Returns:
|
---|
| 71 | ; AH: INT 13h Error Code
|
---|
| 72 | ; CF: Cleared if success, Set if error
|
---|
| 73 | ; Corrupts registers:
|
---|
| 74 | ; AL, BX, CX, DX
|
---|
| 75 | ;--------------------------------------------------------------------
|
---|
| 76 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
| 77 | Device_ResetMasterAndSlaveController:
|
---|
| 78 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
| 79 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
| 80 |
|
---|
| 81 | %else ; IDE
|
---|
| 82 | Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
|
---|
| 83 | %endif
|
---|
| 84 |
|
---|
| 85 |
|
---|
| 86 | ;--------------------------------------------------------------------
|
---|
[150] | 87 | ; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 88 | ; Parameters:
|
---|
| 89 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
[613] | 90 | ; CX: XUB_INT13h_SIGNATURE to ignore illegal ATA-ID values, otherwise
|
---|
| 91 | ; correct them (only used if NOT build with NO_ATAID_CORRECTION)
|
---|
[473] | 92 | ; DX: Autodetected port (for devices that support autodetection)
|
---|
[150] | 93 | ; DS: Segment to RAMVARS
|
---|
[480] | 94 | ; ES:SI: Ptr to buffer to receive 512-byte IDE Information
|
---|
[150] | 95 | ; CS:BP: Ptr to IDEVARS
|
---|
| 96 | ; Returns:
|
---|
| 97 | ; AH: INT 13h Error Code
|
---|
| 98 | ; CF: Cleared if success, Set if error
|
---|
| 99 | ; Corrupts registers:
|
---|
[443] | 100 | ; AL, BX, CX, DX, SI, DI, ES
|
---|
[150] | 101 | ;--------------------------------------------------------------------
|
---|
[621] | 102 | %ifndef NO_ATAID_CORRECTION
|
---|
[613] | 103 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
| 104 | cmp cx, XUB_INT13h_SIGNATURE
|
---|
| 105 | je SHORT .DoNotFixAtaInformation
|
---|
| 106 | push es
|
---|
| 107 | push si
|
---|
| 108 | ePUSH_T cx, AtaID_PopESSIandFixIllegalValuesFromESSI ; Here we modify ATA information if necessary
|
---|
| 109 | .DoNotFixAtaInformation:
|
---|
| 110 |
|
---|
[400] | 111 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[568] | 112 | cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
|
---|
| 113 | %ifdef USE_386
|
---|
| 114 | jne IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 115 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[621] | 116 | %else ; ~USE_386
|
---|
[568] | 117 | je SHORT .IdentifyDriveFromSerialPort
|
---|
[150] | 118 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 119 | .IdentifyDriveFromSerialPort:
|
---|
| 120 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[568] | 121 | %endif
|
---|
[400] | 122 |
|
---|
| 123 | %else ; IDE
|
---|
[613] | 124 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[175] | 125 | %endif
|
---|
[150] | 126 |
|
---|
[621] | 127 | %else ; NO_ATAID_CORRECTION
|
---|
| 128 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
| 129 | cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
|
---|
| 130 | %ifdef USE_386
|
---|
| 131 | jne IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 132 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 133 | %else ; ~USE_386
|
---|
| 134 | je SHORT .IdentifyDriveFromSerialPort
|
---|
| 135 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 136 | .IdentifyDriveFromSerialPort:
|
---|
| 137 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 138 | %endif
|
---|
[181] | 139 |
|
---|
[621] | 140 | %else ; IDE
|
---|
| 141 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH EQU IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 142 | %endif
|
---|
| 143 | %endif ; NO_ATAID_CORRECTION
|
---|
| 144 |
|
---|
| 145 |
|
---|
[150] | 146 | ;--------------------------------------------------------------------
|
---|
| 147 | ; Device_OutputCommandWithParameters
|
---|
| 148 | ; Parameters:
|
---|
| 149 | ; BH: Default system timer ticks for timeout (can be ignored)
|
---|
| 150 | ; BL: IDE Status Register bit to poll after command
|
---|
[480] | 151 | ; ES:SI: Ptr to buffer (for data transfer commands)
|
---|
[150] | 152 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 153 | ; SS:BP: Ptr to IDEPACK
|
---|
| 154 | ; Returns:
|
---|
| 155 | ; AH: INT 13h Error Code
|
---|
[249] | 156 | ; CX: Number of successfully transferred sectors (for transfer commands)
|
---|
[150] | 157 | ; CF: Cleared if success, Set if error
|
---|
| 158 | ; Corrupts registers:
|
---|
[249] | 159 | ; AL, BX, (CX), DX, (ES:SI for data transfer commands)
|
---|
[150] | 160 | ;--------------------------------------------------------------------
|
---|
[400] | 161 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
| 162 | ALIGN JUMP_ALIGN
|
---|
[150] | 163 | Device_OutputCommandWithParameters:
|
---|
[568] | 164 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
| 165 | %ifdef USE_386
|
---|
| 166 | jz IdeCommand_OutputWithParameters
|
---|
| 167 | jmp SerialCommand_OutputWithParameters
|
---|
[621] | 168 | %else ; ~USE_386
|
---|
[568] | 169 | jnz SHORT .OutputCommandToSerialPort
|
---|
[150] | 170 | jmp IdeCommand_OutputWithParameters
|
---|
[181] | 171 |
|
---|
[150] | 172 | ALIGN JUMP_ALIGN
|
---|
| 173 | .OutputCommandToSerialPort:
|
---|
| 174 | jmp SerialCommand_OutputWithParameters
|
---|
[568] | 175 | %endif
|
---|
[400] | 176 |
|
---|
| 177 | %else ; IDE
|
---|
| 178 | Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
|
---|
[175] | 179 | %endif
|
---|
[150] | 180 |
|
---|
[181] | 181 |
|
---|
[150] | 182 | ;--------------------------------------------------------------------
|
---|
[617] | 183 | ; Device_ReadLBAlowRegisterToAL
|
---|
| 184 | ; Returns LBA low register / Sector number register contents.
|
---|
| 185 | ; Note that this returns valid value only after transfer command (read/write/verify)
|
---|
| 186 | ; has stopped to an error. Do not call this otherwise.
|
---|
| 187 | ; Parameters:
|
---|
| 188 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 189 | ; Returns:
|
---|
| 190 | ; AL: Byte read from the device register
|
---|
| 191 | ; Corrupts registers:
|
---|
| 192 | ; BX, DX
|
---|
| 193 | ;--------------------------------------------------------------------
|
---|
| 194 | ;%ifdef MODULE_SERIAL ; IDE + Serial
|
---|
| 195 | ;ALIGN JUMP_ALIGN
|
---|
| 196 | ;Device_ReadLBAlowRegisterToAL:
|
---|
| 197 | ; test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
| 198 | ;%ifdef USE_386
|
---|
| 199 | ; jz IdeCommand_ReadLBAlowRegisterToAL
|
---|
| 200 | ; jmp SerialCommand_ReadLBAlowRegisterToAL
|
---|
[621] | 201 | ;%else ; ~USE_386
|
---|
[617] | 202 | ; jnz SHORT .ReadFromSerialPort
|
---|
| 203 | ; jmp IdeCommand_ReadLBAlowRegisterToAL
|
---|
| 204 |
|
---|
| 205 | ;ALIGN JUMP_ALIGN
|
---|
| 206 | ;.ReadFromSerialPort:
|
---|
| 207 | ; jmp SerialCommand_ReadLBAlowRegisterToAL
|
---|
| 208 | ;%endif
|
---|
| 209 |
|
---|
| 210 | ;%else ; IDE only
|
---|
| 211 | Device_ReadLBAlowRegisterToAL EQU IdeCommand_ReadLBAlowRegisterToAL
|
---|
| 212 | ;%endif
|
---|
| 213 | ; TODO: For now we simply assume serial device do not produce verify errors
|
---|
| 214 |
|
---|
| 215 |
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
[150] | 217 | ; Device_SelectDrive
|
---|
| 218 | ; Parameters:
|
---|
| 219 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 220 | ; SS:BP: Ptr to IDEPACK
|
---|
| 221 | ; Returns:
|
---|
| 222 | ; AH: INT 13h Error Code
|
---|
| 223 | ; CF: Cleared if success, Set if error
|
---|
| 224 | ; Corrupts registers:
|
---|
| 225 | ; AL, BX, CX, DX
|
---|
| 226 | ;--------------------------------------------------------------------
|
---|
[400] | 227 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 228 | Device_SelectDrive:
|
---|
[568] | 229 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE
|
---|
| 230 | %ifndef USE_386
|
---|
| 231 | jnz SHORT ReturnSuccessForSerialPort
|
---|
[150] | 232 | jmp IdeCommand_SelectDrive
|
---|
[621] | 233 | %else ; USE_386
|
---|
[568] | 234 | jz IdeCommand_SelectDrive
|
---|
| 235 | ; Fall to ReturnSuccessForSerialPort
|
---|
| 236 | %endif
|
---|
[181] | 237 |
|
---|
[400] | 238 | %else ; IDE
|
---|
| 239 | Device_SelectDrive EQU IdeCommand_SelectDrive
|
---|
[238] | 240 | %endif
|
---|
| 241 |
|
---|
| 242 |
|
---|
| 243 | %ifdef MODULE_SERIAL
|
---|
[150] | 244 | ReturnSuccessForSerialPort:
|
---|
| 245 | xor ax, ax
|
---|
| 246 | ret
|
---|
[175] | 247 | %endif
|
---|