The Pedigree Project 0.1
arch.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
25/*
26 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without modification,
30 * are permitted provided that the following conditions are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49 * OF SUCH DAMAGE.
50 *
51 * This file is part of the lwIP TCP/IP stack.
52 *
53 * Author: Adam Dunkels <adam@sics.se>
54 *
55 */
56#ifndef LWIP_HDR_ARCH_H
57#define LWIP_HDR_ARCH_H
58
59#ifndef LITTLE_ENDIAN
60#define LITTLE_ENDIAN 1234
61#endif
62
63#ifndef BIG_ENDIAN
64#define BIG_ENDIAN 4321
65#endif
66
67#include "arch/cc.h"
68
83#ifndef BYTE_ORDER
84#define BYTE_ORDER LITTLE_ENDIAN
85#endif
86
88#ifdef __DOXYGEN__
89#define LWIP_RAND() ((u32_t)rand())
90#endif
91
97#ifndef LWIP_PLATFORM_DIAG
98#define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
99#include <stdio.h>
100#include <stdlib.h>
101#endif
102
108#ifndef LWIP_PLATFORM_ASSERT
109#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
110 x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
111#include <stdio.h>
112#include <stdlib.h>
113#endif
114
119#ifndef LWIP_NO_STDDEF_H
120#define LWIP_NO_STDDEF_H 0
121#endif
122
123#if !LWIP_NO_STDDEF_H
124#include <stddef.h> /* for size_t */
125#endif
126
131#ifndef LWIP_NO_STDINT_H
132#define LWIP_NO_STDINT_H 0
133#endif
134
135/* Define generic types used in lwIP */
136#if !LWIP_NO_STDINT_H
137#include <stdint.h>
138typedef uint8_t u8_t;
139typedef int8_t s8_t;
140typedef uint16_t u16_t;
141typedef int16_t s16_t;
142typedef uint32_t u32_t;
143typedef int32_t s32_t;
144typedef uintptr_t mem_ptr_t;
145#endif
146
151#ifndef LWIP_NO_INTTYPES_H
152#define LWIP_NO_INTTYPES_H 0
153#endif
154
155/* Define (sn)printf formatters for these lwIP types */
156#if !LWIP_NO_INTTYPES_H
157#include <inttypes.h>
158#ifndef X8_F
159#define X8_F "02" PRIx8
160#endif
161#ifndef U16_F
162#define U16_F PRIu16
163#endif
164#ifndef S16_F
165#define S16_F PRId16
166#endif
167#ifndef X16_F
168#define X16_F PRIx16
169#endif
170#ifndef U32_F
171#define U32_F PRIu32
172#endif
173#ifndef S32_F
174#define S32_F PRId32
175#endif
176#ifndef X32_F
177#define X32_F PRIx32
178#endif
179#ifndef SZT_F
180#define SZT_F PRIuPTR
181#endif
182#endif
183
188#ifndef LWIP_NO_LIMITS_H
189#define LWIP_NO_LIMITS_H 0
190#endif
191
192/* Include limits.h? */
193#if !LWIP_NO_LIMITS_H
194#include <limits.h>
195#endif
196
198#ifndef LWIP_CONST_CAST
199#define LWIP_CONST_CAST(target_type, val) ((target_type)((ptrdiff_t)val))
200#endif
201
203#ifndef LWIP_ALIGNMENT_CAST
204#define LWIP_ALIGNMENT_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
205#endif
206
210#ifndef LWIP_PTR_NUMERIC_CAST
211#define LWIP_PTR_NUMERIC_CAST(target_type, val) LWIP_CONST_CAST(target_type, val)
212#endif
213
224#ifndef LWIP_DECLARE_MEMORY_ALIGNED
225#define LWIP_DECLARE_MEMORY_ALIGNED(variable_name, size) u8_t variable_name[LWIP_MEM_ALIGN_BUFFER(size)]
226#endif
227
232#ifndef LWIP_MEM_ALIGN_SIZE
233#define LWIP_MEM_ALIGN_SIZE(size) (((size) + MEM_ALIGNMENT - 1U) & ~(MEM_ALIGNMENT-1U))
234#endif
235
240#ifndef LWIP_MEM_ALIGN_BUFFER
241#define LWIP_MEM_ALIGN_BUFFER(size) (((size) + MEM_ALIGNMENT - 1U))
242#endif
243
247#ifndef LWIP_MEM_ALIGN
248#define LWIP_MEM_ALIGN(addr) ((void *)(((mem_ptr_t)(addr) + MEM_ALIGNMENT - 1) & ~(mem_ptr_t)(MEM_ALIGNMENT-1)))
249#endif
250
251#ifdef __cplusplus
252extern "C" {
253#endif
254
260#ifndef PACK_STRUCT_BEGIN
261#define PACK_STRUCT_BEGIN
262#endif /* PACK_STRUCT_BEGIN */
263
269#ifndef PACK_STRUCT_END
270#define PACK_STRUCT_END
271#endif /* PACK_STRUCT_END */
272
278#ifndef PACK_STRUCT_STRUCT
279#if defined(__GNUC__) || defined(__clang__)
280#define PACK_STRUCT_STRUCT __attribute__((packed))
281#else
282#define PACK_STRUCT_STRUCT
283#endif
284#endif /* PACK_STRUCT_STRUCT */
285
291#ifndef PACK_STRUCT_FIELD
292#define PACK_STRUCT_FIELD(x) x
293#endif /* PACK_STRUCT_FIELD */
294
300#ifndef PACK_STRUCT_FLD_8
301#define PACK_STRUCT_FLD_8(x) PACK_STRUCT_FIELD(x)
302#endif /* PACK_STRUCT_FLD_8 */
303
309#ifndef PACK_STRUCT_FLD_S
310#define PACK_STRUCT_FLD_S(x) PACK_STRUCT_FIELD(x)
311#endif /* PACK_STRUCT_FLD_S */
312
321#ifdef __DOXYGEN__
322#define PACK_STRUCT_USE_INCLUDES
323#endif
324
326#ifndef LWIP_UNUSED_ARG
327#define LWIP_UNUSED_ARG(x) (void)x
328#endif /* LWIP_UNUSED_ARG */
329
334#ifdef __cplusplus
335}
336#endif
337
338#endif /* LWIP_HDR_ARCH_H */