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