chore: add rustfmt.toml and format

This commit is contained in:
Paul Pan 2024-02-01 19:12:56 +08:00
parent c321d48860
commit 145b8cf076
8 changed files with 47 additions and 37 deletions

View File

@ -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",
},
];

14
rustfmt.toml Normal file
View File

@ -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

View File

@ -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
}

View File

@ -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();

View File

@ -28,15 +28,11 @@ pub trait AddressOps {
fn as_usize(&self) -> usize;
fn as_non_zero_usize(&self) -> Option<NonZeroUsize>;
fn align_up<T>(&self, align: T) -> Self
where
T: Into<usize>;
where T: Into<usize>;
fn align_down<T>(&self, align: T) -> Self
where
T: Into<usize>;
where T: Into<usize>;
fn is_aligned<T>(&self, align: T) -> bool
where
T: Into<usize> + Copy,
{
where T: Into<usize> + 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<T>(&self, align: T) -> Self
where
T: Into<usize>,
{
where T: Into<usize> {
PhysAddr(align_up(self.0, align.into()))
}
fn align_down<T>(&self, align: T) -> Self
where
T: Into<usize>,
{
where T: Into<usize> {
PhysAddr(align_down(self.0, align.into()))
}
}
@ -95,16 +87,12 @@ impl AddressOps for VirtAddr {
}
fn align_up<T>(&self, align: T) -> Self
where
T: Into<usize>,
{
where T: Into<usize> {
VirtAddr(align_up(self.0, align.into()))
}
fn align_down<T>(&self, align: T) -> Self
where
T: Into<usize>,
{
where T: Into<usize> {
VirtAddr(align_down(self.0, align.into()))
}
}

View File

@ -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<S: PageSize> {
start_address: VirtAddr,
size: PhantomData<S>,
size: PhantomData<S>,
}
impl<S: PageSize> Page<S> {
@ -47,7 +49,7 @@ impl<S: PageSize> Page<S> {
pub fn new(addr: VirtAddr) -> Self {
Self {
start_address: addr.align_down(Self::SIZE),
size: PhantomData,
size: PhantomData,
}
}
}

View File

@ -18,8 +18,7 @@ pub trait Testable {
}
impl<T> Testable for T
where
T: Fn(),
where T: Fn()
{
fn run(&self) {
info!("[TEST] [{}] Testing", core::any::type_name::<T>());

View File

@ -1,6 +1,5 @@
pub struct RawConsole
where
RawConsole: Printer;
where RawConsole: Printer;
pub trait Printer: core::fmt::Write {
fn put_char(c: char);