From: Amelia Coutard Date: Fri, 15 Dec 2023 08:26:31 +0000 (+0100) Subject: Impérialisme linguistique + changement d'API future pour les fichiers X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=250b12203b8950ffe5482b74cc88a7306ec41289;p=voyage-au-centre-des-fichiers.git Impérialisme linguistique + changement d'API future pour les fichiers --- diff --git a/.gitignore b/.gitignore index 064c840..2dcf464 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ out dep isodir -isos.iso +voyage.iso Makefile-conf diff --git a/Makefile b/Makefile index cbcd462..176525e 100644 --- a/Makefile +++ b/Makefile @@ -20,20 +20,20 @@ LDFLAGS ?= -O2 LDFLAGS := $(LDFLAGS) -std=c++20 -Wall -Wextra -Werror -ffreestanding TO_ISO := isodir/boot/grub/grub.cfg -TO_CLEAN := isodir isos.iso +TO_CLEAN := isodir voyage.iso include **/module.mk -build: isos.iso +build: voyage.iso qemu: build - qemu-system-x86_64 -cdrom isos.iso -serial stdio -cpu qemu64,pdpe1gb -no-reboot -m 4096 $(QEMUFLAGS) + qemu-system-x86_64 -cdrom voyage.iso -serial stdio -cpu qemu64,pdpe1gb -no-reboot -m 4096 $(QEMUFLAGS) check: clean: -rm -rf $(TO_CLEAN) install: - install -D isos.iso -t "$(PREFIX)" + install -D voyage.iso -t "$(PREFIX)" -isos.iso: $(TO_ISO) +voyage.iso: $(TO_ISO) grub-mkrescue -o "$@" isodir isodir/boot/grub/grub.cfg: grub.cfg diff --git a/doc.txt b/doc.txt index cd179c8..3c96515 100644 --- a/doc.txt +++ b/doc.txt @@ -1,79 +1,101 @@ -isos documentation: -"isos" means "Incompatible System from Outer Space". -(Also, "Is Operating System". The double meaning is funny.) +Documentation de "voyage au centre des fichiers" (ci-après, nommé simplement "voyage"). +Voyage est un projet de μ-noyau (et d'espace utilisateur associé) inspiré de *Plan 9 From Bell Labs* et de l'*Incompatible Time-Sharing System*. --------------------------- -(Virtual) memory map: +Agencement de la mémoire (virtuelle): -0000'0000'0000'0000 ↔ 0000'0000'0000'1000 - unmapped: 4KiB ensure that NULL causes a page fault if accessed. -0000'0000'0000'1000 ↔ 0000'0010'0000'0000 - program segments (.text, .data, .bss, etc.): 64GiB - 4KiB -0000'0010'0000'1000 ↔ 0000'7FFF'FFFF'0000 - heap: 128TiB - 64GiB - 64KiB -0000'7FFF'FFFF'0000 ↔ 0000'8000'0000'0000 - stack: 64KiB --- Invalid addresses -- -FFFF'8000'0000'0000 ↔ FFFF'C000'0000'0000 - physical memory: 64TiB -FFFF'C000'0000'0000 ↔ FFFF'FFFF'8000'0000 - process information tables: - open file descriptors, namespaces, etc. -FFFF'FFFF'8000'0000 ↔10000'0000'0000'0000 - kernel: 2GiB +0000'0000'0000'0000 ↔ 0000'0000'0000'1000 - Rien, pour assurer les programmes que nullptr n'est jamais une adresse valide. (4Kio) +0000'0000'0000'1000 ↔ 0000'0010'0000'0000 - Les différents segments de l'exécutable. (~64 Gio) +0000'0010'0000'1000 ↔ 0000'7FFF'FFFF'0000 - Tas de mémoire. (~128 Tio) +0000'7FFF'FFFF'0000 ↔ 0000'8000'0000'0000 - Pile d'exécution. (64 Kio) +-- Adresses non-canoniques -- +FFFF'8000'0000'0000 ↔ FFFF'C000'0000'0000 - Représentation de l'entièreté de la mémoire physique. (64 Tio) +FFFF'C000'0000'0000 ↔ FFFF'FFFF'8000'0000 - Tables d'information des processus, et autre ressources stockées dans le noyau. (~64 Tio) +FFFF'FFFF'8000'0000 ↔10000'0000'0000'0000 - Noyau. (2 Gio) --------------------------- -All the IPC is handled via many, many files. -Also, a filename must be a sequence of non-0, non-\n, non-control-character, legal utf-8 codepoints. -A directory will, for the purposes of system calls that operate on file contents, appear as a read-only - file containing each of the file names of its contents, each file name followed by a single \n. -At boot, the first module gets access to a special filesystem, that only it has access to. - - /serial: R/W, serial I/O -All the other modules get only a single open file, corresponding to the file system exposed by the first module's process. +Principes de base: +Tout processus a une vue du système de fichiers. +Ce système de fichier est composé de deux types de fichiers: + - Les fichiers simples, qui contiennent des octets. + - Les répertoires, qui contiennent d'autres fichiers. +Il y a un répertoire racine, nommé "/", dont on accède à l'enfant "" via "/". +Pour nommer l'enfant du répertoire , on utilise "/". +Un chemin est soit absolu (commence par un slash), et ne dépend pas du répertoire spécifié dans l'appel au système qui l'utilise, +soit relatif (ne commence pas par un slash), auquel cas on considère le premier nom du chemin comme étant l'enfant du répertoire spécifié dans l'appel. +Le chemin "" est un chemin relatif qui désigne le répertoire spécifié dans l'appel. +"//.." se réfère toujours à "", de manière pûrement lexicale (si tant est que "/" existe). +"/.." se réfère à "/". + +Quand un fichier est ouvert, un descripteur lui est assigné. +Ce descripteur stocke un indice qui correspond à la position courante dans le fichier. --------------------------- -Data types: +Types de données: -fd_t = int64_t; // Client-side file (or directory) descriptor. +fd_t = int64_t; // Descripteur de fichier ouvert. --------------------------- -The system calls: +Les appels au système: -Input registers in order: %rdi, %rsi, %rdx, %r10, %r8, %r9. -In %rax, the syscall id is specified. -If the operation succeeds, %rax contains the result (think SystemV ABI) (≥ 0). If it fails, %rax contains -1. -The only registers clobbered are %rcx, %r11, and %rax. +L'instruction `syscall` est utilisée. +Les arguments sont placées dans l'ordre %rdi, %rsi, %rdx, %r10, %r8, %r9. +L'appel au système a effectuer est spécifié dans %rax. +Si l'appel réussi, %rax contient le résultat (≥ 0). Sinon, %rax contient -1. +Tous les registres sont préservés, sauf %rcx, %r11 et (évidemment) %rax. enum open_options { - MODE_RO = 0x1 - MODE_WO = 0x2 - MODE_RW = MODE_RO | MODE_WO + MODE_READ = 0x1 + MODE_WRITE = 0x2 MODE_DIRECTORY = 0x4 OPTION_INPLACE = 0x8 }; -fd_t open(fd_t wd, char const path[path_len], ssize_t path_len, open_options options /* See enum above. */); - Options must be one of ro, wo or rw, |-ed with any (including multiple) of MODE_DIRECTORY and OPTION_INPLACE - Try to open path, relative to wd. - If path is absolute, wd can actually not be an open file (but it still needs to be >= 0, for in_place to work). - If OPTION_INPLACE, makes wd point to the opened file/folder in case of success, and return wd. - If not, doesn't change wd, and returns a new fd pointing to the opened file/folder. - If MODE_DIRECTORY, open fails if path refers to a non-directory file. - If not, open fails if path refers to a directory. - When open fails, it returns -1 (as all syscalls) and the program continues as though open was never called. +ssize_t mount_kernel_device(fd_t wd, char device, char const path[path_len], ssize_t path_len); + %rax = 0 + Essaye de monter le système de fichier noyau au chemin path. + Ne fonctionne que si "/" est un chemin existant. + Désormais, "/" ne se réfère plus a son ancien usage, mais uniquement au système monté. + Retourne -1 si wd n'existe pas et que le chemin est relatif, ou si path n'existe pas, ou si device n'existe pas. + Alors l'arbre de fichiers du processus n'est pas modifié. + Sinon, retourne 0. + Alors l'arbre de fichiers du processus est modifié comme spécifié. + +fd_t open(fd_t wd, char const path[path_len], ssize_t path_len, open_options options); + %rax = 1 + Si path est un chemin relatif, il est relatif à wd. + Sinon, wd n'a pas besoin d'être un fd ouvert, ou même un numéro de fd valide. + Les options doivent être un ou binaire des open_options, incluant au moins MODE_READ ou MODE_WRITE. + Si MODE_READ est spécifié, le fichier est ouvert avec la permission de lecture. + Si MODE_WRITE est spécifié, le fichier est ouvert avec la permission d'écriture. + Si MODE_DIRECTORY est spécifié, le fichier est ouvert seulement s'il s'agit d'un répertoire. + Sinon, il est ouvert seulement s'il est un fichier simple. + Si OPTION_INPLACE est spécifiée, en cas de réussite d'ouverture, wd réfère maintenant au fichier ouvert (et wd est fermé s'il se référait déjà à un fichier ouvert). + Sinon, en cas de réussite d'ouverture, wd est toujours valide et un nouveau desccripteur est choisi par le système pour le fichier. + En cas de réussite, la fonction retourne le descripteur du fichier ouvert. + Sinon, elle retourne -1. 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. + %rax = 2 + Essaye de lire au plus len octets à la position courante de file. + Mets la position courante à l'octet suivant le dernier octet lu. + Stocke les octets lus dans data. + Retourne -1 en cas d'échec, sinon retourne le nombre d'octets lus. 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. + %rax = 3 + Essaye d'écrire au plus len octets à la position courante de file. + Mets la position courante à l'octet suivant le dernier octet écrit. + Lis les octets à écrire dans data. + Retourne -1 en cas d'échec, sinon retourne le nombre d'octets écrits. ssize_t close(fd_t file); - Termine the fd `file`. If there were no other copies of it, the corresponding file is closed. - Returns -1 if `file` isn't an opened file descriptor. - -ssize_t fseek(fd_t file, ssize_t offset, int from); - If from is 0, seek offset bytes from start. - If from is 1, seek offset bytes from current file position. - If from is 2, seek offset bytes from end of file. - In the case of non-seekable files (i.e. pipes 'n shit), this is a noop. - Returns the new file position, in bytes from the start. + %rax = 4 + Ferme le fichier correspondant à file: file n'est maintenant plus un descripteur ouvert. + Même en cas d'échec, file n'est plus ouvert. + Retourne -1 si file n'est pas un descripteur ouvert, ou en cas d'échec autre de la fermeture. + Retourne 0 en cas de réussite. diff --git a/grub.cfg b/grub.cfg index 6dc976b..fba8c8a 100644 --- a/grub.cfg +++ b/grub.cfg @@ -5,7 +5,7 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -menuentry "isos" { +menuentry "voyage" { multiboot2 /boot/kernel.elf64 module2 /boot/test-module.elf64 test-module } diff --git a/kernel/src/boot.S b/kernel/src/boot.S index 279767a..8d6c3c2 100644 --- a/kernel/src/boot.S +++ b/kernel/src/boot.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index d5acce1..e4de1cd 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/elf64.hpp b/kernel/src/elf64.hpp index 19d5d13..6136338 100644 --- a/kernel/src/elf64.hpp +++ b/kernel/src/elf64.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/interrupts.S b/kernel/src/interrupts.S index 2259e3c..085ca7e 100644 --- a/kernel/src/interrupts.S +++ b/kernel/src/interrupts.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # diff --git a/kernel/src/interrupts.cpp b/kernel/src/interrupts.cpp index 0af446a..028a672 100644 --- a/kernel/src/interrupts.cpp +++ b/kernel/src/interrupts.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index 93fae7f..d8a3590 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 857766a..cc4d0c1 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/lib/crti.S b/kernel/src/lib/crti.S index 0038611..b467d0c 100644 --- a/kernel/src/lib/crti.S +++ b/kernel/src/lib/crti.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # diff --git a/kernel/src/lib/crtn.S b/kernel/src/lib/crtn.S index 36327e6..e93bbe4 100644 --- a/kernel/src/lib/crtn.S +++ b/kernel/src/lib/crtn.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # diff --git a/kernel/src/lib/multiboot2.hpp b/kernel/src/lib/multiboot2.hpp index bb196f4..8553ec9 100644 --- a/kernel/src/lib/multiboot2.hpp +++ b/kernel/src/lib/multiboot2.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/lib/phys_ptr.hpp b/kernel/src/lib/phys_ptr.hpp index 10d16b2..286b96d 100644 --- a/kernel/src/lib/phys_ptr.hpp +++ b/kernel/src/lib/phys_ptr.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index f752858..38a65e6 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index 6fba85f..a5d4237 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/ring3.S b/kernel/src/ring3.S index fb5f837..c73e9c4 100644 --- a/kernel/src/ring3.S +++ b/kernel/src/ring3.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # @@ -89,11 +89,11 @@ incorrect_syscall: .section .rodata syscalls_call_table: + .quad syscall_mount_kernel_device .quad syscall_open .quad syscall_read .quad syscall_write .quad syscall_close - .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 11e6746..2c458a8 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // @@ -49,6 +49,12 @@ void schedule_next_process() { os::paging::load_pml4t(os::processes.get(os::current_pid).PML4T); } +// extern "C" std::int64_t syscall_mount_kernel_device(std::int64_t wd, char device, char const* path, std::int64_t path_len) { +extern "C" std::int64_t syscall_mount_kernel_device(std::int64_t, char, char const*, std::int64_t) { + os::assert(false, "mount_kernel_device not implemented yet."); + __builtin_unreachable(); +} + // 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."); @@ -97,14 +103,9 @@ extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std:: return len; } -// 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."); + __builtin_unreachable(); } os::incrementing_int64_map& os::processes = *reinterpret_cast*>(0xFFFF'C000'0000'0000); diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index 8ef65d4..4d6bbb0 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index abc05e8..3d14b1a 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/serial.hpp b/kernel/src/serial.hpp index 56c4ef9..56ed9d0 100644 --- a/kernel/src/serial.hpp +++ b/kernel/src/serial.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index d1b997b..4643a27 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index 83baa58..df82e9a 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // diff --git a/test_module/src/test.S b/test_module/src/test.S index 2d326b2..863f1b7 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -1,6 +1,6 @@ # Copyright 2023 Amélia COUTARD. # -# This file from the program isos is free software: you can redistribute it and/or modify it +# This file from the program "voyage au centre des fichiers" 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. # @@ -13,33 +13,34 @@ .section .text +.globl mount_kernel_device +mount_kernel_device: + mov %rcx, %r10 + mov $0, %rax + syscall + ret + .globl open open: mov %rcx, %r10 - mov $0, %rax + mov $1, %rax syscall ret .globl read read: - mov $1, %rax + mov $2, %rax syscall ret .globl write write: - mov $2, %rax + mov $3, %rax syscall ret .globl close close: - mov $3, %rax - syscall - ret - -.globl fseek -fseek: mov $4, %rax syscall ret diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index 14a0df2..62a3576 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -1,6 +1,6 @@ // Copyright 2023 Amélia COUTARD. // -// This file from the program isos is free software: you can redistribute it and/or modify it +// This file from the program "voyage au centre des fichiers" 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. // @@ -15,25 +15,27 @@ #include enum open_options { - MODE_RO = 0x1, - MODE_WO = 0x2, - MODE_RW = MODE_RO | MODE_WO, + MODE_READ = 0x1, + MODE_WRITE = 0x2, MODE_DIRECTORY = 0x4, OPTION_INPLACE = 0x8, }; namespace sys { +extern "C" int64_t mount_kernel_device(int64_t wd, char device, char const* path, int64_t path_len); extern "C" int64_t open(int64_t wd, char const* path, int64_t path_len, open_options 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 close(int64_t file); -extern "C" int64_t fseek(int64_t file, int64_t offset, int from); } // namespace sys +void loop_de_loop() { + loop_de_loop(); +} + extern "C" void _start() { - const int64_t wd = sys::open(0, "/", 1, open_options(MODE_RW | OPTION_INPLACE | MODE_DIRECTORY)); - const int64_t serial = sys::open(wd, "serial", 1, MODE_RW); - const int64_t serial_ = sys::open(wd, "/serial", 1, MODE_WO); + sys::mount_kernel_device(-1, 'I', "/", 1); // 'I' is the I/O device. /serial is the serial port /fb is the framebuffer + const int64_t serial = sys::open(-1, "/serial", 7, MODE_WRITE); sys::write(serial, "Entrez votre nom: ", 18); char data[32]; @@ -50,14 +52,10 @@ extern "C" void _start() { } read += read_this_time; } while (read_this_time != 0 && read < 32 && data[read - 1] != '\r'); - sys::write(serial_, "Bonjour, ", 9); - sys::write(serial_, data, read - (data[read - 1] == '\r' ? 1 : 0)); - sys::write(serial_, ".\n", 2); + sys::write(serial, "Bonjour, ", 9); + sys::write(serial, data, read - (data[read - 1] == '\r' ? 1 : 0)); + sys::write(serial, ".\n", 2); sys::close(serial); - sys::close(serial_); - - while (true) { - sys::fseek(0, 0, 1); - } + loop_de_loop(); }