From 56b399a7d79a36304a93adab67220ae2af1b93a9 Mon Sep 17 00:00:00 2001 From: Nick Shipp Date: Mon, 1 Oct 2018 21:41:35 -0400 Subject: Switch to uefi-rs --- bunny/Cargo.toml | 5 ++++- bunny/Xargo.toml | 2 ++ bunny/libefi | 1 - bunny/src/interrupt.rs | 24 +++++++++++------------ bunny/src/lapic.rs | 2 +- bunny/src/main.rs | 49 +++++++++-------------------------------------- bunny/src/println.rs | 2 +- bunny/uefi-rs | 1 + bunny/x86_64-pc-uefi.json | 22 +++++++++++++++++++++ 9 files changed, 52 insertions(+), 56 deletions(-) create mode 100644 bunny/Xargo.toml delete mode 160000 bunny/libefi create mode 160000 bunny/uefi-rs create mode 100644 bunny/x86_64-pc-uefi.json (limited to 'bunny') 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 index eb7ea42..0000000 --- a/bunny/libefi +++ /dev/null @@ -1 +0,0 @@ -Subproject commit eb7ea420e9f2d8f61961556db9e669fe165ec6cb 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 index 0000000..a556d22 --- /dev/null +++ b/bunny/uefi-rs @@ -0,0 +1 @@ +Subproject commit a556d226fba603dee8a9d5f71e7c1ad44b87ecef 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 +} -- cgit v1.2.3-70-g09d2