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