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_cache.h"
19 #include "armv7m_trace.h"
20 
21 struct adiv5_ap;
22 
23 extern const int armv7m_psp_reg_map[];
24 extern const int armv7m_msp_reg_map[];
25 
26 const char *armv7m_exception_string(int number);
27 
28 /* Cortex-M DCRSR.REGSEL selectors */
29 enum {
34 
39 
44 
49 
53 
64 
70 
71  /* 32bit Floating-point registers */
104 };
105 
106 /* offsets into armv7m core register cache */
107 enum {
108  /* for convenience, the first set of indices match
109  * the Cortex-M DCRSR.REGSEL selectors
110  */
115 
120 
125 
130 
134 
135  /* following indices are arbitrary, do not match DCRSR.REGSEL selectors */
136 
137  /* A block of container and contained registers follows:
138  * THE ORDER IS IMPORTANT to the end of the block ! */
139  /* working register for packing/unpacking special regs, hidden from gdb */
141 
142  /* WARNING: If you use armv7m_write_core_reg() on one of 4 following
143  * special registers, the new data go to ARMV7M_PMSK_BPRI_FLTMSK_CTRL
144  * cache only and are not flushed to CPU HW register.
145  * To trigger write to CPU HW register, add
146  * armv7m_write_core_reg(,,ARMV7M_PMSK_BPRI_FLTMSK_CTRL,);
147  */
152  /* The end of block of container and contained registers */
153 
154  /* ARMv8-M specific registers */
165 
166  /* A block of container and contained registers follows:
167  * THE ORDER IS IMPORTANT to the end of the block ! */
173  /* The end of block of container and contained registers */
174 
175  /* A block of container and contained registers follows:
176  * THE ORDER IS IMPORTANT to the end of the block ! */
182  /* The end of block of container and contained registers */
183 
184  /* 64bit Floating-point registers */
201 
202  /* Floating-point status register */
204 
205  /* Vector Predication Status and Control Register */
207 
208  /* for convenience add registers' block delimiters */
216 };
217 
218 enum {
219  FP_NONE = 0,
225 };
226 
227 #define ARMV7M_NUM_CORE_REGS (ARMV7M_CORE_LAST_REG - ARMV7M_CORE_FIRST_REG + 1)
228 
229 #define ARMV7M_COMMON_MAGIC 0x2A452A45U
230 
232  unsigned int common_magic;
233 
234  struct arm arm;
235 
237 
238  /* AP this processor is connected to in the DAP */
240 
242  uint32_t demcr;
243 
244  /* hla_target uses a high level adapter that does not support all functions */
246 
248 
250 
251  /* Direct processor core register read and writes */
252  int (*load_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t *value);
253  int (*store_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t value);
254 
256  int (*post_debug_entry)(struct target *target);
257 
259 };
260 
261 static inline bool is_armv7m(const struct armv7m_common *armv7m)
262 {
263  return armv7m->common_magic == ARMV7M_COMMON_MAGIC;
264 }
265 
272 static inline struct armv7m_common *
274 {
275  return container_of(target->arch_info, struct armv7m_common, arm);
276 }
277 
284 static inline struct armv7m_common *
286 {
287  if (!target)
288  return NULL;
289 
290  if (!target->arch_info)
291  return NULL;
292 
293  /* Check the parent type first to prevent peeking memory too far
294  * from arch_info pointer */
295  if (!is_arm(target_to_arm(target)))
296  return NULL;
297 
298  struct armv7m_common *armv7m = target_to_armv7m(target);
299  if (!is_armv7m(armv7m))
300  return NULL;
301 
302  return armv7m;
303 }
304 
306  unsigned int common_magic;
307 
308  enum arm_mode core_mode;
309 
310  uint32_t context[ARMV7M_LAST_REG]; /* ARMV7M_NUM_REGS */
311 };
312 
315 
316 enum armv7m_mode armv7m_number_to_mode(int number);
317 int armv7m_mode_to_number(enum armv7m_mode mode);
318 
319 int armv7m_arch_state(struct target *target);
321  struct reg **reg_list[], int *reg_list_size,
322  enum target_register_class reg_class);
323 
324 int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m);
325 
327  int num_mem_params, struct mem_param *mem_params,
328  int num_reg_params, struct reg_param *reg_params,
329  target_addr_t entry_point, target_addr_t exit_point,
330  unsigned int timeout_ms, void *arch_info);
331 
333  int num_mem_params, struct mem_param *mem_params,
334  int num_reg_params, struct reg_param *reg_params,
335  target_addr_t entry_point, target_addr_t exit_point,
336  void *arch_info);
337 
339  int num_mem_params, struct mem_param *mem_params,
340  int num_reg_params, struct reg_param *reg_params,
341  target_addr_t exit_point, unsigned int timeout_ms,
342  void *arch_info);
343 
345 
347 
348 uint32_t armv7m_map_id_to_regsel(unsigned int arm_reg_id);
349 
350 bool armv7m_map_reg_packing(unsigned int arm_reg_id,
351  unsigned int *reg32_id, uint32_t *offset);
352 
354  target_addr_t address, uint32_t count, uint32_t *checksum);
356  struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
357 
358 int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found);
359 
360 extern const struct command_registration armv7m_command_handlers[];
361 
362 #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:496
int armv7m_maybe_skip_bkpt_inst(struct target *target, bool *inst_found)
Definition: armv7m.c:1108
void armv7m_free_reg_cache(struct target *target)
Definition: armv7m.c:868
@ ARMV7M_REGSEL_S1
Definition: armv7m.h:73
@ ARMV7M_REGSEL_S24
Definition: armv7m.h:96
@ ARMV7M_REGSEL_S11
Definition: armv7m.h:83
@ ARMV7M_REGSEL_R8
Definition: armv7m.h:40
@ ARMV7M_REGSEL_S15
Definition: armv7m.h:87
@ ARMV7M_REGSEL_S12
Definition: armv7m.h:84
@ ARMV7M_REGSEL_R9
Definition: armv7m.h:41
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_S
Definition: armv7m.h:66
@ ARMV7M_REGSEL_S0
Definition: armv7m.h:72
@ ARMV7M_REGSEL_FPSCR
Definition: armv7m.h:69
@ ARMV7M_REGSEL_PC
Definition: armv7m.h:48
@ ARMV7M_REGSEL_S27
Definition: armv7m.h:99
@ ARMV7M_REGSEL_R6
Definition: armv7m.h:37
@ ARMV7M_REGSEL_S21
Definition: armv7m.h:93
@ ARMV8M_REGSEL_PSPLIM
Definition: armv7m.h:63
@ ARMV7M_REGSEL_R4
Definition: armv7m.h:35
@ ARMV7M_REGSEL_R1
Definition: armv7m.h:31
@ ARMV7M_REGSEL_S13
Definition: armv7m.h:85
@ ARMV7M_REGSEL_S28
Definition: armv7m.h:100
@ ARMV7M_REGSEL_S5
Definition: armv7m.h:77
@ ARMV7M_REGSEL_R2
Definition: armv7m.h:32
@ ARMV7M_REGSEL_MSP
Definition: armv7m.h:51
@ ARMV7M_REGSEL_R13
Definition: armv7m.h:46
@ ARMV7M_REGSEL_R5
Definition: armv7m.h:36
@ ARMV7M_REGSEL_R11
Definition: armv7m.h:43
@ ARMV7M_REGSEL_S22
Definition: armv7m.h:94
@ ARMV7M_REGSEL_R14
Definition: armv7m.h:47
@ ARMV7M_REGSEL_S16
Definition: armv7m.h:88
@ ARMV7M_REGSEL_S7
Definition: armv7m.h:79
@ ARMV7M_REGSEL_S30
Definition: armv7m.h:102
@ ARMV7M_REGSEL_S29
Definition: armv7m.h:101
@ ARMV7M_REGSEL_S3
Definition: armv7m.h:75
@ ARMV7M_REGSEL_S19
Definition: armv7m.h:91
@ ARMV7M_REGSEL_R10
Definition: armv7m.h:42
@ ARMV8M_REGSEL_MSP_S
Definition: armv7m.h:56
@ ARMV7M_REGSEL_S20
Definition: armv7m.h:92
@ ARMV7M_REGSEL_S6
Definition: armv7m.h:78
@ ARMV8M_REGSEL_MSPLIM_S
Definition: armv7m.h:58
@ ARMV7M_REGSEL_R0
Definition: armv7m.h:30
@ ARMV7M_REGSEL_S23
Definition: armv7m.h:95
@ ARMV7M_REGSEL_S14
Definition: armv7m.h:86
@ ARMV7M_REGSEL_R7
Definition: armv7m.h:38
@ ARMV7M_REGSEL_S4
Definition: armv7m.h:76
@ ARMV8M_REGSEL_PSP_NS
Definition: armv7m.h:55
@ ARMV8M_REGSEL_MSP_NS
Definition: armv7m.h:54
@ ARMV8M_REGSEL_PSP_S
Definition: armv7m.h:57
@ ARMV7M_REGSEL_S31
Definition: armv7m.h:103
@ ARMV8M_REGSEL_PSPLIM_NS
Definition: armv7m.h:61
@ ARMV7M_REGSEL_S8
Definition: armv7m.h:80
@ ARMV8M_REGSEL_PSPLIM_S
Definition: armv7m.h:59
@ ARMV7M_REGSEL_PSP
Definition: armv7m.h:52
@ ARMV7M_REGSEL_R3
Definition: armv7m.h:33
@ ARMV7M_REGSEL_S2
Definition: armv7m.h:74
@ ARMV8M_REGSEL_MSPLIM
Definition: armv7m.h:62
@ ARMV7M_REGSEL_S10
Definition: armv7m.h:82
@ ARMV7M_REGSEL_S9
Definition: armv7m.h:81
@ ARMV7M_REGSEL_R12
Definition: armv7m.h:45
@ ARMV7M_REGSEL_PMSK_BPRI_FLTMSK_CTRL
Definition: armv7m.h:65
@ ARMV7M_REGSEL_S18
Definition: armv7m.h:90
@ ARMV7M_REGSEL_S25
Definition: armv7m.h:97
@ ARMV7M_REGSEL_XPSR
Definition: armv7m.h:50
@ ARMV8M_REGSEL_VPR
Definition: armv7m.h:68
@ ARMV8M_REGSEL_MSPLIM_NS
Definition: armv7m.h:60
@ ARMV7M_REGSEL_S17
Definition: armv7m.h:89
@ ARMV8M_REGSEL_PMSK_BPRI_FLTMSK_CTRL_NS
Definition: armv7m.h:67
@ ARMV7M_REGSEL_S26
Definition: armv7m.h:98
static struct armv7m_common * target_to_armv7m_safe(struct target *target)
Definition: armv7m.h:285
int armv7m_mode_to_number(enum armv7m_mode mode)
@ FPV4_SP
Definition: armv7m.h:220
@ FPV5_MVE_F
Definition: armv7m.h:224
@ FPV5_DP
Definition: armv7m.h:222
@ FPV5_SP
Definition: armv7m.h:221
@ FPV5_MVE_I
Definition: armv7m.h:223
@ FP_NONE
Definition: armv7m.h:219
uint32_t armv7m_map_id_to_regsel(unsigned int arm_reg_id)
Definition: armv7m.c:274
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:801
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:520
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:924
static struct armv7m_common * target_to_armv7m(struct target *target)
Definition: armv7m.h:273
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:660
bool armv7m_map_reg_packing(unsigned int arm_reg_id, unsigned int *reg32_id, uint32_t *offset)
Definition: armv7m.c:321
@ ARMV7M_PRIMASK
Definition: armv7m.h:148
@ ARMV8M_PRIMASK_S
Definition: armv7m.h:169
@ ARMV7M_R1
Definition: armv7m.h:112
@ ARMV7M_CORE_LAST_REG
Definition: armv7m.h:211
@ ARMV8M_CONTROL_S
Definition: armv7m.h:172
@ ARMV7M_FAULTMASK
Definition: armv7m.h:150
@ ARMV7M_D14
Definition: armv7m.h:199
@ ARMV8M_PRIMASK_NS
Definition: armv7m.h:178
@ ARMV8M_BASEPRI_NS
Definition: armv7m.h:179
@ ARMV8M_MSP_NS
Definition: armv7m.h:157
@ ARMV7M_D8
Definition: armv7m.h:193
@ ARMV7M_FPU_LAST_REG
Definition: armv7m.h:213
@ ARMV8M_MSPLIM_S
Definition: armv7m.h:161
@ ARMV7M_MSP
Definition: armv7m.h:132
@ ARMV8M_PSP_NS
Definition: armv7m.h:158
@ ARMV7M_CORE_FIRST_REG
Definition: armv7m.h:210
@ ARMV8M_CONTROL_NS
Definition: armv7m.h:181
@ ARMV7M_R6
Definition: armv7m.h:118
@ ARMV7M_R2
Definition: armv7m.h:113
@ ARMV7M_D3
Definition: armv7m.h:188
@ ARMV7M_D1
Definition: armv7m.h:186
@ ARMV7M_D4
Definition: armv7m.h:189
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_NS
Definition: armv7m.h:177
@ ARMV7M_BASEPRI
Definition: armv7m.h:149
@ ARMV7M_D2
Definition: armv7m.h:187
@ ARMV7M_R3
Definition: armv7m.h:114
@ ARMV8M_MSPLIM_NS
Definition: armv7m.h:163
@ ARMV7M_D11
Definition: armv7m.h:196
@ ARMV7M_CONTROL
Definition: armv7m.h:151
@ ARMV8M_TZ_FIRST_REG
Definition: armv7m.h:214
@ ARMV7M_D9
Definition: armv7m.h:194
@ ARMV7M_R14
Definition: armv7m.h:128
@ ARMV7M_R9
Definition: armv7m.h:122
@ ARMV7M_D7
Definition: armv7m.h:192
@ ARMV7M_R12
Definition: armv7m.h:126
@ ARMV7M_R0
Definition: armv7m.h:111
@ ARMV8M_PSP_S
Definition: armv7m.h:160
@ ARMV7M_PSP
Definition: armv7m.h:133
@ ARMV8M_MSP_S
Definition: armv7m.h:159
@ ARMV8M_TZ_LAST_REG
Definition: armv7m.h:215
@ ARMV7M_FPU_FIRST_REG
Definition: armv7m.h:212
@ ARMV7M_D13
Definition: armv7m.h:198
@ ARMV8M_BASEPRI_S
Definition: armv7m.h:170
@ ARMV7M_R13
Definition: armv7m.h:127
@ ARMV8M_FAULTMASK_S
Definition: armv7m.h:171
@ ARMV7M_PC
Definition: armv7m.h:129
@ ARMV7M_R7
Definition: armv7m.h:119
@ ARMV7M_R4
Definition: armv7m.h:116
@ ARMV8M_PSPLIM
Definition: armv7m.h:156
@ ARMV7M_XPSR
Definition: armv7m.h:131
@ ARMV8M_MSPLIM
Definition: armv7m.h:155
@ ARMV7M_D0
Definition: armv7m.h:185
@ ARMV7M_R8
Definition: armv7m.h:121
@ ARMV7M_R11
Definition: armv7m.h:124
@ ARMV8M_PSPLIM_NS
Definition: armv7m.h:164
@ ARMV8M_FAULTMASK_NS
Definition: armv7m.h:180
@ ARMV7M_D12
Definition: armv7m.h:197
@ ARMV7M_D10
Definition: armv7m.h:195
@ ARMV7M_R10
Definition: armv7m.h:123
@ ARMV7M_D15
Definition: armv7m.h:200
@ ARMV7M_LAST_REG
Definition: armv7m.h:209
@ ARMV7M_FPSCR
Definition: armv7m.h:203
@ ARMV7M_D5
Definition: armv7m.h:190
@ ARMV7M_PMSK_BPRI_FLTMSK_CTRL
Definition: armv7m.h:140
@ ARMV8M_VPR
Definition: armv7m.h:206
@ ARMV7M_R5
Definition: armv7m.h:117
@ ARMV7M_D6
Definition: armv7m.h:191
@ ARMV8M_PSPLIM_S
Definition: armv7m.h:162
@ ARMV8M_PMSK_BPRI_FLTMSK_CTRL_S
Definition: armv7m.h:168
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:975
int armv7m_arch_state(struct target *target)
Logs summary of ARMv7-M state for a halted target.
Definition: armv7m.c:767
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:196
const char * armv7m_exception_string(int number)
Maps ISR number (from xPSR) to name.
Definition: armv7m.c:232
#define ARMV7M_COMMON_MAGIC
Definition: armv7m.h:229
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:545
int armv7m_invalidate_core_regs(struct target *target)
static bool is_armv7m(const struct armv7m_common *armv7m)
Definition: armv7m.h:261
const struct command_registration armv7m_command_handlers[]
Definition: armv7m.c:1142
int armv7m_init_arch_info(struct target *target, struct armv7m_common *armv7m)
Sets up target as a generic ARMv7-M core.
Definition: armv7m.c:902
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:306
enum arm_mode core_mode
Definition: armv7m.h:308
uint32_t context[ARMV7M_LAST_REG]
Definition: armv7m.h:310
struct armv7m_trace_config trace_config
Definition: armv7m.h:249
bool is_hla_target
Definition: armv7m.h:245
int exception_number
Definition: armv7m.h:236
int fp_feature
Definition: armv7m.h:241
void(* pre_restore_context)(struct target *target)
Definition: armv7m.h:258
unsigned int common_magic
Definition: armv7m.h:232
int(* store_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t value)
Definition: armv7m.h:253
int(* load_core_reg_u32)(struct target *target, uint32_t regsel, uint32_t *value)
Definition: armv7m.h:252
uint32_t demcr
Definition: armv7m.h:242
struct adiv5_ap * debug_ap
Definition: armv7m.h:239
int(* examine_debug_reason)(struct target *target)
Definition: armv7m.h:255
struct armv7m_cache_common armv7m_cache
Definition: armv7m.h:247
int(* post_debug_entry)(struct target *target)
Definition: armv7m.h:256
struct reg * reg_list
Definition: register.h:147
Definition: register.h:111
Definition: target.h:119
void * arch_info
Definition: target.h:167
target_register_class
Definition: target.h:113
uint64_t target_addr_t
Definition: types.h:279
#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