diff options
author | Xander <xander@biltopia.org> | 2023-08-17 21:09:27 +0200 |
---|---|---|
committer | Xander <xander@biltopia.org> | 2023-08-17 21:09:27 +0200 |
commit | e2d7deb82cd25b47cbccda0c48ab39e17c5c536d (patch) | |
tree | 30e9d6d316dc3912d077eed469268f710696e916 | |
parent | b06ab74179453e0f8592c77c40992707b3e8b765 (diff) | |
download | ats-os-e2d7deb82cd25b47cbccda0c48ab39e17c5c536d.tar.xz ats-os-e2d7deb82cd25b47cbccda0c48ab39e17c5c536d.zip |
Started implementing paging
-rw-r--r-- | kernel/memory/frame.dats | 2 | ||||
-rw-r--r-- | kernel/memory/frame.sats | 2 | ||||
-rw-r--r-- | kernel/memory/paging.dats | 30 | ||||
-rw-r--r-- | kernel/memory/paging.sats | 33 | ||||
-rw-r--r-- | kernel/prelude/SATS/safe_casts.sats | 1 | ||||
-rw-r--r-- | kernel/prelude/kernel_prelude.hats | 1 |
6 files changed, 68 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 diff --git a/kernel/prelude/SATS/safe_casts.sats b/kernel/prelude/SATS/safe_casts.sats new file mode 100644 index 0000000..50a68a8 --- /dev/null +++ b/kernel/prelude/SATS/safe_casts.sats @@ -0,0 +1 @@ +castfn u2uint64{v : nat | v <= 0xFFFFFFFFFFFFFFFF}(v : uint v) : uint64 v diff --git a/kernel/prelude/kernel_prelude.hats b/kernel/prelude/kernel_prelude.hats index 39e7560..514c2c2 100644 --- a/kernel/prelude/kernel_prelude.hats +++ b/kernel/prelude/kernel_prelude.hats @@ -4,6 +4,7 @@ #include "share/atspre_staload.hats" staload "./DATS/print.dats" +staload "./SATS/safe_casts.sats" #endif |