diff --git a/src/target/adiv5.h b/src/target/adiv5.h index 51faf61cd1c..f2798db3474 100644 --- a/src/target/adiv5.h +++ b/src/target/adiv5.h @@ -167,6 +167,11 @@ #define JTAG_IDCODE_PARTNO_MASK (0xffffU << JTAG_IDCODE_PARTNO_OFFSET) #define JTAG_IDCODE_DESIGNER_OFFSET 1U #define JTAG_IDCODE_DESIGNER_MASK (0x7ffU << JTAG_IDCODE_DESIGNER_OFFSET) +/* Bits 10:7 - JEP-106 Continuation code */ +/* Bits 6:0 - JEP-106 Identity code */ +#define JTAG_IDCODE_DESIGNER_JEP106_CONT_OFFSET 7U +#define JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK (0xfU << ADIV5_DP_DESIGNER_JEP106_CONT_OFFSET) +#define JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK (0x7fU) #define JTAG_IDCODE_ARM_DPv0 UINT32_C(0x4ba00477) diff --git a/src/target/riscv_debug.c b/src/target/riscv_debug.c index 5df661140b6..b2708224799 100644 --- a/src/target/riscv_debug.c +++ b/src/target/riscv_debug.c @@ -352,10 +352,8 @@ static bool riscv_hart_init(riscv_hart_s *const hart) return true; } - /* If the hart implements mvendorid, this gives us the JEP-106, otherwise use the JTAG IDCode */ - target->designer_code = hart->vendorid ? - hart->vendorid : - ((hart->dbg_module->dmi_bus->idcode & JTAG_IDCODE_DESIGNER_MASK) >> JTAG_IDCODE_DESIGNER_OFFSET); + /* If the hart implements mvendorid, this gives us the JEP-106, otherwise use the DTM designer code */ + target->designer_code = hart->vendorid ? hart->vendorid : hart->dbg_module->dmi_bus->designer_code; target->cpuid = hart->archid; riscv_hart_discover_triggers(hart); diff --git a/src/target/riscv_debug.h b/src/target/riscv_debug.h index 9cdeee6d7ac..c1b71790c78 100644 --- a/src/target/riscv_debug.h +++ b/src/target/riscv_debug.h @@ -90,7 +90,7 @@ typedef struct riscv_dmi riscv_dmi_s; struct riscv_dmi { uint32_t ref_count; - uint32_t idcode; + uint16_t designer_code; riscv_debug_version_e version; uint8_t dev_index; diff --git a/src/target/riscv_jtag_dtm.c b/src/target/riscv_jtag_dtm.c index bcf53f3ef92..ea36d6298ad 100644 --- a/src/target/riscv_jtag_dtm.c +++ b/src/target/riscv_jtag_dtm.c @@ -35,6 +35,7 @@ #include "jtag_scan.h" #include "jtagtap.h" #include "riscv_debug.h" +#include "adiv5.h" #define IR_DTMCS 0x10U #define IR_DMI 0x11U @@ -75,12 +76,23 @@ void riscv_jtag_dtm_handler(const uint8_t dev_index) } /* Setup and try to discover the DMI bus */ - dmi->idcode = jtag_devs[dev_index].jd_idcode; dmi->dev_index = dev_index; + /* + * The code in JTAG_IDCODE_DESIGNER is in the form + * Bits 10:7 - JEP-106 Continuation code + * Bits 6:0 - JEP-106 Identity code + * here we convert it to our internal representation, See JEP-106 code list + */ + const uint16_t designer = + (jtag_devs[dev_index].jd_idcode & JTAG_IDCODE_DESIGNER_MASK) >> JTAG_IDCODE_DESIGNER_OFFSET; + dmi->designer_code = + (designer & JTAG_IDCODE_DESIGNER_JEP106_CONT_MASK) << 1U | (designer & JTAG_IDCODE_DESIGNER_JEP106_CODE_MASK); + riscv_jtag_dtm_init(dmi); /* If we failed to find any DMs or Harts, free the structure */ if (!dmi->ref_count) free(dmi); + /* Reset the JTAG machinary back to bypass to scan the next device in the chain */ jtag_dev_write_ir(dev_index, IR_BYPASS); }