Skip to content

Commit

Permalink
deploy: 3dc5ce9
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfcyx committed Oct 19, 2024
1 parent b0cb7dd commit fdff7d0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions _sources/chapter4/6multitasking-based-on-as.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
可以看到,我们最先进行了全局动态内存分配器的初始化,因为接下来马上就要用到 Rust 的堆数据结构。接下来我们初始化物理页帧管理器(内含堆数据结构 ``Vec<T>`` )使能可用物理页帧的分配和回收能力。最后我们创建内核地址空间并让 CPU 开启分页模式, MMU 在地址转换的时候使用内核的多级页表,这一切均在一行之内做到:

- 首先,我们引用 ``KERNEL_SPACE`` ,这是它第一次被使用,就在此时它会被初始化,调用 ``MemorySet::new_kernel`` 创建一个内核地址空间并使用 ``Arc<Mutex<T>>`` 包裹起来;
- 首先,我们引用 ``KERNEL_SPACE`` ,这是它第一次被使用,就在此时它会被初始化,调用 ``MemorySet::new_kernel`` 创建一个内核地址空间并使用 ``Arc<UPSafeCell<T>>`` 包裹起来;
- 接着使用 ``.exclusive_access()`` 获取一个可变引用 ``&mut MemorySet`` 。需要注意的是这里发生了两次隐式类型转换:

