annotate paper/cbc_interface.tex @ 10:a882e390f9a2

dummy, reference, thanks
author tobaru
date Sun, 02 Feb 2020 19:47:49 +0900
parents 737421115770
children f7ed2b4874f4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
1 \chapter{CbC インターフェース}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
2
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
3 構造図書く(今のcbcxv6と同じか確認してから)
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
4 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
5
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
6
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
7 Gears OS では Meta Code Gear で Context から値を取り出し、ノーマルレベルの Code Gear に値を渡す。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
8 しかし、Code Gaer がどの Data Gear の番号に対応するかを指定する必要があったり、 % ぱるすさんコード必要?
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
9 ノーマルレベルとメタレベルで見え方が異なる Data Gear を Meta Code Gear によって 調整する必要があったりと、 % みつきさん
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
10 メタレベルからノーマルレベルの継続の記述が煩雑になるため、Interface 化をしている。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
11 Interface は Data Gear に対しての操作を行う Code Gear であり、実装は別で定義する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
12 % Interface で定義した Code Gear に
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
13
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
14
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
15 % Xv6 の書き換えは Interface を用いてモジュール化する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
16 そうすることで Gears OS の機能を置き換えることできるようになる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
17
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
18
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
19
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
20 \section{インターフェースの定義}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
21 インターフェースはある Data Gear の定義と、
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
22 それに対する操作を行う Code Gear の集合を表現する Meta Data Gear である。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
23 Context では全ての Code Gaer と Data Gear の集合を表現していることに対し、
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
24 インターフェースは一部の Code Gear と一部の Data Gear の集合を表現する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
25 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
26 インターフェースを記述することによってノーマルレベルとメタレベルの分離が可能となる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
27
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
28 Paging のインターフェースを記述したコードを \ref{interface} に示す。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
29
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
30
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
31 \begin{lstlisting}[frame=lrbt,label=interface,caption={\footnotesize vm のインターフェース}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
32 typedef struct vm<Type,Impl> {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
33 union Data* vm;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
34 uint low;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
35 uint hi;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
36 struct proc* p;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
37 pde_t* pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
38 char* init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
39 uint sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
40 char* addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
41 struct inode* ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
42 uint offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
43 uint oldsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
44 uint newsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
45 char* uva;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
46 uint va;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
47 void* pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
48 uint len;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
49 uint phy_low;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
50 uint phy_hi;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
51 __code init_vmm(Impl* vm, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
52 __code kpt_freerange(Impl* vm, uint low, uint hi, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
53 __code kpt_alloc(Impl* vm ,__code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
54 __code switchuvm(Impl* vm ,struct proc* p, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
55 __code init_inituvm(Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
56 __code loaduvm(Impl* vm,pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
57 __code allocuvm(Impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
58 __code clearpteu(Impl* vm, pde_t* pgdir, char* uva, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
59 __code copyuvm(Impl* vm, pde_t* pgdir, uint sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
60 __code uva2ka(Impl* vm, pde_t* pgdir, char* uva, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
61 __code copyout(Impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
62 __code paging_int(Impl* vm, uint phy_low, uint phy_hi, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
63 __code void_ret(Impl* vm);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
64 __code next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
65 } vm;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
66 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
67
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
68
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
69 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
70 2行目から19行目で引数の Data Gear 郡を定義している。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
71 初期化された Data Gear が Code Gear の引数として扱われる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
72 例として、2行目で定義された vm が21行目から32行目までの引数と対応している。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
73 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
74 % インターフェースの Code Gear の goto による継続先は基本的に不定となっており、継続元から渡される。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
75 \_\_code next(...) の引数 ... は複数の Input Data Gear を持つという意味である。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
76 後述する実装によって条件分岐によって複数の継続先が設定されることがある。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
77 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
78 Code Gaer は 20行目から33行目のように "\_\_code [Code Gear名]([引数])"で定義する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
79 この引数が input Data Gear になる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
80
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
81
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
82 % 実装側に書く
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
83 % 引数の Data Gear はその Code Gear の Input Data Gear になり、引数の Code Gear の中の引 数が Output Data Gear になる。Code Gear の第一引数には Interface を実装した Data Gear を渡す。これは、Code Gear の操作の対象となる Data Gear を設定し ており、後述する継続構文では引数として記述を行わない。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
84
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
85
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
86 \section{インターフェースの実装}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
87 インターフェースは Data Gear に対しての Code Gear とその Code Gear で扱われている Data Gear の集合を抽象化した Meta Data Gear で、vm.c に対応する実装は別で定義する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
88 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
89
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
90
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
91
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
92
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
93 \begin{lstlisting}[frame=lrbt,label=impl_vm,caption={\footnotesize vm インターフェースの実装}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
94 #include "../../context.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
95 #interface "vm.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
96
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
97 vm* createvm_impl(struct Context* cbc_context) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
98 struct vm* vm = new vm();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
99 struct vm_impl* vm_impl = new vm_impl();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
100 vm->vm = (union Data*)vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
101 vm_impl->vm_impl = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
102 vm_impl->i = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
103 vm_impl->pte = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
104 vm_impl->sz = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
105 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
106 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
107 vm_impl->allocuvm_check_newsz = C_allocuvm_check_newszvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
108 vm_impl->allocuvm_loop = C_allocuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
109 vm_impl->copyuvm_check_null = C_copyuvm_check_nullvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
110 vm_impl->copyuvm_loop = C_copyuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
111 vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
112 vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
113 vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
114 vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
115 vm_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
116 vm->void_ret = C_vm_void_ret;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
117 vm->init_vmm = C_init_vmmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
118 vm->kpt_freerange = C_kpt_freerangevm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
119 vm->kpt_alloc = C_kpt_allocvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
120 vm->switchuvm = C_switchuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
121 vm->init_inituvm = C_init_inituvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
122 vm->loaduvm = C_loaduvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
123 vm->allocuvm = C_allocuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
124 vm->clearpteu = C_clearpteuvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
125 vm->copyuvm = C_copyuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
126 vm->uva2ka = C_uva2kavm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
127 vm->copyout = C_copyoutvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
128 vm->paging_int = C_paging_intvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
129 return vm;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
130 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
131 extern struct {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
132 struct spinlock lock;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
133 struct run *freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
134 } kpt_mem;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
135
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
136 __code init_vmmvm_impl(struct vm_impl* vm,__code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
137 initlock(&kpt_mem.lock, "vm");
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
138 kpt_mem.freelist = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
139
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
140 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
141 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
142
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
143 extern struct run {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
144 struct run *next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
145 };
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
146
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
147 static void _kpt_free (char *v)
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
148 {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
149 struct run *r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
150
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
151 r = (struct run*) v;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
152 r->next = kpt_mem.freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
153 kpt_mem.freelist = r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
154 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
155
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
156 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
157
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
158 if (low < hi) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
159 _kpt_free((char*)low);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
160 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
161
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
162 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
163 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
164 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
165
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
166 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
167 acquire(&kpt_mem.lock);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
168
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
169 goto kpt_alloc_check_impl(vm_impl, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
170 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
171
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
172 typedef struct proc proc;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
173 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
174
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
175 goto switchuvm_check_pgdirvm_impl(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
176 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
177
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
178 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
179
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
180 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
181 Gearef(cbc_context, vm_impl)->init = init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
182 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
183 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
184 goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
185 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
186
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
187 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
188 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
189 Gearef(cbc_context, vm_impl)->addr = addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
190 Gearef(cbc_context, vm_impl)->ip = ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
191 Gearef(cbc_context, vm_impl)->offset = offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
192 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
193 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
194
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
195 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
196 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
197
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
198 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
199
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
200 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
201 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
202
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
203 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
204
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
205 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
206 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
207
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
208 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
209
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
210 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
211 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
212
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
213 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
214
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
215 goto uva2ka_check_pe_types(vm, pgdir, uva, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
216 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
217
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
218 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
219
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
220 vm->buf = (char*) pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
221
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
222 goto copyout_loopvm_impl(vm, pgdir, va, pp, len, va0, pa0, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
223 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
224
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
225 __code paging_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
226
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
227 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
228 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
229
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
230 __code vm_void_ret(struct vm_impl* vm) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
231 return;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
232 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
233
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
234
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
235 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
236
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
237
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
238 \section{インターフェース内の private メソッド}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
239 インターフェースで定義した Code Gear 以外の Code Gaer も記述することができる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
240 この Code Gear は基本的にインターフェースで指定された Code Gear 内からのみ継続されるため、
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
241 Java の private メソッドのように扱われる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
242
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
243
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
244
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
245 \begin{lstlisting}[frame=lrbt,label=impl_vm_privateh,caption={\footnotesize vm private のヘッダーファイル}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
246
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
247 typedef struct vm_impl<Impl, Isa> impl vm{
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
248 union Data* vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
249 uint i;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
250 pte_t* pte;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
251 uint sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
252 pde_t* pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
253 char* addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
254 struct inode* ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
255 uint offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
256 uint pa;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
257 uint n;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
258 uint oldsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
259 uint newsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
260 uint a;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
261 int ret;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
262 char* mem;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
263 char* uva;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
264 pde_t* d;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
265 uint ap;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
266 uint phy_low;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
267 uint phy_hi;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
268 uint va;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
269 void* pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
270 uint len;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
271 char* buf;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
272 char* pa0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
273 uint va0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
274 proc_struct* p;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
275 char* init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
276
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
277 __code kpt_alloc_check_impl(Type* vm_impl, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
278 __code loaduvm_ptesize_check(Type* vm_impl, __code next(int ret, ...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
279 __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(int ret, ...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
280 __code allocuvm_check_newsz(Type* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
281 __code allocuvm_loop(Type* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, uint a, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
282 __code copyuvm_check_null(Type* vm_impl, pde_t* pgdir, uint sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
283 __code copyuvm_loop(Type* 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, ...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
284 __code clearpteu_check_ptevm_impl(Type* vm_impl, pde_t* pgdir, char* uva, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
285 __code uva2ka_check_pe_types(Type* vm_impl, pde_t* pgdir, char* uva, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
286 __code paging_intvm_impl(Type* vm_impl, uint phy_low, uint phy_hi, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
287 __code copyout_loopvm_impl(Type* vm_impl, pde_t* pgdir, uint va, void* pp, uint len, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
288 __code switchuvm_check_pgdirvm_impl(struct vm_impl* vm_impl, struct proc* p, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
289 __code init_inituvm_check_sz(struct vm_impl* vm_impl, pde_t* pgdir, char* init, uint sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
290 __code void_ret(Type* vm_impl);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
291 __code next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
292 } vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
293
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
294 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
295
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
296 \begin{lstlisting}[frame=lrbt,label=impl_vm_private,caption={\footnotesize vm private の実装}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
297 #include "../../context.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
298 #interface "vm.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
299
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
300 vm* createvm_impl(struct Context* cbc_context) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
301 struct vm* vm = new vm();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
302 struct vm_impl* vm_impl = new vm_impl();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
303 vm->vm = (union Data*)vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
304 vm_impl->vm_impl = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
305 vm_impl->i = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
306 vm_impl->pte = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
307 vm_impl->sz = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
308 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
309 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
310 vm_impl->allocuvm_check_newsz = C_allocuvm_check_newszvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
311 vm_impl->allocuvm_loop = C_allocuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
312 vm_impl->copyuvm_check_null = C_copyuvm_check_nullvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
313 vm_impl->copyuvm_loop = C_copyuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
314 vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
315 vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
316 vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
317 vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
318 vm_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
319 vm->void_ret = C_vm_void_ret;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
320 vm->init_vmm = C_init_vmmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
321 vm->kpt_freerange = C_kpt_freerangevm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
322 vm->kpt_alloc = C_kpt_allocvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
323 vm->switchuvm = C_switchuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
324 vm->init_inituvm = C_init_inituvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
325 vm->loaduvm = C_loaduvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
326 vm->allocuvm = C_allocuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
327 vm->clearpteu = C_clearpteuvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
328 vm->copyuvm = C_copyuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
329 vm->uva2ka = C_uva2kavm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
330 vm->copyout = C_copyoutvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
331 vm->paging_int = C_paging_intvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
332 return vm;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
333 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
334
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
335 extern struct {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
336 struct spinlock lock;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
337 struct run *freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
338 } kpt_mem;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
339
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
340 __code init_vmmvm_impl(struct vm_impl* vm,__code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
341 initlock(&kpt_mem.lock, "vm");
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
342 kpt_mem.freelist = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
343
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
344 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
345 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
346
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
347 extern struct run {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
348 struct run *next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
349 };
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
350
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
351 static void _kpt_free (char *v)
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
352 {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
353 struct run *r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
354
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
355 r = (struct run*) v;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
356 r->next = kpt_mem.freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
357 kpt_mem.freelist = r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
358 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
359
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
360 __code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
361
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
362 if (low < hi) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
363 _kpt_free((char*)low);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
364 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
365
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
366 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
367 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
368 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
369 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
370 acquire(&kpt_mem.lock);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
371
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
372 goto kpt_alloc_check_impl(vm_impl, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
373 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
374
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
375 typedef struct proc proc;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
376 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
377
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
378 goto switchuvm_check_pgdirvm_impl(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
379 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
380
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
381 __code init_inituvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
382
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
383 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
384 Gearef(cbc_context, vm_impl)->init = init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
385 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
386 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
387 goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
388 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
389
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
390 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
391 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
392 Gearef(cbc_context, vm_impl)->addr = addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
393 Gearef(cbc_context, vm_impl)->ip = ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
394 Gearef(cbc_context, vm_impl)->offset = offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
395 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
396 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
397
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
398 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
399 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
400
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
401 __code allocuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
402
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
403 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
404 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
405
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
406 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
407
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
408 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
409 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
410
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
411 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
412
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
413 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
414 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
415
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
416 __code uva2kavm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
417
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
418 goto uva2ka_check_pe_types(vm, pgdir, uva, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
419 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
420
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
421 __code copyoutvm_impl(struct vm_impl* vm, pde_t* pgdir, uint va, void* pp, uint len, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
422
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
423 vm->buf = (char*) pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
424
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
425 goto copyout_loopvm_impl(vm, pgdir, va, pp, len, va0, pa0, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
426 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
427
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
428 __code paging_intvm_impl(struct vm_impl* vm, uint phy_low, uint phy_hi, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
429
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
430 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
431 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
432
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
433 __code vm_void_ret(struct vm_impl* vm) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
434 return;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
435 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
436
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
437 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
438
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
439
10
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
440 \section{インターフェースの呼び出し}
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
441 CbC の場合 goto による遷移を行うので、関数呼び出しのように goto 以降のコードを実行できない。
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
442 例として、\ref{cbc_goto} の16行目のように goto によってインターフェースで定義した命令を行うと、戻ってこれないため17行目以降が実行されなくなる。
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
443
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
444
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
445 \begin{lstlisting}[frame=lrbt,label=cbc_goto,caption={\footnotesize cbc インターフェースのgoto}]
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
446
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
447 void userinit(void)
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
448 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
449 struct proc* p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
450 extern char _binary_initcode_start[], _binary_initcode_size[];
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
451
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
452 p = allocproc();
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
453 initContext(&p->cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
454
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
455 initproc = p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
456
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
457 if((p->pgdir = kpt_alloc()) == NULL) {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
458 panic("userinit: out of memory?");
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
459 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
460
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
461 goto cbc_init_vmm_dummy(&p->cbc_context, p, p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
462 p->sz = PTE_SZ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
463
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
464 // craft the trapframe as if
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
465 memset(p->tf, 0, sizeof(*p->tf));
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
466
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
467
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
468 \end{lstlisting}
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
469
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
470
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
471
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
472
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
473 \begin{lstlisting}[frame=lrbt,label=impl_vm_private,caption={\footnotesize vm private の実装}]
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
474
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
475
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
476 void dummy(struct proc *p, char _binary_initcode_start[], char _binary_initcode_size[])
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
477 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
478 // inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
479 goto cbc_init_vmm_dummy(&p->cbc_context, p, p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
480
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
481 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
482
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
483
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
484
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
485 __ncode cbc_init_vmm_dummy(struct Context* cbc_context, struct proc* p, pde_t* pgdir, char* init, uint sz){//:skip
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
486
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
487 struct vm* vm = createvm_impl(cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
488 // goto vm->init_vmm(vm, pgdir, init, sz , vm->void_ret);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
489 Gearef(cbc_context, vm)->vm = (union Data*) vm;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
490 Gearef(cbc_context, vm)->pgdir = pgdir;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
491 Gearef(cbc_context, vm)->init = init;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
492 Gearef(cbc_context, vm)->sz = sz ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
493 Gearef(cbc_context, vm)->next = C_vm_void_ret ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
494 goto meta(cbc_context, vm->init_inituvm);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
495 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
496
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
497
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
498 void userinit(void)
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
499 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
500 struct proc* p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
501 extern char _binary_initcode_start[], _binary_initcode_size[];
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
502
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
503 p = allocproc();
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
504 initContext(&p->cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
505
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
506 initproc = p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
507
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
508 if((p->pgdir = kpt_alloc()) == NULL) {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
509 panic("userinit: out of memory?");
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
510 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
511
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
512 dummy(p, _binary_initcode_start, _binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
513
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
514
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
515
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
516 \end{lstlisting}