1
+ //! Exports item [`Multiboot2HeaderBuilder`].
2
+
1
3
use crate :: HeaderTagISA ;
2
4
use crate :: {
3
5
AddressHeaderTag , ConsoleHeaderTag , EfiBootServiceHeaderTag , EndHeaderTag , EntryEfi32HeaderTag ,
4
6
EntryEfi64HeaderTag , EntryHeaderTag , FramebufferHeaderTag , InformationRequestHeaderTagBuilder ,
5
- ModuleAlignHeaderTag , Multiboot2HeaderInner , RelocatableHeaderTag , StructAsBytes ,
7
+ ModuleAlignHeaderTag , Multiboot2BasicHeader , RelocatableHeaderTag , StructAsBytes ,
6
8
} ;
7
9
use core:: mem:: size_of;
8
10
@@ -64,10 +66,10 @@ impl Multiboot2HeaderBuilder {
64
66
}
65
67
}
66
68
67
- /// Returns the expected length of the multiboot2 header,
68
- /// when the [ `build`] -method gets called.
69
+ /// Returns the expected length of the Multiboot2 header,
70
+ /// when the `build()` -method gets called.
69
71
pub fn expected_len ( & self ) -> usize {
70
- let base_len = size_of :: < Multiboot2HeaderInner > ( ) ;
72
+ let base_len = size_of :: < Multiboot2BasicHeader > ( ) ;
71
73
// size_or_up_aligned not required, because basic header length is 16 and the
72
74
// begin is 8 byte aligned => first tag automatically 8 byte aligned
73
75
let mut len = Self :: size_or_up_aligned ( base_len) ;
@@ -109,9 +111,9 @@ impl Multiboot2HeaderBuilder {
109
111
len
110
112
}
111
113
112
- /// Adds the bytes of a tag to the final multiboot2 header byte vector.
114
+ /// Adds the bytes of a tag to the final Multiboot2 header byte vector.
113
115
/// Align should be true for all tags except the end tag.
114
- fn build_add_bytes ( dest : & mut Vec < u8 > , source : & Vec < u8 > , is_end_tag : bool ) {
116
+ fn build_add_bytes ( dest : & mut Vec < u8 > , source : & [ u8 ] , is_end_tag : bool ) {
115
117
dest. extend ( source) ;
116
118
if !is_end_tag {
117
119
let size = source. len ( ) ;
@@ -130,7 +132,7 @@ impl Multiboot2HeaderBuilder {
130
132
Self :: build_add_bytes (
131
133
& mut data,
132
134
// important that we write the correct expected length into the header!
133
- & Multiboot2HeaderInner :: new ( self . arch , self . expected_len ( ) as u32 ) . struct_as_bytes ( ) ,
135
+ & Multiboot2BasicHeader :: new ( self . arch , self . expected_len ( ) as u32 ) . struct_as_bytes ( ) ,
134
136
false ,
135
137
) ;
136
138
@@ -174,46 +176,48 @@ impl Multiboot2HeaderBuilder {
174
176
data
175
177
}
176
178
179
+ // clippy thinks this can be a const fn but the compiler denies it
180
+ #[ allow( clippy:: missing_const_for_fn) ]
177
181
pub fn information_request_tag (
178
182
mut self ,
179
183
information_request_tag : InformationRequestHeaderTagBuilder ,
180
184
) -> Self {
181
185
self . information_request_tag = Some ( information_request_tag) ;
182
186
self
183
187
}
184
- pub fn address_tag ( mut self , address_tag : AddressHeaderTag ) -> Self {
188
+ pub const fn address_tag ( mut self , address_tag : AddressHeaderTag ) -> Self {
185
189
self . address_tag = Some ( address_tag) ;
186
190
self
187
191
}
188
- pub fn entry_tag ( mut self , entry_tag : EntryHeaderTag ) -> Self {
192
+ pub const fn entry_tag ( mut self , entry_tag : EntryHeaderTag ) -> Self {
189
193
self . entry_tag = Some ( entry_tag) ;
190
194
self
191
195
}
192
- pub fn console_tag ( mut self , console_tag : ConsoleHeaderTag ) -> Self {
196
+ pub const fn console_tag ( mut self , console_tag : ConsoleHeaderTag ) -> Self {
193
197
self . console_tag = Some ( console_tag) ;
194
198
self
195
199
}
196
- pub fn framebuffer_tag ( mut self , framebuffer_tag : FramebufferHeaderTag ) -> Self {
200
+ pub const fn framebuffer_tag ( mut self , framebuffer_tag : FramebufferHeaderTag ) -> Self {
197
201
self . framebuffer_tag = Some ( framebuffer_tag) ;
198
202
self
199
203
}
200
- pub fn module_align_tag ( mut self , module_align_tag : ModuleAlignHeaderTag ) -> Self {
204
+ pub const fn module_align_tag ( mut self , module_align_tag : ModuleAlignHeaderTag ) -> Self {
201
205
self . module_align_tag = Some ( module_align_tag) ;
202
206
self
203
207
}
204
- pub fn efi_bs_tag ( mut self , efi_bs_tag : EfiBootServiceHeaderTag ) -> Self {
208
+ pub const fn efi_bs_tag ( mut self , efi_bs_tag : EfiBootServiceHeaderTag ) -> Self {
205
209
self . efi_bs_tag = Some ( efi_bs_tag) ;
206
210
self
207
211
}
208
- pub fn efi_32_tag ( mut self , efi_32_tag : EntryEfi32HeaderTag ) -> Self {
212
+ pub const fn efi_32_tag ( mut self , efi_32_tag : EntryEfi32HeaderTag ) -> Self {
209
213
self . efi_32_tag = Some ( efi_32_tag) ;
210
214
self
211
215
}
212
- pub fn efi_64_tag ( mut self , efi_64_tag : EntryEfi64HeaderTag ) -> Self {
216
+ pub const fn efi_64_tag ( mut self , efi_64_tag : EntryEfi64HeaderTag ) -> Self {
213
217
self . efi_64_tag = Some ( efi_64_tag) ;
214
218
self
215
219
}
216
- pub fn relocatable_tag ( mut self , relocatable_tag : RelocatableHeaderTag ) -> Self {
220
+ pub const fn relocatable_tag ( mut self , relocatable_tag : RelocatableHeaderTag ) -> Self {
217
221
self . relocatable_tag = Some ( relocatable_tag) ;
218
222
self
219
223
}
@@ -222,8 +226,8 @@ impl Multiboot2HeaderBuilder {
222
226
#[ cfg( test) ]
223
227
mod tests {
224
228
use crate :: {
225
- load_mb2_header , HeaderTagFlag , HeaderTagISA , InformationRequestHeaderTagBuilder ,
226
- MbiTagType , Multiboot2HeaderBuilder , RelocatableHeaderTag ,
229
+ HeaderTagFlag , HeaderTagISA , InformationRequestHeaderTagBuilder , MbiTagType ,
230
+ Multiboot2Header , Multiboot2HeaderBuilder , RelocatableHeaderTag ,
227
231
RelocatableHeaderTagPreference ,
228
232
} ;
229
233
@@ -238,7 +242,7 @@ mod tests {
238
242
#[ test]
239
243
fn test_size_builder ( ) {
240
244
let builder = Multiboot2HeaderBuilder :: new ( HeaderTagISA :: I386 ) ;
241
- // multiboot2 basic header + end tag
245
+ // Multiboot2 basic header + end tag
242
246
let mut expected_len = 16 + 8 ;
243
247
assert_eq ! ( builder. expected_len( ) , expected_len) ;
244
248
@@ -272,7 +276,7 @@ mod tests {
272
276
273
277
let mb2_hdr_data = builder. build ( ) ;
274
278
let mb2_hdr = mb2_hdr_data. as_ptr ( ) as usize ;
275
- let mb2_hdr = unsafe { load_mb2_header ( mb2_hdr) } ;
279
+ let mb2_hdr = unsafe { Multiboot2Header :: from_addr ( mb2_hdr) } ;
276
280
println ! ( "{:#?}" , mb2_hdr) ;
277
281
278
282
/* you can write the binary to a file and a tool such as crate "bootinfo"
0 commit comments