1. 我们知道 ``exclusive_access`` 是 ``UPSafeCell<T>`` 的方法而不是 ``Arc<T>`` 的方法,由于 ``Arc<T>`` 实现了 ``Deref`` Trait ,当 ``exclusive_access`` 需要一个 ``&UPSafeCell<T>`` 类型的参数的时候,编译器会自动将传入的 ``Arc<UPSafeCell<T>>`` 转换为 ``&UPSafeCell<T>`` 这样就实现了类型匹配;
Expand All @@ -83,7 +83,7 @@
let satp = self.page_table.token();
unsafe {
satp::write(satp);
asm!("sfence.vma" :::: "volatile");
asm!("sfence.vma");
}
}
}
Expand Down Expand Up @@ -119,7 +119,7 @@
// os/src/mm/memory_set.rs
pub fn remap_test() {
let mut kernel_space = KERNEL_SPACE.lock();
let mut kernel_space = KERNEL_SPACE.exclusive_access();
let mid_text: VirtAddr = ((stext as usize + etext as usize) / 2).into();
let mid_rodata: VirtAddr = ((srodata as usize + erodata as usize) / 2).into();
let mid_data: VirtAddr = ((sdata as usize + edata as usize) / 2).into();
Expand Down
6 changes: 3 additions & 3 deletions chapter4/6multitasking-based-on-as.html
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ <h3>创建内核地址空间<a class="headerlink" href="#id5" title="永久链
</div>
<p>可以看到,我们最先进行了全局动态内存分配器的初始化,因为接下来马上就要用到 Rust 的堆数据结构。接下来我们初始化物理页帧管理器(内含堆数据结构 <code class="docutils literal notranslate"><span class="pre">Vec&lt;T&gt;</span></code> )使能可用物理页帧的分配和回收能力。最后我们创建内核地址空间并让 CPU 开启分页模式, MMU 在地址转换的时候使用内核的多级页表,这一切均在一行之内做到:</p>
<ul>
<li><p>首先,我们引用 <code class="docutils literal notranslate"><span class="pre">KERNEL_SPACE</span></code> ,这是它第一次被使用,就在此时它会被初始化,调用 <code class="docutils literal notranslate"><span class="pre">MemorySet::new_kernel</span></code> 创建一个内核地址空间并使用 <code class="docutils literal notranslate"><span class="pre">Arc&lt;Mutex&lt;T&gt;&gt;</span></code> 包裹起来;</p></li>
<li><p>首先,我们引用 <code class="docutils literal notranslate"><span class="pre">KERNEL_SPACE</span></code> ,这是它第一次被使用,就在此时它会被初始化,调用 <code class="docutils literal notranslate"><span class="pre">MemorySet::new_kernel</span></code> 创建一个内核地址空间并使用 <code class="docutils literal notranslate"><span class="pre">Arc&lt;UPSafeCell&lt;T&gt;&gt;</span></code> 包裹起来;</p></li>
<li><p>接着使用 <code class="docutils literal notranslate"><span class="pre">.exclusive_access()</span></code> 获取一个可变引用 <code class="docutils literal notranslate"><span class="pre">&amp;mut</span> <span class="pre">MemorySet</span></code> 。需要注意的是这里发生了两次隐式类型转换:</p>
<ol class="arabic simple">
<li><p>我们知道 <code class="docutils literal notranslate"><span class="pre">exclusive_access</span></code><code class="docutils literal notranslate"><span class="pre">UPSafeCell&lt;T&gt;</span></code> 的方法而不是 <code class="docutils literal notranslate"><span class="pre">Arc&lt;T&gt;</span></code> 的方法,由于 <code class="docutils literal notranslate"><span class="pre">Arc&lt;T&gt;</span></code> 实现了 <code class="docutils literal notranslate"><span class="pre">Deref</span></code> Trait ,当 <code class="docutils literal notranslate"><span class="pre">exclusive_access</span></code> 需要一个 <code class="docutils literal notranslate"><span class="pre">&amp;UPSafeCell&lt;T&gt;</span></code> 类型的参数的时候,编译器会自动将传入的 <code class="docutils literal notranslate"><span class="pre">Arc&lt;UPSafeCell&lt;T&gt;&gt;</span></code> 转换为 <code class="docutils literal notranslate"><span class="pre">&amp;UPSafeCell&lt;T&gt;</span></code> 这样就实现了类型匹配;</p></li>
Expand All @@ -453,7 +453,7 @@ <h3>创建内核地址空间<a class="headerlink" href="#id5" title="永久链
<span class="linenos">11</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">satp</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">page_table</span><span class="p">.</span><span class="n">token</span><span class="p">();</span>
<span class="linenos">12</span><span class="w"> </span><span class="k">unsafe</span><span class="w"> </span><span class="p">{</span>
<span class="linenos">13</span><span class="w"> </span><span class="n">satp</span>::<span class="n">write</span><span class="p">(</span><span class="n">satp</span><span class="p">);</span>
<span class="linenos">14</span><span class="w"> </span><span class="fm">asm!</span><span class="p">(</span><span class="s">&quot;sfence.vma&quot;</span><span class="w"> </span>:::: <span class="s">&quot;volatile&quot;</span><span class="p">);</span>
<span class="linenos">14</span><span class="w"> </span><span class="fm">asm!</span><span class="p">(</span><span class="s">&quot;sfence.vma&quot;</span><span class="p">);</span>
<span class="linenos">15</span><span class="w"> </span><span class="p">}</span>
<span class="linenos">16</span><span class="w"> </span><span class="p">}</span>
<span class="linenos">17</span><span class="p">}</span>
Expand All @@ -480,7 +480,7 @@ <h3>检查内核地址空间的多级页表设置<a class="headerlink" href="#id
<div class="highlight-rust notranslate"><div class="highlight"><pre><span></span><span class="c1">// os/src/mm/memory_set.rs</span>

<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">remap_test</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">kernel_space</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">KERNEL_SPACE</span><span class="p">.</span><span class="n">lock</span><span class="p">();</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">kernel_space</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">KERNEL_SPACE</span><span class="p">.</span><span class="n">exclusive_access</span><span class="p">();</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">mid_text</span>: <span class="nc">VirtAddr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((</span><span class="n">stext</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">etext</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span><span class="p">).</span><span class="n">into</span><span class="p">();</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">mid_rodata</span>: <span class="nc">VirtAddr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((</span><span class="n">srodata</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">erodata</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span><span class="p">).</span><span class="n">into</span><span class="p">();</span>
<span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="n">mid_data</span>: <span class="nc">VirtAddr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">((</span><span class="n">sdata</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">edata</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">)</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="mi">2</span><span class="p">).</span><span class="n">into</span><span class="p">();</span>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit fdff7d0

Please sign in to comment.