1 /* Target-dependent code for the Fujitsu FR-V, for GDB, the GNU Debugger.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
23 #include "symfile.h" /* for entry_point_address */
25 #include "arch-utils.h"
28 extern void _initialize_frv_tdep (void);
30 static gdbarch_init_ftype frv_gdbarch_init
;
32 static gdbarch_register_name_ftype frv_register_name
;
33 static gdbarch_breakpoint_from_pc_ftype frv_breakpoint_from_pc
;
34 static gdbarch_skip_prologue_ftype frv_skip_prologue
;
35 static gdbarch_deprecated_extract_return_value_ftype frv_extract_return_value
;
36 static gdbarch_deprecated_extract_struct_value_address_ftype frv_extract_struct_value_address
;
37 static gdbarch_frameless_function_invocation_ftype frv_frameless_function_invocation
;
38 static gdbarch_deprecated_push_arguments_ftype frv_push_arguments
;
39 static gdbarch_deprecated_saved_pc_after_call_ftype frv_saved_pc_after_call
;
41 static void frv_pop_frame_regular (struct frame_info
*frame
);
43 /* Register numbers. You can change these as needed, but don't forget
44 to update the simulator accordingly. */
46 /* The total number of registers we know exist. */
49 /* Register numbers 0 -- 63 are always reserved for general-purpose
50 registers. The chip at hand may have less. */
54 struct_return_regnum
= 3,
57 /* Register numbers 64 -- 127 are always reserved for floating-point
58 registers. The chip at hand may have less. */
59 first_fpr_regnum
= 64,
60 last_fpr_regnum
= 127,
62 /* Register numbers 128 on up are always reserved for special-purpose
64 first_spr_regnum
= 128,
80 static LONGEST frv_call_dummy_words
[] =
84 /* The contents of this structure can only be trusted after we've
85 frv_frame_init_saved_regs on the frame. */
86 struct frame_extra_info
88 /* The offset from our frame pointer to our caller's stack
90 int fp_to_callers_sp_offset
;
92 /* Non-zero if we've saved our return address on the stack yet.
93 Zero if it's still sitting in the link register. */
94 int lr_saved_on_stack
;
98 /* A structure describing a particular variant of the FRV.
99 We allocate and initialize one of these structures when we create
100 the gdbarch object for a variant.
102 At the moment, all the FR variants we support differ only in which
103 registers are present; the portable code of GDB knows that
104 registers whose names are the empty string don't exist, so the
105 `register_names' array captures all the per-variant information we
108 in the future, if we need to have per-variant maps for raw size,
109 virtual type, etc., we should replace register_names with an array
110 of structures, each of which gives all the necessary info for one
111 register. Don't stick parallel arrays in here --- that's so
115 /* How many general-purpose registers does this variant have? */
118 /* How many floating-point registers does this variant have? */
121 /* How many hardware watchpoints can it support? */
122 int num_hw_watchpoints
;
124 /* How many hardware breakpoints can it support? */
125 int num_hw_breakpoints
;
127 /* Register names. */
128 char **register_names
;
131 #define CURRENT_VARIANT (gdbarch_tdep (current_gdbarch))
134 /* Allocate a new variant structure, and set up default values for all
136 static struct gdbarch_tdep
*
139 struct gdbarch_tdep
*var
;
143 var
= xmalloc (sizeof (*var
));
144 memset (var
, 0, sizeof (*var
));
148 var
->num_hw_watchpoints
= 0;
149 var
->num_hw_breakpoints
= 0;
151 /* By default, don't supply any general-purpose or floating-point
153 var
->register_names
= (char **) xmalloc (frv_num_regs
* sizeof (char *));
154 for (r
= 0; r
< frv_num_regs
; r
++)
155 var
->register_names
[r
] = "";
157 /* Do, however, supply default names for the special-purpose
159 for (r
= first_spr_regnum
; r
<= last_spr_regnum
; ++r
)
161 sprintf (buf
, "x%d", r
);
162 var
->register_names
[r
] = xstrdup (buf
);
165 var
->register_names
[pc_regnum
] = "pc";
166 var
->register_names
[lr_regnum
] = "lr";
167 var
->register_names
[lcr_regnum
] = "lcr";
169 var
->register_names
[psr_regnum
] = "psr";
170 var
->register_names
[ccr_regnum
] = "ccr";
171 var
->register_names
[cccr_regnum
] = "cccr";
172 var
->register_names
[tbr_regnum
] = "tbr";
174 /* Debug registers. */
175 var
->register_names
[brr_regnum
] = "brr";
176 var
->register_names
[dbar0_regnum
] = "dbar0";
177 var
->register_names
[dbar1_regnum
] = "dbar1";
178 var
->register_names
[dbar2_regnum
] = "dbar2";
179 var
->register_names
[dbar3_regnum
] = "dbar3";
185 /* Indicate that the variant VAR has NUM_GPRS general-purpose
186 registers, and fill in the names array appropriately. */
188 set_variant_num_gprs (struct gdbarch_tdep
*var
, int num_gprs
)
192 var
->num_gprs
= num_gprs
;
194 for (r
= 0; r
< num_gprs
; ++r
)
198 sprintf (buf
, "gr%d", r
);
199 var
->register_names
[first_gpr_regnum
+ r
] = xstrdup (buf
);
204 /* Indicate that the variant VAR has NUM_FPRS floating-point
205 registers, and fill in the names array appropriately. */
207 set_variant_num_fprs (struct gdbarch_tdep
*var
, int num_fprs
)
211 var
->num_fprs
= num_fprs
;
213 for (r
= 0; r
< num_fprs
; ++r
)
217 sprintf (buf
, "fr%d", r
);
218 var
->register_names
[first_fpr_regnum
+ r
] = xstrdup (buf
);
224 frv_register_name (int reg
)
228 if (reg
>= frv_num_regs
)
231 return CURRENT_VARIANT
->register_names
[reg
];
236 frv_register_raw_size (int reg
)
242 frv_register_virtual_size (int reg
)
248 frv_register_virtual_type (int reg
)
250 if (reg
>= 64 && reg
<= 127)
251 return builtin_type_float
;
253 return builtin_type_int
;
257 frv_register_byte (int reg
)
262 static const unsigned char *
263 frv_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenp
)
265 static unsigned char breakpoint
[] = {0xc0, 0x70, 0x00, 0x01};
266 *lenp
= sizeof (breakpoint
);
271 frv_frame_chain (struct frame_info
*frame
)
273 CORE_ADDR saved_fp_addr
;
275 if (frame
->saved_regs
&& frame
->saved_regs
[fp_regnum
] != 0)
276 saved_fp_addr
= frame
->saved_regs
[fp_regnum
];
278 /* Just assume it was saved in the usual place. */
279 saved_fp_addr
= frame
->frame
;
281 return read_memory_integer (saved_fp_addr
, 4);
285 frv_frame_saved_pc (struct frame_info
*frame
)
287 frv_frame_init_saved_regs (frame
);
289 /* Perhaps the prologue analyzer recorded where it was stored.
290 (As of 14 Oct 2001, it never does.) */
291 if (frame
->saved_regs
&& frame
->saved_regs
[pc_regnum
] != 0)
292 return read_memory_integer (frame
->saved_regs
[pc_regnum
], 4);
294 /* If the prologue analyzer tells us the link register was saved on
295 the stack, get it from there. */
296 if (frame
->extra_info
->lr_saved_on_stack
)
297 return read_memory_integer (frame
->frame
+ 8, 4);
299 /* Otherwise, it's still in LR.
300 However, if FRAME isn't the youngest frame, this is kind of
301 suspicious --- if this frame called somebody else, then its LR
302 has certainly been overwritten. */
304 return read_register (lr_regnum
);
306 /* By default, assume it's saved in the standard place, relative to
307 the frame pointer. */
308 return read_memory_integer (frame
->frame
+ 8, 4);
312 /* Return true if REG is a caller-saves ("scratch") register,
315 is_caller_saves_reg (int reg
)
317 return ((4 <= reg
&& reg
<= 7)
318 || (14 <= reg
&& reg
<= 15)
319 || (32 <= reg
&& reg
<= 47));
323 /* Return true if REG is a callee-saves register, false otherwise. */
325 is_callee_saves_reg (int reg
)
327 return ((16 <= reg
&& reg
<= 31)
328 || (48 <= reg
&& reg
<= 63));
332 /* Return true if REG is an argument register, false otherwise. */
334 is_argument_reg (int reg
)
336 return (8 <= reg
&& reg
<= 13);
340 /* Scan an FR-V prologue, starting at PC, until frame->PC.
341 If FRAME is non-zero, fill in its saved_regs with appropriate addresses.
342 We assume FRAME's saved_regs array has already been allocated and cleared.
343 Return the first PC value after the prologue.
345 Note that, for unoptimized code, we almost don't need this function
346 at all; all arguments and locals live on the stack, so we just need
347 the FP to find everything. The catch: structures passed by value
348 have their addresses living in registers; they're never spilled to
349 the stack. So if you ever want to be able to get to these
350 arguments in any frame but the top, you'll need to do this serious
351 prologue analysis. */
353 frv_analyze_prologue (CORE_ADDR pc
, struct frame_info
*frame
)
355 /* When writing out instruction bitpatterns, we use the following
356 letters to label instruction fields:
357 P - The parallel bit. We don't use this.
358 J - The register number of GRj in the instruction description.
359 K - The register number of GRk in the instruction description.
360 I - The register number of GRi.
361 S - a signed imediate offset.
362 U - an unsigned immediate offset.
364 The dots below the numbers indicate where hex digit boundaries
365 fall, to make it easier to check the numbers. */
367 /* Non-zero iff we've seen the instruction that initializes the
368 frame pointer for this function's frame. */
371 /* If fp_set is non_zero, then this is the distance from
372 the stack pointer to frame pointer: fp = sp + fp_offset. */
375 /* Total size of frame prior to any alloca operations. */
378 /* The number of the general-purpose register we saved the return
379 address ("link register") in, or -1 if we haven't moved it yet. */
380 int lr_save_reg
= -1;
382 /* Non-zero iff we've saved the LR onto the stack. */
383 int lr_saved_on_stack
= 0;
385 /* If gr_saved[i] is non-zero, then we've noticed that general
386 register i has been saved at gr_sp_offset[i] from the stack
389 int gr_sp_offset
[64];
391 memset (gr_saved
, 0, sizeof (gr_saved
));
393 while (! frame
|| pc
< frame
->pc
)
395 LONGEST op
= read_memory_integer (pc
, 4);
397 /* The tests in this chain of ifs should be in order of
398 decreasing selectivity, so that more particular patterns get
399 to fire before less particular patterns. */
401 /* Setting the FP from the SP:
403 P 000010 0100010 000001 000000000000 = 0x04881000
404 0 111111 1111111 111111 111111111111 = 0x7fffffff
406 We treat this as part of the prologue. */
407 if ((op
& 0x7fffffff) == 0x04881000)
413 /* Move the link register to the scratch register grJ, before saving:
415 P 000100 0000011 010000 000111 JJJJJJ = 0x080d01c0
416 0 111111 1111111 111111 111111 000000 = 0x7fffffc0
418 We treat this as part of the prologue. */
419 else if ((op
& 0x7fffffc0) == 0x080d01c0)
421 int gr_j
= op
& 0x3f;
423 /* If we're moving it to a scratch register, that's fine. */
424 if (is_caller_saves_reg (gr_j
))
426 /* Otherwise it's not a prologue instruction that we
432 /* To save multiple callee-saves registers on the stack, at
436 P KKKKKK 0000011 000001 000011 000000 = 0x000c10c0
437 0 000000 1111111 111111 111111 111111 = 0x01ffffff
440 P KKKKKK 0000011 000001 000100 000000 = 0x000c1100
441 0 000000 1111111 111111 111111 111111 = 0x01ffffff
443 We treat this as part of the prologue, and record the register's
444 saved address in the frame structure. */
445 else if ((op
& 0x01ffffff) == 0x000c10c0
446 || (op
& 0x01ffffff) == 0x000c1100)
448 int gr_k
= ((op
>> 25) & 0x3f);
449 int ope
= ((op
>> 6) & 0x3f);
453 /* Is it an std or an stq? */
459 /* Is it really a callee-saves register? */
460 if (is_callee_saves_reg (gr_k
))
462 for (i
= 0; i
< count
; i
++)
464 gr_saved
[gr_k
+ i
] = 1;
465 gr_sp_offset
[gr_k
+ i
] = 4 * i
;
469 /* It's not a prologue instruction. */
473 /* Adjusting the stack pointer. (The stack pointer is GR1.)
475 P 000001 0010000 000001 SSSSSSSSSSSS = 0x02401000
476 0 111111 1111111 111111 000000000000 = 0x7ffff000
478 We treat this as part of the prologue. */
479 else if ((op
& 0x7ffff000) == 0x02401000)
481 /* Sign-extend the twelve-bit field.
482 (Isn't there a better way to do this?) */
483 int s
= (((op
& 0xfff) - 0x800) & 0xfff) - 0x800;
488 /* Setting the FP to a constant distance from the SP:
490 P 000010 0010000 000001 SSSSSSSSSSSS = 0x04401000
491 0 111111 1111111 111111 000000000000 = 0x7ffff000
493 We treat this as part of the prologue. */
494 else if ((op
& 0x7ffff000) == 0x04401000)
496 /* Sign-extend the twelve-bit field.
497 (Isn't there a better way to do this?) */
498 int s
= (((op
& 0xfff) - 0x800) & 0xfff) - 0x800;
503 /* To spill an argument register to a scratch register:
505 P KKKKKK 0100010 IIIIII 000000000000 = 0x00880000
506 0 000000 1111111 000000 111111111111 = 0x01fc0fff
508 For the time being, we treat this as a prologue instruction,
509 assuming that GRi is an argument register. This one's kind
510 of suspicious, because it seems like it could be part of a
511 legitimate body instruction. But we only come here when the
512 source info wasn't helpful, so we have to do the best we can.
513 Hopefully once GCC and GDB agree on how to emit line number
514 info for prologues, then this code will never come into play. */
515 else if ((op
& 0x01fc0fff) == 0x00880000)
517 int gr_i
= ((op
>> 12) & 0x3f);
519 /* If the source isn't an arg register, then this isn't a
520 prologue instruction. */
521 if (! is_argument_reg (gr_i
))
525 /* To spill 16-bit values to the stack:
527 P KKKKKK 1010001 000010 SSSSSSSSSSSS = 0x01442000
528 0 000000 1111111 111111 000000000000 = 0x01fff000
530 And for 8-bit values, we use STB instructions.
532 P KKKKKK 1010000 000010 SSSSSSSSSSSS = 0x01402000
533 0 000000 1111111 111111 000000000000 = 0x01fff000
535 We check that GRk is really an argument register, and treat
536 all such as part of the prologue. */
537 else if ( (op
& 0x01fff000) == 0x01442000
538 || (op
& 0x01fff000) == 0x01402000)
540 int gr_k
= ((op
>> 25) & 0x3f);
542 if (! is_argument_reg (gr_k
))
543 break; /* Source isn't an arg register. */
546 /* To save multiple callee-saves register on the stack, at a
550 P KKKKKK 1010011 000001 SSSSSSSSSSSS = 0x014c1000
551 0 000000 1111111 111111 000000000000 = 0x01fff000
554 P KKKKKK 1010100 000001 SSSSSSSSSSSS = 0x01501000
555 0 000000 1111111 111111 000000000000 = 0x01fff000
557 We treat this as part of the prologue, and record the register's
558 saved address in the frame structure. */
559 else if ((op
& 0x01fff000) == 0x014c1000
560 || (op
& 0x01fff000) == 0x01501000)
562 int gr_k
= ((op
>> 25) & 0x3f);
566 /* Is it a stdi or a stqi? */
567 if ((op
& 0x01fff000) == 0x014c1000)
572 /* Is it really a callee-saves register? */
573 if (is_callee_saves_reg (gr_k
))
575 /* Sign-extend the twelve-bit field.
576 (Isn't there a better way to do this?) */
577 int s
= (((op
& 0xfff) - 0x800) & 0xfff) - 0x800;
579 for (i
= 0; i
< count
; i
++)
581 gr_saved
[gr_k
+ i
] = 1;
582 gr_sp_offset
[gr_k
+ i
] = s
+ (4 * i
);
586 /* It's not a prologue instruction. */
590 /* Storing any kind of integer register at any constant offset
591 from any other register.
594 P KKKKKK 0000011 IIIIII 000010 000000 = 0x000c0080
595 0 000000 1111111 000000 111111 111111 = 0x01fc0fff
598 P KKKKKK 1010010 IIIIII SSSSSSSSSSSS = 0x01480000
599 0 000000 1111111 000000 000000000000 = 0x01fc0000
601 These could be almost anything, but a lot of prologue
602 instructions fall into this pattern, so let's decode the
603 instruction once, and then work at a higher level. */
604 else if (((op
& 0x01fc0fff) == 0x000c0080)
605 || ((op
& 0x01fc0000) == 0x01480000))
607 int gr_k
= ((op
>> 25) & 0x3f);
608 int gr_i
= ((op
>> 12) & 0x3f);
611 /* Are we storing with gr0 as an offset, or using an
613 if ((op
& 0x01fc0fff) == 0x000c0080)
616 offset
= (((op
& 0xfff) - 0x800) & 0xfff) - 0x800;
618 /* If the address isn't relative to the SP or FP, it's not a
619 prologue instruction. */
620 if (gr_i
!= sp_regnum
&& gr_i
!= fp_regnum
)
623 /* Saving the old FP in the new frame (relative to the SP). */
624 if (gr_k
== fp_regnum
&& gr_i
== sp_regnum
)
627 /* Saving callee-saves register(s) on the stack, relative to
629 else if (gr_i
== sp_regnum
630 && is_callee_saves_reg (gr_k
))
633 gr_sp_offset
[gr_k
] = offset
;
636 /* Saving the scratch register holding the return address. */
637 else if (lr_save_reg
!= -1
638 && gr_k
== lr_save_reg
)
639 lr_saved_on_stack
= 1;
641 /* Spilling int-sized arguments to the stack. */
642 else if (is_argument_reg (gr_k
))
645 /* It's not a store instruction we recognize, so this must
646 be the end of the prologue. */
651 /* It's not any instruction we recognize, so this must be the end
661 frame
->extra_info
->lr_saved_on_stack
= lr_saved_on_stack
;
663 /* If we know the relationship between the stack and frame
664 pointers, record the addresses of the registers we noticed.
665 Note that we have to do this as a separate step at the end,
666 because instructions may save relative to the SP, but we need
667 their addresses relative to the FP. */
672 for (i
= 0; i
< 64; i
++)
674 frame
->saved_regs
[i
] = (frame
->frame
675 - fp_offset
+ gr_sp_offset
[i
]);
677 frame
->extra_info
->fp_to_callers_sp_offset
= framesize
- fp_offset
;
686 frv_skip_prologue (CORE_ADDR pc
)
688 CORE_ADDR func_addr
, func_end
, new_pc
;
692 /* If the line table has entry for a line *within* the function
693 (i.e., not in the prologue, and not past the end), then that's
695 if (find_pc_partial_function (pc
, NULL
, &func_addr
, &func_end
))
697 struct symtab_and_line sal
;
699 sal
= find_pc_line (func_addr
, 0);
701 if (sal
.line
!= 0 && sal
.end
< func_end
)
707 /* The FR-V prologue is at least five instructions long (twenty bytes).
708 If we didn't find a real source location past that, then
709 do a full analysis of the prologue. */
710 if (new_pc
< pc
+ 20)
711 new_pc
= frv_analyze_prologue (pc
, 0);
717 frv_frame_init_saved_regs (struct frame_info
*frame
)
719 if (frame
->saved_regs
)
722 frame_saved_regs_zalloc (frame
);
723 frame
->saved_regs
[fp_regnum
] = frame
->frame
;
725 /* Find the beginning of this function, so we can analyze its
728 CORE_ADDR func_addr
, func_end
;
730 if (find_pc_partial_function (frame
->pc
, NULL
, &func_addr
, &func_end
))
731 frv_analyze_prologue (func_addr
, frame
);
736 frv_extract_return_value (struct type
*type
, char *regbuf
, char *valbuf
)
738 memcpy (valbuf
, (regbuf
739 + frv_register_byte (8)
740 + (TYPE_LENGTH (type
) < 4 ? 4 - TYPE_LENGTH (type
) : 0)),
745 frv_extract_struct_value_address (char *regbuf
)
747 return extract_unsigned_integer (regbuf
+ frv_register_byte (struct_return_regnum
),
752 frv_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
754 write_register (struct_return_regnum
, addr
);
758 frv_frameless_function_invocation (struct frame_info
*frame
)
760 return frameless_look_for_prologue (frame
);
764 frv_saved_pc_after_call (struct frame_info
*frame
)
766 return read_register (lr_regnum
);
770 frv_init_extra_frame_info (int fromleaf
, struct frame_info
*frame
)
772 frame_extra_info_zalloc (frame
, sizeof (struct frame_extra_info
));
773 frame
->extra_info
->fp_to_callers_sp_offset
= 0;
774 frame
->extra_info
->lr_saved_on_stack
= 0;
777 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
778 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
781 frv_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
782 int struct_return
, CORE_ADDR struct_addr
)
789 struct type
*arg_type
;
791 enum type_code typecode
;
797 printf("Push %d args at sp = %x, struct_return=%d (%x)\n",
798 nargs
, (int) sp
, struct_return
, struct_addr
);
802 for (argnum
= 0; argnum
< nargs
; ++argnum
)
803 stack_space
+= ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args
[argnum
])), 4);
805 stack_space
-= (6 * 4);
809 /* Make sure stack is dword aligned. */
810 sp
= ROUND_DOWN (sp
, 8);
817 write_register (struct_return_regnum
, struct_addr
);
819 for (argnum
= 0; argnum
< nargs
; ++argnum
)
822 arg_type
= check_typedef (VALUE_TYPE (arg
));
823 len
= TYPE_LENGTH (arg_type
);
824 typecode
= TYPE_CODE (arg_type
);
826 if (typecode
== TYPE_CODE_STRUCT
|| typecode
== TYPE_CODE_UNION
)
828 store_unsigned_integer (valbuf
, 4, VALUE_ADDRESS (arg
));
829 typecode
= TYPE_CODE_PTR
;
835 val
= (char *) VALUE_CONTENTS (arg
);
840 int partial_len
= (len
< 4 ? len
: 4);
844 regval
= extract_unsigned_integer (val
, partial_len
);
846 printf(" Argnum %d data %x -> reg %d\n",
847 argnum
, (int) regval
, argreg
);
849 write_register (argreg
, regval
);
855 printf(" Argnum %d data %x -> offset %d (%x)\n",
856 argnum
, *((int *)val
), stack_offset
, (int) (sp
+ stack_offset
));
858 write_memory (sp
+ stack_offset
, val
, partial_len
);
859 stack_offset
+= ROUND_UP(partial_len
, 4);
869 frv_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
871 write_register (lr_regnum
, CALL_DUMMY_ADDRESS ());
876 frv_store_return_value (struct type
*type
, char *valbuf
)
878 int length
= TYPE_LENGTH (type
);
879 int reg8_offset
= frv_register_byte (8);
882 deprecated_write_register_bytes (reg8_offset
+ (4 - length
), valbuf
,
884 else if (length
== 8)
885 deprecated_write_register_bytes (reg8_offset
, valbuf
, length
);
887 internal_error (__FILE__
, __LINE__
,
888 "Don't know how to return a %d-byte value.", length
);
894 generic_pop_current_frame (frv_pop_frame_regular
);
898 frv_pop_frame_regular (struct frame_info
*frame
)
905 frv_frame_init_saved_regs (frame
);
907 write_register (pc_regnum
, frv_frame_saved_pc (frame
));
908 for (regno
= 0; regno
< frv_num_regs
; ++regno
)
910 if (frame
->saved_regs
[regno
]
911 && regno
!= pc_regnum
912 && regno
!= sp_regnum
)
914 write_register (regno
,
915 read_memory_integer (frame
->saved_regs
[regno
], 4));
918 write_register (sp_regnum
, fp
+ frame
->extra_info
->fp_to_callers_sp_offset
);
919 flush_cached_frames ();
922 /* Hardware watchpoint / breakpoint support for the FR500
926 frv_check_watch_resources (int type
, int cnt
, int ot
)
928 struct gdbarch_tdep
*var
= CURRENT_VARIANT
;
930 /* Watchpoints not supported on simulator. */
931 if (strcmp (target_shortname
, "sim") == 0)
934 if (type
== bp_hardware_breakpoint
)
936 if (var
->num_hw_breakpoints
== 0)
938 else if (cnt
<= var
->num_hw_breakpoints
)
943 if (var
->num_hw_watchpoints
== 0)
947 else if (cnt
<= var
->num_hw_watchpoints
)
955 frv_stopped_data_address (void)
957 CORE_ADDR brr
, dbar0
, dbar1
, dbar2
, dbar3
;
959 brr
= read_register (brr_regnum
);
960 dbar0
= read_register (dbar0_regnum
);
961 dbar1
= read_register (dbar1_regnum
);
962 dbar2
= read_register (dbar2_regnum
);
963 dbar3
= read_register (dbar3_regnum
);
967 else if (brr
& (1<<10))
969 else if (brr
& (1<<9))
971 else if (brr
& (1<<8))
977 static struct gdbarch
*
978 frv_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
980 struct gdbarch
*gdbarch
;
981 struct gdbarch_tdep
*var
;
983 /* Check to see if we've already built an appropriate architecture
984 object for this executable. */
985 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
987 return arches
->gdbarch
;
989 /* Select the right tdep structure for this variant. */
990 var
= new_variant ();
991 switch (info
.bfd_arch_info
->mach
)
994 case bfd_mach_frvsimple
:
996 case bfd_mach_frvtomcat
:
997 set_variant_num_gprs (var
, 64);
998 set_variant_num_fprs (var
, 64);
1001 case bfd_mach_fr400
:
1002 set_variant_num_gprs (var
, 32);
1003 set_variant_num_fprs (var
, 32);
1007 /* Never heard of this variant. */
1011 gdbarch
= gdbarch_alloc (&info
, var
);
1013 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1014 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1015 set_gdbarch_deprecated_init_frame_pc (gdbarch
, init_frame_pc_default
);
1017 set_gdbarch_short_bit (gdbarch
, 16);
1018 set_gdbarch_int_bit (gdbarch
, 32);
1019 set_gdbarch_long_bit (gdbarch
, 32);
1020 set_gdbarch_long_long_bit (gdbarch
, 64);
1021 set_gdbarch_float_bit (gdbarch
, 32);
1022 set_gdbarch_double_bit (gdbarch
, 64);
1023 set_gdbarch_long_double_bit (gdbarch
, 64);
1024 set_gdbarch_ptr_bit (gdbarch
, 32);
1026 set_gdbarch_num_regs (gdbarch
, frv_num_regs
);
1027 set_gdbarch_sp_regnum (gdbarch
, sp_regnum
);
1028 set_gdbarch_deprecated_fp_regnum (gdbarch
, fp_regnum
);
1029 set_gdbarch_pc_regnum (gdbarch
, pc_regnum
);
1031 set_gdbarch_register_name (gdbarch
, frv_register_name
);
1032 set_gdbarch_deprecated_register_size (gdbarch
, 4);
1033 set_gdbarch_deprecated_register_bytes (gdbarch
, frv_num_regs
* 4);
1034 set_gdbarch_deprecated_register_byte (gdbarch
, frv_register_byte
);
1035 set_gdbarch_deprecated_register_raw_size (gdbarch
, frv_register_raw_size
);
1036 set_gdbarch_deprecated_max_register_raw_size (gdbarch
, 4);
1037 set_gdbarch_deprecated_register_virtual_size (gdbarch
, frv_register_virtual_size
);
1038 set_gdbarch_deprecated_max_register_virtual_size (gdbarch
, 4);
1039 set_gdbarch_deprecated_register_virtual_type (gdbarch
, frv_register_virtual_type
);
1041 set_gdbarch_skip_prologue (gdbarch
, frv_skip_prologue
);
1042 set_gdbarch_breakpoint_from_pc (gdbarch
, frv_breakpoint_from_pc
);
1044 set_gdbarch_frame_args_skip (gdbarch
, 0);
1045 set_gdbarch_frameless_function_invocation (gdbarch
, frv_frameless_function_invocation
);
1047 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, frv_saved_pc_after_call
);
1049 set_gdbarch_deprecated_frame_chain (gdbarch
, frv_frame_chain
);
1050 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, frv_frame_saved_pc
);
1052 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, frv_frame_init_saved_regs
);
1054 set_gdbarch_use_struct_convention (gdbarch
, always_use_struct_convention
);
1055 set_gdbarch_deprecated_extract_return_value (gdbarch
, frv_extract_return_value
);
1057 set_gdbarch_deprecated_store_struct_return (gdbarch
, frv_store_struct_return
);
1058 set_gdbarch_deprecated_store_return_value (gdbarch
, frv_store_return_value
);
1059 set_gdbarch_deprecated_extract_struct_value_address (gdbarch
, frv_extract_struct_value_address
);
1061 /* Settings for calling functions in the inferior. */
1062 set_gdbarch_deprecated_push_arguments (gdbarch
, frv_push_arguments
);
1063 set_gdbarch_deprecated_push_return_address (gdbarch
, frv_push_return_address
);
1064 set_gdbarch_deprecated_pop_frame (gdbarch
, frv_pop_frame
);
1066 set_gdbarch_deprecated_call_dummy_words (gdbarch
, frv_call_dummy_words
);
1067 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, sizeof (frv_call_dummy_words
));
1068 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, frv_init_extra_frame_info
);
1070 /* Settings that should be unnecessary. */
1071 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
1073 set_gdbarch_write_pc (gdbarch
, generic_target_write_pc
);
1074 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
1076 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
1078 set_gdbarch_decr_pc_after_break (gdbarch
, 0);
1079 set_gdbarch_function_start_offset (gdbarch
, 0);
1081 set_gdbarch_remote_translate_xfer_address
1082 (gdbarch
, generic_remote_translate_xfer_address
);
1084 /* Hardware watchpoint / breakpoint support. */
1085 switch (info
.bfd_arch_info
->mach
)
1088 case bfd_mach_frvsimple
:
1089 case bfd_mach_fr500
:
1090 case bfd_mach_frvtomcat
:
1091 /* fr500-style hardware debugging support. */
1092 var
->num_hw_watchpoints
= 4;
1093 var
->num_hw_breakpoints
= 4;
1096 case bfd_mach_fr400
:
1097 /* fr400-style hardware debugging support. */
1098 var
->num_hw_watchpoints
= 2;
1099 var
->num_hw_breakpoints
= 4;
1103 /* Otherwise, assume we don't have hardware debugging support. */
1104 var
->num_hw_watchpoints
= 0;
1105 var
->num_hw_breakpoints
= 0;
1113 _initialize_frv_tdep (void)
1115 register_gdbarch_init (bfd_arch_frv
, frv_gdbarch_init
);
1117 deprecated_tm_print_insn
= print_insn_frv
;