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

Last change on this file since 569 was 558, checked in by krille_n_@…, 11 years ago

Changes:

  • Building the BIOS Drive Information Tool now works again.
  • Moved all XT-CF related code to MODULE_8BIT_IDE_ADVANCED. I don't see how an XT-CF card could work without *_ADVANCED anyway but if I'm wrong, feel free to undo this. Note! The autodetection code in XTIDECFG has NOT been changed to reflect this (still relies on MODULE_8BIT_IDE).
  • Optimizations and fixes in general.
File size: 6.8 KB
Line 
1; Project name : XTIDE Universal BIOS
2; Description : IDE Register I/O functions when supporting 8-bit
3; devices that need address translations.
4
5;
6; XTIDE Universal BIOS and Associated Tools
7; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
8;
9; This program is free software; you can redistribute it and/or modify
10; it under the terms of the GNU General Public License as published by
11; the Free Software Foundation; either version 2 of the License, or
12; (at your option) any later version.
13;
14; This program is distributed in the hope that it will be useful,
15; but WITHOUT ANY WARRANTY; without even the implied warranty of
16; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17; GNU General Public License for more details.
18; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19;
20
21; Section containing code
22SECTION .text
23
24;--------------------------------------------------------------------
25; IdeIO_InputStatusRegisterToAL
26; Parameters:
27; DS:DI: Ptr to DPT (in RAMVARS segment)
28; Returns:
29; AL: IDE Status Register contents
30; Corrupts registers:
31; BX, DX
32;--------------------------------------------------------------------
33ALIGN JUMP_ALIGN
34IdeIO_InputStatusRegisterToAL:
35%ifndef MODULE_8BIT_IDE
36 INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
37 ret
38
39%else
40 mov dl, STATUS_REGISTER_in
41 ; Fall to IdeIO_InputToALfromIdeRegisterInDL
42
43;--------------------------------------------------------------------
44; IdeIO_InputToALfromIdeRegisterInDL
45; Parameters:
46; DL: IDE Register
47; DS:DI: Ptr to DPT (in RAMVARS segment)
48; Returns:
49; AL: Inputted byte
50; Corrupts registers:
51; BX, DX
52;--------------------------------------------------------------------
53IdeIO_InputToALfromIdeRegisterInDL:
54 xor dh, dh ; IDE Register index now in DX...
55 mov al, [di+DPT_ATA.bDevice]
56 cmp al, DEVICE_8BIT_XTIDE_REV2
57 jb SHORT .InputToALfromRegisterInDX ; Standard IDE controllers and XTIDE rev 1
58 mov bx, dx ; ...and BX for A0<->A3 swap and for memory mapped I/O
59
60%ifdef MODULE_8BIT_IDE_ADVANCED
61 je SHORT .ReverseA0andA3fromRegisterIndexInDX
62
63 eSHL_IM dx, 1 ; ADP50L and XT-CF
64 cmp al, DEVICE_8BIT_JRIDE_ISA
65 jb SHORT .InputToALfromRegisterInDX ; All XT-CF modes
66 mov bh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
67 je SHORT .InputToALfromMemoryMappedRegisterInBX
68 mov bl, dl
69 mov bh, ADP50L_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
70
71.InputToALfromMemoryMappedRegisterInBX:
72 push ds
73 mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA and ADP50L
74 mov al, [bx]
75 pop ds
76 ret
77%endif
78
79.ReverseA0andA3fromRegisterIndexInDX:
80 mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
81
82.InputToALfromRegisterInDX:
83 add dx, [di+DPT.wBasePort]
84 in al, dx
85 ret
86
87
88;--------------------------------------------------------------------
89; IdeIO_OutputALtoIdeControlBlockRegisterInDL
90; Parameters:
91; AL: Byte to output
92; DL: IDE Control Block Register
93; DS:DI: Ptr to DPT (in RAMVARS segment)
94; Returns:
95; Nothing
96; Corrupts registers:
97; BX, DX
98;--------------------------------------------------------------------
99IdeIO_OutputALtoIdeControlBlockRegisterInDL:
100 xor dh, dh ; IDE Register index now in DX
101
102 mov bl, [di+DPT_ATA.bDevice]
103 cmp bl, DEVICE_8BIT_XTIDE_REV2
104 jb SHORT .OutputALtoControlBlockRegisterInDX ; Standard IDE controllers and XTIDE rev 1
105
106%ifdef MODULE_8BIT_IDE_ADVANCED
107 je SHORT .ReverseA0andA3fromRegisterIndexInDX
108
109 ; At this point remaining controllers (JRIDE, XTCF and ADP50L) all have a control
110 ; block offset of 8 or (8<<1) so we add 8 here and do the SHL 1 later if needed.
111 add dx, BYTE 8
112 cmp bl, DEVICE_8BIT_JRIDE_ISA
113 jb SHORT IdeIO_OutputALtoIdeRegisterInDL.ShlRegisterIndexInDXandOutputAL ; All XT-CF modes
114 mov bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET - 8 ; Zeroes BL. -8 compensates for the ADD
115 je SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
116 ; The commented instructions below shows what happens next (saved for clarity) but as an optimization
117 ; we can accomplish the same thing with this jump.
118 jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.ShlDXandMovHighByteOfADP50LoffsetsToBH
119; eSHL_IM dx, 1
120; mov bh, (ADP50L_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET - 16) >> 8 ; -16 compensates for the ADD and SHL
121; jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
122%endif
123
124.ReverseA0andA3fromRegisterIndexInDX:
125 ; We cannot use lookup table since A3 will be always set because
126 ; Control Block Registers start from Command Block + 8h. We can do
127 ; a small trick since we only access Device Control Register at
128 ; offset 6h: Always clear A3 and set A0.
129 call AccessDPT_GetIdevarsToCSBX
130 add dx, [cs:bx+IDEVARS.wControlBlockPort]
131 xor dl, 1001b ; Clear A3, Set A0
132 out dx, al
133 ret
134
135.OutputALtoControlBlockRegisterInDX:
136 call AccessDPT_GetIdevarsToCSBX
137 add dx, [cs:bx+IDEVARS.wControlBlockPort]
138 out dx, al
139 ret
140
141
142;--------------------------------------------------------------------
143; IdeIO_OutputALtoIdeRegisterInDL
144; Parameters:
145; AL: Byte to output
146; DL: IDE Command Block Register
147; DS:DI: Ptr to DPT (in RAMVARS segment)
148; Returns:
149; Nothing
150; Corrupts registers:
151; BX, DX
152;--------------------------------------------------------------------
153ALIGN JUMP_ALIGN
154IdeIO_OutputALtoIdeRegisterInDL:
155 xor dh, dh ; IDE Register index now in DX
156
157 mov bl, [di+DPT_ATA.bDevice]
158 cmp bl, DEVICE_8BIT_XTIDE_REV2
159 jb SHORT OutputALtoRegisterInDX ; Standard IDE controllers and XTIDE rev 1
160
161%ifdef MODULE_8BIT_IDE_ADVANCED
162 je SHORT .ReverseA0andA3fromRegisterIndexInDX
163
164 cmp bl, DEVICE_8BIT_JRIDE_ISA
165 jb SHORT .ShlRegisterIndexInDXandOutputAL ; All XT-CF modes
166 mov bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET ; Zeroes BL
167 je SHORT .OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
168.ShlDXandMovHighByteOfADP50LoffsetsToBH:
169 eSHL_IM dx, 1
170 mov bh, ADP50L_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8 ; BL is zero so we only need to change BH
171
172.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
173 add bx, dx
174 push ds
175 mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA and ADP50L
176 mov [bx], al
177 pop ds
178 ret
179%endif
180
181.ReverseA0andA3fromRegisterIndexInDX:
182 mov bx, dx
183 mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
184 SKIP2B bx ; Skip eSHL_IM dx, 1
185
186.ShlRegisterIndexInDXandOutputAL:
187 eSHL_IM dx, 1
188 ; Fall to OutputALtoRegisterInDX
189
190ALIGN JUMP_ALIGN
191OutputALtoRegisterInDX:
192 add dx, [di+DPT.wBasePort]
193 out dx, al
194 ret
195
196
197
198; A0 <-> A3 lookup table
199g_rgbSwapA0andA3fromIdeRegisterIndex:
200 db 0000b ; <-> 0000b, 0
201 db 1000b ; <-> 0001b, 1
202 db 0010b ; <-> 0010b, 2
203 db 1010b ; <-> 0011b, 3
204 db 0100b ; <-> 0100b, 4
205 db 1100b ; <-> 0101b, 5
206 db 0110b ; <-> 0110b, 6
207 db 1110b ; <-> 0111b, 7
208
209%endif ; MODULE_8BIT_IDE
Note: See TracBrowser for help on using the repository browser.