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