From 04d8cfc48cf669400eb9c344c846c571f1fa5c91 Mon Sep 17 00:00:00 2001 From: Mark Zhuang Date: Wed, 12 Jul 2023 22:52:33 +0800 Subject: [PATCH 1/2] target/riscv: update some macro 1. update RISCV_MAX_HARTS to 2^20 according to SPEC 2. remove RISCV_MAX_REGISTERS, it's not used anywhere anymore 3. add parentheses Change-Id: Iadf0fa1ba3bbe5b9420b8430883e140db87f4f9e Signed-off-by: Mark Zhuang --- doc/openocd.texi | 8 +++----- src/target/riscv/riscv.h | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index d1edc91e6..e92ad081a 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -10596,11 +10596,9 @@ addreg rtest 0x1234 org.gnu.gdb.or1k.group0 system @section RISC-V Architecture @uref{http://riscv.org/, RISC-V} is a free and open ISA. OpenOCD supports JTAG -debug of RV32 and RV64 cores in heterogeneous multicore systems of up to 32 -harts. (It's possible to increase this limit to 1024 by changing -RISCV_MAX_HARTS in riscv.h.) OpenOCD primarily supports 0.13 of the RISC-V -Debug Specification, but there is also support for legacy targets that -implement version 0.11. +debug of RV32 and RV64 cores in heterogeneous multicore systems of up to 2^20 +harts. OpenOCD primarily supports 0.13 of the RISC-V Debug Specification, +but there is also support for legacy targets that implement version 0.11. @subsection RISC-V Terminology diff --git a/src/target/riscv/riscv.h b/src/target/riscv/riscv.h index 4cbe00612..b89887e13 100644 --- a/src/target/riscv/riscv.h +++ b/src/target/riscv/riscv.h @@ -12,12 +12,11 @@ struct riscv_program; #include "target/register.h" #include "target/semihosting_common.h" #include +#include #define RISCV_COMMON_MAGIC 0x52495356U -/* The register cache is statically allocated. */ -#define RISCV_MAX_HARTS 1024 -#define RISCV_MAX_REGISTERS 5000 +#define RISCV_MAX_HARTS ((int)BIT(20)) #define RISCV_MAX_TRIGGERS 32 #define RISCV_MAX_HWBPS 16 @@ -30,7 +29,7 @@ struct riscv_program; #define RISCV_HGATP_PPN(xlen) ((xlen) == 32 ? HGATP32_PPN : HGATP64_PPN) #define RISCV_PGSHIFT 12 -# define PG_MAX_LEVEL 4 +#define PG_MAX_LEVEL 4 #define RISCV_NUM_MEM_ACCESS_METHODS 3 From d5425c253cc9635d8f3f79cd5e9c8499eea477cc Mon Sep 17 00:00:00 2001 From: Mark Zhuang Date: Thu, 13 Jul 2023 21:21:32 +0800 Subject: [PATCH 2/2] target/riscv: dynamic allocate memory for hawindow Change-Id: Id2f1a2568a39eec0a9dd4fe0f155619b11f9d6ba Signed-off-by: Mark Zhuang --- src/target/riscv/riscv-013.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 10a4bb15c..cc92da949 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -4448,9 +4448,9 @@ static int select_prepped_harts(struct target *target) assert(dm->hart_count); unsigned hawindow_count = (dm->hart_count + 31) / 32; - uint32_t hawindow[hawindow_count]; - - memset(hawindow, 0, sizeof(uint32_t) * hawindow_count); + uint32_t *hawindow = calloc(hawindow_count, sizeof(uint32_t)); + if (!hawindow) + return ERROR_FAIL; target_list_t *entry; unsigned total_selected = 0; @@ -4472,22 +4472,31 @@ static int select_prepped_harts(struct target *target) if (total_selected == 0) { LOG_TARGET_ERROR(target, "No harts were prepped!"); + free(hawindow); return ERROR_FAIL; } else if (total_selected == 1) { /* Don't use hasel if we only need to talk to one hart. */ + free(hawindow); return dm013_select_hart(target, selected_index); } - if (dm013_select_hart(target, HART_INDEX_MULTIPLE) != ERROR_OK) + if (dm013_select_hart(target, HART_INDEX_MULTIPLE) != ERROR_OK) { + free(hawindow); return ERROR_FAIL; - - for (unsigned i = 0; i < hawindow_count; i++) { - if (dmi_write(target, DM_HAWINDOWSEL, i) != ERROR_OK) - return ERROR_FAIL; - if (dmi_write(target, DM_HAWINDOW, hawindow[i]) != ERROR_OK) - return ERROR_FAIL; } + for (unsigned i = 0; i < hawindow_count; i++) { + if (dmi_write(target, DM_HAWINDOWSEL, i) != ERROR_OK) { + free(hawindow); + return ERROR_FAIL; + } + if (dmi_write(target, DM_HAWINDOW, hawindow[i]) != ERROR_OK) { + free(hawindow); + return ERROR_FAIL; + } + } + + free(hawindow); return ERROR_OK; }