OpenOCD
arm.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) 2008 by Spencer Oliver
8  * spen@spen-soft.co.uk
9  *
10  * Copyright (C) 2009 by Øyvind Harboe
11  * oyvind.harboe@zylin.com
12  *
13  * Copyright (C) 2018 by Liviu Ionescu
14  * <ilg@livius.net>
15  */
16 
17 #ifndef OPENOCD_TARGET_ARM_H
18 #define OPENOCD_TARGET_ARM_H
19 
20 #include <helper/command.h>
21 #include "target.h"
22 
50 };
51 
53 enum arm_arch {
59 };
60 
74 enum arm_mode {
85 
89 
97 
98  ARM_MODE_ANY = -1
99 };
100 
101 /* VFPv3 internal register numbers mapping to d0:31 */
102 enum {
136 };
137 
138 const char *arm_mode_name(unsigned psr_mode);
139 bool is_arm_mode(unsigned psr_mode);
140 
142 enum arm_state {
148 };
149 
156 };
157 
158 #define ARM_COMMON_MAGIC 0x0A450A45U
159 
167 struct arm {
168  unsigned int common_magic;
169 
171 
173  struct reg *pc;
174 
176  struct reg *cpsr;
177 
179  struct reg *spsr;
180 
182  const int *map;
183 
186 
188  enum arm_mode core_mode;
189 
191  enum arm_state core_state;
192 
194  enum arm_arch arch;
195 
198 
199  int (*setup_semihosting)(struct target *target, int enable);
200 
202  struct target *target;
203 
205  struct arm_dpm *dpm;
206 
208  struct etm_context *etm;
209 
210  /* FIXME all these methods should take "struct arm *" not target */
211 
213  int (*full_context)(struct target *target);
214 
216  int (*read_core_reg)(struct target *target, struct reg *reg,
217  int num, enum arm_mode mode);
218  int (*write_core_reg)(struct target *target, struct reg *reg,
219  int num, enum arm_mode mode, uint8_t *value);
220 
222  int (*mrc)(struct target *target, int cpnum,
223  uint32_t op1, uint32_t op2,
224  uint32_t crn, uint32_t crm,
225  uint32_t *value);
226 
228  int (*mcr)(struct target *target, int cpnum,
229  uint32_t op1, uint32_t op2,
230  uint32_t crn, uint32_t crm,
231  uint32_t value);
232 
233  void *arch_info;
234 
239  struct adiv5_dap *dap;
240 };
241 
243 static inline struct arm *target_to_arm(struct target *target)
244 {
245  assert(target);
246  return target->arch_info;
247 }
248 
249 static inline bool is_arm(struct arm *arm)
250 {
251  assert(arm);
252  return arm->common_magic == ARM_COMMON_MAGIC;
253 }
254 
256  unsigned int common_magic;
257 
258  enum arm_mode core_mode;
259  enum arm_state core_state;
260 };
261 
262 struct arm_reg {
263  int num;
264  enum arm_mode mode;
265  struct target *target;
266  struct arm *arm;
267  uint8_t value[16];
268 };
269 
270 struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm);
271 void arm_free_reg_cache(struct arm *arm);
272 
274 
275 extern const struct command_registration arm_command_handlers[];
277 
278 int arm_arch_state(struct target *target);
279 const char *arm_get_gdb_arch(struct target *target);
281  struct reg **reg_list[], int *reg_list_size,
282  enum target_register_class reg_class);
283 const char *armv8_get_gdb_arch(struct target *target);
285  struct reg **reg_list[], int *reg_list_size,
286  enum target_register_class reg_class);
287 
288 int arm_init_arch_info(struct target *target, struct arm *arm);
289 
290 /* REVISIT rename this once it's usable by ARMv7-M */
292  int num_mem_params, struct mem_param *mem_params,
293  int num_reg_params, struct reg_param *reg_params,
294  target_addr_t entry_point, target_addr_t exit_point,
295  int timeout_ms, void *arch_info);
297  int num_mem_params, struct mem_param *mem_params,
298  int num_reg_params, struct reg_param *reg_params,
299  uint32_t entry_point, uint32_t exit_point,
300  int timeout_ms, void *arch_info,
301  int (*run_it)(struct target *target, uint32_t exit_point,
302  int timeout_ms, void *arch_info));
303 
304 int arm_checksum_memory(struct target *target,
305  target_addr_t address, uint32_t count, uint32_t *checksum);
307  struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
308 
309 void arm_set_cpsr(struct arm *arm, uint32_t cpsr);
310 struct reg *arm_reg_current(struct arm *arm, unsigned regnum);
311 struct reg *armv8_reg_current(struct arm *arm, unsigned regnum);
312 
313 #endif /* OPENOCD_TARGET_ARM_H */
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
const struct command_registration arm_all_profiles_command_handlers[]
Definition: armv4_5.c:1148
int arm_arch_state(struct target *target)
Definition: armv4_5.c:782
arm_vfp_version
ARM vector floating point enabled, if yes which version.
Definition: arm.h:151
@ ARM_VFP_V2
Definition: arm.h:154
@ ARM_VFP_V3
Definition: arm.h:155
@ ARM_VFP_V1
Definition: arm.h:153
@ ARM_VFP_DISABLED
Definition: arm.h:152
#define ARM_COMMON_MAGIC
Definition: arm.h:158
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
arm_arch
ARM Architecture specifying the version and the profile.
Definition: arm.h:53
@ ARM_ARCH_V6M
Definition: arm.h:56
@ ARM_ARCH_V8M
Definition: arm.h:58
@ ARM_ARCH_V4
Definition: arm.h:55
@ ARM_ARCH_UNKNOWN
Definition: arm.h:54
@ ARM_ARCH_V7M
Definition: arm.h:57
struct reg_cache * arm_build_reg_cache(struct target *target, struct arm *arm)
Definition: armv4_5.c:646
struct reg * armv8_reg_current(struct arm *arm, unsigned regnum)
Definition: armv8.c:1694
const char * armv8_get_gdb_arch(struct target *target)
Definition: armv8.c:1751
int armv8_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
Definition: armv8.c:1757
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
static bool is_arm(struct arm *arm)
Definition: arm.h:249
arm_mode
Represent state of an ARM core.
Definition: arm.h:74
@ ARM_MODE_IRQ
Definition: arm.h:77
@ ARM_MODE_HANDLER
Definition: arm.h:88
@ ARM_MODE_SYS
Definition: arm.h:84
@ ARM_MODE_HYP
Definition: arm.h:81
@ ARMV8_64_EL0T
Definition: arm.h:90
@ ARMV8_64_EL3H
Definition: arm.h:96
@ ARM_MODE_MON
Definition: arm.h:79
@ ARMV8_64_EL3T
Definition: arm.h:95
@ ARM_MODE_FIQ
Definition: arm.h:76
@ ARM_MODE_UND
Definition: arm.h:82
@ ARM_MODE_1176_MON
Definition: arm.h:83
@ ARM_MODE_ANY
Definition: arm.h:98
@ ARMV8_64_EL1H
Definition: arm.h:92
@ ARM_MODE_USR
Definition: arm.h:75
@ ARM_MODE_SVC
Definition: arm.h:78
@ ARM_MODE_USER_THREAD
Definition: arm.h:87
@ ARMV8_64_EL2H
Definition: arm.h:94
@ ARMV8_64_EL2T
Definition: arm.h:93
@ ARMV8_64_EL1T
Definition: arm.h:91
@ ARM_MODE_ABT
Definition: arm.h:80
@ ARM_MODE_THREAD
Definition: arm.h:86
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
arm_state
The PSR "T" and "J" bits define the mode of "classic ARM" cores.
Definition: arm.h:142
@ ARM_STATE_JAZELLE
Definition: arm.h:145
@ ARM_STATE_THUMB
Definition: arm.h:144
@ ARM_STATE_ARM
Definition: arm.h:143
@ ARM_STATE_AARCH64
Definition: arm.h:147
@ ARM_STATE_THUMB_EE
Definition: arm.h:146
bool is_arm_mode(unsigned psr_mode)
Return true iff the parameter denotes a valid ARM processor mode.
Definition: armv4_5.c:182
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1169
struct reg_cache * armv8_build_reg_cache(struct target *target)
Builds cache of architecturally defined registers.
Definition: armv8.c:1600
const char * arm_mode_name(unsigned psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
Definition: armv4_5.c:171
@ ARM_VFP_V3_D14
Definition: arm.h:117
@ ARM_VFP_V3_D24
Definition: arm.h:127
@ ARM_VFP_V3_D9
Definition: arm.h:112
@ ARM_VFP_V3_D1
Definition: arm.h:104
@ ARM_VFP_V3_D17
Definition: arm.h:120
@ ARM_VFP_V3_D19
Definition: arm.h:122
@ ARM_VFP_V3_D4
Definition: arm.h:107
@ ARM_VFP_V3_D15
Definition: arm.h:118
@ ARM_VFP_V3_D10
Definition: arm.h:113
@ ARM_VFP_V3_D3
Definition: arm.h:106
@ ARM_VFP_V3_D31
Definition: arm.h:134
@ ARM_VFP_V3_D16
Definition: arm.h:119
@ ARM_VFP_V3_D22
Definition: arm.h:125
@ ARM_VFP_V3_D5
Definition: arm.h:108
@ ARM_VFP_V3_D18
Definition: arm.h:121
@ ARM_VFP_V3_D26
Definition: arm.h:129
@ ARM_VFP_V3_D7
Definition: arm.h:110
@ ARM_VFP_V3_D23
Definition: arm.h:126
@ ARM_VFP_V3_D21
Definition: arm.h:124
@ ARM_VFP_V3_D28
Definition: arm.h:131
@ ARM_VFP_V3_D2
Definition: arm.h:105
@ ARM_VFP_V3_D27
Definition: arm.h:130
@ ARM_VFP_V3_D29
Definition: arm.h:132
@ ARM_VFP_V3_D11
Definition: arm.h:114
@ ARM_VFP_V3_FPSCR
Definition: arm.h:135
@ ARM_VFP_V3_D20
Definition: arm.h:123
@ ARM_VFP_V3_D13
Definition: arm.h:116
@ ARM_VFP_V3_D12
Definition: arm.h:115
@ ARM_VFP_V3_D6
Definition: arm.h:109
@ ARM_VFP_V3_D8
Definition: arm.h:111
@ ARM_VFP_V3_D0
Definition: arm.h:103
@ ARM_VFP_V3_D30
Definition: arm.h:133
@ ARM_VFP_V3_D25
Definition: arm.h:128
static struct arm * target_to_arm(struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:243
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1705
void arm_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv4_5.c:438
int armv4_5_run_algorithm_inner(struct target *target, int num_mem_params, struct mem_param *mem_params, int num_reg_params, struct reg_param *reg_params, uint32_t entry_point, uint32_t exit_point, int timeout_ms, void *arch_info, int(*run_it)(struct target *target, uint32_t exit_point, int timeout_ms, void *arch_info))
Definition: armv4_5.c:1311
struct reg * arm_reg_current(struct arm *arm, unsigned regnum)
Returns handle to the register currently mapped to a given number.
Definition: armv4_5.c:502
arm_core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:45
@ ARM_CORE_TYPE_SEC_EXT
Definition: arm.h:47
@ ARM_CORE_TYPE_VIRT_EXT
Definition: arm.h:48
@ ARM_CORE_TYPE_M_PROFILE
Definition: arm.h:49
@ ARM_CORE_TYPE_STD
Definition: arm.h:46
enum arm_mode mode
Definition: armv4_5.c:277
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
Definition: arm_adi_v5.h:320
unsigned int common_magic
Definition: arm.h:256
enum arm_mode core_mode
Definition: arm.h:258
enum arm_state core_state
Definition: arm.h:259
This wraps an implementation of DPM primitives.
Definition: arm_dpm.h:47
Definition: arm.h:262
int num
Definition: arm.h:263
struct arm * arm
Definition: arm.h:266
uint8_t value[16]
Definition: arm.h:267
enum arm_mode mode
Definition: arm.h:264
struct target * target
Definition: arm.h:265
Represents a generic ARM core, with standard application registers.
Definition: arm.h:167
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:213
enum arm_arch arch
ARM architecture version.
Definition: arm.h:194
void * arch_info
Definition: arm.h:233
struct etm_context * etm
Handle for the Embedded Trace Module, if one is present.
Definition: arm.h:208
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:185
int(* mrc)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t *value)
Read coprocessor register.
Definition: arm.h:222
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:188
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:176
struct adiv5_dap * dap
For targets conforming to ARM Debug Interface v5, this handle references the Debug Access Port (DAP) ...
Definition: arm.h:239
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:173
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:218
int(* setup_semihosting)(struct target *target, int enable)
Definition: arm.h:199
const int * map
Support for arm_reg_current()
Definition: arm.h:182
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:216
struct reg_cache * core_cache
Definition: arm.h:170
struct arm_dpm * dpm
Handle for the debug module, if one is present.
Definition: arm.h:205
int(* mcr)(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t crn, uint32_t crm, uint32_t value)
Write coprocessor register.
Definition: arm.h:228
struct reg * spsr
Handle to the SPSR; valid only in core modes with an SPSR.
Definition: arm.h:179
unsigned int common_magic
Definition: arm.h:168
int arm_vfp_version
Floating point or VFP version, 0 if disabled.
Definition: arm.h:197
struct target * target
Backpointer to the target.
Definition: arm.h:202
enum arm_state core_state
Record the current core state: ARM, Thumb, or otherwise.
Definition: arm.h:191
Definition: register.h:111
uint8_t * value
Definition: register.h:122
Definition: target.h:120
void * arch_info
Definition: target.h:169
target_register_class
Definition: target.h:114
uint64_t target_addr_t
Definition: types.h:335
uint8_t count[4]
Definition: vdebug.c:22