From 2a5e3220d7826fd2aeb1d3a4e6b9a32476c40ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Quei=C3=9Fner?= Date: Wed, 7 Oct 2015 13:45:07 +0200 Subject: [PATCH] Adds main.spark with build inclusion and execution. --- Depfile | 27 ++++++++++----------------- Makefile | 31 ++++++++++++------------------- scripts/main.spark | 29 +++++++++++++++++++++++++++++ scripts/main.ts | 45 --------------------------------------------- src/init.c | 2 ++ src/vm.cpp | 8 ++++---- trainOS.pro | 4 ++-- 7 files changed, 59 insertions(+), 87 deletions(-) create mode 100644 scripts/main.spark delete mode 100644 scripts/main.ts diff --git a/Depfile b/Depfile index ecdc24f..f9340d4 100644 --- a/Depfile +++ b/Depfile @@ -2,8 +2,8 @@ Artifact=kernel TempDir=obj SourceDir=asm src -AdditionalObjects=obj/main.o obj/firstcode.o -ExternalObjects=/home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/|*.o +AdditionalObjects=obj/main.o +ExternalObjects=conductance/|*.o LexUseCpp YaccUseCpp @@ -26,25 +26,18 @@ LDFLAGS=-g -m32 -nostdlib -fno-builtin -Tkernel.ld -- -obj/main.o: scripts/main.ts +obj/main.o: scripts/main.spark + /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/bin/spark \ + scripts/main.spark \ + obj/main.ca objcopy -B i386 -I binary -O elf32-i386 \ - scripts/main.ts obj/main.o + obj/main.ca obj/main.o objcopy \ - --redefine-sym _binary_scripts_main_ts_start=mainscript_start \ - --redefine-sym _binary_scripts_main_ts_end=mainscript_end \ - --redefine-sym _binary_scripts_main_ts_size=mainscript_size \ + --redefine-sym _binary_obj_main_ca_start=mainscript_start \ + --redefine-sym _binary_obj_main_ca_end=mainscript_end \ + --redefine-sym _binary_obj_main_ca_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: qemu-system-i386 -serial stdio -kernel kernel diff --git a/Makefile b/Makefile index d4060eb..857a7e7 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ 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 obj/firstcode.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 # Flags FLAGS = -m32 -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 @@ -27,10 +27,10 @@ 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 obj/firstcode.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 -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/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/opcodes.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmpointertype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.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 obj/firstcode.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/assembly.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/compoundtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/opcodes.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/string.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/virtualmachine.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmpointertype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmprimitivetype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmtype.o /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/Conductance/vmvalue.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 conductance/assembly.o conductance/compoundtype.o conductance/opcodes.o conductance/string.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o 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 conductance/assembly.o conductance/compoundtype.o conductance/opcodes.o conductance/string.o conductance/virtualmachine.o conductance/vmpointertype.o conductance/vmprimitivetype.o conductance/vmtype.o conductance/vmvalue.o conductance/vmvoidtype.o # src/console.c obj/console.o: src/console.c include/console.h include/kstdlib.h \ @@ -117,25 +117,18 @@ obj/start.o: asm/start.S # Custom Targets -obj/main.o: scripts/main.ts +obj/main.o: scripts/main.spark + /home/felix/projects/Electronics/build-Electronics-Desktop-Debug/bin/spark \ + scripts/main.spark \ + obj/main.ca objcopy -B i386 -I binary -O elf32-i386 \ - scripts/main.ts obj/main.o + obj/main.ca obj/main.o objcopy \ - --redefine-sym _binary_scripts_main_ts_start=mainscript_start \ - --redefine-sym _binary_scripts_main_ts_end=mainscript_end \ - --redefine-sym _binary_scripts_main_ts_size=mainscript_size \ + --redefine-sym _binary_obj_main_ca_start=mainscript_start \ + --redefine-sym _binary_obj_main_ca_end=mainscript_end \ + --redefine-sym _binary_obj_main_ca_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: qemu-system-i386 -serial stdio -kernel kernel diff --git a/scripts/main.spark b/scripts/main.spark new file mode 100644 index 0000000..75d6c59 --- /dev/null +++ b/scripts/main.spark @@ -0,0 +1,29 @@ +.name OS +.author "Felix Queißner" +.descr "The main file of the operating system" + +main: + pushi 0 + + pusht "Hello World from Conductance!\n" + calln print 1 + +_loop: + load 0 + pushi 5 + comp_less + jmp_if_not _end + + load 0 + pushi 1 + add + store 0 + + pusht "counter: " + load 0 + pusht "\n" + calln print 3 + + jmp _loop +_end: + ret diff --git a/scripts/main.ts b/scripts/main.ts deleted file mode 100644 index 06173bc..0000000 --- a/scripts/main.ts +++ /dev/null @@ -1,45 +0,0 @@ -VAR global : INT; - -OBJ timer : "/sys/timer"; -OBJ console : "/sys/console"; - -VAR ptr : PTR(INT); -VAR pptr : PTR(PTR(INT)); - -PUB main() | i : INT, str : TEXT -BEGIN - 0 -> i; - -# Testing pointer referencing / dereferencing as rvalue - 15 -> global; - REF(global) -> ptr; - console.printInt(VAL(ptr)); - -# Testing lvalue pointer assignment - REF(global) -> ptr; - 25 -> VAL(ptr); - console.printInt(global); - -# Testing double pointers - REF(ptr) -> pptr; - 35 -> VAL(VAL(pptr)); - console.printInt(global); - - "Hello " -> str; - console.printStr(str + "World!"); - WHILE ((i + 1) -> i) <= fun() DO - BEGIN - hlp(i, fun() - i); - timer.sleep(2); - END -END - -PRI hlp(i : INT, j : INT) -BEGIN - console.print2Int(i, j); -END - -PUB fun() -> i : INT -BEGIN - 5 -> i; -END diff --git a/src/init.c b/src/init.c index e3d8256..735f954 100644 --- a/src/init.c +++ b/src/init.c @@ -208,6 +208,8 @@ void init(const MultibootStructure *mbHeader) timer_add_callback(1, update_statusbar); + kputs("\n"); + vm_start(); irq_disable(); diff --git a/src/vm.cpp b/src/vm.cpp index c7e67c4..b9cb137 100644 --- a/src/vm.cpp +++ b/src/vm.cpp @@ -69,15 +69,15 @@ void code() struct { const char *ptr; uint32_t size; - } firstrun { - &firstrun_start, - (uint32_t)&firstrun_size + } mainAssembly { + &mainscript_start, + (uint32_t)&mainscript_size }; VirtualMachine vm; vm.import("print") = printArguments; - Assembly *assembly = vm.load(firstrun.ptr, firstrun.size); + Assembly *assembly = vm.load(mainAssembly.ptr, mainAssembly.size); if(assembly == nullptr) { kprintf("failed to load assembly :(\n"); return; diff --git a/trainOS.pro b/trainOS.pro index 387ccfa..3c6db5a 100644 --- a/trainOS.pro +++ b/trainOS.pro @@ -50,9 +50,9 @@ DISTFILES += \ kernel.ld \ Depfile \ Makefile.new \ - scripts/main.ts \ asm/dynamic.S \ - README.md + README.md \ + scripts/main.spark INCLUDEPATH += $$quote("/home/felix/projects/Electronics/Electronics/Conductance") DEPENDPATH += $$quote("/home/felix/projects/Electronics/Electronics/Conductance")