Compare commits

...

184 Commits

Author SHA1 Message Date
Philipp Oppermann
cb66922dfa Merge branch 'post-08' into post-09 2025-09-03 17:58:33 +02:00
Philipp Oppermann
43f767cfa4 Merge branch 'post-07' into post-08 2025-09-03 17:58:33 +02:00
Philipp Oppermann
e12866e19b Merge branch 'post-06' into post-07 2025-09-03 17:58:33 +02:00
Philipp Oppermann
18ec73ebf0 Merge branch 'post-05' into post-06 2025-09-03 17:58:33 +02:00
Philipp Oppermann
d788a21b40 Merge branch 'post-04' into post-05 2025-09-03 17:58:33 +02:00
Philipp Oppermann
bb5899e437 Merge branch 'post-03' into post-04 2025-09-03 17:58:33 +02:00
Philipp Oppermann
93d0daa1e0 Merge branch 'post-02' into post-03 2025-09-03 17:58:28 +02:00
Philipp Oppermann
83e6c0bc00 Merge pull request #1436 from phil-opp/post-02-fix-target
Fix: `target-pointer-width` field now expects an integer
2025-09-03 17:56:38 +02:00
Philipp Oppermann
2b11ad8397 Fix: target-pointer-width field now expects an integer 2025-09-03 17:53:14 +02:00
Philipp Oppermann
fa51f3adbf Update to latest bootloader version 2025-09-03 17:52:56 +02:00
Philipp Oppermann
9e2562c7c8 Merge branch 'post-08' into post-09 2025-08-26 16:41:45 +02:00
Philipp Oppermann
be2b2db06d Merge branch 'post-08' into post-09 2025-08-18 09:47:01 +02:00
Philipp Oppermann
4f48a36887 Merge branch 'post-08' into post-09 2025-08-07 13:09:45 +02:00
Philipp Oppermann
99432ab712 Merge branch 'post-08' into post-09 2025-08-07 13:08:03 +02:00
Philipp Oppermann
27b56832c1 Merge branch 'post-08' into post-09 2025-03-27 16:13:38 +01:00
Philipp Oppermann
a7c5741ab5 Merge branch 'post-08' into post-09 2025-03-27 16:13:24 +01:00
Philipp Oppermann
2049f23abb Merge branch 'post-08' into post-09 2025-03-27 15:51:38 +01:00
Philipp Oppermann
3a988748de Unsafe operations in unsafe functions require an unsafe block since Rust 2024 2025-03-27 15:21:52 +01:00
Philipp Oppermann
889ceba24a Merge branch 'post-08' into post-09 2025-03-27 15:14:37 +01:00
Philipp Oppermann
bb2c57e1b4 Merge branch 'post-08' into post-09 2025-03-24 11:09:24 +01:00
Philipp Oppermann
ba7b36aa21 Merge branch 'post-08' into post-09 2025-02-10 12:36:07 +01:00
Philipp Oppermann
28c9558a7a Merge branch 'post-08' into post-09 2025-02-10 11:16:22 +01:00
Philipp Oppermann
bb3beb22da Merge branch 'post-08' into post-09 2025-01-15 19:58:30 +01:00
Philipp Oppermann
2870ac4e13 Merge branch 'post-08' into post-09 2024-05-30 10:59:56 +02:00
Philipp Oppermann
c250dd0a91 Merge branch 'post-08' into post-09 2024-04-30 15:39:16 +02:00
Philipp Oppermann
2fdc7c3b5c Merge branch 'post-08' into post-09 2024-02-16 15:59:40 +01:00
Philipp Oppermann
be58db8907 Merge branch 'post-08' into post-09 2024-02-16 13:22:33 +01:00
Philipp Oppermann
b654651a85 Merge branch 'post-08' into post-09 2024-02-16 13:14:09 +01:00
Philipp Oppermann
bf7cf4c65d Merge branch 'post-08' into post-09 2024-02-16 12:39:56 +01:00
Philipp Oppermann
4343f9be6a Merge branch 'post-08' into post-09 2024-01-28 11:45:38 +01:00
Philipp Oppermann
b6437c5cc1 Merge branch 'post-08' into post-09 2022-09-25 11:32:07 +02:00
Philipp Oppermann
ee550a64e0 Merge branch 'post-08' into post-09 2022-04-08 10:07:31 +02:00
Philipp Oppermann
a249900aed Merge branch 'post-08' into post-09 2022-01-18 10:06:44 +01:00
Philipp Oppermann
e56cd71689 Merge branch 'post-08' into post-09 2021-12-22 09:27:53 +01:00
Philipp Oppermann
17e1ae2508 Merge branch 'post-08' into post-09 2021-12-21 13:56:10 +01:00
Philipp Oppermann
f345162ee5 Merge branch 'post-08' into post-09 2021-08-22 14:44:44 +02:00
Philipp Oppermann
01f42c65e8 Merge branch 'post-08' into post-09
# Conflicts:
#	README.md
2021-05-21 19:57:31 +02:00
Philipp Oppermann
3c1db5e79f Merge branch 'post-08' into post-09 2021-05-20 14:33:10 +02:00
Philipp Oppermann
0e1efb591c Merge branch 'post-08' into post-09 2021-05-17 12:47:38 +02:00
Philipp Oppermann
6c161ff3e0 Merge branch 'post-08' into post-09 2021-05-17 12:45:11 +02:00
Philipp Oppermann
66d0d5d11c Merge branch 'post-08' into post-09 2021-05-17 11:47:14 +02:00
Philipp Oppermann
b5d4b9b212 Merge branch 'post-08' into post-09 2021-05-17 11:44:50 +02:00
Philipp Oppermann
3c2b79b1f0 Merge branch 'post-08' into post-09 2021-05-17 11:41:30 +02:00
Philipp Oppermann
8f20817ea3 Merge branch 'post-08' into post-09 2021-05-17 11:30:02 +02:00
Philipp Oppermann
d21dbc7c58 Merge branch 'post-08' into post-09 2021-05-17 11:29:23 +02:00
Philipp Oppermann
3532a12264 Merge branch 'post-08' into post-09 2021-03-10 09:23:02 +01:00
Philipp Oppermann
4bcfdf4b03 Merge branch 'post-08' into post-09 2021-03-10 09:15:58 +01:00
Philipp Oppermann
c79bf064c8 Merge branch 'post-08' into post-09 2021-03-10 09:13:39 +01:00
Philipp Oppermann
71a70a3b95 Merge branch 'post-08' into post-09 2021-03-10 08:53:42 +01:00
Philipp Oppermann
722c5579de Merge branch 'post-08' into post-09 2021-02-02 11:06:38 +01:00
Philipp Oppermann
31d3eef0da Merge branch 'post-08' into post-09 2021-02-02 10:52:06 +01:00
Philipp Oppermann
ce20cc8661 Merge branch 'post-08' into post-09 2020-11-22 13:46:58 +01:00
Philipp Oppermann
93844bee41 Merge branch 'post-08' into post-09 2020-10-02 23:36:43 +02:00
Philipp Oppermann
92238b15b0 Merge branch 'post-08' into post-09 2020-09-29 12:22:06 +02:00
Philipp Oppermann
624596adf1 Merge branch 'post-08' into post-09 2020-09-29 12:19:54 +02:00
Philipp Oppermann
ff72429a55 Merge branch 'post-08' into post-09 2020-09-24 10:28:11 +02:00
Philipp Oppermann
df3a464cec Merge branch 'post-08' into post-09 2020-09-24 09:10:19 +02:00
Philipp Oppermann
c2ef594a78 Merge branch 'post-08' into post-09 2020-08-16 18:03:09 +02:00
Philipp Oppermann
d2e7a4a970 Merge branch 'post-08' into post-09 2020-08-16 17:59:56 +02:00
Philipp Oppermann
6bbaf9de16 Merge branch 'post-08' into post-09 2020-07-17 15:57:35 +02:00
Philipp Oppermann
4cec056568 Merge branch 'post-08' into post-09 2020-07-17 11:48:35 +02:00
Philipp Oppermann
b7835f3976 Merge branch 'post-08' into post-09 2020-07-17 11:28:04 +02:00
Philipp Oppermann
472ddcc696 Merge branch 'post-08' into post-09 2020-07-17 11:25:03 +02:00
Philipp Oppermann
832ab43bdd Merge branch 'post-08' into post-09 2020-06-08 12:30:28 +02:00
Philipp Oppermann
cecab1a310 Merge branch 'post-08' into post-09 2020-06-08 12:06:37 +02:00
Philipp Oppermann
8b90c04c62 Merge branch 'post-08' into post-09 2020-05-21 09:29:56 +02:00
Philipp Oppermann
5e510e41ee Merge branch 'post-08' into post-09 2020-05-20 14:56:19 +02:00
Philipp Oppermann
491889a237 Update paging code for x86_64 v0.11.0 2020-05-20 14:29:36 +02:00
Philipp Oppermann
a2f07828e4 Merge branch 'post-08' into post-09 2020-05-20 14:27:06 +02:00
Philipp Oppermann
d94b9513e7 Merge branch 'post-08' into post-09 2020-05-20 14:08:32 +02:00
Philipp Oppermann
70deb3168e Merge branch 'post-08' into post-09 2020-03-08 14:39:38 +01:00
Philipp Oppermann
a5d409b777 Merge branch 'post-08' into post-09 2020-03-08 14:28:03 +01:00
Philipp Oppermann
79a0172ace Merge branch 'post-08' into post-09 2020-02-26 12:47:32 +01:00
Philipp Oppermann
8fc746555d Merge branch 'post-08' into post-09 2020-02-26 12:21:28 +01:00
Philipp Oppermann
ed3af8e984 Update Github Actions badge for post-09 2019-12-12 09:32:30 +01:00
Philipp Oppermann
1d1075b35e Merge branch 'post-08' into post-09 2019-12-12 09:32:16 +01:00
Philipp Oppermann
8eb44dcbd5 Merge branch 'post-08' into post-09 2019-12-12 09:23:31 +01:00
Philipp Oppermann
f392d8a7f5 Merge pull request #703 from phil-opp/post-09-fix
Update frame allocation code to x86_64 0.8.1
2019-12-11 16:37:49 +01:00
Philipp Oppermann
c7bc26d8ee Update frame allocation code to x86_64 0.8.1 2019-12-11 16:26:38 +01:00
Philipp Oppermann
6c1594ea24 Merge branch 'post-08' into post-09 2019-12-10 17:31:24 +01:00
Philipp Oppermann
94aa2c4093 Merge branch 'post-08' into post-09 2019-12-10 17:17:53 +01:00
Philipp Oppermann
259742a5e3 Merge branch 'post-08' into post-09 2019-12-10 16:55:41 +01:00
Philipp Oppermann
6876e82fc5 Merge branch 'post-08' into post-09 2019-11-28 14:07:43 +01:00
Philipp Oppermann
84ddda6a3f Merge branch 'post-08' into post-09 2019-11-25 13:35:20 +01:00
Philipp Oppermann
f85664fd6b Merge branch 'post-08' into post-09 2019-11-25 13:25:15 +01:00
Philipp Oppermann
a65573b061 Merge branch 'post-08' into post-09 2019-11-22 16:33:23 +01:00
Philipp Oppermann
385004cab2 Merge branch 'post-08' into post-09 2019-11-22 16:05:13 +01:00
Philipp Oppermann
9696612b2b Merge branch 'post-08' into post-09 2019-11-22 15:57:18 +01:00
Philipp Oppermann
d5d7db0de6 Merge branch 'post-08' into post-09 2019-10-08 19:44:38 +02:00
Philipp Oppermann
45375d1f1b Merge branch 'post-08' into post-09 2019-09-25 13:21:06 +02:00
Philipp Oppermann
4897e9c4d5 Merge pull request #667 from phil-opp/post-09-offset_page_table
Update post-09 branch for improved Paging Implementation Post
2019-09-14 19:04:53 +02:00
Philipp Oppermann
5cced71fb0 Directly use OffsetPageTable for create_example_mapping instead of impl trait 2019-09-14 18:33:37 +02:00
Philipp Oppermann
7ec727f69f Update comment 2019-09-14 18:33:16 +02:00
Philipp Oppermann
8059c229c5 Merge branch 'post-08' into post-09 2019-09-13 17:43:25 +02:00
Philipp Oppermann
bc2099d31d Merge branch 'post-08' into post-09 2019-09-13 10:53:50 +02:00
Philipp Oppermann
211ec3898b Use OffsetPageTable instead of MappedPageTable 2019-09-11 13:40:36 +02:00
Philipp Oppermann
2227fa434f Merge branch 'post-08' into post-09 2019-09-11 13:29:14 +02:00
Philipp Oppermann
23d554548a Merge branch 'post-08' into post-09 2019-09-11 11:21:15 +02:00
Philipp Oppermann
091f7ef153 Merge branch 'post-08' into post-09 2019-09-11 10:58:56 +02:00
Philipp Oppermann
38d606b4d1 Merge branch 'post-08' into post-09 2019-09-11 10:32:57 +02:00
Philipp Oppermann
ae75d8b209 Merge branch 'post-08' into post-09 2019-09-11 10:12:46 +02:00
Philipp Oppermann
e0d5cdd625 Merge branch 'post-08' into post-09 2019-09-11 10:11:25 +02:00
Philipp Oppermann
3f95494ae8 Merge branch 'post-08' into post-09 2019-09-11 10:02:41 +02:00
Philipp Oppermann
cabbbec72f Merge branch 'post-08' into post-09 2019-09-10 11:12:54 +02:00
Philipp Oppermann
1dd7f03a7a Merge branch 'post-08' into post-09 2019-09-10 10:21:14 +02:00
Philipp Oppermann
66c4eae9cf Merge branch 'post-08' into post-09 2019-08-07 12:40:04 +02:00
Philipp Oppermann
e721878e4b Merge branch 'post-08' into post-09 2019-07-22 10:46:35 +02:00
Philipp Oppermann
f2eb6cec9a Merge branch 'post-08' into post-09 2019-07-22 10:36:51 +02:00
Philipp Oppermann
bc4ddcef05 Merge branch 'post-08' into post-09 2019-07-18 10:17:37 +02:00
Philipp Oppermann
4580b85fe2 Use correct build badge in post-09 Readme 2019-07-07 11:25:40 +02:00
Philipp Oppermann
45e1e99390 Merge branch 'post-08' into post-09 2019-06-23 18:07:34 +02:00
Philipp Oppermann
b5793c34c6 Merge branch 'post-08' into post-09 2019-06-17 17:28:32 +02:00
Philipp Oppermann
67ee45090d Merge branch 'post-08' into post-09 2019-05-23 12:39:35 +02:00
Philipp Oppermann
64d1a587e7 Merge branch 'post-08' into post-09 2019-05-09 15:38:47 +02:00
Philipp Oppermann
fbe279831e Merge branch 'post-08' into post-09 2019-05-09 14:59:55 +02:00
Philipp Oppermann
375d4d0479 Merge pull request #599 from phil-opp/post-09-new
Update `post-09` branch for version 0.6.0 of `x86_64` crate
2019-05-03 19:41:29 +02:00
Philipp Oppermann
7796d4c14a FrameAllocator is an unsafe trait now
Make `BootInfoFrameAllocator` unsafe because the caller must guarantee that the given memory map is valid.
2019-05-03 19:29:14 +02:00
Philipp Oppermann
78e4b22a2f Merge branch 'post-08' into post-09 2019-05-03 18:36:45 +02:00
Philipp Oppermann
a867450e3b Merge pull request #595 from phil-opp/redesign-frame-allocator
Avoid generic impl trait parameters in BootInfoFrameAllocator
2019-04-30 13:24:43 +02:00
Philipp Oppermann
b5ee44621c Use an import for initializing BootInfoFrameAllocator 2019-04-30 13:10:53 +02:00
Philipp Oppermann
24a9e7abd2 Simplify FrameAllocator implementation using Iterator::nth 2019-04-30 12:47:45 +02:00
Philipp Oppermann
180c77d1f4 Avoid generic impl trait parameters in BootInfoFrameAllocator 2019-04-30 11:14:23 +02:00
Philipp Oppermann
247af45791 Merge branch 'post-08-new' into post-09-new 2019-04-26 15:50:18 +02:00
Philipp Oppermann
fd0646fecf Improve formatting 2019-04-26 15:29:43 +02:00
Philipp Oppermann
c8821cb226 Use entry_point macro in lib.rs too 2019-04-26 15:29:43 +02:00
Philipp Oppermann
2e531850b8 Remove redundant import 2019-04-26 15:29:43 +02:00
Philipp Oppermann
65dbb5ac48 Merge branch 'post-08-new' into post-09-new 2019-04-26 15:28:56 +02:00
Philipp Oppermann
16cf7e8e42 Merge branch 'post-09' into post-10 2019-04-25 11:08:11 +02:00
Philipp Oppermann
19556d9e68 Merge branch 'post-09' into post-10 2019-04-11 15:32:21 +02:00
Philipp Oppermann
338833262c Merge branch 'post-09' into post-10 2019-04-06 17:35:17 +02:00
Philipp Oppermann
77800d9212 Merge branch 'post-09' into post-10 2019-04-06 17:33:49 +02:00
Philipp Oppermann
be618df7f5 Merge branch 'post-09' into post-10 2019-04-06 16:49:18 +02:00
Philipp Oppermann
ff85a2e502 Merge branch 'post-09' into post-10
# Conflicts:
#	README.md
2019-04-03 10:47:15 +02:00
Philipp Oppermann
74675346c9 Merge branch 'post-09' into post-10 2019-03-26 13:26:56 +01:00
Philipp Oppermann
e9344ae046 Remove unneeded into_iter() in init_frame_allocator 2019-03-14 13:20:26 +01:00
Philipp Oppermann
4acf12bb69 Merge branch 'post-09' into post-10 2019-03-14 11:18:40 +01:00
Philipp Oppermann
161d5fe7be Merge pull request #569 from phil-opp/post-10-new
Update post-10 branch for new "Paging Implementation" post
2019-03-14 10:49:55 +01:00
Philipp Oppermann
9bf4ea7341 Use BootInfoFrameAllocator to create a 0xdeadbeaf000 mapping 2019-03-14 10:30:37 +01:00
Philipp Oppermann
a1bf5651fc Create an init_frame_allocator function 2019-03-14 10:30:37 +01:00
Philipp Oppermann
763228c859 Create a generic BootInfoFrameAllocator type 2019-03-14 10:30:37 +01:00
Philipp Oppermann
770af27d75 Create a new mapping and write through it to the screen 2019-03-14 10:30:37 +01:00
Philipp Oppermann
3e59283c19 Create an EmptyFrameAllocator 2019-03-14 10:30:37 +01:00
Philipp Oppermann
6146ccba2d Add a memory::create_example_mapping function 2019-03-14 10:30:37 +01:00
Philipp Oppermann
b0e1527a95 Delete our memory::translate_addr function again 2019-03-14 10:30:37 +01:00
Philipp Oppermann
cb4410c84e Update kernel_main to use MapperAllSizes::translate_addr 2019-03-14 10:30:37 +01:00
Philipp Oppermann
98b5976656 Create a memory::init function that initializes a MappedPageTable 2019-03-14 10:30:37 +01:00
Philipp Oppermann
9335386928 Add and test a memory::translate_addr function 2019-03-14 10:30:37 +01:00
Philipp Oppermann
7c30d62f33 Also show non-empty level 3 table entries 2019-03-14 10:30:37 +01:00
Philipp Oppermann
61683bccda Print non-empty level 4 table entries 2019-03-14 10:30:37 +01:00
Philipp Oppermann
e1ec5159b8 Add boot info argument and use entry_point macro 2019-03-14 10:30:37 +01:00
Philipp Oppermann
7b7d19592f Enable map_physical_memory feature of bootloader 2019-03-14 10:30:37 +01:00
Philipp Oppermann
e387c0b6b8 Create a memory::active_level_4_table function 2019-03-14 10:30:37 +01:00
Philipp Oppermann
d5abc119f3 Update Readme for Paging Implementation post 2019-03-14 10:30:37 +01:00
Philipp Oppermann
59da6e5620 Update bootloader to version 0.4.0 2019-03-14 10:30:37 +01:00
Philipp Oppermann
ef1cc0ed4f Reset code to post-09 branch for new 'Paging Implementation' post 2019-03-14 10:20:46 +01:00
Philipp Oppermann
90f0caec1a Merge branch 'post-09' into post-10 2019-03-14 10:17:37 +01:00
Philipp Oppermann
5c0fb63f33 Merge branch 'post-09' into post-10 2019-03-12 17:48:43 +01:00
Philipp Oppermann
036a8e7608 Merge branch 'post-09' into post-10 2019-03-09 14:21:12 +01:00
Philipp Oppermann
10c4d0509d Update post-10 code for changes in x86_64 0.5.0
We no longer need a custom translate function as we can directly use MapperAllSizes::translate_addr.
2019-03-09 12:40:27 +01:00
Philipp Oppermann
57998ea4f8 Merge branch 'post-09' into post-10 2019-03-09 12:39:25 +01:00
Philipp Oppermann
ef9a629ddc Merge branch 'post-09' into post-10 2019-02-25 17:04:56 +01:00
Philipp Oppermann
d974cf5200 Merge branch 'post-09' into post-10 2019-02-25 16:37:31 +01:00
Philipp Oppermann
36d6c6d0e9 Merge branch 'post-09' into post-10 2019-02-12 19:31:09 +01:00
Philipp Oppermann
ff49104764 Merge branch 'post-09' into post-10 2019-02-07 18:48:39 +01:00
Philipp Oppermann
03e43da9f9 Merge branch 'post-09' into post-10 2019-02-07 16:17:54 +01:00
Philipp Oppermann
e696d65b60 Merge branch 'post-09' into post-10 2019-02-05 15:23:49 +01:00
Philipp Oppermann
ebf626061f Merge branch 'post-09' into post-10 2019-02-05 14:59:15 +01:00
Philipp Oppermann
c3d023ad40 Merge branch 'post-09' into post-10 2019-02-05 10:46:08 +01:00
Philipp Oppermann
0a10b3e784 Merge branch 'post-09' into post-10 2019-02-05 10:45:12 +01:00
Philipp Oppermann
e0f66a8196 Merge branch 'post-09' into post-10 2019-01-29 12:16:54 +01:00
Philipp Oppermann
e5dfbd4b23 Merge branch 'post-09' into post-10 2019-01-28 11:51:35 +01:00
Philipp Oppermann
5ad2962389 Merge branch 'post-09' into post-10 2019-01-28 11:44:14 +01:00
Philipp Oppermann
a56e22b6fc Use BootInfoFrameAllocator instead of EmptyFrameAllocator 2019-01-28 11:30:27 +01:00
Philipp Oppermann
67f536d7c6 Add a BootInfoFrameAllocator 2019-01-28 11:28:51 +01:00
Philipp Oppermann
741224411b Use the BootInfo struct passed by the bootloader 2019-01-28 11:24:16 +01:00
Philipp Oppermann
818417d119 Try to create example mapping for page 0xdeadbeaf000 2019-01-28 11:23:46 +01:00
Philipp Oppermann
f272785861 Create example mapping for page 0x1000 2019-01-28 11:19:46 +01:00
Philipp Oppermann
5d807ee622 Run rustfmt 2019-01-28 11:19:34 +01:00
Philipp Oppermann
90c3cdf0f3 Update Readme for Advanced Paging post 2019-01-27 17:14:58 +01:00
Philipp Oppermann
2bc233b2f6 Merge branch 'post-09' into post-10 2019-01-27 17:14:12 +01:00
Philipp Oppermann
051b23f577 Merge branch 'post-09' into post-10 2019-01-27 16:33:54 +01:00
Philipp Oppermann
f2bc2d33f0 Rewrite translation function on top of RecursivePageTable 2019-01-27 14:38:49 +01:00
Philipp Oppermann
38a121a887 Test translate_addr by translating some virtual addresses 2019-01-27 14:38:49 +01:00
Philipp Oppermann
8b380f0692 Create a new memory module with a translate_addr function 2019-01-27 14:38:49 +01:00
7 changed files with 140 additions and 19 deletions

