Skip to content

Commit

Permalink
chore(pmp): move set_pmp to pmp module
Browse files Browse the repository at this point in the history
Signed-off-by: tfx2001 <[email protected]>
  • Loading branch information
tfx2001 committed Aug 15, 2024
1 parent 5edb5ed commit 0cf5ef0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
14 changes: 1 addition & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main() -> ! {
firmware_address = _start as usize,
);
// 初始化 PMP
set_pmp();
pmp::set_pmp();
// 显示 PMP 配置
pmp::print_pmps();
// 设置陷入栈
Expand Down Expand Up @@ -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!(
Expand Down
13 changes: 11 additions & 2 deletions src/pmp.rs
Original file line number Diff line number Diff line change
@@ -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::<usize>();
Expand Down Expand Up @@ -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")]
Expand All @@ -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(),
Expand Down

0 comments on commit 0cf5ef0

Please sign in to comment.