Skip to content

Commit b578501

Browse files
committed
riscv_debug: document the misa mxl field
1 parent 11a8bbe commit b578501

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/target/riscv_debug.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@
124124
#define RV_CSRW_A0 0x00051073U
125125
#define RV_EBREAK 0x00100073U
126126

127-
#define RV_ISA_EXTENSIONS_MASK 0x03ffffffU
128-
129127
#define RV_VENDOR_JEP106_CONT_MASK 0x7fffff80U
130128
#define RV_VENDOR_JEP106_CODE_MASK 0x7fU
131129

@@ -383,18 +381,17 @@ static void riscv_dm_init(riscv_dm_s *const dbg_module)
383381

384382
static uint8_t riscv_isa_address_width(const uint32_t isa)
385383
{
386-
switch (isa >> 30U) {
387-
case 1:
384+
switch ((isa & RV_ISA_MXL_MASK) >> RV_ISA_MXL_SHIFT) {
385+
case RV_ISA_MXL_32:
388386
return 32U;
389-
case 2:
387+
case RV_ISA_MXL_64:
390388
return 64U;
391-
case 3:
389+
case RV_ISA_MXL_128:
392390
return 128U;
393391
default:
394-
break;
392+
DEBUG_INFO("Unknown address width, defaulting to 32\n");
393+
return 32U;
395394
}
396-
DEBUG_INFO("Unknown address width, defaulting to 32\n");
397-
return 32U;
398395
}
399396

400397
static void riscv_hart_read_ids(riscv_hart_s *const hart)
@@ -423,7 +420,7 @@ static void riscv_hart_read_ids(riscv_hart_s *const hart)
423420
}
424421

425422
static size_t riscv_snprint_isa_subset(
426-
char *const string_buffer, const size_t buffer_size, const uint32_t access_width, const uint32_t extensions)
423+
char *const string_buffer, const size_t buffer_size, const uint8_t access_width, const uint32_t extensions)
427424
{
428425
size_t offset = snprintf(string_buffer, buffer_size, "rv%" PRIu8, access_width);
429426

src/target/riscv_debug.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ typedef struct riscv_hart {
203203
/* The FP base defines the starting register space address for the floating point registers */
204204
#define RV_FP_BASE 0x1020U
205205

206+
/**
207+
* The MXL (Machine XLEN) field encodes the native base integer ISA width
208+
*
209+
* The RISC-V Machine ISA register is MXLEN bits wide so the MXL offset is not fixed
210+
* To work around this we convert the register to it's canonical 32-bit form internally
211+
*/
212+
#define RV_ISA_MXL_SHIFT 30U /* misa Machine XLEN field shift (for 32-bit misa) */
213+
#define RV_ISA_MXL_MASK (0x3U << RV_ISA_MXL_SHIFT) /* misa Machine XLEN field mask (for 32-bit misa) */
214+
#define RV_ISA_MXL_32 0x1U /* misa Machine XLEN field value for 32-bit ISA */
215+
#define RV_ISA_MXL_64 0x2U /* misa Machine XLEN field value for 64-bit ISA */
216+
#define RV_ISA_MXL_128 0x3U /* misa Machine XLEN field value for 128-bit ISA */
217+
206218
/*
207219
* The Extensions field encodes the presence of standard extensions, with a single bit per alphabet letter
208220
* (bit 0 encodes presence of extension “A” through to bit 25 which encodes “Z”)
@@ -211,6 +223,7 @@ typedef struct riscv_hart {
211223
*
212224
* The list order is the canonical representation order in the ISA subset string
213225
*/
226+
#define RV_ISA_EXTENSIONS_MASK 0x03ffffffU /* misa extensions field mask */
214227

215228
/* Base ISA */
216229
#define RV_ISA_EXT_INTEGER (1U << 8U) /* 'I': RV32I/64I/128I integer base ISA */

0 commit comments

Comments
 (0)