aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-16 12:34:18 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-16 12:34:18 +0200
commitd39920b62e3e0371c5698aae2c316671130b0956 (patch)
tree7b561a5f53d1d4373fbe30c72d5ef3b9888a5d4a
parentMap .text and .rodata as read-only (diff)
downloadkernel.cpp-d39920b62e3e0371c5698aae2c316671130b0956.tar.xz
Switch lto to full
-rw-r--r--libk/makefile2
-rw-r--r--libk/stdlib/memory.cc47
-rw-r--r--makefile1
-rw-r--r--src/cpu/registers.h21
-rw-r--r--src/makefile1
-rw-r--r--src/memory.cc11
-rw-r--r--toolchain.makefile8
7 files changed, 67 insertions, 24 deletions
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 <stdlib.h>
+
+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<uint8_t*>(dstptr);
+ const auto* src = static_cast<const uint8_t*>(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<uint8_t*>(bufptr);
+ for (size_t i = 0; i < n; ++i) buf[i] = static_cast<uint8_t>(value);
+ return bufptr;
+}
+
+extern "C" void* memmove(void* dstptr, const void* srcptr, const size_t n) {
+ auto* dst = static_cast<uint8_t*>(dstptr);
+ const auto* src = static_cast<const uint8_t*>(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<const uint8_t*>(aptr);
+ const auto* b = static_cast<const uint8_t*>(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 <stdlib.h>
-
-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 \