Ignore:
Timestamp:
Aug 27, 2007, 9:54:05 PM (18 years ago)
Author:
bird
Message:

Use the new type system.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/kStuff/kLdr/kLdrBase.h

    r3537 r3567  
    2828#define ___kLdrBase_h___
    2929
     30#include <k/kDefs.h>
     31#include <k/kTypes.h>
     32
    3033
    3134/** @defgroup grp_kLdrBase  kLdrBase - Base Definitions And Typedefs
    3235 * @{ */
    33 
    34 /*
    35  * kLdr depend on size_t, [u]intNN_t, [u]intptr_t and some related constants.
    36  * If KLDR_ALREADY_INCLUDED_STD_TYPES or KCOMMON_ALREADY_INCLUDED_STD_TYPES
    37  * is defined, these has already been defined.
    38  */
    39 #if !defined(KLDR_ALREADY_INCLUDED_STD_TYPES) && !defined(KCOMMON_ALREADY_INCLUDED_STD_TYPES)
    40 # define KCOMMON_ALREADY_INCLUDED_STD_TYPES 1
    41 # include <sys/types.h>
    42 # include <stddef.h>
    43 # ifdef _MSC_VER
    44    typedef signed char          int8_t;
    45    typedef unsigned char        uint8_t;
    46    typedef signed short         int16_t;
    47    typedef unsigned short       uint16_t;
    48    typedef signed int           int32_t;
    49    typedef unsigned int         uint32_t;
    50    typedef signed __int64       int64_t;
    51    typedef unsigned __int64     uint64_t;
    52    typedef int64_t              intmax_t;
    53    typedef uint64_t             uintmax_t;
    54 #  define UINT8_C(c)            (c)
    55 #  define UINT16_C(c)           (c)
    56 #  define UINT32_C(c)           (c ## U)
    57 #  define UINT64_C(c)           (c ## ULL)
    58 #  define INT8_C(c)             (c)
    59 #  define INT16_C(c)            (c)
    60 #  define INT32_C(c)            (c)
    61 #  define INT64_C(c)            (c ## LL)
    62 #  define INT8_MIN              (INT8_C(-0x7f) - 1)
    63 #  define INT16_MIN             (INT16_C(-0x7fff) - 1)
    64 #  define INT32_MIN             (INT32_C(-0x7fffffff) - 1)
    65 #  define INT64_MIN             (INT64_C(-0x7fffffffffffffff) - 1)
    66 #  define INT8_MAX              INT8_C(0x7f)
    67 #  define INT16_MAX             INT16_C(0x7fff)
    68 #  define INT32_MAX             INT32_C(0x7fffffff)
    69 #  define INT64_MAX             INT64_C(0x7fffffffffffffff)
    70 #  define UINT8_MAX             UINT8_C(0xff)
    71 #  define UINT16_MAX            UINT16_C(0xffff)
    72 #  define UINT32_MAX            UINT32_C(0xffffffff)
    73 #  define UINT64_MAX            UINT64_C(0xffffffffffffffff)
    74 # else
    75 #  include <stdint.h>
    76 # endif
    77 #endif /* !KLDR_ALREADY_INCLUDED_STD_TYPES && !KCOMMON_ALREADY_INCLUDED_STD_TYPES */
    7836
    7937/** Get the minimum of two values. */
     
    8240#define KLDR_MAX(a, b)              ((a) >= (b) ? (a) : (b))
    8341/** Calculate the offset of a structure member. */
    84 #define KLDR_OFFSETOF(strct, memb)  ( (size_t)( &((strct *)0)->memb ) )
    85 /** Align a size_t value. */
    86 #define KLDR_ALIGN_Z(val, align)    ( ((val) + ((align) - 1)) & ~(size_t)((align) - 1) )
     42#define KLDR_OFFSETOF(strct, memb)  ( (KSIZE)( &((strct *)0)->memb ) )
     43/** Align a KSIZE value. */
     44#define KLDR_ALIGN_Z(val, align)    ( ((val) + ((align) - 1)) & ~(KSIZE)((align) - 1) )
    8745/** Align a void * value. */
    88 #define KLDR_ALIGN_P(pv, align)     ( (void *)( ((uintptr_t)(pv) + ((align) - 1)) & ~(uintptr_t)((align) - 1) ) )
    89 /** Align a size_t value. */
     46#define KLDR_ALIGN_P(pv, align)     ( (void *)( ((KUPTR)(pv) + ((align) - 1)) & ~(KUPTR)((align) - 1) ) )
     47/** Align a KSIZE value. */
    9048#define KLDR_ALIGN_ADDR(val, align) ( ((val) + ((align) - 1)) & ~(KLDRADDR)((align) - 1) )
    9149/** Number of elements in an array. */
     
    11068/** @def KLDR_E2E_U16
    11169 * Convert the endian of an unsigned 16-bit value. */
    112 # define KLDR_E2E_U16(u16)      ( (uint16_t) (((u16) >> 8) | ((u16) << 8)) )
     70# define KLDR_E2E_U16(u16)      ( (KU16) (((u16) >> 8) | ((u16) << 8)) )
    11371/** @def KLDR_E2E_U32
    11472 * Convert the endian of an unsigned 32-bit value. */
    115 # define KLDR_E2E_U32(u32)      (   ( ((u32) & UINT32_C(0xff000000)) >> 24 ) \
    116                                   | ( ((u32) & UINT32_C(0x00ff0000)) >>  8 ) \
    117                                   | ( ((u32) & UINT32_C(0x0000ff00)) <<  8 ) \
    118                                   | ( ((u32) & UINT32_C(0x000000ff)) << 24 ) \
     73# define KLDR_E2E_U32(u32)      (   ( ((u32) & KU32_C(0xff000000)) >> 24 ) \
     74                                  | ( ((u32) & KU32_C(0x00ff0000)) >>  8 ) \
     75                                  | ( ((u32) & KU32_C(0x0000ff00)) <<  8 ) \
     76                                  | ( ((u32) & KU32_C(0x000000ff)) << 24 ) \
    11977                                )
    12078/** @def KLDR_E2E_U64
    12179 * Convert the endian of an unsigned 64-bit value. */
    122 # define KLDR_E2E_U64(u64)      (   ( ((u64) & UINT64_C(0xff00000000000000)) >> 56 ) \
    123                                   | ( ((u64) & UINT64_C(0x00ff000000000000)) >> 40 ) \
    124                                   | ( ((u64) & UINT64_C(0x0000ff0000000000)) >> 24 ) \
    125                                   | ( ((u64) & UINT64_C(0x000000ff00000000)) >>  8 ) \
    126                                   | ( ((u64) & UINT64_C(0x00000000ff000000)) <<  8 ) \
    127                                   | ( ((u64) & UINT64_C(0x0000000000ff0000)) << 24 ) \
    128                                   | ( ((u64) & UINT64_C(0x000000000000ff00)) << 40 ) \
    129                                   | ( ((u64) & UINT64_C(0x00000000000000ff)) << 56 ) \
     80# define KLDR_E2E_U64(u64)      (   ( ((u64) & KU64_C(0xff00000000000000)) >> 56 ) \
     81                                  | ( ((u64) & KU64_C(0x00ff000000000000)) >> 40 ) \
     82                                  | ( ((u64) & KU64_C(0x0000ff0000000000)) >> 24 ) \
     83                                  | ( ((u64) & KU64_C(0x000000ff00000000)) >>  8 ) \
     84                                  | ( ((u64) & KU64_C(0x00000000ff000000)) <<  8 ) \
     85                                  | ( ((u64) & KU64_C(0x0000000000ff0000)) << 24 ) \
     86                                  | ( ((u64) & KU64_C(0x000000000000ff00)) << 40 ) \
     87                                  | ( ((u64) & KU64_C(0x00000000000000ff)) << 56 ) \
    13088                                )
    13189
     
    143101 * Unsigned 64-bit big-endian to host endian. */
    144102#ifdef KLDR_LITTLE_ENDIAN
    145 # define KLDR_LE2H_U16(u16)  ((uint16_t)(u16))
    146 # define KLDR_LE2H_U32(u32)  ((uint32_t)(u32))
    147 # define KLDR_LE2H_U64(u64)  ((uint32_t)(u32))
     103# define KLDR_LE2H_U16(u16)  ((KU16)(u16))
     104# define KLDR_LE2H_U32(u32)  ((KU32)(u32))
     105# define KLDR_LE2H_U64(u64)  ((KU32)(u32))
    148106# define KLDR_BE2H_U16(u16)  KLDR_E2E_U16(u16)
    149107# define KLDR_BE2H_U32(u32)  KLDR_E2E_U32(u32)
     
    153111# define KLDR_LE2H_U32(u32)  KLDR_E2E_U32(u32)
    154112# define KLDR_LE2H_U32(u64)  KLDR_E2E_U64(u64)
    155 # define KLDR_BE2H_U16(u16)  ((uint16_t)(u16))
    156 # define KLDR_BE2H_U32(u32)  ((uint32_t)(u32))
    157 # define KLDR_BE2H_U64(u64)  ((uint32_t)(u32))
     113# define KLDR_BE2H_U16(u16)  ((KU16)(u16))
     114# define KLDR_BE2H_U32(u32)  ((KU32)(u32))
     115# define KLDR_BE2H_U64(u64)  ((KU32)(u32))
    158116#else
    159117# error "KLDR_BIG_ENDIAN or KLDR_LITTLE_ENDIAN is supposed to be defined."
Note: See TracChangeset for help on using the changeset viewer.