mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Compare commits
15 Commits
7b6331cf18
...
80c38bf018
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
80c38bf018 | ||
|
|
b797cc805f | ||
|
|
63cd95b612 | ||
|
|
28753d6a18 | ||
|
|
68698fde20 | ||
|
|
3bb6671dd9 | ||
|
|
a16900efe4 | ||
|
|
55b5cbaba3 | ||
|
|
e0ab3f257d | ||
|
|
4d3b246ef6 | ||
|
|
e037dcfdae | ||
|
|
c87cff0cdd | ||
|
|
5c3adee95b | ||
|
|
fc8c87bee5 | ||
|
|
e1c58bba97 |
@@ -211,7 +211,7 @@ Our target specification file now looks like this:
|
||||
```
|
||||
|
||||
### Building our Kernel
|
||||
Compiling for our new target will use Linux conventions (I'm not quite sure why; I assume it's just LLVM's default). This means that we need an entry point named `_start` as described in the [previous post]:
|
||||
Compiling for our new target will use Linux conventions, since the ld.lld linker-flavor instructs llvm to compile with the `-flavor gnu` flag (for more linker options, see [the rustc documentation](https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor)). This means that we need an entry point named `_start` as described in the [previous post]:
|
||||
|
||||
[previous post]: @/edition-2/posts/01-freestanding-rust-binary/index.md
|
||||
|
||||
|
||||
@@ -656,7 +656,7 @@ Now we can use `println` in our `_start` function:
|
||||
// in src/main.rs
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() {
|
||||
pub extern "C" fn _start() -> ! {
|
||||
println!("Hello World{}", "!");
|
||||
|
||||
loop {}
|
||||
|
||||
@@ -91,7 +91,7 @@ When we run `cargo test` now, we see that it now succeeds (if it doesn't, see th
|
||||
|
||||
<div class = "warning">
|
||||
|
||||
**Note:** There is currently a bug in cargo that leads to "duplicate lang item" errors on `cargo test` in some cases. It occurs when you have set `panic = "abort"` for a profile in your `Cargo.toml`. Try removing it, then `cargo test` should work. Alternatively, if that doesn't work, then add `panic-abort-tests = true` to the `[unstable]` section of your `.config/cargo.toml` file. See the [cargo issue](https://github.com/rust-lang/cargo/issues/7359) for more information on this.
|
||||
**Note:** There is currently a bug in cargo that leads to "duplicate lang item" errors on `cargo test` in some cases. It occurs when you have set `panic = "abort"` for a profile in your `Cargo.toml`. Try removing it, then `cargo test` should work. Alternatively, if that doesn't work, then add `panic-abort-tests = true` to the `[unstable]` section of your `.cargo/config.toml` file. See the [cargo issue](https://github.com/rust-lang/cargo/issues/7359) for more information on this.
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ The `bootloader` crate defines a [`BootInfo`] struct that contains all the infor
|
||||
|
||||
- The `memory_map` field contains an overview of the available physical memory. This tells our kernel how much physical memory is available in the system and which memory regions are reserved for devices such as the VGA hardware. The memory map can be queried from the BIOS or UEFI firmware, but only very early in the boot process. For this reason, it must be provided by the bootloader because there is no way for the kernel to retrieve it later. We will need the memory map later in this post.
|
||||
- The `physical_memory_offset` tells us the virtual start address of the physical memory mapping. By adding this offset to a physical address, we get the corresponding virtual address. This allows us to access arbitrary physical memory from our kernel.
|
||||
- This physical memory offset can be customized by adding a `[package.metadata.bootloader]` table in Cargo.toml and setting the field `physical-memory-offset = "0x0000f00000000000"` (or any other value). However, note that the bootloader can panic if it runs into physical address values that start to overlap with the the space beyond the offset, i.e., areas it would have previously mapped to some other early physical addresses. So in general, the higher the value (> 1 TiB), the better.
|
||||
- This physical memory offset can be customized by adding a `[package.metadata.bootloader]` table in Cargo.toml and setting the field `physical-memory-offset = "0x0000f00000000000"` (or any other value). However, note that the bootloader can panic if it runs into physical address values that start to overlap with the space beyond the offset, i.e., areas it would have previously mapped to some other early physical addresses. So in general, the higher the value (> 1 TiB), the better.
|
||||
|
||||
The bootloader passes the `BootInfo` struct to our kernel in the form of a `&'static BootInfo` argument to our `_start` function. We don't have this argument declared in our function yet, so let's add it:
|
||||
|
||||
|
||||
BIN
scripts/cover.png
Normal file
BIN
scripts/cover.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
30
scripts/create-book.sh
Executable file
30
scripts/create-book.sh
Executable file
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# create working dir
|
||||
rm -r book/
|
||||
mkdir book/
|
||||
|
||||
# copy data to working dir
|
||||
cat ../blog/content/edition-2/posts/*/index.md > book/book.md
|
||||
find ../blog/content/edition-2/posts ! -name "*.md" -exec cp -t book/ {} +
|
||||
|
||||
# remove zola metadata
|
||||
sed -i '/^+++/,/^+++/d' book/book.md
|
||||
# remove br in table in 06, pandoc handles the layout
|
||||
sed -i '/<br>/d' book/book.md
|
||||
# details/summary breaks epub layout
|
||||
sed -i '/^<details>/d' book/book.md
|
||||
sed -i '/^<\/details>/d' book/book.md
|
||||
sed -i '/^<summary>/d' book/book.md
|
||||
|
||||
# special fix for linking to different folder
|
||||
sed -i 's|../paging-introduction/||g' book/book.md
|
||||
|
||||
# go to work dir and create epub
|
||||
cd book/
|
||||
pandoc book.md -o "Writing an OS in Rust.epub" --metadata cover-image="../cover.png" --metadata title="Writing an OS in Rust" --metadata author="Philipp Oppermann" --metadata description="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."
|
||||
|
||||
#clean up
|
||||
cd ..
|
||||
mv "book/Writing an OS in Rust.epub" .
|
||||
rm -rf book/
|
||||
Reference in New Issue
Block a user