diff --git a/build.rs b/build.rs index b9fb0f3..c0ba1f6 100644 --- a/build.rs +++ b/build.rs @@ -3,17 +3,17 @@ fn main() { struct TargetConfig { target: &'static str, - lds: &'static str, + lds: &'static str, } const TARGET_LDS: &[TargetConfig] = &[ TargetConfig { target: "riscv64", - lds: "src/arch/riscv/linker.ld", + lds: "src/arch/riscv/linker.ld", }, TargetConfig { target: "riscv32", - lds: "src/arch/riscv/linker.ld", + lds: "src/arch/riscv/linker.ld", }, ]; diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..ee754e5 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,14 @@ +unstable_features = true +edition = "2021" + +blank_lines_lower_bound = 0 +enum_discrim_align_threshold = 20 +struct_field_align_threshold = 20 + +condense_wildcard_suffixes = true +format_macro_matchers = true +match_arm_leading_pipes = "Preserve" +match_block_trailing_comma = true +reorder_impl_items = true +use_try_shorthand = true +where_single_line = true diff --git a/src/arch/riscv/trap.rs b/src/arch/riscv/trap.rs index 7107d7e..f47c206 100644 --- a/src/arch/riscv/trap.rs +++ b/src/arch/riscv/trap.rs @@ -1,4 +1,5 @@ use lazy_static::lazy_static; + #[cfg(feature = "arch_riscv64")] core::arch::global_asm!( include_str!("./asm/trap64.S"), @@ -27,11 +28,17 @@ lazy_static! { #[repr(C)] pub struct TrapContext { - pub gprs: [usize; 31], // GPRs exclude zero - pub user_sepc: usize, // 248/124 user program counter - pub user_sstatus: usize, // 256/128 user status register - pub kernel_sp: usize, // 264/132 kernel stack pointer - pub kernel_tp: usize, // 272/136 kernel tp - pub kernel_trap: usize, // 280/140 kernel trap handler - pub kernel_satp: usize, // 288/144 kernel page table + pub gprs: [usize; 31], + // GPRs exclude zero + pub user_sepc: usize, + // 248/124 user program counter + pub user_sstatus: usize, + // 256/128 user status register + pub kernel_sp: usize, + // 264/132 kernel stack pointer + pub kernel_tp: usize, + // 272/136 kernel tp + pub kernel_trap: usize, + // 280/140 kernel trap handler + pub kernel_satp: usize, // 288/144 kernel page table } diff --git a/src/entry.rs b/src/entry.rs index 8702b25..afb9a37 100644 --- a/src/entry.rs +++ b/src/entry.rs @@ -2,6 +2,7 @@ use log::{error, info}; use crate::utils::lowlevel::{Hardware, LowLevel}; +#[no_mangle] pub extern "C" fn rust_main(hart_id: usize, device_tree_addr: usize) -> ! { crate::logging::init(); diff --git a/src/mm/addr.rs b/src/mm/addr.rs index 8f6d73b..b829b88 100644 --- a/src/mm/addr.rs +++ b/src/mm/addr.rs @@ -28,15 +28,11 @@ pub trait AddressOps { fn as_usize(&self) -> usize; fn as_non_zero_usize(&self) -> Option; fn align_up(&self, align: T) -> Self - where - T: Into; + where T: Into; fn align_down(&self, align: T) -> Self - where - T: Into; + where T: Into; fn is_aligned(&self, align: T) -> bool - where - T: Into + Copy, - { + where T: Into + Copy { if align.into().is_power_of_two() { self.as_usize() & (align.into() - 1) == 0 } else { @@ -63,16 +59,12 @@ impl AddressOps for PhysAddr { } fn align_up(&self, align: T) -> Self - where - T: Into, - { + where T: Into { PhysAddr(align_up(self.0, align.into())) } fn align_down(&self, align: T) -> Self - where - T: Into, - { + where T: Into { PhysAddr(align_down(self.0, align.into())) } } @@ -95,16 +87,12 @@ impl AddressOps for VirtAddr { } fn align_up(&self, align: T) -> Self - where - T: Into, - { + where T: Into { VirtAddr(align_up(self.0, align.into())) } fn align_down(&self, align: T) -> Self - where - T: Into, - { + where T: Into { VirtAddr(align_down(self.0, align.into())) } } diff --git a/src/mm/page.rs b/src/mm/page.rs index 13d7df3..9ebd519 100644 --- a/src/mm/page.rs +++ b/src/mm/page.rs @@ -1,7 +1,9 @@ -use crate::mm::addr::{AddressOps, PhysAddr, VirtAddr}; -use bitflags::bitflags; use core::marker::PhantomData; +use bitflags::bitflags; + +use crate::mm::addr::{AddressOps, PhysAddr, VirtAddr}; + #[derive(Debug)] pub enum PagingError { AddressNotAligned, @@ -38,7 +40,7 @@ pub trait PageSize { pub struct Page { start_address: VirtAddr, - size: PhantomData, + size: PhantomData, } impl Page { @@ -47,7 +49,7 @@ impl Page { pub fn new(addr: VirtAddr) -> Self { Self { start_address: addr.align_down(Self::SIZE), - size: PhantomData, + size: PhantomData, } } } diff --git a/src/test_runner.rs b/src/test_runner.rs index 7386d44..60ffd1b 100644 --- a/src/test_runner.rs +++ b/src/test_runner.rs @@ -18,8 +18,7 @@ pub trait Testable { } impl Testable for T -where - T: Fn(), +where T: Fn() { fn run(&self) { info!("[TEST] [{}] Testing", core::any::type_name::()); diff --git a/src/utils/io.rs b/src/utils/io.rs index f6d069e..ce3e283 100644 --- a/src/utils/io.rs +++ b/src/utils/io.rs @@ -1,6 +1,5 @@ pub struct RawConsole -where - RawConsole: Printer; +where RawConsole: Printer; pub trait Printer: core::fmt::Write { fn put_char(c: char);