Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L6OcZ-0008IK-1u for qemu-devel@nongnu.org; Sat, 29 Nov 2008 07:08:23 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L6OcV-0008H1-QN for qemu-devel@nongnu.org; Sat, 29 Nov 2008 07:08:21 -0500 Received: from [199.232.76.173] (port=36995 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L6OcU-0008GP-MG for qemu-devel@nongnu.org; Sat, 29 Nov 2008 07:08:19 -0500 Received: from fmmailgate03.web.de ([217.72.192.234]:35207) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L6OcT-0002Kq-PC for qemu-devel@nongnu.org; Sat, 29 Nov 2008 07:08:18 -0500 Message-Id: <2337323E-9792-46C3-92CC-D69368530C57@web.de> From: =?ISO-8859-1?Q?Andreas_F=E4rber?= Content-Type: multipart/mixed; boundary=Apple-Mail-7-545184058 Mime-Version: 1.0 (Apple Message framework v929.2) Date: Sat, 29 Nov 2008 13:08:07 +0100 Sender: andreas.faerber@web.de Subject: [Qemu-devel] [RFC] ppc: rfi and friends 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 Cc: =?ISO-8859-1?Q?Aur=E9lien_Jarno?= --Apple-Mail-7-545184058 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hello, This patch migrates op_40x_rfci et al. to TCG. (op_40x_rfci is the current dyngen breakage on OSX/gcc4.) I believe I have spotted and fixed some ops which were lacking env- >spr[...] in their call to __do_rfi. The TCG code is still untested since it still breaks for op_440_dlmzb. Two issues remain with my patch: hreg_store_msr and cpu_dump_rfi. Is cpu_dump_rfi still needed at all? hreg_store_msr is defined in helper_regs.h as always_inline - should we convert it to an inline TCG function or call it as a helper? Thanks for any help, Andreas --Apple-Mail-7-545184058 Content-Disposition: attachment; filename=op_40x_rfci.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="op_40x_rfci.diff" Content-Transfer-Encoding: 7bit diff --git a/target-ppc/op.c b/target-ppc/op.c index 5d2cfa1..cecb89c 100644 --- a/target-ppc/op.c +++ b/target-ppc/op.c @@ -298,26 +298,6 @@ void OPPROTO op_wait (void) /* Return from interrupt */ #if !defined(CONFIG_USER_ONLY) -void OPPROTO op_rfi (void) -{ - do_rfi(); - RETURN(); -} - -#if defined(TARGET_PPC64) -void OPPROTO op_rfid (void) -{ - do_rfid(); - RETURN(); -} - -void OPPROTO op_hrfid (void) -{ - do_hrfid(); - RETURN(); -} -#endif - /* Exception vectors */ void OPPROTO op_store_excp_prefix (void) { @@ -710,12 +690,6 @@ void OPPROTO op_POWER_rac (void) do_POWER_rac(); RETURN(); } - -void OPPROTO op_POWER_rfsvc (void) -{ - do_POWER_rfsvc(); - RETURN(); -} #endif /* PowerPC 602 specific instruction */ @@ -741,33 +715,6 @@ void OPPROTO op_store_dcr (void) } #if !defined(CONFIG_USER_ONLY) -/* Return from critical interrupt : - * same as rfi, except nip & MSR are loaded from SRR2/3 instead of SRR0/1 - */ -void OPPROTO op_40x_rfci (void) -{ - do_40x_rfci(); - RETURN(); -} - -void OPPROTO op_rfci (void) -{ - do_rfci(); - RETURN(); -} - -void OPPROTO op_rfdi (void) -{ - do_rfdi(); - RETURN(); -} - -void OPPROTO op_rfmci (void) -{ - do_rfmci(); - RETURN(); -} - void OPPROTO op_wrte (void) { /* We don't call do_store_msr here as we won't trigger diff --git a/target-ppc/op_helper.c b/target-ppc/op_helper.c index 6addc74..c131cb8 100644 --- a/target-ppc/op_helper.c +++ b/target-ppc/op_helper.c @@ -1373,55 +1373,6 @@ void do_store_msr (void) raise_exception(env, T0); } } - -static always_inline void __do_rfi (target_ulong nip, target_ulong msr, - target_ulong msrm, int keep_msrh) -{ -#if defined(TARGET_PPC64) - if (msr & (1ULL << MSR_SF)) { - nip = (uint64_t)nip; - msr &= (uint64_t)msrm; - } else { - nip = (uint32_t)nip; - msr = (uint32_t)(msr & msrm); - if (keep_msrh) - msr |= env->msr & ~((uint64_t)0xFFFFFFFF); - } -#else - nip = (uint32_t)nip; - msr &= (uint32_t)msrm; -#endif - /* XXX: beware: this is false if VLE is supported */ - env->nip = nip & ~((target_ulong)0x00000003); - hreg_store_msr(env, msr, 1); -#if defined (DEBUG_OP) - cpu_dump_rfi(env->nip, env->msr); -#endif - /* No need to raise an exception here, - * as rfi is always the last insn of a TB - */ - env->interrupt_request |= CPU_INTERRUPT_EXITTB; -} - -void do_rfi (void) -{ - __do_rfi(env->spr[SPR_SRR0], env->spr[SPR_SRR1], - ~((target_ulong)0xFFFF0000), 1); -} - -#if defined(TARGET_PPC64) -void do_rfid (void) -{ - __do_rfi(env->spr[SPR_SRR0], env->spr[SPR_SRR1], - ~((target_ulong)0xFFFF0000), 0); -} - -void do_hrfid (void) -{ - __do_rfi(env->spr[SPR_HSRR0], env->spr[SPR_HSRR1], - ~((target_ulong)0xFFFF0000), 0); -} -#endif #endif void helper_tw (target_ulong arg1, target_ulong arg2, uint32_t flags) @@ -1615,11 +1566,6 @@ void do_POWER_rac (void) env->nb_BATs = nb_BATs; } -void do_POWER_rfsvc (void) -{ - __do_rfi(env->lr, env->ctr, 0x0000FFFF, 0); -} - void do_store_hid0_601 (void) { uint32_t hid0; @@ -1715,30 +1661,6 @@ void do_store_dcr (void) } #if !defined(CONFIG_USER_ONLY) -void do_40x_rfci (void) -{ - __do_rfi(env->spr[SPR_40x_SRR2], env->spr[SPR_40x_SRR3], - ~((target_ulong)0xFFFF0000), 0); -} - -void do_rfci (void) -{ - __do_rfi(env->spr[SPR_BOOKE_CSRR0], SPR_BOOKE_CSRR1, - ~((target_ulong)0x3FFF0000), 0); -} - -void do_rfdi (void) -{ - __do_rfi(env->spr[SPR_BOOKE_DSRR0], SPR_BOOKE_DSRR1, - ~((target_ulong)0x3FFF0000), 0); -} - -void do_rfmci (void) -{ - __do_rfi(env->spr[SPR_BOOKE_MCSRR0], SPR_BOOKE_MCSRR1, - ~((target_ulong)0x3FFF0000), 0); -} - void do_load_403_pb (int num) { T0 = env->pb[num]; diff --git a/target-ppc/op_helper.h b/target-ppc/op_helper.h index 1c046d8..302a9fe 100644 --- a/target-ppc/op_helper.h +++ b/target-ppc/op_helper.h @@ -62,11 +62,6 @@ void ppc_store_dump_spr (int sprn, target_ulong val); /* Misc */ #if !defined(CONFIG_USER_ONLY) void do_store_msr (void); -void do_rfi (void); -#if defined(TARGET_PPC64) -void do_rfid (void); -void do_hrfid (void); -#endif void do_load_6xx_tlb (int is_code); void do_load_74xx_tlb (int is_code); #endif @@ -83,7 +78,6 @@ void do_POWER_maskg (void); void do_POWER_mulo (void); #if !defined(CONFIG_USER_ONLY) void do_POWER_rac (void); -void do_POWER_rfsvc (void); void do_store_hid0_601 (void); #endif @@ -102,10 +96,6 @@ void do_440_tlbwe (int word); void do_load_dcr (void); void do_store_dcr (void); #if !defined(CONFIG_USER_ONLY) -void do_40x_rfci (void); -void do_rfci (void); -void do_rfdi (void); -void do_rfmci (void); void do_4xx_tlbre_lo (void); void do_4xx_tlbre_hi (void); void do_4xx_tlbwe_lo (void); diff --git a/target-ppc/translate.c b/target-ppc/translate.c index 95cb482..a0a0408 100644 --- a/target-ppc/translate.c +++ b/target-ppc/translate.c @@ -68,6 +68,7 @@ static TCGv cpu_lr; static TCGv cpu_xer; static TCGv_i32 cpu_fpscr; static TCGv_i32 cpu_access_type; +static TCGv_i32 cpu_interrupt_request; /* dyngen register indexes */ static TCGv cpu_T[3]; @@ -167,6 +168,9 @@ void ppc_translate_init(void) cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0, offsetof(CPUState, access_type), "access_type"); + cpu_interrupt_request = tcg_global_mem_new_i32(TCG_AREG0, + offsetof(CPUState, interrupt_request), "interrupt_request"); + /* register helpers */ #define GEN_HELPER 2 #include "helper.h" @@ -277,6 +281,40 @@ static always_inline void gen_update_nip (DisasContext *ctx, target_ulong nip) tcg_gen_movi_tl(cpu_nip, (uint32_t)nip); } +static always_inline void gen_do_rfi(TCGv nip, TCGv msr, target_ulong msrm, int keep_msrh) +{ +#if defined(TARGET_PPC64) + int endLabel = gen_new_label(); + TCGv_i64 t0 = tcg_temp_new_i64(); + tcg_gen_andi_i64(t0, msr, (1ULL << MSR_SF)); + tcg_gen_andi_i64(msr, msr, msrm); + tcg_gen_brcondi_i64(TCG_COND_EQ, t0, 0, endLabel); + tcg_temp_free_i64(t0); + + tcg_gen_andi_i64(nip, nip, 0xFFFFFFFF); + tcg_gen_andi_i64(msr, msr, 0xFFFFFFFF); + if (keep_msrh) { + t0 = tcg_temp_new_i64(); + tcg_gen_andi_i64(t0, cpu_msr, ~((uint64_t)0xFFFFFFFF); + tcg_gen_or_i64(msr, msr, t0); + tcg_temp_free_i64(t0); + } + gen_set_label(endLabel); +#else + tcg_gen_andi_tl(msr, msr, msrm); +#endif + /* XXX: beware: this is false if VLE is supported */ + tcg_gen_andi_tl(cpu_nip, nip, ~((target_ulong)0x00000003); +// hreg_store_msr(env, msr, 1); +#if defined (DEBUG_OP) + /* XXX cpu_dump_rfi(env->nip, env->msr); */ +#endif + /* No need to raise an exception here, + * as rfi is always the last insn of a TB + */ + tcg_gen_ori_i32(cpu_interrupt_request, cpu_interrupt_request, CPU_INTERRUPT_EXITTB); +} + #define GEN_EXCP(ctx, excp, error) \ do { \ TCGv_i32 t0 = tcg_const_i32(excp); \ @@ -3745,7 +3783,8 @@ GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW) GEN_EXCP_PRIVOPC(ctx); return; } - gen_op_rfi(); + gen_do_rfi(cpu_spr[SPR_SRR0], cpu_spr[SPR_SRR1], + ~((target_ulong)0xFFFF0000), 1); GEN_SYNC(ctx); #endif } @@ -3761,7 +3800,8 @@ GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B) GEN_EXCP_PRIVOPC(ctx); return; } - gen_op_rfid(); + gen_do_rfi(cpu_spr[SPR_SRR0], cpu_spr[SPR_SRR1], + ~((target_ulong)0xFFFF0000), 0); GEN_SYNC(ctx); #endif } @@ -3776,7 +3816,8 @@ GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H) GEN_EXCP_PRIVOPC(ctx); return; } - gen_op_hrfid(); + gen_do_rfi(cpu_spr[SPR_HSRR0], cpu_spr[SPR_HSRR1], + ~((target_ulong)0xFFFF0000), 0); GEN_SYNC(ctx); #endif } @@ -5087,7 +5128,7 @@ GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER) GEN_EXCP_PRIVOPC(ctx); return; } - gen_op_POWER_rfsvc(); + gen_do_rfi(cpu_lr, cpu_ctr, 0x0000FFFF, 0); GEN_SYNC(ctx); #endif } @@ -5631,7 +5672,8 @@ GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP) return; } /* Restore CPU state */ - gen_op_40x_rfci(); + gen_do_rfi(cpu_spr[SPR_40x_SRR2], cpu_spr[SPR_40x_SRR3], + ~((target_ulong)0xFFFF0000), 0); GEN_SYNC(ctx); #endif } @@ -5646,7 +5688,8 @@ GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE) return; } /* Restore CPU state */ - gen_op_rfci(); + gen_do_rfi(cpu_spr[SPR_BOOKE_CSRR0], cpu_spr[SPR_BOOKE_CSRR1] + ~((target_ulong)0x3FFF0000), 0); GEN_SYNC(ctx); #endif } @@ -5663,7 +5706,8 @@ GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI) return; } /* Restore CPU state */ - gen_op_rfdi(); + gen_do_rfi(cpu_spr[SPR_BOOKE_DSRR0], cpu_spr[SPR_BOOKE_DSRR1], + ~((target_ulong)0x3FFF0000), 0); GEN_SYNC(ctx); #endif } @@ -5679,7 +5723,8 @@ GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI) return; } /* Restore CPU state */ - gen_op_rfmci(); + gen_do_rfi(cpu_spr[SPR_BOOKE_MCSRR0], cpu_spr[SPR_BOOKE_MCSRR1], + ~((target_ulong)0x3FFF0000), 0); GEN_SYNC(ctx); #endif } --Apple-Mail-7-545184058 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit --Apple-Mail-7-545184058--