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