1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Espressif Xtensa target API for OpenOCD *
5 * Copyright (C) 2019 Espressif Systems Ltd. *
6 ***************************************************************************/
14 #include <target/smp.h>
15 #include "esp_xtensa_apptrace.h"
16 #include <target/register.h>
17 #include "esp_xtensa.h"
18 #include "esp_semihosting.h"
20 #define ESP_XTENSA_DBGSTUBS_UPDATE_DATA_ENTRY(_e_) \
22 uint32_t __internal_val = (_e_); \
23 if (!xtensa_data_addr_valid(target, __internal_val)) { \
24 LOG_ERROR("No valid stub data entry found (0x%" PRIx32 ")!", __internal_val); \
29 #define ESP_XTENSA_DBGSTUBS_UPDATE_CODE_ENTRY(_e_) \
31 uint32_t __internal_val = (_e_); \
32 if (__internal_val == 0) { \
33 LOG_ERROR("No valid stub code entry found (0x%" PRIx32 ")!", __internal_val); \
38 static void esp_xtensa_dbgstubs_info_update(struct target
*target
);
39 static void esp_xtensa_dbgstubs_addr_check(struct target
*target
);
41 static int esp_xtensa_dbgstubs_restore(struct target
*target
)
43 struct esp_xtensa_common
*esp_xtensa
= target_to_esp_xtensa(target
);
45 if (esp_xtensa
->esp
.dbg_stubs
.base
== 0)
48 LOG_TARGET_INFO(target
, "Restore debug stubs address %" PRIx32
, esp_xtensa
->esp
.dbg_stubs
.base
);
49 int res
= esp_xtensa_apptrace_status_reg_write(target
, esp_xtensa
->esp
.dbg_stubs
.base
);
50 if (res
!= ERROR_OK
) {
51 LOG_ERROR("Failed to write trace status (%d)!", res
);
56 int esp_xtensa_on_halt(struct target
*target
)
58 /* debug stubs can be used in HALTED state only, so it is OK to get info about them here */
59 esp_xtensa_dbgstubs_info_update(target
);
63 int esp_xtensa_init_arch_info(struct target
*target
,
64 struct esp_xtensa_common
*esp_xtensa
,
65 struct xtensa_debug_module_config
*dm_cfg
,
66 const struct esp_semihost_ops
*semihost_ops
)
68 int ret
= xtensa_init_arch_info(target
, &esp_xtensa
->xtensa
, dm_cfg
);
71 esp_xtensa
->semihost
.ops
= (struct esp_semihost_ops
*)semihost_ops
;
72 esp_xtensa
->apptrace
.hw
= &esp_xtensa_apptrace_hw
;
76 int esp_xtensa_target_init(struct command_context
*cmd_ctx
, struct target
*target
)
78 return xtensa_target_init(cmd_ctx
, target
);
81 void esp_xtensa_target_deinit(struct target
*target
)
85 if (target_was_examined(target
)) {
86 int ret
= esp_xtensa_dbgstubs_restore(target
);
90 xtensa_target_deinit(target
);
91 free(target_to_esp_xtensa(target
)); /* same as free(xtensa) */
94 int esp_xtensa_arch_state(struct target
*target
)
99 int esp_xtensa_poll(struct target
*target
)
101 struct xtensa
*xtensa
= target_to_xtensa(target
);
102 struct esp_xtensa_common
*esp_xtensa_common
= target_to_esp_xtensa(target
);
104 int ret
= xtensa_poll(target
);
106 if (xtensa_dm_power_status_get(&xtensa
->dbg_mod
) & PWRSTAT_COREWASRESET(xtensa
)) {
107 LOG_TARGET_DEBUG(target
, "Clear debug stubs info");
108 memset(&esp_xtensa_common
->esp
.dbg_stubs
, 0, sizeof(esp_xtensa_common
->esp
.dbg_stubs
));
110 if (target
->state
!= TARGET_DEBUG_RUNNING
)
111 esp_xtensa_dbgstubs_addr_check(target
);
115 static void esp_xtensa_dbgstubs_addr_check(struct target
*target
)
117 struct esp_xtensa_common
*esp_xtensa
= target_to_esp_xtensa(target
);
118 uint32_t vec_addr
= 0;
120 if (esp_xtensa
->esp
.dbg_stubs
.base
!= 0)
123 int res
= esp_xtensa_apptrace_status_reg_read(target
, &vec_addr
);
124 if (res
!= ERROR_OK
) {
125 LOG_ERROR("Failed to read debug stubs address location (%d)!", res
);
128 if (xtensa_data_addr_valid(target
, vec_addr
)) {
129 LOG_TARGET_INFO(target
, "Detected debug stubs @ %" PRIx32
, vec_addr
);
130 res
= esp_xtensa_apptrace_status_reg_write(target
, 0);
132 LOG_ERROR("Failed to clear debug stubs address location (%d)!", res
);
133 esp_xtensa
->esp
.dbg_stubs
.base
= vec_addr
;
137 static void esp_xtensa_dbgstubs_info_update(struct target
*target
)
139 struct esp_xtensa_common
*esp_xtensa
= target_to_esp_xtensa(target
);
141 if (esp_xtensa
->esp
.dbg_stubs
.base
== 0 || esp_xtensa
->esp
.dbg_stubs
.entries_count
!= 0)
144 int res
= esp_dbgstubs_table_read(target
, &esp_xtensa
->esp
.dbg_stubs
);
147 if (esp_xtensa
->esp
.dbg_stubs
.entries_count
== 0)
150 /* read debug stubs descriptor */
151 ESP_XTENSA_DBGSTUBS_UPDATE_DATA_ENTRY(esp_xtensa
->esp
.dbg_stubs
.entries
[ESP_DBG_STUB_DESC
]);
152 res
= target_read_buffer(target
, esp_xtensa
->esp
.dbg_stubs
.entries
[ESP_DBG_STUB_DESC
],
153 sizeof(struct esp_dbg_stubs_desc
),
154 (uint8_t *)&esp_xtensa
->esp
.dbg_stubs
.desc
);
155 if (res
!= ERROR_OK
) {
156 LOG_ERROR("Failed to read debug stubs descriptor (%d)!", res
);
159 ESP_XTENSA_DBGSTUBS_UPDATE_CODE_ENTRY(esp_xtensa
->esp
.dbg_stubs
.desc
.tramp_addr
);
160 ESP_XTENSA_DBGSTUBS_UPDATE_DATA_ENTRY(esp_xtensa
->esp
.dbg_stubs
.desc
.min_stack_addr
);
161 ESP_XTENSA_DBGSTUBS_UPDATE_CODE_ENTRY(esp_xtensa
->esp
.dbg_stubs
.desc
.data_alloc
);
162 ESP_XTENSA_DBGSTUBS_UPDATE_CODE_ENTRY(esp_xtensa
->esp
.dbg_stubs
.desc
.data_free
);
165 int esp_xtensa_breakpoint_add(struct target
*target
, struct breakpoint
*breakpoint
)
167 return xtensa_breakpoint_add(target
, breakpoint
);
168 /* flash breakpoints will be handled in another patch */
171 int esp_xtensa_breakpoint_remove(struct target
*target
, struct breakpoint
*breakpoint
)
173 return xtensa_breakpoint_remove(target
, breakpoint
);
174 /* flash breakpoints will be handled in another patch */
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)