-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This should result in it no longer breaking the build on non-x86_64 build host platforms. Unfortunately, it also means we need to remove the `mnemos-x86_64-core` crate from the workspace's `default-members`. See: #225 (comment) Fixes #225 --------- Co-authored-by: James Munns <[email protected]>
- Loading branch information
1 parent
8a7f4e5
commit 455050b
Showing
7 changed files
with
122 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
use anyhow::Context; | ||
use clap::Parser; | ||
use std::{fmt, path::PathBuf}; | ||
|
||
/// Boots a MnemOS x86_64 kernel using QEMU. | ||
#[derive(Parser, Debug)] | ||
pub struct Args { | ||
/// Path to the UEFI disk image. | ||
/// | ||
/// This environment variable is set by the build script and typically does | ||
/// not need to be set manually. | ||
#[clap(long, env = "UEFI_PATH")] | ||
uefi_path: PathBuf, | ||
|
||
/// Path to the BIOS disk image. | ||
/// | ||
/// This environment variable is set by the build script and typically does | ||
/// not need to be set manually. | ||
#[clap(long, env = "BIOS_PATH")] | ||
bios_path: PathBuf, | ||
|
||
/// Path to the QEMU x86_64 executable. | ||
/// | ||
/// Generally, this does not need to be overridden, unless the QEMU binary | ||
/// has a non-standard name or is not on the PATH. | ||
#[clap(long, default_value = "qemu-system-x86_64")] | ||
qemu: PathBuf, | ||
|
||
/// Whether to boot using UEFI or BIOS. | ||
#[clap(long, default_value_t = BootMode::Uefi)] | ||
boot: BootMode, | ||
|
||
/// Extra arguments passed directly to the QEMU command. | ||
#[arg(last = true)] | ||
qemu_args: Vec<String>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Eq, PartialEq, clap::ValueEnum)] | ||
enum BootMode { | ||
Uefi, | ||
Bios, | ||
} | ||
|
||
// === impl Args === | ||
|
||
impl Args { | ||
pub fn run(self) -> anyhow::Result<()> { | ||
let Args { | ||
uefi_path, | ||
bios_path, | ||
boot, | ||
qemu, | ||
qemu_args, | ||
} = self; | ||
|
||
let mut cmd = std::process::Command::new(qemu); | ||
match boot { | ||
BootMode::Uefi => { | ||
let uefi_path = uefi_path.display(); | ||
println!("booting using UEFI: {uefi_path}"); | ||
|
||
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi()); | ||
cmd.arg("-drive") | ||
.arg(format!("format=raw,file={uefi_path}")); | ||
} | ||
BootMode::Bios => { | ||
let bios_path = bios_path.display(); | ||
println!("booting using BIOS: {bios_path}"); | ||
cmd.arg("-drive") | ||
.arg(format!("format=raw,file={bios_path}")); | ||
} | ||
} | ||
|
||
if !qemu_args.is_empty() { | ||
cmd.args(&qemu_args); | ||
} | ||
|
||
let mut child = cmd.spawn().context("failed to spawn QEMU child process")?; | ||
let status = child.wait().context("QEMU child process failed")?; | ||
|
||
if !status.success() { | ||
anyhow::bail!("QEMU exited with status: {}", status); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
// === impl BootMode === | ||
|
||
impl fmt::Display for BootMode { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Uefi => f.write_str("uefi"), | ||
Self::Bios => f.write_str("bios"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,6 @@ | ||
use clap::Parser; | ||
use std::{fmt, path::PathBuf}; | ||
use mnemos_x86_64_bootloader::Args; | ||
|
||
/// Boots a MnemOS x86_64 kernel using QEMU. | ||
#[derive(Parser, Debug)] | ||
struct Args { | ||
/// Path to the UEFI disk image. | ||
/// | ||
/// This environment variable is set by the build script and typically does | ||
/// not need to be set manually. | ||
#[clap(long, env = "UEFI_PATH")] | ||
uefi_path: PathBuf, | ||
|
||
/// Path to the BIOS disk image. | ||
/// | ||
/// This environment variable is set by the build script and typically does | ||
/// not need to be set manually. | ||
#[clap(long, env = "BIOS_PATH")] | ||
bios_path: PathBuf, | ||
|
||
/// Path to the QEMU x86_64 executable. | ||
/// | ||
/// Generally, this does not need to be overridden, unless the QEMU binary | ||
/// has a non-standard name or is not on the PATH. | ||
#[clap(long, default_value = "qemu-system-x86_64")] | ||
qemu: PathBuf, | ||
|
||
/// Whether to boot using UEFI or BIOS. | ||
#[clap(long, default_value_t = BootMode::Uefi)] | ||
boot: BootMode, | ||
|
||
/// Extra arguments passed directly to the QEMU command. | ||
#[arg(last = true)] | ||
qemu_args: Vec<String>, | ||
} | ||
|
||
#[derive(Copy, Clone, Debug, Eq, PartialEq, clap::ValueEnum)] | ||
enum BootMode { | ||
Uefi, | ||
Bios, | ||
} | ||
|
||
fn main() { | ||
let Args { | ||
uefi_path, | ||
bios_path, | ||
boot, | ||
qemu, | ||
qemu_args, | ||
} = Args::parse(); | ||
|
||
let mut cmd = std::process::Command::new(qemu); | ||
match boot { | ||
BootMode::Uefi => { | ||
let uefi_path = uefi_path.display(); | ||
println!("booting using UEFI: {uefi_path}"); | ||
|
||
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi()); | ||
cmd.arg("-drive") | ||
.arg(format!("format=raw,file={uefi_path}")); | ||
} | ||
BootMode::Bios => { | ||
let bios_path = bios_path.display(); | ||
println!("booting using BIOS: {bios_path}"); | ||
cmd.arg("-drive") | ||
.arg(format!("format=raw,file={bios_path}")); | ||
} | ||
} | ||
|
||
if !qemu_args.is_empty() { | ||
cmd.args(&qemu_args); | ||
} | ||
|
||
let mut child = cmd.spawn().unwrap(); | ||
child.wait().unwrap(); | ||
} | ||
|
||
impl fmt::Display for BootMode { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::Uefi => f.write_str("uefi"), | ||
Self::Bios => f.write_str("bios"), | ||
} | ||
} | ||
fn main() -> anyhow::Result<()> { | ||
Args::parse().run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters