for Page {
#### Allocating a Double Fault Stack
Now we can allocate a new double fault stack by passing the memory controller to our `interrupts::init` function:
-{{< highlight rust "hl_lines=8 11 12 21 22 23" >}}
+```rust
// in src/lib.rs
#[no_mangle]
@@ -427,7 +428,7 @@ pub fn init(memory_controller: &mut MemoryController) {
IDT.load();
}
-{{< / highlight >}}
+```
We allocate a 4096 bytes stack (one page) for our double fault handler. Now we just need some way to tell the CPU that it should use this stack for handling double faults.
@@ -468,7 +469,7 @@ use x86_64::structures::tss::TaskStateSegment;
Let's create a new TSS in our `interrupts::init` function:
-{{< highlight rust "hl_lines=3 9 10" >}}
+```rust
// in src/interrupts.rs
use x86_64::VirtualAddress;
@@ -485,7 +486,7 @@ pub fn init(memory_controller: &mut MemoryController) {
IDT.load();
}
-{{< / highlight >}}
+```
We define that the 0th IST entry is the double fault stack (any other IST index would work too). We create a new TSS through the `TaskStateSegment::new` function and load the top address (stacks grow downwards) of the double fault stack into the 0th entry.
@@ -502,7 +503,7 @@ The Global Descriptor Table (GDT) is a relict that was used for [memory segmenta
We already created a GDT [when switching to long mode]. Back then, we used assembly to create valid code and data segment descriptors, which were required to enter 64-bit mode. We could just edit that assembly file and add an additional TSS descriptor. However, we now have the expressiveness of Rust, so let's do it in Rust instead.
-[when switching to long mode]: {{% relref "02-entering-longmode.md#the-global-descriptor-table" %}}
+[when switching to long mode]: ./posts/02-entering-longmode/index.md#the-global-descriptor-table
We start by creating a new `interrupts::gdt` submodule. For that we need to rename the `src/interrupts.rs` file to `src/interrupts/mod.rs`. Then we can create a new submodule:
@@ -735,7 +736,7 @@ We now have a double fault stack and are able to create and load a TSS (which co
We already created a new TSS in our `interrupts::init` function. Now we can load this TSS by creating a new GDT:
-{{< highlight rust "hl_lines=10 11 12 13" >}}
+```rust
// in src/interrupts/mod.rs
pub fn init(memory_controller: &mut MemoryController) {
@@ -753,7 +754,7 @@ pub fn init(memory_controller: &mut MemoryController) {
IDT.load();
}
-{{< / highlight >}}
+```
However, when we try to compile it, the following errors occur:
@@ -812,7 +813,7 @@ The `Once` type allows us to initialize a `static` at runtime. It is safe becaus
So let's rewrite our `interrupts::init` function to use the static `TSS` and `GDT`:
-{{< highlight rust "hl_lines=5 9 10 12 17 18" >}}
+```rust
pub fn init(memory_controller: &mut MemoryController) {
let double_fault_stack = memory_controller.alloc_stack(1)
.expect("could not allocate double fault stack");
@@ -835,7 +836,7 @@ pub fn init(memory_controller: &mut MemoryController) {
IDT.load();
}
-{{< / highlight >}}
+```
Now it should compile again!
@@ -848,7 +849,7 @@ We're almost done. We successfully loaded our new GDT, which contains a TSS desc
For the first two steps, we need access to the `code_selector` and `tss_selector` variables outside of the closure. We can achieve this by moving the `let` declarations out of the closure:
-{{< highlight rust "hl_lines=3 4 5 8 9 12 13 20 22" >}}
+```rust
// in src/interrupts/mod.rs
pub fn init(memory_controller: &mut MemoryController) {
use x86_64::structures::gdt::SegmentSelector;
@@ -875,7 +876,7 @@ pub fn init(memory_controller: &mut MemoryController) {
IDT.load();
}
-{{< / highlight >}}
+```
We first set the descriptors to `empty` and then update them from inside the closure (which implicitly borrows them as `&mut`). Now we're able to reload the code segment register using [`set_cs`] and to load the TSS using [`load_tss`].
@@ -884,7 +885,7 @@ We first set the descriptors to `empty` and then update them from inside the clo
Now that we loaded a valid TSS and interrupt stack table, we can set the stack index for our double fault handler in the IDT:
-{{< highlight rust "hl_lines=7 9" >}}
+```rust
// in src/interrupt/mod.rs
lazy_static! {
@@ -898,13 +899,13 @@ lazy_static! {
...
};
}
-{{< / highlight >}}
+```
The `set_stack_index` method is unsafe because the the caller must ensure that the used index is valid and not already used for another exception.
That's it! Now the CPU should switch to the double fault stack whenever a double fault occurs. Thus, we are able to catch _all_ double faults, including kernel stack overflows:
-
+
From now on we should never see a triple fault again!
diff --git a/blog/static/images/qemu-catch-double-fault.png b/blog/content/posts/10-double-faults/qemu-catch-double-fault.png
similarity index 100%
rename from blog/static/images/qemu-catch-double-fault.png
rename to blog/content/posts/10-double-faults/qemu-catch-double-fault.png
diff --git a/blog/static/images/qemu-double-fault-on-stack-overflow.png b/blog/content/posts/10-double-faults/qemu-double-fault-on-stack-overflow.png
similarity index 100%
rename from blog/static/images/qemu-double-fault-on-stack-overflow.png
rename to blog/content/posts/10-double-faults/qemu-double-fault-on-stack-overflow.png
diff --git a/blog/content/posts/_index.md b/blog/content/posts/_index.md
new file mode 100644
index 00000000..67040f85
--- /dev/null
+++ b/blog/content/posts/_index.md
@@ -0,0 +1,6 @@
++++
+title = "Posts"
+sort_by = "order"
+insert_anchor = "left"
+render = false
++++
diff --git a/blog/layouts/404.html b/blog/layouts/404.html
deleted file mode 100644
index 518eb4f0..00000000
--- a/blog/layouts/404.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{{ partial "header.html" . }}
-
-Page not found
-
- Sorry, we've misplaced that URL or it's pointing to something that doesn't exist.
- Head back home to try finding it again.
-
-
-If you followed a link on this site, please report it !
-
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/_default/link.html b/blog/layouts/_default/link.html
deleted file mode 100644
index 82ced2f4..00000000
--- a/blog/layouts/_default/link.html
+++ /dev/null
@@ -1 +0,0 @@
-{{ .Title }}
diff --git a/blog/layouts/_default/section.html b/blog/layouts/_default/section.html
deleted file mode 100644
index 518eb4f0..00000000
--- a/blog/layouts/_default/section.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{{ partial "header.html" . }}
-
-
Page not found
-
- Sorry, we've misplaced that URL or it's pointing to something that doesn't exist.
- Head back home to try finding it again.
-
-
-If you followed a link on this site, please report it !
-
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/additional-resource/single.html b/blog/layouts/additional-resource/single.html
deleted file mode 100644
index 83278b21..00000000
--- a/blog/layouts/additional-resource/single.html
+++ /dev/null
@@ -1,11 +0,0 @@
-{{ partial "header.html" . }}
-
-
- {{ .Title }}
-
- {{ .Content }}
-
-
-{{ partial "disqus.html" . }}
-{{ partial "anchorjs.html" . }}
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/index.html b/blog/layouts/index.html
deleted file mode 100644
index 9d86a39b..00000000
--- a/blog/layouts/index.html
+++ /dev/null
@@ -1,56 +0,0 @@
-{{ partial "header.html" . }}
-
-
- This blog series creates a small operating system in the
- Rust programming language . Each post
- is a small tutorial and includes all needed code, so you can follow along if
- you like. The source code is also available in the corresponding
- Github repository .
-
-
Latest post: {{ range first 1 (where .Site.Pages "Section" "post") }}
- {{ .Title }}
- {{ end }}
-
-
-Bare Bones
-
- {{ range first 4 (where .Site.Pages.ByDate "Section" "post") }}
- {{ .Render "teaser" }}
- {{ end }}
-
-
-Memory Management
-
- {{ range first 4 (after 4 (where .Site.Pages.ByDate "Section" "post")) }}
- {{ .Render "teaser" }}
- {{ end }}
-
-
-Exceptions
-
- {{ range first 1 (after 9 (where .Site.Pages.ByDate "Section" "post")) }}
- {{ .Render "teaser" }}
- {{ end }}
- {{ range first 1 (after 8 (where .Site.Pages.ByDate "Section" "post")) }}
- {{ .Render "teaser" }}
- {{ end }}
-
-
-
-Additional Resources
-
-
- {{ range (where .Site.Pages.ByDate "Section" "additional-resource") }}
- {{ .Render "link" }}
- {{ end }}
-
-
-
-
- Recent Updates
- {{ partial "recent-updates.html" . }}
-
-
-
-
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/old-posts/single.html b/blog/layouts/old-posts/single.html
deleted file mode 100644
index d8e2c7a8..00000000
--- a/blog/layouts/old-posts/single.html
+++ /dev/null
@@ -1,28 +0,0 @@
-{{ partial "header.html" . }}
-
-
- {{ .Title }}
-
- {{ .Date.Format .Site.Params.date_format }}
- {{ if isset .Params "updated" }}
- (updated on {{ .Params.updated | dateFormat .Site.Params.date_format }})
- {{ end }}
-
-
- {{ .Content }}
-
-
-
-
- {{ if .PrevInSection }}
-
« {{ .PrevInSection.Title }}
- {{ end }}
- {{ if .NextInSection }}
-
{{ .NextInSection.Title }} »
- {{ end }}
-
-
-
-{{ partial "disqus.html" . }}
-{{ partial "anchorjs.html" . }}
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/old-posts/teaser.html b/blog/layouts/old-posts/teaser.html
deleted file mode 100644
index 795e27ad..00000000
--- a/blog/layouts/old-posts/teaser.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
- {{ .Summary }}
-
-
diff --git a/blog/layouts/page/single.html b/blog/layouts/page/single.html
deleted file mode 100644
index a091108c..00000000
--- a/blog/layouts/page/single.html
+++ /dev/null
@@ -1,10 +0,0 @@
-{{ partial "header.html" . }}
-
-
- {{ .Title }}
-
- {{ .Content }}
-
-
-{{ partial "anchorjs.html" . }}
-{{ partial "footer.html" . }}
diff --git a/blog/layouts/partials/analytics.html b/blog/layouts/partials/analytics.html
deleted file mode 100644
index c226e17a..00000000
--- a/blog/layouts/partials/analytics.html
+++ /dev/null
@@ -1,10 +0,0 @@
-
diff --git a/blog/layouts/partials/anchorjs.html b/blog/layouts/partials/anchorjs.html
deleted file mode 100644
index fb6093e3..00000000
--- a/blog/layouts/partials/anchorjs.html
+++ /dev/null
@@ -1,6 +0,0 @@
-
diff --git a/blog/layouts/partials/disqus.html b/blog/layouts/partials/disqus.html
deleted file mode 100644
index 6973517f..00000000
--- a/blog/layouts/partials/disqus.html
+++ /dev/null
@@ -1,17 +0,0 @@
-
-
-Please enable JavaScript to view the comments powered by Disqus.
diff --git a/blog/layouts/partials/footer.html b/blog/layouts/partials/footer.html
deleted file mode 100644
index 35a5819f..00000000
--- a/blog/layouts/partials/footer.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-