types.h

Go to the documentation of this file.
00001 
00041 #ifndef CPU_TYPES_H
00042 #define CPU_TYPES_H
00043 
00044 #include "detect.h"
00045 #include "attr.h"
00046 #include <cfg/compiler.h> /* for uintXX_t */
00047 
00048 #if CPU_I196
00049 
00050     typedef uint16_t cpu_flags_t; // FIXME
00051     typedef unsigned int cpu_stack_t;
00052     typedef cpu_stack_t cpu_aligned_stack_t;
00053     typedef unsigned int cpu_atomic_t;
00054     #warning Verify following constant
00055     #define SIZEOF_CPUSTACK_T 2
00056     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00057 
00058 #elif CPU_X86
00059 
00060     /* Get cpu_flags_t definition from the hosting environment. */
00061     #include <cfg/os.h>
00062     #if OS_EMBEDDED
00063         typedef uint32_t cpu_flags_t; // FIXME
00064     #endif /* OS_EMBEDDED */
00065 
00066     typedef uint32_t cpu_atomic_t;
00067 
00068     #if CPU_X86_64
00069         typedef uint64_t cpu_stack_t;
00070         typedef cpu_stack_t cpu_aligned_stack_t;
00071         #define SIZEOF_CPUSTACK_T 8
00072         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00073     #else
00074         typedef uint32_t cpu_stack_t;
00075         typedef cpu_stack_t cpu_aligned_stack_t;
00076         #define SIZEOF_CPUSTACK_T 4
00077         #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00078     #endif
00079 
00080 #elif CPU_ARM
00081 
00082     typedef uint32_t cpu_flags_t;
00083     typedef uint32_t cpu_atomic_t;
00084     typedef uint32_t cpu_stack_t;
00085     typedef uint64_t cpu_aligned_stack_t;
00086     #define SIZEOF_CPUSTACK_T 4
00087     #define SIZEOF_CPUALIGNED_T 8
00088 
00089 #elif CPU_PPC
00090 
00091     /* Get cpu_flags_t definition from the hosting environment. */
00092     #include <cfg/os.h>
00093     #if OS_EMBEDDED
00094         typedef uint32_t cpu_flags_t;
00095     #endif
00096 
00097     typedef uint32_t cpu_atomic_t;
00098     typedef uint32_t cpu_stack_t;
00099     typedef  cpu_stack_t cpu_aligned_stack_t;
00100     #define SIZEOF_CPUSTACK_T 4
00101     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00102 
00103 #elif CPU_DSP56K
00104 
00105     typedef uint16_t cpu_flags_t;
00106     typedef uint16_t cpu_atomic_t;
00107     typedef unsigned int cpu_stack_t;
00108     typedef cpu_stack_t cpu_aligned_stack_t;
00109     #warning Verify following costant
00110     #define SIZEOF_CPUSTACK_T 2
00111     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00112 
00113 #elif CPU_AVR
00114 
00115     typedef uint8_t cpu_flags_t;
00116     typedef uint8_t cpu_atomic_t;
00117     typedef uint8_t cpu_stack_t;
00118     typedef cpu_stack_t cpu_aligned_stack_t;
00119     #define SIZEOF_CPUSTACK_T 1
00120     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00121 
00122 #else
00123     #error No CPU_... defined.
00124 #endif
00125 
00143 #ifndef SIZEOF_CHAR
00144 #define SIZEOF_CHAR  1
00145 #endif
00146 
00147 #ifndef SIZEOF_SHORT
00148 #define SIZEOF_SHORT  2
00149 #endif
00150 
00151 #ifndef SIZEOF_INT
00152 #if CPU_REG_BITS < 32
00153     #define SIZEOF_INT  2
00154 #else
00155     #define SIZEOF_INT  4
00156 #endif
00157 #endif /* !SIZEOF_INT */
00158 
00159 #ifndef SIZEOF_LONG
00160 #if CPU_REG_BITS > 32
00161     #define SIZEOF_LONG  8
00162 #else
00163     #define SIZEOF_LONG  4
00164 #endif
00165 #endif
00166 
00167 #ifndef SIZEOF_PTR
00168 #if CPU_REG_BITS < 32
00169     #define SIZEOF_PTR   2
00170 #elif CPU_REG_BITS == 32
00171     #define SIZEOF_PTR   4
00172 #else /* CPU_REG_BITS > 32 */
00173     #define SIZEOF_PTR   8
00174 #endif
00175 #endif
00176 
00177 #ifndef SIZEOF_SIZE_T
00178 #if CPU_REG_BITS < 32
00179     #define SIZEOF_SIZE_T   2
00180 #elif CPU_REG_BITS == 32
00181     #define SIZEOF_SIZE_T   4
00182 #else /* CPU_REG_BITS > 32 */
00183     #define SIZEOF_SIZE_T   8
00184 #endif
00185 #endif
00186 
00187 #ifndef CPU_BITS_PER_CHAR
00188 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
00189 #endif
00190 
00191 #ifndef CPU_BITS_PER_SHORT
00192 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
00193 #endif
00194 
00195 #ifndef CPU_BITS_PER_INT
00196 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
00197 #endif
00198 
00199 #ifndef CPU_BITS_PER_LONG
00200 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
00201 #endif
00202 
00203 #ifndef CPU_BITS_PER_PTR
00204 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
00205 #endif
00206 
00207 
00208 /*\}*/
00209 
00210 #ifndef INT_MAX
00211     #define INT_MAX ((int)((unsigned int)~0 >> 1))
00212     #define INT_MIN (-INT_MAX - 1)
00213 #endif
00214 
00215 /* Sanity checks for the above definitions */
00216 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
00217 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
00218 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
00219 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
00220 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
00221 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
00222 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
00223 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
00224 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
00225 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
00226 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
00227 #ifdef __HAS_INT64_T__
00228 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
00229 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
00230 #endif
00231 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T);
00232 STATIC_ASSERT(sizeof(cpu_aligned_stack_t) == SIZEOF_CPUALIGNED_T);
00233 STATIC_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T);
00234 
00235 #endif /* CPU_TYPES_H */