Resync with changes in grub-experimental
[grub-extras.git] / include_wrap / gpxe / wrap.h
blobe7768993c9b664ef17e369b4cac254cbfc85257d
1 /*
2 * Copyright © 2009 Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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
15 * distribution.
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.
29 */
31 FILE_LICENCE ( BSD2 );
33 #ifndef _GPXE_WRAP_H
34 #define _GPXE_WRAP_H
36 #include <config.h>
38 #include <grub/misc.h>
39 #include <errno.h>
40 #include <grub/mm.h>
41 #include <gpxe/list.h>
42 #include <gpxe/timer.h>
44 void *
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
63 #define htons(x) (x)
64 #define htonl(x) (x)
65 #else
66 #define htons(x) (bswap_16(x))
67 #define htonl(x) ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
68 #endif
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;
88 #define __malloc
89 #define __shared
90 #define __unused __attribute__ ((unused))
92 #define off_t grub_off_t
94 #define strcpy grub_strcpy
96 #if 0
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);
104 #endif
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
116 static inline void *
117 malloc (grub_size_t size)
119 return grub_malloc (size);
122 static inline void *
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);
134 static inline int
135 strcmp (const char *s1, const char *s2)
137 return grub_strcmp (s1, s2);
140 static inline int
141 toupper (int c)
143 return grub_toupper (c);
146 static inline int
147 tolower (int c)
149 return grub_tolower (c);
152 unsigned long strtoul ( const char *p, char **endp, int base );
154 static inline int
155 isspace (int c)
157 return grub_isspace (c);
160 static inline int
161 isdigit (int c)
163 return grub_isdigit (c);
166 static inline int
167 isalpha (int c)
169 return grub_isalpha (c);
172 static inline int
173 islower (int c)
175 return (c >= 'a' && c <= 'z');
178 static inline int
179 isupper (int c)
181 return (c >= 'A' && c <= 'Z');
184 typedef grub_ssize_t ssize_t;
186 static inline void
187 free (void *ptr)
189 grub_free (ptr);
192 #define assert(x) assert_real(__FILE__, __LINE__, x)
194 static inline void
195 assert_real (const char *file, int line, int cond)
197 if (!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
228 static inline void
229 memswap (void *b1, void *b2, grub_size_t size)
231 register grub_uint8_t t;
232 while (size--)
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;
242 static inline int
243 flsl (long n)
245 int i;
246 for (i = sizeof (n) - 1; i >= 0; i--)
247 if (n & (1 << i))
248 return i + 1;
249 return 0;
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
261 #endif