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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [config/] [mips/] [driver-native.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) 2008, 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
 
25
#ifdef __sgi__
26
#include <invent.h>
27
#include <sys/sbd.h>
28
 
29
/* Cf. MIPS R10000 Microprocessor User Guide, Version 2.0, 14.13 Processor
30
   Revision Identifier (PRId) Register (15).
31
 
32
   http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi/hdwr/bks/SGI_Developer/books/R10K_UM/sgi_html/t5.Ver.2.0.book_279.html  */
33
 
34
static const struct cpu_types {
35
  int impl;
36
  const char *cpu;
37
} cpu_types[] = {
38
  { C0_IMP_R2000, "r2000" },
39
  { C0_IMP_R3000, "r3000" },
40
  { C0_IMP_R6000, "r6000" },
41
  { C0_IMP_R4000, "r4000" },
42
  { C0_IMP_R6000A, "r6000" },
43
  { C0_IMP_R10000, "r10000" },
44
  { C0_IMP_R12000, "r12000" },
45
  { C0_IMP_R14000, "r14000" },
46
  { C0_IMP_R8000,  "r8000" },
47
  { C0_IMP_R4600,  "r4600" },
48
  { C0_IMP_R4700,  "r4600" },
49
  { C0_IMP_R4650,  "r4650" },
50
  { C0_IMP_R5000,  "vr5000" },
51
  { C0_IMP_RM7000, "rm7000" },
52
  { C0_IMP_RM5271, "vr5000" },
53
  { 0, 0 }
54
};
55
 
56
static int
57
cputype (inventory_t *inv, void *arg)
58
{
59
  if (inv != NULL
60
      && inv->inv_class == INV_PROCESSOR
61
      && inv->inv_type == INV_CPUCHIP)
62
    {
63
      int i;
64
      /* inv_state is the cpu revision number.  */
65
      int impl = (inv->inv_state & C0_IMPMASK) >> C0_IMPSHIFT;
66
 
67
      for (i = 0; cpu_types[i].cpu != NULL; i++)
68
        if (cpu_types[i].impl == impl)
69
          {
70
            *((const char **) arg) = cpu_types[i].cpu;
71
            break;
72
          }
73
    }
74
  return 0;
75
}
76
#endif
77
 
78
/* This will be called by the spec parser in gcc.c when it sees
79
   a %:local_cpu_detect(args) construct.  Currently it will be called
80
   with either "arch" or "tune" as argument depending on if -march=native
81
   or -mtune=native is to be substituted.
82
 
83
   It returns a string containing new command line parameters to be
84
   put at the place of the above two options, depending on what CPU
85
   this is executed.  E.g. "-march=loongson2f" on a Loongson 2F for
86
   -march=native.  If the routine can't detect a known processor,
87
   the -march or -mtune option is discarded.
88
 
89
   ARGC and ARGV are set depending on the actual arguments given
90
   in the spec.  */
91
const char *
92
host_detect_local_cpu (int argc, const char **argv)
93
{
94
  const char *cpu = NULL;
95
#ifndef __sgi__
96
  char buf[128];
97
  FILE *f;
98
#endif
99
  bool arch;
100
 
101
  if (argc < 1)
102
    return NULL;
103
 
104
  arch = strcmp (argv[0], "arch") == 0;
105
  if (!arch && strcmp (argv[0], "tune"))
106
    return NULL;
107
 
108
#ifdef __sgi__
109
  scaninvent (cputype, &cpu);
110
#else
111
  f = fopen ("/proc/cpuinfo", "r");
112
  if (f == NULL)
113
    return NULL;
114
 
115
  while (fgets (buf, sizeof (buf), f) != NULL)
116
    if (strncmp (buf, "cpu model", sizeof ("cpu model") - 1) == 0)
117
      {
118
        if (strstr (buf, "Godson2 V0.2") != NULL
119
            || strstr (buf, "Loongson-2 V0.2") != NULL)
120
          cpu = "loongson2e";
121
        else if (strstr (buf, "Godson2 V0.3") != NULL
122
                 || strstr (buf, "Loongson-2 V0.3") != NULL)
123
          cpu = "loongson2f";
124
        else if (strstr (buf, "SiByte SB1") != NULL)
125
          cpu = "sb1";
126
        else if (strstr (buf, "R5000") != NULL)
127
          cpu = "r5000";
128
        else if (strstr (buf, "Octeon II") != NULL)
129
          cpu = "octeon2";
130
        else if (strstr (buf, "Octeon") != NULL)
131
          cpu = "octeon";
132
        break;
133
      }
134
 
135
  fclose (f);
136
#endif
137
 
138
  if (cpu == NULL)
139
    return NULL;
140
 
141
  return concat ("-m", argv[0], "=", cpu, NULL);
142
}

powered by: WebSVN 2.1.0

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