1 /* SPU target-dependent code for GDB, the GNU debugger.
2 Copyright (C) 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
4 Contributed by Ulrich Weigand <uweigand@de.ibm.com>.
5 Based on a port by Sid Manning <sid@us.ibm.com>.
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"
48 /* The tdep structure. */
51 /* The spufs ID identifying our address space. */
54 /* SPU-specific vector type. */
55 struct type
*spu_builtin_type_vec128
;
59 /* SPU-specific vector type. */
61 spu_builtin_type_vec128 (struct gdbarch
*gdbarch
)
63 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
65 if (!tdep
->spu_builtin_type_vec128
)
67 const struct builtin_type
*bt
= builtin_type (gdbarch
);
70 t
= arch_composite_type (gdbarch
,
71 "__spu_builtin_type_vec128", TYPE_CODE_UNION
);
72 append_composite_type_field (t
, "uint128", bt
->builtin_int128
);
73 append_composite_type_field (t
, "v2_int64",
74 init_vector_type (bt
->builtin_int64
, 2));
75 append_composite_type_field (t
, "v4_int32",
76 init_vector_type (bt
->builtin_int32
, 4));
77 append_composite_type_field (t
, "v8_int16",
78 init_vector_type (bt
->builtin_int16
, 8));
79 append_composite_type_field (t
, "v16_int8",
80 init_vector_type (bt
->builtin_int8
, 16));
81 append_composite_type_field (t
, "v2_double",
82 init_vector_type (bt
->builtin_double
, 2));
83 append_composite_type_field (t
, "v4_float",
84 init_vector_type (bt
->builtin_float
, 4));
87 TYPE_NAME (t
) = "spu_builtin_type_vec128";
89 tdep
->spu_builtin_type_vec128
= t
;
92 return tdep
->spu_builtin_type_vec128
;
96 /* The list of available "info spu " commands. */
97 static struct cmd_list_element
*infospucmdlist
= NULL
;
102 spu_register_name (struct gdbarch
*gdbarch
, int reg_nr
)
104 static char *register_names
[] =
106 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
107 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
108 "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
109 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
110 "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
111 "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
112 "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
113 "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
114 "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
115 "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
116 "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
117 "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
118 "r96", "r97", "r98", "r99", "r100", "r101", "r102", "r103",
119 "r104", "r105", "r106", "r107", "r108", "r109", "r110", "r111",
120 "r112", "r113", "r114", "r115", "r116", "r117", "r118", "r119",
121 "r120", "r121", "r122", "r123", "r124", "r125", "r126", "r127",
122 "id", "pc", "sp", "fpscr", "srr0", "lslr", "decr", "decr_status"
127 if (reg_nr
>= sizeof register_names
/ sizeof *register_names
)
130 return register_names
[reg_nr
];
134 spu_register_type (struct gdbarch
*gdbarch
, int reg_nr
)
136 if (reg_nr
< SPU_NUM_GPRS
)
137 return spu_builtin_type_vec128 (gdbarch
);
142 return builtin_type (gdbarch
)->builtin_uint32
;
145 return builtin_type (gdbarch
)->builtin_func_ptr
;
148 return builtin_type (gdbarch
)->builtin_data_ptr
;
150 case SPU_FPSCR_REGNUM
:
151 return builtin_type (gdbarch
)->builtin_uint128
;
153 case SPU_SRR0_REGNUM
:
154 return builtin_type (gdbarch
)->builtin_uint32
;
156 case SPU_LSLR_REGNUM
:
157 return builtin_type (gdbarch
)->builtin_uint32
;
159 case SPU_DECR_REGNUM
:
160 return builtin_type (gdbarch
)->builtin_uint32
;
162 case SPU_DECR_STATUS_REGNUM
:
163 return builtin_type (gdbarch
)->builtin_uint32
;
166 internal_error (__FILE__
, __LINE__
, "invalid regnum");
170 /* Pseudo registers for preferred slots - stack pointer. */
173 spu_pseudo_register_read_spu (struct regcache
*regcache
, const char *regname
,
176 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
177 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
182 regcache_raw_read_unsigned (regcache
, SPU_ID_REGNUM
, &id
);
183 xsnprintf (annex
, sizeof annex
, "%d/%s", (int) id
, regname
);
184 memset (reg
, 0, sizeof reg
);
185 target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
188 store_unsigned_integer (buf
, 4, byte_order
, strtoulst (reg
, NULL
, 16));
192 spu_pseudo_register_read (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
193 int regnum
, gdb_byte
*buf
)
202 regcache_raw_read (regcache
, SPU_RAW_SP_REGNUM
, reg
);
203 memcpy (buf
, reg
, 4);
206 case SPU_FPSCR_REGNUM
:
207 regcache_raw_read_unsigned (regcache
, SPU_ID_REGNUM
, &id
);
208 xsnprintf (annex
, sizeof annex
, "%d/fpcr", (int) id
);
209 target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
, buf
, 0, 16);
212 case SPU_SRR0_REGNUM
:
213 spu_pseudo_register_read_spu (regcache
, "srr0", buf
);
216 case SPU_LSLR_REGNUM
:
217 spu_pseudo_register_read_spu (regcache
, "lslr", buf
);
220 case SPU_DECR_REGNUM
:
221 spu_pseudo_register_read_spu (regcache
, "decr", buf
);
224 case SPU_DECR_STATUS_REGNUM
:
225 spu_pseudo_register_read_spu (regcache
, "decr_status", buf
);
229 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
234 spu_pseudo_register_write_spu (struct regcache
*regcache
, const char *regname
,
237 struct gdbarch
*gdbarch
= get_regcache_arch (regcache
);
238 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
243 regcache_raw_read_unsigned (regcache
, SPU_ID_REGNUM
, &id
);
244 xsnprintf (annex
, sizeof annex
, "%d/%s", (int) id
, regname
);
245 xsnprintf (reg
, sizeof reg
, "0x%s",
246 phex_nz (extract_unsigned_integer (buf
, 4, byte_order
), 4));
247 target_write (¤t_target
, TARGET_OBJECT_SPU
, annex
,
248 reg
, 0, strlen (reg
));
252 spu_pseudo_register_write (struct gdbarch
*gdbarch
, struct regcache
*regcache
,
253 int regnum
, const gdb_byte
*buf
)
262 regcache_raw_read (regcache
, SPU_RAW_SP_REGNUM
, reg
);
263 memcpy (reg
, buf
, 4);
264 regcache_raw_write (regcache
, SPU_RAW_SP_REGNUM
, reg
);
267 case SPU_FPSCR_REGNUM
:
268 regcache_raw_read_unsigned (regcache
, SPU_ID_REGNUM
, &id
);
269 xsnprintf (annex
, sizeof annex
, "%d/fpcr", (int) id
);
270 target_write (¤t_target
, TARGET_OBJECT_SPU
, annex
, buf
, 0, 16);
273 case SPU_SRR0_REGNUM
:
274 spu_pseudo_register_write_spu (regcache
, "srr0", buf
);
277 case SPU_LSLR_REGNUM
:
278 spu_pseudo_register_write_spu (regcache
, "lslr", buf
);
281 case SPU_DECR_REGNUM
:
282 spu_pseudo_register_write_spu (regcache
, "decr", buf
);
285 case SPU_DECR_STATUS_REGNUM
:
286 spu_pseudo_register_write_spu (regcache
, "decr_status", buf
);
290 internal_error (__FILE__
, __LINE__
, _("invalid regnum"));
294 /* Value conversion -- access scalar values at the preferred slot. */
296 static struct value
*
297 spu_value_from_register (struct type
*type
, int regnum
,
298 struct frame_info
*frame
)
300 struct value
*value
= default_value_from_register (type
, regnum
, frame
);
301 int len
= TYPE_LENGTH (type
);
303 if (regnum
< SPU_NUM_GPRS
&& len
< 16)
305 int preferred_slot
= len
< 4 ? 4 - len
: 0;
306 set_value_offset (value
, preferred_slot
);
312 /* Register groups. */
315 spu_register_reggroup_p (struct gdbarch
*gdbarch
, int regnum
,
316 struct reggroup
*group
)
318 /* Registers displayed via 'info regs'. */
319 if (group
== general_reggroup
)
322 /* Registers displayed via 'info float'. */
323 if (group
== float_reggroup
)
326 /* Registers that need to be saved/restored in order to
327 push or pop frames. */
328 if (group
== save_reggroup
|| group
== restore_reggroup
)
331 return default_register_reggroup_p (gdbarch
, regnum
, group
);
334 /* Address conversion. */
337 spu_gdbarch_id (struct gdbarch
*gdbarch
)
339 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
342 /* The objfile architecture of a standalone SPU executable does not
343 provide an SPU ID. Retrieve it from the the objfile's relocated
344 address range in this special case. */
346 && symfile_objfile
&& symfile_objfile
->obfd
347 && bfd_get_arch (symfile_objfile
->obfd
) == bfd_arch_spu
348 && symfile_objfile
->sections
!= symfile_objfile
->sections_end
)
349 id
= SPUADDR_SPU (obj_section_addr (symfile_objfile
->sections
));
361 return SPU_LS_SIZE
- 1;
363 xsnprintf (annex
, sizeof annex
, "%d/lslr", id
);
364 memset (buf
, 0, sizeof buf
);
365 target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
368 return strtoulst (buf
, NULL
, 16);
372 spu_address_to_pointer (struct gdbarch
*gdbarch
,
373 struct type
*type
, gdb_byte
*buf
, CORE_ADDR addr
)
375 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
376 store_unsigned_integer (buf
, TYPE_LENGTH (type
), byte_order
,
377 SPUADDR_ADDR (addr
));
381 spu_pointer_to_address (struct gdbarch
*gdbarch
,
382 struct type
*type
, const gdb_byte
*buf
)
384 int id
= spu_gdbarch_id (gdbarch
);
385 ULONGEST lslr
= spu_lslr (id
);
386 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
388 = extract_unsigned_integer (buf
, TYPE_LENGTH (type
), byte_order
);
390 return addr
? SPUADDR (id
, addr
& lslr
) : 0;
394 spu_integer_to_address (struct gdbarch
*gdbarch
,
395 struct type
*type
, const gdb_byte
*buf
)
397 int id
= spu_gdbarch_id (gdbarch
);
398 ULONGEST lslr
= spu_lslr (id
);
399 ULONGEST addr
= unpack_long (type
, buf
);
401 return SPUADDR (id
, addr
& lslr
);
405 /* Decoding SPU instructions. */
442 is_rr (unsigned int insn
, int op
, int *rt
, int *ra
, int *rb
)
444 if ((insn
>> 21) == op
)
447 *ra
= (insn
>> 7) & 127;
448 *rb
= (insn
>> 14) & 127;
456 is_rrr (unsigned int insn
, int op
, int *rt
, int *ra
, int *rb
, int *rc
)
458 if ((insn
>> 28) == op
)
460 *rt
= (insn
>> 21) & 127;
461 *ra
= (insn
>> 7) & 127;
462 *rb
= (insn
>> 14) & 127;
471 is_ri7 (unsigned int insn
, int op
, int *rt
, int *ra
, int *i7
)
473 if ((insn
>> 21) == op
)
476 *ra
= (insn
>> 7) & 127;
477 *i7
= (((insn
>> 14) & 127) ^ 0x40) - 0x40;
485 is_ri10 (unsigned int insn
, int op
, int *rt
, int *ra
, int *i10
)
487 if ((insn
>> 24) == op
)
490 *ra
= (insn
>> 7) & 127;
491 *i10
= (((insn
>> 14) & 0x3ff) ^ 0x200) - 0x200;
499 is_ri16 (unsigned int insn
, int op
, int *rt
, int *i16
)
501 if ((insn
>> 23) == op
)
504 *i16
= (((insn
>> 7) & 0xffff) ^ 0x8000) - 0x8000;
512 is_ri18 (unsigned int insn
, int op
, int *rt
, int *i18
)
514 if ((insn
>> 25) == op
)
517 *i18
= (((insn
>> 7) & 0x3ffff) ^ 0x20000) - 0x20000;
525 is_branch (unsigned int insn
, int *offset
, int *reg
)
529 if (is_ri16 (insn
, op_br
, &rt
, &i16
)
530 || is_ri16 (insn
, op_brsl
, &rt
, &i16
)
531 || is_ri16 (insn
, op_brnz
, &rt
, &i16
)
532 || is_ri16 (insn
, op_brz
, &rt
, &i16
)
533 || is_ri16 (insn
, op_brhnz
, &rt
, &i16
)
534 || is_ri16 (insn
, op_brhz
, &rt
, &i16
))
536 *reg
= SPU_PC_REGNUM
;
541 if (is_ri16 (insn
, op_bra
, &rt
, &i16
)
542 || is_ri16 (insn
, op_brasl
, &rt
, &i16
))
549 if (is_ri7 (insn
, op_bi
, &rt
, reg
, &i7
)
550 || is_ri7 (insn
, op_bisl
, &rt
, reg
, &i7
)
551 || is_ri7 (insn
, op_biz
, &rt
, reg
, &i7
)
552 || is_ri7 (insn
, op_binz
, &rt
, reg
, &i7
)
553 || is_ri7 (insn
, op_bihz
, &rt
, reg
, &i7
)
554 || is_ri7 (insn
, op_bihnz
, &rt
, reg
, &i7
))
564 /* Prolog parsing. */
566 struct spu_prologue_data
568 /* Stack frame size. -1 if analysis was unsuccessful. */
571 /* How to find the CFA. The CFA is equal to SP at function entry. */
575 /* Offset relative to CFA where a register is saved. -1 if invalid. */
576 int reg_offset
[SPU_NUM_GPRS
];
580 spu_analyze_prologue (struct gdbarch
*gdbarch
,
581 CORE_ADDR start_pc
, CORE_ADDR end_pc
,
582 struct spu_prologue_data
*data
)
584 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
588 int reg_immed
[SPU_NUM_GPRS
];
590 CORE_ADDR prolog_pc
= start_pc
;
595 /* Initialize DATA to default values. */
598 data
->cfa_reg
= SPU_RAW_SP_REGNUM
;
599 data
->cfa_offset
= 0;
601 for (i
= 0; i
< SPU_NUM_GPRS
; i
++)
602 data
->reg_offset
[i
] = -1;
604 /* Set up REG_IMMED array. This is non-zero for a register if we know its
605 preferred slot currently holds this immediate value. */
606 for (i
= 0; i
< SPU_NUM_GPRS
; i
++)
609 /* Scan instructions until the first branch.
611 The following instructions are important prolog components:
613 - The first instruction to set up the stack pointer.
614 - The first instruction to set up the frame pointer.
615 - The first instruction to save the link register.
617 We return the instruction after the latest of these three,
618 or the incoming PC if none is found. The first instruction
619 to set up the stack pointer also defines the frame size.
621 Note that instructions saving incoming arguments to their stack
622 slots are not counted as important, because they are hard to
623 identify with certainty. This should not matter much, because
624 arguments are relevant only in code compiled with debug data,
625 and in such code the GDB core will advance until the first source
626 line anyway, using SAL data.
628 For purposes of stack unwinding, we analyze the following types
629 of instructions in addition:
631 - Any instruction adding to the current frame pointer.
632 - Any instruction loading an immediate constant into a register.
633 - Any instruction storing a register onto the stack.
635 These are used to compute the CFA and REG_OFFSET output. */
637 for (pc
= start_pc
; pc
< end_pc
; pc
+= 4)
640 int rt
, ra
, rb
, rc
, immed
;
642 if (target_read_memory (pc
, buf
, 4))
644 insn
= extract_unsigned_integer (buf
, 4, byte_order
);
646 /* AI is the typical instruction to set up a stack frame.
647 It is also used to initialize the frame pointer. */
648 if (is_ri10 (insn
, op_ai
, &rt
, &ra
, &immed
))
650 if (rt
== data
->cfa_reg
&& ra
== data
->cfa_reg
)
651 data
->cfa_offset
-= immed
;
653 if (rt
== SPU_RAW_SP_REGNUM
&& ra
== SPU_RAW_SP_REGNUM
661 else if (rt
== SPU_FP_REGNUM
&& ra
== SPU_RAW_SP_REGNUM
667 data
->cfa_reg
= SPU_FP_REGNUM
;
668 data
->cfa_offset
-= immed
;
672 /* A is used to set up stack frames of size >= 512 bytes.
673 If we have tracked the contents of the addend register,
674 we can handle this as well. */
675 else if (is_rr (insn
, op_a
, &rt
, &ra
, &rb
))
677 if (rt
== data
->cfa_reg
&& ra
== data
->cfa_reg
)
679 if (reg_immed
[rb
] != 0)
680 data
->cfa_offset
-= reg_immed
[rb
];
682 data
->cfa_reg
= -1; /* We don't know the CFA any more. */
685 if (rt
== SPU_RAW_SP_REGNUM
&& ra
== SPU_RAW_SP_REGNUM
691 if (reg_immed
[rb
] != 0)
692 data
->size
= -reg_immed
[rb
];
696 /* We need to track IL and ILA used to load immediate constants
697 in case they are later used as input to an A instruction. */
698 else if (is_ri16 (insn
, op_il
, &rt
, &immed
))
700 reg_immed
[rt
] = immed
;
702 if (rt
== SPU_RAW_SP_REGNUM
&& !found_sp
)
706 else if (is_ri18 (insn
, op_ila
, &rt
, &immed
))
708 reg_immed
[rt
] = immed
& 0x3ffff;
710 if (rt
== SPU_RAW_SP_REGNUM
&& !found_sp
)
714 /* STQD is used to save registers to the stack. */
715 else if (is_ri10 (insn
, op_stqd
, &rt
, &ra
, &immed
))
717 if (ra
== data
->cfa_reg
)
718 data
->reg_offset
[rt
] = data
->cfa_offset
- (immed
<< 4);
720 if (ra
== data
->cfa_reg
&& rt
== SPU_LR_REGNUM
728 /* _start uses SELB to set up the stack pointer. */
729 else if (is_rrr (insn
, op_selb
, &rt
, &ra
, &rb
, &rc
))
731 if (rt
== SPU_RAW_SP_REGNUM
&& !found_sp
)
735 /* We terminate if we find a branch. */
736 else if (is_branch (insn
, &immed
, &ra
))
741 /* If we successfully parsed until here, and didn't find any instruction
742 modifying SP, we assume we have a frameless function. */
746 /* Return cooked instead of raw SP. */
747 if (data
->cfa_reg
== SPU_RAW_SP_REGNUM
)
748 data
->cfa_reg
= SPU_SP_REGNUM
;
753 /* Return the first instruction after the prologue starting at PC. */
755 spu_skip_prologue (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
757 struct spu_prologue_data data
;
758 return spu_analyze_prologue (gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
761 /* Return the frame pointer in use at address PC. */
763 spu_virtual_frame_pointer (struct gdbarch
*gdbarch
, CORE_ADDR pc
,
764 int *reg
, LONGEST
*offset
)
766 struct spu_prologue_data data
;
767 spu_analyze_prologue (gdbarch
, pc
, (CORE_ADDR
)-1, &data
);
769 if (data
.size
!= -1 && data
.cfa_reg
!= -1)
771 /* The 'frame pointer' address is CFA minus frame size. */
773 *offset
= data
.cfa_offset
- data
.size
;
777 /* ??? We don't really know ... */
778 *reg
= SPU_SP_REGNUM
;
783 /* Return true if we are in the function's epilogue, i.e. after the
784 instruction that destroyed the function's stack frame.
786 1) scan forward from the point of execution:
787 a) If you find an instruction that modifies the stack pointer
788 or transfers control (except a return), execution is not in
790 b) Stop scanning if you find a return instruction or reach the
791 end of the function or reach the hard limit for the size of
793 2) scan backward from the point of execution:
794 a) If you find an instruction that modifies the stack pointer,
795 execution *is* in an epilogue, return.
796 b) Stop scanning if you reach an instruction that transfers
797 control or the beginning of the function or reach the hard
798 limit for the size of an epilogue. */
801 spu_in_function_epilogue_p (struct gdbarch
*gdbarch
, CORE_ADDR pc
)
803 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
804 CORE_ADDR scan_pc
, func_start
, func_end
, epilogue_start
, epilogue_end
;
807 int rt
, ra
, rb
, rc
, immed
;
809 /* Find the search limits based on function boundaries and hard limit.
810 We assume the epilogue can be up to 64 instructions long. */
812 const int spu_max_epilogue_size
= 64 * 4;
814 if (!find_pc_partial_function (pc
, NULL
, &func_start
, &func_end
))
817 if (pc
- func_start
< spu_max_epilogue_size
)
818 epilogue_start
= func_start
;
820 epilogue_start
= pc
- spu_max_epilogue_size
;
822 if (func_end
- pc
< spu_max_epilogue_size
)
823 epilogue_end
= func_end
;
825 epilogue_end
= pc
+ spu_max_epilogue_size
;
827 /* Scan forward until next 'bi $0'. */
829 for (scan_pc
= pc
; scan_pc
< epilogue_end
; scan_pc
+= 4)
831 if (target_read_memory (scan_pc
, buf
, 4))
833 insn
= extract_unsigned_integer (buf
, 4, byte_order
);
835 if (is_branch (insn
, &immed
, &ra
))
837 if (immed
== 0 && ra
== SPU_LR_REGNUM
)
843 if (is_ri10 (insn
, op_ai
, &rt
, &ra
, &immed
)
844 || is_rr (insn
, op_a
, &rt
, &ra
, &rb
)
845 || is_ri10 (insn
, op_lqd
, &rt
, &ra
, &immed
))
847 if (rt
== SPU_RAW_SP_REGNUM
)
852 if (scan_pc
>= epilogue_end
)
855 /* Scan backward until adjustment to stack pointer (R1). */
857 for (scan_pc
= pc
- 4; scan_pc
>= epilogue_start
; scan_pc
-= 4)
859 if (target_read_memory (scan_pc
, buf
, 4))
861 insn
= extract_unsigned_integer (buf
, 4, byte_order
);
863 if (is_branch (insn
, &immed
, &ra
))
866 if (is_ri10 (insn
, op_ai
, &rt
, &ra
, &immed
)
867 || is_rr (insn
, op_a
, &rt
, &ra
, &rb
)
868 || is_ri10 (insn
, op_lqd
, &rt
, &ra
, &immed
))
870 if (rt
== SPU_RAW_SP_REGNUM
)
879 /* Normal stack frames. */
881 struct spu_unwind_cache
884 CORE_ADDR frame_base
;
885 CORE_ADDR local_base
;
887 struct trad_frame_saved_reg
*saved_regs
;
890 static struct spu_unwind_cache
*
891 spu_frame_unwind_cache (struct frame_info
*this_frame
,
892 void **this_prologue_cache
)
894 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
895 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
896 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
897 struct spu_unwind_cache
*info
;
898 struct spu_prologue_data data
;
899 CORE_ADDR id
= tdep
->id
;
902 if (*this_prologue_cache
)
903 return *this_prologue_cache
;
905 info
= FRAME_OBSTACK_ZALLOC (struct spu_unwind_cache
);
906 *this_prologue_cache
= info
;
907 info
->saved_regs
= trad_frame_alloc_saved_regs (this_frame
);
908 info
->frame_base
= 0;
909 info
->local_base
= 0;
911 /* Find the start of the current function, and analyze its prologue. */
912 info
->func
= get_frame_func (this_frame
);
915 /* Fall back to using the current PC as frame ID. */
916 info
->func
= get_frame_pc (this_frame
);
920 spu_analyze_prologue (gdbarch
, info
->func
, get_frame_pc (this_frame
),
923 /* If successful, use prologue analysis data. */
924 if (data
.size
!= -1 && data
.cfa_reg
!= -1)
929 /* Determine CFA via unwound CFA_REG plus CFA_OFFSET. */
930 get_frame_register (this_frame
, data
.cfa_reg
, buf
);
931 cfa
= extract_unsigned_integer (buf
, 4, byte_order
) + data
.cfa_offset
;
932 cfa
= SPUADDR (id
, cfa
);
934 /* Call-saved register slots. */
935 for (i
= 0; i
< SPU_NUM_GPRS
; i
++)
936 if (i
== SPU_LR_REGNUM
937 || (i
>= SPU_SAVED1_REGNUM
&& i
<= SPU_SAVEDN_REGNUM
))
938 if (data
.reg_offset
[i
] != -1)
939 info
->saved_regs
[i
].addr
= cfa
- data
.reg_offset
[i
];
942 info
->frame_base
= cfa
;
943 info
->local_base
= cfa
- data
.size
;
946 /* Otherwise, fall back to reading the backchain link. */
953 /* Get the backchain. */
954 reg
= get_frame_register_unsigned (this_frame
, SPU_SP_REGNUM
);
955 status
= safe_read_memory_integer (SPUADDR (id
, reg
), 4, byte_order
,
958 /* A zero backchain terminates the frame chain. Also, sanity
959 check against the local store size limit. */
960 if (status
&& backchain
> 0 && backchain
< SPU_LS_SIZE
)
962 /* Assume the link register is saved into its slot. */
963 if (backchain
+ 16 < SPU_LS_SIZE
)
964 info
->saved_regs
[SPU_LR_REGNUM
].addr
= SPUADDR (id
, backchain
+ 16);
967 info
->frame_base
= SPUADDR (id
, backchain
);
968 info
->local_base
= SPUADDR (id
, reg
);
972 /* If we didn't find a frame, we cannot determine SP / return address. */
973 if (info
->frame_base
== 0)
976 /* The previous SP is equal to the CFA. */
977 trad_frame_set_value (info
->saved_regs
, SPU_SP_REGNUM
,
978 SPUADDR_ADDR (info
->frame_base
));
980 /* Read full contents of the unwound link register in order to
981 be able to determine the return address. */
982 if (trad_frame_addr_p (info
->saved_regs
, SPU_LR_REGNUM
))
983 target_read_memory (info
->saved_regs
[SPU_LR_REGNUM
].addr
, buf
, 16);
985 get_frame_register (this_frame
, SPU_LR_REGNUM
, buf
);
987 /* Normally, the return address is contained in the slot 0 of the
988 link register, and slots 1-3 are zero. For an overlay return,
989 slot 0 contains the address of the overlay manager return stub,
990 slot 1 contains the partition number of the overlay section to
991 be returned to, and slot 2 contains the return address within
992 that section. Return the latter address in that case. */
993 if (extract_unsigned_integer (buf
+ 8, 4, byte_order
) != 0)
994 trad_frame_set_value (info
->saved_regs
, SPU_PC_REGNUM
,
995 extract_unsigned_integer (buf
+ 8, 4, byte_order
));
997 trad_frame_set_value (info
->saved_regs
, SPU_PC_REGNUM
,
998 extract_unsigned_integer (buf
, 4, byte_order
));
1004 spu_frame_this_id (struct frame_info
*this_frame
,
1005 void **this_prologue_cache
, struct frame_id
*this_id
)
1007 struct spu_unwind_cache
*info
=
1008 spu_frame_unwind_cache (this_frame
, this_prologue_cache
);
1010 if (info
->frame_base
== 0)
1013 *this_id
= frame_id_build (info
->frame_base
, info
->func
);
1016 static struct value
*
1017 spu_frame_prev_register (struct frame_info
*this_frame
,
1018 void **this_prologue_cache
, int regnum
)
1020 struct spu_unwind_cache
*info
1021 = spu_frame_unwind_cache (this_frame
, this_prologue_cache
);
1023 /* Special-case the stack pointer. */
1024 if (regnum
== SPU_RAW_SP_REGNUM
)
1025 regnum
= SPU_SP_REGNUM
;
1027 return trad_frame_get_prev_register (this_frame
, info
->saved_regs
, regnum
);
1030 static const struct frame_unwind spu_frame_unwind
= {
1033 spu_frame_prev_register
,
1035 default_frame_sniffer
1039 spu_frame_base_address (struct frame_info
*this_frame
, void **this_cache
)
1041 struct spu_unwind_cache
*info
1042 = spu_frame_unwind_cache (this_frame
, this_cache
);
1043 return info
->local_base
;
1046 static const struct frame_base spu_frame_base
= {
1048 spu_frame_base_address
,
1049 spu_frame_base_address
,
1050 spu_frame_base_address
1054 spu_unwind_pc (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1056 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1057 CORE_ADDR pc
= frame_unwind_register_unsigned (next_frame
, SPU_PC_REGNUM
);
1058 /* Mask off interrupt enable bit. */
1059 return SPUADDR (tdep
->id
, pc
& -4);
1063 spu_unwind_sp (struct gdbarch
*gdbarch
, struct frame_info
*next_frame
)
1065 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1066 CORE_ADDR sp
= frame_unwind_register_unsigned (next_frame
, SPU_SP_REGNUM
);
1067 return SPUADDR (tdep
->id
, sp
);
1071 spu_read_pc (struct regcache
*regcache
)
1073 struct gdbarch_tdep
*tdep
= gdbarch_tdep (get_regcache_arch (regcache
));
1075 regcache_cooked_read_unsigned (regcache
, SPU_PC_REGNUM
, &pc
);
1076 /* Mask off interrupt enable bit. */
1077 return SPUADDR (tdep
->id
, pc
& -4);
1081 spu_write_pc (struct regcache
*regcache
, CORE_ADDR pc
)
1083 /* Keep interrupt enabled state unchanged. */
1085 regcache_cooked_read_unsigned (regcache
, SPU_PC_REGNUM
, &old_pc
);
1086 regcache_cooked_write_unsigned (regcache
, SPU_PC_REGNUM
,
1087 (SPUADDR_ADDR (pc
) & -4) | (old_pc
& 3));
1091 /* Cell/B.E. cross-architecture unwinder support. */
1093 struct spu2ppu_cache
1095 struct frame_id frame_id
;
1096 struct regcache
*regcache
;
1099 static struct gdbarch
*
1100 spu2ppu_prev_arch (struct frame_info
*this_frame
, void **this_cache
)
1102 struct spu2ppu_cache
*cache
= *this_cache
;
1103 return get_regcache_arch (cache
->regcache
);
1107 spu2ppu_this_id (struct frame_info
*this_frame
,
1108 void **this_cache
, struct frame_id
*this_id
)
1110 struct spu2ppu_cache
*cache
= *this_cache
;
1111 *this_id
= cache
->frame_id
;
1114 static struct value
*
1115 spu2ppu_prev_register (struct frame_info
*this_frame
,
1116 void **this_cache
, int regnum
)
1118 struct spu2ppu_cache
*cache
= *this_cache
;
1119 struct gdbarch
*gdbarch
= get_regcache_arch (cache
->regcache
);
1122 buf
= alloca (register_size (gdbarch
, regnum
));
1123 regcache_cooked_read (cache
->regcache
, regnum
, buf
);
1124 return frame_unwind_got_bytes (this_frame
, regnum
, buf
);
1128 spu2ppu_sniffer (const struct frame_unwind
*self
,
1129 struct frame_info
*this_frame
, void **this_prologue_cache
)
1131 struct gdbarch
*gdbarch
= get_frame_arch (this_frame
);
1132 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1133 CORE_ADDR base
, func
, backchain
;
1136 if (gdbarch_bfd_arch_info (target_gdbarch
)->arch
== bfd_arch_spu
)
1139 base
= get_frame_sp (this_frame
);
1140 func
= get_frame_pc (this_frame
);
1141 if (target_read_memory (base
, buf
, 4))
1143 backchain
= extract_unsigned_integer (buf
, 4, byte_order
);
1147 struct frame_info
*fi
;
1149 struct spu2ppu_cache
*cache
1150 = FRAME_OBSTACK_CALLOC (1, struct spu2ppu_cache
);
1152 cache
->frame_id
= frame_id_build (base
+ 16, func
);
1154 for (fi
= get_next_frame (this_frame
); fi
; fi
= get_next_frame (fi
))
1155 if (gdbarch_bfd_arch_info (get_frame_arch (fi
))->arch
!= bfd_arch_spu
)
1160 cache
->regcache
= frame_save_as_regcache (fi
);
1161 *this_prologue_cache
= cache
;
1166 struct regcache
*regcache
;
1167 regcache
= get_thread_arch_regcache (inferior_ptid
, target_gdbarch
);
1168 cache
->regcache
= regcache_dup (regcache
);
1169 *this_prologue_cache
= cache
;
1178 spu2ppu_dealloc_cache (struct frame_info
*self
, void *this_cache
)
1180 struct spu2ppu_cache
*cache
= this_cache
;
1181 regcache_xfree (cache
->regcache
);
1184 static const struct frame_unwind spu2ppu_unwind
= {
1187 spu2ppu_prev_register
,
1190 spu2ppu_dealloc_cache
,
1195 /* Function calling convention. */
1198 spu_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR sp
)
1204 spu_push_dummy_code (struct gdbarch
*gdbarch
, CORE_ADDR sp
, CORE_ADDR funaddr
,
1205 struct value
**args
, int nargs
, struct type
*value_type
,
1206 CORE_ADDR
*real_pc
, CORE_ADDR
*bp_addr
,
1207 struct regcache
*regcache
)
1209 /* Allocate space sufficient for a breakpoint, keeping the stack aligned. */
1210 sp
= (sp
- 4) & ~15;
1211 /* Store the address of that breakpoint */
1213 /* The call starts at the callee's entry point. */
1220 spu_scalar_value_p (struct type
*type
)
1222 switch (TYPE_CODE (type
))
1225 case TYPE_CODE_ENUM
:
1226 case TYPE_CODE_RANGE
:
1227 case TYPE_CODE_CHAR
:
1228 case TYPE_CODE_BOOL
:
1231 return TYPE_LENGTH (type
) <= 16;
1239 spu_value_to_regcache (struct regcache
*regcache
, int regnum
,
1240 struct type
*type
, const gdb_byte
*in
)
1242 int len
= TYPE_LENGTH (type
);
1244 if (spu_scalar_value_p (type
))
1246 int preferred_slot
= len
< 4 ? 4 - len
: 0;
1247 regcache_cooked_write_part (regcache
, regnum
, preferred_slot
, len
, in
);
1253 regcache_cooked_write (regcache
, regnum
++, in
);
1259 regcache_cooked_write_part (regcache
, regnum
, 0, len
, in
);
1264 spu_regcache_to_value (struct regcache
*regcache
, int regnum
,
1265 struct type
*type
, gdb_byte
*out
)
1267 int len
= TYPE_LENGTH (type
);
1269 if (spu_scalar_value_p (type
))
1271 int preferred_slot
= len
< 4 ? 4 - len
: 0;
1272 regcache_cooked_read_part (regcache
, regnum
, preferred_slot
, len
, out
);
1278 regcache_cooked_read (regcache
, regnum
++, out
);
1284 regcache_cooked_read_part (regcache
, regnum
, 0, len
, out
);
1289 spu_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
1290 struct regcache
*regcache
, CORE_ADDR bp_addr
,
1291 int nargs
, struct value
**args
, CORE_ADDR sp
,
1292 int struct_return
, CORE_ADDR struct_addr
)
1294 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1297 int regnum
= SPU_ARG1_REGNUM
;
1301 /* Set the return address. */
1302 memset (buf
, 0, sizeof buf
);
1303 store_unsigned_integer (buf
, 4, byte_order
, SPUADDR_ADDR (bp_addr
));
1304 regcache_cooked_write (regcache
, SPU_LR_REGNUM
, buf
);
1306 /* If STRUCT_RETURN is true, then the struct return address (in
1307 STRUCT_ADDR) will consume the first argument-passing register.
1308 Both adjust the register count and store that value. */
1311 memset (buf
, 0, sizeof buf
);
1312 store_unsigned_integer (buf
, 4, byte_order
, SPUADDR_ADDR (struct_addr
));
1313 regcache_cooked_write (regcache
, regnum
++, buf
);
1316 /* Fill in argument registers. */
1317 for (i
= 0; i
< nargs
; i
++)
1319 struct value
*arg
= args
[i
];
1320 struct type
*type
= check_typedef (value_type (arg
));
1321 const gdb_byte
*contents
= value_contents (arg
);
1322 int len
= TYPE_LENGTH (type
);
1323 int n_regs
= align_up (len
, 16) / 16;
1325 /* If the argument doesn't wholly fit into registers, it and
1326 all subsequent arguments go to the stack. */
1327 if (regnum
+ n_regs
- 1 > SPU_ARGN_REGNUM
)
1333 spu_value_to_regcache (regcache
, regnum
, type
, contents
);
1337 /* Overflow arguments go to the stack. */
1338 if (stack_arg
!= -1)
1342 /* Allocate all required stack size. */
1343 for (i
= stack_arg
; i
< nargs
; i
++)
1345 struct type
*type
= check_typedef (value_type (args
[i
]));
1346 sp
-= align_up (TYPE_LENGTH (type
), 16);
1349 /* Fill in stack arguments. */
1351 for (i
= stack_arg
; i
< nargs
; i
++)
1353 struct value
*arg
= args
[i
];
1354 struct type
*type
= check_typedef (value_type (arg
));
1355 int len
= TYPE_LENGTH (type
);
1358 if (spu_scalar_value_p (type
))
1359 preferred_slot
= len
< 4 ? 4 - len
: 0;
1363 target_write_memory (ap
+ preferred_slot
, value_contents (arg
), len
);
1364 ap
+= align_up (TYPE_LENGTH (type
), 16);
1368 /* Allocate stack frame header. */
1371 /* Store stack back chain. */
1372 regcache_cooked_read (regcache
, SPU_RAW_SP_REGNUM
, buf
);
1373 target_write_memory (sp
, buf
, 16);
1375 /* Finally, update all slots of the SP register. */
1376 sp_delta
= sp
- extract_unsigned_integer (buf
, 4, byte_order
);
1377 for (i
= 0; i
< 4; i
++)
1379 CORE_ADDR sp_slot
= extract_unsigned_integer (buf
+ 4*i
, 4, byte_order
);
1380 store_unsigned_integer (buf
+ 4*i
, 4, byte_order
, sp_slot
+ sp_delta
);
1382 regcache_cooked_write (regcache
, SPU_RAW_SP_REGNUM
, buf
);
1387 static struct frame_id
1388 spu_dummy_id (struct gdbarch
*gdbarch
, struct frame_info
*this_frame
)
1390 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1391 CORE_ADDR pc
= get_frame_register_unsigned (this_frame
, SPU_PC_REGNUM
);
1392 CORE_ADDR sp
= get_frame_register_unsigned (this_frame
, SPU_SP_REGNUM
);
1393 return frame_id_build (SPUADDR (tdep
->id
, sp
), SPUADDR (tdep
->id
, pc
& -4));
1396 /* Function return value access. */
1398 static enum return_value_convention
1399 spu_return_value (struct gdbarch
*gdbarch
, struct type
*func_type
,
1400 struct type
*type
, struct regcache
*regcache
,
1401 gdb_byte
*out
, const gdb_byte
*in
)
1403 enum return_value_convention rvc
;
1405 if (TYPE_LENGTH (type
) <= (SPU_ARGN_REGNUM
- SPU_ARG1_REGNUM
+ 1) * 16)
1406 rvc
= RETURN_VALUE_REGISTER_CONVENTION
;
1408 rvc
= RETURN_VALUE_STRUCT_CONVENTION
;
1414 case RETURN_VALUE_REGISTER_CONVENTION
:
1415 spu_value_to_regcache (regcache
, SPU_ARG1_REGNUM
, type
, in
);
1418 case RETURN_VALUE_STRUCT_CONVENTION
:
1419 error ("Cannot set function return value.");
1427 case RETURN_VALUE_REGISTER_CONVENTION
:
1428 spu_regcache_to_value (regcache
, SPU_ARG1_REGNUM
, type
, out
);
1431 case RETURN_VALUE_STRUCT_CONVENTION
:
1432 error ("Function return value unknown.");
1443 static const gdb_byte
*
1444 spu_breakpoint_from_pc (struct gdbarch
*gdbarch
, CORE_ADDR
* pcptr
, int *lenptr
)
1446 static const gdb_byte breakpoint
[] = { 0x00, 0x00, 0x3f, 0xff };
1448 *lenptr
= sizeof breakpoint
;
1453 /* Software single-stepping support. */
1456 spu_software_single_step (struct frame_info
*frame
)
1458 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1459 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1460 CORE_ADDR pc
, next_pc
;
1465 pc
= get_frame_pc (frame
);
1467 if (target_read_memory (pc
, buf
, 4))
1469 insn
= extract_unsigned_integer (buf
, 4, byte_order
);
1471 /* Next sequential instruction is at PC + 4, except if the current
1472 instruction is a PPE-assisted call, in which case it is at PC + 8.
1473 Wrap around LS limit to be on the safe side. */
1474 if ((insn
& 0xffffff00) == 0x00002100)
1475 next_pc
= (SPUADDR_ADDR (pc
) + 8) & (SPU_LS_SIZE
- 1);
1477 next_pc
= (SPUADDR_ADDR (pc
) + 4) & (SPU_LS_SIZE
- 1);
1479 insert_single_step_breakpoint (gdbarch
, SPUADDR (SPUADDR_SPU (pc
), next_pc
));
1481 if (is_branch (insn
, &offset
, ®
))
1483 CORE_ADDR target
= offset
;
1485 if (reg
== SPU_PC_REGNUM
)
1486 target
+= SPUADDR_ADDR (pc
);
1489 get_frame_register_bytes (frame
, reg
, 0, 4, buf
);
1490 target
+= extract_unsigned_integer (buf
, 4, byte_order
) & -4;
1493 target
= target
& (SPU_LS_SIZE
- 1);
1494 if (target
!= next_pc
)
1495 insert_single_step_breakpoint (gdbarch
,
1496 SPUADDR (SPUADDR_SPU (pc
), target
));
1503 /* Longjmp support. */
1506 spu_get_longjmp_target (struct frame_info
*frame
, CORE_ADDR
*pc
)
1508 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1509 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1510 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1514 /* Jump buffer is pointed to by the argument register $r3. */
1515 get_frame_register_bytes (frame
, SPU_ARG1_REGNUM
, 0, 4, buf
);
1516 jb_addr
= extract_unsigned_integer (buf
, 4, byte_order
);
1517 if (target_read_memory (SPUADDR (tdep
->id
, jb_addr
), buf
, 4))
1520 *pc
= extract_unsigned_integer (buf
, 4, byte_order
);
1521 *pc
= SPUADDR (tdep
->id
, *pc
);
1528 struct spu_dis_asm_data
1530 struct gdbarch
*gdbarch
;
1535 spu_dis_asm_print_address (bfd_vma addr
, struct disassemble_info
*info
)
1537 struct spu_dis_asm_data
*data
= info
->application_data
;
1538 print_address (data
->gdbarch
, SPUADDR (data
->id
, addr
), info
->stream
);
1542 gdb_print_insn_spu (bfd_vma memaddr
, struct disassemble_info
*info
)
1544 /* The opcodes disassembler does 18-bit address arithmetic. Make sure the
1545 SPU ID encoded in the high bits is added back when we call print_address. */
1546 struct disassemble_info spu_info
= *info
;
1547 struct spu_dis_asm_data data
;
1548 data
.gdbarch
= info
->application_data
;
1549 data
.id
= SPUADDR_SPU (memaddr
);
1551 spu_info
.application_data
= &data
;
1552 spu_info
.print_address_func
= spu_dis_asm_print_address
;
1553 return print_insn_spu (memaddr
, &spu_info
);
1557 /* Target overlays for the SPU overlay manager.
1559 See the documentation of simple_overlay_update for how the
1560 interface is supposed to work.
1562 Data structures used by the overlay manager:
1570 } _ovly_table[]; -- one entry per overlay section
1572 struct ovly_buf_table
1575 } _ovly_buf_table[]; -- one entry per overlay buffer
1577 _ovly_table should never change.
1579 Both tables are aligned to a 16-byte boundary, the symbols _ovly_table
1580 and _ovly_buf_table are of type STT_OBJECT and their size set to the size
1581 of the respective array. buf in _ovly_table is an index into _ovly_buf_table.
1583 mapped is an index into _ovly_table. Both the mapped and buf indices start
1584 from one to reference the first entry in their respective tables. */
1586 /* Using the per-objfile private data mechanism, we store for each
1587 objfile an array of "struct spu_overlay_table" structures, one
1588 for each obj_section of the objfile. This structure holds two
1589 fields, MAPPED_PTR and MAPPED_VAL. If MAPPED_PTR is zero, this
1590 is *not* an overlay section. If it is non-zero, it represents
1591 a target address. The overlay section is mapped iff the target
1592 integer at this location equals MAPPED_VAL. */
1594 static const struct objfile_data
*spu_overlay_data
;
1596 struct spu_overlay_table
1598 CORE_ADDR mapped_ptr
;
1599 CORE_ADDR mapped_val
;
1602 /* Retrieve the overlay table for OBJFILE. If not already cached, read
1603 the _ovly_table data structure from the target and initialize the
1604 spu_overlay_table data structure from it. */
1605 static struct spu_overlay_table
*
1606 spu_get_overlay_table (struct objfile
*objfile
)
1608 enum bfd_endian byte_order
= bfd_big_endian (objfile
->obfd
)?
1609 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
1610 struct minimal_symbol
*ovly_table_msym
, *ovly_buf_table_msym
;
1611 CORE_ADDR ovly_table_base
, ovly_buf_table_base
;
1612 unsigned ovly_table_size
, ovly_buf_table_size
;
1613 struct spu_overlay_table
*tbl
;
1614 struct obj_section
*osect
;
1618 tbl
= objfile_data (objfile
, spu_overlay_data
);
1622 ovly_table_msym
= lookup_minimal_symbol ("_ovly_table", NULL
, objfile
);
1623 if (!ovly_table_msym
)
1626 ovly_buf_table_msym
= lookup_minimal_symbol ("_ovly_buf_table", NULL
, objfile
);
1627 if (!ovly_buf_table_msym
)
1630 ovly_table_base
= SYMBOL_VALUE_ADDRESS (ovly_table_msym
);
1631 ovly_table_size
= MSYMBOL_SIZE (ovly_table_msym
);
1633 ovly_buf_table_base
= SYMBOL_VALUE_ADDRESS (ovly_buf_table_msym
);
1634 ovly_buf_table_size
= MSYMBOL_SIZE (ovly_buf_table_msym
);
1636 ovly_table
= xmalloc (ovly_table_size
);
1637 read_memory (ovly_table_base
, ovly_table
, ovly_table_size
);
1639 tbl
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
1640 objfile
->sections_end
- objfile
->sections
,
1641 struct spu_overlay_table
);
1643 for (i
= 0; i
< ovly_table_size
/ 16; i
++)
1645 CORE_ADDR vma
= extract_unsigned_integer (ovly_table
+ 16*i
+ 0,
1647 CORE_ADDR size
= extract_unsigned_integer (ovly_table
+ 16*i
+ 4,
1649 CORE_ADDR pos
= extract_unsigned_integer (ovly_table
+ 16*i
+ 8,
1651 CORE_ADDR buf
= extract_unsigned_integer (ovly_table
+ 16*i
+ 12,
1654 if (buf
== 0 || (buf
- 1) * 4 >= ovly_buf_table_size
)
1657 ALL_OBJFILE_OSECTIONS (objfile
, osect
)
1658 if (vma
== bfd_section_vma (objfile
->obfd
, osect
->the_bfd_section
)
1659 && pos
== osect
->the_bfd_section
->filepos
)
1661 int ndx
= osect
- objfile
->sections
;
1662 tbl
[ndx
].mapped_ptr
= ovly_buf_table_base
+ (buf
- 1) * 4;
1663 tbl
[ndx
].mapped_val
= i
+ 1;
1669 set_objfile_data (objfile
, spu_overlay_data
, tbl
);
1673 /* Read _ovly_buf_table entry from the target to dermine whether
1674 OSECT is currently mapped, and update the mapped state. */
1676 spu_overlay_update_osect (struct obj_section
*osect
)
1678 enum bfd_endian byte_order
= bfd_big_endian (osect
->objfile
->obfd
)?
1679 BFD_ENDIAN_BIG
: BFD_ENDIAN_LITTLE
;
1680 struct spu_overlay_table
*ovly_table
;
1683 ovly_table
= spu_get_overlay_table (osect
->objfile
);
1687 ovly_table
+= osect
- osect
->objfile
->sections
;
1688 if (ovly_table
->mapped_ptr
== 0)
1691 id
= SPUADDR_SPU (obj_section_addr (osect
));
1692 val
= read_memory_unsigned_integer (SPUADDR (id
, ovly_table
->mapped_ptr
),
1694 osect
->ovly_mapped
= (val
== ovly_table
->mapped_val
);
1697 /* If OSECT is NULL, then update all sections' mapped state.
1698 If OSECT is non-NULL, then update only OSECT's mapped state. */
1700 spu_overlay_update (struct obj_section
*osect
)
1702 /* Just one section. */
1704 spu_overlay_update_osect (osect
);
1709 struct objfile
*objfile
;
1711 ALL_OBJSECTIONS (objfile
, osect
)
1712 if (section_is_overlay (osect
))
1713 spu_overlay_update_osect (osect
);
1717 /* Whenever a new objfile is loaded, read the target's _ovly_table.
1718 If there is one, go through all sections and make sure for non-
1719 overlay sections LMA equals VMA, while for overlay sections LMA
1720 is larger than local store size. */
1722 spu_overlay_new_objfile (struct objfile
*objfile
)
1724 struct spu_overlay_table
*ovly_table
;
1725 struct obj_section
*osect
;
1727 /* If we've already touched this file, do nothing. */
1728 if (!objfile
|| objfile_data (objfile
, spu_overlay_data
) != NULL
)
1731 /* Consider only SPU objfiles. */
1732 if (bfd_get_arch (objfile
->obfd
) != bfd_arch_spu
)
1735 /* Check if this objfile has overlays. */
1736 ovly_table
= spu_get_overlay_table (objfile
);
1740 /* Now go and fiddle with all the LMAs. */
1741 ALL_OBJFILE_OSECTIONS (objfile
, osect
)
1743 bfd
*obfd
= objfile
->obfd
;
1744 asection
*bsect
= osect
->the_bfd_section
;
1745 int ndx
= osect
- objfile
->sections
;
1747 if (ovly_table
[ndx
].mapped_ptr
== 0)
1748 bfd_section_lma (obfd
, bsect
) = bfd_section_vma (obfd
, bsect
);
1750 bfd_section_lma (obfd
, bsect
) = bsect
->filepos
+ SPU_LS_SIZE
;
1755 /* "info spu" commands. */
1758 info_spu_event_command (char *args
, int from_tty
)
1760 struct frame_info
*frame
= get_selected_frame (NULL
);
1761 ULONGEST event_status
= 0;
1762 ULONGEST event_mask
= 0;
1763 struct cleanup
*chain
;
1769 if (gdbarch_bfd_arch_info (get_frame_arch (frame
))->arch
!= bfd_arch_spu
)
1770 error (_("\"info spu\" is only supported on the SPU architecture."));
1772 id
= get_frame_register_unsigned (frame
, SPU_ID_REGNUM
);
1774 xsnprintf (annex
, sizeof annex
, "%d/event_status", id
);
1775 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1776 buf
, 0, (sizeof (buf
) - 1));
1778 error (_("Could not read event_status."));
1780 event_status
= strtoulst (buf
, NULL
, 16);
1782 xsnprintf (annex
, sizeof annex
, "%d/event_mask", id
);
1783 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1784 buf
, 0, (sizeof (buf
) - 1));
1786 error (_("Could not read event_mask."));
1788 event_mask
= strtoulst (buf
, NULL
, 16);
1790 chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "SPUInfoEvent");
1792 if (ui_out_is_mi_like_p (uiout
))
1794 ui_out_field_fmt (uiout
, "event_status",
1795 "0x%s", phex_nz (event_status
, 4));
1796 ui_out_field_fmt (uiout
, "event_mask",
1797 "0x%s", phex_nz (event_mask
, 4));
1801 printf_filtered (_("Event Status 0x%s\n"), phex (event_status
, 4));
1802 printf_filtered (_("Event Mask 0x%s\n"), phex (event_mask
, 4));
1805 do_cleanups (chain
);
1809 info_spu_signal_command (char *args
, int from_tty
)
1811 struct frame_info
*frame
= get_selected_frame (NULL
);
1812 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1813 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1814 ULONGEST signal1
= 0;
1815 ULONGEST signal1_type
= 0;
1816 int signal1_pending
= 0;
1817 ULONGEST signal2
= 0;
1818 ULONGEST signal2_type
= 0;
1819 int signal2_pending
= 0;
1820 struct cleanup
*chain
;
1826 if (gdbarch_bfd_arch_info (gdbarch
)->arch
!= bfd_arch_spu
)
1827 error (_("\"info spu\" is only supported on the SPU architecture."));
1829 id
= get_frame_register_unsigned (frame
, SPU_ID_REGNUM
);
1831 xsnprintf (annex
, sizeof annex
, "%d/signal1", id
);
1832 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
, buf
, 0, 4);
1834 error (_("Could not read signal1."));
1837 signal1
= extract_unsigned_integer (buf
, 4, byte_order
);
1838 signal1_pending
= 1;
1841 xsnprintf (annex
, sizeof annex
, "%d/signal1_type", id
);
1842 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1843 buf
, 0, (sizeof (buf
) - 1));
1845 error (_("Could not read signal1_type."));
1847 signal1_type
= strtoulst (buf
, NULL
, 16);
1849 xsnprintf (annex
, sizeof annex
, "%d/signal2", id
);
1850 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
, buf
, 0, 4);
1852 error (_("Could not read signal2."));
1855 signal2
= extract_unsigned_integer (buf
, 4, byte_order
);
1856 signal2_pending
= 1;
1859 xsnprintf (annex
, sizeof annex
, "%d/signal2_type", id
);
1860 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1861 buf
, 0, (sizeof (buf
) - 1));
1863 error (_("Could not read signal2_type."));
1865 signal2_type
= strtoulst (buf
, NULL
, 16);
1867 chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "SPUInfoSignal");
1869 if (ui_out_is_mi_like_p (uiout
))
1871 ui_out_field_int (uiout
, "signal1_pending", signal1_pending
);
1872 ui_out_field_fmt (uiout
, "signal1", "0x%s", phex_nz (signal1
, 4));
1873 ui_out_field_int (uiout
, "signal1_type", signal1_type
);
1874 ui_out_field_int (uiout
, "signal2_pending", signal2_pending
);
1875 ui_out_field_fmt (uiout
, "signal2", "0x%s", phex_nz (signal2
, 4));
1876 ui_out_field_int (uiout
, "signal2_type", signal2_type
);
1880 if (signal1_pending
)
1881 printf_filtered (_("Signal 1 control word 0x%s "), phex (signal1
, 4));
1883 printf_filtered (_("Signal 1 not pending "));
1886 printf_filtered (_("(Type Or)\n"));
1888 printf_filtered (_("(Type Overwrite)\n"));
1890 if (signal2_pending
)
1891 printf_filtered (_("Signal 2 control word 0x%s "), phex (signal2
, 4));
1893 printf_filtered (_("Signal 2 not pending "));
1896 printf_filtered (_("(Type Or)\n"));
1898 printf_filtered (_("(Type Overwrite)\n"));
1901 do_cleanups (chain
);
1905 info_spu_mailbox_list (gdb_byte
*buf
, int nr
, enum bfd_endian byte_order
,
1906 const char *field
, const char *msg
)
1908 struct cleanup
*chain
;
1914 chain
= make_cleanup_ui_out_table_begin_end (uiout
, 1, nr
, "mbox");
1916 ui_out_table_header (uiout
, 32, ui_left
, field
, msg
);
1917 ui_out_table_body (uiout
);
1919 for (i
= 0; i
< nr
; i
++)
1921 struct cleanup
*val_chain
;
1923 val_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "mbox");
1924 val
= extract_unsigned_integer (buf
+ 4*i
, 4, byte_order
);
1925 ui_out_field_fmt (uiout
, field
, "0x%s", phex (val
, 4));
1926 do_cleanups (val_chain
);
1928 if (!ui_out_is_mi_like_p (uiout
))
1929 printf_filtered ("\n");
1932 do_cleanups (chain
);
1936 info_spu_mailbox_command (char *args
, int from_tty
)
1938 struct frame_info
*frame
= get_selected_frame (NULL
);
1939 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
1940 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
1941 struct cleanup
*chain
;
1947 if (gdbarch_bfd_arch_info (gdbarch
)->arch
!= bfd_arch_spu
)
1948 error (_("\"info spu\" is only supported on the SPU architecture."));
1950 id
= get_frame_register_unsigned (frame
, SPU_ID_REGNUM
);
1952 chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "SPUInfoMailbox");
1954 xsnprintf (annex
, sizeof annex
, "%d/mbox_info", id
);
1955 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1956 buf
, 0, sizeof buf
);
1958 error (_("Could not read mbox_info."));
1960 info_spu_mailbox_list (buf
, len
/ 4, byte_order
,
1961 "mbox", "SPU Outbound Mailbox");
1963 xsnprintf (annex
, sizeof annex
, "%d/ibox_info", id
);
1964 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1965 buf
, 0, sizeof buf
);
1967 error (_("Could not read ibox_info."));
1969 info_spu_mailbox_list (buf
, len
/ 4, byte_order
,
1970 "ibox", "SPU Outbound Interrupt Mailbox");
1972 xsnprintf (annex
, sizeof annex
, "%d/wbox_info", id
);
1973 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
1974 buf
, 0, sizeof buf
);
1976 error (_("Could not read wbox_info."));
1978 info_spu_mailbox_list (buf
, len
/ 4, byte_order
,
1979 "wbox", "SPU Inbound Mailbox");
1981 do_cleanups (chain
);
1985 spu_mfc_get_bitfield (ULONGEST word
, int first
, int last
)
1987 ULONGEST mask
= ~(~(ULONGEST
)0 << (last
- first
+ 1));
1988 return (word
>> (63 - last
)) & mask
;
1992 info_spu_dma_cmdlist (gdb_byte
*buf
, int nr
, enum bfd_endian byte_order
)
1994 static char *spu_mfc_opcode
[256] =
1996 /* 00 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
1997 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
1998 /* 10 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
1999 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2000 /* 20 */ "put", "putb", "putf", NULL
, "putl", "putlb", "putlf", NULL
,
2001 "puts", "putbs", "putfs", NULL
, NULL
, NULL
, NULL
, NULL
,
2002 /* 30 */ "putr", "putrb", "putrf", NULL
, "putrl", "putrlb", "putrlf", NULL
,
2003 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2004 /* 40 */ "get", "getb", "getf", NULL
, "getl", "getlb", "getlf", NULL
,
2005 "gets", "getbs", "getfs", NULL
, NULL
, NULL
, NULL
, NULL
,
2006 /* 50 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2007 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2008 /* 60 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2009 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2010 /* 70 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2011 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2012 /* 80 */ "sdcrt", "sdcrtst", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2013 NULL
, "sdcrz", NULL
, NULL
, NULL
, "sdcrst", NULL
, "sdcrf",
2014 /* 90 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2015 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2016 /* a0 */ "sndsig", "sndsigb", "sndsigf", NULL
, NULL
, NULL
, NULL
, NULL
,
2017 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2018 /* b0 */ "putlluc", NULL
, NULL
, NULL
, "putllc", NULL
, NULL
, NULL
,
2019 "putqlluc", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2020 /* c0 */ "barrier", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2021 "mfceieio", NULL
, NULL
, NULL
, "mfcsync", NULL
, NULL
, NULL
,
2022 /* d0 */ "getllar", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2023 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2024 /* e0 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2025 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2026 /* f0 */ NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2027 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
2030 int *seq
= alloca (nr
* sizeof (int));
2032 struct cleanup
*chain
;
2036 /* Determine sequence in which to display (valid) entries. */
2037 for (i
= 0; i
< nr
; i
++)
2039 /* Search for the first valid entry all of whose
2040 dependencies are met. */
2041 for (j
= 0; j
< nr
; j
++)
2043 ULONGEST mfc_cq_dw3
;
2044 ULONGEST dependencies
;
2046 if (done
& (1 << (nr
- 1 - j
)))
2050 = extract_unsigned_integer (buf
+ 32*j
+ 24,8, byte_order
);
2051 if (!spu_mfc_get_bitfield (mfc_cq_dw3
, 16, 16))
2054 dependencies
= spu_mfc_get_bitfield (mfc_cq_dw3
, 0, nr
- 1);
2055 if ((dependencies
& done
) != dependencies
)
2059 done
|= 1 << (nr
- 1 - j
);
2070 chain
= make_cleanup_ui_out_table_begin_end (uiout
, 10, nr
, "dma_cmd");
2072 ui_out_table_header (uiout
, 7, ui_left
, "opcode", "Opcode");
2073 ui_out_table_header (uiout
, 3, ui_left
, "tag", "Tag");
2074 ui_out_table_header (uiout
, 3, ui_left
, "tid", "TId");
2075 ui_out_table_header (uiout
, 3, ui_left
, "rid", "RId");
2076 ui_out_table_header (uiout
, 18, ui_left
, "ea", "EA");
2077 ui_out_table_header (uiout
, 7, ui_left
, "lsa", "LSA");
2078 ui_out_table_header (uiout
, 7, ui_left
, "size", "Size");
2079 ui_out_table_header (uiout
, 7, ui_left
, "lstaddr", "LstAddr");
2080 ui_out_table_header (uiout
, 7, ui_left
, "lstsize", "LstSize");
2081 ui_out_table_header (uiout
, 1, ui_left
, "error_p", "E");
2083 ui_out_table_body (uiout
);
2085 for (i
= 0; i
< nr
; i
++)
2087 struct cleanup
*cmd_chain
;
2088 ULONGEST mfc_cq_dw0
;
2089 ULONGEST mfc_cq_dw1
;
2090 ULONGEST mfc_cq_dw2
;
2091 int mfc_cmd_opcode
, mfc_cmd_tag
, rclass_id
, tclass_id
;
2092 int lsa
, size
, list_lsa
, list_size
, mfc_lsa
, mfc_size
;
2094 int list_valid_p
, noop_valid_p
, qw_valid_p
, ea_valid_p
, cmd_error_p
;
2096 /* Decode contents of MFC Command Queue Context Save/Restore Registers.
2097 See "Cell Broadband Engine Registers V1.3", section 3.3.2.1. */
2100 = extract_unsigned_integer (buf
+ 32*seq
[i
], 8, byte_order
);
2102 = extract_unsigned_integer (buf
+ 32*seq
[i
] + 8, 8, byte_order
);
2104 = extract_unsigned_integer (buf
+ 32*seq
[i
] + 16, 8, byte_order
);
2106 list_lsa
= spu_mfc_get_bitfield (mfc_cq_dw0
, 0, 14);
2107 list_size
= spu_mfc_get_bitfield (mfc_cq_dw0
, 15, 26);
2108 mfc_cmd_opcode
= spu_mfc_get_bitfield (mfc_cq_dw0
, 27, 34);
2109 mfc_cmd_tag
= spu_mfc_get_bitfield (mfc_cq_dw0
, 35, 39);
2110 list_valid_p
= spu_mfc_get_bitfield (mfc_cq_dw0
, 40, 40);
2111 rclass_id
= spu_mfc_get_bitfield (mfc_cq_dw0
, 41, 43);
2112 tclass_id
= spu_mfc_get_bitfield (mfc_cq_dw0
, 44, 46);
2114 mfc_ea
= spu_mfc_get_bitfield (mfc_cq_dw1
, 0, 51) << 12
2115 | spu_mfc_get_bitfield (mfc_cq_dw2
, 25, 36);
2117 mfc_lsa
= spu_mfc_get_bitfield (mfc_cq_dw2
, 0, 13);
2118 mfc_size
= spu_mfc_get_bitfield (mfc_cq_dw2
, 14, 24);
2119 noop_valid_p
= spu_mfc_get_bitfield (mfc_cq_dw2
, 37, 37);
2120 qw_valid_p
= spu_mfc_get_bitfield (mfc_cq_dw2
, 38, 38);
2121 ea_valid_p
= spu_mfc_get_bitfield (mfc_cq_dw2
, 39, 39);
2122 cmd_error_p
= spu_mfc_get_bitfield (mfc_cq_dw2
, 40, 40);
2124 cmd_chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "cmd");
2126 if (spu_mfc_opcode
[mfc_cmd_opcode
])
2127 ui_out_field_string (uiout
, "opcode", spu_mfc_opcode
[mfc_cmd_opcode
]);
2129 ui_out_field_int (uiout
, "opcode", mfc_cmd_opcode
);
2131 ui_out_field_int (uiout
, "tag", mfc_cmd_tag
);
2132 ui_out_field_int (uiout
, "tid", tclass_id
);
2133 ui_out_field_int (uiout
, "rid", rclass_id
);
2136 ui_out_field_fmt (uiout
, "ea", "0x%s", phex (mfc_ea
, 8));
2138 ui_out_field_skip (uiout
, "ea");
2140 ui_out_field_fmt (uiout
, "lsa", "0x%05x", mfc_lsa
<< 4);
2142 ui_out_field_fmt (uiout
, "size", "0x%05x", mfc_size
<< 4);
2144 ui_out_field_fmt (uiout
, "size", "0x%05x", mfc_size
);
2148 ui_out_field_fmt (uiout
, "lstaddr", "0x%05x", list_lsa
<< 3);
2149 ui_out_field_fmt (uiout
, "lstsize", "0x%05x", list_size
<< 3);
2153 ui_out_field_skip (uiout
, "lstaddr");
2154 ui_out_field_skip (uiout
, "lstsize");
2158 ui_out_field_string (uiout
, "error_p", "*");
2160 ui_out_field_skip (uiout
, "error_p");
2162 do_cleanups (cmd_chain
);
2164 if (!ui_out_is_mi_like_p (uiout
))
2165 printf_filtered ("\n");
2168 do_cleanups (chain
);
2172 info_spu_dma_command (char *args
, int from_tty
)
2174 struct frame_info
*frame
= get_selected_frame (NULL
);
2175 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2176 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2177 ULONGEST dma_info_type
;
2178 ULONGEST dma_info_mask
;
2179 ULONGEST dma_info_status
;
2180 ULONGEST dma_info_stall_and_notify
;
2181 ULONGEST dma_info_atomic_command_status
;
2182 struct cleanup
*chain
;
2188 if (gdbarch_bfd_arch_info (get_frame_arch (frame
))->arch
!= bfd_arch_spu
)
2189 error (_("\"info spu\" is only supported on the SPU architecture."));
2191 id
= get_frame_register_unsigned (frame
, SPU_ID_REGNUM
);
2193 xsnprintf (annex
, sizeof annex
, "%d/dma_info", id
);
2194 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
2195 buf
, 0, 40 + 16 * 32);
2197 error (_("Could not read dma_info."));
2200 = extract_unsigned_integer (buf
, 8, byte_order
);
2202 = extract_unsigned_integer (buf
+ 8, 8, byte_order
);
2204 = extract_unsigned_integer (buf
+ 16, 8, byte_order
);
2205 dma_info_stall_and_notify
2206 = extract_unsigned_integer (buf
+ 24, 8, byte_order
);
2207 dma_info_atomic_command_status
2208 = extract_unsigned_integer (buf
+ 32, 8, byte_order
);
2210 chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "SPUInfoDMA");
2212 if (ui_out_is_mi_like_p (uiout
))
2214 ui_out_field_fmt (uiout
, "dma_info_type", "0x%s",
2215 phex_nz (dma_info_type
, 4));
2216 ui_out_field_fmt (uiout
, "dma_info_mask", "0x%s",
2217 phex_nz (dma_info_mask
, 4));
2218 ui_out_field_fmt (uiout
, "dma_info_status", "0x%s",
2219 phex_nz (dma_info_status
, 4));
2220 ui_out_field_fmt (uiout
, "dma_info_stall_and_notify", "0x%s",
2221 phex_nz (dma_info_stall_and_notify
, 4));
2222 ui_out_field_fmt (uiout
, "dma_info_atomic_command_status", "0x%s",
2223 phex_nz (dma_info_atomic_command_status
, 4));
2227 const char *query_msg
= _("no query pending");
2229 if (dma_info_type
& 4)
2230 switch (dma_info_type
& 3)
2232 case 1: query_msg
= _("'any' query pending"); break;
2233 case 2: query_msg
= _("'all' query pending"); break;
2234 default: query_msg
= _("undefined query type"); break;
2237 printf_filtered (_("Tag-Group Status 0x%s\n"),
2238 phex (dma_info_status
, 4));
2239 printf_filtered (_("Tag-Group Mask 0x%s (%s)\n"),
2240 phex (dma_info_mask
, 4), query_msg
);
2241 printf_filtered (_("Stall-and-Notify 0x%s\n"),
2242 phex (dma_info_stall_and_notify
, 4));
2243 printf_filtered (_("Atomic Cmd Status 0x%s\n"),
2244 phex (dma_info_atomic_command_status
, 4));
2245 printf_filtered ("\n");
2248 info_spu_dma_cmdlist (buf
+ 40, 16, byte_order
);
2249 do_cleanups (chain
);
2253 info_spu_proxydma_command (char *args
, int from_tty
)
2255 struct frame_info
*frame
= get_selected_frame (NULL
);
2256 struct gdbarch
*gdbarch
= get_frame_arch (frame
);
2257 enum bfd_endian byte_order
= gdbarch_byte_order (gdbarch
);
2258 ULONGEST dma_info_type
;
2259 ULONGEST dma_info_mask
;
2260 ULONGEST dma_info_status
;
2261 struct cleanup
*chain
;
2267 if (gdbarch_bfd_arch_info (gdbarch
)->arch
!= bfd_arch_spu
)
2268 error (_("\"info spu\" is only supported on the SPU architecture."));
2270 id
= get_frame_register_unsigned (frame
, SPU_ID_REGNUM
);
2272 xsnprintf (annex
, sizeof annex
, "%d/proxydma_info", id
);
2273 len
= target_read (¤t_target
, TARGET_OBJECT_SPU
, annex
,
2274 buf
, 0, 24 + 8 * 32);
2276 error (_("Could not read proxydma_info."));
2278 dma_info_type
= extract_unsigned_integer (buf
, 8, byte_order
);
2279 dma_info_mask
= extract_unsigned_integer (buf
+ 8, 8, byte_order
);
2280 dma_info_status
= extract_unsigned_integer (buf
+ 16, 8, byte_order
);
2282 chain
= make_cleanup_ui_out_tuple_begin_end (uiout
, "SPUInfoProxyDMA");
2284 if (ui_out_is_mi_like_p (uiout
))
2286 ui_out_field_fmt (uiout
, "proxydma_info_type", "0x%s",
2287 phex_nz (dma_info_type
, 4));
2288 ui_out_field_fmt (uiout
, "proxydma_info_mask", "0x%s",
2289 phex_nz (dma_info_mask
, 4));
2290 ui_out_field_fmt (uiout
, "proxydma_info_status", "0x%s",
2291 phex_nz (dma_info_status
, 4));
2295 const char *query_msg
;
2297 switch (dma_info_type
& 3)
2299 case 0: query_msg
= _("no query pending"); break;
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 ("\n");
2312 info_spu_dma_cmdlist (buf
+ 24, 8, byte_order
);
2313 do_cleanups (chain
);
2317 info_spu_command (char *args
, int from_tty
)
2319 printf_unfiltered (_("\"info spu\" must be followed by the name of an SPU facility.\n"));
2320 help_list (infospucmdlist
, "info spu ", -1, gdb_stdout
);
2324 /* Set up gdbarch struct. */
2326 static struct gdbarch
*
2327 spu_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2329 struct gdbarch
*gdbarch
;
2330 struct gdbarch_tdep
*tdep
;
2333 /* Which spufs ID was requested as address space? */
2335 id
= *(int *)info
.tdep_info
;
2336 /* For objfile architectures of SPU solibs, decode the ID from the name.
2337 This assumes the filename convention employed by solib-spu.c. */
2340 char *name
= strrchr (info
.abfd
->filename
, '@');
2342 sscanf (name
, "@0x%*x <%d>", &id
);
2345 /* Find a candidate among extant architectures. */
2346 for (arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2348 arches
= gdbarch_list_lookup_by_info (arches
->next
, &info
))
2350 tdep
= gdbarch_tdep (arches
->gdbarch
);
2351 if (tdep
&& tdep
->id
== id
)
2352 return arches
->gdbarch
;
2355 /* None found, so create a new architecture. */
2356 tdep
= XCALLOC (1, struct gdbarch_tdep
);
2358 gdbarch
= gdbarch_alloc (&info
, tdep
);
2361 set_gdbarch_print_insn (gdbarch
, gdb_print_insn_spu
);
2364 set_gdbarch_num_regs (gdbarch
, SPU_NUM_REGS
);
2365 set_gdbarch_num_pseudo_regs (gdbarch
, SPU_NUM_PSEUDO_REGS
);
2366 set_gdbarch_sp_regnum (gdbarch
, SPU_SP_REGNUM
);
2367 set_gdbarch_pc_regnum (gdbarch
, SPU_PC_REGNUM
);
2368 set_gdbarch_read_pc (gdbarch
, spu_read_pc
);
2369 set_gdbarch_write_pc (gdbarch
, spu_write_pc
);
2370 set_gdbarch_register_name (gdbarch
, spu_register_name
);
2371 set_gdbarch_register_type (gdbarch
, spu_register_type
);
2372 set_gdbarch_pseudo_register_read (gdbarch
, spu_pseudo_register_read
);
2373 set_gdbarch_pseudo_register_write (gdbarch
, spu_pseudo_register_write
);
2374 set_gdbarch_value_from_register (gdbarch
, spu_value_from_register
);
2375 set_gdbarch_register_reggroup_p (gdbarch
, spu_register_reggroup_p
);
2378 set_gdbarch_char_signed (gdbarch
, 0);
2379 set_gdbarch_ptr_bit (gdbarch
, 32);
2380 set_gdbarch_addr_bit (gdbarch
, 32);
2381 set_gdbarch_short_bit (gdbarch
, 16);
2382 set_gdbarch_int_bit (gdbarch
, 32);
2383 set_gdbarch_long_bit (gdbarch
, 32);
2384 set_gdbarch_long_long_bit (gdbarch
, 64);
2385 set_gdbarch_float_bit (gdbarch
, 32);
2386 set_gdbarch_double_bit (gdbarch
, 64);
2387 set_gdbarch_long_double_bit (gdbarch
, 64);
2388 set_gdbarch_float_format (gdbarch
, floatformats_ieee_single
);
2389 set_gdbarch_double_format (gdbarch
, floatformats_ieee_double
);
2390 set_gdbarch_long_double_format (gdbarch
, floatformats_ieee_double
);
2392 /* Address conversion. */
2393 set_gdbarch_address_to_pointer (gdbarch
, spu_address_to_pointer
);
2394 set_gdbarch_pointer_to_address (gdbarch
, spu_pointer_to_address
);
2395 set_gdbarch_integer_to_address (gdbarch
, spu_integer_to_address
);
2397 /* Inferior function calls. */
2398 set_gdbarch_call_dummy_location (gdbarch
, ON_STACK
);
2399 set_gdbarch_frame_align (gdbarch
, spu_frame_align
);
2400 set_gdbarch_frame_red_zone_size (gdbarch
, 2000);
2401 set_gdbarch_push_dummy_code (gdbarch
, spu_push_dummy_code
);
2402 set_gdbarch_push_dummy_call (gdbarch
, spu_push_dummy_call
);
2403 set_gdbarch_dummy_id (gdbarch
, spu_dummy_id
);
2404 set_gdbarch_return_value (gdbarch
, spu_return_value
);
2406 /* Frame handling. */
2407 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2408 frame_unwind_append_unwinder (gdbarch
, &spu_frame_unwind
);
2409 frame_base_set_default (gdbarch
, &spu_frame_base
);
2410 set_gdbarch_unwind_pc (gdbarch
, spu_unwind_pc
);
2411 set_gdbarch_unwind_sp (gdbarch
, spu_unwind_sp
);
2412 set_gdbarch_virtual_frame_pointer (gdbarch
, spu_virtual_frame_pointer
);
2413 set_gdbarch_frame_args_skip (gdbarch
, 0);
2414 set_gdbarch_skip_prologue (gdbarch
, spu_skip_prologue
);
2415 set_gdbarch_in_function_epilogue_p (gdbarch
, spu_in_function_epilogue_p
);
2417 /* Cell/B.E. cross-architecture unwinder support. */
2418 frame_unwind_prepend_unwinder (gdbarch
, &spu2ppu_unwind
);
2421 set_gdbarch_decr_pc_after_break (gdbarch
, 4);
2422 set_gdbarch_breakpoint_from_pc (gdbarch
, spu_breakpoint_from_pc
);
2423 set_gdbarch_cannot_step_breakpoint (gdbarch
, 1);
2424 set_gdbarch_software_single_step (gdbarch
, spu_software_single_step
);
2425 set_gdbarch_get_longjmp_target (gdbarch
, spu_get_longjmp_target
);
2428 set_gdbarch_overlay_update (gdbarch
, spu_overlay_update
);
2433 /* Provide a prototype to silence -Wmissing-prototypes. */
2434 extern initialize_file_ftype _initialize_spu_tdep
;
2437 _initialize_spu_tdep (void)
2439 register_gdbarch_init (bfd_arch_spu
, spu_gdbarch_init
);
2441 /* Add ourselves to objfile event chain. */
2442 observer_attach_new_objfile (spu_overlay_new_objfile
);
2443 spu_overlay_data
= register_objfile_data ();
2445 /* Add root prefix command for all "info spu" commands. */
2446 add_prefix_cmd ("spu", class_info
, info_spu_command
,
2447 _("Various SPU specific commands."),
2448 &infospucmdlist
, "info spu ", 0, &infolist
);
2450 /* Add various "info spu" commands. */
2451 add_cmd ("event", class_info
, info_spu_event_command
,
2452 _("Display SPU event facility status.\n"),
2454 add_cmd ("signal", class_info
, info_spu_signal_command
,
2455 _("Display SPU signal notification facility status.\n"),
2457 add_cmd ("mailbox", class_info
, info_spu_mailbox_command
,
2458 _("Display SPU mailbox facility status.\n"),
2460 add_cmd ("dma", class_info
, info_spu_dma_command
,
2461 _("Display MFC DMA status.\n"),
2463 add_cmd ("proxydma", class_info
, info_spu_proxydma_command
,
2464 _("Display MFC Proxy-DMA status.\n"),