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