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
#![no_std]
#![deny(missing_docs)]
#![feature(alloc_error_handler)]
#![feature(core_intrinsics)]
extern crate alloc;
use {
core::{slice, str},
executor::Executor,
log::{debug, error},
xen::{
console::Writer,
events, grant_table, init_info, println,
scheduler::{schedule_operation, Command, ShutdownReason},
sections::{edata, end, erodata, etext, text_start},
time,
xen_sys::start_info_t,
xenbus, xenstore,
},
};
mod executor;
mod logger;
mod mm;
mod net;
mod trap;
#[cfg(feature = "test")]
mod test;
pub fn launch(start_info: *mut start_info_t) {
init_info(start_info);
let start_info = unsafe { &*start_info };
Writer::init(start_info);
logger::init();
println!();
println!(" _____ _____ _____ _____ _____ __ __ _____ _____ ");
println!(" | __|_ _| _ | _ | | | | __|_ _|");
println!(" |__ | | | | | _| | | |__ | | | ");
println!(" |_____| |_| |__|__|__|__|_____|_____|_____| |_| ");
println!(" █▀█ ▀▄▀ █ █▀▄ █▀▀ ");
println!(" █▄█ █ █ █ █▄▀ ██▄ ");
println!();
print_start_info(start_info);
trap::init();
events::init();
time::init();
mm::init(start_info);
grant_table::init();
xenstore::init();
xenbus::init();
#[cfg(feature = "test")]
test::tests();
let mut executor = Executor::new();
executor.spawn(net::server());
executor.run();
Writer::flush();
schedule_operation(Command::Shutdown(ShutdownReason::Poweroff));
}
fn print_start_info(start_info: &start_info_t) {
let magic_str = str::from_utf8(unsafe {
slice::from_raw_parts(start_info.magic.as_ptr() as *const u8, 32)
})
.unwrap();
debug!(" platform: {}", magic_str);
debug!(" domain ID: {}", xen::xenstore::domain_id());
debug!(" nr_pages: {}", start_info.nr_pages);
debug!("shared_info: {:#X}", start_info.shared_info);
debug!(" pt_base: {:#X}", start_info.pt_base);
debug!(" mfn_list: {:#X}", start_info.mfn_list);
debug!(" mod_start: {:#X}", start_info.mod_start);
debug!(" mod_len: {}", start_info.mod_len);
debug!(" _text: {:#X}", text_start());
debug!(" _etext: {:#X}", etext());
debug!(" _erodata: {:#X}", erodata());
debug!(" _edata: {:#X}", edata());
debug!(" _end: {:#X}", end());
debug!("");
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
error!("{}", info);
Writer::flush();
schedule_operation(Command::Shutdown(ShutdownReason::Crash));
loop {}
}