[473] | 1 | ; Project name : XTIDE Universal BIOS
|
---|
| 2 | ; Description : IDE Read/Write functions for transferring
|
---|
| 3 | ; block using PIO modes.
|
---|
| 4 | ; These functions should only be called from IdeTransfer.asm.
|
---|
| 5 |
|
---|
| 6 | ;
|
---|
| 7 | ; XTIDE Universal BIOS and Associated Tools
|
---|
[526] | 8 | ; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
|
---|
[473] | 9 | ;
|
---|
| 10 | ; This program is free software; you can redistribute it and/or modify
|
---|
| 11 | ; it under the terms of the GNU General Public License as published by
|
---|
| 12 | ; the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | ; (at your option) any later version.
|
---|
| 14 | ;
|
---|
| 15 | ; This program is distributed in the hope that it will be useful,
|
---|
| 16 | ; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | ; GNU General Public License for more details.
|
---|
| 19 | ; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
---|
| 20 | ;
|
---|
| 21 |
|
---|
[545] | 22 | ; Modified by JJP for XT-CFv3 support, Mar-13
|
---|
| 23 |
|
---|
[473] | 24 | ; Section containing code
|
---|
| 25 | SECTION .text
|
---|
| 26 |
|
---|
[545] | 27 |
|
---|
| 28 | ; --------------------------------------------------------------------------------------------------
|
---|
| 29 | ;
|
---|
| 30 | ; READ routines follow
|
---|
| 31 | ;
|
---|
| 32 | ; --------------------------------------------------------------------------------------------------
|
---|
| 33 |
|
---|
| 34 |
|
---|
[473] | 35 | %ifdef MODULE_8BIT_IDE
|
---|
| 36 |
|
---|
| 37 | ;--------------------------------------------------------------------
|
---|
| 38 | ; IdePioBlock_ReadFromXtideRev1
|
---|
| 39 | ; Parameters:
|
---|
| 40 | ; CX: Block size in 512 byte sectors
|
---|
| 41 | ; DX: IDE Data port address
|
---|
| 42 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
| 43 | ; Returns:
|
---|
| 44 | ; Nothing
|
---|
| 45 | ; Corrupts registers:
|
---|
| 46 | ; AX, BX, CX
|
---|
| 47 | ;--------------------------------------------------------------------
|
---|
| 48 | ALIGN JUMP_ALIGN
|
---|
| 49 | IdePioBlock_ReadFromXtideRev1:
|
---|
| 50 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
| 51 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
| 52 | ALIGN JUMP_ALIGN
|
---|
| 53 | .InswLoop:
|
---|
| 54 | %rep 8 ; WORDs
|
---|
| 55 | XTIDE_INSW
|
---|
| 56 | %endrep
|
---|
| 57 | loop .InswLoop
|
---|
| 58 | ret
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | ;--------------------------------------------------------------------
|
---|
[545] | 62 | ; IdePioBlock_ReadFrom8bitDataPort
|
---|
| 63 | ;
|
---|
| 64 | ; 8-bit PIO from a single data port.
|
---|
| 65 | ;
|
---|
[473] | 66 | ; Parameters:
|
---|
[545] | 67 | ; CX: Block size in 512 byte sectors
|
---|
| 68 | ; DX: IDE Data port address
|
---|
[473] | 69 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
| 70 | ; Returns:
|
---|
| 71 | ; Nothing
|
---|
| 72 | ; Corrupts registers:
|
---|
| 73 | ; AX, BX, CX
|
---|
| 74 | ;--------------------------------------------------------------------
|
---|
| 75 | ALIGN JUMP_ALIGN
|
---|
[545] | 76 | IdePioBlock_ReadFrom8bitDataPort:
|
---|
| 77 | %ifdef USE_186
|
---|
| 78 | shl cx, 9 ; Sectors to BYTEs
|
---|
| 79 | rep insb
|
---|
| 80 | ret
|
---|
| 81 | %else ; If 8088/8086
|
---|
[473] | 82 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
| 83 | ALIGN JUMP_ALIGN
|
---|
| 84 | .ReadNextOword:
|
---|
[545] | 85 | %rep 16 ; BYTEs
|
---|
| 86 | in al, dx ; Read BYTE
|
---|
| 87 | stosb ; Store BYTE to [ES:DI]
|
---|
[473] | 88 | %endrep
|
---|
[545] | 89 | loop .ReadNextOword
|
---|
| 90 | ret
|
---|
[473] | 91 | %endif
|
---|
| 92 |
|
---|
[545] | 93 | %endif ; MODULE_8BIT_IDE
|
---|
[473] | 94 |
|
---|
[545] | 95 |
|
---|
[473] | 96 | ;--------------------------------------------------------------------
|
---|
[545] | 97 | ; IdePioBlock_ReadFrom16bitDataPort
|
---|
| 98 | ;
|
---|
| 99 | ; 16-bit PIO from a single data port.
|
---|
| 100 | ;
|
---|
[473] | 101 | ; Parameters:
|
---|
[545] | 102 | ; CX: Block size in 512 byte sectors
|
---|
| 103 | ; DX: IDE Data port address
|
---|
[473] | 104 | ; ES:DI: Normalized ptr to buffer to receive data
|
---|
| 105 | ; Returns:
|
---|
| 106 | ; Nothing
|
---|
| 107 | ; Corrupts registers:
|
---|
| 108 | ; AX, BX, CX
|
---|
| 109 | ;--------------------------------------------------------------------
|
---|
| 110 | ALIGN JUMP_ALIGN
|
---|
[545] | 111 | IdePioBlock_ReadFrom16bitDataPort:
|
---|
[473] | 112 | %ifdef USE_186
|
---|
[545] | 113 | xchg cl, ch ; Sectors to WORDs
|
---|
| 114 | rep insw
|
---|
[473] | 115 | ret
|
---|
| 116 |
|
---|
| 117 | %else ; If 8088/8086
|
---|
| 118 | UNROLL_SECTORS_IN_CX_TO_OWORDS
|
---|
| 119 | ALIGN JUMP_ALIGN
|
---|
| 120 | .ReadNextOword:
|
---|
[545] | 121 | %rep 8 ; WORDs
|
---|
| 122 | in ax, dx ; Read BYTE
|
---|
| 123 | stosw ; Store BYTE to [ES:DI]
|
---|
[473] | 124 | %endrep
|
---|
| 125 | loop .ReadNextOword
|
---|
| 126 | ret
|
---|
| 127 | %endif
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | ;--------------------------------------------------------------------
|
---|
[545] | 131 | ALIGN JUMP_ALIGN
|
---|
| 132 | IdePioBlock_ReadFrom32bitDataPort:
|
---|
| 133 | db 0C1h ; SHL
|
---|
| 134 | db 0E1h ; CX
|
---|
| 135 | db 7 ; 7 (Sectors to DWORDs)
|
---|
| 136 | rep
|
---|
| 137 | db 66h ; Override operand size to 32-bit
|
---|
| 138 | db 6Dh ; INSW/INSD
|
---|
| 139 | ret
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|
| 143 | ; --------------------------------------------------------------------------------------------------
|
---|
| 144 | ;
|
---|
| 145 | ; WRITE routines follow
|
---|
| 146 | ;
|
---|
| 147 | ; --------------------------------------------------------------------------------------------------
|
---|
| 148 |
|
---|
| 149 | %ifdef MODULE_8BIT_IDE
|
---|
| 150 |
|
---|
| 151 | ;--------------------------------------------------------------------
|
---|
[473] | 152 | ; IdePioBlock_WriteToXtideRev1
|
---|
| 153 | ; Parameters:
|
---|
[545] | 154 | ; CX: Block size in 512-byte sectors
|
---|
| 155 | ; DX: IDE Data port address
|
---|
[473] | 156 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
| 157 | ; Returns:
|
---|
| 158 | ; Nothing
|
---|
| 159 | ; Corrupts registers:
|
---|
| 160 | ; AX, BX, CX, DX
|
---|
| 161 | ;--------------------------------------------------------------------
|
---|
| 162 | ALIGN JUMP_ALIGN
|
---|
| 163 | IdePioBlock_WriteToXtideRev1:
|
---|
| 164 | push ds
|
---|
| 165 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
| 166 | mov bl, 8 ; Bit mask for toggling data low/high reg
|
---|
| 167 | push es ; Copy ES...
|
---|
| 168 | pop ds ; ...to DS
|
---|
| 169 | ALIGN JUMP_ALIGN
|
---|
| 170 | .OutswLoop:
|
---|
| 171 | %rep 4 ; WORDs
|
---|
| 172 | XTIDE_OUTSW
|
---|
| 173 | %endrep
|
---|
| 174 | loop .OutswLoop
|
---|
| 175 | pop ds
|
---|
| 176 | ret
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | ;--------------------------------------------------------------------
|
---|
| 180 | ; IdePioBlock_WriteToXtideRev2 or rev 1 with swapped A0 and A3 (chuck-mod)
|
---|
| 181 | ; Parameters:
|
---|
[545] | 182 | ; CX: Block size in 512-byte sectors
|
---|
| 183 | ; DX: IDE Data port address
|
---|
[473] | 184 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
| 185 | ; Returns:
|
---|
| 186 | ; Nothing
|
---|
| 187 | ; Corrupts registers:
|
---|
| 188 | ; AX, BX, CX, DX
|
---|
| 189 | ;--------------------------------------------------------------------
|
---|
| 190 | ALIGN JUMP_ALIGN
|
---|
| 191 | IdePioBlock_WriteToXtideRev2:
|
---|
| 192 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
[545] | 193 | push ds
|
---|
| 194 | push es ; Copy ES...
|
---|
| 195 | pop ds ; ...to DS
|
---|
[473] | 196 | ALIGN JUMP_ALIGN
|
---|
| 197 | .WriteNextQword:
|
---|
| 198 | %rep 4 ; WORDs
|
---|
[545] | 199 | XTIDE_MOD_OUTSW ; special macro
|
---|
[473] | 200 | %endrep
|
---|
| 201 | loop .WriteNextQword
|
---|
| 202 | pop ds
|
---|
| 203 | ret
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | ;--------------------------------------------------------------------
|
---|
[545] | 207 | ; IdePioBlock_WriteTo8bitDataPort
|
---|
[473] | 208 | ; Parameters:
|
---|
[545] | 209 | ; CX: Block size in 512-byte sectors
|
---|
| 210 | ; DX: IDE Data port address
|
---|
[473] | 211 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
| 212 | ; Returns:
|
---|
| 213 | ; Nothing
|
---|
| 214 | ; Corrupts registers:
|
---|
| 215 | ; AX, BX, CX, DX
|
---|
| 216 | ;--------------------------------------------------------------------
|
---|
| 217 | ALIGN JUMP_ALIGN
|
---|
| 218 | IdePioBlock_WriteTo8bitDataPort:
|
---|
| 219 | %ifdef USE_186
|
---|
| 220 | shl cx, 9 ; Sectors to BYTEs
|
---|
| 221 | es ; Source is ES segment
|
---|
| 222 | rep outsb
|
---|
| 223 | ret
|
---|
| 224 |
|
---|
| 225 | %else ; If 8088/8086
|
---|
[545] | 226 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
| 227 | push ds
|
---|
| 228 | ;mov ax, es
|
---|
| 229 | ;mov ds, ax ; move es to ds via ax (does this run faster on 8088?)
|
---|
| 230 | push es
|
---|
| 231 | pop ds
|
---|
[473] | 232 | ALIGN JUMP_ALIGN
|
---|
[545] | 233 | .WriteNextQword:
|
---|
| 234 | %rep 8 ; BYTEs
|
---|
| 235 | lodsb ; Load BYTE from [DS:SI]
|
---|
| 236 | out dx, al ; Write BYTE
|
---|
[473] | 237 | %endrep
|
---|
[545] | 238 | loop .WriteNextQword
|
---|
[473] | 239 | pop ds
|
---|
| 240 | ret
|
---|
| 241 | %endif
|
---|
| 242 |
|
---|
| 243 | %endif ; MODULE_8BIT_IDE
|
---|
| 244 |
|
---|
| 245 |
|
---|
| 246 | ;--------------------------------------------------------------------
|
---|
[545] | 247 | ; IdePioBlock_WriteTo16bitDataPort Normal 16-bit IDE, XT-CFv3 in BIU Mode
|
---|
[473] | 248 | ; IdePioBlock_WriteTo32bitDataPort VLB/PCI 32-bit IDE
|
---|
| 249 | ; Parameters:
|
---|
[545] | 250 | ; CX: Block size in 512-byte sectors
|
---|
| 251 | ; DX: IDE Data port address
|
---|
[473] | 252 | ; ES:SI: Normalized ptr to buffer containing data
|
---|
| 253 | ; Returns:
|
---|
| 254 | ; Nothing
|
---|
| 255 | ; Corrupts registers:
|
---|
| 256 | ; AX, BX, CX, DX
|
---|
| 257 | ;--------------------------------------------------------------------
|
---|
| 258 | ALIGN JUMP_ALIGN
|
---|
| 259 | IdePioBlock_WriteTo16bitDataPort:
|
---|
[545] | 260 | %ifdef USE_186
|
---|
[473] | 261 | xchg cl, ch ; Sectors to WORDs
|
---|
| 262 | es ; Source is ES segment
|
---|
[545] | 263 | rep outsw
|
---|
[473] | 264 | ret
|
---|
| 265 |
|
---|
[545] | 266 | %else ; If 8088/8086
|
---|
| 267 | UNROLL_SECTORS_IN_CX_TO_QWORDS
|
---|
| 268 | push ds
|
---|
| 269 | ;mov ax, es
|
---|
| 270 | ;mov ds, ax ; move es to ds via ax (does this run faster on 8088?)
|
---|
| 271 | push es
|
---|
| 272 | pop ds
|
---|
| 273 | ALIGN JUMP_ALIGN
|
---|
| 274 | .WriteNextQword:
|
---|
| 275 | %rep 4 ; WORDs
|
---|
| 276 | lodsw ; Load BYTE from [DS:SI]
|
---|
| 277 | out dx, ax ; Write BYTE
|
---|
| 278 | %endrep
|
---|
| 279 | loop .WriteNextQword
|
---|
| 280 | pop ds
|
---|
| 281 | ret
|
---|
| 282 | %endif ; if/else USE_186
|
---|
| 283 |
|
---|
[473] | 284 | ;--------------------------------------------------------------------
|
---|
| 285 | ALIGN JUMP_ALIGN
|
---|
| 286 | IdePioBlock_WriteTo32bitDataPort:
|
---|
[480] | 287 | db 0C1h ; SHL
|
---|
| 288 | db 0E1h ; CX
|
---|
| 289 | db 7 ; 7 (Sectors to DWORDs)
|
---|
[473] | 290 | es ; Source is ES segment
|
---|
| 291 | rep
|
---|
| 292 | db 66h ; Override operand size to 32-bit
|
---|
| 293 | db 6Fh ; OUTSW/OUTSD
|
---|
| 294 | ret
|
---|