Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
memN0ps committed Dec 13, 2023
1 parent 4db3373 commit 5f20480
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
resolver = "2"

members = [
"driver",
"boot",
"hypervisor",
]

Expand All @@ -20,4 +20,4 @@ lto = true # Enable Link Time Optimization
#codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = "abort" # Abort on panic
#strip = true # Automatically strip symbols from the binary.
debug-assertions = false
debug-assertions = false
7 changes: 7 additions & 0 deletions boot/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
target = "x86_64-unknown-uefi"
rustflags = ["-Z", "pre-link-args=/subsystem:efi_runtime_driver"]

#[unstable]
#build-std = ["core", "compiler_builtins", "alloc"]
#build-std-features = ["compiler-builtins-mem"]
11 changes: 11 additions & 0 deletions boot/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "boot"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
log = { version = "0.4", default-features = false }
uefi = {version = "0.22.0", features = ["global_allocator", "alloc"] }
com_logger = "0.1.1" # https://crates.io/crates/com_logger
76 changes: 76 additions & 0 deletions boot/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#![no_main]
#![no_std]
#![feature(lang_items)]
#![feature(panic_info_message)]
#![feature(offset_of)]

use {
crate::{
boot::globals::{DRIVER_IMAGE_SIZE, DRIVER_PHYSICAL_MEMORY},
mapper::get_nt_headers,
},
uefi::{
prelude::*,
table::boot::{AllocateType, MemoryType},
},
core::ptr::copy_nonoverlapping,
log::LevelFilter,
};


#[cfg(not(test))]
#[panic_handler]
fn panic_handler(info: &core::panic::PanicInfo) -> ! {
if let Some(location) = info.location() {
log::error!(
"[-] Panic in {} at ({}, {}):",
location.file(),
location.line(),
location.column()
);
if let Some(message) = info.message() {
log::error!("[-] {}", message);
}
}

loop {}
}

/* The image handle represents the currently-running executable, and the system table provides access to many different UEFI services.
(Removed as it requires uefi_services::init)
//#[entry]
//fn main(image_handle: handle, image_handle: Handle, mut system_table: SystemTable<Boot>) { }
*/

#[no_mangle]
fn efi_main(image_handle: Handle, system_table: SystemTable<Boot>) -> Status {
/* Setup a simple memory allocator, initialize logger, and provide panic handler. (Removed as it conflicts with com_logger) */
//uefi_services::init(&mut system_table).unwrap();

/* Clear stdout/stderr output screen */
//system_table.stdout().clear().expect("Failed to clear the stdout output screen.");
//system_table.stderr().clear().expect("Failed to clear the stderr output screen.");

/* Setup a logger with the default settings. The default settings is COM1 port with level filter Info */
//com_logger::init();

// Use COM2 port with level filter Info
com_logger::builder()
.base(0x2f8)
.filter(LevelFilter::Info)
.setup();

log::info!("UEFI Hypervisor (Illusion) in Rust");

/* Make the system pause for 10 seconds */
log::info!("[+] Stalling the processor for 10 seconds");
system_table.boot_services().stall(10_000_000);

/* Start Windows EFI Boot Manager (bootmgfw.efi) */
log::info!("[+] Starting Windows EFI Boot Manager (bootmgfw.efi)...");
boot_services
.start_image(bootmgfw_handle)
.expect("[-] Failed to start Windows EFI Boot Manager");

Status::SUCCESS
}
3 changes: 2 additions & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[toolchain]
channel = "nightly"
channel = "nightly"
targets = ["x86_64-unknown-uefi"]

0 comments on commit 5f20480

Please sign in to comment.