[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : Command and port direction functions for different device types.
|
---|
[376] | 3 |
|
---|
| 4 | ;
|
---|
| 5 | ; XTIDE Universal BIOS and Associated Tools
|
---|
| 6 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2012 by XTIDE Universal BIOS Team.
|
---|
| 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.
|
---|
| 12 | ;
|
---|
| 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.
|
---|
| 17 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 18 | ;
|
---|
| 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:
|
---|
[258] | 49 | ; needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
|
---|
[400] | 50 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
|
---|
[150] | 51 | jmp IdeDPT_Finalize
|
---|
[294] | 52 | .FinalizeDptForSerialPortDevice:
|
---|
[181] | 53 | jmp SerialDPT_Finalize
|
---|
[238] | 54 |
|
---|
[400] | 55 | %else ; IDE
|
---|
| 56 | Device_FinalizeDPT EQU IdeDPT_Finalize
|
---|
[175] | 57 | %endif
|
---|
[150] | 58 |
|
---|
[181] | 59 |
|
---|
[150] | 60 | ;--------------------------------------------------------------------
|
---|
| 61 | ; Device_ResetMasterAndSlaveController
|
---|
| 62 | ; Parameters:
|
---|
| 63 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 64 | ; Returns:
|
---|
| 65 | ; AH: INT 13h Error Code
|
---|
| 66 | ; CF: Cleared if success, Set if error
|
---|
| 67 | ; Corrupts registers:
|
---|
| 68 | ; AL, BX, CX, DX
|
---|
| 69 | ;--------------------------------------------------------------------
|
---|
[400] | 70 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 71 | Device_ResetMasterAndSlaveController:
|
---|
[400] | 72 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[181] | 73 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
[238] | 74 |
|
---|
[400] | 75 | %else ; IDE
|
---|
| 76 | Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
|
---|
[175] | 77 | %endif
|
---|
[150] | 78 |
|
---|
| 79 |
|
---|
| 80 | ;--------------------------------------------------------------------
|
---|
| 81 | ; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
| 82 | ; Parameters:
|
---|
| 83 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
| 84 | ; DS: Segment to RAMVARS
|
---|
[218] | 85 | ; ES:SI: Ptr to normalized buffer to receive 512-byte IDE Information
|
---|
[150] | 86 | ; CS:BP: Ptr to IDEVARS
|
---|
| 87 | ; Returns:
|
---|
| 88 | ; AH: INT 13h Error Code
|
---|
| 89 | ; CF: Cleared if success, Set if error
|
---|
| 90 | ; Corrupts registers:
|
---|
[443] | 91 | ; AL, BX, CX, DX, SI, DI, ES
|
---|
[150] | 92 | ;--------------------------------------------------------------------
|
---|
[400] | 93 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 94 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
[400] | 95 | CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
|
---|
[150] | 96 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
| 97 | .IdentifyDriveFromSerialPort:
|
---|
| 98 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[400] | 99 |
|
---|
| 100 | %else ; IDE
|
---|
| 101 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH EQU IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
[175] | 102 | %endif
|
---|
[150] | 103 |
|
---|
[181] | 104 |
|
---|
[150] | 105 | ;--------------------------------------------------------------------
|
---|
| 106 | ; Device_OutputCommandWithParameters
|
---|
| 107 | ; Parameters:
|
---|
| 108 | ; BH: Default system timer ticks for timeout (can be ignored)
|
---|
| 109 | ; BL: IDE Status Register bit to poll after command
|
---|
[218] | 110 | ; ES:SI: Ptr to normalized buffer (for data transfer commands)
|
---|
[150] | 111 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 112 | ; SS:BP: Ptr to IDEPACK
|
---|
| 113 | ; Returns:
|
---|
| 114 | ; AH: INT 13h Error Code
|
---|
[249] | 115 | ; CX: Number of successfully transferred sectors (for transfer commands)
|
---|
[150] | 116 | ; CF: Cleared if success, Set if error
|
---|
| 117 | ; Corrupts registers:
|
---|
[249] | 118 | ; AL, BX, (CX), DX, (ES:SI for data transfer commands)
|
---|
[150] | 119 | ;--------------------------------------------------------------------
|
---|
[400] | 120 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
| 121 | ALIGN JUMP_ALIGN
|
---|
[150] | 122 | Device_OutputCommandWithParameters:
|
---|
[294] | 123 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
|
---|
[150] | 124 | jmp IdeCommand_OutputWithParameters
|
---|
[181] | 125 |
|
---|
[150] | 126 | ALIGN JUMP_ALIGN
|
---|
| 127 | .OutputCommandToSerialPort:
|
---|
| 128 | jmp SerialCommand_OutputWithParameters
|
---|
[400] | 129 |
|
---|
| 130 | %else ; IDE
|
---|
| 131 | Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
|
---|
[175] | 132 | %endif
|
---|
[150] | 133 |
|
---|
[181] | 134 |
|
---|
[150] | 135 | ;--------------------------------------------------------------------
|
---|
| 136 | ; Device_SelectDrive
|
---|
| 137 | ; Parameters:
|
---|
| 138 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 139 | ; SS:BP: Ptr to IDEPACK
|
---|
| 140 | ; Returns:
|
---|
| 141 | ; AH: INT 13h Error Code
|
---|
| 142 | ; CF: Cleared if success, Set if error
|
---|
| 143 | ; Corrupts registers:
|
---|
| 144 | ; AL, BX, CX, DX
|
---|
| 145 | ;--------------------------------------------------------------------
|
---|
[400] | 146 | %ifdef MODULE_SERIAL ; IDE + Serial
|
---|
[150] | 147 | Device_SelectDrive:
|
---|
[400] | 148 | TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
|
---|
[150] | 149 | jmp IdeCommand_SelectDrive
|
---|
[181] | 150 |
|
---|
[400] | 151 | %else ; IDE
|
---|
| 152 | Device_SelectDrive EQU IdeCommand_SelectDrive
|
---|
[238] | 153 | %endif
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | %ifdef MODULE_SERIAL
|
---|
| 157 | ALIGN JUMP_ALIGN
|
---|
[150] | 158 | ReturnSuccessForSerialPort:
|
---|
| 159 | xor ax, ax
|
---|
| 160 | ret
|
---|
[175] | 161 | %endif
|
---|