Switch more char/short/int/long to sized type
This commit is contained in:
@ -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
|
||||
|
||||
@ -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 */
|
||||
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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));
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 */
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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:
|
||||
|
||||
@ -30,4 +30,4 @@ KeyEventManager kevman;
|
||||
SerialOut serial;
|
||||
|
||||
unsigned int total_mem; // RAM total
|
||||
unsigned long systime = 0;
|
||||
uint64_t systime = 0;
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user