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

Last change on this file since 252 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
RevLine 
[150]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
[238]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
[150]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
[160]31; CS:BP: Ptr to IDEVARS for the controller
[150]32; Returns:
33; Nothing
34; Corrupts registers:
35; AX, BX, CX, DX
36;--------------------------------------------------------------------
[181]37%ifdef MODULE_SERIAL
[150]38Device_FinalizeDPT:
[238]39 TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE .FinalizeDptForSerialPortDevice
[150]40 jmp IdeDPT_Finalize
[175]41.FinalizeDptForSerialPortDevice:
[181]42 jmp SerialDPT_Finalize
[238]43
44%else ; IDE or JR-IDE/ISA
[181]45 Device_FinalizeDPT EQU IdeDPT_Finalize
[175]46%endif
[150]47
[181]48
[150]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;--------------------------------------------------------------------
[238]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
[150]73Device_ResetMasterAndSlaveController:
[238]74 TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[181]75 jmp IdeCommand_ResetMasterAndSlaveController
[238]76
77%else ; IDE
[181]78 Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
[175]79%endif
[150]80
[238]81%ifdef MODULE_JRIDE
82.ResetJrIDE:
83 jmp MemIdeCommand_ResetMasterAndSlaveController
84%endif
[150]85
[238]86
[150]87;--------------------------------------------------------------------
88; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
89; Parameters:
90; BH: Drive Select byte for Drive and Head Select Register
91; DS: Segment to RAMVARS
[218]92; ES:SI: Ptr to normalized buffer to receive 512-byte IDE Information
[150]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;--------------------------------------------------------------------
[238]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
[150]114Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
[238]115 CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
[150]116 jmp IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
[181]117
[238]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
[150]128.IdentifyDriveFromSerialPort:
129 jmp SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
[175]130%endif
[150]131
[181]132
[150]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
[218]138; ES:SI: Ptr to normalized buffer (for data transfer commands)
[150]139; DS:DI: Ptr to DPT (in RAMVARS segment)
140; SS:BP: Ptr to IDEPACK
141; Returns:
142; AH: INT 13h Error Code
[249]143; CX: Number of successfully transferred sectors (for transfer commands)
[150]144; CF: Cleared if success, Set if error
145; Corrupts registers:
[249]146; AL, BX, (CX), DX, (ES:SI for data transfer commands)
[150]147;--------------------------------------------------------------------
[238]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
[150]162Device_OutputCommandWithParameters:
[238]163 TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
[150]164 jmp IdeCommand_OutputWithParameters
[181]165
[238]166%else ; IDE
167 Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
168%endif
169
170%ifdef MODULE_JRIDE
[150]171ALIGN JUMP_ALIGN
[238]172.OutputCommandToJrIDE:
173 jmp MemIdeCommand_OutputWithParameters
174%endif
175
176%ifdef MODULE_SERIAL
177ALIGN JUMP_ALIGN
[150]178.OutputCommandToSerialPort:
179 jmp SerialCommand_OutputWithParameters
[175]180%endif
[150]181
[181]182
[150]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;--------------------------------------------------------------------
[238]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
[150]208Device_SelectDrive:
[238]209 TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
[150]210 jmp IdeCommand_SelectDrive
[181]211
[238]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
[150]224ReturnSuccessForSerialPort:
225 xor ax, ax
226 ret
[175]227%endif
Note: See TracBrowser for help on using the repository browser.