mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-23 17:33:23 +00:00
extend kernel stack to 64KB
This commit is contained in:
@ -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;
|
||||
|
@ -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<IrqCallbackHandle> = 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)]
|
||||
|
@ -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::<usize>()
|
||||
- size_of::<SyscallFrame>();
|
||||
@ -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::<usize>()
|
||||
- size_of::<SyscallFrame>();
|
||||
@ -186,6 +188,7 @@ impl Task {
|
||||
.kstack
|
||||
.frame
|
||||
.end_pa()
|
||||
.unwrap()
|
||||
.kvaddr()
|
||||
.get_mut::<SyscallFrame>() 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::<TrapFrame>() as *mut TrapFrame)
|
||||
&mut *(self.kstack.frame.end_pa().unwrap().kvaddr().get_mut::<TrapFrame>() as *mut TrapFrame)
|
||||
.sub(1)
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,15 @@ impl VmFrameVec {
|
||||
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.
|
||||
pub fn pop(&mut self) -> Option<VmFrame> {
|
||||
self.0.pop()
|
||||
|
Reference in New Issue
Block a user