OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [bsd_tcpip/] [current/] [include/] [sys/] [endian.h] - Blame information for rev 808

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      include/sys/endian.h
4
//
5
//==========================================================================
6
// ####BSDCOPYRIGHTBEGIN####                                    
7
// -------------------------------------------                  
8
// This file is part of eCos, the Embedded Configurable Operating System.
9
//
10
// Portions of this software may have been derived from FreeBSD 
11
// or other sources, and if so are covered by the appropriate copyright
12
// and license included herein.                                 
13
//
14
// Portions created by the Free Software Foundation are         
15
// Copyright (C) 2002 Free Software Foundation, Inc.            
16
// -------------------------------------------                  
17
// ####BSDCOPYRIGHTEND####                                      
18
//==========================================================================
19
 
20
//==========================================================================
21
//
22
//      include/sys/endian.h
23
//
24
//      
25
//
26
//==========================================================================
27
//#####DESCRIPTIONBEGIN####
28
//
29
// Author(s):    gthomas
30
// Contributors: gthomas
31
// Date:         2000-01-10
32
// Purpose:      
33
// Description:  
34
//              
35
//
36
//####DESCRIPTIONEND####
37
//
38
//==========================================================================
39
 
40
 
41
/*      $OpenBSD: endian.h,v 1.4 1999/07/21 05:58:25 csapuntz Exp $     */
42
 
43
/*-
44
 * Copyright (c) 1997 Niklas Hallqvist.  All rights reserved.
45
 *
46
 * Redistribution and use in source and binary forms, with or without
47
 * modification, are permitted provided that the following conditions
48
 * are met:
49
 * 1. Redistributions of source code must retain the above copyright
50
 *    notice, this list of conditions and the following disclaimer.
51
 * 2. Redistributions in binary form must reproduce the above copyright
52
 *    notice, this list of conditions and the following disclaimer in the
53
 *    documentation and/or other materials provided with the distribution.
54
 * 3. All advertising materials mentioning features or use of this software
55
 *    must display the following acknowledgement:
56
 *      This product includes software developed by Niklas Hallqvist.
57
 * 4. The name of the author may not be used to endorse or promote products
58
 *    derived from this software without specific prior written permission.
59
 *
60
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
61
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
62
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
63
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
64
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
65
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
66
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
67
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
68
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
69
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
70
 */
71
 
72
/*
73
 * Generic definitions for little- and big-endian systems.  Other endianesses
74
 * has to be dealt with in the specific machine/endian.h file for that port.
75
 *
76
 * This file is meant to be included from a little- or big-endian port's
77
 * machine/endian.h after setting BYTE_ORDER to either 1234 for little endian
78
 * or 4321 for big..
79
 */
80
 
81
#ifndef _SYS_ENDIAN_H_
82
#define _SYS_ENDIAN_H_
83
 
84
#include <cyg/hal/basetype.h>
85
 
86
#if CYG_BYTEORDER == CYG_MSBFIRST
87
#define BYTE_ORDER BIG_ENDIAN
88
#else
89
#define BYTE_ORDER LITTLE_ENDIAN
90
#endif
91
 
92
#ifndef _POSIX_SOURCE
93
 
94
#define LITTLE_ENDIAN   1234
95
#define BIG_ENDIAN      4321
96
#define PDP_ENDIAN      3412
97
 
98
#ifdef __GNUC__
99
 
100
#define __swap16gen(x) ({                                               \
101
        cyg_uint16 __swap16gen_x = (x);                                 \
102
                                                                        \
103
        (cyg_uint16)((__swap16gen_x & 0xff) << 8 |                      \
104
            (__swap16gen_x & 0xff00) >> 8);                             \
105
})
106
 
107
#define __swap32gen(x) ({                                               \
108
        cyg_uint32 __swap32gen_x = (x);                                 \
109
                                                                        \
110
        (cyg_uint32)((__swap32gen_x & 0xff) << 24 |                     \
111
            (__swap32gen_x & 0xff00) << 8 |                             \
112
            (__swap32gen_x & 0xff0000) >> 8 |                           \
113
            (__swap32gen_x & 0xff000000) >> 24);                        \
114
})
115
 
116
#else /* __GNUC__ */
117
 
118
/* Note that these macros evaluate their arguments several times.  */
119
#define __swap16gen(x)                                                  \
120
    (cyg_uint16)(((cyg_uint16)(x) & 0xff) << 8 | ((cyg_uint16)(x) & 0xff00) >> 8)
121
 
