diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/kmem.c | 53 | ||||
-rw-r--r-- | src/lib/strings.c | 8 |
2 files changed, 4 insertions, 57 deletions
diff --git a/src/lib/kmem.c b/src/lib/kmem.c index 931d5e3..0419662 100644 --- a/src/lib/kmem.c +++ b/src/lib/kmem.c @@ -2,59 +2,6 @@ #include <drivers/uart.h> #include <lib/kmem.h> -void* kmalloc(unsigned int size) -{ - unsigned int sz = 1; - while (sz < size && sz < 0x1000) - sz *= 2; - unsigned long offset = 0x1000*(sz/2); - unsigned int exp = 0; - unsigned int tmp = sz; - while (tmp != 0) { - exp++; - tmp = tmp >> 1; - } - unsigned int i = 0; - while (i < 0x1000) { - if (kmem_lookup[0x1000*exp + i] == 0) { - kmem_lookup[0x1000*exp + i] = 1; - return (void*)kmem_begin + offset + i*sz; - } - i++; - } - return 0; -} - -void* kcalloc(unsigned int size) -{ - unsigned char* ptr = kmalloc(size); - if (ptr == 0) - return 0; - for(unsigned int i = 0; i < size; i++) - ptr[i] = 0; - return ptr; -} - -void kfree(void* ptr) -{ - if (!((unsigned long)kmem_begin <= (unsigned long)ptr && (unsigned long)ptr < (unsigned long)kmem_begin + 0x200000)) - return; - unsigned long size = 1; - while (!((unsigned long)kmem_begin + 0x1000*(size/2) <= (unsigned long)ptr && (unsigned long)ptr < (unsigned long)kmem_begin + 0x1000*size)) { - size *= 2; - } - void* base = (void*)((unsigned long)ptr - ((unsigned long)ptr % size)); - void* block_base = kmem_begin + 0x1000*(size/2); - unsigned int lookup_offset = (base - block_base)/size; - unsigned int exp = 0; - unsigned int tmp = size; - while (tmp != 0) { - exp++; - tmp = tmp >> 1; - } - kmem_lookup[0x1000*exp + lookup_offset] = 0; -} - void kmemshow32(void* data, unsigned long length) { unsigned long* ptr = data; diff --git a/src/lib/strings.c b/src/lib/strings.c index 53caaec..3155afa 100644 --- a/src/lib/strings.c +++ b/src/lib/strings.c @@ -36,7 +36,7 @@ unsigned char strcmpn(string_t a, string_t b, unsigned int n) char* zhex32_to_str(unsigned long value) { - char* data = kcalloc(9); + static char data[10]; char tmp = 0; char isz = -1; for (int i = 0; i < 8; i++) { @@ -53,7 +53,7 @@ char* zhex32_to_str(unsigned long value) char* hex32_to_str(unsigned long value) { - char* data = kcalloc(9); + static char data[10]; char tmp = 0; for (int i = 0; i < 8; i++) { tmp = (value >> 4*(8-i-1))&0xF; @@ -69,7 +69,7 @@ char* u32_to_str(unsigned long value) { unsigned long t = value; unsigned long c; - char* data = kcalloc(11); + static char data[12]; char* dptr = data + 9; for (int i = 0; i <= 10; i++) { c = t%10; @@ -91,7 +91,7 @@ char* s32_to_str(unsigned long value) t = -t; is_neg = 1; } - char* data = kcalloc(12); + static char data[13]; char* dptr = data + 10; for (int i = 0; i <= 10; i++) { c = t%10; |