aboutsummaryrefslogtreecommitdiff
path: root/src/kernel.rs
blob: 1c3bfac20a9414e4bc77588990cf6b56c3f4a20a (plain)
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
//! # Kernel Code
//!
//! ## Initializes the peripherals
//!  - UART
//!  - Allocators

#![doc(html_logo_url = "https://raw.githubusercontent.com/rust-embedded/wg/master/assets/logo/ewg-logo-blue-white-on-transparent.png")]

#![allow(non_snake_case)]
#![allow(clippy::upper_case_acronyms,dead_code)]
#![feature(format_args_nl)]
#![feature(panic_info_message)]
#![feature(trait_alias)]
#![feature(exclusive_range_pattern)]
#![feature(default_alloc_error_handler)]
#![no_main]
#![no_std]

extern crate alloc;

mod console;
mod cpu;
mod draw;
mod mem;
mod panic_wait;
mod print;
mod sync;
mod uart;
use crate::console::console;
use crate::mem::alloc::alloc;

/// # Initialization Code
///
/// Initializes
///  - Allocators
///  - UART
///
/// After initialization, jump to
/// the regular main.
unsafe fn kernel_init() -> ! {
	console().init().unwrap();
	alloc().init().unwrap();
	kernel_main()
}

/// # Post-initialization
///
/// TODO: Figure out what to do here
fn kernel_main() -> ! {
	#[cfg(not(feature="verbose"))]
	{
		draw::draw_ukraine_flag();
		println!();
		draw::draw_american_flag();
		println!();

		println!("\x1b[91mInitialized\x1b[0m \x1b[92m{}\x1b[0m \x1b[93mv{}\x1b[0m", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
		println!("\x1b[94mAuthors:\x1b[0m \x1b[95m{}\x1b[0m", env!("CARGO_PKG_AUTHORS"));
		use crate::console::interface::Statistics;
		println!("Characters written to UART: \x1b[91m{}\x1b[0m", console().chars_written());
	}

	#[cfg(feature="verbose")]
	{
		use alloc::boxed::Box;
		{
			let a: Box<u8> = Box::new(1);
			println!("Box: {}", a);
		}
		{
			let a: Box<u8> = Box::new(2);
			let b: Box<u8> = Box::new(3);
			let c: Box<u8> = Box::new(4);
			println!("Boxes: {}, {}, {}", a, b, c);
		}
		{
			let a: Box<u8> = Box::new(5);
			let b: Box<u8> = Box::new(6);
			let c: Box<u8> = Box::new(7);
			println!("Boxes: {}, {}, {}", a, b, c);
		}
		println!("U8: {:?}", mem::alloc::U8_GRAND_ALLOC);
		use alloc::string::String;
		{
			let mut s = String::new();
			for _ in 0..128 {
				s += "TEST";
			}
			println!("String: Length {}", s.capacity());
		}
		use crate::console::interface::Statistics;
		println!("Characters written to UART: \x1b[91m{}\x1b[0m", console().chars_written());
	}
	loop { }
}