diff --git a/crate/process/build.rs b/crate/process/build.rs new file mode 100644 index 0000000..f3cb10c --- /dev/null +++ b/crate/process/build.rs @@ -0,0 +1,3 @@ +fn main() { + println!("cargo:rerun-if-env-changed=M_MODE"); +} \ No newline at end of file diff --git a/crate/process/src/interrupt.rs b/crate/process/src/interrupt.rs index ea3ea27..6e238be 100644 --- a/crate/process/src/interrupt.rs +++ b/crate/process/src/interrupt.rs @@ -2,7 +2,7 @@ #[cfg(target_arch = "x86_64")] pub unsafe fn disable_and_store() -> usize { let rflags: usize; - asm!("pushfq; popq $0; cli" : "=r"(rflags)); + asm!("pushfq; popq $0; cli" : "=r"(rflags) ::: "volatile"); rflags & (1 << 9) } @@ -10,20 +10,20 @@ pub unsafe fn disable_and_store() -> usize { #[cfg(target_arch = "x86_64")] pub unsafe fn restore(flags: usize) { if flags != 0 { - asm!("sti"); + asm!("sti" :::: "volatile"); } } #[inline(always)] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] pub unsafe fn disable_and_store() -> usize { - if option_env!("m_mode").is_some() { + if env!("M_MODE") == "1" { let mstatus: usize; - asm!("csrci mstatus, 1 << 3" : "=r"(mstatus)); + asm!("csrci mstatus, 1 << 3" : "=r"(mstatus) ::: "volatile"); mstatus & (1 << 3) } else { let sstatus: usize; - asm!("csrci sstatus, 1 << 1" : "=r"(sstatus)); + asm!("csrci sstatus, 1 << 1" : "=r"(sstatus) ::: "volatile"); sstatus & (1 << 1) } } @@ -31,10 +31,10 @@ pub unsafe fn disable_and_store() -> usize { #[inline(always)] #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] pub unsafe fn restore(flags: usize) { - if option_env!("m_mode").is_some() { - asm!("csrs mstatus, $0" :: "r"(flags)); + if env!("M_MODE") == "1" { + asm!("csrs mstatus, $0" :: "r"(flags) :: "volatile"); } else { - asm!("csrs sstatus, $0" :: "r"(flags)); + asm!("csrs sstatus, $0" :: "r"(flags) :: "volatile"); } } @@ -42,8 +42,7 @@ pub unsafe fn restore(flags: usize) { #[cfg(target_arch = "aarch64")] pub unsafe fn disable_and_store() -> usize { let daif: u32; - asm!("mrs $0, DAIF": "=r"(daif) ::: "volatile"); - asm!("msr daifset, #2"); + asm!("mrs $0, DAIF; msr daifset, #2": "=r"(daif) ::: "volatile"); daif as usize } diff --git a/kernel/Makefile b/kernel/Makefile index d73ca8d..b62679a 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -24,8 +24,6 @@ board ?= none mode ?= debug LOG ?= debug smp ?= 4 -# NOTE: crate 'process' use this name 'm_mode' as an environment -# to set interrupt (MIE or SIE) m_mode ?= target := $(arch)-blog_os @@ -34,6 +32,7 @@ bin := target/$(target)/$(mode)/kernel.bin bootimage := target/$(target)/bootimage.bin user_dir := ../user +### export environments ### export ARCH = $(arch) export SMP = $(smp) #export SFSIMG = $(user_dir)/build/user-$(arch).img @@ -45,6 +44,11 @@ endif ifeq ($(arch), aarch64) board := raspi3 endif +ifeq ($(board), k210) +m_mode := 1 +endif +# crate 'process' use this to set interrupt (MIE or SIE) +export M_MODE = $(m_mode) ### qemu options ### qemu_opts := \