Hi,

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

baiyin cai, I added you to the recipients, as marc indicated that this
might overlap with your summer of code effort.

Comments are appreciated.

Signed-off-by: Patrick Georgi <[email protected]>
* create libc-style header files and move function prototypes there
* include those headers from libpayload.h for compatibility
* change strcmp implementation to look more like strncmp
* implement more libc functions:
        strcasecmp, strncasecmp
        strcat
        strtol
        strspn, strcspn
        strtok_r, strtok
        perror
        exit
        getpagesize

Signed-off-by: Patrick Georgi <[email protected]>
Index: libc/printf.c
===================================================================
--- libc/printf.c       (Revision 5631)
+++ libc/printf.c       (Arbeitskopie)
@@ -34,6 +34,7 @@
  */
 
 #include <libpayload.h>
+#include <ctype.h>
 
 /** Structure for specifying output methods for different printf clones. */
 struct printf_spec {
Index: libc/string.c
===================================================================
--- libc/string.c       (Revision 5631)
+++ libc/string.c       (Arbeitskopie)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2007 Uwe Hermann <[email protected]>
  * Copyright (C) 2008 Advanced Micro Devices, Inc.
+ * Copyright (C) 2010 coresystems GmbH
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,6 +30,8 @@
  */
 
 #include <libpayload.h>
+#include <string.h>
+#include <ctype.h>
 
 /**
  * Calculate the length of a fixed-size string.
@@ -83,32 +86,60 @@
  *        zero, if s1 equals s2. Returns a value greater than zero, if
  *        s1 is longer than s2.
  */
-int strcmp(const char *s1, const char *s2)
+int strcasecmp(const char *s1, const char *s2)
 {
-       char c1, c2;
+       int i;
 
-       /* Set c1 == c2, so that we can enter the while loop. */
-       c1 = 0;
-       c2 = 0;
+       for (i = 0; 1; i++) {
+               if (tolower(s1[i]) != tolower(s2[i]))
+                       return s1[i] - s2[i];
+       }
 
-       /* Compare characters until they differ, or one of the strings ends. */
-       while (c1 == c2) {
-               /* Read the next character from each string. */
-               c1 = *s1++;
-               c2 = *s2++;
+       return 0;
+}
 
-               /* Return something negative (if s1 is shorter than s2), or
-                  zero (if s1 equals s2). */
-               if (c1 == '\0')
-                       return c1 - c2;
+/**
+ * Compare two strings with fixed length.
+ *
+ * @param s1 The first string.
+ * @param s2 The second string.
+ * @param maxlen Return at most maxlen characters as length of the string.
+ * @return A non-zero value if s1 and s2 differ, or zero if s1 equals s2.
+ */
+int strncasecmp(const char *s1, const char *s2, size_t maxlen)
+{
+       int i;
+
+       for (i = 0; i < maxlen; i++) {
+               if (tolower(s1[i]) != tolower(s2[i]))
+                       return s1[i] - s2[i];
        }
 
-       /* Return something positive (if s1 is longer than s2), or zero (if s1
-          and s2 are equal). */
-       return c1 - c2;
+       return 0;
 }
 
 /**
+ * Compare two strings.
+ *
+ * @param s1 The first string.
+ * @param s2 The second string.
+ * @return Returns a value less than zero, if s1 is shorter than s2. Returns
+ *        zero, if s1 equals s2. Returns a value greater than zero, if
+ *        s1 is longer than s2.
+ */
+int strcmp(const char *s1, const char *s2)
+{
+       int i;
+
+       for (i = 0; 1; i++) {
+               if (s1[i] != s2[i])
+                       return s1[i] - s2[i];
+       }
+
+       return 0;
+}
+
+/**
  * Compare two strings with fixed length.
  *
  * @param s1 The first string.
@@ -161,6 +192,26 @@
 }
 
 /**
+ * Concatenates two strings
+ *
+ * @param d The destination string.
+ * @param s The source string.
+ * @return A pointer to the destination string.
+ */
+char *strcat(char *d, const char *s)
+{
+       char *p = d + strlen(d);
+       int sl = strlen(s);
+       int i;
+
+       for (i = 0; i < sl; i++)
+               p[i] = s[i];
+
+       p[i] = '\0';
+       return d;
+}
+
+/**
  * Concatenates two strings with a maximum length.
  *
  * @param d The destination string.
@@ -353,6 +404,69 @@
 }
 
 /**
+ * Convert the initial portion of a string into a signed int
+ * @param ptr A pointer to the string to convert
+ * @param endptr A pointer to the unconverted part of the string
+ * @param base The base of the number to convert, or 0 for auto
+ * @return A signed integer representation of the string
+ */
+
+int strtol(const char *ptr, char **endptr, int base)
+{
+        int ret = 0;
+       int negative = 1;
+
+       if (endptr != NULL)
+               *endptr = (char *) ptr;
+
+        /* Purge whitespace */
+
+        for( ; *ptr && isspace(*ptr); ptr++);
+
+       if (ptr[0] == '-') {
+               negative = -1;
+               ptr++;
+       }
+
+        if (!*ptr)
+                return 0;
+
+        /* Determine the base */
+
+        if (base == 0) {
+               if (ptr[0] == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
+                       base = 16;
+               else if (ptr[0] == '0') {
+                       base = 8;
+                       ptr++;
+               }
+               else
+                       base = 10;
+        }
+
+       /* Base 16 allows the 0x on front - so skip over it */
+
+       if (base == 16) {
+               if (ptr[0] == '0' && (ptr[1] == 'x' || ptr[1] == 'X'))
+                       ptr += 2;
+       }
+
+       /* If the first character isn't valid, then don't
+         * bother */
+
+        if (!*ptr || !_valid(*ptr, base))
+                return 0;
+
+        for( ; *ptr && _valid(*ptr, base); ptr++)
+                ret = (ret * base) + _offset(*ptr, base);
+
+       if (endptr != NULL)
+               *endptr = (char *) ptr;
+
+        return ret * negative;
+}
+
+/**
  * Convert the initial portion of a string into an unsigned int
  * @param ptr A pointer to the string to convert
  * @param endptr A pointer to the unconverted part of the string
@@ -409,4 +523,103 @@
         return ret;
 }
 
+/**
+ * Determine the number of leading characters in s that match characters in a
+ * @param s A pointer to the string to analyse
+ * @param a A pointer to an array of characters that match the prefix
+ * @return The number of matching characters
+ */
 
+size_t strspn(const char *s, const char *a)
+{
+       int i, j;
+       int al = strlen(a);
+       for (i = 0; s[i] != 0; i++) {
+               int found = 0;
+               for (j = 0; j < al; j++) {
+                       if (s[i] == a[j]) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if (!found)
+                       break;
+       }
+       return i;
+}
+
+/**
+ * Determine the number of leading characters in s that do not match 
characters in a
+ * @param s A pointer to the string to analyse
+ * @param a A pointer to an array of characters that do not match the prefix
+ * @return The number of not matching characters
+ */
+
+size_t strcspn(const char *s, const char *a)
+{
+       int i, j;
+       int al = strlen(a);
+       for (i = 0; s[i] != 0; i++) {
+               int found = 0;
+               for (j = 0; j < al; j++) {
+                       if (s[i] == a[j]) {
+                               found = 1;
+                               break;
+                       }
+               }
+               if (found)
+                       break;
+       }
+       return i;
+}
+
+/**
+ * Extract first token in string str that is delimited by a character in 
tokens.
+ * Destroys str and eliminates the token delimiter.
+ * @param str A pointer to the string to tokenize.
+ * @param delim A pointer to an array of characters that delimit the token
+ * @param ptr A pointer to a string pointer to keep state of the tokenizer
+ * @return Pointer to token
+ */
+
+char* strtok_r(char *str, const char *delim, char **ptr)
+{
+       /* start new tokenizing job or continue existing one? */
+       if (str == NULL)
+               str = *ptr;
+
+       /* skip over prefix delimiters */
+       char *start = str + strspn(str, delim);
+
+       /* find first delimiter character */
+       char *end = start + strcspn(start, delim);
+       end[0] = '\0';
+
+       *ptr = end+1;
+       return start;
+}
+
+static char **strtok_global;
+
+/**
+ * Extract first token in string str that is delimited by a character in 
tokens.
+ * Destroys str, eliminates the token delimiter and uses global state.
+ * @param str A pointer to the string to tokenize.
+ * @param delim A pointer to an array of characters that delimit the token
+ * @return Pointer to token
+ */
+
+char* strtok(char *str, const char *delim)
+{
+       return strtok_r(str, delim, strtok_global);
+}
+
+/**
+ * Print error message and error number
+ * @param s Error message to print
+ */
+extern int errno;
+void perror(const char *s)
+{
+       printf("%s: %d\n", s?s:"(none)", errno);
+}
Index: libc/lib.c
===================================================================
--- libc/lib.c  (Revision 5631)
+++ libc/lib.c  (Arbeitskopie)
@@ -113,3 +113,13 @@
        halt();
 }
 
+void exit(int status)
+{
+       printf("exited with status %d\n", status);
+       halt();
+}
+
+int getpagesize(void)
+{
+       return 4096;
+}
Index: include/stdint.h
===================================================================
--- include/stdint.h    (Revision 0)
+++ include/stdint.h    (Revision 0)
@@ -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>
Index: include/unistd.h
===================================================================
--- include/unistd.h    (Revision 0)
+++ include/unistd.h    (Revision 0)
@@ -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);
Index: include/string.h
===================================================================
--- include/string.h    (Revision 0)
+++ include/string.h    (Revision 0)
@@ -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
Index: include/pci.h
===================================================================
--- include/pci.h       (Revision 5631)
+++ include/pci.h       (Arbeitskopie)
@@ -36,8 +36,11 @@
 
 #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)
 
Index: include/libpayload.h
===================================================================
--- include/libpayload.h        (Revision 5631)
+++ include/libpayload.h        (Arbeitskopie)
@@ -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 @@
 /** @} */
 
 /**
- * @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,38 +257,8 @@
 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 @@
 /** @} */
 
 /**
- * @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,15 +378,7 @@
 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()
  * and getline() functions. They read a line of input from the console.
Index: include/stdlib.h
===================================================================
--- include/stdlib.h    (Revision 0)
+++ include/stdlib.h    (Revision 0)
@@ -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
+ * @{
+ */
+int strtol(const char *s, char **nptr, int base);
+unsigned 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
Index: include/stdio.h
===================================================================
--- include/stdio.h     (Revision 0)
+++ include/stdio.h     (Revision 0)
@@ -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
Index: include/stdarg.h
===================================================================
--- include/stdarg.h    (Revision 0)
+++ include/stdarg.h    (Revision 0)
@@ -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
Index: include/ctype.h
===================================================================
--- include/ctype.h     (Revision 0)
+++ include/ctype.h     (Revision 0)
@@ -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
Index: include/sys/types.h
===================================================================
--- include/sys/types.h (Revision 0)
+++ include/sys/types.h (Revision 0)
@@ -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>
-- 
coreboot mailing list: [email protected]
http://www.coreboot.org/mailman/listinfo/coreboot

Reply via email to