Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
refactor: Dossier kernel
Browse files Browse the repository at this point in the history
En prévision de quand différents programmes seront chargés
  • Loading branch information
RomainTHD committed Oct 3, 2020
1 parent 91c73cb commit 2a29ebc
Show file tree
Hide file tree
Showing 31 changed files with 95 additions and 77 deletions.
26 changes: 14 additions & 12 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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++..."
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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..."
Expand Down
20 changes: 0 additions & 20 deletions src/kernel.cpp

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/kernel/kernel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Created by Romain on 08/09/2020.

#include <io/printText.hpp>
#include <io/IDT.hpp>
#include <io/IO.hpp>
#include <memory.hpp>

/**
* 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);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 6 additions & 5 deletions src/IO/IDT.hpp → src/std/io/IDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#ifndef ROMAINOS_IDT_HPP
#define ROMAINOS_IDT_HPP

#include "types.hpp"
#include <types.hpp>

#include "keyboard.hpp"

namespace std::IO::IDT {
namespace std::io::idt {
/**
* Interrupt Descriptor Tables
*/
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -106,7 +107,7 @@ namespace std::IO::IDT {
outb(0x20, 0x20);
outb(0xa0, 0x20);

std::IO::handleEvent(b);
std::io::handleEvent(b);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/std/io/IO.hpp
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/IO/keyboard.hpp → src/std/io/keyboard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "keyboardLayouts/AZERTY.hpp"

namespace std::IO {
namespace std::io {
/**
* Différents layouts
*/
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 9 additions & 9 deletions src/IO/printText.hpp → src/std/io/printText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#ifndef ROMAINOS_PRINTTEXT_HPP
#define ROMAINOS_PRINTTEXT_HPP

#include "types.hpp"
#include "string.hpp"
#include <types.hpp>
#include <string.hpp>

#include "IO/IO.hpp"
#include "IO/textColorModes.hpp"
#include "rawIO.hpp"
#include "textColorModes.hpp"

/**
* Emplacement VRAM
Expand All @@ -30,7 +30,7 @@
*/
#define TAB_LENGTH 4

namespace std::IO {
namespace std::io {
namespace {
/**
* Position du curseur
Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/IO/IO.hpp → src/std/io/rawIO.hpp
Original file line number Diff line number Diff line change
@@ -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 <types.hpp>

namespace std::IO {
namespace std::io {
/**
* Transfère de la data à travers les ports sur un octet
*
Expand All @@ -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));
}

Expand Down Expand Up @@ -50,4 +50,4 @@ namespace std::IO {
return res;
}
}
#endif //ROMAINOS_IO_HPP
#endif //ROMAINOS_RAWIO_HPP
File renamed without changes.
File renamed without changes.
23 changes: 12 additions & 11 deletions src/memoryMap.hpp → src/std/memoryMap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#ifndef ROMAINOS_MEMORYMAP_HPP
#define ROMAINOS_MEMORYMAP_HPP

#include "types.hpp"
#include <types.hpp>
#include <io/IO.hpp>

/**
* Nombre de régions
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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();
}
}

Expand All @@ -138,7 +139,7 @@ namespace std::memory {
for (u8 i=0; i<std::memory::getNumberOfUsableMemoryRegions(); i++) {
std::memory::MemoryMapEntry* entry = usableMemoryMap[i];
std::memory::printMemoryMap(entry);
std::IO::printString();
std::io::printString();
}
}
}
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/stack.hpp → src/std/stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef ROMAINOS_STACK_HPP
#define ROMAINOS_STACK_HPP

#include "types.hpp"
#include <types.hpp>

/**
* Stack
Expand Down
4 changes: 2 additions & 2 deletions src/string.hpp → src/std/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#ifndef ROMAINOS_STRING_HPP
#define ROMAINOS_STRING_HPP

#include "types.hpp"
#include "stack.hpp"
#include <types.hpp>
#include <stack.hpp>

/**
* Récupère la taille d'une string
Expand Down
17 changes: 9 additions & 8 deletions src/system.hpp → src/std/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#ifndef ROMAINOS_SYSTEM_HPP
#define ROMAINOS_SYSTEM_HPP

#include <IO/IO.hpp>
#include <io/rawIO.hpp>
#include <io/printText.hpp>
#include <time.hpp>

extern "C" void _exit();
Expand All @@ -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();
}
Expand All @@ -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);
}
}
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 2a29ebc

Please sign in to comment.