122
#define __swap32gen(x)                                                  \
123
    (cyg_uint32)(((cyg_uint32)(x) & 0xff) << 24 |                               \
124
    ((cyg_uint32)(x) & 0xff00) << 8 | ((cyg_uint32)(x) & 0xff0000) >> 8 |       \
125
    ((cyg_uint32)(x) & 0xff000000) >> 24)
126
 
127
#endif /* __GNUC__ */
128
 
129
/*
130
 * Define MD_SWAP if you provide swap{16,32}md functions/macros that are
131
 * optimized for your architecture,  These will be used for swap{16,32}
132
 * unless the argument is a constant and we are using GCC, where we can
133
 * take advantage of the CSE phase much better by using the generic version.
134
 */
135
#ifdef MD_SWAP
136
#if __GNUC__
137
 
138
#define swap16(x) ({                                                    \
139
        cyg_uint16 __swap16_x = (x);                                    \
140
                                                                        \
141
        __builtin_constant_p(x) ? __swap16gen(__swap16_x) :             \
142
            __swap16md(__swap16_x);                                     \
143
})
144
 
145
#define swap32(x) ({                                                    \
146
        cyg_uint32 __swap32_x = (x);                                    \
147
                                                                        \
148
        __builtin_constant_p(x) ? __swap32gen(__swap32_x) :             \
149
            __swap32md(__swap32_x);                                     \
150
})
151
 
152
#endif /* __GNUC__  */
153
 
154
#else /* MD_SWAP */
155
#define swap16 __swap16gen
156
#define swap32 __swap32gen
157
#endif /* MD_SWAP */
158
 
159
#define swap16_multi(v, n) do {                                         \
160
        size_t __swap16_multi_n = (n);                                  \
161
        cyg_uint16 *__swap16_multi_v = (v);                             \
162
                                                                        \
163
        while (__swap16_multi_n) {                                      \
164
                *__swap16_multi_v = swap16(*__swap16_multi_v);          \
165
                __swap16_multi_v++;                                     \
166
                __swap16_multi_n--;                                     \
167
        }                                                               \
168
} while (0)
169
 
170
cyg_uint32      htobe32 __P((cyg_uint32));
171
cyg_uint16      htobe16 __P((cyg_uint16));
172
cyg_uint32      betoh32 __P((cyg_uint32));
173
cyg_uint16      betoh16 __P((cyg_uint16));
174
 
175
cyg_uint32      htole32 __P((cyg_uint32));
176
cyg_uint16      htole16 __P((cyg_uint16));
177
cyg_uint32      letoh32 __P((cyg_uint32));
178
cyg_uint16      letoh16 __P((cyg_uint16));
179
 
180
#if BYTE_ORDER == LITTLE_ENDIAN
181
 
182
/* Can be overridden by machine/endian.h before inclusion of this file.  */
183
#ifndef _QUAD_HIGHWORD
184
#define _QUAD_HIGHWORD 1
185
#endif
186
#ifndef _QUAD_LOWWORD
187
#define _QUAD_LOWWORD 0
188
#endif
189
 
190
#define htobe16 swap16
191
#define htobe32 swap32
192
#define betoh16 swap16
193
#define betoh32 swap32
194
 
195
#define htole16(x) (x)
196
#define htole32(x) (x)
197
#define letoh16(x) (x)
198
#define letoh32(x) (x)
199
 
200
#endif /* BYTE_ORDER */
201
 
202
#if BYTE_ORDER == BIG_ENDIAN
203
 
204
/* Can be overridden by machine/endian.h before inclusion of this file.  */
205
#ifndef _QUAD_HIGHWORD
206
#define _QUAD_HIGHWORD 0
207
#endif
208
#ifndef _QUAD_LOWWORD
209
#define _QUAD_LOWWORD 1
210
#endif
211
 
212
#define htole16 swap16
213
#define htole32 swap32
214
#define letoh16 swap16
215
#define letoh32 swap32
216
 
217
#define htobe16(x) (x)
218
#define htobe32(x) (x)
219
#define betoh16(x) (x)
220
#define betoh32(x) (x)
221
 
222
#endif /* BYTE_ORDER */
223
 
224
#define htons htobe16
225
#define htonl htobe32
226
#define ntohs betoh16
227
#define ntohl betoh32
228
 
229
#define NTOHL(x) (x) = ntohl((cyg_uint32)(x))
230
#define NTOHS(x) (x) = ntohs((cyg_uint16)(x))
231
#define HTONL(x) (x) = htonl((cyg_uint32)(x))
232
#define HTONS(x) (x) = htons((cyg_uint16)(x))
233
 
234
#endif /* _POSIX_SOURCE */
235
#endif /* _SYS_ENDIAN_H_ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.