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