8 |
* your option) any later version. |
* your option) any later version. |
9 |
*/ |
*/ |
10 |
|
|
11 |
#if defined(__linux__) || defined(__FreeBSD__) || defined(GRUB) |
#define __LITTLE_ENDIAN /* x86 */ |
|
#define ETHERBOOT32 |
|
|
#define ntohl(x) swap32(x) |
|
|
#define htonl(x) swap32(x) |
|
|
#define ntohs(x) swap16(x) |
|
|
#define htons(x) swap16(x) |
|
12 |
|
|
13 |
static inline unsigned long int swap32(unsigned long int x) |
/* Taken from /usr/include/linux/hfs_sysdep.h */ |
14 |
|
#if defined(__BIG_ENDIAN) |
15 |
|
# if !defined(__constant_htonl) |
16 |
|
# define __constant_htonl(x) (x) |
17 |
|
# endif |
18 |
|
# if !defined(__constant_htons) |
19 |
|
# define __constant_htons(x) (x) |
20 |
|
# endif |
21 |
|
#elif defined(__LITTLE_ENDIAN) |
22 |
|
# if !defined(__constant_htonl) |
23 |
|
# define __constant_htonl(x) \ |
24 |
|
((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \ |
25 |
|
(((unsigned long int)(x) & 0x0000ff00U) << 8) | \ |
26 |
|
(((unsigned long int)(x) & 0x00ff0000U) >> 8) | \ |
27 |
|
(((unsigned long int)(x) & 0xff000000U) >> 24))) |
28 |
|
# endif |
29 |
|
# if !defined(__constant_htons) |
30 |
|
# define __constant_htons(x) \ |
31 |
|
((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \ |
32 |
|
(((unsigned short int)(x) & 0xff00) >> 8))) |
33 |
|
# endif |
34 |
|
#else |
35 |
|
# error "Don't know if bytes are big- or little-endian!" |
36 |
|
#endif |
37 |
|
|
38 |
|
#define ntohl(x) \ |
39 |
|
(__builtin_constant_p(x) ? \ |
40 |
|
__constant_htonl((x)) : \ |
41 |
|
__swap32(x)) |
42 |
|
#define htonl(x) \ |
43 |
|
(__builtin_constant_p(x) ? \ |
44 |
|
__constant_htonl((x)) : \ |
45 |
|
__swap32(x)) |
46 |
|
#define ntohs(x) \ |
47 |
|
(__builtin_constant_p(x) ? \ |
48 |
|
__constant_htons((x)) : \ |
49 |
|
__swap16(x)) |
50 |
|
#define htons(x) \ |
51 |
|
(__builtin_constant_p(x) ? \ |
52 |
|
__constant_htons((x)) : \ |
53 |
|
__swap16(x)) |
54 |
|
|
55 |
|
static inline unsigned long int __swap32(unsigned long int x) |
56 |
{ |
{ |
57 |
__asm__("xchgb %b0,%h0\n\t" |
__asm__("xchgb %b0,%h0\n\t" |
58 |
"rorl $16,%0\n\t" |
"rorl $16,%0\n\t" |
62 |
return x; |
return x; |
63 |
} |
} |
64 |
|
|
65 |
static inline unsigned short int swap16(unsigned short int x) |
static inline unsigned short int __swap16(unsigned short int x) |
66 |
{ |
{ |
67 |
__asm__("xchgb %b0,%h0" |
__asm__("xchgb %b0,%h0" |
68 |
: "=q" (x) |
: "=q" (x) |
70 |
return x; |
return x; |
71 |
} |
} |
72 |
|
|
73 |
#ifndef GRUB |
/* Make routines available to all */ |
74 |
# include "linux-asm-string.h" |
#define swap32(x) __swap32(x) |
75 |
#endif /* ! GRUB */ |
#define swap16(x) __swap16(x) |
|
#include "linux-asm-io.h" |
|
|
#ifndef GRUB |
|
|
#define _edata edata /* ELF does not prepend a _ */ |
|
|
#define _end end |
|
|
#endif /* ! GRUB */ |
|
|
#endif |
|
76 |
|
|
77 |
#ifdef __BCC__ |
#include "linux-asm-io.h" |
|
#define ETHERBOOT16 |
|
|
#define inline |
|
|
#define const |
|
|
#define volatile |
|
|
#define setjmp _setjmp /* they are that way in libc.a */ |
|
|
#define longjmp _longjmp |
|
|
|
|
|
/* BCC include files are missing these. */ |
|
|
typedef unsigned char u_char; |
|
|
typedef unsigned short u_short; |
|
|
typedef unsigned int u_int; |
|
|
typedef unsigned long u_long; |
|
|
#endif |
|
|
|
|
|
#if !defined(ETHERBOOT16) && !defined(ETHERBOOT32) |
|
|
Error, neither ETHERBOOT16 nor ETHERBOOT32 defined |
|
|
#endif |
|
|
|
|
|
#if defined(ETHERBOOT16) && defined(ETHERBOOT32) |
|
|
Error, both ETHERBOOT16 and ETHERBOOT32 defined |
|
|
#endif |
|
78 |
|
|
79 |
typedef unsigned long Address; |
typedef unsigned long Address; |
80 |
|
|