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