Skip to content

Commit

Permalink
target/esp32c5: register access
Browse files Browse the repository at this point in the history
  • Loading branch information
sobuch authored and erhankur committed Oct 24, 2024
1 parent c467ac1 commit 3778e97
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/target/espressif/esp32c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ static int esp32c2_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32c2_print_reset_reason;
esp_riscv->existent_csrs = NULL;
esp_riscv->existent_csr_size = 0;
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32c2_is_dram_address;
esp_riscv->is_iram_address = esp32c2_is_iram_address;

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp32c3.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ static int esp32c3_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32c3_print_reset_reason;
esp_riscv->existent_csrs = NULL;
esp_riscv->existent_csr_size = 0;
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32c3_is_dram_address;
esp_riscv->is_iram_address = esp32c3_is_iram_address;

Expand Down
26 changes: 25 additions & 1 deletion src/target/espressif/esp32c5.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,29 @@ static const struct esp_flash_breakpoint_ops esp32c5_flash_brp_ops = {
};

static const char *esp32c5_csrs[] = {
"mideleg", "medeleg", "mie", "mip",
"mideleg", "medeleg", "mie", "mip", "jvt", "mtvt",
"mintthresh", "mnxti", "mscratchcsw", "mscratchcswl",
"mcycle", "mcycleh", "minstret", "minstreth",
"mhpmevent8", "mhpmevent9", "mhpmevent13",
"mhpmcounter8", "mhpmcounter9", "mhpmcounter13", "mhpmcounter8h", "mhpmcounter9h", "mhpmcounter13h",
"mcounteren", "mcountinhibit",
/* custom exposed CSRs will start with 'csr_' prefix*/
"csr_pma_cfg0", "csr_pma_cfg1", "csr_pma_cfg2", "csr_pma_cfg3", "csr_pma_cfg4", "csr_pma_cfg5",
"csr_pma_cfg6", "csr_pma_cfg7", "csr_pma_cfg8", "csr_pma_cfg9", "csr_pma_cfg10", "csr_pma_cfg11",
"csr_pma_cfg12", "csr_pma_cfg13", "csr_pma_cfg14", "csr_pma_cfg15", "csr_pma_addr0", "csr_pma_addr1",
"csr_pma_addr2", "csr_pma_addr3", "csr_pma_addr4", "csr_pma_addr5", "csr_pma_addr6", "csr_pma_addr7",
"csr_pma_addr8", "csr_pma_addr9", "csr_pma_addr10", "csr_pma_addr11", "csr_pma_addr12", "csr_pma_addr13",
"csr_pma_addr14", "csr_pma_addr15", "csr_mxstatus", "csr_mhcr", "csr_mhint", "csr_mexstatus",
"csr_mclicbase", "csr_mraddr", "csr_mnmicause",
};

static const char *esp32c5_ro_csrs[] = {
/* read-only CSRs, cannot be save/restored as the write would fail */
"cycle", "time", "instreth", "cycleh", "instret", "timeh",
"hpmcounter8", "hpmcounter9", "hpmcounter13", "hpmcounter8h", "hpmcounter9h", "hpmcounter13h",
"mintstatus",
/* custom exposed CSRs will start with 'csr_' prefix*/
"csr_mcpuid",
};

static int esp32c5_target_create(struct target *target, Jim_Interp *interp)
Expand All @@ -153,6 +175,8 @@ static int esp32c5_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32c5_print_reset_reason;
esp_riscv->existent_csrs = esp32c5_csrs;
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32c5_csrs);
esp_riscv->existent_ro_csrs = esp32c5_ro_csrs;
esp_riscv->existent_ro_csr_size = ARRAY_SIZE(esp32c5_ro_csrs);
esp_riscv->is_dram_address = esp32c5_is_idram_address;
esp_riscv->is_iram_address = esp32c5_is_idram_address;

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp32c6.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ static int esp32c6_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32c6_print_reset_reason;
esp_riscv->existent_csrs = esp32c6_csrs;
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32c6_csrs);
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32c6_is_idram_address;
esp_riscv->is_iram_address = esp32c6_is_idram_address;

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp32c61.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ static int esp32c61_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32c61_print_reset_reason;
esp_riscv->existent_csrs = esp32c61_csrs;
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32c61_csrs);
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32c61_is_idram_address;
esp_riscv->is_iram_address = esp32c61_is_idram_address;

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp32h2.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ static int esp32h2_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32h2_print_reset_reason;
esp_riscv->existent_csrs = esp32h2_csrs;
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32h2_csrs);
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32h2_is_idram_address;
esp_riscv->is_iram_address = esp32h2_is_idram_address;

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp32p4.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ static int esp32p4_target_create(struct target *target, Jim_Interp *interp)
esp_riscv->print_reset_reason = &esp32p4_print_reset_reason;
esp_riscv->existent_csrs = esp32p4_csrs;
esp_riscv->existent_csr_size = ARRAY_SIZE(esp32p4_csrs);
esp_riscv->existent_ro_csrs = NULL;
esp_riscv->existent_ro_csr_size = 0;
esp_riscv->is_dram_address = esp32p4_is_idram_address;
esp_riscv->is_iram_address = esp32p4_is_idram_address;

