1#![no_std]
2#![feature(allocator_api)]
3
4extern crate alloc;
5
6#[macro_use]
7pub(crate) mod printf;
8#[macro_use]
9pub(crate) mod error;
10pub(crate) mod buf;
11pub(crate) mod console;
12pub(crate) mod entry;
13pub(crate) mod exec;
14pub(crate) mod file;
15pub(crate) mod fs;
16pub(crate) mod kalloc;
17pub(crate) mod kernelvec;
18pub(crate) mod log;
19pub(crate) mod memlayout;
20pub(crate) mod param;
21pub(crate) mod pipe;
22pub(crate) mod plic;
23pub(crate) mod proc;
24pub(crate) mod riscv;
25pub(crate) mod sleeplock;
26pub(crate) mod spinlock;
27pub(crate) mod start;
28pub(crate) mod swtch;
29pub(crate) mod sync;
30pub(crate) mod syscall;
31pub(crate) mod sysfile;
32pub(crate) mod sysproc;
33pub(crate) mod trampoline;
34pub(crate) mod trap;
35pub(crate) mod uart;
36pub(crate) mod virtio_disk;
37pub(crate) mod vm;
38
39pub mod abi;
40
41use core::sync::atomic::{AtomicBool, Ordering};
42
43static STARTED: AtomicBool = AtomicBool::new(false);
44
45pub extern "C" fn main() -> ! {
46 let cpu_id = unsafe { proc::current_id() };
47 if cpu_id == 0 {
48 unsafe {
49 console::init();
50
51 println!("");
52 println!("octopos kernel is booting");
53 println!("");
54
55 kalloc::init();
56 vm::init();
57 vm::init_hart();
58 proc::init();
59 trap::init();
60 trap::init_hart();
61 plic::init();
62 plic::init_hart();
63 buf::init();
64 virtio_disk::init();
65 proc::user_init();
66 }
67
68 println!("");
69
70 println!("hart {} is starting", cpu_id);
71
72 STARTED.store(true, Ordering::SeqCst);
73 } else {
74 while !STARTED.load(Ordering::SeqCst) {
75 core::hint::spin_loop()
76 }
77
78 println!("hart {} is starting", cpu_id);
79
80 unsafe {
81 vm::init_hart();
82 trap::init_hart();
83 plic::init_hart();
84 }
85 }
86
87 unsafe { proc::scheduler() };
88}
89
90pub fn panic_handler(info: &core::panic::PanicInfo<'_>) -> ! {
91 printf::panic(info)
92}