]>
Commit | Line | Data |
---|---|---|
489233b4 MM |
1 | /* |
2 | * The PCI Library -- System-Dependent Stuff | |
3 | * | |
76d47191 | 4 | * Copyright (c) 1997--2020 Martin Mares <mj@ucw.cz> |
489233b4 MM |
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)) | |
76d47191 | 12 | #define FORMAT_CHECK(x,y,z) __attribute__((format(x,y,z))) |
489233b4 MM |
13 | #else |
14 | #define UNUSED | |
15 | #define NONRET | |
76d47191 | 16 | #define FORMAT_CHECK(x,y,z) |
489233b4 MM |
17 | #define inline |
18 | #endif | |
19 | ||
f31412d1 MM |
20 | typedef u8 byte; |
21 | typedef u16 word; | |
22 | ||
ee7d8384 | 23 | #ifdef PCI_OS_WINDOWS |
959db7be | 24 | #define strcasecmp _strcmpi |
77702981 | 25 | #define strncasecmp _strnicmp |
50088835 | 26 | #if defined(_MSC_VER) && _MSC_VER < 1900 |
4e6fd387 | 27 | #define snprintf _snprintf |
50088835 PR |
28 | #define vsnprintf _vsnprintf |
29 | #endif | |
ee7d8384 MM |
30 | #endif |
31 | ||
489233b4 MM |
32 | #ifdef PCI_HAVE_LINUX_BYTEORDER_H |
33 | ||
34 | #include <asm/byteorder.h> | |
35 | #define cpu_to_le16 __cpu_to_le16 | |
36 | #define cpu_to_le32 __cpu_to_le32 | |
37 | #define le16_to_cpu __le16_to_cpu | |
38 | #define le32_to_cpu __le32_to_cpu | |
39 | ||
40 | #else | |
41 | ||
42 | #ifdef PCI_OS_LINUX | |
43 | #include <endian.h> | |
44 | #define BYTE_ORDER __BYTE_ORDER | |
45 | #define BIG_ENDIAN __BIG_ENDIAN | |
46 | #endif | |
47 | ||
48 | #ifdef PCI_OS_SUNOS | |
49 | #include <sys/byteorder.h> | |
033a6ecb MM |
50 | #if defined(__i386) && defined(LITTLE_ENDIAN) |
51 | # define BYTE_ORDER LITTLE_ENDIAN | |
52 | #elif defined(__sparc) && defined(BIG_ENDIAN) | |
53 | # define BYTE_ORDER BIG_ENDIAN | |
54 | #else | |
489233b4 | 55 | #define BIG_ENDIAN 4321 |
033a6ecb MM |
56 | #endif |
57 | #ifndef BYTE_ORDER | |
489233b4 MM |
58 | #ifdef _LITTLE_ENDIAN |
59 | #define BYTE_ORDER 1234 | |
60 | #else | |
61 | #define BYTE_ORDER 4321 | |
62 | #endif | |
033a6ecb MM |
63 | #endif /* BYTE_ORDER */ |
64 | #endif /* PCI_OS_SUNOS */ | |
489233b4 MM |
65 | |
66 | #ifdef PCI_OS_WINDOWS | |
ee7d8384 MM |
67 | #ifdef __MINGW32__ |
68 | #include <sys/param.h> | |
69 | #else | |
70 | #include <io.h> | |
71 | #define BIG_ENDIAN 4321 | |
72 | #define LITTLE_ENDIAN 1234 | |
73 | #define BYTE_ORDER LITTLE_ENDIAN | |
ee7d8384 | 74 | #endif |
489233b4 MM |
75 | #endif |
76 | ||
83fd885b MM |
77 | #ifdef PCI_OS_SYLIXOS |
78 | #include <endian.h> | |
79 | #endif | |
80 | ||
5c5ce192 RM |
81 | #ifdef PCI_OS_DJGPP |
82 | #define BIG_ENDIAN 4321 | |
83 | #define LITTLE_ENDIAN 1234 | |
84 | #define BYTE_ORDER LITTLE_ENDIAN | |
85 | #endif | |
86 | ||
87 | #if !defined(BYTE_ORDER) | |
88 | #error "BYTE_ORDER not defined for your platform" | |
89 | #endif | |
90 | ||
489233b4 MM |
91 | #if BYTE_ORDER == BIG_ENDIAN |
92 | #define cpu_to_le16 swab16 | |
93 | #define cpu_to_le32 swab32 | |
94 | #define le16_to_cpu swab16 | |
95 | #define le32_to_cpu swab32 | |
96 | ||
97 | static inline word swab16(word w) | |
98 | { | |
99 | return (w << 8) | ((w >> 8) & 0xff); | |
100 | } | |
101 | ||
102 | static inline u32 swab32(u32 w) | |
103 | { | |
104 | return ((w & 0xff000000) >> 24) | | |
105 | ((w & 0x00ff0000) >> 8) | | |
106 | ((w & 0x0000ff00) << 8) | | |
107 | ((w & 0x000000ff) << 24); | |
108 | } | |
109 | #else | |
110 | #define cpu_to_le16(x) (x) | |
111 | #define cpu_to_le32(x) (x) | |
112 | #define le16_to_cpu(x) (x) | |
113 | #define le32_to_cpu(x) (x) | |
114 | #endif | |
115 | ||
116 | #endif |