aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-20 18:33:29 -0700
committerChristian Cunningham <cc@localhost>2022-01-20 18:33:29 -0700
commit9ca0f8a8bdbfe543a23ff2e75502744a7263a5b7 (patch)
tree3670a0f0aaa70f03c0176e9e1a0d292139f0fa04 /src
parent022dfd0f42962da6c60fbeb5604e1455a07eaaa6 (diff)
Added memory functions
Diffstat (limited to 'src')
-rw-r--r--src/lib/mem.c28
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