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