2002-11-13 Andrew Cagney <cagney@redhat.com>
[deliverable/binutils-gdb.git] / gdb / cris-tdep.c
1 /* Target dependent code for CRIS, for GDB, the GNU debugger.
2 Copyright 2001 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 int signal_handler_caller
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 signal_handler_caller is non-zero when the frame is
409 associated with the call of a signal handler.
410
411 The variable return_pc contains the address where execution should be
412 resumed when the present frame has finished, the return address.
413
414 The variable leaf_function is 1 if the return address is in the register
415 SRP, and 0 if it is on the stack.
416
417 Prologue instructions C-code.
418 The prologue may consist of (-fno-omit-frame-pointer)
419 1) 2)
420 push srp
421 push r8 push r8
422 move.d sp,r8 move.d sp,r8
423 subq X,sp subq X,sp
424 movem rY,[sp] movem rY,[sp]
425 move.S rZ,[r8-U] move.S rZ,[r8-U]
426
427 where 1 is a non-terminal function, and 2 is a leaf-function.
428
429 Note that this assumption is extremely brittle, and will break at the
430 slightest change in GCC's prologue.
431
432 If local variables are declared or register contents are saved on stack
433 the subq-instruction will be present with X as the number of bytes
434 needed for storage. The reshuffle with respect to r8 may be performed
435 with any size S (b, w, d) and any of the general registers Z={0..13}.
436 The offset U should be representable by a signed 8-bit value in all cases.
437 Thus, the prefix word is assumed to be immediate byte offset mode followed
438 by another word containing the instruction.
439
440 Degenerate cases:
441 3)
442 push r8
443 move.d sp,r8
444 move.d r8,sp
445 pop r8
446
447 Prologue instructions C++-code.
448 Case 1) and 2) in the C-code may be followed by
449
450 move.d r10,rS ; this
451 move.d r11,rT ; P1
452 move.d r12,rU ; P2
453 move.d r13,rV ; P3
454 move.S [r8+U],rZ ; P4
455
456 if any of the call parameters are stored. The host expects these
457 instructions to be executed in order to get the call parameters right. */
458
459 /* Examine the prologue of a function. The variable ip is the address of
460 the first instruction of the prologue. The variable limit is the address
461 of the first instruction after the prologue. The variable fi contains the
462 information in struct frame_info. The variable frameless_p controls whether
463 the entire prologue is examined (0) or just enough instructions to
464 determine that it is a prologue (1). */
465
466 CORE_ADDR
467 cris_examine (CORE_ADDR ip, CORE_ADDR limit, struct frame_info *fi,
468 int frameless_p)
469 {
470 /* Present instruction. */
471 unsigned short insn;
472
473 /* Next instruction, lookahead. */
474 unsigned short insn_next;
475 int regno;
476
477 /* Is there a push fp? */
478 int have_fp;
479
480 /* Number of byte on stack used for local variables and movem. */
481 int val;
482
483 /* Highest register number in a movem. */
484 int regsave;
485
486 /* move.d r<source_register>,rS */
487 short source_register;
488
489 /* This frame is with respect to a leaf until a push srp is found. */
490 fi->extra_info->leaf_function = 1;
491
492 /* This frame is without the FP until a push fp is found. */
493 have_fp = 0;
494
495 /* Assume nothing on stack. */
496 val = 0;
497 regsave = -1;
498
499 /* No information about register contents so far. */
500
501 /* We only want to know the end of the prologue when fi->saved_regs == 0.
502 When the saved registers are allocated full information is required. */
503 if (fi->saved_regs)
504 {
505 for (regno = 0; regno < NUM_REGS; regno++)
506 fi->saved_regs[regno] = 0;
507 }
508
509 /* Find the prologue instructions. */
510 do
511 {
512 insn = read_memory_unsigned_integer (ip, sizeof (short));
513 ip += sizeof (short);
514 if (insn == 0xE1FC)
515 {
516 /* push <reg> 32 bit instruction */
517 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
518 ip += sizeof (short);
519 regno = cris_get_operand2 (insn_next);
520
521 /* This check, meant to recognize srp, used to be regno ==
522 (SRP_REGNUM - NUM_GENREGS), but that covers r11 also. */
523 if (insn_next == 0xBE7E)
524 {
525 if (frameless_p)
526 {
527 return ip;
528 }
529 fi->extra_info->leaf_function = 0;
530 }
531 else if (regno == FP_REGNUM)
532 {
533 have_fp = 1;
534 }
535 }
536 else if (insn == 0x866E)
537 {
538 /* move.d sp,r8 */
539 if (frameless_p)
540 {
541 return ip;
542 }
543 continue;
544 }
545 else if (cris_get_operand2 (insn) == SP_REGNUM
546 && cris_get_mode (insn) == 0x0000
547 && cris_get_opcode (insn) == 0x000A)
548 {
549 /* subq <val>,sp */
550 val = cris_get_quick_value (insn);
551 }
552 else if (cris_get_mode (insn) == 0x0002
553 && cris_get_opcode (insn) == 0x000F
554 && cris_get_size (insn) == 0x0003
555 && cris_get_operand1 (insn) == SP_REGNUM)
556 {
557 /* movem r<regsave>,[sp] */
558 if (frameless_p)
559 {
560 return ip;
561 }
562 regsave = cris_get_operand2 (insn);
563 }
564 else if (cris_get_operand2 (insn) == SP_REGNUM
565 && ((insn & 0x0F00) >> 8) == 0x0001
566 && (cris_get_signed_offset (insn) < 0))
567 {
568 /* Immediate byte offset addressing prefix word with sp as base
569 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
570 is between 64 and 128.
571 movem r<regsave>,[sp=sp-<val>] */
572 val = -cris_get_signed_offset (insn);
573 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
574 ip += sizeof (short);
575 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
576 && cris_get_opcode (insn_next) == 0x000F
577 && cris_get_size (insn_next) == 0x0003
578 && cris_get_operand1 (insn_next) == SP_REGNUM)
579 {
580 if (frameless_p)
581 {
582 return ip;
583 }
584 regsave = cris_get_operand2 (insn_next);
585 }
586 else
587 {
588 /* The prologue ended before the limit was reached. */
589 ip -= 2 * sizeof (short);
590 break;
591 }
592 }
593 else if (cris_get_mode (insn) == 0x0001
594 && cris_get_opcode (insn) == 0x0009
595 && cris_get_size (insn) == 0x0002)
596 {
597 /* move.d r<10..13>,r<0..15> */
598 if (frameless_p)
599 {
600 return ip;
601 }
602 source_register = cris_get_operand1 (insn);
603
604 /* FIXME? In the glibc solibs, the prologue might contain something
605 like (this example taken from relocate_doit):
606 move.d $pc,$r0
607 sub.d 0xfffef426,$r0
608 which isn't covered by the source_register check below. Question
609 is whether to add a check for this combo, or make better use of
610 the limit variable instead. */
611 if (source_register < ARG1_REGNUM || source_register > ARG4_REGNUM)
612 {
613 /* The prologue ended before the limit was reached. */
614 ip -= sizeof (short);
615 break;
616 }
617 }
618 else if (cris_get_operand2 (insn) == FP_REGNUM
619 /* The size is a fixed-size. */
620 && ((insn & 0x0F00) >> 8) == 0x0001
621 /* A negative offset. */
622 && (cris_get_signed_offset (insn) < 0))
623 {
624 /* move.S rZ,[r8-U] (?) */
625 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
626 ip += sizeof (short);
627 regno = cris_get_operand2 (insn_next);
628 if ((regno >= 0 && regno < SP_REGNUM)
629 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
630 && cris_get_opcode (insn_next) == 0x000F)
631 {
632 /* move.S rZ,[r8-U] */
633 continue;
634 }
635 else
636 {
637 /* The prologue ended before the limit was reached. */
638 ip -= 2 * sizeof (short);
639 break;
640 }
641 }
642 else if (cris_get_operand2 (insn) == FP_REGNUM
643 /* The size is a fixed-size. */
644 && ((insn & 0x0F00) >> 8) == 0x0001
645 /* A positive offset. */
646 && (cris_get_signed_offset (insn) > 0))
647 {
648 /* move.S [r8+U],rZ (?) */
649 insn_next = read_memory_unsigned_integer (ip, sizeof (short));
650 ip += sizeof (short);
651 regno = cris_get_operand2 (insn_next);
652 if ((regno >= 0 && regno < SP_REGNUM)
653 && cris_get_mode (insn_next) == PREFIX_OFFSET_MODE
654 && cris_get_opcode (insn_next) == 0x0009
655 && cris_get_operand1 (insn_next) == regno)
656 {
657 /* move.S [r8+U],rZ */
658 continue;
659 }
660 else
661 {
662 /* The prologue ended before the limit was reached. */
663 ip -= 2 * sizeof (short);
664 break;
665 }
666 }
667 else
668 {
669 /* The prologue ended before the limit was reached. */
670 ip -= sizeof (short);
671 break;
672 }
673 }
674 while (ip < limit);
675
676 /* We only want to know the end of the prologue when
677 fi->saved_regs == 0. */
678 if (!fi->saved_regs)
679 return ip;
680
681 if (have_fp)
682 {
683 fi->saved_regs[FP_REGNUM] = FRAME_FP (fi);
684
685 /* Calculate the addresses. */
686 for (regno = regsave; regno >= 0; regno--)
687 {
688 fi->saved_regs[regno] = FRAME_FP (fi) - val;
689 val -= 4;
690 }
691 if (fi->extra_info->leaf_function)
692 {
693 /* Set the register SP to contain the stack pointer of
694 the caller. */
695 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 4;
696 }
697 else
698 {
699 /* Set the register SP to contain the stack pointer of
700 the caller. */
701 fi->saved_regs[SP_REGNUM] = FRAME_FP (fi) + 8;
702
703 /* Set the register SRP to contain the return address of
704 the caller. */
705 fi->saved_regs[SRP_REGNUM] = FRAME_FP (fi) + 4;
706 }
707 }
708 return ip;
709 }
710
711 /* Advance pc beyond any function entry prologue instructions at pc
712 to reach some "real" code. */
713
714 CORE_ADDR
715 cris_skip_prologue (CORE_ADDR pc)
716 {
717 return cris_skip_prologue_main (pc, 0);
718 }
719
720 /* As cris_skip_prologue, but stops as soon as it knows that the function
721 has a frame. Its result is equal to its input pc if the function is
722 frameless, unequal otherwise. */
723
724 CORE_ADDR
725 cris_skip_prologue_frameless_p (CORE_ADDR pc)
726 {
727 return cris_skip_prologue_main (pc, 1);
728 }
729
730 /* Given a PC value corresponding to the start of a function, return the PC
731 of the first instruction after the function prologue. */
732
733 CORE_ADDR
734 cris_skip_prologue_main (CORE_ADDR pc, int frameless_p)
735 {
736 struct frame_info fi;
737 static struct frame_extra_info fei;
738 struct symtab_and_line sal = find_pc_line (pc, 0);
739 int best_limit;
740 CORE_ADDR pc_after_prologue;
741
742 /* frame_info now contains dynamic memory. Since fi is a dummy here,
743 I use static memory for extra_info, and don't bother allocating
744 memory for saved_regs. */
745 fi.saved_regs = 0;
746 fi.extra_info = &fei;
747
748 /* If there is no symbol information then sal.end == 0, and we end up
749 examining only the first instruction in the function prologue.
750 Exaggerating the limit seems to be harmless. */
751 if (sal.end > 0)
752 best_limit = sal.end;
753 else
754 best_limit = pc + 100;
755
756 pc_after_prologue = cris_examine (pc, best_limit, &fi, frameless_p);
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 (fi->signal_handler_caller)
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 (fi->pc, 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 (fi->saved_regs)
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 (fi->pc);
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 fi->pc = 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 (PC_IN_CALL_DUMMY (fi->pc, 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 fi->frame = deprecated_read_register_dummy (fi->pc, fi->frame,
1220 SP_REGNUM);
1221 fi->extra_info->return_pc =
1222 deprecated_read_register_dummy (fi->pc, 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 (fi->saved_regs[SRP_REGNUM] != 0)
1234 {
1235 /* SRP was saved on the stack; non-leaf function. */
1236 fi->extra_info->return_pc =
1237 read_memory_integer (fi->saved_regs[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 (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1257 {
1258 return fi->frame;
1259 }
1260 else if (!inside_entry_file (fi->pc))
1261 {
1262 return read_memory_unsigned_integer (FRAME_FP (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 /* Return the address of the argument block for the frame described
1279 by struct frame_info. */
1280
1281 CORE_ADDR
1282 cris_frame_args_address (struct frame_info *fi)
1283 {
1284 return FRAME_FP (fi);
1285 }
1286
1287 /* Return the address of the locals block for the frame
1288 described by struct frame_info. */
1289
1290 CORE_ADDR
1291 cris_frame_locals_address (struct frame_info *fi)
1292 {
1293 return FRAME_FP (fi);
1294 }
1295
1296 /* Setup the function arguments for calling a function in the inferior. */
1297
1298 CORE_ADDR
1299 cris_abi_original_push_arguments (int nargs, struct value **args,
1300 CORE_ADDR sp, int struct_return,
1301 CORE_ADDR struct_addr)
1302 {
1303 int stack_alloc;
1304 int stack_offset;
1305 int argreg;
1306 int argnum;
1307 struct type *type;
1308 int len;
1309 CORE_ADDR regval;
1310 char *val;
1311
1312 /* Data and parameters reside in different areas on the stack.
1313 Both frame pointers grow toward higher addresses. */
1314 CORE_ADDR fp_params;
1315 CORE_ADDR fp_data;
1316
1317 /* Are we returning a value using a structure return or a normal value
1318 return? struct_addr is the address of the reserved space for the return
1319 structure to be written on the stack. */
1320 if (struct_return)
1321 {
1322 write_register (STR_REGNUM, struct_addr);
1323 }
1324
1325 /* Make sure there's space on the stack. Allocate space for data and a
1326 parameter to refer to that data. */
1327 for (argnum = 0, stack_alloc = 0; argnum < nargs; argnum++)
1328 stack_alloc += (TYPE_LENGTH (VALUE_TYPE (args[argnum])) + REGISTER_SIZE);
1329 sp -= stack_alloc;
1330 /* We may over-allocate a little here, but that won't hurt anything. */
1331
1332 /* Initialize stack frame pointers. */
1333 fp_params = sp;
1334 fp_data = sp + (nargs * REGISTER_SIZE);
1335
1336 /* Now load as many as possible of the first arguments into
1337 registers, and push the rest onto the stack. */
1338 argreg = ARG1_REGNUM;
1339 stack_offset = 0;
1340
1341 for (argnum = 0; argnum < nargs; argnum++)
1342 {
1343 type = VALUE_TYPE (args[argnum]);
1344 len = TYPE_LENGTH (type);
1345 val = (char *) VALUE_CONTENTS (args[argnum]);
1346
1347 if (len <= REGISTER_SIZE && argreg <= ARG4_REGNUM)
1348 {
1349 /* Data fits in a register; put it in the first available
1350 register. */
1351 write_register (argreg, *(unsigned long *) val);
1352 argreg++;
1353 }
1354 else if (len > REGISTER_SIZE && argreg <= ARG4_REGNUM)
1355 {
1356 /* Data does not fit in register; pass it on the stack and
1357 put its address in the first available register. */
1358 write_memory (fp_data, val, len);
1359 write_register (argreg, fp_data);
1360 fp_data += len;
1361 argreg++;
1362 }
1363 else if (len > REGISTER_SIZE)
1364 {
1365 /* Data does not fit in register; put both data and
1366 parameter on the stack. */
1367 write_memory (fp_data, val, len);
1368 write_memory (fp_params, (char *) (&fp_data), REGISTER_SIZE);
1369 fp_data += len;
1370 fp_params += REGISTER_SIZE;
1371 }
1372 else
1373 {
1374 /* Data fits in a register, but we are out of registers;
1375 put the parameter on the stack. */
1376 write_memory (fp_params, val, REGISTER_SIZE);
1377 fp_params += REGISTER_SIZE;
1378 }
1379 }
1380
1381 return sp;
1382 }
1383
1384 CORE_ADDR
1385 cris_abi_v2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
1386 int struct_return, CORE_ADDR struct_addr)
1387 {
1388 int stack_alloc;
1389 int stack_offset;
1390 int argreg;
1391 int argnum;
1392
1393 CORE_ADDR regval;
1394
1395 /* The function's arguments and memory allocated by gdb for the arguments to
1396 point at reside in separate areas on the stack.
1397 Both frame pointers grow toward higher addresses. */
1398 CORE_ADDR fp_arg;
1399 CORE_ADDR fp_mem;
1400
1401 /* Are we returning a value using a structure return or a normal value
1402 return? struct_addr is the address of the reserved space for the return
1403 structure to be written on the stack. */
1404 if (struct_return)
1405 {
1406 write_register (STR_REGNUM, struct_addr);
1407 }
1408
1409 /* Allocate enough to keep things word-aligned on both parts of the
1410 stack. */
1411 stack_alloc = 0;
1412 for (argnum = 0; argnum < nargs; argnum++)
1413 {
1414 int len;
1415 int reg_demand;
1416
1417 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1418 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1419
1420 /* reg_demand * REGISTER_SIZE is the amount of memory we might need to
1421 allocate for this argument. 2 * REGISTER_SIZE is the amount of stack
1422 space we might need to pass the argument itself (either by value or by
1423 reference). */
1424 stack_alloc += (reg_demand * REGISTER_SIZE + 2 * REGISTER_SIZE);
1425 }
1426 sp -= stack_alloc;
1427 /* We may over-allocate a little here, but that won't hurt anything. */
1428
1429 /* Initialize frame pointers. */
1430 fp_arg = sp;
1431 fp_mem = sp + (nargs * (2 * REGISTER_SIZE));
1432
1433 /* Now load as many as possible of the first arguments into registers,
1434 and push the rest onto the stack. */
1435 argreg = ARG1_REGNUM;
1436 stack_offset = 0;
1437
1438 for (argnum = 0; argnum < nargs; argnum++)
1439 {
1440 int len;
1441 char *val;
1442 int reg_demand;
1443 int i;
1444
1445 len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
1446 val = (char *) VALUE_CONTENTS (args[argnum]);
1447
1448 /* How may registers worth of storage do we need for this argument? */
1449 reg_demand = (len / REGISTER_SIZE) + (len % REGISTER_SIZE != 0 ? 1 : 0);
1450
1451 if (len <= (2 * REGISTER_SIZE)
1452 && (argreg + reg_demand - 1 <= ARG4_REGNUM))
1453 {
1454 /* Data passed by value. Fits in available register(s). */
1455 for (i = 0; i < reg_demand; i++)
1456 {
1457 write_register (argreg, *(unsigned long *) val);
1458 argreg++;
1459 val += REGISTER_SIZE;
1460 }
1461 }
1462 else if (len <= (2 * REGISTER_SIZE) && argreg <= ARG4_REGNUM)
1463 {
1464 /* Data passed by value. Does not fit in available register(s).
1465 Use the register(s) first, then the stack. */
1466 for (i = 0; i < reg_demand; i++)
1467 {
1468 if (argreg <= ARG4_REGNUM)
1469 {
1470 write_register (argreg, *(unsigned long *) val);
1471 argreg++;
1472 val += REGISTER_SIZE;
1473 }
1474 else
1475 {
1476 /* I guess this memory write could write the remaining data
1477 all at once instead of in REGISTER_SIZE chunks. */
1478 write_memory (fp_arg, val, REGISTER_SIZE);
1479 fp_arg += REGISTER_SIZE;
1480 val += REGISTER_SIZE;
1481 }
1482 }
1483 }
1484 else if (len > (2 * REGISTER_SIZE))
1485 {
1486 /* Data passed by reference. Put it on the stack. */
1487 write_memory (fp_mem, val, len);
1488 write_memory (fp_arg, (char *) (&fp_mem), REGISTER_SIZE);
1489
1490 /* fp_mem need not be word-aligned since it's just a chunk of
1491 memory being pointed at. That is, += len would do. */
1492 fp_mem += reg_demand * REGISTER_SIZE;
1493 fp_arg += REGISTER_SIZE;
1494 }
1495 else
1496 {
1497 /* Data passed by value. No available registers. Put it on
1498 the stack. */
1499 write_memory (fp_arg, val, len);
1500
1501 /* fp_arg must be word-aligned (i.e., don't += len) to match
1502 the function prologue. */
1503 fp_arg += reg_demand * REGISTER_SIZE;
1504 }
1505 }
1506
1507 return sp;
1508 }
1509
1510 /* Never put the return address on the stack. The register SRP is pushed
1511 by the called function unless it is a leaf-function. Due to the BRP
1512 register the PC will change when continue is sent. */
1513
1514 CORE_ADDR
1515 cris_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1516 {
1517 write_register (SRP_REGNUM, CALL_DUMMY_ADDRESS ());
1518 return sp;
1519 }
1520
1521 /* Restore the machine to the state it had before the current frame
1522 was created. Discard the innermost frame from the stack and restore
1523 all saved registers. */
1524
1525 void
1526 cris_pop_frame (void)
1527 {
1528 register struct frame_info *fi = get_current_frame ();
1529 register int regno;
1530 register int stack_offset = 0;
1531
1532 if (PC_IN_CALL_DUMMY (fi->pc, fi->frame, fi->frame))
1533 {
1534 /* This happens when we hit a breakpoint set at the entry point,
1535 when returning from a dummy frame. */
1536 generic_pop_dummy_frame ();
1537 }
1538 else
1539 {
1540 cris_frame_init_saved_regs (fi);
1541
1542 /* For each register, the address of where it was saved on entry to
1543 the frame now lies in fi->saved_regs[regno], or zero if it was not
1544 saved. This includes special registers such as PC and FP saved in
1545 special ways in the stack frame. The SP_REGNUM is even more
1546 special, the address here is the SP for the next frame, not the
1547 address where the SP was saved. */
1548
1549 /* Restore general registers R0 - R7. They were pushed on the stack
1550 after SP was saved. */
1551 for (regno = 0; regno < FP_REGNUM; regno++)
1552 {
1553 if (fi->saved_regs[regno])
1554 {
1555 write_register (regno,
1556 read_memory_integer (fi->saved_regs[regno], 4));
1557 }
1558 }
1559
1560 if (fi->saved_regs[FP_REGNUM])
1561 {
1562 /* Pop the frame pointer (R8). It was pushed before SP
1563 was saved. */
1564 write_register (FP_REGNUM,
1565 read_memory_integer (fi->saved_regs[FP_REGNUM], 4));
1566 stack_offset += 4;
1567
1568 /* Not a leaf function. */
1569 if (fi->saved_regs[SRP_REGNUM])
1570 {
1571 /* SRP was pushed before SP was saved. */
1572 stack_offset += 4;
1573 }
1574
1575 /* Restore the SP and adjust for R8 and (possibly) SRP. */
1576 write_register (SP_REGNUM, fi->saved_regs[FP_REGNUM] + stack_offset);
1577 }
1578 else
1579 {
1580 /* Currently, we can't get the correct info into fi->saved_regs
1581 without a frame pointer. */
1582 }
1583
1584 /* Restore the PC. */
1585 write_register (PC_REGNUM, fi->extra_info->return_pc);
1586 }
1587 flush_cached_frames ();
1588 }
1589
1590 /* Calculates a value that measures how good inst_args constraints an
1591 instruction. It stems from cris_constraint, found in cris-dis.c. */
1592
1593 static int
1594 constraint (unsigned int insn, const signed char *inst_args,
1595 inst_env_type *inst_env)
1596 {
1597 int retval = 0;
1598 int tmp, i;
1599
1600 const char *s = inst_args;
1601
1602 for (; *s; s++)
1603 switch (*s)
1604 {
1605 case 'm':
1606 if ((insn & 0x30) == 0x30)
1607 return -1;
1608 break;
1609
1610 case 'S':
1611 /* A prefix operand. */
1612 if (inst_env->prefix_found)
1613 break;
1614 else
1615 return -1;
1616
1617 case 'B':
1618 /* A "push" prefix. (This check was REMOVED by san 970921.) Check for
1619 valid "push" size. In case of special register, it may be != 4. */
1620 if (inst_env->prefix_found)
1621 break;
1622 else
1623 return -1;
1624
1625 case 'D':
1626 retval = (((insn >> 0xC) & 0xF) == (insn & 0xF));
1627 if (!retval)
1628 return -1;
1629 else
1630 retval += 4;
1631 break;
1632
1633 case 'P':
1634 tmp = (insn >> 0xC) & 0xF;
1635
1636 for (i = 0; cris_spec_regs[i].name != NULL; i++)
1637 {
1638 /* Since we match four bits, we will give a value of
1639 4 - 1 = 3 in a match. If there is a corresponding
1640 exact match of a special register in another pattern, it
1641 will get a value of 4, which will be higher. This should
1642 be correct in that an exact pattern would match better that
1643 a general pattern.
1644 Note that there is a reason for not returning zero; the
1645 pattern for "clear" is partly matched in the bit-pattern
1646 (the two lower bits must be zero), while the bit-pattern
1647 for a move from a special register is matched in the
1648 register constraint.
1649 This also means we will will have a race condition if
1650 there is a partly match in three bits in the bit pattern. */
1651 if (tmp == cris_spec_regs[i].number)
1652 {
1653 retval += 3;
1654 break;
1655 }
1656 }
1657
1658 if (cris_spec_regs[i].name == NULL)
1659 return -1;
1660 break;
1661 }
1662 return retval;
1663 }
1664
1665 /* Returns the number of bits set in the variable value. */
1666
1667 static int
1668 number_of_bits (unsigned int value)
1669 {
1670 int number_of_bits = 0;
1671
1672 while (value != 0)
1673 {
1674 number_of_bits += 1;
1675 value &= (value - 1);
1676 }
1677 return number_of_bits;
1678 }
1679
1680 /* Finds the address that should contain the single step breakpoint(s).
1681 It stems from code in cris-dis.c. */
1682
1683 static int
1684 find_cris_op (unsigned short insn, inst_env_type *inst_env)
1685 {
1686 int i;
1687 int max_level_of_match = -1;
1688 int max_matched = -1;
1689 int level_of_match;
1690
1691 for (i = 0; cris_opcodes[i].name != NULL; i++)
1692 {
1693 if (((cris_opcodes[i].match & insn) == cris_opcodes[i].match)
1694 && ((cris_opcodes[i].lose & insn) == 0))
1695 {
1696 level_of_match = constraint (insn, cris_opcodes[i].args, inst_env);
1697 if (level_of_match >= 0)
1698 {
1699 level_of_match +=
1700 number_of_bits (cris_opcodes[i].match | cris_opcodes[i].lose);
1701 if (level_of_match > max_level_of_match)
1702 {
1703 max_matched = i;
1704 max_level_of_match = level_of_match;
1705 if (level_of_match == 16)
1706 {
1707 /* All bits matched, cannot find better. */
1708 break;
1709 }
1710 }
1711 }
1712 }
1713 }
1714 return max_matched;
1715 }
1716
1717 /* Attempts to find single-step breakpoints. Returns -1 on failure which is
1718 actually an internal error. */
1719
1720 static int
1721 find_step_target (inst_env_type *inst_env)
1722 {
1723 int i;
1724 int offset;
1725 unsigned short insn;
1726
1727 /* Create a local register image and set the initial state. */
1728 for (i = 0; i < NUM_GENREGS; i++)
1729 {
1730 inst_env->reg[i] = (unsigned long) read_register (i);
1731 }
1732 offset = NUM_GENREGS;
1733 for (i = 0; i < NUM_SPECREGS; i++)
1734 {
1735 inst_env->preg[i] = (unsigned long) read_register (offset + i);
1736 }
1737 inst_env->branch_found = 0;
1738 inst_env->slot_needed = 0;
1739 inst_env->delay_slot_pc_active = 0;
1740 inst_env->prefix_found = 0;
1741 inst_env->invalid = 0;
1742 inst_env->xflag_found = 0;
1743 inst_env->disable_interrupt = 0;
1744
1745 /* Look for a step target. */
1746 do
1747 {
1748 /* Read an instruction from the client. */
1749 insn = read_memory_unsigned_integer (inst_env->reg[PC_REGNUM], 2);
1750
1751 /* If the instruction is not in a delay slot the new content of the
1752 PC is [PC] + 2. If the instruction is in a delay slot it is not
1753 that simple. Since a instruction in a delay slot cannot change
1754 the content of the PC, it does not matter what value PC will have.
1755 Just make sure it is a valid instruction. */
1756 if (!inst_env->delay_slot_pc_active)
1757 {
1758 inst_env->reg[PC_REGNUM] += 2;
1759 }
1760 else
1761 {
1762 inst_env->delay_slot_pc_active = 0;
1763 inst_env->reg[PC_REGNUM] = inst_env->delay_slot_pc;
1764 }
1765 /* Analyse the present instruction. */
1766 i = find_cris_op (insn, inst_env);
1767 if (i == -1)
1768 {
1769 inst_env->invalid = 1;
1770 }
1771 else
1772 {
1773 cris_gdb_func (cris_opcodes[i].op, insn, inst_env);
1774 }
1775 } while (!inst_env->invalid
1776 && (inst_env->prefix_found || inst_env->xflag_found
1777 || inst_env->slot_needed));
1778 return i;
1779 }
1780
1781 /* There is no hardware single-step support. The function find_step_target
1782 digs through the opcodes in order to find all possible targets.
1783 Either one ordinary target or two targets for branches may be found. */
1784
1785 void
1786 cris_software_single_step (enum target_signal ignore, int insert_breakpoints)
1787 {
1788 inst_env_type inst_env;
1789
1790 if (insert_breakpoints)
1791 {
1792 /* Analyse the present instruction environment and insert
1793 breakpoints. */
1794 int status = find_step_target (&inst_env);
1795 if (status == -1)
1796 {
1797 /* Could not find a target. FIXME: Should do something. */
1798 }
1799 else
1800 {
1801 /* Insert at most two breakpoints. One for the next PC content
1802 and possibly another one for a branch, jump, etc. */
1803 next_pc = (CORE_ADDR) inst_env.reg[PC_REGNUM];
1804 target_insert_breakpoint (next_pc, break_mem[0]);
1805 if (inst_env.branch_found
1806 && (CORE_ADDR) inst_env.branch_break_address != next_pc)
1807 {
1808 branch_target_address =
1809 (CORE_ADDR) inst_env.branch_break_address;
1810 target_insert_breakpoint (branch_target_address, break_mem[1]);
1811 branch_break_inserted = 1;
1812 }
1813 }
1814 }
1815 else
1816 {
1817 /* Remove breakpoints. */
1818 target_remove_breakpoint (next_pc, break_mem[0]);
1819 if (branch_break_inserted)
1820 {
1821 target_remove_breakpoint (branch_target_address, break_mem[1]);
1822 branch_break_inserted = 0;
1823 }
1824 }
1825 }
1826
1827 /* Calculates the prefix value for quick offset addressing mode. */
1828
1829 void
1830 quick_mode_bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1831 {
1832 /* It's invalid to be in a delay slot. You can't have a prefix to this
1833 instruction (not 100% sure). */
1834 if (inst_env->slot_needed || inst_env->prefix_found)
1835 {
1836 inst_env->invalid = 1;
1837 return;
1838 }
1839
1840 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1841 inst_env->prefix_value += cris_get_bdap_quick_offset (inst);
1842
1843 /* A prefix doesn't change the xflag_found. But the rest of the flags
1844 need updating. */
1845 inst_env->slot_needed = 0;
1846 inst_env->prefix_found = 1;
1847 }
1848
1849 /* Updates the autoincrement register. The size of the increment is derived
1850 from the size of the operation. The PC is always kept aligned on even
1851 word addresses. */
1852
1853 void
1854 process_autoincrement (int size, unsigned short inst, inst_env_type *inst_env)
1855 {
1856 if (size == INST_BYTE_SIZE)
1857 {
1858 inst_env->reg[cris_get_operand1 (inst)] += 1;
1859
1860 /* The PC must be word aligned, so increase the PC with one
1861 word even if the size is byte. */
1862 if (cris_get_operand1 (inst) == REG_PC)
1863 {
1864 inst_env->reg[REG_PC] += 1;
1865 }
1866 }
1867 else if (size == INST_WORD_SIZE)
1868 {
1869 inst_env->reg[cris_get_operand1 (inst)] += 2;
1870 }
1871 else if (size == INST_DWORD_SIZE)
1872 {
1873 inst_env->reg[cris_get_operand1 (inst)] += 4;
1874 }
1875 else
1876 {
1877 /* Invalid size. */
1878 inst_env->invalid = 1;
1879 }
1880 }
1881
1882 /* Just a forward declaration. */
1883
1884 unsigned long
1885 get_data_from_address (unsigned short *inst, CORE_ADDR address);
1886
1887 /* Calculates the prefix value for the general case of offset addressing
1888 mode. */
1889
1890 void
1891 bdap_prefix (unsigned short inst, inst_env_type *inst_env)
1892 {
1893
1894 long offset;
1895
1896 /* It's invalid to be in a delay slot. */
1897 if (inst_env->slot_needed || inst_env->prefix_found)
1898 {
1899 inst_env->invalid = 1;
1900 return;
1901 }
1902
1903 /* The calculation of prefix_value used to be after process_autoincrement,
1904 but that fails for an instruction such as jsr [$r0+12] which is encoded
1905 as 5f0d 0c00 30b9 when compiled with -fpic. Since PC is operand1 it
1906 mustn't be incremented until we have read it and what it points at. */
1907 inst_env->prefix_value = inst_env->reg[cris_get_operand2 (inst)];
1908
1909 /* The offset is an indirection of the contents of the operand1 register. */
1910 inst_env->prefix_value +=
1911 get_data_from_address (&inst, inst_env->reg[cris_get_operand1 (inst)]);
1912
1913 if (cris_get_mode (inst) == AUTOINC_MODE)
1914 {
1915 process_autoincrement (cris_get_size (inst), inst, inst_env);
1916 }
1917
1918 /* A prefix doesn't change the xflag_found. But the rest of the flags
1919 need updating. */
1920 inst_env->slot_needed = 0;
1921 inst_env->prefix_found = 1;
1922 }
1923
1924 /* Calculates the prefix value for the index addressing mode. */
1925
1926 void
1927 biap_prefix (unsigned short inst, inst_env_type *inst_env)
1928 {
1929 /* It's invalid to be in a delay slot. I can't see that it's possible to
1930 have a prefix to this instruction. So I will treat this as invalid. */
1931 if (inst_env->slot_needed || inst_env->prefix_found)
1932 {
1933 inst_env->invalid = 1;
1934 return;
1935 }
1936
1937 inst_env->prefix_value = inst_env->reg[cris_get_operand1 (inst)];
1938
1939 /* The offset is the operand2 value shifted the size of the instruction
1940 to the left. */
1941 inst_env->prefix_value +=
1942 inst_env->reg[cris_get_operand2 (inst)] << cris_get_size (inst);
1943
1944 /* If the PC is operand1 (base) the address used is the address after
1945 the main instruction, i.e. address + 2 (the PC is already compensated
1946 for the prefix operation). */
1947 if (cris_get_operand1 (inst) == REG_PC)
1948 {
1949 inst_env->prefix_value += 2;
1950 }
1951
1952 /* A prefix doesn't change the xflag_found. But the rest of the flags
1953 need updating. */
1954 inst_env->slot_needed = 0;
1955 inst_env->xflag_found = 0;
1956 inst_env->prefix_found = 1;
1957 }
1958
1959 /* Calculates the prefix value for the double indirect addressing mode. */
1960
1961 void
1962 dip_prefix (unsigned short inst, inst_env_type *inst_env)
1963 {
1964
1965 CORE_ADDR address;
1966
1967 /* It's invalid to be in a delay slot. */
1968 if (inst_env->slot_needed || inst_env->prefix_found)
1969 {
1970 inst_env->invalid = 1;
1971 return;
1972 }
1973
1974 /* The prefix value is one dereference of the contents of the operand1
1975 register. */
1976 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
1977 inst_env->prefix_value = read_memory_unsigned_integer (address, 4);
1978
1979 /* Check if the mode is autoincrement. */
1980 if (cris_get_mode (inst) == AUTOINC_MODE)
1981 {
1982 inst_env->reg[cris_get_operand1 (inst)] += 4;
1983 }
1984
1985 /* A prefix doesn't change the xflag_found. But the rest of the flags
1986 need updating. */
1987 inst_env->slot_needed = 0;
1988 inst_env->xflag_found = 0;
1989 inst_env->prefix_found = 1;
1990 }
1991
1992 /* Finds the destination for a branch with 8-bits offset. */
1993
1994 void
1995 eight_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
1996 {
1997
1998 short offset;
1999
2000 /* If we have a prefix or are in a delay slot it's bad. */
2001 if (inst_env->slot_needed || inst_env->prefix_found)
2002 {
2003 inst_env->invalid = 1;
2004 return;
2005 }
2006
2007 /* We have a branch, find out where the branch will land. */
2008 offset = cris_get_branch_short_offset (inst);
2009
2010 /* Check if the offset is signed. */
2011 if (offset & BRANCH_SIGNED_SHORT_OFFSET_MASK)
2012 {
2013 offset |= 0xFF00;
2014 }
2015
2016 /* The offset ends with the sign bit, set it to zero. The address
2017 should always be word aligned. */
2018 offset &= ~BRANCH_SIGNED_SHORT_OFFSET_MASK;
2019
2020 inst_env->branch_found = 1;
2021 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2022
2023 inst_env->slot_needed = 1;
2024 inst_env->prefix_found = 0;
2025 inst_env->xflag_found = 0;
2026 inst_env->disable_interrupt = 1;
2027 }
2028
2029 /* Finds the destination for a branch with 16-bits offset. */
2030
2031 void
2032 sixteen_bit_offset_branch_op (unsigned short inst, inst_env_type *inst_env)
2033 {
2034 short offset;
2035
2036 /* If we have a prefix or is in a delay slot it's bad. */
2037 if (inst_env->slot_needed || inst_env->prefix_found)
2038 {
2039 inst_env->invalid = 1;
2040 return;
2041 }
2042
2043 /* We have a branch, find out the offset for the branch. */
2044 offset = read_memory_integer (inst_env->reg[REG_PC], 2);
2045
2046 /* The instruction is one word longer than normal, so add one word
2047 to the PC. */
2048 inst_env->reg[REG_PC] += 2;
2049
2050 inst_env->branch_found = 1;
2051 inst_env->branch_break_address = inst_env->reg[REG_PC] + offset;
2052
2053
2054 inst_env->slot_needed = 1;
2055 inst_env->prefix_found = 0;
2056 inst_env->xflag_found = 0;
2057 inst_env->disable_interrupt = 1;
2058 }
2059
2060 /* Handles the ABS instruction. */
2061
2062 void
2063 abs_op (unsigned short inst, inst_env_type *inst_env)
2064 {
2065
2066 long value;
2067
2068 /* ABS can't have a prefix, so it's bad if it does. */
2069 if (inst_env->prefix_found)
2070 {
2071 inst_env->invalid = 1;
2072 return;
2073 }
2074
2075 /* Check if the operation affects the PC. */
2076 if (cris_get_operand2 (inst) == REG_PC)
2077 {
2078
2079 /* It's invalid to change to the PC if we are in a delay slot. */
2080 if (inst_env->slot_needed)
2081 {
2082 inst_env->invalid = 1;
2083 return;
2084 }
2085
2086 value = (long) inst_env->reg[REG_PC];
2087
2088 /* The value of abs (SIGNED_DWORD_MASK) is SIGNED_DWORD_MASK. */
2089 if (value != SIGNED_DWORD_MASK)
2090 {
2091 value = -value;
2092 inst_env->reg[REG_PC] = (long) value;
2093 }
2094 }
2095
2096 inst_env->slot_needed = 0;
2097 inst_env->prefix_found = 0;
2098 inst_env->xflag_found = 0;
2099 inst_env->disable_interrupt = 0;
2100 }
2101
2102 /* Handles the ADDI instruction. */
2103
2104 void
2105 addi_op (unsigned short inst, inst_env_type *inst_env)
2106 {
2107 /* It's invalid to have the PC as base register. And ADDI can't have
2108 a prefix. */
2109 if (inst_env->prefix_found || (cris_get_operand1 (inst) == REG_PC))
2110 {
2111 inst_env->invalid = 1;
2112 return;
2113 }
2114
2115 inst_env->slot_needed = 0;
2116 inst_env->prefix_found = 0;
2117 inst_env->xflag_found = 0;
2118 inst_env->disable_interrupt = 0;
2119 }
2120
2121 /* Handles the ASR instruction. */
2122
2123 void
2124 asr_op (unsigned short inst, inst_env_type *inst_env)
2125 {
2126 int shift_steps;
2127 unsigned long value;
2128 unsigned long signed_extend_mask = 0;
2129
2130 /* ASR can't have a prefix, so check that it doesn't. */
2131 if (inst_env->prefix_found)
2132 {
2133 inst_env->invalid = 1;
2134 return;
2135 }
2136
2137 /* Check if the PC is the target register. */
2138 if (cris_get_operand2 (inst) == REG_PC)
2139 {
2140 /* It's invalid to change the PC in a delay slot. */
2141 if (inst_env->slot_needed)
2142 {
2143 inst_env->invalid = 1;
2144 return;
2145 }
2146 /* Get the number of bits to shift. */
2147 shift_steps = cris_get_asr_shift_steps (inst_env->reg[cris_get_operand1 (inst)]);
2148 value = inst_env->reg[REG_PC];
2149
2150 /* Find out how many bits the operation should apply to. */
2151 if (cris_get_size (inst) == INST_BYTE_SIZE)
2152 {
2153 if (value & SIGNED_BYTE_MASK)
2154 {
2155 signed_extend_mask = 0xFF;
2156 signed_extend_mask = signed_extend_mask >> shift_steps;
2157 signed_extend_mask = ~signed_extend_mask;
2158 }
2159 value = value >> shift_steps;
2160 value |= signed_extend_mask;
2161 value &= 0xFF;
2162 inst_env->reg[REG_PC] &= 0xFFFFFF00;
2163 inst_env->reg[REG_PC] |= value;
2164 }
2165 else if (cris_get_size (inst) == INST_WORD_SIZE)
2166 {
2167 if (value & SIGNED_WORD_MASK)
2168 {
2169 signed_extend_mask = 0xFFFF;
2170 signed_extend_mask = signed_extend_mask >> shift_steps;
2171 signed_extend_mask = ~signed_extend_mask;
2172 }
2173 value = value >> shift_steps;
2174 value |= signed_extend_mask;
2175 value &= 0xFFFF;
2176 inst_env->reg[REG_PC] &= 0xFFFF0000;
2177 inst_env->reg[REG_PC] |= value;
2178 }
2179 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2180 {
2181 if (value & SIGNED_DWORD_MASK)
2182 {
2183 signed_extend_mask = 0xFFFFFFFF;
2184 signed_extend_mask = signed_extend_mask >> shift_steps;
2185 signed_extend_mask = ~signed_extend_mask;
2186 }
2187 value = value >> shift_steps;
2188 value |= signed_extend_mask;
2189 inst_env->reg[REG_PC] = value;
2190 }
2191 }
2192 inst_env->slot_needed = 0;
2193 inst_env->prefix_found = 0;
2194 inst_env->xflag_found = 0;
2195 inst_env->disable_interrupt = 0;
2196 }
2197
2198 /* Handles the ASRQ instruction. */
2199
2200 void
2201 asrq_op (unsigned short inst, inst_env_type *inst_env)
2202 {
2203
2204 int shift_steps;
2205 unsigned long value;
2206 unsigned long signed_extend_mask = 0;
2207
2208 /* ASRQ can't have a prefix, so check that it doesn't. */
2209 if (inst_env->prefix_found)
2210 {
2211 inst_env->invalid = 1;
2212 return;
2213 }
2214
2215 /* Check if the PC is the target register. */
2216 if (cris_get_operand2 (inst) == REG_PC)
2217 {
2218
2219 /* It's invalid to change the PC in a delay slot. */
2220 if (inst_env->slot_needed)
2221 {
2222 inst_env->invalid = 1;
2223 return;
2224 }
2225 /* The shift size is given as a 5 bit quick value, i.e. we don't
2226 want the the sign bit of the quick value. */
2227 shift_steps = cris_get_asr_shift_steps (inst);
2228 value = inst_env->reg[REG_PC];
2229 if (value & SIGNED_DWORD_MASK)
2230 {
2231 signed_extend_mask = 0xFFFFFFFF;
2232 signed_extend_mask = signed_extend_mask >> shift_steps;
2233 signed_extend_mask = ~signed_extend_mask;
2234 }
2235 value = value >> shift_steps;
2236 value |= signed_extend_mask;
2237 inst_env->reg[REG_PC] = value;
2238 }
2239 inst_env->slot_needed = 0;
2240 inst_env->prefix_found = 0;
2241 inst_env->xflag_found = 0;
2242 inst_env->disable_interrupt = 0;
2243 }
2244
2245 /* Handles the AX, EI and SETF instruction. */
2246
2247 void
2248 ax_ei_setf_op (unsigned short inst, inst_env_type *inst_env)
2249 {
2250 if (inst_env->prefix_found)
2251 {
2252 inst_env->invalid = 1;
2253 return;
2254 }
2255 /* Check if the instruction is setting the X flag. */
2256 if (cris_is_xflag_bit_on (inst))
2257 {
2258 inst_env->xflag_found = 1;
2259 }
2260 else
2261 {
2262 inst_env->xflag_found = 0;
2263 }
2264 inst_env->slot_needed = 0;
2265 inst_env->prefix_found = 0;
2266 inst_env->disable_interrupt = 1;
2267 }
2268
2269 /* Checks if the instruction is in assign mode. If so, it updates the assign
2270 register. Note that check_assign assumes that the caller has checked that
2271 there is a prefix to this instruction. The mode check depends on this. */
2272
2273 void
2274 check_assign (unsigned short inst, inst_env_type *inst_env)
2275 {
2276 /* Check if it's an assign addressing mode. */
2277 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2278 {
2279 /* Assign the prefix value to operand 1. */
2280 inst_env->reg[cris_get_operand1 (inst)] = inst_env->prefix_value;
2281 }
2282 }
2283
2284 /* Handles the 2-operand BOUND instruction. */
2285
2286 void
2287 two_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2288 {
2289 /* It's invalid to have the PC as the index operand. */
2290 if (cris_get_operand2 (inst) == REG_PC)
2291 {
2292 inst_env->invalid = 1;
2293 return;
2294 }
2295 /* Check if we have a prefix. */
2296 if (inst_env->prefix_found)
2297 {
2298 check_assign (inst, inst_env);
2299 }
2300 /* Check if this is an autoincrement mode. */
2301 else if (cris_get_mode (inst) == AUTOINC_MODE)
2302 {
2303 /* It's invalid to change the PC in a delay slot. */
2304 if (inst_env->slot_needed)
2305 {
2306 inst_env->invalid = 1;
2307 return;
2308 }
2309 process_autoincrement (cris_get_size (inst), inst, inst_env);
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 /* Handles the 3-operand BOUND instruction. */
2318
2319 void
2320 three_operand_bound_op (unsigned short inst, inst_env_type *inst_env)
2321 {
2322 /* It's an error if we haven't got a prefix. And it's also an error
2323 if the PC is the destination register. */
2324 if ((!inst_env->prefix_found) || (cris_get_operand1 (inst) == REG_PC))
2325 {
2326 inst_env->invalid = 1;
2327 return;
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 btst_nop_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 = 0;
2351 }
2352
2353 /* Clears the status flags in inst_env. */
2354
2355 void
2356 clearf_di_op (unsigned short inst, inst_env_type *inst_env)
2357 {
2358 /* It's an error if we have got a prefix. */
2359 if (inst_env->prefix_found)
2360 {
2361 inst_env->invalid = 1;
2362 return;
2363 }
2364
2365 inst_env->slot_needed = 0;
2366 inst_env->prefix_found = 0;
2367 inst_env->xflag_found = 0;
2368 inst_env->disable_interrupt = 1;
2369 }
2370
2371 /* Handles the CLEAR instruction if it's in register mode. */
2372
2373 void
2374 reg_mode_clear_op (unsigned short inst, inst_env_type *inst_env)
2375 {
2376 /* Check if the target is the PC. */
2377 if (cris_get_operand2 (inst) == REG_PC)
2378 {
2379 /* The instruction will clear the instruction's size bits. */
2380 int clear_size = cris_get_clear_size (inst);
2381 if (clear_size == INST_BYTE_SIZE)
2382 {
2383 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFFFF00;
2384 }
2385 if (clear_size == INST_WORD_SIZE)
2386 {
2387 inst_env->delay_slot_pc = inst_env->reg[REG_PC] & 0xFFFF0000;
2388 }
2389 if (clear_size == INST_DWORD_SIZE)
2390 {
2391 inst_env->delay_slot_pc = 0x0;
2392 }
2393 /* The jump will be delayed with one delay slot. So we need a delay
2394 slot. */
2395 inst_env->slot_needed = 1;
2396 inst_env->delay_slot_pc_active = 1;
2397 }
2398 else
2399 {
2400 /* The PC will not change => no delay slot. */
2401 inst_env->slot_needed = 0;
2402 }
2403 inst_env->prefix_found = 0;
2404 inst_env->xflag_found = 0;
2405 inst_env->disable_interrupt = 0;
2406 }
2407
2408 /* Handles the TEST instruction if it's in register mode. */
2409
2410 void
2411 reg_mode_test_op (unsigned short inst, inst_env_type *inst_env)
2412 {
2413 /* It's an error if we have got a prefix. */
2414 if (inst_env->prefix_found)
2415 {
2416 inst_env->invalid = 1;
2417 return;
2418 }
2419 inst_env->slot_needed = 0;
2420 inst_env->prefix_found = 0;
2421 inst_env->xflag_found = 0;
2422 inst_env->disable_interrupt = 0;
2423
2424 }
2425
2426 /* Handles the CLEAR and TEST instruction if the instruction isn't
2427 in register mode. */
2428
2429 void
2430 none_reg_mode_clear_test_op (unsigned short inst, inst_env_type *inst_env)
2431 {
2432 /* Check if we are in a prefix mode. */
2433 if (inst_env->prefix_found)
2434 {
2435 /* The only way the PC can change is if this instruction is in
2436 assign addressing mode. */
2437 check_assign (inst, inst_env);
2438 }
2439 /* Indirect mode can't change the PC so just check if the mode is
2440 autoincrement. */
2441 else if (cris_get_mode (inst) == AUTOINC_MODE)
2442 {
2443 process_autoincrement (cris_get_size (inst), inst, inst_env);
2444 }
2445 inst_env->slot_needed = 0;
2446 inst_env->prefix_found = 0;
2447 inst_env->xflag_found = 0;
2448 inst_env->disable_interrupt = 0;
2449 }
2450
2451 /* Checks that the PC isn't the destination register or the instructions has
2452 a prefix. */
2453
2454 void
2455 dstep_logshift_mstep_neg_not_op (unsigned short inst, inst_env_type *inst_env)
2456 {
2457 /* It's invalid to have the PC as the destination. The instruction can't
2458 have a prefix. */
2459 if ((cris_get_operand2 (inst) == REG_PC) || 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 = 0;
2469 }
2470
2471 /* Checks that the instruction doesn't have a prefix. */
2472
2473 void
2474 break_op (unsigned short inst, inst_env_type *inst_env)
2475 {
2476 /* The instruction can't have a prefix. */
2477 if (inst_env->prefix_found)
2478 {
2479 inst_env->invalid = 1;
2480 return;
2481 }
2482
2483 inst_env->slot_needed = 0;
2484 inst_env->prefix_found = 0;
2485 inst_env->xflag_found = 0;
2486 inst_env->disable_interrupt = 1;
2487 }
2488
2489 /* Checks that the PC isn't the destination register and that the instruction
2490 doesn't have a prefix. */
2491
2492 void
2493 scc_op (unsigned short inst, inst_env_type *inst_env)
2494 {
2495 /* It's invalid to have the PC as the destination. The instruction can't
2496 have a prefix. */
2497 if ((cris_get_operand2 (inst) == REG_PC) || inst_env->prefix_found)
2498 {
2499 inst_env->invalid = 1;
2500 return;
2501 }
2502
2503 inst_env->slot_needed = 0;
2504 inst_env->prefix_found = 0;
2505 inst_env->xflag_found = 0;
2506 inst_env->disable_interrupt = 1;
2507 }
2508
2509 /* Handles the register mode JUMP instruction. */
2510
2511 void
2512 reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2513 {
2514 /* It's invalid to do a JUMP in a delay slot. The mode is register, so
2515 you can't have a prefix. */
2516 if ((inst_env->slot_needed) || (inst_env->prefix_found))
2517 {
2518 inst_env->invalid = 1;
2519 return;
2520 }
2521
2522 /* Just change the PC. */
2523 inst_env->reg[REG_PC] = inst_env->reg[cris_get_operand1 (inst)];
2524 inst_env->slot_needed = 0;
2525 inst_env->prefix_found = 0;
2526 inst_env->xflag_found = 0;
2527 inst_env->disable_interrupt = 1;
2528 }
2529
2530 /* Handles the JUMP instruction for all modes except register. */
2531
2532 void none_reg_mode_jump_op (unsigned short inst, inst_env_type *inst_env)
2533 {
2534 unsigned long newpc;
2535 CORE_ADDR address;
2536
2537 /* It's invalid to do a JUMP in a delay slot. */
2538 if (inst_env->slot_needed)
2539 {
2540 inst_env->invalid = 1;
2541 }
2542 else
2543 {
2544 /* Check if we have a prefix. */
2545 if (inst_env->prefix_found)
2546 {
2547 check_assign (inst, inst_env);
2548
2549 /* Get the new value for the the PC. */
2550 newpc =
2551 read_memory_unsigned_integer ((CORE_ADDR) inst_env->prefix_value,
2552 4);
2553 }
2554 else
2555 {
2556 /* Get the new value for the PC. */
2557 address = (CORE_ADDR) inst_env->reg[cris_get_operand1 (inst)];
2558 newpc = read_memory_unsigned_integer (address, 4);
2559
2560 /* Check if we should increment a register. */
2561 if (cris_get_mode (inst) == AUTOINC_MODE)
2562 {
2563 inst_env->reg[cris_get_operand1 (inst)] += 4;
2564 }
2565 }
2566 inst_env->reg[REG_PC] = newpc;
2567 }
2568 inst_env->slot_needed = 0;
2569 inst_env->prefix_found = 0;
2570 inst_env->xflag_found = 0;
2571 inst_env->disable_interrupt = 1;
2572 }
2573
2574 /* Handles moves to special registers (aka P-register) for all modes. */
2575
2576 void
2577 move_to_preg_op (unsigned short inst, inst_env_type *inst_env)
2578 {
2579 if (inst_env->prefix_found)
2580 {
2581 /* The instruction has a prefix that means we are only interested if
2582 the instruction is in assign mode. */
2583 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2584 {
2585 /* The prefix handles the problem if we are in a delay slot. */
2586 if (cris_get_operand1 (inst) == REG_PC)
2587 {
2588 /* Just take care of the assign. */
2589 check_assign (inst, inst_env);
2590 }
2591 }
2592 }
2593 else if (cris_get_mode (inst) == AUTOINC_MODE)
2594 {
2595 /* The instruction doesn't have a prefix, the only case left that we
2596 are interested in is the autoincrement mode. */
2597 if (cris_get_operand1 (inst) == REG_PC)
2598 {
2599 /* If the PC is to be incremented it's invalid to be in a
2600 delay slot. */
2601 if (inst_env->slot_needed)
2602 {
2603 inst_env->invalid = 1;
2604 return;
2605 }
2606
2607 /* The increment depends on the size of the special register. */
2608 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2609 {
2610 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2611 }
2612 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2613 {
2614 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2615 }
2616 else
2617 {
2618 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2619 }
2620 }
2621 }
2622 inst_env->slot_needed = 0;
2623 inst_env->prefix_found = 0;
2624 inst_env->xflag_found = 0;
2625 inst_env->disable_interrupt = 1;
2626 }
2627
2628 /* Handles moves from special registers (aka P-register) for all modes
2629 except register. */
2630
2631 void
2632 none_reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2633 {
2634 if (inst_env->prefix_found)
2635 {
2636 /* The instruction has a prefix that means we are only interested if
2637 the instruction is in assign mode. */
2638 if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
2639 {
2640 /* The prefix handles the problem if we are in a delay slot. */
2641 if (cris_get_operand1 (inst) == REG_PC)
2642 {
2643 /* Just take care of the assign. */
2644 check_assign (inst, inst_env);
2645 }
2646 }
2647 }
2648 /* The instruction doesn't have a prefix, the only case left that we
2649 are interested in is the autoincrement mode. */
2650 else if (cris_get_mode (inst) == AUTOINC_MODE)
2651 {
2652 if (cris_get_operand1 (inst) == REG_PC)
2653 {
2654 /* If the PC is to be incremented it's invalid to be in a
2655 delay slot. */
2656 if (inst_env->slot_needed)
2657 {
2658 inst_env->invalid = 1;
2659 return;
2660 }
2661
2662 /* The increment depends on the size of the special register. */
2663 if (cris_register_size (cris_get_operand2 (inst)) == 1)
2664 {
2665 process_autoincrement (INST_BYTE_SIZE, inst, inst_env);
2666 }
2667 else if (cris_register_size (cris_get_operand2 (inst)) == 2)
2668 {
2669 process_autoincrement (INST_WORD_SIZE, inst, inst_env);
2670 }
2671 else
2672 {
2673 process_autoincrement (INST_DWORD_SIZE, inst, inst_env);
2674 }
2675 }
2676 }
2677 inst_env->slot_needed = 0;
2678 inst_env->prefix_found = 0;
2679 inst_env->xflag_found = 0;
2680 inst_env->disable_interrupt = 1;
2681 }
2682
2683 /* Handles moves from special registers (aka P-register) when the mode
2684 is register. */
2685
2686 void
2687 reg_mode_move_from_preg_op (unsigned short inst, inst_env_type *inst_env)
2688 {
2689 /* Register mode move from special register can't have a prefix. */
2690 if (inst_env->prefix_found)
2691 {
2692 inst_env->invalid = 1;
2693 return;
2694 }
2695
2696 if (cris_get_operand1 (inst) == REG_PC)
2697 {
2698 /* It's invalid to change the PC in a delay slot. */
2699 if (inst_env->slot_needed)
2700 {
2701 inst_env->invalid = 1;
2702 return;
2703 }
2704 /* The destination is the PC, the jump will have a delay slot. */
2705 inst_env->delay_slot_pc = inst_env->preg[cris_get_operand2 (inst)];
2706 inst_env->slot_needed = 1;
2707 inst_env->delay_slot_pc_active = 1;
2708 }
2709 else
2710 {
2711 /* If the destination isn't PC, there will be no jump. */
2712 inst_env->slot_needed = 0;
2713 }
2714 inst_env->prefix_found = 0;
2715 inst_env->xflag_found = 0;
2716 inst_env->disable_interrupt = 1;
2717 }
2718
2719 /* Handles the MOVEM from memory to general register instruction. */
2720
2721 void
2722 move_mem_to_reg_movem_op (unsigned short inst, inst_env_type *inst_env)
2723 {
2724 if (inst_env->prefix_found)
2725 {
2726 /* The prefix handles the problem if we are in a delay slot. Is the
2727 MOVEM instruction going to change the PC? */
2728 if (cris_get_operand2 (inst) >= REG_PC)
2729 {
2730 inst_env->reg[REG_PC] =
2731 read_memory_unsigned_integer (inst_env->prefix_value, 4);
2732 }
2733 /* The assign value is the value after the increment. Normally, the
2734 assign value is the value before the increment. */
2735 if ((cris_get_operand1 (inst) == REG_PC)
2736 && (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2737 {
2738 inst_env->reg[REG_PC] = inst_env->prefix_value;
2739 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2740 }
2741 }
2742 else
2743 {
2744 /* Is the MOVEM instruction going to change the PC? */
2745 if (cris_get_operand2 (inst) == REG_PC)
2746 {
2747 /* It's invalid to change the PC in a delay slot. */
2748 if (inst_env->slot_needed)
2749 {
2750 inst_env->invalid = 1;
2751 return;
2752 }
2753 inst_env->reg[REG_PC] =
2754 read_memory_unsigned_integer (inst_env->reg[cris_get_operand1 (inst)],
2755 4);
2756 }
2757 /* The increment is not depending on the size, instead it's depending
2758 on the number of registers loaded from memory. */
2759 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2760 {
2761 /* It's invalid to change the PC in a delay slot. */
2762 if (inst_env->slot_needed)
2763 {
2764 inst_env->invalid = 1;
2765 return;
2766 }
2767 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2768 }
2769 }
2770 inst_env->slot_needed = 0;
2771 inst_env->prefix_found = 0;
2772 inst_env->xflag_found = 0;
2773 inst_env->disable_interrupt = 0;
2774 }
2775
2776 /* Handles the MOVEM to memory from general register instruction. */
2777
2778 void
2779 move_reg_to_mem_movem_op (unsigned short inst, inst_env_type *inst_env)
2780 {
2781 if (inst_env->prefix_found)
2782 {
2783 /* The assign value is the value after the increment. Normally, the
2784 assign value is the value before the increment. */
2785 if ((cris_get_operand1 (inst) == REG_PC) &&
2786 (cris_get_mode (inst) == PREFIX_ASSIGN_MODE))
2787 {
2788 /* The prefix handles the problem if we are in a delay slot. */
2789 inst_env->reg[REG_PC] = inst_env->prefix_value;
2790 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2791 }
2792 }
2793 else
2794 {
2795 /* The increment is not depending on the size, instead it's depending
2796 on the number of registers loaded to memory. */
2797 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
2798 {
2799 /* It's invalid to change the PC in a delay slot. */
2800 if (inst_env->slot_needed)
2801 {
2802 inst_env->invalid = 1;
2803 return;
2804 }
2805 inst_env->reg[REG_PC] += 4 * (cris_get_operand2 (inst) + 1);
2806 }
2807 }
2808 inst_env->slot_needed = 0;
2809 inst_env->prefix_found = 0;
2810 inst_env->xflag_found = 0;
2811 inst_env->disable_interrupt = 0;
2812 }
2813
2814 /* Handles the pop instruction to a general register.
2815 POP is a assembler macro for MOVE.D [SP+], Rd. */
2816
2817 void
2818 reg_pop_op (unsigned short inst, inst_env_type *inst_env)
2819 {
2820 /* POP can't have a prefix. */
2821 if (inst_env->prefix_found)
2822 {
2823 inst_env->invalid = 1;
2824 return;
2825 }
2826 if (cris_get_operand2 (inst) == REG_PC)
2827 {
2828 /* It's invalid to change the PC in a delay slot. */
2829 if (inst_env->slot_needed)
2830 {
2831 inst_env->invalid = 1;
2832 return;
2833 }
2834 inst_env->reg[REG_PC] =
2835 read_memory_unsigned_integer (inst_env->reg[REG_SP], 4);
2836 }
2837 inst_env->slot_needed = 0;
2838 inst_env->prefix_found = 0;
2839 inst_env->xflag_found = 0;
2840 inst_env->disable_interrupt = 0;
2841 }
2842
2843 /* Handles moves from register to memory. */
2844
2845 void
2846 move_reg_to_mem_index_inc_op (unsigned short inst, inst_env_type *inst_env)
2847 {
2848 /* Check if we have a prefix. */
2849 if (inst_env->prefix_found)
2850 {
2851 /* The only thing that can change the PC is an assign. */
2852 check_assign (inst, inst_env);
2853 }
2854 else if ((cris_get_operand1 (inst) == REG_PC)
2855 && (cris_get_mode (inst) == AUTOINC_MODE))
2856 {
2857 /* It's invalid to change the PC in a delay slot. */
2858 if (inst_env->slot_needed)
2859 {
2860 inst_env->invalid = 1;
2861 return;
2862 }
2863 process_autoincrement (cris_get_size (inst), inst, inst_env);
2864 }
2865 inst_env->slot_needed = 0;
2866 inst_env->prefix_found = 0;
2867 inst_env->xflag_found = 0;
2868 inst_env->disable_interrupt = 0;
2869 }
2870
2871 /* Handles the intructions that's not yet implemented, by setting
2872 inst_env->invalid to true. */
2873
2874 void
2875 not_implemented_op (unsigned short inst, inst_env_type *inst_env)
2876 {
2877 inst_env->invalid = 1;
2878 }
2879
2880 /* Handles the XOR instruction. */
2881
2882 void
2883 xor_op (unsigned short inst, inst_env_type *inst_env)
2884 {
2885 /* XOR can't have a prefix. */
2886 if (inst_env->prefix_found)
2887 {
2888 inst_env->invalid = 1;
2889 return;
2890 }
2891
2892 /* Check if the PC is the target. */
2893 if (cris_get_operand2 (inst) == REG_PC)
2894 {
2895 /* It's invalid to change the PC in a delay slot. */
2896 if (inst_env->slot_needed)
2897 {
2898 inst_env->invalid = 1;
2899 return;
2900 }
2901 inst_env->reg[REG_PC] ^= inst_env->reg[cris_get_operand1 (inst)];
2902 }
2903 inst_env->slot_needed = 0;
2904 inst_env->prefix_found = 0;
2905 inst_env->xflag_found = 0;
2906 inst_env->disable_interrupt = 0;
2907 }
2908
2909 /* Handles the MULS instruction. */
2910
2911 void
2912 muls_op (unsigned short inst, inst_env_type *inst_env)
2913 {
2914 /* MULS/U can't have a prefix. */
2915 if (inst_env->prefix_found)
2916 {
2917 inst_env->invalid = 1;
2918 return;
2919 }
2920
2921 /* Consider it invalid if the PC is the target. */
2922 if (cris_get_operand2 (inst) == REG_PC)
2923 {
2924 inst_env->invalid = 1;
2925 return;
2926 }
2927 inst_env->slot_needed = 0;
2928 inst_env->prefix_found = 0;
2929 inst_env->xflag_found = 0;
2930 inst_env->disable_interrupt = 0;
2931 }
2932
2933 /* Handles the MULU instruction. */
2934
2935 void
2936 mulu_op (unsigned short inst, inst_env_type *inst_env)
2937 {
2938 /* MULS/U can't have a prefix. */
2939 if (inst_env->prefix_found)
2940 {
2941 inst_env->invalid = 1;
2942 return;
2943 }
2944
2945 /* Consider it invalid if the PC is the target. */
2946 if (cris_get_operand2 (inst) == REG_PC)
2947 {
2948 inst_env->invalid = 1;
2949 return;
2950 }
2951 inst_env->slot_needed = 0;
2952 inst_env->prefix_found = 0;
2953 inst_env->xflag_found = 0;
2954 inst_env->disable_interrupt = 0;
2955 }
2956
2957 /* Calculate the result of the instruction for ADD, SUB, CMP AND, OR and MOVE.
2958 The MOVE instruction is the move from source to register. */
2959
2960 void
2961 add_sub_cmp_and_or_move_action (unsigned short inst, inst_env_type *inst_env,
2962 unsigned long source1, unsigned long source2)
2963 {
2964 unsigned long pc_mask;
2965 unsigned long operation_mask;
2966
2967 /* Find out how many bits the operation should apply to. */
2968 if (cris_get_size (inst) == INST_BYTE_SIZE)
2969 {
2970 pc_mask = 0xFFFFFF00;
2971 operation_mask = 0xFF;
2972 }
2973 else if (cris_get_size (inst) == INST_WORD_SIZE)
2974 {
2975 pc_mask = 0xFFFF0000;
2976 operation_mask = 0xFFFF;
2977 }
2978 else if (cris_get_size (inst) == INST_DWORD_SIZE)
2979 {
2980 pc_mask = 0x0;
2981 operation_mask = 0xFFFFFFFF;
2982 }
2983 else
2984 {
2985 /* The size is out of range. */
2986 inst_env->invalid = 1;
2987 return;
2988 }
2989
2990 /* The instruction just works on uw_operation_mask bits. */
2991 source2 &= operation_mask;
2992 source1 &= operation_mask;
2993
2994 /* Now calculate the result. The opcode's 3 first bits separates
2995 the different actions. */
2996 switch (cris_get_opcode (inst) & 7)
2997 {
2998 case 0: /* add */
2999 source1 += source2;
3000 break;
3001
3002 case 1: /* move */
3003 source1 = source2;
3004 break;
3005
3006 case 2: /* subtract */
3007 source1 -= source2;
3008 break;
3009
3010 case 3: /* compare */
3011 break;
3012
3013 case 4: /* and */
3014 source1 &= source2;
3015 break;
3016
3017 case 5: /* or */
3018 source1 |= source2;
3019 break;
3020
3021 default:
3022 inst_env->invalid = 1;
3023 return;
3024
3025 break;
3026 }
3027
3028 /* Make sure that the result doesn't contain more than the instruction
3029 size bits. */
3030 source2 &= operation_mask;
3031
3032 /* Calculate the new breakpoint address. */
3033 inst_env->reg[REG_PC] &= pc_mask;
3034 inst_env->reg[REG_PC] |= source1;
3035
3036 }
3037
3038 /* Extends the value from either byte or word size to a dword. If the mode
3039 is zero extend then the value is extended with zero. If instead the mode
3040 is signed extend the sign bit of the value is taken into consideration. */
3041
3042 unsigned long
3043 do_sign_or_zero_extend (unsigned long value, unsigned short *inst)
3044 {
3045 /* The size can be either byte or word, check which one it is.
3046 Don't check the highest bit, it's indicating if it's a zero
3047 or sign extend. */
3048 if (cris_get_size (*inst) & INST_WORD_SIZE)
3049 {
3050 /* Word size. */
3051 value &= 0xFFFF;
3052
3053 /* Check if the instruction is signed extend. If so, check if value has
3054 the sign bit on. */
3055 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_WORD_MASK))
3056 {
3057 value |= SIGNED_WORD_EXTEND_MASK;
3058 }
3059 }
3060 else
3061 {
3062 /* Byte size. */
3063 value &= 0xFF;
3064
3065 /* Check if the instruction is signed extend. If so, check if value has
3066 the sign bit on. */
3067 if (cris_is_signed_extend_bit_on (*inst) && (value & SIGNED_BYTE_MASK))
3068 {
3069 value |= SIGNED_BYTE_EXTEND_MASK;
3070 }
3071 }
3072 /* The size should now be dword. */
3073 cris_set_size_to_dword (inst);
3074 return value;
3075 }
3076
3077 /* Handles the register mode for the ADD, SUB, CMP, AND, OR and MOVE
3078 instruction. The MOVE instruction is the move from source to register. */
3079
3080 void
3081 reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3082 inst_env_type *inst_env)
3083 {
3084 unsigned long operand1;
3085 unsigned long operand2;
3086
3087 /* It's invalid to have a prefix to the instruction. This is a register
3088 mode instruction and can't have a prefix. */
3089 if (inst_env->prefix_found)
3090 {
3091 inst_env->invalid = 1;
3092 return;
3093 }
3094 /* Check if the instruction has PC as its target. */
3095 if (cris_get_operand2 (inst) == REG_PC)
3096 {
3097 if (inst_env->slot_needed)
3098 {
3099 inst_env->invalid = 1;
3100 return;
3101 }
3102 /* The instruction has the PC as its target register. */
3103 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3104 operand2 = inst_env->reg[REG_PC];
3105
3106 /* Check if it's a extend, signed or zero instruction. */
3107 if (cris_get_opcode (inst) < 4)
3108 {
3109 operand1 = do_sign_or_zero_extend (operand1, &inst);
3110 }
3111 /* Calculate the PC value after the instruction, i.e. where the
3112 breakpoint should be. The order of the udw_operands is vital. */
3113 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3114 }
3115 inst_env->slot_needed = 0;
3116 inst_env->prefix_found = 0;
3117 inst_env->xflag_found = 0;
3118 inst_env->disable_interrupt = 0;
3119 }
3120
3121 /* Returns the data contained at address. The size of the data is derived from
3122 the size of the operation. If the instruction is a zero or signed
3123 extend instruction, the size field is changed in instruction. */
3124
3125 unsigned long
3126 get_data_from_address (unsigned short *inst, CORE_ADDR address)
3127 {
3128 int size = cris_get_size (*inst);
3129 unsigned long value;
3130
3131 /* If it's an extend instruction we don't want the signed extend bit,
3132 because it influences the size. */
3133 if (cris_get_opcode (*inst) < 4)
3134 {
3135 size &= ~SIGNED_EXTEND_BIT_MASK;
3136 }
3137 /* Is there a need for checking the size? Size should contain the number of
3138 bytes to read. */
3139 size = 1 << size;
3140 value = read_memory_unsigned_integer (address, size);
3141
3142 /* Check if it's an extend, signed or zero instruction. */
3143 if (cris_get_opcode (*inst) < 4)
3144 {
3145 value = do_sign_or_zero_extend (value, inst);
3146 }
3147 return value;
3148 }
3149
3150 /* Handles the assign addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3151 instructions. The MOVE instruction is the move from source to register. */
3152
3153 void
3154 handle_prefix_assign_mode_for_aritm_op (unsigned short inst,
3155 inst_env_type *inst_env)
3156 {
3157 unsigned long operand2;
3158 unsigned long operand3;
3159
3160 check_assign (inst, inst_env);
3161 if (cris_get_operand2 (inst) == REG_PC)
3162 {
3163 operand2 = inst_env->reg[REG_PC];
3164
3165 /* Get the value of the third operand. */
3166 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3167
3168 /* Calculate the PC value after the instruction, i.e. where the
3169 breakpoint should be. The order of the udw_operands is vital. */
3170 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3171 }
3172 inst_env->slot_needed = 0;
3173 inst_env->prefix_found = 0;
3174 inst_env->xflag_found = 0;
3175 inst_env->disable_interrupt = 0;
3176 }
3177
3178 /* Handles the three-operand addressing mode for the ADD, SUB, CMP, AND and
3179 OR instructions. Note that for this to work as expected, the calling
3180 function must have made sure that there is a prefix to this instruction. */
3181
3182 void
3183 three_operand_add_sub_cmp_and_or_op (unsigned short inst,
3184 inst_env_type *inst_env)
3185 {
3186 unsigned long operand2;
3187 unsigned long operand3;
3188
3189 if (cris_get_operand1 (inst) == REG_PC)
3190 {
3191 /* The PC will be changed by the instruction. */
3192 operand2 = inst_env->reg[cris_get_operand2 (inst)];
3193
3194 /* Get the value of the third operand. */
3195 operand3 = get_data_from_address (&inst, inst_env->prefix_value);
3196
3197 /* Calculate the PC value after the instruction, i.e. where the
3198 breakpoint should be. */
3199 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3200 }
3201 inst_env->slot_needed = 0;
3202 inst_env->prefix_found = 0;
3203 inst_env->xflag_found = 0;
3204 inst_env->disable_interrupt = 0;
3205 }
3206
3207 /* Handles the index addresing mode for the ADD, SUB, CMP, AND, OR and MOVE
3208 instructions. The MOVE instruction is the move from source to register. */
3209
3210 void
3211 handle_prefix_index_mode_for_aritm_op (unsigned short inst,
3212 inst_env_type *inst_env)
3213 {
3214 if (cris_get_operand1 (inst) != cris_get_operand2 (inst))
3215 {
3216 /* If the instruction is MOVE it's invalid. If the instruction is ADD,
3217 SUB, AND or OR something weird is going on (if everything works these
3218 instructions should end up in the three operand version). */
3219 inst_env->invalid = 1;
3220 return;
3221 }
3222 else
3223 {
3224 /* three_operand_add_sub_cmp_and_or does the same as we should do here
3225 so use it. */
3226 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3227 }
3228 inst_env->slot_needed = 0;
3229 inst_env->prefix_found = 0;
3230 inst_env->xflag_found = 0;
3231 inst_env->disable_interrupt = 0;
3232 }
3233
3234 /* Handles the autoincrement and indirect addresing mode for the ADD, SUB,
3235 CMP, AND OR and MOVE instruction. The MOVE instruction is the move from
3236 source to register. */
3237
3238 void
3239 handle_inc_and_index_mode_for_aritm_op (unsigned short inst,
3240 inst_env_type *inst_env)
3241 {
3242 unsigned long operand1;
3243 unsigned long operand2;
3244 unsigned long operand3;
3245 int size;
3246
3247 /* The instruction is either an indirect or autoincrement addressing mode.
3248 Check if the destination register is the PC. */
3249 if (cris_get_operand2 (inst) == REG_PC)
3250 {
3251 /* Must be done here, get_data_from_address may change the size
3252 field. */
3253 size = cris_get_size (inst);
3254 operand2 = inst_env->reg[REG_PC];
3255
3256 /* Get the value of the third operand, i.e. the indirect operand. */
3257 operand1 = inst_env->reg[cris_get_operand1 (inst)];
3258 operand3 = get_data_from_address (&inst, operand1);
3259
3260 /* Calculate the PC value after the instruction, i.e. where the
3261 breakpoint should be. The order of the udw_operands is vital. */
3262 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand3);
3263 }
3264 /* If this is an autoincrement addressing mode, check if the increment
3265 changes the PC. */
3266 if ((cris_get_operand1 (inst) == REG_PC) && (cris_get_mode (inst) == AUTOINC_MODE))
3267 {
3268 /* Get the size field. */
3269 size = cris_get_size (inst);
3270
3271 /* If it's an extend instruction we don't want the signed extend bit,
3272 because it influences the size. */
3273 if (cris_get_opcode (inst) < 4)
3274 {
3275 size &= ~SIGNED_EXTEND_BIT_MASK;
3276 }
3277 process_autoincrement (size, inst, inst_env);
3278 }
3279 inst_env->slot_needed = 0;
3280 inst_env->prefix_found = 0;
3281 inst_env->xflag_found = 0;
3282 inst_env->disable_interrupt = 0;
3283 }
3284
3285 /* Handles the two-operand addressing mode, all modes except register, for
3286 the ADD, SUB CMP, AND and OR instruction. */
3287
3288 void
3289 none_reg_mode_add_sub_cmp_and_or_move_op (unsigned short inst,
3290 inst_env_type *inst_env)
3291 {
3292 if (inst_env->prefix_found)
3293 {
3294 if (cris_get_mode (inst) == PREFIX_INDEX_MODE)
3295 {
3296 handle_prefix_index_mode_for_aritm_op (inst, inst_env);
3297 }
3298 else if (cris_get_mode (inst) == PREFIX_ASSIGN_MODE)
3299 {
3300 handle_prefix_assign_mode_for_aritm_op (inst, inst_env);
3301 }
3302 else
3303 {
3304 /* The mode is invalid for a prefixed base instruction. */
3305 inst_env->invalid = 1;
3306 return;
3307 }
3308 }
3309 else
3310 {
3311 handle_inc_and_index_mode_for_aritm_op (inst, inst_env);
3312 }
3313 }
3314
3315 /* Handles the quick addressing mode for the ADD and SUB instruction. */
3316
3317 void
3318 quick_mode_add_sub_op (unsigned short inst, inst_env_type *inst_env)
3319 {
3320 unsigned long operand1;
3321 unsigned long operand2;
3322
3323 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3324 instruction and can't have a prefix. */
3325 if (inst_env->prefix_found)
3326 {
3327 inst_env->invalid = 1;
3328 return;
3329 }
3330
3331 /* Check if the instruction has PC as its target. */
3332 if (cris_get_operand2 (inst) == REG_PC)
3333 {
3334 if (inst_env->slot_needed)
3335 {
3336 inst_env->invalid = 1;
3337 return;
3338 }
3339 operand1 = cris_get_quick_value (inst);
3340 operand2 = inst_env->reg[REG_PC];
3341
3342 /* The size should now be dword. */
3343 cris_set_size_to_dword (&inst);
3344
3345 /* Calculate the PC value after the instruction, i.e. where the
3346 breakpoint should be. */
3347 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3348 }
3349 inst_env->slot_needed = 0;
3350 inst_env->prefix_found = 0;
3351 inst_env->xflag_found = 0;
3352 inst_env->disable_interrupt = 0;
3353 }
3354
3355 /* Handles the quick addressing mode for the CMP, AND and OR instruction. */
3356
3357 void
3358 quick_mode_and_cmp_move_or_op (unsigned short inst, inst_env_type *inst_env)
3359 {
3360 unsigned long operand1;
3361 unsigned long operand2;
3362
3363 /* It's a bad idea to be in a prefix instruction now. This is a quick mode
3364 instruction and can't have a prefix. */
3365 if (inst_env->prefix_found)
3366 {
3367 inst_env->invalid = 1;
3368 return;
3369 }
3370 /* Check if the instruction has PC as its target. */
3371 if (cris_get_operand2 (inst) == REG_PC)
3372 {
3373 if (inst_env->slot_needed)
3374 {
3375 inst_env->invalid = 1;
3376 return;
3377 }
3378 /* The instruction has the PC as its target register. */
3379 operand1 = cris_get_quick_value (inst);
3380 operand2 = inst_env->reg[REG_PC];
3381
3382 /* The quick value is signed, so check if we must do a signed extend. */
3383 if (operand1 & SIGNED_QUICK_VALUE_MASK)
3384 {
3385 /* sign extend */
3386 operand1 |= SIGNED_QUICK_VALUE_EXTEND_MASK;
3387 }
3388 /* The size should now be dword. */
3389 cris_set_size_to_dword (&inst);
3390
3391 /* Calculate the PC value after the instruction, i.e. where the
3392 breakpoint should be. */
3393 add_sub_cmp_and_or_move_action (inst, inst_env, operand2, operand1);
3394 }
3395 inst_env->slot_needed = 0;
3396 inst_env->prefix_found = 0;
3397 inst_env->xflag_found = 0;
3398 inst_env->disable_interrupt = 0;
3399 }
3400
3401 /* Translate op_type to a function and call it. */
3402
3403 static void cris_gdb_func (enum cris_op_type op_type, unsigned short inst,
3404 inst_env_type *inst_env)
3405 {
3406 switch (op_type)
3407 {
3408 case cris_not_implemented_op:
3409 not_implemented_op (inst, inst_env);
3410 break;
3411
3412 case cris_abs_op:
3413 abs_op (inst, inst_env);
3414 break;
3415
3416 case cris_addi_op:
3417 addi_op (inst, inst_env);
3418 break;
3419
3420 case cris_asr_op:
3421 asr_op (inst, inst_env);
3422 break;
3423
3424 case cris_asrq_op:
3425 asrq_op (inst, inst_env);
3426 break;
3427
3428 case cris_ax_ei_setf_op:
3429 ax_ei_setf_op (inst, inst_env);
3430 break;
3431
3432 case cris_bdap_prefix:
3433 bdap_prefix (inst, inst_env);
3434 break;
3435
3436 case cris_biap_prefix:
3437 biap_prefix (inst, inst_env);
3438 break;
3439
3440 case cris_break_op:
3441 break_op (inst, inst_env);
3442 break;
3443
3444 case cris_btst_nop_op:
3445 btst_nop_op (inst, inst_env);
3446 break;
3447
3448 case cris_clearf_di_op:
3449 clearf_di_op (inst, inst_env);
3450 break;
3451
3452 case cris_dip_prefix:
3453 dip_prefix (inst, inst_env);
3454 break;
3455
3456 case cris_dstep_logshift_mstep_neg_not_op:
3457 dstep_logshift_mstep_neg_not_op (inst, inst_env);
3458 break;
3459
3460 case cris_eight_bit_offset_branch_op:
3461 eight_bit_offset_branch_op (inst, inst_env);
3462 break;
3463
3464 case cris_move_mem_to_reg_movem_op:
3465 move_mem_to_reg_movem_op (inst, inst_env);
3466 break;
3467
3468 case cris_move_reg_to_mem_movem_op:
3469 move_reg_to_mem_movem_op (inst, inst_env);
3470 break;
3471
3472 case cris_move_to_preg_op:
3473 move_to_preg_op (inst, inst_env);
3474 break;
3475
3476 case cris_muls_op:
3477 muls_op (inst, inst_env);
3478 break;
3479
3480 case cris_mulu_op:
3481 mulu_op (inst, inst_env);
3482 break;
3483
3484 case cris_none_reg_mode_add_sub_cmp_and_or_move_op:
3485 none_reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3486 break;
3487
3488 case cris_none_reg_mode_clear_test_op:
3489 none_reg_mode_clear_test_op (inst, inst_env);
3490 break;
3491
3492 case cris_none_reg_mode_jump_op:
3493 none_reg_mode_jump_op (inst, inst_env);
3494 break;
3495
3496 case cris_none_reg_mode_move_from_preg_op:
3497 none_reg_mode_move_from_preg_op (inst, inst_env);
3498 break;
3499
3500 case cris_quick_mode_add_sub_op:
3501 quick_mode_add_sub_op (inst, inst_env);
3502 break;
3503
3504 case cris_quick_mode_and_cmp_move_or_op:
3505 quick_mode_and_cmp_move_or_op (inst, inst_env);
3506 break;
3507
3508 case cris_quick_mode_bdap_prefix:
3509 quick_mode_bdap_prefix (inst, inst_env);
3510 break;
3511
3512 case cris_reg_mode_add_sub_cmp_and_or_move_op:
3513 reg_mode_add_sub_cmp_and_or_move_op (inst, inst_env);
3514 break;
3515
3516 case cris_reg_mode_clear_op:
3517 reg_mode_clear_op (inst, inst_env);
3518 break;
3519
3520 case cris_reg_mode_jump_op:
3521 reg_mode_jump_op (inst, inst_env);
3522 break;
3523
3524 case cris_reg_mode_move_from_preg_op:
3525 reg_mode_move_from_preg_op (inst, inst_env);
3526 break;
3527
3528 case cris_reg_mode_test_op:
3529 reg_mode_test_op (inst, inst_env);
3530 break;
3531
3532 case cris_scc_op:
3533 scc_op (inst, inst_env);
3534 break;
3535
3536 case cris_sixteen_bit_offset_branch_op:
3537 sixteen_bit_offset_branch_op (inst, inst_env);
3538 break;
3539
3540 case cris_three_operand_add_sub_cmp_and_or_op:
3541 three_operand_add_sub_cmp_and_or_op (inst, inst_env);
3542 break;
3543
3544 case cris_three_operand_bound_op:
3545 three_operand_bound_op (inst, inst_env);
3546 break;
3547
3548 case cris_two_operand_bound_op:
3549 two_operand_bound_op (inst, inst_env);
3550 break;
3551
3552 case cris_xor_op:
3553 xor_op (inst, inst_env);
3554 break;
3555 }
3556 }
3557
3558 /* This wrapper is to avoid cris_get_assembler being called before
3559 exec_bfd has been set. */
3560
3561 static int
3562 cris_delayed_get_disassembler (bfd_vma addr, disassemble_info *info)
3563 {
3564 tm_print_insn = cris_get_disassembler (exec_bfd);
3565 return TARGET_PRINT_INSN (addr, info);
3566 }
3567
3568 /* Copied from <asm/elf.h>. */
3569 typedef unsigned long elf_greg_t;
3570
3571 /* Same as user_regs_struct struct in <asm/user.h>. */
3572 typedef elf_greg_t elf_gregset_t[35];
3573
3574 /* Unpack an elf_gregset_t into GDB's register cache. */
3575
3576 void
3577 supply_gregset (elf_gregset_t *gregsetp)
3578 {
3579 int i;
3580 elf_greg_t *regp = *gregsetp;
3581 static char zerobuf[4] = {0};
3582
3583 /* The kernel dumps all 32 registers as unsigned longs, but supply_register
3584 knows about the actual size of each register so that's no problem. */
3585 for (i = 0; i < NUM_GENREGS + NUM_SPECREGS; i++)
3586 {
3587 supply_register (i, (char *)&regp[i]);
3588 }
3589 }
3590
3591 /* Use a local version of this function to get the correct types for
3592 regsets, until multi-arch core support is ready. */
3593
3594 static void
3595 fetch_core_registers (char *core_reg_sect, unsigned core_reg_size,
3596 int which, CORE_ADDR reg_addr)
3597 {
3598 elf_gregset_t gregset;
3599
3600 switch (which)
3601 {
3602 case 0:
3603 if (core_reg_size != sizeof (gregset))
3604 {
3605 warning ("wrong size gregset struct in core file");
3606 }
3607 else
3608 {
3609 memcpy (&gregset, core_reg_sect, sizeof (gregset));
3610 supply_gregset (&gregset);
3611 }
3612
3613 default:
3614 /* We've covered all the kinds of registers we know about here,
3615 so this must be something we wouldn't know what to do with
3616 anyway. Just ignore it. */
3617 break;
3618 }
3619 }
3620
3621 static struct core_fns cris_elf_core_fns =
3622 {
3623 bfd_target_elf_flavour, /* core_flavour */
3624 default_check_format, /* check_format */
3625 default_core_sniffer, /* core_sniffer */
3626 fetch_core_registers, /* core_read_registers */
3627 NULL /* next */
3628 };
3629
3630 /* Fetch (and possibly build) an appropriate link_map_offsets
3631 structure for native GNU/Linux CRIS targets using the struct
3632 offsets defined in link.h (but without actual reference to that
3633 file).
3634
3635 This makes it possible to access GNU/Linux CRIS shared libraries
3636 from a GDB that was not built on an GNU/Linux CRIS host (for cross
3637 debugging).
3638
3639 See gdb/solib-svr4.h for an explanation of these fields. */
3640
3641 struct link_map_offsets *
3642 cris_linux_svr4_fetch_link_map_offsets (void)
3643 {
3644 static struct link_map_offsets lmo;
3645 static struct link_map_offsets *lmp = NULL;
3646
3647 if (lmp == NULL)
3648 {
3649 lmp = &lmo;
3650
3651 lmo.r_debug_size = 8; /* The actual size is 20 bytes, but
3652 this is all we need. */
3653 lmo.r_map_offset = 4;
3654 lmo.r_map_size = 4;
3655
3656 lmo.link_map_size = 20;
3657
3658 lmo.l_addr_offset = 0;
3659 lmo.l_addr_size = 4;
3660
3661 lmo.l_name_offset = 4;
3662 lmo.l_name_size = 4;
3663
3664 lmo.l_next_offset = 12;
3665 lmo.l_next_size = 4;
3666
3667 lmo.l_prev_offset = 16;
3668 lmo.l_prev_size = 4;
3669 }
3670
3671 return lmp;
3672 }
3673
3674 static void
3675 cris_fpless_backtrace (char *noargs, int from_tty)
3676 {
3677 /* Points at the instruction after the jsr (except when in innermost frame
3678 where it points at the original pc). */
3679 CORE_ADDR pc = 0;
3680
3681 /* Temporary variable, used for parsing from the start of the function that
3682 the pc is in, up to the pc. */
3683 CORE_ADDR tmp_pc = 0;
3684 CORE_ADDR sp = 0;
3685
3686 /* Information about current frame. */
3687 struct symtab_and_line sal;
3688 char* func_name;
3689
3690 /* Present instruction. */
3691 unsigned short insn;
3692
3693 /* Next instruction, lookahead. */
3694 unsigned short insn_next;
3695
3696 /* This is to store the offset between sp at start of function and until we
3697 reach push srp (if any). */
3698 int sp_add_later = 0;
3699 int push_srp_found = 0;
3700
3701 int val = 0;
3702
3703 /* Frame counter. */
3704 int frame = 0;
3705
3706 /* For the innermost frame, we want to look at srp in case it's a leaf
3707 function (since there's no push srp in that case). */
3708 int innermost_frame = 1;
3709
3710 deprecated_read_register_gen (PC_REGNUM, (char *) &pc);
3711 deprecated_read_register_gen (SP_REGNUM, (char *) &sp);
3712
3713 /* We make an explicit return when we can't find an outer frame. */
3714 while (1)
3715 {
3716 /* Get file name and line number. */
3717 sal = find_pc_line (pc, 0);
3718
3719 /* Get function name. */
3720 find_pc_partial_function (pc, &func_name, (CORE_ADDR *) NULL,
3721 (CORE_ADDR *) NULL);
3722
3723 /* Print information about current frame. */
3724 printf_unfiltered ("#%i 0x%08lx in %s", frame++, pc, func_name);
3725 if (sal.symtab)
3726 {
3727 printf_unfiltered (" at %s:%i", sal.symtab->filename, sal.line);
3728 }
3729 printf_unfiltered ("\n");
3730
3731 /* Get the start address of this function. */
3732 tmp_pc = get_pc_function_start (pc);
3733
3734 /* Mini parser, only meant to find push sp and sub ...,sp from the start
3735 of the function, up to the pc. */
3736 while (tmp_pc < pc)
3737 {
3738 insn = read_memory_unsigned_integer (tmp_pc, sizeof (short));
3739 tmp_pc += sizeof (short);
3740 if (insn == 0xE1FC)
3741 {
3742 /* push <reg> 32 bit instruction */
3743 insn_next = read_memory_unsigned_integer (tmp_pc,
3744 sizeof (short));
3745 tmp_pc += sizeof (short);
3746
3747 /* Recognize srp. */
3748 if (insn_next == 0xBE7E)
3749 {
3750 /* For subsequent (not this one though) push or sub which
3751 affects sp, adjust sp immediately. */
3752 push_srp_found = 1;
3753
3754 /* Note: this will break if we ever encounter a
3755 push vr (1 byte) or push ccr (2 bytes). */
3756 sp_add_later += 4;
3757 }
3758 else
3759 {
3760 /* Some other register was pushed. */
3761 if (push_srp_found)
3762 {
3763 sp += 4;
3764 }
3765 else
3766 {
3767 sp_add_later += 4;
3768 }
3769 }
3770 }
3771 else if (cris_get_operand2 (insn) == SP_REGNUM
3772 && cris_get_mode (insn) == 0x0000
3773 && cris_get_opcode (insn) == 0x000A)
3774 {
3775 /* subq <val>,sp */
3776 val = cris_get_quick_value (insn);
3777
3778 if (push_srp_found)
3779 {
3780 sp += val;
3781 }
3782 else
3783 {
3784 sp_add_later += val;
3785 }
3786
3787 }
3788 else if (cris_get_operand2 (insn) == SP_REGNUM
3789 /* Autoincrement addressing mode. */
3790 && cris_get_mode (insn) == 0x0003
3791 /* Opcode. */
3792 && ((insn) & 0x03E0) >> 5 == 0x0004)
3793 {
3794 /* subu <val>,sp */
3795 val = get_data_from_address (&insn, tmp_pc);
3796
3797 if (push_srp_found)
3798 {
3799 sp += val;
3800 }
3801 else
3802 {
3803 sp_add_later += val;
3804 }
3805 }
3806 else if (cris_get_operand2 (insn) == SP_REGNUM
3807 && ((insn & 0x0F00) >> 8) == 0x0001
3808 && (cris_get_signed_offset (insn) < 0))
3809 {
3810 /* Immediate byte offset addressing prefix word with sp as base
3811 register. Used for CRIS v8 i.e. ETRAX 100 and newer if <val>
3812 is between 64 and 128.
3813 movem r<regsave>,[sp=sp-<val>] */
3814 val = -cris_get_signed_offset (insn);
3815 insn_next = read_memory_unsigned_integer (tmp_pc,
3816 sizeof (short));
3817 tmp_pc += sizeof (short);
3818
3819 if (cris_get_mode (insn_next) == PREFIX_ASSIGN_MODE
3820 && cris_get_opcode (insn_next) == 0x000F
3821 && cris_get_size (insn_next) == 0x0003
3822 && cris_get_operand1 (insn_next) == SP_REGNUM)
3823 {
3824 if (push_srp_found)
3825 {
3826 sp += val;
3827 }
3828 else
3829 {
3830 sp_add_later += val;
3831 }
3832 }
3833 }
3834 }
3835
3836 if (push_srp_found)
3837 {
3838 /* Reset flag. */
3839 push_srp_found = 0;
3840
3841 /* sp should now point at where srp is stored on the stack. Update
3842 the pc to the srp. */
3843 pc = read_memory_unsigned_integer (sp, 4);
3844 }
3845 else if (innermost_frame)
3846 {
3847 /* We couldn't find a push srp in the prologue, so this must be
3848 a leaf function, and thus we use the srp register directly.
3849 This should happen at most once, for the innermost function. */
3850 deprecated_read_register_gen (SRP_REGNUM, (char *) &pc);
3851 }
3852 else
3853 {
3854 /* Couldn't find an outer frame. */
3855 return;
3856 }
3857
3858 /* Reset flag. (In case the innermost frame wasn't a leaf, we don't
3859 want to look at the srp register later either). */
3860 innermost_frame = 0;
3861
3862 /* Now, add the offset for everything up to, and including push srp,
3863 that was held back during the prologue parsing. */
3864 sp += sp_add_later;
3865 sp_add_later = 0;
3866 }
3867 }
3868
3869 void
3870 _initialize_cris_tdep (void)
3871 {
3872 struct cmd_list_element *c;
3873
3874 gdbarch_register (bfd_arch_cris, cris_gdbarch_init, cris_dump_tdep);
3875
3876 /* Used in disassembly. */
3877 tm_print_insn = cris_delayed_get_disassembler;
3878
3879 /* CRIS-specific user-commands. */
3880 c = add_set_cmd ("cris-version", class_support, var_integer,
3881 (char *) &usr_cmd_cris_version,
3882 "Set the current CRIS version.", &setlist);
3883 set_cmd_sfunc (c, cris_version_update);
3884 add_show_from_set (c, &showlist);
3885
3886 c = add_set_enum_cmd ("cris-mode", class_support, cris_mode_enums,
3887 &usr_cmd_cris_mode,
3888 "Set the current CRIS mode.", &setlist);
3889 set_cmd_sfunc (c, cris_mode_update);
3890 add_show_from_set (c, &showlist);
3891
3892 c = add_set_enum_cmd ("cris-abi", class_support, cris_abi_enums,
3893 &usr_cmd_cris_abi,
3894 "Set the current CRIS ABI version.", &setlist);
3895 set_cmd_sfunc (c, cris_abi_update);
3896 add_show_from_set (c, &showlist);
3897
3898 c = add_cmd ("cris-fpless-backtrace", class_support, cris_fpless_backtrace,
3899 "Display call chain using the subroutine return pointer.\n"
3900 "Note that this displays the address after the jump to the "
3901 "subroutine.", &cmdlist);
3902
3903 add_core_fns (&cris_elf_core_fns);
3904
3905 }
3906
3907 /* Prints out all target specific values. */
3908
3909 static void
3910 cris_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
3911 {
3912 struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
3913 if (tdep != NULL)
3914 {
3915 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_version = %i\n",
3916 tdep->cris_version);
3917 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_mode = %s\n",
3918 tdep->cris_mode);
3919 fprintf_unfiltered (file, "cris_dump_tdep: tdep->cris_abi = %s\n",
3920 tdep->cris_abi);
3921
3922 }
3923 }
3924
3925 static void
3926 cris_version_update (char *ignore_args, int from_tty,
3927 struct cmd_list_element *c)
3928 {
3929 struct gdbarch_info info;
3930
3931 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3932 the set command passed as a parameter. The clone operation will
3933 include (BUG?) any ``set'' command callback, if present.
3934 Commands like ``info set'' call all the ``show'' command
3935 callbacks. Unfortunatly, for ``show'' commands cloned from
3936 ``set'', this includes callbacks belonging to ``set'' commands.
3937 Making this worse, this only occures if add_show_from_set() is
3938 called after add_cmd_sfunc() (BUG?). */
3939
3940 /* From here on, trust the user's CRIS version setting. */
3941 if (cmd_type (c) == set_cmd)
3942 {
3943 usr_cmd_cris_version_valid = 1;
3944
3945 /* Update the current architecture, if needed. */
3946 gdbarch_info_init (&info);
3947 if (!gdbarch_update_p (info))
3948 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3949 }
3950 }
3951
3952 static void
3953 cris_mode_update (char *ignore_args, int from_tty,
3954 struct cmd_list_element *c)
3955 {
3956 struct gdbarch_info info;
3957
3958 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3959 the set command passed as a parameter. The clone operation will
3960 include (BUG?) any ``set'' command callback, if present.
3961 Commands like ``info set'' call all the ``show'' command
3962 callbacks. Unfortunatly, for ``show'' commands cloned from
3963 ``set'', this includes callbacks belonging to ``set'' commands.
3964 Making this worse, this only occures if add_show_from_set() is
3965 called after add_cmd_sfunc() (BUG?). */
3966
3967 /* From here on, trust the user's CRIS mode setting. */
3968 if (cmd_type (c) == set_cmd)
3969 {
3970 usr_cmd_cris_mode_valid = 1;
3971
3972 /* Update the current architecture, if needed. */
3973 gdbarch_info_init (&info);
3974 if (!gdbarch_update_p (info))
3975 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
3976 }
3977 }
3978
3979 static void
3980 cris_abi_update (char *ignore_args, int from_tty,
3981 struct cmd_list_element *c)
3982 {
3983 struct gdbarch_info info;
3984
3985 /* NOTE: cagney/2002-03-17: The add_show_from_set() function clones
3986 the set command passed as a parameter. The clone operation will
3987 include (BUG?) any ``set'' command callback, if present.
3988 Commands like ``info set'' call all the ``show'' command
3989 callbacks. Unfortunatly, for ``show'' commands cloned from
3990 ``set'', this includes callbacks belonging to ``set'' commands.
3991 Making this worse, this only occures if add_show_from_set() is
3992 called after add_cmd_sfunc() (BUG?). */
3993
3994 /* From here on, trust the user's CRIS ABI setting. */
3995 if (cmd_type (c) == set_cmd)
3996 {
3997 usr_cmd_cris_abi_valid = 1;
3998
3999 /* Update the current architecture, if needed. */
4000 gdbarch_info_init (&info);
4001 if (!gdbarch_update_p (info))
4002 internal_error (__FILE__, __LINE__, "cris_gdbarch_update: failed to update architecture.");
4003 }
4004 }
4005
4006 /* Copied from pa64solib.c, with a couple of minor changes. */
4007
4008 static CORE_ADDR
4009 bfd_lookup_symbol (bfd *abfd, const char *symname)
4010 {
4011 unsigned int storage_needed;
4012 asymbol *sym;
4013 asymbol **symbol_table;
4014 unsigned int number_of_symbols;
4015 unsigned int i;
4016 struct cleanup *back_to;
4017 CORE_ADDR symaddr = 0;
4018
4019 storage_needed = bfd_get_symtab_upper_bound (abfd);
4020
4021 if (storage_needed > 0)
4022 {
4023 symbol_table = (asymbol **) xmalloc (storage_needed);
4024 back_to = make_cleanup (free, (PTR) symbol_table);
4025 number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
4026
4027 for (i = 0; i < number_of_symbols; i++)
4028 {
4029 sym = *symbol_table++;
4030 if (!strcmp (sym->name, symname))
4031 {
4032 /* Bfd symbols are section relative. */
4033 symaddr = sym->value + sym->section->vma;
4034 break;
4035 }
4036 }
4037 do_cleanups (back_to);
4038 }
4039 return (symaddr);
4040 }
4041
4042 static struct gdbarch *
4043 cris_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
4044 {
4045 struct gdbarch *gdbarch;
4046 struct gdbarch_tdep *tdep;
4047 int cris_version;
4048 const char *cris_mode;
4049 const char *cris_abi;
4050 CORE_ADDR cris_abi_sym = 0;
4051 int register_bytes;
4052
4053 if (usr_cmd_cris_version_valid)
4054 {
4055 /* Trust the user's CRIS version setting. */
4056 cris_version = usr_cmd_cris_version;
4057 }
4058 else
4059 {
4060 /* Assume it's CRIS version 10. */
4061 cris_version = 10;
4062 }
4063
4064 if (usr_cmd_cris_mode_valid)
4065 {
4066 /* Trust the user's CRIS mode setting. */
4067 cris_mode = usr_cmd_cris_mode;
4068 }
4069 else if (cris_version == 10)
4070 {
4071 /* Assume CRIS version 10 is in user mode. */
4072 cris_mode = CRIS_MODE_USER;
4073 }
4074 else
4075 {
4076 /* Strictly speaking, older CRIS version don't have a supervisor mode,
4077 but we regard its only mode as supervisor mode. */
4078 cris_mode = CRIS_MODE_SUPERVISOR;
4079 }
4080
4081 if (usr_cmd_cris_abi_valid)
4082 {
4083 /* Trust the user's ABI setting. */
4084 cris_abi = usr_cmd_cris_abi;
4085 }
4086 else if (info.abfd)
4087 {
4088 if (bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
4089 {
4090 /* An elf target uses the new ABI. */
4091 cris_abi = CRIS_ABI_V2;
4092 }
4093 else if (bfd_get_flavour (info.abfd) == bfd_target_aout_flavour)
4094 {
4095 /* An a.out target may use either ABI. Look for hints in the
4096 symbol table. */
4097 cris_abi_sym = bfd_lookup_symbol (info.abfd, CRIS_ABI_SYMBOL);
4098 cris_abi = cris_abi_sym ? CRIS_ABI_V2 : CRIS_ABI_ORIGINAL;
4099 }
4100 else
4101 {
4102 /* Unknown bfd flavour. Assume it's the new ABI. */
4103 cris_abi = CRIS_ABI_V2;
4104 }
4105 }
4106 else if (arches != NULL)
4107 {
4108 /* No bfd available. Stick with the ABI from the most recently
4109 selected architecture of this same family (the head of arches
4110 always points to this). (This is to avoid changing the ABI
4111 when the user updates the architecture with the 'set
4112 cris-version' command.) */
4113 cris_abi = gdbarch_tdep (arches->gdbarch)->cris_abi;
4114 }
4115 else
4116 {
4117 /* No bfd, and no previously selected architecture available.
4118 Assume it's the new ABI. */
4119 cris_abi = CRIS_ABI_V2;
4120 }
4121
4122 /* Make the current settings visible to the user. */
4123 usr_cmd_cris_version = cris_version;
4124 usr_cmd_cris_mode = cris_mode;
4125 usr_cmd_cris_abi = cris_abi;
4126
4127 /* Find a candidate among the list of pre-declared architectures. Both
4128 CRIS version and ABI must match. */
4129 for (arches = gdbarch_list_lookup_by_info (arches, &info);
4130 arches != NULL;
4131 arches = gdbarch_list_lookup_by_info (arches->next, &info))
4132 {
4133 if ((gdbarch_tdep (arches->gdbarch)->cris_version == cris_version)
4134 && (gdbarch_tdep (arches->gdbarch)->cris_mode == cris_mode)
4135 && (gdbarch_tdep (arches->gdbarch)->cris_abi == cris_abi))
4136 return arches->gdbarch;
4137 }
4138
4139 /* No matching architecture was found. Create a new one. */
4140 tdep = (struct gdbarch_tdep *) xmalloc (sizeof (struct gdbarch_tdep));
4141 gdbarch = gdbarch_alloc (&info, tdep);
4142
4143 tdep->cris_version = cris_version;
4144 tdep->cris_mode = cris_mode;
4145 tdep->cris_abi = cris_abi;
4146
4147 /* INIT shall ensure that the INFO.BYTE_ORDER is non-zero. */
4148 switch (info.byte_order)
4149 {
4150 case BFD_ENDIAN_LITTLE:
4151 /* Ok. */
4152 break;
4153
4154 case BFD_ENDIAN_BIG:
4155 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: big endian byte order in info");
4156 break;
4157
4158 default:
4159 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown byte order in info");
4160 }
4161
4162 /* Initialize the ABI dependent things. */
4163 if (tdep->cris_abi == CRIS_ABI_ORIGINAL)
4164 {
4165 set_gdbarch_double_bit (gdbarch, 32);
4166 set_gdbarch_push_arguments (gdbarch, cris_abi_original_push_arguments);
4167 set_gdbarch_deprecated_store_return_value (gdbarch,
4168 cris_abi_original_store_return_value);
4169 set_gdbarch_deprecated_extract_return_value
4170 (gdbarch, cris_abi_original_extract_return_value);
4171 set_gdbarch_reg_struct_has_addr
4172 (gdbarch, cris_abi_original_reg_struct_has_addr);
4173 }
4174 else if (tdep->cris_abi == CRIS_ABI_V2)
4175 {
4176 set_gdbarch_double_bit (gdbarch, 64);
4177 set_gdbarch_push_arguments (gdbarch, cris_abi_v2_push_arguments);
4178 set_gdbarch_deprecated_store_return_value (gdbarch, cris_abi_v2_store_return_value);
4179 set_gdbarch_deprecated_extract_return_value
4180 (gdbarch, cris_abi_v2_extract_return_value);
4181 set_gdbarch_reg_struct_has_addr (gdbarch,
4182 cris_abi_v2_reg_struct_has_addr);
4183 }
4184 else
4185 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS ABI");
4186
4187 /* The default definition of a long double is 2 * TARGET_DOUBLE_BIT,
4188 which means we have to set this explicitly. */
4189 set_gdbarch_long_double_bit (gdbarch, 64);
4190
4191 /* There are 32 registers (some of which may not be implemented). */
4192 set_gdbarch_num_regs (gdbarch, 32);
4193 set_gdbarch_sp_regnum (gdbarch, 14);
4194 set_gdbarch_fp_regnum (gdbarch, 8);
4195 set_gdbarch_pc_regnum (gdbarch, 15);
4196
4197 set_gdbarch_register_name (gdbarch, cris_register_name);
4198
4199 /* Length of ordinary registers used in push_word and a few other places.
4200 REGISTER_RAW_SIZE is the real way to know how big a register is. */
4201 set_gdbarch_register_size (gdbarch, 4);
4202
4203 /* NEW */
4204 set_gdbarch_register_bytes_ok (gdbarch, cris_register_bytes_ok);
4205 set_gdbarch_software_single_step (gdbarch, cris_software_single_step);
4206
4207
4208 set_gdbarch_cannot_store_register (gdbarch, cris_cannot_store_register);
4209 set_gdbarch_cannot_fetch_register (gdbarch, cris_cannot_fetch_register);
4210
4211
4212 /* The total amount of space needed to store (in an array called registers)
4213 GDB's copy of the machine's register state. Note: We can not use
4214 cris_register_size at this point, since it relies on current_gdbarch
4215 being set. */
4216 switch (tdep->cris_version)
4217 {
4218 case 0:
4219 case 1:
4220 case 2:
4221 case 3:
4222 /* Support for these may be added later. */
4223 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unsupported CRIS version");
4224 break;
4225
4226 case 8:
4227 case 9:
4228 /* CRIS v8 and v9, a.k.a. ETRAX 100. General registers R0 - R15
4229 (32 bits), special registers P0 - P1 (8 bits), P4 - P5 (16 bits),
4230 and P8 - P14 (32 bits). */
4231 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (7 * 4);
4232 break;
4233
4234 case 10:
4235 case 11:
4236 /* CRIS v10 and v11, a.k.a. ETRAX 100LX. In addition to ETRAX 100,
4237 P7 (32 bits), and P15 (32 bits) have been implemented. */
4238 register_bytes = (16 * 4) + (2 * 1) + (2 * 2) + (9 * 4);
4239 break;
4240
4241 default:
4242 internal_error (__FILE__, __LINE__, "cris_gdbarch_init: unknown CRIS version");
4243 }
4244
4245 set_gdbarch_register_bytes (gdbarch, register_bytes);
4246
4247 /* Returns the register offset for the first byte of register regno's space
4248 in the saved register state. */
4249 set_gdbarch_register_byte (gdbarch, cris_register_offset);
4250
4251 /* The length of the registers in the actual machine representation. */
4252 set_gdbarch_register_raw_size (gdbarch, cris_register_size);
4253
4254 /* The largest value REGISTER_RAW_SIZE can have. */
4255 set_gdbarch_max_register_raw_size (gdbarch, 32);
4256
4257 /* The length of the registers in the program's representation. */
4258 set_gdbarch_register_virtual_size (gdbarch, cris_register_size);
4259
4260 /* The largest value REGISTER_VIRTUAL_SIZE can have. */
4261 set_gdbarch_max_register_virtual_size (gdbarch, 32);
4262
4263 set_gdbarch_register_virtual_type (gdbarch, cris_register_virtual_type);
4264
4265 /* Use generic dummy frames. */
4266 set_gdbarch_use_generic_dummy_frames (gdbarch, 1);
4267
4268 /* Where to execute the call in the memory segments. */
4269 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
4270 set_gdbarch_call_dummy_address (gdbarch, entry_point_address);
4271
4272 /* Start execution at the beginning of dummy. */
4273 set_gdbarch_call_dummy_start_offset (gdbarch, 0);
4274 set_gdbarch_call_dummy_breakpoint_offset (gdbarch, 0);
4275
4276 /* Set to 1 since call_dummy_breakpoint_offset was defined. */
4277 set_gdbarch_call_dummy_breakpoint_offset_p (gdbarch, 1);
4278
4279 /* Read all about dummy frames in blockframe.c. */
4280 set_gdbarch_call_dummy_length (gdbarch, 0);
4281 set_gdbarch_pc_in_call_dummy (gdbarch, pc_in_call_dummy_at_entry_point);
4282
4283 /* Defined to 1 to indicate that the target supports inferior function
4284 calls. */
4285 set_gdbarch_call_dummy_p (gdbarch, 1);
4286 set_gdbarch_call_dummy_words (gdbarch, 0);
4287 set_gdbarch_sizeof_call_dummy_words (gdbarch, 0);
4288
4289 /* No stack adjustment needed when peforming an inferior function call. */
4290 set_gdbarch_call_dummy_stack_adjust_p (gdbarch, 0);
4291 set_gdbarch_fix_call_dummy (gdbarch, generic_fix_call_dummy);
4292
4293 set_gdbarch_get_saved_register (gdbarch, deprecated_generic_get_saved_register);
4294
4295 /* No register requires conversion from raw format to virtual format. */
4296 set_gdbarch_register_convertible (gdbarch, generic_register_convertible_not);
4297
4298 set_gdbarch_push_dummy_frame (gdbarch, generic_push_dummy_frame);
4299 set_gdbarch_push_return_address (gdbarch, cris_push_return_address);
4300 set_gdbarch_pop_frame (gdbarch, cris_pop_frame);
4301
4302 set_gdbarch_store_struct_return (gdbarch, cris_store_struct_return);
4303 set_gdbarch_deprecated_extract_struct_value_address
4304 (gdbarch, cris_extract_struct_value_address);
4305 set_gdbarch_use_struct_convention (gdbarch, cris_use_struct_convention);
4306
4307 set_gdbarch_frame_init_saved_regs (gdbarch, cris_frame_init_saved_regs);
4308 set_gdbarch_init_extra_frame_info (gdbarch, cris_init_extra_frame_info);
4309 set_gdbarch_skip_prologue (gdbarch, cris_skip_prologue);
4310 set_gdbarch_prologue_frameless_p (gdbarch, generic_prologue_frameless_p);
4311
4312 /* The stack grows downward. */
4313 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
4314
4315 set_gdbarch_breakpoint_from_pc (gdbarch, cris_breakpoint_from_pc);
4316
4317 /* The PC must not be decremented after a breakpoint. (The breakpoint
4318 handler takes care of that.) */
4319 set_gdbarch_decr_pc_after_break (gdbarch, 0);
4320
4321 /* Offset from address of function to start of its code. */
4322 set_gdbarch_function_start_offset (gdbarch, 0);
4323
4324 /* The number of bytes at the start of arglist that are not really args,
4325 0 in the CRIS ABI. */
4326 set_gdbarch_frame_args_skip (gdbarch, 0);
4327 set_gdbarch_frameless_function_invocation
4328 (gdbarch, cris_frameless_function_invocation);
4329 set_gdbarch_frame_chain (gdbarch, cris_frame_chain);
4330 set_gdbarch_frame_chain_valid (gdbarch, generic_file_frame_chain_valid);
4331
4332 set_gdbarch_frame_saved_pc (gdbarch, cris_frame_saved_pc);
4333 set_gdbarch_frame_args_address (gdbarch, cris_frame_args_address);
4334 set_gdbarch_frame_locals_address (gdbarch, cris_frame_locals_address);
4335 set_gdbarch_saved_pc_after_call (gdbarch, cris_saved_pc_after_call);
4336
4337 set_gdbarch_frame_num_args (gdbarch, frame_num_args_unknown);
4338
4339 /* No extra stack alignment needed. Set to 1 by default. */
4340 set_gdbarch_extra_stack_alignment_needed (gdbarch, 0);
4341
4342 /* Helpful for backtracing and returning in a call dummy. */
4343 set_gdbarch_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
4344
4345 /* Use target_specific function to define link map offsets. */
4346 set_solib_svr4_fetch_link_map_offsets
4347 (gdbarch, cris_linux_svr4_fetch_link_map_offsets);
4348
4349 return gdbarch;
4350 }
This page took 0.127428 seconds and 4 git commands to generate.