Begin setting up registers for virtual paging

This commit is contained in:
wmpod2xwie 2025-02-10 11:08:04 +11:00
parent 395d33035a
commit 5338d8ded5
5 changed files with 38 additions and 23 deletions

9
Cargo.lock generated
View File

@ -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",
]

View File

@ -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"

Binary file not shown.

View File

@ -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 {}