diff options
Diffstat (limited to 'src/kernel/lib')
31 files changed, 0 insertions, 1138 deletions
diff --git a/src/kernel/lib/data.h b/src/kernel/lib/data.h deleted file mode 100644 index 709ca6f..0000000 --- a/src/kernel/lib/data.h +++ /dev/null @@ -1,94 +0,0 @@ -#ifndef MELVIX_DATA_H -#define MELVIX_DATA_H - -#include <stdint.h> - -// LIST - -struct list_node { - struct list_node *prev; - struct list_node *next; - void *val; -}; - -struct list { - struct list_node *head; - struct list_node *tail; - u32 size; -}; - -#define foreach(t, list) for (struct list_node *t = list->head; t != NULL; t = t->next) - -struct list *list_create(); - -u32 list_size(struct list *list); - -struct list_node *list_insert_front(struct list *list, void *val); - -void list_insert_back(struct list *list, void *val); - -void *list_remove_node(struct list *list, struct list_node *node); - -void *list_remove_front(struct list *list); - -void *list_remove_back(struct list *list); - -void list_push(struct list *list, void *val); - -struct list_node *list_pop(struct list *list); - -void list_enqueue(struct list *list, void *val); - -struct list_node *list_dequeue(struct list *list); - -void *list_peek_front(struct list *list); - -void *list_peek_back(struct list *list); - -void list_destroy(struct list *list); - -void listnode_destroy(struct list_node *node); - -int list_contain(struct list *list, void *val); - -struct list_node *list_get_node_by_index(struct list *list, int index); - -void *list_remove_by_index(struct list *list, int index); - -struct list *str_split(const char *str, const char *delim, u32 *numtokens); -char *list_to_str(struct list *list, const char *delim); - -// Tree - -struct tree_node { - struct list *children; - void *value; -}; - -struct tree { - struct tree_node *root; -}; - -struct tree *tree_create(); - -struct tree_node *treenode_create(void *value); - -struct tree_node *tree_insert(struct tree *tree, struct tree_node *subroot, void *value); - -struct tree_node *tree_find_parent(struct tree *tree, struct tree_node *remove_node, - int *child_index); - -struct tree_node *tree_find_parent_recur(struct tree *tree, struct tree_node *remove_node, - struct tree_node *subroot, int *child_index); - -void tree_remove(struct tree *tree, struct tree_node *remove_node); - -void tree2list_recur(struct tree_node *subroot, struct list *list); - -void tree2list(struct tree *tree, struct list *list); - -void tree2array(struct tree *tree, void **array, int *size); - -void tree2array_recur(struct tree_node *subroot, void **array, int *size); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/data/list.c b/src/kernel/lib/data/list.c deleted file mode 100644 index 31e6631..0000000 --- a/src/kernel/lib/data/list.c +++ /dev/null @@ -1,223 +0,0 @@ -#include <lib/data.h> -#include <lib/lib.h> -#include <lib/stdlib.h> -#include <memory/alloc.h> -#include <stddef.h> -#include <stdint.h> - -struct list *list_create() -{ - struct list *list = calloc(sizeof(struct list), 1); - return list; -} - -u32 list_size(struct list *list) -{ - if (!list) - return 0; - return list->size; -} - -void *list_remove_node(struct list *list, struct list_node *node) -{ - void *val = node->val; - if (list->head == node) - return list_remove_front(list); - else if (list->tail == node) - return list_remove_back(list); - else { - node->next->prev = node->prev; - node->prev->next = node->next; - list->size--; - free(node); - } - return val; -} -struct list_node *list_insert_front(struct list *list, void *val) -{ - struct list_node *t = calloc(sizeof(struct list_node), 1); - list->head->prev = t; - t->next = list->head; - t->val = val; - - if (!list->head) - list->tail = t; - - list->head = t; - list->size++; - return t; -} - -void list_insert_back(struct list *list, void *val) -{ - struct list_node *t = calloc(sizeof(struct list_node), 1); - t->prev = list->tail; - if (list->tail) - list->tail->next = t; - t->val = val; - - if (!list->head) - list->head = t; - - list->tail = t; - list->size++; -} - -void *list_remove_front(struct list *list) -{ - if (!list->head) - return NULL; - struct list_node *t = list->head; - void *val = t->val; - list->head = t->next; - if (list->head) - list->head->prev = NULL; - free(t); - list->size--; - return val; -} - -void *list_remove_back(struct list *list) -{ - if (!list->head) - return NULL; - struct list_node *t = list->tail; - void *val = t->val; - list->tail = t->prev; - if (list->tail) - list->tail->next = NULL; - free(t); - list->size--; - return val; -} - -void list_push(struct list *list, void *val) -{ - list_insert_back(list, val); -} - -struct list_node *list_pop(struct list *list) -{ - if (!list->head) - return NULL; - struct list_node *t = list->tail; - list->tail = t->prev; - if (list->tail) - list->tail->next = NULL; - list->size--; - return t; -} - -void list_enqueue(struct list *list, void *val) -{ - list_insert_front(list, val); -} - -struct list_node *list_dequeue(struct list *list) -{ - return list_pop(list); -} - -void *list_peek_front(struct list *list) -{ - if (!list->head) - return NULL; - return list->head->val; -} - -void *list_peek_back(struct list *list) -{ - if (!list->tail) - return NULL; - return list->tail->val; -} - -int list_contain(struct list *list, void *val) -{ - int idx = 0; - foreach(listnode, list) - { - if (listnode->val == val) - return idx; - idx++; - } - return -1; -} - -struct list_node *list_get_node_by_index(struct list *list, int index) -{ - if (index < 0 || index >= list_size(list)) - return NULL; - int curr = 0; - foreach(listnode, list) - { - if (index == curr) - return listnode; - curr++; - } - return NULL; -} - -void *list_remove_by_index(struct list *list, int index) -{ - struct list_node *node = list_get_node_by_index(list, index); - return list_remove_node(list, node); -} - -void list_destroy(struct list *list) -{ - struct list_node *node = list->head; - while (node != NULL) { - struct list_node *save = node; - node = node->next; - free(save); - } - free(list); -} - -void listnode_destroy(struct list_node *node) -{ - free(node); -} - -// Conversion - -struct list *str_split(const char *str, const char *delim, u32 *numtokens) -{ - struct list *ret_list = list_create(); - char *s = strdup(str); - char *token, *rest = s; - while ((token = strsep(&rest, delim)) != NULL) { - if (!strcmp(token, ".")) - continue; - if (!strcmp(token, "..")) { - if (list_size(ret_list) > 0) - list_pop(ret_list); - continue; - } - list_push(ret_list, strdup(token)); - if (numtokens) - (*numtokens)++; - } - free(s); - return ret_list; -} - -char *list_to_str(struct list *list, const char *delim) -{ - char *ret = malloc(256); - memset(ret, 0, 256); - int len = 0, ret_len = 256; - while (list_size(list) > 0) { - char *temp = list_pop(list)->val; - int len_temp = strlen(temp); - if (len + len_temp + 1 + 1 > ret_len) { - ret_len = ret_len * 2; - ret = realloc(ret, ret_len); - len = len + len_temp + 1; - } - strcat(ret, delim); - strcat(ret, temp); - } - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/data/tree.c b/src/kernel/lib/data/tree.c deleted file mode 100644 index 9758ec1..0000000 --- a/src/kernel/lib/data/tree.c +++ /dev/null @@ -1,104 +0,0 @@ -#include <lib/data.h> -#include <memory/alloc.h> -#include <stddef.h> -#include <stdint.h> - -struct tree *tree_create() -{ - return (struct tree *)calloc(sizeof(struct tree), 1); -} - -struct tree_node *treenode_create(void *value) -{ - struct tree_node *n = calloc(sizeof(struct tree_node), 1); - n->value = value; - n->children = list_create(); - return n; -} - -struct tree_node *tree_insert(struct tree *tree, struct tree_node *subroot, void *value) -{ - struct tree_node *treenode = calloc(sizeof(struct tree_node), 1); - treenode->children = list_create(); - treenode->value = value; - - if (!tree->root) { - tree->root = treenode; - return treenode; - } - list_insert_front(subroot->children, treenode); - return treenode; -} - -struct tree_node *tree_find_parent(struct tree *tree, struct tree_node *remove_node, - int *child_index) -{ - if (remove_node == tree->root) - return NULL; - return tree_find_parent_recur(tree, remove_node, tree->root, child_index); -} - -struct tree_node *tree_find_parent_recur(struct tree *tree, struct tree_node *remove_node, - struct tree_node *subroot, int *child_index) -{ - int idx; - if ((idx = list_contain(subroot->children, remove_node)) != -1) { - *child_index = idx; - return subroot; - } - foreach(child, subroot->children) - { - struct tree_node *ret = - tree_find_parent_recur(tree, remove_node, child->val, child_index); - if (ret != NULL) { - return ret; - } - } - return NULL; -} - -void tree_remove(struct tree *tree, struct tree_node *remove_node) -{ - int child_index = -1; - 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); - free(freethis); - } -} - -void tree2list_recur(struct tree_node *subroot, struct list *list) -{ - if (subroot == NULL) - return; - foreach(child, subroot->children) - { - struct tree_node *curr_treenode = (struct tree_node *)child->val; - void *curr_val = curr_treenode->value; - list_insert_back(list, curr_val); - tree2list_recur(child->val, list); - } -} - -void tree2list(struct tree *tree, struct list *list) -{ - tree2list_recur(tree->root, list); -} - -void tree2array(struct tree *tree, void **array, int *size) -{ - tree2array_recur(tree->root, array, size); -} - -void tree2array_recur(struct tree_node *subroot, void **array, int *size) -{ - if (subroot == NULL) - return; - void *curr_val = (void *)subroot->value; - array[*size] = curr_val; - *size = *size + 1; - foreach(child, subroot->children) - { - tree2array_recur(child->val, array, size); - } -}
\ No newline at end of file diff --git a/src/kernel/lib/lib.h b/src/kernel/lib/lib.h deleted file mode 100644 index 06f9eda..0000000 --- a/src/kernel/lib/lib.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef MELVIX_LIB_H -#define MELVIX_LIB_H - -#include <multiboot.h> -#include <stddef.h> -#include <stdint.h> - -/** - * Copy n data from src to dest - * @param dest The destination array pointer - * @param src The source array pointer of the data - * @param count The number of bytes to be copied (src) - * @return The modified dest pointer - */ -void *memcpy(void *dest, const void *src, u32 count); - -/** - * Replace n bytes of dest by val - * @param dest The destination array pointer - * @param val The replacing chracater - * @param count The number of times val should replace dest entry - * @return The modified dest pointer - */ -void *memset(void *dest, char val, u32 count); - -/** - * Compare the first n bytes of a and b - * @param a_ptr The first memory area pointer - * @param b_ptr The second memory area pointer - * @param size The number of bytes to be compared - * @return -1 if a < b, 0 if a = b and 1 if a > b - */ -int memcmp(const void *a_ptr, const void *b_ptr, u32 size); - -void memory_init(); - -void memory_print(); -u32 memory_get_all(); -void bss_clean(); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/math.h b/src/kernel/lib/math.h deleted file mode 100644 index 57877ad..0000000 --- a/src/kernel/lib/math.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MELVIX_MATH_H -#define MELVIX_MATH_H - -int pow(int base, int exp); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/math/pow.c b/src/kernel/lib/math/pow.c deleted file mode 100644 index 5cdcfa5..0000000 --- a/src/kernel/lib/math/pow.c +++ /dev/null @@ -1,13 +0,0 @@ -int pow(int base, int exp) -{ - if (exp < 0) - return 0; - - if (!exp) - return 1; - - int ret = base; - for (int i = 1; i < exp; i++) - ret *= base; - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/memory.c b/src/kernel/lib/memory.c deleted file mode 100644 index ef7cb78..0000000 --- a/src/kernel/lib/memory.c +++ /dev/null @@ -1,138 +0,0 @@ -#include <lib/stdio.h> -#include <memory/mmap.h> -#include <multiboot.h> -#include <stddef.h> -#include <stdint.h> -#include <system.h> - -void *memcpy(void *dest, const void *src, u32 count) -{ - const char *sp = (const char *)src; - char *dp = (char *)dest; - for (; count != 0; count--) - *dp++ = *sp++; - return dest; -} - -void *memset(void *dest, char val, u32 count) -{ - char *temp = (char *)dest; - for (; count != 0; count--) - *temp++ = val; - return dest; -} - -int memcmp(const void *a_ptr, const void *b_ptr, u32 size) -{ - const u8 *a = (const u8 *)a_ptr; - const u8 *b = (const u8 *)b_ptr; - for (u32 i = 0; i < size; i++) { - if (a[i] < b[i]) - return -1; - else if (b[i] < a[i]) - return 1; - } - return 0; -} - -// TODO: Move memory lib! -u32 total = 0; -struct multiboot_tag_basic_meminfo *meminfo = NULL; -struct multiboot_tag_mmap *mmap = NULL; - -u32 memory_get_all() -{ - if (total != 0) { - return total; - } else if (meminfo != NULL) { - return meminfo->mem_lower + meminfo->mem_upper; - } else { - warn("Got no memory info, guessing size!"); - return 42000; // This should not happen on a modern pc but well idk, 42MB? - } -} - -u32 memory_get_free() -{ - int free_memory = memory_get_all() - 42 * 4; // TODO: Fix free memory - if (free_memory < 0) - return 0; - else - return free_memory; -} - -void memory_print() -{ - // TODO: Fix multiboot mem lower/upper - 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)); - info("Total used memory: %dMiB", ((memory_get_all() - memory_get_free()) >> 10)); - info("Total free memory: %dMiB", (memory_get_free() >> 10)); -} - -void memory_info_init() -{ -} - -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; (u8 *)mmap < (u8 *)tag + tag->size; - mmap = (multiboot_memory_map_t *)((u32)mmap + - ((struct multiboot_tag_mmap *)tag)->entry_size)) { - debug("Found memory of type %d from 0x%x-0x%x: %dKiB", mmap->type, (u32)mmap->addr, - (u32)mmap->addr + (u32)mmap->len, mmap->len >> 10); - sum += mmap->len; - - // Translate to pages - if (mmap->type == MULTIBOOT_MEMORY_AVAILABLE) { - for (u32 i = 0; i < mmap->len; i += 0x1000) { - if (mmap->addr + i > 0xFFFFFFFF) - break; - mmap_address_set_free((mmap->addr + i) & 0xFFFFF000); - } - } else { - for (u32 i = 0; i < mmap->len; i += 0x1000) { - if (mmap->addr + i > 0xFFFFFFFF) - break; - mmap_address_set_used((mmap->addr + i) & 0xFFFFF000); - } - } - - total = sum >> 10; // I want kb - } -} - -void memory_init() -{ - struct multiboot_tag *tag = NULL; - - 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"); - meminfo = (struct multiboot_tag_basic_meminfo *)tag; - } else if (tag->type == MULTIBOOT_TAG_TYPE_MMAP) { - info("Got memory map"); - mmap = (struct multiboot_tag_mmap *)tag; - } - } - - assert(mmap && meminfo); - mmap_init(meminfo->mem_lower + meminfo->mem_upper); - memory_mmap_init(mmap); - mmap_init_finalize(); -} - -void bss_clean() -{ - u32 start = &bss_start; - u32 end = &kernel_end; - memset(start, 0, end - start); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio.h b/src/kernel/lib/stdio.h deleted file mode 100644 index 3318ef9..0000000 --- a/src/kernel/lib/stdio.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef MELVIX_STDIO_H -#define MELVIX_STDIO_H - -#include <stdarg.h> - -void putch(char c); - -int sprintf(char *str, const char *fmt, ...); -void vprintf(const char *fmt, va_list args); -int vsprintf(char *str, const char *fmt, va_list args); -void printf(const char *fmt, ...); - -void serial_vprintf(const char *fmt, va_list args); -void serial_printf(const char *fmt, ...); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/stdio/debug.c b/src/kernel/lib/stdio/debug.c deleted file mode 100644 index 879329e..0000000 --- a/src/kernel/lib/stdio/debug.c +++ /dev/null @@ -1,27 +0,0 @@ -#include <io/io.h> -#include <lib/lib.h> -#include <lib/stdio.h> -#include <lib/stdlib.h> -#include <stdint.h> - -void serial_print(const char *data) -{ - for (u32 i = 0; i < strlen(data); i++) - serial_put(data[i]); -} - -void serial_vprintf(const char *fmt, va_list args) -{ - char buf[1024]; - memset(buf, 0, 1024); - vsprintf(buf, fmt, args); - serial_print(buf); -} - -void serial_printf(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - serial_vprintf(fmt, args); - va_end(args); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/printf.c b/src/kernel/lib/stdio/printf.c deleted file mode 100644 index c1b08e7..0000000 --- a/src/kernel/lib/stdio/printf.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <lib/stdio.h> -#include <stdarg.h> - -void printf(const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - vprintf(fmt, args); - va_end(args); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/putch.c b/src/kernel/lib/stdio/putch.c deleted file mode 100644 index 2689ac7..0000000 --- a/src/kernel/lib/stdio/putch.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <graphics/vesa.h> - -void putch(char c) -{ - vesa_draw_char(c); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/sprintf.c b/src/kernel/lib/stdio/sprintf.c deleted file mode 100644 index 8492363..0000000 --- a/src/kernel/lib/stdio/sprintf.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <lib/stdio.h> -#include <stdarg.h> - -int sprintf(char *str, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - int ret = vsprintf(str, fmt, args); - va_end(args); - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/vprintf.c b/src/kernel/lib/stdio/vprintf.c deleted file mode 100644 index 5405309..0000000 --- a/src/kernel/lib/stdio/vprintf.c +++ /dev/null @@ -1,16 +0,0 @@ -#include <lib/lib.h> -#include <lib/stdio.h> -#include <lib/stdlib.h> -#include <stdint.h> - -// TODO: Use global formatting function -// TODO: Fix fixed buffer size -void vprintf(const char *fmt, va_list args) -{ - char buf[1024]; - memset(buf, 0, 1024); - vsprintf(buf, fmt, args); - - for (u32 i = 0; i < strlen(buf); i++) - putch(buf[i]); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdio/vsprintf.c b/src/kernel/lib/stdio/vsprintf.c deleted file mode 100644 index 61f4323..0000000 --- a/src/kernel/lib/stdio/vsprintf.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <lib/stdlib.h> -#include <stdarg.h> -#include <stdint.h> - -static void append(char *dest, char *src, int index) -{ - for (int i = index; i < strlen(src) + index; i++) - dest[i] = src[i - index]; - dest[index + strlen(src)] = 0; -} - -int vsprintf(char *str, const char *fmt, va_list args) -{ - u8 ready_to_format = 0; - - int i = 0; - char buf = 0; - char format_buffer[20] = "\0"; - - for (; *fmt; fmt++) { - if (ready_to_format) { - ready_to_format = 0; - - if (*fmt == '%') { - str[i] = '%'; - continue; - } - - buf = *fmt; - - // TODO: Improve this repetitive code - if (buf == 's') { - char *string = va_arg(args, char *); - append(str, string, i); - i = strlen(str); - } else if (buf == 'x') { - itoa_base(va_arg(args, u32), format_buffer, 16, 0); - append(str, format_buffer, i); - i = strlen(str); - } else if (buf == 'd' || buf == 'i') { - itoa_base(va_arg(args, s32), format_buffer, 10, 1); - append(str, format_buffer, i); - i = strlen(str); - } else if (buf == 'u') { - itoa_base(va_arg(args, u32), format_buffer, 10, 0); - append(str, format_buffer, i); - i = strlen(str); - } else if (buf == 'o') { - itoa_base(va_arg(args, u32), format_buffer, 8, 0); - append(str, format_buffer, i); - i = strlen(str); - } else if (buf == 'b') { - itoa_base(va_arg(args, u32), format_buffer, 2, 0); - append(str, format_buffer, i); - i = strlen(str); - } else if (buf == 'c') { - str[i] = (char)va_arg(args, int); - i++; - } - } else { - if (*fmt == '%') - ready_to_format = 1; - else { - str[i] = *fmt; - i++; - } - } - - format_buffer[0] = '\0'; - } - - return strlen(str); -}
\ No newline at end of file diff --git a/src/kernel/lib/stdlib.h b/src/kernel/lib/stdlib.h deleted file mode 100644 index cee453c..0000000 --- a/src/kernel/lib/stdlib.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef MELVIX_STDLIB_H -#define MELVIX_STDLIB_H - -#include <stdint.h> - -#ifndef MELVIX_STRING_H - -#include <lib/string.h> - -#endif - -char *itoa(int n); -char *itoa_base(int value, char *result, int base, int is_signed); - -int atoi(char *str); - -char *htoa(u32 n); - -int htoi(char *str); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/stdlib/atoi.c b/src/kernel/lib/stdlib/atoi.c deleted file mode 100644 index b90958a..0000000 --- a/src/kernel/lib/stdlib/atoi.c +++ /dev/null @@ -1,28 +0,0 @@ -#include <lib/math.h> -#include <lib/string.h> -#include <stddef.h> -#include <stdint.h> - -int atoi(char *str) -{ - u32 s_str = strlen(str); - if (!s_str) - return 0; - - u8 negative = 0; - if (str[0] == '-') - negative = 1; - - u32 i = 0; - if (negative) - i++; - - int ret = 0; - for (; i < s_str; i++) { - ret += (str[i] - '0') * pow(10, (int)((s_str - i) - 1)); - } - - if (negative) - ret *= -1; - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/stdlib/htoa.c b/src/kernel/lib/stdlib/htoa.c deleted file mode 100644 index 9cf57cc..0000000 --- a/src/kernel/lib/stdlib/htoa.c +++ /dev/null @@ -1,31 +0,0 @@ -#include <lib/string.h> -#include <memory/alloc.h> -#include <stdint.h> - -static const char HTOA_TABLE[] = "0123456789ABCDEF"; - -char *htoa(u32 n) -{ - char *ret = (char *)malloc(10); - - int i = 0; - while (n) { - ret[i++] = HTOA_TABLE[n & 0xF]; - n >>= 4; - } - - if (!i) { - ret[0] = '0'; - i++; - } - - for (; i <= 9; i++) - ret[i] = 0; - - char *aux = strdup(ret); - free(ret); - ret = aux; - - strinv(ret); - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/stdlib/htoi.c b/src/kernel/lib/stdlib/htoi.c deleted file mode 100644 index 367d30e..0000000 --- a/src/kernel/lib/stdlib/htoi.c +++ /dev/null @@ -1,23 +0,0 @@ -#include <lib/math.h> -#include <lib/string.h> -#include <stddef.h> - -int htoi(char *str) -{ - u32 s_str = strlen(str); - - u32 i = 0; - int ret = 0; - for (; i < s_str; i++) { - char c = str[i]; - int aux = 0; - if (c >= '0' && c <= '9') - aux = c - '0'; - else if (c >= 'A' && c <= 'F') - aux = (c - 'A') + 10; - - ret += aux * pow(16, (int)((s_str - i) - 1)); - } - - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/stdlib/itoa.c b/src/kernel/lib/stdlib/itoa.c deleted file mode 100644 index b15befd..0000000 --- a/src/kernel/lib/stdlib/itoa.c +++ /dev/null @@ -1,73 +0,0 @@ -#include <lib/math.h> -#include <lib/string.h> -#include <memory/alloc.h> -#include <memory/paging.h> -#include <stdint.h> - -static const char ITOA_TABLE[] = "0123456789"; - -char *itoa(int n) -{ - if (!n) { - char *ret = (char *)malloc(2); - ret[0] = '0'; - ret[1] = 0; - return ret; - } - u8 negative = (u8)(n < 0); - if (negative) - n *= -1; - - int sz; - for (sz = 0; n % pow(10, sz) != n; sz++) { - } - - char *ret = (char *)malloc((u32)(sz + 1)); - - for (int i = 0; i < sz; i++) { - int digit = (n % pow(10, i + 1)) / pow(10, i); - ret[i] = ITOA_TABLE[digit]; - } - ret[sz] = 0; - - if (negative) { - char *aux = (char *)malloc((u32)(sz + 2)); - strcpy(aux, ret); - aux[sz] = '-'; - aux[sz + 1] = 0; - free(ret); - ret = aux; - } - - strinv(ret); - return ret; -} - -// TODO: Rename itoa_base -char *itoa_base(int value, char *result, int base, int is_signed) -{ - if (base < 2 || base > 36) { - *result = '\0'; - return result; - } - - char *ptr = result, *ptr1 = result, tmp_char; - int tmp_value; - - do { - tmp_value = value; - value /= base; - *ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz" - [35 + (tmp_value - value * base)]; - } while (value); - - if (is_signed && tmp_value < 0) - *ptr++ = '-'; - *ptr-- = '\0'; - while (ptr1 < ptr) { - tmp_char = *ptr; - *ptr-- = *ptr1; - *ptr1++ = tmp_char; - } - return result; -}
\ No newline at end of file diff --git a/src/kernel/lib/string.h b/src/kernel/lib/string.h deleted file mode 100644 index 127dcc4..0000000 --- a/src/kernel/lib/string.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef MELVIX_STRING_H -#define MELVIX_STRING_H - -#include <stddef.h> -#include <stdint.h> - -u32 strlen(const char *str); - -void strcpy(char *dest, const char *orig); - -void strdisp(char *str, int n); - -void strcat(char *dest, const char *orig); - -void strcati(char *dest, const char *orig); - -char strcmp(const char *a, const char *b); - -int strncmp(const char *s1, const char *s2, int c); - -char *strdup(const char *orig); - -void strinv(char *str); - -char *strstr(const char *in, const char *str); - -char *strsep(char **stringp, const char *delim); - -#endif
\ No newline at end of file diff --git a/src/kernel/lib/string/strcat.c b/src/kernel/lib/string/strcat.c deleted file mode 100644 index 3ae8ea0..0000000 --- a/src/kernel/lib/string/strcat.c +++ /dev/null @@ -1,11 +0,0 @@ -#include <lib/string.h> - -void strcat(char *dest, const char *orig) -{ - u32 s_dest = strlen(dest); - u32 s_orig = strlen(orig); - - for (u32 i = 0; i < s_orig; i++) - dest[s_dest + i] = orig[i]; - dest[s_dest + s_orig] = 0; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strcati.c b/src/kernel/lib/string/strcati.c deleted file mode 100644 index 2fda46c..0000000 --- a/src/kernel/lib/string/strcati.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <lib/string.h> - -void strcati(char *dest, const char *orig) -{ - u32 s_orig = strlen(orig); - strdisp(dest, (int)s_orig); - for (u32 i = 0; i < s_orig; i++) - dest[i] = orig[i]; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strcmp.c b/src/kernel/lib/string/strcmp.c deleted file mode 100644 index 7a273ac..0000000 --- a/src/kernel/lib/string/strcmp.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <lib/string.h> - -char strcmp(const char *a, const char *b) -{ - if (strlen(a) != strlen(b)) - return 1; - - for (u32 i = 0; i < strlen(a); i++) - if (a[i] != b[i]) - return 1; - - return 0; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strcpy.c b/src/kernel/lib/string/strcpy.c deleted file mode 100644 index 5d7f194..0000000 --- a/src/kernel/lib/string/strcpy.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <lib/string.h> - -void strcpy(char *dest, const char *orig) -{ - u32 s_orig = strlen(orig); - - for (u32 i = 0; i < s_orig; i++) - dest[i] = orig[i]; - dest[s_orig] = 0; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strdisp.c b/src/kernel/lib/string/strdisp.c deleted file mode 100644 index dada5d0..0000000 --- a/src/kernel/lib/string/strdisp.c +++ /dev/null @@ -1,14 +0,0 @@ -#include <lib/string.h> - -void strdisponce(char *str) -{ - for (u32 i = sizeof(str) + 2; i > 0; i--) - str[i] = str[i - 1]; - str[0] = 0; -} - -void strdisp(char *str, int n) -{ - for (int i = 0; i < n; i++) - strdisponce(str); -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strdup.c b/src/kernel/lib/string/strdup.c deleted file mode 100644 index 3b138e8..0000000 --- a/src/kernel/lib/string/strdup.c +++ /dev/null @@ -1,10 +0,0 @@ -#include <lib/string.h> -#include <memory/alloc.h> - -char *strdup(const char *orig) -{ - u32 s_orig = strlen(orig); - char *ret = (char *)malloc(s_orig + 1); - strcpy(ret, orig); - return ret; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strinv.c b/src/kernel/lib/string/strinv.c deleted file mode 100644 index 90cb581..0000000 --- a/src/kernel/lib/string/strinv.c +++ /dev/null @@ -1,13 +0,0 @@ -#include <lib/string.h> - -void strinv(char *str) -{ - u32 s_str = strlen(str); - - int iterations = (int)s_str / 2; - for (int i = 0; i < iterations; i++) { - char aux = str[i]; - str[i] = str[(s_str - i) - 1]; - str[(s_str - i) - 1] = aux; - } -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strlen.c b/src/kernel/lib/string/strlen.c deleted file mode 100644 index 520ab92..0000000 --- a/src/kernel/lib/string/strlen.c +++ /dev/null @@ -1,9 +0,0 @@ -#include <lib/string.h> - -u32 strlen(const char *str) -{ - u32 len = 0; - while (str[len]) - len++; - return len; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strncmp.c b/src/kernel/lib/string/strncmp.c deleted file mode 100644 index 4dbac59..0000000 --- a/src/kernel/lib/string/strncmp.c +++ /dev/null @@ -1,16 +0,0 @@ -int strncmp(const char *s1, const char *s2, int c) -{ - int result = 0; - - while (c) { - result = *s1 - *s2++; - - if ((result != 0) || (*s1++ == 0)) { - break; - } - - c--; - } - - return result; -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strsep.c b/src/kernel/lib/string/strsep.c deleted file mode 100644 index 8f5201e..0000000 --- a/src/kernel/lib/string/strsep.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <stddef.h> - -char *strsep(char **stringp, const char *delim) -{ - char *s; - const char *spanp; - int c, sc; - char *tok; - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } -}
\ No newline at end of file diff --git a/src/kernel/lib/string/strstr.c b/src/kernel/lib/string/strstr.c deleted file mode 100644 index 720df8c..0000000 --- a/src/kernel/lib/string/strstr.c +++ /dev/null @@ -1,25 +0,0 @@ -#include <lib/stdlib.h> -#include <stdint.h> - -char *strstr(const char *in, const char *str) -{ - char c; - u32 len; - - c = *str++; - if (!c) - return (char *)in; - - len = strlen(str); - do { - char sc; - - do { - sc = *in++; - if (!sc) - return (char *)0; - } while (sc != c); - } while (strncmp(in, str, len) != 0); - - return (char *)(in - 1); -}
\ No newline at end of file |