2009-05-20 21:37:39 +04:00
|
|
|
/*
|
|
|
|
* Xilinx MicroBlaze emulation for qemu: main translation routines.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 Edgar E. Iglesias.
|
2012-04-12 08:30:30 +04:00
|
|
|
* Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
|
2009-05-20 21:37:39 +04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-07-17 00:47:01 +04:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2009-05-20 21:37:39 +04:00
|
|
|
*/
|
|
|
|
|
2016-01-26 21:05:31 +03:00
|
|
|
#include "qemu/osdep.h"
|
2009-05-20 21:37:39 +04:00
|
|
|
#include "cpu.h"
|
2012-10-24 13:12:21 +04:00
|
|
|
#include "disas/disas.h"
|
2016-03-15 15:18:37 +03:00
|
|
|
#include "exec/exec-all.h"
|
2009-05-20 21:37:39 +04:00
|
|
|
#include "tcg-op.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-proto.h"
|
2009-05-20 21:37:39 +04:00
|
|
|
#include "microblaze-decode.h"
|
2014-03-28 22:42:10 +04:00
|
|
|
#include "exec/cpu_ldst.h"
|
2014-04-08 09:31:41 +04:00
|
|
|
#include "exec/helper-gen.h"
|
2017-07-14 11:21:37 +03:00
|
|
|
#include "exec/translator.h"
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2014-05-30 16:12:25 +04:00
|
|
|
#include "trace-tcg.h"
|
2016-01-07 16:55:28 +03:00
|
|
|
#include "exec/log.h"
|
2014-05-30 16:12:25 +04:00
|
|
|
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
#define SIM_COMPAT 0
|
|
|
|
#define DISAS_GNU 1
|
|
|
|
#define DISAS_MB 1
|
|
|
|
#if DISAS_MB && !SIM_COMPAT
|
|
|
|
# define LOG_DIS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
# define LOG_DIS(...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define D(x)
|
|
|
|
|
|
|
|
#define EXTRACT_FIELD(src, start, end) \
|
|
|
|
(((src) >> start) & ((1 << (end - start + 1)) - 1))
|
|
|
|
|
2017-07-14 11:21:37 +03:00
|
|
|
/* is_jmp field values */
|
|
|
|
#define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
|
|
|
|
#define DISAS_UPDATE DISAS_TARGET_1 /* cpu state was modified dynamically */
|
|
|
|
#define DISAS_TB_JUMP DISAS_TARGET_2 /* only pc was modified statically */
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
static TCGv_i32 env_debug;
|
|
|
|
static TCGv_i32 cpu_R[32];
|
2018-04-14 18:59:29 +03:00
|
|
|
static TCGv_i64 cpu_SR[14];
|
2018-04-05 20:09:30 +03:00
|
|
|
static TCGv_i32 env_imm;
|
|
|
|
static TCGv_i32 env_btaken;
|
|
|
|
static TCGv_i32 env_btarget;
|
|
|
|
static TCGv_i32 env_iflags;
|
2018-04-13 21:20:25 +03:00
|
|
|
static TCGv env_res_addr;
|
2018-04-05 20:09:30 +03:00
|
|
|
static TCGv_i32 env_res_val;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/gen-icount.h"
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
/* This is the state at translation time. */
|
|
|
|
typedef struct DisasContext {
|
2013-09-03 22:02:48 +04:00
|
|
|
MicroBlazeCPU *cpu;
|
2018-04-05 20:09:30 +03:00
|
|
|
uint32_t pc;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
/* Decoder. */
|
|
|
|
int type_b;
|
|
|
|
uint32_t ir;
|
|
|
|
uint8_t opcode;
|
|
|
|
uint8_t rd, ra, rb;
|
|
|
|
uint16_t imm;
|
|
|
|
|
|
|
|
unsigned int cpustate_changed;
|
|
|
|
unsigned int delayed_branch;
|
|
|
|
unsigned int tb_flags, synced_flags; /* tb dependent flags. */
|
|
|
|
unsigned int clear_imm;
|
|
|
|
int is_jmp;
|
|
|
|
|
2011-01-14 14:30:26 +03:00
|
|
|
#define JMP_NOJMP 0
|
|
|
|
#define JMP_DIRECT 1
|
|
|
|
#define JMP_DIRECT_CC 2
|
|
|
|
#define JMP_INDIRECT 3
|
2009-05-20 21:37:39 +04:00
|
|
|
unsigned int jmp;
|
|
|
|
uint32_t jmp_pc;
|
|
|
|
|
|
|
|
int abort_at_next_insn;
|
|
|
|
int nr_nops;
|
|
|
|
struct TranslationBlock *tb;
|
|
|
|
int singlestep_enabled;
|
|
|
|
} DisasContext;
|
|
|
|
|
2009-09-23 03:19:02 +04:00
|
|
|
static const char *regnames[] =
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
|
|
|
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
|
|
|
|
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
|
|
|
|
"r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
|
|
|
|
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
|
|
|
|
};
|
|
|
|
|
2009-09-23 03:19:02 +04:00
|
|
|
static const char *special_regnames[] =
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2018-04-14 15:03:06 +03:00
|
|
|
"rpc", "rmsr", "sr2", "rear", "sr4", "resr", "sr6", "rfsr",
|
|
|
|
"sr8", "sr9", "sr10", "rbtr", "sr12", "redr"
|
2009-05-20 21:37:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void t_sync_flags(DisasContext *dc)
|
|
|
|
{
|
2011-11-22 14:06:21 +04:00
|
|
|
/* Synch the tb dependent flags between translator and runtime. */
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->tb_flags != dc->synced_flags) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_iflags, dc->tb_flags);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->synced_flags = dc->tb_flags;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void t_gen_raise_exception(DisasContext *dc, uint32_t index)
|
|
|
|
{
|
|
|
|
TCGv_i32 tmp = tcg_const_i32(index);
|
|
|
|
|
|
|
|
t_sync_flags(dc);
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc);
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_raise_exception(cpu_env, tmp);
|
2009-05-20 21:37:39 +04:00
|
|
|
tcg_temp_free_i32(tmp);
|
|
|
|
dc->is_jmp = DISAS_UPDATE;
|
|
|
|
}
|
|
|
|
|
2016-04-09 01:00:23 +03:00
|
|
|
static inline bool use_goto_tb(DisasContext *dc, target_ulong dest)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_USER_ONLY
|
|
|
|
return (dc->tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK);
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest)
|
|
|
|
{
|
2016-04-09 01:00:23 +03:00
|
|
|
if (use_goto_tb(dc, dest)) {
|
2009-05-20 21:37:39 +04:00
|
|
|
tcg_gen_goto_tb(n);
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dest);
|
2016-04-09 01:00:23 +03:00
|
|
|
tcg_gen_exit_tb((uintptr_t)dc->tb + n);
|
2009-05-20 21:37:39 +04:00
|
|
|
} else {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dest);
|
2009-05-20 21:37:39 +04:00
|
|
|
tcg_gen_exit_tb(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
static void read_carry(DisasContext *dc, TCGv_i32 d)
|
2011-01-22 13:57:19 +03:00
|
|
|
{
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(d, cpu_SR[SR_MSR]);
|
|
|
|
tcg_gen_shri_i32(d, d, 31);
|
2011-01-22 13:57:19 +03:00
|
|
|
}
|
|
|
|
|
2013-10-25 00:31:22 +04:00
|
|
|
/*
|
|
|
|
* write_carry sets the carry bits in MSR based on bit 0 of v.
|
|
|
|
* v[31:1] are ignored.
|
|
|
|
*/
|
2018-04-05 20:09:30 +03:00
|
|
|
static void write_carry(DisasContext *dc, TCGv_i32 v)
|
2011-01-22 13:57:19 +03:00
|
|
|
{
|
2018-04-14 18:59:29 +03:00
|
|
|
TCGv_i64 t0 = tcg_temp_new_i64();
|
|
|
|
tcg_gen_extu_i32_i64(t0, v);
|
|
|
|
/* Deposit bit 0 into MSR_C and the alias MSR_CC. */
|
|
|
|
tcg_gen_deposit_i64(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t0, 2, 1);
|
|
|
|
tcg_gen_deposit_i64(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t0, 31, 1);
|
|
|
|
tcg_temp_free_i64(t0);
|
2011-01-22 13:57:19 +03:00
|
|
|
}
|
|
|
|
|
2013-10-24 14:49:05 +04:00
|
|
|
static void write_carryi(DisasContext *dc, bool carry)
|
2012-06-01 07:23:28 +04:00
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0 = tcg_temp_new_i32();
|
|
|
|
tcg_gen_movi_i32(t0, carry);
|
2012-06-01 07:23:28 +04:00
|
|
|
write_carry(dc, t0);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t0);
|
2012-06-01 07:23:28 +04:00
|
|
|
}
|
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the insn an illegal operation.
|
|
|
|
* If exceptions are enabled, an exception is raised.
|
|
|
|
*/
|
|
|
|
static bool trap_illegal(DisasContext *dc, bool cond)
|
|
|
|
{
|
|
|
|
if (cond && (dc->tb_flags & MSR_EE_FLAG)
|
|
|
|
&& (dc->cpu->env.pvr.regs[2] & PVR2_ILL_OPCODE_EXC_MASK)) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_ESR], ESR_EC_ILLEGAL_OP);
|
2018-04-14 19:41:24 +03:00
|
|
|
t_gen_raise_exception(dc, EXCP_HW_EXCP);
|
|
|
|
}
|
|
|
|
return cond;
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:02:41 +03:00
|
|
|
/*
|
|
|
|
* Returns true if the insn is illegal in userspace.
|
|
|
|
* If exceptions are enabled, an exception is raised.
|
|
|
|
*/
|
|
|
|
static bool trap_userspace(DisasContext *dc, bool cond)
|
|
|
|
{
|
|
|
|
int mem_index = cpu_mmu_index(&dc->cpu->env, false);
|
|
|
|
bool cond_user = cond && mem_index == MMU_USER_IDX;
|
|
|
|
|
|
|
|
if (cond_user && (dc->tb_flags & MSR_EE_FLAG)) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_ESR], ESR_EC_PRIVINSN);
|
2018-04-14 00:02:41 +03:00
|
|
|
t_gen_raise_exception(dc, EXCP_HW_EXCP);
|
|
|
|
}
|
|
|
|
return cond_user;
|
|
|
|
}
|
|
|
|
|
2010-07-24 23:24:59 +04:00
|
|
|
/* True if ALU operand b is a small immediate that may deserve
|
|
|
|
faster treatment. */
|
|
|
|
static inline int dec_alu_op_b_is_small_imm(DisasContext *dc)
|
|
|
|
{
|
|
|
|
/* Immediate insn without the imm prefix ? */
|
|
|
|
return dc->type_b && !(dc->tb_flags & IMM_FLAG);
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
static inline TCGv_i32 *dec_alu_op_b(DisasContext *dc)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
|
|
|
if (dc->type_b) {
|
|
|
|
if (dc->tb_flags & IMM_FLAG)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_ori_i32(env_imm, env_imm, dc->imm);
|
2009-05-20 21:37:39 +04:00
|
|
|
else
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_imm, (int32_t)((int16_t)dc->imm));
|
2009-05-20 21:37:39 +04:00
|
|
|
return &env_imm;
|
|
|
|
} else
|
|
|
|
return &cpu_R[dc->rb];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_add(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int k, c;
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 cf;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
k = dc->opcode & 4;
|
|
|
|
c = dc->opcode & 2;
|
|
|
|
|
|
|
|
LOG_DIS("add%s%s%s r%d r%d r%d\n",
|
|
|
|
dc->type_b ? "i" : "", k ? "k" : "", c ? "c" : "",
|
|
|
|
dc->rd, dc->ra, dc->rb);
|
|
|
|
|
2011-01-22 14:02:53 +03:00
|
|
|
/* Take care of the easy cases first. */
|
|
|
|
if (k) {
|
|
|
|
/* k - keep carry, no need to update MSR. */
|
|
|
|
/* If rd == r0, it's a nop. */
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2011-01-22 14:02:53 +03:00
|
|
|
|
|
|
|
if (c) {
|
|
|
|
/* c - Add carry into the result. */
|
2018-04-05 20:09:30 +03:00
|
|
|
cf = tcg_temp_new_i32();
|
2011-01-22 14:02:53 +03:00
|
|
|
|
|
|
|
read_carry(dc, cf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf);
|
|
|
|
tcg_temp_free_i32(cf);
|
2011-01-22 14:02:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From now on, we can assume k is zero. So we need to update MSR. */
|
|
|
|
/* Extract carry. */
|
2018-04-05 20:09:30 +03:00
|
|
|
cf = tcg_temp_new_i32();
|
2011-01-22 14:02:53 +03:00
|
|
|
if (c) {
|
|
|
|
read_carry(dc, cf);
|
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cf, 0);
|
2011-01-22 14:02:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 ncf = tcg_temp_new_i32();
|
2011-01-23 05:52:20 +03:00
|
|
|
gen_helper_carry(ncf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf);
|
2011-01-22 14:02:53 +03:00
|
|
|
write_carry(dc, ncf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(ncf);
|
2011-01-22 14:02:53 +03:00
|
|
|
} else {
|
2011-01-23 05:52:20 +03:00
|
|
|
gen_helper_carry(cf, cpu_R[dc->ra], *(dec_alu_op_b(dc)), cf);
|
2011-01-22 14:02:53 +03:00
|
|
|
write_carry(dc, cf);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(cf);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_sub(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int u, cmp, k, c;
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 cf, na;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
u = dc->imm & 2;
|
|
|
|
k = dc->opcode & 4;
|
|
|
|
c = dc->opcode & 2;
|
|
|
|
cmp = (dc->imm & 1) && (!dc->type_b) && k;
|
|
|
|
|
|
|
|
if (cmp) {
|
|
|
|
LOG_DIS("cmp%s r%d, r%d ir=%x\n", u ? "u" : "", dc->rd, dc->ra, dc->ir);
|
|
|
|
if (dc->rd) {
|
|
|
|
if (u)
|
|
|
|
gen_helper_cmpu(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
else
|
|
|
|
gen_helper_cmp(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
}
|
2011-01-22 14:39:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DIS("sub%s%s r%d, r%d r%d\n",
|
|
|
|
k ? "k" : "", c ? "c" : "", dc->rd, dc->ra, dc->rb);
|
|
|
|
|
|
|
|
/* Take care of the easy cases first. */
|
|
|
|
if (k) {
|
|
|
|
/* k - keep carry, no need to update MSR. */
|
|
|
|
/* If rd == r0, it's a nop. */
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_sub_i32(cpu_R[dc->rd], *(dec_alu_op_b(dc)), cpu_R[dc->ra]);
|
2011-01-22 14:39:16 +03:00
|
|
|
|
|
|
|
if (c) {
|
|
|
|
/* c - Add carry into the result. */
|
2018-04-05 20:09:30 +03:00
|
|
|
cf = tcg_temp_new_i32();
|
2011-01-22 14:39:16 +03:00
|
|
|
|
|
|
|
read_carry(dc, cf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf);
|
|
|
|
tcg_temp_free_i32(cf);
|
2011-01-22 14:39:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From now on, we can assume k is zero. So we need to update MSR. */
|
|
|
|
/* Extract carry. And complement a into na. */
|
2018-04-05 20:09:30 +03:00
|
|
|
cf = tcg_temp_new_i32();
|
|
|
|
na = tcg_temp_new_i32();
|
2011-01-22 14:39:16 +03:00
|
|
|
if (c) {
|
|
|
|
read_carry(dc, cf);
|
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cf, 1);
|
2011-01-22 14:39:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* d = b + ~a + c. carry defaults to 1. */
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_not_i32(na, cpu_R[dc->ra]);
|
2011-01-22 14:39:16 +03:00
|
|
|
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 ncf = tcg_temp_new_i32();
|
2011-01-23 05:52:20 +03:00
|
|
|
gen_helper_carry(ncf, na, *(dec_alu_op_b(dc)), cf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], na, *(dec_alu_op_b(dc)));
|
|
|
|
tcg_gen_add_i32(cpu_R[dc->rd], cpu_R[dc->rd], cf);
|
2011-01-22 14:39:16 +03:00
|
|
|
write_carry(dc, ncf);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(ncf);
|
2011-01-22 14:39:16 +03:00
|
|
|
} else {
|
2011-01-23 05:52:20 +03:00
|
|
|
gen_helper_carry(cf, na, *(dec_alu_op_b(dc)), cf);
|
2011-01-22 14:39:16 +03:00
|
|
|
write_carry(dc, cf);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(cf);
|
|
|
|
tcg_temp_free_i32(na);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_pattern(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int mode;
|
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_pcmp_instr)) {
|
|
|
|
return;
|
2009-09-03 13:12:30 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
mode = dc->opcode & 3;
|
|
|
|
switch (mode) {
|
|
|
|
case 0:
|
|
|
|
/* pcmpbf. */
|
|
|
|
LOG_DIS("pcmpbf r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
|
|
|
if (dc->rd)
|
|
|
|
gen_helper_pcmpbf(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
LOG_DIS("pcmpeq r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_EQ, cpu_R[dc->rd],
|
2015-09-03 00:46:01 +03:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
LOG_DIS("pcmpne r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_setcond_i32(TCG_COND_NE, cpu_R[dc->rd],
|
2015-09-03 00:46:01 +03:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu),
|
2009-05-20 21:37:39 +04:00
|
|
|
"unsupported pattern insn opcode=%x\n", dc->opcode);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_and(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int not;
|
|
|
|
|
|
|
|
if (!dc->type_b && (dc->imm & (1 << 10))) {
|
|
|
|
dec_pattern(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
not = dc->opcode & (1 << 1);
|
|
|
|
LOG_DIS("and%s\n", not ? "n" : "");
|
|
|
|
|
|
|
|
if (!dc->rd)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (not) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_andc_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
} else
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_and_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_or(DisasContext *dc)
|
|
|
|
{
|
|
|
|
if (!dc->type_b && (dc->imm & (1 << 10))) {
|
|
|
|
dec_pattern(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DIS("or r%d r%d r%d imm=%x\n", dc->rd, dc->ra, dc->rb, dc->imm);
|
|
|
|
if (dc->rd)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_xor(DisasContext *dc)
|
|
|
|
{
|
|
|
|
if (!dc->type_b && (dc->imm & (1 << 10))) {
|
|
|
|
dec_pattern(dc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DIS("xor r%d\n", dc->rd);
|
|
|
|
if (dc->rd)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_xor_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
static inline void msr_read(DisasContext *dc, TCGv_i32 d)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(d, cpu_SR[SR_MSR]);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
static inline void msr_write(DisasContext *dc, TCGv_i32 v)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2018-04-14 18:59:29 +03:00
|
|
|
TCGv_i64 t;
|
2011-08-25 10:41:18 +04:00
|
|
|
|
2018-04-14 18:59:29 +03:00
|
|
|
t = tcg_temp_new_i64();
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->cpustate_changed = 1;
|
2011-08-25 10:41:18 +04:00
|
|
|
/* PVR bit is not writable. */
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extu_i32_i64(t, v);
|
|
|
|
tcg_gen_andi_i64(t, t, ~MSR_PVR);
|
|
|
|
tcg_gen_andi_i64(cpu_SR[SR_MSR], cpu_SR[SR_MSR], MSR_PVR);
|
|
|
|
tcg_gen_or_i64(cpu_SR[SR_MSR], cpu_SR[SR_MSR], t);
|
|
|
|
tcg_temp_free_i64(t);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_msr(DisasContext *dc)
|
|
|
|
{
|
2013-09-03 22:02:48 +04:00
|
|
|
CPUState *cs = CPU(dc->cpu);
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0, t1;
|
2018-04-14 16:17:52 +03:00
|
|
|
unsigned int sr, rn;
|
2018-04-16 22:25:01 +03:00
|
|
|
bool to, clrset, extended = false;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-14 16:17:52 +03:00
|
|
|
sr = extract32(dc->imm, 0, 14);
|
|
|
|
to = extract32(dc->imm, 14, 1);
|
|
|
|
clrset = extract32(dc->imm, 15, 1) == 0;
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->type_b = 1;
|
2018-04-14 16:17:52 +03:00
|
|
|
if (to) {
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->cpustate_changed = 1;
|
2018-04-16 22:25:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Extended MSRs are only available if addr_size > 32. */
|
|
|
|
if (dc->cpu->cfg.addr_size > 32) {
|
|
|
|
/* The E-bit is encoded differently for To/From MSR. */
|
|
|
|
static const unsigned int e_bit[] = { 19, 24 };
|
|
|
|
|
|
|
|
extended = extract32(dc->imm, e_bit[to], 1);
|
2018-04-14 16:17:52 +03:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
/* msrclr and msrset. */
|
2018-04-14 16:17:52 +03:00
|
|
|
if (clrset) {
|
|
|
|
bool clr = extract32(dc->ir, 16, 1);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
LOG_DIS("msr%s r%d imm=%x\n", clr ? "clr" : "set",
|
|
|
|
dc->rd, dc->imm);
|
2009-09-03 13:12:30 +04:00
|
|
|
|
2017-06-20 14:13:26 +03:00
|
|
|
if (!dc->cpu->cfg.use_msr_instr) {
|
2009-09-03 13:12:30 +04:00
|
|
|
/* nop??? */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:02:41 +03:00
|
|
|
if (trap_userspace(dc, dc->imm != 4 && dc->imm != 0)) {
|
2009-09-03 13:12:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->rd)
|
|
|
|
msr_read(dc, cpu_R[dc->rd]);
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
t0 = tcg_temp_new_i32();
|
|
|
|
t1 = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
msr_read(dc, t0);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mov_i32(t1, *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
if (clr) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_not_i32(t1, t1);
|
|
|
|
tcg_gen_and_i32(t0, t0, t1);
|
2009-05-20 21:37:39 +04:00
|
|
|
} else
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_or_i32(t0, t0, t1);
|
2009-05-20 21:37:39 +04:00
|
|
|
msr_write(dc, t0);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t0);
|
|
|
|
tcg_temp_free_i32(t1);
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc + 4);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->is_jmp = DISAS_UPDATE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-14 00:02:41 +03:00
|
|
|
if (trap_userspace(dc, to)) {
|
|
|
|
return;
|
2009-09-03 13:12:30 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
#if !defined(CONFIG_USER_ONLY)
|
|
|
|
/* Catch read/writes to the mmu block. */
|
|
|
|
if ((sr & ~0xff) == 0x1000) {
|
2018-04-16 22:25:01 +03:00
|
|
|
TCGv_i32 tmp_ext = tcg_const_i32(extended);
|
2018-05-16 01:04:54 +03:00
|
|
|
TCGv_i32 tmp_sr;
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
sr &= 7;
|
2018-05-16 01:04:54 +03:00
|
|
|
tmp_sr = tcg_const_i32(sr);
|
2009-05-20 21:37:39 +04:00
|
|
|
LOG_DIS("m%ss sr%d r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm);
|
2018-05-16 01:04:54 +03:00
|
|
|
if (to) {
|
2018-04-16 22:25:01 +03:00
|
|
|
gen_helper_mmu_write(cpu_env, tmp_ext, tmp_sr, cpu_R[dc->ra]);
|
2018-05-16 01:04:54 +03:00
|
|
|
} else {
|
2018-04-16 22:25:01 +03:00
|
|
|
gen_helper_mmu_read(cpu_R[dc->rd], cpu_env, tmp_ext, tmp_sr);
|
2018-05-16 01:04:54 +03:00
|
|
|
}
|
|
|
|
tcg_temp_free_i32(tmp_sr);
|
2018-04-16 22:25:01 +03:00
|
|
|
tcg_temp_free_i32(tmp_ext);
|
2009-05-20 21:37:39 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (to) {
|
|
|
|
LOG_DIS("m%ss sr%x r%d imm=%x\n", to ? "t" : "f", sr, dc->ra, dc->imm);
|
|
|
|
switch (sr) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
msr_write(dc, cpu_R[dc->ra]);
|
|
|
|
break;
|
2018-04-14 16:46:20 +03:00
|
|
|
case SR_EAR:
|
|
|
|
case SR_ESR:
|
2018-04-14 18:42:24 +03:00
|
|
|
case SR_FSR:
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extu_i32_i64(cpu_SR[sr], cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
2012-01-10 13:27:11 +04:00
|
|
|
case 0x800:
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_st_i32(cpu_R[dc->ra],
|
|
|
|
cpu_env, offsetof(CPUMBState, slr));
|
2012-01-10 13:27:11 +04:00
|
|
|
break;
|
|
|
|
case 0x802:
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_st_i32(cpu_R[dc->ra],
|
|
|
|
cpu_env, offsetof(CPUMBState, shr));
|
2012-01-10 13:27:11 +04:00
|
|
|
break;
|
2009-05-20 21:37:39 +04:00
|
|
|
default:
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu), "unknown mts reg %x\n", sr);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOG_DIS("m%ss r%d sr%x imm=%x\n", to ? "t" : "f", dc->rd, sr, dc->imm);
|
|
|
|
|
|
|
|
switch (sr) {
|
|
|
|
case 0:
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cpu_R[dc->rd], dc->pc);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
msr_read(dc, cpu_R[dc->rd]);
|
|
|
|
break;
|
2018-04-14 16:46:20 +03:00
|
|
|
case SR_EAR:
|
2018-04-15 00:44:51 +03:00
|
|
|
if (extended) {
|
|
|
|
tcg_gen_extrh_i64_i32(cpu_R[dc->rd], cpu_SR[sr]);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-14 16:46:20 +03:00
|
|
|
case SR_ESR:
|
|
|
|
case SR_FSR:
|
|
|
|
case SR_BTR:
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(cpu_R[dc->rd], cpu_SR[sr]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
2012-01-10 13:27:11 +04:00
|
|
|
case 0x800:
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_ld_i32(cpu_R[dc->rd],
|
|
|
|
cpu_env, offsetof(CPUMBState, slr));
|
2012-01-10 13:27:11 +04:00
|
|
|
break;
|
|
|
|
case 0x802:
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_ld_i32(cpu_R[dc->rd],
|
|
|
|
cpu_env, offsetof(CPUMBState, shr));
|
2012-01-10 13:27:11 +04:00
|
|
|
break;
|
2018-04-14 16:46:20 +03:00
|
|
|
case 0x2000 ... 0x200c:
|
2009-05-20 21:37:39 +04:00
|
|
|
rn = sr & 0xf;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_ld_i32(cpu_R[dc->rd],
|
2012-03-14 04:38:22 +04:00
|
|
|
cpu_env, offsetof(CPUMBState, pvr.regs[rn]));
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 19:38:47 +04:00
|
|
|
cpu_abort(cs, "unknown mfs reg %x\n", sr);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-03 13:18:55 +04:00
|
|
|
|
|
|
|
if (dc->rd == 0) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cpu_R[0], 0);
|
2009-09-03 13:18:55 +04:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Multiplier unit. */
|
|
|
|
static void dec_mul(DisasContext *dc)
|
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 tmp;
|
2009-05-20 21:37:39 +04:00
|
|
|
unsigned int subcode;
|
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_hw_mul)) {
|
2009-09-03 13:12:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
subcode = dc->imm & 3;
|
|
|
|
|
|
|
|
if (dc->type_b) {
|
|
|
|
LOG_DIS("muli r%d r%d %x\n", dc->rd, dc->ra, dc->imm);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2016-09-28 00:23:53 +03:00
|
|
|
return;
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 13:12:30 +04:00
|
|
|
/* mulh, mulhsu and mulhu are not available if C_USE_HW_MUL is < 2. */
|
2017-06-20 14:06:44 +03:00
|
|
|
if (subcode >= 1 && subcode <= 3 && dc->cpu->cfg.use_hw_mul < 2) {
|
2009-09-03 13:12:30 +04:00
|
|
|
/* nop??? */
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
tmp = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
switch (subcode) {
|
|
|
|
case 0:
|
|
|
|
LOG_DIS("mul r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mul_i32(cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
LOG_DIS("mulh r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_muls2_i32(tmp, cpu_R[dc->rd],
|
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
LOG_DIS("mulhsu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mulsu2_i32(tmp, cpu_R[dc->rd],
|
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
LOG_DIS("mulhu r%d r%d r%d\n", dc->rd, dc->ra, dc->rb);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mulu2_i32(tmp, cpu_R[dc->rd], cpu_R[dc->ra], cpu_R[dc->rb]);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu), "unknown MUL insn %x\n", subcode);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(tmp);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Div unit. */
|
|
|
|
static void dec_div(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int u;
|
|
|
|
|
|
|
|
u = dc->imm & 2;
|
|
|
|
LOG_DIS("div\n");
|
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_div)) {
|
|
|
|
return;
|
2009-09-03 13:12:30 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
if (u)
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_divu(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)),
|
|
|
|
cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
else
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_divs(cpu_R[dc->rd], cpu_env, *(dec_alu_op_b(dc)),
|
|
|
|
cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
if (!dc->rd)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cpu_R[dc->rd], 0);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_barrel(DisasContext *dc)
|
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0;
|
2016-08-10 12:57:59 +03:00
|
|
|
unsigned int imm_w, imm_s;
|
2017-06-15 17:28:35 +03:00
|
|
|
bool s, t, e = false, i = false;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_barrel)) {
|
2009-09-03 13:12:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-10 12:57:59 +03:00
|
|
|
if (dc->type_b) {
|
|
|
|
/* Insert and extract are only available in immediate mode. */
|
2017-06-15 17:28:35 +03:00
|
|
|
i = extract32(dc->imm, 15, 1);
|
2016-08-10 12:57:59 +03:00
|
|
|
e = extract32(dc->imm, 14, 1);
|
|
|
|
}
|
2016-08-09 15:59:35 +03:00
|
|
|
s = extract32(dc->imm, 10, 1);
|
|
|
|
t = extract32(dc->imm, 9, 1);
|
2016-08-10 12:57:59 +03:00
|
|
|
imm_w = extract32(dc->imm, 6, 5);
|
|
|
|
imm_s = extract32(dc->imm, 0, 5);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2016-08-10 12:57:59 +03:00
|
|
|
LOG_DIS("bs%s%s%s r%d r%d r%d\n",
|
|
|
|
e ? "e" : "",
|
2009-05-20 21:37:39 +04:00
|
|
|
s ? "l" : "r", t ? "a" : "l", dc->rd, dc->ra, dc->rb);
|
|
|
|
|
2016-08-10 12:57:59 +03:00
|
|
|
if (e) {
|
|
|
|
if (imm_w + imm_s > 32 || imm_w == 0) {
|
|
|
|
/* These inputs have an undefined behavior. */
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "bsefi: Bad input w=%d s=%d\n",
|
|
|
|
imm_w, imm_s);
|
|
|
|
} else {
|
|
|
|
tcg_gen_extract_i32(cpu_R[dc->rd], cpu_R[dc->ra], imm_s, imm_w);
|
|
|
|
}
|
2017-06-15 17:28:35 +03:00
|
|
|
} else if (i) {
|
|
|
|
int width = imm_w - imm_s + 1;
|
|
|
|
|
|
|
|
if (imm_w < imm_s) {
|
|
|
|
/* These inputs have an undefined behavior. */
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "bsifi: Bad input w=%d s=%d\n",
|
|
|
|
imm_w, imm_s);
|
|
|
|
} else {
|
|
|
|
tcg_gen_deposit_i32(cpu_R[dc->rd], cpu_R[dc->rd], cpu_R[dc->ra],
|
|
|
|
imm_s, width);
|
|
|
|
}
|
2016-08-10 12:57:59 +03:00
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
t0 = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mov_i32(t0, *(dec_alu_op_b(dc)));
|
|
|
|
tcg_gen_andi_i32(t0, t0, 31);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2016-08-10 12:57:59 +03:00
|
|
|
if (s) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_shl_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0);
|
2016-08-09 16:45:36 +03:00
|
|
|
} else {
|
2016-08-10 12:57:59 +03:00
|
|
|
if (t) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_sar_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0);
|
2016-08-10 12:57:59 +03:00
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_shr_i32(cpu_R[dc->rd], cpu_R[dc->ra], t0);
|
2016-08-10 12:57:59 +03:00
|
|
|
}
|
2016-08-09 16:45:36 +03:00
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_bit(DisasContext *dc)
|
|
|
|
{
|
2013-09-03 22:02:48 +04:00
|
|
|
CPUState *cs = CPU(dc->cpu);
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0;
|
2009-05-20 21:37:39 +04:00
|
|
|
unsigned int op;
|
|
|
|
|
2012-05-17 09:37:49 +04:00
|
|
|
op = dc->ir & ((1 << 9) - 1);
|
2009-05-20 21:37:39 +04:00
|
|
|
switch (op) {
|
|
|
|
case 0x21:
|
|
|
|
/* src. */
|
2018-04-05 20:09:30 +03:00
|
|
|
t0 = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
LOG_DIS("src r%d r%d\n", dc->rd, dc->ra);
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(t0, cpu_SR[SR_MSR]);
|
|
|
|
tcg_gen_andi_i32(t0, t0, MSR_CC);
|
2013-10-24 21:18:28 +04:00
|
|
|
write_carry(dc, cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1);
|
|
|
|
tcg_gen_or_i32(cpu_R[dc->rd], cpu_R[dc->rd], t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x1:
|
|
|
|
case 0x41:
|
|
|
|
/* srl. */
|
|
|
|
LOG_DIS("srl r%d r%d\n", dc->rd, dc->ra);
|
|
|
|
|
2013-10-24 21:03:44 +04:00
|
|
|
/* Update carry. Note that write carry only looks at the LSB. */
|
|
|
|
write_carry(dc, cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->rd) {
|
|
|
|
if (op == 0x41)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_shri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1);
|
2009-05-20 21:37:39 +04:00
|
|
|
else
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_sari_i32(cpu_R[dc->rd], cpu_R[dc->ra], 1);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x60:
|
|
|
|
LOG_DIS("ext8s r%d r%d\n", dc->rd, dc->ra);
|
|
|
|
tcg_gen_ext8s_i32(cpu_R[dc->rd], cpu_R[dc->ra]);
|
|
|
|
break;
|
|
|
|
case 0x61:
|
|
|
|
LOG_DIS("ext16s r%d r%d\n", dc->rd, dc->ra);
|
|
|
|
tcg_gen_ext16s_i32(cpu_R[dc->rd], cpu_R[dc->ra]);
|
|
|
|
break;
|
|
|
|
case 0x64:
|
2009-12-13 11:10:08 +03:00
|
|
|
case 0x66:
|
|
|
|
case 0x74:
|
|
|
|
case 0x76:
|
2009-05-20 21:37:39 +04:00
|
|
|
/* wdc. */
|
|
|
|
LOG_DIS("wdc r%d\n", dc->ra);
|
2018-04-14 00:02:41 +03:00
|
|
|
trap_userspace(dc, true);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
case 0x68:
|
|
|
|
/* wic. */
|
|
|
|
LOG_DIS("wic r%d\n", dc->ra);
|
2018-04-14 00:02:41 +03:00
|
|
|
trap_userspace(dc, true);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
2012-01-10 13:17:21 +04:00
|
|
|
case 0xe0:
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_pcmp_instr)) {
|
|
|
|
return;
|
2012-01-10 13:17:21 +04:00
|
|
|
}
|
2017-06-20 14:53:53 +03:00
|
|
|
if (dc->cpu->cfg.use_pcmp_instr) {
|
2016-11-16 12:58:52 +03:00
|
|
|
tcg_gen_clzi_i32(cpu_R[dc->rd], cpu_R[dc->ra], 32);
|
2012-01-10 13:17:21 +04:00
|
|
|
}
|
|
|
|
break;
|
2012-05-17 09:37:49 +04:00
|
|
|
case 0x1e0:
|
|
|
|
/* swapb */
|
|
|
|
LOG_DIS("swapb r%d r%d\n", dc->rd, dc->ra);
|
|
|
|
tcg_gen_bswap32_i32(cpu_R[dc->rd], cpu_R[dc->ra]);
|
|
|
|
break;
|
2012-11-08 08:01:19 +04:00
|
|
|
case 0x1e2:
|
2012-05-17 09:37:49 +04:00
|
|
|
/*swaph */
|
|
|
|
LOG_DIS("swaph r%d r%d\n", dc->rd, dc->ra);
|
|
|
|
tcg_gen_rotri_i32(cpu_R[dc->rd], cpu_R[dc->ra], 16);
|
|
|
|
break;
|
2009-05-20 21:37:39 +04:00
|
|
|
default:
|
2013-09-03 19:38:47 +04:00
|
|
|
cpu_abort(cs, "unknown bit oc=%x op=%x rd=%d ra=%d rb=%d\n",
|
|
|
|
dc->pc, op, dc->rd, dc->ra, dc->rb);
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void sync_jmpstate(DisasContext *dc)
|
|
|
|
{
|
2011-01-14 14:30:26 +03:00
|
|
|
if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) {
|
|
|
|
if (dc->jmp == JMP_DIRECT) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btaken, 1);
|
2011-01-14 14:30:26 +03:00
|
|
|
}
|
2011-01-05 04:21:19 +03:00
|
|
|
dc->jmp = JMP_INDIRECT;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btarget, dc->jmp_pc);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_imm(DisasContext *dc)
|
|
|
|
{
|
|
|
|
LOG_DIS("imm %x\n", dc->imm << 16);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_imm, (dc->imm << 16));
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->tb_flags |= IMM_FLAG;
|
|
|
|
dc->clear_imm = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:04:37 +03:00
|
|
|
static inline void compute_ldst_addr(DisasContext *dc, bool ea, TCGv t)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2018-04-04 17:34:21 +03:00
|
|
|
bool extimm = dc->tb_flags & IMM_FLAG;
|
|
|
|
/* Should be set to true if r1 is used by loadstores. */
|
|
|
|
bool stackprot = false;
|
2018-04-13 21:20:25 +03:00
|
|
|
TCGv_i32 t32;
|
2012-01-10 13:27:11 +04:00
|
|
|
|
|
|
|
/* All load/stores use ra. */
|
2015-05-29 09:30:43 +03:00
|
|
|
if (dc->ra == 1 && dc->cpu->cfg.stackprot) {
|
2018-04-04 17:34:21 +03:00
|
|
|
stackprot = true;
|
2012-01-10 13:27:11 +04:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2011-01-20 00:48:07 +03:00
|
|
|
/* Treat the common cases first. */
|
2009-05-20 21:37:39 +04:00
|
|
|
if (!dc->type_b) {
|
2018-04-13 23:04:37 +03:00
|
|
|
if (ea) {
|
|
|
|
int addr_size = dc->cpu->cfg.addr_size;
|
|
|
|
|
|
|
|
if (addr_size == 32) {
|
|
|
|
tcg_gen_extu_i32_tl(t, cpu_R[dc->rb]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tcg_gen_concat_i32_i64(t, cpu_R[dc->rb], cpu_R[dc->ra]);
|
|
|
|
if (addr_size < 64) {
|
|
|
|
/* Mask off out of range bits. */
|
|
|
|
tcg_gen_andi_i64(t, t, MAKE_64BIT_MASK(0, addr_size));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 17:12:56 +03:00
|
|
|
/* If any of the regs is r0, set t to the value of the other reg. */
|
2010-07-25 01:25:49 +04:00
|
|
|
if (dc->ra == 0) {
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_extu_i32_tl(t, cpu_R[dc->rb]);
|
2018-04-13 17:12:56 +03:00
|
|
|
return;
|
2010-07-25 01:25:49 +04:00
|
|
|
} else if (dc->rb == 0) {
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_extu_i32_tl(t, cpu_R[dc->ra]);
|
2018-04-13 17:12:56 +03:00
|
|
|
return;
|
2010-07-25 01:25:49 +04:00
|
|
|
}
|
|
|
|
|
2015-05-29 09:30:43 +03:00
|
|
|
if (dc->rb == 1 && dc->cpu->cfg.stackprot) {
|
2018-04-04 17:34:21 +03:00
|
|
|
stackprot = true;
|
2012-01-10 13:27:11 +04:00
|
|
|
}
|
|
|
|
|
2018-04-13 21:20:25 +03:00
|
|
|
t32 = tcg_temp_new_i32();
|
|
|
|
tcg_gen_add_i32(t32, cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
tcg_gen_extu_i32_tl(t, t32);
|
|
|
|
tcg_temp_free_i32(t32);
|
2012-01-10 13:27:11 +04:00
|
|
|
|
|
|
|
if (stackprot) {
|
2018-04-13 21:02:07 +03:00
|
|
|
gen_helper_stackprot(cpu_env, t);
|
2012-01-10 13:27:11 +04:00
|
|
|
}
|
2018-04-13 17:12:56 +03:00
|
|
|
return;
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
/* Immediate. */
|
2018-04-13 21:20:25 +03:00
|
|
|
t32 = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
if (!extimm) {
|
2018-05-05 15:27:23 +03:00
|
|
|
tcg_gen_addi_i32(t32, cpu_R[dc->ra], (int16_t)dc->imm);
|
2009-05-20 21:37:39 +04:00
|
|
|
} else {
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_add_i32(t32, cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_extu_i32_tl(t, t32);
|
|
|
|
tcg_temp_free_i32(t32);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2012-01-10 13:27:11 +04:00
|
|
|
if (stackprot) {
|
2018-04-13 21:02:07 +03:00
|
|
|
gen_helper_stackprot(cpu_env, t);
|
2012-01-10 13:27:11 +04:00
|
|
|
}
|
2018-04-13 17:12:56 +03:00
|
|
|
return;
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_load(DisasContext *dc)
|
|
|
|
{
|
2018-04-13 21:20:25 +03:00
|
|
|
TCGv_i32 v;
|
|
|
|
TCGv addr;
|
2018-04-04 14:47:33 +03:00
|
|
|
unsigned int size;
|
2018-04-13 23:04:37 +03:00
|
|
|
bool rev = false, ex = false, ea = false;
|
|
|
|
int mem_index = cpu_mmu_index(&dc->cpu->env, false);
|
2013-12-11 03:40:21 +04:00
|
|
|
TCGMemOp mop;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2013-12-11 03:40:21 +04:00
|
|
|
mop = dc->opcode & 3;
|
|
|
|
size = 1 << mop;
|
2011-01-20 01:18:00 +03:00
|
|
|
if (!dc->type_b) {
|
2018-04-13 23:04:37 +03:00
|
|
|
ea = extract32(dc->ir, 7, 1);
|
2018-04-04 14:47:33 +03:00
|
|
|
rev = extract32(dc->ir, 9, 1);
|
|
|
|
ex = extract32(dc->ir, 10, 1);
|
2011-01-20 01:18:00 +03:00
|
|
|
}
|
2013-12-11 03:40:21 +04:00
|
|
|
mop |= MO_TE;
|
|
|
|
if (rev) {
|
|
|
|
mop ^= MO_BSWAP;
|
|
|
|
}
|
2011-01-20 01:18:00 +03:00
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, size > 4)) {
|
2009-09-04 12:38:59 +04:00
|
|
|
return;
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-13 23:04:37 +03:00
|
|
|
if (trap_userspace(dc, ea)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG_DIS("l%d%s%s%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "",
|
|
|
|
ex ? "x" : "",
|
|
|
|
ea ? "ea" : "");
|
2011-01-20 01:18:00 +03:00
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
t_sync_flags(dc);
|
2018-04-13 21:20:25 +03:00
|
|
|
addr = tcg_temp_new();
|
2018-04-13 23:04:37 +03:00
|
|
|
compute_ldst_addr(dc, ea, addr);
|
|
|
|
/* Extended addressing bypasses the MMU. */
|
|
|
|
mem_index = ea ? MMU_NOMMU_IDX : mem_index;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2011-01-20 01:18:00 +03:00
|
|
|
/*
|
|
|
|
* When doing reverse accesses we need to do two things.
|
|
|
|
*
|
2011-03-13 17:44:02 +03:00
|
|
|
* 1. Reverse the address wrt endianness.
|
2011-01-20 01:18:00 +03:00
|
|
|
* 2. Byteswap the data lanes on the way back into the CPU core.
|
|
|
|
*/
|
|
|
|
if (rev && size != 4) {
|
|
|
|
/* Endian reverse the address. t is addr. */
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
/* 00 -> 11
|
|
|
|
01 -> 10
|
|
|
|
10 -> 10
|
|
|
|
11 -> 00 */
|
2018-04-13 21:20:25 +03:00
|
|
|
TCGv low = tcg_temp_new();
|
2011-01-20 01:18:00 +03:00
|
|
|
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_andi_tl(low, addr, 3);
|
|
|
|
tcg_gen_sub_tl(low, tcg_const_tl(3), low);
|
|
|
|
tcg_gen_andi_tl(addr, addr, ~3);
|
|
|
|
tcg_gen_or_tl(addr, addr, low);
|
|
|
|
tcg_temp_free(low);
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
/* 00 -> 10
|
|
|
|
10 -> 00. */
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_xori_tl(addr, addr, 2);
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu), "Invalid reverse size\n");
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-01 07:23:28 +04:00
|
|
|
/* lwx does not throw unaligned access errors, so force alignment */
|
|
|
|
if (ex) {
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_andi_tl(addr, addr, ~3);
|
2012-06-01 07:23:28 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
/* If we get a fault on a dslot, the jmpstate better be in sync. */
|
|
|
|
sync_jmpstate(dc);
|
2009-09-03 14:59:46 +04:00
|
|
|
|
|
|
|
/* Verify alignment if needed. */
|
2013-12-11 03:40:21 +04:00
|
|
|
/*
|
|
|
|
* Microblaze gives MMU faults priority over faults due to
|
|
|
|
* unaligned addresses. That's why we speculatively do the load
|
|
|
|
* into v. If the load succeeds, we verify alignment of the
|
|
|
|
* address and if that succeeds we write into the destination reg.
|
|
|
|
*/
|
2018-04-05 20:09:30 +03:00
|
|
|
v = tcg_temp_new_i32();
|
2018-04-13 23:04:37 +03:00
|
|
|
tcg_gen_qemu_ld_i32(v, addr, mem_index, mop);
|
2009-09-11 12:35:27 +04:00
|
|
|
|
2013-09-03 22:02:48 +04:00
|
|
|
if ((dc->cpu->env.pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc);
|
2018-04-13 17:12:56 +03:00
|
|
|
gen_helper_memalign(cpu_env, addr, tcg_const_i32(dc->rd),
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_const_i32(0), tcg_const_i32(size - 1));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2013-12-11 03:40:21 +04:00
|
|
|
if (ex) {
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_mov_tl(env_res_addr, addr);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mov_i32(env_res_val, v);
|
2013-12-11 03:40:21 +04:00
|
|
|
}
|
|
|
|
if (dc->rd) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_mov_i32(cpu_R[dc->rd], v);
|
2013-12-11 03:40:21 +04:00
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(v);
|
2013-12-11 03:40:21 +04:00
|
|
|
|
2012-06-01 07:23:28 +04:00
|
|
|
if (ex) { /* lwx */
|
2015-08-26 14:17:13 +03:00
|
|
|
/* no support for AXI exclusive so always clear C */
|
2012-06-01 07:23:28 +04:00
|
|
|
write_carryi(dc, 0);
|
|
|
|
}
|
|
|
|
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_temp_free(addr);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_store(DisasContext *dc)
|
|
|
|
{
|
2018-04-13 21:20:25 +03:00
|
|
|
TCGv addr;
|
2015-02-13 23:51:55 +03:00
|
|
|
TCGLabel *swx_skip = NULL;
|
2018-04-04 14:55:48 +03:00
|
|
|
unsigned int size;
|
2018-04-13 23:04:37 +03:00
|
|
|
bool rev = false, ex = false, ea = false;
|
|
|
|
int mem_index = cpu_mmu_index(&dc->cpu->env, false);
|
2013-12-11 03:40:21 +04:00
|
|
|
TCGMemOp mop;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2013-12-11 03:40:21 +04:00
|
|
|
mop = dc->opcode & 3;
|
|
|
|
size = 1 << mop;
|
2011-01-20 01:18:00 +03:00
|
|
|
if (!dc->type_b) {
|
2018-04-13 23:04:37 +03:00
|
|
|
ea = extract32(dc->ir, 7, 1);
|
2018-04-04 14:55:48 +03:00
|
|
|
rev = extract32(dc->ir, 9, 1);
|
|
|
|
ex = extract32(dc->ir, 10, 1);
|
2011-01-20 01:18:00 +03:00
|
|
|
}
|
2013-12-11 03:40:21 +04:00
|
|
|
mop |= MO_TE;
|
|
|
|
if (rev) {
|
|
|
|
mop ^= MO_BSWAP;
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, size > 4)) {
|
2009-09-04 12:38:59 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-13 23:04:37 +03:00
|
|
|
trap_userspace(dc, ea);
|
|
|
|
|
|
|
|
LOG_DIS("s%d%s%s%s%s\n", size, dc->type_b ? "i" : "", rev ? "r" : "",
|
|
|
|
ex ? "x" : "",
|
|
|
|
ea ? "ea" : "");
|
2009-05-20 21:37:39 +04:00
|
|
|
t_sync_flags(dc);
|
|
|
|
/* If we get a fault on a dslot, the jmpstate better be in sync. */
|
|
|
|
sync_jmpstate(dc);
|
2018-04-13 17:12:56 +03:00
|
|
|
/* SWX needs a temp_local. */
|
2018-04-13 21:20:25 +03:00
|
|
|
addr = ex ? tcg_temp_local_new() : tcg_temp_new();
|
2018-04-13 23:04:37 +03:00
|
|
|
compute_ldst_addr(dc, ea, addr);
|
|
|
|
/* Extended addressing bypasses the MMU. */
|
|
|
|
mem_index = ea ? MMU_NOMMU_IDX : mem_index;
|
2009-09-03 14:59:46 +04:00
|
|
|
|
2012-06-01 07:23:28 +04:00
|
|
|
if (ex) { /* swx */
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 tval;
|
2012-06-01 07:23:28 +04:00
|
|
|
|
|
|
|
/* swx does not throw unaligned access errors, so force alignment */
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_andi_tl(addr, addr, ~3);
|
2012-06-01 07:23:28 +04:00
|
|
|
|
|
|
|
write_carryi(dc, 1);
|
|
|
|
swx_skip = gen_new_label();
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_brcond_tl(TCG_COND_NE, env_res_addr, addr, swx_skip);
|
2013-10-23 18:54:31 +04:00
|
|
|
|
|
|
|
/* Compare the value loaded at lwx with current contents of
|
|
|
|
the reserved location.
|
|
|
|
FIXME: This only works for system emulation where we can expect
|
|
|
|
this compare and the following write to be atomic. For user
|
|
|
|
emulation we need to add atomicity between threads. */
|
2018-04-05 20:09:30 +03:00
|
|
|
tval = tcg_temp_new_i32();
|
2018-04-13 17:12:56 +03:00
|
|
|
tcg_gen_qemu_ld_i32(tval, addr, cpu_mmu_index(&dc->cpu->env, false),
|
|
|
|
MO_TEUL);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_brcond_i32(TCG_COND_NE, env_res_val, tval, swx_skip);
|
2012-06-01 07:23:28 +04:00
|
|
|
write_carryi(dc, 0);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(tval);
|
2012-06-01 07:23:28 +04:00
|
|
|
}
|
|
|
|
|
2011-01-20 01:18:00 +03:00
|
|
|
if (rev && size != 4) {
|
|
|
|
/* Endian reverse the address. t is addr. */
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
/* 00 -> 11
|
|
|
|
01 -> 10
|
|
|
|
10 -> 10
|
|
|
|
11 -> 00 */
|
2018-04-13 21:20:25 +03:00
|
|
|
TCGv low = tcg_temp_new();
|
2011-01-20 01:18:00 +03:00
|
|
|
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_andi_tl(low, addr, 3);
|
|
|
|
tcg_gen_sub_tl(low, tcg_const_tl(3), low);
|
|
|
|
tcg_gen_andi_tl(addr, addr, ~3);
|
|
|
|
tcg_gen_or_tl(addr, addr, low);
|
|
|
|
tcg_temp_free(low);
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
/* 00 -> 10
|
|
|
|
10 -> 00. */
|
|
|
|
/* Force addr into the temp. */
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_gen_xori_tl(addr, addr, 2);
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
default:
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu), "Invalid reverse size\n");
|
2011-01-20 01:18:00 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 23:04:37 +03:00
|
|
|
tcg_gen_qemu_st_i32(cpu_R[dc->rd], addr, mem_index, mop);
|
2009-09-11 12:35:27 +04:00
|
|
|
|
2009-09-03 14:59:46 +04:00
|
|
|
/* Verify alignment if needed. */
|
2013-09-03 22:02:48 +04:00
|
|
|
if ((dc->cpu->env.pvr.regs[2] & PVR2_UNALIGNED_EXC_MASK) && size > 1) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc);
|
2009-09-11 12:35:27 +04:00
|
|
|
/* FIXME: if the alignment is wrong, we should restore the value
|
2011-11-22 14:06:21 +04:00
|
|
|
* in memory. One possible way to achieve this is to probe
|
2011-01-20 01:18:00 +03:00
|
|
|
* the MMU prior to the memaccess, thay way we could put
|
|
|
|
* the alignment checks in between the probe and the mem
|
|
|
|
* access.
|
2009-09-11 12:35:27 +04:00
|
|
|
*/
|
2018-04-13 17:12:56 +03:00
|
|
|
gen_helper_memalign(cpu_env, addr, tcg_const_i32(dc->rd),
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_const_i32(1), tcg_const_i32(size - 1));
|
2009-09-03 14:59:46 +04:00
|
|
|
}
|
2012-06-05 06:31:04 +04:00
|
|
|
|
2012-06-01 07:23:28 +04:00
|
|
|
if (ex) {
|
|
|
|
gen_set_label(swx_skip);
|
|
|
|
}
|
2009-09-03 14:59:46 +04:00
|
|
|
|
2018-04-13 21:20:25 +03:00
|
|
|
tcg_temp_free(addr);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void eval_cc(DisasContext *dc, unsigned int cc,
|
2018-05-08 18:34:21 +03:00
|
|
|
TCGv_i32 d, TCGv_i32 a)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2018-05-08 18:31:50 +03:00
|
|
|
static const int mb_to_tcg_cc[] = {
|
|
|
|
[CC_EQ] = TCG_COND_EQ,
|
|
|
|
[CC_NE] = TCG_COND_NE,
|
|
|
|
[CC_LT] = TCG_COND_LT,
|
|
|
|
[CC_LE] = TCG_COND_LE,
|
|
|
|
[CC_GE] = TCG_COND_GE,
|
|
|
|
[CC_GT] = TCG_COND_GT,
|
|
|
|
};
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
switch (cc) {
|
2018-05-08 18:31:50 +03:00
|
|
|
case CC_EQ:
|
|
|
|
case CC_NE:
|
|
|
|
case CC_LT:
|
|
|
|
case CC_LE:
|
|
|
|
case CC_GE:
|
|
|
|
case CC_GT:
|
2018-05-08 18:34:21 +03:00
|
|
|
tcg_gen_setcondi_i32(mb_to_tcg_cc[cc], d, a, 0);
|
2018-05-08 18:31:50 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cpu_abort(CPU(dc->cpu), "Unknown condition code %x.\n", cc);
|
|
|
|
break;
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 18:59:29 +03:00
|
|
|
static void eval_cond_jmp(DisasContext *dc, TCGv_i32 pc_true, TCGv_i64 pc_false)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2015-02-13 23:51:55 +03:00
|
|
|
TCGLabel *l1 = gen_new_label();
|
2009-05-20 21:37:39 +04:00
|
|
|
/* Conditional jmp. */
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_mov_i64(cpu_SR[SR_PC], pc_false);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_brcondi_i32(TCG_COND_EQ, env_btaken, 0, l1);
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extu_i32_i64(cpu_SR[SR_PC], pc_true);
|
2009-05-20 21:37:39 +04:00
|
|
|
gen_set_label(l1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_bcc(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int cc;
|
|
|
|
unsigned int dslot;
|
|
|
|
|
|
|
|
cc = EXTRACT_FIELD(dc->ir, 21, 23);
|
|
|
|
dslot = dc->ir & (1 << 25);
|
|
|
|
LOG_DIS("bcc%s r%d %x\n", dslot ? "d" : "", dc->ra, dc->imm);
|
|
|
|
|
|
|
|
dc->delayed_branch = 1;
|
|
|
|
if (dslot) {
|
|
|
|
dc->delayed_branch = 2;
|
|
|
|
dc->tb_flags |= D_FLAG;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)),
|
2012-03-14 04:38:22 +04:00
|
|
|
cpu_env, offsetof(CPUMBState, bimm));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2010-07-24 23:24:59 +04:00
|
|
|
if (dec_alu_op_b_is_small_imm(dc)) {
|
|
|
|
int32_t offset = (int32_t)((int16_t)dc->imm); /* sign-extend. */
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btarget, dc->pc + offset);
|
2011-01-14 14:30:26 +03:00
|
|
|
dc->jmp = JMP_DIRECT_CC;
|
2011-01-05 04:21:19 +03:00
|
|
|
dc->jmp_pc = dc->pc + offset;
|
2010-07-24 23:24:59 +04:00
|
|
|
} else {
|
2011-01-05 04:21:19 +03:00
|
|
|
dc->jmp = JMP_INDIRECT;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btarget, dc->pc);
|
|
|
|
tcg_gen_add_i32(env_btarget, env_btarget, *(dec_alu_op_b(dc)));
|
2010-07-24 23:24:59 +04:00
|
|
|
}
|
2018-05-08 18:34:21 +03:00
|
|
|
eval_cc(dc, cc, env_btaken, cpu_R[dc->ra]);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_br(DisasContext *dc)
|
|
|
|
{
|
2012-01-10 13:33:37 +04:00
|
|
|
unsigned int dslot, link, abs, mbar;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
dslot = dc->ir & (1 << 20);
|
|
|
|
abs = dc->ir & (1 << 19);
|
|
|
|
link = dc->ir & (1 << 18);
|
2012-01-10 13:33:37 +04:00
|
|
|
|
|
|
|
/* Memory barrier. */
|
|
|
|
mbar = (dc->ir >> 16) & 31;
|
|
|
|
if (mbar == 2 && dc->imm == 4) {
|
2013-03-29 01:59:03 +04:00
|
|
|
/* mbar IMM & 16 decodes to sleep. */
|
|
|
|
if (dc->rd & 16) {
|
|
|
|
TCGv_i32 tmp_hlt = tcg_const_i32(EXCP_HLT);
|
|
|
|
TCGv_i32 tmp_1 = tcg_const_i32(1);
|
|
|
|
|
|
|
|
LOG_DIS("sleep\n");
|
|
|
|
|
|
|
|
t_sync_flags(dc);
|
|
|
|
tcg_gen_st_i32(tmp_1, cpu_env,
|
|
|
|
-offsetof(MicroBlazeCPU, env)
|
|
|
|
+offsetof(CPUState, halted));
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc + 4);
|
2013-03-29 01:59:03 +04:00
|
|
|
gen_helper_raise_exception(cpu_env, tmp_hlt);
|
|
|
|
tcg_temp_free_i32(tmp_hlt);
|
|
|
|
tcg_temp_free_i32(tmp_1);
|
|
|
|
return;
|
|
|
|
}
|
2012-01-10 13:33:37 +04:00
|
|
|
LOG_DIS("mbar %d\n", dc->rd);
|
|
|
|
/* Break the TB. */
|
|
|
|
dc->cpustate_changed = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
LOG_DIS("br%s%s%s%s imm=%x\n",
|
|
|
|
abs ? "a" : "", link ? "l" : "",
|
|
|
|
dc->type_b ? "i" : "", dslot ? "d" : "",
|
|
|
|
dc->imm);
|
|
|
|
|
|
|
|
dc->delayed_branch = 1;
|
|
|
|
if (dslot) {
|
|
|
|
dc->delayed_branch = 2;
|
|
|
|
dc->tb_flags |= D_FLAG;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)),
|
2012-03-14 04:38:22 +04:00
|
|
|
cpu_env, offsetof(CPUMBState, bimm));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
if (link && dc->rd)
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(cpu_R[dc->rd], dc->pc);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
dc->jmp = JMP_INDIRECT;
|
|
|
|
if (abs) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btaken, 1);
|
|
|
|
tcg_gen_mov_i32(env_btarget, *(dec_alu_op_b(dc)));
|
2010-02-20 16:04:01 +03:00
|
|
|
if (link && !dslot) {
|
|
|
|
if (!(dc->tb_flags & IMM_FLAG) && (dc->imm == 8 || dc->imm == 0x18))
|
|
|
|
t_gen_raise_exception(dc, EXCP_BREAK);
|
|
|
|
if (dc->imm == 0) {
|
2018-04-14 00:02:41 +03:00
|
|
|
if (trap_userspace(dc, true)) {
|
2010-02-20 16:04:01 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
t_gen_raise_exception(dc, EXCP_DEBUG);
|
|
|
|
}
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
} else {
|
2010-07-24 23:24:59 +04:00
|
|
|
if (dec_alu_op_b_is_small_imm(dc)) {
|
|
|
|
dc->jmp = JMP_DIRECT;
|
|
|
|
dc->jmp_pc = dc->pc + (int32_t)((int16_t)dc->imm);
|
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btaken, 1);
|
|
|
|
tcg_gen_movi_i32(env_btarget, dc->pc);
|
|
|
|
tcg_gen_add_i32(env_btarget, env_btarget, *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void do_rti(DisasContext *dc)
|
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0, t1;
|
|
|
|
t0 = tcg_temp_new_i32();
|
|
|
|
t1 = tcg_temp_new_i32();
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(t1, cpu_SR[SR_MSR]);
|
|
|
|
tcg_gen_shri_i32(t0, t1, 1);
|
|
|
|
tcg_gen_ori_i32(t1, t1, MSR_IE);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM));
|
|
|
|
|
|
|
|
tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM));
|
|
|
|
tcg_gen_or_i32(t1, t1, t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
msr_write(dc, t1);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t1);
|
|
|
|
tcg_temp_free_i32(t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->tb_flags &= ~DRTI_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void do_rtb(DisasContext *dc)
|
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0, t1;
|
|
|
|
t0 = tcg_temp_new_i32();
|
|
|
|
t1 = tcg_temp_new_i32();
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(t1, cpu_SR[SR_MSR]);
|
|
|
|
tcg_gen_andi_i32(t1, t1, ~MSR_BIP);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_shri_i32(t0, t1, 1);
|
|
|
|
tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM));
|
|
|
|
|
|
|
|
tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM));
|
|
|
|
tcg_gen_or_i32(t1, t1, t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
msr_write(dc, t1);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t1);
|
|
|
|
tcg_temp_free_i32(t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->tb_flags &= ~DRTB_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void do_rte(DisasContext *dc)
|
|
|
|
{
|
2018-04-05 20:09:30 +03:00
|
|
|
TCGv_i32 t0, t1;
|
|
|
|
t0 = tcg_temp_new_i32();
|
|
|
|
t1 = tcg_temp_new_i32();
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_extrl_i64_i32(t1, cpu_SR[SR_MSR]);
|
|
|
|
tcg_gen_ori_i32(t1, t1, MSR_EE);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_andi_i32(t1, t1, ~MSR_EIP);
|
|
|
|
tcg_gen_shri_i32(t0, t1, 1);
|
|
|
|
tcg_gen_andi_i32(t0, t0, (MSR_VM | MSR_UM));
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_andi_i32(t1, t1, ~(MSR_VM | MSR_UM));
|
|
|
|
tcg_gen_or_i32(t1, t1, t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
msr_write(dc, t1);
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t1);
|
|
|
|
tcg_temp_free_i32(t0);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->tb_flags &= ~DRTE_FLAG;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dec_rts(DisasContext *dc)
|
|
|
|
{
|
|
|
|
unsigned int b_bit, i_bit, e_bit;
|
|
|
|
|
|
|
|
i_bit = dc->ir & (1 << 21);
|
|
|
|
b_bit = dc->ir & (1 << 22);
|
|
|
|
e_bit = dc->ir & (1 << 23);
|
|
|
|
|
2018-04-14 00:02:41 +03:00
|
|
|
if (trap_userspace(dc, i_bit || b_bit || e_bit)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->delayed_branch = 2;
|
|
|
|
dc->tb_flags |= D_FLAG;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_st_i32(tcg_const_i32(dc->type_b && (dc->tb_flags & IMM_FLAG)),
|
2012-03-14 04:38:22 +04:00
|
|
|
cpu_env, offsetof(CPUMBState, bimm));
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
if (i_bit) {
|
|
|
|
LOG_DIS("rtid ir=%x\n", dc->ir);
|
|
|
|
dc->tb_flags |= DRTI_FLAG;
|
|
|
|
} else if (b_bit) {
|
|
|
|
LOG_DIS("rtbd ir=%x\n", dc->ir);
|
|
|
|
dc->tb_flags |= DRTB_FLAG;
|
|
|
|
} else if (e_bit) {
|
|
|
|
LOG_DIS("rted ir=%x\n", dc->ir);
|
|
|
|
dc->tb_flags |= DRTE_FLAG;
|
|
|
|
} else
|
|
|
|
LOG_DIS("rts ir=%x\n", dc->ir);
|
|
|
|
|
2011-01-05 04:21:19 +03:00
|
|
|
dc->jmp = JMP_INDIRECT;
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(env_btaken, 1);
|
|
|
|
tcg_gen_add_i32(env_btarget, cpu_R[dc->ra], *(dec_alu_op_b(dc)));
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
|
2010-09-09 12:20:17 +04:00
|
|
|
static int dec_check_fpuv2(DisasContext *dc)
|
|
|
|
{
|
2015-06-19 07:16:25 +03:00
|
|
|
if ((dc->cpu->cfg.use_fpu != 2) && (dc->tb_flags & MSR_EE_FLAG)) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_ESR], ESR_EC_FPU);
|
2010-09-09 12:20:17 +04:00
|
|
|
t_gen_raise_exception(dc, EXCP_HW_EXCP);
|
|
|
|
}
|
2015-06-19 07:16:25 +03:00
|
|
|
return (dc->cpu->cfg.use_fpu == 2) ? 0 : PVR2_USE_FPU2_MASK;
|
2010-09-09 12:20:17 +04:00
|
|
|
}
|
|
|
|
|
2009-09-03 13:12:30 +04:00
|
|
|
static void dec_fpu(DisasContext *dc)
|
|
|
|
{
|
2010-09-09 12:20:17 +04:00
|
|
|
unsigned int fpu_insn;
|
|
|
|
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, !dc->cpu->cfg.use_fpu)) {
|
2009-09-03 13:12:30 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-09 12:20:17 +04:00
|
|
|
fpu_insn = (dc->ir >> 7) & 7;
|
|
|
|
|
|
|
|
switch (fpu_insn) {
|
|
|
|
case 0:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fadd(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
|
|
|
|
cpu_R[dc->rb]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_frsub(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
|
|
|
|
cpu_R[dc->rb]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fmul(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
|
|
|
|
cpu_R[dc->rb]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fdiv(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra],
|
|
|
|
cpu_R[dc->rb]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
switch ((dc->ir >> 4) & 7) {
|
|
|
|
case 0:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_un(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_lt(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 2:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_eq(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 3:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_le(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 4:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_gt(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 5:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_ne(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
case 6:
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fcmp_ge(cpu_R[dc->rd], cpu_env,
|
2010-09-09 12:20:17 +04:00
|
|
|
cpu_R[dc->ra], cpu_R[dc->rb]);
|
|
|
|
break;
|
|
|
|
default:
|
2012-06-03 21:06:07 +04:00
|
|
|
qemu_log_mask(LOG_UNIMP,
|
|
|
|
"unimplemented fcmp fpu_insn=%x pc=%x"
|
|
|
|
" opc=%x\n",
|
|
|
|
fpu_insn, dc->pc, dc->opcode);
|
2010-09-09 12:20:17 +04:00
|
|
|
dc->abort_at_next_insn = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
if (!dec_check_fpuv2(dc)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_flt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
if (!dec_check_fpuv2(dc)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fint(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
if (!dec_check_fpuv2(dc)) {
|
|
|
|
return;
|
|
|
|
}
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_fsqrt(cpu_R[dc->rd], cpu_env, cpu_R[dc->ra]);
|
2010-09-09 12:20:17 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-06-03 21:06:07 +04:00
|
|
|
qemu_log_mask(LOG_UNIMP, "unimplemented FPU insn fpu_insn=%x pc=%x"
|
|
|
|
" opc=%x\n",
|
|
|
|
fpu_insn, dc->pc, dc->opcode);
|
2010-09-09 12:20:17 +04:00
|
|
|
dc->abort_at_next_insn = 1;
|
|
|
|
break;
|
|
|
|
}
|
2009-09-03 13:12:30 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
static void dec_null(DisasContext *dc)
|
|
|
|
{
|
2018-04-14 19:41:24 +03:00
|
|
|
if (trap_illegal(dc, true)) {
|
2009-09-11 12:38:31 +04:00
|
|
|
return;
|
|
|
|
}
|
2015-11-13 15:24:57 +03:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "unknown insn pc=%x opc=%x\n", dc->pc, dc->opcode);
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->abort_at_next_insn = 1;
|
|
|
|
}
|
|
|
|
|
2011-04-12 02:48:33 +04:00
|
|
|
/* Insns connected to FSL or AXI stream attached devices. */
|
|
|
|
static void dec_stream(DisasContext *dc)
|
|
|
|
{
|
|
|
|
TCGv_i32 t_id, t_ctrl;
|
|
|
|
int ctrl;
|
|
|
|
|
|
|
|
LOG_DIS("%s%s imm=%x\n", dc->rd ? "get" : "put",
|
|
|
|
dc->type_b ? "" : "d", dc->imm);
|
|
|
|
|
2018-04-14 00:02:41 +03:00
|
|
|
if (trap_userspace(dc, true)) {
|
2011-04-12 02:48:33 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
t_id = tcg_temp_new_i32();
|
2011-04-12 02:48:33 +04:00
|
|
|
if (dc->type_b) {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_movi_i32(t_id, dc->imm & 0xf);
|
2011-04-12 02:48:33 +04:00
|
|
|
ctrl = dc->imm >> 10;
|
|
|
|
} else {
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_andi_i32(t_id, cpu_R[dc->rb], 0xf);
|
2011-04-12 02:48:33 +04:00
|
|
|
ctrl = dc->imm >> 5;
|
|
|
|
}
|
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
t_ctrl = tcg_const_i32(ctrl);
|
2011-04-12 02:48:33 +04:00
|
|
|
|
|
|
|
if (dc->rd == 0) {
|
|
|
|
gen_helper_put(t_id, t_ctrl, cpu_R[dc->ra]);
|
|
|
|
} else {
|
|
|
|
gen_helper_get(cpu_R[dc->rd], t_id, t_ctrl);
|
|
|
|
}
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_temp_free_i32(t_id);
|
|
|
|
tcg_temp_free_i32(t_ctrl);
|
2011-04-12 02:48:33 +04:00
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
static struct decoder_info {
|
|
|
|
struct {
|
|
|
|
uint32_t bits;
|
|
|
|
uint32_t mask;
|
|
|
|
};
|
|
|
|
void (*dec)(DisasContext *dc);
|
|
|
|
} decinfo[] = {
|
|
|
|
{DEC_ADD, dec_add},
|
|
|
|
{DEC_SUB, dec_sub},
|
|
|
|
{DEC_AND, dec_and},
|
|
|
|
{DEC_XOR, dec_xor},
|
|
|
|
{DEC_OR, dec_or},
|
|
|
|
{DEC_BIT, dec_bit},
|
|
|
|
{DEC_BARREL, dec_barrel},
|
|
|
|
{DEC_LD, dec_load},
|
|
|
|
{DEC_ST, dec_store},
|
|
|
|
{DEC_IMM, dec_imm},
|
|
|
|
{DEC_BR, dec_br},
|
|
|
|
{DEC_BCC, dec_bcc},
|
|
|
|
{DEC_RTS, dec_rts},
|
2009-09-03 13:12:30 +04:00
|
|
|
{DEC_FPU, dec_fpu},
|
2009-05-20 21:37:39 +04:00
|
|
|
{DEC_MUL, dec_mul},
|
|
|
|
{DEC_DIV, dec_div},
|
|
|
|
{DEC_MSR, dec_msr},
|
2011-04-12 02:48:33 +04:00
|
|
|
{DEC_STREAM, dec_stream},
|
2009-05-20 21:37:39 +04:00
|
|
|
{{0, 0}, dec_null}
|
|
|
|
};
|
|
|
|
|
2012-09-02 12:39:22 +04:00
|
|
|
static inline void decode(DisasContext *dc, uint32_t ir)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-09-02 12:39:22 +04:00
|
|
|
dc->ir = ir;
|
2009-05-20 21:37:39 +04:00
|
|
|
LOG_DIS("%8.8x\t", dc->ir);
|
|
|
|
|
|
|
|
if (dc->ir)
|
|
|
|
dc->nr_nops = 0;
|
|
|
|
else {
|
2018-04-14 19:41:24 +03:00
|
|
|
trap_illegal(dc, dc->cpu->env.pvr.regs[2] & PVR2_OPCODE_0x0_ILL_MASK);
|
2009-09-03 13:12:30 +04:00
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
LOG_DIS("nr_nops=%d\t", dc->nr_nops);
|
|
|
|
dc->nr_nops++;
|
2013-09-03 19:38:47 +04:00
|
|
|
if (dc->nr_nops > 4) {
|
2013-09-03 22:02:48 +04:00
|
|
|
cpu_abort(CPU(dc->cpu), "fetching nop sequence\n");
|
2013-09-03 19:38:47 +04:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
/* bit 2 seems to indicate insn type. */
|
|
|
|
dc->type_b = ir & (1 << 29);
|
|
|
|
|
|
|
|
dc->opcode = EXTRACT_FIELD(ir, 26, 31);
|
|
|
|
dc->rd = EXTRACT_FIELD(ir, 21, 25);
|
|
|
|
dc->ra = EXTRACT_FIELD(ir, 16, 20);
|
|
|
|
dc->rb = EXTRACT_FIELD(ir, 11, 15);
|
|
|
|
dc->imm = EXTRACT_FIELD(ir, 0, 15);
|
|
|
|
|
|
|
|
/* Large switch for all insns. */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(decinfo); i++) {
|
|
|
|
if ((dc->opcode & decinfo[i].mask) == decinfo[i].bits) {
|
|
|
|
decinfo[i].dec(dc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generate intermediate code for basic block 'tb'. */
|
2017-07-14 11:17:35 +03:00
|
|
|
void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2017-07-14 11:17:35 +03:00
|
|
|
CPUMBState *env = cs->env_ptr;
|
2015-09-02 06:01:40 +03:00
|
|
|
MicroBlazeCPU *cpu = mb_env_get_cpu(env);
|
2009-05-20 21:37:39 +04:00
|
|
|
uint32_t pc_start;
|
|
|
|
struct DisasContext ctx;
|
|
|
|
struct DisasContext *dc = &ctx;
|
2018-04-10 17:47:51 +03:00
|
|
|
uint32_t page_start, org_flags;
|
2018-04-05 20:09:30 +03:00
|
|
|
uint32_t npc;
|
2009-05-20 21:37:39 +04:00
|
|
|
int num_insns;
|
|
|
|
int max_insns;
|
|
|
|
|
|
|
|
pc_start = tb->pc;
|
2013-09-03 22:02:48 +04:00
|
|
|
dc->cpu = cpu;
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->tb = tb;
|
|
|
|
org_flags = dc->synced_flags = dc->tb_flags = tb->flags;
|
|
|
|
|
|
|
|
dc->is_jmp = DISAS_NEXT;
|
|
|
|
dc->jmp = 0;
|
|
|
|
dc->delayed_branch = !!(dc->tb_flags & D_FLAG);
|
2011-01-05 04:21:19 +03:00
|
|
|
if (dc->delayed_branch) {
|
|
|
|
dc->jmp = JMP_INDIRECT;
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->pc = pc_start;
|
2013-06-21 22:20:45 +04:00
|
|
|
dc->singlestep_enabled = cs->singlestep_enabled;
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->cpustate_changed = 0;
|
|
|
|
dc->abort_at_next_insn = 0;
|
|
|
|
dc->nr_nops = 0;
|
|
|
|
|
2013-09-03 19:38:47 +04:00
|
|
|
if (pc_start & 3) {
|
|
|
|
cpu_abort(cs, "Microblaze: unaligned PC=%x\n", pc_start);
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-10 17:47:51 +03:00
|
|
|
page_start = pc_start & TARGET_PAGE_MASK;
|
2009-05-20 21:37:39 +04:00
|
|
|
num_insns = 0;
|
2017-07-19 03:46:52 +03:00
|
|
|
max_insns = tb_cflags(tb) & CF_COUNT_MASK;
|
2015-09-01 00:34:41 +03:00
|
|
|
if (max_insns == 0) {
|
2009-05-20 21:37:39 +04:00
|
|
|
max_insns = CF_COUNT_MASK;
|
2015-09-01 00:34:41 +03:00
|
|
|
}
|
|
|
|
if (max_insns > TCG_MAX_INSNS) {
|
|
|
|
max_insns = TCG_MAX_INSNS;
|
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2014-11-26 13:40:05 +03:00
|
|
|
gen_tb_start(tb);
|
2009-05-20 21:37:39 +04:00
|
|
|
do
|
|
|
|
{
|
2015-08-29 22:59:29 +03:00
|
|
|
tcg_gen_insn_start(dc->pc);
|
2015-09-18 00:25:46 +03:00
|
|
|
num_insns++;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2015-09-18 01:58:10 +03:00
|
|
|
#if SIM_COMPAT
|
|
|
|
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], dc->pc);
|
2015-09-18 01:58:10 +03:00
|
|
|
gen_helper_debug();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (unlikely(cpu_breakpoint_test(cs, dc->pc, BP_ANY))) {
|
|
|
|
t_gen_raise_exception(dc, EXCP_DEBUG);
|
|
|
|
dc->is_jmp = DISAS_UPDATE;
|
2015-10-14 01:07:49 +03:00
|
|
|
/* The address covered by the breakpoint must be included in
|
|
|
|
[tb->pc, tb->pc + tb->size) in order to for it to be
|
|
|
|
properly cleared -- thus we increment the PC here so that
|
|
|
|
the logic setting tb->size below does the right thing. */
|
|
|
|
dc->pc += 4;
|
2015-09-18 01:58:10 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
/* Pretty disas. */
|
|
|
|
LOG_DIS("%8.8x:\t", dc->pc);
|
|
|
|
|
2017-07-19 03:46:52 +03:00
|
|
|
if (num_insns == max_insns && (tb_cflags(tb) & CF_LAST_IO)) {
|
2009-05-20 21:37:39 +04:00
|
|
|
gen_io_start();
|
2015-09-18 00:25:46 +03:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
dc->clear_imm = 1;
|
2012-09-02 12:39:22 +04:00
|
|
|
decode(dc, cpu_ldl_code(env, dc->pc));
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->clear_imm)
|
|
|
|
dc->tb_flags &= ~IMM_FLAG;
|
|
|
|
dc->pc += 4;
|
|
|
|
|
|
|
|
if (dc->delayed_branch) {
|
|
|
|
dc->delayed_branch--;
|
|
|
|
if (!dc->delayed_branch) {
|
|
|
|
if (dc->tb_flags & DRTI_FLAG)
|
|
|
|
do_rti(dc);
|
|
|
|
if (dc->tb_flags & DRTB_FLAG)
|
|
|
|
do_rtb(dc);
|
|
|
|
if (dc->tb_flags & DRTE_FLAG)
|
|
|
|
do_rte(dc);
|
|
|
|
/* Clear the delay slot flag. */
|
|
|
|
dc->tb_flags &= ~D_FLAG;
|
|
|
|
/* If it is a direct jump, try direct chaining. */
|
2011-01-05 04:21:19 +03:00
|
|
|
if (dc->jmp == JMP_INDIRECT) {
|
2018-04-14 18:59:29 +03:00
|
|
|
eval_cond_jmp(dc, env_btarget, tcg_const_i64(dc->pc));
|
2009-05-20 21:37:39 +04:00
|
|
|
dc->is_jmp = DISAS_JUMP;
|
2011-01-05 04:21:19 +03:00
|
|
|
} else if (dc->jmp == JMP_DIRECT) {
|
2011-01-14 14:30:26 +03:00
|
|
|
t_sync_flags(dc);
|
|
|
|
gen_goto_tb(dc, 0, dc->jmp_pc);
|
|
|
|
dc->is_jmp = DISAS_TB_JUMP;
|
|
|
|
} else if (dc->jmp == JMP_DIRECT_CC) {
|
2015-02-13 23:51:55 +03:00
|
|
|
TCGLabel *l1 = gen_new_label();
|
2011-01-05 04:21:19 +03:00
|
|
|
t_sync_flags(dc);
|
|
|
|
/* Conditional jmp. */
|
2018-04-05 20:09:30 +03:00
|
|
|
tcg_gen_brcondi_i32(TCG_COND_NE, env_btaken, 0, l1);
|
2011-01-05 04:21:19 +03:00
|
|
|
gen_goto_tb(dc, 1, dc->pc);
|
|
|
|
gen_set_label(l1);
|
|
|
|
gen_goto_tb(dc, 0, dc->jmp_pc);
|
|
|
|
|
|
|
|
dc->is_jmp = DISAS_TB_JUMP;
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-06-21 22:20:45 +04:00
|
|
|
if (cs->singlestep_enabled) {
|
2009-05-20 21:37:39 +04:00
|
|
|
break;
|
2013-06-21 22:20:45 +04:00
|
|
|
}
|
2009-05-20 21:37:39 +04:00
|
|
|
} while (!dc->is_jmp && !dc->cpustate_changed
|
2014-03-31 02:36:56 +04:00
|
|
|
&& !tcg_op_buf_full()
|
|
|
|
&& !singlestep
|
2018-04-10 17:47:51 +03:00
|
|
|
&& (dc->pc - page_start < TARGET_PAGE_SIZE)
|
2014-03-31 02:36:56 +04:00
|
|
|
&& num_insns < max_insns);
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
npc = dc->pc;
|
2011-01-14 14:30:26 +03:00
|
|
|
if (dc->jmp == JMP_DIRECT || dc->jmp == JMP_DIRECT_CC) {
|
2009-05-20 21:37:39 +04:00
|
|
|
if (dc->tb_flags & D_FLAG) {
|
|
|
|
dc->is_jmp = DISAS_UPDATE;
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], npc);
|
2009-05-20 21:37:39 +04:00
|
|
|
sync_jmpstate(dc);
|
|
|
|
} else
|
|
|
|
npc = dc->jmp_pc;
|
|
|
|
}
|
|
|
|
|
2017-07-19 03:46:52 +03:00
|
|
|
if (tb_cflags(tb) & CF_LAST_IO)
|
2009-05-20 21:37:39 +04:00
|
|
|
gen_io_end();
|
|
|
|
/* Force an update if the per-tb cpu state has changed. */
|
|
|
|
if (dc->is_jmp == DISAS_NEXT
|
|
|
|
&& (dc->cpustate_changed || org_flags != dc->tb_flags)) {
|
|
|
|
dc->is_jmp = DISAS_UPDATE;
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], npc);
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
t_sync_flags(dc);
|
|
|
|
|
2013-06-21 22:20:45 +04:00
|
|
|
if (unlikely(cs->singlestep_enabled)) {
|
2011-02-10 02:46:09 +03:00
|
|
|
TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG);
|
|
|
|
|
|
|
|
if (dc->is_jmp != DISAS_JUMP) {
|
2018-04-14 18:59:29 +03:00
|
|
|
tcg_gen_movi_i64(cpu_SR[SR_PC], npc);
|
2011-02-10 02:46:09 +03:00
|
|
|
}
|
2012-09-02 12:39:22 +04:00
|
|
|
gen_helper_raise_exception(cpu_env, tmp);
|
2011-02-10 02:46:09 +03:00
|
|
|
tcg_temp_free_i32(tmp);
|
2009-05-20 21:37:39 +04:00
|
|
|
} else {
|
|
|
|
switch(dc->is_jmp) {
|
|
|
|
case DISAS_NEXT:
|
|
|
|
gen_goto_tb(dc, 1, npc);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
case DISAS_JUMP:
|
|
|
|
case DISAS_UPDATE:
|
|
|
|
/* indicate that the hash table must be used
|
|
|
|
to find the next TB */
|
|
|
|
tcg_gen_exit_tb(0);
|
|
|
|
break;
|
|
|
|
case DISAS_TB_JUMP:
|
|
|
|
/* nothing more to generate */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-02-22 22:10:05 +04:00
|
|
|
gen_tb_end(tb, num_insns);
|
2014-03-31 01:50:30 +04:00
|
|
|
|
2015-09-02 06:01:40 +03:00
|
|
|
tb->size = dc->pc - pc_start;
|
|
|
|
tb->icount = num_insns;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_DISAS
|
|
|
|
#if !SIM_COMPAT
|
2016-04-20 21:39:35 +03:00
|
|
|
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
|
|
|
|
&& qemu_log_in_addr_range(pc_start)) {
|
2016-09-23 01:17:10 +03:00
|
|
|
qemu_log_lock();
|
2016-09-23 18:00:04 +03:00
|
|
|
qemu_log("--------------\n");
|
2017-09-14 18:38:35 +03:00
|
|
|
log_target_disas(cs, pc_start, dc->pc - pc_start);
|
2016-09-23 01:17:10 +03:00
|
|
|
qemu_log_unlock();
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
assert(!dc->abort_at_next_insn);
|
|
|
|
}
|
|
|
|
|
2013-05-27 03:33:50 +04:00
|
|
|
void mb_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf,
|
|
|
|
int flags)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2013-05-27 03:33:50 +04:00
|
|
|
MicroBlazeCPU *cpu = MICROBLAZE_CPU(cs);
|
|
|
|
CPUMBState *env = &cpu->env;
|
2009-05-20 21:37:39 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!env || !f)
|
|
|
|
return;
|
|
|
|
|
2018-04-14 18:59:29 +03:00
|
|
|
cpu_fprintf(f, "IN: PC=%" PRIx64 " %s\n",
|
2009-05-20 21:37:39 +04:00
|
|
|
env->sregs[SR_PC], lookup_symbol(env->sregs[SR_PC]));
|
2018-04-14 18:59:29 +03:00
|
|
|
cpu_fprintf(f, "rmsr=%" PRIx64 " resr=%" PRIx64 " rear=%" PRIx64 " "
|
|
|
|
"debug=%x imm=%x iflags=%x fsr=%" PRIx64 "\n",
|
2009-12-07 16:12:49 +03:00
|
|
|
env->sregs[SR_MSR], env->sregs[SR_ESR], env->sregs[SR_EAR],
|
2010-09-09 12:20:17 +04:00
|
|
|
env->debug, env->imm, env->iflags, env->sregs[SR_FSR]);
|
2009-12-16 14:52:56 +03:00
|
|
|
cpu_fprintf(f, "btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
|
2009-05-20 21:37:39 +04:00
|
|
|
env->btaken, env->btarget,
|
|
|
|
(env->sregs[SR_MSR] & MSR_UM) ? "user" : "kernel",
|
2009-12-16 14:52:56 +03:00
|
|
|
(env->sregs[SR_MSR] & MSR_UMS) ? "user" : "kernel",
|
2018-04-14 18:59:29 +03:00
|
|
|
(bool)(env->sregs[SR_MSR] & MSR_EIP),
|
|
|
|
(bool)(env->sregs[SR_MSR] & MSR_IE));
|
2009-12-16 14:52:56 +03:00
|
|
|
|
2009-05-20 21:37:39 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
cpu_fprintf(f, "r%2.2d=%8.8x ", i, env->regs[i]);
|
|
|
|
if ((i + 1) % 4 == 0)
|
|
|
|
cpu_fprintf(f, "\n");
|
|
|
|
}
|
|
|
|
cpu_fprintf(f, "\n\n");
|
|
|
|
}
|
|
|
|
|
2013-01-20 04:10:52 +04:00
|
|
|
void mb_tcg_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
2009-05-20 21:37:39 +04:00
|
|
|
|
2018-04-05 20:09:30 +03:00
|
|
|
env_debug = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, debug),
|
2009-05-20 21:37:39 +04:00
|
|
|
"debug0");
|
2018-04-05 20:09:30 +03:00
|
|
|
env_iflags = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, iflags),
|
2009-05-20 21:37:39 +04:00
|
|
|
"iflags");
|
2018-04-05 20:09:30 +03:00
|
|
|
env_imm = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, imm),
|
2009-05-20 21:37:39 +04:00
|
|
|
"imm");
|
2018-04-05 20:09:30 +03:00
|
|
|
env_btarget = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, btarget),
|
2009-05-20 21:37:39 +04:00
|
|
|
"btarget");
|
2018-04-05 20:09:30 +03:00
|
|
|
env_btaken = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, btaken),
|
2009-05-20 21:37:39 +04:00
|
|
|
"btaken");
|
2018-04-13 21:20:25 +03:00
|
|
|
env_res_addr = tcg_global_mem_new(cpu_env,
|
2013-10-23 18:44:08 +04:00
|
|
|
offsetof(CPUMBState, res_addr),
|
|
|
|
"res_addr");
|
2018-04-05 20:09:30 +03:00
|
|
|
env_res_val = tcg_global_mem_new_i32(cpu_env,
|
2013-10-23 18:54:31 +04:00
|
|
|
offsetof(CPUMBState, res_val),
|
|
|
|
"res_val");
|
2009-05-20 21:37:39 +04:00
|
|
|
for (i = 0; i < ARRAY_SIZE(cpu_R); i++) {
|
2018-04-05 20:09:30 +03:00
|
|
|
cpu_R[i] = tcg_global_mem_new_i32(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, regs[i]),
|
2009-05-20 21:37:39 +04:00
|
|
|
regnames[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < ARRAY_SIZE(cpu_SR); i++) {
|
2018-04-14 18:59:29 +03:00
|
|
|
cpu_SR[i] = tcg_global_mem_new_i64(cpu_env,
|
2012-03-14 04:38:22 +04:00
|
|
|
offsetof(CPUMBState, sregs[i]),
|
2009-05-20 21:37:39 +04:00
|
|
|
special_regnames[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-02 01:51:12 +03:00
|
|
|
void restore_state_to_opc(CPUMBState *env, TranslationBlock *tb,
|
|
|
|
target_ulong *data)
|
2009-05-20 21:37:39 +04:00
|
|
|
{
|
2015-09-02 01:51:12 +03:00
|
|
|
env->sregs[SR_PC] = data[0];
|
2009-05-20 21:37:39 +04:00
|
|
|
}
|