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