qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Laurent Vivier <laurent@vivier.eu>, qemu-devel@nongnu.org
Cc: Thomas Huth <huth@tuxfamily.org>
Subject: Re: [Qemu-devel] [PATCH v5 07/17] target/m68k: add chk and chk2
Date: Tue, 2 Jan 2018 08:41:20 -0800	[thread overview]
Message-ID: <1acae1a1-68f8-9b16-ecde-7b18d1c89662@linaro.org> (raw)
In-Reply-To: <20180102011032.30056-8-laurent@vivier.eu>

On 01/01/2018 05:10 PM, Laurent Vivier wrote:
> +    SRC_EA(env, tsrc, opsize, 1, NULL);
> +    src = tcg_temp_local_new();
> +    tcg_gen_mov_i32(src, tsrc);
> +
> +    reg = tcg_temp_local_new();
> +    gen_ext(reg, DREG(insn, 9), opsize, 1);
> +    gen_flush_flags(s);
> +    update_cc_op(s);
> +
> +    l1 = gen_new_label();
> +    l2 = gen_new_label();
> +    tcg_gen_brcondi_i32(TCG_COND_GE, reg, 0, l1);
> +    tcg_gen_movi_i32(QREG_CC_N, -1);
> +    tcg_gen_movi_i32(QREG_PC, s->pc);
> +    gen_raise_exception(EXCP_CHK);
> +    tcg_gen_br(l2);

Unreachable branch after exception.

> +    gen_set_label(l1);
> +    tcg_gen_brcond_i32(TCG_COND_LE, reg, src, l2);
> +    tcg_gen_movi_i32(QREG_CC_N, 0);
> +    tcg_gen_movi_i32(QREG_PC, s->pc);
> +    gen_raise_exception(EXCP_CHK);
> +    gen_set_label(l2);
> +    tcg_temp_free(src);
> +    tcg_temp_free(reg);

Does real hardware not change flags at all if the chk passes?  The manual says
it is undefined, which would greatly simplify all this.  Especially just
assigning reg to CC_N...

Generally I put conditional traps like this into a helper, which allows
straight-line optimization of the non-trapping path to continue.  In this case,
something like

void HELPER(chk)(CPUM68kState *env, int32_t val, int32_t ub)
{
    if (val < 0 || val > ub) {
        CPUState *cs = CPU(m68k_env_get_cpu(env));

	/* Recover PC and CC_OP for the beginning of the insn.  */
        cpu_restore_state(cs, GETPC());

        /* Adjust PC and FLAGS to end of the insn.  */
        env->pc += 2;
        helper_flush_flags(env, env->cc_op);
        env->cc_n = val;

        cs->exception_index = EXCP_CHK;
        cpu_loop_exit(cs);
    }
}


r~

  reply	other threads:[~2018-01-02 16:41 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-02  1:10 [Qemu-devel] [PATCH v5 00/17] target/m68k: supervisor mode (part 1) Laurent Vivier
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 01/17] target-m68k: sync CC_OP before gen_jmp_tb() Laurent Vivier
2018-01-02 16:01   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 02/17] target/m68k: fix gen_get_ccr() Laurent Vivier
2018-01-02 16:04   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 03/17] linux-user, m68k: correctly manage SR in context Laurent Vivier
2018-01-02 16:06   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 04/17] target-m68k: use insn_pc to generate instruction fault address Laurent Vivier
2018-01-02 16:08   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 05/17] target/m68k: add CPU_LOG_INT trace Laurent Vivier
2018-01-02 16:10   ` Richard Henderson
2018-01-02 18:37     ` Laurent Vivier
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 06/17] target/m68k: manage 680x0 stack frames Laurent Vivier
2018-01-02 16:16   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 07/17] target/m68k: add chk and chk2 Laurent Vivier
2018-01-02 16:41   ` Richard Henderson [this message]
2018-01-02 23:33     ` Laurent Vivier
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 08/17] target/m68k: add move16 Laurent Vivier
2018-01-02 16:50   ` Richard Henderson
2018-01-02 18:42     ` Laurent Vivier
2018-01-02 23:49       ` Richard Henderson
2018-01-02 23:53         ` Laurent Vivier
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 09/17] target/m68k: softmmu cleanup Laurent Vivier
2018-01-02 16:52   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 10/17] target/m68k: add cpush/cinv Laurent Vivier
2018-01-02 16:53   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 11/17] target/m68k: add reset Laurent Vivier
2018-01-02 16:54   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 12/17] target/m68k: implement fsave/frestore Laurent Vivier
2018-01-02 16:58   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 13/17] target/m68k: move CCR/SR functions Laurent Vivier
2018-01-02 17:00   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 14/17] target/m68k: add 680x0 "move to SR" instruction Laurent Vivier
2018-01-02 17:02   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 15/17] target/m68k: add andi/ori/eori to SR/CCR Laurent Vivier
2018-01-02 17:06   ` Richard Henderson
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 16/17] target/m68k: add the Interrupt Stack Pointer Laurent Vivier
2018-01-02 17:13   ` Richard Henderson
2018-01-02 18:50     ` Laurent Vivier
2018-01-02  1:10 ` [Qemu-devel] [PATCH v5 17/17] target/m68k: fix m68k_cpu_dump_state() Laurent Vivier
2018-01-02 17:14   ` Richard Henderson
2018-01-02  1:31 ` [Qemu-devel] [PATCH v5 00/17] target/m68k: supervisor mode (part 1) no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1acae1a1-68f8-9b16-ecde-7b18d1c89662@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=huth@tuxfamily.org \
    --cc=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).