1cb9cadadSEd Warnicke/*
2cb9cadadSEd Warnicke * Copyright (c) 2015 Cisco and/or its affiliates.
3cb9cadadSEd Warnicke * Licensed under the Apache License, Version 2.0 (the "License");
4cb9cadadSEd Warnicke * you may not use this file except in compliance with the License.
5cb9cadadSEd Warnicke * You may obtain a copy of the License at:
6cb9cadadSEd Warnicke *
7cb9cadadSEd Warnicke *     http://www.apache.org/licenses/LICENSE-2.0
8cb9cadadSEd Warnicke *
9cb9cadadSEd Warnicke * Unless required by applicable law or agreed to in writing, software
10cb9cadadSEd Warnicke * distributed under the License is distributed on an "AS IS" BASIS,
11cb9cadadSEd Warnicke * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb9cadadSEd Warnicke * See the License for the specific language governing permissions and
13cb9cadadSEd Warnicke * limitations under the License.
14cb9cadadSEd Warnicke */
15cb9cadadSEd Warnicke/*
16cb9cadadSEd Warnicke  Copyright (c) 2001-2005 Eliot Dresselhaus
17cb9cadadSEd Warnicke
18cb9cadadSEd Warnicke  Permission is hereby granted, free of charge, to any person obtaining
19cb9cadadSEd Warnicke  a copy of this software and associated documentation files (the
20cb9cadadSEd Warnicke  "Software"), to deal in the Software without restriction, including
21cb9cadadSEd Warnicke  without limitation the rights to use, copy, modify, merge, publish,
22cb9cadadSEd Warnicke  distribute, sublicense, and/or sell copies of the Software, and to
23cb9cadadSEd Warnicke  permit persons to whom the Software is furnished to do so, subject to
24cb9cadadSEd Warnicke  the following conditions:
25cb9cadadSEd Warnicke
26cb9cadadSEd Warnicke  The above copyright notice and this permission notice shall be
27cb9cadadSEd Warnicke  included in all copies or substantial portions of the Software.
28cb9cadadSEd Warnicke
29cb9cadadSEd Warnicke  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30cb9cadadSEd Warnicke  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31cb9cadadSEd Warnicke  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32cb9cadadSEd Warnicke  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33cb9cadadSEd Warnicke  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34cb9cadadSEd Warnicke  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35cb9cadadSEd Warnicke  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36cb9cadadSEd Warnicke*/
37cb9cadadSEd Warnicke
38cb9cadadSEd Warnicke#ifndef included_clib_types_h
39cb9cadadSEd Warnicke#define included_clib_types_h
40cb9cadadSEd Warnicke
41cb9cadadSEd Warnicke/* Standard CLIB types. */
42cb9cadadSEd Warnicke
43cb9cadadSEd Warnicke/* Define signed and unsigned 8, 16, 32, and 64 bit types
44cb9cadadSEd Warnicke   and machine signed/unsigned word for all architectures. */
45ffe9d21bSDamjan Mariontypedef signed char i8;
46ffe9d21bSDamjan Mariontypedef signed short i16;
47cb9cadadSEd Warnicke
48cb9cadadSEd Warnicke/* Avoid conflicts with Linux asm/types.h when __KERNEL__ */
49cb9cadadSEd Warnicke#if defined(CLIB_LINUX_KERNEL)
50cb9cadadSEd Warnicke/* Linux also defines u8/u16/u32/u64 types. */
51cb9cadadSEd Warnicke#include <asm/types.h>
52cb9cadadSEd Warnicke#define CLIB_AVOID_CLASH_WITH_LINUX_TYPES
53cb9cadadSEd Warnicke
54c3799996SDave Barach#else /* ! CLIB_LINUX_KERNEL */
55cb9cadadSEd Warnicke
56cb9cadadSEd Warnicketypedef unsigned char u8;
57cb9cadadSEd Warnicketypedef unsigned short u16;
58cb9cadadSEd Warnicke#endif /* ! CLIB_LINUX_KERNEL */
59cb9cadadSEd Warnicke
60cb9cadadSEd Warnicke#if defined (__x86_64__)
61cb9cadadSEd Warnicke#ifndef __COVERITY__
62ffe9d21bSDamjan Mariontypedef signed int i128 __attribute__ ((mode (TI)));
63cb9cadadSEd Warnicketypedef unsigned int u128 __attribute__ ((mode (TI)));
64cb9cadadSEd Warnicke#endif
65cb9cadadSEd Warnicke#endif
66cb9cadadSEd Warnicke
6728d4271dSCarl Smith#if (defined(i386) || (defined(_mips) && __mips != 64) || defined(powerpc) || defined (__SPU__) || defined(__sparc__) || defined(__arm__) || defined (__xtensa__) || defined(__TMS320C6X__))
68ffe9d21bSDamjan Mariontypedef signed int i32;
69ffe9d21bSDamjan Mariontypedef signed long long i64;
70cb9cadadSEd Warnicke
71cb9cadadSEd Warnicke#ifndef CLIB_AVOID_CLASH_WITH_LINUX_TYPES
72cb9cadadSEd Warnicketypedef unsigned int u32;
73cb9cadadSEd Warnicketypedef unsigned long long u64;
74cb9cadadSEd Warnicke#endif /* CLIB_AVOID_CLASH_WITH_LINUX_TYPES */
75cb9cadadSEd Warnicke
7628d4271dSCarl Smith#elif defined(alpha) || (defined(_mips) && __mips == 64) || defined(__x86_64__) || defined (__powerpc64__) || defined (__aarch64__)
77ffe9d21bSDamjan Mariontypedef signed int i32;
78ffe9d21bSDamjan Mariontypedef signed long i64;
79cb9cadadSEd Warnicke
80cb9cadadSEd Warnicke#define log2_uword_bits 6
8128d4271dSCarl Smith#if defined(_mips)
8228d4271dSCarl Smith#define clib_address_bits _MIPS_SZPTR
8328d4271dSCarl Smith#else
84cb9cadadSEd Warnicke#define clib_address_bits 64
8528d4271dSCarl Smith#endif
86cb9cadadSEd Warnicke
87cb9cadadSEd Warnicke#ifndef CLIB_AVOID_CLASH_WITH_LINUX_TYPES
88cb9cadadSEd Warnicketypedef unsigned int u32;
89cb9cadadSEd Warnicketypedef unsigned long u64;
90cb9cadadSEd Warnicke#endif /* CLIB_AVOID_CLASH_WITH_LINUX_TYPES */
91cb9cadadSEd Warnicke
92cb9cadadSEd Warnicke#else
93cb9cadadSEd Warnicke#error "can't define types"
94cb9cadadSEd Warnicke#endif
95cb9cadadSEd Warnicke
96cb9cadadSEd Warnicke/* Default to 32 bit machines with 32 bit addresses. */
97cb9cadadSEd Warnicke#ifndef log2_uword_bits
98cb9cadadSEd Warnicke#define log2_uword_bits 5
99cb9cadadSEd Warnicke#endif
100cb9cadadSEd Warnicke
101cb9cadadSEd Warnicke/* #ifdef's above define log2_uword_bits. */
102cb9cadadSEd Warnicke#define uword_bits (1 << log2_uword_bits)
103cb9cadadSEd Warnicke
104cb9cadadSEd Warnicke#ifndef clib_address_bits
105cb9cadadSEd Warnicke#define clib_address_bits 32
106cb9cadadSEd Warnicke#endif
107cb9cadadSEd Warnicke
108cb9cadadSEd Warnicke/* Word types. */
109cb9cadadSEd Warnicke#if uword_bits == 64
110cb9cadadSEd Warnicke/* 64 bit word machines. */
111cb9cadadSEd Warnicketypedef i64 word;
112cb9cadadSEd Warnicketypedef u64 uword;
113cb9cadadSEd Warnicke#else
114cb9cadadSEd Warnicke/* 32 bit word machines. */
115cb9cadadSEd Warnicketypedef i32 word;
116cb9cadadSEd Warnicketypedef u32 uword;
117cb9cadadSEd Warnicke#endif
118cb9cadadSEd Warnicke
119cb9cadadSEd Warnicke/* integral type of a pointer (used to cast pointers). */
120cb9cadadSEd Warnicke#if clib_address_bits == 64
121cb9cadadSEd Warnicketypedef u64 clib_address_t;
122cb9cadadSEd Warnicke#else
123cb9cadadSEd Warnicketypedef u32 clib_address_t;
124cb9cadadSEd Warnicke#endif
125cb9cadadSEd Warnicke
126cb9cadadSEd Warnicke/* These are needed to convert between pointers and machine words.
127cb9cadadSEd Warnicke   MIPS is currently the only machine that can have different sized
128cb9cadadSEd Warnicke   pointers and machine words (but only when compiling with 64 bit
129cb9cadadSEd Warnicke   registers and 32 bit pointers). */
130cb9cadadSEd Warnickestatic inline __attribute__ ((always_inline)) uword
131c3799996SDave Barachpointer_to_uword (const void *p)
132c3799996SDave Barach{
133c3799996SDave Barach  return (uword) (clib_address_t) p;
134c3799996SDave Barach}
135cb9cadadSEd Warnicke
136cb9cadadSEd Warnicke#define uword_to_pointer(u,type) ((type) (clib_address_t) (u))
137cb9cadadSEd Warnicke
138cb9cadadSEd Warnicke/* Any type: can be either word or pointer. */
139cb9cadadSEd Warnicketypedef word any;
140cb9cadadSEd Warnicke
141cb9cadadSEd Warnicke/* Floating point types. */
142cb9cadadSEd Warnicketypedef double f64;
143cb9cadadSEd Warnicketypedef float f32;
144cb9cadadSEd Warnicke
145cb9cadadSEd Warnicketypedef __complex__ float cf32;
146cb9cadadSEd Warnicketypedef __complex__ double cf64;
147cb9cadadSEd Warnicke
148cb9cadadSEd Warnicke/* Floating point word size. */
149cb9cadadSEd Warnicketypedef f64 fword;
150cb9cadadSEd Warnicke
151cb9cadadSEd Warnicke/* Can be used as either {r,l}value, e.g. these both work
152cb9cadadSEd Warnicke     clib_mem_unaligned (p, u64) = 99
153cb9cadadSEd Warnicke     clib_mem_unaligned (p, u64) += 99 */
154cb9cadadSEd Warnicke
155cb9cadadSEd Warnicke#define clib_mem_unaligned(pointer,type) \
156cb9cadadSEd Warnicke  (((struct { CLIB_PACKED (type _data); } *) (pointer))->_data)
157cb9cadadSEd Warnicke
158cb9cadadSEd Warnicke/* Access memory with specified alignment depending on align argument.
159cb9cadadSEd Warnicke   As with clib_mem_unaligned, may be used as {r,l}value. */
160cb9cadadSEd Warnicke#define clib_mem_aligned(addr,type,align)		\
161cb9cadadSEd Warnicke  (((struct {						\
162cb9cadadSEd Warnicke       type _data					\
163cb9cadadSEd Warnicke       __attribute__ ((aligned (align), packed));	\
164cb9cadadSEd Warnicke    } *) (addr))->_data)
165cb9cadadSEd Warnicke
166cb9cadadSEd Warnicke#endif /* included_clib_types_h */
167c3799996SDave Barach
168c3799996SDave Barach/*
169c3799996SDave Barach * fd.io coding-style-patch-verification: ON
170c3799996SDave Barach *
171c3799996SDave Barach * Local Variables:
172c3799996SDave Barach * eval: (c-set-style "gnu")
173c3799996SDave Barach * End:
174c3799996SDave Barach */
175