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. */
22 #include "gdb_string.h"
24 #include "symfile.h" /* for entry_point_address */
26 #include "arch-utils.h"
29 #include "frame-unwind.h"
30 #include "frame-base.h"
31 #include "trad-frame.h"
34 extern void _initialize_frv_tdep (void);
36 static gdbarch_init_ftype frv_gdbarch_init;
38 static gdbarch_register_name_ftype frv_register_name;
39 static gdbarch_breakpoint_from_pc_ftype frv_breakpoint_from_pc;
40 static gdbarch_skip_prologue_ftype frv_skip_prologue;
41 static gdbarch_deprecated_extract_return_value_ftype frv_extract_return_value;
42 static gdbarch_deprecated_extract_struct_value_address_ftype frv_extract_struct_value_address;
43 static gdbarch_frameless_function_invocation_ftype frv_frameless_function_invocation;
44 static gdbarch_deprecated_push_arguments_ftype frv_push_arguments;
45 static gdbarch_deprecated_saved_pc_after_call_ftype frv_saved_pc_after_call;
47 /* Register numbers. You can change these as needed, but don't forget
48 to update the simulator accordingly. */
50 /* The total number of registers we know exist. */
53 /* Register numbers 0 -- 63 are always reserved for general-purpose
54 registers. The chip at hand may have less. */
58 struct_return_regnum = 3,
61 /* Register numbers 64 -- 127 are always reserved for floating-point
62 registers. The chip at hand may have less. */
63 first_fpr_regnum = 64,
64 last_fpr_regnum = 127,
66 /* Register numbers 128 on up are always reserved for special-purpose
68 first_spr_regnum = 128,
84 static LONGEST frv_call_dummy_words[] =
88 struct frv_unwind_cache /* was struct frame_extra_info */
90 /* The previous frame's inner-most stack address. Used as this
91 frame ID's stack_addr. */
94 /* The frame's base, optionally used by the high-level debug info. */
97 /* Table indicating the location of each and every register. */
98 struct trad_frame_saved_reg *saved_regs;
102 /* A structure describing a particular variant of the FRV.
103 We allocate and initialize one of these structures when we create
104 the gdbarch object for a variant.
106 At the moment, all the FR variants we support differ only in which
107 registers are present; the portable code of GDB knows that
108 registers whose names are the empty string don't exist, so the
109 `register_names' array captures all the per-variant information we
112 in the future, if we need to have per-variant maps for raw size,
113 virtual type, etc., we should replace register_names with an array
114 of structures, each of which gives all the necessary info for one
115 register. Don't stick parallel arrays in here --- that's so
119 /* How many general-purpose registers does this variant have? */
122 /* How many floating-point registers does this variant have? */
125 /* How many hardware watchpoints can it support? */
126 int num_hw_watchpoints;
128 /* How many hardware breakpoints can it support? */
129 int num_hw_breakpoints;
131 /* Register names. */
132 char **register_names;
135 #define CURRENT_VARIANT (gdbarch_tdep (current_gdbarch))
138 /* Allocate a new variant structure, and set up default values for all
140 static struct gdbarch_tdep *
143 struct gdbarch_tdep *var;
147 var = xmalloc (sizeof (*var));
148 memset (var, 0, sizeof (*var));
152 var->num_hw_watchpoints = 0;
153 var->num_hw_breakpoints = 0;
155 /* By default, don't supply any general-purpose or floating-point
157 var->register_names = (char **) xmalloc (frv_num_regs * sizeof (char *));
158 for (r = 0; r < frv_num_regs; r++)
159 var->register_names[r] = "";
161 /* Do, however, supply default names for the special-purpose
163 for (r = first_spr_regnum; r <= last_spr_regnum; ++r)
165 sprintf (buf, "x%d", r);
166 var->register_names[r] = xstrdup (buf);
169 var->register_names[pc_regnum] = "pc";
170 var->register_names[lr_regnum] = "lr";
171 var->register_names[lcr_regnum] = "lcr";
173 var->register_names[psr_regnum] = "psr";
174 var->register_names[ccr_regnum] = "ccr";
175 var->register_names[cccr_regnum] = "cccr";
176 var->register_names[tbr_regnum] = "tbr";
178 /* Debug registers. */
179 var->register_names[brr_regnum] = "brr";
180 var->register_names[dbar0_regnum] = "dbar0";
181 var->register_names[dbar1_regnum] = "dbar1";
182 var->register_names[dbar2_regnum] = "dbar2";
183 var->register_names[dbar3_regnum] = "dbar3";
189 /* Indicate that the variant VAR has NUM_GPRS general-purpose
190 registers, and fill in the names array appropriately. */
192 set_variant_num_gprs (struct gdbarch_tdep *var, int num_gprs)
196 var->num_gprs = num_gprs;
198 for (r = 0; r < num_gprs; ++r)
202 sprintf (buf, "gr%d", r);
203 var->register_names[first_gpr_regnum + r] = xstrdup (buf);
208 /* Indicate that the variant VAR has NUM_FPRS floating-point
209 registers, and fill in the names array appropriately. */
211 set_variant_num_fprs (struct gdbarch_tdep *var, int num_fprs)
215 var->num_fprs = num_fprs;
217 for (r = 0; r < num_fprs; ++r)
221 sprintf (buf, "fr%d", r);
222 var->register_names[first_fpr_regnum + r] = xstrdup (buf);
228 frv_register_name (int reg)
232 if (reg >= frv_num_regs)
235 return CURRENT_VARIANT->register_names[reg];
240 frv_register_raw_size (int reg)
246 frv_register_virtual_size (int reg)
252 frv_register_virtual_type (int reg)
254 if (reg >= 64 && reg <= 127)
255 return builtin_type_float;
257 return builtin_type_int;
261 frv_register_byte (int reg)
266 static const unsigned char *
267 frv_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenp)
269 static unsigned char breakpoint[] = {0xc0, 0x70, 0x00, 0x01};
270 *lenp = sizeof (breakpoint);
275 /* Return true if REG is a caller-saves ("scratch") register,
278 is_caller_saves_reg (int reg)
280 return ((4 <= reg && reg <= 7)
281 || (14 <= reg && reg <= 15)
282 || (32 <= reg && reg <= 47));
286 /* Return true if REG is a callee-saves register, false otherwise. */
288 is_callee_saves_reg (int reg)
290 return ((16 <= reg && reg <= 31)
291 || (48 <= reg && reg <= 63));
295 /* Return true if REG is an argument register, false otherwise. */
297 is_argument_reg (int reg)
299 return (8 <= reg && reg <= 13);
303 /* Scan an FR-V prologue, starting at PC, until frame->PC.
304 If FRAME is non-zero, fill in its saved_regs with appropriate addresses.
305 We assume FRAME's saved_regs array has already been allocated and cleared.
306 Return the first PC value after the prologue.
308 Note that, for unoptimized code, we almost don't need this function
309 at all; all arguments and locals live on the stack, so we just need
310 the FP to find everything. The catch: structures passed by value
311 have their addresses living in registers; they're never spilled to
312 the stack. So if you ever want to be able to get to these
313 arguments in any frame but the top, you'll need to do this serious
314 prologue analysis. */
316 frv_analyze_prologue (CORE_ADDR pc, struct frame_info *next_frame,
317 struct frv_unwind_cache *info)
319 /* When writing out instruction bitpatterns, we use the following
320 letters to label instruction fields:
321 P - The parallel bit. We don't use this.
322 J - The register number of GRj in the instruction description.
323 K - The register number of GRk in the instruction description.
324 I - The register number of GRi.
325 S - a signed imediate offset.
326 U - an unsigned immediate offset.
328 The dots below the numbers indicate where hex digit boundaries
329 fall, to make it easier to check the numbers. */
331 /* Non-zero iff we've seen the instruction that initializes the
332 frame pointer for this function's frame. */
335 /* If fp_set is non_zero, then this is the distance from
336 the stack pointer to frame pointer: fp = sp + fp_offset. */
339 /* Total size of frame prior to any alloca operations. */
342 /* Flag indicating if lr has been saved on the stack. */
343 int lr_saved_on_stack = 0;
345 /* The number of the general-purpose register we saved the return
346 address ("link register") in, or -1 if we haven't moved it yet. */
347 int lr_save_reg = -1;
349 /* Offset (from sp) at which lr has been saved on the stack. */
351 int lr_sp_offset = 0;
353 /* If gr_saved[i] is non-zero, then we've noticed that general
354 register i has been saved at gr_sp_offset[i] from the stack
357 int gr_sp_offset[64];
359 memset (gr_saved, 0, sizeof (gr_saved));
361 while (! next_frame || pc < frame_pc_unwind (next_frame))
363 LONGEST op = read_memory_integer (pc, 4);
365 /* The tests in this chain of ifs should be in order of
366 decreasing selectivity, so that more particular patterns get
367 to fire before less particular patterns. */
369 /* Setting the FP from the SP:
371 P 000010 0100010 000001 000000000000 = 0x04881000
372 0 111111 1111111 111111 111111111111 = 0x7fffffff
374 We treat this as part of the prologue. */
375 if ((op & 0x7fffffff) == 0x04881000)
381 /* Move the link register to the scratch register grJ, before saving:
383 P 000100 0000011 010000 000111 JJJJJJ = 0x080d01c0
384 0 111111 1111111 111111 111111 000000 = 0x7fffffc0
386 We treat this as part of the prologue. */
387 else if ((op & 0x7fffffc0) == 0x080d01c0)
389 int gr_j = op & 0x3f;
391 /* If we're moving it to a scratch register, that's fine. */
392 if (is_caller_saves_reg (gr_j))
394 /* Otherwise it's not a prologue instruction that we
400 /* To save multiple callee-saves registers on the stack, at
404 P KKKKKK 0000011 000001 000011 000000 = 0x000c10c0
405 0 000000 1111111 111111 111111 111111 = 0x01ffffff
408 P KKKKKK 0000011 000001 000100 000000 = 0x000c1100
409 0 000000 1111111 111111 111111 111111 = 0x01ffffff
411 We treat this as part of the prologue, and record the register's
412 saved address in the frame structure. */
413 else if ((op & 0x01ffffff) == 0x000c10c0
414 || (op & 0x01ffffff) == 0x000c1100)
416 int gr_k = ((op >> 25) & 0x3f);
417 int ope = ((op >> 6) & 0x3f);
421 /* Is it an std or an stq? */
427 /* Is it really a callee-saves register? */
428 if (is_callee_saves_reg (gr_k))
430 for (i = 0; i < count; i++)
432 gr_saved[gr_k + i] = 1;
433 gr_sp_offset[gr_k + i] = 4 * i;
437 /* It's not a prologue instruction. */
441 /* Adjusting the stack pointer. (The stack pointer is GR1.)
443 P 000001 0010000 000001 SSSSSSSSSSSS = 0x02401000
444 0 111111 1111111 111111 000000000000 = 0x7ffff000
446 We treat this as part of the prologue. */
447 else if ((op & 0x7ffff000) == 0x02401000)
449 /* Sign-extend the twelve-bit field.
450 (Isn't there a better way to do this?) */
451 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800;
456 /* Setting the FP to a constant distance from the SP:
458 P 000010 0010000 000001 SSSSSSSSSSSS = 0x04401000
459 0 111111 1111111 111111 000000000000 = 0x7ffff000
461 We treat this as part of the prologue. */
462 else if ((op & 0x7ffff000) == 0x04401000)
464 /* Sign-extend the twelve-bit field.
465 (Isn't there a better way to do this?) */
466 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800;
471 /* To spill an argument register to a scratch register:
473 P KKKKKK 0100010 IIIIII 000000000000 = 0x00880000
474 0 000000 1111111 000000 111111111111 = 0x01fc0fff
476 For the time being, we treat this as a prologue instruction,
477 assuming that GRi is an argument register. This one's kind
478 of suspicious, because it seems like it could be part of a
479 legitimate body instruction. But we only come here when the
480 source info wasn't helpful, so we have to do the best we can.
481 Hopefully once GCC and GDB agree on how to emit line number
482 info for prologues, then this code will never come into play. */
483 else if ((op & 0x01fc0fff) == 0x00880000)
485 int gr_i = ((op >> 12) & 0x3f);
487 /* If the source isn't an arg register, then this isn't a
488 prologue instruction. */
489 if (! is_argument_reg (gr_i))
493 /* To spill 16-bit values to the stack:
495 P KKKKKK 1010001 000010 SSSSSSSSSSSS = 0x01442000
496 0 000000 1111111 111111 000000000000 = 0x01fff000
498 And for 8-bit values, we use STB instructions.
500 P KKKKKK 1010000 000010 SSSSSSSSSSSS = 0x01402000
501 0 000000 1111111 111111 000000000000 = 0x01fff000
503 We check that GRk is really an argument register, and treat
504 all such as part of the prologue. */
505 else if ( (op & 0x01fff000) == 0x01442000
506 || (op & 0x01fff000) == 0x01402000)
508 int gr_k = ((op >> 25) & 0x3f);
510 if (! is_argument_reg (gr_k))
511 break; /* Source isn't an arg register. */
514 /* To save multiple callee-saves register on the stack, at a
518 P KKKKKK 1010011 000001 SSSSSSSSSSSS = 0x014c1000
519 0 000000 1111111 111111 000000000000 = 0x01fff000
522 P KKKKKK 1010100 000001 SSSSSSSSSSSS = 0x01501000
523 0 000000 1111111 111111 000000000000 = 0x01fff000
525 We treat this as part of the prologue, and record the register's
526 saved address in the frame structure. */
527 else if ((op & 0x01fff000) == 0x014c1000
528 || (op & 0x01fff000) == 0x01501000)
530 int gr_k = ((op >> 25) & 0x3f);
534 /* Is it a stdi or a stqi? */
535 if ((op & 0x01fff000) == 0x014c1000)
540 /* Is it really a callee-saves register? */
541 if (is_callee_saves_reg (gr_k))
543 /* Sign-extend the twelve-bit field.
544 (Isn't there a better way to do this?) */
545 int s = (((op & 0xfff) - 0x800) & 0xfff) - 0x800;
547 for (i = 0; i < count; i++)
549 gr_saved[gr_k + i] = 1;
550 gr_sp_offset[gr_k + i] = s + (4 * i);
554 /* It's not a prologue instruction. */
558 /* Storing any kind of integer register at any constant offset
559 from any other register.
562 P KKKKKK 0000011 IIIIII 000010 000000 = 0x000c0080
563 0 000000 1111111 000000 111111 111111 = 0x01fc0fff
566 P KKKKKK 1010010 IIIIII SSSSSSSSSSSS = 0x01480000
567 0 000000 1111111 000000 000000000000 = 0x01fc0000
569 These could be almost anything, but a lot of prologue
570 instructions fall into this pattern, so let's decode the
571 instruction once, and then work at a higher level. */
572 else if (((op & 0x01fc0fff) == 0x000c0080)
573 || ((op & 0x01fc0000) == 0x01480000))
575 int gr_k = ((op >> 25) & 0x3f);
576 int gr_i = ((op >> 12) & 0x3f);
579 /* Are we storing with gr0 as an offset, or using an
581 if ((op & 0x01fc0fff) == 0x000c0080)
584 offset = (((op & 0xfff) - 0x800) & 0xfff) - 0x800;
586 /* If the address isn't relative to the SP or FP, it's not a
587 prologue instruction. */
588 if (gr_i != sp_regnum && gr_i != fp_regnum)
591 /* Saving the old FP in the new frame (relative to the SP). */
592 if (gr_k == fp_regnum && gr_i == sp_regnum)
594 gr_saved[fp_regnum] = 1;
595 gr_sp_offset[fp_regnum] = offset;
598 /* Saving callee-saves register(s) on the stack, relative to
600 else if (gr_i == sp_regnum
601 && is_callee_saves_reg (gr_k))
604 if (gr_i == sp_regnum)
605 gr_sp_offset[gr_k] = offset;
607 gr_sp_offset[gr_k] = offset + fp_offset;
610 /* Saving the scratch register holding the return address. */
611 else if (lr_save_reg != -1
612 && gr_k == lr_save_reg)
614 lr_saved_on_stack = 1;
615 if (gr_i == sp_regnum)
616 lr_sp_offset = offset;
618 lr_sp_offset = offset + fp_offset;
621 /* Spilling int-sized arguments to the stack. */
622 else if (is_argument_reg (gr_k))
625 /* It's not a store instruction we recognize, so this must
626 be the end of the prologue. */
631 /* It's not any instruction we recognize, so this must be the end
639 if (next_frame && info)
644 /* If we know the relationship between the stack and frame
645 pointers, record the addresses of the registers we noticed.
646 Note that we have to do this as a separate step at the end,
647 because instructions may save relative to the SP, but we need
648 their addresses relative to the FP. */
650 frame_unwind_unsigned_register (next_frame, fp_regnum, &this_base);
652 frame_unwind_unsigned_register (next_frame, sp_regnum, &this_base);
654 for (i = 0; i < 64; i++)
656 info->saved_regs[i].addr = this_base - fp_offset + gr_sp_offset[i];
658 info->prev_sp = this_base - fp_offset + framesize;
659 info->base = this_base;
661 /* If LR was saved on the stack, record its location. */
662 if (lr_saved_on_stack)
663 info->saved_regs[lr_regnum].addr = this_base - fp_offset + lr_sp_offset;
665 /* The call instruction moves the caller's PC in the callee's LR.
666 Since this is an unwind, do the reverse. Copy the location of LR
667 into PC (the address / regnum) so that a request for PC will be
668 converted into a request for the LR. */
669 info->saved_regs[pc_regnum] = info->saved_regs[lr_regnum];
671 /* Save the previous frame's computed SP value. */
672 trad_frame_set_value (info->saved_regs, sp_regnum, info->prev_sp);
680 frv_skip_prologue (CORE_ADDR pc)
682 CORE_ADDR func_addr, func_end, new_pc;
686 /* If the line table has entry for a line *within* the function
687 (i.e., not in the prologue, and not past the end), then that's
689 if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
691 struct symtab_and_line sal;
693 sal = find_pc_line (func_addr, 0);
695 if (sal.line != 0 && sal.end < func_end)
701 /* The FR-V prologue is at least five instructions long (twenty bytes).
702 If we didn't find a real source location past that, then
703 do a full analysis of the prologue. */
704 if (new_pc < pc + 20)
705 new_pc = frv_analyze_prologue (pc, 0, 0);
711 static struct frv_unwind_cache *
712 frv_frame_unwind_cache (struct frame_info *next_frame,
713 void **this_prologue_cache)
715 struct gdbarch *gdbarch = get_frame_arch (next_frame);
719 struct frv_unwind_cache *info;
721 if ((*this_prologue_cache))
722 return (*this_prologue_cache);
724 info = FRAME_OBSTACK_ZALLOC (struct frv_unwind_cache);
725 (*this_prologue_cache) = info;
726 info->saved_regs = trad_frame_alloc_saved_regs (next_frame);
728 /* Prologue analysis does the rest... */
729 frv_analyze_prologue (frame_func_unwind (next_frame), next_frame, info);
735 frv_extract_return_value (struct type *type, char *regbuf, char *valbuf)
737 memcpy (valbuf, (regbuf
738 + frv_register_byte (8)
739 + (TYPE_LENGTH (type) < 4 ? 4 - TYPE_LENGTH (type) : 0)),
744 frv_extract_struct_value_address (char *regbuf)
746 return extract_unsigned_integer (regbuf +
747 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);
763 #define ROUND_UP(n,a) (((n)+(a)-1) & ~((a)-1))
764 #define ROUND_DOWN(n,a) ((n) & ~((a)-1))
767 frv_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
769 /* Require dword alignment. */
770 return ROUND_DOWN (sp, 8);
774 frv_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
775 struct regcache *regcache, CORE_ADDR bp_addr,
776 int nargs, struct value **args, CORE_ADDR sp,
777 int struct_return, CORE_ADDR struct_addr)
784 struct type *arg_type;
786 enum type_code typecode;
792 printf("Push %d args at sp = %x, struct_return=%d (%x)\n",
793 nargs, (int) sp, struct_return, struct_addr);
797 for (argnum = 0; argnum < nargs; ++argnum)
798 stack_space += ROUND_UP (TYPE_LENGTH (VALUE_TYPE (args[argnum])), 4);
800 stack_space -= (6 * 4);
804 /* Make sure stack is dword aligned. */
805 sp = ROUND_DOWN (sp, 8);
812 regcache_cooked_write_unsigned (regcache, struct_return_regnum,
815 for (argnum = 0; argnum < nargs; ++argnum)
818 arg_type = check_typedef (VALUE_TYPE (arg));
819 len = TYPE_LENGTH (arg_type);
820 typecode = TYPE_CODE (arg_type);
822 if (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION)
824 store_unsigned_integer (valbuf, 4, VALUE_ADDRESS (arg));
825 typecode = TYPE_CODE_PTR;
831 val = (char *) VALUE_CONTENTS (arg);
836 int partial_len = (len < 4 ? len : 4);
840 regval = extract_unsigned_integer (val, partial_len);
842 printf(" Argnum %d data %x -> reg %d\n",
843 argnum, (int) regval, argreg);
845 regcache_cooked_write_unsigned (regcache, argreg, regval);
851 printf(" Argnum %d data %x -> offset %d (%x)\n",
852 argnum, *((int *)val), stack_offset, (int) (sp + stack_offset));
854 write_memory (sp + stack_offset, val, partial_len);
855 stack_offset += ROUND_UP(partial_len, 4);
862 /* Set the return address. For the frv, the return breakpoint is
863 always at BP_ADDR. */
864 regcache_cooked_write_unsigned (regcache, lr_regnum, bp_addr);
866 /* Finally, update the SP register. */
867 regcache_cooked_write_unsigned (regcache, sp_regnum, sp);
873 frv_store_return_value (struct type *type, char *valbuf)
875 int length = TYPE_LENGTH (type);
876 int reg8_offset = frv_register_byte (8);
879 deprecated_write_register_bytes (reg8_offset + (4 - length), valbuf,
881 else if (length == 8)
882 deprecated_write_register_bytes (reg8_offset, valbuf, length);
884 internal_error (__FILE__, __LINE__,
885 "Don't know how to return a %d-byte value.", length);
889 /* Hardware watchpoint / breakpoint support for the FR500
893 frv_check_watch_resources (int type, int cnt, int ot)
895 struct gdbarch_tdep *var = CURRENT_VARIANT;
897 /* Watchpoints not supported on simulator. */
898 if (strcmp (target_shortname, "sim") == 0)
901 if (type == bp_hardware_breakpoint)
903 if (var->num_hw_breakpoints == 0)
905 else if (cnt <= var->num_hw_breakpoints)
910 if (var->num_hw_watchpoints == 0)
914 else if (cnt <= var->num_hw_watchpoints)
922 frv_stopped_data_address (void)
924 CORE_ADDR brr, dbar0, dbar1, dbar2, dbar3;
926 brr = read_register (brr_regnum);
927 dbar0 = read_register (dbar0_regnum);
928 dbar1 = read_register (dbar1_regnum);
929 dbar2 = read_register (dbar2_regnum);
930 dbar3 = read_register (dbar3_regnum);
934 else if (brr & (1<<10))
936 else if (brr & (1<<9))
938 else if (brr & (1<<8))
945 frv_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
947 return frame_unwind_register_unsigned (next_frame, pc_regnum);
950 /* Given a GDB frame, determine the address of the calling function's
951 frame. This will be used to create a new GDB frame struct. */
954 frv_frame_this_id (struct frame_info *next_frame,
955 void **this_prologue_cache, struct frame_id *this_id)
957 struct frv_unwind_cache *info
958 = frv_frame_unwind_cache (next_frame, this_prologue_cache);
961 struct minimal_symbol *msym_stack;
964 /* The FUNC is easy. */
965 func = frame_func_unwind (next_frame);
967 /* This is meant to halt the backtrace at "_start". Make sure we
968 don't halt it at a generic dummy frame. */
969 if (inside_entry_file (func))
972 /* Check if the stack is empty. */
973 msym_stack = lookup_minimal_symbol ("_stack", NULL, NULL);
974 if (msym_stack && info->base == SYMBOL_VALUE_ADDRESS (msym_stack))
977 /* Hopefully the prologue analysis either correctly determined the
978 frame's base (which is the SP from the previous frame), or set
979 that base to "NULL". */
980 base = info->prev_sp;
984 id = frame_id_build (base, func);
986 /* Check that we're not going round in circles with the same frame
987 ID (but avoid applying the test to sentinel frames which do go
988 round in circles). Can't use frame_id_eq() as that doesn't yet
989 compare the frame's PC value. */
990 if (frame_relative_level (next_frame) >= 0
991 && get_frame_type (next_frame) != DUMMY_FRAME
992 && frame_id_eq (get_frame_id (next_frame), id))
999 frv_frame_prev_register (struct frame_info *next_frame,
1000 void **this_prologue_cache,
1001 int regnum, int *optimizedp,
1002 enum lval_type *lvalp, CORE_ADDR *addrp,
1003 int *realnump, void *bufferp)
1005 struct frv_unwind_cache *info
1006 = frv_frame_unwind_cache (next_frame, this_prologue_cache);
1007 trad_frame_prev_register (next_frame, info->saved_regs, regnum,
1008 optimizedp, lvalp, addrp, realnump, bufferp);
1011 static const struct frame_unwind frv_frame_unwind = {
1014 frv_frame_prev_register
1017 static const struct frame_unwind *
1018 frv_frame_sniffer (struct frame_info *next_frame)
1020 return &frv_frame_unwind;
1024 frv_frame_base_address (struct frame_info *next_frame, void **this_cache)
1026 struct frv_unwind_cache *info
1027 = frv_frame_unwind_cache (next_frame, this_cache);
1031 static const struct frame_base frv_frame_base = {
1033 frv_frame_base_address,
1034 frv_frame_base_address,
1035 frv_frame_base_address
1039 frv_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1041 return frame_unwind_register_unsigned (next_frame, sp_regnum);
1045 /* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
1046 dummy frame. The frame ID's base needs to match the TOS value
1047 saved by save_dummy_frame_tos(), and the PC match the dummy frame's
1050 static struct frame_id
1051 frv_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
1053 return frame_id_build (frv_unwind_sp (gdbarch, next_frame),
1054 frame_pc_unwind (next_frame));
1058 static struct gdbarch *
1059 frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1061 struct gdbarch *gdbarch;
1062 struct gdbarch_tdep *var;
1064 /* Check to see if we've already built an appropriate architecture
1065 object for this executable. */
1066 arches = gdbarch_list_lookup_by_info (arches, &info);
1068 return arches->gdbarch;
1070 /* Select the right tdep structure for this variant. */
1071 var = new_variant ();
1072 switch (info.bfd_arch_info->mach)
1075 case bfd_mach_frvsimple:
1076 case bfd_mach_fr500:
1077 case bfd_mach_frvtomcat:
1078 set_variant_num_gprs (var, 64);
1079 set_variant_num_fprs (var, 64);
1082 case bfd_mach_fr400:
1083 set_variant_num_gprs (var, 32);
1084 set_variant_num_fprs (var, 32);
1088 /* Never heard of this variant. */
1092 gdbarch = gdbarch_alloc (&info, var);
1094 set_gdbarch_short_bit (gdbarch, 16);
1095 set_gdbarch_int_bit (gdbarch, 32);
1096 set_gdbarch_long_bit (gdbarch, 32);
1097 set_gdbarch_long_long_bit (gdbarch, 64);
1098 set_gdbarch_float_bit (gdbarch, 32);
1099 set_gdbarch_double_bit (gdbarch, 64);
1100 set_gdbarch_long_double_bit (gdbarch, 64);
1101 set_gdbarch_ptr_bit (gdbarch, 32);
1103 set_gdbarch_num_regs (gdbarch, frv_num_regs);
1104 set_gdbarch_sp_regnum (gdbarch, sp_regnum);
1105 set_gdbarch_deprecated_fp_regnum (gdbarch, fp_regnum);
1106 set_gdbarch_pc_regnum (gdbarch, pc_regnum);
1108 set_gdbarch_register_name (gdbarch, frv_register_name);
1109 set_gdbarch_deprecated_register_size (gdbarch, 4);
1110 set_gdbarch_deprecated_register_bytes (gdbarch, frv_num_regs * 4);
1111 set_gdbarch_deprecated_register_byte (gdbarch, frv_register_byte);
1112 set_gdbarch_deprecated_register_raw_size (gdbarch, frv_register_raw_size);
1113 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 4);
1114 set_gdbarch_deprecated_register_virtual_size (gdbarch, frv_register_virtual_size);
1115 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 4);
1116 set_gdbarch_deprecated_register_virtual_type (gdbarch, frv_register_virtual_type);
1118 set_gdbarch_skip_prologue (gdbarch, frv_skip_prologue);
1119 set_gdbarch_breakpoint_from_pc (gdbarch, frv_breakpoint_from_pc);
1121 set_gdbarch_frame_args_skip (gdbarch, 0);
1122 set_gdbarch_frameless_function_invocation (gdbarch, frv_frameless_function_invocation);
1124 set_gdbarch_use_struct_convention (gdbarch, always_use_struct_convention);
1125 set_gdbarch_deprecated_extract_return_value (gdbarch, frv_extract_return_value);
1127 set_gdbarch_deprecated_store_struct_return (gdbarch, frv_store_struct_return);
1128 set_gdbarch_deprecated_store_return_value (gdbarch, frv_store_return_value);
1129 set_gdbarch_deprecated_extract_struct_value_address (gdbarch, frv_extract_struct_value_address);
1132 set_gdbarch_unwind_pc (gdbarch, frv_unwind_pc);
1133 set_gdbarch_unwind_sp (gdbarch, frv_unwind_sp);
1134 set_gdbarch_frame_align (gdbarch, frv_frame_align);
1135 frame_unwind_append_sniffer (gdbarch, frv_frame_sniffer);
1136 frame_base_set_default (gdbarch, &frv_frame_base);
1138 /* Settings for calling functions in the inferior. */
1139 set_gdbarch_push_dummy_call (gdbarch, frv_push_dummy_call);
1140 set_gdbarch_unwind_dummy_id (gdbarch, frv_unwind_dummy_id);
1142 /* Settings that should be unnecessary. */
1143 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1145 set_gdbarch_write_pc (gdbarch, generic_target_write_pc);
1147 set_gdbarch_decr_pc_after_break (gdbarch, 0);
1148 set_gdbarch_function_start_offset (gdbarch, 0);
1150 set_gdbarch_remote_translate_xfer_address
1151 (gdbarch, generic_remote_translate_xfer_address);
1153 /* Hardware watchpoint / breakpoint support. */
1154 switch (info.bfd_arch_info->mach)
1157 case bfd_mach_frvsimple:
1158 case bfd_mach_fr500:
1159 case bfd_mach_frvtomcat:
1160 /* fr500-style hardware debugging support. */
1161 var->num_hw_watchpoints = 4;
1162 var->num_hw_breakpoints = 4;
1165 case bfd_mach_fr400:
1166 /* fr400-style hardware debugging support. */
1167 var->num_hw_watchpoints = 2;
1168 var->num_hw_breakpoints = 4;
1172 /* Otherwise, assume we don't have hardware debugging support. */
1173 var->num_hw_watchpoints = 0;
1174 var->num_hw_breakpoints = 0;
1178 set_gdbarch_print_insn (gdbarch, print_insn_frv);
1184 _initialize_frv_tdep (void)
1186 register_gdbarch_init (bfd_arch_frv, frv_gdbarch_init);