1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![no_std]
#![feature(alloc_prelude)]

extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[allow(unused_imports)]
use self::alloc_prelude::*;
use alloc::prelude::v1 as alloc_prelude;

use core::fmt::Debug;
use slos_filesystem::FsFileHandle;

pub mod null_system;

/// System console
pub trait SystemConsole: Debug + FsFileHandle {}

/// System CPU handling
pub trait SystemCpu {
	/// Disable interrupts on the current CPU
	fn interrupts_disable(&mut self);

	/// Enable interrupts on the current CPU
	fn interrupts_enable(&mut self);

	/// Return whether interrupts are enabled on the current CPU
	fn interrupts_are_enabled(&self) -> bool;

	/// Halt the current CPU
	fn halt(&mut self);
}

/// Optional `kmain` hook methods
pub trait SystemKmainHooks {
	/// `kmain` loop head hook
	///
	/// This is called at the beginning of every iteration of the `kmain`
	/// main loop.
	fn hook_kmain_loop_head(&mut self) {}

	/// `kmain` inner partial loop hook
	///
	/// This is called after **each** function in the `KMAIN_LOOP_PARTIALS`
	/// collection.
	fn hook_kmain_loop_inner_part(&mut self) {}
}

/// Base system hardware trait
pub trait SystemHardware: Send + Debug + SystemKmainHooks {
	/// Name of the crate implementing this system
	///
	/// This method should be implemented as the following:
	///
	/// ```no_build
	/// fn system_name(&self) -> &'static str {
	///	    env!("CARGO_PKG_NAME")
	/// }
	/// ```
	fn system_name(&self) -> &'static str;

	/// Get a reference to the default [`SystemConsole`] instance
	fn console(&mut self) -> &'static mut dyn SystemConsole;

	/// Has the HAL has requested an immediate kmain return?
	fn has_requested_return(&self) -> bool;

	/// Current CPU
	fn current_cpu(&mut self) -> &'static mut dyn SystemCpu;

	/// Virtualization
	fn virtualization(&self) -> Option<(&'static str, ())>;
}