forked from koniifer/ableos
Stack grows downwards, baka.
This commit is contained in:
parent
0f7525b7e3
commit
d396da5f3c
|
@ -1,12 +1,10 @@
|
|||
use core::ptr::NonNull;
|
||||
|
||||
mod ecah;
|
||||
mod mem;
|
||||
|
||||
use {
|
||||
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
||||
alloc::boxed::Box,
|
||||
core::{default, future::Future, marker::PhantomData, task::Poll},
|
||||
core::{default, future::Future, marker::PhantomData, ptr::NonNull, task::Poll},
|
||||
hbvm::{
|
||||
mem::{
|
||||
softpaging::{icache::ICache, HandlePageFault, SoftPagedMem},
|
||||
|
@ -17,6 +15,7 @@ use {
|
|||
log::{debug, error, info, trace, warn},
|
||||
};
|
||||
|
||||
const STACK_SIZE: usize = 1024 * 1024;
|
||||
const TIMER_QUOTIENT: usize = 100;
|
||||
type Vm = hbvm::Vm<mem::Memory, TIMER_QUOTIENT>;
|
||||
|
||||
|
@ -41,7 +40,7 @@ impl<'p> ExecThread<'p> {
|
|||
)
|
||||
};
|
||||
|
||||
let stack_top = allocate_stack().as_ptr();
|
||||
let stack_top = unsafe { allocate_stack().as_ptr().add(STACK_SIZE - 1) };
|
||||
vm.write_reg(254, stack_top as u64);
|
||||
|
||||
ExecThread {
|
||||
|
@ -54,7 +53,7 @@ impl<'p> ExecThread<'p> {
|
|||
|
||||
impl<'p> Drop for ExecThread<'p> {
|
||||
fn drop(&mut self) {
|
||||
unsafe { alloc::alloc::dealloc(self.stack_top, stack_layout()) };
|
||||
unsafe { alloc::alloc::dealloc(self.stack_top.sub(STACK_SIZE - 1), stack_layout()) };
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,7 +110,7 @@ impl HandlePageFault for PageFaultHandler {
|
|||
}
|
||||
|
||||
const fn stack_layout() -> core::alloc::Layout {
|
||||
unsafe { alloc::alloc::Layout::from_size_align_unchecked(1024 * 1024, 4096) }
|
||||
unsafe { alloc::alloc::Layout::from_size_align_unchecked(STACK_SIZE, 4096) }
|
||||
}
|
||||
|
||||
fn allocate_stack() -> NonNull<u8> {
|
||||
|
|
Loading…
Reference in a new issue