changeset 218:1c923ae14607

copyuvm
author tobaru
date Fri, 24 Jan 2020 17:01:11 +0900
parents f940ff602312
children b8597756f701
files src/impl/vm_impl_private.cbc
diffstat 1 files changed, 38 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/vm_impl_private.cbc	Fri Jan 24 16:17:25 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Fri Jan 24 17:01:11 2020 +0900
@@ -234,34 +234,51 @@
 __code copyuvm_loopvm_impl(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
 
     if (i < sz) { 
-        if ((pte = walkpgdir(pgdir, (void *) i, 0)) == 0) {
-            panic("copyuvm: pte should exist");
-        }
-
-        if (!(*pte & PE_TYPES)) {
-            panic("copyuvm: page not present");
-        }
-
-        pa = PTE_ADDR (*pte);
-        ap = PTE_AP (*pte);
+        goto copyuvm_loop_check_walkpgdir(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
 
-        if ((mem = alloc_page()) == 0) {
-            goto copyuvm_loop_bad(vm_impl, d, next(...));
-        }
-
-        memmove(mem, (char*) p2v(pa), PTE_SZ);
-
-        if (mappages(d, (void*) i, PTE_SZ, v2p(mem), ap) < 0) {
-            goto copyuvm_loop_bad(vm_impl, d, next(...));
-        }
-        goto copyuvm_loopvm_impl(vm_impl, pgdir, sz, d, pte, pa, i + PTE_SZ, ap, mem, next(ret, ...));
     }
     ret = d;
     goto next(ret, ...);
 }
 
-__code copyuvm_loop_check_walkpgdir() {
+__code copyuvm_loop_check_walkpgdir(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
+        if ((pte = walkpgdir(pgdir, (void *) i, 0)) == 0) {
+            // panic("copyuvm: pte should exist");
+            // goto panic();
+        }
+    goto copyuvm_loop_check_pte(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
+}
+
+__code copyuvm_loop_check_pte(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
+
+        if (!(*pte & PE_TYPES)) {
+            // panic("copyuvm: page not present");
+            // goto panic();
+        }
+
+    goto copyuvm_loop_check_mem(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
+}
 
+__code copyuvm_loop_check_mem(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
+    pa = PTE_ADDR (*pte);
+    ap = PTE_AP (*pte);
+
+    if ((mem = alloc_page()) == 0) {
+        goto copyuvm_loop_bad(vm_impl, d, next(...));
+    }
+    goto copyuvm_loop_check_mappages(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
+    
+}
+
+__code copyuvm_loop_check_mappages(struct vm_impl* vm_impl, pde_t* pgdir, uint sz, pde_t* d, pte_t* pte, uint pa, uint i, uint ap, char* mem, __code next(int ret, ...)) {
+
+    memmove(mem, (char*) p2v(pa), PTE_SZ);
+
+    if (mappages(d, (void*) i, PTE_SZ, v2p(mem), ap) < 0) {
+        goto copyuvm_loop_bad(vm_impl, d, next(...));
+    }
+    goto copyuvm_loopvm_impl(vm_impl, pgdir, sz, d, pte, pa, i, ap, mem, __code next(int ret, ...));
+ 
 }
 
 __code copyuvm_loop_bad(struct vm_impl* vm_impl, pde_t* d, __code next(int ret, ...)) {