diff --git a/Cargo.lock b/Cargo.lock index 5039349..62ad184 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,7 +1,14 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "registers" +version = "0.1.0" [[package]] name = "uefi-os-loader" version = "0.1.0" +dependencies = [ + "registers", +] diff --git a/Cargo.toml b/Cargo.toml index 045db1b..52d1418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +registers = { path = "../registers" } [[bin]] name = "os_loader" diff --git a/docs/Intel® 64 and IA-32 Architectures Software Developer’s Manual.pdf b/docs/Intel® 64 and IA-32 Architectures Software Developer’s Manual.pdf index 74f04d0..95ddb45 100644 Binary files a/docs/Intel® 64 and IA-32 Architectures Software Developer’s Manual.pdf and b/docs/Intel® 64 and IA-32 Architectures Software Developer’s Manual.pdf differ diff --git a/docs/OVMF_VARS.fd b/docs/OVMF_VARS.fd index 2787fd2..f70fc9c 100644 Binary files a/docs/OVMF_VARS.fd and b/docs/OVMF_VARS.fd differ diff --git a/src/os_loader.rs b/src/os_loader.rs index 4910cb7..49f137a 100644 --- a/src/os_loader.rs +++ b/src/os_loader.rs @@ -21,6 +21,8 @@ use simple_text_output::SimpleTextOutputProtocol; use structs::Status; use system_table::SystemTable; use types::Handle; +use registers; +use core::arch::asm; #[no_mangle] #[export_name = "efi_main"] @@ -29,6 +31,8 @@ extern "efiapi" fn efi_main(image_handle: Handle, system_table_ptr: *mut SystemT return usize::from(Status::OutOfResources); } + set_control_registers(); + let system_table: &SystemTable = initialize_system_table(system_table_ptr); let console_out: Option<&SimpleTextOutputProtocol> = initialize_console_out(system_table); let boot_services_table: Option<&BootServicesTable> = initialize_boot_services(system_table); @@ -40,32 +44,11 @@ extern "efiapi" fn efi_main(image_handle: Handle, system_table_ptr: *mut SystemT let mut mode_number: usize = 0; (console_out.output_string)(console_out, utf16_string!("my-os").as_ptr()); + (console_out.output_string)(console_out, utf16_string!("\n").as_ptr()); } - // if let Some(boot_services_table) = boot_services_table { - // let mut filesystem_protocol: *mut *mut SimpleFileSystemProtocol = null_mut(); - // let register = null_mut(); - // - // let mut status: Status = (boot_services_table.locate_protocol)( - // &SimpleFileSystemProtocol::GUID, - // register, - // filesystem_protocol as *mut _ as *mut _, - // ); - // - // let mut root: *mut FileProtocol = core::ptr::null_mut(); - // unsafe { - // status = ((*(*filesystem_protocol)).open_volume)((*filesystem_protocol), &mut root); - // let mut kernel_file: *mut FileProtocol = core::ptr::null_mut(); - // status = ((root.as_mut().unwrap().open)(root, &mut kernel_file, utf16_string!("\\EFI\\BOOT\\KERNEL.BIN").as_ptr(), OpenMode::FileModeRead, 0)); - // } - // } - loop {} - // if let Some(boot_services_table) = boot_services_table { - // (boot_services_table.exit)(image_handle, Status::Success, 0, null()); - // } - usize::from(Status::Success) // EFI_SUCCESS } @@ -90,6 +73,30 @@ fn initialize_boot_services(system_table: &SystemTable) -> Option<&BootServicesT } } +fn set_control_registers() -> () { + unsafe { + registers::CR0::set_protection_enabled_flag(true); + registers::CR0::set_monitor_coprocessor_flag(true); + registers::CR0::set_emulation_flag(false); + registers::CR0::set_task_switched_flag(false); + registers::CR0::set_extension_type_flag(true); + registers::CR0::set_numeric_error_flag(true); + registers::CR0::set_paging_flag(true); + registers::CR0::set_cache_disable_flag(false); + registers::CR0::set_non_writethrough_flag(false); + registers::CR0::set_alignment_mask_flag(false); + registers::CR0::set_write_protect_flag(false); + registers::CR4::set_physical_address_extension_flag(true); + registers::CR4::set_OSFXSR_flag(true); + registers::CR4::set_OSXMMEXCPT_flag(true); + registers::CR4::set_OSXSAVE_flag(true); + registers::CR4::set_SMEP_enable_bit_flag(false); + registers::CR4::set_SMAP_enable_bit_flag(false); + registers::CR4::set_PCID_enable_bit_flag(false); + registers::x87::init_fpu_state(); + } +} + #[panic_handler] fn panic(_info: &PanicInfo) -> ! { loop {}