/
mchp.c
executable file
·6933 lines (6285 loc) · 238 KB
/
mchp.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
/* Subroutines used for Microchip PIC32 MCU support
Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998
1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009
Free Software Foundation, Inc.
Contributed by J. Grosbach, james.grosbach@microchip.com, and
T. Kuhrt, tracy.kuhrt@microchip.com
Changes by J. Kajita, jason.kajita@microchip.com,
G. Loegel, george.loegel@microchip.com and
S. Bekal, swaroopkumar.bekal@microchip.com
This file is part of GCC.
GCC 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, or (at your option)
any later version.
GCC 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 GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#ifndef TARGET_IS_PIC32MX
#define TARGET_IS_PIC32MX
#endif
#ifndef PIC32
#define PIC32
#endif
#ifndef _BUILD_C32_
#define _BUILD_C32_
#endif
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "cppdefault.h"
#include "tm.h"
#include <signal.h>
#include "rtl.h"
#include "regs.h"
#include "hard-reg-set.h"
#include "real.h"
#include "insn-config.h"
#include "conditions.h"
#include "insn-attr.h"
#include "recog.h"
#include "toplev.h"
#include "output.h"
#include "tree.h"
#include "function.h"
#include "expr.h"
#include "optabs.h"
#include "libfuncs.h"
#include "flags.h"
#include "reload.h"
#include "tm_p.h"
#include "ggc.h"
#include "gstab.h"
#include "hashtab.h"
#include "debug.h"
#include "target.h"
#include "target-def.h"
#include "langhooks.h"
#include "sched-int.h"
#include "gimple.h"
#include "bitmap.h"
#include "diagnostic.h"
#include "params.h"
#include "prefix.h"
#include "bversion.h"
#include "opts.h"
#include <stdio.h>
#include <string.h>
#include "cpplib.h"
#include "mchp-protos.h"
#include "mchp-pragmas.h"
#include "c-family/c-pragma.h"
#include "incpath.h"
#include "cppdefault.h"
#include "hwint.h"
#include "config/mips/mips-machine-function.h"
#include "version.h"
/* splitting for lto/non-lto causes beacoup problems */
#include "../../../../c30_resource/src/xc32/resource_info.h"
#include "config/mchp-cci/cci.h"
#ifdef __MINGW32__
void *alloca(size_t);
#else
#include <alloca.h>
#endif
#define xstr(s) str(s)
#define str(s) #s
#define const_section readonly_data_section
#define dconst_section readonly_data_section
/* Global Variables */
//const char *mchp_resource_file = NULL;
char *mchp_resource_file_f; /* stoopid options.c always makes this const */
//extern const char * mchp_text_scn;
SECTION_FLAGS_INT mchp_text_flags = SECTION_CODE;
extern bool user_defined_section_attribute;
extern bool bss_initializer_p (const_tree decl);
extern cpp_options *cpp_opts;
int mchp_profile_option = 0;
unsigned int mchp_pragma_align = 0;
unsigned int mchp_pragma_inline = 0;
unsigned int mchp_pragma_keep = 0;
unsigned int mchp_pragma_coherent = 0;
unsigned int mchp_pragma_printf_args = 0;
unsigned int mchp_pragma_scanf_args = 0;
tree mchp_pragma_section = NULL_TREE;
typedef struct pic32_external_memory {
tree decl;
char *name;
int size;
unsigned int origin;
struct pic32_external_memory *next;
} pic32_external_memory;
static pic32_external_memory *pic32_external_memory_head,
*pic32_external_memory_tail;
typedef struct pic32_function_replacement_prologue {
const char *name;
struct pic32_function_replacement_prologue *next;
} pic32_function_replacement_prologue;
static pic32_function_replacement_prologue *pic32_function_replacement_prologue_head,
*pic32_function_replacement_prologue_tail;
/* Local Variables */
#ifndef BITSET_P
/* True if bit BIT is set in VALUE. */
#define BITSET_P(VALUE, BIT) (((VALUE) & (1 << (BIT))) != 0)
#endif
#define SECTION_FLAG_EXEC "x"
#define SECTION_FLAG_DATA "d"
#define SECTION_FLAG_BSS "b"
#define SECTION_FLAG_READONLY "r"
#define SECTION_NAME_BSS ".bss"
#define SECTION_NAME_NBSS ".sbss"
#define SECTION_NAME_SBSS ".sbss"
#define SECTION_NAME_DATA ".data"
#define SECTION_NAME_NDATA ".sdata"
#define SECTION_NAME_SDATA ".sdata"
#define SECTION_NAME_CONST ".rodata"
#define SECTION_NAME_RAMFUNC ".ramfunc"
#define SECTION_NAME_PBSS ".pbss"
#define SECTION_NAME_INIT ".init"
#define SECTION_NAME_FINI ".fini"
#define SECTION_NAME_CTORS ".ctors"
#define SECTION_NAME_DTORS ".dtors"
#define SECTION_NAME_INIT_ARRAY ".init_array"
#define SECTION_NAME_FINI_ARRAY ".fini_array"
#define SECTION_NAME_SERIALMEM ".serial_mem"
#define JOIN2(X,Y) (X ## Y)
#define JOIN(X,Y) JOIN2(X,Y)
#define MCHP_ULL(X) JOIN2(X,ULL)
/* 0x100000 */
#define SECTION_READ_ONLY (MCHP_ULL(SECTION_MACH_DEP))
#define SECTION_CONST (MCHP_ULL(SECTION_MACH_DEP))
#define SECTION_RAMFUNC (MCHP_ULL(SECTION_MACH_DEP) << 1ull)
#define SECTION_NEAR (MCHP_ULL(SECTION_MACH_DEP) << 2ull)
#define SECTION_PERSIST (MCHP_ULL(SECTION_MACH_DEP) << 3ull)
#define SECTION_NOLOAD (MCHP_ULL(SECTION_MACH_DEP) << 4ull)
#define SECTION_INFO (MCHP_ULL(SECTION_MACH_DEP) << 5ull)
#define SECTION_ADDRESS (MCHP_ULL(SECTION_MACH_DEP) << 6ull)
#define SECTION_ALIGN (MCHP_ULL(SECTION_MACH_DEP) << 7ull)
#define SECTION_KEEP (MCHP_ULL(SECTION_MACH_DEP) << 8ull)
#define SECTION_COHERENT (MCHP_ULL(SECTION_MACH_DEP) << 9ull)
#define SECTION_REGION (MCHP_ULL(SECTION_MACH_DEP) << 10ull)
#define SECTION_SERIALMEM (MCHP_ULL(SECTION_MACH_DEP) << 11ull)
#define SECTION_CO_SHARED (MCHP_ULL(SECTION_MACH_DEP) << 12ull)
/* the attribute names from the assemblers point of view */
#define SECTION_ATTR_ADDRESS "address"
#define SECTION_ATTR_ALIGN "align"
#define SECTION_ATTR_BSS "bss"
#define SECTION_ATTR_CODE "code"
#define SECTION_ATTR_CONST "code"
#define SECTION_ATTR_DATA "data"
#define SECTION_ATTR_SERIALMEM "serial_mem"
#define SECTION_ATTR_INFO "info"
#define SECTION_ATTR_NEAR "near"
#define SECTION_ATTR_NOLOAD "noload"
#define SECTION_ATTR_PERSIST "persist"
#define SECTION_ATTR_RAMFUNC "ramfunc"
#define SECTION_ATTR_DEFAULT "unused"
#define SECTION_ATTR_KEEP "keep"
#define SECTION_ATTR_COHERENT "coherent"
#define SECTION_ATTR_REGION "memory"
#define SECTION_ATTR_CO_SHARED "shared"
struct valid_section_flags_
{
const char *flag_name;
char single_letter_equiv;
unsigned long long flag_mask;
unsigned long long incompatible_with;
} valid_section_flags[] =
{
{
SECTION_ATTR_ADDRESS, 0,
SECTION_ADDRESS, SECTION_ALIGN | SECTION_INFO
},
{
SECTION_ATTR_ALIGN, 0,
SECTION_ALIGN, SECTION_ADDRESS |
SECTION_INFO
},
{
SECTION_ATTR_BSS, 'b',
SECTION_BSS, SECTION_CODE | SECTION_WRITE | SECTION_PERSIST |
SECTION_READ_ONLY
},
{
SECTION_ATTR_CODE, 'x',
SECTION_CODE, SECTION_WRITE | SECTION_BSS |
SECTION_NEAR |
SECTION_PERSIST |
SECTION_READ_ONLY
},
{
SECTION_ATTR_CONST, 'r',
SECTION_READ_ONLY,SECTION_CODE | SECTION_WRITE | SECTION_BSS |
SECTION_NEAR |
SECTION_INFO
},
{
SECTION_ATTR_SERIALMEM, 'r',
SECTION_READ_ONLY,SECTION_CODE | SECTION_WRITE | SECTION_BSS |
SECTION_NEAR |
SECTION_INFO
},
{
SECTION_ATTR_COHERENT, 0,
SECTION_COHERENT,
0
},
{
SECTION_ATTR_DATA, 'd',
SECTION_WRITE, SECTION_BSS | SECTION_PERSIST |
SECTION_READ_ONLY
},
{
SECTION_ATTR_INFO, 0,
SECTION_INFO, SECTION_PERSIST |
SECTION_ADDRESS | SECTION_NEAR |
SECTION_ALIGN |
SECTION_NOLOAD | SECTION_MERGE |
SECTION_READ_ONLY
},
{
SECTION_ATTR_KEEP, 0,
SECTION_KEEP,
0
},
{
SECTION_ATTR_REGION, 0,
SECTION_REGION,
0
},
{
SECTION_ATTR_NOLOAD, 0,
SECTION_NOLOAD, SECTION_MERGE | SECTION_INFO
},
{
SECTION_ATTR_PERSIST, 'b',
SECTION_PERSIST, SECTION_CODE | SECTION_WRITE | SECTION_BSS |
SECTION_MERGE |
SECTION_INFO | SECTION_READ_ONLY
},
{
SECTION_ATTR_RAMFUNC, 0,
SECTION_RAMFUNC, SECTION_WRITE | SECTION_BSS |
SECTION_NEAR |
SECTION_PERSIST |
SECTION_READ_ONLY
},
{ SECTION_ATTR_CO_SHARED, 0,
SECTION_CO_SHARED, SECTION_MERGE
},
{ 0, 0, 0, 0},
};
struct reserved_section_names_
{
const char *section_name;
SECTION_FLAGS_INT mask;
} reserved_section_names[] =
{
{ ".bss", SECTION_BSS },
{ ".rodata", SECTION_READ_ONLY },
{ ".rodata1", SECTION_READ_ONLY },
{ ".data", SECTION_WRITE },
{ ".dconst", SECTION_WRITE },
{ ".sbss", SECTION_BSS | SECTION_NEAR },
{ ".sdata", SECTION_WRITE | SECTION_NEAR },
{ ".sdconst",SECTION_WRITE | SECTION_NEAR },
{ ".pbss", SECTION_PERSIST },
{ ".text", SECTION_CODE },
{ ".ramfunc", SECTION_RAMFUNC },
{ ".gnu.linkonce.d", SECTION_WRITE },
{ ".gnu.linkonce.t", SECTION_CODE },
{ ".gnu.linkonce.r", SECTION_READ_ONLY },
{ ".gnu.linkonce.s2", SECTION_READ_ONLY },
{ ".gnu.linkonce.sb2", SECTION_READ_ONLY },
{ ".got", SECTION_WRITE },
{ ".got.plt", SECTION_WRITE },
{ ".gnu.linkonce.s", SECTION_WRITE | SECTION_NEAR },
{ ".gnu.linkonce.sb", SECTION_BSS | SECTION_NEAR },
{ ".dynsbss", SECTION_BSS | SECTION_NEAR },
{ ".scommon", SECTION_BSS | SECTION_NEAR },
{ ".dynbss", SECTION_BSS },
{ 0, 0},
};
static const char *mchp_default_section = "*";
static char this_default_name[sizeof("*_012345670123456701234567")];
static time_t current_time = 0;
static int lfInExecutableSection = FALSE;
static int pic32_num_register_sets = 2;
static unsigned int pic32_procid = 0;
static bool pic32_loaded_device_mask = false;
static unsigned int pic32_device_mask = HAS_MIPS32R2 | HAS_MIPS16 | HAS_MICROMIPS;
const char * mchp_target_cpu = NULL;
char * mchp_target_cpu_id;
enum
{
ss_pushed = 0, /* section stack was pushed */
ss_set = 1, /* section stack was set */
ss_should_pop = 2 /* popped, but wait til we see what is pushed next */
};
typedef struct sectionStack_
{
const char * pszName;
unsigned int pszFlag;
struct sectionStack_ *pop;
SECTION_FLAGS_INT flags;
} sectionStack;
enum css
{
css_pop = 0,
css_push = 1,
css_activate = 2,
css_tos = 3
};
static sectionStack default_section =
{
".text.default_section", SECTION_CODE , 0x0, 0x0
};
static sectionStack *lSectionStack = &default_section;
static sectionStack *freeSectionStack;
/* The maximum distance between the top of the stack frame and the
value $sp has when we save and restore registers.
The value for normal-mode code must be a SMALL_OPERAND and must
preserve the maximum stack alignment. We therefore use a value
of 0x7ff0 in this case.
MIPS16e SAVE and RESTORE instructions can adjust the stack pointer by
up to 0x7f8 bytes and can usually save or restore all the registers
that we need to save or restore. (Note that we can only use these
instructions for o32, for which the stack alignment is 8 bytes.)
We use a maximum gap of 0x100 or 0x400 for MIPS16 code when SAVE and
RESTORE are not available. We can then use unextended instructions
to save and restore registers, and to allocate and deallocate the top
part of the frame. */
#ifndef MIPS_MAX_FIRST_STACK_STEP
#define MIPS_MAX_FIRST_STACK_STEP \
(!TARGET_MIPS16 ? 0x7ff0 \
: GENERATE_MIPS16E_SAVE_RESTORE ? 0x7f8 \
: TARGET_64BIT ? 0x100 : 0x400)
#endif
#if 1 /* TODO */
enum mips_function_type_tag current_function_type;
typedef struct cheap_rtx_list {
tree t;
rtx x;
int flag;
struct cheap_rtx_list *next;
} cheap_rtx_list;
typedef enum mchp_interesting_fn_info_
{
info_invalid,
info_I,
info_O,
info_O_v,
info_dbl
} mchp_interesting_fn_info;
typedef enum mchp_conversion_status_
{
conv_state_unknown,
conv_possible,
conv_indeterminate,
conv_not_possible,
conv_c = 0x000080,
conv_d = 0x000100,
conv_i = 0x000100,
conv_e = 0x000200,
conv_E = 0x000400,
conv_f = 0x000800,
conv_g = 0x001000,
conv_G = 0x002000,
conv_n = 0x004000,
conv_o = 0x008000,
conv_p = 0x010000,
conv_s = 0x020000,
conv_u = 0x040000,
conv_x = 0x080000,
conv_X = 0x100000,
conv_a = 0x200000,
conv_A = 0x400000,
conv_F = 0x800000
} mchp_conversion_status;
typedef struct mchp_intersting_fn_
{
const char *name;
const char *map_to;
mchp_interesting_fn_info conversion_style;
int interesting_arg;
unsigned int function_convertable;
mchp_conversion_status conv_flags;
char *encoded_name;
} mchp_interesting_fn;
/* The nesting depth of .set noat */
extern struct mips_asm_switch mips_noat;
static HOST_WIDE_INT mchp_interrupt_priority;
static HOST_WIDE_INT mchp_isr_backcompat = 0;
static HOST_WIDE_INT mchp_offset_status = 0;
static HOST_WIDE_INT mchp_offset_epc = 0;
static HOST_WIDE_INT mchp_offset_srsctl = 0;
static HOST_WIDE_INT mchp_offset_dspcontrol = 0;
static HOST_WIDE_INT mchp_offset_fcsr = 0;
static HOST_WIDE_INT mchp_invalid_ipl_warning = 0;
static void push_cheap_rtx(cheap_rtx_list **l, rtx x, tree t, int flag);
static rtx pop_cheap_rtx(cheap_rtx_list **l, tree *t, int *flag);
static tree mchp_function_interrupt_p (tree decl);
static int mchp_function_naked_p (tree func);
static int mchp_persistent_p (tree func);
static int mchp_keep_p (tree decl);
static int mchp_coherent_p (tree decl);
static int mchp_shared_p (tree decl);
static int mchp_vector_attribute_compound_expr (tree *node, tree expr,
bool *no_add_attrs);
int mchp_epilogue_uses (unsigned regno);
static void mchp_output_configuration_words (void);
static void mchp_output_vector_dispatch_table (void);
static void mchp_output_vector_dispatch_table_for_pic (void);
static void mchp_output_ext_region_memory_info (void);
static int mchp_vector_attribute_compound_expr (tree *node, tree expr,
bool *no_add_attrs);
inline int
mchp_register_interrupt_context_p (unsigned regno);
static mchp_interesting_fn *mchp_match_conversion_fn(const char *name);
static const char *default_section_name(tree decl, SECTION_FLAGS_INT flags);
static void mchp_merged_asm_named_section(const char *name,
SECTION_FLAGS_INT flags);
static
char * mchp_get_named_section_flags (const char *pszSectionName,
SECTION_FLAGS_INT flags);
int set_section_stack(const char *pszSectionName,
SECTION_FLAGS_INT pszSectionFlag);
#if 1
void mchp_push_section_name(const char *pszSectionName,
SECTION_FLAGS_INT pszSectionFlag);
#endif
#if 1
static tree mchp_push_pop_constant_section(tree decl, enum css push,
const char **section_name);
static void mchp_pop_section_name(void);
#endif
static tree get_mchp_space_attribute (tree decl);
static tree get_mchp_region_attribute (tree decl);
extern unsigned int mips_get_compress_mode (tree decl);
extern void mips_set_compression_mode (unsigned int compression_mode);
extern void mips_for_each_saved_gpr_and_fpr (HOST_WIDE_INT sp_offset, mchp_save_restore_fn fn, rtx skip_label);
extern void mips_restore_reg (rtx reg, rtx mem);
extern bool mips_interrupt_type_p (tree type);
SECTION_FLAGS_INT mchp_section_type_flags(tree decl, const char *name, int reloc ATTRIBUTE_UNUSED);
void mchp_add_vector_dispatch_entry (const char *target_name, int vector_number, bool fartype,
enum pic32_isa_mode isamode, int emit);
/*
* Function Replacement Prologue generation
*/
static void mchp_output_frp_table (void);
static void mchp_update_frp_info (const char *name);
struct vector_dispatch_spec *vector_dispatch_list_head;
struct mchp_config_specification *mchp_configuration_values;
#if !defined(MCHP_SKIP_RESOURCE_FILE)
/* This will be called by the spec parser in gcc.c when it sees
a %:local_cpu_detect(args) construct.
*/
static const char* mchp_get_resource_file_path(void);
static const char* mchp_get_resource_file_path(void)
{
extern struct cl_decoded_option *save_decoded_options;
/* TODO Correct this path */
#if 0
char* path = make_relative_prefix(save_argv[0], "/bin/bin", "/bin");
#endif
char* path = make_relative_prefix(save_decoded_options[0].arg,
"/pic32mx/bin/gcc/pic32mx/"
str(BUILDING_GCC_MAJOR) "."
str(BUILDING_GCC_MINOR) "."
str(BUILDING_GCC_PATCHLEVEL),
"/bin");
#if defined(__MINGW32__)
{
char *convert;
convert = path;
while (*convert != '\0')
{
if (*convert == '\\')
*convert = '/';
convert++;
}
}
#endif
return path;
}
#if 1
static unsigned int mchp_load_resource_info(char *id, char **matched_id, const char* mchp_resource_file_in);
static unsigned int mchp_load_resource_info(char *id, char **matched_id, const char* mchp_resource_file_in) {
struct resource_introduction_block *rib;
struct resource_data d;
int version;
unsigned int mask;
char *Microchip;
char *new_version = xstrdup(version_string);
char *version_part1;
char *version_part2;
int mismatch=0;
char *match;
char *device_buf;
char *mchp_resource_file_generic;
int buffer_size;
/* No device specified, use defaults */
if (id == NULL)
return 0;
if (mchp_resource_file_in == 0) {
if (mchp_resource_file != 0)
/* specified on the command line */
mchp_resource_file_in = mchp_resource_file;
else
/* use the default */
mchp_resource_file_in = mchp_get_resource_file_path();
}
mchp_resource_file_generic = (char *)mchp_resource_file_in+strlen(mchp_resource_file_in)-strlen("xc32_device.info");
/* read_device_rib assumes that the resource file name is xc32_device.info. Ensure that it is. */
if (strcmp (mchp_resource_file_generic, "xc32_device.info") != 0)
{
buffer_size = strlen(mchp_resource_file_in)+strlen("/xc32_device.info")+1;
mchp_resource_file_generic = (char *)xcalloc (buffer_size,1);
snprintf (mchp_resource_file_generic, buffer_size, "%s/xc32_device.info", mchp_resource_file_in);
}
else
{
buffer_size = strlen(mchp_resource_file_in)+1;
mchp_resource_file_generic = (char *)xcalloc (buffer_size,1);
snprintf (mchp_resource_file_generic, buffer_size, "%s", mchp_resource_file_in);
}
rib = read_device_rib (mchp_resource_file_generic, id);
if (rib == 0) {
error("Could not open resource file for: %qs at %qs", id, mchp_resource_file_generic);
return 0;
}
if (strcmp(rib->tool_chain,"XC32")) {
error("Invalid resource file\n");
close_rib();
return -1;
}
if (rib->field_count >= 4) {
int record;
int isr_names_max=0;
int isr_names_idx=0;
for (record = 0; move_to_record(record); record++) {
read_value(rik_string, &d);
if (strcmp(d.v.s, id) == 0) {
/* match */
*matched_id = d.v.s;
read_value(rik_int, &d);
if (d.v.i & IS_DEVICE_ID) {
pic32_device_mask = (d.v.i & (~IS_DEVICE_ID));
read_value(rik_int, &d);
pic32_num_register_sets = d.v.i;
read_value(rik_int, &d);
pic32_procid = d.v.i;
break;
}
}
}
}
pic32_loaded_device_mask = true;
return pic32_device_mask;
}
#endif
unsigned int validate_device_mask (char *id, char **matched_id, const char* mchp_resource_file_in);
unsigned int validate_device_mask (char *id, char **matched_id, const char* mchp_resource_file_in)
{
mchp_load_resource_info (id, matched_id, mchp_resource_file_in);
/* Disable options that the target does not support */
if (TARGET_MIPS16 && !(pic32_device_mask & HAS_MIPS16) && pic32_loaded_device_mask)
{
error ("The selected %qs device does not support the MIPS16 ISA mode (-mips16)", mchp_processor_string);
}
if (TARGET_MICROMIPS && !(pic32_device_mask & HAS_MICROMIPS) && pic32_loaded_device_mask)
{
error ("The selected %qs device does not support the microMIPS ISA mode (-mmicromips)", mchp_processor_string);
}
if ((pic32_device_mask & HAS_MICROMIPS) && !(pic32_device_mask & HAS_MIPS32R2) && pic32_loaded_device_mask)
{
/* This device supports _only_ the microMIPS ISA. Force MicroMIPS mode. */
target_flags |= MASK_MICROMIPS;
}
if (TARGET_SMALL_ISA && (pic32_device_mask & HAS_MICROMIPS) && pic32_loaded_device_mask)
{
target_flags |= MASK_MICROMIPS;
}
else if (TARGET_SMALL_ISA && (pic32_device_mask & HAS_MIPS16) && pic32_loaded_device_mask)
{
target_flags |= MASK_MIPS16;
}
if (TARGET_DSPR2 && !(pic32_device_mask & HAS_DSPR2) && pic32_loaded_device_mask)
{
warning (0, "The selected %qs device does not support the DSPr2 ASE (-mdspr2)", mchp_processor_string);
target_flags &= ~MASK_DSPR2;
target_flags &= ~MASK_DSP;
}
if (TARGET_MCU && !(pic32_device_mask & HAS_MCU) && pic32_loaded_device_mask)
{
warning (0, "The selected %qs device does not support the MCU ASE (-mmcu)", mchp_processor_string);
target_flags &= ~MASK_MCU;
}
/* Enable ASE features that the target does support */
if (!TARGET_DSPR2 && (pic32_device_mask & HAS_DSPR2))
{
/* Enable DSPr2 ASE by default when the target supports it */
target_flags |= MASK_DSP;
target_flags |= MASK_DSPR2;
}
if (TARGET_NO_DSPR2)
{
/* Override device defaults and disable DSPr2 ASE */
target_flags &= ~MASK_DSP;
target_flags &= ~MASK_DSPR2;
}
if (!TARGET_MCU && (pic32_device_mask & HAS_MCU))
{
/* Enable MCU ASE by default when the target supports it */
target_flags |= MASK_MCU;
}
if (TARGET_NO_MCU)
{
/* Override device defaults and disable MCU ASE */
target_flags &= ~MASK_MCU;
}
return pic32_device_mask;
}
#endif /* (MCHP_SKIP_RESOURCE_FILE) */
void
mchp_subtarget_override_options(void)
{
#if !defined(MCHP_SKIP_RESOURCE_FILE)
int mask;
/* DSP and microMIPS cannot coexist */
if (TARGET_DSP && TARGET_MIPS16) {
error ("unsupported combination: %s", "-mips16 -mdsp");
}
/* DSPr2 and microMIPS cannot coexist */
if (TARGET_DSPR2 && TARGET_MIPS16) {
error ("unsupported combination: %s", "-mips16 -mdspr2");
}
mask = validate_device_mask ((char*)mchp_processor_string, &mchp_target_cpu_id,
mchp_resource_file);
#endif
}
/* Validate the Microchip-specific command-line options. */
void
mchp_subtarget_override_options1 (void)
{
mips_code_readable = CODE_READABLE_PCREL;
/* If smart-io is explicitly disabled, make the size value 0 */
if (!TARGET_MCHP_SMARTIO)
{
mchp_io_size_val = 0;
}
if ((mchp_io_size_val < 0) || (mchp_io_size_val > 2))
{
warning (0, "Invalid smart-io level %d, assuming 1", mchp_io_size_val);
mchp_io_size_val = 1;
}
if (TARGET_LONG_CALLS)
{
TARGET_MCHP_SMARTIO = 0;
mchp_io_size_val = 0;
}
/* Switch on ABICALLS mode if -fpic or -fpie were
used, and the user hasn't explicitly disabled
these modes. */
if ((flag_pic || flag_pie) && !TARGET_ABICALLS
&& !(target_flags_explicit & MASK_ABICALLS)
&& mips_abi != ABI_EABI)
target_flags |= MASK_ABICALLS;
}
void
mchp_subtarget_override_options2 (void)
{
extern char **save_argv;
bool mips_base_mips16 = (mips_base_compression_flags & MASK_MIPS16) != 0;
bool mips_base_micromips = (mips_base_compression_flags & MASK_MICROMIPS) != 0;
if (mips_base_mips16 || mips_base_micromips)
{
flag_inline_small_functions = 0;
flag_inline_functions = 0;
flag_no_inline = 1;
}
if (mchp_profile_option) {
flag_inline_small_functions = 0;
flag_inline_functions = 0;
flag_no_inline = 1;
flag_optimize_sibling_calls = 0;
}
}
static void
mchp_output_configuration_words (void)
{
struct mchp_config_specification *spec;
fputs ("# Microchip Technology PIC32 MCU configuration words\n", asm_out_file);
for (spec = mchp_configuration_values ; spec ; spec = spec->next)
{
/* if there are referenced bits in the word, output its value */
if (spec->referenced_bits)
{
fprintf (asm_out_file, "# Configuration word @ 0x%08x\n", spec->word->address);
fprintf (asm_out_file, "\t.section\t.config_%08X, code, keep, address(0x%08X)\n",
spec->word->address, spec->word->address);
fprintf (asm_out_file, "\t.type\t__config_%08X, @object\n",
spec->word->address);
fprintf (asm_out_file, "\t.size\t__config_%08X, 4\n",
spec->word->address);
fprintf (asm_out_file, "__config_%08X:\n", spec->word->address);
fprintf (asm_out_file, "\t.word\t0x%08X\n", spec->value);
}
}
}
static void
mchp_output_ext_region_memory_info (void)
{
pic32_external_memory *m;
char printed = 0;
for (m = pic32_external_memory_head; m; m = m ->next)
{
fprintf(asm_out_file, "\n\t.memory _%s, origin(0x%x), size(0x%x)", m->name, m->origin, m->size);
printed = 1 ;
}
if (printed)
{
fprintf(asm_out_file, "\n\n");
}
}
void mchp_file_end (void)
{
if (!(flag_pic || flag_pie))
{
mchp_output_ext_region_memory_info();
}
if (flag_pic || flag_pie)
{
mchp_output_vector_dispatch_table_for_pic();
}
else
{
mchp_output_vector_dispatch_table();
}
mchp_output_configuration_words ();
mchp_output_frp_table();
}
/* Callback when a vector attribute is recognized. 'node' points
to the node to which the attribute is applied (which may not be a DECL).
If it is a decl, we modify in place, otherwise we need to create a copy
for any changes. 'name' is the identifier node specifying the attribute.
'args' is a TREE_LIST of the arguments to the attribute. 'flags' gives
us context information. We use 'no_add_attrs' to indicate whether the
attribute should be added to the decl/type or not; in this case, we
never want to keep the attribute since it's just an indicator to us to
add the vector.
Return is NULL_TREE since we're not modifying the attribute for other
decls/types */
tree
mchp_vector_attribute (tree *node, tree name ATTRIBUTE_UNUSED, tree args,
int flags ATTRIBUTE_UNUSED, bool *no_add_attrs)
{
tree decl = *node;
enum pic32_isa_mode isamode = pic32_isa_mips32r2;
/* If this attribute isn't on the actual function declaration, we
ignore it */
if (TREE_CODE (decl) != FUNCTION_DECL)
return NULL_TREE;
if (flag_generate_lto)
{
warning (0, "Attribute vector not supported with -flto option, this file will not participate in LTO");
flag_generate_lto = 0;
}
/* The vector attribute has a comma delimited list of vector #'s as
arguments. At least one must be present. */
gcc_assert (args);
while (args)
{
if (TREE_CODE (TREE_VALUE (args)) == INTEGER_CST)
{
/* The argument must be an integer constant between 0 and 255 */
if ((int)TREE_INT_CST_LOW (TREE_VALUE (args)) < 0 ||
(int)TREE_INT_CST_LOW (TREE_VALUE (args)) > 255)
{
*no_add_attrs = 1;
error ("Vector number must be an integer between 0 and 255");
return NULL_TREE;
}
if (mips_base_compression_flags & (MASK_MICROMIPS))
isamode = pic32_isa_micromips;
/* add the vector to the list of dispatch functions to emit */
mchp_add_vector_dispatch_entry (
IDENTIFIER_POINTER (DECL_NAME (*node)),
(int)TREE_INT_CST_LOW (TREE_VALUE (args)),
mips_far_type_p (TREE_TYPE (*node)),
isamode,
1);
}
else
{
if (TREE_CODE (TREE_VALUE (args)) == COMPOUND_EXPR)
{
mchp_vector_attribute_compound_expr (node, TREE_VALUE(args),
no_add_attrs);
}
else
{
*no_add_attrs = 1;
error ("Vector number must be an integer between 0 and 255");
return NULL_TREE;
}
}
args = TREE_CHAIN (args);
}
return NULL_TREE;
}
/* Handles compound expressions within the vector attribute list.
Called from mchp_vector_attribute(). */
static int
mchp_vector_attribute_compound_expr (tree *node, tree expr,
bool *no_add_attrs)
{
int len = 0;
enum pic32_isa_mode isamode = pic32_isa_mips32r2;
if (expr == NULL_TREE)
return 0;
for (; TREE_CODE (expr) == COMPOUND_EXPR; expr = TREE_OPERAND (expr, 1))
{
len += mchp_vector_attribute_compound_expr (node, TREE_OPERAND (expr, 0),
no_add_attrs);
}
if (TREE_CODE (expr) == INTEGER_CST)
{
/* The argument must be an integer constant between 0 and 255 */
if ((int)TREE_INT_CST_LOW (expr) < 0 ||
(int)TREE_INT_CST_LOW (expr) > 255)
{
*no_add_attrs = 1;
error ("Vector number must be an integer between 0 and 255");
return 0;
}
if (mips_base_compression_flags & (MASK_MICROMIPS))
isamode = pic32_isa_micromips;
/* add the vector to the list of dispatch functions to emit */
mchp_add_vector_dispatch_entry (
IDENTIFIER_POINTER (DECL_NAME (*node)),
(int)TREE_INT_CST_LOW (expr),
mips_far_type_p (TREE_TYPE (*node)),
isamode,
1);
}
++len;
return len;
}
/* Callback when a vector attribute is recognized. 'node' points
to the node to which the attribute is applied (which may not be a DECL).
If it is a decl, we modify in place, otherwise we need to create a copy