Expand Down
1 change: 1 addition & 0 deletions src/target/espressif/esp_riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ int esp_riscv_examine(struct target *target)
{ esp_riscv_fprs, ARRAY_SIZE(esp_riscv_fprs), false },
{ esp_riscv_csrs, ARRAY_SIZE(esp_riscv_csrs), true },
{ esp_riscv_ro_csrs, ARRAY_SIZE(esp_riscv_ro_csrs), false },
{ esp_riscv->existent_ro_csrs, esp_riscv->existent_ro_csr_size, false }, /* chip specific RO CSRs */
{ esp_riscv->existent_csrs, esp_riscv->existent_csr_size, true } /* chip specific CSRs */
};

Expand Down
2 changes: 2 additions & 0 deletions src/target/espressif/esp_riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ struct esp_riscv_common {
bool was_reset;
const char **existent_csrs;
size_t existent_csr_size;
const char **existent_ro_csrs;
size_t existent_ro_csr_size;
bool (*is_iram_address)(target_addr_t addr);
bool (*is_dram_address)(target_addr_t addr);
};
Expand Down
4 changes: 3 additions & 1 deletion src/target/riscv/encoding.h
Original file line number Diff line number Diff line change
Expand Up @@ -2903,7 +2903,8 @@
#define CSR_SSCRATCHCSWL 0x149
#define CSR_MTVT 0x307
#define CSR_MNXTI 0x345
#define CSR_MINTSTATUS 0x346
#define CSR_MINTSTATUS 0xfb1
#define CSR_MINTTHRESH 0x347
#define CSR_MSCRATCHCSW 0x348
#define CSR_MSCRATCHCSWL 0x349
#define CSR_MSTATUS 0x300
Expand Down Expand Up @@ -4661,6 +4662,7 @@ DECLARE_CSR(sscratchcswl, CSR_SSCRATCHCSWL)
DECLARE_CSR(mtvt, CSR_MTVT)
DECLARE_CSR(mnxti, CSR_MNXTI)
DECLARE_CSR(mintstatus, CSR_MINTSTATUS)
DECLARE_CSR(mintthresh, CSR_MINTTHRESH)
DECLARE_CSR(mscratchcsw, CSR_MSCRATCHCSW)
DECLARE_CSR(mscratchcswl, CSR_MSCRATCHCSWL)
DECLARE_CSR(mstatus, CSR_MSTATUS)
Expand Down
79 changes: 40 additions & 39 deletions tcl/target/esp32c5.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,43 @@ proc esp32c5_memprot_is_enabled { } {

create_esp_target $_ESP_ARCH

# TODO: OCD-980
# $_TARGETNAME_0 riscv expose_csrs 2016=mpcer
# $_TARGETNAME_0 riscv expose_csrs 2017=mpcmr
# $_TARGETNAME_0 riscv expose_csrs 2018=mpccr
# $_TARGETNAME_0 riscv expose_csrs 2051=cpu_gpio_oen
# $_TARGETNAME_0 riscv expose_csrs 2052=cpu_gpio_in
# $_TARGETNAME_0 riscv expose_csrs 2053=cpu_gpio_out
# $_TARGETNAME_0 riscv expose_csrs 3008=pma_cfg0
# $_TARGETNAME_0 riscv expose_csrs 3009=pma_cfg1
# $_TARGETNAME_0 riscv expose_csrs 3010=pma_cfg2
# $_TARGETNAME_0 riscv expose_csrs 3011=pma_cfg3
# $_TARGETNAME_0 riscv expose_csrs 3012=pma_cfg4
# $_TARGETNAME_0 riscv expose_csrs 3013=pma_cfg5
# $_TARGETNAME_0 riscv expose_csrs 3014=pma_cfg6
# $_TARGETNAME_0 riscv expose_csrs 3015=pma_cfg7
# $_TARGETNAME_0 riscv expose_csrs 3016=pma_cfg8
# $_TARGETNAME_0 riscv expose_csrs 3017=pma_cfg9
# $_TARGETNAME_0 riscv expose_csrs 3018=pma_cfg10
# $_TARGETNAME_0 riscv expose_csrs 3019=pma_cfg11
# $_TARGETNAME_0 riscv expose_csrs 3020=pma_cfg12
# $_TARGETNAME_0 riscv expose_csrs 3021=pma_cfg13
# $_TARGETNAME_0 riscv expose_csrs 3022=pma_cfg14
# $_TARGETNAME_0 riscv expose_csrs 3023=pma_cfg15
# $_TARGETNAME_0 riscv expose_csrs 3024=pma_addr0
# $_TARGETNAME_0 riscv expose_csrs 3025=pma_addr1
# $_TARGETNAME_0 riscv expose_csrs 3026=pma_addr2
# $_TARGETNAME_0 riscv expose_csrs 3027=pma_addr3
# $_TARGETNAME_0 riscv expose_csrs 3028=pma_addr4
# $_TARGETNAME_0 riscv expose_csrs 3029=pma_addr5
# $_TARGETNAME_0 riscv expose_csrs 3030=pma_addr6
# $_TARGETNAME_0 riscv expose_csrs 3031=pma_addr7
# $_TARGETNAME_0 riscv expose_csrs 3032=pma_addr8
# $_TARGETNAME_0 riscv expose_csrs 3033=pma_addr9
# $_TARGETNAME_0 riscv expose_csrs 3034=pma_addr10
# $_TARGETNAME_0 riscv expose_csrs 3035=pma_addr11
# $_TARGETNAME_0 riscv expose_csrs 3036=pma_addr12
# $_TARGETNAME_0 riscv expose_csrs 3037=pma_addr13
# $_TARGETNAME_0 riscv expose_csrs 3038=pma_addr14
# $_TARGETNAME_0 riscv expose_csrs 3039=pma_addr15
$_TARGETNAME_0 riscv expose_csrs 848=mclicbase
$_TARGETNAME_0 riscv expose_csrs 1984=mxstatus
$_TARGETNAME_0 riscv expose_csrs 1985=mhcr
$_TARGETNAME_0 riscv expose_csrs 1989=mhint
$_TARGETNAME_0 riscv expose_csrs 2016=mraddr
$_TARGETNAME_0 riscv expose_csrs 2017=mexstatus
$_TARGETNAME_0 riscv expose_csrs 2018=mnmicause
$_TARGETNAME_0 riscv expose_csrs 3008=pma_cfg0
$_TARGETNAME_0 riscv expose_csrs 3009=pma_cfg1
$_TARGETNAME_0 riscv expose_csrs 3010=pma_cfg2
$_TARGETNAME_0 riscv expose_csrs 3011=pma_cfg3
$_TARGETNAME_0 riscv expose_csrs 3012=pma_cfg4
$_TARGETNAME_0 riscv expose_csrs 3013=pma_cfg5
$_TARGETNAME_0 riscv expose_csrs 3014=pma_cfg6
$_TARGETNAME_0 riscv expose_csrs 3015=pma_cfg7
$_TARGETNAME_0 riscv expose_csrs 3016=pma_cfg8
$_TARGETNAME_0 riscv expose_csrs 3017=pma_cfg9
$_TARGETNAME_0 riscv expose_csrs 3018=pma_cfg10
$_TARGETNAME_0 riscv expose_csrs 3019=pma_cfg11
$_TARGETNAME_0 riscv expose_csrs 3020=pma_cfg12
$_TARGETNAME_0 riscv expose_csrs 3021=pma_cfg13
$_TARGETNAME_0 riscv expose_csrs 3022=pma_cfg14
$_TARGETNAME_0 riscv expose_csrs 3023=pma_cfg15
$_TARGETNAME_0 riscv expose_csrs 3024=pma_addr0
$_TARGETNAME_0 riscv expose_csrs 3025=pma_addr1
$_TARGETNAME_0 riscv expose_csrs 3026=pma_addr2
$_TARGETNAME_0 riscv expose_csrs 3027=pma_addr3
$_TARGETNAME_0 riscv expose_csrs 3028=pma_addr4
$_TARGETNAME_0 riscv expose_csrs 3029=pma_addr5
$_TARGETNAME_0 riscv expose_csrs 3030=pma_addr6
$_TARGETNAME_0 riscv expose_csrs 3031=pma_addr7
$_TARGETNAME_0 riscv expose_csrs 3032=pma_addr8
$_TARGETNAME_0 riscv expose_csrs 3033=pma_addr9
$_TARGETNAME_0 riscv expose_csrs 3034=pma_addr10
$_TARGETNAME_0 riscv expose_csrs 3035=pma_addr11
$_TARGETNAME_0 riscv expose_csrs 3036=pma_addr12
$_TARGETNAME_0 riscv expose_csrs 3037=pma_addr13
$_TARGETNAME_0 riscv expose_csrs 3038=pma_addr14
$_TARGETNAME_0 riscv expose_csrs 3039=pma_addr15
$_TARGETNAME_0 riscv expose_csrs 4032=mcpuid

0 comments on commit 3778e97

Please sign in to comment.