aboutsummaryrefslogtreecommitdiff
path: root/kernel/memory
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/memory')
-rw-r--r--kernel/memory/frame.dats2
-rw-r--r--kernel/memory/frame.sats2
-rw-r--r--kernel/memory/paging.dats30
-rw-r--r--kernel/memory/paging.sats33
4 files changed, 66 insertions, 1 deletions
diff --git a/kernel/memory/frame.dats b/kernel/memory/frame.dats
index 2910de5..aa02134 100644
--- a/kernel/memory/frame.dats
+++ b/kernel/memory/frame.dats
@@ -10,7 +10,7 @@ staload "lib/DATS/init.dats"
staload UN = "prelude/SATS/unsafe.sats"
-fn containing_address{l:addr}(address : ptr l):<> frame_t =
+implement containing_address(address) =
@{
counter = $UN.cast{size_t}(address) / i2sz(PAGE_SIZE)
}
diff --git a/kernel/memory/frame.sats b/kernel/memory/frame.sats
index 6ace8f9..dfd422e 100644
--- a/kernel/memory/frame.sats
+++ b/kernel/memory/frame.sats
@@ -15,6 +15,8 @@ typedef frame_allocator_t = @{
multiboot_end = frame_t
}
+fn containing_address{l:addr}(ptr l):<> frame_t
+
fn allocate_frame () : frame_t
fn deallocate_frame () : void
fn init(kernel_start: Ptr, kernel_end: Ptr, multiboot_start:Ptr, multiboot_end: Ptr) : void
diff --git a/kernel/memory/paging.dats b/kernel/memory/paging.dats
new file mode 100644
index 0000000..9b55624
--- /dev/null
+++ b/kernel/memory/paging.dats
@@ -0,0 +1,30 @@
+#define ATS_DYNLOADFLAG 0
+
+#include "kernel/prelude/kernel_prelude.hats"
+
+staload UN = "prelude/SATS/unsafe.sats"
+
+staload "./paging.sats"
+staload "./frame.sats"
+
+assume entry_type = uint64
+
+val zero = u2uint64(0u)
+
+implement is_unused(entry) = entry = zero
+implement set_unused(entry) = entry := zero
+
+implement flag_contains(entry,flag) =
+ (entry land $UN.cast{uint64}(1 << (case+ flag of
+ | PRESENT() => 0
+ | WRITABLE() => 1
+ | USER_ACCESSIBLE() => 2
+ | WRITE_THROUGH() => 3
+ | NO_CACHE() => 4
+ | ACCESSED() => 5
+ | DIRTY() => 6
+ | HUGE_PAGE() => 7
+ | GLOBAL() => 8
+ | NO_EXECUTE() => 63
+ ))) != zero
+
diff --git a/kernel/memory/paging.sats b/kernel/memory/paging.sats
new file mode 100644
index 0000000..784f567
--- /dev/null
+++ b/kernel/memory/paging.sats
@@ -0,0 +1,33 @@
+#define ENTRY_COUNT 512
+
+staload "./frame.sats"
+
+abstype paddr_type(l:addr) = ptr(l)
+typedef paddr(l:addr) = paddr_type(l)
+
+abstype vaddr_type(l:addr) = ptr(l)
+typedef vaddr(l:addr) = vaddr_type(l)
+
+abst@ype entry_type = uint64
+typedef entry_t = entry_type
+
+typedef page_t = @{
+ num = size_t
+}
+
+datatype entry_flag =
+ | PRESENT
+ | WRITABLE
+ | USER_ACCESSIBLE
+ | WRITE_THROUGH
+ | NO_CACHE
+ | ACCESSED
+ | DIRTY
+ | HUGE_PAGE
+ | GLOBAL
+ | NO_EXECUTE
+
+fn is_unused(entry_t) : bool
+fn set_unused(&entry_t) : void
+
+fn flag_contains(entry_t,entry_flag) : bool