annotate slide/CbCXv6.md @ 48:eb651ae37444 default tip

fix spell
author tobaru
date Sat, 07 Mar 2020 01:29:41 +0900
parents e68c3bd31098
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
1 # CbCインターフェースによる CbCXv6 の書き換え
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
2 - 並列信頼研
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
3 - 桃原 優
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
4
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
5 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
6
21
tobaru
parents: 19
diff changeset
7 # 概要
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
8 - OS の信頼性を上げたい
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
9 - CbCという言語を使って xv6 という OS を書き換える
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
10 - Paging の書き換えを行った
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
11 - 実装中だが、将来はコンテナやVMを実装できるはず
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
12
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
13 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
14
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
15 # OS の信頼性を上げたい
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
16 - OS自体が複雑で検証が困難。
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
17 - バグの原因に
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
18 - OSの仕様を定義してそれを満たすことを証明する
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
19 - 証明しやすい形の記述を作る
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
20 - CbCの goto で書く
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
21 - 状態遷移系に近い形で記述できる(証明しやすい)
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
22 - 関数型の記述
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
23 - 入力に対しての出力を検証する
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
24 - 記述のモジュール化
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
25 - CbCのインターフェースで書く
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
26 - 煩雑な記述の解消
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
27 - 入力の切り替えによる機能の入れ替え
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
28
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
29 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
30
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
31 # ノーマルレベルとメタレベル
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
32 - ノーマルレベル
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
33 - CbCで記述される部分
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
34 - メタレベル
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
35 - Paging などのメモリやCPU自体の操作
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
36 - (ノーマルレベルの)プログラムの正しさの証明
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
37 - cmake で生成している
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
38
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
39 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
40
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
41 # Continuation based C
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
42 - 状態遷移ベースで記述できる言語(以下CbC)
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
43 - cmake で CbC からメタレベルの記述を生成する
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
44 - Code Gear
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
45 - 基本的な処理の単位
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
46 - goto 文で遷移する
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
47 - Data Gear
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
48 - Code Gear からアクセスできるデータの単位
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
49 - 引数など
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
50 - Meta Code Gear
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
51 - Code Gear の間に挟まれるメタレベルの処理
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
52 - Meta Data Gear
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
53 - Code Gearの間の接続などの情報
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
54 - Context(後ほど説明)
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
55
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
56 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
57
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
58 # ノーマルレベル
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
59
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
60 ---
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
61 # Code Gear による継続
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
62 - Code Gear の処理の間を goto によって遷移していく
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
63 - __code CodeGear名 で定義
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
64 ![](https://i.imgur.com/etfQund.png)
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
65
19
tobaru
parents: 18
diff changeset
66
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
67 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
68
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
69 # Data Gear の継続
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
70 - Code Gear からアクセスできるデータ
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
71 - input Data Gear と Output Data Gear で証明する
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
72
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
73 ![](https://i.imgur.com/3E0DGWA.png)
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
74
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
75 ---
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
76 # メタレベル
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
77
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
78 ---
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
79
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
80 # Meta Code Gear
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
81 - メタレベルで見ると Code Gear の間にメタレベルの処理が挟まっている
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
82 - cmake で __code CodeGear名_stub が生成される
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
83 ![](https://i.imgur.com/vy0NxrG.png)
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
84
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
85 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
86
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
87 # Meta Data Gear
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
88 - ノーマルレベルでの書き換えやアクセスを防ぐために存在
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
89 - CbC の 接続可能な Code Gear, Data Gear のリスト
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
90 - Data Gear を確保するメモリ空間
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
91 - Context
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
92
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
93 ---
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
94
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
95 # Context
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
96 - Meta Data Gear
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
97 - Contextには全てのData Gear と Code Gear が登録されている
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
98 - Xv6ではユーザープロセスに対応して1つのcontextが存在する
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
99 - 将来的なVMやコンテナの実装はContextの切り替えるによる実装を目指している
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
100 ![](https://i.imgur.com/GLIew1x.png)
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
101
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
102 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
103
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
104 # Xv6
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
105 - MIT の講義用教材として作られたOS
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
106 - 規格化される前のCで書かれたUNIX V6 を書き換えた
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
107 - 1万行程の軽量なOS
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
108 - Linuxだと数千万行
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
109 - Xv6 をCbCで書き換える
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
110
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
111 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
112
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
113 # Xv6の構成
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
114 - system call
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
115 - カーネル空間の処理の呼び出し
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
116 - VM(仮想メモリ)
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
117 - Paging
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
118 - File System
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
119 - I/O, Read, Write
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
120 - Scheduler など
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
121
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
122 ---
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
123
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
124 # カーネル空間
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
125 - OS の中核となるプログラムで Meta Level に相当する
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
126 - Xv6 ではカーネルとユーザープログラムは分離されている
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
127 - ユーザープログラムはカーネルに直接アクセスできない。
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
128 - ユーザープログラムによる書き換えやアクセスを防ぐため
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
129 - 呼び出す場合は system call
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
130
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
131 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
132
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
133 # Paging
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
134 - Page と呼ばれる固定長のブロックに分割して、メモリとスワップ領域で Page を入れ替えて管理
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
135 - 仮想メモリとして扱うことでフラグメンテーションの解消と空き番地を探す必要がなくなる
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
136
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
137 ---
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
138
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
139 # Xv6の書き換え方針
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
140 - メタレベルからノーマルレベルを保証するOSを作りたい
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
141 - 段階的に書き換えていきたい
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
142 - Paging を書き換える理由
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
143 - OS の信頼性を保証する上で重要なメモリ管理部分
21
tobaru
parents: 19
diff changeset
144
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
145 - __code で書き直していく
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
146
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
147 ---
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
148
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
149 # インターフェースの導入
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
150 - ノーマルレベルからメタレベルの記述が記述が煩雑になるためインターフェースを導入
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
151 - インターフェースによるメリット
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
152 - 煩雑な記述の解消
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
153 - 入力の切り替えによる実装の入れ替え
19
tobaru
parents: 18
diff changeset
154 - 実装は別で定義し、呼び出す
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
155 - 後ほど説明
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
156
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
157 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
158
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
159 # CbCインターフェース
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
160 - Data Gear と Data Gear に対して操作を行う Code Gear の集合を表現する **Meta Data Gear**
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
161 - インターフェースを定義してそこから呼び出す
19
tobaru
parents: 18
diff changeset
162
tobaru
parents: 18
diff changeset
163 ---
tobaru
parents: 18
diff changeset
164
tobaru
parents: 18
diff changeset
165 # インターフェースの定義
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
166 - Xv6 の Virtual Memory の API 部分のインターフェース
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
167 - 以下のコードについて説明していく
19
tobaru
parents: 18
diff changeset
168
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
169 ``` c
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
170 typedef struct vm<Type,Impl> {
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
171 __code init_vmm(Impl* vm, __code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
172 __code kpt_freerange(Impl* vm, uint low, uint hi, __code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
173 __code kpt_alloc(Impl* vm ,__code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
174 __code switchuvm(Impl* vm ,struct proc* p, __code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
175 __code init_inituvm(Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
176 __code loaduvm(Impl* vm,pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
177 __code allocuvm(Impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...));
19
tobaru
parents: 18
diff changeset
178
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
179 ```
19
tobaru
parents: 18
diff changeset
180
tobaru
parents: 18
diff changeset
181 ---
tobaru
parents: 18
diff changeset
182
tobaru
parents: 18
diff changeset
183
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
184 # インターフェースの命名(1行目)
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
185 - typedef struct の直後にインターフェース名(vm)を書く
19
tobaru
parents: 18
diff changeset
186
tobaru
parents: 18
diff changeset
187 ``` c
tobaru
parents: 18
diff changeset
188 typedef struct vm<Type,Impl> {
tobaru
parents: 18
diff changeset
189 ```
tobaru
parents: 18
diff changeset
190
tobaru
parents: 18
diff changeset
191 ---
tobaru
parents: 18
diff changeset
192
23
49d691a92b41 fix slide
tobaru
parents: 21
diff changeset
193
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
194 # インターフェースの Code Gear(2行目~)
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
195 - vm で使う Code Gear を登録する
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
196 - Code Gear は __code CodeGear名(引数); で記述する
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
197 - 引数が Data Gear に相当する
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
198 - 第1引数の Impl* vm がインターフェースの実装の型になる
19
tobaru
parents: 18
diff changeset
199
tobaru
parents: 18
diff changeset
200
tobaru
parents: 18
diff changeset
201 ``` c
21
tobaru
parents: 19
diff changeset
202 typedef struct vm<Type,Impl> {
19
tobaru
parents: 18
diff changeset
203 __code init_vmm(Impl* vm, __code next(...));
tobaru
parents: 18
diff changeset
204 __code kpt_freerange(Impl* vm, uint low, uint hi, __code next(...));
tobaru
parents: 18
diff changeset
205 __code kpt_alloc(Impl* vm ,__code next(...));
tobaru
parents: 18
diff changeset
206 __code switchuvm(Impl* vm ,struct proc* p, __code next(...));
tobaru
parents: 18
diff changeset
207 __code init_inituvm(Impl* vm, pde_t* pgdir, char* init, uint sz, __code next(...));
tobaru
parents: 18
diff changeset
208 __code loaduvm(Impl* vm,pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...));
tobaru
parents: 18
diff changeset
209 __code allocuvm(Impl* vm, pde_t* pgdir, uint oldsz, uint newsz, __code next(...));
tobaru
parents: 18
diff changeset
210
tobaru
parents: 18
diff changeset
211 ```
tobaru
parents: 18
diff changeset
212
tobaru
parents: 18
diff changeset
213 ---
tobaru
parents: 18
diff changeset
214
tobaru
parents: 18
diff changeset
215 # next(...)
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
216 - __code next(...) は次の Code Gear の継続先
19
tobaru
parents: 18
diff changeset
217 - それぞれの Code Gear の引数の1つに設定する
tobaru
parents: 18
diff changeset
218 ``` c
tobaru
parents: 18
diff changeset
219 __code kpt_freerange(Impl* vm, uint low, uint hi, __code next(...));
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
220 //....
19
tobaru
parents: 18
diff changeset
221 __code next(...);
tobaru
parents: 18
diff changeset
222 } vm;
tobaru
parents: 18
diff changeset
223 ```
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
224 - 例) goto vm->kpt_freerange の引数に exit を設定すると Code Gear である exit に遷移する
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
225 ``` c
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
226 __code exit(){
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
227 //....
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
228 }
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
229
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
230 goto vm->kpt_freerange(vm, low, hi, exit);
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
231 ```
19
tobaru
parents: 18
diff changeset
232
tobaru
parents: 18
diff changeset
233 ---
tobaru
parents: 18
diff changeset
234
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
235 # Interface の実装の型
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
236 - 実装側のヘッダーファイルも vm_impl と同じように用意する
19
tobaru
parents: 18
diff changeset
237
tobaru
parents: 18
diff changeset
238 ``` c
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
239 typedef struct vm_impl<Impl, Isa> impl vm{
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
240 ...
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
241 __code loaduvm_ptesize_check(Type* vm_impl, uint i, pte_t* pte, uint sz,
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
242 __code next(...));
19
tobaru
parents: 18
diff changeset
243 ```
tobaru
parents: 18
diff changeset
244
tobaru
parents: 18
diff changeset
245
tobaru
parents: 18
diff changeset
246 ---
tobaru
parents: 18
diff changeset
247
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
248 # インターフェースの実装
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
249 - 実装は型と実装をそれぞれ別ファイルで定義する(vm_impl.h と vm_impl.cbc)
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
250 - 実装するインターフェースは #interface で宣言する
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
251
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
252 ``` c
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
253 #interface "vm.h"
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
254 ```
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
255
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
256 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
257
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
258 # vmインターフェースの実装の初期化
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
259 - 定義が終わったのでインターフェースを使用したい
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
260 - メモリ上にインターフェースの置き場所と実装を確保
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
261 - struct vm* vm = new vm();
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
262 - インターフェースと実装の紐付け
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
263 - vm->void_ret = C_vm_void_ret;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
264 - Code Gear の enum の設定
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
265 - インターフェースのAPIと enum の番号を紐付けている
19
tobaru
parents: 18
diff changeset
266
tobaru
parents: 18
diff changeset
267 ``` c
tobaru
parents: 18
diff changeset
268 vm* createvm_impl(struct Context* cbc_context) {
tobaru
parents: 18
diff changeset
269 struct vm* vm = new vm();
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
270 struct vm_impl* vm_impl = new vm_impl();
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
271 vm->vm = (union Data*)vm_impl;
19
tobaru
parents: 18
diff changeset
272 ....
tobaru
parents: 18
diff changeset
273 vm->void_ret = C_vm_void_ret;
tobaru
parents: 18
diff changeset
274 vm->init_vmm = C_init_vmmvm_impl;
tobaru
parents: 18
diff changeset
275 vm->kpt_freerange = C_kpt_freerangevm_impl;
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
276 vm->loaduvm = C_loaduvmvm_impl;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
277
19
tobaru
parents: 18
diff changeset
278 vm->kpt_alloc = C_kpt_allocvm_impl;
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
279 ```
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
280
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
281
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
282 - APIの実装の例(init_vmm)
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
283 - C_init_vmmvm_impl が メタレベルでinit_vmmvm_impl と対応する
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
284 ``` c
19
tobaru
parents: 18
diff changeset
285 __code init_vmmvm_impl(struct vm_impl* vm,__code next(...)) {
tobaru
parents: 18
diff changeset
286 initlock(&kpt_mem.lock, "vm");
tobaru
parents: 18
diff changeset
287 kpt_mem.freelist = NULL;
tobaru
parents: 18
diff changeset
288
tobaru
parents: 18
diff changeset
289 goto next(...);
tobaru
parents: 18
diff changeset
290 }
tobaru
parents: 18
diff changeset
291 ```
tobaru
parents: 18
diff changeset
292
tobaru
parents: 18
diff changeset
293 ---
tobaru
parents: 18
diff changeset
294
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
295 # インターフェース実装内の CbC
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
296 - for文やif文がある場合はさらに実装を分ける
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
297 - 状態遷移ベースで記述したい
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
298 - インターフェースは外から呼び出されるAPI
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
299 - それに対してインターフェースの実装の Code Gearから明示的に呼び出される Code Gearは、Java の private メソッドのように扱われる。
19
tobaru
parents: 18
diff changeset
300 - 実際に vm.c の loaduvm の実装を分けた記述を説明する
tobaru
parents: 18
diff changeset
301
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
302 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
303
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
304 ![](https://i.imgur.com/Cj87Pxu.png)
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
305
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
306 ---
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
307 # 実装内の明示的な遷移の処理
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
308 - **vm と同じ create_impl 内で** vm_impl を定義し、private で実装する Code Gear を定義する
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
309 - loaduvmvm_impl で goto によって private に遷移する
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
310
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
311 ``` c
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
312 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
313 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
314 Gearef(cbc_context, vm_impl)->addr = addr;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
315 Gearef(cbc_context, vm_impl)->ip = ip;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
316 Gearef(cbc_context, vm_impl)->offset = offset;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
317 Gearef(cbc_context, vm_impl)->sz = sz;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
318 Gearef(cbc_context, vm_impl)->next = next;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
319
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
320 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
321 }
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
322 ```
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
323
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
324 - vm のインターフェースの実装を vm_impl に設定している
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
325 - vm の実装内で使用する Code Gear も enum の番号で指定する
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
326 - vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
327
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
328 ``` c
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
329 vm* createvm_impl(struct Context* cbc_context) {
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
330 struct vm* vm = new vm();
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
331 struct vm_impl* vm_impl = new vm_impl();
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
332 vm->vm = (union Data*)vm_impl;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
333
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
334 ...
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
335 vm_impl->loaduvm_ptesize_check = C_loaduvm_ptesize_checkvm_impl;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
336 ....
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
337 vm->loaduvm = C_loaduvmvm_impl;
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
338 ....
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
339 }
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
340 ```
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
341 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
342
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
343 # loaduvmの CbCによる書き換え
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
344 - loaduvmは
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
345 - swapから呼び出す
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
346 - kernelの中をloopしてreadiに入る
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
347 - 入った場合は待ちになる
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
348 - user proc側が待ちになる
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
349
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
350 - vm.cのloaduvmの処理をCbC で書き換える
19
tobaru
parents: 18
diff changeset
351
tobaru
parents: 18
diff changeset
352 ``` c
tobaru
parents: 18
diff changeset
353 int loaduvm (pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
tobaru
parents: 18
diff changeset
354 {
tobaru
parents: 18
diff changeset
355 uint i, pa, n;
tobaru
parents: 18
diff changeset
356 pte_t *pte;
tobaru
parents: 18
diff changeset
357
tobaru
parents: 18
diff changeset
358 if ((uint) addr % PTE_SZ != 0) {
tobaru
parents: 18
diff changeset
359 panic("loaduvm: addr must be page aligned");
tobaru
parents: 18
diff changeset
360 }
tobaru
parents: 18
diff changeset
361
tobaru
parents: 18
diff changeset
362 for (i = 0; i < sz; i += PTE_SZ) {
tobaru
parents: 18
diff changeset
363 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
tobaru
parents: 18
diff changeset
364 panic("loaduvm: address should exist");
tobaru
parents: 18
diff changeset
365 }
tobaru
parents: 18
diff changeset
366
tobaru
parents: 18
diff changeset
367 pa = PTE_ADDR(*pte);
tobaru
parents: 18
diff changeset
368
tobaru
parents: 18
diff changeset
369 if (sz - i < PTE_SZ) {
tobaru
parents: 18
diff changeset
370 n = sz - i;
tobaru
parents: 18
diff changeset
371 } else {
tobaru
parents: 18
diff changeset
372 n = PTE_SZ;
tobaru
parents: 18
diff changeset
373 }
tobaru
parents: 18
diff changeset
374
tobaru
parents: 18
diff changeset
375 if (readi(ip, p2v(pa), offset + i, n) != n) {
tobaru
parents: 18
diff changeset
376 return -1;
tobaru
parents: 18
diff changeset
377 }
tobaru
parents: 18
diff changeset
378 }
tobaru
parents: 18
diff changeset
379
tobaru
parents: 18
diff changeset
380 return 0;
tobaru
parents: 18
diff changeset
381 }
tobaru
parents: 18
diff changeset
382 ```
tobaru
parents: 18
diff changeset
383
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
384 - loaduvm_impl がインターフェースから呼ばれる実装
19
tobaru
parents: 18
diff changeset
385
tobaru
parents: 18
diff changeset
386
tobaru
parents: 18
diff changeset
387 ``` c
tobaru
parents: 18
diff changeset
388 __code loaduvmvm_impl(struct vm_impl* vm, pde_t* pgdir, char* addr, struct inode* ip, uint offset, uint sz, __code next(...)) {
tobaru
parents: 18
diff changeset
389 Gearef(cbc_context, vm_impl)->pgdir = pgdir;
tobaru
parents: 18
diff changeset
390 Gearef(cbc_context, vm_impl)->addr = addr;
tobaru
parents: 18
diff changeset
391 Gearef(cbc_context, vm_impl)->ip = ip;
tobaru
parents: 18
diff changeset
392 Gearef(cbc_context, vm_impl)->offset = offset;
tobaru
parents: 18
diff changeset
393 Gearef(cbc_context, vm_impl)->sz = sz;
tobaru
parents: 18
diff changeset
394 Gearef(cbc_context, vm_impl)->next = next;
tobaru
parents: 18
diff changeset
395
tobaru
parents: 18
diff changeset
396 goto loaduvm_ptesize_checkvm_impl(vm, next(...));
tobaru
parents: 18
diff changeset
397 }
tobaru
parents: 18
diff changeset
398 ```
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
399 - loaduvm_impl から private な Code Gear が呼ばれる
19
tobaru
parents: 18
diff changeset
400
tobaru
parents: 18
diff changeset
401 ``` c
tobaru
parents: 18
diff changeset
402 #interface "vm_impl.h"
tobaru
parents: 18
diff changeset
403
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
404 __code loaduvm_ptesize_checkvm_impl(struct vm_impl* vm_impl, __code next(...)) {
19
tobaru
parents: 18
diff changeset
405 char* addr = vm_impl->addr;
tobaru
parents: 18
diff changeset
406
tobaru
parents: 18
diff changeset
407 if ((uint) addr %PTE_SZ != 0) {
tobaru
parents: 18
diff changeset
408 // goto panic
tobaru
parents: 18
diff changeset
409 }
tobaru
parents: 18
diff changeset
410
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
411 goto loaduvm_loopvm_impl(vm_impl, next(...));
19
tobaru
parents: 18
diff changeset
412 }
tobaru
parents: 18
diff changeset
413 ```
tobaru
parents: 18
diff changeset
414
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
415
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
416 - vm.c のloaduvm の実装を CbC で書き直す
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
417 ``` c
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
418
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
419 int loaduvm (pde_t *pgdir, char *addr, struct inode *ip, uint offset, uint sz)
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
420 {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
421 uint i, pa, n;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
422 pte_t *pte;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
423
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
424 if ((uint) addr % PTE_SZ != 0) {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
425 panic("loaduvm: addr must be page aligned");
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
426 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
427
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
428 for (i = 0; i < sz; i += PTE_SZ) {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
429 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
430 panic("loaduvm: address should exist");
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
431 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
432
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
433 pa = PTE_ADDR(*pte);
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
434
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
435 if (sz - i < PTE_SZ) {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
436 n = sz - i;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
437 } else {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
438 n = PTE_SZ;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
439 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
440
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
441 if (readi(ip, p2v(pa), offset + i, n) != n) {
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
442 return -1;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
443 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
444 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
445
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
446 return 0;
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
447 }
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
448 ```
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
449
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
450
19
tobaru
parents: 18
diff changeset
451 - vm.cではここから for だが CbC は if文の中と外にgoto を用意して実装する
tobaru
parents: 18
diff changeset
452
tobaru
parents: 18
diff changeset
453 ![](https://i.imgur.com/ByA7GVJ.png)
tobaru
parents: 18
diff changeset
454
tobaru
parents: 18
diff changeset
455 ```c
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
456 __code loaduvm_loopvm_impl(struct vm_impl* vm_impl, __code next(...)) {
19
tobaru
parents: 18
diff changeset
457 uint i = vm_impl->i;
tobaru
parents: 18
diff changeset
458 uint sz = vm_impl->sz;
tobaru
parents: 18
diff changeset
459
tobaru
parents: 18
diff changeset
460 if (i < sz) {
tobaru
parents: 18
diff changeset
461 goto loaduvm_check_pgdir(vm_impl, next(ret, ...));
tobaru
parents: 18
diff changeset
462 }
tobaru
parents: 18
diff changeset
463
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
464 goto loaduvm_exit(vm_impl, next(...));
19
tobaru
parents: 18
diff changeset
465 }
tobaru
parents: 18
diff changeset
466
tobaru
parents: 18
diff changeset
467
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
468 __code loaduvm_check_pgdir(struct vm_impl* vm_impl, __code next(...)) {
19
tobaru
parents: 18
diff changeset
469 pte_t* pte = vm_impl->pte;
tobaru
parents: 18
diff changeset
470 pde_t* pgdir = vm_impl->pgdir;
tobaru
parents: 18
diff changeset
471 uint i = vm_impl->i;
tobaru
parents: 18
diff changeset
472 char* addr = vm_impl->addr;
tobaru
parents: 18
diff changeset
473 uint pa = vm_impl->pa;
tobaru
parents: 18
diff changeset
474
tobaru
parents: 18
diff changeset
475 if ((pte = walkpgdir(pgdir, addr + i, 0)) == 0) {
tobaru
parents: 18
diff changeset
476 // goto panic
tobaru
parents: 18
diff changeset
477 }
tobaru
parents: 18
diff changeset
478 pa = PTE_ADDR(*pte);
tobaru
parents: 18
diff changeset
479
tobaru
parents: 18
diff changeset
480 vm_impl->pte = pte;
tobaru
parents: 18
diff changeset
481 vm_impl->pgdir = pgdir;
tobaru
parents: 18
diff changeset
482 vm_impl->addr = addr;
tobaru
parents: 18
diff changeset
483 vm_impl->pa = pa;
tobaru
parents: 18
diff changeset
484
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
485 goto loaduvm_check_PTE_SZ(vm_impl, next(...));
19
tobaru
parents: 18
diff changeset
486 }
tobaru
parents: 18
diff changeset
487
tobaru
parents: 18
diff changeset
488 __code loaduvm_check_PTE_SZ(struct vm_impl* vm_impl, __code next(int ret, ...)) {
tobaru
parents: 18
diff changeset
489 if (sz - i < PTE_SZ) {
tobaru
parents: 18
diff changeset
490 n = sz - i;
tobaru
parents: 18
diff changeset
491 } else {
tobaru
parents: 18
diff changeset
492 n = PTE_SZ;
tobaru
parents: 18
diff changeset
493 }
tobaru
parents: 18
diff changeset
494
tobaru
parents: 18
diff changeset
495 if (readi(ip, p2v(pa), offset + i, n) != n) {
tobaru
parents: 18
diff changeset
496 ret = -1;
tobaru
parents: 18
diff changeset
497 goto next(ret, ...);
tobaru
parents: 18
diff changeset
498 }
tobaru
parents: 18
diff changeset
499
tobaru
parents: 18
diff changeset
500 vm_impl->n = n;
tobaru
parents: 18
diff changeset
501
tobaru
parents: 18
diff changeset
502 goto loaduvm_loopvm_impl(vm_impl, next(ret, ...));
tobaru
parents: 18
diff changeset
503 }
tobaru
parents: 18
diff changeset
504
tobaru
parents: 18
diff changeset
505 __code loaduvm_exit(struct vm_impl* vm_impl, __code next(int ret, ...)) {
tobaru
parents: 18
diff changeset
506 ret = 0;
tobaru
parents: 18
diff changeset
507 goto next(ret, ...);
tobaru
parents: 18
diff changeset
508 }
tobaru
parents: 18
diff changeset
509 ```
18
afc36230cf4f slide chapter3,4
tobaru
parents:
diff changeset
510
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
511
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
512 ---
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
513
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
514 # C を CbC に部分的に書き直す手法
19
tobaru
parents: 18
diff changeset
515 - CbC の場合 goto による 遷移を行うので、関数呼び出しのように goto 以降のコードを実行できない
tobaru
parents: 18
diff changeset
516 - 例) goto すると戻ってこれないため それ以降が実行されなくなる。
tobaru
parents: 18
diff changeset
517
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
518 ---
19
tobaru
parents: 18
diff changeset
519
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
520 # CbC から C への遷移
19
tobaru
parents: 18
diff changeset
521 - 最初の命令は next で戻ってこれるので、dummy の関数を用意してそこで実行する
tobaru
parents: 18
diff changeset
522
tobaru
parents: 18
diff changeset
523 ``` c
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
524 void cbc_init_vmm_dummy(struct Context* cbc_context, struct proc* p, pde_t* pgdir, char* init, uint sz)
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
525 {
19
tobaru
parents: 18
diff changeset
526 // inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
tobaru
parents: 18
diff changeset
527
tobaru
parents: 18
diff changeset
528 struct vm* vm = createvm_impl(cbc_context);
tobaru
parents: 18
diff changeset
529 // goto vm->init_vmm(vm, pgdir, init, sz , vm->void_ret);
tobaru
parents: 18
diff changeset
530 Gearef(cbc_context, vm)->vm = (union Data*) vm;
tobaru
parents: 18
diff changeset
531 Gearef(cbc_context, vm)->pgdir = pgdir;
tobaru
parents: 18
diff changeset
532 Gearef(cbc_context, vm)->init = init;
tobaru
parents: 18
diff changeset
533 Gearef(cbc_context, vm)->sz = sz ;
tobaru
parents: 18
diff changeset
534 Gearef(cbc_context, vm)->next = C_vm_void_ret ;
tobaru
parents: 18
diff changeset
535 goto meta(cbc_context, vm->init_inituvm);
tobaru
parents: 18
diff changeset
536 }
tobaru
parents: 18
diff changeset
537
tobaru
parents: 18
diff changeset
538 void userinit(void)
tobaru
parents: 18
diff changeset
539 {
tobaru
parents: 18
diff changeset
540 struct proc* p;
tobaru
parents: 18
diff changeset
541 extern char _binary_initcode_start[], _binary_initcode_size[];
tobaru
parents: 18
diff changeset
542
tobaru
parents: 18
diff changeset
543 p = allocproc();
tobaru
parents: 18
diff changeset
544 initContext(&p->cbc_context);
tobaru
parents: 18
diff changeset
545
tobaru
parents: 18
diff changeset
546 initproc = p;
tobaru
parents: 18
diff changeset
547
tobaru
parents: 18
diff changeset
548 if((p->pgdir = kpt_alloc()) == NULL) {
tobaru
parents: 18
diff changeset
549 panic("userinit: out of memory?");
tobaru
parents: 18
diff changeset
550 }
tobaru
parents: 18
diff changeset
551
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
552 cbc_init_vmm_dummy(&p->cbc_context, p, p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
553
21
tobaru
parents: 19
diff changeset
554 ```
19
tobaru
parents: 18
diff changeset
555
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
556 ---
21
tobaru
parents: 19
diff changeset
557
31
69ac4230c3f2 fix slide
tobaru
parents: 23
diff changeset
558 # まとめ
33
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
559 - OS 内部で CbC インターフェースを扱えるようになった
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
560 - CbC の書 き換えが完了すれば、継続の入力と出力を検査することで OS の信頼性を保証したり、インターフェースの実装の入れ替えが可能になる。
e68c3bd31098 after Master's Thesis Examination
tobaru
parents: 31
diff changeset
561 - Context による複数環境の入れ替えや同時実行を可能にすることで CbCXv6 に おいて コンテナと VM を実装ができると予想される。