a2248cf7846f7d2f153e782bd1fc30832e565752
[bertos.git] / cfg / cpu_detect.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 2004 Giovanni Bajo
6  * This file is part of DevLib - See README.devlib for information.
7  * -->
8  *
9  * \brief CPU detection through special preprocessor macros
10  */
11 #ifndef CPU_DETECT_H
12 #define CPU_DETECT_H
13
14 /* sparse? */
15 #ifdef __CHECKER__
16         /* Any random CPU will do */
17         #define __arm__
18 #endif
19
20 #if defined(__arm__) /* GCC */ \
21         || defined(__ARM4TM__) /* IAR: defined for all cores >= 4tm */
22         #define CPU_ARM                 1
23         #define CPU_ID                  arm
24 #else
25         #define CPU_ARM                 0
26 #endif
27
28 #if (defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)) \
29         && !defined(__ARM4TM__) /* IAR: if not ARM assume I196 */
30         #define CPU_I196                1
31         #define CPU_ID                  i196
32 #else
33         #define CPU_I196                0
34 #endif
35
36 #if defined(__i386__) /* GCC */ \
37         || (defined(_M_IX86) && !defined(_WIN64)) /* MSVC */
38         #define CPU_X86                 1
39         #define CPU_X86_32              1
40         #define CPU_X86_64              0
41         #define CPU_ID                  x86
42 #elif defined(__x86_64__) /* GCC */ \
43         || (defined(_M_IX86) && defined(_WIN64)) /* MSVC */
44         #define CPU_X86                 1
45         #define CPU_X86_32              0
46         #define CPU_X86_64              1
47         #define CPU_ID                  x86
48 #else
49         #define CPU_X86                 0
50         #define CPU_I386                0
51         #define CPU_X86_64              0
52 #endif
53
54 #if defined (_ARCH_PPC) || defined(_ARCH_PPC64)
55         #define CPU_PPC                 1
56         #define CPU_ID                  ppc
57         #if defined(_ARCH_PPC)
58                 #define CPU_PPC32       1
59         #else
60                 #define CPU_PPC32       0
61         #endif
62         #if defined(_ARCH_PPC64)
63                 #define CPU_PPC64       1
64         #else
65                 #define CPU_PPC64       0
66         #endif
67 #else
68         #define CPU_PPC                 0
69         #define CPU_PPC32               0
70         #define CPU_PPC64               0
71 #endif
72
73 #if defined(__m56800E__) || defined(__m56800__)
74         #define CPU_DSP56K              1
75         #define CPU_ID                  dsp56k
76 #else
77         #define CPU_DSP56K              0
78 #endif
79
80 #if defined (__AVR__)
81         #define CPU_AVR                 1
82         #define CPU_ID                  avr
83
84         #if defined(__AVR_ATmega64__)
85                 #define CPU_AVR_ATMEGA64    1
86         #else
87                 #define CPU_AVR_ATMEGA64    0
88         #endif
89
90         #if defined(__AVR_ATmega103__)
91                 #define CPU_AVR_ATMEGA103   1
92         #else
93                 #define CPU_AVR_ATMEGA103   0
94         #endif
95
96         #if defined(__AVR_ATmega128__)
97                 #define CPU_AVR_ATMEGA128   1
98         #else
99                 #define CPU_AVR_ATMEGA128   0
100         #endif
101
102         #if defined(__AVR_ATmega8__)
103                 #define CPU_AVR_ATMEGA8     1
104         #else
105                 #define CPU_AVR_ATMEGA8     0
106         #endif
107
108         #if defined(__AVR_ATmega168__)
109                 #define CPU_AVR_ATMEGA168   1
110         #else
111                 #define CPU_AVR_ATMEGA168   0
112         #endif
113
114         #if defined(__AVR_ATmega1281__)
115                 #define CPU_AVR_ATMEGA1281  1
116         #else
117                 #define CPU_AVR_ATMEGA1281  0
118         #endif
119 #else
120         #define CPU_AVR                 0
121         #define CPU_AVR_ATMEGA8         0
122         #define CPU_AVR_ATMEGA168       0
123         #define CPU_AVR_ATMEGA64        0
124         #define CPU_AVR_ATMEGA103       0
125         #define CPU_AVR_ATMEGA128       0
126         #define CPU_AVR_ATMEGA1281      0
127 #endif
128
129
130 /* Self-check for the detection: only one CPU must be detected */
131 #if CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR == 0
132         #error Unknown CPU
133 #elif !defined(CPU_ID)
134         #error CPU_ID not defined
135 #elif CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR != 1
136         #error Internal CPU configuration error
137 #endif
138
139
140 #endif /* CPU_DETECT_H */