Commit | Line | Data |
---|---|---|
29134980 | 1 | /* Target dependent code for CRIS, for GDB, the GNU debugger. |
6b4d5c91 | 2 | |
42a4f53d | 3 | Copyright (C) 2001-2019 Free Software Foundation, Inc. |
6b4d5c91 | 4 | |
29134980 OF |
5 | Contributed by Axis Communications AB. |
6 | Written by Hendrik Ruijter, Stefan Andersson, and Orjan Friberg. | |
7 | ||
a9762ec7 | 8 | This file is part of GDB. |
29134980 | 9 | |
a9762ec7 JB |
10 | This program is free software; you can redistribute it and/or modify |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 3 of the License, or | |
13 | (at your option) any later version. | |
29134980 | 14 | |
a9762ec7 JB |
15 | This program is distributed in the hope that it will be useful, |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
29134980 | 19 | |
a9762ec7 JB |
20 | You should have received a copy of the GNU General Public License |
21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
29134980 OF |
22 | |
23 | #include "defs.h" | |
24 | #include "frame.h" | |
2e4b5889 OF |
25 | #include "frame-unwind.h" |
26 | #include "frame-base.h" | |
27 | #include "trad-frame.h" | |
28 | #include "dwarf2-frame.h" | |
29134980 OF |
29 | #include "symtab.h" |
30 | #include "inferior.h" | |
31 | #include "gdbtypes.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "target.h" | |
35 | #include "value.h" | |
36 | #include "opcode/cris.h" | |
749c8b38 | 37 | #include "osabi.h" |
29134980 OF |
38 | #include "arch-utils.h" |
39 | #include "regcache.h" | |
40 | ||
9ab9195f | 41 | #include "objfiles.h" |
29134980 | 42 | |
a5f6c8f5 | 43 | #include "solib.h" /* Support for shared libraries. */ |
76a9d10f | 44 | #include "solib-svr4.h" |
a89aa300 | 45 | #include "dis-asm.h" |
dbbff683 | 46 | |
749c8b38 RW |
47 | #include "cris-tdep.h" |
48 | ||
29134980 OF |
49 | enum cris_num_regs |
50 | { | |
51 | /* There are no floating point registers. Used in gdbserver low-linux.c. */ | |
52 | NUM_FREGS = 0, | |
53 | ||
54 | /* There are 16 general registers. */ | |
55 | NUM_GENREGS = 16, | |
56 | ||
57 | /* There are 16 special registers. */ | |
c600d464 OF |
58 | NUM_SPECREGS = 16, |
59 | ||
60 | /* CRISv32 has a pseudo PC register, not noted here. */ | |
61 | ||
62 | /* CRISv32 has 16 support registers. */ | |
63 | NUM_SUPPREGS = 16 | |
29134980 OF |
64 | }; |
65 | ||
66 | /* Register numbers of various important registers. | |
2e4b5889 | 67 | CRIS_FP_REGNUM Contains address of executing stack frame. |
29134980 OF |
68 | STR_REGNUM Contains the address of structure return values. |
69 | RET_REGNUM Contains the return value when shorter than or equal to 32 bits | |
70 | ARG1_REGNUM Contains the first parameter to a function. | |
71 | ARG2_REGNUM Contains the second parameter to a function. | |
72 | ARG3_REGNUM Contains the third parameter to a function. | |
0963b4bd | 73 | ARG4_REGNUM Contains the fourth parameter to a function. Rest on stack. |
3e8c568d UW |
74 | gdbarch_sp_regnum Contains address of top of stack. |
75 | gdbarch_pc_regnum Contains address of next instruction. | |
29134980 OF |
76 | SRP_REGNUM Subroutine return pointer register. |
77 | BRP_REGNUM Breakpoint return pointer register. */ | |
78 | ||
29134980 OF |
79 | enum cris_regnums |
80 | { | |
81 | /* Enums with respect to the general registers, valid for all | |
c600d464 | 82 | CRIS versions. The frame pointer is always in R8. */ |
2e4b5889 | 83 | CRIS_FP_REGNUM = 8, |
c600d464 | 84 | /* ABI related registers. */ |
29134980 OF |
85 | STR_REGNUM = 9, |
86 | RET_REGNUM = 10, | |
87 | ARG1_REGNUM = 10, | |
88 | ARG2_REGNUM = 11, | |
89 | ARG3_REGNUM = 12, | |
90 | ARG4_REGNUM = 13, | |
91 | ||
c600d464 | 92 | /* Registers which happen to be common. */ |
29134980 | 93 | VR_REGNUM = 17, |
c600d464 OF |
94 | MOF_REGNUM = 23, |
95 | SRP_REGNUM = 27, | |
96 | ||
0963b4bd | 97 | /* CRISv10 et al. specific registers. */ |
c600d464 | 98 | P0_REGNUM = 16, |
29134980 OF |
99 | P4_REGNUM = 20, |
100 | CCR_REGNUM = 21, | |
29134980 OF |
101 | P8_REGNUM = 24, |
102 | IBR_REGNUM = 25, | |
103 | IRP_REGNUM = 26, | |
29134980 | 104 | BAR_REGNUM = 28, |
2a9ecef2 | 105 | DCCR_REGNUM = 29, |
29134980 | 106 | BRP_REGNUM = 30, |
c600d464 OF |
107 | USP_REGNUM = 31, |
108 | ||
109 | /* CRISv32 specific registers. */ | |
110 | ACR_REGNUM = 15, | |
111 | BZ_REGNUM = 16, | |
112 | PID_REGNUM = 18, | |
113 | SRS_REGNUM = 19, | |
114 | WZ_REGNUM = 20, | |
115 | EXS_REGNUM = 21, | |
116 | EDA_REGNUM = 22, | |
117 | DZ_REGNUM = 24, | |
118 | EBP_REGNUM = 25, | |
119 | ERP_REGNUM = 26, | |
120 | NRP_REGNUM = 28, | |
121 | CCS_REGNUM = 29, | |
122 | CRISV32USP_REGNUM = 30, /* Shares name but not number with CRISv10. */ | |
123 | SPC_REGNUM = 31, | |
124 | CRISV32PC_REGNUM = 32, /* Shares name but not number with CRISv10. */ | |
125 | ||
126 | S0_REGNUM = 33, | |
127 | S1_REGNUM = 34, | |
128 | S2_REGNUM = 35, | |
129 | S3_REGNUM = 36, | |
130 | S4_REGNUM = 37, | |
131 | S5_REGNUM = 38, | |
132 | S6_REGNUM = 39, | |
133 | S7_REGNUM = 40, | |
134 | S8_REGNUM = 41, | |
135 | S9_REGNUM = 42, | |
136 | S10_REGNUM = 43, | |
137 | S11_REGNUM = 44, | |
138 | S12_REGNUM = 45, | |
139 | S13_REGNUM = 46, | |
140 | S14_REGNUM = 47, | |
141 | S15_REGNUM = 48, | |
29134980 OF |
142 | }; |
143 | ||
144 | extern const struct cris_spec_reg cris_spec_regs[]; | |
145 | ||
146 | /* CRIS version, set via the user command 'set cris-version'. Affects | |
0e6bdb31 | 147 | register names and sizes. */ |
e4286e57 | 148 | static unsigned int usr_cmd_cris_version; |
29134980 OF |
149 | |
150 | /* Indicates whether to trust the above variable. */ | |
151 | static int usr_cmd_cris_version_valid = 0; | |
152 | ||
41922353 OF |
153 | static const char cris_mode_normal[] = "normal"; |
154 | static const char cris_mode_guru[] = "guru"; | |
40478521 | 155 | static const char *const cris_modes[] = { |
0e6bdb31 OF |
156 | cris_mode_normal, |
157 | cris_mode_guru, | |
158 | 0 | |
159 | }; | |
160 | ||
161 | /* CRIS mode, set via the user command 'set cris-mode'. Affects | |
162 | type of break instruction among other things. */ | |
163 | static const char *usr_cmd_cris_mode = cris_mode_normal; | |
164 | ||
a5f6c8f5 OF |
165 | /* Whether to make use of Dwarf-2 CFI (default on). */ |
166 | static int usr_cmd_cris_dwarf2_cfi = 1; | |
29134980 | 167 | |
a5f6c8f5 OF |
168 | /* Sigtramp identification code copied from i386-linux-tdep.c. */ |
169 | ||
170 | #define SIGTRAMP_INSN0 0x9c5f /* movu.w 0xXX, $r9 */ | |
171 | #define SIGTRAMP_OFFSET0 0 | |
172 | #define SIGTRAMP_INSN1 0xe93d /* break 13 */ | |
173 | #define SIGTRAMP_OFFSET1 4 | |
174 | ||
175 | static const unsigned short sigtramp_code[] = | |
176 | { | |
177 | SIGTRAMP_INSN0, 0x0077, /* movu.w $0x77, $r9 */ | |
178 | SIGTRAMP_INSN1 /* break 13 */ | |
179 | }; | |
180 | ||
181 | #define SIGTRAMP_LEN (sizeof sigtramp_code) | |
182 | ||
183 | /* Note: same length as normal sigtramp code. */ | |
184 | ||
185 | static const unsigned short rt_sigtramp_code[] = | |
29134980 | 186 | { |
a5f6c8f5 OF |
187 | SIGTRAMP_INSN0, 0x00ad, /* movu.w $0xad, $r9 */ |
188 | SIGTRAMP_INSN1 /* break 13 */ | |
189 | }; | |
190 | ||
191 | /* If PC is in a sigtramp routine, return the address of the start of | |
192 | the routine. Otherwise, return 0. */ | |
193 | ||
194 | static CORE_ADDR | |
94afd7a6 | 195 | cris_sigtramp_start (struct frame_info *this_frame) |
a5f6c8f5 | 196 | { |
94afd7a6 | 197 | CORE_ADDR pc = get_frame_pc (this_frame); |
e2a2a3e8 | 198 | gdb_byte buf[SIGTRAMP_LEN]; |
a5f6c8f5 | 199 | |
94afd7a6 | 200 | if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN)) |
a5f6c8f5 OF |
201 | return 0; |
202 | ||
e2a2a3e8 | 203 | if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0) |
a5f6c8f5 | 204 | { |
e2a2a3e8 | 205 | if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1) |
a5f6c8f5 OF |
206 | return 0; |
207 | ||
208 | pc -= SIGTRAMP_OFFSET1; | |
94afd7a6 | 209 | if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN)) |
a5f6c8f5 OF |
210 | return 0; |
211 | } | |
212 | ||
213 | if (memcmp (buf, sigtramp_code, SIGTRAMP_LEN) != 0) | |
214 | return 0; | |
215 | ||
216 | return pc; | |
217 | } | |
218 | ||
219 | /* If PC is in a RT sigtramp routine, return the address of the start of | |
220 | the routine. Otherwise, return 0. */ | |
221 | ||
222 | static CORE_ADDR | |
94afd7a6 | 223 | cris_rt_sigtramp_start (struct frame_info *this_frame) |
a5f6c8f5 | 224 | { |
94afd7a6 | 225 | CORE_ADDR pc = get_frame_pc (this_frame); |
e2a2a3e8 | 226 | gdb_byte buf[SIGTRAMP_LEN]; |
a5f6c8f5 | 227 | |
94afd7a6 | 228 | if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN)) |
a5f6c8f5 OF |
229 | return 0; |
230 | ||
e2a2a3e8 | 231 | if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN0) |
a5f6c8f5 | 232 | { |
e2a2a3e8 | 233 | if (((buf[1] << 8) + buf[0]) != SIGTRAMP_INSN1) |
a5f6c8f5 OF |
234 | return 0; |
235 | ||
236 | pc -= SIGTRAMP_OFFSET1; | |
94afd7a6 | 237 | if (!safe_frame_unwind_memory (this_frame, pc, buf, SIGTRAMP_LEN)) |
a5f6c8f5 OF |
238 | return 0; |
239 | } | |
240 | ||
241 | if (memcmp (buf, rt_sigtramp_code, SIGTRAMP_LEN) != 0) | |
242 | return 0; | |
243 | ||
244 | return pc; | |
245 | } | |
246 | ||
94afd7a6 UW |
247 | /* Assuming THIS_FRAME is a frame for a GNU/Linux sigtramp routine, |
248 | return the address of the associated sigcontext structure. */ | |
a5f6c8f5 OF |
249 | |
250 | static CORE_ADDR | |
94afd7a6 | 251 | cris_sigcontext_addr (struct frame_info *this_frame) |
a5f6c8f5 | 252 | { |
e17a4113 UW |
253 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
254 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
a5f6c8f5 OF |
255 | CORE_ADDR pc; |
256 | CORE_ADDR sp; | |
e362b510 | 257 | gdb_byte buf[4]; |
a5f6c8f5 | 258 | |
e17a4113 UW |
259 | get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf); |
260 | sp = extract_unsigned_integer (buf, 4, byte_order); | |
a5f6c8f5 OF |
261 | |
262 | /* Look for normal sigtramp frame first. */ | |
94afd7a6 | 263 | pc = cris_sigtramp_start (this_frame); |
a5f6c8f5 OF |
264 | if (pc) |
265 | { | |
266 | /* struct signal_frame (arch/cris/kernel/signal.c) contains | |
267 | struct sigcontext as its first member, meaning the SP points to | |
268 | it already. */ | |
269 | return sp; | |
270 | } | |
271 | ||
94afd7a6 | 272 | pc = cris_rt_sigtramp_start (this_frame); |
a5f6c8f5 OF |
273 | if (pc) |
274 | { | |
275 | /* struct rt_signal_frame (arch/cris/kernel/signal.c) contains | |
276 | a struct ucontext, which in turn contains a struct sigcontext. | |
277 | Magic digging: | |
278 | 4 + 4 + 128 to struct ucontext, then | |
279 | 4 + 4 + 12 to struct sigcontext. */ | |
280 | return (sp + 156); | |
281 | } | |
282 | ||
8a3fe4f8 | 283 | error (_("Couldn't recognize signal trampoline.")); |
a5f6c8f5 | 284 | return 0; |
29134980 OF |
285 | } |
286 | ||
2e4b5889 | 287 | struct cris_unwind_cache |
29134980 | 288 | { |
2e4b5889 OF |
289 | /* The previous frame's inner most stack address. Used as this |
290 | frame ID's stack_addr. */ | |
291 | CORE_ADDR prev_sp; | |
292 | /* The frame's base, optionally used by the high-level debug info. */ | |
293 | CORE_ADDR base; | |
294 | int size; | |
295 | /* How far the SP and r8 (FP) have been offset from the start of | |
296 | the stack frame (as defined by the previous frame's stack | |
297 | pointer). */ | |
298 | LONGEST sp_offset; | |
299 | LONGEST r8_offset; | |
300 | int uses_frame; | |
301 | ||
302 | /* From old frame_extra_info struct. */ | |
29134980 OF |
303 | CORE_ADDR return_pc; |
304 | int leaf_function; | |
2e4b5889 OF |
305 | |
306 | /* Table indicating the location of each and every register. */ | |
307 | struct trad_frame_saved_reg *saved_regs; | |
29134980 OF |
308 | }; |
309 | ||
a5f6c8f5 | 310 | static struct cris_unwind_cache * |
94afd7a6 | 311 | cris_sigtramp_frame_unwind_cache (struct frame_info *this_frame, |
a5f6c8f5 OF |
312 | void **this_cache) |
313 | { | |
94afd7a6 | 314 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
7fbe2eba | 315 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e17a4113 | 316 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
a5f6c8f5 | 317 | struct cris_unwind_cache *info; |
a5f6c8f5 | 318 | CORE_ADDR addr; |
e362b510 | 319 | gdb_byte buf[4]; |
a5f6c8f5 OF |
320 | int i; |
321 | ||
322 | if ((*this_cache)) | |
9a3c8263 | 323 | return (struct cris_unwind_cache *) (*this_cache); |
a5f6c8f5 OF |
324 | |
325 | info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache); | |
326 | (*this_cache) = info; | |
94afd7a6 | 327 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
a5f6c8f5 OF |
328 | |
329 | /* Zero all fields. */ | |
330 | info->prev_sp = 0; | |
331 | info->base = 0; | |
332 | info->size = 0; | |
333 | info->sp_offset = 0; | |
334 | info->r8_offset = 0; | |
335 | info->uses_frame = 0; | |
336 | info->return_pc = 0; | |
337 | info->leaf_function = 0; | |
338 | ||
94afd7a6 | 339 | get_frame_register (this_frame, gdbarch_sp_regnum (gdbarch), buf); |
e17a4113 | 340 | info->base = extract_unsigned_integer (buf, 4, byte_order); |
a5f6c8f5 | 341 | |
94afd7a6 | 342 | addr = cris_sigcontext_addr (this_frame); |
a5f6c8f5 OF |
343 | |
344 | /* Layout of the sigcontext struct: | |
345 | struct sigcontext { | |
346 | struct pt_regs regs; | |
347 | unsigned long oldmask; | |
348 | unsigned long usp; | |
349 | }; */ | |
350 | ||
c600d464 OF |
351 | if (tdep->cris_version == 10) |
352 | { | |
353 | /* R0 to R13 are stored in reverse order at offset (2 * 4) in | |
354 | struct pt_regs. */ | |
355 | for (i = 0; i <= 13; i++) | |
356 | info->saved_regs[i].addr = addr + ((15 - i) * 4); | |
357 | ||
358 | info->saved_regs[MOF_REGNUM].addr = addr + (16 * 4); | |
359 | info->saved_regs[DCCR_REGNUM].addr = addr + (17 * 4); | |
360 | info->saved_regs[SRP_REGNUM].addr = addr + (18 * 4); | |
361 | /* Note: IRP is off by 2 at this point. There's no point in correcting | |
362 | it though since that will mean that the backtrace will show a PC | |
363 | different from what is shown when stopped. */ | |
364 | info->saved_regs[IRP_REGNUM].addr = addr + (19 * 4); | |
7fbe2eba | 365 | info->saved_regs[gdbarch_pc_regnum (gdbarch)] |
3e8c568d | 366 | = info->saved_regs[IRP_REGNUM]; |
7fbe2eba | 367 | info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr = addr + (24 * 4); |
c600d464 OF |
368 | } |
369 | else | |
370 | { | |
371 | /* CRISv32. */ | |
372 | /* R0 to R13 are stored in order at offset (1 * 4) in | |
373 | struct pt_regs. */ | |
374 | for (i = 0; i <= 13; i++) | |
375 | info->saved_regs[i].addr = addr + ((i + 1) * 4); | |
376 | ||
377 | info->saved_regs[ACR_REGNUM].addr = addr + (15 * 4); | |
378 | info->saved_regs[SRS_REGNUM].addr = addr + (16 * 4); | |
379 | info->saved_regs[MOF_REGNUM].addr = addr + (17 * 4); | |
380 | info->saved_regs[SPC_REGNUM].addr = addr + (18 * 4); | |
381 | info->saved_regs[CCS_REGNUM].addr = addr + (19 * 4); | |
382 | info->saved_regs[SRP_REGNUM].addr = addr + (20 * 4); | |
383 | info->saved_regs[ERP_REGNUM].addr = addr + (21 * 4); | |
384 | info->saved_regs[EXS_REGNUM].addr = addr + (22 * 4); | |
385 | info->saved_regs[EDA_REGNUM].addr = addr + (23 * 4); | |
386 | ||
387 | /* FIXME: If ERP is in a delay slot at this point then the PC will | |
388 | be wrong at this point. This problem manifests itself in the | |
389 | sigaltstack.exp test case, which occasionally generates FAILs when | |
0963b4bd | 390 | the signal is received while in a delay slot. |
c600d464 OF |
391 | |
392 | This could be solved by a couple of read_memory_unsigned_integer and a | |
393 | trad_frame_set_value. */ | |
7fbe2eba | 394 | info->saved_regs[gdbarch_pc_regnum (gdbarch)] |
3e8c568d | 395 | = info->saved_regs[ERP_REGNUM]; |
c600d464 | 396 | |
7fbe2eba | 397 | info->saved_regs[gdbarch_sp_regnum (gdbarch)].addr |
3e8c568d | 398 | = addr + (25 * 4); |
c600d464 | 399 | } |
a5f6c8f5 OF |
400 | |
401 | return info; | |
402 | } | |
403 | ||
404 | static void | |
94afd7a6 | 405 | cris_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache, |
a5f6c8f5 OF |
406 | struct frame_id *this_id) |
407 | { | |
408 | struct cris_unwind_cache *cache = | |
94afd7a6 UW |
409 | cris_sigtramp_frame_unwind_cache (this_frame, this_cache); |
410 | (*this_id) = frame_id_build (cache->base, get_frame_pc (this_frame)); | |
a5f6c8f5 OF |
411 | } |
412 | ||
413 | /* Forward declaration. */ | |
414 | ||
94afd7a6 UW |
415 | static struct value *cris_frame_prev_register (struct frame_info *this_frame, |
416 | void **this_cache, int regnum); | |
417 | static struct value * | |
418 | cris_sigtramp_frame_prev_register (struct frame_info *this_frame, | |
419 | void **this_cache, int regnum) | |
a5f6c8f5 OF |
420 | { |
421 | /* Make sure we've initialized the cache. */ | |
94afd7a6 UW |
422 | cris_sigtramp_frame_unwind_cache (this_frame, this_cache); |
423 | return cris_frame_prev_register (this_frame, this_cache, regnum); | |
424 | } | |
425 | ||
426 | static int | |
427 | cris_sigtramp_frame_sniffer (const struct frame_unwind *self, | |
428 | struct frame_info *this_frame, | |
429 | void **this_cache) | |
430 | { | |
431 | if (cris_sigtramp_start (this_frame) | |
432 | || cris_rt_sigtramp_start (this_frame)) | |
433 | return 1; | |
434 | ||
435 | return 0; | |
a5f6c8f5 OF |
436 | } |
437 | ||
438 | static const struct frame_unwind cris_sigtramp_frame_unwind = | |
439 | { | |
440 | SIGTRAMP_FRAME, | |
8fbca658 | 441 | default_frame_unwind_stop_reason, |
a5f6c8f5 | 442 | cris_sigtramp_frame_this_id, |
94afd7a6 UW |
443 | cris_sigtramp_frame_prev_register, |
444 | NULL, | |
445 | cris_sigtramp_frame_sniffer | |
a5f6c8f5 OF |
446 | }; |
447 | ||
63807e1d | 448 | static int |
c600d464 OF |
449 | crisv32_single_step_through_delay (struct gdbarch *gdbarch, |
450 | struct frame_info *this_frame) | |
451 | { | |
7fbe2eba | 452 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
c600d464 OF |
453 | ULONGEST erp; |
454 | int ret = 0; | |
c600d464 | 455 | |
35488783 | 456 | if (tdep->cris_mode == cris_mode_guru) |
395f2fc2 | 457 | erp = get_frame_register_unsigned (this_frame, NRP_REGNUM); |
0e6bdb31 | 458 | else |
395f2fc2 | 459 | erp = get_frame_register_unsigned (this_frame, ERP_REGNUM); |
c600d464 OF |
460 | |
461 | if (erp & 0x1) | |
462 | { | |
463 | /* In delay slot - check if there's a breakpoint at the preceding | |
464 | instruction. */ | |
6c95b8df | 465 | if (breakpoint_here_p (get_frame_address_space (this_frame), erp & ~0x1)) |
c600d464 OF |
466 | ret = 1; |
467 | } | |
468 | return ret; | |
469 | } | |
470 | ||
29134980 | 471 | /* The instruction environment needed to find single-step breakpoints. */ |
c600d464 | 472 | |
29134980 OF |
473 | typedef |
474 | struct instruction_environment | |
475 | { | |
476 | unsigned long reg[NUM_GENREGS]; | |
477 | unsigned long preg[NUM_SPECREGS]; | |
478 | unsigned long branch_break_address; | |
479 | unsigned long delay_slot_pc; | |
480 | unsigned long prefix_value; | |
481 | int branch_found; | |
482 | int prefix_found; | |
483 | int invalid; | |
484 | int slot_needed; | |
485 | int delay_slot_pc_active; | |
486 | int xflag_found; | |
487 | int disable_interrupt; | |
78c5b882 | 488 | enum bfd_endian byte_order; |
29134980 OF |
489 | } inst_env_type; |
490 | ||
29134980 OF |
491 | /* Machine-dependencies in CRIS for opcodes. */ |
492 | ||
493 | /* Instruction sizes. */ | |
494 | enum cris_instruction_sizes | |
495 | { | |
496 | INST_BYTE_SIZE = 0, | |
497 | INST_WORD_SIZE = 1, | |
498 | INST_DWORD_SIZE = 2 | |
499 | }; | |
500 | ||
501 | /* Addressing modes. */ | |
502 | enum cris_addressing_modes | |
503 | { | |
504 | REGISTER_MODE = 1, | |
505 | INDIRECT_MODE = 2, | |
506 | AUTOINC_MODE = 3 | |
507 | }; | |
508 | ||
509 | /* Prefix addressing modes. */ | |
510 | enum cris_prefix_addressing_modes | |
511 | { | |
512 | PREFIX_INDEX_MODE = 2, | |
513 | PREFIX_ASSIGN_MODE = 3, | |
514 | ||
515 | /* Handle immediate byte offset addressing mode prefix format. */ | |
516 | PREFIX_OFFSET_MODE = 2 | |
517 | }; | |
518 | ||
519 | /* Masks for opcodes. */ | |
520 | enum cris_opcode_masks | |
521 | { | |
522 | BRANCH_SIGNED_SHORT_OFFSET_MASK = 0x1, | |
523 | SIGNED_EXTEND_BIT_MASK = 0x2, | |
524 | SIGNED_BYTE_MASK = 0x80, | |
525 | SIGNED_BYTE_EXTEND_MASK = 0xFFFFFF00, | |
526 | SIGNED_WORD_MASK = 0x8000, | |
527 | SIGNED_WORD_EXTEND_MASK = 0xFFFF0000, | |
528 | SIGNED_DWORD_MASK = 0x80000000, | |
529 | SIGNED_QUICK_VALUE_MASK = 0x20, | |
530 | SIGNED_QUICK_VALUE_EXTEND_MASK = 0xFFFFFFC0 | |
531 | }; | |
532 | ||
533 | /* Functions for opcodes. The general form of the ETRAX 16-bit instruction: | |
534 | Bit 15 - 12 Operand2 | |
535 | 11 - 10 Mode | |
536 | 9 - 6 Opcode | |
537 | 5 - 4 Size | |
538 | 3 - 0 Operand1 */ | |
539 | ||
540 | static int | |
541 | cris_get_operand2 (unsigned short insn) | |
542 | { | |
543 | return ((insn & 0xF000) >> 12); | |
544 | } | |
545 | ||
546 | static int | |
547 | cris_get_mode (unsigned short insn) | |
548 | { | |
549 | return ((insn & 0x0C00) >> 10); | |
550 | } | |
551 | ||
552 | static int | |
553 | cris_get_opcode (unsigned short insn) | |
554 | { | |
555 | return ((insn & 0x03C0) >> 6); | |
556 | } | |
557 | ||
558 | static int | |
559 | cris_get_size (unsigned short insn) | |
560 | { | |
561 | return ((insn & 0x0030) >> 4); | |
562 | } | |
563 | ||
564 | static int | |
565 | cris_get_operand1 (unsigned short insn) | |
566 | { | |
567 | return (insn & 0x000F); | |
568 | } | |
569 | ||
570 | /* Additional functions in order to handle opcodes. */ | |
571 | ||
29134980 OF |
572 | static int |
573 | cris_get_quick_value (unsigned short insn) | |
574 | { | |
575 | return (insn & 0x003F); | |
576 | } | |
577 | ||
578 | static int | |
579 | cris_get_bdap_quick_offset (unsigned short insn) | |
580 | { | |
581 | return (insn & 0x00FF); | |
582 | } | |
583 | ||
584 | static int | |
585 | cris_get_branch_short_offset (unsigned short insn) | |
586 | { | |
587 | return (insn & 0x00FF); | |
588 | } | |
589 | ||
590 | static int | |
591 | cris_get_asr_shift_steps (unsigned long value) | |
592 | { | |
593 | return (value & 0x3F); | |
594 | } | |
595 | ||
29134980 OF |
596 | static int |
597 | cris_get_clear_size (unsigned short insn) | |
598 | { | |
599 | return ((insn) & 0xC000); | |
600 | } | |
601 | ||
602 | static int | |
603 | cris_is_signed_extend_bit_on (unsigned short insn) | |
604 | { | |
605 | return (((insn) & 0x20) == 0x20); | |
606 | } | |
607 | ||
608 | static int | |
609 | cris_is_xflag_bit_on (unsigned short insn) | |
610 | { | |
611 | return (((insn) & 0x1000) == 0x1000); | |
612 | } | |
613 | ||
614 | static void | |
615 | cris_set_size_to_dword (unsigned short *insn) | |
616 | { | |
617 | *insn &= 0xFFCF; | |
618 | *insn |= 0x20; | |
619 | } | |
620 | ||
8535cb38 | 621 | static signed char |
29134980 OF |
622 | cris_get_signed_offset (unsigned short insn) |
623 | { | |
8535cb38 | 624 | return ((signed char) (insn & 0x00FF)); |
29134980 OF |
625 | } |
626 | ||
627 | /* Calls an op function given the op-type, working on the insn and the | |
628 | inst_env. */ | |
be8626e0 MD |
629 | static void cris_gdb_func (struct gdbarch *, enum cris_op_type, unsigned short, |
630 | inst_env_type *); | |
29134980 | 631 | |
29134980 OF |
632 | static struct gdbarch *cris_gdbarch_init (struct gdbarch_info, |
633 | struct gdbarch_list *); | |
634 | ||
29134980 OF |
635 | static void cris_dump_tdep (struct gdbarch *, struct ui_file *); |
636 | ||
eb4c3f4a | 637 | static void set_cris_version (const char *ignore_args, int from_tty, |
a5f6c8f5 | 638 | struct cmd_list_element *c); |
29134980 | 639 | |
eb4c3f4a | 640 | static void set_cris_mode (const char *ignore_args, int from_tty, |
0e6bdb31 OF |
641 | struct cmd_list_element *c); |
642 | ||
eb4c3f4a | 643 | static void set_cris_dwarf2_cfi (const char *ignore_args, int from_tty, |
a5f6c8f5 | 644 | struct cmd_list_element *c); |
29134980 | 645 | |
2e4b5889 | 646 | static CORE_ADDR cris_scan_prologue (CORE_ADDR pc, |
94afd7a6 | 647 | struct frame_info *this_frame, |
2e4b5889 OF |
648 | struct cris_unwind_cache *info); |
649 | ||
5114e29d | 650 | static CORE_ADDR crisv32_scan_prologue (CORE_ADDR pc, |
94afd7a6 | 651 | struct frame_info *this_frame, |
5114e29d OF |
652 | struct cris_unwind_cache *info); |
653 | ||
2e4b5889 | 654 | /* When arguments must be pushed onto the stack, they go on in reverse |
0963b4bd | 655 | order. The below implements a FILO (stack) to do this. |
a5f6c8f5 | 656 | Copied from d10v-tdep.c. */ |
2e4b5889 OF |
657 | |
658 | struct stack_item | |
659 | { | |
660 | int len; | |
661 | struct stack_item *prev; | |
7c543f7b | 662 | gdb_byte *data; |
2e4b5889 OF |
663 | }; |
664 | ||
665 | static struct stack_item * | |
948f8e3d | 666 | push_stack_item (struct stack_item *prev, const gdb_byte *contents, int len) |
2e4b5889 | 667 | { |
8d749320 | 668 | struct stack_item *si = XNEW (struct stack_item); |
7c543f7b | 669 | si->data = (gdb_byte *) xmalloc (len); |
2e4b5889 OF |
670 | si->len = len; |
671 | si->prev = prev; | |
672 | memcpy (si->data, contents, len); | |
673 | return si; | |
674 | } | |
675 | ||
676 | static struct stack_item * | |
677 | pop_stack_item (struct stack_item *si) | |
678 | { | |
679 | struct stack_item *dead = si; | |
680 | si = si->prev; | |
681 | xfree (dead->data); | |
682 | xfree (dead); | |
683 | return si; | |
684 | } | |
685 | ||
686 | /* Put here the code to store, into fi->saved_regs, the addresses of | |
687 | the saved registers of frame described by FRAME_INFO. This | |
688 | includes special registers such as pc and fp saved in special ways | |
689 | in the stack frame. sp is even more special: the address we return | |
a5f6c8f5 | 690 | for it IS the sp for the next frame. */ |
2e4b5889 | 691 | |
63807e1d | 692 | static struct cris_unwind_cache * |
94afd7a6 | 693 | cris_frame_unwind_cache (struct frame_info *this_frame, |
2e4b5889 OF |
694 | void **this_prologue_cache) |
695 | { | |
35488783 UW |
696 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
697 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
2e4b5889 | 698 | struct cris_unwind_cache *info; |
2e4b5889 OF |
699 | |
700 | if ((*this_prologue_cache)) | |
9a3c8263 | 701 | return (struct cris_unwind_cache *) (*this_prologue_cache); |
2e4b5889 OF |
702 | |
703 | info = FRAME_OBSTACK_ZALLOC (struct cris_unwind_cache); | |
704 | (*this_prologue_cache) = info; | |
94afd7a6 | 705 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
2e4b5889 OF |
706 | |
707 | /* Zero all fields. */ | |
708 | info->prev_sp = 0; | |
709 | info->base = 0; | |
710 | info->size = 0; | |
711 | info->sp_offset = 0; | |
712 | info->r8_offset = 0; | |
713 | info->uses_frame = 0; | |
714 | info->return_pc = 0; | |
715 | info->leaf_function = 0; | |
716 | ||
717 | /* Prologue analysis does the rest... */ | |
35488783 | 718 | if (tdep->cris_version == 32) |
94afd7a6 | 719 | crisv32_scan_prologue (get_frame_func (this_frame), this_frame, info); |
5114e29d | 720 | else |
94afd7a6 | 721 | cris_scan_prologue (get_frame_func (this_frame), this_frame, info); |
2e4b5889 OF |
722 | |
723 | return info; | |
724 | } | |
725 | ||
726 | /* Given a GDB frame, determine the address of the calling function's | |
727 | frame. This will be used to create a new GDB frame struct. */ | |
728 | ||
729 | static void | |
94afd7a6 | 730 | cris_frame_this_id (struct frame_info *this_frame, |
2e4b5889 OF |
731 | void **this_prologue_cache, |
732 | struct frame_id *this_id) | |
733 | { | |
734 | struct cris_unwind_cache *info | |
94afd7a6 | 735 | = cris_frame_unwind_cache (this_frame, this_prologue_cache); |
2e4b5889 OF |
736 | CORE_ADDR base; |
737 | CORE_ADDR func; | |
738 | struct frame_id id; | |
739 | ||
740 | /* The FUNC is easy. */ | |
94afd7a6 | 741 | func = get_frame_func (this_frame); |
2e4b5889 OF |
742 | |
743 | /* Hopefully the prologue analysis either correctly determined the | |
744 | frame's base (which is the SP from the previous frame), or set | |
745 | that base to "NULL". */ | |
746 | base = info->prev_sp; | |
747 | if (base == 0) | |
748 | return; | |
749 | ||
750 | id = frame_id_build (base, func); | |
751 | ||
752 | (*this_id) = id; | |
753 | } | |
754 | ||
94afd7a6 UW |
755 | static struct value * |
756 | cris_frame_prev_register (struct frame_info *this_frame, | |
757 | void **this_prologue_cache, int regnum) | |
2e4b5889 OF |
758 | { |
759 | struct cris_unwind_cache *info | |
94afd7a6 UW |
760 | = cris_frame_unwind_cache (this_frame, this_prologue_cache); |
761 | return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum); | |
2e4b5889 OF |
762 | } |
763 | ||
2e4b5889 OF |
764 | static CORE_ADDR |
765 | cris_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp) | |
766 | { | |
767 | /* Align to the size of an instruction (so that they can safely be | |
768 | pushed onto the stack). */ | |
769 | return sp & ~3; | |
770 | } | |
771 | ||
772 | static CORE_ADDR | |
773 | cris_push_dummy_code (struct gdbarch *gdbarch, | |
82585c72 | 774 | CORE_ADDR sp, CORE_ADDR funaddr, |
2e4b5889 OF |
775 | struct value **args, int nargs, |
776 | struct type *value_type, | |
e4fd649a UW |
777 | CORE_ADDR *real_pc, CORE_ADDR *bp_addr, |
778 | struct regcache *regcache) | |
2e4b5889 OF |
779 | { |
780 | /* Allocate space sufficient for a breakpoint. */ | |
781 | sp = (sp - 4) & ~3; | |
782 | /* Store the address of that breakpoint */ | |
783 | *bp_addr = sp; | |
784 | /* CRIS always starts the call at the callee's entry point. */ | |
785 | *real_pc = funaddr; | |
786 | return sp; | |
787 | } | |
788 | ||
789 | static CORE_ADDR | |
7d9b040b | 790 | cris_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
2e4b5889 OF |
791 | struct regcache *regcache, CORE_ADDR bp_addr, |
792 | int nargs, struct value **args, CORE_ADDR sp, | |
cf84fa6b AH |
793 | function_call_return_method return_method, |
794 | CORE_ADDR struct_addr) | |
2e4b5889 | 795 | { |
e17a4113 | 796 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
2e4b5889 OF |
797 | int argreg; |
798 | int argnum; | |
799 | ||
2e4b5889 OF |
800 | struct stack_item *si = NULL; |
801 | ||
a5f6c8f5 | 802 | /* Push the return address. */ |
2e4b5889 OF |
803 | regcache_cooked_write_unsigned (regcache, SRP_REGNUM, bp_addr); |
804 | ||
805 | /* Are we returning a value using a structure return or a normal value | |
806 | return? struct_addr is the address of the reserved space for the return | |
807 | structure to be written on the stack. */ | |
cf84fa6b AH |
808 | if (return_method == return_method_struct) |
809 | regcache_cooked_write_unsigned (regcache, STR_REGNUM, struct_addr); | |
2e4b5889 OF |
810 | |
811 | /* Now load as many as possible of the first arguments into registers, | |
812 | and push the rest onto the stack. */ | |
813 | argreg = ARG1_REGNUM; | |
2e4b5889 OF |
814 | |
815 | for (argnum = 0; argnum < nargs; argnum++) | |
816 | { | |
817 | int len; | |
948f8e3d | 818 | const gdb_byte *val; |
2e4b5889 OF |
819 | int reg_demand; |
820 | int i; | |
821 | ||
4991999e | 822 | len = TYPE_LENGTH (value_type (args[argnum])); |
948f8e3d | 823 | val = value_contents (args[argnum]); |
2e4b5889 OF |
824 | |
825 | /* How may registers worth of storage do we need for this argument? */ | |
826 | reg_demand = (len / 4) + (len % 4 != 0 ? 1 : 0); | |
827 | ||
828 | if (len <= (2 * 4) && (argreg + reg_demand - 1 <= ARG4_REGNUM)) | |
829 | { | |
830 | /* Data passed by value. Fits in available register(s). */ | |
831 | for (i = 0; i < reg_demand; i++) | |
832 | { | |
b66f5587 | 833 | regcache->cooked_write (argreg, val); |
2e4b5889 OF |
834 | argreg++; |
835 | val += 4; | |
836 | } | |
837 | } | |
838 | else if (len <= (2 * 4) && argreg <= ARG4_REGNUM) | |
839 | { | |
840 | /* Data passed by value. Does not fit in available register(s). | |
841 | Use the register(s) first, then the stack. */ | |
842 | for (i = 0; i < reg_demand; i++) | |
843 | { | |
844 | if (argreg <= ARG4_REGNUM) | |
845 | { | |
b66f5587 | 846 | regcache->cooked_write (argreg, val); |
2e4b5889 OF |
847 | argreg++; |
848 | val += 4; | |
849 | } | |
850 | else | |
851 | { | |
852 | /* Push item for later so that pushed arguments | |
853 | come in the right order. */ | |
854 | si = push_stack_item (si, val, 4); | |
855 | val += 4; | |
856 | } | |
857 | } | |
858 | } | |
859 | else if (len > (2 * 4)) | |
860 | { | |
f6e56ab3 UW |
861 | /* Data passed by reference. Push copy of data onto stack |
862 | and pass pointer to this copy as argument. */ | |
863 | sp = (sp - len) & ~3; | |
864 | write_memory (sp, val, len); | |
865 | ||
866 | if (argreg <= ARG4_REGNUM) | |
867 | { | |
868 | regcache_cooked_write_unsigned (regcache, argreg, sp); | |
869 | argreg++; | |
870 | } | |
871 | else | |
872 | { | |
873 | gdb_byte buf[4]; | |
e17a4113 | 874 | store_unsigned_integer (buf, 4, byte_order, sp); |
f6e56ab3 UW |
875 | si = push_stack_item (si, buf, 4); |
876 | } | |
2e4b5889 OF |
877 | } |
878 | else | |
879 | { | |
880 | /* Data passed by value. No available registers. Put it on | |
881 | the stack. */ | |
882 | si = push_stack_item (si, val, len); | |
883 | } | |
884 | } | |
885 | ||
886 | while (si) | |
887 | { | |
888 | /* fp_arg must be word-aligned (i.e., don't += len) to match | |
889 | the function prologue. */ | |
890 | sp = (sp - si->len) & ~3; | |
891 | write_memory (sp, si->data, si->len); | |
892 | si = pop_stack_item (si); | |
893 | } | |
894 | ||
895 | /* Finally, update the SP register. */ | |
7fbe2eba | 896 | regcache_cooked_write_unsigned (regcache, gdbarch_sp_regnum (gdbarch), sp); |
2e4b5889 OF |
897 | |
898 | return sp; | |
899 | } | |
900 | ||
e2a2a3e8 OF |
901 | static const struct frame_unwind cris_frame_unwind = |
902 | { | |
2e4b5889 | 903 | NORMAL_FRAME, |
8fbca658 | 904 | default_frame_unwind_stop_reason, |
2e4b5889 | 905 | cris_frame_this_id, |
94afd7a6 UW |
906 | cris_frame_prev_register, |
907 | NULL, | |
908 | default_frame_sniffer | |
2e4b5889 OF |
909 | }; |
910 | ||
2e4b5889 | 911 | static CORE_ADDR |
94afd7a6 | 912 | cris_frame_base_address (struct frame_info *this_frame, void **this_cache) |
2e4b5889 OF |
913 | { |
914 | struct cris_unwind_cache *info | |
94afd7a6 | 915 | = cris_frame_unwind_cache (this_frame, this_cache); |
2e4b5889 OF |
916 | return info->base; |
917 | } | |
918 | ||
e2a2a3e8 OF |
919 | static const struct frame_base cris_frame_base = |
920 | { | |
2e4b5889 OF |
921 | &cris_frame_unwind, |
922 | cris_frame_base_address, | |
923 | cris_frame_base_address, | |
924 | cris_frame_base_address | |
925 | }; | |
926 | ||
29134980 OF |
927 | /* Frames information. The definition of the struct frame_info is |
928 | ||
929 | CORE_ADDR frame | |
930 | CORE_ADDR pc | |
5a203e44 | 931 | enum frame_type type; |
29134980 OF |
932 | CORE_ADDR return_pc |
933 | int leaf_function | |
934 | ||
935 | If the compilation option -fno-omit-frame-pointer is present the | |
936 | variable frame will be set to the content of R8 which is the frame | |
937 | pointer register. | |
938 | ||
939 | The variable pc contains the address where execution is performed | |
940 | in the present frame. The innermost frame contains the current content | |
941 | of the register PC. All other frames contain the content of the | |
942 | register PC in the next frame. | |
943 | ||
5a203e44 AC |
944 | The variable `type' indicates the frame's type: normal, SIGTRAMP |
945 | (associated with a signal handler), dummy (associated with a dummy | |
946 | frame). | |
29134980 OF |
947 | |
948 | The variable return_pc contains the address where execution should be | |
949 | resumed when the present frame has finished, the return address. | |
950 | ||
951 | The variable leaf_function is 1 if the return address is in the register | |
952 | SRP, and 0 if it is on the stack. | |
953 | ||
954 | Prologue instructions C-code. | |
955 | The prologue may consist of (-fno-omit-frame-pointer) | |
956 | 1) 2) | |
957 | push srp | |
958 | push r8 push r8 | |
959 | move.d sp,r8 move.d sp,r8 | |
960 | subq X,sp subq X,sp | |
961 | movem rY,[sp] movem rY,[sp] | |
962 | move.S rZ,[r8-U] move.S rZ,[r8-U] | |
963 | ||
964 | where 1 is a non-terminal function, and 2 is a leaf-function. | |
965 | ||
966 | Note that this assumption is extremely brittle, and will break at the | |
967 | slightest change in GCC's prologue. | |
968 | ||
969 | If local variables are declared or register contents are saved on stack | |
970 | the subq-instruction will be present with X as the number of bytes | |
971 | needed for storage. The reshuffle with respect to r8 may be performed | |
972 | with any size S (b, w, d) and any of the general registers Z={0..13}. | |
0963b4bd | 973 | The offset U should be representable by a signed 8-bit value in all cases. |
29134980 OF |
974 | Thus, the prefix word is assumed to be immediate byte offset mode followed |
975 | by another word containing the instruction. | |
976 | ||
977 | Degenerate cases: | |
978 | 3) | |
979 | push r8 | |
980 | move.d sp,r8 | |
981 | move.d r8,sp | |
982 | pop r8 | |
983 | ||
984 | Prologue instructions C++-code. | |
985 | Case 1) and 2) in the C-code may be followed by | |
986 | ||
987 | move.d r10,rS ; this | |
988 | move.d r11,rT ; P1 | |
989 | move.d r12,rU ; P2 | |
990 | move.d r13,rV ; P3 | |
991 | move.S [r8+U],rZ ; P4 | |
992 | ||
0963b4bd | 993 | if any of the call parameters are stored. The host expects these |
29134980 OF |
994 | instructions to be executed in order to get the call parameters right. */ |
995 | ||
996 | /* Examine the prologue of a function. The variable ip is the address of | |
997 | the first instruction of the prologue. The variable limit is the address | |
998 | of the first instruction after the prologue. The variable fi contains the | |
999 | information in struct frame_info. The variable frameless_p controls whether | |
1000 | the entire prologue is examined (0) or just enough instructions to | |
1001 | determine that it is a prologue (1). */ | |
1002 | ||
a78f21af | 1003 | static CORE_ADDR |
94afd7a6 | 1004 | cris_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame, |
2e4b5889 | 1005 | struct cris_unwind_cache *info) |
29134980 | 1006 | { |
94afd7a6 | 1007 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
e17a4113 UW |
1008 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
1009 | ||
29134980 OF |
1010 | /* Present instruction. */ |
1011 | unsigned short insn; | |
1012 | ||
1013 | /* Next instruction, lookahead. */ | |
1014 | unsigned short insn_next; | |
1015 | int regno; | |
1016 | ||
29134980 OF |
1017 | /* Number of byte on stack used for local variables and movem. */ |
1018 | int val; | |
1019 | ||
1020 | /* Highest register number in a movem. */ | |
1021 | int regsave; | |
1022 | ||
1023 | /* move.d r<source_register>,rS */ | |
1024 | short source_register; | |
1025 | ||
2e4b5889 OF |
1026 | /* Scan limit. */ |
1027 | int limit; | |
29134980 | 1028 | |
2e4b5889 OF |
1029 | /* This frame is with respect to a leaf until a push srp is found. */ |
1030 | if (info) | |
1031 | { | |
1032 | info->leaf_function = 1; | |
1033 | } | |
29134980 OF |
1034 | |
1035 | /* Assume nothing on stack. */ | |
1036 | val = 0; | |
1037 | regsave = -1; | |
1038 | ||
94afd7a6 | 1039 | /* If we were called without a this_frame, that means we were called |
2e4b5889 OF |
1040 | from cris_skip_prologue which already tried to find the end of the |
1041 | prologue through the symbol information. 64 instructions past current | |
1042 | pc is arbitrarily chosen, but at least it means we'll stop eventually. */ | |
94afd7a6 | 1043 | limit = this_frame ? get_frame_pc (this_frame) : pc + 64; |
29134980 | 1044 | |
29134980 | 1045 | /* Find the prologue instructions. */ |
a5f6c8f5 | 1046 | while (pc > 0 && pc < limit) |
29134980 | 1047 | { |
e17a4113 | 1048 | insn = read_memory_unsigned_integer (pc, 2, byte_order); |
2e4b5889 | 1049 | pc += 2; |
29134980 OF |
1050 | if (insn == 0xE1FC) |
1051 | { | |
0963b4bd | 1052 | /* push <reg> 32 bit instruction. */ |
e17a4113 | 1053 | insn_next = read_memory_unsigned_integer (pc, 2, byte_order); |
2e4b5889 | 1054 | pc += 2; |
29134980 | 1055 | regno = cris_get_operand2 (insn_next); |
2e4b5889 OF |
1056 | if (info) |
1057 | { | |
1058 | info->sp_offset += 4; | |
1059 | } | |
dbbff683 OF |
1060 | /* This check, meant to recognize srp, used to be regno == |
1061 | (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */ | |
1062 | if (insn_next == 0xBE7E) | |
29134980 | 1063 | { |
2e4b5889 OF |
1064 | if (info) |
1065 | { | |
1066 | info->leaf_function = 0; | |
1067 | } | |
29134980 | 1068 | } |
b4206d25 OF |
1069 | else if (insn_next == 0x8FEE) |
1070 | { | |
1071 | /* push $r8 */ | |
1072 | if (info) | |
1073 | { | |
1074 | info->r8_offset = info->sp_offset; | |
1075 | } | |
1076 | } | |
29134980 OF |
1077 | } |
1078 | else if (insn == 0x866E) | |
1079 | { | |
1080 | /* move.d sp,r8 */ | |
2e4b5889 OF |
1081 | if (info) |
1082 | { | |
1083 | info->uses_frame = 1; | |
2e4b5889 | 1084 | } |
29134980 OF |
1085 | continue; |
1086 | } | |
7fbe2eba | 1087 | else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch) |
29134980 OF |
1088 | && cris_get_mode (insn) == 0x0000 |
1089 | && cris_get_opcode (insn) == 0x000A) | |
1090 | { | |
1091 | /* subq <val>,sp */ | |
2e4b5889 OF |
1092 | if (info) |
1093 | { | |
1094 | info->sp_offset += cris_get_quick_value (insn); | |
1095 | } | |
29134980 OF |
1096 | } |
1097 | else if (cris_get_mode (insn) == 0x0002 | |
1098 | && cris_get_opcode (insn) == 0x000F | |
1099 | && cris_get_size (insn) == 0x0003 | |
7fbe2eba | 1100 | && cris_get_operand1 (insn) == gdbarch_sp_regnum (gdbarch)) |
29134980 OF |
1101 | { |
1102 | /* movem r<regsave>,[sp] */ | |
29134980 OF |
1103 | regsave = cris_get_operand2 (insn); |
1104 | } | |
7fbe2eba | 1105 | else if (cris_get_operand2 (insn) == gdbarch_sp_regnum (gdbarch) |
29134980 OF |
1106 | && ((insn & 0x0F00) >> 8) == 0x0001 |
1107 | && (cris_get_signed_offset (insn) < 0)) | |
1108 | { | |
1109 | /* Immediate byte offset addressing prefix word with sp as base | |
1110 | register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val> | |
1111 | is between 64 and 128. | |
1112 | movem r<regsave>,[sp=sp-<val>] */ | |
2e4b5889 OF |
1113 | if (info) |
1114 | { | |
1115 | info->sp_offset += -cris_get_signed_offset (insn); | |
1116 | } | |
e17a4113 | 1117 | insn_next = read_memory_unsigned_integer (pc, 2, byte_order); |
2e4b5889 | 1118 | pc += 2; |
29134980 OF |
1119 | if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE |
1120 | && cris_get_opcode (insn_next) == 0x000F | |
1121 | && cris_get_size (insn_next) == 0x0003 | |
3e8c568d | 1122 | && cris_get_operand1 (insn_next) == gdbarch_sp_regnum |
7fbe2eba | 1123 | (gdbarch)) |
29134980 | 1124 | { |
29134980 OF |
1125 | regsave = cris_get_operand2 (insn_next); |
1126 | } | |
1127 | else | |
1128 | { | |
1129 | /* The prologue ended before the limit was reached. */ | |
2e4b5889 | 1130 | pc -= 4; |
29134980 OF |
1131 | break; |
1132 | } | |
1133 | } | |
1134 | else if (cris_get_mode (insn) == 0x0001 | |
1135 | && cris_get_opcode (insn) == 0x0009 | |
1136 | && cris_get_size (insn) == 0x0002) | |
1137 | { | |
1138 | /* move.d r<10..13>,r<0..15> */ | |
29134980 | 1139 | source_register = cris_get_operand1 (insn); |
2a9ecef2 OF |
1140 | |
1141 | /* FIXME? In the glibc solibs, the prologue might contain something | |
1142 | like (this example taken from relocate_doit): | |
1143 | move.d $pc,$r0 | |
1144 | sub.d 0xfffef426,$r0 | |
1145 | which isn't covered by the source_register check below. Question | |
1146 | is whether to add a check for this combo, or make better use of | |
1147 | the limit variable instead. */ | |
29134980 OF |
1148 | if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM) |
1149 | { | |
1150 | /* The prologue ended before the limit was reached. */ | |
2e4b5889 | 1151 | pc -= 2; |
29134980 OF |
1152 | break; |
1153 | } | |
1154 | } | |
2e4b5889 | 1155 | else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM |
29134980 OF |
1156 | /* The size is a fixed-size. */ |
1157 | && ((insn & 0x0F00) >> 8) == 0x0001 | |
1158 | /* A negative offset. */ | |
1159 | && (cris_get_signed_offset (insn) < 0)) | |
1160 | { | |
1161 | /* move.S rZ,[r8-U] (?) */ | |
e17a4113 | 1162 | insn_next = read_memory_unsigned_integer (pc, 2, byte_order); |
2e4b5889 | 1163 | pc += 2; |
29134980 | 1164 | regno = cris_get_operand2 (insn_next); |
7fbe2eba | 1165 | if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch)) |
29134980 OF |
1166 | && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE |
1167 | && cris_get_opcode (insn_next) == 0x000F) | |
1168 | { | |
1169 | /* move.S rZ,[r8-U] */ | |
1170 | continue; | |
1171 | } | |
1172 | else | |
1173 | { | |
1174 | /* The prologue ended before the limit was reached. */ | |
2e4b5889 | 1175 | pc -= 4; |
29134980 OF |
1176 | break; |
1177 | } | |
1178 | } | |
2e4b5889 | 1179 | else if (cris_get_operand2 (insn) == CRIS_FP_REGNUM |
29134980 OF |
1180 | /* The size is a fixed-size. */ |
1181 | && ((insn & 0x0F00) >> 8) == 0x0001 | |
1182 | /* A positive offset. */ | |
1183 | && (cris_get_signed_offset (insn) > 0)) | |
1184 | { | |
1185 | /* move.S [r8+U],rZ (?) */ | |
e17a4113 | 1186 | insn_next = read_memory_unsigned_integer (pc, 2, byte_order); |
2e4b5889 | 1187 | pc += 2; |
29134980 | 1188 | regno = cris_get_operand2 (insn_next); |
7fbe2eba | 1189 | if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch)) |
29134980 OF |
1190 | && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE |
1191 | && cris_get_opcode (insn_next) == 0x0009 | |
1192 | && cris_get_operand1 (insn_next) == regno) | |
1193 | { | |
1194 | /* move.S [r8+U],rZ */ | |
1195 | continue; | |
1196 | } | |
1197 | else | |
1198 | { | |
1199 | /* The prologue ended before the limit was reached. */ | |
2e4b5889 | 1200 | pc -= 4; |
29134980 OF |
1201 | break; |
1202 | } | |
1203 | } | |
1204 | else | |
1205 | { | |
1206 | /* The prologue ended before the limit was reached. */ | |
2e4b5889 | 1207 | pc -= 2; |
29134980 OF |
1208 | break; |
1209 | } | |
1210 | } | |
29134980 | 1211 | |
94afd7a6 | 1212 | /* We only want to know the end of the prologue when this_frame and info |
2e4b5889 | 1213 | are NULL (called from cris_skip_prologue i.e.). */ |
94afd7a6 | 1214 | if (this_frame == NULL && info == NULL) |
2e4b5889 OF |
1215 | { |
1216 | return pc; | |
1217 | } | |
29134980 | 1218 | |
2e4b5889 OF |
1219 | info->size = info->sp_offset; |
1220 | ||
1221 | /* Compute the previous frame's stack pointer (which is also the | |
1222 | frame's ID's stack address), and this frame's base pointer. */ | |
1223 | if (info->uses_frame) | |
29134980 | 1224 | { |
2e4b5889 OF |
1225 | ULONGEST this_base; |
1226 | /* The SP was moved to the FP. This indicates that a new frame | |
1227 | was created. Get THIS frame's FP value by unwinding it from | |
1228 | the next frame. */ | |
94afd7a6 | 1229 | this_base = get_frame_register_unsigned (this_frame, CRIS_FP_REGNUM); |
2e4b5889 | 1230 | info->base = this_base; |
b4206d25 OF |
1231 | info->saved_regs[CRIS_FP_REGNUM].addr = info->base; |
1232 | ||
2e4b5889 OF |
1233 | /* The FP points at the last saved register. Adjust the FP back |
1234 | to before the first saved register giving the SP. */ | |
1235 | info->prev_sp = info->base + info->r8_offset; | |
1236 | } | |
1237 | else | |
1238 | { | |
1239 | ULONGEST this_base; | |
1240 | /* Assume that the FP is this frame's SP but with that pushed | |
1241 | stack space added back. */ | |
94afd7a6 UW |
1242 | this_base = get_frame_register_unsigned (this_frame, |
1243 | gdbarch_sp_regnum (gdbarch)); | |
2e4b5889 OF |
1244 | info->base = this_base; |
1245 | info->prev_sp = info->base + info->size; | |
1246 | } | |
29134980 | 1247 | |
2e4b5889 OF |
1248 | /* Calculate the addresses for the saved registers on the stack. */ |
1249 | /* FIXME: The address calculation should really be done on the fly while | |
1250 | we're analyzing the prologue (we only hold one regsave value as it is | |
1251 | now). */ | |
1252 | val = info->sp_offset; | |
1253 | ||
1254 | for (regno = regsave; regno >= 0; regno--) | |
1255 | { | |
1256 | info->saved_regs[regno].addr = info->base + info->r8_offset - val; | |
1257 | val -= 4; | |
1258 | } | |
1259 | ||
1260 | /* The previous frame's SP needed to be computed. Save the computed | |
1261 | value. */ | |
3e8c568d | 1262 | trad_frame_set_value (info->saved_regs, |
7fbe2eba | 1263 | gdbarch_sp_regnum (gdbarch), info->prev_sp); |
2e4b5889 OF |
1264 | |
1265 | if (!info->leaf_function) | |
1266 | { | |
b4206d25 OF |
1267 | /* SRP saved on the stack. But where? */ |
1268 | if (info->r8_offset == 0) | |
1269 | { | |
1270 | /* R8 not pushed yet. */ | |
1271 | info->saved_regs[SRP_REGNUM].addr = info->base; | |
1272 | } | |
1273 | else | |
1274 | { | |
1275 | /* R8 pushed, but SP may or may not be moved to R8 yet. */ | |
1276 | info->saved_regs[SRP_REGNUM].addr = info->base + 4; | |
1277 | } | |
29134980 | 1278 | } |
2e4b5889 OF |
1279 | |
1280 | /* The PC is found in SRP (the actual register or located on the stack). */ | |
7fbe2eba | 1281 | info->saved_regs[gdbarch_pc_regnum (gdbarch)] |
3e8c568d | 1282 | = info->saved_regs[SRP_REGNUM]; |
2e4b5889 OF |
1283 | |
1284 | return pc; | |
29134980 OF |
1285 | } |
1286 | ||
5114e29d | 1287 | static CORE_ADDR |
94afd7a6 | 1288 | crisv32_scan_prologue (CORE_ADDR pc, struct frame_info *this_frame, |
5114e29d OF |
1289 | struct cris_unwind_cache *info) |
1290 | { | |
94afd7a6 | 1291 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
5114e29d OF |
1292 | ULONGEST this_base; |
1293 | ||
1294 | /* Unlike the CRISv10 prologue scanner (cris_scan_prologue), this is not | |
1295 | meant to be a full-fledged prologue scanner. It is only needed for | |
1296 | the cases where we end up in code always lacking DWARF-2 CFI, notably: | |
1297 | ||
1298 | * PLT stubs (library calls) | |
1299 | * call dummys | |
1300 | * signal trampolines | |
1301 | ||
1302 | For those cases, it is assumed that there is no actual prologue; that | |
1303 | the stack pointer is not adjusted, and (as a consequence) the return | |
1304 | address is not pushed onto the stack. */ | |
1305 | ||
94afd7a6 | 1306 | /* We only want to know the end of the prologue when this_frame and info |
5114e29d | 1307 | are NULL (called from cris_skip_prologue i.e.). */ |
94afd7a6 | 1308 | if (this_frame == NULL && info == NULL) |
5114e29d OF |
1309 | { |
1310 | return pc; | |
1311 | } | |
1312 | ||
1313 | /* The SP is assumed to be unaltered. */ | |
94afd7a6 UW |
1314 | this_base = get_frame_register_unsigned (this_frame, |
1315 | gdbarch_sp_regnum (gdbarch)); | |
5114e29d OF |
1316 | info->base = this_base; |
1317 | info->prev_sp = this_base; | |
1318 | ||
1319 | /* The PC is assumed to be found in SRP. */ | |
7fbe2eba | 1320 | info->saved_regs[gdbarch_pc_regnum (gdbarch)] |
3e8c568d | 1321 | = info->saved_regs[SRP_REGNUM]; |
5114e29d OF |
1322 | |
1323 | return pc; | |
1324 | } | |
1325 | ||
29134980 OF |
1326 | /* Advance pc beyond any function entry prologue instructions at pc |
1327 | to reach some "real" code. */ | |
1328 | ||
29134980 OF |
1329 | /* Given a PC value corresponding to the start of a function, return the PC |
1330 | of the first instruction after the function prologue. */ | |
1331 | ||
a78f21af | 1332 | static CORE_ADDR |
6093d2eb | 1333 | cris_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc) |
29134980 | 1334 | { |
35488783 | 1335 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
2e4b5889 OF |
1336 | CORE_ADDR func_addr, func_end; |
1337 | struct symtab_and_line sal; | |
29134980 OF |
1338 | CORE_ADDR pc_after_prologue; |
1339 | ||
2e4b5889 OF |
1340 | /* If we have line debugging information, then the end of the prologue |
1341 | should the first assembly instruction of the first source line. */ | |
1342 | if (find_pc_partial_function (pc, NULL, &func_addr, &func_end)) | |
1343 | { | |
1344 | sal = find_pc_line (func_addr, 0); | |
1345 | if (sal.end > 0 && sal.end < func_end) | |
1346 | return sal.end; | |
1347 | } | |
29134980 | 1348 | |
35488783 | 1349 | if (tdep->cris_version == 32) |
5114e29d OF |
1350 | pc_after_prologue = crisv32_scan_prologue (pc, NULL, NULL); |
1351 | else | |
1352 | pc_after_prologue = cris_scan_prologue (pc, NULL, NULL); | |
1353 | ||
29134980 OF |
1354 | return pc_after_prologue; |
1355 | } | |
1356 | ||
cd6c3b4f YQ |
1357 | /* Implement the breakpoint_kind_from_pc gdbarch method. */ |
1358 | ||
d19280ad YQ |
1359 | static int |
1360 | cris_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr) | |
1361 | { | |
1362 | return 2; | |
1363 | } | |
29134980 | 1364 | |
cd6c3b4f YQ |
1365 | /* Implement the sw_breakpoint_from_kind gdbarch method. */ |
1366 | ||
d19280ad YQ |
1367 | static const gdb_byte * |
1368 | cris_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size) | |
29134980 | 1369 | { |
35488783 | 1370 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
0e6bdb31 OF |
1371 | static unsigned char break8_insn[] = {0x38, 0xe9}; |
1372 | static unsigned char break15_insn[] = {0x3f, 0xe9}; | |
d19280ad YQ |
1373 | |
1374 | *size = kind; | |
29134980 | 1375 | |
35488783 | 1376 | if (tdep->cris_mode == cris_mode_guru) |
0e6bdb31 OF |
1377 | return break15_insn; |
1378 | else | |
1379 | return break8_insn; | |
29134980 OF |
1380 | } |
1381 | ||
29134980 OF |
1382 | /* Returns 1 if spec_reg is applicable to the current gdbarch's CRIS version, |
1383 | 0 otherwise. */ | |
1384 | ||
a78f21af | 1385 | static int |
35488783 UW |
1386 | cris_spec_reg_applicable (struct gdbarch *gdbarch, |
1387 | struct cris_spec_reg spec_reg) | |
29134980 | 1388 | { |
35488783 | 1389 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
e4286e57 | 1390 | unsigned int version = tdep->cris_version; |
29134980 OF |
1391 | |
1392 | switch (spec_reg.applicable_version) | |
1393 | { | |
1394 | case cris_ver_version_all: | |
1395 | return 1; | |
1396 | case cris_ver_warning: | |
1397 | /* Indeterminate/obsolete. */ | |
1398 | return 0; | |
29134980 | 1399 | case cris_ver_v0_3: |
b020ff80 | 1400 | return in_inclusive_range (version, 0U, 3U); |
29134980 OF |
1401 | case cris_ver_v3p: |
1402 | return (version >= 3); | |
1403 | case cris_ver_v8: | |
b020ff80 | 1404 | return in_inclusive_range (version, 8U, 9U); |
29134980 OF |
1405 | case cris_ver_v8p: |
1406 | return (version >= 8); | |
c600d464 | 1407 | case cris_ver_v0_10: |
b020ff80 | 1408 | return in_inclusive_range (version, 0U, 10U); |
c600d464 | 1409 | case cris_ver_v3_10: |
b020ff80 | 1410 | return in_inclusive_range (version, 3U, 10U); |
c600d464 | 1411 | case cris_ver_v8_10: |
b020ff80 | 1412 | return in_inclusive_range (version, 8U, 10U); |
c600d464 OF |
1413 | case cris_ver_v10: |
1414 | return (version == 10); | |
29134980 OF |
1415 | case cris_ver_v10p: |
1416 | return (version >= 10); | |
c600d464 OF |
1417 | case cris_ver_v32p: |
1418 | return (version >= 32); | |
29134980 OF |
1419 | default: |
1420 | /* Invalid cris version. */ | |
1421 | return 0; | |
1422 | } | |
1423 | } | |
1424 | ||
1d94326f AC |
1425 | /* Returns the register size in unit byte. Returns 0 for an unimplemented |
1426 | register, -1 for an invalid register. */ | |
1427 | ||
1428 | static int | |
be8626e0 | 1429 | cris_register_size (struct gdbarch *gdbarch, int regno) |
1d94326f AC |
1430 | { |
1431 | int i; | |
1432 | int spec_regno; | |
1433 | ||
1434 | if (regno >= 0 && regno < NUM_GENREGS) | |
1435 | { | |
1436 | /* General registers (R0 - R15) are 32 bits. */ | |
1437 | return 4; | |
1438 | } | |
c600d464 | 1439 | else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS)) |
1d94326f AC |
1440 | { |
1441 | /* Special register (R16 - R31). cris_spec_regs is zero-based. | |
1442 | Adjust regno accordingly. */ | |
1443 | spec_regno = regno - NUM_GENREGS; | |
1444 | ||
c600d464 | 1445 | for (i = 0; cris_spec_regs[i].name != NULL; i++) |
1d94326f AC |
1446 | { |
1447 | if (cris_spec_regs[i].number == spec_regno | |
35488783 | 1448 | && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i])) |
1d94326f AC |
1449 | /* Go with the first applicable register. */ |
1450 | return cris_spec_regs[i].reg_size; | |
1451 | } | |
1452 | /* Special register not applicable to this CRIS version. */ | |
1453 | return 0; | |
1454 | } | |
be8626e0 MD |
1455 | else if (regno >= gdbarch_pc_regnum (gdbarch) |
1456 | && regno < gdbarch_num_regs (gdbarch)) | |
1d94326f | 1457 | { |
c600d464 OF |
1458 | /* This will apply to CRISv32 only where there are additional registers |
1459 | after the special registers (pseudo PC and support registers). */ | |
1460 | return 4; | |
1d94326f | 1461 | } |
c600d464 OF |
1462 | |
1463 | ||
1464 | return -1; | |
1d94326f AC |
1465 | } |
1466 | ||
29134980 OF |
1467 | /* Nonzero if regno should not be fetched from the target. This is the case |
1468 | for unimplemented (size 0) and non-existant registers. */ | |
1469 | ||
a78f21af | 1470 | static int |
64a3914f | 1471 | cris_cannot_fetch_register (struct gdbarch *gdbarch, int regno) |
29134980 | 1472 | { |
64a3914f | 1473 | return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch)) |
be8626e0 | 1474 | || (cris_register_size (gdbarch, regno) == 0)); |
29134980 OF |
1475 | } |
1476 | ||
1477 | /* Nonzero if regno should not be written to the target, for various | |
1478 | reasons. */ | |
1479 | ||
a78f21af | 1480 | static int |
64a3914f | 1481 | cris_cannot_store_register (struct gdbarch *gdbarch, int regno) |
29134980 OF |
1482 | { |
1483 | /* There are three kinds of registers we refuse to write to. | |
1484 | 1. Those that not implemented. | |
1485 | 2. Those that are read-only (depends on the processor mode). | |
0963b4bd | 1486 | 3. Those registers to which a write has no effect. */ |
29134980 | 1487 | |
f57d151a | 1488 | if (regno < 0 |
64a3914f | 1489 | || regno >= gdbarch_num_regs (gdbarch) |
be8626e0 | 1490 | || cris_register_size (gdbarch, regno) == 0) |
29134980 OF |
1491 | /* Not implemented. */ |
1492 | return 1; | |
1493 | ||
1494 | else if (regno == VR_REGNUM) | |
1495 | /* Read-only. */ | |
1496 | return 1; | |
1497 | ||
1498 | else if (regno == P0_REGNUM || regno == P4_REGNUM || regno == P8_REGNUM) | |
1499 | /* Writing has no effect. */ | |
1500 | return 1; | |
1501 | ||
a5f6c8f5 OF |
1502 | /* IBR, BAR, BRP and IRP are read-only in user mode. Let the debug |
1503 | agent decide whether they are writable. */ | |
29134980 OF |
1504 | |
1505 | return 0; | |
1506 | } | |
1507 | ||
c600d464 OF |
1508 | /* Nonzero if regno should not be fetched from the target. This is the case |
1509 | for unimplemented (size 0) and non-existant registers. */ | |
1510 | ||
1511 | static int | |
64a3914f | 1512 | crisv32_cannot_fetch_register (struct gdbarch *gdbarch, int regno) |
c600d464 | 1513 | { |
64a3914f | 1514 | return ((regno < 0 || regno >= gdbarch_num_regs (gdbarch)) |
be8626e0 | 1515 | || (cris_register_size (gdbarch, regno) == 0)); |
c600d464 OF |
1516 | } |
1517 | ||
1518 | /* Nonzero if regno should not be written to the target, for various | |
1519 | reasons. */ | |
1520 | ||
1521 | static int | |
64a3914f | 1522 | crisv32_cannot_store_register (struct gdbarch *gdbarch, int regno) |
c600d464 OF |
1523 | { |
1524 | /* There are three kinds of registers we refuse to write to. | |
1525 | 1. Those that not implemented. | |
1526 | 2. Those that are read-only (depends on the processor mode). | |
0963b4bd | 1527 | 3. Those registers to which a write has no effect. */ |
c600d464 | 1528 | |
f57d151a | 1529 | if (regno < 0 |
64a3914f | 1530 | || regno >= gdbarch_num_regs (gdbarch) |
be8626e0 | 1531 | || cris_register_size (gdbarch, regno) == 0) |
c600d464 OF |
1532 | /* Not implemented. */ |
1533 | return 1; | |
1534 | ||
1535 | else if (regno == VR_REGNUM) | |
1536 | /* Read-only. */ | |
1537 | return 1; | |
1538 | ||
1539 | else if (regno == BZ_REGNUM || regno == WZ_REGNUM || regno == DZ_REGNUM) | |
1540 | /* Writing has no effect. */ | |
1541 | return 1; | |
1542 | ||
1543 | /* Many special registers are read-only in user mode. Let the debug | |
1544 | agent decide whether they are writable. */ | |
1545 | ||
1546 | return 0; | |
1547 | } | |
1548 | ||
29134980 OF |
1549 | /* Return the GDB type (defined in gdbtypes.c) for the "standard" data type |
1550 | of data in register regno. */ | |
1551 | ||
a78f21af | 1552 | static struct type * |
c1d546cd | 1553 | cris_register_type (struct gdbarch *gdbarch, int regno) |
29134980 | 1554 | { |
7fbe2eba | 1555 | if (regno == gdbarch_pc_regnum (gdbarch)) |
0dfff4cb | 1556 | return builtin_type (gdbarch)->builtin_func_ptr; |
7fbe2eba | 1557 | else if (regno == gdbarch_sp_regnum (gdbarch) |
3e8c568d | 1558 | || regno == CRIS_FP_REGNUM) |
0dfff4cb | 1559 | return builtin_type (gdbarch)->builtin_data_ptr; |
7fbe2eba | 1560 | else if ((regno >= 0 && regno < gdbarch_sp_regnum (gdbarch)) |
a5f6c8f5 OF |
1561 | || (regno >= MOF_REGNUM && regno <= USP_REGNUM)) |
1562 | /* Note: R8 taken care of previous clause. */ | |
df4df182 | 1563 | return builtin_type (gdbarch)->builtin_uint32; |
a5f6c8f5 | 1564 | else if (regno >= P4_REGNUM && regno <= CCR_REGNUM) |
df4df182 | 1565 | return builtin_type (gdbarch)->builtin_uint16; |
a5f6c8f5 | 1566 | else if (regno >= P0_REGNUM && regno <= VR_REGNUM) |
df4df182 | 1567 | return builtin_type (gdbarch)->builtin_uint8; |
29134980 | 1568 | else |
a5f6c8f5 | 1569 | /* Invalid (unimplemented) register. */ |
df4df182 | 1570 | return builtin_type (gdbarch)->builtin_int0; |
29134980 OF |
1571 | } |
1572 | ||
c600d464 OF |
1573 | static struct type * |
1574 | crisv32_register_type (struct gdbarch *gdbarch, int regno) | |
1575 | { | |
7fbe2eba | 1576 | if (regno == gdbarch_pc_regnum (gdbarch)) |
0dfff4cb | 1577 | return builtin_type (gdbarch)->builtin_func_ptr; |
7fbe2eba | 1578 | else if (regno == gdbarch_sp_regnum (gdbarch) |
3e8c568d | 1579 | || regno == CRIS_FP_REGNUM) |
0dfff4cb | 1580 | return builtin_type (gdbarch)->builtin_data_ptr; |
c600d464 OF |
1581 | else if ((regno >= 0 && regno <= ACR_REGNUM) |
1582 | || (regno >= EXS_REGNUM && regno <= SPC_REGNUM) | |
1583 | || (regno == PID_REGNUM) | |
1584 | || (regno >= S0_REGNUM && regno <= S15_REGNUM)) | |
1585 | /* Note: R8 and SP taken care of by previous clause. */ | |
df4df182 | 1586 | return builtin_type (gdbarch)->builtin_uint32; |
c600d464 | 1587 | else if (regno == WZ_REGNUM) |
df4df182 | 1588 | return builtin_type (gdbarch)->builtin_uint16; |
c600d464 | 1589 | else if (regno == BZ_REGNUM || regno == VR_REGNUM || regno == SRS_REGNUM) |
df4df182 | 1590 | return builtin_type (gdbarch)->builtin_uint8; |
c600d464 OF |
1591 | else |
1592 | { | |
1593 | /* Invalid (unimplemented) register. Should not happen as there are | |
1594 | no unimplemented CRISv32 registers. */ | |
8a3fe4f8 | 1595 | warning (_("crisv32_register_type: unknown regno %d"), regno); |
df4df182 | 1596 | return builtin_type (gdbarch)->builtin_int0; |
c600d464 OF |
1597 | } |
1598 | } | |
1599 | ||
2e4b5889 OF |
1600 | /* Stores a function return value of type type, where valbuf is the address |
1601 | of the value to be stored. */ | |
29134980 | 1602 | |
2e4b5889 | 1603 | /* In the CRIS ABI, R10 and R11 are used to store return values. */ |
29134980 | 1604 | |
2e4b5889 OF |
1605 | static void |
1606 | cris_store_return_value (struct type *type, struct regcache *regcache, | |
948f8e3d | 1607 | const gdb_byte *valbuf) |
29134980 | 1608 | { |
ac7936df | 1609 | struct gdbarch *gdbarch = regcache->arch (); |
e17a4113 | 1610 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
2e4b5889 | 1611 | ULONGEST val; |
bad43aa5 | 1612 | int len = TYPE_LENGTH (type); |
29134980 | 1613 | |
bad43aa5 | 1614 | if (len <= 4) |
29134980 | 1615 | { |
2e4b5889 | 1616 | /* Put the return value in R10. */ |
bad43aa5 | 1617 | val = extract_unsigned_integer (valbuf, len, byte_order); |
2e4b5889 | 1618 | regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val); |
29134980 | 1619 | } |
bad43aa5 | 1620 | else if (len <= 8) |
29134980 | 1621 | { |
2e4b5889 | 1622 | /* Put the return value in R10 and R11. */ |
e17a4113 | 1623 | val = extract_unsigned_integer (valbuf, 4, byte_order); |
2e4b5889 | 1624 | regcache_cooked_write_unsigned (regcache, ARG1_REGNUM, val); |
948f8e3d | 1625 | val = extract_unsigned_integer (valbuf + 4, len - 4, byte_order); |
2e4b5889 | 1626 | regcache_cooked_write_unsigned (regcache, ARG2_REGNUM, val); |
29134980 | 1627 | } |
2e4b5889 | 1628 | else |
8a3fe4f8 | 1629 | error (_("cris_store_return_value: type length too large.")); |
29134980 OF |
1630 | } |
1631 | ||
0963b4bd MS |
1632 | /* Return the name of register regno as a string. Return NULL for an |
1633 | invalid or unimplemented register. */ | |
29134980 | 1634 | |
c600d464 | 1635 | static const char * |
35488783 | 1636 | cris_special_register_name (struct gdbarch *gdbarch, int regno) |
c600d464 OF |
1637 | { |
1638 | int spec_regno; | |
1639 | int i; | |
1640 | ||
1641 | /* Special register (R16 - R31). cris_spec_regs is zero-based. | |
1642 | Adjust regno accordingly. */ | |
1643 | spec_regno = regno - NUM_GENREGS; | |
1644 | ||
1645 | /* Assume nothing about the layout of the cris_spec_regs struct | |
1646 | when searching. */ | |
1647 | for (i = 0; cris_spec_regs[i].name != NULL; i++) | |
1648 | { | |
1649 | if (cris_spec_regs[i].number == spec_regno | |
35488783 | 1650 | && cris_spec_reg_applicable (gdbarch, cris_spec_regs[i])) |
c600d464 OF |
1651 | /* Go with the first applicable register. */ |
1652 | return cris_spec_regs[i].name; | |
1653 | } | |
1654 | /* Special register not applicable to this CRIS version. */ | |
1655 | return NULL; | |
1656 | } | |
1657 | ||
2e4b5889 | 1658 | static const char * |
d93859e2 | 1659 | cris_register_name (struct gdbarch *gdbarch, int regno) |
2e4b5889 | 1660 | { |
a121b7c1 | 1661 | static const char *cris_genreg_names[] = |
2e4b5889 OF |
1662 | { "r0", "r1", "r2", "r3", \ |
1663 | "r4", "r5", "r6", "r7", \ | |
1664 | "r8", "r9", "r10", "r11", \ | |
1665 | "r12", "r13", "sp", "pc" }; | |
29134980 | 1666 | |
2e4b5889 | 1667 | if (regno >= 0 && regno < NUM_GENREGS) |
29134980 | 1668 | { |
2e4b5889 OF |
1669 | /* General register. */ |
1670 | return cris_genreg_names[regno]; | |
29134980 | 1671 | } |
d93859e2 | 1672 | else if (regno >= NUM_GENREGS && regno < gdbarch_num_regs (gdbarch)) |
29134980 | 1673 | { |
35488783 | 1674 | return cris_special_register_name (gdbarch, regno); |
c600d464 OF |
1675 | } |
1676 | else | |
1677 | { | |
1678 | /* Invalid register. */ | |
2e4b5889 OF |
1679 | return NULL; |
1680 | } | |
c600d464 OF |
1681 | } |
1682 | ||
1683 | static const char * | |
d93859e2 | 1684 | crisv32_register_name (struct gdbarch *gdbarch, int regno) |
c600d464 | 1685 | { |
a121b7c1 | 1686 | static const char *crisv32_genreg_names[] = |
c600d464 OF |
1687 | { "r0", "r1", "r2", "r3", \ |
1688 | "r4", "r5", "r6", "r7", \ | |
1689 | "r8", "r9", "r10", "r11", \ | |
1690 | "r12", "r13", "sp", "acr" | |
1691 | }; | |
1692 | ||
a121b7c1 | 1693 | static const char *crisv32_sreg_names[] = |
c600d464 OF |
1694 | { "s0", "s1", "s2", "s3", \ |
1695 | "s4", "s5", "s6", "s7", \ | |
1696 | "s8", "s9", "s10", "s11", \ | |
1697 | "s12", "s13", "s14", "s15" | |
1698 | }; | |
1699 | ||
1700 | if (regno >= 0 && regno < NUM_GENREGS) | |
1701 | { | |
1702 | /* General register. */ | |
1703 | return crisv32_genreg_names[regno]; | |
1704 | } | |
1705 | else if (regno >= NUM_GENREGS && regno < (NUM_GENREGS + NUM_SPECREGS)) | |
1706 | { | |
35488783 | 1707 | return cris_special_register_name (gdbarch, regno); |
c600d464 | 1708 | } |
d93859e2 | 1709 | else if (regno == gdbarch_pc_regnum (gdbarch)) |
c600d464 OF |
1710 | { |
1711 | return "pc"; | |
1712 | } | |
1713 | else if (regno >= S0_REGNUM && regno <= S15_REGNUM) | |
1714 | { | |
1715 | return crisv32_sreg_names[regno - S0_REGNUM]; | |
1716 | } | |
2e4b5889 OF |
1717 | else |
1718 | { | |
1719 | /* Invalid register. */ | |
1720 | return NULL; | |
29134980 | 1721 | } |
29134980 OF |
1722 | } |
1723 | ||
a5f6c8f5 OF |
1724 | /* Convert DWARF register number REG to the appropriate register |
1725 | number used by GDB. */ | |
1726 | ||
2e4b5889 | 1727 | static int |
d3f73121 | 1728 | cris_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg) |
29134980 | 1729 | { |
a5f6c8f5 OF |
1730 | /* We need to re-map a couple of registers (SRP is 16 in Dwarf-2 register |
1731 | numbering, MOF is 18). | |
1732 | Adapted from gcc/config/cris/cris.h. */ | |
1733 | static int cris_dwarf_regmap[] = { | |
1734 | 0, 1, 2, 3, | |
1735 | 4, 5, 6, 7, | |
1736 | 8, 9, 10, 11, | |
1737 | 12, 13, 14, 15, | |
1738 | 27, -1, -1, -1, | |
1739 | -1, -1, -1, 23, | |
1740 | -1, -1, -1, 27, | |
1741 | -1, -1, -1, -1 | |
1742 | }; | |
1743 | int regnum = -1; | |
1744 | ||
1745 | if (reg >= 0 && reg < ARRAY_SIZE (cris_dwarf_regmap)) | |
1746 | regnum = cris_dwarf_regmap[reg]; | |
1747 | ||
a5f6c8f5 OF |
1748 | return regnum; |
1749 | } | |
1750 | ||
1751 | /* DWARF-2 frame support. */ | |
1752 | ||
1753 | static void | |
1754 | cris_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, | |
aff37fc1 | 1755 | struct dwarf2_frame_state_reg *reg, |
4a4e5149 | 1756 | struct frame_info *this_frame) |
a5f6c8f5 OF |
1757 | { |
1758 | /* The return address column. */ | |
7fbe2eba | 1759 | if (regnum == gdbarch_pc_regnum (gdbarch)) |
a5f6c8f5 OF |
1760 | reg->how = DWARF2_FRAME_REG_RA; |
1761 | ||
1762 | /* The call frame address. */ | |
7fbe2eba | 1763 | else if (regnum == gdbarch_sp_regnum (gdbarch)) |
a5f6c8f5 | 1764 | reg->how = DWARF2_FRAME_REG_CFA; |
29134980 OF |
1765 | } |
1766 | ||
2e4b5889 OF |
1767 | /* Extract from an array regbuf containing the raw register state a function |
1768 | return value of type type, and copy that, in virtual format, into | |
1769 | valbuf. */ | |
1770 | ||
1771 | /* In the CRIS ABI, R10 and R11 are used to store return values. */ | |
29134980 | 1772 | |
2e4b5889 OF |
1773 | static void |
1774 | cris_extract_return_value (struct type *type, struct regcache *regcache, | |
948f8e3d | 1775 | gdb_byte *valbuf) |
29134980 | 1776 | { |
ac7936df | 1777 | struct gdbarch *gdbarch = regcache->arch (); |
e17a4113 | 1778 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
2e4b5889 | 1779 | ULONGEST val; |
bad43aa5 | 1780 | int len = TYPE_LENGTH (type); |
29134980 | 1781 | |
bad43aa5 | 1782 | if (len <= 4) |
29134980 | 1783 | { |
2e4b5889 OF |
1784 | /* Get the return value from R10. */ |
1785 | regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val); | |
bad43aa5 | 1786 | store_unsigned_integer (valbuf, len, byte_order, val); |
29134980 | 1787 | } |
bad43aa5 | 1788 | else if (len <= 8) |
29134980 | 1789 | { |
2e4b5889 OF |
1790 | /* Get the return value from R10 and R11. */ |
1791 | regcache_cooked_read_unsigned (regcache, ARG1_REGNUM, &val); | |
e17a4113 | 1792 | store_unsigned_integer (valbuf, 4, byte_order, val); |
2e4b5889 | 1793 | regcache_cooked_read_unsigned (regcache, ARG2_REGNUM, &val); |
948f8e3d | 1794 | store_unsigned_integer (valbuf + 4, len - 4, byte_order, val); |
29134980 | 1795 | } |
2e4b5889 | 1796 | else |
8a3fe4f8 | 1797 | error (_("cris_extract_return_value: type length too large")); |
2e4b5889 OF |
1798 | } |
1799 | ||
b4206d25 OF |
1800 | /* Handle the CRIS return value convention. */ |
1801 | ||
1802 | static enum return_value_convention | |
6a3a010b | 1803 | cris_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
1804 | struct type *type, struct regcache *regcache, |
1805 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
b4206d25 OF |
1806 | { |
1807 | if (TYPE_CODE (type) == TYPE_CODE_STRUCT | |
1808 | || TYPE_CODE (type) == TYPE_CODE_UNION | |
1809 | || TYPE_LENGTH (type) > 8) | |
1810 | /* Structs, unions, and anything larger than 8 bytes (2 registers) | |
1811 | goes on the stack. */ | |
1812 | return RETURN_VALUE_STRUCT_CONVENTION; | |
1813 | ||
1814 | if (readbuf) | |
1815 | cris_extract_return_value (type, regcache, readbuf); | |
1816 | if (writebuf) | |
1817 | cris_store_return_value (type, regcache, writebuf); | |
1818 | ||
1819 | return RETURN_VALUE_REGISTER_CONVENTION; | |
1820 | } | |
1821 | ||
29134980 OF |
1822 | /* Calculates a value that measures how good inst_args constraints an |
1823 | instruction. It stems from cris_constraint, found in cris-dis.c. */ | |
1824 | ||
1825 | static int | |
948f8e3d | 1826 | constraint (unsigned int insn, const char *inst_args, |
29134980 OF |
1827 | inst_env_type *inst_env) |
1828 | { | |
1829 | int retval = 0; | |
1830 | int tmp, i; | |
1831 | ||
948f8e3d | 1832 | const gdb_byte *s = (const gdb_byte *) inst_args; |
29134980 OF |
1833 | |
1834 | for (; *s; s++) | |
1835 | switch (*s) | |
1836 | { | |
1837 | case 'm': | |
1838 | if ((insn & 0x30) == 0x30) | |
1839 | return -1; | |
1840 | break; | |
1841 | ||
1842 | case 'S': | |
1843 | /* A prefix operand. */ | |
1844 | if (inst_env->prefix_found) | |
1845 | break; | |
1846 | else | |
1847 | return -1; | |
1848 | ||
1849 | case 'B': | |
1850 | /* A "push" prefix. (This check was REMOVED by san 970921.) Check for | |
1851 | valid "push" size. In case of special register, it may be != 4. */ | |
1852 | if (inst_env->prefix_found) | |
1853 | break; | |
1854 | else | |
1855 | return -1; | |
1856 | ||
1857 | case 'D': | |
1858 | retval = (((insn >> 0xC) & 0xF) == (insn & 0xF)); | |
1859 | if (!retval) | |
1860 | return -1; | |
1861 | else | |
1862 | retval += 4; | |
1863 | break; | |
1864 | ||
1865 | case 'P': | |
1866 | tmp = (insn >> 0xC) & 0xF; | |
fa4e4598 OF |
1867 | |
1868 | for (i = 0; cris_spec_regs[i].name != NULL; i++) | |
1869 | { | |
1870 | /* Since we match four bits, we will give a value of | |
1871 | 4 - 1 = 3 in a match. If there is a corresponding | |
1872 | exact match of a special register in another pattern, it | |
1873 | will get a value of 4, which will be higher. This should | |
1874 | be correct in that an exact pattern would match better that | |
1875 | a general pattern. | |
1876 | Note that there is a reason for not returning zero; the | |
1877 | pattern for "clear" is partly matched in the bit-pattern | |
1878 | (the two lower bits must be zero), while the bit-pattern | |
1879 | for a move from a special register is matched in the | |
1880 | register constraint. | |
1881 | This also means we will will have a race condition if | |
1882 | there is a partly match in three bits in the bit pattern. */ | |
1883 | if (tmp == cris_spec_regs[i].number) | |
1884 | { | |
1885 | retval += 3; | |
1886 | break; | |
1887 | } | |
1888 | } | |
1889 | ||
1890 | if (cris_spec_regs[i].name == NULL) | |
29134980 OF |
1891 | return -1; |
1892 | break; | |
1893 | } | |
1894 | return retval; | |
1895 | } | |
1896 | ||
1897 | /* Returns the number of bits set in the variable value. */ | |
1898 | ||
1899 | static int | |
1900 | number_of_bits (unsigned int value) | |
1901 | { | |
1902 | int number_of_bits = 0; | |
1903 | ||
1904 | while (value != 0) | |
1905 | { | |
1906 | number_of_bits += 1; | |
1907 | value &= (value - 1); | |
1908 | } | |
1909 | return number_of_bits; | |
1910 | } | |
1911 | ||
1912 | /* Finds the address that should contain the single step breakpoint(s). | |
1913 | It stems from code in cris-dis.c. */ | |
1914 | ||
1915 | static int | |
1916 | find_cris_op (unsigned short insn, inst_env_type *inst_env) | |
1917 | { | |
1918 | int i; | |
1919 | int max_level_of_match = -1; | |
1920 | int max_matched = -1; | |
1921 | int level_of_match; | |
1922 | ||
1923 | for (i = 0; cris_opcodes[i].name != NULL; i++) | |
1924 | { | |
1925 | if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match) | |
c600d464 OF |
1926 | && ((cris_opcodes[i].lose & insn) == 0) |
1927 | /* Only CRISv10 instructions, please. */ | |
1928 | && (cris_opcodes[i].applicable_version != cris_ver_v32p)) | |
29134980 OF |
1929 | { |
1930 | level_of_match = constraint (insn, cris_opcodes[i].args, inst_env); | |
1931 | if (level_of_match >= 0) | |
1932 | { | |
1933 | level_of_match += | |
1934 | number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose); | |
1935 | if (level_of_match > max_level_of_match) | |
1936 | { | |
1937 | max_matched = i; | |
1938 | max_level_of_match = level_of_match; | |
1939 | if (level_of_match == 16) | |
1940 | { | |
1941 | /* All bits matched, cannot find better. */ | |
1942 | break; | |
1943 | } | |
1944 | } | |
1945 | } | |
1946 | } | |
1947 | } | |
1948 | return max_matched; | |
1949 | } | |
1950 | ||
1951 | /* Attempts to find single-step breakpoints. Returns -1 on failure which is | |
1952 | actually an internal error. */ | |
1953 | ||
1954 | static int | |
5b6e2eee | 1955 | find_step_target (struct regcache *regcache, inst_env_type *inst_env) |
29134980 OF |
1956 | { |
1957 | int i; | |
1958 | int offset; | |
1959 | unsigned short insn; | |
ac7936df | 1960 | struct gdbarch *gdbarch = regcache->arch (); |
e17a4113 | 1961 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
29134980 OF |
1962 | |
1963 | /* Create a local register image and set the initial state. */ | |
1964 | for (i = 0; i < NUM_GENREGS; i++) | |
1965 | { | |
0b1b3e42 | 1966 | inst_env->reg[i] = |
5b6e2eee | 1967 | (unsigned long) regcache_raw_get_unsigned (regcache, i); |
29134980 OF |
1968 | } |
1969 | offset = NUM_GENREGS; | |
1970 | for (i = 0; i < NUM_SPECREGS; i++) | |
1971 | { | |
0b1b3e42 | 1972 | inst_env->preg[i] = |
5b6e2eee | 1973 | (unsigned long) regcache_raw_get_unsigned (regcache, offset + i); |
29134980 OF |
1974 | } |
1975 | inst_env->branch_found = 0; | |
1976 | inst_env->slot_needed = 0; | |
1977 | inst_env->delay_slot_pc_active = 0; | |
1978 | inst_env->prefix_found = 0; | |
1979 | inst_env->invalid = 0; | |
1980 | inst_env->xflag_found = 0; | |
1981 | inst_env->disable_interrupt = 0; | |
e17a4113 | 1982 | inst_env->byte_order = byte_order; |
29134980 OF |
1983 | |
1984 | /* Look for a step target. */ | |
1985 | do | |
1986 | { | |
1987 | /* Read an instruction from the client. */ | |
3e8c568d | 1988 | insn = read_memory_unsigned_integer |
e17a4113 | 1989 | (inst_env->reg[gdbarch_pc_regnum (gdbarch)], 2, byte_order); |
29134980 OF |
1990 | |
1991 | /* If the instruction is not in a delay slot the new content of the | |
1992 | PC is [PC] + 2. If the instruction is in a delay slot it is not | |
1993 | that simple. Since a instruction in a delay slot cannot change | |
1994 | the content of the PC, it does not matter what value PC will have. | |
1995 | Just make sure it is a valid instruction. */ | |
1996 | if (!inst_env->delay_slot_pc_active) | |
1997 | { | |
7fbe2eba | 1998 | inst_env->reg[gdbarch_pc_regnum (gdbarch)] += 2; |
29134980 OF |
1999 | } |
2000 | else | |
2001 | { | |
2002 | inst_env->delay_slot_pc_active = 0; | |
7fbe2eba | 2003 | inst_env->reg[gdbarch_pc_regnum (gdbarch)] |
3e8c568d | 2004 | = inst_env->delay_slot_pc; |
29134980 OF |
2005 | } |
2006 | /* Analyse the present instruction. */ | |
2007 | i = find_cris_op (insn, inst_env); | |
2008 | if (i == -1) | |
2009 | { | |
2010 | inst_env->invalid = 1; | |
2011 | } | |
2012 | else | |
2013 | { | |
be8626e0 | 2014 | cris_gdb_func (gdbarch, cris_opcodes[i].op, insn, inst_env); |
29134980 OF |
2015 | } |
2016 | } while (!inst_env->invalid | |
2017 | && (inst_env->prefix_found || inst_env->xflag_found | |
2018 | || inst_env->slot_needed)); | |
2019 | return i; | |
2020 | } | |
2021 | ||
2022 | /* There is no hardware single-step support. The function find_step_target | |
0963b4bd | 2023 | digs through the opcodes in order to find all possible targets. |
29134980 OF |
2024 | Either one ordinary target or two targets for branches may be found. */ |
2025 | ||
a0ff9e1a | 2026 | static std::vector<CORE_ADDR> |
f5ea389a | 2027 | cris_software_single_step (struct regcache *regcache) |
29134980 | 2028 | { |
ac7936df | 2029 | struct gdbarch *gdbarch = regcache->arch (); |
29134980 | 2030 | inst_env_type inst_env; |
a0ff9e1a | 2031 | std::vector<CORE_ADDR> next_pcs; |
8181d85f | 2032 | |
e0cd558a UW |
2033 | /* Analyse the present instruction environment and insert |
2034 | breakpoints. */ | |
5b6e2eee | 2035 | int status = find_step_target (regcache, &inst_env); |
e0cd558a | 2036 | if (status == -1) |
29134980 | 2037 | { |
e0cd558a UW |
2038 | /* Could not find a target. Things are likely to go downhill |
2039 | from here. */ | |
2040 | warning (_("CRIS software single step could not find a step target.")); | |
29134980 OF |
2041 | } |
2042 | else | |
e0cd558a UW |
2043 | { |
2044 | /* Insert at most two breakpoints. One for the next PC content | |
2045 | and possibly another one for a branch, jump, etc. */ | |
a6d9a66e UW |
2046 | CORE_ADDR next_pc |
2047 | = (CORE_ADDR) inst_env.reg[gdbarch_pc_regnum (gdbarch)]; | |
93f9a11f | 2048 | |
a0ff9e1a | 2049 | next_pcs.push_back (next_pc); |
e0cd558a UW |
2050 | if (inst_env.branch_found |
2051 | && (CORE_ADDR) inst_env.branch_break_address != next_pc) | |
2052 | { | |
2053 | CORE_ADDR branch_target_address | |
2054 | = (CORE_ADDR) inst_env.branch_break_address; | |
93f9a11f | 2055 | |
a0ff9e1a | 2056 | next_pcs.push_back (branch_target_address); |
e0cd558a UW |
2057 | } |
2058 | } | |
e6590a1b | 2059 | |
93f9a11f | 2060 | return next_pcs; |
29134980 OF |
2061 | } |
2062 | ||
2063 | /* Calculates the prefix value for quick offset addressing mode. */ | |
2064 | ||
a78f21af | 2065 | static void |
29134980 OF |
2066 | quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env) |
2067 | { | |
2068 | /* It's invalid to be in a delay slot. You can't have a prefix to this | |
2069 | instruction (not 100% sure). */ | |
2070 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2071 | { | |
2072 | inst_env->invalid = 1; | |
2073 | return; | |
2074 | } | |
2075 | ||
2076 | inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)]; | |
2077 | inst_env->prefix_value += cris_get_bdap_quick_offset (inst); | |
2078 | ||
2079 | /* A prefix doesn't change the xflag_found. But the rest of the flags | |
2080 | need updating. */ | |
2081 | inst_env->slot_needed = 0; | |
2082 | inst_env->prefix_found = 1; | |
2083 | } | |
2084 | ||
2085 | /* Updates the autoincrement register. The size of the increment is derived | |
2086 | from the size of the operation. The PC is always kept aligned on even | |
2087 | word addresses. */ | |
2088 | ||
a78f21af | 2089 | static void |
29134980 OF |
2090 | process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env) |
2091 | { | |
2092 | if (size == INST_BYTE_SIZE) | |
2093 | { | |
2094 | inst_env->reg[cris_get_operand1 (inst)] += 1; | |
2095 | ||
2096 | /* The PC must be word aligned, so increase the PC with one | |
2097 | word even if the size is byte. */ | |
2098 | if (cris_get_operand1 (inst) == REG_PC) | |
2099 | { | |
2100 | inst_env->reg[REG_PC] += 1; | |
2101 | } | |
2102 | } | |
2103 | else if (size == INST_WORD_SIZE) | |
2104 | { | |
2105 | inst_env->reg[cris_get_operand1 (inst)] += 2; | |
2106 | } | |
2107 | else if (size == INST_DWORD_SIZE) | |
2108 | { | |
2109 | inst_env->reg[cris_get_operand1 (inst)] += 4; | |
2110 | } | |
2111 | else | |
2112 | { | |
2113 | /* Invalid size. */ | |
2114 | inst_env->invalid = 1; | |
2115 | } | |
2116 | } | |
2117 | ||
2a9ecef2 OF |
2118 | /* Just a forward declaration. */ |
2119 | ||
a78f21af | 2120 | static unsigned long get_data_from_address (unsigned short *inst, |
e17a4113 UW |
2121 | CORE_ADDR address, |
2122 | enum bfd_endian byte_order); | |
2a9ecef2 | 2123 | |
29134980 OF |
2124 | /* Calculates the prefix value for the general case of offset addressing |
2125 | mode. */ | |
2126 | ||
a78f21af | 2127 | static void |
29134980 OF |
2128 | bdap_prefix (unsigned short inst, inst_env_type *inst_env) |
2129 | { | |
29134980 OF |
2130 | /* It's invalid to be in a delay slot. */ |
2131 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2132 | { | |
2133 | inst_env->invalid = 1; | |
2134 | return; | |
2135 | } | |
2136 | ||
fa4e4598 OF |
2137 | /* The calculation of prefix_value used to be after process_autoincrement, |
2138 | but that fails for an instruction such as jsr [$r0+12] which is encoded | |
2139 | as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it | |
2140 | mustn't be incremented until we have read it and what it points at. */ | |
29134980 OF |
2141 | inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)]; |
2142 | ||
2143 | /* The offset is an indirection of the contents of the operand1 register. */ | |
2144 | inst_env->prefix_value += | |
e17a4113 UW |
2145 | get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)], |
2146 | inst_env->byte_order); | |
2a9ecef2 | 2147 | |
fa4e4598 OF |
2148 | if (cris_get_mode (inst) == AUTOINC_MODE) |
2149 | { | |
2150 | process_autoincrement (cris_get_size (inst), inst, inst_env); | |
2151 | } | |
2152 | ||
29134980 OF |
2153 | /* A prefix doesn't change the xflag_found. But the rest of the flags |
2154 | need updating. */ | |
2155 | inst_env->slot_needed = 0; | |
2156 | inst_env->prefix_found = 1; | |
2157 | } | |
2158 | ||
2159 | /* Calculates the prefix value for the index addressing mode. */ | |
2160 | ||
a78f21af | 2161 | static void |
29134980 OF |
2162 | biap_prefix (unsigned short inst, inst_env_type *inst_env) |
2163 | { | |
2164 | /* It's invalid to be in a delay slot. I can't see that it's possible to | |
2165 | have a prefix to this instruction. So I will treat this as invalid. */ | |
2166 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2167 | { | |
2168 | inst_env->invalid = 1; | |
2169 | return; | |
2170 | } | |
2171 | ||
2172 | inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)]; | |
2173 | ||
2174 | /* The offset is the operand2 value shifted the size of the instruction | |
2175 | to the left. */ | |
2176 | inst_env->prefix_value += | |
2177 | inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst); | |
2178 | ||
2179 | /* If the PC is operand1 (base) the address used is the address after | |
2180 | the main instruction, i.e. address + 2 (the PC is already compensated | |
2181 | for the prefix operation). */ | |
2182 | if (cris_get_operand1 (inst) == REG_PC) | |
2183 | { | |
2184 | inst_env->prefix_value += 2; | |
2185 | } | |
2186 | ||
2187 | /* A prefix doesn't change the xflag_found. But the rest of the flags | |
2188 | need updating. */ | |
2189 | inst_env->slot_needed = 0; | |
2190 | inst_env->xflag_found = 0; | |
2191 | inst_env->prefix_found = 1; | |
2192 | } | |
2193 | ||
2194 | /* Calculates the prefix value for the double indirect addressing mode. */ | |
2195 | ||
a78f21af | 2196 | static void |
29134980 OF |
2197 | dip_prefix (unsigned short inst, inst_env_type *inst_env) |
2198 | { | |
2199 | ||
2200 | CORE_ADDR address; | |
2201 | ||
2202 | /* It's invalid to be in a delay slot. */ | |
2203 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2204 | { | |
2205 | inst_env->invalid = 1; | |
2206 | return; | |
2207 | } | |
2208 | ||
2209 | /* The prefix value is one dereference of the contents of the operand1 | |
2210 | register. */ | |
2211 | address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)]; | |
e17a4113 UW |
2212 | inst_env->prefix_value |
2213 | = read_memory_unsigned_integer (address, 4, inst_env->byte_order); | |
29134980 OF |
2214 | |
2215 | /* Check if the mode is autoincrement. */ | |
2216 | if (cris_get_mode (inst) == AUTOINC_MODE) | |
2217 | { | |
2218 | inst_env->reg[cris_get_operand1 (inst)] += 4; | |
2219 | } | |
2220 | ||
2221 | /* A prefix doesn't change the xflag_found. But the rest of the flags | |
2222 | need updating. */ | |
2223 | inst_env->slot_needed = 0; | |
2224 | inst_env->xflag_found = 0; | |
2225 | inst_env->prefix_found = 1; | |
2226 | } | |
2227 | ||
2228 | /* Finds the destination for a branch with 8-bits offset. */ | |
2229 | ||
a78f21af | 2230 | static void |
29134980 OF |
2231 | eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env) |
2232 | { | |
2233 | ||
2234 | short offset; | |
2235 | ||
2236 | /* If we have a prefix or are in a delay slot it's bad. */ | |
2237 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2238 | { | |
2239 | inst_env->invalid = 1; | |
2240 | return; | |
2241 | } | |
2242 | ||
2243 | /* We have a branch, find out where the branch will land. */ | |
2244 | offset = cris_get_branch_short_offset (inst); | |
2245 | ||
2246 | /* Check if the offset is signed. */ | |
2247 | if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK) | |
2248 | { | |
2249 | offset |= 0xFF00; | |
2250 | } | |
2251 | ||
2252 | /* The offset ends with the sign bit, set it to zero. The address | |
2253 | should always be word aligned. */ | |
2254 | offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK; | |
2255 | ||
2256 | inst_env->branch_found = 1; | |
2257 | inst_env->branch_break_address = inst_env->reg[REG_PC] + offset; | |
2258 | ||
2259 | inst_env->slot_needed = 1; | |
2260 | inst_env->prefix_found = 0; | |
2261 | inst_env->xflag_found = 0; | |
2262 | inst_env->disable_interrupt = 1; | |
2263 | } | |
2264 | ||
2265 | /* Finds the destination for a branch with 16-bits offset. */ | |
2266 | ||
a78f21af | 2267 | static void |
29134980 OF |
2268 | sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env) |
2269 | { | |
2270 | short offset; | |
2271 | ||
2272 | /* If we have a prefix or is in a delay slot it's bad. */ | |
2273 | if (inst_env->slot_needed || inst_env->prefix_found) | |
2274 | { | |
2275 | inst_env->invalid = 1; | |
2276 | return; | |
2277 | } | |
2278 | ||
2279 | /* We have a branch, find out the offset for the branch. */ | |
0963b4bd MS |
2280 | offset = read_memory_integer (inst_env->reg[REG_PC], 2, |
2281 | inst_env->byte_order); | |
29134980 OF |
2282 | |
2283 | /* The instruction is one word longer than normal, so add one word | |
2284 | to the PC. */ | |
2285 | inst_env->reg[REG_PC] += 2; | |
2286 | ||
2287 | inst_env->branch_found = 1; | |
2288 | inst_env->branch_break_address = inst_env->reg[REG_PC] + offset; | |
2289 | ||
2290 | ||
2291 | inst_env->slot_needed = 1; | |
2292 | inst_env->prefix_found = 0; | |
2293 | inst_env->xflag_found = 0; | |
2294 | inst_env->disable_interrupt = 1; | |
2295 | } | |
2296 | ||
2297 | /* Handles the ABS instruction. */ | |
2298 | ||
a78f21af | 2299 | static void |
29134980 OF |
2300 | abs_op (unsigned short inst, inst_env_type *inst_env) |
2301 | { | |
2302 | ||
2303 | long value; | |
2304 | ||
2305 | /* ABS can't have a prefix, so it's bad if it does. */ | |
2306 | if (inst_env->prefix_found) | |
2307 | { | |
2308 | inst_env->invalid = 1; | |
2309 | return; | |
2310 | } | |
2311 | ||
2312 | /* Check if the operation affects the PC. */ | |
2313 | if (cris_get_operand2 (inst) == REG_PC) | |
2314 | { | |
2315 | ||
2316 | /* It's invalid to change to the PC if we are in a delay slot. */ | |
2317 | if (inst_env->slot_needed) | |
2318 | { | |
2319 | inst_env->invalid = 1; | |
2320 | return; | |
2321 | } | |
2322 | ||
2323 | value = (long) inst_env->reg[REG_PC]; | |
2324 | ||
2325 | /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */ | |
2326 | if (value != SIGNED_DWORD_MASK) | |
2327 | { | |
2328 | value = -value; | |
2329 | inst_env->reg[REG_PC] = (long) value; | |
2330 | } | |
2331 | } | |
2332 | ||
2333 | inst_env->slot_needed = 0; | |
2334 | inst_env->prefix_found = 0; | |
2335 | inst_env->xflag_found = 0; | |
2336 | inst_env->disable_interrupt = 0; | |
2337 | } | |
2338 | ||
2339 | /* Handles the ADDI instruction. */ | |
2340 | ||
a78f21af | 2341 | static void |
29134980 OF |
2342 | addi_op (unsigned short inst, inst_env_type *inst_env) |
2343 | { | |
2344 | /* It's invalid to have the PC as base register. And ADDI can't have | |
2345 | a prefix. */ | |
2346 | if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC)) | |
2347 | { | |
2348 | inst_env->invalid = 1; | |
2349 | return; | |
2350 | } | |
2351 | ||
2352 | inst_env->slot_needed = 0; | |
2353 | inst_env->prefix_found = 0; | |
2354 | inst_env->xflag_found = 0; | |
2355 | inst_env->disable_interrupt = 0; | |
2356 | } | |
2357 | ||
2358 | /* Handles the ASR instruction. */ | |
2359 | ||
a78f21af | 2360 | static void |
29134980 OF |
2361 | asr_op (unsigned short inst, inst_env_type *inst_env) |
2362 | { | |
2363 | int shift_steps; | |
2364 | unsigned long value; | |
2365 | unsigned long signed_extend_mask = 0; | |
2366 | ||
2367 | /* ASR can't have a prefix, so check that it doesn't. */ | |
2368 | if (inst_env->prefix_found) | |
2369 | { | |
2370 | inst_env->invalid = 1; | |
2371 | return; | |
2372 | } | |
2373 | ||
2374 | /* Check if the PC is the target register. */ | |
2375 | if (cris_get_operand2 (inst) == REG_PC) | |
2376 | { | |
2377 | /* It's invalid to change the PC in a delay slot. */ | |
2378 | if (inst_env->slot_needed) | |
2379 | { | |
2380 | inst_env->invalid = 1; | |
2381 | return; | |
2382 | } | |
2383 | /* Get the number of bits to shift. */ | |
0963b4bd MS |
2384 | shift_steps |
2385 | = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]); | |
29134980 OF |
2386 | value = inst_env->reg[REG_PC]; |
2387 | ||
2388 | /* Find out how many bits the operation should apply to. */ | |
2389 | if (cris_get_size (inst) == INST_BYTE_SIZE) | |
2390 | { | |
2391 | if (value & SIGNED_BYTE_MASK) | |
2392 | { | |
2393 | signed_extend_mask = 0xFF; | |
2394 | signed_extend_mask = signed_extend_mask >> shift_steps; | |
2395 | signed_extend_mask = ~signed_extend_mask; | |
2396 | } | |
2397 | value = value >> shift_steps; | |
2398 | value |= signed_extend_mask; | |
2399 | value &= 0xFF; | |
2400 | inst_env->reg[REG_PC] &= 0xFFFFFF00; | |
2401 | inst_env->reg[REG_PC] |= value; | |
2402 | } | |
2403 | else if (cris_get_size (inst) == INST_WORD_SIZE) | |
2404 | { | |
2405 | if (value & SIGNED_WORD_MASK) | |
2406 | { | |
2407 | signed_extend_mask = 0xFFFF; | |
2408 | signed_extend_mask = signed_extend_mask >> shift_steps; | |
2409 | signed_extend_mask = ~signed_extend_mask; | |
2410 | } | |
2411 | value = value >> shift_steps; | |
2412 | value |= signed_extend_mask; | |
2413 | value &= 0xFFFF; | |
2414 | inst_env->reg[REG_PC] &= 0xFFFF0000; | |
2415 | inst_env->reg[REG_PC] |= value; | |
2416 | } | |
2417 | else if (cris_get_size (inst) == INST_DWORD_SIZE) | |
2418 | { | |
2419 | if (value & SIGNED_DWORD_MASK) | |
2420 | { | |
2421 | signed_extend_mask = 0xFFFFFFFF; | |
2422 | signed_extend_mask = signed_extend_mask >> shift_steps; | |
2423 | signed_extend_mask = ~signed_extend_mask; | |
2424 | } | |
2425 | value = value >> shift_steps; | |
2426 | value |= signed_extend_mask; | |
2427 | inst_env->reg[REG_PC] = value; | |
2428 | } | |
2429 | } | |
2430 | inst_env->slot_needed = 0; | |
2431 | inst_env->prefix_found = 0; | |
2432 | inst_env->xflag_found = 0; | |
2433 | inst_env->disable_interrupt = 0; | |
2434 | } | |
2435 | ||
2436 | /* Handles the ASRQ instruction. */ | |
2437 | ||
a78f21af | 2438 | static void |
29134980 OF |
2439 | asrq_op (unsigned short inst, inst_env_type *inst_env) |
2440 | { | |
2441 | ||
2442 | int shift_steps; | |
2443 | unsigned long value; | |
2444 | unsigned long signed_extend_mask = 0; | |
2445 | ||
2446 | /* ASRQ can't have a prefix, so check that it doesn't. */ | |
2447 | if (inst_env->prefix_found) | |
2448 | { | |
2449 | inst_env->invalid = 1; | |
2450 | return; | |
2451 | } | |
2452 | ||
2453 | /* Check if the PC is the target register. */ | |
2454 | if (cris_get_operand2 (inst) == REG_PC) | |
2455 | { | |
2456 | ||
2457 | /* It's invalid to change the PC in a delay slot. */ | |
2458 | if (inst_env->slot_needed) | |
2459 | { | |
2460 | inst_env->invalid = 1; | |
2461 | return; | |
2462 | } | |
2463 | /* The shift size is given as a 5 bit quick value, i.e. we don't | |
b021a221 | 2464 | want the sign bit of the quick value. */ |
29134980 OF |
2465 | shift_steps = cris_get_asr_shift_steps (inst); |
2466 | value = inst_env->reg[REG_PC]; | |
2467 | if (value & SIGNED_DWORD_MASK) | |
2468 | { | |
2469 | signed_extend_mask = 0xFFFFFFFF; | |
2470 | signed_extend_mask = signed_extend_mask >> shift_steps; | |
2471 | signed_extend_mask = ~signed_extend_mask; | |
2472 | } | |
2473 | value = value >> shift_steps; | |
2474 | value |= signed_extend_mask; | |
2475 | inst_env->reg[REG_PC] = value; | |
2476 | } | |
2477 | inst_env->slot_needed = 0; | |
2478 | inst_env->prefix_found = 0; | |
2479 | inst_env->xflag_found = 0; | |
2480 | inst_env->disable_interrupt = 0; | |
2481 | } | |
2482 | ||
2483 | /* Handles the AX, EI and SETF instruction. */ | |
2484 | ||
a78f21af | 2485 | static void |
29134980 OF |
2486 | ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env) |
2487 | { | |
2488 | if (inst_env->prefix_found) | |
2489 | { | |
2490 | inst_env->invalid = 1; | |
2491 | return; | |
2492 | } | |
2493 | /* Check if the instruction is setting the X flag. */ | |
2494 | if (cris_is_xflag_bit_on (inst)) | |
2495 | { | |
2496 | inst_env->xflag_found = 1; | |
2497 | } | |
2498 | else | |
2499 | { | |
2500 | inst_env->xflag_found = 0; | |
2501 | } | |
2502 | inst_env->slot_needed = 0; | |
2503 | inst_env->prefix_found = 0; | |
2504 | inst_env->disable_interrupt = 1; | |
2505 | } | |
2506 | ||
2507 | /* Checks if the instruction is in assign mode. If so, it updates the assign | |
2508 | register. Note that check_assign assumes that the caller has checked that | |
2509 | there is a prefix to this instruction. The mode check depends on this. */ | |
2510 | ||
a78f21af | 2511 | static void |
29134980 OF |
2512 | check_assign (unsigned short inst, inst_env_type *inst_env) |
2513 | { | |
2514 | /* Check if it's an assign addressing mode. */ | |
2515 | if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE) | |
2516 | { | |
2517 | /* Assign the prefix value to operand 1. */ | |
2518 | inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value; | |
2519 | } | |
2520 | } | |
2521 | ||
2522 | /* Handles the 2-operand BOUND instruction. */ | |
2523 | ||
a78f21af | 2524 | static void |
29134980 OF |
2525 | two_operand_bound_op (unsigned short inst, inst_env_type *inst_env) |
2526 | { | |
2527 | /* It's invalid to have the PC as the index operand. */ | |
2528 | if (cris_get_operand2 (inst) == REG_PC) | |
2529 | { | |
2530 | inst_env->invalid = 1; | |
2531 | return; | |
2532 | } | |
2533 | /* Check if we have a prefix. */ | |
2534 | if (inst_env->prefix_found) | |
2535 | { | |
2536 | check_assign (inst, inst_env); | |
2537 | } | |
2538 | /* Check if this is an autoincrement mode. */ | |
2539 | else if (cris_get_mode (inst) == AUTOINC_MODE) | |
2540 | { | |
2541 | /* It's invalid to change the PC in a delay slot. */ | |
2542 | if (inst_env->slot_needed) | |
2543 | { | |
2544 | inst_env->invalid = 1; | |
2545 | return; | |
2546 | } | |
2547 | process_autoincrement (cris_get_size (inst), inst, inst_env); | |
2548 | } | |
2549 | inst_env->slot_needed = 0; | |
2550 | inst_env->prefix_found = 0; | |
2551 | inst_env->xflag_found = 0; | |
2552 | inst_env->disable_interrupt = 0; | |
2553 | } | |
2554 | ||
2555 | /* Handles the 3-operand BOUND instruction. */ | |
2556 | ||
a78f21af | 2557 | static void |
29134980 OF |
2558 | three_operand_bound_op (unsigned short inst, inst_env_type *inst_env) |
2559 | { | |
2560 | /* It's an error if we haven't got a prefix. And it's also an error | |
2561 | if the PC is the destination register. */ | |
2562 | if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC)) | |
2563 | { | |
2564 | inst_env->invalid = 1; | |
2565 | return; | |
2566 | } | |
2567 | inst_env->slot_needed = 0; | |
2568 | inst_env->prefix_found = 0; | |
2569 | inst_env->xflag_found = 0; | |
2570 | inst_env->disable_interrupt = 0; | |
2571 | } | |
2572 | ||
2573 | /* Clears the status flags in inst_env. */ | |
2574 | ||
a78f21af | 2575 | static void |
29134980 OF |
2576 | btst_nop_op (unsigned short inst, inst_env_type *inst_env) |
2577 | { | |
2578 | /* It's an error if we have got a prefix. */ | |
2579 | if (inst_env->prefix_found) | |
2580 | { | |
2581 | inst_env->invalid = 1; | |
2582 | return; | |
2583 | } | |
2584 | ||
2585 | inst_env->slot_needed = 0; | |
2586 | inst_env->prefix_found = 0; | |
2587 | inst_env->xflag_found = 0; | |
2588 | inst_env->disable_interrupt = 0; | |
2589 | } | |
2590 | ||
2591 | /* Clears the status flags in inst_env. */ | |
2592 | ||
a78f21af | 2593 | static void |
29134980 OF |
2594 | clearf_di_op (unsigned short inst, inst_env_type *inst_env) |
2595 | { | |
2596 | /* It's an error if we have got a prefix. */ | |
2597 | if (inst_env->prefix_found) | |
2598 | { | |
2599 | inst_env->invalid = 1; | |
2600 | return; | |
2601 | } | |
2602 | ||
2603 | inst_env->slot_needed = 0; | |
2604 | inst_env->prefix_found = 0; | |
2605 | inst_env->xflag_found = 0; | |
2606 | inst_env->disable_interrupt = 1; | |
2607 | } | |
2608 | ||
2609 | /* Handles the CLEAR instruction if it's in register mode. */ | |
2610 | ||
a78f21af | 2611 | static void |
29134980 OF |
2612 | reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env) |
2613 | { | |
2614 | /* Check if the target is the PC. */ | |
2615 | if (cris_get_operand2 (inst) == REG_PC) | |
2616 | { | |
2617 | /* The instruction will clear the instruction's size bits. */ | |
2618 | int clear_size = cris_get_clear_size (inst); | |
2619 | if (clear_size == INST_BYTE_SIZE) | |
2620 | { | |
2621 | inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00; | |
2622 | } | |
2623 | if (clear_size == INST_WORD_SIZE) | |
2624 | { | |
2625 | inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000; | |
2626 | } | |
2627 | if (clear_size == INST_DWORD_SIZE) | |
2628 | { | |
2629 | inst_env->delay_slot_pc = 0x0; | |
2630 | } | |
2631 | /* The jump will be delayed with one delay slot. So we need a delay | |
2632 | slot. */ | |
2633 | inst_env->slot_needed = 1; | |
2634 | inst_env->delay_slot_pc_active = 1; | |
2635 | } | |
2636 | else | |
2637 | { | |
2638 | /* The PC will not change => no delay slot. */ | |
2639 | inst_env->slot_needed = 0; | |
2640 | } | |
2641 | inst_env->prefix_found = 0; | |
2642 | inst_env->xflag_found = 0; | |
2643 | inst_env->disable_interrupt = 0; | |
2644 | } | |
2645 | ||
2646 | /* Handles the TEST instruction if it's in register mode. */ | |
2647 | ||
a78f21af | 2648 | static void |
29134980 OF |
2649 | reg_mode_test_op (unsigned short inst, inst_env_type *inst_env) |
2650 | { | |
2651 | /* It's an error if we have got a prefix. */ | |
2652 | if (inst_env->prefix_found) | |
2653 | { | |
2654 | inst_env->invalid = 1; | |
2655 | return; | |
2656 | } | |
2657 | inst_env->slot_needed = 0; | |
2658 | inst_env->prefix_found = 0; | |
2659 | inst_env->xflag_found = 0; | |
2660 | inst_env->disable_interrupt = 0; | |
2661 | ||
2662 | } | |
2663 | ||
2664 | /* Handles the CLEAR and TEST instruction if the instruction isn't | |
2665 | in register mode. */ | |
2666 | ||
a78f21af | 2667 | static void |
29134980 OF |
2668 | none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env) |
2669 | { | |
2670 | /* Check if we are in a prefix mode. */ | |
2671 | if (inst_env->prefix_found) | |
2672 | { | |
2673 | /* The only way the PC can change is if this instruction is in | |
2674 | assign addressing mode. */ | |
2675 | check_assign (inst, inst_env); | |
2676 | } | |
2677 | /* Indirect mode can't change the PC so just check if the mode is | |
2678 | autoincrement. */ | |
2679 | else if (cris_get_mode (inst) == AUTOINC_MODE) | |
2680 | { | |
2681 | process_autoincrement (cris_get_size (inst), inst, inst_env); | |
2682 | } | |
2683 | inst_env->slot_needed = 0; | |
2684 | inst_env->prefix_found = 0; | |
2685 | inst_env->xflag_found = 0; | |
2686 | inst_env->disable_interrupt = 0; | |
2687 | } | |
2688 | ||
2689 | /* Checks that the PC isn't the destination register or the instructions has | |
2690 | a prefix. */ | |
2691 | ||
a78f21af | 2692 | static void |
29134980 OF |
2693 | dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env) |
2694 | { | |
2695 | /* It's invalid to have the PC as the destination. The instruction can't | |
2696 | have a prefix. */ | |
2697 | if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found) | |
2698 | { | |
2699 | inst_env->invalid = 1; | |
2700 | return; | |
2701 | } | |
2702 | ||
2703 | inst_env->slot_needed = 0; | |
2704 | inst_env->prefix_found = 0; | |
2705 | inst_env->xflag_found = 0; | |
2706 | inst_env->disable_interrupt = 0; | |
2707 | } | |
2708 | ||
2709 | /* Checks that the instruction doesn't have a prefix. */ | |
2710 | ||
a78f21af | 2711 | static void |
29134980 OF |
2712 | break_op (unsigned short inst, inst_env_type *inst_env) |
2713 | { | |
2714 | /* The instruction can't have a prefix. */ | |
2715 | if (inst_env->prefix_found) | |
2716 | { | |
2717 | inst_env->invalid = 1; | |
2718 | return; | |
2719 | } | |
2720 | ||
2721 | inst_env->slot_needed = 0; | |
2722 | inst_env->prefix_found = 0; | |
2723 | inst_env->xflag_found = 0; | |
2724 | inst_env->disable_interrupt = 1; | |
2725 | } | |
2726 | ||
2727 | /* Checks that the PC isn't the destination register and that the instruction | |
2728 | doesn't have a prefix. */ | |
2729 | ||
a78f21af | 2730 | static void |
29134980 OF |
2731 | scc_op (unsigned short inst, inst_env_type *inst_env) |
2732 | { | |
2733 | /* It's invalid to have the PC as the destination. The instruction can't | |
2734 | have a prefix. */ | |
2735 | if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found) | |
2736 | { | |
2737 | inst_env->invalid = 1; | |
2738 | return; | |
2739 | } | |
2740 | ||
2741 | inst_env->slot_needed = 0; | |
2742 | inst_env->prefix_found = 0; | |
2743 | inst_env->xflag_found = 0; | |
2744 | inst_env->disable_interrupt = 1; | |
2745 | } | |
2746 | ||
2747 | /* Handles the register mode JUMP instruction. */ | |
2748 | ||
a78f21af | 2749 | static void |
29134980 OF |
2750 | reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env) |
2751 | { | |
2752 | /* It's invalid to do a JUMP in a delay slot. The mode is register, so | |
2753 | you can't have a prefix. */ | |
2754 | if ((inst_env->slot_needed) || (inst_env->prefix_found)) | |
2755 | { | |
2756 | inst_env->invalid = 1; | |
2757 | return; | |
2758 | } | |
2759 | ||
2760 | /* Just change the PC. */ | |
2761 | inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)]; | |
2762 | inst_env->slot_needed = 0; | |
2763 | inst_env->prefix_found = 0; | |
2764 | inst_env->xflag_found = 0; | |
2765 | inst_env->disable_interrupt = 1; | |
2766 | } | |
2767 | ||
2768 | /* Handles the JUMP instruction for all modes except register. */ | |
2769 | ||
a78f21af AC |
2770 | static void |
2771 | none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env) | |
29134980 OF |
2772 | { |
2773 | unsigned long newpc; | |
2774 | CORE_ADDR address; | |
2775 | ||
2776 | /* It's invalid to do a JUMP in a delay slot. */ | |
2777 | if (inst_env->slot_needed) | |
2778 | { | |
2779 | inst_env->invalid = 1; | |
2780 | } | |
2781 | else | |
2782 | { | |
2783 | /* Check if we have a prefix. */ | |
2784 | if (inst_env->prefix_found) | |
2785 | { | |
2786 | check_assign (inst, inst_env); | |
2787 | ||
b021a221 | 2788 | /* Get the new value for the PC. */ |
29134980 OF |
2789 | newpc = |
2790 | read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value, | |
e17a4113 | 2791 | 4, inst_env->byte_order); |
29134980 OF |
2792 | } |
2793 | else | |
2794 | { | |
2795 | /* Get the new value for the PC. */ | |
2796 | address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)]; | |
e17a4113 UW |
2797 | newpc = read_memory_unsigned_integer (address, |
2798 | 4, inst_env->byte_order); | |
29134980 OF |
2799 | |
2800 | /* Check if we should increment a register. */ | |
2801 | if (cris_get_mode (inst) == AUTOINC_MODE) | |
2802 | { | |
2803 | inst_env->reg[cris_get_operand1 (inst)] += 4; | |
2804 | } | |
2805 | } | |
2806 | inst_env->reg[REG_PC] = newpc; | |
2807 | } | |
2808 | inst_env->slot_needed = 0; | |
2809 | inst_env->prefix_found = 0; | |
2810 | inst_env->xflag_found = 0; | |
2811 | inst_env->disable_interrupt = 1; | |
2812 | } | |
2813 | ||
2814 | /* Handles moves to special registers (aka P-register) for all modes. */ | |
2815 | ||
a78f21af | 2816 | static void |
be8626e0 MD |
2817 | move_to_preg_op (struct gdbarch *gdbarch, unsigned short inst, |
2818 | inst_env_type *inst_env) | |
29134980 OF |
2819 | { |
2820 | if (inst_env->prefix_found) | |
2821 | { | |
2822 | /* The instruction has a prefix that means we are only interested if | |
2823 | the instruction is in assign mode. */ | |
2824 | if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE) | |
2825 | { | |
2826 | /* The prefix handles the problem if we are in a delay slot. */ | |
2827 | if (cris_get_operand1 (inst) == REG_PC) | |
2828 | { | |
2829 | /* Just take care of the assign. */ | |
2830 | check_assign (inst, inst_env); | |
2831 | } | |
2832 | } | |
2833 | } | |
2834 | else if (cris_get_mode (inst) == AUTOINC_MODE) | |
2835 | { | |
2836 | /* The instruction doesn't have a prefix, the only case left that we | |
2837 | are interested in is the autoincrement mode. */ | |
2838 | if (cris_get_operand1 (inst) == REG_PC) | |
2839 | { | |
2840 | /* If the PC is to be incremented it's invalid to be in a | |
2841 | delay slot. */ | |
2842 | if (inst_env->slot_needed) | |
2843 | { | |
2844 | inst_env->invalid = 1; | |
2845 | return; | |
2846 | } | |
2a9ecef2 OF |
2847 | |
2848 | /* The increment depends on the size of the special register. */ | |
be8626e0 | 2849 | if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1) |
29134980 OF |
2850 | { |
2851 | process_autoincrement (INST_BYTE_SIZE, inst, inst_env); | |
2852 | } | |
be8626e0 | 2853 | else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2) |
29134980 OF |
2854 | { |
2855 | process_autoincrement (INST_WORD_SIZE, inst, inst_env); | |
2856 | } | |
2857 | else | |
2858 | { | |
2859 | process_autoincrement (INST_DWORD_SIZE, inst, inst_env); | |
2860 | } | |
2861 | } | |
2862 | } | |
2863 | inst_env->slot_needed = 0; | |
2864 | inst_env->prefix_found = 0; | |
2865 | inst_env->xflag_found = 0; | |
2866 | inst_env->disable_interrupt = 1; | |
2867 | } | |
2868 | ||
2869 | /* Handles moves from special registers (aka P-register) for all modes | |
2870 | except register. */ | |
2871 | ||
a78f21af | 2872 | static void |
be8626e0 MD |
2873 | none_reg_mode_move_from_preg_op (struct gdbarch *gdbarch, unsigned short inst, |
2874 | inst_env_type *inst_env) | |
29134980 OF |
2875 | { |
2876 | if (inst_env->prefix_found) | |
2877 | { | |
2878 | /* The instruction has a prefix that means we are only interested if | |
2879 | the instruction is in assign mode. */ | |
2880 | if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE) | |
2881 | { | |
2882 | /* The prefix handles the problem if we are in a delay slot. */ | |
2883 | if (cris_get_operand1 (inst) == REG_PC) | |
2884 | { | |
2885 | /* Just take care of the assign. */ | |
2886 | check_assign (inst, inst_env); | |
2887 | } | |
2888 | } | |
2889 | } | |
2890 | /* The instruction doesn't have a prefix, the only case left that we | |
2891 | are interested in is the autoincrement mode. */ | |
2892 | else if (cris_get_mode (inst) == AUTOINC_MODE) | |
2893 | { | |
2894 | if (cris_get_operand1 (inst) == REG_PC) | |
2895 | { | |
2896 | /* If the PC is to be incremented it's invalid to be in a | |
2897 | delay slot. */ | |
2898 | if (inst_env->slot_needed) | |
2899 | { | |
2900 | inst_env->invalid = 1; | |
2901 | return; | |
2902 | } | |
2a9ecef2 OF |
2903 | |
2904 | /* The increment depends on the size of the special register. */ | |
be8626e0 | 2905 | if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 1) |
29134980 OF |
2906 | { |
2907 | process_autoincrement (INST_BYTE_SIZE, inst, inst_env); | |
2908 | } | |
be8626e0 | 2909 | else if (cris_register_size (gdbarch, cris_get_operand2 (inst)) == 2) |
29134980 OF |
2910 | { |
2911 | process_autoincrement (INST_WORD_SIZE, inst, inst_env); | |
2912 | } | |
2913 | else | |
2914 | { | |
2915 | process_autoincrement (INST_DWORD_SIZE, inst, inst_env); | |
2916 | } | |
2917 | } | |
2918 | } | |
2919 | inst_env->slot_needed = 0; | |
2920 | inst_env->prefix_found = 0; | |
2921 | inst_env->xflag_found = 0; | |
2922 | inst_env->disable_interrupt = 1; | |
2923 | } | |
2924 | ||
2925 | /* Handles moves from special registers (aka P-register) when the mode | |
2926 | is register. */ | |
2927 | ||
a78f21af | 2928 | static void |
29134980 OF |
2929 | reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env) |
2930 | { | |
2931 | /* Register mode move from special register can't have a prefix. */ | |
2932 | if (inst_env->prefix_found) | |
2933 | { | |
2934 | inst_env->invalid = 1; | |
2935 | return; | |
2936 | } | |
2937 | ||
2938 | if (cris_get_operand1 (inst) == REG_PC) | |
2939 | { | |
2940 | /* It's invalid to change the PC in a delay slot. */ | |
2941 | if (inst_env->slot_needed) | |
2942 | { | |
2943 | inst_env->invalid = 1; | |
2944 | return; | |
2945 | } | |
2946 | /* The destination is the PC, the jump will have a delay slot. */ | |
2947 | inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)]; | |
2948 | inst_env->slot_needed = 1; | |
2949 | inst_env->delay_slot_pc_active = 1; | |
2950 | } | |
2951 | else | |
2952 | { | |
2953 | /* If the destination isn't PC, there will be no jump. */ | |
2954 | inst_env->slot_needed = 0; | |
2955 | } | |
2956 | inst_env->prefix_found = 0; | |
2957 | inst_env->xflag_found = 0; | |
2958 | inst_env->disable_interrupt = 1; | |
2959 | } | |
2960 | ||
2961 | /* Handles the MOVEM from memory to general register instruction. */ | |
2962 | ||
a78f21af | 2963 | static void |
29134980 OF |
2964 | move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env) |
2965 | { | |
2966 | if (inst_env->prefix_found) | |
2967 | { | |
2968 | /* The prefix handles the problem if we are in a delay slot. Is the | |
2969 | MOVEM instruction going to change the PC? */ | |
2970 | if (cris_get_operand2 (inst) >= REG_PC) | |
2971 | { | |
2972 | inst_env->reg[REG_PC] = | |
e17a4113 UW |
2973 | read_memory_unsigned_integer (inst_env->prefix_value, |
2974 | 4, inst_env->byte_order); | |
29134980 OF |
2975 | } |
2976 | /* The assign value is the value after the increment. Normally, the | |
2977 | assign value is the value before the increment. */ | |
2978 | if ((cris_get_operand1 (inst) == REG_PC) | |
2979 | && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)) | |
2980 | { | |
2981 | inst_env->reg[REG_PC] = inst_env->prefix_value; | |
2982 | inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1); | |
2983 | } | |
2984 | } | |
2985 | else | |
2986 | { | |
2987 | /* Is the MOVEM instruction going to change the PC? */ | |
2988 | if (cris_get_operand2 (inst) == REG_PC) | |
2989 | { | |
2990 | /* It's invalid to change the PC in a delay slot. */ | |
2991 | if (inst_env->slot_needed) | |
2992 | { | |
2993 | inst_env->invalid = 1; | |
2994 | return; | |
2995 | } | |
2996 | inst_env->reg[REG_PC] = | |
2997 | read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)], | |
e17a4113 | 2998 | 4, inst_env->byte_order); |
29134980 OF |
2999 | } |
3000 | /* The increment is not depending on the size, instead it's depending | |
3001 | on the number of registers loaded from memory. */ | |
0963b4bd MS |
3002 | if ((cris_get_operand1 (inst) == REG_PC) |
3003 | && (cris_get_mode (inst) == AUTOINC_MODE)) | |
29134980 OF |
3004 | { |
3005 | /* It's invalid to change the PC in a delay slot. */ | |
3006 | if (inst_env->slot_needed) | |
3007 | { | |
3008 | inst_env->invalid = 1; | |
3009 | return; | |
3010 | } | |
3011 | inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1); | |
3012 | } | |
3013 | } | |
3014 | inst_env->slot_needed = 0; | |
3015 | inst_env->prefix_found = 0; | |
3016 | inst_env->xflag_found = 0; | |
3017 | inst_env->disable_interrupt = 0; | |
3018 | } | |
3019 | ||
3020 | /* Handles the MOVEM to memory from general register instruction. */ | |
3021 | ||
a78f21af | 3022 | static void |
29134980 OF |
3023 | move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env) |
3024 | { | |
3025 | if (inst_env->prefix_found) | |
3026 | { | |
3027 | /* The assign value is the value after the increment. Normally, the | |
3028 | assign value is the value before the increment. */ | |
5aafa1cc PM |
3029 | if ((cris_get_operand1 (inst) == REG_PC) |
3030 | && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)) | |
29134980 OF |
3031 | { |
3032 | /* The prefix handles the problem if we are in a delay slot. */ | |
3033 | inst_env->reg[REG_PC] = inst_env->prefix_value; | |
3034 | inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1); | |
3035 | } | |
3036 | } | |
3037 | else | |
3038 | { | |
3039 | /* The increment is not depending on the size, instead it's depending | |
3040 | on the number of registers loaded to memory. */ | |
0963b4bd MS |
3041 | if ((cris_get_operand1 (inst) == REG_PC) |
3042 | && (cris_get_mode (inst) == AUTOINC_MODE)) | |
29134980 OF |
3043 | { |
3044 | /* It's invalid to change the PC in a delay slot. */ | |
3045 | if (inst_env->slot_needed) | |
3046 | { | |
3047 | inst_env->invalid = 1; | |
3048 | return; | |
3049 | } | |
3050 | inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1); | |
3051 | } | |
3052 | } | |
3053 | inst_env->slot_needed = 0; | |
3054 | inst_env->prefix_found = 0; | |
3055 | inst_env->xflag_found = 0; | |
3056 | inst_env->disable_interrupt = 0; | |
3057 | } | |
3058 | ||
29134980 OF |
3059 | /* Handles the intructions that's not yet implemented, by setting |
3060 | inst_env->invalid to true. */ | |
3061 | ||
a78f21af | 3062 | static void |
29134980 OF |
3063 | not_implemented_op (unsigned short inst, inst_env_type *inst_env) |
3064 | { | |
3065 | inst_env->invalid = 1; | |
3066 | } | |
3067 | ||
3068 | /* Handles the XOR instruction. */ | |
3069 | ||
a78f21af | 3070 | static void |
29134980 OF |
3071 | xor_op (unsigned short inst, inst_env_type *inst_env) |
3072 | { | |
3073 | /* XOR can't have a prefix. */ | |
3074 | if (inst_env->prefix_found) | |
3075 | { | |
3076 | inst_env->invalid = 1; | |
3077 | return; | |
3078 | } | |
3079 | ||
3080 | /* Check if the PC is the target. */ | |
3081 | if (cris_get_operand2 (inst) == REG_PC) | |
3082 | { | |
3083 | /* It's invalid to change the PC in a delay slot. */ | |
3084 | if (inst_env->slot_needed) | |
3085 | { | |
3086 | inst_env->invalid = 1; | |
3087 | return; | |
3088 | } | |
3089 | inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)]; | |
3090 | } | |
3091 | inst_env->slot_needed = 0; | |
3092 | inst_env->prefix_found = 0; | |
3093 | inst_env->xflag_found = 0; | |
3094 | inst_env->disable_interrupt = 0; | |
3095 | } | |
3096 | ||
3097 | /* Handles the MULS instruction. */ | |
3098 | ||
a78f21af | 3099 | static void |
29134980 OF |
3100 | muls_op (unsigned short inst, inst_env_type *inst_env) |
3101 | { | |
3102 | /* MULS/U can't have a prefix. */ | |
3103 | if (inst_env->prefix_found) | |
3104 | { | |
3105 | inst_env->invalid = 1; | |
3106 | return; | |
3107 | } | |
3108 | ||
3109 | /* Consider it invalid if the PC is the target. */ | |
3110 | if (cris_get_operand2 (inst) == REG_PC) | |
3111 | { | |
3112 | inst_env->invalid = 1; | |
3113 | return; | |
3114 | } | |
3115 | inst_env->slot_needed = 0; | |
3116 | inst_env->prefix_found = 0; | |
3117 | inst_env->xflag_found = 0; | |
3118 | inst_env->disable_interrupt = 0; | |
3119 | } | |
3120 | ||
3121 | /* Handles the MULU instruction. */ | |
3122 | ||
a78f21af | 3123 | static void |
29134980 OF |
3124 | mulu_op (unsigned short inst, inst_env_type *inst_env) |
3125 | { | |
3126 | /* MULS/U can't have a prefix. */ | |
3127 | if (inst_env->prefix_found) | |
3128 | { | |
3129 | inst_env->invalid = 1; | |
3130 | return; | |
3131 | } | |
3132 | ||
3133 | /* Consider it invalid if the PC is the target. */ | |
3134 | if (cris_get_operand2 (inst) == REG_PC) | |
3135 | { | |
3136 | inst_env->invalid = 1; | |
3137 | return; | |
3138 | } | |
3139 | inst_env->slot_needed = 0; | |
3140 | inst_env->prefix_found = 0; | |
3141 | inst_env->xflag_found = 0; | |
3142 | inst_env->disable_interrupt = 0; | |
3143 | } | |
3144 | ||
0963b4bd | 3145 | /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE. |
29134980 OF |
3146 | The MOVE instruction is the move from source to register. */ |
3147 | ||
a78f21af | 3148 | static void |
29134980 OF |
3149 | add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env, |
3150 | unsigned long source1, unsigned long source2) | |
3151 | { | |
3152 | unsigned long pc_mask; | |
3153 | unsigned long operation_mask; | |
3154 | ||
3155 | /* Find out how many bits the operation should apply to. */ | |
3156 | if (cris_get_size (inst) == INST_BYTE_SIZE) | |
3157 | { | |
3158 | pc_mask = 0xFFFFFF00; | |
3159 | operation_mask = 0xFF; | |
3160 | } | |
3161 | else if (cris_get_size (inst) == INST_WORD_SIZE) | |
3162 | { | |
3163 | pc_mask = 0xFFFF0000; | |
3164 | operation_mask = 0xFFFF; | |
3165 | } | |
3166 | else if (cris_get_size (inst) == INST_DWORD_SIZE) | |
3167 | { | |
3168 | pc_mask = 0x0; | |
3169 | operation_mask = 0xFFFFFFFF; | |
3170 | } | |
3171 | else | |
3172 | { | |
3173 | /* The size is out of range. */ | |
3174 | inst_env->invalid = 1; | |
3175 | return; | |
3176 | } | |
3177 | ||
3178 | /* The instruction just works on uw_operation_mask bits. */ | |
3179 | source2 &= operation_mask; | |
3180 | source1 &= operation_mask; | |
3181 | ||
3182 | /* Now calculate the result. The opcode's 3 first bits separates | |
3183 | the different actions. */ | |
3184 | switch (cris_get_opcode (inst) & 7) | |
3185 | { | |
3186 | case 0: /* add */ | |
3187 | source1 += source2; | |
3188 | break; | |
3189 | ||
3190 | case 1: /* move */ | |
3191 | source1 = source2; | |
3192 | break; | |
3193 | ||
3194 | case 2: /* subtract */ | |
3195 | source1 -= source2; | |
3196 | break; | |
3197 | ||
3198 | case 3: /* compare */ | |
3199 | break; | |
3200 | ||
3201 | case 4: /* and */ | |
3202 | source1 &= source2; | |
3203 | break; | |
3204 | ||
3205 | case 5: /* or */ | |
3206 | source1 |= source2; | |
3207 | break; | |
3208 | ||
3209 | default: | |
3210 | inst_env->invalid = 1; | |
3211 | return; | |
3212 | ||
3213 | break; | |
3214 | } | |
3215 | ||
3216 | /* Make sure that the result doesn't contain more than the instruction | |
3217 | size bits. */ | |
3218 | source2 &= operation_mask; | |
3219 | ||
3220 | /* Calculate the new breakpoint address. */ | |
3221 | inst_env->reg[REG_PC] &= pc_mask; | |
3222 | inst_env->reg[REG_PC] |= source1; | |
3223 | ||
3224 | } | |
3225 | ||
3226 | /* Extends the value from either byte or word size to a dword. If the mode | |
3227 | is zero extend then the value is extended with zero. If instead the mode | |
3228 | is signed extend the sign bit of the value is taken into consideration. */ | |
3229 | ||
a78f21af | 3230 | static unsigned long |
29134980 OF |
3231 | do_sign_or_zero_extend (unsigned long value, unsigned short *inst) |
3232 | { | |
3233 | /* The size can be either byte or word, check which one it is. | |
3234 | Don't check the highest bit, it's indicating if it's a zero | |
3235 | or sign extend. */ | |
3236 | if (cris_get_size (*inst) & INST_WORD_SIZE) | |
3237 | { | |
3238 | /* Word size. */ | |
3239 | value &= 0xFFFF; | |
3240 | ||
3241 | /* Check if the instruction is signed extend. If so, check if value has | |
3242 | the sign bit on. */ | |
3243 | if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK)) | |
3244 | { | |
3245 | value |= SIGNED_WORD_EXTEND_MASK; | |
3246 | } | |
3247 | } | |
3248 | else | |
3249 | { | |
3250 | /* Byte size. */ | |
3251 | value &= 0xFF; | |
3252 | ||
3253 | /* Check if the instruction is signed extend. If so, check if value has | |
3254 | the sign bit on. */ | |
3255 | if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK)) | |
3256 | { | |
3257 | value |= SIGNED_BYTE_EXTEND_MASK; | |
3258 | } | |
3259 | } | |
3260 | /* The size should now be dword. */ | |
3261 | cris_set_size_to_dword (inst); | |
3262 | return value; | |
3263 | } | |
3264 | ||
3265 | /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE | |
3266 | instruction. The MOVE instruction is the move from source to register. */ | |
3267 | ||
a78f21af | 3268 | static void |
29134980 OF |
3269 | reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst, |
3270 | inst_env_type *inst_env) | |
3271 | { | |
3272 | unsigned long operand1; | |
3273 | unsigned long operand2; | |
3274 | ||
3275 | /* It's invalid to have a prefix to the instruction. This is a register | |
3276 | mode instruction and can't have a prefix. */ | |
3277 | if (inst_env->prefix_found) | |
3278 | { | |
3279 | inst_env->invalid = 1; | |
3280 | return; | |
3281 | } | |
3282 | /* Check if the instruction has PC as its target. */ | |
3283 | if (cris_get_operand2 (inst) == REG_PC) | |
3284 | { | |
3285 | if (inst_env->slot_needed) | |
3286 | { | |
3287 | inst_env->invalid = 1; | |
3288 | return; | |
3289 | } | |
3290 | /* The instruction has the PC as its target register. */ | |
7ab98e9e | 3291 | operand1 = inst_env->reg[cris_get_operand1 (inst)]; |
29134980 OF |
3292 | operand2 = inst_env->reg[REG_PC]; |
3293 | ||
3294 | /* Check if it's a extend, signed or zero instruction. */ | |
3295 | if (cris_get_opcode (inst) < 4) | |
3296 | { | |
3297 | operand1 = do_sign_or_zero_extend (operand1, &inst); | |
3298 | } | |
3299 | /* Calculate the PC value after the instruction, i.e. where the | |
3300 | breakpoint should be. The order of the udw_operands is vital. */ | |
3301 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1); | |
3302 | } | |
3303 | inst_env->slot_needed = 0; | |
3304 | inst_env->prefix_found = 0; | |
3305 | inst_env->xflag_found = 0; | |
3306 | inst_env->disable_interrupt = 0; | |
3307 | } | |
3308 | ||
3309 | /* Returns the data contained at address. The size of the data is derived from | |
3310 | the size of the operation. If the instruction is a zero or signed | |
3311 | extend instruction, the size field is changed in instruction. */ | |
3312 | ||
a78f21af | 3313 | static unsigned long |
0963b4bd MS |
3314 | get_data_from_address (unsigned short *inst, CORE_ADDR address, |
3315 | enum bfd_endian byte_order) | |
29134980 OF |
3316 | { |
3317 | int size = cris_get_size (*inst); | |
3318 | unsigned long value; | |
3319 | ||
3320 | /* If it's an extend instruction we don't want the signed extend bit, | |
3321 | because it influences the size. */ | |
3322 | if (cris_get_opcode (*inst) < 4) | |
3323 | { | |
3324 | size &= ~SIGNED_EXTEND_BIT_MASK; | |
3325 | } | |
3326 | /* Is there a need for checking the size? Size should contain the number of | |
3327 | bytes to read. */ | |
3328 | size = 1 << size; | |
e17a4113 | 3329 | value = read_memory_unsigned_integer (address, size, byte_order); |
29134980 OF |
3330 | |
3331 | /* Check if it's an extend, signed or zero instruction. */ | |
3332 | if (cris_get_opcode (*inst) < 4) | |
3333 | { | |
3334 | value = do_sign_or_zero_extend (value, inst); | |
3335 | } | |
3336 | return value; | |
3337 | } | |
3338 | ||
3339 | /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE | |
3340 | instructions. The MOVE instruction is the move from source to register. */ | |
3341 | ||
a78f21af | 3342 | static void |
29134980 OF |
3343 | handle_prefix_assign_mode_for_aritm_op (unsigned short inst, |
3344 | inst_env_type *inst_env) | |
3345 | { | |
3346 | unsigned long operand2; | |
3347 | unsigned long operand3; | |
3348 | ||
3349 | check_assign (inst, inst_env); | |
3350 | if (cris_get_operand2 (inst) == REG_PC) | |
3351 | { | |
3352 | operand2 = inst_env->reg[REG_PC]; | |
3353 | ||
3354 | /* Get the value of the third operand. */ | |
e17a4113 UW |
3355 | operand3 = get_data_from_address (&inst, inst_env->prefix_value, |
3356 | inst_env->byte_order); | |
29134980 OF |
3357 | |
3358 | /* Calculate the PC value after the instruction, i.e. where the | |
3359 | breakpoint should be. The order of the udw_operands is vital. */ | |
3360 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3); | |
3361 | } | |
3362 | inst_env->slot_needed = 0; | |
3363 | inst_env->prefix_found = 0; | |
3364 | inst_env->xflag_found = 0; | |
3365 | inst_env->disable_interrupt = 0; | |
3366 | } | |
3367 | ||
3368 | /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and | |
3369 | OR instructions. Note that for this to work as expected, the calling | |
3370 | function must have made sure that there is a prefix to this instruction. */ | |
3371 | ||
a78f21af | 3372 | static void |
29134980 OF |
3373 | three_operand_add_sub_cmp_and_or_op (unsigned short inst, |
3374 | inst_env_type *inst_env) | |
3375 | { | |
3376 | unsigned long operand2; | |
3377 | unsigned long operand3; | |
3378 | ||
3379 | if (cris_get_operand1 (inst) == REG_PC) | |
3380 | { | |
3381 | /* The PC will be changed by the instruction. */ | |
3382 | operand2 = inst_env->reg[cris_get_operand2 (inst)]; | |
3383 | ||
3384 | /* Get the value of the third operand. */ | |
e17a4113 UW |
3385 | operand3 = get_data_from_address (&inst, inst_env->prefix_value, |
3386 | inst_env->byte_order); | |
29134980 OF |
3387 | |
3388 | /* Calculate the PC value after the instruction, i.e. where the | |
3389 | breakpoint should be. */ | |
3390 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3); | |
3391 | } | |
3392 | inst_env->slot_needed = 0; | |
3393 | inst_env->prefix_found = 0; | |
3394 | inst_env->xflag_found = 0; | |
3395 | inst_env->disable_interrupt = 0; | |
3396 | } | |
3397 | ||
3398 | /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE | |
3399 | instructions. The MOVE instruction is the move from source to register. */ | |
3400 | ||
a78f21af | 3401 | static void |
29134980 OF |
3402 | handle_prefix_index_mode_for_aritm_op (unsigned short inst, |
3403 | inst_env_type *inst_env) | |
3404 | { | |
3405 | if (cris_get_operand1 (inst) != cris_get_operand2 (inst)) | |
3406 | { | |
3407 | /* If the instruction is MOVE it's invalid. If the instruction is ADD, | |
3408 | SUB, AND or OR something weird is going on (if everything works these | |
3409 | instructions should end up in the three operand version). */ | |
3410 | inst_env->invalid = 1; | |
3411 | return; | |
3412 | } | |
3413 | else | |
3414 | { | |
3415 | /* three_operand_add_sub_cmp_and_or does the same as we should do here | |
3416 | so use it. */ | |
3417 | three_operand_add_sub_cmp_and_or_op (inst, inst_env); | |
3418 | } | |
3419 | inst_env->slot_needed = 0; | |
3420 | inst_env->prefix_found = 0; | |
3421 | inst_env->xflag_found = 0; | |
3422 | inst_env->disable_interrupt = 0; | |
3423 | } | |
3424 | ||
3425 | /* Handles the autoincrement and indirect addresing mode for the ADD, SUB, | |
3426 | CMP, AND OR and MOVE instruction. The MOVE instruction is the move from | |
3427 | source to register. */ | |
3428 | ||
a78f21af | 3429 | static void |
29134980 OF |
3430 | handle_inc_and_index_mode_for_aritm_op (unsigned short inst, |
3431 | inst_env_type *inst_env) | |
3432 | { | |
3433 | unsigned long operand1; | |
3434 | unsigned long operand2; | |
3435 | unsigned long operand3; | |
3436 | int size; | |
3437 | ||
0963b4bd | 3438 | /* The instruction is either an indirect or autoincrement addressing mode. |
29134980 OF |
3439 | Check if the destination register is the PC. */ |
3440 | if (cris_get_operand2 (inst) == REG_PC) | |
3441 | { | |
3442 | /* Must be done here, get_data_from_address may change the size | |
3443 | field. */ | |
3444 | size = cris_get_size (inst); | |
3445 | operand2 = inst_env->reg[REG_PC]; | |
3446 | ||
3447 | /* Get the value of the third operand, i.e. the indirect operand. */ | |
3448 | operand1 = inst_env->reg[cris_get_operand1 (inst)]; | |
e17a4113 | 3449 | operand3 = get_data_from_address (&inst, operand1, inst_env->byte_order); |
29134980 OF |
3450 | |
3451 | /* Calculate the PC value after the instruction, i.e. where the | |
3452 | breakpoint should be. The order of the udw_operands is vital. */ | |
3453 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3); | |
3454 | } | |
3455 | /* If this is an autoincrement addressing mode, check if the increment | |
3456 | changes the PC. */ | |
0963b4bd MS |
3457 | if ((cris_get_operand1 (inst) == REG_PC) |
3458 | && (cris_get_mode (inst) == AUTOINC_MODE)) | |
29134980 OF |
3459 | { |
3460 | /* Get the size field. */ | |
3461 | size = cris_get_size (inst); | |
3462 | ||
3463 | /* If it's an extend instruction we don't want the signed extend bit, | |
3464 | because it influences the size. */ | |
3465 | if (cris_get_opcode (inst) < 4) | |
3466 | { | |
3467 | size &= ~SIGNED_EXTEND_BIT_MASK; | |
3468 | } | |
3469 | process_autoincrement (size, inst, inst_env); | |
3470 | } | |
3471 | inst_env->slot_needed = 0; | |
3472 | inst_env->prefix_found = 0; | |
3473 | inst_env->xflag_found = 0; | |
3474 | inst_env->disable_interrupt = 0; | |
3475 | } | |
3476 | ||
3477 | /* Handles the two-operand addressing mode, all modes except register, for | |
3478 | the ADD, SUB CMP, AND and OR instruction. */ | |
3479 | ||
a78f21af | 3480 | static void |
29134980 OF |
3481 | none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst, |
3482 | inst_env_type *inst_env) | |
3483 | { | |
3484 | if (inst_env->prefix_found) | |
3485 | { | |
3486 | if (cris_get_mode (inst) == PREFIX_INDEX_MODE) | |
3487 | { | |
3488 | handle_prefix_index_mode_for_aritm_op (inst, inst_env); | |
3489 | } | |
3490 | else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE) | |
3491 | { | |
3492 | handle_prefix_assign_mode_for_aritm_op (inst, inst_env); | |
3493 | } | |
3494 | else | |
3495 | { | |
3496 | /* The mode is invalid for a prefixed base instruction. */ | |
3497 | inst_env->invalid = 1; | |
3498 | return; | |
3499 | } | |
3500 | } | |
3501 | else | |
3502 | { | |
3503 | handle_inc_and_index_mode_for_aritm_op (inst, inst_env); | |
3504 | } | |
3505 | } | |
3506 | ||
3507 | /* Handles the quick addressing mode for the ADD and SUB instruction. */ | |
3508 | ||
a78f21af | 3509 | static void |
29134980 OF |
3510 | quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env) |
3511 | { | |
3512 | unsigned long operand1; | |
3513 | unsigned long operand2; | |
3514 | ||
3515 | /* It's a bad idea to be in a prefix instruction now. This is a quick mode | |
3516 | instruction and can't have a prefix. */ | |
3517 | if (inst_env->prefix_found) | |
3518 | { | |
3519 | inst_env->invalid = 1; | |
3520 | return; | |
3521 | } | |
3522 | ||
3523 | /* Check if the instruction has PC as its target. */ | |
3524 | if (cris_get_operand2 (inst) == REG_PC) | |
3525 | { | |
3526 | if (inst_env->slot_needed) | |
3527 | { | |
3528 | inst_env->invalid = 1; | |
3529 | return; | |
3530 | } | |
3531 | operand1 = cris_get_quick_value (inst); | |
3532 | operand2 = inst_env->reg[REG_PC]; | |
3533 | ||
3534 | /* The size should now be dword. */ | |
3535 | cris_set_size_to_dword (&inst); | |
3536 | ||
3537 | /* Calculate the PC value after the instruction, i.e. where the | |
3538 | breakpoint should be. */ | |
3539 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1); | |
3540 | } | |
3541 | inst_env->slot_needed = 0; | |
3542 | inst_env->prefix_found = 0; | |
3543 | inst_env->xflag_found = 0; | |
3544 | inst_env->disable_interrupt = 0; | |
3545 | } | |
3546 | ||
3547 | /* Handles the quick addressing mode for the CMP, AND and OR instruction. */ | |
3548 | ||
a78f21af | 3549 | static void |
29134980 OF |
3550 | quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env) |
3551 | { | |
3552 | unsigned long operand1; | |
3553 | unsigned long operand2; | |
3554 | ||
3555 | /* It's a bad idea to be in a prefix instruction now. This is a quick mode | |
3556 | instruction and can't have a prefix. */ | |
3557 | if (inst_env->prefix_found) | |
3558 | { | |
3559 | inst_env->invalid = 1; | |
3560 | return; | |
3561 | } | |
3562 | /* Check if the instruction has PC as its target. */ | |
3563 | if (cris_get_operand2 (inst) == REG_PC) | |
3564 | { | |
3565 | if (inst_env->slot_needed) | |
3566 | { | |
3567 | inst_env->invalid = 1; | |
3568 | return; | |
3569 | } | |
3570 | /* The instruction has the PC as its target register. */ | |
3571 | operand1 = cris_get_quick_value (inst); | |
3572 | operand2 = inst_env->reg[REG_PC]; | |
3573 | ||
3574 | /* The quick value is signed, so check if we must do a signed extend. */ | |
3575 | if (operand1 & SIGNED_QUICK_VALUE_MASK) | |
3576 | { | |
3577 | /* sign extend */ | |
3578 | operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK; | |
3579 | } | |
3580 | /* The size should now be dword. */ | |
3581 | cris_set_size_to_dword (&inst); | |
3582 | ||
3583 | /* Calculate the PC value after the instruction, i.e. where the | |
3584 | breakpoint should be. */ | |
3585 | add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1); | |
3586 | } | |
3587 | inst_env->slot_needed = 0; | |
3588 | inst_env->prefix_found = 0; | |
3589 | inst_env->xflag_found = 0; | |
3590 | inst_env->disable_interrupt = 0; | |
3591 | } | |
3592 | ||
3593 | /* Translate op_type to a function and call it. */ | |
3594 | ||
a78f21af | 3595 | static void |
be8626e0 MD |
3596 | cris_gdb_func (struct gdbarch *gdbarch, enum cris_op_type op_type, |
3597 | unsigned short inst, inst_env_type *inst_env) | |
29134980 OF |
3598 | { |
3599 | switch (op_type) | |
3600 | { | |
3601 | case cris_not_implemented_op: | |
3602 | not_implemented_op (inst, inst_env); | |
3603 | break; | |
3604 | ||
3605 | case cris_abs_op: | |
3606 | abs_op (inst, inst_env); | |
3607 | break; | |
3608 | ||
3609 | case cris_addi_op: | |
3610 | addi_op (inst, inst_env); | |
3611 | break; | |
3612 | ||
3613 | case cris_asr_op: | |
3614 | asr_op (inst, inst_env); | |
3615 | break; | |
3616 | ||
3617 | case cris_asrq_op: | |
3618 | asrq_op (inst, inst_env); | |
3619 | break; | |
3620 | ||
3621 | case cris_ax_ei_setf_op: | |
3622 | ax_ei_setf_op (inst, inst_env); | |
3623 | break; | |
3624 | ||
3625 | case cris_bdap_prefix: | |
3626 | bdap_prefix (inst, inst_env); | |
3627 | break; | |
3628 | ||
3629 | case cris_biap_prefix: | |
3630 | biap_prefix (inst, inst_env); | |
3631 | break; | |
3632 | ||
3633 | case cris_break_op: | |
3634 | break_op (inst, inst_env); | |
3635 | break; | |
3636 | ||
3637 | case cris_btst_nop_op: | |
3638 | btst_nop_op (inst, inst_env); | |
3639 | break; | |
3640 | ||
3641 | case cris_clearf_di_op: | |
3642 | clearf_di_op (inst, inst_env); | |
3643 | break; | |
3644 | ||
3645 | case cris_dip_prefix: | |
3646 | dip_prefix (inst, inst_env); | |
3647 | break; | |
3648 | ||
3649 | case cris_dstep_logshift_mstep_neg_not_op: | |
3650 | dstep_logshift_mstep_neg_not_op (inst, inst_env); | |
3651 | break; | |
3652 | ||
3653 | case cris_eight_bit_offset_branch_op: | |
3654 | eight_bit_offset_branch_op (inst, inst_env); | |
3655 | break; | |
3656 | ||
3657 | case cris_move_mem_to_reg_movem_op: | |
3658 | move_mem_to_reg_movem_op (inst, inst_env); | |
3659 | break; | |
3660 | ||
3661 | case cris_move_reg_to_mem_movem_op: | |
3662 | move_reg_to_mem_movem_op (inst, inst_env); | |
3663 | break; | |
3664 | ||
3665 | case cris_move_to_preg_op: | |
be8626e0 | 3666 | move_to_preg_op (gdbarch, inst, inst_env); |
29134980 OF |
3667 | break; |
3668 | ||
3669 | case cris_muls_op: | |
3670 | muls_op (inst, inst_env); | |
3671 | break; | |
3672 | ||
3673 | case cris_mulu_op: | |
3674 | mulu_op (inst, inst_env); | |
3675 | break; | |
3676 | ||
3677 | case cris_none_reg_mode_add_sub_cmp_and_or_move_op: | |
3678 | none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env); | |
3679 | break; | |
3680 | ||
3681 | case cris_none_reg_mode_clear_test_op: | |
3682 | none_reg_mode_clear_test_op (inst, inst_env); | |
3683 | break; | |
3684 | ||
3685 | case cris_none_reg_mode_jump_op: | |
3686 | none_reg_mode_jump_op (inst, inst_env); | |
3687 | break; | |
3688 | ||
3689 | case cris_none_reg_mode_move_from_preg_op: | |
be8626e0 | 3690 | none_reg_mode_move_from_preg_op (gdbarch, inst, inst_env); |
29134980 OF |
3691 | break; |
3692 | ||
3693 | case cris_quick_mode_add_sub_op: | |
3694 | quick_mode_add_sub_op (inst, inst_env); | |
3695 | break; | |
3696 | ||
3697 | case cris_quick_mode_and_cmp_move_or_op: | |
3698 | quick_mode_and_cmp_move_or_op (inst, inst_env); | |
3699 | break; | |
3700 | ||
3701 | case cris_quick_mode_bdap_prefix: | |
3702 | quick_mode_bdap_prefix (inst, inst_env); | |
3703 | break; | |
3704 | ||
3705 | case cris_reg_mode_add_sub_cmp_and_or_move_op: | |
3706 | reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env); | |
3707 | break; | |
3708 | ||
3709 | case cris_reg_mode_clear_op: | |
3710 | reg_mode_clear_op (inst, inst_env); | |
3711 | break; | |
3712 | ||
3713 | case cris_reg_mode_jump_op: | |
3714 | reg_mode_jump_op (inst, inst_env); | |
3715 | break; | |
3716 | ||
3717 | case cris_reg_mode_move_from_preg_op: | |
3718 | reg_mode_move_from_preg_op (inst, inst_env); | |
3719 | break; | |
3720 | ||
3721 | case cris_reg_mode_test_op: | |
3722 | reg_mode_test_op (inst, inst_env); | |
3723 | break; | |
3724 | ||
3725 | case cris_scc_op: | |
3726 | scc_op (inst, inst_env); | |
3727 | break; | |
3728 | ||
3729 | case cris_sixteen_bit_offset_branch_op: | |
3730 | sixteen_bit_offset_branch_op (inst, inst_env); | |
3731 | break; | |
3732 | ||
3733 | case cris_three_operand_add_sub_cmp_and_or_op: | |
3734 | three_operand_add_sub_cmp_and_or_op (inst, inst_env); | |
3735 | break; | |
3736 | ||
3737 | case cris_three_operand_bound_op: | |
3738 | three_operand_bound_op (inst, inst_env); | |
3739 | break; | |
3740 | ||
3741 | case cris_two_operand_bound_op: | |
3742 | two_operand_bound_op (inst, inst_env); | |
3743 | break; | |
3744 | ||
3745 | case cris_xor_op: | |
3746 | xor_op (inst, inst_env); | |
3747 | break; | |
3748 | } | |
3749 | } | |
3750 | ||
18b3c2f5 RW |
3751 | /* Originally from <asm/elf.h>. */ |
3752 | typedef unsigned char cris_elf_greg_t[4]; | |
dbbff683 OF |
3753 | |
3754 | /* Same as user_regs_struct struct in <asm/user.h>. */ | |
c600d464 | 3755 | #define CRISV10_ELF_NGREG 35 |
18b3c2f5 | 3756 | typedef cris_elf_greg_t cris_elf_gregset_t[CRISV10_ELF_NGREG]; |
c600d464 OF |
3757 | |
3758 | #define CRISV32_ELF_NGREG 32 | |
18b3c2f5 | 3759 | typedef cris_elf_greg_t crisv32_elf_gregset_t[CRISV32_ELF_NGREG]; |
dbbff683 | 3760 | |
18b3c2f5 | 3761 | /* Unpack a cris_elf_gregset_t into GDB's register cache. */ |
dbbff683 | 3762 | |
a78f21af | 3763 | static void |
18b3c2f5 | 3764 | cris_supply_gregset (struct regcache *regcache, cris_elf_gregset_t *gregsetp) |
dbbff683 | 3765 | { |
ac7936df | 3766 | struct gdbarch *gdbarch = regcache->arch (); |
7fbe2eba | 3767 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
dbbff683 | 3768 | int i; |
18b3c2f5 | 3769 | cris_elf_greg_t *regp = *gregsetp; |
dbbff683 OF |
3770 | |
3771 | /* The kernel dumps all 32 registers as unsigned longs, but supply_register | |
3772 | knows about the actual size of each register so that's no problem. */ | |
3773 | for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++) | |
3774 | { | |
73e1c03f | 3775 | regcache->raw_supply (i, (char *)®p[i]); |
dbbff683 | 3776 | } |
c600d464 OF |
3777 | |
3778 | if (tdep->cris_version == 32) | |
3779 | { | |
3780 | /* Needed to set pseudo-register PC for CRISv32. */ | |
3781 | /* FIXME: If ERP is in a delay slot at this point then the PC will | |
3782 | be wrong. Issue a warning to alert the user. */ | |
73e1c03f SM |
3783 | regcache->raw_supply (gdbarch_pc_regnum (gdbarch), |
3784 | (char *)®p[ERP_REGNUM]); | |
c600d464 OF |
3785 | |
3786 | if (*(char *)®p[ERP_REGNUM] & 0x1) | |
3787 | fprintf_unfiltered (gdb_stderr, "Warning: PC in delay slot\n"); | |
3788 | } | |
dbbff683 OF |
3789 | } |
3790 | ||
3791 | /* Use a local version of this function to get the correct types for | |
3792 | regsets, until multi-arch core support is ready. */ | |
3793 | ||
3794 | static void | |
9eefc95f UW |
3795 | fetch_core_registers (struct regcache *regcache, |
3796 | char *core_reg_sect, unsigned core_reg_size, | |
dbbff683 OF |
3797 | int which, CORE_ADDR reg_addr) |
3798 | { | |
18b3c2f5 | 3799 | cris_elf_gregset_t gregset; |
dbbff683 OF |
3800 | |
3801 | switch (which) | |
3802 | { | |
3803 | case 0: | |
18b3c2f5 | 3804 | if (core_reg_size != sizeof (cris_elf_gregset_t) |
c600d464 | 3805 | && core_reg_size != sizeof (crisv32_elf_gregset_t)) |
dbbff683 | 3806 | { |
8a3fe4f8 | 3807 | warning (_("wrong size gregset struct in core file")); |
dbbff683 OF |
3808 | } |
3809 | else | |
3810 | { | |
3811 | memcpy (&gregset, core_reg_sect, sizeof (gregset)); | |
9eefc95f | 3812 | cris_supply_gregset (regcache, &gregset); |
dbbff683 OF |
3813 | } |
3814 | ||
3815 | default: | |
3816 | /* We've covered all the kinds of registers we know about here, | |
3817 | so this must be something we wouldn't know what to do with | |
3818 | anyway. Just ignore it. */ | |
3819 | break; | |
3820 | } | |
3821 | } | |
3822 | ||
3823 | static struct core_fns cris_elf_core_fns = | |
3824 | { | |
3825 | bfd_target_elf_flavour, /* core_flavour */ | |
3826 | default_check_format, /* check_format */ | |
3827 | default_core_sniffer, /* core_sniffer */ | |
3828 | fetch_core_registers, /* core_read_registers */ | |
3829 | NULL /* next */ | |
3830 | }; | |
3831 | ||
29134980 OF |
3832 | void |
3833 | _initialize_cris_tdep (void) | |
3834 | { | |
29134980 OF |
3835 | gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep); |
3836 | ||
29134980 | 3837 | /* CRIS-specific user-commands. */ |
addb4faf PA |
3838 | add_setshow_zuinteger_cmd ("cris-version", class_support, |
3839 | &usr_cmd_cris_version, | |
3840 | _("Set the current CRIS version."), | |
3841 | _("Show the current CRIS version."), | |
3842 | _("\ | |
bdd56253 OF |
3843 | Set to 10 for CRISv10 or 32 for CRISv32 if autodetection fails.\n\ |
3844 | Defaults to 10. "), | |
addb4faf PA |
3845 | set_cris_version, |
3846 | NULL, /* FIXME: i18n: Current CRIS version | |
3847 | is %s. */ | |
3848 | &setlist, &showlist); | |
0e6bdb31 OF |
3849 | |
3850 | add_setshow_enum_cmd ("cris-mode", class_support, | |
3851 | cris_modes, &usr_cmd_cris_mode, | |
3852 | _("Set the current CRIS mode."), | |
3853 | _("Show the current CRIS mode."), | |
bdd56253 OF |
3854 | _("\ |
3855 | Set to CRIS_MODE_GURU when debugging in guru mode.\n\ | |
3856 | Makes GDB use the NRP register instead of the ERP register in certain cases."), | |
0e6bdb31 OF |
3857 | set_cris_mode, |
3858 | NULL, /* FIXME: i18n: Current CRIS version is %s. */ | |
3859 | &setlist, &showlist); | |
dbbff683 | 3860 | |
a5f6c8f5 OF |
3861 | add_setshow_boolean_cmd ("cris-dwarf2-cfi", class_support, |
3862 | &usr_cmd_cris_dwarf2_cfi, | |
7915a72c AC |
3863 | _("Set the usage of Dwarf-2 CFI for CRIS."), |
3864 | _("Show the usage of Dwarf-2 CFI for CRIS."), | |
bdd56253 | 3865 | _("Set this to \"off\" if using gcc-cris < R59."), |
2c5b56ce | 3866 | set_cris_dwarf2_cfi, |
0963b4bd MS |
3867 | NULL, /* FIXME: i18n: Usage of Dwarf-2 CFI |
3868 | for CRIS is %d. */ | |
a5f6c8f5 OF |
3869 | &setlist, &showlist); |
3870 | ||
52bd1401 | 3871 | deprecated_add_core_fns (&cris_elf_core_fns); |
29134980 OF |
3872 | } |
3873 | ||
3874 | /* Prints out all target specific values. */ | |
3875 | ||
3876 | static void | |
3877 | cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) | |
3878 | { | |
7fbe2eba | 3879 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
29134980 OF |
3880 | if (tdep != NULL) |
3881 | { | |
3882 | fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n", | |
3883 | tdep->cris_version); | |
0e6bdb31 OF |
3884 | fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n", |
3885 | tdep->cris_mode); | |
a5f6c8f5 OF |
3886 | fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_dwarf2_cfi = %i\n", |
3887 | tdep->cris_dwarf2_cfi); | |
29134980 OF |
3888 | } |
3889 | } | |
3890 | ||
3891 | static void | |
eb4c3f4a | 3892 | set_cris_version (const char *ignore_args, int from_tty, |
a5f6c8f5 | 3893 | struct cmd_list_element *c) |
29134980 OF |
3894 | { |
3895 | struct gdbarch_info info; | |
3896 | ||
a5f6c8f5 | 3897 | usr_cmd_cris_version_valid = 1; |
29134980 | 3898 | |
a5f6c8f5 OF |
3899 | /* Update the current architecture, if needed. */ |
3900 | gdbarch_info_init (&info); | |
3901 | if (!gdbarch_update_p (info)) | |
3902 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3903 | _("cris_gdbarch_update: failed to update architecture.")); |
29134980 OF |
3904 | } |
3905 | ||
0e6bdb31 | 3906 | static void |
eb4c3f4a | 3907 | set_cris_mode (const char *ignore_args, int from_tty, |
0e6bdb31 OF |
3908 | struct cmd_list_element *c) |
3909 | { | |
3910 | struct gdbarch_info info; | |
3911 | ||
3912 | /* Update the current architecture, if needed. */ | |
3913 | gdbarch_info_init (&info); | |
3914 | if (!gdbarch_update_p (info)) | |
3915 | internal_error (__FILE__, __LINE__, | |
3916 | "cris_gdbarch_update: failed to update architecture."); | |
3917 | } | |
3918 | ||
29134980 | 3919 | static void |
eb4c3f4a | 3920 | set_cris_dwarf2_cfi (const char *ignore_args, int from_tty, |
a5f6c8f5 | 3921 | struct cmd_list_element *c) |
29134980 OF |
3922 | { |
3923 | struct gdbarch_info info; | |
a5f6c8f5 OF |
3924 | |
3925 | /* Update the current architecture, if needed. */ | |
3926 | gdbarch_info_init (&info); | |
3927 | if (!gdbarch_update_p (info)) | |
3928 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 3929 | _("cris_gdbarch_update: failed to update architecture.")); |
29134980 OF |
3930 | } |
3931 | ||
29134980 OF |
3932 | static struct gdbarch * |
3933 | cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) | |
3934 | { | |
3935 | struct gdbarch *gdbarch; | |
3936 | struct gdbarch_tdep *tdep; | |
e4286e57 | 3937 | unsigned int cris_version; |
29134980 OF |
3938 | |
3939 | if (usr_cmd_cris_version_valid) | |
3940 | { | |
3941 | /* Trust the user's CRIS version setting. */ | |
3942 | cris_version = usr_cmd_cris_version; | |
3943 | } | |
c600d464 OF |
3944 | else if (info.abfd && bfd_get_mach (info.abfd) == bfd_mach_cris_v32) |
3945 | { | |
3946 | cris_version = 32; | |
3947 | } | |
29134980 OF |
3948 | else |
3949 | { | |
3950 | /* Assume it's CRIS version 10. */ | |
3951 | cris_version = 10; | |
3952 | } | |
3953 | ||
29134980 OF |
3954 | /* Make the current settings visible to the user. */ |
3955 | usr_cmd_cris_version = cris_version; | |
29134980 | 3956 | |
0e6bdb31 | 3957 | /* Find a candidate among the list of pre-declared architectures. */ |
29134980 OF |
3958 | for (arches = gdbarch_list_lookup_by_info (arches, &info); |
3959 | arches != NULL; | |
3960 | arches = gdbarch_list_lookup_by_info (arches->next, &info)) | |
3961 | { | |
a5f6c8f5 OF |
3962 | if ((gdbarch_tdep (arches->gdbarch)->cris_version |
3963 | == usr_cmd_cris_version) | |
0e6bdb31 OF |
3964 | && (gdbarch_tdep (arches->gdbarch)->cris_mode |
3965 | == usr_cmd_cris_mode) | |
a5f6c8f5 OF |
3966 | && (gdbarch_tdep (arches->gdbarch)->cris_dwarf2_cfi |
3967 | == usr_cmd_cris_dwarf2_cfi)) | |
29134980 OF |
3968 | return arches->gdbarch; |
3969 | } | |
3970 | ||
3971 | /* No matching architecture was found. Create a new one. */ | |
cdd238da | 3972 | tdep = XCNEW (struct gdbarch_tdep); |
7cf1de6c | 3973 | info.byte_order = BFD_ENDIAN_LITTLE; |
29134980 OF |
3974 | gdbarch = gdbarch_alloc (&info, tdep); |
3975 | ||
a5f6c8f5 | 3976 | tdep->cris_version = usr_cmd_cris_version; |
0e6bdb31 | 3977 | tdep->cris_mode = usr_cmd_cris_mode; |
a5f6c8f5 | 3978 | tdep->cris_dwarf2_cfi = usr_cmd_cris_dwarf2_cfi; |
29134980 | 3979 | |
b4206d25 | 3980 | set_gdbarch_return_value (gdbarch, cris_return_value); |
29134980 | 3981 | set_gdbarch_sp_regnum (gdbarch, 14); |
c600d464 OF |
3982 | |
3983 | /* Length of ordinary registers used in push_word and a few other | |
3984 | places. register_size() is the real way to know how big a | |
3985 | register is. */ | |
a5f6c8f5 | 3986 | |
2e4b5889 | 3987 | set_gdbarch_double_bit (gdbarch, 64); |
ea06eb3d | 3988 | /* The default definition of a long double is 2 * gdbarch_double_bit, |
2e4b5889 | 3989 | which means we have to set this explicitly. */ |
c600d464 | 3990 | set_gdbarch_long_double_bit (gdbarch, 64); |
29134980 | 3991 | |
29134980 OF |
3992 | /* The total amount of space needed to store (in an array called registers) |
3993 | GDB's copy of the machine's register state. Note: We can not use | |
d93859e2 | 3994 | cris_register_size at this point, since it relies on gdbarch |
29134980 OF |
3995 | being set. */ |
3996 | switch (tdep->cris_version) | |
3997 | { | |
3998 | case 0: | |
3999 | case 1: | |
4000 | case 2: | |
4001 | case 3: | |
29134980 OF |
4002 | case 8: |
4003 | case 9: | |
a5f6c8f5 | 4004 | /* Old versions; not supported. */ |
114d7832 | 4005 | return 0; |
29134980 OF |
4006 | |
4007 | case 10: | |
4008 | case 11: | |
4009 | /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100, | |
4010 | P7 (32 bits), and P15 (32 bits) have been implemented. */ | |
c600d464 OF |
4011 | set_gdbarch_pc_regnum (gdbarch, 15); |
4012 | set_gdbarch_register_type (gdbarch, cris_register_type); | |
4013 | /* There are 32 registers (some of which may not be implemented). */ | |
4014 | set_gdbarch_num_regs (gdbarch, 32); | |
4015 | set_gdbarch_register_name (gdbarch, cris_register_name); | |
4016 | set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register); | |
4017 | set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register); | |
4018 | ||
4019 | set_gdbarch_software_single_step (gdbarch, cris_software_single_step); | |
4020 | break; | |
4021 | ||
4022 | case 32: | |
4023 | /* CRIS v32. General registers R0 - R15 (32 bits), special registers | |
4024 | P0 - P15 (32 bits) except P0, P1, P3 (8 bits) and P4 (16 bits) | |
4025 | and pseudo-register PC (32 bits). */ | |
4026 | set_gdbarch_pc_regnum (gdbarch, 32); | |
4027 | set_gdbarch_register_type (gdbarch, crisv32_register_type); | |
4028 | /* 32 registers + pseudo-register PC + 16 support registers. */ | |
4029 | set_gdbarch_num_regs (gdbarch, 32 + 1 + 16); | |
4030 | set_gdbarch_register_name (gdbarch, crisv32_register_name); | |
4031 | ||
4032 | set_gdbarch_cannot_store_register | |
4033 | (gdbarch, crisv32_cannot_store_register); | |
4034 | set_gdbarch_cannot_fetch_register | |
4035 | (gdbarch, crisv32_cannot_fetch_register); | |
4036 | ||
4037 | set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1); | |
4038 | ||
4039 | set_gdbarch_single_step_through_delay | |
4040 | (gdbarch, crisv32_single_step_through_delay); | |
4041 | ||
29134980 OF |
4042 | break; |
4043 | ||
4044 | default: | |
114d7832 PA |
4045 | /* Unknown version. */ |
4046 | return 0; | |
29134980 OF |
4047 | } |
4048 | ||
c600d464 OF |
4049 | /* Dummy frame functions (shared between CRISv10 and CRISv32 since they |
4050 | have the same ABI). */ | |
2e4b5889 OF |
4051 | set_gdbarch_push_dummy_code (gdbarch, cris_push_dummy_code); |
4052 | set_gdbarch_push_dummy_call (gdbarch, cris_push_dummy_call); | |
4053 | set_gdbarch_frame_align (gdbarch, cris_frame_align); | |
29134980 | 4054 | set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue); |
29134980 OF |
4055 | |
4056 | /* The stack grows downward. */ | |
4057 | set_gdbarch_inner_than (gdbarch, core_addr_lessthan); | |
4058 | ||
04180708 YQ |
4059 | set_gdbarch_breakpoint_kind_from_pc (gdbarch, cris_breakpoint_kind_from_pc); |
4060 | set_gdbarch_sw_breakpoint_from_kind (gdbarch, cris_sw_breakpoint_from_kind); | |
29134980 | 4061 | |
a5f6c8f5 OF |
4062 | if (tdep->cris_dwarf2_cfi == 1) |
4063 | { | |
4064 | /* Hook in the Dwarf-2 frame sniffer. */ | |
4065 | set_gdbarch_dwarf2_reg_to_regnum (gdbarch, cris_dwarf2_reg_to_regnum); | |
4066 | dwarf2_frame_set_init_reg (gdbarch, cris_dwarf2_frame_init_reg); | |
94afd7a6 | 4067 | dwarf2_append_unwinders (gdbarch); |
a5f6c8f5 OF |
4068 | } |
4069 | ||
0e6bdb31 OF |
4070 | if (tdep->cris_mode != cris_mode_guru) |
4071 | { | |
94afd7a6 | 4072 | frame_unwind_append_unwinder (gdbarch, &cris_sigtramp_frame_unwind); |
0e6bdb31 | 4073 | } |
a5f6c8f5 | 4074 | |
94afd7a6 | 4075 | frame_unwind_append_unwinder (gdbarch, &cris_frame_unwind); |
2e4b5889 | 4076 | frame_base_set_default (gdbarch, &cris_frame_base); |
6c0e89ed | 4077 | |
749c8b38 RW |
4078 | /* Hook in ABI-specific overrides, if they have been registered. */ |
4079 | gdbarch_init_osabi (info, gdbarch); | |
4080 | ||
29134980 OF |
4081 | return gdbarch; |
4082 | } |