2023-03-13 14:51:32 +01:00
|
|
|
|
|
|
|
#![warn(missing_docs)]
|
|
|
|
#![warn(clippy::missing_docs_in_private_items)]
|
|
|
|
|
|
|
|
//! Crate burritos ((BurritOS Using Rust Really Improves The Operating System)
|
|
|
|
//!
|
|
|
|
//! Burritos is an educational operating system written in Rust
|
|
|
|
//! running on RISC-V emulator.
|
|
|
|
|
|
|
|
/// Contain hardware simulated part of the machine
|
2023-01-11 14:58:12 +01:00
|
|
|
mod simulator;
|
2023-02-15 14:56:11 +01:00
|
|
|
mod kernel;
|
2023-03-13 14:51:32 +01:00
|
|
|
/// module containing useful tools which can be use in most part of the OS to ease the development of the OS
|
2023-02-15 18:10:08 +01:00
|
|
|
pub mod utility;
|
2023-01-11 14:58:12 +01:00
|
|
|
|
2023-04-06 13:27:03 +02:00
|
|
|
use std::{rc::Rc, cell::RefCell};
|
|
|
|
|
|
|
|
use kernel::{system::System, thread::Thread, process::Process};
|
|
|
|
use simulator::{machine::Machine, loader};
|
|
|
|
|
|
|
|
|
|
|
|
use clap::Parser;
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
#[command(name = "BurritOS", author, version, about = "Burritos (BurritOS Using Rust Really Improves The Operating System)
|
|
|
|
|
|
|
|
Burritos is an educational operating system written in Rust
|
|
|
|
running on RISC-V emulator.", long_about = None)]
|
|
|
|
struct Args {
|
|
|
|
/// Enable debug mode
|
|
|
|
#[arg(short, long)]
|
|
|
|
debug: bool,
|
|
|
|
/// Path to the executable binary file to execute
|
|
|
|
#[arg(short = 'x', long, value_name = "PATH")]
|
|
|
|
executable: String
|
|
|
|
}
|
2022-10-19 16:39:38 +02:00
|
|
|
|
2022-10-05 16:30:21 +02:00
|
|
|
fn main() {
|
2023-04-06 13:27:03 +02:00
|
|
|
let args = Args::parse();
|
|
|
|
|
|
|
|
let mut machine = Machine::new(args.debug);
|
|
|
|
let (loader, ptr) = loader::Loader::new(args.executable.as_str(), &mut machine, 0).expect("IO Error");
|
|
|
|
|
2023-04-05 12:01:31 +02:00
|
|
|
let mut system = System::default();
|
2023-04-06 13:27:03 +02:00
|
|
|
|
|
|
|
let thread_exec = Thread::new(args.executable.as_str());
|
|
|
|
let thread_exec = Rc::new(RefCell::new(thread_exec));
|
|
|
|
system.get_thread_manager().get_g_alive().push(Rc::clone(&thread_exec));
|
|
|
|
|
|
|
|
let owner1 = Process { num_thread: 0 };
|
|
|
|
system.get_thread_manager().start_thread(Rc::clone(&thread_exec), owner1, loader.elf_header.entrypoint, ptr, -1);
|
|
|
|
|
|
|
|
let to_run = system.get_thread_manager().find_next_to_run().unwrap();
|
|
|
|
system.get_thread_manager().switch_to(&mut machine, Rc::clone(&to_run));
|
|
|
|
|
2023-04-05 12:01:31 +02:00
|
|
|
machine.run(&mut system);
|
2022-10-05 16:30:21 +02:00
|
|
|
}
|