From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCtwz-0007J5-W1 for qemu-devel@nongnu.org; Tue, 05 Mar 2013 10:38:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCtwx-0001QM-JS for qemu-devel@nongnu.org; Tue, 05 Mar 2013 10:38:45 -0500 Received: from mail-pb0-f50.google.com ([209.85.160.50]:33062) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCtwx-0001QE-C3 for qemu-devel@nongnu.org; Tue, 05 Mar 2013 10:38:43 -0500 Received: by mail-pb0-f50.google.com with SMTP id up1so4534514pbc.23 for ; Tue, 05 Mar 2013 07:38:42 -0800 (PST) Sender: Richard Henderson Message-ID: <5136117D.7050206@twiddle.net> Date: Tue, 05 Mar 2013 07:38:37 -0800 From: Richard Henderson MIME-Version: 1.0 References: <1362400146-24782-1-git-send-email-green@moxielogic.com> <1362400146-24782-2-git-send-email-green@moxielogic.com> In-Reply-To: <1362400146-24782-2-git-send-email-green@moxielogic.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v8 1/4] Add moxie target code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Green Cc: qemu-devel@nongnu.org On 03/04/2013 04:29 AM, Anthony Green wrote: > +void tlb_fill(CPUMoxieState *env, target_ulong addr, int is_write, int mmu_idx, > + uintptr_t retaddr) > +{ > + int ret; > + > + ret = cpu_moxie_handle_mmu_fault(env, addr, is_write, mmu_idx); > + if (unlikely(ret)) { > + if (retaddr) { > + cpu_restore_state(env, retaddr); > + } > + } > + cpu_loop_exit(env); > +} > + > +void helper_raise_exception(CPUMoxieState *env, uint32_t pc, int ex) > +{ > + env->exception_index = ex; > + /* Stash the exception type. */ > + env->sregs[2] = ex; > + /* Stash the address where the exception occurred. */ > + env->sregs[5] = pc; > + /* Jump the the exception handline routine. */ > + env->pc = env->sregs[1]; > + cpu_loop_exit(env); > +} To be fixed later: The cpu_restore_state trick is not exclusive to memory operations. Any kind of runtime exception can use it. Which means... > + > +uint32_t helper_div(CPUMoxieState *env, uint32_t pc, uint32_t a, uint32_t b) > +{ > + if (unlikely(b == 0)) { > + helper_raise_exception(env, pc, MOXIE_EX_DIV0); > + return 0; > + } You need not store to or pass cpu_pc into the division routines. > +DEF_HELPER_4(div, i32, env, i32, i32, i32) > +DEF_HELPER_4(udiv, i32, env, i32, i32, i32) Should use HELPER_FLAGS_4 with TCG_CALL_NO_WG, indicating that the function does not write to tcg global registers. (It does read them, via the exception path.) r~