Skip to content

Commit 5e4e01d

Browse files
committed
TagType-enum introduced in v0.11 is now actually public
1 parent 3918c18 commit 5e4e01d

File tree

3 files changed

+72
-24
lines changed

3 files changed

+72
-24
lines changed

Changelog.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.12.1
2+
- `TagType`-enum introduced in `v0.11` is now actually public
3+
- internal code improvements
4+
15
# 0.12.0
26

37
- **breaking:** `load()` and `load_with_offset` now returns a result
@@ -7,7 +11,7 @@
711

812
# 0.11.0
913

10-
- lib now contains public `TagType`-enum that contains
14+
- lib now contains `TagType`-enum that contains
1115
all possible mbi tags that are specified (taken from spec)
1216
- much improved debug-formatting of `BootInformation`
1317
- internal code improvements / formatting

src/header.rs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,89 @@ use core::marker::PhantomData;
1010
/// that the Rust compiler output changes `eax` before you can access it.
1111
pub const MULTIBOOT2_BOOTLOADER_MAGIC: u32 = 0x36d76289;
1212

13-
/// Possible Types of a [`Tag`]. The names and values are taken from the example C code
13+
/// Possible types of a Tag in the Multiboot2 Information Structure (MBI), therefore the value
14+
/// of the the `typ` field in [`Tag`]. The names and values are taken from the example C code
1415
/// at the bottom of the Multiboot2 specification.
1516
#[repr(u32)]
1617
#[derive(Copy, Clone, Debug)]
18+
#[allow(missing_docs)]
1719
pub enum TagType {
20+
/// Marks the end of the tags.
1821
End = 0,
22+
/// Additional command line string.
23+
/// For example `''` or `'--my-custom-option foo --provided by_grub`, if your GRUB config
24+
/// contains `multiboot2 /boot/multiboot2-binary.elf --my-custom-option foo --provided by_grub`
1925
Cmdline = 1,
26+
/// Name of the bootloader, e.g. 'GRUB 2.04-1ubuntu44.2'
2027
BootLoaderName = 2,
28+
/// Additional Multiboot modules, which are BLOBs provided in memory. For example an initial
29+
/// ram disk with essential drivers.
2130
Module = 3,
31+
/// ‘mem_lower’ and ‘mem_upper’ indicate the amount of lower and upper memory, respectively,
32+
/// in kilobytes. Lower memory starts at address 0, and upper memory starts at address 1
33+
/// megabyte. The maximum possible value for lower memory is 640 kilobytes. The value returned
34+
/// for upper memory is maximally the address of the first upper memory hole minus 1 megabyte.
35+
/// It is not guaranteed to be this value.
36+
///
37+
/// This tag may not be provided by some boot loaders on EFI platforms if EFI boot services are
38+
/// enabled and available for the loaded image (EFI boot services not terminated tag exists in
39+
/// Multiboot2 information structure).
2240
BasicMeminfo = 4,
41+
/// This tag indicates which BIOS disk device the boot loader loaded the OS image from. If the
42+
/// OS image was not loaded from a BIOS disk, then this tag must not be present. The operating
43+
/// system may use this field as a hint for determining its own root device, but is not
44+
/// required to.
2345
Bootdev = 5,
46+
/// Memory map. The map provided is guaranteed to list all standard RAM that should be
47+
/// available for normal use. This type however includes the regions occupied by kernel, mbi,
48+
/// segments and modules. Kernel must take care not to overwrite these regions.
49+
//
50+
// This tag may not be provided by some boot loaders on EFI platforms if EFI boot services are
51+
// enabled and available for the loaded image (EFI boot services not terminated tag exists in
52+
// Multiboot2 information structure).
2453
Mmap = 6,
54+
/// Contains the VBE control information returned by the VBE Function 00h and VBE mode
55+
/// information returned by the VBE Function 01h, respectively. Note that VBE 3.0 defines
56+
/// another protected mode interface which is incompatible with the old one. If you want to use the new protected mode interface, you will have to find the table yourself.
2557
Vbe = 7,
58+
/// Framebuffer.
2659
Framebuffer = 8,
60+
/// This tag contains section header table from an ELF kernel, the size of each entry, number
61+
/// of entries, and the string table used as the index of names. They correspond to the
62+
/// ‘shdr_*’ entries (‘shdr_num’, etc.) in the Executable and Linkable Format (ELF)
63+
/// specification in the program header.
2764
ElfSections = 9,
65+
/// APM table. See Advanced Power Management (APM) BIOS Interface Specification, for more
66+
/// information.
2867
Apm = 10,
68+
/// This tag contains pointer to i386 EFI system table.
2969
Efi32 = 11,
70+
/// This tag contains pointer to amd64 EFI system table.
3071
Efi64 = 12,
72+
/// This tag contains a copy of SMBIOS tables as well as their version.
3173
Smbios = 13,
3274
/// Also called "AcpiOld" in other multiboot2 implementations.
3375
AcpiV1 = 14,
3476
/// Refers to version 2 and later of Acpi.
3577
/// Also called "AcpiNew" in other multiboot2 implementations.
3678
AcpiV2 = 15,
79+
/// This tag contains network information in the format specified as DHCP. It may be either a
80+
/// real DHCP reply or just the configuration info in the same format. This tag appears once
81+
/// per card.
3782
Network = 16,
83+
/// This tag contains EFI memory map as per EFI specification.
84+
/// This tag may not be provided by some boot loaders on EFI platforms if EFI boot services are
85+
/// enabled and available for the loaded image (EFI boot services not terminated tag exists in Multiboot2 information structure).
3886
EfiMmap = 17,
87+
/// This tag indicates ExitBootServices wasn't called.
3988
EfiBs = 18,
89+
/// This tag contains pointer to EFI i386 image handle. Usually it is boot loader image handle.
4090
Efi32Ih = 19,
91+
/// This tag contains pointer to EFI amd64 image handle. Usually it is boot loader image handle.
4192
Efi64Ih = 20,
93+
/// This tag contains image load base physical address. The spec tells
94+
/// "It is provided only if image has relocatable header tag." but experience showed
95+
/// that this is not true for at least GRUB 2.
4296
LoadBaseAddr = 21,
4397
}
4498

