feat: added printf

This commit is contained in:
2021-02-06 16:44:35 +01:00
parent a4651ca9d9
commit 7ff33d611c
5 changed files with 129 additions and 56 deletions

View File

@@ -3,9 +3,8 @@
//
#include <types.h>
#include <kprint.h>
#include <mem/mem.h>
#include <libc/libc.h>
#include <libc/kprintf.h>
#define MEMMAP_ENTRIES 16
@@ -28,22 +27,12 @@
extern void *kernel_start;
//extern void *kernel_end;
char *msg_index = "Idx: ";
char *msg_addr = "Address: ";
char *msg_len = "Length: ";
char *msg_type = "Type: ";
char *msg_nl = "\n";
char *msg_malloc_num_entries_avail = "Malloc avail entries: ";
char *msg_malloc_num_entries_used = "Malloc used entries: ";
typedef struct {
void *address;
u32 length;
u32 type;
} __attribute((packed)) mmap_entry;
char *msg_lu = "0123456789ABCDEF";
int malloc_entries = 0;
int malloc_used = 0;
@@ -149,7 +138,7 @@ void *malloc(unsigned int size) {
}
malloc_used++;
current_map->type = MALLOC_TYPE_USED;
return ((void*)current_map) + sizeof(malloc_map);
return ((void *) current_map) + sizeof(malloc_map);
malloc_find_next:
current_map = current_map->next;
@@ -168,21 +157,9 @@ void free(void *mem) {
};
void print_int(int val, int base) {
char tmp_str[32];
memset(tmp_str, 0, 32);
itoa(val, tmp_str, base);
kprint(tmp_str);
}
void print_malloc_info() {
kprint(msg_malloc_num_entries_avail);
print_int(malloc_entries, 10);
kprint(msg_nl);
kprint(msg_malloc_num_entries_used);
print_int(malloc_used, 10);
kprint(msg_nl);
printf("Malloc avail entries: %d\n"
"Malloc used entries: %d\n", malloc_entries, malloc_used);
}
@@ -191,18 +168,9 @@ void print_mmap_info() {
if (memmap[i].type == 0) {
break;
}
kprint(msg_index);
print_int(i, 10);
kprint(msg_nl);
kprint(msg_addr);
print_int((int) memmap[i].address, 16);
kprint(msg_nl);
kprint(msg_len);
print_int(memmap[i].length, 16);
kprint(msg_nl);
kprint(msg_type);
print_int(memmap[i].type, 10);
kprint(msg_nl);
kprint(msg_nl);
printf("Idx: %d\n"
"Address: %8x\n"
"Length: %8x\n"
"Type: %d\n\n", i, memmap[i].address, memmap[i].length, memmap[i].type);
}
}