[150] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
[473] | 2 | ; Description : IDE Register I/O functions when supporting 8-bit
|
---|
| 3 | ; devices that need address translations.
|
---|
[150] | 4 |
|
---|
[376] | 5 | ;
|
---|
[412] | 6 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 7 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[376] | 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.
|
---|
[412] | 13 | ;
|
---|
[376] | 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
|
---|
[412] | 17 | ; GNU General Public License for more details.
|
---|
[376] | 18 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
[412] | 19 | ;
|
---|
[376] | 20 |
|
---|
[150] | 21 | ; Section containing code
|
---|
| 22 | SECTION .text
|
---|
| 23 |
|
---|
| 24 | ;--------------------------------------------------------------------
|
---|
[473] | 25 | ; IdeIO_InputStatusRegisterToAL
|
---|
[150] | 26 | ; Parameters:
|
---|
[160] | 27 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
[150] | 28 | ; Returns:
|
---|
[473] | 29 | ; AL: IDE Status Register contents
|
---|
[150] | 30 | ; Corrupts registers:
|
---|
[160] | 31 | ; BX, DX
|
---|
[150] | 32 | ;--------------------------------------------------------------------
|
---|
[473] | 33 | ALIGN JUMP_ALIGN
|
---|
| 34 | IdeIO_InputStatusRegisterToAL:
|
---|
| 35 | %ifndef MODULE_8BIT_IDE
|
---|
| 36 | INPUT_TO_AL_FROM_IDE_REGISTER STATUS_REGISTER_in
|
---|
| 37 | ret
|
---|
[400] | 38 |
|
---|
[473] | 39 | %else
|
---|
| 40 | mov dl, STATUS_REGISTER_in
|
---|
| 41 | ; Fall to IdeIO_InputToALfromIdeRegisterInDL
|
---|
[332] | 42 |
|
---|
[400] | 43 | ;--------------------------------------------------------------------
|
---|
[473] | 44 | ; IdeIO_InputToALfromIdeRegisterInDL
|
---|
[400] | 45 | ; Parameters:
|
---|
[473] | 46 | ; DL: IDE Register
|
---|
[400] | 47 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 48 | ; Returns:
|
---|
[473] | 49 | ; AL: Inputted byte
|
---|
[400] | 50 | ; Corrupts registers:
|
---|
| 51 | ; BX, DX
|
---|
| 52 | ;--------------------------------------------------------------------
|
---|
[473] | 53 | IdeIO_InputToALfromIdeRegisterInDL:
|
---|
[545] | 54 | xor dh, dh ; IDE Register index now in DX...
|
---|
[473] | 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
|
---|
[545] | 58 | mov bx, dx ; ...and BX for A0<->A3 swap and for memory mapped I/O
|
---|
[505] | 59 |
|
---|
[493] | 60 | %ifdef MODULE_8BIT_IDE_ADVANCED
|
---|
[601] | 61 | cmp al, DEVICE_8BIT_XTIDE_REV2_OLIVETTI
|
---|
| 62 | jbe SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
[505] | 63 |
|
---|
[536] | 64 | eSHL_IM dx, 1 ; ADP50L and XT-CF
|
---|
[473] | 65 | cmp al, DEVICE_8BIT_JRIDE_ISA
|
---|
[536] | 66 | jb SHORT .InputToALfromRegisterInDX ; All XT-CF modes
|
---|
| 67 | mov bh, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
|
---|
| 68 | je SHORT .InputToALfromMemoryMappedRegisterInBX
|
---|
| 69 | mov bl, dl
|
---|
[558] | 70 | mov bh, ADP50L_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8
|
---|
[473] | 71 |
|
---|
[536] | 72 | .InputToALfromMemoryMappedRegisterInBX:
|
---|
[473] | 73 | push ds
|
---|
[536] | 74 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA and ADP50L
|
---|
| 75 | mov al, [bx]
|
---|
[473] | 76 | pop ds
|
---|
[150] | 77 | ret
|
---|
[493] | 78 | %endif
|
---|
[505] | 79 |
|
---|
[473] | 80 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
| 81 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
[150] | 82 |
|
---|
[473] | 83 | .InputToALfromRegisterInDX:
|
---|
| 84 | add dx, [di+DPT.wBasePort]
|
---|
| 85 | in al, dx
|
---|
| 86 | ret
|
---|
| 87 |
|
---|
| 88 |
|
---|
[400] | 89 | ;--------------------------------------------------------------------
|
---|
[473] | 90 | ; IdeIO_OutputALtoIdeControlBlockRegisterInDL
|
---|
[150] | 91 | ; Parameters:
|
---|
[473] | 92 | ; AL: Byte to output
|
---|
| 93 | ; DL: IDE Control Block Register
|
---|
[160] | 94 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
[150] | 95 | ; Returns:
|
---|
[473] | 96 | ; Nothing
|
---|
[150] | 97 | ; Corrupts registers:
|
---|
[160] | 98 | ; BX, DX
|
---|
[150] | 99 | ;--------------------------------------------------------------------
|
---|
[473] | 100 | IdeIO_OutputALtoIdeControlBlockRegisterInDL:
|
---|
| 101 | xor dh, dh ; IDE Register index now in DX
|
---|
| 102 | mov bl, [di+DPT_ATA.bDevice]
|
---|
| 103 | cmp bl, DEVICE_8BIT_XTIDE_REV2
|
---|
[501] | 104 | jb SHORT .OutputALtoControlBlockRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
[496] | 105 |
|
---|
[493] | 106 | %ifdef MODULE_8BIT_IDE_ADVANCED
|
---|
[601] | 107 | cmp bl, DEVICE_8BIT_XTIDE_REV2_OLIVETTI
|
---|
| 108 | jbe SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
[505] | 109 |
|
---|
[536] | 110 | ; At this point remaining controllers (JRIDE, XTCF and ADP50L) all have a control
|
---|
| 111 | ; block offset of 8 or (8<<1) so we add 8 here and do the SHL 1 later if needed.
|
---|
[545] | 112 | add dx, BYTE 8
|
---|
[473] | 113 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
[536] | 114 | jb SHORT IdeIO_OutputALtoIdeRegisterInDL.ShlRegisterIndexInDXandOutputAL ; All XT-CF modes
|
---|
| 115 | mov bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET - 8 ; Zeroes BL. -8 compensates for the ADD
|
---|
| 116 | je SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
|
---|
| 117 | ; The commented instructions below shows what happens next (saved for clarity) but as an optimization
|
---|
| 118 | ; we can accomplish the same thing with this jump.
|
---|
| 119 | jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.ShlDXandMovHighByteOfADP50LoffsetsToBH
|
---|
| 120 | ; eSHL_IM dx, 1
|
---|
| 121 | ; mov bh, (ADP50L_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET - 16) >> 8 ; -16 compensates for the ADD and SHL
|
---|
| 122 | ; jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
|
---|
[496] | 123 | %endif
|
---|
[473] | 124 |
|
---|
[501] | 125 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
| 126 | ; We cannot use lookup table since A3 will be always set because
|
---|
| 127 | ; Control Block Registers start from Command Block + 8h. We can do
|
---|
| 128 | ; a small trick since we only access Device Control Register at
|
---|
| 129 | ; offset 6h: Always clear A3 and set A0.
|
---|
[545] | 130 | call AccessDPT_GetIdevarsToCSBX
|
---|
[501] | 131 | add dx, [cs:bx+IDEVARS.wControlBlockPort]
|
---|
| 132 | xor dl, 1001b ; Clear A3, Set A0
|
---|
[536] | 133 | out dx, al
|
---|
| 134 | ret
|
---|
[501] | 135 |
|
---|
[473] | 136 | .OutputALtoControlBlockRegisterInDX:
|
---|
[545] | 137 | call AccessDPT_GetIdevarsToCSBX
|
---|
[473] | 138 | add dx, [cs:bx+IDEVARS.wControlBlockPort]
|
---|
[536] | 139 | out dx, al
|
---|
| 140 | ret
|
---|
[473] | 141 |
|
---|
| 142 |
|
---|
[160] | 143 | ;--------------------------------------------------------------------
|
---|
[473] | 144 | ; IdeIO_OutputALtoIdeRegisterInDL
|
---|
[160] | 145 | ; Parameters:
|
---|
[473] | 146 | ; AL: Byte to output
|
---|
| 147 | ; DL: IDE Command Block Register
|
---|
[160] | 148 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 149 | ; Returns:
|
---|
[473] | 150 | ; Nothing
|
---|
[160] | 151 | ; Corrupts registers:
|
---|
[473] | 152 | ; BX, DX
|
---|
[160] | 153 | ;--------------------------------------------------------------------
|
---|
| 154 | ALIGN JUMP_ALIGN
|
---|
[473] | 155 | IdeIO_OutputALtoIdeRegisterInDL:
|
---|
| 156 | xor dh, dh ; IDE Register index now in DX
|
---|
| 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
|
---|
[493] | 160 |
|
---|
| 161 | %ifdef MODULE_8BIT_IDE_ADVANCED
|
---|
[601] | 162 | cmp bl, DEVICE_8BIT_XTIDE_REV2_OLIVETTI
|
---|
| 163 | jbe SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
[505] | 164 |
|
---|
[473] | 165 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
[536] | 166 | jb SHORT .ShlRegisterIndexInDXandOutputAL ; All XT-CF modes
|
---|
| 167 | mov bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET ; Zeroes BL
|
---|
| 168 | je SHORT .OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
|
---|
| 169 | .ShlDXandMovHighByteOfADP50LoffsetsToBH:
|
---|
| 170 | eSHL_IM dx, 1
|
---|
| 171 | mov bh, ADP50L_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET >> 8 ; BL is zero so we only need to change BH
|
---|
[400] | 172 |
|
---|
[473] | 173 | .OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
|
---|
| 174 | add bx, dx
|
---|
| 175 | push ds
|
---|
[536] | 176 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA and ADP50L
|
---|
[473] | 177 | mov [bx], al
|
---|
| 178 | pop ds
|
---|
[160] | 179 | ret
|
---|
[493] | 180 | %endif
|
---|
[501] | 181 |
|
---|
[473] | 182 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
| 183 | mov bx, dx
|
---|
| 184 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
[536] | 185 | SKIP2B bx ; Skip eSHL_IM dx, 1
|
---|
[473] | 186 |
|
---|
[536] | 187 | .ShlRegisterIndexInDXandOutputAL:
|
---|
[505] | 188 | eSHL_IM dx, 1
|
---|
[473] | 189 | ; Fall to OutputALtoRegisterInDX
|
---|
| 190 |
|
---|
| 191 | ALIGN JUMP_ALIGN
|
---|
| 192 | OutputALtoRegisterInDX:
|
---|
| 193 | add dx, [di+DPT.wBasePort]
|
---|
| 194 | out dx, al
|
---|
[400] | 195 | ret
|
---|
| 196 |
|
---|
[473] | 197 |
|
---|
| 198 |
|
---|
| 199 | ; A0 <-> A3 lookup table
|
---|
| 200 | g_rgbSwapA0andA3fromIdeRegisterIndex:
|
---|
| 201 | db 0000b ; <-> 0000b, 0
|
---|
| 202 | db 1000b ; <-> 0001b, 1
|
---|
| 203 | db 0010b ; <-> 0010b, 2
|
---|
| 204 | db 1010b ; <-> 0011b, 3
|
---|
| 205 | db 0100b ; <-> 0100b, 4
|
---|
| 206 | db 1100b ; <-> 0101b, 5
|
---|
| 207 | db 0110b ; <-> 0110b, 6
|
---|
| 208 | db 1110b ; <-> 0111b, 7
|
---|
| 209 |
|
---|
| 210 | %endif ; MODULE_8BIT_IDE
|
---|