From d39920b62e3e0371c5698aae2c316671130b0956 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 16 Mar 2021 12:34:18 +0200 Subject: Switch lto to full --- libk/makefile | 2 +- libk/stdlib/memory.cc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ makefile | 1 - src/cpu/registers.h | 21 +++++++++++++++------ src/makefile | 1 - src/memory.cc | 11 ----------- toolchain.makefile | 8 ++++---- 7 files changed, 67 insertions(+), 24 deletions(-) create mode 100644 libk/stdlib/memory.cc delete mode 100644 src/memory.cc diff --git a/libk/makefile b/libk/makefile index afea066..be4a3c0 100644 --- a/libk/makefile +++ b/libk/makefile @@ -1,5 +1,5 @@ CXX_OBJ += libk/string/string.o libk/string/integerview.o \ - libk/stdlib/abort.o libk/stdlib/console.o + libk/stdlib/abort.o libk/stdlib/console.o libk/stdlib/memory.o CXX_TEST_OBJ += libk/test/types.o libk/test/string.o libk/test/result.o diff --git a/libk/stdlib/memory.cc b/libk/stdlib/memory.cc new file mode 100644 index 0000000..c197519 --- /dev/null +++ b/libk/stdlib/memory.cc @@ -0,0 +1,47 @@ +#include + +void operator delete(void*) { + printk("Calling delete\n"); + abort(); +} + +extern "C" void __cxa_pure_virtual() { + printk("__cxa_pure_virtual\n"); + abort(); +} + +extern "C" void* memcpy(void* dstptr, const void* srcptr, const size_t n) { + auto* dst = static_cast(dstptr); + const auto* src = static_cast(srcptr); + for (size_t i = 0; i < n; ++i) dst[i] = src[i]; + return dstptr; +} + +extern "C" void* memset(void* bufptr, const int value, const size_t n) { + auto* buf = static_cast(bufptr); + for (size_t i = 0; i < n; ++i) buf[i] = static_cast(value); + return bufptr; +} + +extern "C" void* memmove(void* dstptr, const void* srcptr, const size_t n) { + auto* dst = static_cast(dstptr); + const auto* src = static_cast(srcptr); + if (dst < src) { + for (size_t i = 0; i < n; ++i) dst[i] = src[i]; + } else { + for (size_t i = n; i != 0; i--) dst[i - 1] = src[i - 1]; + } + return dstptr; +} + +extern "C" int memcmp(const void* aptr, const void* bptr, const size_t n) { + const auto* a = static_cast(aptr); + const auto* b = static_cast(bptr); + for (size_t i = 0; i < n; ++i) { + if (a[i] < b[i]) + return -1; + else if (b[i] < a[i]) + return 1; + } + return 0; +} diff --git a/makefile b/makefile index 5f2d833..fc3338e 100644 --- a/makefile +++ b/makefile @@ -38,7 +38,6 @@ $(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc clean: @rm -rf $(autogen) $(AS_OBJ) $(CXX_OBJ) $(CXX_DEP) $(CXX_TEST_OBJ) $(OBJ_DIR)/glitch.elf $(OBJ_DIR)/isodir - @rm -rf $(OBJ_DIR)/*_cache @make -C tools/kconfig OBJ_DIR=$(CURDIR)/$(OBJ_DIR)/kconfig clean # testing diff --git a/src/cpu/registers.h b/src/cpu/registers.h index edb6b7b..d2f2e74 100644 --- a/src/cpu/registers.h +++ b/src/cpu/registers.h @@ -5,13 +5,22 @@ namespace x86 { struct cpu_state { - /* pusha */ - uint32_t edi, esi; // destination index, source index - uint32_t ebp, esp; // base pointer, stack pointer - uint32_t ebx, edx, ecx, eax; // general registers + /* registers stored by pusha */ + // indexes and pointers + uint32_t edi; // destination index: string, memory copying and setting, far pointer addressing with ES + uint32_t esi; // source index: string and memory copying + uint32_t ebp; // stack base pointer + const uint32_t esp; // stack pointer; this register is not used by popa - uint32_t irq; - uint32_t error; + // general registers + uint32_t ebx; // base register: base pointer for memory access + uint32_t edx; // data register: I/O ports, arithmetic + uint32_t ecx; // counter register: loop counter, for shifts + uint32_t eax; // accumulator register: I/O ports, arithmetic + + /* pushed by interrupt handler macros */ + uint32_t irq; // interrupt number + uint32_t error; // error code /* stack frame, pushed by cpu */ uint32_t eip; diff --git a/src/makefile b/src/makefile index 47e8762..af6c874 100644 --- a/src/makefile +++ b/src/makefile @@ -3,7 +3,6 @@ AS_OBJ += src/boot.o \ CXX_OBJ += src/kernel.o \ src/kernel/dump_gdt.o src/kernel/dump_multiboot.o \ - src/memory.o \ src/gdt.o \ src/gdt/segmentdescriptor.o \ src/idt.o \ diff --git a/src/memory.cc b/src/memory.cc deleted file mode 100644 index 2d440a3..0000000 --- a/src/memory.cc +++ /dev/null @@ -1,11 +0,0 @@ -#include - -void operator delete(void*) { - printk("Calling delete\n"); - abort(); -} - -extern "C" void __cxa_pure_virtual() { - printk("__cxa_pure_virtual\n"); - abort(); -} diff --git a/toolchain.makefile b/toolchain.makefile index ce8fdc6..a4a0667 100644 --- a/toolchain.makefile +++ b/toolchain.makefile @@ -8,13 +8,13 @@ AS := clang AS_FLAGS := LD := ld.lld -LD_FLAGS := -nostdlib -T linker.ld --thinlto-cache-dir=$(OBJ_DIR)/thinlto_cache -# TODO: linking fails with -O0 and -O1 without -flto=thin +LD_FLAGS := -nostdlib -T linker.ld CXX := clang++ TEST_CXX := clang++ -CXX_FLAGS := -std=c++20 -g -O2 -flto=thin \ - -mkernel -ffreestanding -nostdlib -nostdinc -nostdinc++ \ +CXX_FLAGS := -std=c++20 -g -O3 -flto=full \ + -static -ffreestanding -fno-common -nostdinc -nostdinc++ \ + -fno-use-cxa-atexit -fno-rtti -fno-exceptions -fno-non-call-exceptions \ -Wall -Wextra -Werror=pedantic \ -Werror=date-time \ -Werror=shadow-all \ -- cgit v1.2.1