Start adding ABI types
This commit is contained in:
parent
c2f378c0ce
commit
15bb412b83
38
Cargo.lock
generated
38
Cargo.lock
generated
|
@ -24,16 +24,34 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
name = "freeloader"
|
name = "freeloader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"goblin",
|
||||||
"log",
|
"log",
|
||||||
"uefi",
|
"uefi",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "goblin"
|
||||||
|
version = "0.8.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1b363a30c165f666402fe6a3024d3bec7ebc898f96a4a23bd1c99f8dbf3f4f47"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
"plain",
|
||||||
|
"scroll",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "log"
|
name = "log"
|
||||||
version = "0.4.22"
|
version = "0.4.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "plain"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.86"
|
version = "1.0.86"
|
||||||
|
@ -72,6 +90,26 @@ dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scroll"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "6ab8598aa408498679922eff7fa985c25d58a90771bd6be794434c5277eab1a6"
|
||||||
|
dependencies = [
|
||||||
|
"scroll_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "scroll_derive"
|
||||||
|
version = "0.12.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f81c2fde025af7e69b1d1420531c8a8811ca898919db177141a85313b1cb932"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.72",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
|
|
@ -6,3 +6,4 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
uefi = { version = "0.29.0", default-features = false, features = [ "alloc", "global_allocator", "panic_handler", "logger" ] }
|
uefi = { version = "0.29.0", default-features = false, features = [ "alloc", "global_allocator", "panic_handler", "logger" ] }
|
||||||
log = { version = "0.4.22", default-features = false }
|
log = { version = "0.4.22", default-features = false }
|
||||||
|
goblin = { version = "0.8.2", default_features = false, features = [ "elf32", "elf64", "alloc" ] }
|
||||||
|
|
90
src/abi.rs
Normal file
90
src/abi.rs
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
use uefi::proto::console::gop::{GraphicsOutput, PixelFormat};
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct EFIFramebufferParams {
|
||||||
|
pub addr: u64,
|
||||||
|
pub size: u64,
|
||||||
|
pub height: u32,
|
||||||
|
pub width: u32,
|
||||||
|
pub stride: u32,
|
||||||
|
pub mask_red: u32,
|
||||||
|
pub mask_green: u32,
|
||||||
|
pub mask_blue: u32,
|
||||||
|
pub mask_reserved: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EFIFramebufferParams {
|
||||||
|
pub fn from_graphics_output(graphics_output: &mut GraphicsOutput) -> Option<Self> {
|
||||||
|
let mode = graphics_output.current_mode_info();
|
||||||
|
let (mask_red, mask_green, mask_blue, mask_reserved) = match mode.pixel_format() {
|
||||||
|
PixelFormat::Rgb => (0x0000_00ff, 0x0000_ff00, 0x00ff_0000, 0xff00_000),
|
||||||
|
PixelFormat::Bgr => (0x00ff_0000, 0x0000_ff00, 0x0000_00ff, 0xff00_000),
|
||||||
|
PixelFormat::Bitmask => {
|
||||||
|
let bitmask = mode.pixel_bitmask()?;
|
||||||
|
(bitmask.red, bitmask.green, bitmask.blue, bitmask.reserved)
|
||||||
|
}
|
||||||
|
_ => return None,
|
||||||
|
};
|
||||||
|
|
||||||
|
let (width, height) = mode.resolution();
|
||||||
|
|
||||||
|
let mut frame_buffer = graphics_output.frame_buffer();
|
||||||
|
let size = frame_buffer.size();
|
||||||
|
|
||||||
|
Some(Self {
|
||||||
|
addr: frame_buffer.as_mut_ptr() as u64,
|
||||||
|
size: size.try_into().ok()?,
|
||||||
|
height: height.try_into().ok()?,
|
||||||
|
width: width.try_into().ok()?,
|
||||||
|
stride: mode.stride().try_into().ok()?,
|
||||||
|
mask_red,
|
||||||
|
mask_green,
|
||||||
|
mask_blue,
|
||||||
|
mask_reserved,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(target_pointer_width = "64", repr(C, align(8)))]
|
||||||
|
#[cfg_attr(target_pointer_width = "32", repr(C, align(4)))]
|
||||||
|
pub struct ModuleDirectoryElem<T> {
|
||||||
|
ident: ModInfo,
|
||||||
|
size: u32,
|
||||||
|
data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct FileMetadataElem<T> {
|
||||||
|
size: usize,
|
||||||
|
typ: FileMetadataType,
|
||||||
|
addr: *const T,
|
||||||
|
next: Option<*const FileMetadataElem<T>>,
|
||||||
|
data: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(u32)]
|
||||||
|
pub enum ModInfo {
|
||||||
|
End = 0,
|
||||||
|
Name = 1,
|
||||||
|
Type = 2,
|
||||||
|
Addr = 3,
|
||||||
|
Size = 4,
|
||||||
|
Args = 6,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[repr(u16)]
|
||||||
|
pub enum FileMetadataType {
|
||||||
|
AoutExecHeader = 1,
|
||||||
|
ElfHeader = 2,
|
||||||
|
StartSymbols = 3,
|
||||||
|
EndSymbols = 4,
|
||||||
|
Dynamic = 5,
|
||||||
|
MB2Header = 6,
|
||||||
|
SectionHeader = 9,
|
||||||
|
CtorsAddress = 10,
|
||||||
|
CtorsSize = 11,
|
||||||
|
FirmwareHandle = 12,
|
||||||
|
KeyBuffer = 13,
|
||||||
|
Font = 14,
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
mod abi;
|
||||||
|
|
||||||
use log::info;
|
use log::info;
|
||||||
use uefi::prelude::*;
|
use uefi::prelude::*;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue