71 lines
1.8 KiB
Rust
71 lines
1.8 KiB
Rust
mod simple;
|
|
|
|
use domain::memory::page_pool::PagePool;
|
|
use platform::Platform;
|
|
use types::{
|
|
address::{EntryPoint, PhysicalAddress, StackPointer},
|
|
bounded::Priority,
|
|
id::{CoreId, IrqId, ProcessId},
|
|
time::{Ticks, TimerDuration, TimeSlice},
|
|
};
|
|
|
|
use domain::memory::MemoryRegion;
|
|
use domain::thread::SavedContext;
|
|
|
|
use crate::Kernel;
|
|
|
|
pub struct MockPlatform {
|
|
ticks: Ticks,
|
|
core: CoreId,
|
|
cores: u8,
|
|
}
|
|
|
|
impl MockPlatform {
|
|
pub fn new(num_cores: u8) -> Self {
|
|
Self {
|
|
ticks: Ticks::from_raw(0),
|
|
core: CoreId::from_raw(0),
|
|
cores: num_cores,
|
|
}
|
|
}
|
|
|
|
pub fn set_ticks(&mut self, ticks: Ticks) {
|
|
self.ticks = ticks;
|
|
}
|
|
}
|
|
|
|
impl Platform for MockPlatform {
|
|
fn configure_protection(&mut self, _process: ProcessId, _regions: &[MemoryRegion]) {}
|
|
fn context_switch(&mut self, _from: &mut SavedContext, _to: &SavedContext) {}
|
|
fn enable_user_mode(&mut self, _entry: EntryPoint, _stack: StackPointer) -> ! {
|
|
loop {}
|
|
}
|
|
fn set_timer(&mut self, _duration: TimerDuration) {}
|
|
fn current_ticks(&self) -> Ticks {
|
|
self.ticks
|
|
}
|
|
fn mask_irq(&mut self, _irq: IrqId) {}
|
|
fn unmask_irq(&mut self, _irq: IrqId) {}
|
|
fn send_ipi(&mut self, _target: CoreId) {}
|
|
fn core_id(&self) -> CoreId {
|
|
self.core
|
|
}
|
|
fn num_cores(&self) -> u8 {
|
|
self.cores
|
|
}
|
|
}
|
|
|
|
pub fn test_kernel() -> Kernel<MockPlatform> {
|
|
let mock = MockPlatform::new(1);
|
|
let pool = PagePool::new(PhysicalAddress::from_raw(0x8000_0000), 1024);
|
|
Kernel::new(mock, pool)
|
|
}
|
|
|
|
pub fn kernel_with_process() -> (Kernel<MockPlatform>, ProcessId) {
|
|
let mut kernel = test_kernel();
|
|
let (pid, _tid) = kernel
|
|
.boot(Priority::new(16).unwrap(), TimeSlice::new(100))
|
|
.unwrap();
|
|
(kernel, pid)
|
|
}
|