MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / InterruptBase

Class InterruptBase

src/include/interrupt_base.h:23–83  ·  view source on GitHub ↗

* @brief 中断子系统抽象基类 * * 所有架构的中断处理必须实现此接口。 * 已知实现:PLIC(RISC-V)、GIC(AArch64) * * @pre 硬件中断控制器已初始化 * @post 可通过 RegisterInterruptFunc 注册中断处理函数 */

Source from the content-addressed store, hash-verified

21 * @post 可通过 RegisterInterruptFunc 注册中断处理函数
22 */
23class InterruptBase {
24 public:
25 /**
26 * @brief 类型安全的中断处理委托
27 * @param cause 中断或异常号
28 * @param context 中断上下文
29 * @return uint64_t 返回值,0 成功
30 */
31 using InterruptDelegate =
32 etl::delegate<uint64_t(uint64_t, cpu_io::TrapContext*)>;
33
34 /// @name 构造/析构函数
35 /// @{
36 InterruptBase() = default;
37 InterruptBase(const InterruptBase&) = delete;
38 InterruptBase(InterruptBase&&) = delete;
39 auto operator=(const InterruptBase&) -> InterruptBase& = delete;
40 auto operator=(InterruptBase&&) -> InterruptBase& = delete;
41 virtual ~InterruptBase() = default;
42 /// @}
43
44 /**
45 * @brief 执行中断处理
46 * @param 不同平台有不同含义
47 */
48 virtual auto Do(uint64_t, cpu_io::TrapContext*) -> void = 0;
49
50 /**
51 * @brief 注册中断处理函数
52 * @param cause 中断号,不同平台有不同含义
53 * @param func 处理函数
54 */
55 virtual auto RegisterInterruptFunc(uint64_t cause, InterruptDelegate func)
56 -> void = 0;
57
58 /**
59 * @brief 发送 IPI 到指定核心
60 * @param target_cpu_mask 目标核心的位掩码
61 * @return Expected<void> 成功时返回 void,失败时返回错误
62 */
63 [[nodiscard]] virtual auto SendIpi(uint64_t target_cpu_mask)
64 -> Expected<void> = 0;
65
66 /**
67 * @brief 广播 IPI 到所有其他核心
68 * @return Expected<void> 成功时返回 void,失败时返回错误
69 */
70 [[nodiscard]] virtual auto BroadcastIpi() -> Expected<void> = 0;
71
72 /**
73 * @brief 注册外部中断处理函数
74 * @param irq 外部中断号(平台相关: PLIC source_id / GIC INTID)
75 * @param cpu_id 目标 CPU 核心 ID,中断将路由到该核心
76 * @param priority 中断优先级
77 * @param handler 中断处理函数
78 * @return Expected<void> 成功时返回 void,失败时返回错误
79 */
80 [[nodiscard]] virtual auto RegisterExternalInterrupt(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected