From 2a29ebc6ad962d733f1b5bb3ea2d45cedb95493f Mon Sep 17 00:00:00 2001 From: Romain Date: Sat, 3 Oct 2020 22:58:30 +0200 Subject: [PATCH] refactor: Dossier kernel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En prévision de quand différents programmes seront chargés --- makefile | 26 ++++++++++--------- src/kernel.cpp | 20 -------------- src/{ => kernel}/bootSector/bootloader.asm | 0 src/{ => kernel}/bootSector/diskRead.asm | 0 .../bootSector/diskReadSegments.asm | 0 src/{ => kernel}/bootSector/printString.asm | 0 src/kernel/kernel.cpp | 20 ++++++++++++++ src/{ => kernel}/secondSector/CPUID.asm | 0 src/{ => kernel}/secondSector/GDT.asm | 0 src/{ => kernel}/secondSector/IDT.asm | 0 src/{ => kernel}/secondSector/binaries.asm | 0 .../secondSector/extendedProgram.asm | 0 src/{ => kernel}/secondSector/memory.asm | 0 src/{ => kernel}/secondSector/paging.asm | 0 src/{ => kernel}/secondSector/system.asm | 0 src/{ => kernel}/secondSector/time.asm | 0 src/{IO => std/io}/IDT.hpp | 11 ++++---- src/std/io/IO.hpp | 13 ++++++++++ src/{IO => std/io}/keyboard.hpp | 4 +-- src/{IO => std/io}/keyboardLayouts/AZERTY.hpp | 2 +- src/{IO => std/io}/printText.hpp | 18 ++++++------- src/{IO/IO.hpp => std/io/rawIO.hpp} | 12 ++++----- src/{IO => std/io}/textColorModes.hpp | 0 src/{ => std}/memory.hpp | 0 src/{ => std}/memoryMap.hpp | 23 ++++++++-------- src/{ => std}/random.hpp | 0 src/{ => std}/stack.hpp | 2 +- src/{ => std}/string.hpp | 4 +-- src/{ => std}/system.hpp | 17 ++++++------ src/{ => std}/time.hpp | 0 src/{ => std}/types.hpp | 0 31 files changed, 95 insertions(+), 77 deletions(-) delete mode 100644 src/kernel.cpp rename src/{ => kernel}/bootSector/bootloader.asm (100%) rename src/{ => kernel}/bootSector/diskRead.asm (100%) rename src/{ => kernel}/bootSector/diskReadSegments.asm (100%) rename src/{ => kernel}/bootSector/printString.asm (100%) create mode 100644 src/kernel/kernel.cpp rename src/{ => kernel}/secondSector/CPUID.asm (100%) rename src/{ => kernel}/secondSector/GDT.asm (100%) rename src/{ => kernel}/secondSector/IDT.asm (100%) rename src/{ => kernel}/secondSector/binaries.asm (100%) rename src/{ => kernel}/secondSector/extendedProgram.asm (100%) rename src/{ => kernel}/secondSector/memory.asm (100%) rename src/{ => kernel}/secondSector/paging.asm (100%) rename src/{ => kernel}/secondSector/system.asm (100%) rename src/{ => kernel}/secondSector/time.asm (100%) rename src/{IO => std/io}/IDT.hpp (93%) create mode 100644 src/std/io/IO.hpp rename src/{IO => std/io}/keyboard.hpp (98%) rename src/{IO => std/io}/keyboardLayouts/AZERTY.hpp (98%) rename src/{IO => std/io}/printText.hpp (94%) rename src/{IO/IO.hpp => std/io/rawIO.hpp} (85%) rename src/{IO => std/io}/textColorModes.hpp (100%) rename src/{ => std}/memory.hpp (100%) rename src/{ => std}/memoryMap.hpp (85%) rename src/{ => std}/random.hpp (100%) rename src/{ => std}/stack.hpp (99%) rename src/{ => std}/string.hpp (98%) rename src/{ => std}/system.hpp (55%) rename src/{ => std}/time.hpp (100%) rename src/{ => std}/types.hpp (100%) diff --git a/makefile b/makefile index e9a2902..de653e2 100644 --- a/makefile +++ b/makefile @@ -13,13 +13,13 @@ clean: compileAsm: echo "Compilation bootloader..." - cd ./src/bootSector && \ - nasm ./bootloader.asm -f bin -o ../../bin/part/bootloader.bin -w+orphan-labels + cd ./src/kernel/bootSector && \ + nasm ./bootloader.asm -f bin -o ../../../bin/part/bootloader.bin -w+orphan-labels echo "Compilation secteurs suivants..." - cd ./src/secondSector && \ - nasm ./extendedProgram.asm -f elf64 -i ../bootSector/ -o ../../bin/part/extendedProgram.o -w+orphan-labels && \ - nasm ./binaries.asm -f elf64 -o ../../bin/part/binaries.o -w+orphan-labels + cd ./src/kernel/secondSector && \ + nasm ./extendedProgram.asm -f elf64 -i ../bootSector/ -o ../../../bin/part/extendedProgram.o -w+orphan-labels && \ + nasm ./binaries.asm -f elf64 -o ../../../bin/part/binaries.o -w+orphan-labels compileCPP: echo "Compilation C/C++..." @@ -36,11 +36,12 @@ compileCPP: -Wno-write-strings \ -std=c++1z \ -I . \ - -c kernel.cpp \ + -I ./std \ + -c kernel/kernel.cpp \ -o ../bin/part/kernel.o # -Ttext 0x8000 Set la section .text à 0x8000, pour situer le main - # -ffreestanding La lib standard n'existe pas, et main n'est pas le point d'entrée + # -ffreestanding La lib standard n'existe pas, et main n'est pas le point io'entrée # -mno-red-zone Désactive la red-zone, 128 bytes sous le stack utilisés librement par gcc # -m64 Génère du code pour 64 bits # -save-temps=obj Exporte les .cpp en assembleur dans le même dossier que les .o @@ -49,8 +50,9 @@ compileCPP: # -pedantic Erreurs en plus # -Wno-write-strings Disable le warning pour l'utilisation de char* au lieu de std::string (std::string n'existe pas...) # -std=c++1z C++ 17 - # -I . Dossier d'includes pour les .hpp - # -c kernel.cpp Source + # -I . Dossier d'include pour les .hpp + # -I ./std Dossier d'include pour les .hpp : std + # -c kernel/kernel.cpp Source # -o ../bin/part/kernel.o Output link: @@ -63,11 +65,11 @@ merge: cat ./bin/part/bootloader.bin ./bin/part/kernel.bin > ./bin/OS/RomainOS.bin calcNbSeg: - echo "; Fichier généré automatiquement." > src/bootSector/diskReadSegments.asm - echo "; La valeur est calculée selon l'espace occupé par le fichier binaire final." >> src/bootSector/diskReadSegments.asm + echo "; Fichier généré automatiquement." > src/kernel/bootSector/diskReadSegments.asm + echo "; La valeur est calculée selon l'espace occupé par le fichier binaire final." >> src/kernel/bootSector/diskReadSegments.asm nbSeg=$$(($$(wc -c < ./bin/OS/RomainOS.bin)/512)) && \ echo "Nombre de segments nécessaires: $$nbSeg" && \ - echo "mov al," $$nbSeg >> src/bootSector/diskReadSegments.asm + echo "mov al," $$nbSeg >> src/kernel/bootSector/diskReadSegments.asm run: echo "Exécution bootloader..." diff --git a/src/kernel.cpp b/src/kernel.cpp deleted file mode 100644 index 635bc12..0000000 --- a/src/kernel.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: GPL-3.0-or-later -// Created by Romain on 08/09/2020. - -#include -#include -#include -#include - -/** - * Point d'entrée de l'OS - */ -extern "C" void _start() { - std::IO::clearScreen(); - std::IO::setCursorPosition(0, 0); - std::IO::IDT::initIDT(); - std::IO::setKeyboardLayout(std::IO::AZERTY); - std::memory::initHeap(0x100000, 0x100000); - - std::IO::printString("Tout fonctionne !\n", nullptr, BG_RED | FG_WHITE); -} diff --git a/src/bootSector/bootloader.asm b/src/kernel/bootSector/bootloader.asm similarity index 100% rename from src/bootSector/bootloader.asm rename to src/kernel/bootSector/bootloader.asm diff --git a/src/bootSector/diskRead.asm b/src/kernel/bootSector/diskRead.asm similarity index 100% rename from src/bootSector/diskRead.asm rename to src/kernel/bootSector/diskRead.asm diff --git a/src/bootSector/diskReadSegments.asm b/src/kernel/bootSector/diskReadSegments.asm similarity index 100% rename from src/bootSector/diskReadSegments.asm rename to src/kernel/bootSector/diskReadSegments.asm diff --git a/src/bootSector/printString.asm b/src/kernel/bootSector/printString.asm similarity index 100% rename from src/bootSector/printString.asm rename to src/kernel/bootSector/printString.asm diff --git a/src/kernel/kernel.cpp b/src/kernel/kernel.cpp new file mode 100644 index 0000000..392ef50 --- /dev/null +++ b/src/kernel/kernel.cpp @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Created by Romain on 08/09/2020. + +#include +#include +#include +#include + +/** + * Point io'entrée de l'OS + */ +extern "C" void _start() { + std::io::clearScreen(); + std::io::setCursorPosition(0, 0); + std::io::idt::initIDT(); + std::io::setKeyboardLayout(std::io::AZERTY); + std::memory::initHeap(0x100000, 0x100000); + + std::io::printString("Tout fonctionne !\n", nullptr, BG_RED | FG_WHITE); +} diff --git a/src/secondSector/CPUID.asm b/src/kernel/secondSector/CPUID.asm similarity index 100% rename from src/secondSector/CPUID.asm rename to src/kernel/secondSector/CPUID.asm diff --git a/src/secondSector/GDT.asm b/src/kernel/secondSector/GDT.asm similarity index 100% rename from src/secondSector/GDT.asm rename to src/kernel/secondSector/GDT.asm diff --git a/src/secondSector/IDT.asm b/src/kernel/secondSector/IDT.asm similarity index 100% rename from src/secondSector/IDT.asm rename to src/kernel/secondSector/IDT.asm diff --git a/src/secondSector/binaries.asm b/src/kernel/secondSector/binaries.asm similarity index 100% rename from src/secondSector/binaries.asm rename to src/kernel/secondSector/binaries.asm diff --git a/src/secondSector/extendedProgram.asm b/src/kernel/secondSector/extendedProgram.asm similarity index 100% rename from src/secondSector/extendedProgram.asm rename to src/kernel/secondSector/extendedProgram.asm diff --git a/src/secondSector/memory.asm b/src/kernel/secondSector/memory.asm similarity index 100% rename from src/secondSector/memory.asm rename to src/kernel/secondSector/memory.asm diff --git a/src/secondSector/paging.asm b/src/kernel/secondSector/paging.asm similarity index 100% rename from src/secondSector/paging.asm rename to src/kernel/secondSector/paging.asm diff --git a/src/secondSector/system.asm b/src/kernel/secondSector/system.asm similarity index 100% rename from src/secondSector/system.asm rename to src/kernel/secondSector/system.asm diff --git a/src/secondSector/time.asm b/src/kernel/secondSector/time.asm similarity index 100% rename from src/secondSector/time.asm rename to src/kernel/secondSector/time.asm diff --git a/src/IO/IDT.hpp b/src/std/io/IDT.hpp similarity index 93% rename from src/IO/IDT.hpp rename to src/std/io/IDT.hpp index e678520..0f8cefb 100644 --- a/src/IO/IDT.hpp +++ b/src/std/io/IDT.hpp @@ -9,10 +9,11 @@ #ifndef ROMAINOS_IDT_HPP #define ROMAINOS_IDT_HPP -#include "types.hpp" +#include + #include "keyboard.hpp" -namespace std::IO::IDT { +namespace std::io::idt { /** * Interrupt Descriptor Tables */ @@ -57,14 +58,14 @@ namespace std::IO::IDT { /** * IDT */ -extern std::IO::IDT::IDT64 _idt[256]; +extern std::io::idt::IDT64 _idt[256]; /** * Routine assembleur keyboard */ extern uint64_t _isr1; -namespace std::IO::IDT { +namespace std::io::idt { /** * Active les IDT */ @@ -106,7 +107,7 @@ namespace std::IO::IDT { outb(0x20, 0x20); outb(0xa0, 0x20); - std::IO::handleEvent(b); + std::io::handleEvent(b); } } diff --git a/src/std/io/IO.hpp b/src/std/io/IO.hpp new file mode 100644 index 0000000..79dbf85 --- /dev/null +++ b/src/std/io/IO.hpp @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// Created by Romain on 03/10/2020. + +#ifndef ROMAINOS_IO_HPP +#define ROMAINOS_IO_HPP + +#include "IDT.hpp" +#include "keyboard.hpp" +#include "printText.hpp" +#include "rawIO.hpp" +#include "textColorModes.hpp" + +#endif //ROMAINOS_IO_HPP diff --git a/src/IO/keyboard.hpp b/src/std/io/keyboard.hpp similarity index 98% rename from src/IO/keyboard.hpp rename to src/std/io/keyboard.hpp index b7867e2..76dfb2c 100644 --- a/src/IO/keyboard.hpp +++ b/src/std/io/keyboard.hpp @@ -8,7 +8,7 @@ #include "keyboardLayouts/AZERTY.hpp" -namespace std::IO { +namespace std::io { /** * Différents layouts */ @@ -163,7 +163,7 @@ namespace std::IO { */ void handleEvent(byte b) { KeyEvent event = getEvent(b); - std::IO::printChar(event.key); + std::io::printChar(event.key); if (event.keyCode == VK_ESC) { std::system::shutdownAndPrint(); diff --git a/src/IO/keyboardLayouts/AZERTY.hpp b/src/std/io/keyboardLayouts/AZERTY.hpp similarity index 98% rename from src/IO/keyboardLayouts/AZERTY.hpp rename to src/std/io/keyboardLayouts/AZERTY.hpp index 21ea9cd..cead9e9 100644 --- a/src/IO/keyboardLayouts/AZERTY.hpp +++ b/src/std/io/keyboardLayouts/AZERTY.hpp @@ -11,7 +11,7 @@ #define VK_CTRL 0x1d #define VK_CAPS_LOCK 0x3a -namespace std::IO { +namespace std::io { static char _layoutAZERTY[256] = { // 0 1 2 3 4 5 6 7 8 9 A B C D E F /* 0 */ '\0', 0x1b, '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' , ')' , '=' , 0x7f, '\t', diff --git a/src/IO/printText.hpp b/src/std/io/printText.hpp similarity index 94% rename from src/IO/printText.hpp rename to src/std/io/printText.hpp index e9f7fdf..a58394c 100644 --- a/src/IO/printText.hpp +++ b/src/std/io/printText.hpp @@ -4,11 +4,11 @@ #ifndef ROMAINOS_PRINTTEXT_HPP #define ROMAINOS_PRINTTEXT_HPP -#include "types.hpp" -#include "string.hpp" +#include +#include -#include "IO/IO.hpp" -#include "IO/textColorModes.hpp" +#include "rawIO.hpp" +#include "textColorModes.hpp" /** * Emplacement VRAM @@ -30,7 +30,7 @@ */ #define TAB_LENGTH 4 -namespace std::IO { +namespace std::io { namespace { /** * Position du curseur @@ -46,10 +46,10 @@ namespace std::IO { void setCursorPosition(u16 pos) { pos %= (VGA_WIDTH * VGA_HEIGHT); - std::IO::outb(0x3d4, 0x0f); - std::IO::outb(0x3d5, (byte) (pos & (u16) 0xff)); - std::IO::outb(0x3d4, 0x0e); - std::IO::outb(0x3d5, (byte) ((u16) (pos >> (u16) 8) & (u16) 0xff)); + std::io::outb(0x3d4, 0x0f); + std::io::outb(0x3d5, (byte) (pos & (u16) 0xff)); + std::io::outb(0x3d4, 0x0e); + std::io::outb(0x3d5, (byte) ((u16) (pos >> (u16) 8) & (u16) 0xff)); _cursorPosition = pos; } diff --git a/src/IO/IO.hpp b/src/std/io/rawIO.hpp similarity index 85% rename from src/IO/IO.hpp rename to src/std/io/rawIO.hpp index f679142..0d96ea5 100644 --- a/src/IO/IO.hpp +++ b/src/std/io/rawIO.hpp @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-3.0-or-later // Created by Romain on 09/09/2020. -#ifndef ROMAINOS_IO_HPP -#define ROMAINOS_IO_HPP +#ifndef ROMAINOS_RAWIO_HPP +#define ROMAINOS_RAWIO_HPP -#include "types.hpp" +#include -namespace std::IO { +namespace std::io { /** * Transfère de la data à travers les ports sur un octet * @@ -16,7 +16,7 @@ namespace std::IO { * @see https://wiki.osdev.org/I/O_Ports#The_list */ void outb(u16 port, byte val) { - // Volatile pour empêcher le compilateur d'optimiser + // Volatile pour empêcher le compilateur io'optimiser asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port)); } @@ -50,4 +50,4 @@ namespace std::IO { return res; } } -#endif //ROMAINOS_IO_HPP +#endif //ROMAINOS_RAWIO_HPP diff --git a/src/IO/textColorModes.hpp b/src/std/io/textColorModes.hpp similarity index 100% rename from src/IO/textColorModes.hpp rename to src/std/io/textColorModes.hpp diff --git a/src/memory.hpp b/src/std/memory.hpp similarity index 100% rename from src/memory.hpp rename to src/std/memory.hpp diff --git a/src/memoryMap.hpp b/src/std/memoryMap.hpp similarity index 85% rename from src/memoryMap.hpp rename to src/std/memoryMap.hpp index 79d08dd..da235b0 100644 --- a/src/memoryMap.hpp +++ b/src/std/memoryMap.hpp @@ -4,7 +4,8 @@ #ifndef ROMAINOS_MEMORYMAP_HPP #define ROMAINOS_MEMORYMAP_HPP -#include "types.hpp" +#include +#include /** * Nombre de régions @@ -104,17 +105,17 @@ namespace std::memory { * @param entry Memory map entry */ void printMemoryMap(MemoryMapEntry* entry) { - std::IO::printString("Memory base: \t\t", ""); - std::IO::printInt(entry->baseAddress); + std::io::printString("Memory base: \t\t", ""); + std::io::printInt(entry->baseAddress); - std::IO::printString("Memory length: \t\t", ""); - std::IO::printInt(entry->regionLength); + std::io::printString("Memory length: \t\t", ""); + std::io::printInt(entry->regionLength); - std::IO::printString("Memory type: \t\t", ""); - std::IO::printHex(entry->regionType); + std::io::printString("Memory type: \t\t", ""); + std::io::printHex(entry->regionType); - std::IO::printString("Memory attributes: \t", ""); - std::IO::printHex(entry->extendedAttributes); + std::io::printString("Memory attributes: \t", ""); + std::io::printHex(entry->extendedAttributes); } /** @@ -125,7 +126,7 @@ namespace std::memory { std::memory::MemoryMapEntry* entry = (std::memory::MemoryMapEntry*) 0x5000; entry += i; std::memory::printMemoryMap(entry); - std::IO::printString(); + std::io::printString(); } } @@ -138,7 +139,7 @@ namespace std::memory { for (u8 i=0; i /** * Stack diff --git a/src/string.hpp b/src/std/string.hpp similarity index 98% rename from src/string.hpp rename to src/std/string.hpp index 7d42fac..8ae1eb6 100644 --- a/src/string.hpp +++ b/src/std/string.hpp @@ -4,8 +4,8 @@ #ifndef ROMAINOS_STRING_HPP #define ROMAINOS_STRING_HPP -#include "types.hpp" -#include "stack.hpp" +#include +#include /** * Récupère la taille d'une string diff --git a/src/system.hpp b/src/std/system.hpp similarity index 55% rename from src/system.hpp rename to src/std/system.hpp index 609eccb..69f5136 100644 --- a/src/system.hpp +++ b/src/std/system.hpp @@ -4,7 +4,8 @@ #ifndef ROMAINOS_SYSTEM_HPP #define ROMAINOS_SYSTEM_HPP -#include +#include +#include #include extern "C" void _exit(); @@ -14,9 +15,9 @@ namespace std::system { * Shutdown */ void shutdown() { - std::IO::outw(0x604, 0x2000); // Qemu - std::IO::outw(0x4004, 0x3400); // VBox - std::IO::outw(0xB004, 0x2000); // Boshs + std::io::outw(0x604, 0x2000); // Qemu + std::io::outw(0x4004, 0x3400); // VBox + std::io::outw(0xB004, 0x2000); // Boshs _exit(); } @@ -25,15 +26,15 @@ namespace std::system { * Shutdown avec un message */ void shutdownAndPrint() { - std::IO::setCursorPosition(-1, 0); - std::IO::printString("Fin du programme..."); + std::io::setCursorPosition(-1, 0); + std::io::printString("Fin du programme..."); std::time::sleep(1); shutdown(); - std::IO::setCursorPosition(-1, 0); - std::IO::printString("Erreur lors de la sortie de l'emulateur !"); + std::io::setCursorPosition(-1, 0); + std::io::printString("Erreur lors de la sortie de l'emulateur !"); std::time::sleep(1); } } diff --git a/src/time.hpp b/src/std/time.hpp similarity index 100% rename from src/time.hpp rename to src/std/time.hpp diff --git a/src/types.hpp b/src/std/types.hpp similarity index 100% rename from src/types.hpp rename to src/std/types.hpp