source: xtideuniversalbios/trunk/XTIDE_Universal_BIOS/Src/Device/IDE/IdeIO.asm@ 469

Last change on this file since 469 was 443, checked in by aitotat@…, 12 years ago

Changes to XTIDE Universal BIOS:

  • Offset to ATA-ID buffer will no longer get corrupted when trying to enable 8-bit mode for XT-CF.
  • Optimized A0<->A3 swapping a bit.
File size: 5.6 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : IDE Register I/O functions.
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; IdeIO_OutputALtoIdeControlBlockRegisterInDL
25; Parameters:
26; AL: Byte to output
27; DL: IDE Control Block Register
28; DS:DI: Ptr to DPT (in RAMVARS segment)
29; Returns:
30; Nothing
31; Corrupts registers:
32; BX, DX
33;--------------------------------------------------------------------
34IdeIO_OutputALtoIdeControlBlockRegisterInDL:
35 %ifdef MODULE_8BIT_IDE
36 mov dh, [di+DPT_ATA.bDevice]
37 %ifdef MODULE_JRIDE
38 test dh, dh
39 jnz SHORT .OutputToIoMappedIde
40
41 add dx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
42 jmp SHORT OutputToJrIdeRegister
43 .OutputToIoMappedIde:
44 %endif ; MODULE_JRIDE
45 %endif ; MODULE_8BIT_IDE
46
47 mov bl, IDEVARS.wPortCtrl
48 jmp SHORT OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL
49
50
51;--------------------------------------------------------------------
52; IdeIO_OutputALtoIdeRegisterInDL
53; Parameters:
54; AL: Byte to output
55; DL: IDE Command Block Register
56; DS:DI: Ptr to DPT (in RAMVARS segment)
57; Returns:
58; Nothing
59; Corrupts registers:
60; BX, DX
61;--------------------------------------------------------------------
62ALIGN JUMP_ALIGN
63IdeIO_OutputALtoIdeRegisterInDL:
64 %ifdef MODULE_8BIT_IDE
65 mov dh, [di+DPT_ATA.bDevice]
66 %ifdef MODULE_JRIDE
67 test dh, dh
68 jnz SHORT OutputALtoIOmappedIdeRegisterInDL
69
70 %if JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET & 0FFh = 0
71 mov dh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
72 %else
73 add dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
74 %endif
75 OutputToJrIdeRegister:
76 mov bx, dx
77 mov [cs:bx], al
78 ret
79 ALIGN JUMP_ALIGN
80 OutputALtoIOmappedIdeRegisterInDL:
81 %endif ; MODULE_JRIDE
82 %endif ; MODULE_8BIT_IDE
83
84 mov bl, IDEVARS.wPort
85OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL:
86 call GetIdePortToDX
87 out dx, al
88 ret
89
90
91;--------------------------------------------------------------------
92; IdeIO_InputStatusRegisterToAL
93; Parameters:
94; DS:DI: Ptr to DPT (in RAMVARS segment)
95; Returns:
96; AL: IDE Status Register contents
97; Corrupts registers:
98; BX, DX
99;--------------------------------------------------------------------
100ALIGN JUMP_ALIGN
101IdeIO_InputStatusRegisterToAL:
102 mov dl, STATUS_REGISTER_in
103 ; Fall to IdeIO_InputToALfromIdeRegisterInDL
104
105;--------------------------------------------------------------------
106; IdeIO_InputToALfromIdeRegisterInDL
107; Parameters:
108; DL: IDE Register
109; DS:DI: Ptr to DPT (in RAMVARS segment)
110; Returns:
111; AL: Inputted byte
112; Corrupts registers:
113; BX, DX
114;--------------------------------------------------------------------
115IdeIO_InputToALfromIdeRegisterInDL:
116 %ifdef MODULE_8BIT_IDE
117 mov dh, [di+DPT_ATA.bDevice]
118 %ifdef MODULE_JRIDE
119 test dh, dh
120 jnz SHORT .InputToALfromIOmappedIdeRegisterInDL
121
122 %if JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET & 0FFh = 0
123 mov dh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
124 %else
125 add dx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
126 %endif
127 mov bx, dx
128 mov al, [cs:bx]
129 ret
130 .InputToALfromIOmappedIdeRegisterInDL:
131 %endif ; MODULE_JRIDE
132 %endif ; MODULE_8BIT_IDE
133 mov bl, IDEVARS.wPort
134 call GetIdePortToDX
135 in al, dx
136 ret
137
138
139;--------------------------------------------------------------------
140; GetIdePortToDX
141; Parameters:
142; BL: Offset to port in IDEVARS (IDEVARS.wPort or IDEVARS.wPortCtrl)
143; DH: Device Type (IDEVARS.bDevice)
144; DL: IDE Register
145; DS:DI: Ptr to DPT (in RAMVARS segment)
146; Returns:
147; DX: Source/Destination Port
148; Corrupts registers:
149; BX
150;--------------------------------------------------------------------
151ALIGN JUMP_ALIGN
152GetIdePortToDX:
153%ifdef MODULE_8BIT_IDE
154 ; Point CS:BX to IDEVARS
155 xor bh, bh
156 add bl, [di+DPT.bIdevarsOffset] ; CS:BX now points port address
157
158 ; Load port address and check if A0 and A3 address lines need to be reversed
159 cmp dh, DEVICE_8BIT_XTIDE_REV1
160 mov dh, bh ; DX now has IDE register offset
161 jae SHORT .ReturnUntranslatedPortInDX ; No need to swap address lines
162
163 ; Exchange address lines A0 and A3 from DL
164 add dx, [cs:bx] ; DX now has port address
165 mov bl, dl ; Port low byte to BL
166 and bl, MASK_A3_AND_A0_ADDRESS_LINES ; Clear all bits except A0 and A3
167 jz SHORT .ReturnTranslatedPortInDX ; A0 and A3 both zeroes, no change needed
168 cmp bl, MASK_A3_AND_A0_ADDRESS_LINES
169 je SHORT .ReturnTranslatedPortInDX ; A0 and A3 both ones, no change needed
170 xor dl, MASK_A3_AND_A0_ADDRESS_LINES ; Invert A0 and A3
171.ReturnTranslatedPortInDX:
172 ret
173
174.ReturnUntranslatedPortInDX:
175 add dx, [cs:bx]
176 ret
177
178%else ; Only standard IDE devices
179 xor bh, bh
180 add bl, [di+DPT.bIdevarsOffset] ; CS:BX now points port address
181 xor dh, dh
182 add dx, [cs:bx] ; DX now has port address
183 ret
184%endif
Note: See TracBrowser for help on using the repository browser.