From 629b053ea85151d9c5511ae48c2fe19bf0cdc51e Mon Sep 17 00:00:00 2001 From: Zejun Zhao Date: Thu, 25 Sep 2025 21:11:28 +0800 Subject: [PATCH] Make exception table arch-agnostic --- osdk/src/base_crate/x86_64.ld.template | 2 +- ostd/src/arch/x86/mod.rs | 1 - ostd/src/arch/x86/trap/mod.rs | 3 ++- ostd/src/{arch/x86 => }/ex_table.rs | 4 ++++ ostd/src/lib.rs | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) rename ostd/src/{arch/x86 => }/ex_table.rs (95%) diff --git a/osdk/src/base_crate/x86_64.ld.template b/osdk/src/base_crate/x86_64.ld.template index a082fc278..589937be2 100644 --- a/osdk/src/base_crate/x86_64.ld.template +++ b/osdk/src/base_crate/x86_64.ld.template @@ -95,7 +95,7 @@ SECTIONS # The section to store exception table (ExTable). # This table is used for recovering from specific exception handling faults # occurring at known points in the code. - # Ref: /aster-frame/src/arch/x86/ex_table.rs + # Ref: /ostd/src/ex_table.rs .ex_table : AT(ADDR(.ex_table) - KERNEL_VMA) { __ex_table = .; KEEP(*(SORT(.ex_table))) diff --git a/ostd/src/arch/x86/mod.rs b/ostd/src/arch/x86/mod.rs index bc3ac217d..81e8338b3 100644 --- a/ostd/src/arch/x86/mod.rs +++ b/ostd/src/arch/x86/mod.rs @@ -5,7 +5,6 @@ pub(crate) mod boot; pub mod cpu; pub mod device; -pub(crate) mod ex_table; pub(crate) mod io; pub(crate) mod iommu; pub mod irq; diff --git a/ostd/src/arch/x86/trap/mod.rs b/ostd/src/arch/x86/trap/mod.rs index 6b941d2a3..e63ac0512 100644 --- a/ostd/src/arch/x86/trap/mod.rs +++ b/ostd/src/arch/x86/trap/mod.rs @@ -25,7 +25,7 @@ use cfg_if::cfg_if; use log::debug; use spin::Once; -use super::{cpu::context::GeneralRegs, ex_table::ExTable}; +use super::cpu::context::GeneralRegs; use crate::{ arch::{ cpu::context::{CpuException, PageFaultErrorCode, RawPageFaultInfo}, @@ -33,6 +33,7 @@ use crate::{ irq::{disable_local, enable_local, HwIrqLine}, }, cpu::PrivilegeLevel, + ex_table::ExTable, irq::call_irq_callback_functions, mm::{ kspace::{KERNEL_PAGE_TABLE, LINEAR_MAPPING_BASE_VADDR, LINEAR_MAPPING_VADDR_RANGE}, diff --git a/ostd/src/arch/x86/ex_table.rs b/ostd/src/ex_table.rs similarity index 95% rename from ostd/src/arch/x86/ex_table.rs rename to ostd/src/ex_table.rs index 5d84297c8..b98cc569d 100644 --- a/ostd/src/arch/x86/ex_table.rs +++ b/ostd/src/ex_table.rs @@ -61,6 +61,10 @@ impl ExTable { /// This function is generally used when an exception (such as a page fault) occurs. /// if the exception handling fails and there is a predefined recovery action, /// then the found recovery action will be taken. + #[cfg_attr( + any(target_arch = "riscv64", target_arch = "loongarch64"), + expect(unused) + )] pub fn find_recovery_inst_addr(inst_addr: Vaddr) -> Option { let table_size = (__ex_table_end as usize - __ex_table as usize) / size_of::(); // SAFETY: `__ex_table` is a static section consisting of `ExTableItem`. diff --git a/ostd/src/lib.rs b/ostd/src/lib.rs index 16defd330..409d9baac 100644 --- a/ostd/src/lib.rs +++ b/ostd/src/lib.rs @@ -37,6 +37,7 @@ pub mod bus; pub mod console; pub mod cpu; mod error; +mod ex_table; pub mod io; pub mod irq; pub mod logger;