OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [config/] [arm/] [driver-arm.c] - Blame information for rev 744

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 709 jeremybenn
/* Subroutines for the gcc driver.
2
   Copyright (C) 2011 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
    {"0xc08", "armv7-a", "cortex-a8"},
41
    {"0xc09", "armv7-a", "cortex-a9"},
42
    {"0xc0f", "armv7-a", "cortex-a15"},
43
    {"0xc14", "armv7-r", "cortex-r4"},
44
    {"0xc15", "armv7-r", "cortex-r5"},
45
    {"0xc20", "armv6-m", "cortex-m0"},
46
    {"0xc21", "armv6-m", "cortex-m1"},
47
    {"0xc23", "armv7-m", "cortex-m3"},
48
    {"0xc24", "armv7e-m", "cortex-m4"},
49
    {NULL, NULL, NULL}
50
};
51
 
52
static struct {
53
  const char *vendor_no;
54
  const struct vendor_cpu *vendor_parts;
55
} vendors[] = {
56
    {"0x41", arm_cpu_table},
57
    {NULL, NULL}
58
};
59
 
60
/* This will be called by the spec parser in gcc.c when it sees
61
   a %:local_cpu_detect(args) construct.  Currently it will be called
62
   with either "arch", "cpu" or "tune" as argument depending on if
63
   -march=native, -mcpu=native or -mtune=native is to be substituted.
64
 
65
   It returns a string containing new command line parameters to be
66
   put at the place of the above two options, depending on what CPU
67
   this is executed.  E.g. "-march=armv7-a" on a Cortex-A8 for
68
   -march=native.  If the routine can't detect a known processor,
69
   the -march or -mtune option is discarded.
70
 
71
   ARGC and ARGV are set depending on the actual arguments given
72
   in the spec.  */
73
const char *
74
host_detect_local_cpu (int argc, const char **argv)
75
{
76
  const char *val = NULL;
77
  char buf[128];
78
  FILE *f = NULL;
79
  bool arch;
80
  const struct vendor_cpu *cpu_table = NULL;
81
 
82
  if (argc < 1)
83
    goto not_found;
84
 
85
  arch = strcmp (argv[0], "arch") == 0;
86
  if (!arch && strcmp (argv[0], "cpu") != 0 && strcmp (argv[0], "tune"))
87
    goto not_found;
88
 
89
  f = fopen ("/proc/cpuinfo", "r");
90
  if (f == NULL)
91
    goto not_found;
92
 
93
  while (fgets (buf, sizeof (buf), f) != NULL)
94
    {
95
      /* Ensure that CPU implementer is ARM (0x41).  */
96
      if (strncmp (buf, "CPU implementer", sizeof ("CPU implementer") - 1) == 0)
97
        {
98
          int i;
99
          for (i = 0; vendors[i].vendor_no != NULL; i++)
100
            if (strstr (buf, vendors[i].vendor_no) != NULL)
101
              {
102
                cpu_table = vendors[i].vendor_parts;
103
                break;
104
              }
105
        }
106
 
107
      /* Detect arch/cpu.  */
108
      if (strncmp (buf, "CPU part", sizeof ("CPU part") - 1) == 0)
109
        {
110
          int i;
111
 
112
          if (cpu_table == NULL)
113
            goto not_found;
114
 
115
          for (i = 0; cpu_table[i].part_no != NULL; i++)
116
            if (strstr (buf, cpu_table[i].part_no) != NULL)
117
              {
118
                val = arch ? cpu_table[i].arch_name : cpu_table[i].cpu_name;
119
                break;
120
              }
121
          break;
122
        }
123
    }
124
 
125
  fclose (f);
126
 
127
  if (val == NULL)
128
    goto not_found;
129
 
130
  return concat ("-m", argv[0], "=", val, NULL);
131
 
132
not_found:
133
  {
134
    unsigned int i;
135
    unsigned int opt;
136
    const char *search[] = {NULL, "arch"};
137
 
138
    if (f)
139
      fclose (f);
140
 
141
    search[0] = argv[0];
142
    for (opt = 0; opt < ARRAY_SIZE (search); opt++)
143
      for (i = 0; i < ARRAY_SIZE (configure_default_options); i++)
144
        if (strcmp (configure_default_options[i].name, search[opt]) == 0)
145
          return concat ("-m", search[opt], "=",
146
                         configure_default_options[i].value, NULL);
147
    return NULL;
148
  }
149
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.