From: Amelia Coutard Date: Mon, 27 Nov 2023 00:15:34 +0000 (+0100) Subject: Got ready to implement the first 4 syscalls, though, like, that's not done just yet X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=ccd6c41667bb37b9ad495cffee6a80a4492075df;p=voyage-au-centre-des-fichiers.git Got ready to implement the first 4 syscalls, though, like, that's not done just yet --- diff --git a/doc.txt b/doc.txt index 2c6622e..2eb0be8 100644 --- a/doc.txt +++ b/doc.txt @@ -63,7 +63,7 @@ ssize_t read(fd_t file, char data[len], ssize_t len); Read up to len characters from file. Return the number of actually read characters, or -1 on error. -ssize_t write(fd_t file, char data[len], ssize_t len); +ssize_t write(fd_t file, char const data[len], ssize_t len); Write up to len characters to file. Return the number of actually written characters, or -1 on error. diff --git a/grub.cfg b/grub.cfg index f71586a..6dc976b 100644 --- a/grub.cfg +++ b/grub.cfg @@ -8,5 +8,4 @@ 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/ring3.S b/kernel/src/ring3.S index 4bb41c7..8e8fbcc 100644 --- a/kernel/src/ring3.S +++ b/kernel/src/ring3.S @@ -89,9 +89,10 @@ incorrect_syscall: .section .rodata syscalls_call_table: - .quad syscall_print - .quad syscall_print_low_mmap - .quad syscall_yield + .quad syscall_open + .quad syscall_read + .quad syscall_write + .quad syscall_fseek syscalls_call_table_end: .set syscall_n, (syscalls_call_table_end - syscalls_call_table) >> 3 # Because / 8 *doesn't work* ! .globl syscall_n diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index f4aeca2..0381358 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -40,27 +40,7 @@ void os::enable_syscalls() { os::set_msr(0xC0000084, 0x00000000); // syscall flag mask, we don't want to change the flags for now. } -extern "C" void os::syscall_print(char v) { - os::printc(v); -} - -extern "C" void os::syscall_print_low_mmap() { - os::paging::on_all_pages(*get_process(current_pid).PML4T, - [](os::paging::page* vaddr, os::phys_ptr paddr, std::size_t page_size_in_bytes) { - if (std::size_t(vaddr) < 128ul * 1024 * 1024 * 1024 * 1024) { // Lower half: - if (std::size_t(vaddr) < 0x10'0000'0000) { - os::print("segments:"); - } else if (std::size_t(vaddr) < 0x7FFF'FFFF'0000) { - os::print("heap: "); - } else { - os::print("stack: "); - } - os::print(" {} -> {} ({}B)\n", vaddr, paddr, page_size_in_bytes); - } - }); -} - -extern "C" void os::syscall_yield() { +void schedule_next_process() { if (os::processes.present(os::current_pid + 1)) { os::current_pid += 1; } else { @@ -69,6 +49,30 @@ extern "C" void os::syscall_yield() { os::paging::load_pml4t(os::processes.get(os::current_pid).PML4T); } +// extern "C" std::int64_t syscall_open(std::int64_t wd, char const* path, std::int64_t path_len, int options) { +extern "C" std::int64_t syscall_open(std::int64_t, char const*, std::int64_t, int) { + os::assert(false, "open not implemented yet."); + __builtin_unreachable(); +} + +// extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t len) { +extern "C" std::int64_t syscall_read(std::int64_t, char*, std::int64_t) { + os::assert(false, "read not implemented yet."); + __builtin_unreachable(); +} + +// extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) { +extern "C" std::int64_t syscall_write(std::int64_t, char const*, std::int64_t) { + os::assert(false, "write not implemented yet."); + __builtin_unreachable(); +} + +// extern "C" std::int64_t syscall_fseek(std::int64_t file, std::int64_t offset, int from) { +extern "C" std::int64_t syscall_fseek(std::int64_t, std::int64_t, int) { + os::assert(false, "fseek not implemented yet."); + __builtin_unreachable(); +} + extern "C" void os::syscall_rax_error_handler() { os::assert(false, "Incorrect %rax for syscall."); } diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index a66f902..8ef65d4 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -44,9 +44,10 @@ void run_first_process(std::int64_t pid); extern "C" void load_tss(); extern "C" void syscall_64bit_handler(); -extern "C" void syscall_print(char c); -extern "C" void syscall_print_low_mmap(); -extern "C" void syscall_yield(); +extern "C" std::int64_t syscall_open(std::int64_t wd, char const* path, std::int64_t path_len, int options); +extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t len); +extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len); +extern "C" std::int64_t syscall_fseek(std::int64_t file, std::int64_t offset, int from); extern "C" void syscall_rax_error_handler(); void set_ring0_stack(tss& tss, std::uint64_t stack); diff --git a/test_module/src/test.S b/test_module/src/test.S index 348de63..8635763 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -13,20 +13,27 @@ .section .text -.globl print -print: +.globl open +open: + mov %rcx, %r10 mov $0, %rax syscall ret -.globl check_mem -check_mem: +.globl read +read: mov $1, %rax syscall ret -.globl yield -yield: +.globl write +write: mov $2, %rax syscall ret + +.globl fseek +fseek: + mov $3, %rax + syscall + ret diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index b2973ec..1be50ee 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -12,25 +12,15 @@ // not, see . #include +#include -extern "C" void print(char c); -extern "C" void check_mem(); -extern "C" void yield(); - -void printstr(const char* str) { - for (size_t i = 0; str[i] != '\0'; i++) { - print(str[i]); - } -} +extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, int options); +extern "C" int64_t read(int64_t file, char* data, int64_t len); +extern "C" int64_t write(int64_t file, char const* data, int64_t len); +extern "C" int64_t fseek(int64_t file, int64_t offset, int from); extern "C" void _start() { - printstr("Mem prg 1:\n"); - check_mem(); - printstr("Done.\n"); - printstr("Prg 1.\n"); - while (true) { - yield(); - // printstr("Prg 1 again.\n"); + fseek(0, 0, 1); } } diff --git a/test_module_2/module.mk b/test_module_2/module.mk deleted file mode 100644 index 159547f..0000000 --- a/test_module_2/module.mk +++ /dev/null @@ -1,46 +0,0 @@ -# Written in 2023 by Amélia COUTARD -# 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 . - -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_CXX := g++-user -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): CXX := $(LOCAL_CXX) -$(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: CXX := $(LOCAL_CXX) -$(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 deleted file mode 100644 index 348de63..0000000 --- a/test_module_2/src/test.S +++ /dev/null @@ -1,32 +0,0 @@ -# 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 deleted file mode 100644 index 7eeb486..0000000 --- a/test_module_2/src/test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// 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]); - } -}