Skip to main content

strat9_kernel/arch/
facade.rs

1//! Architecture facade (HAL) for Strat9-OS
2//!
3//! This module is the ONLY architecture-neutral entry point that non-arch
4//! kernel code may use. All references to `crate::arch::x86_64::...` outside
5//! of the `arch/` directory have been migrated here (jalon R0 of the RISC-V
6//! port plan: see doc/riscv-port-implementation.md).
7//!
8//! Design:
9//! - Under `target_arch = "x86_64"`, this module re-exports the existing
10//!   `x86_64` backend verbatim (zero behaviour change).
11//! - Under `target_arch = "riscv64"`, a minimal bring-up backend provides
12//!   the same API surface (subset growing with each jalon).
13//! - New code MUST use these re-exports, never a concrete backend directly.
14
15/// The active backend, as `crate::arch::backend::*`.
16#[cfg(target_arch = "x86_64")]
17pub mod backend {
18    pub use crate::arch::x86_64::{
19        cli, cpuid, hlt, interrupts_enabled, percpu, rdtsc, restore_flags, save_flags_and_cli,
20        serial, speaker, sti,
21    };
22}
23
24#[cfg(target_arch = "riscv64")]
25pub mod backend {
26    pub use super::riscv64::{
27        cli, cpuid, hlt, interrupts_enabled, rdtsc, restore_flags, save_flags_and_cli, serial,
28        speaker, sti,
29    };
30}
31
32// ---------------------------------------------------------------------------
33// Neutral re-exports (module surface shared by both backends)
34// ---------------------------------------------------------------------------
35
36/// Per-CPU data. x86_64 uses GS-base blocks; riscv64 will use `sscratch`.
37pub use backend::percpu;
38
39/// Serial console (early output, panic path, cmdline source).
40pub use backend::serial;
41
42/// Interrupt-state primitives.
43pub use backend::{cli, hlt, interrupts_enabled, restore_flags, save_flags_and_cli, sti};
44
45/// Monotonic early-boot counter (TSC on x86_64, `rdtime` on riscv64).
46pub use backend::rdtsc;
47
48/// CPU feature discovery (CPUID vs device-tree ISA string).
49pub use backend::cpuid;
50
51/// PC speaker (no-op stub on riscv64).
52pub use backend::speaker;
53
54// ---------------------------------------------------------------------------
55// x86-only surface, still referenced by not-yet-gated kernel code.
56//
57// These are re-exported from the x86 backend only when compiling for
58// x86_64; each one is scheduled to become either per-arch gated or moved
59// behind a proper HAL trait in later jalons.
60// ---------------------------------------------------------------------------
61
62/// Maximum number of CPUs supported by the kernel (neutral constant).
63#[cfg(target_arch = "x86_64")]
64pub use crate::arch::x86_64::percpu::MAX_CPUS;
65
66#[cfg(target_arch = "riscv64")]
67pub use crate::arch::riscv64::{boot_timestamp, idt, timer, vga, vgabuf};
68
69#[cfg(target_arch = "x86_64")]
70pub use crate::arch::x86_64::{
71    apic, boot_timestamp, clac, gdt, idt, init_cpu_extensions, io, ioapic, keyboard,
72    keyboard_layout, mouse, msi, pci, pic, rdmsr, ring3_diag, smp, stac, syscall, timer, tlb, tss,
73    vga, vgabuf, wrmsr, xgetbv, xsetbv,
74};