mirror of
https://github.com/panpaul/tiny_os
synced 2024-09-20 09:45:19 +08:00
chore: add rustfmt.toml and format
This commit is contained in:
parent
165717621a
commit
c28181888d
14
rustfmt.toml
Normal file
14
rustfmt.toml
Normal 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
|
@ -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 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
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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>());
|
||||
|
@ -1,6 +1,5 @@
|
||||
pub struct RawConsole
|
||||
where
|
||||
RawConsole: Printer;
|
||||
where RawConsole: Printer;
|
||||
|
||||
pub trait Printer: core::fmt::Write {
|
||||
fn put_char(c: char);
|
||||
|
Loading…
Reference in New Issue
Block a user