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)
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/>. */
22 #include "coretypes.h"
24 #include "configargs.h"
28 const char *arch_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"},
54 const char *vendor_no
;
55 const struct vendor_cpu
*vendor_parts
;
57 {"0x41", arm_cpu_table
},
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
75 host_detect_local_cpu (int argc
, const char **argv
)
77 const char *val
= NULL
;
81 const struct vendor_cpu
*cpu_table
= NULL
;
86 arch
= strcmp (argv
[0], "arch") == 0;
87 if (!arch
&& strcmp (argv
[0], "cpu") != 0 && strcmp (argv
[0], "tune"))
90 f
= fopen ("/proc/cpuinfo", "r");
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)
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
;
108 /* Detect arch/cpu. */
109 if (strncmp (buf
, "CPU part", sizeof ("CPU part") - 1) == 0)
113 if (cpu_table
== NULL
)
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
;
131 return concat ("-m", argv
[0], "=", val
, NULL
);
137 const char *search
[] = {NULL
, "arch"};
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
);