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