[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
|
---|
[400] | 55 |
|
---|
[473] | 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 | cmp al, DEVICE_8BIT_JRIDE_ISA
|
---|
| 61 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
| 62 | ; Fall to .InputToALfromMemoryMappedRegisterInDX
|
---|
| 63 |
|
---|
| 64 | .InputToALfromMemoryMappedRegisterInDX:
|
---|
| 65 | mov bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
|
---|
| 66 | add bx, dx
|
---|
| 67 | push ds
|
---|
| 68 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA
|
---|
| 69 | mov al, [bx]
|
---|
| 70 | pop ds
|
---|
[150] | 71 | ret
|
---|
| 72 |
|
---|
[473] | 73 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
| 74 | mov bx, dx
|
---|
| 75 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
| 76 | SKIP2B bx ; Skip shl dx, 1
|
---|
[150] | 77 |
|
---|
[473] | 78 | .ShlRegisterIndexInDX:
|
---|
| 79 | shl dx, 1
|
---|
| 80 | ; Fall to .InputToALfromRegisterInDX
|
---|
[400] | 81 |
|
---|
[473] | 82 | .InputToALfromRegisterInDX:
|
---|
| 83 | add dx, [di+DPT.wBasePort]
|
---|
| 84 | in al, dx
|
---|
| 85 | ret
|
---|
| 86 |
|
---|
| 87 |
|
---|
[400] | 88 | ;--------------------------------------------------------------------
|
---|
[473] | 89 | ; IdeIO_OutputALtoIdeControlBlockRegisterInDL
|
---|
[150] | 90 | ; Parameters:
|
---|
[473] | 91 | ; AL: Byte to output
|
---|
| 92 | ; DL: IDE Control Block Register
|
---|
[160] | 93 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
[150] | 94 | ; Returns:
|
---|
[473] | 95 | ; Nothing
|
---|
[150] | 96 | ; Corrupts registers:
|
---|
[160] | 97 | ; BX, DX
|
---|
[150] | 98 | ;--------------------------------------------------------------------
|
---|
[473] | 99 | IdeIO_OutputALtoIdeControlBlockRegisterInDL:
|
---|
| 100 | ; Note! We do not need to reverse A0 and A3 for XTIDE rev 2 since
|
---|
| 101 | ; the only Control Block Register we access is DEVICE_CONTROL_REGISTER_out
|
---|
| 102 | ; at offset 6 (0110b).
|
---|
| 103 | xor dh, dh ; IDE Register index now in DX
|
---|
[160] | 104 |
|
---|
[473] | 105 | mov bl, [di+DPT_ATA.bDevice]
|
---|
| 106 | cmp bl, DEVICE_8BIT_XTIDE_REV2
|
---|
| 107 | jbe SHORT .OutputALtoControlBlockRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
| 108 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
| 109 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
| 110 | ; Fall to .OutputALtoMemoryMappedRegisterInDX
|
---|
[160] | 111 |
|
---|
[473] | 112 | .OutputALtoMemoryMappedRegisterInDX:
|
---|
| 113 | mov bx, JRIDE_CONTROL_BLOCK_REGISTER_WINDOW_OFFSET
|
---|
| 114 | jmp SHORT IdeIO_OutputALtoIdeRegisterInDL.OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX
|
---|
| 115 |
|
---|
| 116 | .ShlRegisterIndexInDX:
|
---|
| 117 | add dl, OFFSET_TO_CONTROL_BLOCK_REGISTERS
|
---|
| 118 | shl dx, 1
|
---|
| 119 | jmp SHORT OutputALtoRegisterInDX
|
---|
| 120 |
|
---|
| 121 | .OutputALtoControlBlockRegisterInDX:
|
---|
| 122 | call AccessDPT_GetIdevarsToCSBX
|
---|
| 123 | add dx, [cs:bx+IDEVARS.wControlBlockPort]
|
---|
| 124 | jmp SHORT OutputALtoPortInDX
|
---|
| 125 |
|
---|
| 126 |
|
---|
[160] | 127 | ;--------------------------------------------------------------------
|
---|
[473] | 128 | ; IdeIO_OutputALtoIdeRegisterInDL
|
---|
[160] | 129 | ; Parameters:
|
---|
[473] | 130 | ; AL: Byte to output
|
---|
| 131 | ; DL: IDE Command Block Register
|
---|
[160] | 132 | ; DS:DI: Ptr to DPT (in RAMVARS segment)
|
---|
| 133 | ; Returns:
|
---|
[473] | 134 | ; Nothing
|
---|
[160] | 135 | ; Corrupts registers:
|
---|
[473] | 136 | ; BX, DX
|
---|
[160] | 137 | ;--------------------------------------------------------------------
|
---|
| 138 | ALIGN JUMP_ALIGN
|
---|
[473] | 139 | IdeIO_OutputALtoIdeRegisterInDL:
|
---|
| 140 | xor dh, dh ; IDE Register index now in DX
|
---|
[160] | 141 |
|
---|
[473] | 142 | mov bl, [di+DPT_ATA.bDevice]
|
---|
| 143 | cmp bl, DEVICE_8BIT_XTIDE_REV2
|
---|
| 144 | je SHORT .ReverseA0andA3fromRegisterIndexInDX
|
---|
| 145 | jb SHORT OutputALtoRegisterInDX ; Standard IDE controllers and XTIDE rev 1
|
---|
| 146 | cmp bl, DEVICE_8BIT_JRIDE_ISA
|
---|
| 147 | jne SHORT .ShlRegisterIndexInDX ; All XT-CF modes
|
---|
| 148 | ; Fall to .OutputALtoMemoryMappedRegisterInDX
|
---|
[400] | 149 |
|
---|
[473] | 150 | .OutputALtoMemoryMappedRegisterInDX:
|
---|
| 151 | mov bx, JRIDE_COMMAND_BLOCK_REGISTER_WINDOW_OFFSET
|
---|
| 152 | .OutputALtoMemoryMappedRegisterInDXwithWindowOffsetInBX:
|
---|
| 153 | add bx, dx
|
---|
| 154 | push ds
|
---|
| 155 | mov ds, [di+DPT.wBasePort] ; Segment for JR-IDE/ISA
|
---|
| 156 | mov [bx], al
|
---|
| 157 | pop ds
|
---|
[160] | 158 | ret
|
---|
[400] | 159 |
|
---|
[473] | 160 | .ReverseA0andA3fromRegisterIndexInDX:
|
---|
| 161 | mov bx, dx
|
---|
| 162 | mov dl, [cs:bx+g_rgbSwapA0andA3fromIdeRegisterIndex]
|
---|
| 163 | SKIP2B bx ; Skip shl dx, 1
|
---|
| 164 |
|
---|
| 165 | .ShlRegisterIndexInDX:
|
---|
| 166 | shl dx, 1
|
---|
| 167 | ; Fall to OutputALtoRegisterInDX
|
---|
| 168 |
|
---|
| 169 | ALIGN JUMP_ALIGN
|
---|
| 170 | OutputALtoRegisterInDX:
|
---|
| 171 | add dx, [di+DPT.wBasePort]
|
---|
| 172 | OutputALtoPortInDX:
|
---|
| 173 | out dx, al
|
---|
[400] | 174 | ret
|
---|
| 175 |
|
---|
[473] | 176 |
|
---|
| 177 |
|
---|
| 178 | ; A0 <-> A3 lookup table
|
---|
| 179 | g_rgbSwapA0andA3fromIdeRegisterIndex:
|
---|
| 180 | db 0000b ; <-> 0000b, 0
|
---|
| 181 | db 1000b ; <-> 0001b, 1
|
---|
| 182 | db 0010b ; <-> 0010b, 2
|
---|
| 183 | db 1010b ; <-> 0011b, 3
|
---|
| 184 | db 0100b ; <-> 0100b, 4
|
---|
| 185 | db 1100b ; <-> 0101b, 5
|
---|
| 186 | db 0110b ; <-> 0110b, 6
|
---|
| 187 | db 1110b ; <-> 0111b, 7
|
---|
| 188 |
|
---|
| 189 | %endif ; MODULE_8BIT_IDE
|
---|