1 /***************************************************************************
2 * Copyright (C) 2018 by Square, Inc. *
3 * Steven Stallion <stallion@squareup.com> *
4 * James Zhao <hjz@squareup.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
20 #ifndef OPENOCD_TARGET_ESIRISC_H
21 #define OPENOCD_TARGET_ESIRISC_H
23 #include <helper/types.h>
24 #include <target/breakpoints.h>
25 #include <target/register.h>
26 #include <target/target.h>
28 #include "esirisc_jtag.h"
29 #include "esirisc_regs.h"
30 #include "esirisc_trace.h"
32 #define MAX_BREAKPOINTS 8
33 #define MAX_WATCHPOINTS 8
36 #define EID_RESET 0x00
37 #define EID_HARDWARE_FAILURE 0x01
39 #define EID_INST_BREAKPOINT 0x03
40 #define EID_DATA_BREAKPOINT 0x04
41 #define EID_UNSUPPORTED 0x05
42 #define EID_PRIVILEGE_VIOLATION 0x06
43 #define EID_INST_BUS_ERROR 0x07
44 #define EID_DATA_BUS_ERROR 0x08
45 #define EID_ALIGNMENT_ERROR 0x09
46 #define EID_ARITHMETIC_ERROR 0x0a
47 #define EID_SYSTEM_CALL 0x0b
48 #define EID_MEMORY_MANAGEMENT 0x0c
49 #define EID_UNRECOVERABLE 0x0d
50 #define EID_INTERRUPTn 0x20
52 /* Exception Entry Points */
53 #define ENTRY_RESET 0x00
54 #define ENTRY_UNRECOVERABLE 0x01
55 #define ENTRY_HARDWARE_FAILURE 0x02
56 #define ENTRY_RUNTIME 0x03
57 #define ENTRY_MEMORY 0x04
58 #define ENTRY_SYSCALL 0x05
59 #define ENTRY_DEBUG 0x06
60 #define ENTRY_NMI 0x07
61 #define ENTRY_INTERRUPTn 0x08
63 /* Hardware Debug Control */
64 #define HWDC_R (1<<4) /* Reset & Hardware Failure */
65 #define HWDC_I (1<<3) /* Interrupts */
66 #define HWDC_S (1<<2) /* System Calls */
67 #define HWDC_E (1<<1) /* Program Errors */
68 #define HWDC_D (1<<0) /* Debug Exceptions */
71 ESIRISC_CACHE_VON_NEUMANN,
72 ESIRISC_CACHE_HARVARD,
75 struct esirisc_common {
76 struct target *target;
77 struct esirisc_jtag jtag_info;
78 enum esirisc_cache cache_arch;
81 struct reg_cache *reg_cache;
96 struct breakpoint *breakpoints_p[MAX_BREAKPOINTS];
99 struct watchpoint *watchpoints_p[MAX_WATCHPOINTS];
101 struct esirisc_trace trace_info;
104 union esirisc_memory {
111 struct esirisc_common *esirisc;
116 int (*read)(struct reg *reg);
117 int (*write)(struct reg *reg);
120 static inline struct esirisc_common *target_to_esirisc(struct target *target)
122 return (struct esirisc_common *)target->arch_info;
125 static inline char *esirisc_cache_arch_name(struct esirisc_common *esirisc)
127 return esirisc->cache_arch == ESIRISC_CACHE_HARVARD ? "harvard" : "von_neumann";
130 static inline bool esirisc_has_cache(struct esirisc_common *esirisc)
132 return esirisc->has_icache || esirisc->has_dcache;
135 #endif /* OPENOCD_TARGET_ESIRISC_H */