[473] | 1 | ; Project name : XTIDE Universal BIOS |
---|
[558] | 2 | ; Description : IDE Read/Write functions for transferring block using PIO modes. |
---|
[473] | 3 | ; These functions should only be called from IdeTransfer.asm. |
---|
| 4 | |
---|
| 5 | ; |
---|
| 6 | ; XTIDE Universal BIOS and Associated Tools |
---|
[526] | 7 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team. |
---|
[473] | 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. |
---|
| 13 | ; |
---|
| 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 |
---|
| 17 | ; GNU General Public License for more details. |
---|
| 18 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 19 | ; |
---|
| 20 | |
---|
| 21 | ; Section containing code |
---|
| 22 | SECTION .text |
---|
| 23 | |
---|
[545] | 24 | |
---|
| 25 | ; -------------------------------------------------------------------------------------------------- |
---|
| 26 | ; |
---|
| 27 | ; READ routines follow |
---|
| 28 | ; |
---|
| 29 | ; -------------------------------------------------------------------------------------------------- |
---|
| 30 | |
---|
[473] | 31 | %ifdef MODULE_8BIT_IDE |
---|
| 32 | ;-------------------------------------------------------------------- |
---|
| 33 | ; IdePioBlock_ReadFromXtideRev1 |
---|
| 34 | ; Parameters: |
---|
| 35 | ; CX: Block size in 512 byte sectors |
---|
| 36 | ; DX: IDE Data port address |
---|
| 37 | ; ES:DI: Normalized ptr to buffer to receive data |
---|
| 38 | ; Returns: |
---|
| 39 | ; Nothing |
---|
| 40 | ; Corrupts registers: |
---|
| 41 | ; AX, BX, CX |
---|
| 42 | ;-------------------------------------------------------------------- |
---|
| 43 | ALIGN JUMP_ALIGN |
---|
| 44 | IdePioBlock_ReadFromXtideRev1: |
---|
| 45 | UNROLL_SECTORS_IN_CX_TO_OWORDS |
---|
| 46 | mov bl, 8 ; Bit mask for toggling data low/high reg |
---|
| 47 | ALIGN JUMP_ALIGN |
---|
| 48 | .InswLoop: |
---|
[580] | 49 | %rep 8 ; WORDs |
---|
[473] | 50 | XTIDE_INSW |
---|
| 51 | %endrep |
---|
| 52 | loop .InswLoop |
---|
| 53 | ret |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | ;-------------------------------------------------------------------- |
---|
[545] | 57 | ; 8-bit PIO from a single data port. |
---|
| 58 | ; |
---|
[589] | 59 | ; IdePioBlock_ReadFrom8bitDataPort |
---|
[473] | 60 | ; Parameters: |
---|
[558] | 61 | ; CX: Block size in 512 byte sectors |
---|
| 62 | ; DX: IDE Data port address |
---|
[473] | 63 | ; ES:DI: Normalized ptr to buffer to receive data |
---|
| 64 | ; Returns: |
---|
| 65 | ; Nothing |
---|
| 66 | ; Corrupts registers: |
---|
[589] | 67 | ; AX, CX |
---|
[473] | 68 | ;-------------------------------------------------------------------- |
---|
| 69 | ALIGN JUMP_ALIGN |
---|
[545] | 70 | IdePioBlock_ReadFrom8bitDataPort: |
---|
| 71 | %ifdef USE_186 |
---|
| 72 | shl cx, 9 ; Sectors to BYTEs |
---|
| 73 | rep insb |
---|
| 74 | ret |
---|
[580] | 75 | %else ; 808x |
---|
[473] | 76 | UNROLL_SECTORS_IN_CX_TO_OWORDS |
---|
| 77 | ALIGN JUMP_ALIGN |
---|
| 78 | .ReadNextOword: |
---|
[545] | 79 | %rep 16 ; BYTEs |
---|
| 80 | in al, dx ; Read BYTE |
---|
| 81 | stosb ; Store BYTE to [ES:DI] |
---|
[473] | 82 | %endrep |
---|
[545] | 83 | loop .ReadNextOword |
---|
| 84 | ret |
---|
[473] | 85 | %endif |
---|
[589] | 86 | %endif ; MODULE_8BIT_IDE |
---|
[473] | 87 | |
---|
| 88 | |
---|
| 89 | ;-------------------------------------------------------------------- |
---|
[589] | 90 | ; 16-bit and 32-bit PIO from a single data port. |
---|
| 91 | ; |
---|
[545] | 92 | ; IdePioBlock_ReadFrom16bitDataPort |
---|
[589] | 93 | ; IdePioBlock_ReadFrom32bitDataPort |
---|
[473] | 94 | ; Parameters: |
---|
[558] | 95 | ; CX: Block size in 512 byte sectors |
---|
| 96 | ; DX: IDE Data port address |
---|
[473] | 97 | ; ES:DI: Normalized ptr to buffer to receive data |
---|
| 98 | ; Returns: |
---|
| 99 | ; Nothing |
---|
| 100 | ; Corrupts registers: |
---|
[589] | 101 | ; AX, CX |
---|
[473] | 102 | ;-------------------------------------------------------------------- |
---|
| 103 | ALIGN JUMP_ALIGN |
---|
[545] | 104 | IdePioBlock_ReadFrom16bitDataPort: |
---|
[473] | 105 | %ifdef USE_186 |
---|
[589] | 106 | xchg cl, ch ; Sectors to WORDs |
---|
[545] | 107 | rep insw |
---|
[473] | 108 | ret |
---|
| 109 | |
---|
[580] | 110 | %else ; 808x |
---|
[473] | 111 | UNROLL_SECTORS_IN_CX_TO_OWORDS |
---|
| 112 | ALIGN JUMP_ALIGN |
---|
| 113 | .ReadNextOword: |
---|
[545] | 114 | %rep 8 ; WORDs |
---|
[558] | 115 | in ax, dx ; Read WORD |
---|
| 116 | stosw ; Store WORD to [ES:DI] |
---|
[473] | 117 | %endrep |
---|
| 118 | loop .ReadNextOword |
---|
| 119 | ret |
---|
| 120 | %endif |
---|
| 121 | |
---|
| 122 | |
---|
| 123 | ;-------------------------------------------------------------------- |
---|
[589] | 124 | %ifdef MODULE_ADVANCED_ATA |
---|
[545] | 125 | ALIGN JUMP_ALIGN |
---|
| 126 | IdePioBlock_ReadFrom32bitDataPort: |
---|
[589] | 127 | shl cx, 7 ; Sectors to DWORDs |
---|
| 128 | rep insd |
---|
[545] | 129 | ret |
---|
[589] | 130 | %endif ; MODULE_ADVANCED_ATA |
---|
[545] | 131 | |
---|
| 132 | |
---|
| 133 | ; -------------------------------------------------------------------------------------------------- |
---|
| 134 | ; |
---|
| 135 | ; WRITE routines follow |
---|
| 136 | ; |
---|
| 137 | ; -------------------------------------------------------------------------------------------------- |
---|
| 138 | |
---|
| 139 | %ifdef MODULE_8BIT_IDE |
---|
| 140 | ;-------------------------------------------------------------------- |
---|
[473] | 141 | ; IdePioBlock_WriteToXtideRev1 |
---|
| 142 | ; Parameters: |
---|
[558] | 143 | ; CX: Block size in 512-byte sectors |
---|
| 144 | ; DX: IDE Data port address |
---|
[589] | 145 | ; DS:SI: Normalized ptr to buffer containing data |
---|
[473] | 146 | ; Returns: |
---|
| 147 | ; Nothing |
---|
| 148 | ; Corrupts registers: |
---|
[580] | 149 | ; AX, BX, CX |
---|
[473] | 150 | ;-------------------------------------------------------------------- |
---|
| 151 | ALIGN JUMP_ALIGN |
---|
| 152 | IdePioBlock_WriteToXtideRev1: |
---|
| 153 | UNROLL_SECTORS_IN_CX_TO_QWORDS |
---|
| 154 | mov bl, 8 ; Bit mask for toggling data low/high reg |
---|
| 155 | ALIGN JUMP_ALIGN |
---|
| 156 | .OutswLoop: |
---|
| 157 | %rep 4 ; WORDs |
---|
| 158 | XTIDE_OUTSW |
---|
| 159 | %endrep |
---|
| 160 | loop .OutswLoop |
---|
| 161 | ret |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | ;-------------------------------------------------------------------- |
---|
| 165 | ; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod) |
---|
| 166 | ; Parameters: |
---|
[558] | 167 | ; CX: Block size in 512-byte sectors |
---|
| 168 | ; DX: IDE Data port address |
---|
[589] | 169 | ; DS:SI: Normalized ptr to buffer containing data |
---|
[473] | 170 | ; Returns: |
---|
| 171 | ; Nothing |
---|
| 172 | ; Corrupts registers: |
---|
[589] | 173 | ; AX, CX |
---|
[473] | 174 | ;-------------------------------------------------------------------- |
---|
| 175 | ALIGN JUMP_ALIGN |
---|
| 176 | IdePioBlock_WriteToXtideRev2: |
---|
| 177 | UNROLL_SECTORS_IN_CX_TO_QWORDS |
---|
| 178 | ALIGN JUMP_ALIGN |
---|
| 179 | .WriteNextQword: |
---|
| 180 | %rep 4 ; WORDs |
---|
[580] | 181 | XTIDE_MOD_OUTSW |
---|
[473] | 182 | %endrep |
---|
| 183 | loop .WriteNextQword |
---|
| 184 | ret |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | ;-------------------------------------------------------------------- |
---|
[545] | 188 | ; IdePioBlock_WriteTo8bitDataPort |
---|
[473] | 189 | ; Parameters: |
---|
[558] | 190 | ; CX: Block size in 512-byte sectors |
---|
| 191 | ; DX: IDE Data port address |
---|
[589] | 192 | ; DS:SI: Normalized ptr to buffer containing data |
---|
[473] | 193 | ; Returns: |
---|
| 194 | ; Nothing |
---|
| 195 | ; Corrupts registers: |
---|
[589] | 196 | ; AX, CX |
---|
[473] | 197 | ;-------------------------------------------------------------------- |
---|
| 198 | ALIGN JUMP_ALIGN |
---|
| 199 | IdePioBlock_WriteTo8bitDataPort: |
---|
| 200 | %ifdef USE_186 |
---|
| 201 | shl cx, 9 ; Sectors to BYTEs |
---|
| 202 | rep outsb |
---|
| 203 | ret |
---|
| 204 | |
---|
[580] | 205 | %else ; 808x |
---|
[545] | 206 | UNROLL_SECTORS_IN_CX_TO_QWORDS |
---|
[473] | 207 | ALIGN JUMP_ALIGN |
---|
[545] | 208 | .WriteNextQword: |
---|
| 209 | %rep 8 ; BYTEs |
---|
| 210 | lodsb ; Load BYTE from [DS:SI] |
---|
[580] | 211 | out dx, al ; Write BYTE |
---|
[473] | 212 | %endrep |
---|
[545] | 213 | loop .WriteNextQword |
---|
[473] | 214 | ret |
---|
| 215 | %endif |
---|
| 216 | %endif ; MODULE_8BIT_IDE |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | ;-------------------------------------------------------------------- |
---|
[545] | 220 | ; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode |
---|
[473] | 221 | ; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE |
---|
| 222 | ; Parameters: |
---|
[558] | 223 | ; CX: Block size in 512-byte sectors |
---|
| 224 | ; DX: IDE Data port address |
---|
[589] | 225 | ; DS:SI: Normalized ptr to buffer containing data |
---|
[473] | 226 | ; Returns: |
---|
| 227 | ; Nothing |
---|
| 228 | ; Corrupts registers: |
---|
[589] | 229 | ; AX, CX |
---|
[473] | 230 | ;-------------------------------------------------------------------- |
---|
| 231 | ALIGN JUMP_ALIGN |
---|
| 232 | IdePioBlock_WriteTo16bitDataPort: |
---|
[545] | 233 | %ifdef USE_186 |
---|
[473] | 234 | xchg cl, ch ; Sectors to WORDs |
---|
[545] | 235 | rep outsw |
---|
[473] | 236 | ret |
---|
| 237 | |
---|
[580] | 238 | %else ; 808x |
---|
[545] | 239 | UNROLL_SECTORS_IN_CX_TO_QWORDS |
---|
| 240 | ALIGN JUMP_ALIGN |
---|
| 241 | .WriteNextQword: |
---|
| 242 | %rep 4 ; WORDs |
---|
[558] | 243 | lodsw ; Load WORD from [DS:SI] |
---|
[580] | 244 | out dx, ax ; Write WORD |
---|
[545] | 245 | %endrep |
---|
| 246 | loop .WriteNextQword |
---|
| 247 | ret |
---|
[580] | 248 | %endif |
---|
[545] | 249 | |
---|
[473] | 250 | ;-------------------------------------------------------------------- |
---|
[589] | 251 | %ifdef MODULE_ADVANCED_ATA |
---|
[473] | 252 | ALIGN JUMP_ALIGN |
---|
| 253 | IdePioBlock_WriteTo32bitDataPort: |
---|
[589] | 254 | shl cx, 7 ; Sectors to DWORDs |
---|
| 255 | rep outsd |
---|
[473] | 256 | ret |
---|
[589] | 257 | %endif ; MODULE_ADVANCED_ATA |
---|