aboutsummaryrefslogtreecommitdiff
path: root/include/apos
diff options
context:
space:
mode:
Diffstat (limited to 'include/apos')
-rw-r--r--include/apos/attrs.h (renamed from include/apos/compiler_attributes.h)1
-rw-r--r--include/apos/init.h2
-rw-r--r--include/apos/main.h2
-rw-r--r--include/apos/mem.h4
-rw-r--r--include/apos/string.h78
-rw-r--r--include/apos/types.h208
6 files changed, 292 insertions, 3 deletions
diff --git a/include/apos/compiler_attributes.h b/include/apos/attrs.h
index 45b7ac3..00dcf82 100644
--- a/include/apos/compiler_attributes.h
+++ b/include/apos/attrs.h
@@ -2,5 +2,6 @@
#define __section(section) __attribute__((__section__(section)))
#define __noinline __attribute__((noinline))
+#define __weak __attribute((weak))
#endif /* APOS_COMPILER_ATTRIBUTES_H */
diff --git a/include/apos/init.h b/include/apos/init.h
index 82f1774..1bf6a9e 100644
--- a/include/apos/init.h
+++ b/include/apos/init.h
@@ -1,7 +1,7 @@
#ifndef APOS_INIT_H
#define APOS_INIT_H
-#include <apos/compiler_attributes.h>
+#include <apos/attrs.h>
#define __init
#define __initdata
diff --git a/include/apos/main.h b/include/apos/main.h
index 1cea533..5292df7 100644
--- a/include/apos/main.h
+++ b/include/apos/main.h
@@ -1,7 +1,7 @@
#ifndef APOS_MAIN_H
#define APOS_MAIN_H
-#include <apos/compiler_attributes.h>
+#include <apos/attrs.h>
#define __main __section(".text.start") __noinline
diff --git a/include/apos/mem.h b/include/apos/mem.h
new file mode 100644
index 0000000..6b209c5
--- /dev/null
+++ b/include/apos/mem.h
@@ -0,0 +1,4 @@
+#ifndef APOS_MEM_H
+#define APOS_MEM_H
+
+#endif /* APOS_MEM_H */
diff --git a/include/apos/string.h b/include/apos/string.h
new file mode 100644
index 0000000..787f630
--- /dev/null
+++ b/include/apos/string.h
@@ -0,0 +1,78 @@
+#ifndef APOS_STRING_H
+#define APOS_STRING_H
+
+#include <apos/types.h>
+
+/* follow C library functions, drop location and error functions */
+
+char *strcpy(char *dst, const char *src);
+char *strncpy(char *dst, const char *src, size_t num);
+
+char *strcat(char *dst, const char *src);
+char *strncat(char *dst, const char *src, size_t num);
+
+int strcmp(const char *str1, const char *str2);
+int strncmp(const char *str1, const char *str2, size_t num);
+
+char *strchr(const char *str, int chr);
+char *strtok(char *str, const char *delims);
+char *strstr(const char *str1, const char *str2);
+
+char *strrchr(const char *str, int chr);
+char *strpbrk(const char *str1, const char *str2);
+
+size_t strspn(const char *str1, const char *str2);
+size_t strcspn(const char *str1, const char *str2);
+
+size_t strlen(const char *str);
+/* only addition on top of libc */
+size_t strnlen(const char *str, size_t num);
+
+void *memset(void *ptr, int value, size_t num);
+void *memchr(const void *ptr, int val, size_t num);
+void *memcpy(void *dst, const void *src, size_t num);
+void *memmove(void *dst, const void *src, size_t num);
+
+int memcmp(const void *ptr1, const void *ptr2, size_t num);
+
+/* Honorable mentions:
+ *
+ * char *strerror(int err);
+ * int strcoll(const char *str1, const char *str2);
+ * int strxfrm(char *dest, const char *src, size_t num);
+ *
+ */
+
+/* provide macros for builtin functions. The compiler is always allowed to
+ * replace a __builtin_* with a regular call to the function, which is why we
+ * still need to define the functions.
+ *
+ * Does mean we can't take the address of any of these, but I suppose that's not
+ * an issue.
+ */
+
+#define memcpy(dst, src, num) __builtin_memcpy(dst, src, num)
+#define memmove(dst, src, num) __builtin_memmove(dst, src, num)
+#define strcpy(dst, src) __builtin_strcpy(dst, src)
+#define strncpy(dst, src, num) __builtin_strncpy(dst, src, num)
+
+#define strcat(dst, src) __builtin_strcat(dst, src)
+#define strncat(dst, src, num) __builtin_strncat(dst, src, num)
+
+#define memcmp(p1, p2, num) __builtin_memcmp(p1, p2, num)
+#define strcmp(s1, s2) __builtin_strcmp(s1, s2)
+#define strncmp(s1, s2, num) __builtin_strncmp(s1, s2, num)
+
+#define memchr(ptr, val, num) __builtin_memchr(ptr, val, num)
+#define strchr(str, chr) __builtin_strchr(str, chr)
+#define strcspn(s1, s2) __builtin_strcspn(s1, s2)
+#define strpbrk(s1, s2) __builtin_strpbrk(s1, s2)
+#define strrchr(s1, s2) __builtin_strrchr(s1, s2)
+#define strspn(s1, s2) __builtin_strspn(s1, s2)
+#define strstr(s1, s2) __builtin_strstr(s1, s2)
+#define strtok(s1, s2) __builtin_strtok(s1, s2)
+
+#define memset(p, v, n) __builtin_memset(p, v, n)
+#define strlen(s) __builtin_strlen(s)
+
+#endif /* APOS_STRING_H */
diff --git a/include/apos/types.h b/include/apos/types.h
index 2e30080..04afd4c 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -1,4 +1,210 @@
-#ifdef APOS_TYPES_H
+#ifndef APOS_TYPES_H
#define APOS_TYPES_H
+typedef _Bool bool;
+#define true 1
+#define false 0
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+typedef __WCHAR_TYPE__ wchar_t;
+typedef __WINT_TYPE__ wint_t;
+typedef __INTMAX_TYPE__ intmax_t;
+typedef __UINTMAX_TYPE__ uintmax_t;
+typedef __SIG_ATOMIC_TYPE__ sig_atomic_t;
+typedef __INT8_TYPE__ int8_t;
+typedef __INT16_TYPE__ int16_t;
+typedef __INT32_TYPE__ int32_t;
+typedef __INT64_TYPE__ int64_t;
+typedef __UINT8_TYPE__ uint8_t;
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+typedef __UINT64_TYPE__ uint64_t;
+typedef __INT_LEAST8_TYPE__ int_least8_t;
+typedef __INT_LEAST16_TYPE__ int_least16_t;
+typedef __INT_LEAST32_TYPE__ int_least32_t;
+typedef __INT_LEAST64_TYPE__ int_least64_t;
+typedef __UINT_LEAST8_TYPE__ uint_least8_t;
+typedef __UINT_LEAST16_TYPE__ uint_least16_t;
+typedef __UINT_LEAST32_TYPE__ uint_least32_t;
+typedef __UINT_LEAST64_TYPE__ uint_least64_t;
+typedef __INT_FAST8_TYPE__ int_fast8_t;
+typedef __INT_FAST16_TYPE__ int_fast16_t;
+typedef __INT_FAST32_TYPE__ int_fast32_t;
+typedef __INT_FAST64_TYPE__ int_fast64_t;
+typedef __UINT_FAST8_TYPE__ uint_fast8_t;
+typedef __UINT_FAST16_TYPE__ uint_fast16_t;
+typedef __UINT_FAST32_TYPE__ uint_fast32_t;
+typedef __UINT_FAST64_TYPE__ uint_fast64_t;
+typedef __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+
+#define INT8_C __INT8_C
+#define INT16_C __INT16_C
+#define INT32_C __INT32_C
+#define INT64_C __INT64_C
+#define UINT8_C __UINT8_C
+#define UINT16_C __UINT16_C
+#define UINT32_C __UINT32_C
+#define UINT64_C __UINT64_C
+#define INTMAX_C __INTMAX_C
+#define UINTMAX_C __UINTMAX_C
+
+#define CHAR_BIT __CHAR_BIT__
+
+#define SCHAR_MAX __SCHAR_MAX__
+#define SCHAR_MIN (-__SCHAR_MAX - 1)
+#define UCHAR_MAX (2 * __SCHAR_MAX__ - 1)
+
+#ifdef __CHAR_UNSIGNED__
+#define CHAR_MIN 0
+#define CHAR_MAX UCHAR_MAX
+#else
+#define CHAR_MIN SCHAR_MIN
+#define CHAR_MAX SCHAR_MAX
+#endif
+
+/* probably not necessary? */
+#define MB_LEN_MAX 16
+
+#define SHRT_MAX __SHRT_MAX__
+#define SHRT_MIN (-__SHRT_MAX - 1)
+#define USHRT_MAX (2 * __SHRT_MAX + 1)
+
+#define INT_MAX __INT_MAX__
+#define INT_MIN (-__INT_MAX__ - 1)
+#define UINT_MAX (2 * __INT_MAX__ + 1)
+
+#define LONG_MAX __LONG__MAX__
+#define LONG_MIN (-__LONG_MAX__ - 1)
+#define ULONG_MAX (2 * __INT_MAX__ + 1)
+
+#define LLONG_MAX __LONG_LONG_MAX__
+#define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
+#define ULLONG_MAX (2 * __LONG_LONG_MAX__ + 1)
+
+#define INT8_MAX __INT8_MAX__
+#define INT8_MIN (-__INT8_MAX__ - 1)
+#define UINT8_MAX __UINT8_MAX__
+
+#define INT16_MAX __INT16_MAX__
+#define INT16_MIN (-__INT16_MAX__ - 1)
+#define UINT16_MAX __UINT16_MAX__
+
+#define INT32_MAX __INT32_MAX__
+#define INT32_MIN (-__INT32_MAX__ - 1)
+#define UINT32_MAX __UINT32_MAX__
+
+#define INT64_MAX __INT64_MAX__
+#define INT64_MIN (-__INT64_MAX__ - 1)
+#define UINT64_MAX __UINT64_MAX__
+
+#define INT_LEAST8_MAX __INT_LEAST8_MAX__
+#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
+#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
+
+#define INT_LEAST16_MAX __INT_LEAST16_MAX__
+#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
+#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
+
+#define INT_LEAST32_MAX __INT_LEAST32_MAX__
+#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
+#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
+
+#define INT_LEAST64_MAX __INT_LEAST64_MAX__
+#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
+#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
+
+#define INT_FAST8_MAX __INT_FAST8_MAX__
+#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
+#define UINT_FAST8_MAX __UINT_FAST8_MAX__
+
+#define INT_FAST16_MAX __INT_FAST16_MAX__
+#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
+#define UINT_FAST16_MAX __UINT_FAST16_MAX__
+
+#define INT_FAST32_MAX __INT_FAST32_MAX__
+#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
+#define UINT_FAST32_MAX __UINT_FAST32_MAX__
+
+#define INT_FAST64_MAX __INT_FAST64_MAX__
+#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
+#define UINT_FAST64_MAX __UINT_FAST64_MAX__
+
+#define INTPTR_MAX __INTPTR_MAX__
+#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
+#define UINTPTR_MAX __UINTPTR_MAX__
+
+#define INTMAX_MAX __INTMAX_MAX__
+#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
+#define UINTMAX_MAX __UINTMAX_MAX__
+
+#define INT8_WIDTH 8
+#define INT16_WIDTH 16
+#define INT32_WIDTH 32
+#define INT64_WIDTH 64
+#define UINT8_WIDTH 8
+#define UINT16_WIDTH 16
+#define UINT32_WIDTH 32
+#define UINT64_WIDTH 64
+
+#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
+#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
+#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
+#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
+#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
+#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
+#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
+#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
+
+#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+
+#define INTPTR_WIDTH __INTPTR_WIDTH__
+#define INTMAX_WIDTH __INTMAX_WIDTH__
+#define UINTPTR_WIDTH __INTPTR_WIDTH__
+#define UINTMAX_WIDTH __INTMAX_WIDTH__
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define be16_to_cpu(x) __builtin_bswap16(x)
+#define be32_to_cpu(x) __builtin_bswap32(x)
+#define be64_to_cpu(x) __builtin_bswap64(x)
+
+#define cpu_to_be16(x) __builtin_bswap16(x)
+#define cpu_to_be32(x) __builtin_bswap32(x)
+#define cpu_to_be64(x) __builtin_bswap64(x)
+
+#define le16_to_cpu(x) (x)
+#define le32_to_cpu(x) (x)
+#define le64_to_cpu(x) (x)
+
+#define cpu_to_le16(x) (x)
+#define cpu_to_le32(x) (x)
+#define cpu_to_le64(x) (x)
+#else
+#define be16_to_cpu(x) (x)
+#define be32_to_cpu(x) (x)
+#define be64_to_cpu(x) (x)
+
+#define cpu_to_be16(x) (x)
+#define cpu_to_be32(x) (x)
+#define cpu_to_be64(x) (x)
+
+#define le16_to_cpu(x) __builtin_bswap16(x)
+#define le32_to_cpu(x) __builtin_bswap32(x)
+#define le64_to_cpu(x) __builtin_bswap64(x)
+
+#define cpu_to_le16(x) __builtin_bswap16(x)
+#define cpu_to_le32(x) __builtin_bswap32(x)
+#define cpu_to_le64(x) __builtin_bswap64(x)
+#endif
+
+#define NULL 0
+
#endif /* APOS_TYPES_H */