annotate src/impl/vm_impl.cbc @ 202:66db83ec1ec2

kpt_alloc_check_impl and freerange
author tobaru
date Thu, 23 Jan 2020 20:48:16 +0900
parents 02bb0f8be908
children 6e03cee9733e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
192
tobaru
parents: 190
diff changeset
1 #include "../../context.h"
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
2 #interface "vm.h"
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
3
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
4 // ----
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
5 // typedef struct vm_impl<Impl, Isa> impl vm{
196
anatofuz
parents: 195
diff changeset
6 // union Data* vm_impl;
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
7 // uint i;
196
anatofuz
parents: 195
diff changeset
8 // pte_t* pte;
anatofuz
parents: 195
diff changeset
9 // uint sz;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
10 //
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
11 // __code loaduvm_ptesize_check(Type* vm_impl, __code next(...));
196
anatofuz
parents: 195
diff changeset
12 // __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...));
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
13 // __code next(...);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
14 //
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
15 //
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
16 // } vm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
17 // ----
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
18
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
19 vm* createvm_impl(struct Context* cbc_context) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
20 struct vm* vm = new vm();
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
21 struct vm_impl* vm_impl = new vm_impl();
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
22 vm->vm = (union Data*)vm_impl;
196
anatofuz
parents: 195
diff changeset
23 vm_impl->vm_impl = NULL;
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
24 vm_impl->i = 0;
196
anatofuz
parents: 195
diff changeset
25 vm_impl->pte = NULL;
anatofuz
parents: 195
diff changeset
26 vm_impl->sz = 0;
anatofuz
parents: 195
diff changeset
27 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
anatofuz
parents: 195
diff changeset
28 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
29 vm->init_vmm = C_init_vmmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
30 vm->kpt_freerange = C_kpt_freerangevm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
31 vm->kpt_alloc = C_kpt_allocvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
32 vm->switchuvm = C_switchuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
33 vm->init_inituvm = C_init_inituvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
34 vm->loaduvm = C_loaduvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
35 vm->allocuvm = C_allocuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
36 vm->clearpteu = C_clearpteuvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
37 vm->copyuvm = C_copyuvmvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
38 vm->uva2ka = C_uva2kavm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
39 vm->copyout = C_copyoutvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
40 vm->pagind_int = C_pagind_intvm_impl;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
41 return vm;
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
42 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
43
201
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
44 extern struct {
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
45 struct spinlock lock;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
46 struct run *freelist;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
47 } kpt_mem;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
48
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
49 __code init_vmmvm_impl(struct vm_impl* vm, __code next(...)) {
201
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
50 initlock(&kpt_mem.lock, "vm");
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
51 kpt_mem.freelist = NULL;
02bb0f8be908 rewrite init_vmm by cbc
tobaru
parents: 197
diff changeset
52
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
53 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
54 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
55
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
56 extern struct run {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
57 struct run *next;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
58 };
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
59
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
60 static void _kpt_free (char *v)
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
61 {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
62 struct run *r;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
63
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
64 r = (struct run*) v;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
65 r->next = kpt_mem.freelist;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
66 kpt_mem.freelist = r;
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
67 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
68
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
69 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
70
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
71 if (low < hi) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
72 _kpt_free((char*)low);
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
73 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
74
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
75 }
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
76 goto next(...);
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
77 }
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
78 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
79 struct run *r;
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
80 acquire(&kpt_mem.lock);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
81
202
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
82 goto kpt_alloc_check_impl(vm_impl, r, next(...));
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
83
66db83ec1ec2 kpt_alloc_check_impl and freerange
tobaru
parents: 201
diff changeset
84 goto next(...);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
85 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
86
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
87 typedef struct proc proc;
196
anatofuz
parents: 195
diff changeset
88 __code switchuvmvm_impl(struct vm_impl* vm ,struct proc* p, __code next(...)) { //:skip
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
89
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
90 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
91 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
92
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
93 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) { //:skip
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
94
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
95 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
96 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
97
197
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
98 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
99 vm->pgdir = pgdir;
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
100 vm->addr = addr;
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
101 vm->ip = ip;
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
102 vm->offset = offset;
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
103 vm->sz = sz;
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
104
3cac4139b31d send arg at vm_impl
tobaru
parents: 196
diff changeset
105 goto loaduvm_ptesize_checkvm_impl(vm, next);
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
106 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
107
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
108 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
109
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
110 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
111 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
112
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
113 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
114
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
115 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
116 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
117
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
118 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
119
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
120 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
121 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
122
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
123 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
124
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
125 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
126 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
127
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
128 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
129
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
130 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
131 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
132
193
1301727600cc success build
anatofuz
parents: 192
diff changeset
133 __code pagind_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
190
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
134
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
135 goto next(...);
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
136 }
14aa35b56347 add page table interface
tobaru
parents:
diff changeset
137