mips32: add micromips isa handling
[openocd.git] / src / target / mips_ejtag.h
1 /***************************************************************************
2 * Copyright (C) 2008 by Spencer Oliver *
3 * spen@spen-soft.co.uk *
4 * *
5 * Copyright (C) 2008 by David T.L. Wong *
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 ***************************************************************************/
20
21 #ifndef OPENOCD_TARGET_MIPS_EJTAG_H
22 #define OPENOCD_TARGET_MIPS_EJTAG_H
23
24 #include <jtag/jtag.h>
25
26 /* tap instructions */
27 #define EJTAG_INST_IDCODE 0x01
28 #define EJTAG_INST_IMPCODE 0x03
29 #define EJTAG_INST_ADDRESS 0x08
30 #define EJTAG_INST_DATA 0x09
31 #define EJTAG_INST_CONTROL 0x0A
32 #define EJTAG_INST_ALL 0x0B
33 #define EJTAG_INST_EJTAGBOOT 0x0C
34 #define EJTAG_INST_NORMALBOOT 0x0D
35 #define EJTAG_INST_FASTDATA 0x0E
36 #define EJTAG_INST_TCBCONTROLA 0x10
37 #define EJTAG_INST_TCBCONTROLB 0x11
38 #define EJTAG_INST_TCBDATA 0x12
39 #define EJTAG_INST_BYPASS 0xFF
40
41 /* microchip PIC32MX specific instructions */
42 #define MTAP_SW_MTAP 0x04
43 #define MTAP_SW_ETAP 0x05
44 #define MTAP_COMMAND 0x07
45
46 /* microchip specific cmds */
47 #define MCHP_ASERT_RST 0xd1
48 #define MCHP_DE_ASSERT_RST 0xd0
49 #define MCHP_ERASE 0xfc
50 #define MCHP_STATUS 0x00
51
52 /* ejtag control register bits ECR */
53 #define EJTAG_CTRL_TOF (1 << 1)
54 #define EJTAG_CTRL_TIF (1 << 2)
55 #define EJTAG_CTRL_BRKST (1 << 3)
56 #define EJTAG_CTRL_DLOCK (1 << 5)
57 #define EJTAG_CTRL_DRWN (1 << 9)
58 #define EJTAG_CTRL_DERR (1 << 10)
59 #define EJTAG_CTRL_DSTRT (1 << 11)
60 #define EJTAG_CTRL_JTAGBRK (1 << 12)
61 #define EJTAG_CTRL_DBGISA (1 << 13)
62 #define EJTAG_CTRL_SETDEV (1 << 14)
63 #define EJTAG_CTRL_PROBEN (1 << 15)
64 #define EJTAG_CTRL_PRRST (1 << 16)
65 #define EJTAG_CTRL_DMAACC (1 << 17)
66 #define EJTAG_CTRL_PRACC (1 << 18)
67 #define EJTAG_CTRL_PRNW (1 << 19)
68 #define EJTAG_CTRL_PERRST (1 << 20)
69 #define EJTAG_CTRL_SYNC (1 << 23)
70 #define EJTAG_CTRL_DNM (1 << 28)
71 #define EJTAG_CTRL_ROCC (1 << 31)
72
73 /* Debug Register (CP0 Register 23, Select 0) */
74
75 #define EJTAG_DEBUG_DSS (1 << 0)
76 #define EJTAG_DEBUG_DBP (1 << 1)
77 #define EJTAG_DEBUG_DDBL (1 << 2)
78 #define EJTAG_DEBUG_DDBS (1 << 3)
79 #define EJTAG_DEBUG_DIB (1 << 4)
80 #define EJTAG_DEBUG_DINT (1 << 5)
81 #define EJTAG_DEBUG_OFFLINE (1 << 7)
82 #define EJTAG_DEBUG_SST (1 << 8)
83 #define EJTAG_DEBUG_NOSST (1 << 9)
84 #define EJTAG_DEBUG_DDBLIMPR (1 << 18)
85 #define EJTAG_DEBUG_DDBSIMPR (1 << 19)
86 #define EJTAG_DEBUG_IEXI (1 << 20)
87 #define EJTAG_DEBUG_DBUSEP (1 << 21)
88 #define EJTAG_DEBUG_CACHEEP (1 << 22)
89 #define EJTAG_DEBUG_MCHECKP (1 << 23)
90 #define EJTAG_DEBUG_IBUSEP (1 << 24)
91 #define EJTAG_DEBUG_COUNTDM (1 << 25)
92 #define EJTAG_DEBUG_HALT (1 << 26)
93 #define EJTAG_DEBUG_DOZE (1 << 27)
94 #define EJTAG_DEBUG_LSNM (1 << 28)
95 #define EJTAG_DEBUG_NODCR (1 << 29)
96 #define EJTAG_DEBUG_DM (1 << 30)
97 #define EJTAG_DEBUG_DBD (1 << 31)
98
99 /* implementation MIPS register bits.
100 * Bits marked with V20 or v2.0 mean that, this registers supported only
101 * by EJTAG v2.0. Bits marked with Lexra or BMIPS are different from the
102 * official EJATG.
103 * NOTE: Lexra or BMIPS use EJTAG v2.0 */
104
105 #define EJTAG_IMP_HAS(x) (ejtag_info->impcode & (x))
106 /* v2.0(Lexra) 29 - 1’b1 - Lexra Internal Trace Buffer implemented. This bit
107 * overlaps with version bit of MIPS EJTAG specification. */
108 #define EJTAG_V26_IMP_R3K (1 << 28)
109 /* v2.0 - 24:25 - 2’b00- No profiling support */
110 #define EJTAG_V26_IMP_DINT (1 << 24)
111 #define EJTAG_V20_IMP_SDBBP (1 << 23) /* 1’b1 - sdbbp is Special2 Opcode */
112 #define EJTAG_IMP_ASID8 (1 << 22)
113 #define EJTAG_IMP_ASID6 (1 << 21)
114 #define EJTAG_V20_IMP_COMPLEX_BREAK (1 << 20) /* Complex Breaks supported*/
115 #define EJTAG_V20_IMP_EADDR_NO32BIT (1 << 19) /* EJTAG_ADDR > 32 bits wide */
116 #define EJTAG_V20_IMP_DCACHE_COH (1 << 18) /* DCache does keep DMA coherent */
117 #define EJTAG_V20_IMP_ICACHE_COH (1 << 17) /* DCache does keep DMA coherent */
118 #define EJTAG_IMP_MIPS16 (1 << 16)
119 #define EJTAG_IMP_NODMA (1 << 14)
120 /* v2.0 - 11:13 external PC trace. Trace PC Width. */
121 /* v2.0 - 8:10 external PC trace. PCST Width and DCLK Division Factor */
122 #define EJTAG_V20_IMP_NOPB (1 << 7) /* no processor breaks */
123 #define EJTAG_V20_IMP_NODB (1 << 6) /* no data breaks */
124 #define EJTAG_V20_IMP_NOIB (1 << 5) /* no instruction breaks implemented */
125 /* v2.0 - 1:4 Number of Break Channels. */
126 #define EJTAG_V20_IMP_BCHANNELS_MASK 0xf
127 #define EJTAG_V20_IMP_BCHANNELS_SHIFT 1
128 #define EJTAG_DCR_MIPS64 (1 << 0)
129
130 /* Debug Control Register DCR */
131 #define EJTAG_DCR 0xFF300000
132 #define EJTAG_DCR_ENM (1 << 29)
133 #define EJTAG_DCR_DB (1 << 17)
134 #define EJTAG_DCR_IB (1 << 16)
135 #define EJTAG_DCR_INTE (1 << 4)
136 #define EJTAG_DCR_MP (1 << 2)
137
138 /* breakpoint support */
139 /* EJTAG_V20_* was tested on Broadcom BCM7401
140 * and may or will differ with other hardware. For example EZ4021-FC. */
141 #define EJTAG_V20_IBS 0xFF300004
142 #define EJTAG_V20_IBA0 0xFF300100
143 #define EJTAG_V20_IBC_OFFS 0x4 /* IBC Offset */
144 #define EJTAG_V20_IBM_OFFS 0x8
145 #define EJTAG_V20_IBAn_STEP 0x10 /* Offset for next channel */
146 #define EJTAG_V20_DBS 0xFF300008
147 #define EJTAG_V20_DBA0 0xFF300200
148 #define EJTAG_V20_DBC_OFFS 0x4
149 #define EJTAG_V20_DBM_OFFS 0x8
150 #define EJTAG_V20_DBV_OFFS 0xc
151 #define EJTAG_V20_DBAn_STEP 0x10
152
153 #define EJTAG_V25_IBS 0xFF301000
154 #define EJTAG_V25_IBA0 0xFF301100
155 #define EJTAG_V25_IBM_OFFS 0x8
156 #define EJTAG_V25_IBASID_OFFS 0x10
157 #define EJTAG_V25_IBC_OFFS 0x18
158 #define EJTAG_V25_IBAn_STEP 0x100
159 #define EJTAG_V25_DBS 0xFF302000
160 #define EJTAG_V25_DBA0 0xFF302100
161 #define EJTAG_V25_DBM_OFFS 0x8
162 #define EJTAG_V25_DBASID_OFFS 0x10
163 #define EJTAG_V25_DBC_OFFS 0x18
164 #define EJTAG_V25_DBV_OFFS 0x20
165 #define EJTAG_V25_DBAn_STEP 0x100
166
167 #define EJTAG_DBCn_NOSB (1 << 13)
168 #define EJTAG_DBCn_NOLB (1 << 12)
169 #define EJTAG_DBCn_BLM_MASK 0xff
170 #define EJTAG_DBCn_BLM_SHIFT 4
171 #define EJTAG_DBCn_BE (1 << 0)
172
173 #define EJTAG_VERSION_20 0
174 #define EJTAG_VERSION_25 1
175 #define EJTAG_VERSION_26 2
176 #define EJTAG_VERSION_31 3
177 #define EJTAG_VERSION_41 4
178 #define EJTAG_VERSION_51 5
179
180 struct mips_ejtag {
181 struct jtag_tap *tap;
182 uint32_t impcode;
183 uint32_t idcode;
184 uint32_t ejtag_ctrl;
185 int fast_access_save;
186 uint32_t config_regs; /* number of config registers read */
187 uint32_t config[4]; /* cp0 config to config3 */
188
189 uint32_t reg8;
190 uint32_t reg9;
191 unsigned scan_delay;
192 int mode;
193 uint32_t pa_ctrl;
194 uint32_t pa_addr;
195 unsigned int ejtag_version;
196 uint32_t isa;
197 uint32_t endianness;
198
199 /* Memory-Mapped Registers. This addresses are not same on different
200 * EJTAG versions. */
201 uint32_t debug_caps;
202 uint32_t ejtag_ibs_addr; /* Instruction Address Break Status */
203 uint32_t ejtag_iba0_addr; /* IAB channel 0 */
204 uint32_t ejtag_ibc_offs; /* IAB Control offset */
205 uint32_t ejtag_ibm_offs; /* IAB Mask offset */
206 uint32_t ejtag_ibasid_offs; /* IAB ASID (4Kc) */
207
208 uint32_t ejtag_dbs_addr; /* Data Address Break Status Register */
209 uint32_t ejtag_dba0_addr; /* DAB channel 0 */
210 uint32_t ejtag_dbc_offs; /* DAB Control offset */
211 uint32_t ejtag_dbm_offs; /* DAB Mask offset */
212 uint32_t ejtag_dbv_offs; /* DAB Value offset */
213 uint32_t ejtag_dbasid_offs; /* DAB ASID (4Kc) */
214
215 uint32_t ejtag_iba_step_size;
216 uint32_t ejtag_dba_step_size; /* size of step till next *DBAn register. */
217 };
218
219 void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info, uint32_t new_instr);
220 int mips_ejtag_enter_debug(struct mips_ejtag *ejtag_info);
221 int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info);
222 int mips_ejtag_get_idcode(struct mips_ejtag *ejtag_info, uint32_t *idcode);
223 void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info,
224 uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf);
225 void mips_ejtag_drscan_32_out(struct mips_ejtag *ejtag_info, uint32_t data);
226 int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data);
227 void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data);
228 int mips_ejtag_drscan_8(struct mips_ejtag *ejtag_info, uint8_t *data);
229 int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data);
230
231 int mips_ejtag_init(struct mips_ejtag *ejtag_info);
232 int mips_ejtag_config_step(struct mips_ejtag *ejtag_info, int enable_step);
233
234 static inline void mips_le_to_h_u32(jtag_callback_data_t arg)
235 {
236 uint8_t *in = (uint8_t *)arg;
237 *((uint32_t *)arg) = le_to_h_u32(in);
238 }
239
240 #endif /* OPENOCD_TARGET_MIPS_EJTAG_H */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)