multiboot2/
apm.rs

1//! Module for [`ApmTag`].
2
3use crate::{TagHeader, TagType};
4use core::mem;
5use multiboot2_common::{MaybeDynSized, Tag};
6
7/// The Advanced Power Management (APM) tag.
8#[derive(Debug)]
9#[repr(C, align(8))]
10pub struct ApmTag {
11    header: TagHeader,
12    version: u16,
13    cseg: u16,
14    offset: u32,
15    cset_16: u16,
16    dseg: u16,
17    flags: u16,
18    cseg_len: u16,
19    cseg_16_len: u16,
20    dseg_len: u16,
21}
22
23impl ApmTag {
24    /// Creates a new tag.
25    #[allow(clippy::too_many_arguments)]
26    #[must_use]
27    pub fn new(
28        version: u16,
29        cseg: u16,
30        offset: u32,
31        cset_16: u16,
32        dset: u16,
33        flags: u16,
34        cseg_len: u16,
35        cseg_16_len: u16,
36        dseg_len: u16,
37    ) -> Self {
38        Self {
39            header: TagHeader::new(Self::ID, mem::size_of::<Self>() as u32),
40            version,
41            cseg,
42            offset,
43            cset_16,
44            dseg: dset,
45            flags,
46            cseg_len,
47            cseg_16_len,
48            dseg_len,
49        }
50    }
51
52    /// The version number of the APM BIOS.
53    #[must_use]
54    pub const fn version(&self) -> u16 {
55        self.version
56    }
57
58    /// Contains the 16-bit code segment (CS) address for the APM entry point.
59    #[must_use]
60    pub const fn cseg(&self) -> u16 {
61        self.cseg
62    }
63
64    /// Represents the offset address within the code segment (`cseg`) for the
65    /// APM entry point.
66    #[must_use]
67    pub const fn offset(&self) -> u32 {
68        self.offset
69    }
70
71    /// Contains the 16-bit code segment (CS) address used for 16-bit protected
72    /// mode APM functions.
73    #[must_use]
74    pub const fn cset_16(&self) -> u16 {
75        self.cset_16
76    }
77
78    /// Holds the 16-bit data segment (DS) address used by the APM BIOS for
79    /// data operations.
80    #[must_use]
81    pub const fn dseg(&self) -> u16 {
82        self.dseg
83    }
84
85    /// Indicates the status and characteristics of the APM connection, such as
86    /// if APM is present and its capabilities.
87    #[must_use]
88    pub const fn flags(&self) -> u16 {
89        self.flags
90    }
91
92    /// Indicates the length, in bytes, of the data segment (`dseg`) used by
93    /// the APM BIOS
94    #[must_use]
95    pub const fn cseg_len(&self) -> u16 {
96        self.cseg_len
97    }
98
99    /// Provides the length, in bytes, of the 16-bit code segment (`cseg_16`)
100    /// used for APM functions.
101    #[must_use]
102    pub const fn cseg_16_len(&self) -> u16 {
103        self.cseg_16_len
104    }
105
106    /// Indicates the length, in bytes, of the data segment (`dseg`) used by
107    /// the APM BIOS.
108    #[must_use]
109    pub const fn dseg_len(&self) -> u16 {
110        self.dseg_len
111    }
112}
113
114impl MaybeDynSized for ApmTag {
115    type Header = TagHeader;
116
117    const BASE_SIZE: usize = mem::size_of::<Self>();
118
119    fn dst_len(_: &TagHeader) {}
120}
121
122impl Tag for ApmTag {
123    type IDType = TagType;
124
125    const ID: TagType = TagType::Apm;
126}