source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/Device.asm@ 378

Last change on this file since 378 was 376, checked in by gregli@…, 13 years ago

WIDE checkin... Added copyright and license information to sorce files, as per the GPL instructions for usage.

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