qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] target/nios2: Use gen_io_start/end around wrctl instruction.


From: Peter Maydell
Subject: Re: [PATCH] target/nios2: Use gen_io_start/end around wrctl instruction.
Date: Thu, 18 Jun 2020 18:31:16 +0100

On Thu, 18 Jun 2020 at 04:50, wentongw <wentong.wu@intel.com> wrote:
>
> From: Wentong Wu <wentong.wu@intel.com>
>
> wrctl instruction on nios2 target will cause checking cpu interrupt,
> but tcg_handle_interrupt() will call cpu_abort() if the CPU gets an
> interrupt while it's not in a 'can do IO' state, so around wrctl
> instruction add gen_io_start/end.
>
> Signed-off-by: Wentong Wu <wentong.wu@intel.com>
> ---
>  target/nios2/translate.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/target/nios2/translate.c b/target/nios2/translate.c
> index e17656e6..deaefcaf 100644
> --- a/target/nios2/translate.c
> +++ b/target/nios2/translate.c
> @@ -32,6 +32,7 @@
>  #include "exec/cpu_ldst.h"
>  #include "exec/translator.h"
>  #include "qemu/qemu-print.h"
> +#include "exec/gen-icount.h"
>
>  /* is_jmp field values */
>  #define DISAS_JUMP    DISAS_TARGET_0 /* only pc was modified dynamically */
> @@ -518,7 +519,13 @@ static void wrctl(DisasContext *dc, uint32_t code, 
> uint32_t flags)
>      /* If interrupts were enabled using WRCTL, trigger them. */
>  #if !defined(CONFIG_USER_ONLY)
>      if ((instr.imm5 + CR_BASE) == CR_STATUS) {
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_start();
> +        }
>          gen_helper_check_interrupts(dc->cpu_env);
> +        if (tb_cflags(dc->tb) & CF_USE_ICOUNT) {
> +            gen_io_end();
> +        }

You also need to end the TB, which we should do whether
we're using icount or not. This is awkward because nios2 has
not correctly implemented the DISAS_UPDATE that is the right
way to do that. So you'll need some preliminary patches:

Patch 1: Implement and use DISAS_NORETURN
 + the current places in t_gen_helper_raise_exception() and
   gen_exception() that set dc->is_jmp = DISAS_UPDATE
   should instead set it to DISAS_NORETURN. (This is because
   they both call gen_helper_raise_exception() and at runtime
   execution will never return from that helper call.)
 + In gen_intermediate_code(), in the "switch (dc->is_jmp)"
   you need a new "case DISAS_NORETURN:" which goes with
   DISAS_TB_JUMP as another kind of "nothing more to generate".

Patch 2: Make DISAS_UPDATE write PC back to CPU state
 + Move the "case DISAS_UPDATE:" from being like DISAS_JUMP
   up so it does the same thing as DISAS_NEXT (ie explicitly
   writes the PC back into the cpu state before doing a
   tcg_gen_exit_tb()). This is OK because patch 1 removed
   the only two previous users of it, so we don't break
   anything by bringing its semantics into line with how
   most targets use it.

Patch 3: this patch to use gen_io_start/end
 + You can now put "dc->is_jmp = DISAS_UPDATE;" inside the
   "is this a CR_STATUS write" if() block, which should
   cause the wrctl to always end the TB.

thanks
-- PMM



reply via email to

[Prev in Thread] Current Thread [Next in Thread]