Mercurial > hg > Papers > 2020 > tobaru-master
comparison slide/CbCXv6.html @ 32:4c24694af0b0
slide html
author | tobaru |
---|---|
date | Sun, 09 Feb 2020 22:55:38 +0900 |
parents | 98cee2f6c919 |
children | e68c3bd31098 |
comparison
equal
deleted
inserted
replaced
31:69ac4230c3f2 | 32:4c24694af0b0 |
---|---|
32 <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js" integrity="sha256-8E4Is26QH0bD52WoQpcB+R/tcWQtpzlCojrybUd7Mxo=" crossorigin="anonymous"></script> | 32 <script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js" integrity="sha256-8E4Is26QH0bD52WoQpcB+R/tcWQtpzlCojrybUd7Mxo=" crossorigin="anonymous"></script> |
33 <![endif]--> | 33 <![endif]--> |
34 </head> | 34 </head> |
35 | 35 |
36 <body> | 36 <body> |
37 <div id="doc" class="markdown-body container-fluid comment-enabled" data-hard-breaks="true"><h1 id="CbCインターフェースによる-CbCXv6-の書き換え" style=""><a class="anchor hidden-xs" href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる-CbCXv6-の書き換え"><span class="octicon octicon-link"></span></a>CbCインターフェースによる CbCXv6 の書き換え</h1><ul> | 37 <div id="doc" class="markdown-body container-fluid comment-enabled" data-hard-breaks="true" style="position: relative;"><h1 class="highlight" id="CbCインターフェースによる-CbCXv6-の書き換え" style=""><a class="anchor hidden-xs" href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる-CbCXv6-の書き換え"><span class="octicon octicon-link"></span></a>CbCインターフェースによる CbCXv6 の書き換え</h1><ul> |
38 <li>並列信頼研</li> | 38 <li>並列信頼研</li> |
39 <li>桃原 優</li> | 39 <li>桃原 優</li> |
40 </ul><hr><h1 id="目次" style=""><a class="anchor hidden-xs" href="#目次" title="目次"><span class="octicon octicon-link"></span></a>目次</h1><ol> | 40 </ul><hr><h1 class="highlight" id="概要" style=""><a class="anchor hidden-xs" href="#概要" title="概要"><span class="octicon octicon-link"></span></a>概要</h1><ul> |
41 <li><strong>OS の信頼性の保証</strong></li> | 41 <li>OS の信頼性を上げたい</li> |
42 <li>CbC による Gears OS の開発</li> | 42 <li>CbCを使って xv6 という OS を書き換える</li> |
43 <li>Xv6</li> | 43 <li>Paging の書き換えを行った</li> |
44 <li>CbCXv6 での Paging</li> | 44 <li>まだ実装中</li> |
45 <li>CbC インターフェース</li> | 45 <li>将来はコンテナやVMをメタ計算として実装できるはず</li> |
46 <li>評価</li> | 46 </ul><hr><h1 id="OS-の信頼性を上げたい" style=""><a class="anchor hidden-xs" href="#OS-の信頼性を上げたい" title="OS-の信頼性を上げたい"><span class="octicon octicon-link"></span></a>OS の信頼性を上げたい</h1><ul class="highlight"> |
47 <li>まとめ</li> | 47 <li>仕様を満たすことを証明する</li> |
48 </ol><hr><h1 id="OS-の信頼性の重要性" style=""><a class="anchor hidden-xs" href="#OS-の信頼性の重要性" title="OS-の信頼性の重要性"><span class="octicon octicon-link"></span></a>OS の信頼性の重要性</h1><ul> | 48 <li>証明しやすい形の記述を作る</li> |
49 <li>OS のバグは日常生活に支障をきたす | 49 <li>CbCの goto で書く |
50 <ul> | 50 <ul> |
51 <li>パスワードなしで root にアクセスできるバグ</li> | 51 <li>状態遷移系に近い形で記述できる(証明しやすい)</li> |
52 <li>日付設定でコンピュータが壊れる</li> | 52 <li>関数型の記述</li> |
53 <li>-> OS自体に信頼性が求められる</li> | 53 </ul> |
54 </ul> | 54 </li> |
55 </li> | 55 <li>CbCのinterface で書く</li> |
56 </ul><hr><h1 id="OS-の信頼性の重要性1" style=""><a class="anchor hidden-xs" href="#OS-の信頼性の重要性1" title="OS-の信頼性の重要性1"><span class="octicon octicon-link"></span></a>OS の信頼性の重要性</h1><ul> | 56 <li>記述のモジュール化</li> |
57 <li> | 57 </ul><hr><h1 id="メタレベルとノーマルレベル" style=""><a class="anchor hidden-xs" href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル"><span class="octicon octicon-link"></span></a>メタレベルとノーマルレベル</h1><ul class="highlight"> |
58 <p>全てのOSのコードに対して検証を行うのは困難</p> | |
59 <ul> | |
60 <li>複雑な機能が多い</li> | |
61 <li>短期間のアップデート</li> | |
62 </ul> | |
63 </li> | |
64 <li> | |
65 <p>ユーザーが検証を行うこともできない</p> | |
66 <ul> | |
67 <li>資源管理はOSが行なってる</li> | |
68 <li>そもそも資源管理が複雑</li> | |
69 <li>アクセスされたり書き換えられるリスク</li> | |
70 </ul> | |
71 </li> | |
72 </ul><hr><h1 id="メタレベルとノーマルレベル" style=""><a class="anchor hidden-xs" href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル"><span class="octicon octicon-link"></span></a>メタレベルとノーマルレベル</h1><ul> | |
73 <li>ノーマルレベル | 58 <li>ノーマルレベル |
74 <ul> | 59 <ul> |
75 <li>ユーザーがプログラミング言語によって記述する部分の処理</li> | 60 <li>CbCで記述される普通のアルゴリズム</li> |
76 </ul> | 61 </ul> |
77 </li> | 62 </li> |
78 <li>メタレベル | 63 <li>メタレベル |
79 <ul> | 64 <ul> |
80 <li>ユーザーが記述しないOS 側の処理 | 65 <li>Paging などのメモリやCPU自体の操作</li> |
81 <ul> | 66 <li>プログラムの正しさの証明</li> |
82 <li>CPU</li> | 67 </ul> |
83 <li>メモリ</li> | 68 </li> |
84 </ul> | 69 <li>Context |
85 </li> | 70 <ul> |
86 </ul> | 71 <li>メタレベルで使用される Meta Data を置く場所</li> |
87 </li> | 72 </ul> |
88 </ul><hr><h1 id="Continuation-based-C" style=""><a class="anchor hidden-xs" href="#Continuation-based-C" title="Continuation-based-C"><span class="octicon octicon-link"></span></a>Continuation based C</h1><ul> | 73 </li> |
74 </ul><hr><h1 id="Continuation-based-C" style=""><a class="anchor hidden-xs" href="#Continuation-based-C" title="Continuation-based-C"><span class="octicon octicon-link"></span></a>Continuation based C</h1><ul class="highlight"> | |
89 <li>ノーマルレベルとメタレベルの処理を同じ言語で行えるようにした言語(以下CbC)</li> | 75 <li>ノーマルレベルとメタレベルの処理を同じ言語で行えるようにした言語(以下CbC)</li> |
90 <li>Code Gear | 76 <li>Code Gear |
91 <ul> | 77 <ul> |
92 <li>基本的な処理の単位</li> | 78 <li>基本的な処理の単位</li> |
79 <li>goto 文で遷移する</li> | |
93 </ul> | 80 </ul> |
94 </li> | 81 </li> |
95 <li>Data Gear | 82 <li>Data Gear |
96 <ul> | 83 <ul> |
97 <li>データの単位</li> | 84 <li>データの単位</li> |
85 </ul> | |
86 </li> | |
87 <li>Meta Code Gear | |
88 <ul> | |
89 <li>goto meta</li> | |
90 <li>Code Gear の間に挟める計算</li> | |
91 </ul> | |
92 </li> | |
93 <li>Meta Data Gear | |
94 <ul> | |
95 <li>Context</li> | |
96 <li>Code Gearの間の接続など</li> | |
98 </ul> | 97 </ul> |
99 </li> | 98 </li> |
100 </ul><hr><h1 id="goto-による継続" style=""><a class="anchor hidden-xs" href="#goto-による継続" title="goto-による継続"><span class="octicon octicon-link"></span></a>goto による継続</h1><ul> | 99 </ul><hr><h1 id="goto-による継続" style=""><a class="anchor hidden-xs" href="#goto-による継続" title="goto-による継続"><span class="octicon octicon-link"></span></a>goto による継続</h1><ul> |
101 <li>Code Gear の処理の間を goto によって遷移していく</li> | 100 <li>Code Gear の処理の間を goto によって遷移していく</li> |
102 </ul><p><img src="https://i.imgur.com/etfQund.png" alt=""></p><hr><h1 id="Data-Gear-の継続" style=""><a class="anchor hidden-xs" href="#Data-Gear-の継続" title="Data-Gear-の継続"><span class="octicon octicon-link"></span></a>Data Gear の継続</h1><ul> | 101 </ul><p><img src="https://i.imgur.com/etfQund.png" alt=""></p><hr><h1 id="Data-Gear-の継続" style=""><a class="anchor hidden-xs" href="#Data-Gear-の継続" title="Data-Gear-の継続"><span class="octicon octicon-link"></span></a>Data Gear の継続</h1><ul> |
102 <li>Code Gear で定義されたデータ</li> | |
103 <li>goto の際に Data Gear も継続される</li> | 103 <li>goto の際に Data Gear も継続される</li> |
104 </ul><p><img src="https://i.imgur.com/3E0DGWA.png" alt=""></p><hr><h1 id="Meta-Code-Gear" style=""><a class="anchor hidden-xs" href="#Meta-Code-Gear" title="Meta-Code-Gear"><span class="octicon octicon-link"></span></a>Meta Code Gear</h1><ul> | 104 </ul><p><img src="https://i.imgur.com/3E0DGWA.png" alt=""></p><hr><h1 id="Meta-Code-Gear" style=""><a class="anchor hidden-xs" href="#Meta-Code-Gear" title="Meta-Code-Gear"><span class="octicon octicon-link"></span></a>Meta Code Gear</h1><ul> |
105 <li>実際にはノーマルレベルの間にメタレベルの処理がある</li> | 105 <li>実際にはノーマルレベルの間にメタレベルの処理がある</li> |
106 <li>Meta Level では Data Gear の見え方は変わる(Meta Data Gear)</li> | 106 </ul><p><img src="https://i.imgur.com/vy0NxrG.png" alt=""></p><hr><h1 id="Meta-Data-Gear" style=""><a class="anchor hidden-xs" href="#Meta-Data-Gear" title="Meta-Data-Gear"><span class="octicon octicon-link"></span></a>Meta Data Gear</h1><ul> |
107 </ul><p><img src="https://i.imgur.com/vy0NxrG.png" alt=""></p><hr><h1 id="状態遷移モデル" style=""><a class="anchor hidden-xs" href="#状態遷移モデル" title="状態遷移モデル"><span class="octicon octicon-link"></span></a>状態遷移モデル</h1><ul> | 107 <li>CbC では接続可能な Code Gear, Data Gear のリスト</li> |
108 <li>goto の遷移によって状態遷移モデルに落とし込める</li> | 108 <li>Data Gear を確保するメモリ空間</li> |
109 <li>Code Gear に対しての入力に対して期待される出力がされているかで検査して<strong>信頼性を保証する</strong></li> | 109 <li>ノーマルレベルでの書き換えやアクセスを防ぐために存在</li> |
110 </ul><hr><h1 id="Agda-による検証" style=""><a class="anchor hidden-xs" href="#Agda-による検証" title="Agda-による検証"><span class="octicon octicon-link"></span></a>Agda による検証</h1><ul> | 110 </ul><hr><h1 id="Xv6" style=""><a class="anchor hidden-xs" href="#Xv6" title="Xv6"><span class="octicon octicon-link"></span></a>Xv6</h1><ul> |
111 <li>モデル検査 | |
112 <ul> | |
113 <li>定理証明支援系である Agda を用いる。</li> | |
114 </ul> | |
115 </li> | |
116 <li>Agda | |
117 <ul> | |
118 <li>Haure Logic という検証手法を扱える。</li> | |
119 </ul> | |
120 </li> | |
121 </ul><hr><h1 id="Haure-Logic" style=""><a class="anchor hidden-xs" href="#Haure-Logic" title="Haure-Logic"><span class="octicon octicon-link"></span></a>Haure Logic</h1><ul> | |
122 <li>検証手法 | |
123 <ul> | |
124 <li>事前条件を使ってある関数を実行して事後条件を満たすことを確認する</li> | |
125 </ul> | |
126 </li> | |
127 <li>CbCと相性がいい | |
128 <ul> | |
129 <li>継続に事前条件(Input Data Gear)と事後条件(Output Data Gear)を持たせることができる</li> | |
130 </ul> | |
131 </li> | |
132 </ul><hr><h1 id="Geas-OS" style=""><a class="anchor hidden-xs" href="#Geas-OS" title="Geas-OS"><span class="octicon octicon-link"></span></a>Geas OS</h1><ul> | |
133 <li>CbC を使って信頼性の保証と拡張性を持たせる Gears OS の開発を行なっている</li> | |
134 <li>Xv6 という OS を参考に書き換えをしている</li> | |
135 </ul><hr><h1 id="メモリ管理" style=""><a class="anchor hidden-xs" href="#メモリ管理" title="メモリ管理"><span class="octicon octicon-link"></span></a>メモリ管理</h1><ul> | |
136 <li>OS の信頼性の1つであるメモリ管理部分を CbC で書き換える | |
137 <ul> | |
138 <li>Page のバリデーションチェック</li> | |
139 <li>サンドボックスによるエクセプション</li> | |
140 </ul> | |
141 </li> | |
142 </ul><hr><h1 id="インターフェース" style=""><a class="anchor hidden-xs" href="#インターフェース" title="インターフェース"><span class="octicon octicon-link"></span></a>インターフェース</h1><ul> | |
143 <li>書き換えを防ぐために見える Data Gear に違いが生じる</li> | |
144 <li>-> Gears OS のノーマルレベルからメタレベルの記述が記述が煩雑になるためインターフェースを導入</li> | |
145 <li>機能の入れ替えによる他のメリット | |
146 <ul> | |
147 <li>煩雑な記述の解消</li> | |
148 <li>機能の入れ替え</li> | |
149 <li>Agda による証明</li> | |
150 </ul> | |
151 </li> | |
152 </ul><hr><h1 id="目次1" style=""><a class="anchor hidden-xs" href="#目次1" title="目次1"><span class="octicon octicon-link"></span></a>目次</h1><ol> | |
153 <li>OS の信頼性の保証</li> | |
154 <li><strong>CbC による Gears OS の開発</strong></li> | |
155 <li>Xv6</li> | |
156 <li>CbCXv6 での Paging</li> | |
157 <li>CbC インターフェース</li> | |
158 <li>評価</li> | |
159 <li>まとめ</li> | |
160 </ol><hr><h1 id="CbC-による-Gears-OS-の開発" style=""><a class="anchor hidden-xs" href="#CbC-による-Gears-OS-の開発" title="CbC-による-Gears-OS-の開発"><span class="octicon octicon-link"></span></a>CbC による Gears OS の開発</h1><ul> | |
161 <li>a</li> | |
162 </ul><hr><h1 id="Context" style=""><a class="anchor hidden-xs" href="#Context" title="Context"><span class="octicon octicon-link"></span></a>Context</h1><ul> | |
163 <li>a</li> | |
164 </ul><hr><h1 id="目次2" style=""><a class="anchor hidden-xs" href="#目次2" title="目次2"><span class="octicon octicon-link"></span></a>目次</h1><ol> | |
165 <li>OS の信頼性の保証</li> | |
166 <li>CbC による Gears OS の開発</li> | |
167 <li><strong>Xv6</strong></li> | |
168 <li>CbCXv6 での Paging</li> | |
169 <li>CbC インターフェース</li> | |
170 <li>評価</li> | |
171 <li>まとめ</li> | |
172 </ol><hr><h1 id="Xv6" style=""><a class="anchor hidden-xs" href="#Xv6" title="Xv6"><span class="octicon octicon-link"></span></a>Xv6</h1><ul> | |
173 <li>MIT の講義用教材として作られたOS | 111 <li>MIT の講義用教材として作られたOS |
174 <ul> | 112 <ul> |
175 <li>企画課される前のCで書かれたUNIX V6 を書き換えた</li> | 113 <li>規格化される前のCで書かれたUNIX V6 を書き換えた</li> |
176 <li>1万行程の軽量なOS</li> | 114 <li>1万行程の軽量なOS</li> |
177 <li>Linuxだと数千万行</li> | 115 <li>Linuxだと数千万行</li> |
178 </ul> | 116 </ul> |
179 </li> | 117 </li> |
180 <li>Xv6 を参考に CbC で書き直すことで Gears OS を実装する</li> | 118 <li>Xv6 をCbCで書き換える</li> |
119 </ul><hr><h1 id="Xv6の構成" style=""><a class="anchor hidden-xs" href="#Xv6の構成" title="Xv6の構成"><span class="octicon octicon-link"></span></a>Xv6の構成</h1><ul class="highlight"> | |
120 <li>systemcall</li> | |
121 <li>Scheduler</li> | |
122 <li>Virtual Memory</li> | |
123 <li>file system</li> | |
124 <li>tty</li> | |
181 </ul><hr><h1 id="カーネル空間" style=""><a class="anchor hidden-xs" href="#カーネル空間" title="カーネル空間"><span class="octicon octicon-link"></span></a>カーネル空間</h1><ul> | 125 </ul><hr><h1 id="カーネル空間" style=""><a class="anchor hidden-xs" href="#カーネル空間" title="カーネル空間"><span class="octicon octicon-link"></span></a>カーネル空間</h1><ul> |
182 <li>OS の中核となるプログラムで Meta Level に相当する</li> | 126 <li>OS の中核となるプログラムで Meta Level に相当する</li> |
183 <li>Xv6 ではカーネルとユーザープログラムは分離されている</li> | 127 <li>Xv6 ではカーネルとユーザープログラムは分離されている</li> |
184 <li>ユーザープログラムはカーネルに直接アクセスできない。 | 128 <li>ユーザープログラムはカーネルに直接アクセスできない。 |
185 <ul> | 129 <ul> |
186 <li>書き換えやアクセスを防ぐため</li> | 130 <li>ユーザープログラムによる書き換えやアクセスを防ぐため</li> |
187 <li>呼び出す場合は system call</li> | 131 <li>呼び出す場合は system call</li> |
188 </ul> | |
189 </li> | |
190 </ul><hr><h1 id="カーネルが提供するもの" style=""><a class="anchor hidden-xs" href="#カーネルが提供するもの" title="カーネルが提供するもの"><span class="octicon octicon-link"></span></a>カーネルが提供するもの</h1><ul> | |
191 <li>プロセス管理</li> | |
192 <li>メモリ管理</li> | |
193 <li>ファイル管理 | |
194 <ul> | |
195 <li>I/O, read, write</li> | |
196 </ul> | |
197 </li> | |
198 </ul><hr><h1 id="カーネルの保護機構" style=""><a class="anchor hidden-xs" href="#カーネルの保護機構" title="カーネルの保護機構"><span class="octicon octicon-link"></span></a>カーネルの保護機構</h1><ul> | |
199 <li>CPUのハードウェア保護機構を持っている</li> | |
200 <li>ユーザー空間で実行されているプロセスが自身のメモリのみアクセスできるように保護</li> | |
201 <li>system call | |
202 <ul> | |
203 <li>ハードウェアが一時的に特権レベルをあげ、カーネルのプログラムが実行される</li> | |
204 </ul> | 132 </ul> |
205 </li> | 133 </li> |
206 </ul><hr><h1 id="system-call" style=""><a class="anchor hidden-xs" href="#system-call" title="system-call"><span class="octicon octicon-link"></span></a>system call</h1><ul> | 134 </ul><hr><h1 id="system-call" style=""><a class="anchor hidden-xs" href="#system-call" title="system-call"><span class="octicon octicon-link"></span></a>system call</h1><ul> |
207 <li>system call 呼び出し</li> | 135 <li>system call 呼び出し</li> |
208 <li>トラップ の発生</li> | 136 <li>トラップ の発生</li> |
209 <li>ユーザープログラムの中断</li> | 137 <li>ユーザープログラムの中断</li> |
210 <li>処理がカーネルに切り替わる</li> | 138 <li>処理がカーネルに切り替わる</li> |
211 </ul><hr><h1 id="system-call1" style=""><a class="anchor hidden-xs" href="#system-call1" title="system-call1"><span class="octicon octicon-link"></span></a>system call</h1><ul> | |
212 <li>ソースコード載せる</li> | |
213 </ul><hr><h1 id="Xv6-rpi" style=""><a class="anchor hidden-xs" href="#Xv6-rpi" title="Xv6-rpi"><span class="octicon octicon-link"></span></a>Xv6-rpi</h1><ul> | |
214 <li>Xv6 は Arm のバイナリを出力するので様々なハードウェアで動かすことができる | |
215 <ul> | |
216 <li>Raspberry Pi</li> | |
217 <li>携帯電話</li> | |
218 </ul> | |
219 </li> | |
220 <li>実際にRaspberry Pi で動かすために xv6-rpi を用意して動作しているかコンソールで確認中 | |
221 <ul> | |
222 <li>CbCxv6 とは別</li> | |
223 </ul> | |
224 </li> | |
225 </ul><hr><h1 id="目次3" style=""><a class="anchor hidden-xs" href="#目次3" title="目次3"><span class="octicon octicon-link"></span></a>目次</h1><ol> | |
226 <li>OS の信頼性の保証</li> | |
227 <li>CbC による Gears OS の開発</li> | |
228 <li>Xv6</li> | |
229 <li><strong>CbCXv6 での Paging</strong></li> | |
230 <li>CbC インターフェース</li> | |
231 <li>評価</li> | |
232 <li>まとめ</li> | |
233 </ol><hr><h1 id="CbCXv6-での-Paging" style=""><a class="anchor hidden-xs" href="#CbCXv6-での-Paging" title="CbCXv6-での-Paging"><span class="octicon octicon-link"></span></a>CbCXv6 での Paging</h1><ul> | |
234 <li>OS の信頼性の1つであるメモリ管理部分の書き換えについて説明</li> | |
235 </ul><hr><h1 id="実メモリの直接操作" style=""><a class="anchor hidden-xs" href="#実メモリの直接操作" title="実メモリの直接操作"><span class="octicon octicon-link"></span></a>実メモリの直接操作</h1><ul> | |
236 <li>実メモリを直接扱うと様々な問題が生じる | |
237 <ul> | |
238 <li>ユーザープログラムで空いているメモリ番地を探す必要</li> | |
239 <li>フラグメンテーションが起こる | |
240 <ul> | |
241 <li>メモリ間に扱うには小さな隙間ができる</li> | |
242 </ul> | |
243 </li> | |
244 </ul> | |
245 </li> | |
246 </ul><hr><h1 id="Paging" style=""><a class="anchor hidden-xs" href="#Paging" title="Paging"><span class="octicon octicon-link"></span></a>Paging</h1><ul> | 139 </ul><hr><h1 id="Paging" style=""><a class="anchor hidden-xs" href="#Paging" title="Paging"><span class="octicon octicon-link"></span></a>Paging</h1><ul> |
247 <li>メモリ管理の手法</li> | |
248 <li>Page と呼ばれる固定長のブロックに分割して、メモリとスワップ領域で Page を入れ替えて管理</li> | 140 <li>Page と呼ばれる固定長のブロックに分割して、メモリとスワップ領域で Page を入れ替えて管理</li> |
249 <li>仮想メモリとして扱うことでフラグメンテーションの解消と空き番地を探す必要がなくなる</li> | 141 <li>仮想メモリとして扱うことでフラグメンテーションの解消と空き番地を探す必要がなくなる</li> |
250 </ul><hr><h1 id="Pagingの図" style=""><a class="anchor hidden-xs" href="#Pagingの図" title="Pagingの図"><span class="octicon octicon-link"></span></a>Pagingの図</h1><ul> | 142 </ul><hr><h1 id="Xv6の書き換え方針" style=""><a class="anchor hidden-xs" href="#Xv6の書き換え方針" title="Xv6の書き換え方針"><span class="octicon octicon-link"></span></a>Xv6の書き換え方針</h1><ul> |
251 <li>必要?</li> | 143 <li> |
252 </ul><hr><h1 id="メタレベルでの-Paging-の操作" style=""><a class="anchor hidden-xs" href="#メタレベルでの-Paging-の操作" title="メタレベルでの-Paging-の操作"><span class="octicon octicon-link"></span></a>メタレベルでの Paging の操作</h1><ul> | 144 <p>メタレベルとノーマルレベルを記述できるOSを実装したい</p> |
253 <li>Page Table に相当するデータを Input Data Gear で受け取って変更した後、Context にある Meta Data Gear に goto で遷移してアクセス</li> | 145 </li> |
254 <li>メタレベルで処理することで本来カーネル側の処理である Page Table を操作できる</li> | 146 <li> |
255 </ul><hr><h1 id="Paging-の信頼性" style=""><a class="anchor hidden-xs" href="#Paging-の信頼性" title="Paging-の信頼性"><span class="octicon octicon-link"></span></a>Paging の信頼性</h1><ul> | 147 <p>段階的に書き換えていきたい</p> |
256 <li>Input Data Gear に対しての Output Data Gear をバリデーションチェックすることで他のプロセスから書き換えられることを防ぐ</li> | 148 </li> |
257 <li>サンドボックス | 149 <li> |
258 <ul> | 150 <p>Paging を書き換える理由</p> |
259 <li>他のプロセスから書き換えられた時にエクセプションを飛ばす</li> | 151 <ul> |
260 </ul> | 152 <li>OS の信頼性を保証する上で重要なメモリ管理部分</li> |
261 </li> | 153 </ul> |
262 </ul><hr><h1 id="Paging-の書き換え" style=""><a class="anchor hidden-xs" href="#Paging-の書き換え" title="Paging-の書き換え"><span class="octicon octicon-link"></span></a>Paging の書き換え</h1><ul> | 154 </li> |
263 <li>Xv6 では実メモリから仮想メモリの変換をvm.cで行なっている。</li> | 155 <li> |
264 <li>次の章で書き換えについて説明する</li> | 156 <p>__code で書き直していく</p> |
265 </ul><hr><h1 id="目次4" style=""><a class="anchor hidden-xs" href="#目次4" title="目次4"><span class="octicon octicon-link"></span></a>目次</h1><ol> | 157 </li> |
266 <li>OS の信頼性の保証</li> | 158 </ul><hr><h1 id="CbCインターフェース0" style=""><a class="anchor hidden-xs" href="#CbCインターフェース0" title="CbCインターフェース0"><span class="octicon octicon-link"></span></a>CbCインターフェース</h1><ul> |
267 <li>CbC による Gears OS の開発</li> | 159 <li> |
268 <li>Xv6</li> | 160 <p>ノーマルレベルからメタレベルの記述が記述が煩雑になるためインターフェースを導入</p> |
269 <li>CbCXv6 での Paging</li> | 161 </li> |
270 <li><strong>CbC インターフェース</strong></li> | 162 <li> |
271 <li>評価</li> | 163 <p>インターフェースによる他のメリット</p> |
272 <li>まとめ</li> | 164 <ul> |
273 </ol><hr><h1 id="CbC-インターフェースの導入" style=""><a class="anchor hidden-xs" href="#CbC-インターフェースの導入" title="CbC-インターフェースの導入"><span class="octicon octicon-link"></span></a>CbC インターフェースの導入</h1><ul> | 165 <li>煩雑な記述の解消</li> |
274 <li>継続の記述が煩雑になる | 166 <li>実装の入れ替え</li> |
275 <ul> | 167 </ul> |
276 <li>Code Gear がどの Data Gear の番号に対応するか指定する必要がある</li> | 168 </li> |
277 <li>ノーマルレベルとメタレベルで Data Gear の見え方が異なるため調整する必要がある</li> | 169 <li> |
278 </ul> | 170 <p>実装は別で定義し、呼び出す</p> |
279 </li> | 171 </li> |
280 <li>->インターフェースの導入</li> | 172 <li> |
281 </ul><hr><h1 id="CbC-インターフェース" style=""><a class="anchor hidden-xs" href="#CbC-インターフェース" title="CbC-インターフェース"><span class="octicon octicon-link"></span></a>CbC インターフェース</h1><ul> | 173 <p>インターフェースによって実装を置き換えることができる</p> |
282 <li>インターフェースは Data Gear に対しての操作を行う Code Gear</li> | 174 </li> |
283 <li>実装は別で定義し、呼び出す</li> | 175 </ul><hr><h1 id="CbCインターフェース" style=""><a class="anchor hidden-xs" href="#CbCインターフェース" title="CbCインターフェース"><span class="octicon octicon-link"></span></a>CbCインターフェース</h1><ul> |
284 <li>インターフェースによって機能を置き換えることができる</li> | 176 <li> |
285 </ul><hr><h1 id="インターフェースの定義" style=""><a class="anchor hidden-xs" href="#インターフェースの定義" title="インターフェースの定義"><span class="octicon octicon-link"></span></a>インターフェースの定義</h1><ul> | 177 <p>Data Gear と Data Gear に対して操作を行う Code Gear の集合を表現する <strong>Meta Data Gear</strong></p> |
286 <li>Data Gear と Data Gear に対して操作を行う Code Gear の集合を表現する <strong>Meta Data Gear</strong></li> | 178 </li> |
287 </ul><hr><h1 id="インターフェースのソースコード" style=""><a class="anchor hidden-xs" href="#インターフェースのソースコード" title="インターフェースのソースコード"><span class="octicon octicon-link"></span></a>インターフェースのソースコード</h1><ul> | 179 <li> |
288 <li>vm.c をインターフェースで書き換えた vm.h のコードの説明をしていく</li> | 180 <p>インターフェース実装と定義の図入れる</p> |
289 </ul><hr><h1 id="実装名の定義" style=""><a class="anchor hidden-xs" href="#実装名の定義" title="実装名の定義"><span class="octicon octicon-link"></span></a>実装名の定義</h1><ul> | 181 </li> |
290 <li>typedef struct の直後に実装名(vm)を書く</li> | 182 </ul><hr><h1 id="インターフェースの定義0" style=""><a class="anchor hidden-xs" href="#インターフェースの定義0" title="インターフェースの定義0"><span class="octicon octicon-link"></span></a>インターフェースの定義</h1><ul> |
183 <li>Xv6 の Virtual Memory の API 部分のインターフェース</li> | |
291 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm<span class="token operator"><</span>Type<span class="token punctuation">,</span>Impl<span class="token operator">></span> <span class="token punctuation">{</span> | 184 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm<span class="token operator"><</span>Type<span class="token punctuation">,</span>Impl<span class="token operator">></span> <span class="token punctuation">{</span> |
292 </code></pre><hr><h1 id="Data-Gear-の定義" style=""><a class="anchor hidden-xs" href="#Data-Gear-の定義" title="Data-Gear-の定義"><span class="octicon octicon-link"></span></a>Data Gear の定義</h1><ul> | 185 __code <span class="token function">init_vmm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
293 <li>2行目から19行目で引数の Data Gear を定義している</li> | |
294 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm<span class="token operator"><</span>Type<span class="token punctuation">,</span>Impl<span class="token operator">></span> <span class="token punctuation">{</span> | |
295 <span class="token keyword">union</span> Data<span class="token operator">*</span> vm<span class="token punctuation">;</span> | |
296 uint low<span class="token punctuation">;</span> | |
297 uint hi<span class="token punctuation">;</span> | |
298 <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">;</span> | |
299 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | |
300 </code></pre><hr><h1 id="Code-Gear-の定義" style=""><a class="anchor hidden-xs" href="#Code-Gear-の定義" title="Code-Gear-の定義"><span class="octicon octicon-link"></span></a>Code Gear の定義</h1><ul> | |
301 <li>Code Gear は __Code CodeGear名(引数); で記述する</li> | |
302 <li>第1引数の Impl* vm が Code Gear の型になる</li> | |
303 <li>初期化された Data Gear が それぞれの Code Gear の引数として扱われる</li> | |
304 <li>例)定義された uinit が kpt_freerange の Code Gear の第1引数と対応している</li> | |
305 </ul><pre><code class="c hljs"> __code <span class="token function">init_vmm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
306 __code <span class="token function">kpt_freerange</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> uint low<span class="token punctuation">,</span> uint hi<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 186 __code <span class="token function">kpt_freerange</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> uint low<span class="token punctuation">,</span> uint hi<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
307 __code <span class="token function">kpt_alloc</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span>__code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 187 __code <span class="token function">kpt_alloc</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span>__code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
308 __code <span class="token function">switchuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span><span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 188 __code <span class="token function">switchuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span><span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
309 __code <span class="token function">init_inituvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> init<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 189 __code <span class="token function">init_inituvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> init<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
310 __code <span class="token function">loaduvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span>pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 190 __code <span class="token function">loaduvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span>pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
311 __code <span class="token function">allocuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> uint oldsz<span class="token punctuation">,</span> uint newsz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 191 __code <span class="token function">allocuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> uint oldsz<span class="token punctuation">,</span> uint newsz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
312 | 192 |
313 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 193 </code></pre><hr><h1 id="インターフェースの命名" style=""><a class="anchor hidden-xs" href="#インターフェースの命名" title="インターフェースの命名"><span class="octicon octicon-link"></span></a>インターフェースの命名</h1><ul> |
194 <li>typedef struct の直後にインターフェース名(vm)を書く</li> | |
195 <li>Data Gear にマッピングされる</li> | |
196 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm<span class="token operator"><</span>Type<span class="token punctuation">,</span>Impl<span class="token operator">></span> <span class="token punctuation">{</span> | |
197 </code></pre><hr><h1 id="インターフェースの-Code-Gear" style=""><a class="anchor hidden-xs" href="#インターフェースの-Code-Gear" title="インターフェースの-Code-Gear"><span class="octicon octicon-link"></span></a>インターフェースの Code Gear</h1><ul> | |
198 <li>Code Gear は __code CodeGear名(引数); で記述する | |
199 <ul> | |
200 <li>引数が Data Gear に相当する</li> | |
201 </ul> | |
202 </li> | |
203 <li>第1引数の Impl* vm がインターフェースの実装の型になる</li> | |
204 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm<span class="token operator"><</span>Type<span class="token punctuation">,</span>Impl<span class="token operator">></span> <span class="token punctuation">{</span> | |
205 __code <span class="token function">init_vmm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
206 __code <span class="token function">kpt_freerange</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> uint low<span class="token punctuation">,</span> uint hi<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
207 __code <span class="token function">kpt_alloc</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span>__code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
208 __code <span class="token function">switchuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm <span class="token punctuation">,</span><span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
209 __code <span class="token function">init_inituvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> init<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
210 __code <span class="token function">loaduvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span>pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
211 __code <span class="token function">allocuvm</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> uint oldsz<span class="token punctuation">,</span> uint newsz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
314 | 212 |
315 </code></pre><hr><h1 id="next…" style=""><a class="anchor hidden-xs" href="#next…" title="next…"><span class="octicon octicon-link"></span></a>next(…)</h1><ul> | 213 </code></pre><hr><h1 id="next…" style=""><a class="anchor hidden-xs" href="#next…" title="next…"><span class="octicon octicon-link"></span></a>next(…)</h1><ul> |
316 <li>__code next(…) は条件分岐によって複数の継続先が設定される</li> | 214 <li>__code next(…) は次の Code Gear の継続先</li> |
317 <li>それぞれの Code Gear の引数の1つに設定する</li> | 215 <li>それぞれの Code Gear の引数の1つに設定する</li> |
318 </ul><pre><code class="c hljs"> __code <span class="token function">kpt_freerange</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> uint low<span class="token punctuation">,</span> uint hi<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 216 </ul><pre><code class="c hljs"> __code <span class="token function">kpt_freerange</span><span class="token punctuation">(</span>Impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> uint low<span class="token punctuation">,</span> uint hi<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
319 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 217 <span class="token comment">//....</span> |
320 __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 218 __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
321 <span class="token punctuation">}</span> vm<span class="token punctuation">;</span> | 219 <span class="token punctuation">}</span> vm<span class="token punctuation">;</span> |
220 </code></pre><pre><code class="c hljs">__code <span class="token function">exit</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span> | |
221 <span class="token comment">//....</span> | |
222 <span class="token punctuation">}</span> | |
223 | |
224 <span class="token keyword">goto</span> vm<span class="token operator">-></span><span class="token function">kpt_freerange</span><span class="token punctuation">(</span>vm<span class="token punctuation">,</span> low<span class="token punctuation">,</span> hi<span class="token punctuation">,</span> exit<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
225 </code></pre><hr><h1 id="Interface-の実装の型" style=""><a class="anchor hidden-xs" href="#Interface-の実装の型" title="Interface-の実装の型"><span class="octicon octicon-link"></span></a>Interface の実装の型</h1><ul> | |
226 <li>実装側のヘッダーファイルも vm_impl と同じように用意する</li> | |
227 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm_impl<span class="token operator"><</span>Impl<span class="token punctuation">,</span> Isa<span class="token operator">></span> impl vm<span class="token punctuation">{</span> | |
228 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | |
229 __code <span class="token function">loaduvm_ptesize_check</span><span class="token punctuation">(</span>Type<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> uint i<span class="token punctuation">,</span> pte_t<span class="token operator">*</span> pte<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> | |
230 __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
322 </code></pre><hr><h1 id="インターフェースの実装" style=""><a class="anchor hidden-xs" href="#インターフェースの実装" title="インターフェースの実装"><span class="octicon octicon-link"></span></a>インターフェースの実装</h1><ul> | 231 </code></pre><hr><h1 id="インターフェースの実装" style=""><a class="anchor hidden-xs" href="#インターフェースの実装" title="インターフェースの実装"><span class="octicon octicon-link"></span></a>インターフェースの実装</h1><ul> |
323 <li>インターフェースの実装は別ファイルで定義する(vm_impl.cbc)</li> | 232 <li>実装は型と実装をそれぞれ別ファイルで定義する(vm_impl.h と vm_impl.cbc)</li> |
324 <li>ヘッダーファイルの呼び出しは #include ではなく #interface で呼び出す</li> | 233 <li>実装するインターフェースは #interface で宣言する</li> |
325 </ul><pre><code class="c hljs"><span class="token macro property">#<span class="token directive keyword">include</span> <span class="token string">"../../context.h"</span></span> | 234 </ul><pre><code class="c hljs"><span class="token macro property">#interface "vm.h"</span> |
326 <span class="token macro property">#interface "vm.h"</span> | 235 </code></pre><hr><h1 class="highlight" id="vm_impl-のコンストラクタ" style=""><a class="anchor hidden-xs" href="#vm_impl-のコンストラクタ" title="vm_impl-のコンストラクタ"><span class="octicon octicon-link"></span></a>vm_impl のコンストラクタ</h1><ul> |
327 | 236 <li> |
328 </code></pre><hr><h1 id="create_impl" style=""><a class="anchor hidden-xs" href="#create_impl" title="create_impl"><span class="octicon octicon-link"></span></a>create_impl</h1><ul> | 237 <p>create_imple の関数内で vm の型を定義し、vm->CodeGear名 で対応させていく</p> |
329 <li>create_imple の関数内で vm の型を定義し、vm->CodeGear名 で対応させていく</li> | 238 </li> |
330 <li>実装を Code Gear で記述していく。</li> | 239 <li> |
331 </ul><pre><code class="c hljs"> | 240 <p>実装を Code Gear で記述していく。</p> |
332 vm<span class="token operator">*</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">)</span> <span class="token punctuation">{</span> | 241 </li> |
242 <li> | |
243 <p>struct vm* vm = new vm();</p> | |
244 <ul> | |
245 <li>インターフェースのメモリ空間を確保</li> | |
246 </ul> | |
247 </li> | |
248 <li> | |
249 <p>vm->void_ret = C_vm_void_ret;</p> | |
250 <ul> | |
251 <li>Code Gear の enum の設定</li> | |
252 <li>インターフェースのAPIと enum の番号を紐付けている</li> | |
253 </ul> | |
254 </li> | |
255 </ul><pre><code class="c hljs">vm<span class="token operator">*</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
333 <span class="token keyword">struct</span> vm<span class="token operator">*</span> vm <span class="token operator">=</span> new <span class="token function">vm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 256 <span class="token keyword">struct</span> vm<span class="token operator">*</span> vm <span class="token operator">=</span> new <span class="token function">vm</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
334 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 257 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> |
335 vm<span class="token operator">-></span>void_ret <span class="token operator">=</span> C_vm_void_ret<span class="token punctuation">;</span> | 258 vm<span class="token operator">-></span>void_ret <span class="token operator">=</span> C_vm_void_ret<span class="token punctuation">;</span> |
336 vm<span class="token operator">-></span>init_vmm <span class="token operator">=</span> C_init_vmmvm_impl<span class="token punctuation">;</span> | 259 vm<span class="token operator">-></span>init_vmm <span class="token operator">=</span> C_init_vmmvm_impl<span class="token punctuation">;</span> |
337 vm<span class="token operator">-></span>kpt_freerange <span class="token operator">=</span> C_kpt_freerangevm_impl<span class="token punctuation">;</span> | 260 vm<span class="token operator">-></span>kpt_freerange <span class="token operator">=</span> C_kpt_freerangevm_impl<span class="token punctuation">;</span> |
338 vm<span class="token operator">-></span>kpt_alloc <span class="token operator">=</span> C_kpt_allocvm_impl<span class="token punctuation">;</span> | 261 vm<span class="token operator">-></span>kpt_alloc <span class="token operator">=</span> C_kpt_allocvm_impl<span class="token punctuation">;</span> |
339 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 262 </code></pre><ul> |
340 __code <span class="token function">init_vmmvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm<span class="token punctuation">,</span>__code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 263 <li>APIの実装の例(init_vmm) |
264 <ul> | |
265 <li>C_init_vmmvm_impl が メタレベルでinit_vmmvm_impl と対応する</li> | |
266 </ul> | |
267 </li> | |
268 </ul><pre><code class="c hljs">__code <span class="token function">init_vmmvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm<span class="token punctuation">,</span>__code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
341 <span class="token function">initlock</span><span class="token punctuation">(</span><span class="token operator">&</span>kpt_mem<span class="token punctuation">.</span>lock<span class="token punctuation">,</span> <span class="token string">"vm"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 269 <span class="token function">initlock</span><span class="token punctuation">(</span><span class="token operator">&</span>kpt_mem<span class="token punctuation">.</span>lock<span class="token punctuation">,</span> <span class="token string">"vm"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
342 kpt_mem<span class="token punctuation">.</span>freelist <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span> | 270 kpt_mem<span class="token punctuation">.</span>freelist <span class="token operator">=</span> <span class="token constant">NULL</span><span class="token punctuation">;</span> |
343 | 271 |
344 <span class="token keyword">goto</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 272 <span class="token keyword">goto</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
345 <span class="token punctuation">}</span> | 273 <span class="token punctuation">}</span> |
346 </code></pre><hr><h1 id="private" style=""><a class="anchor hidden-xs" href="#private" title="private"><span class="octicon octicon-link"></span></a>private</h1><ul> | 274 </code></pre><hr><h1 id="インターフェース実装内の-CbC" style=""><a class="anchor hidden-xs" href="#インターフェース実装内の-CbC" title="インターフェース実装内の-CbC"><span class="octicon octicon-link"></span></a>インターフェース実装内の CbC</h1><ul> |
347 <li>CbC は信頼性を保証するためにそれぞれの Code Gear を細かくする必要があるので、for文やif文がある場合はさらに実装を分ける</li> | 275 <li>for文やif文がある場合はさらに実装を分ける |
348 <li>Code Gear は基本的にインターフェースで指定された Code Gear 内からのみ継続さ れるため、Java の private メソッドのように扱われる。</li> | 276 <ul> |
277 <li>状態遷移ベースで記述したい</li> | |
278 </ul> | |
279 </li> | |
280 <li>インターフェースは外から呼び出されるAPI</li> | |
281 <li>それに対してインターフェースの実装の Code Gearから明示的に呼び出される Code Gearは、Java の private メソッドのように扱われる。</li> | |
349 <li>実際に vm.c の loaduvm の実装を分けた記述を説明する</li> | 282 <li>実際に vm.c の loaduvm の実装を分けた記述を説明する</li> |
350 </ul><pre><code class="c hljs"><span class="token keyword">int</span> loaduvm <span class="token punctuation">(</span>pde_t <span class="token operator">*</span>pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span>addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode <span class="token operator">*</span>ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span> | 283 </ul><hr><h1 id="実装内の明示的な遷移の処理" style=""><a class="anchor hidden-xs" href="#実装内の明示的な遷移の処理" title="実装内の明示的な遷移の処理"><span class="octicon octicon-link"></span></a>実装内の明示的な遷移の処理</h1><ul> |
351 <span class="token punctuation">{</span> | |
352 uint i<span class="token punctuation">,</span> pa<span class="token punctuation">,</span> n<span class="token punctuation">;</span> | |
353 pte_t <span class="token operator">*</span>pte<span class="token punctuation">;</span> | |
354 | |
355 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>uint<span class="token punctuation">)</span> addr <span class="token operator">%</span> PTE_SZ <span class="token operator">!=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
356 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"loaduvm: addr must be page aligned"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
357 <span class="token punctuation">}</span> | |
358 | |
359 <span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> sz<span class="token punctuation">;</span> i <span class="token operator">+</span><span class="token operator">=</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
360 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>pte <span class="token operator">=</span> <span class="token function">walkpgdir</span><span class="token punctuation">(</span>pgdir<span class="token punctuation">,</span> addr <span class="token operator">+</span> i<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
361 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"loaduvm: address should exist"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
362 <span class="token punctuation">}</span> | |
363 | |
364 pa <span class="token operator">=</span> <span class="token function">PTE_ADDR</span><span class="token punctuation">(</span><span class="token operator">*</span>pte<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
365 | |
366 <span class="token keyword">if</span> <span class="token punctuation">(</span>sz <span class="token operator">-</span> i <span class="token operator"><</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
367 n <span class="token operator">=</span> sz <span class="token operator">-</span> i<span class="token punctuation">;</span> | |
368 <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> | |
369 n <span class="token operator">=</span> PTE_SZ<span class="token punctuation">;</span> | |
370 <span class="token punctuation">}</span> | |
371 | |
372 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">readi</span><span class="token punctuation">(</span>ip<span class="token punctuation">,</span> <span class="token function">p2v</span><span class="token punctuation">(</span>pa<span class="token punctuation">)</span><span class="token punctuation">,</span> offset <span class="token operator">+</span> i<span class="token punctuation">,</span> n<span class="token punctuation">)</span> <span class="token operator">!=</span> n<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
373 <span class="token keyword">return</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> | |
374 <span class="token punctuation">}</span> | |
375 <span class="token punctuation">}</span> | |
376 | |
377 <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span> | |
378 <span class="token punctuation">}</span> | |
379 </code></pre><hr><h1 id="goto-private" style=""><a class="anchor hidden-xs" href="#goto-private" title="goto-private"><span class="octicon octicon-link"></span></a>goto private</h1><ul> | |
380 <li>vm と同じ create_impl 内で vm_impl を定義し、private で実装する Code Gear を定義する</li> | 284 <li>vm と同じ create_impl 内で vm_impl を定義し、private で実装する Code Gear を定義する</li> |
381 <li>loaduvmvm_impl で goto によって private に遷移する</li> | 285 <li>loaduvmvm_impl で goto によって private に遷移する</li> |
382 </ul><pre><code class="c hljs">vm<span class="token operator">*</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">)</span> <span class="token punctuation">{</span> | 286 </ul><pre class="highlight"><code class="c hljs">__code <span class="token function">loaduvmvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
287 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> | |
288 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>addr <span class="token operator">=</span> addr<span class="token punctuation">;</span> | |
289 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>ip <span class="token operator">=</span> ip<span class="token punctuation">;</span> | |
290 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>offset <span class="token operator">=</span> offset<span class="token punctuation">;</span> | |
291 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>sz <span class="token operator">=</span> sz<span class="token punctuation">;</span> | |
292 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>next <span class="token operator">=</span> next<span class="token punctuation">;</span> | |
293 | |
294 <span class="token keyword">goto</span> <span class="token function">loaduvm_ptesize_checkvm_impl</span><span class="token punctuation">(</span>vm<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
295 <span class="token punctuation">}</span> | |
296 </code></pre><pre class="highlight"><code class="c hljs">vm<span class="token operator">*</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
383 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 297 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> |
384 <span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl <span class="token operator">=</span> new <span class="token function">vm_impl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 298 <span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl <span class="token operator">=</span> new <span class="token function">vm_impl</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
385 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 299 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> |
386 vm_impl<span class="token operator">-></span>loaduvm_ptesize_check <span class="token operator">=</span> C_loaduvm_ptesize_checkvm_impl<span class="token punctuation">;</span> | 300 vm_impl<span class="token operator">-></span>loaduvm_ptesize_check <span class="token operator">=</span> C_loaduvm_ptesize_checkvm_impl<span class="token punctuation">;</span> |
387 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 301 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> |
388 vm<span class="token operator">-></span>loaduvm <span class="token operator">=</span> C_loaduvmvm_impl<span class="token punctuation">;</span> | 302 vm<span class="token operator">-></span>loaduvm <span class="token operator">=</span> C_loaduvmvm_impl<span class="token punctuation">;</span> |
389 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 303 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> |
390 <span class="token punctuation">}</span> | 304 <span class="token punctuation">}</span> |
391 | 305 </code></pre><hr><h1 id="loaduvmの-CbCによる書き換え" style=""><a class="anchor hidden-xs" href="#loaduvmの-CbCによる書き換え" title="loaduvmの-CbCによる書き換え"><span class="octicon octicon-link"></span></a>loaduvmの CbCによる書き換え</h1><ul> |
392 __code <span class="token function">loaduvmvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 306 <li>loaduvmは何でなぜ書き換えてるのか</li> |
307 <li>vm.cのloaduvmの処理をCbC で書き換える</li> | |
308 </ul><pre><code class="c hljs"><span class="token keyword">int</span> loaduvm <span class="token punctuation">(</span>pde_t <span class="token operator">*</span>pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span>addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode <span class="token operator">*</span>ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span> | |
309 <span class="token punctuation">{</span> | |
310 uint i<span class="token punctuation">,</span> pa<span class="token punctuation">,</span> n<span class="token punctuation">;</span> | |
311 pte_t <span class="token operator">*</span>pte<span class="token punctuation">;</span> | |
312 | |
313 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>uint<span class="token punctuation">)</span> addr <span class="token operator">%</span> PTE_SZ <span class="token operator">!=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
314 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"loaduvm: addr must be page aligned"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
315 <span class="token punctuation">}</span> | |
316 | |
317 <span class="token keyword">for</span> <span class="token punctuation">(</span>i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator"><</span> sz<span class="token punctuation">;</span> i <span class="token operator">+</span><span class="token operator">=</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
318 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>pte <span class="token operator">=</span> <span class="token function">walkpgdir</span><span class="token punctuation">(</span>pgdir<span class="token punctuation">,</span> addr <span class="token operator">+</span> i<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
319 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"loaduvm: address should exist"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
320 <span class="token punctuation">}</span> | |
321 | |
322 pa <span class="token operator">=</span> <span class="token function">PTE_ADDR</span><span class="token punctuation">(</span><span class="token operator">*</span>pte<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
323 | |
324 <span class="token keyword">if</span> <span class="token punctuation">(</span>sz <span class="token operator">-</span> i <span class="token operator"><</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
325 n <span class="token operator">=</span> sz <span class="token operator">-</span> i<span class="token punctuation">;</span> | |
326 <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> | |
327 n <span class="token operator">=</span> PTE_SZ<span class="token punctuation">;</span> | |
328 <span class="token punctuation">}</span> | |
329 | |
330 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token function">readi</span><span class="token punctuation">(</span>ip<span class="token punctuation">,</span> <span class="token function">p2v</span><span class="token punctuation">(</span>pa<span class="token punctuation">)</span><span class="token punctuation">,</span> offset <span class="token operator">+</span> i<span class="token punctuation">,</span> n<span class="token punctuation">)</span> <span class="token operator">!=</span> n<span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
331 <span class="token keyword">return</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span> | |
332 <span class="token punctuation">}</span> | |
333 <span class="token punctuation">}</span> | |
334 | |
335 <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span> | |
336 <span class="token punctuation">}</span> | |
337 </code></pre><ul> | |
338 <li>loaduvm_impl がインターフェースから呼ばれる実装</li> | |
339 </ul><pre><code class="c hljs">__code <span class="token function">loaduvmvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
393 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> | 340 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> |
394 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>addr <span class="token operator">=</span> addr<span class="token punctuation">;</span> | 341 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>addr <span class="token operator">=</span> addr<span class="token punctuation">;</span> |
395 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>ip <span class="token operator">=</span> ip<span class="token punctuation">;</span> | 342 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>ip <span class="token operator">=</span> ip<span class="token punctuation">;</span> |
396 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>offset <span class="token operator">=</span> offset<span class="token punctuation">;</span> | 343 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>offset <span class="token operator">=</span> offset<span class="token punctuation">;</span> |
397 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>sz <span class="token operator">=</span> sz<span class="token punctuation">;</span> | 344 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>sz <span class="token operator">=</span> sz<span class="token punctuation">;</span> |
398 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>next <span class="token operator">=</span> next<span class="token punctuation">;</span> | 345 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm_impl<span class="token punctuation">)</span><span class="token operator">-></span>next <span class="token operator">=</span> next<span class="token punctuation">;</span> |
399 | 346 |
400 <span class="token keyword">goto</span> <span class="token function">loaduvm_ptesize_checkvm_impl</span><span class="token punctuation">(</span>vm<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 347 <span class="token keyword">goto</span> <span class="token function">loaduvm_ptesize_checkvm_impl</span><span class="token punctuation">(</span>vm<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
401 <span class="token punctuation">}</span> | 348 <span class="token punctuation">}</span> |
402 </code></pre><hr><h1 id="private-のヘッダー" style=""><a class="anchor hidden-xs" href="#private-のヘッダー" title="private-のヘッダー"><span class="octicon octicon-link"></span></a>private のヘッダー</h1><ul> | 349 </code></pre><ul> |
403 <li>private 側のヘッダーファイルも vm_impl と同じように用意する</li> | 350 <li>loaduvm_impl から private な Code Gear が呼ばれる</li> |
404 </ul><pre><code class="c hljs"><span class="token keyword">typedef</span> <span class="token keyword">struct</span> vm_impl<span class="token operator"><</span>Impl<span class="token punctuation">,</span> Isa<span class="token operator">></span> impl vm<span class="token punctuation">{</span> | 351 </ul><pre><code class="c hljs"><span class="token macro property">#interface "vm_impl.h"</span> |
405 <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> | 352 |
406 __code <span class="token function">loaduvm_ptesize_check</span><span class="token punctuation">(</span>Type<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> uint i<span class="token punctuation">,</span> pte_t<span class="token operator">*</span> pte<span class="token punctuation">,</span> uint sz<span class="token punctuation">,</span> | 353 __code <span class="token function">loaduvm_ptesize_checkvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
407 __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
408 </code></pre><hr><h1 id="private-の記述" style=""><a class="anchor hidden-xs" href="#private-の記述" title="private-の記述"><span class="octicon octicon-link"></span></a>private の記述</h1><pre><code class="c hljs"><span class="token macro property">#interface "vm_impl.h"</span> | |
409 | |
410 __code <span class="token function">loaduvm_ptesize_checkvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
411 <span class="token keyword">char</span><span class="token operator">*</span> addr <span class="token operator">=</span> vm_impl<span class="token operator">-></span>addr<span class="token punctuation">;</span> | 354 <span class="token keyword">char</span><span class="token operator">*</span> addr <span class="token operator">=</span> vm_impl<span class="token operator">-></span>addr<span class="token punctuation">;</span> |
412 | 355 |
413 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>uint<span class="token punctuation">)</span> addr <span class="token operator">%</span>PTE_SZ <span class="token operator">!=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 356 <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token punctuation">(</span>uint<span class="token punctuation">)</span> addr <span class="token operator">%</span>PTE_SZ <span class="token operator">!=</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
414 <span class="token comment">// goto panic</span> | 357 <span class="token comment">// goto panic</span> |
415 <span class="token punctuation">}</span> | 358 <span class="token punctuation">}</span> |
416 | 359 |
417 <span class="token keyword">goto</span> <span class="token function">loaduvm_loopvm_impl</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 360 <span class="token keyword">goto</span> <span class="token function">loaduvm_loopvm_impl</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
418 <span class="token punctuation">}</span> | 361 <span class="token punctuation">}</span> |
419 </code></pre><ul> | 362 </code></pre><ul> |
420 <li>vm.cではここから for だが CbC は if文の中と外にgoto を用意して実装する</li> | 363 <li>vm.cではここから for だが CbC は if文の中と外にgoto を用意して実装する</li> |
421 </ul><p><img src="https://i.imgur.com/ByA7GVJ.png" alt=""></p><pre><code class="c hljs">__code <span class="token function">loaduvm_loopvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 364 </ul><p><img src="https://i.imgur.com/ByA7GVJ.png" alt=""></p><pre><code class="c hljs">__code <span class="token function">loaduvm_loopvm_impl</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
422 uint i <span class="token operator">=</span> vm_impl<span class="token operator">-></span>i<span class="token punctuation">;</span> | 365 uint i <span class="token operator">=</span> vm_impl<span class="token operator">-></span>i<span class="token punctuation">;</span> |
423 uint sz <span class="token operator">=</span> vm_impl<span class="token operator">-></span>sz<span class="token punctuation">;</span> | 366 uint sz <span class="token operator">=</span> vm_impl<span class="token operator">-></span>sz<span class="token punctuation">;</span> |
424 | 367 |
425 <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator"><</span> sz<span class="token punctuation">)</span> <span class="token punctuation">{</span> | 368 <span class="token keyword">if</span> <span class="token punctuation">(</span>i <span class="token operator"><</span> sz<span class="token punctuation">)</span> <span class="token punctuation">{</span> |
426 <span class="token keyword">goto</span> <span class="token function">loaduvm_check_pgdir</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 369 <span class="token keyword">goto</span> <span class="token function">loaduvm_check_pgdir</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
427 <span class="token punctuation">}</span> | 370 <span class="token punctuation">}</span> |
428 | 371 |
429 <span class="token keyword">goto</span> <span class="token function">loaduvm_exit</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 372 <span class="token keyword">goto</span> <span class="token function">loaduvm_exit</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
430 <span class="token punctuation">}</span> | 373 <span class="token punctuation">}</span> |
431 | 374 |
432 | 375 |
433 __code <span class="token function">loaduvm_check_pgdir</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 376 __code <span class="token function">loaduvm_check_pgdir</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
434 pte_t<span class="token operator">*</span> pte <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pte<span class="token punctuation">;</span> | 377 pte_t<span class="token operator">*</span> pte <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pte<span class="token punctuation">;</span> |
435 pde_t<span class="token operator">*</span> pgdir <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pgdir<span class="token punctuation">;</span> | 378 pde_t<span class="token operator">*</span> pgdir <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pgdir<span class="token punctuation">;</span> |
436 uint i <span class="token operator">=</span> vm_impl<span class="token operator">-></span>i<span class="token punctuation">;</span> | 379 uint i <span class="token operator">=</span> vm_impl<span class="token operator">-></span>i<span class="token punctuation">;</span> |
437 <span class="token keyword">char</span><span class="token operator">*</span> addr <span class="token operator">=</span> vm_impl<span class="token operator">-></span>addr<span class="token punctuation">;</span> | 380 <span class="token keyword">char</span><span class="token operator">*</span> addr <span class="token operator">=</span> vm_impl<span class="token operator">-></span>addr<span class="token punctuation">;</span> |
438 uint pa <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pa<span class="token punctuation">;</span> | 381 uint pa <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pa<span class="token punctuation">;</span> |
445 vm_impl<span class="token operator">-></span>pte <span class="token operator">=</span> pte<span class="token punctuation">;</span> | 388 vm_impl<span class="token operator">-></span>pte <span class="token operator">=</span> pte<span class="token punctuation">;</span> |
446 vm_impl<span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> | 389 vm_impl<span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> |
447 vm_impl<span class="token operator">-></span>addr <span class="token operator">=</span> addr<span class="token punctuation">;</span> | 390 vm_impl<span class="token operator">-></span>addr <span class="token operator">=</span> addr<span class="token punctuation">;</span> |
448 vm_impl<span class="token operator">-></span>pa <span class="token operator">=</span> pa<span class="token punctuation">;</span> | 391 vm_impl<span class="token operator">-></span>pa <span class="token operator">=</span> pa<span class="token punctuation">;</span> |
449 | 392 |
450 <span class="token keyword">goto</span> <span class="token function">loaduvm_check_PTE_SZ</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 393 <span class="token keyword">goto</span> <span class="token function">loaduvm_check_PTE_SZ</span><span class="token punctuation">(</span>vm_impl<span class="token punctuation">,</span> <span class="token function">next</span><span class="token punctuation">(</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
451 <span class="token punctuation">}</span> | 394 <span class="token punctuation">}</span> |
452 | 395 |
453 __code <span class="token function">loaduvm_check_PTE_SZ</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 396 __code <span class="token function">loaduvm_check_PTE_SZ</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
454 uint sz <span class="token operator">=</span> vm_impl<span class="token operator">-></span>sz<span class="token punctuation">;</span> | |
455 uint i <span class="token operator">=</span> vm_impl<span class="token operator">-></span>i<span class="token punctuation">;</span> | |
456 uint n <span class="token operator">=</span> vm_impl<span class="token operator">-></span>n<span class="token punctuation">;</span> | |
457 <span class="token keyword">struct</span> inode<span class="token operator">*</span> ip <span class="token operator">=</span> vm_impl<span class="token operator">-></span>ip<span class="token punctuation">;</span> | |
458 uint pa <span class="token operator">=</span> vm_impl<span class="token operator">-></span>pa<span class="token punctuation">;</span> | |
459 uint offset <span class="token operator">=</span> vm_impl<span class="token operator">-></span>offset<span class="token punctuation">;</span> | |
460 | |
461 <span class="token keyword">if</span> <span class="token punctuation">(</span>sz <span class="token operator">-</span> i <span class="token operator"><</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> | 397 <span class="token keyword">if</span> <span class="token punctuation">(</span>sz <span class="token operator">-</span> i <span class="token operator"><</span> PTE_SZ<span class="token punctuation">)</span> <span class="token punctuation">{</span> |
462 n <span class="token operator">=</span> sz <span class="token operator">-</span> i<span class="token punctuation">;</span> | 398 n <span class="token operator">=</span> sz <span class="token operator">-</span> i<span class="token punctuation">;</span> |
463 <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> | 399 <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span> |
464 n <span class="token operator">=</span> PTE_SZ<span class="token punctuation">;</span> | 400 n <span class="token operator">=</span> PTE_SZ<span class="token punctuation">;</span> |
465 <span class="token punctuation">}</span> | 401 <span class="token punctuation">}</span> |
476 | 412 |
477 __code <span class="token function">loaduvm_exit</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 413 __code <span class="token function">loaduvm_exit</span><span class="token punctuation">(</span><span class="token keyword">struct</span> vm_impl<span class="token operator">*</span> vm_impl<span class="token punctuation">,</span> __code <span class="token function">next</span><span class="token punctuation">(</span><span class="token keyword">int</span> ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
478 ret <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> | 414 ret <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> |
479 <span class="token keyword">goto</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 415 <span class="token keyword">goto</span> <span class="token function">next</span><span class="token punctuation">(</span>ret<span class="token punctuation">,</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
480 <span class="token punctuation">}</span> | 416 <span class="token punctuation">}</span> |
481 </code></pre><pre><code class="c hljs"> | 417 </code></pre><hr><pre><code class="c hljs"> |
482 <span class="token keyword">int</span> loaduvm <span class="token punctuation">(</span>pde_t <span class="token operator">*</span>pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span>addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode <span class="token operator">*</span>ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span> | 418 <span class="token keyword">int</span> loaduvm <span class="token punctuation">(</span>pde_t <span class="token operator">*</span>pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span> <span class="token operator">*</span>addr<span class="token punctuation">,</span> <span class="token keyword">struct</span> inode <span class="token operator">*</span>ip<span class="token punctuation">,</span> uint offset<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span> |
483 <span class="token punctuation">{</span> | 419 <span class="token punctuation">{</span> |
484 uint i<span class="token punctuation">,</span> pa<span class="token punctuation">,</span> n<span class="token punctuation">;</span> | 420 uint i<span class="token punctuation">,</span> pa<span class="token punctuation">,</span> n<span class="token punctuation">;</span> |
485 pte_t <span class="token operator">*</span>pte<span class="token punctuation">;</span> | 421 pte_t <span class="token operator">*</span>pte<span class="token punctuation">;</span> |
486 | 422 |
506 <span class="token punctuation">}</span> | 442 <span class="token punctuation">}</span> |
507 <span class="token punctuation">}</span> | 443 <span class="token punctuation">}</span> |
508 | 444 |
509 <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span> | 445 <span class="token keyword">return</span> <span class="token number">0</span><span class="token punctuation">;</span> |
510 <span class="token punctuation">}</span> | 446 <span class="token punctuation">}</span> |
511 </code></pre><h1 id="インターフェースの呼び出し" style=""><a class="anchor hidden-xs" href="#インターフェースの呼び出し" title="インターフェースの呼び出し"><span class="octicon octicon-link"></span></a>インターフェースの呼び出し</h1><ul> | 447 </code></pre><hr><h1 id="stub" style=""><a class="anchor hidden-xs" href="#stub" title="stub"><span class="octicon octicon-link"></span></a>stub</h1><ul> |
512 <li>定義したインターフェースの呼び出しについて説明する</li> | 448 <li>goto meta はstub を呼び込んでいる</li> |
449 <li>説明</li> | |
450 </ul><hr><h1 id="C-を-CbC-に部分的に書き直す手法" style=""><a class="anchor hidden-xs" href="#C-を-CbC-に部分的に書き直す手法" title="C-を-CbC-に部分的に書き直す手法"><span class="octicon octicon-link"></span></a>C を CbC に部分的に書き直す手法</h1><ul> | |
513 <li>CbC の場合 goto による 遷移を行うので、関数呼び出しのように goto 以降のコードを実行できない</li> | 451 <li>CbC の場合 goto による 遷移を行うので、関数呼び出しのように goto 以降のコードを実行できない</li> |
514 <li>例) goto すると戻ってこれないため それ以降が実行されなくなる。</li> | 452 <li>例) goto すると戻ってこれないため それ以降が実行されなくなる。</li> |
515 </ul><pre><code class="c hljs"><span class="token keyword">void</span> <span class="token function">userinit</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> | 453 </ul><hr><h1 id="CbC-から-C-への遷移" style=""><a class="anchor hidden-xs" href="#CbC-から-C-への遷移" title="CbC-から-C-への遷移"><span class="octicon octicon-link"></span></a>CbC から C への遷移</h1><ul class="highlight"> |
516 <span class="token punctuation">{</span> | |
517 <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">;</span> | |
518 <span class="token keyword">extern</span> <span class="token keyword">char</span> _binary_initcode_start<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> _binary_initcode_size<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> | |
519 | |
520 p <span class="token operator">=</span> <span class="token function">allocproc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
521 <span class="token function">initContext</span><span class="token punctuation">(</span><span class="token operator">&</span>p<span class="token operator">-></span>cbc_context<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
522 | |
523 initproc <span class="token operator">=</span> p<span class="token punctuation">;</span> | |
524 | |
525 <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token punctuation">(</span>p<span class="token operator">-></span>pgdir <span class="token operator">=</span> <span class="token function">kpt_alloc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token constant">NULL</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | |
526 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"userinit: out of memory?"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
527 <span class="token punctuation">}</span> | |
528 | |
529 <span class="token keyword">goto</span> <span class="token function">cbc_init_vmm_dummy</span><span class="token punctuation">(</span><span class="token operator">&</span>p<span class="token operator">-></span>cbc_context<span class="token punctuation">,</span> p<span class="token punctuation">,</span> p<span class="token operator">-></span>pgdir<span class="token punctuation">,</span> _binary_initcode_start<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span>_binary_initcode_size<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
530 p<span class="token operator">-></span>sz <span class="token operator">=</span> PTE_SZ<span class="token punctuation">;</span> | |
531 | |
532 <span class="token comment">// craft the trapframe as if</span> | |
533 <span class="token function">memset</span><span class="token punctuation">(</span>p<span class="token operator">-></span>tf<span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">,</span> <span class="token keyword">sizeof</span><span class="token punctuation">(</span><span class="token operator">*</span>p<span class="token operator">-></span>tf<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | |
534 <span class="token operator">~</span> | |
535 </code></pre><h1 id="呼び出しの解決" style=""><a class="anchor hidden-xs" href="#呼び出しの解決" title="呼び出しの解決"><span class="octicon octicon-link"></span></a>呼び出しの解決</h1><ul> | |
536 <li>最初の命令は next で戻ってこれるので、dummy の関数を用意してそこで実行する</li> | 454 <li>最初の命令は next で戻ってこれるので、dummy の関数を用意してそこで実行する</li> |
537 </ul><pre><code class="c hljs"><span class="token keyword">void</span> <span class="token function">dummy</span><span class="token punctuation">(</span><span class="token keyword">struct</span> proc <span class="token operator">*</span>p<span class="token punctuation">,</span> <span class="token keyword">char</span> _binary_initcode_start<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token keyword">char</span> _binary_initcode_size<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> | 455 </ul><pre class="highlight"><code class="c hljs"><span class="token keyword">void</span> <span class="token function">cbc_init_vmm_dummy</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">,</span> <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> init<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span> |
538 <span class="token punctuation">{</span> | 456 <span class="token punctuation">{</span> |
539 <span class="token comment">// inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);</span> | 457 <span class="token comment">// inituvm(p->pgdir, _binary_initcode_start, (int)_binary_initcode_size);</span> |
540 <span class="token keyword">goto</span> <span class="token function">cbc_init_vmm_dummy</span><span class="token punctuation">(</span><span class="token operator">&</span>p<span class="token operator">-></span>cbc_context<span class="token punctuation">,</span> p<span class="token punctuation">,</span> p<span class="token operator">-></span>pgdir<span class="token punctuation">,</span> _binary_initcode_start<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span>_binary_initcode_size<span class="token punctuation">)</span><span class="token punctuation">;</span> | |
541 | |
542 <span class="token punctuation">}</span> | |
543 | |
544 | |
545 | |
546 __ncode <span class="token function">cbc_init_vmm_dummy</span><span class="token punctuation">(</span><span class="token keyword">struct</span> Context<span class="token operator">*</span> cbc_context<span class="token punctuation">,</span> <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">,</span> pde_t<span class="token operator">*</span> pgdir<span class="token punctuation">,</span> <span class="token keyword">char</span><span class="token operator">*</span> init<span class="token punctuation">,</span> uint sz<span class="token punctuation">)</span><span class="token punctuation">{</span><span class="token comment">//:skip</span> | |
547 | 458 |
548 <span class="token keyword">struct</span> vm<span class="token operator">*</span> vm <span class="token operator">=</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">)</span><span class="token punctuation">;</span> | 459 <span class="token keyword">struct</span> vm<span class="token operator">*</span> vm <span class="token operator">=</span> <span class="token function">createvm_impl</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">)</span><span class="token punctuation">;</span> |
549 <span class="token comment">// goto vm->init_vmm(vm, pgdir, init, sz , vm->void_ret);</span> | 460 <span class="token comment">// goto vm->init_vmm(vm, pgdir, init, sz , vm->void_ret);</span> |
550 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>vm <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">union</span> Data<span class="token operator">*</span><span class="token punctuation">)</span> vm<span class="token punctuation">;</span> | 461 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>vm <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword">union</span> Data<span class="token operator">*</span><span class="token punctuation">)</span> vm<span class="token punctuation">;</span> |
551 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> | 462 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>pgdir <span class="token operator">=</span> pgdir<span class="token punctuation">;</span> |
553 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>sz <span class="token operator">=</span> sz <span class="token punctuation">;</span> | 464 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>sz <span class="token operator">=</span> sz <span class="token punctuation">;</span> |
554 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>next <span class="token operator">=</span> C_vm_void_ret <span class="token punctuation">;</span> | 465 <span class="token function">Gearef</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token punctuation">)</span><span class="token operator">-></span>next <span class="token operator">=</span> C_vm_void_ret <span class="token punctuation">;</span> |
555 <span class="token keyword">goto</span> <span class="token function">meta</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token operator">-></span>init_inituvm<span class="token punctuation">)</span><span class="token punctuation">;</span> | 466 <span class="token keyword">goto</span> <span class="token function">meta</span><span class="token punctuation">(</span>cbc_context<span class="token punctuation">,</span> vm<span class="token operator">-></span>init_inituvm<span class="token punctuation">)</span><span class="token punctuation">;</span> |
556 <span class="token punctuation">}</span> | 467 <span class="token punctuation">}</span> |
557 | 468 |
558 | |
559 <span class="token keyword">void</span> <span class="token function">userinit</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> | 469 <span class="token keyword">void</span> <span class="token function">userinit</span><span class="token punctuation">(</span><span class="token keyword">void</span><span class="token punctuation">)</span> |
560 <span class="token punctuation">{</span> | 470 <span class="token punctuation">{</span> |
561 <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">;</span> | 471 <span class="token keyword">struct</span> proc<span class="token operator">*</span> p<span class="token punctuation">;</span> |
562 <span class="token keyword">extern</span> <span class="token keyword">char</span> _binary_initcode_start<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> _binary_initcode_size<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> | 472 <span class="token keyword">extern</span> <span class="token keyword">char</span> _binary_initcode_start<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> _binary_initcode_size<span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> |
563 | 473 |
568 | 478 |
569 <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token punctuation">(</span>p<span class="token operator">-></span>pgdir <span class="token operator">=</span> <span class="token function">kpt_alloc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token constant">NULL</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> | 479 <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token punctuation">(</span>p<span class="token operator">-></span>pgdir <span class="token operator">=</span> <span class="token function">kpt_alloc</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token constant">NULL</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> |
570 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"userinit: out of memory?"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> | 480 <span class="token function">panic</span><span class="token punctuation">(</span><span class="token string">"userinit: out of memory?"</span><span class="token punctuation">)</span><span class="token punctuation">;</span> |
571 <span class="token punctuation">}</span> | 481 <span class="token punctuation">}</span> |
572 | 482 |
573 <span class="token function">dummy</span><span class="token punctuation">(</span>p<span class="token punctuation">,</span> _binary_initcode_start<span class="token punctuation">,</span> _binary_initcode_size<span class="token punctuation">)</span><span class="token punctuation">;</span> | 483 <span class="token function">cbc_init_vmm_dummy</span><span class="token punctuation">(</span><span class="token operator">&</span>p<span class="token operator">-></span>cbc_context<span class="token punctuation">,</span> p<span class="token punctuation">,</span> p<span class="token operator">-></span>pgdir<span class="token punctuation">,</span> _binary_initcode_start<span class="token punctuation">,</span> <span class="token punctuation">(</span><span class="token keyword">int</span><span class="token punctuation">)</span>_binary_initcode_size<span class="token punctuation">)</span><span class="token punctuation">;</span> |
574 <span class="token operator">~</span> | 484 |
575 | 485 </code></pre><hr><h1 id="まとめ" style=""><a class="anchor hidden-xs" href="#まとめ" title="まとめ"><span class="octicon octicon-link"></span></a>まとめ</h1></div> |
576 </code></pre></div> | |
577 <div class="ui-toc dropup unselectable hidden-print" style="display:none;"> | 486 <div class="ui-toc dropup unselectable hidden-print" style="display:none;"> |
578 <div class="pull-right dropdown"> | 487 <div class="pull-right dropdown"> |
579 <a id="tocLabel" class="ui-toc-label btn btn-default" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="Table of content"> | 488 <a id="tocLabel" class="ui-toc-label btn btn-default" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="Table of content"> |
580 <i class="fa fa-bars"></i> | 489 <i class="fa fa-bars"></i> |
581 </a> | 490 </a> |
582 <ul id="ui-toc" class="ui-toc-dropdown dropdown-menu" aria-labelledby="tocLabel"> | 491 <ul id="ui-toc" class="ui-toc-dropdown dropdown-menu" aria-labelledby="tocLabel"> |
583 <div class="toc"><ul class="nav"> | 492 <div class="toc"><ul class="nav"> |
584 <li class=""><a href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる CbCXv6 の書き換え">CbCインターフェースによる CbCXv6 の書き換え</a></li> | 493 <li class=""><a href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる CbCXv6 の書き換え">CbCインターフェースによる CbCXv6 の書き換え</a></li> |
585 <li><a href="#目次" title="目次">目次</a></li> | 494 <li class=""><a href="#概要" title="概要">概要</a></li> |
586 <li><a href="#OS-の信頼性の重要性" title="OS の信頼性の重要性">OS の信頼性の重要性</a></li> | 495 <li class=""><a href="#OS-の信頼性を上げたい" title="OS の信頼性を上げたい">OS の信頼性を上げたい</a></li> |
587 <li><a href="#OS-の信頼性の重要性1" title="OS の信頼性の重要性">OS の信頼性の重要性</a></li> | 496 <li class=""><a href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル">メタレベルとノーマルレベル</a></li> |
588 <li><a href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル">メタレベルとノーマルレベル</a></li> | 497 <li class=""><a href="#Continuation-based-C" title="Continuation based C">Continuation based C</a></li> |
589 <li><a href="#Continuation-based-C" title="Continuation based C">Continuation based C</a></li> | 498 <li class=""><a href="#goto-による継続" title="goto による継続">goto による継続</a></li> |
590 <li><a href="#goto-による継続" title="goto による継続">goto による継続</a></li> | 499 <li class=""><a href="#Data-Gear-の継続" title="Data Gear の継続">Data Gear の継続</a></li> |
591 <li><a href="#Data-Gear-の継続" title="Data Gear の継続">Data Gear の継続</a></li> | 500 <li class=""><a href="#Meta-Code-Gear" title="Meta Code Gear">Meta Code Gear</a></li> |
592 <li><a href="#Meta-Code-Gear" title="Meta Code Gear">Meta Code Gear</a></li> | 501 <li class=""><a href="#Meta-Data-Gear" title="Meta Data Gear">Meta Data Gear</a></li> |
593 <li><a href="#状態遷移モデル" title="状態遷移モデル">状態遷移モデル</a></li> | 502 <li class=""><a href="#Xv6" title="Xv6">Xv6</a></li> |
594 <li><a href="#Agda-による検証" title="Agda による検証">Agda による検証</a></li> | 503 <li class=""><a href="#Xv6の構成" title="Xv6の構成">Xv6の構成</a></li> |
595 <li><a href="#Haure-Logic" title="Haure Logic">Haure Logic</a></li> | 504 <li class=""><a href="#カーネル空間" title="カーネル空間">カーネル空間</a></li> |
596 <li><a href="#Geas-OS" title="Geas OS">Geas OS</a></li> | 505 <li class=""><a href="#system-call" title="system call">system call</a></li> |
597 <li><a href="#メモリ管理" title="メモリ管理">メモリ管理</a></li> | 506 <li class=""><a href="#Paging" title="Paging">Paging</a></li> |
598 <li><a href="#インターフェース" title="インターフェース">インターフェース</a></li> | 507 <li class=""><a href="#Xv6の書き換え方針" title="Xv6の書き換え方針">Xv6の書き換え方針</a></li> |
599 <li><a href="#目次1" title="目次">目次</a></li> | 508 <li class=""><a href="#CbCインターフェース0" title="CbCインターフェース">CbCインターフェース</a></li> |
600 <li><a href="#CbC-による-Gears-OS-の開発" title="CbC による Gears OS の開発">CbC による Gears OS の開発</a></li> | 509 <li class=""><a href="#CbCインターフェース" title="CbCインターフェース">CbCインターフェース</a></li> |
601 <li><a href="#Context" title="Context">Context</a></li> | 510 <li class=""><a href="#インターフェースの定義0" title="インターフェースの定義">インターフェースの定義</a></li> |
602 <li><a href="#目次2" title="目次">目次</a></li> | 511 <li><a href="#インターフェースの命名" title="インターフェースの命名">インターフェースの命名</a></li> |
603 <li><a href="#Xv6" title="Xv6">Xv6</a></li> | 512 <li><a href="#インターフェースの-Code-Gear" title="インターフェースの Code Gear">インターフェースの Code Gear</a></li> |
604 <li><a href="#カーネル空間" title="カーネル空間">カーネル空間</a></li> | |
605 <li><a href="#カーネルが提供するもの" title="カーネルが提供するもの">カーネルが提供するもの</a></li> | |
606 <li><a href="#カーネルの保護機構" title="カーネルの保護機構">カーネルの保護機構</a></li> | |
607 <li><a href="#system-call" title="system call">system call</a></li> | |
608 <li><a href="#system-call1" title="system call">system call</a></li> | |
609 <li><a href="#Xv6-rpi" title="Xv6-rpi">Xv6-rpi</a></li> | |
610 <li><a href="#目次3" title="目次">目次</a></li> | |
611 <li><a href="#CbCXv6-での-Paging" title="CbCXv6 での Paging">CbCXv6 での Paging</a></li> | |
612 <li><a href="#実メモリの直接操作" title="実メモリの直接操作">実メモリの直接操作</a></li> | |
613 <li><a href="#Paging" title="Paging">Paging</a></li> | |
614 <li><a href="#Pagingの図" title="Pagingの図">Pagingの図</a></li> | |
615 <li><a href="#メタレベルでの-Paging-の操作" title="メタレベルでの Paging の操作">メタレベルでの Paging の操作</a></li> | |
616 <li><a href="#Paging-の信頼性" title="Paging の信頼性">Paging の信頼性</a></li> | |
617 <li><a href="#Paging-の書き換え" title="Paging の書き換え">Paging の書き換え</a></li> | |
618 <li><a href="#目次4" title="目次">目次</a></li> | |
619 <li><a href="#CbC-インターフェースの導入" title="CbC インターフェースの導入">CbC インターフェースの導入</a></li> | |
620 <li><a href="#CbC-インターフェース" title="CbC インターフェース">CbC インターフェース</a></li> | |
621 <li><a href="#インターフェースの定義" title="インターフェースの定義">インターフェースの定義</a></li> | |
622 <li><a href="#インターフェースのソースコード" title="インターフェースのソースコード">インターフェースのソースコード</a></li> | |
623 <li><a href="#実装名の定義" title="実装名の定義">実装名の定義</a></li> | |
624 <li><a href="#Data-Gear-の定義" title="Data Gear の定義">Data Gear の定義</a></li> | |
625 <li><a href="#Code-Gear-の定義" title="Code Gear の定義">Code Gear の定義</a></li> | |
626 <li><a href="#next…" title="next(…)">next(…)</a></li> | 513 <li><a href="#next…" title="next(…)">next(…)</a></li> |
514 <li><a href="#Interface-の実装の型" title="Interface の実装の型">Interface の実装の型</a></li> | |
627 <li><a href="#インターフェースの実装" title="インターフェースの実装">インターフェースの実装</a></li> | 515 <li><a href="#インターフェースの実装" title="インターフェースの実装">インターフェースの実装</a></li> |
628 <li><a href="#create_impl" title="create_impl">create_impl</a></li> | 516 <li><a href="#vm_impl-のコンストラクタ" title="vm_impl のコンストラクタ">vm_impl のコンストラクタ</a></li> |
629 <li><a href="#private" title="private">private</a></li> | 517 <li class=""><a href="#インターフェース実装内の-CbC" title="インターフェース実装内の CbC">インターフェース実装内の CbC</a></li> |
630 <li><a href="#goto-private" title="goto private">goto private</a></li> | 518 <li><a href="#実装内の明示的な遷移の処理" title="実装内の明示的な遷移の処理">実装内の明示的な遷移の処理</a></li> |
631 <li><a href="#private-のヘッダー" title="private のヘッダー">private のヘッダー</a></li> | 519 <li><a href="#loaduvmの-CbCによる書き換え" title="loaduvmの CbCによる書き換え">loaduvmの CbCによる書き換え</a></li> |
632 <li class=""><a href="#private-の記述" title="private の記述">private の記述</a></li> | 520 <li><a href="#stub" title="stub">stub</a></li> |
633 <li class=""><a href="#インターフェースの呼び出し" title="インターフェースの呼び出し">インターフェースの呼び出し</a></li> | 521 <li><a href="#C-を-CbC-に部分的に書き直す手法" title="C を CbC に部分的に書き直す手法">C を CbC に部分的に書き直す手法</a></li> |
634 <li class=""><a href="#呼び出しの解決" title="呼び出しの解決">呼び出しの解決</a></li> | 522 <li><a href="#CbC-から-C-への遷移" title="CbC から C への遷移">CbC から C への遷移</a></li> |
523 <li><a href="#まとめ" title="まとめ">まとめ</a></li> | |
635 </ul> | 524 </ul> |
636 </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div> | 525 </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div> |
637 </ul> | 526 </ul> |
638 </div> | 527 </div> |
639 </div> | 528 </div> |
640 <div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:17px;display:none;" null null> | 529 <div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:17px;display:none;" null null> |
641 <div class="toc"><ul class="nav"> | 530 <div class="toc"><ul class="nav"> |
642 <li class=""><a href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる CbCXv6 の書き換え">CbCインターフェースによる CbCXv6 の書き換え</a></li> | 531 <li class=""><a href="#CbCインターフェースによる-CbCXv6-の書き換え" title="CbCインターフェースによる CbCXv6 の書き換え">CbCインターフェースによる CbCXv6 の書き換え</a></li> |
643 <li><a href="#目次" title="目次">目次</a></li> | 532 <li class=""><a href="#概要" title="概要">概要</a></li> |
644 <li><a href="#OS-の信頼性の重要性" title="OS の信頼性の重要性">OS の信頼性の重要性</a></li> | 533 <li class=""><a href="#OS-の信頼性を上げたい" title="OS の信頼性を上げたい">OS の信頼性を上げたい</a></li> |
645 <li><a href="#OS-の信頼性の重要性1" title="OS の信頼性の重要性">OS の信頼性の重要性</a></li> | 534 <li class=""><a href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル">メタレベルとノーマルレベル</a></li> |
646 <li><a href="#メタレベルとノーマルレベル" title="メタレベルとノーマルレベル">メタレベルとノーマルレベル</a></li> | 535 <li class=""><a href="#Continuation-based-C" title="Continuation based C">Continuation based C</a></li> |
647 <li><a href="#Continuation-based-C" title="Continuation based C">Continuation based C</a></li> | 536 <li class=""><a href="#goto-による継続" title="goto による継続">goto による継続</a></li> |
648 <li><a href="#goto-による継続" title="goto による継続">goto による継続</a></li> | 537 <li class=""><a href="#Data-Gear-の継続" title="Data Gear の継続">Data Gear の継続</a></li> |
649 <li><a href="#Data-Gear-の継続" title="Data Gear の継続">Data Gear の継続</a></li> | 538 <li class=""><a href="#Meta-Code-Gear" title="Meta Code Gear">Meta Code Gear</a></li> |
650 <li><a href="#Meta-Code-Gear" title="Meta Code Gear">Meta Code Gear</a></li> | 539 <li class=""><a href="#Meta-Data-Gear" title="Meta Data Gear">Meta Data Gear</a></li> |
651 <li><a href="#状態遷移モデル" title="状態遷移モデル">状態遷移モデル</a></li> | 540 <li class=""><a href="#Xv6" title="Xv6">Xv6</a></li> |
652 <li><a href="#Agda-による検証" title="Agda による検証">Agda による検証</a></li> | 541 <li class=""><a href="#Xv6の構成" title="Xv6の構成">Xv6の構成</a></li> |
653 <li><a href="#Haure-Logic" title="Haure Logic">Haure Logic</a></li> | 542 <li class=""><a href="#カーネル空間" title="カーネル空間">カーネル空間</a></li> |
654 <li><a href="#Geas-OS" title="Geas OS">Geas OS</a></li> | 543 <li class=""><a href="#system-call" title="system call">system call</a></li> |
655 <li><a href="#メモリ管理" title="メモリ管理">メモリ管理</a></li> | 544 <li class=""><a href="#Paging" title="Paging">Paging</a></li> |
656 <li><a href="#インターフェース" title="インターフェース">インターフェース</a></li> | 545 <li class=""><a href="#Xv6の書き換え方針" title="Xv6の書き換え方針">Xv6の書き換え方針</a></li> |
657 <li><a href="#目次1" title="目次">目次</a></li> | 546 <li class=""><a href="#CbCインターフェース0" title="CbCインターフェース">CbCインターフェース</a></li> |
658 <li><a href="#CbC-による-Gears-OS-の開発" title="CbC による Gears OS の開発">CbC による Gears OS の開発</a></li> | 547 <li class=""><a href="#CbCインターフェース" title="CbCインターフェース">CbCインターフェース</a></li> |
659 <li><a href="#Context" title="Context">Context</a></li> | 548 <li class=""><a href="#インターフェースの定義0" title="インターフェースの定義">インターフェースの定義</a></li> |
660 <li><a href="#目次2" title="目次">目次</a></li> | 549 <li><a href="#インターフェースの命名" title="インターフェースの命名">インターフェースの命名</a></li> |
661 <li><a href="#Xv6" title="Xv6">Xv6</a></li> | 550 <li><a href="#インターフェースの-Code-Gear" title="インターフェースの Code Gear">インターフェースの Code Gear</a></li> |
662 <li><a href="#カーネル空間" title="カーネル空間">カーネル空間</a></li> | |
663 <li><a href="#カーネルが提供するもの" title="カーネルが提供するもの">カーネルが提供するもの</a></li> | |
664 <li><a href="#カーネルの保護機構" title="カーネルの保護機構">カーネルの保護機構</a></li> | |
665 <li><a href="#system-call" title="system call">system call</a></li> | |
666 <li><a href="#system-call1" title="system call">system call</a></li> | |
667 <li><a href="#Xv6-rpi" title="Xv6-rpi">Xv6-rpi</a></li> | |
668 <li><a href="#目次3" title="目次">目次</a></li> | |
669 <li><a href="#CbCXv6-での-Paging" title="CbCXv6 での Paging">CbCXv6 での Paging</a></li> | |
670 <li><a href="#実メモリの直接操作" title="実メモリの直接操作">実メモリの直接操作</a></li> | |
671 <li><a href="#Paging" title="Paging">Paging</a></li> | |
672 <li><a href="#Pagingの図" title="Pagingの図">Pagingの図</a></li> | |
673 <li><a href="#メタレベルでの-Paging-の操作" title="メタレベルでの Paging の操作">メタレベルでの Paging の操作</a></li> | |
674 <li><a href="#Paging-の信頼性" title="Paging の信頼性">Paging の信頼性</a></li> | |
675 <li><a href="#Paging-の書き換え" title="Paging の書き換え">Paging の書き換え</a></li> | |
676 <li><a href="#目次4" title="目次">目次</a></li> | |
677 <li><a href="#CbC-インターフェースの導入" title="CbC インターフェースの導入">CbC インターフェースの導入</a></li> | |
678 <li><a href="#CbC-インターフェース" title="CbC インターフェース">CbC インターフェース</a></li> | |
679 <li><a href="#インターフェースの定義" title="インターフェースの定義">インターフェースの定義</a></li> | |
680 <li><a href="#インターフェースのソースコード" title="インターフェースのソースコード">インターフェースのソースコード</a></li> | |
681 <li><a href="#実装名の定義" title="実装名の定義">実装名の定義</a></li> | |
682 <li><a href="#Data-Gear-の定義" title="Data Gear の定義">Data Gear の定義</a></li> | |
683 <li><a href="#Code-Gear-の定義" title="Code Gear の定義">Code Gear の定義</a></li> | |
684 <li><a href="#next…" title="next(…)">next(…)</a></li> | 551 <li><a href="#next…" title="next(…)">next(…)</a></li> |
552 <li><a href="#Interface-の実装の型" title="Interface の実装の型">Interface の実装の型</a></li> | |
685 <li><a href="#インターフェースの実装" title="インターフェースの実装">インターフェースの実装</a></li> | 553 <li><a href="#インターフェースの実装" title="インターフェースの実装">インターフェースの実装</a></li> |
686 <li><a href="#create_impl" title="create_impl">create_impl</a></li> | 554 <li><a href="#vm_impl-のコンストラクタ" title="vm_impl のコンストラクタ">vm_impl のコンストラクタ</a></li> |
687 <li><a href="#private" title="private">private</a></li> | 555 <li class=""><a href="#インターフェース実装内の-CbC" title="インターフェース実装内の CbC">インターフェース実装内の CbC</a></li> |
688 <li><a href="#goto-private" title="goto private">goto private</a></li> | 556 <li><a href="#実装内の明示的な遷移の処理" title="実装内の明示的な遷移の処理">実装内の明示的な遷移の処理</a></li> |
689 <li><a href="#private-のヘッダー" title="private のヘッダー">private のヘッダー</a></li> | 557 <li><a href="#loaduvmの-CbCによる書き換え" title="loaduvmの CbCによる書き換え">loaduvmの CbCによる書き換え</a></li> |
690 <li class=""><a href="#private-の記述" title="private の記述">private の記述</a></li> | 558 <li><a href="#stub" title="stub">stub</a></li> |
691 <li class=""><a href="#インターフェースの呼び出し" title="インターフェースの呼び出し">インターフェースの呼び出し</a></li> | 559 <li><a href="#C-を-CbC-に部分的に書き直す手法" title="C を CbC に部分的に書き直す手法">C を CbC に部分的に書き直す手法</a></li> |
692 <li class=""><a href="#呼び出しの解決" title="呼び出しの解決">呼び出しの解決</a></li> | 560 <li><a href="#CbC-から-C-への遷移" title="CbC から C への遷移">CbC から C への遷移</a></li> |
561 <li><a href="#まとめ" title="まとめ">まとめ</a></li> | |
693 </ul> | 562 </ul> |
694 </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div> | 563 </div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div> |
695 </div> | 564 </div> |
696 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> | 565 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> |
697 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous" defer></script> | 566 <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous" defer></script> |