changeset 227:80398e02ae72

init_inituvm
author tobaru
date Fri, 24 Jan 2020 20:44:49 +0900
parents 415081e357ec
children e2520f609094 3a080883a4f4
files src/impl/vm_impl.cbc src/impl/vm_impl.h src/impl/vm_impl_private.cbc
diffstat 3 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/vm_impl.cbc	Fri Jan 24 20:26:26 2020 +0900
+++ b/src/impl/vm_impl.cbc	Fri Jan 24 20:44:49 2020 +0900
@@ -34,6 +34,7 @@
     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_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
     vm->init_vmm = C_init_vmmvm_impl;
     vm->kpt_freerange = C_kpt_freerangevm_impl;
     vm->kpt_alloc = C_kpt_allocvm_impl;
@@ -95,9 +96,9 @@
     goto switchuvm_check_pgdirvm_impl(...);
 }
 
-__code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) { //:skip
+__code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) { 
 
-    goto next(...);
+    goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
 }
 
 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz,  __code next(...)) {
--- a/src/impl/vm_impl.h	Fri Jan 24 20:26:26 2020 +0900
+++ b/src/impl/vm_impl.h	Fri Jan 24 20:44:49 2020 +0900
@@ -26,6 +26,7 @@
     char* pa0;
     uint va0;
     proc_struct* p;
+    char* init;
 
     __code kpt_alloc_check_impl(Type* vm_impl, __code next(...));
     __code loaduvm_ptesize_check(Type* vm_impl, __code next(int ret, ...));
@@ -38,7 +39,8 @@
     __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 switchuvm_check_pgdirvm_impl(struct vm_impl* vm_impl, struct proc* p, __code next(...));
+    __code init_inituvm_check_sz(struct vm_impl* vm_impl, pde_t* pgdir, char* init, uint sz, __code next(...));
     __code next(...);
 } vm_impl;
 
--- a/src/impl/vm_impl_private.cbc	Fri Jan 24 20:26:26 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Fri Jan 24 20:44:49 2020 +0900
@@ -381,3 +381,19 @@
 
     goto next(...);
 }
+
+__code init_inituvm_check_sz(struct vm_impl* vm_impl, pde_t* pgdir, char* init, uint sz, __code next(...)) {
+    char* mem;
+
+    if (sz >= PTE_SZ) {
+        // goto panic;
+        // panic("inituvm: more than a page");
+    }
+
+    mem = alloc_page();
+    memset(mem, 0, PTE_SZ);
+    mappages(pgdir, 0, PTE_SZ, v2p(mem), AP_KU);
+    memmove(mem, init, sz);
+
+    goto next(...);
+}