Skip to content

Commit 373169a

Browse files
committed
Move memory region structs to boot_info module
1 parent f7478eb commit 373169a

File tree

7 files changed

+53
-54
lines changed

7 files changed

+53
-54
lines changed

src/binary/bios/memory_descriptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{binary::legacy_memory_region::LegacyMemoryRegion, memory_region::MemoryRegionKind};
1+
use crate::{binary::legacy_memory_region::LegacyMemoryRegion, boot_info::MemoryRegionKind};
22
use x86_64::PhysAddr;
33

44
impl LegacyMemoryRegion for E820MemoryRegion {

src/binary/legacy_memory_region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::memory_region::{MemoryRegion, MemoryRegionKind};
1+
use crate::boot_info::{MemoryRegion, MemoryRegionKind};
22
use core::mem::MaybeUninit;
33
use x86_64::{
44
structures::paging::{FrameAllocator, PhysFrame, Size4KiB},

src/binary/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::binary::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion};
2-
use crate::boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, TlsTemplate};
3-
use crate::memory_region::MemoryRegion;
1+
use crate::{
2+
binary::legacy_memory_region::{LegacyFrameAllocator, LegacyMemoryRegion},
3+
boot_info::{BootInfo, FrameBuffer, FrameBufferInfo, MemoryRegion, TlsTemplate},
4+
};
45
use core::{
56
mem::{self, MaybeUninit},
67
slice,

src/binary/uefi/memory_descriptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{binary::legacy_memory_region::LegacyMemoryRegion, memory_region::MemoryRegionKind};
1+
use crate::{binary::legacy_memory_region::LegacyMemoryRegion, boot_info::MemoryRegionKind};
22
use uefi::table::boot::{MemoryDescriptor, MemoryType};
33
use x86_64::PhysAddr;
44

src/boot_info.rs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::memory_region::MemoryRegion;
21
use core::{ops, slice};
32

43
/// This structure represents the information that the bootloader passes to the kernel.
@@ -104,6 +103,52 @@ impl From<MemoryRegions> for &'static mut [MemoryRegion] {
104103
}
105104
}
106105

106+
/// Represent a physical memory region.
107+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
108+
#[repr(C)]
109+
pub struct MemoryRegion {
110+
/// The physical start address of the region.
111+
pub start: u64,
112+
/// The physical end address (exclusive) of the region.
113+
pub end: u64,
114+
/// The memory type of the memory region.
115+
///
116+
/// Only [`Usable`][MemoryRegionKind::Usable] regions can be freely used.
117+
pub kind: MemoryRegionKind,
118+
}
119+
120+
impl MemoryRegion {
121+
/// Creates a new empty memory region (with length 0).
122+
pub const fn empty() -> Self {
123+
MemoryRegion {
124+
start: 0,
125+
end: 0,
126+
kind: MemoryRegionKind::Bootloader,
127+
}
128+
}
129+
}
130+
131+
/// Represents the different types of memory.
132+
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
133+
#[non_exhaustive]
134+
#[repr(C)]
135+
pub enum MemoryRegionKind {
136+
/// Unused conventional memory, can be used by the kernel.
137+
Usable,
138+
/// Memory mappings created by the bootloader, including the kernel and boot info mappings.
139+
///
140+
/// This memory should _not_ be used by the kernel.
141+
Bootloader,
142+
/// An unknown memory region reported by the UEFI firmware.
143+
///
144+
/// This should only be used if the UEFI memory type is known as usable.
145+
UnknownUefi(u32),
146+
/// An unknown memory region reported by the BIOS firmware.
147+
///
148+
/// This should only be used if the BIOS memory type is known as usable.
149+
UnknownBios(u32),
150+
}
151+
107152
/// A pixel-based framebuffer that controls the screen output.
108153
#[derive(Debug)]
109154
#[repr(C)]

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ pub mod config;
1919

2020
/// Contains the boot information struct sent by the bootloader to the kernel on startup.
2121
pub mod boot_info;
22-
/// Provides a memory region type that is used in the memory map of the boot info structure.
23-
pub mod memory_region;
2422

2523
/// Contains the actual bootloader implementation ("bootloader as a binary").
2624
///

src/memory_region.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)