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 || CPU_CM3
00081 
00082     typedef uint32_t cpu_flags_t;
00083     typedef uint32_t cpu_atomic_t;
00084     typedef uint32_t cpu_stack_t;
00085     #define SIZEOF_CPUSTACK_T 4
00086 
00087     typedef uint64_t cpu_aligned_stack_t;
00088     #define SIZEOF_CPUALIGNED_T 8
00089 
00090 #elif CPU_PPC
00091 
00092     /* Get cpu_flags_t definition from the hosting environment. */
00093     #include <cfg/os.h>
00094     #if OS_EMBEDDED
00095         typedef uint32_t cpu_flags_t;
00096     #endif
00097 
00098     typedef uint32_t cpu_atomic_t;
00099     typedef uint32_t cpu_stack_t;
00100     typedef  cpu_stack_t cpu_aligned_stack_t;
00101     #define SIZEOF_CPUSTACK_T 4
00102     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00103 
00104 #elif CPU_DSP56K
00105 
00106     typedef uint16_t cpu_flags_t;
00107     typedef uint16_t cpu_atomic_t;
00108     typedef unsigned int cpu_stack_t;
00109     typedef cpu_stack_t cpu_aligned_stack_t;
00110     #warning Verify following costant
00111     #define SIZEOF_CPUSTACK_T 2
00112     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00113 
00114 #elif CPU_AVR
00115 
00116     typedef uint8_t cpu_flags_t;
00117     typedef uint8_t cpu_atomic_t;
00118     typedef uint8_t cpu_stack_t;
00119     typedef cpu_stack_t cpu_aligned_stack_t;
00120     #define SIZEOF_CPUSTACK_T 1
00121     #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T
00122 
00123 #else
00124     #error No CPU_... defined.
00125 #endif
00126 
00144 #ifndef SIZEOF_CHAR
00145 #define SIZEOF_CHAR  1
00146 #endif
00147 
00148 #ifndef SIZEOF_SHORT
00149 #define SIZEOF_SHORT  2
00150 #endif
00151 
00152 #ifndef SIZEOF_INT
00153 #if CPU_REG_BITS < 32
00154     #define SIZEOF_INT  2
00155 #else
00156     #define SIZEOF_INT  4
00157 #endif
00158 #endif /* !SIZEOF_INT */
00159 
00160 #ifndef SIZEOF_LONG
00161 #if CPU_REG_BITS > 32
00162     #define SIZEOF_LONG  8
00163 #else
00164     #define SIZEOF_LONG  4
00165 #endif
00166 #endif
00167 
00168 #ifndef SIZEOF_PTR
00169 #if CPU_REG_BITS < 32
00170     #define SIZEOF_PTR   2
00171 #elif CPU_REG_BITS == 32
00172     #define SIZEOF_PTR   4
00173 #else /* CPU_REG_BITS > 32 */
00174     #define SIZEOF_PTR   8
00175 #endif
00176 #endif
00177 
00178 #ifndef SIZEOF_SIZE_T
00179 #if CPU_REG_BITS < 32
00180     #define SIZEOF_SIZE_T   2
00181 #elif CPU_REG_BITS == 32
00182     #define SIZEOF_SIZE_T   4
00183 #else /* CPU_REG_BITS > 32 */
00184     #define SIZEOF_SIZE_T   8
00185 #endif
00186 #endif
00187 
00188 #ifndef CPU_BITS_PER_CHAR
00189 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
00190 #endif
00191 
00192 #ifndef CPU_BITS_PER_SHORT
00193 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
00194 #endif
00195 
00196 #ifndef CPU_BITS_PER_INT
00197 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
00198 #endif
00199 
00200 #ifndef CPU_BITS_PER_LONG
00201 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
00202 #endif
00203 
00204 #ifndef CPU_BITS_PER_PTR
00205 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
00206 #endif
00207 
00208 
00209 /*\}*/
00210 
00211 #ifndef INT_MAX
00212     #define INT_MAX ((int)((unsigned int)~0 >> 1))
00213     #define INT_MIN (-INT_MAX - 1)
00214 #endif
00215 
00216 /* Sanity checks for the above definitions */
00217 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
00218 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
00219 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
00220 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
00221 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
00222 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
00223 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
00224 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
00225 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
00226 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
00227 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
00228 #ifdef __HAS_INT64_T__
00229 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
00230 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
00231 #endif
00232 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T);
00233 STATIC_ASSERT(sizeof(cpu_aligned_stack_t) == SIZEOF_CPUALIGNED_T);
00234 STATIC_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T);
00235 
00236 #endif /* CPU_TYPES_H */