------------
A microkernel will not make use of system libraries, and provide local
-implementations of all required functionality. C99 however provides
-standard headers which are explicitly safe for embedded use. These
-should be used instead of reimplementing equivalent functionality
-locally.
-
-An incomplete list includes:
-
- * inttypes.h (PRIx64, ...)
- * limits.h (INT_MAX, ...)
- * stdarg.h (va_list, ...)
- * stdbool.h (bool, true, false)
- * stdint.h (uint??_t ...)
+implementations of all required functionality.
COMMON_CFLAGS := $(COMMON_FLAGS) $(COMMON_CFLAGS-y)
COMMON_CFLAGS += -Wall -Wextra -Werror -std=gnu99 -Wstrict-prototypes -O3 -g
COMMON_CFLAGS += -fno-common -fno-asynchronous-unwind-tables -fno-strict-aliasing
-COMMON_CFLAGS += -fno-stack-protector -fno-pic -ffreestanding
+COMMON_CFLAGS += -fno-stack-protector -fno-pic -ffreestanding -nostdinc
COMMON_CFLAGS += -mno-red-zone -mno-sse
COMMON_CFLAGS += -Wno-unused-parameter -Winline
Requirements:
- GNU Make >= 3.81
-- GNU compatible 32 and 64-bit toolchain, capable of `-std=gnu99`, `-m64`, and
- `-m32`
- - For Debian-based systems, the `build-essential` package is
- sufficient. For RHEL-based systems, the `glibc-devel.i686` package is
- generally needed beyond the default toolchain packages.
- - Clang may be used, via `CC="clang"`
- Python 2.6 or later
-Optionally:
-- A toolchain with x32 support.
- - `hvm64` tests would prefer to use the `elf32-x86-64` format, so they
- both load and disassemble correctly. In the absence of x32 support,
- `elf32-i386` will be used which will load correctly, but disassemble
- incorrectly.
+For x86:
+ - GNU compatible 32 and 64-bit toolchain, capable of `-std=gnu99`, `-m64`,
+ and `-m32`.
+ - Clang may be used, via `CC="clang"`.
+ - Optionally, a toolchain with x32 support.
+ - `hvm64` tests would prefer to use the `elf32-x86-64` format, so they
+ both load and disassemble correctly. In the absence of x32 support,
+ `elf32-i386` will be used which will load correctly, but disassemble
+ incorrectly.
To obtain and build:
--- /dev/null
+/**
+ * @file include/inttypes.h
+ *
+ * Local subset of C's inttypes.h
+ */
+#ifndef INTTYPES_H
+#define INTTYPES_H
+
+#if __SIZEOF_LONG__ == 8
+# define __PRI64 "l"
+# define __PRIPTR "l"
+#else
+# define __PRI64 "ll"
+# define __PRIPTR
+#endif
+
+#define PRId64 __PRI64 "d"
+#define PRIx64 __PRI64 "x"
+#define PRIo64 __PRI64 "o"
+#define PRIu64 __PRI64 "u"
+
+#define PRIdPTR __PRIPTR "d"
+#define PRIoPTR __PRIPTR "o"
+#define PRIuPTR __PRIPTR "u"
+#define PRIxPTR __PRIPTR "x"
+
+#endif /* INTTYPES_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/**
+ * @file include/limits.h
+ *
+ * Local subset of C's limits.h
+ */
+#ifndef LIMITS_H
+#define LIMITS_H
+
+#define CHAR_BIT __CHAR_BIT__
+
+#endif /* LIMITS_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/**
+ * @file include/stdarg.h
+ *
+ * Local subset of C's stdarg.h
+ */
+#ifndef STDARG_H
+#define STDARG_H
+
+typedef __builtin_va_list va_list;
+#define va_start(v, l) __builtin_va_start(v, l)
+#define va_end(v) __builtin_va_end(v)
+#define va_arg(v, l) __builtin_va_arg(v, l)
+#define va_copy(d, s) __builtin_va_copy(d, s)
+
+#endif /* STDARG_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/**
+ * @file include/stdbool.h
+ *
+ * Local subset of C's stdbool.h
+ */
+#ifndef STDBOOL_H
+#define STDBOOL_H
+
+typedef _Bool bool;
+#define true 1
+#define false 0
+
+#endif /* STDBOOL_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/**
+ * @file include/stddef.h
+ *
+ * Local subset of C's stddef.h
+ */
+#ifndef STDDEF_H
+#define STDDEF_H
+
+typedef __SIZE_TYPE__ size_t;
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+#define NULL ((void *)0)
+
+#define offsetof(t, m) __builtin_offsetof(t, m)
+
+#endif /* STDDEF_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
--- /dev/null
+/**
+ * @file include/stdint.h
+ *
+ * Local subset of C's stdint.h
+ */
+#ifndef STDINT_H
+#define STDINT_H
+
+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 __INTPTR_TYPE__ intptr_t;
+typedef __UINTPTR_TYPE__ uintptr_t;
+
+#endif /* STDINT_H */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */