mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
178 Commits
post-04-no
...
post-06-st
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3e8a3e112 | ||
|
|
c211412ce2 | ||
|
|
93d3de6feb | ||
|
|
6dcf5c61fb | ||
|
|
96683c596b | ||
|
|
651c629ffd | ||
|
|
5ac91e5e38 | ||
|
|
8d8a7e0973 | ||
|
|
ec933ab329 | ||
|
|
423b6e49cc | ||
|
|
d1cf8000a3 | ||
|
|
76483ab6bf | ||
|
|
16c499f966 | ||
|
|
9d6ba0d31e | ||
|
|
3a65487f17 | ||
|
|
590585da33 | ||
|
|
6828849bc4 | ||
|
|
a604e1fa14 | ||
|
|
29063f4531 | ||
|
|
05c3a17c49 | ||
|
|
3470636653 | ||
|
|
6979a125cf | ||
|
|
1a1ce5120f | ||
|
|
78fdba7606 | ||
|
|
215900cb39 | ||
|
|
8d6915beba | ||
|
|
df1e2c1c41 | ||
|
|
0eaaa3ff2b | ||
|
|
b851eb01a8 | ||
|
|
086304c9c4 | ||
|
|
3f8c629f28 | ||
|
|
2e27b91220 | ||
|
|
06929ee840 | ||
|
|
cb77074476 | ||
|
|
e43daca563 | ||
|
|
d0afb95b50 | ||
|
|
baa2c3b445 | ||
|
|
1b0378f87e | ||
|
|
c58570fbea | ||
|
|
b91f71784d | ||
|
|
17c3138763 | ||
|
|
6316a0e1df | ||
|
|
d85274ca2a | ||
|
|
38cfb5e324 | ||
|
|
aa084dd539 | ||
|
|
a9921e9448 | ||
|
|
0d87aa7e98 | ||
|
|
9770d481f2 | ||
|
|
6797b2b70e | ||
|
|
7baa3b0155 | ||
|
|
752a65e4da | ||
|
|
08bf4405a9 | ||
|
|
b6683d95ec | ||
|
|
9d5b5f33f1 | ||
|
|
a7710b3d5c | ||
|
|
9b4b810bd3 | ||
|
|
618d10eac8 | ||
|
|
7a45083975 | ||
|
|
2faeaa8964 | ||
|
|
01040fc643 | ||
|
|
2dfc5e838a | ||
|
|
5a68816b45 | ||
|
|
12c08d72e4 | ||
|
|
111c3e1029 | ||
|
|
70d981e179 | ||
|
|
ee3d2219ab | ||
|
|
c5a39e0902 | ||
|
|
4774893a93 | ||
|
|
3c59321b54 | ||
|
|
f5345db3e6 | ||
|
|
94622ebfd5 | ||
|
|
53f3236754 | ||
|
|
82014268da | ||
|
|
a5b6422785 | ||
|
|
b7eefae5f9 | ||
|
|
df8335f8c7 | ||
|
|
f301ae461a | ||
|
|
e0d68fee24 | ||
|
|
8f76952ff0 | ||
|
|
57b30bf346 | ||
|
|
6f623dc7b4 | ||
|
|
c6ebca363b | ||
|
|
3bbc72f92b | ||
|
|
dc1f862177 | ||
|
|
f5996c1e22 | ||
|
|
eafcd8b269 | ||
|
|
fdf0fe617b | ||
|
|
daf5ed954d | ||
|
|
4753c0e1c8 | ||
|
|
dddc314b7c | ||
|
|
23fcb9f20b | ||
|
|
5531e437c4 | ||
|
|
0cd92f9567 | ||
|
|
ffb76038bc | ||
|
|
555a76b559 | ||
|
|
802c7151e4 | ||
|
|
f42461b99b | ||
|
|
19db8f6095 | ||
|
|
3a273540f4 | ||
|
|
701823742e | ||
|
|
ea096a561a | ||
|
|
6d45ffd4d7 | ||
|
|
b533bf6596 | ||
|
|
7648993b8f | ||
|
|
17bd271573 | ||
|
|
1ed76411f7 | ||
|
|
8e5b6a3e3f | ||
|
|
be0ed3a54d | ||
|
|
b895f8c745 | ||
|
|
eee9d7b899 | ||
|
|
9787e6dce6 | ||
|
|
f5b6094521 | ||
|
|
a4f675739a | ||
|
|
b1cca8de88 | ||
|
|
38bd9a65b6 | ||
|
|
493fcb5d84 | ||
|
|
b651214f1e | ||
|
|
b3e94470e4 | ||
|
|
3fca470487 | ||
|
|
bac8703e04 | ||
|
|
7b01e9c862 | ||
|
|
290ee927e8 | ||
|
|
99171b003e | ||
|
|
5452e0f455 | ||
|
|
86b17ea139 | ||
|
|
f15bbaea3f | ||
|
|
b66b7563c2 | ||
|
|
202902f30d | ||
|
|
223ce459a1 | ||
|
|
d808cbff94 | ||
|
|
3bb30fd1e8 | ||
|
|
62e2cee989 | ||
|
|
69ab78108b | ||
|
|
41e36b4afa | ||
|
|
a7ada29c5e | ||
|
|
968620dce8 | ||
|
|
f76ec1ae32 | ||
|
|
1a801e3d35 | ||
|
|
efe92e5004 | ||
|
|
f0580e82a1 | ||
|
|
233943310c | ||
|
|
ef6d69f82b | ||
|
|
94014b5a39 | ||
|
|
680aab362e | ||
|
|
92cc34712c | ||
|
|
bdbbd219d0 | ||
|
|
637b517f47 | ||
|
|
ab8d8b46e2 | ||
|
|
3cd7427ed8 | ||
|
|
5802c97938 | ||
|
|
33f9f14391 | ||
|
|
68d09db7c5 | ||
|
|
6bbd12ba7a | ||
|
|
29ee6b15dd | ||
|
|
15b394f0eb | ||
|
|
17f2699277 | ||
|
|
90ad333e90 | ||
|
|
cc3a868863 | ||
|
|
d1545e7fbf | ||
|
|
afe8dc3dcf | ||
|
|
8bb0187f35 | ||
|
|
e0ed423e52 | ||
|
|
d8edfccca4 | ||
|
|
ff25a7d86c | ||
|
|
b5202e26a1 | ||
|
|
ea1b031fd3 | ||
|
|
db4e879c34 | ||
|
|
7fd29c9cbe | ||
|
|
218cb9399e | ||
|
|
b96636984c | ||
|
|
b9dd088dc1 | ||
|
|
c6bd48e812 | ||
|
|
9448b0e025 | ||
|
|
ade6c99885 | ||
|
|
59579108a7 | ||
|
|
bd39105793 | ||
|
|
d007aae993 | ||
|
|
c21f051300 |
5
.cargo/config
Normal file
5
.cargo/config
Normal file
@@ -0,0 +1,5 @@
|
||||
[build]
|
||||
target = "x86_64-blog_os.json"
|
||||
|
||||
[target.'cfg(target_os = "none")']
|
||||
runner = "bootimage runner"
|
||||
@@ -1,11 +0,0 @@
|
||||
[unstable]
|
||||
# build-std = ["core", "compiler_builtins"]
|
||||
|
||||
[build]
|
||||
# target = "x86_64-blog_os.json"
|
||||
|
||||
[target.'cfg(target_os = "none")']
|
||||
runner = "cargo run --manifest-path disk_image/Cargo.toml --bin runner --quiet"
|
||||
|
||||
[alias]
|
||||
bootimage = "run --manifest-path disk_image/Cargo.toml --bin disk_image --quiet"
|
||||
162
.github/workflows/build-code.yml
vendored
162
.github/workflows/build-code.yml
vendored
@@ -10,36 +10,11 @@ on:
|
||||
schedule:
|
||||
- cron: '40 3 * * *' # every day at 3:40
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [
|
||||
ubuntu-latest,
|
||||
macos-latest,
|
||||
windows-latest
|
||||
]
|
||||
runs-on: ${{ matrix.platform }}
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
- name: Install `rust-src` Rustup Component
|
||||
run: rustup component add rust-src
|
||||
- name: Run `cargo check`
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: check
|
||||
|
||||
test:
|
||||
name: Test
|
||||
name: "Test"
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
platform: [
|
||||
@@ -47,86 +22,75 @@ jobs:
|
||||
macos-latest,
|
||||
windows-latest
|
||||
]
|
||||
|
||||
runs-on: ${{ matrix.platform }}
|
||||
timeout-minutes: 15
|
||||
|
||||
steps:
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
- name: Install bootimage
|
||||
run: cargo install bootimage --debug
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rustup Components
|
||||
run: rustup component add rust-src llvm-tools-preview
|
||||
- name: Run `cargo bootimage`
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: bootimage
|
||||
- name: "Checkout Repository"
|
||||
uses: actions/checkout@v1
|
||||
|
||||
# install QEMU
|
||||
- name: Install QEMU (Linux)
|
||||
run: sudo apt update && sudo apt install qemu-system-x86
|
||||
if: runner.os == 'Linux'
|
||||
- name: Install QEMU (macOS)
|
||||
run: brew install qemu
|
||||
if: runner.os == 'macOS'
|
||||
env:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: 1
|
||||
HOMEBREW_NO_INSTALL_CLEANUP: 1
|
||||
- name: Install Scoop (Windows)
|
||||
run: |
|
||||
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
||||
echo ::add-path::$HOME\scoop\shims
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
- name: Install QEMU (Windows)
|
||||
run: scoop install qemu
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
- name: "Print QEMU Version"
|
||||
run: qemu-system-x86_64 --version
|
||||
- name: Install Rustup
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain nightly
|
||||
echo ::add-path::$HOME/.cargo/bin
|
||||
if: runner.os == 'macOS'
|
||||
|
||||
- name: Run `cargo test`
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: test
|
||||
- name: "Print Rust Version"
|
||||
run: |
|
||||
rustc -Vv
|
||||
cargo -Vv
|
||||
|
||||
- name: "Install Rustup Components"
|
||||
run: rustup component add rust-src llvm-tools-preview
|
||||
- name: "Install cargo-xbuild"
|
||||
run: cargo install cargo-xbuild --debug
|
||||
- name: "Install bootimage"
|
||||
run: cargo install bootimage --debug
|
||||
|
||||
- name: "Run cargo xbuild"
|
||||
run: cargo xbuild
|
||||
- name: "Create Bootimage"
|
||||
run: cargo bootimage
|
||||
|
||||
# install QEMU
|
||||
- name: Install QEMU (Linux)
|
||||
run: sudo apt update && sudo apt install qemu-system-x86
|
||||
if: runner.os == 'Linux'
|
||||
- name: Install QEMU (macOS)
|
||||
run: brew install qemu
|
||||
if: runner.os == 'macOS'
|
||||
env:
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
HOMEBREW_NO_BOTTLE_SOURCE_FALLBACK: 1
|
||||
HOMEBREW_NO_INSTALL_CLEANUP: 1
|
||||
- name: Install Scoop (Windows)
|
||||
run: |
|
||||
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
|
||||
echo ::add-path::$HOME\scoop\shims
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
- name: Install QEMU (Windows)
|
||||
run: scoop install qemu
|
||||
if: runner.os == 'Windows'
|
||||
shell: pwsh
|
||||
- name: "Print QEMU Version"
|
||||
run: qemu-system-x86_64 --version
|
||||
|
||||
- name: "Run cargo xtest"
|
||||
run: cargo xtest
|
||||
|
||||
check_formatting:
|
||||
name: Check Formatting
|
||||
name: "Check Formatting"
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 2
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
- uses: actions/checkout@v1
|
||||
- name: "Use the latest Rust nightly with rustfmt"
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
profile: minimal
|
||||
components: rustfmt
|
||||
override: true
|
||||
- name: Run `cargo fmt`
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: --all -- --check
|
||||
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Install Rust Toolchain
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
components: clippy, rust-src
|
||||
override: true
|
||||
- name: Run `cargo clippy`
|
||||
uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
- run: cargo fmt -- --check
|
||||
|
||||
223
Cargo.lock
generated
223
Cargo.lock
generated
@@ -1,10 +1,13 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.32"
|
||||
name = "array-init"
|
||||
version = "0.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
||||
checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72"
|
||||
dependencies = [
|
||||
"nodrop",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
@@ -24,58 +27,26 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bootloader",
|
||||
"lazy_static",
|
||||
"rlibc",
|
||||
"spin",
|
||||
"uart_16550",
|
||||
"volatile",
|
||||
"x86_64",
|
||||
"x86_64 0.8.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bootloader"
|
||||
version = "0.9.8"
|
||||
|
||||
[[package]]
|
||||
name = "bootloader-locator"
|
||||
version = "0.0.3"
|
||||
dependencies = [
|
||||
"cargo_metadata",
|
||||
"locate-cargo-manifest",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cargo_metadata"
|
||||
version = "0.11.1"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35"
|
||||
dependencies = [
|
||||
"semver",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
checksum = "d596849a47f28abdea62d7a6a25c4f6e69c3d9b09b0a2877db6e9cda004ca993"
|
||||
|
||||
[[package]]
|
||||
name = "disk_image"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bootloader-locator",
|
||||
"locate-cargo-manifest",
|
||||
"runner-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.4.6"
|
||||
name = "cast"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6"
|
||||
|
||||
[[package]]
|
||||
name = "json"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
|
||||
checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0"
|
||||
dependencies = [
|
||||
"rustc_version",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
@@ -87,67 +58,27 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.76"
|
||||
name = "nodrop"
|
||||
version = "0.1.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3"
|
||||
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
|
||||
|
||||
[[package]]
|
||||
name = "locate-cargo-manifest"
|
||||
version = "0.2.0"
|
||||
name = "rustc_version"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d264d672563b20c0a2eb9045f4072e1352002f6c316cc0677bed8b767e17b7e1"
|
||||
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||
dependencies = [
|
||||
"json",
|
||||
"thiserror",
|
||||
"semver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rlibc"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
|
||||
|
||||
[[package]]
|
||||
name = "runner-utils"
|
||||
version = "0.0.2"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.10.0"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190"
|
||||
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||
dependencies = [
|
||||
"semver-parser",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -156,111 +87,55 @@ version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.115"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e54c9a88f2da7238af84b5101443f0c0d0a3bbdc455e34a5c9497b1903ed55d5"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.115"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "609feed1d0a73cc36a0182a840a9b37b4a82f0b1150369f0536a9e3f2a31dc48"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.57"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "164eacbdb13512ec2745fb09d51fd5b22b0d65ed294a1dcf7285a360c80a675c"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.39"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7dfdd070ccd8ccb78f4ad66bf1982dc37f620ef696c6b5028fe2ed83dd3d0d08"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bd80fc12f73063ac132ac92aceea36734f04a1d93c1240c6944e23a3b8841793"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uart_16550"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e58fc40dc1712664fc9b0a7bd8ca2f21ab49960924fb245a80a05e1e92f3dfe9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"x86_64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
checksum = "803ea8cb602dbb32c1a657a866d2dd79fe7dbeab0fb2ac667cb4dcc7de12a58b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"x86_64 0.7.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ux"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88dfeb711b61ce620c0cb6fd9f8e3e678622f0c971da2a63c4b3e25e88ed012f"
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
version = "0.4.0-alpha.00"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a1da81878b88e2b57ca8b3d62c0c3e9979d9531cfe0e6d1c094174d8458eac6"
|
||||
checksum = "6af0edf5b4faacc31fc51159244d78d65ec580f021afcef7bd53c04aeabc7f29"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.0"
|
||||
name = "x86_64"
|
||||
version = "0.7.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||
checksum = "1f27d9168654aee1b0c1b73746caeb4aa33248f8b8c8f6e100e697fcc2a794b2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"array-init",
|
||||
"bit_field",
|
||||
"bitflags",
|
||||
"cast",
|
||||
"ux",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "x86_64"
|
||||
version = "0.11.0"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "365de37eb7c6da582cbb510dd0f3f1235d24ff6309a8a96e8a9909cc9bfd608f"
|
||||
checksum = "f21672dcbed52bc09eea030d189600c0189c66c97bc5b31779eb780e064a201f"
|
||||
dependencies = [
|
||||
"array-init",
|
||||
"bit_field",
|
||||
"bitflags",
|
||||
"cast",
|
||||
]
|
||||
|
||||
16
Cargo.toml
16
Cargo.toml
@@ -4,21 +4,19 @@ version = "0.1.0"
|
||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"disk_image",
|
||||
]
|
||||
|
||||
[[test]]
|
||||
name = "should_panic"
|
||||
harness = false
|
||||
|
||||
[[test]]
|
||||
name = "stack_overflow"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
bootloader = { path = "../../uefi-test"}
|
||||
rlibc = "1.0.0"
|
||||
volatile = "0.4.0-alpha"
|
||||
bootloader = "0.8.0"
|
||||
volatile = "0.2.6"
|
||||
spin = "0.5.2"
|
||||
x86_64 = "0.11.0"
|
||||
x86_64 = "0.8.1"
|
||||
uart_16550 = "0.2.0"
|
||||
|
||||
[dependencies.lazy_static]
|
||||
|
||||
26
README.md
26
README.md
@@ -1,32 +1,28 @@
|
||||
# Blog OS (Testing)
|
||||
# Blog OS (Double Faults)
|
||||
|
||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Build+Code%22+branch%3Apost-04)
|
||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Build+Code%22+branch%3Apost-06)
|
||||
|
||||
This repository contains the source code for the [Testing][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
||||
This repository contains the source code for the [Double Faults][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
||||
|
||||
[post]: https://os.phil-opp.com/testing/
|
||||
[post]: https://os.phil-opp.com/double-fault-exceptions/
|
||||
|
||||
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
||||
|
||||
## Building
|
||||
|
||||
This project requires a nightly version of Rust because it uses some unstable features. At least nightly _2020-07-15_ is required for building. You might need to run `rustup update nightly --force` to update to the latest nightly even if some components such as `rustfmt` are missing it.
|
||||
|
||||
You can build the project by running:
|
||||
You need a nightly Rust compiler. First you need to install the `cargo-xbuild` and `bootimage` tools:
|
||||
|
||||
```
|
||||
cargo build
|
||||
cargo install cargo-xbuild bootimage
|
||||
```
|
||||
|
||||
To create a bootable disk image from the compiled kernel, you need to install the [`bootimage`] tool:
|
||||
|
||||
[`bootimage`]: https://github.com/rust-osdev/bootimage
|
||||
Then you can build the project by running:
|
||||
|
||||
```
|
||||
cargo install bootimage
|
||||
cargo xbuild
|
||||
```
|
||||
|
||||
After installing, you can create the bootable disk image by running:
|
||||
To create a bootable disk image, run:
|
||||
|
||||
```
|
||||
cargo bootimage
|
||||
@@ -43,10 +39,10 @@ You can run the disk image in [QEMU] through:
|
||||
[QEMU]: https://www.qemu.org/
|
||||
|
||||
```
|
||||
cargo run
|
||||
cargo xrun
|
||||
```
|
||||
|
||||
[QEMU] and the [`bootimage`] tool need to be installed for this.
|
||||
Of course [QEMU] needs to be installed for this.
|
||||
|
||||
You can also write the image to an USB stick for booting it on a real machine. On Linux, the command for this is:
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
[package]
|
||||
name = "disk_image"
|
||||
version = "0.1.0"
|
||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.32"
|
||||
bootloader-locator = {path = "../../../bootloader-locator"}
|
||||
runner-utils = { path = "../../../runner-utils/" }
|
||||
locate-cargo-manifest = "0.2.0"
|
||||
@@ -1,57 +0,0 @@
|
||||
use anyhow::anyhow;
|
||||
use std::{
|
||||
path::PathBuf,
|
||||
process::{Command, ExitStatus},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
const RUN_ARGS: &[&str] = &["-d", "int", "--no-reboot", "-s"];
|
||||
const TEST_ARGS: &[&str] = &[
|
||||
"-device",
|
||||
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||
"-serial",
|
||||
"stdio",
|
||||
"-display",
|
||||
"none",
|
||||
"--no-reboot",
|
||||
];
|
||||
const TEST_TIMEOUT_SECS: u64 = 10;
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
let kernel_binary_path = {
|
||||
let path = PathBuf::from(std::env::args().nth(1).unwrap());
|
||||
path.canonicalize()?
|
||||
};
|
||||
|
||||
let disk_image = disk_image::create_disk_image(&kernel_binary_path, true)?;
|
||||
|
||||
let mut run_cmd = Command::new("qemu-system-x86_64");
|
||||
run_cmd
|
||||
.arg("-drive")
|
||||
.arg(format!("format=raw,file={}", disk_image.display()));
|
||||
|
||||
let binary_kind = runner_utils::binary_kind(&kernel_binary_path);
|
||||
if binary_kind.is_test() {
|
||||
run_cmd.args(TEST_ARGS);
|
||||
|
||||
let exit_status = run_test_command(run_cmd)?;
|
||||
match exit_status.code() {
|
||||
Some(33) => {} // success
|
||||
other => return Err(anyhow!("Test failed (exit code: {:?})", other)),
|
||||
}
|
||||
} else {
|
||||
run_cmd.args(RUN_ARGS);
|
||||
|
||||
let exit_status = run_cmd.status()?;
|
||||
if !exit_status.success() {
|
||||
std::process::exit(exit_status.code().unwrap_or(1));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_test_command(mut cmd: Command) -> anyhow::Result<ExitStatus> {
|
||||
let status = runner_utils::run_with_timeout(&mut cmd, Duration::from_secs(TEST_TIMEOUT_SECS))?;
|
||||
Ok(status)
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
use anyhow::anyhow;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::Result<PathBuf> {
|
||||
let bootloader_info = bootloader_locator::locate_bootloader()?;
|
||||
let kernel_manifest_path = &bootloader_info.kernel_manifest_path;
|
||||
|
||||
let mut build_cmd = Command::new(env!("CARGO"));
|
||||
build_cmd.current_dir(bootloader_info.package.manifest_path.parent().unwrap());
|
||||
build_cmd.arg("builder");
|
||||
build_cmd
|
||||
.arg("--kernel-manifest")
|
||||
.arg(&kernel_manifest_path);
|
||||
build_cmd.arg("--kernel-binary").arg(&kernel_binary_path);
|
||||
build_cmd
|
||||
.arg("--target-dir")
|
||||
.arg(kernel_manifest_path.parent().unwrap().join("target"));
|
||||
build_cmd
|
||||
.arg("--out-dir")
|
||||
.arg(kernel_binary_path.parent().unwrap());
|
||||
build_cmd.arg("--quiet");
|
||||
if bios_only {
|
||||
build_cmd.arg("--firmware").arg("bios");
|
||||
}
|
||||
|
||||
if !build_cmd.status()?.success() {
|
||||
return Err(anyhow!("build failed"));
|
||||
}
|
||||
|
||||
let kernel_binary_name = kernel_binary_path.file_name().unwrap().to_str().unwrap();
|
||||
let disk_image = kernel_binary_path
|
||||
.parent()
|
||||
.unwrap()
|
||||
.join(format!("bootimage-bios-{}.bin", kernel_binary_name));
|
||||
if !disk_image.exists() {
|
||||
return Err(anyhow!(
|
||||
"Disk image does not exist at {} after bootloader build",
|
||||
disk_image.display()
|
||||
));
|
||||
}
|
||||
Ok(disk_image)
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
use anyhow::anyhow;
|
||||
use std::process::Command;
|
||||
|
||||
const TARGET_NAME: &str = "x86_64-blog_os";
|
||||
const KERNEL_BINARIES: &[&str] = &["blog_os"];
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
// build all binaries
|
||||
let mut build_cmd = Command::new(env!("CARGO"));
|
||||
build_cmd.arg("build");
|
||||
build_cmd.arg("--release");
|
||||
build_cmd.arg("-Zbuild-std=core");
|
||||
build_cmd
|
||||
.arg("--target")
|
||||
.arg(format!("{}.json", TARGET_NAME));
|
||||
if !build_cmd.status()?.success() {
|
||||
return Err(anyhow!("build failed"));
|
||||
};
|
||||
|
||||
let kernel_manifest = locate_cargo_manifest::locate_manifest()?;
|
||||
let target_dir_root = kernel_manifest.parent().unwrap().join("target");
|
||||
let target_dir = target_dir_root.join(TARGET_NAME).join("release");
|
||||
|
||||
for binary_name in KERNEL_BINARIES {
|
||||
let binary_path = {
|
||||
let path = target_dir.join(binary_name);
|
||||
path.canonicalize()?
|
||||
};
|
||||
|
||||
let disk_image = disk_image::create_disk_image(&binary_path, false)?;
|
||||
|
||||
println!(
|
||||
"Created disk image for binary {} at {}",
|
||||
binary_name,
|
||||
disk_image.display()
|
||||
);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
56
src/gdt.rs
Normal file
56
src/gdt.rs
Normal file
@@ -0,0 +1,56 @@
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable, SegmentSelector};
|
||||
use x86_64::structures::tss::TaskStateSegment;
|
||||
use x86_64::VirtAddr;
|
||||
|
||||
pub const DOUBLE_FAULT_IST_INDEX: u16 = 0;
|
||||
|
||||
lazy_static! {
|
||||
static ref TSS: TaskStateSegment = {
|
||||
let mut tss = TaskStateSegment::new();
|
||||
tss.interrupt_stack_table[DOUBLE_FAULT_IST_INDEX as usize] = {
|
||||
const STACK_SIZE: usize = 4096;
|
||||
|
||||
#[repr(align(16))]
|
||||
struct Stack([u8; STACK_SIZE]);
|
||||
|
||||
static mut STACK: Stack = Stack([0; STACK_SIZE]);
|
||||
|
||||
let stack_start = VirtAddr::from_ptr(unsafe { &STACK });
|
||||
let stack_end = stack_start + STACK_SIZE;
|
||||
stack_end
|
||||
};
|
||||
tss
|
||||
};
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref GDT: (GlobalDescriptorTable, Selectors) = {
|
||||
let mut gdt = GlobalDescriptorTable::new();
|
||||
let code_selector = gdt.add_entry(Descriptor::kernel_code_segment());
|
||||
let tss_selector = gdt.add_entry(Descriptor::tss_segment(&TSS));
|
||||
(
|
||||
gdt,
|
||||
Selectors {
|
||||
code_selector,
|
||||
tss_selector,
|
||||
},
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
struct Selectors {
|
||||
code_selector: SegmentSelector,
|
||||
tss_selector: SegmentSelector,
|
||||
}
|
||||
|
||||
pub fn init() {
|
||||
use x86_64::instructions::segmentation::set_cs;
|
||||
use x86_64::instructions::tables::load_tss;
|
||||
|
||||
GDT.0.load();
|
||||
unsafe {
|
||||
set_cs(GDT.1.code_selector);
|
||||
load_tss(GDT.1.tss_selector);
|
||||
}
|
||||
}
|
||||
42
src/interrupts.rs
Normal file
42
src/interrupts.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use crate::{gdt, println};
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
|
||||
lazy_static! {
|
||||
static ref IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
idt.breakpoint.set_handler_fn(breakpoint_handler);
|
||||
unsafe {
|
||||
idt.double_fault
|
||||
.set_handler_fn(double_fault_handler)
|
||||
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
|
||||
}
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_idt() {
|
||||
IDT.load();
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn breakpoint_handler(stack_frame: &mut InterruptStackFrame) {
|
||||
println!("EXCEPTION: BREAKPOINT\n{:#?}", stack_frame);
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn double_fault_handler(
|
||||
stack_frame: &mut InterruptStackFrame,
|
||||
_error_code: u64,
|
||||
) -> ! {
|
||||
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::{serial_print, serial_println};
|
||||
|
||||
#[test_case]
|
||||
fn test_breakpoint_exception() {
|
||||
serial_print!("test_breakpoint_exception...");
|
||||
// invoke a breakpoint exception
|
||||
x86_64::instructions::interrupts::int3();
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
28
src/lib.rs
28
src/lib.rs
@@ -1,35 +1,26 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(test, no_main)]
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
#![test_runner(crate::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
extern crate rlibc;
|
||||
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
pub mod gdt;
|
||||
pub mod interrupts;
|
||||
pub mod serial;
|
||||
//pub mod vga_buffer;
|
||||
pub mod vga_buffer;
|
||||
|
||||
pub trait Testable {
|
||||
fn run(&self) -> ();
|
||||
pub fn init() {
|
||||
gdt::init();
|
||||
interrupts::init_idt();
|
||||
}
|
||||
|
||||
impl<T> Testable for T
|
||||
where
|
||||
T: Fn(),
|
||||
{
|
||||
fn run(&self) {
|
||||
serial_print!("{}...\t", core::any::type_name::<T>());
|
||||
self();
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn test_runner(tests: &[&dyn Testable]) {
|
||||
pub fn test_runner(tests: &[&dyn Fn()]) {
|
||||
serial_println!("Running {} tests", tests.len());
|
||||
for test in tests {
|
||||
test.run();
|
||||
test();
|
||||
}
|
||||
exit_qemu(QemuExitCode::Success);
|
||||
}
|
||||
@@ -61,6 +52,7 @@ pub fn exit_qemu(exit_code: QemuExitCode) {
|
||||
#[cfg(test)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
init();
|
||||
test_main();
|
||||
loop {}
|
||||
}
|
||||
|
||||
41
src/main.rs
41
src/main.rs
@@ -4,36 +4,34 @@
|
||||
#![test_runner(blog_os::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
use blog_os::serial_println;
|
||||
use core::{panic::PanicInfo, ptr, slice};
|
||||
use blog_os::println;
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info::BootInfo) -> ! {
|
||||
pub extern "C" fn _start() -> ! {
|
||||
println!("Hello World{}", "!");
|
||||
|
||||
blog_os::init();
|
||||
|
||||
fn stack_overflow() {
|
||||
stack_overflow(); // for each recursion, the return address is pushed
|
||||
}
|
||||
|
||||
// uncomment line below to trigger a stack overflow
|
||||
// stack_overflow();
|
||||
|
||||
#[cfg(test)]
|
||||
test_main();
|
||||
|
||||
let mut framebuffer = {
|
||||
let ptr = boot_info.framebuffer.start_addr as *mut u8;
|
||||
let slice = unsafe { slice::from_raw_parts_mut(ptr, boot_info.framebuffer.len) };
|
||||
volatile::Volatile::new(slice)
|
||||
};
|
||||
|
||||
//serial_println!("Hello World{}", "!");
|
||||
|
||||
for i in 0..boot_info.framebuffer.len {
|
||||
framebuffer.index_mut(i).write(0x99);
|
||||
}
|
||||
|
||||
loop {
|
||||
x86_64::instructions::hlt();
|
||||
}
|
||||
println!("It did not crash!");
|
||||
loop {}
|
||||
}
|
||||
|
||||
/// This function is called on panic.
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
serial_println!("{}", info);
|
||||
println!("{}", info);
|
||||
loop {}
|
||||
}
|
||||
|
||||
@@ -42,8 +40,3 @@ fn panic(info: &PanicInfo) -> ! {
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
blog_os::test_panic_handler(info)
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn trivial_assertion() {
|
||||
assert_eq!(1, 1);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@ use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use volatile::Volatile;
|
||||
|
||||
#[cfg(test)]
|
||||
use crate::{serial_print, serial_println};
|
||||
|
||||
lazy_static! {
|
||||
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
||||
///
|
||||
@@ -172,22 +175,30 @@ pub fn _print(args: fmt::Arguments) {
|
||||
|
||||
#[test_case]
|
||||
fn test_println_simple() {
|
||||
serial_print!("test_println... ");
|
||||
println!("test_println_simple output");
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_println_many() {
|
||||
serial_print!("test_println_many... ");
|
||||
for _ in 0..200 {
|
||||
println!("test_println_many output");
|
||||
}
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
|
||||
#[test_case]
|
||||
fn test_println_output() {
|
||||
serial_print!("test_println_output... ");
|
||||
|
||||
let s = "Some test string that fits on a single line";
|
||||
println!("{}", s);
|
||||
for (i, c) in s.chars().enumerate() {
|
||||
let screen_char = WRITER.lock().buffer.chars[BUFFER_HEIGHT - 2][i].read();
|
||||
assert_eq!(char::from(screen_char.ascii_character), c);
|
||||
}
|
||||
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#![test_runner(blog_os::test_runner)]
|
||||
#![reexport_test_harness_main = "test_main"]
|
||||
|
||||
use blog_os::{println, serial_print, serial_println};
|
||||
use core::panic::PanicInfo;
|
||||
|
||||
#[no_mangle] // don't mangle the name of this function
|
||||
@@ -20,5 +21,7 @@ fn panic(info: &PanicInfo) -> ! {
|
||||
|
||||
#[test_case]
|
||||
fn test_println() {
|
||||
//println!("test_println output");
|
||||
serial_print!("test_println... ");
|
||||
println!("test_println output");
|
||||
serial_println!("[ok]");
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ pub extern "C" fn _start() -> ! {
|
||||
}
|
||||
|
||||
fn should_fail() {
|
||||
serial_print!("should_panic::should_fail...\t");
|
||||
serial_print!("should_fail... ");
|
||||
assert_eq!(0, 1);
|
||||
}
|
||||
|
||||
|
||||
57
tests/stack_overflow.rs
Normal file
57
tests/stack_overflow.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
|
||||
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
|
||||
use core::panic::PanicInfo;
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
serial_print!("stack_overflow... ");
|
||||
|
||||
blog_os::gdt::init();
|
||||
init_test_idt();
|
||||
|
||||
// trigger a stack overflow
|
||||
stack_overflow();
|
||||
|
||||
panic!("Execution continued after stack overflow");
|
||||
}
|
||||
|
||||
#[allow(unconditional_recursion)]
|
||||
fn stack_overflow() {
|
||||
stack_overflow(); // for each recursion, the return address is pushed
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref TEST_IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
unsafe {
|
||||
idt.double_fault
|
||||
.set_handler_fn(test_double_fault_handler)
|
||||
.set_stack_index(blog_os::gdt::DOUBLE_FAULT_IST_INDEX);
|
||||
}
|
||||
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
pub fn init_test_idt() {
|
||||
TEST_IDT.load();
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn test_double_fault_handler(
|
||||
_stack_frame: &mut InterruptStackFrame,
|
||||
_error_code: u64,
|
||||
) -> ! {
|
||||
serial_println!("[ok]");
|
||||
exit_qemu(QemuExitCode::Success);
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
blog_os::test_panic_handler(info)
|
||||
}
|
||||
Reference in New Issue
Block a user