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

Last change on this file since 459 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
RevLine 
[150]1; Project name : XTIDE Universal BIOS
2; Description : IDE Register I/O functions.
3
[376]4;
[412]5; XTIDE Universal BIOS and Associated Tools
[376]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.
[412]12;
[376]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
[412]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[412]18;
[376]19
[150]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
[332]24; IdeIO_OutputALtoIdeControlBlockRegisterInDL
[150]25; Parameters:
26; AL: Byte to output
[400]27; DL: IDE Control Block Register
[160]28; DS:DI: Ptr to DPT (in RAMVARS segment)
[150]29; Returns:
30; Nothing
31; Corrupts registers:
[160]32; BX, DX
[150]33;--------------------------------------------------------------------
[332]34IdeIO_OutputALtoIdeControlBlockRegisterInDL:
[414]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
[400]46
[332]47 mov bl, IDEVARS.wPortCtrl
[400]48 jmp SHORT OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL
[332]49
[400]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
[160]63IdeIO_OutputALtoIdeRegisterInDL:
[414]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
[400]83
[181]84 mov bl, IDEVARS.wPort
[400]85OutputALtoIdeRegisterInDLwithIdevarsOffsetToBasePortInBL:
86 call GetIdePortToDX
[150]87 out dx, al
88 ret
89
90
91;--------------------------------------------------------------------
[400]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;--------------------------------------------------------------------
[160]106; IdeIO_InputToALfromIdeRegisterInDL
[150]107; Parameters:
[160]108; DL: IDE Register
109; DS:DI: Ptr to DPT (in RAMVARS segment)
[150]110; Returns:
111; AL: Inputted byte
112; Corrupts registers:
[160]113; BX, DX
[150]114;--------------------------------------------------------------------
[160]115IdeIO_InputToALfromIdeRegisterInDL:
[414]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
[181]133 mov bl, IDEVARS.wPort
[400]134 call GetIdePortToDX
[150]135 in al, dx
136 ret
[160]137
138
139;--------------------------------------------------------------------
[400]140; GetIdePortToDX
[160]141; Parameters:
[181]142; BL: Offset to port in IDEVARS (IDEVARS.wPort or IDEVARS.wPortCtrl)
[400]143; DH: Device Type (IDEVARS.bDevice)
[160]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
[400]152GetIdePortToDX:
153%ifdef MODULE_8BIT_IDE
154 ; Point CS:BX to IDEVARS
[181]155 xor bh, bh
[400]156 add bl, [di+DPT.bIdevarsOffset] ; CS:BX now points port address
[160]157
[400]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
[160]163 ; Exchange address lines A0 and A3 from DL
[400]164 add dx, [cs:bx] ; DX now has port address
[443]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
[400]171.ReturnTranslatedPortInDX:
[160]172 ret
[400]173
174.ReturnUntranslatedPortInDX:
175 add dx, [cs:bx]
176 ret
177
178%else ; Only standard IDE devices
179 xor bh, bh
[412]180 add bl, [di+DPT.bIdevarsOffset] ; CS:BX now points port address
[400]181 xor dh, dh
[412]182 add dx, [cs:bx] ; DX now has port address
[400]183 ret
184%endif
Note: See TracBrowser for help on using the repository browser.