changeset 206:247aa9ee931c

loaduvm_loopvm_impl
author tobaru
date Thu, 23 Jan 2020 17:12:02 +0900
parents 3cac4139b31d
children 8a55878f6a25
files src/impl/vm_impl.h src/impl/vm_impl_private.cbc
diffstat 2 files changed, 66 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/vm_impl.h	Thu Jan 23 15:43:36 2020 +0900
+++ b/src/impl/vm_impl.h	Thu Jan 23 17:12:02 2020 +0900
@@ -7,6 +7,7 @@
     char* addr;
     struct inode* ip;
     uint offset;
+    uint pa;
 
     __code loaduvm_ptesize_check(Type* vm_impl, __code next(...));
     __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...));
--- a/src/impl/vm_impl_private.cbc	Thu Jan 23 15:43:36 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Thu Jan 23 17:12:02 2020 +0900
@@ -1,12 +1,71 @@
 #include "../../context.h"
+#include "mmu.h"
+#include "memlayout.h"
 #interface "vm_impl.h"
 
-__code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl) {
-    
-    
-    goto vm_impl->next();
+/*
+vm_impl* createvm_impl2();
+*/
+
+__code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl, __code next(...)) {
+
+    if ((uint) vm_impl->addr %PTE_SZ != 0) {
+       // goto panic 
+    }
+
+    goto loaduvm_loopvm_impl(vm_impl, next(...));
 }
 
-__code loaduvm_loopvm_impl(struct vm_impl* vm_impl) {
-    goto vm_impl->next();
+__code loaduvm_loopvm_impl(struct vm_impl* vm_impl, __code next(...)) {
+
+    if (vm_impl->i < vm_impl->sz) {
+        goto loaduvm_check_pgdir(vm_impl, next(...));  
+    } 
+    goto loaduvm_exit(vm_impl, next(...));
 }
+static pte_t* walkpgdir (pde_t *pgdir, const void *va, int alloc)
+{
+    pde_t *pde;
+    pte_t *pgtab;
+
+    // pgdir points to the page directory, get the page direcotry entry (pde)
+    pde = &pgdir[PDE_IDX(va)];
+
+    if (*pde & PE_TYPES) {
+        pgtab = (pte_t*) p2v(PT_ADDR(*pde));
+
+    } else {
+        if (!alloc || (pgtab = (pte_t*) kpt_alloc()) == 0) {
+            return 0;
+        }
+
+        // Make sure all those PTE_P bits are zero.
+        memset(pgtab, 0, PT_SZ);
+
+        // The permissions here are overly generous, but they can
+        // be further restricted by the permissions in the page table
+        // entries, if necessary.
+        *pde = v2p(pgtab) | UPDE_TYPE;
+    }
+
+    return &pgtab[PTE_IDX(va)];
+}
+
+
+__code loaduvm_check_pgdir(struct vm_impl* vm_impl, __code next(...)) {
+    if ((vm_impl->pte = walkpgdir(vm_impl->pgdir, vm_impl->addr + vm_impl->i, 0)) == 0) {
+        // goto panic
+    } 
+    vm_impl->pa = PTE_ADDR(*vm_impl->pte);
+ 
+    goto loaduvm_check_PTE_SZ(vm_impl, next(...));
+}
+
+__code loaduvm_check_PTE_SZ(struct vm_impl* vm_impl, __code next(...)) {
+    goto loaduvm_exit(vm_impl, next(...));
+}
+
+__code loaduvm_exit(struct vm_impl* vm_impl, __code next(...)) {
+
+    goto next(...);
+}