qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>,
	qemu-devel@nongnu.org
Cc: bcain@quicinc.com, sidneym@quicinc.com, ale@rev.ng, anjo@rev.ng,
	ltaylorsimpson@gmail.com
Subject: Re: [PATCH v2] Hexagon: add PC alignment check and exception
Date: Mon, 29 Apr 2024 13:59:10 -0700	[thread overview]
Message-ID: <29ebfe76-d3c3-456b-86b0-7a371125844f@linaro.org> (raw)
In-Reply-To: <e559b521d1920f804df10244c8c07564431aeba5.1714419461.git.quic_mathbern@quicinc.com>

On 4/29/24 12:40, Matheus Tavares Bernardino wrote:
> @@ -144,6 +148,9 @@ static inline void cpu_get_tb_cpu_state(CPUHexagonState *env, vaddr *pc,
>           hex_flags = FIELD_DP32(hex_flags, TB_FLAGS, IS_TIGHT_LOOP, 1);
>       }
>       *flags = hex_flags;
> +    if (*pc & PCALIGN_MASK) {
> +        hexagon_raise_exception_err(env, HEX_EXCP_PC_NOT_ALIGNED, 0);
> +    }
>   }

With the test here ...

> diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
> index 47a870f42d..26e6809976 100644
> --- a/target/hexagon/translate.c
> +++ b/target/hexagon/translate.c
> @@ -346,8 +346,9 @@ static void mark_implicit_pred_writes(DisasContext *ctx)
>   static bool pkt_raises_exception(Packet *pkt)
>   {
>       if (check_for_attrib(pkt, A_LOAD) ||
> -        check_for_attrib(pkt, A_STORE)) {
> -        return true;
> +        check_for_attrib(pkt, A_STORE) ||
> +        check_for_attrib(pkt, A_COF)) {
> +            return true;
>       }

... you don't need a change here, because we don't raise the exception from within the packet.


> +run-unaligned_pc run-unaligned_pc_endloop run-unaligned_pc_multi_cof:
> +	$(call run-test, $<, $(QEMU) $< 2> $<.stderr,"$< on $(TARGET_NAME)"); \
> +	if [ $$? -ne 1 ] ; then \
> +		return 1; \
> +	fi
> +	$(call quiet-command, \
> +		grep -q "exception 0x1e" $<.stderr, \
> +		"GREP", "exception 0x1e");

What's missing in the patch set is handling this exception in 
linux-user/hexagon/cpu_loop.c.  This would correspond to misaligned_instruction() in the 
kernel.

At which point you could improve the test case to set up a signal handler in C, generate 
the exception, and test for correct values in the signal frame.


r~


PS: I think the kernel could be improved to use

    force_sig_fault(SIGBUS, BUS_ADRALN, regs->r31);
instead of
    force_sig(SIGBUS);

and similarly for misaligned_data_{load,store}.



      reply	other threads:[~2024-04-29 20:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-29 19:40 [PATCH v2] Hexagon: add PC alignment check and exception Matheus Tavares Bernardino
2024-04-29 20:59 ` Richard Henderson [this message]

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=29ebfe76-d3c3-456b-86b0-7a371125844f@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=ale@rev.ng \
    --cc=anjo@rev.ng \
    --cc=bcain@quicinc.com \
    --cc=ltaylorsimpson@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=quic_mathbern@quicinc.com \
    --cc=sidneym@quicinc.com \
    /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).