From: Andre Przywara <andre.przywara@arm.com>
To: Tom Rini <trini@konsulko.com>
Cc: Simon Glass <sjg@chromium.org>,
Heinrich Schuchardt <heinrich.schuchardt@canonical.com>,
Michael Walle <michael@walle.cc>, Nishanth Menon <nm@ti.com>,
Alison Wang <alison.wang@nxp.com>,
Peter Hoyes <Peter.Hoyes@arm.com>,
Marek Vasut <marek.vasut+renesas@gmail.com>,
Priyanka Jain <priyanka.jain@nxp.com>,
Priyanka Singh <priyanka.singh@nxp.com>,
Mark Kettenis <mark.kettenis@xs4all.nl>,
u-boot@lists.denx.de
Subject: [PATCH v2 1/6] cmd: exception: arm64: fix undefined, add faults
Date: Fri, 11 Feb 2022 11:29:34 +0000 [thread overview]
Message-ID: <20220211112939.1327953-2-andre.przywara@arm.com> (raw)
In-Reply-To: <20220211112939.1327953-1-andre.przywara@arm.com>
The arm64 version of the exception command was just defining the
undefined exception, but actually copied the AArch32 instruction.
Replace that with an encoding that is guaranteed to be and stay
undefined. Also add instructions to trigger unaligned access faults and
a breakpoint.
This brings ARM64 on par with ARM(32) for the exception command.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
cmd/arm/exception64.c | 64 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 4 deletions(-)
diff --git a/cmd/arm/exception64.c b/cmd/arm/exception64.c
index d5de50a080..589a23115b 100644
--- a/cmd/arm/exception64.c
+++ b/cmd/arm/exception64.c
@@ -7,19 +7,73 @@
#include <common.h>
#include <command.h>
+#include <linux/bitops.h>
static int do_undefined(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
/*
- * 0xe7f...f. is undefined in ARM mode
- * 0xde.. is undefined in Thumb mode
+ * Instructions starting with the upper 16 bits all 0 are permanently
+ * undefined. The lower 16 bits can be used for some kind of immediate.
+ * --- ARMv8 ARM (ARM DDI 0487G.a C6.2.339: "UDF")
*/
- asm volatile (".word 0xe7f7defb\n");
+ asm volatile (".word 0x00001234\n");
+
+ return CMD_RET_FAILURE;
+}
+
+/*
+ * The ID_AA64MMFR2_EL1 register name is only know to binutils for ARMv8.2
+ * and later architecture revisions. However the register is valid regardless
+ * of binutils architecture support or the core the code is running on, so
+ * just use the generic encoding.
+ */
+#define ID_AA64MMFR2_EL1 "S3_0_C0_C7_2"
+
+static int do_unaligned(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ uint64_t reg;
+
+ /*
+ * The unaligned LDAR access below is only guaranteed to generate an
+ * alignment fault on cores not implementing FEAT_LSE2. To avoid false
+ * negatives, check this condition before we exectute LDAR.
+ */
+ asm ("mrs %0, "ID_AA64MMFR2_EL1"\n" : "=r" (reg));
+ if (reg & GENMASK(35, 32)) {
+ printf("unaligned access check only supported on pre-v8.4 cores\n");
+ return CMD_RET_FAILURE;
+ }
+
+ /*
+ * The load acquire instruction requires the data source to be
+ * naturally aligned, and will fault even if strict alignment fault
+ * checking is disabled (but only without FEAT_LSE2).
+ * --- ARMv8 ARM (ARM DDI 0487G.a B2.5.2: "Alignment of data accesses")
+ */
+ asm volatile (
+ "mov x1, sp\n\t"
+ "orr x1, x1, #3\n\t"
+ "ldar x0, [x1]\n"
+ ::: "x0", "x1" );
+
+ return CMD_RET_FAILURE;
+}
+
+static int do_breakpoint(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ asm volatile ("brk #123\n");
+
return CMD_RET_FAILURE;
}
static struct cmd_tbl cmd_sub[] = {
+ U_BOOT_CMD_MKENT(breakpoint, CONFIG_SYS_MAXARGS, 1, do_breakpoint,
+ "", ""),
+ U_BOOT_CMD_MKENT(unaligned, CONFIG_SYS_MAXARGS, 1, do_unaligned,
+ "", ""),
U_BOOT_CMD_MKENT(undefined, CONFIG_SYS_MAXARGS, 1, do_undefined,
"", ""),
};
@@ -27,7 +81,9 @@ static struct cmd_tbl cmd_sub[] = {
static char exception_help_text[] =
"<ex>\n"
" The following exceptions are available:\n"
- " undefined - undefined instruction\n"
+ " breakpoint - breakpoint instruction exception\n"
+ " unaligned - unaligned LDAR data abort\n"
+ " undefined - undefined instruction exception\n"
;
#include <exception.h>
--
2.25.1
next prev parent reply other threads:[~2022-02-11 11:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-11 11:29 [PATCH v2 0/6] armv8: fixes and cleanups Andre Przywara
2022-02-11 11:29 ` Andre Przywara [this message]
2022-03-02 22:41 ` [PATCH v2 1/6] cmd: exception: arm64: fix undefined, add faults Tom Rini
2022-02-11 11:29 ` [PATCH v2 2/6] armv8: Always unmask SErrors Andre Przywara
2022-03-02 22:41 ` Tom Rini
2022-02-11 11:29 ` [PATCH v2 3/6] armv8: Force SP_ELx stack pointer usage Andre Przywara
2022-03-02 22:41 ` Tom Rini
2022-02-11 11:29 ` [PATCH v2 4/6] arm: Clean up asm/io.h Andre Przywara
2022-03-02 22:41 ` Tom Rini
2022-02-11 11:29 ` [PATCH v2 5/6] armv8: Simplify switch_el macro Andre Przywara
2022-03-02 22:41 ` Tom Rini
2022-02-11 11:29 ` [PATCH v2 6/6] armv8: Fix and simplify branch_if_master/branch_if_slave Andre Przywara
2022-03-02 22:41 ` Tom Rini
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=20220211112939.1327953-2-andre.przywara@arm.com \
--to=andre.przywara@arm.com \
--cc=Peter.Hoyes@arm.com \
--cc=alison.wang@nxp.com \
--cc=heinrich.schuchardt@canonical.com \
--cc=marek.vasut+renesas@gmail.com \
--cc=mark.kettenis@xs4all.nl \
--cc=michael@walle.cc \
--cc=nm@ti.com \
--cc=priyanka.jain@nxp.com \
--cc=priyanka.singh@nxp.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
/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.