Featurize certain components, making them optional

This commit is contained in:
August 2025-07-06 21:56:29 -04:00
parent d0f547b1c0
commit 100d1336da
Signed by: shibedrill
GPG Key ID: 5FE0CB25945EFAA2
6 changed files with 90 additions and 54 deletions

View File

@ -4,9 +4,9 @@ version = "0.3.0"
edition = "2024"
[dependencies]
acpi = "5.2.0"
acpi = { version = "5.2.0", optional = true }
bitflags = "2.9.1"
fdt = { git = "https://github.com/repnop/fdt", version = "0.2.0-alpha1" }
fdt = { git = "https://github.com/repnop/fdt", version = "0.2.0-alpha1", optional = true }
flagset = "0.4.7"
intbits = "0.2.0"
lazy_static = { version = "1.5.0", default-features = false, features = ["spin_no_std"] }
@ -17,7 +17,7 @@ num-traits = { version = "0.2.19", default-features = false }
once_cell = { version = "1.21.3", default-features = false, features = ["alloc", "critical-section"] }
spin = "0.10.0"
talc = "4.4.3"
tar-no-std = "0.3.4"
tar-no-std = { version = "0.3.4", optional = true }
[target.'cfg(target_arch = "x86_64")'.dependencies]
x86_64 = "0.15.2"
@ -33,3 +33,10 @@ test = false
doctest = false
bench = false
[features]
default = ["acpi", "dtb", "uefi", "compression"]
acpi = ["dep:acpi"] # Support ACPI
dtb = ["dep:fdt"] # Support device tree blobs
uefi = [] # Enable UEFI dependent features
compression = ["dep:tar-no-std"] # Enable compressed initramfs

View File

@ -24,8 +24,4 @@ pub static MP_REQUEST: MpRequest = limine::request::MpRequest::new();
#[used]
#[unsafe(link_section = ".requests")]
pub static FRAMEBUFFER_REQUEST: FramebufferRequest = limine::request::FramebufferRequest::new();
#[used]
#[unsafe(link_section = ".requests")]
pub static DTB_REQUEST: DeviceTreeBlobRequest = limine::request::DeviceTreeBlobRequest::new();
pub static FRAMEBUFFER_REQUEST: FramebufferRequest = limine::request::FramebufferRequest::new();

View File

@ -5,8 +5,18 @@ use crate::format;
use crate::log::LogLevel;
use crate::memory::alloc::string::String;
// TODO: Add API to query available features
pub static ACPI_ENABLED: bool = if cfg!(feature = "acpi") { true } else { false };
pub static DTB_ENABLED: bool = if cfg!(feature = "dtb") { true } else { false };
pub static COMPRESSION_ENABLED: bool = if cfg!(feature = "compression") { true } else { false };
pub static UEFI_ENABLED: bool = if cfg!(feature = "uefi") { true } else { false };
#[allow(dead_code)]
pub static INITRAMFS_DEFAULT_PATH: &str = "/boot/initramfs.tar.lzma";
pub static INITRAMFS_DEFAULT_PATH: &str = if cfg!(feature = "compression") {
"/boot/initramfs.tar.lzma"
} else {
"/boot/initramfs.tar"
};
pub static LOG_DEFAULT_LEVEL: LogLevel = LogLevel::Info;

View File

@ -3,8 +3,24 @@
// TODO: Implement per-arch memory handlers for ACPI memory map regions
use limine::request::RsdpRequest;
use limine::{request::RsdpRequest, response::RsdpResponse};
use lazy_static::lazy_static;
use crate::{format, log_info, log_warning, log::*};
#[used]
#[unsafe(link_section = ".requests")]
pub static RSDP_REQUEST: RsdpRequest = limine::request::RsdpRequest::new();
lazy_static! {
pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got RSDP pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get RSDP pointer, ACPI unavailable");
None
}
};
}

View File

@ -0,0 +1,35 @@
use lazy_static::lazy_static;
use limine::{request::DeviceTreeBlobRequest, response::DeviceTreeBlobResponse};
use fdt::*;
use crate::{format, log_trace, log_info, log_warning, log::*};
#[used]
#[unsafe(link_section = ".requests")]
pub static DTB_REQUEST: DeviceTreeBlobRequest = limine::request::DeviceTreeBlobRequest::new();
lazy_static! {
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got DTB pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get DTB pointer");
None
}
};
}
#[allow(dead_code)]
pub fn device_tree_parsed() -> Option<Fdt<'static>> {
if let Some(ok_dtb) = *DTB
&& let Ok(ok_parsed_dt) = unsafe { fdt::Fdt::from_ptr(ok_dtb.dtb_ptr() as *const u8) }
{
log_trace!("Device: Parsed device tree");
Some(ok_parsed_dt)
} else {
None
}
}

View File

@ -1,57 +1,29 @@
// Copyright (c) 2025 shibedrill
// SPDX-License-Identifier: GPL-3.0-or-later
#[cfg(feature = "acpi")]
mod acpi;
#[cfg(feature = "dtb")]
mod devtree;
use fdt::*;
use lazy_static::lazy_static;
use limine::response::{DeviceTreeBlobResponse, RsdpResponse};
use crate::boot::DTB_REQUEST;
use crate::device::acpi::RSDP_REQUEST;
use crate::log::{LOGGER, LogLevel};
use crate::{format, log_error, log_info, log_trace, log_warning};
lazy_static! {
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got DTB pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get DTB pointer");
None
}
};
pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() {
Some(resp) => {
log_info!("Device: Got RSDP pointer");
Some(resp)
}
None => {
log_warning!("Device: Did not get RSDP pointer, ACPI unavailable");
None
}
};
}
use crate::{format, log_error};
// Just to check
pub fn init_statics() {
let dtb = DTB.is_some();
let rdsp = RSDP.is_some();
let dtb = {
#[cfg(feature = "dtb")]
{ devtree::DTB.is_some() }
#[cfg(not(feature = "dtb"))]
false
};
let rdsp = {
#[cfg(feature = "acpi")]
{ acpi::RSDP.is_some() }
#[cfg(not(feature = "acpi"))]
false
};
if !dtb & !rdsp {
log_error!("Device: Neither DTB nor ACPI available, booted system will be useless")
}
}
#[allow(dead_code)]
pub fn device_tree_parsed() -> Option<Fdt<'static>> {
if let Some(ok_dtb) = *DTB
&& let Ok(ok_parsed_dt) = unsafe { fdt::Fdt::from_ptr(ok_dtb.dtb_ptr() as *const u8) }
{
log_trace!("Device: Parsed device tree");
Some(ok_parsed_dt)
} else {
None
}
}