David Brownell <david-b@pacbell.net>:
[openocd.git] / src / target / armv7m.c
index a2e74702160a99dc7b18c27edb237ca24435fa9c..5849443018afb4c75481110bc3dae203db8e85c8 100644 (file)
@@ -8,7 +8,7 @@
  *   Copyright (C) 2008 by Spencer Oliver                                  *
  *   spen@spen-soft.co.uk                                                  *
  *                                                                         *
- *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
+ *   Copyright (C) 2007,2008 Øyvind Harboe                                 *
  *   oyvind.harboe@zylin.com                                               *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -60,8 +60,8 @@ char* armv7m_core_reg_list[] =
        "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12",
        "sp", "lr", "pc",
        "xPSR", "msp", "psp",
-       /* reg 20 has 4 bytes: CONTROL, FAULTMASK, BASEPRI, PRIMASK */
-       "spec20",
+       /* Registers accessed through special reg 20 */
+       "primask", "basepri", "faultmask", "control"
 };
 
 uint8_t armv7m_gdb_dummy_fp_value[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@@ -111,11 +111,11 @@ armv7m_core_reg_t armv7m_core_reg_list_arch_info[] =
        {17, ARMV7M_REGISTER_CORE_GP, ARMV7M_MODE_ANY, NULL, NULL}, /* MSP */
        {18, ARMV7M_REGISTER_CORE_GP, ARMV7M_MODE_ANY, NULL, NULL}, /* PSP */
 
-       /* FIXME the register numbers here are core-specific.
-        * Numbers 0..18 above work for all Cortex-M3 revisions.
-        * Number 20 below works for CM3 r2p0 and later.
-        */
-       {20, ARMV7M_REGISTER_CORE_SP, ARMV7M_MODE_ANY, NULL, NULL},
+       /*  CORE_SP are accesible using coreregister 20 */
+       {19, ARMV7M_REGISTER_CORE_SP, ARMV7M_MODE_ANY, NULL, NULL}, /* PRIMASK */
+       {20, ARMV7M_REGISTER_CORE_SP, ARMV7M_MODE_ANY, NULL, NULL}, /* BASEPRI */
+       {21, ARMV7M_REGISTER_CORE_SP, ARMV7M_MODE_ANY, NULL, NULL}, /* FAULTMASK */
+       {22, ARMV7M_REGISTER_CORE_SP, ARMV7M_MODE_ANY, NULL, NULL}  /* CONTROL */
 };
 
 int armv7m_core_reg_arch_type = -1;
@@ -387,21 +387,12 @@ int armv7m_run_algorithm(struct target_s *target, int num_mem_params, mem_param_
                armv7m_set_core_reg(reg, reg_params[i].value);
        }
 
-       /* NOTE:  CONTROL is bits 31:24 of SPEC20 register, if it's present;
-        * holding a two-bit field.
-        *
-        * FIXME need a solution using ARMV7M_T_MSR().  Use it at least for
-        * earlier cores.
-        */
-       if (armv7m_algorithm_info->core_mode != ARMV7M_MODE_ANY
-                       && armv7m->has_spec20)
+       if (armv7m_algorithm_info->core_mode != ARMV7M_MODE_ANY)
        {
                LOG_DEBUG("setting core_mode: 0x%2.2x", armv7m_algorithm_info->core_mode);
-
-               buf_set_u32(armv7m->core_cache->reg_list[ARMV7M_SPEC20].value,
-                               24, 2, armv7m_algorithm_info->core_mode);
-               armv7m->core_cache->reg_list[ARMV7M_SPEC20].dirty = 1;
-               armv7m->core_cache->reg_list[ARMV7M_SPEC20].valid = 1;
+               buf_set_u32(armv7m->core_cache->reg_list[ARMV7M_CONTROL].value, 0, 1, armv7m_algorithm_info->core_mode);
+               armv7m->core_cache->reg_list[ARMV7M_CONTROL].dirty = 1;
+               armv7m->core_cache->reg_list[ARMV7M_CONTROL].valid = 1;
        }
 
        /* ARMV7M always runs in Thumb state */
@@ -554,20 +545,6 @@ int armv7m_init_arch_info(target_t *target, armv7m_common_t *armv7m)
        return ERROR_OK;
 }
 
