out
dep
isodir
-isos.iso
+voyage.iso
Makefile-conf
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
-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 "<fichier>" via "/<fichier>".
+Pour nommer l'enfant <fichier> du répertoire <répertoire>, on utilise "<répertoire>/<fichier>".
+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.
+"<répertoire>/<répertoire-bis>/.." se réfère toujours à "<répertoire>", de manière pûrement lexicale (si tant est que "<répertoire>/<répertoire-bis>" 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 "<wd>/<path>" est un chemin existant.
+ Désormais, "<wd>/<path>" 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.
# 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/>.
-menuentry "isos" {
+menuentry "voyage" {
multiboot2 /boot/kernel.elf64
module2 /boot/test-module.elf64 test-module
}
# 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.
#
// 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.
//
// 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.
//
# 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.
#
// 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.
//
// 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.
//
// 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.
//
# 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.
#
# 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.
#
// 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.
//
// 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.
//
// 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.
//
// 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.
//
# 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.
#
.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
// 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.
//
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.");
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::process>& os::processes = *reinterpret_cast<os::incrementing_int64_map<os::process>*>(0xFFFF'C000'0000'0000);
// 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.
//
// 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.
//
// 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.
//
// 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.
//
// 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.
//
# 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.
#
.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
// 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.
//
#include <stdint.h>
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];
}
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();
}