mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
253 Commits
8708b54756
...
post-04-no
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db307d89bc | ||
|
|
fe23af5b3e | ||
|
|
a3d58588a2 | ||
|
|
edd155d570 | ||
|
|
3200b7a68d | ||
|
|
cde3c8f955 | ||
|
|
c18cd874ca | ||
|
|
f316bd1a08 | ||
|
|
4a4d704384 | ||
|
|
6380e069f7 | ||
|
|
1ddc27ca88 | ||
|
|
71d8a438f7 | ||
|
|
3a77cbe794 | ||
|
|
7341cff39d | ||
|
|
406c406d5f | ||
|
|
6f9cfce6f9 | ||
|
|
acf3717551 | ||
|
|
e78d33a5bf | ||
|
|
6292789393 | ||
|
|
651adbc8bd | ||
|
|
4bbaae24a4 | ||
|
|
44d7654ef6 | ||
|
|
f135aefae8 | ||
|
|
ffaac76876 | ||
|
|
5ae9f62f4d | ||
|
|
da0ee38f09 | ||
|
|
263e852dcc | ||
|
|
614e5b0e86 | ||
|
|
9ee42e0f5f | ||
|
|
c4672096d4 | ||
|
|
ffe1b6abd0 | ||
|
|
16ffe80fd5 | ||
|
|
07d8a22a53 | ||
|
|
bf33685d00 | ||
|
|
3ee6badb33 | ||
|
|
9f9ff59489 | ||
|
|
a1c7931a77 | ||
|
|
2c30310281 | ||
|
|
57cd52b7f5 | ||
|
|
a004e7da9c | ||
|
|
b1bf0873ce | ||
|
|
d7e505da9e | ||
|
|
2039cd7a64 | ||
|
|
ebb862de2a | ||
|
|
d588dca953 | ||
|
|
f23269ed93 | ||
|
|
46264d08ca | ||
|
|
029d6bee78 | ||
|
|
0fc6fedd82 | ||
|
|
0489c09d05 | ||
|
|
99b139ddff | ||
|
|
fea4fa9c67 | ||
|
|
ddbe317099 | ||
|
|
56cf71df9f | ||
|
|
abd2f4c5e2 | ||
|
|
0cc02f02c5 | ||
|
|
adcb547765 | ||
|
|
faf097fd06 | ||
|
|
dbb3db2dc7 | ||
|
|
58629ea208 | ||
|
|
1636196d54 | ||
|
|
5c964dc7b9 | ||
|
|
0c3e6f95f6 | ||
|
|
23d8bb948e | ||
|
|
748365bf62 | ||
|
|
2b1f72ccd8 | ||
|
|
1c4ca04a2f | ||
|
|
60856aac6b | ||
|
|
ea998c9267 | ||
|
|
679e453509 | ||
|
|
7de138aa04 | ||
|
|
79ad84c502 | ||
|
|
4f90781b3f | ||
|
|
9e40f377db | ||
|
|
2a1f4d047c | ||
|
|
01d9a028a3 | ||
|
|
515d98645e | ||
|
|
6b23fa3d28 | ||
|
|
6e012e5e42 | ||
|
|
a86fe5c2af | ||
|
|
99a7231d52 | ||
|
|
f4ed1fce81 | ||
|
|
ab10af6f99 | ||
|
|
621364bd1b | ||
|
|
086c3a02d3 | ||
|
|
14b38a3ea4 | ||
|
|
bcafb60069 | ||
|
|
818bfb9646 | ||
|
|
b1121cdee2 | ||
|
|
465eb45cfe | ||
|
|
e27666cd75 | ||
|
|
6771c2cc7f | ||
|
|
c6d5a4d567 | ||
|
|
fe5e1fd92c | ||
|
|
ffd1bda509 | ||
|
|
1d60156fce | ||
|
|
a1060f79f0 | ||
|
|
bb8923cf56 | ||
|
|
467300126b | ||
|
|
3765c27020 | ||
|
|
dbe0802c6d | ||
|
|
19b8ab1c4e | ||
|
|
70b339a4a5 | ||
|
|
9e1e3926fa | ||
|
|
f927742601 | ||
|
|
210af19293 | ||
|
|
6f90ee89fd | ||
|
|
153beec1c4 | ||
|
|
7b00599bf8 | ||
|
|
72aa3a4580 | ||
|
|
5d7c4678de | ||
|
|
20ef920fc6 | ||
|
|
9602f4e16d | ||
|
|
bfde53de79 | ||
|
|
7197d8b18a | ||
|
|
d3e4c55fc5 | ||
|
|
f1ae82b220 | ||
|
|
aad98c0611 | ||
|
|
f98145d556 | ||
|
|
99ea302aaa | ||
|
|
133f73ab0b | ||
|
|
298ec5f4b6 | ||
|
|
e86c95bd24 | ||
|
|
28d5eeb9c4 | ||
|
|
5adfe28cf4 | ||
|
|
ff8afb814e | ||
|
|
47bcca33b3 | ||
|
|
5ed27923e8 | ||
|
|
d2e0d38218 | ||
|
|
7003268b9f | ||
|
|
fcd849f471 | ||
|
|
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 | ||
|
|
70c24b76d0 | ||
|
|
b59720f6e1 | ||
|
|
16a314ab8d | ||
|
|
63b97fe1f8 | ||
|
|
528bbd4e9f | ||
|
|
06d1c9ff81 | ||
|
|
c1064ad316 | ||
|
|
4eb7f94171 | ||
|
|
f875a933e5 | ||
|
|
3c2a5ef0f6 | ||
|
|
d497d12649 | ||
|
|
652d91154f | ||
|
|
64e7ea7b1a | ||
|
|
66f79fa254 | ||
|
|
9a879e69c5 | ||
|
|
eee4718115 | ||
|
|
5422f555cf | ||
|
|
186321623a | ||
|
|
1246fc4df9 | ||
|
|
9237c875f3 | ||
|
|
ceaa5c2dab | ||
|
|
03da22d8e1 | ||
|
|
62b89cd80f | ||
|
|
e1034aa9ac | ||
|
|
577c6b8cfc | ||
|
|
768c09dffe | ||
|
|
d98a4d0cbc | ||
|
|
f308628db2 | ||
|
|
cc949a2ef3 | ||
|
|
93b2134692 | ||
|
|
ab16203ed7 | ||
|
|
c6aaa66420 | ||
|
|
4d405d5098 | ||
|
|
63f8f3a6eb | ||
|
|
0bec03e080 | ||
|
|
e3f9cd42b0 | ||
|
|
013e6f2add | ||
|
|
71099663ad | ||
|
|
61f524f040 | ||
|
|
d5cb74ac8b | ||
|
|
3bf2c66acc | ||
|
|
a53f0573d8 | ||
|
|
3f9072e8b5 | ||
|
|
0e6ffc1a4f | ||
|
|
b71e0644bf | ||
|
|
078aebe32a | ||
|
|
bac4a3c549 | ||
|
|
57484164ab | ||
|
|
1ca8cec4e6 | ||
|
|
afc89c9e4c | ||
|
|
4bfcea2368 | ||
|
|
2d5d6ee850 | ||
|
|
2db616bd7d | ||
|
|
af0b258279 | ||
|
|
c9ce9d5735 | ||
|
|
237a848459 | ||
|
|
de2b99f0d2 | ||
|
|
053216ffd4 | ||
|
|
61d10d686b | ||
|
|
52bc8ea29f | ||
|
|
8c1e98752a | ||
|
|
ceb5cf4eed | ||
|
|
f013172dd7 | ||
|
|
858a2f94c6 | ||
|
|
5b3e3642ca | ||
|
|
1d5bc372a0 | ||
|
|
2ce4af4a65 | ||
|
|
d516dac0c3 | ||
|
|
c0fcb5f922 | ||
|
|
0874a50544 | ||
|
|
8d730050d3 | ||
|
|
752a7ed84e | ||
|
|
be46130322 | ||
|
|
b5c05193e1 | ||
|
|
76110c1dd8 | ||
|
|
92c4206e86 | ||
|
|
a15e01f2eb | ||
|
|
76a65ca3ee | ||
|
|
8e74084d52 | ||
|
|
5366fe2ff8 | ||
|
|
6c427e7cee | ||
|
|
c43d6191c5 | ||
|
|
c1e3fa57c6 | ||
|
|
3574958d5f | ||
|
|
cbfe6221bd | ||
|
|
d1897af515 | ||
|
|
59f9fe1e69 | ||
|
|
f4fd0e264a | ||
|
|
bbc19e132c | ||
|
|
f9ffee92c7 | ||
|
|
fd08b1a123 | ||
|
|
d71e6a7cb6 | ||
|
|
27f2c4c2ff | ||
|
|
19de9e560d |
11
.cargo/config.toml
Normal file
11
.cargo/config.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[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"
|
||||
44
.github/workflows/build-code.yml
vendored
44
.github/workflows/build-code.yml
vendored
@@ -54,21 +54,45 @@ jobs:
|
||||
with:
|
||||
profile: minimal
|
||||
toolchain: nightly
|
||||
- name: Install bootimage
|
||||
run: cargo install bootimage --debug
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v2
|
||||
- name: Add thumbv7em-none-eabihf Target
|
||||
run: rustup target add thumbv7em-none-eabihf
|
||||
- name: Build for thumbv7em-none-eabihf
|
||||
run: cargo build --target thumbv7em-none-eabihf
|
||||
- name: Build for Linux
|
||||
- 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
|
||||
|
||||
# install QEMU
|
||||
- name: Install QEMU (Linux)
|
||||
run: sudo apt update && sudo apt install qemu-system-x86
|
||||
if: runner.os == 'Linux'
|
||||
run: cargo rustc -- -C link-arg=-nostartfiles
|
||||
- name: Build for macOS
|
||||
- name: Install QEMU (macOS)
|
||||
run: brew install qemu
|
||||
if: runner.os == 'macOS'
|
||||
run: cargo rustc -- -C link-args="-e __start -static -nostartfiles"
|
||||
- name: Build for Windows
|
||||
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'
|
||||
run: cargo rustc -- -C link-args="/ENTRY:_start /SUBSYSTEM:console"
|
||||
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:
|
||||
name: Check Formatting
|
||||
|
||||
261
Cargo.lock
generated
261
Cargo.lock
generated
@@ -1,5 +1,266 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[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]]
|
||||
name = "blog_os"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bootloader",
|
||||
"lazy_static",
|
||||
"rlibc",
|
||||
"spin",
|
||||
"uart_16550",
|
||||
"volatile",
|
||||
"x86_64",
|
||||
]
|
||||
|
||||
[[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"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
dependencies = [
|
||||
"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]]
|
||||
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"
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
version = "0.4.0-alpha.00"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
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
@@ -4,10 +4,31 @@ version = "0.1.0"
|
||||
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[workspace]
|
||||
members = [
|
||||
"disk_image",
|
||||
]
|
||||
|
||||
[[test]]
|
||||
name = "should_panic"
|
||||
harness = false
|
||||
|
||||
[dependencies]
|
||||
bootloader = { path = "../../uefi-test"}
|
||||
rlibc = "1.0.0"
|
||||
volatile = "0.4.0-alpha"
|
||||
spin = "0.5.2"
|
||||
x86_64 = "0.11.0"
|
||||
uart_16550 = "0.2.0"
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
[dependencies.lazy_static]
|
||||
version = "1.0"
|
||||
features = ["spin_no_std"]
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
[package.metadata.bootimage]
|
||||
test-args = [
|
||||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
|
||||
"-display", "none"
|
||||
]
|
||||
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||
|
||||
54
README.md
54
README.md
@@ -1,25 +1,65 @@
|
||||
# Blog OS (A Freestanding Rust Binary)
|
||||
# Blog OS (Testing)
|
||||
|
||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Build+Code%22+branch%3Apost-01)
|
||||
[](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 [A Freestanding Rust Binary][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/freestanding-rust-binary/
|
||||
[post]: https://os.phil-opp.com/testing/
|
||||
|
||||
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**
|
||||
|
||||
## Building
|
||||
|
||||
To build the project on Linux, run:
|
||||
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:
|
||||
|
||||
```
|
||||
cargo rustc -- -Clink-arg=-nostartfiles
|
||||
cargo build
|
||||
```
|
||||
|
||||
The entry point and the build command differ slightly on macOS and Windows. See the [post] for more information.
|
||||
To create a bootable disk image from the compiled kernel, you need to install the [`bootimage`] tool:
|
||||
|
||||
[`bootimage`]: https://github.com/rust-osdev/bootimage
|
||||
|
||||
```
|
||||
cargo install bootimage
|
||||
```
|
||||
|
||||
After installing, you can create the bootable disk image by running:
|
||||
|
||||
```
|
||||
cargo bootimage
|
||||
```
|
||||
|
||||
This creates a bootable disk image in the `target/x86_64-blog_os/debug` directory.
|
||||
|
||||
Please file an issue if you have any problems.
|
||||
|
||||
## Running
|
||||
|
||||
You can run the disk image in [QEMU] through:
|
||||
|
||||
[QEMU]: https://www.qemu.org/
|
||||
|
||||
```
|
||||
cargo run
|
||||
```
|
||||
|
||||
[QEMU] and the [`bootimage`] tool need 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:
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
## Testing
|
||||
|
||||
To run the unit and integration tests, execute `cargo xtest`.
|
||||
|
||||
## License
|
||||
|
||||
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(())
|
||||
}
|
||||
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@@ -0,0 +1 @@
|
||||
nightly
|
||||
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)
|
||||
}
|
||||
42
src/main.rs
42
src/main.rs
@@ -1,15 +1,49 @@
|
||||
#![no_std]
|
||||
#![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};
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn _start() -> ! {
|
||||
loop {}
|
||||
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info::BootInfo) -> ! {
|
||||
#[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();
|
||||
}
|
||||
}
|
||||
|
||||
/// This function is called on panic.
|
||||
#[cfg(not(test))]
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! {
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
serial_println!("{}", info);
|
||||
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)*));
|
||||
}
|
||||
193
src/vga_buffer.rs
Normal file
193
src/vga_buffer.rs
Normal file
@@ -0,0 +1,193 @@
|
||||
use core::fmt;
|
||||
use lazy_static::lazy_static;
|
||||
use spin::Mutex;
|
||||
use volatile::Volatile;
|
||||
|
||||
lazy_static! {
|
||||
/// A global `Writer` instance that can be used for printing to the VGA text buffer.
|
||||
///
|
||||
/// Used by the `print!` and `println!` macros.
|
||||
pub static ref WRITER: Mutex<Writer> = Mutex::new(Writer {
|
||||
column_position: 0,
|
||||
color_code: ColorCode::new(Color::Yellow, Color::Black),
|
||||
buffer: unsafe { &mut *(0xb8000 as *mut Buffer) },
|
||||
});
|
||||
}
|
||||
|
||||
/// The standard color palette in VGA text mode.
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum Color {
|
||||
Black = 0,
|
||||
Blue = 1,
|
||||
Green = 2,
|
||||
Cyan = 3,
|
||||
Red = 4,
|
||||
Magenta = 5,
|
||||
Brown = 6,
|
||||
LightGray = 7,
|
||||
DarkGray = 8,
|
||||
LightBlue = 9,
|
||||
LightGreen = 10,
|
||||
LightCyan = 11,
|
||||
LightRed = 12,
|
||||
Pink = 13,
|
||||
Yellow = 14,
|
||||
White = 15,
|
||||
}
|
||||
|
||||
/// A combination of a foreground and a background color.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(transparent)]
|
||||
struct ColorCode(u8);
|
||||
|
||||
impl ColorCode {
|
||||
/// Create a new `ColorCode` with the given foreground and background colors.
|
||||
fn new(foreground: Color, background: Color) -> ColorCode {
|
||||
ColorCode((background as u8) << 4 | (foreground as u8))
|
||||
}
|
||||
}
|
||||
|
||||
/// A screen character in the VGA text buffer, consisting of an ASCII character and a `ColorCode`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(C)]
|
||||
struct ScreenChar {
|
||||
ascii_character: u8,
|
||||
color_code: ColorCode,
|
||||
}
|
||||
|
||||
/// The height of the text buffer (normally 25 lines).
|
||||
const BUFFER_HEIGHT: usize = 25;
|
||||
/// The width of the text buffer (normally 80 columns).
|
||||
const BUFFER_WIDTH: usize = 80;
|
||||
|
||||
/// A structure representing the VGA text buffer.
|
||||
#[repr(transparent)]
|
||||
struct Buffer {
|
||||
chars: [[Volatile<ScreenChar>; BUFFER_WIDTH]; BUFFER_HEIGHT],
|
||||
}
|
||||
|
||||
/// A writer type that allows writing ASCII bytes and strings to an underlying `Buffer`.
|
||||
///
|
||||
/// Wraps lines at `BUFFER_WIDTH`. Supports newline characters and implements the
|
||||
/// `core::fmt::Write` trait.
|
||||
pub struct Writer {
|
||||
column_position: usize,
|
||||
color_code: ColorCode,
|
||||
buffer: &'static mut Buffer,
|
||||
}
|
||||
|
||||
impl Writer {
|
||||
/// Writes an ASCII byte to the buffer.
|
||||
///
|
||||
/// Wraps lines at `BUFFER_WIDTH`. Supports the `\n` newline character.
|
||||
pub fn write_byte(&mut self, byte: u8) {
|
||||
match byte {
|
||||
b'\n' => self.new_line(),
|
||||
byte => {
|
||||
if self.column_position >= BUFFER_WIDTH {
|
||||
self.new_line();
|
||||
}
|
||||
|
||||
let row = BUFFER_HEIGHT - 1;
|
||||
let col = self.column_position;
|
||||
|
||||
let color_code = self.color_code;
|
||||
self.buffer.chars[row][col].write(ScreenChar {
|
||||
ascii_character: byte,
|
||||
color_code,
|
||||
});
|
||||
self.column_position += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the given ASCII string to the buffer.
|
||||
///
|
||||
/// Wraps lines at `BUFFER_WIDTH`. Supports the `\n` newline character. Does **not**
|
||||
/// support strings with non-ASCII characters, since they can't be printed in the VGA text
|
||||
/// mode.
|
||||
fn write_string(&mut self, s: &str) {
|
||||
for byte in s.bytes() {
|
||||
match byte {
|
||||
// printable ASCII byte or newline
|
||||
0x20..=0x7e | b'\n' => self.write_byte(byte),
|
||||
// not part of printable ASCII range
|
||||
_ => self.write_byte(0xfe),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Shifts all lines one line up and clears the last row.
|
||||
fn new_line(&mut self) {
|
||||
for row in 1..BUFFER_HEIGHT {
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
let character = self.buffer.chars[row][col].read();
|
||||
self.buffer.chars[row - 1][col].write(character);
|
||||
}
|
||||
}
|
||||
self.clear_row(BUFFER_HEIGHT - 1);
|
||||
self.column_position = 0;
|
||||
}
|
||||
|
||||
/// Clears a row by overwriting it with blank characters.
|
||||
fn clear_row(&mut self, row: usize) {
|
||||
let blank = ScreenChar {
|
||||
ascii_character: b' ',
|
||||
color_code: self.color_code,
|
||||
};
|
||||
for col in 0..BUFFER_WIDTH {
|
||||
self.buffer.chars[row][col].write(blank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Write for Writer {
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
self.write_string(s);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Like the `print!` macro in the standard library, but prints to the VGA text buffer.
|
||||
#[macro_export]
|
||||
macro_rules! print {
|
||||
($($arg:tt)*) => ($crate::vga_buffer::_print(format_args!($($arg)*)));
|
||||
}
|
||||
|
||||
/// Like the `println!` macro in the standard library, but prints to the VGA text buffer.
|
||||
#[macro_export]
|
||||
macro_rules! println {
|
||||
() => ($crate::print!("\n"));
|
||||
($($arg:tt)*) => ($crate::print!("{}\n", format_args!($($arg)*)));
|
||||
}
|
||||
|
||||
/// Prints the given formatted string to the VGA text buffer through the global `WRITER` instance.
|
||||
#[doc(hidden)]
|
||||
pub fn _print(args: fmt::Arguments) {
|
||||
use core::fmt::Write;
|
||||
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 {}
|
||||
}
|
||||
15
x86_64-blog_os.json
Normal file
15
x86_64-blog_os.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"llvm-target": "x86_64-unknown-none",
|
||||
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
|
||||
"arch": "x86_64",
|
||||
"target-endian": "little",
|
||||
"target-pointer-width": "64",
|
||||
"target-c-int-width": "32",
|
||||
"os": "none",
|
||||
"executables": true,
|
||||
"linker-flavor": "ld.lld",
|
||||
"linker": "rust-lld",
|
||||
"panic-strategy": "abort",
|
||||
"disable-redzone": true,
|
||||
"features": "-mmx,-sse,+soft-float"
|
||||
}
|
||||
Reference in New Issue
Block a user