mips: add breakpoint support for EJTAG 2.0
[openocd.git] / src / target / mips_ejtag.h
blobdb20e9d0dfdf31f3f80eb24d19b542d35d6c2a13
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, write to the *
19 * Free Software Foundation, Inc., *
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
21 ***************************************************************************/
23 #ifndef MIPS_EJTAG
24 #define MIPS_EJTAG
26 #include <jtag/jtag.h>
28 /* tap instructions */
29 #define EJTAG_INST_IDCODE 0x01
30 #define EJTAG_INST_IMPCODE 0x03
31 #define EJTAG_INST_ADDRESS 0x08
32 #define EJTAG_INST_DATA 0x09
33 #define EJTAG_INST_CONTROL 0x0A
34 #define EJTAG_INST_ALL 0x0B
35 #define EJTAG_INST_EJTAGBOOT 0x0C
36 #define EJTAG_INST_NORMALBOOT 0x0D
37 #define EJTAG_INST_FASTDATA 0x0E
38 #define EJTAG_INST_TCBCONTROLA 0x10
39 #define EJTAG_INST_TCBCONTROLB 0x11
40 #define EJTAG_INST_TCBDATA 0x12
41 #define EJTAG_INST_BYPASS 0xFF
43 /* microchip PIC32MX specific instructions */
44 #define MTAP_SW_MTAP 0x04
45 #define MTAP_SW_ETAP 0x05
46 #define MTAP_COMMAND 0x07
48 /* microchip specific cmds */
49 #define MCHP_ASERT_RST 0xd1
50 #define MCHP_DE_ASSERT_RST 0xd0
51 #define MCHP_ERASE 0xfc
52 #define MCHP_STATUS 0x00
54 /* ejtag control register bits ECR */
55 #define EJTAG_CTRL_TOF (1 << 1)
56 #define EJTAG_CTRL_TIF (1 << 2)
57 #define EJTAG_CTRL_BRKST (1 << 3)
58 #define EJTAG_CTRL_DLOCK (1 << 5)
59 #define EJTAG_CTRL_DRWN (1 << 9)
60 #define EJTAG_CTRL_DERR (1 << 10)
61 #define EJTAG_CTRL_DSTRT (1 << 11)
62 #define EJTAG_CTRL_JTAGBRK (1 << 12)
63 #define EJTAG_CTRL_SETDEV (1 << 14)
64 #define EJTAG_CTRL_PROBEN (1 << 15)
65 #define EJTAG_CTRL_PRRST (1 << 16)
66 #define EJTAG_CTRL_DMAACC (1 << 17)
67 #define EJTAG_CTRL_PRACC (1 << 18)
68 #define EJTAG_CTRL_PRNW (1 << 19)
69 #define EJTAG_CTRL_PERRST (1 << 20)
70 #define EJTAG_CTRL_SYNC (1 << 23)
71 #define EJTAG_CTRL_DNM (1 << 28)
72 #define EJTAG_CTRL_ROCC (1 << 31)
74 /* Debug Register (CP0 Register 23, Select 0) */
76 #define EJTAG_DEBUG_DSS (1 << 0)
77 #define EJTAG_DEBUG_DBP (1 << 1)
78 #define EJTAG_DEBUG_DDBL (1 << 2)
79 #define EJTAG_DEBUG_DDBS (1 << 3)
80 #define EJTAG_DEBUG_DIB (1 << 4)
81 #define EJTAG_DEBUG_DINT (1 << 5)
82 #define EJTAG_DEBUG_OFFLINE (1 << 7)
83 #define EJTAG_DEBUG_SST (1 << 8)
84 #define EJTAG_DEBUG_NOSST (1 << 9)
85 #define EJTAG_DEBUG_DDBLIMPR (1 << 18)
86 #define EJTAG_DEBUG_DDBSIMPR (1 << 19)
87 #define EJTAG_DEBUG_IEXI (1 << 20)
88 #define EJTAG_DEBUG_DBUSEP (1 << 21)
89 #define EJTAG_DEBUG_CACHEEP (1 << 22)
90 #define EJTAG_DEBUG_MCHECKP (1 << 23)
91 #define EJTAG_DEBUG_IBUSEP (1 << 24)
92 #define EJTAG_DEBUG_COUNTDM (1 << 25)
93 #define EJTAG_DEBUG_HALT (1 << 26)
94 #define EJTAG_DEBUG_DOZE (1 << 27)
95 #define EJTAG_DEBUG_LSNM (1 << 28)
96 #define EJTAG_DEBUG_NODCR (1 << 29)
97 #define EJTAG_DEBUG_DM (1 << 30)
98 #define EJTAG_DEBUG_DBD (1 << 31)
100 /* implementaion register bits */
101 #define EJTAG_IMP_R3K (1 << 28)
102 #define EJTAG_IMP_DINT (1 << 24)
103 #define EJTAG_IMP_NODMA (1 << 14)
104 #define EJTAG_IMP_MIPS16 (1 << 16)
105 #define EJTAG_DCR_MIPS64 (1 << 0)
107 /* Debug Control Register DCR */
108 #define EJTAG_DCR 0xFF300000
109 #define EJTAG_DCR_ENM (1 << 29)
110 #define EJTAG_DCR_DB (1 << 17)
111 #define EJTAG_DCR_IB (1 << 16)
112 #define EJTAG_DCR_INTE (1 << 4)
113 #define EJTAG_DCR_MP (1 << 2)
115 /* breakpoint support */
116 /* EJTAG_V20_* was tested on Broadcom BCM7401
117 * and may or will differ with other hardware. For example EZ4021-FC. */
118 #define EJTAG_V20_IBS 0xFF300004
119 #define EJTAG_V20_IBA0 0xFF300100
120 #define EJTAG_V20_IBC_OFFS 0x4 /* IBC Offset */
121 #define EJTAG_V20_IBM_OFFS 0x8
122 #define EJTAG_V20_IBAn_STEP 0x10 /* Offset for next channel */
123 #define EJTAG_V20_DBS 0xFF30008
124 #define EJTAG_V20_DBA0 0xFF300200
125 #define EJTAG_V20_DBC_OFFS 0x4
126 #define EJTAG_V20_DBM_OFFS 0x8
127 #define EJTAG_V20_DBV_OFFS 0xc
128 #define EJTAG_V20_DBAn_STEP 0x10
130 #define EJTAG_V25_IBS 0xFF301000
131 #define EJTAG_V25_IBA0 0xFF301100
132 #define EJTAG_V25_IBM_OFFS 0x8
133 #define EJTAG_V25_IBASID_OFFS 0x10
134 #define EJTAG_V25_IBC_OFFS 0x18
135 #define EJTAG_V25_IBAn_STEP 0x100
136 #define EJTAG_V25_DBS 0xFF302000
137 #define EJTAG_V25_DBA0 0xFF302100
138 #define EJTAG_V25_DBM_OFFS 0x8
139 #define EJTAG_V25_DBASID_OFFS 0x10
140 #define EJTAG_V25_DBC_OFFS 0x18
141 #define EJTAG_V25_DBV_OFFS 0x20
142 #define EJTAG_V25_DBAn_STEP 0x100
144 #define EJTAG_DBCn_NOSB (1 << 13)
145 #define EJTAG_DBCn_NOLB (1 << 12)
146 #define EJTAG_DBCn_BLM_MASK 0xff
147 #define EJTAG_DBCn_BLM_SHIFT 4
148 #define EJTAG_DBCn_BE (1 << 0)
150 #define EJTAG_VERSION_20 0
151 #define EJTAG_VERSION_25 1
152 #define EJTAG_VERSION_26 2
153 #define EJTAG_VERSION_31 3
154 #define EJTAG_VERSION_41 4
155 #define EJTAG_VERSION_51 5
157 struct mips_ejtag {
158 struct jtag_tap *tap;
159 uint32_t impcode;
160 uint32_t idcode;
161 uint32_t ejtag_ctrl;
162 int fast_access_save;
163 uint32_t reg8;
164 uint32_t reg9;
165 unsigned scan_delay;
166 int mode;
167 unsigned int ejtag_version;
169 /* Memory-Mapped Registers. This addresses are not same on different
170 * EJTAG versions. */
171 uint32_t ejtag_ibs_addr; /* Instruction Address Break Status */
172 uint32_t ejtag_iba0_addr; /* IAB channel 0 */
173 uint32_t ejtag_ibc_offs; /* IAB Control offset */
174 uint32_t ejtag_ibm_offs; /* IAB Mask offset */
175 uint32_t ejtag_ibasid_offs; /* IAB ASID (4Kc) */
177 uint32_t ejtag_dbs_addr; /* Data Address Break Status Register */
178 uint32_t ejtag_dba0_addr; /* DAB channel 0 */
179 uint32_t ejtag_dbc_offs; /* DAB Control offset */
180 uint32_t ejtag_dbm_offs; /* DAB Mask offset */
181 uint32_t ejtag_dbv_offs; /* DAB Value offset */
182 uint32_t ejtag_dbasid_offs; /* DAB ASID (4Kc) */
184 uint32_t ejtag_iba_step_size;
185 uint32_t ejtag_dba_step_size; /* siez of step till next
186 * *DBAn register. */
189 void mips_ejtag_set_instr(struct mips_ejtag *ejtag_info,
190 int new_instr);
191 int mips_ejtag_enter_debug(struct mips_ejtag *ejtag_info);
192 int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info);
193 int mips_ejtag_get_idcode(struct mips_ejtag *ejtag_info, uint32_t *idcode);
194 void mips_ejtag_add_scan_96(struct mips_ejtag *ejtag_info,
195 uint32_t ctrl, uint32_t data, uint8_t *in_scan_buf);
196 void mips_ejtag_drscan_32_out(struct mips_ejtag *ejtag_info, uint32_t data);
197 int mips_ejtag_drscan_32(struct mips_ejtag *ejtag_info, uint32_t *data);
198 void mips_ejtag_drscan_8_out(struct mips_ejtag *ejtag_info, uint8_t data);
199 int mips_ejtag_drscan_8(struct mips_ejtag *ejtag_info, uint32_t *data);
200 int mips_ejtag_fastdata_scan(struct mips_ejtag *ejtag_info, int write_t, uint32_t *data);
202 int mips_ejtag_init(struct mips_ejtag *ejtag_info);
203 int mips_ejtag_config_step(struct mips_ejtag *ejtag_info, int enable_step);
205 static inline void mips_le_to_h_u32(jtag_callback_data_t arg)
207 uint8_t *in = (uint8_t *)arg;
208 *((uint32_t *)arg) = le_to_h_u32(in);
211 #endif /* MIPS_EJTAG */