source: rtems/cpukit/libnetworking/machine/endian.h @ 4bf1801

4.104.114.84.95
Last change on this file since 4bf1801 was 96b39164, checked in by Joel Sherrill <joel.sherrill@…>, on 08/20/98 at 21:56:40

Added CVS Ids

  • Property mode set to 100644
File size: 1.3 KB
Line 
1/*
2 *  $Id$
3 */
4
5#ifndef _MACHINE_ENDIAN_H_
6#define _MACHINE_ENDIAN_H_
7
8#include <rtems/score/cpu.h>
9
10/*
11 * BSD-style endian declaration
12 */
13#define BIG_ENDIAN      4321
14#define LITTLE_ENDIAN   1234
15
16#if CPU_BIG_ENDIAN
17# define BYTE_ORDER BIG_ENDIAN
18#elif CPU_LITTLE_ENDIAN
19# define BYTE_ORDER LITTLE_ENDIAN
20#else
21# error "Can't decide which end is which!"
22#endif
23
24#if ( CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES == FALSE )
25
26#if ( CPU_BIG_ENDIAN == TRUE )
27
28/*
29 *  Very simply on big endian CPUs
30 */
31
32#define       ntohl(_x)        (_x)
33#define       ntohs(_x)        (_x)
34#define       htonl(_x)        (_x)
35#define       htons(_x)        (_x)
36
37#define NTOHS(x)
38#define HTONS(x)
39#define NTOHL(x)
40#define HTONL(x)
41
42#elif ( CPU_LITTLE_ENDIAN == TRUE )
43
44/*
45 *  A little more complicated on little endian CPUs
46 */
47
48#define       ntohl(_x)        ((long)  CPU_swap_u32((unsigned32)_x))
49#define       ntohs(_x)        ((short) CPU_swap_u16((unsigned16)_x))
50#define       htonl(_x)        ((long)  CPU_swap_u32((unsigned32)_x))
51#define       htons(_x)        ((short) CPU_swap_u16((unsigned16)_x))
52
53#define NTOHS(x) (x) = ntohs(x)
54#define HTONS(x) (x) = htons(x)
55#define NTOHL(x) (x) = ntohl(x)
56#define HTONL(x) (x) = htonl(x)
57
58#else
59#error "Unknown endian-ness for this cpu"
60#endif
61
62#endif  /* CPU_HAS_OWN_HOST_TO_NETWORK_ROUTINES */
63
64#endif /* _MACHINE_ENDIAN_H_ */
Note: See TracBrowser for help on using the repository browser.