diff --git a/Depfile b/Depfile index 801703a..270cf23 100644 --- a/Depfile +++ b/Depfile @@ -2,7 +2,7 @@ Artifact=kernel TempDir=obj SourceDir=asm src -AdditionalObjects=obj/main.o +AdditionalObjects=obj/main.o obj/firstcode.o AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o @@ -10,6 +10,7 @@ AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Deb AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o +AdditionalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o LexUseCpp YaccUseCpp @@ -28,9 +29,10 @@ FLAGS=-m32 -DCONDUCTANCE_64BIT -DCIRCUIT_OS -Dnullptr=0 -D__cdecl="__attribute__ ASFLAGS=-masm=intel CCFLAGS=-g -std=c11 -Dnullptr=0 -Wall -g -fno-stack-protector -ffreestanding -Iinclude CXXFLAGS=-g -std=c++11 -Wall -g -fno-stack-protector -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra -ffreestanding -Wno-unused-function -Iinclude -LDFLAGS=-g -m32 -nostdlib -fno-builtin -Tkernel.ld -L/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/ -lConductance +LDFLAGS=-g -m32 -nostdlib -fno-builtin -Tkernel.ld -- + obj/main.o: scripts/main.ts objcopy -B i386 -I binary -O elf32-i386 \ scripts/main.ts obj/main.o @@ -40,6 +42,15 @@ obj/main.o: scripts/main.ts --redefine-sym _binary_scripts_main_ts_size=mainscript_size \ obj/main.o +obj/firstcode.o: /home/felix/projects/Electronics/first-run.ca + cp /home/felix/projects/Electronics/first-run.ca obj/firstrun.ca + objcopy -B i386 -I binary -O elf32-i386 \ + obj/firstrun.ca obj/firstcode.o + objcopy \ + --redefine-sym _binary_obj_firstrun_ca_start=firstrun_start \ + --redefine-sym _binary_obj_firstrun_ca_end=firstrun_end \ + --redefine-sym _binary_obj_firstrun_ca_size=firstrun_size \ + obj/firstcode.o .PHONY: run run: diff --git a/Makefile b/Makefile index f7b4a5c..5b8a99a 100644 --- a/Makefile +++ b/Makefile @@ -13,32 +13,32 @@ YACC = bison SRCS_AS = asm/dynamic.S asm/intr_common_handler.S asm/multiboot.S asm/start.S SRCS_CC = src/console.c src/init.c src/interrupts.c src/malloc.c src/pmm.c src/serial.c src/stdlib.c src/timer.c src/vmm.c SRCS_CXX = src/cplusplus.cpp src/cpp-test.cpp src/vm.cpp -OBJS = obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o +OBJS = obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o obj/firstcode.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o # Flags FLAGS = -m32 -DCONDUCTANCE_64BIT -DCIRCUIT_OS -Dnullptr=0 -D__cdecl="__attribute__((cdecl))" -mno-sse -mno-sse2 -mno-mmx -I/home/felix/projects/Electronics/Electronics/Conductance -I/home/felix/projects/Electronics/Electronics/Tools ASFLAGS = -masm=intel CCFLAGS = -g -std=c11 -Dnullptr=0 -Wall -g -fno-stack-protector -ffreestanding -Iinclude CXXFLAGS = -g -std=c++11 -Wall -g -fno-stack-protector -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wall -Wextra -ffreestanding -Wno-unused-function -Iinclude -LDFLAGS = -g -m32 -nostdlib -fno-builtin -Tkernel.ld -L/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/ -lConductance +LDFLAGS = -g -m32 -nostdlib -fno-builtin -Tkernel.ld # Targets all: kernel .PHONY: clean clean: - $(RM) obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o + $(RM) obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o obj/firstcode.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o -kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o - $(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o +kernel: obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o obj/firstcode.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o + $(LD) $(FLAGS) $(LDFLAGS) -o $@ obj/dynamic.o obj/intr_common_handler.o obj/multiboot.o obj/start.o obj/console.o obj/init.o obj/interrupts.o obj/malloc.o obj/pmm.o obj/serial.o obj/stdlib.o obj/timer.o obj/vmm.o obj/cplusplus.o obj/cpp-test.o obj/vm.o obj/main.o obj/firstcode.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvoidtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o # src/console.c -obj/console.o: src/console.c include/console.h include/stdlib.h \ +obj/console.o: src/console.c include/console.h include/kstdlib.h \ include/varargs.h include/config.h include/malloc.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/console.c # src/init.c -obj/init.o: src/init.c include/kernel.h include/stdlib.h include/varargs.h \ +obj/init.o: src/init.c include/kernel.h include/kstdlib.h include/varargs.h \ include/config.h include/malloc.h include/console.h include/interrupts.h \ include/cpustate.h include/pmm.h include/multiboot.h include/vmm.h \ include/timer.h include/serial.h @@ -46,29 +46,29 @@ obj/init.o: src/init.c include/kernel.h include/stdlib.h include/varargs.h \ # src/interrupts.c obj/interrupts.o: src/interrupts.c include/interrupts.h include/cpustate.h \ - include/console.h include/stdlib.h include/varargs.h include/config.h \ + include/console.h include/kstdlib.h include/varargs.h include/config.h \ include/malloc.h include/io.h src/intr_stubs.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/interrupts.c # src/malloc.c -obj/malloc.o: src/malloc.c include/kernel.h include/stdlib.h \ - include/varargs.h include/config.h include/malloc.h include/console.h \ +obj/malloc.o: src/malloc.c include/config.h include/kernel.h \ + include/kstdlib.h include/varargs.h include/malloc.h include/console.h \ include/serial.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/malloc.c # src/pmm.c obj/pmm.o: src/pmm.c include/pmm.h include/multiboot.h include/kernel.h \ - include/stdlib.h include/varargs.h include/config.h include/malloc.h \ + include/kstdlib.h include/varargs.h include/config.h include/malloc.h \ include/console.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/pmm.c # src/serial.c -obj/serial.o: src/serial.c include/io.h include/serial.h include/stdlib.h \ +obj/serial.o: src/serial.c include/io.h include/serial.h include/kstdlib.h \ include/varargs.h include/config.h include/malloc.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/serial.c # src/stdlib.c -obj/stdlib.o: src/stdlib.c include/stdlib.h include/varargs.h \ +obj/stdlib.o: src/stdlib.c include/kstdlib.h include/varargs.h \ include/config.h include/malloc.h include/kernel.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/stdlib.c @@ -79,24 +79,23 @@ obj/timer.o: src/timer.c include/timer.h include/kernel.h \ # src/vmm.c obj/vmm.o: src/vmm.c include/config.h include/vmm.h include/pmm.h \ - include/multiboot.h include/stdlib.h include/varargs.h include/malloc.h \ + include/multiboot.h include/kstdlib.h include/varargs.h include/malloc.h \ include/console.h include/kernel.h $(CC) $(FLAGS) $(CCFLAGS) -o $@ -c src/vmm.c # src/cplusplus.cpp -obj/cplusplus.o: src/cplusplus.cpp include/stdlib.h include/varargs.h \ +obj/cplusplus.o: src/cplusplus.cpp include/kstdlib.h include/varargs.h \ include/config.h include/malloc.h include/console.h include/ker/new.hpp $(CXX) $(FLAGS) $(CXXFLAGS) -o $@ -c src/cplusplus.cpp # src/cpp-test.cpp obj/cpp-test.o: src/cpp-test.cpp include/console.h include/ker/string.hpp \ - include/stdlib.h include/varargs.h include/config.h include/malloc.h \ - include/string.h include/ker/vector.hpp include/ker/new.hpp \ - include/ker/dictionary.hpp include/kernel.h include/ker/pair.hpp + include/ker/vector.hpp include/ker/dictionary.hpp include/kernel.h \ + include/ker/pair.hpp $(CXX) $(FLAGS) $(CXXFLAGS) -o $@ -c src/cpp-test.cpp # src/vm.cpp -obj/vm.o: src/vm.cpp include/stdlib.h include/varargs.h include/config.h \ +obj/vm.o: src/vm.cpp include/kstdlib.h include/varargs.h include/config.h \ include/malloc.h include/timer.h include/dynamic.h include/console.h $(CXX) $(FLAGS) $(CXXFLAGS) -o $@ -c src/vm.cpp @@ -117,6 +116,7 @@ obj/start.o: asm/start.S $(AS) $(FLAGS) $(ASFLAGS) -o $@ -c asm/start.S # Custom Targets + obj/main.o: scripts/main.ts objcopy -B i386 -I binary -O elf32-i386 \ scripts/main.ts obj/main.o @@ -126,6 +126,15 @@ obj/main.o: scripts/main.ts --redefine-sym _binary_scripts_main_ts_size=mainscript_size \ obj/main.o +obj/firstcode.o: /home/felix/projects/Electronics/first-run.ca + cp /home/felix/projects/Electronics/first-run.ca obj/firstrun.ca + objcopy -B i386 -I binary -O elf32-i386 \ + obj/firstrun.ca obj/firstcode.o + objcopy \ + --redefine-sym _binary_obj_firstrun_ca_start=firstrun_start \ + --redefine-sym _binary_obj_firstrun_ca_end=firstrun_end \ + --redefine-sym _binary_obj_firstrun_ca_size=firstrun_size \ + obj/firstcode.o .PHONY: run run: diff --git a/include/ker/string.hpp b/include/ker/string.hpp index 2edac22..60df5ec 100644 --- a/include/ker/string.hpp +++ b/include/ker/string.hpp @@ -3,7 +3,6 @@ #include #if defined(CIRCUIT_OS) #include -#error "???" #else #include #include @@ -224,10 +223,7 @@ namespace ker } template - static String from(const T &) - { - return "Not implemented yet"; - } + static String from(const T &); }; diff --git a/include/ker/vector.hpp b/include/ker/vector.hpp index ce4741a..5a14fac 100644 --- a/include/ker/vector.hpp +++ b/include/ker/vector.hpp @@ -150,7 +150,7 @@ namespace ker if(current > size) { // "Downgrade" - for(int32_t i = static_cast(this->mLength) - 1; i > static_cast(size); i--) { + for(int32_t i = static_cast(this->mLength) - 1; i >= static_cast(size); i--) { this->mData[i].~T(); } } else { diff --git a/include/kstdlib.h b/include/kstdlib.h index 999e2e8..6e3c276 100644 --- a/include/kstdlib.h +++ b/include/kstdlib.h @@ -13,7 +13,7 @@ extern "C" { char *itoa(int value, char *str, int base); int atoi(const char *str); -float atof(const char *str); +// float atof(const char *str); void exit(int errorCode); diff --git a/ker/string.cpp b/ker/string.cpp new file mode 100644 index 0000000..0cc6ff3 --- /dev/null +++ b/ker/string.cpp @@ -0,0 +1,138 @@ +#include +#include "../include/ker/string.hpp" + +#define SPEC(type) template<> String String::from(const type &val) + +static void reverse(char *str, int length) +{ + int start = 0; + int end = length -1; + while (start < end) + { + char tmp = *(str+start); + *(str+start) = *(str+end); + *(str+end) = tmp; + start++; + end--; + } +} + +static char *_itoa(int num, char *str, int base, bool useUnsigned) +{ + int i = 0; + int isNegative = 0; + + if(str == nullptr) { + static char tmp[64]; + str = tmp; + } + + /* Handle 0 explicitely, otherwise empty string is printed for 0 */ + if (num == 0) + { + str[i++] = '0'; + str[i] = '\0'; + return str; + } + + // In standard itoa(), negative numbers are handled only with + // base 10. Otherwise numbers are considered unsigned. + if ((useUnsigned == false) && (num < 0) && (base == 10)) + { + isNegative = 1; + num = -num; + } + + // Process individual digits + while (num != 0) + { + int rem = num % base; + str[i++] = (rem > 9)? (rem-10) + 'A' : rem + '0'; + num = num/base; + } + + // If number is negative, append '-' + if (isNegative) + { + str[i++] = '-'; + } + str[i] = '\0'; // Append string terminator + + // Reverse the string + reverse(str, i); + + return str; +} + +namespace ker +{ + SPEC(bool) + { + return val ? "true" : "false"; + } + + SPEC(String) + { + return val; + } + + SPEC(int8_t) { + static char buffer[16]; + _itoa(val, buffer, 10, false); + return buffer; + } + + SPEC(int16_t) { + static char buffer[16]; + _itoa(val, buffer, 10, false); + return buffer; + } + + SPEC(int32_t) { + static char buffer[16]; + _itoa(val, buffer, 10, false); + return buffer; + } + + SPEC(uint8_t) { + static char buffer[16]; + _itoa(val, buffer, 10, true); + return buffer; + } + + SPEC(uint16_t) { + static char buffer[16]; + _itoa(val, buffer, 10, true); + return buffer; + } + + SPEC(uint32_t) { + static char buffer[16]; + _itoa(val, buffer, 10, true); + return buffer; + } + + SPEC(float) { + (void)val; + return "f32"; + } + +#if defined(CONDUCTANCE_64BIT) + + SPEC(int64_t) + { + return "i64"; + } + + SPEC(uint64_t) + { + return "u64"; + } + + SPEC(double) + { + return "f64"; + } + +#endif +} diff --git a/src/console.c b/src/console.c index 5b3562c..4bcba33 100644 --- a/src/console.c +++ b/src/console.c @@ -1,5 +1,6 @@ +#include #include "console.h" -#include "stdlib.h" +#include "kstdlib.h" typedef enum { diff --git a/src/cplusplus.cpp b/src/cplusplus.cpp index 8037fa2..5595461 100644 --- a/src/cplusplus.cpp +++ b/src/cplusplus.cpp @@ -1,5 +1,5 @@ -#include +#include #include #include #include @@ -71,3 +71,25 @@ extern "C" void cpp_init() { initialiseConstructors(); } + + + +typedef void (*destructor)(); +/* +// Im Linkerskript definiert +extern "C" destructor start_dtors; +extern "C" destructor end_dtors; + +extern "C" void initialiseDestructors(); + +// Ruft die Konstruktoren für globale/statische Objekte auf +void initialiseDestructors() +{ + for (destructor* i = &start_dtors;i != &end_dtors;++i) + (*i)(); +} +*/ +extern "C" void cpp_exit() +{ + initialiseConstructors(); +} diff --git a/src/init.c b/src/init.c index a37a096..e3d8256 100644 --- a/src/init.c +++ b/src/init.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -143,6 +143,8 @@ static void dumpMB(const MultibootStructure *mbHeader) void cpp_init(); +void cpp_exit(); + void putsuccess() { int y; kgetpos(nullptr, &y); @@ -210,6 +212,8 @@ void init(const MultibootStructure *mbHeader) irq_disable(); + cpp_exit(); + kputs("\x12\x04" "CircuitOS stopped." "\x12\x07" "\n"); #if defined(ENABLE_MALLOC_MONITORING) diff --git a/src/interrupts.c b/src/interrupts.c index 5aef37f..af77753 100644 --- a/src/interrupts.c +++ b/src/interrupts.c @@ -1,6 +1,6 @@ #include "interrupts.h" #include "console.h" -#include "stdlib.h" +#include "kstdlib.h" #include "cpustate.h" #include "io.h" diff --git a/src/malloc.c b/src/malloc.c index b7bc8fa..a94d8d2 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -1,5 +1,6 @@ +#include #include -#include +#include #include #include #include @@ -38,13 +39,17 @@ static uint32_t hash(List *list) static int isValid(List *list) { +#if defined(USE_MAGIC_SECURED_MALLOC) return list->hash == hash(list); +#else + return 1; // Yes, it is always valid. What a pity.... +#endif } size_t mallocCount = 0, freeCount = 0; size_t allocatedMemory = 0; -static const size_t minimumAllocSize = 2 * sizeof(List); +static const size_t minimumAllocSize = 1; // 2 * sizeof(List); static char * const malloc_heap_start = (char *)0x400000; static char * const malloc_heap_end = (char *)0x800000; @@ -196,7 +201,10 @@ void *malloc(size_t len) cursor->allocationFile = file; cursor->allocationLine = line; #endif + +#if defined(USE_MAGIC_SECURED_MALLOC) cursor->hash = hash(cursor); +#endif allocatedMemory += len; mallocCount++; diff --git a/src/pmm.c b/src/pmm.c index 0f334f9..7d3c8ef 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -1,7 +1,7 @@ #include #include "pmm.h" #include "kernel.h" -#include "stdlib.h" +#include "kstdlib.h" #include "console.h" diff --git a/src/serial.c b/src/serial.c index f18f095..0e4e034 100644 --- a/src/serial.c +++ b/src/serial.c @@ -1,6 +1,6 @@ #include #include -#include +#include #include // Funktion zum initialisieren eines COM-Ports diff --git a/src/stdlib.c b/src/stdlib.c index 143f230..c434ab2 100644 --- a/src/stdlib.c +++ b/src/stdlib.c @@ -1,4 +1,4 @@ -#include +#include #include void exit(int errorCode) diff --git a/src/vm.cpp b/src/vm.cpp index f00f685..c7e67c4 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -11,6 +11,10 @@ extern "C" { extern const char mainscript_start; extern const char mainscript_end; extern const char mainscript_size; + + extern const char firstrun_start; + extern const char firstrun_end; + extern const char firstrun_size; } void printVMValue(const VMValue &value) @@ -45,25 +49,68 @@ ExceptionCode printArguments(VMValue &, const VMArray &args) return ExceptionCode::None; } +struct dtortest { + void *mem; + + dtortest() : mem(malloc(42)) { } + ~dtortest() { free(mem); } +}; + extern "C" void vm_start() { - struct { - const char *ptr; - uint32_t size; - } mainfile { - &mainscript_start, - (uint32_t)&mainscript_size - }; + +/* +} + +void code() +{ +//*/ + + struct { + const char *ptr; + uint32_t size; + } firstrun { + &firstrun_start, + (uint32_t)&firstrun_size + }; VirtualMachine vm; vm.import("print") = printArguments; + Assembly *assembly = vm.load(firstrun.ptr, firstrun.size); + if(assembly == nullptr) { + kprintf("failed to load assembly :(\n"); + return; + } + + /* + kprintf("Assembly:\n"); + kprintf(" Name: %s\n", assembly->name().str()); + kprintf(" Author: %s\n", assembly->author().str()); + kprintf(" Description: %s\n", assembly->description().str()); + //*/ + /* + kprintf("Type list:\n"); + for(const auto &type : vm.types()) { + kprintf("%s: %x\n", type.first.str(), vm.type(type.first)); + } + //*/ + + Process *process = vm.createProcess(assembly); + if(process == nullptr) { + kprintf("Failed to create process.\n"); + return; + } + while(vm.step()) { - kprintf("."); + // kprintf("."); } + process->release(); + assembly->release(); + kprintf("\n"); } diff --git a/src/vmm.c b/src/vmm.c index a923f0b..2550356 100644 --- a/src/vmm.c +++ b/src/vmm.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/trainOS.pro b/trainOS.pro index 83d2585..5bcbf21 100644 --- a/trainOS.pro +++ b/trainOS.pro @@ -26,7 +26,7 @@ HEADERS += \ include/kernel.h \ include/multiboot.h \ include/pmm.h \ - include/stdlib.h \ + include/kstdlib.h \ include/varargs.h \ include/vmm.h \ include/timer.h \ @@ -34,7 +34,7 @@ HEADERS += \ include/ker/pair.hpp \ include/ker/vector.hpp \ include/ker/dictionary.hpp \ - include/string.h \ + include/kstring.h \ include/ker/new.hpp \ include/dynamic.h \ include/config.h \