add a shnitton of loggers
This commit is contained in:
@ -8,12 +8,12 @@ void BufferedCGA::init(unsigned int pages) {
|
||||
this->screen_buffer = std::make_unique<CGA::cga_page_t>();
|
||||
|
||||
if (this->scrollback_buffer == NULL || this->screen_buffer == NULL) {
|
||||
if constexpr (DEBUG) { kout << "Error initializing scrollback buffer" << endl; }
|
||||
log << ERROR << "Error initializing scrollback buffer" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
this->initialized = true;
|
||||
if constexpr (DEBUG) { kout << "Initialized scrollback buffer" << endl; }
|
||||
log << INFO << "Initialized scrollback buffer" << endl;
|
||||
}
|
||||
|
||||
void BufferedCGA::display_scrollback() {
|
||||
@ -26,7 +26,7 @@ void BufferedCGA::display_scrollback() {
|
||||
this->scrollback_buffer->get((CGA::cga_line_t*)CGA_START, this->scrollback - 1);
|
||||
}
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
log << DEBUG << "ScrollbackBuffer not initialized" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ void BufferedCGA::scrollup() {
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->put((CGA::cga_line_t*)CGA_START);
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
log << DEBUG << "ScrollbackBuffer not initialized" << endl;
|
||||
}
|
||||
|
||||
CGA::scrollup();
|
||||
@ -59,7 +59,7 @@ void BufferedCGA::clear() {
|
||||
this->scrollback_buffer->clear();
|
||||
mmem::zero<CGA::cga_page_t>(this->screen_buffer.get());
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
log << DEBUG << "ScrollbackBuffer not initialized" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ void BufferedCGA::scroll_page_backward() {
|
||||
}
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
log << DEBUG << "ScrollbackBuffer not initialized" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,6 +90,6 @@ void BufferedCGA::scroll_page_forward() {
|
||||
}
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
log << DEBUG << "ScrollbackBuffer not initialized" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "devices/CGA.h"
|
||||
#include "devices/Keyboard.h"
|
||||
#include "user/lib/Logger.h"
|
||||
#include "user/ScrollbackBuffer.h"
|
||||
#include <memory>
|
||||
|
||||
@ -16,8 +17,10 @@ private:
|
||||
|
||||
BufferedCGA(const BufferedCGA&) = delete;
|
||||
|
||||
Logger log;
|
||||
|
||||
public:
|
||||
BufferedCGA() : initialized(false), scrollback(0) {}
|
||||
BufferedCGA() : initialized(false), scrollback(0), log("BufferedCGA") {}
|
||||
|
||||
unsigned char scrollback; // The page that is displayed, public to enable page display
|
||||
|
||||
|
||||
@ -148,7 +148,7 @@ void LFBgraphics::drawStraightLine(unsigned int x1, unsigned int y1, unsigned in
|
||||
this->drawPixel(i, y1, col);
|
||||
}
|
||||
} else {
|
||||
kout << "Error (LFBgraphics::drawStraightLine): Line is not straight" << endl;
|
||||
log << ERROR << "Line is not straight" << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#define __LFBgraphics_include__
|
||||
|
||||
#include "devices/fonts/Fonts.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
// Hilfsfunktionen um Farbwerte fuer einen Pixel zu erzeugen
|
||||
#define RGB_24(r, g, b) (unsigned int)((r << 16) + (g << 8) + b)
|
||||
@ -24,10 +25,11 @@
|
||||
#define BUFFER_VISIBLE 1
|
||||
|
||||
class LFBgraphics {
|
||||
|
||||
private:
|
||||
LFBgraphics(const LFBgraphics& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
Logger log;
|
||||
|
||||
// Hilfsfunktion fuer drawString
|
||||
void drawMonoBitmap(unsigned int x, unsigned int y,
|
||||
unsigned int width, unsigned int height,
|
||||
@ -40,7 +42,7 @@ public:
|
||||
unsigned int hfb; // Adresse des versteckten Buffers (optional, fuer Animationen)
|
||||
unsigned int mode; // Zeichnen im sichtbaren = 1 oder unsichtbaren = 0 Puffer
|
||||
|
||||
LFBgraphics() : mode(BUFFER_VISIBLE) {};
|
||||
LFBgraphics() : log("LFBgraphics"), mode(BUFFER_VISIBLE) {};
|
||||
|
||||
void clear();
|
||||
void drawPixel(unsigned int x, unsigned int y, unsigned int col);
|
||||
|
||||
@ -29,7 +29,6 @@ void PIT::interval(int us) {
|
||||
control.outb(0x36); // Zähler 0 Mode 3
|
||||
|
||||
unsigned int cntStart = (1193180.0 / 1000000.0) * us; // 1.19Mhz PIT
|
||||
// kout << "PIT cntStart: " << dec << cntStart << endl;
|
||||
|
||||
IOport data0(0x40);
|
||||
data0.outb(cntStart & 0xFF); // Zaehler-0 laden (Lobyte)
|
||||
|
||||
@ -14,11 +14,10 @@
|
||||
#include "kernel/interrupts/ISR.h"
|
||||
|
||||
class PIT : public ISR {
|
||||
|
||||
private:
|
||||
PIT(const PIT ©) = delete; // Verhindere Kopieren
|
||||
|
||||
enum { time_base = 838 }; /* ns */
|
||||
PIT(const PIT& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
enum { time_base = 838 }; /* ns */
|
||||
int timer_interval;
|
||||
|
||||
char indicator[4] = {'|', '/', '-', '\\'};
|
||||
@ -27,24 +26,24 @@ private:
|
||||
|
||||
public:
|
||||
// Zeitgeber initialisieren.
|
||||
PIT (int us) {
|
||||
interval (us);
|
||||
PIT(int us) {
|
||||
this->interval(us);
|
||||
}
|
||||
|
||||
|
||||
// Konfiguriertes Zeitintervall auslesen.
|
||||
int interval () {
|
||||
int interval() {
|
||||
return timer_interval;
|
||||
}
|
||||
|
||||
|
||||
// Zeitintervall in Mikrosekunden, nachdem periodisch ein Interrupt
|
||||
//erzeugt werden soll.
|
||||
void interval (int us);
|
||||
void interval(int us);
|
||||
|
||||
// Aktivierung der Unterbrechungen fuer den Zeitgeber
|
||||
void plugin ();
|
||||
|
||||
void plugin();
|
||||
|
||||
// Unterbrechnungsroutine des Zeitgebers.
|
||||
void trigger ();
|
||||
void trigger();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -8,64 +8,59 @@
|
||||
* Autor: Michael Schoettner, HHU, 18.3.2017 *
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#include "devices/VESA.h"
|
||||
#include "kernel/BIOS.h"
|
||||
#include "kernel/Globals.h"
|
||||
|
||||
|
||||
// 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
|
||||
|
||||
unsigned short Xres, Yres;
|
||||
unsigned char Wchar, Ychar, planes, bpp, banks;
|
||||
unsigned char memory_model, bank_size, image_pages;
|
||||
unsigned char 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;
|
||||
|
||||
unsigned int physbase; // Adresse des Linear-Framebuffers
|
||||
unsigned int OffScreenMemOffset;
|
||||
unsigned short OffScreenMemSize;
|
||||
} __attribute__((packed));
|
||||
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
|
||||
|
||||
unsigned short Xres, Yres;
|
||||
unsigned char Wchar, Ychar, planes, bpp, banks;
|
||||
unsigned char memory_model, bank_size, image_pages;
|
||||
unsigned char 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;
|
||||
|
||||
unsigned int physbase; // Adresse des Linear-Framebuffers
|
||||
unsigned int OffScreenMemOffset;
|
||||
unsigned short OffScreenMemSize;
|
||||
} __attribute__((packed));
|
||||
|
||||
// Informationen ueber die Grafikkarte
|
||||
// (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
|
||||
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
|
||||
} __attribute__((packed));
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: VESA::initTextMode *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Schalter in den Text-Modus 80x25 Zeichen. *
|
||||
*****************************************************************************/
|
||||
void VESA::initTextMode() {
|
||||
BC_params->AX = 0x4f02; // SVFA BIOS, init mode
|
||||
BC_params->BX = 0x4003; // 80x25
|
||||
BC_params->AX = 0x4f02; // SVFA BIOS, init mode
|
||||
BC_params->BX = 0x4003; // 80x25
|
||||
bios.Int(0x10);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: VESA::initGraphicMode *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -81,29 +76,29 @@ bool VESA::initGraphicMode(unsigned short mode) {
|
||||
BC_params->ES = RETURN_MEM >> 4;
|
||||
BC_params->DI = RETURN_MEM & 0xF;
|
||||
bios.Int(0x10);
|
||||
|
||||
struct VbeInfoBlock *ib = (struct VbeInfoBlock *) RETURN_MEM;
|
||||
|
||||
|
||||
struct VbeInfoBlock* ib = (struct VbeInfoBlock*)RETURN_MEM;
|
||||
|
||||
// Signaturen pruefen
|
||||
if (BC_params->AX != 0x004F) {
|
||||
kout << "Error: VESA wird nicht unterstuetzt." << endl;
|
||||
log << ERROR << "VESA wird nicht unterstuetzt." << endl;
|
||||
return false;
|
||||
}
|
||||
if (ib->VbeSignature[0]!='V' || ib->VbeSignature[1]!='E' ||
|
||||
ib->VbeSignature[2]!='S' || ib->VbeSignature[3]!='A' ) {
|
||||
kout << "Error: VESA wird nicht unterstuetzt." << endl;
|
||||
if (ib->VbeSignature[0] != 'V' || ib->VbeSignature[1] != 'E' ||
|
||||
ib->VbeSignature[2] != 'S' || ib->VbeSignature[3] != 'A') {
|
||||
log << ERROR << "VESA wird nicht unterstuetzt." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// kout << "TotalVideoMemory: " << ((ib->TotalMemory*65536) / (1024*1024)) << " MB" << endl;
|
||||
// kout << "TotalVideoMemory: " << ((ib->TotalMemory*65536) / (1024*1024)) << " MB" << endl;
|
||||
|
||||
// Gewuenschten Grafikmodus aus Antwort suchen
|
||||
unsigned short *modePtr = (unsigned short*)( (ib->VideoModePtr[1]<<4) + ib->VideoModePtr[0]);
|
||||
for (int i=0; modePtr[i]!=0xFFFF; ++i ) {
|
||||
unsigned short* modePtr = (unsigned short*)((ib->VideoModePtr[1] << 4) + ib->VideoModePtr[0]);
|
||||
for (int i = 0; modePtr[i] != 0xFFFF; ++i) {
|
||||
// Gewuenschter Grafikmodus gefunden?
|
||||
if (modePtr[i] == mode) {
|
||||
struct VbeModeInfoBlock *minf = (struct VbeModeInfoBlock *)RETURN_MEM;
|
||||
|
||||
struct VbeModeInfoBlock* minf = (struct VbeModeInfoBlock*)RETURN_MEM;
|
||||
|
||||
// Weitere Infos ueber diesen Grafikmodus abfragen
|
||||
BC_params->AX = 0x4F01;
|
||||
BC_params->CX = mode;
|
||||
@ -112,26 +107,26 @@ bool VESA::initGraphicMode(unsigned short mode) {
|
||||
bios.Int(0x10);
|
||||
|
||||
// Text-Modi 0-3 haben keinen LFB
|
||||
if ( mode > 3 && (minf->attributes & 0x90) == 0 ) {
|
||||
kout << "Error: Grafikmodus bietet keinen linearen Framebuffer." << endl;
|
||||
if (mode > 3 && (minf->attributes & 0x90) == 0) {
|
||||
log << ERROR << "Grafikmodus bietet keinen linearen Framebuffer." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
mode_nr = mode;
|
||||
xres = minf->Xres;
|
||||
yres = minf->Yres;
|
||||
bpp = (int) minf->bpp;
|
||||
lfb = minf->physbase;
|
||||
|
||||
hfb = (unsigned int) new char [xres*yres*bpp/8];
|
||||
|
||||
bpp = (int)minf->bpp;
|
||||
lfb = minf->physbase;
|
||||
|
||||
hfb = (unsigned int)new char[xres * yres * bpp / 8];
|
||||
|
||||
// Grafikmodus einschalten
|
||||
BC_params->AX = 0x4f02; // SVFA BIOS, init mode
|
||||
BC_params->AX = 0x4f02; // SVFA BIOS, init mode
|
||||
BC_params->BX = mode;
|
||||
bios.Int(0x10);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
kout << "Error: Grafikmodus nicht gefunden." << endl;
|
||||
log << ERROR << "Grafikmodus nicht gefunden." << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -11,34 +11,30 @@
|
||||
#ifndef __VESA_include__
|
||||
#define __VESA_include__
|
||||
|
||||
|
||||
#include "devices/LFBgraphics.h"
|
||||
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
// Ausgewaehlte Grafikmodi mit Mode-Nummer
|
||||
#define MODE_640_480_16BITS 0x111
|
||||
#define MODE_640_480_24BITS 0x112
|
||||
#define MODE_800_600_16BITS 0x114
|
||||
#define MODE_800_600_24BITS 0x115
|
||||
#define MODE_1024_768_16BITS 0x117
|
||||
#define MODE_1024_768_24BITS 0x118
|
||||
|
||||
#define MODE_640_480_16BITS 0x111
|
||||
#define MODE_640_480_24BITS 0x112
|
||||
#define MODE_800_600_16BITS 0x114
|
||||
#define MODE_800_600_24BITS 0x115
|
||||
#define MODE_1024_768_16BITS 0x117
|
||||
#define MODE_1024_768_24BITS 0x118
|
||||
|
||||
class VESA : public LFBgraphics {
|
||||
|
||||
private:
|
||||
int mode_nr; // Nummer des Modus
|
||||
|
||||
VESA (const VESA ©); // Verhindere Kopieren
|
||||
int mode_nr; // Nummer des Modus
|
||||
Logger log;
|
||||
|
||||
VESA(const VESA& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
VESA () {}
|
||||
|
||||
VESA() : log("VESA") {}
|
||||
|
||||
// Bestimmten Grafikmodus einschalten
|
||||
bool initGraphicMode (unsigned short mode);
|
||||
bool initGraphicMode(unsigned short mode);
|
||||
void initTextMode();
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@ -48,8 +48,6 @@ extern Scheduler scheduler;
|
||||
|
||||
extern SerialOut serial;
|
||||
|
||||
constexpr bool DEBUG = false;
|
||||
|
||||
extern unsigned int total_mem; // RAM total
|
||||
extern unsigned long systime; // wird all 10ms hochgezaehlt
|
||||
|
||||
|
||||
@ -160,10 +160,10 @@ void pg_init() {
|
||||
// sodass genau der physikalische Adressraum abgedeckt ist?
|
||||
num_pages = total_mem / (4096 * 1024);
|
||||
|
||||
kout << "pg_init: " << total_mem << endl;
|
||||
|
||||
kout << " total_mem: " << total_mem << endl;
|
||||
kout << " #pages: " << total_mem / (4096 * 1024) << endl;
|
||||
Logger log("Paging"); // This is only called one time
|
||||
log << INFO << "pg_init: " << total_mem << endl;
|
||||
log << INFO << " total_mem: " << total_mem << endl;
|
||||
log << INFO << " #pages: " << total_mem / (4096 * 1024) << endl;
|
||||
|
||||
//
|
||||
// Aufbau des Page-Directory
|
||||
|
||||
@ -52,6 +52,8 @@
|
||||
#ifndef __Paging_include__
|
||||
#define __Paging_include__
|
||||
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
// Externe Funktionen in startup.asm
|
||||
extern "C" {
|
||||
void paging_on(unsigned int* p_pdir); // Paging einschalten
|
||||
|
||||
@ -25,7 +25,7 @@ void BumpAllocator::init() {
|
||||
this->allocations = 0;
|
||||
this->next = (unsigned char*)heap_start;
|
||||
|
||||
if constexpr (DEBUG) { kout << "Initialized Bump Allocator" << endl; }
|
||||
log << INFO << "Initialized Bump Allocator" << endl;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -51,10 +51,10 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
if constexpr (DEBUG) { kout << "Requested " << hex << req_size << " Bytes" << endl; }
|
||||
log << DEBUG << "Requested " << hex << req_size << " Bytes" << endl;
|
||||
|
||||
if (req_size + (unsigned int)this->next > this->heap_end) {
|
||||
if constexpr (DEBUG) { kout << " - More memory requested than available :(" << endl; }
|
||||
log << ERROR << " - More memory requested than available :(" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
this->next = (unsigned char*)((unsigned int)this->next + req_size);
|
||||
this->allocations = this->allocations + 1;
|
||||
|
||||
if constexpr (DEBUG) { kout << " - Allocated " << hex << req_size << " Bytes." << endl; }
|
||||
log << TRACE << " - Allocated " << hex << req_size << " Bytes." << endl;
|
||||
|
||||
return allocated;
|
||||
}
|
||||
@ -73,5 +73,5 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
||||
* Beschreibung: Nicht implementiert. *
|
||||
*****************************************************************************/
|
||||
void BumpAllocator::free(void* ptr) {
|
||||
if constexpr (DEBUG) { kout << " mm_free: ptr= " << hex << (unsigned int)ptr << ", not supported" << endl; }
|
||||
log << ERROR << " mm_free: ptr= " << hex << (unsigned int)ptr << ", not supported" << endl;
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#define __BumpAllocator_include__
|
||||
|
||||
#include "kernel/Allocator.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
class BumpAllocator : Allocator {
|
||||
|
||||
@ -20,10 +21,12 @@ private:
|
||||
unsigned char* next;
|
||||
unsigned int allocations;
|
||||
|
||||
Logger log;
|
||||
|
||||
BumpAllocator(Allocator& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
public:
|
||||
BumpAllocator() {}; // Allocator() called implicitely in C++
|
||||
BumpAllocator() : log("BMP-Alloc") {}; // Allocator() called implicitely in C++
|
||||
|
||||
void init() override;
|
||||
void dump_free_memory() override;
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
|
||||
#include "kernel/allocator/LinkedListAllocator.h"
|
||||
#include "kernel/Globals.h"
|
||||
#include "user/lib/Logger.h"
|
||||
#include <stddef.h>
|
||||
|
||||
// I don't order the list by size so that the block order corresponds to the location in memory
|
||||
@ -37,7 +38,7 @@ void LinkedListAllocator::init() {
|
||||
this->free_start->size = this->heap_size - sizeof(free_block_t);
|
||||
this->free_start->next = this->free_start; // Only one block, points to itself
|
||||
|
||||
if constexpr (DEBUG) { kout << "Initialized LinkedList Allocator" << endl; }
|
||||
log << INFO << "Initialized LinkedList Allocator" << endl;
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -75,10 +76,10 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
// NOTE: next pointer zeigt auf headeranfang, returned wird zeiger auf anfang des nutzbaren freispeichers
|
||||
|
||||
if constexpr (DEBUG) { kout << "Requested " << hex << req_size << " Bytes" << endl; }
|
||||
log << DEBUG << "Requested " << hex << req_size << " Bytes" << endl;
|
||||
|
||||
if (this->free_start == NULL) {
|
||||
if constexpr (DEBUG) { kout << " - No free memory remaining :(" << endl; }
|
||||
log << ERROR << " - No free memory remaining :(" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -86,7 +87,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
unsigned int req_size_diff = (BASIC_ALIGN - req_size % BASIC_ALIGN) % BASIC_ALIGN;
|
||||
unsigned int rreq_size = req_size + req_size_diff;
|
||||
if (req_size_diff > 0) {
|
||||
if constexpr (DEBUG) { kout << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl; }
|
||||
log << TRACE << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl;
|
||||
}
|
||||
|
||||
free_block_t* current = this->free_start;
|
||||
@ -117,7 +118,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
// Next-fit
|
||||
this->free_start = new_next;
|
||||
|
||||
if constexpr (DEBUG) { kout << " - Allocated " << hex << rreq_size << " Bytes with cutting" << endl; }
|
||||
log << TRACE << " - Allocated " << hex << rreq_size << " Bytes with cutting" << endl;
|
||||
} else {
|
||||
// Block too small to be cut, allocate whole block
|
||||
|
||||
@ -125,11 +126,11 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
this->free_start = current->next; // Pointer keeps pointing to current if last block
|
||||
if (this->free_start == current) {
|
||||
// No free block remaining
|
||||
if constexpr (DEBUG) { kout << " - Disabled freelist" << endl; }
|
||||
log << TRACE << " - Disabled freelist" << endl;
|
||||
this->free_start = NULL;
|
||||
}
|
||||
|
||||
if constexpr (DEBUG) { kout << " - Allocated " << hex << current->size << " Bytes without cutting" << endl; }
|
||||
log << TRACE << " - Allocated " << hex << current->size << " Bytes without cutting" << endl;
|
||||
}
|
||||
|
||||
// Block aushängen
|
||||
@ -146,7 +147,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
||||
current = current->next;
|
||||
} while (current != this->free_start); // Stop when arriving at the first block again
|
||||
|
||||
if constexpr (DEBUG) { kout << " - More memory requested than available :(" << endl; }
|
||||
log << ERROR << " - More memory requested than available :(" << endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -159,7 +160,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
if constexpr (DEBUG) { kout << "Freeing " << hex << (unsigned int)ptr << endl; }
|
||||
log << DEBUG << "Freeing " << hex << (unsigned int)ptr << endl;
|
||||
|
||||
free_block_t* block_start = (free_block_t*)((unsigned int)ptr - sizeof(free_block_t));
|
||||
|
||||
@ -170,8 +171,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
block_start->allocated = false;
|
||||
block_start->next = block_start;
|
||||
|
||||
if constexpr (DEBUG) { kout << " - Enabling freelist with one block" << endl; }
|
||||
|
||||
log << TRACE << " - Enabling freelist with one block" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -201,7 +201,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
// Try to merge forward ========================================================================
|
||||
if (next_block == next_free) {
|
||||
if constexpr (DEBUG) { kout << " - Merging block forward" << endl; }
|
||||
log << TRACE << " - Merging block forward" << endl;
|
||||
|
||||
// Current and next adjacent block can be merged
|
||||
// [previous_free | previous_free_next | <> | block_start | next_free]
|
||||
@ -220,7 +220,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
if (this->free_start == next_free) {
|
||||
// next_free is now invalid after merge
|
||||
if constexpr (DEBUG) { kout << " - Moving freelist start to " << hex << (unsigned int)block_start << endl; }
|
||||
log << TRACE << " - Moving freelist start to " << hex << (unsigned int)block_start << endl;
|
||||
this->free_start = block_start;
|
||||
}
|
||||
} else {
|
||||
@ -236,7 +236,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
// Try to merge backward =====================================================================
|
||||
if (previous_free_next == block_start) {
|
||||
if constexpr (DEBUG) { kout << " - Merging block backward" << endl; }
|
||||
log << TRACE << " - Merging block backward" << endl;
|
||||
|
||||
// Current and previous adjacent block can be merged
|
||||
// [previous_free | block_start]
|
||||
@ -249,7 +249,7 @@ void LinkedListAllocator::free(void* ptr) {
|
||||
|
||||
if (this->free_start == block_start) {
|
||||
// block_start is now invalid after merge
|
||||
if constexpr (DEBUG) { kout << " - Moving freelist start to " << hex << (unsigned int)previous_free << endl; }
|
||||
log << TRACE << " - Moving freelist start to " << hex << (unsigned int)previous_free << endl;
|
||||
this->free_start = previous_free;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#define __LinkedListAllocator_include__
|
||||
|
||||
#include "kernel/Allocator.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
// Format eines freien Blocks, 4 + 4 + 4 Byte
|
||||
typedef struct free_block {
|
||||
@ -28,21 +29,21 @@ typedef struct free_block {
|
||||
} free_block_t;
|
||||
|
||||
class LinkedListAllocator : Allocator {
|
||||
|
||||
private:
|
||||
// freie Bloecke werden verkettet
|
||||
struct free_block* free_start;
|
||||
|
||||
LinkedListAllocator(Allocator& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
// NOTE: I added this
|
||||
// Traverses the whole list forward till previous block is reached.
|
||||
// This can only be called on free blocks as allocated blocks
|
||||
// aren't reachable from the freelist.
|
||||
static struct free_block* find_previous_block(struct free_block*);
|
||||
|
||||
Logger log;
|
||||
|
||||
public:
|
||||
LinkedListAllocator() {}
|
||||
LinkedListAllocator() : log("LL-Alloc") {}
|
||||
|
||||
void init() override;
|
||||
void dump_free_memory() override;
|
||||
|
||||
@ -33,6 +33,9 @@ void int_disp(unsigned int vector) {
|
||||
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
// 32 = Timer Interrupt
|
||||
// kout << "Interrupt: " << dec << vector << endl;
|
||||
|
||||
if (vector < 32) {
|
||||
bs_dump(vector);
|
||||
cpu.halt();
|
||||
@ -45,17 +48,6 @@ void int_disp(unsigned int vector) {
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Konstruktor: IntDispatcher::IntDispatcher *
|
||||
*---------------------------------------------------------------------------*
|
||||
* Beschreibung: Initialisierung der ISR map mit einer Default-ISR. *
|
||||
*****************************************************************************/
|
||||
IntDispatcher::IntDispatcher() {
|
||||
for (unsigned int slot = 0; slot < size; slot++) {
|
||||
map[slot] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
* Methode: IntDispatcher::assign *
|
||||
*---------------------------------------------------------------------------*
|
||||
@ -72,12 +64,12 @@ int IntDispatcher::assign(unsigned int vector, ISR& isr) {
|
||||
/* hier muss Code eingefuegt werden */
|
||||
|
||||
if (vector >= this->size) {
|
||||
if constexpr (DEBUG) { kout << "Invalid vector number when assigning" << endl; }
|
||||
log << ERROR << "Invalid vector number when assigning" << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
this->map[vector] = &isr;
|
||||
if constexpr (DEBUG) { kout << "Registered ISR for vector " << dec << vector << endl; }
|
||||
log << INFO << "Registered ISR for vector " << dec << vector << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -103,7 +95,7 @@ int IntDispatcher::report(unsigned int vector) {
|
||||
ISR* isr = this->map[vector];
|
||||
|
||||
if (isr == 0) {
|
||||
if constexpr (DEBUG) { kout << "No ISR registered for vector " << vector << endl; }
|
||||
log << ERROR << "No ISR registered for vector " << vector << endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -14,12 +14,15 @@
|
||||
#define __IntDispatcher_include__
|
||||
|
||||
#include "kernel/interrupts/ISR.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
class IntDispatcher {
|
||||
|
||||
private:
|
||||
IntDispatcher(const IntDispatcher& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
Logger log;
|
||||
|
||||
enum { size = 256 };
|
||||
ISR* map[size];
|
||||
|
||||
@ -32,7 +35,11 @@ public:
|
||||
};
|
||||
|
||||
// Initialisierung der ISR map mit einer Default-ISR.
|
||||
IntDispatcher();
|
||||
IntDispatcher() : log("IntDis") {
|
||||
for (unsigned int slot = 0; slot < size; slot++) {
|
||||
map[slot] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Registrierung einer ISR. (Rueckgabewert: 0 = Erfolg, -1 = Fehler)
|
||||
int assign(unsigned int vector, ISR& isr);
|
||||
|
||||
@ -55,8 +55,8 @@ void Scheduler::ready(Thread* that) {
|
||||
// Thread-Wechsel durch PIT verhindern
|
||||
cpu.disable_int();
|
||||
this->ready_queue.insert(that);
|
||||
kout << "Scheduler :: Adding to ready_queue" << endl;
|
||||
this->ready_queue.print();
|
||||
log << TRACE << "Scheduler :: Adding to ready_queue" << endl;
|
||||
this->ready_queue.print(log << TRACE);
|
||||
cpu.enable_int();
|
||||
}
|
||||
|
||||
@ -75,8 +75,8 @@ void Scheduler::exit() {
|
||||
// Thread-Wechsel durch PIT verhindern
|
||||
cpu.disable_int();
|
||||
Thread& next = *(Thread*)this->ready_queue.remove_first();
|
||||
kout << "Scheduler :: Exiting thread" << endl;
|
||||
this->ready_queue.print();
|
||||
log << TRACE << "Scheduler :: Exiting thread" << endl;
|
||||
this->ready_queue.print(log << TRACE);
|
||||
this->dispatch(next);
|
||||
|
||||
// Interrupts werden in Thread_switch in Thread.asm wieder zugelassen
|
||||
@ -101,8 +101,8 @@ void Scheduler::kill(Thread* that) {
|
||||
// Thread-Wechsel durch PIT verhindern
|
||||
cpu.disable_int();
|
||||
this->ready_queue.remove(that);
|
||||
kout << "Scheduler :: Killing thread" << endl;
|
||||
this->ready_queue.print();
|
||||
log << TRACE << "Scheduler :: Killing thread" << endl;
|
||||
this->ready_queue.print(log << TRACE);
|
||||
cpu.enable_int();
|
||||
}
|
||||
|
||||
@ -125,8 +125,8 @@ void Scheduler::yield() {
|
||||
cpu.disable_int();
|
||||
this->ready_queue.insert(this->get_active());
|
||||
Thread& next = *(Thread*)this->ready_queue.remove_first();
|
||||
kout << "Scheduler :: Yield" << endl;
|
||||
this->ready_queue.print();
|
||||
log << TRACE << "Scheduler :: Yield" << endl;
|
||||
this->ready_queue.print(log << TRACE);
|
||||
this->dispatch(next);
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
#include "lib/Queue.h"
|
||||
#include "lib/SpinLock.h"
|
||||
#include "user/lib/ArrayList.h"
|
||||
#include "user/lib/Logger.h"
|
||||
|
||||
class Scheduler : public Dispatcher {
|
||||
private:
|
||||
@ -29,6 +30,8 @@ private:
|
||||
// bevor er initialisiert wurde
|
||||
bool has_idle_thread;
|
||||
|
||||
Logger log;
|
||||
|
||||
// NOTE: I would have to release the lock when switching threads but I don't know exactly how to do this
|
||||
// in the assembly function
|
||||
// SpinLock lock; // Use spinlock instead of cpu.disable_int() because it still allows preemption
|
||||
@ -39,7 +42,7 @@ private:
|
||||
ArrayList<Thread*> ready_queue;
|
||||
|
||||
public:
|
||||
Scheduler() : has_idle_thread(false) {}
|
||||
Scheduler() : has_idle_thread(false), log("SCHED") {}
|
||||
|
||||
void init() {
|
||||
this->ready_queue.init();
|
||||
|
||||
@ -68,7 +68,7 @@ void OutStream::flush() {
|
||||
//
|
||||
// Zeichen und Zeichenketten in Stream ausgeben
|
||||
//
|
||||
// NOTE: The implementations now resides in the OutStream.h as I switched them to templated functions
|
||||
// NOTE: The implementations now reside in the OutStream.h as I switched them to templated functions
|
||||
|
||||
//
|
||||
// Manipulatorfunktionen
|
||||
|
||||
@ -221,6 +221,7 @@ public:
|
||||
// Zeilenumbruch in Ausgabe einfuegen.
|
||||
template<typename T>
|
||||
T& endl(T& os) {
|
||||
// os << '\r';
|
||||
os << '\n';
|
||||
os.flush();
|
||||
return os;
|
||||
|
||||
@ -7,13 +7,13 @@ void ArrayListDemo::run() {
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
kout << "Removing all elements from the front" << endl;
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.remove_first();
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
// ============================================================
|
||||
|
||||
@ -22,37 +22,37 @@ void ArrayListDemo::run() {
|
||||
kout << "Add " << dec << i << endl;
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
kout << "Removing all elements from the back" << endl;
|
||||
for (unsigned int i = 0; i < 10; ++i) {
|
||||
this->list.remove_last();
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
// ============================================================
|
||||
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.insert(i);
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
kout << "Adding inside the list (at idx 0, 2, 5)" << endl;
|
||||
this->list.insert_at(10, 0);
|
||||
this->list.insert_at(10, 2);
|
||||
this->list.insert_at(10, 5);
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
kout << "Removing inside the list (at idx 0, 2, 5)" << endl;
|
||||
this->list.remove_at(0);
|
||||
this->list.remove_at(2);
|
||||
this->list.remove_at(5);
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
for (unsigned int i = 0; i < 5; ++i) {
|
||||
this->list.remove_first();
|
||||
}
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
// ============================================================
|
||||
|
||||
@ -63,7 +63,7 @@ void ArrayListDemo::run() {
|
||||
this->list.insert(1);
|
||||
this->list.insert(2);
|
||||
this->list.insert(3);
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
kout << "Starting..." << endl;
|
||||
for (unsigned int n = 0; n < 10000000; ++n) {
|
||||
@ -76,12 +76,12 @@ void ArrayListDemo::run() {
|
||||
}
|
||||
|
||||
if (n < 5) {
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
}
|
||||
}
|
||||
kout << "Finished." << endl;
|
||||
|
||||
this->list.print();
|
||||
this->list.print(kout);
|
||||
|
||||
scheduler.exit();
|
||||
}
|
||||
|
||||
@ -9,14 +9,15 @@ void PreemptiveLoopThread::run() {
|
||||
|
||||
// Saving + restoring kout position doesn't help much as preemption still occurs,
|
||||
// only LoopThreads are synchronized, so other output will be disturbed sometimes
|
||||
// kout.setpos(55, this->id);
|
||||
// kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
||||
kout.setpos(55, this->id);
|
||||
kout << fillw(3) << this->id << fillw(0) << ": " << dec << cnt++ << endl;
|
||||
|
||||
sem->v();
|
||||
}
|
||||
}
|
||||
|
||||
void PreemptiveThreadDemo::run() {
|
||||
kout << "Preemptive Thread Demo" << endl;
|
||||
kout << "Initializing Semaphore" << endl;
|
||||
Semaphore* sem = new Semaphore(1); // Create this semaphore on the heap as this thread exits itself,
|
||||
// so stack allocated objects will be lost
|
||||
|
||||
@ -5,18 +5,19 @@
|
||||
// NOTE: Implement this here as we need to include globals for printing
|
||||
|
||||
template<typename T>
|
||||
void ArrayList<T>::print() const {
|
||||
void ArrayList<T>::print(OutStream& out) const {
|
||||
if (this->buffer_pos == 0) {
|
||||
kout << "Print List (0 elements)" << endl;
|
||||
out << "Print List (0 elements)" << endl;
|
||||
return;
|
||||
}
|
||||
|
||||
kout << "Print List (" << dec << this->buffer_pos << " elements): ";
|
||||
out << "Print List (" << dec << this->buffer_pos << " elements): ";
|
||||
for (unsigned int i = 0; i < this->buffer_pos; ++i) {
|
||||
kout << dec << this->get(i) << " ";
|
||||
out << dec << this->get(i) << " ";
|
||||
}
|
||||
kout << endl;
|
||||
out << endl;
|
||||
}
|
||||
|
||||
// List all types that are used with print()
|
||||
template class ArrayList<int>;
|
||||
template class ArrayList<Thread*>;
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
// ArrayList instead, without additional effort.
|
||||
// It's also cool to use the allocator a bit more and introduce realloc because I coded that thing
|
||||
|
||||
#include "lib/OutStream.h"
|
||||
#include <cstddef>
|
||||
|
||||
// I put the whole implementation in the header because the templating makes it cumbersome to split
|
||||
@ -184,7 +185,7 @@ public:
|
||||
return this->buffer_pos;
|
||||
}
|
||||
|
||||
void print() const;
|
||||
void print(OutStream& out) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user