-int armv7m_register_commands(struct command_context_s *cmd_ctx)
-{
-       command_t *arm_adi_v5_dap_cmd;
-
-       arm_adi_v5_dap_cmd = register_command(cmd_ctx, NULL, "dap", NULL, COMMAND_ANY, "cortex dap specific commands");
-       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "info", handle_dap_info_command, COMMAND_EXEC, "Displays dap info for ap [num], default currently selected AP");
-       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "apsel", handle_dap_apsel_command, COMMAND_EXEC, "Select a different AP [num] (default 0)");
-       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "apid", handle_dap_apid_command, COMMAND_EXEC, "Displays id reg from AP [num], default currently selected AP");
-       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "baseaddr", handle_dap_baseaddr_command, COMMAND_EXEC, "Displays debug base address from AP [num], default currently selected AP");
-       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "memaccess", handle_dap_memaccess_command, COMMAND_EXEC, "set/get number of extra tck for mem-ap memory bus access [0-255]");
-
-       return ERROR_OK;
-}
-
 int armv7m_checksum_memory(struct target_s *target, uint32_t address, uint32_t count, uint32_t* checksum)
 {
        working_area_t *crc_algorithm;
@@ -711,10 +688,12 @@ int armv7m_blank_check_memory(struct target_s *target, uint32_t address, uint32_
        return ERROR_OK;
 }
 
-/********************************************************************************************************************
-* Return the debug ap baseaddress in hexadecimal, no extra output to simplify script processing
-*********************************************************************************************************************/
-int handle_dap_baseaddr_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+/*
+ * Return the debug ap baseaddress in hexadecimal;
+ * no extra output to simplify script processing
+ */
+static int handle_dap_baseaddr_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
        armv7m_common_t *armv7m = target->arch_info;
@@ -746,97 +725,83 @@ int handle_dap_baseaddr_command(struct command_context_s *cmd_ctx, char *cmd, ch
 }
 
 
-/********************************************************************************************************************
-* Return the debug ap id in hexadecimal, no extra output to simplify script processing
-*********************************************************************************************************************/
-extern int handle_dap_apid_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+/*
+ * Return the debug ap id in hexadecimal;
+ * no extra output to simplify script processing
+ */
+extern int handle_dap_apid_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
        armv7m_common_t *armv7m = target->arch_info;
        swjdp_common_t *swjdp = &armv7m->swjdp_info;
-       uint32_t apsel, apselsave, apid;
-       int retval;
 
-       apsel = swjdp->apsel;
-       apselsave = swjdp->apsel;
-       if (argc > 0)
-       {
-               apsel = strtoul(args[0], NULL, 0);
-       }
-
-       if (apselsave != apsel)
-       {
-               dap_ap_select(swjdp, apsel);
-       }
-
-       dap_ap_read_reg_u32(swjdp, 0xFC, &apid);
-       retval = swjdp_transaction_endcheck(swjdp);
-       command_print(cmd_ctx, "0x%8.8" PRIx32 "", apid);
-       if (apselsave != apsel)
-       {
-               dap_ap_select(swjdp, apselsave);
-       }
-
-       return retval;
+       return dap_apid_command(cmd_ctx, swjdp, args, argc);
 }
 
-int handle_dap_apsel_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int handle_dap_apsel_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
        armv7m_common_t *armv7m = target->arch_info;
        swjdp_common_t *swjdp = &armv7m->swjdp_info;
-       uint32_t apsel, apid;
-       int retval;
-
-       apsel = 0;
-       if (argc > 0)
-       {
-               apsel = strtoul(args[0], NULL, 0);
-       }
-
-       dap_ap_select(swjdp, apsel);
-       dap_ap_read_reg_u32(swjdp, 0xFC, &apid);
-       retval = swjdp_transaction_endcheck(swjdp);
-       command_print(cmd_ctx, "ap %i selected, identification register 0x%8.8" PRIx32 "", (int)apsel, apid);
 
-       return retval;
+       return dap_apsel_command(cmd_ctx, swjdp, args, argc);
 }
 
-int handle_dap_memaccess_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+static int handle_dap_memaccess_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
        armv7m_common_t *armv7m = target->arch_info;
        swjdp_common_t *swjdp = &armv7m->swjdp_info;
-       uint32_t memaccess_tck;
-
-       memaccess_tck = swjdp->memaccess_tck;
-       if (argc > 0)
-       {
-               memaccess_tck = strtoul(args[0], NULL, 0);
-       }
-
-       swjdp->memaccess_tck = memaccess_tck;
-       command_print(cmd_ctx, "memory bus access delay set to %i tck", (int)(swjdp->memaccess_tck));
 
-       return ERROR_OK;
+       return dap_memaccess_command(cmd_ctx, swjdp, args, argc);
 }
 
-int handle_dap_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc)
+
+static int handle_dap_info_command(struct command_context_s *cmd_ctx,
+               char *cmd, char **args, int argc)
 {
        target_t *target = get_current_target(cmd_ctx);
        armv7m_common_t *armv7m = target->arch_info;
        swjdp_common_t *swjdp = &armv7m->swjdp_info;
-       int retval;
        uint32_t apsel;
 
        apsel =  swjdp->apsel;
        if (argc > 0)
-       {
                apsel = strtoul(args[0], NULL, 0);
-       }
-
-       retval = dap_info_command(cmd_ctx, swjdp, apsel);
 
-       return retval;
+       return dap_info_command(cmd_ctx, swjdp, apsel);
 }
 
+int armv7m_register_commands(struct command_context_s *cmd_ctx)
+{
+       command_t *arm_adi_v5_dap_cmd;
+
+       arm_adi_v5_dap_cmd = register_command(cmd_ctx, NULL, "dap",
+                       NULL, COMMAND_ANY,
+                       "cortex dap specific commands");
+
+       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "info",
+                       handle_dap_info_command, COMMAND_EXEC,
+                       "Displays dap info for ap [num],"
+                       "default currently selected AP");
+       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "apsel",
+                       handle_dap_apsel_command, COMMAND_EXEC,
+                       "Select a different AP [num] (default 0)");
+       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "apid",
+                       handle_dap_apid_command, COMMAND_EXEC,
+                       "Displays id reg from AP [num], "
+                       "default currently selected AP");
+       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "baseaddr",
+                       handle_dap_baseaddr_command, COMMAND_EXEC,
+                       "Displays debug base address from AP [num],"
+                       "default currently selected AP");
+       register_command(cmd_ctx, arm_adi_v5_dap_cmd, "memaccess",
+                       handle_dap_memaccess_command, COMMAND_EXEC,
+                       "set/get number of extra tck for mem-ap "
+                       "memory bus access [0-255]");
+
+       return ERROR_OK;
+}

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)