From 9d82b295174254dd0860bedc30843b8c0c1294d8 Mon Sep 17 00:00:00 2001 From: Runji Wang Date: Wed, 24 Jun 2020 00:09:52 +0800 Subject: [PATCH] move wait_for_interrupt from executor to kernel --- kernel/Cargo.lock | 7 ++----- kernel/Cargo.toml | 2 +- kernel/src/arch/aarch64/interrupt/mod.rs | 10 ++++++++++ kernel/src/arch/riscv/interrupt/mod.rs | 12 ++++++++++++ kernel/src/arch/x86_64/interrupt/mod.rs | 5 +++++ kernel/src/lib.rs | 5 ++++- 6 files changed, 34 insertions(+), 7 deletions(-) diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index ff61a29d..6d56fc66 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -186,21 +186,18 @@ dependencies = [ [[package]] name = "executor" version = "0.6.0" -source = "git+https://github.com/rcore-os/executor.git?rev=7cf7ac0#7cf7ac0e9ff27086b41621ca7096520a1f3f6a57" +source = "git+https://github.com/rcore-os/executor.git?rev=a2d02ee9#a2d02ee9567973209f557db53adc988dad2095e5" dependencies = [ - "aarch64", "executor-macros", "lazy_static", - "riscv 0.5.6 (git+https://github.com/rcore-os/riscv?rev=d9794e)", "spin", "woke", - "x86_64", ] [[package]] name = "executor-macros" version = "0.0.1" -source = "git+https://github.com/rcore-os/executor.git?rev=7cf7ac0#7cf7ac0e9ff27086b41621ca7096520a1f3f6a57" +source = "git+https://github.com/rcore-os/executor.git?rev=a2d02ee9#a2d02ee9567973209f557db53adc988dad2095e5" dependencies = [ "proc-macro2", "quote", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 6525717c..03d0fa87 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -54,7 +54,7 @@ bit_field = "0.10" buddy_system_allocator = "0.4.0" compression = { version = "0.1.4", default-features = false, features = ["gzip"] } device_tree = { git = "https://github.com/rcore-os/device_tree-rs", rev = "2fa8411c" } -executor = { git = "https://github.com/rcore-os/executor.git", rev = "7cf7ac0" } +executor = { git = "https://github.com/rcore-os/executor.git", rev = "a2d02ee9" } isomorphic_drivers = { git = "https://github.com/rcore-os/isomorphic_drivers", rev = "fcf694d2", features = ["log"] } lazy_static = { version = "1.4", features = ["spin_no_std"] } log = "0.4" diff --git a/kernel/src/arch/aarch64/interrupt/mod.rs b/kernel/src/arch/aarch64/interrupt/mod.rs index 81ffb11d..14a7a3af 100644 --- a/kernel/src/arch/aarch64/interrupt/mod.rs +++ b/kernel/src/arch/aarch64/interrupt/mod.rs @@ -58,3 +58,13 @@ pub fn get_trap_num(cx: &UserContext) -> usize { pub fn enable_irq(irq: usize) { // TODO } + +pub fn wait_for_interrupt() { + use aarch64::regs::*; + let daif = DAIF.get(); + unsafe { + llvm_asm!("msr daifclr, #2"); + } + aarch64::asm::wfe(); + DAIF.set(daif); +} diff --git a/kernel/src/arch/riscv/interrupt/mod.rs b/kernel/src/arch/riscv/interrupt/mod.rs index 66747250..871f8307 100644 --- a/kernel/src/arch/riscv/interrupt/mod.rs +++ b/kernel/src/arch/riscv/interrupt/mod.rs @@ -101,3 +101,15 @@ pub fn enable_irq(irq: usize) { pub fn get_trap_num(_context: &UserContext) -> usize { scause::read().bits() } + +pub fn wait_for_interrupt() { + unsafe { + // enable interrupt and disable + let sie = riscv::register::sstatus::read().sie(); + riscv::register::sstatus::set_sie(); + riscv::asm::wfi(); + if !sie { + riscv::register::sstatus::clear_sie(); + } + } +} diff --git a/kernel/src/arch/x86_64/interrupt/mod.rs b/kernel/src/arch/x86_64/interrupt/mod.rs index 9526a9d2..76d3106d 100644 --- a/kernel/src/arch/x86_64/interrupt/mod.rs +++ b/kernel/src/arch/x86_64/interrupt/mod.rs @@ -55,3 +55,8 @@ pub fn ack(_irq: usize) { pub fn get_trap_num(context: &UserContext) -> usize { context.trap_num } + +pub fn wait_for_interrupt() { + x86_64::instructions::interrupts::enable_interrupts_and_hlt(); + x86_64::instructions::interrupts::disable(); +} diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 07cd8a30..e2745ba2 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -69,7 +69,10 @@ pub mod arch; pub mod arch; pub fn kmain() -> ! { - executor::run(); + loop { + executor::run_until_idle(); + arch::interrupt::wait_for_interrupt(); + } } /// Global heap allocator