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

Last change on this file since 503 was 503, checked in by aitotat@…, 11 years ago

Changes to XTIDE Universal BIOS:

  • Optimized AH=0h a bit.
File size: 6.0 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-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
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     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       
61%ifdef MODULE_8BIT_IDE_ADVANCED
62    cmp     al, DEVICE_8BIT_JRIDE_ISA
63    jne     SHORT .ShlRegisterIndexInDX         ; All XT-CF modes
64    ; Fall to .InputToALfromMemoryMappedRegisterInDX
65
66.InputToALfromMemoryMappedRegisterInDX:
67    push    ds
68    mov     ds, [di+DPT.wBasePort]  ; Segment for JR-IDE/ISA
69    mov     al, [bx+JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET]
70    pop     ds
71    ret
72%endif
73       
74.ReverseA0andA3fromRegisterIndexInDX:
75    mov     dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
76    SKIP2B  bx  ; Skip shl dx, 1
77
78.ShlRegisterIndexInDX:
79    shl     dx, 1
80    ; Fall to .InputToALfromRegisterInDX
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    je      SHORT .ReverseA0andA3fromRegisterIndexInDX
105    jb      SHORT .OutputALtoControlBlockRegisterInDX   ; Standard IDE controllers and XTIDE rev 1
106
107%ifdef MODULE_8BIT_IDE_ADVANCED
108    cmp     bl, DEVICE_8BIT_JRIDE_ISA
109    jne     SHORT .ShlRegisterIndexInDX     ; All XT-CF modes
110    ; Fall to .OutputALtoMemoryMappedRegisterInDX
111
112.OutputALtoMemoryMappedRegisterInDX:
113    mov     bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
114    jmp     SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
115%endif
116
117.ReverseA0andA3fromRegisterIndexInDX:
118    ; We cannot use lookup table since A3 will be always set because
119    ; Control Block Registers start from Command Block + 8h. We can do
120    ; a small trick since we only access Device Control Register at
121    ; offset 6h: Always clear A3 and set A0.
122    add     dx, [cs:bx+IDEVARS.wControlBlockPort]
123    xor     dl, 1001b                       ; Clear A3, Set A0
124    jmp     SHORT OutputALtoPortInDX
125
126.ShlRegisterIndexInDX:
127    shl     dx, 1
128    add     dx, BYTE XTCF_CONTROL_BLOCK_OFFSET
129    jmp     SHORT OutputALtoRegisterInDX
130
131.OutputALtoControlBlockRegisterInDX:
132    call    AccessDPT_GetIdevarsToCSBX
133    add     dx, [cs:bx+IDEVARS.wControlBlockPort]
134    jmp     SHORT OutputALtoPortInDX
135
136
137;--------------------------------------------------------------------
138; IdeIO_OutputALtoIdeRegisterInDL
139;   Parameters:
140;       AL:     Byte to output
141;       DL:     IDE Command Block Register
142;       DS:DI:  Ptr to DPT (in RAMVARS segment)
143;   Returns:
144;       Nothing
145;   Corrupts registers:
146;       BX, DX
147;--------------------------------------------------------------------
148ALIGN JUMP_ALIGN
149IdeIO_OutputALtoIdeRegisterInDL:
150    xor     dh, dh  ; IDE Register index now in DX
151
152    mov     bl, [di+DPT_ATA.bDevice]
153    cmp     bl, DEVICE_8BIT_XTIDE_REV2
154    je      SHORT .ReverseA0andA3fromRegisterIndexInDX
155    jb      SHORT OutputALtoRegisterInDX    ; Standard IDE controllers and XTIDE rev 1
156
157%ifdef MODULE_8BIT_IDE_ADVANCED
158    cmp     bl, DEVICE_8BIT_JRIDE_ISA
159    jne     SHORT .ShlRegisterIndexInDX     ; All XT-CF modes
160    ; Fall to .OutputALtoMemoryMappedRegisterInDX
161
162.OutputALtoMemoryMappedRegisterInDX:
163    mov     bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
164.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
165    add     bx, dx
166    push    ds
167    mov     ds, [di+DPT.wBasePort]  ; Segment for JR-IDE/ISA
168    mov     [bx], al
169    pop     ds
170    ret
171%endif
172
173.ReverseA0andA3fromRegisterIndexInDX:
174    mov     bx, dx
175    mov     dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
176    SKIP2B  bx  ; Skip shl dx, 1
177
178.ShlRegisterIndexInDX:
179    shl     dx, 1
180    ; Fall to OutputALtoRegisterInDX
181
182ALIGN JUMP_ALIGN
183OutputALtoRegisterInDX:
184    add     dx, [di+DPT.wBasePort]
185OutputALtoPortInDX:
186    out     dx, al
187    ret
188
189
190
191; A0 <-> A3 lookup table
192g_rgbSwapA0andA3fromIdeRegisterIndex:
193    db  0000b   ; <-> 0000b, 0
194    db  1000b   ; <-> 0001b, 1
195    db  0010b   ; <-> 0010b, 2
196    db  1010b   ; <-> 0011b, 3
197    db  0100b   ; <-> 0100b, 4
198    db  1100b   ; <-> 0101b, 5
199    db  0110b   ; <-> 0110b, 6
200    db  1110b   ; <-> 0111b, 7
201
202%endif ; MODULE_8BIT_IDE
Note: See TracBrowser for help on using the repository browser.