OpenOCD
arm966e.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2005 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2008 by Spencer Oliver *
8  * spen@spen-soft.co.uk *
9  ***************************************************************************/
10 
11 #ifdef HAVE_CONFIG_H
12 #include "config.h"
13 #endif
14 
15 #include "arm966e.h"
16 #include "target_type.h"
17 #include "arm_opcodes.h"
18 
19 #if 0
20 #define _DEBUG_INSTRUCTION_EXECUTION_
21 #endif
22 
23 int arm966e_init_arch_info(struct target *target, struct arm966e_common *arm966e, struct jtag_tap *tap)
24 {
25  struct arm7_9_common *arm7_9 = &arm966e->arm7_9_common;
26 
27  /* initialize arm7/arm9 specific info (including armv4_5) */
28  arm9tdmi_init_arch_info(target, arm7_9, tap);
29 
31 
32  /* The ARM966E-S implements the ARMv5TE architecture which
33  * has the BKPT instruction, so we don't have to use a watchpoint comparator
34  */
35  arm7_9->arm_bkpt = ARMV5_BKPT(0x0);
36  arm7_9->thumb_bkpt = ARMV5_T_BKPT(0x0) & 0xffff;
37 
38  return ERROR_OK;
39 }
40 
41 static int arm966e_target_create(struct target *target, Jim_Interp *interp)
42 {
43  struct arm966e_common *arm966e = calloc(1, sizeof(struct arm966e_common));
44 
45  return arm966e_init_arch_info(target, arm966e, target->tap);
46 }
47 
48 static void arm966e_deinit_target(struct target *target)
49 {
50  struct arm *arm = target_to_arm(target);
51  struct arm966e_common *arm966e = target_to_arm966(target);
52 
55  free(arm966e);
56 }
57 
59  struct arm966e_common *arm966e)
60 {
61  if (arm966e->common_magic != ARM966E_COMMON_MAGIC) {
62  command_print(cmd, "target is not an ARM966");
63  return ERROR_TARGET_INVALID;
64  }
65  return ERROR_OK;
66 }
67 
68 /*
69  * REVISIT: The "read_cp15" and "write_cp15" commands could hook up
70  * to eventual mrc() and mcr() routines ... the reg_addr values being
71  * constructed (for CP15 only) from Opcode_1, Opcode_2, and CRn values.
72  * See section 7.3 of the ARM966E-S TRM.
73  */
74 
75 static int arm966e_read_cp15(struct target *target, int reg_addr, uint32_t *value)
76 {
77  int retval = ERROR_OK;
78  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
79  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
80  struct scan_field fields[3];
81  uint8_t reg_addr_buf = reg_addr & 0x3f;
82  uint8_t nr_w_buf = 0;
83 
84  retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
85  if (retval != ERROR_OK)
86  return retval;
87  retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
88  if (retval != ERROR_OK)
89  return retval;
90 
91  fields[0].num_bits = 32;
92  /* REVISIT: table 7-2 shows that bits 31-31 need to be
93  * specified for accessing BIST registers ...
94  */
95  fields[0].out_value = NULL;
96  fields[0].in_value = NULL;
97 
98  fields[1].num_bits = 6;
99  fields[1].out_value = &reg_addr_buf;
100  fields[1].in_value = NULL;
101 
102  fields[2].num_bits = 1;
103  fields[2].out_value = &nr_w_buf;
104  fields[2].in_value = NULL;
105 
106  jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
107 
108  fields[1].in_value = (uint8_t *)value;
109 
110  jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
111 
113 
114 
115 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
116  retval = jtag_execute_queue();
117  if (retval != ERROR_OK)
118  return retval;
119  LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, *value);
120 #endif
121 
122  return ERROR_OK;
123 }
124 
125 /* EXPORTED to str9x (flash) */
126 int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
127 {
128  int retval = ERROR_OK;
129  struct arm7_9_common *arm7_9 = target_to_arm7_9(target);
130  struct arm_jtag *jtag_info = &arm7_9->jtag_info;
131  struct scan_field fields[3];
132  uint8_t reg_addr_buf = reg_addr & 0x3f;
133  uint8_t nr_w_buf = 1;
134  uint8_t value_buf[4];
135 
136  buf_set_u32(value_buf, 0, 32, value);
137 
138  retval = arm_jtag_scann(jtag_info, 0xf, TAP_IDLE);
139  if (retval != ERROR_OK)
140  return retval;
141  retval = arm_jtag_set_instr(jtag_info->tap, jtag_info->intest_instr, NULL, TAP_IDLE);
142  if (retval != ERROR_OK)
143  return retval;
144 
145  fields[0].num_bits = 32;
146  fields[0].out_value = value_buf;
147  fields[0].in_value = NULL;
148 
149  fields[1].num_bits = 6;
150  fields[1].out_value = &reg_addr_buf;
151  fields[1].in_value = NULL;
152 
153  fields[2].num_bits = 1;
154  fields[2].out_value = &nr_w_buf;
155  fields[2].in_value = NULL;
156 
157  jtag_add_dr_scan(jtag_info->tap, 3, fields, TAP_IDLE);
158 
159 #ifdef _DEBUG_INSTRUCTION_EXECUTION_
160  LOG_DEBUG("addr: 0x%x value: %8.8x", reg_addr, value);
161 #endif
162 
163  return ERROR_OK;
164 }
165 
166 COMMAND_HANDLER(arm966e_handle_cp15_command)
167 {
168  int retval;
170  struct arm966e_common *arm966e = target_to_arm966(target);
171 
172  retval = arm966e_verify_pointer(CMD, arm966e);
173  if (retval != ERROR_OK)
174  return retval;
175 
176  if (target->state != TARGET_HALTED) {
177  command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME);
178  return ERROR_OK;
179  }
180 
181  /* one or more argument, access a single register (write if second argument is given */
182  if (CMD_ARGC >= 1) {
183  uint32_t address;
184  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address);
185 
186  if (CMD_ARGC == 1) {
187  uint32_t value;
188  retval = arm966e_read_cp15(target, address, &value);
189  if (retval != ERROR_OK) {
191  "couldn't access reg %" PRIu32,
192  address);
193  return ERROR_OK;
194  }
195  retval = jtag_execute_queue();
196  if (retval != ERROR_OK)
197  return retval;
198 
199  command_print(CMD, "%" PRIu32 ": %8.8" PRIx32,
200  address, value);
201  } else if (CMD_ARGC == 2) {
202  uint32_t value;
203  COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value);
204  retval = arm966e_write_cp15(target, address, value);
205  if (retval != ERROR_OK) {
207  "couldn't access reg %" PRIu32,
208  address);
209  return ERROR_OK;
210  }
211  command_print(CMD, "%" PRIu32 ": %8.8" PRIx32,
212  address, value);
213  }
214  }
215 
216  return ERROR_OK;
217 }
218 
219 static const struct command_registration arm966e_exec_command_handlers[] = {
220  {
221  .name = "cp15",
222  .handler = arm966e_handle_cp15_command,
223  .mode = COMMAND_EXEC,
224  .usage = "regnum [value]",
225  .help = "display/modify cp15 register",
226  },
228 };
229 
231  {
233  },
234  {
235  .name = "arm966e",
236  .mode = COMMAND_ANY,
237  .help = "arm966e command group",
238  .usage = "",
240  },
242 };
243 
245 struct target_type arm966e_target = {
246  .name = "arm966e",
247 
248  .poll = arm7_9_poll,
249  .arch_state = arm_arch_state,
250 
251  .target_request_data = arm7_9_target_request_data,
252 
253  .halt = arm7_9_halt,
254  .resume = arm7_9_resume,
255  .step = arm7_9_step,
256 
257  .assert_reset = arm7_9_assert_reset,
258  .deassert_reset = arm7_9_deassert_reset,
259  .soft_reset_halt = arm7_9_soft_reset_halt,
260 
261  .get_gdb_arch = arm_get_gdb_arch,
262  .get_gdb_reg_list = arm_get_gdb_reg_list,
263 
264  .read_memory = arm7_9_read_memory,
265  .write_memory = arm7_9_write_memory_opt,
266 
267  .checksum_memory = arm_checksum_memory,
268  .blank_check_memory = arm_blank_check_memory,
269 
270  .run_algorithm = armv4_5_run_algorithm,
271 
272  .add_breakpoint = arm7_9_add_breakpoint,
273  .remove_breakpoint = arm7_9_remove_breakpoint,
274  .add_watchpoint = arm7_9_add_watchpoint,
275  .remove_watchpoint = arm7_9_remove_watchpoint,
276 
277  .commands = arm966e_command_handlers,
278  .target_create = arm966e_target_create,
279  .init_target = arm9tdmi_init_target,
280  .deinit_target = arm966e_deinit_target,
281  .examine = arm7_9_examine,
282  .check_reset = arm7_9_check_reset,
283 };
int arm7_9_write_memory_opt(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
int arm7_9_examine(struct target *target)
Perform per-target setup that requires JTAG access.
void arm7_9_deinit(struct target *target)
int arm7_9_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
int arm7_9_add_breakpoint(struct target *target, struct breakpoint *breakpoint)
Add a breakpoint to an ARM7/9 target.
int arm7_9_soft_reset_halt(struct target *target)
Issue a software reset and halt to an ARM7/9 target.
int arm7_9_assert_reset(struct target *target)
Asserts the reset (SRST) on an ARM7/9 target.
int arm7_9_poll(struct target *target)
Polls an ARM7/9 target for its current status.
int arm7_9_halt(struct target *target)
Halt an ARM7/9 target.
int arm7_9_remove_breakpoint(struct target *target, struct breakpoint *breakpoint)
Removes a breakpoint from an ARM7/9 target.
int arm7_9_remove_watchpoint(struct target *target, struct watchpoint *watchpoint)
Remove a watchpoint from an ARM7/9 target.
int arm7_9_deassert_reset(struct target *target)
Deassert the reset (SRST) signal on an ARM7/9 target.
int arm7_9_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
int arm7_9_target_request_data(struct target *target, uint32_t size, uint8_t *buffer)
Get some data from the ARM7/9 target.
int arm7_9_add_watchpoint(struct target *target, struct watchpoint *watchpoint)
Add a watchpoint to an ARM7/9 target.
int arm7_9_check_reset(struct target *target)
int arm7_9_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
static struct arm7_9_common * target_to_arm7_9(struct target *target)
struct target_type arm966e_target
Holds methods for ARM966 targets.
Definition: arm966e.c:245
static const struct command_registration arm966e_exec_command_handlers[]
Definition: arm966e.c:219
static int arm966e_read_cp15(struct target *target, int reg_addr, uint32_t *value)
Definition: arm966e.c:75
static int arm966e_verify_pointer(struct command_invocation *cmd, struct arm966e_common *arm966e)
Definition: arm966e.c:58
int arm966e_write_cp15(struct target *target, int reg_addr, uint32_t value)
Definition: arm966e.c:126
static void arm966e_deinit_target(struct target *target)
Definition: arm966e.c:48
static int arm966e_target_create(struct target *target, Jim_Interp *interp)
Definition: arm966e.c:41
COMMAND_HANDLER(arm966e_handle_cp15_command)
Definition: arm966e.c:166
const struct command_registration arm966e_command_handlers[]
Definition: arm966e.c:230
int arm966e_init_arch_info(struct target *target, struct arm966e_common *arm966e, struct jtag_tap *tap)
Definition: arm966e.c:23
static struct arm966e_common * target_to_arm966(struct target *target)
Definition: arm966e.h:26
#define ARM966E_COMMON_MAGIC
Definition: arm966e.h:16
int arm9tdmi_init_arch_info(struct target *target, struct arm7_9_common *arm7_9, struct jtag_tap *tap)
Definition: arm9tdmi.c:711
int arm9tdmi_init_target(struct command_context *cmd_ctx, struct target *target)
Definition: arm9tdmi.c:703
const struct command_registration arm9tdmi_command_handlers[]
Definition: arm9tdmi.c:873
int arm_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Runs ARM code in the target to check whether a memory block holds all ones.
Definition: armv4_5.c:1595
int arm_arch_state(struct target *target)
Definition: armv4_5.c:782
int arm_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Runs ARM code in the target to calculate a CRC32 checksum.
Definition: armv4_5.c:1522
int arm_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: armv4_5.c:1194
int armv4_5_run_algorithm(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, target_addr_t entry_point, target_addr_t exit_point, int timeout_ms, void *arch_info)
Definition: armv4_5.c:1496
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:761
const char * arm_get_gdb_arch(struct target *target)
Definition: armv4_5.c:1189
static struct arm * target_to_arm(struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:243
static int arm_jtag_scann(struct arm_jtag *jtag_info, uint32_t new_scan_chain, tap_state_t end_state)
Definition: arm_jtag.h:43
static int arm_jtag_set_instr(struct jtag_tap *tap, uint32_t new_instr, void *no_verify_capture, tap_state_t end_state)
Definition: arm_jtag.h:31
static void arm_le_to_h_u32(jtag_callback_data_t arg)
Definition: arm_jtag.h:63
Macros used to generate various ARM or Thumb opcodes.
#define ARMV5_BKPT(im)
Definition: arm_opcodes.h:205
#define ARMV5_T_BKPT(im)
Definition: arm_opcodes.h:291
static void buf_set_u32(uint8_t *_buffer, unsigned first, unsigned num, uint32_t value)
Sets num bits in _buffer, starting at the first bit, using the bits in value.
Definition: binarybuffer.h:30
void command_print(struct command_invocation *cmd, const char *format,...)
Definition: command.c:473
#define CMD
Use this macro to access the command being handled, rather than accessing the variable directly.
Definition: command.h:140
#define CMD_NAME
Use this macro to access the name of the command being handled, rather than accessing the variable di...
Definition: command.h:160
#define CMD_ARGV
Use this macro to access the arguments for the command being handled, rather than accessing the varia...
Definition: command.h:155
#define CMD_ARGC
Use this macro to access the number of arguments for the command being handled, rather than accessing...
Definition: command.h:150
#define COMMAND_PARSE_NUMBER(type, in, out)
parses the string in into out as a type, or prints a command error and passes the error code to the c...
Definition: command.h:425
#define CMD_CTX
Use this macro to access the context of the command being handled, rather than accessing the variable...
Definition: command.h:145
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
@ COMMAND_EXEC
Definition: command.h:40
int jtag_execute_queue(void)
For software FIFO implementations, the queued commands can be executed during this call or earlier.
Definition: jtag/core.c:1037
void jtag_add_dr_scan(struct jtag_tap *active, int in_num_fields, const struct scan_field *in_fields, tap_state_t state)
Generate a DR SCAN using the fields passed to the function.
Definition: jtag/core.c:451
void jtag_add_callback(jtag_callback1_t f, jtag_callback_data_t data0)
A simpler version of jtag_add_callback4().
@ TAP_IDLE
Definition: jtag.h:52
intptr_t jtag_callback_data_t
Defines the type of data passed to the jtag_callback_t interface.
Definition: jtag.h:333
#define LOG_DEBUG(expr ...)
Definition: log.h:109
#define ERROR_OK
Definition: log.h:155
Structure for items that are common between both ARM7 and ARM9 targets.
Definition: arm7_9_common.h:28
uint32_t arm_bkpt
ARM breakpoint instruction.
Definition: arm7_9_common.h:36
struct arm_jtag jtag_info
JTAG information for target.
Definition: arm7_9_common.h:33
uint16_t thumb_bkpt
Thumb breakpoint instruction.
Definition: arm7_9_common.h:37
struct arm7_9_common arm7_9_common
Definition: arm966e.h:21
unsigned int common_magic
Definition: arm966e.h:19
uint32_t intest_instr
Definition: arm_jtag.h:24
struct jtag_tap * tap
Definition: arm_jtag.h:18
Represents a generic ARM core, with standard application registers.
Definition: arm.h:167
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
const char * name
Definition: command.h:229
const struct command_registration * chain
If non-NULL, the commands in chain will be registered in the same context and scope of this registrat...
Definition: command.h:243
Definition: jtag.h:100
This structure defines a single scan field in the scan.
Definition: jtag.h:86
int num_bits
The number of bits this field specifies.
Definition: jtag.h:88
uint8_t * in_value
A pointer to a 32-bit memory location for data scanned out.
Definition: jtag.h:92
const uint8_t * out_value
A pointer to value to be scanned into the device.
Definition: jtag.h:90
This holds methods shared between all instances of a given target type.
Definition: target_type.h:26
const char * name
Name of this type of target.
Definition: target_type.h:31
Definition: target.h:120
struct jtag_tap * tap
Definition: target.h:124
enum target_state state
Definition: target.h:162
struct target * get_current_target(struct command_context *cmd_ctx)
Definition: target.c:536
#define ERROR_TARGET_INVALID
Definition: target.h:789
@ TARGET_HALTED
Definition: target.h:55
#define NULL
Definition: usb.h:16
uint8_t cmd
Definition: vdebug.c:1