From: Amelia Coutard Date: Sun, 6 Aug 2023 01:54:28 +0000 (+0200) Subject: Added support for multiple startup modules, and a second module to test yield better X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=9493ea8dfaa584841004df62ef8e3ed092ed7b44;p=voyage-au-centre-des-fichiers.git Added support for multiple startup modules, and a second module to test yield better --- diff --git a/grub.cfg b/grub.cfg index d008406..fee1476 100644 --- a/grub.cfg +++ b/grub.cfg @@ -11,4 +11,5 @@ menuentry "isos" { multiboot2 /boot/kernel.elf64 module2 /boot/test-module.elf64 test-module + module2 /boot/test-module-2.elf64 test-module-2 } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index e467397..a0e47ef 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -41,6 +41,46 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(PDPT_alloc.ptr.get_phys_addr())); } - os::paging::setup_page(PML4T, (void*)0xFFFF'C000'0000'0000, 1, 0); // The startup module. - std::int64_t module_process = os::processes.create(); - { struct { os::phys_ptr start_address = nullptr; @@ -83,9 +120,8 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr{}: {}\n", multiboot2::modules_mod_start(it), multiboot2::modules_mod_end(it), multiboot2::modules_string(it)); - os::assert(!module_specified, "Multiple modules specified in the multiboot. This is unsupported."); module_specified = true; - os::elf::load_elf(os::get_process(module_process), + os::elf::load_elf(os::get_process(os::processes.create()), (std::byte*)multiboot2::modules_mod_start(it), multiboot2::modules_mod_end(it) - multiboot2::modules_mod_start(it), PML4T); @@ -142,46 +178,6 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(get_base_address(PML4T.contents[0]).get_phys_addr()), .size = 1}); @@ -195,5 +191,5 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr +# To the extent possible under law, the author(s) have dedicated all copyright +# and related and neighboring rights to this file to the public domain worldwide. +# This file is distributed without any warranty. +# You should have received a copy of the CC0 Public Domain Dedication along with +# this file. If not, see . + +# So, about the license. I don't think I have a copyright on this file's code, but, +# since I gave it the CC0 license in case I do, that doesn't matter either way. + +SRC_DIR := test_module_2/src/ +OUT_DIR := test_module_2/out/ +DEP_DIR := test_module_2/dep/ +EXEC_NAME := test-module-2.elf64 + +TO_ISO += isodir/boot/$(EXEC_NAME) +TO_CLEAN += $(OUT_DIR) $(DEP_DIR) + +LOCAL_CXXFLAGS := $(CXXFLAGS) +LOCAL_LDFLAGS := $(LDFLAGS) + +CPPSRCS := $(shell find $(SRC_DIR) -name '*.cpp') +CPPOBJS := $(CPPSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o) +ASMSRCS := $(shell find $(SRC_DIR) -name '*.S') +ASMOBJS := $(ASMSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o) +OBJS := $(CPPOBJS) $(ASMOBJS) + +isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME) + mkdir -p "$(@D)" + install -m 644 "$<" "$@" + +$(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS) +$(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc +$(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LOCAL_LDFLAGS) +$(OUT_DIR)$(EXEC_NAME): $(OBJS) + mkdir -p "$(@D)" + $(CXX) $(LDFLAGS) -o "$@" $+ $(LDLIBS) + +$(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR) +$(OUT_DIR)%.o: CXXFLAGS := $(LOCAL_CXXFLAGS) +$(OUT_DIR)%.o: $(SRC_DIR)% + mkdir -p $(@D) + mkdir -p $(dir $(DEP_DIR)$*) + $(CXX) $(CXXFLAGS) -c "$<" -MMD -MT "$@" -MF "$(DEP_DIR)$*.d" -o "$@" + +-include $(DEP_DIR)*.d diff --git a/test_module_2/src/test.S b/test_module_2/src/test.S new file mode 100644 index 0000000..348de63 --- /dev/null +++ b/test_module_2/src/test.S @@ -0,0 +1,32 @@ +# Copyright 2023 Amélia COUTARD. +# +# This file from the program isos is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free Software Foundation, +# either version 3 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +# without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +# PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program. If +# not, see . + +.section .text + +.globl print +print: + mov $0, %rax + syscall + ret + +.globl check_mem +check_mem: + mov $1, %rax + syscall + ret + +.globl yield +yield: + mov $2, %rax + syscall + ret diff --git a/test_module_2/src/test.cpp b/test_module_2/src/test.cpp new file mode 100644 index 0000000..f4d1791 --- /dev/null +++ b/test_module_2/src/test.cpp @@ -0,0 +1,38 @@ +// Copyright 2023 Amélia COUTARD. +// +// This file from the program isos is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free Software Foundation, +// either version 3 of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with this program. If +// not, see . + +#include + +extern "C" void print(char c); +extern "C" void check_mem(); +extern "C" void yield(); + +void printstr(const char* str); + +extern "C" void _start() { + printstr("Mem program 2:\n"); + check_mem(); + printstr("Done.\n"); + printstr("Prog 2.\n"); + + while (true) { + yield(); + printstr("Prog 2 again.\n"); + } +} + +void printstr(const char* str) { + for (size_t i = 0; str[i] != '\0'; i++) { + print(str[i]); + } +}