diff --git a/src/kxos-frame/src/config.rs b/src/kxos-frame/src/config.rs index 5f1fc51d8..71bd2c993 100644 --- a/src/kxos-frame/src/config.rs +++ b/src/kxos-frame/src/config.rs @@ -1,7 +1,7 @@ #![allow(unused)] -pub const USER_STACK_SIZE: usize = 4096 * 2; -pub const KERNEL_STACK_SIZE: usize = 4096 * 2; +pub const USER_STACK_SIZE: usize = PAGE_SIZE * 2; +pub const KERNEL_STACK_SIZE: usize = PAGE_SIZE * 16; pub const KERNEL_HEAP_SIZE: usize = 0x1_000_000; pub const KERNEL_OFFSET: usize = 0xffffff00_00000000; diff --git a/src/kxos-frame/src/lib.rs b/src/kxos-frame/src/lib.rs index 45bf6acc6..d1a255531 100644 --- a/src/kxos-frame/src/lib.rs +++ b/src/kxos-frame/src/lib.rs @@ -33,10 +33,15 @@ use core::{mem, panic::PanicInfo}; pub use self::error::Error; pub(crate) use self::sync::up::UPSafeCell; +use alloc::vec::Vec; use bootloader::{ boot_info::{FrameBuffer, MemoryRegionKind}, BootInfo, }; +use trap::{TrapFrame, IrqLine, IrqCallbackHandle}; + +static mut IRQ_CALLBACK_LIST : Vec = Vec::new(); + pub fn init(boot_info: &'static mut BootInfo) { let siz = boot_info.framebuffer.as_ref().unwrap() as *const FrameBuffer as usize; @@ -61,6 +66,17 @@ pub fn init(boot_info: &'static mut BootInfo) { if !memory_init { panic!("memory init failed"); } + 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); + panic!("couldn't handler trap right now"); } #[inline(always)] diff --git a/src/kxos-frame/src/task/task.rs b/src/kxos-frame/src/task/task.rs index a8c1f2647..0f81d0530 100644 --- a/src/kxos-frame/src/task/task.rs +++ b/src/kxos-frame/src/task/task.rs @@ -4,9 +4,10 @@ use core::mem::size_of; use lazy_static::lazy_static; use crate::cell::Cell; -use crate::mm::PhysFrame; +use crate::config::{PAGE_SIZE, KERNEL_STACK_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::{prelude::*, UPSafeCell}; use super::processor::{current_task, schedule}; @@ -68,7 +69,7 @@ lazy_static! { }; task.task_inner.exclusive_access().task_status = TaskStatus::Runnable; task.task_inner.exclusive_access().ctx.rip = context_switch_to_user_space as usize; - task.task_inner.exclusive_access().ctx.regs.rsp = task.kstack.frame.end_pa().kvaddr().0 + task.task_inner.exclusive_access().ctx.regs.rsp = task.kstack.frame.end_pa().unwrap().kvaddr().0 as usize - size_of::() - size_of::(); @@ -77,13 +78,13 @@ lazy_static! { } pub struct KernelStack { - frame: PhysFrame, + frame: VmFrameVec, } impl KernelStack { pub fn new() -> Self { Self { - frame: PhysFrame::alloc().expect("out of memory"), + frame: VmFrameVec::allocate(&VmAllocOptions::new(KERNEL_STACK_SIZE/PAGE_SIZE)).expect("out of memory"), } } } @@ -149,7 +150,8 @@ impl Task { fn kernel_task_entry() { let current_task = current_task() .expect("no current task, it should have current task in kernel task entry"); - current_task.func.call(()) + current_task.func.call(()); + current_task.exit(); } let result = Self { func: Box::new(task_fn), @@ -168,7 +170,7 @@ 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().kvaddr().0 + result.task_inner.exclusive_access().ctx.regs.rsp = result.kstack.frame.end_pa().unwrap().kvaddr().0 as usize - size_of::() - size_of::(); @@ -186,6 +188,7 @@ impl Task { .kstack .frame .end_pa() + .unwrap() .kvaddr() .get_mut::() as *mut SyscallFrame) .sub(1) @@ -194,7 +197,7 @@ impl Task { pub(crate) fn trap_frame(&self) -> &mut TrapFrame { unsafe { - &mut *(self.kstack.frame.end_pa().kvaddr().get_mut::() as *mut TrapFrame) + &mut *(self.kstack.frame.end_pa().unwrap().kvaddr().get_mut::() as *mut TrapFrame) .sub(1) } } diff --git a/src/kxos-frame/src/vm/frame.rs b/src/kxos-frame/src/vm/frame.rs index 42e269fb4..9f462f2ae 100644 --- a/src/kxos-frame/src/vm/frame.rs +++ b/src/kxos-frame/src/vm/frame.rs @@ -43,6 +43,15 @@ impl VmFrameVec { self.0.push(new_frame); } + /// get the end pa of the collection + pub fn end_pa(&self) -> Option{ + if let Some(frame) = self.0.last(){ + Some(PhysAddr(frame.paddr()+PAGE_SIZE)) + }else{ + None + } + } + /// Pop a frame from the collection. pub fn pop(&mut self) -> Option { self.0.pop()