]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/infra/v2_0/include/cyg_type.h
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / infra / v2_0 / include / cyg_type.h
1 #ifndef CYGONCE_INFRA_CYG_TYPE_H
2 #define CYGONCE_INFRA_CYG_TYPE_H
3
4 //==========================================================================
5 //
6 //      cyg_type.h
7 //
8 //      Standard types, and some useful coding macros.
9 //
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):   nickg from an original by hmt
47 // Contributors:  nickg
48 // Date:        1997-09-08
49 // Purpose:     share unambiguously sized types.
50 // Description: we typedef [cyg_][u]int8,16,32 &c for general use.
51 // Usage:       #include "cyg/infra/cyg_type.h"
52 //              ...
53 //              cyg_int32 my_32bit_integer;
54 //              
55 //####DESCRIPTIONEND####
56 //
57
58 #include <stddef.h>           // Definition of NULL from the compiler
59
60 // -------------------------------------------------------------------------
61 // Some useful macros. These are defined here by default.
62
63 // __externC is used in mixed C/C++ headers to force C linkage on an external
64 // definition. It avoids having to put all sorts of ifdefs in.
65
66 #ifdef __cplusplus
67 # define __externC extern "C"
68 #else
69 # define __externC extern
70 #endif
71 // Also define externC for now - but it is deprecated
72 #define externC __externC
73
74 // -------------------------------------------------------------------------
75 // The header <basetype.h> defines the base types used here. It is
76 // supplied either by the target architecture HAL, or by the host
77 // porting kit. They are all defined as macros, and only those that
78 // make choices other than the defaults given below need be defined.
79
80 #define CYG_LSBFIRST 1234
81 #define CYG_MSBFIRST 4321
82
83 #include <cyg/hal/basetype.h>
84
85 #if (CYG_BYTEORDER != CYG_LSBFIRST) && (CYG_BYTEORDER != CYG_MSBFIRST)
86 # error You must define CYG_BYTEORDER to equal CYG_LSBFIRST or CYG_MSBFIRST
87 #endif
88
89 #ifndef CYG_DOUBLE_BYTEORDER
90 #define CYG_DOUBLE_BYTEORDER CYG_BYTEORDER
91 #endif
92
93 #ifndef cyg_halint8
94 # define cyg_halint8 char
95 #endif
96 #ifndef cyg_halint16
97 # define cyg_halint16 short
98 #endif
99 #ifndef cyg_halint32
100 # define cyg_halint32 int
101 #endif
102 #ifndef cyg_halint64
103 # define cyg_halint64 long long
104 #endif
105
106 #ifndef cyg_halcount8
107 # define cyg_halcount8 int
108 #endif
109 #ifndef cyg_halcount16
110 # define cyg_halcount16 int
111 #endif
112 #ifndef cyg_halcount32
113 # define cyg_halcount32 int
114 #endif
115 #ifndef cyg_halcount64
116 # define cyg_halcount64 long long
117 #endif
118
119 #ifndef cyg_haladdress
120 # define cyg_haladdress cyg_uint32
121 #endif
122 #ifndef cyg_haladdrword
123 # define cyg_haladdrword cyg_uint32
124 #endif
125
126 #ifndef cyg_halbool
127 # define cyg_halbool int
128 #endif
129
130 #ifndef cyg_halatomic
131 # define cyg_halatomic cyg_halint8
132 #endif
133
134 // -------------------------------------------------------------------------
135 // Provide a default architecture alignment
136 // This may be overridden in basetype.h if necessary.
137 // These should be straightforward numbers to allow use in assembly.
138
139 #ifndef CYGARC_ALIGNMENT
140 # define CYGARC_ALIGNMENT 8
141 #endif
142 // And corresponding power of two alignment
143 #ifndef CYGARC_P2ALIGNMENT
144 # define CYGARC_P2ALIGNMENT 3
145 #endif
146 #if (CYGARC_ALIGNMENT) != (1 << CYGARC_P2ALIGNMENT)
147 # error "Inconsistent CYGARC_ALIGNMENT and CYGARC_P2ALIGNMENT values"
148 #endif
149
150 // -------------------------------------------------------------------------
151 // The obvious few that compilers may define for you.
152 // But in case they don't:
153
154 #ifndef NULL
155 # define NULL 0
156 #endif
157
158 #ifndef __cplusplus
159
160 typedef cyg_halbool bool;
161
162 # ifndef false
163 #  define false 0
164 # endif
165
166 # ifndef true
167 #  define true (!false)
168 # endif
169
170 #endif
171
172 // -------------------------------------------------------------------------
173 // Allow creation of procedure-like macros that are a single statement,
174 // and must be followed by a semi-colon
175
176 #define CYG_MACRO_START do {
177 #define CYG_MACRO_END   } while (0)
178
179 #define CYG_EMPTY_STATEMENT CYG_MACRO_START CYG_MACRO_END
180
181 #define CYG_UNUSED_PARAM( _type_, _name_ ) CYG_MACRO_START      \
182   _type_ __tmp1 = (_name_);                                     \
183   _type_ __tmp2 = __tmp1;                                       \
184   __tmp1 = __tmp2;                                              \
185 CYG_MACRO_END
186
187
188 // -------------------------------------------------------------------------
189 // Reference a symbol without explicitly making use of it. Ensures that
190 // the object containing the symbol will be included when linking.
191
192 #define CYG_REFERENCE_OBJECT(__object__)                                 \
193      CYG_MACRO_START                                                     \
194      static void *__cygvar_discard_me__ __attribute__ ((unused)) =       \
195                                                           &(__object__); \
196      CYG_MACRO_END
197
198 // -------------------------------------------------------------------------
199 // Define basic types for using integers in memory and structures;
200 // depends on compiler defaults and CPU type.
201
202 typedef unsigned cyg_halint8    cyg_uint8  ;
203 typedef   signed cyg_halint8    cyg_int8   ;
204
205 typedef unsigned cyg_halint16   cyg_uint16 ;
206 typedef   signed cyg_halint16   cyg_int16  ;
207
208 typedef unsigned cyg_halint32   cyg_uint32 ;
209 typedef   signed cyg_halint32   cyg_int32  ;
210
211 typedef unsigned cyg_halint64   cyg_uint64 ;
212 typedef   signed cyg_halint64   cyg_int64  ;
213
214 typedef  cyg_halbool            cyg_bool   ;
215
216 // -------------------------------------------------------------------------
217 // Define types for using integers in registers for looping and the like;
218 // depends on CPU type, choose what it is most comfortable with, with at
219 // least the range required.
220
221 typedef unsigned cyg_halcount8  cyg_ucount8  ;
222 typedef   signed cyg_halcount8  cyg_count8   ;
223
224 typedef unsigned cyg_halcount16 cyg_ucount16 ;
225 typedef   signed cyg_halcount16 cyg_count16  ;
226
227 typedef unsigned cyg_halcount32 cyg_ucount32 ;
228 typedef   signed cyg_halcount32 cyg_count32  ;
229
230 typedef unsigned cyg_halcount64 cyg_ucount64 ;
231 typedef   signed cyg_halcount64 cyg_count64  ;
232
233 // -------------------------------------------------------------------------
234 // Define a type to be used for atomic accesses. This type is guaranteed
235 // to be read or written in a single uninterruptible operation. This type
236 // is at least a single byte.
237
238 typedef volatile unsigned cyg_halatomic  cyg_atomic;
239 typedef volatile unsigned cyg_halatomic  CYG_ATOMIC;
240
241 // -------------------------------------------------------------------------
242 // Define types for access plain, on-the-metal memory or devices.
243
244 typedef cyg_uint32  CYG_WORD;
245 typedef cyg_uint8   CYG_BYTE;
246 typedef cyg_uint16  CYG_WORD16;
247 typedef cyg_uint32  CYG_WORD32;
248 typedef cyg_uint64  CYG_WORD64;
249
250 typedef cyg_haladdress  CYG_ADDRESS;
251 typedef cyg_haladdrword CYG_ADDRWORD;
252
253 // -------------------------------------------------------------------------
254 // Number of elements in a (statically allocated) array.
255
256 #define CYG_NELEM(a) (sizeof(a) / sizeof((a)[0]))
257
258 // -------------------------------------------------------------------------
259 // Constructor ordering macros.  These are added as annotations to all
260 // static objects to order the constuctors appropriately.
261
262 #if defined(__cplusplus) && defined(__GNUC__) && \
263     !defined(CYGBLD_ATTRIB_INIT_PRI)
264 # define CYGBLD_ATTRIB_INIT_PRI( _pri_ ) __attribute__((init_priority(_pri_)))
265 #elif !defined(CYGBLD_ATTRIB_INIT_PRI)
266 // FIXME: should maybe just bomb out if this is attempted anywhere else?
267 // Not sure
268 # define CYGBLD_ATTRIB_INIT_PRI( _pri_ )
269 #endif
270     
271 // The following will be removed eventually as it doesn't allow the use of
272 // e.g. pri+5 format
273 #define CYG_INIT_PRIORITY( _pri_ ) CYGBLD_ATTRIB_INIT_PRI( CYG_INIT_##_pri_ )
274
275 #define CYGBLD_ATTRIB_INIT_BEFORE( _pri_ ) CYGBLD_ATTRIB_INIT_PRI(_pri_-100)
276 #define CYGBLD_ATTRIB_INIT_AFTER( _pri_ )  CYGBLD_ATTRIB_INIT_PRI(_pri_+100)
277
278 #define CYG_INIT_HAL                    10000
279 #define CYG_INIT_SCHEDULER              11000
280 #define CYG_INIT_INTERRUPTS             12000
281 #define CYG_INIT_DRIVERS                13000
282 #define CYG_INIT_CLOCK                  14000
283 #define CYG_INIT_IDLE_THREAD            15000
284 #define CYG_INIT_THREADS                16000
285 #define CYG_INIT_KERNEL                 40000
286 #define CYG_INIT_MEMALLOC               47000
287 #define CYG_INIT_IO                     49000
288 #define CYG_INIT_IO_FS                  50000
289 #define CYG_INIT_LIBC                   52000
290 #define CYG_INIT_COMPAT                 55000
291 #define CYG_INIT_APPLICATION            60000
292 #define CYG_INIT_PREDEFAULT             65534
293 #define CYG_INIT_DEFAULT                65535
294
295 // -------------------------------------------------------------------------
296 // Label name macros. Some toolsets generate labels with initial
297 // underscores and others don't. CYG_LABEL_NAME should be used on
298 // labels in C/C++ code that are defined in assembly code or linker
299 // scripts. CYG_LABEL_DEFN is for use in assembly code and linker
300 // scripts where we need to manufacture labels that can be used from
301 // C/C++.
302 // These are default implementations that should work for most targets.
303 // They may be overridden in basetype.h if necessary.
304
305 #ifndef CYG_LABEL_NAME
306
307 #define CYG_LABEL_NAME(_name_) _name_
308
309 #endif
310
311 #ifndef CYG_LABEL_DEFN
312
313 #define CYG_LABEL_DEFN(_label) _label
314
315 #endif
316
317 // -------------------------------------------------------------------------
318 // COMPILER-SPECIFIC STUFF
319
320 #ifdef __GNUC__
321 #if defined(__GNUC_PATCHLEVEL__)
322 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
323                             + __GNUC_MINOR__ * 100 \
324                             + __GNUC_PATCHLEVEL__)
325 #else
326 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
327                             + __GNUC_MINOR__ * 100)
328 #endif
329
330 // Force a 'C' routine to be called like a 'C++' contructor
331 # if !defined(CYGBLD_ATTRIB_CONSTRUCTOR)
332 #  define CYGBLD_ATTRIB_CONSTRUCTOR __attribute__((constructor))
333 # endif
334
335 // Define a compiler-specific rune for saying a function doesn't return
336 # if !defined(CYGBLD_ATTRIB_NORET)
337 #  define CYGBLD_ATTRIB_NORET __attribute__((noreturn))
338 # endif
339
340 // How to define weak symbols - this is only relevant for ELF and a.out,
341 // but that won't be a problem for eCos
342 # if !defined(CYGBLD_ATTRIB_WEAK)
343 #  define CYGBLD_ATTRIB_WEAK __attribute__ ((weak))
344 # endif
345
346 // How to define alias to symbols. Just pass in the symbol itself, not
347 // the string name of the symbol
348 # if !defined(CYGBLD_ATTRIB_ALIAS)
349 #  define CYGBLD_ATTRIB_ALIAS(__symbol__) \
350         __attribute__ ((alias (#__symbol__)))
351 # endif
352
353 // This effectively does the reverse of the previous macro. It defines
354 // a name that the attributed variable or function will actually have
355 // in assembler.
356 # if !defined(CYGBLD_ATTRIB_ASM_ALIAS)
357 #  define __Str(x) #x
358 #  define __Xstr(x) __Str(x)
359 #  define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) \
360              __asm__ ( __Xstr( CYG_LABEL_DEFN( __symbol__ ) ) )
361 # endif
362
363 // Shows that a function returns the same value when given the same args, but
364 // note this can't be used if there are pointer args
365 # if !defined(CYGBLD_ATTRIB_CONST)
366 #  define CYGBLD_ATTRIB_CONST __attribute__((const))
367 #endif
368
369 // Assign a defined variable to a specific section
370 # if !defined(CYGBLD_ATTRIB_SECTION)
371 #  define CYGBLD_ATTRIB_SECTION(__sect__) __attribute__((section (__sect__)))
372 # endif
373
374 // Give a type or object explicit minimum alignment
375 # if !defined(CYGBLD_ATTRIB_ALIGN)
376 #  define CYGBLD_ATTRIB_ALIGN(__align__) __attribute__((aligned(__align__)))
377 # endif
378
379 # if !defined(CYGBLD_ATTRIB_ALIGN_MAX)
380 #  define CYGBLD_ATTRIB_ALIGN_MAX __attribute__((aligned))
381 # endif
382
383 # if !defined(CYGBLD_ATTRIB_ALIGNOFTYPE)
384 #  define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) \
385      __attribute__((aligned(__alignof__( _type_ ))))
386 # endif
387
388 // Teach compiler how to check format of printf-like functions
389 # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__) \
390         __attribute__((format (printf, __format__, __args__)))
391
392 // Teach compiler how to check format of scanf-like functions
393 # define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__) \
394         __attribute__((format (scanf, __format__, __args__)))
395
396 // Teach compiler how to check format of strftime-like functions
397 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__) \
398         __attribute__((format (strftime, __format__, __args__)))
399
400 // Tell the compiler not to throw away a variable or function. Only known
401 // available on 3.3.2 or above. Old version's didn't throw them away,
402 // but using the unused attribute should stop warnings.
403 # if !defined(CYGBLD_ATTRIB_USED)
404 #  if __GNUC_VERSION__ >= 30302
405 #   define CYGBLD_ATTRIB_USED __attribute__((used))
406 #  else
407 #   define CYGBLD_ATTRIB_USED __attribute__((unused))
408 #  endif
409 # endif 
410 #else // non-GNU
411
412 # define CYGBLD_ATTRIB_CONSTRUCTOR
413
414 # define CYGBLD_ATTRIB_NORET
415     // This intentionally gives an error only if we actually try to
416     // use it.  #error would give an error if we simply can't.
417 // FIXME: Had to disarm the bomb - the CYGBLD_ATTRIB_WEAK macro is now
418 //        (indirectly) used in host tools.
419 # define CYGBLD_ATTRIB_WEAK /* !!!-- Attribute weak not defined --!!! */
420
421 # define CYGBLD_ATTRIB_ALIAS(__x__) !!!-- Attribute alias not defined --!!!
422
423 # define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) !!!-- Asm alias not defined --!!!
424
425 # define CYGBLD_ATTRIB_CONST
426
427 # define CYGBLD_ATTRIB_ALIGN(__align__) !!!-- Alignment alias not defined --!!!
428
429 # define CYGBLD_ATTRIB_ALIGN_MAX !!!-- Alignment alias not defined --!!!
430
431 # define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) !!!-- Alignment alias not defined --!!!
432
433 # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__)
434
435 # define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__)
436
437 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__)
438
439
440 #endif
441
442 // How to define weak aliases. Currently this is simply a mixture of the
443 // above
444
445 # define CYGBLD_ATTRIB_WEAK_ALIAS(__symbol__) \
446         CYGBLD_ATTRIB_WEAK CYGBLD_ATTRIB_ALIAS(__symbol__)
447
448 #ifdef __cplusplus
449 # define __THROW throw()
450 #else
451 # define __THROW
452 #endif
453
454 // -------------------------------------------------------------------------
455 // Variable annotations
456 // These annotations may be added to various static variables in the
457 // HAL and kernel to indicate which component they belong to. These
458 // are used by some targets to optimize memory placement of these
459 // variables.
460
461 #ifndef CYGBLD_ANNOTATE_VARIABLE_HAL
462 #define CYGBLD_ANNOTATE_VARIABLE_HAL
463 #endif
464 #ifndef CYGBLD_ANNOTATE_VARIABLE_SCHED
465 #define CYGBLD_ANNOTATE_VARIABLE_SCHED
466 #endif
467 #ifndef CYGBLD_ANNOTATE_VARIABLE_CLOCK
468 #define CYGBLD_ANNOTATE_VARIABLE_CLOCK
469 #endif
470 #ifndef CYGBLD_ANNOTATE_VARIABLE_INTR
471 #define CYGBLD_ANNOTATE_VARIABLE_INTR
472 #endif
473
474 // -------------------------------------------------------------------------
475 // Various "flavours" of memory regions that can be described by the 
476 // Memory Layout Tool (MLT).
477
478 #define CYGMEM_REGION_ATTR_R  0x01  // Region can be read
479 #define CYGMEM_REGION_ATTR_W  0x02  // Region can be written
480
481 // -------------------------------------------------------------------------
482 #endif // CYGONCE_INFRA_CYG_TYPE_H multiple inclusion protection
483 // EOF cyg_type.h