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