changeset 226:415081e357ec

switchuvm_check_pgdirvm_impl
author tobaru
date Fri, 24 Jan 2020 20:26:26 +0900
parents 408ea2236abc
children 80398e02ae72
files src/gearsTools/lib/Gears/Context/Template/XV6.pm src/impl/vm_impl.cbc src/impl/vm_impl.h src/impl/vm_impl_private.cbc
diffstat 4 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Fri Jan 24 19:00:44 2020 +0900
+++ b/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Fri Jan 24 20:26:26 2020 +0900
@@ -161,6 +161,7 @@
 #ifndef USE_CUDAWorker
 typedef unsigned long long CUdeviceptr;
 #endif
+typedef struct proc proc_struct;
 typedef uint32  pte_t;
 typedef uint32  pde_t;
 EOFEOF
--- a/src/impl/vm_impl.cbc	Fri Jan 24 19:00:44 2020 +0900
+++ b/src/impl/vm_impl.cbc	Fri Jan 24 20:26:26 2020 +0900
@@ -33,6 +33,7 @@
     vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
     vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
     vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
+    vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
     vm->init_vmm = C_init_vmmvm_impl;
     vm->kpt_freerange = C_kpt_freerangevm_impl;
     vm->kpt_alloc = C_kpt_allocvm_impl;
@@ -91,7 +92,7 @@
 typedef struct proc proc;
 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
 
-    goto next(...);
+    goto switchuvm_check_pgdirvm_impl(...);
 }
 
 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) { //:skip
--- a/src/impl/vm_impl.h	Fri Jan 24 19:00:44 2020 +0900
+++ b/src/impl/vm_impl.h	Fri Jan 24 20:26:26 2020 +0900
@@ -25,6 +25,7 @@
     char* buf;
     char* pa0;
     uint va0;
+    proc_struct* p;
 
     __code kpt_alloc_check_impl(Type* vm_impl, __code next(...));
     __code loaduvm_ptesize_check(Type* vm_impl, __code next(int ret, ...));
@@ -37,6 +38,7 @@
     __code uva2ka_check_pe_types(Type* vm_impl, pde_t* pgdir, char* uva, __code next(...));
     __code paging_intvm_impl(Type* vm_impl, uint phy_low, uint phy_hi, __code next(...));
     __code copyout_loopvm_impl(Type* vm_impl, pde_t* pgdir, uint va, void* pp, uint len, __code next(...));
+    __code switchuvm_check_pgdirvm_impl(struct vm_impl* vm_impl, struct proc *p, __code next(...));
     __code next(...);
 } vm_impl;
 
--- a/src/impl/vm_impl_private.cbc	Fri Jan 24 19:00:44 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Fri Jan 24 20:26:26 2020 +0900
@@ -1,4 +1,5 @@
-#include "../../context.h"
+#include "param.h"
+#include "proc.h"
 #include "mmu.h"
 #include "defs.h"
 #include "memlayout.h"
@@ -361,3 +362,22 @@
     goto copyout_loopvm_impl(vm_impl, pgdir, va, pp, len, va0, pa0, next(...));
 }
 
+typedef struct proc proc_struct;
+__code switchuvm_check_pgdirvm_impl(struct vm_impl* vm_impl, proc_struct* p, __code next(...)) { //:skip
+    uint val;
+
+    pushcli();
+
+    if (p->pgdir == 0) {
+        panic("switchuvm: no pgdir");
+    }
+
+    val = (uint) V2P(p->pgdir) | 0x00;
+
+    asm("MCR p15, 0, %[v], c2, c0, 0": :[v]"r" (val):);
+    flush_tlb();
+
+    popcli();
+
+    goto next(...);
+}