Add kfile_off_t typedef, and use it.
[bertos.git] / 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, 2006, 2007 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
44         #if defined(__ARM_AT91SAM7S32__)
45                 #define CPU_ARM_AT91         1
46                 #define CPU_ARM_AT91SAM7S32  1
47         #else
48                 #define CPU_ARM_AT91SAM7S32  0
49         #endif
50
51         #if defined(__ARM_AT91SAM7S64__)
52                 #define CPU_ARM_AT91         1
53                 #define CPU_ARM_AT91SAM7S64  1
54         #else
55                 #define CPU_ARM_AT91SAM7S64  0
56         #endif
57
58         #if defined(__ARM_AT91SAM7S128__)
59                 #define CPU_ARM_AT91         1
60                 #define CPU_ARM_AT91SAM7S128 1
61         #else
62                 #define CPU_ARM_AT91SAM7S128 0
63         #endif
64
65         #if defined(__ARM_AT91SAM7S256__)
66                 #define CPU_ARM_AT91         1
67                 #define CPU_ARM_AT91SAM7S256 1
68         #else
69                 #define CPU_ARM_AT91SAM7S256 0
70         #endif
71
72         #if defined(CPU_ARM_AT91)
73                 #if CPU_ARM_AT91SAM7S32 + CPU_ARM_AT91SAM7S64 \
74                 + CPU_ARM_AT91SAM7S128 + CPU_ARM_AT91SAM7S256 != 1
75                         #error ARM CPU configuration error
76                 #endif
77         /* #elif Add other ARM families here */
78         #else
79                 #define CPU_ATM_AT91         0
80         #endif
81
82
83         #if CPU_ARM_AT91 + 0 /* Add other ARM families here */ != 1
84                 #error ARM CPU configuration error
85         #endif
86 #else
87         #define CPU_ARM                 0
88
89         /* ARM Families */
90         #define CPU_ARM_AT91            0
91
92         /* ARM CPUs */
93         #define CPU_ARM_AT91SAM7S32     0
94         #define CPU_ARM_AT91SAM7S64     0
95         #define CPU_ARM_AT91SAM7S128    0
96         #define CPU_ARM_AT91SAM7S256    0
97 #endif
98
99 #if (defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)) \
100         && !defined(__ARM4TM__) /* IAR: if not ARM assume I196 */
101         #warning Assuming CPU is I196
102         #define CPU_I196                1
103         #define CPU_ID                  i196
104 #else
105         #define CPU_I196                0
106 #endif
107
108 #if defined(__i386__) /* GCC */ \
109         || (defined(_M_IX86) && !defined(_WIN64)) /* MSVC */
110         #define CPU_X86                 1
111         #define CPU_X86_32              1
112         #define CPU_X86_64              0
113         #define CPU_ID                  x86
114 #elif defined(__x86_64__) /* GCC */ \
115         || (defined(_M_IX86) && defined(_WIN64)) /* MSVC */
116         #define CPU_X86                 1
117         #define CPU_X86_32              0
118         #define CPU_X86_64              1
119         #define CPU_ID                  x86
120 #else
121         #define CPU_X86                 0
122         #define CPU_I386                0
123         #define CPU_X86_64              0
124 #endif
125
126 #if defined (_ARCH_PPC) || defined(_ARCH_PPC64)
127         #define CPU_PPC                 1
128         #define CPU_ID                  ppc
129         #if defined(_ARCH_PPC)
130                 #define CPU_PPC32       1
131         #else
132                 #define CPU_PPC32       0
133         #endif
134         #if defined(_ARCH_PPC64)
135                 #define CPU_PPC64       1
136         #else
137                 #define CPU_PPC64       0
138         #endif
139 #else
140         #define CPU_PPC                 0
141         #define CPU_PPC32               0
142         #define CPU_PPC64               0
143 #endif
144
145 #if defined(__m56800E__) || defined(__m56800__)
146         #define CPU_DSP56K              1
147         #define CPU_ID                  dsp56k
148 #else
149         #define CPU_DSP56K              0
150 #endif
151
152 #if defined (__AVR__)
153         #define CPU_AVR                 1
154         #define CPU_ID                  avr
155
156         #if defined(__AVR_ATmega64__)
157                 #define CPU_AVR_ATMEGA64    1
158         #else
159                 #define CPU_AVR_ATMEGA64    0
160         #endif
161
162         #if defined(__AVR_ATmega103__)
163                 #define CPU_AVR_ATMEGA103   1
164         #else
165                 #define CPU_AVR_ATMEGA103   0
166         #endif
167
168         #if defined(__AVR_ATmega128__)
169                 #define CPU_AVR_ATMEGA128   1
170         #else
171                 #define CPU_AVR_ATMEGA128   0
172         #endif
173
174         #if defined(__AVR_ATmega8__)
175                 #define CPU_AVR_ATMEGA8     1
176         #else
177                 #define CPU_AVR_ATMEGA8     0
178         #endif
179
180         #if defined(__AVR_ATmega168__)
181                 #define CPU_AVR_ATMEGA168   1
182         #else
183                 #define CPU_AVR_ATMEGA168   0
184         #endif
185
186         #if defined(__AVR_ATmega1281__)
187                 #define CPU_AVR_ATMEGA1281  1
188         #else
189                 #define CPU_AVR_ATMEGA1281  0
190         #endif
191
192         #if CPU_AVR_ATMEGA64 + CPU_AVR_ATMEGA103 + CPU_AVR_ATMEGA128 \
193           + CPU_AVR_ATMEGA8 + CPU_AVR_ATMEGA168 + CPU_AVR_ATMEGA1281 != 1
194                 #error AVR CPU configuration error
195         #endif
196 #else
197         #define CPU_AVR                 0
198         #define CPU_AVR_ATMEGA8         0
199         #define CPU_AVR_ATMEGA168       0
200         #define CPU_AVR_ATMEGA64        0
201         #define CPU_AVR_ATMEGA103       0
202         #define CPU_AVR_ATMEGA128       0
203         #define CPU_AVR_ATMEGA1281      0
204 #endif
205
206
207 /* Self-check for the detection: only one CPU must be detected */
208 #if CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR == 0
209         #error Unknown CPU
210 #elif !defined(CPU_ID)
211         #error CPU_ID not defined
212 #elif CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR != 1
213         #error Internal CPU configuration error
214 #endif
215
216
217 #endif /* CPU_DETECT_H */