1/**
2 * \file
3 * \brief lwIP architecture configuration file for Barrelfish.
4 */
5
6/*
7 * Copyright (c) 2007, 2008, 2011, 2012, ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group.
13 */
14
15#ifndef CC_H
16#define CC_H
17
18#include <string.h>
19#include <stdint.h>
20#include <machine/endian.h>
21
22/* Define platform endianness */
23#ifndef BYTE_ORDER
24#define BYTE_ORDER LITTLE_ENDIAN
25#endif /* BYTE_ORDER */
26
27typedef uint8_t         u8_t;
28typedef int8_t          s8_t;
29typedef uint16_t        u16_t;
30typedef int16_t         s16_t;
31typedef uint32_t        u32_t;
32typedef int32_t         s32_t;
33typedef uintptr_t       mem_ptr_t;
34
35// (sn)printf() format strings for integer types
36#define U16_F "hu"
37#define S16_F "hd"
38#define X16_F "hx"
39#define U32_F "u"
40#define S32_F "d"
41#define X32_F "x"
42
43/* Compiler hints for packing structures */
44#if __GNUC__ >= 4
45/* GCC 4.1 doesn't like '__attribute__((packed))' after a field declaration */
46#define PACK_STRUCT_FIELD(x) x
47#define PACK_STRUCT_STRUCT __attribute__((packed))
48#define PACK_STRUCT_BEGIN
49#define PACK_STRUCT_END
50#else
51#define PACK_STRUCT_FIELD(x) x __attribute__((packed))
52#define PACK_STRUCT_STRUCT __attribute__((packed))
53#define PACK_STRUCT_BEGIN
54#define PACK_STRUCT_END
55#endif /* __GNUC__ */
56
57#define INLINE  inline
58
59#include <stdio.h>
60#include <stdlib.h>
61
62
63#define LWIP_PLATFORM_DIAG(x)   do {printf x;} while(0)
64#define LWIP_PLATFORM_ASSERT(x) do {printf("Assertion \"%s\" failed at line %d in %s\n", \
65                                     x, __LINE__, __FILE__); fflush(NULL); abort();} while(0)
66
67// Declare [nh]to[nh][ls]() in this header, so we don't depend on liblwip.a
68// when using them.
69
70#define LWIP_PLATFORM_BYTESWAP 1
71
72// Use optimized version if available
73#ifdef __htonl
74
75#define LWIP_PLATFORM_HTONS(x) __htons(x)
76#define LWIP_PLATFORM_HTONL(x) __htonl(x)
77#define LWIP_PLATFORM_NTOHS(x) __ntohs(x)
78#define LWIP_PLATFORM_NTOHL(x) __ntohl(x)
79
80#else
81
82/**
83 * Convert an u16_t from host- to network byte order.
84 *
85 * @param n u16_t in host byte order
86 * @return n in network byte order
87 */
88static inline u16_t barrelfish_htons(u16_t n)
89{
90    return ((n & 0xff) << 8) | ((n & 0xff00) >> 8);
91}
92
93/**
94 * Convert an u16_t from network- to host byte order.
95 *
96 * @param n u16_t in network byte order
97 * @return n in host byte order
98 */
99static inline u16_t barrelfish_ntohs(u16_t n)
100{
101    return barrelfish_htons(n);
102}
103
104/**
105 * Convert an u32_t from host- to network byte order.
106 *
107 * @param n u32_t in host byte order
108 * @return n in network byte order
109 */
110static inline u32_t barrelfish_htonl(u32_t n)
111{
112    return ((n & 0xff) << 24) |
113      ((n & 0xff00) << 8) |
114      ((n & 0xff0000UL) >> 8) | ((n & 0xff000000UL) >> 24);
115}
116
117/**
118 * Convert an u32_t from network- to host byte order.
119 *
120 * @param n u32_t in network byte order
121 * @return n in host byte order
122 */
123static inline u32_t barrelfish_ntohl(u32_t n)
124{
125    return barrelfish_htonl(n);
126}
127
128#define LWIP_PLATFORM_HTONS(x) barrelfish_htons(x)
129#define LWIP_PLATFORM_HTONL(x) barrelfish_htonl(x)
130#define LWIP_PLATFORM_NTOHS(x) barrelfish_ntohs(x)
131#define LWIP_PLATFORM_NTOHL(x) barrelfish_ntohl(x)
132
133#endif
134
135#endif
136