cortex_m: implement hit_watchpoint function
[openocd.git] / src / target / cortex_m.c
index 4580c10ff48f0d3ce56240e72ea5f70b4ef47769..2b38b4a7fda9177d67236a8d18791611a4f8028d 100644 (file)
@@ -521,7 +521,7 @@ static int cortex_m_debug_entry(struct target *target)
 
        for (i = 0; i < num_regs; i++) {
                r = &armv7m->arm.core_cache->reg_list[i];
-               if (!r->valid)
+               if (r->exist && !r->valid)
                        arm->read_core_reg(target, r, i, ARM_MODE_ANY);
        }
 
@@ -1596,6 +1596,35 @@ int cortex_m_remove_watchpoint(struct target *target, struct watchpoint *watchpo
        return ERROR_OK;
 }
 
+int cortex_m_hit_watchpoint(struct target *target, struct watchpoint **hit_watchpoint)
+{
+       if (target->debug_reason != DBG_REASON_WATCHPOINT)
+               return ERROR_FAIL;
+
+       struct cortex_m_common *cortex_m = target_to_cm(target);
+
+       for (struct watchpoint *wp = target->watchpoints; wp; wp = wp->next) {
+               if (!wp->set)
+                       continue;
+
+               unsigned int dwt_num = wp->set - 1;
+               struct cortex_m_dwt_comparator *comparator = cortex_m->dwt_comparator_list + dwt_num;
+
+               uint32_t dwt_function;
+               int retval = target_read_u32(target, comparator->dwt_comparator_address + 8, &dwt_function);
+               if (retval != ERROR_OK)
+                       return ERROR_FAIL;
+
+               /* check the MATCHED bit */
+               if (dwt_function & BIT(24)) {
+                       *hit_watchpoint = wp;
+                       return ERROR_OK;
+               }
+       }
+
+       return ERROR_FAIL;
+}
+
 void cortex_m_enable_watchpoints(struct target *target)
 {
        struct watchpoint *watchpoint = target->watchpoints;
@@ -1648,8 +1677,6 @@ void cortex_m_deinit_target(struct target *target)
 {
        struct cortex_m_common *cortex_m = target_to_cm(target);
 
-       armv7m_trace_tpiu_exit(target);
-
        free(cortex_m->fp_comparator_list);
 
        cortex_m_dwt_free(target);
@@ -2021,7 +2048,7 @@ int cortex_m_examine(struct target *target)
                        /* test for floating point feature on Cortex-M4 */
                        if ((mvfr0 == MVFR0_DEFAULT_M4) && (mvfr1 == MVFR1_DEFAULT_M4)) {
                                LOG_DEBUG("Cortex-M%d floating point feature FPv4_SP found", i);
-                               armv7m->fp_feature = FPv4_SP;
+                               armv7m->fp_feature = FPV4_SP;
                        }
                } else if (i == 7 || i == 33 || i == 35 || i == 55) {
                        target_read_u32(target, MVFR0, &mvfr0);
@@ -2030,29 +2057,21 @@ int cortex_m_examine(struct target *target)
                        /* test for floating point features on Cortex-M7 */
                        if ((mvfr0 == MVFR0_DEFAULT_M7_SP) && (mvfr1 == MVFR1_DEFAULT_M7_SP)) {
                                LOG_DEBUG("Cortex-M%d floating point feature FPv5_SP found", i);
-                               armv7m->fp_feature = FPv5_SP;
+                               armv7m->fp_feature = FPV5_SP;
                        } else if ((mvfr0 == MVFR0_DEFAULT_M7_DP) && (mvfr1 == MVFR1_DEFAULT_M7_DP)) {
                                LOG_DEBUG("Cortex-M%d floating point feature FPv5_DP found", i);
-                               armv7m->fp_feature = FPv5_DP;
+                               armv7m->fp_feature = FPV5_DP;
                        }
                } else if (i == 0) {
                        /* Cortex-M0 does not support unaligned memory access */
                        armv7m->arm.is_armv6m = true;
                }
 
-               if (armv7m->fp_feature == FP_NONE &&
-                   armv7m->arm.core_cache->num_regs > ARMV7M_NUM_CORE_REGS_NOFP) {
-                       /* free unavailable FPU registers */
-                       size_t idx;
+               /* Check for FPU, otherwise mark FPU register as non-existent */
+               if (armv7m->fp_feature == FP_NONE)
+                       for (size_t idx = ARMV7M_FPU_FIRST_REG; idx <= ARMV7M_FPU_LAST_REG; idx++)
+                               armv7m->arm.core_cache->reg_list[idx].exist = false;
 
-                       for (idx = ARMV7M_NUM_CORE_REGS_NOFP;
-                            idx < armv7m->arm.core_cache->num_regs;
-                            idx++) {
-                               free(armv7m->arm.core_cache->reg_list[idx].feature);
-                               free(armv7m->arm.core_cache->reg_list[idx].reg_data_type);
-                       }
-                       armv7m->arm.core_cache->num_regs = ARMV7M_NUM_CORE_REGS_NOFP;
-               }
 
                if (!armv7m->stlink) {
                        if (i == 3 || i == 4)
@@ -2082,9 +2101,6 @@ int cortex_m_examine(struct target *target)
                if (retval != ERROR_OK)
                        return retval;
 
-               if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED)
-                       armv7m_trace_tpiu_config(target);
-
                if (armv7m->trace_config.itm_deferred_config)
                        armv7m_trace_itm_config(target);
 
@@ -2486,6 +2502,11 @@ static const struct command_registration cortex_m_command_handlers[] = {
        {
                .chain = armv7m_trace_command_handlers,
        },
+       /* START_DEPRECATED_TPIU */
+       {
+               .chain = arm_tpiu_deprecated_command_handlers,
+       },
+       /* END_DEPRECATED_TPIU */
        {
                .name = "cortex_m",
                .mode = COMMAND_EXEC,
@@ -2501,7 +2522,6 @@ static const struct command_registration cortex_m_command_handlers[] = {
 
 struct target_type cortexm_target = {
        .name = "cortex_m",
-       .deprecated_name = "cortex_m3",
 
        .poll = cortex_m_poll,
        .arch_state = armv7m_arch_state,
@@ -2532,6 +2552,7 @@ struct target_type cortexm_target = {
        .remove_breakpoint = cortex_m_remove_breakpoint,
        .add_watchpoint = cortex_m_add_watchpoint,
        .remove_watchpoint = cortex_m_remove_watchpoint,
+       .hit_watchpoint = cortex_m_hit_watchpoint,
 
        .commands = cortex_m_command_handlers,
        .target_create = cortex_m_target_create,

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)