aboutsummaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/frame.h14
-rw-r--r--kernel/include/sys.h14
2 files changed, 28 insertions, 0 deletions
diff --git a/kernel/include/frame.h b/kernel/include/frame.h
new file mode 100644
index 0000000..9ffafb3
--- /dev/null
+++ b/kernel/include/frame.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <sys.h>
+
+// frame.h : physical memory allocator
+
+void frame_init_allocator(size_t total_ram, void** kernel_data_end);
+
+uint32_t frame_alloc(size_t n); // allocate n consecutive frames (returns 0 on failure)
+void frame_free(uint32_t base, size_t n);
+
+void dbg_print_frame_stats();
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/kernel/include/sys.h b/kernel/include/sys.h
index 2304eec..a9d2d4c 100644
--- a/kernel/include/sys.h
+++ b/kernel/include/sys.h
@@ -29,4 +29,18 @@ void panic_assert(const char* assertion, const char* file, int line);
#define BOCHS_BREAKPOINT asm volatile("xchg %bx, %bx")
+
+// Utility functions for memory alignment
+
+#define PAGE_SIZE 0x1000
+#define PAGE_MASK 0xFFFFF000
+#define PAGE_ALIGN_DOWN(x) (((size_t)x) & PAGE_MASK)
+#define PAGE_ALIGN_UP(x) ((((size_t)x)&(~PAGE_MASK)) == 0 ? ((size_t)x) : (((size_t)x) & PAGE_MASK) + PAGE_SIZE)
+#define PAGE_ID(x) (((size_t)x) / PAGE_SIZE)
+
+#define MASK4 0xFFFFFFFC
+#define ALIGN4_UP(x) ((((size_t)x)&(~MASK4)) == 0 ? ((size_t)x) : (((size_t)x) & MASK4) + 4)
+#define ALIGN4_DOWN(x) (((size_t)x)&MASK4)
+
+
/* vim: set ts=4 sw=4 tw=0 noet :*/