src/lib.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ pub use elf_sections::{
3030
ElfSection, ElfSectionFlags, ElfSectionIter, ElfSectionType, ElfSectionsTag,
3131
};
3232
pub use framebuffer::{FramebufferColor, FramebufferField, FramebufferTag, FramebufferType};
33+
pub use header::TagType;
3334
pub use header::MULTIBOOT2_BOOTLOADER_MAGIC;
34-
use header::{Tag, TagIter, TagType};
35+
use header::{Tag, TagIter};
3536
pub use memory_map::{
3637
EFIMemoryAreaType, EFIMemoryDesc, EFIMemoryMapTag, MemoryArea, MemoryAreaIter, MemoryAreaType,
3738
MemoryMapTag,
@@ -88,7 +89,10 @@ pub unsafe fn load(address: usize) -> Result<BootInformation, MbiLoadError> {
8889
/// let boot_info = unsafe { load_with_offset(ptr as usize, 0xCAFEBABE).unwrap() };
8990
/// println!("{:?}", boot_info);
9091
/// ```
91-
pub unsafe fn load_with_offset(address: usize, offset: usize) -> Result<BootInformation, MbiLoadError> {
92+
pub unsafe fn load_with_offset(
93+
address: usize,
94+
offset: usize,
95+
) -> Result<BootInformation, MbiLoadError> {
9296
let address = address + offset;
9397
let null_ptr = address == 0;
9498
let eight_byte_aligned = address & 0b111 == 0;
@@ -106,12 +110,10 @@ pub unsafe fn load_with_offset(address: usize, offset: usize) -> Result<BootInfo
106110
return Err(MbiLoadError::NoEndTag);
107111
}
108112

109-
Ok(
110-
BootInformation {
111-
inner: multiboot,
112-
offset,
113-
}
114-
)
113+
Ok(BootInformation {
114+
inner: multiboot,
115+
offset,
116+
})
115117
}
116118

117119
/// Error type that describes errors while loading/parsing a multiboot2 information structure
@@ -1058,22 +1060,10 @@ mod tests {
10581060
let addr = bytes.0.as_ptr() as usize;
10591061
let bi = unsafe { load(addr) };
10601062
let bi = bi.unwrap();
1061-
test_grub2_boot_info(
1062-
bi,
1063-
addr,
1064-
string_addr,
1065-
&bytes.0,
1066-
&string_bytes.0,
1067-
);
1063+
test_grub2_boot_info(bi, addr, string_addr, &bytes.0, &string_bytes.0);
10681064
let bi = unsafe { load_with_offset(addr, 0) };
10691065
let bi = bi.unwrap();
1070-
test_grub2_boot_info(
1071-
bi,
1072-
addr,
1073-
string_addr,
1074-
&bytes.0,
1075-
&string_bytes.0,
1076-
);
1066+
test_grub2_boot_info(bi, addr, string_addr, &bytes.0, &string_bytes.0);
10771067
let offset = 8usize;
10781068
for i in 0..8 {
10791069
bytes.0[796 + i] = ((string_addr - offset as u64) >> (i * 8)) as u8;

0 commit comments

Comments
 (0)