mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Merge pull request #122 from phil-opp/update-x86-crate
Update x86 crate to version 0.6 and disable performance counter
This commit is contained in:
@@ -9,7 +9,10 @@ crate-type = ["staticlib"]
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
rlibc = "0.1.4"
|
rlibc = "0.1.4"
|
||||||
spin = "0.3.4"
|
spin = "0.3.4"
|
||||||
x86 = "0.5.0"
|
|
||||||
|
[dependencies.x86]
|
||||||
|
version = "0.6.0"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
[dependencies.multiboot2]
|
[dependencies.multiboot2]
|
||||||
git = "https://github.com/phil-opp/multiboot2-elf64"
|
git = "https://github.com/phil-opp/multiboot2-elf64"
|
||||||
|
|||||||
@@ -882,10 +882,21 @@ An x86 processor has many different caches because always accessing the main mem
|
|||||||
|
|
||||||
The translation lookaside buffer, or TLB, caches the translation of virtual to physical addresses. It's filled automatically when a page is accessed. But it's not updated transparently when the mapping of a page changes. This is the reason that we still can access the page even through we unmapped it in the page table.
|
The translation lookaside buffer, or TLB, caches the translation of virtual to physical addresses. It's filled automatically when a page is accessed. But it's not updated transparently when the mapping of a page changes. This is the reason that we still can access the page even through we unmapped it in the page table.
|
||||||
|
|
||||||
So to fix our `unmap` function, we need to remove the cached translation from the TLB. We can use Gerd Zellweger's [x86][x86 crate] crate to do this easily. To add it, append `x86 = "0.5.0"` to the dependency section in the `Cargo.toml`. Then we can use it to fix `unmap`:
|
So to fix our `unmap` function, we need to remove the cached translation from the TLB. We can use Gerd Zellweger's [x86][x86 crate] crate to do this easily. To add it, we append the following to our `Cargo.toml`:
|
||||||
|
|
||||||
[x86 crate]: https://github.com/gz/rust-x86
|
[x86 crate]: https://github.com/gz/rust-x86
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies.x86]
|
||||||
|
version = "0.6.0"
|
||||||
|
default-features = false
|
||||||
|
```
|
||||||
|
It has a `performance-counter` feature that allows reading the CPU specific [performance counters] but increases compile times. We don't need it right now, so we disable it using `default-features = false`.
|
||||||
|
|
||||||
|
[performance counters]: http://gz.github.io/rust-x86/x86/perfcnt/index.html
|
||||||
|
|
||||||
|
Now we can use it to fix `unmap`:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
...
|
...
|
||||||
p1[page.p1_index()].set_unused();
|
p1[page.p1_index()].set_unused();
|
||||||
|
|||||||
Reference in New Issue
Block a user