Paging should work ish, need to complete page reservation for kernel app. need to set stack pointer, then we are ready to hit it.

This commit is contained in:
ivajon
2026-05-11 18:16:33 +02:00
parent c68d3fab14
commit 4c2a5b1068
8 changed files with 970 additions and 30 deletions

View File

@@ -73,6 +73,20 @@ pub struct Handle(*mut ());
#[derive(Debug)]
pub struct ExitBootServicesKey(usize);
#[repr(C, packed)]
pub struct Guid {
_1: u32,
_2: u16,
_3: u16,
_4: [u8; 8],
}
const EFI_LOADED_IMAGE_PROTOCOL_GUID: Guid = Guid {
_1: 0x5B1B31A1,
_2: 0x9562,
_3: 0x11d2,
_4: [0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B],
};
#[repr(C)]
pub struct EfiBootServices {
hdr: EfiTableHeader,
@@ -111,7 +125,12 @@ pub struct EfiBootServices {
install_protocol_interface: *const core::ffi::c_void,
reinstall_protocol_interface: *const core::ffi::c_void,
uninstall_protocol_interface: *const core::ffi::c_void,
handle_protocol: *const core::ffi::c_void,
// TODO: Handle interface here
handle_protocol: extern "efiapi" fn(
efi_handle: Handle,
protocol: *const Guid,
interface: *const *const core::ffi::c_void,
) -> RawUefiStatus,
reserved: *const core::ffi::c_void,
register_protocol_notify: *const core::ffi::c_void,
locate_handle: *const core::ffi::c_void,
@@ -233,6 +252,20 @@ impl<'a> Iterator for PageIter<'a> {
}
}
#[repr(C)]
pub struct EfiLoadedImageProtocol {
pub revision: u32,
pub parent_handle: Handle,
pub system_table: *mut EfiSystemTable,
pub device_handle: Handle,
pub file_path: *mut core::ffi::c_void, // EFI_DEVICE_PATH_PROTOCOL*
pub reserved: *mut core::ffi::c_void,
pub load_options_size: u32,
pub load_options: *mut core::ffi::c_void,
pub image_base: *mut u8, // ← what you want
pub image_size: u64, // ← what you want
}
impl EfiBootServices {
pub fn memory_map<'a, 'b>(
&mut self,
@@ -287,6 +320,27 @@ impl EfiBootServices {
}
Err(Some(res))
}
pub fn get_image_info(&self, handle: Handle) -> Result<(*const u8, u64), Option<UefiStatus>> {
let protocol = EFI_LOADED_IMAGE_PROTOCOL_GUID;
let mut interface: *mut EfiLoadedImageProtocol = core::ptr::null_mut();
let Some(ret) = (self.handle_protocol)(
handle,
core::ptr::from_ref(&protocol),
core::ptr::from_mut(&mut interface).cast(),
)
.interpret() else {
return Err(None);
};
if ret.is_error() {
return Err(Some(ret));
}
let result = (unsafe { interface.read() });
Ok((result.image_base, result.image_size))
}
}
impl EfiSystemTable {