XeOS/src/main.rs

65 lines
1.5 KiB
Rust
Raw Permalink Normal View History

2019-10-23 23:19:02 +00:00
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(xe_os::test_runner)]
#![reexport_test_harness_main = "test_main"]
2019-10-24 00:30:47 +00:00
extern crate alloc;
2020-03-26 15:06:17 +00:00
use alloc::string::ToString;
2019-10-24 00:30:47 +00:00
use bootloader::{entry_point, BootInfo};
2019-10-23 23:19:02 +00:00
use core::panic::PanicInfo;
2020-03-27 21:11:09 +00:00
use xe_os::{clock, init, println, wasm, task::{Task, executor::Executor, keyboard}};
2019-10-23 23:19:02 +00:00
2019-10-24 00:30:47 +00:00
entry_point!(kernel_main);
fn kernel_main(boot_info: &'static BootInfo) -> ! {
2019-10-24 15:34:10 +00:00
init(&boot_info);
2019-10-23 23:19:02 +00:00
#[cfg(test)]
test_main();
2019-10-24 14:43:38 +00:00
// Read the rtc date time using this year
2019-10-24 15:34:10 +00:00
let now = clock::current_time();
2020-03-28 14:33:57 +00:00
println!(" started at {}", now.to_string());
2019-10-24 14:43:38 +00:00
2020-03-27 21:11:09 +00:00
let mut executor = Executor::new();
executor.spawn(Task::new(h_task()));
executor.spawn(Task::new(example_task()));
executor.spawn(Task::new(keyboard::print_keypresses()));
2020-03-28 14:33:57 +00:00
println!("[a] Starting async executor");
2020-03-27 21:11:09 +00:00
executor.run();
2019-10-23 23:19:02 +00:00
}
// our existing panic handler
#[cfg(not(test))] // new attribute
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
2019-10-23 23:36:24 +00:00
xe_os::hlt_loop();
2019-10-23 23:19:02 +00:00
}
// our panic handler in test mode
#[cfg(test)]
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
xe_os::test_panic_handler(info);
}
2020-03-27 21:11:09 +00:00
async fn async_number() -> u32 {
42
}
async fn example_task() {
2020-03-28 14:33:57 +00:00
println!("[n] Starting number task");
2020-03-27 21:11:09 +00:00
let number = async_number().await;
2020-03-28 14:33:57 +00:00
println!(" async number: {}", number);
2020-03-27 21:11:09 +00:00
}
async fn h_task() {
2020-03-28 14:33:57 +00:00
println!("[w] Running WASM");
2020-03-27 21:11:09 +00:00
wasm::run().await;
println!(" success");
}