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

Last change on this file since 257 was 249, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

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