misc: Do not rely on libc-provided headers
diff --git a/autogen.sh b/autogen.sh
index 8a619cf1..909282e1 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#! /bin/sh
set -ex
diff --git a/decompressor/GNUmakefile b/decompressor/GNUmakefile
index 5e816add..47f5e35f 100644
--- a/decompressor/GNUmakefile
+++ b/decompressor/GNUmakefile
@@ -24,9 +24,11 @@ override INTERNAL_CFLAGS := \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
+ -fno-lto \
-fno-pic \
-fno-pie \
-fomit-frame-pointer \
+ -nostdinc \
-Wno-address-of-packed-member \
-mno-80387 \
-mno-mmx \
@@ -34,6 +36,7 @@ override INTERNAL_CFLAGS := \
-mno-sse \
-mno-sse2 \
-MMD \
+ -I../stdinc \
-I. \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
diff --git a/stage23/GNUmakefile b/stage23/GNUmakefile
index adfc9f0b..ca09ae9c 100644
--- a/stage23/GNUmakefile
+++ b/stage23/GNUmakefile
@@ -49,6 +49,7 @@ override INTERNAL_CFLAGS := \
-fno-stack-protector \
-fno-omit-frame-pointer \
-fno-lto \
+ -nostdinc \
-Wno-address-of-packed-member \
-Wshadow \
-mno-80387 \
@@ -61,6 +62,7 @@ override INTERNAL_CFLAGS := \
-DLIMINE_COPYRIGHT='"$(LIMINE_COPYRIGHT)"' \
-DCOM_OUTPUT=$(COM_OUTPUT) \
-DE9_OUTPUT=$(E9_OUTPUT) \
+ -I../stdinc \
-I. \
-I../stivale \
-I'$(call SHESCAPE,$(BUILDDIR))/tinf'
diff --git a/stage23/protos/multiboot1.c b/stage23/protos/multiboot1.c
index 29973317..7d3d2e3c 100644
--- a/stage23/protos/multiboot1.c
+++ b/stage23/protos/multiboot1.c
@@ -180,7 +180,7 @@ bool multiboot1_load(char *config, char *cmdline) {
if (cmdline)
multiboot1_info->flags |= (1 << 2);
- char *bootload_name = "Limine";
+ char *bootload_name = "Limine " LIMINE_VERSION;
char *lowmem_bootname = conv_mem_alloc(strlen(bootload_name) + 1);
strcpy(lowmem_bootname, bootload_name);
diff --git a/stage23/protos/multiboot2.c b/stage23/protos/multiboot2.c
index 95697e89..40daee34 100644
--- a/stage23/protos/multiboot2.c
+++ b/stage23/protos/multiboot2.c
@@ -19,6 +19,8 @@
#include <lib/blib.h>
#include <drivers/vga_textmode.h>
+#define LIMINE_BRAND "Limine " LIMINE_VERSION
+
/// Returns the size required to store the multiboot2 info.
static size_t get_multiboot2_info_size(
char *cmdline,
@@ -27,8 +29,8 @@ static size_t get_multiboot2_info_size(
uint32_t smbios_tag_size
) {
return ALIGN_UP(sizeof(struct multiboot2_start_tag), MULTIBOOT_TAG_ALIGN) + // start
- ALIGN_UP(strlen(cmdline) + 1 + offsetof(struct multiboot_tag_string, string), MULTIBOOT_TAG_ALIGN) + // cmdline
- ALIGN_UP(8 + offsetof(struct multiboot_tag_string, string), MULTIBOOT_TAG_ALIGN) + // bootloader brand
+ ALIGN_UP(sizeof(struct multiboot_tag_string) + strlen(cmdline) + 1, MULTIBOOT_TAG_ALIGN) + // cmdline
+ ALIGN_UP(sizeof(struct multiboot_tag_string) + sizeof(LIMINE_BRAND), MULTIBOOT_TAG_ALIGN) + // bootloader brand
ALIGN_UP(sizeof(struct multiboot_tag_framebuffer), MULTIBOOT_TAG_ALIGN) + // framebuffer
ALIGN_UP(sizeof(struct multiboot_tag_new_acpi) + sizeof(struct rsdp), MULTIBOOT_TAG_ALIGN) + // new ACPI info
ALIGN_UP(sizeof(struct multiboot_tag_old_acpi) + 20, MULTIBOOT_TAG_ALIGN) + // old ACPI info
@@ -340,7 +342,7 @@ bool multiboot2_load(char *config, char* cmdline) {
// Create command line tag
//////////////////////////////////////////////
{
- uint32_t size = strlen(cmdline) + 1 + offsetof(struct multiboot_tag_string, string);
+ uint32_t size = sizeof(struct multiboot_tag_string) + strlen(cmdline) + 1;
struct multiboot_tag_string *tag = (struct multiboot_tag_string *)(mb2_info + info_idx);
tag->type = MULTIBOOT_TAG_TYPE_CMDLINE;
@@ -354,14 +356,13 @@ bool multiboot2_load(char *config, char* cmdline) {
// Create bootloader name tag
//////////////////////////////////////////////
{
- char brand[] = "Limine";
- uint32_t size = sizeof(brand) + offsetof(struct multiboot_tag_string, string);
+ uint32_t size = sizeof(struct multiboot_tag_string) + sizeof(LIMINE_BRAND);
struct multiboot_tag_string *tag = (struct multiboot_tag_string *)(mb2_info + info_idx);
tag->type = MULTIBOOT_TAG_TYPE_BOOT_LOADER_NAME;
tag->size = size;
- strcpy(tag->string, brand);
+ strcpy(tag->string, LIMINE_BRAND);
append_tag(info_idx, tag);
}
diff --git a/stdinc/stdalign.h b/stdinc/stdalign.h
new file mode 100644
index 00000000..e0f666e8
--- /dev/null
+++ b/stdinc/stdalign.h
@@ -0,0 +1,6 @@
+#ifndef __STDALIGN_H__
+#define __STDALIGN_H__
+
+#define alignas(a) __attribute__((aligned(a)))
+
+#endif
diff --git a/stdinc/stdarg.h b/stdinc/stdarg.h
new file mode 100644
index 00000000..72c8707e
--- /dev/null
+++ b/stdinc/stdarg.h
@@ -0,0 +1,10 @@
+#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)
+
+#endif
diff --git a/stdinc/stdbool.h b/stdinc/stdbool.h
new file mode 100644
index 00000000..1308f450
--- /dev/null
+++ b/stdinc/stdbool.h
@@ -0,0 +1,9 @@
+#ifndef __STDBOOL_H__
+#define __STDBOOL_H__
+
+#define bool _Bool
+
+#define true 1
+#define false 0
+
+#endif
diff --git a/stdinc/stddef.h b/stdinc/stddef.h
new file mode 100644
index 00000000..b5ad4bb6
--- /dev/null
+++ b/stdinc/stddef.h
@@ -0,0 +1,14 @@
+#ifndef __STDDEF_H__
+#define __STDDEF_H__
+
+typedef __SIZE_TYPE__ size_t;
+
+#ifdef NULL
+#undef NULL
+#endif
+
+#define NULL ((void *)0)
+
+#define offsetof(s, m) __builtin_offsetof(s, m)
+
+#endif
diff --git a/stdinc/stdint.h b/stdinc/stdint.h
new file mode 100644
index 00000000..b937d413
--- /dev/null
+++ b/stdinc/stdint.h
@@ -0,0 +1,16 @@
+#ifndef __STDINT_H__
+#define __STDINT_H__
+
+typedef __UINT8_TYPE__ uint8_t;
+typedef __UINT16_TYPE__ uint16_t;
+typedef __UINT32_TYPE__ uint32_t;
+typedef __UINT64_TYPE__ uint64_t;
+
+typedef __INT8_TYPE__ int8_t;
+typedef __INT16_TYPE__ int16_t;
+typedef __INT32_TYPE__ int32_t;
+typedef __INT64_TYPE__ int64_t;
+
+typedef __UINTPTR_TYPE__ uintptr_t;
+
+#endif
diff --git a/stdinc/stdnoreturn.h b/stdinc/stdnoreturn.h
new file mode 100644
index 00000000..fa6603d2
--- /dev/null
+++ b/stdinc/stdnoreturn.h
@@ -0,0 +1,6 @@
+#ifndef __STDNORETURN_H__
+#define __STDNORETURN_H__
+
+#define noreturn __attribute__((noreturn))
+
+#endif
