mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Compare commits
345 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4e9519de0 | ||
|
|
a129329b0a | ||
|
|
0df06162c8 | ||
|
|
d71b49aebf | ||
|
|
fe04fb8093 | ||
|
|
a9f5ed6e74 | ||
|
|
423ef15fc5 | ||
|
|
cef626d762 | ||
|
|
200695fcc8 | ||
|
|
360a40b5a7 | ||
|
|
86a3c7065e | ||
|
|
26a1ce37b3 | ||
|
|
70b46ee8cf | ||
|
|
7172bed760 | ||
|
|
f1bfc72747 | ||
|
|
4b368f2e5b | ||
|
|
5ef9960d51 | ||
|
|
8bf38af9a1 | ||
|
|
121dc393f8 | ||
|
|
ff1611b10d | ||
|
|
08a6e13df4 | ||
|
|
569232322e | ||
|
|
3936fd7ebc | ||
|
|
eda7450657 | ||
|
|
94149c93f9 | ||
|
|
34195ec8b7 | ||
|
|
25f4bdeea1 | ||
|
|
194fa3c3fe | ||
|
|
9799487962 | ||
|
|
a4efef7baa | ||
|
|
0da8a4bc6b | ||
|
|
d43aa8aebf | ||
|
|
95b30647b1 | ||
|
|
6de3aeaac3 | ||
|
|
4057d8db22 | ||
|
|
a26d6c1b54 | ||
|
|
dc03bde076 | ||
|
|
3fedddde32 | ||
|
|
aa4f62187e | ||
|
|
e8f6e7300d | ||
|
|
9bdde30bd5 | ||
|
|
69fe1aed12 | ||
|
|
d849a7dea5 | ||
|
|
c8b265a0ae | ||
|
|
bc7335ce6c | ||
|
|
722093e2c4 | ||
|
|
845cdd70d4 | ||
|
|
6dc837db7c | ||
|
|
4dd9c6bce7 | ||
|
|
e1f4a05136 | ||
|
|
4f6558c021 | ||
|
|
f63e0dacca | ||
|
|
8d5540e15c | ||
|
|
9ea911b0bb | ||
|
|
df2c149e79 | ||
|
|
a2ca911f4e | ||
|
|
39ee714093 | ||
|
|
3743997479 | ||
|
|
f4592bac7a | ||
|
|
9c546d4899 | ||
|
|
486975e4dc | ||
|
|
b4b2ab89c2 | ||
|
|
e59a2d1249 | ||
|
|
268b5b6856 | ||
|
|
a3c9cfa0e5 | ||
|
|
9bcbf17073 | ||
|
|
d54e691261 | ||
|
|
e06daf91ba | ||
|
|
bd148f9bf2 | ||
|
|
1550e83094 | ||
|
|
98353f2a75 | ||
|
|
64aeb0e98e | ||
|
|
cd244cc604 | ||
|
|
45c39c07b5 | ||
|
|
06f064aefa | ||
|
|
6b51fa467e | ||
|
|
c9cdf562f2 | ||
|
|
f5b5251092 | ||
|
|
92f197c2e5 | ||
|
|
af909cab1e | ||
|
|
2a393c5453 | ||
|
|
515ab6f1bf | ||
|
|
5fc6566d45 | ||
|
|
4101a0bd2e | ||
|
|
70714bc27d | ||
|
|
f0149947cf | ||
|
|
f1dec65abb | ||
|
|
1893caa212 | ||
|
|
09a3ac4f80 | ||
|
|
e53e389474 | ||
|
|
a859eddacf | ||
|
|
506a1d1961 | ||
|
|
152103f322 | ||
|
|
6b4666fbaf | ||
|
|
e41ff18ea0 | ||
|
|
070d0be18a | ||
|
|
371f86175b | ||
|
|
0af790efa6 | ||
|
|
a68ded230f | ||
|
|
b0ec3ba71f | ||
|
|
8452f2617a | ||
|
|
859d936c45 | ||
|
|
235b56a8e3 | ||
|
|
71e6fb1c40 | ||
|
|
78432f9444 | ||
|
|
e3b19929b7 | ||
|
|
f2d93a4e27 | ||
|
|
91f5ba58fd | ||
|
|
2359915246 | ||
|
|
31d907a1f2 | ||
|
|
0380d3a02f | ||
|
|
1acc894846 | ||
|
|
62378b25df | ||
|
|
0f0e18d2b3 | ||
|
|
3508e8a058 | ||
|
|
51caf33232 | ||
|
|
75cad2305f | ||
|
|
d8478d537b | ||
|
|
7653ffcb40 | ||
|
|
55baf4f0b6 | ||
|
|
64264ce6ec | ||
|
|
20dce91c5b | ||
|
|
ad63d440cf | ||
|
|
56be80d62b | ||
|
|
80b847f685 | ||
|
|
b19100a021 | ||
|
|
60664c8876 | ||
|
|
5ffe8c4cbe | ||
|
|
abb90be792 | ||
|
|
ca120eed8c | ||
|
|
0f5ed7f715 | ||
|
|
98c9de82b5 | ||
|
|
a9e8caed90 | ||
|
|
a6a3e30275 | ||
|
|
ffd34a58f9 | ||
|
|
95d6962eb5 | ||
|
|
1ced86e362 | ||
|
|
2e5107d6e8 | ||
|
|
e4cb98a688 | ||
|
|
4b0c11a7de | ||
|
|
9783bf99ca | ||
|
|
151a402d6d | ||
|
|
59639c8fe7 | ||
|
|
ccc507a243 | ||
|
|
b5ba939a13 | ||
|
|
5d8e8d6c02 | ||
|
|
7ef188cda0 | ||
|
|
55a787f413 | ||
|
|
d57a9d3f1f | ||
|
|
63be7cda6b | ||
|
|
8ca3aa3846 | ||
|
|
9925d2e46e | ||
|
|
380e54d6b8 | ||
|
|
0404f437f9 | ||
|
|
d0661d7301 | ||
|
|
7e05d80506 | ||
|
|
162071d611 | ||
|
|
67dbd09d45 | ||
|
|
180e6ba36c | ||
|
|
38dc3b8396 | ||
|
|
ed93cfb926 | ||
|
|
3a230d0624 | ||
|
|
d5f674e62e | ||
|
|
ca3dfc719c | ||
|
|
76282b9981 | ||
|
|
124a95b2d3 | ||
|
|
bc618ad457 | ||
|
|
c1133b0948 | ||
|
|
35612e8b0e | ||
|
|
f7b5e22f68 | ||
|
|
6742a16d50 | ||
|
|
c93dfdd41b | ||
|
|
340cbaba36 | ||
|
|
da9573a4e5 | ||
|
|
231dfacf3b | ||
|
|
4e08f97310 | ||
|
|
5e061c8792 | ||
|
|
9bf21a0392 | ||
|
|
aa800ddc83 | ||
|
|
aadac66bd4 | ||
|
|
139c8ca454 | ||
|
|
487b130c85 | ||
|
|
deb95c5ead | ||
|
|
d820839541 | ||
|
|
a38fe2cd0b | ||
|
|
d28ad91407 | ||
|
|
6ebeb28fdb | ||
|
|
0ce451a144 | ||
|
|
43b5f835ab | ||
|
|
f48eed487c | ||
|
|
cbb5c30954 | ||
|
|
91790d8007 | ||
|
|
287fed94ef | ||
|
|
112d66b98e | ||
|
|
93cb9dfdbe | ||
|
|
9af48bae17 | ||
|
|
7debb78849 | ||
|
|
b0cb401b3b | ||
|
|
d215eb07c2 | ||
|
|
69c7df8a30 | ||
|
|
991c3c863a | ||
|
|
bd4487cefa | ||
|
|
e68f7a1d31 | ||
|
|
ae504f6a61 | ||
|
|
cc8ecaadc2 | ||
|
|
07b4e93ec7 | ||
|
|
c66758ccad | ||
|
|
e7fd27b648 | ||
|
|
0a97c2c97b | ||
|
|
f54a2d7574 | ||
|
|
9809ea57ae | ||
|
|
c2790cf352 | ||
|
|
e6c4c63c00 | ||
|
|
0e7a2dc6ae | ||
|
|
ed543a4591 | ||
|
|
b567d06108 | ||
|
|
080be9bca6 | ||
|
|
0d661fcfdd | ||
|
|
384902502c | ||
|
|
0404ceb1af | ||
|
|
6f12524245 | ||
|
|
0db15e5ee5 | ||
|
|
60b5f3402e | ||
|
|
9828ec0eff | ||
|
|
44ab90f92d | ||
|
|
7a5d91cb96 | ||
|
|
a076ff16ad | ||
|
|
d95da1d511 | ||
|
|
1eab81f58d | ||
|
|
84c1070b0b | ||
|
|
7bfacb39c4 | ||
|
|
f118749cb2 | ||
|
|
9887c1257d | ||
|
|
ee0c11d316 | ||
|
|
b862534be5 | ||
|
|
e465c5b278 | ||
|
|
50b4b89ac2 | ||
|
|
d7b144364d | ||
|
|
d63ddde756 | ||
|
|
79dbd2968a | ||
|
|
b1be646e46 | ||
|
|
71b10a70df | ||
|
|
629fe0fdec | ||
|
|
b25b841467 | ||
|
|
dac7e67403 | ||
|
|
2cc188a403 | ||
|
|
fbeedde68f | ||
|
|
3c28d7f364 | ||
|
|
02c36bae29 | ||
|
|
83b67df8af | ||
|
|
714d9cef7d | ||
|
|
7b0d8f05ba | ||
|
|
3735ae51c9 | ||
|
|
f230ee4258 | ||
|
|
a430d5ef06 | ||
|
|
39f14b6d0b | ||
|
|
dd1daf2652 | ||
|
|
f4331daa25 | ||
|
|
9a415c85b9 | ||
|
|
921dd54207 | ||
|
|
c7cc718ae3 | ||
|
|
3a6d3153a4 | ||
|
|
9fb6c1d0bd | ||
|
|
5ed04baab0 | ||
|
|
00fedc801e | ||
|
|
0f74db4812 | ||
|
|
93fd330ab9 | ||
|
|
3ad5f117c2 | ||
|
|
d1678f5a96 | ||
|
|
002d6f255f | ||
|
|
6c3bf0b10f | ||
|
|
7a792f5cb0 | ||
|
|
93b4dcf434 | ||
|
|
821dd2adb4 | ||
|
|
d636939b51 | ||
|
|
9b7326541e | ||
|
|
4f234b67ef | ||
|
|
7381e11f3c | ||
|
|
a9fe65a0ce | ||
|
|
2001814119 | ||
|
|
a5c50e7408 | ||
|
|
70a52c291d | ||
|
|
c56bfa27e4 | ||
|
|
55aec9ebf3 | ||
|
|
2e1d132a9a | ||
|
|
63e8577d77 | ||
|
|
75d826bf69 | ||
|
|
45be3f0648 | ||
|
|
055c560a7a | ||
|
|
e87044a7ee | ||
|
|
08d2289dad | ||
|
|
7c84dbaa1d | ||
|
|
882c83f9de | ||
|
|
869a69e531 | ||
|
|
817267e51c | ||
|
|
9e75078dab | ||
|
|
41f38d92f2 | ||
|
|
3ac5318c94 | ||
|
|
e94a489a31 | ||
|
|
9da9ecb515 | ||
|
|
f226ba0c3f | ||
|
|
c1fc7171fb | ||
|
|
cf527e9ce7 | ||
|
|
c891acb234 | ||
|
|
b9a0702bc0 | ||
|
|
2919cbdefc | ||
|
|
059ea76848 | ||
|
|
2f085b7310 | ||
|
|
cc713e4570 | ||
|
|
b3066e9a78 | ||
|
|
66c3a0de76 | ||
|
|
96d9de76b0 | ||
|
|
f56e4d24e3 | ||
|
|
8d3d712cef | ||
|
|
5f66b437d5 | ||
|
|
0694f29946 | ||
|
|
889c0771d6 | ||
|
|
e74d9753f2 | ||
|
|
9fc71547d7 | ||
|
|
caa9d8b0e4 | ||
|
|
29512ddd31 | ||
|
|
a7943e7e55 | ||
|
|
bcdadec5b6 | ||
|
|
17f8866264 | ||
|
|
a7ef4012d0 | ||
|
|
6f07c2b666 | ||
|
|
e89c77398d | ||
|
|
f3a7689f33 | ||
|
|
14d0e07b3e | ||
|
|
9651eb7a3b | ||
|
|
89e3e2b190 | ||
|
|
004282138c | ||
|
|
8c575388cf | ||
|
|
4792ec41b1 | ||
|
|
df75f7f4e8 | ||
|
|
5cf3884396 | ||
|
|
e5b6ba38ac | ||
|
|
f429a8ab03 | ||
|
|
d7484ab48b | ||
|
|
06fc63028a | ||
|
|
d4623419b0 | ||
|
|
417c44159e | ||
|
|
ebbc6d55d2 | ||
|
|
c0367074ac | ||
|
|
48e2175bac |
@@ -1,5 +1,5 @@
|
|||||||
[unstable]
|
[unstable]
|
||||||
build-std = ["core", "compiler_builtins"]
|
build-std = ["core", "compiler_builtins", "alloc"]
|
||||||
build-std-features = ["compiler-builtins-mem"]
|
build-std-features = ["compiler-builtins-mem"]
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
|
|||||||
110
Cargo.lock
generated
110
Cargo.lock
generated
@@ -2,6 +2,12 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
@@ -25,7 +31,11 @@ name = "blog_os"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bootloader",
|
"bootloader",
|
||||||
|
"conquer-once",
|
||||||
|
"crossbeam-queue",
|
||||||
|
"futures-util",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
"linked_list_allocator",
|
||||||
"pc-keyboard",
|
"pc-keyboard",
|
||||||
"pic8259",
|
"pic8259",
|
||||||
"spin 0.5.2",
|
"spin 0.5.2",
|
||||||
@@ -40,6 +50,60 @@ version = "0.9.33"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
|
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "conquer-once"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96eb12fb69466716fbae9009d389e6a30830ae8975e170eff2d2cff579f9efa3"
|
||||||
|
dependencies = [
|
||||||
|
"conquer-util",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "conquer-util"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "654fb2472cc369d311c547103a1fa81d467bef370ae7a0680f65939895b1182a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-queue"
|
||||||
|
version = "0.3.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0f58bbc28f91df819d0aa2a2c00cd19754769c2fad90579b3592b1c9ba7a3115"
|
||||||
|
dependencies = [
|
||||||
|
"crossbeam-utils",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "crossbeam-utils"
|
||||||
|
version = "0.8.21"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-core"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-task"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "futures-util"
|
||||||
|
version = "0.3.31"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||||
|
dependencies = [
|
||||||
|
"futures-core",
|
||||||
|
"futures-task",
|
||||||
|
"pin-project-lite",
|
||||||
|
"pin-utils",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lazy_static"
|
name = "lazy_static"
|
||||||
version = "1.5.0"
|
version = "1.5.0"
|
||||||
@@ -49,6 +113,25 @@ dependencies = [
|
|||||||
"spin 0.9.8",
|
"spin 0.9.8",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "linked_list_allocator"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "549ce1740e46b291953c4340adcd74c59bcf4308f4cac050fd33ba91b7168f4a"
|
||||||
|
dependencies = [
|
||||||
|
"spinning_top",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lock_api"
|
||||||
|
version = "0.4.13"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
"scopeguard",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "pc-keyboard"
|
name = "pc-keyboard"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
@@ -64,12 +147,30 @@ dependencies = [
|
|||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-project-lite"
|
||||||
|
version = "0.2.16"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "pin-utils"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustversion"
|
name = "rustversion"
|
||||||
version = "1.0.22"
|
version = "1.0.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scopeguard"
|
||||||
|
version = "1.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "spin"
|
name = "spin"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
@@ -82,6 +183,15 @@ version = "0.9.8"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "spinning_top"
|
||||||
|
version = "0.2.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0"
|
||||||
|
dependencies = [
|
||||||
|
"lock_api",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uart_16550"
|
name = "uart_16550"
|
||||||
version = "0.2.19"
|
version = "0.2.19"
|
||||||
|
|||||||
14
Cargo.toml
14
Cargo.toml
@@ -20,6 +20,7 @@ x86_64 = "0.14.2"
|
|||||||
uart_16550 = "0.2.0"
|
uart_16550 = "0.2.0"
|
||||||
pic8259 = "0.10.1"
|
pic8259 = "0.10.1"
|
||||||
pc-keyboard = "0.7.0"
|
pc-keyboard = "0.7.0"
|
||||||
|
linked_list_allocator = "0.9.0"
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
@@ -30,6 +31,19 @@ name = "blog_os"
|
|||||||
test = true
|
test = true
|
||||||
bench = false
|
bench = false
|
||||||
|
|
||||||
|
[dependencies.crossbeam-queue]
|
||||||
|
version = "0.3.11"
|
||||||
|
default-features = false
|
||||||
|
features = ["alloc"]
|
||||||
|
|
||||||
|
[dependencies.conquer-once]
|
||||||
|
version = "0.2.0"
|
||||||
|
default-features = false
|
||||||
|
|
||||||
|
[dependencies.futures-util]
|
||||||
|
version = "0.3.4"
|
||||||
|
default-features = false
|
||||||
|
features = ["alloc"]
|
||||||
|
|
||||||
[package.metadata.bootimage]
|
[package.metadata.bootimage]
|
||||||
test-args = [
|
test-args = [
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# Blog OS (Paging Implementation)
|
# Blog OS (Async/Await)
|
||||||
|
|
||||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-09)
|
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-12)
|
||||||
|
|
||||||
This repository contains the source code for the [Paging Implementation][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
This repository contains the source code for the [Async/Await][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
|
||||||
|
|
||||||
[post]: https://os.phil-opp.com/paging-implementation/
|
[post]: https://os.phil-opp.com/async-await/
|
||||||
|
|
||||||
**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.**
|
||||||
|
|
||||||
|
|||||||
82
src/allocator.rs
Normal file
82
src/allocator.rs
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::ptr::null_mut;
|
||||||
|
use fixed_size_block::FixedSizeBlockAllocator;
|
||||||
|
use x86_64::{
|
||||||
|
VirtAddr,
|
||||||
|
structures::paging::{
|
||||||
|
FrameAllocator, Mapper, Page, PageTableFlags, Size4KiB, mapper::MapToError,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub mod bump;
|
||||||
|
pub mod fixed_size_block;
|
||||||
|
pub mod linked_list;
|
||||||
|
|
||||||
|
pub const HEAP_START: usize = 0x_4444_4444_0000;
|
||||||
|
pub const HEAP_SIZE: usize = 100 * 1024; // 100 KiB
|
||||||
|
|
||||||
|
#[global_allocator]
|
||||||
|
static ALLOCATOR: Locked<FixedSizeBlockAllocator> = Locked::new(FixedSizeBlockAllocator::new());
|
||||||
|
|
||||||
|
pub fn init_heap(
|
||||||
|
mapper: &mut impl Mapper<Size4KiB>,
|
||||||
|
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
|
||||||
|
) -> Result<(), MapToError<Size4KiB>> {
|
||||||
|
let page_range = {
|
||||||
|
let heap_start = VirtAddr::new(HEAP_START as u64);
|
||||||
|
let heap_end = heap_start + HEAP_SIZE - 1u64;
|
||||||
|
let heap_start_page = Page::containing_address(heap_start);
|
||||||
|
let heap_end_page = Page::containing_address(heap_end);
|
||||||
|
Page::range_inclusive(heap_start_page, heap_end_page)
|
||||||
|
};
|
||||||
|
|
||||||
|
for page in page_range {
|
||||||
|
let frame = frame_allocator
|
||||||
|
.allocate_frame()
|
||||||
|
.ok_or(MapToError::FrameAllocationFailed)?;
|
||||||
|
let flags = PageTableFlags::PRESENT | PageTableFlags::WRITABLE;
|
||||||
|
unsafe { mapper.map_to(page, frame, flags, frame_allocator)?.flush() };
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe {
|
||||||
|
ALLOCATOR.lock().init(HEAP_START, HEAP_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Dummy;
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for Dummy {
|
||||||
|
unsafe fn alloc(&self, _layout: Layout) -> *mut u8 {
|
||||||
|
null_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
|
||||||
|
panic!("dealloc should be never called")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A wrapper around spin::Mutex to permit trait implementations.
|
||||||
|
pub struct Locked<A> {
|
||||||
|
inner: spin::Mutex<A>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<A> Locked<A> {
|
||||||
|
pub const fn new(inner: A) -> Self {
|
||||||
|
Locked {
|
||||||
|
inner: spin::Mutex::new(inner),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lock(&self) -> spin::MutexGuard<A> {
|
||||||
|
self.inner.lock()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Align the given address `addr` upwards to alignment `align`.
|
||||||
|
///
|
||||||
|
/// Requires that `align` is a power of two.
|
||||||
|
fn align_up(addr: usize, align: usize) -> usize {
|
||||||
|
(addr + align - 1) & !(align - 1)
|
||||||
|
}
|
||||||
61
src/allocator/bump.rs
Normal file
61
src/allocator/bump.rs
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
use super::{Locked, align_up};
|
||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::ptr;
|
||||||
|
|
||||||
|
pub struct BumpAllocator {
|
||||||
|
heap_start: usize,
|
||||||
|
heap_end: usize,
|
||||||
|
next: usize,
|
||||||
|
allocations: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BumpAllocator {
|
||||||
|
/// Creates a new empty bump allocator.
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
BumpAllocator {
|
||||||
|
heap_start: 0,
|
||||||
|
heap_end: 0,
|
||||||
|
next: 0,
|
||||||
|
allocations: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initializes the bump allocator with the given heap bounds.
|
||||||
|
///
|
||||||
|
/// This method is unsafe because the caller must ensure that the given
|
||||||
|
/// memory range is unused. Also, this method must be called only once.
|
||||||
|
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
|
||||||
|
self.heap_start = heap_start;
|
||||||
|
self.heap_end = heap_start.saturating_add(heap_size);
|
||||||
|
self.next = heap_start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for Locked<BumpAllocator> {
|
||||||
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
|
let mut bump = self.lock(); // get a mutable reference
|
||||||
|
|
||||||
|
let alloc_start = align_up(bump.next, layout.align());
|
||||||
|
let alloc_end = match alloc_start.checked_add(layout.size()) {
|
||||||
|
Some(end) => end,
|
||||||
|
None => return ptr::null_mut(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if alloc_end > bump.heap_end {
|
||||||
|
ptr::null_mut() // out of memory
|
||||||
|
} else {
|
||||||
|
bump.next = alloc_end;
|
||||||
|
bump.allocations += 1;
|
||||||
|
alloc_start as *mut u8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {
|
||||||
|
let mut bump = self.lock(); // get a mutable reference
|
||||||
|
|
||||||
|
bump.allocations -= 1;
|
||||||
|
if bump.allocations == 0 {
|
||||||
|
bump.next = bump.heap_start;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
109
src/allocator/fixed_size_block.rs
Normal file
109
src/allocator/fixed_size_block.rs
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
use super::Locked;
|
||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::{
|
||||||
|
mem,
|
||||||
|
ptr::{self, NonNull},
|
||||||
|
};
|
||||||
|
|
||||||
|
/// The block sizes to use.
|
||||||
|
///
|
||||||
|
/// The sizes must each be power of 2 because they are also used as
|
||||||
|
/// the block alignment (alignments must be always powers of 2).
|
||||||
|
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048];
|
||||||
|
|
||||||
|
/// Choose an appropriate block size for the given layout.
|
||||||
|
///
|
||||||
|
/// Returns an index into the `BLOCK_SIZES` array.
|
||||||
|
fn list_index(layout: &Layout) -> Option<usize> {
|
||||||
|
let required_block_size = layout.size().max(layout.align());
|
||||||
|
BLOCK_SIZES.iter().position(|&s| s >= required_block_size)
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ListNode {
|
||||||
|
next: Option<&'static mut ListNode>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct FixedSizeBlockAllocator {
|
||||||
|
list_heads: [Option<&'static mut ListNode>; BLOCK_SIZES.len()],
|
||||||
|
fallback_allocator: linked_list_allocator::Heap,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FixedSizeBlockAllocator {
|
||||||
|
/// Creates an empty FixedSizeBlockAllocator.
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
const EMPTY: Option<&'static mut ListNode> = None;
|
||||||
|
FixedSizeBlockAllocator {
|
||||||
|
list_heads: [EMPTY; BLOCK_SIZES.len()],
|
||||||
|
fallback_allocator: linked_list_allocator::Heap::empty(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize the allocator with the given heap bounds.
|
||||||
|
///
|
||||||
|
/// This function is unsafe because the caller must guarantee that the given
|
||||||
|
/// heap bounds are valid and that the heap is unused. This method must be
|
||||||
|
/// called only once.
|
||||||
|
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
|
||||||
|
unsafe {
|
||||||
|
self.fallback_allocator.init(heap_start, heap_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Allocates using the fallback allocator.
|
||||||
|
fn fallback_alloc(&mut self, layout: Layout) -> *mut u8 {
|
||||||
|
match self.fallback_allocator.allocate_first_fit(layout) {
|
||||||
|
Ok(ptr) => ptr.as_ptr(),
|
||||||
|
Err(_) => ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for Locked<FixedSizeBlockAllocator> {
|
||||||
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
|
let mut allocator = self.lock();
|
||||||
|
match list_index(&layout) {
|
||||||
|
Some(index) => {
|
||||||
|
match allocator.list_heads[index].take() {
|
||||||
|
Some(node) => {
|
||||||
|
allocator.list_heads[index] = node.next.take();
|
||||||
|
node as *mut ListNode as *mut u8
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
// no block exists in list => allocate new block
|
||||||
|
let block_size = BLOCK_SIZES[index];
|
||||||
|
// only works if all block sizes are a power of 2
|
||||||
|
let block_align = block_size;
|
||||||
|
let layout = Layout::from_size_align(block_size, block_align).unwrap();
|
||||||
|
allocator.fallback_alloc(layout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => allocator.fallback_alloc(layout),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||||
|
let mut allocator = self.lock();
|
||||||
|
match list_index(&layout) {
|
||||||
|
Some(index) => {
|
||||||
|
let new_node = ListNode {
|
||||||
|
next: allocator.list_heads[index].take(),
|
||||||
|
};
|
||||||
|
// verify that block has size and alignment required for storing node
|
||||||
|
assert!(mem::size_of::<ListNode>() <= BLOCK_SIZES[index]);
|
||||||
|
assert!(mem::align_of::<ListNode>() <= BLOCK_SIZES[index]);
|
||||||
|
let new_node_ptr = ptr as *mut ListNode;
|
||||||
|
unsafe {
|
||||||
|
new_node_ptr.write(new_node);
|
||||||
|
allocator.list_heads[index] = Some(&mut *new_node_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let ptr = NonNull::new(ptr).unwrap();
|
||||||
|
unsafe {
|
||||||
|
allocator.fallback_allocator.deallocate(ptr, layout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
151
src/allocator/linked_list.rs
Normal file
151
src/allocator/linked_list.rs
Normal file
@@ -0,0 +1,151 @@
|
|||||||
|
use super::{Locked, align_up};
|
||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::{mem, ptr};
|
||||||
|
|
||||||
|
struct ListNode {
|
||||||
|
size: usize,
|
||||||
|
next: Option<&'static mut ListNode>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ListNode {
|
||||||
|
const fn new(size: usize) -> Self {
|
||||||
|
ListNode { size, next: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn start_addr(&self) -> usize {
|
||||||
|
self as *const Self as usize
|
||||||
|
}
|
||||||
|
|
||||||
|
fn end_addr(&self) -> usize {
|
||||||
|
self.start_addr() + self.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct LinkedListAllocator {
|
||||||
|
head: ListNode,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LinkedListAllocator {
|
||||||
|
/// Creates an empty LinkedListAllocator.
|
||||||
|
pub const fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
head: ListNode::new(0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Initialize the allocator with the given heap bounds.
|
||||||
|
///
|
||||||
|
/// This function is unsafe because the caller must guarantee that the given
|
||||||
|
/// heap bounds are valid and that the heap is unused. This method must be
|
||||||
|
/// called only once.
|
||||||
|
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
|
||||||
|
unsafe {
|
||||||
|
self.add_free_region(heap_start, heap_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds the given memory region to the front of the list.
|
||||||
|
unsafe fn add_free_region(&mut self, addr: usize, size: usize) {
|
||||||
|
// ensure that the freed region is capable of holding ListNode
|
||||||
|
assert_eq!(align_up(addr, mem::align_of::<ListNode>()), addr);
|
||||||
|
assert!(size >= mem::size_of::<ListNode>());
|
||||||
|
|
||||||
|
// create a new list node and append it at the start of the list
|
||||||
|
let mut node = ListNode::new(size);
|
||||||
|
node.next = self.head.next.take();
|
||||||
|
let node_ptr = addr as *mut ListNode;
|
||||||
|
unsafe {
|
||||||
|
node_ptr.write(node);
|
||||||
|
self.head.next = Some(&mut *node_ptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Looks for a free region with the given size and alignment and removes
|
||||||
|
/// it from the list.
|
||||||
|
///
|
||||||
|
/// Returns a tuple of the list node and the start address of the allocation.
|
||||||
|
fn find_region(&mut self, size: usize, align: usize) -> Option<(&'static mut ListNode, usize)> {
|
||||||
|
// reference to current list node, updated for each iteration
|
||||||
|
let mut current = &mut self.head;
|
||||||
|
// look for a large enough memory region in linked list
|
||||||
|
while let Some(ref mut region) = current.next {
|
||||||
|
if let Ok(alloc_start) = Self::alloc_from_region(®ion, size, align) {
|
||||||
|
// region suitable for allocation -> remove node from list
|
||||||
|
let next = region.next.take();
|
||||||
|
let ret = Some((current.next.take().unwrap(), alloc_start));
|
||||||
|
current.next = next;
|
||||||
|
return ret;
|
||||||
|
} else {
|
||||||
|
// region not suitable -> continue with next region
|
||||||
|
current = current.next.as_mut().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// no suitable region found
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Try to use the given region for an allocation with given size and alignment.
|
||||||
|
///
|
||||||
|
/// Returns the allocation start address on success.
|
||||||
|
fn alloc_from_region(region: &ListNode, size: usize, align: usize) -> Result<usize, ()> {
|
||||||
|
let alloc_start = align_up(region.start_addr(), align);
|
||||||
|
let alloc_end = alloc_start.checked_add(size).ok_or(())?;
|
||||||
|
|
||||||
|
if alloc_end > region.end_addr() {
|
||||||
|
// region too small
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let excess_size = region.end_addr() - alloc_end;
|
||||||
|
if excess_size > 0 && excess_size < mem::size_of::<ListNode>() {
|
||||||
|
// rest of region too small to hold a ListNode (required because the
|
||||||
|
// allocation splits the region in a used and a free part)
|
||||||
|
return Err(());
|
||||||
|
}
|
||||||
|
|
||||||
|
// region suitable for allocation
|
||||||
|
Ok(alloc_start)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adjust the given layout so that the resulting allocated memory
|
||||||
|
/// region is also capable of storing a `ListNode`.
|
||||||
|
///
|
||||||
|
/// Returns the adjusted size and alignment as a (size, align) tuple.
|
||||||
|
fn size_align(layout: Layout) -> (usize, usize) {
|
||||||
|
let layout = layout
|
||||||
|
.align_to(mem::align_of::<ListNode>())
|
||||||
|
.expect("adjusting alignment failed")
|
||||||
|
.pad_to_align();
|
||||||
|
let size = layout.size().max(mem::size_of::<ListNode>());
|
||||||
|
(size, layout.align())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for Locked<LinkedListAllocator> {
|
||||||
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
|
// perform layout adjustments
|
||||||
|
let (size, align) = LinkedListAllocator::size_align(layout);
|
||||||
|
let mut allocator = self.lock();
|
||||||
|
|
||||||
|
if let Some((region, alloc_start)) = allocator.find_region(size, align) {
|
||||||
|
let alloc_end = alloc_start.checked_add(size).expect("overflow");
|
||||||
|
let excess_size = region.end_addr() - alloc_end;
|
||||||
|
if excess_size > 0 {
|
||||||
|
unsafe {
|
||||||
|
allocator.add_free_region(alloc_end, excess_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
alloc_start as *mut u8
|
||||||
|
} else {
|
||||||
|
ptr::null_mut()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
|
||||||
|
// perform layout adjustments
|
||||||
|
let (size, _) = LinkedListAllocator::size_align(layout);
|
||||||
|
|
||||||
|
unsafe { self.lock().add_free_region(ptr as usize, size) }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -80,31 +80,11 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: InterruptStackFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
||||||
use pc_keyboard::{DecodedKey, HandleControl, Keyboard, ScancodeSet1, layouts};
|
|
||||||
use spin::Mutex;
|
|
||||||
use x86_64::instructions::port::Port;
|
use x86_64::instructions::port::Port;
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
|
|
||||||
Mutex::new(Keyboard::new(
|
|
||||||
ScancodeSet1::new(),
|
|
||||||
layouts::Us104Key,
|
|
||||||
HandleControl::Ignore
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut keyboard = KEYBOARD.lock();
|
|
||||||
let mut port = Port::new(0x60);
|
let mut port = Port::new(0x60);
|
||||||
|
|
||||||
let scancode: u8 = unsafe { port.read() };
|
let scancode: u8 = unsafe { port.read() };
|
||||||
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
|
crate::task::keyboard::add_scancode(scancode);
|
||||||
if let Some(key) = keyboard.process_keyevent(key_event) {
|
|
||||||
match key {
|
|
||||||
DecodedKey::Unicode(character) => print!("{}", character),
|
|
||||||
DecodedKey::RawKey(key) => print!("{:?}", key),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
PICS.lock()
|
PICS.lock()
|
||||||
|
|||||||
@@ -5,12 +5,15 @@
|
|||||||
#![test_runner(crate::test_runner)]
|
#![test_runner(crate::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
pub mod allocator;
|
||||||
pub mod gdt;
|
pub mod gdt;
|
||||||
pub mod interrupts;
|
pub mod interrupts;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
pub mod serial;
|
pub mod serial;
|
||||||
|
pub mod task;
|
||||||
pub mod vga_buffer;
|
pub mod vga_buffer;
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
|
|||||||
29
src/main.rs
29
src/main.rs
@@ -4,15 +4,19 @@
|
|||||||
#![test_runner(blog_os::test_runner)]
|
#![test_runner(blog_os::test_runner)]
|
||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
use blog_os::println;
|
use blog_os::println;
|
||||||
|
use blog_os::task::{Task, executor::Executor, keyboard};
|
||||||
use bootloader::{BootInfo, entry_point};
|
use bootloader::{BootInfo, entry_point};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
entry_point!(kernel_main);
|
entry_point!(kernel_main);
|
||||||
|
|
||||||
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
||||||
|
use blog_os::allocator;
|
||||||
use blog_os::memory::{self, BootInfoFrameAllocator};
|
use blog_os::memory::{self, BootInfoFrameAllocator};
|
||||||
use x86_64::{VirtAddr, structures::paging::Page};
|
use x86_64::VirtAddr;
|
||||||
|
|
||||||
println!("Hello World{}", "!");
|
println!("Hello World{}", "!");
|
||||||
blog_os::init();
|
blog_os::init();
|
||||||
@@ -21,19 +25,15 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! {
|
|||||||
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
||||||
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||||
|
|
||||||
// map an unused page
|
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
||||||
let page = Page::containing_address(VirtAddr::new(0xdeadbeaf000));
|
|
||||||
memory::create_example_mapping(page, &mut mapper, &mut frame_allocator);
|
|
||||||
|
|
||||||
// write the string `New!` to the screen through the new mapping
|
|
||||||
let page_ptr: *mut u64 = page.start_address().as_mut_ptr();
|
|
||||||
unsafe { page_ptr.offset(400).write_volatile(0x_f021_f077_f065_f04e) };
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|
||||||
println!("It did not crash!");
|
let mut executor = Executor::new();
|
||||||
blog_os::hlt_loop();
|
executor.spawn(Task::new(example_task()));
|
||||||
|
executor.spawn(Task::new(keyboard::print_keypresses()));
|
||||||
|
executor.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function is called on panic.
|
/// This function is called on panic.
|
||||||
@@ -50,6 +50,15 @@ fn panic(info: &PanicInfo) -> ! {
|
|||||||
blog_os::test_panic_handler(info)
|
blog_os::test_panic_handler(info)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn async_number() -> u32 {
|
||||||
|
42
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn example_task() {
|
||||||
|
let number = async_number().await;
|
||||||
|
println!("async number: {}", number);
|
||||||
|
}
|
||||||
|
|
||||||
#[test_case]
|
#[test_case]
|
||||||
fn trivial_assertion() {
|
fn trivial_assertion() {
|
||||||
assert_eq!(1, 1);
|
assert_eq!(1, 1);
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
|
||||||
use x86_64::{
|
use x86_64::{
|
||||||
PhysAddr, VirtAddr,
|
PhysAddr, VirtAddr,
|
||||||
structures::paging::{
|
structures::paging::{FrameAllocator, OffsetPageTable, PageTable, PhysFrame, Size4KiB},
|
||||||
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Initialize a new OffsetPageTable.
|
/// Initialize a new OffsetPageTable.
|
||||||
@@ -37,24 +35,6 @@ unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut
|
|||||||
unsafe { &mut *page_table_ptr }
|
unsafe { &mut *page_table_ptr }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates an example mapping for the given page to frame `0xb8000`.
|
|
||||||
pub fn create_example_mapping(
|
|
||||||
page: Page,
|
|
||||||
mapper: &mut OffsetPageTable,
|
|
||||||
frame_allocator: &mut impl FrameAllocator<Size4KiB>,
|
|
||||||
) {
|
|
||||||
use x86_64::structures::paging::PageTableFlags as Flags;
|
|
||||||
|
|
||||||
let frame = PhysFrame::containing_address(PhysAddr::new(0xb8000));
|
|
||||||
let flags = Flags::PRESENT | Flags::WRITABLE;
|
|
||||||
|
|
||||||
let map_to_result = unsafe {
|
|
||||||
// FIXME: this is not safe, we do it only for testing
|
|
||||||
mapper.map_to(page, frame, flags, frame_allocator)
|
|
||||||
};
|
|
||||||
map_to_result.expect("map_to failed").flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A FrameAllocator that always returns `None`.
|
/// A FrameAllocator that always returns `None`.
|
||||||
pub struct EmptyFrameAllocator;
|
pub struct EmptyFrameAllocator;
|
||||||
|
|
||||||
|
|||||||
102
src/task/executor.rs
Normal file
102
src/task/executor.rs
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
use super::{Task, TaskId};
|
||||||
|
use alloc::{collections::BTreeMap, sync::Arc, task::Wake};
|
||||||
|
use core::task::{Context, Poll, Waker};
|
||||||
|
use crossbeam_queue::ArrayQueue;
|
||||||
|
|
||||||
|
pub struct Executor {
|
||||||
|
tasks: BTreeMap<TaskId, Task>,
|
||||||
|
task_queue: Arc<ArrayQueue<TaskId>>,
|
||||||
|
waker_cache: BTreeMap<TaskId, Waker>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Executor {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Executor {
|
||||||
|
tasks: BTreeMap::new(),
|
||||||
|
task_queue: Arc::new(ArrayQueue::new(100)),
|
||||||
|
waker_cache: BTreeMap::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn spawn(&mut self, task: Task) {
|
||||||
|
let task_id = task.id;
|
||||||
|
if self.tasks.insert(task.id, task).is_some() {
|
||||||
|
panic!("task with same ID already in tasks");
|
||||||
|
}
|
||||||
|
self.task_queue.push(task_id).expect("queue full");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&mut self) -> ! {
|
||||||
|
loop {
|
||||||
|
self.run_ready_tasks();
|
||||||
|
self.sleep_if_idle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run_ready_tasks(&mut self) {
|
||||||
|
// destructure `self` to avoid borrow checker errors
|
||||||
|
let Self {
|
||||||
|
tasks,
|
||||||
|
task_queue,
|
||||||
|
waker_cache,
|
||||||
|
} = self;
|
||||||
|
|
||||||
|
while let Some(task_id) = task_queue.pop() {
|
||||||
|
let task = match tasks.get_mut(&task_id) {
|
||||||
|
Some(task) => task,
|
||||||
|
None => continue, // task no longer exists
|
||||||
|
};
|
||||||
|
let waker = waker_cache
|
||||||
|
.entry(task_id)
|
||||||
|
.or_insert_with(|| TaskWaker::new(task_id, task_queue.clone()));
|
||||||
|
let mut context = Context::from_waker(waker);
|
||||||
|
match task.poll(&mut context) {
|
||||||
|
Poll::Ready(()) => {
|
||||||
|
// task done -> remove it and its cached waker
|
||||||
|
tasks.remove(&task_id);
|
||||||
|
waker_cache.remove(&task_id);
|
||||||
|
}
|
||||||
|
Poll::Pending => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sleep_if_idle(&self) {
|
||||||
|
use x86_64::instructions::interrupts::{self, enable_and_hlt};
|
||||||
|
|
||||||
|
interrupts::disable();
|
||||||
|
if self.task_queue.is_empty() {
|
||||||
|
enable_and_hlt();
|
||||||
|
} else {
|
||||||
|
interrupts::enable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TaskWaker {
|
||||||
|
task_id: TaskId,
|
||||||
|
task_queue: Arc<ArrayQueue<TaskId>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TaskWaker {
|
||||||
|
fn new(task_id: TaskId, task_queue: Arc<ArrayQueue<TaskId>>) -> Waker {
|
||||||
|
Waker::from(Arc::new(TaskWaker {
|
||||||
|
task_id,
|
||||||
|
task_queue,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wake_task(&self) {
|
||||||
|
self.task_queue.push(self.task_id).expect("task_queue full");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Wake for TaskWaker {
|
||||||
|
fn wake(self: Arc<Self>) {
|
||||||
|
self.wake_task();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn wake_by_ref(self: &Arc<Self>) {
|
||||||
|
self.wake_task();
|
||||||
|
}
|
||||||
|
}
|
||||||
87
src/task/keyboard.rs
Normal file
87
src/task/keyboard.rs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
use crate::{print, println};
|
||||||
|
use conquer_once::spin::OnceCell;
|
||||||
|
use core::{
|
||||||
|
pin::Pin,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
use crossbeam_queue::ArrayQueue;
|
||||||
|
use futures_util::{
|
||||||
|
stream::{Stream, StreamExt},
|
||||||
|
task::AtomicWaker,
|
||||||
|
};
|
||||||
|
use pc_keyboard::{DecodedKey, HandleControl, Keyboard, ScancodeSet1, layouts};
|
||||||
|
|
||||||
|
static SCANCODE_QUEUE: OnceCell<ArrayQueue<u8>> = OnceCell::uninit();
|
||||||
|
static WAKER: AtomicWaker = AtomicWaker::new();
|
||||||
|
|
||||||
|
/// Called by the keyboard interrupt handler
|
||||||
|
///
|
||||||
|
/// Must not block or allocate.
|
||||||
|
pub(crate) fn add_scancode(scancode: u8) {
|
||||||
|
if let Ok(queue) = SCANCODE_QUEUE.try_get() {
|
||||||
|
if let Err(_) = queue.push(scancode) {
|
||||||
|
println!("WARNING: scancode queue full; dropping keyboard input");
|
||||||
|
} else {
|
||||||
|
WAKER.wake();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("WARNING: scancode queue uninitialized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ScancodeStream {
|
||||||
|
_private: (),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScancodeStream {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
SCANCODE_QUEUE
|
||||||
|
.try_init_once(|| ArrayQueue::new(100))
|
||||||
|
.expect("ScancodeStream::new should only be called once");
|
||||||
|
ScancodeStream { _private: () }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Stream for ScancodeStream {
|
||||||
|
type Item = u8;
|
||||||
|
|
||||||
|
fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<u8>> {
|
||||||
|
let queue = SCANCODE_QUEUE
|
||||||
|
.try_get()
|
||||||
|
.expect("scancode queue not initialized");
|
||||||
|
|
||||||
|
// fast path
|
||||||
|
if let Some(scancode) = queue.pop() {
|
||||||
|
return Poll::Ready(Some(scancode));
|
||||||
|
}
|
||||||
|
|
||||||
|
WAKER.register(&cx.waker());
|
||||||
|
match queue.pop() {
|
||||||
|
Some(scancode) => {
|
||||||
|
WAKER.take();
|
||||||
|
Poll::Ready(Some(scancode))
|
||||||
|
}
|
||||||
|
None => Poll::Pending,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn print_keypresses() {
|
||||||
|
let mut scancodes = ScancodeStream::new();
|
||||||
|
let mut keyboard = Keyboard::new(
|
||||||
|
ScancodeSet1::new(),
|
||||||
|
layouts::Us104Key,
|
||||||
|
HandleControl::Ignore,
|
||||||
|
);
|
||||||
|
|
||||||
|
while let Some(scancode) = scancodes.next().await {
|
||||||
|
if let Ok(Some(key_event)) = keyboard.add_byte(scancode) {
|
||||||
|
if let Some(key) = keyboard.process_keyevent(key_event) {
|
||||||
|
match key {
|
||||||
|
DecodedKey::Unicode(character) => print!("{}", character),
|
||||||
|
DecodedKey::RawKey(key) => print!("{:?}", key),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/task/mod.rs
Normal file
39
src/task/mod.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
use alloc::boxed::Box;
|
||||||
|
use core::{
|
||||||
|
future::Future,
|
||||||
|
pin::Pin,
|
||||||
|
sync::atomic::{AtomicU64, Ordering},
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub mod executor;
|
||||||
|
pub mod keyboard;
|
||||||
|
pub mod simple_executor;
|
||||||
|
|
||||||
|
pub struct Task {
|
||||||
|
id: TaskId,
|
||||||
|
future: Pin<Box<dyn Future<Output = ()>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Task {
|
||||||
|
pub fn new(future: impl Future<Output = ()> + 'static) -> Task {
|
||||||
|
Task {
|
||||||
|
id: TaskId::new(),
|
||||||
|
future: Box::pin(future),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn poll(&mut self, context: &mut Context) -> Poll<()> {
|
||||||
|
self.future.as_mut().poll(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
struct TaskId(u64);
|
||||||
|
|
||||||
|
impl TaskId {
|
||||||
|
fn new() -> Self {
|
||||||
|
static NEXT_ID: AtomicU64 = AtomicU64::new(0);
|
||||||
|
TaskId(NEXT_ID.fetch_add(1, Ordering::Relaxed))
|
||||||
|
}
|
||||||
|
}
|
||||||
44
src/task/simple_executor.rs
Normal file
44
src/task/simple_executor.rs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
use super::Task;
|
||||||
|
use alloc::collections::VecDeque;
|
||||||
|
use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
|
||||||
|
|
||||||
|
pub struct SimpleExecutor {
|
||||||
|
task_queue: VecDeque<Task>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SimpleExecutor {
|
||||||
|
pub fn new() -> SimpleExecutor {
|
||||||
|
SimpleExecutor {
|
||||||
|
task_queue: VecDeque::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn spawn(&mut self, task: Task) {
|
||||||
|
self.task_queue.push_back(task)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&mut self) {
|
||||||
|
while let Some(mut task) = self.task_queue.pop_front() {
|
||||||
|
let waker = dummy_waker();
|
||||||
|
let mut context = Context::from_waker(&waker);
|
||||||
|
match task.poll(&mut context) {
|
||||||
|
Poll::Ready(()) => {} // task done
|
||||||
|
Poll::Pending => self.task_queue.push_back(task),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dummy_raw_waker() -> RawWaker {
|
||||||
|
fn no_op(_: *const ()) {}
|
||||||
|
fn clone(_: *const ()) -> RawWaker {
|
||||||
|
dummy_raw_waker()
|
||||||
|
}
|
||||||
|
|
||||||
|
let vtable = &RawWakerVTable::new(clone, no_op, no_op, no_op);
|
||||||
|
RawWaker::new(0 as *const (), vtable)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dummy_waker() -> Waker {
|
||||||
|
unsafe { Waker::from_raw(dummy_raw_waker()) }
|
||||||
|
}
|
||||||
70
tests/heap_allocation.rs
Normal file
70
tests/heap_allocation.rs
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
#![feature(custom_test_frameworks)]
|
||||||
|
#![test_runner(blog_os::test_runner)]
|
||||||
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
use alloc::{boxed::Box, vec::Vec};
|
||||||
|
use blog_os::allocator::HEAP_SIZE;
|
||||||
|
use bootloader::{BootInfo, entry_point};
|
||||||
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
entry_point!(main);
|
||||||
|
|
||||||
|
fn main(boot_info: &'static BootInfo) -> ! {
|
||||||
|
use blog_os::allocator;
|
||||||
|
use blog_os::memory::{self, BootInfoFrameAllocator};
|
||||||
|
use x86_64::VirtAddr;
|
||||||
|
|
||||||
|
blog_os::init();
|
||||||
|
let phys_mem_offset = VirtAddr::new(boot_info.physical_memory_offset);
|
||||||
|
let mut mapper = unsafe { memory::init(phys_mem_offset) };
|
||||||
|
let mut frame_allocator = unsafe { BootInfoFrameAllocator::init(&boot_info.memory_map) };
|
||||||
|
allocator::init_heap(&mut mapper, &mut frame_allocator).expect("heap initialization failed");
|
||||||
|
|
||||||
|
test_main();
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn simple_allocation() {
|
||||||
|
let heap_value_1 = Box::new(41);
|
||||||
|
let heap_value_2 = Box::new(13);
|
||||||
|
assert_eq!(*heap_value_1, 41);
|
||||||
|
assert_eq!(*heap_value_2, 13);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn large_vec() {
|
||||||
|
let n = 1000;
|
||||||
|
let mut vec = Vec::new();
|
||||||
|
for i in 0..n {
|
||||||
|
vec.push(i);
|
||||||
|
}
|
||||||
|
assert_eq!(vec.iter().sum::<u64>(), (n - 1) * n / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn many_boxes() {
|
||||||
|
for i in 0..HEAP_SIZE {
|
||||||
|
let x = Box::new(i);
|
||||||
|
assert_eq!(*x, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn many_boxes_long_lived() {
|
||||||
|
let long_lived = Box::new(1); // new
|
||||||
|
for i in 0..HEAP_SIZE {
|
||||||
|
let x = Box::new(i);
|
||||||
|
assert_eq!(*x, i);
|
||||||
|
}
|
||||||
|
assert_eq!(*long_lived, 1); // new
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user