OpenOCD
nds32.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2013 Andes Technology *
5  * Hsiangkai Wang <hkwang@andestech.com> *
6  ***************************************************************************/
7 
8 #ifndef OPENOCD_TARGET_NDS32_H
9 #define OPENOCD_TARGET_NDS32_H
10 
11 #include <jtag/jtag.h>
12 #include "target.h"
13 #include "target_type.h"
14 #include "register.h"
15 #include "breakpoints.h"
16 #include "nds32_reg.h"
17 #include "nds32_insn.h"
18 #include "nds32_edm.h"
19 
20 #define NDS32_EDM_OPERATION_MAX_NUM 64
21 
22 #define CHECK_RETVAL(action) \
23  do { \
24  int __retval = (action); \
25  if (__retval != ERROR_OK) { \
26  LOG_DEBUG("error while calling \"%s\"", \
27  # action); \
28  return __retval; \
29  } \
30  } while (0)
31 
37 extern const char *nds32_debug_type_name[11];
38 
51 };
52 
53 #define NDS32_STRUCT_STAT_SIZE 60
54 #define NDS32_STRUCT_TIMEVAL_SIZE 8
55 
72 };
73 
74 #define NDS32_COMMON_MAGIC 0xADE5ADE5U
75 
76 struct nds32_edm {
77 
79  int version;
80 
83 
87 
90 
93 };
94 
95 struct nds32_cache {
96 
98  bool enable;
99 
101  int set;
102 
104  int way;
105 
108 
111 };
112 
113 struct nds32_memory {
114 
116  struct nds32_cache icache;
117 
119  struct nds32_cache dcache;
120 
122  int ilm_base;
123 
125  int ilm_size;
126 
129 
132 
135 
137  int ilm_end;
138 
140  int dlm_base;
141 
143  int dlm_size;
144 
147 
150 
153 
155  int dlm_end;
156 
159 
161  enum nds_memory_select mode;
162 
165 };
166 
173 
174  int revision;
177 };
178 
183  int tlb_size;
184  int tlb_ways;
185  int tlb_sets;
188  bool tlb_lock;
193  bool vlpt;
194  bool ntme;
195  bool drde;
198 };
199 
201  bool edm;
209  bool l2_cache;
211  bool addr_24;
217  bool ifc;
218  bool mcu;
219  bool ex9;
220  int shadow;
221 };
222 
226 struct nds32 {
227  unsigned int common_magic;
228 
230 
232  struct nds32_edm edm;
233 
235  struct nds32_memory memory;
236 
239 
242 
245 
247  int (*full_context)(struct nds32 *nds32);
248 
250  int (*register_map)(struct nds32 *nds32, int reg_no);
251 
253  int (*get_debug_reason)(struct nds32 *nds32, uint32_t *reason);
254 
256  int (*leave_debug_state)(struct nds32 *nds32, bool enable_watchpoint);
257 
259  int (*enter_debug_state)(struct nds32 *nds32, bool enable_watchpoint);
260 
262  int (*get_watched_address)(struct nds32 *nds32, uint32_t *address, uint32_t reason);
263 
266 
269 
270  uint32_t watched_address;
271 
274 
277 
280 
283 
286 
287  struct breakpoint syscall_break;
288 
291 
294 
297 
301 
302  /* Value of $EDM_CTL before target enters debug mode */
303  uint32_t backup_edm_ctl;
304 
307 
310 
313 
315  uint32_t boot_time;
316 
319 
322 
325 
328 
329  /* Andes Core has mixed endian model. Instruction is always big-endian.
330  * Data may be big or little endian. Device registers may have different
331  * endian from data and instruction. */
334 
337 
341 
342  /* Flag to indicate the target is attached by debugger or not */
343  bool attached;
344 
346  struct target *target;
347 
348  void *arch_info;
349 };
350 
351 struct nds32_reg {
352  int32_t num;
353  uint8_t value[8];
354  struct target *target;
355  struct nds32 *nds32;
356  bool enable;
357 };
358 
360  uint32_t reg_no;
361  uint32_t value;
362 };
363 
364 extern int nds32_config(struct nds32 *nds32);
365 extern int nds32_init_arch_info(struct target *target, struct nds32 *nds32);
366 extern int nds32_full_context(struct nds32 *nds32);
367 extern int nds32_arch_state(struct target *target);
368 extern int nds32_add_software_breakpoint(struct target *target,
369  struct breakpoint *breakpoint);
371  struct breakpoint *breakpoint);
372 
373 extern int nds32_get_gdb_reg_list(struct target *target,
374  struct reg **reg_list[], int *reg_list_size,
375  enum target_register_class reg_class);
376 
377 extern int nds32_write_buffer(struct target *target, uint32_t address,
378  uint32_t size, const uint8_t *buffer);
379 extern int nds32_read_buffer(struct target *target, uint32_t address,
380  uint32_t size, uint8_t *buffer);
381 extern int nds32_read_memory(struct target *target, uint32_t address,
382  uint32_t size, uint32_t count, uint8_t *buffer);
383 extern int nds32_write_memory(struct target *target, uint32_t address,
384  uint32_t size, uint32_t count, const uint8_t *buffer);
385 
386 extern int nds32_init_register_table(struct nds32 *nds32);
387 extern int nds32_init_memory_info(struct nds32 *nds32);
388 extern int nds32_restore_context(struct target *target);
389 extern int nds32_get_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t *value);
390 extern int nds32_set_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t value);
391 
392 extern int nds32_edm_config(struct nds32 *nds32);
393 extern int nds32_cache_sync(struct target *target, target_addr_t address, uint32_t length);
394 extern int nds32_mmu(struct target *target, int *enabled);
395 extern int nds32_virtual_to_physical(struct target *target, target_addr_t address,
396  target_addr_t *physical);
397 extern int nds32_read_phys_memory(struct target *target, target_addr_t address,
398  uint32_t size, uint32_t count, uint8_t *buffer);
399 extern int nds32_write_phys_memory(struct target *target, target_addr_t address,
400  uint32_t size, uint32_t count, const uint8_t *buffer);
401 extern uint32_t nds32_nextpc(struct nds32 *nds32, int current, uint32_t address);
402 extern int nds32_examine_debug_reason(struct nds32 *nds32);
403 extern int nds32_step(struct target *target, int current,
404  target_addr_t address, int handle_breakpoints);
405 extern int nds32_target_state(struct nds32 *nds32, enum target_state *state);
406 extern int nds32_halt(struct target *target);
407 extern int nds32_poll(struct target *target);
408 extern int nds32_resume(struct target *target, int current,
409  target_addr_t address, int handle_breakpoints, int debug_execution);
410 extern int nds32_assert_reset(struct target *target);
411 extern int nds32_init(struct nds32 *nds32);
412 extern int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info);
413 extern int nds32_gdb_fileio_write_memory(struct nds32 *nds32, uint32_t address,
414  uint32_t size, const uint8_t *buffer);
415 extern int nds32_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c);
416 extern int nds32_reset_halt(struct nds32 *nds32);
417 extern int nds32_login(struct nds32 *nds32);
418 extern int nds32_profiling(struct target *target, uint32_t *samples,
419  uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds);
420 
422 static inline struct nds32 *target_to_nds32(struct target *target)
423 {
424  assert(target);
425  return target->arch_info;
426 }
427 
429 static inline struct aice_port_s *target_to_aice(struct target *target)
430 {
431  assert(target);
432  return target->tap->priv;
433 }
434 
435 static inline bool is_nds32(struct nds32 *nds32)
436 {
437  assert(nds32);
439 }
440 
441 static inline bool nds32_reach_max_interrupt_level(struct nds32 *nds32)
442 {
443  assert(nds32);
445 }
446 
447 #endif /* OPENOCD_TARGET_NDS32_H */
uint8_t length
Definition: esp_usb_jtag.c:1
The JTAG interface can be implemented with a software or hardware fifo.
int nds32_examine_debug_reason(struct nds32 *nds32)
Definition: nds32.c:1888
int nds32_poll(struct target *target)
Definition: nds32.c:2061
int nds32_config(struct nds32 *nds32)
Definition: nds32.c:1593
int nds32_full_context(struct nds32 *nds32)
Definition: nds32.c:494
static struct nds32 * target_to_nds32(struct target *target)
Convert target handle to generic Andes target state handle.
Definition: nds32.h:422
int nds32_mmu(struct target *target, int *enabled)
Definition: nds32.c:945
int nds32_halt(struct target *target)
Definition: nds32.c:2031
int nds32_gdb_fileio_end(struct target *target, int retcode, int fileio_errno, bool ctrl_c)
Definition: nds32.c:2458
int nds32_read_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: nds32.c:804
static bool is_nds32(struct nds32 *nds32)
Definition: nds32.h:435
int nds32_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class)
get all register list
Definition: nds32.c:596
int nds32_arch_state(struct target *target)
Definition: nds32.c:964
int nds32_init_memory_info(struct nds32 *nds32)
int nds32_get_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t *value)
Definition: nds32.c:513
nds32_syscall_id
Definition: nds32.h:56
@ NDS32_SYSCALL_UNLINK
Definition: nds32.h:64
@ NDS32_SYSCALL_UNDEFINED
Definition: nds32.h:57
@ NDS32_SYSCALL_FSTAT
Definition: nds32.h:66
@ NDS32_SYSCALL_RENAME
Definition: nds32.h:65
@ NDS32_SYSCALL_EXIT
Definition: nds32.h:58
@ NDS32_SYSCALL_OPEN
Definition: nds32.h:59
@ NDS32_SYSCALL_STAT
Definition: nds32.h:67
@ NDS32_SYSCALL_SYSTEM
Definition: nds32.h:70
@ NDS32_SYSCALL_CLOSE
Definition: nds32.h:60
@ NDS32_SYSCALL_LSEEK
Definition: nds32.h:63
@ NDS32_SYSCALL_GETTIMEOFDAY
Definition: nds32.h:68
@ NDS32_SYSCALL_WRITE
Definition: nds32.h:62
@ NDS32_SYSCALL_ISATTY
Definition: nds32.h:69
@ NDS32_SYSCALL_ERRNO
Definition: nds32.h:71
@ NDS32_SYSCALL_READ
Definition: nds32.h:61
int nds32_restore_context(struct target *target)
Restore the processor context on an Andes target.
Definition: nds32.c:1510
int nds32_get_gdb_fileio_info(struct target *target, struct gdb_fileio_info *fileio_info)
Definition: nds32.c:2297
int nds32_edm_config(struct nds32 *nds32)
Definition: nds32.c:1554
int nds32_target_state(struct nds32 *nds32, enum target_state *state)
Definition: nds32.c:1851
int nds32_step(struct target *target, int current, target_addr_t address, int handle_breakpoints)
Definition: nds32.c:1750
int nds32_cache_sync(struct target *target, target_addr_t address, uint32_t length)
Definition: nds32.c:1680
#define NDS32_COMMON_MAGIC
Definition: nds32.h:74
int nds32_write_memory(struct target *target, uint32_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: nds32.c:913
const char * nds32_debug_type_name[11]
Definition: nds32.c:22
int nds32_read_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer)
Definition: nds32.c:812
int nds32_add_software_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: nds32.c:1431
int nds32_profiling(struct target *target, uint32_t *samples, uint32_t max_num_samples, uint32_t *num_samples, uint32_t seconds)
Definition: nds32.c:2474
int nds32_virtual_to_physical(struct target *target, target_addr_t address, target_addr_t *physical)
Definition: nds32.c:1662
int nds32_gdb_fileio_write_memory(struct nds32 *nds32, uint32_t address, uint32_t size, const uint8_t *buffer)
Definition: nds32.c:2499
int nds32_login(struct nds32 *nds32)
Definition: nds32.c:1969
int nds32_write_phys_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, const uint8_t *buffer)
Definition: nds32.c:921
uint32_t nds32_nextpc(struct nds32 *nds32, int current, uint32_t address)
Definition: nds32.c:1740
static bool nds32_reach_max_interrupt_level(struct nds32 *nds32)
Definition: nds32.h:441
int nds32_resume(struct target *target, int current, target_addr_t address, int handle_breakpoints, int debug_execution)
Definition: nds32.c:2104
int nds32_init_arch_info(struct target *target, struct nds32 *nds32)
Definition: nds32.c:1620
int nds32_init_register_table(struct nds32 *nds32)
Definition: nds32.c:1424
nds32_debug_reason
Definition: nds32.h:39
@ NDS32_DEBUG_BREAK
Definition: nds32.h:40
@ NDS32_DEBUG_DATA_ADDR_WATCHPOINT_PRECISE
Definition: nds32.h:43
@ NDS32_DEBUG_DATA_ADDR_WATCHPOINT_NEXT_PRECISE
Definition: nds32.h:48
@ NDS32_DEBUG_LOAD_STORE_GLOBAL_STOP
Definition: nds32.h:50
@ NDS32_DEBUG_DATA_VALUE_WATCHPOINT_PRECISE
Definition: nds32.h:44
@ NDS32_DEBUG_DATA_VALUE_WATCHPOINT_NEXT_PRECISE
Definition: nds32.h:49
@ NDS32_DEBUG_HARDWARE_SINGLE_STEP
Definition: nds32.h:47
@ NDS32_DEBUG_BREAK_16
Definition: nds32.h:41
@ NDS32_DEBUG_DATA_VALUE_WATCHPOINT_IMPRECISE
Definition: nds32.h:45
@ NDS32_DEBUG_INST_BREAK
Definition: nds32.h:42
@ NDS32_DEBUG_DEBUG_INTERRUPT
Definition: nds32.h:46
int nds32_set_mapped_reg(struct nds32 *nds32, unsigned regnum, uint32_t value)
set register internally
Definition: nds32.c:532
int nds32_assert_reset(struct target *target)
Definition: nds32.c:2176
static struct aice_port_s * target_to_aice(struct target *target)
Definition: nds32.h:429
int nds32_remove_software_breakpoint(struct target *target, struct breakpoint *breakpoint)
Definition: nds32.c:1469
int nds32_read_buffer(struct target *target, uint32_t address, uint32_t size, uint8_t *buffer)
Definition: nds32.c:713
int nds32_write_buffer(struct target *target, uint32_t address, uint32_t size, const uint8_t *buffer)
Definition: nds32.c:836
int nds32_reset_halt(struct nds32 *nds32)
Definition: nds32.c:2605
int nds32_init(struct nds32 *nds32)
Definition: nds32.c:2285
This is the interface to the Embedded Debug Module for Andes cores.
nds_memory_select
Definition: nds32_edm.h:87
nds_memory_access
Definition: nds32_edm.h:82
size_t size
Size of the control block search area.
Definition: rtt/rtt.c:30
void * priv
Definition: jtag.h:139
bool lock_support
cache locking support
Definition: nds32.h:110
int line_size
cache line size
Definition: nds32.h:107
int set
cache sets per way
Definition: nds32.h:101
bool enable
enable cache or not
Definition: nds32.h:98
int way
cache ways
Definition: nds32.h:104
bool performance_extension
Definition: nds32.h:168
int cpu_id_version
Definition: nds32.h:176
int cpu_id_family
Definition: nds32.h:175
bool performance_extension_2
Definition: nds32.h:170
bool string_extension
Definition: nds32.h:172
bool _16bit_extension
Definition: nds32.h:169
bool cop_fpu_extension
Definition: nds32.h:171
uint32_t reg_no
Definition: nds32.h:360
uint32_t value
Definition: nds32.h:361
bool direct_access_local_memory
EDM_CFG.DALM, indicate if direct local memory access feature is supported or not.
Definition: nds32.h:86
bool support_max_stop
Definition: nds32.h:92
int breakpoint_num
The number of hardware breakpoints.
Definition: nds32.h:82
bool access_control
Support ACC_CTL register.
Definition: nds32.h:89
int version
EDM_CFG.VER, indicate the EDM version.
Definition: nds32.h:79
int ilm_size
On-chip instruction local memory size.
Definition: nds32.h:125
int dlm_size
On-chip data local memory size.
Definition: nds32.h:143
enum nds_memory_access access_channel
Memory access method.
Definition: nds32.h:158
int dlm_base
On-chip data local memory base.
Definition: nds32.h:140
int dlm_start
DLM start address.
Definition: nds32.h:152
bool address_translation
Address translation.
Definition: nds32.h:164
int dlm_end
DLM end address.
Definition: nds32.h:155
int ilm_base
On-chip instruction local memory base.
Definition: nds32.h:122
struct nds32_cache dcache
DCache.
Definition: nds32.h:119
struct nds32_cache icache
ICache.
Definition: nds32.h:116
bool ilm_enable
DLM is enabled or not.
Definition: nds32.h:131
enum nds_memory_select mode
Memory access mode.
Definition: nds32.h:161
int dlm_align_ver
DLM base register alignment version.
Definition: nds32.h:146
int ilm_end
DLM end address.
Definition: nds32.h:137
int ilm_align_ver
ILM base register alignment version.
Definition: nds32.h:128
int ilm_start
DLM start address.
Definition: nds32.h:134
bool dlm_enable
DLM is enabled or not.
Definition: nds32.h:149
bool interruption_level
Definition: nds32.h:212
bool local_memory_dma
Definition: nds32.h:202
int baseline_instruction
Definition: nds32.h:213
bool debug_tracer
Definition: nds32.h:205
bool no_dx_register
Definition: nds32.h:214
bool high_speed_memory_port
Definition: nds32.h:204
bool mac_instruction
Definition: nds32.h:207
bool implement_dependant_register
Definition: nds32.h:215
bool reduce_register
Definition: nds32.h:210
bool performance_monitor
Definition: nds32.h:203
bool div_instruction
Definition: nds32.h:206
bool implement_dependant_sr_encoding
Definition: nds32.h:216
int default_min_page_size
Definition: nds32.h:196
bool tlb_lock
Definition: nds32.h:188
bool hardware_page_table_walker
Definition: nds32.h:189
bool _8k_page_support
Definition: nds32.h:186
int partition_num
Definition: nds32.h:191
bool multiple_page_size_in_use
Definition: nds32.h:197
bool invisible_tlb
Definition: nds32.h:192
bool fully_associative_tlb
Definition: nds32.h:182
int memory_protection
Definition: nds32.h:180
int extra_page_size_support
Definition: nds32.h:187
int memory_protection_version
Definition: nds32.h:181
bool default_endian
Definition: nds32.h:190
struct nds32 * nds32
Definition: nds32.h:355
int32_t num
Definition: nds32.h:352
bool enable
Definition: nds32.h:356
uint8_t value[8]
Definition: nds32.h:353
struct target * target
Definition: nds32.h:354
Represents a generic Andes core.
Definition: nds32.h:226
bool init_arch_info_after_halted
Flag to indicate register table is ready or not.
Definition: nds32.h:321
int virtual_hosting_errno
Value to be returned by virtual hosting SYS_ERRNO request.
Definition: nds32.h:279
struct target * target
Backpointer to the target.
Definition: nds32.h:346
bool auto_convert_hw_bp
Flag to indicate if auto convert software breakpoints to hardware breakpoints or not in ROM.
Definition: nds32.h:340
bool fpu_enable
Flag to indicate fpu-extension is enabled or not.
Definition: nds32.h:327
void * arch_info
Definition: nds32.h:348
int privilege_level
current privilege_level if using secure MCU.
Definition: nds32.h:312
uint32_t boot_time
Period to wait after SRST.
Definition: nds32.h:315
int(* register_map)(struct nds32 *nds32, int reg_no)
Register mappings.
Definition: nds32.h:250
bool reset_halt_as_examine
reset-halt as target examine
Definition: nds32.h:296
bool keep_target_edm_ctl
backup/restore target EDM_CTL value.
Definition: nds32.h:300
bool word_access_mem
always use word-aligned address to access memory
Definition: nds32.h:306
struct nds32_memory memory
Memory information.
Definition: nds32.h:235
bool hit_syscall
Flag reporting whether continue/step hits syscall or not.
Definition: nds32.h:276
bool global_stop
Flag reporting whether global stop is active.
Definition: nds32.h:290
bool soft_reset_halt
Flag reporting whether to use soft-reset-halt or not as issuing reset-halt.
Definition: nds32.h:293
bool audio_enable
Flag to indicate audio-extension is enabled or not.
Definition: nds32.h:324
enum target_endianness device_reg_endian
Endian of device registers.
Definition: nds32.h:336
char * edm_passcode
EDM passcode for debugging secure MCU.
Definition: nds32.h:309
struct nds32_edm edm
Handle for the debug module.
Definition: nds32.h:232
bool virtual_hosting
Flag reporting whether virtual hosting is active.
Definition: nds32.h:273
struct nds32_cpu_version cpu_version
cpu version
Definition: nds32.h:238
unsigned int common_magic
Definition: nds32.h:227
uint32_t max_interrupt_level
maximum interrupt level
Definition: nds32.h:265
uint32_t backup_edm_ctl
Definition: nds32.h:303
struct nds32_mmu_config mmu_config
MMU configuration.
Definition: nds32.h:241
bool attached
Definition: nds32.h:343
uint32_t watched_address
Definition: nds32.h:270
enum target_endianness data_endian
Endian of data memory.
Definition: nds32.h:333
struct reg_cache * core_cache
Definition: nds32.h:229
int(* leave_debug_state)(struct nds32 *nds32, bool enable_watchpoint)
Restore target registers may be modified in debug state.
Definition: nds32.h:256
int(* full_context)(struct nds32 *nds32)
Retrieve all core registers, for display.
Definition: nds32.h:247
int active_syscall_id
Record syscall ID for other operations to do special processing for target.
Definition: nds32.h:285
int(* get_debug_reason)(struct nds32 *nds32, uint32_t *reason)
Get debug exception virtual address.
Definition: nds32.h:253
int(* get_watched_address)(struct nds32 *nds32, uint32_t *address, uint32_t reason)
Get address hit watchpoint.
Definition: nds32.h:262
bool virtual_hosting_ctrl_c
Flag reporting whether syscall is aborted.
Definition: nds32.h:282
uint32_t current_interrupt_level
current interrupt level
Definition: nds32.h:268
struct nds32_misc_config misc_config
Misc configuration.
Definition: nds32.h:244
struct breakpoint syscall_break
Definition: nds32.h:287
bool step_isr_enable
Flag to indicate HSS steps into ISR or not.
Definition: nds32.h:318
int(* enter_debug_state)(struct nds32 *nds32, bool enable_watchpoint)
Backup target registers may be modified in debug state.
Definition: nds32.h:259
Definition: register.h:111
Definition: target.h:120
struct jtag_tap * tap
Definition: target.h:124
void * arch_info
Definition: target.h:169
target_register_class
Definition: target.h:114
target_state
Definition: target.h:52
target_endianness
Definition: target.h:84
uint64_t target_addr_t
Definition: types.h:335
uint8_t state[4]
Definition: vdebug.c:21
uint8_t count[4]
Definition: vdebug.c:22