2 * Copyright © 2009 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 FILE_LICENCE ( BSD2
);
38 #include <grub/misc.h>
41 #include <gpxe/list.h>
42 #include <gpxe/timer.h>
45 memchr (void *s
, grub_uint8_t c
, grub_size_t size
);
47 #define be64_to_cpu grub_be_to_cpu64
48 #define cpu_to_be64 grub_cpu_to_be64
49 #define cpu_to_be32 grub_cpu_to_be32
50 #define cpu_to_be16 grub_cpu_to_be16
51 #define le16_to_cpu grub_le_to_cpu16
52 #define be16_to_cpu grub_be_to_cpu16
53 #define be32_to_cpu grub_be_to_cpu32
54 #define cpu_to_le16 grub_cpu_to_le16
55 #define cpu_to_le32 grub_cpu_to_le32
56 #define le32_to_cpu grub_le_to_cpu32
58 /* In gPXE codebase following has to be a macro.
59 So grub_cpu_to_be isn't usable. */
60 #define bswap_16(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
61 #define swap16 bswap_16
62 #ifdef GRUB_CPU_WORDS_BIGENDIAN
66 #define htons(x) (bswap_16(x))
67 #define htonl(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
70 #define ntohl(x) htonl(x)
71 #define ntohs(x) htons(x)
73 typedef grub_uint64_t u64
;
74 typedef grub_uint64_t
uint64_t;
75 typedef grub_uint32_t u32
;
76 typedef grub_int32_t s32
;
77 typedef grub_uint32_t
uint32_t;
78 typedef grub_int32_t
int32_t;
79 typedef grub_uint16_t u16
;
80 typedef grub_int16_t s16
;
81 typedef grub_uint16_t
uint16_t;
82 typedef grub_int16_t
int16_t;
83 typedef grub_uint8_t u8
;
84 typedef grub_uint8_t
uint8_t;
85 typedef grub_int8_t
int8_t;
86 typedef grub_size_t
size_t;
90 #define __unused __attribute__ ((unused))
92 #define off_t grub_off_t
94 #define strcpy grub_strcpy
97 typedef void *userptr_t
;
99 static inline void memcpy_user ( userptr_t dest
, off_t dest_off
,
100 userptr_t src
, off_t src_off
, size_t len
)
102 grub_memcpy ((void *) (dest
+ dest_off
), (void *) (src
+ src_off
), len
);
106 #define memcpy grub_memcpy
108 #define zalloc grub_zalloc
109 #define strdup grub_strdup
110 #define strncmp grub_strncmp
111 #define strchr grub_strchr
112 #define strcasecmp grub_strcasecmp
113 #define printf grub_printf
114 #define intptr_t grub_addr_t
117 malloc (grub_size_t size
)
119 return grub_malloc (size
);
123 realloc (void *ptr
, grub_size_t size
)
125 return grub_realloc (ptr
, size
);
128 static inline grub_size_t
129 strlen (const char *s
)
131 return grub_strlen (s
);
135 strcmp (const char *s1
, const char *s2
)
137 return grub_strcmp (s1
, s2
);
143 return grub_toupper (c
);
149 return grub_tolower (c
);
152 unsigned long strtoul ( const char *p
, char **endp
, int base
);
157 return grub_isspace (c
);
163 return grub_isdigit (c
);
169 return grub_isalpha (c
);
175 return (c
>= 'a' && c
<= 'z');
181 return (c
>= 'A' && c
<= 'Z');
184 typedef grub_ssize_t ssize_t
;
192 #define assert(x) assert_real(__FILE__, __LINE__, x)
195 assert_real (const char *file
, int line
, int cond
)
198 grub_fatal ("Assertion failed at %s:%d\n", file
, line
);
201 #define __assert_fail grub_abort
203 #define __always_inline
205 #define VERSION_MAJOR 1
206 #define VERSION_MINOR 97
207 #define VERSION_PATCH 1
209 #define strstr grub_strstr
210 #define alloc_memblock(size,align) grub_memalign(align,size)
212 #define DBG(fmt,args...) grub_dprintf("net", fmt, ## args)
213 #define DBG2(fmt,args...) grub_dprintf("net", fmt, ## args)
214 #define DBG_HD(data,len)
215 #define DBGP(fmt,args...) grub_dprintf("net", fmt, ## args)
216 #define DBGP_HD(data,len)
217 #define DBGC(ptr, fmt,args...) grub_dprintf("net", fmt, ## args)
218 #define DBGCP(ptr, fmt,args...) grub_dprintf("net", fmt, ## args)
219 #define DBGC2(ptr, fmt,args...) grub_dprintf("net", fmt, ## args)
220 #define DBGC_HD(ptr,data,len)
221 #define DBGCP_HD(ptr,data,len)
222 #define DBGC_HDA(ptr,s,data,len)
223 #define DBGC2_HDA(ptr,s,data,len)
224 #define DBGCP_HDA(ptr,s,data,len)
226 #define strrchr grub_strrchr
229 memswap (void *b1
, void *b2
, grub_size_t size
)
231 register grub_uint8_t t
;
234 t
= *(grub_uint8_t
*) b1
;
235 *(grub_uint8_t
*) b1
= *(grub_uint8_t
*) b2
;
236 *(grub_uint8_t
*) b2
= t
;
237 b1
= (grub_uint8_t
*) b1
+ 1;
238 b2
= (grub_uint8_t
*) b2
+ 1;
246 for (i
= sizeof (n
) - 1; i
>= 0; i
--)
252 #define INT_MAX 2147483647L
254 #define putchar(x) grub_putchar(x)
256 #define asprintf grub_asprintf
257 #define snprintf grub_snprintf
258 #define ssnprintf grub_snprintf
259 #define vsnprintf grub_vsnprintf