From 7e4c9777f8cb29dce60bffec7050925c16130adc Mon Sep 17 00:00:00 2001 From: IPlayZed Date: Thu, 3 Feb 2022 21:46:03 +0100 Subject: [PATCH] Added -fpermissive for ctor iteration comparison. FIXME: When calling call_ctors in loader.s, kernel hangs. --- src/Makefile | 4 ++-- src/kernel.cpp | 6 +++++- src/loader.s | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index fdf1dcf..17e1398 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,5 @@ # g++ parameters -GPP_PARAMS = -m32 -Wall -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore +GPP_PARAMS = -m32 -Wall -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -fpermissive # assembler parameters AS_PARAMS = --32 # linker parameters @@ -36,4 +36,4 @@ sunix.iso: sunix.bin cp grub.cfg ${ISO_GRUB_DIR} grub-mkrescue --output=$@ ${ISO_DIR} rm -rf iso - mv $@ ../out \ No newline at end of file + mv $@ ../out diff --git a/src/kernel.cpp b/src/kernel.cpp index 2fdce03..ede7c06 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -30,9 +30,13 @@ void printf(char* str) } } +/* For composite object static/global objects (like class instances) we must call the compiler + * generated constructors. + * We just iterate through them. + * */ extern LANG_C void call_ctors() { - for(ctor* i = &start_ctors; i != (ctor*)end_ctors; i++) + for(ctor* i = &start_ctors; i != end_ctors; i++) { (*i)(); } diff --git a/src/loader.s b/src/loader.s index d60b2c9..a52f858 100644 --- a/src/loader.s +++ b/src/loader.s @@ -14,9 +14,10 @@ .global loader loader: - mov $kernel_stack_ptr, %esp # set stack pointer, as kernel_main is a cpp program and it expects the stack pointer to be set + mov $kernel_stack_ptr, %esp # set stack pointer, as kernel_main is a cpp program and it expects the stack pointer to be set. - call call_ctors + # FIXME: When this is called, kernel doesn't run? + #call call_ctors # Call the compiler generated constructors. push %eax # The (GRUB2) bootloader stores the multiboot structure's RAM adress in the AX register during loading the kernel of choice, which contains valuable information, like the size of the RAM. We should push this to the stack in order to access it later. push %ebx # The (GRUB2) bootloader stores the MULTIBOOT_FLAG value in the BX register.