]>
Commit | Line | Data |
---|---|---|
489233b4 MM |
1 | /* |
2 | * The PCI Library -- System-Dependent Stuff | |
3 | * | |
4 | * Copyright (c) 1997--2004 Martin Mares <mj@ucw.cz> | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #ifdef __GNUC__ | |
10 | #define UNUSED __attribute__((unused)) | |
11 | #define NONRET __attribute__((noreturn)) | |
12 | #else | |
13 | #define UNUSED | |
14 | #define NONRET | |
15 | #define inline | |
16 | #endif | |
17 | ||
f31412d1 MM |
18 | typedef u8 byte; |
19 | typedef u16 word; | |
20 | ||
ee7d8384 | 21 | #ifdef PCI_OS_WINDOWS |
ee7d8384 MM |
22 | #define strcasecmp strcmpi |
23 | #endif | |
24 | ||
489233b4 MM |
25 | #ifdef PCI_HAVE_LINUX_BYTEORDER_H |
26 | ||
27 | #include <asm/byteorder.h> | |
28 | #define cpu_to_le16 __cpu_to_le16 | |
29 | #define cpu_to_le32 __cpu_to_le32 | |
30 | #define le16_to_cpu __le16_to_cpu | |
31 | #define le32_to_cpu __le32_to_cpu | |
32 | ||
33 | #else | |
34 | ||
35 | #ifdef PCI_OS_LINUX | |
36 | #include <endian.h> | |
37 | #define BYTE_ORDER __BYTE_ORDER | |
38 | #define BIG_ENDIAN __BIG_ENDIAN | |
39 | #endif | |
40 | ||
41 | #ifdef PCI_OS_SUNOS | |
42 | #include <sys/byteorder.h> | |
033a6ecb MM |
43 | #if defined(__i386) && defined(LITTLE_ENDIAN) |
44 | # define BYTE_ORDER LITTLE_ENDIAN | |
45 | #elif defined(__sparc) && defined(BIG_ENDIAN) | |
46 | # define BYTE_ORDER BIG_ENDIAN | |
47 | #else | |
489233b4 | 48 | #define BIG_ENDIAN 4321 |
033a6ecb MM |
49 | #endif |
50 | #ifndef BYTE_ORDER | |
489233b4 MM |
51 | #ifdef _LITTLE_ENDIAN |
52 | #define BYTE_ORDER 1234 | |
53 | #else | |
54 | #define BYTE_ORDER 4321 | |
55 | #endif | |
033a6ecb MM |
56 | #endif /* BYTE_ORDER */ |
57 | #endif /* PCI_OS_SUNOS */ | |
489233b4 MM |
58 | |
59 | #ifdef PCI_OS_WINDOWS | |
ee7d8384 MM |
60 | #ifdef __MINGW32__ |
61 | #include <sys/param.h> | |
62 | #else | |
63 | #include <io.h> | |
64 | #define BIG_ENDIAN 4321 | |
65 | #define LITTLE_ENDIAN 1234 | |
66 | #define BYTE_ORDER LITTLE_ENDIAN | |
67 | #define snprintf _snprintf | |
68 | #endif | |
489233b4 MM |
69 | #endif |
70 | ||
5c5ce192 RM |
71 | #ifdef PCI_OS_DJGPP |
72 | #define BIG_ENDIAN 4321 | |
73 | #define LITTLE_ENDIAN 1234 | |
74 | #define BYTE_ORDER LITTLE_ENDIAN | |
75 | #endif | |
76 | ||
77 | #if !defined(BYTE_ORDER) | |
78 | #error "BYTE_ORDER not defined for your platform" | |
79 | #endif | |
80 | ||
489233b4 MM |
81 | #if BYTE_ORDER == BIG_ENDIAN |
82 | #define cpu_to_le16 swab16 | |
83 | #define cpu_to_le32 swab32 | |
84 | #define le16_to_cpu swab16 | |
85 | #define le32_to_cpu swab32 | |
86 | ||
87 | static inline word swab16(word w) | |
88 | { | |
89 | return (w << 8) | ((w >> 8) & 0xff); | |
90 | } | |
91 | ||
92 | static inline u32 swab32(u32 w) | |
93 | { | |
94 | return ((w & 0xff000000) >> 24) | | |
95 | ((w & 0x00ff0000) >> 8) | | |
96 | ((w & 0x0000ff00) << 8) | | |
97 | ((w & 0x000000ff) << 24); | |
98 | } | |
99 | #else | |
100 | #define cpu_to_le16(x) (x) | |
101 | #define cpu_to_le32(x) (x) | |
102 | #define le16_to_cpu(x) (x) | |
103 | #define le32_to_cpu(x) (x) | |
104 | #endif | |
105 | ||
106 | #endif |