2021-11-16 22:52:17 -06:00
|
|
|
use clap::Parser;
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2021-11-16 22:52:17 -06:00
|
|
|
#[derive(clap::Parser, Debug)]
|
2022-04-11 15:34:40 -05:00
|
|
|
// #[clap(version = clap::crate_version!(), author = clap::crate_authors!("\n"))]
|
|
|
|
|
2021-11-16 22:52:17 -06:00
|
|
|
/// Hello Remember this is a feature
|
2021-11-16 00:09:27 -06:00
|
|
|
enum Command {
|
2022-02-18 10:04:10 -06:00
|
|
|
Run {
|
|
|
|
#[clap(long, short)]
|
|
|
|
debug: bool,
|
2021-11-16 22:52:17 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
#[clap(long, short, arg_enum)]
|
|
|
|
machine: Option<MachineType>,
|
|
|
|
},
|
2021-11-21 02:13:50 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
Doc {
|
|
|
|
#[clap(long, short, arg_enum)]
|
|
|
|
machine: Option<MachineType>,
|
|
|
|
},
|
2022-03-26 06:26:17 -05:00
|
|
|
|
|
|
|
Mount {
|
|
|
|
#[clap(long, short)]
|
|
|
|
path: Option<String>,
|
|
|
|
},
|
|
|
|
|
|
|
|
Unmount {
|
|
|
|
#[clap(long, short)]
|
|
|
|
path: Option<String>,
|
|
|
|
},
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
2021-11-17 08:42:54 -06:00
|
|
|
|
2021-11-16 22:52:17 -06:00
|
|
|
#[derive(clap::ArgEnum, Debug, Clone)]
|
|
|
|
enum MachineType {
|
2022-02-18 10:04:10 -06:00
|
|
|
X86,
|
2022-04-11 15:51:54 -05:00
|
|
|
Riscv,
|
|
|
|
Arm,
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() -> anyhow::Result<()> {
|
2022-02-18 10:04:10 -06:00
|
|
|
let args = Command::parse();
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
match args {
|
|
|
|
Command::Run { debug, machine } => {
|
|
|
|
let _dir = xshell::pushd("./ableos");
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
let _debug_log: &[&str] = match debug {
|
|
|
|
true => &["-D", "debug.log"],
|
|
|
|
false => &[],
|
|
|
|
};
|
|
|
|
match machine.unwrap_or(MachineType::X86) {
|
|
|
|
MachineType::X86 => {
|
|
|
|
xshell::cmd!("cargo run --release").run()?;
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
MachineType::Arm => {
|
2022-02-18 10:04:10 -06:00
|
|
|
xshell::cmd!("cargo build --release --target=json_targets/aarch64-ableos.json")
|
|
|
|
.run()?;
|
|
|
|
#[rustfmt::skip]
|
2021-11-16 22:52:17 -06:00
|
|
|
xshell::cmd!(
|
|
|
|
"qemu-system-aarch64
|
|
|
|
-machine virt
|
|
|
|
-m 1024M
|
|
|
|
-cpu cortex-a53
|
|
|
|
-kernel target/aarch64-ableos/release/ableos
|
|
|
|
-device virtio-keyboard
|
|
|
|
"
|
2021-11-18 00:35:50 -06:00
|
|
|
).run()?;
|
2022-02-18 10:04:10 -06:00
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
MachineType::Riscv => {
|
2022-02-18 10:04:10 -06:00
|
|
|
xshell::cmd!("cargo build --release --target=riscv64gc-unknown-none-elf")
|
|
|
|
.run()?;
|
|
|
|
#[rustfmt::skip]
|
2021-11-16 22:52:17 -06:00
|
|
|
xshell::cmd!(
|
2021-11-17 08:42:54 -06:00
|
|
|
"qemu-system-riscv64
|
|
|
|
-machine virt
|
|
|
|
-cpu rv64
|
|
|
|
-smp 8
|
|
|
|
-m 128M
|
|
|
|
-bios src/arch/riscv/firmwear/opensbi-riscv64-generic-fw_jump.bin
|
2022-02-18 10:04:10 -06:00
|
|
|
-kernel target/riscv64gc-unknown-none-elf/release/ableos
|
|
|
|
"
|
|
|
|
// -serial stdio
|
2021-11-17 08:42:54 -06:00
|
|
|
).run()?;
|
2022-02-18 10:04:10 -06:00
|
|
|
}
|
2021-11-16 22:52:17 -06:00
|
|
|
}
|
2022-02-18 10:04:10 -06:00
|
|
|
}
|
2021-11-21 02:13:50 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
Command::Doc { machine } => {
|
|
|
|
let _dir = xshell::pushd("./ableos");
|
2021-11-21 02:13:50 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
match machine.unwrap_or(MachineType::X86) {
|
|
|
|
MachineType::X86 => {
|
|
|
|
xshell::cmd!("cargo doc --open").run()?;
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
MachineType::Arm => {
|
2022-02-18 10:04:10 -06:00
|
|
|
xshell::cmd!("cargo doc --open --target=json_targets/aarch64-ableos.json")
|
|
|
|
.run()?;
|
|
|
|
}
|
2022-04-11 15:51:54 -05:00
|
|
|
MachineType::Riscv => {
|
2022-02-18 10:04:10 -06:00
|
|
|
xshell::cmd!("cargo doc --open --target=riscv64gc-unknown-none-elf").run()?;
|
|
|
|
}
|
2021-11-21 02:13:50 -06:00
|
|
|
}
|
2022-02-18 10:04:10 -06:00
|
|
|
}
|
2022-03-26 06:26:17 -05:00
|
|
|
|
|
|
|
Command::Mount { path } => {
|
2022-04-11 15:51:54 -05:00
|
|
|
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
|
2022-03-26 06:26:17 -05:00
|
|
|
xshell::cmd!("sudo mount userland/root_fs/ext2.img {path}").run()?;
|
2022-04-11 15:34:40 -05:00
|
|
|
}
|
2022-03-26 06:26:17 -05:00
|
|
|
|
|
|
|
Command::Unmount { path } => {
|
2022-04-11 15:51:54 -05:00
|
|
|
let path = path.unwrap_or_else(|| "./userland/root_fs/mnt".to_string());
|
2022-03-26 06:26:17 -05:00
|
|
|
xshell::cmd!("sudo umount {path}").run()?;
|
2022-04-11 15:34:40 -05:00
|
|
|
}
|
2022-02-18 10:04:10 -06:00
|
|
|
}
|
2021-11-16 00:09:27 -06:00
|
|
|
|
2022-02-18 10:04:10 -06:00
|
|
|
Ok(())
|
2021-11-16 00:09:27 -06:00
|
|
|
}
|