浏览代码

multiboot2: cleanup

Philipp Schuster 1 年之前
父节点
当前提交
1f840b2238

+ 1 - 0
.github/workflows/rust.yml

@@ -75,6 +75,7 @@ jobs:
   # check that devs can also use this on Windows.
   build_nostd_stable_windows:
     name: build no_std (stable) [Windows]
+    needs: build_stable
     uses: ./.github/workflows/_build-rust.yml
     with:
       runs-on: windows-latest

+ 2 - 2
multiboot2-header/src/information_request.rs

@@ -98,12 +98,12 @@ pub struct InformationRequestHeaderTagIter<'a> {
 }
 
 impl<'a> InformationRequestHeaderTagIter<'a> {
-    fn new(count: u32, base_ptr: *const MbiTagTypeId) -> Self {
+    const fn new(count: u32, base_ptr: *const MbiTagTypeId) -> Self {
         Self {
             i: 0,
             count,
             base_ptr,
-            _marker: PhantomData::default(),
+            _marker: PhantomData,
         }
     }
 }

+ 1 - 1
multiboot2/src/efi.rs

@@ -162,7 +162,7 @@ mod tests {
 
     #[test]
     fn test_build_eftih64() {
-        let tag = EFIImageHandle32::new(ADDR.try_into().unwrap());
+        let tag = EFIImageHandle64::new(ADDR.try_into().unwrap());
         assert_eq!(tag.image_handle(), ADDR);
     }
 }

+ 34 - 1
multiboot2/src/framebuffer.rs

@@ -1,4 +1,4 @@
-use crate::{Reader, Tag, TagTrait, TagTypeId};
+use crate::{Tag, TagTrait, TagTypeId};
 
 use core::fmt::Debug;
 use core::mem::size_of;
@@ -11,6 +11,39 @@ use {
     alloc::boxed::Box, alloc::vec::Vec,
 };
 
+/// Helper struct to read bytes from a raw pointer and increase the pointer
+/// automatically.
+struct Reader {
+    ptr: *const u8,
+    off: usize,
+}
+
+impl Reader {
+    fn new<T>(ptr: *const T) -> Reader {
+        Reader {
+            ptr: ptr as *const u8,
+            off: 0,
+        }
+    }
+
+    fn read_u8(&mut self) -> u8 {
+        self.off += 1;
+        unsafe { *self.ptr.add(self.off - 1) }
+    }
+
+    fn read_u16(&mut self) -> u16 {
+        self.read_u8() as u16 | (self.read_u8() as u16) << 8
+    }
+
+    fn read_u32(&mut self) -> u32 {
+        self.read_u16() as u32 | (self.read_u16() as u32) << 16
+    }
+
+    fn current_address(&self) -> usize {
+        unsafe { self.ptr.add(self.off) as usize }
+    }
+}
+
 const METADATA_SIZE: usize = size_of::<TagTypeId>()
     + 4 * size_of::<u32>()
     + size_of::<u64>()

+ 0 - 31
multiboot2/src/lib.rs

@@ -502,37 +502,6 @@ impl fmt::Debug for BootInformation {
     }
 }
 
-pub(crate) struct Reader {
-    pub(crate) ptr: *const u8,
-    pub(crate) off: usize,
-}
-
-impl Reader {
-    pub(crate) fn new<T>(ptr: *const T) -> Reader {
-        Reader {
-            ptr: ptr as *const u8,
-            off: 0,
-        }
-    }
-
-    pub(crate) fn read_u8(&mut self) -> u8 {
-        self.off += 1;
-        unsafe { *self.ptr.add(self.off - 1) }
-    }
-
-    pub(crate) fn read_u16(&mut self) -> u16 {
-        self.read_u8() as u16 | (self.read_u8() as u16) << 8
-    }
-
-    pub(crate) fn read_u32(&mut self) -> u32 {
-        self.read_u16() as u32 | (self.read_u16() as u32) << 16
-    }
-
-    pub(crate) fn current_address(&self) -> usize {
-        unsafe { self.ptr.add(self.off) as usize }
-    }
-}
-
 /// A trait to abstract over all sized and unsized tags (DSTs). For sized tags,
 /// this trait does not much. For DSTs, a `TagTrait::dst_size` implementation
 /// must me provided, which returns the right size hint for the dynamically