diff options
author | Patrick Georgi <patrick.georgi@coresystems.de> | 2010-06-24 11:16:10 +0000 |
---|---|---|
committer | Patrick Georgi <patrick.georgi@coresystems.de> | 2010-06-24 11:16:10 +0000 |
commit | 980a69b8c20ad975553980ccb320bf25ff7c0b16 (patch) | |
tree | 65b64bf8ac67db37bc8a868cc246ce41925c5915 /payloads/libpayload/include | |
parent | 815c47f7b458f7342195ffe99e994e2757df96c1 (diff) | |
download | coreboot-980a69b8c20ad975553980ccb320bf25ff7c0b16.tar.xz |
Attached patch moves functions out of the huge libpayload.h into headers
according to libc/posix traditions, to simplify porting applications to
payloads.
It also adds a couple of functions:
strcasecmp, strncasecmp, strcat, strtol, strspn, strcspn, strtok_r,
strtok, perror, exit, getpagesize
Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de>
Acked-by: Stefan Reinauer <stepan@coresystems.de>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5643 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads/libpayload/include')
-rw-r--r-- | payloads/libpayload/include/ctype.h | 55 | ||||
-rw-r--r-- | payloads/libpayload/include/errno.h | 35 | ||||
-rw-r--r-- | payloads/libpayload/include/libpayload.h | 167 | ||||
-rw-r--r-- | payloads/libpayload/include/pci.h | 3 | ||||
-rw-r--r-- | payloads/libpayload/include/stdarg.h | 44 | ||||
-rw-r--r-- | payloads/libpayload/include/stdint.h | 30 | ||||
-rw-r--r-- | payloads/libpayload/include/stdio.h | 46 | ||||
-rw-r--r-- | payloads/libpayload/include/stdlib.h | 144 | ||||
-rw-r--r-- | payloads/libpayload/include/string.h | 71 | ||||
-rw-r--r-- | payloads/libpayload/include/sys/types.h | 30 | ||||
-rw-r--r-- | payloads/libpayload/include/unistd.h | 30 |
11 files changed, 493 insertions, 162 deletions
diff --git a/payloads/libpayload/include/ctype.h b/payloads/libpayload/include/ctype.h new file mode 100644 index 0000000000..7dfec41048 --- /dev/null +++ b/payloads/libpayload/include/ctype.h @@ -0,0 +1,55 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _CTYPE_H +#define _CTYPE_H + +/** + * @defgroup ctype Character type functions + * @{ + */ +int isalnum(int c); +int isalpha(int c); +int isascii(int c); +int isblank(int c); +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); +int tolower(int c); +int toupper(int c); +/** @} */ + + +#endif diff --git a/payloads/libpayload/include/errno.h b/payloads/libpayload/include/errno.h new file mode 100644 index 0000000000..f8eae83dc4 --- /dev/null +++ b/payloads/libpayload/include/errno.h @@ -0,0 +1,35 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2010 coresystems GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _ERRNO_H +#define _ERRNO_H + +extern int errno; + +#endif diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 51e42c7ea2..2efb88e328 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -44,12 +44,16 @@ #define _LIBPAYLOAD_H #include <libpayload-config.h> +#include <ctype.h> #include <stddef.h> +#include <stdio.h> +#include <stdarg.h> +#include <stdlib.h> +#include <string.h> #include <arch/types.h> #include <arch/io.h> #include <arch/virtual.h> #include <sysinfo.h> -#include <stdarg.h> #include <pci.h> #ifdef CONFIG_LAR #include <lar.h> @@ -225,114 +229,12 @@ void console_add_input_driver(struct console_input_driver *in); /** @} */ /** - * @defgroup ctype Character type functions - * @{ - */ -int isalnum(int c); -int isalpha(int c); -int isascii(int c); -int isblank(int c); -int iscntrl(int c); -int isdigit(int c); -int isgraph(int c); -int islower(int c); -int isprint(int c); -int ispunct(int c); -int isspace(int c); -int isupper(int c); -int isxdigit(int c); -int tolower(int c); -int toupper(int c); -/** @} */ - -/** * @defgroup ipchecksum IP checksum functions * @{ */ unsigned short ipchksum(const void *ptr, unsigned long nbytes); /** @} */ -/** - * @defgroup malloc Memory allocation functions - * @{ - */ -#if defined(CONFIG_DEBUG_MALLOC) && !defined(IN_MALLOC_C) -#define free(p) \ - ({ \ - extern void print_malloc_map(void); \ - extern void free(void *); \ - printf("free(%p) called from %s:%s:%d...\n", p, __FILE__, __func__, \ - __LINE__);\ - printf("PRE free()\n"); \ - print_malloc_map(); \ - free(p); \ - printf("POST free()\n"); \ - print_malloc_map(); \ - }) -#define malloc(s) \ - ({ \ - extern void print_malloc_map(void); \ - extern void *malloc(size_t); \ - void *ptr; \ - printf("malloc(%u) called from %s:%s:%d...\n", s, __FILE__, __func__, \ - __LINE__);\ - printf("PRE malloc\n"); \ - print_malloc_map(); \ - ptr = malloc(s); \ - printf("POST malloc (ptr = %p)\n", ptr); \ - print_malloc_map(); \ - ptr; \ - }) -#define calloc(n,s) \ - ({ \ - extern void print_malloc_map(void); \ - extern void *calloc(size_t,size_t); \ - void *ptr; \ - printf("calloc(%u, %u) called from %s:%s:%d...\n", n, s, __FILE__, \ - __func__, __LINE__);\ - printf("PRE calloc\n"); \ - print_malloc_map(); \ - ptr = calloc(n,s); \ - printf("POST calloc (ptr = %p)\n", ptr); \ - print_malloc_map(); \ - ptr; \ - }) -#define realloc(p,s) \ - ({ \ - extern void print_malloc_map(void); \ - extern void *realloc(void*,size_t); \ - void *ptr; \ - printf("realloc(%p, %u) called from %s:%s:%d...\n", p, s, __FILE__, \ - __func__, __LINE__);\ - printf("PRE realloc\n"); \ - print_malloc_map(); \ - ptr = realloc(p,s); \ - printf("POST realloc (ptr = %p)\n", ptr); \ - print_malloc_map(); \ - ptr; \ - }) -#define memalign(a,s) \ - ({ \ - extern void print_malloc_map(void); \ - extern void *memalign(size_t, size_t); \ - void *ptr; \ - printf("memalign(%u, %u) called from %s:%s:%d...\n", a, s, __FILE__, \ - __func__, __LINE__);\ - printf("PRE memalign\n"); \ - print_malloc_map(); \ - ptr = memalign(a,s); \ - printf("POST realloc (ptr = %p)\n", ptr); \ - print_malloc_map(); \ - ptr; \ - }) -#else -void free(void *ptr); -void *malloc(size_t size); -void *calloc(size_t nmemb, size_t size); -void *realloc(void *ptr, size_t size); -void *memalign(size_t align, size_t size); -#endif -/** @} */ /** * @defgroup exec Execution functions @@ -355,36 +257,6 @@ u8 hex2bin(u8 h); void fatal(const char *msg) __attribute__ ((noreturn)); /** @} */ -/** - * @defgroup memory Memory manipulation functions - * @{ - */ -void *memset(void *s, int c, size_t n); -void *memcpy(void *dst, const void *src, size_t n); -void *memmove(void *dst, const void *src, size_t n); -int memcmp(const void *s1, const void *s2, size_t len); -/** @} */ - -/** - * @defgroup printf Print functions - * @{ - */ -int snprintf(char *str, size_t size, const char *fmt, ...); -int sprintf(char *str, const char *fmt, ...); -int vsnprintf(char *str, size_t size, const char *fmt, va_list ap); -int vsprintf(char *str, const char *fmt, va_list ap); -int printf(const char *fmt, ...); -int vprintf(const char *fmt, va_list ap); -/** @} */ - -/** - * @defgroup rand Random number generator functions - * @{ - */ -int rand_r(unsigned int *seed); -int rand(void); -void srand(unsigned int seed); -/** @} */ /** * @defgroup hash Hashing functions @@ -405,27 +277,6 @@ u8 *sha1(const u8 *data, size_t len, u8 *buf); /** @} */ /** - * @defgroup string String functions - * @{ - */ -size_t strnlen(const char *str, size_t maxlen); -size_t strlen(const char *str); -int strcmp(const char *s1, const char *s2); -int strncmp(const char *s1, const char *s2, size_t maxlen); -char *strncpy(char *d, const char *s, size_t n); -char *strcpy(char *d, const char *s); -char *strncat(char *d, const char *s, size_t n); -size_t strlcat(char *d, const char *s, size_t n); -char *strchr(const char *s, int c); -char *strrchr(const char *s, int c); -char *strdup(const char *s); -char *strstr(const char *h, const char *n); -char *strsep(char **stringp, const char *delim); -unsigned int strtoul(const char *s, char **nptr, int base); - -/** @} */ - -/** * @defgroup time Time functions * @{ */ @@ -527,14 +378,6 @@ void udelay(unsigned int n); void mdelay(unsigned int n); void delay(unsigned int n); -#define abort() halt() /**< Alias for the halt() function */ - -/** - * Stop execution and halt the processor (this function does not return). - */ -void halt(void) __attribute__ ((noreturn)); -/** @} */ - /** * @defgroup readline Readline functions * This interface provides a simple implementation of the standard readline() diff --git a/payloads/libpayload/include/pci.h b/payloads/libpayload/include/pci.h index 93d1267ef5..2490f6cb4c 100644 --- a/payloads/libpayload/include/pci.h +++ b/payloads/libpayload/include/pci.h @@ -36,8 +36,11 @@ typedef u32 pcidev_t; #define REG_VENDOR_ID 0x00 #define REG_COMMAND 0x04 +#define REG_CLASS_DEV 0x0A #define REG_HEADER_TYPE 0x0E #define REG_PRIMARY_BUS 0x18 +#define REG_SUBSYS_VENDOR_ID 0x2C +#define REG_SUBSYS_ID 0x2E #define REG_COMMAND_BM (1 << 2) diff --git a/payloads/libpayload/include/stdarg.h b/payloads/libpayload/include/stdarg.h new file mode 100644 index 0000000000..7a6244e9ec --- /dev/null +++ b/payloads/libpayload/include/stdarg.h @@ -0,0 +1,44 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _LIBPAYLOAD_STDARG_H +#define _LIBPAYLOAD_STDARG_H + +#include_next <stdarg.h> + +/** + * @defgroup vprintf Varargs print functions + * @{ + */ +int vsnprintf(char *str, size_t size, const char *fmt, va_list ap); +int vsprintf(char *str, const char *fmt, va_list ap); +int vprintf(const char *fmt, va_list ap); +/** @} */ + +#endif diff --git a/payloads/libpayload/include/stdint.h b/payloads/libpayload/include/stdint.h new file mode 100644 index 0000000000..ae143d702c --- /dev/null +++ b/payloads/libpayload/include/stdint.h @@ -0,0 +1,30 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2010 coresystems GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <arch/types.h> diff --git a/payloads/libpayload/include/stdio.h b/payloads/libpayload/include/stdio.h new file mode 100644 index 0000000000..2aea4459fa --- /dev/null +++ b/payloads/libpayload/include/stdio.h @@ -0,0 +1,46 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _STDIO_H +#define _STDIO_H + +#include <stddef.h> + +/** + * @defgroup printf Print functions + * @{ + */ +int snprintf(char *str, size_t size, const char *fmt, ...); +int sprintf(char *str, const char *fmt, ...); +int printf(const char *fmt, ...); +/** @} */ + +void perror(const char *s); + +#endif diff --git a/payloads/libpayload/include/stdlib.h b/payloads/libpayload/include/stdlib.h new file mode 100644 index 0000000000..a106607b4b --- /dev/null +++ b/payloads/libpayload/include/stdlib.h @@ -0,0 +1,144 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _STDLIB_H +#define _STDLIB_H + +#include <stddef.h> + +/** + * @defgroup malloc Memory allocation functions + * @{ + */ +#if defined(CONFIG_DEBUG_MALLOC) && !defined(IN_MALLOC_C) +#define free(p) \ + ({ \ + extern void print_malloc_map(void); \ + extern void free(void *); \ + printf("free(%p) called from %s:%s:%d...\n", p, __FILE__, __func__, \ + __LINE__);\ + printf("PRE free()\n"); \ + print_malloc_map(); \ + free(p); \ + printf("POST free()\n"); \ + print_malloc_map(); \ + }) +#define malloc(s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *malloc(size_t); \ + void *ptr; \ + printf("malloc(%u) called from %s:%s:%d...\n", s, __FILE__, __func__, \ + __LINE__);\ + printf("PRE malloc\n"); \ + print_malloc_map(); \ + ptr = malloc(s); \ + printf("POST malloc (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#define calloc(n,s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *calloc(size_t,size_t); \ + void *ptr; \ + printf("calloc(%u, %u) called from %s:%s:%d...\n", n, s, __FILE__, \ + __func__, __LINE__);\ + printf("PRE calloc\n"); \ + print_malloc_map(); \ + ptr = calloc(n,s); \ + printf("POST calloc (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#define realloc(p,s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *realloc(void*,size_t); \ + void *ptr; \ + printf("realloc(%p, %u) called from %s:%s:%d...\n", p, s, __FILE__, \ + __func__, __LINE__);\ + printf("PRE realloc\n"); \ + print_malloc_map(); \ + ptr = realloc(p,s); \ + printf("POST realloc (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#define memalign(a,s) \ + ({ \ + extern void print_malloc_map(void); \ + extern void *memalign(size_t, size_t); \ + void *ptr; \ + printf("memalign(%u, %u) called from %s:%s:%d...\n", a, s, __FILE__, \ + __func__, __LINE__);\ + printf("PRE memalign\n"); \ + print_malloc_map(); \ + ptr = memalign(a,s); \ + printf("POST realloc (ptr = %p)\n", ptr); \ + print_malloc_map(); \ + ptr; \ + }) +#else +void free(void *ptr); +void *malloc(size_t size); +void *calloc(size_t nmemb, size_t size); +void *realloc(void *ptr, size_t size); +void *memalign(size_t align, size_t size); +#endif +/** @} */ + +/** + * @defgroup stdlib String conversion functions + * @{ + */ +long int strtol(const char *s, char **nptr, int base); +unsigned long int strtoul(const char *s, char **nptr, int base); + +/** @} */ + +/** + * @defgroup rand Random number generator functions + * @{ + */ +int rand_r(unsigned int *seed); +int rand(void); +void srand(unsigned int seed); +/** @} */ + +/** + * Stop execution and halt the processor (this function does not return). + */ +void halt(void) __attribute__ ((noreturn)); +void exit(int status) __attribute__ ((noreturn)); +#define abort() halt() /**< Alias for the halt() function */ + +/** @} */ + +#endif diff --git a/payloads/libpayload/include/string.h b/payloads/libpayload/include/string.h new file mode 100644 index 0000000000..88054e017b --- /dev/null +++ b/payloads/libpayload/include/string.h @@ -0,0 +1,71 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2008 Advanced Micro Devices, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _STRING_H +#define _STRING_H + +#include <stddef.h> + +/** + * @defgroup memory Memory manipulation functions + * @{ + */ +void *memset(void *s, int c, size_t n); +void *memcpy(void *dst, const void *src, size_t n); +void *memmove(void *dst, const void *src, size_t n); +int memcmp(const void *s1, const void *s2, size_t len); +/** @} */ + +/** + * @defgroup string String functions + * @{ + */ +size_t strnlen(const char *str, size_t maxlen); +size_t strlen(const char *str); +int strcmp(const char *s1, const char *s2); +int strncmp(const char *s1, const char *s2, size_t maxlen); +int strcasecmp(const char *s1, const char *s2); +int strncasecmp(const char *s1, const char *s2, size_t maxlen); +char *strncpy(char *d, const char *s, size_t n); +char *strcpy(char *d, const char *s); +char *strncat(char *d, const char *s, size_t n); +size_t strlcat(char *d, const char *s, size_t n); +char *strcat(char *d, const char *s); +char *strchr(const char *s, int c); +char *strrchr(const char *s, int c); +char *strdup(const char *s); +char *strstr(const char *h, const char *n); +char *strsep(char **stringp, const char *delim); +size_t strspn(const char *s, const char *a); +size_t strcspn(const char *s, const char *a); +char* strtok(char *str, const char *delim); +char* strtok_r(char *str, const char *delim, char **ptr); +/** @} */ + +#endif diff --git a/payloads/libpayload/include/sys/types.h b/payloads/libpayload/include/sys/types.h new file mode 100644 index 0000000000..ae143d702c --- /dev/null +++ b/payloads/libpayload/include/sys/types.h @@ -0,0 +1,30 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2010 coresystems GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <arch/types.h> diff --git a/payloads/libpayload/include/unistd.h b/payloads/libpayload/include/unistd.h new file mode 100644 index 0000000000..878638d419 --- /dev/null +++ b/payloads/libpayload/include/unistd.h @@ -0,0 +1,30 @@ +/* + * This file is part of the libpayload project. + * + * Copyright (C) 2010 coresystems GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +int getpagesize(void); |