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.
menuentry "isos" {
multiboot2 /boot/kernel.elf64
module2 /boot/test-module.elf64 test-module
- module2 /boot/test-module-2.elf64 test-module-2
}
.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
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<os::paging::page> 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 {
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.");
}
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);
.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
// not, see <https://www.gnu.org/licenses/>.
#include <stddef.h>
+#include <stdint.h>
-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);
}
}
+++ /dev/null
-# Written in 2023 by Amélia COUTARD <eliottulio.coutard@gmail.com>
-# 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 <http://creativecommons.org/publicdomain/zero/1.0/>.
-
-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
+++ /dev/null
-# 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 <https://www.gnu.org/licenses/>.
-
-.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
+++ /dev/null
-// 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 <https://www.gnu.org/licenses/>.
-
-#include <stddef.h>
-
-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]);
- }
-}