Initial commit

This commit is contained in:
pjht 2024-06-06 22:03:02 -05:00
commit 6e7424bbf0
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
7 changed files with 1450 additions and 0 deletions

7
.cargo/config.toml Normal file
View File

@ -0,0 +1,7 @@
[unstable]
# enable the unstable artifact-dependencies feature, see
# https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies
bindeps = true
[build]
rustflags = ["-C", "force-unwind-tables", "-C", "link-args=/home/pterpstra/projects/os-rust/kernel/eh_frame.ld"]

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
sysroot

1345
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

28
Cargo.toml Normal file
View File

@ -0,0 +1,28 @@
[package]
name = "os"
version = "0.1.0"
resolver = "2"
[build-dependencies]
bootloader = { version = "0.11.7" }
kernel = { path = "../kernel", artifact = "bin", target = "x86_64-unknown-none" }
[dependencies]
# used for UEFI booting in QEMU
ovmf-prebuilt = "0.1.0-alpha.1"
[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"
strip = false
debug = 2
# [workspace]
# members = ["kernel", "init", "test_proc", "toolchain_test"]
# exclude = ["x86_64", "rust"]
#
[patch.crates-io]
x86_64 = { git = "https://gitea.pterpstra.com/mikros/x86_64" }

46
build.rs Normal file
View File

@ -0,0 +1,46 @@
use std::{path::{Path, PathBuf}, process::Command};
extern crate bootloader;
use bootloader::{UefiBoot, BiosBoot};
fn main() {
println!("cargo:rerun-if-changed=sysroot");
println!("cargo:rerun-if-changed=build.rs");
// set by cargo, build scripts should use this directory for output files
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let mut initrd_path = out_dir.clone();
initrd_path.push("initrd.tar");
Command::new("sh")
.arg("-c")
.arg(format!("cd sysroot; tar cvf {:?} *", initrd_path))
.spawn()
.unwrap()
.wait()
.unwrap();
// set by cargo's artifact dependency feature, see
// https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#artifact-dependencies
let kernel = PathBuf::from(std::env::var_os("CARGO_BIN_FILE_KERNEL_kernel").unwrap());
// create an UEFI disk image (optional)
let mut uefi_path = out_dir.clone();
uefi_path.push("uefi.img");
UefiBoot::new(&kernel)
.set_ramdisk(Path::new(&initrd_path))
.create_disk_image(Path::new(&uefi_path))
.unwrap();
// create a BIOS disk image (optional)
let mut bios_path = out_dir.clone();
bios_path.push("bios.img");
BiosBoot::new(&kernel)
.set_ramdisk(Path::new(&initrd_path))
.create_disk_image(Path::new(&bios_path))
.unwrap();
println!("cargo:rustc-env=UEFI_PATH={}", uefi_path.to_string_lossy());
println!("cargo:rustc-env=BIOS_PATH={}", bios_path.to_string_lossy());
}

BIN
ext2.img Normal file

Binary file not shown.

22
src/main.rs Normal file
View File

@ -0,0 +1,22 @@
fn main() {
// read env variables that were set in build script
let uefi_path = env!("UEFI_PATH");
// let bios_path = env!("BIOS_PATH");
let mut cmd = std::process::Command::new("qemu-system-x86_64");
cmd.arg("-nographic");
cmd.arg("-m").arg("4G");
cmd.arg("-device")
.arg("isa-debug-exit,iobase=0xf4,iosize=0x04");
cmd.arg("--no-reboot");
cmd.arg("--machine").arg("type=q35,accel=kvm");
cmd.arg("-bios").arg(ovmf_prebuilt::ovmf_pure_efi());
cmd.arg("-drive")
.arg(format!("format=raw,file={uefi_path},if=ide,index=0"));
// .arg(format!("format=raw,file={bios_path}"));
cmd.arg("-drive").arg("format=raw,file=ext2.img,if=ide,index=1");
// cmd.arg("-s");
// cmd.arg("-S");
let mut child = cmd.spawn().unwrap();
child.wait().unwrap();
}