1+ //! Exports item [`Multiboot2HeaderBuilder`].
2+
13use crate :: HeaderTagISA ;
24use crate :: {
35 AddressHeaderTag , ConsoleHeaderTag , EfiBootServiceHeaderTag , EndHeaderTag , EntryEfi32HeaderTag ,
46 EntryEfi64HeaderTag , EntryHeaderTag , FramebufferHeaderTag , InformationRequestHeaderTagBuilder ,
5- ModuleAlignHeaderTag , Multiboot2HeaderInner , RelocatableHeaderTag , StructAsBytes ,
7+ ModuleAlignHeaderTag , Multiboot2BasicHeader , RelocatableHeaderTag , StructAsBytes ,
68} ;
79use core:: mem:: size_of;
810
@@ -64,10 +66,10 @@ impl Multiboot2HeaderBuilder {
6466 }
6567 }
6668
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.
6971 pub fn expected_len ( & self ) -> usize {
70- let base_len = size_of :: < Multiboot2HeaderInner > ( ) ;
72+ let base_len = size_of :: < Multiboot2BasicHeader > ( ) ;
7173 // size_or_up_aligned not required, because basic header length is 16 and the
7274 // begin is 8 byte aligned => first tag automatically 8 byte aligned
7375 let mut len = Self :: size_or_up_aligned ( base_len) ;
@@ -109,9 +111,9 @@ impl Multiboot2HeaderBuilder {
109111 len
110112 }
111113
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.
113115 /// 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 ) {
115117 dest. extend ( source) ;
116118 if !is_end_tag {
117119 let size = source. len ( ) ;
@@ -130,7 +132,7 @@ impl Multiboot2HeaderBuilder {
130132 Self :: build_add_bytes (
131133 & mut data,
132134 // 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 ( ) ,
134136 false ,
135137 ) ;
136138
@@ -174,46 +176,48 @@ impl Multiboot2HeaderBuilder {
174176 data
175177 }
176178
179+ // clippy thinks this can be a const fn but the compiler denies it
180+ #[ allow( clippy:: missing_const_for_fn) ]
177181 pub fn information_request_tag (
178182 mut self ,
179183 information_request_tag : InformationRequestHeaderTagBuilder ,
180184 ) -> Self {
181185 self . information_request_tag = Some ( information_request_tag) ;
182186 self
183187 }
184- pub fn address_tag ( mut self , address_tag : AddressHeaderTag ) -> Self {
188+ pub const fn address_tag ( mut self , address_tag : AddressHeaderTag ) -> Self {
185189 self . address_tag = Some ( address_tag) ;
186190 self
187191 }
188- pub fn entry_tag ( mut self , entry_tag : EntryHeaderTag ) -> Self {
192+ pub const fn entry_tag ( mut self , entry_tag : EntryHeaderTag ) -> Self {
189193 self . entry_tag = Some ( entry_tag) ;
190194 self
191195 }
192- pub fn console_tag ( mut self , console_tag : ConsoleHeaderTag ) -> Self {
196+ pub const fn console_tag ( mut self , console_tag : ConsoleHeaderTag ) -> Self {
193197 self . console_tag = Some ( console_tag) ;
194198 self
195199 }
196- pub fn framebuffer_tag ( mut self , framebuffer_tag : FramebufferHeaderTag ) -> Self {
200+ pub const fn framebuffer_tag ( mut self , framebuffer_tag : FramebufferHeaderTag ) -> Self {
197201 self . framebuffer_tag = Some ( framebuffer_tag) ;
198202 self
199203 }
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 {
201205 self . module_align_tag = Some ( module_align_tag) ;
202206 self
203207 }
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 {
205209 self . efi_bs_tag = Some ( efi_bs_tag) ;
206210 self
207211 }
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 {
209213 self . efi_32_tag = Some ( efi_32_tag) ;
210214 self
211215 }
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 {
213217 self . efi_64_tag = Some ( efi_64_tag) ;
214218 self
215219 }
216- pub fn relocatable_tag ( mut self , relocatable_tag : RelocatableHeaderTag ) -> Self {
220+ pub const fn relocatable_tag ( mut self , relocatable_tag : RelocatableHeaderTag ) -> Self {
217221 self . relocatable_tag = Some ( relocatable_tag) ;
218222 self
219223 }
@@ -222,8 +226,8 @@ impl Multiboot2HeaderBuilder {
222226#[ cfg( test) ]
223227mod tests {
224228 use crate :: {
225- load_mb2_header , HeaderTagFlag , HeaderTagISA , InformationRequestHeaderTagBuilder ,
226- MbiTagType , Multiboot2HeaderBuilder , RelocatableHeaderTag ,
229+ HeaderTagFlag , HeaderTagISA , InformationRequestHeaderTagBuilder , MbiTagType ,
230+ Multiboot2Header , Multiboot2HeaderBuilder , RelocatableHeaderTag ,
227231 RelocatableHeaderTagPreference ,
228232 } ;
229233
@@ -238,7 +242,7 @@ mod tests {
238242 #[ test]
239243 fn test_size_builder ( ) {
240244 let builder = Multiboot2HeaderBuilder :: new ( HeaderTagISA :: I386 ) ;
241- // multiboot2 basic header + end tag
245+ // Multiboot2 basic header + end tag
242246 let mut expected_len = 16 + 8 ;
243247 assert_eq ! ( builder. expected_len( ) , expected_len) ;
244248
@@ -272,7 +276,7 @@ mod tests {
272276
273277 let mb2_hdr_data = builder. build ( ) ;
274278 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) } ;
276280 println ! ( "{:#?}" , mb2_hdr) ;
277281
278282 /* you can write the binary to a file and a tool such as crate "bootinfo"
0 commit comments