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
/
hppa-tdep.c
3143 lines (2644 loc) · 93.8 KB
/
hppa-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 the HP PA-RISC architecture.
Copyright (C) 1986-2024 Free Software Foundation, Inc.
Contributed by the Center for Software Science at the
University of Utah (pa-gdb-bugs@cs.utah.edu).
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 "bfd.h"
#include "inferior.h"
#include "regcache.h"
#include "completer.h"
#include "osabi.h"
#include "arch-utils.h"
/* For argument passing to the inferior. */
#include "symtab.h"
#include "dis-asm.h"
#include "trad-frame.h"
#include "frame-unwind.h"
#include "frame-base.h"
#include "gdbcore.h"
#include "gdbcmd.h"
#include "gdbtypes.h"
#include "objfiles.h"
#include "hppa-tdep.h"
#include <algorithm>
static bool hppa_debug = false;
/* Some local constants. */
static const int hppa32_num_regs = 128;
static const int hppa64_num_regs = 96;
/* We use the objfile->obj_private pointer for two things:
* 1. An unwind table;
*
* 2. A pointer to any associated shared library object.
*
* #defines are used to help refer to these objects.
*/
/* Info about the unwind table associated with an object file.
* This is hung off of the "objfile->obj_private" pointer, and
* is allocated in the objfile's psymbol obstack. This allows
* us to have unique unwind info for each executable and shared
* library that we are debugging.
*/
struct hppa_unwind_info
{
struct unwind_table_entry *table; /* Pointer to unwind info */
struct unwind_table_entry *cache; /* Pointer to last entry we found */
int last; /* Index of last entry */
};
struct hppa_objfile_private
{
struct hppa_unwind_info *unwind_info = nullptr; /* a pointer */
solib *so_info = nullptr; /* a pointer */
CORE_ADDR dp = 0;
int dummy_call_sequence_reg = 0;
CORE_ADDR dummy_call_sequence_addr = 0;
};
/* hppa-specific object data -- unwind and solib info.
TODO/maybe: think about splitting this into two parts; the unwind data is
common to all hppa targets, but is only used in this file; we can register
that separately and make this static. The solib data is probably hpux-
specific, so we can create a separate extern objfile_data that is registered
by hppa-hpux-tdep.c and shared with pa64solib.c and somsolib.c. */
static const registry<objfile>::key<hppa_objfile_private>
hppa_objfile_priv_data;
/* Get at various relevant fields of an instruction word. */
#define MASK_5 0x1f
#define MASK_11 0x7ff
#define MASK_14 0x3fff
#define MASK_21 0x1fffff
/* Sizes (in bytes) of the native unwind entries. */
#define UNWIND_ENTRY_SIZE 16
#define STUB_UNWIND_ENTRY_SIZE 8
/* Routines to extract various sized constants out of hppa
instructions. */
/* This assumes that no garbage lies outside of the lower bits of
value. */
static int
hppa_sign_extend (unsigned val, unsigned bits)
{
return (int) (val >> (bits - 1) ? (-(1 << bits)) | val : val);
}
/* For many immediate values the sign bit is the low bit! */
static int
hppa_low_hppa_sign_extend (unsigned val, unsigned bits)
{
return (int) ((val & 0x1 ? (-(1 << (bits - 1))) : 0) | val >> 1);
}
/* Extract the bits at positions between FROM and TO, using HP's numbering
(MSB = 0). */
int
hppa_get_field (unsigned word, int from, int to)
{
return ((word) >> (31 - (to)) & ((1 << ((to) - (from) + 1)) - 1));
}
/* Extract the immediate field from a ld{bhw}s instruction. */
int
hppa_extract_5_load (unsigned word)
{
return hppa_low_hppa_sign_extend (word >> 16 & MASK_5, 5);
}
/* Extract the immediate field from a break instruction. */
unsigned
hppa_extract_5r_store (unsigned word)
{
return (word & MASK_5);
}
/* Extract the immediate field from a {sr}sm instruction. */
unsigned
hppa_extract_5R_store (unsigned word)
{
return (word >> 16 & MASK_5);
}
/* Extract a 14 bit immediate field. */
int
hppa_extract_14 (unsigned word)
{
return hppa_low_hppa_sign_extend (word & MASK_14, 14);
}
/* Extract a 21 bit constant. */
int
hppa_extract_21 (unsigned word)
{
int val;
word &= MASK_21;
word <<= 11;
val = hppa_get_field (word, 20, 20);
val <<= 11;
val |= hppa_get_field (word, 9, 19);
val <<= 2;
val |= hppa_get_field (word, 5, 6);
val <<= 5;
val |= hppa_get_field (word, 0, 4);
val <<= 2;
val |= hppa_get_field (word, 7, 8);
return hppa_sign_extend (val, 21) << 11;
}
/* extract a 17 bit constant from branch instructions, returning the
19 bit signed value. */
int
hppa_extract_17 (unsigned word)
{
return hppa_sign_extend (hppa_get_field (word, 19, 28) |
hppa_get_field (word, 29, 29) << 10 |
hppa_get_field (word, 11, 15) << 11 |
(word & 0x1) << 16, 17) << 2;
}
CORE_ADDR
hppa_symbol_address(const char *sym)
{
struct bound_minimal_symbol minsym;
minsym = lookup_minimal_symbol (sym, NULL, NULL);
if (minsym.minsym)
return minsym.value_address ();
else
return (CORE_ADDR)-1;
}
/* Compare the start address for two unwind entries returning 1 if
the first address is larger than the second, -1 if the second is
larger than the first, and zero if they are equal. */
static int
compare_unwind_entries (const void *arg1, const void *arg2)
{
const struct unwind_table_entry *a = (const struct unwind_table_entry *) arg1;
const struct unwind_table_entry *b = (const struct unwind_table_entry *) arg2;
if (a->region_start > b->region_start)
return 1;
else if (a->region_start < b->region_start)
return -1;
else
return 0;
}
static void
record_text_segment_lowaddr (bfd *abfd, asection *section, void *data)
{
if ((section->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
== (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
{
bfd_vma value = section->vma - section->filepos;
CORE_ADDR *low_text_segment_address = (CORE_ADDR *)data;
if (value < *low_text_segment_address)
*low_text_segment_address = value;
}
}
static void
internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
asection *section, unsigned int entries,
size_t size, CORE_ADDR text_offset)
{
/* We will read the unwind entries into temporary memory, then
fill in the actual unwind table. */
if (size > 0)
{
struct gdbarch *gdbarch = objfile->arch ();
hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
unsigned long tmp;
unsigned i;
char *buf = (char *) alloca (size);
CORE_ADDR low_text_segment_address;
/* For ELF targets, then unwinds are supposed to
be segment relative offsets instead of absolute addresses.
Note that when loading a shared library (text_offset != 0) the
unwinds are already relative to the text_offset that will be
passed in. */
if (tdep->is_elf && text_offset == 0)
{
low_text_segment_address = -1;
bfd_map_over_sections (objfile->obfd.get (),
record_text_segment_lowaddr,
&low_text_segment_address);
text_offset = low_text_segment_address;
}
else if (tdep->solib_get_text_base)
{
text_offset = tdep->solib_get_text_base (objfile);
}
bfd_get_section_contents (objfile->obfd.get (), section, buf, 0, size);
/* Now internalize the information being careful to handle host/target
endian issues. */
for (i = 0; i < entries; i++)
{
table[i].region_start = bfd_get_32 (objfile->obfd,
(bfd_byte *) buf);
table[i].region_start += text_offset;
buf += 4;
table[i].region_end = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
table[i].region_end += text_offset;
buf += 4;
tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
buf += 4;
table[i].Cannot_unwind = (tmp >> 31) & 0x1;
table[i].Millicode = (tmp >> 30) & 0x1;
table[i].Millicode_save_sr0 = (tmp >> 29) & 0x1;
table[i].Region_description = (tmp >> 27) & 0x3;
table[i].reserved = (tmp >> 26) & 0x1;
table[i].Entry_SR = (tmp >> 25) & 0x1;
table[i].Entry_FR = (tmp >> 21) & 0xf;
table[i].Entry_GR = (tmp >> 16) & 0x1f;
table[i].Args_stored = (tmp >> 15) & 0x1;
table[i].Variable_Frame = (tmp >> 14) & 0x1;
table[i].Separate_Package_Body = (tmp >> 13) & 0x1;
table[i].Frame_Extension_Millicode = (tmp >> 12) & 0x1;
table[i].Stack_Overflow_Check = (tmp >> 11) & 0x1;
table[i].Two_Instruction_SP_Increment = (tmp >> 10) & 0x1;
table[i].sr4export = (tmp >> 9) & 0x1;
table[i].cxx_info = (tmp >> 8) & 0x1;
table[i].cxx_try_catch = (tmp >> 7) & 0x1;
table[i].sched_entry_seq = (tmp >> 6) & 0x1;
table[i].reserved1 = (tmp >> 5) & 0x1;
table[i].Save_SP = (tmp >> 4) & 0x1;
table[i].Save_RP = (tmp >> 3) & 0x1;
table[i].Save_MRP_in_frame = (tmp >> 2) & 0x1;
table[i].save_r19 = (tmp >> 1) & 0x1;
table[i].Cleanup_defined = tmp & 0x1;
tmp = bfd_get_32 (objfile->obfd, (bfd_byte *) buf);
buf += 4;
table[i].MPE_XL_interrupt_marker = (tmp >> 31) & 0x1;
table[i].HP_UX_interrupt_marker = (tmp >> 30) & 0x1;
table[i].Large_frame = (tmp >> 29) & 0x1;
table[i].alloca_frame = (tmp >> 28) & 0x1;
table[i].reserved2 = (tmp >> 27) & 0x1;
table[i].Total_frame_size = tmp & 0x7ffffff;
/* Stub unwinds are handled elsewhere. */
table[i].stub_unwind.stub_type = 0;
table[i].stub_unwind.padding = 0;
}
}
}
/* Read in the backtrace information stored in the `$UNWIND_START$' section of
the object file. This info is used mainly by find_unwind_entry() to find
out the stack frame size and frame pointer used by procedures. We put
everything on the psymbol obstack in the objfile so that it automatically
gets freed when the objfile is destroyed. */
static void
read_unwind_info (struct objfile *objfile)
{
asection *unwind_sec, *stub_unwind_sec;
size_t unwind_size, stub_unwind_size, total_size;
unsigned index, unwind_entries;
unsigned stub_entries, total_entries;
CORE_ADDR text_offset;
struct hppa_unwind_info *ui;
struct hppa_objfile_private *obj_private;
text_offset = objfile->text_section_offset ();
ui = (struct hppa_unwind_info *) obstack_alloc (&objfile->objfile_obstack,
sizeof (struct hppa_unwind_info));
ui->table = NULL;
ui->cache = NULL;
ui->last = -1;
/* For reasons unknown the HP PA64 tools generate multiple unwinder
sections in a single executable. So we just iterate over every
section in the BFD looking for unwinder sections instead of trying
to do a lookup with bfd_get_section_by_name.
First determine the total size of the unwind tables so that we
can allocate memory in a nice big hunk. */
total_entries = 0;
for (unwind_sec = objfile->obfd->sections;
unwind_sec;
unwind_sec = unwind_sec->next)
{
if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
|| strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
{
unwind_size = bfd_section_size (unwind_sec);
unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
total_entries += unwind_entries;
}
}
/* Now compute the size of the stub unwinds. Note the ELF tools do not
use stub unwinds at the current time. */
stub_unwind_sec = bfd_get_section_by_name (objfile->obfd.get (),
"$UNWIND_END$");
if (stub_unwind_sec)
{
stub_unwind_size = bfd_section_size (stub_unwind_sec);
stub_entries = stub_unwind_size / STUB_UNWIND_ENTRY_SIZE;
}
else
{
stub_unwind_size = 0;
stub_entries = 0;
}
/* Compute total number of unwind entries and their total size. */
total_entries += stub_entries;
total_size = total_entries * sizeof (struct unwind_table_entry);
/* Allocate memory for the unwind table. */
ui->table = (struct unwind_table_entry *)
obstack_alloc (&objfile->objfile_obstack, total_size);
ui->last = total_entries - 1;
/* Now read in each unwind section and internalize the standard unwind
entries. */
index = 0;
for (unwind_sec = objfile->obfd->sections;
unwind_sec;
unwind_sec = unwind_sec->next)
{
if (strcmp (unwind_sec->name, "$UNWIND_START$") == 0
|| strcmp (unwind_sec->name, ".PARISC.unwind") == 0)
{
unwind_size = bfd_section_size (unwind_sec);
unwind_entries = unwind_size / UNWIND_ENTRY_SIZE;
internalize_unwinds (objfile, &ui->table[index], unwind_sec,
unwind_entries, unwind_size, text_offset);
index += unwind_entries;
}
}
/* Now read in and internalize the stub unwind entries. */
if (stub_unwind_size > 0)
{
unsigned int i;
char *buf = (char *) alloca (stub_unwind_size);
/* Read in the stub unwind entries. */
bfd_get_section_contents (objfile->obfd.get (), stub_unwind_sec, buf,
0, stub_unwind_size);
/* Now convert them into regular unwind entries. */
for (i = 0; i < stub_entries; i++, index++)
{
/* Clear out the next unwind entry. */
memset (&ui->table[index], 0, sizeof (struct unwind_table_entry));
/* Convert offset & size into region_start and region_end.
Stuff away the stub type into "reserved" fields. */
ui->table[index].region_start = bfd_get_32 (objfile->obfd,
(bfd_byte *) buf);
ui->table[index].region_start += text_offset;
buf += 4;
ui->table[index].stub_unwind.stub_type = bfd_get_8 (objfile->obfd,
(bfd_byte *) buf);
buf += 2;
ui->table[index].region_end
= ui->table[index].region_start + 4 *
(bfd_get_16 (objfile->obfd, (bfd_byte *) buf) - 1);
buf += 2;
}
}
/* Unwind table needs to be kept sorted. */
qsort (ui->table, total_entries, sizeof (struct unwind_table_entry),
compare_unwind_entries);
/* Keep a pointer to the unwind information. */
obj_private = hppa_objfile_priv_data.get (objfile);
if (obj_private == NULL)
obj_private = hppa_objfile_priv_data.emplace (objfile);
obj_private->unwind_info = ui;
}
/* Lookup the unwind (stack backtrace) info for the given PC. We search all
of the objfiles seeking the unwind table entry for this PC. Each objfile
contains a sorted list of struct unwind_table_entry. Since we do a binary
search of the unwind tables, we depend upon them to be sorted. */
struct unwind_table_entry *
find_unwind_entry (CORE_ADDR pc)
{
int first, middle, last;
if (hppa_debug)
gdb_printf (gdb_stdlog, "{ find_unwind_entry %s -> ",
hex_string (pc));
/* A function at address 0? Not in HP-UX! */
if (pc == (CORE_ADDR) 0)
{
if (hppa_debug)
gdb_printf (gdb_stdlog, "NULL }\n");
return NULL;
}
for (objfile *objfile : current_program_space->objfiles ())
{
struct hppa_unwind_info *ui;
ui = NULL;
struct hppa_objfile_private *priv = hppa_objfile_priv_data.get (objfile);
if (priv)
ui = priv->unwind_info;
if (!ui)
{
read_unwind_info (objfile);
priv = hppa_objfile_priv_data.get (objfile);
if (priv == NULL)
error (_("Internal error reading unwind information."));
ui = priv->unwind_info;
}
/* First, check the cache. */
if (ui->cache
&& pc >= ui->cache->region_start
&& pc <= ui->cache->region_end)
{
if (hppa_debug)
gdb_printf (gdb_stdlog, "%s (cached) }\n",
hex_string ((uintptr_t) ui->cache));
return ui->cache;
}
/* Not in the cache, do a binary search. */
first = 0;
last = ui->last;
while (first <= last)
{
middle = (first + last) / 2;
if (pc >= ui->table[middle].region_start
&& pc <= ui->table[middle].region_end)
{
ui->cache = &ui->table[middle];
if (hppa_debug)
gdb_printf (gdb_stdlog, "%s }\n",
hex_string ((uintptr_t) ui->cache));
return &ui->table[middle];
}
if (pc < ui->table[middle].region_start)
last = middle - 1;
else
first = middle + 1;
}
}
if (hppa_debug)
gdb_printf (gdb_stdlog, "NULL (not found) }\n");
return NULL;
}
/* Implement the stack_frame_destroyed_p gdbarch method.
The epilogue is defined here as the area either on the `bv' instruction
itself or an instruction which destroys the function's stack frame.
We do not assume that the epilogue is at the end of a function as we can
also have return sequences in the middle of a function. */
static int
hppa_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
unsigned long status;
unsigned int inst;
gdb_byte buf[4];
status = target_read_memory (pc, buf, 4);
if (status != 0)
return 0;
inst = extract_unsigned_integer (buf, 4, byte_order);
/* The most common way to perform a stack adjustment ldo X(sp),sp
We are destroying a stack frame if the offset is negative. */
if ((inst & 0xffffc000) == 0x37de0000
&& hppa_extract_14 (inst) < 0)
return 1;
/* ldw,mb D(sp),X or ldd,mb D(sp),X */
if (((inst & 0x0fc010e0) == 0x0fc010e0
|| (inst & 0x0fc010e0) == 0x0fc010e0)
&& hppa_extract_14 (inst) < 0)
return 1;
/* bv %r0(%rp) or bv,n %r0(%rp) */
if (inst == 0xe840c000 || inst == 0xe840c002)
return 1;
return 0;
}
constexpr gdb_byte hppa_break_insn[] = {0x00, 0x01, 0x00, 0x04};
typedef BP_MANIPULATION (hppa_break_insn) hppa_breakpoint;
/* Return the name of a register. */
static const char *
hppa32_register_name (struct gdbarch *gdbarch, int i)
{
static const char *names[] = {
"flags", "r1", "rp", "r3",
"r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11",
"r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19",
"r20", "r21", "r22", "r23",
"r24", "r25", "r26", "dp",
"ret0", "ret1", "sp", "r31",
"sar", "pcoqh", "pcsqh", "pcoqt",
"pcsqt", "eiem", "iir", "isr",
"ior", "ipsw", "goto", "sr4",
"sr0", "sr1", "sr2", "sr3",
"sr5", "sr6", "sr7", "cr0",
"cr8", "cr9", "ccr", "cr12",
"cr13", "cr24", "cr25", "cr26",
"mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
"fpsr", "fpe1", "fpe2", "fpe3",
"fpe4", "fpe5", "fpe6", "fpe7",
"fr4", "fr4R", "fr5", "fr5R",
"fr6", "fr6R", "fr7", "fr7R",
"fr8", "fr8R", "fr9", "fr9R",
"fr10", "fr10R", "fr11", "fr11R",
"fr12", "fr12R", "fr13", "fr13R",
"fr14", "fr14R", "fr15", "fr15R",
"fr16", "fr16R", "fr17", "fr17R",
"fr18", "fr18R", "fr19", "fr19R",
"fr20", "fr20R", "fr21", "fr21R",
"fr22", "fr22R", "fr23", "fr23R",
"fr24", "fr24R", "fr25", "fr25R",
"fr26", "fr26R", "fr27", "fr27R",
"fr28", "fr28R", "fr29", "fr29R",
"fr30", "fr30R", "fr31", "fr31R"
};
static_assert (ARRAY_SIZE (names) == hppa32_num_regs);
return names[i];
}
static const char *
hppa64_register_name (struct gdbarch *gdbarch, int i)
{
static const char *names[] = {
"flags", "r1", "rp", "r3",
"r4", "r5", "r6", "r7",
"r8", "r9", "r10", "r11",
"r12", "r13", "r14", "r15",
"r16", "r17", "r18", "r19",
"r20", "r21", "r22", "r23",
"r24", "r25", "r26", "dp",
"ret0", "ret1", "sp", "r31",
"sar", "pcoqh", "pcsqh", "pcoqt",
"pcsqt", "eiem", "iir", "isr",
"ior", "ipsw", "goto", "sr4",
"sr0", "sr1", "sr2", "sr3",
"sr5", "sr6", "sr7", "cr0",
"cr8", "cr9", "ccr", "cr12",
"cr13", "cr24", "cr25", "cr26",
"mpsfu_high","mpsfu_low","mpsfu_ovflo","pad",
"fpsr", "fpe1", "fpe2", "fpe3",
"fr4", "fr5", "fr6", "fr7",
"fr8", "fr9", "fr10", "fr11",
"fr12", "fr13", "fr14", "fr15",
"fr16", "fr17", "fr18", "fr19",
"fr20", "fr21", "fr22", "fr23",
"fr24", "fr25", "fr26", "fr27",
"fr28", "fr29", "fr30", "fr31"
};
static_assert (ARRAY_SIZE (names) == hppa64_num_regs);
return names[i];
}
/* Map dwarf DBX register numbers to GDB register numbers. */
static int
hppa64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
{
/* The general registers and the sar are the same in both sets. */
if (reg >= 0 && reg <= 32)
return reg;
/* fr4-fr31 are mapped from 72 in steps of 2. */
if (reg >= 72 && reg < 72 + 28 * 2 && !(reg & 1))
return HPPA64_FP4_REGNUM + (reg - 72) / 2;
return -1;
}
/* This function pushes a stack frame with arguments as part of the
inferior function calling mechanism.
This is the version of the function for the 32-bit PA machines, in
which later arguments appear at lower addresses. (The stack always
grows towards higher addresses.)
We simply allocate the appropriate amount of stack space and put
arguments into their proper slots. */
static CORE_ADDR
hppa32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
struct regcache *regcache, CORE_ADDR bp_addr,
int nargs, struct value **args, CORE_ADDR sp,
function_call_return_method return_method,
CORE_ADDR struct_addr)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
/* Stack base address at which any pass-by-reference parameters are
stored. */
CORE_ADDR struct_end = 0;
/* Stack base address at which the first parameter is stored. */
CORE_ADDR param_end = 0;
/* Two passes. First pass computes the location of everything,
second pass writes the bytes out. */
int write_pass;
/* Global pointer (r19) of the function we are trying to call. */
CORE_ADDR gp;
hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
for (write_pass = 0; write_pass < 2; write_pass++)
{
CORE_ADDR struct_ptr = 0;
/* The first parameter goes into sp-36, each stack slot is 4-bytes.
struct_ptr is adjusted for each argument below, so the first
argument will end up at sp-36. */
CORE_ADDR param_ptr = 32;
int i;
int small_struct = 0;
for (i = 0; i < nargs; i++)
{
struct value *arg = args[i];
struct type *type = check_typedef (arg->type ());
/* The corresponding parameter that is pushed onto the
stack, and [possibly] passed in a register. */
gdb_byte param_val[8];
int param_len;
memset (param_val, 0, sizeof param_val);
if (type->length () > 8)
{
/* Large parameter, pass by reference. Store the value
in "struct" area and then pass its address. */
param_len = 4;
struct_ptr += align_up (type->length (), 8);
if (write_pass)
write_memory (struct_end - struct_ptr,
arg->contents ().data (), type->length ());
store_unsigned_integer (param_val, 4, byte_order,
struct_end - struct_ptr);
}
else if (type->code () == TYPE_CODE_INT
|| type->code () == TYPE_CODE_ENUM)
{
/* Integer value store, right aligned. "unpack_long"
takes care of any sign-extension problems. */
param_len = align_up (type->length (), 4);
store_unsigned_integer
(param_val, param_len, byte_order,
unpack_long (type, arg->contents ().data ()));
}
else if (type->code () == TYPE_CODE_FLT)
{
/* Floating point value store, right aligned. */
param_len = align_up (type->length (), 4);
memcpy (param_val, arg->contents ().data (), param_len);
}
else
{
param_len = align_up (type->length (), 4);
/* Small struct value are stored right-aligned. */
memcpy (param_val + param_len - type->length (),
arg->contents ().data (), type->length ());
/* Structures of size 5, 6 and 7 bytes are special in that
the higher-ordered word is stored in the lower-ordered
argument, and even though it is a 8-byte quantity the
registers need not be 8-byte aligned. */
if (param_len > 4 && param_len < 8)
small_struct = 1;
}
param_ptr += param_len;
if (param_len == 8 && !small_struct)
param_ptr = align_up (param_ptr, 8);
/* First 4 non-FP arguments are passed in gr26-gr23.
First 4 32-bit FP arguments are passed in fr4L-fr7L.
First 2 64-bit FP arguments are passed in fr5 and fr7.
The rest go on the stack, starting at sp-36, towards lower
addresses. 8-byte arguments must be aligned to a 8-byte
stack boundary. */
if (write_pass)
{
write_memory (param_end - param_ptr, param_val, param_len);
/* There are some cases when we don't know the type
expected by the callee (e.g. for variadic functions), so
pass the parameters in both general and fp regs. */
if (param_ptr <= 48)
{
int grreg = 26 - (param_ptr - 36) / 4;
int fpLreg = 72 + (param_ptr - 36) / 4 * 2;
int fpreg = 74 + (param_ptr - 32) / 8 * 4;
regcache->cooked_write (grreg, param_val);
regcache->cooked_write (fpLreg, param_val);
if (param_len > 4)
{
regcache->cooked_write (grreg + 1, param_val + 4);
regcache->cooked_write (fpreg, param_val);
regcache->cooked_write (fpreg + 1, param_val + 4);
}
}
}
}
/* Update the various stack pointers. */
if (!write_pass)
{
struct_end = sp + align_up (struct_ptr, 64);
/* PARAM_PTR already accounts for all the arguments passed
by the user. However, the ABI mandates minimum stack
space allocations for outgoing arguments. The ABI also
mandates minimum stack alignments which we must
preserve. */
param_end = struct_end + align_up (param_ptr, 64);
}
}
/* If a structure has to be returned, set up register 28 to hold its
address. */
if (return_method == return_method_struct)
regcache_cooked_write_unsigned (regcache, 28, struct_addr);
gp = tdep->find_global_pointer (gdbarch, function);
if (gp != 0)
regcache_cooked_write_unsigned (regcache, 19, gp);
/* Set the return address. */
if (!gdbarch_push_dummy_code_p (gdbarch))
regcache_cooked_write_unsigned (regcache, HPPA_RP_REGNUM, bp_addr);
/* Update the Stack Pointer. */
regcache_cooked_write_unsigned (regcache, HPPA_SP_REGNUM, param_end);
return param_end;
}
/* The 64-bit PA-RISC calling conventions are documented in "64-Bit
Runtime Architecture for PA-RISC 2.0", which is distributed as part
as of the HP-UX Software Transition Kit (STK). This implementation
is based on version 3.3, dated October 6, 1997. */
/* Check whether TYPE is an "Integral or Pointer Scalar Type". */
static int
hppa64_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 ();
return (len == 1 || len == 2 || len == 4 || len == 8);
}
case TYPE_CODE_PTR:
case TYPE_CODE_REF:
case TYPE_CODE_RVALUE_REF:
return (type->length () == 8);
default:
break;
}
return 0;
}
/* Check whether TYPE is a "Floating Scalar Type". */
static int
hppa64_floating_p (const struct type *type)
{
switch (type->code ())
{
case TYPE_CODE_FLT:
{
int len = type->length ();
return (len == 4 || len == 8 || len == 16);
}
default:
break;
}
return 0;
}
/* If CODE points to a function entry address, try to look up the corresponding
function descriptor and return its address instead. If CODE is not a
function entry address, then just return it unchanged. */
static CORE_ADDR
hppa64_convert_code_addr_to_fptr (struct gdbarch *gdbarch, CORE_ADDR code)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
struct obj_section *sec;
sec = find_pc_section (code);
if (!sec)
return code;
/* If CODE is in a data section, assume it's already a fptr. */
if (!(sec->the_bfd_section->flags & SEC_CODE))
return code;
for (obj_section *opd : sec->objfile->sections ())
{
if (strcmp (opd->the_bfd_section->name, ".opd") == 0)
{
for (CORE_ADDR addr = opd->addr ();
addr < opd->endaddr ();
addr += 2 * 8)
{
ULONGEST opdaddr;
gdb_byte tmp[8];
if (target_read_memory (addr, tmp, sizeof (tmp)))
break;
opdaddr = extract_unsigned_integer (tmp, sizeof (tmp), byte_order);
if (opdaddr == code)
return addr - 16;
}
}
}
return code;
}
static CORE_ADDR
hppa64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
struct regcache *regcache, CORE_ADDR bp_addr,
int nargs, struct value **args, CORE_ADDR sp,
function_call_return_method return_method,
CORE_ADDR struct_addr)
{
hppa_gdbarch_tdep *tdep = gdbarch_tdep<hppa_gdbarch_tdep> (gdbarch);
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int i, offset = 0;
CORE_ADDR gp;
/* "The outgoing parameter area [...] must be aligned at a 16-byte
boundary." */
sp = align_up (sp, 16);
for (i = 0; i < nargs; i++)
{
struct value *arg = args[i];
struct type *type = arg->type ();
int len = type->length ();
const bfd_byte *valbuf;
bfd_byte fptrbuf[8];
int regnum;
/* "Each parameter begins on a 64-bit (8-byte) boundary." */
offset = align_up (offset, 8);
if (hppa64_integral_or_pointer_p (type))
{
/* "Integral scalar parameters smaller than 64 bits are
padded on the left (i.e., the value is in the
least-significant bits of the 64-bit storage unit, and
the high-order bits are undefined)." Therefore we can
safely sign-extend them. */
if (len < 8)
{
arg = value_cast (builtin_type (gdbarch)->builtin_int64, arg);
len = 8;
}
}
else if (hppa64_floating_p (type))
{
if (len > 8)
{
/* "Quad-precision (128-bit) floating-point scalar
parameters are aligned on a 16-byte boundary." */
offset = align_up (offset, 16);
/* "Double-extended- and quad-precision floating-point
parameters within the first 64 bytes of the parameter
list are always passed in general registers." */
}