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