forked from AbleOS/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 ecah;
|
||||||
mod mem;
|
mod mem;
|
||||||
|
|
||||||
use {
|
use {
|
||||||
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
crate::{arch, ipc::buffer::IpcBuffer, kmain::IPC_BUFFERS},
|
||||||
alloc::boxed::Box,
|
alloc::boxed::Box,
|
||||||
core::{default, future::Future, marker::PhantomData, task::Poll},
|
core::{default, future::Future, marker::PhantomData, ptr::NonNull, task::Poll},
|
||||||
hbvm::{
|
hbvm::{
|
||||||
mem::{
|
mem::{
|
||||||
softpaging::{icache::ICache, HandlePageFault, SoftPagedMem},
|
softpaging::{icache::ICache, HandlePageFault, SoftPagedMem},
|
||||||
|
@ -17,6 +15,7 @@ use {
|
||||||
log::{debug, error, info, trace, warn},
|
log::{debug, error, info, trace, warn},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const STACK_SIZE: usize = 1024 * 1024;
|
||||||
const TIMER_QUOTIENT: usize = 100;
|
const TIMER_QUOTIENT: usize = 100;
|
||||||
type Vm = hbvm::Vm<mem::Memory, TIMER_QUOTIENT>;
|
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);
|
vm.write_reg(254, stack_top as u64);
|
||||||
|
|
||||||
ExecThread {
|
ExecThread {
|
||||||
|
@ -54,7 +53,7 @@ impl<'p> ExecThread<'p> {
|
||||||
|
|
||||||
impl<'p> Drop for ExecThread<'p> {
|
impl<'p> Drop for ExecThread<'p> {
|
||||||
fn drop(&mut self) {
|
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 {
|
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> {
|
fn allocate_stack() -> NonNull<u8> {
|
||||||
|
|
Loading…
Reference in a new issue