2024-07-11 08:56:52 +02:00
|
|
|
#include <kernel/tty.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <strlib.h>
|
2024-08-10 14:37:31 +02:00
|
|
|
#include <kernel/heap.h>
|
2024-07-11 08:56:52 +02:00
|
|
|
|
2024-07-16 22:51:41 +02:00
|
|
|
void print_hex_digit(uint8_t digit)
|
|
|
|
{
|
2024-07-11 08:56:52 +02:00
|
|
|
digit = digit & 0xf;
|
|
|
|
if (digit < 0xA) {
|
|
|
|
terminal_putchar(digit + 0x30);
|
|
|
|
} else {
|
|
|
|
terminal_putchar(digit + 0x41 - 0xA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-16 22:51:41 +02:00
|
|
|
void print_hex_byte(uint8_t byte)
|
|
|
|
{
|
2024-07-11 08:56:52 +02:00
|
|
|
int upper = byte >> 4;
|
|
|
|
int lower = byte & 0x0F;
|
|
|
|
|
|
|
|
print_hex_digit(upper);
|
|
|
|
print_hex_digit(lower);
|
|
|
|
}
|
2024-07-16 22:51:41 +02:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
2024-08-10 14:37:31 +02:00
|
|
|
|
|
|
|
void print_heap()
|
|
|
|
{
|
2024-08-12 16:27:53 +02:00
|
|
|
terminal_writestring("--START HEAP--\n");
|
2024-08-10 14:37:31 +02:00
|
|
|
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;
|
|
|
|
}
|
2024-08-12 16:27:53 +02:00
|
|
|
terminal_writestring("--END HEAP--\n");
|
2024-08-10 14:37:31 +02:00
|
|
|
}
|