aboutsummaryrefslogtreecommitdiff
path: root/bunny/src/uefi.rs
blob: e23e6685e43f531c6b5908f120e2d8479184bacf (plain)
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
use core::ptr;
use efi::boot_services::*;
use efi::types::Status;

extern "win64" fn _wakeup(_ev: &Event, _ctxt: &u64) { }

#[allow(unused)]
pub fn sleep(microseconds: u64) {
    let bs = &unsafe { &*crate::SYSTEM_TABLE }.boot_services;

    dprintln!("create_event");
    let mut ev = &Event::default();

    (bs._create_event)(EventType::TIMER,
                       TPL::Application,
                       None,
                       ptr::null(),
                       &mut ev)
        .as_result()
        .map(|_| ev)
        .unwrap();

    dprintln!("set_timer");
    /* Set timer (unit is 100ns, so multiply microseconds by 10) */
    bs.set_timer(ev,
                 TimerDelay::Relative,
                 microseconds * 10)
        .unwrap();

    dprintln!("wait_for_event");
    bs.wait_for_event(&[ev]).unwrap();
    dprintln!("close_event");
    bs.close_event(ev).unwrap();
}

#[allow(unused)]
pub fn dump_mem_map() -> Result<usize, Status>  {
    let bs = &unsafe { &*crate::SYSTEM_TABLE }.boot_services;

    let mmap = bs.get_memory_map()?;

    println!("{:^16} {:^16} {:^23}", "PHYS START", "PHYS END", "TYPE");
    for map in mmap.iter() {
        println!("{:016x} {:016x} {:23?}",
                 map.physical_start as u64,
                 (map.physical_start as u64) + (0x1000 * map.number_of_pages),
                 map.memory_type);
    }

    Ok(mmap.key)
}