From e44101b9d4e971fa4516fb89a0731b587862faf2 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Thu, 21 Dec 2023 22:44:26 +0100 Subject: [PATCH 01/16] =?utf8?q?Pr=C3=A9cisions=20sur=20les=20fichiers=20e?= =?utf8?q?t=20leur=20noms?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- doc.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc.txt b/doc.txt index 59ef402..0e7324c 100644 --- a/doc.txt +++ b/doc.txt @@ -18,10 +18,11 @@ FFFF'FFFF'8000'0000 ↔10000'0000'0000'0000 - Noyau. (2 Gio) Principes de base: Tout processus a une vue du système de fichiers. +Un nom de fichier est composé d'une séquence de points de code UTF-8 valides, excepté ceux de 0 à 31 inclus. Ce système de fichier est composé de deux types de fichiers: - Les fichiers simples, qui contiennent des octets. On dit d'un fichier simple qu'il est un fichier texte s'il est composé uniquement de 0, 1, ou plusieurs lignes. - Une ligne est une séquence de caractères UTF-8 valides, suivie d'un \n. + Une ligne est une séquence de points de code UTF-8 valides, suivie d'un \n. Tout fichier texte se termine donc par un \n. - Les répertoires, qui contiennent d'autres fichiers. Il y a un répertoire racine, nommé "/", dont on accède à l'enfant "" via "/". -- 2.47.0 From 310aa826f8051221e03749f62b8d6430f4437e50 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Fri, 22 Dec 2023 12:12:05 +0100 Subject: [PATCH 02/16] Changement de styles de commentaires pour les fichiers en assembleur --- kernel/src/boot.S | 170 ++++++++++++++++++++-------------------- kernel/src/interrupts.S | 24 +++--- kernel/src/lib/crti.S | 24 +++--- kernel/src/lib/crtn.S | 24 +++--- kernel/src/ring3.S | 64 +++++++-------- test_module/src/test.S | 24 +++--- 6 files changed, 165 insertions(+), 165 deletions(-) diff --git a/kernel/src/boot.S b/kernel/src/boot.S index 8d6c3c2..3dfa906 100644 --- a/kernel/src/boot.S +++ b/kernel/src/boot.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 "lib/multiboot2.hpp" @@ -47,43 +47,43 @@ GDT: .set GDT.NULL, . - GDT .quad 0 .set GDT.KERNEL_DATA, . - GDT - .short 0xFFFF # Limit[0:16] - .short 0x0000 # Base[0:16] - .byte 0x00 # Base[16:24] - .byte 0b10010010 # Access: present | writeable | ring0 - .byte 0b11001111 # Flags: page_gran | d_b, Limit[16:20] - .byte 0x00 # Base[24:32] + .short 0xFFFF // Limit[0:16] + .short 0x0000 // Base[0:16] + .byte 0x00 // Base[16:24] + .byte 0b10010010 // Access: present | writeable | ring0 + .byte 0b11001111 // Flags: page_gran | d_b, Limit[16:20] + .byte 0x00 // Base[24:32] .set GDT.KERNEL_CODE, . - GDT - .short 0xFFFF # Limit[0:16] - .short 0x0000 # Base[0:16] - .byte 0x00 # Base[16:24] - .byte 0b10011010 # Access: present | readable | ring0 - .byte 0b10101111 # Flags: page_gran | long_mode, Limit[16:20] - .byte 0x00 # Base[24:32] + .short 0xFFFF // Limit[0:16] + .short 0x0000 // Base[0:16] + .byte 0x00 // Base[16:24] + .byte 0b10011010 // Access: present | readable | ring0 + .byte 0b10101111 // Flags: page_gran | long_mode, Limit[16:20] + .byte 0x00 // Base[24:32] .set GDT.USER_DATA, . - GDT - .short 0xFFFF # Limit[0:16] - .short 0x0000 # Base[0:16] - .byte 0x00 # Base[16:24] - .byte 0b11110010 # Access: present | writeable | ring3 - .byte 0b11001111 # Flags: page_gran | d_b, Limit[16:20] - .byte 0x00 # Base[24:32] + .short 0xFFFF // Limit[0:16] + .short 0x0000 // Base[0:16] + .byte 0x00 // Base[16:24] + .byte 0b11110010 // Access: present | writeable | ring3 + .byte 0b11001111 // Flags: page_gran | d_b, Limit[16:20] + .byte 0x00 // Base[24:32] .set GDT.USER_CODE, . - GDT - .short 0xFFFF # Limit[0:16] - .short 0x0000 # Base[0:16] - .byte 0x00 # Base[16:24] - .byte 0b11111010 # Access: present | readable | ring3 - .byte 0b10101111 # Flags: page_gran | long_mode, Limit[16:20] - .byte 0x00 # Base[24:32] + .short 0xFFFF // Limit[0:16] + .short 0x0000 // Base[0:16] + .byte 0x00 // Base[16:24] + .byte 0b11111010 // Access: present | readable | ring3 + .byte 0b10101111 // Flags: page_gran | long_mode, Limit[16:20] + .byte 0x00 // Base[24:32] .globl GDT.TSS .set GDT.TSS, . - GDT - .short (TSS_SIZE - 1) & 0xFFFF # Limit[0:16] - .short 0x0000 # Base[0:16] # TSS & 0xFFFF - .byte 0x00 # Base[16:24] # (TSS >> 16) & 0xFF - .byte 0b10001001 # Access - .byte (0b0000 << 4) | (((TSS_SIZE - 1) >> 16) & 0xF) # Flags, Limit[16:20] - .byte 0x00 # Base[24:32] # (TSS >> 24) & 0xFF - .int 0 # Base[32:63] # (TSS >> 32) & 0xFFFFFFFF - .int 0 # reserved + .short (TSS_SIZE - 1) & 0xFFFF // Limit[0:16] + .short 0x0000 // Base[0:16] // TSS & 0xFFFF + .byte 0x00 // Base[16:24] // (TSS >> 16) & 0xFF + .byte 0b10001001 // Access + .byte (0b0000 << 4) | (((TSS_SIZE - 1) >> 16) & 0xF) // Flags, Limit[16:20] + .byte 0x00 // Base[24:32] // (TSS >> 24) & 0xFF + .int 0 // Base[32:63] // (TSS >> 32) & 0xFFFFFFFF + .int 0 // reserved GDT.PTR: .short . - GDT - 1 .quad GDT - KERNEL_VMA @@ -116,10 +116,10 @@ old_PML4T: PML4T: .quad PDPT_low - KERNEL_VMA + 3 .skip 0x1000 - 16 .quad PDPT_high - KERNEL_VMA + 3 -PDPT_low: .quad 0x83 # 1GiB page | R/W | P +PDPT_low: .quad 0x83 // 1GiB page | R/W | P .skip 0x1000 - 8 PDPT_high: .skip 0x1000 - 16 - .quad 0x183 # G | 1GiB page | R/W | P + .quad 0x183 // G | 1GiB page | R/W | P .quad 0x183 + 1024 * 1024 * 1024 .section .bss @@ -127,11 +127,11 @@ PDPT_high: .skip 0x1000 - 16 phys_mem_map: .skip 0x1000 * 128 - 8 .align 16 stack_bottom: -.skip 4096 * 4 # 16KiB +.skip 4096 * 4 // 16KiB .globl stack_top stack_top: interrupt_stack_bottom: -.skip 4096 * 4 # 16KiB +.skip 4096 * 4 // 16KiB .globl interrupt_stack_top interrupt_stack_top: @@ -153,22 +153,22 @@ check_cpuid_support: push %ecx popfl xor %ecx, %eax - jz halt # No cpuid. + jz halt // No cpuid. ret check_long_mode_support: mov $0x80000000, %eax cpuid cmp $0x80000001, %eax - jb halt # No ability to check for long mode. + jb halt // No ability to check for long mode. mov $0x80000001, %eax cpuid - # Long mode: + // Long mode: test $1 << 29, %edx - jz halt # No long mode. - # 1GiB pages: + jz halt // No long mode. + // 1GiB pages: test $1 << 26, %edx - jz halt # No 1GiB pages. + jz halt // No 1GiB pages. ret .globl _start @@ -176,43 +176,43 @@ _start: cli mov $stack_top - KERNEL_VMA, %esp - # Save multiboot info: - push $0 # / - push %eax # \ magic - push $0 # / - push %ebx # \ info structure + // Save multiboot info: + push $0 // / + push %eax // \ magic + push $0 // / + push %ebx // \ info structure call check_cpuid_support call check_long_mode_support - # Disable 32-bit paging: + // Disable 32-bit paging: mov %cr0, %eax and $~(1 << 31), %eax mov %eax, %cr0 - # Setup 64-bit paging: + // Setup 64-bit paging: mov $PML4T - KERNEL_VMA, %eax - or $0x10, %eax # NO CACHE + or $0x10, %eax // NO CACHE mov %eax, %cr3 - # Enable PAE paging, and global pages: + // Enable PAE paging, and global pages: mov %cr4, %eax - or $1 << 5, %eax # PAE - or $1 << 7, %eax # PGE + or $1 << 5, %eax // PAE + or $1 << 7, %eax // PGE mov %eax, %cr4 - # Set long mode bit (and NXE): + // Set long mode bit (and NXE): mov $0xC0000080, %ecx rdmsr or $1 << 8, %eax or $1 << 11, %eax wrmsr - # Enable paging: + // Enable paging: mov %cr0, %eax or $1 << 31, %eax mov %eax, %cr0 - # Jump to 64 bits: + // Jump to 64 bits: lgdt GDT.PTR - KERNEL_VMA jmp $GDT.KERNEL_CODE, $.trampoline @@ -221,19 +221,19 @@ _start: mov %esp, %esp movq $GDT, GDT.PTR + 2 - lgdt GDT.PTR # Reload GDT in higher half. + lgdt GDT.PTR // Reload GDT in higher half. pushq $GDT.KERNEL_CODE movabsq $.trampoline2, %rax pushq %rax - lretq # Jump to new GDT. + lretq // Jump to new GDT. .trampoline2: - mov $GDT.KERNEL_DATA, %ax # Set the A-register to the data descriptor. - mov %ax, %ds # Set the data segment to the A-register. - mov %ax, %es # Set the extra segment to the A-register. - mov %ax, %fs # Set the F-segment to the A-register. - mov %ax, %gs # Set the G-segment to the A-register. - mov %ax, %ss # Set the stack segment to the A-register. + mov $GDT.KERNEL_DATA, %ax // Set the A-register to the data descriptor. + mov %ax, %ds // Set the data segment to the A-register. + mov %ax, %es // Set the extra segment to the A-register. + mov %ax, %fs // Set the F-segment to the A-register. + mov %ax, %gs // Set the G-segment to the A-register. + mov %ax, %ss // Set the stack segment to the A-register. mov $.higher_half, %rax jmp *%rax @@ -241,11 +241,11 @@ _start: .section .text .higher_half: mov %esp, %esp - pop %r14 # Multiboot info address. - pop %r15 # Multiboot magic. + pop %r14 // Multiboot info address. + pop %r15 // Multiboot magic. mov $stack_top, %rsp - # map physical memory in kernel: + // map physical memory in kernel: mov $phys_mem_map - KERNEL_VMA + 3, %rbx mov $PML4T + 256 * 8, %rdi mov $128, %rcx @@ -254,7 +254,7 @@ _start: add $8, %rdi loop 1b - mov $0x183, %rbx # G | R/W | P + mov $0x183, %rbx // G | R/W | P mov $phys_mem_map, %rdi mov $128 * 512, %rcx 1: mov %rbx, (%rdi) @@ -262,12 +262,12 @@ _start: add $8, %rdi loop 1b - # Setup new page tables: + // Setup new page tables: mov $PML4T - KERNEL_VMA, %rax - or $0x10, %eax # NO CACHE + or $0x10, %eax // NO CACHE mov %rax, %cr3 - # Setup TSS address in GDT + // Setup TSS address in GDT movabs $TSS, %rax shr $0, %rax and $0xFFFF, %rax @@ -288,9 +288,9 @@ _start: mov %r14, %rsi mov %r15, %rdi - call kmain # With the two arguments popped earlier. + call kmain // With the two arguments popped earlier. - # kmain should never terminate, but, oh well. + // kmain should never terminate, but, oh well. call _fini cli diff --git a/kernel/src/interrupts.S b/kernel/src/interrupts.S index 085ca7e..c416176 100644 --- a/kernel/src/interrupts.S +++ b/kernel/src/interrupts.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . #define PUSH_REGS \ pushq %rax; \ diff --git a/kernel/src/lib/crti.S b/kernel/src/lib/crti.S index b467d0c..4353c68 100644 --- a/kernel/src/lib/crti.S +++ b/kernel/src/lib/crti.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 .init .global _init diff --git a/kernel/src/lib/crtn.S b/kernel/src/lib/crtn.S index e93bbe4..c202ca1 100644 --- a/kernel/src/lib/crtn.S +++ b/kernel/src/lib/crtn.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 .init /* gcc will nicely put the contents of crtend.o's .init section here. */ diff --git a/kernel/src/ring3.S b/kernel/src/ring3.S index c73e9c4..6b5a690 100644 --- a/kernel/src/ring3.S +++ b/kernel/src/ring3.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 @@ -20,7 +20,7 @@ ftl_to_userspace: mov %ax, %es mov %ax, %fs mov %ax, %gs - # iretq handles cs and ss + // iretq handles cs and ss pushq $(8 * 3) | 3 pushq %rsi @@ -37,27 +37,27 @@ load_tss: .globl syscall_64bit_handler syscall_64bit_handler: - # Save all registers: + // Save all registers: .irp reg,rax,rbx,rcx,rdx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15 mov %\reg, save_reg_tmp_\reg .endr - # Setup stack: + // Setup stack: mov $stack_top, %rsp - # Get process data location: + // Get process data location: mov current_pid, %rdi call get_process - # Really save all regs: + // Really save all regs: .irp reg,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 - mov save_regs_tmp + \reg * 8, %rbx # Get %r\reg - mov %rbx, 8 + \reg * 8(%rax) # And store it. + mov save_regs_tmp + \reg * 8, %rbx // Get %r\reg + mov %rbx, 8 + \reg * 8(%rax) // And store it. .endr - mov save_reg_tmp_rcx, %rbx # Save the rip also. + mov save_reg_tmp_rcx, %rbx // Save the rip also. mov %rbx, 0x88(%rax) - # Get ready for syscall: + // Get ready for syscall: mov save_reg_tmp_rdi, %rdi mov save_reg_tmp_rsi, %rsi mov save_reg_tmp_rdx, %rdx - mov save_reg_tmp_r10, %rcx # Syscall ABI -> C ABI + mov save_reg_tmp_r10, %rcx // Syscall ABI -> C ABI mov save_reg_tmp_r8, %r8 mov save_reg_tmp_r9, %r9 mov save_reg_tmp_rax, %rax @@ -65,23 +65,23 @@ syscall_64bit_handler: jae incorrect_syscall callq *syscalls_call_table(, %rax, 8) syscall_end: - mov %rax, %rbp # Save the return - # Get process data location: + mov %rax, %rbp // Save the return + // Get process data location: mov current_pid, %rdi call get_process - # Restore all regs: + // Restore all regs: .irp reg,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 - mov 8 + \reg * 8(%rax), %rbx # Get %r\reg - mov %rbx, save_regs_tmp + \reg * 8 # And restore it. + mov 8 + \reg * 8(%rax), %rbx // Get %r\reg + mov %rbx, save_regs_tmp + \reg * 8 // And restore it. .endr - mov %rbp, save_reg_tmp_rax # Restore the return register as well. - mov 0x88(%rax), %rbx # Save the rip in place of rcx, because this is sysret. + mov %rbp, save_reg_tmp_rax // Restore the return register as well. + mov 0x88(%rax), %rbx // Save the rip in place of rcx, because this is sysret. mov %rbx, save_reg_tmp_rcx - # Really restore all regs: + // Really restore all regs: .irp reg,rax,rbx,rcx,rdx,rsp,rbp,rsi,rdi,r8,r9,r10,r11,r12,r13,r14,r15 mov save_reg_tmp_\reg, %\reg .endr - # Current process registers have now all been restored. + // Current process registers have now all been restored. sysretq incorrect_syscall: call syscall_rax_error_handler @@ -95,7 +95,7 @@ syscalls_call_table: .quad syscall_write .quad syscall_close syscalls_call_table_end: -.set syscall_n, (syscalls_call_table_end - syscalls_call_table) >> 3 # Because / 8 *doesn't work* ! +.set syscall_n, (syscalls_call_table_end - syscalls_call_table) >> 3 // Because / 8 *doesn't work* ! .globl syscall_n .section .data diff --git a/test_module/src/test.S b/test_module/src/test.S index 863f1b7..c5919fa 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -1,15 +1,15 @@ -# Copyright 2023 Amélia COUTARD. -# -# 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. -# -# 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 . +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 -- 2.47.0 From 4923e9aed7b4b498eba177a8e3d73ad5ea94e263 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Fri, 22 Dec 2023 12:20:55 +0100 Subject: [PATCH 03/16] Simplification des makefiles --- Makefile | 50 ++++++++++++++++++++++++++------- kernel/module.mk | 65 +++++++++++++++---------------------------- test_module/module.mk | 45 ++++++++++-------------------- 3 files changed, 77 insertions(+), 83 deletions(-) diff --git a/Makefile b/Makefile index 176525e..c308c81 100644 --- a/Makefile +++ b/Makefile @@ -10,19 +10,31 @@ ifneq ($(MAKECMDGOALS),clean) endif .PHONY: build qemu clean +.SECONDEXPANSION: build: # Build as default target -CXXFLAGS ?= -O2 -CXXFLAGS := $(CXXFLAGS) -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror \ - -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -LDFLAGS ?= -O2 -LDFLAGS := $(LDFLAGS) -std=c++20 -Wall -Wextra -Werror -ffreestanding +CXXFLAGS := -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror \ + -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -O2 $(CXXFLAGS) +LDFLAGS := $(CXXFLAGS) $(LDFLAGS) TO_ISO := isodir/boot/grub/grub.cfg TO_CLEAN := isodir voyage.iso +TO_INCLUDE := -include **/module.mk +SRC_DIR = $(SUBDIR)src/ +OUT_DIR = $(SUBDIR)out/ +DEP_DIR = $(SUBDIR)dep/ + +SRCS = $(shell find '$(SRC_DIR)' -name '*.cpp') $(shell find '$(SRC_DIR)' -name '*.S') +PREP = $(patsubst $(SRC_DIR)%.S,$(OUT_DIR)%.s,$(SRCS:$(SRC_DIR)%.cpp=$(OUT_DIR)%.ii)) +DEPS = $(SRCS:$(SRC_DIR)%=$(DEP_DIR)%.d) +OBJS = $(PREP:=.o) + +SUBDIR := kernel/ +include $(SUBDIR)module.mk +SUBDIR := test_module/ +include $(SUBDIR)module.mk build: voyage.iso qemu: build @@ -31,11 +43,29 @@ check: clean: -rm -rf $(TO_CLEAN) install: - install -D voyage.iso -t "$(PREFIX)" + install -D voyage.iso -t '$(PREFIX)' voyage.iso: $(TO_ISO) - grub-mkrescue -o "$@" isodir + grub-mkrescue -o '$@' isodir isodir/boot/grub/grub.cfg: grub.cfg - mkdir -p "$(@D)" - install -m 644 "$<" "$@" + mkdir -p '$(@D)' + install -m 644 '$<' '$@' + +PRECOND = $(patsubst $(OUT_DIR)%.s,$(SRC_DIR)%.S,$(patsubst $(OUT_DIR)%.ii,$(SRC_DIR)%.cpp,$(patsubst $(DEP_DIR)%.d,$(SRC_DIR)%,$@))) +EXP = $(patsubst $(DEP_DIR)%.S.d,$(OUT_DIR)%.s,$(@:$(DEP_DIR)%.cpp.d=$(OUT_DIR)%.ii)) +DEP = $(patsubst $(OUT_DIR)%.s,$(DEP_DIR)%.S.d,$(@:$(OUT_DIR)%.ii=$(DEP_DIR)%.cpp.d)) +%.ii %.cpp.d &: $$(PRECOND) + mkdir -p '$(dir $(EXP))' '$(dir $(DEP))' + $(CXX) $(CXXFLAGS) -E '$<' -MMD -MT '$(EXP)' -MF '$(DEP)' -o '$(EXP)' +%.s %.S.d &: $$(PRECOND) + mkdir -p '$(dir $(EXP))' '$(dir $(DEP))' + $(CXX) $(CXXFLAGS) -E '$<' -MMD -MT '$(EXP)' -MF '$(DEP)' -o '$(EXP)' + +%: %.o # Because it causes shitty useless loops with the next rule +%.o: % + $(CXX) $(CXXFLAGS) -fpreprocessed -c '$<' -o '$@' + +ifneq ($(MAKECMDGOALS),clean) + include $(TO_INCLUDE) +endif diff --git a/kernel/module.mk b/kernel/module.mk index c867969..cc8acc3 100644 --- a/kernel/module.mk +++ b/kernel/module.mk @@ -5,51 +5,32 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -SRC_DIR := kernel/src/ -OUT_DIR := kernel/out/ -DEP_DIR := kernel/dep/ EXEC_NAME := kernel.elf64 TO_ISO += isodir/boot/$(EXEC_NAME) TO_CLEAN += $(OUT_DIR) $(DEP_DIR) - -LOCAL_CXX := g++-system -LOCAL_CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone \ - -isystem $(INCLUDES) -isystem $(INCLUDES)/c++ -isystem $(INCLUDES)/c++/x86_64-unknown-linux-gnu - # The previous line is a dirty hack. But not that much, because it doesn't allow me to include non-freestanding headers anyways -LOCAL_LDFLAGS := $(LDFLAGS) -T kernel/linker.ld -z max-page-size=0x1000 \ - -mno-red-zone -mcmodel=kernel - -CPPSRCS := $(shell find $(SRC_DIR) -name '*.cpp') -CPPOBJS := $(CPPSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o) -ASMSRCS := $(shell find $(SRC_DIR) -name '*.S' | grep -v crt) -ASMOBJS := $(ASMSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o) - -CRTI_OBJ := $(OUT_DIR)/lib/crti.S.o -CRTBEGIN_OBJ := $(shell $(LOCAL_CXX) $(LOCAL_LDFLAGS) -print-file-name=crtbegin.o) -CRTEND_OBJ := $(shell $(LOCAL_CXX) $(LOCAL_LDFLAGS) -print-file-name=crtend.o) -CRTN_OBJ := $(OUT_DIR)/lib/crtn.S.o - -OBJS := $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(CPPOBJS) $(ASMOBJS) $(CRTEND_OBJ) $(CRTN_OBJ) +TO_INCLUDE += $(DEPS) 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) kernel/linker.ld - mkdir -p "$(@D)" - $(CXX) $(LDFLAGS) -o "$@" $(OBJS) $(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 + mkdir -p '$(@D)' + install -m 644 '$<' '$@' + +CRTI_OBJ := $(OUT_DIR)lib/crti.s.o +CRTBEGIN_OBJ := $$(shell $$(CXX) $$(LDFLAGS) -print-file-name=crtbegin.o) +CRTEND_OBJ := $$(shell $$(CXX) $$(LDFLAGS) -print-file-name=crtend.o) +CRTN_OBJ := $(OUT_DIR)lib/crtn.s.o + +TARGETS_TO_VAR := $(OUT_DIR)$(EXEC_NAME) $(PREP) $(DEPS) $(OBJS) + +$(TARGETS_TO_VAR): SUBDIR := $(SUBDIR) +$(TARGETS_TO_VAR): CXX := g++-system +$(TARGETS_TO_VAR): CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone\ +-isystem $(INCLUDES) -isystem $(INCLUDES)/c++ -isystem $(INCLUDES)/c++/x86_64-unknown-linux-gnu +# The previous line is a dirty hack. But not that much, because it doesn't allow me to include non-freestanding headers anyways +$(TARGETS_TO_VAR): LDFLAGS := $(LDFLAGS) -z max-page-size=0x1000 -mno-red-zone -mcmodel=kernel +$(TARGETS_TO_VAR): LDLIBS := -nostdlib -lgcc +$(OUT_DIR)$(EXEC_NAME): kernel/linker.ld $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(filter-out $(CRTI_OBJ) $(CRTN_OBJ),$(OBJS)) $(CRTEND_OBJ) $(CRTN_OBJ) + mkdir -p '$(@D)' + $(CXX) $(LDFLAGS) -o '$@' -T $+ $(LDLIBS) + +.SECONDARY: $(PREP) $(OBJS) diff --git a/test_module/module.mk b/test_module/module.mk index a0d8d0b..c79760c 100644 --- a/test_module/module.mk +++ b/test_module/module.mk @@ -5,42 +5,25 @@ # You should have received a copy of the CC0 Public Domain Dedication along with # this file. If not, see . -SRC_DIR := test_module/src/ -OUT_DIR := test_module/out/ -DEP_DIR := test_module/dep/ EXEC_NAME := test-module.elf64 -TO_ISO += isodir/boot/$(EXEC_NAME) +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) +TO_INCLUDE += $(DEPS) isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME) - mkdir -p "$(@D)" - install -m 644 "$<" "$@" + 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) +TARGETS_TO_VAR := $(OUT_DIR)$(EXEC_NAME) $(PREP) $(DEPS) $(OBJS) -$(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 "$@" +$(TARGETS_TO_VAR): SUBDIR := $(SUBDIR) +$(TARGETS_TO_VAR): CXX := g++-user +$(TARGETS_TO_VAR): CXXFLAGS := $(CXXFLAGS) +$(TARGETS_TO_VAR): LDFLAGS := $(LDFLAGS) +$(TARGETS_TO_VAR): LDLIBS := -nostdlib -lgcc +$(OUT_DIR)$(EXEC_NAME): $(OBJS) + mkdir -p '$(@D)' + $(CXX) $(LDFLAGS) -o '$@' $+ $(LDLIBS) --include $(DEP_DIR)*.d +.SECONDARY: $(PREP) $(OBJS) -- 2.47.0 From 6612d28513742e639786131c721a3cd2f7aa1111 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Sun, 24 Dec 2023 17:29:04 +0100 Subject: [PATCH 04/16] =?utf8?q?Retir=C3=A9=20le=20hack=20d=C3=A9gueulasse?= =?utf8?q?=20pour=20importer=20la=20librairie=20standard.=20Commenc=C3=A9?= =?utf8?q?=20=C3=A0=20impl=C3=A9menter=20une=20librairie=20"standard"?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 3 +- kernel/module.mk | 6 +-- kernel/src/elf64.cpp | 22 ++++----- kernel/src/elf64.hpp | 56 +++++++++++----------- kernel/src/interrupts.cpp | 34 +++++++------- kernel/src/interrupts.hpp | 58 +++++++++++------------ kernel/src/kernel.cpp | 50 ++++++++++---------- kernel/src/lib/multiboot2.hpp | 78 +++++++++++++++---------------- kernel/src/lib/phys_ptr.hpp | 59 +++++++++++++++-------- kernel/src/paging.cpp | 2 +- kernel/src/paging.hpp | 62 ++++++++++++------------ kernel/src/ring3.cpp | 46 +++++++++--------- kernel/src/ring3.hpp | 88 +++++++++++++++++------------------ kernel/src/serial.cpp | 17 ++++--- kernel/src/serial.hpp | 45 +++++++++--------- kernel/src/utils.cpp | 26 ++++++----- kernel/src/utils.hpp | 39 ++++++++-------- libcpp/memory.hpp | 37 +++++++++++++++ libcpp/types.hpp | 40 ++++++++++++++++ test_module/src/test.S | 4 ++ test_module/src/test.cpp | 31 ++++++------ 21 files changed, 452 insertions(+), 351 deletions(-) create mode 100644 libcpp/memory.hpp create mode 100644 libcpp/types.hpp diff --git a/Makefile b/Makefile index c308c81..f8ac673 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,8 @@ endif build: # Build as default target CXXFLAGS := -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror \ - -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -O2 $(CXXFLAGS) + -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -O2 \ + -I libcpp $(CXXFLAGS) LDFLAGS := $(CXXFLAGS) $(LDFLAGS) TO_ISO := isodir/boot/grub/grub.cfg diff --git a/kernel/module.mk b/kernel/module.mk index cc8acc3..1263b79 100644 --- a/kernel/module.mk +++ b/kernel/module.mk @@ -24,10 +24,8 @@ TARGETS_TO_VAR := $(OUT_DIR)$(EXEC_NAME) $(PREP) $(DEPS) $(OBJS) $(TARGETS_TO_VAR): SUBDIR := $(SUBDIR) $(TARGETS_TO_VAR): CXX := g++-system -$(TARGETS_TO_VAR): CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone\ --isystem $(INCLUDES) -isystem $(INCLUDES)/c++ -isystem $(INCLUDES)/c++/x86_64-unknown-linux-gnu -# The previous line is a dirty hack. But not that much, because it doesn't allow me to include non-freestanding headers anyways -$(TARGETS_TO_VAR): LDFLAGS := $(LDFLAGS) -z max-page-size=0x1000 -mno-red-zone -mcmodel=kernel +$(TARGETS_TO_VAR): CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone +$(TARGETS_TO_VAR): LDFLAGS := $(LDFLAGS) -mno-red-zone -mcmodel=kernel -z max-page-size=0x1000 $(TARGETS_TO_VAR): LDLIBS := -nostdlib -lgcc $(OUT_DIR)$(EXEC_NAME): kernel/linker.ld $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(filter-out $(CRTI_OBJ) $(CRTN_OBJ),$(OBJS)) $(CRTEND_OBJ) $(CRTN_OBJ) mkdir -p '$(@D)' diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index 1223fcc..1b3f7c9 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -13,8 +13,8 @@ #include "elf64.hpp" -void os::elf::load_elf(os::process& result, std::byte* start, std::size_t length, const paging::PML4T& original_PML4T) { - os::assert(length >= sizeof(os::elf::header), "Elf file isn't big enough to contain a header: there is an error."); +void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, const paging::PML4T& original_PML4T) { + os::assert(length >= 0 && (unsigned long long)(length) >= sizeof(os::elf::header), "Elf file isn't big enough to contain a header: there is an error."); // TODO: Check that the elf file sections are all fully inside the file. // Load test-module elf file: @@ -30,14 +30,14 @@ void os::elf::load_elf(os::process& result, std::byte* start, std::size_t length os::assert(elf_header.type == 2, "Elf file not executable."); os::assert(elf_header.arch == 0x3E, "Elf file not x86_64."); - constexpr std::size_t stack_size = 16 * 0x1000 /* 64KiB */; - std::byte* const stack = (std::byte*)0x0000'8000'0000'0000 - stack_size; + constexpr amy::size stack_size = 16 * 0x1000 /* 64KiB */; + amy::byte* const stack = (amy::byte*)0x0000'8000'0000'0000 - stack_size; const auto page = os::paging::page_allocator.allocate(1); os::assert(page.ptr != nullptr, "Not enough memory for elf file loading."); result.PML4T = phys_ptr(page.ptr.get_phys_addr()); - result.rip = std::uint64_t(elf_header.entry); - result.rsp = std::uint64_t(stack + stack_size); + result.rip = amy::u64(elf_header.entry); + result.rsp = amy::u64(stack + stack_size); result.rax = 0; result.rbx = 0; result.rcx = 0; @@ -58,7 +58,7 @@ void os::elf::load_elf(os::process& result, std::byte* start, std::size_t length memset(result.PML4T->contents, 0, 256 * sizeof(os::paging::PML4E)); memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * sizeof(os::paging::PML4E)); - for (std::size_t i = 0; i < elf_header.entry_count_program_header_table; i++) { + for (amy::size i = 0; i < elf_header.entry_count_program_header_table; i++) { const os::elf::program_header program_header = *(os::elf::program_header*)( start + elf_header.program_header_table + i * elf_header.entry_size_program_header_table @@ -68,13 +68,13 @@ void os::elf::load_elf(os::process& result, std::byte* start, std::size_t length continue; } os::print("Segment: loadable\n"); - os::assert(0x1000 <= std::uint64_t(program_header.p_vaddr) - && std::uint64_t(program_header.p_vaddr + program_header.p_memsz) < 0x10'0000'0000, + os::assert(0x1000 <= amy::u64(program_header.p_vaddr) + && amy::u64(program_header.p_vaddr + program_header.p_memsz) < 0x10'0000'0000, "Program segments must be contained between 0x1000 and 0x10'0000'0000 (i.e. 64GiB)."); // Allocate, map and initialise memory for segment (memory above program_header.p_filesz is already 0-initialised by the page allocator): - std::size_t nb_pages = (std::uint64_t(program_header.p_vaddr) % 0x1000 + program_header.p_memsz + 0x1000 - 1) / 0x1000; - for (std::size_t i = 0; i < nb_pages; i++) { + amy::size nb_pages = (amy::u64(program_header.p_vaddr) % 0x1000 + program_header.p_memsz + 0x1000 - 1) / 0x1000; + for (amy::size i = 0; i < nb_pages; i++) { auto const alloc = os::paging::page_allocator.allocate(1); os::assert(alloc.ptr != nullptr, "Failed to allocate enough memory for loading of elf binary."); os::paging::map_page(*result.PML4T, (os::paging::page<0>*)(program_header.p_vaddr + i * 0x1000), alloc.ptr, { diff --git a/kernel/src/elf64.hpp b/kernel/src/elf64.hpp index 6136338..8ae4df3 100644 --- a/kernel/src/elf64.hpp +++ b/kernel/src/elf64.hpp @@ -13,7 +13,7 @@ #pragma once -#include +#include #include "lib/phys_ptr.hpp" #include "ring3.hpp" @@ -22,39 +22,39 @@ namespace os { namespace elf { struct program_header; struct header { - std::uint8_t magic[4]; - std::uint8_t bitn; - std::uint8_t endianness; - std::uint8_t header_version; - std::uint8_t abi; - std::uint64_t : 64; - std::uint16_t type; - std::uint16_t arch; - std::uint32_t elf_version; + amy::u8 magic[4]; + amy::u8 bitn; + amy::u8 endianness; + amy::u8 header_version; + amy::u8 abi; + amy::u64 : 64; + amy::u16 type; + amy::u16 arch; + amy::u32 elf_version; void* entry; - std::uint64_t program_header_table; - std::uint64_t section_header_table; - std::uint32_t flags; - std::uint16_t header_size; - std::uint16_t entry_size_program_header_table; - std::uint16_t entry_count_program_header_table; - std::uint16_t entry_size_section_header_table; - std::uint16_t entry_count_section_header_table; - std::uint16_t index_section_names_section_header_table; + amy::u64 program_header_table; + amy::u64 section_header_table; + amy::u32 flags; + amy::u16 header_size; + amy::u16 entry_size_program_header_table; + amy::u16 entry_count_program_header_table; + amy::u16 entry_size_section_header_table; + amy::u16 entry_count_section_header_table; + amy::u16 index_section_names_section_header_table; }; static_assert(sizeof(header) == 64); struct program_header { - std::uint32_t type; - std::uint32_t flags; - std::uint64_t p_offset; - std::byte* p_vaddr; - std::uint64_t : 64; - std::uint64_t p_filesz; - std::uint64_t p_memsz; - std::uint64_t align; + amy::u32 type; + amy::u32 flags; + amy::u64 p_offset; + amy::byte* p_vaddr; + amy::u64 : 64; + amy::u64 p_filesz; + amy::u64 p_memsz; + amy::u64 align; }; static_assert(sizeof(program_header) == 56); - void load_elf(os::process& result, std::byte* start, std::size_t length, const paging::PML4T& original_PML4T); + void load_elf(os::process& result, amy::byte* start, amy::size length, const paging::PML4T& original_PML4T); } } // namespace os::elf diff --git a/kernel/src/interrupts.cpp b/kernel/src/interrupts.cpp index a2b6def..11ca4d7 100644 --- a/kernel/src/interrupts.cpp +++ b/kernel/src/interrupts.cpp @@ -20,7 +20,7 @@ void os::lidt(idtr idtr) { asm volatile("lidt %0" : : "m"(idtr)); } bool os::is_APIC_builtin() { - std::uint32_t eax, ebx, ecx, edx; + amy::u32 eax, ebx, ecx, edx; __cpuid(0x01, eax, ebx, ecx, edx); return (edx & (1 << 9)) != 0; } @@ -28,19 +28,19 @@ void os::disable_PIC() { outb(0xA1, 0xFF); outb(0x21, 0xFF); } -void os::set_APIC_base(os::phys_ptr ptr) { +void os::set_APIC_base(os::phys_ptr ptr) { os::set_msr(0x1B, (ptr.get_phys_addr() & 0xFFFFFFFFFFFFF000) | 0x800); } -os::phys_ptr os::get_APIC_base() { - return os::phys_ptr{os::get_msr(0x1B) & 0xFFFFFFFFFFFFF000}; +os::phys_ptr os::get_APIC_base() { + return os::phys_ptr{os::get_msr(0x1B) & 0xFFFFFFFFFFFFF000}; } -std::uint32_t os::get_APIC_reg(std::ptrdiff_t offset) { +amy::u32 os::get_APIC_reg(amy::dptr offset) { return get_APIC_base()[offset / 4]; } -void os::set_APIC_reg(std::ptrdiff_t offset, std::uint32_t v) { +void os::set_APIC_reg(amy::dptr offset, amy::u32 v) { get_APIC_base()[offset / 4] = v; } -extern "C" void set_APIC_reg_asm(std::ptrdiff_t offset, std::uint32_t v) { +extern "C" void set_APIC_reg_asm(amy::dptr offset, amy::u32 v) { os::set_APIC_reg(offset, v); } @@ -77,7 +77,7 @@ extern "C" void int_device_not_available() { os::print("Interrupt: Device Not Available.\n"); while (true) { os::hlt(); } } -extern "C" void int_double_fault(std::uint32_t err_code) { +extern "C" void int_double_fault(amy::u32 err_code) { os::print("Interrupt: Double Fault.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } @@ -86,27 +86,27 @@ extern "C" void int_coprocessor_segment_overrun() { os::print("Interrupt: Coprocessor Segment Overrun.\n"); while (true) { os::hlt(); } } -extern "C" void int_invalid_TSS(std::uint32_t err_code) { +extern "C" void int_invalid_TSS(amy::u32 err_code) { os::print("Interrupt: Invalid TSS.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } } -extern "C" void int_segment_not_present(std::uint32_t err_code) { +extern "C" void int_segment_not_present(amy::u32 err_code) { os::print("Interrupt: Segment Not Present.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } } -extern "C" void int_stack_segment_fault(std::uint32_t err_code) { +extern "C" void int_stack_segment_fault(amy::u32 err_code) { os::print("Interrupt: Stack-Segment Fault.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } } -extern "C" void int_general_protection_fault(std::uint32_t err_code) { +extern "C" void int_general_protection_fault(amy::u32 err_code) { os::print("Interrupt: General Protection Fault.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } } -extern "C" void int_page_fault(std::uint32_t err_code, std::uint64_t vaddr) { +extern "C" void int_page_fault(amy::u32 err_code, amy::u64 vaddr) { if ( (0xFFFF'C000'0000'0000 <= vaddr && vaddr < 0xFFFF'C000'1000'0000) // process/port info ) { // Kernel memory @@ -135,7 +135,7 @@ extern "C" void int_x87_floating_point_exception() { os::print("Interrupt: x87 Floating-Point Exception.\n"); while (true) { os::hlt(); } } -extern "C" void int_alignment_check(std::uint32_t err_code) { +extern "C" void int_alignment_check(amy::u32 err_code) { os::print("Interrupt: Alignment Check.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } @@ -152,7 +152,7 @@ extern "C" void int_virtualization_exception() { os::print("Interrupt: Virtualization Exception.\n"); while (true) { os::hlt(); } } -extern "C" void int_control_protection_exception(std::uint32_t err_code) { +extern "C" void int_control_protection_exception(amy::u32 err_code) { os::print("Interrupt: Control Protection Exception.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } @@ -161,12 +161,12 @@ extern "C" void int_hypervisor_injection_exception() { os::print("Interrupt: Hypervisor Injection Exception.\n"); while (true) { os::hlt(); } } -extern "C" void int_VMM_communication_exception(std::uint32_t err_code) { +extern "C" void int_VMM_communication_exception(amy::u32 err_code) { os::print("Interrupt: VMM Communication Exception.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } } -extern "C" void int_security_exception(std::uint32_t err_code) { +extern "C" void int_security_exception(amy::u32 err_code) { os::print("Interrupt: Security Exception.\n"); os::print("Err code: {}.\n", err_code); while (true) { os::hlt(); } diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index d8a3590..2d9aa47 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -13,7 +13,7 @@ #pragma once -#include +#include #include "lib/phys_ptr.hpp" #include "serial.hpp" #include "utils.hpp" @@ -21,69 +21,69 @@ namespace os { struct ide { - std::uint16_t offset_low; - std::uint16_t kernel_cs; - std::uint8_t ist_offset : 3; - std::uint8_t reserved_1 : 5 = 0; - std::uint8_t gate_type : 4; - std::uint8_t bit_0 : 1 = 0; - std::uint8_t dpl : 2; - std::uint8_t present : 1; - std::uint16_t offset_mid; - std::uint32_t offset_high; - std::uint32_t reserved_2 = 0; + amy::u16 offset_low; + amy::u16 kernel_cs; + amy::u8 ist_offset : 3; + amy::u8 reserved_1 : 5 = 0; + amy::u8 gate_type : 4; + amy::u8 bit_0 : 1 = 0; + amy::u8 dpl : 2; + amy::u8 present : 1; + amy::u16 offset_mid; + amy::u32 offset_high; + amy::u32 reserved_2 = 0; }; static_assert(sizeof(ide) == 16); -template +template using idt __attribute__((aligned(0x1000))) = ide[interrupt_nb]; struct __attribute__((packed)) idtr { - std::uint16_t size; - std::uint64_t offset; + amy::u16 size; + amy::u64 offset; }; void lidt(idtr idtr); bool is_APIC_builtin(); void disable_PIC(); -void set_APIC_base(phys_ptr ptr); -phys_ptr get_APIC_base(); -std::uint32_t get_APIC_reg(std::ptrdiff_t offset); -void set_APIC_reg(std::ptrdiff_t offset, std::uint32_t v); +void set_APIC_base(phys_ptr ptr); +phys_ptr get_APIC_base(); +amy::u32 get_APIC_reg(amy::dptr offset); +void set_APIC_reg(amy::dptr offset, amy::u32 v); struct isr_info { - std::uintptr_t addr; + amy::uptr addr; enum class type_t { trap_gate = 0xF, interrupt_gate = 0xE }; type_t type : 4; - std::uint8_t dpl: 2 = 0b00; + amy::u8 dpl: 2 = 0b00; bool present : 1 = true; }; template void assert(bool cond, const char* format, const Ts&... vs); -template +template void enable_interrupts(const isr_info (&ISRs)[interrupt_nb], os::idt& idt) { os::assert(is_APIC_builtin(), "No builtin APIC."); disable_PIC(); set_APIC_reg(0xF0, 0x1FF); // Enable APIC - for (std::size_t i = 0; i < interrupt_nb; i++) { + for (amy::size i = 0; i < interrupt_nb; i++) { idt[i] = { - .offset_low = uint16_t(ISRs[i].addr & 0xFFFF), + .offset_low = amy::u16(ISRs[i].addr & 0xFFFF), .kernel_cs = 0x10, .ist_offset = 0, - .gate_type = std::uint8_t(ISRs[i].type), // Trap gate. + .gate_type = amy::u8(ISRs[i].type), // Trap gate. .dpl = ISRs[i].dpl, - .present = std::uint8_t(ISRs[i].present ? 1 : 0), - .offset_mid = uint16_t((ISRs[i].addr >> 16) & 0xFFFF), - .offset_high = uint32_t((ISRs[i].addr >> 32) & 0xFFFFFFFF), + .present = amy::u8(ISRs[i].present ? 1 : 0), + .offset_mid = amy::u16((ISRs[i].addr >> 16) & 0xFFFF), + .offset_high = amy::u32((ISRs[i].addr >> 32) & 0xFFFFFFFF), }; } os::idtr idtr { .size = sizeof(idt) - 1, - .offset = reinterpret_cast(&idt[0]), + .offset = reinterpret_cast(&idt[0]), }; lidt(idtr); sti(); diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index f1c1459..bffc658 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -44,15 +44,15 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < std::size_t(&_kernel_phys_rw_start)) { + } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::iptr(&_kernel_phys_rw_start)) { os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); i += 1024 * 1024 * 2; @@ -62,12 +62,12 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < std::size_t(&_kernel_phys_rw_start)) { + } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::iptr(&_kernel_phys_rw_start)) { os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); i += 1024 * 1024 * 2; @@ -82,9 +82,9 @@ extern "C" void kmain(unsigned long magic, os::phys_ptrtype) { case multiboot2::info::type_t::memory_map: os::print("RAM:\n"); - for (std::size_t i = 0; i < multiboot2::memory_map_number_of_entries(it); i++) { - std::size_t const s = multiboot2::memory_map_base_addr(it, i); - std::size_t const e = s + multiboot2::memory_map_length(it, i); + for (amy::size i = 0; i < multiboot2::memory_map_number_of_entries(it); i++) { + amy::iptr const s = multiboot2::memory_map_base_addr(it, i); + amy::iptr const e = s + multiboot2::memory_map_length(it, i); os::print("{} -> {} : {}\n", (void*)s, (void*)e, multiboot2::memory_map_type(it, i)); if (multiboot2::memory_map_type(it, i) != 1) { continue; @@ -94,7 +94,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr( os::paging::global_PML4T, @@ -126,11 +126,11 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr{std::uintptr_t(&os::paging::global_PML4T) - 0xFFFF'FFFF'8000'0000}); + os::paging::load_pml4t(os::phys_ptr{amy::uptr(&os::paging::global_PML4T) - 0xFFFF'FFFF'8000'0000}); { // Enable interrupts really early so I don't have to manually manage memory... Will make better later, when I make utils.hpp/incrementing_int64_map better. os::isr_info isr_info[32]; - for (size_t i = 0; i < sizeof(isr_info) / sizeof(isr_info[0]); i++) { + for (amy::size i = 0; (unsigned long long)(i) < sizeof(isr_info) / sizeof(isr_info[0]); i++) { isr_info[i].type = os::isr_info::type_t::trap_gate; } asm ("movq $handler_0x00,%0" : "=ri"(isr_info[0x00].addr) : ); @@ -177,7 +177,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> (12 + 9 * 3)) & 0x1FF; + amy::size const index = (amy::size(&os::processes) >> (12 + 9 * 3)) & 0x1FF; os::paging::global_PML4T.contents[index].paging_table_info({.RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false}); const auto PDPT_alloc = os::paging::page_allocator.allocate(1); os::memset((void*)PDPT_alloc.ptr, 0, 0x1000); @@ -189,7 +189,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> start_address = nullptr; os::phys_ptr> end_address = nullptr; } available_ram[50]; - std::size_t available_ram_length = 0; + amy::size available_ram_length = 0; bool module_specified = false; for (auto it = multiboot2::next(info); it->type != multiboot2::info::type_t::end; it = multiboot2::next(it)) { @@ -201,7 +201,7 @@ 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)); module_specified = true; os::elf::load_elf(os::get_process(os::processes.create()), - (std::byte*)multiboot2::modules_mod_start(it), + (amy::byte*)multiboot2::modules_mod_start(it), multiboot2::modules_mod_end(it) - multiboot2::modules_mod_start(it), os::paging::global_PML4T); break; @@ -229,11 +229,11 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> kernel_s{std::size_t(&_kernel_phys_start)}; - const os::phys_ptr> kernel_e{std::size_t(&_kernel_phys_end)}; + const os::phys_ptr> kernel_s{amy::uptr(&_kernel_phys_start)}; + const os::phys_ptr> kernel_e{amy::uptr(&_kernel_phys_end)}; // Remove kernel from available RAM: - for (std::size_t i = 0; i < available_ram_length; i++) { + for (amy::iptr i = 0; i < available_ram_length; i++) { if (kernel_e < available_ram[i].start_address || available_ram[i].end_address < kernel_s) { continue; } @@ -254,10 +254,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr +# include # include "phys_ptr.hpp" namespace multiboot2 { #endif // __cplusplus #ifdef __cplusplus - constexpr std::uint32_t magic = 0xE85250D6; - constexpr std::uint32_t arch_i386_32bit = 0; - constexpr std::uint32_t arch_mips_32bit = 4; - constexpr std::uint32_t checksum(std::uint32_t arch, std::uint32_t length) { return -(magic + arch + length); } + constexpr amy::u32 magic = 0xE85250D6; + constexpr amy::u32 arch_i386_32bit = 0; + constexpr amy::u32 arch_mips_32bit = 4; + constexpr amy::u32 checksum(amy::u32 arch, amy::u32 length) { return -(magic + arch + length); } #else # define multiboot2_magic 0xE85250D6 # define multiboot2_arch_i386_32bit 0 @@ -33,11 +33,11 @@ #ifdef __cplusplus struct __attribute__((packed)) info_start { - std::uint32_t total_size; - std::uint32_t reserved; + amy::u32 total_size; + amy::u32 reserved; }; struct __attribute__((packed)) info { - enum class type_t : std::uint32_t { + enum class type_t : amy::u32 { end = 0, basic_memory_info = 4, bios_boot_device = 5, @@ -62,8 +62,8 @@ image_load_base_physical_address = 21, }; type_t type; - std::uint32_t size; - std::uint8_t rest[]; + amy::u32 size; + amy::u8 rest[]; }; inline os::phys_ptr next(os::phys_ptr ptr) { @@ -73,52 +73,52 @@ return os::phys_ptr((ptr.get_phys_addr() + ptr->size + 7) / 8 * 8); // + 7) / 8 * 8 is required for alignment. } - inline std::uint64_t framebuffer_addr(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[0]); + inline amy::u64 framebuffer_addr(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[0]); } - inline std::uint32_t framebuffer_pitch(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[8]); + inline amy::u32 framebuffer_pitch(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[8]); } - inline std::uint32_t framebuffer_width(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[12]); + inline amy::u32 framebuffer_width(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[12]); } - inline std::uint32_t framebuffer_height(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[16]); + inline amy::u32 framebuffer_height(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[16]); } - inline std::uint8_t framebuffer_bpp(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[20]); + inline amy::u8 framebuffer_bpp(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[20]); } - inline std::uint8_t framebuffer_type(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[21]); + inline amy::u8 framebuffer_type(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[21]); } - inline const std::uint8_t* color_info(os::phys_ptr ptr) { - return reinterpret_cast(&ptr->rest[24]); + inline const amy::u8* color_info(os::phys_ptr ptr) { + return reinterpret_cast(&ptr->rest[24]); } - inline std::uint32_t memory_map_entry_size(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[0]); + inline amy::u32 memory_map_entry_size(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[0]); } - inline std::uint32_t memory_map_entry_version(os::phys_ptr ptr) { - return *reinterpret_cast(&ptr->rest[4]); + inline amy::u32 memory_map_entry_version(os::phys_ptr ptr) { + return *reinterpret_cast(&ptr->rest[4]); } - inline std::size_t memory_map_number_of_entries(os::phys_ptr ptr) { + inline amy::size memory_map_number_of_entries(os::phys_ptr ptr) { return (ptr->size - 16) / memory_map_entry_size(ptr); } - inline std::uint64_t memory_map_base_addr(os::phys_ptr ptr, std::size_t index) { - return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 0]); + inline amy::u64 memory_map_base_addr(os::phys_ptr ptr, amy::size index) { + return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 0]); } - inline std::uint64_t memory_map_length(os::phys_ptr ptr, std::size_t index) { - return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 8]); + inline amy::u64 memory_map_length(os::phys_ptr ptr, amy::size index) { + return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 8]); } - inline std::uint32_t memory_map_type(os::phys_ptr ptr, std::size_t index) { - return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 16]); + inline amy::u32 memory_map_type(os::phys_ptr ptr, amy::size index) { + return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 16]); } - inline os::phys_ptr modules_mod_start(os::phys_ptr ptr) { - return os::phys_ptr{*reinterpret_cast(&ptr->rest[0])}; + inline os::phys_ptr modules_mod_start(os::phys_ptr ptr) { + return os::phys_ptr{*reinterpret_cast(&ptr->rest[0])}; } - inline os::phys_ptr modules_mod_end(os::phys_ptr ptr) { - return os::phys_ptr{*reinterpret_cast(&ptr->rest[4])}; + inline os::phys_ptr modules_mod_end(os::phys_ptr ptr) { + return os::phys_ptr{*reinterpret_cast(&ptr->rest[4])}; } inline const char* modules_string(os::phys_ptr ptr) { return reinterpret_cast(&ptr->rest[8]); diff --git a/kernel/src/lib/phys_ptr.hpp b/kernel/src/lib/phys_ptr.hpp index 0755c0b..400f5e9 100644 --- a/kernel/src/lib/phys_ptr.hpp +++ b/kernel/src/lib/phys_ptr.hpp @@ -13,8 +13,7 @@ #pragma once -#include -#include +#include namespace os { @@ -24,8 +23,8 @@ class phys_ptr; template <> class phys_ptr { public: - constexpr explicit phys_ptr(std::uintptr_t phys_addr): phys_addr(phys_addr) {} - constexpr phys_ptr(std::nullptr_t): phys_addr(~0ull) {} + constexpr explicit phys_ptr(amy::uptr phys_addr): phys_addr(phys_addr) {} + constexpr phys_ptr(amy::nptr): phys_addr(~0ull) {} inline void* operator->() const { return get_virt_addr(); @@ -34,27 +33,32 @@ public: return get_virt_addr(); } - constexpr std::uintptr_t get_phys_addr() const { + constexpr amy::uptr get_phys_addr() const { return phys_addr; } - friend constexpr auto operator<=>(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator<(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator<=(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator>(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator>=(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator==(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator!=(phys_ptr a, phys_ptr b) = default; private: constexpr void* get_virt_addr() const { return reinterpret_cast(phys_addr + 0xFFFF800000000000); } - std::uintptr_t phys_addr; + amy::uptr phys_addr; }; template class phys_ptr { public: - constexpr explicit phys_ptr(std::uintptr_t phys_addr): phys_addr(phys_addr) {} - constexpr phys_ptr(std::nullptr_t): phys_addr(~0ull) {} + constexpr explicit phys_ptr(amy::uptr phys_addr): phys_addr(phys_addr) {} + constexpr phys_ptr(amy::nptr): phys_addr(~0ull) {} - T& operator[](std::size_t i) const { + T& operator[](amy::size i) const { return get_virt_addr()[i]; } T& operator*() const { @@ -89,38 +93,55 @@ public: operator--(); return old; } - constexpr phys_ptr& operator+=(std::ptrdiff_t offset) { + constexpr phys_ptr& operator+=(amy::dptr offset) { return *this = *this + offset; } - constexpr phys_ptr& operator-=(std::ptrdiff_t offset) { + constexpr phys_ptr& operator-=(amy::dptr offset) { return *this = *this - offset; } - friend constexpr phys_ptr operator+(phys_ptr ptr, std::ptrdiff_t offset) { + friend constexpr phys_ptr operator+(phys_ptr ptr, amy::dptr offset) { return phys_ptr{ptr.phys_addr + offset * sizeof(T)}; } - friend constexpr phys_ptr operator+(std::ptrdiff_t offset, phys_ptr ptr) { + friend constexpr phys_ptr operator+(amy::dptr offset, phys_ptr ptr) { return ptr + offset; } - friend constexpr phys_ptr operator-(phys_ptr ptr, std::ptrdiff_t offset) { + friend constexpr phys_ptr operator-(phys_ptr ptr, amy::dptr offset) { return phys_ptr{ptr.phys_addr - offset * sizeof(T)}; } - friend constexpr std::ptrdiff_t operator-(phys_ptr a, phys_ptr b) { + friend constexpr amy::dptr operator-(phys_ptr a, phys_ptr b) { return (a.phys_addr - b.phys_addr) / sizeof(T); } - constexpr std::uintptr_t get_phys_addr() const { + constexpr amy::uptr get_phys_addr() const { return phys_addr; } - friend constexpr auto operator<=>(phys_ptr a, phys_ptr b) = default; + friend constexpr bool operator<(phys_ptr a, phys_ptr b) { + return a.phys_addr < b.phys_addr; + } + friend constexpr bool operator<=(phys_ptr a, phys_ptr b) { + return a.phys_addr <= b.phys_addr; + } + friend constexpr bool operator>(phys_ptr a, phys_ptr b) { + return a.phys_addr > b.phys_addr; + } + friend constexpr bool operator>=(phys_ptr a, phys_ptr b) { + return a.phys_addr >= b.phys_addr; + } + friend constexpr bool operator==(phys_ptr a, phys_ptr b) { + return a.phys_addr == b.phys_addr; + } + friend constexpr bool operator!=(phys_ptr a, phys_ptr b) { + return a.phys_addr != b.phys_addr; + } private: constexpr T* get_virt_addr() const { return reinterpret_cast(phys_addr + 0xFFFF800000000000); } - std::uintptr_t phys_addr; + amy::uptr phys_addr; }; } // namespace os diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index 38a65e6..1a36a24 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -30,7 +30,7 @@ void os::paging::page_allocator_t::print_all() const { } } -os::paging::page_allocator_t::block os::paging::page_allocator_t::allocate(std::uint64_t count) { +os::paging::page_allocator_t::block os::paging::page_allocator_t::allocate(amy::size count) { if (begin == nullptr) { return { .ptr = nullptr, .size = count }; } diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index e085523..bae5657 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -13,16 +13,16 @@ #pragma once -#include +#include #include "serial.hpp" #include "utils.hpp" #include "lib/phys_ptr.hpp" namespace os { namespace paging { -template struct paging_entry; -template struct paging_table; -template struct page; +template struct paging_entry; +template struct paging_table; +template struct page; struct page_info { bool RW; @@ -33,7 +33,7 @@ struct page_info { bool D; bool PAT; bool G; - std::uint16_t AVL; // Only 14 bits, actually. + amy::u16 AVL; // Only 14 bits, actually. bool NX; }; struct paging_table_info { @@ -42,12 +42,12 @@ struct paging_table_info { bool PWT; bool PCD; bool A; - std::uint16_t AVL; // Really 16 bits ! + amy::u16 AVL; // Really 16 bits ! bool NX; }; -template struct paging_entry { - std::uint64_t data = 0; +template struct paging_entry { + amy::u64 data = 0; bool is_present() { return (data & (1 << 0)) != 0; @@ -77,7 +77,7 @@ template struct paging_entry { } os::phys_ptr> page_ptr() { os::assert(is_page(), "Cannot access page physical pointer for a non-page."); - std::uintptr_t addr = data & (depth == 0 ? 0x0000'FFFF'FFFF'F000 : 0x0000'FFFF'FFFF'E000); + amy::uptr addr = data & (depth == 0 ? 0x0000'FFFF'FFFF'F000 : 0x0000'FFFF'FFFF'E000); return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void page_ptr(os::phys_ptr> page) { @@ -104,7 +104,7 @@ template struct paging_entry { } os::phys_ptr> paging_table_ptr() { os::assert(!is_page(), "Cannot access paging table physical pointer for a page."); - std::uintptr_t addr = data & 0x0000'FFFF'FFFF'F000; + amy::uptr addr = data & 0x0000'FFFF'FFFF'F000; return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void paging_table_ptr(os::phys_ptr> table) { @@ -125,8 +125,8 @@ template struct paging_entry { | (info.D ? (1ull << 6) : 0) | (info.PAT ? (depth == 0 ? 1 << 7: 1 << 12) : 0) | (info.G ? (1ull << 8) : 0) - | (std::uint64_t(info.AVL & 0x7) << 9) - | (std::uint64_t(info.AVL & 0x3FF8) << 49) + | (amy::u64(info.AVL & 0x7) << 9) + | (amy::u64(info.AVL & 0x3FF8) << 49) | (info.NX ? (1ull << 63) : 0); } void paging_table_info(os::paging::paging_table_info info) { @@ -136,18 +136,18 @@ template struct paging_entry { | (info.PWT ? (1ull << 3) : 0) | (info.PCD ? (1ull << 4) : 0) | (info.A ? (1ull << 5) : 0) - | (std::uint64_t(info.AVL & 0x1) << 6) - | (std::uint64_t(info.AVL & 0x1E) << 7) - | (std::uint64_t(info.AVL & 0xFFE0) << 47) + | (amy::u64(info.AVL & 0x1) << 6) + | (amy::u64(info.AVL & 0x1E) << 7) + | (amy::u64(info.AVL & 0xFFE0) << 47) | (info.NX ? (1ull << 63) : 0); } }; -template struct __attribute__((aligned(0x1000))) paging_table { +template struct __attribute__((aligned(0x1000))) paging_table { paging_entry contents[512]; }; // Alignment should be the same as size, but that's literally too big for the compiler. -template struct __attribute__((aligned(0x1000))) page { - std::byte contents[0x1000ull << (9 * depth)]; +template struct __attribute__((aligned(0x1000))) page { + amy::byte contents[0x1000ull << (9 * depth)]; }; static_assert(sizeof(page<0>) == 0x1000); @@ -181,10 +181,10 @@ using PE = paging_entry<0>; extern PML4T global_PML4T; -template +template void map_page(paging_table& paging_table, page const* vaddr, phys_ptr> paddr, os::paging::page_info page_info); -template -void on_all_pages(const paging_table& paging_table, auto f, std::size_t vaddr_offset = 0); +template +void on_all_pages(const paging_table& paging_table, auto f, amy::uptr vaddr_offset = 0); void load_pml4t(phys_ptr PML4T); @@ -195,19 +195,19 @@ class page_allocator_t { public: struct block { phys_ptr> ptr = nullptr; - std::uint64_t size; + amy::size size; }; page_allocator_t(); void print_all() const; - block allocate(std::uint64_t page_count); + block allocate(amy::size page_count); void deallocate(block b); private: struct __attribute__((aligned(0x1000))) page { phys_ptr next; - std::uint64_t size; + amy::size size; }; static_assert(sizeof(page) == 0x1000); static_assert(alignof(page) == 0x1000); @@ -216,9 +216,9 @@ private: bool merge(phys_ptr it); }; -template +template void map_page(paging_table& paging_table, page const* vaddr, phys_ptr> paddr, os::paging::page_info page_info) { - std::size_t const index = (std::uint64_t(vaddr) >> (12 + 9 * paging_depth)) & 0x1FF; + amy::size const index = (amy::uptr(vaddr) >> (12 + 9 * paging_depth)) & 0x1FF; if constexpr (depth == paging_depth) { os::assert(!paging_table.contents[index].is_present(), "Virtual address 0x{} is already mapped.", vaddr); paging_table.contents[index].page_info(page_info); @@ -239,14 +239,14 @@ void map_page(paging_table& paging_table, page const* vaddr } } -template -void on_all_pages(const paging_table& paging_table, auto f, std::size_t vaddr_offset) { - for (std::size_t i = 0; i < 512; i++) { +template +void on_all_pages(const paging_table& paging_table, auto f, amy::uptr vaddr_offset) { + for (amy::size i = 0; i < 512; i++) { if (!is_present(paging_table.contents[i])) { continue; } - std::size_t const new_offset = ([&]() { - std::size_t const new_offset = vaddr_offset + (i << (12 + 9 * depth)); + amy::uptr const new_offset = ([&]() { + amy::uptr const new_offset = vaddr_offset + (i << (12 + 9 * depth)); return new_offset | (new_offset >> 47 ? 0xFFFF'8000'0000'0000 : 0); })(); if constexpr (depth == 3) { diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index 0073e07..4625e1e 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -16,13 +16,13 @@ #include "serial.hpp" #include "paging.hpp" -void os::run_first_process(std::int64_t pid) { +void os::run_first_process(amy::i64 pid) { current_pid = pid; os::paging::load_pml4t(os::get_process(current_pid).PML4T); - os::ftl_to_userspace((void*)os::get_process(current_pid).rip, (std::byte*)os::get_process(current_pid).rsp); + os::ftl_to_userspace((void*)os::get_process(current_pid).rip, (amy::byte*)os::get_process(current_pid).rsp); } -void os::set_ring0_stack(os::tss& tss, std::uint64_t stack) { +void os::set_ring0_stack(os::tss& tss, amy::u64 stack) { tss.rsp0 = stack; } @@ -31,11 +31,11 @@ void os::enable_syscalls() { // This is required to enable syscall/sysret on x86_64 intel. os::set_msr(0xC0000080, os::get_msr(0xC0000080) | (1 << 0)); os::set_msr(0xC0000081, - (std::uint64_t(24 - 8 + 0b11) << 48) + // sysret_cs_and_ss (e.g., userspace segments) - (std::uint64_t( 8 - 8 + 0b00) << 32) + // syscall_cs_and_ss (e.g., kernelspace segments) - std::uint64_t(0) // syscall_target_eip, only relevant to 32-bits so useless here + (amy::u64(24 - 8 + 0b11) << 48) + // sysret_cs_and_ss (e.g., userspace segments) + (amy::u64( 8 - 8 + 0b00) << 32) + // syscall_cs_and_ss (e.g., kernelspace segments) + amy::u64(0) // syscall_target_eip, only relevant to 32-bits so useless here ); - os::set_msr(0xC0000082, std::uint64_t(&syscall_64bit_handler)); // RIP for 64-bit program + os::set_msr(0xC0000082, amy::u64(&syscall_64bit_handler)); // RIP for 64-bit program os::set_msr(0xC0000083, 0); // RIP for 32-bit program, we ignore this one because the OS is only supposed to support programs running with 64 bits. os::set_msr(0xC0000084, 0x00000000); // syscall flag mask, we don't want to change the flags for now. } @@ -49,25 +49,25 @@ 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, int mount_type) { -extern "C" std::int64_t syscall_mount_kernel_device(std::int64_t, char, char const*, std::int64_t, int) { +// extern "C" int os::syscall_mount_kernel_device(amy::fd wd, char device, char const* path, amy::size path_len, int mount_type); +extern "C" int os::syscall_mount_kernel_device(amy::fd, char, char const*, amy::size, int) { 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) { +// extern "C" amy::fd os::syscall_open(amy::fd wd, char const* path, amy::size path_len, int options); +extern "C" amy::fd os::syscall_open(amy::fd, char const*, amy::size, 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" amy::size os::syscall_read(amy::fd file, char* data, amy::size len) { os::assert(file == 0, "Read isn't really implemented for now."); os::assert(len >= 0, "Read expects a positive size."); if (len == 0) { return 0; } - for (std::int64_t i = 0; i < len; i++) { + for (amy::size i = 0; i < len; i++) { if (i == 0) { data[i] = os::read_serial(); continue; @@ -81,19 +81,13 @@ extern "C" std::int64_t syscall_read(std::int64_t file, char* data, std::int64_t return len; } -// extern "C" std::int64_t syscall_close(std::int64_t file) { -extern "C" std::int64_t syscall_close(std::int64_t) { - os::assert(false, "Close isn't implemented for now."); - __builtin_unreachable(); -} - -extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std::int64_t len) { +extern "C" amy::size os::syscall_write(amy::fd file, char const* data, amy::size len) { os::assert(file == 0, "Write isn't really implemented for now."); os::assert(len >= 0, "Write expects a positive size."); if (len == 0) { return 0; } - for (std::int64_t i = 0; i < len; i++) { + for (amy::size i = 0; i < len; i++) { if (os::serial_transmit_empty()) { os::write_serial(data[i]); } else { @@ -103,13 +97,19 @@ extern "C" std::int64_t syscall_write(std::int64_t file, char const* data, std:: return len; } +// extern "C" int syscall_close(amy::fd file); +extern "C" int os::syscall_close(amy::fd) { + os::assert(false, "Close isn't implemented for now."); + __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); -std::int64_t os::current_pid; -os::process& os::get_process(std::int64_t pid) { +amy::pid os::current_pid; +os::process& os::get_process(amy::pid pid) { return processes.get(pid); } diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index 4d6bbb0..b79b7a5 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -13,79 +13,79 @@ #pragma once -#include -#include +#include #include "lib/phys_ptr.hpp" #include "paging.hpp" namespace os { struct __attribute__((packed)) tss { - std::uint32_t reserved_1; - std::uint64_t rsp0; - std::uint64_t rsp1; - std::uint64_t rsp2; - std::uint64_t reserved_2; - std::uint64_t ist1; - std::uint64_t ist2; - std::uint64_t ist3; - std::uint64_t ist4; - std::uint64_t ist5; - std::uint64_t ist6; - std::uint64_t ist7; - char reserved_3[10]; - std::uint16_t iopb; + amy::u32 reserved_1; + amy::u64 rsp0; + amy::u64 rsp1; + amy::u64 rsp2; + amy::u64 reserved_2; + amy::u64 ist1; + amy::u64 ist2; + amy::u64 ist3; + amy::u64 ist4; + amy::u64 ist5; + amy::u64 ist6; + amy::u64 ist7; + amy::byte reserved_3[10]; + amy::u16 iopb; }; struct process; -extern "C" void ftl_to_userspace(void* program, std::byte* stack); -void run_first_process(std::int64_t pid); +extern "C" void ftl_to_userspace(void* program, amy::byte* stack); +void run_first_process(amy::i64 pid); extern "C" void load_tss(); extern "C" void syscall_64bit_handler(); -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" int syscall_mount_kernel_device(amy::fd wd, char device, char const* path, amy::size path_len, int mount_type); +extern "C" amy::fd syscall_open(amy::fd wd, char const* path, amy::size path_len, int options); +extern "C" amy::size syscall_read(amy::fd file, char* data, amy::size len); +extern "C" amy::size syscall_write(amy::fd file, char const* data, amy::size len); +extern "C" int syscall_close(amy::fd file); extern "C" void syscall_rax_error_handler(); -void set_ring0_stack(tss& tss, std::uint64_t stack); +void set_ring0_stack(tss& tss, amy::u64 stack); void enable_syscalls(); struct port { bool exists; bool is_open; - std::uint64_t other_pid; - std::uint64_t other_port; + amy::u64 other_pid; + amy::u64 other_port; }; struct process { phys_ptr PML4T = nullptr; - std::uint64_t rax; - std::uint64_t rbx; - std::uint64_t rcx; - std::uint64_t rdx; - std::uint64_t rsp; - std::uint64_t rbp; - std::uint64_t rsi; - std::uint64_t rdi; - std::uint64_t r8; - std::uint64_t r9; - std::uint64_t r10; - std::uint64_t r11; - std::uint64_t r12; - std::uint64_t r13; - std::uint64_t r14; - std::uint64_t r15; - std::uint64_t rip; + amy::u64 rax; + amy::u64 rbx; + amy::u64 rcx; + amy::u64 rdx; + amy::u64 rsp; + amy::u64 rbp; + amy::u64 rsi; + amy::u64 rdi; + amy::u64 r8; + amy::u64 r9; + amy::u64 r10; + amy::u64 r11; + amy::u64 r12; + amy::u64 r13; + amy::u64 r14; + amy::u64 r15; + amy::u64 rip; incrementing_int64_map ports; }; static_assert(0xFFFF'C000'0000'0000 + sizeof(incrementing_int64_map) < 0xFFFF'FFFF'8000'0000); extern incrementing_int64_map& processes; -extern "C" std::int64_t current_pid; -extern "C" process& get_process(std::int64_t pid); +extern "C" amy::pid current_pid; +extern "C" process& get_process(amy::i64 pid); } // namespace os diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index 3d14b1a..a686584 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -11,7 +11,6 @@ // You should have received a copy of the GNU General Public License along with this program. If // not, see . -#include #include "utils.hpp" #include "interrupts.hpp" #include "serial.hpp" @@ -37,14 +36,14 @@ bool os::init_serial_port() { bool os::serial_received() { return (inb(serial_port + 5) & 0x01) != 0; } -std::uint8_t os::read_serial() { +amy::u8 os::read_serial() { while (!serial_received()) {} return inb(serial_port + 0); } bool os::serial_transmit_empty() { return (inb(serial_port + 5) & 0x20) != 0; } -void os::write_serial(std::uint8_t v) { +void os::write_serial(amy::u8 v) { while (!serial_transmit_empty()) {} outb(serial_port + 0, v); } @@ -54,11 +53,11 @@ void os::printc(char c) { } void os::print_formatted(const char* format, const char* val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); - for (std::size_t i = 0; val[i] != '\0'; i++) { + for (amy::size i = 0; val[i] != '\0'; i++) { os::printc(val[i]); } } -void os::print_formatted(const char* format, std::uint64_t val) { +void os::print_formatted(const char* format, amy::u64 val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); char data[20]; char* curr = data + 19; @@ -74,14 +73,14 @@ void os::print_formatted(const char* format, std::uint64_t val) { os::printc(*curr++); } } -void os::print_formatted(const char* format, std::int64_t val) { +void os::print_formatted(const char* format, amy::i64 val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); if (val < 0) { os::printc('-'); - os::print_formatted(format, std::uint64_t(-val)); + os::print_formatted(format, amy::u64(-val)); } else { os::printc(' '); - os::print_formatted(format, std::uint64_t(val)); + os::print_formatted(format, amy::u64(val)); } } void os::print_formatted(const char* format, phys_ptr val) { @@ -96,7 +95,7 @@ void os::print_formatted(const char* format, const void* val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); os::print("0x"); for (int i = 60; i >= 0; i -= 4) { - const int v = (reinterpret_cast(val) >> i) & 0xF; + const int v = (reinterpret_cast(val) >> i) & 0xF; os::printc(v < 10 ? v + '0' : v - 10 + 'a'); } } diff --git a/kernel/src/serial.hpp b/kernel/src/serial.hpp index 56ed9d0..479f1f0 100644 --- a/kernel/src/serial.hpp +++ b/kernel/src/serial.hpp @@ -13,8 +13,7 @@ #pragma once -#include - +#include "types.hpp" #include "lib/phys_ptr.hpp" namespace os { @@ -22,19 +21,19 @@ namespace os { template void assert(bool cond, const char* format, const Ts&... vs); -constexpr std::uint16_t serial_port{0x3F8}; +constexpr amy::u16 serial_port{0x3F8}; bool init_serial_port(); bool serial_received(); -std::uint8_t read_serial(); +amy::u8 read_serial(); bool serial_transmit_empty(); -void write_serial(std::uint8_t v); +void write_serial(amy::u8 v); void printc(char c); void print_formatted(const char* format, const char* val); -void print_formatted(const char* format, std::uint64_t val); -void print_formatted(const char* format, std::int64_t val); +void print_formatted(const char* format, amy::u64 val); +void print_formatted(const char* format, amy::i64 val); void print_formatted(const char* format, phys_ptr val); void print_formatted(const char* format, const void* val); @@ -42,37 +41,35 @@ template struct get_more_general_type_helper { using T = T_; }; template using get_more_general_type_helper_t = get_more_general_type_helper::T; -template <> struct get_more_general_type_helper { using T = std::uint64_t; }; -template <> struct get_more_general_type_helper { using T = std::uint64_t; }; -template <> struct get_more_general_type_helper { using T = std::uint64_t; }; -template <> struct get_more_general_type_helper { using T = std::int64_t; }; -template <> struct get_more_general_type_helper { using T = std::int64_t; }; -template <> struct get_more_general_type_helper { using T = std::int64_t; }; +template <> struct get_more_general_type_helper { using T = amy::u64; }; +template <> struct get_more_general_type_helper { using T = amy::u64; }; +template <> struct get_more_general_type_helper { using T = amy::u64; }; +template <> struct get_more_general_type_helper { using T = amy::i64; }; +template <> struct get_more_general_type_helper { using T = amy::i64; }; +template <> struct get_more_general_type_helper { using T = amy::i64; }; template <> struct get_more_general_type_helper { using T = const char*; }; template <> struct get_more_general_type_helper { using T = const char*; }; template struct get_more_general_type_helper> { using T = phys_ptr; }; template struct get_more_general_type_helper { using T = const void*; }; -template struct get_more_general_type_helper { using T = const char*; }; +template struct get_more_general_type_helper { using T = const char*; }; struct print_nth_helper { - std::size_t n; + amy::size n; const char* format; template inline print_nth_helper operator%(const T& v) { if (n == 0) { print_formatted(format, v); - return print_nth_helper{std::size_t(-1), format}; - } else { - return print_nth_helper{n - 1, format}; } + return print_nth_helper{n - 1, format}; } }; template void print(const char* format, const Ts&... vs) { - std::size_t arg_n = 0; + amy::size arg_n = 0; bool arg_n_is_given = 0; - for (std::size_t i = 0; format[i] != '\0'; i++) { + for (amy::size i = 0; format[i] != '\0'; i++) { if (format[i] == '{') { i++; if (format[i] == '\0') { @@ -81,19 +78,19 @@ void print(const char* format, const Ts&... vs) { printc('{'); continue; } else { - std::size_t format_spec_end = i; + amy::size format_spec_end = i; while (format[format_spec_end] != '}') { if (format[format_spec_end++] == '\0') { os::assert(false, "Error in format string: unterminated '{{}'."); } } - std::size_t n = arg_n; + amy::size n = arg_n; if ('0' <= format[i] && format[i] <= '9') { if (arg_n == 0) { arg_n_is_given = true; } os::assert(arg_n_is_given, "Error in format string: either the arg_id is always given, or never."); - std::size_t n_ = 0; + amy::size n_ = 0; while ('0' <= format[i] && format[i] <= '9') { n_ = n_ * 10 + (format[i++] - '0'); } @@ -109,7 +106,7 @@ void print(const char* format, const Ts&... vs) { } else { os::assert(format[i] == '}', "Error in format string: ':' required before format spec."); } - os::assert(n < sizeof...(vs), "Error in format string: not enough arguments."); + os::assert(n < amy::size(sizeof...(vs)), "Error in format string: not enough arguments."); (print_nth_helper{n, &format[i]} % ... % get_more_general_type_helper_t(vs)); i = format_spec_end; arg_n++; diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index 4643a27..43a8c2b 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -28,37 +28,39 @@ void os::hlt() { asm volatile("hlt" :); } -void os::outb(std::uint16_t port, std::uint8_t data) { +void os::outb(amy::u16 port, amy::u8 data) { asm volatile ("outb %1,%0" : : "dN"(port), "a"(data)); } -std::uint8_t os::inb(std::uint16_t port) { - std::uint8_t data; +amy::u8 os::inb(amy::u16 port) { + amy::u8 data; asm volatile ("inb %1,%0" : "=a"(data) : "dN"(port)); return data; } bool os::cpu_has_msr() { - std::uint32_t eax, ebx, ecx, edx; + amy::u32 eax, ebx, ecx, edx; __cpuid(0x01, eax, ebx, ecx, edx); return (edx & (1 << 5)) != 0; } -std::uint64_t os::get_msr(std::uint32_t msr) { - std::uint64_t lo, hi; +amy::u64 os::get_msr(amy::u32 msr) { + amy::u64 lo, hi; asm volatile ("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr)); return lo + (hi << 32); } -void os::set_msr(std::uint32_t msr, std::uint64_t v) { - asm volatile ("wrmsr" : : "a"(v & 0xFFFFFFFF), "d"((v >> 32) & 0xFFFFFFFF), "c"(msr)); +void os::set_msr(amy::u32 msr, amy::u64 v) { + asm volatile ("wrmsr" : : "a"(v & 0xFFFF'FFFF), "d"((v >> 32) & 0xFFFF'FFFF), "c"(msr)); } -extern "C" void* os::memset(void* dest, int c, size_t n) { +extern "C" void* os::memset(void* dest, int c, amy::size n) { + os::assert(n >= 0, "Memset expects a positive size."); while (n-- > 0) { - reinterpret_cast(dest)[n] = std::byte(c); + reinterpret_cast(dest)[n] = amy::byte(c); } return dest; } -extern "C" void* os::memcpy(void* dest, const void* src, size_t n) { +extern "C" void* os::memcpy(void* dest, const void* src, amy::size n) { + os::assert(n >= 0, "Memcpy expects a positive size."); while (n-- > 0) { - reinterpret_cast(dest)[n] = reinterpret_cast(src)[n]; + reinterpret_cast(dest)[n] = reinterpret_cast(src)[n]; } return dest; } diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index df82e9a..035760e 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -13,9 +13,8 @@ #pragma once -#include -#include -#include +#include +#include #include "serial.hpp" namespace os { @@ -24,16 +23,16 @@ void invlpg(const void* vaddr); void cli(); void sti(); void hlt(); -void outb(std::uint16_t port, std::uint8_t data); -std::uint8_t inb(std::uint16_t port); +void outb(amy::u16 port, amy::u8 data); +amy::u8 inb(amy::u16 port); bool cpu_has_msr(); -std::uint64_t get_msr(std::uint32_t msr); -void set_msr(std::uint32_t msr, std::uint64_t v); +amy::u64 get_msr(amy::u32 msr); +void set_msr(amy::u32 msr, amy::u64 v); template T clamp(T min, T v, T max) { return v < min ? min : max < v ? max : v; } -extern "C" void* memset(void* dest, int c, size_t n); -extern "C" void* memcpy(void* dest, const void* src, size_t n); +extern "C" void* memset(void* dest, int c, amy::size n); +extern "C" void* memcpy(void* dest, const void* src, amy::size n); template struct incrementing_int64_map { @@ -42,7 +41,7 @@ public: incrementing_int64_map(const incrementing_int64_map& other) = delete; incrementing_int64_map& operator=(const incrementing_int64_map& other) = delete; ~incrementing_int64_map() { - for (std::int64_t i = 0; i < n; i++) { + for (amy::i64 i = 0; i < n; i++) { if (present(i)) { remove(i); } } } @@ -50,36 +49,36 @@ public: bool has_room() { return n < max_n; } - bool present(std::int64_t index) { + bool present(amy::i64 index) { return 0 <= index && index < n && elems[index].present; } - std::int64_t create() { + amy::i64 create() { os::assert(has_room(), "Too many allocated elems in incrementing_int64_map."); elems[n].present = true; new(elems[n].buffer) T; return n++; } - void remove(std::int64_t index) { + void remove(amy::i64 index) { os::assert(present(index), "Tried removing non-existant element of incrementing_int64_map."); get(index).~T(); elems[index].present = false; } - T& get(std::int64_t index) { + T& get(amy::i64 index) { os::assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); - return *std::launder(reinterpret_cast(&elems[index].buffer[0])); + return *amy::launder(reinterpret_cast(&elems[index].buffer[0])); } - const T& get(std::int64_t index) const { + const T& get(amy::i64 index) const { os::assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); - return *std::launder(reinterpret_cast(&elems[index].buffer[0])); + return *amy::launder(reinterpret_cast(&elems[index].buffer[0])); } private: struct elem_t { bool present; - alignas(T) std::byte buffer[sizeof(T)]; + alignas(T) amy::byte buffer[sizeof(T)]; }; - std::int64_t n = 0; - static constexpr std::int64_t max_n = 4096; + amy::i64 n = 0; + static constexpr amy::i64 max_n = 4096; elem_t elems[max_n]; }; diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp new file mode 100644 index 0000000..81ae2a6 --- /dev/null +++ b/libcpp/memory.hpp @@ -0,0 +1,37 @@ +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . + +#pragma once + +#include + +// See the C++ documentation for documentation. + +// Placement new and delete (taken from glibcxx, should be fine copyright-wise): +[[nodiscard]] inline void* operator new(unsigned long, void* p) noexcept { + return p; +} +[[nodiscard]] inline void* operator new[](unsigned long, void* p) noexcept { + return p; +} +inline void operator delete(void*, void*) noexcept {} +inline void operator delete[](void*, void*) noexcept {} + +namespace amy { + +// Taken from glibcxx, should be fine copyright-wise: +template +[[nodiscard]] constexpr T* launder(T* p) noexcept { + return __builtin_launder(p); +} +} // namespace amy diff --git a/libcpp/types.hpp b/libcpp/types.hpp new file mode 100644 index 0000000..2e7f2d6 --- /dev/null +++ b/libcpp/types.hpp @@ -0,0 +1,40 @@ +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . + +#pragma once + +#include + +namespace amy { + +enum class byte : unsigned char {}; +using i8 = int8_t; +using u8 = uint8_t; +using i16 = int16_t; +using u16 = uint16_t; +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; + +using iptr = intptr_t; +using uptr = uintptr_t; +using dptr = __PTRDIFF_TYPE__; +using nptr = decltype(nullptr); + +using size = i64; + +using pid = i64; +using fd = i64; + +} // namespace amy diff --git a/test_module/src/test.S b/test_module/src/test.S index c5919fa..eb6dd23 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -44,3 +44,7 @@ close: mov $4, %rax syscall ret + +.globl loop_de_loop +loop_de_loop: +1: jmp 1b diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index 62a3576..a66ecd2 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -11,8 +11,13 @@ // You should have received a copy of the GNU General Public License along with this program. If // not, see . -#include -#include +#include + +enum mount_type { + MOUNT_REPLACE = 0, + MOUNT_BEFORE = 1, + MOUNT_AFTER = 2, +}; enum open_options { MODE_READ = 0x1, @@ -22,25 +27,23 @@ enum open_options { }; 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" int mount_kernel_device(amy::fd wd, char device, char const* path, amy::size path_len, mount_type type); +extern "C" amy::fd open(amy::fd wd, char const* path, amy::size path_len, open_options options); +extern "C" amy::size read(amy::fd file, char* data, amy::size len); +extern "C" amy::size write(amy::fd file, char const* data, amy::size len); +extern "C" int close(amy::fd file); } // namespace sys -void loop_de_loop() { - loop_de_loop(); -} +extern "C" void loop_de_loop(); extern "C" void _start() { - 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::mount_kernel_device(-1, 'I', "/", 1, MOUNT_REPLACE); // 'I' is the I/O device. /serial is the serial port /fb is the framebuffer + const amy::fd serial = sys::open(-1, "/serial", 7, MODE_WRITE); sys::write(serial, "Entrez votre nom: ", 18); char data[32]; - int64_t read = 0; - int64_t read_this_time; + amy::size read = 0; + amy::size read_this_time; do { read_this_time = sys::read(serial, data + read, 1); if (read_this_time) { -- 2.47.0 From 06b84d59cff8ad95f5cf9ef8716ec50ef3893080 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Sun, 24 Dec 2023 23:06:50 +0100 Subject: [PATCH 05/16] =?utf8?q?J'ai=20r=C3=A9fl=C3=A9chi=20un=20peu=20aux?= =?utf8?q?=20types=20entiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/src/elf64.cpp | 6 ++--- kernel/src/elf64.hpp | 4 +-- kernel/src/interrupts.cpp | 10 ++++---- kernel/src/interrupts.hpp | 14 +++++------ kernel/src/kernel.cpp | 46 +++++++++++++++++------------------ kernel/src/lib/multiboot2.hpp | 4 +-- kernel/src/lib/phys_ptr.hpp | 37 ++++++++++++++-------------- kernel/src/paging.hpp | 38 ++++++++++++++--------------- kernel/src/ring3.cpp | 16 ++++++------ kernel/src/ring3.hpp | 6 ++--- kernel/src/serial.cpp | 2 +- kernel/src/utils.hpp | 2 +- libcpp/memory.hpp | 11 ++++++++- libcpp/types.hpp | 13 +++++----- test_module/src/test.cpp | 4 +-- 15 files changed, 112 insertions(+), 101 deletions(-) diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index 1b3f7c9..239cb6b 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -14,7 +14,7 @@ #include "elf64.hpp" void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, const paging::PML4T& original_PML4T) { - os::assert(length >= 0 && (unsigned long long)(length) >= sizeof(os::elf::header), "Elf file isn't big enough to contain a header: there is an error."); + os::assert(length >= amy::byte_size(), "Elf file isn't big enough to contain a header: there is an error."); // TODO: Check that the elf file sections are all fully inside the file. // Load test-module elf file: @@ -55,8 +55,8 @@ void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, result.r15 = 0; // Copy kernel mappings to the new virtual address space. - memset(result.PML4T->contents, 0, 256 * sizeof(os::paging::PML4E)); - memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * sizeof(os::paging::PML4E)); + memset(result.PML4T->contents, 0, 256 * amy::byte_size()); + memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * amy::byte_size()); for (amy::size i = 0; i < elf_header.entry_count_program_header_table; i++) { const os::elf::program_header program_header = *(os::elf::program_header*)( diff --git a/kernel/src/elf64.hpp b/kernel/src/elf64.hpp index 8ae4df3..9347353 100644 --- a/kernel/src/elf64.hpp +++ b/kernel/src/elf64.hpp @@ -42,7 +42,7 @@ namespace os { namespace elf { amy::u16 entry_count_section_header_table; amy::u16 index_section_names_section_header_table; }; - static_assert(sizeof(header) == 64); + static_assert(amy::byte_size
() == 64); struct program_header { amy::u32 type; @@ -54,7 +54,7 @@ namespace os { namespace elf { amy::u64 p_memsz; amy::u64 align; }; - static_assert(sizeof(program_header) == 56); + static_assert(amy::byte_size() == 56); void load_elf(os::process& result, amy::byte* start, amy::size length, const paging::PML4T& original_PML4T); } } // namespace os::elf diff --git a/kernel/src/interrupts.cpp b/kernel/src/interrupts.cpp index 11ca4d7..2288039 100644 --- a/kernel/src/interrupts.cpp +++ b/kernel/src/interrupts.cpp @@ -29,18 +29,18 @@ void os::disable_PIC() { outb(0x21, 0xFF); } void os::set_APIC_base(os::phys_ptr ptr) { - os::set_msr(0x1B, (ptr.get_phys_addr() & 0xFFFFFFFFFFFFF000) | 0x800); + os::set_msr(0x1B, (ptr.get_phys_addr() & 0xFFFF'FFFF'FFFF'F000) | 0x800); } os::phys_ptr os::get_APIC_base() { - return os::phys_ptr{os::get_msr(0x1B) & 0xFFFFFFFFFFFFF000}; + return os::phys_ptr{amy::ptr(os::get_msr(0x1B)) & amy::ptr(0xFFFF'FFFF'FFFF'F000)}; } -amy::u32 os::get_APIC_reg(amy::dptr offset) { +amy::u32 os::get_APIC_reg(amy::diff offset) { return get_APIC_base()[offset / 4]; } -void os::set_APIC_reg(amy::dptr offset, amy::u32 v) { +void os::set_APIC_reg(amy::diff offset, amy::u32 v) { get_APIC_base()[offset / 4] = v; } -extern "C" void set_APIC_reg_asm(amy::dptr offset, amy::u32 v) { +extern "C" void set_APIC_reg_asm(amy::diff offset, amy::u32 v) { os::set_APIC_reg(offset, v); } diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index 2d9aa47..564a4b6 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -33,13 +33,13 @@ struct ide { amy::u32 offset_high; amy::u32 reserved_2 = 0; }; -static_assert(sizeof(ide) == 16); +static_assert(amy::byte_size() == 16); template using idt __attribute__((aligned(0x1000))) = ide[interrupt_nb]; struct __attribute__((packed)) idtr { amy::u16 size; - amy::u64 offset; + amy::ptr offset; }; void lidt(idtr idtr); @@ -47,11 +47,11 @@ bool is_APIC_builtin(); void disable_PIC(); void set_APIC_base(phys_ptr ptr); phys_ptr get_APIC_base(); -amy::u32 get_APIC_reg(amy::dptr offset); -void set_APIC_reg(amy::dptr offset, amy::u32 v); +amy::u32 get_APIC_reg(amy::diff offset); +void set_APIC_reg(amy::diff offset, amy::u32 v); struct isr_info { - amy::uptr addr; + amy::ptr addr; enum class type_t { trap_gate = 0xF, interrupt_gate = 0xE }; type_t type : 4; amy::u8 dpl: 2 = 0b00; @@ -82,8 +82,8 @@ void enable_interrupts(const isr_info (&ISRs)[interrupt_nb], os::idt(&idt[0]), + .size = amy::byte_size() - 1, + .offset = reinterpret_cast(&idt[0]), }; lidt(idtr); sti(); diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index bffc658..cc709be 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -38,21 +38,21 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr>(reinterpret_cast(bootstrap_pages_for_memory) - 0xFFFF'FFFF'8000'0000), - .size = sizeof(bootstrap_pages_for_memory) / sizeof(bootstrap_pages_for_memory[0]) + .ptr = os::phys_ptr>(amy::ptr(&bootstrap_pages_for_memory) & amy::ptr(~0xFFFF'FFFF'8000'0000)), + .size = amy::byte_size() / amy::byte_size() }); os::assert(os::cpu_has_msr(), "MSRs aren't supported."); // Initialise kernel map. - os::assert(amy::iptr(&_kernel_phys_start) % 4096 == 0, "Kernel isn't page aligned !"); - os::assert(amy::iptr(&_kernel_phys_rw_start) % 4096 == 0, "Kernel isn't page aligned !"); - os::assert(amy::iptr(&_kernel_phys_end) % 4096 == 0, "Kernel isn't page aligned !"); - for (amy::size i = amy::iptr(&_kernel_phys_start); i < amy::iptr(&_kernel_phys_rw_start); ) { - if (i % (1024 * 1024 * 1024) == 0 && i + 1024 * 1024 * 1024 < amy::iptr(&_kernel_phys_rw_start)) { + os::assert(amy::ptr(&_kernel_phys_start) % 4096 == 0, "Kernel isn't page aligned !"); + os::assert(amy::ptr(&_kernel_phys_rw_start) % 4096 == 0, "Kernel isn't page aligned !"); + os::assert(amy::ptr(&_kernel_phys_end) % 4096 == 0, "Kernel isn't page aligned !"); + for (amy::size i = amy::ptr(&_kernel_phys_start); i < amy::ptr(&_kernel_phys_rw_start); ) { + if (i % (1024 * 1024 * 1024) == 0 && i + 1024 * 1024 * 1024 < amy::ptr(&_kernel_phys_rw_start)) { os::paging::map_page<2, 3>(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::iptr(&_kernel_phys_rw_start)) { + } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); i += 1024 * 1024 * 2; @@ -62,12 +62,12 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::iptr(&_kernel_phys_rw_start)) { + } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); i += 1024 * 1024 * 2; @@ -83,8 +83,8 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr {} : {}\n", (void*)s, (void*)e, multiboot2::memory_map_type(it, i)); if (multiboot2::memory_map_type(it, i) != 1) { continue; @@ -94,7 +94,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr( os::paging::global_PML4T, @@ -126,11 +126,11 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr{amy::uptr(&os::paging::global_PML4T) - 0xFFFF'FFFF'8000'0000}); + os::paging::load_pml4t(os::phys_ptr{amy::ptr(&os::paging::global_PML4T) & amy::ptr(~0xFFFF'FFFF'8000'0000)}); { // Enable interrupts really early so I don't have to manually manage memory... Will make better later, when I make utils.hpp/incrementing_int64_map better. os::isr_info isr_info[32]; - for (amy::size i = 0; (unsigned long long)(i) < sizeof(isr_info) / sizeof(isr_info[0]); i++) { + for (amy::size i = 0; i < amy::byte_size() / amy::byte_size(); i++) { isr_info[i].type = os::isr_info::type_t::trap_gate; } asm ("movq $handler_0x00,%0" : "=ri"(isr_info[0x00].addr) : ); @@ -175,7 +175,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr() <= 1024 * 1024 * 1024, "Error: processes array too big."); { amy::size const index = (amy::size(&os::processes) >> (12 + 9 * 3)) & 0x1FF; os::paging::global_PML4T.contents[index].paging_table_info({.RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false}); @@ -217,7 +217,7 @@ 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)); module_specified = true; - os::elf::load_elf(os::get_process(os::processes.create()), + os::elf::load_elf(os::get_process(amy::pid(os::processes.create())), (amy::byte*)multiboot2::modules_mod_start(it), multiboot2::modules_mod_end(it) - multiboot2::modules_mod_start(it), os::paging::global_PML4T); @@ -229,11 +229,11 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> kernel_s{amy::uptr(&_kernel_phys_start)}; - const os::phys_ptr> kernel_e{amy::uptr(&_kernel_phys_end)}; + const os::phys_ptr> kernel_s{amy::ptr(&_kernel_phys_start)}; + const os::phys_ptr> kernel_e{amy::ptr(&_kernel_phys_end)}; // Remove kernel from available RAM: - for (amy::iptr i = 0; i < available_ram_length; i++) { + for (amy::ptr i = 0; i < available_ram_length; i++) { if (kernel_e < available_ram[i].start_address || available_ram[i].end_address < kernel_s) { continue; } @@ -254,7 +254,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr ptr) { return (ptr->size - 16) / memory_map_entry_size(ptr); } - inline amy::u64 memory_map_base_addr(os::phys_ptr ptr, amy::size index) { - return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 0]); + inline amy::ptr memory_map_base_addr(os::phys_ptr ptr, amy::size index) { + return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 0]); } inline amy::u64 memory_map_length(os::phys_ptr ptr, amy::size index) { return *reinterpret_cast(&ptr->rest[8 + memory_map_entry_size(ptr) * index + 8]); diff --git a/kernel/src/lib/phys_ptr.hpp b/kernel/src/lib/phys_ptr.hpp index 400f5e9..4fb474a 100644 --- a/kernel/src/lib/phys_ptr.hpp +++ b/kernel/src/lib/phys_ptr.hpp @@ -14,6 +14,7 @@ #pragma once #include +#include namespace os { @@ -23,8 +24,8 @@ class phys_ptr; template <> class phys_ptr { public: - constexpr explicit phys_ptr(amy::uptr phys_addr): phys_addr(phys_addr) {} - constexpr phys_ptr(amy::nptr): phys_addr(~0ull) {} + constexpr explicit phys_ptr(amy::ptr phys_addr): phys_addr(phys_addr) {} + constexpr phys_ptr(amy::nil_t): phys_addr(0xF000'0000'0000'0000) {} inline void* operator->() const { return get_virt_addr(); @@ -33,7 +34,7 @@ public: return get_virt_addr(); } - constexpr amy::uptr get_phys_addr() const { + constexpr amy::ptr get_phys_addr() const { return phys_addr; } @@ -49,16 +50,16 @@ private: return reinterpret_cast(phys_addr + 0xFFFF800000000000); } - amy::uptr phys_addr; + amy::ptr phys_addr; }; template class phys_ptr { public: - constexpr explicit phys_ptr(amy::uptr phys_addr): phys_addr(phys_addr) {} - constexpr phys_ptr(amy::nptr): phys_addr(~0ull) {} + constexpr explicit phys_ptr(amy::ptr phys_addr): phys_addr(phys_addr) {} + constexpr phys_ptr(amy::nil_t): phys_addr(0xF000'0000'0000'0000) {} - T& operator[](amy::size i) const { + T& operator[](amy::diff i) const { return get_virt_addr()[i]; } T& operator*() const { @@ -93,27 +94,27 @@ public: operator--(); return old; } - constexpr phys_ptr& operator+=(amy::dptr offset) { + constexpr phys_ptr& operator+=(amy::diff offset) { return *this = *this + offset; } - constexpr phys_ptr& operator-=(amy::dptr offset) { + constexpr phys_ptr& operator-=(amy::diff offset) { return *this = *this - offset; } - friend constexpr phys_ptr operator+(phys_ptr ptr, amy::dptr offset) { - return phys_ptr{ptr.phys_addr + offset * sizeof(T)}; + friend constexpr phys_ptr operator+(phys_ptr ptr, amy::diff offset) { + return phys_ptr{ptr.phys_addr + offset * amy::byte_size()}; } - friend constexpr phys_ptr operator+(amy::dptr offset, phys_ptr ptr) { + friend constexpr phys_ptr operator+(amy::diff offset, phys_ptr ptr) { return ptr + offset; } - friend constexpr phys_ptr operator-(phys_ptr ptr, amy::dptr offset) { - return phys_ptr{ptr.phys_addr - offset * sizeof(T)}; + friend constexpr phys_ptr operator-(phys_ptr ptr, amy::diff offset) { + return phys_ptr{ptr.phys_addr - offset * amy::byte_size()}; } - friend constexpr amy::dptr operator-(phys_ptr a, phys_ptr b) { - return (a.phys_addr - b.phys_addr) / sizeof(T); + friend constexpr amy::diff operator-(phys_ptr a, phys_ptr b) { + return (a.phys_addr - b.phys_addr) / amy::byte_size(); } - constexpr amy::uptr get_phys_addr() const { + constexpr amy::ptr get_phys_addr() const { return phys_addr; } @@ -141,7 +142,7 @@ private: return reinterpret_cast(phys_addr + 0xFFFF800000000000); } - amy::uptr phys_addr; + amy::ptr phys_addr; }; } // namespace os diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index bae5657..7b8087d 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -77,7 +77,7 @@ template struct paging_entry { } os::phys_ptr> page_ptr() { os::assert(is_page(), "Cannot access page physical pointer for a non-page."); - amy::uptr addr = data & (depth == 0 ? 0x0000'FFFF'FFFF'F000 : 0x0000'FFFF'FFFF'E000); + amy::ptr addr = data & (depth == 0 ? 0x0000'FFFF'FFFF'F000 : 0x0000'FFFF'FFFF'E000); return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void page_ptr(os::phys_ptr> page) { @@ -104,7 +104,7 @@ template struct paging_entry { } os::phys_ptr> paging_table_ptr() { os::assert(!is_page(), "Cannot access paging table physical pointer for a page."); - amy::uptr addr = data & 0x0000'FFFF'FFFF'F000; + amy::ptr addr = data & 0x0000'FFFF'FFFF'F000; return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void paging_table_ptr(os::phys_ptr> table) { @@ -150,25 +150,25 @@ template struct __attribute__((aligned(0x1000))) page { amy::byte contents[0x1000ull << (9 * depth)]; }; -static_assert(sizeof(page<0>) == 0x1000); -static_assert(sizeof(page<1>) == 0x1000 * 512); -static_assert(sizeof(page<2>) == 0x1000ull * 512 * 512); -static_assert(sizeof(paging_table<3>) == 0x1000); +static_assert(amy::byte_size>() == 0x1000); +static_assert(amy::byte_size>() == 0x1000 * 512); +static_assert(amy::byte_size>() == 0x1000ull * 512 * 512); +static_assert(amy::byte_size>() == 0x1000); static_assert(alignof(paging_table<3>) == 0x1000); static_assert(alignof(paging_entry<3>) == 8); -static_assert(sizeof(paging_entry<3>) == 8); -static_assert(sizeof(paging_table<2>) == 0x1000); +static_assert(amy::byte_size>() == 8); +static_assert(amy::byte_size>() == 0x1000); static_assert(alignof(paging_table<2>) == 0x1000); static_assert(alignof(paging_entry<2>) == 8); -static_assert(sizeof(paging_entry<2>) == 8); -static_assert(sizeof(paging_table<1>) == 0x1000); +static_assert(amy::byte_size>() == 8); +static_assert(amy::byte_size>() == 0x1000); static_assert(alignof(paging_table<1>) == 0x1000); static_assert(alignof(paging_entry<1>) == 8); -static_assert(sizeof(paging_entry<1>) == 8); -static_assert(sizeof(paging_table<0>) == 0x1000); +static_assert(amy::byte_size>() == 8); +static_assert(amy::byte_size>() == 0x1000); static_assert(alignof(paging_table<0>) == 0x1000); static_assert(alignof(paging_entry<0>) == 8); -static_assert(sizeof(paging_entry<0>) == 8); +static_assert(amy::byte_size>() == 8); using PML4T = paging_table<3>; using PML4E = paging_entry<3>; @@ -184,7 +184,7 @@ extern PML4T global_PML4T; template void map_page(paging_table& paging_table, page const* vaddr, phys_ptr> paddr, os::paging::page_info page_info); template -void on_all_pages(const paging_table& paging_table, auto f, amy::uptr vaddr_offset = 0); +void on_all_pages(const paging_table& paging_table, auto f, amy::diff vaddr_offset = 0); void load_pml4t(phys_ptr PML4T); @@ -209,7 +209,7 @@ private: phys_ptr next; amy::size size; }; - static_assert(sizeof(page) == 0x1000); + static_assert(amy::byte_size() == 0x1000); static_assert(alignof(page) == 0x1000); phys_ptr begin; @@ -218,7 +218,7 @@ private: template void map_page(paging_table& paging_table, page const* vaddr, phys_ptr> paddr, os::paging::page_info page_info) { - amy::size const index = (amy::uptr(vaddr) >> (12 + 9 * paging_depth)) & 0x1FF; + amy::size const index = (amy::ptr(vaddr) >> (12 + 9 * paging_depth)) & 0x1FF; if constexpr (depth == paging_depth) { os::assert(!paging_table.contents[index].is_present(), "Virtual address 0x{} is already mapped.", vaddr); paging_table.contents[index].page_info(page_info); @@ -240,13 +240,13 @@ void map_page(paging_table& paging_table, page const* vaddr } template -void on_all_pages(const paging_table& paging_table, auto f, amy::uptr vaddr_offset) { +void on_all_pages(const paging_table& paging_table, auto f, amy::diff vaddr_offset) { for (amy::size i = 0; i < 512; i++) { if (!is_present(paging_table.contents[i])) { continue; } - amy::uptr const new_offset = ([&]() { - amy::uptr const new_offset = vaddr_offset + (i << (12 + 9 * depth)); + amy::diff const new_offset = ([&]() { + amy::diff const new_offset = vaddr_offset + (i << (12 + 9 * depth)); return new_offset | (new_offset >> 47 ? 0xFFFF'8000'0000'0000 : 0); })(); if constexpr (depth == 3) { diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index 4625e1e..5df22c5 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -16,7 +16,7 @@ #include "serial.hpp" #include "paging.hpp" -void os::run_first_process(amy::i64 pid) { +void os::run_first_process(amy::pid pid) { current_pid = pid; os::paging::load_pml4t(os::get_process(current_pid).PML4T); os::ftl_to_userspace((void*)os::get_process(current_pid).rip, (amy::byte*)os::get_process(current_pid).rsp); @@ -41,12 +41,12 @@ void os::enable_syscalls() { } void schedule_next_process() { - if (os::processes.present(os::current_pid + 1)) { - os::current_pid += 1; + if (os::processes.present(amy::i64(os::current_pid) + 1)) { + os::current_pid = amy::pid(amy::i64(os::current_pid) + 1); } else { - os::current_pid = 0; + os::current_pid = amy::pid(0); } - os::paging::load_pml4t(os::processes.get(os::current_pid).PML4T); + os::paging::load_pml4t(os::processes.get(amy::i64(os::current_pid)).PML4T); } // extern "C" int os::syscall_mount_kernel_device(amy::fd wd, char device, char const* path, amy::size path_len, int mount_type); @@ -62,7 +62,7 @@ extern "C" amy::fd os::syscall_open(amy::fd, char const*, amy::size, int) { } extern "C" amy::size os::syscall_read(amy::fd file, char* data, amy::size len) { - os::assert(file == 0, "Read isn't really implemented for now."); + os::assert(file == amy::fd(0), "Read isn't really implemented for now."); os::assert(len >= 0, "Read expects a positive size."); if (len == 0) { return 0; @@ -82,7 +82,7 @@ extern "C" amy::size os::syscall_read(amy::fd file, char* data, amy::size len) { } extern "C" amy::size os::syscall_write(amy::fd file, char const* data, amy::size len) { - os::assert(file == 0, "Write isn't really implemented for now."); + os::assert(file == amy::fd(0), "Write isn't really implemented for now."); os::assert(len >= 0, "Write expects a positive size."); if (len == 0) { return 0; @@ -111,5 +111,5 @@ extern "C" void os::syscall_rax_error_handler() { os::incrementing_int64_map& os::processes = *reinterpret_cast*>(0xFFFF'C000'0000'0000); amy::pid os::current_pid; os::process& os::get_process(amy::pid pid) { - return processes.get(pid); + return processes.get(amy::i64(pid)); } diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index b79b7a5..6859526 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -39,7 +39,7 @@ struct __attribute__((packed)) tss { struct process; extern "C" void ftl_to_userspace(void* program, amy::byte* stack); -void run_first_process(amy::i64 pid); +void run_first_process(amy::pid pid); extern "C" void load_tss(); extern "C" void syscall_64bit_handler(); @@ -82,10 +82,10 @@ struct process { incrementing_int64_map ports; }; -static_assert(0xFFFF'C000'0000'0000 + sizeof(incrementing_int64_map) < 0xFFFF'FFFF'8000'0000); +static_assert(0xFFFF'C000'0000'0000 + amy::byte_size>() < 0xFFFF'FFFF'8000'0000); extern incrementing_int64_map& processes; extern "C" amy::pid current_pid; -extern "C" process& get_process(amy::i64 pid); +extern "C" process& get_process(amy::pid pid); } // namespace os diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index a686584..5f2f58a 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -95,7 +95,7 @@ void os::print_formatted(const char* format, const void* val) { os::assert(format[0] == '}', "Format string unsupported. TODO."); os::print("0x"); for (int i = 60; i >= 0; i -= 4) { - const int v = (reinterpret_cast(val) >> i) & 0xF; + const int v = (reinterpret_cast(val) >> i) & 0xF; os::printc(v < 10 ? v + '0' : v - 10 + 'a'); } } diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index 035760e..b3a8edb 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -75,7 +75,7 @@ public: private: struct elem_t { bool present; - alignas(T) amy::byte buffer[sizeof(T)]; + alignas(T) amy::byte buffer[amy::byte_size()]; }; amy::i64 n = 0; static constexpr amy::i64 max_n = 4096; diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp index 81ae2a6..40c38d5 100644 --- a/libcpp/memory.hpp +++ b/libcpp/memory.hpp @@ -29,9 +29,18 @@ inline void operator delete[](void*, void*) noexcept {} namespace amy { -// Taken from glibcxx, should be fine copyright-wise: +// "Launder" taken from glibcxx, should be fine copyright-wise: template [[nodiscard]] constexpr T* launder(T* p) noexcept { return __builtin_launder(p); } + + +template constexpr size byte_size() { + return sizeof(T); +} +template constexpr size byte_align() { + return alignof(T); +} + } // namespace amy diff --git a/libcpp/types.hpp b/libcpp/types.hpp index 2e7f2d6..94c4598 100644 --- a/libcpp/types.hpp +++ b/libcpp/types.hpp @@ -27,14 +27,15 @@ using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; -using iptr = intptr_t; -using uptr = uintptr_t; -using dptr = __PTRDIFF_TYPE__; -using nptr = decltype(nullptr); +using ptr = intptr_t; +constexpr auto nil = nullptr; +using nil_t = decltype(nil); using size = i64; +using diff = i64; +static_assert(sizeof(diff) >= sizeof(__PTRDIFF_TYPE__)); -using pid = i64; -using fd = i64; +enum class pid : i64 {}; +enum class fd : i64 {}; } // namespace amy diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index a66ecd2..421ce3f 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -37,8 +37,8 @@ extern "C" int close(amy::fd file); extern "C" void loop_de_loop(); extern "C" void _start() { - sys::mount_kernel_device(-1, 'I', "/", 1, MOUNT_REPLACE); // 'I' is the I/O device. /serial is the serial port /fb is the framebuffer - const amy::fd serial = sys::open(-1, "/serial", 7, MODE_WRITE); + sys::mount_kernel_device(amy::fd(-1), 'I', "/", 1, MOUNT_REPLACE); // 'I' is the I/O device. /serial is the serial port /fb is the framebuffer + const amy::fd serial = sys::open(amy::fd(-1), "/serial", 7, MODE_WRITE); sys::write(serial, "Entrez votre nom: ", 18); char data[32]; -- 2.47.0 From afbd82992ce0a2a9825a3c422b5f74cad91fa87a Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Mon, 25 Dec 2023 01:40:21 +0100 Subject: [PATCH 06/16] Ajout de declval --- libcpp/memory.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp index 40c38d5..2c01f93 100644 --- a/libcpp/memory.hpp +++ b/libcpp/memory.hpp @@ -17,7 +17,7 @@ // See the C++ documentation for documentation. -// Placement new and delete (taken from glibcxx, should be fine copyright-wise): +// Implementation for placement new and delete taken from glibcxx. [[nodiscard]] inline void* operator new(unsigned long, void* p) noexcept { return p; } @@ -29,7 +29,7 @@ inline void operator delete[](void*, void*) noexcept {} namespace amy { -// "Launder" taken from glibcxx, should be fine copyright-wise: +// Implementation for launder taken from glibcxx. template [[nodiscard]] constexpr T* launder(T* p) noexcept { return __builtin_launder(p); @@ -42,5 +42,9 @@ template constexpr size byte_size() { template constexpr size byte_align() { return alignof(T); } +// Implementation based on https://en.cppreference.com/w/cpp/utility/declval +template constexpr T&& declval() noexcept { + static_assert(false, "amy::declval cannot be used in an evaluated context."); +} } // namespace amy -- 2.47.0 From 5b6c2ca63b4a6e65ab9b93625407d42c33c9668e Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Mon, 25 Dec 2023 02:06:33 +0100 Subject: [PATCH 07/16] =?utf8?q?D=C3=A9placement=20de=20memset=20et=20memc?= =?utf8?q?py=20vers=20la=20"librairie=20standard"?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/src/elf64.cpp | 6 +++--- kernel/src/kernel.cpp | 2 +- kernel/src/paging.hpp | 2 +- kernel/src/utils.cpp | 14 -------------- kernel/src/utils.hpp | 2 -- libcpp/memory.hpp | 14 ++++++++++++++ 6 files changed, 19 insertions(+), 21 deletions(-) diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index 239cb6b..d5df9d9 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -55,8 +55,8 @@ void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, result.r15 = 0; // Copy kernel mappings to the new virtual address space. - memset(result.PML4T->contents, 0, 256 * amy::byte_size()); - memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * amy::byte_size()); + amy::memset(result.PML4T->contents, 0, 256 * amy::byte_size()); + amy::memcpy(result.PML4T->contents + 256, original_PML4T.contents + 256, 256 * amy::byte_size()); for (amy::size i = 0; i < elf_header.entry_count_program_header_table; i++) { const os::elf::program_header program_header = *(os::elf::program_header*)( @@ -82,7 +82,7 @@ void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, .US = true, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = false, .AVL = 0, .NX = (program_header.flags & 1) == 0, }); - memcpy((void*)alloc.ptr, start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul)); + amy::memcpy((void*)alloc.ptr, start + program_header.p_offset, clamp(0ul, program_header.p_filesz - i * 0x1000, 0x1000ul)); } } } diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index cc709be..233770e 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -180,7 +180,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> (12 + 9 * 3)) & 0x1FF; os::paging::global_PML4T.contents[index].paging_table_info({.RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false}); const auto PDPT_alloc = os::paging::page_allocator.allocate(1); - os::memset((void*)PDPT_alloc.ptr, 0, 0x1000); + amy::memset((void*)PDPT_alloc.ptr, 0, 0x1000); os::paging::global_PML4T.contents[index].paging_table_ptr(os::phys_ptr(PDPT_alloc.ptr.get_phys_addr())); } diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index 7b8087d..ede7e3b 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -230,7 +230,7 @@ void map_page(paging_table& paging_table, page const* vaddr } else { auto const alloc = page_allocator.allocate(1); assert(alloc.ptr != nullptr, "Not enough RAM to create the paging structures."); - memset((void*)alloc.ptr, 0, 0x1000); + amy::memset((void*)alloc.ptr, 0, 0x1000); paging_table.contents[index].paging_table_info( {.RW = true, .US = page_info.US, .PWT = false, .PCD = false, .A = false, .AVL = 0, .NX = false}); paging_table.contents[index].paging_table_ptr(os::phys_ptr>{alloc.ptr.get_phys_addr()}); diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index 43a8c2b..64c88f0 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -50,17 +50,3 @@ amy::u64 os::get_msr(amy::u32 msr) { void os::set_msr(amy::u32 msr, amy::u64 v) { asm volatile ("wrmsr" : : "a"(v & 0xFFFF'FFFF), "d"((v >> 32) & 0xFFFF'FFFF), "c"(msr)); } -extern "C" void* os::memset(void* dest, int c, amy::size n) { - os::assert(n >= 0, "Memset expects a positive size."); - while (n-- > 0) { - reinterpret_cast(dest)[n] = amy::byte(c); - } - return dest; -} -extern "C" void* os::memcpy(void* dest, const void* src, amy::size n) { - os::assert(n >= 0, "Memcpy expects a positive size."); - while (n-- > 0) { - reinterpret_cast(dest)[n] = reinterpret_cast(src)[n]; - } - return dest; -} diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index b3a8edb..3ac872f 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -31,8 +31,6 @@ void set_msr(amy::u32 msr, amy::u64 v); template T clamp(T min, T v, T max) { return v < min ? min : max < v ? max : v; } -extern "C" void* memset(void* dest, int c, amy::size n); -extern "C" void* memcpy(void* dest, const void* src, amy::size n); template struct incrementing_int64_map { diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp index 2c01f93..f8c3b7e 100644 --- a/libcpp/memory.hpp +++ b/libcpp/memory.hpp @@ -47,4 +47,18 @@ template constexpr T&& declval() noexcept { static_assert(false, "amy::declval cannot be used in an evaluated context."); } + +extern "C" inline void* memset(void* dest, int c, amy::size n) { + while (n-- > 0) { + reinterpret_cast(dest)[n] = amy::byte(c); + } + return dest; +} +extern "C" inline void* memcpy(void* dest, const void* src, amy::size n) { + while (n-- > 0) { + reinterpret_cast(dest)[n] = reinterpret_cast(src)[n]; + } + return dest; +} + } // namespace amy -- 2.47.0 From 1f5bae1f4a41bc90193462aabf28505daf0803de Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Mon, 25 Dec 2023 11:45:57 +0100 Subject: [PATCH 08/16] =?utf8?q?J'ai=20toujours=20=C3=A9t=C3=A9=20p=C3=A9d?= =?utf8?q?ante?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- kernel/src/interrupts.hpp | 2 +- kernel/src/lib/multiboot2.hpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f8ac673..9fe55cf 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif build: # Build as default target -CXXFLAGS := -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror \ +CXXFLAGS := -std=c++20 -fno-strict-aliasing -Wall -Wextra -pedantic -Werror \ -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -O2 \ -I libcpp $(CXXFLAGS) LDFLAGS := $(CXXFLAGS) $(LDFLAGS) diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index 564a4b6..1ea335f 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -52,7 +52,7 @@ void set_APIC_reg(amy::diff offset, amy::u32 v); struct isr_info { amy::ptr addr; - enum class type_t { trap_gate = 0xF, interrupt_gate = 0xE }; + enum class type_t : unsigned char { trap_gate = 0xF, interrupt_gate = 0xE }; type_t type : 4; amy::u8 dpl: 2 = 0b00; bool present : 1 = true; diff --git a/kernel/src/lib/multiboot2.hpp b/kernel/src/lib/multiboot2.hpp index 719edd8..1f1fd41 100644 --- a/kernel/src/lib/multiboot2.hpp +++ b/kernel/src/lib/multiboot2.hpp @@ -63,7 +63,7 @@ }; type_t type; amy::u32 size; - amy::u8 rest[]; + amy::u8 rest[9223372036854775799]; }; inline os::phys_ptr next(os::phys_ptr ptr) { -- 2.47.0 From 3ed3b1becd5d90608484f25abc6a8ff55c55d96c Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Wed, 27 Dec 2023 01:14:42 +0100 Subject: [PATCH 09/16] =?utf8?q?J'ai=20commenc=C3=A9=20=C3=A0=20impl=C3=A9?= =?utf8?q?menter=20des=20alloueurs=20de=20m=C3=A9moire,=20et=20=C3=A0=20le?= =?utf8?q?s=20utiliser?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/src/kernel.cpp | 28 +++--- libcpp/allocator.hpp | 198 ++++++++++++++++++++++++++++++++++++++++++ libcpp/concept.hpp | 33 +++++++ libcpp/vector.hpp | 103 ++++++++++++++++++++++ 4 files changed, 350 insertions(+), 12 deletions(-) create mode 100644 libcpp/allocator.hpp create mode 100644 libcpp/concept.hpp create mode 100644 libcpp/vector.hpp diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 233770e..42d0355 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -11,6 +11,8 @@ // You should have received a copy of the GNU General Public License along with this program. If // not, see . +#include +#include #include "lib/multiboot2.hpp" #include "paging.hpp" #include "utils.hpp" @@ -185,10 +187,13 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> start_address = nullptr; - os::phys_ptr> end_address = nullptr; - } available_ram[50]; + struct ram_range { + os::phys_ptr> start_address; + os::phys_ptr> end_address; + }; + amy::stack_allocator() * 64, amy::byte_align()> available_ram_allocator; + amy::vector available_ram(available_ram_allocator); + os::assert(!available_ram.construction_failed(), "Failed to create vector."); amy::size available_ram_length = 0; bool module_specified = false; @@ -210,8 +215,8 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> kernel_e{amy::ptr(&_kernel_phys_end)}; // Remove kernel from available RAM: - for (amy::ptr i = 0; i < available_ram_length; i++) { + for (amy::diff i = 0; i < available_ram.size(); i++) { if (kernel_e < available_ram[i].start_address || available_ram[i].end_address < kernel_s) { continue; } @@ -245,16 +250,15 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr. + +#pragma once + +#include +#include +#include + +// The design is based on Andrei Alexandrescu's "std::allocator is to allocation what std::vector is to vexation". +// See https://github.com/CppCon/CppCon2015/tree/master/Presentations/allocator%20Is%20to%20Allocation%20what%20vector%20Is%20to%20Vexation for more details. + +namespace amy { + +template using allocator_helper = void; + +template +concept allocator = requires(T allocator) { + // max_align is the maximum alignment that this allocator can provide. + // post: max_align ≥ 1 + // post: max_align is a power of 2 + typename allocator_helper; + // good_size(size, align) returns the actual amount of bytes that will be allocated for a call to allocate(size, align). + // pre: size ≥ 1 + // pre: align ≥ 1 + // pre: align is a power of 2 + // pre: max_align ≡ 0 [align] + // post: good_size(size, align) ≥ size + // post: ∀n ≥ 0, good_size(size + n, align) ≥ good_size(size, align) + // post: ∀n ≥ 0, good_size(size, align + n) ≥ good_size(size, align) + { T::good_size(amy::declval(), amy::declval()) } -> amy::same_as; + typename allocator_helper; + // allocate(size, align) returns a pointer to a memory area of at least size bytes, aligned to align bytes, or nullptr + // pre: size ≥ 1 + // pre: align ≥ 1 + // pre: align is a power of 2 + // pre: max_align ≡ 0 [align] + { allocator.allocate(amy::declval(), amy::declval()) } -> amy::same_as; + // expand(ptr, size, delta) tries to change the size of the allocation at ptr from size to size+delta. + // If delta = 0, returns true and does nothing. + // If the memory area at ptr can be resized to size, do it and return true. + // Otherwise, return false, leaving the memory at ptr unchanged. + // pre: ptr is a pointer to a memory area of size size allocated by this allocator + // pre: size + delta ≥ 1 + { allocator.expand(amy::declval(), amy::declval(), amy::declval()) } -> amy::same_as; + // deallocate(ptr, size, align) invalidates the memory area at ptr. + // This function cannot fail. + // pre: ptr is a pointer to a memory area of size size and alignment align allocated by this allocator + { allocator.deallocate(amy::declval(), amy::declval(), amy::declval()) } -> amy::same_as; +}; + + +// reallocate(allocator, ptr, old_size, new_size, align) tries to resize this memory area, or to create a new one, such that +// the contents of it, up to the byte min(old_size, new_size), are identical, and the resulting area is aligned to align. +// If this fails, it will return amy::nil. +// Otherwise, it will return the new pointer to the area. The old one shouldn't be used anymore. +// pre: ptr is a pointer to a memory area of size old_size and alignment align allocated by the allocator allocator. +// pre: new_size ≥ 1 +void* reallocate(allocator auto allocator, void* ptr, amy::size old_size, amy::size new_size, amy::size align) { + if (allocator.expand(ptr, old_size, new_size - old_size)) { + return ptr; + } + void* res = allocator.allocate(new_size, align); + if (res == amy::nil) { + return amy::nil; + } + amy::memcpy(res, ptr, old_size < new_size ? old_size : new_size); + allocator.deallocate(ptr, old_size, align); + return res; +} + +template +concept knowning_allocator = allocator && requires(T allocator) { + // owns(ptr) returns true if, and only if, ptr is a pointer to a memory area allocated by this allocator. + // pre: ptr is a pointer to a memory area allocated by **ANY** allocator + { allocator.owns(amy::declval()) } -> amy::same_as; +}; + +template struct stack_allocator { + static_assert(data_size >= 0); + static_assert(data_align >= 1); + static_assert((data_align & (data_align - 1)) == 0); // Assert power of 2. + + static constexpr amy::size good_size(amy::size size, amy::size) { + return size; + } + static constexpr amy::size max_align = data_align; + void* allocate(amy::size size, amy::size align) { + amy::diff aligned_first_free_byte = (first_free_byte + (align - 1)) / align * align; + if (aligned_first_free_byte + size > data_size) { + return amy::nil; + } + first_free_byte = aligned_first_free_byte + size; + return &data[aligned_first_free_byte]; + } + bool expand(void* ptr, amy::size size, amy::diff delta) { + if (delta == 0) { + return true; + } + if ((amy::byte*)ptr - data + size == first_free_byte) { + if ((amy::byte*)ptr - data + size + delta > data_size) { + return false; + } + first_free_byte = (amy::byte*)ptr - data + size + delta; + return true; + } else { + return delta < 0; + } + } + void deallocate(void* ptr, amy::size size, amy::size) { + if ((amy::byte*)ptr - data + size == first_free_byte) { + first_free_byte = (amy::byte*)ptr - data; + } + } + bool owns(void* ptr) { + return amy::ptr(&data) <= amy::ptr(ptr) && amy::ptr(ptr) < amy::ptr(&data) + data_size; + } +private: + amy::byte __attribute__((aligned(data_align))) data[data_size]; + amy::diff first_free_byte = 0; +}; + +template +struct freelist { + static_assert(min_data_size >= 1); + static_assert(max_data_size >= min_data_size); + // static_assert(max_data_size >= amy::byte_size()); // Enough room for intrusive list. + static_assert(min_data_align >= 1); + static_assert(max_data_align >= min_data_align); + static_assert((min_data_align & (min_data_align - 1)) == 0); // Assert power of 2. + static_assert((max_data_align & (max_data_align - 1)) == 0); // Assert power of 2. + static_assert(max_data_align <= suballocator_t::max_align); + static_assert(min_data_size == 1 || suballocator_t::good_size(min_data_size - 1, max_data_align) < min_data_size); + static_assert(suballocator_t::good_size(max_data_size, max_data_align) == max_data_size); +private: + struct block { + block* next; + amy::byte padding[max_data_size - amy::byte_size]; + }; + +public: + static constexpr amy::size good_size(amy::size size, amy::size align) { + if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { + return suballocator_t::good_size(size, align); + } + return max_data_size; + } + static constexpr amy::size max_align = suballocator_t::max_align; + void* allocate(amy::size size, amy::size align) { + if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { + return sub.allocate(size, align); + } + if (head == amy::nil) { + return sub.allocate(max_data_size, max_data_align); + } + block* new_head = head->next; + block* old_head = head; + old_head->~block(); + head = new_head; + return old_head; + } + bool expand(void* ptr, amy::size size, amy::diff delta) { + if (min_data_size <= size && size <= max_data_size) { + delta = (size + delta) - max_data_size; + size = max_data_size; + } + if (min_data_size <= size + delta && size + delta <= max_data_size) { + delta = max_data_size - size; + } + return sub.expand(ptr, size, delta); + } + void deallocate(void* ptr, amy::size size, amy::size align) { + if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { + return sub.deallocate(ptr, size, align); + } + new(ptr) block; + amy::launder(reinterpret_cast(ptr))->next = head; + head = amy::launder(reinterpret_cast(ptr)); + } + bool owns(void* ptr) requires knowning_allocator { + return sub.owns(ptr); + } +private: + suballocator_t sub; + block* head = amy::nil; +}; + +} // namespace amy diff --git a/libcpp/concept.hpp b/libcpp/concept.hpp new file mode 100644 index 0000000..f63608b --- /dev/null +++ b/libcpp/concept.hpp @@ -0,0 +1,33 @@ +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . + +#pragma once + +#include +#include + +namespace amy { + +template +struct same_as_helper { + constexpr static bool v = false; +}; +template +struct same_as_helper { + constexpr static bool v = true; +}; + +template +concept same_as = same_as_helper::v; + +} // namespace amy diff --git a/libcpp/vector.hpp b/libcpp/vector.hpp new file mode 100644 index 0000000..0b217ea --- /dev/null +++ b/libcpp/vector.hpp @@ -0,0 +1,103 @@ +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . + +#pragma once + +#include +#include +#include + +namespace amy { + +template +struct vector { + static_assert(amy::byte_align() <= allocator_t::max_align); + +public: + vector(allocator_t& allocator): allocator(allocator) { + size_ = 0; + capacity_ = 1; + data = (T*)allocator.allocate(capacity_ * amy::byte_size(), amy::byte_align()); + } + bool construction_failed() { + return data == amy::nil; + } + ~vector() { + if (data != amy::nil) { + for (amy::diff i = 0; i < size_; i++) { + data[i].~T(); + } + allocator.deallocate(data, capacity_ * amy::byte_size(), amy::byte_align()); + } + } + + vector(const vector& other) { + size_ = other.size_; + capacity_ = size_ == 0 ? 1 : size_; + data = allocator.allocate(capacity_ * amy::byte_size(), amy::byte_align()); + if (data == amy::nil) { + return; + } + for (amy::diff i = 0; i < size_; i++) { + new(&data[i]) T(other.data[i]); + } + } + vector(vector&& other): allocator(other.allocator) { + data = other.data; + other.data = amy::nil; + size_ = other.size_; + capacity_ = other.capacity_; + } + vector& operator=(const vector& other) = delete; // Later, when contracts work. Because allocators must be the same. + vector& operator=(vector&& other) = delete; + + amy::size size() { + return size_; + } + amy::size capacity() { + return capacity_; + } + bool push_back(const T& v) { + if (size_ == capacity_) { + if (allocator.expand(data, capacity_ * amy::byte_size(), amy::byte_size())) { + capacity_++; + } else if (auto new_data = + amy::reallocate(allocator, data, capacity_ * amy::byte_size(), capacity_ * 2 * amy::byte_size(), amy::byte_align())) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdangling-pointer" + data = (T*)new_data; +#pragma GCC diagnostic pop + capacity_ *= 2; + } else { + return false; + } + } + size_++; + new(&data[size_ - 1]) T(v); + return true; + } + T& operator[](amy::size i) { + return data[i]; + } + const T& operator[](amy::size i) const { + return data[i]; + } + +private: + T* data; + amy::size size_; + amy::size capacity_; + allocator_t& allocator; +}; + +} // namespace amy -- 2.47.0 From b8eb61a15beb07a3361c324bead97c65cbd966a4 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Wed, 27 Dec 2023 01:24:50 +0100 Subject: [PATCH 10/16] =?utf8?q?Puisque=20j'ai=20retir=C3=A9=20le=20hack?= =?utf8?q?=20d=C3=A9gueu,=20je=20n'ai=20plus=20besoin=20de=20cette=20libra?= =?utf8?q?irie=20standard?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- configure | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/configure b/configure index 50bab00..84f4ca8 100755 --- a/configure +++ b/configure @@ -7,19 +7,12 @@ # You should have received a copy of the CC0 Public Domain Dedication along # with this software. If not, see . -printf '' > Makefile-conf - -TEMP=$(getopt -o 'h' --long 'prefix:,c++-includes-stdlib:,build:,enable-fast-install,help' -n 'download-playlist' -- "$@") || (echo 'Terminating.' >&2; exit 1) +TEMP=$(getopt -o 'h' --long 'prefix:,build:,enable-fast-install,help' -n 'download-playlist' -- "$@") || (echo 'Terminating.' >&2; exit 1) eval set -- "$TEMP" unset TEMP while true; do case "$1" in - '--c++-includes-stdlib') - INCLUDES="$2" - shift 2 - continue - ;; '--prefix') PREFIX="$2" shift 2 @@ -34,8 +27,7 @@ while true; do continue ;; '-h'|'--help') - echo '--prefix Install prefix' - echo '--c++-includes-stdlib C++ standard library include files location' + echo '--prefix Install prefix' shift exit 0 ;; @@ -52,11 +44,5 @@ if test "$PREFIX" = ""; then exit 1 fi -if test "$INCLUDES" = ""; then - echo 'Missing argument: --c++-includes-stdlib.' >&2 - echo 'See --help for more detail.' >&2 - exit 1 -fi - +printf '' > Makefile-conf echo "PREFIX = $PREFIX" >> Makefile-conf -echo "INCLUDES = $INCLUDES" >> Makefile-conf -- 2.47.0 From 027ab6719a30395276053f545d72a42308d1b15e Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Fri, 29 Dec 2023 04:29:14 +0100 Subject: [PATCH 11/16] Remplacement de os::assert par une macro assert dans la "librairie standard" --- kernel/src/elf64.cpp | 25 +++++++++++++------------ kernel/src/interrupts.cpp | 4 ++-- kernel/src/interrupts.hpp | 6 ++---- kernel/src/kernel.cpp | 23 ++++++++++++----------- kernel/src/lib/phys_ptr.hpp | 6 ++++++ kernel/src/paging.hpp | 19 ++++++++++--------- kernel/src/ring3.cpp | 17 +++++++++-------- kernel/src/serial.cpp | 17 ++++++++++++----- kernel/src/serial.hpp | 34 +++++++++------------------------- kernel/src/utils.hpp | 9 +++++---- libcpp/assert.hpp | 20 ++++++++++++++++++++ 11 files changed, 100 insertions(+), 80 deletions(-) create mode 100644 libcpp/assert.hpp diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index d5df9d9..9ced6fb 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -12,29 +12,30 @@ // not, see . #include "elf64.hpp" +#include void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, const paging::PML4T& original_PML4T) { - os::assert(length >= amy::byte_size(), "Elf file isn't big enough to contain a header: there is an error."); + assert(length >= amy::byte_size(), "Elf file isn't big enough to contain a header: there is an error."); // TODO: Check that the elf file sections are all fully inside the file. // Load test-module elf file: const os::elf::header elf_header = *(os::elf::header*)start; // Check if elf is valid: - os::assert(elf_header.magic[0] == '\x7f', "No elf header."); - os::assert(elf_header.magic[1] == 'E', "No elf header."); - os::assert(elf_header.magic[2] == 'L', "No elf header."); - os::assert(elf_header.magic[3] == 'F', "No elf header."); - os::assert(elf_header.bitn == 2, "Elf file not 64 bits."); - os::assert(elf_header.endianness == 1, "Elf file not little endian."); - os::assert(elf_header.type == 2, "Elf file not executable."); - os::assert(elf_header.arch == 0x3E, "Elf file not x86_64."); + assert(elf_header.magic[0] == '\x7f', "No elf header."); + assert(elf_header.magic[1] == 'E', "No elf header."); + assert(elf_header.magic[2] == 'L', "No elf header."); + assert(elf_header.magic[3] == 'F', "No elf header."); + assert(elf_header.bitn == 2, "Elf file not 64 bits."); + assert(elf_header.endianness == 1, "Elf file not little endian."); + assert(elf_header.type == 2, "Elf file not executable."); + assert(elf_header.arch == 0x3E, "Elf file not x86_64."); constexpr amy::size stack_size = 16 * 0x1000 /* 64KiB */; amy::byte* const stack = (amy::byte*)0x0000'8000'0000'0000 - stack_size; const auto page = os::paging::page_allocator.allocate(1); - os::assert(page.ptr != nullptr, "Not enough memory for elf file loading."); + assert(page.ptr != amy::nil, "Not enough memory for elf file loading."); result.PML4T = phys_ptr(page.ptr.get_phys_addr()); result.rip = amy::u64(elf_header.entry); result.rsp = amy::u64(stack + stack_size); @@ -68,7 +69,7 @@ void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, continue; } os::print("Segment: loadable\n"); - os::assert(0x1000 <= amy::u64(program_header.p_vaddr) + assert(0x1000 <= amy::u64(program_header.p_vaddr) && amy::u64(program_header.p_vaddr + program_header.p_memsz) < 0x10'0000'0000, "Program segments must be contained between 0x1000 and 0x10'0000'0000 (i.e. 64GiB)."); @@ -76,7 +77,7 @@ void os::elf::load_elf(os::process& result, amy::byte* start, amy::size length, amy::size nb_pages = (amy::u64(program_header.p_vaddr) % 0x1000 + program_header.p_memsz + 0x1000 - 1) / 0x1000; for (amy::size i = 0; i < nb_pages; i++) { auto const alloc = os::paging::page_allocator.allocate(1); - os::assert(alloc.ptr != nullptr, "Failed to allocate enough memory for loading of elf binary."); + assert(alloc.ptr != nullptr, "Failed to allocate enough memory for loading of elf binary."); os::paging::map_page(*result.PML4T, (os::paging::page<0>*)(program_header.p_vaddr + i * 0x1000), alloc.ptr, { .RW = ((program_header.flags & 2) >> 1) != 0, .US = true, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = false, .AVL = 0, diff --git a/kernel/src/interrupts.cpp b/kernel/src/interrupts.cpp index 2288039..3b7d9ef 100644 --- a/kernel/src/interrupts.cpp +++ b/kernel/src/interrupts.cpp @@ -112,7 +112,7 @@ extern "C" void int_page_fault(amy::u32 err_code, amy::u64 vaddr) { ) { // Kernel memory os::print("Allocating (Ring 0): {}\n", (void*)vaddr); auto const alloc = os::paging::page_allocator.allocate(1); - os::assert(alloc.ptr != nullptr, "Out of memory."); + assert(alloc.ptr != nullptr, "Out of memory."); os::paging::map_page(os::paging::global_PML4T, (os::paging::page<0>*)vaddr, alloc.ptr, {.RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true}); return; @@ -121,7 +121,7 @@ extern "C" void int_page_fault(amy::u32 err_code, amy::u64 vaddr) { ) { // Userspace memory os::print("Allocating (Ring 3): {}\n", (void*)vaddr); auto const alloc = os::paging::page_allocator.allocate(1); - os::assert(alloc.ptr != nullptr, "Out of memory."); + assert(alloc.ptr != nullptr, "Out of memory."); os::paging::map_page(*os::get_process(os::current_pid).PML4T, (os::paging::page<0>*)vaddr, alloc.ptr, {.RW = true, .US = true, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = false, .AVL = 0, .NX = true}); return; diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index 1ea335f..846168f 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -14,6 +14,7 @@ #pragma once #include +#include #include "lib/phys_ptr.hpp" #include "serial.hpp" #include "utils.hpp" @@ -58,12 +59,9 @@ struct isr_info { bool present : 1 = true; }; -template -void assert(bool cond, const char* format, const Ts&... vs); - template void enable_interrupts(const isr_info (&ISRs)[interrupt_nb], os::idt& idt) { - os::assert(is_APIC_builtin(), "No builtin APIC."); + assert(is_APIC_builtin(), "No builtin APIC."); disable_PIC(); set_APIC_reg(0xF0, 0x1FF); // Enable APIC diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 42d0355..76dcd4a 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -13,6 +13,7 @@ #include #include +#include #include "lib/multiboot2.hpp" #include "paging.hpp" #include "utils.hpp" @@ -37,18 +38,18 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr>(amy::ptr(&bootstrap_pages_for_memory) & amy::ptr(~0xFFFF'FFFF'8000'0000)), .size = amy::byte_size() / amy::byte_size() }); - os::assert(os::cpu_has_msr(), "MSRs aren't supported."); + assert(os::cpu_has_msr(), "MSRs aren't supported."); // Initialise kernel map. - os::assert(amy::ptr(&_kernel_phys_start) % 4096 == 0, "Kernel isn't page aligned !"); - os::assert(amy::ptr(&_kernel_phys_rw_start) % 4096 == 0, "Kernel isn't page aligned !"); - os::assert(amy::ptr(&_kernel_phys_end) % 4096 == 0, "Kernel isn't page aligned !"); + assert(amy::ptr(&_kernel_phys_start) % 4096 == 0, "Kernel isn't page aligned !"); + assert(amy::ptr(&_kernel_phys_rw_start) % 4096 == 0, "Kernel isn't page aligned !"); + assert(amy::ptr(&_kernel_phys_end) % 4096 == 0, "Kernel isn't page aligned !"); for (amy::size i = amy::ptr(&_kernel_phys_start); i < amy::ptr(&_kernel_phys_rw_start); ) { if (i % (1024 * 1024 * 1024) == 0 && i + 1024 * 1024 * 1024 < amy::ptr(&_kernel_phys_rw_start)) { os::paging::map_page<2, 3>(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), @@ -94,8 +95,8 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr( @@ -193,7 +194,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr() * 64, amy::byte_align()> available_ram_allocator; amy::vector available_ram(available_ram_allocator); - os::assert(!available_ram.construction_failed(), "Failed to create vector."); + assert(!available_ram.construction_failed(), "Failed to create vector."); amy::size available_ram_length = 0; bool module_specified = false; @@ -215,7 +216,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr> kernel_s{amy::ptr(&_kernel_phys_start)}; @@ -250,7 +251,7 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr #include +#include namespace os { @@ -28,9 +29,11 @@ public: constexpr phys_ptr(amy::nil_t): phys_addr(0xF000'0000'0000'0000) {} inline void* operator->() const { + assert(*this != amy::nil); return get_virt_addr(); } inline explicit operator void*() const { + assert(*this != amy::nil); return get_virt_addr(); } @@ -60,12 +63,15 @@ public: constexpr phys_ptr(amy::nil_t): phys_addr(0xF000'0000'0000'0000) {} T& operator[](amy::diff i) const { + assert(*this != amy::nil); return get_virt_addr()[i]; } T& operator*() const { + assert(*this != amy::nil); return *get_virt_addr(); } T* operator->() const { + assert(*this != amy::nil); return get_virt_addr(); } explicit operator T*() const { diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index ede7e3b..67df518 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -13,10 +13,11 @@ #pragma once +#include #include +#include "lib/phys_ptr.hpp" #include "serial.hpp" #include "utils.hpp" -#include "lib/phys_ptr.hpp" namespace os { namespace paging { @@ -53,12 +54,12 @@ template struct paging_entry { return (data & (1 << 0)) != 0; } bool is_page() { - os::assert(is_present(), "Cannot check if a paging_entry is a page if it's not present."); + assert(is_present(), "Cannot check if a paging_entry is a page if it's not present."); return depth == 0 || (data & (1 << 7)) != 0; } paging::page_info page_info() { - os::assert(is_page(), "Cannot access page info for a non-page."); + assert(is_page(), "Cannot access page info for a non-page."); return { .RW = (data & (1ull << 1)) != 0, .US = (data & (1ull << 2)) != 0, @@ -76,12 +77,12 @@ template struct paging_entry { }; } os::phys_ptr> page_ptr() { - os::assert(is_page(), "Cannot access page physical pointer for a non-page."); + assert(is_page(), "Cannot access page physical pointer for a non-page."); amy::ptr addr = data & (depth == 0 ? 0x0000'FFFF'FFFF'F000 : 0x0000'FFFF'FFFF'E000); return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void page_ptr(os::phys_ptr> page) { - os::assert(is_page(), "Cannot access page physical pointer for a non-page."); + assert(is_page(), "Cannot access page physical pointer for a non-page."); if (depth == 0) { data = (data & ~0x0000'FFFF'FFFF'F000) | page.get_phys_addr(); } else { @@ -89,7 +90,7 @@ template struct paging_entry { } } paging::paging_table_info paging_table_info() { - os::assert(!is_page(), "Cannot access paging table info for a page."); + assert(!is_page(), "Cannot access paging table info for a page."); return { .RW = (data & (1ull << 1)) != 0, .US = (data & (1ull << 2)) != 0, @@ -103,12 +104,12 @@ template struct paging_entry { }; } os::phys_ptr> paging_table_ptr() { - os::assert(!is_page(), "Cannot access paging table physical pointer for a page."); + assert(!is_page(), "Cannot access paging table physical pointer for a page."); amy::ptr addr = data & 0x0000'FFFF'FFFF'F000; return os::phys_ptr>(addr | ((addr & 0x0000'8000'0000'0000) != 0 ? 0xFFFF'8000'0000'0000 : 0)); } void paging_table_ptr(os::phys_ptr> table) { - os::assert(!is_page(), "Cannot access paging table physical pointer for a page."); + assert(!is_page(), "Cannot access paging table physical pointer for a page."); data = (data & ~0x0000'FFFF'FFFF'F000) | table.get_phys_addr(); } void remove() { @@ -220,7 +221,7 @@ template void map_page(paging_table& paging_table, page const* vaddr, phys_ptr> paddr, os::paging::page_info page_info) { amy::size const index = (amy::ptr(vaddr) >> (12 + 9 * paging_depth)) & 0x1FF; if constexpr (depth == paging_depth) { - os::assert(!paging_table.contents[index].is_present(), "Virtual address 0x{} is already mapped.", vaddr); + assert(!paging_table.contents[index].is_present(), "Virtual address 0x{} is already mapped.", vaddr); paging_table.contents[index].page_info(page_info); paging_table.contents[index].page_ptr(paddr); invlpg(vaddr); diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index 5df22c5..f0716d5 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -11,6 +11,7 @@ // You should have received a copy of the GNU General Public License along with this program. If // not, see . +#include #include "ring3.hpp" #include "utils.hpp" #include "serial.hpp" @@ -51,19 +52,19 @@ void schedule_next_process() { // extern "C" int os::syscall_mount_kernel_device(amy::fd wd, char device, char const* path, amy::size path_len, int mount_type); extern "C" int os::syscall_mount_kernel_device(amy::fd, char, char const*, amy::size, int) { - os::assert(false, "mount_kernel_device not implemented yet."); + assert(false, "mount_kernel_device not implemented yet."); __builtin_unreachable(); } // extern "C" amy::fd os::syscall_open(amy::fd wd, char const* path, amy::size path_len, int options); extern "C" amy::fd os::syscall_open(amy::fd, char const*, amy::size, int) { - os::assert(false, "open not implemented yet."); + assert(false, "open not implemented yet."); __builtin_unreachable(); } extern "C" amy::size os::syscall_read(amy::fd file, char* data, amy::size len) { - os::assert(file == amy::fd(0), "Read isn't really implemented for now."); - os::assert(len >= 0, "Read expects a positive size."); + assert(file == amy::fd(0), "Read isn't really implemented for now."); + assert(len >= 0, "Read expects a positive size."); if (len == 0) { return 0; } @@ -82,8 +83,8 @@ extern "C" amy::size os::syscall_read(amy::fd file, char* data, amy::size len) { } extern "C" amy::size os::syscall_write(amy::fd file, char const* data, amy::size len) { - os::assert(file == amy::fd(0), "Write isn't really implemented for now."); - os::assert(len >= 0, "Write expects a positive size."); + assert(file == amy::fd(0), "Write isn't really implemented for now."); + assert(len >= 0, "Write expects a positive size."); if (len == 0) { return 0; } @@ -99,12 +100,12 @@ extern "C" amy::size os::syscall_write(amy::fd file, char const* data, amy::size // extern "C" int syscall_close(amy::fd file); extern "C" int os::syscall_close(amy::fd) { - os::assert(false, "Close isn't implemented for now."); + assert(false, "Close isn't implemented for now."); __builtin_unreachable(); } extern "C" void os::syscall_rax_error_handler() { - os::assert(false, "Incorrect %rax for syscall."); + assert(false, "Incorrect %rax for syscall."); __builtin_unreachable(); } diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index 5f2f58a..2bd0477 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -15,6 +15,13 @@ #include "interrupts.hpp" #include "serial.hpp" +void amy::assert_handler(char const* cond, char const* file, int line) { + os::print("Assertion error in file '{}', at line {}: {}.\n", file, (unsigned)line, cond); + while (true) { + os::hlt(); + } +} + bool os::init_serial_port() { outb(serial_port + 1, 0x00); // Disable interrupts. outb(serial_port + 3, 0x80); // Prepare to set baud rate divisor (38400 baud). @@ -52,13 +59,13 @@ void os::printc(char c) { write_serial(c); } void os::print_formatted(const char* format, const char* val) { - os::assert(format[0] == '}', "Format string unsupported. TODO."); + assert(format[0] == '}', "Format string unsupported. TODO."); for (amy::size i = 0; val[i] != '\0'; i++) { os::printc(val[i]); } } void os::print_formatted(const char* format, amy::u64 val) { - os::assert(format[0] == '}', "Format string unsupported. TODO."); + assert(format[0] == '}', "Format string unsupported. TODO."); char data[20]; char* curr = data + 19; while (val != 0) { @@ -74,7 +81,7 @@ void os::print_formatted(const char* format, amy::u64 val) { } } void os::print_formatted(const char* format, amy::i64 val) { - os::assert(format[0] == '}', "Format string unsupported. TODO."); + assert(format[0] == '}', "Format string unsupported. TODO."); if (val < 0) { os::printc('-'); os::print_formatted(format, amy::u64(-val)); @@ -84,7 +91,7 @@ void os::print_formatted(const char* format, amy::i64 val) { } } void os::print_formatted(const char* format, phys_ptr val) { - os::assert(format[0] == '}', "Format string unsupported. TODO."); + assert(format[0] == '}', "Format string unsupported. TODO."); os::print("0x"); for (int i = 60; i >= 0; i -= 4) { const int v = (val.get_phys_addr() >> i) & 0xF; @@ -92,7 +99,7 @@ void os::print_formatted(const char* format, phys_ptr val) { } } void os::print_formatted(const char* format, const void* val) { - os::assert(format[0] == '}', "Format string unsupported. TODO."); + assert(format[0] == '}', "Format string unsupported. TODO."); os::print("0x"); for (int i = 60; i >= 0; i -= 4) { const int v = (reinterpret_cast(val) >> i) & 0xF; diff --git a/kernel/src/serial.hpp b/kernel/src/serial.hpp index 479f1f0..908ab50 100644 --- a/kernel/src/serial.hpp +++ b/kernel/src/serial.hpp @@ -13,14 +13,12 @@ #pragma once +#include #include "types.hpp" #include "lib/phys_ptr.hpp" namespace os { -template -void assert(bool cond, const char* format, const Ts&... vs); - constexpr amy::u16 serial_port{0x3F8}; bool init_serial_port(); @@ -72,24 +70,21 @@ void print(const char* format, const Ts&... vs) { for (amy::size i = 0; format[i] != '\0'; i++) { if (format[i] == '{') { i++; - if (format[i] == '\0') { - os::assert(false, "Error in format string: unterminated '{{}'."); - } else if (format[i] == '{') { + assert(format[i] != '\0', "Error in format string: unterminated '{{}'."); + if (format[i] == '{') { printc('{'); continue; } else { amy::size format_spec_end = i; while (format[format_spec_end] != '}') { - if (format[format_spec_end++] == '\0') { - os::assert(false, "Error in format string: unterminated '{{}'."); - } + assert(format[format_spec_end++] != '\0', "Error in format string: unterminated '{{}'."); } amy::size n = arg_n; if ('0' <= format[i] && format[i] <= '9') { if (arg_n == 0) { arg_n_is_given = true; } - os::assert(arg_n_is_given, "Error in format string: either the arg_id is always given, or never."); + assert(arg_n_is_given, "Error in format string: either the arg_id is always given, or never."); amy::size n_ = 0; while ('0' <= format[i] && format[i] <= '9') { n_ = n_ * 10 + (format[i++] - '0'); @@ -99,20 +94,20 @@ void print(const char* format, const Ts&... vs) { if (arg_n == 0) { arg_n_is_given = false; } - os::assert(!arg_n_is_given, "Error in format string: either the arg_id is always given, or never."); + assert(!arg_n_is_given, "Error in format string: either the arg_id is always given, or never."); } if (format[i] == ':') { i++; } else { - os::assert(format[i] == '}', "Error in format string: ':' required before format spec."); + assert(format[i] == '}', "Error in format string: ':' required before format spec."); } - os::assert(n < amy::size(sizeof...(vs)), "Error in format string: not enough arguments."); + assert(n < amy::size(sizeof...(vs)), "Error in format string: not enough arguments."); (print_nth_helper{n, &format[i]} % ... % get_more_general_type_helper_t(vs)); i = format_spec_end; arg_n++; } } else if (format[i] == '}') { - os::assert(format[i + 1] == '}', "Error in format string: unexpected '}'."); + assert(format[i + 1] == '}', "Error in format string: unexpected '}'."); i++; printc('}'); } else { @@ -124,15 +119,4 @@ void print(const char* format, const Ts&... vs) { void cli(); void hlt(); -template -void assert(bool cond, const char* format, const Ts&... vs) { - if (!cond) { - print("Error: "); - print(format, vs...); - printc('\n'); - cli(); - while (true) { hlt(); } - } -} - } // namespace os diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index 3ac872f..2381c04 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -13,6 +13,7 @@ #pragma once +#include #include #include #include "serial.hpp" @@ -51,22 +52,22 @@ public: return 0 <= index && index < n && elems[index].present; } amy::i64 create() { - os::assert(has_room(), "Too many allocated elems in incrementing_int64_map."); + assert(has_room(), "Too many allocated elems in incrementing_int64_map."); elems[n].present = true; new(elems[n].buffer) T; return n++; } void remove(amy::i64 index) { - os::assert(present(index), "Tried removing non-existant element of incrementing_int64_map."); + assert(present(index), "Tried removing non-existant element of incrementing_int64_map."); get(index).~T(); elems[index].present = false; } T& get(amy::i64 index) { - os::assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); + assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); return *amy::launder(reinterpret_cast(&elems[index].buffer[0])); } const T& get(amy::i64 index) const { - os::assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); + assert(present(index), "Tried getting non-existant element of incrementing_int64_map."); return *amy::launder(reinterpret_cast(&elems[index].buffer[0])); } diff --git a/libcpp/assert.hpp b/libcpp/assert.hpp new file mode 100644 index 0000000..1e61440 --- /dev/null +++ b/libcpp/assert.hpp @@ -0,0 +1,20 @@ +// Copyright 2023 Amélia COUTARD. +// +// 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. +// +// 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 . + +#pragma once + +#define assert(cond, ...) if (!(cond)) amy::assert_handler(#cond ", " #__VA_ARGS__, __FILE__, __LINE__) + +namespace amy { + void assert_handler(char const* cond, char const* file, int line) __attribute__((noreturn)); +} // namespace amy -- 2.47.0 From 89754e51a891c05cfe0acca55078c6e3b617c2a3 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Fri, 29 Dec 2023 05:01:43 +0100 Subject: [PATCH 12/16] =?utf8?q?Correction=20d'un=20bug:=20le=20compilateu?= =?utf8?q?r=20avait,=20de=20mani=C3=A8re=20peu=20surprenante,=20raison?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- libcpp/allocator.hpp | 2 +- libcpp/vector.hpp | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libcpp/allocator.hpp b/libcpp/allocator.hpp index ce976b8..f398779 100644 --- a/libcpp/allocator.hpp +++ b/libcpp/allocator.hpp @@ -66,7 +66,7 @@ concept allocator = requires(T allocator) { // Otherwise, it will return the new pointer to the area. The old one shouldn't be used anymore. // pre: ptr is a pointer to a memory area of size old_size and alignment align allocated by the allocator allocator. // pre: new_size ≥ 1 -void* reallocate(allocator auto allocator, void* ptr, amy::size old_size, amy::size new_size, amy::size align) { +void* reallocate(allocator auto& allocator, void* ptr, amy::size old_size, amy::size new_size, amy::size align) { if (allocator.expand(ptr, old_size, new_size - old_size)) { return ptr; } diff --git a/libcpp/vector.hpp b/libcpp/vector.hpp index 0b217ea..97cd731 100644 --- a/libcpp/vector.hpp +++ b/libcpp/vector.hpp @@ -73,10 +73,7 @@ public: capacity_++; } else if (auto new_data = amy::reallocate(allocator, data, capacity_ * amy::byte_size(), capacity_ * 2 * amy::byte_size(), amy::byte_align())) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdangling-pointer" data = (T*)new_data; -#pragma GCC diagnostic pop capacity_ *= 2; } else { return false; -- 2.47.0 From 81dec07afb146db80be587d353310603da4bd4a4 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Fri, 29 Dec 2023 05:46:58 +0100 Subject: [PATCH 13/16] =?utf8?q?Plein=20d'assertions,=20pour=20un=20code?= =?utf8?q?=20plus=20s=C3=BBr.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- libcpp/allocator.hpp | 53 ++++++++++++++++++++++++++++++++++++-------- libcpp/memory.hpp | 13 +++++++++-- libcpp/vector.hpp | 34 ++++++++++++++++++++++++---- 4 files changed, 86 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 9fe55cf..e7a3b31 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif build: # Build as default target -CXXFLAGS := -std=c++20 -fno-strict-aliasing -Wall -Wextra -pedantic -Werror \ +CXXFLAGS := -std=c++23 -fno-strict-aliasing -Wall -Wextra -pedantic -Werror \ -mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding -O2 \ -I libcpp $(CXXFLAGS) LDFLAGS := $(CXXFLAGS) $(LDFLAGS) diff --git a/libcpp/allocator.hpp b/libcpp/allocator.hpp index f398779..131459e 100644 --- a/libcpp/allocator.hpp +++ b/libcpp/allocator.hpp @@ -59,6 +59,12 @@ concept allocator = requires(T allocator) { { allocator.deallocate(amy::declval(), amy::declval(), amy::declval()) } -> amy::same_as; }; +template +concept knowning_allocator = allocator && requires(T allocator) { + // owns(ptr) returns true if, and only if, ptr is a pointer to a memory area allocated by this allocator. + // pre: ptr is a pointer to a memory area allocated by **ANY** allocator + { allocator.owns(amy::declval()) } -> amy::same_as; +}; // reallocate(allocator, ptr, old_size, new_size, align) tries to resize this memory area, or to create a new one, such that // the contents of it, up to the byte min(old_size, new_size), are identical, and the resulting area is aligned to align. @@ -67,6 +73,11 @@ concept allocator = requires(T allocator) { // pre: ptr is a pointer to a memory area of size old_size and alignment align allocated by the allocator allocator. // pre: new_size ≥ 1 void* reallocate(allocator auto& allocator, void* ptr, amy::size old_size, amy::size new_size, amy::size align) { + assert(ptr != amy::nil); + if constexpr (knowning_allocator) { + assert(allocator.owns(ptr)); + } + assert(new_size >= 1); if (allocator.expand(ptr, old_size, new_size - old_size)) { return ptr; } @@ -79,23 +90,26 @@ void* reallocate(allocator auto& allocator, void* ptr, amy::size old_size, amy:: return res; } -template -concept knowning_allocator = allocator && requires(T allocator) { - // owns(ptr) returns true if, and only if, ptr is a pointer to a memory area allocated by this allocator. - // pre: ptr is a pointer to a memory area allocated by **ANY** allocator - { allocator.owns(amy::declval()) } -> amy::same_as; -}; - template struct stack_allocator { static_assert(data_size >= 0); static_assert(data_align >= 1); static_assert((data_align & (data_align - 1)) == 0); // Assert power of 2. - static constexpr amy::size good_size(amy::size size, amy::size) { + static constexpr amy::size good_size(amy::size size, amy::size align) { + if ! consteval { + assert(size >= 1); + assert(align >= 1); + assert((align & (align - 1)) == 0); + assert(align <= max_align); + } return size; } static constexpr amy::size max_align = data_align; void* allocate(amy::size size, amy::size align) { + assert(size >= 1); + assert(align >= 1); + assert((align & (align - 1)) == 0); + assert(align <= max_align); amy::diff aligned_first_free_byte = (first_free_byte + (align - 1)) / align * align; if (aligned_first_free_byte + size > data_size) { return amy::nil; @@ -104,6 +118,8 @@ template struct stack_allocator { return &data[aligned_first_free_byte]; } bool expand(void* ptr, amy::size size, amy::diff delta) { + assert(owns(ptr)); + assert(size + delta >= 1); if (delta == 0) { return true; } @@ -118,6 +134,7 @@ template struct stack_allocator { } } void deallocate(void* ptr, amy::size size, amy::size) { + assert(owns(ptr)); if ((amy::byte*)ptr - data + size == first_free_byte) { first_free_byte = (amy::byte*)ptr - data; } @@ -134,7 +151,6 @@ template = 1); static_assert(max_data_size >= min_data_size); - // static_assert(max_data_size >= amy::byte_size()); // Enough room for intrusive list. static_assert(min_data_align >= 1); static_assert(max_data_align >= min_data_align); static_assert((min_data_align & (min_data_align - 1)) == 0); // Assert power of 2. @@ -150,6 +166,12 @@ private: public: static constexpr amy::size good_size(amy::size size, amy::size align) { + if ! consteval { + assert(size >= 1); + assert(align >= 1); + assert((align & (align - 1)) == 0); + assert(align <= max_align); + } if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { return suballocator_t::good_size(size, align); } @@ -157,6 +179,10 @@ public: } static constexpr amy::size max_align = suballocator_t::max_align; void* allocate(amy::size size, amy::size align) { + assert(size >= 1); + assert(align >= 1); + assert((align & (align - 1)) == 0); + assert(align <= max_align); if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { return sub.allocate(size, align); } @@ -170,6 +196,11 @@ public: return old_head; } bool expand(void* ptr, amy::size size, amy::diff delta) { + assert(ptr != amy::nil); + if constexpr (knowning_allocator) { + assert(owns(ptr)); + } + assert(size + delta >= 1); if (min_data_size <= size && size <= max_data_size) { delta = (size + delta) - max_data_size; size = max_data_size; @@ -180,6 +211,10 @@ public: return sub.expand(ptr, size, delta); } void deallocate(void* ptr, amy::size size, amy::size align) { + assert(ptr != amy::nil); + if constexpr (knowning_allocator) { + assert(owns(ptr)); + } if (size < min_data_size || max_data_size < size || align < min_data_align || max_data_align < align) { return sub.deallocate(ptr, size, align); } diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp index f8c3b7e..a0b2497 100644 --- a/libcpp/memory.hpp +++ b/libcpp/memory.hpp @@ -13,6 +13,7 @@ #pragma once +#include #include // See the C++ documentation for documentation. @@ -37,10 +38,14 @@ template template constexpr size byte_size() { - return sizeof(T); + constexpr size res = sizeof(T); + static_assert(res >= 0); + return res; } template constexpr size byte_align() { - return alignof(T); + constexpr size res = alignof(T); + static_assert(res >= 0); + return res; } // Implementation based on https://en.cppreference.com/w/cpp/utility/declval template constexpr T&& declval() noexcept { @@ -49,12 +54,16 @@ template constexpr T&& declval() noexcept { extern "C" inline void* memset(void* dest, int c, amy::size n) { + assert(n >= 0); + assert(0 <= c && c <= 255); while (n-- > 0) { reinterpret_cast(dest)[n] = amy::byte(c); } return dest; } extern "C" inline void* memcpy(void* dest, const void* src, amy::size n) { + assert(n >= 0); + assert(amy::ptr(dest) + n <= amy::ptr(src) || amy::ptr(src) + n <= amy::ptr(dest)); while (n-- > 0) { reinterpret_cast(dest)[n] = reinterpret_cast(src)[n]; } diff --git a/libcpp/vector.hpp b/libcpp/vector.hpp index 97cd731..84577e6 100644 --- a/libcpp/vector.hpp +++ b/libcpp/vector.hpp @@ -58,16 +58,38 @@ public: size_ = other.size_; capacity_ = other.capacity_; } - vector& operator=(const vector& other) = delete; // Later, when contracts work. Because allocators must be the same. - vector& operator=(vector&& other) = delete; + vector& operator=(const vector& other) { + assert(&allocator == &other.allocator); + vector(other).swap(*this); + } + vector& operator=(vector&& other) { + assert(&allocator == &other.allocator); + this->swap(other); + } + + void swap(vector& other) { + assert(&allocator == &other.allocator); + amy::size bak = size_; + size_ = other.size_; + other.size_ = bak; + bak = capacity_; + capacity_ = other.capacity_; + other.capacity_ = bak; + T* bak_ = data; + data = other.data; + other.data = bak; + } amy::size size() { + assert(!construction_failed()); return size_; } amy::size capacity() { + assert(!construction_failed()); return capacity_; } bool push_back(const T& v) { + assert(!construction_failed()); if (size_ == capacity_) { if (allocator.expand(data, capacity_ * amy::byte_size(), amy::byte_size())) { capacity_++; @@ -83,10 +105,14 @@ public: new(&data[size_ - 1]) T(v); return true; } - T& operator[](amy::size i) { + T& operator[](amy::diff i) { + assert(!construction_failed()); + assert(0 <= i && i < size_); return data[i]; } - const T& operator[](amy::size i) const { + const T& operator[](amy::diff i) const { + assert(!construction_failed()); + assert(0 <= i && i < size_); return data[i]; } -- 2.47.0 From 68d01930df734673beb219edf5f8de3e684c5a88 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Sat, 30 Dec 2023 01:24:19 +0100 Subject: [PATCH 14/16] Des fonctions de plus pour le vecteur --- libcpp/vector.hpp | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/libcpp/vector.hpp b/libcpp/vector.hpp index 84577e6..940358f 100644 --- a/libcpp/vector.hpp +++ b/libcpp/vector.hpp @@ -88,23 +88,37 @@ public: assert(!construction_failed()); return capacity_; } + bool reserve(amy::size n) { + assert(!construction_failed()); + if (n <= capacity_) { + return true; + } + T* new_data = (T*)amy::reallocate(allocator, data, capacity_ * amy::byte_size(), n * amy::byte_size(), amy::byte_align()); + if (new_data == amy::nil) { + return false; + } + data = new_data; + capacity_ = n; + return true; + } bool push_back(const T& v) { + return emplace_back(v); + } + template + bool emplace_back(Ts... vs) { assert(!construction_failed()); - if (size_ == capacity_) { - if (allocator.expand(data, capacity_ * amy::byte_size(), amy::byte_size())) { - capacity_++; - } else if (auto new_data = - amy::reallocate(allocator, data, capacity_ * amy::byte_size(), capacity_ * 2 * amy::byte_size(), amy::byte_align())) { - data = (T*)new_data; - capacity_ *= 2; - } else { - return false; - } + if (size_ == capacity_ && !reserve(2 * capacity_)) { + return false; } size_++; - new(&data[size_ - 1]) T(v); + new(&data[size_ - 1]) T(vs...); return true; } + void pop_back() { + assert(size_ > 0); + data[size_ - 1].~T(); + size_--; + } T& operator[](amy::diff i) { assert(!construction_failed()); assert(0 <= i && i < size_); -- 2.47.0 From 9c6a551be066ee8d75252eaad9498f1aa46b26ed Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Sat, 30 Dec 2023 03:10:31 +0100 Subject: [PATCH 15/16] =?utf8?q?D=C3=A9duplication=20du=20code=20pour=20me?= =?utf8?q?ttre=20les=20plus=20grandes=20pages=20physiques=20possibles=20da?= =?utf8?q?ns=20la=20m=C3=A9moire=20virtuelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- kernel/src/kernel.cpp | 70 +++++++++++++------------------------------ 1 file changed, 21 insertions(+), 49 deletions(-) diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 76dcd4a..10547cd 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -32,6 +32,19 @@ char _kernel_phys_end; os::paging::page<0> bootstrap_pages_for_memory[256]; // 256 pages = 1MiB +void map_biggest_physical_page(os::paging::PML4T& paging_table, void const* vaddr, amy::ptr& phys_addr, amy::ptr phys_addr_end, os::paging::page_info page_info) { + if (phys_addr % (1024 * 1024 * 1024) == 0 && phys_addr + 1024 * 1024 * 1024 < phys_addr_end) { + os::paging::map_page<2, 3>(paging_table, (os::paging::page<2>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 1024 * 1024; + } else if (phys_addr % (1024 * 1024 * 2) == 0 && phys_addr + 1024 * 1024 * 2 < phys_addr_end) { + os::paging::map_page<1, 3>(paging_table, (os::paging::page<1>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 1024 * 2; + } else { + os::paging::map_page<0, 3>(paging_table, (os::paging::page<0>*)vaddr, os::phys_ptr>(phys_addr), page_info); + phys_addr += 1024 * 4; + } +} + extern "C" void kmain(unsigned long magic, os::phys_ptr info) { if (!os::init_serial_port()) { while (true) { @@ -51,34 +64,12 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, (os::paging::page<0>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); - i += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, (void*)(0xFFFF'FFFF'8000'0000 + i), i, amy::ptr(&_kernel_phys_rw_start), + { .RW = false, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = false }); } for (amy::size i = amy::ptr(&_kernel_phys_rw_start); i < amy::ptr(&_kernel_phys_end); ) { - if (i % (1024 * 1024 * 1024) == 0 && i + 1024 * 1024 * 1024 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<2, 3>(os::paging::global_PML4T, (os::paging::page<2>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 1024 * 1024; - } else if (i % (1024 * 1024 * 2) == 0 && i + 1024 * 1024 * 2 < amy::ptr(&_kernel_phys_rw_start)) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, (os::paging::page<1>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, (os::paging::page<0>*)(0xFFFF'FFFF'8000'0000 + i), os::phys_ptr>(i), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); - i += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, (void*)(0xFFFF'FFFF'8000'0000 + i), i, amy::ptr(&_kernel_phys_end), + { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, .PAT = false, .G = true, .AVL = 0, .NX = true }); } // Initialise physical memory map. for (auto it = multiboot2::next(info); it->type != multiboot2::info::type_t::end; it = multiboot2::next(it)) { @@ -98,29 +89,10 @@ extern "C" void kmain(unsigned long magic, os::phys_ptr( - os::paging::global_PML4T, - (os::paging::page<2>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 1024 * 1024; - } else if (j % (1024 * 1024 * 2) == 0 && j + 1024 * 1024 * 2 < e) { - os::paging::map_page<1, 3>(os::paging::global_PML4T, - (os::paging::page<1>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 1024 * 2; - } else { - os::paging::map_page<0, 3>(os::paging::global_PML4T, - (os::paging::page<0>*)(0xFFFF'8000'0000'0000 + j), - os::phys_ptr>(j), - { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, - .PAT = false, .G = true, .AVL = 0, .NX = true }); - j += 1024 * 4; - } + map_biggest_physical_page(os::paging::global_PML4T, + (void*)(0xFFFF'8000'0000'0000 + j), j, e, + { .RW = true, .US = false, .PWT = false, .PCD = false, .A = false, .D = false, + .PAT = false, .G = true, .AVL = 0, .NX = true }); } } os::print("RAM END\n"); -- 2.47.0 From 8460423c25f06f88ec3aa75db7a0ce1572336cf6 Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Wed, 3 Jan 2024 02:52:08 +0100 Subject: [PATCH 16/16] =?utf8?q?Plut=C3=B4t=20l'AGPL,=20au=20final,=20car?= =?utf8?q?=20ce=20syst=C3=A8me=20est=20fait=20pour=20=C3=AAtre=20=C3=A9ven?= =?utf8?q?tuellement=20utilis=C3=A9=20entre=20autre=20en=20ligne=20sur=20d?= =?utf8?q?es=20ordinateurs=20centraux?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- COPYING-GPL-3.0 => COPYING-AGPL-3.0 | 480 +++++++++++++++------------- kernel/src/boot.S | 14 +- kernel/src/elf64.cpp | 14 +- kernel/src/elf64.hpp | 14 +- kernel/src/interrupts.S | 14 +- kernel/src/interrupts.cpp | 14 +- kernel/src/interrupts.hpp | 14 +- kernel/src/kernel.cpp | 14 +- kernel/src/lib/crti.S | 14 +- kernel/src/lib/crtn.S | 14 +- kernel/src/lib/multiboot2.hpp | 14 +- kernel/src/lib/phys_ptr.hpp | 14 +- kernel/src/paging.cpp | 14 +- kernel/src/paging.hpp | 14 +- kernel/src/ring3.S | 14 +- kernel/src/ring3.cpp | 14 +- kernel/src/ring3.hpp | 14 +- kernel/src/serial.cpp | 14 +- kernel/src/serial.hpp | 14 +- kernel/src/utils.cpp | 14 +- kernel/src/utils.hpp | 14 +- libcpp/allocator.hpp | 14 +- libcpp/assert.hpp | 14 +- libcpp/concept.hpp | 14 +- libcpp/memory.hpp | 14 +- libcpp/types.hpp | 14 +- libcpp/vector.hpp | 14 +- test_module/src/test.S | 14 +- test_module/src/test.cpp | 14 +- 29 files changed, 457 insertions(+), 415 deletions(-) rename COPYING-GPL-3.0 => COPYING-AGPL-3.0 (56%) diff --git a/COPYING-GPL-3.0 b/COPYING-AGPL-3.0 similarity index 56% rename from COPYING-GPL-3.0 rename to COPYING-AGPL-3.0 index 9f8fd5c..be3f7b2 100644 --- a/COPYING-GPL-3.0 +++ b/COPYING-AGPL-3.0 @@ -1,106 +1,94 @@ -GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 -Copyright (C) 2007 Free Software Foundation, Inc. -Everyone is permitted to copy and distribute verbatim copies -of this license document, but changing it is not allowed. + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. - Preamble + Preamble -The GNU General Public License is a free, copyleft license for -software and other kinds of works. + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. -The licenses for most software and other practical works are designed + The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to +our General Public Licenses are intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. +software for all its users. -When we speak of free software, we are referring to freedom, not + When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. -To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - -For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - -Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - -For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - -Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - -Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - -The precise terms and conditions for copying, distribution and + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and modification follow. - TERMS AND CONDITIONS + TERMS AND CONDITIONS -0. Definitions. + 0. Definitions. -"This License" refers to version 3 of the GNU General Public License. + "This License" refers to version 3 of the GNU Affero General Public License. -"Copyright" also means copyright-like laws that apply to other kinds of + "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. -"The Program" refers to any copyrightable work licensed under this + "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. -To "modify" a work means to copy from or adapt all or part of the work + To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. -A "covered work" means either the unmodified Program or a work based + A "covered work" means either the unmodified Program or a work based on the Program. -To "propagate" a work means to do anything with it that, without + To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. -To "convey" a work means any kind of propagation that enables other + To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. -An interactive user interface displays "Appropriate Legal Notices" + An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the @@ -109,18 +97,18 @@ work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. -1. Source Code. + 1. Source Code. -The "source code" for a work means the preferred form of the work + The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. -A "Standard Interface" means an interface that either is an official + A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. -The "System Libraries" of an executable work include anything, other + The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that @@ -131,7 +119,7 @@ implementation is available to the public in source code form. A (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. -The "Corresponding Source" for a work in object code form means all + The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's @@ -144,16 +132,16 @@ linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. -The Corresponding Source need not include anything that users + The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. -The Corresponding Source for a work in source code form is that + The Corresponding Source for a work in source code form is that same work. -2. Basic Permissions. + 2. Basic Permissions. -All rights granted under this License are granted for the term of + All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a @@ -161,7 +149,7 @@ covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. -You may make, run and propagate covered works that you do not + You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you @@ -172,19 +160,19 @@ for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. -Conveying under any other circumstances is permitted solely under + Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. -3. Protecting Users' Legal Rights From Anti-Circumvention Law. + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. -No covered work shall be deemed part of an effective technological + No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. -When you convey a covered work, you waive any legal power to forbid + When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or @@ -192,9 +180,9 @@ modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. -4. Conveying Verbatim Copies. + 4. Conveying Verbatim Copies. -You may convey verbatim copies of the Program's source code as you + You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any @@ -202,37 +190,37 @@ non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. -You may charge any price or no price for each copy that you convey, + You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. -5. Conveying Modified Source Versions. + 5. Conveying Modified Source Versions. -You may convey a work based on the Program, or the modifications to + You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: -a) The work must carry prominent notices stating that you modified -it, and giving a relevant date. + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. -b) The work must carry prominent notices stating that it is -released under this License and any conditions added under section -7. This requirement modifies the requirement in section 4 to -"keep intact all notices". + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". -c) You must license the entire work, as a whole, under this -License to anyone who comes into possession of a copy. This -License will therefore apply, along with any applicable section 7 -additional terms, to the whole of the work, and all its parts, -regardless of how they are packaged. This License gives no -permission to license the work in any other way, but it does not -invalidate such permission if you have separately received it. + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. -d) If the work has interactive user interfaces, each must display -Appropriate Legal Notices; however, if the Program has interactive -interfaces that do not display Appropriate Legal Notices, your -work need not make them do so. + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. -A compilation of a covered work with other separate and independent + A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an @@ -242,59 +230,59 @@ beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. -6. Conveying Non-Source Forms. + 6. Conveying Non-Source Forms. -You may convey a covered work in object code form under the terms + You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: -a) Convey the object code in, or embodied in, a physical product -(including a physical distribution medium), accompanied by the -Corresponding Source fixed on a durable physical medium -customarily used for software interchange. - -b) Convey the object code in, or embodied in, a physical product -(including a physical distribution medium), accompanied by a -written offer, valid for at least three years and valid for as -long as you offer spare parts or customer support for that product -model, to give anyone who possesses the object code either (1) a -copy of the Corresponding Source for all the software in the -product that is covered by this License, on a durable physical -medium customarily used for software interchange, for a price no -more than your reasonable cost of physically performing this -conveying of source, or (2) access to copy the -Corresponding Source from a network server at no charge. - -c) Convey individual copies of the object code with a copy of the -written offer to provide the Corresponding Source. This -alternative is allowed only occasionally and noncommercially, and -only if you received the object code with such an offer, in accord -with subsection 6b. - -d) Convey the object code by offering access from a designated -place (gratis or for a charge), and offer equivalent access to the -Corresponding Source in the same way through the same place at no -further charge. You need not require recipients to copy the -Corresponding Source along with the object code. If the place to -copy the object code is a network server, the Corresponding Source -may be on a different server (operated by you or a third party) -that supports equivalent copying facilities, provided you maintain -clear directions next to the object code saying where to find the -Corresponding Source. Regardless of what server hosts the -Corresponding Source, you remain obligated to ensure that it is -available for as long as needed to satisfy these requirements. - -e) Convey the object code using peer-to-peer transmission, provided -you inform other peers where the object code and Corresponding -Source of the work are being offered to the general public at no -charge under subsection 6d. - -A separable portion of the object code, whose source code is excluded + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. -A "User Product" is either (1) a "consumer product", which means any + A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, @@ -307,7 +295,7 @@ is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. -"Installation Information" for a User Product means any methods, + "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must @@ -315,7 +303,7 @@ suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. -If you convey an object code work under this section in, or with, or + If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a @@ -326,7 +314,7 @@ if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). -The requirement to provide Installation Information does not include a + The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a @@ -334,15 +322,15 @@ network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. -Corresponding Source conveyed, and Installation Information provided, + Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. -7. Additional Terms. + 7. Additional Terms. -"Additional permissions" are terms that supplement the terms of this + "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent @@ -351,41 +339,41 @@ apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. -When you convey a copy of a covered work, you may at your option + When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. -Notwithstanding any other provision of this License, for material you + Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: -a) Disclaiming warranty or limiting liability differently from the -terms of sections 15 and 16 of this License; or + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or -b) Requiring preservation of specified reasonable legal notices or -author attributions in that material or in the Appropriate Legal -Notices displayed by works containing it; or + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or -c) Prohibiting misrepresentation of the origin of that material, or -requiring that modified versions of such material be marked in -reasonable ways as different from the original version; or + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or -d) Limiting the use for publicity purposes of names of licensors or -authors of the material; or + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or -e) Declining to grant rights under trademark law for use of some -trade names, trademarks, or service marks; or + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or -f) Requiring indemnification of licensors and authors of that -material by anyone who conveys the material (or modified versions of -it) with contractual assumptions of liability to the recipient, for -any liability that these contractual assumptions directly impose on -those licensors and authors. + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. -All other non-permissive additional terms are considered "further + All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further @@ -395,46 +383,46 @@ License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. -If you add terms to a covered work in accord with this section, you + If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. -Additional terms, permissive or non-permissive, may be stated in the + Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. -8. Termination. + 8. Termination. -You may not propagate or modify a covered work except as expressly + You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). -However, if you cease all violation of this License, then your + However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. -Moreover, your license from a particular copyright holder is + Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. -Termination of your rights under this section does not terminate the + Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. -9. Acceptance Not Required for Having Copies. + 9. Acceptance Not Required for Having Copies. -You are not required to accept this License in order to receive or + You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, @@ -443,14 +431,14 @@ modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. -10. Automatic Licensing of Downstream Recipients. + 10. Automatic Licensing of Downstream Recipients. -Each time you convey a covered work, the recipient automatically + Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. -An "entity transaction" is a transaction transferring control of an + An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that @@ -460,7 +448,7 @@ give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. -You may not impose any further restrictions on the exercise of the + You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation @@ -468,13 +456,13 @@ rights granted under this License, and you may not initiate litigation any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. -11. Patents. + 11. Patents. -A "contributor" is a copyright holder who authorizes use under this + A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". -A contributor's "essential patent claims" are all patent claims + A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, @@ -484,19 +472,19 @@ purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. -Each contributor grants you a non-exclusive, worldwide, royalty-free + Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. -In the following three paragraphs, a "patent license" is any express + In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. -If you convey a covered work, knowingly relying on a patent license, + If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, @@ -510,7 +498,7 @@ covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. -If, pursuant to or in connection with a single transaction or + If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify @@ -518,7 +506,7 @@ or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. -A patent license is "discriminatory" if it does not include within + A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered @@ -533,13 +521,13 @@ for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. -Nothing in this License shall be construed as excluding or limiting + Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. -12. No Surrender of Others' Freedom. + 12. No Surrender of Others' Freedom. -If conditions are imposed on you (whether by court order, agreement or + If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this @@ -549,46 +537,56 @@ to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. -13. Use with the GNU Affero General Public License. + 13. Remote Network Interaction; Use with the GNU General Public License. -Notwithstanding any other provision of this License, you have + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single +under version 3 of the GNU General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. -14. Revised Versions of this License. + 14. Revised Versions of this License. -The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. -Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published +GNU Affero General Public License, you may choose any version ever published by the Free Software Foundation. -If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. -Later license versions may give you additional or different + Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. -15. Disclaimer of Warranty. + 15. Disclaimer of Warranty. -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, @@ -597,9 +595,9 @@ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. -16. Limitation of Liability. + 16. Limitation of Liability. -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE @@ -609,11 +607,55 @@ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. -17. Interpretation of Sections 15 and 16. + 17. Interpretation of Sections 15 and 16. -If the disclaimer of warranty and limitation of liability provided + If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/kernel/src/boot.S b/kernel/src/boot.S index 3dfa906..c9a7776 100644 --- a/kernel/src/boot.S +++ b/kernel/src/boot.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include "lib/multiboot2.hpp" diff --git a/kernel/src/elf64.cpp b/kernel/src/elf64.cpp index 9ced6fb..d5fc9ff 100644 --- a/kernel/src/elf64.cpp +++ b/kernel/src/elf64.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include "elf64.hpp" diff --git a/kernel/src/elf64.hpp b/kernel/src/elf64.hpp index 9347353..e782e69 100644 --- a/kernel/src/elf64.hpp +++ b/kernel/src/elf64.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/interrupts.S b/kernel/src/interrupts.S index c416176..4a1b482 100644 --- a/kernel/src/interrupts.S +++ b/kernel/src/interrupts.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #define PUSH_REGS \ diff --git a/kernel/src/interrupts.cpp b/kernel/src/interrupts.cpp index 3b7d9ef..7c7ad31 100644 --- a/kernel/src/interrupts.cpp +++ b/kernel/src/interrupts.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include diff --git a/kernel/src/interrupts.hpp b/kernel/src/interrupts.hpp index 846168f..90f65cb 100644 --- a/kernel/src/interrupts.hpp +++ b/kernel/src/interrupts.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/kernel.cpp b/kernel/src/kernel.cpp index 10547cd..05fc8f0 100644 --- a/kernel/src/kernel.cpp +++ b/kernel/src/kernel.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include diff --git a/kernel/src/lib/crti.S b/kernel/src/lib/crti.S index 4353c68..4b4ead1 100644 --- a/kernel/src/lib/crti.S +++ b/kernel/src/lib/crti.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . .section .init diff --git a/kernel/src/lib/crtn.S b/kernel/src/lib/crtn.S index c202ca1..05b9226 100644 --- a/kernel/src/lib/crtn.S +++ b/kernel/src/lib/crtn.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . .section .init diff --git a/kernel/src/lib/multiboot2.hpp b/kernel/src/lib/multiboot2.hpp index 1f1fd41..c9adaa5 100644 --- a/kernel/src/lib/multiboot2.hpp +++ b/kernel/src/lib/multiboot2.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/lib/phys_ptr.hpp b/kernel/src/lib/phys_ptr.hpp index b9e0989..888073e 100644 --- a/kernel/src/lib/phys_ptr.hpp +++ b/kernel/src/lib/phys_ptr.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/paging.cpp b/kernel/src/paging.cpp index 1a36a24..a8f546c 100644 --- a/kernel/src/paging.cpp +++ b/kernel/src/paging.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include "paging.hpp" diff --git a/kernel/src/paging.hpp b/kernel/src/paging.hpp index 67df518..2b36fbd 100644 --- a/kernel/src/paging.hpp +++ b/kernel/src/paging.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/ring3.S b/kernel/src/ring3.S index 6b5a690..5507698 100644 --- a/kernel/src/ring3.S +++ b/kernel/src/ring3.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . .section .text diff --git a/kernel/src/ring3.cpp b/kernel/src/ring3.cpp index f0716d5..f782315 100644 --- a/kernel/src/ring3.cpp +++ b/kernel/src/ring3.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include diff --git a/kernel/src/ring3.hpp b/kernel/src/ring3.hpp index 6859526..d48cc80 100644 --- a/kernel/src/ring3.hpp +++ b/kernel/src/ring3.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/serial.cpp b/kernel/src/serial.cpp index 2bd0477..a273d5b 100644 --- a/kernel/src/serial.cpp +++ b/kernel/src/serial.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include "utils.hpp" diff --git a/kernel/src/serial.hpp b/kernel/src/serial.hpp index 908ab50..cfd448f 100644 --- a/kernel/src/serial.hpp +++ b/kernel/src/serial.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/kernel/src/utils.cpp b/kernel/src/utils.cpp index 64c88f0..5d586e6 100644 --- a/kernel/src/utils.cpp +++ b/kernel/src/utils.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include "utils.hpp" diff --git a/kernel/src/utils.hpp b/kernel/src/utils.hpp index 2381c04..e8b015d 100644 --- a/kernel/src/utils.hpp +++ b/kernel/src/utils.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/allocator.hpp b/libcpp/allocator.hpp index 131459e..0b4331a 100644 --- a/libcpp/allocator.hpp +++ b/libcpp/allocator.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/assert.hpp b/libcpp/assert.hpp index 1e61440..1566359 100644 --- a/libcpp/assert.hpp +++ b/libcpp/assert.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/concept.hpp b/libcpp/concept.hpp index f63608b..017bad3 100644 --- a/libcpp/concept.hpp +++ b/libcpp/concept.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/memory.hpp b/libcpp/memory.hpp index a0b2497..acc824d 100644 --- a/libcpp/memory.hpp +++ b/libcpp/memory.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/types.hpp b/libcpp/types.hpp index 94c4598..01aba23 100644 --- a/libcpp/types.hpp +++ b/libcpp/types.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/libcpp/vector.hpp b/libcpp/vector.hpp index 940358f..a907242 100644 --- a/libcpp/vector.hpp +++ b/libcpp/vector.hpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #pragma once diff --git a/test_module/src/test.S b/test_module/src/test.S index eb6dd23..af679da 100644 --- a/test_module/src/test.S +++ b/test_module/src/test.S @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . .section .text diff --git a/test_module/src/test.cpp b/test_module/src/test.cpp index 421ce3f..f7876db 100644 --- a/test_module/src/test.cpp +++ b/test_module/src/test.cpp @@ -1,14 +1,14 @@ // Copyright 2023 Amélia COUTARD. // -// 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. +// 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 Affero 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. +// 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 Affero General +// Public License for more details. // -// You should have received a copy of the GNU General Public License along with this program. If +// You should have received a copy of the GNU Affero General Public License along with this program. If // not, see . #include -- 2.47.0