Avoid re-exporting arch specific modules in the crate root

This commit is contained in:
bjorn3
2026-04-06 15:35:20 +02:00
parent 141c87650f
commit 572bb4ce1f
29 changed files with 101 additions and 77 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ use alloc::boxed::Box;
use super::{find_sdt, sdt::Sdt};
use crate::{
device::generic_timer::GenericTimer,
arch::device::generic_timer::GenericTimer,
dtb::irqchip::{register_irq, IRQ_CHIP},
};
+1 -1
View File
@@ -2,7 +2,7 @@ use alloc::{boxed::Box, vec::Vec};
use super::{Madt, MadtEntry};
use crate::{
device::irqchip::{
arch::device::irqchip::{
gic::{GenericInterruptController, GicCpuIf, GicDistIf},
gicv3::{GicV3, GicV3CpuIf},
},
+4 -3
View File
@@ -4,14 +4,15 @@ use core::{
};
use crate::{
arch::start::KernelArgsAp,
arch::{
device::local_apic::the_local_apic,
start::{kstart_ap, KernelArgsAp},
},
cpu_set::LogicalCpuId,
device::local_apic::the_local_apic,
memory::{
allocate_p2frame, Frame, KernelMapper, Page, PageFlags, PhysicalAddress, RmmA, RmmArch,
VirtualAddress, PAGE_SIZE,
},
start::kstart_ap,
AP_READY,
};
+2 -2
View File
@@ -1,6 +1,6 @@
use super::{find_sdt, sdt::Sdt, GenericAddressStructure};
use crate::{
device::serial::COM1,
arch::device::serial::COM1,
devices::{serial::SerialKind, uart_pl011},
log::LOG,
memory::{map_device_memory, PhysicalAddress, PAGE_SIZE},
@@ -87,7 +87,7 @@ impl Spcr {
if (spcr.interrupt_type & INTERRUPT_TYPE_GIC) == INTERRUPT_TYPE_GIC {
#[cfg(target_arch = "aarch64")]
unsafe {
crate::device::serial::init_acpi(spcr.gsiv);
crate::arch::device::serial::init_acpi(spcr.gsiv);
}
}
} else {
+1 -1
View File
@@ -1,6 +1,6 @@
use spin::MutexGuard;
use crate::{device::serial::COM1, devices::serial::SerialKind};
use crate::{arch::device::serial::COM1, devices::serial::SerialKind};
pub struct Writer<'a> {
serial: MutexGuard<'a, SerialKind>,
+1 -1
View File
@@ -1,6 +1,6 @@
use core::fmt::{Result, Write};
use crate::device::cpu::registers::{control_regs, id_regs};
use crate::arch::device::cpu::registers::{control_regs, id_regs};
pub mod registers;
+2 -3
View File
@@ -2,9 +2,8 @@ use alloc::boxed::Box;
use super::ic_for_chip;
use crate::{
context,
context::timeout,
device::cpu::registers::control_regs,
arch::device::cpu::registers::control_regs,
context::{self, timeout},
dtb::{
get_interrupt,
irqchip::{register_irq, InterruptHandler, IRQ_CHIP},
+2 -2
View File
@@ -6,7 +6,7 @@ use crate::{
impl PercpuBlock {
pub fn current() -> &'static Self {
unsafe { &*(crate::device::cpu::registers::control_regs::tpidr_el1() as *const Self) }
unsafe { &*(crate::arch::device::cpu::registers::control_regs::tpidr_el1() as *const Self) }
}
}
@@ -18,6 +18,6 @@ pub unsafe fn init(cpu_id: LogicalCpuId) {
virt.write(PercpuBlock::init(cpu_id));
crate::device::cpu::registers::control_regs::tpidr_el1_write(virt as u64);
crate::arch::device::cpu::registers::control_regs::tpidr_el1_write(virt as u64);
}
}
+8 -2
View File
@@ -6,7 +6,13 @@ use core::{arch::naked_asm, cell::SyncUnsafeCell, slice};
use fdt::Fdt;
use crate::{allocator, device, devices::graphical_debug, dtb, paging, startup::KernelArgs};
use crate::{
allocator,
arch::{device, paging},
devices::graphical_debug,
dtb,
startup::KernelArgs,
};
/// Test of zero values in BSS.
static mut BSS_TEST_ZERO: usize = 0;
@@ -94,7 +100,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs) -> ! {
// Initialize paging
paging::init();
crate::misc::init(crate::cpu_set::LogicalCpuId::new(0));
crate::arch::misc::init(crate::cpu_set::LogicalCpuId::new(0));
// Setup kernel heap
allocator::init();
+1 -1
View File
@@ -1,6 +1,6 @@
use spin::MutexGuard;
use crate::{device::serial::COM1, devices::serial::SerialKind};
use crate::{arch::device::serial::COM1, devices::serial::SerialKind};
pub struct Writer<'a> {
serial: MutexGuard<'a, SerialKind>,
+7 -3
View File
@@ -5,8 +5,12 @@ use core::{
};
use crate::{
allocator, arch::paging, device, devices::graphical_debug, dtb::serial::init_early,
interrupt::exception_handler, startup::KernelArgs,
allocator,
arch::{device, paging},
devices::graphical_debug,
dtb::serial::init_early,
interrupt::exception_handler,
startup::KernelArgs,
};
/// Test of zero values in BSS.
@@ -111,7 +115,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs) -> ! {
paging::init();
crate::misc::init(crate::cpu_set::LogicalCpuId::new(0));
crate::arch::misc::init(crate::cpu_set::LogicalCpuId::new(0));
// Setup kernel heap
allocator::init();
+3 -3
View File
@@ -75,9 +75,9 @@ impl InterruptStack {
pub fn init(&mut self) {
// Always enable interrupts!
self.iret.eflags = x86::bits32::eflags::EFlags::FLAGS_IF.bits() as usize;
self.iret.ss = (crate::gdt::GDT_USER_DATA << 3) | 3;
self.iret.cs = (crate::gdt::GDT_USER_CODE << 3) | 3;
self.gs = (crate::gdt::GDT_USER_GS << 3) | 3;
self.iret.ss = (crate::arch::gdt::GDT_USER_DATA << 3) | 3;
self.iret.cs = (crate::arch::gdt::GDT_USER_CODE << 3) | 3;
self.gs = (crate::arch::gdt::GDT_USER_GS << 3) | 3;
}
pub fn dump(&self) {
self.iret.dump();
+1 -1
View File
@@ -4,8 +4,8 @@ use spin::Once;
use x86::controlregs::{Cr4, Xcr0};
use crate::{
arch::cpuid::{cpuid, feature_info, has_ext_feat},
context::memory::PageSpan,
cpuid::{cpuid, feature_info, has_ext_feat},
memory::{KernelMapper, Page, PageFlags, VirtualAddress, PAGE_SIZE},
};
+4 -4
View File
@@ -97,8 +97,8 @@ impl InterruptStack {
pub fn init(&mut self) {
// Always enable interrupts!
self.iret.rflags = x86::bits64::rflags::RFlags::FLAGS_IF.bits() as usize;
self.iret.cs = (crate::gdt::GDT_USER_CODE << 3) | 3;
self.iret.ss = (crate::gdt::GDT_USER_DATA << 3) | 3;
self.iret.cs = (crate::arch::gdt::GDT_USER_CODE << 3) | 3;
self.iret.ss = (crate::arch::gdt::GDT_USER_DATA << 3) | 3;
}
pub fn frame_pointer(&self) -> usize {
self.preserved.rbp
@@ -417,7 +417,7 @@ macro_rules! interrupt_stack {
inner = sym inner,
IA32_GS_BASE = const(x86::msr::IA32_GS_BASE),
PCR_GDT_OFFSET = const(core::mem::offset_of!($crate::gdt::ProcessorControlRegion, gdt)),
PCR_GDT_OFFSET = const(core::mem::offset_of!($crate::arch::gdt::ProcessorControlRegion, gdt)),
);
}
};
@@ -510,7 +510,7 @@ macro_rules! interrupt_error {
"iretq;",
inner = sym inner,
rax_offset = const(size_of::<$crate::interrupt::handler::PreservedRegisters>() + size_of::<$crate::interrupt::handler::ScratchRegisters>() - 8),
rax_offset = const(size_of::<$crate::arch::interrupt::handler::PreservedRegisters>() + size_of::<$crate::arch::interrupt::handler::ScratchRegisters>() - 8),
);
}
};
+1 -1
View File
@@ -1,8 +1,8 @@
use x86::controlregs::Cr4;
use crate::{
arch::cpuid::{cpuid, has_ext_feat},
cpu_set::LogicalCpuId,
cpuid::{cpuid, has_ext_feat},
};
pub unsafe fn init(cpu_id: LogicalCpuId) {
+1 -2
View File
@@ -5,8 +5,7 @@ use core::{
use x86::msr::*;
use crate::{
arch::cpuid::cpuid,
ipi::IpiKind,
arch::{cpuid::cpuid, ipi::IpiKind},
memory::{map_device_memory, PhysicalAddress},
percpu::PercpuBlock,
};
+1 -1
View File
@@ -122,7 +122,7 @@ pub fn get_kvm_support() -> &'static Option<KvmSupport> {
pub unsafe fn init() -> bool {
unsafe {
let cpuid = crate::cpuid::cpuid();
let cpuid = crate::arch::cpuid::cpuid();
if !cpuid.get_feature_info().is_some_and(|f| f.has_tsc()) {
return false;
}
+13 -7
View File
@@ -13,12 +13,14 @@ use x86::{
};
use crate::{
cpu_set::LogicalCpuId,
interrupt::{
irq::{__generic_interrupts_end, __generic_interrupts_start},
*,
arch::{
interrupt::{
irq::{__generic_interrupts_end, __generic_interrupts_start},
*,
},
ipi::IpiKind,
},
ipi::IpiKind,
cpu_set::LogicalCpuId,
memory::PAGE_SIZE,
};
@@ -269,7 +271,8 @@ pub unsafe fn install_idt(idt_ptr: *mut Idt) {
#[cfg(target_arch = "x86_64")] // TODO: x86
{
(*crate::gdt::pcr()).tss.ist[usize::from(BACKUP_IST - 1)] = idt.backup_stack_end as u64;
(*crate::arch::gdt::pcr()).tss.ist[usize::from(BACKUP_IST - 1)] =
idt.backup_stack_end as u64;
}
let idtr: DescriptorTablePointer<X86IdtEntry> = DescriptorTablePointer {
@@ -350,6 +353,9 @@ impl IdtEntry {
// A function to set the offset more easily
pub fn set_func(&mut self, func: unsafe extern "C" fn()) {
self.set_flags(IdtFlags::PRESENT | IdtFlags::RING_0 | IdtFlags::INTERRUPT);
self.set_offset((crate::gdt::GDT_KERNEL_CODE as u16) << 3, func as usize);
self.set_offset(
(crate::arch::gdt::GDT_KERNEL_CODE as u16) << 3,
func as usize,
);
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
use crate::{
context, device::local_apic::the_local_apic, percpu::PercpuBlock, sync::CleanLockToken,
arch::device::local_apic::the_local_apic, context, percpu::PercpuBlock, sync::CleanLockToken,
};
interrupt!(wakeup, || {
+7 -5
View File
@@ -3,12 +3,14 @@ use core::sync::atomic::{AtomicUsize, Ordering};
use alloc::vec::Vec;
use crate::{
context::{self, timeout},
device::{
ioapic, local_apic, pic, pit,
serial::{COM1, COM2},
arch::{
device::{
ioapic, local_apic, pic, pit,
serial::{COM1, COM2},
},
ipi::{ipi, IpiKind, IpiTarget},
},
ipi::{ipi, IpiKind, IpiTarget},
context::{self, timeout},
percpu::PercpuBlock,
scheme::{irq::irq_trigger, serio::serio_input},
sync::CleanLockToken,
+2 -2
View File
@@ -20,7 +20,7 @@ pub enum IpiTarget {
#[inline(always)]
pub fn ipi(kind: IpiKind, target: IpiTarget) {
use crate::device::local_apic::the_local_apic;
use crate::arch::device::local_apic::the_local_apic;
if cfg!(not(feature = "multi_core")) {
return;
@@ -39,7 +39,7 @@ pub fn ipi(kind: IpiKind, target: IpiTarget) {
#[inline(always)]
pub fn ipi_single(kind: IpiKind, target: &crate::percpu::PercpuBlock) {
use crate::device::local_apic::the_local_apic;
use crate::arch::device::local_apic::the_local_apic;
if cfg!(not(feature = "multi_core")) {
return;
+9 -6
View File
@@ -5,8 +5,11 @@
use core::{arch::naked_asm, cell::SyncUnsafeCell, mem::offset_of};
use crate::{
allocator, cpu_set::LogicalCpuId, device, devices::graphical_debug, gdt, idt, interrupt,
paging, startup::KernelArgs,
allocator,
arch::{device, gdt, idt, interrupt, paging},
cpu_set::LogicalCpuId,
devices::graphical_debug,
startup::KernelArgs,
};
/// Test of zero values in BSS.
@@ -107,7 +110,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! {
paging::init();
#[cfg(target_arch = "x86_64")]
crate::alternative::early_init(true);
crate::arch::alternative::early_init(true);
// Set up syscall instruction
interrupt::syscall::init();
@@ -122,7 +125,7 @@ unsafe extern "C" fn start(args_ptr: *const KernelArgs, stack_end: usize) -> ! {
// Initialize miscellaneous processor features
#[cfg(target_arch = "x86_64")]
crate::misc::init(LogicalCpuId::BSP);
crate::arch::misc::init(LogicalCpuId::BSP);
// Initialize devices
device::init();
@@ -199,14 +202,14 @@ unsafe extern "C" fn start_ap(args_ptr: *const KernelArgsAp) -> ! {
crate::profiling::init();
#[cfg(target_arch = "x86_64")]
crate::alternative::early_init(false);
crate::arch::alternative::early_init(false);
// Set up syscall instruction
interrupt::syscall::init();
// Initialize miscellaneous processor features
#[cfg(target_arch = "x86_64")]
crate::misc::init(args.cpu_id);
crate::arch::misc::init(args.cpu_id);
// Initialize devices (for AP)
device::init_ap();
+5 -5
View File
@@ -1,7 +1,7 @@
use core::sync::atomic::AtomicBool;
use crate::{
gdt::{pcr, GDT_USER_FS, GDT_USER_GS},
arch::gdt::{pcr, GDT_USER_FS, GDT_USER_GS},
percpu::PercpuBlock,
syscall::FloatRegisters,
};
@@ -137,7 +137,7 @@ impl super::Context {
if self.is_current_context() {
unsafe {
crate::gdt::set_userspace_io_allowed(crate::gdt::pcr(), allowed);
crate::arch::gdt::set_userspace_io_allowed(crate::arch::gdt::pcr(), allowed);
}
}
}
@@ -215,12 +215,12 @@ pub unsafe fn empty_cr3() -> rmm::PhysicalAddress {
/// Switch to the next context by restoring its stack and registers
pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) {
unsafe {
let pcr = crate::gdt::pcr();
let pcr = crate::arch::gdt::pcr();
if let Some(ref stack) = next.kstack {
crate::gdt::set_tss_stack(pcr, stack.initial_top() as usize);
crate::arch::gdt::set_tss_stack(pcr, stack.initial_top() as usize);
}
crate::gdt::set_userspace_io_allowed(pcr, next.arch.userspace_io_allowed);
crate::arch::gdt::set_userspace_io_allowed(pcr, next.arch.userspace_io_allowed);
core::arch::asm!("
fxsave [{prev_fx}]
+5 -5
View File
@@ -107,7 +107,7 @@ impl Context {
stack_top = stack_top.sub(size_of::<usize>());
stack_top
.cast::<usize>()
.write(crate::interrupt::syscall::enter_usermode as usize);
.write(crate::arch::interrupt::syscall::enter_usermode as usize);
}
stack_top = stack_top.sub(size_of::<usize>());
@@ -155,7 +155,7 @@ impl super::Context {
if self.is_current_context() {
unsafe {
crate::gdt::set_userspace_io_allowed(crate::gdt::pcr(), allowed);
crate::arch::gdt::set_userspace_io_allowed(crate::arch::gdt::pcr(), allowed);
}
}
}
@@ -239,12 +239,12 @@ pub unsafe fn empty_cr3() -> rmm::PhysicalAddress {
/// Switch to the next context by restoring its stack and registers
pub unsafe fn switch_to(prev: &mut super::Context, next: &mut super::Context) {
unsafe {
let pcr = crate::gdt::pcr();
let pcr = crate::arch::gdt::pcr();
if let Some(ref stack) = next.kstack {
crate::gdt::set_tss_stack(pcr, stack.initial_top() as usize);
crate::arch::gdt::set_tss_stack(pcr, stack.initial_top() as usize);
}
crate::gdt::set_userspace_io_allowed(pcr, next.arch.userspace_io_allowed);
crate::arch::gdt::set_userspace_io_allowed(pcr, next.arch.userspace_io_allowed);
core::arch::asm!(
alternative2!(
+1 -3
View File
@@ -26,8 +26,6 @@ use core::{
use crate::context::switch::SwitchResult;
use crate::consts::*;
#[macro_use]
/// Shared data structures
mod common;
@@ -39,7 +37,7 @@ mod macros;
#[macro_use]
#[allow(dead_code)] // TODO
mod arch;
use crate::arch::*;
use crate::arch::{consts::*, interrupt, ipi, stop, CurrentRmmArch};
/// Offset of physmap
#[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), expect(dead_code))]
const PHYS_OFFSET: usize = <arch::CurrentRmmArch as ::rmm::Arch>::PHYS_OFFSET;
+4 -2
View File
@@ -15,9 +15,11 @@ use rmm::VirtualAddress;
use rustc_demangle::demangle;
use crate::{
arch::{consts::USER_END_OFFSET, interrupt::trace::StackTrace},
arch::{
consts::USER_END_OFFSET,
interrupt::{self, trace::StackTrace, InterruptStack},
},
context, cpu_id,
interrupt::{self, InterruptStack},
memory::KernelMapper,
sync::CleanLockToken,
syscall::{self, usercopy::UserSliceRo},
+1 -1
View File
@@ -45,7 +45,7 @@ pub struct PercpuBlock {
pub syscall_debug_info: Cell<SyscallDebugInfo>,
pub misc_arch_info: crate::device::ArchPercpuMisc,
pub misc_arch_info: crate::arch::device::ArchPercpuMisc,
pub stats: CpuStats,
pub contexts: RwLock<L1, BTreeSet<ContextRef>>,
+11 -7
View File
@@ -7,16 +7,16 @@ use core::{
use alloc::boxed::Box;
#[cfg(feature = "profiling")]
use crate::{
arch::idt::Idt,
interrupt::{self, irq::aux_timer, InterruptStack},
};
use crate::{
cpu_set::LogicalCpuId,
percpu::PercpuBlock,
syscall::{error::*, usercopy::UserSliceWo},
};
#[cfg(feature = "profiling")]
use crate::{
idt::Idt,
interrupt::{self, irq::aux_timer, InterruptStack},
};
const N: usize = 16 * 1024 * 1024;
@@ -237,11 +237,15 @@ pub fn maybe_run_profiling_helper_forever(cpu_id: LogicalCpuId) {
}
unsafe {
for i in 33..255 {
crate::idt::IDTS.write().get_mut(&cpu_id).unwrap().entries[i]
crate::arch::idt::IDTS
.write()
.get_mut(&cpu_id)
.unwrap()
.entries[i]
.set_func(crate::interrupt::ipi::wakeup);
}
let apic = &mut crate::device::local_apic::the_local_apic();
let apic = &mut crate::arch::device::local_apic::the_local_apic();
apic.set_lvt_timer((0b01 << 17) | 32);
apic.set_div_conf(0b1011);
apic.set_init_count(0xffff_f);
+1 -1
View File
@@ -1,7 +1,7 @@
use alloc::vec::Vec;
use crate::{
device::cpu::cpu_info,
arch::device::cpu::cpu_info,
sync::CleanLockToken,
syscall::error::{Error, Result, EIO},
};