git: f820b6ed34d5 - main - arm64: Switch to get_user_reg in fill_dbregs

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Mon, 23 Jun 2025 12:07:35 UTC
The branch main has been updated by andrew:

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

commit f820b6ed34d5e97835d7f55d63076f07ed5d7ef5
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2025-06-23 10:15:00 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2025-06-23 10:18:19 +0000

    arm64: Switch to get_user_reg in fill_dbregs
    
    This lets us read the register in one go then decode it, rather than
    searching for the register 3 times.
    
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D50903
---
 sys/arm64/arm64/exec_machdep.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/sys/arm64/arm64/exec_machdep.c b/sys/arm64/arm64/exec_machdep.c
index 6a536233a62d..751329affd91 100644
--- a/sys/arm64/arm64/exec_machdep.c
+++ b/sys/arm64/arm64/exec_machdep.c
@@ -191,17 +191,27 @@ int
 fill_dbregs(struct thread *td, struct dbreg *regs)
 {
 	struct debug_monitor_state *monitor;
+	uint64_t dfr0;
 	int i;
 	uint8_t debug_ver, nbkpts, nwtpts;
 
 	memset(regs, 0, sizeof(*regs));
 
-	extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_DebugVer_SHIFT,
-	    &debug_ver);
-	extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_BRPs_SHIFT,
-	    &nbkpts);
-	extract_user_id_field(ID_AA64DFR0_EL1, ID_AA64DFR0_WRPs_SHIFT,
-	    &nwtpts);
+	/*
+	 * Read these the Debug Feature Register 0 to get info we need.
+	 * It will be identical on FreeBSD and Linux, so there is no need
+	 * to check which the target is.
+	 */
+	if (!get_user_reg(ID_AA64DFR0_EL1, &dfr0, true)) {
+		debug_ver = ID_AA64DFR0_DebugVer_8;
+		nbkpts = 0;
+		nwtpts = 0;
+	} else {
+		debug_ver = ID_AA64DFR0_DebugVer_VAL(dfr0) >>
+		    ID_AA64DFR0_DebugVer_SHIFT;
+		nbkpts = ID_AA64DFR0_BRPs_VAL(dfr0) >> ID_AA64DFR0_BRPs_SHIFT;
+		nwtpts = ID_AA64DFR0_WRPs_VAL(dfr0) >> ID_AA64DFR0_WRPs_SHIFT;
+	}
 
 	/*
 	 * The BRPs field contains the number of breakpoints - 1. Armv8-A