forked from vmware-archive/node-replicated-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
142 lines (127 loc) · 3.51 KB
/
Copy pathmain.rs
File metadata and controls
142 lines (127 loc) · 3.51 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright © 2021 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! The nrk kernel.
//!
//! Here we define the core modules and the main function that the kernel runs after
//! the arch-specific initialization is done (see `arch/x86_64/mod.rs` for an example).
#![cfg_attr(target_os = "none", no_std)]
#![deny(warnings)]
#![cfg_attr(target_family = "unix", allow(unused))]
#![feature(
is_sorted,
intrinsics,
core_intrinsics,
lang_items,
asm_const,
start,
box_syntax,
panic_info_message,
allocator_api,
linkage,
c_variadic,
drain_filter,
let_chains,
new_uninit,
get_mut_unchecked,
const_refs_to_cell,
nonnull_slice_from_raw_parts,
cell_update,
thread_local,
maybe_uninit_write_slice,
alloc_error_handler
)]
extern crate alloc;
/// The x86-64 platform specific code.
#[cfg(all(target_arch = "x86_64", target_os = "none"))]
#[path = "arch/x86_64/mod.rs"]
pub mod arch;
/// The unix platform specific code.
#[cfg(all(target_arch = "x86_64", target_family = "unix"))]
#[path = "arch/unix/mod.rs"]
pub mod arch;
/// To write unit-tests for our bare-metal code, we include the x86_64
/// arch-specific code on the `unix` platform.
#[cfg(all(test, target_arch = "x86_64", target_family = "unix"))]
#[path = "arch/x86_64/mod.rs"]
pub mod x86_64_arch;
mod environment;
mod error;
mod fs;
mod graphviz;
mod memory;
mod nr;
mod nrproc;
#[macro_use]
mod prelude;
mod cmdline;
mod fallible_string;
mod mpmc;
mod pci;
mod process;
mod scheduler;
mod stack;
mod syscalls;
mod transport;
pub mod panic;
use spin::Once;
/// Arguments passed form the bootloader to the kernel.
pub(crate) static KERNEL_ARGS: Once<&'static crate::arch::KernelArgs> = Once::new();
/// Parsed arguments passed from the user to the kernel (via command line args).
pub(crate) static CMDLINE: Once<cmdline::CommandLineArguments> = Once::new();
#[cfg(feature = "integration-test")]
mod integration_tests;
/// A kernel exit status.
///
/// This is used to communicate the exit status
/// (if somehow possible) to the outside world.
///
/// If we run in qemu a special ioport can be used
/// to exit the VM and communicate the status to the host.
///
/// # Notes
/// If this type is modified, update the `run.py` script and `testutils/*.rs` as well.
#[derive(Copy, Clone, Debug)]
#[repr(u8)]
pub(crate) enum ExitReason {
Ok = 0,
ReturnFromMain = 1,
KernelPanic = 2,
OutOfMemory = 3,
UnhandledInterrupt = 4,
GeneralProtectionFault = 5,
PageFault = 6,
UserSpaceError = 7,
ExceptionDuringInitialization = 8,
UnrecoverableError = 9,
}
/// Kernel entry-point (after initialization has completed).
///
/// # Notes
/// This function is executed from each core (which is
/// different from a traditional main routine).
pub(crate) fn main() {
#[cfg(feature = "rackscale")]
if CMDLINE
.get()
.map_or(false, |c| c.mode == cmdline::Mode::Controller)
{
arch::rackscale::controller::run();
}
#[cfg(not(feature = "integration-test"))]
{
let ret = arch::process::spawn("init");
if let Err(e) = ret {
log::warn!("{}", e);
}
crate::scheduler::schedule()
}
#[cfg(feature = "integration-test")]
{
log::debug!("About to run '{:?}'", CMDLINE.get().map(|c| c.test));
if let Some(test) = CMDLINE.get().and_then(|c| c.test) {
integration_tests::run_test(test)
} else {
log::error!("No test selected, exiting...");
}
}
}