[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe
From: |
Lionel Landwerlin |
Subject: |
[Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe |
Date: |
Thu, 15 Jan 2009 14:42:37 +0100 |
This is usefull for user emulation where guest threads are emulated
with host threads and atomic guest instructions must keep atomic in
generated host instructions.
Signed-off-by: Lionel Landwerlin <address@hidden>
---
target-sh4/helper.h | 3 +++
target-sh4/op_helper.c | 12 ++++++++++++
target-sh4/translate.c | 5 ++++-
3 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/target-sh4/helper.h b/target-sh4/helper.h
index e665185..887d57a 100644
--- a/target-sh4/helper.h
+++ b/target-sh4/helper.h
@@ -46,4 +46,7 @@ DEF_HELPER_1(fsqrt_DT, i64, i64)
DEF_HELPER_1(ftrc_FT, i32, i32)
DEF_HELPER_1(ftrc_DT, i32, i64)
+DEF_HELPER_0(lock, void)
+DEF_HELPER_0(unlock, void)
+
#include "def-helper.h"
diff --git a/target-sh4/op_helper.c b/target-sh4/op_helper.c
index ead14e3..a11e8d6 100644
--- a/target-sh4/op_helper.c
+++ b/target-sh4/op_helper.c
@@ -615,3 +615,15 @@ uint32_t helper_ftrc_DT(uint64_t t0)
d.ll = t0;
return float64_to_int32_round_to_zero(d.d, &env->fp_status);
}
+
+static spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
+
+void helper_lock(void)
+{
+ spin_lock(&global_cpu_lock);
+}
+
+void helper_unlock(void)
+{
+ spin_unlock(&global_cpu_lock);
+}
diff --git a/target-sh4/translate.c b/target-sh4/translate.c
index bce7463..4762ef7 100644
--- a/target-sh4/translate.c
+++ b/target-sh4/translate.c
@@ -1656,7 +1656,9 @@ static void _decode_opc(DisasContext * ctx)
case 0x401b: /* tas.b @Rn */
{
TCGv addr, val;
- addr = tcg_temp_local_new();
+
+ gen_helper_lock();
+ addr = tcg_temp_local_new();
tcg_gen_mov_i32(addr, REG(B11_8));
val = tcg_temp_local_new();
tcg_gen_qemu_ld8u(val, addr, ctx->memidx);
@@ -1665,6 +1667,7 @@ static void _decode_opc(DisasContext * ctx)
tcg_gen_qemu_st8(val, addr, ctx->memidx);
tcg_temp_free(val);
tcg_temp_free(addr);
+ gen_helper_unlock();
}
return;
case 0xf00d: /* fsts FPUL,FRn - FPSCR: Nothing */
--
1.5.6.5
- [Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe,
Lionel Landwerlin <=