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

Last change on this file since 258 was 258, checked in by gregli@…, 12 years ago

Added floppy drive emulation over the serial connection (MODULE_SERIAL_FLOPPY). Along the way, various optimizations were made to stay within the 8K ROM size target. Also, serial code now returns the number of sectors transferred.

File size: 7.3 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    ; needs to check IDEVARS vs. checking the DPT as the serial bit in the DPT is set in the Finalize routine
40    CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .FinalizeDptForSerialPortDevice
41    jmp     IdeDPT_Finalize
42.FinalizeDptForSerialPortDevice: 
43    jmp     SerialDPT_Finalize
44
45%else   ; IDE or JR-IDE/ISA
46    Device_FinalizeDPT EQU IdeDPT_Finalize
47%endif
48
49
50;--------------------------------------------------------------------
51; Device_ResetMasterAndSlaveController
52;   Parameters:
53;       DS:DI:  Ptr to DPT (in RAMVARS segment)
54;   Returns:
55;       AH:     INT 13h Error Code
56;       CF:     Cleared if success, Set if error
57;   Corrupts registers:
58;       AL, BX, CX, DX
59;--------------------------------------------------------------------
60%ifdef MODULE_JRIDE
61    %ifdef MODULE_SERIAL                ; IDE + JR-IDE/ISA + Serial
62    Device_ResetMasterAndSlaveController:
63        TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
64        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
65        jmp     IdeCommand_ResetMasterAndSlaveController
66
67    %else                               ; IDE + JR-IDE/ISA
68    Device_ResetMasterAndSlaveController:
69        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .ResetJrIDE
70        jmp     IdeCommand_ResetMasterAndSlaveController
71    %endif
72
73%elifdef MODULE_SERIAL                  ; IDE + Serial
74Device_ResetMasterAndSlaveController:
75    TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
76    jmp     IdeCommand_ResetMasterAndSlaveController
77
78%else                                   ; IDE
79    Device_ResetMasterAndSlaveController EQU IdeCommand_ResetMasterAndSlaveController
80%endif
81
82%ifdef MODULE_JRIDE
83.ResetJrIDE:
84    jmp     MemIdeCommand_ResetMasterAndSlaveController
85%endif
86
87
88;--------------------------------------------------------------------
89; Device_IdentifyToBufferInESSIwithDriveSelectByteInBH
90;   Parameters:
91;       BH:     Drive Select byte for Drive and Head Select Register
92;       DS:     Segment to RAMVARS
93;       ES:SI:  Ptr to normalized buffer to receive 512-byte IDE Information
94;       CS:BP:  Ptr to IDEVARS
95;   Returns:
96;       AH:     INT 13h Error Code
97;       CF:     Cleared if success, Set if error
98;   Corrupts registers:
99;       AL, BL, CX, DX, SI, DI, ES
100;--------------------------------------------------------------------
101%ifdef MODULE_JRIDE
102    %ifdef MODULE_SERIAL                ; IDE + JR-IDE/ISA + Serial
103    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
104        CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
105        CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
106        jmp     IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
107
108    %else                               ; IDE + JR-IDE/ISA
109    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
110        CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_JRIDE_ISA, .IdentifyDriveFromJrIde
111        jmp     IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
112    %endif
113
114%elifdef MODULE_SERIAL                  ; IDE + Serial
115Device_IdentifyToBufferInESSIwithDriveSelectByteInBH:
116    CMP_USING_IDEVARS_IN_CSBP_AND_JUMP_IF DEVICE_SERIAL_PORT, .IdentifyDriveFromSerialPort
117    jmp     IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
118
119%else                                   ; IDE
120    Device_IdentifyToBufferInESSIwithDriveSelectByteInBH EQU IdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
121%endif
122
123%ifdef MODULE_JRIDE
124.IdentifyDriveFromJrIde:
125    jmp     MemIdeCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
126%endif
127
128%ifdef MODULE_SERIAL
129.IdentifyDriveFromSerialPort:
130    jmp     SerialCommand_IdentifyDeviceToBufferInESSIwithDriveSelectByteInBH
131%endif
132
133
134;--------------------------------------------------------------------
135; Device_OutputCommandWithParameters
136;   Parameters:
137;       BH:     Default system timer ticks for timeout (can be ignored)
138;       BL:     IDE Status Register bit to poll after command
139;       ES:SI:  Ptr to normalized buffer (for data transfer commands)
140;       DS:DI:  Ptr to DPT (in RAMVARS segment)
141;       SS:BP:  Ptr to IDEPACK
142;   Returns:
143;       AH:     INT 13h Error Code
144;       CX:     Number of successfully transferred sectors (for transfer commands)
145;       CF:     Cleared if success, Set if error
146;   Corrupts registers:
147;       AL, BX, (CX), DX, (ES:SI for data transfer commands)
148;--------------------------------------------------------------------
149%ifdef MODULE_JRIDE
150    %ifdef MODULE_SERIAL                ; IDE + JR-IDE/ISA + Serial
151    Device_OutputCommandWithParameters:
152        TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
153        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
154        jmp     IdeCommand_OutputWithParameters
155
156    %else                               ; IDE + JR-IDE/ISA
157    Device_OutputCommandWithParameters:
158        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .OutputCommandToJrIDE
159        jmp     IdeCommand_OutputWithParameters
160    %endif
161
162%elifdef MODULE_SERIAL                  ; IDE + Serial
163Device_OutputCommandWithParameters:
164    TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE .OutputCommandToSerialPort
165    jmp     IdeCommand_OutputWithParameters
166
167%else                                   ; IDE
168    Device_OutputCommandWithParameters EQU IdeCommand_OutputWithParameters
169%endif
170
171%ifdef MODULE_JRIDE
172ALIGN JUMP_ALIGN
173.OutputCommandToJrIDE:
174    jmp     MemIdeCommand_OutputWithParameters
175%endif
176
177%ifdef MODULE_SERIAL
178ALIGN JUMP_ALIGN
179.OutputCommandToSerialPort:
180    jmp     SerialCommand_OutputWithParameters
181%endif
182
183
184;--------------------------------------------------------------------
185; Device_SelectDrive
186;   Parameters:
187;       DS:DI:  Ptr to DPT (in RAMVARS segment)
188;       SS:BP:  Ptr to IDEPACK
189;   Returns:
190;       AH:     INT 13h Error Code
191;       CF:     Cleared if success, Set if error
192;   Corrupts registers:
193;       AL, BX, CX, DX
194;--------------------------------------------------------------------
195%ifdef MODULE_JRIDE
196    %ifdef MODULE_SERIAL                ; IDE + JR-IDE/ISA + Serial
197    Device_SelectDrive:
198        TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
199        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
200        jmp     IdeCommand_SelectDrive
201
202    %else                               ; IDE + JR-IDE/ISA
203    Device_SelectDrive:
204        CMP_USING_DPT_AND_JUMP_IF_JRIDE_DEVICE .SelectJrIdeDrive
205        jmp     IdeCommand_SelectDrive
206    %endif
207
208%elifdef MODULE_SERIAL                  ; IDE + Serial
209Device_SelectDrive:
210    TEST_USIGN_DPT_AND_JUMP_IF_SERIAL_DEVICE ReturnSuccessForSerialPort
211    jmp     IdeCommand_SelectDrive
212
213%else                                   ; IDE
214    Device_SelectDrive EQU IdeCommand_SelectDrive
215%endif
216
217%ifdef MODULE_JRIDE
218ALIGN JUMP_ALIGN
219.SelectJrIdeDrive:
220    jmp     MemIdeCommand_SelectDrive
221%endif
222
223%ifdef MODULE_SERIAL
224ALIGN JUMP_ALIGN
225ReturnSuccessForSerialPort:
226    xor     ax, ax
227    ret
228%endif
Note: See TracBrowser for help on using the repository browser.