aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/globals.h2
-rw-r--r--include/lib/kmem.h9
-rw-r--r--linker.ld2
-rw-r--r--src/boot.S4
-rw-r--r--src/cpu/irq.c8
-rw-r--r--src/globals.c2
-rw-r--r--src/lib/kmem.c76
-rw-r--r--src/sys/core.c1
8 files changed, 92 insertions, 12 deletions
diff --git a/include/globals.h b/include/globals.h
index 2d1f7a4..423425f 100644
--- a/include/globals.h
+++ b/include/globals.h
@@ -9,6 +9,8 @@ extern unsigned long cntfrq;
extern char* os_name;
extern char* os_info_v;
+unsigned char kmem_begin[0x2000000];
+unsigned char kmem_lookup[0xD000];
extern unsigned long exe_cnt;
extern struct Mutex exe_cnt_m;
extern unsigned char rpi_heap[MAX_MM];
diff --git a/include/lib/kmem.h b/include/lib/kmem.h
new file mode 100644
index 0000000..4e79c96
--- /dev/null
+++ b/include/lib/kmem.h
@@ -0,0 +1,9 @@
+#ifndef LIB_KMEM_H
+#define LIB_KMEM_H
+
+void* kmalloc(unsigned int size);
+void* kcalloc(unsigned int size);
+void* krealloc(void* old, unsigned int size);
+void kfree(void* ptr);
+
+#endif
diff --git a/linker.ld b/linker.ld
index 260e1f1..c97501c 100644
--- a/linker.ld
+++ b/linker.ld
@@ -33,6 +33,8 @@ SECTIONS
. = ALIGN(4096);
KEEP(*(.bss.estacks))
. = ALIGN(4096);
+ KEEP(*(.bss.kmem))
+ . = ALIGN(4096);
*(.bss)
*(.bss.*)
KEEP(*(.bss.mmheap))
diff --git a/src/boot.S b/src/boot.S
index 3e8a209..9259874 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -137,10 +137,6 @@ core0_mbox: .word 0
core1_mbox: .word 0
core2_mbox: .word 0
core3_mbox: .word 0
-core0_msg: .asciz "Powering up, Core 0 Online!\n"
-core1_msg: .asciz "Powering up, Core 1 Online!\n"
-core2_msg: .asciz "Powering up, Core 2 Online!\n"
-core3_msg: .asciz "Powering up, Core 3 Online!\n"
.section .bss.estacks
.align 4
diff --git a/src/cpu/irq.c b/src/cpu/irq.c
index ac08c05..6be4bc7 100644
--- a/src/cpu/irq.c
+++ b/src/cpu/irq.c
@@ -103,13 +103,5 @@ void handle_data(unsigned char data)
add_thread(uart_scheduler, 0, 2);
} else if (data == 0x62) {
add_thread(heap_info, 0, 2);
- } else {
}
- g_Drawer.x = 0;
- g_Drawer.y = 7;
- for(int i = 0; i < 128; i++)
- write_char(&g_Drawer, ' ');
- g_Drawer.x = 0;
- g_Drawer.y = 7;
- write_string(&g_Drawer, "> ");
}
diff --git a/src/globals.c b/src/globals.c
index 6e2e70c..7560d82 100644
--- a/src/globals.c
+++ b/src/globals.c
@@ -10,6 +10,8 @@ char* os_info_v = "?";
char* os_info_v = VERSION;
#endif
+__attribute__((section(".bss.kmem"))) unsigned char kmem_begin[0x2000000];
+__attribute__((section(".bss"))) unsigned char kmem_lookup[0xD000];
__attribute__((section(".bss"))) unsigned long exe_cnt;
__attribute__((section(".bss"))) struct Mutex exe_cnt_m;
__attribute__((section(".bss"))) unsigned long nextpid;
diff --git a/src/lib/kmem.c b/src/lib/kmem.c
new file mode 100644
index 0000000..fc91fc4
--- /dev/null
+++ b/src/lib/kmem.c
@@ -0,0 +1,76 @@
+#include <lib/kmem.h>
+#include <globals.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* krealloc(void* old, unsigned int size)
+{
+ unsigned long old_size = 1;
+ while (!((unsigned long)kmem_begin + 0x1000*(old_size/2) <= (unsigned long)old && (unsigned long)old < (unsigned long)kmem_begin + 0x1000*old_size))
+ old_size *= 2;
+ if (size <= old_size)
+ return old;
+ void* new = kmalloc(size);
+ if (new == 0)
+ return 0;
+ void* base = (void*)((unsigned long)old - ((unsigned long)old % old_size));
+ void* block_base = kmem_begin + 0x1000*(old_size/2);
+ unsigned int lookup_offset = (base - block_base)/old_size;
+ unsigned int exp = 0;
+ unsigned int tmp = old_size;
+ while (tmp != 0) {
+ exp++;
+ tmp = tmp >> 1;
+ }
+ kmem_lookup[0x1000*exp + lookup_offset] = 0;
+ return new;
+}
+
+void kfree(void* ptr)
+{
+ 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;
+}
diff --git a/src/sys/core.c b/src/sys/core.c
index adfbd20..a42b581 100644
--- a/src/sys/core.c
+++ b/src/sys/core.c
@@ -4,6 +4,7 @@
#include <globals.h>
#include <graphics/drawer.h>
#include <graphics/lfb.h>
+#include <lib/kmem.h>
#include <lib/mem.h>
#include <lib/strings.h>
#include <symbols.h>