qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe
@ 2009-01-15 13:42 Lionel Landwerlin
  2009-01-15 17:20 ` Paul Brook
  0 siblings, 1 reply; 2+ messages in thread
From: Lionel Landwerlin @ 2009-01-15 13:42 UTC (permalink / raw)
  To: qemu-devel


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 <lionel.landwerlin@openwide.fr>
---
 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe
  2009-01-15 13:42 [Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe Lionel Landwerlin
@ 2009-01-15 17:20 ` Paul Brook
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Brook @ 2009-01-15 17:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Lionel Landwerlin

On Thursday 15 January 2009, Lionel Landwerlin wrote:
> 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.

Doesn't this deadlock if the instruction faults?

Paul

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-01-15 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-15 13:42 [Qemu-devel] [PATCH] sh4: Make atomic tas.b instruction thread safe Lionel Landwerlin
2009-01-15 17:20 ` Paul Brook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).