cortex_m: Call mem_ap_read/write directly
[openocd.git] / src / target / cortex_m.c
index 7094b0708f250bf91daf8f77ebb7a54472915334..ea8a086027e42edb498a3f3bdc093b889197f5af 100644 (file)
@@ -21,7 +21,7 @@
  *   You should have received a copy of the GNU General Public License     *
  *   along with this program; if not, write to the                         *
  *   Free Software Foundation, Inc.,                                       *
- *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.           *
  *                                                                         *
  *                                                                         *
  *   Cortex-M3(tm) TRM, ARM DDI 0337E (r1p1) and 0337G (r2p0)              *
@@ -430,20 +430,9 @@ static int cortex_m3_debug_entry(struct target *target)
                        arm->read_core_reg(target, r, i, ARM_MODE_ANY);
        }
 
-       r = arm->core_cache->reg_list + ARMV7M_xPSR;
+       r = arm->cpsr;
        xPSR = buf_get_u32(r->value, 0, 32);
 
-#ifdef ARMV7_GDB_HACKS
-       /* FIXME this breaks on scan chains with more than one Cortex-M3.
-        * Instead, each CM3 should have its own dummy value...
-        */
-       /* copy real xpsr reg for gdb, setting thumb bit */
-       buf_set_u32(armv7m_gdb_dummy_cpsr_value, 0, 32, xPSR);
-       buf_set_u32(armv7m_gdb_dummy_cpsr_value, 5, 1, 1);
-       armv7m_gdb_dummy_cpsr_reg.valid = r->valid;
-       armv7m_gdb_dummy_cpsr_reg.dirty = r->dirty;
-#endif
-
        /* For IT instructions xPSR must be reloaded on resume and clear on debug exec */
        if (xPSR & 0xf00) {
                r->dirty = r->valid;
@@ -632,6 +621,12 @@ static int cortex_m3_soft_reset_halt(struct target *target)
        uint32_t dcb_dhcsr = 0;
        int retval, timeout = 0;
 
+       /* soft_reset_halt is deprecated on cortex_m as the same functionality
+        * can be obtained by using 'reset halt' and 'cortex_m reset_config vectreset'
+        * As this reset only used VC_CORERESET it would only ever reset the cortex_m
+        * core, not the peripherals */
+       LOG_WARNING("soft_reset_halt is deprecated, please use 'reset halt' instead.");
+
        /* Enter debug state on reset; restore DEMCR in endreset_event() */
        retval = mem_ap_write_u32(swjdp, DCB_DEMCR,
                        TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET);
@@ -726,7 +721,7 @@ static int cortex_m3_resume(struct target *target, int current,
                r->valid = true;
 
                /* Make sure we are in Thumb mode */
-               r = armv7m->arm.core_cache->reg_list + ARMV7M_xPSR;
+               r = armv7m->arm.cpsr;
                buf_set_u32(r->value, 24, 1, 1);
                r->dirty = true;
                r->valid = true;
@@ -989,7 +984,8 @@ static int cortex_m3_assert_reset(struct target *target)
 
        bool srst_asserted = false;
 
-       if (jtag_reset_config & RESET_SRST_NO_GATING) {
+       if ((jtag_reset_config & RESET_HAS_SRST) &&
+           (jtag_reset_config & RESET_SRST_NO_GATING)) {
                adapter_assert_reset();
                srst_asserted = true;
        }
@@ -1060,11 +1056,11 @@ static int cortex_m3_assert_reset(struct target *target)
                if (retval != ERROR_OK)
                        return retval;
 
-               LOG_DEBUG("Using Cortex-M3 %s", (reset_config == CORTEX_M3_RESET_SYSRESETREQ)
+               LOG_DEBUG("Using Cortex-M %s", (reset_config == CORTEX_M3_RESET_SYSRESETREQ)
                        ? "SYSRESETREQ" : "VECTRESET");
 
                if (reset_config == CORTEX_M3_RESET_VECTRESET) {
-                       LOG_WARNING("Only resetting the Cortex-M3 core, use a reset-init event "
+                       LOG_WARNING("Only resetting the Cortex-M core, use a reset-init event "
                                "handler to reset any peripherals or configure hardware srst support.");
                }
 
@@ -1225,17 +1221,8 @@ int cortex_m3_add_breakpoint(struct target *target, struct breakpoint *breakpoin
 {
        struct cortex_m3_common *cortex_m3 = target_to_cm3(target);
 
-       if (cortex_m3->auto_bp_type) {
+       if (cortex_m3->auto_bp_type)
                breakpoint->type = BKPT_TYPE_BY_ADDR(breakpoint->address);
-#ifdef ARMV7_GDB_HACKS
-               if (breakpoint->length != 2) {
-                       /* XXX Hack: Replace all breakpoints with length != 2 with
-                        * a hardware breakpoint. */
-                       breakpoint->type = BKPT_HARD;
-                       breakpoint->length = 2;
-               }
-#endif
-       }
 
        if (breakpoint->type != BKPT_TYPE_BY_ADDR(breakpoint->address)) {
                if (breakpoint->type == BKPT_HARD) {
@@ -1533,18 +1520,6 @@ static int cortex_m3_store_core_reg_u32(struct target *target,
        struct armv7m_common *armv7m = target_to_armv7m(target);
        struct adiv5_dap *swjdp = armv7m->arm.dap;
 
-#ifdef ARMV7_GDB_HACKS
-       /* If the LR register is being modified, make sure it will put us
-        * in "thumb" mode, or an INVSTATE exception will occur. This is a
-        * hack to deal with the fact that gdb will sometimes "forge"
-        * return addresses, and doesn't set the LSB correctly (i.e., when
-        * printing expressions containing function calls, it sets LR = 0.)
-        * Valid exception return codes have bit 0 set too.
-        */
-       if (num == ARMV7M_R14)
-               value |= 0x01;
-#endif
-
        /* NOTE:  we "know" here that the register identifiers used
         * in the v7m header match the Cortex-M3 Debug Core Register
         * Selector values for R0..R15, xPSR, MSP, and PSP.
@@ -1608,7 +1583,6 @@ static int cortex_m3_read_memory(struct target *target, uint32_t address,
 {
        struct armv7m_common *armv7m = target_to_armv7m(target);
        struct adiv5_dap *swjdp = armv7m->arm.dap;
-       int retval = ERROR_COMMAND_SYNTAX_ERROR;
 
        if (armv7m->arm.is_armv6m) {
                /* armv6m does not handle unaligned memory access */
@@ -1616,22 +1590,7 @@ static int cortex_m3_read_memory(struct target *target, uint32_t address,
                        return ERROR_TARGET_UNALIGNED_ACCESS;
        }
 
-       /* cortex_m3 handles unaligned memory access */
-       if (count && buffer) {
-               switch (size) {
-                       case 4:
-                               retval = mem_ap_read_buf_u32(swjdp, buffer, 4 * count, address, true);
-                               break;
-                       case 2:
-                               retval = mem_ap_read_buf_u16(swjdp, buffer, 2 * count, address);
-                               break;
-                       case 1:
-                               retval = mem_ap_read_buf_u8(swjdp, buffer, count, address);
-                               break;
-               }
-       }
-
-       return retval;
+       return mem_ap_read(swjdp, buffer, size, count, address, true);
 }
 
 static int cortex_m3_write_memory(struct target *target, uint32_t address,
@@ -1639,7 +1598,6 @@ static int cortex_m3_write_memory(struct target *target, uint32_t address,
 {
        struct armv7m_common *armv7m = target_to_armv7m(target);
        struct adiv5_dap *swjdp = armv7m->arm.dap;
-       int retval = ERROR_COMMAND_SYNTAX_ERROR;
 
        if (armv7m->arm.is_armv6m) {
                /* armv6m does not handle unaligned memory access */
@@ -1647,21 +1605,7 @@ static int cortex_m3_write_memory(struct target *target, uint32_t address,
                        return ERROR_TARGET_UNALIGNED_ACCESS;
        }
 
-       if (count && buffer) {
-               switch (size) {
-                       case 4:
-                               retval = mem_ap_write_buf_u32(swjdp, buffer, 4 * count, address, true);
-                               break;
-                       case 2:
-                               retval = mem_ap_write_buf_u16(swjdp, buffer, 2 * count, address);
-                               break;
-                       case 1:
-                               retval = mem_ap_write_buf_u8(swjdp, buffer, count, address);
-                               break;
-               }
-       }
-
-       return retval;
+       return mem_ap_write(swjdp, buffer, size, count, address, true);
 }
 
 static int cortex_m3_init_target(struct command_context *cmd_ctx,
@@ -1917,7 +1861,7 @@ static int cortex_m3_dcc_read(struct adiv5_dap *swjdp, uint8_t *value, uint8_t *
        uint16_t dcrdr;
        int retval;
 
-       mem_ap_read_buf_u16(swjdp, (uint8_t *)&dcrdr, 1, DCB_DCRDR);
+       mem_ap_read_buf_u16(swjdp, (uint8_t *)&dcrdr, 2, DCB_DCRDR);
        *ctrl = (uint8_t)dcrdr;
        *value = (uint8_t)(dcrdr >> 8);
 
@@ -1927,7 +1871,7 @@ static int cortex_m3_dcc_read(struct adiv5_dap *swjdp, uint8_t *value, uint8_t *
         * signify we have read data */
        if (dcrdr & (1 << 0)) {
                dcrdr = 0;
-               retval = mem_ap_write_buf_u16(swjdp, (uint8_t *)&dcrdr, 1, DCB_DCRDR);
+               retval = mem_ap_write_buf_u16(swjdp, (uint8_t *)&dcrdr, 2, DCB_DCRDR);
                if (retval != ERROR_OK)
                        return retval;
        }
@@ -2050,7 +1994,7 @@ static int cortex_m3_verify_pointer(struct command_context *cmd_ctx,
        struct cortex_m3_common *cm3)
 {
        if (cm3->common_magic != CORTEX_M3_COMMON_MAGIC) {
-               command_print(cmd_ctx, "target is not a Cortex-M3");
+               command_print(cmd_ctx, "target is not a Cortex-M");
                return ERROR_TARGET_INVALID;
        }
        return ERROR_OK;
@@ -2185,7 +2129,7 @@ COMMAND_HANDLER(handle_cortex_m3_mask_interrupts_command)
        }
 
        n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_m3->isrmasking_mode);
-       command_print(CMD_CTX, "cortex_m3 interrupt mask %s", n->name);
+       command_print(CMD_CTX, "cortex_m interrupt mask %s", n->name);
 
        return ERROR_OK;
 }
@@ -2222,7 +2166,7 @@ COMMAND_HANDLER(handle_cortex_m3_reset_config_command)
                        break;
        }
 
-       command_print(CMD_CTX, "cortex_m3 reset_config %s", reset_config);
+       command_print(CMD_CTX, "cortex_m reset_config %s", reset_config);
 
        return ERROR_OK;
 }
@@ -2232,7 +2176,7 @@ static const struct command_registration cortex_m3_exec_command_handlers[] = {
                .name = "maskisr",
                .handler = handle_cortex_m3_mask_interrupts_command,
                .mode = COMMAND_EXEC,
-               .help = "mask cortex_m3 interrupts",
+               .help = "mask cortex_m interrupts",
                .usage = "['auto'|'on'|'off']",
        },
        {
@@ -2256,9 +2200,9 @@ static const struct command_registration cortex_m3_command_handlers[] = {
                .chain = armv7m_command_handlers,
        },
        {
-               .name = "cortex_m3",
+               .name = "cortex_m",
                .mode = COMMAND_EXEC,
-               .help = "Cortex-M3 command group",
+               .help = "Cortex-M command group",
                .usage = "",
                .chain = cortex_m3_exec_command_handlers,
        },
@@ -2266,7 +2210,8 @@ static const struct command_registration cortex_m3_command_handlers[] = {
 };
 
 struct target_type cortexm3_target = {
-       .name = "cortex_m3",
+       .name = "cortex_m",
+       .deprecated_name = "cortex_m3",
 
        .poll = cortex_m3_poll,
        .arch_state = armv7m_arch_state,

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)