render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0012-cris-Handle-conditional-stores-on-CRISv10.patch

Justin M. Forbes 45e84a
From 3e8088148bb56b84a739c2ef3c63d89188a1ad8f Mon Sep 17 00:00:00 2001
Justin M. Forbes 45e84a
From: Stefan Sandstrom <Stefan.Sandstrom@axis.com>
Justin M. Forbes 45e84a
Date: Mon, 12 Dec 2011 11:38:31 +0100
Justin M. Forbes 45e84a
Subject: [PATCH 12/25] cris: Handle conditional stores on CRISv10
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
Signed-off-by: Stefan Sandstrom <Stefan.Sandstrom@axis.com>
Justin M. Forbes 45e84a
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Justin M. Forbes 45e84a
---
Justin M. Forbes 45e84a
 target-cris/cpu.h           |    2 +
Justin M. Forbes 45e84a
 target-cris/helper.c        |    1 +
Justin M. Forbes 45e84a
 target-cris/translate_v10.c |   72 +++++++++++++++++++++++++++++++++++++++---
Justin M. Forbes 45e84a
 3 files changed, 69 insertions(+), 6 deletions(-)
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
diff --git a/target-cris/cpu.h b/target-cris/cpu.h
Justin M. Forbes 45e84a
index 8ae0ce3..453afbb 100644
Justin M. Forbes 45e84a
--- a/target-cris/cpu.h
Justin M. Forbes 45e84a
+++ b/target-cris/cpu.h
Justin M. Forbes 45e84a
@@ -67,6 +67,8 @@
Justin M. Forbes 45e84a
 #define Q_FLAG 0x80000000
Justin M. Forbes 45e84a
 #define M_FLAG 0x40000000
Justin M. Forbes 45e84a
 #define PFIX_FLAG 0x800      /* CRISv10 Only.  */
Justin M. Forbes 45e84a
+#define F_FLAG_V10 0x400
Justin M. Forbes 45e84a
+#define P_FLAG_V10 0x200
Justin M. Forbes 45e84a
 #define S_FLAG 0x200
Justin M. Forbes 45e84a
 #define R_FLAG 0x100
Justin M. Forbes 45e84a
 #define P_FLAG 0x80
Justin M. Forbes 45e84a
diff --git a/target-cris/helper.c b/target-cris/helper.c
Justin M. Forbes 45e84a
index 75f0035..5bc6d81 100644
Justin M. Forbes 45e84a
--- a/target-cris/helper.c
Justin M. Forbes 45e84a
+++ b/target-cris/helper.c
Justin M. Forbes 45e84a
@@ -157,6 +157,7 @@ static void do_interruptv10(CPUState *env)
Justin M. Forbes 45e84a
 	/* Now that we are in kernel mode, load the handlers address.  */
Justin M. Forbes 45e84a
 	env->pc = ldl_code(env->pregs[PR_EBP] + ex_vec * 4);
Justin M. Forbes 45e84a
 	env->locked_irq = 1;
