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 
67 };
68 
82 enum arm_mode {
93 
97 
105 
106  ARM_MODE_ANY = -1
107 };
108 
109 /* VFPv3 internal register numbers mapping to d0:31 */
110 enum {
144 };
145 
146 const char *arm_mode_name(unsigned int psr_mode);
147 bool is_arm_mode(unsigned int psr_mode);
148 
150 enum arm_state {
156 };
157 
164 };
165 
166 #define ARM_COMMON_MAGIC 0x0A450A45U
167 
175 struct arm {
176  unsigned int common_magic;
177 
179 
181  struct reg *pc;
182 
184  struct reg *cpsr;
185 
187  struct reg *spsr;
188 
190  const int *map;
191 
194 
196  enum arm_mode core_mode;
197 
199  enum arm_state core_state;
200 
202  enum arm_arch arch;
203 
206 
207  int (*setup_semihosting)(struct target *target, int enable);
208 
210  struct target *target;
211 
213  struct arm_dpm *dpm;
214 
216  struct etm_context *etm;
217 
218  /* FIXME all these methods should take "struct arm *" not target */
219 
221  int (*full_context)(struct target *target);
222 
224  int (*read_core_reg)(struct target *target, struct reg *reg,
225  int num, enum arm_mode mode);
226  int (*write_core_reg)(struct target *target, struct reg *reg,
227  int num, enum arm_mode mode, uint8_t *value);
228 
230  int (*mrc)(struct target *target, int cpnum,
231  uint32_t op1, uint32_t op2,
232  uint32_t crn, uint32_t crm,
233  uint32_t *value);
234 
236  int (*mrrc)(struct target *target, int cpnum,
237  uint32_t op, uint32_t crm,
238  uint64_t *value);
239 
241  int (*mcr)(struct target *target, int cpnum,
242  uint32_t op1, uint32_t op2,
243  uint32_t crn, uint32_t crm,
244  uint32_t value);
245 
247  int (*mcrr)(struct target *target, int cpnum,
248  uint32_t op, uint32_t crm,
249  uint64_t value);
250 
251  void *arch_info;
252 
257  struct adiv5_dap *dap;
258 };
259 
261 static inline struct arm *target_to_arm(const struct target *target)
262 {
263  assert(target);
264  return target->arch_info;
265 }
266 
267 static inline bool is_arm(struct arm *arm)
268 {
269  assert(arm);
270  return arm->common_magic == ARM_COMMON_MAGIC;
271 }
272 
274  unsigned int common_magic;
275 
276  enum arm_mode core_mode;
277  enum arm_state core_state;
278 };
279 
280 struct arm_reg {
281  int num;
282  enum arm_mode mode;
283  struct target *target;
284  struct arm *arm;
285  uint8_t value[16];
286 };
287 
288 struct reg_cache *arm_build_reg_cache(struct target *target, struct arm *arm);
289 void arm_free_reg_cache(struct arm *arm);
290 
292 
293 extern const struct command_registration arm_command_handlers[];
295 
296 int arm_arch_state(struct target *target);
297 const char *arm_get_gdb_arch(const struct target *target);
299  struct reg **reg_list[], int *reg_list_size,
300  enum target_register_class reg_class);
301 const char *armv8_get_gdb_arch(const struct target *target);
303  struct reg **reg_list[], int *reg_list_size,
304  enum target_register_class reg_class);
305 
306 int arm_init_arch_info(struct target *target, struct arm *arm);
307 
308 /* REVISIT rename this once it's usable by ARMv7-M */
310  int num_mem_params, struct mem_param *mem_params,
311  int num_reg_params, struct reg_param *reg_params,
312  target_addr_t entry_point, target_addr_t exit_point,
313  unsigned int timeout_ms, void *arch_info);
315  int num_mem_params, struct mem_param *mem_params,
316  int num_reg_params, struct reg_param *reg_params,
317  uint32_t entry_point, uint32_t exit_point,
318  unsigned int timeout_ms, void *arch_info,
319  int (*run_it)(struct target *target, uint32_t exit_point,
320  unsigned int timeout_ms, void *arch_info));
321 
322 int arm_checksum_memory(struct target *target,
323  target_addr_t address, uint32_t count, uint32_t *checksum);
325  struct target_memory_check_block *blocks, int num_blocks, uint8_t erased_value);
326 
327 void arm_set_cpsr(struct arm *arm, uint32_t cpsr);
328 struct reg *arm_reg_current(struct arm *arm, unsigned int regnum);
329 struct reg *armv8_reg_current(struct arm *arm, unsigned int regnum);
330 
331 #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:1673
const char * armv8_get_gdb_arch(const struct target *target)
Definition: armv8.c:1952
const struct command_registration arm_all_profiles_command_handlers[]
Definition: armv4_5.c:1226
struct reg * arm_reg_current(struct arm *arm, unsigned int regnum)
Returns handle to the register currently mapped to a given number.
Definition: armv4_5.c:502
arm_implementer
Known ARM implementer IDs.
Definition: arm.h:62
@ ARM_IMPLEMENTER_ARM
Definition: arm.h:63
@ ARM_IMPLEMENTER_ARM_CHINA
Definition: arm.h:65
@ ARM_IMPLEMENTER_INFINEON
Definition: arm.h:64
@ ARM_IMPLEMENTER_REALTEK
Definition: arm.h:66
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, unsigned int timeout_ms, void *arch_info, int(*run_it)(struct target *target, uint32_t exit_point, unsigned int timeout_ms, void *arch_info))
Definition: armv4_5.c:1389
int arm_arch_state(struct target *target)
Definition: armv4_5.c:782
bool is_arm_mode(unsigned int psr_mode)
Return true iff the parameter denotes a valid ARM processor mode.
Definition: armv4_5.c:182
arm_vfp_version
ARM vector floating point enabled, if yes which version.
Definition: arm.h:159
@ ARM_VFP_V2
Definition: arm.h:162
@ ARM_VFP_V3
Definition: arm.h:163
@ ARM_VFP_V1
Definition: arm.h:161
@ ARM_VFP_DISABLED
Definition: arm.h:160
#define ARM_COMMON_MAGIC
Definition: arm.h:166
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:1600
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 int regnum)
Definition: armv8.c:1884
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:1958
const char * arm_get_gdb_arch(const struct target *target)
Definition: armv4_5.c:1267
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:1272
static bool is_arm(struct arm *arm)
Definition: arm.h:267
arm_mode
Represent state of an ARM core.
Definition: arm.h:82
@ ARM_MODE_IRQ
Definition: arm.h:85
@ ARM_MODE_HANDLER
Definition: arm.h:96
@ ARM_MODE_SYS
Definition: arm.h:92
@ ARM_MODE_HYP
Definition: arm.h:89
@ ARMV8_64_EL0T
Definition: arm.h:98
@ ARMV8_64_EL3H
Definition: arm.h:104
@ ARM_MODE_MON
Definition: arm.h:87
@ ARMV8_64_EL3T
Definition: arm.h:103
@ ARM_MODE_FIQ
Definition: arm.h:84
@ ARM_MODE_UND
Definition: arm.h:90
@ ARM_MODE_1176_MON
Definition: arm.h:91
@ ARM_MODE_ANY
Definition: arm.h:106
@ ARMV8_64_EL1H
Definition: arm.h:100
@ ARM_MODE_USR
Definition: arm.h:83
@ ARM_MODE_SVC
Definition: arm.h:86
@ ARM_MODE_USER_THREAD
Definition: arm.h:95
@ ARMV8_64_EL2H
Definition: arm.h:102
@ ARMV8_64_EL2T
Definition: arm.h:101
@ ARMV8_64_EL1T
Definition: arm.h:99
@ ARM_MODE_ABT
Definition: arm.h:88
@ ARM_MODE_THREAD
Definition: arm.h:94
void arm_free_reg_cache(struct arm *arm)
Definition: armv4_5.c:761
static struct arm * target_to_arm(const struct target *target)
Convert target handle to generic ARM target state handle.
Definition: arm.h:261
@ ARM_VFP_V3_D14
Definition: arm.h:125
@ ARM_VFP_V3_D24
Definition: arm.h:135
@ ARM_VFP_V3_D9
Definition: arm.h:120
@ ARM_VFP_V3_D1
Definition: arm.h:112
@ ARM_VFP_V3_D17
Definition: arm.h:128
@ ARM_VFP_V3_D19
Definition: arm.h:130
@ ARM_VFP_V3_D4
Definition: arm.h:115
@ ARM_VFP_V3_D15
Definition: arm.h:126
@ ARM_VFP_V3_D10
Definition: arm.h:121
@ ARM_VFP_V3_D3
Definition: arm.h:114
@ ARM_VFP_V3_D31
Definition: arm.h:142
@ ARM_VFP_V3_D16
Definition: arm.h:127
@ ARM_VFP_V3_D22
Definition: arm.h:133
@ ARM_VFP_V3_D5
Definition: arm.h:116
@ ARM_VFP_V3_D18
Definition: arm.h:129
@ ARM_VFP_V3_D26
Definition: arm.h:137
@ ARM_VFP_V3_D7
Definition: arm.h:118
@ ARM_VFP_V3_D23
Definition: arm.h:134
@ ARM_VFP_V3_D21
Definition: arm.h:132
@ ARM_VFP_V3_D28
Definition: arm.h:139
@ ARM_VFP_V3_D2
Definition: arm.h:113
@ ARM_VFP_V3_D27
Definition: arm.h:138
@ ARM_VFP_V3_D29
Definition: arm.h:140
@ ARM_VFP_V3_D11
Definition: arm.h:122
@ ARM_VFP_V3_FPSCR
Definition: arm.h:143
@ ARM_VFP_V3_D20
Definition: arm.h:131
@ ARM_VFP_V3_D13
Definition: arm.h:124
@ ARM_VFP_V3_D12
Definition: arm.h:123
@ ARM_VFP_V3_D6
Definition: arm.h:117
@ ARM_VFP_V3_D8
Definition: arm.h:119
@ ARM_VFP_V3_D0
Definition: arm.h:111
@ ARM_VFP_V3_D30
Definition: arm.h:141
@ ARM_VFP_V3_D25
Definition: arm.h:136
arm_state
The PSR "T" and "J" bits define the mode of "classic ARM" cores.
Definition: arm.h:150
@ ARM_STATE_JAZELLE
Definition: arm.h:153
@ ARM_STATE_THUMB
Definition: arm.h:152
@ ARM_STATE_ARM
Definition: arm.h:151
@ ARM_STATE_AARCH64
Definition: arm.h:155
@ ARM_STATE_THUMB_EE
Definition: arm.h:154
const struct command_registration arm_command_handlers[]
Definition: armv4_5.c:1247
struct reg_cache * armv8_build_reg_cache(struct target *target)
Builds cache of architecturally defined registers.
Definition: armv8.c:1787
int arm_init_arch_info(struct target *target, struct arm *arm)
Definition: armv4_5.c:1799
const char * arm_mode_name(unsigned int psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
Definition: armv4_5.c:171
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(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)
Definition: armv4_5.c:1574
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
uint64_t op
Definition: lakemont.c:68
This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
Definition: arm_adi_v5.h:348
unsigned int common_magic
Definition: arm.h:274
enum arm_mode core_mode
Definition: arm.h:276
enum arm_state core_state
Definition: arm.h:277
This wraps an implementation of DPM primitives.
Definition: arm_dpm.h:47
Definition: arm.h:280
int num
Definition: arm.h:281
struct arm * arm
Definition: arm.h:284
uint8_t value[16]
Definition: arm.h:285
enum arm_mode mode
Definition: arm.h:282
struct target * target
Definition: arm.h:283
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
int(* full_context)(struct target *target)
Retrieve all core registers, for display.
Definition: arm.h:221
enum arm_arch arch
ARM architecture version.
Definition: arm.h:202
int(* mrrc)(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t *value)
Read coprocessor to two registers.
Definition: arm.h:236
void * arch_info
Definition: arm.h:251
struct etm_context * etm
Handle for the Embedded Trace Module, if one is present.
Definition: arm.h:216
enum arm_core_type core_type
Indicates what registers are in the ARM state core register set.
Definition: arm.h:193
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:230
enum arm_mode core_mode
Record the current core mode: SVC, USR, or some other mode.
Definition: arm.h:196
struct reg * cpsr
Handle to the CPSR/xPSR; valid in all core modes.
Definition: arm.h:184
struct adiv5_dap * dap
For targets conforming to ARM Debug Interface v5, this handle references the Debug Access Port (DAP) ...
Definition: arm.h:257
struct reg * pc
Handle to the PC; valid in all core modes.
Definition: arm.h:181
int(* write_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode, uint8_t *value)
Definition: arm.h:226
int(* setup_semihosting)(struct target *target, int enable)
Definition: arm.h:207
const int * map
Support for arm_reg_current()
Definition: arm.h:190
int(* mcrr)(struct target *target, int cpnum, uint32_t op, uint32_t crm, uint64_t value)
Write coprocessor from two registers.
Definition: arm.h:247
int(* read_core_reg)(struct target *target, struct reg *reg, int num, enum arm_mode mode)
Retrieve a single core register.
Definition: arm.h:224
struct reg_cache * core_cache
Definition: arm.h:178
struct arm_dpm * dpm
Handle for the debug module, if one is present.
Definition: arm.h:213
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:241
struct reg * spsr
Handle to the SPSR; valid only in core modes with an SPSR.
Definition: arm.h:187
unsigned int common_magic
Definition: arm.h:176
int arm_vfp_version
Floating point or VFP version, 0 if disabled.
Definition: arm.h:205
struct target * target
Backpointer to the target.
Definition: arm.h:210
enum arm_state core_state
Record the current core state: ARM, Thumb, or otherwise.
Definition: arm.h:199
Definition: register.h:111
uint8_t * value
Definition: register.h:122
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
uint8_t count[4]
Definition: vdebug.c:22