diff options
Diffstat (limited to 'src/lib/mem.c')
-rw-r--r-- | src/lib/mem.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/lib/mem.c b/src/lib/mem.c index ac5db4d..91fed94 100644 --- a/src/lib/mem.c +++ b/src/lib/mem.c @@ -11,6 +11,13 @@ void memshow32(unsigned long* addr, unsigned int n) uart_char(0x0a); } +void memset(unsigned char* dest, unsigned char value, unsigned int n) +{ + for(unsigned int i = 0; i < n; i++) { + dest[i] = value; + } +} + void memcpy(unsigned char* src, unsigned char* dest, unsigned int n) { for(unsigned int i = 0; i < n; i++) { @@ -27,6 +34,13 @@ unsigned char memcmp(unsigned char* a, unsigned char* b, unsigned int n) return 1; } +void memset32(unsigned long* dest, unsigned long value, unsigned int n) +{ + for(unsigned int i = 0; i < n; i++) { + dest[i] = value; + } +} + void memcpy32(unsigned long* src, unsigned long* dest, unsigned int n) { for(unsigned int i = 0; i < n; i++) { @@ -66,6 +80,13 @@ void* malloc(unsigned char size) return (void*)&mem[i + MEM_BASE_SIZE]; } +void* calloc(unsigned char size) +{ + void* addr = malloc(size); + memset(addr, 0, size); + return addr; +} + void* malloca(unsigned char size, unsigned char amnt) { // Return malloc if alignment size is 0 or 1 - trivial alignment @@ -113,6 +134,13 @@ void* malloca(unsigned char size, unsigned char amnt) } } +void* calloca(unsigned char size, unsigned char amnt) +{ + void* addr = malloca(size, amnt); + memset(addr, 0, size); + return addr; +} + void free(void* memloc) { // Don't try to free memory outside of heap |