diff options
Diffstat (limited to 'src/kernel/lib')
-rw-r--r-- | src/kernel/lib/data/list.c | 25 | ||||
-rw-r--r-- | src/kernel/lib/data/tree.c | 9 | ||||
-rw-r--r-- | src/kernel/lib/lib.h | 3 | ||||
-rw-r--r-- | src/kernel/lib/memory.c | 33 | ||||
-rw-r--r-- | src/kernel/lib/stdio/debug.c | 4 | ||||
-rw-r--r-- | src/kernel/lib/stdio/vprintf.c | 4 | ||||
-rw-r--r-- | src/kernel/lib/stdlib/htoa.c | 4 | ||||
-rw-r--r-- | src/kernel/lib/stdlib/itoa.c | 8 | ||||
-rw-r--r-- | src/kernel/lib/string/strdup.c | 2 |
9 files changed, 55 insertions, 37 deletions
diff --git a/src/kernel/lib/data/list.c b/src/kernel/lib/data/list.c index 7ecc950..31e6631 100644 --- a/src/kernel/lib/data/list.c +++ b/src/kernel/lib/data/list.c @@ -7,7 +7,7 @@ struct list *list_create() { - struct list *list = kcalloc(sizeof(struct list), 1); + struct list *list = calloc(sizeof(struct list), 1); return list; } @@ -29,13 +29,13 @@ void *list_remove_node(struct list *list, struct list_node *node) node->next->prev = node->prev; node->prev->next = node->next; list->size--; - kfree(node); + free(node); } return val; } struct list_node *list_insert_front(struct list *list, void *val) { - struct list_node *t = kcalloc(sizeof(struct list_node), 1); + struct list_node *t = calloc(sizeof(struct list_node), 1); list->head->prev = t; t->next = list->head; t->val = val; @@ -50,7 +50,7 @@ struct list_node *list_insert_front(struct list *list, void *val) void list_insert_back(struct list *list, void *val) { - struct list_node *t = kcalloc(sizeof(struct list_node), 1); + struct list_node *t = calloc(sizeof(struct list_node), 1); t->prev = list->tail; if (list->tail) list->tail->next = t; @@ -72,7 +72,7 @@ void *list_remove_front(struct list *list) list->head = t->next; if (list->head) list->head->prev = NULL; - kfree(t); + free(t); list->size--; return val; } @@ -86,7 +86,7 @@ void *list_remove_back(struct list *list) list->tail = t->prev; if (list->tail) list->tail->next = NULL; - kfree(t); + free(t); list->size--; return val; } @@ -170,14 +170,14 @@ void list_destroy(struct list *list) while (node != NULL) { struct list_node *save = node; node = node->next; - kfree(save); + free(save); } - kfree(list); + free(list); } void listnode_destroy(struct list_node *node) { - kfree(node); + free(node); } // Conversion @@ -199,13 +199,13 @@ struct list *str_split(const char *str, const char *delim, u32 *numtokens) if (numtokens) (*numtokens)++; } - kfree(s); + free(s); return ret_list; } char *list_to_str(struct list *list, const char *delim) { - char *ret = kmalloc(256); + char *ret = malloc(256); memset(ret, 0, 256); int len = 0, ret_len = 256; while (list_size(list) > 0) { @@ -213,8 +213,7 @@ char *list_to_str(struct list *list, const char *delim) int len_temp = strlen(temp); if (len + len_temp + 1 + 1 > ret_len) { ret_len = ret_len * 2; - /* ret = krealloc(ret, ret_len); */ - ret = kmalloc(ret_len); + ret = realloc(ret, ret_len); len = len + len_temp + 1; } strcat(ret, delim); diff --git a/src/kernel/lib/data/tree.c b/src/kernel/lib/data/tree.c index 65b8433..9758ec1 100644 --- a/src/kernel/lib/data/tree.c +++ b/src/kernel/lib/data/tree.c @@ -1,15 +1,16 @@ #include <lib/data.h> #include <memory/alloc.h> +#include <stddef.h> #include <stdint.h> struct tree *tree_create() { - return (struct tree *)kcalloc(sizeof(struct tree), 1); + return (struct tree *)calloc(sizeof(struct tree), 1); } struct tree_node *treenode_create(void *value) { - struct tree_node *n = kcalloc(sizeof(struct tree_node), 1); + struct tree_node *n = calloc(sizeof(struct tree_node), 1); n->value = value; n->children = list_create(); return n; @@ -17,7 +18,7 @@ struct tree_node *treenode_create(void *value) struct tree_node *tree_insert(struct tree *tree, struct tree_node *subroot, void *value) { - struct tree_node *treenode = kcalloc(sizeof(struct tree_node), 1); + struct tree_node *treenode = calloc(sizeof(struct tree_node), 1); treenode->children = list_create(); treenode->value = value; @@ -62,7 +63,7 @@ void tree_remove(struct tree *tree, struct tree_node *remove_node) struct tree_node *parent = tree_find_parent(tree, remove_node, &child_index); if (parent != NULL) { struct tree_node *freethis = list_remove_by_index(parent->children, child_index); - kfree(freethis); + free(freethis); } } diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h index 921e575..6f2c04d 100644 --- a/src/kernel/lib/lib.h +++ b/src/kernel/lib/lib.h @@ -33,11 +33,10 @@ void *memset(void *dest, char val, u32 count); int memcmp(const void *a_ptr, const void *b_ptr, u32 size); void memory_info_init(struct multiboot_tag_basic_meminfo *tag); - void memory_mmap_init(struct multiboot_tag_mmap *tag); +int memory_init(u32 multiboot_address); void memory_print(); - u32 memory_get_all(); #endif
\ No newline at end of file diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c index 61b1414..0f3cb34 100644 --- a/src/kernel/lib/memory.c +++ b/src/kernel/lib/memory.c @@ -58,10 +58,10 @@ u32 memory_get_free() void memory_print() { // TODO: Fix multiboot mem lower/upper - /*if (meminfo != NULL) { + if (meminfo != NULL) { info("Mem lower: 0x%x", meminfo->mem_lower); info("Mem upper: 0x%x", meminfo->mem_upper); - }*/ + } info("Total memory found: %dMiB", (memory_get_all() >> 10) + 1); info("Total free memory: %dMiB", (memory_get_free() >> 10) + 1); } @@ -76,18 +76,17 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag) u32 sum = 0; struct multiboot_mmap_entry *mmap; - for (mmap = ((struct multiboot_tag_mmap *)tag)->entries; - (multiboot_u8 *)mmap < (multiboot_u8 *)tag + tag->size; + for (mmap = ((struct multiboot_tag_mmap *)tag)->entries; (u8 *)mmap < (u8 *)tag + tag->size; mmap = (multiboot_memory_map_t *)((u32)mmap + ((struct multiboot_tag_mmap *)tag)->entry_size)) { if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { debug("Found free memory"); - /* paging_set_present(mmap->addr, mmap->len >> 12); */ + paging_set_present(mmap->addr, mmap->len >> 12); sum += mmap->len; } else if (mmap->type == MULTIBOOT_MEMORY_RESERVED) { debug("Found reserved memory"); - /* paging_set_present(mmap->addr, mmap->len >> 12); */ - /* paging_set_used(mmap->addr, mmap->len >> 12); */ + paging_set_present(mmap->addr, mmap->len >> 12); + paging_set_used(mmap->addr, mmap->len >> 12); } else if (mmap->type == MULTIBOOT_MEMORY_ACPI_RECLAIMABLE) { debug("Found ACPI reclaimable memory"); } else if (mmap->type == MULTIBOOT_MEMORY_NVS) { @@ -97,4 +96,24 @@ void memory_mmap_init(struct multiboot_tag_mmap *tag) } } total = sum >> 10; // I want kb +} + +int memory_init(u32 multiboot_address) +{ + int ret = 0; + struct multiboot_tag *tag; + + for (tag = (struct multiboot_tag *)(multiboot_address + 8); + tag->type != MULTIBOOT_TAG_TYPE_END; + tag = (struct multiboot_tag *)((u8 *)tag + ((tag->size + 7) & ~7))) { + if (tag->type == MULTIBOOT_TAG_TYPE_BASIC_MEMINFO) { + info("Got memory info"); + memory_info_init((struct multiboot_tag_basic_meminfo *)tag); + } else if (tag->type == MULTIBOOT_TAG_TYPE_MMAP) { + info("Got memory map"); + memory_mmap_init((struct multiboot_tag_mmap *)tag); + ret = 1; + } + } + return ret; }
\ No newline at end of file diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c index 74eb594..3acb987 100644 --- a/src/kernel/lib/stdio/debug.c +++ b/src/kernel/lib/stdio/debug.c @@ -33,12 +33,12 @@ void serial_vprintf(const char *fmt, va_list args) } else if (buff == 'x') { char *p = htoa((u32)va_arg(args, int)); serial_print(p); - kfree(p); + free(p); readyToFormat = 0; } else if (buff == 'd') { char *p = itoa(va_arg(args, int)); serial_print(p); - kfree(p); + free(p); readyToFormat = 0; } else if (buff == 'c') { serial_put((char)va_arg(args, int)); diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c index 37723b2..4c0c432 100644 --- a/src/kernel/lib/stdio/vprintf.c +++ b/src/kernel/lib/stdio/vprintf.c @@ -33,12 +33,12 @@ void vprintf(const char *fmt, va_list args) } else if (buff == 'x') { char *p = htoa((u32)va_arg(args, int)); _puts(p); - kfree(p); + free(p); readyToFormat = 0; } else if (buff == 'd') { char *p = itoa(va_arg(args, int)); _puts(p); - kfree(p); + free(p); readyToFormat = 0; } else if (buff == 'c') { putch((char)va_arg(args, int)); diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c index c4dbd5e..9cf57cc 100644 --- a/src/kernel/lib/stdlib/htoa.c +++ b/src/kernel/lib/stdlib/htoa.c @@ -6,7 +6,7 @@ static const char HTOA_TABLE[] = "0123456789ABCDEF"; char *htoa(u32 n) { - char *ret = (char *)kmalloc(10); + char *ret = (char *)malloc(10); int i = 0; while (n) { @@ -23,7 +23,7 @@ char *htoa(u32 n) ret[i] = 0; char *aux = strdup(ret); - kfree(ret); + free(ret); ret = aux; strinv(ret); diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c index b4a9db1..2020ca6 100644 --- a/src/kernel/lib/stdlib/itoa.c +++ b/src/kernel/lib/stdlib/itoa.c @@ -9,7 +9,7 @@ static const char ITOA_TABLE[] = "0123456789"; char *itoa(int n) { if (!n) { - char *ret = (char *)kmalloc(2); + char *ret = (char *)malloc(2); ret[0] = '0'; ret[1] = 0; return ret; @@ -22,7 +22,7 @@ char *itoa(int n) for (sz = 0; n % pow(10, sz) != n; sz++) { } - char *ret = (char *)kmalloc((u32)(sz + 1)); + char *ret = (char *)malloc((u32)(sz + 1)); for (int i = 0; i < sz; i++) { int digit = (n % pow(10, i + 1)) / pow(10, i); @@ -31,11 +31,11 @@ char *itoa(int n) ret[sz] = 0; if (negative) { - char *aux = (char *)kmalloc((u32)(sz + 2)); + char *aux = (char *)malloc((u32)(sz + 2)); strcpy(aux, ret); aux[sz] = '-'; aux[sz + 1] = 0; - kfree(ret); + free(ret); ret = aux; } diff --git a/src/kernel/lib/string/strdup.c b/src/kernel/lib/string/strdup.c index 00bb863..3b138e8 100644 --- a/src/kernel/lib/string/strdup.c +++ b/src/kernel/lib/string/strdup.c @@ -4,7 +4,7 @@ char *strdup(const char *orig) { u32 s_orig = strlen(orig); - char *ret = (char *)kmalloc(s_orig + 1); + char *ret = (char *)malloc(s_orig + 1); strcpy(ret, orig); return ret; }
\ No newline at end of file |