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