rustubs/
kthread.rs

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
//! kernel threads
pub mod meeseeks;
pub use meeseeks::Meeseeks;

pub mod echo;
pub use echo::Echo;

pub mod lazy;
pub use lazy::Lazy;

pub mod kshell;
pub use kshell::Kshell;

use crate::proc::sync::LEAVE_L2;

pub trait KThread {
	fn entry() -> !;
	/// the actual entry, where we also explicitly release L2
	extern "C" fn _entry() {
		LEAVE_L2();
		Self::entry();
	}
	fn get_entry() -> u64 { Self::_entry as u64 }
}

pub struct Idle {}
impl KThread for Idle {
	fn entry() -> ! {
		use core::arch::asm;
		loop {
			unsafe { asm!("sti; hlt") };
		}
	}
}