annotate paper/cbc_interface.tex @ 12:9cf9e0b086c7

fix private code
author tobaru
date Tue, 04 Feb 2020 15:35:28 +0900
parents f7ed2b4874f4
children 1ef114182e80
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
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
28 Paging のインターフェースを記述したコードを ソースコード \ref{interface} に示す。
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
29
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
30
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
31 \begin{lstlisting}[frame=lrbt,label=interface,caption={\footnotesize vm のインターフェースの定義(vm.h)}]
8
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
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
68 1行目ので実装名を定義している。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
69 typedef struct の直後に実装名(vm)を書く。
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
70 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
71 2行目から19行目で引数の Data Gear 郡を定義している。
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
72 初期化された Data Gear がそれぞれの Code Gear の引数として扱われる。
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
73 例として、2行目で定義された vm が21行目から32行目までの引数と対応している。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
74 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
75 % インターフェースの Code Gear の goto による継続先は基本的に不定となっており、継続元から渡される。
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
76 Code Gear は\_\_code CodeGearName () で記述する。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
77 第一引数である Impl* vm が Code Gear の型になる。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
78 \par
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
79 \_\_code next(...) の引数 ... は複数の 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 \par
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
82 Code Gaer は 20行目から33行目のように "\_\_code [Code Gear名]([引数])"で定義する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
83 この引数が input 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 % 実装側に書く
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
87 % 引数の 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
88
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
89
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
90 \section{インターフェースの実装}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
91 インターフェースは Data Gear に対しての Code Gear とその Code Gear で扱われている Data Gear の集合を抽象化した Meta Data Gear で、vm.c に対応する実装は別で定義する。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
92 \par
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
93 インターフェースの実装についてソースコード \ref{impl_vm} で示す。
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
94
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
95
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
96 \begin{lstlisting}[frame=lrbt,label=impl_vm,caption={\footnotesize vm インターフェースの実装}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
97 #include "../../context.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
98 #interface "vm.h"
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
99
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
100 vm* createvm_impl(struct Context* cbc_context) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
101 struct vm* vm = new vm();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
102 struct vm_impl* vm_impl = new vm_impl();
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
103 vm->vm = (union Data*)vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
104 vm_impl->vm_impl = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
105 vm_impl->i = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
106 vm_impl->pte = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
107 vm_impl->sz = 0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
108 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
109 vm_impl->loaduvm_loop = C_loaduvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
110 vm_impl->allocuvm_check_newsz = C_allocuvm_check_newszvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
111 vm_impl->allocuvm_loop = C_allocuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
112 vm_impl->copyuvm_check_null = C_copyuvm_check_nullvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
113 vm_impl->copyuvm_loop = C_copyuvm_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
114 vm_impl->uva2ka_check_pe_types = C_uva2ka_check_pe_types;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
115 vm_impl->paging_intvm_impl = C_paging_intvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
116 vm_impl->copyout_loopvm_impl = C_copyout_loopvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
117 vm_impl->switchuvm_check_pgdirvm_impl = C_switchuvm_check_pgdirvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
118 vm_impl->init_inituvm_check_sz = C_init_inituvm_check_sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
119 vm->void_ret = C_vm_void_ret;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
120 vm->init_vmm = C_init_vmmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
121 vm->kpt_freerange = C_kpt_freerangevm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
122 vm->kpt_alloc = C_kpt_allocvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
123 vm->switchuvm = C_switchuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
124 vm->init_inituvm = C_init_inituvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
125 vm->loaduvm = C_loaduvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
126 vm->allocuvm = C_allocuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
127 vm->clearpteu = C_clearpteuvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
128 vm->copyuvm = C_copyuvmvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
129 vm->uva2ka = C_uva2kavm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
130 vm->copyout = C_copyoutvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
131 vm->paging_int = C_paging_intvm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
132 return vm;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
133 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
134 extern struct {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
135 struct spinlock lock;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
136 struct run *freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
137 } kpt_mem;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
138
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
139 __code init_vmmvm_impl(struct vm_impl* vm,__code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
140 initlock(&kpt_mem.lock, "vm");
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
141 kpt_mem.freelist = NULL;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
142
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
143 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
144 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
145
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
146 extern struct run {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
147 struct run *next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
148 };
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
149
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
150 static void _kpt_free (char *v)
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
151 {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
152 struct run *r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
153
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
154 r = (struct run*) v;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
155 r->next = kpt_mem.freelist;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
156 kpt_mem.freelist = r;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
157 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
158
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
159 __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
160
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
161 if (low < hi) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
162 _kpt_free((char*)low);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
163 goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, 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 goto next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
167 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
168
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
169 __code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
170 acquire(&kpt_mem.lock);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
171
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
172 goto kpt_alloc_check_impl(vm_impl, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
173 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
174
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
175 typedef struct proc proc;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
176 __code switchuvmvm_impl(struct vm_impl* vm , struct proc* p, __code next(...)) { //:skip
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
177
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
178 goto switchuvm_check_pgdirvm_impl(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
179 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
180
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
181 __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
182
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
183 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
184 Gearef(cbc_context, vm_impl)->init = init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
185 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
186 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
187 goto init_inituvm_check_sz(vm, pgdir, init, sz, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
188 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
189
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
190 __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
191 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
192 Gearef(cbc_context, vm_impl)->addr = addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
193 Gearef(cbc_context, vm_impl)->ip = ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
194 Gearef(cbc_context, vm_impl)->offset = offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
195 Gearef(cbc_context, vm_impl)->sz = sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
196 Gearef(cbc_context, vm_impl)->next = next;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
197
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
198 goto loaduvm_ptesize_checkvm_impl(vm, 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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
201 __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
202
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
203 goto allocuvm_check_newszvm_impl(vm, pgdir, oldsz, newsz, 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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
206 __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
207
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
208 goto clearpteu_check_ptevm_impl(vm, pgdir, uva, 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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
211 __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
212
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
213 goto copyuvm_check_nullvm_impl(vm, pgdir, sz, __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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
216 __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
217
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
218 goto uva2ka_check_pe_types(vm, pgdir, uva, 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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
221 __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
222
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
223 vm->buf = (char*) pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
224
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
225 goto copyout_loopvm_impl(vm, pgdir, va, pp, len, va0, pa0, 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
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
228 __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
229
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
230 goto paging_intvmvm_impl(vm, phy_low, phy_hi, next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
231 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
232
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
233 __code vm_void_ret(struct vm_impl* vm) {
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
234 return;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
235 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
236
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
237 \end{lstlisting}
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
238
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
239
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
240 2行目のようにインターフェースのヘッダーファイルは \#interface で呼び出す。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
241 \par
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
242 create\_impl の関数内で、インターフェースを vm で定義し、23行目の vm-$>$void\_ret のようにそれぞれのインターフェースに対応させていく。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
243 \par
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
244 CbCは1つ1つの関数の信頼性を保障させるために細かくする必要があるので、for文やif文がある場合はさらに実装を分ける。vm と同じように vm\_impl を定義し、遷移する関数名に対応させていく。分けた実装はさらに別で実装する(vm\_impl\_private.cbc)。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
245
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
246
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
247 % インターフェースを呼び出す場合は、struct vm* vm = createvm_impl(cbc_context);
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
248 \par
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
249
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
250
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
251
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
252
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
253
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
254
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
255
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
256
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
257 \section{インターフェース内の private メソッド}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
258 インターフェースで定義した Code Gear 以外の Code Gaer も記述することができる。
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
259 この Code Gear は基本的にインターフェースで指定された Code Gear 内からのみ継続されるため、
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
260 Java の private メソッドのように扱われる。
11
f7ed2b4874f4 xv6 reference
tobaru
parents: 10
diff changeset
261 \par
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
262 インターフェースと同じようにヘッダーファイルをソースコード \ref{impl_vm_privateh} で定義する。
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
263
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
264
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
265 \begin{lstlisting}[frame=lrbt,label=impl_vm_privateh,caption={\footnotesize vm private のヘッダーファイル}]
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
266 typedef struct vm_impl<Impl, Isa> impl vm{
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
267 union Data* vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
268 uint i;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
269 pte_t* pte;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
270 uint sz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
271 pde_t* pgdir;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
272 char* addr;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
273 struct inode* ip;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
274 uint offset;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
275 uint pa;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
276 uint n;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
277 uint oldsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
278 uint newsz;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
279 uint a;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
280 int ret;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
281 char* mem;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
282 char* uva;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
283 pde_t* d;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
284 uint ap;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
285 uint phy_low;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
286 uint phy_hi;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
287 uint va;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
288 void* pp;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
289 uint len;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
290 char* buf;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
291 char* pa0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
292 uint va0;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
293 proc_struct* p;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
294 char* init;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
295
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
296 __code kpt_alloc_check_impl(Type* vm_impl, __code next(...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
297 __code loaduvm_ptesize_check(Type* vm_impl, __code next(int ret, ...));
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
298 __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
299 __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
300 __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
301 __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
302 __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
303 __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
304 __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
305 __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
306 __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
307 __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
308 __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
309 __code void_ret(Type* vm_impl);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
310 __code next(...);
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
311 } vm_impl;
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
312
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
313 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
314
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
315
11
f7ed2b4874f4 xv6 reference
tobaru
parents: 10
diff changeset
316
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
317 private での CbC の記述を vm.c と比べて説明する。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
318 全体の記述量が多いため、if文とfor文のある loaduvm という関数で説明を行う。
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
319
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
320
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
321 \begin{lstlisting}[frame=lrbt,label=vm_loaduvm,caption={\footnotesize vm.c のloaduvm}]
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
322
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
323 int loaduvm (pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
324 {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
325 uint i, pa, n;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
326 pte_t *pte;
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
327
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
328 if ((uint) addr % PTE_SZ != 0) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
329 panic("loaduvm: addr must be page aligned");
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
330 }
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
331
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
332 for (i = 0; i < sz; i += PTE_SZ) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
333 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
334 panic("loaduvm: address should exist");
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
335 }
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
336
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
337 pa = PTE_ADDR(*pte);
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
338
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
339 if (sz - i < PTE_SZ) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
340 n = sz - i;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
341 } else {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
342 n = PTE_SZ;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
343 }
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
344
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
345 if (readi(ip, p2v(pa), offset + i, n) != n) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
346 return -1;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
347 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
348 }
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
349
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
350 return 0;
8
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
351 }
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
352
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
353 \end{lstlisting}
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
354
737421115770 chapter cbc_interface and impl_paging
tobaru
parents:
diff changeset
355
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
356
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
357
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
358 \begin{lstlisting}[frame=lrbt,label=impl_vm_loaduvm,caption={\footnotesize privateでの loaduvm の実装}]
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
359 #interface "vm_impl.h"
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
360
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
361 __code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl, __code next(int ret, ...)) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
362 char* addr = vm_impl->addr;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
363
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
364 if ((uint) addr %PTE_SZ != 0) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
365 // goto panic
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
366 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
367
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
368 goto loaduvm_loopvm_impl(vm_impl, next(ret, ...));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
369 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
370
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
371 __code loaduvm_loopvm_impl(struct vm_impl* vm_impl, __code next(int ret, ...)) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
372 uint i = vm_impl->i;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
373 uint sz = vm_impl->sz;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
374
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
375 if (i < sz) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
376 goto loaduvm_check_pgdir(vm_impl, next(ret, ...));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
377 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
378
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
379 goto loaduvm_exit(vm_impl, next(ret, ...));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
380 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
381
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
382
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
383 static pte_t* walkpgdir (pde_t *pgdir, const void *va, int alloc)
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
384 {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
385 pde_t *pde;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
386 pte_t *pgtab;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
387
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
388 // pgdir points to the page directory, get the page direcotry entry (pde)
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
389 pde = &pgdir[PDE_IDX(va)];
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
390
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
391 if (*pde & PE_TYPES) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
392 pgtab = (pte_t*) p2v(PT_ADDR(*pde));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
393
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
394 } else {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
395 if (!alloc || (pgtab = (pte_t*) kpt_alloc()) == 0) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
396 return 0;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
397 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
398
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
399 // Make sure all those PTE_P bits are zero.
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
400 memset(pgtab, 0, PT_SZ);
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
401
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
402 // The permissions here are overly generous, but they can
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
403 // be further restricted by the permissions in the page table
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
404 // entries, if necessary.
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
405 *pde = v2p(pgtab) | UPDE_TYPE;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
406 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
407
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
408 return &pgtab[PTE_IDX(va)];
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
409 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
410
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
411
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
412 __code loaduvm_check_pgdir(struct vm_impl* vm_impl, __code next(int ret, ...)) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
413 pte_t* pte = vm_impl->pte;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
414 pde_t* pgdir = vm_impl->pgdir;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
415 uint i = vm_impl->i;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
416 char* addr = vm_impl->addr;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
417 uint pa = vm_impl->pa;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
418
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
419 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
420 // goto panic
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
421 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
422 pa = PTE_ADDR(*pte);
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
423
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
424 vm_impl->pte = pte;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
425 vm_impl->pgdir = pgdir;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
426 vm_impl->addr = addr;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
427 vm_impl->pa = pa;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
428
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
429 goto loaduvm_check_PTE_SZ(vm_impl, next(ret, ...));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
430 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
431
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
432 __code loaduvm_check_PTE_SZ(struct vm_impl* vm_impl, __code next(int ret, ...)) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
433 uint sz = vm_impl->sz;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
434 uint i = vm_impl->i;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
435 uint n = vm_impl->n;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
436 struct inode* ip = vm_impl->ip;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
437 uint pa = vm_impl->pa;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
438 uint offset = vm_impl->offset;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
439
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
440 if (sz - i < PTE_SZ) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
441 n = sz - i;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
442 } else {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
443 n = PTE_SZ;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
444 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
445
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
446 if (readi(ip, p2v(pa), offset + i, n) != n) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
447 ret = -1;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
448 goto next(ret, ...);
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
449 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
450
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
451 vm_impl->n = n;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
452
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
453 goto loaduvm_loopvm_impl(vm_impl, next(ret, ...));
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
454 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
455
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
456 __code loaduvm_exit(struct vm_impl* vm_impl, __code next(int ret, ...)) {
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
457 ret = 0;
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
458 goto next(ret, ...);
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
459 }
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
460
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
461 \end{lstlisting}
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
462
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
463
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
464
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
465
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
466
10
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
467 \section{インターフェースの呼び出し}
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
468 定義したインターフェースの呼び出し方について説明する。
10
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
469 CbC の場合 goto による遷移を行うので、関数呼び出しのように goto 以降のコードを実行できない。
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
470 例として、ソースコード \ref{cbc_goto} の16行目のように goto によってインターフェースで定義した命令を行うと、戻ってこれないため17行目以降が実行されなくなる。
10
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=cbc_goto,caption={\footnotesize cbc インターフェースのgoto}]
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
474
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
475 void userinit(void)
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
476 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
477 struct proc* p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
478 extern char _binary_initcode_start[], _binary_initcode_size[];
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
479
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
480 p = allocproc();
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
481 initContext(&p->cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
482
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
483 initproc = p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
484
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
485 if((p->pgdir = kpt_alloc()) == NULL) {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
486 panic("userinit: out of memory?");
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
487 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
488
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
489 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
490 p->sz = PTE_SZ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
491
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
492 // craft the trapframe as if
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
493 memset(p->tf, 0, sizeof(*p->tf));
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
494
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
495
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
496 \end{lstlisting}
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
497
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
498
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
499
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
500
11
f7ed2b4874f4 xv6 reference
tobaru
parents: 10
diff changeset
501 \begin{lstlisting}[frame=lrbt,label=dummy,caption={\footnotesize dummy を使った呼び出し}]
10
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
502
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
503
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
504 void dummy(struct proc *p, char _binary_initcode_start[], char _binary_initcode_size[])
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
505 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
506 // inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
507 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
508
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
509 }
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
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
513 __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
514
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
515 struct vm* vm = createvm_impl(cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
516 // goto vm->init_vmm(vm, pgdir, init, sz , vm->void_ret);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
517 Gearef(cbc_context, vm)->vm = (union Data*) vm;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
518 Gearef(cbc_context, vm)->pgdir = pgdir;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
519 Gearef(cbc_context, vm)->init = init;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
520 Gearef(cbc_context, vm)->sz = sz ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
521 Gearef(cbc_context, vm)->next = C_vm_void_ret ;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
522 goto meta(cbc_context, vm->init_inituvm);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
523 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
524
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
525
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
526 void userinit(void)
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
527 {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
528 struct proc* p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
529 extern char _binary_initcode_start[], _binary_initcode_size[];
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
530
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
531 p = allocproc();
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
532 initContext(&p->cbc_context);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
533
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
534 initproc = p;
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
535
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
536 if((p->pgdir = kpt_alloc()) == NULL) {
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
537 panic("userinit: out of memory?");
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
538 }
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
539
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
540 dummy(p, _binary_initcode_start, _binary_initcode_size);
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
541
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
542
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
543
a882e390f9a2 dummy, reference, thanks
tobaru
parents: 8
diff changeset
544 \end{lstlisting}
12
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
545 ソースコードの説明
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
546
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
547
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
548
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
549
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
550
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
551
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
552
9cf9e0b086c7 fix private code
tobaru
parents: 11
diff changeset
553