forked from gbenson/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm32c-tdep.c
2710 lines (2206 loc) · 83.5 KB
/
m32c-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
/* Renesas M32C target-dependent code for GDB, the GNU debugger.
Copyright (C) 2004-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 "elf-bfd.h"
#include "elf/m32c.h"
#include "gdb/sim-m32c.h"
#include "dis-asm.h"
#include "gdbtypes.h"
#include "regcache.h"
#include "arch-utils.h"
#include "frame.h"
#include "frame-unwind.h"
#include "dwarf2-frame.h"
#include "dwarf2expr.h"
#include "symtab.h"
#include "gdbcore.h"
#include "value.h"
#include "reggroups.h"
#include "prologue-value.h"
#include "target.h"
#include "objfiles.h"
/* The m32c tdep structure. */
static struct reggroup *m32c_dma_reggroup;
struct m32c_reg;
/* The type of a function that moves the value of REG between CACHE or
BUF --- in either direction. */
typedef enum register_status (m32c_move_reg_t) (struct m32c_reg *reg,
struct regcache *cache,
void *buf);
struct m32c_reg
{
/* The name of this register. */
const char *name;
/* Its type. */
struct type *type;
/* The architecture this register belongs to. */
struct gdbarch *arch;
/* Its GDB register number. */
int num;
/* Its sim register number. */
int sim_num;
/* Its DWARF register number, or -1 if it doesn't have one. */
int dwarf_num;
/* Register group memberships. */
unsigned int general_p : 1;
unsigned int dma_p : 1;
unsigned int system_p : 1;
unsigned int save_restore_p : 1;
/* Functions to read its value from a regcache, and write its value
to a regcache. */
m32c_move_reg_t *read, *write;
/* Data for READ and WRITE functions. The exact meaning depends on
the specific functions selected; see the comments for those
functions. */
struct m32c_reg *rx, *ry;
int n;
};
/* An overestimate of the number of raw and pseudoregisters we will
have. The exact answer depends on the variant of the architecture
at hand, but we can use this to declare statically allocated
arrays, and bump it up when needed. */
#define M32C_MAX_NUM_REGS (75)
/* The largest assigned DWARF register number. */
#define M32C_MAX_DWARF_REGNUM (40)
struct gdbarch_tdep
{
/* All the registers for this variant, indexed by GDB register
number, and the number of registers present. */
struct m32c_reg regs[M32C_MAX_NUM_REGS];
/* The number of valid registers. */
int num_regs;
/* Interesting registers. These are pointers into REGS. */
struct m32c_reg *pc, *flg;
struct m32c_reg *r0, *r1, *r2, *r3, *a0, *a1;
struct m32c_reg *r2r0, *r3r2r1r0, *r3r1r2r0;
struct m32c_reg *sb, *fb, *sp;
/* A table indexed by DWARF register numbers, pointing into
REGS. */
struct m32c_reg *dwarf_regs[M32C_MAX_DWARF_REGNUM + 1];
/* Types for this architecture. We can't use the builtin_type_foo
types, because they're not initialized when building a gdbarch
structure. */
struct type *voyd, *ptr_voyd, *func_voyd;
struct type *uint8, *uint16;
struct type *int8, *int16, *int32, *int64;
/* The types for data address and code address registers. */
struct type *data_addr_reg_type, *code_addr_reg_type;
/* The number of bytes a return address pushed by a 'jsr' instruction
occupies on the stack. */
int ret_addr_bytes;
/* The number of bytes an address register occupies on the stack
when saved by an 'enter' or 'pushm' instruction. */
int push_addr_bytes;
};
/* Types. */
static void
make_types (struct gdbarch *arch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
unsigned long mach = gdbarch_bfd_arch_info (arch)->mach;
int data_addr_reg_bits, code_addr_reg_bits;
char type_name[50];
#if 0
/* This is used to clip CORE_ADDR values, so this value is
appropriate both on the m32c, where pointers are 32 bits long,
and on the m16c, where pointers are sixteen bits long, but there
may be code above the 64k boundary. */
set_gdbarch_addr_bit (arch, 24);
#else
/* GCC uses 32 bits for addrs in the dwarf info, even though
only 16/24 bits are used. Setting addr_bit to 24 causes
errors in reading the dwarf addresses. */
set_gdbarch_addr_bit (arch, 32);
#endif
set_gdbarch_int_bit (arch, 16);
switch (mach)
{
case bfd_mach_m16c:
data_addr_reg_bits = 16;
code_addr_reg_bits = 24;
set_gdbarch_ptr_bit (arch, 16);
tdep->ret_addr_bytes = 3;
tdep->push_addr_bytes = 2;
break;
case bfd_mach_m32c:
data_addr_reg_bits = 24;
code_addr_reg_bits = 24;
set_gdbarch_ptr_bit (arch, 32);
tdep->ret_addr_bytes = 4;
tdep->push_addr_bytes = 4;
break;
default:
gdb_assert_not_reached ("unexpected mach");
}
/* The builtin_type_mumble variables are sometimes uninitialized when
this is called, so we avoid using them. */
tdep->voyd = arch_type (arch, TYPE_CODE_VOID, 1, "void");
tdep->ptr_voyd
= arch_type (arch, TYPE_CODE_PTR, gdbarch_ptr_bit (arch) / TARGET_CHAR_BIT,
NULL);
TYPE_TARGET_TYPE (tdep->ptr_voyd) = tdep->voyd;
TYPE_UNSIGNED (tdep->ptr_voyd) = 1;
tdep->func_voyd = lookup_function_type (tdep->voyd);
xsnprintf (type_name, sizeof (type_name), "%s_data_addr_t",
gdbarch_bfd_arch_info (arch)->printable_name);
tdep->data_addr_reg_type
= arch_type (arch, TYPE_CODE_PTR, data_addr_reg_bits / TARGET_CHAR_BIT,
xstrdup (type_name));
TYPE_TARGET_TYPE (tdep->data_addr_reg_type) = tdep->voyd;
TYPE_UNSIGNED (tdep->data_addr_reg_type) = 1;
xsnprintf (type_name, sizeof (type_name), "%s_code_addr_t",
gdbarch_bfd_arch_info (arch)->printable_name);
tdep->code_addr_reg_type
= arch_type (arch, TYPE_CODE_PTR, code_addr_reg_bits / TARGET_CHAR_BIT,
xstrdup (type_name));
TYPE_TARGET_TYPE (tdep->code_addr_reg_type) = tdep->func_voyd;
TYPE_UNSIGNED (tdep->code_addr_reg_type) = 1;
tdep->uint8 = arch_integer_type (arch, 8, 1, "uint8_t");
tdep->uint16 = arch_integer_type (arch, 16, 1, "uint16_t");
tdep->int8 = arch_integer_type (arch, 8, 0, "int8_t");
tdep->int16 = arch_integer_type (arch, 16, 0, "int16_t");
tdep->int32 = arch_integer_type (arch, 32, 0, "int32_t");
tdep->int64 = arch_integer_type (arch, 64, 0, "int64_t");
}
/* Register set. */
static const char *
m32c_register_name (struct gdbarch *gdbarch, int num)
{
return gdbarch_tdep (gdbarch)->regs[num].name;
}
static struct type *
m32c_register_type (struct gdbarch *arch, int reg_nr)
{
return gdbarch_tdep (arch)->regs[reg_nr].type;
}
static int
m32c_register_sim_regno (struct gdbarch *gdbarch, int reg_nr)
{
return gdbarch_tdep (gdbarch)->regs[reg_nr].sim_num;
}
static int
m32c_debug_info_reg_to_regnum (struct gdbarch *gdbarch, int reg_nr)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
if (0 <= reg_nr && reg_nr <= M32C_MAX_DWARF_REGNUM
&& tdep->dwarf_regs[reg_nr])
return tdep->dwarf_regs[reg_nr]->num;
else
/* The DWARF CFI code expects to see -1 for invalid register
numbers. */
return -1;
}
static int
m32c_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
struct reggroup *group)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
struct m32c_reg *reg = &tdep->regs[regnum];
/* The anonymous raw registers aren't in any groups. */
if (! reg->name)
return 0;
if (group == all_reggroup)
return 1;
if (group == general_reggroup
&& reg->general_p)
return 1;
if (group == m32c_dma_reggroup
&& reg->dma_p)
return 1;
if (group == system_reggroup
&& reg->system_p)
return 1;
/* Since the m32c DWARF register numbers refer to cooked registers, not
raw registers, and frame_pop depends on the save and restore groups
containing registers the DWARF CFI will actually mention, our save
and restore groups are cooked registers, not raw registers. (This is
why we can't use the default reggroup function.) */
if ((group == save_reggroup
|| group == restore_reggroup)
&& reg->save_restore_p)
return 1;
return 0;
}
/* Register move functions. We declare them here using
m32c_move_reg_t to check the types. */
static m32c_move_reg_t m32c_raw_read, m32c_raw_write;
static m32c_move_reg_t m32c_banked_read, m32c_banked_write;
static m32c_move_reg_t m32c_sb_read, m32c_sb_write;
static m32c_move_reg_t m32c_part_read, m32c_part_write;
static m32c_move_reg_t m32c_cat_read, m32c_cat_write;
static m32c_move_reg_t m32c_r3r2r1r0_read, m32c_r3r2r1r0_write;
/* Copy the value of the raw register REG from CACHE to BUF. */
static enum register_status
m32c_raw_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
return regcache_raw_read (cache, reg->num, buf);
}
/* Copy the value of the raw register REG from BUF to CACHE. */
static enum register_status
m32c_raw_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
regcache_raw_write (cache, reg->num, (const void *) buf);
return REG_VALID;
}
/* Return the value of the 'flg' register in CACHE. */
static int
m32c_read_flg (struct regcache *cache)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (get_regcache_arch (cache));
ULONGEST flg;
regcache_raw_read_unsigned (cache, tdep->flg->num, &flg);
return flg & 0xffff;
}
/* Evaluate the real register number of a banked register. */
static struct m32c_reg *
m32c_banked_register (struct m32c_reg *reg, struct regcache *cache)
{
return ((m32c_read_flg (cache) & reg->n) ? reg->ry : reg->rx);
}
/* Move the value of a banked register from CACHE to BUF.
If the value of the 'flg' register in CACHE has any of the bits
masked in REG->n set, then read REG->ry. Otherwise, read
REG->rx. */
static enum register_status
m32c_banked_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
struct m32c_reg *bank_reg = m32c_banked_register (reg, cache);
return regcache_raw_read (cache, bank_reg->num, buf);
}
/* Move the value of a banked register from BUF to CACHE.
If the value of the 'flg' register in CACHE has any of the bits
masked in REG->n set, then write REG->ry. Otherwise, write
REG->rx. */
static enum register_status
m32c_banked_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
struct m32c_reg *bank_reg = m32c_banked_register (reg, cache);
regcache_raw_write (cache, bank_reg->num, (const void *) buf);
return REG_VALID;
}
/* Move the value of SB from CACHE to BUF. On bfd_mach_m32c, SB is a
banked register; on bfd_mach_m16c, it's not. */
static enum register_status
m32c_sb_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
if (gdbarch_bfd_arch_info (reg->arch)->mach == bfd_mach_m16c)
return m32c_raw_read (reg->rx, cache, buf);
else
return m32c_banked_read (reg, cache, buf);
}
/* Move the value of SB from BUF to CACHE. On bfd_mach_m32c, SB is a
banked register; on bfd_mach_m16c, it's not. */
static enum register_status
m32c_sb_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
if (gdbarch_bfd_arch_info (reg->arch)->mach == bfd_mach_m16c)
m32c_raw_write (reg->rx, cache, buf);
else
m32c_banked_write (reg, cache, buf);
return REG_VALID;
}
/* Assuming REG uses m32c_part_read and m32c_part_write, set *OFFSET_P
and *LEN_P to the offset and length, in bytes, of the part REG
occupies in its underlying register. The offset is from the
lower-addressed end, regardless of the architecture's endianness.
(The M32C family is always little-endian, but let's keep those
assumptions out of here.) */
static void
m32c_find_part (struct m32c_reg *reg, int *offset_p, int *len_p)
{
/* The length of the containing register, of which REG is one part. */
int containing_len = TYPE_LENGTH (reg->rx->type);
/* The length of one "element" in our imaginary array. */
int elt_len = TYPE_LENGTH (reg->type);
/* The offset of REG's "element" from the least significant end of
the containing register. */
int elt_offset = reg->n * elt_len;
/* If we extend off the end, trim the length of the element. */
if (elt_offset + elt_len > containing_len)
{
elt_len = containing_len - elt_offset;
/* We shouldn't be declaring partial registers that go off the
end of their containing registers. */
gdb_assert (elt_len > 0);
}
/* Flip the offset around if we're big-endian. */
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
elt_offset = TYPE_LENGTH (reg->rx->type) - elt_offset - elt_len;
*offset_p = elt_offset;
*len_p = elt_len;
}
/* Move the value of a partial register (r0h, intbl, etc.) from CACHE
to BUF. Treating the value of the register REG->rx as an array of
REG->type values, where higher indices refer to more significant
bits, read the value of the REG->n'th element. */
static enum register_status
m32c_part_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
int offset, len;
memset (buf, 0, TYPE_LENGTH (reg->type));
m32c_find_part (reg, &offset, &len);
return regcache_cooked_read_part (cache, reg->rx->num, offset, len, buf);
}
/* Move the value of a banked register from BUF to CACHE.
Treating the value of the register REG->rx as an array of REG->type
values, where higher indices refer to more significant bits, write
the value of the REG->n'th element. */
static enum register_status
m32c_part_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
int offset, len;
m32c_find_part (reg, &offset, &len);
regcache_cooked_write_part (cache, reg->rx->num, offset, len, buf);
return REG_VALID;
}
/* Move the value of REG from CACHE to BUF. REG's value is the
concatenation of the values of the registers REG->rx and REG->ry,
with REG->rx contributing the more significant bits. */
static enum register_status
m32c_cat_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
int high_bytes = TYPE_LENGTH (reg->rx->type);
int low_bytes = TYPE_LENGTH (reg->ry->type);
/* For address arithmetic. */
unsigned char *cbuf = buf;
enum register_status status;
gdb_assert (TYPE_LENGTH (reg->type) == high_bytes + low_bytes);
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
{
status = regcache_cooked_read (cache, reg->rx->num, cbuf);
if (status == REG_VALID)
status = regcache_cooked_read (cache, reg->ry->num, cbuf + high_bytes);
}
else
{
status = regcache_cooked_read (cache, reg->rx->num, cbuf + low_bytes);
if (status == REG_VALID)
status = regcache_cooked_read (cache, reg->ry->num, cbuf);
}
return status;
}
/* Move the value of REG from CACHE to BUF. REG's value is the
concatenation of the values of the registers REG->rx and REG->ry,
with REG->rx contributing the more significant bits. */
static enum register_status
m32c_cat_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
int high_bytes = TYPE_LENGTH (reg->rx->type);
int low_bytes = TYPE_LENGTH (reg->ry->type);
/* For address arithmetic. */
unsigned char *cbuf = buf;
gdb_assert (TYPE_LENGTH (reg->type) == high_bytes + low_bytes);
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
{
regcache_cooked_write (cache, reg->rx->num, cbuf);
regcache_cooked_write (cache, reg->ry->num, cbuf + high_bytes);
}
else
{
regcache_cooked_write (cache, reg->rx->num, cbuf + low_bytes);
regcache_cooked_write (cache, reg->ry->num, cbuf);
}
return REG_VALID;
}
/* Copy the value of the raw register REG from CACHE to BUF. REG is
the concatenation (from most significant to least) of r3, r2, r1,
and r0. */
static enum register_status
m32c_r3r2r1r0_read (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (reg->arch);
int len = TYPE_LENGTH (tdep->r0->type);
enum register_status status;
/* For address arithmetic. */
unsigned char *cbuf = buf;
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
{
status = regcache_cooked_read (cache, tdep->r0->num, cbuf + len * 3);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r1->num, cbuf + len * 2);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r2->num, cbuf + len * 1);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r3->num, cbuf);
}
else
{
status = regcache_cooked_read (cache, tdep->r0->num, cbuf);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r1->num, cbuf + len * 1);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r2->num, cbuf + len * 2);
if (status == REG_VALID)
status = regcache_cooked_read (cache, tdep->r3->num, cbuf + len * 3);
}
return status;
}
/* Copy the value of the raw register REG from BUF to CACHE. REG is
the concatenation (from most significant to least) of r3, r2, r1,
and r0. */
static enum register_status
m32c_r3r2r1r0_write (struct m32c_reg *reg, struct regcache *cache, void *buf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (reg->arch);
int len = TYPE_LENGTH (tdep->r0->type);
/* For address arithmetic. */
unsigned char *cbuf = buf;
if (gdbarch_byte_order (reg->arch) == BFD_ENDIAN_BIG)
{
regcache_cooked_write (cache, tdep->r0->num, cbuf + len * 3);
regcache_cooked_write (cache, tdep->r1->num, cbuf + len * 2);
regcache_cooked_write (cache, tdep->r2->num, cbuf + len * 1);
regcache_cooked_write (cache, tdep->r3->num, cbuf);
}
else
{
regcache_cooked_write (cache, tdep->r0->num, cbuf);
regcache_cooked_write (cache, tdep->r1->num, cbuf + len * 1);
regcache_cooked_write (cache, tdep->r2->num, cbuf + len * 2);
regcache_cooked_write (cache, tdep->r3->num, cbuf + len * 3);
}
return REG_VALID;
}
static enum register_status
m32c_pseudo_register_read (struct gdbarch *arch,
struct regcache *cache,
int cookednum,
gdb_byte *buf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
struct m32c_reg *reg;
gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
gdb_assert (arch == get_regcache_arch (cache));
gdb_assert (arch == tdep->regs[cookednum].arch);
reg = &tdep->regs[cookednum];
return reg->read (reg, cache, buf);
}
static void
m32c_pseudo_register_write (struct gdbarch *arch,
struct regcache *cache,
int cookednum,
const gdb_byte *buf)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
struct m32c_reg *reg;
gdb_assert (0 <= cookednum && cookednum < tdep->num_regs);
gdb_assert (arch == get_regcache_arch (cache));
gdb_assert (arch == tdep->regs[cookednum].arch);
reg = &tdep->regs[cookednum];
reg->write (reg, cache, (void *) buf);
}
/* Add a register with the given fields to the end of ARCH's table.
Return a pointer to the newly added register. */
static struct m32c_reg *
add_reg (struct gdbarch *arch,
const char *name,
struct type *type,
int sim_num,
m32c_move_reg_t *read,
m32c_move_reg_t *write,
struct m32c_reg *rx,
struct m32c_reg *ry,
int n)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
struct m32c_reg *r = &tdep->regs[tdep->num_regs];
gdb_assert (tdep->num_regs < M32C_MAX_NUM_REGS);
r->name = name;
r->type = type;
r->arch = arch;
r->num = tdep->num_regs;
r->sim_num = sim_num;
r->dwarf_num = -1;
r->general_p = 0;
r->dma_p = 0;
r->system_p = 0;
r->save_restore_p = 0;
r->read = read;
r->write = write;
r->rx = rx;
r->ry = ry;
r->n = n;
tdep->num_regs++;
return r;
}
/* Record NUM as REG's DWARF register number. */
static void
set_dwarf_regnum (struct m32c_reg *reg, int num)
{
gdb_assert (num < M32C_MAX_NUM_REGS);
/* Update the reg->DWARF mapping. Only count the first number
assigned to this register. */
if (reg->dwarf_num == -1)
reg->dwarf_num = num;
/* Update the DWARF->reg mapping. */
gdbarch_tdep (reg->arch)->dwarf_regs[num] = reg;
}
/* Mark REG as a general-purpose register, and return it. */
static struct m32c_reg *
mark_general (struct m32c_reg *reg)
{
reg->general_p = 1;
return reg;
}
/* Mark REG as a DMA register, and return it. */
static struct m32c_reg *
mark_dma (struct m32c_reg *reg)
{
reg->dma_p = 1;
return reg;
}
/* Mark REG as a SYSTEM register, and return it. */
static struct m32c_reg *
mark_system (struct m32c_reg *reg)
{
reg->system_p = 1;
return reg;
}
/* Mark REG as a save-restore register, and return it. */
static struct m32c_reg *
mark_save_restore (struct m32c_reg *reg)
{
reg->save_restore_p = 1;
return reg;
}
#define FLAGBIT_B 0x0010
#define FLAGBIT_U 0x0080
/* Handy macros for declaring registers. These all evaluate to
pointers to the register declared. Macros that define two
registers evaluate to a pointer to the first. */
/* A raw register named NAME, with type TYPE and sim number SIM_NUM. */
#define R(name, type, sim_num) \
(add_reg (arch, (name), (type), (sim_num), \
m32c_raw_read, m32c_raw_write, NULL, NULL, 0))
/* The simulator register number for a raw register named NAME. */
#define SIM(name) (m32c_sim_reg_ ## name)
/* A raw unsigned 16-bit data register named NAME.
NAME should be an identifier, not a string. */
#define R16U(name) \
(R(#name, tdep->uint16, SIM (name)))
/* A raw data address register named NAME.
NAME should be an identifier, not a string. */
#define RA(name) \
(R(#name, tdep->data_addr_reg_type, SIM (name)))
/* A raw code address register named NAME. NAME should
be an identifier, not a string. */
#define RC(name) \
(R(#name, tdep->code_addr_reg_type, SIM (name)))
/* A pair of raw registers named NAME0 and NAME1, with type TYPE.
NAME should be an identifier, not a string. */
#define RP(name, type) \
(R(#name "0", (type), SIM (name ## 0)), \
R(#name "1", (type), SIM (name ## 1)) - 1)
/* A raw banked general-purpose data register named NAME.
NAME should be an identifier, not a string. */
#define RBD(name) \
(R(NULL, tdep->int16, SIM (name ## _bank0)), \
R(NULL, tdep->int16, SIM (name ## _bank1)) - 1)
/* A raw banked data address register named NAME.
NAME should be an identifier, not a string. */
#define RBA(name) \
(R(NULL, tdep->data_addr_reg_type, SIM (name ## _bank0)), \
R(NULL, tdep->data_addr_reg_type, SIM (name ## _bank1)) - 1)
/* A cooked register named NAME referring to a raw banked register
from the bank selected by the current value of FLG. RAW_PAIR
should be a pointer to the first register in the banked pair.
NAME must be an identifier, not a string. */
#define CB(name, raw_pair) \
(add_reg (arch, #name, (raw_pair)->type, 0, \
m32c_banked_read, m32c_banked_write, \
(raw_pair), (raw_pair + 1), FLAGBIT_B))
/* A pair of registers named NAMEH and NAMEL, of type TYPE, that
access the top and bottom halves of the register pointed to by
NAME. NAME should be an identifier. */
#define CHL(name, type) \
(add_reg (arch, #name "h", (type), 0, \
m32c_part_read, m32c_part_write, name, NULL, 1), \
add_reg (arch, #name "l", (type), 0, \
m32c_part_read, m32c_part_write, name, NULL, 0) - 1)
/* A register constructed by concatenating the two registers HIGH and
LOW, whose name is HIGHLOW and whose type is TYPE. */
#define CCAT(high, low, type) \
(add_reg (arch, #high #low, (type), 0, \
m32c_cat_read, m32c_cat_write, (high), (low), 0))
/* Abbreviations for marking register group membership. */
#define G(reg) (mark_general (reg))
#define S(reg) (mark_system (reg))
#define DMA(reg) (mark_dma (reg))
/* Construct the register set for ARCH. */
static void
make_regs (struct gdbarch *arch)
{
struct gdbarch_tdep *tdep = gdbarch_tdep (arch);
int mach = gdbarch_bfd_arch_info (arch)->mach;
int num_raw_regs;
int num_cooked_regs;
struct m32c_reg *r0;
struct m32c_reg *r1;
struct m32c_reg *r2;
struct m32c_reg *r3;
struct m32c_reg *a0;
struct m32c_reg *a1;
struct m32c_reg *fb;
struct m32c_reg *sb;
struct m32c_reg *sp;
struct m32c_reg *r0hl;
struct m32c_reg *r1hl;
struct m32c_reg *r2hl;
struct m32c_reg *r3hl;
struct m32c_reg *intbhl;
struct m32c_reg *r2r0;
struct m32c_reg *r3r1;
struct m32c_reg *r3r1r2r0;
struct m32c_reg *r3r2r1r0;
struct m32c_reg *a1a0;
struct m32c_reg *raw_r0_pair = RBD (r0);
struct m32c_reg *raw_r1_pair = RBD (r1);
struct m32c_reg *raw_r2_pair = RBD (r2);
struct m32c_reg *raw_r3_pair = RBD (r3);
struct m32c_reg *raw_a0_pair = RBA (a0);
struct m32c_reg *raw_a1_pair = RBA (a1);
struct m32c_reg *raw_fb_pair = RBA (fb);
/* sb is banked on the bfd_mach_m32c, but not on bfd_mach_m16c.
We always declare both raw registers, and deal with the distinction
in the pseudoregister. */
struct m32c_reg *raw_sb_pair = RBA (sb);
struct m32c_reg *usp = S (RA (usp));
struct m32c_reg *isp = S (RA (isp));
struct m32c_reg *intb = S (RC (intb));
struct m32c_reg *pc = G (RC (pc));
struct m32c_reg *flg = G (R16U (flg));
if (mach == bfd_mach_m32c)
{
struct m32c_reg *svf = S (R16U (svf));
struct m32c_reg *svp = S (RC (svp));
struct m32c_reg *vct = S (RC (vct));
struct m32c_reg *dmd01 = DMA (RP (dmd, tdep->uint8));
struct m32c_reg *dct01 = DMA (RP (dct, tdep->uint16));
struct m32c_reg *drc01 = DMA (RP (drc, tdep->uint16));
struct m32c_reg *dma01 = DMA (RP (dma, tdep->data_addr_reg_type));
struct m32c_reg *dsa01 = DMA (RP (dsa, tdep->data_addr_reg_type));
struct m32c_reg *dra01 = DMA (RP (dra, tdep->data_addr_reg_type));
}
num_raw_regs = tdep->num_regs;
r0 = G (CB (r0, raw_r0_pair));
r1 = G (CB (r1, raw_r1_pair));
r2 = G (CB (r2, raw_r2_pair));
r3 = G (CB (r3, raw_r3_pair));
a0 = G (CB (a0, raw_a0_pair));
a1 = G (CB (a1, raw_a1_pair));
fb = G (CB (fb, raw_fb_pair));
/* sb is banked on the bfd_mach_m32c, but not on bfd_mach_m16c.
Specify custom read/write functions that do the right thing. */
sb = G (add_reg (arch, "sb", raw_sb_pair->type, 0,
m32c_sb_read, m32c_sb_write,
raw_sb_pair, raw_sb_pair + 1, 0));
/* The current sp is either usp or isp, depending on the value of
the FLG register's U bit. */
sp = G (add_reg (arch, "sp", usp->type, 0,
m32c_banked_read, m32c_banked_write,
isp, usp, FLAGBIT_U));
r0hl = CHL (r0, tdep->int8);
r1hl = CHL (r1, tdep->int8);
r2hl = CHL (r2, tdep->int8);
r3hl = CHL (r3, tdep->int8);
intbhl = CHL (intb, tdep->int16);
r2r0 = CCAT (r2, r0, tdep->int32);
r3r1 = CCAT (r3, r1, tdep->int32);
r3r1r2r0 = CCAT (r3r1, r2r0, tdep->int64);
r3r2r1r0
= add_reg (arch, "r3r2r1r0", tdep->int64, 0,
m32c_r3r2r1r0_read, m32c_r3r2r1r0_write, NULL, NULL, 0);
if (mach == bfd_mach_m16c)
a1a0 = CCAT (a1, a0, tdep->int32);
else
a1a0 = NULL;
num_cooked_regs = tdep->num_regs - num_raw_regs;
tdep->pc = pc;
tdep->flg = flg;
tdep->r0 = r0;
tdep->r1 = r1;
tdep->r2 = r2;
tdep->r3 = r3;
tdep->r2r0 = r2r0;
tdep->r3r2r1r0 = r3r2r1r0;
tdep->r3r1r2r0 = r3r1r2r0;
tdep->a0 = a0;
tdep->a1 = a1;
tdep->sb = sb;
tdep->fb = fb;
tdep->sp = sp;
/* Set up the DWARF register table. */
memset (tdep->dwarf_regs, 0, sizeof (tdep->dwarf_regs));
set_dwarf_regnum (r0hl + 1, 0x01);
set_dwarf_regnum (r0hl + 0, 0x02);
set_dwarf_regnum (r1hl + 1, 0x03);
set_dwarf_regnum (r1hl + 0, 0x04);
set_dwarf_regnum (r0, 0x05);
set_dwarf_regnum (r1, 0x06);
set_dwarf_regnum (r2, 0x07);
set_dwarf_regnum (r3, 0x08);
set_dwarf_regnum (a0, 0x09);
set_dwarf_regnum (a1, 0x0a);
set_dwarf_regnum (fb, 0x0b);
set_dwarf_regnum (sp, 0x0c);
set_dwarf_regnum (pc, 0x0d); /* GCC's invention */
set_dwarf_regnum (sb, 0x13);
set_dwarf_regnum (r2r0, 0x15);
set_dwarf_regnum (r3r1, 0x16);
if (a1a0)
set_dwarf_regnum (a1a0, 0x17);
/* Enumerate the save/restore register group.
The regcache_save and regcache_restore functions apply their read
function to each register in this group.
Since frame_pop supplies frame_unwind_register as its read
function, the registers meaningful to the Dwarf unwinder need to
be in this group.
On the other hand, when we make inferior calls, save_inferior_status
and restore_inferior_status use them to preserve the current register
values across the inferior call. For this, you'd kind of like to
preserve all the raw registers, to protect the interrupted code from
any sort of bank switching the callee might have done. But we handle
those cases so badly anyway --- for example, it matters whether we
restore FLG before or after we restore the general-purpose registers,
but there's no way to express that --- that it isn't worth worrying
about.
We omit control registers like inthl: if you call a function that
changes those, it's probably because you wanted that change to be
visible to the interrupted code. */
mark_save_restore (r0);
mark_save_restore (r1);
mark_save_restore (r2);
mark_save_restore (r3);
mark_save_restore (a0);
mark_save_restore (a1);
mark_save_restore (sb);
mark_save_restore (fb);
mark_save_restore (sp);
mark_save_restore (pc);
mark_save_restore (flg);
set_gdbarch_num_regs (arch, num_raw_regs);
set_gdbarch_num_pseudo_regs (arch, num_cooked_regs);
set_gdbarch_pc_regnum (arch, pc->num);
set_gdbarch_sp_regnum (arch, sp->num);
set_gdbarch_register_name (arch, m32c_register_name);
set_gdbarch_register_type (arch, m32c_register_type);
set_gdbarch_pseudo_register_read (arch, m32c_pseudo_register_read);
set_gdbarch_pseudo_register_write (arch, m32c_pseudo_register_write);
set_gdbarch_register_sim_regno (arch, m32c_register_sim_regno);
set_gdbarch_stab_reg_to_regnum (arch, m32c_debug_info_reg_to_regnum);
set_gdbarch_dwarf2_reg_to_regnum (arch, m32c_debug_info_reg_to_regnum);
set_gdbarch_register_reggroup_p (arch, m32c_register_reggroup_p);
reggroup_add (arch, general_reggroup);
reggroup_add (arch, all_reggroup);
reggroup_add (arch, save_reggroup);
reggroup_add (arch, restore_reggroup);
reggroup_add (arch, system_reggroup);
reggroup_add (arch, m32c_dma_reggroup);
}
/* Breakpoints. */
static const unsigned char *