aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Shipp <nick@shipp.ninja>2018-10-01 21:41:35 -0400
committerNick Shipp <nick@shipp.ninja>2018-10-01 21:41:35 -0400
commit56b399a7d79a36304a93adab67220ae2af1b93a9 (patch)
tree1f0dfe19ff76c41b7cbb241b3f788019da8f2c23
parenta10f50a5f908e77cd350afe91cdf66821172a5b3 (diff)
Switch to uefi-rsHEADmaster
-rw-r--r--.gitmodules6
-rw-r--r--bunny/Cargo.toml5
-rw-r--r--bunny/Xargo.toml2
m---------bunny/libefi0
-rw-r--r--bunny/src/interrupt.rs24
-rw-r--r--bunny/src/lapic.rs2
-rw-r--r--bunny/src/main.rs49
-rw-r--r--bunny/src/println.rs2
m---------bunny/uefi-rs0
-rw-r--r--bunny/x86_64-pc-uefi.json22
10 files changed, 54 insertions, 58 deletions
diff --git a/.gitmodules b/.gitmodules
index d82a40a..3798097 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
-[submodule "bunny/libefi"]
- path = bunny/libefi
- url = https://github.com/reynoldsbd/libefi
+[submodule "bunny/uefi-rs"]
+ path = bunny/uefi-rs
+ url = https://github.com/GabrielMajeri/uefi-rs.git
diff --git a/bunny/Cargo.toml b/bunny/Cargo.toml
index e8a5617..119113b 100644
--- a/bunny/Cargo.toml
+++ b/bunny/Cargo.toml
@@ -6,6 +6,9 @@ build = "build.rs"
edition = "2018"
[dependencies]
-efi = { path = "libefi" }
+uefi = { path = "uefi-rs" }
+uefi-exts = { path = "uefi-rs/uefi-exts" }
+uefi-services = { path = "uefi-rs/uefi-services" }
x86_64 = "*"
volatile = "*"
+log = "*"
diff --git a/bunny/Xargo.toml b/bunny/Xargo.toml
new file mode 100644
index 0000000..c2a2569
--- /dev/null
+++ b/bunny/Xargo.toml
@@ -0,0 +1,2 @@
+[target.x86_64-pc-uefi.dependencies.alloc]
+features = []
diff --git a/bunny/libefi b/bunny/libefi
deleted file mode 160000
-Subproject eb7ea420e9f2d8f61961556db9e669fe165ec6c
diff --git a/bunny/src/interrupt.rs b/bunny/src/interrupt.rs
index 4ac8192..a79e4ed 100644
--- a/bunny/src/interrupt.rs
+++ b/bunny/src/interrupt.rs
@@ -9,59 +9,59 @@ pub const IRQ_APIC_LVT_ERROR: u8 = 0x20;
static mut IDT: InterruptDescriptorTable = InterruptDescriptorTable::new();
extern "x86-interrupt" fn handle_divzero(exc: &mut ExceptionStackFrame) {
- println!("DIVISION BY ZERO: {:x?}", exc);
+ error!("DIVISION BY ZERO: {:x?}", exc);
loop {}
}
extern "x86-interrupt" fn handle_seg_not_present(exc: &mut ExceptionStackFrame, code: u64) {
- println!("SEGMENT NOT PRESENT 0x{:x}: {:x?}", code, exc);
+ error!("SEGMENT NOT PRESENT 0x{:x}: {:x?}", code, exc);
}
extern "x86-interrupt" fn handle_ss_fault(exc: &mut ExceptionStackFrame, code: u64) {
- println!("STACK SEGMENT FAULT 0x{:x}: {:x?}", code, exc);
+ error!("STACK SEGMENT FAULT 0x{:x}: {:x?}", code, exc);
loop {}
}
extern "x86-interrupt" fn handle_gp(exc: &mut ExceptionStackFrame, code: u64) {
- println!("GENERAL PROTECTION FAULT 0x{:x}: {:x?}", code, exc);
+ error!("GENERAL PROTECTION FAULT 0x{:x}: {:x?}", code, exc);
loop {}
}
extern "x86-interrupt" fn handle_iopc(exc: &mut ExceptionStackFrame) {
- println!("INVALID OPCODE @ 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
+ error!("INVALID OPCODE @ 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
loop {}
}
extern "x86-interrupt" fn handle_pagefault(exc: &mut ExceptionStackFrame, code: PageFaultErrorCode) {
- println!("PAGE FAULT {:?}: {:x?}", code, exc);
+ error!("PAGE FAULT {:?}: {:x?}", code, exc);
loop {}
}
extern "x86-interrupt" fn handle_inval_tss(exc: &mut ExceptionStackFrame, code: u64) {
- println!("INVALID TSS 0x{:x}: {:x?}", code, exc);
+ error!("INVALID TSS 0x{:x}: {:x?}", code, exc);
loop {}
}
extern "x86-interrupt" fn handle_doublefault(exc: &mut ExceptionStackFrame, code: u64) {
- println!("DOUBLE FAULT 0x{:x}: {:x?}", code, exc);
+ error!("DOUBLE FAULT 0x{:x}: {:x?}", code, exc);
loop {}
}
extern "x86-interrupt" fn handle_mce(exc: &mut ExceptionStackFrame) {
- println!("MACHINE CHECK EXCEPTION: {:x?}", exc);
+ error!("MACHINE CHECK EXCEPTION: {:x?}", exc);
loop {}
}
extern "x86-interrupt" fn handle_breakpoint(exc: &mut ExceptionStackFrame) {
- println!("BREAKPOINT AT 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
+ error!("BREAKPOINT AT 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
}
extern "x86-interrupt" fn handle_apic_error(exc: &mut ExceptionStackFrame) {
- println!("APIC ERROR AT 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
+ error!("APIC ERROR AT 0x{:x}: {:x?}", exc.instruction_pointer.as_u64(), exc);
}
fn unhandled_irq(exc: &mut ExceptionStackFrame, num: u8) {
- println!("UNHANDLED IRQ#{:02x}h: {:x?}", num, exc);
+ error!("UNHANDLED IRQ#{:02x}h: {:x?}", num, exc);
}
diff --git a/bunny/src/lapic.rs b/bunny/src/lapic.rs
index c1bfce6..111ac3d 100644
--- a/bunny/src/lapic.rs
+++ b/bunny/src/lapic.rs
@@ -78,7 +78,7 @@ impl LocalApic {
/* Set bits 10 and 11 of IA32_APIC_BASE MSR to enable x2APIC */
let mut apic_base_msr = Msr::new(0x1b);
let mut apic_base = unsafe { apic_base_msr.read() };
- dprintln!("APIC BASE: 0x{:x}", apic_base);
+ debug!("APIC BASE: 0x{:x}", apic_base);
apic_base |= 0b11 << 10;
unsafe { apic_base_msr.write(apic_base) };
diff --git a/bunny/src/main.rs b/bunny/src/main.rs
index e7f5c70..cfb2f4a 100644
--- a/bunny/src/main.rs
+++ b/bunny/src/main.rs
@@ -2,24 +2,20 @@
#![no_std]
#![no_main]
-extern crate efi;
-extern crate x86_64;
-extern crate volatile;
+#[macro_use]
+extern crate log;
#[macro_use]
mod println;
mod interrupt;
mod lapic;
mod io;
-mod uefi;
mod inttraits;
-use core::panic::PanicInfo;
use core::ptr;
use core::slice;
-use efi::types::Handle;
-use efi::SystemTable;
+use uefi::prelude::*;
use x86_64::instructions::interrupts;
use self::interrupt::*;
@@ -28,8 +24,6 @@ use self::inttraits::*;
const NUM_CORES: u8 = 4;
-static mut SYSTEM_TABLE: *const SystemTable = 0 as *const SystemTable;
-
#[allow(improper_ctypes)]
extern "C" {
#[link_name = "llvm.x86.rdtsc"]
@@ -49,23 +43,18 @@ fn busy() {
}
#[no_mangle]
-pub extern fn efi_main(_handle: Handle, systab: &SystemTable) -> ! {
+pub extern fn efi_main(_handle: uefi::Handle, systab: &'static SystemTable) -> ! {
/*
* Disable interrupts to avoid noise generated before we actually
* have anything to do *with* interrupts
*/
interrupts::disable();
- /*
- * Save EFI system table ptr to globally accessible location.
- * MUST do this before calling println!(), or just about anything else.
- */
- unsafe {
- SYSTEM_TABLE = systab;
- }
+ /* Initialize UEFI boot services (logger, allocator) */
+ uefi_services::init(systab);
- println!("FUZZY BUNNIES {}", env!("CARGO_PKG_VERSION"));
- println!("efi_main @ 0x{:x}", efi_main as *const u8 as usize);
+ info!("FUZZY BUNNIES {}", env!("CARGO_PKG_VERSION"));
+ info!("efi_main @ 0x{:x}", efi_main as *const u8 as usize);
/* Set up basic exception handlers */
register_handlers();
@@ -133,7 +122,7 @@ pub extern fn efi_main(_handle: Handle, systab: &SystemTable) -> ! {
n_aps = unsafe { ptr::read_volatile(0x6001 as *const u8) };
}
- dprintln!("All cores online");
+ debug!("All cores online");
/* All good, turn interrupts back on and idle */
interrupts::enable();
@@ -142,23 +131,3 @@ pub extern fn efi_main(_handle: Handle, systab: &SystemTable) -> ! {
unsafe { asm!("hlt"); }
}
}
-
-#[lang = "eh_personality"]
-#[no_mangle]
-pub extern fn eh_personality() { }
-
-#[no_mangle]
-#[panic_handler]
-pub extern fn panic_impl(pi: &PanicInfo) -> ! {
- println!("!!! PANIC !!!");
-
- if let Some(loc) = pi.location() {
- println!("in file {}:{}:{}", loc.file(), loc.line(), loc.column());
- }
-
- if let Some(msg) = pi.message() {
- println!("{}", msg);
- }
-
- loop {}
-}
diff --git a/bunny/src/println.rs b/bunny/src/println.rs
index 6e17cd2..15f74de 100644
--- a/bunny/src/println.rs
+++ b/bunny/src/println.rs
@@ -2,7 +2,7 @@
macro_rules! print {
($($arg:tt)*) => ({
use core::fmt::Write;
- unsafe { (&*crate::SYSTEM_TABLE.as_ref().unwrap().con_out) }
+ uefi_services::system_table().stdout()
.write_fmt(format_args!($($arg)*))
.expect("could not write to console");
});
diff --git a/bunny/uefi-rs b/bunny/uefi-rs
new file mode 160000
+Subproject a556d226fba603dee8a9d5f71e7c1ad44b87ece
diff --git a/bunny/x86_64-pc-uefi.json b/bunny/x86_64-pc-uefi.json
new file mode 100644
index 0000000..ae455de
--- /dev/null
+++ b/bunny/x86_64-pc-uefi.json
@@ -0,0 +1,22 @@
+{
+ "llvm-target": "x86_64-pc-windows-msvc",
+ "target-endian": "little",
+ "target-pointer-width": "64",
+ "target-c-int-width": "32",
+ "os": "none",
+ "arch": "x86_64",
+ "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
+ "executables": true,
+ "disable-redzone": true,
+ "panic-strategy": "abort",
+ "linker-flavor": "lld-link",
+ "pre-link-args": {
+ "lld-link": [
+ "/SUBSYSTEM:EFI_Application",
+ "/ENTRY:efi_main"
+ ]
+ },
+ "exe-suffix": ".efi",
+ "position-independent-executables": "true",
+ "emit-debug-gdb-scripts": false
+}