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