Format Rust code

This commit is contained in:
Tate, Hongliang Tian
2022-09-05 15:27:44 -07:00
parent fd50d184fa
commit 128ffa0bff
7 changed files with 32 additions and 34 deletions

View File

@ -23,7 +23,6 @@ docs:
@cd docs && mdbook build # Build mdBook
check:
@cd src && cargo check # Check dependency errors
@cd src && cargo fmt --check # Check Rust format issues
@cd src && cargo clippy # Check common programming mistakes

View File

@ -38,10 +38,9 @@ use bootloader::{
boot_info::{FrameBuffer, MemoryRegionKind},
BootInfo,
};
use trap::{TrapFrame, IrqLine, IrqCallbackHandle};
static mut IRQ_CALLBACK_LIST : Vec<IrqCallbackHandle> = Vec::new();
use trap::{IrqCallbackHandle, IrqLine, TrapFrame};
static mut IRQ_CALLBACK_LIST: Vec<IrqCallbackHandle> = Vec::new();
pub fn init(boot_info: &'static mut BootInfo) {
let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize;
@ -66,16 +65,14 @@ pub fn init(boot_info: &'static mut BootInfo) {
if !memory_init {
panic!("memory init failed");
}
unsafe{
for i in 0..256{
unsafe {
for i in 0..256 {
IRQ_CALLBACK_LIST.push(IrqLine::acquire(i as u8).on_active(general_handler))
}
}
}
fn general_handler(trap_frame: TrapFrame){
println!("{:?}",trap_frame);
fn general_handler(trap_frame: TrapFrame) {
println!("{:?}", trap_frame);
panic!("couldn't handler trap right now");
}

View File

@ -4,10 +4,10 @@ use core::mem::size_of;
use lazy_static::lazy_static;
use crate::cell::Cell;
use crate::config::{PAGE_SIZE, KERNEL_STACK_SIZE};
use crate::config::{KERNEL_STACK_SIZE, PAGE_SIZE};
use crate::trap::{CalleeRegs, SyscallFrame, TrapFrame};
use crate::user::{syscall_switch_to_user_space, trap_switch_to_user_space, UserSpace};
use crate::vm::{VmFrameVec, VmAllocOptions};
use crate::vm::{VmAllocOptions, VmFrameVec};
use crate::{prelude::*, UPSafeCell};
use super::processor::{current_task, schedule};
@ -84,7 +84,8 @@ pub struct KernelStack {
impl KernelStack {
pub fn new() -> Self {
Self {
frame: VmFrameVec::allocate(&VmAllocOptions::new(KERNEL_STACK_SIZE/PAGE_SIZE)).expect("out of memory"),
frame: VmFrameVec::allocate(&VmAllocOptions::new(KERNEL_STACK_SIZE / PAGE_SIZE))
.expect("out of memory"),
}
}
}
@ -170,8 +171,8 @@ impl Task {
result.task_inner.exclusive_access().task_status = TaskStatus::Runnable;
result.task_inner.exclusive_access().ctx.rip = kernel_task_entry as usize;
result.task_inner.exclusive_access().ctx.regs.rsp = result.kstack.frame.end_pa().unwrap().kvaddr().0
as usize
result.task_inner.exclusive_access().ctx.regs.rsp =
result.kstack.frame.end_pa().unwrap().kvaddr().0 as usize
- size_of::<usize>()
- size_of::<SyscallFrame>();
@ -197,7 +198,13 @@ impl Task {
pub(crate) fn trap_frame(&self) -> &mut TrapFrame {
unsafe {
&mut *(self.kstack.frame.end_pa().unwrap().kvaddr().get_mut::<TrapFrame>() as *mut TrapFrame)
&mut *(self
.kstack
.frame
.end_pa()
.unwrap()
.kvaddr()
.get_mut::<TrapFrame>() as *mut TrapFrame)
.sub(1)
}
}

View File

@ -44,10 +44,10 @@ impl VmFrameVec {
}
/// get the end pa of the collection
pub fn end_pa(&self) -> Option<PhysAddr>{
if let Some(frame) = self.0.last(){
Some(PhysAddr(frame.paddr()+PAGE_SIZE))
}else{
pub fn end_pa(&self) -> Option<PhysAddr> {
if let Some(frame) = self.0.last() {
Some(PhysAddr(frame.paddr() + PAGE_SIZE))
} else {
None
}
}

View File

@ -261,15 +261,9 @@ fn read_segment_data<'a>(
) -> Result<&'a [u8], &'static str> {
match segment.get_data(&elf_file) {
Err(msg) => Err(msg),
Ok(data) => {
match data {
SegmentData::Note64(_, data) | SegmentData::Undefined(data) => {
Ok(data)
Ok(data) => match data {
SegmentData::Note64(_, data) | SegmentData::Undefined(data) => Ok(data),
_ => Err("Unkonwn segment data type"),
},
_ => {
Err("Unkonwn segment data type")
}
}
}
}
}

View File

@ -1,9 +1,10 @@
use alloc::sync::Arc;
use kxos_frame::{
cpu::CpuContext,
debug,
task::Task,
user::{UserEvent, UserMode, UserSpace},
vm::VmSpace, debug,
vm::VmSpace,
};
use crate::{memory::load_elf_to_vm_space, syscall::syscall_handler};