diff options
Diffstat (limited to 'bunny/src')
-rw-r--r-- | bunny/src/interrupt.rs | 24 | ||||
-rw-r--r-- | bunny/src/lapic.rs | 2 | ||||
-rw-r--r-- | bunny/src/main.rs | 49 | ||||
-rw-r--r-- | bunny/src/println.rs | 2 |
4 files changed, 23 insertions, 54 deletions
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"); }); |