Rename myself
[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 cpuflags_t; // FIXME
51         typedef unsigned int cpustack_t;
52         #warning Verify following constant
53         #define SIZEOF_CPUSTACK_T 2
54
55 #elif CPU_X86
56
57         /* Get IRQ_* definitions from the hosting environment. */
58         #include <cfg/os.h>
59         #if OS_EMBEDDED
60                 typedef uint32_t cpuflags_t; // FIXME
61         #endif /* OS_EMBEDDED */
62
63         #if CPU_X86_64
64                 typedef uint64_t cpustack_t;
65                 #define SIZEOF_CPUSTACK_T 8
66         #else
67                 typedef uint32_t cpustack_t;
68                 #define SIZEOF_CPUSTACK_T 4
69         #endif
70
71 #elif CPU_ARM
72
73         typedef uint32_t cpuflags_t;
74         typedef uint32_t cpustack_t;
75         #define SIZEOF_CPUSTACK_T 4
76
77 #elif CPU_PPC
78
79         typedef uint32_t cpuflags_t; // FIXME
80         typedef uint32_t cpustack_t; // FIXME
81         #define SIZEOF_CPUSTACK_T 4
82
83 #elif CPU_DSP56K
84
85         typedef uint16_t cpuflags_t;
86         typedef unsigned int cpustack_t;
87         #warning Verify following costant
88         #define SIZEOF_CPUSTACK_T 2
89
90 #elif CPU_AVR
91
92         typedef uint8_t cpuflags_t;
93         typedef uint8_t cpustack_t;
94         #define SIZEOF_CPUSTACK_T 1
95
96 #else
97         #error No CPU_... defined.
98 #endif
99
100 /**
101  * \name Default type sizes.
102  *
103  * These defaults are reasonable for most 16/32bit machines.
104  * Some of these macros may be overridden by CPU-specific code above.
105  *
106  * ANSI C requires that the following equations be true:
107  * \code
108  *   sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
109  *   sizeof(float) <= sizeof(double)
110  *   CPU_BITS_PER_CHAR  >= 8
111  *   CPU_BITS_PER_SHORT >= 8
112  *   CPU_BITS_PER_INT   >= 16
113  *   CPU_BITS_PER_LONG  >= 32
114  * \endcode
115  * \{
116  */
117 #ifndef SIZEOF_CHAR
118 #define SIZEOF_CHAR  1
119 #endif
120
121 #ifndef SIZEOF_SHORT
122 #define SIZEOF_SHORT  2
123 #endif
124
125 #ifndef SIZEOF_INT
126 #if CPU_REG_BITS < 32
127         #define SIZEOF_INT  2
128 #else
129         #define SIZEOF_INT  4
130 #endif
131 #endif /* !SIZEOF_INT */
132
133 #ifndef SIZEOF_LONG
134 #if CPU_REG_BITS > 32
135         #define SIZEOF_LONG  8
136 #else
137         #define SIZEOF_LONG  4
138 #endif
139 #endif
140
141 #ifndef SIZEOF_PTR
142 #if CPU_REG_BITS < 32
143         #define SIZEOF_PTR   2
144 #elif CPU_REG_BITS == 32
145         #define SIZEOF_PTR   4
146 #else /* CPU_REG_BITS > 32 */
147         #define SIZEOF_PTR   8
148 #endif
149 #endif
150
151 #ifndef CPU_BITS_PER_CHAR
152 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
153 #endif
154
155 #ifndef CPU_BITS_PER_SHORT
156 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
157 #endif
158
159 #ifndef CPU_BITS_PER_INT
160 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
161 #endif
162
163 #ifndef CPU_BITS_PER_LONG
164 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
165 #endif
166
167 #ifndef CPU_BITS_PER_PTR
168 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
169 #endif
170
171
172 /*\}*/
173
174 /* Sanity checks for the above definitions */
175 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
176 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
177 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
178 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
179 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
180 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
181 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
182 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
183 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
184 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
185 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
186 #ifdef __HAS_INT64_T__
187 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
188 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
189 #endif
190 STATIC_ASSERT(sizeof(cpustack_t) == SIZEOF_CPUSTACK_T);
191
192
193 #endif /* CPU_TYPES_H */