[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 4/8] target/riscv: Remove the hardcoded MSTATUS_SD macro

From: Richard Henderson
Subject: Re: [PATCH v1 4/8] target/riscv: Remove the hardcoded MSTATUS_SD macro
Date: Mon, 5 Apr 2021 08:10:35 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1

On 4/2/21 1:02 PM, Alistair Francis wrote:
@@ -369,6 +369,9 @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong 
  static void mark_fs_dirty(DisasContext *ctx)
      TCGv tmp;
+    CPUState *cpu = ctx->cs;
+    CPURISCVState *env = cpu->env_ptr;
      if (ctx->mstatus_fs == MSTATUS_FS) {
@@ -377,12 +380,24 @@ static void mark_fs_dirty(DisasContext *ctx)
tmp = tcg_temp_new();
      tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus));
-    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS_SD);
+    if (riscv_cpu_is_32bit(env)) {

This is less than ideal, and will be incorrect long term.
You should check ctx->misa instead.

Eventually you'll need to change riscv_tr_init_disas_context to not just copy ctx->misa from env. At present we flush all translation blocks when misa changes, which works. But you won't want to do that when the hypervisor is 64-bit and the guest is 32-bit.

Anyway, I think it would be a good idea to create a helper local to translate, akin to has_ext().

+        tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS32_SD);
+    } else {
+#if defined(TARGET_RISCV64)
+        tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | MSTATUS64_SD);

The ifdefs are ugly. I presume there's some sort of compiler warning here? Does it go away if you cast to target_ulong?

How about

    target_ulong sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD;
    tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd);


reply via email to

[Prev in Thread] Current Thread [Next in Thread]