]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/arm/driver-arm.c
driver-arm.c (arm_cpu_table): Add cortex-a12 entry.
[thirdparty/gcc.git] / gcc / config / arm / driver-arm.c
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "configargs.h"
25
26 struct vendor_cpu {
27 const char *part_no;
28 const char *arch_name;
29 const char *cpu_name;
30 };
31
32 static struct vendor_cpu arm_cpu_table[] = {
33 {"0x926", "armv5te", "arm926ej-s"},
34 {"0xa26", "armv5te", "arm1026ej-s"},
35 {"0xb02", "armv6k", "mpcore"},
36 {"0xb36", "armv6j", "arm1136j-s"},
37 {"0xb56", "armv6t2", "arm1156t2-s"},
38 {"0xb76", "armv6zk", "arm1176jz-s"},
39 {"0xc05", "armv7-a", "cortex-a5"},
40 {"0xc07", "armv7-a", "cortex-a7"},
41 {"0xc08", "armv7-a", "cortex-a8"},
42 {"0xc09", "armv7-a", "cortex-a9"},
43 {"0xc0d", "armv7-a", "cortex-a12"},
44 {"0xc0f", "armv7-a", "cortex-a15"},
45 {"0xc14", "armv7-r", "cortex-r4"},
46 {"0xc15", "armv7-r", "cortex-r5"},
47 {"0xc20", "armv6-m", "cortex-m0"},
48 {"0xc21", "armv6-m", "cortex-m1"},
49 {"0xc23", "armv7-m", "cortex-m3"},
50 {"0xc24", "armv7e-m", "cortex-m4"},
51 {NULL, NULL, NULL}
52 };
53
54 static struct {
55 const char *vendor_no;
56 const struct vendor_cpu *vendor_parts;
57 } vendors[] = {
58 {"0x41", arm_cpu_table},
59 {NULL, NULL}
60 };
61
62 /* This will be called by the spec parser in gcc.c when it sees
63 a %:local_cpu_detect(args) construct. Currently it will be called
64 with either "arch", "cpu" or "tune" as argument depending on if
65 -march=native, -mcpu=native or -mtune=native is to be substituted.
66
67 It returns a string containing new command line parameters to be
68 put at the place of the above two options, depending on what CPU
69 this is executed. E.g. "-march=armv7-a" on a Cortex-A8 for
70 -march=native. If the routine can't detect a known processor,
71 the -march or -mtune option is discarded.
72
73 ARGC and ARGV are set depending on the actual arguments given
74 in the spec. */
75 const char *
76 host_detect_local_cpu (int argc, const char **argv)
77 {
78 const char *val = NULL;
79 char buf[128];
80 FILE *f = NULL;
81 bool arch;
82 const struct vendor_cpu *cpu_table = NULL;
83
84 if (argc < 1)
85 goto not_found;
86
87 arch = strcmp (argv[0], "arch") == 0;
88 if (!arch && strcmp (argv[0], "cpu") != 0 && strcmp (argv[0], "tune"))
89 goto not_found;
90
91 f = fopen ("/proc/cpuinfo", "r");
92 if (f == NULL)
93 goto not_found;
94
95 while (fgets (buf, sizeof (buf), f) != NULL)
96 {
97 /* Ensure that CPU implementer is ARM (0x41). */
98 if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0)
99 {
100 int i;
101 for (i = 0; vendors[i].vendor_no != NULL; i++)
102 if (strstr (buf, vendors[i].vendor_no) != NULL)
103 {
104 cpu_table = vendors[i].vendor_parts;
105 break;
106 }
107 }
108
109 /* Detect arch/cpu. */
110 if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
111 {
112 int i;
113
114 if (cpu_table == NULL)
115 goto not_found;
116
117 for (i = 0; cpu_table[i].part_no != NULL; i++)
118 if (strstr (buf, cpu_table[i].part_no) != NULL)
119 {
120 val = arch ? cpu_table[i].arch_name : cpu_table[i].cpu_name;
121 break;
122 }
123 break;
124 }
125 }
126
127 fclose (f);
128
129 if (val == NULL)
130 goto not_found;
131
132 return concat ("-m", argv[0], "=", val, NULL);
133
134 not_found:
135 {
136 unsigned int i;
137 unsigned int opt;
138 const char *search[] = {NULL, "arch"};
139
140 if (f)
141 fclose (f);
142
143 search[0] = argv[0];
144 for (opt = 0; opt < ARRAY_SIZE (search); opt++)
145 for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
146 if (strcmp (configure_default_options[i].name, search[opt]) == 0)
147 return concat ("-m", search[opt], "=",
148 configure_default_options[i].value, NULL);
149 return NULL;
150 }
151 }