target/arm946e: change prototype of arm946e_verify_pointer()
[openocd.git] / src / target / arm946e.c
index 2a71f2d3501d6011190cb316acbe04c120008ea4..278a70ca24f0447b82801491fd75fbd9de701efd 100644 (file)
@@ -19,9 +19,7 @@
  *   GNU General Public License for more details.                          *
  *                                                                         *
  *   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.             *
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
  ***************************************************************************/
 
 #ifdef HAVE_CONFIG_H
@@ -101,16 +99,26 @@ static int arm946e_target_create(struct target *target, Jim_Interp *interp)
        return ERROR_OK;
 }
 
-static int arm946e_verify_pointer(struct command_context *cmd_ctx,
+static int arm946e_verify_pointer(struct command_invocation *cmd,
        struct arm946e_common *arm946e)
 {
        if (arm946e->common_magic != ARM946E_COMMON_MAGIC) {
-               command_print(cmd_ctx, "target is not an ARM946");
+               command_print(cmd->ctx, "target is not an ARM946");
                return ERROR_TARGET_INVALID;
        }
        return ERROR_OK;
 }
 
+/*
+ * Update cp15_control_reg, saved on debug_entry.
+ */
+static void arm946e_update_cp15_caches(struct target *target, uint32_t value)
+{
+       struct arm946e_common *arm946e = target_to_arm946(target);
+       arm946e->cp15_control_reg = (arm946e->cp15_control_reg & ~(CP15_CTL_DCACHE|CP15_CTL_ICACHE))
+               | (value & (CP15_CTL_DCACHE|CP15_CTL_ICACHE));
+}
+
 /*
  * REVISIT:  The "read_cp15" and "write_cp15" commands could hook up
  * to eventual mrc() and mcr() routines ... the reg_addr values being
@@ -129,7 +137,7 @@ static int arm946e_read_cp15(struct target *target, int reg_addr, uint32_t *valu
        retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
-       retval = arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
+       retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
 
@@ -181,7 +189,7 @@ int arm946e_write_cp15(struct target *target, int reg_addr, uint32_t value)
        retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
-       retval = arm_jtag_set_instr(jtag_info, jtag_info->intest_instr, NULL, TAP_IDLE);
+       retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
        if (retval != ERROR_OK)
                return retval;
 
@@ -479,7 +487,7 @@ uint32_t arm946e_invalidate_icache(struct target *target, uint32_t address,
 }
 
 /** Writes a buffer, in the specified word size, with current MMU settings. */
-int arm946e_write_memory(struct target *target, uint32_t address,
+int arm946e_write_memory(struct target *target, target_addr_t address,
        uint32_t size, uint32_t count, const uint8_t *buffer)
 {
        int retval;
@@ -494,7 +502,7 @@ int arm946e_write_memory(struct target *target, uint32_t address,
        /**
         * Write memory
         */
-       retval = arm7_9_write_memory(target, address, size, count, buffer);
+       retval = arm7_9_write_memory_opt(target, address, size, count, buffer);
        if (retval != ERROR_OK)
                return retval;
 
@@ -527,7 +535,7 @@ int arm946e_write_memory(struct target *target, uint32_t address,
 
 }
 
-int arm946e_read_memory(struct target *target, uint32_t address,
+int arm946e_read_memory(struct target *target, target_addr_t address,
        uint32_t size, uint32_t count, uint8_t *buffer)
 {
        int retval;
@@ -541,61 +549,162 @@ int arm946e_read_memory(struct target *target, uint32_t address,
        return ERROR_OK;
 }
 
+COMMAND_HANDLER(arm946e_handle_cp15)
+{
+       /* one or two arguments, access a single register (write if second argument is given) */
+       if (CMD_ARGC < 1 || CMD_ARGC > 2)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
+       struct target *target = get_current_target(CMD_CTX);
+
+       struct arm946e_common *arm946e = target_to_arm946(target);
+       int retval = arm946e_verify_pointer(CMD, arm946e);
+       if (retval != ERROR_OK)
+               return retval;
+
+       if (target->state != TARGET_HALTED) {
+               command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+
+       uint32_t address;
+       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
+
+       if (CMD_ARGC == 1) {
+               uint32_t value;
+               retval = arm946e_read_cp15(target, address, &value);
+               if (retval != ERROR_OK) {
+                       command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address);
+                       return retval;
+               }
+               retval = jtag_execute_queue();
+               if (retval != ERROR_OK)
+                       return retval;
+
+               /* Return value in hex format */
+               command_print(CMD_CTX, "0x%08" PRIx32, value);
+       } else if (CMD_ARGC == 2) {
+               uint32_t value;
+               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
+
+               retval = arm946e_write_cp15(target, address, value);
+               if (retval != ERROR_OK) {
+                       command_print(CMD_CTX, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address);
+                       return retval;
+               }
+               if (address == CP15_CTL)
+                       arm946e_update_cp15_caches(target, value);
+       }
+
+       return ERROR_OK;
+}
 
-COMMAND_HANDLER(arm946e_handle_cp15_command)
+COMMAND_HANDLER(arm946e_handle_idcache)
 {
+       if (CMD_ARGC > 1)
+               return ERROR_COMMAND_SYNTAX_ERROR;
+
        int retval;
        struct target *target = get_current_target(CMD_CTX);
        struct arm946e_common *arm946e = target_to_arm946(target);
 
-       retval = arm946e_verify_pointer(CMD_CTX, arm946e);
+       retval = arm946e_verify_pointer(CMD, arm946e);
        if (retval != ERROR_OK)
                return retval;
 
        if (target->state != TARGET_HALTED) {
                command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME);
+               return ERROR_TARGET_NOT_HALTED;
+       }
+
+       bool icache = (strcmp(CMD_NAME, "icache") == 0);
+       uint32_t csize = arm946e_cp15_get_csize(target, icache ? GET_ICACHE_SIZE : GET_DCACHE_SIZE) / 1024;
+       if (CMD_ARGC == 0) {
+               bool  bena = ((arm946e->cp15_control_reg & (icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE)) != 0)
+                         && (arm946e->cp15_control_reg & 0x1);
+               if (csize == 0)
+                       command_print(CMD_CTX, "%s-cache absent", icache ? "I" : "D");
+               else
+                       command_print(CMD_CTX, "%s-cache size: %" PRIu32 "K, %s",
+                                     icache ? "I" : "D", csize, bena ? "enabled" : "disabled");
                return ERROR_OK;
        }
 
-       /* one or more argument, access a single register (write if second argument is given */
-       if (CMD_ARGC >= 1) {
-               uint32_t address;
-               COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
+       bool flush = false;
+       bool enable = false;
+       retval = command_parse_bool_arg(CMD_ARGV[0], &enable);
+       if (retval == ERROR_COMMAND_SYNTAX_ERROR) {
+               if (strcmp(CMD_ARGV[0], "flush") == 0) {
+                       flush = true;
+                       retval = ERROR_OK;
+               } else
+                       return retval;
+       }
 
-               if (CMD_ARGC == 1) {
-                       uint32_t value;
-                       retval = arm946e_read_cp15(target, address, &value);
-                       if (retval != ERROR_OK) {
-                               command_print(CMD_CTX, "couldn't access reg %" PRIi32, address);
-                               return ERROR_OK;
-                       }
-                       retval = jtag_execute_queue();
-                       if (retval != ERROR_OK)
-                               return retval;
+       /* Do not invalidate or change state, if cache is absent */
+       if (csize == 0) {
+               command_print(CMD_CTX, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]);
+               return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
+       }
 
-                       command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, address, value);
-               } else if (CMD_ARGC == 2) {
-                       uint32_t value;
-                       COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
-                       retval = arm946e_write_cp15(target, address, value);
-                       if (retval != ERROR_OK) {
-                               command_print(CMD_CTX, "couldn't access reg %" PRIi32, address);
-                               return ERROR_OK;
-                       }
-                       command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, address, value);
-               }
+       /* NOTE: flushing entire cache will not preserve lock-down cache regions */
+       if (icache) {
+               if ((arm946e->cp15_control_reg & CP15_CTL_ICACHE) && !enable)
+                       retval = arm946e_invalidate_whole_icache(target);
+       } else {
+               if ((arm946e->cp15_control_reg & CP15_CTL_DCACHE) && !enable)
+                       retval = arm946e_invalidate_whole_dcache(target);
        }
 
+       if (retval != ERROR_OK || flush)
+               return retval;
+
+       uint32_t value;
+       retval = arm946e_read_cp15(target, CP15_CTL, &value);
+       if (retval != ERROR_OK)
+               return retval;
+
+       uint32_t vnew = value;
+       uint32_t cmask = icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE;
+       if (enable) {
+               if ((value & 0x1) == 0)
+                       LOG_WARNING("arm946e: MPU must be enabled for cache to operate");
+               vnew |= cmask;
+       } else
+               vnew &= ~cmask;
+
+       if (vnew == value)
+               return ERROR_OK;
+
+       retval = arm946e_write_cp15(target, CP15_CTL, vnew);
+       if (retval != ERROR_OK)
+               return retval;
+
+       arm946e_update_cp15_caches(target, vnew);
        return ERROR_OK;
 }
 
 static const struct command_registration arm946e_exec_command_handlers[] = {
        {
                .name = "cp15",
-               .handler = arm946e_handle_cp15_command,
+               .handler = arm946e_handle_cp15,
                .mode = COMMAND_EXEC,
                .usage = "regnum [value]",
-               .help = "display/modify cp15 register",
+               .help = "read/modify cp15 register",
+       },
+       {
+               .name = "icache",
+               .handler = arm946e_handle_idcache,
+               .mode = COMMAND_EXEC,
+               .usage = "['enable'|'disable'|'flush']",
+               .help = "I-cache info and operations",
+       },
+       {
+               .name = "dcache",
+               .handler = arm946e_handle_idcache,
+               .mode = COMMAND_EXEC,
+               .usage = "['enable'|'disable'|'flush']",
+               .help = "D-cache info and operations",
        },
        COMMAND_REGISTRATION_DONE
 };
@@ -631,6 +740,7 @@ struct target_type arm946e_target = {
        .deassert_reset = arm7_9_deassert_reset,
        .soft_reset_halt = arm7_9_soft_reset_halt,
 
+       .get_gdb_arch = arm_get_gdb_arch,
        .get_gdb_reg_list = arm_get_gdb_reg_list,
 
        /* .read_memory = arm7_9_read_memory, */
@@ -638,8 +748,6 @@ struct target_type arm946e_target = {
        .read_memory = arm946e_read_memory,
        .write_memory = arm946e_write_memory,
 
-       .bulk_write_memory = arm7_9_bulk_write_memory,
-
        .checksum_memory = arm_checksum_memory,
        .blank_check_memory = arm_blank_check_memory,
 

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)