OpenOCD
armv8.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2015 by David Ung *
5  ***************************************************************************/
6 
7 #ifndef OPENOCD_TARGET_ARMV8_H
8 #define OPENOCD_TARGET_ARMV8_H
9 
10 #include "arm_adi_v5.h"
11 #include "arm.h"
12 #include "armv4_5_mmu.h"
13 #include "armv4_5_cache.h"
14 #include "armv8_dpm.h"
15 #include "arm_cti.h"
16 
17 enum {
18  ARMV8_R0 = 0,
49 
50  ARMV8_SP = 31,
51  ARMV8_PC = 32,
52  ARMV8_XPSR = 33,
53 
54  ARMV8_V0 = 34,
88 
92 
96 
100 
101  /* Pseudo registers defined by GDB to remove the pauth signature. */
104 
106 };
107 
113 };
114 
115 #define ARMV8_COMMON_MAGIC 0x0A450AAAU
116 
117 /* VA to PA translation operations opc2 values*/
118 #define V2PCWPR 0
119 #define V2PCWPW 1
120 #define V2PCWUR 2
121 #define V2PCWUW 3
122 #define V2POWPR 4
123 #define V2POWPW 5
124 #define V2POWUR 6
125 #define V2POWUW 7
126 /* L210/L220 cache controller support */
128  uint32_t base;
129  uint32_t way;
130 };
131 
133  uint32_t level_num;
134  /* cache dimensioning */
135  uint32_t linelen;
136  uint32_t associativity;
137  uint32_t nsets;
138  uint32_t cachesize;
139  /* info for set way operation on cache */
140  uint32_t index;
141  uint32_t index_shift;
142  uint32_t way;
143  uint32_t way_shift;
144 };
145 
146 /* information about one architecture cache at any level */
148  int ctype; /* cache type, CLIDR encoding */
149  struct armv8_cachesize d_u_size; /* data cache */
150  struct armv8_cachesize i_size; /* instruction cache */
151 };
152 
154  int info;
155  int loc;
156  uint32_t iminline;
157  uint32_t dminline;
158  struct armv8_arch_cache arch[6]; /* cache info, L1 - L7 */
161 
162  /* l2 external unified cache if some */
163  void *l2_cache;
167  struct armv8_cache_common *armv8_cache);
168 };
169 
171  /* following field mmu working way */
172  int32_t ttbr1_used; /* -1 not initialized, 0 no ttbr1 1 ttbr1 used and */
173  uint64_t ttbr0_mask;/* masked to be used */
174 
175  uint32_t ttbcr; /* cache for ttbcr register */
176  uint32_t ttbr_mask[2];
177  uint32_t ttbr_range[2];
178 
180  uint32_t size, uint32_t count, uint8_t *buffer);
182  uint32_t mmu_enabled;
183 };
184 
185 struct armv8_common {
186  unsigned int common_magic;
187 
188  struct arm arm;
190 
191  /* Core Debug Unit */
192  struct arm_dpm dpm;
195 
196  const uint32_t *opcodes;
197 
198  /* armv8 aarch64 need below information for page translation */
199  uint8_t va_size;
200  uint8_t pa_size;
201  uint32_t page_size;
202  uint64_t ttbr_base;
203  bool is_armv8r;
204 
206 
207  struct arm_cti *cti;
208 
209  /* True if OpenOCD provides pointer auth related info to GDB */
211 
213 
214  /* last run-control command issued to this target (resume, halt, step) */
216 
217  /* Direct processor core register read and writes */
218  int (*read_reg_u64)(struct armv8_common *armv8, int num, uint64_t *value);
219  int (*write_reg_u64)(struct armv8_common *armv8, int num, uint64_t value);
220 
221  /* SIMD/FPU registers read/write interface */
222  int (*read_reg_u128)(struct armv8_common *armv8, int num,
223  uint64_t *lvalue, uint64_t *hvalue);
224  int (*write_reg_u128)(struct armv8_common *armv8, int num,
225  uint64_t lvalue, uint64_t hvalue);
226 
228  int (*post_debug_entry)(struct target *target);
229 
231 };
232 
233 static inline struct armv8_common *
235 {
236  return container_of(target->arch_info, struct armv8_common, arm);
237 }
238 
239 static inline bool is_armv8(struct armv8_common *armv8)
240 {
241  return armv8->common_magic == ARMV8_COMMON_MAGIC;
242 }
243 
244 /* register offsets from armv8.debug_base */
245 #define CPUV8_DBG_MAINID0 0xD00
246 #define CPUV8_DBG_CPUFEATURE0 0xD20
247 #define CPUV8_DBG_DBGFEATURE0 0xD28
248 #define CPUV8_DBG_MEMFEATURE0 0xD38
249 
250 #define CPUV8_DBG_LOCKACCESS 0xFB0
251 #define CPUV8_DBG_LOCKSTATUS 0xFB4
252 
253 #define CPUV8_DBG_EDESR 0x20
254 #define CPUV8_DBG_EDECR 0x24
255 #define CPUV8_DBG_EDWAR0 0x30
256 #define CPUV8_DBG_EDWAR1 0x34
257 #define CPUV8_DBG_DSCR 0x088
258 #define CPUV8_DBG_DRCR 0x090
259 #define CPUV8_DBG_ECCR 0x098
260 #define CPUV8_DBG_PRCR 0x310
261 #define CPUV8_DBG_PRSR 0x314
262 
263 #define CPUV8_DBG_DTRRX 0x080
264 #define CPUV8_DBG_ITR 0x084
265 #define CPUV8_DBG_SCR 0x088
266 #define CPUV8_DBG_DTRTX 0x08c
267 
268 #define CPUV8_DBG_BVR_BASE 0x400
269 #define CPUV8_DBG_BCR_BASE 0x408
270 #define CPUV8_DBG_WVR_BASE 0x800
271 #define CPUV8_DBG_WCR_BASE 0x808
272 #define CPUV8_DBG_VCR 0x01C
273 
274 #define CPUV8_DBG_OSLAR 0x300
275 
276 #define CPUV8_DBG_AUTHSTATUS 0xFB8
277 
278 #define PAGE_SIZE_4KB 0x1000
279 #define PAGE_SIZE_4KB_LEVEL0_BITS 39
280 #define PAGE_SIZE_4KB_LEVEL1_BITS 30
281 #define PAGE_SIZE_4KB_LEVEL2_BITS 21
282 #define PAGE_SIZE_4KB_LEVEL3_BITS 12
283 
284 #define PAGE_SIZE_4KB_LEVEL0_MASK ((0x1FFULL) << PAGE_SIZE_4KB_LEVEL0_BITS)
285 #define PAGE_SIZE_4KB_LEVEL1_MASK ((0x1FFULL) << PAGE_SIZE_4KB_LEVEL1_BITS)
286 #define PAGE_SIZE_4KB_LEVEL2_MASK ((0x1FFULL) << PAGE_SIZE_4KB_LEVEL2_BITS)
287 #define PAGE_SIZE_4KB_LEVEL3_MASK ((0x1FFULL) << PAGE_SIZE_4KB_LEVEL3_BITS)
288 
289 #define PAGE_SIZE_4KB_TRBBASE_MASK 0xFFFFFFFFF000
290 
291 int armv8_arch_state(struct target *target);
292 int armv8_read_mpidr(struct armv8_common *armv8);
293 int armv8_identify_cache(struct armv8_common *armv8);
294 int armv8_init_arch_info(struct target *target, struct armv8_common *armv8);
296  target_addr_t *val, int meminfo);
297 
299  struct armv8_cache_common *armv8_cache);
300 
301 void armv8_set_cpsr(struct arm *arm, uint32_t cpsr);
302 
303 static inline unsigned int armv8_curel_from_core_mode(enum arm_mode core_mode)
304 {
305  switch (core_mode) {
306  /* Aarch32 modes */
307  case ARM_MODE_USR:
308  return 0;
309  case ARM_MODE_SVC:
310  case ARM_MODE_ABT: /* FIXME: EL3? */
311  case ARM_MODE_IRQ: /* FIXME: EL3? */
312  case ARM_MODE_FIQ: /* FIXME: EL3? */
313  case ARM_MODE_UND: /* FIXME: EL3? */
314  case ARM_MODE_SYS: /* FIXME: EL3? */
315  return 1;
316  /* case ARM_MODE_HYP:
317  * return 2;
318  */
319  case ARM_MODE_MON:
320  return 3;
321  /* all Aarch64 modes */
322  default:
323  return (core_mode >> 2) & 3;
324  }
325 }
326 
327 const char *armv8_mode_name(unsigned int psr_mode);
328 void armv8_select_reg_access(struct armv8_common *armv8, bool is_aarch64);
329 int armv8_set_dbgreg_bits(struct armv8_common *armv8, unsigned int reg, unsigned long mask, unsigned long value);
330 
331 extern void armv8_free_reg_cache(struct target *target);
332 
333 extern const struct command_registration armv8_command_handlers[];
334 
335 #endif /* OPENOCD_TARGET_ARMV8_H */
Holds the interface to ARM cores.
arm_mode
Represent state of an ARM core.
Definition: arm.h:82
@ ARM_MODE_IRQ
Definition: arm.h:85
@ ARM_MODE_SYS
Definition: arm.h:92
@ ARM_MODE_MON
Definition: arm.h:87
@ ARM_MODE_FIQ
Definition: arm.h:84
@ ARM_MODE_UND
Definition: arm.h:90
@ ARM_MODE_USR
Definition: arm.h:83
@ ARM_MODE_SVC
Definition: arm.h:86
@ ARM_MODE_ABT
Definition: arm.h:88
This defines formats and data structures used to talk to ADIv5 entities.
int armv8_init_arch_info(struct target *target, struct armv8_common *armv8)
Definition: armv8.c:1320
int armv8_set_dbgreg_bits(struct armv8_common *armv8, unsigned int reg, unsigned long mask, unsigned long value)
Definition: armv8.c:2052
int armv8_identify_cache(struct armv8_common *armv8)
Definition: armv8_cache.c:354
int armv8_read_mpidr(struct armv8_common *armv8)
Definition: armv8.c:881
void armv8_free_reg_cache(struct target *target)
Definition: armv8.c:1948
static struct armv8_common * target_to_armv8(struct target *target)
Definition: armv8.h:234
run_control_op
Definition: armv8.h:108
@ ARMV8_RUNCONTROL_HALT
Definition: armv8.h:111
@ ARMV8_RUNCONTROL_UNKNOWN
Definition: armv8.h:109
@ ARMV8_RUNCONTROL_RESUME
Definition: armv8.h:110
@ ARMV8_RUNCONTROL_STEP
Definition: armv8.h:112
int armv8_arch_state(struct target *target)
Definition: armv8.c:1360
int armv8_mmu_translate_va_pa(struct target *target, target_addr_t va, target_addr_t *val, int meminfo)
Definition: armv8.c:1137
static bool is_armv8(struct armv8_common *armv8)
Definition: armv8.h:239
const struct command_registration armv8_command_handlers[]
Definition: armv8.c:1962
void armv8_set_cpsr(struct arm *arm, uint32_t cpsr)
Configures host-side ARM records to reflect the specified CPSR.
Definition: armv8.c:961
static unsigned int armv8_curel_from_core_mode(enum arm_mode core_mode)
Definition: armv8.h:303
void armv8_select_reg_access(struct armv8_common *armv8, bool is_aarch64)
Definition: armv8.c:864
@ ARMV8_V27
Definition: armv8.h:81
@ ARMV8_R14
Definition: armv8.h:32
@ ARMV8_ESR_EL2
Definition: armv8.h:94
@ ARMV8_R20
Definition: armv8.h:38
@ ARMV8_V16
Definition: armv8.h:70
@ ARMV8_V1
Definition: armv8.h:55
@ ARMV8_V11
Definition: armv8.h:65
@ ARMV8_R0
Definition: armv8.h:18
@ ARMV8_V23
Definition: armv8.h:77
@ ARMV8_V2
Definition: armv8.h:56
@ ARMV8_R12
Definition: armv8.h:30
@ ARMV8_R21
Definition: armv8.h:39
@ ARMV8_R5
Definition: armv8.h:23
@ ARMV8_V5
Definition: armv8.h:59
@ ARMV8_ESR_EL1
Definition: armv8.h:90
@ ARMV8_V12
Definition: armv8.h:66
@ ARMV8_V4
Definition: armv8.h:58
@ ARMV8_V25
Definition: armv8.h:79
@ ARMV8_R7
Definition: armv8.h:25
@ ARMV8_V14
Definition: armv8.h:68
@ ARMV8_PAUTH_DMASK
Definition: armv8.h:102
@ ARMV8_R9
Definition: armv8.h:27
@ ARMV8_LAST_REG
Definition: armv8.h:105
@ ARMV8_V18
Definition: armv8.h:72
@ ARMV8_R17
Definition: armv8.h:35
@ ARMV8_R23
Definition: armv8.h:41
@ ARMV8_V6
Definition: armv8.h:60
@ ARMV8_R18
Definition: armv8.h:36
@ ARMV8_R1
Definition: armv8.h:19
@ ARMV8_SPSR_EL3
Definition: armv8.h:99
@ ARMV8_SPSR_EL2
Definition: armv8.h:95
@ ARMV8_R24
Definition: armv8.h:42
@ ARMV8_V19
Definition: armv8.h:73
@ ARMV8_R22
Definition: armv8.h:40
@ ARMV8_SP
Definition: armv8.h:50
@ ARMV8_R6
Definition: armv8.h:24
@ ARMV8_R29
Definition: armv8.h:47
@ ARMV8_V3
Definition: armv8.h:57
@ ARMV8_V7
Definition: armv8.h:61
@ ARMV8_V31
Definition: armv8.h:85
@ ARMV8_V17
Definition: armv8.h:71
@ ARMV8_V13
Definition: armv8.h:67
@ ARMV8_R25
Definition: armv8.h:43
@ ARMV8_V28
Definition: armv8.h:82
@ ARMV8_V9
Definition: armv8.h:63
@ ARMV8_V22
Definition: armv8.h:76
@ ARMV8_ELR_EL3
Definition: armv8.h:97
@ ARMV8_XPSR
Definition: armv8.h:52
@ ARMV8_R30
Definition: armv8.h:48
@ ARMV8_PAUTH_CMASK
Definition: armv8.h:103
@ ARMV8_V8
Definition: armv8.h:62
@ ARMV8_R27
Definition: armv8.h:45
@ ARMV8_R4
Definition: armv8.h:22
@ ARMV8_FPCR
Definition: armv8.h:87
@ ARMV8_V24
Definition: armv8.h:78
@ ARMV8_R8
Definition: armv8.h:26
@ ARMV8_PC
Definition: armv8.h:51
@ ARMV8_V0
Definition: armv8.h:54
@ ARMV8_SPSR_EL1
Definition: armv8.h:91
@ ARMV8_R13
Definition: armv8.h:31
@ ARMV8_ELR_EL2
Definition: armv8.h:93
@ ARMV8_V29
Definition: armv8.h:83
@ ARMV8_ESR_EL3
Definition: armv8.h:98
@ ARMV8_R10
Definition: armv8.h:28
@ ARMV8_V26
Definition: armv8.h:80
@ ARMV8_V10
Definition: armv8.h:64
@ ARMV8_R28
Definition: armv8.h:46
@ ARMV8_R3
Definition: armv8.h:21
@ ARMV8_R26
Definition: armv8.h:44
@ ARMV8_V21
Definition: armv8.h:75
@ ARMV8_V15
Definition: armv8.h:69
@ ARMV8_V20
Definition: armv8.h:74
@ ARMV8_R16
Definition: armv8.h:34
@ ARMV8_V30
Definition: armv8.h:84
@ ARMV8_R11
Definition: armv8.h:29
@ ARMV8_FPSR
Definition: armv8.h:86
@ ARMV8_ELR_EL1
Definition: armv8.h:89
@ ARMV8_R15
Definition: armv8.h:33
@ ARMV8_R2
Definition: armv8.h:20
@ ARMV8_R19
Definition: armv8.h:37
#define ARMV8_COMMON_MAGIC
Definition: armv8.h:115
const char * armv8_mode_name(unsigned int psr_mode)
Map PSR mode bits to the name of an ARM processor operating mode.
Definition: armv8.c:108
int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache)
Definition: armv8.c:1302
uint64_t buffer
Pointer to data buffer to send over SPI.
Definition: dw-spi-helper.h:0
uint32_t size
Size of dw_spi_transaction::buffer.
Definition: dw-spi-helper.h:4
uint32_t address
Starting address. Sector aligned.
Definition: dw-spi-helper.h:0
int mask
Definition: esirisc.c:1740
struct target * target
Definition: rtt/rtt.c:26
This represents an ARM Debug Interface (v5) Access Port (AP).
Definition: arm_adi_v5.h:250
This wraps an implementation of DPM primitives.
Definition: arm_dpm.h:47
Represents a generic ARM core, with standard application registers.
Definition: arm.h:175
struct armv8_cachesize d_u_size
Definition: armv8.h:149
struct armv8_cachesize i_size
Definition: armv8.h:150
uint32_t iminline
Definition: armv8.h:156
void * l2_cache
Definition: armv8.h:163
uint32_t dminline
Definition: armv8.h:157
int d_u_cache_enabled
Definition: armv8.h:160
int(* invalidate_all_instruction_cache)(struct target *target)
Definition: armv8.h:165
struct armv8_arch_cache arch[6]
Definition: armv8.h:158
int(* display_cache_info)(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache)
Definition: armv8.h:166
int(* flush_all_data_cache)(struct target *target)
Definition: armv8.h:164
int i_cache_enabled
Definition: armv8.h:159
uint32_t way_shift
Definition: armv8.h:143
uint32_t associativity
Definition: armv8.h:136
uint32_t index
Definition: armv8.h:140
uint32_t index_shift
Definition: armv8.h:141
uint32_t way
Definition: armv8.h:142
uint32_t level_num
Definition: armv8.h:133
uint32_t nsets
Definition: armv8.h:137
uint32_t linelen
Definition: armv8.h:135
uint32_t cachesize
Definition: armv8.h:138
uint8_t va_size
Definition: armv8.h:199
uint32_t page_size
Definition: armv8.h:201
struct arm_dpm dpm
Definition: armv8.h:192
uint64_t ttbr_base
Definition: armv8.h:202
bool is_armv8r
Definition: armv8.h:203
target_addr_t debug_base
Definition: armv8.h:193
struct reg_cache * core_cache
Definition: armv8.h:189
bool sticky_reset
Definition: armv8.h:212
enum run_control_op last_run_control_op
Definition: armv8.h:215
struct armv8_mmu_common armv8_mmu
Definition: armv8.h:205
int(* read_reg_u64)(struct armv8_common *armv8, int num, uint64_t *value)
Definition: armv8.h:218
int(* write_reg_u128)(struct armv8_common *armv8, int num, uint64_t lvalue, uint64_t hvalue)
Definition: armv8.h:224
struct adiv5_ap * debug_ap
Definition: armv8.h:194
int(* read_reg_u128)(struct armv8_common *armv8, int num, uint64_t *lvalue, uint64_t *hvalue)
Definition: armv8.h:222
unsigned int common_magic
Definition: armv8.h:186
struct arm_cti * cti
Definition: armv8.h:207
void(* pre_restore_context)(struct target *target)
Definition: armv8.h:230
int(* examine_debug_reason)(struct target *target)
Definition: armv8.h:227
int(* write_reg_u64)(struct armv8_common *armv8, int num, uint64_t value)
Definition: armv8.h:219
bool enable_pauth
Definition: armv8.h:210
const uint32_t * opcodes
Definition: armv8.h:196
uint8_t pa_size
Definition: armv8.h:200
int(* post_debug_entry)(struct target *target)
Definition: armv8.h:228
uint32_t base
Definition: armv8.h:128
uint32_t way
Definition: armv8.h:129
int32_t ttbr1_used
Definition: armv8.h:172
uint64_t ttbr0_mask
Definition: armv8.h:173
uint32_t mmu_enabled
Definition: armv8.h:182
uint32_t ttbr_mask[2]
Definition: armv8.h:176
uint32_t ttbcr
Definition: armv8.h:175
int(* read_physical_memory)(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: armv8.h:179
struct armv8_cache_common armv8_cache
Definition: armv8.h:181
uint32_t ttbr_range[2]
Definition: armv8.h:177
When run_command is called, a new instance will be created on the stack, filled with the proper value...
Definition: command.h:76
Definition: register.h:111
Definition: target.h:119
void * arch_info
Definition: target.h:167
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
uint8_t cmd
Definition: vdebug.c:1
uint8_t count[4]
Definition: vdebug.c:22