54ecbf38 |
1 | /* |
2 | * LTTTypes.h |
3 | * |
4 | * Copyright (C) 2000 Karim Yaghmour (karym@opersys.com). |
5 | * |
6 | * This is distributed under GPL. |
7 | * |
8 | * Header for LTT-secific types. |
9 | * |
10 | * History : |
11 | * K.Y. 07/09/2001, Added David Schleef's architecture independent ltt_set_bit/ltt_clear_bit/ltt_test_bit |
12 | * JAL, 05/01/2001, Modified PPC bit manipulation functions for x86 compatibility. |
13 | * (andy_lowe@mvista.com) |
14 | * K.Y., 31/05/2000, Initial typing. |
15 | */ |
16 | |
17 | #ifndef __TRACE_TOOLKIT_TYPES_HEADER__ |
18 | #define __TRACE_TOOLKIT_TYPES_HEADER__ |
19 | |
20 | #include <sys/types.h> |
21 | #include <sys/time.h> |
22 | |
23 | #if defined(sun) |
24 | |
25 | typedef unsigned char u_int8_t; |
26 | typedef unsigned short u_int16_t; |
27 | typedef unsigned int u_int32_t; |
28 | #ifdef _LP64 |
29 | typedef unsigned long u_int64_t; |
30 | #else /* _ILP32 */ |
31 | #if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG) |
32 | typedef unsigned long long u_int64_t; |
33 | #endif /* __STDC__ - 0 == 0 && !defined(_NO_LONGLONG) */ |
34 | #endif /* _LP64 */ |
35 | |
36 | #endif /* defined(sun) */ |
37 | |
38 | extern __inline__ int ltt_set_bit(int nr, void * addr) |
39 | { |
40 | unsigned char *p = addr; |
41 | unsigned char mask = 1 << (nr&7); |
42 | unsigned char old; |
43 | |
44 | p += nr>>3; |
45 | old = *p; |
46 | *p |= mask; |
47 | |
48 | return ((old & mask) != 0); |
49 | } |
50 | |
51 | extern __inline__ int ltt_clear_bit(int nr, void * addr) |
52 | { |
53 | unsigned char *p = addr; |
54 | unsigned char mask = 1 << (nr&7); |
55 | unsigned char old; |
56 | |
57 | p += nr>>3; |
58 | old = *p; |
59 | *p &= ~mask; |
60 | |
61 | return ((old & mask) != 0); |
62 | } |
63 | |
64 | extern __inline__ int ltt_test_bit(int nr,void *addr) |
65 | { |
66 | unsigned char *p = addr; |
67 | unsigned char mask = 1 << (nr&7); |
68 | |
69 | p += nr>>3; |
70 | |
71 | return ((*p & mask) != 0); |
72 | } |
73 | |
74 | /* Big-endian/little-endian conversion macros for cross-development. */ |
75 | #if TARGET_NATIVE |
76 | /* For native development, these conversion macros aren't needed. */ |
77 | #define BREV16(x) (x) |
78 | #define BREV32(x) (x) |
79 | #define BREV64(x) (x) |
80 | #define RFT8(db,x) (x) |
81 | #define RFT16(db,x) (x) |
82 | #define RFT32(db,x) (x) |
83 | #define RFT64(db,x) (x) |
84 | |
85 | /* Non-native development */ |
86 | #else |
87 | /* BREV16: byte-reverse a 16-bit integer */ |
88 | #define BREV16(x) ((((x) & 0xff00) >> 8) | (((x) & 0x00ff) << 8)) |
89 | /* BREV32: byte-reverse a 32-bit integer */ |
90 | #define BREV32(x) ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ |
91 | | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) |
92 | /* BREV64: byte-reverse a 64-bit integer */ |
93 | #define BREV64(x) ((((x) & 0xff00000000000000) >> 56) \ |
94 | | (((x) & 0x00ff000000000000) >> 40) \ |
95 | | (((x) & 0x0000ff0000000000) >> 24) \ |
96 | | (((x) & 0x000000ff00000000) >> 8) \ |
97 | | (((x) & 0x00000000ff000000) << 8) \ |
98 | | (((x) & 0x0000000000ff0000) << 24) \ |
99 | | (((x) & 0x000000000000ff00) << 40) \ |
100 | | (((x) & 0x00000000000000ff) << 56)) |
101 | /* RFTn: Read From Trace |
102 | * Conditionally byte-reverse an 8-, 16-, 32-, or 64-bit integer |
103 | * based on the value of the ByteRev member of the trace database |
104 | * structure pointer passed as the first argument.. |
105 | */ |
106 | #define RFT8(db,x) (x) |
107 | #define RFT16(db,x) ((db)->ByteRev ? BREV16(x) : (x)) |
108 | #define RFT32(db,x) ((db)->ByteRev ? BREV32(x) : (x)) |
109 | #define RFT64(db,x) ((db)->ByteRev ? BREV64(x) : (x)) |
110 | #endif /* TRACE_TARGET_NATIVE */ |
111 | |
112 | #if !defined(sun) |
113 | /* Some type corrections, just in case */ |
114 | #ifndef uint8_t |
115 | #define uint8_t u_int8_t |
116 | #endif |
117 | #ifndef uint16_t |
118 | #define uint16_t u_int16_t |
119 | #endif |
120 | #ifndef uint32_t |
121 | #define uint32_t u_int32_t |
122 | #endif |
123 | #ifndef uint64_t |
124 | #define uint64_t u_int64_t |
125 | #endif |
126 | #endif /* !defined(sun) */ |
127 | |
128 | /* Structure packing */ |
129 | #if LTT_UNPACKED_STRUCTS |
130 | #define LTT_PACKED_STRUCT |
131 | #else |
132 | #define LTT_PACKED_STRUCT __attribute__ ((packed)) |
133 | #endif /* UNPACKED_STRUCTS */ |
134 | |
135 | /* Trace mask */ |
136 | typedef uint64_t trace_event_mask; |
137 | |
138 | /* Boolean stuff */ |
139 | //#define TRUE 1 |
140 | //#define FALSE 0 |
141 | |
142 | #endif /* __TRACE_TOOLKIT_TYPES_HEADER__ */ |