Use a custom config flag to conditionally compile DTB-specific areas

Would be great if we could use a feature instead, but Cargo can't do target-specific defaults features
This commit is contained in:
Andrey Turkin
2024-10-18 10:34:00 +03:00
parent 0a6a90415a
commit 55041e2eeb
13 changed files with 73 additions and 46 deletions
Generated
+48 -16
View File
@@ -58,9 +58,12 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "cc"
version = "1.0.89"
version = "1.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0ba8f7aaa012f30d5b2861462f6708eccd49c3c39863fe083a308035f63d723"
checksum = "b16803a61b81d9eabb7eae2588776c4c1e584b738ede45fdbb4c972cec1e9945"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
@@ -224,7 +227,7 @@ checksum = "64072665120942deff5fd5425d6c1811b854f4939e7f1c01ce755f64432bbea7"
[[package]]
name = "redox_syscall"
version = "0.5.6"
version = "0.5.7"
dependencies = [
"bitflags 2.4.2",
]
@@ -235,9 +238,12 @@ version = "0.1.0"
[[package]]
name = "rustc-cfg"
version = "0.3.0"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56a596b5718bf5e059d59a30af12f7f462a152de147aa462b70892849ee18704"
checksum = "9ddf7a5e441e8003a5a88aab97f1c6113043ddde252d789ef9dea3871b78633a"
dependencies = [
"thiserror",
]
[[package]]
name = "rustc-demangle"
@@ -279,13 +285,19 @@ dependencies = [
[[package]]
name = "serde_spanned"
version = "0.6.5"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1"
checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1"
dependencies = [
"serde",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "slab"
version = "0.4.9"
@@ -354,10 +366,30 @@ dependencies = [
]
[[package]]
name = "toml"
version = "0.7.8"
name = "thiserror"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257"
checksum = "d50af8abc119fb8bb6dbabcfa89656f46f84aa0ac7688088608076ad2b459a84"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08904e7672f5eb876eaaf87e0ce17857500934f4981c4a0ab2b4aa98baac7fc3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "toml"
version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
dependencies = [
"serde",
"serde_spanned",
@@ -367,18 +399,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
version = "0.6.5"
version = "0.6.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
version = "0.19.15"
version = "0.22.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5"
dependencies = [
"indexmap",
"serde",
@@ -401,9 +433,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "winnow"
version = "0.5.40"
version = "0.6.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876"
checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b"
dependencies = [
"memchr",
]
+3 -3
View File
@@ -5,9 +5,9 @@ build = "build.rs"
edition = "2021"
[build-dependencies]
cc = "1.0.3"
rustc-cfg = "0.3.0"
toml = "0.7"
cc = "1.0"
rustc-cfg = "0.5"
toml = "0.8"
[dependencies]
bitflags = "2"
+2 -1
View File
@@ -43,7 +43,7 @@ fn main() {
println!("cargo:rustc-env=TARGET={}", env::var("TARGET").unwrap());
let out_dir = env::var("OUT_DIR").unwrap();
let cfg = Cfg::new(env::var_os("TARGET").unwrap()).unwrap();
let cfg = Cfg::of(env::var("TARGET").unwrap().as_str()).unwrap();
let arch_str = cfg.target_arch.as_str();
match arch_str {
@@ -56,6 +56,7 @@ fn main() {
.target("aarch64-unknown-redox")
.compile("early_init");
*/
println!("cargo:rustc-cfg=dtb");
}
"x86" => {
println!("cargo:rerun-if-changed=src/asm/x86/trampoline.asm");
-2
View File
@@ -10,12 +10,10 @@ use crate::devices::graphical_debug;
use fdt::Fdt;
use log::info;
use rmm::PhysicalAddress;
use crate::{
allocator, device, dtb,
dtb::register_dev_memory_ranges,
memory::{Frame, PAGE_SIZE},
paging,
startup::memory::{register_bootloader_areas, register_memory_region, BootloaderMemoryKind},
};
-1
View File
@@ -17,7 +17,6 @@ use crate::{
paging::{RmmA, RmmArch},
percpu::PercpuBlock,
scheme::FileHandle,
sync::WaitCondition,
};
use crate::syscall::error::{Error, Result, EAGAIN, ESRCH};
+2 -7
View File
@@ -2,12 +2,7 @@
//!
//! For resources on contexts, please consult [wikipedia](https://en.wikipedia.org/wiki/Context_switch) and [osdev](https://wiki.osdev.org/Context_Switching)
use alloc::{
borrow::Cow,
collections::BTreeSet,
sync::{Arc, Weak},
vec::Vec,
};
use alloc::{borrow::Cow, collections::BTreeSet, sync::Arc, vec::Vec};
use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard};
use spinning_top::RwSpinlock;
@@ -214,7 +209,7 @@ pub fn spawn(
}
#[cfg(target_arch = "aarch64")]
unsafe {
{
context
.arch
.set_lr(crate::interrupt::syscall::enter_usermode as usize);
+2 -1
View File
@@ -44,6 +44,7 @@
#![feature(allocator_api)]
#![feature(asm_const)]
#![feature(core_intrinsics)]
#![allow(internal_features)]
#![feature(int_roundings)]
#![feature(iter_next_chunk)]
#![feature(let_chains)]
@@ -90,7 +91,7 @@ mod allocator;
#[allow(dead_code)] // TODO
mod acpi;
#[cfg(all(any(target_arch = "aarch64")))]
#[cfg(dtb)]
mod dtb;
/// Logical CPU ID and bitset types
+7 -7
View File
@@ -28,7 +28,7 @@ use crate::{
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
use self::acpi::AcpiScheme;
#[cfg(all(any(target_arch = "aarch64")))]
#[cfg(dtb)]
use self::dtb::DtbScheme;
use self::{
@@ -40,7 +40,7 @@ use self::{
/// When compiled with the "acpi" feature - `acpi:` - allows drivers to read a limited set of ACPI tables.
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
pub mod acpi;
#[cfg(all(any(target_arch = "aarch64")))]
#[cfg(dtb)]
pub mod dtb;
/// `debug:` - provides access to serial console
@@ -148,7 +148,7 @@ impl SchemeList {
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
insert_globals(&[Acpi]);
#[cfg(target_arch = "aarch64")]
#[cfg(dtb)]
insert_globals(&[Dtb]);
}
@@ -202,7 +202,7 @@ impl SchemeList {
let ns = self.new_ns();
// These schemes should only be available on the root
#[cfg(all(any(target_arch = "aarch64")))]
#[cfg(dtb)]
{
self.insert_global(ns, "kernel.dtb", GlobalSchemes::Dtb)
.unwrap();
@@ -539,7 +539,7 @@ pub enum GlobalSchemes {
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
Acpi,
#[cfg(target_arch = "aarch64")]
#[cfg(dtb)]
Dtb,
}
pub const MAX_GLOBAL_SCHEMES: usize = 16;
@@ -578,7 +578,7 @@ impl core::ops::Deref for GlobalSchemes {
Self::ProcRestricted => &ProcScheme::<false>,
#[cfg(all(feature = "acpi", any(target_arch = "x86", target_arch = "x86_64")))]
Self::Acpi => &AcpiScheme,
#[cfg(target_arch = "aarch64")]
#[cfg(dtb)]
Self::Dtb => &DtbScheme,
}
}
@@ -595,7 +595,7 @@ pub fn init_globals() {
{
AcpiScheme::init();
}
#[cfg(target_arch = "aarch64")]
#[cfg(dtb)]
{
DtbScheme::init();
}
+5 -4
View File
@@ -1,12 +1,12 @@
use crate::{
arch::paging::{Page, RmmA, RmmArch, VirtualAddress},
arch::paging::{Page, VirtualAddress},
context::{
self,
context::{HardBlockedReason, SignalState},
file::{FileDescriptor, InternalFlags},
memory::{handle_notify_files, AddrSpaceWrapper, Grant, PageSpan},
process::{self, Process, ProcessId, ProcessInfo, ProcessStatus},
Context, ContextRef, Status,
Context, Status,
},
memory::PAGE_SIZE,
ptrace,
@@ -21,6 +21,7 @@ use crate::{
},
};
use super::{CallerCtx, GlobalSchemes, KernelSchemes, OpenResult};
use ::syscall::{SigProcControl, Sigcontrol};
use alloc::{
boxed::Box,
@@ -38,8 +39,6 @@ use core::{
use spin::RwLock;
use spinning_top::RwSpinlock;
use super::{CallerCtx, GlobalSchemes, KernelSchemes, OpenResult};
fn read_from(dst: UserSliceWo, src: &[u8], offset: u64) -> Result<usize> {
let avail_src = usize::try_from(offset)
.ok()
@@ -1682,6 +1681,8 @@ fn write_env_regs(context: Arc<RwSpinlock<Context>>, regs: EnvRegisters) -> Resu
#[cfg(target_arch = "x86_64")]
fn write_env_regs(context: Arc<RwSpinlock<Context>>, regs: EnvRegisters) -> Result<()> {
use crate::memory::RmmA;
use rmm::Arch;
if !(RmmA::virt_is_valid(VirtualAddress::new(regs.fsbase as usize))
&& RmmA::virt_is_valid(VirtualAddress::new(regs.gsbase as usize)))
{
+1 -1
View File
@@ -1,4 +1,4 @@
use alloc::{boxed::Box, string::ToString, sync::Arc, vec::Vec};
use alloc::{boxed::Box, string::ToString, sync::Arc};
use core::{
str,
sync::atomic::{AtomicUsize, Ordering},
+1 -1
View File
@@ -1,6 +1,7 @@
use crate::{
arch::{consts::KERNEL_OFFSET, paging::entry::EntryFlags, rmm::page_flags, CurrentRmmArch},
memory::PAGE_SIZE,
startup::memory::BootloaderMemoryKind::Null,
};
use core::{
cmp::{max, min},
@@ -11,7 +12,6 @@ use rmm::{
Arch, BumpAllocator, MemoryArea, PageFlags, PageMapper, PhysicalAddress, TableKind,
VirtualAddress, KILOBYTE, MEGABYTE,
};
use crate::startup::memory::BootloaderMemoryKind::Null;
// Keep synced with OsMemoryKind in bootloader
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+1 -1
View File
@@ -2,7 +2,7 @@ use alloc::{
sync::{Arc, Weak},
vec::Vec,
};
use spin::{Mutex, MutexGuard};
use spin::Mutex;
use spinning_top::RwSpinlock;
use crate::context::{self, Context};
+1 -1
View File
@@ -632,7 +632,7 @@ fn reap(pid: ProcessId) -> Result<ProcessId> {
loop {
// TODO: exit WaitCondition?
{
let mut process = process_lock.read();
let process = process_lock.read();
if process
.threads
.iter()