1 #ifndef CYGONCE_INFRA_CYG_TYPE_H
2 #define CYGONCE_INFRA_CYG_TYPE_H
4 //==========================================================================
8 // Standard types, and some useful coding macros.
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.
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.
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
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.
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.
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.
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####
46 // Author(s): nickg from an original by hmt
47 // Contributors: nickg
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"
53 // cyg_int32 my_32bit_integer;
55 //####DESCRIPTIONEND####
58 #include <stddef.h> // Definition of NULL from the compiler
60 // -------------------------------------------------------------------------
61 // Some useful macros. These are defined here by default.
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.
67 # define __externC extern "C"
69 # define __externC extern
71 // Also define externC for now - but it is deprecated
72 #define externC __externC
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.
80 #define CYG_LSBFIRST 1234
81 #define CYG_MSBFIRST 4321
83 #include <cyg/hal/basetype.h>
85 #if (CYG_BYTEORDER != CYG_LSBFIRST) && (CYG_BYTEORDER != CYG_MSBFIRST)
86 # error You must define CYG_BYTEORDER to equal CYG_LSBFIRST or CYG_MSBFIRST
89 #ifndef CYG_DOUBLE_BYTEORDER
90 #define CYG_DOUBLE_BYTEORDER CYG_BYTEORDER
94 # define cyg_halint8 char
97 # define cyg_halint16 short
100 # define cyg_halint32 int
103 # define cyg_halint64 long long
106 #ifndef cyg_halcount8
107 # define cyg_halcount8 int
109 #ifndef cyg_halcount16
110 # define cyg_halcount16 int
112 #ifndef cyg_halcount32
113 # define cyg_halcount32 int
115 #ifndef cyg_halcount64
116 # define cyg_halcount64 long long
119 #ifndef cyg_haladdress
120 # define cyg_haladdress cyg_uint32
122 #ifndef cyg_haladdrword
123 # define cyg_haladdrword cyg_uint32
127 # define cyg_halbool int
130 #ifndef cyg_halatomic
131 # define cyg_halatomic cyg_halint8
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.
139 #ifndef CYGARC_ALIGNMENT
140 # define CYGARC_ALIGNMENT 8
142 // And corresponding power of two alignment
143 #ifndef CYGARC_P2ALIGNMENT
144 # define CYGARC_P2ALIGNMENT 3
146 #if (CYGARC_ALIGNMENT) != (1 << CYGARC_P2ALIGNMENT)
147 # error "Inconsistent CYGARC_ALIGNMENT and CYGARC_P2ALIGNMENT values"
150 // -------------------------------------------------------------------------
151 // The obvious few that compilers may define for you.
152 // But in case they don't:
160 typedef cyg_halbool bool;
167 # define true (!false)
172 // -------------------------------------------------------------------------
173 // Allow creation of procedure-like macros that are a single statement,
174 // and must be followed by a semi-colon
176 #define CYG_MACRO_START do {
177 #define CYG_MACRO_END } while (0)
179 #define CYG_EMPTY_STATEMENT CYG_MACRO_START CYG_MACRO_END
181 #define CYG_UNUSED_PARAM( _type_, _name_ ) CYG_MACRO_START \
182 _type_ __tmp1 = (_name_); \
183 _type_ __tmp2 = __tmp1; \
188 // -------------------------------------------------------------------------
189 // Reference a symbol without explicitly making use of it. Ensures that
190 // the object containing the symbol will be included when linking.
192 #define CYG_REFERENCE_OBJECT(__object__) \
194 static void *__cygvar_discard_me__ __attribute__ ((unused)) = \
198 // -------------------------------------------------------------------------
199 // Define basic types for using integers in memory and structures;
200 // depends on compiler defaults and CPU type.
202 typedef unsigned cyg_halint8 cyg_uint8 ;
203 typedef signed cyg_halint8 cyg_int8 ;
205 typedef unsigned cyg_halint16 cyg_uint16 ;
206 typedef signed cyg_halint16 cyg_int16 ;
208 typedef unsigned cyg_halint32 cyg_uint32 ;
209 typedef signed cyg_halint32 cyg_int32 ;
211 typedef unsigned cyg_halint64 cyg_uint64 ;
212 typedef signed cyg_halint64 cyg_int64 ;
214 typedef cyg_halbool cyg_bool ;
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.
221 typedef unsigned cyg_halcount8 cyg_ucount8 ;
222 typedef signed cyg_halcount8 cyg_count8 ;
224 typedef unsigned cyg_halcount16 cyg_ucount16 ;
225 typedef signed cyg_halcount16 cyg_count16 ;
227 typedef unsigned cyg_halcount32 cyg_ucount32 ;
228 typedef signed cyg_halcount32 cyg_count32 ;
230 typedef unsigned cyg_halcount64 cyg_ucount64 ;
231 typedef signed cyg_halcount64 cyg_count64 ;
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.
238 typedef volatile unsigned cyg_halatomic cyg_atomic;
239 typedef volatile unsigned cyg_halatomic CYG_ATOMIC;
241 // -------------------------------------------------------------------------
242 // Define types for access plain, on-the-metal memory or devices.
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;
250 typedef cyg_haladdress CYG_ADDRESS;
251 typedef cyg_haladdrword CYG_ADDRWORD;
253 // -------------------------------------------------------------------------
254 // Constructor ordering macros. These are added as annotations to all
255 // static objects to order the constuctors appropriately.
257 #if defined(__cplusplus) && defined(__GNUC__) && \
258 !defined(CYGBLD_ATTRIB_INIT_PRI)
259 # define CYGBLD_ATTRIB_INIT_PRI( _pri_ ) __attribute__((init_priority(_pri_)))
260 #elif !defined(CYGBLD_ATTRIB_INIT_PRI)
261 // FIXME: should maybe just bomb out if this is attempted anywhere else?
263 # define CYGBLD_ATTRIB_INIT_PRI( _pri_ )
266 // The following will be removed eventually as it doesn't allow the use of
268 #define CYG_INIT_PRIORITY( _pri_ ) CYGBLD_ATTRIB_INIT_PRI( CYG_INIT_##_pri_ )
270 #define CYGBLD_ATTRIB_INIT_BEFORE( _pri_ ) CYGBLD_ATTRIB_INIT_PRI(_pri_-100)
271 #define CYGBLD_ATTRIB_INIT_AFTER( _pri_ ) CYGBLD_ATTRIB_INIT_PRI(_pri_+100)
273 #define CYG_INIT_HAL 10000
274 #define CYG_INIT_SCHEDULER 11000
275 #define CYG_INIT_INTERRUPTS 12000
276 #define CYG_INIT_DRIVERS 13000
277 #define CYG_INIT_CLOCK 14000
278 #define CYG_INIT_IDLE_THREAD 15000
279 #define CYG_INIT_THREADS 16000
280 #define CYG_INIT_KERNEL 40000
281 #define CYG_INIT_MEMALLOC 47000
282 #define CYG_INIT_IO 49000
283 #define CYG_INIT_IO_FS 50000
284 #define CYG_INIT_LIBC 52000
285 #define CYG_INIT_COMPAT 55000
286 #define CYG_INIT_APPLICATION 60000
287 #define CYG_INIT_PREDEFAULT 65534
288 #define CYG_INIT_DEFAULT 65535
290 // -------------------------------------------------------------------------
291 // Label name macros. Some toolsets generate labels with initial
292 // underscores and others don't. CYG_LABEL_NAME should be used on
293 // labels in C/C++ code that are defined in assembly code or linker
294 // scripts. CYG_LABEL_DEFN is for use in assembly code and linker
295 // scripts where we need to manufacture labels that can be used from
297 // These are default implementations that should work for most targets.
298 // They may be overridden in basetype.h if necessary.
300 #ifndef CYG_LABEL_NAME
302 #define CYG_LABEL_NAME(_name_) _name_
306 #ifndef CYG_LABEL_DEFN
308 #define CYG_LABEL_DEFN(_label) _label
312 // -------------------------------------------------------------------------
313 // COMPILER-SPECIFIC STUFF
316 #if defined(__GNU_PATCHLEVEL__)
317 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
318 + __GNUC_MINOR__ * 100 \
319 + __GNUC_PATCHLEVEL__)
321 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
322 + __GNUC_MINOR__ * 100)
325 // Force a 'C' routine to be called like a 'C++' contructor
326 # if !defined(CYGBLD_ATTRIB_CONSTRUCTOR)
327 # define CYGBLD_ATTRIB_CONSTRUCTOR __attribute__((constructor))
330 // Define a compiler-specific rune for saying a function doesn't return
331 # if !defined(CYGBLD_ATTRIB_NORET)
332 # define CYGBLD_ATTRIB_NORET __attribute__((noreturn))
335 // How to define weak symbols - this is only relevant for ELF and a.out,
336 // but that won't be a problem for eCos
337 # if !defined(CYGBLD_ATTRIB_WEAK)
338 # define CYGBLD_ATTRIB_WEAK __attribute__ ((weak))
341 // How to define alias to symbols. Just pass in the symbol itself, not
342 // the string name of the symbol
343 # if !defined(CYGBLD_ATTRIB_ALIAS)
344 # define CYGBLD_ATTRIB_ALIAS(__symbol__) \
345 __attribute__ ((alias (#__symbol__)))
348 // This effectively does the reverse of the previous macro. It defines
349 // a name that the attributed variable or function will actually have
351 # if !defined(CYGBLD_ATTRIB_ASM_ALIAS)
353 # define __Xstr(x) __Str(x)
354 # define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) \
355 __asm__ ( __Xstr( CYG_LABEL_DEFN( __symbol__ ) ) )
358 // Shows that a function returns the same value when given the same args, but
359 // note this can't be used if there are pointer args
360 # if !defined(CYGBLD_ATTRIB_CONST)
361 # define CYGBLD_ATTRIB_CONST __attribute__((const))
364 // Assign a defined variable to a specific section
365 # if !defined(CYGBLD_ATTRIB_SECTION)
366 # define CYGBLD_ATTRIB_SECTION(__sect__) __attribute__((section (__sect__)))
369 // Give a type or object explicit minimum alignment
370 # if !defined(CYGBLD_ATTRIB_ALIGN)
371 # define CYGBLD_ATTRIB_ALIGN(__align__) __attribute__((aligned(__align__)))
374 # if !defined(CYGBLD_ATTRIB_ALIGN_MAX)
375 # define CYGBLD_ATTRIB_ALIGN_MAX __attribute__((aligned))
378 # if !defined(CYGBLD_ATTRIB_ALIGNOFTYPE)
379 # define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) \
380 __attribute__((aligned(__alignof__( _type_ ))))
383 // Teach compiler how to check format of printf-like functions
384 # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__) \
385 __attribute__((format (printf, __format__, __args__)))
387 // Teach compiler how to check format of scanf-like functions
388 # define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__) \
389 __attribute__((format (scanf, __format__, __args__)))
391 // Teach compiler how to check format of strftime-like functions
392 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__) \
393 __attribute__((format (strftime, __format__, __args__)))
395 // Tell the compiler not to throw away a variable or function. Only
396 // available on 3.3.4 or above. Old version's didn't throw them away,
397 // but using the unused attribute should stop warnings.
398 # if !defined(CYGBLD_ATTRIB_USED)
399 # if __GNUC_VERSION__ >= 30404
400 # define CYGBLD_ATTRIB_USED __attribute__((used))
402 # define CYGBLD_ATTRIB_USED __attribute__((unused))
407 # define CYGBLD_ATTRIB_CONSTRUCTOR
409 # define CYGBLD_ATTRIB_NORET
410 // This intentionally gives an error only if we actually try to
411 // use it. #error would give an error if we simply can't.
412 // FIXME: Had to disarm the bomb - the CYGBLD_ATTRIB_WEAK macro is now
413 // (indirectly) used in host tools.
414 # define CYGBLD_ATTRIB_WEAK /* !!!-- Attribute weak not defined --!!! */
416 # define CYGBLD_ATTRIB_ALIAS(__x__) !!!-- Attribute alias not defined --!!!
418 # define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) !!!-- Asm alias not defined --!!!
420 # define CYGBLD_ATTRIB_CONST
422 # define CYGBLD_ATTRIB_ALIGN(__align__) !!!-- Alignment alias not defined --!!!
424 # define CYGBLD_ATTRIB_ALIGN_MAX !!!-- Alignment alias not defined --!!!
426 # define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) !!!-- Alignment alias not defined --!!!
428 # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__)
430 # define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__)
432 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__)
437 // How to define weak aliases. Currently this is simply a mixture of the
440 # define CYGBLD_ATTRIB_WEAK_ALIAS(__symbol__) \
441 CYGBLD_ATTRIB_WEAK CYGBLD_ATTRIB_ALIAS(__symbol__)
444 # define __THROW throw()
449 // -------------------------------------------------------------------------
450 // Variable annotations
451 // These annotations may be added to various static variables in the
452 // HAL and kernel to indicate which component they belong to. These
453 // are used by some targets to optimize memory placement of these
456 #ifndef CYGBLD_ANNOTATE_VARIABLE_HAL
457 #define CYGBLD_ANNOTATE_VARIABLE_HAL
459 #ifndef CYGBLD_ANNOTATE_VARIABLE_SCHED
460 #define CYGBLD_ANNOTATE_VARIABLE_SCHED
462 #ifndef CYGBLD_ANNOTATE_VARIABLE_CLOCK
463 #define CYGBLD_ANNOTATE_VARIABLE_CLOCK
465 #ifndef CYGBLD_ANNOTATE_VARIABLE_INTR
466 #define CYGBLD_ANNOTATE_VARIABLE_INTR
469 // -------------------------------------------------------------------------
470 // Various "flavours" of memory regions that can be described by the
471 // Memory Layout Tool (MLT).
473 #define CYGMEM_REGION_ATTR_R 0x01 // Region can be read
474 #define CYGMEM_REGION_ATTR_W 0x02 // Region can be written
476 // -------------------------------------------------------------------------
477 #endif // CYGONCE_INFRA_CYG_TYPE_H multiple inclusion protection