1

Switch more char/short/int/long to sized type

This commit is contained in:
2022-12-07 18:39:13 +01:00
parent ae98dc586e
commit c87e691588
40 changed files with 213 additions and 206 deletions

View File

@ -33,7 +33,7 @@ BIOScall_params* BC_params = reinterpret_cast<BIOScall_params*>(BIOS16_PARAM_BAS
* im 4. GDT-Eintrag (siehe startup.asm). *
*****************************************************************************/
BIOS::BIOS() {
unsigned char* codeAddr = reinterpret_cast<unsigned char*>(BIOS16_CODE_MEMORY_START);
auto* codeAddr = reinterpret_cast<uint8_t*>(BIOS16_CODE_MEMORY_START);
// mov eax, 25000 (Adresse wohin aktuelles esp gesichert wird)
*codeAddr = 0x66;
@ -312,11 +312,11 @@ BIOS::BIOS() {
*---------------------------------------------------------------------------*
* Beschreibung: Fuehrt einen BIOS-Aufruf per Software-Interrupt durch. *
*****************************************************************************/
void BIOS::Int(int inter) {
unsigned char* ptr = reinterpret_cast<unsigned char*>(BIOS16_CODE_MEMORY_START);
void BIOS::Int(uint8_t inter) {
auto* ptr = reinterpret_cast<uint8_t*>(BIOS16_CODE_MEMORY_START);
// Interrupt-Nummer in 16-Bit Code-Segment schreiben (unschoen, aber ...)
*(ptr + 48) = static_cast<unsigned char>(inter);
*(ptr + 48) = static_cast<uint8_t>(inter);
CPU::disable_int(); // Interrupts abschalten
bios_call();

View File

@ -10,23 +10,25 @@
#ifndef BIOS_include__
#define BIOS_include__
#include <cstdint>
// Speicherseite fuer Rueckgabewerte von BIOS-Aufrufen
constexpr const unsigned int RETURN_MEM = 0x9F000;
// Struktur fuer Parameteruebergabe fuer einen BIOS-Aufruf
struct BIOScall_params {
unsigned short DS;
unsigned short ES;
unsigned short FS;
unsigned short Flags;
unsigned int DI;
unsigned int SI;
unsigned int BP;
unsigned int SP;
unsigned int BX;
unsigned int DX;
unsigned int CX;
unsigned int AX;
uint16_t DS;
uint16_t ES;
uint16_t FS;
uint16_t Flags;
uint32_t DI;
uint32_t SI;
uint32_t BP;
uint32_t SP;
uint32_t BX;
uint32_t DX;
uint32_t CX;
uint32_t AX;
} __attribute__((packed));
// kein Auffuellen von bytes auf Wortgrenzen
@ -47,7 +49,7 @@ public:
}
// BIOS-Aufruf, per Software-Interrupt
static void Int(int inter);
static void Int(uint8_t inter);
};
#endif

View File

@ -32,9 +32,9 @@ void CGA::setpos(uint8_t x, uint8_t y) {
/* Hier muess Code eingefuegt werden */
// NOTE: The cursor addresses positions on screen, not bytes
unsigned short pos = x + y * COLUMNS;
unsigned char cursor_low = pos & 0xFF;
unsigned char cursor_high = (pos >> 8) & 0xFF;
uint16_t pos = x + y * COLUMNS;
uint8_t cursor_low = pos & 0xFF;
uint8_t cursor_high = (pos >> 8) & 0xFF;
index_port.outb(0xF); // Cursor(low)
data_port.outb(cursor_low);
@ -55,13 +55,12 @@ void CGA::getpos(uint8_t& x, uint8_t& y) {
/* Hier muess Code eingefuegt werden */
index_port.outb(0xF); // Cursor(low)
unsigned char cursor_low = data_port.inb();
uint8_t cursor_low = data_port.inb();
index_port.outb(0xE); // Cursor(high)
unsigned char cursor_high = data_port.inb();
uint8_t cursor_high = data_port.inb();
unsigned short cursor =
(cursor_low & 0xFF) | ((cursor_high << 8) & 0xFF00);
uint16_t cursor = (cursor_low & 0xFF) | ((cursor_high << 8) & 0xFF00);
x = cursor % COLUMNS;
y = (cursor / COLUMNS);
@ -103,7 +102,7 @@ void CGA::show(uint8_t x, uint8_t y, char character, uint8_t attrib) {
* n Laenger der Zeichenkette *
* attrib Attributbyte fuer alle Zeichen der Zeichenkette *
*****************************************************************************/
void CGA::print(const bse::string_view string, unsigned char attrib) const {
void CGA::print(const bse::string_view string, uint8_t attrib) const {
/* Hier muess Code eingefuegt werden */
@ -192,7 +191,7 @@ void CGA::clear() {
* fg Foreground color *
* blink ywa/no *
*****************************************************************************/
unsigned char CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
uint8_t CGA::attribute(CGA::color bg, CGA::color fg, bool blink) {
/* Hier muess Code eingefuegt werden */

View File

@ -67,7 +67,7 @@ public:
// Easier access to memory (also easier copying of lines/pages etc)
struct cga_char_t {
char cga_char;
unsigned char cga_attribute;
uint8_t cga_attribute;
};
struct cga_line_t {
@ -103,7 +103,7 @@ public:
virtual void clear();
// Hilfsfunktion zur Erzeugung eines Attribut-Bytes
static unsigned char attribute(CGA::color bg, CGA::color fg, bool blink);
static uint8_t attribute(CGA::color bg, CGA::color fg, bool blink);
};
#endif

View File

@ -10,7 +10,7 @@
constexpr const uint32_t FONTDATAMAX_8x16 = 4096;
constexpr const unsigned char fontdata_8x16[FONTDATAMAX_8x16] = {
constexpr const uint8_t fontdata_8x16[FONTDATAMAX_8x16] = {
/* 0 0x00 '^@' */
0x00, /* 00000000 */

View File

@ -8,7 +8,7 @@
constexpr const uint32_t FONTDATAMAX_8x8 = 2048;
constexpr const unsigned char fontdata_8x8[FONTDATAMAX_8x8] = {
constexpr const uint8_t fontdata_8x8[FONTDATAMAX_8x8] = {
/* 0 0x00 '^@' */
0x00, /* 00000000 */

View File

@ -2,7 +2,7 @@
/* Acorn-like font definition, with PC graphics characters */
constexpr const unsigned char acorndata_8x8[] = {
constexpr const uint8_t acorndata_8x8[] = {
/* 00 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ^@ */
/* 01 */ 0x7e, 0x81, 0xa5, 0x81, 0xbd, 0x99, 0x81, 0x7e, /* ^A */
/* 02 */ 0x7e, 0xff, 0xbd, 0xff, 0xc3, 0xe7, 0xff, 0x7e, /* ^B */

View File

@ -13,7 +13,7 @@
constexpr const uint32_t FONTDATAMAX_PEARL_8x8 = 2048;
constexpr const unsigned char fontdata_pearl_8x8[FONTDATAMAX_PEARL_8x8] = {
constexpr const uint8_t fontdata_pearl_8x8[FONTDATAMAX_PEARL_8x8] = {
/* 0 0x00 '^@' */
0x00, /* 00000000 */

View File

@ -2,7 +2,7 @@
constexpr const uint32_t FONTDATAMAX_SUN_12x22 = 11264;
constexpr const unsigned char fontdata_sun_12x22[FONTDATAMAX_SUN_12x22] = {
constexpr const uint8_t fontdata_sun_12x22[FONTDATAMAX_SUN_12x22] = {
/* 0 0x00 '^@' */
0x00, 0x00, /* 000000000000 */

View File

@ -2,7 +2,7 @@
constexpr const uint32_t FONTDATAMAX_SUN8x16 = 4096;
constexpr const unsigned char fontdata_sun_8x16[FONTDATAMAX_SUN8x16] = {
constexpr const uint8_t fontdata_sun_8x16[FONTDATAMAX_SUN8x16] = {
/* */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* */ 0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xbd,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00,
/* */ 0x00,0x00,0x7e,0xff,0xdb,0xff,0xff,0xc3,0xe7,0xff,0xff,0x7e,0x00,0x00,0x00,0x00,

View File

@ -18,7 +18,7 @@ class Font {
public:
virtual ~Font() = default;
virtual const unsigned char* getChar(uint32_t c) const = 0;
virtual const uint8_t* getChar(uint32_t c) const = 0;
virtual uint32_t get_char_width() const = 0;
virtual uint32_t get_char_height() const = 0;
};
@ -44,12 +44,12 @@ public:
}
};
extern const unsigned char fontdata_8x16[];
extern const unsigned char fontdata_8x8[];
extern const unsigned char acorndata_8x8[];
extern const unsigned char fontdata_pearl_8x8[];
extern const unsigned char fontdata_sun_12x22[];
extern const unsigned char fontdata_sun_8x16[];
extern const uint8_t fontdata_8x16[];
extern const uint8_t fontdata_8x8[];
extern const uint8_t acorndata_8x8[];
extern const uint8_t fontdata_pearl_8x8[];
extern const uint8_t fontdata_sun_12x22[];
extern const uint8_t fontdata_sun_8x16[];
using Font_8x16 = FontInstance<8, 16, fontdata_8x16>;
using Font_8x8 = FontInstance<8, 8, fontdata_8x8>;

View File

@ -39,7 +39,7 @@ 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);
uint16_t width_byte = width / 8 + ((width % 8 != 0) ? 1 : 0);
for (uint32_t yoff = 0; yoff < height; ++yoff) {
uint32_t xpos = x;
@ -70,7 +70,7 @@ inline void LFBgraphics::drawMonoBitmap(uint32_t x, uint32_t y,
*****************************************************************************/
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) {
for (uint32_t 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();
}
@ -84,15 +84,15 @@ void LFBgraphics::drawString(const Font& fnt, uint32_t x, uint32_t y,
* *
* Beschreibung: Zeichnen eines Pixels. *
*****************************************************************************/
void LFBgraphics::drawPixel(unsigned int x, unsigned int y, unsigned int col) const {
unsigned char* ptr = reinterpret_cast<unsigned char*>(lfb);
void LFBgraphics::drawPixel(uint32_t x, uint32_t y, uint32_t col) const {
auto* ptr = reinterpret_cast<uint8_t*>(lfb);
if (hfb == 0 || lfb == 0) {
return;
}
if (mode == BUFFER_INVISIBLE) {
ptr = reinterpret_cast<unsigned char*>(hfb);
ptr = reinterpret_cast<uint8_t*>(hfb);
}
// Pixel ausserhalb des sichtbaren Bereichs?
@ -132,7 +132,7 @@ void LFBgraphics::drawPixel(unsigned int x, unsigned int y, unsigned int col) co
}
}
void LFBgraphics::drawStraightLine(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int col) const {
void LFBgraphics::drawStraightLine(uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2, unsigned int col) const {
// Don't set mode inside the drawing function to use them in animations
if (x1 == x2 && y2 > y1) {
@ -164,8 +164,8 @@ void LFBgraphics::drawCircle(unsigned int x, unsigned int y, unsigned int rad, u
// TODO
}
void LFBgraphics::drawSprite(unsigned int width, unsigned int height, unsigned int bytes_pp, const unsigned char* pixel_data) const {
const unsigned char* ptr;
void LFBgraphics::drawSprite(unsigned int width, unsigned int height, unsigned int bytes_pp, const uint8_t* pixel_data) const {
const uint8_t* ptr;
for (unsigned int x = 0; x < width; ++x) {
for (unsigned int y = 0; y < height; ++y) {
ptr = pixel_data + (x + y * width) * bytes_pp;

View File

@ -30,7 +30,7 @@ private:
// Hilfsfunktion fuer drawString
void drawMonoBitmap(uint32_t x, uint32_t y,
uint32_t width, uint32_t height,
const unsigned char* bitmap, uint32_t col) const;
const uint8_t* bitmap, uint32_t col) const;
public:
LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren
@ -46,13 +46,13 @@ public:
void clear() 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, uint32_t x, uint32_t y, uint32_t col, const char* str, uint32_t len) const;
void drawCircle(unsigned int x, unsigned int y, unsigned int rad, unsigned int col) const;
void drawStraightLine(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int col) const;
void drawCircle(uint32_t x, uint32_t y, uint32_t rad, uint32_t col) const;
void drawStraightLine(uint32_t x1, uint32_t y1, uint32_t x2, unsigned int y2, unsigned int col) const;
void drawRectangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, unsigned int col) const;
void drawSprite(unsigned int width, unsigned int height, unsigned int bytes_pp, const unsigned char* pixel_data) const;
void drawSprite(unsigned int width, unsigned int height, unsigned int bytes_pp, const uint8_t* pixel_data) const;
// stellt ein, ob in den sichtbaren Puffer gezeichnet wird
void setDrawingBuff(int v);

View File

@ -14,24 +14,24 @@
// Informationen ueber einen VESA-Grafikmodus
// (siehe http://wiki.osdev.org/VESA_Video_Modes)
struct VbeModeInfoBlock {
unsigned short attributes;
unsigned char winA, winB;
unsigned short granularity;
unsigned short winsize;
unsigned short segmentA, segmentB;
unsigned short realFctPtr[2];
unsigned short pitch; // Bytes pro Scanline
uint16_t attributes;
uint8_t winA, winB;
uint16_t granularity;
uint16_t winsize;
uint16_t segmentA, segmentB;
uint16_t realFctPtr[2];
uint16_t pitch; // Bytes pro Scanline
unsigned short Xres, Yres;
unsigned char Wchar, Ychar, planes, bpp, banks;
unsigned char memory_model, bank_size, image_pages;
unsigned char reserved0;
uint16_t Xres, Yres;
uint8_t Wchar, Ychar, planes, bpp, banks;
uint8_t memory_model, bank_size, image_pages;
uint8_t reserved0;
unsigned char red_mask, red_position;
unsigned char green_mask, green_position;
unsigned char blue_mask, blue_position;
unsigned char rsv_mask, rsv_position;
unsigned char directcolor_attributes;
uint8_t red_mask, red_position;
uint8_t green_mask, green_position;
uint8_t blue_mask, blue_position;
uint8_t rsv_mask, rsv_position;
uint8_t directcolor_attributes;
uint32_t physbase; // Adresse des Linear-Framebuffers
uint32_t OffScreenMemOffset;
@ -42,11 +42,11 @@ struct VbeModeInfoBlock {
// (siehe http://wiki.osdev.org/VESA_Video_Modes)
struct VbeInfoBlock {
char VbeSignature[4]; // == "VESA"
unsigned short VbeVersion; // == 0x0300 for VBE 3.0
unsigned short OemStringPtr[2]; // isa vbeFarPtr
unsigned char Capabilities[4];
unsigned short VideoModePtr[2]; // isa vbeFarPtr
unsigned short TotalMemory; // as # of 64KB blocks
uint16_t VbeVersion; // == 0x0300 for VBE 3.0
uint16_t OemStringPtr[2]; // isa vbeFarPtr
uint8_t Capabilities[4];
uint16_t VideoModePtr[2]; // isa vbeFarPtr
uint16_t TotalMemory; // as # of 64KB blocks
} __attribute__((packed));
/*****************************************************************************
@ -68,7 +68,7 @@ void VESA::initTextMode() {
* Beschreibung: Bestimmten Grafikmodus einschalten. Dies wird durch *
* einen Aufruf des BIOS gemacht. *
*****************************************************************************/
bool VESA::initGraphicMode(unsigned short mode) {
bool VESA::initGraphicMode(uint16_t mode) {
// Alle Grafikmodi abfragen
BC_params->AX = 0x4F00;
@ -117,7 +117,7 @@ bool VESA::initGraphicMode(unsigned short mode) {
bpp = static_cast<uint8_t>(minf->bpp);
lfb = minf->physbase;
hfb = reinterpret_cast<unsigned int>(new char[xres * yres * bpp / 8]);
hfb = reinterpret_cast<uint32_t>(new char[xres * yres * bpp / 8]);
// Grafikmodus einschalten
BC_params->AX = 0x4f02; // SVFA BIOS, init mode

View File

@ -35,7 +35,7 @@ public:
// Can't make singleton because atexit
// Bestimmten Grafikmodus einschalten
bool initGraphicMode(unsigned short mode);
bool initGraphicMode(uint16_t mode);
static void initTextMode();
};

View File

@ -13,9 +13,9 @@
class Key {
// Kopieren erlaubt!
unsigned char asc; // ASCII code
unsigned char scan; // scan code
unsigned char modi; // modifier
uint8_t asc; // ASCII code
uint8_t scan; // scan code
uint8_t modi; // modifier
// Bit-Masken fuer die Modifier-Tasten
struct mbit {
@ -44,10 +44,10 @@ public:
void invalidate() { scan = 0; }
// ASCII, SCANCODE: Setzen und Abfragen von Ascii und Scancode
void ascii(unsigned char a) { asc = a; }
void scancode(unsigned char s) { scan = s; }
unsigned char ascii() const { return asc; }
unsigned char scancode() const { return scan; }
void ascii(uint8_t a) { asc = a; }
void scancode(uint8_t s) { scan = s; }
uint8_t ascii() const { return asc; }
uint8_t scancode() const { return scan; }
//
// Funktionen zum Setzen und Loeschen von SHIFT, ALT, CTRL usw.

View File

@ -17,7 +17,7 @@ const IOport Keyboard::data_port(0x60);
/* Tabellen fuer ASCII-Codes (Klassenvariablen) intiialisieren */
constexpr const unsigned char Keyboard::normal_tab[] = {
constexpr const uint8_t Keyboard::normal_tab[] = {
0, 0, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 225, 39, '\b',
0, 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', 129, '+', '\n',
0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 148, 132, '^', 0, '#',
@ -25,7 +25,7 @@ constexpr const unsigned char Keyboard::normal_tab[] = {
'*', 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '-',
0, 0, 0, '+', 0, 0, 0, 0, 0, 0, 0, '<', 0, 0};
constexpr const unsigned char Keyboard::shift_tab[] = {
constexpr const uint8_t Keyboard::shift_tab[] = {
0, 0, '!', '"', 21, '$', '%', '&', '/', '(', ')', '=', '?', 96, 0,
0, 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 154, '*', 0,
0, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 153, 142, 248, 0, 39,
@ -33,7 +33,7 @@ constexpr const unsigned char Keyboard::shift_tab[] = {
0, 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '>', 0, 0};
constexpr const unsigned char Keyboard::alt_tab[] = {
constexpr const uint8_t Keyboard::alt_tab[] = {
0, 0, 0, 253, 0, 0, 0, 0, '{', '[', ']', '}', '\\', 0, 0,
0, '@', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '~', 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -41,10 +41,10 @@ constexpr const unsigned char Keyboard::alt_tab[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '|', 0, 0};
constexpr const unsigned char Keyboard::asc_num_tab[] = {
constexpr const uint8_t Keyboard::asc_num_tab[] = {
'7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', ','};
constexpr const unsigned char Keyboard::scan_num_tab[] = {
constexpr const uint8_t Keyboard::scan_num_tab[] = {
8, 9, 10, 53, 5, 6, 7, 27, 2, 3, 4, 11, 51};
/*****************************************************************************
@ -288,7 +288,7 @@ void Keyboard::reboot() {
// Dem BIOS mitteilen, dass das Reset beabsichtigt war
// und kein Speichertest durchgefuehrt werden muss.
*reinterpret_cast<unsigned short*>(0x472) = 0x1234;
*reinterpret_cast<uint16_t*>(0x472) = 0x1234;
// Der Tastaturcontroller soll das Reset ausloesen.
do {

View File

@ -18,8 +18,8 @@
class Keyboard : public ISR {
private:
unsigned char code; // Byte von Tastatur
unsigned char prefix; // Prefix von Tastatur
uint8_t code; // Byte von Tastatur
uint8_t prefix; // Prefix von Tastatur
Key gather; // letzter dekodierter Key
char leds; // Zustand LEDs
@ -57,11 +57,11 @@ private:
prefix2 = 0xe1 };
// Klassenvariablen
static const unsigned char normal_tab[];
static const unsigned char shift_tab[];
static const unsigned char alt_tab[];
static const unsigned char asc_num_tab[];
static const unsigned char scan_num_tab[];
static const uint8_t normal_tab[];
static const uint8_t shift_tab[];
static const uint8_t alt_tab[];
static const uint8_t asc_num_tab[];
static const uint8_t scan_num_tab[];
// Interpretiert die Make und Break-Codes der Tastatur.
bool key_decoded();
@ -80,7 +80,7 @@ public:
// ~Keyboard() override = default;
// unsigned int lastkey; // speichert den ASCII-Code der zuletzt gedrückten Taste
// uint32_t lastkey; // speichert den ASCII-Code der zuletzt gedrückten Taste
// Fuehrt einen Neustart des Rechners durch.
static void reboot();

View File

@ -16,46 +16,48 @@
#ifndef IOport_include__
#define IOport_include__
#include <cstdint>
class IOport {
private:
// 16-Bit Adresse im I/O-Adressraum
const unsigned short address;
const uint16_t address;
public:
// Konstruktor, speichert Port-Adresse
explicit IOport(unsigned short a) : address(a) {};
explicit IOport(uint16_t a) : address(a) {};
// Byteweise Ausgabe eines Wertes ueber einen I/O-Port.
void outb(unsigned char val) const {
void outb(uint8_t val) const {
asm volatile("outb %0, %1"
:
: "a"(val), "Nd"(address));
}
// NOTE: I added this for easier init of COM1 port
void outb(unsigned char offset, unsigned char val) const {
void outb(uint8_t offset, uint8_t val) const {
asm volatile("outb %0, %1"
:
: "a"(val), "Nd"(static_cast<unsigned short>(address + offset)));
: "a"(val), "Nd"(static_cast<uint16_t>(address + offset)));
}
// Wortweise Ausgabe eines Wertes ueber einen I/O-Port.
void outw(unsigned short val) const {
void outw(uint16_t val) const {
asm volatile("outw %0, %1"
:
: "a"(val), "Nd"(address));
}
// 32-Bit Ausgabe eines Wertes ueber einen I/O-Port.
void outdw(unsigned int val) const {
void outdw(uint32_t val) const {
asm volatile("outl %0, %1"
:
: "a"(val), "Nd"(address));
}
// Byteweises Einlesen eines Wertes ueber einen I/O-Port.
unsigned char inb() const {
unsigned char ret;
uint8_t inb() const {
uint8_t ret;
asm volatile("inb %1, %0"
: "=a"(ret)
@ -64,18 +66,18 @@ public:
}
// NOTE: I added this for COM1 port
unsigned char inb(unsigned char offset) const {
unsigned char ret;
uint8_t inb(uint8_t offset) const {
uint8_t ret;
asm volatile("inb %1, %0"
: "=a"(ret)
: "Nd"(static_cast<unsigned short>(address + offset)));
: "Nd"(static_cast<uint16_t>(address + offset)));
return ret;
}
// Wortweises Einlesen eines Wertes ueber einen I/O-Port.
unsigned short inw() const {
unsigned short ret;
uint16_t inw() const {
uint16_t ret;
asm volatile("inw %1, %0"
: "=a"(ret)

View File

@ -71,7 +71,7 @@ inline void PCSPK::delay(uint32_t time) {
/* Hier muess Code eingefuegt werden */
unsigned long start_time = systime;
uint64_t start_time = systime;
// systime is incremented in 10ms steps
while ((systime - start_time) * 10 < time) {}

View File

@ -29,7 +29,7 @@ void PIT::interval(uint32_t us) {
control.outb(0x36); // Zähler 0 Mode 3
uint32_t cntStart = static_cast<unsigned int>((1193180.0 / 1000000.0) * us); // 1.19Mhz PIT
auto cntStart = static_cast<uint32_t>((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

@ -29,7 +29,7 @@ void TextDemo::run() {
<< "| dec | hex | bin |" << endl
<< "+-------+-------+-------+" << endl;
for (unsigned short num = 0; num < 17; ++num) {
for (uint16_t num = 0; num < 17; ++num) {
kout << fillw(0) << "| " << fillw(6) << dec << num
<< fillw(0) << "| " << fillw(6) << hex << num
<< fillw(0) << "| " << fillw(6) << bin << num

View File

@ -56,7 +56,7 @@ void VBEdemo::drawBitmap() {
unsigned int sprite_width = hhu.width;
unsigned int sprite_height = hhu.height;
unsigned int sprite_bpp = hhu.bytes_per_pixel;
const unsigned char* sprite_pixel = reinterpret_cast<const unsigned char*>(hhu.pixel_data);
const uint8_t* sprite_pixel = reinterpret_cast<const uint8_t*>(hhu.pixel_data);
/* Hier muss Code eingefuegt werden */

View File

@ -1,10 +1,12 @@
#include <cstdint>
/* GIMP RGB C-Source image dump (hhulogo.c) */
static constexpr struct {
unsigned int width;
unsigned int height;
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
unsigned char pixel_data[200 * 52 * 3 + 1];
uint32_t width;
uint32_t height;
uint8_t bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
uint8_t pixel_data[200 * 52 * 3 + 1];
} hhu = {
200,
52,

View File

@ -14,7 +14,7 @@
// in startup.asm
extern "C" {
// CR2 auslesen
unsigned int get_page_fault_address();
uint32_t get_page_fault_address();
// 1st level interrupt handler in startup.asm sichert Zeiger auf Stackframe
// unmittelbar nach dem Interrupt und nachdem alle Register mit PUSHAD
@ -45,7 +45,7 @@ extern "C" {
// | EDI |
// |-------------| <-- int_esp
void get_int_esp(unsigned int** esp);
void get_int_esp(uint32_t** esp);
}
void break_on_bluescreen() {
@ -95,7 +95,7 @@ void bs_lf() {
* Beschreibung: Ein Zeichen ausgeben. *
*****************************************************************************/
void bs_print_char(char c) {
unsigned char* ptr = reinterpret_cast<unsigned char*>(0xb8000);
auto* ptr = reinterpret_cast<uint8_t*>(0xb8000);
*(ptr + bs_ypos * 80 * 2 + bs_xpos * 2) = c;
bs_xpos++;
@ -121,9 +121,9 @@ void bs_print_string(char* str) {
*****************************************************************************/
void bs_printHexDigit(int c) {
if (c < 10) {
bs_print_char('0' + static_cast<unsigned char>(c));
bs_print_char('0' + static_cast<uint8_t>(c));
} else {
bs_print_char('A' + static_cast<unsigned char>(c - 10));
bs_print_char('A' + static_cast<uint8_t>(c - 10));
}
}
@ -132,7 +132,7 @@ void bs_printHexDigit(int c) {
*---------------------------------------------------------------------------*
* Beschreibung: Integer ausgeben. *
*****************************************************************************/
void bs_print_uintHex(unsigned int c) {
void bs_print_uintHex(uint32_t c) {
for (int i = 28; i >= 0; i = i - 4) {
bs_printHexDigit((c >> i) & 0xF);
}
@ -144,7 +144,7 @@ void bs_print_uintHex(unsigned int c) {
* Beschreibung: String mit Integer ausgeben. Wird verwendet um ein *
* Register auszugeben. *
*****************************************************************************/
void bs_printReg(char* str, unsigned int value) {
void bs_printReg(char* str, uint32_t value) {
bs_print_string(str);
bs_print_uintHex(value);
bs_print_string(" \0");
@ -251,7 +251,7 @@ void bs_dump(uint8_t exceptionNr) {
// Exception mit Error-Code?
if (has_error_code == 1) {
unsigned int error_nr = *(sptr + 8);
uint32_t error_nr = *(sptr + 8);
if (exceptionNr == 14) {
if (error_nr == 3) {
@ -278,7 +278,7 @@ void bs_dump(uint8_t exceptionNr) {
bs_lf();
int x = 0;
auto* ebp = reinterpret_cast<uint32_t*>(*(sptr + 2));
unsigned int raddr;
uint32_t raddr;
// solange eip > 1 MB && ebp < 128 MB, max. Aufruftiefe 10
while (*ebp > 0x100000 && *ebp < 0x8000000 && x < 10) {

View File

@ -22,7 +22,7 @@ void BumpAllocator::init() {
/* Hier muess Code eingefuegt werden */
allocations = 0;
next = reinterpret_cast<unsigned char*>(heap_start);
next = reinterpret_cast<uint8_t*>(heap_start);
log.info() << "Initialized Bump Allocator" << endl;
}
@ -37,7 +37,7 @@ void BumpAllocator::dump_free_memory() {
/* Hier muess Code eingefuegt werden */
kout << "Freier Speicher:" << endl
<< " - Next: " << hex << reinterpret_cast<unsigned int>(next)
<< " - Next: " << hex << reinterpret_cast<uint32_t>(next)
<< ", Allocations: " << dec << allocations << endl;
}
@ -46,19 +46,19 @@ void BumpAllocator::dump_free_memory() {
*---------------------------------------------------------------------------*
* Beschreibung: Einen neuen Speicherblock allozieren. *
*****************************************************************************/
void* BumpAllocator::alloc(unsigned int req_size) {
void* BumpAllocator::alloc(uint32_t req_size) {
/* Hier muess Code eingefuegt werden */
log.debug() << "Requested " << hex << req_size << " Bytes" << endl;
if (req_size + reinterpret_cast<unsigned int>(next) > heap_end) {
if (req_size + reinterpret_cast<uint32_t>(next) > heap_end) {
log.error() << " - More memory requested than available :(" << endl;
return nullptr;
}
void* allocated = next;
next = reinterpret_cast<unsigned char*>(reinterpret_cast<unsigned int>(next) + req_size);
next = reinterpret_cast<uint8_t*>(reinterpret_cast<uint32_t>(next) + req_size);
allocations = allocations + 1;
log.trace() << " - Allocated " << hex << req_size << " Bytes." << endl;
@ -72,5 +72,5 @@ void* BumpAllocator::alloc(unsigned int req_size) {
* Beschreibung: Nicht implementiert. *
*****************************************************************************/
void BumpAllocator::free(void* ptr) {
log.error() << " mm_free: ptr= " << hex << reinterpret_cast<unsigned int>(ptr) << ", not supported" << endl;
log.error() << " mm_free: ptr= " << hex << reinterpret_cast<uint32_t>(ptr) << ", not supported" << endl;
}

View File

@ -17,8 +17,8 @@
class BumpAllocator : Allocator {
private:
unsigned char* next;
unsigned int allocations;
uint8_t* next;
uint32_t allocations;
NamedLogger log;
@ -31,7 +31,7 @@ public:
void init() override;
void dump_free_memory() override;
void* alloc(unsigned int req_size) override;
void* alloc(uint32_t req_size) override;
void free(void* ptr) override;
};

View File

@ -53,11 +53,11 @@ void LinkedListAllocator::dump_free_memory() {
if (free_start == nullptr) {
kout << " - No free Blocks" << endl;
} else {
kout << " - Freelist start: " << hex << reinterpret_cast<unsigned int>(free_start) << endl;
kout << " - Freelist start: " << hex << reinterpret_cast<uint32_t>(free_start) << endl;
free_block_t* current = free_start;
do {
kout << " - Free Block (Start: " << hex << reinterpret_cast<unsigned int>(current)
kout << " - Free Block (Start: " << hex << reinterpret_cast<uint32_t>(current)
<< " Size: " << hex << current->size << ")" << endl;
current = current->next;
} while (current != free_start);
@ -69,7 +69,7 @@ void LinkedListAllocator::dump_free_memory() {
*---------------------------------------------------------------------------*
* Beschreibung: Einen neuen Speicherblock allozieren. *
*****************************************************************************/
void* LinkedListAllocator::alloc(unsigned int req_size) {
void* LinkedListAllocator::alloc(uint32_t req_size) {
lock.acquire();
/* Hier muess Code eingefuegt werden */
@ -84,8 +84,8 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
}
// Round to word borders
unsigned int req_size_diff = (BASIC_ALIGN - req_size % BASIC_ALIGN) % BASIC_ALIGN;
unsigned int rreq_size = req_size + req_size_diff;
uint32_t req_size_diff = (BASIC_ALIGN - req_size % BASIC_ALIGN) % BASIC_ALIGN;
uint32_t rreq_size = req_size + req_size_diff;
if (req_size_diff > 0) {
log.trace() << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl;
}
@ -105,7 +105,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
// In case of only one freeblock:
// [current | new_next]
free_block_t* new_next =
reinterpret_cast<free_block_t*>(reinterpret_cast<unsigned int>(current) + sizeof(free_block_t) + rreq_size);
reinterpret_cast<free_block_t*>(reinterpret_cast<uint32_t>(current) + sizeof(free_block_t) + rreq_size);
// If only one block exists, current->next is current
// This shouldn't be a problem since the block gets removed from the list later
@ -149,14 +149,14 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
// free_block_t* c = current;
// log.debug() << "Checking list Integrity" << endl;
// while (c->allocated) {
// log.debug() << hex << (unsigned int)c << endl;
// log.debug() << hex << (uint32_t)c << endl;
// c = c->next;
// }
// log.debug() << "Finished check" << endl;
log.debug() << "returning memory address " << hex << reinterpret_cast<unsigned int>(current) + sizeof(free_block_t) << endl;
log.debug() << "returning memory address " << hex << reinterpret_cast<uint32_t>(current) + sizeof(free_block_t) << endl;
lock.release();
return reinterpret_cast<void*>(reinterpret_cast<unsigned int>(current) + sizeof(free_block_t)); // Speicheranfang, nicht header
return reinterpret_cast<void*>(reinterpret_cast<uint32_t>(current) + sizeof(free_block_t)); // Speicheranfang, nicht header
}
current = current->next;
@ -178,9 +178,9 @@ void LinkedListAllocator::free(void* ptr) {
/* Hier muess Code eingefuegt werden */
// Account for header
free_block_t* block_start = reinterpret_cast<free_block_t*>(reinterpret_cast<unsigned int>(ptr) - sizeof(free_block_t));
free_block_t* block_start = reinterpret_cast<free_block_t*>(reinterpret_cast<uint32_t>(ptr) - sizeof(free_block_t));
log.debug() << "Freeing " << hex << reinterpret_cast<unsigned int>(ptr) << ", Size: " << block_start->size << endl;
log.debug() << "Freeing " << hex << reinterpret_cast<uint32_t>(ptr) << ", Size: " << block_start->size << endl;
if (!block_start->allocated) {
log.error() << "Block already free" << endl;
@ -201,7 +201,7 @@ void LinkedListAllocator::free(void* ptr) {
}
free_block_t* next_block =
reinterpret_cast<free_block_t*>(reinterpret_cast<unsigned int>(block_start) + sizeof(free_block_t) + block_start->size);
reinterpret_cast<free_block_t*>(reinterpret_cast<uint32_t>(block_start) + sizeof(free_block_t) + block_start->size);
// Find the next free block, multiple next blocks can be allocated so walk through them
free_block_t* next_free = block_start->next;
@ -211,7 +211,7 @@ void LinkedListAllocator::free(void* ptr) {
free_block_t* previous_free = LinkedListAllocator::find_previous_block(next_free);
free_block_t* previous_free_next =
reinterpret_cast<free_block_t*>(reinterpret_cast<unsigned int>(previous_free) + sizeof(free_block_t) + previous_free->size);
reinterpret_cast<free_block_t*>(reinterpret_cast<uint32_t>(previous_free) + sizeof(free_block_t) + previous_free->size);
// We have: [previous_free | previous_free_next | <> | block_start | next_block | <> | next_free]
// The <> spaces don't have to exist and next_block could be the same as next_free
@ -225,7 +225,7 @@ void LinkedListAllocator::free(void* ptr) {
// Should result in: [block_start]
// log.trace() << "Before doing any merging:" << endl;
// log.trace() << "previous_free:" << hex << (unsigned int)previous_free << "Size:" << previous_free->size << "Next:" << (unsigned int)previous_free->next << endl;
// log.trace() << "previous_free:" << hex << (uint32_t)previous_free << "Size:" << previous_free->size << "Next:" << (unsigned int)previous_free->next << endl;
// log.trace() << "previous_free_next:" << hex << (unsigned int)previous_free_next << "Size:" << previous_free_next->size << "Next:" << (unsigned int)previous_free_next->next << endl;
// log.trace() << "block_start:" << hex << (unsigned int)block_start << "Size:" << block_start->size << "Next:" << (unsigned int)block_start->next << endl;
// log.trace() << "next_block:" << hex << (unsigned int)next_block << "Size:" << next_block->size << "Next:" << (unsigned int)next_block->next << endl;

View File

@ -25,7 +25,7 @@ typedef struct free_block {
// We only need a way to determine when the free block is reached.
// This also means that the whole list has to be traversed
// to merge blocks. Would be faster with doubly linked list.
unsigned int size;
uint32_t size;
struct free_block* next;
} free_block_t;
@ -51,7 +51,7 @@ public:
void init() override;
void dump_free_memory() override;
void* alloc(unsigned int req_size) override;
void* alloc(uint32_t req_size) override;
void free(void* ptr) override;
};

View File

@ -19,26 +19,26 @@ void TreeAllocator::dump_free_memory() {
list_block_t* current = reinterpret_cast<list_block_t*>(heap_start);
do {
if (!current->allocated) {
kout << " - Free Block at " << reinterpret_cast<unsigned int>(current) << ", Size: "
<< reinterpret_cast<unsigned int>(current->next) - reinterpret_cast<unsigned int>(current)
kout << " - Free Block at " << reinterpret_cast<uint32_t>(current) << ", Size: "
<< reinterpret_cast<uint32_t>(current->next) - reinterpret_cast<uint32_t>(current)
<< endl;
}
current = current->next;
} while (reinterpret_cast<unsigned int>(current) != heap_start);
} while (reinterpret_cast<uint32_t>(current) != heap_start);
}
void* TreeAllocator::alloc(unsigned int req_size) {
void* TreeAllocator::alloc(uint32_t req_size) {
log.debug() << "Requested " << dec << req_size << " Bytes" << endl;
// Round to word borders + tree_block size
unsigned int rreq_size = req_size;
uint32_t rreq_size = req_size;
if (rreq_size < sizeof(tree_block_t) - sizeof(list_block_t)) {
// the list_block_t is part of every block, but when freeing
// memory we need enough space to store the rbt metadata
rreq_size = sizeof(tree_block_t) - sizeof(list_block_t);
log.trace() << " - Increased block size for rbt metadata" << endl;
}
unsigned int req_size_diff = (BASIC_ALIGN - rreq_size % BASIC_ALIGN) % BASIC_ALIGN;
uint32_t req_size_diff = (BASIC_ALIGN - rreq_size % BASIC_ALIGN) % BASIC_ALIGN;
rreq_size = rreq_size + req_size_diff;
if (req_size_diff > 0) {
log.trace() << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl;
@ -56,8 +56,8 @@ void* TreeAllocator::alloc(unsigned int req_size) {
return nullptr;
}
best_fit->allocated = true;
unsigned int size = get_size(best_fit);
log.trace() << " - Found best-fit: " << hex << reinterpret_cast<unsigned int>(best_fit) << endl;
uint32_t size = get_size(best_fit);
log.trace() << " - Found best-fit: " << hex << reinterpret_cast<uint32_t>(best_fit) << endl;
// HACK: I didn't want to handle situations with only one block (where the tree root would
// get removed), so I make sure there are always at least 2 blocks by inserting a dummy
@ -90,13 +90,13 @@ void* TreeAllocator::alloc(unsigned int req_size) {
rbt_remove(&dummy);
log.trace() << " - Returned address " << hex
<< reinterpret_cast<unsigned int>(reinterpret_cast<char*>(best_fit) + sizeof(list_block_t))
<< reinterpret_cast<uint32_t>(reinterpret_cast<char*>(best_fit) + sizeof(list_block_t))
<< endl;
return reinterpret_cast<void*>(reinterpret_cast<char*>(best_fit) + sizeof(list_block_t));
}
void TreeAllocator::free(void* ptr) {
log.info() << "Freeing " << hex << reinterpret_cast<unsigned int>(ptr) << endl;
log.info() << "Freeing " << hex << reinterpret_cast<uint32_t>(ptr) << endl;
list_block_t* block = reinterpret_cast<list_block_t*>(reinterpret_cast<char*>(ptr) - sizeof(list_block_t));
if (!block->allocated) {
@ -147,13 +147,13 @@ void TreeAllocator::free(void* ptr) {
rbt_remove(&dummy);
}
unsigned int TreeAllocator::get_size(list_block_t* block) const {
uint32_t TreeAllocator::get_size(list_block_t* block) const {
if (block->next == block) {
// Only one block exists
return heap_end - (reinterpret_cast<unsigned int>(block) + sizeof(list_block_t));
return heap_end - (reinterpret_cast<uint32_t>(block) + sizeof(list_block_t));
}
if (reinterpret_cast<unsigned int>(block->next) > reinterpret_cast<unsigned int>(block)) {
if (reinterpret_cast<uint32_t>(block->next) > reinterpret_cast<unsigned int>(block)) {
// Next block is placed later in memory
return reinterpret_cast<unsigned int>(block->next) - (reinterpret_cast<unsigned int>(block) + sizeof(list_block_t));
}

View File

@ -39,8 +39,8 @@ private:
NamedLogger log;
// Returns the size of the usable memory of a block
unsigned int get_size(list_block_t* block) const;
unsigned int get_size(tree_block_t* block) const { return get_size(reinterpret_cast<list_block_t*>(block)); }
uint32_t get_size(list_block_t* block) const;
uint32_t get_size(tree_block_t* block) const { return get_size(reinterpret_cast<list_block_t*>(block)); }
void dump_free_memory(tree_block_t* node);
@ -56,8 +56,8 @@ private:
void rbt_remove(tree_block_t* z);
void rbt_fix_remove(tree_block_t* x);
tree_block_t* rbt_search_bestfit(tree_block_t* node, unsigned int req_size);
tree_block_t* rbt_search_bestfit(unsigned int req_size) { return rbt_search_bestfit(free_start, req_size); }
tree_block_t* rbt_search_bestfit(tree_block_t* node, uint32_t req_size);
tree_block_t* rbt_search_bestfit(uint32_t req_size) { return rbt_search_bestfit(free_start, req_size); }
void dll_insert(list_block_t* previous, list_block_t* node);
void dll_insert(tree_block_t* previous, tree_block_t* node) {
@ -74,7 +74,7 @@ public:
void init() override;
void dump_free_memory() override;
void* alloc(unsigned int req_size) override;
void* alloc(uint32_t req_size) override;
void free(void* ptr) override;
};

View File

@ -262,7 +262,7 @@ void TreeAllocator::rbt_fix_remove(tree_block_t* x) {
// END copy from algorithmtutorprograms
// This is recursive and depends on luck
tree_block_t* TreeAllocator::rbt_search_bestfit(tree_block_t* node, unsigned int req_size) {
tree_block_t* TreeAllocator::rbt_search_bestfit(tree_block_t* node, uint32_t req_size) {
if (node == nullptr) {
return nullptr;
}

View File

@ -131,10 +131,10 @@ void Scheduler::exit() {
* Parameter: *
* that Zu terminierender Thread *
*****************************************************************************/
void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
void Scheduler::kill(uint32_t tid, bse::unique_ptr<Thread>* ptr) {
CPU::disable_int();
unsigned int prev_tid = (*active)->tid;
uint32_t prev_tid = (*active)->tid;
// Block queue, can always kill
for (bse::vector<bse::unique_ptr<Thread>>::iterator it = block_queue.begin(); it != block_queue.end(); ++it) {
@ -143,7 +143,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
if (ptr != nullptr) {
// Move old thread out of queue to return it
unsigned int pos = bse::distance(block_queue.begin(), it);
uint32_t pos = bse::distance(block_queue.begin(), it);
*ptr = std::move(block_queue[pos]); // Return the killed thread
}
@ -169,7 +169,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
if (ptr != nullptr) {
// Move old thread out of queue to return it
unsigned int pos = bse::distance(ready_queue.begin(), it);
uint32_t pos = bse::distance(ready_queue.begin(), it);
*ptr = std::move(ready_queue[pos]); // Return the killed thread
}
@ -197,7 +197,7 @@ void Scheduler::kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
// TODO: Can't retrive the thread right now because it's not clear when it's finished,
// maybe introduce a exited_queue and get it from there
void Scheduler::nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr) {
void Scheduler::nice_kill(uint32_t tid, bse::unique_ptr<Thread>* ptr) {
CPU::disable_int();
for (bse::unique_ptr<Thread>& thread : block_queue) {
@ -314,7 +314,7 @@ void Scheduler::block() {
* *
* Parameter: that: Thread der deblockiert werden soll. *
*****************************************************************************/
void Scheduler::deblock(unsigned int tid) {
void Scheduler::deblock(uint32_t tid) {
/* hier muss Code eingefuegt werden */

View File

@ -30,14 +30,14 @@ private:
// Scheduler wird evt. von einer Unterbrechung vom Zeitgeber gerufen,
// bevor er initialisiert wurde
unsigned int idle_tid = 0U;
uint32_t idle_tid = 0U;
// Roughly the old dispatcher functionality
void start(bse::vector<bse::unique_ptr<Thread>>::iterator next); // Start next without prev
void switch_to(Thread* prev_raw, bse::vector<bse::unique_ptr<Thread>>::iterator next); // Switch from prev to next
// Kann nur vom Idle-Thread aufgerufen werden (erster Thread der vom Scheduler gestartet wird)
void enable_preemption(unsigned int tid) { idle_tid = tid; }
void enable_preemption(uint32_t tid) { idle_tid = tid; }
friend class IdleThread;
void ready(bse::unique_ptr<Thread>&& thread);
@ -53,7 +53,7 @@ public:
block_queue.reserve();
}
unsigned int get_active() const {
uint32_t get_active() const {
return (*active)->tid;
}
@ -67,9 +67,9 @@ public:
// Helper that directly constructs the thread, then readys it
template<typename T, typename... Args>
unsigned int ready(Args... args) {
uint32_t ready(Args... args) {
bse::unique_ptr<Thread> thread = bse::make_unique<T>(std::forward<Args>(args)...);
unsigned int tid = thread->tid;
uint32_t tid = thread->tid;
ready(std::move(thread));
@ -83,15 +83,15 @@ public:
void exit(); // Returns on error because we don't have exceptions
// Thread mit 'Gewalt' terminieren
void kill(unsigned int tid, bse::unique_ptr<Thread>* ptr);
void kill(unsigned int tid) { kill(tid, nullptr); }
void kill(uint32_t tid, bse::unique_ptr<Thread>* ptr);
void kill(uint32_t tid) { kill(tid, nullptr); }
// Asks thread to exit
// NOTE: I had many problems with killing threads that were stuck in some semaphore
// or were involved in any locking mechanisms, so with this a thread can make sure
// to "set things right" before exiting itself (but could also be ignored)
void nice_kill(unsigned int tid, bse::unique_ptr<Thread>* ptr);
void nice_kill(unsigned int tid) { nice_kill(tid, nullptr); }
void nice_kill(uint32_t tid, bse::unique_ptr<Thread>* ptr);
void nice_kill(uint32_t tid) { nice_kill(tid, nullptr); }
// CPU freiwillig abgeben und Auswahl des naechsten Threads
void yield(); // Returns when only the idle thread runs
@ -103,7 +103,7 @@ public:
void block(); // Returns on error because we don't have exceptions
// Deblock by tid (move to ready_queue)
void deblock(unsigned int tid);
void deblock(uint32_t tid);
};
#endif

View File

@ -33,7 +33,7 @@ extern "C" {
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
uint32_t ThreadCnt = 1; // Skip tid 0 as the scheduler indicates no preemption with 0
/*****************************************************************************
* Prozedur: Coroutine_init *
@ -44,8 +44,8 @@ unsigned int ThreadCnt = 1; // Skip tid 0 as the scheduler indicates no preempt
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;
// unsigned int** sp = (unsigned int**)stack;
// register uint32_t** sp = (uint32_t**)stack;
// uint32_t** sp = (uint32_t**)stack;
// Stack initialisieren. Es soll so aussehen, als waere soeben die
// eine Funktion aufgerufen worden, die als Parameter den Zeiger
@ -56,20 +56,20 @@ void Thread_init(uint32_t* esp, uint32_t* stack, void (*kickoff)(Thread*), void*
// wird, sie darf also nicht terminieren, sonst kracht's.
// I thought this syntax was a bit clearer than decrementing a pointer
stack[-1] = reinterpret_cast<unsigned int>(object);
stack[-1] = reinterpret_cast<uint32_t>(object);
stack[-2] = 0x131155U;
stack[-3] = reinterpret_cast<unsigned int>(kickoff);
stack[-3] = reinterpret_cast<uint32_t>(kickoff);
stack[-4] = 0; // EAX
stack[-5] = 0; // ECX
stack[-6] = 0; // EDX
stack[-7] = 0; // EBX
stack[-8] = reinterpret_cast<unsigned int>(&stack[-3]); // ESP
stack[-8] = reinterpret_cast<uint32_t>(&stack[-3]); // ESP
stack[-9] = 0; // EBP
stack[-10] = 0; // ESI
stack[-11] = 0; // EDI
stack[-12] = 0x200U;
*esp = reinterpret_cast<unsigned int>(&stack[-12]);
*esp = reinterpret_cast<uint32_t>(&stack[-12]);
}
/*****************************************************************************
@ -97,7 +97,7 @@ void Thread_init(uint32_t* esp, uint32_t* stack, void (*kickoff)(Thread*), void*
* Parameter: *
* stack Stack für die neue Koroutine *
*****************************************************************************/
Thread::Thread(char* name) : stack(new unsigned int[1024]), esp(0), log(name), name(name), tid(ThreadCnt++) {
Thread::Thread(char* name) : stack(new uint32_t[1024]), esp(0), log(name), name(name), tid(ThreadCnt++) {
if (stack == nullptr) {
log.error() << "Couldn't initialize Thread (couldn't alloc stack)" << endl;
return;

View File

@ -42,7 +42,7 @@ protected:
bool running = true; // For soft exit, if thread uses infinite loop inside run(), use this as condition
char* name; // For logging
unsigned int tid; // Thread-ID (wird im Konstruktor vergeben)
uint32_t tid; // Thread-ID (wird im Konstruktor vergeben)
friend class Scheduler; // Scheduler can access tid
public:

View File

@ -30,4 +30,4 @@ KeyEventManager kevman;
SerialOut serial;
unsigned int total_mem; // RAM total
unsigned long systime = 0;
uint64_t systime = 0;

View File

@ -48,7 +48,7 @@ extern Scheduler scheduler;
extern KeyEventManager kevman;
extern SerialOut serial;
extern unsigned int total_mem; // RAM total
extern unsigned long systime; // wird all 10ms hochgezaehlt
extern uint32_t total_mem; // RAM total
extern uint64_t systime; // wird all 10ms hochgezaehlt
#endif

View File

@ -23,8 +23,8 @@
* *ptr := _new *
* return prev *
*****************************************************************************/
static inline unsigned long CAS(const unsigned long* ptr) {
unsigned long prev;
static inline uint32_t CAS(const uint32_t* ptr) {
uint32_t prev;
/*
AT&T/UNIX assembly syntax

View File

@ -12,10 +12,12 @@
#ifndef SpinLock_include__
#define SpinLock_include__
#include <cstdint>
class SpinLock {
private:
unsigned long lock;
unsigned long* ptr;
uint32_t lock;
uint32_t* ptr;
public:
SpinLock(const SpinLock& copy) = delete; // Verhindere Kopieren