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