Justin M. Forbes 45e84a
+	env->pregs[PR_CCS] |= F_FLAG_V10; /* set F.  */
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
 	qemu_log_mask(CPU_LOG_INT, "%s isr=%x vec=%x ccs=%x pid=%d erp=%x\n", 
Justin M. Forbes 45e84a
 		      __func__, env->pc, ex_vec, 
Justin M. Forbes 45e84a
diff --git a/target-cris/translate_v10.c b/target-cris/translate_v10.c
Justin M. Forbes 45e84a
index 637ac20..95053b6 100644
Justin M. Forbes 45e84a
--- a/target-cris/translate_v10.c
Justin M. Forbes 45e84a
+++ b/target-cris/translate_v10.c
Justin M. Forbes 45e84a
@@ -62,6 +62,65 @@ static inline void cris_illegal_insn(DisasContext *dc)
Justin M. Forbes 45e84a
     t_gen_raise_exception(EXCP_BREAK);
Justin M. Forbes 45e84a
 }
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
+static void gen_store_v10_conditional(DisasContext *dc, TCGv addr, TCGv val,
Justin M. Forbes 45e84a
+                       unsigned int size, int mem_index)
Justin M. Forbes 45e84a
+{
Justin M. Forbes 45e84a
+    int l1 = gen_new_label();
Justin M. Forbes 45e84a
+    TCGv taddr = tcg_temp_local_new();
Justin M. Forbes 45e84a
+    TCGv tval = tcg_temp_local_new();
Justin M. Forbes 45e84a
+    TCGv t1 = tcg_temp_local_new();
Justin M. Forbes 45e84a
+    dc->postinc = 0;
Justin M. Forbes 45e84a
+    cris_evaluate_flags(dc);
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    tcg_gen_mov_tl(taddr, addr);
Justin M. Forbes 45e84a
+    tcg_gen_mov_tl(tval, val);
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    /* Store only if F flag isn't set */
Justin M. Forbes 45e84a
+    tcg_gen_andi_tl(t1, cpu_PR[PR_CCS], F_FLAG_V10);
Justin M. Forbes 45e84a
+    tcg_gen_brcondi_tl(TCG_COND_NE, t1, 0, l1);
Justin M. Forbes 45e84a
+    if (size == 1) {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st8(tval, taddr, mem_index);
Justin M. Forbes 45e84a
+    } else if (size == 2) {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st16(tval, taddr, mem_index);
Justin M. Forbes 45e84a
+    } else {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st32(tval, taddr, mem_index);
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+    gen_set_label(l1);
Justin M. Forbes 45e84a
+    tcg_gen_shri_tl(t1, t1, 1);  /* shift F to P position */
Justin M. Forbes 45e84a
+    tcg_gen_or_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], t1); /*P=F*/
Justin M. Forbes 45e84a
+    tcg_temp_free(t1);
Justin M. Forbes 45e84a
+    tcg_temp_free(tval);
Justin M. Forbes 45e84a
+    tcg_temp_free(taddr);
Justin M. Forbes 45e84a
+}
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+static void gen_store_v10(DisasContext *dc, TCGv addr, TCGv val,
Justin M. Forbes 45e84a
+                       unsigned int size)
Justin M. Forbes 45e84a
+{
Justin M. Forbes 45e84a
+    int mem_index = cpu_mmu_index(dc->env);
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    /* If we get a fault on a delayslot we must keep the jmp state in
Justin M. Forbes 45e84a
+       the cpu-state to be able to re-execute the jmp.  */
Justin M. Forbes 45e84a
+    if (dc->delayed_branch == 1) {
Justin M. Forbes 45e84a
+        cris_store_direct_jmp(dc);
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    /* Conditional writes. We only support the kind were X is known
Justin M. Forbes 45e84a
+       at translation time.  */
Justin M. Forbes 45e84a
+    if (dc->flagx_known && dc->flags_x) {
Justin M. Forbes 45e84a
+        gen_store_v10_conditional(dc, addr, val, size, mem_index);
Justin M. Forbes 45e84a
+        return;
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    if (size == 1) {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st8(val, addr, mem_index);
Justin M. Forbes 45e84a
+    } else if (size == 2) {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st16(val, addr, mem_index);
Justin M. Forbes 45e84a
+    } else {
Justin M. Forbes 45e84a
+        tcg_gen_qemu_st32(val, addr, mem_index);
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+}
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
 /* Prefix flag and register are used to handle the more complex
Justin M. Forbes 45e84a
    addressing modes.  */
Justin M. Forbes 45e84a
 static void cris_set_prefix(DisasContext *dc)
Justin M. Forbes 45e84a
@@ -313,7 +372,8 @@ static unsigned int dec10_setclrf(DisasContext *dc)
Justin M. Forbes 45e84a
     if (set) {
Justin M. Forbes 45e84a
         tcg_gen_ori_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], flags);
Justin M. Forbes 45e84a
     } else {
Justin M. Forbes 45e84a
-        tcg_gen_andi_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS], ~flags);
Justin M. Forbes 45e84a
+        tcg_gen_andi_tl(cpu_PR[PR_CCS], cpu_PR[PR_CCS],
Justin M. Forbes 45e84a
+                        ~(flags|F_FLAG_V10|P_FLAG_V10));
Justin M. Forbes 45e84a
     }
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
     dc->flags_uptodate = 1;
