1 /* Target-dependent code for UltraSPARC.
3 Copyright 2003, 2004, 2005 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 #include "arch-utils.h"
24 #include "floatformat.h"
26 #include "frame-base.h"
27 #include "frame-unwind.h"
38 #include "gdb_assert.h"
39 #include "gdb_string.h"
41 #include "sparc64-tdep.h"
43 /* This file implements the The SPARC 64-bit ABI as defined by the
44 section "Low-Level System Information" of the SPARC Compliance
45 Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
48 /* Please use the sparc32_-prefix for 32-bit specific code, the
49 sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
50 code can handle both. */
52 /* The functions on this page are intended to be used to classify
53 function arguments. */
55 /* Check whether TYPE is "Integral or Pointer". */
58 sparc64_integral_or_pointer_p (const struct type
*type
)
60 switch (TYPE_CODE (type
))
68 int len
= TYPE_LENGTH (type
);
69 gdb_assert (len
== 1 || len
== 2 || len
== 4 || len
== 8);
75 int len
= TYPE_LENGTH (type
);
76 gdb_assert (len
== 8);
86 /* Check whether TYPE is "Floating". */
89 sparc64_floating_p (const struct type
*type
)
91 switch (TYPE_CODE (type
))
95 int len
= TYPE_LENGTH (type
);
96 gdb_assert (len
== 4 || len
== 8 || len
== 16);
106 /* Check whether TYPE is "Structure or Union". */
109 sparc64_structure_or_union_p (const struct type
*type
)
111 switch (TYPE_CODE (type
))
113 case TYPE_CODE_STRUCT
:
114 case TYPE_CODE_UNION
:
123 /* Register information. */
125 struct sparc64_register_info
131 static struct sparc64_register_info sparc64_register_info
[] =
133 { "g0", &builtin_type_int64
},
134 { "g1", &builtin_type_int64
},
135 { "g2", &builtin_type_int64
},
136 { "g3", &builtin_type_int64
},
137 { "g4", &builtin_type_int64
},
138 { "g5", &builtin_type_int64
},
139 { "g6", &builtin_type_int64
},
140 { "g7", &builtin_type_int64
},
142 { "o0", &builtin_type_int64
},
143 { "o1", &builtin_type_int64
},
144 { "o2", &builtin_type_int64
},
145 { "o3", &builtin_type_int64
},
146 { "o4", &builtin_type_int64
},
147 { "o5", &builtin_type_int64
},
148 { "sp", &builtin_type_void_data_ptr
},
149 { "o7", &builtin_type_int64
},
151 { "l0", &builtin_type_int64
},
152 { "l1", &builtin_type_int64
},
153 { "l2", &builtin_type_int64
},
154 { "l3", &builtin_type_int64
},
155 { "l4", &builtin_type_int64
},
156 { "l5", &builtin_type_int64
},
157 { "l6", &builtin_type_int64
},
158 { "l7", &builtin_type_int64
},
160 { "i0", &builtin_type_int64
},
161 { "i1", &builtin_type_int64
},
162 { "i2", &builtin_type_int64
},
163 { "i3", &builtin_type_int64
},
164 { "i4", &builtin_type_int64
},
165 { "i5", &builtin_type_int64
},
166 { "fp", &builtin_type_void_data_ptr
},
167 { "i7", &builtin_type_int64
},
169 { "f0", &builtin_type_float
},
170 { "f1", &builtin_type_float
},
171 { "f2", &builtin_type_float
},
172 { "f3", &builtin_type_float
},
173 { "f4", &builtin_type_float
},
174 { "f5", &builtin_type_float
},
175 { "f6", &builtin_type_float
},
176 { "f7", &builtin_type_float
},
177 { "f8", &builtin_type_float
},
178 { "f9", &builtin_type_float
},
179 { "f10", &builtin_type_float
},
180 { "f11", &builtin_type_float
},
181 { "f12", &builtin_type_float
},
182 { "f13", &builtin_type_float
},
183 { "f14", &builtin_type_float
},
184 { "f15", &builtin_type_float
},
185 { "f16", &builtin_type_float
},
186 { "f17", &builtin_type_float
},
187 { "f18", &builtin_type_float
},
188 { "f19", &builtin_type_float
},
189 { "f20", &builtin_type_float
},
190 { "f21", &builtin_type_float
},
191 { "f22", &builtin_type_float
},
192 { "f23", &builtin_type_float
},
193 { "f24", &builtin_type_float
},
194 { "f25", &builtin_type_float
},
195 { "f26", &builtin_type_float
},
196 { "f27", &builtin_type_float
},
197 { "f28", &builtin_type_float
},
198 { "f29", &builtin_type_float
},
199 { "f30", &builtin_type_float
},
200 { "f31", &builtin_type_float
},
201 { "f32", &builtin_type_double
},
202 { "f34", &builtin_type_double
},
203 { "f36", &builtin_type_double
},
204 { "f38", &builtin_type_double
},
205 { "f40", &builtin_type_double
},
206 { "f42", &builtin_type_double
},
207 { "f44", &builtin_type_double
},
208 { "f46", &builtin_type_double
},
209 { "f48", &builtin_type_double
},
210 { "f50", &builtin_type_double
},
211 { "f52", &builtin_type_double
},
212 { "f54", &builtin_type_double
},
213 { "f56", &builtin_type_double
},
214 { "f58", &builtin_type_double
},
215 { "f60", &builtin_type_double
},
216 { "f62", &builtin_type_double
},
218 { "pc", &builtin_type_void_func_ptr
},
219 { "npc", &builtin_type_void_func_ptr
},
221 /* This raw register contains the contents of %cwp, %pstate, %asi
222 and %ccr as laid out in a %tstate register. */
223 /* FIXME: Give it a name until we start using register groups. */
224 { "state", &builtin_type_int64
},
226 { "fsr", &builtin_type_int64
},
227 { "fprs", &builtin_type_int64
},
229 /* "Although Y is a 64-bit register, its high-order 32 bits are
230 reserved and always read as 0." */
231 { "y", &builtin_type_int64
}
234 /* Total number of registers. */
235 #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_info)
237 /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
238 registers as "psuedo" registers. */
240 static struct sparc64_register_info sparc64_pseudo_register_info
[] =
242 { "cwp", &builtin_type_int64
},
243 { "pstate", &builtin_type_int64
},
244 { "asi", &builtin_type_int64
},
245 { "ccr", &builtin_type_int64
},
247 { "d0", &builtin_type_double
},
248 { "d2", &builtin_type_double
},
249 { "d4", &builtin_type_double
},
250 { "d6", &builtin_type_double
},
251 { "d8", &builtin_type_double
},
252 { "d10", &builtin_type_double
},
253 { "d12", &builtin_type_double
},
254 { "d14", &builtin_type_double
},
255 { "d16", &builtin_type_double
},
256 { "d18", &builtin_type_double
},
257 { "d20", &builtin_type_double
},
258 { "d22", &builtin_type_double
},
259 { "d24", &builtin_type_double
},
260 { "d26", &builtin_type_double
},
261 { "d28", &builtin_type_double
},
262 { "d30", &builtin_type_double
},
263 { "d32", &builtin_type_double
},
264 { "d34", &builtin_type_double
},
265 { "d36", &builtin_type_double
},
266 { "d38", &builtin_type_double
},
267 { "d40", &builtin_type_double
},
268 { "d42", &builtin_type_double
},
269 { "d44", &builtin_type_double
},
270 { "d46", &builtin_type_double
},
271 { "d48", &builtin_type_double
},
272 { "d50", &builtin_type_double
},
273 { "d52", &builtin_type_double
},
274 { "d54", &builtin_type_double
},
275 { "d56", &builtin_type_double
},
276 { "d58", &builtin_type_double
},
277 { "d60", &builtin_type_double
},
278 { "d62", &builtin_type_double
},
280 { "q0", &builtin_type_long_double
},
281 { "q4", &builtin_type_long_double
},
282 { "q8", &builtin_type_long_double
},
283 { "q12", &builtin_type_long_double
},
284 { "q16", &builtin_type_long_double
},
285 { "q20", &builtin_type_long_double
},
286 { "q24", &builtin_type_long_double
},
287 { "q28", &builtin_type_long_double
},
288 { "q32", &builtin_type_long_double
},
289 { "q36", &builtin_type_long_double
},
290 { "q40", &builtin_type_long_double
},
291 { "q44", &builtin_type_long_double
},
292 { "q48", &builtin_type_long_double
},
293 { "q52", &builtin_type_long_double
},
294 { "q56", &builtin_type_long_double
},
295 { "q60", &builtin_type_long_double
}
298 /* Total number of pseudo registers. */
299 #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_info)
301 /* Return the name of register REGNUM. */
304 sparc64_register_name (int regnum
)
306 if (regnum
>= 0 && regnum
< SPARC64_NUM_REGS
)
307 return sparc64_register_info
[regnum
].name
;
309 if (regnum
>= SPARC64_NUM_REGS
310 && regnum
< SPARC64_NUM_REGS
+ SPARC64_NUM_PSEUDO_REGS
)
311 return sparc64_pseudo_register_info
[regnum
- SPARC64_NUM_REGS
].name
;
316 /* Return the GDB type object for the "standard" data type of data in
320 sparc64_register_type (struct gdbarch
*gdbarch
, int regnum
)
322 if (regnum
>= SPARC64_NUM_REGS
323 && regnum
< SPARC64_NUM_REGS
+ SPARC64_NUM_PSEUDO_REGS
)
324 return *sparc64_pseudo_register_info
[regnum
- SPARC64_NUM_REGS
].type
;
326 gdb_assert (regnum
>= 0 && regnum
< SPARC64_NUM_REGS
);
327 return *sparc64_register_info
[regnum
].type
;
331 sparc64_pseudo_register_read (struct gdbarch
*gdbarch
,
332 struct regcache
*regcache
,
333 int regnum
, void *buf
)
335 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
337 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
339 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
340 regcache_raw_read (regcache
, regnum
, buf
);
341 regcache_raw_read (regcache
, regnum
+ 1, ((char *)buf
) + 4);
343 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
345 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
346 regcache_raw_read (regcache
, regnum
, buf
);
348 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
350 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
351 regcache_raw_read (regcache
, regnum
, buf
);
352 regcache_raw_read (regcache
, regnum
+ 1, ((char *)buf
) + 4);
353 regcache_raw_read (regcache
, regnum
+ 2, ((char *)buf
) + 8);
354 regcache_raw_read (regcache
, regnum
+ 3, ((char *)buf
) + 12);
356 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
358 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
359 regcache_raw_read (regcache
, regnum
, buf
);
360 regcache_raw_read (regcache
, regnum
+ 1, ((char *)buf
) + 8);
362 else if (regnum
== SPARC64_CWP_REGNUM
363 || regnum
== SPARC64_PSTATE_REGNUM
364 || regnum
== SPARC64_ASI_REGNUM
365 || regnum
== SPARC64_CCR_REGNUM
)
369 regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
372 case SPARC64_CWP_REGNUM
:
373 state
= (state
>> 0) & ((1 << 5) - 1);
375 case SPARC64_PSTATE_REGNUM
:
376 state
= (state
>> 8) & ((1 << 12) - 1);
378 case SPARC64_ASI_REGNUM
:
379 state
= (state
>> 24) & ((1 << 8) - 1);
381 case SPARC64_CCR_REGNUM
:
382 state
= (state
>> 32) & ((1 << 8) - 1);
385 store_unsigned_integer (buf
, 8, state
);
390 sparc64_pseudo_register_write (struct gdbarch
*gdbarch
,
391 struct regcache
*regcache
,
392 int regnum
, const void *buf
)
394 gdb_assert (regnum
>= SPARC64_NUM_REGS
);
396 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D30_REGNUM
)
398 regnum
= SPARC_F0_REGNUM
+ 2 * (regnum
- SPARC64_D0_REGNUM
);
399 regcache_raw_write (regcache
, regnum
, buf
);
400 regcache_raw_write (regcache
, regnum
+ 1, ((const char *)buf
) + 4);
402 else if (regnum
>= SPARC64_D32_REGNUM
&& regnum
<= SPARC64_D62_REGNUM
)
404 regnum
= SPARC64_F32_REGNUM
+ (regnum
- SPARC64_D32_REGNUM
);
405 regcache_raw_write (regcache
, regnum
, buf
);
407 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q28_REGNUM
)
409 regnum
= SPARC_F0_REGNUM
+ 4 * (regnum
- SPARC64_Q0_REGNUM
);
410 regcache_raw_write (regcache
, regnum
, buf
);
411 regcache_raw_write (regcache
, regnum
+ 1, ((const char *)buf
) + 4);
412 regcache_raw_write (regcache
, regnum
+ 2, ((const char *)buf
) + 8);
413 regcache_raw_write (regcache
, regnum
+ 3, ((const char *)buf
) + 12);
415 else if (regnum
>= SPARC64_Q32_REGNUM
&& regnum
<= SPARC64_Q60_REGNUM
)
417 regnum
= SPARC64_F32_REGNUM
+ 2 * (regnum
- SPARC64_Q32_REGNUM
);
418 regcache_raw_write (regcache
, regnum
, buf
);
419 regcache_raw_write (regcache
, regnum
+ 1, ((const char *)buf
) + 8);
421 else if (regnum
== SPARC64_CWP_REGNUM
422 || regnum
== SPARC64_PSTATE_REGNUM
423 || regnum
== SPARC64_ASI_REGNUM
424 || regnum
== SPARC64_CCR_REGNUM
)
426 ULONGEST state
, bits
;
428 regcache_raw_read_unsigned (regcache
, SPARC64_STATE_REGNUM
, &state
);
429 bits
= extract_unsigned_integer (buf
, 8);
432 case SPARC64_CWP_REGNUM
:
433 state
|= ((bits
& ((1 << 5) - 1)) << 0);
435 case SPARC64_PSTATE_REGNUM
:
436 state
|= ((bits
& ((1 << 12) - 1)) << 8);
438 case SPARC64_ASI_REGNUM
:
439 state
|= ((bits
& ((1 << 8) - 1)) << 24);
441 case SPARC64_CCR_REGNUM
:
442 state
|= ((bits
& ((1 << 8) - 1)) << 32);
445 regcache_raw_write_unsigned (regcache
, SPARC64_STATE_REGNUM
, state
);
450 /* Return PC of first real instruction of the function starting at
454 sparc64_skip_prologue (CORE_ADDR start_pc
)
456 struct symtab_and_line sal
;
457 CORE_ADDR func_start
, func_end
;
458 struct sparc_frame_cache cache
;
460 /* This is the preferred method, find the end of the prologue by
461 using the debugging information. */
462 if (find_pc_partial_function (start_pc
, NULL
, &func_start
, &func_end
))
464 sal
= find_pc_line (func_start
, 0);
466 if (sal
.end
< func_end
467 && start_pc
<= sal
.end
)
471 return sparc_analyze_prologue (start_pc
, 0xffffffffffffffffULL
, &cache
);
476 static struct sparc_frame_cache
*
477 sparc64_frame_cache (struct frame_info
*next_frame
, void **this_cache
)
479 return sparc_frame_cache (next_frame
, this_cache
);
483 sparc64_frame_this_id (struct frame_info
*next_frame
, void **this_cache
,
484 struct frame_id
*this_id
)
486 struct sparc_frame_cache
*cache
=
487 sparc64_frame_cache (next_frame
, this_cache
);
489 /* This marks the outermost frame. */
490 if (cache
->base
== 0)
493 (*this_id
) = frame_id_build (cache
->base
, cache
->pc
);
497 sparc64_frame_prev_register (struct frame_info
*next_frame
, void **this_cache
,
498 int regnum
, int *optimizedp
,
499 enum lval_type
*lvalp
, CORE_ADDR
*addrp
,
500 int *realnump
, void *valuep
)
502 struct sparc_frame_cache
*cache
=
503 sparc64_frame_cache (next_frame
, this_cache
);
505 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== SPARC64_NPC_REGNUM
)
513 CORE_ADDR pc
= (regnum
== SPARC64_NPC_REGNUM
) ? 4 : 0;
515 regnum
= cache
->frameless_p
? SPARC_O7_REGNUM
: SPARC_I7_REGNUM
;
516 pc
+= frame_unwind_register_unsigned (next_frame
, regnum
) + 8;
517 store_unsigned_integer (valuep
, 8, pc
);
522 /* The previous frame's `local' and `in' registers have been saved
523 in the register save area. */
524 if (!cache
->frameless_p
525 && regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
)
528 *lvalp
= lval_memory
;
529 *addrp
= cache
->base
+ (regnum
- SPARC_L0_REGNUM
) * 8;
533 struct gdbarch
*gdbarch
= get_frame_arch (next_frame
);
535 /* Read the value in from memory. */
536 read_memory (*addrp
, valuep
, register_size (gdbarch
, regnum
));
541 /* The previous frame's `out' registers are accessable as the
542 current frame's `in' registers. */
543 if (!cache
->frameless_p
544 && regnum
>= SPARC_O0_REGNUM
&& regnum
<= SPARC_O7_REGNUM
)
545 regnum
+= (SPARC_I0_REGNUM
- SPARC_O0_REGNUM
);
548 *lvalp
= lval_register
;
552 frame_unwind_register (next_frame
, regnum
, valuep
);
555 static const struct frame_unwind sparc64_frame_unwind
=
558 sparc64_frame_this_id
,
559 sparc64_frame_prev_register
562 static const struct frame_unwind
*
563 sparc64_frame_sniffer (struct frame_info
*next_frame
)
565 return &sparc64_frame_unwind
;
570 sparc64_frame_base_address (struct frame_info
*next_frame
, void **this_cache
)
572 struct sparc_frame_cache
*cache
=
573 sparc64_frame_cache (next_frame
, this_cache
);
578 static const struct frame_base sparc64_frame_base
=
580 &sparc64_frame_unwind
,
581 sparc64_frame_base_address
,
582 sparc64_frame_base_address
,
583 sparc64_frame_base_address
586 /* Check whether TYPE must be 16-byte aligned. */
589 sparc64_16_byte_align_p (struct type
*type
)
591 if (sparc64_floating_p (type
) && TYPE_LENGTH (type
) == 16)
594 if (sparc64_structure_or_union_p (type
))
598 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
600 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
602 if (sparc64_16_byte_align_p (subtype
))
610 /* Store floating fields of element ELEMENT of an "parameter array"
611 that has type TYPE and is stored at BITPOS in VALBUF in the
612 apropriate registers of REGCACHE. This function can be called
613 recursively and therefore handles floating types in addition to
617 sparc64_store_floating_fields (struct regcache
*regcache
, struct type
*type
,
618 const char *valbuf
, int element
, int bitpos
)
620 gdb_assert (element
< 16);
622 if (sparc64_floating_p (type
))
624 int len
= TYPE_LENGTH (type
);
629 gdb_assert (bitpos
== 0);
630 gdb_assert ((element
% 2) == 0);
632 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
633 regcache_cooked_write (regcache
, regnum
, valbuf
);
637 gdb_assert (bitpos
== 0 || bitpos
== 64);
639 regnum
= SPARC64_D0_REGNUM
+ element
+ bitpos
/ 64;
640 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
644 gdb_assert (len
== 4);
645 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 128);
647 regnum
= SPARC_F0_REGNUM
+ element
* 2 + bitpos
/ 32;
648 regcache_cooked_write (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
651 else if (sparc64_structure_or_union_p (type
))
655 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
657 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
658 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
660 sparc64_store_floating_fields (regcache
, subtype
, valbuf
,
664 /* GCC has an interesting bug. If TYPE is a structure that has
665 a single `float' member, GCC doesn't treat it as a structure
666 at all, but rather as an ordinary `float' argument. This
667 argument will be stored in %f1, as required by the psABI.
668 However, as a member of a structure the psABI requires it to
669 be stored in %f0. This bug is present in GCC 3.3.2, but
670 probably in older releases to. To appease GCC, if a
671 structure has only a single `float' member, we store its
672 value in %f1 too (we already have stored in %f0). */
673 if (TYPE_NFIELDS (type
) == 1)
675 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, 0));
677 if (sparc64_floating_p (subtype
) && TYPE_LENGTH (subtype
) == 4)
678 regcache_cooked_write (regcache
, SPARC_F1_REGNUM
, valbuf
);
683 /* Fetch floating fields from a variable of type TYPE from the
684 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
685 in VALBUF. This function can be called recursively and therefore
686 handles floating types in addition to structures. */
689 sparc64_extract_floating_fields (struct regcache
*regcache
, struct type
*type
,
690 char *valbuf
, int bitpos
)
692 if (sparc64_floating_p (type
))
694 int len
= TYPE_LENGTH (type
);
699 gdb_assert (bitpos
== 0 || bitpos
== 128);
701 regnum
= SPARC64_Q0_REGNUM
+ bitpos
/ 128;
702 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
706 gdb_assert (bitpos
% 64 == 0 && bitpos
>= 0 && bitpos
< 256);
708 regnum
= SPARC64_D0_REGNUM
+ bitpos
/ 64;
709 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
713 gdb_assert (len
== 4);
714 gdb_assert (bitpos
% 32 == 0 && bitpos
>= 0 && bitpos
< 256);
716 regnum
= SPARC_F0_REGNUM
+ bitpos
/ 32;
717 regcache_cooked_read (regcache
, regnum
, valbuf
+ (bitpos
/ 8));
720 else if (sparc64_structure_or_union_p (type
))
724 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
726 struct type
*subtype
= check_typedef (TYPE_FIELD_TYPE (type
, i
));
727 int subpos
= bitpos
+ TYPE_FIELD_BITPOS (type
, i
);
729 sparc64_extract_floating_fields (regcache
, subtype
, valbuf
, subpos
);
734 /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
735 non-zero) in REGCACHE and on the stack (starting from address SP). */
738 sparc64_store_arguments (struct regcache
*regcache
, int nargs
,
739 struct value
**args
, CORE_ADDR sp
,
740 int struct_return
, CORE_ADDR struct_addr
)
742 /* Number of extended words in the "parameter array". */
743 int num_elements
= 0;
747 /* Take BIAS into account. */
750 /* First we calculate the number of extended words in the "parameter
751 array". While doing so we also convert some of the arguments. */
756 for (i
= 0; i
< nargs
; i
++)
758 struct type
*type
= value_type (args
[i
]);
759 int len
= TYPE_LENGTH (type
);
761 if (sparc64_structure_or_union_p (type
))
763 /* Structure or Union arguments. */
766 if (num_elements
% 2 && sparc64_16_byte_align_p (type
))
768 num_elements
+= ((len
+ 7) / 8);
772 /* The psABI says that "Structures or unions larger than
773 sixteen bytes are copied by the caller and passed
774 indirectly; the caller will pass the address of a
775 correctly aligned structure value. This sixty-four
776 bit address will occupy one word in the parameter
777 array, and may be promoted to an %o register like any
778 other pointer value." Allocate memory for these
779 values on the stack. */
782 /* Use 16-byte alignment for these values. That's
783 always correct, and wasting a few bytes shouldn't be
787 write_memory (sp
, value_contents (args
[i
]), len
);
788 args
[i
] = value_from_pointer (lookup_pointer_type (type
), sp
);
792 else if (sparc64_floating_p (type
))
794 /* Floating arguments. */
798 /* The psABI says that "Each quad-precision parameter
799 value will be assigned to two extended words in the
803 /* The psABI says that "Long doubles must be
804 quad-aligned, and thus a hole might be introduced
805 into the parameter array to force alignment." Skip
806 an element if necessary. */
807 if (num_elements
% 2)
815 /* Integral and pointer arguments. */
816 gdb_assert (sparc64_integral_or_pointer_p (type
));
818 /* The psABI says that "Each argument value of integral type
819 smaller than an extended word will be widened by the
820 caller to an extended word according to the signed-ness
821 of the argument type." */
823 args
[i
] = value_cast (builtin_type_int64
, args
[i
]);
828 /* Allocate the "parameter array". */
829 sp
-= num_elements
* 8;
831 /* The psABI says that "Every stack frame must be 16-byte aligned." */
834 /* Now we store the arguments in to the "paramater array". Some
835 Integer or Pointer arguments and Structure or Union arguments
836 will be passed in %o registers. Some Floating arguments and
837 floating members of structures are passed in floating-point
838 registers. However, for functions with variable arguments,
839 floating arguments are stored in an %0 register, and for
840 functions without a prototype floating arguments are stored in
841 both a floating-point and an %o registers, or a floating-point
842 register and memory. To simplify the logic here we always pass
843 arguments in memory, an %o register, and a floating-point
844 register if appropriate. This should be no problem since the
845 contents of any unused memory or registers in the "parameter
846 array" are undefined. */
850 regcache_cooked_write_unsigned (regcache
, SPARC_O0_REGNUM
, struct_addr
);
854 for (i
= 0; i
< nargs
; i
++)
856 const char *valbuf
= value_contents (args
[i
]);
857 struct type
*type
= value_type (args
[i
]);
858 int len
= TYPE_LENGTH (type
);
862 if (sparc64_structure_or_union_p (type
))
864 /* Structure or Union arguments. */
865 gdb_assert (len
<= 16);
866 memset (buf
, 0, sizeof (buf
));
867 valbuf
= memcpy (buf
, valbuf
, len
);
869 if (element
% 2 && sparc64_16_byte_align_p (type
))
874 regnum
= SPARC_O0_REGNUM
+ element
;
875 if (len
> 8 && element
< 5)
876 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
880 sparc64_store_floating_fields (regcache
, type
, valbuf
, element
, 0);
882 else if (sparc64_floating_p (type
))
884 /* Floating arguments. */
890 regnum
= SPARC64_Q0_REGNUM
+ element
/ 2;
895 regnum
= SPARC64_D0_REGNUM
+ element
;
899 /* The psABI says "Each single-precision parameter value
900 will be assigned to one extended word in the
901 parameter array, and right-justified within that
902 word; the left half (even floatregister) is
903 undefined." Even though the psABI says that "the
904 left half is undefined", set it to zero here. */
906 memcpy (buf
+ 4, valbuf
, 4);
910 regnum
= SPARC64_D0_REGNUM
+ element
;
915 /* Integral and pointer arguments. */
916 gdb_assert (len
== 8);
918 regnum
= SPARC_O0_REGNUM
+ element
;
923 regcache_cooked_write (regcache
, regnum
, valbuf
);
925 /* If we're storing the value in a floating-point register,
926 also store it in the corresponding %0 register(s). */
927 if (regnum
>= SPARC64_D0_REGNUM
&& regnum
<= SPARC64_D10_REGNUM
)
929 gdb_assert (element
< 6);
930 regnum
= SPARC_O0_REGNUM
+ element
;
931 regcache_cooked_write (regcache
, regnum
, valbuf
);
933 else if (regnum
>= SPARC64_Q0_REGNUM
&& regnum
<= SPARC64_Q8_REGNUM
)
935 gdb_assert (element
< 6);
936 regnum
= SPARC_O0_REGNUM
+ element
;
937 regcache_cooked_write (regcache
, regnum
, valbuf
);
938 regcache_cooked_write (regcache
, regnum
+ 1, valbuf
+ 8);
942 /* Always store the argument in memory. */
943 write_memory (sp
+ element
* 8, valbuf
, len
);
944 element
+= ((len
+ 7) / 8);
947 gdb_assert (element
== num_elements
);
949 /* Take BIAS into account. */
955 sparc64_push_dummy_call (struct gdbarch
*gdbarch
, struct value
*function
,
956 struct regcache
*regcache
, CORE_ADDR bp_addr
,
957 int nargs
, struct value
**args
, CORE_ADDR sp
,
958 int struct_return
, CORE_ADDR struct_addr
)
960 /* Set return address. */
961 regcache_cooked_write_unsigned (regcache
, SPARC_O7_REGNUM
, bp_addr
- 8);
963 /* Set up function arguments. */
964 sp
= sparc64_store_arguments (regcache
, nargs
, args
, sp
,
965 struct_return
, struct_addr
);
967 /* Allocate the register save area. */
970 /* Stack should be 16-byte aligned at this point. */
971 gdb_assert ((sp
+ BIAS
) % 16 == 0);
973 /* Finally, update the stack pointer. */
974 regcache_cooked_write_unsigned (regcache
, SPARC_SP_REGNUM
, sp
);
980 /* Extract from an array REGBUF containing the (raw) register state, a
981 function return value of TYPE, and copy that into VALBUF. */
984 sparc64_extract_return_value (struct type
*type
, struct regcache
*regcache
,
987 int len
= TYPE_LENGTH (type
);
991 if (sparc64_structure_or_union_p (type
))
993 /* Structure or Union return values. */
994 gdb_assert (len
<= 32);
996 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
997 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
998 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
999 sparc64_extract_floating_fields (regcache
, type
, buf
, 0);
1000 memcpy (valbuf
, buf
, len
);
1002 else if (sparc64_floating_p (type
))
1004 /* Floating return values. */
1005 for (i
= 0; i
< len
/ 4; i
++)
1006 regcache_cooked_read (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1007 memcpy (valbuf
, buf
, len
);
1011 /* Integral and pointer return values. */
1012 gdb_assert (sparc64_integral_or_pointer_p (type
));
1014 /* Just stripping off any unused bytes should preserve the
1015 signed-ness just fine. */
1016 regcache_cooked_read (regcache
, SPARC_O0_REGNUM
, buf
);
1017 memcpy (valbuf
, buf
+ 8 - len
, len
);
1021 /* Write into the appropriate registers a function return value stored
1022 in VALBUF of type TYPE. */
1025 sparc64_store_return_value (struct type
*type
, struct regcache
*regcache
,
1028 int len
= TYPE_LENGTH (type
);
1032 if (sparc64_structure_or_union_p (type
))
1034 /* Structure or Union return values. */
1035 gdb_assert (len
<= 32);
1037 /* Simplify matters by storing the complete value (including
1038 floating members) into %o0 and %o1. Floating members are
1039 also store in the appropriate floating-point registers. */
1040 memset (buf
, 0, sizeof (buf
));
1041 memcpy (buf
, valbuf
, len
);
1042 for (i
= 0; i
< ((len
+ 7) / 8); i
++)
1043 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
+ i
, buf
+ i
* 8);
1044 if (TYPE_CODE (type
) != TYPE_CODE_UNION
)
1045 sparc64_store_floating_fields (regcache
, type
, buf
, 0, 0);
1047 else if (sparc64_floating_p (type
))
1049 /* Floating return values. */
1050 memcpy (buf
, valbuf
, len
);
1051 for (i
= 0; i
< len
/ 4; i
++)
1052 regcache_cooked_write (regcache
, SPARC_F0_REGNUM
+ i
, buf
+ i
* 4);
1056 /* Integral and pointer return values. */
1057 gdb_assert (sparc64_integral_or_pointer_p (type
));
1059 /* ??? Do we need to do any sign-extension here? */
1061 memcpy (buf
+ 8 - len
, valbuf
, len
);
1062 regcache_cooked_write (regcache
, SPARC_O0_REGNUM
, buf
);
1066 static enum return_value_convention
1067 sparc64_return_value (struct gdbarch
*gdbarch
, struct type
*type
,
1068 struct regcache
*regcache
, void *readbuf
,
1069 const void *writebuf
)
1071 if (TYPE_LENGTH (type
) > 32)
1072 return RETURN_VALUE_STRUCT_CONVENTION
;
1075 sparc64_extract_return_value (type
, regcache
, readbuf
);
1077 sparc64_store_return_value (type
, regcache
, writebuf
);
1079 return RETURN_VALUE_REGISTER_CONVENTION
;
1084 sparc64_init_abi (struct gdbarch_info info
, struct gdbarch
*gdbarch
)
1086 struct gdbarch_tdep
*tdep
= gdbarch_tdep (gdbarch
);
1088 tdep
->pc_regnum
= SPARC64_PC_REGNUM
;
1089 tdep
->npc_regnum
= SPARC64_NPC_REGNUM
;
1091 /* This is what all the fuss is about. */
1092 set_gdbarch_long_bit (gdbarch
, 64);
1093 set_gdbarch_long_long_bit (gdbarch
, 64);
1094 set_gdbarch_ptr_bit (gdbarch
, 64);
1096 set_gdbarch_num_regs (gdbarch
, SPARC64_NUM_REGS
);
1097 set_gdbarch_register_name (gdbarch
, sparc64_register_name
);
1098 set_gdbarch_register_type (gdbarch
, sparc64_register_type
);
1099 set_gdbarch_num_pseudo_regs (gdbarch
, SPARC64_NUM_PSEUDO_REGS
);
1100 set_gdbarch_pseudo_register_read (gdbarch
, sparc64_pseudo_register_read
);
1101 set_gdbarch_pseudo_register_write (gdbarch
, sparc64_pseudo_register_write
);
1103 /* Register numbers of various important registers. */
1104 set_gdbarch_pc_regnum (gdbarch
, SPARC64_PC_REGNUM
); /* %pc */
1106 /* Call dummy code. */
1107 set_gdbarch_call_dummy_location (gdbarch
, AT_ENTRY_POINT
);
1108 set_gdbarch_push_dummy_code (gdbarch
, NULL
);
1109 set_gdbarch_push_dummy_call (gdbarch
, sparc64_push_dummy_call
);
1111 set_gdbarch_return_value (gdbarch
, sparc64_return_value
);
1112 set_gdbarch_stabs_argument_has_addr
1113 (gdbarch
, default_stabs_argument_has_addr
);
1115 set_gdbarch_skip_prologue (gdbarch
, sparc64_skip_prologue
);
1117 frame_unwind_append_sniffer (gdbarch
, sparc64_frame_sniffer
);
1118 frame_base_set_default (gdbarch
, &sparc64_frame_base
);
1122 /* Helper functions for dealing with register sets. */
1124 #define TSTATE_CWP 0x000000000000001fULL
1125 #define TSTATE_ICC 0x0000000f00000000ULL
1126 #define TSTATE_XCC 0x000000f000000000ULL
1128 #define PSR_S 0x00000080
1129 #define PSR_ICC 0x00f00000
1130 #define PSR_VERS 0x0f000000
1131 #define PSR_IMPL 0xf0000000
1132 #define PSR_V8PLUS 0xff000000
1133 #define PSR_XCC 0x000f0000
1136 sparc64_supply_gregset (const struct sparc_gregset
*gregset
,
1137 struct regcache
*regcache
,
1138 int regnum
, const void *gregs
)
1140 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
1141 const char *regs
= gregs
;
1146 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1148 int offset
= gregset
->r_tstate_offset
;
1149 ULONGEST tstate
, psr
;
1152 tstate
= extract_unsigned_integer (regs
+ offset
, 8);
1153 psr
= ((tstate
& TSTATE_CWP
) | PSR_S
| ((tstate
& TSTATE_ICC
) >> 12)
1154 | ((tstate
& TSTATE_XCC
) >> 20) | PSR_V8PLUS
);
1155 store_unsigned_integer (buf
, 4, psr
);
1156 regcache_raw_supply (regcache
, SPARC32_PSR_REGNUM
, buf
);
1159 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1160 regcache_raw_supply (regcache
, SPARC32_PC_REGNUM
,
1161 regs
+ gregset
->r_pc_offset
+ 4);
1163 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1164 regcache_raw_supply (regcache
, SPARC32_NPC_REGNUM
,
1165 regs
+ gregset
->r_npc_offset
+ 4);
1167 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1169 int offset
= gregset
->r_y_offset
+ 8 - gregset
->r_y_size
;
1170 regcache_raw_supply (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1175 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1176 regcache_raw_supply (regcache
, SPARC64_STATE_REGNUM
,
1177 regs
+ gregset
->r_tstate_offset
);
1179 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1180 regcache_raw_supply (regcache
, SPARC64_PC_REGNUM
,
1181 regs
+ gregset
->r_pc_offset
);
1183 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1184 regcache_raw_supply (regcache
, SPARC64_NPC_REGNUM
,
1185 regs
+ gregset
->r_npc_offset
);
1187 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1192 memcpy (buf
+ 8 - gregset
->r_y_size
,
1193 regs
+ gregset
->r_y_offset
, gregset
->r_y_size
);
1194 regcache_raw_supply (regcache
, SPARC64_Y_REGNUM
, buf
);
1197 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1198 && gregset
->r_fprs_offset
!= -1)
1199 regcache_raw_supply (regcache
, SPARC64_FPRS_REGNUM
,
1200 regs
+ gregset
->r_fprs_offset
);
1203 if (regnum
== SPARC_G0_REGNUM
|| regnum
== -1)
1204 regcache_raw_supply (regcache
, SPARC_G0_REGNUM
, NULL
);
1206 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1208 int offset
= gregset
->r_g1_offset
;
1213 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1215 if (regnum
== i
|| regnum
== -1)
1216 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1221 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1223 /* Not all of the register set variants include Locals and
1224 Inputs. For those that don't, we read them off the stack. */
1225 if (gregset
->r_l0_offset
== -1)
1229 regcache_cooked_read_unsigned (regcache
, SPARC_SP_REGNUM
, &sp
);
1230 sparc_supply_rwindow (regcache
, sp
, regnum
);
1234 int offset
= gregset
->r_l0_offset
;
1239 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1241 if (regnum
== i
|| regnum
== -1)
1242 regcache_raw_supply (regcache
, i
, regs
+ offset
);
1250 sparc64_collect_gregset (const struct sparc_gregset
*gregset
,
1251 const struct regcache
*regcache
,
1252 int regnum
, void *gregs
)
1254 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
1260 if (regnum
== SPARC32_PSR_REGNUM
|| regnum
== -1)
1262 int offset
= gregset
->r_tstate_offset
;
1263 ULONGEST tstate
, psr
;
1266 tstate
= extract_unsigned_integer (regs
+ offset
, 8);
1267 regcache_raw_collect (regcache
, SPARC32_PSR_REGNUM
, buf
);
1268 psr
= extract_unsigned_integer (buf
, 4);
1269 tstate
|= (psr
& PSR_ICC
) << 12;
1270 if ((psr
& (PSR_VERS
| PSR_IMPL
)) == PSR_V8PLUS
)
1271 tstate
|= (psr
& PSR_XCC
) << 20;
1272 store_unsigned_integer (buf
, 8, tstate
);
1273 memcpy (regs
+ offset
, buf
, 8);
1276 if (regnum
== SPARC32_PC_REGNUM
|| regnum
== -1)
1277 regcache_raw_collect (regcache
, SPARC32_PC_REGNUM
,
1278 regs
+ gregset
->r_pc_offset
+ 4);
1280 if (regnum
== SPARC32_NPC_REGNUM
|| regnum
== -1)
1281 regcache_raw_collect (regcache
, SPARC32_NPC_REGNUM
,
1282 regs
+ gregset
->r_npc_offset
+ 4);
1284 if (regnum
== SPARC32_Y_REGNUM
|| regnum
== -1)
1286 int offset
= gregset
->r_y_offset
+ 8 - gregset
->r_y_size
;
1287 regcache_raw_collect (regcache
, SPARC32_Y_REGNUM
, regs
+ offset
);
1292 if (regnum
== SPARC64_STATE_REGNUM
|| regnum
== -1)
1293 regcache_raw_collect (regcache
, SPARC64_STATE_REGNUM
,
1294 regs
+ gregset
->r_tstate_offset
);
1296 if (regnum
== SPARC64_PC_REGNUM
|| regnum
== -1)
1297 regcache_raw_collect (regcache
, SPARC64_PC_REGNUM
,
1298 regs
+ gregset
->r_pc_offset
);
1300 if (regnum
== SPARC64_NPC_REGNUM
|| regnum
== -1)
1301 regcache_raw_collect (regcache
, SPARC64_NPC_REGNUM
,
1302 regs
+ gregset
->r_npc_offset
);
1304 if (regnum
== SPARC64_Y_REGNUM
|| regnum
== -1)
1308 regcache_raw_collect (regcache
, SPARC64_Y_REGNUM
, buf
);
1309 memcpy (regs
+ gregset
->r_y_offset
,
1310 buf
+ 8 - gregset
->r_y_size
, gregset
->r_y_size
);
1313 if ((regnum
== SPARC64_FPRS_REGNUM
|| regnum
== -1)
1314 && gregset
->r_fprs_offset
!= -1)
1315 regcache_raw_collect (regcache
, SPARC64_FPRS_REGNUM
,
1316 regs
+ gregset
->r_fprs_offset
);
1320 if ((regnum
>= SPARC_G1_REGNUM
&& regnum
<= SPARC_O7_REGNUM
) || regnum
== -1)
1322 int offset
= gregset
->r_g1_offset
;
1327 /* %g0 is always zero. */
1328 for (i
= SPARC_G1_REGNUM
; i
<= SPARC_O7_REGNUM
; i
++)
1330 if (regnum
== i
|| regnum
== -1)
1331 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1336 if ((regnum
>= SPARC_L0_REGNUM
&& regnum
<= SPARC_I7_REGNUM
) || regnum
== -1)
1338 /* Not all of the register set variants include Locals and
1339 Inputs. For those that don't, we read them off the stack. */
1340 if (gregset
->r_l0_offset
!= -1)
1342 int offset
= gregset
->r_l0_offset
;
1347 for (i
= SPARC_L0_REGNUM
; i
<= SPARC_I7_REGNUM
; i
++)
1349 if (regnum
== i
|| regnum
== -1)
1350 regcache_raw_collect (regcache
, i
, regs
+ offset
);
1358 sparc64_supply_fpregset (struct regcache
*regcache
,
1359 int regnum
, const void *fpregs
)
1361 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
1362 const char *regs
= fpregs
;
1365 for (i
= 0; i
< 32; i
++)
1367 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1368 regcache_raw_supply (regcache
, SPARC_F0_REGNUM
+ i
, regs
+ (i
* 4));
1373 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1374 regcache_raw_supply (regcache
, SPARC32_FSR_REGNUM
,
1375 regs
+ (32 * 4) + (16 * 8) + 4);
1379 for (i
= 0; i
< 16; i
++)
1381 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1382 regcache_raw_supply (regcache
, SPARC64_F32_REGNUM
+ i
,
1383 regs
+ (32 * 4) + (i
* 8));
1386 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1387 regcache_raw_supply (regcache
, SPARC64_FSR_REGNUM
,
1388 regs
+ (32 * 4) + (16 * 8));
1393 sparc64_collect_fpregset (const struct regcache
*regcache
,
1394 int regnum
, void *fpregs
)
1396 int sparc32
= (gdbarch_ptr_bit (current_gdbarch
) == 32);
1397 char *regs
= fpregs
;
1400 for (i
= 0; i
< 32; i
++)
1402 if (regnum
== (SPARC_F0_REGNUM
+ i
) || regnum
== -1)
1403 regcache_raw_collect (regcache
, SPARC_F0_REGNUM
+ i
, regs
+ (i
* 4));
1408 if (regnum
== SPARC32_FSR_REGNUM
|| regnum
== -1)
1409 regcache_raw_collect (regcache
, SPARC32_FSR_REGNUM
,
1410 regs
+ (32 * 4) + (16 * 8) + 4);
1414 for (i
= 0; i
< 16; i
++)
1416 if (regnum
== (SPARC64_F32_REGNUM
+ i
) || regnum
== -1)
1417 regcache_raw_collect (regcache
, SPARC64_F32_REGNUM
+ i
,
1418 regs
+ (32 * 4) + (i
* 8));
1421 if (regnum
== SPARC64_FSR_REGNUM
|| regnum
== -1)
1422 regcache_raw_collect (regcache
, SPARC64_FSR_REGNUM
,
1423 regs
+ (32 * 4) + (16 * 8));