mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Update to bootloader-locator 0.0.3; cargo fmt; add QEMU run args
This commit is contained in:
16
Cargo.lock
generated
16
Cargo.lock
generated
@@ -37,14 +37,11 @@ version = "0.9.8"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bootloader-locator"
|
name = "bootloader-locator"
|
||||||
version = "0.0.2"
|
version = "0.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "28ad4c6eeee6c832cb7b2d11fab963674418878c8edaedbef67fcae403dae645"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
"locate-cargo-manifest",
|
"locate-cargo-manifest",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"toml",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -132,8 +129,6 @@ checksum = "fc874b127765f014d792f16763a81245ab80500e2ad921ed4ee9e82481ee08fe"
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "runner-utils"
|
name = "runner-utils"
|
||||||
version = "0.0.2"
|
version = "0.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c9dc6848b056990cd51e72aa5556bdbea4a96013e8b18635d183c84159c2988f"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror",
|
"thiserror",
|
||||||
"wait-timeout",
|
"wait-timeout",
|
||||||
@@ -229,15 +224,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "toml"
|
|
||||||
version = "0.5.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a"
|
|
||||||
dependencies = [
|
|
||||||
"serde",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "uart_16550"
|
name = "uart_16550"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
use std::{process::{ExitStatus, Command}, path::PathBuf, time::Duration};
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use std::{
|
||||||
|
path::PathBuf,
|
||||||
|
process::{Command, ExitStatus},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
const TEST_ARGS: &[&str] = &["-device", "isa-debug-exit,iobase=0xf4,iosize=0x04", "-serial", "stdio",
|
const RUN_ARGS: &[&str] = &["-d", "int", "--no-reboot", "-s"];
|
||||||
"-display", "none"
|
const TEST_ARGS: &[&str] = &[
|
||||||
|
"-device",
|
||||||
|
"isa-debug-exit,iobase=0xf4,iosize=0x04",
|
||||||
|
"-serial",
|
||||||
|
"stdio",
|
||||||
|
"-display",
|
||||||
|
"none",
|
||||||
|
"--no-reboot",
|
||||||
];
|
];
|
||||||
const TEST_TIMEOUT_SECS: u64 = 10;
|
const TEST_TIMEOUT_SECS: u64 = 10;
|
||||||
|
|
||||||
@@ -15,7 +26,9 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let disk_image = disk_image::create_disk_image(&kernel_binary_path, true)?;
|
let disk_image = disk_image::create_disk_image(&kernel_binary_path, true)?;
|
||||||
|
|
||||||
let mut run_cmd = Command::new("qemu-system-x86_64");
|
let mut run_cmd = Command::new("qemu-system-x86_64");
|
||||||
run_cmd.arg("-drive").arg(format!("format=raw,file={}", disk_image.display()));
|
run_cmd
|
||||||
|
.arg("-drive")
|
||||||
|
.arg(format!("format=raw,file={}", disk_image.display()));
|
||||||
|
|
||||||
let binary_kind = runner_utils::binary_kind(&kernel_binary_path);
|
let binary_kind = runner_utils::binary_kind(&kernel_binary_path);
|
||||||
if binary_kind.is_test() {
|
if binary_kind.is_test() {
|
||||||
@@ -23,10 +36,12 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let exit_status = run_test_command(run_cmd)?;
|
let exit_status = run_test_command(run_cmd)?;
|
||||||
match exit_status.code() {
|
match exit_status.code() {
|
||||||
Some(33) => {}, // success
|
Some(33) => {} // success
|
||||||
other => return Err(anyhow!("Test failed (exit code: {:?})", other)),
|
other => return Err(anyhow!("Test failed (exit code: {:?})", other)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
run_cmd.args(RUN_ARGS);
|
||||||
|
|
||||||
let exit_status = run_cmd.status()?;
|
let exit_status = run_cmd.status()?;
|
||||||
if !exit_status.success() {
|
if !exit_status.success() {
|
||||||
std::process::exit(exit_status.code().unwrap_or(1));
|
std::process::exit(exit_status.code().unwrap_or(1));
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
use std::{process::Command, path::{Path, PathBuf}};
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use std::{
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
process::Command,
|
||||||
|
};
|
||||||
|
|
||||||
pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::Result<PathBuf> {
|
pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::Result<PathBuf> {
|
||||||
let bootloader_info= bootloader_locator::locate_bootloader()?;
|
let bootloader_info = bootloader_locator::locate_bootloader()?;
|
||||||
let kernel_manifest_path = &bootloader_info.kernel_manifest_path;
|
let kernel_manifest_path = &bootloader_info.kernel_manifest_path;
|
||||||
|
|
||||||
let mut build_cmd = Command::new(env!("CARGO"));
|
let mut build_cmd = Command::new(env!("CARGO"));
|
||||||
build_cmd.current_dir(bootloader_info.package.manifest_path.parent().unwrap());
|
build_cmd.current_dir(bootloader_info.package.manifest_path.parent().unwrap());
|
||||||
build_cmd.arg("builder");
|
build_cmd.arg("builder");
|
||||||
build_cmd.arg("--kernel-manifest").arg(&kernel_manifest_path);
|
build_cmd
|
||||||
|
.arg("--kernel-manifest")
|
||||||
|
.arg(&kernel_manifest_path);
|
||||||
build_cmd.arg("--kernel-binary").arg(&kernel_binary_path);
|
build_cmd.arg("--kernel-binary").arg(&kernel_binary_path);
|
||||||
build_cmd.arg("--features").args(bootloader_info.features);
|
build_cmd
|
||||||
build_cmd.arg("--target-dir").arg(kernel_manifest_path.parent().unwrap().join("target"));
|
.arg("--target-dir")
|
||||||
build_cmd.arg("--out-dir").arg(kernel_binary_path.parent().unwrap());
|
.arg(kernel_manifest_path.parent().unwrap().join("target"));
|
||||||
|
build_cmd
|
||||||
|
.arg("--out-dir")
|
||||||
|
.arg(kernel_binary_path.parent().unwrap());
|
||||||
build_cmd.arg("--quiet");
|
build_cmd.arg("--quiet");
|
||||||
if bios_only {
|
if bios_only {
|
||||||
build_cmd.arg("--firmware").arg("bios");
|
build_cmd.arg("--firmware").arg("bios");
|
||||||
@@ -23,9 +31,15 @@ pub fn create_disk_image(kernel_binary_path: &Path, bios_only: bool) -> anyhow::
|
|||||||
}
|
}
|
||||||
|
|
||||||
let kernel_binary_name = kernel_binary_path.file_name().unwrap().to_str().unwrap();
|
let kernel_binary_name = kernel_binary_path.file_name().unwrap().to_str().unwrap();
|
||||||
let disk_image = kernel_binary_path.parent().unwrap().join(format!("bootimage-bios-{}.bin", kernel_binary_name));
|
let disk_image = kernel_binary_path
|
||||||
|
.parent()
|
||||||
|
.unwrap()
|
||||||
|
.join(format!("bootimage-bios-{}.bin", kernel_binary_name));
|
||||||
if !disk_image.exists() {
|
if !disk_image.exists() {
|
||||||
return Err(anyhow!("Disk image does not exist at {} after bootloader build", disk_image.display()));
|
return Err(anyhow!(
|
||||||
|
"Disk image does not exist at {} after bootloader build",
|
||||||
|
disk_image.display()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Ok(disk_image)
|
Ok(disk_image)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use std::process::Command;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
const TARGET_NAME: &str = "x86_64-blog_os";
|
const TARGET_NAME: &str = "x86_64-blog_os";
|
||||||
const KERNEL_BINARIES: &[&str] = &["blog_os"];
|
const KERNEL_BINARIES: &[&str] = &["blog_os"];
|
||||||
@@ -10,7 +10,9 @@ fn main() -> anyhow::Result<()> {
|
|||||||
build_cmd.arg("build");
|
build_cmd.arg("build");
|
||||||
build_cmd.arg("--release");
|
build_cmd.arg("--release");
|
||||||
build_cmd.arg("-Zbuild-std=core");
|
build_cmd.arg("-Zbuild-std=core");
|
||||||
build_cmd.arg("--target").arg(format!("{}.json", TARGET_NAME));
|
build_cmd
|
||||||
|
.arg("--target")
|
||||||
|
.arg(format!("{}.json", TARGET_NAME));
|
||||||
if !build_cmd.status()?.success() {
|
if !build_cmd.status()?.success() {
|
||||||
return Err(anyhow!("build failed"));
|
return Err(anyhow!("build failed"));
|
||||||
};
|
};
|
||||||
@@ -27,7 +29,11 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let disk_image = disk_image::create_disk_image(&binary_path, false)?;
|
let disk_image = disk_image::create_disk_image(&binary_path, false)?;
|
||||||
|
|
||||||
println!("Created disk image for binary {} at {}", binary_name, disk_image.display());
|
println!(
|
||||||
|
"Created disk image for binary {} at {}",
|
||||||
|
binary_name,
|
||||||
|
disk_image.display()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -5,16 +5,13 @@
|
|||||||
#![reexport_test_harness_main = "test_main"]
|
#![reexport_test_harness_main = "test_main"]
|
||||||
|
|
||||||
use blog_os::serial_println;
|
use blog_os::serial_println;
|
||||||
use core::{ptr, panic::PanicInfo, slice};
|
use core::{panic::PanicInfo, ptr, slice};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info_uefi::BootInfo) -> ! {
|
pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info::BootInfo) -> ! {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
test_main();
|
test_main();
|
||||||
|
|
||||||
loop {
|
|
||||||
x86_64::instructions::hlt();
|
|
||||||
}
|
|
||||||
let mut framebuffer = {
|
let mut framebuffer = {
|
||||||
let ptr = boot_info.framebuffer.start_addr as *mut u8;
|
let ptr = boot_info.framebuffer.start_addr as *mut u8;
|
||||||
let slice = unsafe { slice::from_raw_parts_mut(ptr, boot_info.framebuffer.len) };
|
let slice = unsafe { slice::from_raw_parts_mut(ptr, boot_info.framebuffer.len) };
|
||||||
@@ -23,7 +20,6 @@ pub extern "C" fn _start(boot_info: &'static mut bootloader::boot_info_uefi::Boo
|
|||||||
|
|
||||||
//serial_println!("Hello World{}", "!");
|
//serial_println!("Hello World{}", "!");
|
||||||
|
|
||||||
|
|
||||||
for i in 0..boot_info.framebuffer.len {
|
for i in 0..boot_info.framebuffer.len {
|
||||||
framebuffer.index_mut(i).write(0x99);
|
framebuffer.index_mut(i).write(0x99);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user