forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxtensa-tdep.c
3311 lines (2787 loc) · 99.9 KB
/
xtensa-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 Xtensa port of GDB, the GNU debugger.
Copyright (C) 2003-2015 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 "frame.h"
#include "solib-svr4.h"
#include "symtab.h"
#include "symfile.h"
#include "objfiles.h"
#include "gdbtypes.h"
#include "gdbcore.h"
#include "value.h"
#include "dis-asm.h"
#include "inferior.h"
#include "osabi.h"
#include "floatformat.h"
#include "regcache.h"
#include "reggroups.h"
#include "regset.h"
#include "dummy-frame.h"
#include "dwarf2.h"
#include "dwarf2-frame.h"
#include "dwarf2loc.h"
#include "frame-base.h"
#include "frame-unwind.h"
#include "arch-utils.h"
#include "gdbarch.h"
#include "remote.h"
#include "serial.h"
#include "command.h"
#include "gdbcmd.h"
#include "xtensa-isa.h"
#include "xtensa-tdep.h"
#include "xtensa-config.h"
static unsigned int xtensa_debug_level = 0;
#define DEBUGWARN(args...) \
if (xtensa_debug_level > 0) \
fprintf_unfiltered (gdb_stdlog, "(warn ) " args)
#define DEBUGINFO(args...) \
if (xtensa_debug_level > 1) \
fprintf_unfiltered (gdb_stdlog, "(info ) " args)
#define DEBUGTRACE(args...) \
if (xtensa_debug_level > 2) \
fprintf_unfiltered (gdb_stdlog, "(trace) " args)
#define DEBUGVERB(args...) \
if (xtensa_debug_level > 3) \
fprintf_unfiltered (gdb_stdlog, "(verb ) " args)
/* According to the ABI, the SP must be aligned to 16-byte boundaries. */
#define SP_ALIGNMENT 16
/* On Windowed ABI, we use a6 through a11 for passing arguments
to a function called by GDB because CALL4 is used. */
#define ARGS_NUM_REGS 6
#define REGISTER_SIZE 4
/* Extract the call size from the return address or PS register. */
#define PS_CALLINC_SHIFT 16
#define PS_CALLINC_MASK 0x00030000
#define CALLINC(ps) (((ps) & PS_CALLINC_MASK) >> PS_CALLINC_SHIFT)
#define WINSIZE(ra) (4 * (( (ra) >> 30) & 0x3))
/* On TX, hardware can be configured without Exception Option.
There is no PS register in this case. Inside XT-GDB, let us treat
it as a virtual read-only register always holding the same value. */
#define TX_PS 0x20
/* ABI-independent macros. */
#define ARG_NOF(gdbarch) \
(gdbarch_tdep (gdbarch)->call_abi \
== CallAbiCall0Only ? C0_NARGS : (ARGS_NUM_REGS))
#define ARG_1ST(gdbarch) \
(gdbarch_tdep (gdbarch)->call_abi == CallAbiCall0Only \
? (gdbarch_tdep (gdbarch)->a0_base + C0_ARGS) \
: (gdbarch_tdep (gdbarch)->a0_base + 6))
/* XTENSA_IS_ENTRY tests whether the first byte of an instruction
indicates that the instruction is an ENTRY instruction. */
#define XTENSA_IS_ENTRY(gdbarch, op1) \
((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) \
? ((op1) == 0x6c) : ((op1) == 0x36))
#define XTENSA_ENTRY_LENGTH 3
/* windowing_enabled() returns true, if windowing is enabled.
WOE must be set to 1; EXCM to 0.
Note: We assume that EXCM is always 0 for XEA1. */
#define PS_WOE (1<<18)
#define PS_EXC (1<<4)
static int
windowing_enabled (struct gdbarch *gdbarch, unsigned int ps)
{
/* If we know CALL0 ABI is set explicitly, say it is Call0. */
if (gdbarch_tdep (gdbarch)->call_abi == CallAbiCall0Only)
return 0;
return ((ps & PS_EXC) == 0 && (ps & PS_WOE) != 0);
}
/* Convert a live A-register number to the corresponding AR-register
number. */
static int
arreg_number (struct gdbarch *gdbarch, int a_regnum, ULONGEST wb)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
int arreg;
arreg = a_regnum - tdep->a0_base;
arreg += (wb & ((tdep->num_aregs - 1) >> 2)) << WB_SHIFT;
arreg &= tdep->num_aregs - 1;
return arreg + tdep->ar_base;
}
/* Convert a live AR-register number to the corresponding A-register order
number in a range [0..15]. Return -1, if AR_REGNUM is out of WB window. */
static int
areg_number (struct gdbarch *gdbarch, int ar_regnum, unsigned int wb)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
int areg;
areg = ar_regnum - tdep->ar_base;
if (areg < 0 || areg >= tdep->num_aregs)
return -1;
areg = (areg - wb * 4) & (tdep->num_aregs - 1);
return (areg > 15) ? -1 : areg;
}
/* Read Xtensa register directly from the hardware. */
static unsigned long
xtensa_read_register (int regnum)
{
ULONGEST value;
regcache_raw_read_unsigned (get_current_regcache (), regnum, &value);
return (unsigned long) value;
}
/* Write Xtensa register directly to the hardware. */
static void
xtensa_write_register (int regnum, ULONGEST value)
{
regcache_raw_write_unsigned (get_current_regcache (), regnum, value);
}
/* Return the window size of the previous call to the function from which we
have just returned.
This function is used to extract the return value after a called function
has returned to the caller. On Xtensa, the register that holds the return
value (from the perspective of the caller) depends on what call
instruction was used. For now, we are assuming that the call instruction
precedes the current address, so we simply analyze the call instruction.
If we are in a dummy frame, we simply return 4 as we used a 'pseudo-call4'
method to call the inferior function. */
static int
extract_call_winsize (struct gdbarch *gdbarch, CORE_ADDR pc)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
int winsize = 4;
int insn;
gdb_byte buf[4];
DEBUGTRACE ("extract_call_winsize (pc = 0x%08x)\n", (int) pc);
/* Read the previous instruction (should be a call[x]{4|8|12}. */
read_memory (pc-3, buf, 3);
insn = extract_unsigned_integer (buf, 3, byte_order);
/* Decode call instruction:
Little Endian
call{0,4,8,12} OFFSET || {00,01,10,11} || 0101
callx{0,4,8,12} OFFSET || 11 || {00,01,10,11} || 0000
Big Endian
call{0,4,8,12} 0101 || {00,01,10,11} || OFFSET
callx{0,4,8,12} 0000 || {00,01,10,11} || 11 || OFFSET. */
if (byte_order == BFD_ENDIAN_LITTLE)
{
if (((insn & 0xf) == 0x5) || ((insn & 0xcf) == 0xc0))
winsize = (insn & 0x30) >> 2; /* 0, 4, 8, 12. */
}
else
{
if (((insn >> 20) == 0x5) || (((insn >> 16) & 0xf3) == 0x03))
winsize = (insn >> 16) & 0xc; /* 0, 4, 8, 12. */
}
return winsize;
}
/* REGISTER INFORMATION */
/* Find register by name. */
static int
xtensa_find_register_by_name (struct gdbarch *gdbarch, char *name)
{
int i;
for (i = 0; i < gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch);
i++)
if (strcasecmp (gdbarch_tdep (gdbarch)->regmap[i].name, name) == 0)
return i;
return -1;
}
/* Returns the name of a register. */
static const char *
xtensa_register_name (struct gdbarch *gdbarch, int regnum)
{
/* Return the name stored in the register map. */
if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch))
return gdbarch_tdep (gdbarch)->regmap[regnum].name;
internal_error (__FILE__, __LINE__, _("invalid register %d"), regnum);
return 0;
}
/* Return the type of a register. Create a new type, if necessary. */
static struct type *
xtensa_register_type (struct gdbarch *gdbarch, int regnum)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
/* Return signed integer for ARx and Ax registers. */
if ((regnum >= tdep->ar_base
&& regnum < tdep->ar_base + tdep->num_aregs)
|| (regnum >= tdep->a0_base
&& regnum < tdep->a0_base + 16))
return builtin_type (gdbarch)->builtin_int;
if (regnum == gdbarch_pc_regnum (gdbarch)
|| regnum == tdep->a0_base + 1)
return builtin_type (gdbarch)->builtin_data_ptr;
/* Return the stored type for all other registers. */
else if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch))
{
xtensa_register_t* reg = &tdep->regmap[regnum];
/* Set ctype for this register (only the first time). */
if (reg->ctype == 0)
{
struct ctype_cache *tp;
int size = reg->byte_size;
/* We always use the memory representation,
even if the register width is smaller. */
switch (size)
{
case 1:
reg->ctype = builtin_type (gdbarch)->builtin_uint8;
break;
case 2:
reg->ctype = builtin_type (gdbarch)->builtin_uint16;
break;
case 4:
reg->ctype = builtin_type (gdbarch)->builtin_uint32;
break;
case 8:
reg->ctype = builtin_type (gdbarch)->builtin_uint64;
break;
case 16:
reg->ctype = builtin_type (gdbarch)->builtin_uint128;
break;
default:
for (tp = tdep->type_entries; tp != NULL; tp = tp->next)
if (tp->size == size)
break;
if (tp == NULL)
{
char *name = xstrprintf ("int%d", size * 8);
tp = XNEW (struct ctype_cache);
tp->next = tdep->type_entries;
tdep->type_entries = tp;
tp->size = size;
tp->virtual_type
= arch_integer_type (gdbarch, size * 8, 1, name);
xfree (name);
}
reg->ctype = tp->virtual_type;
}
}
return reg->ctype;
}
internal_error (__FILE__, __LINE__, _("invalid register number %d"), regnum);
return 0;
}
/* Return the 'local' register number for stubs, dwarf2, etc.
The debugging information enumerates registers starting from 0 for A0
to n for An. So, we only have to add the base number for A0. */
static int
xtensa_reg_to_regnum (struct gdbarch *gdbarch, int regnum)
{
int i;
if (regnum >= 0 && regnum < 16)
return gdbarch_tdep (gdbarch)->a0_base + regnum;
for (i = 0;
i < gdbarch_num_regs (gdbarch) + gdbarch_num_pseudo_regs (gdbarch);
i++)
if (regnum == gdbarch_tdep (gdbarch)->regmap[i].target_number)
return i;
internal_error (__FILE__, __LINE__,
_("invalid dwarf/stabs register number %d"), regnum);
return 0;
}
/* Write the bits of a masked register to the various registers.
Only the masked areas of these registers are modified; the other
fields are untouched. The size of masked registers is always less
than or equal to 32 bits. */
static void
xtensa_register_write_masked (struct regcache *regcache,
xtensa_register_t *reg, const gdb_byte *buffer)
{
unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
const xtensa_mask_t *mask = reg->mask;
int shift = 0; /* Shift for next mask (mod 32). */
int start, size; /* Start bit and size of current mask. */
unsigned int *ptr = value;
unsigned int regval, m, mem = 0;
int bytesize = reg->byte_size;
int bitsize = bytesize * 8;
int i, r;
DEBUGTRACE ("xtensa_register_write_masked ()\n");
/* Copy the masked register to host byte-order. */
if (gdbarch_byte_order (get_regcache_arch (regcache)) == BFD_ENDIAN_BIG)
for (i = 0; i < bytesize; i++)
{
mem >>= 8;
mem |= (buffer[bytesize - i - 1] << 24);
if ((i & 3) == 3)
*ptr++ = mem;
}
else
for (i = 0; i < bytesize; i++)
{
mem >>= 8;
mem |= (buffer[i] << 24);
if ((i & 3) == 3)
*ptr++ = mem;
}
/* We might have to shift the final value:
bytesize & 3 == 0 -> nothing to do, we use the full 32 bits,
bytesize & 3 == x -> shift (4-x) * 8. */
*ptr = mem >> (((0 - bytesize) & 3) * 8);
ptr = value;
mem = *ptr;
/* Write the bits to the masked areas of the other registers. */
for (i = 0; i < mask->count; i++)
{
start = mask->mask[i].bit_start;
size = mask->mask[i].bit_size;
regval = mem >> shift;
if ((shift += size) > bitsize)
error (_("size of all masks is larger than the register"));
if (shift >= 32)
{
mem = *(++ptr);
shift -= 32;
bitsize -= 32;
if (shift > 0)
regval |= mem << (size - shift);
}
/* Make sure we have a valid register. */
r = mask->mask[i].reg_num;
if (r >= 0 && size > 0)
{
/* Don't overwrite the unmasked areas. */
ULONGEST old_val;
regcache_cooked_read_unsigned (regcache, r, &old_val);
m = 0xffffffff >> (32 - size) << start;
regval <<= start;
regval = (regval & m) | (old_val & ~m);
regcache_cooked_write_unsigned (regcache, r, regval);
}
}
}
/* Read a tie state or mapped registers. Read the masked areas
of the registers and assemble them into a single value. */
static enum register_status
xtensa_register_read_masked (struct regcache *regcache,
xtensa_register_t *reg, gdb_byte *buffer)
{
unsigned int value[(MAX_REGISTER_SIZE + 3) / 4];
const xtensa_mask_t *mask = reg->mask;
int shift = 0;
int start, size;
unsigned int *ptr = value;
unsigned int regval, mem = 0;
int bytesize = reg->byte_size;
int bitsize = bytesize * 8;
int i;
DEBUGTRACE ("xtensa_register_read_masked (reg \"%s\", ...)\n",
reg->name == 0 ? "" : reg->name);
/* Assemble the register from the masked areas of other registers. */
for (i = 0; i < mask->count; i++)
{
int r = mask->mask[i].reg_num;
if (r >= 0)
{
enum register_status status;
ULONGEST val;
status = regcache_cooked_read_unsigned (regcache, r, &val);
if (status != REG_VALID)
return status;
regval = (unsigned int) val;
}
else
regval = 0;
start = mask->mask[i].bit_start;
size = mask->mask[i].bit_size;
regval >>= start;
if (size < 32)
regval &= (0xffffffff >> (32 - size));
mem |= regval << shift;
if ((shift += size) > bitsize)
error (_("size of all masks is larger than the register"));
if (shift >= 32)
{
*ptr++ = mem;
bitsize -= 32;
shift -= 32;
if (shift == 0)
mem = 0;
else
mem = regval >> (size - shift);
}
}
if (shift > 0)
*ptr = mem;
/* Copy value to target byte order. */
ptr = value;
mem = *ptr;
if (gdbarch_byte_order (get_regcache_arch (regcache)) == BFD_ENDIAN_BIG)
for (i = 0; i < bytesize; i++)
{
if ((i & 3) == 0)
mem = *ptr++;
buffer[bytesize - i - 1] = mem & 0xff;
mem >>= 8;
}
else
for (i = 0; i < bytesize; i++)
{
if ((i & 3) == 0)
mem = *ptr++;
buffer[i] = mem & 0xff;
mem >>= 8;
}
return REG_VALID;
}
/* Read pseudo registers. */
static enum register_status
xtensa_pseudo_register_read (struct gdbarch *gdbarch,
struct regcache *regcache,
int regnum,
gdb_byte *buffer)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
DEBUGTRACE ("xtensa_pseudo_register_read (... regnum = %d (%s) ...)\n",
regnum, xtensa_register_name (gdbarch, regnum));
/* Read aliases a0..a15, if this is a Windowed ABI. */
if (gdbarch_tdep (gdbarch)->isa_use_windowed_registers
&& (regnum >= gdbarch_tdep (gdbarch)->a0_base)
&& (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
{
gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
enum register_status status;
status = regcache_raw_read (regcache,
gdbarch_tdep (gdbarch)->wb_regnum,
buf);
if (status != REG_VALID)
return status;
regnum = arreg_number (gdbarch, regnum,
extract_unsigned_integer (buf, 4, byte_order));
}
/* We can always read non-pseudo registers. */
if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
return regcache_raw_read (regcache, regnum, buffer);
/* We have to find out how to deal with priveleged registers.
Let's treat them as pseudo-registers, but we cannot read/write them. */
else if (regnum < gdbarch_tdep (gdbarch)->a0_base)
{
buffer[0] = (gdb_byte)0;
buffer[1] = (gdb_byte)0;
buffer[2] = (gdb_byte)0;
buffer[3] = (gdb_byte)0;
return REG_VALID;
}
/* Pseudo registers. */
else if (regnum >= 0
&& regnum < gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch))
{
xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
xtensa_register_type_t type = reg->type;
int flags = gdbarch_tdep (gdbarch)->target_flags;
/* We cannot read Unknown or Unmapped registers. */
if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
{
if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
{
warning (_("cannot read register %s"),
xtensa_register_name (gdbarch, regnum));
return REG_VALID;
}
}
/* Some targets cannot read TIE register files. */
else if (type == xtRegisterTypeTieRegfile)
{
/* Use 'fetch' to get register? */
if (flags & xtTargetFlagsUseFetchStore)
{
warning (_("cannot read register"));
return REG_VALID;
}
/* On some targets (esp. simulators), we can always read the reg. */
else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
{
warning (_("cannot read register"));
return REG_VALID;
}
}
/* We can always read mapped registers. */
else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
return xtensa_register_read_masked (regcache, reg, buffer);
/* Assume that we can read the register. */
return regcache_raw_read (regcache, regnum, buffer);
}
else
internal_error (__FILE__, __LINE__,
_("invalid register number %d"), regnum);
}
/* Write pseudo registers. */
static void
xtensa_pseudo_register_write (struct gdbarch *gdbarch,
struct regcache *regcache,
int regnum,
const gdb_byte *buffer)
{
enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
DEBUGTRACE ("xtensa_pseudo_register_write (... regnum = %d (%s) ...)\n",
regnum, xtensa_register_name (gdbarch, regnum));
/* Renumber register, if aliase a0..a15 on Windowed ABI. */
if (gdbarch_tdep (gdbarch)->isa_use_windowed_registers
&& (regnum >= gdbarch_tdep (gdbarch)->a0_base)
&& (regnum <= gdbarch_tdep (gdbarch)->a0_base + 15))
{
gdb_byte *buf = (gdb_byte *) alloca (MAX_REGISTER_SIZE);
regcache_raw_read (regcache,
gdbarch_tdep (gdbarch)->wb_regnum, buf);
regnum = arreg_number (gdbarch, regnum,
extract_unsigned_integer (buf, 4, byte_order));
}
/* We can always write 'core' registers.
Note: We might have converted Ax->ARy. */
if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch))
regcache_raw_write (regcache, regnum, buffer);
/* We have to find out how to deal with priveleged registers.
Let's treat them as pseudo-registers, but we cannot read/write them. */
else if (regnum < gdbarch_tdep (gdbarch)->a0_base)
{
return;
}
/* Pseudo registers. */
else if (regnum >= 0
&& regnum < gdbarch_num_regs (gdbarch)
+ gdbarch_num_pseudo_regs (gdbarch))
{
xtensa_register_t *reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
xtensa_register_type_t type = reg->type;
int flags = gdbarch_tdep (gdbarch)->target_flags;
/* On most targets, we cannot write registers
of type "Unknown" or "Unmapped". */
if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
{
if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
{
warning (_("cannot write register %s"),
xtensa_register_name (gdbarch, regnum));
return;
}
}
/* Some targets cannot read TIE register files. */
else if (type == xtRegisterTypeTieRegfile)
{
/* Use 'store' to get register? */
if (flags & xtTargetFlagsUseFetchStore)
{
warning (_("cannot write register"));
return;
}
/* On some targets (esp. simulators), we can always write
the register. */
else if ((flags & xtTargetFlagsNonVisibleRegs) == 0)
{
warning (_("cannot write register"));
return;
}
}
/* We can always write mapped registers. */
else if (type == xtRegisterTypeMapped || type == xtRegisterTypeTieState)
{
xtensa_register_write_masked (regcache, reg, buffer);
return;
}
/* Assume that we can write the register. */
regcache_raw_write (regcache, regnum, buffer);
}
else
internal_error (__FILE__, __LINE__,
_("invalid register number %d"), regnum);
}
static struct reggroup *xtensa_ar_reggroup;
static struct reggroup *xtensa_user_reggroup;
static struct reggroup *xtensa_vectra_reggroup;
static struct reggroup *xtensa_cp[XTENSA_MAX_COPROCESSOR];
static void
xtensa_init_reggroups (void)
{
int i;
char cpname[] = "cp0";
xtensa_ar_reggroup = reggroup_new ("ar", USER_REGGROUP);
xtensa_user_reggroup = reggroup_new ("user", USER_REGGROUP);
xtensa_vectra_reggroup = reggroup_new ("vectra", USER_REGGROUP);
for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
{
cpname[2] = '0' + i;
xtensa_cp[i] = reggroup_new (cpname, USER_REGGROUP);
}
}
static void
xtensa_add_reggroups (struct gdbarch *gdbarch)
{
int i;
/* Predefined groups. */
reggroup_add (gdbarch, all_reggroup);
reggroup_add (gdbarch, save_reggroup);
reggroup_add (gdbarch, restore_reggroup);
reggroup_add (gdbarch, system_reggroup);
reggroup_add (gdbarch, vector_reggroup);
reggroup_add (gdbarch, general_reggroup);
reggroup_add (gdbarch, float_reggroup);
/* Xtensa-specific groups. */
reggroup_add (gdbarch, xtensa_ar_reggroup);
reggroup_add (gdbarch, xtensa_user_reggroup);
reggroup_add (gdbarch, xtensa_vectra_reggroup);
for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
reggroup_add (gdbarch, xtensa_cp[i]);
}
static int
xtensa_coprocessor_register_group (struct reggroup *group)
{
int i;
for (i = 0; i < XTENSA_MAX_COPROCESSOR; i++)
if (group == xtensa_cp[i])
return i;
return -1;
}
#define SAVE_REST_FLAGS (XTENSA_REGISTER_FLAGS_READABLE \
| XTENSA_REGISTER_FLAGS_WRITABLE \
| XTENSA_REGISTER_FLAGS_VOLATILE)
#define SAVE_REST_VALID (XTENSA_REGISTER_FLAGS_READABLE \
| XTENSA_REGISTER_FLAGS_WRITABLE)
static int
xtensa_register_reggroup_p (struct gdbarch *gdbarch,
int regnum,
struct reggroup *group)
{
xtensa_register_t* reg = &gdbarch_tdep (gdbarch)->regmap[regnum];
xtensa_register_type_t type = reg->type;
xtensa_register_group_t rg = reg->group;
int cp_number;
if (group == save_reggroup)
/* Every single register should be included into the list of registers
to be watched for changes while using -data-list-changed-registers. */
return 1;
/* First, skip registers that are not visible to this target
(unknown and unmapped registers when not using ISS). */
if (type == xtRegisterTypeUnmapped || type == xtRegisterTypeUnknown)
return 0;
if (group == all_reggroup)
return 1;
if (group == xtensa_ar_reggroup)
return rg & xtRegisterGroupAddrReg;
if (group == xtensa_user_reggroup)
return rg & xtRegisterGroupUser;
if (group == float_reggroup)
return rg & xtRegisterGroupFloat;
if (group == general_reggroup)
return rg & xtRegisterGroupGeneral;
if (group == system_reggroup)
return rg & xtRegisterGroupState;
if (group == vector_reggroup || group == xtensa_vectra_reggroup)
return rg & xtRegisterGroupVectra;
if (group == restore_reggroup)
return (regnum < gdbarch_num_regs (gdbarch)
&& (reg->flags & SAVE_REST_FLAGS) == SAVE_REST_VALID);
cp_number = xtensa_coprocessor_register_group (group);
if (cp_number >= 0)
return rg & (xtRegisterGroupCP0 << cp_number);
else
return 1;
}
/* Supply register REGNUM from the buffer specified by GREGS and LEN
in the general-purpose register set REGSET to register cache
REGCACHE. If REGNUM is -1 do this for all registers in REGSET. */
static void
xtensa_supply_gregset (const struct regset *regset,
struct regcache *rc,
int regnum,
const void *gregs,
size_t len)
{
const xtensa_elf_gregset_t *regs = gregs;
struct gdbarch *gdbarch = get_regcache_arch (rc);
int i;
DEBUGTRACE ("xtensa_supply_gregset (..., regnum==%d, ...)\n", regnum);
if (regnum == gdbarch_pc_regnum (gdbarch) || regnum == -1)
regcache_raw_supply (rc, gdbarch_pc_regnum (gdbarch), (char *) ®s->pc);
if (regnum == gdbarch_ps_regnum (gdbarch) || regnum == -1)
regcache_raw_supply (rc, gdbarch_ps_regnum (gdbarch), (char *) ®s->ps);
if (regnum == gdbarch_tdep (gdbarch)->wb_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->wb_regnum,
(char *) ®s->windowbase);
if (regnum == gdbarch_tdep (gdbarch)->ws_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->ws_regnum,
(char *) ®s->windowstart);
if (regnum == gdbarch_tdep (gdbarch)->lbeg_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lbeg_regnum,
(char *) ®s->lbeg);
if (regnum == gdbarch_tdep (gdbarch)->lend_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lend_regnum,
(char *) ®s->lend);
if (regnum == gdbarch_tdep (gdbarch)->lcount_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->lcount_regnum,
(char *) ®s->lcount);
if (regnum == gdbarch_tdep (gdbarch)->sar_regnum || regnum == -1)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->sar_regnum,
(char *) ®s->sar);
if (regnum >=gdbarch_tdep (gdbarch)->ar_base
&& regnum < gdbarch_tdep (gdbarch)->ar_base
+ gdbarch_tdep (gdbarch)->num_aregs)
regcache_raw_supply (rc, regnum,
(char *) ®s->ar[regnum - gdbarch_tdep
(gdbarch)->ar_base]);
else if (regnum == -1)
{
for (i = 0; i < gdbarch_tdep (gdbarch)->num_aregs; ++i)
regcache_raw_supply (rc, gdbarch_tdep (gdbarch)->ar_base + i,
(char *) ®s->ar[i]);
}
}
/* Xtensa register set. */
static struct regset
xtensa_gregset =
{
NULL,
xtensa_supply_gregset
};
/* Iterate over supported core file register note sections. */
static void
xtensa_iterate_over_regset_sections (struct gdbarch *gdbarch,
iterate_over_regset_sections_cb *cb,
void *cb_data,
const struct regcache *regcache)
{
DEBUGTRACE ("xtensa_iterate_over_regset_sections\n");
cb (".reg", sizeof (xtensa_elf_gregset_t), &xtensa_gregset,
NULL, cb_data);
}
/* Handling frames. */
/* Number of registers to save in case of Windowed ABI. */
#define XTENSA_NUM_SAVED_AREGS 12
/* Frame cache part for Windowed ABI. */
typedef struct xtensa_windowed_frame_cache
{
int wb; /* WINDOWBASE of the previous frame. */
int callsize; /* Call size of this frame. */
int ws; /* WINDOWSTART of the previous frame. It keeps track of
life windows only. If there is no bit set for the
window, that means it had been already spilled
because of window overflow. */
/* Addresses of spilled A-registers.
AREGS[i] == -1, if corresponding AR is alive. */
CORE_ADDR aregs[XTENSA_NUM_SAVED_AREGS];
} xtensa_windowed_frame_cache_t;
/* Call0 ABI Definitions. */
#define C0_MAXOPDS 3 /* Maximum number of operands for prologue
analysis. */
#define C0_NREGS 16 /* Number of A-registers to track. */
#define C0_CLESV 12 /* Callee-saved registers are here and up. */
#define C0_SP 1 /* Register used as SP. */
#define C0_FP 15 /* Register used as FP. */
#define C0_RA 0 /* Register used as return address. */
#define C0_ARGS 2 /* Register used as first arg/retval. */
#define C0_NARGS 6 /* Number of A-regs for args/retvals. */
/* Each element of xtensa_call0_frame_cache.c0_rt[] describes for each
A-register where the current content of the reg came from (in terms
of an original reg and a constant). Negative values of c0_rt[n].fp_reg
mean that the orignal content of the register was saved to the stack.
c0_rt[n].fr.ofs is NOT the offset from the frame base because we don't
know where SP will end up until the entire prologue has been analyzed. */
#define C0_CONST -1 /* fr_reg value if register contains a constant. */
#define C0_INEXP -2 /* fr_reg value if inexpressible as reg + offset. */
#define C0_NOSTK -1 /* to_stk value if register has not been stored. */
extern xtensa_isa xtensa_default_isa;
typedef struct xtensa_c0reg
{
int fr_reg; /* original register from which register content
is derived, or C0_CONST, or C0_INEXP. */
int fr_ofs; /* constant offset from reg, or immediate value. */
int to_stk; /* offset from original SP to register (4-byte aligned),
or C0_NOSTK if register has not been saved. */
} xtensa_c0reg_t;
/* Frame cache part for Call0 ABI. */
typedef struct xtensa_call0_frame_cache
{
int c0_frmsz; /* Stack frame size. */
int c0_hasfp; /* Current frame uses frame pointer. */
int fp_regnum; /* A-register used as FP. */
int c0_fp; /* Actual value of frame pointer. */
int c0_fpalign; /* Dinamic adjustment for the stack
pointer. It's an AND mask. Zero,
if alignment was not adjusted. */
int c0_old_sp; /* In case of dynamic adjustment, it is
a register holding unaligned sp.
C0_INEXP, when undefined. */
int c0_sp_ofs; /* If "c0_old_sp" was spilled it's a
stack offset. C0_NOSTK otherwise. */
xtensa_c0reg_t c0_rt[C0_NREGS]; /* Register tracking information. */
} xtensa_call0_frame_cache_t;
typedef struct xtensa_frame_cache
{
CORE_ADDR base; /* Stack pointer of this frame. */
CORE_ADDR pc; /* PC of this frame at the function entry point. */
CORE_ADDR ra; /* The raw return address of this frame. */
CORE_ADDR ps; /* The PS register of the previous (older) frame. */