Skip to content

Commit ef79b8b

Browse files
authored
Merge pull request #144 from rust-osdev/dev3
streamline default derives
2 parents 9dd5c2a + ab6bb32 commit ef79b8b

29 files changed

+80
-76
lines changed

multiboot2-header/src/address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem::size_of;
55
/// format, but it must be provided if the image is in a.out format or in some
66
/// other format. Required for legacy boot (BIOS).
77
/// Determines load addresses.
8-
#[derive(Copy, Clone, Debug)]
8+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
99
#[repr(C)]
1010
pub struct AddressHeaderTag {
1111
typ: HeaderTagType,

multiboot2-header/src/builder/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use core::mem::size_of;
1414
/// Builder to construct a valid Multiboot2 header dynamically at runtime.
1515
/// The tags will appear in the order of their corresponding enumeration,
1616
/// except for the END tag.
17-
#[derive(Debug)]
17+
#[derive(Clone, Debug, PartialEq, Eq)]
1818
pub struct Multiboot2HeaderBuilder {
1919
arch: HeaderTagISA,
2020
// first

multiboot2-header/src/builder/information_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use multiboot2::TagTypeId;
1111
/// at runtime. The information request tag has a dedicated builder because this way one
1212
/// can dynamically attach several requests to it. Otherwise, the number of requested tags
1313
/// must be known at compile time.
14-
#[derive(Debug)]
14+
#[derive(Clone, Debug, PartialEq, Eq)]
1515
#[cfg(feature = "builder")]
1616
pub struct InformationRequestHeaderTagBuilder {
1717
flag: HeaderTagFlag,

multiboot2-header/src/console.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem::size_of;
33

44
/// Possible flags for [`ConsoleHeaderTag`].
55
#[repr(u32)]
6-
#[derive(Copy, Clone, Debug)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
77
pub enum ConsoleHeaderTagFlags {
88
/// Console required.
99
ConsoleRequired = 0,
@@ -13,7 +13,7 @@ pub enum ConsoleHeaderTagFlags {
1313

1414
/// Tells that a console must be available in MBI.
1515
/// Only relevant for legacy BIOS.
16-
#[derive(Copy, Clone, Debug)]
16+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1717
#[repr(C)]
1818
pub struct ConsoleHeaderTag {
1919
typ: HeaderTagType,

multiboot2-header/src/end.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// Terminates a list of optional tags in a Multiboot2 header.
5-
#[derive(Copy, Clone, Debug)]
5+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
66
#[repr(C)]
77
pub struct EndHeaderTag {
88
// u16 value

multiboot2-header/src/entry_address.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem::size_of;
55

66
/// Specifies the physical address to which the boot loader should jump in
77
/// order to start running the operating system. Not needed for ELF files.
8-
#[derive(Copy, Clone)]
8+
#[derive(Copy, Clone, PartialEq, Eq)]
99
#[repr(C)]
1010
pub struct EntryAddressHeaderTag {
1111
typ: HeaderTagType,

multiboot2-header/src/entry_efi_32.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem::size_of;
99
///
1010
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
1111
/// [`crate::HeaderTagType`].
12-
#[derive(Copy, Clone)]
12+
#[derive(Copy, Clone, PartialEq, Eq)]
1313
#[repr(C)]
1414
pub struct EntryEfi32HeaderTag {
1515
typ: HeaderTagType,

multiboot2-header/src/entry_efi_64.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem::size_of;
99
///
1010
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
1111
/// [`crate::HeaderTagType`].
12-
#[derive(Copy, Clone)]
12+
#[derive(Copy, Clone, PartialEq, Eq)]
1313
#[repr(C)]
1414
pub struct EntryEfi64HeaderTag {
1515
typ: HeaderTagType,

multiboot2-header/src/framebuffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use core::mem::size_of;
55
/// is present the bootloader assumes that the payload
66
/// has framebuffer support. Note: This is only a
77
/// recommended mode. Only relevant on legacy BIOS.
8-
#[derive(Copy, Clone, Debug)]
8+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
99
#[repr(C)]
1010
pub struct FramebufferHeaderTag {
1111
typ: HeaderTagType,

multiboot2-header/src/header.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'a> Debug for Multiboot2Header<'a> {
200200

201201
/// Errors that can occur when parsing a header from a slice.
202202
/// See [`Multiboot2Header::find_header`].
203-
#[derive(Debug, Clone, PartialEq, Eq)]
203+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
204204
pub enum LoadError {
205205
/// The checksum does not match the data.
206206
ChecksumMismatch,
@@ -226,7 +226,7 @@ impl core::error::Error for LoadError {}
226226
///
227227
/// The "basic" Multiboot2 header. This means only the properties, that are known during
228228
/// compile time. All other information are derived during runtime from the size property.
229-
#[derive(Copy, Clone)]
229+
#[derive(Copy, Clone, PartialEq, Eq)]
230230
#[repr(C)]
231231
pub struct Multiboot2BasicHeader {
232232
/// Must be the value of [`MULTIBOOT2_HEADER_MAGIC`].

multiboot2-header/src/information_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use multiboot2::TagType;
88

99
/// Specifies what specific tag types the bootloader should provide
1010
/// inside the mbi.
11-
#[derive(Copy, Clone)]
11+
#[derive(Copy, Clone, PartialEq, Eq)]
1212
#[repr(C)]
1313
pub struct InformationRequestHeaderTag<const N: usize> {
1414
typ: HeaderTagType,
@@ -126,7 +126,7 @@ impl<'a> Iterator for InformationRequestHeaderTagIter<'a> {
126126
impl<'a> Debug for InformationRequestHeaderTagIter<'a> {
127127
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
128128
let mut debug = f.debug_list();
129-
(*self).for_each(|e| {
129+
self.for_each(|e| {
130130
debug.entry(&e);
131131
});
132132
debug.finish()

multiboot2-header/src/module_align.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType};
22
use core::mem::size_of;
33

44
/// If this tag is present, provided boot modules must be page aligned.
5-
#[derive(Copy, Clone, Debug)]
5+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
66
#[repr(C)]
77
pub struct ModuleAlignHeaderTag {
88
typ: HeaderTagType,

multiboot2-header/src/relocatable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::mem::size_of;
88
/// but not lower than min addr and ‘2’ means load image at highest possible
99
/// address but not higher than max addr.
1010
#[repr(u32)]
11-
#[derive(Copy, Clone, Debug, PartialEq)]
11+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1212
pub enum RelocatableHeaderTagPreference {
1313
/// Let boot loader decide.
1414
None = 0,
@@ -19,7 +19,7 @@ pub enum RelocatableHeaderTagPreference {
1919
}
2020

2121
/// This tag indicates that the image is relocatable.
22-
#[derive(Copy, Clone)]
22+
#[derive(Copy, Clone, PartialEq, Eq)]
2323
#[repr(C)]
2424
pub struct RelocatableHeaderTag {
2525
typ: HeaderTagType,

multiboot2-header/src/tags.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
/// ISA/ARCH in Multiboot2 header.
66
#[repr(u32)]
7-
#[derive(Copy, Clone, Debug)]
7+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
88
pub enum HeaderTagISA {
99
/// Spec: "means 32-bit (protected) mode of i386".
1010
/// Caution: This is confusing. If you use the EFI64-tag
@@ -19,7 +19,7 @@ pub enum HeaderTagISA {
1919
/// from the example C code at the bottom of the Multiboot2 specification. This value
2020
/// stands in the `typ` property of [`crate::tags::HeaderTag`].
2121
#[repr(u16)]
22-
#[derive(Copy, Clone, Debug, PartialEq)]
22+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2323
pub enum HeaderTagType {
2424
/// Type for [`crate::EndHeaderTag`].
2525
End = 0,
@@ -54,7 +54,7 @@ impl HeaderTagType {
5454

5555
/// Flags for Multiboot2 header tags.
5656
#[repr(u16)]
57-
#[derive(Copy, Clone, Debug, PartialEq)]
57+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
5858
pub enum HeaderTagFlag {
5959
Required = 0,
6060
Optional = 1,
@@ -63,7 +63,7 @@ pub enum HeaderTagFlag {
6363
/// Common properties for all header tags. Other tags may have additional fields
6464
/// that depend on the `typ` and the `size` field. All tags share the same beginning of the
6565
/// struct.
66-
#[derive(Copy, Clone, Debug)]
66+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
6767
#[repr(C)]
6868
pub struct HeaderTag {
6969
// u16 value

multiboot2-header/src/uefi_bs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::mem::size_of;
33

44
/// This tag indicates that payload supports starting without terminating UEFI boot services.
55
/// Or in other words: The payload wants to use UEFI boot services.
6-
#[derive(Copy, Clone, Debug)]
6+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
77
#[repr(C)]
88
pub struct EfiBootServiceHeaderTag {
99
typ: HeaderTagType,

multiboot2/src/boot_loader_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use {
1212
const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();
1313

1414
/// The bootloader name tag.
15-
#[derive(ptr_meta::Pointee)]
16-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
15+
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
16+
#[repr(C)]
1717
pub struct BootLoaderNameTag {
1818
typ: TagTypeId,
1919
size: u32,

multiboot2/src/builder/information.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use core::mem::size_of;
1515
/// The tags will appear in the order of their corresponding enumeration,
1616
/// except for the END tag.
1717
#[derive(Debug)]
18+
// #[derive(Debug, PartialEq, Eq)] // wait for uefi-raw 0.3.0
1819
pub struct Multiboot2InformationBuilder {
1920
basic_memory_info_tag: Option<BasicMemoryInfoTag>,
2021
boot_loader_name_tag: Option<Box<BootLoaderNameTag>>,

multiboot2/src/command_line.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub(crate) const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + mem::size_
1818
///
1919
/// The string is a normal C-style UTF-8 zero-terminated string that can be
2020
/// obtained via the `command_line` method.
21-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
22-
#[derive(ptr_meta::Pointee)]
21+
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
22+
#[repr(C)]
2323
pub struct CommandLineTag {
2424
typ: TagTypeId,
2525
size: u32,

multiboot2/src/efi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use core::mem::size_of;
99
use crate::builder::traits::StructAsBytes;
1010

1111
/// EFI system table in 32 bit mode
12-
#[derive(Clone, Copy, Debug)]
13-
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
12+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
13+
#[repr(C)]
1414
pub struct EFISdt32 {
1515
typ: TagTypeId,
1616
size: u32,
@@ -41,7 +41,7 @@ impl StructAsBytes for EFISdt32 {
4141
}
4242

4343
/// EFI system table in 64 bit mode
44-
#[derive(Clone, Copy, Debug)]
44+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
4545
#[repr(C)]
4646
pub struct EFISdt64 {
4747
typ: TagTypeId,
@@ -73,7 +73,7 @@ impl StructAsBytes for EFISdt64 {
7373
}
7474

7575
/// Contains pointer to boot loader image handle.
76-
#[derive(Debug)]
76+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7777
#[repr(C)]
7878
pub struct EFIImageHandle32 {
7979
typ: TagTypeId,
@@ -105,7 +105,7 @@ impl StructAsBytes for EFIImageHandle32 {
105105
}
106106

107107
/// Contains pointer to boot loader image handle.
108-
#[derive(Debug)]
108+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
109109
#[repr(C)]
110110
pub struct EFIImageHandle64 {
111111
typ: TagTypeId,

multiboot2/src/elf_sections.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + 4 * size_of::<u32>();
1515
/// This tag contains section header table from an ELF kernel.
1616
///
1717
/// The sections iterator is provided via the `sections` method.
18-
#[derive(ptr_meta::Pointee)]
19-
#[repr(C, packed)]
18+
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
19+
#[repr(C)]
2020
pub struct ElfSectionsTag {
2121
typ: TagTypeId,
2222
pub(crate) size: u32,
@@ -142,7 +142,7 @@ impl Default for ElfSectionIter {
142142
}
143143

144144
/// A single generic ELF Section.
145-
#[derive(Debug)]
145+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
146146
pub struct ElfSection {
147147
inner: *const u8,
148148
string_section: *const u8,
@@ -353,7 +353,7 @@ impl ElfSectionInner for ElfSectionInner64 {
353353
}
354354

355355
/// An enum abstraction over raw ELF section types.
356-
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
356+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
357357
#[repr(u32)]
358358
pub enum ElfSectionType {
359359
/// This value marks the section header as inactive; it does not have an

multiboot2/src/framebuffer.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>()
5151
+ 2 * size_of::<u8>();
5252

5353
/// The VBE Framebuffer information Tag.
54-
#[derive(Eq, ptr_meta::Pointee)]
55-
#[repr(C, packed)]
54+
#[derive(ptr_meta::Pointee, Eq)]
55+
#[repr(C)]
5656
pub struct FramebufferTag {
5757
typ: TagTypeId,
5858
size: u32,
@@ -244,7 +244,7 @@ impl TryFrom<u8> for FramebufferTypeId {
244244
}
245245

246246
/// The type of framebuffer.
247-
#[derive(Debug, PartialEq, Eq)]
247+
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
248248
pub enum FramebufferType<'a> {
249249
/// Indexed color.
250250
Indexed {
@@ -300,7 +300,7 @@ impl<'a> FramebufferType<'a> {
300300
}
301301

302302
/// An RGB color type field.
303-
#[derive(Debug, PartialEq, Eq)]
303+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
304304
pub struct FramebufferField {
305305
/// Color field position.
306306
pub position: u8,
@@ -317,8 +317,8 @@ impl StructAsBytes for FramebufferField {
317317
}
318318

319319
/// A framebuffer color descriptor in the palette.
320-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
321-
#[repr(C, packed)] // only repr(C) would add unwanted padding at the end
320+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
321+
#[repr(C)] // no align(8) here is correct
322322
pub struct FramebufferColor {
323323
/// The Red component of the color.
324324
pub red: u8,
@@ -344,3 +344,14 @@ impl StructAsBytes for FramebufferColor {
344344
size_of::<Self>()
345345
}
346346
}
347+
348+
#[cfg(test)]
349+
mod tests {
350+
use super::*;
351+
352+
// Compile time test
353+
#[test]
354+
fn test_size() {
355+
assert_eq!(size_of::<FramebufferColor>(), 3)
356+
}
357+
}

multiboot2/src/image_load_addr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use {
77

88
/// If the image has relocatable header tag, this tag contains the image's
99
/// base physical address.
10-
#[derive(Debug)]
10+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
1111
#[repr(C)]
1212
pub struct ImageLoadPhysAddr {
1313
typ: TagTypeId,

multiboot2/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub unsafe fn load_with_offset(
173173

174174
/// Error type that describes errors while loading/parsing a multiboot2 information structure
175175
/// from a given address.
176-
#[derive(Debug, Display)]
176+
#[derive(Display, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
177177
pub enum MbiLoadError {
178178
/// The address is invalid. Make sure that the address is 8-byte aligned,
179179
/// according to the spec.
@@ -385,7 +385,7 @@ impl BootInformation {
385385
/// use std::str::Utf8Error;
386386
/// use multiboot2::{Tag, TagTrait, TagTypeId};
387387
///
388-
/// #[repr(C, align(8))]
388+
/// #[repr(C)]
389389
/// #[derive(multiboot2::Pointee)] // Only needed for DSTs.
390390
/// struct CustomTag {
391391
/// // new type from the lib: has repr(u32)

0 commit comments

Comments
 (0)