Remove unneeded macros. Remove empty header.
[bertos.git] / bertos / cpu / types.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-specific type definitions.
35  *
36  * \author Giovanni Bajo <rasky@develer.com>
37  * \author Bernie Innocenti <bernie@codewiz.org>
38  * \author Stefano Fedrigo <aleph@develer.com>
39  * \author Francesco Sacchi <batt@develer.com>
40  */
41 #ifndef CPU_TYPES_H
42 #define CPU_TYPES_H
43
44 #include "detect.h"
45 #include "attr.h"
46 #include <cfg/compiler.h> /* for uintXX_t */
47
48 #if CPU_I196
49
50         typedef uint16_t cpu_flags_t; // FIXME
51         typedef unsigned int cpu_stack_t;
52         typedef cpu_stack_t cpu_aligned_stack_t;
53         typedef unsigned int cpu_atomic_t;
54         #warning Verify following constant
55         #define SIZEOF_CPUSTACK_T 2
56         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
57
58 #elif CPU_X86
59
60         /* Get cpu_flags_t definition from the hosting environment. */
61         #include <cfg/os.h>
62         #if OS_EMBEDDED
63                 typedef uint32_t cpu_flags_t; // FIXME
64         #endif /* OS_EMBEDDED */
65
66         typedef uint32_t cpu_atomic_t;
67
68         #if CPU_X86_64
69                 typedef uint64_t cpu_stack_t;
70                 typedef cpu_stack_t cpu_aligned_stack_t;
71                 #define SIZEOF_CPUSTACK_T 8
72                 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
73         #else
74                 typedef uint32_t cpu_stack_t;
75                 typedef cpu_stack_t cpu_aligned_stack_t;
76                 #define SIZEOF_CPUSTACK_T 4
77                 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
78         #endif
79
80 #elif CPU_ARM || CPU_CM3
81
82         typedef uint32_t cpu_flags_t;
83         typedef uint32_t cpu_atomic_t;
84         typedef uint32_t cpu_stack_t;
85         #define SIZEOF_CPUSTACK_T 4
86
87         typedef uint64_t cpu_aligned_stack_t;
88         #define SIZEOF_CPUALIGNED_T 8
89
90 #elif CPU_PPC
91
92         /* Get cpu_flags_t definition from the hosting environment. */
93         #include <cfg/os.h>
94         #if OS_EMBEDDED
95                 typedef uint32_t cpu_flags_t;
96         #endif
97
98         typedef uint32_t cpu_atomic_t;
99         typedef uint32_t cpu_stack_t;
100         typedef  cpu_stack_t cpu_aligned_stack_t;
101         #define SIZEOF_CPUSTACK_T 4
102         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
103
104 #elif CPU_DSP56K
105
106         typedef uint16_t cpu_flags_t;
107         typedef uint16_t cpu_atomic_t;
108         typedef unsigned int cpu_stack_t;
109         typedef cpu_stack_t cpu_aligned_stack_t;
110         #warning Verify following costant
111         #define SIZEOF_CPUSTACK_T 2
112         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
113
114 #elif CPU_AVR
115
116         typedef uint8_t cpu_flags_t;
117         typedef uint8_t cpu_atomic_t;
118         typedef uint8_t cpu_stack_t;
119         typedef cpu_stack_t cpu_aligned_stack_t;
120         #define SIZEOF_CPUSTACK_T 1
121         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
122
123 #else
124         #error No CPU_... defined.
125 #endif
126
127 /**
128  * \name Default type sizes.
129  *
130  * These defaults are reasonable for most 16/32bit machines.
131  * Some of these macros may be overridden by CPU-specific code above.
132  *
133  * ANSI C requires that the following equations be true:
134  * \code
135  *   sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
136  *   sizeof(float) <= sizeof(double)
137  *   CPU_BITS_PER_CHAR  >= 8
138  *   CPU_BITS_PER_SHORT >= 8
139  *   CPU_BITS_PER_INT   >= 16
140  *   CPU_BITS_PER_LONG  >= 32
141  * \endcode
142  * \{
143  */
144 #ifndef SIZEOF_CHAR
145 #define SIZEOF_CHAR  1
146 #endif
147
148 #ifndef SIZEOF_SHORT
149 #define SIZEOF_SHORT  2
150 #endif
151
152 #ifndef SIZEOF_INT
153 #if CPU_REG_BITS < 32
154         #define SIZEOF_INT  2
155 #else
156         #define SIZEOF_INT  4
157 #endif
158 #endif /* !SIZEOF_INT */
159
160 #ifndef SIZEOF_LONG
161 #if CPU_REG_BITS > 32
162         #define SIZEOF_LONG  8
163 #else
164         #define SIZEOF_LONG  4
165 #endif
166 #endif
167
168 #ifndef SIZEOF_PTR
169 #if CPU_REG_BITS < 32
170         #define SIZEOF_PTR   2
171 #elif CPU_REG_BITS == 32
172         #define SIZEOF_PTR   4
173 #else /* CPU_REG_BITS > 32 */
174         #define SIZEOF_PTR   8
175 #endif
176 #endif
177
178 #ifndef SIZEOF_SIZE_T
179 #if CPU_REG_BITS < 32
180         #define SIZEOF_SIZE_T   2
181 #elif CPU_REG_BITS == 32
182         #define SIZEOF_SIZE_T   4
183 #else /* CPU_REG_BITS > 32 */
184         #define SIZEOF_SIZE_T   8
185 #endif
186 #endif
187
188 #ifndef CPU_BITS_PER_CHAR
189 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
190 #endif
191
192 #ifndef CPU_BITS_PER_SHORT
193 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
194 #endif
195
196 #ifndef CPU_BITS_PER_INT
197 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
198 #endif
199
200 #ifndef CPU_BITS_PER_LONG
201 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
202 #endif
203
204 #ifndef CPU_BITS_PER_PTR
205 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
206 #endif
207
208
209 /*\}*/
210
211 #ifndef INT_MAX
212         #define INT_MAX ((int)((unsigned int)~0 >> 1))
213         #define INT_MIN (-INT_MAX - 1)
214 #endif
215
216 /* Sanity checks for the above definitions */
217 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
218 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
219 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
220 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
221 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
222 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
223 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
224 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
225 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
226 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
227 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
228 #ifdef __HAS_INT64_T__
229 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
230 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
231 #endif
232 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T);
233 STATIC_ASSERT(sizeof(cpu_aligned_stack_t) == SIZEOF_CPUALIGNED_T);
234 STATIC_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T);
235
236
237 /**
238  * Macros for hardware access, both direct and via the bit-band region.
239  */
240 /*\{*/
241 #define HWREG(x)   (*((reg32_t *)(x)))
242 #define HWREGH(x)  (*((reg16_t *)(x)))
243 #define HWREGB(x)  (*((reg8_t *)(x)))
244 /*\}*/
245
246 #endif /* CPU_TYPES_H */