mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Compare commits
217 Commits
48dfc6d027
...
post-09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb66922dfa | ||
|
|
43f767cfa4 | ||
|
|
e12866e19b | ||
|
|
18ec73ebf0 | ||
|
|
d788a21b40 | ||
|
|
bb5899e437 | ||
|
|
93d0daa1e0 | ||
|
|
83e6c0bc00 | ||
|
|
2b11ad8397 | ||
|
|
fa51f3adbf | ||
|
|
9e2562c7c8 | ||
|
|
53cec5e822 | ||
|
|
8002474616 | ||
|
|
aaaa58d1ab | ||
|
|
0b61e748fb | ||
|
|
ceb91f955a | ||
|
|
3340babf51 | ||
|
|
be2b2db06d | ||
|
|
45122f09c9 | ||
|
|
8c7e0127db | ||
|
|
28b6a96eed | ||
|
|
86352f9b8f | ||
|
|
a862287880 | ||
|
|
37a0ae0097 | ||
|
|
6fc9fbfb7d | ||
|
|
1f097bba71 | ||
|
|
99fbbad9b0 | ||
|
|
94d14d8d62 | ||
|
|
4f48a36887 | ||
|
|
f090d8b01b | ||
|
|
2f06d875da | ||
|
|
f4c35f7091 | ||
|
|
d46aef945f | ||
|
|
ebfc7c5f7e | ||
|
|
6f0be666f3 | ||
|
|
d9fa84edd6 | ||
|
|
99432ab712 | ||
|
|
0eb93f9325 | ||
|
|
f8c6732c88 | ||
|
|
41f4b88041 | ||
|
|
e24e33f6ff | ||
|
|
d1bf96108a | ||
|
|
97de98df33 | ||
|
|
9684f75819 | ||
|
|
d6cc562907 | ||
|
|
b44d8ab7fc | ||
|
|
c551fec1ce | ||
|
|
27b56832c1 | ||
|
|
a7c5741ab5 | ||
|
|
2049f23abb | ||
|
|
3a988748de | ||
|
|
889ceba24a | ||
|
|
bb2c57e1b4 | ||
|
|
ba7b36aa21 | ||
|
|
28c9558a7a | ||
|
|
bb3beb22da | ||
|
|
2870ac4e13 | ||
|
|
c250dd0a91 | ||
|
|
2fdc7c3b5c | ||
|
|
be58db8907 | ||
|
|
b654651a85 | ||
|
|
bf7cf4c65d | ||
|
|
4343f9be6a | ||
|
|
b6437c5cc1 | ||
|
|
ee550a64e0 | ||
|
|
a249900aed | ||
|
|
e56cd71689 | ||
|
|
17e1ae2508 | ||
|
|
f345162ee5 | ||
|
|
01f42c65e8 | ||
|
|
3c1db5e79f | ||
|
|
0e1efb591c | ||
|
|
6c161ff3e0 | ||
|
|
66d0d5d11c | ||
|
|
b5d4b9b212 | ||
|
|
3c2b79b1f0 | ||
|
|
8f20817ea3 | ||
|
|
d21dbc7c58 | ||
|
|
3532a12264 | ||
|
|
4bcfdf4b03 | ||
|
|
c79bf064c8 | ||
|
|
71a70a3b95 | ||
|
|
722c5579de | ||
|
|
31d3eef0da | ||
|
|
ce20cc8661 | ||
|
|
93844bee41 | ||
|
|
92238b15b0 | ||
|
|
624596adf1 | ||
|
|
ff72429a55 | ||
|
|
df3a464cec | ||
|
|
c2ef594a78 | ||
|
|
d2e7a4a970 | ||
|
|
6bbaf9de16 | ||
|
|
4cec056568 | ||
|
|
b7835f3976 | ||
|
|
472ddcc696 | ||
|
|
832ab43bdd | ||
|
|
cecab1a310 | ||
|
|
8b90c04c62 | ||
|
|
5e510e41ee | ||
|
|
491889a237 | ||
|
|
a2f07828e4 | ||
|
|
d94b9513e7 | ||
|
|
70deb3168e | ||
|
|
a5d409b777 | ||
|
|
79a0172ace | ||
|
|
8fc746555d | ||
|
|
ed3af8e984 | ||
|
|
1d1075b35e | ||
|
|
8eb44dcbd5 | ||
|
|
f392d8a7f5 | ||
|
|
c7bc26d8ee | ||
|
|
6c1594ea24 | ||
|
|
94aa2c4093 | ||
|
|
259742a5e3 | ||
|
|
6876e82fc5 | ||
|
|
84ddda6a3f | ||
|
|
f85664fd6b | ||
|
|
a65573b061 | ||
|
|
385004cab2 | ||
|
|
9696612b2b | ||
|
|
d5d7db0de6 | ||
|
|
45375d1f1b | ||
|
|
4897e9c4d5 | ||
|
|
5cced71fb0 | ||
|
|
7ec727f69f | ||
|
|
8059c229c5 | ||
|
|
bc2099d31d | ||
|
|
211ec3898b | ||
|
|
2227fa434f | ||
|
|
23d554548a | ||
|
|
091f7ef153 | ||
|
|
38d606b4d1 | ||
|
|
ae75d8b209 | ||
|
|
e0d5cdd625 | ||
|
|
3f95494ae8 | ||
|
|
cabbbec72f | ||
|
|
1dd7f03a7a | ||
|
|
66c4eae9cf | ||
|
|
e721878e4b | ||
|
|
f2eb6cec9a | ||
|
|
bc4ddcef05 | ||
|
|
4580b85fe2 | ||
|
|
45e1e99390 | ||
|
|
b5793c34c6 | ||
|
|
67ee45090d | ||
|
|
64d1a587e7 | ||
|
|
fbe279831e | ||
|
|
375d4d0479 | ||
|
|
7796d4c14a | ||
|
|
78e4b22a2f | ||
|
|
a867450e3b | ||
|
|
b5ee44621c | ||
|
|
24a9e7abd2 | ||
|
|
180c77d1f4 | ||
|
|
247af45791 | ||
|
|
fd0646fecf | ||
|
|
c8821cb226 | ||
|
|
2e531850b8 | ||
|
|
65dbb5ac48 | ||
|
|
16cf7e8e42 | ||
|
|
19556d9e68 | ||
|
|
338833262c | ||
|
|
77800d9212 | ||
|
|
be618df7f5 | ||
|
|
ff85a2e502 | ||
|
|
74675346c9 | ||
|
|
e9344ae046 | ||
|
|
4acf12bb69 | ||
|
|
161d5fe7be | ||
|
|
9bf4ea7341 | ||
|
|
a1bf5651fc | ||
|
|
763228c859 | ||
|
|
770af27d75 | ||
|
|
3e59283c19 | ||
|
|
6146ccba2d | ||
|
|
b0e1527a95 | ||
|
|
cb4410c84e | ||
|
|
98b5976656 | ||
|
|
9335386928 | ||
|
|
7c30d62f33 | ||
|
|
61683bccda | ||
|
|
e1ec5159b8 | ||
|
|
7b7d19592f | ||
|
|
e387c0b6b8 | ||
|
|
d5abc119f3 | ||
|
|
59da6e5620 | ||
|
|
ef1cc0ed4f | ||
|
|
90f0caec1a | ||
|
|
5c0fb63f33 | ||
|
|
036a8e7608 | ||
|
|
10c4d0509d | ||
|
|
57998ea4f8 | ||
|
|
ef9a629ddc | ||
|
|
d974cf5200 | ||
|
|
36d6c6d0e9 | ||
|
|
ff49104764 | ||
|
|
03e43da9f9 | ||
|
|
e696d65b60 | ||
|
|
ebf626061f | ||
|
|
c3d023ad40 | ||
|
|
0a10b3e784 | ||
|
|
e0f66a8196 | ||
|
|
e5dfbd4b23 | ||
|
|
5ad2962389 | ||
|
|
a56e22b6fc | ||
|
|
67f536d7c6 | ||
|
|
741224411b | ||
|
|
818417d119 | ||
|
|
f272785861 | ||
|
|
5d807ee622 | ||
|
|
90c3cdf0f3 | ||
|
|
2bc233b2f6 | ||
|
|
051b23f577 | ||
|
|
f2bc2d33f0 | ||
|
|
38a121a887 | ||
|
|
8b380f0692 |
64
Cargo.lock
generated
64
Cargo.lock
generated
@@ -4,15 +4,21 @@ version = 4
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.1"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcb6dd1c2376d2e096796e234a70e17e94cc2d5d54ff8ce42b28cef1d0d359a4"
|
||||
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29"
|
||||
|
||||
[[package]]
|
||||
name = "blog_os"
|
||||
@@ -22,7 +28,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"pc-keyboard",
|
||||
"pic8259",
|
||||
"spin",
|
||||
"spin 0.5.2",
|
||||
"uart_16550",
|
||||
"volatile 0.2.7",
|
||||
"x86_64",
|
||||
@@ -30,17 +36,17 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "bootloader"
|
||||
version = "0.9.31"
|
||||
version = "0.9.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "974e79cf1b0b737839f01330fb5393095daf1124d52693696494e32523ae9ef5"
|
||||
checksum = "7bdfddac270bbdd45903296bc1caf29a7fdce6b326aaf0bbab7f04c5f98b7447"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
dependencies = [
|
||||
"spin",
|
||||
"spin 0.9.8",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -51,13 +57,19 @@ checksum = "ed089a1fbffe3337a1a345501c981f1eb1e47e69de5a40e852433e12953c3174"
|
||||
|
||||
[[package]]
|
||||
name = "pic8259"
|
||||
version = "0.10.1"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08cc920d83ee33c0f9b73aa441e75468bf2d10c959a3eb6260cf720b05ac91a1"
|
||||
checksum = "cb844b5b01db1e0b17938685738f113bfc903846f18932b378bc0eabfa40e194"
|
||||
dependencies = [
|
||||
"x86_64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||
|
||||
[[package]]
|
||||
name = "spin"
|
||||
version = "0.5.2"
|
||||
@@ -65,12 +77,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "uart_16550"
|
||||
version = "0.2.14"
|
||||
name = "spin"
|
||||
version = "0.9.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "503a6c0e6d82daa87985e662d120c0176b09587c92a68db22781b28ae95405dd"
|
||||
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
|
||||
|
||||
[[package]]
|
||||
name = "uart_16550"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "614ff2a87880d4bd4374722268598a970bbad05ced8bf630439417347254ab2e"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bitflags 1.3.2",
|
||||
"rustversion",
|
||||
"x86_64",
|
||||
]
|
||||
|
||||
@@ -82,17 +101,18 @@ checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945"
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
version = "0.4.4"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4c2dbd44eb8b53973357e6e207e370f0c1059990df850aca1eca8947cf464f0"
|
||||
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
|
||||
|
||||
[[package]]
|
||||
name = "x86_64"
|
||||
version = "0.14.7"
|
||||
version = "0.14.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fb611915c917c6296d11e23f71ff1ecfe49c5766daba92cd3df52df6b58285b6"
|
||||
checksum = "c101112411baafbb4bf8d33e4c4a80ab5b02d74d2612331c61e8192fc9710491"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags",
|
||||
"volatile 0.4.4",
|
||||
"bitflags 2.9.2",
|
||||
"rustversion",
|
||||
"volatile 0.4.6",
|
||||
]
|
||||
|
||||
17
Cargo.toml
17
Cargo.toml
@@ -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"
|
||||
@@ -25,10 +25,19 @@ pc-keyboard = "0.7.0"
|
||||
version = "1.0"
|
||||
features = ["spin_no_std"]
|
||||
|
||||
[[bin]]
|
||||
name = "blog_os"
|
||||
test = true
|
||||
bench = false
|
||||
|
||||
|
||||
[package.metadata.bootimage]
|
||||
test-args = [
|
||||
"-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
|
||||
"-display", "none"
|
||||
"-device",
|
||||
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||
"-serial",
|
||||
"stdio",
|
||||
"-display",
|
||||
"none",
|
||||
]
|
||||
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Blog OS (Introduction to Paging)
|
||||
# Blog OS (Paging Implementation)
|
||||
|
||||
[](https://github.com/phil-opp/blog_os/actions?query=workflow%3A%22Code%22+branch%3Apost-08)
|
||||
[](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.**
|
||||
|
||||
|
||||
10
src/lib.rs
10
src/lib.rs
@@ -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();
|
||||
|
||||
27
src/main.rs
27
src/main.rs
@@ -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
106
src/memory.rs
Normal 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
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,8 @@
|
||||
"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-c-int-width": "32",
|
||||
"target-pointer-width": 64,
|
||||
"target-c-int-width": 32,
|
||||
"os": "none",
|
||||
"executables": true,
|
||||
"linker-flavor": "ld.lld",
|
||||
|
||||
Reference in New Issue
Block a user