Move out memory allocation code
authorCafe <cafe@not.applicable>
Tue, 25 Jul 2017 00:00:00 +0000 (00:00 +0000)
committerCafe <cafe@not.applicable>
Tue, 25 Jul 2017 17:19:50 +0000 (17:19 +0000)
memory.c [new file with mode: 0644]
memory.h [new file with mode: 0644]
re.c

diff --git a/memory.c b/memory.c
new file mode 100644 (file)
index 0000000..3dbac91
--- /dev/null
+++ b/memory.c
@@ -0,0 +1,25 @@
+/* CBMA -- Cafe's Bad Memory Allocator */
+
+#define CBMA_PAGES 1024
+uint64_t cbma_bottom;
+
+void init_cbma(int fd)
+{
+       cbma_bottom = alloc_gpu_pages(fd, CBMA_PAGES, BASE_MEM_PROT_GPU_RD | BASE_MEM_PROT_GPU_WR | BASE_MEM_SAME_VA);
+}
+
+void* galloc(size_t sz)
+{
+       cbma_bottom &= 0xFFFFFF00;
+       cbma_bottom += 0x100;
+       cbma_bottom += sz;
+       return (void*) (uint32_t) (cbma_bottom - sz);
+}
+
+void gfree(void* ptr)
+{
+       printf("gfree %p", ptr);
+       /* TODO */
+}
+
+
diff --git a/memory.h b/memory.h
new file mode 100644 (file)
index 0000000..0628139
--- /dev/null
+++ b/memory.h
@@ -0,0 +1,5 @@
+/* TODO: Find non-hackish memory allocator */
+
+void init_cbma(int fd);
+void* galloc(size_t sz);
+void gfree(void* ptr);
diff --git a/re.c b/re.c
index 581ce57c20fcea168d4cc42fe888cfed91be9924..f362f58a86cbda206fa061b3298a2ebaf7ed1f37 100644 (file)
--- a/re.c
+++ b/re.c
@@ -5,29 +5,9 @@
 
 #include "shim.h"
 #include "jobs.h"
+#include "memory.h"
 #include "../oolong/chai-notes.h"
 
-/* CBMA -- Cafe's Bad Memory Allocator */
-
-#define CBMA_PAGES 1024
-uint64_t cbma_bottom;
-
-void init_cbma(int fd) {
-       cbma_bottom = alloc_gpu_pages(fd, CBMA_PAGES, BASE_MEM_PROT_GPU_RD | BASE_MEM_PROT_GPU_WR | BASE_MEM_SAME_VA);
-}
-
-void* galloc(size_t sz) {
-       cbma_bottom &= 0xFFFFFF00;
-       cbma_bottom += 0x100;
-       cbma_bottom += sz;
-       return (void*) (uint32_t) (cbma_bottom - sz);
-}
-
-void gfree(void* ptr) {
-       printf("gfree %p", ptr);
-       /* TODO */
-}
-
 int atom_count = 0;
 
 int job_chain_set_value(int fd) {