extend kernel stack to 64KB

This commit is contained in:
Yuke Peng
2022-09-04 23:41:15 -07:00
parent f706699cf1
commit bce4e9ffd5
4 changed files with 37 additions and 9 deletions

View File

@ -1,7 +1,7 @@
#![allow(unused)] #![allow(unused)]
pub const USER_STACK_SIZE: usize = 4096 * 2; pub const USER_STACK_SIZE: usize = PAGE_SIZE * 2;
pub const KERNEL_STACK_SIZE: usize = 4096 * 2; pub const KERNEL_STACK_SIZE: usize = PAGE_SIZE * 16;
pub const KERNEL_HEAP_SIZE: usize = 0x1_000_000; pub const KERNEL_HEAP_SIZE: usize = 0x1_000_000;
pub const KERNEL_OFFSET: usize = 0xffffff00_00000000; pub const KERNEL_OFFSET: usize = 0xffffff00_00000000;

View File

@ -33,10 +33,15 @@ use core::{mem, panic::PanicInfo};
pub use self::error::Error; pub use self::error::Error;
pub(crate) use self::sync::up::UPSafeCell; pub(crate) use self::sync::up::UPSafeCell;
use alloc::vec::Vec;
use bootloader::{ use bootloader::{
boot_info::{FrameBuffer, MemoryRegionKind}, boot_info::{FrameBuffer, MemoryRegionKind},
BootInfo, BootInfo,
}; };
use trap::{TrapFrame, IrqLine, IrqCallbackHandle};
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;
@ -61,6 +66,17 @@ pub fn init(boot_info: &'static mut BootInfo) {
if !memory_init { if !memory_init {
panic!("memory init failed"); 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)] #[inline(always)]

View File

@ -4,9 +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::mm::PhysFrame; use crate::config::{PAGE_SIZE, KERNEL_STACK_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::{prelude::*, UPSafeCell}; use crate::{prelude::*, UPSafeCell};
use super::processor::{current_task, schedule}; 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().task_status = TaskStatus::Runnable;
task.task_inner.exclusive_access().ctx.rip = context_switch_to_user_space as usize; 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 as usize
- size_of::<usize>() - size_of::<usize>()
- size_of::<SyscallFrame>(); - size_of::<SyscallFrame>();
@ -77,13 +78,13 @@ lazy_static! {
} }
pub struct KernelStack { pub struct KernelStack {
frame: PhysFrame, frame: VmFrameVec,
} }
impl KernelStack { impl KernelStack {
pub fn new() -> Self { pub fn new() -> Self {
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() { fn kernel_task_entry() {
let current_task = current_task() let current_task = current_task()
.expect("no current task, it should have current task in kernel task entry"); .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 { let result = Self {
func: Box::new(task_fn), 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().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().kvaddr().0 result.task_inner.exclusive_access().ctx.regs.rsp = result.kstack.frame.end_pa().unwrap().kvaddr().0
as usize as usize
- size_of::<usize>() - size_of::<usize>()
- size_of::<SyscallFrame>(); - size_of::<SyscallFrame>();
@ -186,6 +188,7 @@ impl Task {
.kstack .kstack
.frame .frame
.end_pa() .end_pa()
.unwrap()
.kvaddr() .kvaddr()
.get_mut::<SyscallFrame>() as *mut SyscallFrame) .get_mut::<SyscallFrame>() as *mut SyscallFrame)
.sub(1) .sub(1)
@ -194,7 +197,7 @@ 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().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

@ -43,6 +43,15 @@ impl VmFrameVec {
self.0.push(new_frame); self.0.push(new_frame);
} }
/// 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{
None
}
}
/// Pop a frame from the collection. /// Pop a frame from the collection.
pub fn pop(&mut self) -> Option<VmFrame> { pub fn pop(&mut self) -> Option<VmFrame> {
self.0.pop() self.0.pop()