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

Last change on this file since 384 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
RevLine 
[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
21SECTION .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_DPT_AND_JUMP_IF_JRIDE_DEVICE 1
[268]30 xchg ax, bx
[238]31 eMOVZX bx, [di+DPT.bIdevarsOffset]
32 cmp BYTE [cs:bx+IDEVARS.bDevice], DEVICE_JRIDE_ISA
[268]33 xchg bx, ax ; Restore BX
[238]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
[150]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
[160]49; CS:BP: Ptr to IDEVARS for the controller
[150]50; Returns:
51; Nothing
52; Corrupts registers:
53; AX, BX, CX, DX
54;--------------------------------------------------------------------
[181]55%ifdef MODULE_SERIAL
[150]56Device_FinalizeDPT:
[258]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
[150]59 jmp IdeDPT_Finalize
[294]60.FinalizeDptForSerialPortDevice:
[181]61 jmp SerialDPT_Finalize
[238]62
63%else ; IDE or JR-IDE/ISA
[181]64 Device_FinalizeDPT EQU IdeDPT_Finalize
[175]65%endif
[150]66
[181]67
[150]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;--------------------------------------------------------------------
[238]78%ifdef MODULE_JRIDE
79 %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
80 Device_ResetMasterAndSlaveController:
[294]81 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[238]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
[150]92Device_ResetMasterAndSlaveController:
[294]93 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[181]94 jmp IdeCommand_ResetMasterAndSlaveController
[238]95
96%else ; IDE
[181]97 Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
[175]98%endif
[150]99
[238]100%ifdef MODULE_JRIDE
101.ResetJrIDE:
102 jmp MemIdeCommand_ResetMasterAndSlaveController
103%endif
[150]104
[238]105
[150]106;--------------------------------------------------------------------
107; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
108; Parameters:
109; BH: Drive Select byte for Drive and Head Select Register
110; DS: Segment to RAMVARS
[218]111; ES:SI: Ptr to normalized buffer to receive 512-byte IDE Information
[150]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;--------------------------------------------------------------------
[238]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
[150]133Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
[238]134 CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
[150]135 jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
[181]136
[238]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
[150]147.IdentifyDriveFromSerialPort:
148 jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
[175]149%endif
[150]150
[181]151
[150]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
[218]157; ES:SI: Ptr to normalized buffer (for data transfer commands)
[150]158; DS:DI: Ptr to DPT (in RAMVARS segment)
159; SS:BP: Ptr to IDEPACK
160; Returns:
161; AH: INT 13h Error Code
[249]162; CX: Number of successfully transferred sectors (for transfer commands)
[150]163; CF: Cleared if success, Set if error
164; Corrupts registers:
[249]165; AL, BX, (CX), DX, (ES:SI for data transfer commands)
[150]166;--------------------------------------------------------------------
[238]167%ifdef MODULE_JRIDE
168 %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
169 Device_OutputCommandWithParameters:
[294]170 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
[238]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
[150]181Device_OutputCommandWithParameters:
[294]182 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
[150]183 jmp IdeCommand_OutputWithParameters
[181]184
[238]185%else ; IDE
186 Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
187%endif
188
189%ifdef MODULE_JRIDE
[150]190ALIGN JUMP_ALIGN
[238]191.OutputCommandToJrIDE:
192 jmp MemIdeCommand_OutputWithParameters
193%endif
194
195%ifdef MODULE_SERIAL
196ALIGN JUMP_ALIGN
[150]197.OutputCommandToSerialPort:
198 jmp SerialCommand_OutputWithParameters
[175]199%endif
[150]200
[181]201
[150]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;--------------------------------------------------------------------
[238]213%ifdef MODULE_JRIDE
214 %ifdef MODULE_SERIAL ; IDE + JR-IDE/ISA + Serial
215 Device_SelectDrive:
[294]216 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[238]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
[150]227Device_SelectDrive:
[294]228 TEST_USING_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[150]229 jmp IdeCommand_SelectDrive
[181]230
[238]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
[150]243ReturnSuccessForSerialPort:
244 xor ax, ax
245 ret
[175]246%endif
Note: See TracBrowser for help on using the repository browser.