arch power
This commit is contained in:
parent
b64809e9b5
commit
1e12ccddb3
@ -2,3 +2,4 @@
|
||||
pub mod riscv;
|
||||
|
||||
pub mod interrupt;
|
||||
pub mod power;
|
||||
|
4
kernel/rustkernel/src/arch/power.rs
Normal file
4
kernel/rustkernel/src/arch/power.rs
Normal file
@ -0,0 +1,4 @@
|
||||
//! Architecture-agnostic power handling.
|
||||
|
||||
#[cfg(target_arch = "riscv64")]
|
||||
pub use super::riscv::power::shutdown;
|
@ -18,9 +18,6 @@
|
||||
|
||||
use super::{MAXVA, PGSIZE};
|
||||
|
||||
// QEMU test interface. Used for power off and on.
|
||||
pub const QEMU_POWER: u64 = 0x100000u64;
|
||||
|
||||
// QEMU puts UART registers here in physical memory.
|
||||
pub const UART0: usize = 0x10000000;
|
||||
pub const UART0_IRQ: usize = 10;
|
||||
|
@ -2,6 +2,7 @@ pub mod asm;
|
||||
pub mod clint;
|
||||
pub mod memlayout;
|
||||
pub mod plic;
|
||||
pub mod power;
|
||||
pub mod start;
|
||||
|
||||
pub use asm::*;
|
||||
|
8
kernel/rustkernel/src/arch/riscv/power.rs
Normal file
8
kernel/rustkernel/src/arch/riscv/power.rs
Normal file
@ -0,0 +1,8 @@
|
||||
/// QEMU test interface. Used for power off and on.
|
||||
pub const QEMU_POWER: usize = 0x100000;
|
||||
|
||||
pub unsafe fn shutdown() -> ! {
|
||||
let qemu_power = QEMU_POWER as *mut u32;
|
||||
qemu_power.write_volatile(0x5555u32);
|
||||
unreachable!();
|
||||
}
|
@ -1,9 +1,10 @@
|
||||
use crate::{
|
||||
arch::riscv::{
|
||||
asm, make_satp,
|
||||
memlayout::{KERNBASE, PHYSTOP, QEMU_POWER, TRAMPOLINE, UART0, VIRTIO0},
|
||||
memlayout::{KERNBASE, PHYSTOP, TRAMPOLINE, UART0, VIRTIO0},
|
||||
pg_round_down, pg_round_up,
|
||||
plic::PLIC,
|
||||
power::QEMU_POWER,
|
||||
pte2pa, Pagetable, PagetableEntry, MAXVA, PGSIZE, PTE_R, PTE_U, PTE_V, PTE_W, PTE_X,
|
||||
},
|
||||
mem::{
|
||||
@ -30,7 +31,13 @@ pub unsafe fn kvmmake() -> Pagetable {
|
||||
memset(pagetable.cast(), 0, PGSIZE as u32);
|
||||
|
||||
// QEMU test interface used for power management.
|
||||
kvmmap(pagetable, QEMU_POWER, QEMU_POWER, PGSIZE, PTE_R | PTE_W);
|
||||
kvmmap(
|
||||
pagetable,
|
||||
QEMU_POWER as u64,
|
||||
QEMU_POWER as u64,
|
||||
PGSIZE,
|
||||
PTE_R | PTE_W,
|
||||
);
|
||||
|
||||
// UART registers
|
||||
kvmmap(pagetable, UART0 as u64, UART0 as u64, PGSIZE, PTE_R | PTE_W);
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
arch::riscv::memlayout::QEMU_POWER,
|
||||
arch::power::shutdown,
|
||||
fs::{
|
||||
self,
|
||||
file::{self, File},
|
||||
@ -200,11 +200,7 @@ impl Syscall {
|
||||
-1i64 as u64
|
||||
}
|
||||
}
|
||||
Syscall::Shutdown => {
|
||||
let qemu_power = QEMU_POWER as usize as *mut u32;
|
||||
qemu_power.write_volatile(0x5555u32);
|
||||
panic!("shutdown");
|
||||
}
|
||||
Syscall::Shutdown => unsafe { shutdown() },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user