1 /* SPU target-dependent code for GDB, the GNU debugger.
2 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
27 #include "gdb_string.h"
28 #include "gdb_assert.h"
30 #include "frame-unwind.h"
31 #include "frame-base.h"
32 #include "trad-frame.h"
41 #include "reggroups.h"
42 #include "floatformat.h"
49 /* The list of available "set spu " and "show spu " commands. */
50 static struct cmd_list_element *setspucmdlist = NULL;
51 static struct cmd_list_element *showspucmdlist = NULL;
53 /* Whether to stop for new SPE contexts. */
54 static int spu_stop_on_load_p = 0;
57 /* The tdep structure. */
60 /* The spufs ID identifying our address space. */
63 /* SPU-specific vector type. */
64 struct type *spu_builtin_type_vec128;
68 /* SPU-specific vector type. */
70 spu_builtin_type_vec128 (struct gdbarch *gdbarch)
72 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
74 if (!tdep->spu_builtin_type_vec128)
76 const struct builtin_type *bt = builtin_type (gdbarch);
79 t = arch_composite_type (gdbarch,
80 "__spu_builtin_type_vec128", TYPE_CODE_UNION);
81 append_composite_type_field (t, "uint128", bt->builtin_int128);
82 append_composite_type_field (t, "v2_int64",
83 init_vector_type (bt->builtin_int64, 2));
84 append_composite_type_field (t, "v4_int32",
85 init_vector_type (bt->builtin_int32, 4));
86 append_composite_type_field (t, "v8_int16",
87 init_vector_type (bt->builtin_int16, 8));
88 append_composite_type_field (t, "v16_int8",
89 init_vector_type (bt->builtin_int8, 16));
90 append_composite_type_field (t, "v2_double",
91 init_vector_type (bt->builtin_double, 2));
92 append_composite_type_field (t, "v4_float",
93 init_vector_type (bt->builtin_float, 4));
96 TYPE_NAME (t) = "spu_builtin_type_vec128";
98 tdep->spu_builtin_type_vec128 = t;
101 return tdep->spu_builtin_type_vec128;
105 /* The list of available "info spu " commands. */
106 static struct cmd_list_element *infospucmdlist = NULL;
111 spu_register_name (struct gdbarch *gdbarch, int reg_nr)
113 static char *register_names[] =
115 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
116 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
117 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
118 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
119 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
120 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
121 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
122 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
123 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
124 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
125 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
126 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
127 "r96", "r97", "r98", "r99", "r100", "r101", "r102", "r103",
128 "r104", "r105", "r106", "r107", "r108", "r109", "r110", "r111",
129 "r112", "r113", "r114", "r115", "r116", "r117", "r118", "r119",
130 "r120", "r121", "r122", "r123", "r124", "r125", "r126", "r127",
131 "id", "pc", "sp", "fpscr", "srr0", "lslr", "decr", "decr_status"
136 if (reg_nr >= sizeof register_names / sizeof *register_names)
139 return register_names[reg_nr];
143 spu_register_type (struct gdbarch *gdbarch, int reg_nr)
145 if (reg_nr < SPU_NUM_GPRS)
146 return spu_builtin_type_vec128 (gdbarch);
151 return builtin_type (gdbarch)->builtin_uint32;
154 return builtin_type (gdbarch)->builtin_func_ptr;
157 return builtin_type (gdbarch)->builtin_data_ptr;
159 case SPU_FPSCR_REGNUM:
160 return builtin_type (gdbarch)->builtin_uint128;
162 case SPU_SRR0_REGNUM:
163 return builtin_type (gdbarch)->builtin_uint32;
165 case SPU_LSLR_REGNUM:
166 return builtin_type (gdbarch)->builtin_uint32;
168 case SPU_DECR_REGNUM:
169 return builtin_type (gdbarch)->builtin_uint32;
171 case SPU_DECR_STATUS_REGNUM:
172 return builtin_type (gdbarch)->builtin_uint32;
175 internal_error (__FILE__, __LINE__, "invalid regnum");
179 /* Pseudo registers for preferred slots - stack pointer. */
182 spu_pseudo_register_read_spu (struct regcache *regcache, const char *regname,
185 struct gdbarch *gdbarch = get_regcache_arch (regcache);
186 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
191 regcache_raw_read_unsigned (regcache, SPU_ID_REGNUM, &id);
192 xsnprintf (annex, sizeof annex, "%d/%s", (int) id, regname);
193 memset (reg, 0, sizeof reg);
194 target_read (¤t_target, TARGET_OBJECT_SPU, annex,
197 store_unsigned_integer (buf, 4, byte_order, strtoulst (reg, NULL, 16));
201 spu_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache,
202 int regnum, gdb_byte *buf)
211 regcache_raw_read (regcache, SPU_RAW_SP_REGNUM, reg);
212 memcpy (buf, reg, 4);
215 case SPU_FPSCR_REGNUM:
216 regcache_raw_read_unsigned (regcache, SPU_ID_REGNUM, &id);
217 xsnprintf (annex, sizeof annex, "%d/fpcr", (int) id);
218 target_read (¤t_target, TARGET_OBJECT_SPU, annex, buf, 0, 16);
221 case SPU_SRR0_REGNUM:
222 spu_pseudo_register_read_spu (regcache, "srr0", buf);
225 case SPU_LSLR_REGNUM:
226 spu_pseudo_register_read_spu (regcache, "lslr", buf);
229 case SPU_DECR_REGNUM:
230 spu_pseudo_register_read_spu (regcache, "decr", buf);
233 case SPU_DECR_STATUS_REGNUM:
234 spu_pseudo_register_read_spu (regcache, "decr_status", buf);
238 internal_error (__FILE__, __LINE__, _("invalid regnum"));
243 spu_pseudo_register_write_spu (struct regcache *regcache, const char *regname,
246 struct gdbarch *gdbarch = get_regcache_arch (regcache);
247 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
252 regcache_raw_read_unsigned (regcache, SPU_ID_REGNUM, &id);
253 xsnprintf (annex, sizeof annex, "%d/%s", (int) id, regname);
254 xsnprintf (reg, sizeof reg, "0x%s",
255 phex_nz (extract_unsigned_integer (buf, 4, byte_order), 4));
256 target_write (¤t_target, TARGET_OBJECT_SPU, annex,
257 reg, 0, strlen (reg));
261 spu_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
262 int regnum, const gdb_byte *buf)
271 regcache_raw_read (regcache, SPU_RAW_SP_REGNUM, reg);
272 memcpy (reg, buf, 4);
273 regcache_raw_write (regcache, SPU_RAW_SP_REGNUM, reg);
276 case SPU_FPSCR_REGNUM:
277 regcache_raw_read_unsigned (regcache, SPU_ID_REGNUM, &id);
278 xsnprintf (annex, sizeof annex, "%d/fpcr", (int) id);
279 target_write (¤t_target, TARGET_OBJECT_SPU, annex, buf, 0, 16);
282 case SPU_SRR0_REGNUM:
283 spu_pseudo_register_write_spu (regcache, "srr0", buf);
286 case SPU_LSLR_REGNUM:
287 spu_pseudo_register_write_spu (regcache, "lslr", buf);
290 case SPU_DECR_REGNUM:
291 spu_pseudo_register_write_spu (regcache, "decr", buf);
294 case SPU_DECR_STATUS_REGNUM:
295 spu_pseudo_register_write_spu (regcache, "decr_status", buf);
299 internal_error (__FILE__, __LINE__, _("invalid regnum"));
303 /* Value conversion -- access scalar values at the preferred slot. */
305 static struct value *
306 spu_value_from_register (struct type *type, int regnum,
307 struct frame_info *frame)
309 struct value *value = default_value_from_register (type, regnum, frame);
310 int len = TYPE_LENGTH (type);
312 if (regnum < SPU_NUM_GPRS && len < 16)
314 int preferred_slot = len < 4 ? 4 - len : 0;
315 set_value_offset (value, preferred_slot);
321 /* Register groups. */
324 spu_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
325 struct reggroup *group)
327 /* Registers displayed via 'info regs'. */
328 if (group == general_reggroup)
331 /* Registers displayed via 'info float'. */
332 if (group == float_reggroup)
335 /* Registers that need to be saved/restored in order to
336 push or pop frames. */
337 if (group == save_reggroup || group == restore_reggroup)
340 return default_register_reggroup_p (gdbarch, regnum, group);
343 /* Address conversion. */
346 spu_gdbarch_id (struct gdbarch *gdbarch)
348 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
351 /* The objfile architecture of a standalone SPU executable does not
352 provide an SPU ID. Retrieve it from the the objfile's relocated
353 address range in this special case. */
355 && symfile_objfile && symfile_objfile->obfd
356 && bfd_get_arch (symfile_objfile->obfd) == bfd_arch_spu
357 && symfile_objfile->sections != symfile_objfile->sections_end)
358 id = SPUADDR_SPU (obj_section_addr (symfile_objfile->sections));
370 return SPU_LS_SIZE - 1;
372 xsnprintf (annex, sizeof annex, "%d/lslr", id);
373 memset (buf, 0, sizeof buf);
374 target_read (¤t_target, TARGET_OBJECT_SPU, annex,
377 return strtoulst (buf, NULL, 16);
381 spu_address_to_pointer (struct gdbarch *gdbarch,
382 struct type *type, gdb_byte *buf, CORE_ADDR addr)
384 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
385 store_unsigned_integer (buf, TYPE_LENGTH (type), byte_order,
386 SPUADDR_ADDR (addr));
390 spu_pointer_to_address (struct gdbarch *gdbarch,
391 struct type *type, const gdb_byte *buf)
393 int id = spu_gdbarch_id (gdbarch);
394 ULONGEST lslr = spu_lslr (id);
395 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
397 = extract_unsigned_integer (buf, TYPE_LENGTH (type), byte_order);
399 return addr? SPUADDR (id, addr & lslr) : 0;
403 spu_integer_to_address (struct gdbarch *gdbarch,
404 struct type *type, const gdb_byte *buf)
406 int id = spu_gdbarch_id (gdbarch);
407 ULONGEST lslr = spu_lslr (id);
408 ULONGEST addr = unpack_long (type, buf);
410 return SPUADDR (id, addr & lslr);
414 /* Decoding SPU instructions. */
451 is_rr (unsigned int insn, int op, int *rt, int *ra, int *rb)
453 if ((insn >> 21) == op)
456 *ra = (insn >> 7) & 127;
457 *rb = (insn >> 14) & 127;
465 is_rrr (unsigned int insn, int op, int *rt, int *ra, int *rb, int *rc)
467 if ((insn >> 28) == op)
469 *rt = (insn >> 21) & 127;
470 *ra = (insn >> 7) & 127;
471 *rb = (insn >> 14) & 127;
480 is_ri7 (unsigned int insn, int op, int *rt, int *ra, int *i7)
482 if ((insn >> 21) == op)
485 *ra = (insn >> 7) & 127;
486 *i7 = (((insn >> 14) & 127) ^ 0x40) - 0x40;
494 is_ri10 (unsigned int insn, int op, int *rt, int *ra, int *i10)
496 if ((insn >> 24) == op)
499 *ra = (insn >> 7) & 127;
500 *i10 = (((insn >> 14) & 0x3ff) ^ 0x200) - 0x200;
508 is_ri16 (unsigned int insn, int op, int *rt, int *i16)
510 if ((insn >> 23) == op)
513 *i16 = (((insn >> 7) & 0xffff) ^ 0x8000) - 0x8000;
521 is_ri18 (unsigned int insn, int op, int *rt, int *i18)
523 if ((insn >> 25) == op)
526 *i18 = (((insn >> 7) & 0x3ffff) ^ 0x20000) - 0x20000;
534 is_branch (unsigned int insn, int *offset, int *reg)
538 if (is_ri16 (insn, op_br, &rt, &i16)
539 || is_ri16 (insn, op_brsl, &rt, &i16)
540 || is_ri16 (insn, op_brnz, &rt, &i16)
541 || is_ri16 (insn, op_brz, &rt, &i16)
542 || is_ri16 (insn, op_brhnz, &rt, &i16)
543 || is_ri16 (insn, op_brhz, &rt, &i16))
545 *reg = SPU_PC_REGNUM;
550 if (is_ri16 (insn, op_bra, &rt, &i16)
551 || is_ri16 (insn, op_brasl, &rt, &i16))
558 if (is_ri7 (insn, op_bi, &rt, reg, &i7)
559 || is_ri7 (insn, op_bisl, &rt, reg, &i7)
560 || is_ri7 (insn, op_biz, &rt, reg, &i7)
561 || is_ri7 (insn, op_binz, &rt, reg, &i7)
562 || is_ri7 (insn, op_bihz, &rt, reg, &i7)
563 || is_ri7 (insn, op_bihnz, &rt, reg, &i7))
573 /* Prolog parsing. */
575 struct spu_prologue_data
577 /* Stack frame size. -1 if analysis was unsuccessful. */
580 /* How to find the CFA. The CFA is equal to SP at function entry. */
584 /* Offset relative to CFA where a register is saved. -1 if invalid. */
585 int reg_offset[SPU_NUM_GPRS];
589 spu_analyze_prologue (struct gdbarch *gdbarch,
590 CORE_ADDR start_pc, CORE_ADDR end_pc,
591 struct spu_prologue_data *data)
593 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
597 int reg_immed[SPU_NUM_GPRS];
599 CORE_ADDR prolog_pc = start_pc;
604 /* Initialize DATA to default values. */
607 data->cfa_reg = SPU_RAW_SP_REGNUM;
608 data->cfa_offset = 0;
610 for (i = 0; i < SPU_NUM_GPRS; i++)
611 data->reg_offset[i] = -1;
613 /* Set up REG_IMMED array. This is non-zero for a register if we know its
614 preferred slot currently holds this immediate value. */
615 for (i = 0; i < SPU_NUM_GPRS; i++)
618 /* Scan instructions until the first branch.
620 The following instructions are important prolog components:
622 - The first instruction to set up the stack pointer.
623 - The first instruction to set up the frame pointer.
624 - The first instruction to save the link register.
626 We return the instruction after the latest of these three,
627 or the incoming PC if none is found. The first instruction
628 to set up the stack pointer also defines the frame size.
630 Note that instructions saving incoming arguments to their stack
631 slots are not counted as important, because they are hard to
632 identify with certainty. This should not matter much, because
633 arguments are relevant only in code compiled with debug data,
634 and in such code the GDB core will advance until the first source
635 line anyway, using SAL data.
637 For purposes of stack unwinding, we analyze the following types
638 of instructions in addition:
640 - Any instruction adding to the current frame pointer.
641 - Any instruction loading an immediate constant into a register.
642 - Any instruction storing a register onto the stack.
644 These are used to compute the CFA and REG_OFFSET output. */
646 for (pc = start_pc; pc < end_pc; pc += 4)
649 int rt, ra, rb, rc, immed;
651 if (target_read_memory (pc, buf, 4))
653 insn = extract_unsigned_integer (buf, 4, byte_order);
655 /* AI is the typical instruction to set up a stack frame.
656 It is also used to initialize the frame pointer. */
657 if (is_ri10 (insn, op_ai, &rt, &ra, &immed))
659 if (rt == data->cfa_reg && ra == data->cfa_reg)
660 data->cfa_offset -= immed;
662 if (rt == SPU_RAW_SP_REGNUM && ra == SPU_RAW_SP_REGNUM
670 else if (rt == SPU_FP_REGNUM && ra == SPU_RAW_SP_REGNUM
676 data->cfa_reg = SPU_FP_REGNUM;
677 data->cfa_offset -= immed;
681 /* A is used to set up stack frames of size >= 512 bytes.
682 If we have tracked the contents of the addend register,
683 we can handle this as well. */
684 else if (is_rr (insn, op_a, &rt, &ra, &rb))
686 if (rt == data->cfa_reg && ra == data->cfa_reg)
688 if (reg_immed[rb] != 0)
689 data->cfa_offset -= reg_immed[rb];
691 data->cfa_reg = -1; /* We don't know the CFA any more. */
694 if (rt == SPU_RAW_SP_REGNUM && ra == SPU_RAW_SP_REGNUM
700 if (reg_immed[rb] != 0)
701 data->size = -reg_immed[rb];
705 /* We need to track IL and ILA used to load immediate constants
706 in case they are later used as input to an A instruction. */
707 else if (is_ri16 (insn, op_il, &rt, &immed))
709 reg_immed[rt] = immed;
711 if (rt == SPU_RAW_SP_REGNUM && !found_sp)
715 else if (is_ri18 (insn, op_ila, &rt, &immed))
717 reg_immed[rt] = immed & 0x3ffff;
719 if (rt == SPU_RAW_SP_REGNUM && !found_sp)
723 /* STQD is used to save registers to the stack. */
724 else if (is_ri10 (insn, op_stqd, &rt, &ra, &immed))
726 if (ra == data->cfa_reg)
727 data->reg_offset[rt] = data->cfa_offset - (immed << 4);
729 if (ra == data->cfa_reg && rt == SPU_LR_REGNUM
737 /* _start uses SELB to set up the stack pointer. */
738 else if (is_rrr (insn, op_selb, &rt, &ra, &rb, &rc))
740 if (rt == SPU_RAW_SP_REGNUM && !found_sp)
744 /* We terminate if we find a branch. */
745 else if (is_branch (insn, &immed, &ra))
750 /* If we successfully parsed until here, and didn't find any instruction
751 modifying SP, we assume we have a frameless function. */
755 /* Return cooked instead of raw SP. */
756 if (data->cfa_reg == SPU_RAW_SP_REGNUM)
757 data->cfa_reg = SPU_SP_REGNUM;
762 /* Return the first instruction after the prologue starting at PC. */
764 spu_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
766 struct spu_prologue_data data;
767 return spu_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data);
770 /* Return the frame pointer in use at address PC. */
772 spu_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc,
773 int *reg, LONGEST *offset)
775 struct spu_prologue_data data;
776 spu_analyze_prologue (gdbarch, pc, (CORE_ADDR)-1, &data);
778 if (data.size != -1 && data.cfa_reg != -1)
780 /* The 'frame pointer' address is CFA minus frame size. */
782 *offset = data.cfa_offset - data.size;
786 /* ??? We don't really know ... */
787 *reg = SPU_SP_REGNUM;
792 /* Return true if we are in the function's epilogue, i.e. after the
793 instruction that destroyed the function's stack frame.
795 1) scan forward from the point of execution:
796 a) If you find an instruction that modifies the stack pointer
797 or transfers control (except a return), execution is not in
799 b) Stop scanning if you find a return instruction or reach the
800 end of the function or reach the hard limit for the size of
802 2) scan backward from the point of execution:
803 a) If you find an instruction that modifies the stack pointer,
804 execution *is* in an epilogue, return.
805 b) Stop scanning if you reach an instruction that transfers
806 control or the beginning of the function or reach the hard
807 limit for the size of an epilogue. */
810 spu_in_function_epilogue_p (struct gdbarch *gdbarch, CORE_ADDR pc)
812 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
813 CORE_ADDR scan_pc, func_start, func_end, epilogue_start, epilogue_end;
816 int rt, ra, rb, rc, immed;
818 /* Find the search limits based on function boundaries and hard limit.
819 We assume the epilogue can be up to 64 instructions long. */
821 const int spu_max_epilogue_size = 64 * 4;
823 if (!find_pc_partial_function (pc, NULL, &func_start, &func_end))
826 if (pc - func_start < spu_max_epilogue_size)
827 epilogue_start = func_start;
829 epilogue_start = pc - spu_max_epilogue_size;
831 if (func_end - pc < spu_max_epilogue_size)
832 epilogue_end = func_end;
834 epilogue_end = pc + spu_max_epilogue_size;
836 /* Scan forward until next 'bi $0'. */
838 for (scan_pc = pc; scan_pc < epilogue_end; scan_pc += 4)
840 if (target_read_memory (scan_pc, buf, 4))
842 insn = extract_unsigned_integer (buf, 4, byte_order);
844 if (is_branch (insn, &immed, &ra))
846 if (immed == 0 && ra == SPU_LR_REGNUM)
852 if (is_ri10 (insn, op_ai, &rt, &ra, &immed)
853 || is_rr (insn, op_a, &rt, &ra, &rb)
854 || is_ri10 (insn, op_lqd, &rt, &ra, &immed))
856 if (rt == SPU_RAW_SP_REGNUM)
861 if (scan_pc >= epilogue_end)
864 /* Scan backward until adjustment to stack pointer (R1). */
866 for (scan_pc = pc - 4; scan_pc >= epilogue_start; scan_pc -= 4)
868 if (target_read_memory (scan_pc, buf, 4))
870 insn = extract_unsigned_integer (buf, 4, byte_order);
872 if (is_branch (insn, &immed, &ra))
875 if (is_ri10 (insn, op_ai, &rt, &ra, &immed)
876 || is_rr (insn, op_a, &rt, &ra, &rb)
877 || is_ri10 (insn, op_lqd, &rt, &ra, &immed))
879 if (rt == SPU_RAW_SP_REGNUM)
888 /* Normal stack frames. */
890 struct spu_unwind_cache
893 CORE_ADDR frame_base;
894 CORE_ADDR local_base;
896 struct trad_frame_saved_reg *saved_regs;
899 static struct spu_unwind_cache *
900 spu_frame_unwind_cache (struct frame_info *this_frame,
901 void **this_prologue_cache)
903 struct gdbarch *gdbarch = get_frame_arch (this_frame);
904 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
905 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
906 struct spu_unwind_cache *info;
907 struct spu_prologue_data data;
908 CORE_ADDR id = tdep->id;
911 if (*this_prologue_cache)
912 return *this_prologue_cache;
914 info = FRAME_OBSTACK_ZALLOC (struct spu_unwind_cache);
915 *this_prologue_cache = info;
916 info->saved_regs = trad_frame_alloc_saved_regs (this_frame);
917 info->frame_base = 0;
918 info->local_base = 0;
920 /* Find the start of the current function, and analyze its prologue. */
921 info->func = get_frame_func (this_frame);
924 /* Fall back to using the current PC as frame ID. */
925 info->func = get_frame_pc (this_frame);
929 spu_analyze_prologue (gdbarch, info->func, get_frame_pc (this_frame),
932 /* If successful, use prologue analysis data. */
933 if (data.size != -1 && data.cfa_reg != -1)
938 /* Determine CFA via unwound CFA_REG plus CFA_OFFSET. */
939 get_frame_register (this_frame, data.cfa_reg, buf);
940 cfa = extract_unsigned_integer (buf, 4, byte_order) + data.cfa_offset;
941 cfa = SPUADDR (id, cfa);
943 /* Call-saved register slots. */
944 for (i = 0; i < SPU_NUM_GPRS; i++)
945 if (i == SPU_LR_REGNUM
946 || (i >= SPU_SAVED1_REGNUM && i <= SPU_SAVEDN_REGNUM))
947 if (data.reg_offset[i] != -1)
948 info->saved_regs[i].addr = cfa - data.reg_offset[i];
951 info->frame_base = cfa;
952 info->local_base = cfa - data.size;
955 /* Otherwise, fall back to reading the backchain link. */
962 /* Get the backchain. */
963 reg = get_frame_register_unsigned (this_frame, SPU_SP_REGNUM);
964 status = safe_read_memory_integer (SPUADDR (id, reg), 4, byte_order,
967 /* A zero backchain terminates the frame chain. Also, sanity
968 check against the local store size limit. */
969 if (status && backchain > 0 && backchain < SPU_LS_SIZE)
971 /* Assume the link register is saved into its slot. */
972 if (backchain + 16 < SPU_LS_SIZE)
973 info->saved_regs[SPU_LR_REGNUM].addr = SPUADDR (id, backchain + 16);
976 info->frame_base = SPUADDR (id, backchain);
977 info->local_base = SPUADDR (id, reg);
981 /* If we didn't find a frame, we cannot determine SP / return address. */
982 if (info->frame_base == 0)
985 /* The previous SP is equal to the CFA. */
986 trad_frame_set_value (info->saved_regs, SPU_SP_REGNUM,
987 SPUADDR_ADDR (info->frame_base));
989 /* Read full contents of the unwound link register in order to
990 be able to determine the return address. */
991 if (trad_frame_addr_p (info->saved_regs, SPU_LR_REGNUM))
992 target_read_memory (info->saved_regs[SPU_LR_REGNUM].addr, buf, 16);
994 get_frame_register (this_frame, SPU_LR_REGNUM, buf);
996 /* Normally, the return address is contained in the slot 0 of the
997 link register, and slots 1-3 are zero. For an overlay return,
998 slot 0 contains the address of the overlay manager return stub,
999 slot 1 contains the partition number of the overlay section to
1000 be returned to, and slot 2 contains the return address within
1001 that section. Return the latter address in that case. */
1002 if (extract_unsigned_integer (buf + 8, 4, byte_order) != 0)
1003 trad_frame_set_value (info->saved_regs, SPU_PC_REGNUM,
1004 extract_unsigned_integer (buf + 8, 4, byte_order));
1006 trad_frame_set_value (info->saved_regs, SPU_PC_REGNUM,
1007 extract_unsigned_integer (buf, 4, byte_order));
1013 spu_frame_this_id (struct frame_info *this_frame,
1014 void **this_prologue_cache, struct frame_id *this_id)
1016 struct spu_unwind_cache *info =
1017 spu_frame_unwind_cache (this_frame, this_prologue_cache);
1019 if (info->frame_base == 0)
1022 *this_id = frame_id_build (info->frame_base, info->func);
1025 static struct value *
1026 spu_frame_prev_register (struct frame_info *this_frame,
1027 void **this_prologue_cache, int regnum)
1029 struct spu_unwind_cache *info
1030 = spu_frame_unwind_cache (this_frame, this_prologue_cache);
1032 /* Special-case the stack pointer. */
1033 if (regnum == SPU_RAW_SP_REGNUM)
1034 regnum = SPU_SP_REGNUM;
1036 return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
1039 static const struct frame_unwind spu_frame_unwind = {
1042 spu_frame_prev_register,
1044 default_frame_sniffer
1048 spu_frame_base_address (struct frame_info *this_frame, void **this_cache)
1050 struct spu_unwind_cache *info
1051 = spu_frame_unwind_cache (this_frame, this_cache);
1052 return info->local_base;
1055 static const struct frame_base spu_frame_base = {
1057 spu_frame_base_address,
1058 spu_frame_base_address,
1059 spu_frame_base_address
1063 spu_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
1065 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1066 CORE_ADDR pc = frame_unwind_register_unsigned (next_frame, SPU_PC_REGNUM);
1067 /* Mask off interrupt enable bit. */
1068 return SPUADDR (tdep->id, pc & -4);
1072 spu_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
1074 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1075 CORE_ADDR sp = frame_unwind_register_unsigned (next_frame, SPU_SP_REGNUM);
1076 return SPUADDR (tdep->id, sp);
1080 spu_read_pc (struct regcache *regcache)
1082 struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (regcache));
1084 regcache_cooked_read_unsigned (regcache, SPU_PC_REGNUM, &pc);
1085 /* Mask off interrupt enable bit. */
1086 return SPUADDR (tdep->id, pc & -4);
1090 spu_write_pc (struct regcache *regcache, CORE_ADDR pc)
1092 /* Keep interrupt enabled state unchanged. */
1094 regcache_cooked_read_unsigned (regcache, SPU_PC_REGNUM, &old_pc);
1095 regcache_cooked_write_unsigned (regcache, SPU_PC_REGNUM,
1096 (SPUADDR_ADDR (pc) & -4) | (old_pc & 3));
1100 /* Cell/B.E. cross-architecture unwinder support. */
1102 struct spu2ppu_cache
1104 struct frame_id frame_id;
1105 struct regcache *regcache;
1108 static struct gdbarch *
1109 spu2ppu_prev_arch (struct frame_info *this_frame, void **this_cache)
1111 struct spu2ppu_cache *cache = *this_cache;
1112 return get_regcache_arch (cache->regcache);
1116 spu2ppu_this_id (struct frame_info *this_frame,
1117 void **this_cache, struct frame_id *this_id)
1119 struct spu2ppu_cache *cache = *this_cache;
1120 *this_id = cache->frame_id;
1123 static struct value *
1124 spu2ppu_prev_register (struct frame_info *this_frame,
1125 void **this_cache, int regnum)
1127 struct spu2ppu_cache *cache = *this_cache;
1128 struct gdbarch *gdbarch = get_regcache_arch (cache->regcache);
1131 buf = alloca (register_size (gdbarch, regnum));
1132 regcache_cooked_read (cache->regcache, regnum, buf);
1133 return frame_unwind_got_bytes (this_frame, regnum, buf);
1137 spu2ppu_sniffer (const struct frame_unwind *self,
1138 struct frame_info *this_frame, void **this_prologue_cache)
1140 struct gdbarch *gdbarch = get_frame_arch (this_frame);
1141 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1142 CORE_ADDR base, func, backchain;
1145 if (gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_spu)
1148 base = get_frame_sp (this_frame);
1149 func = get_frame_pc (this_frame);
1150 if (target_read_memory (base, buf, 4))
1152 backchain = extract_unsigned_integer (buf, 4, byte_order);
1156 struct frame_info *fi;
1158 struct spu2ppu_cache *cache
1159 = FRAME_OBSTACK_CALLOC (1, struct spu2ppu_cache);
1161 cache->frame_id = frame_id_build (base + 16, func);
1163 for (fi = get_next_frame (this_frame); fi; fi = get_next_frame (fi))
1164 if (gdbarch_bfd_arch_info (get_frame_arch (fi))->arch != bfd_arch_spu)
1169 cache->regcache = frame_save_as_regcache (fi);
1170 *this_prologue_cache = cache;
1175 struct regcache *regcache;
1176 regcache = get_thread_arch_regcache (inferior_ptid, target_gdbarch);
1177 cache->regcache = regcache_dup (regcache);
1178 *this_prologue_cache = cache;
1187 spu2ppu_dealloc_cache (struct frame_info *self, void *this_cache)
1189 struct spu2ppu_cache *cache = this_cache;
1190 regcache_xfree (cache->regcache);
1193 static const struct frame_unwind spu2ppu_unwind = {
1196 spu2ppu_prev_register,
1199 spu2ppu_dealloc_cache,
1204 /* Function calling convention. */
1207 spu_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
1213 spu_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
1214 struct value **args, int nargs, struct type *value_type,
1215 CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
1216 struct regcache *regcache)
1218 /* Allocate space sufficient for a breakpoint, keeping the stack aligned. */
1219 sp = (sp - 4) & ~15;
1220 /* Store the address of that breakpoint */
1222 /* The call starts at the callee's entry point. */
1229 spu_scalar_value_p (struct type *type)
1231 switch (TYPE_CODE (type))
1234 case TYPE_CODE_ENUM:
1235 case TYPE_CODE_RANGE:
1236 case TYPE_CODE_CHAR:
1237 case TYPE_CODE_BOOL:
1240 return TYPE_LENGTH (type) <= 16;
1248 spu_value_to_regcache (struct regcache *regcache, int regnum,
1249 struct type *type, const gdb_byte *in)
1251 int len = TYPE_LENGTH (type);
1253 if (spu_scalar_value_p (type))
1255 int preferred_slot = len < 4 ? 4 - len : 0;
1256 regcache_cooked_write_part (regcache, regnum, preferred_slot, len, in);
1262 regcache_cooked_write (regcache, regnum++, in);
1268 regcache_cooked_write_part (regcache, regnum, 0, len, in);
1273 spu_regcache_to_value (struct regcache *regcache, int regnum,
1274 struct type *type, gdb_byte *out)
1276 int len = TYPE_LENGTH (type);
1278 if (spu_scalar_value_p (type))
1280 int preferred_slot = len < 4 ? 4 - len : 0;
1281 regcache_cooked_read_part (regcache, regnum, preferred_slot, len, out);
1287 regcache_cooked_read (regcache, regnum++, out);
1293 regcache_cooked_read_part (regcache, regnum, 0, len, out);
1298 spu_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
1299 struct regcache *regcache, CORE_ADDR bp_addr,
1300 int nargs, struct value **args, CORE_ADDR sp,
1301 int struct_return, CORE_ADDR struct_addr)
1303 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1306 int regnum = SPU_ARG1_REGNUM;
1310 /* Set the return address. */
1311 memset (buf, 0, sizeof buf);
1312 store_unsigned_integer (buf, 4, byte_order, SPUADDR_ADDR (bp_addr));
1313 regcache_cooked_write (regcache, SPU_LR_REGNUM, buf);
1315 /* If STRUCT_RETURN is true, then the struct return address (in
1316 STRUCT_ADDR) will consume the first argument-passing register.
1317 Both adjust the register count and store that value. */
1320 memset (buf, 0, sizeof buf);
1321 store_unsigned_integer (buf, 4, byte_order, SPUADDR_ADDR (struct_addr));
1322 regcache_cooked_write (regcache, regnum++, buf);
1325 /* Fill in argument registers. */
1326 for (i = 0; i < nargs; i++)
1328 struct value *arg = args[i];
1329 struct type *type = check_typedef (value_type (arg));
1330 const gdb_byte *contents = value_contents (arg);
1331 int len = TYPE_LENGTH (type);
1332 int n_regs = align_up (len, 16) / 16;
1334 /* If the argument doesn't wholly fit into registers, it and
1335 all subsequent arguments go to the stack. */
1336 if (regnum + n_regs - 1 > SPU_ARGN_REGNUM)
1342 spu_value_to_regcache (regcache, regnum, type, contents);
1346 /* Overflow arguments go to the stack. */
1347 if (stack_arg != -1)
1351 /* Allocate all required stack size. */
1352 for (i = stack_arg; i < nargs; i++)
1354 struct type *type = check_typedef (value_type (args[i]));
1355 sp -= align_up (TYPE_LENGTH (type), 16);
1358 /* Fill in stack arguments. */
1360 for (i = stack_arg; i < nargs; i++)
1362 struct value *arg = args[i];
1363 struct type *type = check_typedef (value_type (arg));
1364 int len = TYPE_LENGTH (type);
1367 if (spu_scalar_value_p (type))
1368 preferred_slot = len < 4 ? 4 - len : 0;
1372 target_write_memory (ap + preferred_slot, value_contents (arg), len);
1373 ap += align_up (TYPE_LENGTH (type), 16);
1377 /* Allocate stack frame header. */
1380 /* Store stack back chain. */
1381 regcache_cooked_read (regcache, SPU_RAW_SP_REGNUM, buf);
1382 target_write_memory (sp, buf, 16);
1384 /* Finally, update all slots of the SP register. */
1385 sp_delta = sp - extract_unsigned_integer (buf, 4, byte_order);
1386 for (i = 0; i < 4; i++)
1388 CORE_ADDR sp_slot = extract_unsigned_integer (buf + 4*i, 4, byte_order);
1389 store_unsigned_integer (buf + 4*i, 4, byte_order, sp_slot + sp_delta);
1391 regcache_cooked_write (regcache, SPU_RAW_SP_REGNUM, buf);
1396 static struct frame_id
1397 spu_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
1399 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1400 CORE_ADDR pc = get_frame_register_unsigned (this_frame, SPU_PC_REGNUM);
1401 CORE_ADDR sp = get_frame_register_unsigned (this_frame, SPU_SP_REGNUM);
1402 return frame_id_build (SPUADDR (tdep->id, sp), SPUADDR (tdep->id, pc & -4));
1405 /* Function return value access. */
1407 static enum return_value_convention
1408 spu_return_value (struct gdbarch *gdbarch, struct type *func_type,
1409 struct type *type, struct regcache *regcache,
1410 gdb_byte *out, const gdb_byte *in)
1412 enum return_value_convention rvc;
1414 if (TYPE_LENGTH (type) <= (SPU_ARGN_REGNUM - SPU_ARG1_REGNUM + 1) * 16)
1415 rvc = RETURN_VALUE_REGISTER_CONVENTION;
1417 rvc = RETURN_VALUE_STRUCT_CONVENTION;
1423 case RETURN_VALUE_REGISTER_CONVENTION:
1424 spu_value_to_regcache (regcache, SPU_ARG1_REGNUM, type, in);
1427 case RETURN_VALUE_STRUCT_CONVENTION:
1428 error ("Cannot set function return value.");
1436 case RETURN_VALUE_REGISTER_CONVENTION:
1437 spu_regcache_to_value (regcache, SPU_ARG1_REGNUM, type, out);
1440 case RETURN_VALUE_STRUCT_CONVENTION:
1441 error ("Function return value unknown.");
1452 static const gdb_byte *
1453 spu_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR * pcptr, int *lenptr)
1455 static const gdb_byte breakpoint[] = { 0x00, 0x00, 0x3f, 0xff };
1457 *lenptr = sizeof breakpoint;
1462 /* Software single-stepping support. */
1465 spu_software_single_step (struct frame_info *frame)
1467 struct gdbarch *gdbarch = get_frame_arch (frame);
1468 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1469 CORE_ADDR pc, next_pc;
1474 pc = get_frame_pc (frame);
1476 if (target_read_memory (pc, buf, 4))
1478 insn = extract_unsigned_integer (buf, 4, byte_order);
1480 /* Next sequential instruction is at PC + 4, except if the current
1481 instruction is a PPE-assisted call, in which case it is at PC + 8.
1482 Wrap around LS limit to be on the safe side. */
1483 if ((insn & 0xffffff00) == 0x00002100)
1484 next_pc = (SPUADDR_ADDR (pc) + 8) & (SPU_LS_SIZE - 1);
1486 next_pc = (SPUADDR_ADDR (pc) + 4) & (SPU_LS_SIZE - 1);
1488 insert_single_step_breakpoint (gdbarch, SPUADDR (SPUADDR_SPU (pc), next_pc));
1490 if (is_branch (insn, &offset, ®))
1492 CORE_ADDR target = offset;
1494 if (reg == SPU_PC_REGNUM)
1495 target += SPUADDR_ADDR (pc);
1498 get_frame_register_bytes (frame, reg, 0, 4, buf);
1499 target += extract_unsigned_integer (buf, 4, byte_order) & -4;
1502 target = target & (SPU_LS_SIZE - 1);
1503 if (target != next_pc)
1504 insert_single_step_breakpoint (gdbarch,
1505 SPUADDR (SPUADDR_SPU (pc), target));
1512 /* Longjmp support. */
1515 spu_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
1517 struct gdbarch *gdbarch = get_frame_arch (frame);
1518 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
1519 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1523 /* Jump buffer is pointed to by the argument register $r3. */
1524 get_frame_register_bytes (frame, SPU_ARG1_REGNUM, 0, 4, buf);
1525 jb_addr = extract_unsigned_integer (buf, 4, byte_order);
1526 if (target_read_memory (SPUADDR (tdep->id, jb_addr), buf, 4))
1529 *pc = extract_unsigned_integer (buf, 4, byte_order);
1530 *pc = SPUADDR (tdep->id, *pc);
1537 struct spu_dis_asm_data
1539 struct gdbarch *gdbarch;
1544 spu_dis_asm_print_address (bfd_vma addr, struct disassemble_info *info)
1546 struct spu_dis_asm_data *data = info->application_data;
1547 print_address (data->gdbarch, SPUADDR (data->id, addr), info->stream);
1551 gdb_print_insn_spu (bfd_vma memaddr, struct disassemble_info *info)
1553 /* The opcodes disassembler does 18-bit address arithmetic. Make sure the
1554 SPU ID encoded in the high bits is added back when we call print_address. */
1555 struct disassemble_info spu_info = *info;
1556 struct spu_dis_asm_data data;
1557 data.gdbarch = info->application_data;
1558 data.id = SPUADDR_SPU (memaddr);
1560 spu_info.application_data = &data;
1561 spu_info.print_address_func = spu_dis_asm_print_address;
1562 return print_insn_spu (memaddr, &spu_info);
1566 /* Target overlays for the SPU overlay manager.
1568 See the documentation of simple_overlay_update for how the
1569 interface is supposed to work.
1571 Data structures used by the overlay manager:
1579 } _ovly_table[]; -- one entry per overlay section
1581 struct ovly_buf_table
1584 } _ovly_buf_table[]; -- one entry per overlay buffer
1586 _ovly_table should never change.
1588 Both tables are aligned to a 16-byte boundary, the symbols _ovly_table
1589 and _ovly_buf_table are of type STT_OBJECT and their size set to the size
1590 of the respective array. buf in _ovly_table is an index into _ovly_buf_table.
1592 mapped is an index into _ovly_table. Both the mapped and buf indices start
1593 from one to reference the first entry in their respective tables. */
1595 /* Using the per-objfile private data mechanism, we store for each
1596 objfile an array of "struct spu_overlay_table" structures, one
1597 for each obj_section of the objfile. This structure holds two
1598 fields, MAPPED_PTR and MAPPED_VAL. If MAPPED_PTR is zero, this
1599 is *not* an overlay section. If it is non-zero, it represents
1600 a target address. The overlay section is mapped iff the target
1601 integer at this location equals MAPPED_VAL. */
1603 static const struct objfile_data *spu_overlay_data;
1605 struct spu_overlay_table
1607 CORE_ADDR mapped_ptr;
1608 CORE_ADDR mapped_val;
1611 /* Retrieve the overlay table for OBJFILE. If not already cached, read
1612 the _ovly_table data structure from the target and initialize the
1613 spu_overlay_table data structure from it. */
1614 static struct spu_overlay_table *
1615 spu_get_overlay_table (struct objfile *objfile)
1617 enum bfd_endian byte_order = bfd_big_endian (objfile->obfd)?
1618 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
1619 struct minimal_symbol *ovly_table_msym, *ovly_buf_table_msym;
1620 CORE_ADDR ovly_table_base, ovly_buf_table_base;
1621 unsigned ovly_table_size, ovly_buf_table_size;
1622 struct spu_overlay_table *tbl;
1623 struct obj_section *osect;
1627 tbl = objfile_data (objfile, spu_overlay_data);
1631 ovly_table_msym = lookup_minimal_symbol ("_ovly_table", NULL, objfile);
1632 if (!ovly_table_msym)
1635 ovly_buf_table_msym = lookup_minimal_symbol ("_ovly_buf_table", NULL, objfile);
1636 if (!ovly_buf_table_msym)
1639 ovly_table_base = SYMBOL_VALUE_ADDRESS (ovly_table_msym);
1640 ovly_table_size = MSYMBOL_SIZE (ovly_table_msym);
1642 ovly_buf_table_base = SYMBOL_VALUE_ADDRESS (ovly_buf_table_msym);
1643 ovly_buf_table_size = MSYMBOL_SIZE (ovly_buf_table_msym);
1645 ovly_table = xmalloc (ovly_table_size);
1646 read_memory (ovly_table_base, ovly_table, ovly_table_size);
1648 tbl = OBSTACK_CALLOC (&objfile->objfile_obstack,
1649 objfile->sections_end - objfile->sections,
1650 struct spu_overlay_table);
1652 for (i = 0; i < ovly_table_size / 16; i++)
1654 CORE_ADDR vma = extract_unsigned_integer (ovly_table + 16*i + 0,
1656 CORE_ADDR size = extract_unsigned_integer (ovly_table + 16*i + 4,
1658 CORE_ADDR pos = extract_unsigned_integer (ovly_table + 16*i + 8,
1660 CORE_ADDR buf = extract_unsigned_integer (ovly_table + 16*i + 12,
1663 if (buf == 0 || (buf - 1) * 4 >= ovly_buf_table_size)
1666 ALL_OBJFILE_OSECTIONS (objfile, osect)
1667 if (vma == bfd_section_vma (objfile->obfd, osect->the_bfd_section)
1668 && pos == osect->the_bfd_section->filepos)
1670 int ndx = osect - objfile->sections;
1671 tbl[ndx].mapped_ptr = ovly_buf_table_base + (buf - 1) * 4;
1672 tbl[ndx].mapped_val = i + 1;
1678 set_objfile_data (objfile, spu_overlay_data, tbl);
1682 /* Read _ovly_buf_table entry from the target to dermine whether
1683 OSECT is currently mapped, and update the mapped state. */
1685 spu_overlay_update_osect (struct obj_section *osect)
1687 enum bfd_endian byte_order = bfd_big_endian (osect->objfile->obfd)?
1688 BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE;
1689 struct spu_overlay_table *ovly_table;
1692 ovly_table = spu_get_overlay_table (osect->objfile);
1696 ovly_table += osect - osect->objfile->sections;
1697 if (ovly_table->mapped_ptr == 0)
1700 id = SPUADDR_SPU (obj_section_addr (osect));
1701 val = read_memory_unsigned_integer (SPUADDR (id, ovly_table->mapped_ptr),
1703 osect->ovly_mapped = (val == ovly_table->mapped_val);
1706 /* If OSECT is NULL, then update all sections' mapped state.
1707 If OSECT is non-NULL, then update only OSECT's mapped state. */
1709 spu_overlay_update (struct obj_section *osect)
1711 /* Just one section. */
1713 spu_overlay_update_osect (osect);
1718 struct objfile *objfile;
1720 ALL_OBJSECTIONS (objfile, osect)
1721 if (section_is_overlay (osect))
1722 spu_overlay_update_osect (osect);
1726 /* Whenever a new objfile is loaded, read the target's _ovly_table.
1727 If there is one, go through all sections and make sure for non-
1728 overlay sections LMA equals VMA, while for overlay sections LMA
1729 is larger than local store size. */
1731 spu_overlay_new_objfile (struct objfile *objfile)
1733 struct spu_overlay_table *ovly_table;
1734 struct obj_section *osect;
1736 /* If we've already touched this file, do nothing. */
1737 if (!objfile || objfile_data (objfile, spu_overlay_data) != NULL)
1740 /* Consider only SPU objfiles. */
1741 if (bfd_get_arch (objfile->obfd) != bfd_arch_spu)
1744 /* Check if this objfile has overlays. */
1745 ovly_table = spu_get_overlay_table (objfile);
1749 /* Now go and fiddle with all the LMAs. */
1750 ALL_OBJFILE_OSECTIONS (objfile, osect)
1752 bfd *obfd = objfile->obfd;
1753 asection *bsect = osect->the_bfd_section;
1754 int ndx = osect - objfile->sections;
1756 if (ovly_table[ndx].mapped_ptr == 0)
1757 bfd_section_lma (obfd, bsect) = bfd_section_vma (obfd, bsect);
1759 bfd_section_lma (obfd, bsect) = bsect->filepos + SPU_LS_SIZE;
1764 /* Insert temporary breakpoint on "main" function of newly loaded
1765 SPE context OBJFILE. */
1767 spu_catch_start (struct objfile *objfile)
1769 struct minimal_symbol *minsym;
1770 struct symtab *symtab;
1774 /* Do this only if requested by "set spu stop-on-load on". */
1775 if (!spu_stop_on_load_p)
1778 /* Consider only SPU objfiles. */
1779 if (!objfile || bfd_get_arch (objfile->obfd) != bfd_arch_spu)
1782 /* The main objfile is handled differently. */
1783 if (objfile == symfile_objfile)
1786 /* There can be multiple symbols named "main". Search for the
1787 "main" in *this* objfile. */
1788 minsym = lookup_minimal_symbol ("main", NULL, objfile);
1792 /* If we have debugging information, try to use it -- this
1793 will allow us to properly skip the prologue. */
1794 pc = SYMBOL_VALUE_ADDRESS (minsym);
1795 symtab = find_pc_sect_symtab (pc, SYMBOL_OBJ_SECTION (minsym));
1798 struct blockvector *bv = BLOCKVECTOR (symtab);
1799 struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
1801 struct symtab_and_line sal;
1803 sym = lookup_block_symbol (block, "main", NULL, VAR_DOMAIN);
1806 fixup_symbol_section (sym, objfile);
1807 sal = find_function_start_sal (sym, 1);
1812 /* Use a numerical address for the set_breakpoint command to avoid having
1813 the breakpoint re-set incorrectly. */
1814 xsnprintf (buf, sizeof buf, "*%s", core_addr_to_string (pc));
1815 set_breakpoint (get_objfile_arch (objfile),
1816 buf, NULL /* condition */,
1817 0 /* hardwareflag */, 1 /* tempflag */,
1818 -1 /* thread */, 0 /* ignore_count */,
1819 0 /* pending */, 1 /* enabled */);
1823 /* "info spu" commands. */
1826 info_spu_event_command (char *args, int from_tty)
1828 struct frame_info *frame = get_selected_frame (NULL);
1829 ULONGEST event_status = 0;
1830 ULONGEST event_mask = 0;
1831 struct cleanup *chain;
1837 if (gdbarch_bfd_arch_info (get_frame_arch (frame))->arch != bfd_arch_spu)
1838 error (_("\"info spu\" is only supported on the SPU architecture."));
1840 id = get_frame_register_unsigned (frame, SPU_ID_REGNUM);
1842 xsnprintf (annex, sizeof annex, "%d/event_status", id);
1843 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1844 buf, 0, (sizeof (buf) - 1));
1846 error (_("Could not read event_status."));
1848 event_status = strtoulst (buf, NULL, 16);
1850 xsnprintf (annex, sizeof annex, "%d/event_mask", id);
1851 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1852 buf, 0, (sizeof (buf) - 1));
1854 error (_("Could not read event_mask."));
1856 event_mask = strtoulst (buf, NULL, 16);
1858 chain = make_cleanup_ui_out_tuple_begin_end (uiout, "SPUInfoEvent");
1860 if (ui_out_is_mi_like_p (uiout))
1862 ui_out_field_fmt (uiout, "event_status",
1863 "0x%s", phex_nz (event_status, 4));
1864 ui_out_field_fmt (uiout, "event_mask",
1865 "0x%s", phex_nz (event_mask, 4));
1869 printf_filtered (_("Event Status 0x%s\n"), phex (event_status, 4));
1870 printf_filtered (_("Event Mask 0x%s\n"), phex (event_mask, 4));
1873 do_cleanups (chain);
1877 info_spu_signal_command (char *args, int from_tty)
1879 struct frame_info *frame = get_selected_frame (NULL);
1880 struct gdbarch *gdbarch = get_frame_arch (frame);
1881 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1882 ULONGEST signal1 = 0;
1883 ULONGEST signal1_type = 0;
1884 int signal1_pending = 0;
1885 ULONGEST signal2 = 0;
1886 ULONGEST signal2_type = 0;
1887 int signal2_pending = 0;
1888 struct cleanup *chain;
1894 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
1895 error (_("\"info spu\" is only supported on the SPU architecture."));
1897 id = get_frame_register_unsigned (frame, SPU_ID_REGNUM);
1899 xsnprintf (annex, sizeof annex, "%d/signal1", id);
1900 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex, buf, 0, 4);
1902 error (_("Could not read signal1."));
1905 signal1 = extract_unsigned_integer (buf, 4, byte_order);
1906 signal1_pending = 1;
1909 xsnprintf (annex, sizeof annex, "%d/signal1_type", id);
1910 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1911 buf, 0, (sizeof (buf) - 1));
1913 error (_("Could not read signal1_type."));
1915 signal1_type = strtoulst (buf, NULL, 16);
1917 xsnprintf (annex, sizeof annex, "%d/signal2", id);
1918 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex, buf, 0, 4);
1920 error (_("Could not read signal2."));
1923 signal2 = extract_unsigned_integer (buf, 4, byte_order);
1924 signal2_pending = 1;
1927 xsnprintf (annex, sizeof annex, "%d/signal2_type", id);
1928 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
1929 buf, 0, (sizeof (buf) - 1));
1931 error (_("Could not read signal2_type."));
1933 signal2_type = strtoulst (buf, NULL, 16);
1935 chain = make_cleanup_ui_out_tuple_begin_end (uiout, "SPUInfoSignal");
1937 if (ui_out_is_mi_like_p (uiout))
1939 ui_out_field_int (uiout, "signal1_pending", signal1_pending);
1940 ui_out_field_fmt (uiout, "signal1", "0x%s", phex_nz (signal1, 4));
1941 ui_out_field_int (uiout, "signal1_type", signal1_type);
1942 ui_out_field_int (uiout, "signal2_pending", signal2_pending);
1943 ui_out_field_fmt (uiout, "signal2", "0x%s", phex_nz (signal2, 4));
1944 ui_out_field_int (uiout, "signal2_type", signal2_type);
1948 if (signal1_pending)
1949 printf_filtered (_("Signal 1 control word 0x%s "), phex (signal1, 4));
1951 printf_filtered (_("Signal 1 not pending "));
1954 printf_filtered (_("(Type Or)\n"));
1956 printf_filtered (_("(Type Overwrite)\n"));
1958 if (signal2_pending)
1959 printf_filtered (_("Signal 2 control word 0x%s "), phex (signal2, 4));
1961 printf_filtered (_("Signal 2 not pending "));
1964 printf_filtered (_("(Type Or)\n"));
1966 printf_filtered (_("(Type Overwrite)\n"));
1969 do_cleanups (chain);
1973 info_spu_mailbox_list (gdb_byte *buf, int nr, enum bfd_endian byte_order,
1974 const char *field, const char *msg)
1976 struct cleanup *chain;
1982 chain = make_cleanup_ui_out_table_begin_end (uiout, 1, nr, "mbox");
1984 ui_out_table_header (uiout, 32, ui_left, field, msg);
1985 ui_out_table_body (uiout);
1987 for (i = 0; i < nr; i++)
1989 struct cleanup *val_chain;
1991 val_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "mbox");
1992 val = extract_unsigned_integer (buf + 4*i, 4, byte_order);
1993 ui_out_field_fmt (uiout, field, "0x%s", phex (val, 4));
1994 do_cleanups (val_chain);
1996 if (!ui_out_is_mi_like_p (uiout))
1997 printf_filtered ("\n");
2000 do_cleanups (chain);
2004 info_spu_mailbox_command (char *args, int from_tty)
2006 struct frame_info *frame = get_selected_frame (NULL);
2007 struct gdbarch *gdbarch = get_frame_arch (frame);
2008 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2009 struct cleanup *chain;
2015 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
2016 error (_("\"info spu\" is only supported on the SPU architecture."));
2018 id = get_frame_register_unsigned (frame, SPU_ID_REGNUM);
2020 chain = make_cleanup_ui_out_tuple_begin_end (uiout, "SPUInfoMailbox");
2022 xsnprintf (annex, sizeof annex, "%d/mbox_info", id);
2023 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
2024 buf, 0, sizeof buf);
2026 error (_("Could not read mbox_info."));
2028 info_spu_mailbox_list (buf, len / 4, byte_order,
2029 "mbox", "SPU Outbound Mailbox");
2031 xsnprintf (annex, sizeof annex, "%d/ibox_info", id);
2032 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
2033 buf, 0, sizeof buf);
2035 error (_("Could not read ibox_info."));
2037 info_spu_mailbox_list (buf, len / 4, byte_order,
2038 "ibox", "SPU Outbound Interrupt Mailbox");
2040 xsnprintf (annex, sizeof annex, "%d/wbox_info", id);
2041 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
2042 buf, 0, sizeof buf);
2044 error (_("Could not read wbox_info."));
2046 info_spu_mailbox_list (buf, len / 4, byte_order,
2047 "wbox", "SPU Inbound Mailbox");
2049 do_cleanups (chain);
2053 spu_mfc_get_bitfield (ULONGEST word, int first, int last)
2055 ULONGEST mask = ~(~(ULONGEST)0 << (last - first + 1));
2056 return (word >> (63 - last)) & mask;
2060 info_spu_dma_cmdlist (gdb_byte *buf, int nr, enum bfd_endian byte_order)
2062 static char *spu_mfc_opcode[256] =
2064 /* 00 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2065 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2066 /* 10 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2067 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2068 /* 20 */ "put", "putb", "putf", NULL, "putl", "putlb", "putlf", NULL,
2069 "puts", "putbs", "putfs", NULL, NULL, NULL, NULL, NULL,
2070 /* 30 */ "putr", "putrb", "putrf", NULL, "putrl", "putrlb", "putrlf", NULL,
2071 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2072 /* 40 */ "get", "getb", "getf", NULL, "getl", "getlb", "getlf", NULL,
2073 "gets", "getbs", "getfs", NULL, NULL, NULL, NULL, NULL,
2074 /* 50 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2075 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2076 /* 60 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2077 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2078 /* 70 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2079 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2080 /* 80 */ "sdcrt", "sdcrtst", NULL, NULL, NULL, NULL, NULL, NULL,
2081 NULL, "sdcrz", NULL, NULL, NULL, "sdcrst", NULL, "sdcrf",
2082 /* 90 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2083 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2084 /* a0 */ "sndsig", "sndsigb", "sndsigf", NULL, NULL, NULL, NULL, NULL,
2085 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2086 /* b0 */ "putlluc", NULL, NULL, NULL, "putllc", NULL, NULL, NULL,
2087 "putqlluc", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2088 /* c0 */ "barrier", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2089 "mfceieio", NULL, NULL, NULL, "mfcsync", NULL, NULL, NULL,
2090 /* d0 */ "getllar", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2091 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2092 /* e0 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2093 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2094 /* f0 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2095 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
2098 int *seq = alloca (nr * sizeof (int));
2100 struct cleanup *chain;
2104 /* Determine sequence in which to display (valid) entries. */
2105 for (i = 0; i < nr; i++)
2107 /* Search for the first valid entry all of whose
2108 dependencies are met. */
2109 for (j = 0; j < nr; j++)
2111 ULONGEST mfc_cq_dw3;
2112 ULONGEST dependencies;
2114 if (done & (1 << (nr - 1 - j)))
2118 = extract_unsigned_integer (buf + 32*j + 24,8, byte_order);
2119 if (!spu_mfc_get_bitfield (mfc_cq_dw3, 16, 16))
2122 dependencies = spu_mfc_get_bitfield (mfc_cq_dw3, 0, nr - 1);
2123 if ((dependencies & done) != dependencies)
2127 done |= 1 << (nr - 1 - j);
2138 chain = make_cleanup_ui_out_table_begin_end (uiout, 10, nr, "dma_cmd");
2140 ui_out_table_header (uiout, 7, ui_left, "opcode", "Opcode");
2141 ui_out_table_header (uiout, 3, ui_left, "tag", "Tag");
2142 ui_out_table_header (uiout, 3, ui_left, "tid", "TId");
2143 ui_out_table_header (uiout, 3, ui_left, "rid", "RId");
2144 ui_out_table_header (uiout, 18, ui_left, "ea", "EA");
2145 ui_out_table_header (uiout, 7, ui_left, "lsa", "LSA");
2146 ui_out_table_header (uiout, 7, ui_left, "size", "Size");
2147 ui_out_table_header (uiout, 7, ui_left, "lstaddr", "LstAddr");
2148 ui_out_table_header (uiout, 7, ui_left, "lstsize", "LstSize");
2149 ui_out_table_header (uiout, 1, ui_left, "error_p", "E");
2151 ui_out_table_body (uiout);
2153 for (i = 0; i < nr; i++)
2155 struct cleanup *cmd_chain;
2156 ULONGEST mfc_cq_dw0;
2157 ULONGEST mfc_cq_dw1;
2158 ULONGEST mfc_cq_dw2;
2159 int mfc_cmd_opcode, mfc_cmd_tag, rclass_id, tclass_id;
2160 int lsa, size, list_lsa, list_size, mfc_lsa, mfc_size;
2162 int list_valid_p, noop_valid_p, qw_valid_p, ea_valid_p, cmd_error_p;
2164 /* Decode contents of MFC Command Queue Context Save/Restore Registers.
2165 See "Cell Broadband Engine Registers V1.3", section 3.3.2.1. */
2168 = extract_unsigned_integer (buf + 32*seq[i], 8, byte_order);
2170 = extract_unsigned_integer (buf + 32*seq[i] + 8, 8, byte_order);
2172 = extract_unsigned_integer (buf + 32*seq[i] + 16, 8, byte_order);
2174 list_lsa = spu_mfc_get_bitfield (mfc_cq_dw0, 0, 14);
2175 list_size = spu_mfc_get_bitfield (mfc_cq_dw0, 15, 26);
2176 mfc_cmd_opcode = spu_mfc_get_bitfield (mfc_cq_dw0, 27, 34);
2177 mfc_cmd_tag = spu_mfc_get_bitfield (mfc_cq_dw0, 35, 39);
2178 list_valid_p = spu_mfc_get_bitfield (mfc_cq_dw0, 40, 40);
2179 rclass_id = spu_mfc_get_bitfield (mfc_cq_dw0, 41, 43);
2180 tclass_id = spu_mfc_get_bitfield (mfc_cq_dw0, 44, 46);
2182 mfc_ea = spu_mfc_get_bitfield (mfc_cq_dw1, 0, 51) << 12
2183 | spu_mfc_get_bitfield (mfc_cq_dw2, 25, 36);
2185 mfc_lsa = spu_mfc_get_bitfield (mfc_cq_dw2, 0, 13);
2186 mfc_size = spu_mfc_get_bitfield (mfc_cq_dw2, 14, 24);
2187 noop_valid_p = spu_mfc_get_bitfield (mfc_cq_dw2, 37, 37);
2188 qw_valid_p = spu_mfc_get_bitfield (mfc_cq_dw2, 38, 38);
2189 ea_valid_p = spu_mfc_get_bitfield (mfc_cq_dw2, 39, 39);
2190 cmd_error_p = spu_mfc_get_bitfield (mfc_cq_dw2, 40, 40);
2192 cmd_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "cmd");
2194 if (spu_mfc_opcode[mfc_cmd_opcode])
2195 ui_out_field_string (uiout, "opcode", spu_mfc_opcode[mfc_cmd_opcode]);
2197 ui_out_field_int (uiout, "opcode", mfc_cmd_opcode);
2199 ui_out_field_int (uiout, "tag", mfc_cmd_tag);
2200 ui_out_field_int (uiout, "tid", tclass_id);
2201 ui_out_field_int (uiout, "rid", rclass_id);
2204 ui_out_field_fmt (uiout, "ea", "0x%s", phex (mfc_ea, 8));
2206 ui_out_field_skip (uiout, "ea");
2208 ui_out_field_fmt (uiout, "lsa", "0x%05x", mfc_lsa << 4);
2210 ui_out_field_fmt (uiout, "size", "0x%05x", mfc_size << 4);
2212 ui_out_field_fmt (uiout, "size", "0x%05x", mfc_size);
2216 ui_out_field_fmt (uiout, "lstaddr", "0x%05x", list_lsa << 3);
2217 ui_out_field_fmt (uiout, "lstsize", "0x%05x", list_size << 3);
2221 ui_out_field_skip (uiout, "lstaddr");
2222 ui_out_field_skip (uiout, "lstsize");
2226 ui_out_field_string (uiout, "error_p", "*");
2228 ui_out_field_skip (uiout, "error_p");
2230 do_cleanups (cmd_chain);
2232 if (!ui_out_is_mi_like_p (uiout))
2233 printf_filtered ("\n");
2236 do_cleanups (chain);
2240 info_spu_dma_command (char *args, int from_tty)
2242 struct frame_info *frame = get_selected_frame (NULL);
2243 struct gdbarch *gdbarch = get_frame_arch (frame);
2244 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2245 ULONGEST dma_info_type;
2246 ULONGEST dma_info_mask;
2247 ULONGEST dma_info_status;
2248 ULONGEST dma_info_stall_and_notify;
2249 ULONGEST dma_info_atomic_command_status;
2250 struct cleanup *chain;
2256 if (gdbarch_bfd_arch_info (get_frame_arch (frame))->arch != bfd_arch_spu)
2257 error (_("\"info spu\" is only supported on the SPU architecture."));
2259 id = get_frame_register_unsigned (frame, SPU_ID_REGNUM);
2261 xsnprintf (annex, sizeof annex, "%d/dma_info", id);
2262 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
2263 buf, 0, 40 + 16 * 32);
2265 error (_("Could not read dma_info."));
2268 = extract_unsigned_integer (buf, 8, byte_order);
2270 = extract_unsigned_integer (buf + 8, 8, byte_order);
2272 = extract_unsigned_integer (buf + 16, 8, byte_order);
2273 dma_info_stall_and_notify
2274 = extract_unsigned_integer (buf + 24, 8, byte_order);
2275 dma_info_atomic_command_status
2276 = extract_unsigned_integer (buf + 32, 8, byte_order);
2278 chain = make_cleanup_ui_out_tuple_begin_end (uiout, "SPUInfoDMA");
2280 if (ui_out_is_mi_like_p (uiout))
2282 ui_out_field_fmt (uiout, "dma_info_type", "0x%s",
2283 phex_nz (dma_info_type, 4));
2284 ui_out_field_fmt (uiout, "dma_info_mask", "0x%s",
2285 phex_nz (dma_info_mask, 4));
2286 ui_out_field_fmt (uiout, "dma_info_status", "0x%s",
2287 phex_nz (dma_info_status, 4));
2288 ui_out_field_fmt (uiout, "dma_info_stall_and_notify", "0x%s",
2289 phex_nz (dma_info_stall_and_notify, 4));
2290 ui_out_field_fmt (uiout, "dma_info_atomic_command_status", "0x%s",
2291 phex_nz (dma_info_atomic_command_status, 4));
2295 const char *query_msg = _("no query pending");
2297 if (dma_info_type & 4)
2298 switch (dma_info_type & 3)
2300 case 1: query_msg = _("'any' query pending"); break;
2301 case 2: query_msg = _("'all' query pending"); break;
2302 default: query_msg = _("undefined query type"); break;
2305 printf_filtered (_("Tag-Group Status 0x%s\n"),
2306 phex (dma_info_status, 4));
2307 printf_filtered (_("Tag-Group Mask 0x%s (%s)\n"),
2308 phex (dma_info_mask, 4), query_msg);
2309 printf_filtered (_("Stall-and-Notify 0x%s\n"),
2310 phex (dma_info_stall_and_notify, 4));
2311 printf_filtered (_("Atomic Cmd Status 0x%s\n"),
2312 phex (dma_info_atomic_command_status, 4));
2313 printf_filtered ("\n");
2316 info_spu_dma_cmdlist (buf + 40, 16, byte_order);
2317 do_cleanups (chain);
2321 info_spu_proxydma_command (char *args, int from_tty)
2323 struct frame_info *frame = get_selected_frame (NULL);
2324 struct gdbarch *gdbarch = get_frame_arch (frame);
2325 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
2326 ULONGEST dma_info_type;
2327 ULONGEST dma_info_mask;
2328 ULONGEST dma_info_status;
2329 struct cleanup *chain;
2335 if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_spu)
2336 error (_("\"info spu\" is only supported on the SPU architecture."));
2338 id = get_frame_register_unsigned (frame, SPU_ID_REGNUM);
2340 xsnprintf (annex, sizeof annex, "%d/proxydma_info", id);
2341 len = target_read (¤t_target, TARGET_OBJECT_SPU, annex,
2342 buf, 0, 24 + 8 * 32);
2344 error (_("Could not read proxydma_info."));
2346 dma_info_type = extract_unsigned_integer (buf, 8, byte_order);
2347 dma_info_mask = extract_unsigned_integer (buf + 8, 8, byte_order);
2348 dma_info_status = extract_unsigned_integer (buf + 16, 8, byte_order);
2350 chain = make_cleanup_ui_out_tuple_begin_end (uiout, "SPUInfoProxyDMA");
2352 if (ui_out_is_mi_like_p (uiout))
2354 ui_out_field_fmt (uiout, "proxydma_info_type", "0x%s",
2355 phex_nz (dma_info_type, 4));
2356 ui_out_field_fmt (uiout, "proxydma_info_mask", "0x%s",
2357 phex_nz (dma_info_mask, 4));
2358 ui_out_field_fmt (uiout, "proxydma_info_status", "0x%s",
2359 phex_nz (dma_info_status, 4));
2363 const char *query_msg;
2365 switch (dma_info_type & 3)
2367 case 0: query_msg = _("no query pending"); break;
2368 case 1: query_msg = _("'any' query pending"); break;
2369 case 2: query_msg = _("'all' query pending"); break;
2370 default: query_msg = _("undefined query type"); break;
2373 printf_filtered (_("Tag-Group Status 0x%s\n"),
2374 phex (dma_info_status, 4));
2375 printf_filtered (_("Tag-Group Mask 0x%s (%s)\n"),
2376 phex (dma_info_mask, 4), query_msg);
2377 printf_filtered ("\n");
2380 info_spu_dma_cmdlist (buf + 24, 8, byte_order);
2381 do_cleanups (chain);
2385 info_spu_command (char *args, int from_tty)
2387 printf_unfiltered (_("\"info spu\" must be followed by the name of an SPU facility.\n"));
2388 help_list (infospucmdlist, "info spu ", -1, gdb_stdout);
2392 /* Root of all "set spu "/"show spu " commands. */
2395 show_spu_command (char *args, int from_tty)
2397 help_list (showspucmdlist, "show spu ", all_commands, gdb_stdout);
2401 set_spu_command (char *args, int from_tty)
2403 help_list (setspucmdlist, "set spu ", all_commands, gdb_stdout);
2407 show_spu_stop_on_load (struct ui_file *file, int from_tty,
2408 struct cmd_list_element *c, const char *value)
2410 fprintf_filtered (file, _("Stopping for new SPE threads is %s.\n"),
2415 /* Set up gdbarch struct. */
2417 static struct gdbarch *
2418 spu_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
2420 struct gdbarch *gdbarch;
2421 struct gdbarch_tdep *tdep;
2424 /* Which spufs ID was requested as address space? */
2426 id = *(int *)info.tdep_info;
2427 /* For objfile architectures of SPU solibs, decode the ID from the name.
2428 This assumes the filename convention employed by solib-spu.c. */
2431 char *name = strrchr (info.abfd->filename, '@');
2433 sscanf (name, "@0x%*x <%d>", &id);
2436 /* Find a candidate among extant architectures. */
2437 for (arches = gdbarch_list_lookup_by_info (arches, &info);
2439 arches = gdbarch_list_lookup_by_info (arches->next, &info))
2441 tdep = gdbarch_tdep (arches->gdbarch);
2442 if (tdep && tdep->id == id)
2443 return arches->gdbarch;
2446 /* None found, so create a new architecture. */
2447 tdep = XCALLOC (1, struct gdbarch_tdep);
2449 gdbarch = gdbarch_alloc (&info, tdep);
2452 set_gdbarch_print_insn (gdbarch, gdb_print_insn_spu);
2455 set_gdbarch_num_regs (gdbarch, SPU_NUM_REGS);
2456 set_gdbarch_num_pseudo_regs (gdbarch, SPU_NUM_PSEUDO_REGS);
2457 set_gdbarch_sp_regnum (gdbarch, SPU_SP_REGNUM);
2458 set_gdbarch_pc_regnum (gdbarch, SPU_PC_REGNUM);
2459 set_gdbarch_read_pc (gdbarch, spu_read_pc);
2460 set_gdbarch_write_pc (gdbarch, spu_write_pc);
2461 set_gdbarch_register_name (gdbarch, spu_register_name);
2462 set_gdbarch_register_type (gdbarch, spu_register_type);
2463 set_gdbarch_pseudo_register_read (gdbarch, spu_pseudo_register_read);
2464 set_gdbarch_pseudo_register_write (gdbarch, spu_pseudo_register_write);
2465 set_gdbarch_value_from_register (gdbarch, spu_value_from_register);
2466 set_gdbarch_register_reggroup_p (gdbarch, spu_register_reggroup_p);
2469 set_gdbarch_char_signed (gdbarch, 0);
2470 set_gdbarch_ptr_bit (gdbarch, 32);
2471 set_gdbarch_addr_bit (gdbarch, 32);
2472 set_gdbarch_short_bit (gdbarch, 16);
2473 set_gdbarch_int_bit (gdbarch, 32);
2474 set_gdbarch_long_bit (gdbarch, 32);
2475 set_gdbarch_long_long_bit (gdbarch, 64);
2476 set_gdbarch_float_bit (gdbarch, 32);
2477 set_gdbarch_double_bit (gdbarch, 64);
2478 set_gdbarch_long_double_bit (gdbarch, 64);
2479 set_gdbarch_float_format (gdbarch, floatformats_ieee_single);
2480 set_gdbarch_double_format (gdbarch, floatformats_ieee_double);
2481 set_gdbarch_long_double_format (gdbarch, floatformats_ieee_double);
2483 /* Address conversion. */
2484 set_gdbarch_address_to_pointer (gdbarch, spu_address_to_pointer);
2485 set_gdbarch_pointer_to_address (gdbarch, spu_pointer_to_address);
2486 set_gdbarch_integer_to_address (gdbarch, spu_integer_to_address);
2488 /* Inferior function calls. */
2489 set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
2490 set_gdbarch_frame_align (gdbarch, spu_frame_align);
2491 set_gdbarch_frame_red_zone_size (gdbarch, 2000);
2492 set_gdbarch_push_dummy_code (gdbarch, spu_push_dummy_code);
2493 set_gdbarch_push_dummy_call (gdbarch, spu_push_dummy_call);
2494 set_gdbarch_dummy_id (gdbarch, spu_dummy_id);
2495 set_gdbarch_return_value (gdbarch, spu_return_value);
2497 /* Frame handling. */
2498 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
2499 frame_unwind_append_unwinder (gdbarch, &spu_frame_unwind);
2500 frame_base_set_default (gdbarch, &spu_frame_base);
2501 set_gdbarch_unwind_pc (gdbarch, spu_unwind_pc);
2502 set_gdbarch_unwind_sp (gdbarch, spu_unwind_sp);
2503 set_gdbarch_virtual_frame_pointer (gdbarch, spu_virtual_frame_pointer);
2504 set_gdbarch_frame_args_skip (gdbarch, 0);
2505 set_gdbarch_skip_prologue (gdbarch, spu_skip_prologue);
2506 set_gdbarch_in_function_epilogue_p (gdbarch, spu_in_function_epilogue_p);
2508 /* Cell/B.E. cross-architecture unwinder support. */
2509 frame_unwind_prepend_unwinder (gdbarch, &spu2ppu_unwind);
2512 set_gdbarch_decr_pc_after_break (gdbarch, 4);
2513 set_gdbarch_breakpoint_from_pc (gdbarch, spu_breakpoint_from_pc);
2514 set_gdbarch_cannot_step_breakpoint (gdbarch, 1);
2515 set_gdbarch_software_single_step (gdbarch, spu_software_single_step);
2516 set_gdbarch_get_longjmp_target (gdbarch, spu_get_longjmp_target);
2519 set_gdbarch_overlay_update (gdbarch, spu_overlay_update);
2524 /* Provide a prototype to silence -Wmissing-prototypes. */
2525 extern initialize_file_ftype _initialize_spu_tdep;
2528 _initialize_spu_tdep (void)
2530 register_gdbarch_init (bfd_arch_spu, spu_gdbarch_init);
2532 /* Add ourselves to objfile event chain. */
2533 observer_attach_new_objfile (spu_overlay_new_objfile);
2534 spu_overlay_data = register_objfile_data ();
2536 /* Install spu stop-on-load handler. */
2537 observer_attach_new_objfile (spu_catch_start);
2539 /* Add root prefix command for all "set spu"/"show spu" commands. */
2540 add_prefix_cmd ("spu", no_class, set_spu_command,
2541 _("Various SPU specific commands."),
2542 &setspucmdlist, "set spu ", 0, &setlist);
2543 add_prefix_cmd ("spu", no_class, show_spu_command,
2544 _("Various SPU specific commands."),
2545 &showspucmdlist, "show spu ", 0, &showlist);
2547 /* Toggle whether or not to add a temporary breakpoint at the "main"
2548 function of new SPE contexts. */
2549 add_setshow_boolean_cmd ("stop-on-load", class_support,
2550 &spu_stop_on_load_p, _("\
2551 Set whether to stop for new SPE threads."),
2553 Show whether to stop for new SPE threads."),
2555 Use \"on\" to give control to the user when a new SPE thread\n\
2556 enters its \"main\" function.\n\
2557 Use \"off\" to disable stopping for new SPE threads."),
2559 show_spu_stop_on_load,
2560 &setspucmdlist, &showspucmdlist);
2562 /* Add root prefix command for all "info spu" commands. */
2563 add_prefix_cmd ("spu", class_info, info_spu_command,
2564 _("Various SPU specific commands."),
2565 &infospucmdlist, "info spu ", 0, &infolist);
2567 /* Add various "info spu" commands. */
2568 add_cmd ("event", class_info, info_spu_event_command,
2569 _("Display SPU event facility status.\n"),
2571 add_cmd ("signal", class_info, info_spu_signal_command,
2572 _("Display SPU signal notification facility status.\n"),
2574 add_cmd ("mailbox", class_info, info_spu_mailbox_command,
2575 _("Display SPU mailbox facility status.\n"),
2577 add_cmd ("dma", class_info, info_spu_dma_command,
2578 _("Display MFC DMA status.\n"),
2580 add_cmd ("proxydma", class_info, info_spu_proxydma_command,
2581 _("Display MFC Proxy-DMA status.\n"),