Skip to content

Commit

Permalink
target/loongarch: Adjust the layout of hardware flags bit fields
Browse files Browse the repository at this point in the history
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Song Gao <gaosong@loongson.cn>
Signed-off-by: Rui Wang <wangrui@loongson.cn>
Message-Id: <20221104040517.222059-2-wangrui@loongson.cn>
Signed-off-by: Song Gao <gaosong@loongson.cn>
  • Loading branch information
heiher authored and gaosong-loongson committed Nov 4, 2022
1 parent 8752b13 commit b4bda20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion target/loongarch/cpu.h
Expand Up @@ -14,6 +14,7 @@
#include "qemu/timer.h"
#include "exec/memory.h"
#include "hw/sysbus.h"
#include "cpu-csr.h"

#define IOCSRF_TEMP 0
#define IOCSRF_NODECNT 1
Expand Down Expand Up @@ -391,14 +392,20 @@ static inline int cpu_mmu_index(CPULoongArchState *env, bool ifetch)
#endif
}

/*
* LoongArch CPUs hardware flags.
*/
#define HW_FLAGS_PLV_MASK R_CSR_CRMD_PLV_MASK /* 0x03 */
#define HW_FLAGS_CRMD_PG R_CSR_CRMD_PG_MASK /* 0x10 */

static inline void cpu_get_tb_cpu_state(CPULoongArchState *env,
target_ulong *pc,
target_ulong *cs_base,
uint32_t *flags)
{
*pc = env->pc;
*cs_base = 0;
*flags = cpu_mmu_index(env, false);
*flags = env->CSR_CRMD & (R_CSR_CRMD_PLV_MASK | R_CSR_CRMD_PG_MASK);
}

void loongarch_cpu_list(void);
Expand Down
2 changes: 1 addition & 1 deletion target/loongarch/insn_trans/trans_privileged.c.inc
Expand Up @@ -159,7 +159,7 @@ static const CSRInfo csr_info[] = {

static bool check_plv(DisasContext *ctx)
{
if (ctx->base.tb->flags == MMU_USER_IDX) {
if (ctx->mem_idx == MMU_USER_IDX) {
generate_exception(ctx, EXCCODE_IPE);
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion target/loongarch/translate.c
Expand Up @@ -75,7 +75,11 @@ static void loongarch_tr_init_disas_context(DisasContextBase *dcbase,
DisasContext *ctx = container_of(dcbase, DisasContext, base);

ctx->page_start = ctx->base.pc_first & TARGET_PAGE_MASK;
ctx->mem_idx = ctx->base.tb->flags;
if (ctx->base.tb->flags & HW_FLAGS_CRMD_PG) {
ctx->mem_idx = ctx->base.tb->flags & HW_FLAGS_PLV_MASK;
} else {
ctx->mem_idx = MMU_DA_IDX;
}

/* Bound the number of insns to execute to those left on the page. */
bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4;
Expand Down

0 comments on commit b4bda20

Please sign in to comment.