PalmTypes.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005 Palmsource, Inc.
00003  * 
00004  * This software is licensed as described in the file LICENSE, which
00005  * you should have received as part of this distribution. The terms
00006  * are also available at http://www.openbinder.org/license.html.
00007  * 
00008  * This software consists of voluntary contributions made by many
00009  * individuals. For the exact contribution history, see the revision
00010  * history and logs, available at http://www.openbinder.org
00011  */
00012 
00018 #ifndef _PALMTYPES_H_
00019 #define _PALMTYPES_H_
00020 
00026 /************************************************************
00027  * Environment configuration
00028  *************************************************************/
00029 // <BuildDefaults.h> must be included here, rather than in <PalmOS.h>
00030 // because they must be included for ALL builds.
00031 // Not every build includes <PalmOS.h>.
00032 
00033 // To override build options in a local component, include <BuildDefines.h>
00034 // first, then define switches as need, and THEN include <PalmTypes.h>.
00035 // This new mechanism supercedes the old "AppBuildRules.h" approach.
00036 // More details available in <BuildDefaults.h>.
00037 #include <BuildDefaults.h>
00038 
00039 
00040 /********************************************************************
00041  * Elementary data types
00042  ********************************************************************/
00043 // force the Palm OS 6 version of sys/types.h
00044 #include <stdint.h>
00045 #include <stddef.h>
00046 #if TARGET_HOST == TARGET_HOST_PALMOS
00047 #   include <sys/types.h>
00048     /*-------------------------------------------------------------*/
00049     /* PalmOS types and definitions */
00050     /*-------------------------------------------------------------*/
00051 
00052     /* Descriptive formats */
00053     typedef int32_t                 status_t;
00054     typedef int64_t                 nsecs_t;
00055     typedef uint32_t                type_code;
00056     typedef uint32_t                perform_code;
00057 
00058     /* IOS */
00059     typedef int     FDCELL;
00060     typedef void*       PCELL;
00061     typedef int32_t pl_t;
00062 
00063 #   ifndef uuid_t
00064     typedef struct uuid_t
00065     {
00066         uint32_t time_low;
00067         uint16_t time_mid;
00068         uint16_t time_hi_and_version;
00069         uint8_t clock_seq_hi_and_reserved;
00070         uint8_t clock_seq_low;
00071         uint8_t node[6];
00072     } uuid_t;
00073 #   endif
00074 #elif (TARGET_HOST == TARGET_HOST_MACOS) || (TARGET_HOST == TARGET_HOST_LINUX)
00075     typedef int32_t                 status_t;
00076     typedef int64_t                 nsecs_t;
00077     typedef uint32_t                type_code;
00078     typedef uint32_t                perform_code;
00079     /* IOS */
00080     typedef int     FDCELL;
00081     typedef void*       PCELL;
00082     typedef int32_t pl_t;
00083 #else
00084 // Windows native tools
00085 #   include <sys/types.h>
00086 #endif
00087 
00088 // Logical data types
00089 typedef uint16_t            wchar16_t;
00090 typedef uint32_t            wchar32_t;
00091 
00092 typedef int16_t             Coord;      // screen/window coordinate
00093 typedef float               fcoord_t;   // floating pt for the GcApis
00094 
00095 typedef float               coord;      // XXX must be removed
00096 
00097 typedef unsigned char       Boolean;
00098 
00099 // for Boolean values
00100 #ifndef TRUE
00101 #define TRUE (1)
00102 #endif
00103 #ifndef FALSE
00104 #define FALSE (0)
00105 #endif
00106 
00107 // force enum size
00108 typedef uint8_t             Enum8;
00109 typedef uint16_t            Enum16;
00110 typedef int8_t              SignedEnum8;
00111 typedef int16_t             SignedEnum16;
00112 
00113 typedef void *              MemPtr;     // global pointer
00114 typedef struct _opaque *    MemHandle;  // global handle
00115 
00116 typedef uint32_t            VAddr;      // Virtual Address
00117 typedef uint32_t            SysHandle;  // Virtual Address
00118 
00119 typedef int32_t (*ProcPtr)();
00120 
00121 
00122 /************************************************************
00123  * Useful Macros 
00124  *************************************************************/
00125 #ifndef ErrConvertFrom68k
00126 #define ErrConvertFrom68k(x) ( (((status_t)(x))&0xFFFF) | 0x80000000 )
00127 #endif
00128 
00129 #ifndef ErrConvertTo68k
00130 #define ErrConvertTo68k(x) ((uint16_t)(((uint32_t)(x))&0xFFFF))
00131 #endif
00132 
00133 // Nanosecond units
00134 #define B_ONE_NANOSECOND        ((nsecs_t)1)
00135 #define B_ONE_MICROSECOND       (B_ONE_NANOSECOND*1000)
00136 #define B_ONE_MILLISECOND       (B_ONE_MICROSECOND*1000)
00137 #define B_ONE_SECOND            (B_ONE_MILLISECOND*1000)
00138 
00139 // Conversions to nsecs_t (nanoseconds)
00140 #define B_US2NS(us)                             ((nsecs_t)(us) * 1000)
00141 #define B_MS2NS(ms)                             ((nsecs_t)(ms) * 1000000)
00142 #define B_S2NS(s)                               ((nsecs_t)(s) * 1000000000)
00143 #define B_MICROSECONDS_TO_NANOSECONDS(us)       B_US2NS(us)
00144 #define B_MILLISECONDS_TO_NANOSECONDS(ms)       B_MS2NS(ms)
00145 #define B_SECONDS_TO_NANOSECONDS(s)             B_S2NS(s)
00146 
00147 // Conversions from nsecs_t (nanoseconds)
00148 #define B_NS2US(ns)                             ((int64_t)(ns) / 1000)
00149 #define B_NS2MS(ns)                             ((int64_t)(ns) / 1000000)
00150 #define B_NS2S(ns)                              ((int64_t)(ns) / 1000000000)
00151 #define B_NANOSECONDS_TO_MICROSECONDS(ns)       B_NS2US(ns)
00152 #define B_NANOSECONDS_TO_MILLISECONDS(ns)       B_NS2MS(ns)
00153 #define B_NANOSECONDS_TO_SECONDS(ns)            B_NS2S(ns)
00154 
00155 // macros can be used to get at high and lo parts of 64 bit doubles     
00156 #define _FLB_FIRST32(x) *((uint32_t *) &x)
00157 #define _FLB_SECOND32(x) *((uint32_t *) &x + 1)
00158 #define _FLB_ALL32(x) *((uint32_t *) &x)
00159 
00160 #if CPU_ENDIAN == CPU_ENDIAN_LITTLE
00161 #define _FLB_LO32(x) *((uint32_t *) &x)
00162 #define _FLB_HI32(x) *((uint32_t *) &x + 1)
00163 
00164 #else
00165 #define _FLB_HI32(x) *((uint32_t *) &x)
00166 #define _FLB_LO32(x) *((uint32_t *) &x + 1)
00167 
00168 #endif
00169 
00170 /************************************************************
00171  * Common constants
00172  *************************************************************/
00173 #ifndef NULL
00174 #define NULL    0
00175 #endif  // NULL
00176 
00177 // Include the following typedefs if types.h wasn't read.
00178 #ifdef __MWERKS__
00179     #if !__option(bool)
00180         #ifndef true
00181             #define true            1
00182         #endif
00183         #ifndef false
00184             #define false           0
00185         #endif
00186     #endif
00187 #else
00188   #ifndef __cplusplus
00189       #ifndef true
00190             enum {false, true};
00191       #endif
00192    #endif
00193 #endif
00194 
00195 
00196 
00197 
00198 /************************************************************
00199  * Misc
00200  *************************************************************/
00201 
00202 // Basic macros for swapping bytes in words or dwords to switch between
00203 // big endian byte order and little endian byte order
00204 #define EndianSwap16(n) (((((uint16_t) n) << 8) & 0xFF00) | \
00205                          ((((uint16_t) n) >> 8) & 0x00FF))
00206 
00207 #define EndianSwap32(n) (((((uint32_t) n) << 24) & 0xFF000000) |    \
00208                          ((((uint32_t) n) <<  8) & 0x00FF0000) |    \
00209                          ((((uint32_t) n) >>  8) & 0x0000FF00) |    \
00210                          ((((uint32_t) n) >> 24) & 0x000000FF))
00211 
00212 // Macros to convert a resource from BigEndian to LittleEndian
00213 // when running on a LittleEndian device.
00214 
00215 #if CPU_ENDIAN == CPU_ENDIAN_BIG
00216 // Resources are always aligned to 16-bit boundaries so we can read 16-bits at a time.
00217 #define RsrcEndianSwap16(x) (x)
00218 
00219 // Note, the source MUST be 32-bit aligned on most machines.
00220 #define RsrcEndianSwap32(x) (x)
00221 
00222 #elif CPU_ENDIAN == CPU_ENDIAN_LITTLE
00223 
00224 // Resources are always aligned to 16-bit boundaries so
00225 // we can read 16-bits at a time.
00226 #define RsrcEndianSwap16(x) EndianSwap16(*(uint16_t*)&(x))
00227 
00228 // Note, the source MUST be 32-bit aligned on most machines.
00229 #define RsrcEndianSwap32(x) EndianSwap32(*(uint32_t*)&(x))
00230 
00231 #endif
00232 
00233 
00234 /************************************************************
00235  * ARM specific
00236  *************************************************************/
00237 #if defined(NO_RUNTIME_SHARED_LIBRARIES) && defined(__arm)
00238     // prevent r9 (sb) from being used in PalmOS for Monolithic builds
00239     // so we can use it as a process global for heapBase
00240     __global_reg(6)   uint32_t sb;
00241 #endif  
00242 
00243 // Use this storage class modifier macro to guarantee that objects are x bytes aligned in ARM.
00244 #if defined(__arm) && defined(__ARMCC_VERSION) && (__ARMCC_VERSION < 130000)
00245 #define _STACK_ALIGN(x)    __align(x)
00246 #else
00247 #define _STACK_ALIGN(x)
00248 #endif
00249 
00252 #endif //_PALMTYPES_H_