Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 May 2025 12:50:23 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 71ca0252dc6d - main - arm64: Split out the 32-bit undef handling
Message-ID:  <202505121250.54CCoNYU082928@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=71ca0252dc6d75b1f945b32a53ae5cbdb405ce24

commit 71ca0252dc6d75b1f945b32a53ae5cbdb405ce24
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2025-05-12 11:06:37 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2025-05-12 11:06:37 +0000

    arm64: Split out the 32-bit undef handling
    
    Rather than checking in the handler if we are in a 32 or 64 bit
    process have two lists to iterate over.
    
    Reviewed by:    harry.moulton_arm.com
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D50207
---
 sys/arm64/arm64/undefined.c   | 40 ++++++++++++++++++++++++++++++++++------
 sys/arm64/include/undefined.h |  3 +++
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/sys/arm64/arm64/undefined.c b/sys/arm64/arm64/undefined.c
index 71c9b689aa78..74b9de49a7ef 100644
--- a/sys/arm64/arm64/undefined.c
+++ b/sys/arm64/arm64/undefined.c
@@ -88,6 +88,10 @@ struct undef_handler {
  */
 LIST_HEAD(, undef_handler) undef_handlers =
     LIST_HEAD_INITIALIZER(undef_handlers);
+#ifdef COMPAT_FREEBSD32
+LIST_HEAD(, undef_handler) undef32_handlers =
+    LIST_HEAD_INITIALIZER(undef32_handlers);
+#endif
 
 static bool
 arm_cond_match(uint32_t insn, struct trapframe *frame)
@@ -150,8 +154,7 @@ gdb_trapper(vm_offset_t va, uint32_t insn, struct trapframe *frame,
 	struct thread *td = curthread;
 
 	if (insn == GDB_BREAKPOINT || insn == GDB5_BREAKPOINT) {
-		if (SV_PROC_FLAG(td->td_proc, SV_ILP32) &&
-		    va < VM_MAXUSER_ADDRESS) {
+		if (va < VM_MAXUSER_ADDRESS) {
 			ksiginfo_t ksi;
 
 			ksiginfo_init_trap(&ksi);
@@ -183,8 +186,7 @@ swp_emulate(vm_offset_t va, uint32_t insn, struct trapframe *frame,
 	 * swp, swpb only; there are no Thumb swp/swpb instructions so we can
 	 * safely bail out if we're in Thumb mode.
 	 */
-	if (!compat32_emul_swp || !SV_PROC_FLAG(td->td_proc, SV_ILP32) ||
-	    (frame->tf_spsr & PSR_T) != 0)
+	if (!compat32_emul_swp || (frame->tf_spsr & PSR_T) != 0)
 		return (0);
 	else if ((insn & 0x0fb00ff0) != 0x01000090)
 		return (0);
@@ -250,8 +252,8 @@ void
 undef_init(void)
 {
 #ifdef COMPAT_FREEBSD32
-	install_undef_handler(gdb_trapper);
-	install_undef_handler(swp_emulate);
+	install_undef32_handler(gdb_trapper);
+	install_undef32_handler(swp_emulate);
 #endif
 }
 
@@ -267,6 +269,20 @@ install_undef_handler(undef_handler_t func)
 	return (uh);
 }
 
+#ifdef COMPAT_FREEBSD32
+void *
+install_undef32_handler(undef_handler_t func)
+{
+	struct undef_handler *uh;
+
+	uh = malloc(sizeof(*uh), M_UNDEF, M_WAITOK);
+	uh->uh_handler = func;
+	LIST_INSERT_HEAD(&undef32_handlers, uh, uh_link);
+
+	return (uh);
+}
+#endif
+
 void
 remove_undef_handler(void *handle)
 {
@@ -289,6 +305,18 @@ undef_insn(struct trapframe *frame)
 	if (ret != 0)
 		return (0);
 
+#ifdef COMPAT_FREEBSD32
+	if (SV_PROC_FLAG(curthread->td_proc, SV_ILP32)) {
+		LIST_FOREACH(uh, &undef32_handlers, uh_link) {
+			ret = uh->uh_handler(frame->tf_elr, insn, frame,
+			    frame->tf_esr);
+			if (ret)
+				return (1);
+		}
+		return (0);
+	}
+#endif
+
 	LIST_FOREACH(uh, &undef_handlers, uh_link) {
 		ret = uh->uh_handler(frame->tf_elr, insn, frame, frame->tf_esr);
 		if (ret)
diff --git a/sys/arm64/include/undefined.h b/sys/arm64/include/undefined.h
index 1370a648b17c..104d6e9a8e67 100644
--- a/sys/arm64/include/undefined.h
+++ b/sys/arm64/include/undefined.h
@@ -58,6 +58,9 @@ MRS_GET(Op2)
 
 void undef_init(void);
 void *install_undef_handler(undef_handler_t);
+#ifdef COMPAT_FREEBSD32
+void *install_undef32_handler(undef_handler_t);
+#endif
 void remove_undef_handler(void *);
 int undef_insn(struct trapframe *);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505121250.54CCoNYU082928>