Kaynağa Gözat

fix(prototyper): rust code format fixes

Signed-off-by: Zhouqi Jiang <luojia@openatom.club>
Zhouqi Jiang 2 hafta önce
ebeveyn
işleme
95f169d675

+ 2 - 2
library/pmpm/Cargo.toml

@@ -2,8 +2,8 @@
 name = "pmpm"
 description = "penglai/Keystone style PMP management"
 version = "0.0.0"
-authors = ["Char <jinzhe.oerv@isrc.iscas.ac.cn>", "Luo Jia <me@luojia.cc>"]
-documentation = "https://docs.rs/penglai"
+authors = ["Char <jinzhe.oerv@isrc.iscas.ac.cn>", "Luo Jia <luojia@openatom.club>"]
+documentation = "https://docs.rs/pmpm"
 edition.workspace = true
 license.workspace = true
 repository.workspace = true

+ 3 - 3
library/pmpm/src/lib.rs

@@ -74,9 +74,9 @@ pub struct PmpSlice {
 impl PmpSlice {
     pub fn new(num_bytes: usize, pa_lo: usize, pa_hi: usize) -> Self {
         PmpSlice {
-            num_bytes: (num_bytes),
-            pa_lo: (pa_lo),
-            pa_hi: (pa_hi),
+            num_bytes,
+            pa_lo,
+            pa_hi,
         }
     }
     #[inline]

+ 21 - 60
prototyper/prototyper/src/firmware/mod.rs

@@ -11,17 +11,15 @@ cfg_if::cfg_if! {
     }
 }
 
+use crate::fail;
 use alloc::{format, vec};
 #[allow(unused)]
 use core::arch::{asm, naked_asm};
 use core::{ops::Range, usize};
-use crate::fail;
 
 use riscv::register::mstatus;
 use serde::Serialize;
 
-use pmpm::{PmpSlice, get_pmp_entry, set_pmp_entry};
-
 pub struct BootInfo {
     pub next_address: usize,
     pub mpp: mstatus::MPP,
@@ -213,67 +211,30 @@ pub fn log_pmp_cfg(memory_range: &Range<usize>) {
             "PMP", "Range", "Permission", "Address"
         );
 
-        set_pmp_entry(
-            2,
-            PmpSlice::new(0, SBI_START_ADDRESS, 0),
-            Range::TOR,
-            Permission::RWX,
-        );
-        set_pmp_entry(
-            3,
-            PmpSlice::new(0, RODATA_START_ADDRESS, 0),
-            Range::TOR,
-            Permission::NONE,
-        );
-        set_pmp_entry(
-            4,
-            PmpSlice::new(0, RODATA_END_ADDRESS, 0),
-            Range::TOR,
-            Permission::NONE,
-        );
-        set_pmp_entry(
-            5,
-            PmpSlice::new(0, SBI_END_ADDRESS, 0),
-            Range::TOR,
-            Permission::NONE,
-        );
-        set_pmp_entry(
-            6,
-            PmpSlice::new(0, memory_range.end, 0),
-            Range::TOR,
-            Permission::RWX,
+        info!("{:<10} {:<10} {:<15} 0x{:08x}", "PMP 0:", "OFF", "NONE", 0);
+        info!(
+            "{:<10} {:<10} {:<15} 0x{:08x} - 0x{:08x}",
+            "PMP 1-2:", "TOR", "RWX/RWX", memory_range.start, SBI_START_ADDRESS
         );
-        set_pmp_entry(
-            7,
-            PmpSlice::new(0, usize::MAX, 0),
-            Range::TOR,
-            Permission::RWX,
+        info!(
+            "{:<10} {:<10} {:<15} 0x{:08x} - 0x{:08x} - 0x{:08x}",
+            "PMP 3-5:",
+            "TOR",
+            "NONE/NONE",
+            RODATA_START_ADDRESS,
+            RODATA_END_ADDRESS,
+            SBI_END_ADDRESS
         );
-
-        set_pmp_entry(
-            8,
-            PmpSlice::new(memory_range.end - memory_range.start, memory_range.start, 0),
-            Range::NAPOT,
-            Permission::RWX,
+        info!(
+            "{:<10} {:<10} {:<15} 0x{:08x}",
+            "PMP 6:", "TOR", "RWX", memory_range.end
         );
-    }
-}
-
-pub fn log_pmp_cfg(memory_range: &Range<usize>) {
-    info!("PMP Configuration");
-    info!(
-        "{:<10} {:<10} {:<15} {:<30}",
-        "PMP", "Range", "Permission", "Address"
-    );
-    for i in 0..16 {
-        let (slice, config) = get_pmp_entry(i);
         info!(
-            "{:<10} 0x{:<10b} 0x{:<15b} 0x{:08x}+0x{:08x}",
-            format_args!("PMP {}", i),
-            config.range as u8,
-            config.permission as u8,
-            slice.lo(),
-            slice.size()
+            "{:<10} {:<10} {:<15} 0x{:08x}",
+            "PMP 7:",
+            "TOR",
+            "RWX",
+            usize::MAX
         );
     }
 }

+ 4 - 4
prototyper/prototyper/src/sbi/pmpm.rs

@@ -160,10 +160,10 @@ pub fn set_pmp_slot(idx: u8, slice: PmpSlice, mode: Range, perm: Permission) ->
     let sbi_ret = unsafe { PLATFORM.sbi.ipi.as_ref() }
         .unwrap()
         .send_ipi_by_pmpsync(PmpSyncContext {
-            slice: slice,
-            mode: (mode),
-            perm: (perm),
-            idx: (idx),
+            slice,
+            mode,
+            perm,
+            idx,
         });
     // If configure other harts successfully, then configure local PMP.
     set_pmp_entry(idx, slice, mode, perm);