Skip to main content

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;
31pub mod syscalls;
32extern crate alloc;
33use crate::proc::sched::*;
34use arch::x86_64::interrupt;
35use arch::x86_64::interrupt::pic_8259;
36use arch::x86_64::interrupt::pic_8259::PicDeviceInt;
37use defs::*;
38use kthread::KThread;
39use machine::multiboot;
40use proc::task::Task;
41
42#[no_mangle]
43pub unsafe extern "C" fn _entry() -> ! {
44	// initialize cga display
45	io::set_attr(0x1f);
46	io::reset_screen();
47	// check mbi now. This will be later used to initilize the allocator
48	assert!(multiboot::check(), "bad multiboot info from grub!");
49	// promote gdt to high memory mapping
50	arch::x86_64::gdt::init();
51	// initialize the idt and re-program the pic. Must do this before enabling
52	// irq also must initialize the idt before mm, because the later may trigger
53	// page faults, which is fatal and we want to catch them during system
54	// initilization. (disabling interrupts have no effect on exceptions)
55	interrupt::init();
56	// initialize memory manager
57	mm::init();
58	// point of no return: low memory can no longer be accessed after this point
59	mm::drop_init_mapping();
60	// initialize proc and sync primitives
61	proc::init();
62	// initialize interrupt timer to roughly ... 50 hz
63	let _interval = interrupt::pit::PIT::set_interval(20000);
64	pic_8259::allow(PicDeviceInt::KEYBOARD);
65	pic_8259::allow(PicDeviceInt::TIMER);
66	// interrupt should be enabled at the end
67	// run kernel threads
68	create_tasks();
69	interrupt::interrupt_enable();
70	Scheduler::kickoff();
71	panic!("should not reach");
72}
73
74fn create_tasks() {
75	let mut sched = GLOBAL_SCHEDULER.lock();
76	sched.insert_task(Task::create_task(1, kthread::Idle::get_entry()));
77	// sched.insert_task(Task::create_task(2, kthread::Meeseeks::get_entry()));
78	sched.insert_task(Task::create_task(3, kthread::Kshell::get_entry()));
79	// sched.insert_task(Task::create_task(4, kthread::Lazy::get_entry()));
80}