1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#![no_std]
#![feature(alloc)]
#![feature(alloc_error_handler)]
#![feature(alloc_prelude)]
#![feature(panic_info_message)]

extern crate alloc;
extern crate late_static;
extern crate r_efi;
extern crate ucs2;

mod allocator;
#[macro_use] mod console;

use alloc::prelude::v1::*;

pub use alloc::*;
pub use self::console::*;

pub mod efi;

#[global_allocator]
static ALLOCATOR: allocator::Allocator = allocator::Allocator;

extern {
    #[no_mangle]
    fn efw_main();
}

#[no_mangle]
unsafe extern fn efi_main(handle: efi::bits::Handle, system_table: *mut efi::bits::SystemTable) -> efi::bits::Status {
    efi::Handle::init_self_handle(handle);
    efi::SystemTable::init(system_table);

    efw_main();

    efi::bits::Status::SUCCESS
}

#[panic_handler]
fn panic_handler(panic_info: &core::panic::PanicInfo) -> ! {
    let message = match panic_info.message() {
        Some(s) => s.clone(),
        None => format_args!("no message"),
    };
    println!("Panic occured: \"{}\"", message);
    match panic_info.location() {
        Some(l) => {
            println!("  File: {}", l.file());
            println!("  Line: {}", l.line());
            println!("  Column: {}", l.column());
        },
        None => {},
    }
    println!("Halting...");
    loop {}
}