Add launch argument parser, add debug parameter to machine
burritos now launch binary
This commit is contained in:
40
src/main.rs
40
src/main.rs
@ -13,11 +13,45 @@ mod kernel;
|
||||
/// module containing useful tools which can be use in most part of the OS to ease the development of the OS
|
||||
pub mod utility;
|
||||
|
||||
use kernel::system::System;
|
||||
use simulator::machine::Machine;
|
||||
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
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut machine = Machine::init_machine();
|
||||
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");
|
||||
|
||||
let mut system = System::default();
|
||||
|
||||
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));
|
||||
|
||||
machine.run(&mut system);
|
||||
}
|
||||
|
Reference in New Issue
Block a user