diff --git a/src/gop_policy.rs b/src/gop_policy.rs index ba7f928..8587ac6 100644 --- a/src/gop_policy.rs +++ b/src/gop_policy.rs @@ -72,29 +72,10 @@ extern "efiapi" fn GetPlatformDockStatus(_CurrentDockStatus: DockStatus) -> Stat Status::UNSUPPORTED } -impl GopPolicy { - pub fn new() -> Box { - Box::new(Self { - Revision: Self::REVISION_03, - GetPlatformLidStatus, - GetVbtData, - GetPlatformDockStatus, - GopOverrideGuid: Guid::NULL, - }) - } - - pub fn install(self: Box) -> Result<()> { - let uefi = unsafe { std::system_table_mut() }; - - let self_ptr = Box::into_raw(self); - let mut handle = Handle(0); - Result::from((uefi.BootServices.InstallProtocolInterface)( - &mut handle, - &Self::GUID, - InterfaceType::Native, - self_ptr as usize, - ))?; - - Ok(()) - } -} +pub static GOP_POLICY: GopPolicy = GopPolicy { + Revision: GopPolicy::REVISION_03, + GetPlatformLidStatus, + GetVbtData, + GetPlatformDockStatus, + GopOverrideGuid: Guid::NULL, +}; diff --git a/src/main.rs b/src/main.rs index ee52ffe..af58f67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,20 +3,23 @@ #![no_std] #![no_main] -#[macro_use] extern crate uefi_std as std; -use std::prelude::*; - mod gop_policy; +use gop_policy::{GopPolicy, GOP_POLICY}; +use std::prelude::*; +use std::uefi::boot::InterfaceType; + #[no_mangle] pub extern "C" fn main() -> Status { - let gop_policy = gop_policy::GopPolicy::new(); - if let Err(err) = gop_policy.install() { - println!("GopPolicy error: {:?}", err); - err - } else { - Status::SUCCESS - } + let uefi = unsafe { std::system_table_mut() }; + let mut handle = Handle(0); + + (uefi.BootServices.InstallProtocolInterface)( + &mut handle, + &GopPolicy::GUID, + InterfaceType::Native, + core::ptr::addr_of!(GOP_POLICY) as usize, + ) }