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 @cd docs && mdbook build # Build mdBook
check: check:
@cd src && cargo check # Check dependency errors
@cd src && cargo fmt --check # Check Rust format issues @cd src && cargo fmt --check # Check Rust format issues
@cd src && cargo clippy # Check common programming mistakes @cd src && cargo clippy # Check common programming mistakes

View File

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

View File

@ -4,10 +4,10 @@ use core::mem::size_of;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use crate::cell::Cell; 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::trap::{CalleeRegs, SyscallFrame, TrapFrame};
use crate::user::{syscall_switch_to_user_space, trap_switch_to_user_space, UserSpace}; 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 crate::{prelude::*, UPSafeCell};
use super::processor::{current_task, schedule}; use super::processor::{current_task, schedule};
@ -84,7 +84,8 @@ pub struct KernelStack {
impl KernelStack { impl KernelStack {
pub fn new() -> Self { pub fn new() -> Self {
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,10 +171,10 @@ impl Task {
result.task_inner.exclusive_access().task_status = TaskStatus::Runnable; 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.rip = kernel_task_entry as usize;
result.task_inner.exclusive_access().ctx.regs.rsp = result.kstack.frame.end_pa().unwrap().kvaddr().0 result.task_inner.exclusive_access().ctx.regs.rsp =
as usize result.kstack.frame.end_pa().unwrap().kvaddr().0 as usize
- size_of::<usize>() - size_of::<usize>()
- size_of::<SyscallFrame>(); - size_of::<SyscallFrame>();
let arc_self = Arc::new(result); let arc_self = Arc::new(result);
add_task(arc_self.clone()); add_task(arc_self.clone());
@ -197,7 +198,13 @@ impl Task {
pub(crate) fn trap_frame(&self) -> &mut TrapFrame { pub(crate) fn trap_frame(&self) -> &mut TrapFrame {
unsafe { 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) .sub(1)
} }
} }

View File

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

View File

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

View File

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