misc: Do not rely on libc-provided headers

This commit is contained in:
mintsuki 2022-01-20 05:17:45 +01:00
parent 8de42af1a8
commit 65ef9561a5
11 changed files with 75 additions and 8 deletions

View File

@ -1,4 +1,4 @@
#!/bin/sh
#! /bin/sh
set -ex

View File

@ -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'

View File

@ -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'

View File

@ -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);

View File

@ -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);
}

6
stdinc/stdalign.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __STDALIGN_H__
#define __STDALIGN_H__
#define alignas(a) __attribute__((aligned(a)))
#endif

10
stdinc/stdarg.h Normal file
View File

@ -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

9
stdinc/stdbool.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef __STDBOOL_H__
#define __STDBOOL_H__
#define bool _Bool
#define true 1
#define false 0
#endif

14
stdinc/stddef.h Normal file
View File

@ -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

16
stdinc/stdint.h Normal file
View File

@ -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

6
stdinc/stdnoreturn.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __STDNORETURN_H__
#define __STDNORETURN_H__
#define noreturn __attribute__((noreturn))
#endif