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-2012 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
|
---|
22 | SECTION .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 | ;--------------------------------------------------------------------
|
---|
33 | ALIGN JUMP_ALIGN
|
---|
34 | IdeIO_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 | ;--------------------------------------------------------------------
|
---|
53 | IdeIO_InputToALfromIdeRegisterInDL:
|
---|
54 | xor dh, dh ; IDE Register index now in DX
|
---|
55 | mov bx, dx ; and BX
|
---|
56 | mov al, [di+DPT_ATA.bDevice]
|
---|
57 | cmp al, DEVICE_8BIT_XTIDE_REV2
|
---|
58 | je SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
59 | jb SHORT .InputToALfromRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
60 | cmp al, DEVICE_8BIT_JRIDE_ISA
|
---|
61 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
62 | ; Fall to .InputToALfromMemoryMappedRegisterInDX
|
---|
63 |
|
---|
64 | .InputToALfromMemoryMappedRegisterInDX:
|
---|
65 | push ds
|
---|
66 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA
|
---|
67 | mov al, [bx+JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET]
|
---|
68 | pop ds
|
---|
69 | ret
|
---|
70 |
|
---|
71 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
72 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
73 | SKIP2B bx ; Skip shl dx, 1
|
---|
74 |
|
---|
75 | .ShlRegisterIndexInDX:
|
---|
76 | eSHL_IM dx, 1
|
---|
77 | ; Fall to .InputToALfromRegisterInDX
|
---|
78 |
|
---|
79 | .InputToALfromRegisterInDX:
|
---|
80 | add dx, [di+DPT.wBasePort]
|
---|
81 | in al, dx
|
---|
82 | ret
|
---|
83 |
|
---|
84 |
|
---|
85 | ;--------------------------------------------------------------------
|
---|
86 | ; IdeIO_OutputALtoIdeControlBlockRegisterInDL
|
---|
87 | ; Parameters:
|
---|
88 | ; AL: Byte to output
|
---|
89 | ; DL: IDE Control Block Register
|
---|
90 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
91 | ; Returns:
|
---|
92 | ; Nothing
|
---|
93 | ; Corrupts registers:
|
---|
94 | ; BX, DX
|
---|
95 | ;--------------------------------------------------------------------
|
---|
96 | IdeIO_OutputALtoIdeControlBlockRegisterInDL:
|
---|
97 | ; Note! We do not need to reverse A0 and A3 for XTIDE rev 2 since
|
---|
98 | ; the only Control Block Register we access is DEVICE_CONTROL_REGISTER_out
|
---|
99 | ; at offset 6 (0110b).
|
---|
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 | jbe SHORT .OutputALtoControlBlockRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
105 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
106 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
107 | ; Fall to .OutputALtoMemoryMappedRegisterInDX
|
---|
108 |
|
---|
109 | .OutputALtoMemoryMappedRegisterInDX:
|
---|
110 | mov bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
|
---|
111 | jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
|
---|
112 |
|
---|
113 | .ShlRegisterIndexInDX:
|
---|
114 | add dl, OFFSET_TO_CONTROL_BLOCK_REGISTERS
|
---|
115 | eSHL_IM dx, 1
|
---|
116 | jmp SHORT OutputALtoRegisterInDX
|
---|
117 |
|
---|
118 | .OutputALtoControlBlockRegisterInDX:
|
---|
119 | call AccessDPT_GetIdevarsToCSBX
|
---|
120 | add dx, [cs:bx+IDEVARS.wControlBlockPort]
|
---|
121 | jmp SHORT OutputALtoPortInDX
|
---|
122 |
|
---|
123 |
|
---|
124 | ;--------------------------------------------------------------------
|
---|
125 | ; IdeIO_OutputALtoIdeRegisterInDL
|
---|
126 | ; Parameters:
|
---|
127 | ; AL: Byte to output
|
---|
128 | ; DL: IDE Command Block Register
|
---|
129 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
130 | ; Returns:
|
---|
131 | ; Nothing
|
---|
132 | ; Corrupts registers:
|
---|
133 | ; BX, DX
|
---|
134 | ;--------------------------------------------------------------------
|
---|
135 | ALIGN JUMP_ALIGN
|
---|
136 | IdeIO_OutputALtoIdeRegisterInDL:
|
---|
137 | xor dh, dh ; IDE Register index now in DX
|
---|
138 |
|
---|
139 | mov bl, [di+DPT_ATA.bDevice]
|
---|
140 | cmp bl, DEVICE_8BIT_XTIDE_REV2
|
---|
141 | je SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
142 | jb SHORT OutputALtoRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
143 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
144 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
145 | ; Fall to .OutputALtoMemoryMappedRegisterInDX
|
---|
146 |
|
---|
147 | .OutputALtoMemoryMappedRegisterInDX:
|
---|
148 | mov bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
|
---|
149 | .OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
|
---|
150 | add bx, dx
|
---|
151 | push ds
|
---|
152 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA
|
---|
153 | mov [bx], al
|
---|
154 | pop ds
|
---|
155 | ret
|
---|
156 |
|
---|
157 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
158 | mov bx, dx
|
---|
159 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
160 | SKIP2B bx ; Skip shl dx, 1
|
---|
161 |
|
---|
162 | .ShlRegisterIndexInDX:
|
---|
163 | eSHL_IM dx, 1
|
---|
164 | ; Fall to OutputALtoRegisterInDX
|
---|
165 |
|
---|
166 | ALIGN JUMP_ALIGN
|
---|
167 | OutputALtoRegisterInDX:
|
---|
168 | add dx, [di+DPT.wBasePort]
|
---|
169 | OutputALtoPortInDX:
|
---|
170 | out dx, al
|
---|
171 | ret
|
---|
172 |
|
---|
173 |
|
---|
174 |
|
---|
175 | ; A0 <-> A3 lookup table
|
---|
176 | g_rgbSwapA0andA3fromIdeRegisterIndex:
|
---|
177 | db 0000b ; <-> 0000b, 0
|
---|
178 | db 1000b ; <-> 0001b, 1
|
---|
179 | db 0010b ; <-> 0010b, 2
|
---|
180 | db 1010b ; <-> 0011b, 3
|
---|
181 | db 0100b ; <-> 0100b, 4
|
---|
182 | db 1100b ; <-> 0101b, 5
|
---|
183 | db 0110b ; <-> 0110b, 6
|
---|
184 | db 1110b ; <-> 0111b, 7
|
---|
185 |
|
---|
186 | %endif ; MODULE_8BIT_IDE
|
---|