From d4f04d9094ce90605acee22a408dea16141b0979 Mon Sep 17 00:00:00 2001 From: tfx2001 Date: Thu, 15 Aug 2024 01:30:49 +0800 Subject: [PATCH] chore(pmp): move set_pmp to pmp module Signed-off-by: tfx2001 --- src/main.rs | 14 +------------- src/pmp.rs | 13 +++++++++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7ab25f8..c9c681e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,7 @@ fn main() -> ! { firmware_address = _start as usize, ); // 初始化 PMP - set_pmp(); + pmp::set_pmp(); // 显示 PMP 配置 pmp::print_pmps(); // 设置陷入栈 @@ -94,18 +94,6 @@ fn main() -> ! { } } -/// 设置 PMP。 -fn set_pmp() { - use riscv::register::*; - unsafe { - // 1. SDRAM - pmpcfg0::set_pmp(0, Range::OFF, Permission::NONE, false); - pmpaddr0::write((0x4000_0000) >> 2); - pmpcfg0::set_pmp(1, Range::TOR, Permission::RWX, false); - pmpaddr1::write(usize::MAX >> 2); - } -} - #[panic_handler] fn panic(info: &core::panic::PanicInfo) -> ! { println!( diff --git a/src/pmp.rs b/src/pmp.rs index 52cf546..0ad4bdb 100644 --- a/src/pmp.rs +++ b/src/pmp.rs @@ -1,4 +1,15 @@ use crate::println; +use riscv::register::*; + +pub fn set_pmp() { + unsafe { + // 1. SDRAM + pmpcfg0::set_pmp(0, Range::OFF, Permission::NONE, false); + pmpaddr0::write((0x4000_0000) >> 2); + pmpcfg0::set_pmp(1, Range::TOR, Permission::RWX, false); + pmpaddr1::write(usize::MAX >> 2); + } +} pub(crate) fn print_pmps() { const ITEM_PER_CFG: usize = core::mem::size_of::(); @@ -47,7 +58,6 @@ fn dump_pmp(i: usize, s: usize, e: usize, cfg: usize) { } fn pmpcfg(i: usize) -> usize { - use riscv::register::*; match i { 0 => pmpcfg0::read().bits, #[cfg(target_arch = "riscv32")] @@ -60,7 +70,6 @@ fn pmpcfg(i: usize) -> usize { } fn pmpaddr(i: usize) -> usize { - use riscv::register::*; match i { 0x0 => pmpaddr0::read(), 0x1 => pmpaddr1::read(),