This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparc64-tdep.c
2184 lines (1826 loc) · 61 KB
/
sparc64-tdep.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* Target-dependent code for UltraSPARC.
Copyright (C) 2003-2024 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "arch-utils.h"
#include "dwarf2/frame.h"
#include "frame.h"
#include "frame-base.h"
#include "frame-unwind.h"
#include "gdbcore.h"
#include "gdbtypes.h"
#include "inferior.h"
#include "symtab.h"
#include "objfiles.h"
#include "osabi.h"
#include "regcache.h"
#include "target-descriptions.h"
#include "target.h"
#include "value.h"
#include "sparc64-tdep.h"
#include <forward_list>
/* This file implements the SPARC 64-bit ABI as defined by the
section "Low-Level System Information" of the SPARC Compliance
Definition (SCD) 2.4.1, which is the 64-bit System V psABI for
SPARC. */
/* Please use the sparc32_-prefix for 32-bit specific code, the
sparc64_-prefix for 64-bit specific code and the sparc_-prefix for
code can handle both. */
/* The M7 processor supports an Application Data Integrity (ADI) feature
that detects invalid data accesses. When software allocates memory and
enables ADI on the allocated memory, it chooses a 4-bit version number,
sets the version in the upper 4 bits of the 64-bit pointer to that data,
and stores the 4-bit version in every cacheline of the object. Hardware
saves the latter in spare bits in the cache and memory hierarchy. On each
load and store, the processor compares the upper 4 VA (virtual address) bits
to the cacheline's version. If there is a mismatch, the processor generates
a version mismatch trap which can be either precise or disrupting.
The trap is an error condition which the kernel delivers to the process
as a SIGSEGV signal.
The upper 4 bits of the VA represent a version and are not part of the
true address. The processor clears these bits and sign extends bit 59
to generate the true address.
Note that 32-bit applications cannot use ADI. */
#include <algorithm>
#include "cli/cli-utils.h"
#include "gdbcmd.h"
#include "auxv.h"
#define MAX_PROC_NAME_SIZE sizeof("/proc/99999/lwp/9999/adi/lstatus")
/* ELF Auxiliary vectors */
#ifndef AT_ADI_BLKSZ
#define AT_ADI_BLKSZ 34
#endif
#ifndef AT_ADI_NBITS
#define AT_ADI_NBITS 35
#endif
#ifndef AT_ADI_UEONADI
#define AT_ADI_UEONADI 36
#endif
/* ADI command list. */
static struct cmd_list_element *sparc64adilist = NULL;
/* ADI stat settings. */
struct adi_stat_t
{
/* The ADI block size. */
unsigned long blksize;
/* Number of bits used for an ADI version tag which can be
used together with the shift value for an ADI version tag
to encode or extract the ADI version value in a pointer. */
unsigned long nbits;
/* The maximum ADI version tag value supported. */
int max_version;
/* ADI version tag file. */
int tag_fd = 0;
/* ADI availability check has been done. */
bool checked_avail = false;
/* ADI is available. */
bool is_avail = false;
};
/* Per-process ADI stat info. */
struct sparc64_adi_info
{
sparc64_adi_info (pid_t pid_)
: pid (pid_)
{}
/* The process identifier. */
pid_t pid;
/* The ADI stat. */
adi_stat_t stat = {};
};
static std::forward_list<sparc64_adi_info> adi_proc_list;
/* Get ADI info for process PID, creating one if it doesn't exist. */
static sparc64_adi_info *
get_adi_info_proc (pid_t pid)
{
auto found = std::find_if (adi_proc_list.begin (), adi_proc_list.end (),
[&pid] (const sparc64_adi_info &info)
{
return info.pid == pid;
});
if (found == adi_proc_list.end ())
{
adi_proc_list.emplace_front (pid);
return &adi_proc_list.front ();
}
else
{
return &(*found);
}
}
static adi_stat_t
get_adi_info (pid_t pid)
{
sparc64_adi_info *proc;
proc = get_adi_info_proc (pid);
return proc->stat;
}
/* Is called when GDB is no longer debugging process PID. It
deletes data structure that keeps track of the ADI stat. */
void
sparc64_forget_process (pid_t pid)
{
fileio_error target_errno;
for (auto pit = adi_proc_list.before_begin (),
it = std::next (pit);
it != adi_proc_list.end ();
)
{
if ((*it).pid == pid)
{
if ((*it).stat.tag_fd > 0)
target_fileio_close ((*it).stat.tag_fd, &target_errno);
adi_proc_list.erase_after (pit);
break;
}
else
pit = it++;
}
}
/* Read attributes of a maps entry in /proc/[pid]/adi/maps. */
static void
read_maps_entry (const char *line,
ULONGEST *addr, ULONGEST *endaddr)
{
const char *p = line;
*addr = strtoulst (p, &p, 16);
if (*p == '-')
p++;
*endaddr = strtoulst (p, &p, 16);
}
/* Check if ADI is available. */
static bool
adi_available (void)
{
pid_t pid = inferior_ptid.pid ();
sparc64_adi_info *proc = get_adi_info_proc (pid);
CORE_ADDR value;
if (proc->stat.checked_avail)
return proc->stat.is_avail;
proc->stat.checked_avail = true;
if (target_auxv_search (AT_ADI_BLKSZ, &value) <= 0)
return false;
proc->stat.blksize = value;
target_auxv_search (AT_ADI_NBITS, &value);
proc->stat.nbits = value;
proc->stat.max_version = (1 << proc->stat.nbits) - 2;
proc->stat.is_avail = true;
return proc->stat.is_avail;
}
/* Normalize a versioned address - a VA with ADI bits (63-60) set. */
static CORE_ADDR
adi_normalize_address (CORE_ADDR addr)
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
if (ast.nbits)
{
/* Clear upper bits. */
addr &= ((uint64_t) -1) >> ast.nbits;
/* Sign extend. */
CORE_ADDR signbit = (uint64_t) 1 << (64 - ast.nbits - 1);
return (addr ^ signbit) - signbit;
}
return addr;
}
/* Align a normalized address - a VA with bit 59 sign extended into
ADI bits. */
static CORE_ADDR
adi_align_address (CORE_ADDR naddr)
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
return (naddr - (naddr % ast.blksize)) / ast.blksize;
}
/* Convert a byte count to count at a ratio of 1:adi_blksz. */
static int
adi_convert_byte_count (CORE_ADDR naddr, int nbytes, CORE_ADDR locl)
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
return ((naddr + nbytes + ast.blksize - 1) / ast.blksize) - locl;
}
/* The /proc/[pid]/adi/tags file, which allows gdb to get/set ADI
version in a target process, maps linearly to the address space
of the target process at a ratio of 1:adi_blksz.
A read (or write) at offset K in the file returns (or modifies)
the ADI version tag stored in the cacheline containing address
K * adi_blksz, encoded as 1 version tag per byte. The allowed
version tag values are between 0 and adi_stat.max_version. */
static int
adi_tag_fd (void)
{
pid_t pid = inferior_ptid.pid ();
sparc64_adi_info *proc = get_adi_info_proc (pid);
if (proc->stat.tag_fd != 0)
return proc->stat.tag_fd;
char cl_name[MAX_PROC_NAME_SIZE];
snprintf (cl_name, sizeof(cl_name), "/proc/%ld/adi/tags", (long) pid);
fileio_error target_errno;
proc->stat.tag_fd = target_fileio_open (NULL, cl_name, O_RDWR|O_EXCL,
false, 0, &target_errno);
return proc->stat.tag_fd;
}
/* Check if an address set is ADI enabled, using /proc/[pid]/adi/maps
which was exported by the kernel and contains the currently ADI
mapped memory regions and their access permissions. */
static bool
adi_is_addr_mapped (CORE_ADDR vaddr, size_t cnt)
{
char filename[MAX_PROC_NAME_SIZE];
size_t i = 0;
pid_t pid = inferior_ptid.pid ();
snprintf (filename, sizeof filename, "/proc/%ld/adi/maps", (long) pid);
gdb::unique_xmalloc_ptr<char> data
= target_fileio_read_stralloc (NULL, filename);
if (data)
{
adi_stat_t adi_stat = get_adi_info (pid);
char *saveptr;
for (char *line = strtok_r (data.get (), "\n", &saveptr);
line;
line = strtok_r (NULL, "\n", &saveptr))
{
ULONGEST addr, endaddr;
read_maps_entry (line, &addr, &endaddr);
while (((vaddr + i) * adi_stat.blksize) >= addr
&& ((vaddr + i) * adi_stat.blksize) < endaddr)
{
if (++i == cnt)
return true;
}
}
}
else
warning (_("unable to open /proc file '%s'"), filename);
return false;
}
/* Read ADI version tag value for memory locations starting at "VADDR"
for "SIZE" number of bytes. */
static int
adi_read_versions (CORE_ADDR vaddr, size_t size, gdb_byte *tags)
{
int fd = adi_tag_fd ();
if (fd == -1)
return -1;
if (!adi_is_addr_mapped (vaddr, size))
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
error(_("Address at %s is not in ADI maps"),
paddress (current_inferior ()->arch (), vaddr * ast.blksize));
}
fileio_error target_errno;
return target_fileio_pread (fd, tags, size, vaddr, &target_errno);
}
/* Write ADI version tag for memory locations starting at "VADDR" for
"SIZE" number of bytes to "TAGS". */
static int
adi_write_versions (CORE_ADDR vaddr, size_t size, unsigned char *tags)
{
int fd = adi_tag_fd ();
if (fd == -1)
return -1;
if (!adi_is_addr_mapped (vaddr, size))
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
error(_("Address at %s is not in ADI maps"),
paddress (current_inferior ()->arch (), vaddr * ast.blksize));
}
fileio_error target_errno;
return target_fileio_pwrite (fd, tags, size, vaddr, &target_errno);
}
/* Print ADI version tag value in "TAGS" for memory locations starting
at "VADDR" with number of "CNT". */
static void
adi_print_versions (CORE_ADDR vaddr, size_t cnt, gdb_byte *tags)
{
int v_idx = 0;
const int maxelts = 8; /* # of elements per line */
adi_stat_t adi_stat = get_adi_info (inferior_ptid.pid ());
while (cnt > 0)
{
QUIT;
gdb_printf ("%s:\t",
paddress (current_inferior ()->arch (),
vaddr * adi_stat.blksize));
for (int i = maxelts; i > 0 && cnt > 0; i--, cnt--)
{
if (tags[v_idx] == 0xff) /* no version tag */
gdb_printf ("-");
else
gdb_printf ("%1X", tags[v_idx]);
if (cnt > 1)
gdb_printf (" ");
++v_idx;
}
gdb_printf ("\n");
vaddr += maxelts;
}
}
static void
do_examine (CORE_ADDR start, int bcnt)
{
CORE_ADDR vaddr = adi_normalize_address (start);
CORE_ADDR vstart = adi_align_address (vaddr);
int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
gdb::byte_vector buf (cnt);
int read_cnt = adi_read_versions (vstart, cnt, buf.data ());
if (read_cnt == -1)
error (_("No ADI information"));
else if (read_cnt < cnt)
error(_("No ADI information at %s"),
paddress (current_inferior ()->arch (), vaddr));
adi_print_versions (vstart, cnt, buf.data ());
}
static void
do_assign (CORE_ADDR start, size_t bcnt, int version)
{
CORE_ADDR vaddr = adi_normalize_address (start);
CORE_ADDR vstart = adi_align_address (vaddr);
int cnt = adi_convert_byte_count (vaddr, bcnt, vstart);
std::vector<unsigned char> buf (cnt, version);
int set_cnt = adi_write_versions (vstart, cnt, buf.data ());
if (set_cnt == -1)
error (_("No ADI information"));
else if (set_cnt < cnt)
error(_("No ADI information at %s"),
paddress (current_inferior ()->arch (), vaddr));
}
/* ADI examine version tag command.
Command syntax:
adi (examine|x)[/COUNT] [ADDR] */
static void
adi_examine_command (const char *args, int from_tty)
{
/* make sure program is active and adi is available */
if (!target_has_execution ())
error (_("ADI command requires a live process/thread"));
if (!adi_available ())
error (_("No ADI information"));
int cnt = 1;
const char *p = args;
if (p && *p == '/')
{
p++;
cnt = get_number (&p);
}
CORE_ADDR next_address = 0;
if (p != 0 && *p != 0)
next_address = parse_and_eval_address (p);
if (!cnt || !next_address)
error (_("Usage: adi examine|x[/COUNT] [ADDR]"));
do_examine (next_address, cnt);
}
/* ADI assign version tag command.
Command syntax:
adi (assign|a)[/COUNT] ADDR = VERSION */
static void
adi_assign_command (const char *args, int from_tty)
{
static const char *adi_usage
= N_("Usage: adi assign|a[/COUNT] ADDR = VERSION");
/* make sure program is active and adi is available */
if (!target_has_execution ())
error (_("ADI command requires a live process/thread"));
if (!adi_available ())
error (_("No ADI information"));
const char *exp = args;
if (exp == 0)
error_no_arg (_(adi_usage));
char *q = (char *) strchr (exp, '=');
if (q)
*q++ = 0;
else
error ("%s", _(adi_usage));
size_t cnt = 1;
const char *p = args;
if (exp && *exp == '/')
{
p = exp + 1;
cnt = get_number (&p);
}
CORE_ADDR next_address = 0;
if (p != 0 && *p != 0)
next_address = parse_and_eval_address (p);
else
error ("%s", _(adi_usage));
int version = 0;
if (q != NULL) /* parse version tag */
{
adi_stat_t ast = get_adi_info (inferior_ptid.pid ());
version = parse_and_eval_long (q);
if (version < 0 || version > ast.max_version)
error (_("Invalid ADI version tag %d"), version);
}
do_assign (next_address, cnt, version);
}
void _initialize_sparc64_adi_tdep ();
void
_initialize_sparc64_adi_tdep ()
{
add_basic_prefix_cmd ("adi", class_support,
_("ADI version related commands."),
&sparc64adilist, 0, &cmdlist);
cmd_list_element *adi_examine_cmd
= add_cmd ("examine", class_support, adi_examine_command,
_("Examine ADI versions."), &sparc64adilist);
add_alias_cmd ("x", adi_examine_cmd, no_class, 1, &sparc64adilist);
add_cmd ("assign", class_support, adi_assign_command,
_("Assign ADI versions."), &sparc64adilist);
}
/* The functions on this page are intended to be used to classify
function arguments. */
/* Check whether TYPE is "Integral or Pointer". */
static int
sparc64_integral_or_pointer_p (const struct type *type)
{
switch (type->code ())
{
case TYPE_CODE_INT:
case TYPE_CODE_BOOL:
case TYPE_CODE_CHAR:
case TYPE_CODE_ENUM:
case TYPE_CODE_RANGE:
{
int len = type->length ();
gdb_assert (len == 1 || len == 2 || len == 4 || len == 8);
}
return 1;
case TYPE_CODE_PTR:
case TYPE_CODE_REF:
case TYPE_CODE_RVALUE_REF:
{
int len = type->length ();
gdb_assert (len == 8);
}
return 1;
default:
break;
}
return 0;
}
/* Check whether TYPE is "Floating". */
static int
sparc64_floating_p (const struct type *type)
{
switch (type->code ())
{
case TYPE_CODE_FLT:
{
int len = type->length ();
gdb_assert (len == 4 || len == 8 || len == 16);
}
return 1;
default:
break;
}
return 0;
}
/* Check whether TYPE is "Complex Floating". */
static int
sparc64_complex_floating_p (const struct type *type)
{
switch (type->code ())
{
case TYPE_CODE_COMPLEX:
{
int len = type->length ();
gdb_assert (len == 8 || len == 16 || len == 32);
}
return 1;
default:
break;
}
return 0;
}
/* Check whether TYPE is "Structure or Union".
In terms of Ada subprogram calls, arrays are treated the same as
struct and union types. So this function also returns non-zero
for array types. */
static int
sparc64_structure_or_union_p (const struct type *type)
{
switch (type->code ())
{
case TYPE_CODE_STRUCT:
case TYPE_CODE_UNION:
case TYPE_CODE_ARRAY:
return 1;
default:
break;
}
return 0;
}
/* Construct types for ISA-specific registers. */
static struct type *
sparc64_pstate_type (struct gdbarch *gdbarch)
{
sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
if (!tdep->sparc64_pstate_type)
{
struct type *type;
type = arch_flags_type (gdbarch, "builtin_type_sparc64_pstate", 64);
append_flags_type_flag (type, 0, "AG");
append_flags_type_flag (type, 1, "IE");
append_flags_type_flag (type, 2, "PRIV");
append_flags_type_flag (type, 3, "AM");
append_flags_type_flag (type, 4, "PEF");
append_flags_type_flag (type, 5, "RED");
append_flags_type_flag (type, 8, "TLE");
append_flags_type_flag (type, 9, "CLE");
append_flags_type_flag (type, 10, "PID0");
append_flags_type_flag (type, 11, "PID1");
tdep->sparc64_pstate_type = type;
}
return tdep->sparc64_pstate_type;
}
static struct type *
sparc64_ccr_type (struct gdbarch *gdbarch)
{
sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
if (tdep->sparc64_ccr_type == NULL)
{
struct type *type;
type = arch_flags_type (gdbarch, "builtin_type_sparc64_ccr", 64);
append_flags_type_flag (type, 0, "icc.c");
append_flags_type_flag (type, 1, "icc.v");
append_flags_type_flag (type, 2, "icc.z");
append_flags_type_flag (type, 3, "icc.n");
append_flags_type_flag (type, 4, "xcc.c");
append_flags_type_flag (type, 5, "xcc.v");
append_flags_type_flag (type, 6, "xcc.z");
append_flags_type_flag (type, 7, "xcc.n");
tdep->sparc64_ccr_type = type;
}
return tdep->sparc64_ccr_type;
}
static struct type *
sparc64_fsr_type (struct gdbarch *gdbarch)
{
sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
if (!tdep->sparc64_fsr_type)
{
struct type *type;
type = arch_flags_type (gdbarch, "builtin_type_sparc64_fsr", 64);
append_flags_type_flag (type, 0, "NXC");
append_flags_type_flag (type, 1, "DZC");
append_flags_type_flag (type, 2, "UFC");
append_flags_type_flag (type, 3, "OFC");
append_flags_type_flag (type, 4, "NVC");
append_flags_type_flag (type, 5, "NXA");
append_flags_type_flag (type, 6, "DZA");
append_flags_type_flag (type, 7, "UFA");
append_flags_type_flag (type, 8, "OFA");
append_flags_type_flag (type, 9, "NVA");
append_flags_type_flag (type, 22, "NS");
append_flags_type_flag (type, 23, "NXM");
append_flags_type_flag (type, 24, "DZM");
append_flags_type_flag (type, 25, "UFM");
append_flags_type_flag (type, 26, "OFM");
append_flags_type_flag (type, 27, "NVM");
tdep->sparc64_fsr_type = type;
}
return tdep->sparc64_fsr_type;
}
static struct type *
sparc64_fprs_type (struct gdbarch *gdbarch)
{
sparc_gdbarch_tdep *tdep = gdbarch_tdep<sparc_gdbarch_tdep> (gdbarch);
if (!tdep->sparc64_fprs_type)
{
struct type *type;
type = arch_flags_type (gdbarch, "builtin_type_sparc64_fprs", 64);
append_flags_type_flag (type, 0, "DL");
append_flags_type_flag (type, 1, "DU");
append_flags_type_flag (type, 2, "FEF");
tdep->sparc64_fprs_type = type;
}
return tdep->sparc64_fprs_type;
}
/* Register information. */
#define SPARC64_FPU_REGISTERS \
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", \
"f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15", \
"f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23", \
"f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31", \
"f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46", \
"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62"
#define SPARC64_CP0_REGISTERS \
"pc", "npc", \
/* FIXME: Give "state" a name until we start using register groups. */ \
"state", \
"fsr", \
"fprs", \
"y"
static const char * const sparc64_fpu_register_names[] = {
SPARC64_FPU_REGISTERS
};
static const char * const sparc64_cp0_register_names[] = {
SPARC64_CP0_REGISTERS
};
static const char * const sparc64_register_names[] =
{
SPARC_CORE_REGISTERS,
SPARC64_FPU_REGISTERS,
SPARC64_CP0_REGISTERS
};
/* Total number of registers. */
#define SPARC64_NUM_REGS ARRAY_SIZE (sparc64_register_names)
/* We provide the aliases %d0..%d62 and %q0..%q60 for the floating
registers as "psuedo" registers. */
static const char * const sparc64_pseudo_register_names[] =
{
"cwp", "pstate", "asi", "ccr",
"d0", "d2", "d4", "d6", "d8", "d10", "d12", "d14",
"d16", "d18", "d20", "d22", "d24", "d26", "d28", "d30",
"d32", "d34", "d36", "d38", "d40", "d42", "d44", "d46",
"d48", "d50", "d52", "d54", "d56", "d58", "d60", "d62",
"q0", "q4", "q8", "q12", "q16", "q20", "q24", "q28",
"q32", "q36", "q40", "q44", "q48", "q52", "q56", "q60",
};
/* Total number of pseudo registers. */
#define SPARC64_NUM_PSEUDO_REGS ARRAY_SIZE (sparc64_pseudo_register_names)
/* Return the name of pseudo register REGNUM. */
static const char *
sparc64_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
{
regnum -= gdbarch_num_regs (gdbarch);
gdb_assert (regnum < SPARC64_NUM_PSEUDO_REGS);
return sparc64_pseudo_register_names[regnum];
}
/* Return the name of register REGNUM. */
static const char *
sparc64_register_name (struct gdbarch *gdbarch, int regnum)
{
if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
return tdesc_register_name (gdbarch, regnum);
if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
return sparc64_register_names[regnum];
return sparc64_pseudo_register_name (gdbarch, regnum);
}
/* Return the GDB type object for the "standard" data type of data in
pseudo register REGNUM. */
static struct type *
sparc64_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
{
regnum -= gdbarch_num_regs (gdbarch);
if (regnum == SPARC64_CWP_REGNUM)
return builtin_type (gdbarch)->builtin_int64;
if (regnum == SPARC64_PSTATE_REGNUM)
return sparc64_pstate_type (gdbarch);
if (regnum == SPARC64_ASI_REGNUM)
return builtin_type (gdbarch)->builtin_int64;
if (regnum == SPARC64_CCR_REGNUM)
return sparc64_ccr_type (gdbarch);
if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D62_REGNUM)
return builtin_type (gdbarch)->builtin_double;
if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q60_REGNUM)
return builtin_type (gdbarch)->builtin_long_double;
internal_error (_("sparc64_pseudo_register_type: bad register number %d"),
regnum);
}
/* Return the GDB type object for the "standard" data type of data in
register REGNUM. */
static struct type *
sparc64_register_type (struct gdbarch *gdbarch, int regnum)
{
if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
return tdesc_register_type (gdbarch, regnum);
/* Raw registers. */
if (regnum == SPARC_SP_REGNUM || regnum == SPARC_FP_REGNUM)
return builtin_type (gdbarch)->builtin_data_ptr;
if (regnum >= SPARC_G0_REGNUM && regnum <= SPARC_I7_REGNUM)
return builtin_type (gdbarch)->builtin_int64;
if (regnum >= SPARC_F0_REGNUM && regnum <= SPARC_F31_REGNUM)
return builtin_type (gdbarch)->builtin_float;
if (regnum >= SPARC64_F32_REGNUM && regnum <= SPARC64_F62_REGNUM)
return builtin_type (gdbarch)->builtin_double;
if (regnum == SPARC64_PC_REGNUM || regnum == SPARC64_NPC_REGNUM)
return builtin_type (gdbarch)->builtin_func_ptr;
/* This raw register contains the contents of %cwp, %pstate, %asi
and %ccr as laid out in a %tstate register. */
if (regnum == SPARC64_STATE_REGNUM)
return builtin_type (gdbarch)->builtin_int64;
if (regnum == SPARC64_FSR_REGNUM)
return sparc64_fsr_type (gdbarch);
if (regnum == SPARC64_FPRS_REGNUM)
return sparc64_fprs_type (gdbarch);
/* "Although Y is a 64-bit register, its high-order 32 bits are
reserved and always read as 0." */
if (regnum == SPARC64_Y_REGNUM)
return builtin_type (gdbarch)->builtin_int64;
/* Pseudo registers. */
if (regnum >= gdbarch_num_regs (gdbarch))
return sparc64_pseudo_register_type (gdbarch, regnum);
internal_error (_("invalid regnum"));
}
static enum register_status
sparc64_pseudo_register_read (struct gdbarch *gdbarch,
readable_regcache *regcache,
int regnum, gdb_byte *buf)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
enum register_status status;
regnum -= gdbarch_num_regs (gdbarch);
if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
{
regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
status = regcache->raw_read (regnum, buf);
if (status == REG_VALID)
status = regcache->raw_read (regnum + 1, buf + 4);
return status;
}
else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
{
regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
return regcache->raw_read (regnum, buf);
}
else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
{
regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
status = regcache->raw_read (regnum, buf);
if (status == REG_VALID)
status = regcache->raw_read (regnum + 1, buf + 4);
if (status == REG_VALID)
status = regcache->raw_read (regnum + 2, buf + 8);
if (status == REG_VALID)
status = regcache->raw_read (regnum + 3, buf + 12);
return status;
}
else if (regnum >= SPARC64_Q32_REGNUM && regnum <= SPARC64_Q60_REGNUM)
{
regnum = SPARC64_F32_REGNUM + 2 * (regnum - SPARC64_Q32_REGNUM);
status = regcache->raw_read (regnum, buf);
if (status == REG_VALID)
status = regcache->raw_read (regnum + 1, buf + 8);
return status;
}
else if (regnum == SPARC64_CWP_REGNUM
|| regnum == SPARC64_PSTATE_REGNUM
|| regnum == SPARC64_ASI_REGNUM
|| regnum == SPARC64_CCR_REGNUM)
{
ULONGEST state;
status = regcache->raw_read (SPARC64_STATE_REGNUM, &state);
if (status != REG_VALID)
return status;
switch (regnum)
{
case SPARC64_CWP_REGNUM:
state = (state >> 0) & ((1 << 5) - 1);
break;
case SPARC64_PSTATE_REGNUM:
state = (state >> 8) & ((1 << 12) - 1);
break;
case SPARC64_ASI_REGNUM:
state = (state >> 24) & ((1 << 8) - 1);
break;
case SPARC64_CCR_REGNUM:
state = (state >> 32) & ((1 << 8) - 1);
break;
}
store_unsigned_integer (buf, 8, byte_order, state);
}
return REG_VALID;
}
static void
sparc64_pseudo_register_write (struct gdbarch *gdbarch,
struct regcache *regcache,
int regnum, const gdb_byte *buf)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
regnum -= gdbarch_num_regs (gdbarch);
if (regnum >= SPARC64_D0_REGNUM && regnum <= SPARC64_D30_REGNUM)
{
regnum = SPARC_F0_REGNUM + 2 * (regnum - SPARC64_D0_REGNUM);
regcache->raw_write (regnum, buf);
regcache->raw_write (regnum + 1, buf + 4);
}
else if (regnum >= SPARC64_D32_REGNUM && regnum <= SPARC64_D62_REGNUM)
{
regnum = SPARC64_F32_REGNUM + (regnum - SPARC64_D32_REGNUM);
regcache->raw_write (regnum, buf);
}
else if (regnum >= SPARC64_Q0_REGNUM && regnum <= SPARC64_Q28_REGNUM)
{
regnum = SPARC_F0_REGNUM + 4 * (regnum - SPARC64_Q0_REGNUM);
regcache->raw_write (regnum, buf);
regcache->raw_write (regnum + 1, buf + 4);
regcache->raw_write (regnum + 2, buf + 8);