4
Cargo.lock generated
View File

@@ -36,9 +36,9 @@ dependencies = [
[[package]]
name = "bootloader"
version = "0.9.32"
version = "0.9.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea119c3ed05625c179e09d17d0914570a3753ca09c890a73d98f6b72aea00d2"
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
[[package]]
name = "lazy_static"

View File

@@ -13,7 +13,7 @@ name = "stack_overflow"
harness = false
[dependencies]
bootloader = "0.9"
bootloader = { version = "0.9", features = ["map_physical_memory"] }
volatile = "0.2.6"
spin = "0.5.2"
x86_64 = "0.14.2"

View File

@@ -1,10 +1,10 @@
# Blog OS (Introduction to Paging)
# Blog OS (Paging Implementation)
[![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-08)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-08)
[![Build Status](https://github.com/phil-opp/blog_os/workflows/Code/badge.svg?branch=post-09)](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-09)
This repository contains the source code for the [Introduction to Paging][post] post of the [Writing an OS in Rust](https://os.phil-opp.com) series.
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.
[post]: https://os.phil-opp.com/paging-introduction/
[post]: https://os.phil-opp.com/paging-implementation/
**Check out the [master branch](https://github.com/phil-opp/blog_os) for more information.**

View File

@@ -9,6 +9,7 @@ use core::panic::PanicInfo;
pub mod gdt;
pub mod interrupts;
pub mod memory;
pub mod serial;
pub mod vga_buffer;
@@ -70,10 +71,15 @@ pub fn hlt_loop() -> ! {
}
}
#[cfg(test)]
use bootloader::{BootInfo, entry_point};
#[cfg(test)]
entry_point!(test_kernel_main);
/// Entry point for `cargo xtest`
#[cfg(test)]
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
fn test_kernel_main(_boot_info: &'static BootInfo) -> ! {
init();
test_main();
hlt_loop();

View File

@@ -5,20 +5,29 @@
#![reexport_test_harness_main = "test_main"]
use blog_os::println;
use bootloader::{BootInfo, entry_point};
use core::panic::PanicInfo;
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
use x86_64::registers::control::Cr3;
println!("Hello World{}", "!");
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! {
use blog_os::memory::{self, BootInfoFrameAllocator};
use x86_64::{VirtAddr, structures::paging::Page};
println!("Hello World{}", "!");
blog_os::init();
let (level_4_page_table, _) = Cr3::read();
println!(
"Level 4 page table at: {:?}",
level_4_page_table.start_address()
);
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) };
// map an unused page
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)]
test_main();

106
src/memory.rs Normal file
View File

@@ -0,0 +1,106 @@
use bootloader::bootinfo::{MemoryMap, MemoryRegionType};
use x86_64::{
PhysAddr, VirtAddr,
structures::paging::{
FrameAllocator, Mapper, OffsetPageTable, Page, PageTable, PhysFrame, Size4KiB,
},
};
/// Initialize a new OffsetPageTable.
///
/// This function is unsafe because the caller must guarantee that the
/// complete physical memory is mapped to virtual memory at the passed
/// `physical_memory_offset`. Also, this function must be only called once
/// to avoid aliasing `&mut` references (which is undefined behavior).
pub unsafe fn init(physical_memory_offset: VirtAddr) -> OffsetPageTable<'static> {
unsafe {
let level_4_table = active_level_4_table(physical_memory_offset);
OffsetPageTable::new(level_4_table, physical_memory_offset)
}
}
/// Returns a mutable reference to the active level 4 table.
///
/// This function is unsafe because the caller must guarantee that the
/// complete physical memory is mapped to virtual memory at the passed
/// `physical_memory_offset`. Also, this function must be only called once
/// to avoid aliasing `&mut` references (which is undefined behavior).
unsafe fn active_level_4_table(physical_memory_offset: VirtAddr) -> &'static mut PageTable {
use x86_64::registers::control::Cr3;
let (level_4_table_frame, _) = Cr3::read();
let phys = level_4_table_frame.start_address();
let virt = physical_memory_offset + phys.as_u64();
let page_table_ptr: *mut PageTable = virt.as_mut_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`.
pub struct EmptyFrameAllocator;
unsafe impl FrameAllocator<Size4KiB> for EmptyFrameAllocator {
fn allocate_frame(&mut self) -> Option<PhysFrame> {
None
}
}
/// A FrameAllocator that returns usable frames from the bootloader's memory map.
pub struct BootInfoFrameAllocator {
memory_map: &'static MemoryMap,
next: usize,
}
impl BootInfoFrameAllocator {
/// Create a FrameAllocator from the passed memory map.
///
/// This function is unsafe because the caller must guarantee that the passed
/// memory map is valid. The main requirement is that all frames that are marked
/// as `USABLE` in it are really unused.
pub unsafe fn init(memory_map: &'static MemoryMap) -> Self {
BootInfoFrameAllocator {
memory_map,
next: 0,
}
}
/// Returns an iterator over the usable frames specified in the memory map.
fn usable_frames(&self) -> impl Iterator<Item = PhysFrame> {
// get usable regions from memory map
let regions = self.memory_map.iter();
let usable_regions = regions.filter(|r| r.region_type == MemoryRegionType::Usable);
// map each region to its address range
let addr_ranges = usable_regions.map(|r| r.range.start_addr()..r.range.end_addr());
// transform to an iterator of frame start addresses
let frame_addresses = addr_ranges.flat_map(|r| r.step_by(4096));
// create `PhysFrame` types from the start addresses
frame_addresses.map(|addr| PhysFrame::containing_address(PhysAddr::new(addr)))
}
}
unsafe impl FrameAllocator<Size4KiB> for BootInfoFrameAllocator {
fn allocate_frame(&mut self) -> Option<PhysFrame> {
let frame = self.usable_frames().nth(self.next);
self.next += 1;
frame
}
}

View File

@@ -3,7 +3,7 @@
"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",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": "64",
"target-pointer-width": 64,
"target-c-int-width": 32,
"os": "none",
"executables": true,