mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Compare commits
5 Commits
51e0dc1b63
...
cf28a5fdf9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf28a5fdf9 | ||
|
|
2a49491fc7 | ||
|
|
ba8b0392b8 | ||
|
|
98da4b2f9a | ||
|
|
34b1eb4741 |
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -132,6 +132,7 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"bootloader",
|
"bootloader",
|
||||||
"kernel",
|
"kernel",
|
||||||
|
"ovmf-prebuilt",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -495,6 +496,12 @@ version = "2.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ovmf-prebuilt"
|
||||||
|
version = "0.1.0-alpha.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "fa50141d081512ab30fd9e7e7692476866df5098b028536ad6680212e717fa8d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking"
|
name = "parking"
|
||||||
version = "2.1.0"
|
version = "2.1.0"
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
name = "blog_os"
|
name = "blog_os"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
default-run = "blog_os"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["kernel"]
|
members = ["kernel"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
ovmf-prebuilt = "0.1.0-alpha"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" }
|
kernel = { path = "kernel", artifact = "bin", target = "x86_64-unknown-none" }
|
||||||
bootloader = "0.11.3"
|
bootloader = "0.11.3"
|
||||||
|
|||||||
21
build.rs
Normal file
21
build.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
use bootloader::DiskImageBuilder;
|
||||||
|
use std::{env, path::PathBuf};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// set by cargo for the kernel artifact dependency
|
||||||
|
let kernel_path = env::var("CARGO_BIN_FILE_KERNEL").unwrap();
|
||||||
|
let disk_builder = DiskImageBuilder::new(PathBuf::from(kernel_path));
|
||||||
|
|
||||||
|
// specify output paths
|
||||||
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
||||||
|
let uefi_path = out_dir.join("blog_os-uefi.img");
|
||||||
|
let bios_path = out_dir.join("blog_os-bios.img");
|
||||||
|
|
||||||
|
// create the disk images
|
||||||
|
disk_builder.create_uefi_image(&uefi_path).unwrap();
|
||||||
|
disk_builder.create_bios_image(&bios_path).unwrap();
|
||||||
|
|
||||||
|
// pass the disk image paths via environment variables
|
||||||
|
println!("cargo:rustc-env=UEFI_IMAGE={}", uefi_path.display());
|
||||||
|
println!("cargo:rustc-env=BIOS_IMAGE={}", bios_path.display());
|
||||||
|
}
|
||||||
@@ -3,7 +3,10 @@ name = "kernel"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
[[bin]]
|
||||||
|
name = "kernel"
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bootloader_api = "0.11.0"
|
bootloader_api = "0.11.0"
|
||||||
|
|||||||
@@ -3,9 +3,18 @@
|
|||||||
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
|
use bootloader_api::BootInfo;
|
||||||
|
|
||||||
bootloader_api::entry_point!(kernel_main);
|
bootloader_api::entry_point!(kernel_main);
|
||||||
|
|
||||||
fn kernel_main(_bootinfo: &'static mut bootloader_api::BootInfo) -> ! {
|
fn kernel_main(boot_info: &'static mut BootInfo) -> ! {
|
||||||
|
if let Some(framebuffer) = boot_info.framebuffer.as_mut() {
|
||||||
|
let mut value = 0x90;
|
||||||
|
for byte in framebuffer.buffer_mut() {
|
||||||
|
*byte = value;
|
||||||
|
value = value.wrapping_add(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
12
src/bin/qemu-bios.rs
Normal file
12
src/bin/qemu-bios.rs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
use std::{
|
||||||
|
env,
|
||||||
|
process::{self, Command},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut qemu = Command::new("qemu-system-x86_64");
|
||||||
|
qemu.arg("-drive");
|
||||||
|
qemu.arg(format!("format=raw,file={}", env!("BIOS_IMAGE")));
|
||||||
|
let exit_status = qemu.status().unwrap();
|
||||||
|
process::exit(exit_status.code().unwrap_or(-1));
|
||||||
|
}
|
||||||
13
src/bin/qemu-uefi.rs
Normal file
13
src/bin/qemu-uefi.rs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
use std::{
|
||||||
|
env,
|
||||||
|
process::{self, Command},
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut qemu = Command::new("qemu-system-x86_64");
|
||||||
|
qemu.arg("-drive");
|
||||||
|
qemu.arg(format!("format=raw,file={}", env!("UEFI_IMAGE")));
|
||||||
|
qemu.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi());
|
||||||
|
let exit_status = qemu.status().unwrap();
|
||||||
|
process::exit(exit_status.code().unwrap_or(-1));
|
||||||
|
}
|
||||||
26
src/main.rs
26
src/main.rs
@@ -1,21 +1,13 @@
|
|||||||
use bootloader::DiskImageBuilder;
|
use std::{env, fs};
|
||||||
use std::{env, error::Error, path::PathBuf};
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() {
|
||||||
// set by cargo for the kernel artifact dependency
|
let current_exe = env::current_exe().unwrap();
|
||||||
let kernel_path = PathBuf::from(env!("CARGO_BIN_FILE_KERNEL"));
|
let uefi_target = current_exe.with_file_name("uefi.img");
|
||||||
let disk_builder = DiskImageBuilder::new(kernel_path);
|
let bios_target = current_exe.with_file_name("bios.img");
|
||||||
|
|
||||||
// place the disk image files under target/debug or target/release
|
fs::copy(env!("UEFI_IMAGE"), &uefi_target).unwrap();
|
||||||
let target_dir = env::current_exe()?;
|
fs::copy(env!("BIOS_IMAGE"), &bios_target).unwrap();
|
||||||
|
|
||||||
let uefi_path = target_dir.with_file_name("blog_os-uefi.img");
|
println!("UEFI disk image at {}", uefi_target.display());
|
||||||
disk_builder.create_uefi_image(&uefi_path)?;
|
println!("BIOS disk image at {}", bios_target.display());
|
||||||
println!("Created UEFI disk image at {}", uefi_path.display());
|
|
||||||
|
|
||||||
let bios_path = target_dir.with_file_name("blog_os-bios.img");
|
|
||||||
disk_builder.create_bios_image(&bios_path)?;
|
|
||||||
println!("Created BIOS disk image at {}", bios_path.display());
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user