From b0254d9afb4aa6bb959dcaf48b7158eeb2be7d3d Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Mon, 24 Feb 2020 16:25:11 +0000 Subject: [PATCH] debug_monitor: Avoid setting the PSR_D flag for 32bits binaries. In dbg_monitor_exit(), avoid setting the PSR_D bit if the process is a 32bits binary. PSR_D is an aarch64-only flags, and for aarch32 processes, it means "run in big endian". This should make COMPAT_FREEBSD32 run much better on arm64. --- sys/arm64/arm64/debug_monitor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sys/arm64/arm64/debug_monitor.c b/sys/arm64/arm64/debug_monitor.c index 37e82d0aa77..dcb3645cf5d 100644 --- a/sys/arm64/arm64/debug_monitor.c +++ b/sys/arm64/arm64/debug_monitor.c @@ -38,6 +38,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -534,7 +535,13 @@ dbg_monitor_exit(struct thread *thread, struct trapframe *frame) { int i; - frame->tf_spsr |= PSR_D; + /* + * PSR_D is an aarch64-only flag. On aarch32, it switches + * the processor to big-endian, so avoid setting it for + * 32bits binaries. + */ + if (!(SV_PROC_FLAG(thread->td_proc, SV_ILP32))) + frame->tf_spsr |= PSR_D; if ((thread->td_pcb->pcb_dbg_regs.dbg_flags & DBGMON_ENABLED) != 0) { /* Install the kernel version of the registers */ dbg_register_sync(&thread->td_pcb->pcb_dbg_regs);