61 lines
1.3 KiB
C
61 lines
1.3 KiB
C
#include <kernel/tty.h>
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include <strlib.h>
|
|
#include <kernel/heap.h>
|
|
|
|
void print_hex_digit(uint8_t digit)
|
|
{
|
|
digit = digit & 0xf;
|
|
if (digit < 0xA) {
|
|
terminal_putchar(digit + 0x30);
|
|
} else {
|
|
terminal_putchar(digit + 0x41 - 0xA);
|
|
}
|
|
}
|
|
|
|
void print_hex_byte(uint8_t byte)
|
|
{
|
|
int upper = byte >> 4;
|
|
int lower = byte & 0x0F;
|
|
|
|
print_hex_digit(upper);
|
|
print_hex_digit(lower);
|
|
}
|
|
|
|
void print_hex_bytes(void* bytes, size_t len)
|
|
{
|
|
uint8_t* value = bytes;
|
|
for (size_t i = len; i > 0; i--) {
|
|
print_hex_byte(value[i - 1]);
|
|
}
|
|
}
|
|
|
|
void print_heap()
|
|
{
|
|
terminal_writestring("--START HEAP--\n");
|
|
struct Heap_Block* current = global_heap.start;
|
|
|
|
while (current != 0) {
|
|
terminal_writestring("Block at: ");
|
|
print_hex_bytes(¤t, 4);
|
|
|
|
terminal_writestring("\nSize: ");
|
|
print_hex_bytes(¤t->size, 4);
|
|
|
|
terminal_writestring("\nUsed: ");
|
|
if (current->used) {
|
|
terminal_writestring("True\n");
|
|
} else {
|
|
terminal_writestring("False\n");
|
|
}
|
|
|
|
terminal_writestring("Data: ");
|
|
print_hex_bytes(¤t->data, 4);
|
|
terminal_putchar('\n');
|
|
|
|
current = current->next;
|
|
}
|
|
terminal_writestring("--END HEAP--\n");
|
|
}
|