@@ -5,6 +5,7 @@ const PAGE_SIZE: u64 = 4096;
5
5
6
6
const MAX_MEMORY_MAP_SIZE : usize = 64 ;
7
7
8
+ /// A map of the physical memory regions of the underlying machine.
8
9
#[ repr( C ) ]
9
10
pub struct MemoryMap {
10
11
entries : [ MemoryRegion ; MAX_MEMORY_MAP_SIZE ] ,
@@ -13,6 +14,7 @@ pub struct MemoryMap {
13
14
next_entry_index : u64 ,
14
15
}
15
16
17
+ #[ doc( hidden) ]
16
18
impl MemoryMap {
17
19
pub fn new ( ) -> Self {
18
20
MemoryMap {
@@ -83,13 +85,17 @@ impl fmt::Debug for MemoryMap {
83
85
}
84
86
}
85
87
88
+ /// Represents a region of physical memory.
86
89
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
87
90
#[ repr( C ) ]
88
91
pub struct MemoryRegion {
92
+ /// The range of frames that belong to the region.
89
93
pub range : FrameRange ,
94
+ /// The type of the region.
90
95
pub region_type : MemoryRegionType ,
91
96
}
92
97
98
+ #[ doc( hidden) ]
93
99
impl MemoryRegion {
94
100
pub fn empty ( ) -> Self {
95
101
MemoryRegion {
@@ -102,11 +108,19 @@ impl MemoryRegion {
102
108
}
103
109
}
104
110
111
+ /// A range of frames with an exclusive upper bound.
105
112
#[ derive( Clone , Copy , PartialEq , Eq ) ]
106
113
#[ repr( C ) ]
107
114
pub struct FrameRange {
115
+ /// The frame _number_ of the first 4KiB frame in the region.
116
+ ///
117
+ /// This convert this frame number to a physical address, multiply it with the
118
+ /// page size (4KiB).
108
119
pub start_frame_number : u64 ,
109
- // exclusive
120
+ /// The frame _number_ of the first 4KiB frame that does no longer belong to the region.
121
+ ///
122
+ /// This convert this frame number to a physical address, multiply it with the
123
+ /// page size (4KiB).
110
124
pub end_frame_number : u64 ,
111
125
}
112
126
@@ -122,14 +136,17 @@ impl FrameRange {
122
136
}
123
137
}
124
138
139
+ /// Returns true if the frame range contains no frames.
125
140
pub fn is_empty ( & self ) -> bool {
126
141
self . start_frame_number == self . end_frame_number
127
142
}
128
143
144
+ /// Returns the physical start address of the memory region.
129
145
pub fn start_addr ( & self ) -> u64 {
130
146
self . start_frame_number * PAGE_SIZE
131
147
}
132
148
149
+ /// Returns the physical end address of the memory region.
133
150
pub fn end_addr ( & self ) -> u64 {
134
151
self . end_frame_number * PAGE_SIZE
135
152
}
@@ -146,41 +163,47 @@ impl fmt::Debug for FrameRange {
146
163
}
147
164
}
148
165
166
+ /// Represents possible types for memory regions.
149
167
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
150
168
#[ repr( C ) ]
151
169
pub enum MemoryRegionType {
152
- /// free RAM
170
+ /// Unused memory, can be freely used by the kernel.
153
171
Usable ,
154
- /// used RAM
172
+ /// Memory that is already in use.
155
173
InUse ,
156
- /// unusable
174
+ /// Memory reserved by the hardware. Not usable.
157
175
Reserved ,
158
176
/// ACPI reclaimable memory
159
177
AcpiReclaimable ,
160
178
/// ACPI NVS memory
161
179
AcpiNvs ,
162
180
/// Area containing bad memory
163
181
BadMemory ,
164
- /// kernel memory
182
+ /// Memory used for loading the kernel.
165
183
Kernel ,
166
- /// kernel stack memory
184
+ /// Memory used for the kernel stack.
167
185
KernelStack ,
168
- /// memory used by page tables
186
+ /// Memory used for creating page tables.
169
187
PageTable ,
170
- /// memory used by the bootloader
188
+ /// Memory used by the bootloader.
171
189
Bootloader ,
172
- /// frame at address zero
190
+ /// Frame at address zero.
173
191
///
174
192
/// (shouldn't be used because it's easy to make mistakes related to null pointers)
175
193
FrameZero ,
176
- /// an empty region with size 0
194
+ /// An empty region with size 0
177
195
Empty ,
178
- /// used for storing the boot information
196
+ /// Memory used for storing the boot information.
179
197
BootInfo ,
180
- /// used for storing the supplied package
198
+ /// Memory used for storing the supplied package
181
199
Package ,
200
+ /// Additional variant to ensure that we can add more variants in the future without
201
+ /// breaking backwards compatibility.
202
+ #[ doc( hidden) ]
203
+ NonExhaustive ,
182
204
}
183
205
206
+ #[ doc( hidden) ]
184
207
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
185
208
#[ repr( C ) ]
186
209
pub struct E820MemoryRegion {
0 commit comments