Run --gc-sections tests only if supported.
[deliverable/binutils-gdb.git] / gdb / sparc64-tdep.c
CommitLineData
8b39fe56
MK
1/* Target-dependent code for UltraSPARC.
2
7b6bb8da 3 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
9b254dd1 4 Free Software Foundation, Inc.
8b39fe56
MK
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
a9762ec7 10 the Free Software Foundation; either version 3 of the License, or
8b39fe56
MK
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
a9762ec7 19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8b39fe56
MK
20
21#include "defs.h"
22#include "arch-utils.h"
02a71ae8 23#include "dwarf2-frame.h"
8b39fe56
MK
24#include "floatformat.h"
25#include "frame.h"
26#include "frame-base.h"
27#include "frame-unwind.h"
28#include "gdbcore.h"
29#include "gdbtypes.h"
386c036b
MK
30#include "inferior.h"
31#include "symtab.h"
32#include "objfiles.h"
8b39fe56
MK
33#include "osabi.h"
34#include "regcache.h"
35#include "target.h"
36#include "value.h"
37
38#include "gdb_assert.h"
39#include "gdb_string.h"
40
41#include "sparc64-tdep.h"
42
b021a221 43/* This file implements the SPARC 64-bit ABI as defined by the
8b39fe56
MK
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
46 SPARC. */
47
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. */
8b39fe56
MK
51\f
52/* The functions on this page are intended to be used to classify
53 function arguments. */
54
8b39fe56
MK
55/* Check whether TYPE is "Integral or Pointer". */
56
57static int
58sparc64_integral_or_pointer_p (const struct type *type)
59{
60 switch (TYPE_CODE (type))
61 {
62 case TYPE_CODE_INT:
63 case TYPE_CODE_BOOL:
64 case TYPE_CODE_CHAR:
65 case TYPE_CODE_ENUM:
66 case TYPE_CODE_RANGE:
67 {
68 int len = TYPE_LENGTH (type);
69 gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
70 }
71 return 1;
72 case TYPE_CODE_PTR:
73 case TYPE_CODE_REF:
74 {
75 int len = TYPE_LENGTH (type);
76 gdb_assert (len == 8);
77 }
78 return 1;
79 default:
80 break;
81 }
82
83 return 0;
84}
85
86/* Check whether TYPE is "Floating". */
87
88static int
89sparc64_floating_p (const struct type *type)
90{
91 switch (TYPE_CODE (type))
92 {
93 case TYPE_CODE_FLT:
94 {
95 int len = TYPE_LENGTH (type);
96 gdb_assert (len == 4 || len == 8 || len == 16);
97 }
98 return 1;
99 default:
100 break;
101 }
102
103 return 0;
104}
105
fe10a582
DM
106/* Check whether TYPE is "Complex Floating". */
107
108static int
109sparc64_complex_floating_p (const struct type *type)
110{
111 switch (TYPE_CODE (type))
112 {
113 case TYPE_CODE_COMPLEX:
114 {
115 int len = TYPE_LENGTH (type);
116 gdb_assert (len == 8 || len == 16 || len == 32);
117 }
118 return 1;
119 default:
120 break;
121 }
122
123 return 0;
124}
125
0497f5b0
JB
126/* Check whether TYPE is "Structure or Union".
127
128 In terms of Ada subprogram calls, arrays are treated the same as
129 struct and union types. So this function also returns non-zero
130 for array types. */
8b39fe56
MK
131
132static int
133sparc64_structure_or_union_p (const struct type *type)
134{
135 switch (TYPE_CODE (type))
136 {
137 case TYPE_CODE_STRUCT:
138 case TYPE_CODE_UNION:
0497f5b0 139 case TYPE_CODE_ARRAY:
8b39fe56
MK
140 return 1;
141 default:
142 break;
143 }
144
145 return 0;
146}
fd936806
MK
147\f
148
209bd28e 149/* Construct types for ISA-specific registers. */
fd936806 150
209bd28e
UW
151static struct type *
152sparc64_pstate_type (struct gdbarch *gdbarch)
153{
154 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
fd936806 155
209bd28e
UW
156 if (!tdep->sparc64_pstate_type)
157 {
158 struct type *type;
159
e9bb382b 160 type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8);
209bd28e
UW
161 append_flags_type_flag (type, 0, "AG");
162 append_flags_type_flag (type, 1, "IE");
163 append_flags_type_flag (type, 2, "PRIV");
164 append_flags_type_flag (type, 3, "AM");
165 append_flags_type_flag (type, 4, "PEF");
166 append_flags_type_flag (type, 5, "RED");
167 append_flags_type_flag (type, 8, "TLE");
168 append_flags_type_flag (type, 9, "CLE");
169 append_flags_type_flag (type, 10, "PID0");
170 append_flags_type_flag (type, 11, "PID1");
171
172 tdep->sparc64_pstate_type = type;
173 }
fd936806 174
209bd28e
UW
175 return tdep->sparc64_pstate_type;
176}
fd936806 177
209bd28e
UW
178static struct type *
179sparc64_fsr_type (struct gdbarch *gdbarch)
180{
181 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
182
183 if (!tdep->sparc64_fsr_type)
184 {
185 struct type *type;
186
e9bb382b 187 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8);
209bd28e
UW
188 append_flags_type_flag (type, 0, "NXA");
189 append_flags_type_flag (type, 1, "DZA");
190 append_flags_type_flag (type, 2, "UFA");
191 append_flags_type_flag (type, 3, "OFA");
192 append_flags_type_flag (type, 4, "NVA");
193 append_flags_type_flag (type, 5, "NXC");
194 append_flags_type_flag (type, 6, "DZC");
195 append_flags_type_flag (type, 7, "UFC");
196 append_flags_type_flag (type, 8, "OFC");
197 append_flags_type_flag (type, 9, "NVC");
198 append_flags_type_flag (type, 22, "NS");
199 append_flags_type_flag (type, 23, "NXM");
200 append_flags_type_flag (type, 24, "DZM");
201 append_flags_type_flag (type, 25, "UFM");
202 append_flags_type_flag (type, 26, "OFM");
203 append_flags_type_flag (type, 27, "NVM");
204
205 tdep->sparc64_fsr_type = type;
206 }
207
208 return tdep->sparc64_fsr_type;
209}
210
211static struct type *
212sparc64_fprs_type (struct gdbarch *gdbarch)
fd936806 213{
209bd28e
UW
214 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
215
216 if (!tdep->sparc64_fprs_type)
217 {
218 struct type *type;
219
e9bb382b 220 type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8);
209bd28e
UW
221 append_flags_type_flag (type, 0, "DL");
222 append_flags_type_flag (type, 1, "DU");
223 append_flags_type_flag (type, 2, "FEF");
224
225 tdep->sparc64_fprs_type = type;
226 }
227
228 return tdep->sparc64_fprs_type;
fd936806 229}
8b39fe56 230
209bd28e 231
8b39fe56
MK
232/* Register information. */
233
6707b003 234static const char *sparc64_register_names[] =
8b39fe56 235{
6707b003
UW
236 "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
237 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
238 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
239 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7",
240
241 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
242 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
243 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
244 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
245 "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
246 "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
247
248 "pc", "npc",
8b39fe56 249
6707b003
UW
250 /* FIXME: Give "state" a name until we start using register groups. */
251 "state",
252 "fsr",
253 "fprs",
254 "y",
8b39fe56
MK
255};
256
257/* Total number of registers. */
6707b003 258#define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
8b39fe56
MK
259
260/* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
261 registers as "psuedo" registers. */
262
6707b003 263static const char *sparc64_pseudo_register_names[] =
8b39fe56 264{
6707b003
UW
265 "cwp", "pstate", "asi", "ccr",
266
267 "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
268 "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
269 "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
270 "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
271
272 "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
273 "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
8b39fe56
MK
274};
275
276/* Total number of pseudo registers. */
6707b003 277#define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
8b39fe56
MK
278
279/* Return the name of register REGNUM. */
280
281static const char *
d93859e2 282sparc64_register_name (struct gdbarch *gdbarch, int regnum)
8b39fe56
MK
283{
284 if (regnum >= 0 && regnum < SPARC64_NUM_REGS)
6707b003 285 return sparc64_register_names[regnum];
8b39fe56
MK
286
287 if (regnum >= SPARC64_NUM_REGS
288 && regnum < SPARC64_NUM_REGS + SPARC64_NUM_PSEUDO_REGS)
6707b003 289 return sparc64_pseudo_register_names[regnum - SPARC64_NUM_REGS];
8b39fe56
MK
290
291 return NULL;
292}
293
294/* Return the GDB type object for the "standard" data type of data in
c378eb4e 295 register REGNUM. */
8b39fe56
MK
296
297static struct type *
298sparc64_register_type (struct gdbarch *gdbarch, int regnum)
299{
6707b003
UW
300 /* Raw registers. */
301
302 if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
0dfff4cb 303 return builtin_type (gdbarch)->builtin_data_ptr;
6707b003 304 if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
df4df182 305 return builtin_type (gdbarch)->builtin_int64;
6707b003 306 if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
0dfff4cb 307 return builtin_type (gdbarch)->builtin_float;
6707b003 308 if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
0dfff4cb 309 return builtin_type (gdbarch)->builtin_double;
6707b003 310 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
0dfff4cb 311 return builtin_type (gdbarch)->builtin_func_ptr;
6707b003
UW
312 /* This raw register contains the contents of %cwp, %pstate, %asi
313 and %ccr as laid out in a %tstate register. */
314 if (regnum == SPARC64_STATE_REGNUM)
df4df182 315 return builtin_type (gdbarch)->builtin_int64;
6707b003 316 if (regnum == SPARC64_FSR_REGNUM)
209bd28e 317 return sparc64_fsr_type (gdbarch);
6707b003 318 if (regnum == SPARC64_FPRS_REGNUM)
209bd28e 319 return sparc64_fprs_type (gdbarch);
6707b003
UW
320 /* "Although Y is a 64-bit register, its high-order 32 bits are
321 reserved and always read as 0." */
322 if (regnum == SPARC64_Y_REGNUM)
df4df182 323 return builtin_type (gdbarch)->builtin_int64;
6707b003
UW
324
325 /* Pseudo registers. */
326
327 if (regnum == SPARC64_CWP_REGNUM)
df4df182 328 return builtin_type (gdbarch)->builtin_int64;
6707b003 329 if (regnum == SPARC64_PSTATE_REGNUM)
209bd28e 330 return sparc64_pstate_type (gdbarch);
6707b003 331 if (regnum == SPARC64_ASI_REGNUM)
df4df182 332 return builtin_type (gdbarch)->builtin_int64;
6707b003 333 if (regnum == SPARC64_CCR_REGNUM)
df4df182 334 return builtin_type (gdbarch)->builtin_int64;
6707b003 335 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
0dfff4cb 336 return builtin_type (gdbarch)->builtin_double;
6707b003 337 if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
0dfff4cb 338 return builtin_type (gdbarch)->builtin_long_double;
6707b003
UW
339
340 internal_error (__FILE__, __LINE__, _("invalid regnum"));
8b39fe56
MK
341}
342
05d1431c 343static enum register_status
8b39fe56
MK
344sparc64_pseudo_register_read (struct gdbarch *gdbarch,
345 struct regcache *regcache,
e1613aba 346 int regnum, gdb_byte *buf)
8b39fe56 347{
e17a4113 348 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
05d1431c
PA
349 enum register_status status;
350
8b39fe56
MK
351 gdb_assert (regnum >= SPARC64_NUM_REGS);
352
353 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
354 {
355 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
05d1431c
PA
356 status = regcache_raw_read (regcache, regnum, buf);
357 if (status == REG_VALID)
358 status = regcache_raw_read (regcache, regnum + 1, buf + 4);
359 return status;
8b39fe56
MK
360 }
361 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
362 {
363 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
05d1431c 364 return regcache_raw_read (regcache, regnum, buf);
8b39fe56
MK
365 }
366 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
367 {
368 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
05d1431c
PA
369
370 status = regcache_raw_read (regcache, regnum, buf);
371 if (status == REG_VALID)
372 status = regcache_raw_read (regcache, regnum + 1, buf + 4);
373 if (status == REG_VALID)
374 status = regcache_raw_read (regcache, regnum + 2, buf + 8);
375 if (status == REG_VALID)
376 status = regcache_raw_read (regcache, regnum + 3, buf + 12);
377
378 return status;
8b39fe56
MK
379 }
380 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
381 {
382 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
05d1431c
PA
383
384 status = regcache_raw_read (regcache, regnum, buf);
385 if (status == REG_VALID)
386 status = regcache_raw_read (regcache, regnum + 1, buf + 8);
387
388 return status;
8b39fe56
MK
389 }
390 else if (regnum == SPARC64_CWP_REGNUM
391 || regnum == SPARC64_PSTATE_REGNUM
392 || regnum == SPARC64_ASI_REGNUM
393 || regnum == SPARC64_CCR_REGNUM)
394 {
395 ULONGEST state;
396
05d1431c
PA
397 status = regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
398 if (status != REG_VALID)
399 return status;
400
8b39fe56
MK
401 switch (regnum)
402 {
3567a8ea 403 case SPARC64_CWP_REGNUM:
8b39fe56
MK
404 state = (state >> 0) & ((1 << 5) - 1);
405 break;
3567a8ea 406 case SPARC64_PSTATE_REGNUM:
8b39fe56
MK
407 state = (state >> 8) & ((1 << 12) - 1);
408 break;
3567a8ea 409 case SPARC64_ASI_REGNUM:
8b39fe56
MK
410 state = (state >> 24) & ((1 << 8) - 1);
411 break;
3567a8ea 412 case SPARC64_CCR_REGNUM:
8b39fe56
MK
413 state = (state >> 32) & ((1 << 8) - 1);
414 break;
415 }
e17a4113 416 store_unsigned_integer (buf, 8, byte_order, state);
8b39fe56 417 }
05d1431c
PA
418
419 return REG_VALID;
8b39fe56
MK
420}
421
422static void
423sparc64_pseudo_register_write (struct gdbarch *gdbarch,
424 struct regcache *regcache,
e1613aba 425 int regnum, const gdb_byte *buf)
8b39fe56 426{
e17a4113 427 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
8b39fe56
MK
428 gdb_assert (regnum >= SPARC64_NUM_REGS);
429
430 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
431 {
432 regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
433 regcache_raw_write (regcache, regnum, buf);
e1613aba 434 regcache_raw_write (regcache, regnum + 1, buf + 4);
8b39fe56
MK
435 }
436 else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
437 {
438 regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
439 regcache_raw_write (regcache, regnum, buf);
440 }
441 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
442 {
443 regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
444 regcache_raw_write (regcache, regnum, buf);
e1613aba
MK
445 regcache_raw_write (regcache, regnum + 1, buf + 4);
446 regcache_raw_write (regcache, regnum + 2, buf + 8);
447 regcache_raw_write (regcache, regnum + 3, buf + 12);
8b39fe56
MK
448 }
449 else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
450 {
451 regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
452 regcache_raw_write (regcache, regnum, buf);
e1613aba 453 regcache_raw_write (regcache, regnum + 1, buf + 8);
8b39fe56 454 }
3567a8ea
MK
455 else if (regnum == SPARC64_CWP_REGNUM
456 || regnum == SPARC64_PSTATE_REGNUM
457 || regnum == SPARC64_ASI_REGNUM
458 || regnum == SPARC64_CCR_REGNUM)
459 {
460 ULONGEST state, bits;
461
462 regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state);
e17a4113 463 bits = extract_unsigned_integer (buf, 8, byte_order);
3567a8ea
MK
464 switch (regnum)
465 {
466 case SPARC64_CWP_REGNUM:
467 state |= ((bits & ((1 << 5) - 1)) << 0);
468 break;
469 case SPARC64_PSTATE_REGNUM:
470 state |= ((bits & ((1 << 12) - 1)) << 8);
471 break;
472 case SPARC64_ASI_REGNUM:
473 state |= ((bits & ((1 << 8) - 1)) << 24);
474 break;
475 case SPARC64_CCR_REGNUM:
476 state |= ((bits & ((1 << 8) - 1)) << 32);
477 break;
478 }
479 regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state);
480 }
8b39fe56 481}
8b39fe56
MK
482\f
483
8b39fe56
MK
484/* Return PC of first real instruction of the function starting at
485 START_PC. */
486
487static CORE_ADDR
6093d2eb 488sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
8b39fe56
MK
489{
490 struct symtab_and_line sal;
491 CORE_ADDR func_start, func_end;
386c036b 492 struct sparc_frame_cache cache;
8b39fe56
MK
493
494 /* This is the preferred method, find the end of the prologue by
495 using the debugging information. */
496 if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end))
497 {
498 sal = find_pc_line (func_start, 0);
499
500 if (sal.end < func_end
501 && start_pc <= sal.end)
502 return sal.end;
503 }
504
be8626e0
MD
505 return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL,
506 &cache);
8b39fe56
MK
507}
508
509/* Normal frames. */
510
386c036b 511static struct sparc_frame_cache *
236369e7 512sparc64_frame_cache (struct frame_info *this_frame, void **this_cache)
8b39fe56 513{
236369e7 514 return sparc_frame_cache (this_frame, this_cache);
8b39fe56
MK
515}
516
517static void
236369e7 518sparc64_frame_this_id (struct frame_info *this_frame, void **this_cache,
8b39fe56
MK
519 struct frame_id *this_id)
520{
386c036b 521 struct sparc_frame_cache *cache =
236369e7 522 sparc64_frame_cache (this_frame, this_cache);
8b39fe56
MK
523
524 /* This marks the outermost frame. */
525 if (cache->base == 0)
526 return;
527
528 (*this_id) = frame_id_build (cache->base, cache->pc);
529}
530
236369e7
JB
531static struct value *
532sparc64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
533 int regnum)
8b39fe56 534{
e17a4113 535 struct gdbarch *gdbarch = get_frame_arch (this_frame);
386c036b 536 struct sparc_frame_cache *cache =
236369e7 537 sparc64_frame_cache (this_frame, this_cache);
8b39fe56
MK
538
539 if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
540 {
236369e7 541 CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0;
8b39fe56 542
369c397b
JB
543 regnum =
544 (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM;
236369e7
JB
545 pc += get_frame_register_unsigned (this_frame, regnum) + 8;
546 return frame_unwind_got_constant (this_frame, regnum, pc);
8b39fe56
MK
547 }
548
f700a364
MK
549 /* Handle StackGhost. */
550 {
e17a4113 551 ULONGEST wcookie = sparc_fetch_wcookie (gdbarch);
f700a364
MK
552
553 if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM)
554 {
236369e7
JB
555 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
556 ULONGEST i7;
557
558 /* Read the value in from memory. */
559 i7 = get_frame_memory_unsigned (this_frame, addr, 8);
560 return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie);
f700a364
MK
561 }
562 }
563
369c397b 564 /* The previous frame's `local' and `in' registers may have been saved
8b39fe56 565 in the register save area. */
369c397b
JB
566 if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM
567 && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM))))
8b39fe56 568 {
236369e7 569 CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8;
8b39fe56 570
236369e7 571 return frame_unwind_got_memory (this_frame, regnum, addr);
8b39fe56
MK
572 }
573
369c397b
JB
574 /* The previous frame's `out' registers may be accessible as the current
575 frame's `in' registers. */
576 if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM
577 && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM))))
8b39fe56
MK
578 regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM);
579
236369e7 580 return frame_unwind_got_register (this_frame, regnum, regnum);
8b39fe56
MK
581}
582
583static const struct frame_unwind sparc64_frame_unwind =
584{
585 NORMAL_FRAME,
8fbca658 586 default_frame_unwind_stop_reason,
8b39fe56 587 sparc64_frame_this_id,
236369e7
JB
588 sparc64_frame_prev_register,
589 NULL,
590 default_frame_sniffer
8b39fe56 591};
8b39fe56
MK
592\f
593
594static CORE_ADDR
236369e7 595sparc64_frame_base_address (struct frame_info *this_frame, void **this_cache)
8b39fe56 596{
386c036b 597 struct sparc_frame_cache *cache =
236369e7 598 sparc64_frame_cache (this_frame, this_cache);
8b39fe56 599
5b2d44a0 600 return cache->base;
8b39fe56
MK
601}
602
603static const struct frame_base sparc64_frame_base =
604{
605 &sparc64_frame_unwind,
606 sparc64_frame_base_address,
607 sparc64_frame_base_address,
608 sparc64_frame_base_address
609};
8b39fe56
MK
610\f
611/* Check whether TYPE must be 16-byte aligned. */
612
613static int
614sparc64_16_byte_align_p (struct type *type)
615{
616 if (sparc64_floating_p (type) && TYPE_LENGTH (type) == 16)
617 return 1;
618
619 if (sparc64_structure_or_union_p (type))
620 {
621 int i;
622
623 for (i = 0; i < TYPE_NFIELDS (type); i++)
60af1db2
MK
624 {
625 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
626
627 if (sparc64_16_byte_align_p (subtype))
628 return 1;
629 }
8b39fe56
MK
630 }
631
632 return 0;
633}
634
635/* Store floating fields of element ELEMENT of an "parameter array"
636 that has type TYPE and is stored at BITPOS in VALBUF in the
637 apropriate registers of REGCACHE. This function can be called
638 recursively and therefore handles floating types in addition to
639 structures. */
640
641static void
642sparc64_store_floating_fields (struct regcache *regcache, struct type *type,
e1613aba 643 const gdb_byte *valbuf, int element, int bitpos)
8b39fe56 644{
fe10a582
DM
645 int len = TYPE_LENGTH (type);
646
8b39fe56
MK
647 gdb_assert (element < 16);
648
fe10a582
DM
649 if (sparc64_floating_p (type)
650 || (sparc64_complex_floating_p (type) && len <= 16))
8b39fe56 651 {
8b39fe56
MK
652 int regnum;
653
654 if (len == 16)
655 {
656 gdb_assert (bitpos == 0);
657 gdb_assert ((element % 2) == 0);
658
659 regnum = SPARC64_Q0_REGNUM + element / 2;
660 regcache_cooked_write (regcache, regnum, valbuf);
661 }
662 else if (len == 8)
663 {
664 gdb_assert (bitpos == 0 || bitpos == 64);
665
666 regnum = SPARC64_D0_REGNUM + element + bitpos / 64;
667 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
668 }
669 else
670 {
671 gdb_assert (len == 4);
672 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128);
673
674 regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32;
675 regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8));
676 }
677 }
678 else if (sparc64_structure_or_union_p (type))
679 {
680 int i;
681
682 for (i = 0; i < TYPE_NFIELDS (type); i++)
60af1db2
MK
683 {
684 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
685 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
686
687 sparc64_store_floating_fields (regcache, subtype, valbuf,
688 element, subpos);
689 }
200cc553
MK
690
691 /* GCC has an interesting bug. If TYPE is a structure that has
692 a single `float' member, GCC doesn't treat it as a structure
693 at all, but rather as an ordinary `float' argument. This
694 argument will be stored in %f1, as required by the psABI.
695 However, as a member of a structure the psABI requires it to
5154b0cd
MK
696 be stored in %f0. This bug is present in GCC 3.3.2, but
697 probably in older releases to. To appease GCC, if a
698 structure has only a single `float' member, we store its
699 value in %f1 too (we already have stored in %f0). */
200cc553
MK
700 if (TYPE_NFIELDS (type) == 1)
701 {
702 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0));
703
704 if (sparc64_floating_p (subtype) && TYPE_LENGTH (subtype) == 4)
705 regcache_cooked_write (regcache, SPARC_F1_REGNUM, valbuf);
706 }
8b39fe56
MK
707 }
708}
709
710/* Fetch floating fields from a variable of type TYPE from the
711 appropriate registers for BITPOS in REGCACHE and store it at BITPOS
712 in VALBUF. This function can be called recursively and therefore
713 handles floating types in addition to structures. */
714
715static void
716sparc64_extract_floating_fields (struct regcache *regcache, struct type *type,
e1613aba 717 gdb_byte *valbuf, int bitpos)
8b39fe56
MK
718{
719 if (sparc64_floating_p (type))
720 {
721 int len = TYPE_LENGTH (type);
722 int regnum;
723
724 if (len == 16)
725 {
726 gdb_assert (bitpos == 0 || bitpos == 128);
727
728 regnum = SPARC64_Q0_REGNUM + bitpos / 128;
729 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
730 }
731 else if (len == 8)
732 {
733 gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256);
734
735 regnum = SPARC64_D0_REGNUM + bitpos / 64;
736 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
737 }
738 else
739 {
740 gdb_assert (len == 4);
741 gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256);
742
743 regnum = SPARC_F0_REGNUM + bitpos / 32;
744 regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8));
745 }
746 }
747 else if (sparc64_structure_or_union_p (type))
748 {
749 int i;
750
751 for (i = 0; i < TYPE_NFIELDS (type); i++)
60af1db2
MK
752 {
753 struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i));
754 int subpos = bitpos + TYPE_FIELD_BITPOS (type, i);
755
756 sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos);
757 }
8b39fe56
MK
758 }
759}
760
761/* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is
762 non-zero) in REGCACHE and on the stack (starting from address SP). */
763
764static CORE_ADDR
765sparc64_store_arguments (struct regcache *regcache, int nargs,
766 struct value **args, CORE_ADDR sp,
767 int struct_return, CORE_ADDR struct_addr)
768{
df4df182 769 struct gdbarch *gdbarch = get_regcache_arch (regcache);
8b39fe56
MK
770 /* Number of extended words in the "parameter array". */
771 int num_elements = 0;
772 int element = 0;
773 int i;
774
775 /* Take BIAS into account. */
776 sp += BIAS;
777
778 /* First we calculate the number of extended words in the "parameter
779 array". While doing so we also convert some of the arguments. */
780
781 if (struct_return)
782 num_elements++;
783
784 for (i = 0; i < nargs; i++)
785 {
4991999e 786 struct type *type = value_type (args[i]);
8b39fe56
MK
787 int len = TYPE_LENGTH (type);
788
789 if (sparc64_structure_or_union_p (type))
790 {
791 /* Structure or Union arguments. */
792 if (len <= 16)
793 {
794 if (num_elements % 2 && sparc64_16_byte_align_p (type))
795 num_elements++;
796 num_elements += ((len + 7) / 8);
797 }
798 else
799 {
800 /* The psABI says that "Structures or unions larger than
801 sixteen bytes are copied by the caller and passed
802 indirectly; the caller will pass the address of a
803 correctly aligned structure value. This sixty-four
804 bit address will occupy one word in the parameter
805 array, and may be promoted to an %o register like any
806 other pointer value." Allocate memory for these
807 values on the stack. */
808 sp -= len;
809
810 /* Use 16-byte alignment for these values. That's
811 always correct, and wasting a few bytes shouldn't be
812 a problem. */
813 sp &= ~0xf;
814
0fd88904 815 write_memory (sp, value_contents (args[i]), len);
8b39fe56
MK
816 args[i] = value_from_pointer (lookup_pointer_type (type), sp);
817 num_elements++;
818 }
819 }
820 else if (sparc64_floating_p (type))
821 {
822 /* Floating arguments. */
823
824 if (len == 16)
825 {
826 /* The psABI says that "Each quad-precision parameter
827 value will be assigned to two extended words in the
828 parameter array. */
829 num_elements += 2;
830
831 /* The psABI says that "Long doubles must be
832 quad-aligned, and thus a hole might be introduced
833 into the parameter array to force alignment." Skip
834 an element if necessary. */
835 if (num_elements % 2)
836 num_elements++;
837 }
838 else
839 num_elements++;
840 }
841 else
842 {
843 /* Integral and pointer arguments. */
844 gdb_assert (sparc64_integral_or_pointer_p (type));
845
846 /* The psABI says that "Each argument value of integral type
847 smaller than an extended word will be widened by the
848 caller to an extended word according to the signed-ness
849 of the argument type." */
850 if (len < 8)
df4df182
UW
851 args[i] = value_cast (builtin_type (gdbarch)->builtin_int64,
852 args[i]);
8b39fe56
MK
853 num_elements++;
854 }
855 }
856
857 /* Allocate the "parameter array". */
858 sp -= num_elements * 8;
859
860 /* The psABI says that "Every stack frame must be 16-byte aligned." */
861 sp &= ~0xf;
862
863 /* Now we store the arguments in to the "paramater array". Some
864 Integer or Pointer arguments and Structure or Union arguments
865 will be passed in %o registers. Some Floating arguments and
866 floating members of structures are passed in floating-point
867 registers. However, for functions with variable arguments,
868 floating arguments are stored in an %0 register, and for
869 functions without a prototype floating arguments are stored in
870 both a floating-point and an %o registers, or a floating-point
871 register and memory. To simplify the logic here we always pass
872 arguments in memory, an %o register, and a floating-point
873 register if appropriate. This should be no problem since the
874 contents of any unused memory or registers in the "parameter
875 array" are undefined. */
876
877 if (struct_return)
878 {
879 regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr);
880 element++;
881 }
882
883 for (i = 0; i < nargs; i++)
884 {
e1613aba 885 const gdb_byte *valbuf = value_contents (args[i]);
4991999e 886 struct type *type = value_type (args[i]);
8b39fe56
MK
887 int len = TYPE_LENGTH (type);
888 int regnum = -1;
e1613aba 889 gdb_byte buf[16];
8b39fe56
MK
890
891 if (sparc64_structure_or_union_p (type))
892 {
893 /* Structure or Union arguments. */
894 gdb_assert (len <= 16);
895 memset (buf, 0, sizeof (buf));
896 valbuf = memcpy (buf, valbuf, len);
897
898 if (element % 2 && sparc64_16_byte_align_p (type))
899 element++;
900
901 if (element < 6)
902 {
903 regnum = SPARC_O0_REGNUM + element;
904 if (len > 8 && element < 5)
905 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
906 }
907
908 if (element < 16)
909 sparc64_store_floating_fields (regcache, type, valbuf, element, 0);
910 }
fe10a582 911 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
8b39fe56
MK
912 {
913 /* Floating arguments. */
914 if (len == 16)
915 {
916 if (element % 2)
917 element++;
918 if (element < 16)
919 regnum = SPARC64_Q0_REGNUM + element / 2;
920 }
921 else if (len == 8)
922 {
923 if (element < 16)
924 regnum = SPARC64_D0_REGNUM + element;
925 }
fe10a582 926 else if (len == 4)
8b39fe56
MK
927 {
928 /* The psABI says "Each single-precision parameter value
929 will be assigned to one extended word in the
930 parameter array, and right-justified within that
931 word; the left half (even floatregister) is
932 undefined." Even though the psABI says that "the
933 left half is undefined", set it to zero here. */
934 memset (buf, 0, 4);
8ada74e3
MK
935 memcpy (buf + 4, valbuf, 4);
936 valbuf = buf;
8b39fe56
MK
937 len = 8;
938 if (element < 16)
8ada74e3 939 regnum = SPARC64_D0_REGNUM + element;
8b39fe56
MK
940 }
941 }
942 else
943 {
944 /* Integral and pointer arguments. */
945 gdb_assert (len == 8);
946 if (element < 6)
947 regnum = SPARC_O0_REGNUM + element;
948 }
949
950 if (regnum != -1)
951 {
952 regcache_cooked_write (regcache, regnum, valbuf);
953
954 /* If we're storing the value in a floating-point register,
955 also store it in the corresponding %0 register(s). */
956 if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM)
957 {
958 gdb_assert (element < 6);
959 regnum = SPARC_O0_REGNUM + element;
960 regcache_cooked_write (regcache, regnum, valbuf);
961 }
962 else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM)
963 {
964 gdb_assert (element < 6);
965 regnum = SPARC_O0_REGNUM + element;
966 regcache_cooked_write (regcache, regnum, valbuf);
d47079be 967 regcache_cooked_write (regcache, regnum + 1, valbuf + 8);
8b39fe56
MK
968 }
969 }
970
c4f2d4d7 971 /* Always store the argument in memory. */
8b39fe56
MK
972 write_memory (sp + element * 8, valbuf, len);
973 element += ((len + 7) / 8);
974 }
975
976 gdb_assert (element == num_elements);
977
978 /* Take BIAS into account. */
979 sp -= BIAS;
980 return sp;
981}
982
49a45ecf
JB
983static CORE_ADDR
984sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address)
985{
986 /* The ABI requires 16-byte alignment. */
987 return address & ~0xf;
988}
989
8b39fe56 990static CORE_ADDR
7d9b040b 991sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
8b39fe56
MK
992 struct regcache *regcache, CORE_ADDR bp_addr,
993 int nargs, struct value **args, CORE_ADDR sp,
994 int struct_return, CORE_ADDR struct_addr)
995{
996 /* Set return address. */
997 regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8);
998
999 /* Set up function arguments. */
1000 sp = sparc64_store_arguments (regcache, nargs, args, sp,
1001 struct_return, struct_addr);
1002
1003 /* Allocate the register save area. */
1004 sp -= 16 * 8;
1005
1006 /* Stack should be 16-byte aligned at this point. */
3567a8ea 1007 gdb_assert ((sp + BIAS) % 16 == 0);
8b39fe56
MK
1008
1009 /* Finally, update the stack pointer. */
1010 regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp);
1011
5b2d44a0 1012 return sp + BIAS;
8b39fe56
MK
1013}
1014\f
1015
1016/* Extract from an array REGBUF containing the (raw) register state, a
1017 function return value of TYPE, and copy that into VALBUF. */
1018
1019static void
1020sparc64_extract_return_value (struct type *type, struct regcache *regcache,
e1613aba 1021 gdb_byte *valbuf)
8b39fe56
MK
1022{
1023 int len = TYPE_LENGTH (type);
e1613aba 1024 gdb_byte buf[32];
8b39fe56
MK
1025 int i;
1026
1027 if (sparc64_structure_or_union_p (type))
1028 {
1029 /* Structure or Union return values. */
1030 gdb_assert (len <= 32);
1031
1032 for (i = 0; i < ((len + 7) / 8); i++)
1033 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1034 if (TYPE_CODE (type) != TYPE_CODE_UNION)
1035 sparc64_extract_floating_fields (regcache, type, buf, 0);
1036 memcpy (valbuf, buf, len);
1037 }
1038 else if (sparc64_floating_p (type))
1039 {
1040 /* Floating return values. */
1041 for (i = 0; i < len / 4; i++)
1042 regcache_cooked_read (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
1043 memcpy (valbuf, buf, len);
1044 }
4bd87714
JB
1045 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1046 {
1047 /* Small arrays are returned the same way as small structures. */
1048 gdb_assert (len <= 32);
1049
1050 for (i = 0; i < ((len + 7) / 8); i++)
1051 regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1052 memcpy (valbuf, buf, len);
1053 }
8b39fe56
MK
1054 else
1055 {
1056 /* Integral and pointer return values. */
1057 gdb_assert (sparc64_integral_or_pointer_p (type));
1058
1059 /* Just stripping off any unused bytes should preserve the
1060 signed-ness just fine. */
1061 regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf);
1062 memcpy (valbuf, buf + 8 - len, len);
1063 }
1064}
1065
1066/* Write into the appropriate registers a function return value stored
1067 in VALBUF of type TYPE. */
1068
1069static void
1070sparc64_store_return_value (struct type *type, struct regcache *regcache,
e1613aba 1071 const gdb_byte *valbuf)
8b39fe56
MK
1072{
1073 int len = TYPE_LENGTH (type);
e1613aba 1074 gdb_byte buf[16];
8b39fe56
MK
1075 int i;
1076
1077 if (sparc64_structure_or_union_p (type))
1078 {
1079 /* Structure or Union return values. */
1080 gdb_assert (len <= 32);
1081
1082 /* Simplify matters by storing the complete value (including
1083 floating members) into %o0 and %o1. Floating members are
1084 also store in the appropriate floating-point registers. */
1085 memset (buf, 0, sizeof (buf));
1086 memcpy (buf, valbuf, len);
1087 for (i = 0; i < ((len + 7) / 8); i++)
60af1db2 1088 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
8b39fe56
MK
1089 if (TYPE_CODE (type) != TYPE_CODE_UNION)
1090 sparc64_store_floating_fields (regcache, type, buf, 0, 0);
1091 }
fe10a582 1092 else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type))
8b39fe56
MK
1093 {
1094 /* Floating return values. */
1095 memcpy (buf, valbuf, len);
1096 for (i = 0; i < len / 4; i++)
1097 regcache_cooked_write (regcache, SPARC_F0_REGNUM + i, buf + i * 4);
1098 }
4bd87714
JB
1099 else if (TYPE_CODE (type) == TYPE_CODE_ARRAY)
1100 {
1101 /* Small arrays are returned the same way as small structures. */
1102 gdb_assert (len <= 32);
1103
1104 memset (buf, 0, sizeof (buf));
1105 memcpy (buf, valbuf, len);
1106 for (i = 0; i < ((len + 7) / 8); i++)
1107 regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8);
1108 }
8b39fe56
MK
1109 else
1110 {
1111 /* Integral and pointer return values. */
1112 gdb_assert (sparc64_integral_or_pointer_p (type));
1113
1114 /* ??? Do we need to do any sign-extension here? */
1115 memset (buf, 0, 8);
1116 memcpy (buf + 8 - len, valbuf, len);
1117 regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf);
1118 }
1119}
1120
60af1db2 1121static enum return_value_convention
c055b101
CV
1122sparc64_return_value (struct gdbarch *gdbarch, struct type *func_type,
1123 struct type *type, struct regcache *regcache,
1124 gdb_byte *readbuf, const gdb_byte *writebuf)
8b39fe56 1125{
60af1db2
MK
1126 if (TYPE_LENGTH (type) > 32)
1127 return RETURN_VALUE_STRUCT_CONVENTION;
1128
1129 if (readbuf)
1130 sparc64_extract_return_value (type, regcache, readbuf);
1131 if (writebuf)
1132 sparc64_store_return_value (type, regcache, writebuf);
1133
1134 return RETURN_VALUE_REGISTER_CONVENTION;
8b39fe56 1135}
8b39fe56 1136\f
8b39fe56 1137
02a71ae8
MK
1138static void
1139sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum,
aff37fc1 1140 struct dwarf2_frame_state_reg *reg,
4a4e5149 1141 struct frame_info *this_frame)
02a71ae8
MK
1142{
1143 switch (regnum)
1144 {
1145 case SPARC_G0_REGNUM:
1146 /* Since %g0 is always zero, there is no point in saving it, and
1147 people will be inclined omit it from the CFI. Make sure we
1148 don't warn about that. */
1149 reg->how = DWARF2_FRAME_REG_SAME_VALUE;
1150 break;
1151 case SPARC_SP_REGNUM:
1152 reg->how = DWARF2_FRAME_REG_CFA;
1153 break;
1154 case SPARC64_PC_REGNUM:
1155 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1156 reg->loc.offset = 8;
1157 break;
1158 case SPARC64_NPC_REGNUM:
1159 reg->how = DWARF2_FRAME_REG_RA_OFFSET;
1160 reg->loc.offset = 12;
1161 break;
1162 }
1163}
1164
8b39fe56 1165void
386c036b 1166sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
8b39fe56 1167{
386c036b 1168 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
8b39fe56 1169
386c036b
MK
1170 tdep->pc_regnum = SPARC64_PC_REGNUM;
1171 tdep->npc_regnum = SPARC64_NPC_REGNUM;
8b39fe56 1172
386c036b 1173 /* This is what all the fuss is about. */
8b39fe56
MK
1174 set_gdbarch_long_bit (gdbarch, 64);
1175 set_gdbarch_long_long_bit (gdbarch, 64);
1176 set_gdbarch_ptr_bit (gdbarch, 64);
8b39fe56
MK
1177
1178 set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS);
1179 set_gdbarch_register_name (gdbarch, sparc64_register_name);
1180 set_gdbarch_register_type (gdbarch, sparc64_register_type);
1181 set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS);
1182 set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read);
1183 set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write);
1184
1185 /* Register numbers of various important registers. */
8b39fe56 1186 set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */
8b39fe56
MK
1187
1188 /* Call dummy code. */
49a45ecf 1189 set_gdbarch_frame_align (gdbarch, sparc64_frame_align);
386c036b
MK
1190 set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT);
1191 set_gdbarch_push_dummy_code (gdbarch, NULL);
8b39fe56
MK
1192 set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call);
1193
60af1db2 1194 set_gdbarch_return_value (gdbarch, sparc64_return_value);
386c036b
MK
1195 set_gdbarch_stabs_argument_has_addr
1196 (gdbarch, default_stabs_argument_has_addr);
8b39fe56
MK
1197
1198 set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue);
1199
02a71ae8
MK
1200 /* Hook in the DWARF CFI frame unwinder. */
1201 dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg);
1202 /* FIXME: kettenis/20050423: Don't enable the unwinder until the
1203 StackGhost issues have been resolved. */
1204
236369e7 1205 frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind);
8b39fe56 1206 frame_base_set_default (gdbarch, &sparc64_frame_base);
386c036b
MK
1207}
1208\f
8b39fe56 1209
386c036b 1210/* Helper functions for dealing with register sets. */
8b39fe56 1211
386c036b
MK
1212#define TSTATE_CWP 0x000000000000001fULL
1213#define TSTATE_ICC 0x0000000f00000000ULL
1214#define TSTATE_XCC 0x000000f000000000ULL
8b39fe56 1215
386c036b
MK
1216#define PSR_S 0x00000080
1217#define PSR_ICC 0x00f00000
1218#define PSR_VERS 0x0f000000
1219#define PSR_IMPL 0xf0000000
1220#define PSR_V8PLUS 0xff000000
1221#define PSR_XCC 0x000f0000
8b39fe56 1222
3567a8ea 1223void
386c036b
MK
1224sparc64_supply_gregset (const struct sparc_gregset *gregset,
1225 struct regcache *regcache,
1226 int regnum, const void *gregs)
8b39fe56 1227{
e17a4113
UW
1228 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1229 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1230 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
e1613aba 1231 const gdb_byte *regs = gregs;
22e74ef9 1232 gdb_byte zero[8] = { 0 };
8b39fe56
MK
1233 int i;
1234
386c036b 1235 if (sparc32)
8b39fe56 1236 {
386c036b
MK
1237 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1238 {
1239 int offset = gregset->r_tstate_offset;
1240 ULONGEST tstate, psr;
e1613aba 1241 gdb_byte buf[4];
386c036b 1242
e17a4113 1243 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
386c036b
MK
1244 psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12)
1245 | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS);
e17a4113 1246 store_unsigned_integer (buf, 4, byte_order, psr);
386c036b
MK
1247 regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, buf);
1248 }
1249
1250 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1251 regcache_raw_supply (regcache, SPARC32_PC_REGNUM,
1252 regs + gregset->r_pc_offset + 4);
1253
1254 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1255 regcache_raw_supply (regcache, SPARC32_NPC_REGNUM,
1256 regs + gregset->r_npc_offset + 4);
8b39fe56 1257
386c036b 1258 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
8b39fe56 1259 {
386c036b
MK
1260 int offset = gregset->r_y_offset + 8 - gregset->r_y_size;
1261 regcache_raw_supply (regcache, SPARC32_Y_REGNUM, regs + offset);
8b39fe56
MK
1262 }
1263 }
1264 else
1265 {
386c036b
MK
1266 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1267 regcache_raw_supply (regcache, SPARC64_STATE_REGNUM,
1268 regs + gregset->r_tstate_offset);
8b39fe56 1269
386c036b
MK
1270 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1271 regcache_raw_supply (regcache, SPARC64_PC_REGNUM,
1272 regs + gregset->r_pc_offset);
1273
1274 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1275 regcache_raw_supply (regcache, SPARC64_NPC_REGNUM,
1276 regs + gregset->r_npc_offset);
1277
1278 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
3567a8ea 1279 {
e1613aba 1280 gdb_byte buf[8];
386c036b
MK
1281
1282 memset (buf, 0, 8);
1283 memcpy (buf + 8 - gregset->r_y_size,
1284 regs + gregset->r_y_offset, gregset->r_y_size);
1285 regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf);
3567a8ea 1286 }
8b39fe56 1287
386c036b
MK
1288 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1289 && gregset->r_fprs_offset != -1)
1290 regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM,
1291 regs + gregset->r_fprs_offset);
1292 }
1293
1294 if (regnum == SPARC_G0_REGNUM || regnum == -1)
22e74ef9 1295 regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero);
386c036b
MK
1296
1297 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1298 {
1299 int offset = gregset->r_g1_offset;
1300
1301 if (sparc32)
1302 offset += 4;
1303
1304 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
8b39fe56 1305 {
3567a8ea 1306 if (regnum == i || regnum == -1)
386c036b
MK
1307 regcache_raw_supply (regcache, i, regs + offset);
1308 offset += 8;
1309 }
1310 }
1311
1312 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1313 {
1314 /* Not all of the register set variants include Locals and
1315 Inputs. For those that don't, we read them off the stack. */
1316 if (gregset->r_l0_offset == -1)
1317 {
1318 ULONGEST sp;
1319
1320 regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp);
1321 sparc_supply_rwindow (regcache, sp, regnum);
1322 }
1323 else
1324 {
1325 int offset = gregset->r_l0_offset;
1326
1327 if (sparc32)
1328 offset += 4;
1329
1330 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
3567a8ea 1331 {
386c036b
MK
1332 if (regnum == i || regnum == -1)
1333 regcache_raw_supply (regcache, i, regs + offset);
1334 offset += 8;
3567a8ea 1335 }
8b39fe56
MK
1336 }
1337 }
1338}
1339
1340void
386c036b
MK
1341sparc64_collect_gregset (const struct sparc_gregset *gregset,
1342 const struct regcache *regcache,
1343 int regnum, void *gregs)
8b39fe56 1344{
e17a4113
UW
1345 struct gdbarch *gdbarch = get_regcache_arch (regcache);
1346 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
1347 int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32);
e1613aba 1348 gdb_byte *regs = gregs;
3567a8ea
MK
1349 int i;
1350
386c036b 1351 if (sparc32)
8b39fe56 1352 {
386c036b
MK
1353 if (regnum == SPARC32_PSR_REGNUM || regnum == -1)
1354 {
1355 int offset = gregset->r_tstate_offset;
1356 ULONGEST tstate, psr;
e1613aba 1357 gdb_byte buf[8];
386c036b 1358
e17a4113 1359 tstate = extract_unsigned_integer (regs + offset, 8, byte_order);
386c036b 1360 regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, buf);
e17a4113 1361 psr = extract_unsigned_integer (buf, 4, byte_order);
386c036b
MK
1362 tstate |= (psr & PSR_ICC) << 12;
1363 if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS)
1364 tstate |= (psr & PSR_XCC) << 20;
e17a4113 1365 store_unsigned_integer (buf, 8, byte_order, tstate);
386c036b
MK
1366 memcpy (regs + offset, buf, 8);
1367 }
8b39fe56 1368
386c036b
MK
1369 if (regnum == SPARC32_PC_REGNUM || regnum == -1)
1370 regcache_raw_collect (regcache, SPARC32_PC_REGNUM,
1371 regs + gregset->r_pc_offset + 4);
1372
1373 if (regnum == SPARC32_NPC_REGNUM || regnum == -1)
1374 regcache_raw_collect (regcache, SPARC32_NPC_REGNUM,
1375 regs + gregset->r_npc_offset + 4);
1376
1377 if (regnum == SPARC32_Y_REGNUM || regnum == -1)
8b39fe56 1378 {
386c036b
MK
1379 int offset = gregset->r_y_offset + 8 - gregset->r_y_size;
1380 regcache_raw_collect (regcache, SPARC32_Y_REGNUM, regs + offset);
8b39fe56
MK
1381 }
1382 }
1383 else
1384 {
386c036b
MK
1385 if (regnum == SPARC64_STATE_REGNUM || regnum == -1)
1386 regcache_raw_collect (regcache, SPARC64_STATE_REGNUM,
1387 regs + gregset->r_tstate_offset);
1388
1389 if (regnum == SPARC64_PC_REGNUM || regnum == -1)
1390 regcache_raw_collect (regcache, SPARC64_PC_REGNUM,
1391 regs + gregset->r_pc_offset);
3567a8ea 1392
386c036b
MK
1393 if (regnum == SPARC64_NPC_REGNUM || regnum == -1)
1394 regcache_raw_collect (regcache, SPARC64_NPC_REGNUM,
1395 regs + gregset->r_npc_offset);
3567a8ea 1396
386c036b 1397 if (regnum == SPARC64_Y_REGNUM || regnum == -1)
3567a8ea 1398 {
e1613aba 1399 gdb_byte buf[8];
386c036b
MK
1400
1401 regcache_raw_collect (regcache, SPARC64_Y_REGNUM, buf);
1402 memcpy (regs + gregset->r_y_offset,
1403 buf + 8 - gregset->r_y_size, gregset->r_y_size);
1404 }
1405
1406 if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1)
1407 && gregset->r_fprs_offset != -1)
1408 regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM,
1409 regs + gregset->r_fprs_offset);
1410
1411 }
1412
1413 if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1)
1414 {
1415 int offset = gregset->r_g1_offset;
1416
1417 if (sparc32)
1418 offset += 4;
1419
1420 /* %g0 is always zero. */
1421 for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++)
1422 {
1423 if (regnum == i || regnum == -1)
1424 regcache_raw_collect (regcache, i, regs + offset);
1425 offset += 8;
1426 }
1427 }
1428
1429 if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1)
1430 {
1431 /* Not all of the register set variants include Locals and
1432 Inputs. For those that don't, we read them off the stack. */
1433 if (gregset->r_l0_offset != -1)
1434 {
1435 int offset = gregset->r_l0_offset;
1436
1437 if (sparc32)
1438 offset += 4;
1439
1440 for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++)
3567a8ea 1441 {
386c036b
MK
1442 if (regnum == i || regnum == -1)
1443 regcache_raw_collect (regcache, i, regs + offset);
1444 offset += 8;
3567a8ea
MK
1445 }
1446 }
8b39fe56
MK
1447 }
1448}
8b39fe56 1449
386c036b
MK
1450void
1451sparc64_supply_fpregset (struct regcache *regcache,
1452 int regnum, const void *fpregs)
1453{
e6d4f032 1454 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
e1613aba 1455 const gdb_byte *regs = fpregs;
386c036b
MK
1456 int i;
1457
1458 for (i = 0; i < 32; i++)
1459 {
1460 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1461 regcache_raw_supply (regcache, SPARC_F0_REGNUM + i, regs + (i * 4));
1462 }
1463
1464 if (sparc32)
1465 {
1466 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1467 regcache_raw_supply (regcache, SPARC32_FSR_REGNUM,
1468 regs + (32 * 4) + (16 * 8) + 4);
1469 }
1470 else
1471 {
1472 for (i = 0; i < 16; i++)
1473 {
1474 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1475 regcache_raw_supply (regcache, SPARC64_F32_REGNUM + i,
1476 regs + (32 * 4) + (i * 8));
1477 }
1478
1479 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1480 regcache_raw_supply (regcache, SPARC64_FSR_REGNUM,
1481 regs + (32 * 4) + (16 * 8));
1482 }
1483}
8b39fe56
MK
1484
1485void
386c036b
MK
1486sparc64_collect_fpregset (const struct regcache *regcache,
1487 int regnum, void *fpregs)
8b39fe56 1488{
e6d4f032 1489 int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32);
e1613aba 1490 gdb_byte *regs = fpregs;
386c036b
MK
1491 int i;
1492
1493 for (i = 0; i < 32; i++)
1494 {
1495 if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1)
1496 regcache_raw_collect (regcache, SPARC_F0_REGNUM + i, regs + (i * 4));
1497 }
1498
1499 if (sparc32)
1500 {
1501 if (regnum == SPARC32_FSR_REGNUM || regnum == -1)
1502 regcache_raw_collect (regcache, SPARC32_FSR_REGNUM,
1503 regs + (32 * 4) + (16 * 8) + 4);
1504 }
1505 else
1506 {
1507 for (i = 0; i < 16; i++)
1508 {
1509 if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1)
1510 regcache_raw_collect (regcache, SPARC64_F32_REGNUM + i,
1511 regs + (32 * 4) + (i * 8));
1512 }
1513
1514 if (regnum == SPARC64_FSR_REGNUM || regnum == -1)
1515 regcache_raw_collect (regcache, SPARC64_FSR_REGNUM,
1516 regs + (32 * 4) + (16 * 8));
1517 }
8b39fe56 1518}
fd936806 1519
This page took 0.881283 seconds and 4 git commands to generate.