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 |
|
---|
7 | ;--------------------------------------------------------------------
|
---|
8 | ; Device_FinalizeDPT
|
---|
9 | ; Parameters:
|
---|
10 | ; DS:DI: Ptr to Disk Parameter Table
|
---|
11 | ; ES:SI: Ptr to 512-byte ATA information read from the drive
|
---|
12 | ; Returns:
|
---|
13 | ; Nothing
|
---|
14 | ; Corrupts registers:
|
---|
15 | ; AX, BX, CX, DX
|
---|
16 | ;--------------------------------------------------------------------
|
---|
17 | Device_FinalizeDPT:
|
---|
18 | test WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
|
---|
19 | jnz SHORT ReturnSuccessForSerialPort
|
---|
20 | jmp IdeDPT_Finalize
|
---|
21 | .FinalizeDptForSerialPortDevice:
|
---|
22 | jmp SerialDPT_Finalize
|
---|
23 |
|
---|
24 |
|
---|
25 | ;--------------------------------------------------------------------
|
---|
26 | ; Device_ResetMasterAndSlaveController
|
---|
27 | ; Parameters:
|
---|
28 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
29 | ; Returns:
|
---|
30 | ; AH: INT 13h Error Code
|
---|
31 | ; CF: Cleared if success, Set if error
|
---|
32 | ; Corrupts registers:
|
---|
33 | ; AL, BX, CX, DX
|
---|
34 | ;--------------------------------------------------------------------
|
---|
35 | Device_ResetMasterAndSlaveController:
|
---|
36 | test WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
|
---|
37 | jnz SHORT ReturnSuccessForSerialPort
|
---|
38 | jmp IdeCommand_ResetMasterAndSlaveController
|
---|
39 |
|
---|
40 |
|
---|
41 | ;--------------------------------------------------------------------
|
---|
42 | ; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
|
---|
43 | ; Parameters:
|
---|
44 | ; BH: Drive Select byte for Drive and Head Select Register
|
---|
45 | ; DS: Segment to RAMVARS
|
---|
46 | ; ES:SI: Ptr to buffer to receive 512-byte IDE Information
|
---|
47 | ; CS:BP: Ptr to IDEVARS
|
---|
48 | ; Returns:
|
---|
49 | ; AH: INT 13h Error Code
|
---|
50 | ; CF: Cleared if success, Set if error
|
---|
51 | ; Corrupts registers:
|
---|
52 | ; AL, BL, CX, DX, SI, DI, ES
|
---|
53 | ;--------------------------------------------------------------------
|
---|
54 | Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
|
---|
55 | cmp BYTE [cs:bp+IDEVARS.bDevice], DEVICE_SERIAL_PORT
|
---|
56 | je SHORT .IdentifyDriveFromSerialPort
|
---|
57 | jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
58 | .IdentifyDriveFromSerialPort:
|
---|
59 | jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
|
---|
60 |
|
---|
61 |
|
---|
62 | ;--------------------------------------------------------------------
|
---|
63 | ; Device_OutputCommandWithParameters
|
---|
64 | ; Parameters:
|
---|
65 | ; BH: Default system timer ticks for timeout (can be ignored)
|
---|
66 | ; BL: IDE Status Register bit to poll after command
|
---|
67 | ; ES:SI: Ptr to buffer (for data transfer commands)
|
---|
68 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
69 | ; SS:BP: Ptr to IDEPACK
|
---|
70 | ; Returns:
|
---|
71 | ; AH: INT 13h Error Code
|
---|
72 | ; CF: Cleared if success, Set if error
|
---|
73 | ; Corrupts registers:
|
---|
74 | ; AL, BX, CX, DX, (ES:SI for data transfer commands)
|
---|
75 | ;--------------------------------------------------------------------
|
---|
76 | ALIGN JUMP_ALIGN
|
---|
77 | Device_OutputCommandWithParameters:
|
---|
78 | call IdeIrq_SetInServiceDPTandClearTaskFlag
|
---|
79 | test WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
|
---|
80 | jnz SHORT .OutputCommandToSerialPort
|
---|
81 | jmp IdeCommand_OutputWithParameters
|
---|
82 | ALIGN JUMP_ALIGN
|
---|
83 | .OutputCommandToSerialPort:
|
---|
84 | jmp SerialCommand_OutputWithParameters
|
---|
85 |
|
---|
86 |
|
---|
87 | ;--------------------------------------------------------------------
|
---|
88 | ; Device_SelectDrive
|
---|
89 | ; Parameters:
|
---|
90 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
91 | ; SS:BP: Ptr to IDEPACK
|
---|
92 | ; Returns:
|
---|
93 | ; AH: INT 13h Error Code
|
---|
94 | ; CF: Cleared if success, Set if error
|
---|
95 | ; Corrupts registers:
|
---|
96 | ; AL, BX, CX, DX
|
---|
97 | ;--------------------------------------------------------------------
|
---|
98 | ALIGN JUMP_ALIGN
|
---|
99 | Device_SelectDrive:
|
---|
100 | test WORD [di+DPT.wFlags], FLG_DPT_SERIAL_DEVICE
|
---|
101 | jnz SHORT ReturnSuccessForSerialPort
|
---|
102 | jmp IdeCommand_SelectDrive
|
---|
103 | ReturnSuccessForSerialPort:
|
---|
104 | xor ax, ax
|
---|
105 | ret
|
---|
106 |
|
---|
107 |
|
---|
108 | ;--------------------------------------------------------------------
|
---|
109 | ; Device_OutputALtoIdeRegisterInDL
|
---|
110 | ; Parameters:
|
---|
111 | ; AL: Byte to output
|
---|
112 | ; DL: IDE Register
|
---|
113 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
114 | ; Returns:
|
---|
115 | ; Nothing
|
---|
116 | ; Corrupts registers:
|
---|
117 | ; BX, DX
|
---|
118 | ;--------------------------------------------------------------------
|
---|
119 | ALIGN JUMP_ALIGN
|
---|
120 | Device_OutputALtoIdeRegisterInDL:
|
---|
121 | mov bx, IdeIO_OutputALtoIdeRegisterInDX
|
---|
122 | jmp SHORT TranslateRegisterAddressInDLifNecessaryThenJumpToBX
|
---|
123 |
|
---|
124 |
|
---|
125 | ;--------------------------------------------------------------------
|
---|
126 | ; Device_OutputALtoIdeControlBlockRegisterInDL
|
---|
127 | ; Parameters:
|
---|
128 | ; AL: Byte to output
|
---|
129 | ; DL: IDE Control Block Register
|
---|
130 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
131 | ; Returns:
|
---|
132 | ; Nothing
|
---|
133 | ; Corrupts registers:
|
---|
134 | ; BX, DX
|
---|
135 | ;--------------------------------------------------------------------
|
---|
136 | ALIGN JUMP_ALIGN
|
---|
137 | Device_OutputALtoIdeControlBlockRegisterInDL:
|
---|
138 | mov bx, IdeIO_OutputALtoIdeControlBlockRegisterInDX
|
---|
139 | jmp SHORT TranslateRegisterAddressInDLifNecessaryThenJumpToBX
|
---|
140 |
|
---|
141 |
|
---|
142 | ;--------------------------------------------------------------------
|
---|
143 | ; Device_InputToALfromIdeRegisterInDL
|
---|
144 | ; Parameters:
|
---|
145 | ; DL: IDE Register
|
---|
146 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
147 | ; Returns:
|
---|
148 | ; AL: Inputted byte
|
---|
149 | ; Corrupts registers:
|
---|
150 | ; BX, DX
|
---|
151 | ;--------------------------------------------------------------------
|
---|
152 | ALIGN JUMP_ALIGN
|
---|
153 | Device_InputToALfromIdeRegisterInDL:
|
---|
154 | mov bx, IdeIO_InputToALfromIdeRegisterInDX
|
---|
155 | ; Fall to TranslateRegisterAddressInDLifNecessaryThenJumpToBX
|
---|
156 |
|
---|
157 |
|
---|
158 | ;--------------------------------------------------------------------
|
---|
159 | ; TranslateRegisterAddressInDLifNecessaryThenJumpToBX
|
---|
160 | ; Parameters:
|
---|
161 | ; AL: Byte to output (if output function in BX)
|
---|
162 | ; DL: IDE Register
|
---|
163 | ; BX: I/O function to jump to
|
---|
164 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
165 | ; Returns:
|
---|
166 | ; AL: Inputted byte (if input function in BX)
|
---|
167 | ; Corrupts registers:
|
---|
168 | ; BX, DX
|
---|
169 | ;--------------------------------------------------------------------
|
---|
170 | TranslateRegisterAddressInDLifNecessaryThenJumpToBX:
|
---|
171 | test WORD [di+DPT.wFlags], FLG_DPT_REVERSED_A0_AND_A3
|
---|
172 | jz SHORT .JumpToIoFunctionInSI
|
---|
173 |
|
---|
174 | ; Exchange address lines A0 and A3 from DL
|
---|
175 | mov dh, MASK_A3_AND_A0_ADDRESS_LINES
|
---|
176 | and dh, dl ; DH = 0, 1, 8 or 9, we can ignore 0 and 9
|
---|
177 | jz SHORT .JumpToIoFunctionInSI ; Jump out since DH is 0
|
---|
178 | xor dh, MASK_A3_AND_A0_ADDRESS_LINES
|
---|
179 | jz SHORT .JumpToIoFunctionInSI ; Jump out since DH was 9
|
---|
180 | and dl, ~MASK_A3_AND_A0_ADDRESS_LINES
|
---|
181 | or dl, dh ; Address lines now reversed
|
---|
182 |
|
---|
183 | ALIGN JUMP_ALIGN
|
---|
184 | .JumpToIoFunctionInSI:
|
---|
185 | push bx
|
---|
186 | xor dh, dh
|
---|
187 | eMOVZX bx, BYTE [di+DPT.bIdevarsOffset]; CS:BX now points to IDEVARS
|
---|
188 | ret
|
---|