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