OpenOCD
arc.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2013-2015,2019-2020 Synopsys, Inc. *
5  * Frank Dols <frank.dols@synopsys.com> *
6  * Mischa Jonker <mischa.jonker@synopsys.com> *
7  * Anton Kolesov <anton.kolesov@synopsys.com> *
8  * Evgeniy Didin <didin@synopsys.com> *
9  ***************************************************************************/
10 
11 #ifndef OPENOCD_TARGET_ARC_H
12 #define OPENOCD_TARGET_ARC_H
13 
14 #include <helper/time_support.h>
15 #include <jtag/jtag.h>
16 
17 #include "algorithm.h"
18 #include "breakpoints.h"
19 #include "jtag/interface.h"
20 #include "register.h"
21 #include "target.h"
22 #include "target_request.h"
23 #include "target_type.h"
24 #include "helper/bits.h"
25 
26 #include "arc_jtag.h"
27 #include "arc_cmd.h"
28 #include "arc_mem.h"
29 
30 #define ARC_COMMON_MAGIC 0xB32EB324U /* just a unique number */
31 
32 #define AUX_DEBUG_REG 0x5
33 #define AUX_PC_REG 0x6
34 #define AUX_STATUS32_REG 0xA
35 
36 
37 #define SET_CORE_FORCE_HALT BIT(1)
38 #define SET_CORE_HALT_BIT BIT(0) /* STATUS32[0] = H field */
39 #define SET_CORE_ENABLE_INTERRUPTS BIT(31)
40 /* STATUS32[5] or AE bit indicates if the processor is in exception state */
41 #define SET_CORE_AE_BIT BIT(5)
42 /* Single instruction step bit in Debug register */
43 #define SET_CORE_SINGLE_INSTR_STEP BIT(11)
44 
45 #define AUX_STATUS32_REG_HALT_BIT BIT(0)
46 #define AUX_STATUS32_REG_IE_BIT BIT(31) /* STATUS32[31] = IE field */
47 
48 /* ARC register numbers */
49 enum {
76  ARC_GP = 26,
77  ARC_FP = 27,
78  ARC_SP = 28,
79  ARC_ILINK = 29,
81  ARC_BLINK = 31,
83 
84  /* Reserved registers */
85  ARC_R61 = 61,
86  ARC_R62 = 62,
87 
88  ARC_PCL = 63,
89  ARC_PC = 64,
91  ARC_LP_END = 66,
93 };
94 
95 #define CORE_REG_MAX_NUMBER (63)
96 
97 /* Limit reg_type/reg_type_field name to 20 symbols */
98 #define REG_TYPE_MAX_NAME_LENGTH 20
99 
100 /* ARC 32bits opcodes */
101 #define ARC_SDBBP_32 0x256F003FU /* BRK */
102 
103 /* ARC 16bits opcodes */
104 #define ARC_SDBBP_16 0x7FFF /* BRK_S */
105 
106 /* Cache registers */
107 #define AUX_IC_IVIC_REG 0X10
108 #define IC_IVIC_INVALIDATE 0XFFFFFFFF
109 
110 #define AUX_DC_IVDC_REG 0X47
111 #define DC_IVDC_INVALIDATE BIT(0)
112 #define AUX_DC_CTRL_REG 0X48
113 #define DC_CTRL_IM BIT(6)
114 
115 /* L2 cache registers */
116 #define SLC_AUX_CACHE_CTRL 0x903
117 #define L2_CTRL_IM BIT(6)
118 #define L2_CTRL_BS BIT(8) /* Busy flag */
119 #define SLC_AUX_CACHE_FLUSH 0x904
120 #define L2_FLUSH_FL BIT(0)
121 #define SLC_AUX_CACHE_INV 0x905
122 #define L2_INV_IV BIT(0)
123 
124  /* Action Point */
125 #define AP_AC_AT_INST_ADDR 0x0
126 #define AP_AC_AT_MEMORY_ADDR 0x2
127 #define AP_AC_AT_AUXREG_ADDR 0x4
128 
129 #define AP_AC_TT_DISABLE 0x00
130 #define AP_AC_TT_WRITE 0x10
131 #define AP_AC_TT_READ 0x20
132 #define AP_AC_TT_READWRITE 0x30
133 
137 };
138 /* Register data type */
140  struct list_head list;
141  struct reg_data_type data_type;
146  union {
149  };
150 };
151 
152 /* Standard GDB register types */
153 static const struct reg_data_type standard_gdb_types[] = {
154  { .type = REG_TYPE_INT, .id = "int" },
155  { .type = REG_TYPE_INT8, .id = "int8" },
156  { .type = REG_TYPE_INT16, .id = "int16" },
157  { .type = REG_TYPE_INT32, .id = "int32" },
158  { .type = REG_TYPE_INT64, .id = "int64" },
159  { .type = REG_TYPE_INT128, .id = "int128" },
160  { .type = REG_TYPE_UINT8, .id = "uint8" },
161  { .type = REG_TYPE_UINT16, .id = "uint16" },
162  { .type = REG_TYPE_UINT32, .id = "uint32" },
163  { .type = REG_TYPE_UINT64, .id = "uint64" },
164  { .type = REG_TYPE_UINT128, .id = "uint128" },
165  { .type = REG_TYPE_CODE_PTR, .id = "code_ptr" },
166  { .type = REG_TYPE_DATA_PTR, .id = "data_ptr" },
167  { .type = REG_TYPE_FLOAT, .id = "float" },
168  { .type = REG_TYPE_IEEE_SINGLE, .id = "ieee_single" },
169  { .type = REG_TYPE_IEEE_DOUBLE, .id = "ieee_double" },
170 };
171 
175 };
176 
177 /* Actionpoint related fields */
179  int used;
180  uint32_t bp_value;
181  uint32_t reg_address;
183 };
184 
185 struct arc_common {
186  unsigned int common_magic;
187 
188  struct arc_jtag jtag_info;
189 
192 
193  /* Cache control */
197  /* If true, then D$ has been already flushed since core has been
198  * halted. */
200  /* If true, then L2 has been already flushed since core has been
201  * halted. */
203  /* If true, then caches have been already flushed since core has been
204  * halted. */
208 
209  /* Indicate if cache was built (for deinit function) */
212  /* Closely Coupled memory(CCM) regions for performance-critical
213  * code (optional). */
214  uint32_t iccm0_start;
215  uint32_t iccm0_end;
216  uint32_t iccm1_start;
217  uint32_t iccm1_end;
218  uint32_t dccm_start;
219  uint32_t dccm_end;
220 
222 
223  /* Register descriptions */
224  struct list_head reg_data_types;
228  unsigned long num_regs;
229  unsigned long num_core_regs;
230  unsigned long num_aux_regs;
231  unsigned long num_bcr_regs;
232  unsigned long last_general_reg;
233 
234  /* PC register location in register cache. */
235  unsigned long pc_index_in_cache;
236  /* DEBUG register location in register cache. */
237  unsigned long debug_index_in_cache;
238 
239  /* Actionpoints */
240  unsigned int actionpoints_num;
243 };
244 
245 /* Borrowed from nds32.h */
246 #define CHECK_RETVAL(action) \
247  do { \
248  int __retval = (action); \
249  if (__retval != ERROR_OK) { \
250  LOG_DEBUG("error while calling \"%s\"", \
251  # action); \
252  return __retval; \
253  } \
254  } while (0)
255 
256 #define JIM_CHECK_RETVAL(action) \
257  do { \
258  int __retval = (action); \
259  if (__retval != JIM_OK) { \
260  LOG_DEBUG("error while calling \"%s\"", \
261  # action); \
262  return __retval; \
263  } \
264  } while (0)
265 
266 static inline struct arc_common *target_to_arc(struct target *target)
267 {
268  return target->arch_info;
269 }
270 
271 /* ----- Inlined functions ------------------------------------------------- */
272 
277 static inline void arc_h_u32_to_me(uint8_t *buf, int val)
278 {
279  buf[1] = (uint8_t) (val >> 24);
280  buf[0] = (uint8_t) (val >> 16);
281  buf[3] = (uint8_t) (val >> 8);
282  buf[2] = (uint8_t) (val >> 0);
283 }
284 
289 static inline uint32_t arc_me_to_h_u32(const uint8_t *buf)
290 {
291  return (uint32_t)(buf[2] | buf[3] << 8 | buf[0] << 16 | buf[1] << 24);
292 }
293 
294 
295 /* ARC Register description */
296 struct arc_reg_desc {
297 
298  struct target *target;
299 
300  /* Register name */
301  char *name;
302 
303  /* Actual place of storing reg_value */
304  uint8_t reg_value[4];
305 
306  /* Actual place of storing register feature */
307  struct reg_feature feature;
308 
309  /* GDB XML feature */
311 
312  /* Is this a register in g/G-packet? */
314 
315  /* Architectural number: core reg num or AUX reg num */
316  uint32_t arch_num;
317 
318  /* Core or AUX register? */
319  bool is_core;
320 
321  /* Build configuration register? */
322  bool is_bcr;
323 
324  /* Data type */
326 
327  struct list_head list;
328 };
329 
330 /* Error codes */
331 #define ERROR_ARC_REGISTER_NOT_FOUND (-700)
332 #define ERROR_ARC_REGISTER_FIELD_NOT_FOUND (-701)
333 #define ERROR_ARC_REGISTER_IS_NOT_STRUCT (-702)
334 #define ERROR_ARC_FIELD_IS_NOT_BITFIELD (-703)
335 #define ERROR_ARC_REGTYPE_NOT_FOUND (-704)
336 
337 void free_reg_desc(struct arc_reg_desc *r);
338 
339 
340 void arc_reg_data_type_add(struct target *target,
341  struct arc_reg_data_type *data_type);
342 
343 int arc_reg_add(struct target *target, struct arc_reg_desc *arc_reg,
344  const char * const type_name, const size_t type_name_len);
345 
346 struct reg *arc_reg_get_by_name(struct reg_cache *first,
347  const char *name, bool search_all);
348 
349 int arc_reg_get_field(struct target *target, const char *reg_name,
350  const char *field_name, uint32_t *value_ptr);
351 
352 int arc_cache_flush(struct target *target);
353 int arc_cache_invalidate(struct target *target);
354 
356  uint32_t auxreg_addr, uint32_t transaction);
357 int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr);
358 int arc_set_actionpoints_num(struct target *target, uint32_t ap_num);
359 
360 #endif /* OPENOCD_TARGET_ARC_H */
static struct arc_common * target_to_arc(struct target *target)
Definition: arc.h:266
int arc_reg_get_field(struct target *target, const char *reg_name, const char *field_name, uint32_t *value_ptr)
Definition: arc.c:542
int arc_reg_add(struct target *target, struct arc_reg_desc *arc_reg, const char *const type_name, const size_t type_name_len)
Definition: arc.c:167
void arc_reg_data_type_add(struct target *target, struct arc_reg_data_type *data_type)
Definition: arc.c:54
static void arc_h_u32_to_me(uint8_t *buf, int val)
Convert data in host endianness to the middle endian.
Definition: arc.h:277
int arc_cache_flush(struct target *target)
Definition: arc.c:2231
static const struct reg_data_type standard_gdb_types[]
Definition: arc.h:153
int arc_cache_invalidate(struct target *target)
Definition: arc.c:2154
static uint32_t arc_me_to_h_u32(const uint8_t *buf)
Convert data in middle endian to host endian.
Definition: arc.h:289
arc_actionpointype
Definition: arc.h:172
@ ARC_AP_BREAKPOINT
Definition: arc.h:173
@ ARC_AP_WATCHPOINT
Definition: arc.h:174
int arc_remove_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr)
Definition: arc.c:1779
void free_reg_desc(struct arc_reg_desc *r)
Definition: arc_cmd.c:656
int arc_add_auxreg_actionpoint(struct target *target, uint32_t auxreg_addr, uint32_t transaction)
Definition: arc.c:1747
int arc_set_actionpoints_num(struct target *target, uint32_t ap_num)
Definition: arc.c:1723
#define REG_TYPE_MAX_NAME_LENGTH
Definition: arc.h:98
@ ARC_R5
Definition: arc.h:55
@ ARC_LP_COUNT
Definition: arc.h:82
@ ARC_R18
Definition: arc.h:68
@ ARC_R17
Definition: arc.h:67
@ ARC_R2
Definition: arc.h:52
@ ARC_R21
Definition: arc.h:71
@ ARC_R4
Definition: arc.h:54
@ ARC_R15
Definition: arc.h:65
@ ARC_R12
Definition: arc.h:62
@ ARC_R14
Definition: arc.h:64
@ ARC_R11
Definition: arc.h:61
@ ARC_R7
Definition: arc.h:57
@ ARC_R20
Definition: arc.h:70
@ ARC_ILINK
Definition: arc.h:79
@ ARC_R6
Definition: arc.h:56
@ ARC_R16
Definition: arc.h:66
@ ARC_BLINK
Definition: arc.h:81
@ ARC_R24
Definition: arc.h:74
@ ARC_GP
Definition: arc.h:76
@ ARC_FP
Definition: arc.h:77
@ ARC_R22
Definition: arc.h:72
@ ARC_PC
Definition: arc.h:89
@ ARC_R8
Definition: arc.h:58
@ ARC_R30
Definition: arc.h:80
@ ARC_SP
Definition: arc.h:78
@ ARC_STATUS32
Definition: arc.h:92
@ ARC_R9
Definition: arc.h:59
@ ARC_R19
Definition: arc.h:69
@ ARC_R13
Definition: arc.h:63
@ ARC_LP_START
Definition: arc.h:90
@ ARC_LP_END
Definition: arc.h:91
@ ARC_R3
Definition: arc.h:53
@ ARC_PCL
Definition: arc.h:88
@ ARC_R1
Definition: arc.h:51
@ ARC_R25
Definition: arc.h:75
@ ARC_R61
Definition: arc.h:85
@ ARC_R0
Definition: arc.h:50
@ ARC_R23
Definition: arc.h:73
@ ARC_R10
Definition: arc.h:60
@ ARC_R62
Definition: arc.h:86
struct reg * arc_reg_get_by_name(struct reg_cache *first, const char *name, bool search_all)
Private implementation of register_get_by_name() for ARC that doesn't skip not [yet] existing registe...
Definition: arc.c:70
const char * name
Definition: armv4_5.c:76
struct reg_data_type * data_type
Definition: armv8.c:1331
The JTAG interface can be implemented with a software or hardware fifo.
@ REG_TYPE_INT
Definition: register.h:21
@ REG_TYPE_UINT16
Definition: register.h:29
@ REG_TYPE_IEEE_DOUBLE
Definition: register.h:37
@ REG_TYPE_INT64
Definition: register.h:25
@ REG_TYPE_INT16
Definition: register.h:23
@ REG_TYPE_UINT32
Definition: register.h:30
@ REG_TYPE_CODE_PTR
Definition: register.h:33
@ REG_TYPE_DATA_PTR
Definition: register.h:34
@ REG_TYPE_INT32
Definition: register.h:24
@ REG_TYPE_INT128
Definition: register.h:26
@ REG_TYPE_UINT128
Definition: register.h:32
@ REG_TYPE_FLOAT
Definition: register.h:35
@ REG_TYPE_UINT64
Definition: register.h:31
@ REG_TYPE_INT8
Definition: register.h:22
@ REG_TYPE_IEEE_SINGLE
Definition: register.h:36
@ REG_TYPE_UINT8
Definition: register.h:28
int used
Definition: arc.h:179
uint32_t reg_address
Definition: arc.h:181
uint32_t bp_value
Definition: arc.h:180
enum arc_actionpointype type
Definition: arc.h:182
uint32_t dccm_start
Definition: arc.h:218
unsigned long num_core_regs
Definition: arc.h:229
bool has_icache
Definition: arc.h:195
uint32_t dccm_end
Definition: arc.h:219
bool dcache_flushed
Definition: arc.h:199
struct list_head core_reg_descriptions
Definition: arc.h:225
unsigned long debug_index_in_cache
Definition: arc.h:237
bool l2cache_flushed
Definition: arc.h:202
unsigned long num_aux_regs
Definition: arc.h:230
uint32_t iccm1_end
Definition: arc.h:217
bool dcache_invalidated
Definition: arc.h:206
bool has_l2cache
Definition: arc.h:196
int irq_state
Definition: arc.h:221
unsigned int actionpoints_num
Definition: arc.h:240
unsigned long pc_index_in_cache
Definition: arc.h:235
unsigned int actionpoints_num_avail
Definition: arc.h:241
unsigned long num_regs
Definition: arc.h:228
struct reg_cache * core_and_aux_cache
Definition: arc.h:190
bool icache_invalidated
Definition: arc.h:205
uint32_t iccm0_end
Definition: arc.h:215
bool core_aux_cache_built
Definition: arc.h:210
bool has_dcache
Definition: arc.h:194
unsigned long num_bcr_regs
Definition: arc.h:231
uint32_t iccm1_start
Definition: arc.h:216
unsigned int common_magic
Definition: arc.h:186
struct reg_cache * bcr_cache
Definition: arc.h:191
struct arc_jtag jtag_info
Definition: arc.h:188
struct arc_actionpoint * actionpoints_list
Definition: arc.h:242
uint32_t iccm0_start
Definition: arc.h:214
unsigned long last_general_reg
Definition: arc.h:232
struct list_head reg_data_types
Definition: arc.h:224
bool bcr_cache_built
Definition: arc.h:211
bool l2cache_invalidated
Definition: arc.h:207
struct list_head aux_reg_descriptions
Definition: arc.h:226
struct list_head bcr_reg_descriptions
Definition: arc.h:227
char name[REG_TYPE_MAX_NAME_LENGTH]
Definition: arc.h:136
struct reg_data_type_bitfield bitfield
Definition: arc.h:135
struct reg_data_type_flags_field * reg_type_flags_field
Definition: arc.h:148
struct reg_data_type data_type
Definition: arc.h:141
char data_type_id[REG_TYPE_MAX_NAME_LENGTH]
Definition: arc.h:144
struct list_head list
Definition: arc.h:140
struct reg_data_type_struct data_type_struct
Definition: arc.h:143
struct reg_data_type_flags data_type_flags
Definition: arc.h:142
struct arc_reg_bitfield * bitfields
Definition: arc.h:145
struct reg_data_type_struct_field * reg_type_struct_field
Definition: arc.h:147
struct list_head list
Definition: arc.h:327
char * gdb_xml_feature
Definition: arc.h:310
uint8_t reg_value[4]
Definition: arc.h:304
struct reg_data_type * data_type
Definition: arc.h:325
uint32_t arch_num
Definition: arc.h:316
bool is_general
Definition: arc.h:313
struct target * target
Definition: arc.h:298
bool is_core
Definition: arc.h:319
char * name
Definition: arc.h:301
bool is_bcr
Definition: arc.h:322
struct reg_feature feature
Definition: arc.h:307
Definition: list.h:26
enum reg_type type
Definition: register.h:100
Definition: register.h:111
Definition: target.h:120
void * arch_info
Definition: target.h:169