summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/main.rs b/src/main.rs
index 03072f6..274ef02 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,33 +4,38 @@
// This file is part of TRVE (https://gitea.taitep.se/taitep/trve)
// See LICENSE file in the project root for full license text.
-use std::{env, sync::Arc, time::Duration};
+use std::{env, path::PathBuf, sync::Arc, time::Duration};
+
+use clap::Parser;
use trve::{
consts::{Addr, Byte, DWord, HWord, Word},
core::Core,
exceptions::MemoryExceptionType,
+ gdb,
mem::{MemConfig, MemDeviceInterface, MmioRoot, Ram},
};
-use anyhow::{Result, bail};
+use anyhow::Result;
use crate::basic_uart::BasicUart;
mod execload;
+#[derive(Parser)]
+struct Args {
+ executable: PathBuf,
+ #[arg(long)]
+ wait: bool,
+}
+
fn main() -> Result<()> {
+ let args = Args::parse();
+
let mut ram = Ram::try_new(16 * 1024 * 1024)?;
let buf = ram.buf_mut();
- let args: Vec<String> = env::args().collect();
-
- if args.len() != 2 {
- eprintln!("USAGE: trve <ram_image>");
- bail!("Wrong number of arguments");
- }
-
- let entry_point = execload::load(&args[1], buf)?;
+ let entry_point = execload::load(args.executable, buf)?;
let mut mmio_root = MmioRoot::default();
mmio_root.insert(0, Arc::new(DbgOut));
@@ -44,9 +49,18 @@ fn main() -> Result<()> {
mmio_root,
};
- let mut core = Core::new(mem_cfg);
+ let (cmd_sender, cmd_reciever) = std::sync::mpsc::channel();
+
+ gdb::run_stub(cmd_sender.clone());
+
+ let mut core = Core::new(mem_cfg, cmd_reciever);
core.reset(entry_point);
- core.run();
+
+ if args.wait {
+ core.run_waiting_for_cmd();
+ } else {
+ core.run();
+ }
Ok(())
}