summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kc/core/memory.c34
-rw-r--r--kc/core/vm_object.h21
2 files changed, 22 insertions, 33 deletions
diff --git a/kc/core/memory.c b/kc/core/memory.c
index 7421b04..8feab88 100644
--- a/kc/core/memory.c
+++ b/kc/core/memory.c
@@ -2,6 +2,7 @@
#include "kprint.h"
#include "panic.h"
#include "vm_tree.h"
+#include "vm_object.h"
#include <stdint.h>
@@ -21,48 +22,15 @@
#define align_next(v, a) (((uint64_t)v + a - 1) & ~(a - 1))
-typedef int (*page_fault_handler_func)(uint32_t code, void *address);
-
static int core_image_handler(uint32_t code, void *address);
static int core_vmobject_handler(uint32_t code, void *address);
-enum memory_space_flags
-{
- VOID_MEMORY_SPACE = 0x00, // memory that cannot do anything, i.e. a guard page
- TRANSLATION_MEMORY_SPACE = 0x01, // a mapping to a fixed location in memory
- ANONYMOUS_MEMORY_SPACE = 0x02, // a mapping to an arbitrary location in memory
- OBJECT_MEMORY_SPACE = 0x03, // a mapping managed by an underlying object
-
- MEMORY_SPACE_TYPE_MASK = 0x0f, //
-
- NOFAULT_MEMORY_FLAG = 0x10, // a mapping that cannot be resolved during a page fault
- NOSWAP_MEMORY_FLAG = 0x20, // a mapping that cannot be swapped out
- COW_MEMORY_FLAG = 0x40, // a mapping that is copy-on-write
-
- MEMORY_SPACE_FLAGS_MASK = 0xf0,
-
- INVALID_MEMORY_SPACE = 0xff
-};
-
struct page
{
uint32_t next: 31;
uint32_t used: 1;
};
-enum vm_object_type
-{
- NULL_VM_OBJECT, // a non-object. shouldn't even exist. an abomination unto man and god
- TRANSLATION_VM_OBJECT, // a direct mapping between a physical and virtual address range
- ANONYMOUS_VM_OBJECT, // a mapping that has no definite physical location
-};
-
-struct vm_object
-{
- enum vm_object_type type;
- page_fault_handler_func handler;
-};
-
static struct page *const page_array = (struct page *)0xffffffd800000000;
static int first_free_page_index = -1;
static size_t page_array_entries = 0;
diff --git a/kc/core/vm_object.h b/kc/core/vm_object.h
new file mode 100644
index 0000000..d1de145
--- /dev/null
+++ b/kc/core/vm_object.h
@@ -0,0 +1,21 @@
+#pragma once
+
+typedef int (*vm_object_handler_func)(uint32_t code, void *address);
+
+enum vm_object_type
+{
+ NULL_VM_OBJECT, // a non-object. shouldn't even exist. an abomination unto man and god
+ DIRECT_VM_OBJECT, // a 1:1 physical-to-virtual mapping
+ TRANSLATION_VM_OBJECT, // a mapping between a physical and virtual address range
+ ANONYMOUS_VM_OBJECT, // a mapping that has no definite physical location
+ KC_IMAGE_VM_OBJECT, // a kernel component image
+ KC_HEAP_VM_OBJECT, // a kernel component heap
+ // TODO: more to come
+};
+
+struct vm_object
+{
+ enum vm_object_type type;
+ vm_object_handler_func handler;
+};
+