mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
115 Commits
post-03
...
post-04-no
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db307d89bc | ||
|
|
fe23af5b3e | ||
|
|
a3d58588a2 | ||
|
|
edd155d570 | ||
|
|
c18cd874ca | ||
|
|
6380e069f7 | ||
|
|
7341cff39d | ||
|
|
acf3717551 | ||
|
|
e78d33a5bf | ||
|
|
6292789393 | ||
|
|
bf33685d00 | ||
|
|
3ee6badb33 | ||
|
|
9f9ff59489 | ||
|
|
a1c7931a77 | ||
|
|
2c30310281 | ||
|
|
57cd52b7f5 | ||
|
|
d7e505da9e | ||
|
|
2039cd7a64 | ||
|
|
ebb862de2a | ||
|
|
d588dca953 | ||
|
|
029d6bee78 | ||
|
|
0fc6fedd82 | ||
|
|
56cf71df9f | ||
|
|
adcb547765 | ||
|
|
faf097fd06 | ||
|
|
1636196d54 | ||
|
|
5c964dc7b9 | ||
|
|
0c3e6f95f6 | ||
|
|
23d8bb948e | ||
|
|
ea998c9267 | ||
|
|
79ad84c502 | ||
|
|
2a1f4d047c | ||
|
|
01d9a028a3 | ||
|
|
6e012e5e42 | ||
|
|
f4ed1fce81 | ||
|
|
086c3a02d3 | ||
|
|
14b38a3ea4 | ||
|
|
b1121cdee2 | ||
|
|
e27666cd75 | ||
|
|
6771c2cc7f | ||
|
|
1d60156fce | ||
|
|
467300126b | ||
|
|
19b8ab1c4e | ||
|
|
f927742601 | ||
|
|
210af19293 | ||
|
|
6f90ee89fd | ||
|
|
20ef920fc6 | ||
|
|
9602f4e16d | ||
|
|
d3e4c55fc5 | ||
|
|
f1ae82b220 | ||
|
|
aad98c0611 | ||
|
|
f98145d556 | ||
|
|
99ea302aaa | ||
|
|
133f73ab0b | ||
|
|
28d5eeb9c4 | ||
|
|
5adfe28cf4 | ||
|
|
d2e0d38218 | ||
|
|
7003268b9f | ||
|
|
c8d1bbeef8 | ||
|
|
158aed0c18 | ||
|
|
3098be9653 | ||
|
|
86b57f696f | ||
|
|
ac9b661395 | ||
|
|
ad99afae98 | ||
|
|
8374aa6ab6 | ||
|
|
c8087cdd6f | ||
|
|
ccb8b79ef8 | ||
|
|
a55ced6b7f | ||
|
|
2e5f192f35 | ||
|
|
c2f36e086e | ||
|
|
cdd91df869 | ||
|
|
a2d628cabe | ||
|
|
48e1f72d23 | ||
|
|
3b13211579 | ||
|
|
d0629ba5a2 | ||
|
|
46bb44b95d | ||
|
|
4cbac20b40 | ||
|
|
d4ebbc291a | ||
|
|
3ecf9a9b56 | ||
|
|
1559493802 | ||
|
|
98a0e605be | ||
|
|
dbdd46da9a | ||
|
|
3aa6151729 | ||
|
|
0beb0d80f8 | ||
|
|
3c421e9ccb | ||
|
|
23cbafab1c | ||
|
|
4eb7f94171 | ||
|
|
d497d12649 | ||
|
|
66f79fa254 | ||
|
|
5422f555cf | ||
|
|
ceaa5c2dab | ||
|
|
768c09dffe | ||
|
|
cc949a2ef3 | ||
|
|
c6aaa66420 | ||
|
|
0bec03e080 | ||
|
|
71099663ad | ||
|
|
a53f0573d8 | ||
|
|
b71e0644bf | ||
|
|
078aebe32a | ||
|
|
afc89c9e4c | ||
|
|
2db616bd7d | ||
|
|
237a848459 | ||
|
|
053216ffd4 | ||
|
|
61d10d686b | ||
|
|
52bc8ea29f | ||
|
|
5b3e3642ca | ||
|
|
d516dac0c3 | ||
|
|
c0fcb5f922 | ||
|
|
be46130322 | ||
|
|
76110c1dd8 | ||
|
|
92c4206e86 | ||
|
|
a15e01f2eb | ||
|
|
76a65ca3ee | ||
|
|
8e74084d52 | ||
|
|
5366fe2ff8 |
@@ -1,9 +1,11 @@
|
|||||||
[unstable]
|
[unstable]
|
||||||
build-std = ["core", "compiler_builtins"]
|
# build-std = ["core", "compiler_builtins"]
|
||||||
build-std-features = ["compiler-builtins-mem"]
|
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
target = "x86_64-blog_os.json"
|
# target = "x86_64-blog_os.json"
|
||||||
|
|
||||||
[target.'cfg(target_os = "none")']
|
[target.'cfg(target_os = "none")']
|
||||||
runner = "bootimage runner"
|
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"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: Code
|
name: Build Code
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -16,7 +16,6 @@ jobs:
|
|||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
platform: [
|
platform: [
|
||||||
ubuntu-latest,
|
ubuntu-latest,
|
||||||
@@ -42,7 +41,6 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: Test
|
name: Test
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
matrix:
|
||||||
platform: [
|
platform: [
|
||||||
ubuntu-latest,
|
ubuntu-latest,
|
||||||
@@ -67,6 +65,35 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: bootimage
|
command: 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 test`
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
|
||||||
check_formatting:
|
check_formatting:
|
||||||
name: Check Formatting
|
name: Check Formatting
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
244
Cargo.lock
generated
244
Cargo.lock
generated
@@ -1,6 +1,22 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
# This file is automatically @generated by Cargo.
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.32"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bit_field"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed8765909f9009617974ab6b7d332625b320b33c326b1e9321382ef1999b5d56"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "1.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "blog_os"
|
name = "blog_os"
|
||||||
@@ -8,23 +24,167 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bootloader",
|
"bootloader",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"spin 0.5.2",
|
"rlibc",
|
||||||
|
"spin",
|
||||||
|
"uart_16550",
|
||||||
"volatile",
|
"volatile",
|
||||||
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bootloader"
|
name = "bootloader"
|
||||||
version = "0.9.33"
|
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"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
|
checksum = "89fec17b16f1ac67908af82e47d0a90a7afd0e1827b181cd77504323d3263d35"
|
||||||
|
dependencies = [
|
||||||
|
"semver",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "disk_image"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"bootloader-locator",
|
||||||
|
"locate-cargo-manifest",
|
||||||
|
"runner-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "0.4.6"
|
||||||
|
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"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.5.0"
|
version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"spin 0.9.8",
|
"spin",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.76"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "755456fae044e6fa1ebbbd1b3e902ae19e73097ed4ed87bb79934a867c007bc3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "locate-cargo-manifest"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d264d672563b20c0a2eb9045f4072e1352002f6c316cc0677bed8b767e17b7e1"
|
||||||
|
dependencies = [
|
||||||
|
"json",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[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"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "394cec28fa623e00903caf7ba4fa6fb9a0e260280bb8cdbbba029611108a0190"
|
||||||
|
dependencies = [
|
||||||
|
"semver-parser",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver-parser"
|
||||||
|
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]]
|
[[package]]
|
||||||
@@ -34,13 +194,73 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "syn"
|
||||||
version = "0.9.8"
|
version = "1.0.39"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
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"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "volatile"
|
name = "volatile"
|
||||||
version = "0.2.7"
|
version = "0.4.0-alpha.00"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945"
|
checksum = "9a1da81878b88e2b57ca8b3d62c0c3e9979d9531cfe0e6d1c094174d8458eac6"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wait-timeout"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "x86_64"
|
||||||
|
version = "0.11.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "365de37eb7c6da582cbb510dd0f3f1235d24ff6309a8a96e8a9909cc9bfd608f"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bitflags",
|
||||||
|
]
|
||||||
|
|||||||
29
Cargo.toml
29
Cargo.toml
@@ -2,18 +2,33 @@
|
|||||||
name = "blog_os"
|
name = "blog_os"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||||
edition = "2024"
|
edition = "2018"
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"disk_image",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[test]]
|
||||||
|
name = "should_panic"
|
||||||
|
harness = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bootloader = "0.9"
|
bootloader = { path = "../../uefi-test"}
|
||||||
volatile = "0.2.6"
|
rlibc = "1.0.0"
|
||||||
|
volatile = "0.4.0-alpha"
|
||||||
spin = "0.5.2"
|
spin = "0.5.2"
|
||||||
|
x86_64 = "0.11.0"
|
||||||
|
uart_16550 = "0.2.0"
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
features = ["spin_no_std"]
|
features = ["spin_no_std"]
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "blog_os"
|
[package.metadata.bootimage]
|
||||||
test = false
|
test-args = [
|
||||||
bench = false
|
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
|
||||||
|
"-display", "none"
|
||||||
|
]
|
||||||
|
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -1,10 +1,10 @@
|
|||||||
# Blog OS (VGA Text Mode)
|
# Blog OS (Testing)
|
||||||
|
|
||||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-03)
|
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Build+Code%22+branch%3Apost-04)
|
||||||
|
|
||||||
This repository contains the source code for the [VGA Text Mode][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
This repository contains the source code for the [Testing][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
||||||
|
|
||||||
[post]: https://os.phil-opp.com/vga-text-mode/
|
[post]: https://os.phil-opp.com/testing/
|
||||||
|
|
||||||
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
||||||
|
|
||||||
@@ -56,6 +56,10 @@ dd if=target/x86_64-blog_os/debug/bootimage-blog_os.bin of=/dev/sdX && sync
|
|||||||
|
|
||||||
Where `sdX` is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.
|
Where `sdX` is the device name of your USB stick. **Be careful** to choose the correct device name, because everything on that device is overwritten.
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
To run the unit and integration tests, execute `cargo xtest`.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Licensed under either of
|
Licensed under either of
|
||||||
|
|||||||
13
disk_image/Cargo.toml
Normal file
13
disk_image/Cargo.toml
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[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"
|
||||||
57
disk_image/src/bin/runner.rs
Normal file
57
disk_image/src/bin/runner.rs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
45
disk_image/src/lib.rs
Normal file
45
disk_image/src/lib.rs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
40
disk_image/src/main.rs
Normal file
40
disk_image/src/main.rs
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
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(())
|
||||||
|
}
|
||||||
72
src/lib.rs
Normal file
72
src/lib.rs
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![cfg_attr(test, no_main)]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(crate::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
extern crate rlibc;
|
||||||
|
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
pub mod serial;
|
||||||
|
//pub mod vga_buffer;
|
||||||
|
|
||||||
|
pub trait Testable {
|
||||||
|
fn run(&self) -> ();
|
||||||
|
}
|
||||||
|
|
||||||
|
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]) {
|
||||||
|
serial_println!("Running {} tests", tests.len());
|
||||||
|
for test in tests {
|
||||||
|
test.run();
|
||||||
|
}
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn test_panic_handler(info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[failed]\n");
|
||||||
|
serial_println!("Error: {}\n", info);
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
#[repr(u32)]
|
||||||
|
pub enum QemuExitCode {
|
||||||
|
Success = 0x10,
|
||||||
|
Failed = 0x11,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn exit_qemu(exit_code: QemuExitCode) {
|
||||||
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
let mut port = Port::new(0xf4);
|
||||||
|
port.write(exit_code as u32);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Entry point for `cargo xtest`
|
||||||
|
#[cfg(test)]
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
test_main();
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
test_panic_handler(info)
|
||||||
|
}
|
||||||
43
src/main.rs
43
src/main.rs
@@ -1,20 +1,49 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(blog_os::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
use core::panic::PanicInfo;
|
use blog_os::serial_println;
|
||||||
|
use core::{panic::PanicInfo, ptr, slice};
|
||||||
|
|
||||||
mod vga_buffer;
|
#[no_mangle]
|
||||||
|
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info::BootInfo) -> ! {
|
||||||
|
#[cfg(test)]
|
||||||
|
test_main();
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
let mut framebuffer = {
|
||||||
pub extern "C" fn _start() -> ! {
|
let ptr = boot_info.framebuffer.start_addr as *mut u8;
|
||||||
println!("Hello World{}", "!");
|
let slice = unsafe { slice::from_raw_parts_mut(ptr, boot_info.framebuffer.len) };
|
||||||
|
volatile::Volatile::new(slice)
|
||||||
|
};
|
||||||
|
|
||||||
loop {}
|
//serial_println!("Hello World{}", "!");
|
||||||
|
|
||||||
|
for i in 0..boot_info.framebuffer.len {
|
||||||
|
framebuffer.index_mut(i).write(0x99);
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {
|
||||||
|
x86_64::instructions::hlt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is called on panic.
|
/// This function is called on panic.
|
||||||
|
#[cfg(not(test))]
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
println!("{}", info);
|
serial_println!("{}", info);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn trivial_assertion() {
|
||||||
|
assert_eq!(1, 1);
|
||||||
|
}
|
||||||
|
|||||||
37
src/serial.rs
Normal file
37
src/serial.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
use lazy_static::lazy_static;
|
||||||
|
use spin::Mutex;
|
||||||
|
use uart_16550::SerialPort;
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
pub static ref SERIAL1: Mutex<SerialPort> = {
|
||||||
|
let mut serial_port = unsafe { SerialPort::new(0x3F8) };
|
||||||
|
serial_port.init();
|
||||||
|
Mutex::new(serial_port)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn _print(args: ::core::fmt::Arguments) {
|
||||||
|
use core::fmt::Write;
|
||||||
|
SERIAL1
|
||||||
|
.lock()
|
||||||
|
.write_fmt(args)
|
||||||
|
.expect("Printing to serial failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Prints to the host through the serial interface.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! serial_print {
|
||||||
|
($($arg:tt)*) => {
|
||||||
|
$crate::serial::_print(format_args!($($arg)*));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Prints to the host through the serial interface, appending a newline.
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! serial_println {
|
||||||
|
() => ($crate::serial_print!("\n"));
|
||||||
|
($fmt:expr) => ($crate::serial_print!(concat!($fmt, "\n")));
|
||||||
|
($fmt:expr, $($arg:tt)*) => ($crate::serial_print!(
|
||||||
|
concat!($fmt, "\n"), $($arg)*));
|
||||||
|
}
|
||||||
@@ -169,3 +169,25 @@ pub fn _print(args: fmt::Arguments) {
|
|||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
WRITER.lock().write_fmt(args).unwrap();
|
WRITER.lock().write_fmt(args).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_simple() {
|
||||||
|
println!("test_println_simple output");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println_many() {
|
||||||
|
for _ in 0..200 {
|
||||||
|
println!("test_println_many output");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
24
tests/basic_boot.rs
Normal file
24
tests/basic_boot.rs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(blog_os::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[no_mangle] // don't mangle the name of this function
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
test_main();
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_println() {
|
||||||
|
//println!("test_println output");
|
||||||
|
}
|
||||||
25
tests/should_panic.rs
Normal file
25
tests/should_panic.rs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
should_fail();
|
||||||
|
serial_println!("[test did not panic]");
|
||||||
|
exit_qemu(QemuExitCode::Failed);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_fail() {
|
||||||
|
serial_print!("should_panic::should_fail...\t");
|
||||||
|
assert_eq!(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(_info: &PanicInfo) -> ! {
|
||||||
|
serial_println!("[ok]");
|
||||||
|
exit_qemu(QemuExitCode::Success);
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
{
|
{
|
||||||
"llvm-target": "x86_64-unknown-none",
|
"llvm-target": "x86_64-unknown-none",
|
||||||
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
|
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
|
||||||
"arch": "x86_64",
|
"arch": "x86_64",
|
||||||
"target-endian": "little",
|
"target-endian": "little",
|
||||||
"target-pointer-width": 64,
|
"target-pointer-width": "64",
|
||||||
"target-c-int-width": 32,
|
"target-c-int-width": "32",
|
||||||
"os": "none",
|
"os": "none",
|
||||||
"executables": true,
|
"executables": true,
|
||||||
"linker-flavor": "ld.lld",
|
"linker-flavor": "ld.lld",
|
||||||
"linker": "rust-lld",
|
"linker": "rust-lld",
|
||||||
"panic-strategy": "abort",
|
"panic-strategy": "abort",
|
||||||
"disable-redzone": true,
|
"disable-redzone": true,
|
||||||
"features": "-mmx,-sse,+soft-float",
|
"features": "-mmx,-sse,+soft-float"
|
||||||
"rustc-abi": "x86-softfloat"
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user