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 "lib/mem/Memory.h"
#include <cstdint>
const IOport CGA::index_port(0x3d4);
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. *
*****************************************************************************/
void CGA::setpos(unsigned int x, unsigned int y) {
void CGA::setpos(uint8_t x, uint8_t y) {
/* Hier muess Code eingefuegt werden */
@ -49,7 +50,7 @@ void CGA::setpos(unsigned int x, unsigned int 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 */
@ -77,7 +78,7 @@ void CGA::getpos(unsigned int& x, unsigned int& y) {
* character Das auszugebende 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 */
@ -106,8 +107,8 @@ void CGA::print(const bse::string_view string, unsigned char attrib) const {
/* Hier muess Code eingefuegt werden */
unsigned int cursor_x = 0;
unsigned int cursor_y = 0; // Don't poll registers every stroke
uint8_t cursor_x = 0;
uint8_t cursor_y = 0; // Don't poll registers every stroke
getpos(cursor_x, cursor_y);
for (char current : string) {

View File

@ -14,6 +14,7 @@
#ifndef CGA_include_H_
#define CGA_include_H_
#include <cstdint>
#include "device/port/IOport.h"
#include "lib/util/Array.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]
// 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
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
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
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.
// Neue Zeile am unteren Bildrand mit Leerzeichen fuellen

View File

@ -4,9 +4,11 @@
/* */
/* 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] = {

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] = {

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] = {

View File

@ -1,6 +1,6 @@
// 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] = {

View File

@ -1,6 +1,6 @@
// 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] = {
/* */ 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__
#define FONTS_H__
#include <cstdint>
#include "lib/util/Array.h"
class Font {
public:
virtual ~Font() = default;
virtual const unsigned char* getChar(int c) const = 0;
virtual unsigned int get_char_width() const = 0;
virtual unsigned int get_char_height() const = 0;
virtual const unsigned char* getChar(uint32_t c) const = 0;
virtual uint32_t get_char_width() 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 {
const unsigned int char_width;
const unsigned int char_height;
const unsigned int char_mem_size;
const unsigned char* font_data;
const uint32_t char_width;
const uint32_t char_height;
const uint32_t char_mem_size;
const uint8_t* font_data;
public:
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];
}
inline unsigned int get_char_width() const override {
inline uint32_t get_char_width() const override {
return char_width;
}
inline unsigned int get_char_height() const override {
inline uint32_t get_char_height() const override {
return char_height;
}
};

View File

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

View File

@ -18,7 +18,7 @@
#include "Fonts.h"
// 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);
}
@ -28,23 +28,23 @@ constexpr const bool BUFFER_VISIBLE = true;
class LFBgraphics {
private:
// Hilfsfunktion fuer drawString
void drawMonoBitmap(unsigned int x, unsigned int y,
unsigned int width, unsigned int height,
const unsigned char* bitmap, unsigned int col) const;
void drawMonoBitmap(uint32_t x, uint32_t y,
uint32_t width, uint32_t height,
const unsigned char* bitmap, uint32_t col) const;
public:
LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren
LFBgraphics() : mode(BUFFER_VISIBLE) {};
unsigned int xres, yres; // Aufloesung in Pixel
unsigned int bpp; // Farbtiefe (Bits per Pixel)
unsigned int lfb; // Adresse des Linearen Framebuffers
unsigned int hfb; // Adresse des versteckten Buffers (optional, fuer Animationen)
unsigned int mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer
uint32_t xres, yres; // Aufloesung in Pixel
uint8_t bpp; // Farbtiefe (Bits per Pixel)
uint32_t lfb; // Adresse des Linearen Framebuffers
uint32_t hfb; // Adresse des versteckten Buffers (optional, fuer Animationen)
uint8_t mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer
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;

View File

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

View File

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

View File

@ -284,7 +284,7 @@ Key Keyboard::key_hit() {
* Beschreibung: Fuehrt einen Neustart des Rechners durch. *
*****************************************************************************/
void Keyboard::reboot() {
int status;
uint8_t status;
// Dem BIOS mitteilen, dass das Reset beabsichtigt war
// und kein Speichertest durchgefuehrt werden muss.
@ -310,7 +310,7 @@ void Keyboard::reboot() {
* sollen. Erlaubt sind Werte zwischen 0 (sehr schnell) *
* 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. */
}

View File

@ -11,6 +11,7 @@
#ifndef Keyboard_include__
#define Keyboard_include__
#include <cstdint>
#include "Key.h"
#include "kernel/interrupt/ISR.h"
#include "device/port/IOport.h"
@ -85,7 +86,7 @@ public:
static void reboot();
// 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.
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: *
* irq: IRQ der erlaubt werden soll *
*****************************************************************************/
void PIC::allow(int irq) {
void PIC::allow(uint8_t irq) {
/* hier muss Code eingefuegt werden */
// NOTE: allow sets the bit to 0
unsigned char IMR;
unsigned char mask = ~(0x1 << (irq % 8));
uint8_t IMR;
uint8_t mask = ~(0x1 << (irq % 8));
if (irq < 8) {
// PIC 1
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: *
* interrupt: IRQ der maskiert werden soll *
*****************************************************************************/
void PIC::forbid(int irq) {
void PIC::forbid(uint8_t irq) {
/* hier muss Code eingefuegt werden */
// NOTE: forbid sets the bit to 1
unsigned char IMR;
unsigned char mask = 0x1 << (irq % 8);
uint8_t IMR;
uint8_t mask = 0x1 << (irq % 8);
if (irq < 8) {
// PIC 1
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: *
* irq: IRQ dessen Status erfragt werden soll *
*****************************************************************************/
bool PIC::status(int irq) {
bool PIC::status(uint8_t irq) {
/* hier muss Code eingefuegt werden */
unsigned char IMR;
uint8_t IMR;
if (irq < 8) {
// PIC 1
IMR = IMR1.inb();
@ -100,6 +100,6 @@ bool PIC::status(int irq) {
}
// Use % 8 to account for two PICs
unsigned char mask = 0x1 << (irq % 8);
uint8_t mask = 0x1 << (irq % 8);
return IMR & mask;
}

View File

@ -17,6 +17,7 @@
#ifndef PIC_include__
#define PIC_include__
#include <cstdint>
#include "device/port/IOport.h"
class PIC {
@ -39,13 +40,13 @@ public:
};
// 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
static void forbid(int irq);
static void forbid(uint8_t irq);
// Abfragen, ob die Weiterleitung fuer einen bestimmten IRQ unterdrueckt ist
static bool status(int interrupt_device);
static bool status(uint8_t interrupt_device);
};
#endif

View File

@ -27,10 +27,10 @@ const IOport PCSPK::ppi(0x61);
* Rückgabewerte: f: Frequenz des Tons *
* len: Laenge des Tons in ms *
*****************************************************************************/
void PCSPK::play(float f, int len) {
int freq = static_cast<int>(f);
int cntStart = 1193180 / freq;
int status;
void PCSPK::play(float f, uint32_t len) {
auto freq = static_cast<uint32_t>(f);
uint32_t cntStart = 1193180 / freq;
uint8_t status;
// Zaehler laden
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)
// 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
// Pause
@ -54,9 +54,9 @@ void PCSPK::play(float f, int len) {
* Beschreibung: Lautsprecher ausschalten. *
*****************************************************************************/
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
}
@ -67,7 +67,7 @@ void PCSPK::off() {
* *
* Parameter: time (delay in ms) *
*****************************************************************************/
inline void PCSPK::delay(int time) {
inline void PCSPK::delay(uint32_t time) {
/* Hier muess Code eingefuegt werden */

View File

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

View File

@ -23,13 +23,13 @@ const IOport PIT::data0(0x40);
* us: Zeitintervall in Mikrosekunden, nachdem periodisch ein *
* Interrupt erzeugt werden soll. *
*****************************************************************************/
void PIT::interval(int us) {
void PIT::interval(uint32_t us) {
/* hier muss Code eingefuegt werden */
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 >> 8); // Zaehler-0 laden (Hibyte)

View File

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

View File

@ -8,7 +8,7 @@ void PagingDemo::writeprotect_page() {
// BlueScreen 2
log.info() << "Allocating page" << endl;
unsigned int* page = pg_alloc_page();
uint32_t* page = pg_alloc_page();
*page = 42;
log.info() << "Writeprotecting page..." << endl;
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;
log.info() << "Allocating page" << endl;
unsigned int* page = pg_alloc_page();
uint32_t* page = pg_alloc_page();
*page = 42;
log.info() << "Marking page notpresent..." << endl;

View File

@ -56,8 +56,8 @@ void break_on_bluescreen() {
}
// Cursor-Position
int bs_xpos = 0;
int bs_ypos = 0;
uint8_t bs_xpos = 0;
uint8_t bs_ypos = 0;
/*****************************************************************************
* Funktion: bs_clear *
@ -65,13 +65,13 @@ int bs_ypos = 0;
* Beschreibung: Bildschirm loeschen. *
*****************************************************************************/
void bs_clear() {
unsigned int x;
unsigned int y;
unsigned short* ptr = reinterpret_cast<unsigned short*>(0xb8000);
uint8_t x;
uint8_t y;
auto* ptr = reinterpret_cast<uint16_t*>(0xb8000);
for (x = 0; x < 80; x++) {
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. *
*****************************************************************************/
void bs_dump(unsigned int exceptionNr) {
unsigned int* int_esp;
unsigned int* sptr;
unsigned int faultAdress;
unsigned int has_error_code = 0;
void bs_dump(uint8_t exceptionNr) {
uint32_t* int_esp;
uint32_t* sptr;
uint32_t faultAdress;
uint8_t has_error_code = 0;
bs_clear();
bs_print_string("HHUos crashed with Exception \0");
@ -210,7 +210,7 @@ void bs_dump(unsigned int exceptionNr) {
get_int_esp(&int_esp);
// 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();
@ -277,7 +277,7 @@ void bs_dump(unsigned int exceptionNr) {
bs_print_string("Calling Stack:\0");
bs_lf();
int x = 0;
unsigned int* ebp = reinterpret_cast<unsigned int*>(*(sptr + 2));
auto* ebp = reinterpret_cast<uint32_t*>(*(sptr + 2));
unsigned int raddr;
// solange eip > 1 MB && ebp < 128 MB, max. Aufruftiefe 10
@ -288,7 +288,7 @@ void bs_dump(unsigned int exceptionNr) {
bs_lf();
// dynamische Kette -> zum Aufrufer
ebp = reinterpret_cast<unsigned int*>(*ebp);
ebp = reinterpret_cast<uint32_t*>(*ebp);
x++;
}

View File

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

View File

@ -15,7 +15,7 @@
#include "kernel/system/Globals.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 *
@ -29,7 +29,7 @@ extern "C" void int_disp(unsigned int vector);
* Parameter: *
* vector: Vektor-Nummer der Unterbrechung *
*****************************************************************************/
void int_disp(unsigned int vector) {
void int_disp(uint8_t vector) {
/* hier muss Code eingefuegt werden */
@ -56,7 +56,7 @@ void int_disp(unsigned int vector) {
* *
* 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 */
@ -81,7 +81,7 @@ int IntDispatcher::assign(unsigned int vector, ISR& isr) {
* *
* 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 */

View File

@ -42,10 +42,10 @@ public:
}
// 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
int report(unsigned int vector);
int report(uint8_t vector);
};
#endif

View File

@ -19,7 +19,8 @@ void Logger::log(const bse::string_view message, CGA::color col) const {
if (Logger::kout_enabled) {
CGA::color old_col = kout.color_fg;
kout << fgc(col)
<< Logger::level_to_string(current_message_level) << "::"
<< "["
<< Logger::level_to_string(current_message_level) << "] "
<< message << fgc(old_col);
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:
SerialOut::write(ansi_default);
}
SerialOut::write("[");
SerialOut::write(Logger::level_to_string(current_message_level));
SerialOut::write(":: ");
SerialOut::write("] ");
SerialOut::write(message);
SerialOut::write('\r');
// serial.write("\r\n");

View File

@ -8,6 +8,8 @@
#include "lib/util/StringView.h"
class Logger : public OutStream {
friend class NamedLogger; // Allow NamedLogger to lock/unlock
public:
static Logger& instance() {
static Logger log;
@ -20,9 +22,7 @@ private:
static bool kout_enabled;
static bool serial_enabled;
void log(const bse::string_view message, CGA::color col) const;
friend class NamedLogger; // Allow NamedLogger to lock/unlock
void log(bse::string_view message, CGA::color col) const;
SpinLock sem; // Semaphore would be a cyclic include
static void lock() { Logger::instance().sem.acquire(); }
@ -47,10 +47,10 @@ public:
void flush() override;
void trace(const bse::string_view message) const;
void debug(const bse::string_view message) const;
void error(const bse::string_view message) const;
void info(const bse::string_view message) const;
void trace(bse::string_view message) const;
void debug(bse::string_view message) const;
void error(bse::string_view message) const;
void info(bse::string_view message) const;
// TODO: Make lvl change accessible over menu
static void set_level(LogLevel lvl) {
@ -60,13 +60,13 @@ public:
static bse::string_view level_to_string(LogLevel lvl) {
switch (lvl) {
case Logger::TRACE:
return "TRACE";
return "TRC";
case Logger::DEBUG:
return "DEBUG";
return "DBG";
case Logger::ERROR:
return "ERROR";
return "ERR";
case Logger::INFO:
return "INFO";
return "INF";
}
}
@ -99,22 +99,22 @@ public:
Logger& trace() {
Logger::lock();
return Logger::instance() << TRACE << name << "::";
return Logger::instance() << TRACE << name << " :: ";
}
Logger& debug() {
Logger::lock();
return Logger::instance() << DEBUG << name << "::";
return Logger::instance() << DEBUG << name << " :: ";
}
Logger& error() {
Logger::lock();
return Logger::instance() << ERROR << name << "::";
return Logger::instance() << ERROR << name << " :: ";
}
Logger& info() {
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 *
* lediglich Setzen eines eigenen RESERVED-Bits. *
*****************************************************************************/
unsigned int* pg_alloc_page() {
unsigned int* p_page;
uint32_t* pg_alloc_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
// 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)
for (int i = 1; i < 1024; i++) {
for (uint32_t i = 1; i < 1024; i++) {
p_page++;
// pruefe ob Page frei
if (((*p_page) & PAGE_RESERVED) == 0) {
*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;
@ -99,13 +99,13 @@ unsigned int* pg_alloc_page() {
* Beschreibung: Schreibschutz fuer die uebergebene Seite aktivieren. *
* 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 */
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
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. *
*****************************************************************************/
void pg_notpresent_page(const unsigned int* p_page) {
void pg_notpresent_page(const uint32_t* p_page) {
/* 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
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- *
* Bit geloescht. *
*****************************************************************************/
void pg_free_page(unsigned int* p_page) {
unsigned int idx = reinterpret_cast<unsigned int>(p_page) >> 12;
void pg_free_page(uint32_t* p_page) {
uint32_t idx = reinterpret_cast<uint32_t>(p_page) >> 12;
// ausserhalb Page ?
if (idx < 1 || idx > 1023) {
@ -143,7 +143,7 @@ void pg_free_page(unsigned int* p_page) {
}
// 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 << 12) | PAGE_WRITEABLE | PAGE_PRESENT);
@ -156,10 +156,10 @@ void pg_free_page(unsigned int* p_page) {
* startup.asm aktivieren. *
*****************************************************************************/
void pg_init() {
unsigned int i;
unsigned int* p_pdir; // Zeiger auf Page-Directory
unsigned int* 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 i;
uint32_t* p_pdir; // Zeiger auf Page-Directory
uint32_t* p_page; // Zeiger auf einzige Page-Table fuer 4 KB Pages
uint32_t num_pages; // Anzahl 4 MB Pages die phys. Adressraum umfassen
// wie viele 4 MB Seiten sollen als 'Present' angelegt werden,
// sodass genau der physikalische Adressraum abgedeckt ist?
@ -174,7 +174,7 @@ void pg_init() {
//
// 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;
// Eintraege 1-1023: Direktes Mapping (1:1) auf 4 MB Pages (ohne Page-Table)
@ -190,7 +190,7 @@ void pg_init() {
//
// 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
*p_page = 0;
@ -209,5 +209,5 @@ void pg_init() {
}
// 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__
// Externe Funktionen in startup.asm
#include <cstdint>
extern "C" {
void paging_on(unsigned int* p_pdir); // Paging einschalten
void invalidate_tlb_entry(const unsigned int* ptr); // Page in TLB invalid.
void paging_on(uint32_t* p_pdir); // Paging einschalten
void invalidate_tlb_entry(const uint32_t* ptr); // Page in TLB invalid.
}
// ativiert paging
extern void pg_init();
// alloziert eine 4 KB Page
extern unsigned int* pg_alloc_page();
extern uint32_t* pg_alloc_page();
// 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
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
extern void pg_free_page(unsigned int* p_page);
extern void pg_free_page(uint32_t* p_page);
#endif

View File

@ -26,11 +26,11 @@
// extern "C" deklariert werden, da sie nicht dem Name-Mangeling von C++
// entsprechen.
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,
// 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
@ -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 *
* 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
// register unsigned int** sp = (unsigned int**)stack;

View File

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

View File

@ -73,14 +73,21 @@ int main() {
scheduler.schedule();
// NOTE: Pre-Post ToDo's
// TODO: Reorganize the project similar to hhuOS:
// - TODO: Use CMake
// - TODO: Copy file structure: build, cmake, src
// - TODO: Translate the src/Makefile and boot/Makefile
// TODO: Update some parts to C++20 (I wanted to use reference optionals somewhere...)
// DONE: Reorganize the project similar to hhuOS:
// - DONE: Use CMake
// - DONE: Copy file structure: build, cmake, src
// - DONE: Translate the src/Makefile and boot/Makefile
// TODO: Switch char/short/int/long to uint_ sized types where appropriate
// 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
// TODO: Singleton class wrapper
// TODO: Optional type for addresses
// 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: Use linear framebuffer to draw output/shell/text instead of CGA
@ -88,9 +95,11 @@ int main() {
// TODO: Manage exited threads in scheduler
// TODO: Query thread state in scheduler
// 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
// 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)
// NOTE: Filesystem enable ToDo's (huge)
@ -103,7 +112,7 @@ int main() {
// NOTE: Insane ToDo's
// 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)
// DONE: Rewrite demos for threads