aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-01-02 16:37:15 -0800
committerChristian Cunningham <cc@localhost>2022-01-02 16:37:15 -0800
commit23acc27565157bf8caf896f0099ad10c192326e6 (patch)
tree98fb4e00bf7a1f36dcd06399e027776eed67c167 /src/lib
parent8823cb198dff5ef086fb70da93d1134423e8198b (diff)
Fixed Logic Error
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/mem.c15
-rw-r--r--src/lib/mem.h6
2 files changed, 15 insertions, 6 deletions
diff --git a/src/lib/mem.c b/src/lib/mem.c
index 1a974f1..296e096 100644
--- a/src/lib/mem.c
+++ b/src/lib/mem.c
@@ -1,3 +1,4 @@
+#include "../lib/mem.h"
#include "../drivers/uart.h"
void memshow32(unsigned long* addr, unsigned int n)
@@ -51,14 +52,15 @@ void* malloc(unsigned char size)
unsigned char* mem = (unsigned char*)rpi_heap;
unsigned long i = 0;
// TODO: Use Null PID
- while ((mem[i] != 0) && !(mem[i] == size && mem[i+1]==0)) {
+ while (((void*)(mem+i) < rpi_heap_top) && !(mem[i] == size && mem[i+1]==0)) {
i += mem[i]+2;
}
+ // Update top of heap
+ if (mem[i] == 0)
+ rpi_heap_top = (void*)&mem[i+2+size];
mem[i] = size;
// Use allocator's PID
mem[i+1] = 1;
- // Update top of heap
- rpi_heap_top = (void*)&mem[i+2+size];
return (void*)&mem[i+2];
}
@@ -91,17 +93,18 @@ void heap_info(void)
{
unsigned char* base = rpi_heap;
while ((void*)base < rpi_heap_top) {
+ unsigned char size = *base;
if(base[1] == 0) {
uart_char('F');
uart_char(' ');
}
uart_hex((unsigned long)(base+2));
uart_string(" Size: ");
- uart_10(base[0]);
+ uart_10(size);
uart_string("\n");
static char* data = "00 \0";
static unsigned char temp = 0;
- for(unsigned int i = 0; i < base[0]; i++) {
+ for(unsigned int i = 0; i < size; i++) {
temp = (base[2+i]>>4)&0xF;
if(temp > 9)
temp += 7;
@@ -115,7 +118,7 @@ void heap_info(void)
uart_string(data);
}
uart_char('\n');
- base += *base + 2;
+ base += size + 2;
}
uart_char('\n');
}
diff --git a/src/lib/mem.h b/src/lib/mem.h
index 4d02236..ec1402f 100644
--- a/src/lib/mem.h
+++ b/src/lib/mem.h
@@ -1,6 +1,12 @@
#ifndef LIB_MEM_H
#define LIB_MEM_H
+struct MemTab {
+ unsigned char size;
+ unsigned char in_use;
+ void* data;
+} __attribute__((packed));
+
void memcpy(unsigned char* src, unsigned char* dest, unsigned int n);
unsigned char memcmp(unsigned char* a, unsigned char* b, unsigned int n);