OpenOCD
armv7m.h
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) 2006 by Magnus Lundin *
8  * lundin@mlu.mine.nu *
9  * *
10  * Copyright (C) 2008 by Spencer Oliver *
11  * spen@spen-soft.co.uk *
12  ***************************************************************************/
13 
14 #ifndef OPENOCD_TARGET_ARMV7M_H
15 #define OPENOCD_TARGET_ARMV7M_H
16 
17 #include "arm.h"
18 #include "armv7m_trace.h"
19 
20 struct adiv5_ap;
21 
22 extern const int armv7m_psp_reg_map[];
23 extern const int armv7m_msp_reg_map[];
24 
25 const char *armv7m_exception_string(int number);
26 
27 /* Cortex-M DCRSR.REGSEL selectors */
28 enum {
33 
38 
43 
48 
52 
61 
67 
68  /* 32bit Floating-point registers */
101 };
102 
103 /* offsets into armv7m core register cache */
104 enum {
105  /* for convenience, the first set of indices match
106  * the Cortex-M DCRSR.REGSEL selectors
107  */
112 
117 
122 
127 
131 
132  /* following indices are arbitrary, do not match DCRSR.REGSEL selectors */
133 
134  /* A block of container and contained registers follows:
135  * THE ORDER IS IMPORTANT to the end of the block ! */
136  /* working register for packing/unpacking special regs, hidden from gdb */
138 
139  /* WARNING: If you use armv7m_write_core_reg() on one of 4 following
140  * special registers, the new data go to ARMV7M_PMSK_BPRI_FLTMSK_CTRL
141  * cache only and are not flushed to CPU HW register.
142  * To trigger write to CPU HW register, add
143  * armv7m_write_core_reg(,,ARMV7M_PMSK_BPRI_FLTMSK_CTRL,);
144  */
149  /* The end of block of container and contained registers */
150 
151  /* ARMv8-M specific registers */
160 
161  /* A block of container and contained registers follows:
162  * THE ORDER IS IMPORTANT to the end of the block ! */
168  /* The end of block of container and contained registers */
169 
170  /* A block of container and contained registers follows:
171  * THE ORDER IS IMPORTANT to the end of the block ! */
177  /* The end of block of container and contained registers */
178 
179  /* 64bit Floating-point registers */
196 
197  /* Floating-point status register */
199 
200  /* Vector Predication Status and Control Register */
202 
203  /* for convenience add registers' block delimiters */
211 };
212 
213 enum {
214  FP_NONE = 0,
220 };
221 
222 #define ARMV7M_NUM_CORE_REGS (ARMV7M_CORE_LAST_REG - ARMV7M_CORE_FIRST_REG + 1)
223 
224 #define ARMV7M_COMMON_MAGIC 0x2A452A45U
225 
227  unsigned int common_magic;
228 
229  struct arm arm;
230 
232 
233  /* AP this processor is connected to in the DAP */
235 
237  uint32_t demcr;
238 
239  /* hla_target uses a high level adapter that does not support all functions */
241 
243 
244  /* Direct processor core register read and writes */
245  int (*load_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t *value);
246  int (*store_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t value);
247 
249  int (*post_debug_entry)(struct target *target);
250 
252 };
253 
254 static inline bool is_armv7m(const struct armv7m_common *armv7m)
255 {
256  return armv7m->common_magic == ARMV7M_COMMON_MAGIC;
257 }
258 
265 static inline struct armv7m_common *
267 {
268  return container_of(target->arch_info, struct armv7m_common, arm);
269 }
270 
277 static inline struct armv7m_common *
279 {
280  if (!target)
281  return NULL;
282 
283  if (!target->arch_info)
284  return NULL;
285 
286  /* Check the parent type first to prevent peeking memory too far
287  * from arch_info pointer */
288  if (!is_arm(target_to_arm(target)))
289  return NULL;
290 
291  struct armv7m_common *armv7m = target_to_armv7m(target);
292  if (!is_armv7m(armv7m))
293  return NULL;
294 
295  return armv7m;
296 }
297 
299  unsigned int common_magic;
300 
301  enum arm_mode core_mode;
302 
303  uint32_t context[ARMV7M_LAST_REG]; /* ARMV7M_NUM_REGS */
304 };
305 
308 
309 enum armv7m_mode armv7m_number_to_mode(int number);
310 int armv7m_mode_to_number(enum armv7m_mode mode);
311 
312 int armv7m_arch_state(struct target *target);
314  struct reg **reg_list[], int *reg_list_size,
315  enum target_register_class reg_class);
316 
317 int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m);
318 
320  int num_mem_params, struct mem_param *mem_params,
321  int num_reg_params, struct reg_param *reg_params,
322  target_addr_t entry_point, target_addr_t exit_point,
323  unsigned int timeout_ms, void *arch_info);
324 
326  int num_mem_params, struct mem_param *mem_params,
327  int num_reg_params, struct reg_param *reg_params,
328  target_addr_t entry_point, target_addr_t exit_point,
329  void *arch_info);
330 
332  int num_mem_params, struct mem_param *mem_params,
333  int num_reg_params, struct reg_param *reg_params,
334  target_addr_t exit_point, unsigned int timeout_ms,
335  void *arch_info);
336 
338 
340 
341 uint32_t armv7m_map_id_to_regsel(unsigned int arm_reg_id);
342 
343 bool armv7m_map_reg_packing(unsigned int arm_reg_id,
344  unsigned int *reg32_id, uint32_t *offset);
345 
347  target_addr_t address, uint32_t count, uint32_t *checksum);
349  struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
350 
351 int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found);
352 
353 extern const struct command_registration armv7m_command_handlers[];
354 
355 #endif /* OPENOCD_TARGET_ARMV7M_H */
Holds the interface to ARM cores.
static bool is_arm(struct arm *arm)
Definition: arm.h:267
arm_mode
Represent state of an ARM core.
Definition: arm.h:82
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
enum arm_mode mode
Definition: armv4_5.c:281
int armv7m_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Returns generic ARM userspace registers to GDB.
Definition: armv7m.c:487
int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found)
Definition: armv7m.c:1099
void armv7m_free_reg_cache(struct target *target)
Definition: armv7m.c:859
static struct armv7m_common * target_to_armv7m_safe(struct target *target)
Definition: armv7m.h:278
@ ARMV7M_PRIMASK
Definition: armv7m.h:145
@ ARMV8M_PRIMASK_S
Definition: armv7m.h:164
@ ARMV7M_R1
Definition: armv7m.h:109
@ ARMV7M_CORE_LAST_REG
Definition: armv7m.h:206
@ ARMV8M_CONTROL_S
Definition: armv7m.h:167
@ ARMV7M_FAULTMASK
Definition: armv7m.h:147
@ ARMV7M_D14
Definition: armv7m.h:194
@ ARMV8M_PRIMASK_NS
Definition: armv7m.h:173
@ ARMV8M_BASEPRI_NS
Definition: armv7m.h:174
@ ARMV8M_MSP_NS
Definition: armv7m.h:152
@ ARMV7M_D8
Definition: armv7m.h:188
@ ARMV7M_FPU_LAST_REG
Definition: armv7m.h:208
@ ARMV8M_MSPLIM_S
Definition: armv7m.h:156
@ ARMV7M_MSP
Definition: armv7m.h:129
@ ARMV8M_PSP_NS
Definition: armv7m.h:153
@ ARMV7M_CORE_FIRST_REG
Definition: armv7m.h:205
@ ARMV8M_CONTROL_NS
Definition: armv7m.h:176
@ ARMV7M_R6
Definition: armv7m.h:115
@ ARMV7M_R2
Definition: armv7m.h:110
@ ARMV7M_D3
Definition: armv7m.h:183
@ ARMV7M_D1
Definition: armv7m.h:181
@ ARMV7M_D4
Definition: armv7m.h:184
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_NS
Definition: armv7m.h:172
@ ARMV7M_BASEPRI
Definition: armv7m.h:146
@ ARMV7M_D2
Definition: armv7m.h:182
@ ARMV7M_R3
Definition: armv7m.h:111
@ ARMV8M_MSPLIM_NS
Definition: armv7m.h:158
@ ARMV7M_D11
Definition: armv7m.h:191
@ ARMV7M_CONTROL
Definition: armv7m.h:148
@ ARMV7M_D9
Definition: armv7m.h:189
@ ARMV7M_R14
Definition: armv7m.h:125
@ ARMV7M_R9
Definition: armv7m.h:119
@ ARMV7M_D7
Definition: armv7m.h:187
@ ARMV7M_R12
Definition: armv7m.h:123
@ ARMV7M_R0
Definition: armv7m.h:108
@ ARMV8M_PSP_S
Definition: armv7m.h:155
@ ARMV7M_PSP
Definition: armv7m.h:130
@ ARMV8M_MSP_S
Definition: armv7m.h:154
@ ARMV8M_LAST_REG
Definition: armv7m.h:210
@ ARMV7M_FPU_FIRST_REG
Definition: armv7m.h:207
@ ARMV7M_D13
Definition: armv7m.h:193
@ ARMV8M_BASEPRI_S
Definition: armv7m.h:165
@ ARMV7M_R13
Definition: armv7m.h:124
@ ARMV8M_FAULTMASK_S
Definition: armv7m.h:166
@ ARMV7M_PC
Definition: armv7m.h:126
@ ARMV7M_R7
Definition: armv7m.h:116
@ ARMV7M_R4
Definition: armv7m.h:113
@ ARMV7M_XPSR
Definition: armv7m.h:128
@ ARMV7M_D0
Definition: armv7m.h:180
@ ARMV7M_R8
Definition: armv7m.h:118
@ ARMV7M_R11
Definition: armv7m.h:121
@ ARMV8M_PSPLIM_NS
Definition: armv7m.h:159
@ ARMV8M_FAULTMASK_NS
Definition: armv7m.h:175
@ ARMV8M_FIRST_REG
Definition: armv7m.h:209
@ ARMV7M_D12
Definition: armv7m.h:192
@ ARMV7M_D10
Definition: armv7m.h:190
@ ARMV7M_R10
Definition: armv7m.h:120
@ ARMV7M_D15
Definition: armv7m.h:195
@ ARMV7M_LAST_REG
Definition: armv7m.h:204
@ ARMV7M_FPSCR
Definition: armv7m.h:198
@ ARMV7M_D5
Definition: armv7m.h:185
@ ARMV7M_PMSK_BPRI_FLTMSK_CTRL
Definition: armv7m.h:137
@ ARMV8M_VPR
Definition: armv7m.h:201
@ ARMV7M_R5
Definition: armv7m.h:114
@ ARMV7M_D6
Definition: armv7m.h:186
@ ARMV8M_PSPLIM_S
Definition: armv7m.h:157
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_S
Definition: armv7m.h:163
int armv7m_mode_to_number(enum armv7m_mode mode)
uint32_t armv7m_map_id_to_regsel(unsigned int arm_reg_id)
Definition: armv7m.c:271
@ ARMV7M_REGSEL_S1
Definition: armv7m.h:70
@ ARMV7M_REGSEL_S24
Definition: armv7m.h:93
@ ARMV7M_REGSEL_S11
Definition: armv7m.h:80
@ ARMV7M_REGSEL_R8
Definition: armv7m.h:39
@ ARMV7M_REGSEL_S15
Definition: armv7m.h:84
@ ARMV7M_REGSEL_S12
Definition: armv7m.h:81
@ ARMV7M_REGSEL_R9
Definition: armv7m.h:40
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_S
Definition: armv7m.h:63
@ ARMV7M_REGSEL_S0
Definition: armv7m.h:69
@ ARMV7M_REGSEL_FPSCR
Definition: armv7m.h:66
@ ARMV7M_REGSEL_PC
Definition: armv7m.h:47
@ ARMV7M_REGSEL_S27
Definition: armv7m.h:96
@ ARMV7M_REGSEL_R6
Definition: armv7m.h:36
@ ARMV7M_REGSEL_S21
Definition: armv7m.h:90
@ ARMV7M_REGSEL_R4
Definition: armv7m.h:34
@ ARMV7M_REGSEL_R1
Definition: armv7m.h:30
@ ARMV7M_REGSEL_S13
Definition: armv7m.h:82
@ ARMV7M_REGSEL_S28
Definition: armv7m.h:97
@ ARMV7M_REGSEL_S5
Definition: armv7m.h:74
@ ARMV7M_REGSEL_R2
Definition: armv7m.h:31
@ ARMV7M_REGSEL_MSP
Definition: armv7m.h:50
@ ARMV7M_REGSEL_R13
Definition: armv7m.h:45
@ ARMV7M_REGSEL_R5
Definition: armv7m.h:35
@ ARMV7M_REGSEL_R11
Definition: armv7m.h:42
@ ARMV7M_REGSEL_S22
Definition: armv7m.h:91
@ ARMV7M_REGSEL_R14
Definition: armv7m.h:46
@ ARMV7M_REGSEL_S16
Definition: armv7m.h:85
@ ARMV7M_REGSEL_S7
Definition: armv7m.h:76
@ ARMV7M_REGSEL_S30
Definition: armv7m.h:99
@ ARMV7M_REGSEL_S29
Definition: armv7m.h:98
@ ARMV7M_REGSEL_S3
Definition: armv7m.h:72
@ ARMV7M_REGSEL_S19
Definition: armv7m.h:88
@ ARMV7M_REGSEL_R10
Definition: armv7m.h:41
@ ARMV8M_REGSEL_MSP_S
Definition: armv7m.h:55
@ ARMV7M_REGSEL_S20
Definition: armv7m.h:89
@ ARMV7M_REGSEL_S6
Definition: armv7m.h:75
@ ARMV8M_REGSEL_MSPLIM_S
Definition: armv7m.h:57
@ ARMV7M_REGSEL_R0
Definition: armv7m.h:29
@ ARMV7M_REGSEL_S23
Definition: armv7m.h:92
@ ARMV7M_REGSEL_S14
Definition: armv7m.h:83
@ ARMV7M_REGSEL_R7
Definition: armv7m.h:37
@ ARMV7M_REGSEL_S4
Definition: armv7m.h:73
@ ARMV8M_REGSEL_PSP_NS
Definition: armv7m.h:54
@ ARMV8M_REGSEL_MSP_NS
Definition: armv7m.h:53
@ ARMV8M_REGSEL_PSP_S
Definition: armv7m.h:56
@ ARMV7M_REGSEL_S31
Definition: armv7m.h:100
@ ARMV8M_REGSEL_PSPLIM_NS
Definition: armv7m.h:60
@ ARMV7M_REGSEL_S8
Definition: armv7m.h:77
@ ARMV8M_REGSEL_PSPLIM_S
Definition: armv7m.h:58
@ ARMV7M_REGSEL_PSP
Definition: armv7m.h:51
@ ARMV7M_REGSEL_R3
Definition: armv7m.h:32
@ ARMV7M_REGSEL_S2
Definition: armv7m.h:71
@ ARMV7M_REGSEL_S10
Definition: armv7m.h:79
@ ARMV7M_REGSEL_S9
Definition: armv7m.h:78
@ ARMV7M_REGSEL_R12
Definition: armv7m.h:44
@ ARMV7M_REGSEL_PMSK_BPRI_FLTMSK_CTRL
Definition: armv7m.h:62
@ ARMV7M_REGSEL_S18
Definition: armv7m.h:87
@ ARMV7M_REGSEL_S25
Definition: armv7m.h:94
@ ARMV7M_REGSEL_XPSR
Definition: armv7m.h:49
@ ARMV8M_REGSEL_VPR
Definition: armv7m.h:65
@ ARMV8M_REGSEL_MSPLIM_NS
Definition: armv7m.h:59
@ ARMV7M_REGSEL_S17
Definition: armv7m.h:86
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_NS
Definition: armv7m.h:64
@ ARMV7M_REGSEL_S26
Definition: armv7m.h:95
const int armv7m_msp_reg_map[]
Definition: armv7m.c:60
struct reg_cache * armv7m_build_reg_cache(struct target *target)
Builds cache of architecturally defined registers.
Definition: armv7m.c:792
enum armv7m_mode armv7m_number_to_mode(int number)
int armv7m_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, unsigned int timeout_ms, void *arch_info)
Runs a Thumb algorithm in the target.
Definition: armv7m.c:511
int armv7m_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum)
Generates a CRC32 checksum of a memory region.
Definition: armv7m.c:915
static struct armv7m_common * target_to_armv7m(struct target *target)
Definition: armv7m.h:266
int armv7m_wait_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 exit_point, unsigned int timeout_ms, void *arch_info)
Waits for an algorithm in the target.
Definition: armv7m.c:651
bool armv7m_map_reg_packing(unsigned int arm_reg_id, unsigned int *reg32_id, uint32_t *offset)
Definition: armv7m.c:312
@ FPV4_SP
Definition: armv7m.h:215
@ FPV5_MVE_F
Definition: armv7m.h:219
@ FPV5_DP
Definition: armv7m.h:217
@ FPV5_SP
Definition: armv7m.h:216
@ FPV5_MVE_I
Definition: armv7m.h:218
@ FP_NONE
Definition: armv7m.h:214
int armv7m_blank_check_memory(struct target *target, struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value)
Checks an array of memory regions whether they are erased.
Definition: armv7m.c:966
int armv7m_arch_state(struct target *target)
Logs summary of ARMv7-M state for a halted target.
Definition: armv7m.c:758
int armv7m_restore_context(struct target *target)
Restores target context using the cache of core registers set up by armv7m_build_reg_cache(),...
Definition: armv7m.c:193
const char * armv7m_exception_string(int number)
Maps ISR number (from xPSR) to name.
Definition: armv7m.c:229
#define ARMV7M_COMMON_MAGIC
Definition: armv7m.h:224
int armv7m_start_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, void *arch_info)
Starts a Thumb algorithm in the target.
Definition: armv7m.c:536
int armv7m_invalidate_core_regs(struct target *target)
static bool is_armv7m(const struct armv7m_common *armv7m)
Definition: armv7m.h:254
const struct command_registration armv7m_command_handlers[]
Definition: armv7m.c:1133
int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m)
Sets up target as a generic ARMv7-M core.
Definition: armv7m.c:893
const int armv7m_psp_reg_map[]
Definition: armv7m.c:51
Holds the interface to ITM and DWT configuration functions.
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
enum esirisc_reg_num number
Definition: esirisc.c:87
struct target * target
Definition: rtt/rtt.c:26
This represents an ARM Debug Interface (v5) Access Port (AP).
Definition: arm_adi_v5.h:250
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
unsigned int common_magic
Definition: armv7m.h:299
enum arm_mode core_mode
Definition: armv7m.h:301
uint32_t context[ARMV7M_LAST_REG]
Definition: armv7m.h:303
struct armv7m_trace_config trace_config
Definition: armv7m.h:242
bool is_hla_target
Definition: armv7m.h:240
int exception_number
Definition: armv7m.h:231
int fp_feature
Definition: armv7m.h:236
void(* pre_restore_context)(struct target *target)
Definition: armv7m.h:251
unsigned int common_magic
Definition: armv7m.h:227
int(* store_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t value)
Definition: armv7m.h:246
int(* load_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t *value)
Definition: armv7m.h:245
uint32_t demcr
Definition: armv7m.h:237
struct adiv5_ap * debug_ap
Definition: armv7m.h:234
int(* examine_debug_reason)(struct target *target)
Definition: armv7m.h:248
int(* post_debug_entry)(struct target *target)
Definition: armv7m.h:249
struct reg * reg_list
Definition: register.h:147
Definition: register.h:111
Definition: target.h:116
void * arch_info
Definition: target.h:164
target_register_class
Definition: target.h:110
uint64_t target_addr_t
Definition: types.h:335
#define container_of(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition: types.h:68
#define NULL
Definition: usb.h:16
uint8_t offset[4]
Definition: vdebug.c:9
uint8_t count[4]
Definition: vdebug.c:22