1fcf5ef2aSThomas Huth /* 2fcf5ef2aSThomas Huth * Xilinx MicroBlaze emulation for qemu: main translation routines. 3fcf5ef2aSThomas Huth * 4fcf5ef2aSThomas Huth * Copyright (c) 2009 Edgar E. Iglesias. 5fcf5ef2aSThomas Huth * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd. 6fcf5ef2aSThomas Huth * 7fcf5ef2aSThomas Huth * This library is free software; you can redistribute it and/or 8fcf5ef2aSThomas Huth * modify it under the terms of the GNU Lesser General Public 9fcf5ef2aSThomas Huth * License as published by the Free Software Foundation; either 10fcf5ef2aSThomas Huth * version 2 of the License, or (at your option) any later version. 11fcf5ef2aSThomas Huth * 12fcf5ef2aSThomas Huth * This library is distributed in the hope that it will be useful, 13fcf5ef2aSThomas Huth * but WITHOUT ANY WARRANTY; without even the implied warranty of 14fcf5ef2aSThomas Huth * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15fcf5ef2aSThomas Huth * Lesser General Public License for more details. 16fcf5ef2aSThomas Huth * 17fcf5ef2aSThomas Huth * You should have received a copy of the GNU Lesser General Public 18fcf5ef2aSThomas Huth * License along with this library; if not, see <http://www.gnu.org/licenses/>. 19fcf5ef2aSThomas Huth */ 20fcf5ef2aSThomas Huth 21fcf5ef2aSThomas Huth #include "qemu/osdep.h" 22fcf5ef2aSThomas Huth #include "cpu.h" 23fcf5ef2aSThomas Huth #include "disas/disas.h" 24fcf5ef2aSThomas Huth #include "exec/exec-all.h" 25dcb32f1dSPhilippe Mathieu-Daudé #include "tcg/tcg-op.h" 26fcf5ef2aSThomas Huth #include "exec/helper-proto.h" 27fcf5ef2aSThomas Huth #include "microblaze-decode.h" 28fcf5ef2aSThomas Huth #include "exec/cpu_ldst.h" 29fcf5ef2aSThomas Huth #include "exec/helper-gen.h" 3077fc6f5eSLluís Vilanova #include "exec/translator.h" 3190c84c56SMarkus Armbruster #include "qemu/qemu-print.h" 32fcf5ef2aSThomas Huth 33fcf5ef2aSThomas Huth #include "trace-tcg.h" 34fcf5ef2aSThomas Huth #include "exec/log.h" 35fcf5ef2aSThomas Huth 36fcf5ef2aSThomas Huth #define EXTRACT_FIELD(src, start, end) \ 37fcf5ef2aSThomas Huth (((src) >> start) & ((1 << (end - start + 1)) - 1)) 38fcf5ef2aSThomas Huth 3977fc6f5eSLluís Vilanova /* is_jmp field values */ 4077fc6f5eSLluís Vilanova #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */ 4177fc6f5eSLluís Vilanova #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */ 4277fc6f5eSLluís Vilanova 43cfeea807SEdgar E. Iglesias static TCGv_i32 cpu_R[32]; 440f96e96bSRichard Henderson static TCGv_i32 cpu_pc; 453e0e16aeSRichard Henderson static TCGv_i32 cpu_msr; 461074c0fbSRichard Henderson static TCGv_i32 cpu_msr_c; 479b158558SRichard Henderson static TCGv_i32 cpu_imm; 489b158558SRichard Henderson static TCGv_i32 cpu_btaken; 490f96e96bSRichard Henderson static TCGv_i32 cpu_btarget; 509b158558SRichard Henderson static TCGv_i32 cpu_iflags; 519b158558SRichard Henderson static TCGv cpu_res_addr; 529b158558SRichard Henderson static TCGv_i32 cpu_res_val; 53fcf5ef2aSThomas Huth 54fcf5ef2aSThomas Huth #include "exec/gen-icount.h" 55fcf5ef2aSThomas Huth 56fcf5ef2aSThomas Huth /* This is the state at translation time. */ 57fcf5ef2aSThomas Huth typedef struct DisasContext { 58d4705ae0SRichard Henderson DisasContextBase base; 59fcf5ef2aSThomas Huth MicroBlazeCPU *cpu; 60fcf5ef2aSThomas Huth 61fcf5ef2aSThomas Huth /* Decoder. */ 62fcf5ef2aSThomas Huth int type_b; 63fcf5ef2aSThomas Huth uint32_t ir; 64fcf5ef2aSThomas Huth uint8_t opcode; 65fcf5ef2aSThomas Huth uint8_t rd, ra, rb; 66fcf5ef2aSThomas Huth uint16_t imm; 67fcf5ef2aSThomas Huth 68fcf5ef2aSThomas Huth unsigned int cpustate_changed; 69fcf5ef2aSThomas Huth unsigned int delayed_branch; 70fcf5ef2aSThomas Huth unsigned int tb_flags, synced_flags; /* tb dependent flags. */ 71fcf5ef2aSThomas Huth unsigned int clear_imm; 72fcf5ef2aSThomas Huth 73fcf5ef2aSThomas Huth #define JMP_NOJMP 0 74fcf5ef2aSThomas Huth #define JMP_DIRECT 1 75fcf5ef2aSThomas Huth #define JMP_DIRECT_CC 2 76fcf5ef2aSThomas Huth #define JMP_INDIRECT 3 77fcf5ef2aSThomas Huth unsigned int jmp; 78fcf5ef2aSThomas Huth uint32_t jmp_pc; 79fcf5ef2aSThomas Huth 80fcf5ef2aSThomas Huth int abort_at_next_insn; 81fcf5ef2aSThomas Huth } DisasContext; 82fcf5ef2aSThomas Huth 83fcf5ef2aSThomas Huth static inline void t_sync_flags(DisasContext *dc) 84fcf5ef2aSThomas Huth { 85fcf5ef2aSThomas Huth /* Synch the tb dependent flags between translator and runtime. */ 86fcf5ef2aSThomas Huth if (dc->tb_flags != dc->synced_flags) { 879b158558SRichard Henderson tcg_gen_movi_i32(cpu_iflags, dc->tb_flags); 88fcf5ef2aSThomas Huth dc->synced_flags = dc->tb_flags; 89fcf5ef2aSThomas Huth } 90fcf5ef2aSThomas Huth } 91fcf5ef2aSThomas Huth 9241ba37c4SRichard Henderson static void gen_raise_exception(DisasContext *dc, uint32_t index) 93fcf5ef2aSThomas Huth { 94fcf5ef2aSThomas Huth TCGv_i32 tmp = tcg_const_i32(index); 95fcf5ef2aSThomas Huth 96fcf5ef2aSThomas Huth gen_helper_raise_exception(cpu_env, tmp); 97fcf5ef2aSThomas Huth tcg_temp_free_i32(tmp); 98d4705ae0SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 99fcf5ef2aSThomas Huth } 100fcf5ef2aSThomas Huth 10141ba37c4SRichard Henderson static void gen_raise_exception_sync(DisasContext *dc, uint32_t index) 10241ba37c4SRichard Henderson { 10341ba37c4SRichard Henderson t_sync_flags(dc); 104d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next); 10541ba37c4SRichard Henderson gen_raise_exception(dc, index); 10641ba37c4SRichard Henderson } 10741ba37c4SRichard Henderson 10841ba37c4SRichard Henderson static void gen_raise_hw_excp(DisasContext *dc, uint32_t esr_ec) 10941ba37c4SRichard Henderson { 11041ba37c4SRichard Henderson TCGv_i32 tmp = tcg_const_i32(esr_ec); 11141ba37c4SRichard Henderson tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUMBState, esr)); 11241ba37c4SRichard Henderson tcg_temp_free_i32(tmp); 11341ba37c4SRichard Henderson 11441ba37c4SRichard Henderson gen_raise_exception_sync(dc, EXCP_HW_EXCP); 11541ba37c4SRichard Henderson } 11641ba37c4SRichard Henderson 117fcf5ef2aSThomas Huth static inline bool use_goto_tb(DisasContext *dc, target_ulong dest) 118fcf5ef2aSThomas Huth { 119fcf5ef2aSThomas Huth #ifndef CONFIG_USER_ONLY 120d4705ae0SRichard Henderson return (dc->base.pc_first & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); 121fcf5ef2aSThomas Huth #else 122fcf5ef2aSThomas Huth return true; 123fcf5ef2aSThomas Huth #endif 124fcf5ef2aSThomas Huth } 125fcf5ef2aSThomas Huth 126fcf5ef2aSThomas Huth static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) 127fcf5ef2aSThomas Huth { 128d4705ae0SRichard Henderson if (dc->base.singlestep_enabled) { 1290b46fa08SRichard Henderson TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG); 1300b46fa08SRichard Henderson tcg_gen_movi_i32(cpu_pc, dest); 1310b46fa08SRichard Henderson gen_helper_raise_exception(cpu_env, tmp); 1320b46fa08SRichard Henderson tcg_temp_free_i32(tmp); 1330b46fa08SRichard Henderson } else if (use_goto_tb(dc, dest)) { 134fcf5ef2aSThomas Huth tcg_gen_goto_tb(n); 1350f96e96bSRichard Henderson tcg_gen_movi_i32(cpu_pc, dest); 136d4705ae0SRichard Henderson tcg_gen_exit_tb(dc->base.tb, n); 137fcf5ef2aSThomas Huth } else { 1380f96e96bSRichard Henderson tcg_gen_movi_i32(cpu_pc, dest); 13907ea28b4SRichard Henderson tcg_gen_exit_tb(NULL, 0); 140fcf5ef2aSThomas Huth } 141d4705ae0SRichard Henderson dc->base.is_jmp = DISAS_NORETURN; 142fcf5ef2aSThomas Huth } 143fcf5ef2aSThomas Huth 144bdfc1e88SEdgar E. Iglesias /* 1459ba8cd45SEdgar E. Iglesias * Returns true if the insn an illegal operation. 1469ba8cd45SEdgar E. Iglesias * If exceptions are enabled, an exception is raised. 1479ba8cd45SEdgar E. Iglesias */ 1489ba8cd45SEdgar E. Iglesias static bool trap_illegal(DisasContext *dc, bool cond) 1499ba8cd45SEdgar E. Iglesias { 1509ba8cd45SEdgar E. Iglesias if (cond && (dc->tb_flags & MSR_EE_FLAG) 1515143fdf3SEdgar E. Iglesias && dc->cpu->cfg.illegal_opcode_exception) { 15241ba37c4SRichard Henderson gen_raise_hw_excp(dc, ESR_EC_ILLEGAL_OP); 1539ba8cd45SEdgar E. Iglesias } 1549ba8cd45SEdgar E. Iglesias return cond; 1559ba8cd45SEdgar E. Iglesias } 1569ba8cd45SEdgar E. Iglesias 1579ba8cd45SEdgar E. Iglesias /* 158bdfc1e88SEdgar E. Iglesias * Returns true if the insn is illegal in userspace. 159bdfc1e88SEdgar E. Iglesias * If exceptions are enabled, an exception is raised. 160bdfc1e88SEdgar E. Iglesias */ 161bdfc1e88SEdgar E. Iglesias static bool trap_userspace(DisasContext *dc, bool cond) 162bdfc1e88SEdgar E. Iglesias { 163bdfc1e88SEdgar E. Iglesias int mem_index = cpu_mmu_index(&dc->cpu->env, false); 164bdfc1e88SEdgar E. Iglesias bool cond_user = cond && mem_index == MMU_USER_IDX; 165bdfc1e88SEdgar E. Iglesias 166bdfc1e88SEdgar E. Iglesias if (cond_user && (dc->tb_flags & MSR_EE_FLAG)) { 16741ba37c4SRichard Henderson gen_raise_hw_excp(dc, ESR_EC_PRIVINSN); 168bdfc1e88SEdgar E. Iglesias } 169bdfc1e88SEdgar E. Iglesias return cond_user; 170bdfc1e88SEdgar E. Iglesias } 171bdfc1e88SEdgar E. Iglesias 172fcf5ef2aSThomas Huth /* True if ALU operand b is a small immediate that may deserve 173fcf5ef2aSThomas Huth faster treatment. */ 174fcf5ef2aSThomas Huth static inline int dec_alu_op_b_is_small_imm(DisasContext *dc) 175fcf5ef2aSThomas Huth { 176fcf5ef2aSThomas Huth /* Immediate insn without the imm prefix ? */ 177fcf5ef2aSThomas Huth return dc->type_b && !(dc->tb_flags & IMM_FLAG); 178fcf5ef2aSThomas Huth } 179fcf5ef2aSThomas Huth 180cfeea807SEdgar E. Iglesias static inline TCGv_i32 *dec_alu_op_b(DisasContext *dc) 181fcf5ef2aSThomas Huth { 182fcf5ef2aSThomas Huth if (dc->type_b) { 183fcf5ef2aSThomas Huth if (dc->tb_flags & IMM_FLAG) 1849b158558SRichard Henderson tcg_gen_ori_i32(cpu_imm, cpu_imm, dc->imm); 185fcf5ef2aSThomas Huth else 1869b158558SRichard Henderson tcg_gen_movi_i32(cpu_imm, (int32_t)((int16_t)dc->imm)); 1879b158558SRichard Henderson return &cpu_imm; 188fcf5ef2aSThomas Huth } else 189fcf5ef2aSThomas Huth return &cpu_R[dc->rb]; 190fcf5ef2aSThomas Huth } 191fcf5ef2aSThomas Huth 192fcf5ef2aSThomas Huth static void dec_add(DisasContext *dc) 193fcf5ef2aSThomas Huth { 194fcf5ef2aSThomas Huth unsigned int k, c; 195cfeea807SEdgar E. Iglesias TCGv_i32 cf; 196fcf5ef2aSThomas Huth 197fcf5ef2aSThomas Huth k = dc->opcode & 4; 198fcf5ef2aSThomas Huth c = dc->opcode & 2; 199fcf5ef2aSThomas Huth 200fcf5ef2aSThomas Huth /* Take care of the easy cases first. */ 201fcf5ef2aSThomas Huth if (k) { 202fcf5ef2aSThomas Huth /* k - keep carry, no need to update MSR. */ 203fcf5ef2aSThomas Huth /* If rd == r0, it's a nop. */ 204fcf5ef2aSThomas Huth if (dc->rd) { 205cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 206fcf5ef2aSThomas Huth 207fcf5ef2aSThomas Huth if (c) { 208fcf5ef2aSThomas Huth /* c - Add carry into the result. */ 2091074c0fbSRichard Henderson tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cpu_msr_c); 210fcf5ef2aSThomas Huth } 211fcf5ef2aSThomas Huth } 212fcf5ef2aSThomas Huth return; 213fcf5ef2aSThomas Huth } 214fcf5ef2aSThomas Huth 215fcf5ef2aSThomas Huth /* From now on, we can assume k is zero. So we need to update MSR. */ 216fcf5ef2aSThomas Huth /* Extract carry. */ 217cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 218fcf5ef2aSThomas Huth if (c) { 2191074c0fbSRichard Henderson tcg_gen_mov_i32(cf, cpu_msr_c); 220fcf5ef2aSThomas Huth } else { 221cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cf, 0); 222fcf5ef2aSThomas Huth } 223fcf5ef2aSThomas Huth 2241074c0fbSRichard Henderson gen_helper_carry(cpu_msr_c, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf); 225fcf5ef2aSThomas Huth if (dc->rd) { 226cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 227cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 228fcf5ef2aSThomas Huth } 229cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 230fcf5ef2aSThomas Huth } 231fcf5ef2aSThomas Huth 232fcf5ef2aSThomas Huth static void dec_sub(DisasContext *dc) 233fcf5ef2aSThomas Huth { 234fcf5ef2aSThomas Huth unsigned int u, cmp, k, c; 235cfeea807SEdgar E. Iglesias TCGv_i32 cf, na; 236fcf5ef2aSThomas Huth 237fcf5ef2aSThomas Huth u = dc->imm & 2; 238fcf5ef2aSThomas Huth k = dc->opcode & 4; 239fcf5ef2aSThomas Huth c = dc->opcode & 2; 240fcf5ef2aSThomas Huth cmp = (dc->imm & 1) && (!dc->type_b) && k; 241fcf5ef2aSThomas Huth 242fcf5ef2aSThomas Huth if (cmp) { 243fcf5ef2aSThomas Huth if (dc->rd) { 244fcf5ef2aSThomas Huth if (u) 245fcf5ef2aSThomas Huth gen_helper_cmpu(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 246fcf5ef2aSThomas Huth else 247fcf5ef2aSThomas Huth gen_helper_cmp(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 248fcf5ef2aSThomas Huth } 249fcf5ef2aSThomas Huth return; 250fcf5ef2aSThomas Huth } 251fcf5ef2aSThomas Huth 252fcf5ef2aSThomas Huth /* Take care of the easy cases first. */ 253fcf5ef2aSThomas Huth if (k) { 254fcf5ef2aSThomas Huth /* k - keep carry, no need to update MSR. */ 255fcf5ef2aSThomas Huth /* If rd == r0, it's a nop. */ 256fcf5ef2aSThomas Huth if (dc->rd) { 257cfeea807SEdgar E. Iglesias tcg_gen_sub_i32(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]); 258fcf5ef2aSThomas Huth 259fcf5ef2aSThomas Huth if (c) { 260fcf5ef2aSThomas Huth /* c - Add carry into the result. */ 2611074c0fbSRichard Henderson tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cpu_msr_c); 262fcf5ef2aSThomas Huth } 263fcf5ef2aSThomas Huth } 264fcf5ef2aSThomas Huth return; 265fcf5ef2aSThomas Huth } 266fcf5ef2aSThomas Huth 267fcf5ef2aSThomas Huth /* From now on, we can assume k is zero. So we need to update MSR. */ 268fcf5ef2aSThomas Huth /* Extract carry. And complement a into na. */ 269cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 270cfeea807SEdgar E. Iglesias na = tcg_temp_new_i32(); 271fcf5ef2aSThomas Huth if (c) { 2721074c0fbSRichard Henderson tcg_gen_mov_i32(cf, cpu_msr_c); 273fcf5ef2aSThomas Huth } else { 274cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cf, 1); 275fcf5ef2aSThomas Huth } 276fcf5ef2aSThomas Huth 277fcf5ef2aSThomas Huth /* d = b + ~a + c. carry defaults to 1. */ 278cfeea807SEdgar E. Iglesias tcg_gen_not_i32(na, cpu_R[dc->ra]); 279fcf5ef2aSThomas Huth 2801074c0fbSRichard Henderson gen_helper_carry(cpu_msr_c, na, *(dec_alu_op_b(dc)), cf); 281fcf5ef2aSThomas Huth if (dc->rd) { 282cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], na, *(dec_alu_op_b(dc))); 283cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 284fcf5ef2aSThomas Huth } 285cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 286cfeea807SEdgar E. Iglesias tcg_temp_free_i32(na); 287fcf5ef2aSThomas Huth } 288fcf5ef2aSThomas Huth 289fcf5ef2aSThomas Huth static void dec_pattern(DisasContext *dc) 290fcf5ef2aSThomas Huth { 291fcf5ef2aSThomas Huth unsigned int mode; 292fcf5ef2aSThomas Huth 2939ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_pcmp_instr)) { 2949ba8cd45SEdgar E. Iglesias return; 295fcf5ef2aSThomas Huth } 296fcf5ef2aSThomas Huth 297fcf5ef2aSThomas Huth mode = dc->opcode & 3; 298fcf5ef2aSThomas Huth switch (mode) { 299fcf5ef2aSThomas Huth case 0: 300fcf5ef2aSThomas Huth /* pcmpbf. */ 301fcf5ef2aSThomas Huth if (dc->rd) 302fcf5ef2aSThomas Huth gen_helper_pcmpbf(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 303fcf5ef2aSThomas Huth break; 304fcf5ef2aSThomas Huth case 2: 305fcf5ef2aSThomas Huth if (dc->rd) { 306cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_EQ, cpu_R[dc->rd], 307fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 308fcf5ef2aSThomas Huth } 309fcf5ef2aSThomas Huth break; 310fcf5ef2aSThomas Huth case 3: 311fcf5ef2aSThomas Huth if (dc->rd) { 312cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_NE, cpu_R[dc->rd], 313fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 314fcf5ef2aSThomas Huth } 315fcf5ef2aSThomas Huth break; 316fcf5ef2aSThomas Huth default: 317fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), 318fcf5ef2aSThomas Huth "unsupported pattern insn opcode=%x\n", dc->opcode); 319fcf5ef2aSThomas Huth break; 320fcf5ef2aSThomas Huth } 321fcf5ef2aSThomas Huth } 322fcf5ef2aSThomas Huth 323fcf5ef2aSThomas Huth static void dec_and(DisasContext *dc) 324fcf5ef2aSThomas Huth { 325fcf5ef2aSThomas Huth unsigned int not; 326fcf5ef2aSThomas Huth 327fcf5ef2aSThomas Huth if (!dc->type_b && (dc->imm & (1 << 10))) { 328fcf5ef2aSThomas Huth dec_pattern(dc); 329fcf5ef2aSThomas Huth return; 330fcf5ef2aSThomas Huth } 331fcf5ef2aSThomas Huth 332fcf5ef2aSThomas Huth not = dc->opcode & (1 << 1); 333fcf5ef2aSThomas Huth 334fcf5ef2aSThomas Huth if (!dc->rd) 335fcf5ef2aSThomas Huth return; 336fcf5ef2aSThomas Huth 337fcf5ef2aSThomas Huth if (not) { 338cfeea807SEdgar E. Iglesias tcg_gen_andc_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 339fcf5ef2aSThomas Huth } else 340cfeea807SEdgar E. Iglesias tcg_gen_and_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 341fcf5ef2aSThomas Huth } 342fcf5ef2aSThomas Huth 343fcf5ef2aSThomas Huth static void dec_or(DisasContext *dc) 344fcf5ef2aSThomas Huth { 345fcf5ef2aSThomas Huth if (!dc->type_b && (dc->imm & (1 << 10))) { 346fcf5ef2aSThomas Huth dec_pattern(dc); 347fcf5ef2aSThomas Huth return; 348fcf5ef2aSThomas Huth } 349fcf5ef2aSThomas Huth 350fcf5ef2aSThomas Huth if (dc->rd) 351cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 352fcf5ef2aSThomas Huth } 353fcf5ef2aSThomas Huth 354fcf5ef2aSThomas Huth static void dec_xor(DisasContext *dc) 355fcf5ef2aSThomas Huth { 356fcf5ef2aSThomas Huth if (!dc->type_b && (dc->imm & (1 << 10))) { 357fcf5ef2aSThomas Huth dec_pattern(dc); 358fcf5ef2aSThomas Huth return; 359fcf5ef2aSThomas Huth } 360fcf5ef2aSThomas Huth 361fcf5ef2aSThomas Huth if (dc->rd) 362cfeea807SEdgar E. Iglesias tcg_gen_xor_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 363fcf5ef2aSThomas Huth } 364fcf5ef2aSThomas Huth 3651074c0fbSRichard Henderson static void msr_read(DisasContext *dc, TCGv_i32 d) 366fcf5ef2aSThomas Huth { 3671074c0fbSRichard Henderson TCGv_i32 t; 3681074c0fbSRichard Henderson 3691074c0fbSRichard Henderson /* Replicate the cpu_msr_c boolean into the proper bit and the copy. */ 3701074c0fbSRichard Henderson t = tcg_temp_new_i32(); 3711074c0fbSRichard Henderson tcg_gen_muli_i32(t, cpu_msr_c, MSR_C | MSR_CC); 3721074c0fbSRichard Henderson tcg_gen_or_i32(d, cpu_msr, t); 3731074c0fbSRichard Henderson tcg_temp_free_i32(t); 374fcf5ef2aSThomas Huth } 375fcf5ef2aSThomas Huth 3761074c0fbSRichard Henderson static void msr_write(DisasContext *dc, TCGv_i32 v) 377fcf5ef2aSThomas Huth { 378fcf5ef2aSThomas Huth dc->cpustate_changed = 1; 3791074c0fbSRichard Henderson 3801074c0fbSRichard Henderson /* Install MSR_C. */ 3811074c0fbSRichard Henderson tcg_gen_extract_i32(cpu_msr_c, v, 2, 1); 3821074c0fbSRichard Henderson 3831074c0fbSRichard Henderson /* Clear MSR_C and MSR_CC; MSR_PVR is not writable, and is always clear. */ 3841074c0fbSRichard Henderson tcg_gen_andi_i32(cpu_msr, v, ~(MSR_C | MSR_CC | MSR_PVR)); 385fcf5ef2aSThomas Huth } 386fcf5ef2aSThomas Huth 387fcf5ef2aSThomas Huth static void dec_msr(DisasContext *dc) 388fcf5ef2aSThomas Huth { 389fcf5ef2aSThomas Huth CPUState *cs = CPU(dc->cpu); 390cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 3912023e9a3SEdgar E. Iglesias unsigned int sr, rn; 392f0f7e7f7SEdgar E. Iglesias bool to, clrset, extended = false; 393fcf5ef2aSThomas Huth 3942023e9a3SEdgar E. Iglesias sr = extract32(dc->imm, 0, 14); 3952023e9a3SEdgar E. Iglesias to = extract32(dc->imm, 14, 1); 3962023e9a3SEdgar E. Iglesias clrset = extract32(dc->imm, 15, 1) == 0; 397fcf5ef2aSThomas Huth dc->type_b = 1; 3982023e9a3SEdgar E. Iglesias if (to) { 399fcf5ef2aSThomas Huth dc->cpustate_changed = 1; 400f0f7e7f7SEdgar E. Iglesias } 401f0f7e7f7SEdgar E. Iglesias 402f0f7e7f7SEdgar E. Iglesias /* Extended MSRs are only available if addr_size > 32. */ 403f0f7e7f7SEdgar E. Iglesias if (dc->cpu->cfg.addr_size > 32) { 404f0f7e7f7SEdgar E. Iglesias /* The E-bit is encoded differently for To/From MSR. */ 405f0f7e7f7SEdgar E. Iglesias static const unsigned int e_bit[] = { 19, 24 }; 406f0f7e7f7SEdgar E. Iglesias 407f0f7e7f7SEdgar E. Iglesias extended = extract32(dc->imm, e_bit[to], 1); 4082023e9a3SEdgar E. Iglesias } 409fcf5ef2aSThomas Huth 410fcf5ef2aSThomas Huth /* msrclr and msrset. */ 4112023e9a3SEdgar E. Iglesias if (clrset) { 4122023e9a3SEdgar E. Iglesias bool clr = extract32(dc->ir, 16, 1); 413fcf5ef2aSThomas Huth 41456837509SEdgar E. Iglesias if (!dc->cpu->cfg.use_msr_instr) { 415fcf5ef2aSThomas Huth /* nop??? */ 416fcf5ef2aSThomas Huth return; 417fcf5ef2aSThomas Huth } 418fcf5ef2aSThomas Huth 419bdfc1e88SEdgar E. Iglesias if (trap_userspace(dc, dc->imm != 4 && dc->imm != 0)) { 420fcf5ef2aSThomas Huth return; 421fcf5ef2aSThomas Huth } 422fcf5ef2aSThomas Huth 423fcf5ef2aSThomas Huth if (dc->rd) 424fcf5ef2aSThomas Huth msr_read(dc, cpu_R[dc->rd]); 425fcf5ef2aSThomas Huth 426cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 427cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 428fcf5ef2aSThomas Huth msr_read(dc, t0); 429cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t1, *(dec_alu_op_b(dc))); 430fcf5ef2aSThomas Huth 431fcf5ef2aSThomas Huth if (clr) { 432cfeea807SEdgar E. Iglesias tcg_gen_not_i32(t1, t1); 433cfeea807SEdgar E. Iglesias tcg_gen_and_i32(t0, t0, t1); 434fcf5ef2aSThomas Huth } else 435cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t0, t0, t1); 436fcf5ef2aSThomas Huth msr_write(dc, t0); 437cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 438cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 439d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next + 4); 440d4705ae0SRichard Henderson dc->base.is_jmp = DISAS_UPDATE; 441fcf5ef2aSThomas Huth return; 442fcf5ef2aSThomas Huth } 443fcf5ef2aSThomas Huth 444bdfc1e88SEdgar E. Iglesias if (trap_userspace(dc, to)) { 445fcf5ef2aSThomas Huth return; 446fcf5ef2aSThomas Huth } 447fcf5ef2aSThomas Huth 448fcf5ef2aSThomas Huth #if !defined(CONFIG_USER_ONLY) 449fcf5ef2aSThomas Huth /* Catch read/writes to the mmu block. */ 450fcf5ef2aSThomas Huth if ((sr & ~0xff) == 0x1000) { 451f0f7e7f7SEdgar E. Iglesias TCGv_i32 tmp_ext = tcg_const_i32(extended); 45205a9a651SEdgar E. Iglesias TCGv_i32 tmp_sr; 45305a9a651SEdgar E. Iglesias 454fcf5ef2aSThomas Huth sr &= 7; 45505a9a651SEdgar E. Iglesias tmp_sr = tcg_const_i32(sr); 45605a9a651SEdgar E. Iglesias if (to) { 457f0f7e7f7SEdgar E. Iglesias gen_helper_mmu_write(cpu_env, tmp_ext, tmp_sr, cpu_R[dc->ra]); 45805a9a651SEdgar E. Iglesias } else { 459f0f7e7f7SEdgar E. Iglesias gen_helper_mmu_read(cpu_R[dc->rd], cpu_env, tmp_ext, tmp_sr); 46005a9a651SEdgar E. Iglesias } 46105a9a651SEdgar E. Iglesias tcg_temp_free_i32(tmp_sr); 462f0f7e7f7SEdgar E. Iglesias tcg_temp_free_i32(tmp_ext); 463fcf5ef2aSThomas Huth return; 464fcf5ef2aSThomas Huth } 465fcf5ef2aSThomas Huth #endif 466fcf5ef2aSThomas Huth 467fcf5ef2aSThomas Huth if (to) { 468fcf5ef2aSThomas Huth switch (sr) { 469aa28e6d4SRichard Henderson case SR_PC: 470fcf5ef2aSThomas Huth break; 471aa28e6d4SRichard Henderson case SR_MSR: 472fcf5ef2aSThomas Huth msr_write(dc, cpu_R[dc->ra]); 473fcf5ef2aSThomas Huth break; 474351527b7SEdgar E. Iglesias case SR_EAR: 475dbdb77c4SRichard Henderson { 476dbdb77c4SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 477dbdb77c4SRichard Henderson tcg_gen_extu_i32_i64(t64, cpu_R[dc->ra]); 478dbdb77c4SRichard Henderson tcg_gen_st_i64(t64, cpu_env, offsetof(CPUMBState, ear)); 479dbdb77c4SRichard Henderson tcg_temp_free_i64(t64); 480dbdb77c4SRichard Henderson } 481aa28e6d4SRichard Henderson break; 482351527b7SEdgar E. Iglesias case SR_ESR: 48341ba37c4SRichard Henderson tcg_gen_st_i32(cpu_R[dc->ra], 48441ba37c4SRichard Henderson cpu_env, offsetof(CPUMBState, esr)); 485aa28e6d4SRichard Henderson break; 486ab6dd380SEdgar E. Iglesias case SR_FSR: 48786017ccfSRichard Henderson tcg_gen_st_i32(cpu_R[dc->ra], 48886017ccfSRichard Henderson cpu_env, offsetof(CPUMBState, fsr)); 489aa28e6d4SRichard Henderson break; 490aa28e6d4SRichard Henderson case SR_BTR: 491ccf628b7SRichard Henderson tcg_gen_st_i32(cpu_R[dc->ra], 492ccf628b7SRichard Henderson cpu_env, offsetof(CPUMBState, btr)); 493aa28e6d4SRichard Henderson break; 494aa28e6d4SRichard Henderson case SR_EDR: 49539db007eSRichard Henderson tcg_gen_st_i32(cpu_R[dc->ra], 49639db007eSRichard Henderson cpu_env, offsetof(CPUMBState, edr)); 497fcf5ef2aSThomas Huth break; 498fcf5ef2aSThomas Huth case 0x800: 499cfeea807SEdgar E. Iglesias tcg_gen_st_i32(cpu_R[dc->ra], 500cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, slr)); 501fcf5ef2aSThomas Huth break; 502fcf5ef2aSThomas Huth case 0x802: 503cfeea807SEdgar E. Iglesias tcg_gen_st_i32(cpu_R[dc->ra], 504cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, shr)); 505fcf5ef2aSThomas Huth break; 506fcf5ef2aSThomas Huth default: 507fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), "unknown mts reg %x\n", sr); 508fcf5ef2aSThomas Huth break; 509fcf5ef2aSThomas Huth } 510fcf5ef2aSThomas Huth } else { 511fcf5ef2aSThomas Huth switch (sr) { 512aa28e6d4SRichard Henderson case SR_PC: 513d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_R[dc->rd], dc->base.pc_next); 514fcf5ef2aSThomas Huth break; 515aa28e6d4SRichard Henderson case SR_MSR: 516fcf5ef2aSThomas Huth msr_read(dc, cpu_R[dc->rd]); 517fcf5ef2aSThomas Huth break; 518351527b7SEdgar E. Iglesias case SR_EAR: 519dbdb77c4SRichard Henderson { 520dbdb77c4SRichard Henderson TCGv_i64 t64 = tcg_temp_new_i64(); 521dbdb77c4SRichard Henderson tcg_gen_ld_i64(t64, cpu_env, offsetof(CPUMBState, ear)); 522a1b48e3aSEdgar E. Iglesias if (extended) { 523dbdb77c4SRichard Henderson tcg_gen_extrh_i64_i32(cpu_R[dc->rd], t64); 524aa28e6d4SRichard Henderson } else { 525dbdb77c4SRichard Henderson tcg_gen_extrl_i64_i32(cpu_R[dc->rd], t64); 526dbdb77c4SRichard Henderson } 527dbdb77c4SRichard Henderson tcg_temp_free_i64(t64); 528a1b48e3aSEdgar E. Iglesias } 529aa28e6d4SRichard Henderson break; 530351527b7SEdgar E. Iglesias case SR_ESR: 53141ba37c4SRichard Henderson tcg_gen_ld_i32(cpu_R[dc->rd], 53241ba37c4SRichard Henderson cpu_env, offsetof(CPUMBState, esr)); 533aa28e6d4SRichard Henderson break; 534351527b7SEdgar E. Iglesias case SR_FSR: 53586017ccfSRichard Henderson tcg_gen_ld_i32(cpu_R[dc->rd], 53686017ccfSRichard Henderson cpu_env, offsetof(CPUMBState, fsr)); 537aa28e6d4SRichard Henderson break; 538351527b7SEdgar E. Iglesias case SR_BTR: 539ccf628b7SRichard Henderson tcg_gen_ld_i32(cpu_R[dc->rd], 540ccf628b7SRichard Henderson cpu_env, offsetof(CPUMBState, btr)); 541aa28e6d4SRichard Henderson break; 5427cdae31dSTong Ho case SR_EDR: 54339db007eSRichard Henderson tcg_gen_ld_i32(cpu_R[dc->rd], 54439db007eSRichard Henderson cpu_env, offsetof(CPUMBState, edr)); 545fcf5ef2aSThomas Huth break; 546fcf5ef2aSThomas Huth case 0x800: 547cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 548cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, slr)); 549fcf5ef2aSThomas Huth break; 550fcf5ef2aSThomas Huth case 0x802: 551cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 552cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, shr)); 553fcf5ef2aSThomas Huth break; 554351527b7SEdgar E. Iglesias case 0x2000 ... 0x200c: 555fcf5ef2aSThomas Huth rn = sr & 0xf; 556cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 557fcf5ef2aSThomas Huth cpu_env, offsetof(CPUMBState, pvr.regs[rn])); 558fcf5ef2aSThomas Huth break; 559fcf5ef2aSThomas Huth default: 560fcf5ef2aSThomas Huth cpu_abort(cs, "unknown mfs reg %x\n", sr); 561fcf5ef2aSThomas Huth break; 562fcf5ef2aSThomas Huth } 563fcf5ef2aSThomas Huth } 564fcf5ef2aSThomas Huth 565fcf5ef2aSThomas Huth if (dc->rd == 0) { 566cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[0], 0); 567fcf5ef2aSThomas Huth } 568fcf5ef2aSThomas Huth } 569fcf5ef2aSThomas Huth 570fcf5ef2aSThomas Huth /* Multiplier unit. */ 571fcf5ef2aSThomas Huth static void dec_mul(DisasContext *dc) 572fcf5ef2aSThomas Huth { 573cfeea807SEdgar E. Iglesias TCGv_i32 tmp; 574fcf5ef2aSThomas Huth unsigned int subcode; 575fcf5ef2aSThomas Huth 5769ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_hw_mul)) { 577fcf5ef2aSThomas Huth return; 578fcf5ef2aSThomas Huth } 579fcf5ef2aSThomas Huth 580fcf5ef2aSThomas Huth subcode = dc->imm & 3; 581fcf5ef2aSThomas Huth 582fcf5ef2aSThomas Huth if (dc->type_b) { 583cfeea807SEdgar E. Iglesias tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 584fcf5ef2aSThomas Huth return; 585fcf5ef2aSThomas Huth } 586fcf5ef2aSThomas Huth 587fcf5ef2aSThomas Huth /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */ 5889b964318SEdgar E. Iglesias if (subcode >= 1 && subcode <= 3 && dc->cpu->cfg.use_hw_mul < 2) { 589fcf5ef2aSThomas Huth /* nop??? */ 590fcf5ef2aSThomas Huth } 591fcf5ef2aSThomas Huth 592cfeea807SEdgar E. Iglesias tmp = tcg_temp_new_i32(); 593fcf5ef2aSThomas Huth switch (subcode) { 594fcf5ef2aSThomas Huth case 0: 595cfeea807SEdgar E. Iglesias tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 596fcf5ef2aSThomas Huth break; 597fcf5ef2aSThomas Huth case 1: 598cfeea807SEdgar E. Iglesias tcg_gen_muls2_i32(tmp, cpu_R[dc->rd], 599cfeea807SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 600fcf5ef2aSThomas Huth break; 601fcf5ef2aSThomas Huth case 2: 602cfeea807SEdgar E. Iglesias tcg_gen_mulsu2_i32(tmp, cpu_R[dc->rd], 603cfeea807SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 604fcf5ef2aSThomas Huth break; 605fcf5ef2aSThomas Huth case 3: 606cfeea807SEdgar E. Iglesias tcg_gen_mulu2_i32(tmp, cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 607fcf5ef2aSThomas Huth break; 608fcf5ef2aSThomas Huth default: 609fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), "unknown MUL insn %x\n", subcode); 610fcf5ef2aSThomas Huth break; 611fcf5ef2aSThomas Huth } 612cfeea807SEdgar E. Iglesias tcg_temp_free_i32(tmp); 613fcf5ef2aSThomas Huth } 614fcf5ef2aSThomas Huth 615fcf5ef2aSThomas Huth /* Div unit. */ 616fcf5ef2aSThomas Huth static void dec_div(DisasContext *dc) 617fcf5ef2aSThomas Huth { 618fcf5ef2aSThomas Huth unsigned int u; 619fcf5ef2aSThomas Huth 620fcf5ef2aSThomas Huth u = dc->imm & 2; 621fcf5ef2aSThomas Huth 6229ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_div)) { 6239ba8cd45SEdgar E. Iglesias return; 624fcf5ef2aSThomas Huth } 625fcf5ef2aSThomas Huth 626fcf5ef2aSThomas Huth if (u) 627fcf5ef2aSThomas Huth gen_helper_divu(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)), 628fcf5ef2aSThomas Huth cpu_R[dc->ra]); 629fcf5ef2aSThomas Huth else 630fcf5ef2aSThomas Huth gen_helper_divs(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)), 631fcf5ef2aSThomas Huth cpu_R[dc->ra]); 632fcf5ef2aSThomas Huth if (!dc->rd) 633cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[dc->rd], 0); 634fcf5ef2aSThomas Huth } 635fcf5ef2aSThomas Huth 636fcf5ef2aSThomas Huth static void dec_barrel(DisasContext *dc) 637fcf5ef2aSThomas Huth { 638cfeea807SEdgar E. Iglesias TCGv_i32 t0; 639faa48d74SEdgar E. Iglesias unsigned int imm_w, imm_s; 640d09b2585SEdgar E. Iglesias bool s, t, e = false, i = false; 641fcf5ef2aSThomas Huth 6429ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_barrel)) { 643fcf5ef2aSThomas Huth return; 644fcf5ef2aSThomas Huth } 645fcf5ef2aSThomas Huth 646faa48d74SEdgar E. Iglesias if (dc->type_b) { 647faa48d74SEdgar E. Iglesias /* Insert and extract are only available in immediate mode. */ 648d09b2585SEdgar E. Iglesias i = extract32(dc->imm, 15, 1); 649faa48d74SEdgar E. Iglesias e = extract32(dc->imm, 14, 1); 650faa48d74SEdgar E. Iglesias } 651e3e84983SEdgar E. Iglesias s = extract32(dc->imm, 10, 1); 652e3e84983SEdgar E. Iglesias t = extract32(dc->imm, 9, 1); 653faa48d74SEdgar E. Iglesias imm_w = extract32(dc->imm, 6, 5); 654faa48d74SEdgar E. Iglesias imm_s = extract32(dc->imm, 0, 5); 655fcf5ef2aSThomas Huth 656faa48d74SEdgar E. Iglesias if (e) { 657faa48d74SEdgar E. Iglesias if (imm_w + imm_s > 32 || imm_w == 0) { 658faa48d74SEdgar E. Iglesias /* These inputs have an undefined behavior. */ 659faa48d74SEdgar E. Iglesias qemu_log_mask(LOG_GUEST_ERROR, "bsefi: Bad input w=%d s=%d\n", 660faa48d74SEdgar E. Iglesias imm_w, imm_s); 661faa48d74SEdgar E. Iglesias } else { 662faa48d74SEdgar E. Iglesias tcg_gen_extract_i32(cpu_R[dc->rd], cpu_R[dc->ra], imm_s, imm_w); 663faa48d74SEdgar E. Iglesias } 664d09b2585SEdgar E. Iglesias } else if (i) { 665d09b2585SEdgar E. Iglesias int width = imm_w - imm_s + 1; 666d09b2585SEdgar E. Iglesias 667d09b2585SEdgar E. Iglesias if (imm_w < imm_s) { 668d09b2585SEdgar E. Iglesias /* These inputs have an undefined behavior. */ 669d09b2585SEdgar E. Iglesias qemu_log_mask(LOG_GUEST_ERROR, "bsifi: Bad input w=%d s=%d\n", 670d09b2585SEdgar E. Iglesias imm_w, imm_s); 671d09b2585SEdgar E. Iglesias } else { 672d09b2585SEdgar E. Iglesias tcg_gen_deposit_i32(cpu_R[dc->rd], cpu_R[dc->rd], cpu_R[dc->ra], 673d09b2585SEdgar E. Iglesias imm_s, width); 674d09b2585SEdgar E. Iglesias } 675faa48d74SEdgar E. Iglesias } else { 676cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 677fcf5ef2aSThomas Huth 678cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t0, *(dec_alu_op_b(dc))); 679cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, 31); 680fcf5ef2aSThomas Huth 6812acf6d53SEdgar E. Iglesias if (s) { 682cfeea807SEdgar E. Iglesias tcg_gen_shl_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 6832acf6d53SEdgar E. Iglesias } else { 6842acf6d53SEdgar E. Iglesias if (t) { 685cfeea807SEdgar E. Iglesias tcg_gen_sar_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 6862acf6d53SEdgar E. Iglesias } else { 687cfeea807SEdgar E. Iglesias tcg_gen_shr_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 688fcf5ef2aSThomas Huth } 689fcf5ef2aSThomas Huth } 690cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 6912acf6d53SEdgar E. Iglesias } 692faa48d74SEdgar E. Iglesias } 693fcf5ef2aSThomas Huth 694fcf5ef2aSThomas Huth static void dec_bit(DisasContext *dc) 695fcf5ef2aSThomas Huth { 696fcf5ef2aSThomas Huth CPUState *cs = CPU(dc->cpu); 697cfeea807SEdgar E. Iglesias TCGv_i32 t0; 698fcf5ef2aSThomas Huth unsigned int op; 699fcf5ef2aSThomas Huth 700fcf5ef2aSThomas Huth op = dc->ir & ((1 << 9) - 1); 701fcf5ef2aSThomas Huth switch (op) { 702fcf5ef2aSThomas Huth case 0x21: 703fcf5ef2aSThomas Huth /* src. */ 704cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 705fcf5ef2aSThomas Huth 7061074c0fbSRichard Henderson tcg_gen_shli_i32(t0, cpu_msr_c, 31); 7071074c0fbSRichard Henderson tcg_gen_andi_i32(cpu_msr_c, cpu_R[dc->ra], 1); 708fcf5ef2aSThomas Huth if (dc->rd) { 709cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 710cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->rd], t0); 711fcf5ef2aSThomas Huth } 712cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 713fcf5ef2aSThomas Huth break; 714fcf5ef2aSThomas Huth 715fcf5ef2aSThomas Huth case 0x1: 716fcf5ef2aSThomas Huth case 0x41: 717fcf5ef2aSThomas Huth /* srl. */ 7181074c0fbSRichard Henderson tcg_gen_andi_i32(cpu_msr_c, cpu_R[dc->ra], 1); 719fcf5ef2aSThomas Huth if (dc->rd) { 720fcf5ef2aSThomas Huth if (op == 0x41) 721cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 722fcf5ef2aSThomas Huth else 723cfeea807SEdgar E. Iglesias tcg_gen_sari_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 724fcf5ef2aSThomas Huth } 725fcf5ef2aSThomas Huth break; 726fcf5ef2aSThomas Huth case 0x60: 727fcf5ef2aSThomas Huth tcg_gen_ext8s_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 728fcf5ef2aSThomas Huth break; 729fcf5ef2aSThomas Huth case 0x61: 730fcf5ef2aSThomas Huth tcg_gen_ext16s_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 731fcf5ef2aSThomas Huth break; 732fcf5ef2aSThomas Huth case 0x64: 733fcf5ef2aSThomas Huth case 0x66: 734fcf5ef2aSThomas Huth case 0x74: 735fcf5ef2aSThomas Huth case 0x76: 736fcf5ef2aSThomas Huth /* wdc. */ 737bdfc1e88SEdgar E. Iglesias trap_userspace(dc, true); 738fcf5ef2aSThomas Huth break; 739fcf5ef2aSThomas Huth case 0x68: 740fcf5ef2aSThomas Huth /* wic. */ 741bdfc1e88SEdgar E. Iglesias trap_userspace(dc, true); 742fcf5ef2aSThomas Huth break; 743fcf5ef2aSThomas Huth case 0xe0: 7449ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_pcmp_instr)) { 7459ba8cd45SEdgar E. Iglesias return; 746fcf5ef2aSThomas Huth } 7478fc5239eSEdgar E. Iglesias if (dc->cpu->cfg.use_pcmp_instr) { 7485318420cSRichard Henderson tcg_gen_clzi_i32(cpu_R[dc->rd], cpu_R[dc->ra], 32); 749fcf5ef2aSThomas Huth } 750fcf5ef2aSThomas Huth break; 751fcf5ef2aSThomas Huth case 0x1e0: 752fcf5ef2aSThomas Huth /* swapb */ 753fcf5ef2aSThomas Huth tcg_gen_bswap32_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 754fcf5ef2aSThomas Huth break; 755fcf5ef2aSThomas Huth case 0x1e2: 756fcf5ef2aSThomas Huth /*swaph */ 757fcf5ef2aSThomas Huth tcg_gen_rotri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 16); 758fcf5ef2aSThomas Huth break; 759fcf5ef2aSThomas Huth default: 760fcf5ef2aSThomas Huth cpu_abort(cs, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n", 761d4705ae0SRichard Henderson (uint32_t)dc->base.pc_next, op, dc->rd, dc->ra, dc->rb); 762fcf5ef2aSThomas Huth break; 763fcf5ef2aSThomas Huth } 764fcf5ef2aSThomas Huth } 765fcf5ef2aSThomas Huth 766fcf5ef2aSThomas Huth static inline void sync_jmpstate(DisasContext *dc) 767fcf5ef2aSThomas Huth { 768fcf5ef2aSThomas Huth if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) { 769fcf5ef2aSThomas Huth if (dc->jmp == JMP_DIRECT) { 7709b158558SRichard Henderson tcg_gen_movi_i32(cpu_btaken, 1); 771fcf5ef2aSThomas Huth } 772fcf5ef2aSThomas Huth dc->jmp = JMP_INDIRECT; 7730f96e96bSRichard Henderson tcg_gen_movi_i32(cpu_btarget, dc->jmp_pc); 774fcf5ef2aSThomas Huth } 775fcf5ef2aSThomas Huth } 776fcf5ef2aSThomas Huth 777fcf5ef2aSThomas Huth static void dec_imm(DisasContext *dc) 778fcf5ef2aSThomas Huth { 7799b158558SRichard Henderson tcg_gen_movi_i32(cpu_imm, (dc->imm << 16)); 780fcf5ef2aSThomas Huth dc->tb_flags |= IMM_FLAG; 781fcf5ef2aSThomas Huth dc->clear_imm = 0; 782fcf5ef2aSThomas Huth } 783fcf5ef2aSThomas Huth 784d248e1beSEdgar E. Iglesias static inline void compute_ldst_addr(DisasContext *dc, bool ea, TCGv t) 785fcf5ef2aSThomas Huth { 7860e9033c8SEdgar E. Iglesias bool extimm = dc->tb_flags & IMM_FLAG; 7870e9033c8SEdgar E. Iglesias /* Should be set to true if r1 is used by loadstores. */ 7880e9033c8SEdgar E. Iglesias bool stackprot = false; 789403322eaSEdgar E. Iglesias TCGv_i32 t32; 790fcf5ef2aSThomas Huth 791fcf5ef2aSThomas Huth /* All load/stores use ra. */ 792fcf5ef2aSThomas Huth if (dc->ra == 1 && dc->cpu->cfg.stackprot) { 7930e9033c8SEdgar E. Iglesias stackprot = true; 794fcf5ef2aSThomas Huth } 795fcf5ef2aSThomas Huth 796fcf5ef2aSThomas Huth /* Treat the common cases first. */ 797fcf5ef2aSThomas Huth if (!dc->type_b) { 798d248e1beSEdgar E. Iglesias if (ea) { 799d248e1beSEdgar E. Iglesias int addr_size = dc->cpu->cfg.addr_size; 800d248e1beSEdgar E. Iglesias 801d248e1beSEdgar E. Iglesias if (addr_size == 32) { 802d248e1beSEdgar E. Iglesias tcg_gen_extu_i32_tl(t, cpu_R[dc->rb]); 803d248e1beSEdgar E. Iglesias return; 804d248e1beSEdgar E. Iglesias } 805d248e1beSEdgar E. Iglesias 806d248e1beSEdgar E. Iglesias tcg_gen_concat_i32_i64(t, cpu_R[dc->rb], cpu_R[dc->ra]); 807d248e1beSEdgar E. Iglesias if (addr_size < 64) { 808d248e1beSEdgar E. Iglesias /* Mask off out of range bits. */ 809d248e1beSEdgar E. Iglesias tcg_gen_andi_i64(t, t, MAKE_64BIT_MASK(0, addr_size)); 810d248e1beSEdgar E. Iglesias } 811d248e1beSEdgar E. Iglesias return; 812d248e1beSEdgar E. Iglesias } 813d248e1beSEdgar E. Iglesias 8140dc4af5cSEdgar E. Iglesias /* If any of the regs is r0, set t to the value of the other reg. */ 815fcf5ef2aSThomas Huth if (dc->ra == 0) { 816403322eaSEdgar E. Iglesias tcg_gen_extu_i32_tl(t, cpu_R[dc->rb]); 8170dc4af5cSEdgar E. Iglesias return; 818fcf5ef2aSThomas Huth } else if (dc->rb == 0) { 819403322eaSEdgar E. Iglesias tcg_gen_extu_i32_tl(t, cpu_R[dc->ra]); 8200dc4af5cSEdgar E. Iglesias return; 821fcf5ef2aSThomas Huth } 822fcf5ef2aSThomas Huth 823fcf5ef2aSThomas Huth if (dc->rb == 1 && dc->cpu->cfg.stackprot) { 8240e9033c8SEdgar E. Iglesias stackprot = true; 825fcf5ef2aSThomas Huth } 826fcf5ef2aSThomas Huth 827403322eaSEdgar E. Iglesias t32 = tcg_temp_new_i32(); 828403322eaSEdgar E. Iglesias tcg_gen_add_i32(t32, cpu_R[dc->ra], cpu_R[dc->rb]); 829403322eaSEdgar E. Iglesias tcg_gen_extu_i32_tl(t, t32); 830403322eaSEdgar E. Iglesias tcg_temp_free_i32(t32); 831fcf5ef2aSThomas Huth 832fcf5ef2aSThomas Huth if (stackprot) { 8330a87e691SEdgar E. Iglesias gen_helper_stackprot(cpu_env, t); 834fcf5ef2aSThomas Huth } 8350dc4af5cSEdgar E. Iglesias return; 836fcf5ef2aSThomas Huth } 837fcf5ef2aSThomas Huth /* Immediate. */ 838403322eaSEdgar E. Iglesias t32 = tcg_temp_new_i32(); 839fcf5ef2aSThomas Huth if (!extimm) { 840f7a66e3aSEdgar E. Iglesias tcg_gen_addi_i32(t32, cpu_R[dc->ra], (int16_t)dc->imm); 841403322eaSEdgar E. Iglesias } else { 842403322eaSEdgar E. Iglesias tcg_gen_add_i32(t32, cpu_R[dc->ra], *(dec_alu_op_b(dc))); 843403322eaSEdgar E. Iglesias } 844403322eaSEdgar E. Iglesias tcg_gen_extu_i32_tl(t, t32); 845403322eaSEdgar E. Iglesias tcg_temp_free_i32(t32); 846fcf5ef2aSThomas Huth 847fcf5ef2aSThomas Huth if (stackprot) { 8480a87e691SEdgar E. Iglesias gen_helper_stackprot(cpu_env, t); 849fcf5ef2aSThomas Huth } 8500dc4af5cSEdgar E. Iglesias return; 851fcf5ef2aSThomas Huth } 852fcf5ef2aSThomas Huth 853fcf5ef2aSThomas Huth static void dec_load(DisasContext *dc) 854fcf5ef2aSThomas Huth { 855403322eaSEdgar E. Iglesias TCGv_i32 v; 856403322eaSEdgar E. Iglesias TCGv addr; 8578534063aSEdgar E. Iglesias unsigned int size; 858d248e1beSEdgar E. Iglesias bool rev = false, ex = false, ea = false; 859d248e1beSEdgar E. Iglesias int mem_index = cpu_mmu_index(&dc->cpu->env, false); 86014776ab5STony Nguyen MemOp mop; 861fcf5ef2aSThomas Huth 862fcf5ef2aSThomas Huth mop = dc->opcode & 3; 863fcf5ef2aSThomas Huth size = 1 << mop; 864fcf5ef2aSThomas Huth if (!dc->type_b) { 865d248e1beSEdgar E. Iglesias ea = extract32(dc->ir, 7, 1); 8668534063aSEdgar E. Iglesias rev = extract32(dc->ir, 9, 1); 8678534063aSEdgar E. Iglesias ex = extract32(dc->ir, 10, 1); 868fcf5ef2aSThomas Huth } 869fcf5ef2aSThomas Huth mop |= MO_TE; 870fcf5ef2aSThomas Huth if (rev) { 871fcf5ef2aSThomas Huth mop ^= MO_BSWAP; 872fcf5ef2aSThomas Huth } 873fcf5ef2aSThomas Huth 8749ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, size > 4)) { 875fcf5ef2aSThomas Huth return; 876fcf5ef2aSThomas Huth } 877fcf5ef2aSThomas Huth 878d248e1beSEdgar E. Iglesias if (trap_userspace(dc, ea)) { 879d248e1beSEdgar E. Iglesias return; 880d248e1beSEdgar E. Iglesias } 881d248e1beSEdgar E. Iglesias 882fcf5ef2aSThomas Huth t_sync_flags(dc); 883403322eaSEdgar E. Iglesias addr = tcg_temp_new(); 884d248e1beSEdgar E. Iglesias compute_ldst_addr(dc, ea, addr); 885d248e1beSEdgar E. Iglesias /* Extended addressing bypasses the MMU. */ 886d248e1beSEdgar E. Iglesias mem_index = ea ? MMU_NOMMU_IDX : mem_index; 887fcf5ef2aSThomas Huth 888fcf5ef2aSThomas Huth /* 889fcf5ef2aSThomas Huth * When doing reverse accesses we need to do two things. 890fcf5ef2aSThomas Huth * 891fcf5ef2aSThomas Huth * 1. Reverse the address wrt endianness. 892fcf5ef2aSThomas Huth * 2. Byteswap the data lanes on the way back into the CPU core. 893fcf5ef2aSThomas Huth */ 894fcf5ef2aSThomas Huth if (rev && size != 4) { 895fcf5ef2aSThomas Huth /* Endian reverse the address. t is addr. */ 896fcf5ef2aSThomas Huth switch (size) { 897fcf5ef2aSThomas Huth case 1: 898fcf5ef2aSThomas Huth { 899a6338015SEdgar E. Iglesias tcg_gen_xori_tl(addr, addr, 3); 900fcf5ef2aSThomas Huth break; 901fcf5ef2aSThomas Huth } 902fcf5ef2aSThomas Huth 903fcf5ef2aSThomas Huth case 2: 904fcf5ef2aSThomas Huth /* 00 -> 10 905fcf5ef2aSThomas Huth 10 -> 00. */ 906403322eaSEdgar E. Iglesias tcg_gen_xori_tl(addr, addr, 2); 907fcf5ef2aSThomas Huth break; 908fcf5ef2aSThomas Huth default: 909fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), "Invalid reverse size\n"); 910fcf5ef2aSThomas Huth break; 911fcf5ef2aSThomas Huth } 912fcf5ef2aSThomas Huth } 913fcf5ef2aSThomas Huth 914fcf5ef2aSThomas Huth /* lwx does not throw unaligned access errors, so force alignment */ 915fcf5ef2aSThomas Huth if (ex) { 916403322eaSEdgar E. Iglesias tcg_gen_andi_tl(addr, addr, ~3); 917fcf5ef2aSThomas Huth } 918fcf5ef2aSThomas Huth 919fcf5ef2aSThomas Huth /* If we get a fault on a dslot, the jmpstate better be in sync. */ 920fcf5ef2aSThomas Huth sync_jmpstate(dc); 921fcf5ef2aSThomas Huth 922fcf5ef2aSThomas Huth /* Verify alignment if needed. */ 923fcf5ef2aSThomas Huth /* 924fcf5ef2aSThomas Huth * Microblaze gives MMU faults priority over faults due to 925fcf5ef2aSThomas Huth * unaligned addresses. That's why we speculatively do the load 926fcf5ef2aSThomas Huth * into v. If the load succeeds, we verify alignment of the 927fcf5ef2aSThomas Huth * address and if that succeeds we write into the destination reg. 928fcf5ef2aSThomas Huth */ 929cfeea807SEdgar E. Iglesias v = tcg_temp_new_i32(); 930d248e1beSEdgar E. Iglesias tcg_gen_qemu_ld_i32(v, addr, mem_index, mop); 931fcf5ef2aSThomas Huth 9321507e5f6SEdgar E. Iglesias if (dc->cpu->cfg.unaligned_exceptions && size > 1) { 933a6338015SEdgar E. Iglesias TCGv_i32 t0 = tcg_const_i32(0); 934a6338015SEdgar E. Iglesias TCGv_i32 treg = tcg_const_i32(dc->rd); 935a6338015SEdgar E. Iglesias TCGv_i32 tsize = tcg_const_i32(size - 1); 936a6338015SEdgar E. Iglesias 937d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next); 938a6338015SEdgar E. Iglesias gen_helper_memalign(cpu_env, addr, treg, t0, tsize); 939a6338015SEdgar E. Iglesias 940a6338015SEdgar E. Iglesias tcg_temp_free_i32(t0); 941a6338015SEdgar E. Iglesias tcg_temp_free_i32(treg); 942a6338015SEdgar E. Iglesias tcg_temp_free_i32(tsize); 943fcf5ef2aSThomas Huth } 944fcf5ef2aSThomas Huth 945fcf5ef2aSThomas Huth if (ex) { 9469b158558SRichard Henderson tcg_gen_mov_tl(cpu_res_addr, addr); 9479b158558SRichard Henderson tcg_gen_mov_i32(cpu_res_val, v); 948fcf5ef2aSThomas Huth } 949fcf5ef2aSThomas Huth if (dc->rd) { 950cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], v); 951fcf5ef2aSThomas Huth } 952cfeea807SEdgar E. Iglesias tcg_temp_free_i32(v); 953fcf5ef2aSThomas Huth 954fcf5ef2aSThomas Huth if (ex) { /* lwx */ 955fcf5ef2aSThomas Huth /* no support for AXI exclusive so always clear C */ 9561074c0fbSRichard Henderson tcg_gen_movi_i32(cpu_msr_c, 0); 957fcf5ef2aSThomas Huth } 958fcf5ef2aSThomas Huth 959403322eaSEdgar E. Iglesias tcg_temp_free(addr); 960fcf5ef2aSThomas Huth } 961fcf5ef2aSThomas Huth 962fcf5ef2aSThomas Huth static void dec_store(DisasContext *dc) 963fcf5ef2aSThomas Huth { 964403322eaSEdgar E. Iglesias TCGv addr; 965fcf5ef2aSThomas Huth TCGLabel *swx_skip = NULL; 966b51b3d43SEdgar E. Iglesias unsigned int size; 967d248e1beSEdgar E. Iglesias bool rev = false, ex = false, ea = false; 968d248e1beSEdgar E. Iglesias int mem_index = cpu_mmu_index(&dc->cpu->env, false); 96914776ab5STony Nguyen MemOp mop; 970fcf5ef2aSThomas Huth 971fcf5ef2aSThomas Huth mop = dc->opcode & 3; 972fcf5ef2aSThomas Huth size = 1 << mop; 973fcf5ef2aSThomas Huth if (!dc->type_b) { 974d248e1beSEdgar E. Iglesias ea = extract32(dc->ir, 7, 1); 975b51b3d43SEdgar E. Iglesias rev = extract32(dc->ir, 9, 1); 976b51b3d43SEdgar E. Iglesias ex = extract32(dc->ir, 10, 1); 977fcf5ef2aSThomas Huth } 978fcf5ef2aSThomas Huth mop |= MO_TE; 979fcf5ef2aSThomas Huth if (rev) { 980fcf5ef2aSThomas Huth mop ^= MO_BSWAP; 981fcf5ef2aSThomas Huth } 982fcf5ef2aSThomas Huth 9839ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, size > 4)) { 984fcf5ef2aSThomas Huth return; 985fcf5ef2aSThomas Huth } 986fcf5ef2aSThomas Huth 987d248e1beSEdgar E. Iglesias trap_userspace(dc, ea); 988d248e1beSEdgar E. Iglesias 989fcf5ef2aSThomas Huth t_sync_flags(dc); 990fcf5ef2aSThomas Huth /* If we get a fault on a dslot, the jmpstate better be in sync. */ 991fcf5ef2aSThomas Huth sync_jmpstate(dc); 9920dc4af5cSEdgar E. Iglesias /* SWX needs a temp_local. */ 993403322eaSEdgar E. Iglesias addr = ex ? tcg_temp_local_new() : tcg_temp_new(); 994d248e1beSEdgar E. Iglesias compute_ldst_addr(dc, ea, addr); 995d248e1beSEdgar E. Iglesias /* Extended addressing bypasses the MMU. */ 996d248e1beSEdgar E. Iglesias mem_index = ea ? MMU_NOMMU_IDX : mem_index; 997fcf5ef2aSThomas Huth 998fcf5ef2aSThomas Huth if (ex) { /* swx */ 999cfeea807SEdgar E. Iglesias TCGv_i32 tval; 1000fcf5ef2aSThomas Huth 1001fcf5ef2aSThomas Huth /* swx does not throw unaligned access errors, so force alignment */ 1002403322eaSEdgar E. Iglesias tcg_gen_andi_tl(addr, addr, ~3); 1003fcf5ef2aSThomas Huth 10041074c0fbSRichard Henderson tcg_gen_movi_i32(cpu_msr_c, 1); 1005fcf5ef2aSThomas Huth swx_skip = gen_new_label(); 10069b158558SRichard Henderson tcg_gen_brcond_tl(TCG_COND_NE, cpu_res_addr, addr, swx_skip); 1007fcf5ef2aSThomas Huth 1008071cdc67SEdgar E. Iglesias /* 1009071cdc67SEdgar E. Iglesias * Compare the value loaded at lwx with current contents of 1010071cdc67SEdgar E. Iglesias * the reserved location. 1011071cdc67SEdgar E. Iglesias */ 1012cfeea807SEdgar E. Iglesias tval = tcg_temp_new_i32(); 1013071cdc67SEdgar E. Iglesias 10149b158558SRichard Henderson tcg_gen_atomic_cmpxchg_i32(tval, addr, cpu_res_val, 1015071cdc67SEdgar E. Iglesias cpu_R[dc->rd], mem_index, 1016071cdc67SEdgar E. Iglesias mop); 1017071cdc67SEdgar E. Iglesias 10189b158558SRichard Henderson tcg_gen_brcond_i32(TCG_COND_NE, cpu_res_val, tval, swx_skip); 10191074c0fbSRichard Henderson tcg_gen_movi_i32(cpu_msr_c, 0); 1020cfeea807SEdgar E. Iglesias tcg_temp_free_i32(tval); 1021fcf5ef2aSThomas Huth } 1022fcf5ef2aSThomas Huth 1023fcf5ef2aSThomas Huth if (rev && size != 4) { 1024fcf5ef2aSThomas Huth /* Endian reverse the address. t is addr. */ 1025fcf5ef2aSThomas Huth switch (size) { 1026fcf5ef2aSThomas Huth case 1: 1027fcf5ef2aSThomas Huth { 1028a6338015SEdgar E. Iglesias tcg_gen_xori_tl(addr, addr, 3); 1029fcf5ef2aSThomas Huth break; 1030fcf5ef2aSThomas Huth } 1031fcf5ef2aSThomas Huth 1032fcf5ef2aSThomas Huth case 2: 1033fcf5ef2aSThomas Huth /* 00 -> 10 1034fcf5ef2aSThomas Huth 10 -> 00. */ 1035fcf5ef2aSThomas Huth /* Force addr into the temp. */ 1036403322eaSEdgar E. Iglesias tcg_gen_xori_tl(addr, addr, 2); 1037fcf5ef2aSThomas Huth break; 1038fcf5ef2aSThomas Huth default: 1039fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), "Invalid reverse size\n"); 1040fcf5ef2aSThomas Huth break; 1041fcf5ef2aSThomas Huth } 1042fcf5ef2aSThomas Huth } 1043071cdc67SEdgar E. Iglesias 1044071cdc67SEdgar E. Iglesias if (!ex) { 1045d248e1beSEdgar E. Iglesias tcg_gen_qemu_st_i32(cpu_R[dc->rd], addr, mem_index, mop); 1046071cdc67SEdgar E. Iglesias } 1047fcf5ef2aSThomas Huth 1048fcf5ef2aSThomas Huth /* Verify alignment if needed. */ 10491507e5f6SEdgar E. Iglesias if (dc->cpu->cfg.unaligned_exceptions && size > 1) { 1050a6338015SEdgar E. Iglesias TCGv_i32 t1 = tcg_const_i32(1); 1051a6338015SEdgar E. Iglesias TCGv_i32 treg = tcg_const_i32(dc->rd); 1052a6338015SEdgar E. Iglesias TCGv_i32 tsize = tcg_const_i32(size - 1); 1053a6338015SEdgar E. Iglesias 1054d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next); 1055fcf5ef2aSThomas Huth /* FIXME: if the alignment is wrong, we should restore the value 1056fcf5ef2aSThomas Huth * in memory. One possible way to achieve this is to probe 1057fcf5ef2aSThomas Huth * the MMU prior to the memaccess, thay way we could put 1058fcf5ef2aSThomas Huth * the alignment checks in between the probe and the mem 1059fcf5ef2aSThomas Huth * access. 1060fcf5ef2aSThomas Huth */ 1061a6338015SEdgar E. Iglesias gen_helper_memalign(cpu_env, addr, treg, t1, tsize); 1062a6338015SEdgar E. Iglesias 1063a6338015SEdgar E. Iglesias tcg_temp_free_i32(t1); 1064a6338015SEdgar E. Iglesias tcg_temp_free_i32(treg); 1065a6338015SEdgar E. Iglesias tcg_temp_free_i32(tsize); 1066fcf5ef2aSThomas Huth } 1067fcf5ef2aSThomas Huth 1068fcf5ef2aSThomas Huth if (ex) { 1069fcf5ef2aSThomas Huth gen_set_label(swx_skip); 1070fcf5ef2aSThomas Huth } 1071fcf5ef2aSThomas Huth 1072403322eaSEdgar E. Iglesias tcg_temp_free(addr); 1073fcf5ef2aSThomas Huth } 1074fcf5ef2aSThomas Huth 1075fcf5ef2aSThomas Huth static inline void eval_cc(DisasContext *dc, unsigned int cc, 10769e6e1828SEdgar E. Iglesias TCGv_i32 d, TCGv_i32 a) 1077fcf5ef2aSThomas Huth { 1078d89b86e9SEdgar E. Iglesias static const int mb_to_tcg_cc[] = { 1079d89b86e9SEdgar E. Iglesias [CC_EQ] = TCG_COND_EQ, 1080d89b86e9SEdgar E. Iglesias [CC_NE] = TCG_COND_NE, 1081d89b86e9SEdgar E. Iglesias [CC_LT] = TCG_COND_LT, 1082d89b86e9SEdgar E. Iglesias [CC_LE] = TCG_COND_LE, 1083d89b86e9SEdgar E. Iglesias [CC_GE] = TCG_COND_GE, 1084d89b86e9SEdgar E. Iglesias [CC_GT] = TCG_COND_GT, 1085d89b86e9SEdgar E. Iglesias }; 1086d89b86e9SEdgar E. Iglesias 1087fcf5ef2aSThomas Huth switch (cc) { 1088fcf5ef2aSThomas Huth case CC_EQ: 1089fcf5ef2aSThomas Huth case CC_NE: 1090fcf5ef2aSThomas Huth case CC_LT: 1091fcf5ef2aSThomas Huth case CC_LE: 1092fcf5ef2aSThomas Huth case CC_GE: 1093fcf5ef2aSThomas Huth case CC_GT: 10949e6e1828SEdgar E. Iglesias tcg_gen_setcondi_i32(mb_to_tcg_cc[cc], d, a, 0); 1095fcf5ef2aSThomas Huth break; 1096fcf5ef2aSThomas Huth default: 1097fcf5ef2aSThomas Huth cpu_abort(CPU(dc->cpu), "Unknown condition code %x.\n", cc); 1098fcf5ef2aSThomas Huth break; 1099fcf5ef2aSThomas Huth } 1100fcf5ef2aSThomas Huth } 1101fcf5ef2aSThomas Huth 11020f96e96bSRichard Henderson static void eval_cond_jmp(DisasContext *dc, TCGv_i32 pc_true, TCGv_i32 pc_false) 1103fcf5ef2aSThomas Huth { 11040f96e96bSRichard Henderson TCGv_i32 zero = tcg_const_i32(0); 1105e956caf2SEdgar E. Iglesias 11060f96e96bSRichard Henderson tcg_gen_movcond_i32(TCG_COND_NE, cpu_pc, 11079b158558SRichard Henderson cpu_btaken, zero, 1108e956caf2SEdgar E. Iglesias pc_true, pc_false); 1109e956caf2SEdgar E. Iglesias 11100f96e96bSRichard Henderson tcg_temp_free_i32(zero); 1111fcf5ef2aSThomas Huth } 1112fcf5ef2aSThomas Huth 1113f91c60f0SEdgar E. Iglesias static void dec_setup_dslot(DisasContext *dc) 1114f91c60f0SEdgar E. Iglesias { 1115f91c60f0SEdgar E. Iglesias TCGv_i32 tmp = tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)); 1116f91c60f0SEdgar E. Iglesias 1117f91c60f0SEdgar E. Iglesias dc->delayed_branch = 2; 1118f91c60f0SEdgar E. Iglesias dc->tb_flags |= D_FLAG; 1119f91c60f0SEdgar E. Iglesias 1120f91c60f0SEdgar E. Iglesias tcg_gen_st_i32(tmp, cpu_env, offsetof(CPUMBState, bimm)); 1121f91c60f0SEdgar E. Iglesias tcg_temp_free_i32(tmp); 1122f91c60f0SEdgar E. Iglesias } 1123f91c60f0SEdgar E. Iglesias 1124fcf5ef2aSThomas Huth static void dec_bcc(DisasContext *dc) 1125fcf5ef2aSThomas Huth { 1126fcf5ef2aSThomas Huth unsigned int cc; 1127fcf5ef2aSThomas Huth unsigned int dslot; 1128fcf5ef2aSThomas Huth 1129fcf5ef2aSThomas Huth cc = EXTRACT_FIELD(dc->ir, 21, 23); 1130fcf5ef2aSThomas Huth dslot = dc->ir & (1 << 25); 1131fcf5ef2aSThomas Huth 1132fcf5ef2aSThomas Huth dc->delayed_branch = 1; 1133fcf5ef2aSThomas Huth if (dslot) { 1134f91c60f0SEdgar E. Iglesias dec_setup_dslot(dc); 1135fcf5ef2aSThomas Huth } 1136fcf5ef2aSThomas Huth 1137fcf5ef2aSThomas Huth if (dec_alu_op_b_is_small_imm(dc)) { 1138fcf5ef2aSThomas Huth int32_t offset = (int32_t)((int16_t)dc->imm); /* sign-extend. */ 1139fcf5ef2aSThomas Huth 1140d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_btarget, dc->base.pc_next + offset); 1141fcf5ef2aSThomas Huth dc->jmp = JMP_DIRECT_CC; 1142d4705ae0SRichard Henderson dc->jmp_pc = dc->base.pc_next + offset; 1143fcf5ef2aSThomas Huth } else { 1144fcf5ef2aSThomas Huth dc->jmp = JMP_INDIRECT; 1145d4705ae0SRichard Henderson tcg_gen_addi_i32(cpu_btarget, *dec_alu_op_b(dc), dc->base.pc_next); 1146fcf5ef2aSThomas Huth } 11479b158558SRichard Henderson eval_cc(dc, cc, cpu_btaken, cpu_R[dc->ra]); 1148fcf5ef2aSThomas Huth } 1149fcf5ef2aSThomas Huth 1150fcf5ef2aSThomas Huth static void dec_br(DisasContext *dc) 1151fcf5ef2aSThomas Huth { 1152fcf5ef2aSThomas Huth unsigned int dslot, link, abs, mbar; 1153fcf5ef2aSThomas Huth 1154fcf5ef2aSThomas Huth dslot = dc->ir & (1 << 20); 1155fcf5ef2aSThomas Huth abs = dc->ir & (1 << 19); 1156fcf5ef2aSThomas Huth link = dc->ir & (1 << 18); 1157fcf5ef2aSThomas Huth 1158fcf5ef2aSThomas Huth /* Memory barrier. */ 1159fcf5ef2aSThomas Huth mbar = (dc->ir >> 16) & 31; 1160fcf5ef2aSThomas Huth if (mbar == 2 && dc->imm == 4) { 1161badcbf9dSEdgar E. Iglesias uint16_t mbar_imm = dc->rd; 1162badcbf9dSEdgar E. Iglesias 11633f172744SEdgar E. Iglesias /* Data access memory barrier. */ 11643f172744SEdgar E. Iglesias if ((mbar_imm & 2) == 0) { 11653f172744SEdgar E. Iglesias tcg_gen_mb(TCG_BAR_SC | TCG_MO_ALL); 11663f172744SEdgar E. Iglesias } 11673f172744SEdgar E. Iglesias 1168fcf5ef2aSThomas Huth /* mbar IMM & 16 decodes to sleep. */ 1169badcbf9dSEdgar E. Iglesias if (mbar_imm & 16) { 117041ba37c4SRichard Henderson TCGv_i32 tmp_1; 1171fcf5ef2aSThomas Huth 1172b4919e7dSEdgar E. Iglesias if (trap_userspace(dc, true)) { 1173b4919e7dSEdgar E. Iglesias /* Sleep is a privileged instruction. */ 1174b4919e7dSEdgar E. Iglesias return; 1175b4919e7dSEdgar E. Iglesias } 1176b4919e7dSEdgar E. Iglesias 1177fcf5ef2aSThomas Huth t_sync_flags(dc); 117841ba37c4SRichard Henderson 117941ba37c4SRichard Henderson tmp_1 = tcg_const_i32(1); 1180fcf5ef2aSThomas Huth tcg_gen_st_i32(tmp_1, cpu_env, 1181fcf5ef2aSThomas Huth -offsetof(MicroBlazeCPU, env) 1182fcf5ef2aSThomas Huth +offsetof(CPUState, halted)); 1183fcf5ef2aSThomas Huth tcg_temp_free_i32(tmp_1); 118441ba37c4SRichard Henderson 1185d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next + 4); 118641ba37c4SRichard Henderson 118741ba37c4SRichard Henderson gen_raise_exception(dc, EXCP_HLT); 1188fcf5ef2aSThomas Huth return; 1189fcf5ef2aSThomas Huth } 1190fcf5ef2aSThomas Huth /* Break the TB. */ 1191fcf5ef2aSThomas Huth dc->cpustate_changed = 1; 1192fcf5ef2aSThomas Huth return; 1193fcf5ef2aSThomas Huth } 1194fcf5ef2aSThomas Huth 1195fcf5ef2aSThomas Huth dc->delayed_branch = 1; 1196fcf5ef2aSThomas Huth if (dslot) { 1197f91c60f0SEdgar E. Iglesias dec_setup_dslot(dc); 1198fcf5ef2aSThomas Huth } 1199fcf5ef2aSThomas Huth if (link && dc->rd) 1200d4705ae0SRichard Henderson tcg_gen_movi_i32(cpu_R[dc->rd], dc->base.pc_next); 1201fcf5ef2aSThomas Huth 1202fcf5ef2aSThomas Huth dc->jmp = JMP_INDIRECT; 1203fcf5ef2aSThomas Huth if (abs) { 12049b158558SRichard Henderson tcg_gen_movi_i32(cpu_btaken, 1); 12050f96e96bSRichard Henderson tcg_gen_mov_i32(cpu_btarget, *(dec_alu_op_b(dc))); 1206fcf5ef2aSThomas Huth if (link && !dslot) { 120741ba37c4SRichard Henderson if (!(dc->tb_flags & IMM_FLAG) && 120841ba37c4SRichard Henderson (dc->imm == 8 || dc->imm == 0x18)) { 120941ba37c4SRichard Henderson gen_raise_exception_sync(dc, EXCP_BREAK); 121041ba37c4SRichard Henderson } 1211fcf5ef2aSThomas Huth if (dc->imm == 0) { 1212bdfc1e88SEdgar E. Iglesias if (trap_userspace(dc, true)) { 1213fcf5ef2aSThomas Huth return; 1214fcf5ef2aSThomas Huth } 121541ba37c4SRichard Henderson gen_raise_exception_sync(dc, EXCP_DEBUG); 1216fcf5ef2aSThomas Huth } 1217fcf5ef2aSThomas Huth } 1218fcf5ef2aSThomas Huth } else { 1219fcf5ef2aSThomas Huth if (dec_alu_op_b_is_small_imm(dc)) { 1220fcf5ef2aSThomas Huth dc->jmp = JMP_DIRECT; 1221d4705ae0SRichard Henderson dc->jmp_pc = dc->base.pc_next + (int32_t)((int16_t)dc->imm); 1222fcf5ef2aSThomas Huth } else { 12239b158558SRichard Henderson tcg_gen_movi_i32(cpu_btaken, 1); 1224d4705ae0SRichard Henderson tcg_gen_addi_i32(cpu_btarget, *dec_alu_op_b(dc), dc->base.pc_next); 1225fcf5ef2aSThomas Huth } 1226fcf5ef2aSThomas Huth } 1227fcf5ef2aSThomas Huth } 1228fcf5ef2aSThomas Huth 1229fcf5ef2aSThomas Huth static inline void do_rti(DisasContext *dc) 1230fcf5ef2aSThomas Huth { 1231cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1232cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1233cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 12343e0e16aeSRichard Henderson tcg_gen_mov_i32(t1, cpu_msr); 12350a22f8cfSEdgar E. Iglesias tcg_gen_shri_i32(t0, t1, 1); 12360a22f8cfSEdgar E. Iglesias tcg_gen_ori_i32(t1, t1, MSR_IE); 1237cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 1238fcf5ef2aSThomas Huth 1239cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1240cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 1241fcf5ef2aSThomas Huth msr_write(dc, t1); 1242cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1243cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 1244fcf5ef2aSThomas Huth dc->tb_flags &= ~DRTI_FLAG; 1245fcf5ef2aSThomas Huth } 1246fcf5ef2aSThomas Huth 1247fcf5ef2aSThomas Huth static inline void do_rtb(DisasContext *dc) 1248fcf5ef2aSThomas Huth { 1249cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1250cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1251cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 12523e0e16aeSRichard Henderson tcg_gen_mov_i32(t1, cpu_msr); 12530a22f8cfSEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~MSR_BIP); 1254cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(t0, t1, 1); 1255cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 1256fcf5ef2aSThomas Huth 1257cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1258cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 1259fcf5ef2aSThomas Huth msr_write(dc, t1); 1260cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1261cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 1262fcf5ef2aSThomas Huth dc->tb_flags &= ~DRTB_FLAG; 1263fcf5ef2aSThomas Huth } 1264fcf5ef2aSThomas Huth 1265fcf5ef2aSThomas Huth static inline void do_rte(DisasContext *dc) 1266fcf5ef2aSThomas Huth { 1267cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1268cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1269cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 1270fcf5ef2aSThomas Huth 12713e0e16aeSRichard Henderson tcg_gen_mov_i32(t1, cpu_msr); 12720a22f8cfSEdgar E. Iglesias tcg_gen_ori_i32(t1, t1, MSR_EE); 1273cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~MSR_EIP); 1274cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(t0, t1, 1); 1275cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 1276fcf5ef2aSThomas Huth 1277cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1278cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 1279fcf5ef2aSThomas Huth msr_write(dc, t1); 1280cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1281cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 1282fcf5ef2aSThomas Huth dc->tb_flags &= ~DRTE_FLAG; 1283fcf5ef2aSThomas Huth } 1284fcf5ef2aSThomas Huth 1285fcf5ef2aSThomas Huth static void dec_rts(DisasContext *dc) 1286fcf5ef2aSThomas Huth { 1287fcf5ef2aSThomas Huth unsigned int b_bit, i_bit, e_bit; 1288fcf5ef2aSThomas Huth 1289fcf5ef2aSThomas Huth i_bit = dc->ir & (1 << 21); 1290fcf5ef2aSThomas Huth b_bit = dc->ir & (1 << 22); 1291fcf5ef2aSThomas Huth e_bit = dc->ir & (1 << 23); 1292fcf5ef2aSThomas Huth 1293bdfc1e88SEdgar E. Iglesias if (trap_userspace(dc, i_bit || b_bit || e_bit)) { 1294bdfc1e88SEdgar E. Iglesias return; 1295bdfc1e88SEdgar E. Iglesias } 1296bdfc1e88SEdgar E. Iglesias 1297f91c60f0SEdgar E. Iglesias dec_setup_dslot(dc); 1298fcf5ef2aSThomas Huth 1299fcf5ef2aSThomas Huth if (i_bit) { 1300fcf5ef2aSThomas Huth dc->tb_flags |= DRTI_FLAG; 1301fcf5ef2aSThomas Huth } else if (b_bit) { 1302fcf5ef2aSThomas Huth dc->tb_flags |= DRTB_FLAG; 1303fcf5ef2aSThomas Huth } else if (e_bit) { 1304fcf5ef2aSThomas Huth dc->tb_flags |= DRTE_FLAG; 1305*11105d67SRichard Henderson } 1306fcf5ef2aSThomas Huth 1307fcf5ef2aSThomas Huth dc->jmp = JMP_INDIRECT; 13089b158558SRichard Henderson tcg_gen_movi_i32(cpu_btaken, 1); 13090f96e96bSRichard Henderson tcg_gen_add_i32(cpu_btarget, cpu_R[dc->ra], *dec_alu_op_b(dc)); 1310fcf5ef2aSThomas Huth } 1311fcf5ef2aSThomas Huth 1312fcf5ef2aSThomas Huth static int dec_check_fpuv2(DisasContext *dc) 1313fcf5ef2aSThomas Huth { 1314fcf5ef2aSThomas Huth if ((dc->cpu->cfg.use_fpu != 2) && (dc->tb_flags & MSR_EE_FLAG)) { 131541ba37c4SRichard Henderson gen_raise_hw_excp(dc, ESR_EC_FPU); 1316fcf5ef2aSThomas Huth } 13172016a6a7SJoe Komlodi return (dc->cpu->cfg.use_fpu == 2) ? PVR2_USE_FPU2_MASK : 0; 1318fcf5ef2aSThomas Huth } 1319fcf5ef2aSThomas Huth 1320fcf5ef2aSThomas Huth static void dec_fpu(DisasContext *dc) 1321fcf5ef2aSThomas Huth { 1322fcf5ef2aSThomas Huth unsigned int fpu_insn; 1323fcf5ef2aSThomas Huth 13249ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, !dc->cpu->cfg.use_fpu)) { 1325fcf5ef2aSThomas Huth return; 1326fcf5ef2aSThomas Huth } 1327fcf5ef2aSThomas Huth 1328fcf5ef2aSThomas Huth fpu_insn = (dc->ir >> 7) & 7; 1329fcf5ef2aSThomas Huth 1330fcf5ef2aSThomas Huth switch (fpu_insn) { 1331fcf5ef2aSThomas Huth case 0: 1332fcf5ef2aSThomas Huth gen_helper_fadd(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 1333fcf5ef2aSThomas Huth cpu_R[dc->rb]); 1334fcf5ef2aSThomas Huth break; 1335fcf5ef2aSThomas Huth 1336fcf5ef2aSThomas Huth case 1: 1337fcf5ef2aSThomas Huth gen_helper_frsub(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 1338fcf5ef2aSThomas Huth cpu_R[dc->rb]); 1339fcf5ef2aSThomas Huth break; 1340fcf5ef2aSThomas Huth 1341fcf5ef2aSThomas Huth case 2: 1342fcf5ef2aSThomas Huth gen_helper_fmul(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 1343fcf5ef2aSThomas Huth cpu_R[dc->rb]); 1344fcf5ef2aSThomas Huth break; 1345fcf5ef2aSThomas Huth 1346fcf5ef2aSThomas Huth case 3: 1347fcf5ef2aSThomas Huth gen_helper_fdiv(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 1348fcf5ef2aSThomas Huth cpu_R[dc->rb]); 1349fcf5ef2aSThomas Huth break; 1350fcf5ef2aSThomas Huth 1351fcf5ef2aSThomas Huth case 4: 1352fcf5ef2aSThomas Huth switch ((dc->ir >> 4) & 7) { 1353fcf5ef2aSThomas Huth case 0: 1354fcf5ef2aSThomas Huth gen_helper_fcmp_un(cpu_R[dc->rd], cpu_env, 1355fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1356fcf5ef2aSThomas Huth break; 1357fcf5ef2aSThomas Huth case 1: 1358fcf5ef2aSThomas Huth gen_helper_fcmp_lt(cpu_R[dc->rd], cpu_env, 1359fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1360fcf5ef2aSThomas Huth break; 1361fcf5ef2aSThomas Huth case 2: 1362fcf5ef2aSThomas Huth gen_helper_fcmp_eq(cpu_R[dc->rd], cpu_env, 1363fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1364fcf5ef2aSThomas Huth break; 1365fcf5ef2aSThomas Huth case 3: 1366fcf5ef2aSThomas Huth gen_helper_fcmp_le(cpu_R[dc->rd], cpu_env, 1367fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1368fcf5ef2aSThomas Huth break; 1369fcf5ef2aSThomas Huth case 4: 1370fcf5ef2aSThomas Huth gen_helper_fcmp_gt(cpu_R[dc->rd], cpu_env, 1371fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1372fcf5ef2aSThomas Huth break; 1373fcf5ef2aSThomas Huth case 5: 1374fcf5ef2aSThomas Huth gen_helper_fcmp_ne(cpu_R[dc->rd], cpu_env, 1375fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1376fcf5ef2aSThomas Huth break; 1377fcf5ef2aSThomas Huth case 6: 1378fcf5ef2aSThomas Huth gen_helper_fcmp_ge(cpu_R[dc->rd], cpu_env, 1379fcf5ef2aSThomas Huth cpu_R[dc->ra], cpu_R[dc->rb]); 1380fcf5ef2aSThomas Huth break; 1381fcf5ef2aSThomas Huth default: 1382fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP, 1383fcf5ef2aSThomas Huth "unimplemented fcmp fpu_insn=%x pc=%x" 1384fcf5ef2aSThomas Huth " opc=%x\n", 1385d4705ae0SRichard Henderson fpu_insn, (uint32_t)dc->base.pc_next, 1386d4705ae0SRichard Henderson dc->opcode); 1387fcf5ef2aSThomas Huth dc->abort_at_next_insn = 1; 1388fcf5ef2aSThomas Huth break; 1389fcf5ef2aSThomas Huth } 1390fcf5ef2aSThomas Huth break; 1391fcf5ef2aSThomas Huth 1392fcf5ef2aSThomas Huth case 5: 1393fcf5ef2aSThomas Huth if (!dec_check_fpuv2(dc)) { 1394fcf5ef2aSThomas Huth return; 1395fcf5ef2aSThomas Huth } 1396fcf5ef2aSThomas Huth gen_helper_flt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 1397fcf5ef2aSThomas Huth break; 1398fcf5ef2aSThomas Huth 1399fcf5ef2aSThomas Huth case 6: 1400fcf5ef2aSThomas Huth if (!dec_check_fpuv2(dc)) { 1401fcf5ef2aSThomas Huth return; 1402fcf5ef2aSThomas Huth } 1403fcf5ef2aSThomas Huth gen_helper_fint(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 1404fcf5ef2aSThomas Huth break; 1405fcf5ef2aSThomas Huth 1406fcf5ef2aSThomas Huth case 7: 1407fcf5ef2aSThomas Huth if (!dec_check_fpuv2(dc)) { 1408fcf5ef2aSThomas Huth return; 1409fcf5ef2aSThomas Huth } 1410fcf5ef2aSThomas Huth gen_helper_fsqrt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 1411fcf5ef2aSThomas Huth break; 1412fcf5ef2aSThomas Huth 1413fcf5ef2aSThomas Huth default: 1414fcf5ef2aSThomas Huth qemu_log_mask(LOG_UNIMP, "unimplemented FPU insn fpu_insn=%x pc=%x" 1415fcf5ef2aSThomas Huth " opc=%x\n", 1416d4705ae0SRichard Henderson fpu_insn, (uint32_t)dc->base.pc_next, dc->opcode); 1417fcf5ef2aSThomas Huth dc->abort_at_next_insn = 1; 1418fcf5ef2aSThomas Huth break; 1419fcf5ef2aSThomas Huth } 1420fcf5ef2aSThomas Huth } 1421fcf5ef2aSThomas Huth 1422fcf5ef2aSThomas Huth static void dec_null(DisasContext *dc) 1423fcf5ef2aSThomas Huth { 14249ba8cd45SEdgar E. Iglesias if (trap_illegal(dc, true)) { 1425fcf5ef2aSThomas Huth return; 1426fcf5ef2aSThomas Huth } 1427d4705ae0SRichard Henderson qemu_log_mask(LOG_GUEST_ERROR, "unknown insn pc=%x opc=%x\n", 1428d4705ae0SRichard Henderson (uint32_t)dc->base.pc_next, dc->opcode); 1429fcf5ef2aSThomas Huth dc->abort_at_next_insn = 1; 1430fcf5ef2aSThomas Huth } 1431fcf5ef2aSThomas Huth 1432fcf5ef2aSThomas Huth /* Insns connected to FSL or AXI stream attached devices. */ 1433fcf5ef2aSThomas Huth static void dec_stream(DisasContext *dc) 1434fcf5ef2aSThomas Huth { 1435fcf5ef2aSThomas Huth TCGv_i32 t_id, t_ctrl; 1436fcf5ef2aSThomas Huth int ctrl; 1437fcf5ef2aSThomas Huth 1438bdfc1e88SEdgar E. Iglesias if (trap_userspace(dc, true)) { 1439fcf5ef2aSThomas Huth return; 1440fcf5ef2aSThomas Huth } 1441fcf5ef2aSThomas Huth 1442cfeea807SEdgar E. Iglesias t_id = tcg_temp_new_i32(); 1443fcf5ef2aSThomas Huth if (dc->type_b) { 1444cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(t_id, dc->imm & 0xf); 1445fcf5ef2aSThomas Huth ctrl = dc->imm >> 10; 1446fcf5ef2aSThomas Huth } else { 1447cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t_id, cpu_R[dc->rb], 0xf); 1448fcf5ef2aSThomas Huth ctrl = dc->imm >> 5; 1449fcf5ef2aSThomas Huth } 1450fcf5ef2aSThomas Huth 1451cfeea807SEdgar E. Iglesias t_ctrl = tcg_const_i32(ctrl); 1452fcf5ef2aSThomas Huth 1453fcf5ef2aSThomas Huth if (dc->rd == 0) { 1454fcf5ef2aSThomas Huth gen_helper_put(t_id, t_ctrl, cpu_R[dc->ra]); 1455fcf5ef2aSThomas Huth } else { 1456fcf5ef2aSThomas Huth gen_helper_get(cpu_R[dc->rd], t_id, t_ctrl); 1457fcf5ef2aSThomas Huth } 1458cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t_id); 1459cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t_ctrl); 1460fcf5ef2aSThomas Huth } 1461fcf5ef2aSThomas Huth 1462fcf5ef2aSThomas Huth static struct decoder_info { 1463fcf5ef2aSThomas Huth struct { 1464fcf5ef2aSThomas Huth uint32_t bits; 1465fcf5ef2aSThomas Huth uint32_t mask; 1466fcf5ef2aSThomas Huth }; 1467fcf5ef2aSThomas Huth void (*dec)(DisasContext *dc); 1468fcf5ef2aSThomas Huth } decinfo[] = { 1469fcf5ef2aSThomas Huth {DEC_ADD, dec_add}, 1470fcf5ef2aSThomas Huth {DEC_SUB, dec_sub}, 1471fcf5ef2aSThomas Huth {DEC_AND, dec_and}, 1472fcf5ef2aSThomas Huth {DEC_XOR, dec_xor}, 1473fcf5ef2aSThomas Huth {DEC_OR, dec_or}, 1474fcf5ef2aSThomas Huth {DEC_BIT, dec_bit}, 1475fcf5ef2aSThomas Huth {DEC_BARREL, dec_barrel}, 1476fcf5ef2aSThomas Huth {DEC_LD, dec_load}, 1477fcf5ef2aSThomas Huth {DEC_ST, dec_store}, 1478fcf5ef2aSThomas Huth {DEC_IMM, dec_imm}, 1479fcf5ef2aSThomas Huth {DEC_BR, dec_br}, 1480fcf5ef2aSThomas Huth {DEC_BCC, dec_bcc}, 1481fcf5ef2aSThomas Huth {DEC_RTS, dec_rts}, 1482fcf5ef2aSThomas Huth {DEC_FPU, dec_fpu}, 1483fcf5ef2aSThomas Huth {DEC_MUL, dec_mul}, 1484fcf5ef2aSThomas Huth {DEC_DIV, dec_div}, 1485fcf5ef2aSThomas Huth {DEC_MSR, dec_msr}, 1486fcf5ef2aSThomas Huth {DEC_STREAM, dec_stream}, 1487fcf5ef2aSThomas Huth {{0, 0}, dec_null} 1488fcf5ef2aSThomas Huth }; 1489fcf5ef2aSThomas Huth 1490fcf5ef2aSThomas Huth static inline void decode(DisasContext *dc, uint32_t ir) 1491fcf5ef2aSThomas Huth { 1492fcf5ef2aSThomas Huth int i; 1493fcf5ef2aSThomas Huth 1494fcf5ef2aSThomas Huth dc->ir = ir; 1495fcf5ef2aSThomas Huth 1496462c2544SEdgar E. Iglesias if (ir == 0) { 14971ee1bd28SEdgar E. Iglesias trap_illegal(dc, dc->cpu->cfg.opcode_0_illegal); 1498462c2544SEdgar E. Iglesias /* Don't decode nop/zero instructions any further. */ 1499462c2544SEdgar E. Iglesias return; 1500462c2544SEdgar E. Iglesias } 1501fcf5ef2aSThomas Huth 1502fcf5ef2aSThomas Huth /* bit 2 seems to indicate insn type. */ 1503fcf5ef2aSThomas Huth dc->type_b = ir & (1 << 29); 1504fcf5ef2aSThomas Huth 1505fcf5ef2aSThomas Huth dc->opcode = EXTRACT_FIELD(ir, 26, 31); 1506fcf5ef2aSThomas Huth dc->rd = EXTRACT_FIELD(ir, 21, 25); 1507fcf5ef2aSThomas Huth dc->ra = EXTRACT_FIELD(ir, 16, 20); 1508fcf5ef2aSThomas Huth dc->rb = EXTRACT_FIELD(ir, 11, 15); 1509fcf5ef2aSThomas Huth dc->imm = EXTRACT_FIELD(ir, 0, 15); 1510fcf5ef2aSThomas Huth 1511fcf5ef2aSThomas Huth /* Large switch for all insns. */ 1512fcf5ef2aSThomas Huth for (i = 0; i < ARRAY_SIZE(decinfo); i++) { 1513fcf5ef2aSThomas Huth if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits) { 1514fcf5ef2aSThomas Huth decinfo[i].dec(dc); 1515fcf5ef2aSThomas Huth break; 1516fcf5ef2aSThomas Huth } 1517fcf5ef2aSThomas Huth } 1518fcf5ef2aSThomas Huth } 1519fcf5ef2aSThomas Huth 1520372122e3SRichard Henderson static void mb_tr_init_disas_context(DisasContextBase *dcb, CPUState *cs) 1521fcf5ef2aSThomas Huth { 1522372122e3SRichard Henderson DisasContext *dc = container_of(dcb, DisasContext, base); 1523372122e3SRichard Henderson MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); 1524372122e3SRichard Henderson int bound; 1525fcf5ef2aSThomas Huth 1526fcf5ef2aSThomas Huth dc->cpu = cpu; 1527372122e3SRichard Henderson dc->synced_flags = dc->tb_flags = dc->base.tb->flags; 1528fcf5ef2aSThomas Huth dc->delayed_branch = !!(dc->tb_flags & D_FLAG); 1529372122e3SRichard Henderson dc->jmp = dc->delayed_branch ? JMP_INDIRECT : JMP_NOJMP; 1530fcf5ef2aSThomas Huth dc->cpustate_changed = 0; 1531fcf5ef2aSThomas Huth dc->abort_at_next_insn = 0; 1532fcf5ef2aSThomas Huth 1533372122e3SRichard Henderson bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4; 1534372122e3SRichard Henderson dc->base.max_insns = MIN(dc->base.max_insns, bound); 1535fcf5ef2aSThomas Huth } 1536fcf5ef2aSThomas Huth 1537372122e3SRichard Henderson static void mb_tr_tb_start(DisasContextBase *dcb, CPUState *cs) 1538fcf5ef2aSThomas Huth { 1539fcf5ef2aSThomas Huth } 1540fcf5ef2aSThomas Huth 1541372122e3SRichard Henderson static void mb_tr_insn_start(DisasContextBase *dcb, CPUState *cs) 1542372122e3SRichard Henderson { 1543372122e3SRichard Henderson tcg_gen_insn_start(dcb->pc_next); 1544372122e3SRichard Henderson } 1545fcf5ef2aSThomas Huth 1546372122e3SRichard Henderson static bool mb_tr_breakpoint_check(DisasContextBase *dcb, CPUState *cs, 1547372122e3SRichard Henderson const CPUBreakpoint *bp) 1548372122e3SRichard Henderson { 1549372122e3SRichard Henderson DisasContext *dc = container_of(dcb, DisasContext, base); 1550372122e3SRichard Henderson 1551372122e3SRichard Henderson gen_raise_exception_sync(dc, EXCP_DEBUG); 1552372122e3SRichard Henderson 1553372122e3SRichard Henderson /* 1554372122e3SRichard Henderson * The address covered by the breakpoint must be included in 1555372122e3SRichard Henderson * [tb->pc, tb->pc + tb->size) in order to for it to be 1556372122e3SRichard Henderson * properly cleared -- thus we increment the PC here so that 1557372122e3SRichard Henderson * the logic setting tb->size below does the right thing. 1558372122e3SRichard Henderson */ 1559372122e3SRichard Henderson dc->base.pc_next += 4; 1560372122e3SRichard Henderson return true; 1561372122e3SRichard Henderson } 1562372122e3SRichard Henderson 1563372122e3SRichard Henderson static void mb_tr_translate_insn(DisasContextBase *dcb, CPUState *cs) 1564372122e3SRichard Henderson { 1565372122e3SRichard Henderson DisasContext *dc = container_of(dcb, DisasContext, base); 1566372122e3SRichard Henderson CPUMBState *env = cs->env_ptr; 1567372122e3SRichard Henderson 1568372122e3SRichard Henderson /* TODO: This should raise an exception, not terminate qemu. */ 1569372122e3SRichard Henderson if (dc->base.pc_next & 3) { 1570372122e3SRichard Henderson cpu_abort(cs, "Microblaze: unaligned PC=%x\n", 1571372122e3SRichard Henderson (uint32_t)dc->base.pc_next); 1572fcf5ef2aSThomas Huth } 1573fcf5ef2aSThomas Huth 1574fcf5ef2aSThomas Huth dc->clear_imm = 1; 1575d4705ae0SRichard Henderson decode(dc, cpu_ldl_code(env, dc->base.pc_next)); 1576372122e3SRichard Henderson if (dc->clear_imm) { 1577fcf5ef2aSThomas Huth dc->tb_flags &= ~IMM_FLAG; 1578372122e3SRichard Henderson } 1579d4705ae0SRichard Henderson dc->base.pc_next += 4; 1580fcf5ef2aSThomas Huth 1581372122e3SRichard Henderson if (dc->delayed_branch && --dc->delayed_branch == 0) { 1582372122e3SRichard Henderson if (dc->tb_flags & DRTI_FLAG) { 1583fcf5ef2aSThomas Huth do_rti(dc); 1584372122e3SRichard Henderson } 1585372122e3SRichard Henderson if (dc->tb_flags & DRTB_FLAG) { 1586fcf5ef2aSThomas Huth do_rtb(dc); 1587372122e3SRichard Henderson } 1588372122e3SRichard Henderson if (dc->tb_flags & DRTE_FLAG) { 1589fcf5ef2aSThomas Huth do_rte(dc); 1590372122e3SRichard Henderson } 1591fcf5ef2aSThomas Huth /* Clear the delay slot flag. */ 1592fcf5ef2aSThomas Huth dc->tb_flags &= ~D_FLAG; 1593372122e3SRichard Henderson dc->base.is_jmp = DISAS_JUMP; 1594372122e3SRichard Henderson } 1595372122e3SRichard Henderson 1596372122e3SRichard Henderson /* Force an exit if the per-tb cpu state has changed. */ 1597372122e3SRichard Henderson if (dc->base.is_jmp == DISAS_NEXT && dc->cpustate_changed) { 1598372122e3SRichard Henderson dc->base.is_jmp = DISAS_UPDATE; 1599372122e3SRichard Henderson tcg_gen_movi_i32(cpu_pc, dc->base.pc_next); 1600372122e3SRichard Henderson } 1601372122e3SRichard Henderson } 1602372122e3SRichard Henderson 1603372122e3SRichard Henderson static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs) 1604372122e3SRichard Henderson { 1605372122e3SRichard Henderson DisasContext *dc = container_of(dcb, DisasContext, base); 1606372122e3SRichard Henderson 1607372122e3SRichard Henderson assert(!dc->abort_at_next_insn); 1608372122e3SRichard Henderson 1609372122e3SRichard Henderson if (dc->base.is_jmp == DISAS_NORETURN) { 1610372122e3SRichard Henderson /* We have already exited the TB. */ 1611372122e3SRichard Henderson return; 1612372122e3SRichard Henderson } 1613372122e3SRichard Henderson 1614372122e3SRichard Henderson t_sync_flags(dc); 1615372122e3SRichard Henderson if (dc->tb_flags & D_FLAG) { 1616372122e3SRichard Henderson sync_jmpstate(dc); 1617372122e3SRichard Henderson dc->jmp = JMP_NOJMP; 1618372122e3SRichard Henderson } 1619372122e3SRichard Henderson 1620372122e3SRichard Henderson switch (dc->base.is_jmp) { 1621372122e3SRichard Henderson case DISAS_TOO_MANY: 1622372122e3SRichard Henderson assert(dc->jmp == JMP_NOJMP); 1623372122e3SRichard Henderson gen_goto_tb(dc, 0, dc->base.pc_next); 1624372122e3SRichard Henderson return; 1625372122e3SRichard Henderson 1626372122e3SRichard Henderson case DISAS_UPDATE: 1627372122e3SRichard Henderson assert(dc->jmp == JMP_NOJMP); 1628372122e3SRichard Henderson if (unlikely(cs->singlestep_enabled)) { 1629372122e3SRichard Henderson gen_raise_exception(dc, EXCP_DEBUG); 1630372122e3SRichard Henderson } else { 1631372122e3SRichard Henderson tcg_gen_exit_tb(NULL, 0); 1632372122e3SRichard Henderson } 1633372122e3SRichard Henderson return; 1634372122e3SRichard Henderson 1635372122e3SRichard Henderson case DISAS_JUMP: 1636372122e3SRichard Henderson switch (dc->jmp) { 1637372122e3SRichard Henderson case JMP_INDIRECT: 1638372122e3SRichard Henderson { 1639d4705ae0SRichard Henderson TCGv_i32 tmp_pc = tcg_const_i32(dc->base.pc_next); 16400f96e96bSRichard Henderson eval_cond_jmp(dc, cpu_btarget, tmp_pc); 16410f96e96bSRichard Henderson tcg_temp_free_i32(tmp_pc); 1642372122e3SRichard Henderson 1643372122e3SRichard Henderson if (unlikely(cs->singlestep_enabled)) { 1644372122e3SRichard Henderson gen_raise_exception(dc, EXCP_DEBUG); 1645372122e3SRichard Henderson } else { 1646372122e3SRichard Henderson tcg_gen_exit_tb(NULL, 0); 1647372122e3SRichard Henderson } 1648372122e3SRichard Henderson } 1649372122e3SRichard Henderson return; 1650372122e3SRichard Henderson 1651372122e3SRichard Henderson case JMP_DIRECT_CC: 1652372122e3SRichard Henderson { 1653fcf5ef2aSThomas Huth TCGLabel *l1 = gen_new_label(); 16549b158558SRichard Henderson tcg_gen_brcondi_i32(TCG_COND_NE, cpu_btaken, 0, l1); 1655d4705ae0SRichard Henderson gen_goto_tb(dc, 1, dc->base.pc_next); 1656fcf5ef2aSThomas Huth gen_set_label(l1); 1657372122e3SRichard Henderson } 1658372122e3SRichard Henderson /* fall through */ 1659372122e3SRichard Henderson 1660372122e3SRichard Henderson case JMP_DIRECT: 1661fcf5ef2aSThomas Huth gen_goto_tb(dc, 0, dc->jmp_pc); 1662372122e3SRichard Henderson return; 1663fcf5ef2aSThomas Huth } 1664372122e3SRichard Henderson /* fall through */ 1665fcf5ef2aSThomas Huth 1666a2b80dbdSRichard Henderson default: 1667a2b80dbdSRichard Henderson g_assert_not_reached(); 1668fcf5ef2aSThomas Huth } 1669fcf5ef2aSThomas Huth } 1670fcf5ef2aSThomas Huth 1671372122e3SRichard Henderson static void mb_tr_disas_log(const DisasContextBase *dcb, CPUState *cs) 1672372122e3SRichard Henderson { 1673372122e3SRichard Henderson qemu_log("IN: %s\n", lookup_symbol(dcb->pc_first)); 1674372122e3SRichard Henderson log_target_disas(cs, dcb->pc_first, dcb->tb->size); 1675fcf5ef2aSThomas Huth } 1676372122e3SRichard Henderson 1677372122e3SRichard Henderson static const TranslatorOps mb_tr_ops = { 1678372122e3SRichard Henderson .init_disas_context = mb_tr_init_disas_context, 1679372122e3SRichard Henderson .tb_start = mb_tr_tb_start, 1680372122e3SRichard Henderson .insn_start = mb_tr_insn_start, 1681372122e3SRichard Henderson .breakpoint_check = mb_tr_breakpoint_check, 1682372122e3SRichard Henderson .translate_insn = mb_tr_translate_insn, 1683372122e3SRichard Henderson .tb_stop = mb_tr_tb_stop, 1684372122e3SRichard Henderson .disas_log = mb_tr_disas_log, 1685372122e3SRichard Henderson }; 1686372122e3SRichard Henderson 1687372122e3SRichard Henderson void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb, int max_insns) 1688372122e3SRichard Henderson { 1689372122e3SRichard Henderson DisasContext dc; 1690372122e3SRichard Henderson translator_loop(&mb_tr_ops, &dc.base, cpu, tb, max_insns); 1691fcf5ef2aSThomas Huth } 1692fcf5ef2aSThomas Huth 169390c84c56SMarkus Armbruster void mb_cpu_dump_state(CPUState *cs, FILE *f, int flags) 1694fcf5ef2aSThomas Huth { 1695fcf5ef2aSThomas Huth MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); 1696fcf5ef2aSThomas Huth CPUMBState *env = &cpu->env; 1697fcf5ef2aSThomas Huth int i; 1698fcf5ef2aSThomas Huth 169990c84c56SMarkus Armbruster if (!env) { 1700fcf5ef2aSThomas Huth return; 170190c84c56SMarkus Armbruster } 1702fcf5ef2aSThomas Huth 17030f96e96bSRichard Henderson qemu_fprintf(f, "IN: PC=%x %s\n", 170476e8187dSRichard Henderson env->pc, lookup_symbol(env->pc)); 17056efd5599SRichard Henderson qemu_fprintf(f, "rmsr=%x resr=%x rear=%" PRIx64 " " 1706eb2022b7SRichard Henderson "imm=%x iflags=%x fsr=%x rbtr=%x\n", 170778e9caf2SRichard Henderson env->msr, env->esr, env->ear, 1708eb2022b7SRichard Henderson env->imm, env->iflags, env->fsr, env->btr); 17090f96e96bSRichard Henderson qemu_fprintf(f, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n", 1710fcf5ef2aSThomas Huth env->btaken, env->btarget, 17112e5282caSRichard Henderson (env->msr & MSR_UM) ? "user" : "kernel", 17122e5282caSRichard Henderson (env->msr & MSR_UMS) ? "user" : "kernel", 17132e5282caSRichard Henderson (bool)(env->msr & MSR_EIP), 17142e5282caSRichard Henderson (bool)(env->msr & MSR_IE)); 17152ead1b18SJoe Komlodi for (i = 0; i < 12; i++) { 17162ead1b18SJoe Komlodi qemu_fprintf(f, "rpvr%2.2d=%8.8x ", i, env->pvr.regs[i]); 17172ead1b18SJoe Komlodi if ((i + 1) % 4 == 0) { 17182ead1b18SJoe Komlodi qemu_fprintf(f, "\n"); 17192ead1b18SJoe Komlodi } 17202ead1b18SJoe Komlodi } 1721fcf5ef2aSThomas Huth 17222ead1b18SJoe Komlodi /* Registers that aren't modeled are reported as 0 */ 172339db007eSRichard Henderson qemu_fprintf(f, "redr=%x rpid=0 rzpr=0 rtlbx=0 rtlbsx=0 " 1724af20a93aSRichard Henderson "rtlblo=0 rtlbhi=0\n", env->edr); 17252ead1b18SJoe Komlodi qemu_fprintf(f, "slr=%x shr=%x\n", env->slr, env->shr); 1726fcf5ef2aSThomas Huth for (i = 0; i < 32; i++) { 172790c84c56SMarkus Armbruster qemu_fprintf(f, "r%2.2d=%8.8x ", i, env->regs[i]); 1728fcf5ef2aSThomas Huth if ((i + 1) % 4 == 0) 172990c84c56SMarkus Armbruster qemu_fprintf(f, "\n"); 1730fcf5ef2aSThomas Huth } 173190c84c56SMarkus Armbruster qemu_fprintf(f, "\n\n"); 1732fcf5ef2aSThomas Huth } 1733fcf5ef2aSThomas Huth 1734fcf5ef2aSThomas Huth void mb_tcg_init(void) 1735fcf5ef2aSThomas Huth { 1736480d29a8SRichard Henderson #define R(X) { &cpu_R[X], offsetof(CPUMBState, regs[X]), "r" #X } 1737480d29a8SRichard Henderson #define SP(X) { &cpu_##X, offsetof(CPUMBState, X), #X } 1738fcf5ef2aSThomas Huth 1739480d29a8SRichard Henderson static const struct { 1740480d29a8SRichard Henderson TCGv_i32 *var; int ofs; char name[8]; 1741480d29a8SRichard Henderson } i32s[] = { 1742480d29a8SRichard Henderson R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7), 1743480d29a8SRichard Henderson R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15), 1744480d29a8SRichard Henderson R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23), 1745480d29a8SRichard Henderson R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31), 1746480d29a8SRichard Henderson 1747480d29a8SRichard Henderson SP(pc), 1748480d29a8SRichard Henderson SP(msr), 17491074c0fbSRichard Henderson SP(msr_c), 1750480d29a8SRichard Henderson SP(imm), 1751480d29a8SRichard Henderson SP(iflags), 1752480d29a8SRichard Henderson SP(btaken), 1753480d29a8SRichard Henderson SP(btarget), 1754480d29a8SRichard Henderson SP(res_val), 1755480d29a8SRichard Henderson }; 1756480d29a8SRichard Henderson 1757480d29a8SRichard Henderson #undef R 1758480d29a8SRichard Henderson #undef SP 1759480d29a8SRichard Henderson 1760480d29a8SRichard Henderson for (int i = 0; i < ARRAY_SIZE(i32s); ++i) { 1761480d29a8SRichard Henderson *i32s[i].var = 1762480d29a8SRichard Henderson tcg_global_mem_new_i32(cpu_env, i32s[i].ofs, i32s[i].name); 1763fcf5ef2aSThomas Huth } 176476e8187dSRichard Henderson 1765480d29a8SRichard Henderson cpu_res_addr = 1766480d29a8SRichard Henderson tcg_global_mem_new(cpu_env, offsetof(CPUMBState, res_addr), "res_addr"); 1767fcf5ef2aSThomas Huth } 1768fcf5ef2aSThomas Huth 1769fcf5ef2aSThomas Huth void restore_state_to_opc(CPUMBState *env, TranslationBlock *tb, 1770fcf5ef2aSThomas Huth target_ulong *data) 1771fcf5ef2aSThomas Huth { 177276e8187dSRichard Henderson env->pc = data[0]; 1773fcf5ef2aSThomas Huth } 1774