Mercurial > hg > Members > menikon > CbC_xv6
changeset 210:ab5a80021afe
merge
author | menikon <e165723@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 23 Jan 2020 20:33:39 +0900 |
parents | b73c5bd61c37 (current diff) 02bb0f8be908 (diff) |
children | e2520f609094 |
files | |
diffstat | 5 files changed, 138 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gearsTools/lib/Gears/Context.pm Thu Jan 23 01:55:03 2020 +0900 +++ b/src/gearsTools/lib/Gears/Context.pm Thu Jan 23 20:33:39 2020 +0900 @@ -240,7 +240,7 @@ my $header_paths = Gears::Util->find_headers_path($search_bash_path); map { - if (/(\w+)\.(?:h|dg)/) { + if (/(\w+)\.(?:h|dg)$/) { my $header_file = $1; if (exists $res{$header_file}) { if ($res{$header_file} =~ /^\d+$/){
--- a/src/gearsTools/lib/Gears/Util.pm Thu Jan 23 01:55:03 2020 +0900 +++ b/src/gearsTools/lib/Gears/Util.pm Thu Jan 23 20:33:39 2020 +0900 @@ -40,6 +40,7 @@ sub _parse_base { my ($file,$code_verbose) = @_; my $ir = {}; + $ir->{file_name} = $file; Gears::Util->file_checking($file); open my $fh, '<', $file; @@ -153,10 +154,10 @@ sub h2context_str { my ($class, $h2context) = @_; - my $context = ''; my $space = ' '; - $context = "${space}struct $h2context->{name} {\n"; + my $context = "${space}//$h2context->{file_name}\n"; + $context .= "${space}struct $h2context->{name} {\n"; my $content_space; if (exists $h2context->{content}){ my @chars = split //, $h2context->{content}->[0];
--- a/src/impl/vm_impl.cbc Thu Jan 23 01:55:03 2020 +0900 +++ b/src/impl/vm_impl.cbc Thu Jan 23 20:33:39 2020 +0900 @@ -3,12 +3,13 @@ // ---- // typedef struct vm_impl<Impl, Isa> impl vm{ +// union Data* vm_impl; // uint i; -// pte_t *pte; -// unsigned int sz; +// pte_t* pte; +// uint sz; // // __code loaduvm_ptesize_check(Type* vm_impl, __code next(...)); -// __code loaduvm_loop(Type* vm_impl, uint i, pte_t *pte, unsigned int sz, __code next(...)); +// __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...)); // __code next(...); // // @@ -19,8 +20,12 @@ struct vm* vm = new vm(); struct vm_impl* vm_impl = new vm_impl(); vm->vm = (union Data*)vm_impl; + vm_impl->vm_impl = NULL; vm_impl->i = 0; - vm_impl->sz = 0; + vm_impl->pte = NULL; + vm_impl->sz = 0; + vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl; + vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl; vm->init_vmm = C_init_vmmvm_impl; vm->kpt_freerange = C_kpt_freerangevm_impl; vm->kpt_alloc = C_kpt_allocvm_impl; @@ -36,10 +41,15 @@ return vm; } - +extern struct { + struct spinlock lock; + struct run *freelist; +} kpt_mem; __code init_vmmvm_impl(struct vm_impl* vm, __code next(...)) { - + initlock(&kpt_mem.lock, "vm"); + kpt_mem.freelist = NULL; + goto next(...); } @@ -64,9 +74,14 @@ goto next(...); } -__code loaduvmvm_impl(struct vm_impl* vm,pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) { - - goto next(...); +__code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) { + vm->pgdir = pgdir; + vm->addr = addr; + vm->ip = ip; + vm->offset = offset; + vm->sz = sz; + + goto loaduvm_ptesize_checkvm_impl(vm, next); } __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) { @@ -99,4 +114,3 @@ goto next(...); } -
--- a/src/impl/vm_impl.h Thu Jan 23 01:55:03 2020 +0900 +++ b/src/impl/vm_impl.h Thu Jan 23 20:33:39 2020 +0900 @@ -1,10 +1,18 @@ typedef struct vm_impl<Impl, Isa> impl vm{ + union Data* vm_impl; uint i; pte_t* pte; - unsigned int sz; - + uint sz; + pde_t* pgdir; + char* addr; + struct inode* ip; + uint offset; + uint pa; + uint n; + + __code init_vmm(Type* vm_impl, __code next(...)); __code loaduvm_ptesize_check(Type* vm_impl, __code next(...)); - __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, unsigned int sz, __code next(...)); + __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...)); __code next(...);
--- a/src/impl/vm_impl_private.cbc Thu Jan 23 01:55:03 2020 +0900 +++ b/src/impl/vm_impl_private.cbc Thu Jan 23 20:33:39 2020 +0900 @@ -1,14 +1,108 @@ #include "../../context.h" +#include "mmu.h" +#include "memlayout.h" #interface "vm_impl.h" -#define __ncode + +/* +vm_impl* createvm_impl2(); +*/ + +__code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl, __code next(...)) { + char* addr = vm_impl->addr; -__ncode loaduvm_ptesize_checkvm_impl(struct vm_impl* vm, enum Code next) { + if ((uint) addr %PTE_SZ != 0) { + // goto panic + } + + goto loaduvm_loopvm_impl(vm_impl, next(...)); +} - // goto meta(); +__code loaduvm_loopvm_impl(struct vm_impl* vm_impl, __code next(...)) { + uint i = vm_impl->i; + uint sz = vm_impl->sz; + + if (i < sz) { + goto loaduvm_check_pgdir(vm_impl, next(...)); + } + + goto loaduvm_exit(vm_impl, next(...)); } -__ncode loaduvm_loopvm_impl(struct vm_impl* vm, uint* i, pte_t* pte, uint sz, enum Code 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)); - // goto meta(); + } 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(...)) { + pte_t* pte = vm_impl->pte; + pde_t* pgdir = vm_impl->pgdir; + uint i = vm_impl->i; + char* addr = vm_impl->addr; + uint pa = vm_impl->pa; + + if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) { + // goto panic + } + pa = PTE_ADDR(*pte); + + vm_impl->pte = pte; + vm_impl->pgdir = pgdir; + vm_impl->addr = addr; + vm_impl->pa = pa; + + goto loaduvm_check_PTE_SZ(vm_impl, next(...)); +} + +__code loaduvm_check_PTE_SZ(struct vm_impl* vm_impl, __code next(...)) { + uint sz = vm_impl->sz; + uint i = vm_impl->i; + uint n = vm_impl->n; + struct inode* ip = vm_impl->ip; + uint pa = vm_impl->pa; + uint offset = vm_impl->offset; + + if (sz - i < PTE_SZ) { + n = sz - i; + } else { + n = PTE_SZ; + } + + if (readi(ip, p2v(pa), offset + i, n) != n) { + // panic + // return -1; + } + + vm_impl->n = n; + + goto loaduvm_exit(vm_impl, next(...)); +} + +__code loaduvm_exit(struct vm_impl* vm_impl, __code next(...)) { + + goto next(...); +}