mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-29 04:13:24 +00:00
Format Rust code
This commit is contained in:
1
Makefile
1
Makefile
@ -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
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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,10 +171,10 @@ 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
|
||||
- size_of::<usize>()
|
||||
- size_of::<SyscallFrame>();
|
||||
result.task_inner.exclusive_access().ctx.regs.rsp =
|
||||
result.kstack.frame.end_pa().unwrap().kvaddr().0 as usize
|
||||
- size_of::<usize>()
|
||||
- size_of::<SyscallFrame>();
|
||||
|
||||
let arc_self = Arc::new(result);
|
||||
add_task(arc_self.clone());
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ impl VmSpace {
|
||||
memory_set: unsafe { UPSafeCell::new(MemorySet::new()) },
|
||||
}
|
||||
}
|
||||
/// Activate the page table, load root physical address to cr3
|
||||
/// Activate the page table, load root physical address to cr3
|
||||
pub unsafe fn activate(&self) {
|
||||
x86_64_util::set_cr3(self.memory_set.exclusive_access().pt.root_pa.0);
|
||||
}
|
||||
|
@ -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)
|
||||
},
|
||||
_ => {
|
||||
Err("Unkonwn segment data type")
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(data) => match data {
|
||||
SegmentData::Note64(_, data) | SegmentData::Undefined(data) => Ok(data),
|
||||
_ => Err("Unkonwn segment data type"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -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};
|
||||
|
Reference in New Issue
Block a user