[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 |
---|
| 54 | %else |
---|
| 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 | ;-------------------------------------------------------------------- |
---|
[613] | 102 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH: |
---|
| 103 | %ifndef NO_ATAID_CORRECTION |
---|
| 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 | %endif |
---|
| 111 | |
---|
[400] | 112 | %ifdef MODULE_SERIAL ; IDE + Serial |
---|
[568] | 113 | cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT |
---|
| 114 | %ifdef USE_386 |
---|
| 115 | jne IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH |
---|
| 116 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH |
---|
| 117 | %else |
---|
| 118 | je SHORT .IdentifyDriveFromSerialPort |
---|
[150] | 119 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH |
---|
| 120 | .IdentifyDriveFromSerialPort: |
---|
| 121 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH |
---|
[568] | 122 | %endif |
---|
[400] | 123 | |
---|
| 124 | %else ; IDE |
---|
[613] | 125 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH |
---|
[175] | 126 | %endif |
---|
[150] | 127 | |
---|
[181] | 128 | |
---|
[150] | 129 | ;-------------------------------------------------------------------- |
---|
| 130 | ; Device_OutputCommandWithParameters |
---|
| 131 | ; Parameters: |
---|
| 132 | ; BH: Default system timer ticks for timeout (can be ignored) |
---|
| 133 | ; BL: IDE Status Register bit to poll after command |
---|
[480] | 134 | ; ES:SI: Ptr to buffer (for data transfer commands) |
---|
[150] | 135 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 136 | ; SS:BP: Ptr to IDEPACK |
---|
| 137 | ; Returns: |
---|
| 138 | ; AH: INT 13h Error Code |
---|
[249] | 139 | ; CX: Number of successfully transferred sectors (for transfer commands) |
---|
[150] | 140 | ; CF: Cleared if success, Set if error |
---|
| 141 | ; Corrupts registers: |
---|
[249] | 142 | ; AL, BX, (CX), DX, (ES:SI for data transfer commands) |
---|
[150] | 143 | ;-------------------------------------------------------------------- |
---|
[400] | 144 | %ifdef MODULE_SERIAL ; IDE + Serial |
---|
| 145 | ALIGN JUMP_ALIGN |
---|
[150] | 146 | Device_OutputCommandWithParameters: |
---|
[568] | 147 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE |
---|
| 148 | %ifdef USE_386 |
---|
| 149 | jz IdeCommand_OutputWithParameters |
---|
| 150 | jmp SerialCommand_OutputWithParameters |
---|
| 151 | %else |
---|
| 152 | jnz SHORT .OutputCommandToSerialPort |
---|
[150] | 153 | jmp IdeCommand_OutputWithParameters |
---|
[181] | 154 | |
---|
[150] | 155 | ALIGN JUMP_ALIGN |
---|
| 156 | .OutputCommandToSerialPort: |
---|
| 157 | jmp SerialCommand_OutputWithParameters |
---|
[568] | 158 | %endif |
---|
[400] | 159 | |
---|
| 160 | %else ; IDE |
---|
| 161 | Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters |
---|
[175] | 162 | %endif |
---|
[150] | 163 | |
---|
[181] | 164 | |
---|
[150] | 165 | ;-------------------------------------------------------------------- |
---|
[617] | 166 | ; Device_ReadLBAlowRegisterToAL |
---|
| 167 | ; Returns LBA low register / Sector number register contents. |
---|
| 168 | ; Note that this returns valid value only after transfer command (read/write/verify) |
---|
| 169 | ; has stopped to an error. Do not call this otherwise. |
---|
| 170 | ; Parameters: |
---|
| 171 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 172 | ; Returns: |
---|
| 173 | ; AL: Byte read from the device register |
---|
| 174 | ; Corrupts registers: |
---|
| 175 | ; BX, DX |
---|
| 176 | ;-------------------------------------------------------------------- |
---|
| 177 | ;%ifdef MODULE_SERIAL ; IDE + Serial |
---|
| 178 | ;ALIGN JUMP_ALIGN |
---|
| 179 | ;Device_ReadLBAlowRegisterToAL: |
---|
| 180 | ; test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE |
---|
| 181 | ;%ifdef USE_386 |
---|
| 182 | ; jz IdeCommand_ReadLBAlowRegisterToAL |
---|
| 183 | ; jmp SerialCommand_ReadLBAlowRegisterToAL |
---|
| 184 | ;%else |
---|
| 185 | ; jnz SHORT .ReadFromSerialPort |
---|
| 186 | ; jmp IdeCommand_ReadLBAlowRegisterToAL |
---|
| 187 | |
---|
| 188 | ;ALIGN JUMP_ALIGN |
---|
| 189 | ;.ReadFromSerialPort: |
---|
| 190 | ; jmp SerialCommand_ReadLBAlowRegisterToAL |
---|
| 191 | ;%endif |
---|
| 192 | |
---|
| 193 | ;%else ; IDE only |
---|
| 194 | Device_ReadLBAlowRegisterToAL EQU IdeCommand_ReadLBAlowRegisterToAL |
---|
| 195 | ;%endif |
---|
| 196 | ; TODO: For now we simply assume serial device do not produce verify errors |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | ;-------------------------------------------------------------------- |
---|
[150] | 200 | ; Device_SelectDrive |
---|
| 201 | ; Parameters: |
---|
| 202 | ; DS:DI: Ptr to DPT (in RAMVARS segment) |
---|
| 203 | ; SS:BP: Ptr to IDEPACK |
---|
| 204 | ; Returns: |
---|
| 205 | ; AH: INT 13h Error Code |
---|
| 206 | ; CF: Cleared if success, Set if error |
---|
| 207 | ; Corrupts registers: |
---|
| 208 | ; AL, BX, CX, DX |
---|
| 209 | ;-------------------------------------------------------------------- |
---|
[400] | 210 | %ifdef MODULE_SERIAL ; IDE + Serial |
---|
[150] | 211 | Device_SelectDrive: |
---|
[568] | 212 | test BYTE [di+DPT.bFlagsHigh], FLGH_DPT_SERIAL_DEVICE |
---|
| 213 | %ifndef USE_386 |
---|
| 214 | jnz SHORT ReturnSuccessForSerialPort |
---|
[150] | 215 | jmp IdeCommand_SelectDrive |
---|
[568] | 216 | %else |
---|
| 217 | jz IdeCommand_SelectDrive |
---|
| 218 | ; Fall to ReturnSuccessForSerialPort |
---|
| 219 | %endif |
---|
[181] | 220 | |
---|
[400] | 221 | %else ; IDE |
---|
| 222 | Device_SelectDrive EQU IdeCommand_SelectDrive |
---|
[238] | 223 | %endif |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | %ifdef MODULE_SERIAL |
---|
| 227 | ALIGN JUMP_ALIGN |
---|
[150] | 228 | ReturnSuccessForSerialPort: |
---|
| 229 | xor ax, ax |
---|
| 230 | ret |
---|
[175] | 231 | %endif |
---|