move.py revision 7087:fb8d5786ff30
1# Copyright (c) 2007-2008 The Hewlett-Packard Development Company 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license 9# terms below provided that you ensure that this notice is replicated 10# unmodified and in its entirety in all distributions of the software, 11# modified or unmodified, in source code or in binary form. 12# 13# Redistribution and use in source and binary forms, with or without 14# modification, are permitted provided that the following conditions are 15# met: redistributions of source code must retain the above copyright 16# notice, this list of conditions and the following disclaimer; 17# redistributions in binary form must reproduce the above copyright 18# notice, this list of conditions and the following disclaimer in the 19# documentation and/or other materials provided with the distribution; 20# neither the name of the copyright holders nor the names of its 21# contributors may be used to endorse or promote products derived from 22# this software without specific prior written permission. 23# 24# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 27# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 28# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 30# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 34# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35# 36# Authors: Gabe Black 37 38microcode = ''' 39 40# 41# Regular moves 42# 43 44def macroop MOV_R_MI { 45 limm t1, imm, dataSize=asz 46 ld reg, seg, [1, t0, t1] 47}; 48 49def macroop MOV_MI_R { 50 limm t1, imm, dataSize=asz 51 st reg, seg, [1, t0, t1] 52}; 53 54def macroop MOV_R_R { 55 mov reg, reg, regm 56}; 57 58def macroop MOV_M_R { 59 st reg, seg, sib, disp 60}; 61 62def macroop MOV_P_R { 63 rdip t7 64 st reg, seg, riprel, disp 65}; 66 67def macroop MOV_R_M { 68 ld reg, seg, sib, disp 69}; 70 71def macroop MOV_R_P { 72 rdip t7 73 ld reg, seg, riprel, disp 74}; 75 76def macroop MOV_R_I { 77 limm reg, imm 78}; 79 80def macroop MOV_M_I { 81 limm t1, imm 82 st t1, seg, sib, disp 83}; 84 85def macroop MOV_P_I { 86 rdip t7 87 limm t1, imm 88 st t1, seg, riprel, disp 89}; 90 91# 92# Sign extending moves 93# 94 95def macroop MOVSXD_R_R { 96 sexti reg, regm, 31 97}; 98 99def macroop MOVSXD_R_M { 100 ld t1, seg, sib, disp, dataSize=4 101 sexti reg, t1, 31 102}; 103 104def macroop MOVSXD_R_P { 105 rdip t7 106 ld t1, seg, riprel, disp, dataSize=4 107 sexti reg, t1, 31 108}; 109 110def macroop MOVSX_B_R_R { 111 mov t1, t1, regm, dataSize=1 112 sexti reg, t1, 7 113}; 114 115def macroop MOVSX_B_R_M { 116 ld t1, seg, sib, disp, dataSize=1 117 sexti reg, t1, 7 118}; 119 120def macroop MOVSX_B_R_P { 121 rdip t7 122 ld t1, seg, riprel, disp, dataSize=1 123 sexti reg, t1, 7 124}; 125 126def macroop MOVSX_W_R_R { 127 sexti reg, regm, 15 128}; 129 130def macroop MOVSX_W_R_M { 131 ld reg, seg, sib, disp, dataSize=2 132 sexti reg, reg, 15 133}; 134 135def macroop MOVSX_W_R_P { 136 rdip t7 137 ld reg, seg, riprel, disp, dataSize=2 138 sexti reg, reg, 15 139}; 140 141# 142# Zero extending moves 143# 144 145def macroop MOVZX_B_R_R { 146 mov t1, t1, regm, dataSize=1 147 zexti reg, t1, 7 148}; 149 150def macroop MOVZX_B_R_M { 151 ld t1, seg, sib, disp, dataSize=1 152 zexti reg, t1, 7 153}; 154 155def macroop MOVZX_B_R_P { 156 rdip t7 157 ld t1, seg, riprel, disp, dataSize=1 158 zexti reg, t1, 7 159}; 160 161def macroop MOVZX_W_R_R { 162 zexti reg, regm, 15 163}; 164 165def macroop MOVZX_W_R_M { 166 ld t1, seg, sib, disp, dataSize=2 167 zexti reg, t1, 15 168}; 169 170def macroop MOVZX_W_R_P { 171 rdip t7 172 ld t1, seg, riprel, disp, dataSize=2 173 zexti reg, t1, 15 174}; 175 176def macroop MOV_C_R { 177 .adjust_env maxOsz 178 wrcr reg, regm 179}; 180 181def macroop MOV_R_C { 182 .adjust_env maxOsz 183 rdcr reg, regm 184}; 185 186def macroop MOV_D_R { 187 .adjust_env maxOsz 188 wrdr reg, regm 189}; 190 191def macroop MOV_R_D { 192 .adjust_env maxOsz 193 rddr reg, regm 194}; 195 196def macroop MOV_R_S { 197 rdsel reg, regm 198}; 199 200def macroop MOV_M_S { 201 rdsel t1, reg 202 st t1, seg, sib, disp, dataSize=2 203}; 204 205def macroop MOV_P_S { 206 rdip t7 207 rdsel t1, reg 208 st t1, seg, riprel, disp, dataSize=2 209}; 210 211def macroop MOV_REAL_S_R { 212 zexti t2, regm, 15, dataSize=8 213 slli t3, t2, 4, dataSize=8 214 wrsel reg, regm 215 wrbase reg, t3 216}; 217 218def macroop MOV_REAL_S_M { 219 ld t1, seg, sib, disp, dataSize=2 220 zexti t2, t1, 15, dataSize=8 221 slli t3, t2, 4, dataSize=8 222 wrsel reg, t1 223 wrbase reg, t3 224}; 225 226def macroop MOV_REAL_S_P { 227 panic "RIP relative addressing shouldn't happen in real mode" 228}; 229 230def macroop MOV_S_R { 231 andi t0, regm, 0xFC, flags=(EZF,), dataSize=2 232 br label("processDescriptor"), flags=(CEZF,) 233 andi t2, regm, 0xF8, dataSize=8 234 andi t0, regm, 0x4, flags=(EZF,), dataSize=2 235 br label("globalDescriptor"), flags=(CEZF,) 236 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 237 br label("processDescriptor") 238globalDescriptor: 239 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 240processDescriptor: 241 chks regm, t3, dataSize=8 242 wrdl reg, t3, regm 243 wrsel reg, regm 244}; 245 246def macroop MOV_S_M { 247 ld t1, seg, sib, disp, dataSize=2 248 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 249 br label("processDescriptor"), flags=(CEZF,) 250 andi t2, t1, 0xF8, dataSize=8 251 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 252 br label("globalDescriptor"), flags=(CEZF,) 253 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 254 br label("processDescriptor") 255globalDescriptor: 256 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 257processDescriptor: 258 chks t1, t3, dataSize=8 259 wrdl reg, t3, t1 260 wrsel reg, t1 261}; 262 263def macroop MOV_S_P { 264 rdip t7 265 ld t1, seg, riprel, disp, dataSize=2 266 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 267 br label("processDescriptor"), flags=(CEZF,) 268 andi t2, t1, 0xF8, dataSize=8 269 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 270 br label("globalDescriptor"), flags=(CEZF,) 271 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 272 br label("processDescriptor") 273globalDescriptor: 274 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 275processDescriptor: 276 chks t1, t3, dataSize=8 277 wrdl reg, t3, t1 278 wrsel reg, t1 279}; 280 281def macroop MOVSS_S_R { 282 andi t0, regm, 0xFC, flags=(EZF,), dataSize=2 283 br label("processDescriptor"), flags=(CEZF,) 284 andi t2, regm, 0xF8, dataSize=8 285 andi t0, regm, 0x4, flags=(EZF,), dataSize=2 286 br label("globalDescriptor"), flags=(CEZF,) 287 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 288 br label("processDescriptor") 289globalDescriptor: 290 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 291processDescriptor: 292 chks regm, t3, SSCheck, dataSize=8 293 wrdl reg, t3, regm 294 wrsel reg, regm 295}; 296 297def macroop MOVSS_S_M { 298 ld t1, seg, sib, disp, dataSize=2 299 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 300 br label("processDescriptor"), flags=(CEZF,) 301 andi t2, t1, 0xF8, dataSize=8 302 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 303 br label("globalDescriptor"), flags=(CEZF,) 304 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 305 br label("processDescriptor") 306globalDescriptor: 307 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 308processDescriptor: 309 chks t1, t3, SSCheck, dataSize=8 310 wrdl reg, t3, t1 311 wrsel reg, t1 312}; 313 314def macroop MOVSS_S_P { 315 rdip t7 316 ld t1, seg, riprel, disp, dataSize=2 317 andi t0, t1, 0xFC, flags=(EZF,), dataSize=2 318 br label("processDescriptor"), flags=(CEZF,) 319 andi t2, t1, 0xF8, dataSize=8 320 andi t0, t1, 0x4, flags=(EZF,), dataSize=2 321 br label("globalDescriptor"), flags=(CEZF,) 322 ld t3, tsl, [1, t0, t2], dataSize=8, addressSize=8 323 br label("processDescriptor") 324globalDescriptor: 325 ld t3, tsg, [1, t0, t2], dataSize=8, addressSize=8 326processDescriptor: 327 chks t1, t3, SSCheck, dataSize=8 328 wrdl reg, t3, t1 329 wrsel reg, t1 330}; 331 332def macroop MOVNTI_M_R { 333 st reg, seg, sib, disp 334}; 335 336def macroop MOVNTI_P_R { 337 rdip t7 338 st reg, seg, riprel, disp 339}; 340 341def macroop MOVD_XMM_R { 342 mov2fp xmml, regm, srcSize=dsz, destSize=8 343 lfpimm xmmh, 0 344}; 345 346def macroop MOVD_XMM_M { 347 ldfp xmml, seg, sib, disp, dataSize=dsz 348 lfpimm xmmh, 0 349}; 350 351def macroop MOVD_XMM_P { 352 rdip t7 353 ldfp xmml, seg, riprel, disp, dataSize=dsz 354 lfpimm xmmh, 0 355}; 356 357def macroop MOVD_R_XMM { 358 mov2int reg, xmmlm, size=dsz 359}; 360 361def macroop MOVD_M_XMM { 362 stfp xmml, seg, sib, disp, dataSize=dsz 363}; 364 365def macroop MOVD_P_XMM { 366 rdip t7 367 stfp xmml, seg, riprel, disp, dataSize=dsz 368}; 369 370''' 371#let {{ 372# class MOVD(Inst): 373# "GenFault ${new UnimpInstFault}" 374#}}; 375