Removed 'This file is part of DevLib ...'
[bertos.git] / cfg / cpu_detect.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos 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 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program 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 this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2004 Giovanni Bajo
31  *
32  * -->
33  *
34  * \brief CPU detection through special preprocessor macros
35  */
36 #ifndef CPU_DETECT_H
37 #define CPU_DETECT_H
38
39 #if defined(__arm__) /* GCC */ \
40         || defined(__ARM4TM__) /* IAR: defined for all cores >= 4tm */
41         #define CPU_ARM                 1
42         #define CPU_ID                  arm
43 #else
44         #define CPU_ARM                 0
45 #endif
46
47 #if (defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)) \
48         && !defined(__ARM4TM__) /* IAR: if not ARM assume I196 */
49         #warning Assuming CPU is I196
50         #define CPU_I196                1
51         #define CPU_ID                  i196
52 #else
53         #define CPU_I196                0
54 #endif
55
56 #if defined(__i386__) /* GCC */ \
57         || (defined(_M_IX86) && !defined(_WIN64)) /* MSVC */
58         #define CPU_X86                 1
59         #define CPU_X86_32              1
60         #define CPU_X86_64              0
61         #define CPU_ID                  x86
62 #elif defined(__x86_64__) /* GCC */ \
63         || (defined(_M_IX86) && defined(_WIN64)) /* MSVC */
64         #define CPU_X86                 1
65         #define CPU_X86_32              0
66         #define CPU_X86_64              1
67         #define CPU_ID                  x86
68 #else
69         #define CPU_X86                 0
70         #define CPU_I386                0
71         #define CPU_X86_64              0
72 #endif
73
74 #if defined (_ARCH_PPC) || defined(_ARCH_PPC64)
75         #define CPU_PPC                 1
76         #define CPU_ID                  ppc
77         #if defined(_ARCH_PPC)
78                 #define CPU_PPC32       1
79         #else
80                 #define CPU_PPC32       0
81         #endif
82         #if defined(_ARCH_PPC64)
83                 #define CPU_PPC64       1
84         #else
85                 #define CPU_PPC64       0
86         #endif
87 #else
88         #define CPU_PPC                 0
89         #define CPU_PPC32               0
90         #define CPU_PPC64               0
91 #endif
92
93 #if defined(__m56800E__) || defined(__m56800__)
94         #define CPU_DSP56K              1
95         #define CPU_ID                  dsp56k
96 #else
97         #define CPU_DSP56K              0
98 #endif
99
100 #if defined (__AVR__)
101         #define CPU_AVR                 1
102         #define CPU_ID                  avr
103
104         #if defined(__AVR_ATmega64__)
105                 #define CPU_AVR_ATMEGA64    1
106         #else
107                 #define CPU_AVR_ATMEGA64    0
108         #endif
109
110         #if defined(__AVR_ATmega103__)
111                 #define CPU_AVR_ATMEGA103   1
112         #else
113                 #define CPU_AVR_ATMEGA103   0
114         #endif
115
116         #if defined(__AVR_ATmega128__)
117                 #define CPU_AVR_ATMEGA128   1
118         #else
119                 #define CPU_AVR_ATMEGA128   0
120         #endif
121
122         #if defined(__AVR_ATmega8__)
123                 #define CPU_AVR_ATMEGA8     1
124         #else
125                 #define CPU_AVR_ATMEGA8     0
126         #endif
127
128         #if defined(__AVR_ATmega168__)
129                 #define CPU_AVR_ATMEGA168   1
130         #else
131                 #define CPU_AVR_ATMEGA168   0
132         #endif
133
134         #if defined(__AVR_ATmega1281__)
135                 #define CPU_AVR_ATMEGA1281  1
136         #else
137                 #define CPU_AVR_ATMEGA1281  0
138         #endif
139 #else
140         #define CPU_AVR                 0
141         #define CPU_AVR_ATMEGA8         0
142         #define CPU_AVR_ATMEGA168       0
143         #define CPU_AVR_ATMEGA64        0
144         #define CPU_AVR_ATMEGA103       0
145         #define CPU_AVR_ATMEGA128       0
146         #define CPU_AVR_ATMEGA1281      0
147 #endif
148
149
150 /* Self-check for the detection: only one CPU must be detected */
151 #if CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR == 0
152         #error Unknown CPU
153 #elif !defined(CPU_ID)
154         #error CPU_ID not defined
155 #elif CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR != 1
156         #error Internal CPU configuration error
157 #endif
158
159
160 #endif /* CPU_DETECT_H */