From df083e306a53e6a45a5730e7059032be43cc75ff Mon Sep 17 00:00:00 2001 From: Nick Shipp Date: Sun, 30 Sep 2018 17:05:47 -0400 Subject: Dirty rotten commit full of badness Milestone: Got SMP cores booting and into long mode. The rest is all trash, but maybe trash worth a future archaeological dig. --- bunny/src/uefi.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 bunny/src/uefi.rs (limited to 'bunny/src/uefi.rs') diff --git a/bunny/src/uefi.rs b/bunny/src/uefi.rs new file mode 100644 index 0000000..a4a76d1 --- /dev/null +++ b/bunny/src/uefi.rs @@ -0,0 +1,49 @@ +use core::ptr; +use efi::boot_services::*; +use efi::types::Status; + +extern "win64" fn _wakeup(_ev: &Event, _ctxt: &u64) { } + +pub fn sleep(microseconds: u64) { + let bs = &unsafe { &*::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(); +} + +pub fn dump_mem_map() -> Result { + let bs = &unsafe { &*::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) +} -- cgit v1.2.3-54-g00ecf