Update Copyright years for files modified in 2011 and/or 2012.
[official-gcc.git] / gcc / config / arm / driver-arm.c
blob03e8c90da61d5d8d5391aec7fada7f9097bb05fa
1 /* Subroutines for the gcc driver.
2 Copyright (C) 2011, 2012 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "tm.h"
24 #include "configargs.h"
26 struct vendor_cpu {
27 const char *part_no;
28 const char *arch_name;
29 const char *cpu_name;
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 {"0xc0f", "armv7-a", "cortex-a15"},
44 {"0xc14", "armv7-r", "cortex-r4"},
45 {"0xc15", "armv7-r", "cortex-r5"},
46 {"0xc20", "armv6-m", "cortex-m0"},
47 {"0xc21", "armv6-m", "cortex-m1"},
48 {"0xc23", "armv7-m", "cortex-m3"},
49 {"0xc24", "armv7e-m", "cortex-m4"},
50 {NULL, NULL, NULL}
53 static struct {
54 const char *vendor_no;
55 const struct vendor_cpu *vendor_parts;
56 } vendors[] = {
57 {"0x41", arm_cpu_table},
58 {NULL, NULL}
61 /* This will be called by the spec parser in gcc.c when it sees
62 a %:local_cpu_detect(args) construct. Currently it will be called
63 with either "arch", "cpu" or "tune" as argument depending on if
64 -march=native, -mcpu=native or -mtune=native is to be substituted.
66 It returns a string containing new command line parameters to be
67 put at the place of the above two options, depending on what CPU
68 this is executed. E.g. "-march=armv7-a" on a Cortex-A8 for
69 -march=native. If the routine can't detect a known processor,
70 the -march or -mtune option is discarded.
72 ARGC and ARGV are set depending on the actual arguments given
73 in the spec. */
74 const char *
75 host_detect_local_cpu (int argc, const char **argv)
77 const char *val = NULL;
78 char buf[128];
79 FILE *f = NULL;
80 bool arch;
81 const struct vendor_cpu *cpu_table = NULL;
83 if (argc < 1)
84 goto not_found;
86 arch = strcmp (argv[0], "arch") == 0;
87 if (!arch && strcmp (argv[0], "cpu") != 0 && strcmp (argv[0], "tune"))
88 goto not_found;
90 f = fopen ("/proc/cpuinfo", "r");
91 if (f == NULL)
92 goto not_found;
94 while (fgets (buf, sizeof (buf), f) != NULL)
96 /* Ensure that CPU implementer is ARM (0x41). */
97 if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0)
99 int i;
100 for (i = 0; vendors[i].vendor_no != NULL; i++)
101 if (strstr (buf, vendors[i].vendor_no) != NULL)
103 cpu_table = vendors[i].vendor_parts;
104 break;
108 /* Detect arch/cpu. */
109 if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
111 int i;
113 if (cpu_table == NULL)
114 goto not_found;
116 for (i = 0; cpu_table[i].part_no != NULL; i++)
117 if (strstr (buf, cpu_table[i].part_no) != NULL)
119 val = arch ? cpu_table[i].arch_name : cpu_table[i].cpu_name;
120 break;
122 break;
126 fclose (f);
128 if (val == NULL)
129 goto not_found;
131 return concat ("-m", argv[0], "=", val, NULL);
133 not_found:
135 unsigned int i;
136 unsigned int opt;
137 const char *search[] = {NULL, "arch"};
139 if (f)
140 fclose (f);
142 search[0] = argv[0];
143 for (opt = 0; opt < ARRAY_SIZE (search); opt++)
144 for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
145 if (strcmp (configure_default_options[i].name, search[opt]) == 0)
146 return concat ("-m", search[opt], "=",
147 configure_default_options[i].value, NULL);
148 return NULL;