From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KyIge-0008CC-Lr for qemu-devel@nongnu.org; Thu, 06 Nov 2008 23:11:08 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KyIgc-0008Bw-Bz for qemu-devel@nongnu.org; Thu, 06 Nov 2008 23:11:07 -0500 Received: from [199.232.76.173] (port=57986 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KyIgc-0008Bm-7G for qemu-devel@nongnu.org; Thu, 06 Nov 2008 23:11:06 -0500 Received: from csl.cornell.edu ([128.84.224.10]:1811 helo=vlsi.csl.cornell.edu) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KyIgb-0000Ir-HD for qemu-devel@nongnu.org; Thu, 06 Nov 2008 23:11:05 -0500 Received: from stanley.csl.cornell.edu (stanley.csl.cornell.edu [128.84.224.15]) by vlsi.csl.cornell.edu (8.13.4/8.13.4) with ESMTP id mA74AsKW058732 for ; Thu, 6 Nov 2008 23:10:59 -0500 (EST) Date: Thu, 6 Nov 2008 23:10:54 -0500 (EST) From: Vince Weaver Message-ID: <20081106230635.U85421@stanley.csl.cornell.edu> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: [Qemu-devel] [PATCH] alpha ldl_l stl_c fix Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Hello The following patch is needed for a hello world binary to run under alpha-linux-user. The issue is the ldl_l and stl_c instructions. The current implementation is a bit confused. ldl_l should set the lock bit, and write the address to a table stl_c should write to memory only if lock bit is set, then return the lock_bit, then reset the lock_bit to zero The current code does a weird mix of these things that don't seem to work. This patch fixes things enough for me for hello_world to work, but it still isn't correct if we ever want to use these instructions to implement atomic loads/stores or run multithreaded code. Note... the patch includes a commented out branch. For proper emulation that branch should be included, but for some reason on my x86_64 system if the branch is included, then the memory address calculation is converted to nops for some reason (leading to a segfault). I'm not sure why that is happening. Vince Index: target-alpha/translate.c =================================================================== --- target-alpha/translate.c (revision 5643) +++ target-alpha/translate.c (working copy) @@ -138,13 +138,13 @@ static always_inline void gen_qemu_ldl_l (TCGv t0, TCGv t1, int flags) { - tcg_gen_mov_i64(cpu_lock, t1); + tcg_gen_movi_i64(cpu_lock, 1); tcg_gen_qemu_ld32s(t0, t1, flags); } static always_inline void gen_qemu_ldq_l (TCGv t0, TCGv t1, int flags) { - tcg_gen_mov_i64(cpu_lock, t1); + tcg_gen_movi_i64(cpu_lock, 1); tcg_gen_qemu_ld64(t0, t1, flags); } @@ -201,34 +201,27 @@ static always_inline void gen_qemu_stl_c (TCGv t0, TCGv t1, int flags) { - int l1, l2; + int l1; l1 = gen_new_label(); - l2 = gen_new_label(); - tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1); +// tcg_gen_brcondi_i64(TCG_COND_EQ, cpu_lock, 0, l1); tcg_gen_qemu_st32(t0, t1, flags); - tcg_gen_movi_i64(t0, 0); - tcg_gen_br(l2); gen_set_label(l1); - tcg_gen_movi_i64(t0, 1); - gen_set_label(l2); - tcg_gen_movi_i64(cpu_lock, -1); + tcg_gen_mov_i64(t0, cpu_lock); + tcg_gen_movi_i64(cpu_lock, 0); + } static always_inline void gen_qemu_stq_c (TCGv t0, TCGv t1, int flags) { - int l1, l2; + int l1; l1 = gen_new_label(); - l2 = gen_new_label(); - tcg_gen_brcond_i64(TCG_COND_NE, cpu_lock, t1, l1); +// tcg_gen_brcondi_i64(TCG_COND_EQ, cpu_lock, 0, l1); tcg_gen_qemu_st64(t0, t1, flags); - tcg_gen_movi_i64(t0, 0); - tcg_gen_br(l2); gen_set_label(l1); - tcg_gen_movi_i64(t0, 1); - gen_set_label(l2); - tcg_gen_movi_i64(cpu_lock, -1); + tcg_gen_movi_i64(t0, cpu_lock); + tcg_gen_movi_i64(cpu_lock, 0); } static always_inline void gen_store_mem (DisasContext *ctx,