rustubs/
lib.rs

1#![allow(dead_code)]
2// #![allow(unused_imports)]
3#![allow(non_snake_case)]
4#![no_std]
5#![no_main]
6#![feature(sync_unsafe_cell)]
7#![allow(clippy::fn_to_numeric_cast)]
8#![allow(clippy::missing_safety_doc)]
9#![allow(clippy::upper_case_acronyms)]
10// Some lints are created by the utterly deranged narcissistic soy devs who have
11// a bad take on "clean code". They have no idea what "clean" or "ergonomic" is.
12// These are the people who tell you to create a factory that creates a factory
13// which could produce more factories of factory because so that you can have a
14// nice abstraction of abstraction of abstractions.
15#![allow(clippy::new_without_default)]
16#![allow(clippy::needless_return)]
17#![allow(clippy::needless_range_loop)]
18// note: how can I get interior mutability (with mut ref) without
19// triggering clippy?
20#![allow(clippy::mut_from_ref)]
21pub mod arch;
22pub mod defs;
23#[macro_use]
24pub mod io;
25pub mod black_magic;
26pub mod fs;
27pub mod kthread;
28pub mod machine;
29pub mod mm;
30pub mod proc;
31extern crate alloc;
32use crate::proc::sched::*;
33use arch::x86_64::interrupt;
34use arch::x86_64::interrupt::pic_8259;
35use arch::x86_64::interrupt::pic_8259::PicDeviceInt;
36use defs::*;
37use kthread::KThread;
38use machine::multiboot;
39use proc::task::Task;
40
41#[no_mangle]
42pub unsafe extern "C" fn _entry() -> ! {
43	// initialize cga display
44	io::set_attr(0x1f);
45	io::reset_screen();
46	// check mbi now. This will be later used to initilize the allocator
47	assert!(multiboot::check(), "bad multiboot info from grub!");
48	// promote gdt to high memory mapping
49	arch::x86_64::gdt::init();
50	// initialize the idt and re-program the pic. Must do this before enabling
51	// irq also must initialize the idt before mm, because the later may trigger
52	// page faults, which is fatal and we want to catch them during system
53	// initilization. (disabling interrupts have no effect on exceptions)
54	interrupt::init();
55	// initialize memory manager
56	mm::init();
57	// point of no return: low memory can no longer be accessed after this point
58	mm::drop_init_mapping();
59	// initialize proc and sync primitives
60	proc::init();
61	// initialize interrupt timer to roughly ... 50 hz
62	let _interval = interrupt::pit::PIT::set_interval(20000);
63	pic_8259::allow(PicDeviceInt::KEYBOARD);
64	pic_8259::allow(PicDeviceInt::TIMER);
65	// interrupt should be enabled at the end
66	// run kernel threads
67	create_tasks();
68	interrupt::interrupt_enable();
69	Scheduler::kickoff();
70	panic!("should not reach");
71}
72
73fn create_tasks() {
74	let mut sched = GLOBAL_SCHEDULER.lock();
75	sched.insert_task(Task::create_task(1, kthread::Idle::get_entry()));
76	sched.insert_task(Task::create_task(2, kthread::Meeseeks::get_entry()));
77	sched.insert_task(Task::create_task(3, kthread::Kshell::get_entry()));
78	sched.insert_task(Task::create_task(4, kthread::Lazy::get_entry()));
79}