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 // Number of elements in a (statically allocated) array.
256 #define CYG_NELEM(a) (sizeof(a) / sizeof((a)[0]))
258 // -------------------------------------------------------------------------
259 // Constructor ordering macros. These are added as annotations to all
260 // static objects to order the constuctors appropriately.
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?
268 # define CYGBLD_ATTRIB_INIT_PRI( _pri_ )
271 // The following will be removed eventually as it doesn't allow the use of
273 #define CYG_INIT_PRIORITY( _pri_ ) CYGBLD_ATTRIB_INIT_PRI( CYG_INIT_##_pri_ )
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)
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
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
302 // These are default implementations that should work for most targets.
303 // They may be overridden in basetype.h if necessary.
305 #ifndef CYG_LABEL_NAME
307 #define CYG_LABEL_NAME(_name_) _name_
311 #ifndef CYG_LABEL_DEFN
313 #define CYG_LABEL_DEFN(_label) _label
317 // -------------------------------------------------------------------------
318 // COMPILER-SPECIFIC STUFF
321 #if defined(__GNUC_PATCHLEVEL__)
322 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
323 + __GNUC_MINOR__ * 100 \
324 + __GNUC_PATCHLEVEL__)
326 # define __GNUC_VERSION__ (__GNUC__ * 10000 \
327 + __GNUC_MINOR__ * 100)
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))
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))
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))
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__)))
353 // This effectively does the reverse of the previous macro. It defines
354 // a name that the attributed variable or function will actually have
356 # if !defined(CYGBLD_ATTRIB_ASM_ALIAS)
358 # define __Xstr(x) __Str(x)
359 # define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) \
360 __asm__ ( __Xstr( CYG_LABEL_DEFN( __symbol__ ) ) )
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))
369 // Assign a defined variable to a specific section
370 # if !defined(CYGBLD_ATTRIB_SECTION)
371 # define CYGBLD_ATTRIB_SECTION(__sect__) __attribute__((section (__sect__)))
374 // Give a type or object explicit minimum alignment
375 # if !defined(CYGBLD_ATTRIB_ALIGN)
376 # define CYGBLD_ATTRIB_ALIGN(__align__) __attribute__((aligned(__align__)))
379 # if !defined(CYGBLD_ATTRIB_ALIGN_MAX)
380 # define CYGBLD_ATTRIB_ALIGN_MAX __attribute__((aligned))
383 # if !defined(CYGBLD_ATTRIB_ALIGNOFTYPE)
384 # define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) \
385 __attribute__((aligned(__alignof__( _type_ ))))
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__)))
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__)))
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__)))
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))
407 # define CYGBLD_ATTRIB_USED __attribute__((unused))
412 # define CYGBLD_ATTRIB_CONSTRUCTOR
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 --!!! */
421 # define CYGBLD_ATTRIB_ALIAS(__x__) !!!-- Attribute alias not defined --!!!
423 # define CYGBLD_ATTRIB_ASM_ALIAS(__symbol__) !!!-- Asm alias not defined --!!!
425 # define CYGBLD_ATTRIB_CONST
427 # define CYGBLD_ATTRIB_ALIGN(__align__) !!!-- Alignment alias not defined --!!!
429 # define CYGBLD_ATTRIB_ALIGN_MAX !!!-- Alignment alias not defined --!!!
431 # define CYGBLD_ATTRIB_ALIGNOFTYPE( _type_ ) !!!-- Alignment alias not defined --!!!
433 # define CYGBLD_ATTRIB_PRINTF_FORMAT(__format__, __args__)
435 # define CYGBLD_ATTRIB_SCANF_FORMAT(__format__, __args__)
437 # define CYGBLD_ATTRIB_STRFTIME_FORMAT(__format__, __args__)
442 // How to define weak aliases. Currently this is simply a mixture of the
445 # define CYGBLD_ATTRIB_WEAK_ALIAS(__symbol__) \
446 CYGBLD_ATTRIB_WEAK CYGBLD_ATTRIB_ALIAS(__symbol__)
449 # define __THROW throw()
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
461 #ifndef CYGBLD_ANNOTATE_VARIABLE_HAL
462 #define CYGBLD_ANNOTATE_VARIABLE_HAL
464 #ifndef CYGBLD_ANNOTATE_VARIABLE_SCHED
465 #define CYGBLD_ANNOTATE_VARIABLE_SCHED
467 #ifndef CYGBLD_ANNOTATE_VARIABLE_CLOCK
468 #define CYGBLD_ANNOTATE_VARIABLE_CLOCK
470 #ifndef CYGBLD_ANNOTATE_VARIABLE_INTR
471 #define CYGBLD_ANNOTATE_VARIABLE_INTR
474 // -------------------------------------------------------------------------
475 // Various "flavours" of memory regions that can be described by the
476 // Memory Layout Tool (MLT).
478 #define CYGMEM_REGION_ATTR_R 0x01 // Region can be read
479 #define CYGMEM_REGION_ATTR_W 0x02 // Region can be written
481 // -------------------------------------------------------------------------
482 #endif // CYGONCE_INFRA_CYG_TYPE_H multiple inclusion protection