flash/nor/at91samd: Use 32-bit register writes for ST-Link compat
[fw/openocd] / src / target / esirisc.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4  *   Copyright (C) 2018 by Square, Inc.                                    *
5  *   Steven Stallion <stallion@squareup.com>                               *
6  *   James Zhao <hjz@squareup.com>                                         *
7  ***************************************************************************/
8
9 #ifndef OPENOCD_TARGET_ESIRISC_H
10 #define OPENOCD_TARGET_ESIRISC_H
11
12 #include <helper/types.h>
13 #include <target/breakpoints.h>
14 #include <target/register.h>
15 #include <target/target.h>
16
17 #include "esirisc_jtag.h"
18 #include "esirisc_regs.h"
19 #include "esirisc_trace.h"
20
21 #define MAX_BREAKPOINTS                 8
22 #define MAX_WATCHPOINTS                 8
23
24 /* Exception IDs */
25 #define EID_RESET                               0x00
26 #define EID_HARDWARE_FAILURE    0x01
27 #define EID_NMI                                 0x02
28 #define EID_INST_BREAKPOINT             0x03
29 #define EID_DATA_BREAKPOINT             0x04
30 #define EID_UNSUPPORTED                 0x05
31 #define EID_PRIVILEGE_VIOLATION 0x06
32 #define EID_INST_BUS_ERROR              0x07
33 #define EID_DATA_BUS_ERROR              0x08
34 #define EID_ALIGNMENT_ERROR             0x09
35 #define EID_ARITHMETIC_ERROR    0x0a
36 #define EID_SYSTEM_CALL                 0x0b
37 #define EID_MEMORY_MANAGEMENT   0x0c
38 #define EID_UNRECOVERABLE               0x0d
39 #define EID_INTERRUPT_N                 0x20
40
41 /* Exception Entry Points */
42 #define ENTRY_RESET                             0x00
43 #define ENTRY_UNRECOVERABLE             0x01
44 #define ENTRY_HARDWARE_FAILURE  0x02
45 #define ENTRY_RUNTIME                   0x03
46 #define ENTRY_MEMORY                    0x04
47 #define ENTRY_SYSCALL                   0x05
48 #define ENTRY_DEBUG                             0x06
49 #define ENTRY_NMI                               0x07
50 #define ENTRY_INTERRUPT_N               0x08
51
52 /* Hardware Debug Control */
53 #define HWDC_R                                  (1<<4)  /* Reset & Hardware Failure */
54 #define HWDC_I                                  (1<<3)  /* Interrupts */
55 #define HWDC_S                                  (1<<2)  /* System Calls */
56 #define HWDC_E                                  (1<<1)  /* Program Errors */
57 #define HWDC_D                                  (1<<0)  /* Debug Exceptions */
58
59 enum esirisc_cache {
60         ESIRISC_CACHE_VON_NEUMANN,
61         ESIRISC_CACHE_HARVARD,
62 };
63
64 struct esirisc_common {
65         struct target *target;
66         struct esirisc_jtag jtag_info;
67         enum esirisc_cache cache_arch;
68         char *gdb_arch;
69
70         struct reg_cache *reg_cache;
71         struct reg *epc;
72         struct reg *ecas;
73         struct reg *eid;
74         struct reg *ed;
75         uint32_t etc_save;
76         uint32_t hwdc_save;
77
78         int num_bits;
79         int num_regs;
80         bool has_icache;
81         bool has_dcache;
82         bool has_trace;
83
84         int num_breakpoints;
85         struct breakpoint *breakpoints_p[MAX_BREAKPOINTS];
86
87         int num_watchpoints;
88         struct watchpoint *watchpoints_p[MAX_WATCHPOINTS];
89
90         struct esirisc_trace trace_info;
91 };
92
93 union esirisc_memory {
94         uint32_t word;
95         uint16_t hword;
96         uint8_t byte;
97 };
98
99 struct esirisc_reg {
100         struct esirisc_common *esirisc;
101
102         uint8_t bank;
103         uint8_t csr;
104
105         int (*read)(struct reg *reg);
106         int (*write)(struct reg *reg);
107 };
108
109 static inline struct esirisc_common *target_to_esirisc(struct target *target)
110 {
111         return (struct esirisc_common *)target->arch_info;
112 }
113
114 static inline char *esirisc_cache_arch_name(struct esirisc_common *esirisc)
115 {
116         return esirisc->cache_arch == ESIRISC_CACHE_HARVARD ? "harvard" : "von_neumann";
117 }
118
119 static inline bool esirisc_has_cache(struct esirisc_common *esirisc)
120 {
121         return esirisc->has_icache || esirisc->has_dcache;
122 }
123
124 #endif /* OPENOCD_TARGET_ESIRISC_H */