Cease working on loading the kernel, switch to setting up the CPU for virtual memory and long mode

This commit is contained in:
wmpod2xwie 2024-06-23 22:21:53 +10:00
parent 8ca901ef50
commit 395d33035a
10 changed files with 310 additions and 107 deletions

Binary file not shown.

View File

@ -1,5 +1,7 @@
use crate::memory_allocation_services::*;
use crate::structs::*; use crate::structs::*;
use crate::types::Handle; use crate::types::Handle;
use core::ffi::c_void;
/** /**
UEFI uses the EFI Boot Services Table, which contains a table header and pointers to all of the boot UEFI uses the EFI Boot Services Table, which contains a table header and pointers to all of the boot
services. The definition for this table is shown in the following code fragments. Except for the table services. The definition for this table is shown in the following code fragments. Except for the table
@ -58,9 +60,40 @@ pub struct BootServicesTable {
pub type RaiseTpl = extern "efiapi" fn() -> Status; pub type RaiseTpl = extern "efiapi" fn() -> Status;
pub type RestoreTpl = extern "efiapi" fn() -> Status; pub type RestoreTpl = extern "efiapi" fn() -> Status;
pub type AllocatePages = extern "efiapi" fn() -> Status; /// The AllocatePages() function allocates the requested number of pages and returns a pointer to the base address of the page range in the location referenced by Memory. The function scans the memory map to locate free pages. When it finds a physically contiguous block of pages that is large enough and also satisfies the allocation requirements of Type, it changes the memory map to indicate that the pages are now of type MemoryType. In general, UEFI OS loaders and UEFI applications should allocate memory (and pool) of type EfiLoaderData. UEFI boot service drivers must allocate memory (and pool) of type EfiBootServicesData. UREFI runtime drivers should allocate memory (and pool) of type EfiRuntimeServicesData (although such allocation can only be made during boot services time). Allocation requests of Type AllocateAnyPages allocate any available range of pages that satisfies the request. On input, the address pointed to by Memory is ignored. Allocation requests of Type AllocateMaxAddress allocate any available range of pages whose uppermost address is less than or equal to the address pointed to by Memory on input. Allocation requests of Type AllocateAddress allocate pages at the address pointed to by Memory on input.
pub type FreePages = extern "efiapi" fn() -> Status; /// # Arguments
pub type GetMemoryMap = extern "efiapi" fn() -> Status; /// * `Type` - The type of allocation to perform.
/// * `MemoryType` - The type of memory to allocate. Normal allocations (that is, allocations by any UEFI ap plication) are of type LoaderData. MemoryType values in the range 0x70000000..0x7FFFFFFF are reserved for OEM use. MemoryType values in the range 0x80000000..0xFFFFFFFF are reserved for use by UEFI OS loaders that are provided by operating system vendors.
/// * `Pages` - The number of contiguous 4 KiB pages to allocate.
/// * `Memory` - Pointer to a physical address. On input, the way in which the address is used depends on the value of Type. On output the address is set to the base of the page range that was allocated.
pub type AllocatePages = extern "efiapi" fn(
r#type: AllocateType,
memory_type: MemoryType,
pages: usize,
&mut PhysicalAddress,
) -> Status;
/// The FreePages() function returns memory allocated by AllocatePages() to the firmware.
/// # Arguments
/// * `Memory` - The base physical address of the pages to be freed. Type EFI_PHYSICAL_ADDRESS is defined in the EFI_BOOT_SERVICES.AllocatePages() function description.
/// * `Pages` - The number of contiguous 4 KiB pages to free.
pub type FreePages = extern "efiapi" fn(memory: PhysicalAddress, pages: usize) -> Status;
/// The GetMemoryMap() function returns a copy of the current memory map. The map is an array of memory descriptors, each of which describes a contiguous block of memory. The map describes all of memory, no mat- ter how it is being used. That is, it includes blocks allocated by EFI_BOOT_SERVICES.AllocatePages() and EFI_BOOT_SERVICES.AllocatePool(), as well as blocks that the firmware is using for its own purposes. The memory map is only used to describe memory that is present in the system. The firmware does not return a range description for address space regions that are not backed by physical hardware. Regions that are backed by physical hardware, but are not supposed to be accessed by the OS, must be returned as EfiReservedMemoryType. The OS may use addresses of memory ranges that are not described in the memory map at its own discretion. Until EFI_BOOT_SERVICES.ExitBootServices() is called, the memory map is owned by the firmware and the cur- rently executing UEFI Image should only use memory pages it has explicitly allocated. If the MemoryMap buffer is too small, the EFI_BUFFER_TOO_SMALL error code is returned and the MemoryMap- Size value contains the size of the buffer needed to contain the current memory map. The actual size of the buffer allocated for the consequent call to GetMemoryMap() should be bigger then the value returned in MemoryMapSize, since allocation of the new buffer may potentially increase memory map size. On success a MapKey is returned that identifies the current memory map. The firmwares key is changed every time something in the memory map changes. In order to successfully invoke EFI_BOOT_SERVICES.ExitBootServices() the caller must provide the current memory map key. The GetMemoryMap() function also returns the size and revision number of the EFI_MEMORY_DESCRIPTOR. The DescriptorSize represents the size in bytes of an EFI_MEMORY_DESCRIPTOR array element returned in Mem- oryMap. The size is returned to allow for future expansion of the EFI_MEMORY_DESCRIPTOR in response to hardware innovation. The structure of the EFI_MEMORY_DESCRIPTOR may be extended in the future but it will remain backwards compatible with the current definition. Thus OS software must use the DescriptorSize to find the start of each EFI_MEMORY_DESCRIPTOR in the MemoryMap array.
/// # Arguments
/// * `MemoryMapSize` - A pointer to the size, in bytes, of the MemoryMap buffer. On input, this is the size of the buffer allocated by the caller. On output, it is the size of the buffer returned by the firmware if the buffer was large enough, or the size of the buffer needed to contain the map if the buffer was too small.
/// * `MemoryMap` - A pointer to the buffer in which firmware places the current memory map. The map is an array of EFI_MEMORY_DESCRIPTORs.
/// * `MapKey` - A pointer to the location in which firmware returns the key for the current memory map.
/// * `DescriptorSize` - A pointer to the location in which firmware returns the size, in bytes, of an individual EFI_MEMORY_DESCRIPTOR.
/// * `DescriptorVersion` - A pointer to the location in which firmware returns the version number associated with the EFI_MEMORY_DESCRIPTOR.
pub type GetMemoryMap = extern "efiapi" fn(
memory_map_size: &mut usize,
memory_map: *mut MemoryDescriptor,
map_key: &mut usize,
descriptor_size: &mut usize,
descriptor_version: &mut u32,
) -> Status;
pub type AllocatePool = extern "efiapi" fn() -> Status; pub type AllocatePool = extern "efiapi" fn() -> Status;
pub type FreePool = extern "efiapi" fn() -> Status; pub type FreePool = extern "efiapi" fn() -> Status;
pub type CreateEvent = extern "efiapi" fn() -> Status; pub type CreateEvent = extern "efiapi" fn() -> Status;
@ -84,7 +117,7 @@ pub type Exit = extern "efiapi" fn(
image_handle: Handle, image_handle: Handle,
exit_status: Status, exit_status: Status,
exit_data_size: usize, exit_data_size: usize,
*const u16 *const u16,
) -> Status; ) -> Status;
pub type UnloadImage = extern "efiapi" fn() -> Status; pub type UnloadImage = extern "efiapi" fn() -> Status;
pub type ExitBootServices = extern "efiapi" fn() -> Status; pub type ExitBootServices = extern "efiapi" fn() -> Status;
@ -98,7 +131,16 @@ pub type CloseProtocol = extern "efiapi" fn() -> Status;
pub type OpenProtocolInformation = extern "efiapi" fn() -> Status; pub type OpenProtocolInformation = extern "efiapi" fn() -> Status;
pub type ProtocolPerHandle = extern "efiapi" fn() -> Status; pub type ProtocolPerHandle = extern "efiapi" fn() -> Status;
pub type LocateHandleBuffer = extern "efiapi" fn() -> Status; pub type LocateHandleBuffer = extern "efiapi" fn() -> Status;
pub type LocateProtocol = extern "efiapi" fn() -> Status; /// The LocateProtocol() function finds the first device handle that support Protocol, and returns a pointer to the protocol interface from that handle in Interface. If no protocol instances are found, then Interface is set to NULL. If Interface is NULL, then EFI_INVALID_PARAMETER is returned. If Protocol is NULL, then EFI_INVALID_PARAMETER is returned. If Registration is NULL, and there are no handles in the handle database that support Protocol, then EFI_NOT_FOUND is returned. If Registration is not NULL, and there are no new handles for Registration, then EFI_NOT_FOUND is returned.
/// # Arguments
/// * `Protocol` - Provides the protocol to search for.
/// * `Registration` - Optional registration key returned from EFI_BOOT_SERVICES.RegisterProtocolNotify() . If Registration is NULL, then it is ignored.
/// * `Interface` - On return, a pointer to the first interface that matches Protocol and Registration.
pub type LocateProtocol = extern "efiapi" fn(
protocol: &GUID,
registration: *mut c_void,
interface: *mut *mut c_void,
) -> Status;
pub type InstallMultipleProtocolInterfaces = extern "efiapi" fn() -> Status; pub type InstallMultipleProtocolInterfaces = extern "efiapi" fn() -> Status;
pub type UninstallMultipleProtocolInterfaces = extern "efiapi" fn() -> Status; pub type UninstallMultipleProtocolInterfaces = extern "efiapi" fn() -> Status;
pub type CalculateCrc32 = extern "efiapi" fn() -> Status; pub type CalculateCrc32 = extern "efiapi" fn() -> Status;

13
src/macros.rs Normal file
View File

@ -0,0 +1,13 @@
#[macro_export]
macro_rules! utf16_string {
($s:expr) => {{
const LEN: usize = $s.len();
let mut utf16_array: [u16; LEN] = [0; LEN];
let utf16_iter = $s.encode_utf16();
for (index, char) in utf16_iter.enumerate() {
utf16_array[index] = char;
}
utf16_array
}};
}

View File

@ -0,0 +1,78 @@
#[repr(C)]
pub enum MemoryType {
ReservedMemoryType,
LoaderCode,
BootServicesCode,
BootServicesData,
RuntimeServicesCode,
RuntimeServiceData,
ConventionalMemory,
UnusableMemory,
ACPIReclaimMemory,
APCIMemoryNVS,
MemoryMappedIO,
MemoryMappedIOPortSpace,
PalCode,
PersistentMemory,
UnacceptedMemoryType,
MaxMemoryType,
}
pub type PhysicalAddress = u64;
pub type VirtualAddress = u64;
#[repr(C)]
pub struct MemoryDescriptor {
r#type: u32,
physical_start: PhysicalAddress,
virtual_start: VirtualAddress,
number_of_pages: u64,
attribute: Attribute,
}
#[repr(C)]
pub enum AllocateType {
/// Allocation requests of Type AllocateAnyPages allocate any available range of pages that satisfies the request. On input, the address pointed to by Memory is ignored.
AllocateAnyPages,
/// Allocation requests of Type AllocateMaxAddress allocate any available range of pages whose uppermost address is less than or equal to the address pointed to by Memory on input.
AllocateMaxAddress,
/// Allocation requests of Type AllocateAddress allocate pages at the address pointed to by Memory on input.
AllocateAddress,
MaxAllocateType,
}
#[repr(u64)]
pub enum Attribute {
/// The memory region supports being configured as not cacheable.
MemoryUC = 0x0000000000000001,
/// The memory region supports being configured as write combining.
MemoryWC = 0x0000000000000002,
/// The memory region supports being configured as cacheable with a “write through” policy. Writes that hit in the cache will also be written to main memory.
MemoryWT = 0x0000000000000004,
/// The memory region supports being configured as cacheable with a “write back” policy. Reads and writes that hit in the cache do not propagate to main memory. Dirty data is written back to main memory when a new cache line is allocated.
MemoryWB = 0x0000000000000008,
/// The memory region supports being configured as not cacheable, exported, and supports the “fetch and add” semaphore mechanism.
MemoryUCE = 0x0000000000000010,
/// Physical memory protection attribute: The memory region supports being configured as write protected by system hardware. This is typically used as a cacheability attribute today. The memory region supports being configured as cacheable with a “write protected” policy. Reads come from cache lines when possible, and read misses cause cache fills. Writes are propagated to the system bus and cause corresponding cache lines on all processors on the bus to be invalidated.
MemoryWP = 0x0000000000001000,
/// Physical memory protection attribute: The memory region supports being configured as read- protected by system hardware.
MemoryRP = 0x0000000000002000,
/// Physical memory protection attribute: The memory region supports being configured so it is protected by system hardware from executing code.
MemoryXP = 0x0000000000004000,
/// Runtime memory attribute: The memory region refers to persistent memory
MemoryNV = 0x0000000000008000,
/// The memory region provides higher reliability relative to other memory in the system. If all memory has the same reliability, then this bit is not used.
MemoryMoreReliable = 0x0000000000010000,
/// Physical memory protection attribute: The memory region supports making this memory range read-only by system hardware.
MemoryRO = 0x0000000000020000,
/// Specific-purpose memory (SPM). The memory is earmarked for specific purposes such as for specific device drivers or applications. The SPM attribute serves as a hint to the OS to avoid allocating this memory for core OS data or code that can not be relocated. Prolonged use of this memory for purposes other than the intended purpose may result in suboptimal platform performance.
MemorySP = 0x0000000000040000,
/// If this flag is set, the memory region is capable of being protected with the CPUs memory cryptographic capabilities. If this flag is clear, the memory region is not capable of being protected with the CPUs memory cryptographic capabilities or the CPU does not support CPU memory cryptographic capabilities.
MemoryCpuCrypto = 0x0000000000080000,
/// Runtime memory attribute: The memory region needs to be given a virtual mapping by the operating system when SetVirtualAddressMap() is called (described in Virtual Memory Services.
MemoryRuntime = 0x8000000000000000,
/// If this flag is set, the memory region is described with additional ISA-specific memory attributes as specified in EFI_MEMORY_ISA_MASK
MemoryISAValid = 0x4000000000000000,
/// Defines the bits reserved for describing optional ISA-specific cacheability attributes that are not covered by the standard UEFI Memory Attributes cacheability bits (EFI_MEMORY_UC, EFI_MEMORY_WC, EFI_MEMORY_WT, EFI_MEMORY_WB and EFI_MEMORY_UCE). See Calling Conventions for further ISA-specific enumeration of these bits.
MemoryISAMask = 0x0FFFF00000000000,
}

View File

@ -2,13 +2,21 @@
#![no_main] #![no_main]
pub mod boot_services; pub mod boot_services;
pub mod macros;
pub mod memory_allocation_services;
pub mod simple_filesystem_protocol;
pub mod simple_text_output; pub mod simple_text_output;
pub mod structs; pub mod structs;
pub mod system_table; pub mod system_table;
pub mod types; pub mod types;
use core::{panic::PanicInfo, ptr::null};
use boot_services::BootServicesTable; use boot_services::BootServicesTable;
use core::{
ffi::c_void,
panic::PanicInfo,
ptr::{null, null_mut},
};
use simple_filesystem_protocol::{FileProtocol, OpenMode, SimpleFileSystemProtocol};
use simple_text_output::SimpleTextOutputProtocol; use simple_text_output::SimpleTextOutputProtocol;
use structs::Status; use structs::Status;
use system_table::SystemTable; use system_table::SystemTable;
@ -27,11 +35,36 @@ extern "efiapi" fn efi_main(image_handle: Handle, system_table_ptr: *mut SystemT
if let Some(console_out) = console_out { if let Some(console_out) = console_out {
(console_out.clear_screen)(console_out); (console_out.clear_screen)(console_out);
let mut columns: usize = 0;
let mut rows: usize = 0;
let mut mode_number: usize = 0;
(console_out.output_string)(console_out, utf16_string!("my-os").as_ptr());
} }
if let Some(boot_services_table) = boot_services_table { // if let Some(boot_services_table) = boot_services_table {
(boot_services_table.exit)(image_handle, Status::Success, 0, null()); // 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 usize::from(Status::Success) // EFI_SUCCESS
} }
@ -51,7 +84,7 @@ fn initialize_console_out(system_table: &SystemTable) -> Option<&SimpleTextOutpu
fn initialize_boot_services(system_table: &SystemTable) -> Option<&BootServicesTable> { fn initialize_boot_services(system_table: &SystemTable) -> Option<&BootServicesTable> {
if !system_table.boot_services_table_pointer.is_null() { if !system_table.boot_services_table_pointer.is_null() {
unsafe { Some(&*system_table.boot_services_table_pointer)} unsafe { Some(&*system_table.boot_services_table_pointer) }
} else { } else {
None None
} }

View File

@ -0,0 +1,92 @@
use crate::structs::{Status, GUID};
use crate::types::char16;
#[repr(C)]
pub struct SimpleFileSystemProtocol {
pub revision: u64,
pub open_volume: OpenVolume,
}
impl SimpleFileSystemProtocol {
pub const GUID: GUID = GUID {
data1: 0x0964e5b22,
data2: 0x6459,
data3: 0x11d2,
data4: [0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b],
};
}
/// The OpenVolume() function opens a volume, and returns a file handle to the volumes root directory. This handle is used to perform all other file I/O operations. The volume remains open until all the file handles to it are closed. If the medium is changed while there are open file handles to the volume, all file handles to the volume will return EFI_MEDIA_CHANGED. To access the files on the new medium, the volume must be reopened with OpenVol- ume(). If the new medium is a different file system than the one supplied in the EFI_HANDLEs DevicePath for the EFI_SIMPLE_SYSTEM_PROTOCOL, OpenVolume() will return EFI_UNSUPPORTED.
/// # Arguments
/// * `this` - A pointer to the volume to open the root directory of.
/// * `root` - A pointer to the location to return the opened file handle for the root directory.
pub type OpenVolume =
extern "efiapi" fn(this: *mut SimpleFileSystemProtocol, root: *mut *mut FileProtocol) -> Status;
#[repr(u64)]
pub enum OpenMode {
FileModeRead = 0x0000000000000001,
FileModeWrite = 0x0000000000000002,
FileModeCreate = 0x8000000000000000,
}
#[repr(u64)]
pub enum FileAttribute {
FileReadOnly = 0x0000000000000001,
FileHidden = 0x0000000000000002,
FileSystem = 0x0000000000000004,
FileReserved = 0x0000000000000008,
FileDirectory = 0x0000000000000010,
FileArchive = 0x0000000000000020,
FileValidAttr = 0x0000000000000037,
}
#[repr(C)]
pub struct FileProtocol {
pub revision: u64,
pub open: FileOpen,
pub close: FileClose,
pub delete: FileDelete,
pub read: FileRead,
pub write: FileWrite,
pub get_position: FileGetPosition,
pub set_position: FileSetPosition,
pub get_info: FileGetInfo,
pub set_info: FileSetInfo,
pub flush: FileFlush,
pub open_ex: FileOpenEx,
pub read_ex: FileReadEx,
pub write_ex: FileWriteEx,
pub flush_ex: FileFlushEx,
}
/// The Open() function opens the file or directory referred to by FileName relative to the location of This and returns a NewHandle. The FileName may include the following path modifiers: “\” If the filename starts with a “\” the relative location is the root directory that This resides on; otherwise “" separates name components. Each name component is opened in turn, and the handle to the last file opened is returned. “.” Opens the current location. “..” Opens the parent directory for the current location. If the location is the root directory the request will return an error, as there is no parent directory for the root directory. If EFI_FILE_MODE_CREATE is set, then the file is created in the directory. If the final location of FileName does not refer to a directory, then the operation fails. If the file does not exist in the directory, then a new file is created. If the file already exists in the directory, then the existing file is opened. If the medium of the device changes, all accesses (including
/// # Arguments
/// * `This` - A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to the source location. This would typically be an open handle to a directory. See the type EFI_FILE_PROTOCOL description.
/// * `NewHandle` - A pointer to the location to return the opened handle for the new file.
/// * `FileName` - The Null-terminated string of the name of the file to be opened. The file name may contain the following path modifiers: “", “.”, and “..”.
/// * `OpenMode` - The mode to open the file. The only valid combinations that the file may be opened with are: Read, Read/Write, or Create/Read/Write. See “Related Definitions” below.
/// * `Attributes` - Only valid for EFI_FILE_MODE_CREATE, in which case these are the attribute bits for the newly created file. See “Related Definitions” below.
pub type FileOpen = extern "efiapi" fn(
this: *mut FileProtocol,
new_handle: *mut *mut FileProtocol,
file_name: *const char16,
open_mode: OpenMode,
attributes: FileAttribute,
) -> Status;
/// The Close() function closes a specified file handle. All “dirty” cached file data is flushed to the device, and the file is closed. In all cases the handle is closed. The operation will wait for all pending asynchronous I/O requests to complete before completing.
/// # Arguments
/// * `This` - A pointer to the EFI_FILE_PROTOCOL instance that is the file handle to close.
pub type FileClose = extern "efiapi" fn(this: &FileProtocol) -> Status;
pub type FileDelete = extern "efiapi" fn() -> Status;
pub type FileRead = extern "efiapi" fn() -> Status;
pub type FileWrite = extern "efiapi" fn() -> Status;
pub type FileGetPosition = extern "efiapi" fn() -> Status;
pub type FileSetPosition = extern "efiapi" fn() -> Status;
pub type FileGetInfo = extern "efiapi" fn() -> Status;
pub type FileSetInfo = extern "efiapi" fn() -> Status;
pub type FileFlush = extern "efiapi" fn() -> Status;
pub type FileOpenEx = extern "efiapi" fn() -> Status;
pub type FileReadEx = extern "efiapi" fn() -> Status;
pub type FileWriteEx = extern "efiapi" fn() -> Status;
pub type FileFlushEx = extern "efiapi" fn() -> Status;

View File

@ -1,17 +1,17 @@
use crate::structs::{Status, GUID}; use crate::structs::{Status, GUID};
use crate::types::Char16; use crate::types::char16;
#[repr(C)] #[repr(C)]
pub struct SimpleTextOutputProtocol { pub struct SimpleTextOutputProtocol {
pub reset: text_reset, pub reset: TextReset,
pub output_string: text_string, pub output_string: TextString,
pub test_string: text_test_string, pub test_string: TextTestString,
pub query_mode: text_query_mode, pub query_mode: TextQueryMode,
pub set_mode: text_set_mode, pub set_mode: TextSetMode,
pub set_attribute: text_set_attribute, pub set_attribute: TextSetAttribute,
pub clear_screen: text_clear_screen, pub clear_screen: TextClearScreen,
pub set_cursor_position: text_set_cursor_position, pub set_cursor_position: TextSetCursorPosition,
pub enable_cursor: text_enable_cursor, pub enable_cursor: TextEnableCursor,
pub mode: *mut SimpleTextOutputMode, pub mode: *mut SimpleTextOutputMode,
} }
@ -22,29 +22,28 @@ impl SimpleTextOutputProtocol {
data3: 0x11d2, data3: 0x11d2,
data4: [0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b], data4: [0x8e, 0x39, 0x00, 0xa0, 0xc9, 0x69, 0x72, 0x3b],
}; };
} }
pub type text_reset = pub type TextReset =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, extended_verification: bool) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, extended_verification: bool) -> Status;
pub type text_string = pub type TextString =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, string: *const Char16) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, string: *const char16) -> Status;
pub type text_test_string = pub type TextTestString =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, string: *const Char16) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, string: *const char16) -> Status;
pub type text_query_mode = extern "efiapi" fn( pub type TextQueryMode = extern "efiapi" fn(
this: &SimpleTextOutputProtocol, this: &SimpleTextOutputProtocol,
mode_number: usize, mode_number: usize,
column: &mut usize, column: &mut usize,
rows: &mut usize, rows: &mut usize,
) -> Status; ) -> Status;
pub type text_set_mode = pub type TextSetMode =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, mode_number: usize) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, mode_number: usize) -> Status;
pub type text_set_attribute = pub type TextSetAttribute =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, Attribute: usize) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, Attribute: usize) -> Status;
pub type text_clear_screen = extern "efiapi" fn(this: &SimpleTextOutputProtocol) -> Status; pub type TextClearScreen = extern "efiapi" fn(this: &SimpleTextOutputProtocol) -> Status;
pub type text_set_cursor_position = pub type TextSetCursorPosition =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, column: usize, row: usize) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, column: usize, row: usize) -> Status;
pub type text_enable_cursor = pub type TextEnableCursor =
extern "efiapi" fn(this: &SimpleTextOutputProtocol, visible: bool) -> Status; extern "efiapi" fn(this: &SimpleTextOutputProtocol, visible: bool) -> Status;
#[repr(C)] #[repr(C)]

View File

@ -1,11 +1,6 @@
#[repr(C)] #[repr(C)]
pub struct TableSignatures; pub struct TableSignatures;
impl TableSignatures {
pub const SYSTEM_TABLE_SIGNATURE: u64 = 0x5453595320494249;
pub const BOOT_TABLE_SIGNATURE: u64 = 0x56524553544f4f42;
}
#[repr(C)] #[repr(C)]
pub struct RuntimeServicesTable { pub struct RuntimeServicesTable {
efi_table_header: TableHeader, efi_table_header: TableHeader,
@ -127,48 +122,6 @@ impl From<Status> for usize {
} }
} }
// #[repr(u64)]
// pub enum Status {
// Success,
// LoadError,
// InvalidParameter,
// Unsupported,
// BadBufferSize,
// BufferTooSmall,
// NotReady,
// DeviceError,
// WriteProtected,
// OutOfResources,
// VolumeCorrupted,
// VolumeFull,
// NoMedia,
// MediaChanged,
// NotFound,
// AccessDenied,
// NoResponce,
// NoMapping,
// Timeout,
// NotStarted,
// AlreadyStarted,
// Aborted,
// IcmpError,
// TftpError,
// ProtocolError,
// IncompatibleVersion,
// SecurityViolation,
// CrcError,
// EndOfMedia,
// EndOfFile,
// InvalidLanguage,
// CompromisedData,
// IpAddressConflict,
// HttpError,
// }
#[repr(C)]
pub struct TPL {}
#[repr(C)] #[repr(C)]
pub struct GUID { pub struct GUID {
pub data1: u32, pub data1: u32,
@ -176,12 +129,3 @@ pub struct GUID {
pub data3: u16, pub data3: u16,
pub data4: [u8; 8], pub data4: [u8; 8],
} }
#[repr(C)]
pub struct MemoryDescriptor {
pub type_: u32,
pub physical_start: u64,
pub virtual_start: u64,
pub number_of_pages: u64,
pub attribute: u64,
}

View File

@ -1,7 +1,7 @@
use crate::boot_services::BootServicesTable; use crate::boot_services::BootServicesTable;
use crate::simple_text_output::SimpleTextOutputProtocol;
use crate::structs::*; use crate::structs::*;
use crate::types::Handle; use crate::types::Handle;
use crate::simple_text_output::SimpleTextOutputProtocol;
#[repr(C)] #[repr(C)]
pub struct SystemTable { pub struct SystemTable {
@ -36,27 +36,30 @@ pub struct SystemTable {
// SALSystemTable: *mut SALSystemTable // SALSystemTable: *mut SALSystemTable
} }
impl SystemTable {
pub const SYSTEM_TABLE_SIGNATURE: u64 = 0x5453595320494249;
}
#[repr(C)] #[repr(C)]
pub struct ImageEntryPoint { pub struct ImageEntryPoint {
image_handle: *const i32, // The firmware allocated handle for the UEFI image. image_handle: *const i32, // The firmware allocated handle for the UEFI image.
system_table_pointer: *const i32, // A pointer to the EFI System Table. system_table_pointer: *const i32, // A pointer to the EFI System Table.
} }
#[repr(u32)] #[repr(u32)]
pub enum SystemTableRevisions { pub enum SystemTableRevisions {
EFI_2_100_SYSTEM_TABLE_REVISION = (2 << 16) | 100, EFI2_100SystemTableRevision = (2 << 16) | 100,
EFI_1_90_SYSTEM_TABLE_REVISION = ((2 << 16) | (90)), EFI1_90SystemTableRevision = ((2 << 16) | (90)),
EFI_1_80_SYSTEM_TABLE_REVISION = ((2 << 16) | (80)), EFI1_80SystemTableRevision = ((2 << 16) | (80)),
EFI_1_70_SYSTEM_TABLE_REVISION = ((2 << 16) | (70)), EFI1_70SystemTableRevision = ((2 << 16) | (70)),
EFI_1_60_SYSTEM_TABLE_REVISION = ((2 << 16) | (60)), EFI1_60SystemTableRevision = ((2 << 16) | (60)),
EFI_1_50_SYSTEM_TABLE_REVISION = ((2 << 16) | (50)), EFI1_50SystemTableRevision = ((2 << 16) | (50)),
EFI_1_40_SYSTEM_TABLE_REVISION = ((2 << 16) | (40)), EFI1_40SystemTableRevision = ((2 << 16) | (40)),
EFI_1_31_SYSTEM_TABLE_REVISION = ((2 << 16) | (31)), EFI1_31SystemTableRevision = ((2 << 16) | (31)),
EFI_1_30_SYSTEM_TABLE_REVISION = ((2 << 16) | (30)), EFI1_30SystemTableRevision = ((2 << 16) | (30)),
EFI_1_20_SYSTEM_TABLE_REVISION = ((2 << 16) | (20)), EFI1_20SystemTableRevision = ((2 << 16) | (20)),
EFI_1_10_SYSTEM_TABLE_REVISION = ((2 << 16) | (10)), EFI1_10SystemTableRevision = ((2 << 16) | (10)),
EFI_1_00_SYSTEM_TABLE_REVISION = ((2 << 16) | (00)), EFI1_00SystemTableRevision = ((2 << 16) | (00)),
EFI_0_10_SYSTEM_TABLE_REVISION = ((1 << 16) | (10)), EFI0_10SystemTableRevision = ((1 << 16) | (10)),
EFI_0_02_SYSTEM_TABLE_REVISION = ((1 << 16) | (02)), EFI0_02SystemTableRevision = ((1 << 16) | (02)),
} }

View File

@ -1,4 +1,3 @@
use core; use core;
pub type Handle = *mut core::ffi::c_void; pub type Handle = *mut core::ffi::c_void;
pub type PhysicalAddress = u64; pub type char16 = u16;
pub type Char16 = u16;