14acb54baSEdgar E. Iglesias /* 24acb54baSEdgar E. Iglesias * Xilinx MicroBlaze emulation for qemu: main translation routines. 34acb54baSEdgar E. Iglesias * 44acb54baSEdgar E. Iglesias * Copyright (c) 2009 Edgar E. Iglesias. 5dadc1064SPeter A. G. Crosthwaite * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd. 64acb54baSEdgar E. Iglesias * 74acb54baSEdgar E. Iglesias * This library is free software; you can redistribute it and/or 84acb54baSEdgar E. Iglesias * modify it under the terms of the GNU Lesser General Public 94acb54baSEdgar E. Iglesias * License as published by the Free Software Foundation; either 104acb54baSEdgar E. Iglesias * version 2 of the License, or (at your option) any later version. 114acb54baSEdgar E. Iglesias * 124acb54baSEdgar E. Iglesias * This library is distributed in the hope that it will be useful, 134acb54baSEdgar E. Iglesias * but WITHOUT ANY WARRANTY; without even the implied warranty of 144acb54baSEdgar E. Iglesias * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 154acb54baSEdgar E. Iglesias * Lesser General Public License for more details. 164acb54baSEdgar E. Iglesias * 174acb54baSEdgar E. Iglesias * You should have received a copy of the GNU Lesser General Public 188167ee88SBlue Swirl * License along with this library; if not, see <http://www.gnu.org/licenses/>. 194acb54baSEdgar E. Iglesias */ 204acb54baSEdgar E. Iglesias 218fd9deceSPeter Maydell #include "qemu/osdep.h" 224acb54baSEdgar E. Iglesias #include "cpu.h" 2376cad711SPaolo Bonzini #include "disas/disas.h" 2463c91552SPaolo Bonzini #include "exec/exec-all.h" 254acb54baSEdgar E. Iglesias #include "tcg-op.h" 262ef6175aSRichard Henderson #include "exec/helper-proto.h" 274acb54baSEdgar E. Iglesias #include "microblaze-decode.h" 28f08b6170SPaolo Bonzini #include "exec/cpu_ldst.h" 292ef6175aSRichard Henderson #include "exec/helper-gen.h" 3077fc6f5eSLluís Vilanova #include "exec/translator.h" 314acb54baSEdgar E. Iglesias 32a7e30d84SLluís Vilanova #include "trace-tcg.h" 33508127e2SPaolo Bonzini #include "exec/log.h" 34a7e30d84SLluís Vilanova 35a7e30d84SLluís Vilanova 364acb54baSEdgar E. Iglesias #define SIM_COMPAT 0 374acb54baSEdgar E. Iglesias #define DISAS_GNU 1 384acb54baSEdgar E. Iglesias #define DISAS_MB 1 394acb54baSEdgar E. Iglesias #if DISAS_MB && !SIM_COMPAT 404acb54baSEdgar E. Iglesias # define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) 414acb54baSEdgar E. Iglesias #else 424acb54baSEdgar E. Iglesias # define LOG_DIS(...) do { } while (0) 434acb54baSEdgar E. Iglesias #endif 444acb54baSEdgar E. Iglesias 454acb54baSEdgar E. Iglesias #define D(x) 464acb54baSEdgar E. Iglesias 474acb54baSEdgar E. Iglesias #define EXTRACT_FIELD(src, start, end) \ 484acb54baSEdgar E. Iglesias (((src) >> start) & ((1 << (end - start + 1)) - 1)) 494acb54baSEdgar E. Iglesias 5077fc6f5eSLluís Vilanova /* is_jmp field values */ 5177fc6f5eSLluís Vilanova #define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */ 5277fc6f5eSLluís Vilanova #define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */ 5377fc6f5eSLluís Vilanova #define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */ 5477fc6f5eSLluís Vilanova 55*cfeea807SEdgar E. Iglesias static TCGv_i32 env_debug; 56*cfeea807SEdgar E. Iglesias static TCGv_i32 cpu_R[32]; 57*cfeea807SEdgar E. Iglesias static TCGv_i32 cpu_SR[14]; 58*cfeea807SEdgar E. Iglesias static TCGv_i32 env_imm; 59*cfeea807SEdgar E. Iglesias static TCGv_i32 env_btaken; 60*cfeea807SEdgar E. Iglesias static TCGv_i32 env_btarget; 61*cfeea807SEdgar E. Iglesias static TCGv_i32 env_iflags; 62*cfeea807SEdgar E. Iglesias static TCGv_i32 env_res_addr; 63*cfeea807SEdgar E. Iglesias static TCGv_i32 env_res_val; 644acb54baSEdgar E. Iglesias 65022c62cbSPaolo Bonzini #include "exec/gen-icount.h" 664acb54baSEdgar E. Iglesias 674acb54baSEdgar E. Iglesias /* This is the state at translation time. */ 684acb54baSEdgar E. Iglesias typedef struct DisasContext { 690063ebd6SAndreas Färber MicroBlazeCPU *cpu; 70*cfeea807SEdgar E. Iglesias uint32_t pc; 714acb54baSEdgar E. Iglesias 724acb54baSEdgar E. Iglesias /* Decoder. */ 734acb54baSEdgar E. Iglesias int type_b; 744acb54baSEdgar E. Iglesias uint32_t ir; 754acb54baSEdgar E. Iglesias uint8_t opcode; 764acb54baSEdgar E. Iglesias uint8_t rd, ra, rb; 774acb54baSEdgar E. Iglesias uint16_t imm; 784acb54baSEdgar E. Iglesias 794acb54baSEdgar E. Iglesias unsigned int cpustate_changed; 804acb54baSEdgar E. Iglesias unsigned int delayed_branch; 814acb54baSEdgar E. Iglesias unsigned int tb_flags, synced_flags; /* tb dependent flags. */ 824acb54baSEdgar E. Iglesias unsigned int clear_imm; 834acb54baSEdgar E. Iglesias int is_jmp; 844acb54baSEdgar E. Iglesias 854acb54baSEdgar E. Iglesias #define JMP_NOJMP 0 864acb54baSEdgar E. Iglesias #define JMP_DIRECT 1 87844bab60SEdgar E. Iglesias #define JMP_DIRECT_CC 2 88844bab60SEdgar E. Iglesias #define JMP_INDIRECT 3 894acb54baSEdgar E. Iglesias unsigned int jmp; 904acb54baSEdgar E. Iglesias uint32_t jmp_pc; 914acb54baSEdgar E. Iglesias 924acb54baSEdgar E. Iglesias int abort_at_next_insn; 934acb54baSEdgar E. Iglesias int nr_nops; 944acb54baSEdgar E. Iglesias struct TranslationBlock *tb; 954acb54baSEdgar E. Iglesias int singlestep_enabled; 964acb54baSEdgar E. Iglesias } DisasContext; 974acb54baSEdgar E. Iglesias 9838972938SJuan Quintela static const char *regnames[] = 994acb54baSEdgar E. Iglesias { 1004acb54baSEdgar E. Iglesias "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", 1014acb54baSEdgar E. Iglesias "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", 1024acb54baSEdgar E. Iglesias "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", 1034acb54baSEdgar E. Iglesias "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", 1044acb54baSEdgar E. Iglesias }; 1054acb54baSEdgar E. Iglesias 10638972938SJuan Quintela static const char *special_regnames[] = 1074acb54baSEdgar E. Iglesias { 1084acb54baSEdgar E. Iglesias "rpc", "rmsr", "sr2", "sr3", "sr4", "sr5", "sr6", "sr7", 1095c594ef3SEdgar E. Iglesias "sr8", "sr9", "sr10", "sr11", "sr12", "sr13" 1104acb54baSEdgar E. Iglesias }; 1114acb54baSEdgar E. Iglesias 1124acb54baSEdgar E. Iglesias static inline void t_sync_flags(DisasContext *dc) 1134acb54baSEdgar E. Iglesias { 1144abf79a4SDong Xu Wang /* Synch the tb dependent flags between translator and runtime. */ 1154acb54baSEdgar E. Iglesias if (dc->tb_flags != dc->synced_flags) { 116*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_iflags, dc->tb_flags); 1174acb54baSEdgar E. Iglesias dc->synced_flags = dc->tb_flags; 1184acb54baSEdgar E. Iglesias } 1194acb54baSEdgar E. Iglesias } 1204acb54baSEdgar E. Iglesias 1214acb54baSEdgar E. Iglesias static inline void t_gen_raise_exception(DisasContext *dc, uint32_t index) 1224acb54baSEdgar E. Iglesias { 1234acb54baSEdgar E. Iglesias TCGv_i32 tmp = tcg_const_i32(index); 1244acb54baSEdgar E. Iglesias 1254acb54baSEdgar E. Iglesias t_sync_flags(dc); 126*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc); 12764254ebaSBlue Swirl gen_helper_raise_exception(cpu_env, tmp); 1284acb54baSEdgar E. Iglesias tcg_temp_free_i32(tmp); 1294acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_UPDATE; 1304acb54baSEdgar E. Iglesias } 1314acb54baSEdgar E. Iglesias 13290aa39a1SSergey Fedorov static inline bool use_goto_tb(DisasContext *dc, target_ulong dest) 13390aa39a1SSergey Fedorov { 13490aa39a1SSergey Fedorov #ifndef CONFIG_USER_ONLY 13590aa39a1SSergey Fedorov return (dc->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); 13690aa39a1SSergey Fedorov #else 13790aa39a1SSergey Fedorov return true; 13890aa39a1SSergey Fedorov #endif 13990aa39a1SSergey Fedorov } 14090aa39a1SSergey Fedorov 1414acb54baSEdgar E. Iglesias static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) 1424acb54baSEdgar E. Iglesias { 14390aa39a1SSergey Fedorov if (use_goto_tb(dc, dest)) { 1444acb54baSEdgar E. Iglesias tcg_gen_goto_tb(n); 145*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dest); 14690aa39a1SSergey Fedorov tcg_gen_exit_tb((uintptr_t)dc->tb + n); 1474acb54baSEdgar E. Iglesias } else { 148*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dest); 1494acb54baSEdgar E. Iglesias tcg_gen_exit_tb(0); 1504acb54baSEdgar E. Iglesias } 1514acb54baSEdgar E. Iglesias } 1524acb54baSEdgar E. Iglesias 153*cfeea807SEdgar E. Iglesias static void read_carry(DisasContext *dc, TCGv_i32 d) 154ee8b246fSEdgar E. Iglesias { 155*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(d, cpu_SR[SR_MSR], 31); 156ee8b246fSEdgar E. Iglesias } 157ee8b246fSEdgar E. Iglesias 15804ec7df7SEdgar E. Iglesias /* 15904ec7df7SEdgar E. Iglesias * write_carry sets the carry bits in MSR based on bit 0 of v. 16004ec7df7SEdgar E. Iglesias * v[31:1] are ignored. 16104ec7df7SEdgar E. Iglesias */ 162*cfeea807SEdgar E. Iglesias static void write_carry(DisasContext *dc, TCGv_i32 v) 163ee8b246fSEdgar E. Iglesias { 164*cfeea807SEdgar E. Iglesias TCGv_i32 t0 = tcg_temp_new_i32(); 165*cfeea807SEdgar E. Iglesias tcg_gen_shli_i32(t0, v, 31); 166*cfeea807SEdgar E. Iglesias tcg_gen_sari_i32(t0, t0, 31); 167*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_C | MSR_CC)); 168*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(cpu_SR[SR_MSR], cpu_SR[SR_MSR], 169ee8b246fSEdgar E. Iglesias ~(MSR_C | MSR_CC)); 170*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t0); 171*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 172ee8b246fSEdgar E. Iglesias } 173ee8b246fSEdgar E. Iglesias 17465ab5eb4SEdgar E. Iglesias static void write_carryi(DisasContext *dc, bool carry) 1758cc9b43fSPeter A. G. Crosthwaite { 176*cfeea807SEdgar E. Iglesias TCGv_i32 t0 = tcg_temp_new_i32(); 177*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(t0, carry); 1788cc9b43fSPeter A. G. Crosthwaite write_carry(dc, t0); 179*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 1808cc9b43fSPeter A. G. Crosthwaite } 1818cc9b43fSPeter A. G. Crosthwaite 18261204ce8SEdgar E. Iglesias /* True if ALU operand b is a small immediate that may deserve 18361204ce8SEdgar E. Iglesias faster treatment. */ 18461204ce8SEdgar E. Iglesias static inline int dec_alu_op_b_is_small_imm(DisasContext *dc) 18561204ce8SEdgar E. Iglesias { 18661204ce8SEdgar E. Iglesias /* Immediate insn without the imm prefix ? */ 18761204ce8SEdgar E. Iglesias return dc->type_b && !(dc->tb_flags & IMM_FLAG); 18861204ce8SEdgar E. Iglesias } 18961204ce8SEdgar E. Iglesias 190*cfeea807SEdgar E. Iglesias static inline TCGv_i32 *dec_alu_op_b(DisasContext *dc) 1914acb54baSEdgar E. Iglesias { 1924acb54baSEdgar E. Iglesias if (dc->type_b) { 1934acb54baSEdgar E. Iglesias if (dc->tb_flags & IMM_FLAG) 194*cfeea807SEdgar E. Iglesias tcg_gen_ori_i32(env_imm, env_imm, dc->imm); 1954acb54baSEdgar E. Iglesias else 196*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_imm, (int32_t)((int16_t)dc->imm)); 1974acb54baSEdgar E. Iglesias return &env_imm; 1984acb54baSEdgar E. Iglesias } else 1994acb54baSEdgar E. Iglesias return &cpu_R[dc->rb]; 2004acb54baSEdgar E. Iglesias } 2014acb54baSEdgar E. Iglesias 2024acb54baSEdgar E. Iglesias static void dec_add(DisasContext *dc) 2034acb54baSEdgar E. Iglesias { 2044acb54baSEdgar E. Iglesias unsigned int k, c; 205*cfeea807SEdgar E. Iglesias TCGv_i32 cf; 2064acb54baSEdgar E. Iglesias 2074acb54baSEdgar E. Iglesias k = dc->opcode & 4; 2084acb54baSEdgar E. Iglesias c = dc->opcode & 2; 2094acb54baSEdgar E. Iglesias 2104acb54baSEdgar E. Iglesias LOG_DIS("add%s%s%s r%d r%d r%d\n", 2114acb54baSEdgar E. Iglesias dc->type_b ? "i" : "", k ? "k" : "", c ? "c" : "", 2124acb54baSEdgar E. Iglesias dc->rd, dc->ra, dc->rb); 2134acb54baSEdgar E. Iglesias 21440cbf5b7SEdgar E. Iglesias /* Take care of the easy cases first. */ 21540cbf5b7SEdgar E. Iglesias if (k) { 21640cbf5b7SEdgar E. Iglesias /* k - keep carry, no need to update MSR. */ 21740cbf5b7SEdgar E. Iglesias /* If rd == r0, it's a nop. */ 21840cbf5b7SEdgar E. Iglesias if (dc->rd) { 219*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 22040cbf5b7SEdgar E. Iglesias 22140cbf5b7SEdgar E. Iglesias if (c) { 22240cbf5b7SEdgar E. Iglesias /* c - Add carry into the result. */ 223*cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 22440cbf5b7SEdgar E. Iglesias 22540cbf5b7SEdgar E. Iglesias read_carry(dc, cf); 226*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 227*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 2284acb54baSEdgar E. Iglesias } 2294acb54baSEdgar E. Iglesias } 23040cbf5b7SEdgar E. Iglesias return; 23140cbf5b7SEdgar E. Iglesias } 23240cbf5b7SEdgar E. Iglesias 23340cbf5b7SEdgar E. Iglesias /* From now on, we can assume k is zero. So we need to update MSR. */ 23440cbf5b7SEdgar E. Iglesias /* Extract carry. */ 235*cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 23640cbf5b7SEdgar E. Iglesias if (c) { 23740cbf5b7SEdgar E. Iglesias read_carry(dc, cf); 23840cbf5b7SEdgar E. Iglesias } else { 239*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cf, 0); 24040cbf5b7SEdgar E. Iglesias } 24140cbf5b7SEdgar E. Iglesias 24240cbf5b7SEdgar E. Iglesias if (dc->rd) { 243*cfeea807SEdgar E. Iglesias TCGv_i32 ncf = tcg_temp_new_i32(); 2445d0bb823SEdgar E. Iglesias gen_helper_carry(ncf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf); 245*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 246*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 24740cbf5b7SEdgar E. Iglesias write_carry(dc, ncf); 248*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(ncf); 24940cbf5b7SEdgar E. Iglesias } else { 2505d0bb823SEdgar E. Iglesias gen_helper_carry(cf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf); 25140cbf5b7SEdgar E. Iglesias write_carry(dc, cf); 25240cbf5b7SEdgar E. Iglesias } 253*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 25440cbf5b7SEdgar E. Iglesias } 2554acb54baSEdgar E. Iglesias 2564acb54baSEdgar E. Iglesias static void dec_sub(DisasContext *dc) 2574acb54baSEdgar E. Iglesias { 2584acb54baSEdgar E. Iglesias unsigned int u, cmp, k, c; 259*cfeea807SEdgar E. Iglesias TCGv_i32 cf, na; 2604acb54baSEdgar E. Iglesias 2614acb54baSEdgar E. Iglesias u = dc->imm & 2; 2624acb54baSEdgar E. Iglesias k = dc->opcode & 4; 2634acb54baSEdgar E. Iglesias c = dc->opcode & 2; 2644acb54baSEdgar E. Iglesias cmp = (dc->imm & 1) && (!dc->type_b) && k; 2654acb54baSEdgar E. Iglesias 2664acb54baSEdgar E. Iglesias if (cmp) { 2674acb54baSEdgar E. Iglesias LOG_DIS("cmp%s r%d, r%d ir=%x\n", u ? "u" : "", dc->rd, dc->ra, dc->ir); 2684acb54baSEdgar E. Iglesias if (dc->rd) { 2694acb54baSEdgar E. Iglesias if (u) 2704acb54baSEdgar E. Iglesias gen_helper_cmpu(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 2714acb54baSEdgar E. Iglesias else 2724acb54baSEdgar E. Iglesias gen_helper_cmp(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 2734acb54baSEdgar E. Iglesias } 274e0a42ebcSEdgar E. Iglesias return; 275e0a42ebcSEdgar E. Iglesias } 276e0a42ebcSEdgar E. Iglesias 2774acb54baSEdgar E. Iglesias LOG_DIS("sub%s%s r%d, r%d r%d\n", 2784acb54baSEdgar E. Iglesias k ? "k" : "", c ? "c" : "", dc->rd, dc->ra, dc->rb); 2794acb54baSEdgar E. Iglesias 280e0a42ebcSEdgar E. Iglesias /* Take care of the easy cases first. */ 281e0a42ebcSEdgar E. Iglesias if (k) { 282e0a42ebcSEdgar E. Iglesias /* k - keep carry, no need to update MSR. */ 283e0a42ebcSEdgar E. Iglesias /* If rd == r0, it's a nop. */ 284e0a42ebcSEdgar E. Iglesias if (dc->rd) { 285*cfeea807SEdgar E. Iglesias tcg_gen_sub_i32(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]); 286e0a42ebcSEdgar E. Iglesias 287e0a42ebcSEdgar E. Iglesias if (c) { 288e0a42ebcSEdgar E. Iglesias /* c - Add carry into the result. */ 289*cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 290e0a42ebcSEdgar E. Iglesias 291e0a42ebcSEdgar E. Iglesias read_carry(dc, cf); 292*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 293*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 2944acb54baSEdgar E. Iglesias } 2954acb54baSEdgar E. Iglesias } 296e0a42ebcSEdgar E. Iglesias return; 297e0a42ebcSEdgar E. Iglesias } 298e0a42ebcSEdgar E. Iglesias 299e0a42ebcSEdgar E. Iglesias /* From now on, we can assume k is zero. So we need to update MSR. */ 300e0a42ebcSEdgar E. Iglesias /* Extract carry. And complement a into na. */ 301*cfeea807SEdgar E. Iglesias cf = tcg_temp_new_i32(); 302*cfeea807SEdgar E. Iglesias na = tcg_temp_new_i32(); 303e0a42ebcSEdgar E. Iglesias if (c) { 304e0a42ebcSEdgar E. Iglesias read_carry(dc, cf); 305e0a42ebcSEdgar E. Iglesias } else { 306*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cf, 1); 307e0a42ebcSEdgar E. Iglesias } 308e0a42ebcSEdgar E. Iglesias 309e0a42ebcSEdgar E. Iglesias /* d = b + ~a + c. carry defaults to 1. */ 310*cfeea807SEdgar E. Iglesias tcg_gen_not_i32(na, cpu_R[dc->ra]); 311e0a42ebcSEdgar E. Iglesias 312e0a42ebcSEdgar E. Iglesias if (dc->rd) { 313*cfeea807SEdgar E. Iglesias TCGv_i32 ncf = tcg_temp_new_i32(); 3145d0bb823SEdgar E. Iglesias gen_helper_carry(ncf, na, *(dec_alu_op_b(dc)), cf); 315*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], na, *(dec_alu_op_b(dc))); 316*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf); 317e0a42ebcSEdgar E. Iglesias write_carry(dc, ncf); 318*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(ncf); 319e0a42ebcSEdgar E. Iglesias } else { 3205d0bb823SEdgar E. Iglesias gen_helper_carry(cf, na, *(dec_alu_op_b(dc)), cf); 321e0a42ebcSEdgar E. Iglesias write_carry(dc, cf); 322e0a42ebcSEdgar E. Iglesias } 323*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(cf); 324*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(na); 325e0a42ebcSEdgar E. Iglesias } 3264acb54baSEdgar E. Iglesias 3274acb54baSEdgar E. Iglesias static void dec_pattern(DisasContext *dc) 3284acb54baSEdgar E. Iglesias { 3294acb54baSEdgar E. Iglesias unsigned int mode; 3304acb54baSEdgar E. Iglesias 3311567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 3320063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 3338fc5239eSEdgar E. Iglesias && !dc->cpu->cfg.use_pcmp_instr) { 334*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 3351567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 3361567a005SEdgar E. Iglesias } 3371567a005SEdgar E. Iglesias 3384acb54baSEdgar E. Iglesias mode = dc->opcode & 3; 3394acb54baSEdgar E. Iglesias switch (mode) { 3404acb54baSEdgar E. Iglesias case 0: 3414acb54baSEdgar E. Iglesias /* pcmpbf. */ 3424acb54baSEdgar E. Iglesias LOG_DIS("pcmpbf r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 3434acb54baSEdgar E. Iglesias if (dc->rd) 3444acb54baSEdgar E. Iglesias gen_helper_pcmpbf(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 3454acb54baSEdgar E. Iglesias break; 3464acb54baSEdgar E. Iglesias case 2: 3474acb54baSEdgar E. Iglesias LOG_DIS("pcmpeq r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 3484acb54baSEdgar E. Iglesias if (dc->rd) { 349*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_EQ, cpu_R[dc->rd], 35086112805SRichard Henderson cpu_R[dc->ra], cpu_R[dc->rb]); 3514acb54baSEdgar E. Iglesias } 3524acb54baSEdgar E. Iglesias break; 3534acb54baSEdgar E. Iglesias case 3: 3544acb54baSEdgar E. Iglesias LOG_DIS("pcmpne r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 3554acb54baSEdgar E. Iglesias if (dc->rd) { 356*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_NE, cpu_R[dc->rd], 35786112805SRichard Henderson cpu_R[dc->ra], cpu_R[dc->rb]); 3584acb54baSEdgar E. Iglesias } 3594acb54baSEdgar E. Iglesias break; 3604acb54baSEdgar E. Iglesias default: 3610063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), 3624acb54baSEdgar E. Iglesias "unsupported pattern insn opcode=%x\n", dc->opcode); 3634acb54baSEdgar E. Iglesias break; 3644acb54baSEdgar E. Iglesias } 3654acb54baSEdgar E. Iglesias } 3664acb54baSEdgar E. Iglesias 3674acb54baSEdgar E. Iglesias static void dec_and(DisasContext *dc) 3684acb54baSEdgar E. Iglesias { 3694acb54baSEdgar E. Iglesias unsigned int not; 3704acb54baSEdgar E. Iglesias 3714acb54baSEdgar E. Iglesias if (!dc->type_b && (dc->imm & (1 << 10))) { 3724acb54baSEdgar E. Iglesias dec_pattern(dc); 3734acb54baSEdgar E. Iglesias return; 3744acb54baSEdgar E. Iglesias } 3754acb54baSEdgar E. Iglesias 3764acb54baSEdgar E. Iglesias not = dc->opcode & (1 << 1); 3774acb54baSEdgar E. Iglesias LOG_DIS("and%s\n", not ? "n" : ""); 3784acb54baSEdgar E. Iglesias 3794acb54baSEdgar E. Iglesias if (!dc->rd) 3804acb54baSEdgar E. Iglesias return; 3814acb54baSEdgar E. Iglesias 3824acb54baSEdgar E. Iglesias if (not) { 383*cfeea807SEdgar E. Iglesias tcg_gen_andc_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 3844acb54baSEdgar E. Iglesias } else 385*cfeea807SEdgar E. Iglesias tcg_gen_and_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 3864acb54baSEdgar E. Iglesias } 3874acb54baSEdgar E. Iglesias 3884acb54baSEdgar E. Iglesias static void dec_or(DisasContext *dc) 3894acb54baSEdgar E. Iglesias { 3904acb54baSEdgar E. Iglesias if (!dc->type_b && (dc->imm & (1 << 10))) { 3914acb54baSEdgar E. Iglesias dec_pattern(dc); 3924acb54baSEdgar E. Iglesias return; 3934acb54baSEdgar E. Iglesias } 3944acb54baSEdgar E. Iglesias 3954acb54baSEdgar E. Iglesias LOG_DIS("or r%d r%d r%d imm=%x\n", dc->rd, dc->ra, dc->rb, dc->imm); 3964acb54baSEdgar E. Iglesias if (dc->rd) 397*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 3984acb54baSEdgar E. Iglesias } 3994acb54baSEdgar E. Iglesias 4004acb54baSEdgar E. Iglesias static void dec_xor(DisasContext *dc) 4014acb54baSEdgar E. Iglesias { 4024acb54baSEdgar E. Iglesias if (!dc->type_b && (dc->imm & (1 << 10))) { 4034acb54baSEdgar E. Iglesias dec_pattern(dc); 4044acb54baSEdgar E. Iglesias return; 4054acb54baSEdgar E. Iglesias } 4064acb54baSEdgar E. Iglesias 4074acb54baSEdgar E. Iglesias LOG_DIS("xor r%d\n", dc->rd); 4084acb54baSEdgar E. Iglesias if (dc->rd) 409*cfeea807SEdgar E. Iglesias tcg_gen_xor_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 4104acb54baSEdgar E. Iglesias } 4114acb54baSEdgar E. Iglesias 412*cfeea807SEdgar E. Iglesias static inline void msr_read(DisasContext *dc, TCGv_i32 d) 4134acb54baSEdgar E. Iglesias { 414*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(d, cpu_SR[SR_MSR]); 4154acb54baSEdgar E. Iglesias } 4164acb54baSEdgar E. Iglesias 417*cfeea807SEdgar E. Iglesias static inline void msr_write(DisasContext *dc, TCGv_i32 v) 4184acb54baSEdgar E. Iglesias { 419*cfeea807SEdgar E. Iglesias TCGv_i32 t; 42097b833c5SEdgar E. Iglesias 421*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 4224acb54baSEdgar E. Iglesias dc->cpustate_changed = 1; 42397b833c5SEdgar E. Iglesias /* PVR bit is not writable. */ 424*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t, v, ~MSR_PVR); 425*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR); 426*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t); 42797b833c5SEdgar E. Iglesias tcg_temp_free(t); 4284acb54baSEdgar E. Iglesias } 4294acb54baSEdgar E. Iglesias 4304acb54baSEdgar E. Iglesias static void dec_msr(DisasContext *dc) 4314acb54baSEdgar E. Iglesias { 4320063ebd6SAndreas Färber CPUState *cs = CPU(dc->cpu); 433*cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 4344acb54baSEdgar E. Iglesias unsigned int sr, to, rn; 43597ed5ccdSBenjamin Herrenschmidt int mem_index = cpu_mmu_index(&dc->cpu->env, false); 4364acb54baSEdgar E. Iglesias 4374acb54baSEdgar E. Iglesias sr = dc->imm & ((1 << 14) - 1); 4384acb54baSEdgar E. Iglesias to = dc->imm & (1 << 14); 4394acb54baSEdgar E. Iglesias dc->type_b = 1; 4404acb54baSEdgar E. Iglesias if (to) 4414acb54baSEdgar E. Iglesias dc->cpustate_changed = 1; 4424acb54baSEdgar E. Iglesias 4434acb54baSEdgar E. Iglesias /* msrclr and msrset. */ 4444acb54baSEdgar E. Iglesias if (!(dc->imm & (1 << 15))) { 4454acb54baSEdgar E. Iglesias unsigned int clr = dc->ir & (1 << 16); 4464acb54baSEdgar E. Iglesias 4474acb54baSEdgar E. Iglesias LOG_DIS("msr%s r%d imm=%x\n", clr ? "clr" : "set", 4484acb54baSEdgar E. Iglesias dc->rd, dc->imm); 4491567a005SEdgar E. Iglesias 45056837509SEdgar E. Iglesias if (!dc->cpu->cfg.use_msr_instr) { 4511567a005SEdgar E. Iglesias /* nop??? */ 4521567a005SEdgar E. Iglesias return; 4531567a005SEdgar E. Iglesias } 4541567a005SEdgar E. Iglesias 4551567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 4561567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX && (dc->imm != 4 && dc->imm != 0)) { 457*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 4581567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 4591567a005SEdgar E. Iglesias return; 4601567a005SEdgar E. Iglesias } 4611567a005SEdgar E. Iglesias 4624acb54baSEdgar E. Iglesias if (dc->rd) 4634acb54baSEdgar E. Iglesias msr_read(dc, cpu_R[dc->rd]); 4644acb54baSEdgar E. Iglesias 465*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 466*cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 4674acb54baSEdgar E. Iglesias msr_read(dc, t0); 468*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t1, *(dec_alu_op_b(dc))); 4694acb54baSEdgar E. Iglesias 4704acb54baSEdgar E. Iglesias if (clr) { 471*cfeea807SEdgar E. Iglesias tcg_gen_not_i32(t1, t1); 472*cfeea807SEdgar E. Iglesias tcg_gen_and_i32(t0, t0, t1); 4734acb54baSEdgar E. Iglesias } else 474*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t0, t0, t1); 4754acb54baSEdgar E. Iglesias msr_write(dc, t0); 476*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 477*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 478*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc + 4); 4794acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_UPDATE; 4804acb54baSEdgar E. Iglesias return; 4814acb54baSEdgar E. Iglesias } 4824acb54baSEdgar E. Iglesias 4831567a005SEdgar E. Iglesias if (to) { 4841567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 4851567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 486*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 4871567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 4881567a005SEdgar E. Iglesias return; 4891567a005SEdgar E. Iglesias } 4901567a005SEdgar E. Iglesias } 4911567a005SEdgar E. Iglesias 4924acb54baSEdgar E. Iglesias #if !defined(CONFIG_USER_ONLY) 4934acb54baSEdgar E. Iglesias /* Catch read/writes to the mmu block. */ 4944acb54baSEdgar E. Iglesias if ((sr & ~0xff) == 0x1000) { 4954acb54baSEdgar E. Iglesias sr &= 7; 4964acb54baSEdgar E. Iglesias LOG_DIS("m%ss sr%d r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm); 4974acb54baSEdgar E. Iglesias if (to) 498*cfeea807SEdgar E. Iglesias gen_helper_mmu_write(cpu_env, tcg_const_i32(sr), cpu_R[dc->ra]); 4994acb54baSEdgar E. Iglesias else 500*cfeea807SEdgar E. Iglesias gen_helper_mmu_read(cpu_R[dc->rd], cpu_env, tcg_const_i32(sr)); 5014acb54baSEdgar E. Iglesias return; 5024acb54baSEdgar E. Iglesias } 5034acb54baSEdgar E. Iglesias #endif 5044acb54baSEdgar E. Iglesias 5054acb54baSEdgar E. Iglesias if (to) { 5064acb54baSEdgar E. Iglesias LOG_DIS("m%ss sr%x r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm); 5074acb54baSEdgar E. Iglesias switch (sr) { 5084acb54baSEdgar E. Iglesias case 0: 5094acb54baSEdgar E. Iglesias break; 5104acb54baSEdgar E. Iglesias case 1: 5114acb54baSEdgar E. Iglesias msr_write(dc, cpu_R[dc->ra]); 5124acb54baSEdgar E. Iglesias break; 5134acb54baSEdgar E. Iglesias case 0x3: 514*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_SR[SR_EAR], cpu_R[dc->ra]); 5154acb54baSEdgar E. Iglesias break; 5164acb54baSEdgar E. Iglesias case 0x5: 517*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_SR[SR_ESR], cpu_R[dc->ra]); 5184acb54baSEdgar E. Iglesias break; 5194acb54baSEdgar E. Iglesias case 0x7: 520*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(cpu_SR[SR_FSR], cpu_R[dc->ra], 31); 5214acb54baSEdgar E. Iglesias break; 5225818dee5SEdgar E. Iglesias case 0x800: 523*cfeea807SEdgar E. Iglesias tcg_gen_st_i32(cpu_R[dc->ra], 524*cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, slr)); 5255818dee5SEdgar E. Iglesias break; 5265818dee5SEdgar E. Iglesias case 0x802: 527*cfeea807SEdgar E. Iglesias tcg_gen_st_i32(cpu_R[dc->ra], 528*cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, shr)); 5295818dee5SEdgar E. Iglesias break; 5304acb54baSEdgar E. Iglesias default: 5310063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "unknown mts reg %x\n", sr); 5324acb54baSEdgar E. Iglesias break; 5334acb54baSEdgar E. Iglesias } 5344acb54baSEdgar E. Iglesias } else { 5354acb54baSEdgar E. Iglesias LOG_DIS("m%ss r%d sr%x imm=%x\n", to ? "t" : "f", dc->rd, sr, dc->imm); 5364acb54baSEdgar E. Iglesias 5374acb54baSEdgar E. Iglesias switch (sr) { 5384acb54baSEdgar E. Iglesias case 0: 539*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[dc->rd], dc->pc); 5404acb54baSEdgar E. Iglesias break; 5414acb54baSEdgar E. Iglesias case 1: 5424acb54baSEdgar E. Iglesias msr_read(dc, cpu_R[dc->rd]); 5434acb54baSEdgar E. Iglesias break; 5444acb54baSEdgar E. Iglesias case 0x3: 545*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], cpu_SR[SR_EAR]); 5464acb54baSEdgar E. Iglesias break; 5474acb54baSEdgar E. Iglesias case 0x5: 548*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], cpu_SR[SR_ESR]); 5494acb54baSEdgar E. Iglesias break; 5504acb54baSEdgar E. Iglesias case 0x7: 551*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], cpu_SR[SR_FSR]); 5524acb54baSEdgar E. Iglesias break; 5534acb54baSEdgar E. Iglesias case 0xb: 554*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], cpu_SR[SR_BTR]); 5554acb54baSEdgar E. Iglesias break; 5565818dee5SEdgar E. Iglesias case 0x800: 557*cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 558*cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, slr)); 5595818dee5SEdgar E. Iglesias break; 5605818dee5SEdgar E. Iglesias case 0x802: 561*cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 562*cfeea807SEdgar E. Iglesias cpu_env, offsetof(CPUMBState, shr)); 5635818dee5SEdgar E. Iglesias break; 5644acb54baSEdgar E. Iglesias case 0x2000: 5654acb54baSEdgar E. Iglesias case 0x2001: 5664acb54baSEdgar E. Iglesias case 0x2002: 5674acb54baSEdgar E. Iglesias case 0x2003: 5684acb54baSEdgar E. Iglesias case 0x2004: 5694acb54baSEdgar E. Iglesias case 0x2005: 5704acb54baSEdgar E. Iglesias case 0x2006: 5714acb54baSEdgar E. Iglesias case 0x2007: 5724acb54baSEdgar E. Iglesias case 0x2008: 5734acb54baSEdgar E. Iglesias case 0x2009: 5744acb54baSEdgar E. Iglesias case 0x200a: 5754acb54baSEdgar E. Iglesias case 0x200b: 5764acb54baSEdgar E. Iglesias case 0x200c: 5774acb54baSEdgar E. Iglesias rn = sr & 0xf; 578*cfeea807SEdgar E. Iglesias tcg_gen_ld_i32(cpu_R[dc->rd], 57968cee38aSAndreas Färber cpu_env, offsetof(CPUMBState, pvr.regs[rn])); 5804acb54baSEdgar E. Iglesias break; 5814acb54baSEdgar E. Iglesias default: 582a47dddd7SAndreas Färber cpu_abort(cs, "unknown mfs reg %x\n", sr); 5834acb54baSEdgar E. Iglesias break; 5844acb54baSEdgar E. Iglesias } 5854acb54baSEdgar E. Iglesias } 586ee7dbcf8SEdgar E. Iglesias 587ee7dbcf8SEdgar E. Iglesias if (dc->rd == 0) { 588*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[0], 0); 589ee7dbcf8SEdgar E. Iglesias } 5904acb54baSEdgar E. Iglesias } 5914acb54baSEdgar E. Iglesias 5924acb54baSEdgar E. Iglesias /* Multiplier unit. */ 5934acb54baSEdgar E. Iglesias static void dec_mul(DisasContext *dc) 5944acb54baSEdgar E. Iglesias { 595*cfeea807SEdgar E. Iglesias TCGv_i32 tmp; 5964acb54baSEdgar E. Iglesias unsigned int subcode; 5974acb54baSEdgar E. Iglesias 5981567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 5990063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 6009b964318SEdgar E. Iglesias && !dc->cpu->cfg.use_hw_mul) { 601*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 6021567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 6031567a005SEdgar E. Iglesias return; 6041567a005SEdgar E. Iglesias } 6051567a005SEdgar E. Iglesias 6064acb54baSEdgar E. Iglesias subcode = dc->imm & 3; 6074acb54baSEdgar E. Iglesias 6084acb54baSEdgar E. Iglesias if (dc->type_b) { 6094acb54baSEdgar E. Iglesias LOG_DIS("muli r%d r%d %x\n", dc->rd, dc->ra, dc->imm); 610*cfeea807SEdgar E. Iglesias tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc))); 61116ece88dSRichard Henderson return; 6124acb54baSEdgar E. Iglesias } 6134acb54baSEdgar E. Iglesias 6141567a005SEdgar E. Iglesias /* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */ 6159b964318SEdgar E. Iglesias if (subcode >= 1 && subcode <= 3 && dc->cpu->cfg.use_hw_mul < 2) { 6161567a005SEdgar E. Iglesias /* nop??? */ 6171567a005SEdgar E. Iglesias } 6181567a005SEdgar E. Iglesias 619*cfeea807SEdgar E. Iglesias tmp = tcg_temp_new_i32(); 6204acb54baSEdgar E. Iglesias switch (subcode) { 6214acb54baSEdgar E. Iglesias case 0: 6224acb54baSEdgar E. Iglesias LOG_DIS("mul r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 623*cfeea807SEdgar E. Iglesias tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 6244acb54baSEdgar E. Iglesias break; 6254acb54baSEdgar E. Iglesias case 1: 6264acb54baSEdgar E. Iglesias LOG_DIS("mulh r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 627*cfeea807SEdgar E. Iglesias tcg_gen_muls2_i32(tmp, cpu_R[dc->rd], 628*cfeea807SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 6294acb54baSEdgar E. Iglesias break; 6304acb54baSEdgar E. Iglesias case 2: 6314acb54baSEdgar E. Iglesias LOG_DIS("mulhsu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 632*cfeea807SEdgar E. Iglesias tcg_gen_mulsu2_i32(tmp, cpu_R[dc->rd], 633*cfeea807SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 6344acb54baSEdgar E. Iglesias break; 6354acb54baSEdgar E. Iglesias case 3: 6364acb54baSEdgar E. Iglesias LOG_DIS("mulhu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb); 637*cfeea807SEdgar E. Iglesias tcg_gen_mulu2_i32(tmp, cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]); 6384acb54baSEdgar E. Iglesias break; 6394acb54baSEdgar E. Iglesias default: 6400063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "unknown MUL insn %x\n", subcode); 6414acb54baSEdgar E. Iglesias break; 6424acb54baSEdgar E. Iglesias } 643*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(tmp); 6444acb54baSEdgar E. Iglesias } 6454acb54baSEdgar E. Iglesias 6464acb54baSEdgar E. Iglesias /* Div unit. */ 6474acb54baSEdgar E. Iglesias static void dec_div(DisasContext *dc) 6484acb54baSEdgar E. Iglesias { 6494acb54baSEdgar E. Iglesias unsigned int u; 6504acb54baSEdgar E. Iglesias 6514acb54baSEdgar E. Iglesias u = dc->imm & 2; 6524acb54baSEdgar E. Iglesias LOG_DIS("div\n"); 6534acb54baSEdgar E. Iglesias 6540063ebd6SAndreas Färber if ((dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 65547709e4cSEdgar E. Iglesias && !dc->cpu->cfg.use_div) { 656*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 6571567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 6581567a005SEdgar E. Iglesias } 6591567a005SEdgar E. Iglesias 6604acb54baSEdgar E. Iglesias if (u) 66164254ebaSBlue Swirl gen_helper_divu(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)), 66264254ebaSBlue Swirl cpu_R[dc->ra]); 6634acb54baSEdgar E. Iglesias else 66464254ebaSBlue Swirl gen_helper_divs(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)), 66564254ebaSBlue Swirl cpu_R[dc->ra]); 6664acb54baSEdgar E. Iglesias if (!dc->rd) 667*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[dc->rd], 0); 6684acb54baSEdgar E. Iglesias } 6694acb54baSEdgar E. Iglesias 6704acb54baSEdgar E. Iglesias static void dec_barrel(DisasContext *dc) 6714acb54baSEdgar E. Iglesias { 672*cfeea807SEdgar E. Iglesias TCGv_i32 t0; 673faa48d74SEdgar E. Iglesias unsigned int imm_w, imm_s; 674d09b2585SEdgar E. Iglesias bool s, t, e = false, i = false; 6754acb54baSEdgar E. Iglesias 6761567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 6770063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 6787faa66aaSEdgar E. Iglesias && !dc->cpu->cfg.use_barrel) { 679*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 6801567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 6811567a005SEdgar E. Iglesias return; 6821567a005SEdgar E. Iglesias } 6831567a005SEdgar E. Iglesias 684faa48d74SEdgar E. Iglesias if (dc->type_b) { 685faa48d74SEdgar E. Iglesias /* Insert and extract are only available in immediate mode. */ 686d09b2585SEdgar E. Iglesias i = extract32(dc->imm, 15, 1); 687faa48d74SEdgar E. Iglesias e = extract32(dc->imm, 14, 1); 688faa48d74SEdgar E. Iglesias } 689e3e84983SEdgar E. Iglesias s = extract32(dc->imm, 10, 1); 690e3e84983SEdgar E. Iglesias t = extract32(dc->imm, 9, 1); 691faa48d74SEdgar E. Iglesias imm_w = extract32(dc->imm, 6, 5); 692faa48d74SEdgar E. Iglesias imm_s = extract32(dc->imm, 0, 5); 6934acb54baSEdgar E. Iglesias 694faa48d74SEdgar E. Iglesias LOG_DIS("bs%s%s%s r%d r%d r%d\n", 695faa48d74SEdgar E. Iglesias e ? "e" : "", 6964acb54baSEdgar E. Iglesias s ? "l" : "r", t ? "a" : "l", dc->rd, dc->ra, dc->rb); 6974acb54baSEdgar E. Iglesias 698faa48d74SEdgar E. Iglesias if (e) { 699faa48d74SEdgar E. Iglesias if (imm_w + imm_s > 32 || imm_w == 0) { 700faa48d74SEdgar E. Iglesias /* These inputs have an undefined behavior. */ 701faa48d74SEdgar E. Iglesias qemu_log_mask(LOG_GUEST_ERROR, "bsefi: Bad input w=%d s=%d\n", 702faa48d74SEdgar E. Iglesias imm_w, imm_s); 703faa48d74SEdgar E. Iglesias } else { 704faa48d74SEdgar E. Iglesias tcg_gen_extract_i32(cpu_R[dc->rd], cpu_R[dc->ra], imm_s, imm_w); 705faa48d74SEdgar E. Iglesias } 706d09b2585SEdgar E. Iglesias } else if (i) { 707d09b2585SEdgar E. Iglesias int width = imm_w - imm_s + 1; 708d09b2585SEdgar E. Iglesias 709d09b2585SEdgar E. Iglesias if (imm_w < imm_s) { 710d09b2585SEdgar E. Iglesias /* These inputs have an undefined behavior. */ 711d09b2585SEdgar E. Iglesias qemu_log_mask(LOG_GUEST_ERROR, "bsifi: Bad input w=%d s=%d\n", 712d09b2585SEdgar E. Iglesias imm_w, imm_s); 713d09b2585SEdgar E. Iglesias } else { 714d09b2585SEdgar E. Iglesias tcg_gen_deposit_i32(cpu_R[dc->rd], cpu_R[dc->rd], cpu_R[dc->ra], 715d09b2585SEdgar E. Iglesias imm_s, width); 716d09b2585SEdgar E. Iglesias } 717faa48d74SEdgar E. Iglesias } else { 718*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 7194acb54baSEdgar E. Iglesias 720*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t0, *(dec_alu_op_b(dc))); 721*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, 31); 7224acb54baSEdgar E. Iglesias 7232acf6d53SEdgar E. Iglesias if (s) { 724*cfeea807SEdgar E. Iglesias tcg_gen_shl_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 7252acf6d53SEdgar E. Iglesias } else { 7262acf6d53SEdgar E. Iglesias if (t) { 727*cfeea807SEdgar E. Iglesias tcg_gen_sar_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 7282acf6d53SEdgar E. Iglesias } else { 729*cfeea807SEdgar E. Iglesias tcg_gen_shr_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0); 7304acb54baSEdgar E. Iglesias } 7314acb54baSEdgar E. Iglesias } 732*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 7332acf6d53SEdgar E. Iglesias } 734faa48d74SEdgar E. Iglesias } 7354acb54baSEdgar E. Iglesias 7364acb54baSEdgar E. Iglesias static void dec_bit(DisasContext *dc) 7374acb54baSEdgar E. Iglesias { 7380063ebd6SAndreas Färber CPUState *cs = CPU(dc->cpu); 739*cfeea807SEdgar E. Iglesias TCGv_i32 t0; 7404acb54baSEdgar E. Iglesias unsigned int op; 74197ed5ccdSBenjamin Herrenschmidt int mem_index = cpu_mmu_index(&dc->cpu->env, false); 7424acb54baSEdgar E. Iglesias 743ace2e4daSPeter A. G. Crosthwaite op = dc->ir & ((1 << 9) - 1); 7444acb54baSEdgar E. Iglesias switch (op) { 7454acb54baSEdgar E. Iglesias case 0x21: 7464acb54baSEdgar E. Iglesias /* src. */ 747*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 7484acb54baSEdgar E. Iglesias 7494acb54baSEdgar E. Iglesias LOG_DIS("src r%d r%d\n", dc->rd, dc->ra); 750*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, cpu_SR[SR_MSR], MSR_CC); 75109b9f113SEdgar E. Iglesias write_carry(dc, cpu_R[dc->ra]); 7524acb54baSEdgar E. Iglesias if (dc->rd) { 753*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 754*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->rd], t0); 7554acb54baSEdgar E. Iglesias } 756*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 7574acb54baSEdgar E. Iglesias break; 7584acb54baSEdgar E. Iglesias 7594acb54baSEdgar E. Iglesias case 0x1: 7604acb54baSEdgar E. Iglesias case 0x41: 7614acb54baSEdgar E. Iglesias /* srl. */ 7624acb54baSEdgar E. Iglesias LOG_DIS("srl r%d r%d\n", dc->rd, dc->ra); 7634acb54baSEdgar E. Iglesias 764bb3cb951SEdgar E. Iglesias /* Update carry. Note that write carry only looks at the LSB. */ 765bb3cb951SEdgar E. Iglesias write_carry(dc, cpu_R[dc->ra]); 7664acb54baSEdgar E. Iglesias if (dc->rd) { 7674acb54baSEdgar E. Iglesias if (op == 0x41) 768*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 7694acb54baSEdgar E. Iglesias else 770*cfeea807SEdgar E. Iglesias tcg_gen_sari_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1); 7714acb54baSEdgar E. Iglesias } 7724acb54baSEdgar E. Iglesias break; 7734acb54baSEdgar E. Iglesias case 0x60: 7744acb54baSEdgar E. Iglesias LOG_DIS("ext8s r%d r%d\n", dc->rd, dc->ra); 7754acb54baSEdgar E. Iglesias tcg_gen_ext8s_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 7764acb54baSEdgar E. Iglesias break; 7774acb54baSEdgar E. Iglesias case 0x61: 7784acb54baSEdgar E. Iglesias LOG_DIS("ext16s r%d r%d\n", dc->rd, dc->ra); 7794acb54baSEdgar E. Iglesias tcg_gen_ext16s_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 7804acb54baSEdgar E. Iglesias break; 7814acb54baSEdgar E. Iglesias case 0x64: 782f062a3c7SEdgar E. Iglesias case 0x66: 783f062a3c7SEdgar E. Iglesias case 0x74: 784f062a3c7SEdgar E. Iglesias case 0x76: 7854acb54baSEdgar E. Iglesias /* wdc. */ 7864acb54baSEdgar E. Iglesias LOG_DIS("wdc r%d\n", dc->ra); 7871567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 7881567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 789*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 7901567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 7911567a005SEdgar E. Iglesias return; 7921567a005SEdgar E. Iglesias } 7934acb54baSEdgar E. Iglesias break; 7944acb54baSEdgar E. Iglesias case 0x68: 7954acb54baSEdgar E. Iglesias /* wic. */ 7964acb54baSEdgar E. Iglesias LOG_DIS("wic r%d\n", dc->ra); 7971567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 7981567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 799*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 8001567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 8011567a005SEdgar E. Iglesias return; 8021567a005SEdgar E. Iglesias } 8034acb54baSEdgar E. Iglesias break; 80448b5e96fSEdgar E. Iglesias case 0xe0: 80548b5e96fSEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 8060063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 8078fc5239eSEdgar E. Iglesias && !dc->cpu->cfg.use_pcmp_instr) { 808*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 80948b5e96fSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 81048b5e96fSEdgar E. Iglesias } 8118fc5239eSEdgar E. Iglesias if (dc->cpu->cfg.use_pcmp_instr) { 8125318420cSRichard Henderson tcg_gen_clzi_i32(cpu_R[dc->rd], cpu_R[dc->ra], 32); 81348b5e96fSEdgar E. Iglesias } 81448b5e96fSEdgar E. Iglesias break; 815ace2e4daSPeter A. G. Crosthwaite case 0x1e0: 816ace2e4daSPeter A. G. Crosthwaite /* swapb */ 817ace2e4daSPeter A. G. Crosthwaite LOG_DIS("swapb r%d r%d\n", dc->rd, dc->ra); 818ace2e4daSPeter A. G. Crosthwaite tcg_gen_bswap32_i32(cpu_R[dc->rd], cpu_R[dc->ra]); 819ace2e4daSPeter A. G. Crosthwaite break; 820b8c6a5d9SPeter Crosthwaite case 0x1e2: 821ace2e4daSPeter A. G. Crosthwaite /*swaph */ 822ace2e4daSPeter A. G. Crosthwaite LOG_DIS("swaph r%d r%d\n", dc->rd, dc->ra); 823ace2e4daSPeter A. G. Crosthwaite tcg_gen_rotri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 16); 824ace2e4daSPeter A. G. Crosthwaite break; 8254acb54baSEdgar E. Iglesias default: 826a47dddd7SAndreas Färber cpu_abort(cs, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n", 8274acb54baSEdgar E. Iglesias dc->pc, op, dc->rd, dc->ra, dc->rb); 8284acb54baSEdgar E. Iglesias break; 8294acb54baSEdgar E. Iglesias } 8304acb54baSEdgar E. Iglesias } 8314acb54baSEdgar E. Iglesias 8324acb54baSEdgar E. Iglesias static inline void sync_jmpstate(DisasContext *dc) 8334acb54baSEdgar E. Iglesias { 834844bab60SEdgar E. Iglesias if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) { 8354acb54baSEdgar E. Iglesias if (dc->jmp == JMP_DIRECT) { 836*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btaken, 1); 837844bab60SEdgar E. Iglesias } 8384acb54baSEdgar E. Iglesias dc->jmp = JMP_INDIRECT; 839*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btarget, dc->jmp_pc); 8404acb54baSEdgar E. Iglesias } 8414acb54baSEdgar E. Iglesias } 8424acb54baSEdgar E. Iglesias 8434acb54baSEdgar E. Iglesias static void dec_imm(DisasContext *dc) 8444acb54baSEdgar E. Iglesias { 8454acb54baSEdgar E. Iglesias LOG_DIS("imm %x\n", dc->imm << 16); 846*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_imm, (dc->imm << 16)); 8474acb54baSEdgar E. Iglesias dc->tb_flags |= IMM_FLAG; 8484acb54baSEdgar E. Iglesias dc->clear_imm = 0; 8494acb54baSEdgar E. Iglesias } 8504acb54baSEdgar E. Iglesias 851*cfeea807SEdgar E. Iglesias static inline TCGv_i32 *compute_ldst_addr(DisasContext *dc, TCGv_i32 *t) 8524acb54baSEdgar E. Iglesias { 8530e9033c8SEdgar E. Iglesias bool extimm = dc->tb_flags & IMM_FLAG; 8540e9033c8SEdgar E. Iglesias /* Should be set to true if r1 is used by loadstores. */ 8550e9033c8SEdgar E. Iglesias bool stackprot = false; 8565818dee5SEdgar E. Iglesias 8575818dee5SEdgar E. Iglesias /* All load/stores use ra. */ 8589aaaa181SAlistair Francis if (dc->ra == 1 && dc->cpu->cfg.stackprot) { 8590e9033c8SEdgar E. Iglesias stackprot = true; 8605818dee5SEdgar E. Iglesias } 8614acb54baSEdgar E. Iglesias 8629ef55357SEdgar E. Iglesias /* Treat the common cases first. */ 8634acb54baSEdgar E. Iglesias if (!dc->type_b) { 8644b5ef0b5SEdgar E. Iglesias /* If any of the regs is r0, return a ptr to the other. */ 8654b5ef0b5SEdgar E. Iglesias if (dc->ra == 0) { 8664b5ef0b5SEdgar E. Iglesias return &cpu_R[dc->rb]; 8674b5ef0b5SEdgar E. Iglesias } else if (dc->rb == 0) { 8684b5ef0b5SEdgar E. Iglesias return &cpu_R[dc->ra]; 8694b5ef0b5SEdgar E. Iglesias } 8704b5ef0b5SEdgar E. Iglesias 8719aaaa181SAlistair Francis if (dc->rb == 1 && dc->cpu->cfg.stackprot) { 8720e9033c8SEdgar E. Iglesias stackprot = true; 8735818dee5SEdgar E. Iglesias } 8745818dee5SEdgar E. Iglesias 875*cfeea807SEdgar E. Iglesias *t = tcg_temp_new_i32(); 876*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(*t, cpu_R[dc->ra], cpu_R[dc->rb]); 8775818dee5SEdgar E. Iglesias 8785818dee5SEdgar E. Iglesias if (stackprot) { 87964254ebaSBlue Swirl gen_helper_stackprot(cpu_env, *t); 8805818dee5SEdgar E. Iglesias } 8814acb54baSEdgar E. Iglesias return t; 8824acb54baSEdgar E. Iglesias } 8834acb54baSEdgar E. Iglesias /* Immediate. */ 8844acb54baSEdgar E. Iglesias if (!extimm) { 8854acb54baSEdgar E. Iglesias if (dc->imm == 0) { 8864acb54baSEdgar E. Iglesias return &cpu_R[dc->ra]; 8874acb54baSEdgar E. Iglesias } 888*cfeea807SEdgar E. Iglesias *t = tcg_temp_new_i32(); 889*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(*t, (int32_t)((int16_t)dc->imm)); 890*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(*t, cpu_R[dc->ra], *t); 8914acb54baSEdgar E. Iglesias } else { 892*cfeea807SEdgar E. Iglesias *t = tcg_temp_new_i32(); 893*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(*t, cpu_R[dc->ra], *(dec_alu_op_b(dc))); 8944acb54baSEdgar E. Iglesias } 8954acb54baSEdgar E. Iglesias 8965818dee5SEdgar E. Iglesias if (stackprot) { 89764254ebaSBlue Swirl gen_helper_stackprot(cpu_env, *t); 8985818dee5SEdgar E. Iglesias } 8994acb54baSEdgar E. Iglesias return t; 9004acb54baSEdgar E. Iglesias } 9014acb54baSEdgar E. Iglesias 9024acb54baSEdgar E. Iglesias static void dec_load(DisasContext *dc) 9034acb54baSEdgar E. Iglesias { 904*cfeea807SEdgar E. Iglesias TCGv_i32 t, v, *addr; 9058534063aSEdgar E. Iglesias unsigned int size; 9068534063aSEdgar E. Iglesias bool rev = false, ex = false; 90747acdd63SRichard Henderson TCGMemOp mop; 9084acb54baSEdgar E. Iglesias 90947acdd63SRichard Henderson mop = dc->opcode & 3; 91047acdd63SRichard Henderson size = 1 << mop; 9119f8beb66SEdgar E. Iglesias if (!dc->type_b) { 9128534063aSEdgar E. Iglesias rev = extract32(dc->ir, 9, 1); 9138534063aSEdgar E. Iglesias ex = extract32(dc->ir, 10, 1); 9149f8beb66SEdgar E. Iglesias } 91547acdd63SRichard Henderson mop |= MO_TE; 91647acdd63SRichard Henderson if (rev) { 91747acdd63SRichard Henderson mop ^= MO_BSWAP; 91847acdd63SRichard Henderson } 9199f8beb66SEdgar E. Iglesias 9200187688fSEdgar E. Iglesias if (size > 4 && (dc->tb_flags & MSR_EE_FLAG) 9210063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) { 922*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 9230187688fSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 9240187688fSEdgar E. Iglesias return; 9250187688fSEdgar E. Iglesias } 9264acb54baSEdgar E. Iglesias 9278cc9b43fSPeter A. G. Crosthwaite LOG_DIS("l%d%s%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "", 9288cc9b43fSPeter A. G. Crosthwaite ex ? "x" : ""); 9299f8beb66SEdgar E. Iglesias 9304acb54baSEdgar E. Iglesias t_sync_flags(dc); 9314acb54baSEdgar E. Iglesias addr = compute_ldst_addr(dc, &t); 9324acb54baSEdgar E. Iglesias 9339f8beb66SEdgar E. Iglesias /* 9349f8beb66SEdgar E. Iglesias * When doing reverse accesses we need to do two things. 9359f8beb66SEdgar E. Iglesias * 9364ff9786cSStefan Weil * 1. Reverse the address wrt endianness. 9379f8beb66SEdgar E. Iglesias * 2. Byteswap the data lanes on the way back into the CPU core. 9389f8beb66SEdgar E. Iglesias */ 9399f8beb66SEdgar E. Iglesias if (rev && size != 4) { 9409f8beb66SEdgar E. Iglesias /* Endian reverse the address. t is addr. */ 9419f8beb66SEdgar E. Iglesias switch (size) { 9429f8beb66SEdgar E. Iglesias case 1: 9439f8beb66SEdgar E. Iglesias { 9449f8beb66SEdgar E. Iglesias /* 00 -> 11 9459f8beb66SEdgar E. Iglesias 01 -> 10 9469f8beb66SEdgar E. Iglesias 10 -> 10 9479f8beb66SEdgar E. Iglesias 11 -> 00 */ 948*cfeea807SEdgar E. Iglesias TCGv_i32 low = tcg_temp_new_i32(); 9499f8beb66SEdgar E. Iglesias 9509f8beb66SEdgar E. Iglesias /* Force addr into the temp. */ 9519f8beb66SEdgar E. Iglesias if (addr != &t) { 952*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 953*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t, *addr); 9549f8beb66SEdgar E. Iglesias addr = &t; 9559f8beb66SEdgar E. Iglesias } 9569f8beb66SEdgar E. Iglesias 957*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(low, t, 3); 958*cfeea807SEdgar E. Iglesias tcg_gen_sub_i32(low, tcg_const_i32(3), low); 959*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t, t, ~3); 960*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t, t, low); 961*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(low); 9629f8beb66SEdgar E. Iglesias break; 9639f8beb66SEdgar E. Iglesias } 9649f8beb66SEdgar E. Iglesias 9659f8beb66SEdgar E. Iglesias case 2: 9669f8beb66SEdgar E. Iglesias /* 00 -> 10 9679f8beb66SEdgar E. Iglesias 10 -> 00. */ 9689f8beb66SEdgar E. Iglesias /* Force addr into the temp. */ 9699f8beb66SEdgar E. Iglesias if (addr != &t) { 970*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 971*cfeea807SEdgar E. Iglesias tcg_gen_xori_i32(t, *addr, 2); 9729f8beb66SEdgar E. Iglesias addr = &t; 9739f8beb66SEdgar E. Iglesias } else { 974*cfeea807SEdgar E. Iglesias tcg_gen_xori_i32(t, t, 2); 9759f8beb66SEdgar E. Iglesias } 9769f8beb66SEdgar E. Iglesias break; 9779f8beb66SEdgar E. Iglesias default: 9780063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "Invalid reverse size\n"); 9799f8beb66SEdgar E. Iglesias break; 9809f8beb66SEdgar E. Iglesias } 9819f8beb66SEdgar E. Iglesias } 9829f8beb66SEdgar E. Iglesias 9838cc9b43fSPeter A. G. Crosthwaite /* lwx does not throw unaligned access errors, so force alignment */ 9848cc9b43fSPeter A. G. Crosthwaite if (ex) { 9858cc9b43fSPeter A. G. Crosthwaite /* Force addr into the temp. */ 9868cc9b43fSPeter A. G. Crosthwaite if (addr != &t) { 987*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 988*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t, *addr); 9898cc9b43fSPeter A. G. Crosthwaite addr = &t; 9908cc9b43fSPeter A. G. Crosthwaite } 991*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t, t, ~3); 9928cc9b43fSPeter A. G. Crosthwaite } 9938cc9b43fSPeter A. G. Crosthwaite 9944acb54baSEdgar E. Iglesias /* If we get a fault on a dslot, the jmpstate better be in sync. */ 9954acb54baSEdgar E. Iglesias sync_jmpstate(dc); 996968a40f6SEdgar E. Iglesias 997968a40f6SEdgar E. Iglesias /* Verify alignment if needed. */ 998a12f6507SEdgar E. Iglesias /* 999a12f6507SEdgar E. Iglesias * Microblaze gives MMU faults priority over faults due to 1000a12f6507SEdgar E. Iglesias * unaligned addresses. That's why we speculatively do the load 1001a12f6507SEdgar E. Iglesias * into v. If the load succeeds, we verify alignment of the 1002a12f6507SEdgar E. Iglesias * address and if that succeeds we write into the destination reg. 1003a12f6507SEdgar E. Iglesias */ 1004*cfeea807SEdgar E. Iglesias v = tcg_temp_new_i32(); 1005*cfeea807SEdgar E. Iglesias tcg_gen_qemu_ld_i32(v, *addr, cpu_mmu_index(&dc->cpu->env, false), mop); 1006a12f6507SEdgar E. Iglesias 10070063ebd6SAndreas Färber if ((dc->cpu->env.pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) { 1008*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc); 1009*cfeea807SEdgar E. Iglesias gen_helper_memalign(cpu_env, *addr, tcg_const_i32(dc->rd), 1010*cfeea807SEdgar E. Iglesias tcg_const_i32(0), tcg_const_i32(size - 1)); 101147acdd63SRichard Henderson } 101247acdd63SRichard Henderson 101347acdd63SRichard Henderson if (ex) { 1014*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(env_res_addr, *addr); 1015*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(env_res_val, v); 101647acdd63SRichard Henderson } 10179f8beb66SEdgar E. Iglesias if (dc->rd) { 1018*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_R[dc->rd], v); 10199f8beb66SEdgar E. Iglesias } 1020*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(v); 10214acb54baSEdgar E. Iglesias 10228cc9b43fSPeter A. G. Crosthwaite if (ex) { /* lwx */ 1023b6af0975SDaniel P. Berrange /* no support for AXI exclusive so always clear C */ 10248cc9b43fSPeter A. G. Crosthwaite write_carryi(dc, 0); 10258cc9b43fSPeter A. G. Crosthwaite } 10268cc9b43fSPeter A. G. Crosthwaite 10274acb54baSEdgar E. Iglesias if (addr == &t) 1028*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t); 10294acb54baSEdgar E. Iglesias } 10304acb54baSEdgar E. Iglesias 10314acb54baSEdgar E. Iglesias static void dec_store(DisasContext *dc) 10324acb54baSEdgar E. Iglesias { 1033*cfeea807SEdgar E. Iglesias TCGv_i32 t, *addr, swx_addr; 103442a268c2SRichard Henderson TCGLabel *swx_skip = NULL; 1035b51b3d43SEdgar E. Iglesias unsigned int size; 1036b51b3d43SEdgar E. Iglesias bool rev = false, ex = false; 103747acdd63SRichard Henderson TCGMemOp mop; 10384acb54baSEdgar E. Iglesias 103947acdd63SRichard Henderson mop = dc->opcode & 3; 104047acdd63SRichard Henderson size = 1 << mop; 10419f8beb66SEdgar E. Iglesias if (!dc->type_b) { 1042b51b3d43SEdgar E. Iglesias rev = extract32(dc->ir, 9, 1); 1043b51b3d43SEdgar E. Iglesias ex = extract32(dc->ir, 10, 1); 10449f8beb66SEdgar E. Iglesias } 104547acdd63SRichard Henderson mop |= MO_TE; 104647acdd63SRichard Henderson if (rev) { 104747acdd63SRichard Henderson mop ^= MO_BSWAP; 104847acdd63SRichard Henderson } 10494acb54baSEdgar E. Iglesias 10500187688fSEdgar E. Iglesias if (size > 4 && (dc->tb_flags & MSR_EE_FLAG) 10510063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) { 1052*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 10530187688fSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 10540187688fSEdgar E. Iglesias return; 10550187688fSEdgar E. Iglesias } 10560187688fSEdgar E. Iglesias 10578cc9b43fSPeter A. G. Crosthwaite LOG_DIS("s%d%s%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "", 10588cc9b43fSPeter A. G. Crosthwaite ex ? "x" : ""); 10594acb54baSEdgar E. Iglesias t_sync_flags(dc); 10604acb54baSEdgar E. Iglesias /* If we get a fault on a dslot, the jmpstate better be in sync. */ 10614acb54baSEdgar E. Iglesias sync_jmpstate(dc); 10624acb54baSEdgar E. Iglesias addr = compute_ldst_addr(dc, &t); 1063968a40f6SEdgar E. Iglesias 1064*cfeea807SEdgar E. Iglesias swx_addr = tcg_temp_local_new_i32(); 1065083dbf48SPeter A. G. Crosthwaite if (ex) { /* swx */ 1066*cfeea807SEdgar E. Iglesias TCGv_i32 tval; 10678cc9b43fSPeter A. G. Crosthwaite 10688cc9b43fSPeter A. G. Crosthwaite /* Force addr into the swx_addr. */ 1069*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(swx_addr, *addr); 10708cc9b43fSPeter A. G. Crosthwaite addr = &swx_addr; 10718cc9b43fSPeter A. G. Crosthwaite /* swx does not throw unaligned access errors, so force alignment */ 1072*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(swx_addr, swx_addr, ~3); 10738cc9b43fSPeter A. G. Crosthwaite 10748cc9b43fSPeter A. G. Crosthwaite write_carryi(dc, 1); 10758cc9b43fSPeter A. G. Crosthwaite swx_skip = gen_new_label(); 1076*cfeea807SEdgar E. Iglesias tcg_gen_brcond_i32(TCG_COND_NE, env_res_addr, swx_addr, swx_skip); 107711a76217SEdgar E. Iglesias 107811a76217SEdgar E. Iglesias /* Compare the value loaded at lwx with current contents of 107911a76217SEdgar E. Iglesias the reserved location. 108011a76217SEdgar E. Iglesias FIXME: This only works for system emulation where we can expect 108111a76217SEdgar E. Iglesias this compare and the following write to be atomic. For user 108211a76217SEdgar E. Iglesias emulation we need to add atomicity between threads. */ 1083*cfeea807SEdgar E. Iglesias tval = tcg_temp_new_i32(); 1084*cfeea807SEdgar E. Iglesias tcg_gen_qemu_ld_i32(tval, swx_addr, cpu_mmu_index(&dc->cpu->env, false), 10850063ebd6SAndreas Färber MO_TEUL); 1086*cfeea807SEdgar E. Iglesias tcg_gen_brcond_i32(TCG_COND_NE, env_res_val, tval, swx_skip); 10878cc9b43fSPeter A. G. Crosthwaite write_carryi(dc, 0); 1088*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(tval); 10898cc9b43fSPeter A. G. Crosthwaite } 10908cc9b43fSPeter A. G. Crosthwaite 10919f8beb66SEdgar E. Iglesias if (rev && size != 4) { 10929f8beb66SEdgar E. Iglesias /* Endian reverse the address. t is addr. */ 10939f8beb66SEdgar E. Iglesias switch (size) { 10949f8beb66SEdgar E. Iglesias case 1: 10959f8beb66SEdgar E. Iglesias { 10969f8beb66SEdgar E. Iglesias /* 00 -> 11 10979f8beb66SEdgar E. Iglesias 01 -> 10 10989f8beb66SEdgar E. Iglesias 10 -> 10 10999f8beb66SEdgar E. Iglesias 11 -> 00 */ 1100*cfeea807SEdgar E. Iglesias TCGv_i32 low = tcg_temp_new_i32(); 11019f8beb66SEdgar E. Iglesias 11029f8beb66SEdgar E. Iglesias /* Force addr into the temp. */ 11039f8beb66SEdgar E. Iglesias if (addr != &t) { 1104*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 1105*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(t, *addr); 11069f8beb66SEdgar E. Iglesias addr = &t; 11079f8beb66SEdgar E. Iglesias } 11089f8beb66SEdgar E. Iglesias 1109*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(low, t, 3); 1110*cfeea807SEdgar E. Iglesias tcg_gen_sub_i32(low, tcg_const_i32(3), low); 1111*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t, t, ~3); 1112*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t, t, low); 1113*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(low); 11149f8beb66SEdgar E. Iglesias break; 11159f8beb66SEdgar E. Iglesias } 11169f8beb66SEdgar E. Iglesias 11179f8beb66SEdgar E. Iglesias case 2: 11189f8beb66SEdgar E. Iglesias /* 00 -> 10 11199f8beb66SEdgar E. Iglesias 10 -> 00. */ 11209f8beb66SEdgar E. Iglesias /* Force addr into the temp. */ 11219f8beb66SEdgar E. Iglesias if (addr != &t) { 1122*cfeea807SEdgar E. Iglesias t = tcg_temp_new_i32(); 1123*cfeea807SEdgar E. Iglesias tcg_gen_xori_i32(t, *addr, 2); 11249f8beb66SEdgar E. Iglesias addr = &t; 11259f8beb66SEdgar E. Iglesias } else { 1126*cfeea807SEdgar E. Iglesias tcg_gen_xori_i32(t, t, 2); 11279f8beb66SEdgar E. Iglesias } 11289f8beb66SEdgar E. Iglesias break; 11299f8beb66SEdgar E. Iglesias default: 11300063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "Invalid reverse size\n"); 11319f8beb66SEdgar E. Iglesias break; 11329f8beb66SEdgar E. Iglesias } 11339f8beb66SEdgar E. Iglesias } 1134*cfeea807SEdgar E. Iglesias tcg_gen_qemu_st_i32(cpu_R[dc->rd], *addr, 1135*cfeea807SEdgar E. Iglesias cpu_mmu_index(&dc->cpu->env, false), mop); 1136a12f6507SEdgar E. Iglesias 1137968a40f6SEdgar E. Iglesias /* Verify alignment if needed. */ 11380063ebd6SAndreas Färber if ((dc->cpu->env.pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) { 1139*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc); 1140a12f6507SEdgar E. Iglesias /* FIXME: if the alignment is wrong, we should restore the value 11414abf79a4SDong Xu Wang * in memory. One possible way to achieve this is to probe 11429f8beb66SEdgar E. Iglesias * the MMU prior to the memaccess, thay way we could put 11439f8beb66SEdgar E. Iglesias * the alignment checks in between the probe and the mem 11449f8beb66SEdgar E. Iglesias * access. 1145a12f6507SEdgar E. Iglesias */ 1146*cfeea807SEdgar E. Iglesias gen_helper_memalign(cpu_env, *addr, tcg_const_i32(dc->rd), 1147*cfeea807SEdgar E. Iglesias tcg_const_i32(1), tcg_const_i32(size - 1)); 1148968a40f6SEdgar E. Iglesias } 1149083dbf48SPeter A. G. Crosthwaite 11508cc9b43fSPeter A. G. Crosthwaite if (ex) { 11518cc9b43fSPeter A. G. Crosthwaite gen_set_label(swx_skip); 1152083dbf48SPeter A. G. Crosthwaite } 1153*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(swx_addr); 1154968a40f6SEdgar E. Iglesias 11554acb54baSEdgar E. Iglesias if (addr == &t) 1156*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t); 11574acb54baSEdgar E. Iglesias } 11584acb54baSEdgar E. Iglesias 11594acb54baSEdgar E. Iglesias static inline void eval_cc(DisasContext *dc, unsigned int cc, 1160*cfeea807SEdgar E. Iglesias TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) 11614acb54baSEdgar E. Iglesias { 11624acb54baSEdgar E. Iglesias switch (cc) { 11634acb54baSEdgar E. Iglesias case CC_EQ: 1164*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_EQ, d, a, b); 11654acb54baSEdgar E. Iglesias break; 11664acb54baSEdgar E. Iglesias case CC_NE: 1167*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_NE, d, a, b); 11684acb54baSEdgar E. Iglesias break; 11694acb54baSEdgar E. Iglesias case CC_LT: 1170*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_LT, d, a, b); 11714acb54baSEdgar E. Iglesias break; 11724acb54baSEdgar E. Iglesias case CC_LE: 1173*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_LE, d, a, b); 11744acb54baSEdgar E. Iglesias break; 11754acb54baSEdgar E. Iglesias case CC_GE: 1176*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_GE, d, a, b); 11774acb54baSEdgar E. Iglesias break; 11784acb54baSEdgar E. Iglesias case CC_GT: 1179*cfeea807SEdgar E. Iglesias tcg_gen_setcond_i32(TCG_COND_GT, d, a, b); 11804acb54baSEdgar E. Iglesias break; 11814acb54baSEdgar E. Iglesias default: 11820063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "Unknown condition code %x.\n", cc); 11834acb54baSEdgar E. Iglesias break; 11844acb54baSEdgar E. Iglesias } 11854acb54baSEdgar E. Iglesias } 11864acb54baSEdgar E. Iglesias 1187*cfeea807SEdgar E. Iglesias static void eval_cond_jmp(DisasContext *dc, TCGv_i32 pc_true, TCGv_i32 pc_false) 11884acb54baSEdgar E. Iglesias { 118942a268c2SRichard Henderson TCGLabel *l1 = gen_new_label(); 11904acb54baSEdgar E. Iglesias /* Conditional jmp. */ 1191*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_SR[SR_PC], pc_false); 1192*cfeea807SEdgar E. Iglesias tcg_gen_brcondi_i32(TCG_COND_EQ, env_btaken, 0, l1); 1193*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(cpu_SR[SR_PC], pc_true); 11944acb54baSEdgar E. Iglesias gen_set_label(l1); 11954acb54baSEdgar E. Iglesias } 11964acb54baSEdgar E. Iglesias 11974acb54baSEdgar E. Iglesias static void dec_bcc(DisasContext *dc) 11984acb54baSEdgar E. Iglesias { 11994acb54baSEdgar E. Iglesias unsigned int cc; 12004acb54baSEdgar E. Iglesias unsigned int dslot; 12014acb54baSEdgar E. Iglesias 12024acb54baSEdgar E. Iglesias cc = EXTRACT_FIELD(dc->ir, 21, 23); 12034acb54baSEdgar E. Iglesias dslot = dc->ir & (1 << 25); 12044acb54baSEdgar E. Iglesias LOG_DIS("bcc%s r%d %x\n", dslot ? "d" : "", dc->ra, dc->imm); 12054acb54baSEdgar E. Iglesias 12064acb54baSEdgar E. Iglesias dc->delayed_branch = 1; 12074acb54baSEdgar E. Iglesias if (dslot) { 12084acb54baSEdgar E. Iglesias dc->delayed_branch = 2; 12094acb54baSEdgar E. Iglesias dc->tb_flags |= D_FLAG; 1210*cfeea807SEdgar E. Iglesias tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)), 121168cee38aSAndreas Färber cpu_env, offsetof(CPUMBState, bimm)); 12124acb54baSEdgar E. Iglesias } 12134acb54baSEdgar E. Iglesias 121461204ce8SEdgar E. Iglesias if (dec_alu_op_b_is_small_imm(dc)) { 121561204ce8SEdgar E. Iglesias int32_t offset = (int32_t)((int16_t)dc->imm); /* sign-extend. */ 121661204ce8SEdgar E. Iglesias 1217*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btarget, dc->pc + offset); 1218844bab60SEdgar E. Iglesias dc->jmp = JMP_DIRECT_CC; 121923979dc5SEdgar E. Iglesias dc->jmp_pc = dc->pc + offset; 122061204ce8SEdgar E. Iglesias } else { 122123979dc5SEdgar E. Iglesias dc->jmp = JMP_INDIRECT; 1222*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btarget, dc->pc); 1223*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(env_btarget, env_btarget, *(dec_alu_op_b(dc))); 122461204ce8SEdgar E. Iglesias } 1225*cfeea807SEdgar E. Iglesias eval_cc(dc, cc, env_btaken, cpu_R[dc->ra], tcg_const_i32(0)); 12264acb54baSEdgar E. Iglesias } 12274acb54baSEdgar E. Iglesias 12284acb54baSEdgar E. Iglesias static void dec_br(DisasContext *dc) 12294acb54baSEdgar E. Iglesias { 12309f6113c7SEdgar E. Iglesias unsigned int dslot, link, abs, mbar; 123197ed5ccdSBenjamin Herrenschmidt int mem_index = cpu_mmu_index(&dc->cpu->env, false); 12324acb54baSEdgar E. Iglesias 12334acb54baSEdgar E. Iglesias dslot = dc->ir & (1 << 20); 12344acb54baSEdgar E. Iglesias abs = dc->ir & (1 << 19); 12354acb54baSEdgar E. Iglesias link = dc->ir & (1 << 18); 12369f6113c7SEdgar E. Iglesias 12379f6113c7SEdgar E. Iglesias /* Memory barrier. */ 12389f6113c7SEdgar E. Iglesias mbar = (dc->ir >> 16) & 31; 12399f6113c7SEdgar E. Iglesias if (mbar == 2 && dc->imm == 4) { 12405d45de97SEdgar E. Iglesias /* mbar IMM & 16 decodes to sleep. */ 12415d45de97SEdgar E. Iglesias if (dc->rd & 16) { 12425d45de97SEdgar E. Iglesias TCGv_i32 tmp_hlt = tcg_const_i32(EXCP_HLT); 12435d45de97SEdgar E. Iglesias TCGv_i32 tmp_1 = tcg_const_i32(1); 12445d45de97SEdgar E. Iglesias 12455d45de97SEdgar E. Iglesias LOG_DIS("sleep\n"); 12465d45de97SEdgar E. Iglesias 12475d45de97SEdgar E. Iglesias t_sync_flags(dc); 12485d45de97SEdgar E. Iglesias tcg_gen_st_i32(tmp_1, cpu_env, 12495d45de97SEdgar E. Iglesias -offsetof(MicroBlazeCPU, env) 12505d45de97SEdgar E. Iglesias +offsetof(CPUState, halted)); 1251*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc + 4); 12525d45de97SEdgar E. Iglesias gen_helper_raise_exception(cpu_env, tmp_hlt); 12535d45de97SEdgar E. Iglesias tcg_temp_free_i32(tmp_hlt); 12545d45de97SEdgar E. Iglesias tcg_temp_free_i32(tmp_1); 12555d45de97SEdgar E. Iglesias return; 12565d45de97SEdgar E. Iglesias } 12579f6113c7SEdgar E. Iglesias LOG_DIS("mbar %d\n", dc->rd); 12589f6113c7SEdgar E. Iglesias /* Break the TB. */ 12599f6113c7SEdgar E. Iglesias dc->cpustate_changed = 1; 12609f6113c7SEdgar E. Iglesias return; 12619f6113c7SEdgar E. Iglesias } 12629f6113c7SEdgar E. Iglesias 12634acb54baSEdgar E. Iglesias LOG_DIS("br%s%s%s%s imm=%x\n", 12644acb54baSEdgar E. Iglesias abs ? "a" : "", link ? "l" : "", 12654acb54baSEdgar E. Iglesias dc->type_b ? "i" : "", dslot ? "d" : "", 12664acb54baSEdgar E. Iglesias dc->imm); 12674acb54baSEdgar E. Iglesias 12684acb54baSEdgar E. Iglesias dc->delayed_branch = 1; 12694acb54baSEdgar E. Iglesias if (dslot) { 12704acb54baSEdgar E. Iglesias dc->delayed_branch = 2; 12714acb54baSEdgar E. Iglesias dc->tb_flags |= D_FLAG; 1272*cfeea807SEdgar E. Iglesias tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)), 127368cee38aSAndreas Färber cpu_env, offsetof(CPUMBState, bimm)); 12744acb54baSEdgar E. Iglesias } 12754acb54baSEdgar E. Iglesias if (link && dc->rd) 1276*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_R[dc->rd], dc->pc); 12774acb54baSEdgar E. Iglesias 12784acb54baSEdgar E. Iglesias dc->jmp = JMP_INDIRECT; 12794acb54baSEdgar E. Iglesias if (abs) { 1280*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btaken, 1); 1281*cfeea807SEdgar E. Iglesias tcg_gen_mov_i32(env_btarget, *(dec_alu_op_b(dc))); 1282ff21f70aSEdgar E. Iglesias if (link && !dslot) { 1283ff21f70aSEdgar E. Iglesias if (!(dc->tb_flags & IMM_FLAG) && (dc->imm == 8 || dc->imm == 0x18)) 12844acb54baSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_BREAK); 1285ff21f70aSEdgar E. Iglesias if (dc->imm == 0) { 1286ff21f70aSEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) && mem_index == MMU_USER_IDX) { 1287*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 1288ff21f70aSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 1289ff21f70aSEdgar E. Iglesias return; 1290ff21f70aSEdgar E. Iglesias } 1291ff21f70aSEdgar E. Iglesias 12924acb54baSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_DEBUG); 1293ff21f70aSEdgar E. Iglesias } 1294ff21f70aSEdgar E. Iglesias } 12954acb54baSEdgar E. Iglesias } else { 129661204ce8SEdgar E. Iglesias if (dec_alu_op_b_is_small_imm(dc)) { 129761204ce8SEdgar E. Iglesias dc->jmp = JMP_DIRECT; 129861204ce8SEdgar E. Iglesias dc->jmp_pc = dc->pc + (int32_t)((int16_t)dc->imm); 129961204ce8SEdgar E. Iglesias } else { 1300*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btaken, 1); 1301*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btarget, dc->pc); 1302*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(env_btarget, env_btarget, *(dec_alu_op_b(dc))); 13034acb54baSEdgar E. Iglesias } 13044acb54baSEdgar E. Iglesias } 13054acb54baSEdgar E. Iglesias } 13064acb54baSEdgar E. Iglesias 13074acb54baSEdgar E. Iglesias static inline void do_rti(DisasContext *dc) 13084acb54baSEdgar E. Iglesias { 1309*cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1310*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1311*cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 1312*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(t0, cpu_SR[SR_MSR], 1); 1313*cfeea807SEdgar E. Iglesias tcg_gen_ori_i32(t1, cpu_SR[SR_MSR], MSR_IE); 1314*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 13154acb54baSEdgar E. Iglesias 1316*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1317*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 13184acb54baSEdgar E. Iglesias msr_write(dc, t1); 1319*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1320*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 13214acb54baSEdgar E. Iglesias dc->tb_flags &= ~DRTI_FLAG; 13224acb54baSEdgar E. Iglesias } 13234acb54baSEdgar E. Iglesias 13244acb54baSEdgar E. Iglesias static inline void do_rtb(DisasContext *dc) 13254acb54baSEdgar E. Iglesias { 1326*cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1327*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1328*cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 1329*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, cpu_SR[SR_MSR], ~MSR_BIP); 1330*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(t0, t1, 1); 1331*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 13324acb54baSEdgar E. Iglesias 1333*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1334*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 13354acb54baSEdgar E. Iglesias msr_write(dc, t1); 1336*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1337*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 13384acb54baSEdgar E. Iglesias dc->tb_flags &= ~DRTB_FLAG; 13394acb54baSEdgar E. Iglesias } 13404acb54baSEdgar E. Iglesias 13414acb54baSEdgar E. Iglesias static inline void do_rte(DisasContext *dc) 13424acb54baSEdgar E. Iglesias { 1343*cfeea807SEdgar E. Iglesias TCGv_i32 t0, t1; 1344*cfeea807SEdgar E. Iglesias t0 = tcg_temp_new_i32(); 1345*cfeea807SEdgar E. Iglesias t1 = tcg_temp_new_i32(); 13464acb54baSEdgar E. Iglesias 1347*cfeea807SEdgar E. Iglesias tcg_gen_ori_i32(t1, cpu_SR[SR_MSR], MSR_EE); 1348*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~MSR_EIP); 1349*cfeea807SEdgar E. Iglesias tcg_gen_shri_i32(t0, t1, 1); 1350*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM)); 13514acb54baSEdgar E. Iglesias 1352*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM)); 1353*cfeea807SEdgar E. Iglesias tcg_gen_or_i32(t1, t1, t0); 13544acb54baSEdgar E. Iglesias msr_write(dc, t1); 1355*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t1); 1356*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t0); 13574acb54baSEdgar E. Iglesias dc->tb_flags &= ~DRTE_FLAG; 13584acb54baSEdgar E. Iglesias } 13594acb54baSEdgar E. Iglesias 13604acb54baSEdgar E. Iglesias static void dec_rts(DisasContext *dc) 13614acb54baSEdgar E. Iglesias { 13624acb54baSEdgar E. Iglesias unsigned int b_bit, i_bit, e_bit; 136397ed5ccdSBenjamin Herrenschmidt int mem_index = cpu_mmu_index(&dc->cpu->env, false); 13644acb54baSEdgar E. Iglesias 13654acb54baSEdgar E. Iglesias i_bit = dc->ir & (1 << 21); 13664acb54baSEdgar E. Iglesias b_bit = dc->ir & (1 << 22); 13674acb54baSEdgar E. Iglesias e_bit = dc->ir & (1 << 23); 13684acb54baSEdgar E. Iglesias 13694acb54baSEdgar E. Iglesias dc->delayed_branch = 2; 13704acb54baSEdgar E. Iglesias dc->tb_flags |= D_FLAG; 1371*cfeea807SEdgar E. Iglesias tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)), 137268cee38aSAndreas Färber cpu_env, offsetof(CPUMBState, bimm)); 13734acb54baSEdgar E. Iglesias 13744acb54baSEdgar E. Iglesias if (i_bit) { 13754acb54baSEdgar E. Iglesias LOG_DIS("rtid ir=%x\n", dc->ir); 13761567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 13771567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 1378*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 13791567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 13801567a005SEdgar E. Iglesias } 13814acb54baSEdgar E. Iglesias dc->tb_flags |= DRTI_FLAG; 13824acb54baSEdgar E. Iglesias } else if (b_bit) { 13834acb54baSEdgar E. Iglesias LOG_DIS("rtbd ir=%x\n", dc->ir); 13841567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 13851567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 1386*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 13871567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 13881567a005SEdgar E. Iglesias } 13894acb54baSEdgar E. Iglesias dc->tb_flags |= DRTB_FLAG; 13904acb54baSEdgar E. Iglesias } else if (e_bit) { 13914acb54baSEdgar E. Iglesias LOG_DIS("rted ir=%x\n", dc->ir); 13921567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 13931567a005SEdgar E. Iglesias && mem_index == MMU_USER_IDX) { 1394*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 13951567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 13961567a005SEdgar E. Iglesias } 13974acb54baSEdgar E. Iglesias dc->tb_flags |= DRTE_FLAG; 13984acb54baSEdgar E. Iglesias } else 13994acb54baSEdgar E. Iglesias LOG_DIS("rts ir=%x\n", dc->ir); 14004acb54baSEdgar E. Iglesias 140123979dc5SEdgar E. Iglesias dc->jmp = JMP_INDIRECT; 1402*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(env_btaken, 1); 1403*cfeea807SEdgar E. Iglesias tcg_gen_add_i32(env_btarget, cpu_R[dc->ra], *(dec_alu_op_b(dc))); 14044acb54baSEdgar E. Iglesias } 14054acb54baSEdgar E. Iglesias 140697694c57SEdgar E. Iglesias static int dec_check_fpuv2(DisasContext *dc) 140797694c57SEdgar E. Iglesias { 1408be67e9abSAlistair Francis if ((dc->cpu->cfg.use_fpu != 2) && (dc->tb_flags & MSR_EE_FLAG)) { 1409*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_FPU); 141097694c57SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 141197694c57SEdgar E. Iglesias } 1412be67e9abSAlistair Francis return (dc->cpu->cfg.use_fpu == 2) ? 0 : PVR2_USE_FPU2_MASK; 141397694c57SEdgar E. Iglesias } 141497694c57SEdgar E. Iglesias 14151567a005SEdgar E. Iglesias static void dec_fpu(DisasContext *dc) 14161567a005SEdgar E. Iglesias { 141797694c57SEdgar E. Iglesias unsigned int fpu_insn; 141897694c57SEdgar E. Iglesias 14191567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 14200063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 14215153bb89SEdgar E. Iglesias && !dc->cpu->cfg.use_fpu) { 1422*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 14231567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 14241567a005SEdgar E. Iglesias return; 14251567a005SEdgar E. Iglesias } 14261567a005SEdgar E. Iglesias 142797694c57SEdgar E. Iglesias fpu_insn = (dc->ir >> 7) & 7; 142897694c57SEdgar E. Iglesias 142997694c57SEdgar E. Iglesias switch (fpu_insn) { 143097694c57SEdgar E. Iglesias case 0: 143164254ebaSBlue Swirl gen_helper_fadd(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 143264254ebaSBlue Swirl cpu_R[dc->rb]); 143397694c57SEdgar E. Iglesias break; 143497694c57SEdgar E. Iglesias 143597694c57SEdgar E. Iglesias case 1: 143664254ebaSBlue Swirl gen_helper_frsub(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 143764254ebaSBlue Swirl cpu_R[dc->rb]); 143897694c57SEdgar E. Iglesias break; 143997694c57SEdgar E. Iglesias 144097694c57SEdgar E. Iglesias case 2: 144164254ebaSBlue Swirl gen_helper_fmul(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 144264254ebaSBlue Swirl cpu_R[dc->rb]); 144397694c57SEdgar E. Iglesias break; 144497694c57SEdgar E. Iglesias 144597694c57SEdgar E. Iglesias case 3: 144664254ebaSBlue Swirl gen_helper_fdiv(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra], 144764254ebaSBlue Swirl cpu_R[dc->rb]); 144897694c57SEdgar E. Iglesias break; 144997694c57SEdgar E. Iglesias 145097694c57SEdgar E. Iglesias case 4: 145197694c57SEdgar E. Iglesias switch ((dc->ir >> 4) & 7) { 145297694c57SEdgar E. Iglesias case 0: 145364254ebaSBlue Swirl gen_helper_fcmp_un(cpu_R[dc->rd], cpu_env, 145497694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 145597694c57SEdgar E. Iglesias break; 145697694c57SEdgar E. Iglesias case 1: 145764254ebaSBlue Swirl gen_helper_fcmp_lt(cpu_R[dc->rd], cpu_env, 145897694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 145997694c57SEdgar E. Iglesias break; 146097694c57SEdgar E. Iglesias case 2: 146164254ebaSBlue Swirl gen_helper_fcmp_eq(cpu_R[dc->rd], cpu_env, 146297694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 146397694c57SEdgar E. Iglesias break; 146497694c57SEdgar E. Iglesias case 3: 146564254ebaSBlue Swirl gen_helper_fcmp_le(cpu_R[dc->rd], cpu_env, 146697694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 146797694c57SEdgar E. Iglesias break; 146897694c57SEdgar E. Iglesias case 4: 146964254ebaSBlue Swirl gen_helper_fcmp_gt(cpu_R[dc->rd], cpu_env, 147097694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 147197694c57SEdgar E. Iglesias break; 147297694c57SEdgar E. Iglesias case 5: 147364254ebaSBlue Swirl gen_helper_fcmp_ne(cpu_R[dc->rd], cpu_env, 147497694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 147597694c57SEdgar E. Iglesias break; 147697694c57SEdgar E. Iglesias case 6: 147764254ebaSBlue Swirl gen_helper_fcmp_ge(cpu_R[dc->rd], cpu_env, 147897694c57SEdgar E. Iglesias cpu_R[dc->ra], cpu_R[dc->rb]); 147997694c57SEdgar E. Iglesias break; 148097694c57SEdgar E. Iglesias default: 148171547a3bSBlue Swirl qemu_log_mask(LOG_UNIMP, 148271547a3bSBlue Swirl "unimplemented fcmp fpu_insn=%x pc=%x" 148371547a3bSBlue Swirl " opc=%x\n", 148497694c57SEdgar E. Iglesias fpu_insn, dc->pc, dc->opcode); 14851567a005SEdgar E. Iglesias dc->abort_at_next_insn = 1; 148697694c57SEdgar E. Iglesias break; 148797694c57SEdgar E. Iglesias } 148897694c57SEdgar E. Iglesias break; 148997694c57SEdgar E. Iglesias 149097694c57SEdgar E. Iglesias case 5: 149197694c57SEdgar E. Iglesias if (!dec_check_fpuv2(dc)) { 149297694c57SEdgar E. Iglesias return; 149397694c57SEdgar E. Iglesias } 149464254ebaSBlue Swirl gen_helper_flt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 149597694c57SEdgar E. Iglesias break; 149697694c57SEdgar E. Iglesias 149797694c57SEdgar E. Iglesias case 6: 149897694c57SEdgar E. Iglesias if (!dec_check_fpuv2(dc)) { 149997694c57SEdgar E. Iglesias return; 150097694c57SEdgar E. Iglesias } 150164254ebaSBlue Swirl gen_helper_fint(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 150297694c57SEdgar E. Iglesias break; 150397694c57SEdgar E. Iglesias 150497694c57SEdgar E. Iglesias case 7: 150597694c57SEdgar E. Iglesias if (!dec_check_fpuv2(dc)) { 150697694c57SEdgar E. Iglesias return; 150797694c57SEdgar E. Iglesias } 150864254ebaSBlue Swirl gen_helper_fsqrt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]); 150997694c57SEdgar E. Iglesias break; 151097694c57SEdgar E. Iglesias 151197694c57SEdgar E. Iglesias default: 151271547a3bSBlue Swirl qemu_log_mask(LOG_UNIMP, "unimplemented FPU insn fpu_insn=%x pc=%x" 151371547a3bSBlue Swirl " opc=%x\n", 151497694c57SEdgar E. Iglesias fpu_insn, dc->pc, dc->opcode); 151597694c57SEdgar E. Iglesias dc->abort_at_next_insn = 1; 151697694c57SEdgar E. Iglesias break; 151797694c57SEdgar E. Iglesias } 15181567a005SEdgar E. Iglesias } 15191567a005SEdgar E. Iglesias 15204acb54baSEdgar E. Iglesias static void dec_null(DisasContext *dc) 15214acb54baSEdgar E. Iglesias { 152202b33596SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 15230063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) { 1524*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 152502b33596SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 152602b33596SEdgar E. Iglesias return; 152702b33596SEdgar E. Iglesias } 15281d512a65SPaolo Bonzini qemu_log_mask(LOG_GUEST_ERROR, "unknown insn pc=%x opc=%x\n", dc->pc, dc->opcode); 15294acb54baSEdgar E. Iglesias dc->abort_at_next_insn = 1; 15304acb54baSEdgar E. Iglesias } 15314acb54baSEdgar E. Iglesias 15326d76d23eSEdgar E. Iglesias /* Insns connected to FSL or AXI stream attached devices. */ 15336d76d23eSEdgar E. Iglesias static void dec_stream(DisasContext *dc) 15346d76d23eSEdgar E. Iglesias { 153597ed5ccdSBenjamin Herrenschmidt int mem_index = cpu_mmu_index(&dc->cpu->env, false); 15366d76d23eSEdgar E. Iglesias TCGv_i32 t_id, t_ctrl; 15376d76d23eSEdgar E. Iglesias int ctrl; 15386d76d23eSEdgar E. Iglesias 15396d76d23eSEdgar E. Iglesias LOG_DIS("%s%s imm=%x\n", dc->rd ? "get" : "put", 15406d76d23eSEdgar E. Iglesias dc->type_b ? "" : "d", dc->imm); 15416d76d23eSEdgar E. Iglesias 15426d76d23eSEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) && (mem_index == MMU_USER_IDX)) { 1543*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_PRIVINSN); 15446d76d23eSEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 15456d76d23eSEdgar E. Iglesias return; 15466d76d23eSEdgar E. Iglesias } 15476d76d23eSEdgar E. Iglesias 1548*cfeea807SEdgar E. Iglesias t_id = tcg_temp_new_i32(); 15496d76d23eSEdgar E. Iglesias if (dc->type_b) { 1550*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(t_id, dc->imm & 0xf); 15516d76d23eSEdgar E. Iglesias ctrl = dc->imm >> 10; 15526d76d23eSEdgar E. Iglesias } else { 1553*cfeea807SEdgar E. Iglesias tcg_gen_andi_i32(t_id, cpu_R[dc->rb], 0xf); 15546d76d23eSEdgar E. Iglesias ctrl = dc->imm >> 5; 15556d76d23eSEdgar E. Iglesias } 15566d76d23eSEdgar E. Iglesias 1557*cfeea807SEdgar E. Iglesias t_ctrl = tcg_const_i32(ctrl); 15586d76d23eSEdgar E. Iglesias 15596d76d23eSEdgar E. Iglesias if (dc->rd == 0) { 15606d76d23eSEdgar E. Iglesias gen_helper_put(t_id, t_ctrl, cpu_R[dc->ra]); 15616d76d23eSEdgar E. Iglesias } else { 15626d76d23eSEdgar E. Iglesias gen_helper_get(cpu_R[dc->rd], t_id, t_ctrl); 15636d76d23eSEdgar E. Iglesias } 1564*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t_id); 1565*cfeea807SEdgar E. Iglesias tcg_temp_free_i32(t_ctrl); 15666d76d23eSEdgar E. Iglesias } 15676d76d23eSEdgar E. Iglesias 15684acb54baSEdgar E. Iglesias static struct decoder_info { 15694acb54baSEdgar E. Iglesias struct { 15704acb54baSEdgar E. Iglesias uint32_t bits; 15714acb54baSEdgar E. Iglesias uint32_t mask; 15724acb54baSEdgar E. Iglesias }; 15734acb54baSEdgar E. Iglesias void (*dec)(DisasContext *dc); 15744acb54baSEdgar E. Iglesias } decinfo[] = { 15754acb54baSEdgar E. Iglesias {DEC_ADD, dec_add}, 15764acb54baSEdgar E. Iglesias {DEC_SUB, dec_sub}, 15774acb54baSEdgar E. Iglesias {DEC_AND, dec_and}, 15784acb54baSEdgar E. Iglesias {DEC_XOR, dec_xor}, 15794acb54baSEdgar E. Iglesias {DEC_OR, dec_or}, 15804acb54baSEdgar E. Iglesias {DEC_BIT, dec_bit}, 15814acb54baSEdgar E. Iglesias {DEC_BARREL, dec_barrel}, 15824acb54baSEdgar E. Iglesias {DEC_LD, dec_load}, 15834acb54baSEdgar E. Iglesias {DEC_ST, dec_store}, 15844acb54baSEdgar E. Iglesias {DEC_IMM, dec_imm}, 15854acb54baSEdgar E. Iglesias {DEC_BR, dec_br}, 15864acb54baSEdgar E. Iglesias {DEC_BCC, dec_bcc}, 15874acb54baSEdgar E. Iglesias {DEC_RTS, dec_rts}, 15881567a005SEdgar E. Iglesias {DEC_FPU, dec_fpu}, 15894acb54baSEdgar E. Iglesias {DEC_MUL, dec_mul}, 15904acb54baSEdgar E. Iglesias {DEC_DIV, dec_div}, 15914acb54baSEdgar E. Iglesias {DEC_MSR, dec_msr}, 15926d76d23eSEdgar E. Iglesias {DEC_STREAM, dec_stream}, 15934acb54baSEdgar E. Iglesias {{0, 0}, dec_null} 15944acb54baSEdgar E. Iglesias }; 15954acb54baSEdgar E. Iglesias 159664254ebaSBlue Swirl static inline void decode(DisasContext *dc, uint32_t ir) 15974acb54baSEdgar E. Iglesias { 15984acb54baSEdgar E. Iglesias int i; 15994acb54baSEdgar E. Iglesias 160064254ebaSBlue Swirl dc->ir = ir; 16014acb54baSEdgar E. Iglesias LOG_DIS("%8.8x\t", dc->ir); 16024acb54baSEdgar E. Iglesias 16034acb54baSEdgar E. Iglesias if (dc->ir) 16044acb54baSEdgar E. Iglesias dc->nr_nops = 0; 16054acb54baSEdgar E. Iglesias else { 16061567a005SEdgar E. Iglesias if ((dc->tb_flags & MSR_EE_FLAG) 16070063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK) 16080063ebd6SAndreas Färber && (dc->cpu->env.pvr.regs[2] & PVR2_OPCODE_0x0_ILL_MASK)) { 1609*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP); 16101567a005SEdgar E. Iglesias t_gen_raise_exception(dc, EXCP_HW_EXCP); 16111567a005SEdgar E. Iglesias return; 16121567a005SEdgar E. Iglesias } 16131567a005SEdgar E. Iglesias 16144acb54baSEdgar E. Iglesias LOG_DIS("nr_nops=%d\t", dc->nr_nops); 16154acb54baSEdgar E. Iglesias dc->nr_nops++; 1616a47dddd7SAndreas Färber if (dc->nr_nops > 4) { 16170063ebd6SAndreas Färber cpu_abort(CPU(dc->cpu), "fetching nop sequence\n"); 1618a47dddd7SAndreas Färber } 16194acb54baSEdgar E. Iglesias } 16204acb54baSEdgar E. Iglesias /* bit 2 seems to indicate insn type. */ 16214acb54baSEdgar E. Iglesias dc->type_b = ir & (1 << 29); 16224acb54baSEdgar E. Iglesias 16234acb54baSEdgar E. Iglesias dc->opcode = EXTRACT_FIELD(ir, 26, 31); 16244acb54baSEdgar E. Iglesias dc->rd = EXTRACT_FIELD(ir, 21, 25); 16254acb54baSEdgar E. Iglesias dc->ra = EXTRACT_FIELD(ir, 16, 20); 16264acb54baSEdgar E. Iglesias dc->rb = EXTRACT_FIELD(ir, 11, 15); 16274acb54baSEdgar E. Iglesias dc->imm = EXTRACT_FIELD(ir, 0, 15); 16284acb54baSEdgar E. Iglesias 16294acb54baSEdgar E. Iglesias /* Large switch for all insns. */ 16304acb54baSEdgar E. Iglesias for (i = 0; i < ARRAY_SIZE(decinfo); i++) { 16314acb54baSEdgar E. Iglesias if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits) { 16324acb54baSEdgar E. Iglesias decinfo[i].dec(dc); 16334acb54baSEdgar E. Iglesias break; 16344acb54baSEdgar E. Iglesias } 16354acb54baSEdgar E. Iglesias } 16364acb54baSEdgar E. Iglesias } 16374acb54baSEdgar E. Iglesias 16384acb54baSEdgar E. Iglesias /* generate intermediate code for basic block 'tb'. */ 16399c489ea6SLluís Vilanova void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) 16404acb54baSEdgar E. Iglesias { 16419c489ea6SLluís Vilanova CPUMBState *env = cs->env_ptr; 16424e5e1215SRichard Henderson MicroBlazeCPU *cpu = mb_env_get_cpu(env); 16434acb54baSEdgar E. Iglesias uint32_t pc_start; 16444acb54baSEdgar E. Iglesias struct DisasContext ctx; 16454acb54baSEdgar E. Iglesias struct DisasContext *dc = &ctx; 164656371527SEmilio G. Cota uint32_t page_start, org_flags; 1647*cfeea807SEdgar E. Iglesias uint32_t npc; 16484acb54baSEdgar E. Iglesias int num_insns; 16494acb54baSEdgar E. Iglesias int max_insns; 16504acb54baSEdgar E. Iglesias 16514acb54baSEdgar E. Iglesias pc_start = tb->pc; 16520063ebd6SAndreas Färber dc->cpu = cpu; 16534acb54baSEdgar E. Iglesias dc->tb = tb; 16544acb54baSEdgar E. Iglesias org_flags = dc->synced_flags = dc->tb_flags = tb->flags; 16554acb54baSEdgar E. Iglesias 16564acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_NEXT; 16574acb54baSEdgar E. Iglesias dc->jmp = 0; 16584acb54baSEdgar E. Iglesias dc->delayed_branch = !!(dc->tb_flags & D_FLAG); 165923979dc5SEdgar E. Iglesias if (dc->delayed_branch) { 166023979dc5SEdgar E. Iglesias dc->jmp = JMP_INDIRECT; 166123979dc5SEdgar E. Iglesias } 16624acb54baSEdgar E. Iglesias dc->pc = pc_start; 1663ed2803daSAndreas Färber dc->singlestep_enabled = cs->singlestep_enabled; 16644acb54baSEdgar E. Iglesias dc->cpustate_changed = 0; 16654acb54baSEdgar E. Iglesias dc->abort_at_next_insn = 0; 16664acb54baSEdgar E. Iglesias dc->nr_nops = 0; 16674acb54baSEdgar E. Iglesias 1668a47dddd7SAndreas Färber if (pc_start & 3) { 1669a47dddd7SAndreas Färber cpu_abort(cs, "Microblaze: unaligned PC=%x\n", pc_start); 1670a47dddd7SAndreas Färber } 16714acb54baSEdgar E. Iglesias 167256371527SEmilio G. Cota page_start = pc_start & TARGET_PAGE_MASK; 16734acb54baSEdgar E. Iglesias num_insns = 0; 1674c5a49c63SEmilio G. Cota max_insns = tb_cflags(tb) & CF_COUNT_MASK; 1675190ce7fbSRichard Henderson if (max_insns == 0) { 16764acb54baSEdgar E. Iglesias max_insns = CF_COUNT_MASK; 1677190ce7fbSRichard Henderson } 1678190ce7fbSRichard Henderson if (max_insns > TCG_MAX_INSNS) { 1679190ce7fbSRichard Henderson max_insns = TCG_MAX_INSNS; 1680190ce7fbSRichard Henderson } 16814acb54baSEdgar E. Iglesias 1682cd42d5b2SPaolo Bonzini gen_tb_start(tb); 16834acb54baSEdgar E. Iglesias do 16844acb54baSEdgar E. Iglesias { 1685667b8e29SRichard Henderson tcg_gen_insn_start(dc->pc); 1686959082fcSRichard Henderson num_insns++; 16874acb54baSEdgar E. Iglesias 1688b933066aSRichard Henderson #if SIM_COMPAT 1689b933066aSRichard Henderson if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { 1690*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], dc->pc); 1691b933066aSRichard Henderson gen_helper_debug(); 1692b933066aSRichard Henderson } 1693b933066aSRichard Henderson #endif 1694b933066aSRichard Henderson 1695b933066aSRichard Henderson if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) { 1696b933066aSRichard Henderson t_gen_raise_exception(dc, EXCP_DEBUG); 1697b933066aSRichard Henderson dc->is_jmp = DISAS_UPDATE; 1698522a0d4eSRichard Henderson /* The address covered by the breakpoint must be included in 1699522a0d4eSRichard Henderson [tb->pc, tb->pc + tb->size) in order to for it to be 1700522a0d4eSRichard Henderson properly cleared -- thus we increment the PC here so that 1701522a0d4eSRichard Henderson the logic setting tb->size below does the right thing. */ 1702522a0d4eSRichard Henderson dc->pc += 4; 1703b933066aSRichard Henderson break; 1704b933066aSRichard Henderson } 1705b933066aSRichard Henderson 17064acb54baSEdgar E. Iglesias /* Pretty disas. */ 17074acb54baSEdgar E. Iglesias LOG_DIS("%8.8x:\t", dc->pc); 17084acb54baSEdgar E. Iglesias 1709c5a49c63SEmilio G. Cota if (num_insns == max_insns && (tb_cflags(tb) & CF_LAST_IO)) { 17104acb54baSEdgar E. Iglesias gen_io_start(); 1711959082fcSRichard Henderson } 17124acb54baSEdgar E. Iglesias 17134acb54baSEdgar E. Iglesias dc->clear_imm = 1; 171464254ebaSBlue Swirl decode(dc, cpu_ldl_code(env, dc->pc)); 17154acb54baSEdgar E. Iglesias if (dc->clear_imm) 17164acb54baSEdgar E. Iglesias dc->tb_flags &= ~IMM_FLAG; 17174acb54baSEdgar E. Iglesias dc->pc += 4; 17184acb54baSEdgar E. Iglesias 17194acb54baSEdgar E. Iglesias if (dc->delayed_branch) { 17204acb54baSEdgar E. Iglesias dc->delayed_branch--; 17214acb54baSEdgar E. Iglesias if (!dc->delayed_branch) { 17224acb54baSEdgar E. Iglesias if (dc->tb_flags & DRTI_FLAG) 17234acb54baSEdgar E. Iglesias do_rti(dc); 17244acb54baSEdgar E. Iglesias if (dc->tb_flags & DRTB_FLAG) 17254acb54baSEdgar E. Iglesias do_rtb(dc); 17264acb54baSEdgar E. Iglesias if (dc->tb_flags & DRTE_FLAG) 17274acb54baSEdgar E. Iglesias do_rte(dc); 17284acb54baSEdgar E. Iglesias /* Clear the delay slot flag. */ 17294acb54baSEdgar E. Iglesias dc->tb_flags &= ~D_FLAG; 17304acb54baSEdgar E. Iglesias /* If it is a direct jump, try direct chaining. */ 173123979dc5SEdgar E. Iglesias if (dc->jmp == JMP_INDIRECT) { 1732*cfeea807SEdgar E. Iglesias eval_cond_jmp(dc, env_btarget, tcg_const_i32(dc->pc)); 17334acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_JUMP; 173423979dc5SEdgar E. Iglesias } else if (dc->jmp == JMP_DIRECT) { 1735844bab60SEdgar E. Iglesias t_sync_flags(dc); 1736844bab60SEdgar E. Iglesias gen_goto_tb(dc, 0, dc->jmp_pc); 1737844bab60SEdgar E. Iglesias dc->is_jmp = DISAS_TB_JUMP; 1738844bab60SEdgar E. Iglesias } else if (dc->jmp == JMP_DIRECT_CC) { 173942a268c2SRichard Henderson TCGLabel *l1 = gen_new_label(); 174023979dc5SEdgar E. Iglesias t_sync_flags(dc); 174123979dc5SEdgar E. Iglesias /* Conditional jmp. */ 1742*cfeea807SEdgar E. Iglesias tcg_gen_brcondi_i32(TCG_COND_NE, env_btaken, 0, l1); 174323979dc5SEdgar E. Iglesias gen_goto_tb(dc, 1, dc->pc); 174423979dc5SEdgar E. Iglesias gen_set_label(l1); 174523979dc5SEdgar E. Iglesias gen_goto_tb(dc, 0, dc->jmp_pc); 174623979dc5SEdgar E. Iglesias 174723979dc5SEdgar E. Iglesias dc->is_jmp = DISAS_TB_JUMP; 17484acb54baSEdgar E. Iglesias } 17494acb54baSEdgar E. Iglesias break; 17504acb54baSEdgar E. Iglesias } 17514acb54baSEdgar E. Iglesias } 1752ed2803daSAndreas Färber if (cs->singlestep_enabled) { 17534acb54baSEdgar E. Iglesias break; 1754ed2803daSAndreas Färber } 17554acb54baSEdgar E. Iglesias } while (!dc->is_jmp && !dc->cpustate_changed 1756fe700adbSRichard Henderson && !tcg_op_buf_full() 17574acb54baSEdgar E. Iglesias && !singlestep 175856371527SEmilio G. Cota && (dc->pc - page_start < TARGET_PAGE_SIZE) 17594acb54baSEdgar E. Iglesias && num_insns < max_insns); 17604acb54baSEdgar E. Iglesias 17614acb54baSEdgar E. Iglesias npc = dc->pc; 1762844bab60SEdgar E. Iglesias if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) { 17634acb54baSEdgar E. Iglesias if (dc->tb_flags & D_FLAG) { 17644acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_UPDATE; 1765*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], npc); 17664acb54baSEdgar E. Iglesias sync_jmpstate(dc); 17674acb54baSEdgar E. Iglesias } else 17684acb54baSEdgar E. Iglesias npc = dc->jmp_pc; 17694acb54baSEdgar E. Iglesias } 17704acb54baSEdgar E. Iglesias 1771c5a49c63SEmilio G. Cota if (tb_cflags(tb) & CF_LAST_IO) 17724acb54baSEdgar E. Iglesias gen_io_end(); 17734acb54baSEdgar E. Iglesias /* Force an update if the per-tb cpu state has changed. */ 17744acb54baSEdgar E. Iglesias if (dc->is_jmp == DISAS_NEXT 17754acb54baSEdgar E. Iglesias && (dc->cpustate_changed || org_flags != dc->tb_flags)) { 17764acb54baSEdgar E. Iglesias dc->is_jmp = DISAS_UPDATE; 1777*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], npc); 17784acb54baSEdgar E. Iglesias } 17794acb54baSEdgar E. Iglesias t_sync_flags(dc); 17804acb54baSEdgar E. Iglesias 1781ed2803daSAndreas Färber if (unlikely(cs->singlestep_enabled)) { 17826c5f738dSEdgar E. Iglesias TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG); 17836c5f738dSEdgar E. Iglesias 17846c5f738dSEdgar E. Iglesias if (dc->is_jmp != DISAS_JUMP) { 1785*cfeea807SEdgar E. Iglesias tcg_gen_movi_i32(cpu_SR[SR_PC], npc); 17866c5f738dSEdgar E. Iglesias } 178764254ebaSBlue Swirl gen_helper_raise_exception(cpu_env, tmp); 17886c5f738dSEdgar E. Iglesias tcg_temp_free_i32(tmp); 17894acb54baSEdgar E. Iglesias } else { 17904acb54baSEdgar E. Iglesias switch(dc->is_jmp) { 17914acb54baSEdgar E. Iglesias case DISAS_NEXT: 17924acb54baSEdgar E. Iglesias gen_goto_tb(dc, 1, npc); 17934acb54baSEdgar E. Iglesias break; 17944acb54baSEdgar E. Iglesias default: 17954acb54baSEdgar E. Iglesias case DISAS_JUMP: 17964acb54baSEdgar E. Iglesias case DISAS_UPDATE: 17974acb54baSEdgar E. Iglesias /* indicate that the hash table must be used 17984acb54baSEdgar E. Iglesias to find the next TB */ 17994acb54baSEdgar E. Iglesias tcg_gen_exit_tb(0); 18004acb54baSEdgar E. Iglesias break; 18014acb54baSEdgar E. Iglesias case DISAS_TB_JUMP: 18024acb54baSEdgar E. Iglesias /* nothing more to generate */ 18034acb54baSEdgar E. Iglesias break; 18044acb54baSEdgar E. Iglesias } 18054acb54baSEdgar E. Iglesias } 1806806f352dSPeter Maydell gen_tb_end(tb, num_insns); 18070a7df5daSRichard Henderson 18084acb54baSEdgar E. Iglesias tb->size = dc->pc - pc_start; 18094acb54baSEdgar E. Iglesias tb->icount = num_insns; 18104acb54baSEdgar E. Iglesias 18114acb54baSEdgar E. Iglesias #ifdef DEBUG_DISAS 18124acb54baSEdgar E. Iglesias #if !SIM_COMPAT 18134910e6e4SRichard Henderson if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM) 18144910e6e4SRichard Henderson && qemu_log_in_addr_range(pc_start)) { 18151ee73216SRichard Henderson qemu_log_lock(); 1816f01a5e7eSRichard Henderson qemu_log("--------------\n"); 18171d48474dSRichard Henderson log_target_disas(cs, pc_start, dc->pc - pc_start); 18181ee73216SRichard Henderson qemu_log_unlock(); 18194acb54baSEdgar E. Iglesias } 18204acb54baSEdgar E. Iglesias #endif 18214acb54baSEdgar E. Iglesias #endif 18224acb54baSEdgar E. Iglesias assert(!dc->abort_at_next_insn); 18234acb54baSEdgar E. Iglesias } 18244acb54baSEdgar E. Iglesias 1825878096eeSAndreas Färber void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, 18264acb54baSEdgar E. Iglesias int flags) 18274acb54baSEdgar E. Iglesias { 1828878096eeSAndreas Färber MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs); 1829878096eeSAndreas Färber CPUMBState *env = &cpu->env; 18304acb54baSEdgar E. Iglesias int i; 18314acb54baSEdgar E. Iglesias 18324acb54baSEdgar E. Iglesias if (!env || !f) 18334acb54baSEdgar E. Iglesias return; 18344acb54baSEdgar E. Iglesias 18354acb54baSEdgar E. Iglesias cpu_fprintf(f, "IN: PC=%x %s\n", 18364acb54baSEdgar E. Iglesias env->sregs[SR_PC], lookup_symbol(env->sregs[SR_PC])); 183797694c57SEdgar E. Iglesias cpu_fprintf(f, "rmsr=%x resr=%x rear=%x debug=%x imm=%x iflags=%x fsr=%x\n", 18384c24aa0aSMichal Simek env->sregs[SR_MSR], env->sregs[SR_ESR], env->sregs[SR_EAR], 183997694c57SEdgar E. Iglesias env->debug, env->imm, env->iflags, env->sregs[SR_FSR]); 184017c52a43SEdgar E. Iglesias cpu_fprintf(f, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n", 18414acb54baSEdgar E. Iglesias env->btaken, env->btarget, 18424acb54baSEdgar E. Iglesias (env->sregs[SR_MSR] & MSR_UM) ? "user" : "kernel", 184317c52a43SEdgar E. Iglesias (env->sregs[SR_MSR] & MSR_UMS) ? "user" : "kernel", 184417c52a43SEdgar E. Iglesias (env->sregs[SR_MSR] & MSR_EIP), 184517c52a43SEdgar E. Iglesias (env->sregs[SR_MSR] & MSR_IE)); 184617c52a43SEdgar E. Iglesias 18474acb54baSEdgar E. Iglesias for (i = 0; i < 32; i++) { 18484acb54baSEdgar E. Iglesias cpu_fprintf(f, "r%2.2d=%8.8x ", i, env->regs[i]); 18494acb54baSEdgar E. Iglesias if ((i + 1) % 4 == 0) 18504acb54baSEdgar E. Iglesias cpu_fprintf(f, "\n"); 18514acb54baSEdgar E. Iglesias } 18524acb54baSEdgar E. Iglesias cpu_fprintf(f, "\n\n"); 18534acb54baSEdgar E. Iglesias } 18544acb54baSEdgar E. Iglesias 1855cd0c24f9SAndreas Färber void mb_tcg_init(void) 1856cd0c24f9SAndreas Färber { 1857cd0c24f9SAndreas Färber int i; 18584acb54baSEdgar E. Iglesias 1859*cfeea807SEdgar E. Iglesias env_debug = tcg_global_mem_new_i32(cpu_env, 186068cee38aSAndreas Färber offsetof(CPUMBState, debug), 18614acb54baSEdgar E. Iglesias "debug0"); 1862*cfeea807SEdgar E. Iglesias env_iflags = tcg_global_mem_new_i32(cpu_env, 186368cee38aSAndreas Färber offsetof(CPUMBState, iflags), 18644acb54baSEdgar E. Iglesias "iflags"); 1865*cfeea807SEdgar E. Iglesias env_imm = tcg_global_mem_new_i32(cpu_env, 186668cee38aSAndreas Färber offsetof(CPUMBState, imm), 18674acb54baSEdgar E. Iglesias "imm"); 1868*cfeea807SEdgar E. Iglesias env_btarget = tcg_global_mem_new_i32(cpu_env, 186968cee38aSAndreas Färber offsetof(CPUMBState, btarget), 18704acb54baSEdgar E. Iglesias "btarget"); 1871*cfeea807SEdgar E. Iglesias env_btaken = tcg_global_mem_new_i32(cpu_env, 187268cee38aSAndreas Färber offsetof(CPUMBState, btaken), 18734acb54baSEdgar E. Iglesias "btaken"); 1874*cfeea807SEdgar E. Iglesias env_res_addr = tcg_global_mem_new_i32(cpu_env, 18754a536270SEdgar E. Iglesias offsetof(CPUMBState, res_addr), 18764a536270SEdgar E. Iglesias "res_addr"); 1877*cfeea807SEdgar E. Iglesias env_res_val = tcg_global_mem_new_i32(cpu_env, 187811a76217SEdgar E. Iglesias offsetof(CPUMBState, res_val), 187911a76217SEdgar E. Iglesias "res_val"); 18804acb54baSEdgar E. Iglesias for (i = 0; i < ARRAY_SIZE(cpu_R); i++) { 1881*cfeea807SEdgar E. Iglesias cpu_R[i] = tcg_global_mem_new_i32(cpu_env, 188268cee38aSAndreas Färber offsetof(CPUMBState, regs[i]), 18834acb54baSEdgar E. Iglesias regnames[i]); 18844acb54baSEdgar E. Iglesias } 18854acb54baSEdgar E. Iglesias for (i = 0; i < ARRAY_SIZE(cpu_SR); i++) { 1886*cfeea807SEdgar E. Iglesias cpu_SR[i] = tcg_global_mem_new_i32(cpu_env, 188768cee38aSAndreas Färber offsetof(CPUMBState, sregs[i]), 18884acb54baSEdgar E. Iglesias special_regnames[i]); 18894acb54baSEdgar E. Iglesias } 18904acb54baSEdgar E. Iglesias } 18914acb54baSEdgar E. Iglesias 1892bad729e2SRichard Henderson void restore_state_to_opc(CPUMBState *env, TranslationBlock *tb, 1893bad729e2SRichard Henderson target_ulong *data) 18944acb54baSEdgar E. Iglesias { 1895bad729e2SRichard Henderson env->sregs[SR_PC] = data[0]; 18964acb54baSEdgar E. Iglesias } 1897