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