From nobody Fri Apr 12 09:37:43 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VGBLb69Xhz5H4H5; Fri, 12 Apr 2024 09:37:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VGBLb4Qgvz4DyZ; Fri, 12 Apr 2024 09:37:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712914663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3Agr3pZ72DUCcPbJsWJYG9U4IZVlBkYu0HQgQXL4lg0=; b=Bzk0F4lDfmQxghsiWeucrvtUo9pCISa1xukTWguEtP46ETJJabjt9WVMTgpGpr+Sc1RYv9 XVcS0q9oxMyOYACnZURwx1BeZAj0K6/DBF1hpRCWsFPOAH6VGks+sGU4eeq9Wu5Zdog/bF MSmYOQF4I99825nMuWwPMQ8Mp/Gt3UtVoqYFZW7DXmnu+YH2OGM3YlKaYuK3aaawzGEW/D uDZ2u5stHSKsWGj8jui+lfQzs7DbqkFTFrPTcKu2AGONk6EOEw+I/XOTmpLqhMoKf46O9s stRpsswpW0VtRjs7pClwmdKMqnCGPjMybxUQKyzFVR3sGIPnCaUaCfXHxt0AdQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712914663; a=rsa-sha256; cv=none; b=u6SzY7ZoJxiYHufv+UtqIgLyUMdWib8EaGdu58PwzhDhcGsQ9nfEUhHc/NyVSpbkH0SpcP d9XJ2wOy5udUTg6nVqTFsV+LmbpwazT4u//p0GNFjQpWAG9uxCEtv4uCtqc52B3yI55v5f 6U/0vZCMQbPrLRoDuezaPDAwJwFi8mxYcE//YKlKJeL1FL0d9YUk9GGOivVvcgCUAmCf8U Bou6ruq81uwec5CoNyT7tsH5ATJeA28mtN06g/S1HPHpZJNV/8ot5kmysn/XpVAl02IFR2 uGSBL0MDdvNOQo79YfVWAh+wBd4d6G33k8ZeCgy1EIYFooEHXgwErQk9HuVQWA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712914663; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3Agr3pZ72DUCcPbJsWJYG9U4IZVlBkYu0HQgQXL4lg0=; b=OyV3qhjI/ZfMz2ZpkGaGmOOA9J0hI7mgKVvZmYOUiZNqMGgrSwxNk/2Ay0C6Xmk4ay0lhL aSbcblwF/dARRxlgVSNzsGZNhVfSTwSBNGfXP0a2OFkfPaxdrl23031LLpOncaiJ5SfWLn 3CdmsvR9uTTdAOkdCm0Tu6Ylq27Dhhfrtv04DaqeeEb5ppVN8/312LJLo2yGAiD8COIt3e KjV5eCofcSv42ARH3/MFHpRuo6WOtn+oSRZrMJ0KXI1x0YlTnq/4R/9ZFDOncat/ONu5Hl xo071rLCs3CCPbE2mORIdvJVIKWGdU9jCTUFSCk8U37VE6AvLePaj4bhXwq+lA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VGBLb3p4JzkkB; Fri, 12 Apr 2024 09:37:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43C9bhOu096698; Fri, 12 Apr 2024 09:37:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43C9bhTN096695; Fri, 12 Apr 2024 09:37:43 GMT (envelope-from git) Date: Fri, 12 Apr 2024 09:37:43 GMT Message-Id: <202404120937.43C9bhTN096695@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: f242c47ee278 - main - arm64: Support hardware breakpoints List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f242c47ee278e8e119e98b8f4f00e52fbd0d4efd Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=f242c47ee278e8e119e98b8f4f00e52fbd0d4efd commit f242c47ee278e8e119e98b8f4f00e52fbd0d4efd Author: Andrew Turner AuthorDate: 2024-03-12 17:14:38 +0000 Commit: Andrew Turner CommitDate: 2024-04-12 09:32:56 +0000 arm64: Support hardware breakpoints As with watchpoints allow the kernel debugger to set hardware breakpoints on arm64. These have been tested to work in both the ddb and gdb backends. Reviewed by: jhb (earlier version) Sponsored by: Arm Ltd Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D44355 --- sys/arm64/arm64/db_trace.c | 7 +++ sys/arm64/arm64/debug_monitor.c | 99 +++++++++++++++++++++++++++++++++++++++ sys/arm64/arm64/gdb_machdep.c | 9 +++- sys/arm64/include/db_machdep.h | 3 ++ sys/arm64/include/debug_monitor.h | 1 + sys/arm64/include/kdb.h | 2 + 6 files changed, 120 insertions(+), 1 deletion(-) diff --git a/sys/arm64/arm64/db_trace.c b/sys/arm64/arm64/db_trace.c index 4bc6af26a023..7b0fdeaeba29 100644 --- a/sys/arm64/arm64/db_trace.c +++ b/sys/arm64/arm64/db_trace.c @@ -47,6 +47,13 @@ #define FRAME_SERROR 3 #define FRAME_UNHANDLED 4 +void +db_md_list_breakpoints(void) +{ + + dbg_show_breakpoint(); +} + void db_md_list_watchpoints(void) { diff --git a/sys/arm64/arm64/debug_monitor.c b/sys/arm64/arm64/debug_monitor.c index 3d8e753e1c45..2e1a956ad75c 100644 --- a/sys/arm64/arm64/debug_monitor.c +++ b/sys/arm64/arm64/debug_monitor.c @@ -44,7 +44,9 @@ #include #ifdef DDB +#include #include +#include #include #endif @@ -59,6 +61,10 @@ static struct debug_monitor_state kernel_monitor = { .dbg_flags = DBGMON_KERNEL }; +static int dbg_setup_breakpoint(struct debug_monitor_state *monitor, + vm_offset_t addr); +static int dbg_remove_breakpoint(struct debug_monitor_state *monitor, + vm_offset_t addr); static int dbg_setup_watchpoint(struct debug_monitor_state *, vm_offset_t, vm_size_t, enum dbg_access_t); static int dbg_remove_watchpoint(struct debug_monitor_state *, vm_offset_t, @@ -185,6 +191,18 @@ dbg_wb_write_reg(int reg, int n, uint64_t val) } #if defined(DDB) || defined(GDB) +int +kdb_cpu_set_breakpoint(vm_offset_t addr) +{ + return (dbg_setup_breakpoint(NULL, addr)); +} + +int +kdb_cpu_clr_breakpoint(vm_offset_t addr) +{ + return (dbg_remove_breakpoint(NULL, addr)); +} + void kdb_cpu_set_singlestep(void) { @@ -272,6 +290,33 @@ kdb_cpu_clr_watchpoint(vm_offset_t addr, vm_size_t size) #endif /* DDB || GDB */ #ifdef DDB +void +dbg_show_breakpoint(void) +{ + db_breakpoint_t bkpt; + uint32_t bcr; + uint64_t addr; + int i; + + db_printf("\nhardware breakpoints:\n"); + db_printf(" break status count address symbol\n"); + db_printf(" ----- -------- ----- ------------------ ------------------\n"); + for (i = 0; i < dbg_breakpoint_num; i++) { + bcr = dbg_wb_read_reg(DBG_REG_BASE_BCR, i); + if ((bcr & DBG_WB_CTRL_E) != 0) { + addr = dbg_wb_read_reg(DBG_REG_BASE_BVR, i); + bkpt = db_find_breakpoint_here(addr); + db_printf(" %-5d %-8s %-5d 0x%16lx ", + i, "enabled", bkpt == NULL ? -1 : bkpt->count, + addr); + db_printsym((db_addr_t)addr, DB_STGY_ANY); + db_printf("\n"); + } else { + db_printf(" %-5d disabled\n", i); + } + } +} + static const char * dbg_watchtype_str(uint32_t type) { @@ -394,6 +439,60 @@ dbg_find_slot(struct debug_monitor_state *monitor, enum dbg_t type, return (-1); } +static int +dbg_setup_breakpoint(struct debug_monitor_state *monitor, vm_offset_t addr) +{ + uint64_t bcr_priv; + u_int i; + + if (monitor == NULL) + monitor = &kernel_monitor; + + i = dbg_find_free_slot(monitor, DBG_TYPE_BREAKPOINT); + if (i == -1) { + printf("Can not find slot for breakpoint, max %d" + " breakpoints supported\n", dbg_breakpoint_num); + return (EBUSY); + } + + if ((monitor->dbg_flags & DBGMON_KERNEL) == 0) + bcr_priv = DBG_WB_CTRL_EL0; + else + bcr_priv = DBG_WB_CTRL_EL1; + + monitor->dbg_bvr[i] = addr; + monitor->dbg_bcr[i] = (0xf << 5) | bcr_priv | DBG_WB_CTRL_E; + monitor->dbg_enable_count++; + monitor->dbg_flags |= DBGMON_ENABLED; + dbg_register_sync(monitor); + + return (0); +} + +static int +dbg_remove_breakpoint(struct debug_monitor_state *monitor, vm_offset_t addr) +{ + u_int i; + + if (monitor == NULL) + monitor = &kernel_monitor; + + i = dbg_find_slot(monitor, DBG_TYPE_BREAKPOINT, addr); + if (i == -1) { + printf("Can not find breakpoint for address 0%lx\n", addr); + return (i); + } + + monitor->dbg_bvr[i] = 0; + monitor->dbg_bcr[i] = 0; + monitor->dbg_enable_count--; + if (monitor->dbg_enable_count == 0) + monitor->dbg_flags &= ~DBGMON_ENABLED; + dbg_register_sync(monitor); + + return (0); +} + static int dbg_setup_watchpoint(struct debug_monitor_state *monitor, vm_offset_t addr, vm_size_t size, enum dbg_access_t access) diff --git a/sys/arm64/arm64/gdb_machdep.c b/sys/arm64/arm64/gdb_machdep.c index 7b21675ea927..04c69e5f6079 100644 --- a/sys/arm64/arm64/gdb_machdep.c +++ b/sys/arm64/arm64/gdb_machdep.c @@ -121,9 +121,16 @@ void gdb_cpu_stop_reason(int type, int code __unused) { - if (type == EXCP_WATCHPT_EL1) { + switch (type) { + case EXCP_WATCHPT_EL1: gdb_tx_str("watch:"); gdb_tx_varhex((uintmax_t)READ_SPECIALREG(far_el1)); gdb_tx_char(';'); + break; + case EXCP_BRKPT_EL1: + gdb_tx_str("hwbreak:;"); + break; + default: + break; } } diff --git a/sys/arm64/include/db_machdep.h b/sys/arm64/include/db_machdep.h index 45b97443aec5..5dc496ca851d 100644 --- a/sys/arm64/include/db_machdep.h +++ b/sys/arm64/include/db_machdep.h @@ -40,6 +40,9 @@ #define T_SINGLESTEP (EXCP_SOFTSTP_EL1) #define T_WATCHPOINT (EXCP_WATCHPT_EL1) +#define HAS_HW_BREAKPOINT +#define NHBREAKPOINTS 16 + typedef vm_offset_t db_addr_t; typedef long db_expr_t; diff --git a/sys/arm64/include/debug_monitor.h b/sys/arm64/include/debug_monitor.h index 578e90db7f12..8698f21a7c2a 100644 --- a/sys/arm64/include/debug_monitor.h +++ b/sys/arm64/include/debug_monitor.h @@ -56,6 +56,7 @@ void dbg_monitor_init(void); void dbg_register_sync(struct debug_monitor_state *); #ifdef DDB +void dbg_show_breakpoint(void); void dbg_show_watchpoint(void); #endif diff --git a/sys/arm64/include/kdb.h b/sys/arm64/include/kdb.h index aa36e7e756f9..3148b7df7d1b 100644 --- a/sys/arm64/include/kdb.h +++ b/sys/arm64/include/kdb.h @@ -37,6 +37,8 @@ void kdb_cpu_clear_singlestep(void); void kdb_cpu_set_singlestep(void); +int kdb_cpu_set_breakpoint(vm_offset_t addr); +int kdb_cpu_clr_breakpoint(vm_offset_t addr); int kdb_cpu_set_watchpoint(vm_offset_t addr, size_t size, int access); int kdb_cpu_clr_watchpoint(vm_offset_t addr, size_t size);