1

Switch int to sized types

This commit is contained in:
2022-12-07 18:08:15 +01:00
parent d8fce00eed
commit ae98dc586e
32 changed files with 202 additions and 180 deletions

View File

@ -13,6 +13,7 @@
*****************************************************************************/ *****************************************************************************/
#include "CGA.h" #include "CGA.h"
#include "lib/mem/Memory.h" #include "lib/mem/Memory.h"
#include <cstdint>
const IOport CGA::index_port(0x3d4); const IOport CGA::index_port(0x3d4);
const IOport CGA::data_port(0x3d5); const IOport CGA::data_port(0x3d5);
@ -26,7 +27,7 @@ CGA::cga_page_t* const CGA::SCREEN_PAGE {reinterpret_cast<CGA::cga_page_t*>(0xb8
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Setzen des Cursors in Spalte x und Zeile y. * * Beschreibung: Setzen des Cursors in Spalte x und Zeile y. *
*****************************************************************************/ *****************************************************************************/
void CGA::setpos(unsigned int x, unsigned int y) { void CGA::setpos(uint8_t x, uint8_t y) {
/* Hier muess Code eingefuegt werden */ /* Hier muess Code eingefuegt werden */
@ -49,7 +50,7 @@ void CGA::setpos(unsigned int x, unsigned int y) {
* * * *
* Rückgabewerte: x und y * * Rückgabewerte: x und y *
*****************************************************************************/ *****************************************************************************/
void CGA::getpos(unsigned int& x, unsigned int& y) { void CGA::getpos(uint8_t& x, uint8_t& y) {
/* Hier muess Code eingefuegt werden */ /* Hier muess Code eingefuegt werden */
@ -77,7 +78,7 @@ void CGA::getpos(unsigned int& x, unsigned int& y) {
* character Das auszugebende Zeichen * * character Das auszugebende Zeichen *
* attrib Attributbyte fuer das Zeichen * * attrib Attributbyte fuer das Zeichen *
*****************************************************************************/ *****************************************************************************/
void CGA::show(unsigned int x, unsigned int y, char character, unsigned char attrib) { void CGA::show(uint8_t x, uint8_t y, char character, uint8_t attrib) {
/* Hier muess Code eingefuegt werden */ /* Hier muess Code eingefuegt werden */
@ -106,8 +107,8 @@ void CGA::print(const bse::string_view string, unsigned char attrib) const {
/* Hier muess Code eingefuegt werden */ /* Hier muess Code eingefuegt werden */
unsigned int cursor_x = 0; uint8_t cursor_x = 0;
unsigned int cursor_y = 0; // Don't poll registers every stroke uint8_t cursor_y = 0; // Don't poll registers every stroke
getpos(cursor_x, cursor_y); getpos(cursor_x, cursor_y);
for (char current : string) { for (char current : string) {

View File

@ -14,6 +14,7 @@
#ifndef CGA_include_H_ #ifndef CGA_include_H_
#define CGA_include_H_ #define CGA_include_H_
#include <cstdint>
#include "device/port/IOport.h" #include "device/port/IOport.h"
#include "lib/util/Array.h" #include "lib/util/Array.h"
#include "lib/util/Span.h" #include "lib/util/Span.h"
@ -83,16 +84,16 @@ public:
static cga_page_t* const SCREEN_PAGE; // No span because can't address anything in [0, 1] static cga_page_t* const SCREEN_PAGE; // No span because can't address anything in [0, 1]
// Setzen des Cursors in Spalte x und Zeile y. // Setzen des Cursors in Spalte x und Zeile y.
static void setpos(unsigned int x, unsigned int y); static void setpos(uint8_t x, uint8_t y);
// Abfragen der Cursorpostion // Abfragen der Cursorpostion
static void getpos(unsigned int& x, unsigned int& y) ; static void getpos(uint8_t& x, uint8_t& y) ;
// Anzeige eines Zeichens mit Attribut an einer bestimmten Stelle // Anzeige eines Zeichens mit Attribut an einer bestimmten Stelle
static void show(unsigned int x, unsigned int y, char character, unsigned char attrib = STD_ATTR); static void show(uint8_t x, uint8_t y, char character, uint8_t attrib = STD_ATTR);
// Anzeige mehrerer Zeichen ab der aktuellen Cursorposition // Anzeige mehrerer Zeichen ab der aktuellen Cursorposition
void print(const bse::string_view substring, unsigned char attrib = STD_ATTR) const; void print(const bse::string_view substring, uint8_t attrib = STD_ATTR) const;
// Verschiebt den Bildschirminhalt um eine Zeile nach oben. // Verschiebt den Bildschirminhalt um eine Zeile nach oben.
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen // Neue Zeile am unteren Bildrand mit Leerzeichen fuellen

View File

@ -4,9 +4,11 @@
/* */ /* */
/* Font file generated by cpi2fnt */ /* Font file generated by cpi2fnt */
/* */ /* */
#include <cstdint>
/**********************************************/ /**********************************************/
constexpr const unsigned int FONTDATAMAX_8x16 = 4096; constexpr const uint32_t FONTDATAMAX_8x16 = 4096;
constexpr const unsigned char fontdata_8x16[FONTDATAMAX_8x16] = { constexpr const unsigned char fontdata_8x16[FONTDATAMAX_8x16] = {

View File

@ -6,7 +6,7 @@
/* */ /* */
/**********************************************/ /**********************************************/
constexpr const unsigned int FONTDATAMAX_8x8 = 2048; constexpr const uint32_t FONTDATAMAX_8x8 = 2048;
constexpr const unsigned char fontdata_8x8[FONTDATAMAX_8x8] = { constexpr const unsigned char fontdata_8x8[FONTDATAMAX_8x8] = {

View File

@ -11,7 +11,7 @@
/* */ /* */
/**********************************************/ /**********************************************/
constexpr const unsigned int FONTDATAMAX_PEARL_8x8 = 2048; constexpr const uint32_t FONTDATAMAX_PEARL_8x8 = 2048;
constexpr const unsigned char fontdata_pearl_8x8[FONTDATAMAX_PEARL_8x8] = { constexpr const unsigned char fontdata_pearl_8x8[FONTDATAMAX_PEARL_8x8] = {

View File

@ -1,6 +1,6 @@
// vim: set et ts=4 sw=4: // vim: set et ts=4 sw=4:
constexpr const unsigned int FONTDATAMAX_SUN_12x22 = 11264; constexpr const uint32_t FONTDATAMAX_SUN_12x22 = 11264;
constexpr const unsigned char fontdata_sun_12x22[FONTDATAMAX_SUN_12x22] = { constexpr const unsigned char fontdata_sun_12x22[FONTDATAMAX_SUN_12x22] = {

View File

@ -1,6 +1,6 @@
// vim: set et ts=4 sw=4: // vim: set et ts=4 sw=4:
constexpr const unsigned int FONTDATAMAX_SUN8x16 = 4096; constexpr const uint32_t FONTDATAMAX_SUN8x16 = 4096;
constexpr const unsigned char fontdata_sun_8x16[FONTDATAMAX_SUN8x16] = { constexpr const unsigned char fontdata_sun_8x16[FONTDATAMAX_SUN8x16] = {
/* */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

View File

@ -11,34 +11,35 @@
#ifndef FONTS_H__ #ifndef FONTS_H__
#define FONTS_H__ #define FONTS_H__
#include <cstdint>
#include "lib/util/Array.h" #include "lib/util/Array.h"
class Font { class Font {
public: public:
virtual ~Font() = default; virtual ~Font() = default;
virtual const unsigned char* getChar(int c) const = 0; virtual const unsigned char* getChar(uint32_t c) const = 0;
virtual unsigned int get_char_width() const = 0; virtual uint32_t get_char_width() const = 0;
virtual unsigned int get_char_height() const = 0; virtual uint32_t get_char_height() const = 0;
}; };
template<unsigned int width, unsigned int height, const unsigned char* data> template<uint32_t width, uint32_t height, const uint8_t* data>
class FontInstance : public Font { class FontInstance : public Font {
const unsigned int char_width; const uint32_t char_width;
const unsigned int char_height; const uint32_t char_height;
const unsigned int char_mem_size; const uint32_t char_mem_size;
const unsigned char* font_data; const uint8_t* font_data;
public: public:
FontInstance() : char_width(width), char_height(height), char_mem_size((((char_width + (8 >> 1)) / 8) * char_height)), font_data(data) {} FontInstance() : char_width(width), char_height(height), char_mem_size((((char_width + (8 >> 1)) / 8) * char_height)), font_data(data) {}
inline const unsigned char* getChar(int c) const override { inline const uint8_t* getChar(uint32_t c) const override {
return &font_data[char_mem_size * c]; return &font_data[char_mem_size * c];
} }
inline unsigned int get_char_width() const override { inline uint32_t get_char_width() const override {
return char_width; return char_width;
} }
inline unsigned int get_char_height() const override { inline uint32_t get_char_height() const override {
return char_height; return char_height;
} }
}; };

View File

@ -15,8 +15,8 @@
#include "LFBgraphics.h" #include "LFBgraphics.h"
/* Hilfsfunktionen */ /* Hilfsfunktionen */
void swap(unsigned int* a, unsigned int* b); void swap(uint32_t* a, uint32_t* b);
int abs(int a); uint16_t abs(int32_t a);
/***************************************************************************** /*****************************************************************************
* Methode: LFBgraphics::drawMonoBitmap * * Methode: LFBgraphics::drawMonoBitmap *
@ -35,17 +35,17 @@ int abs(int a);
* mit cpi2fnt (AmigaOS) erzeugt wurden. Das Format erklaert* * mit cpi2fnt (AmigaOS) erzeugt wurden. Das Format erklaert*
* sich in den C-Dateien in fonts/ von selbst. * * sich in den C-Dateien in fonts/ von selbst. *
*****************************************************************************/ *****************************************************************************/
inline void LFBgraphics::drawMonoBitmap(unsigned int x, unsigned int y, inline void LFBgraphics::drawMonoBitmap(uint32_t x, uint32_t y,
unsigned int width, unsigned int height, uint32_t width, uint32_t height,
const unsigned char* bitmap, unsigned int color) const { const uint8_t* bitmap, uint32_t color) const {
// Breite in Bytes // Breite in Bytes
unsigned short width_byte = width / 8 + ((width % 8 != 0) ? 1 : 0); unsigned short width_byte = width / 8 + ((width % 8 != 0) ? 1 : 0);
for (unsigned int yoff = 0; yoff < height; ++yoff) { for (uint32_t yoff = 0; yoff < height; ++yoff) {
unsigned int xpos = x; uint32_t xpos = x;
unsigned int ypos = y + yoff; uint32_t ypos = y + yoff;
for (unsigned int xb = 0; xb < width_byte; ++xb) { for (uint32_t xb = 0; xb < width_byte; ++xb) {
for (int src = 7; src >= 0; --src) { for (int32_t src = 7; src >= 0; --src) {
if ((1 << src) & *bitmap) { if ((1 << src) & *bitmap) {
drawPixel(xpos, ypos, color); drawPixel(xpos, ypos, color);
} }
@ -68,8 +68,8 @@ inline void LFBgraphics::drawMonoBitmap(unsigned int x, unsigned int y,
* Beschreibung: Gibt eine Zeichenkette mit gewaehlter Schrift an der * * Beschreibung: Gibt eine Zeichenkette mit gewaehlter Schrift an der *
* Position x,y aus. * * Position x,y aus. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::drawString(const Font& fnt, unsigned int x, unsigned int y, void LFBgraphics::drawString(const Font& fnt, uint32_t x, uint32_t y,
unsigned int col, const char* str, unsigned int len) const { uint32_t col, const char* str, uint32_t len) const {
for (unsigned int i = 0; i < len; ++i) { for (unsigned int i = 0; i < len; ++i) {
drawMonoBitmap(x, y, fnt.get_char_width(), fnt.get_char_height(), fnt.getChar(*(str + i)), col); drawMonoBitmap(x, y, fnt.get_char_width(), fnt.get_char_height(), fnt.getChar(*(str + i)), col);
x += fnt.get_char_width(); x += fnt.get_char_width();
@ -192,7 +192,7 @@ void LFBgraphics::drawSprite(unsigned int width, unsigned int height, unsigned i
* Beschreibung: Bildschirm loeschen. * * Beschreibung: Bildschirm loeschen. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::clear() const { void LFBgraphics::clear() const {
unsigned int* ptr = reinterpret_cast<unsigned int*>(lfb); auto* ptr = reinterpret_cast<uint32_t*>(lfb);
unsigned int i; unsigned int i;
if (hfb == 0 || lfb == 0) { if (hfb == 0 || lfb == 0) {
@ -200,7 +200,7 @@ void LFBgraphics::clear() const {
} }
if (mode == 0) { if (mode == 0) {
ptr = reinterpret_cast<unsigned int*>(hfb); ptr = reinterpret_cast<uint32_t*>(hfb);
} }
switch (bpp) { switch (bpp) {
@ -243,9 +243,9 @@ void LFBgraphics::setDrawingBuff(int v) {
* Beschreibung: Kopiert den versteckten Puffer in den sichtbaren LFB. * * Beschreibung: Kopiert den versteckten Puffer in den sichtbaren LFB. *
*****************************************************************************/ *****************************************************************************/
void LFBgraphics::copyHiddenToVisible() const { void LFBgraphics::copyHiddenToVisible() const {
unsigned int* sptr = reinterpret_cast<unsigned int*>(hfb); auto* sptr = reinterpret_cast<uint32_t*>(hfb);
unsigned int* dptr = reinterpret_cast<unsigned int*>(lfb); auto* dptr = reinterpret_cast<uint32_t*>(lfb);
unsigned int i; uint32_t i;
if (hfb == 0 || lfb == 0) { if (hfb == 0 || lfb == 0) {
return; return;
@ -276,14 +276,14 @@ void LFBgraphics::copyHiddenToVisible() const {
} }
} }
void swap(unsigned int* a, unsigned int* b) { void swap(uint32_t* a, uint32_t* b) {
unsigned int h = *a; uint32_t h = *a;
*a = *b; *a = *b;
*b = h; *b = h;
} }
int abs(int a) { uint16_t abs(int32_t a) {
if (a < 0) { if (a < 0) {
return -a; return -a;
} }

View File

@ -18,7 +18,7 @@
#include "Fonts.h" #include "Fonts.h"
// Hilfsfunktionen um Farbwerte fuer einen Pixel zu erzeugen // Hilfsfunktionen um Farbwerte fuer einen Pixel zu erzeugen
constexpr unsigned int RGB_24(unsigned int r, unsigned int g, unsigned int b) { constexpr uint32_t RGB_24(uint8_t r, uint8_t g, uint8_t b) {
return ((r << 16) + (g << 8) + b); return ((r << 16) + (g << 8) + b);
} }
@ -28,23 +28,23 @@ constexpr const bool BUFFER_VISIBLE = true;
class LFBgraphics { class LFBgraphics {
private: private:
// Hilfsfunktion fuer drawString // Hilfsfunktion fuer drawString
void drawMonoBitmap(unsigned int x, unsigned int y, void drawMonoBitmap(uint32_t x, uint32_t y,
unsigned int width, unsigned int height, uint32_t width, uint32_t height,
const unsigned char* bitmap, unsigned int col) const; const unsigned char* bitmap, uint32_t col) const;
public: public:
LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren
LFBgraphics() : mode(BUFFER_VISIBLE) {}; LFBgraphics() : mode(BUFFER_VISIBLE) {};
unsigned int xres, yres; // Aufloesung in Pixel uint32_t xres, yres; // Aufloesung in Pixel
unsigned int bpp; // Farbtiefe (Bits per Pixel) uint8_t bpp; // Farbtiefe (Bits per Pixel)
unsigned int lfb; // Adresse des Linearen Framebuffers uint32_t lfb; // Adresse des Linearen Framebuffers
unsigned int hfb; // Adresse des versteckten Buffers (optional, fuer Animationen) uint32_t hfb; // Adresse des versteckten Buffers (optional, fuer Animationen)
unsigned int mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer uint8_t mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer
void clear() const; void clear() const;
void drawPixel(unsigned int x, unsigned int y, unsigned int col) const; void drawPixel(uint32_t x, uint32_t y, uint32_t col) const;
void drawString(const Font& fnt, unsigned int x, unsigned int y, unsigned int col, const char* str, unsigned int len) const; void drawString(const Font& fnt, unsigned int x, unsigned int y, unsigned int col, const char* str, unsigned int len) const;

View File

@ -33,9 +33,9 @@ struct VbeModeInfoBlock {
unsigned char rsv_mask, rsv_position; unsigned char rsv_mask, rsv_position;
unsigned char directcolor_attributes; unsigned char directcolor_attributes;
unsigned int physbase; // Adresse des Linear-Framebuffers uint32_t physbase; // Adresse des Linear-Framebuffers
unsigned int OffScreenMemOffset; uint32_t OffScreenMemOffset;
unsigned short OffScreenMemSize; uint32_t OffScreenMemSize;
} __attribute__((packed)); } __attribute__((packed));
// Informationen ueber die Grafikkarte // Informationen ueber die Grafikkarte
@ -92,8 +92,8 @@ bool VESA::initGraphicMode(unsigned short mode) {
// kout << "TotalVideoMemory: " << ((ib->TotalMemory*65536) / (1024*1024)) << " MB" << endl; // kout << "TotalVideoMemory: " << ((ib->TotalMemory*65536) / (1024*1024)) << " MB" << endl;
// Gewuenschten Grafikmodus aus Antwort suchen // Gewuenschten Grafikmodus aus Antwort suchen
unsigned short* modePtr = reinterpret_cast<unsigned short*>((ib->VideoModePtr[1] << 4) + ib->VideoModePtr[0]); auto* modePtr = reinterpret_cast<uint16_t*>((ib->VideoModePtr[1] << 4) + ib->VideoModePtr[0]);
for (int i = 0; modePtr[i] != 0xFFFF; ++i) { for (uint32_t i = 0; modePtr[i] != 0xFFFF; ++i) {
// Gewuenschter Grafikmodus gefunden? // Gewuenschter Grafikmodus gefunden?
if (modePtr[i] == mode) { if (modePtr[i] == mode) {
VbeModeInfoBlock* minf = reinterpret_cast<VbeModeInfoBlock*>(RETURN_MEM); VbeModeInfoBlock* minf = reinterpret_cast<VbeModeInfoBlock*>(RETURN_MEM);
@ -114,7 +114,7 @@ bool VESA::initGraphicMode(unsigned short mode) {
mode_nr = mode; mode_nr = mode;
xres = minf->Xres; xres = minf->Xres;
yres = minf->Yres; yres = minf->Yres;
bpp = static_cast<int>(minf->bpp); bpp = static_cast<uint8_t>(minf->bpp);
lfb = minf->physbase; lfb = minf->physbase;
hfb = reinterpret_cast<unsigned int>(new char[xres * yres * bpp / 8]); hfb = reinterpret_cast<unsigned int>(new char[xres * yres * bpp / 8]);

View File

@ -15,12 +15,12 @@
#include "kernel/log/Logger.h" #include "kernel/log/Logger.h"
// Ausgewaehlte Grafikmodi mit Mode-Nummer // Ausgewaehlte Grafikmodi mit Mode-Nummer
constexpr const unsigned int MODE_640_480_16BITS = 0x111; constexpr const uint16_t MODE_640_480_16BITS = 0x111;
constexpr const unsigned int MODE_640_480_24BITS = 0x112; constexpr const uint16_t MODE_640_480_24BITS = 0x112;
constexpr const unsigned int MODE_800_600_16BITS = 0x114; constexpr const uint16_t MODE_800_600_16BITS = 0x114;
constexpr const unsigned int MODE_800_600_24BITS = 0x115; constexpr const uint16_t MODE_800_600_24BITS = 0x115;
constexpr const unsigned int MODE_1024_768_16BITS = 0x117; constexpr const uint16_t MODE_1024_768_16BITS = 0x117;
constexpr const unsigned int MODE_1024_768_24BITS = 0x118; constexpr const uint16_t MODE_1024_768_24BITS = 0x118;
class VESA : public LFBgraphics { class VESA : public LFBgraphics {
private: private:

View File

@ -284,7 +284,7 @@ Key Keyboard::key_hit() {
* Beschreibung: Fuehrt einen Neustart des Rechners durch. * * Beschreibung: Fuehrt einen Neustart des Rechners durch. *
*****************************************************************************/ *****************************************************************************/
void Keyboard::reboot() { void Keyboard::reboot() {
int status; uint8_t status;
// Dem BIOS mitteilen, dass das Reset beabsichtigt war // Dem BIOS mitteilen, dass das Reset beabsichtigt war
// und kein Speichertest durchgefuehrt werden muss. // und kein Speichertest durchgefuehrt werden muss.
@ -310,7 +310,7 @@ void Keyboard::reboot() {
* sollen. Erlaubt sind Werte zwischen 0 (sehr schnell) * * sollen. Erlaubt sind Werte zwischen 0 (sehr schnell) *
* und 31 (sehr langsam). * * und 31 (sehr langsam). *
*****************************************************************************/ *****************************************************************************/
void Keyboard::set_repeat_rate(int speed, int delay) { void Keyboard::set_repeat_rate(uint8_t speed, uint8_t delay) {
/* Hier muss Code eingefuegt werden. */ /* Hier muss Code eingefuegt werden. */
} }

View File

@ -11,6 +11,7 @@
#ifndef Keyboard_include__ #ifndef Keyboard_include__
#define Keyboard_include__ #define Keyboard_include__
#include <cstdint>
#include "Key.h" #include "Key.h"
#include "kernel/interrupt/ISR.h" #include "kernel/interrupt/ISR.h"
#include "device/port/IOport.h" #include "device/port/IOport.h"
@ -85,7 +86,7 @@ public:
static void reboot(); static void reboot();
// Einstellen der Wiederholungsrate der Tastatur. // Einstellen der Wiederholungsrate der Tastatur.
void set_repeat_rate(int speed, int delay); void set_repeat_rate(uint8_t speed, uint8_t delay);
// Setzt oder loescht die angegebene Leuchtdiode. // Setzt oder loescht die angegebene Leuchtdiode.
void set_led(char led, bool on); void set_led(char led, bool on);

View File

@ -31,14 +31,14 @@ IOport const PIC::IMR2(0xa1); // interrupt mask register von PIC 2
* Parameter: * * Parameter: *
* irq: IRQ der erlaubt werden soll * * irq: IRQ der erlaubt werden soll *
*****************************************************************************/ *****************************************************************************/
void PIC::allow(int irq) { void PIC::allow(uint8_t irq) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
// NOTE: allow sets the bit to 0 // NOTE: allow sets the bit to 0
unsigned char IMR; uint8_t IMR;
unsigned char mask = ~(0x1 << (irq % 8)); uint8_t mask = ~(0x1 << (irq % 8));
if (irq < 8) { if (irq < 8) {
// PIC 1 // PIC 1
IMR = IMR1.inb(); // We don't want to change the other interrupt masks so use this as start value IMR = IMR1.inb(); // We don't want to change the other interrupt masks so use this as start value
@ -58,14 +58,14 @@ void PIC::allow(int irq) {
* Parameter: * * Parameter: *
* interrupt: IRQ der maskiert werden soll * * interrupt: IRQ der maskiert werden soll *
*****************************************************************************/ *****************************************************************************/
void PIC::forbid(int irq) { void PIC::forbid(uint8_t irq) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
// NOTE: forbid sets the bit to 1 // NOTE: forbid sets the bit to 1
unsigned char IMR; uint8_t IMR;
unsigned char mask = 0x1 << (irq % 8); uint8_t mask = 0x1 << (irq % 8);
if (irq < 8) { if (irq < 8) {
// PIC 1 // PIC 1
IMR = IMR1.inb(); // We don't want to change the other interrupt masks so use this as start value IMR = IMR1.inb(); // We don't want to change the other interrupt masks so use this as start value
@ -86,11 +86,11 @@ void PIC::forbid(int irq) {
* Parameter: * * Parameter: *
* irq: IRQ dessen Status erfragt werden soll * * irq: IRQ dessen Status erfragt werden soll *
*****************************************************************************/ *****************************************************************************/
bool PIC::status(int irq) { bool PIC::status(uint8_t irq) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
unsigned char IMR; uint8_t IMR;
if (irq < 8) { if (irq < 8) {
// PIC 1 // PIC 1
IMR = IMR1.inb(); IMR = IMR1.inb();
@ -100,6 +100,6 @@ bool PIC::status(int irq) {
} }
// Use % 8 to account for two PICs // Use % 8 to account for two PICs
unsigned char mask = 0x1 << (irq % 8); uint8_t mask = 0x1 << (irq % 8);
return IMR & mask; return IMR & mask;
} }

View File

@ -17,6 +17,7 @@
#ifndef PIC_include__ #ifndef PIC_include__
#define PIC_include__ #define PIC_include__
#include <cstdint>
#include "device/port/IOport.h" #include "device/port/IOport.h"
class PIC { class PIC {
@ -39,13 +40,13 @@ public:
}; };
// Freischalten der Weiterleitung eines IRQs durch den PIC an die CPU // Freischalten der Weiterleitung eines IRQs durch den PIC an die CPU
static void allow(int irq); static void allow(uint8_t irq);
// Unterdruecken der Weiterleitung eines IRQs durch den PIC an die CPU // Unterdruecken der Weiterleitung eines IRQs durch den PIC an die CPU
static void forbid(int irq); static void forbid(uint8_t irq);
// Abfragen, ob die Weiterleitung fuer einen bestimmten IRQ unterdrueckt ist // Abfragen, ob die Weiterleitung fuer einen bestimmten IRQ unterdrueckt ist
static bool status(int interrupt_device); static bool status(uint8_t interrupt_device);
}; };
#endif #endif

View File

@ -27,10 +27,10 @@ const IOport PCSPK::ppi(0x61);
* Rückgabewerte: f: Frequenz des Tons * * Rückgabewerte: f: Frequenz des Tons *
* len: Laenge des Tons in ms * * len: Laenge des Tons in ms *
*****************************************************************************/ *****************************************************************************/
void PCSPK::play(float f, int len) { void PCSPK::play(float f, uint32_t len) {
int freq = static_cast<int>(f); auto freq = static_cast<uint32_t>(f);
int cntStart = 1193180 / freq; uint32_t cntStart = 1193180 / freq;
int status; uint8_t status;
// Zaehler laden // Zaehler laden
control.outb(0xB6); // Zaehler-2 konfigurieren control.outb(0xB6); // Zaehler-2 konfigurieren
@ -38,7 +38,7 @@ void PCSPK::play(float f, int len) {
data2.outb(cntStart / 256); // Zaehler-2 laden (Hibyte) data2.outb(cntStart / 256); // Zaehler-2 laden (Hibyte)
// Lautsprecher einschalten // Lautsprecher einschalten
status = static_cast<int>(ppi.inb()); // Status-Register des PPI auslesen status = static_cast<uint8_t>(ppi.inb()); // Status-Register des PPI auslesen
ppi.outb(status | 3); // Lautpsrecher Einschalten ppi.outb(status | 3); // Lautpsrecher Einschalten
// Pause // Pause
@ -54,9 +54,9 @@ void PCSPK::play(float f, int len) {
* Beschreibung: Lautsprecher ausschalten. * * Beschreibung: Lautsprecher ausschalten. *
*****************************************************************************/ *****************************************************************************/
void PCSPK::off() { void PCSPK::off() {
int status; uint8_t status;
status = static_cast<int>(ppi.inb()); // Status-Register des PPI auslesen status = static_cast<uint8_t>(ppi.inb()); // Status-Register des PPI auslesen
ppi.outb((status >> 2) << 2); // Lautsprecher ausschalten ppi.outb((status >> 2) << 2); // Lautsprecher ausschalten
} }
@ -67,7 +67,7 @@ void PCSPK::off() {
* * * *
* Parameter: time (delay in ms) * * Parameter: time (delay in ms) *
*****************************************************************************/ *****************************************************************************/
inline void PCSPK::delay(int time) { inline void PCSPK::delay(uint32_t time) {
/* Hier muess Code eingefuegt werden */ /* Hier muess Code eingefuegt werden */

View File

@ -15,6 +15,7 @@
#ifndef PCSPK_include__ #ifndef PCSPK_include__
#define PCSPK_include__ #define PCSPK_include__
#include <cstdint>
#include "device/port/IOport.h" #include "device/port/IOport.h"
// Note, Frequenz // Note, Frequenz
@ -65,7 +66,7 @@ private:
static const IOport ppi; // Status-Register des PPI static const IOport ppi; // Status-Register des PPI
// Verzoegerung um X ms (in 1ms Schritten; Min. 1ms) // Verzoegerung um X ms (in 1ms Schritten; Min. 1ms)
static inline void delay(int time); static inline void delay(uint32_t time);
public: public:
PCSPK(const PCSPK& copy) = delete; // Verhindere Kopieren PCSPK(const PCSPK& copy) = delete; // Verhindere Kopieren
@ -80,7 +81,7 @@ public:
static void aerodynamic(); static void aerodynamic();
// Ton abspielen // Ton abspielen
static void play(float f, int len); static void play(float f, uint32_t len);
// Lautsprecher ausschalten // Lautsprecher ausschalten
static void off(); static void off();

View File

@ -23,13 +23,13 @@ const IOport PIT::data0(0x40);
* us: Zeitintervall in Mikrosekunden, nachdem periodisch ein * * us: Zeitintervall in Mikrosekunden, nachdem periodisch ein *
* Interrupt erzeugt werden soll. * * Interrupt erzeugt werden soll. *
*****************************************************************************/ *****************************************************************************/
void PIT::interval(int us) { void PIT::interval(uint32_t us) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
control.outb(0x36); // Zähler 0 Mode 3 control.outb(0x36); // Zähler 0 Mode 3
unsigned int cntStart = static_cast<unsigned int>((1193180.0 / 1000000.0) * us); // 1.19Mhz PIT uint32_t cntStart = static_cast<unsigned int>((1193180.0 / 1000000.0) * us); // 1.19Mhz PIT
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte) data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte) data0.outb(cntStart >> 8); // Zaehler-0 laden (Hibyte)

View File

@ -14,6 +14,7 @@
#include "kernel/interrupt/ISR.h" #include "kernel/interrupt/ISR.h"
#include "device/port/IOport.h" #include "device/port/IOport.h"
#include "lib/util/Array.h" #include "lib/util/Array.h"
#include <cstdint>
class PIT : public ISR { class PIT : public ISR {
private: private:
@ -21,11 +22,11 @@ private:
const static IOport data0; const static IOport data0;
enum { time_base = 838 }; /* ns */ enum { time_base = 838 }; /* ns */
int timer_interval; uint32_t timer_interval;
const bse::array<char, 4> indicator{'|', '/', '-', '\\'}; const bse::array<char, 4> indicator{'|', '/', '-', '\\'};
unsigned int indicator_pos = 0; uint8_t indicator_pos = 0;
unsigned long last_indicator_refresh = 0; uint64_t last_indicator_refresh = 0;
public: public:
PIT(const PIT& copy) = delete; // Verhindere Kopieren PIT(const PIT& copy) = delete; // Verhindere Kopieren
@ -33,16 +34,16 @@ public:
// ~PIT() override = default; // ~PIT() override = default;
// Zeitgeber initialisieren. // Zeitgeber initialisieren.
explicit PIT(int us) { explicit PIT(uint32_t us) {
PIT::interval(us); PIT::interval(us);
} }
// Konfiguriertes Zeitintervall auslesen. // Konfiguriertes Zeitintervall auslesen.
int interval() const { return timer_interval; } uint32_t interval() const { return timer_interval; }
// Zeitintervall in Mikrosekunden, nachdem periodisch ein Interrupt // Zeitintervall in Mikrosekunden, nachdem periodisch ein Interrupt
//erzeugt werden soll. //erzeugt werden soll.
static void interval(int us); static void interval(uint32_t us);
// Aktivierung der Unterbrechungen fuer den Zeitgeber // Aktivierung der Unterbrechungen fuer den Zeitgeber
void plugin(); void plugin();

View File

@ -8,7 +8,7 @@ void PagingDemo::writeprotect_page() {
// BlueScreen 2 // BlueScreen 2
log.info() << "Allocating page" << endl; log.info() << "Allocating page" << endl;
unsigned int* page = pg_alloc_page(); uint32_t* page = pg_alloc_page();
*page = 42; *page = 42;
log.info() << "Writeprotecting page..." << endl; log.info() << "Writeprotecting page..." << endl;
pg_write_protect_page(page); pg_write_protect_page(page);
@ -23,7 +23,7 @@ void PagingDemo::notpresent_page() {
kout << "Produces pagefault, if you can read this it didn't work" << endl; kout << "Produces pagefault, if you can read this it didn't work" << endl;
log.info() << "Allocating page" << endl; log.info() << "Allocating page" << endl;
unsigned int* page = pg_alloc_page(); uint32_t* page = pg_alloc_page();
*page = 42; *page = 42;
log.info() << "Marking page notpresent..." << endl; log.info() << "Marking page notpresent..." << endl;

View File

@ -56,8 +56,8 @@ void break_on_bluescreen() {
} }
// Cursor-Position // Cursor-Position
int bs_xpos = 0; uint8_t bs_xpos = 0;
int bs_ypos = 0; uint8_t bs_ypos = 0;
/***************************************************************************** /*****************************************************************************
* Funktion: bs_clear * * Funktion: bs_clear *
@ -65,13 +65,13 @@ int bs_ypos = 0;
* Beschreibung: Bildschirm loeschen. * * Beschreibung: Bildschirm loeschen. *
*****************************************************************************/ *****************************************************************************/
void bs_clear() { void bs_clear() {
unsigned int x; uint8_t x;
unsigned int y; uint8_t y;
unsigned short* ptr = reinterpret_cast<unsigned short*>(0xb8000); auto* ptr = reinterpret_cast<uint16_t*>(0xb8000);
for (x = 0; x < 80; x++) { for (x = 0; x < 80; x++) {
for (y = 0; y < 25; y++) { for (y = 0; y < 25; y++) {
*(ptr + y * 80 + x) = static_cast<short>(0x1F00); *(ptr + y * 80 + x) = static_cast<uint16_t>(0x1F00);
} }
} }
@ -155,11 +155,11 @@ void bs_printReg(char* str, unsigned int value) {
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Hauptroutine des Bluescreens. * * Beschreibung: Hauptroutine des Bluescreens. *
*****************************************************************************/ *****************************************************************************/
void bs_dump(unsigned int exceptionNr) { void bs_dump(uint8_t exceptionNr) {
unsigned int* int_esp; uint32_t* int_esp;
unsigned int* sptr; uint32_t* sptr;
unsigned int faultAdress; uint32_t faultAdress;
unsigned int has_error_code = 0; uint8_t has_error_code = 0;
bs_clear(); bs_clear();
bs_print_string("HHUos crashed with Exception \0"); bs_print_string("HHUos crashed with Exception \0");
@ -210,7 +210,7 @@ void bs_dump(unsigned int exceptionNr) {
get_int_esp(&int_esp); get_int_esp(&int_esp);
// wir müssen den Inhalt auslesen und das als Zeiger verwenden, um den Stack auszulesen // wir müssen den Inhalt auslesen und das als Zeiger verwenden, um den Stack auszulesen
sptr = reinterpret_cast<unsigned int*>(*int_esp); sptr = reinterpret_cast<uint32_t*>(*int_esp);
bs_lf(); bs_lf();
@ -277,7 +277,7 @@ void bs_dump(unsigned int exceptionNr) {
bs_print_string("Calling Stack:\0"); bs_print_string("Calling Stack:\0");
bs_lf(); bs_lf();
int x = 0; int x = 0;
unsigned int* ebp = reinterpret_cast<unsigned int*>(*(sptr + 2)); auto* ebp = reinterpret_cast<uint32_t*>(*(sptr + 2));
unsigned int raddr; unsigned int raddr;
// solange eip > 1 MB && ebp < 128 MB, max. Aufruftiefe 10 // solange eip > 1 MB && ebp < 128 MB, max. Aufruftiefe 10
@ -288,7 +288,7 @@ void bs_dump(unsigned int exceptionNr) {
bs_lf(); bs_lf();
// dynamische Kette -> zum Aufrufer // dynamische Kette -> zum Aufrufer
ebp = reinterpret_cast<unsigned int*>(*ebp); ebp = reinterpret_cast<uint32_t*>(*ebp);
x++; x++;
} }

View File

@ -14,6 +14,6 @@
#define Bluescreen_include__ #define Bluescreen_include__
// dump blue screen (will not return) // dump blue screen (will not return)
void bs_dump(unsigned int exceptionNr); void bs_dump(uint8_t exceptionNr);
#endif #endif

View File

@ -15,7 +15,7 @@
#include "kernel/system/Globals.h" #include "kernel/system/Globals.h"
#include "kernel/interrupt/Bluescreen.h" #include "kernel/interrupt/Bluescreen.h"
extern "C" void int_disp(unsigned int vector); extern "C" void int_disp(uint8_t vector);
/***************************************************************************** /*****************************************************************************
* Prozedur: int_disp * * Prozedur: int_disp *
@ -29,7 +29,7 @@ extern "C" void int_disp(unsigned int vector);
* Parameter: * * Parameter: *
* vector: Vektor-Nummer der Unterbrechung * * vector: Vektor-Nummer der Unterbrechung *
*****************************************************************************/ *****************************************************************************/
void int_disp(unsigned int vector) { void int_disp(uint8_t vector) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
@ -56,7 +56,7 @@ void int_disp(unsigned int vector) {
* * * *
* Rueckgabewert: 0 = Erfolg, -1 = Fehler * * Rueckgabewert: 0 = Erfolg, -1 = Fehler *
*****************************************************************************/ *****************************************************************************/
int IntDispatcher::assign(unsigned int vector, ISR& isr) { int IntDispatcher::assign(uint8_t vector, ISR& isr) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */
@ -81,7 +81,7 @@ int IntDispatcher::assign(unsigned int vector, ISR& isr) {
* * * *
* Rueckgabewert: 0 = ISR wurde aufgerufen, -1 = unbekannte Vektor-Nummer * * Rueckgabewert: 0 = ISR wurde aufgerufen, -1 = unbekannte Vektor-Nummer *
*****************************************************************************/ *****************************************************************************/
int IntDispatcher::report(unsigned int vector) { int IntDispatcher::report(uint8_t vector) {
/* hier muss Code eingefuegt werden */ /* hier muss Code eingefuegt werden */

View File

@ -42,10 +42,10 @@ public:
} }
// Registrierung einer ISR. (Rueckgabewert: 0 = Erfolg, -1 = Fehler) // Registrierung einer ISR. (Rueckgabewert: 0 = Erfolg, -1 = Fehler)
int assign(unsigned int vector, ISR& isr); int assign(uint8_t vector, ISR& isr);
// ISR fuer 'vector' ausfuehren // ISR fuer 'vector' ausfuehren
int report(unsigned int vector); int report(uint8_t vector);
}; };
#endif #endif

View File

@ -19,7 +19,8 @@ void Logger::log(const bse::string_view message, CGA::color col) const {
if (Logger::kout_enabled) { if (Logger::kout_enabled) {
CGA::color old_col = kout.color_fg; CGA::color old_col = kout.color_fg;
kout << fgc(col) kout << fgc(col)
<< Logger::level_to_string(current_message_level) << "::" << "["
<< Logger::level_to_string(current_message_level) << "] "
<< message << fgc(old_col); << message << fgc(old_col);
kout.flush(); // Don't add newline, Logger already does that kout.flush(); // Don't add newline, Logger already does that
} }
@ -40,8 +41,9 @@ void Logger::log(const bse::string_view message, CGA::color col) const {
default: default:
SerialOut::write(ansi_default); SerialOut::write(ansi_default);
} }
SerialOut::write("[");
SerialOut::write(Logger::level_to_string(current_message_level)); SerialOut::write(Logger::level_to_string(current_message_level));
SerialOut::write(":: "); SerialOut::write("] ");
SerialOut::write(message); SerialOut::write(message);
SerialOut::write('\r'); SerialOut::write('\r');
// serial.write("\r\n"); // serial.write("\r\n");

View File

@ -8,6 +8,8 @@
#include "lib/util/StringView.h" #include "lib/util/StringView.h"
class Logger : public OutStream { class Logger : public OutStream {
friend class NamedLogger; // Allow NamedLogger to lock/unlock
public: public:
static Logger& instance() { static Logger& instance() {
static Logger log; static Logger log;
@ -20,9 +22,7 @@ private:
static bool kout_enabled; static bool kout_enabled;
static bool serial_enabled; static bool serial_enabled;
void log(const bse::string_view message, CGA::color col) const; void log(bse::string_view message, CGA::color col) const;
friend class NamedLogger; // Allow NamedLogger to lock/unlock
SpinLock sem; // Semaphore would be a cyclic include SpinLock sem; // Semaphore would be a cyclic include
static void lock() { Logger::instance().sem.acquire(); } static void lock() { Logger::instance().sem.acquire(); }
@ -47,10 +47,10 @@ public:
void flush() override; void flush() override;
void trace(const bse::string_view message) const; void trace(bse::string_view message) const;
void debug(const bse::string_view message) const; void debug(bse::string_view message) const;
void error(const bse::string_view message) const; void error(bse::string_view message) const;
void info(const bse::string_view message) const; void info(bse::string_view message) const;
// TODO: Make lvl change accessible over menu // TODO: Make lvl change accessible over menu
static void set_level(LogLevel lvl) { static void set_level(LogLevel lvl) {
@ -60,13 +60,13 @@ public:
static bse::string_view level_to_string(LogLevel lvl) { static bse::string_view level_to_string(LogLevel lvl) {
switch (lvl) { switch (lvl) {
case Logger::TRACE: case Logger::TRACE:
return "TRACE"; return "TRC";
case Logger::DEBUG: case Logger::DEBUG:
return "DEBUG"; return "DBG";
case Logger::ERROR: case Logger::ERROR:
return "ERROR"; return "ERR";
case Logger::INFO: case Logger::INFO:
return "INFO"; return "INF";
} }
} }
@ -99,22 +99,22 @@ public:
Logger& trace() { Logger& trace() {
Logger::lock(); Logger::lock();
return Logger::instance() << TRACE << name << "::"; return Logger::instance() << TRACE << name << " :: ";
} }
Logger& debug() { Logger& debug() {
Logger::lock(); Logger::lock();
return Logger::instance() << DEBUG << name << "::"; return Logger::instance() << DEBUG << name << " :: ";
} }
Logger& error() { Logger& error() {
Logger::lock(); Logger::lock();
return Logger::instance() << ERROR << name << "::"; return Logger::instance() << ERROR << name << " :: ";
} }
Logger& info() { Logger& info() {
Logger::lock(); Logger::lock();
return Logger::instance() << INFO << name << "::"; return Logger::instance() << INFO << name << " :: ";
} }
}; };

View File

@ -74,20 +74,20 @@ constexpr const unsigned int LST_ALLOCABLE_PAGE = 0x2FF000;
* Beschreibung: Alloziert eine 4 KB Seite. Allozieren heisst hier * * Beschreibung: Alloziert eine 4 KB Seite. Allozieren heisst hier *
* lediglich Setzen eines eigenen RESERVED-Bits. * * lediglich Setzen eines eigenen RESERVED-Bits. *
*****************************************************************************/ *****************************************************************************/
unsigned int* pg_alloc_page() { uint32_t* pg_alloc_page() {
unsigned int* p_page; uint32_t* p_page;
p_page = reinterpret_cast<unsigned int*>(PAGE_TABLE); p_page = reinterpret_cast<uint32_t*>(PAGE_TABLE);
// 1. Eintrag ist fuer Null-Pointer-Exception reserviert // 1. Eintrag ist fuer Null-Pointer-Exception reserviert
// ausserdem liegt an die Page-Table an Adresse PAGE_TABLE // ausserdem liegt die Page-Table an Adresse PAGE_TABLE
// somit ist est PAGE_TABLE + 4 KB frei (bis max. 3 MB, da beginnt der Heap) // somit ist est PAGE_TABLE + 4 KB frei (bis max. 3 MB, da beginnt der Heap)
for (int i = 1; i < 1024; i++) { for (uint32_t i = 1; i < 1024; i++) {
p_page++; p_page++;
// pruefe ob Page frei // pruefe ob Page frei
if (((*p_page) & PAGE_RESERVED) == 0) { if (((*p_page) & PAGE_RESERVED) == 0) {
*p_page = (*p_page | PAGE_RESERVED); *p_page = (*p_page | PAGE_RESERVED);
return reinterpret_cast<unsigned int*>(i << 12); // Address without flags (Offset 0) return reinterpret_cast<uint32_t*>(i << 12); // Address without flags (Offset 0)
} }
} }
return nullptr; return nullptr;
@ -99,13 +99,13 @@ unsigned int* pg_alloc_page() {
* Beschreibung: Schreibschutz fuer die uebergebene Seite aktivieren. * * Beschreibung: Schreibschutz fuer die uebergebene Seite aktivieren. *
* Dies fuer das Debugging nuetzlich. * * Dies fuer das Debugging nuetzlich. *
*****************************************************************************/ *****************************************************************************/
void pg_write_protect_page(const unsigned int* p_page) { void pg_write_protect_page(const uint32_t* p_page) {
/* hier muss Code eingefügt werden */ /* hier muss Code eingefügt werden */
unsigned int* page = reinterpret_cast<unsigned int*>(PAGE_TABLE) + (reinterpret_cast<unsigned int>(p_page) >> 12); // Pagetable entry uint32_t* page = reinterpret_cast<uint32_t*>(PAGE_TABLE) + (reinterpret_cast<uint32_t>(p_page) >> 12); // Pagetable entry
unsigned int mask = PAGE_WRITEABLE; // fill to 32bit uint32_t mask = PAGE_WRITEABLE; // fill to 32bit
*page = *page & ~mask; // set writable to 0 *page = *page & ~mask; // set writable to 0
invalidate_tlb_entry(p_page); invalidate_tlb_entry(p_page);
@ -116,13 +116,13 @@ void pg_write_protect_page(const unsigned int* p_page) {
*---------------------------------------------------------------------------* *---------------------------------------------------------------------------*
* Beschreibung: Seite als ausgelagert markieren. Nur fuer Testzwecke. * * Beschreibung: Seite als ausgelagert markieren. Nur fuer Testzwecke. *
*****************************************************************************/ *****************************************************************************/
void pg_notpresent_page(const unsigned int* p_page) { void pg_notpresent_page(const uint32_t* p_page) {
/* hier muss Code eingefügt werden */ /* hier muss Code eingefügt werden */
unsigned int* page = reinterpret_cast<unsigned int*>(PAGE_TABLE) + (reinterpret_cast<unsigned int>(p_page) >> 12); // Pagetable entry uint32_t* page = reinterpret_cast<uint32_t*>(PAGE_TABLE) + (reinterpret_cast<uint32_t>(p_page) >> 12); // Pagetable entry
unsigned int mask = PAGE_PRESENT; uint32_t mask = PAGE_PRESENT;
*page = *page & ~mask; // set present to 0 *page = *page & ~mask; // set present to 0
invalidate_tlb_entry(p_page); invalidate_tlb_entry(p_page);
@ -134,8 +134,8 @@ void pg_notpresent_page(const unsigned int* p_page) {
* Beschreibung: Gibt eine 4 KB Seite frei. Es wird hierbei das RESERVED- * * Beschreibung: Gibt eine 4 KB Seite frei. Es wird hierbei das RESERVED- *
* Bit geloescht. * * Bit geloescht. *
*****************************************************************************/ *****************************************************************************/
void pg_free_page(unsigned int* p_page) { void pg_free_page(uint32_t* p_page) {
unsigned int idx = reinterpret_cast<unsigned int>(p_page) >> 12; uint32_t idx = reinterpret_cast<uint32_t>(p_page) >> 12;
// ausserhalb Page ? // ausserhalb Page ?
if (idx < 1 || idx > 1023) { if (idx < 1 || idx > 1023) {
@ -143,7 +143,7 @@ void pg_free_page(unsigned int* p_page) {
} }
// Eintrag einlesen und aendern (PAGE_WRITEABLE loeschen) // Eintrag einlesen und aendern (PAGE_WRITEABLE loeschen)
p_page = reinterpret_cast<unsigned int*>(PAGE_TABLE); p_page = reinterpret_cast<uint32_t*>(PAGE_TABLE);
p_page += idx; p_page += idx;
*p_page = ((idx << 12) | PAGE_WRITEABLE | PAGE_PRESENT); *p_page = ((idx << 12) | PAGE_WRITEABLE | PAGE_PRESENT);
@ -156,10 +156,10 @@ void pg_free_page(unsigned int* p_page) {
* startup.asm aktivieren. * * startup.asm aktivieren. *
*****************************************************************************/ *****************************************************************************/
void pg_init() { void pg_init() {
unsigned int i; uint32_t i;
unsigned int* p_pdir; // Zeiger auf Page-Directory uint32_t* p_pdir; // Zeiger auf Page-Directory
unsigned int* p_page; // Zeiger auf einzige Page-Table fuer 4 KB Pages uint32_t* p_page; // Zeiger auf einzige Page-Table fuer 4 KB Pages
unsigned int num_pages; // Anzahl 4 MB Pages die phys. Adressraum umfassen uint32_t num_pages; // Anzahl 4 MB Pages die phys. Adressraum umfassen
// wie viele 4 MB Seiten sollen als 'Present' angelegt werden, // wie viele 4 MB Seiten sollen als 'Present' angelegt werden,
// sodass genau der physikalische Adressraum abgedeckt ist? // sodass genau der physikalische Adressraum abgedeckt ist?
@ -174,7 +174,7 @@ void pg_init() {
// //
// Eintrag 0: Zeiger auf 4 KB Page-Table // Eintrag 0: Zeiger auf 4 KB Page-Table
p_pdir = reinterpret_cast<unsigned int*>(PAGE_DIRECTORY); p_pdir = reinterpret_cast<uint32_t*>(PAGE_DIRECTORY);
*p_pdir = PAGE_TABLE | PAGE_WRITEABLE | PAGE_PRESENT; *p_pdir = PAGE_TABLE | PAGE_WRITEABLE | PAGE_PRESENT;
// Eintraege 1-1023: Direktes Mapping (1:1) auf 4 MB Pages (ohne Page-Table) // Eintraege 1-1023: Direktes Mapping (1:1) auf 4 MB Pages (ohne Page-Table)
@ -190,7 +190,7 @@ void pg_init() {
// //
// 1. Page-Table // 1. Page-Table
// //
p_page = reinterpret_cast<unsigned int*>(PAGE_TABLE); p_page = reinterpret_cast<uint32_t*>(PAGE_TABLE);
// ersten Eintrag loeschen -> not present, write protected -> Null-Pointer abfangen // ersten Eintrag loeschen -> not present, write protected -> Null-Pointer abfangen
*p_page = 0; *p_page = 0;
@ -209,5 +209,5 @@ void pg_init() {
} }
// Paging aktivieren (in startup.asm) // Paging aktivieren (in startup.asm)
paging_on(reinterpret_cast<unsigned int*>(PAGE_DIRECTORY)); paging_on(reinterpret_cast<uint32_t*>(PAGE_DIRECTORY));
} }

View File

@ -53,24 +53,26 @@
#define Paging_include__ #define Paging_include__
// Externe Funktionen in startup.asm // Externe Funktionen in startup.asm
#include <cstdint>
extern "C" { extern "C" {
void paging_on(unsigned int* p_pdir); // Paging einschalten void paging_on(uint32_t* p_pdir); // Paging einschalten
void invalidate_tlb_entry(const unsigned int* ptr); // Page in TLB invalid. void invalidate_tlb_entry(const uint32_t* ptr); // Page in TLB invalid.
} }
// ativiert paging // ativiert paging
extern void pg_init(); extern void pg_init();
// alloziert eine 4 KB Page // alloziert eine 4 KB Page
extern unsigned int* pg_alloc_page(); extern uint32_t* pg_alloc_page();
// Schreibschutz auf Seite setzen -> fuer debugging nuetzlich // Schreibschutz auf Seite setzen -> fuer debugging nuetzlich
extern void pg_write_protect_page(const unsigned int* p_page); extern void pg_write_protect_page(const uint32_t* p_page);
// Present Bit loeschen // Present Bit loeschen
extern void pg_notpresent_page(const unsigned int* p_page); extern void pg_notpresent_page(const uint32_t* p_page);
// gibt eine 4 KB Page frei // gibt eine 4 KB Page frei
extern void pg_free_page(unsigned int* p_page); extern void pg_free_page(uint32_t* p_page);
#endif #endif

View File

@ -26,11 +26,11 @@
// extern "C" deklariert werden, da sie nicht dem Name-Mangeling von C++ // extern "C" deklariert werden, da sie nicht dem Name-Mangeling von C++
// entsprechen. // entsprechen.
extern "C" { extern "C" {
void Thread_start(unsigned int esp); void Thread_start(uint32_t esp);
// NOTE: Only when backing up the previous thread the esp gets updated, // NOTE: Only when backing up the previous thread the esp gets updated,
// so only esp_pre is a pointer // so only esp_pre is a pointer
void Thread_switch(unsigned int* esp_prev, unsigned int esp_next); void Thread_switch(uint32_t* esp_prev, uint32_t esp_next);
} }
unsigned int ThreadCnt = 1; // Skip tid 0 as the scheduler indicates no preemption with 0 unsigned int ThreadCnt = 1; // Skip tid 0 as the scheduler indicates no preemption with 0
@ -41,7 +41,7 @@ unsigned int ThreadCnt = 1; // Skip tid 0 as the scheduler indicates no preempt
* Beschreibung: Bereitet den Kontext der Koroutine fuer den ersten * * Beschreibung: Bereitet den Kontext der Koroutine fuer den ersten *
* Aufruf vor. * * Aufruf vor. *
*****************************************************************************/ *****************************************************************************/
void Thread_init(unsigned int* esp, unsigned int* stack, void (*kickoff)(Thread*), void* object) { void Thread_init(uint32_t* esp, uint32_t* stack, void (*kickoff)(Thread*), void* object) {
// NOTE: c++17 doesn't allow register // NOTE: c++17 doesn't allow register
// register unsigned int** sp = (unsigned int**)stack; // register unsigned int** sp = (unsigned int**)stack;

View File

@ -32,8 +32,8 @@
class Thread { class Thread {
private: private:
unsigned int* stack; uint32_t* stack;
unsigned int esp; uint32_t esp;
protected: protected:
Thread(char* name); Thread(char* name);

View File

@ -73,14 +73,21 @@ int main() {
scheduler.schedule(); scheduler.schedule();
// NOTE: Pre-Post ToDo's // NOTE: Pre-Post ToDo's
// TODO: Reorganize the project similar to hhuOS: // DONE: Reorganize the project similar to hhuOS:
// - TODO: Use CMake // - DONE: Use CMake
// - TODO: Copy file structure: build, cmake, src // - DONE: Copy file structure: build, cmake, src
// - TODO: Translate the src/Makefile and boot/Makefile // - DONE: Translate the src/Makefile and boot/Makefile
// TODO: Update some parts to C++20 (I wanted to use reference optionals somewhere...) // TODO: Switch char/short/int/long to uint_ sized types where appropriate
// TODO: Namespace that shit // TODO: Namespace that shit
// TODO: Investigate: C++20 (I wanted to use reference optionals somewhere...)
// TODO: Compare current (hhuOS) compiler flags with old BSEos compiler flags
// TODO: Change int types to cstdint
// TODO: Rearrange code inside classes (public structs, public functions, private structs, private functions, private variables)
// TODO: Write documentation comments
// NOTE: Post ToDo's // NOTE: Post ToDo's
// TODO: Singleton class wrapper
// TODO: Optional type for addresses
// TODO: Generalize key event system to eventbus (where custom events can be registered) // TODO: Generalize key event system to eventbus (where custom events can be registered)
// TODO: Introduce kernel services and abstract time, memory, scheduler, interrupt etc. (like in hhuOS) // TODO: Introduce kernel services and abstract time, memory, scheduler, interrupt etc. (like in hhuOS)
// TODO: Use linear framebuffer to draw output/shell/text instead of CGA // TODO: Use linear framebuffer to draw output/shell/text instead of CGA
@ -88,9 +95,11 @@ int main() {
// TODO: Manage exited threads in scheduler // TODO: Manage exited threads in scheduler
// TODO: Query thread state in scheduler // TODO: Query thread state in scheduler
// TODO: Bitfield lib class that has defined behavior regarding ordering/packing (for easy register access)? // TODO: Bitfield lib class that has defined behavior regarding ordering/packing (for easy register access)?
// TODO: Port my APIC code from hhuOS
// TODO: Exceptions
// NOTE: Large post ToDo's // NOTE: Large post ToDo's
// TODO: Add a RB-Tree datastructure and use it for memory management // TODO: Add a RB-Tree datastructure and use it for memory management?
// TODO: Enable full paging (check hhuOS for implementation example) // TODO: Enable full paging (check hhuOS for implementation example)
// NOTE: Filesystem enable ToDo's (huge) // NOTE: Filesystem enable ToDo's (huge)
@ -103,7 +112,7 @@ int main() {
// NOTE: Insane ToDo's // NOTE: Insane ToDo's
// TODO: Write a very simple text editor that can save files to the filesystem // TODO: Write a very simple text editor that can save files to the filesystem
// TODO: Small compiler to write small programs inside the system (I don't want to deal with register allocation so compile to bytecode and use a VM?) // TODO: Small interpreter to run source code on the system
// NOTE: Enforced ToDo's (needed) // NOTE: Enforced ToDo's (needed)
// DONE: Rewrite demos for threads // DONE: Rewrite demos for threads