1fcf5ef2aSThomas Huth /* 2fcf5ef2aSThomas Huth * SH4 translation 3fcf5ef2aSThomas Huth * 4fcf5ef2aSThomas Huth * Copyright (c) 2005 Samuel Tardieu 5fcf5ef2aSThomas Huth * 6fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or 7fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public 8fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either 9fcf5ef2aSThomas Huth * version 2 of the License, or (at your option) any later version. 10fcf5ef2aSThomas Huth * 11fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful, 12fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of 13fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14fcf5ef2aSThomas Huth * Lesser General Public License for more details. 15fcf5ef2aSThomas Huth * 16fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public 17fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>. 18fcf5ef2aSThomas Huth */ 19fcf5ef2aSThomas Huth 20fcf5ef2aSThomas Huth #define DEBUG_DISAS 21fcf5ef2aSThomas Huth 22fcf5ef2aSThomas Huth #include "qemu/osdep.h" 23fcf5ef2aSThomas Huth #include "cpu.h" 24fcf5ef2aSThomas Huth #include "disas/disas.h" 25fcf5ef2aSThomas Huth #include "exec/exec-all.h" 26fcf5ef2aSThomas Huth #include "tcg-op.h" 27fcf5ef2aSThomas Huth #include "exec/cpu_ldst.h" 28fcf5ef2aSThomas Huth 29fcf5ef2aSThomas Huth #include "exec/helper-proto.h" 30fcf5ef2aSThomas Huth #include "exec/helper-gen.h" 31fcf5ef2aSThomas Huth 32fcf5ef2aSThomas Huth #include "trace-tcg.h" 33fcf5ef2aSThomas Huth #include "exec/log.h" 34fcf5ef2aSThomas Huth 35fcf5ef2aSThomas Huth 36fcf5ef2aSThomas Huth typedef struct DisasContext { 37fcf5ef2aSThomas Huth struct TranslationBlock *tb; 38fcf5ef2aSThomas Huth target_ulong pc; 39fcf5ef2aSThomas Huth uint16_t opcode; 40a6215749SAurelien Jarno uint32_t tbflags; /* should stay unmodified during the TB translation */ 41a6215749SAurelien Jarno uint32_t envflags; /* should stay in sync with env->flags using TCG ops */ 42fcf5ef2aSThomas Huth int bstate; 43fcf5ef2aSThomas Huth int memidx; 443a3bb8d2SRichard Henderson int gbank; 455c13bad9SRichard Henderson int fbank; 46fcf5ef2aSThomas Huth uint32_t delayed_pc; 47fcf5ef2aSThomas Huth int singlestep_enabled; 48fcf5ef2aSThomas Huth uint32_t features; 49fcf5ef2aSThomas Huth int has_movcal; 50fcf5ef2aSThomas Huth } DisasContext; 51fcf5ef2aSThomas Huth 52fcf5ef2aSThomas Huth #if defined(CONFIG_USER_ONLY) 53fcf5ef2aSThomas Huth #define IS_USER(ctx) 1 54fcf5ef2aSThomas Huth #else 55a6215749SAurelien Jarno #define IS_USER(ctx) (!(ctx->tbflags & (1u << SR_MD))) 56fcf5ef2aSThomas Huth #endif 57fcf5ef2aSThomas Huth 58fcf5ef2aSThomas Huth enum { 59fcf5ef2aSThomas Huth BS_NONE = 0, /* We go out of the TB without reaching a branch or an 60fcf5ef2aSThomas Huth * exception condition 61fcf5ef2aSThomas Huth */ 62fcf5ef2aSThomas Huth BS_STOP = 1, /* We want to stop translation for any reason */ 63fcf5ef2aSThomas Huth BS_BRANCH = 2, /* We reached a branch condition */ 64fcf5ef2aSThomas Huth BS_EXCP = 3, /* We reached an exception condition */ 65fcf5ef2aSThomas Huth }; 66fcf5ef2aSThomas Huth 67fcf5ef2aSThomas Huth /* global register indexes */ 68fcf5ef2aSThomas Huth static TCGv_env cpu_env; 693a3bb8d2SRichard Henderson static TCGv cpu_gregs[32]; 70fcf5ef2aSThomas Huth static TCGv cpu_sr, cpu_sr_m, cpu_sr_q, cpu_sr_t; 71fcf5ef2aSThomas Huth static TCGv cpu_pc, cpu_ssr, cpu_spc, cpu_gbr; 72fcf5ef2aSThomas Huth static TCGv cpu_vbr, cpu_sgr, cpu_dbr, cpu_mach, cpu_macl; 73fcf5ef2aSThomas Huth static TCGv cpu_pr, cpu_fpscr, cpu_fpul, cpu_ldst; 74fcf5ef2aSThomas Huth static TCGv cpu_fregs[32]; 75fcf5ef2aSThomas Huth 76fcf5ef2aSThomas Huth /* internal register indexes */ 7747b9f4d5SAurelien Jarno static TCGv cpu_flags, cpu_delayed_pc, cpu_delayed_cond; 78fcf5ef2aSThomas Huth 79fcf5ef2aSThomas Huth #include "exec/gen-icount.h" 80fcf5ef2aSThomas Huth 81fcf5ef2aSThomas Huth void sh4_translate_init(void) 82fcf5ef2aSThomas Huth { 83fcf5ef2aSThomas Huth int i; 84fcf5ef2aSThomas Huth static int done_init = 0; 85fcf5ef2aSThomas Huth static const char * const gregnames[24] = { 86fcf5ef2aSThomas Huth "R0_BANK0", "R1_BANK0", "R2_BANK0", "R3_BANK0", 87fcf5ef2aSThomas Huth "R4_BANK0", "R5_BANK0", "R6_BANK0", "R7_BANK0", 88fcf5ef2aSThomas Huth "R8", "R9", "R10", "R11", "R12", "R13", "R14", "R15", 89fcf5ef2aSThomas Huth "R0_BANK1", "R1_BANK1", "R2_BANK1", "R3_BANK1", 90fcf5ef2aSThomas Huth "R4_BANK1", "R5_BANK1", "R6_BANK1", "R7_BANK1" 91fcf5ef2aSThomas Huth }; 92fcf5ef2aSThomas Huth static const char * const fregnames[32] = { 93fcf5ef2aSThomas Huth "FPR0_BANK0", "FPR1_BANK0", "FPR2_BANK0", "FPR3_BANK0", 94fcf5ef2aSThomas Huth "FPR4_BANK0", "FPR5_BANK0", "FPR6_BANK0", "FPR7_BANK0", 95fcf5ef2aSThomas Huth "FPR8_BANK0", "FPR9_BANK0", "FPR10_BANK0", "FPR11_BANK0", 96fcf5ef2aSThomas Huth "FPR12_BANK0", "FPR13_BANK0", "FPR14_BANK0", "FPR15_BANK0", 97fcf5ef2aSThomas Huth "FPR0_BANK1", "FPR1_BANK1", "FPR2_BANK1", "FPR3_BANK1", 98fcf5ef2aSThomas Huth "FPR4_BANK1", "FPR5_BANK1", "FPR6_BANK1", "FPR7_BANK1", 99fcf5ef2aSThomas Huth "FPR8_BANK1", "FPR9_BANK1", "FPR10_BANK1", "FPR11_BANK1", 100fcf5ef2aSThomas Huth "FPR12_BANK1", "FPR13_BANK1", "FPR14_BANK1", "FPR15_BANK1", 101fcf5ef2aSThomas Huth }; 102fcf5ef2aSThomas Huth 1033a3bb8d2SRichard Henderson if (done_init) { 104fcf5ef2aSThomas Huth return; 1053a3bb8d2SRichard Henderson } 106fcf5ef2aSThomas Huth 107fcf5ef2aSThomas Huth cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); 108fcf5ef2aSThomas Huth tcg_ctx.tcg_env = cpu_env; 109fcf5ef2aSThomas Huth 1103a3bb8d2SRichard Henderson for (i = 0; i < 24; i++) { 111fcf5ef2aSThomas Huth cpu_gregs[i] = tcg_global_mem_new_i32(cpu_env, 112fcf5ef2aSThomas Huth offsetof(CPUSH4State, gregs[i]), 113fcf5ef2aSThomas Huth gregnames[i]); 1143a3bb8d2SRichard Henderson } 1153a3bb8d2SRichard Henderson memcpy(cpu_gregs + 24, cpu_gregs + 8, 8 * sizeof(TCGv)); 116fcf5ef2aSThomas Huth 117fcf5ef2aSThomas Huth cpu_pc = tcg_global_mem_new_i32(cpu_env, 118fcf5ef2aSThomas Huth offsetof(CPUSH4State, pc), "PC"); 119fcf5ef2aSThomas Huth cpu_sr = tcg_global_mem_new_i32(cpu_env, 120fcf5ef2aSThomas Huth offsetof(CPUSH4State, sr), "SR"); 121fcf5ef2aSThomas Huth cpu_sr_m = tcg_global_mem_new_i32(cpu_env, 122fcf5ef2aSThomas Huth offsetof(CPUSH4State, sr_m), "SR_M"); 123fcf5ef2aSThomas Huth cpu_sr_q = tcg_global_mem_new_i32(cpu_env, 124fcf5ef2aSThomas Huth offsetof(CPUSH4State, sr_q), "SR_Q"); 125fcf5ef2aSThomas Huth cpu_sr_t = tcg_global_mem_new_i32(cpu_env, 126fcf5ef2aSThomas Huth offsetof(CPUSH4State, sr_t), "SR_T"); 127fcf5ef2aSThomas Huth cpu_ssr = tcg_global_mem_new_i32(cpu_env, 128fcf5ef2aSThomas Huth offsetof(CPUSH4State, ssr), "SSR"); 129fcf5ef2aSThomas Huth cpu_spc = tcg_global_mem_new_i32(cpu_env, 130fcf5ef2aSThomas Huth offsetof(CPUSH4State, spc), "SPC"); 131fcf5ef2aSThomas Huth cpu_gbr = tcg_global_mem_new_i32(cpu_env, 132fcf5ef2aSThomas Huth offsetof(CPUSH4State, gbr), "GBR"); 133fcf5ef2aSThomas Huth cpu_vbr = tcg_global_mem_new_i32(cpu_env, 134fcf5ef2aSThomas Huth offsetof(CPUSH4State, vbr), "VBR"); 135fcf5ef2aSThomas Huth cpu_sgr = tcg_global_mem_new_i32(cpu_env, 136fcf5ef2aSThomas Huth offsetof(CPUSH4State, sgr), "SGR"); 137fcf5ef2aSThomas Huth cpu_dbr = tcg_global_mem_new_i32(cpu_env, 138fcf5ef2aSThomas Huth offsetof(CPUSH4State, dbr), "DBR"); 139fcf5ef2aSThomas Huth cpu_mach = tcg_global_mem_new_i32(cpu_env, 140fcf5ef2aSThomas Huth offsetof(CPUSH4State, mach), "MACH"); 141fcf5ef2aSThomas Huth cpu_macl = tcg_global_mem_new_i32(cpu_env, 142fcf5ef2aSThomas Huth offsetof(CPUSH4State, macl), "MACL"); 143fcf5ef2aSThomas Huth cpu_pr = tcg_global_mem_new_i32(cpu_env, 144fcf5ef2aSThomas Huth offsetof(CPUSH4State, pr), "PR"); 145fcf5ef2aSThomas Huth cpu_fpscr = tcg_global_mem_new_i32(cpu_env, 146fcf5ef2aSThomas Huth offsetof(CPUSH4State, fpscr), "FPSCR"); 147fcf5ef2aSThomas Huth cpu_fpul = tcg_global_mem_new_i32(cpu_env, 148fcf5ef2aSThomas Huth offsetof(CPUSH4State, fpul), "FPUL"); 149fcf5ef2aSThomas Huth 150fcf5ef2aSThomas Huth cpu_flags = tcg_global_mem_new_i32(cpu_env, 151fcf5ef2aSThomas Huth offsetof(CPUSH4State, flags), "_flags_"); 152fcf5ef2aSThomas Huth cpu_delayed_pc = tcg_global_mem_new_i32(cpu_env, 153fcf5ef2aSThomas Huth offsetof(CPUSH4State, delayed_pc), 154fcf5ef2aSThomas Huth "_delayed_pc_"); 15547b9f4d5SAurelien Jarno cpu_delayed_cond = tcg_global_mem_new_i32(cpu_env, 15647b9f4d5SAurelien Jarno offsetof(CPUSH4State, 15747b9f4d5SAurelien Jarno delayed_cond), 15847b9f4d5SAurelien Jarno "_delayed_cond_"); 159fcf5ef2aSThomas Huth cpu_ldst = tcg_global_mem_new_i32(cpu_env, 160fcf5ef2aSThomas Huth offsetof(CPUSH4State, ldst), "_ldst_"); 161fcf5ef2aSThomas Huth 162fcf5ef2aSThomas Huth for (i = 0; i < 32; i++) 163fcf5ef2aSThomas Huth cpu_fregs[i] = tcg_global_mem_new_i32(cpu_env, 164fcf5ef2aSThomas Huth offsetof(CPUSH4State, fregs[i]), 165fcf5ef2aSThomas Huth fregnames[i]); 166fcf5ef2aSThomas Huth 167fcf5ef2aSThomas Huth done_init = 1; 168fcf5ef2aSThomas Huth } 169fcf5ef2aSThomas Huth 170fcf5ef2aSThomas Huth void superh_cpu_dump_state(CPUState *cs, FILE *f, 171fcf5ef2aSThomas Huth fprintf_function cpu_fprintf, int flags) 172fcf5ef2aSThomas Huth { 173fcf5ef2aSThomas Huth SuperHCPU *cpu = SUPERH_CPU(cs); 174fcf5ef2aSThomas Huth CPUSH4State *env = &cpu->env; 175fcf5ef2aSThomas Huth int i; 176fcf5ef2aSThomas Huth cpu_fprintf(f, "pc=0x%08x sr=0x%08x pr=0x%08x fpscr=0x%08x\n", 177fcf5ef2aSThomas Huth env->pc, cpu_read_sr(env), env->pr, env->fpscr); 178fcf5ef2aSThomas Huth cpu_fprintf(f, "spc=0x%08x ssr=0x%08x gbr=0x%08x vbr=0x%08x\n", 179fcf5ef2aSThomas Huth env->spc, env->ssr, env->gbr, env->vbr); 180fcf5ef2aSThomas Huth cpu_fprintf(f, "sgr=0x%08x dbr=0x%08x delayed_pc=0x%08x fpul=0x%08x\n", 181fcf5ef2aSThomas Huth env->sgr, env->dbr, env->delayed_pc, env->fpul); 182fcf5ef2aSThomas Huth for (i = 0; i < 24; i += 4) { 183fcf5ef2aSThomas Huth cpu_fprintf(f, "r%d=0x%08x r%d=0x%08x r%d=0x%08x r%d=0x%08x\n", 184fcf5ef2aSThomas Huth i, env->gregs[i], i + 1, env->gregs[i + 1], 185fcf5ef2aSThomas Huth i + 2, env->gregs[i + 2], i + 3, env->gregs[i + 3]); 186fcf5ef2aSThomas Huth } 187fcf5ef2aSThomas Huth if (env->flags & DELAY_SLOT) { 188fcf5ef2aSThomas Huth cpu_fprintf(f, "in delay slot (delayed_pc=0x%08x)\n", 189fcf5ef2aSThomas Huth env->delayed_pc); 190fcf5ef2aSThomas Huth } else if (env->flags & DELAY_SLOT_CONDITIONAL) { 191fcf5ef2aSThomas Huth cpu_fprintf(f, "in conditional delay slot (delayed_pc=0x%08x)\n", 192fcf5ef2aSThomas Huth env->delayed_pc); 193be53081aSAurelien Jarno } else if (env->flags & DELAY_SLOT_RTE) { 194be53081aSAurelien Jarno cpu_fprintf(f, "in rte delay slot (delayed_pc=0x%08x)\n", 195be53081aSAurelien Jarno env->delayed_pc); 196fcf5ef2aSThomas Huth } 197fcf5ef2aSThomas Huth } 198fcf5ef2aSThomas Huth 199fcf5ef2aSThomas Huth static void gen_read_sr(TCGv dst) 200fcf5ef2aSThomas Huth { 201fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 202fcf5ef2aSThomas Huth tcg_gen_shli_i32(t0, cpu_sr_q, SR_Q); 203fcf5ef2aSThomas Huth tcg_gen_or_i32(dst, dst, t0); 204fcf5ef2aSThomas Huth tcg_gen_shli_i32(t0, cpu_sr_m, SR_M); 205fcf5ef2aSThomas Huth tcg_gen_or_i32(dst, dst, t0); 206fcf5ef2aSThomas Huth tcg_gen_shli_i32(t0, cpu_sr_t, SR_T); 207fcf5ef2aSThomas Huth tcg_gen_or_i32(dst, cpu_sr, t0); 208fcf5ef2aSThomas Huth tcg_temp_free_i32(t0); 209fcf5ef2aSThomas Huth } 210fcf5ef2aSThomas Huth 211fcf5ef2aSThomas Huth static void gen_write_sr(TCGv src) 212fcf5ef2aSThomas Huth { 213fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr, src, 214fcf5ef2aSThomas Huth ~((1u << SR_Q) | (1u << SR_M) | (1u << SR_T))); 215a380f9dbSAurelien Jarno tcg_gen_extract_i32(cpu_sr_q, src, SR_Q, 1); 216a380f9dbSAurelien Jarno tcg_gen_extract_i32(cpu_sr_m, src, SR_M, 1); 217a380f9dbSAurelien Jarno tcg_gen_extract_i32(cpu_sr_t, src, SR_T, 1); 218fcf5ef2aSThomas Huth } 219fcf5ef2aSThomas Huth 220ac9707eaSAurelien Jarno static inline void gen_save_cpu_state(DisasContext *ctx, bool save_pc) 221ac9707eaSAurelien Jarno { 222ac9707eaSAurelien Jarno if (save_pc) { 223ac9707eaSAurelien Jarno tcg_gen_movi_i32(cpu_pc, ctx->pc); 224ac9707eaSAurelien Jarno } 225ac9707eaSAurelien Jarno if (ctx->delayed_pc != (uint32_t) -1) { 226ac9707eaSAurelien Jarno tcg_gen_movi_i32(cpu_delayed_pc, ctx->delayed_pc); 227ac9707eaSAurelien Jarno } 228e1933d14SRichard Henderson if ((ctx->tbflags & TB_FLAG_ENVFLAGS_MASK) != ctx->envflags) { 229ac9707eaSAurelien Jarno tcg_gen_movi_i32(cpu_flags, ctx->envflags); 230ac9707eaSAurelien Jarno } 231ac9707eaSAurelien Jarno } 232ac9707eaSAurelien Jarno 233fcf5ef2aSThomas Huth static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) 234fcf5ef2aSThomas Huth { 235fcf5ef2aSThomas Huth if (unlikely(ctx->singlestep_enabled)) { 236fcf5ef2aSThomas Huth return false; 237fcf5ef2aSThomas Huth } 2384bfa602bSRichard Henderson if (ctx->tbflags & GUSA_EXCLUSIVE) { 2394bfa602bSRichard Henderson return false; 2404bfa602bSRichard Henderson } 241fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY 242fcf5ef2aSThomas Huth return (ctx->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); 243fcf5ef2aSThomas Huth #else 244fcf5ef2aSThomas Huth return true; 245fcf5ef2aSThomas Huth #endif 246fcf5ef2aSThomas Huth } 247fcf5ef2aSThomas Huth 248fcf5ef2aSThomas Huth static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) 249fcf5ef2aSThomas Huth { 250fcf5ef2aSThomas Huth if (use_goto_tb(ctx, dest)) { 251fcf5ef2aSThomas Huth /* Use a direct jump if in same page and singlestep not enabled */ 252fcf5ef2aSThomas Huth tcg_gen_goto_tb(n); 253fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pc, dest); 254fcf5ef2aSThomas Huth tcg_gen_exit_tb((uintptr_t)ctx->tb + n); 255fcf5ef2aSThomas Huth } else { 256fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pc, dest); 257fcf5ef2aSThomas Huth if (ctx->singlestep_enabled) 258fcf5ef2aSThomas Huth gen_helper_debug(cpu_env); 259fcf5ef2aSThomas Huth tcg_gen_exit_tb(0); 260fcf5ef2aSThomas Huth } 261fcf5ef2aSThomas Huth } 262fcf5ef2aSThomas Huth 263fcf5ef2aSThomas Huth static void gen_jump(DisasContext * ctx) 264fcf5ef2aSThomas Huth { 265fcf5ef2aSThomas Huth if (ctx->delayed_pc == (uint32_t) - 1) { 266fcf5ef2aSThomas Huth /* Target is not statically known, it comes necessarily from a 267fcf5ef2aSThomas Huth delayed jump as immediate jump are conditinal jumps */ 268fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_pc, cpu_delayed_pc); 269ac9707eaSAurelien Jarno tcg_gen_discard_i32(cpu_delayed_pc); 270fcf5ef2aSThomas Huth if (ctx->singlestep_enabled) 271fcf5ef2aSThomas Huth gen_helper_debug(cpu_env); 272fcf5ef2aSThomas Huth tcg_gen_exit_tb(0); 273fcf5ef2aSThomas Huth } else { 274fcf5ef2aSThomas Huth gen_goto_tb(ctx, 0, ctx->delayed_pc); 275fcf5ef2aSThomas Huth } 276fcf5ef2aSThomas Huth } 277fcf5ef2aSThomas Huth 278fcf5ef2aSThomas Huth /* Immediate conditional jump (bt or bf) */ 2794bfa602bSRichard Henderson static void gen_conditional_jump(DisasContext *ctx, target_ulong dest, 2804bfa602bSRichard Henderson bool jump_if_true) 281fcf5ef2aSThomas Huth { 282fcf5ef2aSThomas Huth TCGLabel *l1 = gen_new_label(); 2834bfa602bSRichard Henderson TCGCond cond_not_taken = jump_if_true ? TCG_COND_EQ : TCG_COND_NE; 2844bfa602bSRichard Henderson 2854bfa602bSRichard Henderson if (ctx->tbflags & GUSA_EXCLUSIVE) { 2864bfa602bSRichard Henderson /* When in an exclusive region, we must continue to the end. 2874bfa602bSRichard Henderson Therefore, exit the region on a taken branch, but otherwise 2884bfa602bSRichard Henderson fall through to the next instruction. */ 2894bfa602bSRichard Henderson tcg_gen_brcondi_i32(cond_not_taken, cpu_sr_t, 0, l1); 2904bfa602bSRichard Henderson tcg_gen_movi_i32(cpu_flags, ctx->envflags & ~GUSA_MASK); 2914bfa602bSRichard Henderson /* Note that this won't actually use a goto_tb opcode because we 2924bfa602bSRichard Henderson disallow it in use_goto_tb, but it handles exit + singlestep. */ 2934bfa602bSRichard Henderson gen_goto_tb(ctx, 0, dest); 294fcf5ef2aSThomas Huth gen_set_label(l1); 2954bfa602bSRichard Henderson return; 2964bfa602bSRichard Henderson } 2974bfa602bSRichard Henderson 2984bfa602bSRichard Henderson gen_save_cpu_state(ctx, false); 2994bfa602bSRichard Henderson tcg_gen_brcondi_i32(cond_not_taken, cpu_sr_t, 0, l1); 3004bfa602bSRichard Henderson gen_goto_tb(ctx, 0, dest); 3014bfa602bSRichard Henderson gen_set_label(l1); 3024bfa602bSRichard Henderson gen_goto_tb(ctx, 1, ctx->pc + 2); 303b3995c23SAurelien Jarno ctx->bstate = BS_BRANCH; 304fcf5ef2aSThomas Huth } 305fcf5ef2aSThomas Huth 306fcf5ef2aSThomas Huth /* Delayed conditional jump (bt or bf) */ 307fcf5ef2aSThomas Huth static void gen_delayed_conditional_jump(DisasContext * ctx) 308fcf5ef2aSThomas Huth { 3094bfa602bSRichard Henderson TCGLabel *l1 = gen_new_label(); 3104bfa602bSRichard Henderson TCGv ds = tcg_temp_new(); 311fcf5ef2aSThomas Huth 31247b9f4d5SAurelien Jarno tcg_gen_mov_i32(ds, cpu_delayed_cond); 31347b9f4d5SAurelien Jarno tcg_gen_discard_i32(cpu_delayed_cond); 3144bfa602bSRichard Henderson 3154bfa602bSRichard Henderson if (ctx->tbflags & GUSA_EXCLUSIVE) { 3164bfa602bSRichard Henderson /* When in an exclusive region, we must continue to the end. 3174bfa602bSRichard Henderson Therefore, exit the region on a taken branch, but otherwise 3184bfa602bSRichard Henderson fall through to the next instruction. */ 3194bfa602bSRichard Henderson tcg_gen_brcondi_i32(TCG_COND_EQ, ds, 0, l1); 3204bfa602bSRichard Henderson 3214bfa602bSRichard Henderson /* Leave the gUSA region. */ 3224bfa602bSRichard Henderson tcg_gen_movi_i32(cpu_flags, ctx->envflags & ~GUSA_MASK); 3234bfa602bSRichard Henderson gen_jump(ctx); 3244bfa602bSRichard Henderson 3254bfa602bSRichard Henderson gen_set_label(l1); 3264bfa602bSRichard Henderson return; 3274bfa602bSRichard Henderson } 3284bfa602bSRichard Henderson 329fcf5ef2aSThomas Huth tcg_gen_brcondi_i32(TCG_COND_NE, ds, 0, l1); 330fcf5ef2aSThomas Huth gen_goto_tb(ctx, 1, ctx->pc + 2); 331fcf5ef2aSThomas Huth gen_set_label(l1); 332fcf5ef2aSThomas Huth gen_jump(ctx); 333fcf5ef2aSThomas Huth } 334fcf5ef2aSThomas Huth 335e5d8053eSRichard Henderson static inline void gen_load_fpr64(DisasContext *ctx, TCGv_i64 t, int reg) 336fcf5ef2aSThomas Huth { 3371e0b21d8SRichard Henderson /* We have already signaled illegal instruction for odd Dr. */ 3381e0b21d8SRichard Henderson tcg_debug_assert((reg & 1) == 0); 3391e0b21d8SRichard Henderson reg ^= ctx->fbank; 340fcf5ef2aSThomas Huth tcg_gen_concat_i32_i64(t, cpu_fregs[reg + 1], cpu_fregs[reg]); 341fcf5ef2aSThomas Huth } 342fcf5ef2aSThomas Huth 343e5d8053eSRichard Henderson static inline void gen_store_fpr64(DisasContext *ctx, TCGv_i64 t, int reg) 344fcf5ef2aSThomas Huth { 3451e0b21d8SRichard Henderson /* We have already signaled illegal instruction for odd Dr. */ 3461e0b21d8SRichard Henderson tcg_debug_assert((reg & 1) == 0); 3471e0b21d8SRichard Henderson reg ^= ctx->fbank; 34858d2a9aeSAurelien Jarno tcg_gen_extr_i64_i32(cpu_fregs[reg + 1], cpu_fregs[reg], t); 349fcf5ef2aSThomas Huth } 350fcf5ef2aSThomas Huth 351fcf5ef2aSThomas Huth #define B3_0 (ctx->opcode & 0xf) 352fcf5ef2aSThomas Huth #define B6_4 ((ctx->opcode >> 4) & 0x7) 353fcf5ef2aSThomas Huth #define B7_4 ((ctx->opcode >> 4) & 0xf) 354fcf5ef2aSThomas Huth #define B7_0 (ctx->opcode & 0xff) 355fcf5ef2aSThomas Huth #define B7_0s ((int32_t) (int8_t) (ctx->opcode & 0xff)) 356fcf5ef2aSThomas Huth #define B11_0s (ctx->opcode & 0x800 ? 0xfffff000 | (ctx->opcode & 0xfff) : \ 357fcf5ef2aSThomas Huth (ctx->opcode & 0xfff)) 358fcf5ef2aSThomas Huth #define B11_8 ((ctx->opcode >> 8) & 0xf) 359fcf5ef2aSThomas Huth #define B15_12 ((ctx->opcode >> 12) & 0xf) 360fcf5ef2aSThomas Huth 3613a3bb8d2SRichard Henderson #define REG(x) cpu_gregs[(x) ^ ctx->gbank] 3623a3bb8d2SRichard Henderson #define ALTREG(x) cpu_gregs[(x) ^ ctx->gbank ^ 0x10] 3635c13bad9SRichard Henderson #define FREG(x) cpu_fregs[(x) ^ ctx->fbank] 364fcf5ef2aSThomas Huth 365fcf5ef2aSThomas Huth #define XHACK(x) ((((x) & 1 ) << 4) | ((x) & 0xe)) 366fcf5ef2aSThomas Huth 367fcf5ef2aSThomas Huth #define CHECK_NOT_DELAY_SLOT \ 3689a562ae7SAurelien Jarno if (ctx->envflags & DELAY_SLOT_MASK) { \ 369*dec16c6eSRichard Henderson goto do_illegal_slot; \ 370fcf5ef2aSThomas Huth } 371fcf5ef2aSThomas Huth 372fcf5ef2aSThomas Huth #define CHECK_PRIVILEGED \ 373fcf5ef2aSThomas Huth if (IS_USER(ctx)) { \ 374ac9707eaSAurelien Jarno gen_save_cpu_state(ctx, true); \ 3759a562ae7SAurelien Jarno if (ctx->envflags & DELAY_SLOT_MASK) { \ 376fcf5ef2aSThomas Huth gen_helper_raise_slot_illegal_instruction(cpu_env); \ 377fcf5ef2aSThomas Huth } else { \ 378fcf5ef2aSThomas Huth gen_helper_raise_illegal_instruction(cpu_env); \ 379fcf5ef2aSThomas Huth } \ 38063205665SAurelien Jarno ctx->bstate = BS_EXCP; \ 381fcf5ef2aSThomas Huth return; \ 382fcf5ef2aSThomas Huth } 383fcf5ef2aSThomas Huth 384fcf5ef2aSThomas Huth #define CHECK_FPU_ENABLED \ 385a6215749SAurelien Jarno if (ctx->tbflags & (1u << SR_FD)) { \ 386ac9707eaSAurelien Jarno gen_save_cpu_state(ctx, true); \ 3879a562ae7SAurelien Jarno if (ctx->envflags & DELAY_SLOT_MASK) { \ 388fcf5ef2aSThomas Huth gen_helper_raise_slot_fpu_disable(cpu_env); \ 389fcf5ef2aSThomas Huth } else { \ 390fcf5ef2aSThomas Huth gen_helper_raise_fpu_disable(cpu_env); \ 391fcf5ef2aSThomas Huth } \ 39263205665SAurelien Jarno ctx->bstate = BS_EXCP; \ 393fcf5ef2aSThomas Huth return; \ 394fcf5ef2aSThomas Huth } 395fcf5ef2aSThomas Huth 396fcf5ef2aSThomas Huth static void _decode_opc(DisasContext * ctx) 397fcf5ef2aSThomas Huth { 398fcf5ef2aSThomas Huth /* This code tries to make movcal emulation sufficiently 399fcf5ef2aSThomas Huth accurate for Linux purposes. This instruction writes 400fcf5ef2aSThomas Huth memory, and prior to that, always allocates a cache line. 401fcf5ef2aSThomas Huth It is used in two contexts: 402fcf5ef2aSThomas Huth - in memcpy, where data is copied in blocks, the first write 403fcf5ef2aSThomas Huth of to a block uses movca.l for performance. 404fcf5ef2aSThomas Huth - in arch/sh/mm/cache-sh4.c, movcal.l + ocbi combination is used 405fcf5ef2aSThomas Huth to flush the cache. Here, the data written by movcal.l is never 406fcf5ef2aSThomas Huth written to memory, and the data written is just bogus. 407fcf5ef2aSThomas Huth 408fcf5ef2aSThomas Huth To simulate this, we simulate movcal.l, we store the value to memory, 409fcf5ef2aSThomas Huth but we also remember the previous content. If we see ocbi, we check 410fcf5ef2aSThomas Huth if movcal.l for that address was done previously. If so, the write should 411fcf5ef2aSThomas Huth not have hit the memory, so we restore the previous content. 412fcf5ef2aSThomas Huth When we see an instruction that is neither movca.l 413fcf5ef2aSThomas Huth nor ocbi, the previous content is discarded. 414fcf5ef2aSThomas Huth 415fcf5ef2aSThomas Huth To optimize, we only try to flush stores when we're at the start of 416fcf5ef2aSThomas Huth TB, or if we already saw movca.l in this TB and did not flush stores 417fcf5ef2aSThomas Huth yet. */ 418fcf5ef2aSThomas Huth if (ctx->has_movcal) 419fcf5ef2aSThomas Huth { 420fcf5ef2aSThomas Huth int opcode = ctx->opcode & 0xf0ff; 421fcf5ef2aSThomas Huth if (opcode != 0x0093 /* ocbi */ 422fcf5ef2aSThomas Huth && opcode != 0x00c3 /* movca.l */) 423fcf5ef2aSThomas Huth { 424fcf5ef2aSThomas Huth gen_helper_discard_movcal_backup(cpu_env); 425fcf5ef2aSThomas Huth ctx->has_movcal = 0; 426fcf5ef2aSThomas Huth } 427fcf5ef2aSThomas Huth } 428fcf5ef2aSThomas Huth 429fcf5ef2aSThomas Huth #if 0 430fcf5ef2aSThomas Huth fprintf(stderr, "Translating opcode 0x%04x\n", ctx->opcode); 431fcf5ef2aSThomas Huth #endif 432fcf5ef2aSThomas Huth 433fcf5ef2aSThomas Huth switch (ctx->opcode) { 434fcf5ef2aSThomas Huth case 0x0019: /* div0u */ 435fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_sr_m, 0); 436fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_sr_q, 0); 437fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_sr_t, 0); 438fcf5ef2aSThomas Huth return; 439fcf5ef2aSThomas Huth case 0x000b: /* rts */ 440fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 441fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_delayed_pc, cpu_pr); 442a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 443fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 444fcf5ef2aSThomas Huth return; 445fcf5ef2aSThomas Huth case 0x0028: /* clrmac */ 446fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_mach, 0); 447fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_macl, 0); 448fcf5ef2aSThomas Huth return; 449fcf5ef2aSThomas Huth case 0x0048: /* clrs */ 450fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr, cpu_sr, ~(1u << SR_S)); 451fcf5ef2aSThomas Huth return; 452fcf5ef2aSThomas Huth case 0x0008: /* clrt */ 453fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_sr_t, 0); 454fcf5ef2aSThomas Huth return; 455fcf5ef2aSThomas Huth case 0x0038: /* ldtlb */ 456fcf5ef2aSThomas Huth CHECK_PRIVILEGED 457fcf5ef2aSThomas Huth gen_helper_ldtlb(cpu_env); 458fcf5ef2aSThomas Huth return; 459fcf5ef2aSThomas Huth case 0x002b: /* rte */ 460fcf5ef2aSThomas Huth CHECK_PRIVILEGED 461fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 462fcf5ef2aSThomas Huth gen_write_sr(cpu_ssr); 463fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_delayed_pc, cpu_spc); 464be53081aSAurelien Jarno ctx->envflags |= DELAY_SLOT_RTE; 465fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 466be53081aSAurelien Jarno ctx->bstate = BS_STOP; 467fcf5ef2aSThomas Huth return; 468fcf5ef2aSThomas Huth case 0x0058: /* sets */ 469fcf5ef2aSThomas Huth tcg_gen_ori_i32(cpu_sr, cpu_sr, (1u << SR_S)); 470fcf5ef2aSThomas Huth return; 471fcf5ef2aSThomas Huth case 0x0018: /* sett */ 472fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_sr_t, 1); 473fcf5ef2aSThomas Huth return; 474fcf5ef2aSThomas Huth case 0xfbfd: /* frchg */ 475fcf5ef2aSThomas Huth tcg_gen_xori_i32(cpu_fpscr, cpu_fpscr, FPSCR_FR); 476fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 477fcf5ef2aSThomas Huth return; 478fcf5ef2aSThomas Huth case 0xf3fd: /* fschg */ 479fcf5ef2aSThomas Huth tcg_gen_xori_i32(cpu_fpscr, cpu_fpscr, FPSCR_SZ); 480fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 481fcf5ef2aSThomas Huth return; 482fcf5ef2aSThomas Huth case 0x0009: /* nop */ 483fcf5ef2aSThomas Huth return; 484fcf5ef2aSThomas Huth case 0x001b: /* sleep */ 485fcf5ef2aSThomas Huth CHECK_PRIVILEGED 486fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pc, ctx->pc + 2); 487fcf5ef2aSThomas Huth gen_helper_sleep(cpu_env); 488fcf5ef2aSThomas Huth return; 489fcf5ef2aSThomas Huth } 490fcf5ef2aSThomas Huth 491fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf000) { 492fcf5ef2aSThomas Huth case 0x1000: /* mov.l Rm,@(disp,Rn) */ 493fcf5ef2aSThomas Huth { 494fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 495fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B11_8), B3_0 * 4); 496fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUL); 497fcf5ef2aSThomas Huth tcg_temp_free(addr); 498fcf5ef2aSThomas Huth } 499fcf5ef2aSThomas Huth return; 500fcf5ef2aSThomas Huth case 0x5000: /* mov.l @(disp,Rm),Rn */ 501fcf5ef2aSThomas Huth { 502fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 503fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 4); 504fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_TESL); 505fcf5ef2aSThomas Huth tcg_temp_free(addr); 506fcf5ef2aSThomas Huth } 507fcf5ef2aSThomas Huth return; 508fcf5ef2aSThomas Huth case 0xe000: /* mov #imm,Rn */ 5094bfa602bSRichard Henderson #ifdef CONFIG_USER_ONLY 5104bfa602bSRichard Henderson /* Detect the start of a gUSA region. If so, update envflags 5114bfa602bSRichard Henderson and end the TB. This will allow us to see the end of the 5124bfa602bSRichard Henderson region (stored in R0) in the next TB. */ 5134bfa602bSRichard Henderson if (B11_8 == 15 && B7_0s < 0 && parallel_cpus) { 5144bfa602bSRichard Henderson ctx->envflags = deposit32(ctx->envflags, GUSA_SHIFT, 8, B7_0s); 5154bfa602bSRichard Henderson ctx->bstate = BS_STOP; 5164bfa602bSRichard Henderson } 5174bfa602bSRichard Henderson #endif 518fcf5ef2aSThomas Huth tcg_gen_movi_i32(REG(B11_8), B7_0s); 519fcf5ef2aSThomas Huth return; 520fcf5ef2aSThomas Huth case 0x9000: /* mov.w @(disp,PC),Rn */ 521fcf5ef2aSThomas Huth { 522fcf5ef2aSThomas Huth TCGv addr = tcg_const_i32(ctx->pc + 4 + B7_0 * 2); 523fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_TESW); 524fcf5ef2aSThomas Huth tcg_temp_free(addr); 525fcf5ef2aSThomas Huth } 526fcf5ef2aSThomas Huth return; 527fcf5ef2aSThomas Huth case 0xd000: /* mov.l @(disp,PC),Rn */ 528fcf5ef2aSThomas Huth { 529fcf5ef2aSThomas Huth TCGv addr = tcg_const_i32((ctx->pc + 4 + B7_0 * 4) & ~3); 530fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_TESL); 531fcf5ef2aSThomas Huth tcg_temp_free(addr); 532fcf5ef2aSThomas Huth } 533fcf5ef2aSThomas Huth return; 534fcf5ef2aSThomas Huth case 0x7000: /* add #imm,Rn */ 535fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), B7_0s); 536fcf5ef2aSThomas Huth return; 537fcf5ef2aSThomas Huth case 0xa000: /* bra disp */ 538fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 539fcf5ef2aSThomas Huth ctx->delayed_pc = ctx->pc + 4 + B11_0s * 2; 540a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 541fcf5ef2aSThomas Huth return; 542fcf5ef2aSThomas Huth case 0xb000: /* bsr disp */ 543fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 544fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pr, ctx->pc + 4); 545fcf5ef2aSThomas Huth ctx->delayed_pc = ctx->pc + 4 + B11_0s * 2; 546a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 547fcf5ef2aSThomas Huth return; 548fcf5ef2aSThomas Huth } 549fcf5ef2aSThomas Huth 550fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf00f) { 551fcf5ef2aSThomas Huth case 0x6003: /* mov Rm,Rn */ 552fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), REG(B7_4)); 553fcf5ef2aSThomas Huth return; 554fcf5ef2aSThomas Huth case 0x2000: /* mov.b Rm,@Rn */ 555fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), REG(B11_8), ctx->memidx, MO_UB); 556fcf5ef2aSThomas Huth return; 557fcf5ef2aSThomas Huth case 0x2001: /* mov.w Rm,@Rn */ 558fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), REG(B11_8), ctx->memidx, MO_TEUW); 559fcf5ef2aSThomas Huth return; 560fcf5ef2aSThomas Huth case 0x2002: /* mov.l Rm,@Rn */ 561fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), REG(B11_8), ctx->memidx, MO_TEUL); 562fcf5ef2aSThomas Huth return; 563fcf5ef2aSThomas Huth case 0x6000: /* mov.b @Rm,Rn */ 564fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_SB); 565fcf5ef2aSThomas Huth return; 566fcf5ef2aSThomas Huth case 0x6001: /* mov.w @Rm,Rn */ 567fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_TESW); 568fcf5ef2aSThomas Huth return; 569fcf5ef2aSThomas Huth case 0x6002: /* mov.l @Rm,Rn */ 570fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_TESL); 571fcf5ef2aSThomas Huth return; 572fcf5ef2aSThomas Huth case 0x2004: /* mov.b Rm,@-Rn */ 573fcf5ef2aSThomas Huth { 574fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 575fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 1); 576fcf5ef2aSThomas Huth /* might cause re-execution */ 577fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_UB); 578fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); /* modify register status */ 579fcf5ef2aSThomas Huth tcg_temp_free(addr); 580fcf5ef2aSThomas Huth } 581fcf5ef2aSThomas Huth return; 582fcf5ef2aSThomas Huth case 0x2005: /* mov.w Rm,@-Rn */ 583fcf5ef2aSThomas Huth { 584fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 585fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 2); 586fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUW); 587fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 588fcf5ef2aSThomas Huth tcg_temp_free(addr); 589fcf5ef2aSThomas Huth } 590fcf5ef2aSThomas Huth return; 591fcf5ef2aSThomas Huth case 0x2006: /* mov.l Rm,@-Rn */ 592fcf5ef2aSThomas Huth { 593fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 594fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 4); 595fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUL); 596fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 597fcf5ef2aSThomas Huth } 598fcf5ef2aSThomas Huth return; 599fcf5ef2aSThomas Huth case 0x6004: /* mov.b @Rm+,Rn */ 600fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_SB); 601fcf5ef2aSThomas Huth if ( B11_8 != B7_4 ) 602fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 1); 603fcf5ef2aSThomas Huth return; 604fcf5ef2aSThomas Huth case 0x6005: /* mov.w @Rm+,Rn */ 605fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_TESW); 606fcf5ef2aSThomas Huth if ( B11_8 != B7_4 ) 607fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 2); 608fcf5ef2aSThomas Huth return; 609fcf5ef2aSThomas Huth case 0x6006: /* mov.l @Rm+,Rn */ 610fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), REG(B7_4), ctx->memidx, MO_TESL); 611fcf5ef2aSThomas Huth if ( B11_8 != B7_4 ) 612fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4); 613fcf5ef2aSThomas Huth return; 614fcf5ef2aSThomas Huth case 0x0004: /* mov.b Rm,@(R0,Rn) */ 615fcf5ef2aSThomas Huth { 616fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 617fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B11_8), REG(0)); 618fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_UB); 619fcf5ef2aSThomas Huth tcg_temp_free(addr); 620fcf5ef2aSThomas Huth } 621fcf5ef2aSThomas Huth return; 622fcf5ef2aSThomas Huth case 0x0005: /* mov.w Rm,@(R0,Rn) */ 623fcf5ef2aSThomas Huth { 624fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 625fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B11_8), REG(0)); 626fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUW); 627fcf5ef2aSThomas Huth tcg_temp_free(addr); 628fcf5ef2aSThomas Huth } 629fcf5ef2aSThomas Huth return; 630fcf5ef2aSThomas Huth case 0x0006: /* mov.l Rm,@(R0,Rn) */ 631fcf5ef2aSThomas Huth { 632fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 633fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B11_8), REG(0)); 634fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(B7_4), addr, ctx->memidx, MO_TEUL); 635fcf5ef2aSThomas Huth tcg_temp_free(addr); 636fcf5ef2aSThomas Huth } 637fcf5ef2aSThomas Huth return; 638fcf5ef2aSThomas Huth case 0x000c: /* mov.b @(R0,Rm),Rn */ 639fcf5ef2aSThomas Huth { 640fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 641fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B7_4), REG(0)); 642fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_SB); 643fcf5ef2aSThomas Huth tcg_temp_free(addr); 644fcf5ef2aSThomas Huth } 645fcf5ef2aSThomas Huth return; 646fcf5ef2aSThomas Huth case 0x000d: /* mov.w @(R0,Rm),Rn */ 647fcf5ef2aSThomas Huth { 648fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 649fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B7_4), REG(0)); 650fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_TESW); 651fcf5ef2aSThomas Huth tcg_temp_free(addr); 652fcf5ef2aSThomas Huth } 653fcf5ef2aSThomas Huth return; 654fcf5ef2aSThomas Huth case 0x000e: /* mov.l @(R0,Rm),Rn */ 655fcf5ef2aSThomas Huth { 656fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 657fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B7_4), REG(0)); 658fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(B11_8), addr, ctx->memidx, MO_TESL); 659fcf5ef2aSThomas Huth tcg_temp_free(addr); 660fcf5ef2aSThomas Huth } 661fcf5ef2aSThomas Huth return; 662fcf5ef2aSThomas Huth case 0x6008: /* swap.b Rm,Rn */ 663fcf5ef2aSThomas Huth { 664fcf5ef2aSThomas Huth TCGv low = tcg_temp_new();; 665fcf5ef2aSThomas Huth tcg_gen_ext16u_i32(low, REG(B7_4)); 666fcf5ef2aSThomas Huth tcg_gen_bswap16_i32(low, low); 667fcf5ef2aSThomas Huth tcg_gen_deposit_i32(REG(B11_8), REG(B7_4), low, 0, 16); 668fcf5ef2aSThomas Huth tcg_temp_free(low); 669fcf5ef2aSThomas Huth } 670fcf5ef2aSThomas Huth return; 671fcf5ef2aSThomas Huth case 0x6009: /* swap.w Rm,Rn */ 672fcf5ef2aSThomas Huth tcg_gen_rotli_i32(REG(B11_8), REG(B7_4), 16); 673fcf5ef2aSThomas Huth return; 674fcf5ef2aSThomas Huth case 0x200d: /* xtrct Rm,Rn */ 675fcf5ef2aSThomas Huth { 676fcf5ef2aSThomas Huth TCGv high, low; 677fcf5ef2aSThomas Huth high = tcg_temp_new(); 678fcf5ef2aSThomas Huth tcg_gen_shli_i32(high, REG(B7_4), 16); 679fcf5ef2aSThomas Huth low = tcg_temp_new(); 680fcf5ef2aSThomas Huth tcg_gen_shri_i32(low, REG(B11_8), 16); 681fcf5ef2aSThomas Huth tcg_gen_or_i32(REG(B11_8), high, low); 682fcf5ef2aSThomas Huth tcg_temp_free(low); 683fcf5ef2aSThomas Huth tcg_temp_free(high); 684fcf5ef2aSThomas Huth } 685fcf5ef2aSThomas Huth return; 686fcf5ef2aSThomas Huth case 0x300c: /* add Rm,Rn */ 687fcf5ef2aSThomas Huth tcg_gen_add_i32(REG(B11_8), REG(B11_8), REG(B7_4)); 688fcf5ef2aSThomas Huth return; 689fcf5ef2aSThomas Huth case 0x300e: /* addc Rm,Rn */ 690fcf5ef2aSThomas Huth { 691fcf5ef2aSThomas Huth TCGv t0, t1; 692fcf5ef2aSThomas Huth t0 = tcg_const_tl(0); 693fcf5ef2aSThomas Huth t1 = tcg_temp_new(); 694fcf5ef2aSThomas Huth tcg_gen_add2_i32(t1, cpu_sr_t, cpu_sr_t, t0, REG(B7_4), t0); 695fcf5ef2aSThomas Huth tcg_gen_add2_i32(REG(B11_8), cpu_sr_t, 696fcf5ef2aSThomas Huth REG(B11_8), t0, t1, cpu_sr_t); 697fcf5ef2aSThomas Huth tcg_temp_free(t0); 698fcf5ef2aSThomas Huth tcg_temp_free(t1); 699fcf5ef2aSThomas Huth } 700fcf5ef2aSThomas Huth return; 701fcf5ef2aSThomas Huth case 0x300f: /* addv Rm,Rn */ 702fcf5ef2aSThomas Huth { 703fcf5ef2aSThomas Huth TCGv t0, t1, t2; 704fcf5ef2aSThomas Huth t0 = tcg_temp_new(); 705fcf5ef2aSThomas Huth tcg_gen_add_i32(t0, REG(B7_4), REG(B11_8)); 706fcf5ef2aSThomas Huth t1 = tcg_temp_new(); 707fcf5ef2aSThomas Huth tcg_gen_xor_i32(t1, t0, REG(B11_8)); 708fcf5ef2aSThomas Huth t2 = tcg_temp_new(); 709fcf5ef2aSThomas Huth tcg_gen_xor_i32(t2, REG(B7_4), REG(B11_8)); 710fcf5ef2aSThomas Huth tcg_gen_andc_i32(cpu_sr_t, t1, t2); 711fcf5ef2aSThomas Huth tcg_temp_free(t2); 712fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_t, cpu_sr_t, 31); 713fcf5ef2aSThomas Huth tcg_temp_free(t1); 714fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B7_4), t0); 715fcf5ef2aSThomas Huth tcg_temp_free(t0); 716fcf5ef2aSThomas Huth } 717fcf5ef2aSThomas Huth return; 718fcf5ef2aSThomas Huth case 0x2009: /* and Rm,Rn */ 719fcf5ef2aSThomas Huth tcg_gen_and_i32(REG(B11_8), REG(B11_8), REG(B7_4)); 720fcf5ef2aSThomas Huth return; 721fcf5ef2aSThomas Huth case 0x3000: /* cmp/eq Rm,Rn */ 722fcf5ef2aSThomas Huth tcg_gen_setcond_i32(TCG_COND_EQ, cpu_sr_t, REG(B11_8), REG(B7_4)); 723fcf5ef2aSThomas Huth return; 724fcf5ef2aSThomas Huth case 0x3003: /* cmp/ge Rm,Rn */ 725fcf5ef2aSThomas Huth tcg_gen_setcond_i32(TCG_COND_GE, cpu_sr_t, REG(B11_8), REG(B7_4)); 726fcf5ef2aSThomas Huth return; 727fcf5ef2aSThomas Huth case 0x3007: /* cmp/gt Rm,Rn */ 728fcf5ef2aSThomas Huth tcg_gen_setcond_i32(TCG_COND_GT, cpu_sr_t, REG(B11_8), REG(B7_4)); 729fcf5ef2aSThomas Huth return; 730fcf5ef2aSThomas Huth case 0x3006: /* cmp/hi Rm,Rn */ 731fcf5ef2aSThomas Huth tcg_gen_setcond_i32(TCG_COND_GTU, cpu_sr_t, REG(B11_8), REG(B7_4)); 732fcf5ef2aSThomas Huth return; 733fcf5ef2aSThomas Huth case 0x3002: /* cmp/hs Rm,Rn */ 734fcf5ef2aSThomas Huth tcg_gen_setcond_i32(TCG_COND_GEU, cpu_sr_t, REG(B11_8), REG(B7_4)); 735fcf5ef2aSThomas Huth return; 736fcf5ef2aSThomas Huth case 0x200c: /* cmp/str Rm,Rn */ 737fcf5ef2aSThomas Huth { 738fcf5ef2aSThomas Huth TCGv cmp1 = tcg_temp_new(); 739fcf5ef2aSThomas Huth TCGv cmp2 = tcg_temp_new(); 740fcf5ef2aSThomas Huth tcg_gen_xor_i32(cmp2, REG(B7_4), REG(B11_8)); 741fcf5ef2aSThomas Huth tcg_gen_subi_i32(cmp1, cmp2, 0x01010101); 742fcf5ef2aSThomas Huth tcg_gen_andc_i32(cmp1, cmp1, cmp2); 743fcf5ef2aSThomas Huth tcg_gen_andi_i32(cmp1, cmp1, 0x80808080); 744fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_NE, cpu_sr_t, cmp1, 0); 745fcf5ef2aSThomas Huth tcg_temp_free(cmp2); 746fcf5ef2aSThomas Huth tcg_temp_free(cmp1); 747fcf5ef2aSThomas Huth } 748fcf5ef2aSThomas Huth return; 749fcf5ef2aSThomas Huth case 0x2007: /* div0s Rm,Rn */ 750fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_q, REG(B11_8), 31); /* SR_Q */ 751fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_m, REG(B7_4), 31); /* SR_M */ 752fcf5ef2aSThomas Huth tcg_gen_xor_i32(cpu_sr_t, cpu_sr_q, cpu_sr_m); /* SR_T */ 753fcf5ef2aSThomas Huth return; 754fcf5ef2aSThomas Huth case 0x3004: /* div1 Rm,Rn */ 755fcf5ef2aSThomas Huth { 756fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 757fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new(); 758fcf5ef2aSThomas Huth TCGv t2 = tcg_temp_new(); 759fcf5ef2aSThomas Huth TCGv zero = tcg_const_i32(0); 760fcf5ef2aSThomas Huth 761fcf5ef2aSThomas Huth /* shift left arg1, saving the bit being pushed out and inserting 762fcf5ef2aSThomas Huth T on the right */ 763fcf5ef2aSThomas Huth tcg_gen_shri_i32(t0, REG(B11_8), 31); 764fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1); 765fcf5ef2aSThomas Huth tcg_gen_or_i32(REG(B11_8), REG(B11_8), cpu_sr_t); 766fcf5ef2aSThomas Huth 767fcf5ef2aSThomas Huth /* Add or subtract arg0 from arg1 depending if Q == M. To avoid 768fcf5ef2aSThomas Huth using 64-bit temps, we compute arg0's high part from q ^ m, so 769fcf5ef2aSThomas Huth that it is 0x00000000 when adding the value or 0xffffffff when 770fcf5ef2aSThomas Huth subtracting it. */ 771fcf5ef2aSThomas Huth tcg_gen_xor_i32(t1, cpu_sr_q, cpu_sr_m); 772fcf5ef2aSThomas Huth tcg_gen_subi_i32(t1, t1, 1); 773fcf5ef2aSThomas Huth tcg_gen_neg_i32(t2, REG(B7_4)); 774fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_EQ, t2, t1, zero, REG(B7_4), t2); 775fcf5ef2aSThomas Huth tcg_gen_add2_i32(REG(B11_8), t1, REG(B11_8), zero, t2, t1); 776fcf5ef2aSThomas Huth 777fcf5ef2aSThomas Huth /* compute T and Q depending on carry */ 778fcf5ef2aSThomas Huth tcg_gen_andi_i32(t1, t1, 1); 779fcf5ef2aSThomas Huth tcg_gen_xor_i32(t1, t1, t0); 780fcf5ef2aSThomas Huth tcg_gen_xori_i32(cpu_sr_t, t1, 1); 781fcf5ef2aSThomas Huth tcg_gen_xor_i32(cpu_sr_q, cpu_sr_m, t1); 782fcf5ef2aSThomas Huth 783fcf5ef2aSThomas Huth tcg_temp_free(zero); 784fcf5ef2aSThomas Huth tcg_temp_free(t2); 785fcf5ef2aSThomas Huth tcg_temp_free(t1); 786fcf5ef2aSThomas Huth tcg_temp_free(t0); 787fcf5ef2aSThomas Huth } 788fcf5ef2aSThomas Huth return; 789fcf5ef2aSThomas Huth case 0x300d: /* dmuls.l Rm,Rn */ 790fcf5ef2aSThomas Huth tcg_gen_muls2_i32(cpu_macl, cpu_mach, REG(B7_4), REG(B11_8)); 791fcf5ef2aSThomas Huth return; 792fcf5ef2aSThomas Huth case 0x3005: /* dmulu.l Rm,Rn */ 793fcf5ef2aSThomas Huth tcg_gen_mulu2_i32(cpu_macl, cpu_mach, REG(B7_4), REG(B11_8)); 794fcf5ef2aSThomas Huth return; 795fcf5ef2aSThomas Huth case 0x600e: /* exts.b Rm,Rn */ 796fcf5ef2aSThomas Huth tcg_gen_ext8s_i32(REG(B11_8), REG(B7_4)); 797fcf5ef2aSThomas Huth return; 798fcf5ef2aSThomas Huth case 0x600f: /* exts.w Rm,Rn */ 799fcf5ef2aSThomas Huth tcg_gen_ext16s_i32(REG(B11_8), REG(B7_4)); 800fcf5ef2aSThomas Huth return; 801fcf5ef2aSThomas Huth case 0x600c: /* extu.b Rm,Rn */ 802fcf5ef2aSThomas Huth tcg_gen_ext8u_i32(REG(B11_8), REG(B7_4)); 803fcf5ef2aSThomas Huth return; 804fcf5ef2aSThomas Huth case 0x600d: /* extu.w Rm,Rn */ 805fcf5ef2aSThomas Huth tcg_gen_ext16u_i32(REG(B11_8), REG(B7_4)); 806fcf5ef2aSThomas Huth return; 807fcf5ef2aSThomas Huth case 0x000f: /* mac.l @Rm+,@Rn+ */ 808fcf5ef2aSThomas Huth { 809fcf5ef2aSThomas Huth TCGv arg0, arg1; 810fcf5ef2aSThomas Huth arg0 = tcg_temp_new(); 811fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(arg0, REG(B7_4), ctx->memidx, MO_TESL); 812fcf5ef2aSThomas Huth arg1 = tcg_temp_new(); 813fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(arg1, REG(B11_8), ctx->memidx, MO_TESL); 814fcf5ef2aSThomas Huth gen_helper_macl(cpu_env, arg0, arg1); 815fcf5ef2aSThomas Huth tcg_temp_free(arg1); 816fcf5ef2aSThomas Huth tcg_temp_free(arg0); 817fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4); 818fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); 819fcf5ef2aSThomas Huth } 820fcf5ef2aSThomas Huth return; 821fcf5ef2aSThomas Huth case 0x400f: /* mac.w @Rm+,@Rn+ */ 822fcf5ef2aSThomas Huth { 823fcf5ef2aSThomas Huth TCGv arg0, arg1; 824fcf5ef2aSThomas Huth arg0 = tcg_temp_new(); 825fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(arg0, REG(B7_4), ctx->memidx, MO_TESL); 826fcf5ef2aSThomas Huth arg1 = tcg_temp_new(); 827fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(arg1, REG(B11_8), ctx->memidx, MO_TESL); 828fcf5ef2aSThomas Huth gen_helper_macw(cpu_env, arg0, arg1); 829fcf5ef2aSThomas Huth tcg_temp_free(arg1); 830fcf5ef2aSThomas Huth tcg_temp_free(arg0); 831fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 2); 832fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 2); 833fcf5ef2aSThomas Huth } 834fcf5ef2aSThomas Huth return; 835fcf5ef2aSThomas Huth case 0x0007: /* mul.l Rm,Rn */ 836fcf5ef2aSThomas Huth tcg_gen_mul_i32(cpu_macl, REG(B7_4), REG(B11_8)); 837fcf5ef2aSThomas Huth return; 838fcf5ef2aSThomas Huth case 0x200f: /* muls.w Rm,Rn */ 839fcf5ef2aSThomas Huth { 840fcf5ef2aSThomas Huth TCGv arg0, arg1; 841fcf5ef2aSThomas Huth arg0 = tcg_temp_new(); 842fcf5ef2aSThomas Huth tcg_gen_ext16s_i32(arg0, REG(B7_4)); 843fcf5ef2aSThomas Huth arg1 = tcg_temp_new(); 844fcf5ef2aSThomas Huth tcg_gen_ext16s_i32(arg1, REG(B11_8)); 845fcf5ef2aSThomas Huth tcg_gen_mul_i32(cpu_macl, arg0, arg1); 846fcf5ef2aSThomas Huth tcg_temp_free(arg1); 847fcf5ef2aSThomas Huth tcg_temp_free(arg0); 848fcf5ef2aSThomas Huth } 849fcf5ef2aSThomas Huth return; 850fcf5ef2aSThomas Huth case 0x200e: /* mulu.w Rm,Rn */ 851fcf5ef2aSThomas Huth { 852fcf5ef2aSThomas Huth TCGv arg0, arg1; 853fcf5ef2aSThomas Huth arg0 = tcg_temp_new(); 854fcf5ef2aSThomas Huth tcg_gen_ext16u_i32(arg0, REG(B7_4)); 855fcf5ef2aSThomas Huth arg1 = tcg_temp_new(); 856fcf5ef2aSThomas Huth tcg_gen_ext16u_i32(arg1, REG(B11_8)); 857fcf5ef2aSThomas Huth tcg_gen_mul_i32(cpu_macl, arg0, arg1); 858fcf5ef2aSThomas Huth tcg_temp_free(arg1); 859fcf5ef2aSThomas Huth tcg_temp_free(arg0); 860fcf5ef2aSThomas Huth } 861fcf5ef2aSThomas Huth return; 862fcf5ef2aSThomas Huth case 0x600b: /* neg Rm,Rn */ 863fcf5ef2aSThomas Huth tcg_gen_neg_i32(REG(B11_8), REG(B7_4)); 864fcf5ef2aSThomas Huth return; 865fcf5ef2aSThomas Huth case 0x600a: /* negc Rm,Rn */ 866fcf5ef2aSThomas Huth { 867fcf5ef2aSThomas Huth TCGv t0 = tcg_const_i32(0); 868fcf5ef2aSThomas Huth tcg_gen_add2_i32(REG(B11_8), cpu_sr_t, 869fcf5ef2aSThomas Huth REG(B7_4), t0, cpu_sr_t, t0); 870fcf5ef2aSThomas Huth tcg_gen_sub2_i32(REG(B11_8), cpu_sr_t, 871fcf5ef2aSThomas Huth t0, t0, REG(B11_8), cpu_sr_t); 872fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, cpu_sr_t, 1); 873fcf5ef2aSThomas Huth tcg_temp_free(t0); 874fcf5ef2aSThomas Huth } 875fcf5ef2aSThomas Huth return; 876fcf5ef2aSThomas Huth case 0x6007: /* not Rm,Rn */ 877fcf5ef2aSThomas Huth tcg_gen_not_i32(REG(B11_8), REG(B7_4)); 878fcf5ef2aSThomas Huth return; 879fcf5ef2aSThomas Huth case 0x200b: /* or Rm,Rn */ 880fcf5ef2aSThomas Huth tcg_gen_or_i32(REG(B11_8), REG(B11_8), REG(B7_4)); 881fcf5ef2aSThomas Huth return; 882fcf5ef2aSThomas Huth case 0x400c: /* shad Rm,Rn */ 883fcf5ef2aSThomas Huth { 884fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 885fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new(); 886fcf5ef2aSThomas Huth TCGv t2 = tcg_temp_new(); 887fcf5ef2aSThomas Huth 888fcf5ef2aSThomas Huth tcg_gen_andi_i32(t0, REG(B7_4), 0x1f); 889fcf5ef2aSThomas Huth 890fcf5ef2aSThomas Huth /* positive case: shift to the left */ 891fcf5ef2aSThomas Huth tcg_gen_shl_i32(t1, REG(B11_8), t0); 892fcf5ef2aSThomas Huth 893fcf5ef2aSThomas Huth /* negative case: shift to the right in two steps to 894fcf5ef2aSThomas Huth correctly handle the -32 case */ 895fcf5ef2aSThomas Huth tcg_gen_xori_i32(t0, t0, 0x1f); 896fcf5ef2aSThomas Huth tcg_gen_sar_i32(t2, REG(B11_8), t0); 897fcf5ef2aSThomas Huth tcg_gen_sari_i32(t2, t2, 1); 898fcf5ef2aSThomas Huth 899fcf5ef2aSThomas Huth /* select between the two cases */ 900fcf5ef2aSThomas Huth tcg_gen_movi_i32(t0, 0); 901fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_GE, REG(B11_8), REG(B7_4), t0, t1, t2); 902fcf5ef2aSThomas Huth 903fcf5ef2aSThomas Huth tcg_temp_free(t0); 904fcf5ef2aSThomas Huth tcg_temp_free(t1); 905fcf5ef2aSThomas Huth tcg_temp_free(t2); 906fcf5ef2aSThomas Huth } 907fcf5ef2aSThomas Huth return; 908fcf5ef2aSThomas Huth case 0x400d: /* shld Rm,Rn */ 909fcf5ef2aSThomas Huth { 910fcf5ef2aSThomas Huth TCGv t0 = tcg_temp_new(); 911fcf5ef2aSThomas Huth TCGv t1 = tcg_temp_new(); 912fcf5ef2aSThomas Huth TCGv t2 = tcg_temp_new(); 913fcf5ef2aSThomas Huth 914fcf5ef2aSThomas Huth tcg_gen_andi_i32(t0, REG(B7_4), 0x1f); 915fcf5ef2aSThomas Huth 916fcf5ef2aSThomas Huth /* positive case: shift to the left */ 917fcf5ef2aSThomas Huth tcg_gen_shl_i32(t1, REG(B11_8), t0); 918fcf5ef2aSThomas Huth 919fcf5ef2aSThomas Huth /* negative case: shift to the right in two steps to 920fcf5ef2aSThomas Huth correctly handle the -32 case */ 921fcf5ef2aSThomas Huth tcg_gen_xori_i32(t0, t0, 0x1f); 922fcf5ef2aSThomas Huth tcg_gen_shr_i32(t2, REG(B11_8), t0); 923fcf5ef2aSThomas Huth tcg_gen_shri_i32(t2, t2, 1); 924fcf5ef2aSThomas Huth 925fcf5ef2aSThomas Huth /* select between the two cases */ 926fcf5ef2aSThomas Huth tcg_gen_movi_i32(t0, 0); 927fcf5ef2aSThomas Huth tcg_gen_movcond_i32(TCG_COND_GE, REG(B11_8), REG(B7_4), t0, t1, t2); 928fcf5ef2aSThomas Huth 929fcf5ef2aSThomas Huth tcg_temp_free(t0); 930fcf5ef2aSThomas Huth tcg_temp_free(t1); 931fcf5ef2aSThomas Huth tcg_temp_free(t2); 932fcf5ef2aSThomas Huth } 933fcf5ef2aSThomas Huth return; 934fcf5ef2aSThomas Huth case 0x3008: /* sub Rm,Rn */ 935fcf5ef2aSThomas Huth tcg_gen_sub_i32(REG(B11_8), REG(B11_8), REG(B7_4)); 936fcf5ef2aSThomas Huth return; 937fcf5ef2aSThomas Huth case 0x300a: /* subc Rm,Rn */ 938fcf5ef2aSThomas Huth { 939fcf5ef2aSThomas Huth TCGv t0, t1; 940fcf5ef2aSThomas Huth t0 = tcg_const_tl(0); 941fcf5ef2aSThomas Huth t1 = tcg_temp_new(); 942fcf5ef2aSThomas Huth tcg_gen_add2_i32(t1, cpu_sr_t, cpu_sr_t, t0, REG(B7_4), t0); 943fcf5ef2aSThomas Huth tcg_gen_sub2_i32(REG(B11_8), cpu_sr_t, 944fcf5ef2aSThomas Huth REG(B11_8), t0, t1, cpu_sr_t); 945fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, cpu_sr_t, 1); 946fcf5ef2aSThomas Huth tcg_temp_free(t0); 947fcf5ef2aSThomas Huth tcg_temp_free(t1); 948fcf5ef2aSThomas Huth } 949fcf5ef2aSThomas Huth return; 950fcf5ef2aSThomas Huth case 0x300b: /* subv Rm,Rn */ 951fcf5ef2aSThomas Huth { 952fcf5ef2aSThomas Huth TCGv t0, t1, t2; 953fcf5ef2aSThomas Huth t0 = tcg_temp_new(); 954fcf5ef2aSThomas Huth tcg_gen_sub_i32(t0, REG(B11_8), REG(B7_4)); 955fcf5ef2aSThomas Huth t1 = tcg_temp_new(); 956fcf5ef2aSThomas Huth tcg_gen_xor_i32(t1, t0, REG(B7_4)); 957fcf5ef2aSThomas Huth t2 = tcg_temp_new(); 958fcf5ef2aSThomas Huth tcg_gen_xor_i32(t2, REG(B11_8), REG(B7_4)); 959fcf5ef2aSThomas Huth tcg_gen_and_i32(t1, t1, t2); 960fcf5ef2aSThomas Huth tcg_temp_free(t2); 961fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_t, t1, 31); 962fcf5ef2aSThomas Huth tcg_temp_free(t1); 963fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), t0); 964fcf5ef2aSThomas Huth tcg_temp_free(t0); 965fcf5ef2aSThomas Huth } 966fcf5ef2aSThomas Huth return; 967fcf5ef2aSThomas Huth case 0x2008: /* tst Rm,Rn */ 968fcf5ef2aSThomas Huth { 969fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 970fcf5ef2aSThomas Huth tcg_gen_and_i32(val, REG(B7_4), REG(B11_8)); 971fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, val, 0); 972fcf5ef2aSThomas Huth tcg_temp_free(val); 973fcf5ef2aSThomas Huth } 974fcf5ef2aSThomas Huth return; 975fcf5ef2aSThomas Huth case 0x200a: /* xor Rm,Rn */ 976fcf5ef2aSThomas Huth tcg_gen_xor_i32(REG(B11_8), REG(B11_8), REG(B7_4)); 977fcf5ef2aSThomas Huth return; 978fcf5ef2aSThomas Huth case 0xf00c: /* fmov {F,D,X}Rm,{F,D,X}Rn - FPSCR: Nothing */ 979fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 980a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 981bdcb3739SRichard Henderson int xsrc = XHACK(B7_4); 982bdcb3739SRichard Henderson int xdst = XHACK(B11_8); 983bdcb3739SRichard Henderson tcg_gen_mov_i32(FREG(xdst), FREG(xsrc)); 984bdcb3739SRichard Henderson tcg_gen_mov_i32(FREG(xdst + 1), FREG(xsrc + 1)); 985fcf5ef2aSThomas Huth } else { 9867c9f7038SRichard Henderson tcg_gen_mov_i32(FREG(B11_8), FREG(B7_4)); 987fcf5ef2aSThomas Huth } 988fcf5ef2aSThomas Huth return; 989fcf5ef2aSThomas Huth case 0xf00a: /* fmov {F,D,X}Rm,@Rn - FPSCR: Nothing */ 990fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 991a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 9924d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 9934d57fa50SRichard Henderson gen_load_fpr64(ctx, fp, XHACK(B7_4)); 9944d57fa50SRichard Henderson tcg_gen_qemu_st_i64(fp, REG(B11_8), ctx->memidx, MO_TEQ); 9954d57fa50SRichard Henderson tcg_temp_free_i64(fp); 996fcf5ef2aSThomas Huth } else { 9977c9f7038SRichard Henderson tcg_gen_qemu_st_i32(FREG(B7_4), REG(B11_8), ctx->memidx, MO_TEUL); 998fcf5ef2aSThomas Huth } 999fcf5ef2aSThomas Huth return; 1000fcf5ef2aSThomas Huth case 0xf008: /* fmov @Rm,{F,D,X}Rn - FPSCR: Nothing */ 1001fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1002a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 10034d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 10044d57fa50SRichard Henderson tcg_gen_qemu_ld_i64(fp, REG(B7_4), ctx->memidx, MO_TEQ); 10054d57fa50SRichard Henderson gen_store_fpr64(ctx, fp, XHACK(B11_8)); 10064d57fa50SRichard Henderson tcg_temp_free_i64(fp); 1007fcf5ef2aSThomas Huth } else { 10087c9f7038SRichard Henderson tcg_gen_qemu_ld_i32(FREG(B11_8), REG(B7_4), ctx->memidx, MO_TEUL); 1009fcf5ef2aSThomas Huth } 1010fcf5ef2aSThomas Huth return; 1011fcf5ef2aSThomas Huth case 0xf009: /* fmov @Rm+,{F,D,X}Rn - FPSCR: Nothing */ 1012fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1013a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 10144d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 10154d57fa50SRichard Henderson tcg_gen_qemu_ld_i64(fp, REG(B7_4), ctx->memidx, MO_TEQ); 10164d57fa50SRichard Henderson gen_store_fpr64(ctx, fp, XHACK(B11_8)); 10174d57fa50SRichard Henderson tcg_temp_free_i64(fp); 1018fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 8); 1019fcf5ef2aSThomas Huth } else { 10207c9f7038SRichard Henderson tcg_gen_qemu_ld_i32(FREG(B11_8), REG(B7_4), ctx->memidx, MO_TEUL); 1021fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B7_4), REG(B7_4), 4); 1022fcf5ef2aSThomas Huth } 1023fcf5ef2aSThomas Huth return; 1024fcf5ef2aSThomas Huth case 0xf00b: /* fmov {F,D,X}Rm,@-Rn - FPSCR: Nothing */ 1025fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 10264d57fa50SRichard Henderson { 1027fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new_i32(); 1028a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 10294d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 10304d57fa50SRichard Henderson gen_load_fpr64(ctx, fp, XHACK(B7_4)); 10314d57fa50SRichard Henderson tcg_gen_subi_i32(addr, REG(B11_8), 8); 10324d57fa50SRichard Henderson tcg_gen_qemu_st_i64(fp, addr, ctx->memidx, MO_TEQ); 10334d57fa50SRichard Henderson tcg_temp_free_i64(fp); 1034fcf5ef2aSThomas Huth } else { 10354d57fa50SRichard Henderson tcg_gen_subi_i32(addr, REG(B11_8), 4); 10367c9f7038SRichard Henderson tcg_gen_qemu_st_i32(FREG(B7_4), addr, ctx->memidx, MO_TEUL); 1037fcf5ef2aSThomas Huth } 1038fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 1039fcf5ef2aSThomas Huth tcg_temp_free(addr); 10404d57fa50SRichard Henderson } 1041fcf5ef2aSThomas Huth return; 1042fcf5ef2aSThomas Huth case 0xf006: /* fmov @(R0,Rm),{F,D,X}Rm - FPSCR: Nothing */ 1043fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1044fcf5ef2aSThomas Huth { 1045fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new_i32(); 1046fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B7_4), REG(0)); 1047a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 10484d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 10494d57fa50SRichard Henderson tcg_gen_qemu_ld_i64(fp, addr, ctx->memidx, MO_TEQ); 10504d57fa50SRichard Henderson gen_store_fpr64(ctx, fp, XHACK(B11_8)); 10514d57fa50SRichard Henderson tcg_temp_free_i64(fp); 1052fcf5ef2aSThomas Huth } else { 10537c9f7038SRichard Henderson tcg_gen_qemu_ld_i32(FREG(B11_8), addr, ctx->memidx, MO_TEUL); 1054fcf5ef2aSThomas Huth } 1055fcf5ef2aSThomas Huth tcg_temp_free(addr); 1056fcf5ef2aSThomas Huth } 1057fcf5ef2aSThomas Huth return; 1058fcf5ef2aSThomas Huth case 0xf007: /* fmov {F,D,X}Rn,@(R0,Rn) - FPSCR: Nothing */ 1059fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1060fcf5ef2aSThomas Huth { 1061fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1062fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(B11_8), REG(0)); 1063a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_SZ) { 10644d57fa50SRichard Henderson TCGv_i64 fp = tcg_temp_new_i64(); 10654d57fa50SRichard Henderson gen_load_fpr64(ctx, fp, XHACK(B7_4)); 10664d57fa50SRichard Henderson tcg_gen_qemu_st_i64(fp, addr, ctx->memidx, MO_TEQ); 10674d57fa50SRichard Henderson tcg_temp_free_i64(fp); 1068fcf5ef2aSThomas Huth } else { 10697c9f7038SRichard Henderson tcg_gen_qemu_st_i32(FREG(B7_4), addr, ctx->memidx, MO_TEUL); 1070fcf5ef2aSThomas Huth } 1071fcf5ef2aSThomas Huth tcg_temp_free(addr); 1072fcf5ef2aSThomas Huth } 1073fcf5ef2aSThomas Huth return; 1074fcf5ef2aSThomas Huth case 0xf000: /* fadd Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ 1075fcf5ef2aSThomas Huth case 0xf001: /* fsub Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ 1076fcf5ef2aSThomas Huth case 0xf002: /* fmul Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ 1077fcf5ef2aSThomas Huth case 0xf003: /* fdiv Rm,Rn - FPSCR: R[PR,Enable.O/U/I]/W[Cause,Flag] */ 1078fcf5ef2aSThomas Huth case 0xf004: /* fcmp/eq Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ 1079fcf5ef2aSThomas Huth case 0xf005: /* fcmp/gt Rm,Rn - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ 1080fcf5ef2aSThomas Huth { 1081fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1082a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_PR) { 1083fcf5ef2aSThomas Huth TCGv_i64 fp0, fp1; 1084fcf5ef2aSThomas Huth 1085fcf5ef2aSThomas Huth if (ctx->opcode & 0x0110) 1086fcf5ef2aSThomas Huth break; /* illegal instruction */ 1087fcf5ef2aSThomas Huth fp0 = tcg_temp_new_i64(); 1088fcf5ef2aSThomas Huth fp1 = tcg_temp_new_i64(); 10891e0b21d8SRichard Henderson gen_load_fpr64(ctx, fp0, B11_8); 10901e0b21d8SRichard Henderson gen_load_fpr64(ctx, fp1, B7_4); 1091fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf00f) { 1092fcf5ef2aSThomas Huth case 0xf000: /* fadd Rm,Rn */ 1093fcf5ef2aSThomas Huth gen_helper_fadd_DT(fp0, cpu_env, fp0, fp1); 1094fcf5ef2aSThomas Huth break; 1095fcf5ef2aSThomas Huth case 0xf001: /* fsub Rm,Rn */ 1096fcf5ef2aSThomas Huth gen_helper_fsub_DT(fp0, cpu_env, fp0, fp1); 1097fcf5ef2aSThomas Huth break; 1098fcf5ef2aSThomas Huth case 0xf002: /* fmul Rm,Rn */ 1099fcf5ef2aSThomas Huth gen_helper_fmul_DT(fp0, cpu_env, fp0, fp1); 1100fcf5ef2aSThomas Huth break; 1101fcf5ef2aSThomas Huth case 0xf003: /* fdiv Rm,Rn */ 1102fcf5ef2aSThomas Huth gen_helper_fdiv_DT(fp0, cpu_env, fp0, fp1); 1103fcf5ef2aSThomas Huth break; 1104fcf5ef2aSThomas Huth case 0xf004: /* fcmp/eq Rm,Rn */ 110592f1f83eSAurelien Jarno gen_helper_fcmp_eq_DT(cpu_sr_t, cpu_env, fp0, fp1); 1106fcf5ef2aSThomas Huth return; 1107fcf5ef2aSThomas Huth case 0xf005: /* fcmp/gt Rm,Rn */ 110892f1f83eSAurelien Jarno gen_helper_fcmp_gt_DT(cpu_sr_t, cpu_env, fp0, fp1); 1109fcf5ef2aSThomas Huth return; 1110fcf5ef2aSThomas Huth } 11111e0b21d8SRichard Henderson gen_store_fpr64(ctx, fp0, B11_8); 1112fcf5ef2aSThomas Huth tcg_temp_free_i64(fp0); 1113fcf5ef2aSThomas Huth tcg_temp_free_i64(fp1); 1114fcf5ef2aSThomas Huth } else { 1115fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf00f) { 1116fcf5ef2aSThomas Huth case 0xf000: /* fadd Rm,Rn */ 11177c9f7038SRichard Henderson gen_helper_fadd_FT(FREG(B11_8), cpu_env, 11187c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1119fcf5ef2aSThomas Huth break; 1120fcf5ef2aSThomas Huth case 0xf001: /* fsub Rm,Rn */ 11217c9f7038SRichard Henderson gen_helper_fsub_FT(FREG(B11_8), cpu_env, 11227c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1123fcf5ef2aSThomas Huth break; 1124fcf5ef2aSThomas Huth case 0xf002: /* fmul Rm,Rn */ 11257c9f7038SRichard Henderson gen_helper_fmul_FT(FREG(B11_8), cpu_env, 11267c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1127fcf5ef2aSThomas Huth break; 1128fcf5ef2aSThomas Huth case 0xf003: /* fdiv Rm,Rn */ 11297c9f7038SRichard Henderson gen_helper_fdiv_FT(FREG(B11_8), cpu_env, 11307c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1131fcf5ef2aSThomas Huth break; 1132fcf5ef2aSThomas Huth case 0xf004: /* fcmp/eq Rm,Rn */ 113392f1f83eSAurelien Jarno gen_helper_fcmp_eq_FT(cpu_sr_t, cpu_env, 11347c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1135fcf5ef2aSThomas Huth return; 1136fcf5ef2aSThomas Huth case 0xf005: /* fcmp/gt Rm,Rn */ 113792f1f83eSAurelien Jarno gen_helper_fcmp_gt_FT(cpu_sr_t, cpu_env, 11387c9f7038SRichard Henderson FREG(B11_8), FREG(B7_4)); 1139fcf5ef2aSThomas Huth return; 1140fcf5ef2aSThomas Huth } 1141fcf5ef2aSThomas Huth } 1142fcf5ef2aSThomas Huth } 1143fcf5ef2aSThomas Huth return; 1144fcf5ef2aSThomas Huth case 0xf00e: /* fmac FR0,RM,Rn */ 1145fcf5ef2aSThomas Huth { 1146fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1147a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_PR) { 1148fcf5ef2aSThomas Huth break; /* illegal instruction */ 1149fcf5ef2aSThomas Huth } else { 11507c9f7038SRichard Henderson gen_helper_fmac_FT(FREG(B11_8), cpu_env, 11517c9f7038SRichard Henderson FREG(0), FREG(B7_4), FREG(B11_8)); 1152fcf5ef2aSThomas Huth return; 1153fcf5ef2aSThomas Huth } 1154fcf5ef2aSThomas Huth } 1155fcf5ef2aSThomas Huth } 1156fcf5ef2aSThomas Huth 1157fcf5ef2aSThomas Huth switch (ctx->opcode & 0xff00) { 1158fcf5ef2aSThomas Huth case 0xc900: /* and #imm,R0 */ 1159fcf5ef2aSThomas Huth tcg_gen_andi_i32(REG(0), REG(0), B7_0); 1160fcf5ef2aSThomas Huth return; 1161fcf5ef2aSThomas Huth case 0xcd00: /* and.b #imm,@(R0,GBR) */ 1162fcf5ef2aSThomas Huth { 1163fcf5ef2aSThomas Huth TCGv addr, val; 1164fcf5ef2aSThomas Huth addr = tcg_temp_new(); 1165fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(0), cpu_gbr); 1166fcf5ef2aSThomas Huth val = tcg_temp_new(); 1167fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, addr, ctx->memidx, MO_UB); 1168fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, val, B7_0); 1169fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(val, addr, ctx->memidx, MO_UB); 1170fcf5ef2aSThomas Huth tcg_temp_free(val); 1171fcf5ef2aSThomas Huth tcg_temp_free(addr); 1172fcf5ef2aSThomas Huth } 1173fcf5ef2aSThomas Huth return; 1174fcf5ef2aSThomas Huth case 0x8b00: /* bf label */ 1175fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 11764bfa602bSRichard Henderson gen_conditional_jump(ctx, ctx->pc + 4 + B7_0s * 2, false); 1177fcf5ef2aSThomas Huth return; 1178fcf5ef2aSThomas Huth case 0x8f00: /* bf/s label */ 1179fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1180ac9707eaSAurelien Jarno tcg_gen_xori_i32(cpu_delayed_cond, cpu_sr_t, 1); 1181ac9707eaSAurelien Jarno ctx->delayed_pc = ctx->pc + 4 + B7_0s * 2; 1182a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT_CONDITIONAL; 1183fcf5ef2aSThomas Huth return; 1184fcf5ef2aSThomas Huth case 0x8900: /* bt label */ 1185fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 11864bfa602bSRichard Henderson gen_conditional_jump(ctx, ctx->pc + 4 + B7_0s * 2, true); 1187fcf5ef2aSThomas Huth return; 1188fcf5ef2aSThomas Huth case 0x8d00: /* bt/s label */ 1189fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1190ac9707eaSAurelien Jarno tcg_gen_mov_i32(cpu_delayed_cond, cpu_sr_t); 1191ac9707eaSAurelien Jarno ctx->delayed_pc = ctx->pc + 4 + B7_0s * 2; 1192a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT_CONDITIONAL; 1193fcf5ef2aSThomas Huth return; 1194fcf5ef2aSThomas Huth case 0x8800: /* cmp/eq #imm,R0 */ 1195fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, REG(0), B7_0s); 1196fcf5ef2aSThomas Huth return; 1197fcf5ef2aSThomas Huth case 0xc400: /* mov.b @(disp,GBR),R0 */ 1198fcf5ef2aSThomas Huth { 1199fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1200fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0); 1201fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), addr, ctx->memidx, MO_SB); 1202fcf5ef2aSThomas Huth tcg_temp_free(addr); 1203fcf5ef2aSThomas Huth } 1204fcf5ef2aSThomas Huth return; 1205fcf5ef2aSThomas Huth case 0xc500: /* mov.w @(disp,GBR),R0 */ 1206fcf5ef2aSThomas Huth { 1207fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1208fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 2); 1209fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), addr, ctx->memidx, MO_TESW); 1210fcf5ef2aSThomas Huth tcg_temp_free(addr); 1211fcf5ef2aSThomas Huth } 1212fcf5ef2aSThomas Huth return; 1213fcf5ef2aSThomas Huth case 0xc600: /* mov.l @(disp,GBR),R0 */ 1214fcf5ef2aSThomas Huth { 1215fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1216fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 4); 1217fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), addr, ctx->memidx, MO_TESL); 1218fcf5ef2aSThomas Huth tcg_temp_free(addr); 1219fcf5ef2aSThomas Huth } 1220fcf5ef2aSThomas Huth return; 1221fcf5ef2aSThomas Huth case 0xc000: /* mov.b R0,@(disp,GBR) */ 1222fcf5ef2aSThomas Huth { 1223fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1224fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0); 1225fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), addr, ctx->memidx, MO_UB); 1226fcf5ef2aSThomas Huth tcg_temp_free(addr); 1227fcf5ef2aSThomas Huth } 1228fcf5ef2aSThomas Huth return; 1229fcf5ef2aSThomas Huth case 0xc100: /* mov.w R0,@(disp,GBR) */ 1230fcf5ef2aSThomas Huth { 1231fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1232fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 2); 1233fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), addr, ctx->memidx, MO_TEUW); 1234fcf5ef2aSThomas Huth tcg_temp_free(addr); 1235fcf5ef2aSThomas Huth } 1236fcf5ef2aSThomas Huth return; 1237fcf5ef2aSThomas Huth case 0xc200: /* mov.l R0,@(disp,GBR) */ 1238fcf5ef2aSThomas Huth { 1239fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1240fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, cpu_gbr, B7_0 * 4); 1241fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), addr, ctx->memidx, MO_TEUL); 1242fcf5ef2aSThomas Huth tcg_temp_free(addr); 1243fcf5ef2aSThomas Huth } 1244fcf5ef2aSThomas Huth return; 1245fcf5ef2aSThomas Huth case 0x8000: /* mov.b R0,@(disp,Rn) */ 1246fcf5ef2aSThomas Huth { 1247fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1248fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B7_4), B3_0); 1249fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), addr, ctx->memidx, MO_UB); 1250fcf5ef2aSThomas Huth tcg_temp_free(addr); 1251fcf5ef2aSThomas Huth } 1252fcf5ef2aSThomas Huth return; 1253fcf5ef2aSThomas Huth case 0x8100: /* mov.w R0,@(disp,Rn) */ 1254fcf5ef2aSThomas Huth { 1255fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1256fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 2); 1257fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), addr, ctx->memidx, MO_TEUW); 1258fcf5ef2aSThomas Huth tcg_temp_free(addr); 1259fcf5ef2aSThomas Huth } 1260fcf5ef2aSThomas Huth return; 1261fcf5ef2aSThomas Huth case 0x8400: /* mov.b @(disp,Rn),R0 */ 1262fcf5ef2aSThomas Huth { 1263fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1264fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B7_4), B3_0); 1265fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), addr, ctx->memidx, MO_SB); 1266fcf5ef2aSThomas Huth tcg_temp_free(addr); 1267fcf5ef2aSThomas Huth } 1268fcf5ef2aSThomas Huth return; 1269fcf5ef2aSThomas Huth case 0x8500: /* mov.w @(disp,Rn),R0 */ 1270fcf5ef2aSThomas Huth { 1271fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1272fcf5ef2aSThomas Huth tcg_gen_addi_i32(addr, REG(B7_4), B3_0 * 2); 1273fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), addr, ctx->memidx, MO_TESW); 1274fcf5ef2aSThomas Huth tcg_temp_free(addr); 1275fcf5ef2aSThomas Huth } 1276fcf5ef2aSThomas Huth return; 1277fcf5ef2aSThomas Huth case 0xc700: /* mova @(disp,PC),R0 */ 1278fcf5ef2aSThomas Huth tcg_gen_movi_i32(REG(0), ((ctx->pc & 0xfffffffc) + 4 + B7_0 * 4) & ~3); 1279fcf5ef2aSThomas Huth return; 1280fcf5ef2aSThomas Huth case 0xcb00: /* or #imm,R0 */ 1281fcf5ef2aSThomas Huth tcg_gen_ori_i32(REG(0), REG(0), B7_0); 1282fcf5ef2aSThomas Huth return; 1283fcf5ef2aSThomas Huth case 0xcf00: /* or.b #imm,@(R0,GBR) */ 1284fcf5ef2aSThomas Huth { 1285fcf5ef2aSThomas Huth TCGv addr, val; 1286fcf5ef2aSThomas Huth addr = tcg_temp_new(); 1287fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(0), cpu_gbr); 1288fcf5ef2aSThomas Huth val = tcg_temp_new(); 1289fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, addr, ctx->memidx, MO_UB); 1290fcf5ef2aSThomas Huth tcg_gen_ori_i32(val, val, B7_0); 1291fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(val, addr, ctx->memidx, MO_UB); 1292fcf5ef2aSThomas Huth tcg_temp_free(val); 1293fcf5ef2aSThomas Huth tcg_temp_free(addr); 1294fcf5ef2aSThomas Huth } 1295fcf5ef2aSThomas Huth return; 1296fcf5ef2aSThomas Huth case 0xc300: /* trapa #imm */ 1297fcf5ef2aSThomas Huth { 1298fcf5ef2aSThomas Huth TCGv imm; 1299fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1300ac9707eaSAurelien Jarno gen_save_cpu_state(ctx, true); 1301fcf5ef2aSThomas Huth imm = tcg_const_i32(B7_0); 1302fcf5ef2aSThomas Huth gen_helper_trapa(cpu_env, imm); 1303fcf5ef2aSThomas Huth tcg_temp_free(imm); 130463205665SAurelien Jarno ctx->bstate = BS_EXCP; 1305fcf5ef2aSThomas Huth } 1306fcf5ef2aSThomas Huth return; 1307fcf5ef2aSThomas Huth case 0xc800: /* tst #imm,R0 */ 1308fcf5ef2aSThomas Huth { 1309fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1310fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, REG(0), B7_0); 1311fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, val, 0); 1312fcf5ef2aSThomas Huth tcg_temp_free(val); 1313fcf5ef2aSThomas Huth } 1314fcf5ef2aSThomas Huth return; 1315fcf5ef2aSThomas Huth case 0xcc00: /* tst.b #imm,@(R0,GBR) */ 1316fcf5ef2aSThomas Huth { 1317fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1318fcf5ef2aSThomas Huth tcg_gen_add_i32(val, REG(0), cpu_gbr); 1319fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, val, ctx->memidx, MO_UB); 1320fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, val, B7_0); 1321fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, val, 0); 1322fcf5ef2aSThomas Huth tcg_temp_free(val); 1323fcf5ef2aSThomas Huth } 1324fcf5ef2aSThomas Huth return; 1325fcf5ef2aSThomas Huth case 0xca00: /* xor #imm,R0 */ 1326fcf5ef2aSThomas Huth tcg_gen_xori_i32(REG(0), REG(0), B7_0); 1327fcf5ef2aSThomas Huth return; 1328fcf5ef2aSThomas Huth case 0xce00: /* xor.b #imm,@(R0,GBR) */ 1329fcf5ef2aSThomas Huth { 1330fcf5ef2aSThomas Huth TCGv addr, val; 1331fcf5ef2aSThomas Huth addr = tcg_temp_new(); 1332fcf5ef2aSThomas Huth tcg_gen_add_i32(addr, REG(0), cpu_gbr); 1333fcf5ef2aSThomas Huth val = tcg_temp_new(); 1334fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, addr, ctx->memidx, MO_UB); 1335fcf5ef2aSThomas Huth tcg_gen_xori_i32(val, val, B7_0); 1336fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(val, addr, ctx->memidx, MO_UB); 1337fcf5ef2aSThomas Huth tcg_temp_free(val); 1338fcf5ef2aSThomas Huth tcg_temp_free(addr); 1339fcf5ef2aSThomas Huth } 1340fcf5ef2aSThomas Huth return; 1341fcf5ef2aSThomas Huth } 1342fcf5ef2aSThomas Huth 1343fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf08f) { 1344fcf5ef2aSThomas Huth case 0x408e: /* ldc Rm,Rn_BANK */ 1345fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1346fcf5ef2aSThomas Huth tcg_gen_mov_i32(ALTREG(B6_4), REG(B11_8)); 1347fcf5ef2aSThomas Huth return; 1348fcf5ef2aSThomas Huth case 0x4087: /* ldc.l @Rm+,Rn_BANK */ 1349fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1350fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(ALTREG(B6_4), REG(B11_8), ctx->memidx, MO_TESL); 1351fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); 1352fcf5ef2aSThomas Huth return; 1353fcf5ef2aSThomas Huth case 0x0082: /* stc Rm_BANK,Rn */ 1354fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1355fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), ALTREG(B6_4)); 1356fcf5ef2aSThomas Huth return; 1357fcf5ef2aSThomas Huth case 0x4083: /* stc.l Rm_BANK,@-Rn */ 1358fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1359fcf5ef2aSThomas Huth { 1360fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1361fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 4); 1362fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(ALTREG(B6_4), addr, ctx->memidx, MO_TEUL); 1363fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 1364fcf5ef2aSThomas Huth tcg_temp_free(addr); 1365fcf5ef2aSThomas Huth } 1366fcf5ef2aSThomas Huth return; 1367fcf5ef2aSThomas Huth } 1368fcf5ef2aSThomas Huth 1369fcf5ef2aSThomas Huth switch (ctx->opcode & 0xf0ff) { 1370fcf5ef2aSThomas Huth case 0x0023: /* braf Rn */ 1371fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1372fcf5ef2aSThomas Huth tcg_gen_addi_i32(cpu_delayed_pc, REG(B11_8), ctx->pc + 4); 1373a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 1374fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 1375fcf5ef2aSThomas Huth return; 1376fcf5ef2aSThomas Huth case 0x0003: /* bsrf Rn */ 1377fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1378fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pr, ctx->pc + 4); 1379fcf5ef2aSThomas Huth tcg_gen_add_i32(cpu_delayed_pc, REG(B11_8), cpu_pr); 1380a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 1381fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 1382fcf5ef2aSThomas Huth return; 1383fcf5ef2aSThomas Huth case 0x4015: /* cmp/pl Rn */ 1384fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_GT, cpu_sr_t, REG(B11_8), 0); 1385fcf5ef2aSThomas Huth return; 1386fcf5ef2aSThomas Huth case 0x4011: /* cmp/pz Rn */ 1387fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_GE, cpu_sr_t, REG(B11_8), 0); 1388fcf5ef2aSThomas Huth return; 1389fcf5ef2aSThomas Huth case 0x4010: /* dt Rn */ 1390fcf5ef2aSThomas Huth tcg_gen_subi_i32(REG(B11_8), REG(B11_8), 1); 1391fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, REG(B11_8), 0); 1392fcf5ef2aSThomas Huth return; 1393fcf5ef2aSThomas Huth case 0x402b: /* jmp @Rn */ 1394fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1395fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_delayed_pc, REG(B11_8)); 1396a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 1397fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 1398fcf5ef2aSThomas Huth return; 1399fcf5ef2aSThomas Huth case 0x400b: /* jsr @Rn */ 1400fcf5ef2aSThomas Huth CHECK_NOT_DELAY_SLOT 1401fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_pr, ctx->pc + 4); 1402fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_delayed_pc, REG(B11_8)); 1403a6215749SAurelien Jarno ctx->envflags |= DELAY_SLOT; 1404fcf5ef2aSThomas Huth ctx->delayed_pc = (uint32_t) - 1; 1405fcf5ef2aSThomas Huth return; 1406fcf5ef2aSThomas Huth case 0x400e: /* ldc Rm,SR */ 1407fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1408fcf5ef2aSThomas Huth { 1409fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1410fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, REG(B11_8), 0x700083f3); 1411fcf5ef2aSThomas Huth gen_write_sr(val); 1412fcf5ef2aSThomas Huth tcg_temp_free(val); 1413fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 1414fcf5ef2aSThomas Huth } 1415fcf5ef2aSThomas Huth return; 1416fcf5ef2aSThomas Huth case 0x4007: /* ldc.l @Rm+,SR */ 1417fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1418fcf5ef2aSThomas Huth { 1419fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1420fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, REG(B11_8), ctx->memidx, MO_TESL); 1421fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, val, 0x700083f3); 1422fcf5ef2aSThomas Huth gen_write_sr(val); 1423fcf5ef2aSThomas Huth tcg_temp_free(val); 1424fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); 1425fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 1426fcf5ef2aSThomas Huth } 1427fcf5ef2aSThomas Huth return; 1428fcf5ef2aSThomas Huth case 0x0002: /* stc SR,Rn */ 1429fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1430fcf5ef2aSThomas Huth gen_read_sr(REG(B11_8)); 1431fcf5ef2aSThomas Huth return; 1432fcf5ef2aSThomas Huth case 0x4003: /* stc SR,@-Rn */ 1433fcf5ef2aSThomas Huth CHECK_PRIVILEGED 1434fcf5ef2aSThomas Huth { 1435fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1436fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1437fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 4); 1438fcf5ef2aSThomas Huth gen_read_sr(val); 1439fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(val, addr, ctx->memidx, MO_TEUL); 1440fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 1441fcf5ef2aSThomas Huth tcg_temp_free(val); 1442fcf5ef2aSThomas Huth tcg_temp_free(addr); 1443fcf5ef2aSThomas Huth } 1444fcf5ef2aSThomas Huth return; 1445fcf5ef2aSThomas Huth #define LD(reg,ldnum,ldpnum,prechk) \ 1446fcf5ef2aSThomas Huth case ldnum: \ 1447fcf5ef2aSThomas Huth prechk \ 1448fcf5ef2aSThomas Huth tcg_gen_mov_i32 (cpu_##reg, REG(B11_8)); \ 1449fcf5ef2aSThomas Huth return; \ 1450fcf5ef2aSThomas Huth case ldpnum: \ 1451fcf5ef2aSThomas Huth prechk \ 1452fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(cpu_##reg, REG(B11_8), ctx->memidx, MO_TESL); \ 1453fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); \ 1454fcf5ef2aSThomas Huth return; 1455fcf5ef2aSThomas Huth #define ST(reg,stnum,stpnum,prechk) \ 1456fcf5ef2aSThomas Huth case stnum: \ 1457fcf5ef2aSThomas Huth prechk \ 1458fcf5ef2aSThomas Huth tcg_gen_mov_i32 (REG(B11_8), cpu_##reg); \ 1459fcf5ef2aSThomas Huth return; \ 1460fcf5ef2aSThomas Huth case stpnum: \ 1461fcf5ef2aSThomas Huth prechk \ 1462fcf5ef2aSThomas Huth { \ 1463fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); \ 1464fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 4); \ 1465fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(cpu_##reg, addr, ctx->memidx, MO_TEUL); \ 1466fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); \ 1467fcf5ef2aSThomas Huth tcg_temp_free(addr); \ 1468fcf5ef2aSThomas Huth } \ 1469fcf5ef2aSThomas Huth return; 1470fcf5ef2aSThomas Huth #define LDST(reg,ldnum,ldpnum,stnum,stpnum,prechk) \ 1471fcf5ef2aSThomas Huth LD(reg,ldnum,ldpnum,prechk) \ 1472fcf5ef2aSThomas Huth ST(reg,stnum,stpnum,prechk) 1473fcf5ef2aSThomas Huth LDST(gbr, 0x401e, 0x4017, 0x0012, 0x4013, {}) 1474fcf5ef2aSThomas Huth LDST(vbr, 0x402e, 0x4027, 0x0022, 0x4023, CHECK_PRIVILEGED) 1475fcf5ef2aSThomas Huth LDST(ssr, 0x403e, 0x4037, 0x0032, 0x4033, CHECK_PRIVILEGED) 1476fcf5ef2aSThomas Huth LDST(spc, 0x404e, 0x4047, 0x0042, 0x4043, CHECK_PRIVILEGED) 1477fcf5ef2aSThomas Huth ST(sgr, 0x003a, 0x4032, CHECK_PRIVILEGED) 1478fcf5ef2aSThomas Huth LD(sgr, 0x403a, 0x4036, CHECK_PRIVILEGED if (!(ctx->features & SH_FEATURE_SH4A)) break;) 1479fcf5ef2aSThomas Huth LDST(dbr, 0x40fa, 0x40f6, 0x00fa, 0x40f2, CHECK_PRIVILEGED) 1480fcf5ef2aSThomas Huth LDST(mach, 0x400a, 0x4006, 0x000a, 0x4002, {}) 1481fcf5ef2aSThomas Huth LDST(macl, 0x401a, 0x4016, 0x001a, 0x4012, {}) 1482fcf5ef2aSThomas Huth LDST(pr, 0x402a, 0x4026, 0x002a, 0x4022, {}) 1483fcf5ef2aSThomas Huth LDST(fpul, 0x405a, 0x4056, 0x005a, 0x4052, {CHECK_FPU_ENABLED}) 1484fcf5ef2aSThomas Huth case 0x406a: /* lds Rm,FPSCR */ 1485fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1486fcf5ef2aSThomas Huth gen_helper_ld_fpscr(cpu_env, REG(B11_8)); 1487fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 1488fcf5ef2aSThomas Huth return; 1489fcf5ef2aSThomas Huth case 0x4066: /* lds.l @Rm+,FPSCR */ 1490fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1491fcf5ef2aSThomas Huth { 1492fcf5ef2aSThomas Huth TCGv addr = tcg_temp_new(); 1493fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(addr, REG(B11_8), ctx->memidx, MO_TESL); 1494fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); 1495fcf5ef2aSThomas Huth gen_helper_ld_fpscr(cpu_env, addr); 1496fcf5ef2aSThomas Huth tcg_temp_free(addr); 1497fcf5ef2aSThomas Huth ctx->bstate = BS_STOP; 1498fcf5ef2aSThomas Huth } 1499fcf5ef2aSThomas Huth return; 1500fcf5ef2aSThomas Huth case 0x006a: /* sts FPSCR,Rn */ 1501fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1502fcf5ef2aSThomas Huth tcg_gen_andi_i32(REG(B11_8), cpu_fpscr, 0x003fffff); 1503fcf5ef2aSThomas Huth return; 1504fcf5ef2aSThomas Huth case 0x4062: /* sts FPSCR,@-Rn */ 1505fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1506fcf5ef2aSThomas Huth { 1507fcf5ef2aSThomas Huth TCGv addr, val; 1508fcf5ef2aSThomas Huth val = tcg_temp_new(); 1509fcf5ef2aSThomas Huth tcg_gen_andi_i32(val, cpu_fpscr, 0x003fffff); 1510fcf5ef2aSThomas Huth addr = tcg_temp_new(); 1511fcf5ef2aSThomas Huth tcg_gen_subi_i32(addr, REG(B11_8), 4); 1512fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(val, addr, ctx->memidx, MO_TEUL); 1513fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), addr); 1514fcf5ef2aSThomas Huth tcg_temp_free(addr); 1515fcf5ef2aSThomas Huth tcg_temp_free(val); 1516fcf5ef2aSThomas Huth } 1517fcf5ef2aSThomas Huth return; 1518fcf5ef2aSThomas Huth case 0x00c3: /* movca.l R0,@Rm */ 1519fcf5ef2aSThomas Huth { 1520fcf5ef2aSThomas Huth TCGv val = tcg_temp_new(); 1521fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(val, REG(B11_8), ctx->memidx, MO_TEUL); 1522fcf5ef2aSThomas Huth gen_helper_movcal(cpu_env, REG(B11_8), val); 1523fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), REG(B11_8), ctx->memidx, MO_TEUL); 1524fcf5ef2aSThomas Huth } 1525fcf5ef2aSThomas Huth ctx->has_movcal = 1; 1526fcf5ef2aSThomas Huth return; 1527143021b2SAurelien Jarno case 0x40a9: /* movua.l @Rm,R0 */ 1528143021b2SAurelien Jarno /* Load non-boundary-aligned data */ 1529143021b2SAurelien Jarno if (ctx->features & SH_FEATURE_SH4A) { 153034257c21SAurelien Jarno tcg_gen_qemu_ld_i32(REG(0), REG(B11_8), ctx->memidx, 153134257c21SAurelien Jarno MO_TEUL | MO_UNALN); 1532fcf5ef2aSThomas Huth return; 1533143021b2SAurelien Jarno } 1534143021b2SAurelien Jarno break; 1535143021b2SAurelien Jarno case 0x40e9: /* movua.l @Rm+,R0 */ 1536143021b2SAurelien Jarno /* Load non-boundary-aligned data */ 1537143021b2SAurelien Jarno if (ctx->features & SH_FEATURE_SH4A) { 153834257c21SAurelien Jarno tcg_gen_qemu_ld_i32(REG(0), REG(B11_8), ctx->memidx, 153934257c21SAurelien Jarno MO_TEUL | MO_UNALN); 1540fcf5ef2aSThomas Huth tcg_gen_addi_i32(REG(B11_8), REG(B11_8), 4); 1541fcf5ef2aSThomas Huth return; 1542143021b2SAurelien Jarno } 1543143021b2SAurelien Jarno break; 1544fcf5ef2aSThomas Huth case 0x0029: /* movt Rn */ 1545fcf5ef2aSThomas Huth tcg_gen_mov_i32(REG(B11_8), cpu_sr_t); 1546fcf5ef2aSThomas Huth return; 1547fcf5ef2aSThomas Huth case 0x0073: 1548fcf5ef2aSThomas Huth /* MOVCO.L 1549fcf5ef2aSThomas Huth LDST -> T 1550fcf5ef2aSThomas Huth If (T == 1) R0 -> (Rn) 1551fcf5ef2aSThomas Huth 0 -> LDST 1552fcf5ef2aSThomas Huth */ 1553fcf5ef2aSThomas Huth if (ctx->features & SH_FEATURE_SH4A) { 1554fcf5ef2aSThomas Huth TCGLabel *label = gen_new_label(); 1555fcf5ef2aSThomas Huth tcg_gen_mov_i32(cpu_sr_t, cpu_ldst); 1556fcf5ef2aSThomas Huth tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_ldst, 0, label); 1557fcf5ef2aSThomas Huth tcg_gen_qemu_st_i32(REG(0), REG(B11_8), ctx->memidx, MO_TEUL); 1558fcf5ef2aSThomas Huth gen_set_label(label); 1559fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_ldst, 0); 1560fcf5ef2aSThomas Huth return; 1561fcf5ef2aSThomas Huth } else 1562fcf5ef2aSThomas Huth break; 1563fcf5ef2aSThomas Huth case 0x0063: 1564fcf5ef2aSThomas Huth /* MOVLI.L @Rm,R0 1565fcf5ef2aSThomas Huth 1 -> LDST 1566fcf5ef2aSThomas Huth (Rm) -> R0 1567fcf5ef2aSThomas Huth When interrupt/exception 1568fcf5ef2aSThomas Huth occurred 0 -> LDST 1569fcf5ef2aSThomas Huth */ 1570fcf5ef2aSThomas Huth if (ctx->features & SH_FEATURE_SH4A) { 1571fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_ldst, 0); 1572fcf5ef2aSThomas Huth tcg_gen_qemu_ld_i32(REG(0), REG(B11_8), ctx->memidx, MO_TESL); 1573fcf5ef2aSThomas Huth tcg_gen_movi_i32(cpu_ldst, 1); 1574fcf5ef2aSThomas Huth return; 1575fcf5ef2aSThomas Huth } else 1576fcf5ef2aSThomas Huth break; 1577fcf5ef2aSThomas Huth case 0x0093: /* ocbi @Rn */ 1578fcf5ef2aSThomas Huth { 1579fcf5ef2aSThomas Huth gen_helper_ocbi(cpu_env, REG(B11_8)); 1580fcf5ef2aSThomas Huth } 1581fcf5ef2aSThomas Huth return; 1582fcf5ef2aSThomas Huth case 0x00a3: /* ocbp @Rn */ 1583fcf5ef2aSThomas Huth case 0x00b3: /* ocbwb @Rn */ 1584fcf5ef2aSThomas Huth /* These instructions are supposed to do nothing in case of 1585fcf5ef2aSThomas Huth a cache miss. Given that we only partially emulate caches 1586fcf5ef2aSThomas Huth it is safe to simply ignore them. */ 1587fcf5ef2aSThomas Huth return; 1588fcf5ef2aSThomas Huth case 0x0083: /* pref @Rn */ 1589fcf5ef2aSThomas Huth return; 1590fcf5ef2aSThomas Huth case 0x00d3: /* prefi @Rn */ 1591fcf5ef2aSThomas Huth if (ctx->features & SH_FEATURE_SH4A) 1592fcf5ef2aSThomas Huth return; 1593fcf5ef2aSThomas Huth else 1594fcf5ef2aSThomas Huth break; 1595fcf5ef2aSThomas Huth case 0x00e3: /* icbi @Rn */ 1596fcf5ef2aSThomas Huth if (ctx->features & SH_FEATURE_SH4A) 1597fcf5ef2aSThomas Huth return; 1598fcf5ef2aSThomas Huth else 1599fcf5ef2aSThomas Huth break; 1600fcf5ef2aSThomas Huth case 0x00ab: /* synco */ 1601aa351317SAurelien Jarno if (ctx->features & SH_FEATURE_SH4A) { 1602aa351317SAurelien Jarno tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC); 1603fcf5ef2aSThomas Huth return; 1604aa351317SAurelien Jarno } 1605fcf5ef2aSThomas Huth break; 1606fcf5ef2aSThomas Huth case 0x4024: /* rotcl Rn */ 1607fcf5ef2aSThomas Huth { 1608fcf5ef2aSThomas Huth TCGv tmp = tcg_temp_new(); 1609fcf5ef2aSThomas Huth tcg_gen_mov_i32(tmp, cpu_sr_t); 1610fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_t, REG(B11_8), 31); 1611fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1); 1612fcf5ef2aSThomas Huth tcg_gen_or_i32(REG(B11_8), REG(B11_8), tmp); 1613fcf5ef2aSThomas Huth tcg_temp_free(tmp); 1614fcf5ef2aSThomas Huth } 1615fcf5ef2aSThomas Huth return; 1616fcf5ef2aSThomas Huth case 0x4025: /* rotcr Rn */ 1617fcf5ef2aSThomas Huth { 1618fcf5ef2aSThomas Huth TCGv tmp = tcg_temp_new(); 1619fcf5ef2aSThomas Huth tcg_gen_shli_i32(tmp, cpu_sr_t, 31); 1620fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, REG(B11_8), 1); 1621fcf5ef2aSThomas Huth tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 1); 1622fcf5ef2aSThomas Huth tcg_gen_or_i32(REG(B11_8), REG(B11_8), tmp); 1623fcf5ef2aSThomas Huth tcg_temp_free(tmp); 1624fcf5ef2aSThomas Huth } 1625fcf5ef2aSThomas Huth return; 1626fcf5ef2aSThomas Huth case 0x4004: /* rotl Rn */ 1627fcf5ef2aSThomas Huth tcg_gen_rotli_i32(REG(B11_8), REG(B11_8), 1); 1628fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, REG(B11_8), 0); 1629fcf5ef2aSThomas Huth return; 1630fcf5ef2aSThomas Huth case 0x4005: /* rotr Rn */ 1631fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, REG(B11_8), 0); 1632fcf5ef2aSThomas Huth tcg_gen_rotri_i32(REG(B11_8), REG(B11_8), 1); 1633fcf5ef2aSThomas Huth return; 1634fcf5ef2aSThomas Huth case 0x4000: /* shll Rn */ 1635fcf5ef2aSThomas Huth case 0x4020: /* shal Rn */ 1636fcf5ef2aSThomas Huth tcg_gen_shri_i32(cpu_sr_t, REG(B11_8), 31); 1637fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 1); 1638fcf5ef2aSThomas Huth return; 1639fcf5ef2aSThomas Huth case 0x4021: /* shar Rn */ 1640fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, REG(B11_8), 1); 1641fcf5ef2aSThomas Huth tcg_gen_sari_i32(REG(B11_8), REG(B11_8), 1); 1642fcf5ef2aSThomas Huth return; 1643fcf5ef2aSThomas Huth case 0x4001: /* shlr Rn */ 1644fcf5ef2aSThomas Huth tcg_gen_andi_i32(cpu_sr_t, REG(B11_8), 1); 1645fcf5ef2aSThomas Huth tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 1); 1646fcf5ef2aSThomas Huth return; 1647fcf5ef2aSThomas Huth case 0x4008: /* shll2 Rn */ 1648fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 2); 1649fcf5ef2aSThomas Huth return; 1650fcf5ef2aSThomas Huth case 0x4018: /* shll8 Rn */ 1651fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 8); 1652fcf5ef2aSThomas Huth return; 1653fcf5ef2aSThomas Huth case 0x4028: /* shll16 Rn */ 1654fcf5ef2aSThomas Huth tcg_gen_shli_i32(REG(B11_8), REG(B11_8), 16); 1655fcf5ef2aSThomas Huth return; 1656fcf5ef2aSThomas Huth case 0x4009: /* shlr2 Rn */ 1657fcf5ef2aSThomas Huth tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 2); 1658fcf5ef2aSThomas Huth return; 1659fcf5ef2aSThomas Huth case 0x4019: /* shlr8 Rn */ 1660fcf5ef2aSThomas Huth tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 8); 1661fcf5ef2aSThomas Huth return; 1662fcf5ef2aSThomas Huth case 0x4029: /* shlr16 Rn */ 1663fcf5ef2aSThomas Huth tcg_gen_shri_i32(REG(B11_8), REG(B11_8), 16); 1664fcf5ef2aSThomas Huth return; 1665fcf5ef2aSThomas Huth case 0x401b: /* tas.b @Rn */ 1666fcf5ef2aSThomas Huth { 1667cb32f179SAurelien Jarno TCGv val = tcg_const_i32(0x80); 1668cb32f179SAurelien Jarno tcg_gen_atomic_fetch_or_i32(val, REG(B11_8), val, 1669cb32f179SAurelien Jarno ctx->memidx, MO_UB); 1670fcf5ef2aSThomas Huth tcg_gen_setcondi_i32(TCG_COND_EQ, cpu_sr_t, val, 0); 1671fcf5ef2aSThomas Huth tcg_temp_free(val); 1672fcf5ef2aSThomas Huth } 1673fcf5ef2aSThomas Huth return; 1674fcf5ef2aSThomas Huth case 0xf00d: /* fsts FPUL,FRn - FPSCR: Nothing */ 1675fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 16767c9f7038SRichard Henderson tcg_gen_mov_i32(FREG(B11_8), cpu_fpul); 1677fcf5ef2aSThomas Huth return; 1678fcf5ef2aSThomas Huth case 0xf01d: /* flds FRm,FPUL - FPSCR: Nothing */ 1679fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 16807c9f7038SRichard Henderson tcg_gen_mov_i32(cpu_fpul, FREG(B11_8)); 1681fcf5ef2aSThomas Huth return; 1682fcf5ef2aSThomas Huth case 0xf02d: /* float FPUL,FRn/DRn - FPSCR: R[PR,Enable.I]/W[Cause,Flag] */ 1683fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1684a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_PR) { 1685fcf5ef2aSThomas Huth TCGv_i64 fp; 1686fcf5ef2aSThomas Huth if (ctx->opcode & 0x0100) 1687fcf5ef2aSThomas Huth break; /* illegal instruction */ 1688fcf5ef2aSThomas Huth fp = tcg_temp_new_i64(); 1689fcf5ef2aSThomas Huth gen_helper_float_DT(fp, cpu_env, cpu_fpul); 16901e0b21d8SRichard Henderson gen_store_fpr64(ctx, fp, B11_8); 1691fcf5ef2aSThomas Huth tcg_temp_free_i64(fp); 1692fcf5ef2aSThomas Huth } 1693fcf5ef2aSThomas Huth else { 16947c9f7038SRichard Henderson gen_helper_float_FT(FREG(B11_8), cpu_env, cpu_fpul); 1695fcf5ef2aSThomas Huth } 1696fcf5ef2aSThomas Huth return; 1697fcf5ef2aSThomas Huth case 0xf03d: /* ftrc FRm/DRm,FPUL - FPSCR: R[PR,Enable.V]/W[Cause,Flag] */ 1698fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1699a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_PR) { 1700fcf5ef2aSThomas Huth TCGv_i64 fp; 1701fcf5ef2aSThomas Huth if (ctx->opcode & 0x0100) 1702fcf5ef2aSThomas Huth break; /* illegal instruction */ 1703fcf5ef2aSThomas Huth fp = tcg_temp_new_i64(); 17041e0b21d8SRichard Henderson gen_load_fpr64(ctx, fp, B11_8); 1705fcf5ef2aSThomas Huth gen_helper_ftrc_DT(cpu_fpul, cpu_env, fp); 1706fcf5ef2aSThomas Huth tcg_temp_free_i64(fp); 1707fcf5ef2aSThomas Huth } 1708fcf5ef2aSThomas Huth else { 17097c9f7038SRichard Henderson gen_helper_ftrc_FT(cpu_fpul, cpu_env, FREG(B11_8)); 1710fcf5ef2aSThomas Huth } 1711fcf5ef2aSThomas Huth return; 1712fcf5ef2aSThomas Huth case 0xf04d: /* fneg FRn/DRn - FPSCR: Nothing */ 1713fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 17147c9f7038SRichard Henderson tcg_gen_xori_i32(FREG(B11_8), FREG(B11_8), 0x80000000); 1715fcf5ef2aSThomas Huth return; 171657f5c1b0SAurelien Jarno case 0xf05d: /* fabs FRn/DRn - FPCSR: Nothing */ 1717fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 17187c9f7038SRichard Henderson tcg_gen_andi_i32(FREG(B11_8), FREG(B11_8), 0x7fffffff); 1719fcf5ef2aSThomas Huth return; 1720fcf5ef2aSThomas Huth case 0xf06d: /* fsqrt FRn */ 1721fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1722a6215749SAurelien Jarno if (ctx->tbflags & FPSCR_PR) { 1723fcf5ef2aSThomas Huth if (ctx->opcode & 0x0100) 1724fcf5ef2aSThomas Huth break; /* illegal instruction */ 1725fcf5ef2aSThomas Huth TCGv_i64 fp = tcg_temp_new_i64(); 17261e0b21d8SRichard Henderson gen_load_fpr64(ctx, fp, B11_8); 1727fcf5ef2aSThomas Huth gen_helper_fsqrt_DT(fp, cpu_env, fp); 17281e0b21d8SRichard Henderson gen_store_fpr64(ctx, fp, B11_8); 1729fcf5ef2aSThomas Huth tcg_temp_free_i64(fp); 1730fcf5ef2aSThomas Huth } else { 17317c9f7038SRichard Henderson gen_helper_fsqrt_FT(FREG(B11_8), cpu_env, FREG(B11_8)); 1732fcf5ef2aSThomas Huth } 1733fcf5ef2aSThomas Huth return; 1734fcf5ef2aSThomas Huth case 0xf07d: /* fsrra FRn */ 1735fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1736fcf5ef2aSThomas Huth break; 1737fcf5ef2aSThomas Huth case 0xf08d: /* fldi0 FRn - FPSCR: R[PR] */ 1738fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1739a6215749SAurelien Jarno if (!(ctx->tbflags & FPSCR_PR)) { 17407c9f7038SRichard Henderson tcg_gen_movi_i32(FREG(B11_8), 0); 1741fcf5ef2aSThomas Huth } 1742fcf5ef2aSThomas Huth return; 1743fcf5ef2aSThomas Huth case 0xf09d: /* fldi1 FRn - FPSCR: R[PR] */ 1744fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1745a6215749SAurelien Jarno if (!(ctx->tbflags & FPSCR_PR)) { 17467c9f7038SRichard Henderson tcg_gen_movi_i32(FREG(B11_8), 0x3f800000); 1747fcf5ef2aSThomas Huth } 1748fcf5ef2aSThomas Huth return; 1749fcf5ef2aSThomas Huth case 0xf0ad: /* fcnvsd FPUL,DRn */ 1750fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1751fcf5ef2aSThomas Huth { 1752fcf5ef2aSThomas Huth TCGv_i64 fp = tcg_temp_new_i64(); 1753fcf5ef2aSThomas Huth gen_helper_fcnvsd_FT_DT(fp, cpu_env, cpu_fpul); 17541e0b21d8SRichard Henderson gen_store_fpr64(ctx, fp, B11_8); 1755fcf5ef2aSThomas Huth tcg_temp_free_i64(fp); 1756fcf5ef2aSThomas Huth } 1757fcf5ef2aSThomas Huth return; 1758fcf5ef2aSThomas Huth case 0xf0bd: /* fcnvds DRn,FPUL */ 1759fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1760fcf5ef2aSThomas Huth { 1761fcf5ef2aSThomas Huth TCGv_i64 fp = tcg_temp_new_i64(); 17621e0b21d8SRichard Henderson gen_load_fpr64(ctx, fp, B11_8); 1763fcf5ef2aSThomas Huth gen_helper_fcnvds_DT_FT(cpu_fpul, cpu_env, fp); 1764fcf5ef2aSThomas Huth tcg_temp_free_i64(fp); 1765fcf5ef2aSThomas Huth } 1766fcf5ef2aSThomas Huth return; 1767fcf5ef2aSThomas Huth case 0xf0ed: /* fipr FVm,FVn */ 1768fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1769a6215749SAurelien Jarno if ((ctx->tbflags & FPSCR_PR) == 0) { 1770fcf5ef2aSThomas Huth TCGv m, n; 1771fcf5ef2aSThomas Huth m = tcg_const_i32((ctx->opcode >> 8) & 3); 1772fcf5ef2aSThomas Huth n = tcg_const_i32((ctx->opcode >> 10) & 3); 1773fcf5ef2aSThomas Huth gen_helper_fipr(cpu_env, m, n); 1774fcf5ef2aSThomas Huth tcg_temp_free(m); 1775fcf5ef2aSThomas Huth tcg_temp_free(n); 1776fcf5ef2aSThomas Huth return; 1777fcf5ef2aSThomas Huth } 1778fcf5ef2aSThomas Huth break; 1779fcf5ef2aSThomas Huth case 0xf0fd: /* ftrv XMTRX,FVn */ 1780fcf5ef2aSThomas Huth CHECK_FPU_ENABLED 1781fcf5ef2aSThomas Huth if ((ctx->opcode & 0x0300) == 0x0100 && 1782a6215749SAurelien Jarno (ctx->tbflags & FPSCR_PR) == 0) { 1783fcf5ef2aSThomas Huth TCGv n; 1784fcf5ef2aSThomas Huth n = tcg_const_i32((ctx->opcode >> 10) & 3); 1785fcf5ef2aSThomas Huth gen_helper_ftrv(cpu_env, n); 1786fcf5ef2aSThomas Huth tcg_temp_free(n); 1787fcf5ef2aSThomas Huth return; 1788fcf5ef2aSThomas Huth } 1789fcf5ef2aSThomas Huth break; 1790fcf5ef2aSThomas Huth } 1791fcf5ef2aSThomas Huth #if 0 1792fcf5ef2aSThomas Huth fprintf(stderr, "unknown instruction 0x%04x at pc 0x%08x\n", 1793fcf5ef2aSThomas Huth ctx->opcode, ctx->pc); 1794fcf5ef2aSThomas Huth fflush(stderr); 1795fcf5ef2aSThomas Huth #endif 17969a562ae7SAurelien Jarno if (ctx->envflags & DELAY_SLOT_MASK) { 1797*dec16c6eSRichard Henderson do_illegal_slot: 1798*dec16c6eSRichard Henderson gen_save_cpu_state(ctx, true); 1799fcf5ef2aSThomas Huth gen_helper_raise_slot_illegal_instruction(cpu_env); 1800fcf5ef2aSThomas Huth } else { 1801*dec16c6eSRichard Henderson gen_save_cpu_state(ctx, true); 1802fcf5ef2aSThomas Huth gen_helper_raise_illegal_instruction(cpu_env); 1803fcf5ef2aSThomas Huth } 180463205665SAurelien Jarno ctx->bstate = BS_EXCP; 1805fcf5ef2aSThomas Huth } 1806fcf5ef2aSThomas Huth 1807fcf5ef2aSThomas Huth static void decode_opc(DisasContext * ctx) 1808fcf5ef2aSThomas Huth { 1809a6215749SAurelien Jarno uint32_t old_flags = ctx->envflags; 1810fcf5ef2aSThomas Huth 1811fcf5ef2aSThomas Huth _decode_opc(ctx); 1812fcf5ef2aSThomas Huth 18139a562ae7SAurelien Jarno if (old_flags & DELAY_SLOT_MASK) { 1814fcf5ef2aSThomas Huth /* go out of the delay slot */ 18159a562ae7SAurelien Jarno ctx->envflags &= ~DELAY_SLOT_MASK; 18164bfa602bSRichard Henderson 18174bfa602bSRichard Henderson /* When in an exclusive region, we must continue to the end 18184bfa602bSRichard Henderson for conditional branches. */ 18194bfa602bSRichard Henderson if (ctx->tbflags & GUSA_EXCLUSIVE 18204bfa602bSRichard Henderson && old_flags & DELAY_SLOT_CONDITIONAL) { 18214bfa602bSRichard Henderson gen_delayed_conditional_jump(ctx); 18224bfa602bSRichard Henderson return; 18234bfa602bSRichard Henderson } 18244bfa602bSRichard Henderson /* Otherwise this is probably an invalid gUSA region. 18254bfa602bSRichard Henderson Drop the GUSA bits so the next TB doesn't see them. */ 18264bfa602bSRichard Henderson ctx->envflags &= ~GUSA_MASK; 18274bfa602bSRichard Henderson 1828ac9707eaSAurelien Jarno tcg_gen_movi_i32(cpu_flags, ctx->envflags); 1829fcf5ef2aSThomas Huth ctx->bstate = BS_BRANCH; 1830fcf5ef2aSThomas Huth if (old_flags & DELAY_SLOT_CONDITIONAL) { 1831fcf5ef2aSThomas Huth gen_delayed_conditional_jump(ctx); 1832be53081aSAurelien Jarno } else { 1833fcf5ef2aSThomas Huth gen_jump(ctx); 1834fcf5ef2aSThomas Huth } 18354bfa602bSRichard Henderson } 18364bfa602bSRichard Henderson } 1837fcf5ef2aSThomas Huth 18384bfa602bSRichard Henderson #ifdef CONFIG_USER_ONLY 18394bfa602bSRichard Henderson /* For uniprocessors, SH4 uses optimistic restartable atomic sequences. 18404bfa602bSRichard Henderson Upon an interrupt, a real kernel would simply notice magic values in 18414bfa602bSRichard Henderson the registers and reset the PC to the start of the sequence. 18424bfa602bSRichard Henderson 18434bfa602bSRichard Henderson For QEMU, we cannot do this in quite the same way. Instead, we notice 18444bfa602bSRichard Henderson the normal start of such a sequence (mov #-x,r15). While we can handle 18454bfa602bSRichard Henderson any sequence via cpu_exec_step_atomic, we can recognize the "normal" 18464bfa602bSRichard Henderson sequences and transform them into atomic operations as seen by the host. 18474bfa602bSRichard Henderson */ 18484bfa602bSRichard Henderson static int decode_gusa(DisasContext *ctx, CPUSH4State *env, int *pmax_insns) 18494bfa602bSRichard Henderson { 1850d6a6cffdSRichard Henderson uint16_t insns[5]; 1851d6a6cffdSRichard Henderson int ld_adr, ld_dst, ld_mop; 1852d6a6cffdSRichard Henderson int op_dst, op_src, op_opc; 1853d6a6cffdSRichard Henderson int mv_src, mt_dst, st_src, st_mop; 1854d6a6cffdSRichard Henderson TCGv op_arg; 1855d6a6cffdSRichard Henderson 18564bfa602bSRichard Henderson uint32_t pc = ctx->pc; 18574bfa602bSRichard Henderson uint32_t pc_end = ctx->tb->cs_base; 18584bfa602bSRichard Henderson int backup = sextract32(ctx->tbflags, GUSA_SHIFT, 8); 18594bfa602bSRichard Henderson int max_insns = (pc_end - pc) / 2; 1860d6a6cffdSRichard Henderson int i; 18614bfa602bSRichard Henderson 18624bfa602bSRichard Henderson if (pc != pc_end + backup || max_insns < 2) { 18634bfa602bSRichard Henderson /* This is a malformed gUSA region. Don't do anything special, 18644bfa602bSRichard Henderson since the interpreter is likely to get confused. */ 18654bfa602bSRichard Henderson ctx->envflags &= ~GUSA_MASK; 18664bfa602bSRichard Henderson return 0; 1867fcf5ef2aSThomas Huth } 18684bfa602bSRichard Henderson 18694bfa602bSRichard Henderson if (ctx->tbflags & GUSA_EXCLUSIVE) { 18704bfa602bSRichard Henderson /* Regardless of single-stepping or the end of the page, 18714bfa602bSRichard Henderson we must complete execution of the gUSA region while 18724bfa602bSRichard Henderson holding the exclusive lock. */ 18734bfa602bSRichard Henderson *pmax_insns = max_insns; 18744bfa602bSRichard Henderson return 0; 1875fcf5ef2aSThomas Huth } 1876fcf5ef2aSThomas Huth 1877d6a6cffdSRichard Henderson /* The state machine below will consume only a few insns. 1878d6a6cffdSRichard Henderson If there are more than that in a region, fail now. */ 1879d6a6cffdSRichard Henderson if (max_insns > ARRAY_SIZE(insns)) { 1880d6a6cffdSRichard Henderson goto fail; 1881d6a6cffdSRichard Henderson } 1882d6a6cffdSRichard Henderson 1883d6a6cffdSRichard Henderson /* Read all of the insns for the region. */ 1884d6a6cffdSRichard Henderson for (i = 0; i < max_insns; ++i) { 1885d6a6cffdSRichard Henderson insns[i] = cpu_lduw_code(env, pc + i * 2); 1886d6a6cffdSRichard Henderson } 1887d6a6cffdSRichard Henderson 1888d6a6cffdSRichard Henderson ld_adr = ld_dst = ld_mop = -1; 1889d6a6cffdSRichard Henderson mv_src = -1; 1890d6a6cffdSRichard Henderson op_dst = op_src = op_opc = -1; 1891d6a6cffdSRichard Henderson mt_dst = -1; 1892d6a6cffdSRichard Henderson st_src = st_mop = -1; 1893d6a6cffdSRichard Henderson TCGV_UNUSED(op_arg); 1894d6a6cffdSRichard Henderson i = 0; 1895d6a6cffdSRichard Henderson 1896d6a6cffdSRichard Henderson #define NEXT_INSN \ 1897d6a6cffdSRichard Henderson do { if (i >= max_insns) goto fail; ctx->opcode = insns[i++]; } while (0) 1898d6a6cffdSRichard Henderson 1899d6a6cffdSRichard Henderson /* 1900d6a6cffdSRichard Henderson * Expect a load to begin the region. 1901d6a6cffdSRichard Henderson */ 1902d6a6cffdSRichard Henderson NEXT_INSN; 1903d6a6cffdSRichard Henderson switch (ctx->opcode & 0xf00f) { 1904d6a6cffdSRichard Henderson case 0x6000: /* mov.b @Rm,Rn */ 1905d6a6cffdSRichard Henderson ld_mop = MO_SB; 1906d6a6cffdSRichard Henderson break; 1907d6a6cffdSRichard Henderson case 0x6001: /* mov.w @Rm,Rn */ 1908d6a6cffdSRichard Henderson ld_mop = MO_TESW; 1909d6a6cffdSRichard Henderson break; 1910d6a6cffdSRichard Henderson case 0x6002: /* mov.l @Rm,Rn */ 1911d6a6cffdSRichard Henderson ld_mop = MO_TESL; 1912d6a6cffdSRichard Henderson break; 1913d6a6cffdSRichard Henderson default: 1914d6a6cffdSRichard Henderson goto fail; 1915d6a6cffdSRichard Henderson } 1916d6a6cffdSRichard Henderson ld_adr = B7_4; 1917d6a6cffdSRichard Henderson ld_dst = B11_8; 1918d6a6cffdSRichard Henderson if (ld_adr == ld_dst) { 1919d6a6cffdSRichard Henderson goto fail; 1920d6a6cffdSRichard Henderson } 1921d6a6cffdSRichard Henderson /* Unless we see a mov, any two-operand operation must use ld_dst. */ 1922d6a6cffdSRichard Henderson op_dst = ld_dst; 1923d6a6cffdSRichard Henderson 1924d6a6cffdSRichard Henderson /* 1925d6a6cffdSRichard Henderson * Expect an optional register move. 1926d6a6cffdSRichard Henderson */ 1927d6a6cffdSRichard Henderson NEXT_INSN; 1928d6a6cffdSRichard Henderson switch (ctx->opcode & 0xf00f) { 1929d6a6cffdSRichard Henderson case 0x6003: /* mov Rm,Rn */ 1930d6a6cffdSRichard Henderson /* Here we want to recognize ld_dst being saved for later consumtion, 1931d6a6cffdSRichard Henderson or for another input register being copied so that ld_dst need not 1932d6a6cffdSRichard Henderson be clobbered during the operation. */ 1933d6a6cffdSRichard Henderson op_dst = B11_8; 1934d6a6cffdSRichard Henderson mv_src = B7_4; 1935d6a6cffdSRichard Henderson if (op_dst == ld_dst) { 1936d6a6cffdSRichard Henderson /* Overwriting the load output. */ 1937d6a6cffdSRichard Henderson goto fail; 1938d6a6cffdSRichard Henderson } 1939d6a6cffdSRichard Henderson if (mv_src != ld_dst) { 1940d6a6cffdSRichard Henderson /* Copying a new input; constrain op_src to match the load. */ 1941d6a6cffdSRichard Henderson op_src = ld_dst; 1942d6a6cffdSRichard Henderson } 1943d6a6cffdSRichard Henderson break; 1944d6a6cffdSRichard Henderson 1945d6a6cffdSRichard Henderson default: 1946d6a6cffdSRichard Henderson /* Put back and re-examine as operation. */ 1947d6a6cffdSRichard Henderson --i; 1948d6a6cffdSRichard Henderson } 1949d6a6cffdSRichard Henderson 1950d6a6cffdSRichard Henderson /* 1951d6a6cffdSRichard Henderson * Expect the operation. 1952d6a6cffdSRichard Henderson */ 1953d6a6cffdSRichard Henderson NEXT_INSN; 1954d6a6cffdSRichard Henderson switch (ctx->opcode & 0xf00f) { 1955d6a6cffdSRichard Henderson case 0x300c: /* add Rm,Rn */ 1956d6a6cffdSRichard Henderson op_opc = INDEX_op_add_i32; 1957d6a6cffdSRichard Henderson goto do_reg_op; 1958d6a6cffdSRichard Henderson case 0x2009: /* and Rm,Rn */ 1959d6a6cffdSRichard Henderson op_opc = INDEX_op_and_i32; 1960d6a6cffdSRichard Henderson goto do_reg_op; 1961d6a6cffdSRichard Henderson case 0x200a: /* xor Rm,Rn */ 1962d6a6cffdSRichard Henderson op_opc = INDEX_op_xor_i32; 1963d6a6cffdSRichard Henderson goto do_reg_op; 1964d6a6cffdSRichard Henderson case 0x200b: /* or Rm,Rn */ 1965d6a6cffdSRichard Henderson op_opc = INDEX_op_or_i32; 1966d6a6cffdSRichard Henderson do_reg_op: 1967d6a6cffdSRichard Henderson /* The operation register should be as expected, and the 1968d6a6cffdSRichard Henderson other input cannot depend on the load. */ 1969d6a6cffdSRichard Henderson if (op_dst != B11_8) { 1970d6a6cffdSRichard Henderson goto fail; 1971d6a6cffdSRichard Henderson } 1972d6a6cffdSRichard Henderson if (op_src < 0) { 1973d6a6cffdSRichard Henderson /* Unconstrainted input. */ 1974d6a6cffdSRichard Henderson op_src = B7_4; 1975d6a6cffdSRichard Henderson } else if (op_src == B7_4) { 1976d6a6cffdSRichard Henderson /* Constrained input matched load. All operations are 1977d6a6cffdSRichard Henderson commutative; "swap" them by "moving" the load output 1978d6a6cffdSRichard Henderson to the (implicit) first argument and the move source 1979d6a6cffdSRichard Henderson to the (explicit) second argument. */ 1980d6a6cffdSRichard Henderson op_src = mv_src; 1981d6a6cffdSRichard Henderson } else { 1982d6a6cffdSRichard Henderson goto fail; 1983d6a6cffdSRichard Henderson } 1984d6a6cffdSRichard Henderson op_arg = REG(op_src); 1985d6a6cffdSRichard Henderson break; 1986d6a6cffdSRichard Henderson 1987d6a6cffdSRichard Henderson case 0x6007: /* not Rm,Rn */ 1988d6a6cffdSRichard Henderson if (ld_dst != B7_4 || mv_src >= 0) { 1989d6a6cffdSRichard Henderson goto fail; 1990d6a6cffdSRichard Henderson } 1991d6a6cffdSRichard Henderson op_dst = B11_8; 1992d6a6cffdSRichard Henderson op_opc = INDEX_op_xor_i32; 1993d6a6cffdSRichard Henderson op_arg = tcg_const_i32(-1); 1994d6a6cffdSRichard Henderson break; 1995d6a6cffdSRichard Henderson 1996d6a6cffdSRichard Henderson case 0x7000 ... 0x700f: /* add #imm,Rn */ 1997d6a6cffdSRichard Henderson if (op_dst != B11_8 || mv_src >= 0) { 1998d6a6cffdSRichard Henderson goto fail; 1999d6a6cffdSRichard Henderson } 2000d6a6cffdSRichard Henderson op_opc = INDEX_op_add_i32; 2001d6a6cffdSRichard Henderson op_arg = tcg_const_i32(B7_0s); 2002d6a6cffdSRichard Henderson break; 2003d6a6cffdSRichard Henderson 2004d6a6cffdSRichard Henderson case 0x3000: /* cmp/eq Rm,Rn */ 2005d6a6cffdSRichard Henderson /* Looking for the middle of a compare-and-swap sequence, 2006d6a6cffdSRichard Henderson beginning with the compare. Operands can be either order, 2007d6a6cffdSRichard Henderson but with only one overlapping the load. */ 2008d6a6cffdSRichard Henderson if ((ld_dst == B11_8) + (ld_dst == B7_4) != 1 || mv_src >= 0) { 2009d6a6cffdSRichard Henderson goto fail; 2010d6a6cffdSRichard Henderson } 2011d6a6cffdSRichard Henderson op_opc = INDEX_op_setcond_i32; /* placeholder */ 2012d6a6cffdSRichard Henderson op_src = (ld_dst == B11_8 ? B7_4 : B11_8); 2013d6a6cffdSRichard Henderson op_arg = REG(op_src); 2014d6a6cffdSRichard Henderson 2015d6a6cffdSRichard Henderson NEXT_INSN; 2016d6a6cffdSRichard Henderson switch (ctx->opcode & 0xff00) { 2017d6a6cffdSRichard Henderson case 0x8b00: /* bf label */ 2018d6a6cffdSRichard Henderson case 0x8f00: /* bf/s label */ 2019d6a6cffdSRichard Henderson if (pc + (i + 1 + B7_0s) * 2 != pc_end) { 2020d6a6cffdSRichard Henderson goto fail; 2021d6a6cffdSRichard Henderson } 2022d6a6cffdSRichard Henderson if ((ctx->opcode & 0xff00) == 0x8b00) { /* bf label */ 2023d6a6cffdSRichard Henderson break; 2024d6a6cffdSRichard Henderson } 2025d6a6cffdSRichard Henderson /* We're looking to unconditionally modify Rn with the 2026d6a6cffdSRichard Henderson result of the comparison, within the delay slot of 2027d6a6cffdSRichard Henderson the branch. This is used by older gcc. */ 2028d6a6cffdSRichard Henderson NEXT_INSN; 2029d6a6cffdSRichard Henderson if ((ctx->opcode & 0xf0ff) == 0x0029) { /* movt Rn */ 2030d6a6cffdSRichard Henderson mt_dst = B11_8; 2031d6a6cffdSRichard Henderson } else { 2032d6a6cffdSRichard Henderson goto fail; 2033d6a6cffdSRichard Henderson } 2034d6a6cffdSRichard Henderson break; 2035d6a6cffdSRichard Henderson 2036d6a6cffdSRichard Henderson default: 2037d6a6cffdSRichard Henderson goto fail; 2038d6a6cffdSRichard Henderson } 2039d6a6cffdSRichard Henderson break; 2040d6a6cffdSRichard Henderson 2041d6a6cffdSRichard Henderson case 0x2008: /* tst Rm,Rn */ 2042d6a6cffdSRichard Henderson /* Looking for a compare-and-swap against zero. */ 2043d6a6cffdSRichard Henderson if (ld_dst != B11_8 || ld_dst != B7_4 || mv_src >= 0) { 2044d6a6cffdSRichard Henderson goto fail; 2045d6a6cffdSRichard Henderson } 2046d6a6cffdSRichard Henderson op_opc = INDEX_op_setcond_i32; 2047d6a6cffdSRichard Henderson op_arg = tcg_const_i32(0); 2048d6a6cffdSRichard Henderson 2049d6a6cffdSRichard Henderson NEXT_INSN; 2050d6a6cffdSRichard Henderson if ((ctx->opcode & 0xff00) != 0x8900 /* bt label */ 2051d6a6cffdSRichard Henderson || pc + (i + 1 + B7_0s) * 2 != pc_end) { 2052d6a6cffdSRichard Henderson goto fail; 2053d6a6cffdSRichard Henderson } 2054d6a6cffdSRichard Henderson break; 2055d6a6cffdSRichard Henderson 2056d6a6cffdSRichard Henderson default: 2057d6a6cffdSRichard Henderson /* Put back and re-examine as store. */ 2058d6a6cffdSRichard Henderson --i; 2059d6a6cffdSRichard Henderson } 2060d6a6cffdSRichard Henderson 2061d6a6cffdSRichard Henderson /* 2062d6a6cffdSRichard Henderson * Expect the store. 2063d6a6cffdSRichard Henderson */ 2064d6a6cffdSRichard Henderson /* The store must be the last insn. */ 2065d6a6cffdSRichard Henderson if (i != max_insns - 1) { 2066d6a6cffdSRichard Henderson goto fail; 2067d6a6cffdSRichard Henderson } 2068d6a6cffdSRichard Henderson NEXT_INSN; 2069d6a6cffdSRichard Henderson switch (ctx->opcode & 0xf00f) { 2070d6a6cffdSRichard Henderson case 0x2000: /* mov.b Rm,@Rn */ 2071d6a6cffdSRichard Henderson st_mop = MO_UB; 2072d6a6cffdSRichard Henderson break; 2073d6a6cffdSRichard Henderson case 0x2001: /* mov.w Rm,@Rn */ 2074d6a6cffdSRichard Henderson st_mop = MO_UW; 2075d6a6cffdSRichard Henderson break; 2076d6a6cffdSRichard Henderson case 0x2002: /* mov.l Rm,@Rn */ 2077d6a6cffdSRichard Henderson st_mop = MO_UL; 2078d6a6cffdSRichard Henderson break; 2079d6a6cffdSRichard Henderson default: 2080d6a6cffdSRichard Henderson goto fail; 2081d6a6cffdSRichard Henderson } 2082d6a6cffdSRichard Henderson /* The store must match the load. */ 2083d6a6cffdSRichard Henderson if (ld_adr != B11_8 || st_mop != (ld_mop & MO_SIZE)) { 2084d6a6cffdSRichard Henderson goto fail; 2085d6a6cffdSRichard Henderson } 2086d6a6cffdSRichard Henderson st_src = B7_4; 2087d6a6cffdSRichard Henderson 2088d6a6cffdSRichard Henderson #undef NEXT_INSN 2089d6a6cffdSRichard Henderson 2090d6a6cffdSRichard Henderson /* 2091d6a6cffdSRichard Henderson * Emit the operation. 2092d6a6cffdSRichard Henderson */ 2093d6a6cffdSRichard Henderson tcg_gen_insn_start(pc, ctx->envflags); 2094d6a6cffdSRichard Henderson switch (op_opc) { 2095d6a6cffdSRichard Henderson case -1: 2096d6a6cffdSRichard Henderson /* No operation found. Look for exchange pattern. */ 2097d6a6cffdSRichard Henderson if (st_src == ld_dst || mv_src >= 0) { 2098d6a6cffdSRichard Henderson goto fail; 2099d6a6cffdSRichard Henderson } 2100d6a6cffdSRichard Henderson tcg_gen_atomic_xchg_i32(REG(ld_dst), REG(ld_adr), REG(st_src), 2101d6a6cffdSRichard Henderson ctx->memidx, ld_mop); 2102d6a6cffdSRichard Henderson break; 2103d6a6cffdSRichard Henderson 2104d6a6cffdSRichard Henderson case INDEX_op_add_i32: 2105d6a6cffdSRichard Henderson if (op_dst != st_src) { 2106d6a6cffdSRichard Henderson goto fail; 2107d6a6cffdSRichard Henderson } 2108d6a6cffdSRichard Henderson if (op_dst == ld_dst && st_mop == MO_UL) { 2109d6a6cffdSRichard Henderson tcg_gen_atomic_add_fetch_i32(REG(ld_dst), REG(ld_adr), 2110d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2111d6a6cffdSRichard Henderson } else { 2112d6a6cffdSRichard Henderson tcg_gen_atomic_fetch_add_i32(REG(ld_dst), REG(ld_adr), 2113d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2114d6a6cffdSRichard Henderson if (op_dst != ld_dst) { 2115d6a6cffdSRichard Henderson /* Note that mop sizes < 4 cannot use add_fetch 2116d6a6cffdSRichard Henderson because it won't carry into the higher bits. */ 2117d6a6cffdSRichard Henderson tcg_gen_add_i32(REG(op_dst), REG(ld_dst), op_arg); 2118d6a6cffdSRichard Henderson } 2119d6a6cffdSRichard Henderson } 2120d6a6cffdSRichard Henderson break; 2121d6a6cffdSRichard Henderson 2122d6a6cffdSRichard Henderson case INDEX_op_and_i32: 2123d6a6cffdSRichard Henderson if (op_dst != st_src) { 2124d6a6cffdSRichard Henderson goto fail; 2125d6a6cffdSRichard Henderson } 2126d6a6cffdSRichard Henderson if (op_dst == ld_dst) { 2127d6a6cffdSRichard Henderson tcg_gen_atomic_and_fetch_i32(REG(ld_dst), REG(ld_adr), 2128d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2129d6a6cffdSRichard Henderson } else { 2130d6a6cffdSRichard Henderson tcg_gen_atomic_fetch_and_i32(REG(ld_dst), REG(ld_adr), 2131d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2132d6a6cffdSRichard Henderson tcg_gen_and_i32(REG(op_dst), REG(ld_dst), op_arg); 2133d6a6cffdSRichard Henderson } 2134d6a6cffdSRichard Henderson break; 2135d6a6cffdSRichard Henderson 2136d6a6cffdSRichard Henderson case INDEX_op_or_i32: 2137d6a6cffdSRichard Henderson if (op_dst != st_src) { 2138d6a6cffdSRichard Henderson goto fail; 2139d6a6cffdSRichard Henderson } 2140d6a6cffdSRichard Henderson if (op_dst == ld_dst) { 2141d6a6cffdSRichard Henderson tcg_gen_atomic_or_fetch_i32(REG(ld_dst), REG(ld_adr), 2142d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2143d6a6cffdSRichard Henderson } else { 2144d6a6cffdSRichard Henderson tcg_gen_atomic_fetch_or_i32(REG(ld_dst), REG(ld_adr), 2145d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2146d6a6cffdSRichard Henderson tcg_gen_or_i32(REG(op_dst), REG(ld_dst), op_arg); 2147d6a6cffdSRichard Henderson } 2148d6a6cffdSRichard Henderson break; 2149d6a6cffdSRichard Henderson 2150d6a6cffdSRichard Henderson case INDEX_op_xor_i32: 2151d6a6cffdSRichard Henderson if (op_dst != st_src) { 2152d6a6cffdSRichard Henderson goto fail; 2153d6a6cffdSRichard Henderson } 2154d6a6cffdSRichard Henderson if (op_dst == ld_dst) { 2155d6a6cffdSRichard Henderson tcg_gen_atomic_xor_fetch_i32(REG(ld_dst), REG(ld_adr), 2156d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2157d6a6cffdSRichard Henderson } else { 2158d6a6cffdSRichard Henderson tcg_gen_atomic_fetch_xor_i32(REG(ld_dst), REG(ld_adr), 2159d6a6cffdSRichard Henderson op_arg, ctx->memidx, ld_mop); 2160d6a6cffdSRichard Henderson tcg_gen_xor_i32(REG(op_dst), REG(ld_dst), op_arg); 2161d6a6cffdSRichard Henderson } 2162d6a6cffdSRichard Henderson break; 2163d6a6cffdSRichard Henderson 2164d6a6cffdSRichard Henderson case INDEX_op_setcond_i32: 2165d6a6cffdSRichard Henderson if (st_src == ld_dst) { 2166d6a6cffdSRichard Henderson goto fail; 2167d6a6cffdSRichard Henderson } 2168d6a6cffdSRichard Henderson tcg_gen_atomic_cmpxchg_i32(REG(ld_dst), REG(ld_adr), op_arg, 2169d6a6cffdSRichard Henderson REG(st_src), ctx->memidx, ld_mop); 2170d6a6cffdSRichard Henderson tcg_gen_setcond_i32(TCG_COND_EQ, cpu_sr_t, REG(ld_dst), op_arg); 2171d6a6cffdSRichard Henderson if (mt_dst >= 0) { 2172d6a6cffdSRichard Henderson tcg_gen_mov_i32(REG(mt_dst), cpu_sr_t); 2173d6a6cffdSRichard Henderson } 2174d6a6cffdSRichard Henderson break; 2175d6a6cffdSRichard Henderson 2176d6a6cffdSRichard Henderson default: 2177d6a6cffdSRichard Henderson g_assert_not_reached(); 2178d6a6cffdSRichard Henderson } 2179d6a6cffdSRichard Henderson 2180d6a6cffdSRichard Henderson /* If op_src is not a valid register, then op_arg was a constant. */ 2181d6a6cffdSRichard Henderson if (op_src < 0) { 2182d6a6cffdSRichard Henderson tcg_temp_free_i32(op_arg); 2183d6a6cffdSRichard Henderson } 2184d6a6cffdSRichard Henderson 2185d6a6cffdSRichard Henderson /* The entire region has been translated. */ 2186d6a6cffdSRichard Henderson ctx->envflags &= ~GUSA_MASK; 2187d6a6cffdSRichard Henderson ctx->pc = pc_end; 2188d6a6cffdSRichard Henderson return max_insns; 2189d6a6cffdSRichard Henderson 2190d6a6cffdSRichard Henderson fail: 21914bfa602bSRichard Henderson qemu_log_mask(LOG_UNIMP, "Unrecognized gUSA sequence %08x-%08x\n", 21924bfa602bSRichard Henderson pc, pc_end); 21934bfa602bSRichard Henderson 21944bfa602bSRichard Henderson /* Restart with the EXCLUSIVE bit set, within a TB run via 21954bfa602bSRichard Henderson cpu_exec_step_atomic holding the exclusive lock. */ 21964bfa602bSRichard Henderson tcg_gen_insn_start(pc, ctx->envflags); 21974bfa602bSRichard Henderson ctx->envflags |= GUSA_EXCLUSIVE; 21984bfa602bSRichard Henderson gen_save_cpu_state(ctx, false); 21994bfa602bSRichard Henderson gen_helper_exclusive(cpu_env); 22004bfa602bSRichard Henderson ctx->bstate = BS_EXCP; 22014bfa602bSRichard Henderson 22024bfa602bSRichard Henderson /* We're not executing an instruction, but we must report one for the 22034bfa602bSRichard Henderson purposes of accounting within the TB. We might as well report the 22044bfa602bSRichard Henderson entire region consumed via ctx->pc so that it's immediately available 22054bfa602bSRichard Henderson in the disassembly dump. */ 22064bfa602bSRichard Henderson ctx->pc = pc_end; 22074bfa602bSRichard Henderson return 1; 22084bfa602bSRichard Henderson } 22094bfa602bSRichard Henderson #endif 22104bfa602bSRichard Henderson 2211fcf5ef2aSThomas Huth void gen_intermediate_code(CPUSH4State * env, struct TranslationBlock *tb) 2212fcf5ef2aSThomas Huth { 2213fcf5ef2aSThomas Huth SuperHCPU *cpu = sh_env_get_cpu(env); 2214fcf5ef2aSThomas Huth CPUState *cs = CPU(cpu); 2215fcf5ef2aSThomas Huth DisasContext ctx; 2216fcf5ef2aSThomas Huth target_ulong pc_start; 2217fcf5ef2aSThomas Huth int num_insns; 2218fcf5ef2aSThomas Huth int max_insns; 2219fcf5ef2aSThomas Huth 2220fcf5ef2aSThomas Huth pc_start = tb->pc; 2221fcf5ef2aSThomas Huth ctx.pc = pc_start; 2222a6215749SAurelien Jarno ctx.tbflags = (uint32_t)tb->flags; 2223e1933d14SRichard Henderson ctx.envflags = tb->flags & TB_FLAG_ENVFLAGS_MASK; 2224fcf5ef2aSThomas Huth ctx.bstate = BS_NONE; 2225a6215749SAurelien Jarno ctx.memidx = (ctx.tbflags & (1u << SR_MD)) == 0 ? 1 : 0; 2226fcf5ef2aSThomas Huth /* We don't know if the delayed pc came from a dynamic or static branch, 2227fcf5ef2aSThomas Huth so assume it is a dynamic branch. */ 2228fcf5ef2aSThomas Huth ctx.delayed_pc = -1; /* use delayed pc from env pointer */ 2229fcf5ef2aSThomas Huth ctx.tb = tb; 2230fcf5ef2aSThomas Huth ctx.singlestep_enabled = cs->singlestep_enabled; 2231fcf5ef2aSThomas Huth ctx.features = env->features; 2232a6215749SAurelien Jarno ctx.has_movcal = (ctx.tbflags & TB_FLAG_PENDING_MOVCA); 22333a3bb8d2SRichard Henderson ctx.gbank = ((ctx.tbflags & (1 << SR_MD)) && 22343a3bb8d2SRichard Henderson (ctx.tbflags & (1 << SR_RB))) * 0x10; 22355c13bad9SRichard Henderson ctx.fbank = ctx.tbflags & FPSCR_FR ? 0x10 : 0; 2236fcf5ef2aSThomas Huth 2237fcf5ef2aSThomas Huth max_insns = tb->cflags & CF_COUNT_MASK; 2238fcf5ef2aSThomas Huth if (max_insns == 0) { 2239fcf5ef2aSThomas Huth max_insns = CF_COUNT_MASK; 2240fcf5ef2aSThomas Huth } 22414448a836SRichard Henderson max_insns = MIN(max_insns, TCG_MAX_INSNS); 22424448a836SRichard Henderson 22434448a836SRichard Henderson /* Since the ISA is fixed-width, we can bound by the number 22444448a836SRichard Henderson of instructions remaining on the page. */ 22454448a836SRichard Henderson num_insns = -(ctx.pc | TARGET_PAGE_MASK) / 2; 22464448a836SRichard Henderson max_insns = MIN(max_insns, num_insns); 22474448a836SRichard Henderson 22484448a836SRichard Henderson /* Single stepping means just that. */ 22494448a836SRichard Henderson if (ctx.singlestep_enabled || singlestep) { 22504448a836SRichard Henderson max_insns = 1; 2251fcf5ef2aSThomas Huth } 2252fcf5ef2aSThomas Huth 2253fcf5ef2aSThomas Huth gen_tb_start(tb); 22544448a836SRichard Henderson num_insns = 0; 22554448a836SRichard Henderson 22564bfa602bSRichard Henderson #ifdef CONFIG_USER_ONLY 22574bfa602bSRichard Henderson if (ctx.tbflags & GUSA_MASK) { 22584bfa602bSRichard Henderson num_insns = decode_gusa(&ctx, env, &max_insns); 22594bfa602bSRichard Henderson } 22604bfa602bSRichard Henderson #endif 22614bfa602bSRichard Henderson 22624448a836SRichard Henderson while (ctx.bstate == BS_NONE 22634448a836SRichard Henderson && num_insns < max_insns 22644448a836SRichard Henderson && !tcg_op_buf_full()) { 2265a6215749SAurelien Jarno tcg_gen_insn_start(ctx.pc, ctx.envflags); 2266fcf5ef2aSThomas Huth num_insns++; 2267fcf5ef2aSThomas Huth 2268fcf5ef2aSThomas Huth if (unlikely(cpu_breakpoint_test(cs, ctx.pc, BP_ANY))) { 2269fcf5ef2aSThomas Huth /* We have hit a breakpoint - make sure PC is up-to-date */ 2270ac9707eaSAurelien Jarno gen_save_cpu_state(&ctx, true); 2271fcf5ef2aSThomas Huth gen_helper_debug(cpu_env); 227263205665SAurelien Jarno ctx.bstate = BS_EXCP; 2273fcf5ef2aSThomas Huth /* The address covered by the breakpoint must be included in 2274fcf5ef2aSThomas Huth [tb->pc, tb->pc + tb->size) in order to for it to be 2275fcf5ef2aSThomas Huth properly cleared -- thus we increment the PC here so that 2276fcf5ef2aSThomas Huth the logic setting tb->size below does the right thing. */ 2277fcf5ef2aSThomas Huth ctx.pc += 2; 2278fcf5ef2aSThomas Huth break; 2279fcf5ef2aSThomas Huth } 2280fcf5ef2aSThomas Huth 2281fcf5ef2aSThomas Huth if (num_insns == max_insns && (tb->cflags & CF_LAST_IO)) { 2282fcf5ef2aSThomas Huth gen_io_start(); 2283fcf5ef2aSThomas Huth } 2284fcf5ef2aSThomas Huth 2285fcf5ef2aSThomas Huth ctx.opcode = cpu_lduw_code(env, ctx.pc); 2286fcf5ef2aSThomas Huth decode_opc(&ctx); 2287fcf5ef2aSThomas Huth ctx.pc += 2; 2288fcf5ef2aSThomas Huth } 22894448a836SRichard Henderson if (tb->cflags & CF_LAST_IO) { 2290fcf5ef2aSThomas Huth gen_io_end(); 22914448a836SRichard Henderson } 22924bfa602bSRichard Henderson 22934bfa602bSRichard Henderson if (ctx.tbflags & GUSA_EXCLUSIVE) { 22944bfa602bSRichard Henderson /* Ending the region of exclusivity. Clear the bits. */ 22954bfa602bSRichard Henderson ctx.envflags &= ~GUSA_MASK; 22964bfa602bSRichard Henderson } 22974bfa602bSRichard Henderson 2298fcf5ef2aSThomas Huth if (cs->singlestep_enabled) { 2299ac9707eaSAurelien Jarno gen_save_cpu_state(&ctx, true); 2300fcf5ef2aSThomas Huth gen_helper_debug(cpu_env); 2301fcf5ef2aSThomas Huth } else { 2302fcf5ef2aSThomas Huth switch (ctx.bstate) { 2303fcf5ef2aSThomas Huth case BS_STOP: 2304ac9707eaSAurelien Jarno gen_save_cpu_state(&ctx, true); 23050fc37a8bSAurelien Jarno tcg_gen_exit_tb(0); 23060fc37a8bSAurelien Jarno break; 2307fcf5ef2aSThomas Huth case BS_NONE: 2308ac9707eaSAurelien Jarno gen_save_cpu_state(&ctx, false); 2309fcf5ef2aSThomas Huth gen_goto_tb(&ctx, 0, ctx.pc); 2310fcf5ef2aSThomas Huth break; 2311fcf5ef2aSThomas Huth case BS_EXCP: 231263205665SAurelien Jarno /* fall through */ 2313fcf5ef2aSThomas Huth case BS_BRANCH: 2314fcf5ef2aSThomas Huth default: 2315fcf5ef2aSThomas Huth break; 2316fcf5ef2aSThomas Huth } 2317fcf5ef2aSThomas Huth } 2318fcf5ef2aSThomas Huth 2319fcf5ef2aSThomas Huth gen_tb_end(tb, num_insns); 2320fcf5ef2aSThomas Huth 2321fcf5ef2aSThomas Huth tb->size = ctx.pc - pc_start; 2322fcf5ef2aSThomas Huth tb->icount = num_insns; 2323fcf5ef2aSThomas Huth 2324fcf5ef2aSThomas Huth #ifdef DEBUG_DISAS 2325fcf5ef2aSThomas Huth if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) 2326fcf5ef2aSThomas Huth && qemu_log_in_addr_range(pc_start)) { 2327fcf5ef2aSThomas Huth qemu_log_lock(); 2328fcf5ef2aSThomas Huth qemu_log("IN:\n"); /* , lookup_symbol(pc_start)); */ 2329fcf5ef2aSThomas Huth log_target_disas(cs, pc_start, ctx.pc - pc_start, 0); 2330fcf5ef2aSThomas Huth qemu_log("\n"); 2331fcf5ef2aSThomas Huth qemu_log_unlock(); 2332fcf5ef2aSThomas Huth } 2333fcf5ef2aSThomas Huth #endif 2334fcf5ef2aSThomas Huth } 2335fcf5ef2aSThomas Huth 2336fcf5ef2aSThomas Huth void restore_state_to_opc(CPUSH4State *env, TranslationBlock *tb, 2337fcf5ef2aSThomas Huth target_ulong *data) 2338fcf5ef2aSThomas Huth { 2339fcf5ef2aSThomas Huth env->pc = data[0]; 2340fcf5ef2aSThomas Huth env->flags = data[1]; 2341ac9707eaSAurelien Jarno /* Theoretically delayed_pc should also be restored. In practice the 2342ac9707eaSAurelien Jarno branch instruction is re-executed after exception, so the delayed 2343ac9707eaSAurelien Jarno branch target will be recomputed. */ 2344fcf5ef2aSThomas Huth } 2345