From: <ltaylorsimpson@gmail.com>
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>, <richard.henderson@linaro.org>,
"'Laurent Vivier'" <laurent@vivier.eu>
Subject: RE: [PATCH v3] Hexagon: add PC alignment check and exception
Date: Tue, 30 Apr 2024 14:41:48 -0500 [thread overview]
Message-ID: <02cb01da9b36$719b3fb0$54d1bf10$@gmail.com> (raw)
In-Reply-To: <5c90567ec28723865e144f386b36f5b676b7a5d3.1714486874.git.quic_mathbern@quicinc.com>
> -----Original Message-----
> From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> Sent: Tuesday, April 30, 2024 9:25 AM
> To: qemu-devel@nongnu.org
> Cc: bcain@quicinc.com; sidneym@quicinc.com; ale@rev.ng; anjo@rev.ng;
> ltaylorsimpson@gmail.com; richard.henderson@linaro.org; Laurent Vivier
> <laurent@vivier.eu>
> Subject: [PATCH v3] Hexagon: add PC alignment check and exception
>
> The Hexagon Programmer's Reference Manual says that the exception 0x1e
> should be raised upon an unaligned program counter. Let's implement that
> and also add some tests.
>
> Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> ---
> v2: https://lore.kernel.org/qemu-
> devel/e559b521d1920f804df10244c8c07564431aeba5.1714419461.git.quic_ma
> thbern@quicinc.com/
>
> Thanks for the comments, Richard and Taylor!
>
> Changed in v3:
> - Removed now unnecessary pkt_raises_exception addition.
> - Added HEX_EXCP_PC_NOT_ALIGNED handling at
> linux-user/hexagon/cpu_loop.c.
> - Merged all tests into a C file that uses signal handler to check
> that the exception was raised.
>
> target/hexagon/cpu.h | 7 ++
> target/hexagon/cpu_bits.h | 4 +
> target/hexagon/macros.h | 3 -
> linux-user/hexagon/cpu_loop.c | 4 +
> target/hexagon/op_helper.c | 9 +--
> tests/tcg/hexagon/unaligned_pc.c | 85 ++++++++++++++++++++++
> tests/tcg/hexagon/Makefile.target | 4 +
> tests/tcg/hexagon/unaligned_pc_multi_cof.S | 5 ++
> 8 files changed, 113 insertions(+), 8 deletions(-) create mode 100644
> tests/tcg/hexagon/unaligned_pc.c create mode 100644
> tests/tcg/hexagon/unaligned_pc_multi_cof.S
>
> a/tests/tcg/hexagon/unaligned_pc.c b/tests/tcg/hexagon/unaligned_pc.c
> new file mode 100644
> index 0000000000..1add2d0d99
> --- /dev/null
> +++ b/tests/tcg/hexagon/unaligned_pc.c
> @@ -0,0 +1,85 @@
> +#include <stdio.h>
> +#include <signal.h>
> +#include <setjmp.h>
> +#include <stdlib.h>
> +
> +/* will be changed in signal handler */ volatile sig_atomic_t
> +completed_tests; static jmp_buf after_test; static int nr_tests;
> +
> +void __attribute__((naked)) test_return(void) {
> + asm volatile(
> + "allocframe(#0x8)\n"
> + "r0 = #0xffffffff\n"
> + "framekey = r0\n"
> + "dealloc_return\n"
> + : : : "r0");
Add r29, r30, r31 to clobbers list.
Add framekey to clobbers list (assuming the compiler will take it).
> +}
> +
> +void test_endloop(void)
> +{
> + asm volatile(
> + "loop0(1f, #2)\n"
> + "1: r0 = #0x3\n"
> + "sa0 = r0\n"
> + "{ nop }:endloop0\n"
> + : : : "r0");
> +}
Add sa0, lc0, usr to the clobbers list.
> +
> +void test_multi_cof(void)
> +{
> + asm volatile(
> + "p0 = cmp.eq(r0, r0)\n"
> + "{\n"
> + " if (p0) jump test_multi_cof_unaligned\n"
> + " jump 1f\n"
> + "}\n"
> + "1: nop\n"
> + : : : "p0");
> +}
> +
> +void sigbus_handler(int signum)
> +{
> + /* retore framekey after test_return */
> + asm volatile(
> + "r0 = #0\n"
> + "framekey = r0\n"
> + : : : "r0");
Add framekey to the clobbers list.
> + printf("Test %d complete\n", completed_tests);
> + completed_tests++;
> + siglongjmp(after_test, 1);
> +}
> +
> +void test_done(void)
> +{
> + int err = (completed_tests != nr_tests);
> + puts(err ? "FAIL" : "PASS");
> + exit(err);
> +}
> +
> +typedef void (*test_fn)(void);
> +
> +int main()
> +{
> + test_fn tests[] = { test_return, test_endloop, test_multi_cof,
test_done
> };
> + nr_tests = (sizeof(tests) / sizeof(tests[0])) - 1;
> +
> + struct sigaction sa = {
> + .sa_sigaction = sigbus_handler,
> + .sa_flags = SA_SIGINFO
> + };
> +
> + if (sigaction(SIGBUS, &sa, NULL) < 0) {
> + perror("sigaction");
> + return EXIT_FAILURE;
> + }
> +
> + sigsetjmp(after_test, 1);
> + tests[completed_tests]();
> +
> + /* should never get here */
> + puts("FAIL");
> + return 1;
> +}
> diff --git a/tests/tcg/hexagon/Makefile.target
> b/tests/tcg/hexagon/Makefile.target
> index f839b2c0d5..75139e731c 100644
> --- a/tests/tcg/hexagon/Makefile.target
> +++ b/tests/tcg/hexagon/Makefile.target
> @@ -51,6 +51,7 @@ HEX_TESTS += scatter_gather HEX_TESTS += hvx_misc
> HEX_TESTS += hvx_histogram HEX_TESTS += invalid-slots
> +HEX_TESTS += unaligned_pc
>
> run-and-check-exception = $(call run-test,$2,$3 2>$2.stderr; \
> test $$? -eq 1 && grep -q "exception $(strip $1)" $2.stderr) @@ -
> 108,6 +109,9 @@ preg_alias: preg_alias.c hex_test.h
> read_write_overlap: read_write_overlap.c hex_test.h
> reg_mut: reg_mut.c hex_test.h
>
> +unaligned_pc: unaligned_pc.c unaligned_pc_multi_cof.S
> + $(CC) $(CFLAGS) $(CROSS_CC_GUEST_CFLAGS) -mv73 $^ -o $@
> $(LDFLAGS)
> +
> # This test has to be compiled for the -mv67t target
> usr: usr.c hex_test.h
> $(CC) $(CFLAGS) -mv67t -O2 -Wno-inline-asm -Wno-expansion-to-
> defined $< -o $@ $(LDFLAGS) diff --git
> a/tests/tcg/hexagon/unaligned_pc_multi_cof.S
> b/tests/tcg/hexagon/unaligned_pc_multi_cof.S
> new file mode 100644
> index 0000000000..10accd0057
> --- /dev/null
> +++ b/tests/tcg/hexagon/unaligned_pc_multi_cof.S
> @@ -0,0 +1,5 @@
> +.org 0x3
> +.global test_multi_cof_unaligned
> +test_multi_cof_unaligned:
> + nop
> + jumpr r31
> --
> 2.37.2
prev parent reply other threads:[~2024-04-30 19:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 14:25 [PATCH v3] Hexagon: add PC alignment check and exception Matheus Tavares Bernardino
2024-04-30 15:45 ` Richard Henderson
2024-04-30 15:52 ` Richard Henderson
2024-04-30 18:31 ` Brian Cain
2024-05-02 14:35 ` Matheus Tavares Bernardino
2024-04-30 19:41 ` ltaylorsimpson [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='02cb01da9b36$719b3fb0$54d1bf10$@gmail.com' \
--to=ltaylorsimpson@gmail.com \
--cc=ale@rev.ng \
--cc=anjo@rev.ng \
--cc=bcain@quicinc.com \
--cc=laurent@vivier.eu \
--cc=qemu-devel@nongnu.org \
--cc=quic_mathbern@quicinc.com \
--cc=richard.henderson@linaro.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.