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

Last change on this file since 420 was 414, checked in by aitotat@…, 13 years ago

Changes to XTIDE Universal BIOS:

  • MEMPIOVARS no longer overflow when not building MODULE_EBIOS.
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
[160]165 mov bl, dl
166 mov bh, MASK_A3_AND_A0_ADDRESS_LINES
[400]167 and bh, bl ; BH = 0, 1, 8 or 9, we can ignore 0 and 9
168 jz SHORT .ReturnTranslatedPortInDX ; Jump out since DH is 0
[160]169 xor bh, MASK_A3_AND_A0_ADDRESS_LINES
[400]170 jz SHORT .ReturnTranslatedPortInDX ; Jump out since DH was 9
[160]171 and dl, ~MASK_A3_AND_A0_ADDRESS_LINES
[400]172 or dl, bh ; Address lines now reversed
173.ReturnTranslatedPortInDX:
[160]174 ret
[400]175
176.ReturnUntranslatedPortInDX:
177 add dx, [cs:bx]
178 ret
179
180%else ; Only standard IDE devices
181 xor bh, bh
[412]182 add bl, [di+DPT.bIdevarsOffset] ; CS:BX now points port address
[400]183 xor dh, dh
[412]184 add dx, [cs:bx] ; DX now has port address
[400]185 ret
186%endif
Note: See TracBrowser for help on using the repository browser.