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