adi_v5: Remove unused features of the DAP and SWD interfaces
[openocd.git] / src / target / x86_32_common.h
1 /*
2 * Copyright(c) 2013 Intel Corporation.
3 *
4 * Adrian Burns (adrian.burns@intel.com)
5 * Thomas Faust (thomas.faust@intel.com)
6 * Ivan De Cesaris (ivan.de.cesaris@intel.com)
7 * Julien Carreno (julien.carreno@intel.com)
8 * Jeffrey Maxwell (jeffrey.r.maxwell@intel.com)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 * Contact Information:
24 * Intel Corporation
25 */
26
27 /*
28 * @file
29 * This is the interface to the x86 32 bit memory and breakpoint operations.
30 */
31
32 #ifndef X86_32_COMMON_H
33 #define X86_32_COMMON_H
34
35 #include <jtag/jtag.h>
36 #include <helper/command.h>
37 #include <helper/types.h>
38
39 extern const struct command_registration x86_32_command_handlers[];
40
41 /* for memory access */
42 #define BYTE 1
43 #define WORD 2
44 #define DWORD 4
45
46 #define EFLAGS_TF ((uint32_t)0x00000100) /* Trap Flag */
47 #define EFLAGS_IF ((uint32_t)0x00000200) /* Interrupt Flag */
48 #define EFLAGS_RF ((uint32_t)0x00010000) /* Resume Flag */
49 #define EFLAGS_VM86 ((uint32_t)0x00020000) /* Virtual 8086 Mode */
50
51 #define CSAR_DPL ((uint32_t)0x00006000)
52 #define CSAR_D ((uint32_t)0x00400000)
53 #define SSAR_DPL ((uint32_t)0x00006000)
54
55 #define CR0_PE ((uint32_t)0x00000001) /* Protected Mode Enable */
56 #define CR0_NW ((uint32_t)0x20000000) /* Non Write-Through */
57 #define CR0_CD ((uint32_t)0x40000000) /* Cache Disable */
58 #define CR0_PG ((uint32_t)0x80000000) /* Paging Enable */
59
60 /* TODO - move back to PM specific file */
61 #define PM_DR6 ((uint32_t)0xFFFF0FF0)
62
63 #define DR6_BRKDETECT_0 ((uint32_t)0x00000001) /* B0 through B3 */
64 #define DR6_BRKDETECT_1 ((uint32_t)0x00000002) /* breakpoint condition detected */
65 #define DR6_BRKDETECT_2 ((uint32_t)0x00000004)
66 #define DR6_BRKDETECT_3 ((uint32_t)0x00000008)
67
68 enum {
69 /* general purpose registers */
70 EAX = 0,
71 ECX,
72 EDX,
73 EBX,
74 ESP,
75 EBP,
76 ESI,
77 EDI,
78 /* instruction pointer & flags */
79 EIP,
80 EFLAGS,
81
82 /* segment registers */
83 CS,
84 SS,
85 DS,
86 ES,
87 FS,
88 GS,
89
90 /* floating point unit registers */
91 ST0,
92 ST1,
93 ST2,
94 ST3,
95 ST4,
96 ST5,
97 ST6,
98 ST7,
99 FCTRL,
100 FSTAT,
101 FTAG,
102 FISEG,
103 FIOFF,
104 FOSEG,
105 FOOFF,
106 FOP,
107
108 /* control registers */
109 CR0,
110 CR2,
111 CR3,
112 CR4,
113
114 /* debug registers */
115 DR0,
116 DR1,
117 DR2,
118 DR3,
119 DR6,
120 DR7,
121
122 /* descriptor tables */
123 IDTB,
124 IDTL,
125 IDTAR,
126 GDTB,
127 GDTL,
128 GDTAR,
129 TR,
130 LDTR,
131 LDTB,
132 LDTL,
133 LDTAR,
134
135 /* segment registers */
136 CSB,
137 CSL,
138 CSAR,
139 DSB,
140 DSL,
141 DSAR,
142 ESB,
143 ESL,
144 ESAR,
145 FSB,
146 FSL,
147 FSAR,
148 GSB,
149 GSL,
150 GSAR,
151 SSB,
152 SSL,
153 SSAR,
154 TSSB,
155 TSSL,
156 TSSAR,
157
158 /* PM control reg */
159 PMCR,
160 };
161
162 #define X86_32_COMMON_MAGIC 0x86328632
163
164 enum {
165 /* memory read/write */
166 MEMRDB32 = 0,
167 MEMRDB16,
168 MEMRDH32,
169 MEMRDH16,
170 MEMRDW32,
171 MEMRDW16,
172 MEMWRB32,
173 MEMWRB16,
174 MEMWRH32,
175 MEMWRH16,
176 MEMWRW32,
177 MEMWRW16,
178 /* IO read/write */
179 IORDB32,
180 IORDB16,
181 IORDH32,
182 IORDH16,
183 IORDW32,
184 IORDW16,
185 IOWRB32,
186 IOWRB16,
187 IOWRH32,
188 IOWRH16,
189 IOWRW32,
190 IOWRW16,
191 /* lakemont1 core shadow ram access opcodes */
192 SRAMACCESS,
193 SRAM2PDR,
194 PDR2SRAM,
195 WBINVD,
196 };
197
198 struct swbp_mem_patch {
199 uint8_t orig_byte;
200 uint32_t swbp_unique_id;
201 uint32_t physaddr;
202 struct swbp_mem_patch *next;
203 };
204
205 /* TODO - probemode specific - consider removing */
206 #define NUM_PM_REGS 18 /* regs used in save/restore */
207
208 struct x86_32_common {
209 uint32_t common_magic;
210 void *arch_info;
211 struct reg_cache *cache;
212 struct jtag_tap *curr_tap;
213 uint32_t stored_pc;
214 int flush;
215
216 /* pm_regs are for probemode save/restore state */
217 uint32_t pm_regs[NUM_PM_REGS];
218
219 /* working area for fastdata access */
220 struct working_area *fast_data_area;
221
222 int num_hw_bpoints;
223 struct x86_32_dbg_reg *hw_break_list;
224 struct swbp_mem_patch *swbbp_mem_patch_list;
225
226 /* core probemode implementation dependent functions */
227 uint8_t (*get_num_user_regs)(struct target *t);
228 bool (*is_paging_enabled)(struct target *t);
229 int (*disable_paging)(struct target *t);
230 int (*enable_paging)(struct target *t);
231 bool (*sw_bpts_supported)(struct target *t);
232 int (*transaction_status)(struct target *t);
233 int (*submit_instruction)(struct target *t, int num);
234 int (*read_hw_reg)(struct target *t, int reg, uint32_t *regval, uint8_t cache);
235 int (*write_hw_reg)(struct target *t, int reg,
236 uint32_t regval, uint8_t cache);
237
238 /* register cache to processor synchronization */
239 int (*read_hw_reg_to_cache)(struct target *target, int num);
240 int (*write_hw_reg_from_cache)(struct target *target, int num);
241 };
242
243 static inline struct x86_32_common *
244 target_to_x86_32(struct target *target)
245 {
246 return target->arch_info;
247 }
248 bool check_not_halted(const struct target *t);
249
250 /* breakpoint defines */
251 #define MAX_DEBUG_REGS 4
252 #define SW_BP_OPCODE 0xf1
253 #define MAX_SW_BPTS 20
254
255 struct x86_32_dbg_reg {
256 int used;
257 uint32_t bp_value;
258 };
259
260 #define DR7_G_ENABLE_SHIFT 1
261 #define DR7_ENABLE_SIZE 2 /* 2 bits per debug reg */
262 #define DR7_RW_SHIFT 16
263 #define DR7_LENGTH_SHIFT 18
264 #define DR7_RW_LEN_SIZE 4
265 #define DR7_BP_EXECUTE 0 /* 00 - only on instruction execution*/
266 #define DR7_BP_WRITE 1 /* 01 - only on data writes */
267 /*#define DR7_RW_IORW 2 UNSUPPORTED 10 - an I/O read and I/O write */
268 #define DR7_BP_READWRITE 3 /* on data read or data write */
269 #define DR7_BP_LENGTH_1 0 /* 00 - 1 byte length */
270 #define DR7_BP_LENGTH_2 1 /* 01 - 2 byte length */
271 #define DR7_BP_LENGTH_4 3 /* 11 - 4 byte length */
272
273 #define DR7_GLOBAL_ENABLE(val, regnum) \
274 (val |= (1 << (DR7_G_ENABLE_SHIFT + (DR7_ENABLE_SIZE * (regnum)))))
275
276 #define DR7_GLOBAL_DISABLE(val, regnum) \
277 (val &= ~(3 << (DR7_ENABLE_SIZE * (regnum))))
278
279 #define DR7_BP_FREE(val, regnum) \
280 ((val & (3 << (DR7_ENABLE_SIZE * (regnum)))) == 0)
281
282 #define DR7_RESET_RWLEN_BITS(val, regnum) \
283 (val &= ~(0x0f << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
284
285 #define DR7_SET_EXE(val, regnum) \
286 (val &= ~(0x0f << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
287
288 #define DR7_SET_WRITE(val, regnum) \
289 (val |= (DR7_BP_WRITE << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
290
291 #define DR7_SET_ACCESS(val, regnum) \
292 (val |= (DR7_BP_READWRITE << (DR7_RW_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
293
294 #define DR7_SET_LENGTH(val, regnum, len) \
295 (val |= (len == 1) ? (DR7_BP_LENGTH_1 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))) : \
296 (len == 2) ? (DR7_BP_LENGTH_2 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))) : \
297 (DR7_BP_LENGTH_4 << (DR7_LENGTH_SHIFT + DR7_RW_LEN_SIZE * (regnum))))
298
299 /* public interface */
300 int x86_32_get_gdb_reg_list(struct target *t,
301 struct reg **reg_list[], int *reg_list_size,
302 enum target_register_class reg_class);
303 int x86_32_common_init_arch_info(struct target *target,
304 struct x86_32_common *x86_32);
305 int x86_32_common_mmu(struct target *t, int *enabled);
306 int x86_32_common_virt2phys(struct target *t, uint32_t address, uint32_t *physical);
307 int x86_32_common_read_phys_mem(struct target *t, uint32_t phys_address,
308 uint32_t size, uint32_t count, uint8_t *buffer);
309 int x86_32_common_write_phys_mem(struct target *t, uint32_t phys_address,
310 uint32_t size, uint32_t count, const uint8_t *buffer);
311 int x86_32_common_read_memory(struct target *t, uint32_t addr,
312 uint32_t size, uint32_t count, uint8_t *buf);
313 int x86_32_common_write_memory(struct target *t, uint32_t addr,
314 uint32_t size, uint32_t count, const uint8_t *buf);
315 int x86_32_common_read_io(struct target *t, uint32_t addr,
316 uint32_t size, uint8_t *buf);
317 int x86_32_common_write_io(struct target *t, uint32_t addr,
318 uint32_t size, const uint8_t *buf);
319 int x86_32_common_add_breakpoint(struct target *t, struct breakpoint *bp);
320 int x86_32_common_remove_breakpoint(struct target *t, struct breakpoint *bp);
321 int x86_32_common_add_watchpoint(struct target *t, struct watchpoint *wp);
322 int x86_32_common_remove_watchpoint(struct target *t, struct watchpoint *wp);
323
324 #endif /* X86_32_COMMON_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)