qemu_i486_q35/
multiboot.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2024.
4
5//! Minimal implementation of Multiboot V1
6//!
7//! <https://www.gnu.org/software/grub/manual/multiboot/multiboot.html>
8
9/// Magic number for Multboot V1 header
10const MAGIC_NUMBER: u32 = 0x1BADB002;
11
12/// Minimal Multiboot V1 header structure
13#[repr(C)]
14pub struct MultibootV1Header {
15    magic: u32,
16    flags: u32,
17    checksum: u32,
18}
19
20impl MultibootV1Header {
21    /// Constructs a new Multiboot header instance using the given flags
22    ///
23    /// This function automatically computes an appropriate checksum value for the header.
24    pub const fn new(flags: u32) -> Self {
25        let mut checksum: u32 = 0;
26        checksum = checksum.wrapping_sub(MAGIC_NUMBER);
27        checksum = checksum.wrapping_sub(flags);
28
29        Self {
30            magic: MAGIC_NUMBER,
31            flags,
32            checksum,
33        }
34    }
35}