use DEBUG in more places
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
#include "BufferedCGA.h"
|
#include "BufferedCGA.h"
|
||||||
|
#include "kernel/Globals.h"
|
||||||
|
|
||||||
// Can't initialize in constructor as memory management already needs working CGA for output
|
// Can't initialize in constructor as memory management already needs working CGA for output
|
||||||
// NOTE: This has to be called when memorymanagement is active
|
// NOTE: This has to be called when memorymanagement is active
|
||||||
@ -7,12 +8,12 @@ void BufferedCGA::init(unsigned int pages) {
|
|||||||
this->screen_buffer = new CGA::cga_page_t;
|
this->screen_buffer = new CGA::cga_page_t;
|
||||||
|
|
||||||
if (this->scrollback_buffer == NULL || this->screen_buffer == NULL) {
|
if (this->scrollback_buffer == NULL || this->screen_buffer == NULL) {
|
||||||
this->print("Error initializing scrollback buffer\n", 39);
|
if (DEBUG) kout << "Error initializing scrollback buffer" << endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->initialized = true;
|
this->initialized = true;
|
||||||
this->print("Initialized scrollback buffer\n", 32);
|
if (DEBUG) kout << "Initialized scrollback buffer" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BufferedCGA::display_scrollback() {
|
void BufferedCGA::display_scrollback() {
|
||||||
@ -25,7 +26,7 @@ void BufferedCGA::display_scrollback() {
|
|||||||
this->scrollback_buffer->get((cga_line_t*)CGA_START, this->scrollback - 1);
|
this->scrollback_buffer->get((cga_line_t*)CGA_START, this->scrollback - 1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this->print("ScrollbackBuffer not initialized\n", 34);
|
if (DEBUG) kout << "ScrollbackBuffer not initialized" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ void BufferedCGA::scrollup() {
|
|||||||
if (this->initialized) {
|
if (this->initialized) {
|
||||||
this->scrollback_buffer->put((cga_line_t*)CGA_START);
|
this->scrollback_buffer->put((cga_line_t*)CGA_START);
|
||||||
} else {
|
} else {
|
||||||
this->print("ScrollbackBuffer not initialized\n", 34);
|
if (DEBUG) kout << "ScrollbackBuffer not initialized" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGA::scrollup();
|
CGA::scrollup();
|
||||||
@ -58,7 +59,7 @@ void BufferedCGA::clear() {
|
|||||||
this->scrollback_buffer->clear();
|
this->scrollback_buffer->clear();
|
||||||
mmem::zero<CGA::cga_page_t>(this->screen_buffer);
|
mmem::zero<CGA::cga_page_t>(this->screen_buffer);
|
||||||
} else {
|
} else {
|
||||||
this->print("ScrollbackBuffer not initialized\n", 34);
|
if (DEBUG) kout << "ScrollbackBuffer not initialized" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ void BufferedCGA::scroll_page_backward() {
|
|||||||
}
|
}
|
||||||
this->display_scrollback();
|
this->display_scrollback();
|
||||||
} else {
|
} else {
|
||||||
this->print("ScrollbackBuffer not initialized\n", 34);
|
if (DEBUG) kout << "ScrollbackBuffer not initialized" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,6 +90,6 @@ void BufferedCGA::scroll_page_forward() {
|
|||||||
}
|
}
|
||||||
this->display_scrollback();
|
this->display_scrollback();
|
||||||
} else {
|
} else {
|
||||||
this->print("ScrollbackBuffer not initialized\n", 34);
|
if (DEBUG) kout << "ScrollbackBuffer not initialized" << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,9 +25,7 @@ void BumpAllocator::init() {
|
|||||||
this->allocations = 0;
|
this->allocations = 0;
|
||||||
this->next = (unsigned char*)heap_start;
|
this->next = (unsigned char*)heap_start;
|
||||||
|
|
||||||
kout << "Initialized Bump Allocator" << endl
|
if (DEBUG) kout << "Initialized Bump Allocator" << endl;
|
||||||
<< " - Heap Start: " << hex << (unsigned int)this->heap_start
|
|
||||||
<< ", Heap End: " << hex << (unsigned int)this->heap_end << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -53,10 +51,10 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
kout << "Requested " << hex << req_size << " Bytes" << endl;
|
if (DEBUG) kout << "Requested " << hex << req_size << " Bytes" << endl;
|
||||||
|
|
||||||
if (req_size + (unsigned int)this->next > this->heap_end) {
|
if (req_size + (unsigned int)this->next > this->heap_end) {
|
||||||
kout << " - More memory requested than available :(" << endl;
|
if (DEBUG) kout << " - More memory requested than available :(" << endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +62,7 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
|||||||
this->next = (unsigned char*)((unsigned int)this->next + req_size);
|
this->next = (unsigned char*)((unsigned int)this->next + req_size);
|
||||||
this->allocations = this->allocations + 1;
|
this->allocations = this->allocations + 1;
|
||||||
|
|
||||||
kout << " - Allocated " << hex << req_size << " Bytes." << endl;
|
if (DEBUG) kout << " - Allocated " << hex << req_size << " Bytes." << endl;
|
||||||
|
|
||||||
return allocated;
|
return allocated;
|
||||||
}
|
}
|
||||||
@ -75,5 +73,5 @@ void* BumpAllocator::alloc(unsigned int req_size) {
|
|||||||
* Beschreibung: Nicht implementiert. *
|
* Beschreibung: Nicht implementiert. *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void BumpAllocator::free(void* ptr) {
|
void BumpAllocator::free(void* ptr) {
|
||||||
kout << " mm_free: ptr= " << hex << (unsigned int)ptr << ", not supported" << endl;
|
if (DEBUG) kout << " mm_free: ptr= " << hex << (unsigned int)ptr << ", not supported" << endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,11 +37,7 @@ void LinkedListAllocator::init() {
|
|||||||
this->free_start->size = this->heap_size - sizeof(free_block_t);
|
this->free_start->size = this->heap_size - sizeof(free_block_t);
|
||||||
this->free_start->next = this->free_start; // Only one block, points to itself
|
this->free_start->next = this->free_start; // Only one block, points to itself
|
||||||
|
|
||||||
kout << "Initialized LinkedList Allocator" << endl
|
if (DEBUG) kout << "Initialized LinkedList Allocator" << endl;
|
||||||
<< " - Heap Start: " << hex << (unsigned int)this->heap_start
|
|
||||||
<< ", Heap End: " << hex << (unsigned int)this->heap_end
|
|
||||||
<< ", Heap Size: " << hex << this->heap_size << endl;
|
|
||||||
kout << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
@ -79,10 +75,10 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
|||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
// NOTE: next pointer zeigt auf headeranfang, returned wird zeiger auf anfang des nutzbaren freispeichers
|
// NOTE: next pointer zeigt auf headeranfang, returned wird zeiger auf anfang des nutzbaren freispeichers
|
||||||
|
|
||||||
kout << "Requested " << hex << req_size << " Bytes" << endl;
|
if (DEBUG) kout << "Requested " << hex << req_size << " Bytes" << endl;
|
||||||
|
|
||||||
if (this->free_start == NULL) {
|
if (this->free_start == NULL) {
|
||||||
kout << " - No free memory remaining :(" << endl;
|
if (DEBUG) kout << " - No free memory remaining :(" << endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +86,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
|||||||
unsigned int req_size_diff = (BASIC_ALIGN - req_size % BASIC_ALIGN) % BASIC_ALIGN;
|
unsigned int req_size_diff = (BASIC_ALIGN - req_size % BASIC_ALIGN) % BASIC_ALIGN;
|
||||||
unsigned int rreq_size = req_size + req_size_diff;
|
unsigned int rreq_size = req_size + req_size_diff;
|
||||||
if (req_size_diff > 0) {
|
if (req_size_diff > 0) {
|
||||||
kout << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl;
|
if (DEBUG) kout << " - Rounded to word border (+" << dec << req_size_diff << " bytes)" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
free_block_t* current = this->free_start;
|
free_block_t* current = this->free_start;
|
||||||
@ -121,7 +117,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
|||||||
// Next-fit
|
// Next-fit
|
||||||
this->free_start = new_next;
|
this->free_start = new_next;
|
||||||
|
|
||||||
kout << " - Allocated " << hex << rreq_size << " Bytes with cutting" << endl;
|
if (DEBUG) kout << " - Allocated " << hex << rreq_size << " Bytes with cutting" << endl;
|
||||||
} else {
|
} else {
|
||||||
// Block too small to be cut, allocate whole block
|
// Block too small to be cut, allocate whole block
|
||||||
|
|
||||||
@ -129,11 +125,11 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
|||||||
this->free_start = current->next; // Pointer keeps pointing to current if last block
|
this->free_start = current->next; // Pointer keeps pointing to current if last block
|
||||||
if (this->free_start == current) {
|
if (this->free_start == current) {
|
||||||
// No free block remaining
|
// No free block remaining
|
||||||
kout << " - Disabled freelist" << endl;
|
if (DEBUG) kout << " - Disabled freelist" << endl;
|
||||||
this->free_start = NULL;
|
this->free_start = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
kout << " - Allocated " << hex << current->size << " Bytes without cutting" << endl;
|
if (DEBUG) kout << " - Allocated " << hex << current->size << " Bytes without cutting" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block aushängen
|
// Block aushängen
|
||||||
@ -150,7 +146,7 @@ void* LinkedListAllocator::alloc(unsigned int req_size) {
|
|||||||
current = current->next;
|
current = current->next;
|
||||||
} while (current != this->free_start); // Stop when arriving at the first block again
|
} while (current != this->free_start); // Stop when arriving at the first block again
|
||||||
|
|
||||||
kout << " - More memory requested than available :(" << endl;
|
if (DEBUG) kout << " - More memory requested than available :(" << endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +159,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
|
|
||||||
/* Hier muess Code eingefuegt werden */
|
/* Hier muess Code eingefuegt werden */
|
||||||
|
|
||||||
kout << "Freeing " << hex << (unsigned int)ptr << endl;
|
if (DEBUG) kout << "Freeing " << hex << (unsigned int)ptr << endl;
|
||||||
|
|
||||||
free_block_t* block_start = (free_block_t*)((unsigned int)ptr - sizeof(free_block_t));
|
free_block_t* block_start = (free_block_t*)((unsigned int)ptr - sizeof(free_block_t));
|
||||||
|
|
||||||
@ -174,7 +170,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
block_start->allocated = false;
|
block_start->allocated = false;
|
||||||
block_start->next = block_start;
|
block_start->next = block_start;
|
||||||
|
|
||||||
kout << " - Enabling freelist with one block" << endl;
|
if (DEBUG) kout << " - Enabling freelist with one block" << endl;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -205,7 +201,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
|
|
||||||
// Try to merge forward ========================================================================
|
// Try to merge forward ========================================================================
|
||||||
if (next_block == next_free) {
|
if (next_block == next_free) {
|
||||||
kout << " - Merging block forward" << endl;
|
if (DEBUG) kout << " - Merging block forward" << endl;
|
||||||
|
|
||||||
// Current and next adjacent block can be merged
|
// Current and next adjacent block can be merged
|
||||||
// [previous_free | previous_free_next | <> | block_start | next_free]
|
// [previous_free | previous_free_next | <> | block_start | next_free]
|
||||||
@ -224,7 +220,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
|
|
||||||
if (this->free_start == next_free) {
|
if (this->free_start == next_free) {
|
||||||
// next_free is now invalid after merge
|
// next_free is now invalid after merge
|
||||||
kout << " - Moving freelist start to " << hex << (unsigned int)block_start << endl;
|
if (DEBUG) kout << " - Moving freelist start to " << hex << (unsigned int)block_start << endl;
|
||||||
this->free_start = block_start;
|
this->free_start = block_start;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -240,7 +236,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
|
|
||||||
// Try to merge backward =====================================================================
|
// Try to merge backward =====================================================================
|
||||||
if (previous_free_next == block_start) {
|
if (previous_free_next == block_start) {
|
||||||
kout << " - Merging block backward" << endl;
|
if (DEBUG) kout << " - Merging block backward" << endl;
|
||||||
|
|
||||||
// Current and previous adjacent block can be merged
|
// Current and previous adjacent block can be merged
|
||||||
// [previous_free | block_start]
|
// [previous_free | block_start]
|
||||||
@ -253,7 +249,7 @@ void LinkedListAllocator::free(void* ptr) {
|
|||||||
|
|
||||||
if (this->free_start == block_start) {
|
if (this->free_start == block_start) {
|
||||||
// block_start is now invalid after merge
|
// block_start is now invalid after merge
|
||||||
kout << " - Moving freelist start to " << hex << (unsigned int)previous_free << endl;
|
if (DEBUG) kout << " - Moving freelist start to " << hex << (unsigned int)previous_free << endl;
|
||||||
this->free_start = previous_free;
|
this->free_start = previous_free;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ void TreeAllocator::init() {
|
|||||||
this->free_start->next = (list_block_t*)this->free_start;
|
this->free_start->next = (list_block_t*)this->free_start;
|
||||||
this->free_start->previous = (list_block_t*)this->free_start;
|
this->free_start->previous = (list_block_t*)this->free_start;
|
||||||
|
|
||||||
kout << "Initialized Tree Allocator" << endl;
|
if (DEBUG) kout << "Initialized Tree Allocator" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TreeAllocator::dump_free_memory() {
|
void TreeAllocator::dump_free_memory() {
|
||||||
@ -33,7 +33,7 @@ void TreeAllocator::dump_free_memory(tree_block_t* node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void* TreeAllocator::alloc(unsigned int req_size) {
|
void* TreeAllocator::alloc(unsigned int req_size) {
|
||||||
kout << "Requested " << dec << req_size << " Bytes" << endl;
|
if (DEBUG) kout << "Requested " << dec << req_size << " Bytes" << endl;
|
||||||
|
|
||||||
// Round to word borders + tree_block size
|
// Round to word borders + tree_block size
|
||||||
unsigned int rreq_size = req_size;
|
unsigned int rreq_size = req_size;
|
||||||
@ -52,12 +52,12 @@ void* TreeAllocator::alloc(unsigned int req_size) {
|
|||||||
// Finds smallest block that is large enough
|
// Finds smallest block that is large enough
|
||||||
tree_block_t* best_fit = this->rbt_search_bestfit(rreq_size);
|
tree_block_t* best_fit = this->rbt_search_bestfit(rreq_size);
|
||||||
if (best_fit == NULL) {
|
if (best_fit == NULL) {
|
||||||
kout << " - No block found" << endl;
|
if (DEBUG) kout << " - No block found" << endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (best_fit->allocated) {
|
if (best_fit->allocated) {
|
||||||
// Something went really wrong
|
// Something went really wrong
|
||||||
kout << " - Block already allocated :(" << endl;
|
if (DEBUG) kout << " - Block already allocated :(" << endl;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
best_fit->allocated = true;
|
best_fit->allocated = true;
|
||||||
@ -88,7 +88,7 @@ void* TreeAllocator::alloc(unsigned int req_size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TreeAllocator::free(void* ptr) {
|
void TreeAllocator::free(void* ptr) {
|
||||||
kout << "Freeing " << hex << (unsigned int)ptr << endl;
|
if (DEBUG) kout << "Freeing " << hex << (unsigned int)ptr << endl;
|
||||||
|
|
||||||
list_block_t* block = (list_block_t*)((char*)ptr - sizeof(list_block_t));
|
list_block_t* block = (list_block_t*)((char*)ptr - sizeof(list_block_t));
|
||||||
if (!block->allocated) {
|
if (!block->allocated) {
|
||||||
|
|||||||
@ -63,12 +63,12 @@ int IntDispatcher::assign(unsigned int vector, ISR& isr) {
|
|||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|
||||||
if (vector >= this->size) {
|
if (vector >= this->size) {
|
||||||
kout << "Invalid vector number when assigning" << endl;
|
if (DEBUG) kout << "Invalid vector number when assigning" << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->map[vector] = &isr;
|
this->map[vector] = &isr;
|
||||||
kout << "Registered ISR for vector " << dec << vector << endl;
|
if (DEBUG) kout << "Registered ISR for vector " << dec << vector << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -94,7 +94,7 @@ int IntDispatcher::report(unsigned int vector) {
|
|||||||
ISR* isr = this->map[vector];
|
ISR* isr = this->map[vector];
|
||||||
|
|
||||||
if (isr == 0) {
|
if (isr == 0) {
|
||||||
kout << "No ISR registered for vector " << vector << endl;
|
if (DEBUG) kout << "No ISR registered for vector " << vector << endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
21
c_os/main.cc
21
c_os/main.cc
@ -25,16 +25,17 @@ int main() {
|
|||||||
kout.init(5);
|
kout.init(5);
|
||||||
|
|
||||||
// Startmeldung
|
// Startmeldung
|
||||||
// kout << "HHUos 0.5" << endl
|
if (!DEBUG)
|
||||||
// << "=========" << endl
|
kout << "HHUos 0.5" << endl
|
||||||
// << "Unterstuetzte Funktionen:" << endl
|
<< "=========" << endl
|
||||||
// << " - Bildschirmausgaben" << endl
|
<< "Unterstuetzte Funktionen:" << endl
|
||||||
// << " - Sound ueber den PC-Lautsprecher" << endl
|
<< " - Bildschirmausgaben" << endl
|
||||||
// << " - Tastatureingaben per Abfrage" << endl
|
<< " - Sound ueber den PC-Lautsprecher" << endl
|
||||||
// << " - Einfache Heap verwaltung" << endl
|
<< " - Tastatureingaben per Abfrage" << endl
|
||||||
// << " - Tastatureingaben per Interrupt" << endl
|
<< " - Einfache Heap verwaltung" << endl
|
||||||
// << " - Koroutinen" << endl
|
<< " - Tastatureingaben per Interrupt" << endl
|
||||||
// << endl;
|
<< " - Koroutinen" << endl
|
||||||
|
<< endl;
|
||||||
|
|
||||||
// Tastatur-Unterbrechungsroutine 'einstoepseln'
|
// Tastatur-Unterbrechungsroutine 'einstoepseln'
|
||||||
/* hier muss Code eingefuegt werden */
|
/* hier muss Code eingefuegt werden */
|
||||||
|
|||||||
Reference in New Issue
Block a user