kernel/state/kstate.rs
1// SPDX-License-Identifier: GPL-3.0-only
2//! Central kernel state aggregate ([`KState`]): one static holding every OS
3//! subsystem's state.
4//!
5//! Authors: MarioS271
6
7use crate::cpu::state::Cpu;
8use crate::kprint::state::KPrint;
9use crate::mm::state::Mm;
10use crate::sched::state::sched::Sched;
11use crate::vfs::state::Vfs;
12
13pub static KSTATE: KState = KState {
14 cpu: Cpu::new(),
15 kprint: KPrint::new(),
16 mm: Mm::new(),
17 sched: Sched::new(),
18 vfs: Vfs::new()
19};
20
21/// The central kernel state aggregate; one field per OS subsystem domain.
22pub struct KState {
23 pub cpu: Cpu,
24 pub kprint: KPrint,
25 pub mm: Mm,
26 pub sched: Sched,
27 pub vfs: Vfs
28}
29
30impl KState {
31 /// Calls the `init` method of all subsystems which have one
32 ///
33 /// > This method should be the very first call the kernel makes, as without it,
34 /// a lot of [`KSTATE`] will be in an incorrect state for the boot process
35 ///
36 /// Use this to initialize any non-zero default values; those aren't initialized in
37 /// the const fn new, as that would increase the binary size by the size of the entire KSTATE
38 /// struct, which we don't want
39 pub fn init(&self) {
40 self.kprint.init();
41 self.mm.init();
42 self.sched.init();
43 }
44}