Skip to content

Commit 5dbc503

Browse files
committed
Remove uefi dependency of common crate
1 parent f1bf6de commit 5dbc503

File tree

5 files changed

+22
-19
lines changed

5 files changed

+22
-19
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/src/info.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,9 @@ pub enum MemoryRegionKind {
147147
Bootloader,
148148
/// An unknown memory region reported by the UEFI firmware.
149149
///
150-
/// This should only be used if the UEFI memory type is known as usable.
150+
/// Contains the UEFI memory type tag.
151151
UnknownUefi(u32),
152152
/// An unknown memory region reported by the BIOS firmware.
153-
///
154-
/// This should only be used if the BIOS memory type is known as usable.
155153
UnknownBios(u32),
156154
}
157155

common/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ bootloader_api = { version = "0.1.0-alpha.0", path = "../api" }
1212
conquer-once = { version = "0.3.2", default-features = false }
1313
log = "0.4.14"
1414
spinning_top = "0.2.4"
15-
uefi = "0.13"
1615
usize_conversions = "0.2.0"
1716
x86_64 = { version = "0.14.8" }
1817
xmas-elf = "0.8.0"

common/src/legacy_memory_region.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ pub trait LegacyMemoryRegion: Copy + core::fmt::Debug {
1313
fn len(&self) -> u64;
1414
/// Returns the type of the region, e.g. whether it is usable or reserved.
1515
fn kind(&self) -> MemoryRegionKind;
16+
17+
/// Mark additional regions as usable just before the bootloader jumps to the kernel.
18+
fn on_bootloader_exit(&mut self) {}
1619
}
1720

1821
/// A physical frame allocator based on a BIOS or UEFI provided memory map.
@@ -101,10 +104,11 @@ where
101104
) -> &mut [MemoryRegion] {
102105
let mut next_index = 0;
103106

104-
for descriptor in self.original {
107+
for mut descriptor in self.original {
105108
let mut start = descriptor.start();
106109
let end = start + descriptor.len();
107110
let next_free = self.next_frame.start_address();
111+
descriptor.on_bootloader_exit();
108112
let kind = match descriptor.kind() {
109113
MemoryRegionKind::Usable => {
110114
if end <= next_free {
@@ -126,19 +130,6 @@ where
126130
MemoryRegionKind::Usable
127131
}
128132
}
129-
// some mappings created by the UEFI firmware become usable again at this point
130-
MemoryRegionKind::UnknownUefi(other) => {
131-
use uefi::table::boot::MemoryType as M;
132-
match M(other) {
133-
M::LOADER_CODE
134-
| M::LOADER_DATA
135-
| M::BOOT_SERVICES_CODE
136-
| M::BOOT_SERVICES_DATA
137-
| M::RUNTIME_SERVICES_CODE
138-
| M::RUNTIME_SERVICES_DATA => MemoryRegionKind::Usable,
139-
other => MemoryRegionKind::UnknownUefi(other.0),
140-
}
141-
}
142133
other => other,
143134
};
144135

uefi/src/memory_descriptor.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,20 @@ impl<'a> LegacyMemoryRegion for UefiMemoryDescriptor {
2323
other => MemoryRegionKind::UnknownUefi(other.0),
2424
}
2525
}
26+
27+
fn on_bootloader_exit(&mut self) {
28+
match self.0.ty {
29+
// the bootloader is about to exit, so we can reallocate its data
30+
MemoryType::LOADER_CODE
31+
| MemoryType::LOADER_DATA
32+
| MemoryType::BOOT_SERVICES_CODE
33+
| MemoryType::BOOT_SERVICES_DATA
34+
| MemoryType::RUNTIME_SERVICES_CODE
35+
| MemoryType::RUNTIME_SERVICES_DATA => {
36+
// we don't need this data anymore
37+
self.0.ty = MemoryType::CONVENTIONAL;
38+
}
39+
_ => {}
40+
}
41+
}
2642
}

0 commit comments

Comments
 (0)