Justin M. Forbes 45e84a
@@ -723,7 +783,7 @@ static unsigned int dec10_ind_move_r_m(DisasContext *dc, unsigned int size)
Justin M. Forbes 45e84a
     LOG_DIS("move.%d $r%d, [$r%d]\n", dc->size, dc->src, dc->dst);
Justin M. Forbes 45e84a
     addr = tcg_temp_new();
Justin M. Forbes 45e84a
     crisv10_prepare_memaddr(dc, addr, size);
Justin M. Forbes 45e84a
-    gen_store(dc, addr, cpu_R[dc->dst], size);
Justin M. Forbes 45e84a
+    gen_store_v10(dc, addr, cpu_R[dc->dst], size);
Justin M. Forbes 45e84a
     insn_len += crisv10_post_memaddr(dc, size);
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
     return insn_len;
Justin M. Forbes 45e84a
@@ -767,10 +827,10 @@ static unsigned int dec10_ind_move_pr_m(DisasContext *dc)
Justin M. Forbes 45e84a
         t0 = tcg_temp_new();
Justin M. Forbes 45e84a
         cris_evaluate_flags(dc);
Justin M. Forbes 45e84a
         tcg_gen_andi_tl(t0, cpu_PR[PR_CCS], ~PFIX_FLAG);
Justin M. Forbes 45e84a
-        gen_store(dc, addr, t0, size);
Justin M. Forbes 45e84a
+        gen_store_v10(dc, addr, t0, size);
Justin M. Forbes 45e84a
         tcg_temp_free(t0);
Justin M. Forbes 45e84a
     } else {
Justin M. Forbes 45e84a
-        gen_store(dc, addr, cpu_PR[dc->dst], size);
Justin M. Forbes 45e84a
+        gen_store_v10(dc, addr, cpu_PR[dc->dst], size);
Justin M. Forbes 45e84a
     }
Justin M. Forbes 45e84a
     t0 = tcg_temp_new();
Justin M. Forbes 45e84a
     insn_len += crisv10_post_memaddr(dc, size);
Justin M. Forbes 45e84a
@@ -793,9 +853,9 @@ static void dec10_movem_r_m(DisasContext *dc)
Justin M. Forbes 45e84a
     tcg_gen_mov_tl(t0, addr);
Justin M. Forbes 45e84a
     for (i = dc->dst; i >= 0; i--) {
Justin M. Forbes 45e84a
         if ((pfix && dc->mode == CRISV10_MODE_AUTOINC) && dc->src == i) {
Justin M. Forbes 45e84a
-            gen_store(dc, addr, t0, 4);
Justin M. Forbes 45e84a
+            gen_store_v10(dc, addr, t0, 4);
Justin M. Forbes 45e84a
         } else {
Justin M. Forbes 45e84a
-            gen_store(dc, addr, cpu_R[i], 4);
Justin M. Forbes 45e84a
+            gen_store_v10(dc, addr, cpu_R[i], 4);
Justin M. Forbes 45e84a
         }
Justin M. Forbes 45e84a
         tcg_gen_addi_tl(addr, addr, 4);
Justin M. Forbes 45e84a
     }
Justin M. Forbes 45e84a
-- 
Justin M. Forbes 45e84a
1.7.7.5
Justin M. Forbes 45e84a