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 | 48 | \f |
58afddc6 WP |
49 | /* The M7 processor supports an Application Data Integrity (ADI) feature |
50 | that detects invalid data accesses. When software allocates memory and | |
51 | enables ADI on the allocated memory, it chooses a 4-bit version number, | |
52 | sets the version in the upper 4 bits of the 64-bit pointer to that data, | |
53 | and stores the 4-bit version in every cacheline of the object. Hardware | |
54 | saves the latter in spare bits in the cache and memory hierarchy. On each | |
55 | load and store, the processor compares the upper 4 VA (virtual address) bits | |
56 | to the cacheline's version. If there is a mismatch, the processor generates | |
57 | a version mismatch trap which can be either precise or disrupting. | |
58 | The trap is an error condition which the kernel delivers to the process | |
59 | as a SIGSEGV signal. | |
60 | ||
61 | The upper 4 bits of the VA represent a version and are not part of the | |
62 | true address. The processor clears these bits and sign extends bit 59 | |
63 | to generate the true address. | |
64 | ||
65 | Note that 32-bit applications cannot use ADI. */ | |
66 | ||
67 | ||
68 | #include <algorithm> | |
69 | #include "cli/cli-utils.h" | |
70 | #include "gdbcmd.h" | |
71 | #include "auxv.h" | |
72 | ||
73 | #define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus") | |
74 | ||
75 | /* ELF Auxiliary vectors */ | |
76 | #ifndef AT_ADI_BLKSZ | |
77 | #define AT_ADI_BLKSZ 34 | |
78 | #endif | |
79 | #ifndef AT_ADI_NBITS | |
80 | #define AT_ADI_NBITS 35 | |
81 | #endif | |
82 | #ifndef AT_ADI_UEONADI | |
83 | #define AT_ADI_UEONADI 36 | |
84 | #endif | |
85 | ||
86 | /* ADI command list. */ | |
87 | static struct cmd_list_element *sparc64adilist = NULL; | |
88 | ||
89 | /* ADI stat settings. */ | |
90 | typedef struct | |
91 | { | |
92 | /* The ADI block size. */ | |
93 | unsigned long blksize; | |
94 | ||
95 | /* Number of bits used for an ADI version tag which can be | |
654670a4 WP |
96 | used together with the shift value for an ADI version tag |
97 | to encode or extract the ADI version value in a pointer. */ | |
58afddc6 WP |
98 | unsigned long nbits; |
99 | ||
100 | /* The maximum ADI version tag value supported. */ | |
101 | int max_version; | |
102 | ||
103 | /* ADI version tag file. */ | |
104 | int tag_fd = 0; | |
105 | ||
106 | /* ADI availability check has been done. */ | |
107 | bool checked_avail = false; | |
108 | ||
109 | /* ADI is available. */ | |
110 | bool is_avail = false; | |
111 | ||
112 | } adi_stat_t; | |
113 | ||
114 | /* Per-process ADI stat info. */ | |
115 | ||
116 | typedef struct sparc64_adi_info | |
117 | { | |
118 | sparc64_adi_info (pid_t pid_) | |
119 | : pid (pid_) | |
120 | {} | |
121 | ||
122 | /* The process identifier. */ | |
123 | pid_t pid; | |
124 | ||
125 | /* The ADI stat. */ | |
126 | adi_stat_t stat = {}; | |
127 | ||
128 | } sparc64_adi_info; | |
129 | ||
130 | static std::forward_list<sparc64_adi_info> adi_proc_list; | |
131 | ||
132 | ||
133 | /* Get ADI info for process PID, creating one if it doesn't exist. */ | |
134 | ||
135 | static sparc64_adi_info * | |
136 | get_adi_info_proc (pid_t pid) | |
137 | { | |
138 | auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (), | |
139 | [&pid] (const sparc64_adi_info &info) | |
140 | { | |
141 | return info.pid == pid; | |
142 | }); | |
143 | ||
144 | if (found == adi_proc_list.end ()) | |
145 | { | |
146 | adi_proc_list.emplace_front (pid); | |
147 | return &adi_proc_list.front (); | |
148 | } | |
149 | else | |
150 | { | |
151 | return &(*found); | |
152 | } | |
153 | } | |
154 | ||
155 | static adi_stat_t | |
156 | get_adi_info (pid_t pid) | |
157 | { | |
158 | sparc64_adi_info *proc; | |
159 | ||
160 | proc = get_adi_info_proc (pid); | |
161 | return proc->stat; | |
162 | } | |
163 | ||
164 | /* Is called when GDB is no longer debugging process PID. It | |
165 | deletes data structure that keeps track of the ADI stat. */ | |
166 | ||
167 | void | |
168 | sparc64_forget_process (pid_t pid) | |
169 | { | |
170 | int target_errno; | |
171 | ||
172 | for (auto pit = adi_proc_list.before_begin (), | |
173 | it = std::next (pit); | |
174 | it != adi_proc_list.end (); | |
175 | ) | |
176 | { | |
177 | if ((*it).pid == pid) | |
178 | { | |
179 | if ((*it).stat.tag_fd > 0) | |
180 | target_fileio_close ((*it).stat.tag_fd, &target_errno); | |
181 | adi_proc_list.erase_after (pit); | |
182 | break; | |
183 | } | |
184 | else | |
185 | pit = it++; | |
186 | } | |
187 | ||
188 | } | |
189 | ||
190 | static void | |
191 | info_adi_command (char *args, int from_tty) | |
192 | { | |
193 | printf_unfiltered ("\"adi\" must be followed by \"examine\" " | |
194 | "or \"assign\".\n"); | |
195 | help_list (sparc64adilist, "adi ", all_commands, gdb_stdout); | |
196 | } | |
197 | ||
198 | /* Read attributes of a maps entry in /proc/[pid]/adi/maps. */ | |
199 | ||
200 | static void | |
201 | read_maps_entry (const char *line, | |
202 | ULONGEST *addr, ULONGEST *endaddr) | |
203 | { | |
204 | const char *p = line; | |
205 | ||
206 | *addr = strtoulst (p, &p, 16); | |
207 | if (*p == '-') | |
208 | p++; | |
209 | ||
210 | *endaddr = strtoulst (p, &p, 16); | |
211 | } | |
212 | ||
213 | /* Check if ADI is available. */ | |
214 | ||
215 | static bool | |
216 | adi_available (void) | |
217 | { | |
218 | pid_t pid = ptid_get_pid (inferior_ptid); | |
219 | sparc64_adi_info *proc = get_adi_info_proc (pid); | |
654670a4 | 220 | CORE_ADDR value; |
58afddc6 WP |
221 | |
222 | if (proc->stat.checked_avail) | |
223 | return proc->stat.is_avail; | |
224 | ||
225 | proc->stat.checked_avail = true; | |
654670a4 | 226 | if (target_auxv_search (¤t_target, AT_ADI_BLKSZ, &value) <= 0) |
58afddc6 | 227 | return false; |
654670a4 WP |
228 | proc->stat.blksize = value; |
229 | target_auxv_search (¤t_target, AT_ADI_NBITS, &value); | |
230 | proc->stat.nbits = value; | |
58afddc6 WP |
231 | proc->stat.max_version = (1 << proc->stat.nbits) - 2; |
232 | proc->stat.is_avail = true; | |
233 | ||
234 | return proc->stat.is_avail; | |
235 | } | |
236 | ||
237 | /* Normalize a versioned address - a VA with ADI bits (63-60) set. */ | |
238 | ||
239 | static CORE_ADDR | |
240 | adi_normalize_address (CORE_ADDR addr) | |
241 | { | |
242 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
243 | ||
244 | if (ast.nbits) | |
654670a4 WP |
245 | { |
246 | /* Clear upper bits. */ | |
247 | addr &= ((uint64_t) -1) >> ast.nbits; | |
248 | ||
249 | /* Sign extend. */ | |
250 | CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1); | |
251 | return (addr ^ signbit) - signbit; | |
252 | } | |
58afddc6 WP |
253 | return addr; |
254 | } | |
255 | ||
256 | /* Align a normalized address - a VA with bit 59 sign extended into | |
257 | ADI bits. */ | |
258 | ||
259 | static CORE_ADDR | |
260 | adi_align_address (CORE_ADDR naddr) | |
261 | { | |
262 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
263 | ||
264 | return (naddr - (naddr % ast.blksize)) / ast.blksize; | |
265 | } | |
266 | ||
267 | /* Convert a byte count to count at a ratio of 1:adi_blksz. */ | |
268 | ||
269 | static int | |
270 | adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl) | |
271 | { | |
272 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
273 | ||
274 | return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl; | |
275 | } | |
276 | ||
277 | /* The /proc/[pid]/adi/tags file, which allows gdb to get/set ADI | |
278 | version in a target process, maps linearly to the address space | |
279 | of the target process at a ratio of 1:adi_blksz. | |
280 | ||
281 | A read (or write) at offset K in the file returns (or modifies) | |
282 | the ADI version tag stored in the cacheline containing address | |
283 | K * adi_blksz, encoded as 1 version tag per byte. The allowed | |
284 | version tag values are between 0 and adi_stat.max_version. */ | |
285 | ||
286 | static int | |
287 | adi_tag_fd (void) | |
288 | { | |
289 | pid_t pid = ptid_get_pid (inferior_ptid); | |
290 | sparc64_adi_info *proc = get_adi_info_proc (pid); | |
291 | ||
292 | if (proc->stat.tag_fd != 0) | |
293 | return proc->stat.tag_fd; | |
294 | ||
295 | char cl_name[MAX_PROC_NAME_SIZE]; | |
296 | snprintf (cl_name, sizeof(cl_name), "/proc/%d/adi/tags", pid); | |
297 | int target_errno; | |
298 | proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL, | |
299 | 0, &target_errno); | |
300 | return proc->stat.tag_fd; | |
301 | } | |
302 | ||
303 | /* Check if an address set is ADI enabled, using /proc/[pid]/adi/maps | |
304 | which was exported by the kernel and contains the currently ADI | |
305 | mapped memory regions and their access permissions. */ | |
306 | ||
307 | static bool | |
308 | adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt) | |
309 | { | |
310 | char filename[MAX_PROC_NAME_SIZE]; | |
311 | size_t i = 0; | |
312 | ||
313 | pid_t pid = ptid_get_pid (inferior_ptid); | |
314 | snprintf (filename, sizeof filename, "/proc/%d/adi/maps", pid); | |
315 | char *data = target_fileio_read_stralloc (NULL, filename); | |
316 | if (data) | |
317 | { | |
318 | struct cleanup *cleanup = make_cleanup (xfree, data); | |
319 | adi_stat_t adi_stat = get_adi_info (pid); | |
320 | char *line; | |
321 | for (line = strtok (data, "\n"); line; line = strtok (NULL, "\n")) | |
322 | { | |
323 | ULONGEST addr, endaddr; | |
324 | ||
325 | read_maps_entry (line, &addr, &endaddr); | |
326 | ||
327 | while (((vaddr + i) * adi_stat.blksize) >= addr | |
328 | && ((vaddr + i) * adi_stat.blksize) < endaddr) | |
329 | { | |
330 | if (++i == cnt) | |
331 | { | |
332 | do_cleanups (cleanup); | |
333 | return true; | |
334 | } | |
335 | } | |
336 | } | |
337 | do_cleanups (cleanup); | |
338 | } | |
339 | else | |
340 | warning (_("unable to open /proc file '%s'"), filename); | |
341 | ||
342 | return false; | |
343 | } | |
344 | ||
345 | /* Read ADI version tag value for memory locations starting at "VADDR" | |
346 | for "SIZE" number of bytes. */ | |
347 | ||
348 | static int | |
349 | adi_read_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags) | |
350 | { | |
351 | int fd = adi_tag_fd (); | |
352 | if (fd == -1) | |
353 | return -1; | |
354 | ||
355 | if (!adi_is_addr_mapped (vaddr, size)) | |
356 | { | |
357 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
654670a4 WP |
358 | error(_("Address at %s is not in ADI maps"), |
359 | paddress (target_gdbarch (), vaddr * ast.blksize)); | |
58afddc6 WP |
360 | } |
361 | ||
362 | int target_errno; | |
363 | return target_fileio_pread (fd, tags, size, vaddr, &target_errno); | |
364 | } | |
365 | ||
366 | /* Write ADI version tag for memory locations starting at "VADDR" for | |
367 | "SIZE" number of bytes to "TAGS". */ | |
368 | ||
369 | static int | |
370 | adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags) | |
371 | { | |
372 | int fd = adi_tag_fd (); | |
373 | if (fd == -1) | |
374 | return -1; | |
375 | ||
376 | if (!adi_is_addr_mapped (vaddr, size)) | |
377 | { | |
378 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
654670a4 WP |
379 | error(_("Address at %s is not in ADI maps"), |
380 | paddress (target_gdbarch (), vaddr * ast.blksize)); | |
58afddc6 WP |
381 | } |
382 | ||
383 | int target_errno; | |
384 | return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno); | |
385 | } | |
386 | ||
387 | /* Print ADI version tag value in "TAGS" for memory locations starting | |
388 | at "VADDR" with number of "CNT". */ | |
389 | ||
390 | static void | |
391 | adi_print_versions (CORE_ADDR vaddr, size_t cnt, unsigned char *tags) | |
392 | { | |
393 | int v_idx = 0; | |
394 | const int maxelts = 8; /* # of elements per line */ | |
395 | ||
396 | adi_stat_t adi_stat = get_adi_info (ptid_get_pid (inferior_ptid)); | |
397 | ||
398 | while (cnt > 0) | |
399 | { | |
400 | QUIT; | |
654670a4 WP |
401 | printf_filtered ("%s:\t", |
402 | paddress (target_gdbarch (), vaddr * adi_stat.blksize)); | |
58afddc6 WP |
403 | for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--) |
404 | { | |
405 | if (tags[v_idx] == 0xff) /* no version tag */ | |
406 | printf_filtered ("-"); | |
407 | else | |
408 | printf_filtered ("%1X", tags[v_idx]); | |
409 | if (cnt > 1) | |
410 | printf_filtered (" "); | |
411 | ++v_idx; | |
412 | } | |
413 | printf_filtered ("\n"); | |
414 | gdb_flush (gdb_stdout); | |
415 | vaddr += maxelts; | |
416 | } | |
417 | } | |
418 | ||
419 | static void | |
420 | do_examine (CORE_ADDR start, int bcnt) | |
421 | { | |
422 | CORE_ADDR vaddr = adi_normalize_address (start); | |
423 | struct cleanup *cleanup; | |
424 | ||
425 | CORE_ADDR vstart = adi_align_address (vaddr); | |
426 | int cnt = adi_convert_byte_count (vaddr, bcnt, vstart); | |
427 | unsigned char *buf = (unsigned char *) xmalloc (cnt); | |
428 | cleanup = make_cleanup (xfree, buf); | |
429 | int read_cnt = adi_read_versions (vstart, cnt, buf); | |
430 | if (read_cnt == -1) | |
431 | error (_("No ADI information")); | |
432 | else if (read_cnt < cnt) | |
654670a4 | 433 | error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr)); |
58afddc6 WP |
434 | |
435 | adi_print_versions (vstart, cnt, buf); | |
436 | ||
437 | do_cleanups (cleanup); | |
438 | } | |
439 | ||
440 | static void | |
441 | do_assign (CORE_ADDR start, size_t bcnt, int version) | |
442 | { | |
443 | CORE_ADDR vaddr = adi_normalize_address (start); | |
444 | ||
445 | CORE_ADDR vstart = adi_align_address (vaddr); | |
446 | int cnt = adi_convert_byte_count (vaddr, bcnt, vstart); | |
447 | std::vector<unsigned char> buf (cnt, version); | |
448 | int set_cnt = adi_write_versions (vstart, cnt, buf.data ()); | |
449 | ||
450 | if (set_cnt == -1) | |
451 | error (_("No ADI information")); | |
452 | else if (set_cnt < cnt) | |
654670a4 | 453 | error(_("No ADI information at %s"), paddress (target_gdbarch (), vaddr)); |
58afddc6 WP |
454 | |
455 | } | |
456 | ||
457 | /* ADI examine version tag command. | |
458 | ||
459 | Command syntax: | |
460 | ||
461 | adi (examine|x)/count <addr> */ | |
462 | ||
463 | static void | |
464 | adi_examine_command (char *args, int from_tty) | |
465 | { | |
466 | /* make sure program is active and adi is available */ | |
467 | if (!target_has_execution) | |
468 | error (_("ADI command requires a live process/thread")); | |
469 | ||
470 | if (!adi_available ()) | |
471 | error (_("No ADI information")); | |
472 | ||
473 | pid_t pid = ptid_get_pid (inferior_ptid); | |
474 | sparc64_adi_info *proc = get_adi_info_proc (pid); | |
475 | int cnt = 1; | |
476 | char *p = args; | |
477 | if (p && *p == '/') | |
478 | { | |
479 | p++; | |
480 | cnt = get_number (&p); | |
481 | } | |
482 | ||
483 | CORE_ADDR next_address = 0; | |
484 | if (p != 0 && *p != 0) | |
485 | next_address = parse_and_eval_address (p); | |
486 | if (!cnt || !next_address) | |
487 | error (_("Usage: adi examine|x[/count] <addr>")); | |
488 | ||
489 | do_examine (next_address, cnt); | |
490 | } | |
491 | ||
492 | /* ADI assign version tag command. | |
493 | ||
494 | Command syntax: | |
495 | ||
496 | adi (assign|a)/count <addr> = <version> */ | |
497 | ||
498 | static void | |
499 | adi_assign_command (char *args, int from_tty) | |
500 | { | |
501 | /* make sure program is active and adi is available */ | |
502 | if (!target_has_execution) | |
503 | error (_("ADI command requires a live process/thread")); | |
504 | ||
505 | if (!adi_available ()) | |
506 | error (_("No ADI information")); | |
507 | ||
508 | char *exp = args; | |
509 | if (exp == 0) | |
510 | error_no_arg (_("Usage: adi assign|a[/count] <addr> = <version>")); | |
511 | ||
512 | char *q = (char *) strchr (exp, '='); | |
513 | if (q) | |
514 | *q++ = 0; | |
515 | else | |
516 | error (_("Usage: adi assign|a[/count] <addr> = <version>")); | |
517 | ||
518 | size_t cnt = 1; | |
519 | char *p = args; | |
520 | if (exp && *exp == '/') | |
521 | { | |
522 | p = exp + 1; | |
523 | cnt = get_number (&p); | |
524 | } | |
525 | ||
526 | CORE_ADDR next_address = 0; | |
527 | if (p != 0 && *p != 0) | |
528 | next_address = parse_and_eval_address (p); | |
529 | else | |
530 | error (_("Usage: adi assign|a[/count] <addr> = <version>")); | |
531 | ||
532 | int version = 0; | |
533 | if (q != NULL) /* parse version tag */ | |
534 | { | |
535 | adi_stat_t ast = get_adi_info (ptid_get_pid (inferior_ptid)); | |
536 | version = parse_and_eval_long (q); | |
537 | if (version < 0 || version > ast.max_version) | |
538 | error (_("Invalid ADI version tag %d"), version); | |
539 | } | |
540 | ||
541 | do_assign (next_address, cnt, version); | |
542 | } | |
543 | ||
544 | void | |
545 | _initialize_sparc64_adi_tdep (void) | |
546 | { | |
547 | ||
548 | add_prefix_cmd ("adi", class_support, info_adi_command, | |
549 | _("ADI version related commands."), | |
550 | &sparc64adilist, "adi ", 0, &cmdlist); | |
551 | add_cmd ("examine", class_support, adi_examine_command, | |
552 | _("Examine ADI versions."), &sparc64adilist); | |
553 | add_alias_cmd ("x", "examine", no_class, 1, &sparc64adilist); | |
554 | add_cmd ("assign", class_support, adi_assign_command, | |
555 | _("Assign ADI versions."), &sparc64adilist); | |
556 | ||
557 | } | |
558 | \f | |
559 | ||
8b39fe56 MK |
560 | /* The functions on this page are intended to be used to classify |
561 | function arguments. */ | |
562 | ||
8b39fe56 MK |
563 | /* Check whether TYPE is "Integral or Pointer". */ |
564 | ||
565 | static int | |
566 | sparc64_integral_or_pointer_p (const struct type *type) | |
567 | { | |
568 | switch (TYPE_CODE (type)) | |
569 | { | |
570 | case TYPE_CODE_INT: | |
571 | case TYPE_CODE_BOOL: | |
572 | case TYPE_CODE_CHAR: | |
573 | case TYPE_CODE_ENUM: | |
574 | case TYPE_CODE_RANGE: | |
575 | { | |
576 | int len = TYPE_LENGTH (type); | |
577 | gdb_assert (len == 1 || len == 2 || len == 4 || len == 8); | |
578 | } | |
579 | return 1; | |
580 | case TYPE_CODE_PTR: | |
581 | case TYPE_CODE_REF: | |
aa006118 | 582 | case TYPE_CODE_RVALUE_REF: |
8b39fe56 MK |
583 | { |
584 | int len = TYPE_LENGTH (type); | |
585 | gdb_assert (len == 8); | |
586 | } | |
587 | return 1; | |
588 | default: | |
589 | break; | |
590 | } | |
591 | ||
592 | return 0; | |
593 | } | |
594 | ||
595 | /* Check whether TYPE is "Floating". */ | |
596 | ||
597 | static int | |
598 | sparc64_floating_p (const struct type *type) | |
599 | { | |
600 | switch (TYPE_CODE (type)) | |
601 | { | |
602 | case TYPE_CODE_FLT: | |
603 | { | |
604 | int len = TYPE_LENGTH (type); | |
605 | gdb_assert (len == 4 || len == 8 || len == 16); | |
606 | } | |
607 | return 1; | |
608 | default: | |
609 | break; | |
610 | } | |
611 | ||
612 | return 0; | |
613 | } | |
614 | ||
fe10a582 DM |
615 | /* Check whether TYPE is "Complex Floating". */ |
616 | ||
617 | static int | |
618 | sparc64_complex_floating_p (const struct type *type) | |
619 | { | |
620 | switch (TYPE_CODE (type)) | |
621 | { | |
622 | case TYPE_CODE_COMPLEX: | |
623 | { | |
624 | int len = TYPE_LENGTH (type); | |
625 | gdb_assert (len == 8 || len == 16 || len == 32); | |
626 | } | |
627 | return 1; | |
628 | default: | |
629 | break; | |
630 | } | |
631 | ||
632 | return 0; | |
633 | } | |
634 | ||
0497f5b0 JB |
635 | /* Check whether TYPE is "Structure or Union". |
636 | ||
637 | In terms of Ada subprogram calls, arrays are treated the same as | |
638 | struct and union types. So this function also returns non-zero | |
639 | for array types. */ | |
8b39fe56 MK |
640 | |
641 | static int | |
642 | sparc64_structure_or_union_p (const struct type *type) | |
643 | { | |
644 | switch (TYPE_CODE (type)) | |
645 | { | |
646 | case TYPE_CODE_STRUCT: | |
647 | case TYPE_CODE_UNION: | |
0497f5b0 | 648 | case TYPE_CODE_ARRAY: |
8b39fe56 MK |
649 | return 1; |
650 | default: | |
651 | break; | |
652 | } | |
653 | ||
654 | return 0; | |
655 | } | |
fd936806 MK |
656 | \f |
657 | ||
209bd28e | 658 | /* Construct types for ISA-specific registers. */ |
fd936806 | 659 | |
209bd28e UW |
660 | static struct type * |
661 | sparc64_pstate_type (struct gdbarch *gdbarch) | |
662 | { | |
663 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
fd936806 | 664 | |
209bd28e UW |
665 | if (!tdep->sparc64_pstate_type) |
666 | { | |
667 | struct type *type; | |
668 | ||
e9bb382b | 669 | type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 8); |
209bd28e UW |
670 | append_flags_type_flag (type, 0, "AG"); |
671 | append_flags_type_flag (type, 1, "IE"); | |
672 | append_flags_type_flag (type, 2, "PRIV"); | |
673 | append_flags_type_flag (type, 3, "AM"); | |
674 | append_flags_type_flag (type, 4, "PEF"); | |
675 | append_flags_type_flag (type, 5, "RED"); | |
676 | append_flags_type_flag (type, 8, "TLE"); | |
677 | append_flags_type_flag (type, 9, "CLE"); | |
678 | append_flags_type_flag (type, 10, "PID0"); | |
679 | append_flags_type_flag (type, 11, "PID1"); | |
680 | ||
681 | tdep->sparc64_pstate_type = type; | |
682 | } | |
fd936806 | 683 | |
209bd28e UW |
684 | return tdep->sparc64_pstate_type; |
685 | } | |
fd936806 | 686 | |
5badf10a IR |
687 | static struct type * |
688 | sparc64_ccr_type (struct gdbarch *gdbarch) | |
689 | { | |
690 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
691 | ||
692 | if (tdep->sparc64_ccr_type == NULL) | |
693 | { | |
694 | struct type *type; | |
695 | ||
696 | type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 8); | |
697 | append_flags_type_flag (type, 0, "icc.c"); | |
698 | append_flags_type_flag (type, 1, "icc.v"); | |
699 | append_flags_type_flag (type, 2, "icc.z"); | |
700 | append_flags_type_flag (type, 3, "icc.n"); | |
701 | append_flags_type_flag (type, 4, "xcc.c"); | |
702 | append_flags_type_flag (type, 5, "xcc.v"); | |
703 | append_flags_type_flag (type, 6, "xcc.z"); | |
704 | append_flags_type_flag (type, 7, "xcc.n"); | |
705 | ||
706 | tdep->sparc64_ccr_type = type; | |
707 | } | |
708 | ||
709 | return tdep->sparc64_ccr_type; | |
710 | } | |
711 | ||
209bd28e UW |
712 | static struct type * |
713 | sparc64_fsr_type (struct gdbarch *gdbarch) | |
714 | { | |
715 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
716 | ||
717 | if (!tdep->sparc64_fsr_type) | |
718 | { | |
719 | struct type *type; | |
720 | ||
e9bb382b | 721 | type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 8); |
5badf10a IR |
722 | append_flags_type_flag (type, 0, "NXC"); |
723 | append_flags_type_flag (type, 1, "DZC"); | |
724 | append_flags_type_flag (type, 2, "UFC"); | |
725 | append_flags_type_flag (type, 3, "OFC"); | |
726 | append_flags_type_flag (type, 4, "NVC"); | |
727 | append_flags_type_flag (type, 5, "NXA"); | |
728 | append_flags_type_flag (type, 6, "DZA"); | |
729 | append_flags_type_flag (type, 7, "UFA"); | |
730 | append_flags_type_flag (type, 8, "OFA"); | |
731 | append_flags_type_flag (type, 9, "NVA"); | |
209bd28e UW |
732 | append_flags_type_flag (type, 22, "NS"); |
733 | append_flags_type_flag (type, 23, "NXM"); | |
734 | append_flags_type_flag (type, 24, "DZM"); | |
735 | append_flags_type_flag (type, 25, "UFM"); | |
736 | append_flags_type_flag (type, 26, "OFM"); | |
737 | append_flags_type_flag (type, 27, "NVM"); | |
738 | ||
739 | tdep->sparc64_fsr_type = type; | |
740 | } | |
741 | ||
742 | return tdep->sparc64_fsr_type; | |
743 | } | |
744 | ||
745 | static struct type * | |
746 | sparc64_fprs_type (struct gdbarch *gdbarch) | |
fd936806 | 747 | { |
209bd28e UW |
748 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
749 | ||
750 | if (!tdep->sparc64_fprs_type) | |
751 | { | |
752 | struct type *type; | |
753 | ||
e9bb382b | 754 | type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 8); |
209bd28e UW |
755 | append_flags_type_flag (type, 0, "DL"); |
756 | append_flags_type_flag (type, 1, "DU"); | |
757 | append_flags_type_flag (type, 2, "FEF"); | |
758 | ||
759 | tdep->sparc64_fprs_type = type; | |
760 | } | |
761 | ||
762 | return tdep->sparc64_fprs_type; | |
fd936806 | 763 | } |
8b39fe56 | 764 | |
209bd28e | 765 | |
8b39fe56 | 766 | /* Register information. */ |
7a36499a IR |
767 | #define SPARC64_FPU_REGISTERS \ |
768 | "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \ | |
769 | "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \ | |
770 | "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \ | |
771 | "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \ | |
772 | "f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \ | |
773 | "f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62" | |
774 | #define SPARC64_CP0_REGISTERS \ | |
775 | "pc", "npc", \ | |
776 | /* FIXME: Give "state" a name until we start using register groups. */ \ | |
777 | "state", \ | |
778 | "fsr", \ | |
779 | "fprs", \ | |
780 | "y" | |
8b39fe56 | 781 | |
3f7b46f2 IR |
782 | static const char *sparc64_fpu_register_names[] = { SPARC64_FPU_REGISTERS }; |
783 | static const char *sparc64_cp0_register_names[] = { SPARC64_CP0_REGISTERS }; | |
784 | ||
6707b003 | 785 | static const char *sparc64_register_names[] = |
8b39fe56 | 786 | { |
7a36499a IR |
787 | SPARC_CORE_REGISTERS, |
788 | SPARC64_FPU_REGISTERS, | |
789 | SPARC64_CP0_REGISTERS | |
8b39fe56 MK |
790 | }; |
791 | ||
792 | /* Total number of registers. */ | |
6707b003 | 793 | #define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names) |
8b39fe56 MK |
794 | |
795 | /* We provide the aliases %d0..%d62 and %q0..%q60 for the floating | |
796 | registers as "psuedo" registers. */ | |
797 | ||
6707b003 | 798 | static const char *sparc64_pseudo_register_names[] = |
8b39fe56 | 799 | { |
6707b003 UW |
800 | "cwp", "pstate", "asi", "ccr", |
801 | ||
802 | "d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14", | |
803 | "d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30", | |
804 | "d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46", | |
805 | "d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62", | |
806 | ||
807 | "q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28", | |
808 | "q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60", | |
8b39fe56 MK |
809 | }; |
810 | ||
811 | /* Total number of pseudo registers. */ | |
6707b003 | 812 | #define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names) |
8b39fe56 | 813 | |
7a36499a IR |
814 | /* Return the name of pseudo register REGNUM. */ |
815 | ||
816 | static const char * | |
817 | sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum) | |
818 | { | |
819 | regnum -= gdbarch_num_regs (gdbarch); | |
820 | ||
821 | if (regnum < SPARC64_NUM_PSEUDO_REGS) | |
822 | return sparc64_pseudo_register_names[regnum]; | |
823 | ||
824 | internal_error (__FILE__, __LINE__, | |
825 | _("sparc64_pseudo_register_name: bad register number %d"), | |
826 | regnum); | |
827 | } | |
828 | ||
8b39fe56 MK |
829 | /* Return the name of register REGNUM. */ |
830 | ||
831 | static const char * | |
d93859e2 | 832 | sparc64_register_name (struct gdbarch *gdbarch, int regnum) |
8b39fe56 | 833 | { |
3f7b46f2 IR |
834 | if (tdesc_has_registers (gdbarch_target_desc (gdbarch))) |
835 | return tdesc_register_name (gdbarch, regnum); | |
836 | ||
7a36499a | 837 | if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)) |
6707b003 | 838 | return sparc64_register_names[regnum]; |
8b39fe56 | 839 | |
7a36499a IR |
840 | return sparc64_pseudo_register_name (gdbarch, regnum); |
841 | } | |
842 | ||
843 | /* Return the GDB type object for the "standard" data type of data in | |
844 | pseudo register REGNUM. */ | |
845 | ||
846 | static struct type * | |
847 | sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum) | |
848 | { | |
849 | regnum -= gdbarch_num_regs (gdbarch); | |
850 | ||
851 | if (regnum == SPARC64_CWP_REGNUM) | |
852 | return builtin_type (gdbarch)->builtin_int64; | |
853 | if (regnum == SPARC64_PSTATE_REGNUM) | |
854 | return sparc64_pstate_type (gdbarch); | |
855 | if (regnum == SPARC64_ASI_REGNUM) | |
856 | return builtin_type (gdbarch)->builtin_int64; | |
857 | if (regnum == SPARC64_CCR_REGNUM) | |
5badf10a | 858 | return sparc64_ccr_type (gdbarch); |
7a36499a IR |
859 | if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM) |
860 | return builtin_type (gdbarch)->builtin_double; | |
861 | if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM) | |
862 | return builtin_type (gdbarch)->builtin_long_double; | |
8b39fe56 | 863 | |
7a36499a IR |
864 | internal_error (__FILE__, __LINE__, |
865 | _("sparc64_pseudo_register_type: bad register number %d"), | |
866 | regnum); | |
8b39fe56 MK |
867 | } |
868 | ||
869 | /* Return the GDB type object for the "standard" data type of data in | |
c378eb4e | 870 | register REGNUM. */ |
8b39fe56 MK |
871 | |
872 | static struct type * | |
873 | sparc64_register_type (struct gdbarch *gdbarch, int regnum) | |
874 | { | |
3f7b46f2 IR |
875 | if (tdesc_has_registers (gdbarch_target_desc (gdbarch))) |
876 | return tdesc_register_type (gdbarch, regnum); | |
877 | ||
6707b003 | 878 | /* Raw registers. */ |
6707b003 | 879 | if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM) |
0dfff4cb | 880 | return builtin_type (gdbarch)->builtin_data_ptr; |
6707b003 | 881 | if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM) |
df4df182 | 882 | return builtin_type (gdbarch)->builtin_int64; |
6707b003 | 883 | if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM) |
0dfff4cb | 884 | return builtin_type (gdbarch)->builtin_float; |
6707b003 | 885 | if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM) |
0dfff4cb | 886 | return builtin_type (gdbarch)->builtin_double; |
6707b003 | 887 | if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM) |
0dfff4cb | 888 | return builtin_type (gdbarch)->builtin_func_ptr; |
6707b003 UW |
889 | /* This raw register contains the contents of %cwp, %pstate, %asi |
890 | and %ccr as laid out in a %tstate register. */ | |
891 | if (regnum == SPARC64_STATE_REGNUM) | |
df4df182 | 892 | return builtin_type (gdbarch)->builtin_int64; |
6707b003 | 893 | if (regnum == SPARC64_FSR_REGNUM) |
209bd28e | 894 | return sparc64_fsr_type (gdbarch); |
6707b003 | 895 | if (regnum == SPARC64_FPRS_REGNUM) |
209bd28e | 896 | return sparc64_fprs_type (gdbarch); |
6707b003 UW |
897 | /* "Although Y is a 64-bit register, its high-order 32 bits are |
898 | reserved and always read as 0." */ | |
899 | if (regnum == SPARC64_Y_REGNUM) | |
df4df182 | 900 | return builtin_type (gdbarch)->builtin_int64; |
6707b003 UW |
901 | |
902 | /* Pseudo registers. */ | |
7a36499a IR |
903 | if (regnum >= gdbarch_num_regs (gdbarch)) |
904 | return sparc64_pseudo_register_type (gdbarch, regnum); | |
6707b003 UW |
905 | |
906 | internal_error (__FILE__, __LINE__, _("invalid regnum")); | |
8b39fe56 MK |
907 | } |
908 | ||
05d1431c | 909 | static enum register_status |
8b39fe56 MK |
910 | sparc64_pseudo_register_read (struct gdbarch *gdbarch, |
911 | struct regcache *regcache, | |
e1613aba | 912 | int regnum, gdb_byte *buf) |
8b39fe56 | 913 | { |
e17a4113 | 914 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
05d1431c PA |
915 | enum register_status status; |
916 | ||
7a36499a | 917 | regnum -= gdbarch_num_regs (gdbarch); |
8b39fe56 MK |
918 | |
919 | if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM) | |
920 | { | |
921 | regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM); | |
05d1431c PA |
922 | status = regcache_raw_read (regcache, regnum, buf); |
923 | if (status == REG_VALID) | |
924 | status = regcache_raw_read (regcache, regnum + 1, buf + 4); | |
925 | return status; | |
8b39fe56 MK |
926 | } |
927 | else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM) | |
928 | { | |
929 | regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM); | |
05d1431c | 930 | return regcache_raw_read (regcache, regnum, buf); |
8b39fe56 MK |
931 | } |
932 | else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM) | |
933 | { | |
934 | regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM); | |
05d1431c PA |
935 | |
936 | status = regcache_raw_read (regcache, regnum, buf); | |
937 | if (status == REG_VALID) | |
938 | status = regcache_raw_read (regcache, regnum + 1, buf + 4); | |
939 | if (status == REG_VALID) | |
940 | status = regcache_raw_read (regcache, regnum + 2, buf + 8); | |
941 | if (status == REG_VALID) | |
942 | status = regcache_raw_read (regcache, regnum + 3, buf + 12); | |
943 | ||
944 | return status; | |
8b39fe56 MK |
945 | } |
946 | else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM) | |
947 | { | |
948 | regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM); | |
05d1431c PA |
949 | |
950 | status = regcache_raw_read (regcache, regnum, buf); | |
951 | if (status == REG_VALID) | |
952 | status = regcache_raw_read (regcache, regnum + 1, buf + 8); | |
953 | ||
954 | return status; | |
8b39fe56 MK |
955 | } |
956 | else if (regnum == SPARC64_CWP_REGNUM | |
957 | || regnum == SPARC64_PSTATE_REGNUM | |
958 | || regnum == SPARC64_ASI_REGNUM | |
959 | || regnum == SPARC64_CCR_REGNUM) | |
960 | { | |
961 | ULONGEST state; | |
962 | ||
05d1431c PA |
963 | status = regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state); |
964 | if (status != REG_VALID) | |
965 | return status; | |
966 | ||
8b39fe56 MK |
967 | switch (regnum) |
968 | { | |
3567a8ea | 969 | case SPARC64_CWP_REGNUM: |
8b39fe56 MK |
970 | state = (state >> 0) & ((1 << 5) - 1); |
971 | break; | |
3567a8ea | 972 | case SPARC64_PSTATE_REGNUM: |
8b39fe56 MK |
973 | state = (state >> 8) & ((1 << 12) - 1); |
974 | break; | |
3567a8ea | 975 | case SPARC64_ASI_REGNUM: |
8b39fe56 MK |
976 | state = (state >> 24) & ((1 << 8) - 1); |
977 | break; | |
3567a8ea | 978 | case SPARC64_CCR_REGNUM: |
8b39fe56 MK |
979 | state = (state >> 32) & ((1 << 8) - 1); |
980 | break; | |
981 | } | |
e17a4113 | 982 | store_unsigned_integer (buf, 8, byte_order, state); |
8b39fe56 | 983 | } |
05d1431c PA |
984 | |
985 | return REG_VALID; | |
8b39fe56 MK |
986 | } |
987 | ||
988 | static void | |
989 | sparc64_pseudo_register_write (struct gdbarch *gdbarch, | |
990 | struct regcache *regcache, | |
e1613aba | 991 | int regnum, const gdb_byte *buf) |
8b39fe56 | 992 | { |
e17a4113 | 993 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
7a36499a IR |
994 | |
995 | regnum -= gdbarch_num_regs (gdbarch); | |
8b39fe56 MK |
996 | |
997 | if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM) | |
998 | { | |
999 | regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM); | |
1000 | regcache_raw_write (regcache, regnum, buf); | |
e1613aba | 1001 | regcache_raw_write (regcache, regnum + 1, buf + 4); |
8b39fe56 MK |
1002 | } |
1003 | else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM) | |
1004 | { | |
1005 | regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM); | |
1006 | regcache_raw_write (regcache, regnum, buf); | |
1007 | } | |
1008 | else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM) | |
1009 | { | |
1010 | regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM); | |
1011 | regcache_raw_write (regcache, regnum, buf); | |
e1613aba MK |
1012 | regcache_raw_write (regcache, regnum + 1, buf + 4); |
1013 | regcache_raw_write (regcache, regnum + 2, buf + 8); | |
1014 | regcache_raw_write (regcache, regnum + 3, buf + 12); | |
8b39fe56 MK |
1015 | } |
1016 | else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM) | |
1017 | { | |
1018 | regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM); | |
1019 | regcache_raw_write (regcache, regnum, buf); | |
e1613aba | 1020 | regcache_raw_write (regcache, regnum + 1, buf + 8); |
8b39fe56 | 1021 | } |
3567a8ea MK |
1022 | else if (regnum == SPARC64_CWP_REGNUM |
1023 | || regnum == SPARC64_PSTATE_REGNUM | |
1024 | || regnum == SPARC64_ASI_REGNUM | |
1025 | || regnum == SPARC64_CCR_REGNUM) | |
1026 | { | |
1027 | ULONGEST state, bits; | |
1028 | ||
1029 | regcache_raw_read_unsigned (regcache, SPARC64_STATE_REGNUM, &state); | |
e17a4113 | 1030 | bits = extract_unsigned_integer (buf, 8, byte_order); |
3567a8ea MK |
1031 | switch (regnum) |
1032 | { | |
1033 | case SPARC64_CWP_REGNUM: | |
1034 | state |= ((bits & ((1 << 5) - 1)) << 0); | |
1035 | break; | |
1036 | case SPARC64_PSTATE_REGNUM: | |
1037 | state |= ((bits & ((1 << 12) - 1)) << 8); | |
1038 | break; | |
1039 | case SPARC64_ASI_REGNUM: | |
1040 | state |= ((bits & ((1 << 8) - 1)) << 24); | |
1041 | break; | |
1042 | case SPARC64_CCR_REGNUM: | |
1043 | state |= ((bits & ((1 << 8) - 1)) << 32); | |
1044 | break; | |
1045 | } | |
1046 | regcache_raw_write_unsigned (regcache, SPARC64_STATE_REGNUM, state); | |
1047 | } | |
8b39fe56 | 1048 | } |
8b39fe56 MK |
1049 | \f |
1050 | ||
8b39fe56 MK |
1051 | /* Return PC of first real instruction of the function starting at |
1052 | START_PC. */ | |
1053 | ||
1054 | static CORE_ADDR | |
6093d2eb | 1055 | sparc64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc) |
8b39fe56 MK |
1056 | { |
1057 | struct symtab_and_line sal; | |
1058 | CORE_ADDR func_start, func_end; | |
386c036b | 1059 | struct sparc_frame_cache cache; |
8b39fe56 MK |
1060 | |
1061 | /* This is the preferred method, find the end of the prologue by | |
1062 | using the debugging information. */ | |
1063 | if (find_pc_partial_function (start_pc, NULL, &func_start, &func_end)) | |
1064 | { | |
1065 | sal = find_pc_line (func_start, 0); | |
1066 | ||
1067 | if (sal.end < func_end | |
1068 | && start_pc <= sal.end) | |
1069 | return sal.end; | |
1070 | } | |
1071 | ||
be8626e0 MD |
1072 | return sparc_analyze_prologue (gdbarch, start_pc, 0xffffffffffffffffULL, |
1073 | &cache); | |
8b39fe56 MK |
1074 | } |
1075 | ||
1076 | /* Normal frames. */ | |
1077 | ||
386c036b | 1078 | static struct sparc_frame_cache * |
236369e7 | 1079 | sparc64_frame_cache (struct frame_info *this_frame, void **this_cache) |
8b39fe56 | 1080 | { |
236369e7 | 1081 | return sparc_frame_cache (this_frame, this_cache); |
8b39fe56 MK |
1082 | } |
1083 | ||
1084 | static void | |
236369e7 | 1085 | sparc64_frame_this_id (struct frame_info *this_frame, void **this_cache, |
8b39fe56 MK |
1086 | struct frame_id *this_id) |
1087 | { | |
386c036b | 1088 | struct sparc_frame_cache *cache = |
236369e7 | 1089 | sparc64_frame_cache (this_frame, this_cache); |
8b39fe56 MK |
1090 | |
1091 | /* This marks the outermost frame. */ | |
1092 | if (cache->base == 0) | |
1093 | return; | |
1094 | ||
1095 | (*this_id) = frame_id_build (cache->base, cache->pc); | |
1096 | } | |
1097 | ||
236369e7 JB |
1098 | static struct value * |
1099 | sparc64_frame_prev_register (struct frame_info *this_frame, void **this_cache, | |
1100 | int regnum) | |
8b39fe56 | 1101 | { |
e17a4113 | 1102 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
386c036b | 1103 | struct sparc_frame_cache *cache = |
236369e7 | 1104 | sparc64_frame_cache (this_frame, this_cache); |
8b39fe56 MK |
1105 | |
1106 | if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM) | |
1107 | { | |
236369e7 | 1108 | CORE_ADDR pc = (regnum == SPARC64_NPC_REGNUM) ? 4 : 0; |
8b39fe56 | 1109 | |
369c397b JB |
1110 | regnum = |
1111 | (cache->copied_regs_mask & 0x80) ? SPARC_I7_REGNUM : SPARC_O7_REGNUM; | |
236369e7 JB |
1112 | pc += get_frame_register_unsigned (this_frame, regnum) + 8; |
1113 | return frame_unwind_got_constant (this_frame, regnum, pc); | |
8b39fe56 MK |
1114 | } |
1115 | ||
f700a364 MK |
1116 | /* Handle StackGhost. */ |
1117 | { | |
e17a4113 | 1118 | ULONGEST wcookie = sparc_fetch_wcookie (gdbarch); |
f700a364 MK |
1119 | |
1120 | if (wcookie != 0 && !cache->frameless_p && regnum == SPARC_I7_REGNUM) | |
1121 | { | |
236369e7 JB |
1122 | CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8; |
1123 | ULONGEST i7; | |
1124 | ||
1125 | /* Read the value in from memory. */ | |
1126 | i7 = get_frame_memory_unsigned (this_frame, addr, 8); | |
1127 | return frame_unwind_got_constant (this_frame, regnum, i7 ^ wcookie); | |
f700a364 MK |
1128 | } |
1129 | } | |
1130 | ||
369c397b | 1131 | /* The previous frame's `local' and `in' registers may have been saved |
8b39fe56 | 1132 | in the register save area. */ |
369c397b JB |
1133 | if (regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM |
1134 | && (cache->saved_regs_mask & (1 << (regnum - SPARC_L0_REGNUM)))) | |
8b39fe56 | 1135 | { |
236369e7 | 1136 | CORE_ADDR addr = cache->base + (regnum - SPARC_L0_REGNUM) * 8; |
8b39fe56 | 1137 | |
236369e7 | 1138 | return frame_unwind_got_memory (this_frame, regnum, addr); |
8b39fe56 MK |
1139 | } |
1140 | ||
369c397b JB |
1141 | /* The previous frame's `out' registers may be accessible as the current |
1142 | frame's `in' registers. */ | |
1143 | if (regnum >= SPARC_O0_REGNUM && regnum <= SPARC_O7_REGNUM | |
1144 | && (cache->copied_regs_mask & (1 << (regnum - SPARC_O0_REGNUM)))) | |
8b39fe56 MK |
1145 | regnum += (SPARC_I0_REGNUM - SPARC_O0_REGNUM); |
1146 | ||
236369e7 | 1147 | return frame_unwind_got_register (this_frame, regnum, regnum); |
8b39fe56 MK |
1148 | } |
1149 | ||
1150 | static const struct frame_unwind sparc64_frame_unwind = | |
1151 | { | |
1152 | NORMAL_FRAME, | |
8fbca658 | 1153 | default_frame_unwind_stop_reason, |
8b39fe56 | 1154 | sparc64_frame_this_id, |
236369e7 JB |
1155 | sparc64_frame_prev_register, |
1156 | NULL, | |
1157 | default_frame_sniffer | |
8b39fe56 | 1158 | }; |
8b39fe56 MK |
1159 | \f |
1160 | ||
1161 | static CORE_ADDR | |
236369e7 | 1162 | sparc64_frame_base_address (struct frame_info *this_frame, void **this_cache) |
8b39fe56 | 1163 | { |
386c036b | 1164 | struct sparc_frame_cache *cache = |
236369e7 | 1165 | sparc64_frame_cache (this_frame, this_cache); |
8b39fe56 | 1166 | |
5b2d44a0 | 1167 | return cache->base; |
8b39fe56 MK |
1168 | } |
1169 | ||
1170 | static const struct frame_base sparc64_frame_base = | |
1171 | { | |
1172 | &sparc64_frame_unwind, | |
1173 | sparc64_frame_base_address, | |
1174 | sparc64_frame_base_address, | |
1175 | sparc64_frame_base_address | |
1176 | }; | |
8b39fe56 MK |
1177 | \f |
1178 | /* Check whether TYPE must be 16-byte aligned. */ | |
1179 | ||
1180 | static int | |
1181 | sparc64_16_byte_align_p (struct type *type) | |
1182 | { | |
1933fd8e VM |
1183 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) |
1184 | { | |
1185 | struct type *t = check_typedef (TYPE_TARGET_TYPE (type)); | |
1186 | ||
1187 | if (sparc64_floating_p (t)) | |
1188 | return 1; | |
1189 | } | |
8b39fe56 MK |
1190 | if (sparc64_floating_p (type) && TYPE_LENGTH (type) == 16) |
1191 | return 1; | |
1192 | ||
1193 | if (sparc64_structure_or_union_p (type)) | |
1194 | { | |
1195 | int i; | |
1196 | ||
1197 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
60af1db2 MK |
1198 | { |
1199 | struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
1200 | ||
1201 | if (sparc64_16_byte_align_p (subtype)) | |
1202 | return 1; | |
1203 | } | |
8b39fe56 MK |
1204 | } |
1205 | ||
1206 | return 0; | |
1207 | } | |
1208 | ||
1209 | /* Store floating fields of element ELEMENT of an "parameter array" | |
1210 | that has type TYPE and is stored at BITPOS in VALBUF in the | |
1211 | apropriate registers of REGCACHE. This function can be called | |
1212 | recursively and therefore handles floating types in addition to | |
1213 | structures. */ | |
1214 | ||
1215 | static void | |
1216 | sparc64_store_floating_fields (struct regcache *regcache, struct type *type, | |
e1613aba | 1217 | const gdb_byte *valbuf, int element, int bitpos) |
8b39fe56 | 1218 | { |
7a36499a | 1219 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
fe10a582 DM |
1220 | int len = TYPE_LENGTH (type); |
1221 | ||
8b39fe56 MK |
1222 | gdb_assert (element < 16); |
1223 | ||
1933fd8e VM |
1224 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) |
1225 | { | |
1226 | gdb_byte buf[8]; | |
1227 | int regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32; | |
1228 | ||
1229 | valbuf += bitpos / 8; | |
1230 | if (len < 8) | |
1231 | { | |
1232 | memset (buf, 0, 8 - len); | |
1233 | memcpy (buf + 8 - len, valbuf, len); | |
1234 | valbuf = buf; | |
1235 | len = 8; | |
1236 | } | |
1237 | for (int n = 0; n < (len + 3) / 4; n++) | |
1238 | regcache_cooked_write (regcache, regnum + n, valbuf + n * 4); | |
1239 | } | |
1240 | else if (sparc64_floating_p (type) | |
fe10a582 | 1241 | || (sparc64_complex_floating_p (type) && len <= 16)) |
8b39fe56 | 1242 | { |
8b39fe56 MK |
1243 | int regnum; |
1244 | ||
1245 | if (len == 16) | |
1246 | { | |
1247 | gdb_assert (bitpos == 0); | |
1248 | gdb_assert ((element % 2) == 0); | |
1249 | ||
7a36499a | 1250 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM + element / 2; |
8b39fe56 MK |
1251 | regcache_cooked_write (regcache, regnum, valbuf); |
1252 | } | |
1253 | else if (len == 8) | |
1254 | { | |
1255 | gdb_assert (bitpos == 0 || bitpos == 64); | |
1256 | ||
7a36499a IR |
1257 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM |
1258 | + element + bitpos / 64; | |
8b39fe56 MK |
1259 | regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8)); |
1260 | } | |
1261 | else | |
1262 | { | |
1263 | gdb_assert (len == 4); | |
1264 | gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 128); | |
1265 | ||
1266 | regnum = SPARC_F0_REGNUM + element * 2 + bitpos / 32; | |
1267 | regcache_cooked_write (regcache, regnum, valbuf + (bitpos / 8)); | |
1268 | } | |
1269 | } | |
1270 | else if (sparc64_structure_or_union_p (type)) | |
1271 | { | |
1272 | int i; | |
1273 | ||
1274 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
60af1db2 MK |
1275 | { |
1276 | struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
1277 | int subpos = bitpos + TYPE_FIELD_BITPOS (type, i); | |
1278 | ||
1279 | sparc64_store_floating_fields (regcache, subtype, valbuf, | |
1280 | element, subpos); | |
1281 | } | |
200cc553 MK |
1282 | |
1283 | /* GCC has an interesting bug. If TYPE is a structure that has | |
1284 | a single `float' member, GCC doesn't treat it as a structure | |
1285 | at all, but rather as an ordinary `float' argument. This | |
1286 | argument will be stored in %f1, as required by the psABI. | |
1287 | However, as a member of a structure the psABI requires it to | |
5154b0cd MK |
1288 | be stored in %f0. This bug is present in GCC 3.3.2, but |
1289 | probably in older releases to. To appease GCC, if a | |
1290 | structure has only a single `float' member, we store its | |
1291 | value in %f1 too (we already have stored in %f0). */ | |
200cc553 MK |
1292 | if (TYPE_NFIELDS (type) == 1) |
1293 | { | |
1294 | struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, 0)); | |
1295 | ||
1296 | if (sparc64_floating_p (subtype) && TYPE_LENGTH (subtype) == 4) | |
1297 | regcache_cooked_write (regcache, SPARC_F1_REGNUM, valbuf); | |
1298 | } | |
8b39fe56 MK |
1299 | } |
1300 | } | |
1301 | ||
1302 | /* Fetch floating fields from a variable of type TYPE from the | |
1303 | appropriate registers for BITPOS in REGCACHE and store it at BITPOS | |
1304 | in VALBUF. This function can be called recursively and therefore | |
1305 | handles floating types in addition to structures. */ | |
1306 | ||
1307 | static void | |
1308 | sparc64_extract_floating_fields (struct regcache *regcache, struct type *type, | |
e1613aba | 1309 | gdb_byte *valbuf, int bitpos) |
8b39fe56 | 1310 | { |
7a36499a IR |
1311 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1312 | ||
1933fd8e VM |
1313 | if (TYPE_CODE (type) == TYPE_CODE_ARRAY) |
1314 | { | |
1315 | int len = TYPE_LENGTH (type); | |
1316 | int regnum = SPARC_F0_REGNUM + bitpos / 32; | |
1317 | ||
1318 | valbuf += bitpos / 8; | |
1319 | if (len < 4) | |
1320 | { | |
1321 | gdb_byte buf[4]; | |
1322 | regcache_cooked_read (regcache, regnum, buf); | |
1323 | memcpy (valbuf, buf + 4 - len, len); | |
1324 | } | |
1325 | else | |
1326 | for (int i = 0; i < (len + 3) / 4; i++) | |
1327 | regcache_cooked_read (regcache, regnum + i, valbuf + i * 4); | |
1328 | } | |
1329 | else if (sparc64_floating_p (type)) | |
8b39fe56 MK |
1330 | { |
1331 | int len = TYPE_LENGTH (type); | |
1332 | int regnum; | |
1333 | ||
1334 | if (len == 16) | |
1335 | { | |
1336 | gdb_assert (bitpos == 0 || bitpos == 128); | |
1337 | ||
7a36499a IR |
1338 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM |
1339 | + bitpos / 128; | |
8b39fe56 MK |
1340 | regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); |
1341 | } | |
1342 | else if (len == 8) | |
1343 | { | |
1344 | gdb_assert (bitpos % 64 == 0 && bitpos >= 0 && bitpos < 256); | |
1345 | ||
7a36499a | 1346 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + bitpos / 64; |
8b39fe56 MK |
1347 | regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); |
1348 | } | |
1349 | else | |
1350 | { | |
1351 | gdb_assert (len == 4); | |
1352 | gdb_assert (bitpos % 32 == 0 && bitpos >= 0 && bitpos < 256); | |
1353 | ||
1354 | regnum = SPARC_F0_REGNUM + bitpos / 32; | |
1355 | regcache_cooked_read (regcache, regnum, valbuf + (bitpos / 8)); | |
1356 | } | |
1357 | } | |
1358 | else if (sparc64_structure_or_union_p (type)) | |
1359 | { | |
1360 | int i; | |
1361 | ||
1362 | for (i = 0; i < TYPE_NFIELDS (type); i++) | |
60af1db2 MK |
1363 | { |
1364 | struct type *subtype = check_typedef (TYPE_FIELD_TYPE (type, i)); | |
1365 | int subpos = bitpos + TYPE_FIELD_BITPOS (type, i); | |
1366 | ||
1367 | sparc64_extract_floating_fields (regcache, subtype, valbuf, subpos); | |
1368 | } | |
8b39fe56 MK |
1369 | } |
1370 | } | |
1371 | ||
1372 | /* Store the NARGS arguments ARGS and STRUCT_ADDR (if STRUCT_RETURN is | |
1373 | non-zero) in REGCACHE and on the stack (starting from address SP). */ | |
1374 | ||
1375 | static CORE_ADDR | |
1376 | sparc64_store_arguments (struct regcache *regcache, int nargs, | |
1377 | struct value **args, CORE_ADDR sp, | |
1378 | int struct_return, CORE_ADDR struct_addr) | |
1379 | { | |
df4df182 | 1380 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
8b39fe56 MK |
1381 | /* Number of extended words in the "parameter array". */ |
1382 | int num_elements = 0; | |
1383 | int element = 0; | |
1384 | int i; | |
1385 | ||
1386 | /* Take BIAS into account. */ | |
1387 | sp += BIAS; | |
1388 | ||
1389 | /* First we calculate the number of extended words in the "parameter | |
1390 | array". While doing so we also convert some of the arguments. */ | |
1391 | ||
1392 | if (struct_return) | |
1393 | num_elements++; | |
1394 | ||
1395 | for (i = 0; i < nargs; i++) | |
1396 | { | |
4991999e | 1397 | struct type *type = value_type (args[i]); |
8b39fe56 MK |
1398 | int len = TYPE_LENGTH (type); |
1399 | ||
fb57d452 MK |
1400 | if (sparc64_structure_or_union_p (type) |
1401 | || (sparc64_complex_floating_p (type) && len == 32)) | |
8b39fe56 MK |
1402 | { |
1403 | /* Structure or Union arguments. */ | |
1404 | if (len <= 16) | |
1405 | { | |
1406 | if (num_elements % 2 && sparc64_16_byte_align_p (type)) | |
1407 | num_elements++; | |
1408 | num_elements += ((len + 7) / 8); | |
1409 | } | |
1410 | else | |
1411 | { | |
1412 | /* The psABI says that "Structures or unions larger than | |
1413 | sixteen bytes are copied by the caller and passed | |
1414 | indirectly; the caller will pass the address of a | |
1415 | correctly aligned structure value. This sixty-four | |
1416 | bit address will occupy one word in the parameter | |
1417 | array, and may be promoted to an %o register like any | |
1418 | other pointer value." Allocate memory for these | |
1419 | values on the stack. */ | |
1420 | sp -= len; | |
1421 | ||
1422 | /* Use 16-byte alignment for these values. That's | |
1423 | always correct, and wasting a few bytes shouldn't be | |
1424 | a problem. */ | |
1425 | sp &= ~0xf; | |
1426 | ||
0fd88904 | 1427 | write_memory (sp, value_contents (args[i]), len); |
8b39fe56 MK |
1428 | args[i] = value_from_pointer (lookup_pointer_type (type), sp); |
1429 | num_elements++; | |
1430 | } | |
1431 | } | |
cdc7b32f | 1432 | else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) |
8b39fe56 MK |
1433 | { |
1434 | /* Floating arguments. */ | |
8b39fe56 MK |
1435 | if (len == 16) |
1436 | { | |
1437 | /* The psABI says that "Each quad-precision parameter | |
1438 | value will be assigned to two extended words in the | |
1439 | parameter array. */ | |
1440 | num_elements += 2; | |
1441 | ||
1442 | /* The psABI says that "Long doubles must be | |
1443 | quad-aligned, and thus a hole might be introduced | |
1444 | into the parameter array to force alignment." Skip | |
1445 | an element if necessary. */ | |
49caec94 | 1446 | if ((num_elements % 2) && sparc64_16_byte_align_p (type)) |
8b39fe56 MK |
1447 | num_elements++; |
1448 | } | |
1449 | else | |
1450 | num_elements++; | |
1451 | } | |
1452 | else | |
1453 | { | |
1454 | /* Integral and pointer arguments. */ | |
1455 | gdb_assert (sparc64_integral_or_pointer_p (type)); | |
1456 | ||
1457 | /* The psABI says that "Each argument value of integral type | |
1458 | smaller than an extended word will be widened by the | |
1459 | caller to an extended word according to the signed-ness | |
1460 | of the argument type." */ | |
1461 | if (len < 8) | |
df4df182 UW |
1462 | args[i] = value_cast (builtin_type (gdbarch)->builtin_int64, |
1463 | args[i]); | |
8b39fe56 MK |
1464 | num_elements++; |
1465 | } | |
1466 | } | |
1467 | ||
1468 | /* Allocate the "parameter array". */ | |
1469 | sp -= num_elements * 8; | |
1470 | ||
1471 | /* The psABI says that "Every stack frame must be 16-byte aligned." */ | |
1472 | sp &= ~0xf; | |
1473 | ||
1474 | /* Now we store the arguments in to the "paramater array". Some | |
1475 | Integer or Pointer arguments and Structure or Union arguments | |
1476 | will be passed in %o registers. Some Floating arguments and | |
1477 | floating members of structures are passed in floating-point | |
1478 | registers. However, for functions with variable arguments, | |
1479 | floating arguments are stored in an %0 register, and for | |
1480 | functions without a prototype floating arguments are stored in | |
1481 | both a floating-point and an %o registers, or a floating-point | |
1482 | register and memory. To simplify the logic here we always pass | |
1483 | arguments in memory, an %o register, and a floating-point | |
1484 | register if appropriate. This should be no problem since the | |
1485 | contents of any unused memory or registers in the "parameter | |
1486 | array" are undefined. */ | |
1487 | ||
1488 | if (struct_return) | |
1489 | { | |
1490 | regcache_cooked_write_unsigned (regcache, SPARC_O0_REGNUM, struct_addr); | |
1491 | element++; | |
1492 | } | |
1493 | ||
1494 | for (i = 0; i < nargs; i++) | |
1495 | { | |
e1613aba | 1496 | const gdb_byte *valbuf = value_contents (args[i]); |
4991999e | 1497 | struct type *type = value_type (args[i]); |
8b39fe56 MK |
1498 | int len = TYPE_LENGTH (type); |
1499 | int regnum = -1; | |
e1613aba | 1500 | gdb_byte buf[16]; |
8b39fe56 | 1501 | |
fb57d452 MK |
1502 | if (sparc64_structure_or_union_p (type) |
1503 | || (sparc64_complex_floating_p (type) && len == 32)) | |
8b39fe56 | 1504 | { |
49caec94 | 1505 | /* Structure, Union or long double Complex arguments. */ |
8b39fe56 MK |
1506 | gdb_assert (len <= 16); |
1507 | memset (buf, 0, sizeof (buf)); | |
cfcb22a5 SM |
1508 | memcpy (buf, valbuf, len); |
1509 | valbuf = buf; | |
8b39fe56 MK |
1510 | |
1511 | if (element % 2 && sparc64_16_byte_align_p (type)) | |
1512 | element++; | |
1513 | ||
1514 | if (element < 6) | |
1515 | { | |
1516 | regnum = SPARC_O0_REGNUM + element; | |
1517 | if (len > 8 && element < 5) | |
1518 | regcache_cooked_write (regcache, regnum + 1, valbuf + 8); | |
1519 | } | |
1520 | ||
1521 | if (element < 16) | |
1522 | sparc64_store_floating_fields (regcache, type, valbuf, element, 0); | |
1523 | } | |
49caec94 JM |
1524 | else if (sparc64_complex_floating_p (type)) |
1525 | { | |
1526 | /* Float Complex or double Complex arguments. */ | |
1527 | if (element < 16) | |
1528 | { | |
7a36499a | 1529 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM + element; |
49caec94 JM |
1530 | |
1531 | if (len == 16) | |
1532 | { | |
7a36499a | 1533 | if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D30_REGNUM) |
49caec94 | 1534 | regcache_cooked_write (regcache, regnum + 1, valbuf + 8); |
7a36499a | 1535 | if (regnum < gdbarch_num_regs (gdbarch) + SPARC64_D10_REGNUM) |
49caec94 JM |
1536 | regcache_cooked_write (regcache, |
1537 | SPARC_O0_REGNUM + element + 1, | |
1538 | valbuf + 8); | |
1539 | } | |
1540 | } | |
1541 | } | |
1542 | else if (sparc64_floating_p (type)) | |
8b39fe56 MK |
1543 | { |
1544 | /* Floating arguments. */ | |
1545 | if (len == 16) | |
1546 | { | |
1547 | if (element % 2) | |
1548 | element++; | |
1549 | if (element < 16) | |
7a36499a IR |
1550 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_Q0_REGNUM |
1551 | + element / 2; | |
8b39fe56 MK |
1552 | } |
1553 | else if (len == 8) | |
1554 | { | |
1555 | if (element < 16) | |
7a36499a IR |
1556 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM |
1557 | + element; | |
8b39fe56 | 1558 | } |
fe10a582 | 1559 | else if (len == 4) |
8b39fe56 MK |
1560 | { |
1561 | /* The psABI says "Each single-precision parameter value | |
1562 | will be assigned to one extended word in the | |
1563 | parameter array, and right-justified within that | |
cdc7b32f | 1564 | word; the left half (even float register) is |
8b39fe56 MK |
1565 | undefined." Even though the psABI says that "the |
1566 | left half is undefined", set it to zero here. */ | |
1567 | memset (buf, 0, 4); | |
8ada74e3 MK |
1568 | memcpy (buf + 4, valbuf, 4); |
1569 | valbuf = buf; | |
8b39fe56 MK |
1570 | len = 8; |
1571 | if (element < 16) | |
7a36499a IR |
1572 | regnum = gdbarch_num_regs (gdbarch) + SPARC64_D0_REGNUM |
1573 | + element; | |
8b39fe56 MK |
1574 | } |
1575 | } | |
1576 | else | |
1577 | { | |
1578 | /* Integral and pointer arguments. */ | |
1579 | gdb_assert (len == 8); | |
1580 | if (element < 6) | |
1581 | regnum = SPARC_O0_REGNUM + element; | |
1582 | } | |
1583 | ||
1584 | if (regnum != -1) | |
1585 | { | |
1586 | regcache_cooked_write (regcache, regnum, valbuf); | |
1587 | ||
1588 | /* If we're storing the value in a floating-point register, | |
1589 | also store it in the corresponding %0 register(s). */ | |
7a36499a IR |
1590 | if (regnum >= gdbarch_num_regs (gdbarch)) |
1591 | { | |
1592 | regnum -= gdbarch_num_regs (gdbarch); | |
1593 | ||
1594 | if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D10_REGNUM) | |
1595 | { | |
1596 | gdb_assert (element < 6); | |
1597 | regnum = SPARC_O0_REGNUM + element; | |
1598 | regcache_cooked_write (regcache, regnum, valbuf); | |
1599 | } | |
1600 | else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q8_REGNUM) | |
1601 | { | |
1602 | gdb_assert (element < 5); | |
1603 | regnum = SPARC_O0_REGNUM + element; | |
1604 | regcache_cooked_write (regcache, regnum, valbuf); | |
1605 | regcache_cooked_write (regcache, regnum + 1, valbuf + 8); | |
1606 | } | |
1607 | } | |
8b39fe56 MK |
1608 | } |
1609 | ||
c4f2d4d7 | 1610 | /* Always store the argument in memory. */ |
8b39fe56 MK |
1611 | write_memory (sp + element * 8, valbuf, len); |
1612 | element += ((len + 7) / 8); | |
1613 | } | |
1614 | ||
1615 | gdb_assert (element == num_elements); | |
1616 | ||
1617 | /* Take BIAS into account. */ | |
1618 | sp -= BIAS; | |
1619 | return sp; | |
1620 | } | |
1621 | ||
49a45ecf JB |
1622 | static CORE_ADDR |
1623 | sparc64_frame_align (struct gdbarch *gdbarch, CORE_ADDR address) | |
1624 | { | |
1625 | /* The ABI requires 16-byte alignment. */ | |
1626 | return address & ~0xf; | |
1627 | } | |
1628 | ||
8b39fe56 | 1629 | static CORE_ADDR |
7d9b040b | 1630 | sparc64_push_dummy_call (struct gdbarch *gdbarch, struct value *function, |
8b39fe56 MK |
1631 | struct regcache *regcache, CORE_ADDR bp_addr, |
1632 | int nargs, struct value **args, CORE_ADDR sp, | |
1633 | int struct_return, CORE_ADDR struct_addr) | |
1634 | { | |
1635 | /* Set return address. */ | |
1636 | regcache_cooked_write_unsigned (regcache, SPARC_O7_REGNUM, bp_addr - 8); | |
1637 | ||
1638 | /* Set up function arguments. */ | |
1639 | sp = sparc64_store_arguments (regcache, nargs, args, sp, | |
1640 | struct_return, struct_addr); | |
1641 | ||
1642 | /* Allocate the register save area. */ | |
1643 | sp -= 16 * 8; | |
1644 | ||
1645 | /* Stack should be 16-byte aligned at this point. */ | |
3567a8ea | 1646 | gdb_assert ((sp + BIAS) % 16 == 0); |
8b39fe56 MK |
1647 | |
1648 | /* Finally, update the stack pointer. */ | |
1649 | regcache_cooked_write_unsigned (regcache, SPARC_SP_REGNUM, sp); | |
1650 | ||
5b2d44a0 | 1651 | return sp + BIAS; |
8b39fe56 MK |
1652 | } |
1653 | \f | |
1654 | ||
1655 | /* Extract from an array REGBUF containing the (raw) register state, a | |
1656 | function return value of TYPE, and copy that into VALBUF. */ | |
1657 | ||
1658 | static void | |
1659 | sparc64_extract_return_value (struct type *type, struct regcache *regcache, | |
e1613aba | 1660 | gdb_byte *valbuf) |
8b39fe56 MK |
1661 | { |
1662 | int len = TYPE_LENGTH (type); | |
e1613aba | 1663 | gdb_byte buf[32]; |
8b39fe56 MK |
1664 | int i; |
1665 | ||
1666 | if (sparc64_structure_or_union_p (type)) | |
1667 | { | |
1668 | /* Structure or Union return values. */ | |
1669 | gdb_assert (len <= 32); | |
1670 | ||
1671 | for (i = 0; i < ((len + 7) / 8); i++) | |
1672 | regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8); | |
1673 | if (TYPE_CODE (type) != TYPE_CODE_UNION) | |
1674 | sparc64_extract_floating_fields (regcache, type, buf, 0); | |
1675 | memcpy (valbuf, buf, len); | |
1676 | } | |
cdc7b32f | 1677 | else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) |
8b39fe56 MK |
1678 | { |
1679 | /* Floating return values. */ | |
1680 | for (i = 0; i < len / 4; i++) | |
1681 | regcache_cooked_read (regcache, SPARC_F0_REGNUM + i, buf + i * 4); | |
1682 | memcpy (valbuf, buf, len); | |
1683 | } | |
4bd87714 JB |
1684 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) |
1685 | { | |
1686 | /* Small arrays are returned the same way as small structures. */ | |
1687 | gdb_assert (len <= 32); | |
1688 | ||
1689 | for (i = 0; i < ((len + 7) / 8); i++) | |
1690 | regcache_cooked_read (regcache, SPARC_O0_REGNUM + i, buf + i * 8); | |
1691 | memcpy (valbuf, buf, len); | |
1692 | } | |
8b39fe56 MK |
1693 | else |
1694 | { | |
1695 | /* Integral and pointer return values. */ | |
1696 | gdb_assert (sparc64_integral_or_pointer_p (type)); | |
1697 | ||
1698 | /* Just stripping off any unused bytes should preserve the | |
1699 | signed-ness just fine. */ | |
1700 | regcache_cooked_read (regcache, SPARC_O0_REGNUM, buf); | |
1701 | memcpy (valbuf, buf + 8 - len, len); | |
1702 | } | |
1703 | } | |
1704 | ||
1705 | /* Write into the appropriate registers a function return value stored | |
1706 | in VALBUF of type TYPE. */ | |
1707 | ||
1708 | static void | |
1709 | sparc64_store_return_value (struct type *type, struct regcache *regcache, | |
e1613aba | 1710 | const gdb_byte *valbuf) |
8b39fe56 MK |
1711 | { |
1712 | int len = TYPE_LENGTH (type); | |
e1613aba | 1713 | gdb_byte buf[16]; |
8b39fe56 MK |
1714 | int i; |
1715 | ||
1716 | if (sparc64_structure_or_union_p (type)) | |
1717 | { | |
1718 | /* Structure or Union return values. */ | |
1719 | gdb_assert (len <= 32); | |
1720 | ||
1721 | /* Simplify matters by storing the complete value (including | |
1722 | floating members) into %o0 and %o1. Floating members are | |
1723 | also store in the appropriate floating-point registers. */ | |
1724 | memset (buf, 0, sizeof (buf)); | |
1725 | memcpy (buf, valbuf, len); | |
1726 | for (i = 0; i < ((len + 7) / 8); i++) | |
60af1db2 | 1727 | regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8); |
8b39fe56 MK |
1728 | if (TYPE_CODE (type) != TYPE_CODE_UNION) |
1729 | sparc64_store_floating_fields (regcache, type, buf, 0, 0); | |
1730 | } | |
fe10a582 | 1731 | else if (sparc64_floating_p (type) || sparc64_complex_floating_p (type)) |
8b39fe56 MK |
1732 | { |
1733 | /* Floating return values. */ | |
1734 | memcpy (buf, valbuf, len); | |
1735 | for (i = 0; i < len / 4; i++) | |
1736 | regcache_cooked_write (regcache, SPARC_F0_REGNUM + i, buf + i * 4); | |
1737 | } | |
4bd87714 JB |
1738 | else if (TYPE_CODE (type) == TYPE_CODE_ARRAY) |
1739 | { | |
1740 | /* Small arrays are returned the same way as small structures. */ | |
1741 | gdb_assert (len <= 32); | |
1742 | ||
1743 | memset (buf, 0, sizeof (buf)); | |
1744 | memcpy (buf, valbuf, len); | |
1745 | for (i = 0; i < ((len + 7) / 8); i++) | |
1746 | regcache_cooked_write (regcache, SPARC_O0_REGNUM + i, buf + i * 8); | |
1747 | } | |
8b39fe56 MK |
1748 | else |
1749 | { | |
1750 | /* Integral and pointer return values. */ | |
1751 | gdb_assert (sparc64_integral_or_pointer_p (type)); | |
1752 | ||
1753 | /* ??? Do we need to do any sign-extension here? */ | |
1754 | memset (buf, 0, 8); | |
1755 | memcpy (buf + 8 - len, valbuf, len); | |
1756 | regcache_cooked_write (regcache, SPARC_O0_REGNUM, buf); | |
1757 | } | |
1758 | } | |
1759 | ||
60af1db2 | 1760 | static enum return_value_convention |
6a3a010b | 1761 | sparc64_return_value (struct gdbarch *gdbarch, struct value *function, |
c055b101 CV |
1762 | struct type *type, struct regcache *regcache, |
1763 | gdb_byte *readbuf, const gdb_byte *writebuf) | |
8b39fe56 | 1764 | { |
60af1db2 MK |
1765 | if (TYPE_LENGTH (type) > 32) |
1766 | return RETURN_VALUE_STRUCT_CONVENTION; | |
1767 | ||
1768 | if (readbuf) | |
1769 | sparc64_extract_return_value (type, regcache, readbuf); | |
1770 | if (writebuf) | |
1771 | sparc64_store_return_value (type, regcache, writebuf); | |
1772 | ||
1773 | return RETURN_VALUE_REGISTER_CONVENTION; | |
8b39fe56 | 1774 | } |
8b39fe56 | 1775 | \f |
8b39fe56 | 1776 | |
02a71ae8 MK |
1777 | static void |
1778 | sparc64_dwarf2_frame_init_reg (struct gdbarch *gdbarch, int regnum, | |
aff37fc1 | 1779 | struct dwarf2_frame_state_reg *reg, |
4a4e5149 | 1780 | struct frame_info *this_frame) |
02a71ae8 MK |
1781 | { |
1782 | switch (regnum) | |
1783 | { | |
1784 | case SPARC_G0_REGNUM: | |
1785 | /* Since %g0 is always zero, there is no point in saving it, and | |
1786 | people will be inclined omit it from the CFI. Make sure we | |
1787 | don't warn about that. */ | |
1788 | reg->how = DWARF2_FRAME_REG_SAME_VALUE; | |
1789 | break; | |
1790 | case SPARC_SP_REGNUM: | |
1791 | reg->how = DWARF2_FRAME_REG_CFA; | |
1792 | break; | |
1793 | case SPARC64_PC_REGNUM: | |
1794 | reg->how = DWARF2_FRAME_REG_RA_OFFSET; | |
1795 | reg->loc.offset = 8; | |
1796 | break; | |
1797 | case SPARC64_NPC_REGNUM: | |
1798 | reg->how = DWARF2_FRAME_REG_RA_OFFSET; | |
1799 | reg->loc.offset = 12; | |
1800 | break; | |
1801 | } | |
1802 | } | |
1803 | ||
58afddc6 WP |
1804 | /* sparc64_addr_bits_remove - remove useless address bits */ |
1805 | ||
1806 | static CORE_ADDR | |
1807 | sparc64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr) | |
1808 | { | |
1809 | return adi_normalize_address (addr); | |
1810 | } | |
1811 | ||
8b39fe56 | 1812 | void |
386c036b | 1813 | sparc64_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) |
8b39fe56 | 1814 | { |
386c036b | 1815 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
8b39fe56 | 1816 | |
386c036b MK |
1817 | tdep->pc_regnum = SPARC64_PC_REGNUM; |
1818 | tdep->npc_regnum = SPARC64_NPC_REGNUM; | |
3f7b46f2 IR |
1819 | tdep->fpu_register_names = sparc64_fpu_register_names; |
1820 | tdep->fpu_registers_num = ARRAY_SIZE (sparc64_fpu_register_names); | |
1821 | tdep->cp0_register_names = sparc64_cp0_register_names; | |
1822 | tdep->cp0_registers_num = ARRAY_SIZE (sparc64_cp0_register_names); | |
8b39fe56 | 1823 | |
386c036b | 1824 | /* This is what all the fuss is about. */ |
8b39fe56 MK |
1825 | set_gdbarch_long_bit (gdbarch, 64); |
1826 | set_gdbarch_long_long_bit (gdbarch, 64); | |
1827 | set_gdbarch_ptr_bit (gdbarch, 64); | |
8b39fe56 | 1828 | |
53375380 PA |
1829 | set_gdbarch_wchar_bit (gdbarch, 16); |
1830 | set_gdbarch_wchar_signed (gdbarch, 0); | |
1831 | ||
8b39fe56 MK |
1832 | set_gdbarch_num_regs (gdbarch, SPARC64_NUM_REGS); |
1833 | set_gdbarch_register_name (gdbarch, sparc64_register_name); | |
1834 | set_gdbarch_register_type (gdbarch, sparc64_register_type); | |
1835 | set_gdbarch_num_pseudo_regs (gdbarch, SPARC64_NUM_PSEUDO_REGS); | |
3f7b46f2 IR |
1836 | set_tdesc_pseudo_register_name (gdbarch, sparc64_pseudo_register_name); |
1837 | set_tdesc_pseudo_register_type (gdbarch, sparc64_pseudo_register_type); | |
8b39fe56 MK |
1838 | set_gdbarch_pseudo_register_read (gdbarch, sparc64_pseudo_register_read); |
1839 | set_gdbarch_pseudo_register_write (gdbarch, sparc64_pseudo_register_write); | |
1840 | ||
1841 | /* Register numbers of various important registers. */ | |
8b39fe56 | 1842 | set_gdbarch_pc_regnum (gdbarch, SPARC64_PC_REGNUM); /* %pc */ |
8b39fe56 MK |
1843 | |
1844 | /* Call dummy code. */ | |
49a45ecf | 1845 | set_gdbarch_frame_align (gdbarch, sparc64_frame_align); |
386c036b MK |
1846 | set_gdbarch_call_dummy_location (gdbarch, AT_ENTRY_POINT); |
1847 | set_gdbarch_push_dummy_code (gdbarch, NULL); | |
8b39fe56 MK |
1848 | set_gdbarch_push_dummy_call (gdbarch, sparc64_push_dummy_call); |
1849 | ||
60af1db2 | 1850 | set_gdbarch_return_value (gdbarch, sparc64_return_value); |
386c036b MK |
1851 | set_gdbarch_stabs_argument_has_addr |
1852 | (gdbarch, default_stabs_argument_has_addr); | |
8b39fe56 MK |
1853 | |
1854 | set_gdbarch_skip_prologue (gdbarch, sparc64_skip_prologue); | |
c9cf6e20 | 1855 | set_gdbarch_stack_frame_destroyed_p (gdbarch, sparc_stack_frame_destroyed_p); |
8b39fe56 | 1856 | |
02a71ae8 MK |
1857 | /* Hook in the DWARF CFI frame unwinder. */ |
1858 | dwarf2_frame_set_init_reg (gdbarch, sparc64_dwarf2_frame_init_reg); | |
1859 | /* FIXME: kettenis/20050423: Don't enable the unwinder until the | |
1860 | StackGhost issues have been resolved. */ | |
1861 | ||
236369e7 | 1862 | frame_unwind_append_unwinder (gdbarch, &sparc64_frame_unwind); |
8b39fe56 | 1863 | frame_base_set_default (gdbarch, &sparc64_frame_base); |
58afddc6 WP |
1864 | |
1865 | set_gdbarch_addr_bits_remove (gdbarch, sparc64_addr_bits_remove); | |
386c036b MK |
1866 | } |
1867 | \f | |
8b39fe56 | 1868 | |
386c036b | 1869 | /* Helper functions for dealing with register sets. */ |
8b39fe56 | 1870 | |
386c036b MK |
1871 | #define TSTATE_CWP 0x000000000000001fULL |
1872 | #define TSTATE_ICC 0x0000000f00000000ULL | |
1873 | #define TSTATE_XCC 0x000000f000000000ULL | |
8b39fe56 | 1874 | |
386c036b MK |
1875 | #define PSR_S 0x00000080 |
1876 | #define PSR_ICC 0x00f00000 | |
1877 | #define PSR_VERS 0x0f000000 | |
1878 | #define PSR_IMPL 0xf0000000 | |
1879 | #define PSR_V8PLUS 0xff000000 | |
1880 | #define PSR_XCC 0x000f0000 | |
8b39fe56 | 1881 | |
3567a8ea | 1882 | void |
b4fd25c9 | 1883 | sparc64_supply_gregset (const struct sparc_gregmap *gregmap, |
386c036b MK |
1884 | struct regcache *regcache, |
1885 | int regnum, const void *gregs) | |
8b39fe56 | 1886 | { |
e17a4113 UW |
1887 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
1888 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
1889 | int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32); | |
19ba03f4 | 1890 | const gdb_byte *regs = (const gdb_byte *) gregs; |
22e74ef9 | 1891 | gdb_byte zero[8] = { 0 }; |
8b39fe56 MK |
1892 | int i; |
1893 | ||
386c036b | 1894 | if (sparc32) |
8b39fe56 | 1895 | { |
386c036b MK |
1896 | if (regnum == SPARC32_PSR_REGNUM || regnum == -1) |
1897 | { | |
b4fd25c9 | 1898 | int offset = gregmap->r_tstate_offset; |
386c036b | 1899 | ULONGEST tstate, psr; |
e1613aba | 1900 | gdb_byte buf[4]; |
386c036b | 1901 | |
e17a4113 | 1902 | tstate = extract_unsigned_integer (regs + offset, 8, byte_order); |
386c036b MK |
1903 | psr = ((tstate & TSTATE_CWP) | PSR_S | ((tstate & TSTATE_ICC) >> 12) |
1904 | | ((tstate & TSTATE_XCC) >> 20) | PSR_V8PLUS); | |
e17a4113 | 1905 | store_unsigned_integer (buf, 4, byte_order, psr); |
386c036b MK |
1906 | regcache_raw_supply (regcache, SPARC32_PSR_REGNUM, buf); |
1907 | } | |
1908 | ||
1909 | if (regnum == SPARC32_PC_REGNUM || regnum == -1) | |
1910 | regcache_raw_supply (regcache, SPARC32_PC_REGNUM, | |
b4fd25c9 | 1911 | regs + gregmap->r_pc_offset + 4); |
386c036b MK |
1912 | |
1913 | if (regnum == SPARC32_NPC_REGNUM || regnum == -1) | |
1914 | regcache_raw_supply (regcache, SPARC32_NPC_REGNUM, | |
b4fd25c9 | 1915 | regs + gregmap->r_npc_offset + 4); |
8b39fe56 | 1916 | |
386c036b | 1917 | if (regnum == SPARC32_Y_REGNUM || regnum == -1) |
8b39fe56 | 1918 | { |
b4fd25c9 | 1919 | int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size; |
386c036b | 1920 | regcache_raw_supply (regcache, SPARC32_Y_REGNUM, regs + offset); |
8b39fe56 MK |
1921 | } |
1922 | } | |
1923 | else | |
1924 | { | |
386c036b MK |
1925 | if (regnum == SPARC64_STATE_REGNUM || regnum == -1) |
1926 | regcache_raw_supply (regcache, SPARC64_STATE_REGNUM, | |
b4fd25c9 | 1927 | regs + gregmap->r_tstate_offset); |
8b39fe56 | 1928 | |
386c036b MK |
1929 | if (regnum == SPARC64_PC_REGNUM || regnum == -1) |
1930 | regcache_raw_supply (regcache, SPARC64_PC_REGNUM, | |
b4fd25c9 | 1931 | regs + gregmap->r_pc_offset); |
386c036b MK |
1932 | |
1933 | if (regnum == SPARC64_NPC_REGNUM || regnum == -1) | |
1934 | regcache_raw_supply (regcache, SPARC64_NPC_REGNUM, | |
b4fd25c9 | 1935 | regs + gregmap->r_npc_offset); |
386c036b MK |
1936 | |
1937 | if (regnum == SPARC64_Y_REGNUM || regnum == -1) | |
3567a8ea | 1938 | { |
e1613aba | 1939 | gdb_byte buf[8]; |
386c036b MK |
1940 | |
1941 | memset (buf, 0, 8); | |
b4fd25c9 AA |
1942 | memcpy (buf + 8 - gregmap->r_y_size, |
1943 | regs + gregmap->r_y_offset, gregmap->r_y_size); | |
386c036b | 1944 | regcache_raw_supply (regcache, SPARC64_Y_REGNUM, buf); |
3567a8ea | 1945 | } |
8b39fe56 | 1946 | |
386c036b | 1947 | if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1) |
b4fd25c9 | 1948 | && gregmap->r_fprs_offset != -1) |
386c036b | 1949 | regcache_raw_supply (regcache, SPARC64_FPRS_REGNUM, |
b4fd25c9 | 1950 | regs + gregmap->r_fprs_offset); |
386c036b MK |
1951 | } |
1952 | ||
1953 | if (regnum == SPARC_G0_REGNUM || regnum == -1) | |
22e74ef9 | 1954 | regcache_raw_supply (regcache, SPARC_G0_REGNUM, &zero); |
386c036b MK |
1955 | |
1956 | if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) | |
1957 | { | |
b4fd25c9 | 1958 | int offset = gregmap->r_g1_offset; |
386c036b MK |
1959 | |
1960 | if (sparc32) | |
1961 | offset += 4; | |
1962 | ||
1963 | for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) | |
8b39fe56 | 1964 | { |
3567a8ea | 1965 | if (regnum == i || regnum == -1) |
386c036b MK |
1966 | regcache_raw_supply (regcache, i, regs + offset); |
1967 | offset += 8; | |
1968 | } | |
1969 | } | |
1970 | ||
1971 | if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) | |
1972 | { | |
1973 | /* Not all of the register set variants include Locals and | |
1974 | Inputs. For those that don't, we read them off the stack. */ | |
b4fd25c9 | 1975 | if (gregmap->r_l0_offset == -1) |
386c036b MK |
1976 | { |
1977 | ULONGEST sp; | |
1978 | ||
1979 | regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM, &sp); | |
1980 | sparc_supply_rwindow (regcache, sp, regnum); | |
1981 | } | |
1982 | else | |
1983 | { | |
b4fd25c9 | 1984 | int offset = gregmap->r_l0_offset; |
386c036b MK |
1985 | |
1986 | if (sparc32) | |
1987 | offset += 4; | |
1988 | ||
1989 | for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) | |
3567a8ea | 1990 | { |
386c036b MK |
1991 | if (regnum == i || regnum == -1) |
1992 | regcache_raw_supply (regcache, i, regs + offset); | |
1993 | offset += 8; | |
3567a8ea | 1994 | } |
8b39fe56 MK |
1995 | } |
1996 | } | |
1997 | } | |
1998 | ||
1999 | void | |
b4fd25c9 | 2000 | sparc64_collect_gregset (const struct sparc_gregmap *gregmap, |
386c036b MK |
2001 | const struct regcache *regcache, |
2002 | int regnum, void *gregs) | |
8b39fe56 | 2003 | { |
e17a4113 UW |
2004 | struct gdbarch *gdbarch = get_regcache_arch (regcache); |
2005 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
2006 | int sparc32 = (gdbarch_ptr_bit (gdbarch) == 32); | |
19ba03f4 | 2007 | gdb_byte *regs = (gdb_byte *) gregs; |
3567a8ea MK |
2008 | int i; |
2009 | ||
386c036b | 2010 | if (sparc32) |
8b39fe56 | 2011 | { |
386c036b MK |
2012 | if (regnum == SPARC32_PSR_REGNUM || regnum == -1) |
2013 | { | |
b4fd25c9 | 2014 | int offset = gregmap->r_tstate_offset; |
386c036b | 2015 | ULONGEST tstate, psr; |
e1613aba | 2016 | gdb_byte buf[8]; |
386c036b | 2017 | |
e17a4113 | 2018 | tstate = extract_unsigned_integer (regs + offset, 8, byte_order); |
386c036b | 2019 | regcache_raw_collect (regcache, SPARC32_PSR_REGNUM, buf); |
e17a4113 | 2020 | psr = extract_unsigned_integer (buf, 4, byte_order); |
386c036b MK |
2021 | tstate |= (psr & PSR_ICC) << 12; |
2022 | if ((psr & (PSR_VERS | PSR_IMPL)) == PSR_V8PLUS) | |
2023 | tstate |= (psr & PSR_XCC) << 20; | |
e17a4113 | 2024 | store_unsigned_integer (buf, 8, byte_order, tstate); |
386c036b MK |
2025 | memcpy (regs + offset, buf, 8); |
2026 | } | |
8b39fe56 | 2027 | |
386c036b MK |
2028 | if (regnum == SPARC32_PC_REGNUM || regnum == -1) |
2029 | regcache_raw_collect (regcache, SPARC32_PC_REGNUM, | |
b4fd25c9 | 2030 | regs + gregmap->r_pc_offset + 4); |
386c036b MK |
2031 | |
2032 | if (regnum == SPARC32_NPC_REGNUM || regnum == -1) | |
2033 | regcache_raw_collect (regcache, SPARC32_NPC_REGNUM, | |
b4fd25c9 | 2034 | regs + gregmap->r_npc_offset + 4); |
386c036b MK |
2035 | |
2036 | if (regnum == SPARC32_Y_REGNUM || regnum == -1) | |
8b39fe56 | 2037 | { |
b4fd25c9 | 2038 | int offset = gregmap->r_y_offset + 8 - gregmap->r_y_size; |
386c036b | 2039 | regcache_raw_collect (regcache, SPARC32_Y_REGNUM, regs + offset); |
8b39fe56 MK |
2040 | } |
2041 | } | |
2042 | else | |
2043 | { | |
386c036b MK |
2044 | if (regnum == SPARC64_STATE_REGNUM || regnum == -1) |
2045 | regcache_raw_collect (regcache, SPARC64_STATE_REGNUM, | |
b4fd25c9 | 2046 | regs + gregmap->r_tstate_offset); |
386c036b MK |
2047 | |
2048 | if (regnum == SPARC64_PC_REGNUM || regnum == -1) | |
2049 | regcache_raw_collect (regcache, SPARC64_PC_REGNUM, | |
b4fd25c9 | 2050 | regs + gregmap->r_pc_offset); |
3567a8ea | 2051 | |
386c036b MK |
2052 | if (regnum == SPARC64_NPC_REGNUM || regnum == -1) |
2053 | regcache_raw_collect (regcache, SPARC64_NPC_REGNUM, | |
b4fd25c9 | 2054 | regs + gregmap->r_npc_offset); |
3567a8ea | 2055 | |
386c036b | 2056 | if (regnum == SPARC64_Y_REGNUM || regnum == -1) |
3567a8ea | 2057 | { |
e1613aba | 2058 | gdb_byte buf[8]; |
386c036b MK |
2059 | |
2060 | regcache_raw_collect (regcache, SPARC64_Y_REGNUM, buf); | |
b4fd25c9 AA |
2061 | memcpy (regs + gregmap->r_y_offset, |
2062 | buf + 8 - gregmap->r_y_size, gregmap->r_y_size); | |
386c036b MK |
2063 | } |
2064 | ||
2065 | if ((regnum == SPARC64_FPRS_REGNUM || regnum == -1) | |
b4fd25c9 | 2066 | && gregmap->r_fprs_offset != -1) |
386c036b | 2067 | regcache_raw_collect (regcache, SPARC64_FPRS_REGNUM, |
b4fd25c9 | 2068 | regs + gregmap->r_fprs_offset); |
386c036b MK |
2069 | |
2070 | } | |
2071 | ||
2072 | if ((regnum >= SPARC_G1_REGNUM && regnum <= SPARC_O7_REGNUM) || regnum == -1) | |
2073 | { | |
b4fd25c9 | 2074 | int offset = gregmap->r_g1_offset; |
386c036b MK |
2075 | |
2076 | if (sparc32) | |
2077 | offset += 4; | |
2078 | ||
2079 | /* %g0 is always zero. */ | |
2080 | for (i = SPARC_G1_REGNUM; i <= SPARC_O7_REGNUM; i++) | |
2081 | { | |
2082 | if (regnum == i || regnum == -1) | |
2083 | regcache_raw_collect (regcache, i, regs + offset); | |
2084 | offset += 8; | |
2085 | } | |
2086 | } | |
2087 | ||
2088 | if ((regnum >= SPARC_L0_REGNUM && regnum <= SPARC_I7_REGNUM) || regnum == -1) | |
2089 | { | |
2090 | /* Not all of the register set variants include Locals and | |
2091 | Inputs. For those that don't, we read them off the stack. */ | |
b4fd25c9 | 2092 | if (gregmap->r_l0_offset != -1) |
386c036b | 2093 | { |
b4fd25c9 | 2094 | int offset = gregmap->r_l0_offset; |
386c036b MK |
2095 | |
2096 | if (sparc32) | |
2097 | offset += 4; | |
2098 | ||
2099 | for (i = SPARC_L0_REGNUM; i <= SPARC_I7_REGNUM; i++) | |
3567a8ea | 2100 | { |
386c036b MK |
2101 | if (regnum == i || regnum == -1) |
2102 | regcache_raw_collect (regcache, i, regs + offset); | |
2103 | offset += 8; | |
3567a8ea MK |
2104 | } |
2105 | } | |
8b39fe56 MK |
2106 | } |
2107 | } | |
8b39fe56 | 2108 | |
386c036b | 2109 | void |
b4fd25c9 | 2110 | sparc64_supply_fpregset (const struct sparc_fpregmap *fpregmap, |
db75c717 | 2111 | struct regcache *regcache, |
386c036b MK |
2112 | int regnum, const void *fpregs) |
2113 | { | |
e6d4f032 | 2114 | int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32); |
19ba03f4 | 2115 | const gdb_byte *regs = (const gdb_byte *) fpregs; |
386c036b MK |
2116 | int i; |
2117 | ||
2118 | for (i = 0; i < 32; i++) | |
2119 | { | |
2120 | if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) | |
db75c717 | 2121 | regcache_raw_supply (regcache, SPARC_F0_REGNUM + i, |
b4fd25c9 | 2122 | regs + fpregmap->r_f0_offset + (i * 4)); |
386c036b MK |
2123 | } |
2124 | ||
2125 | if (sparc32) | |
2126 | { | |
2127 | if (regnum == SPARC32_FSR_REGNUM || regnum == -1) | |
2128 | regcache_raw_supply (regcache, SPARC32_FSR_REGNUM, | |
b4fd25c9 | 2129 | regs + fpregmap->r_fsr_offset); |
386c036b MK |
2130 | } |
2131 | else | |
2132 | { | |
2133 | for (i = 0; i < 16; i++) | |
2134 | { | |
2135 | if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1) | |
2136 | regcache_raw_supply (regcache, SPARC64_F32_REGNUM + i, | |
b4fd25c9 | 2137 | (regs + fpregmap->r_f0_offset |
db75c717 | 2138 | + (32 * 4) + (i * 8))); |
386c036b MK |
2139 | } |
2140 | ||
2141 | if (regnum == SPARC64_FSR_REGNUM || regnum == -1) | |
2142 | regcache_raw_supply (regcache, SPARC64_FSR_REGNUM, | |
b4fd25c9 | 2143 | regs + fpregmap->r_fsr_offset); |
386c036b MK |
2144 | } |
2145 | } | |
8b39fe56 MK |
2146 | |
2147 | void | |
b4fd25c9 | 2148 | sparc64_collect_fpregset (const struct sparc_fpregmap *fpregmap, |
db75c717 | 2149 | const struct regcache *regcache, |
386c036b | 2150 | int regnum, void *fpregs) |
8b39fe56 | 2151 | { |
e6d4f032 | 2152 | int sparc32 = (gdbarch_ptr_bit (get_regcache_arch (regcache)) == 32); |
19ba03f4 | 2153 | gdb_byte *regs = (gdb_byte *) fpregs; |
386c036b MK |
2154 | int i; |
2155 | ||
2156 | for (i = 0; i < 32; i++) | |
2157 | { | |
2158 | if (regnum == (SPARC_F0_REGNUM + i) || regnum == -1) | |
db75c717 | 2159 | regcache_raw_collect (regcache, SPARC_F0_REGNUM + i, |
b4fd25c9 | 2160 | regs + fpregmap->r_f0_offset + (i * 4)); |
386c036b MK |
2161 | } |
2162 | ||
2163 | if (sparc32) | |
2164 | { | |
2165 | if (regnum == SPARC32_FSR_REGNUM || regnum == -1) | |
2166 | regcache_raw_collect (regcache, SPARC32_FSR_REGNUM, | |
b4fd25c9 | 2167 | regs + fpregmap->r_fsr_offset); |
386c036b MK |
2168 | } |
2169 | else | |
2170 | { | |
2171 | for (i = 0; i < 16; i++) | |
2172 | { | |
2173 | if (regnum == (SPARC64_F32_REGNUM + i) || regnum == -1) | |
2174 | regcache_raw_collect (regcache, SPARC64_F32_REGNUM + i, | |
b4fd25c9 | 2175 | (regs + fpregmap->r_f0_offset |
db75c717 | 2176 | + (32 * 4) + (i * 8))); |
386c036b MK |
2177 | } |
2178 | ||
2179 | if (regnum == SPARC64_FSR_REGNUM || regnum == -1) | |
2180 | regcache_raw_collect (regcache, SPARC64_FSR_REGNUM, | |
b4fd25c9 | 2181 | regs + fpregmap->r_fsr_offset); |
386c036b | 2182 | } |
8b39fe56 | 2183 | } |
fd936806 | 2184 | |
b4fd25c9 | 2185 | const struct sparc_fpregmap sparc64_bsd_fpregmap = |
db75c717 DM |
2186 | { |
2187 | 0 * 8, /* %f0 */ | |
2188 | 32 * 8, /* %fsr */ | |
2189 | }; |