ostd/arch/x86/device/
cmos.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-License-Identifier: MPL-2.0

//! Provides CMOS I/O port access.
//!
//! "CMOS" is a tiny bit of very low power static memory that lives on the same chip as the Real-Time Clock (RTC).
//!
//! Reference: <https://wiki.osdev.org/CMOS>
//!

#![expect(unused_variables)]

use acpi::fadt::Fadt;
use x86_64::instructions::port::{ReadOnlyAccess, WriteOnlyAccess};

use crate::{
    arch::kernel::acpi::get_acpi_tables,
    io::{sensitive_io_port, IoPort},
};

sensitive_io_port!(unsafe {
    /// CMOS address I/O port
    pub static CMOS_ADDRESS: IoPort<u8, WriteOnlyAccess> = IoPort::new(0x70);
    /// CMOS data I/O port
    pub static CMOS_DATA: IoPort<u8, ReadOnlyAccess> = IoPort::new(0x71);
});

/// Gets the century register location. This function is used in RTC(Real Time Clock) module initialization.
pub fn century_register() -> Option<u8> {
    let acpi_tables = get_acpi_tables()?;
    match acpi_tables.find_table::<Fadt>() {
        Ok(a) => Some(a.century),
        Err(er) => None,
    }
}