vaseboot/include/VasEBoot/efiemu/efiemu.h

287 lines
11 KiB
C

/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VAS_EBOOT_EFI_EMU_HEADER
#define VAS_EBOOT_EFI_EMU_HEADER 1
#include <VasEBoot/efi/api.h>
#include <VasEBoot/file.h>
#include <VasEBoot/memory.h>
#define VAS_EBOOT_EFIEMU_PAGESIZE 4096
/* EFI api defined in 32-bit and 64-bit version*/
struct VasEBoot_efi_system_table32
{
VasEBoot_efi_table_header_t hdr;
VasEBoot_efi_uint32_t firmware_vendor;
VasEBoot_efi_uint32_t firmware_revision;
VasEBoot_efi_uint32_t console_in_handler;
VasEBoot_efi_uint32_t con_in;
VasEBoot_efi_uint32_t console_out_handler;
VasEBoot_efi_uint32_t con_out;
VasEBoot_efi_uint32_t standard_error_handle;
VasEBoot_efi_uint32_t std_err;
VasEBoot_efi_uint32_t runtime_services;
VasEBoot_efi_uint32_t boot_services;
VasEBoot_efi_uint32_t num_table_entries;
VasEBoot_efi_uint32_t configuration_table;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efi_system_table32 VasEBoot_efi_system_table32_t;
struct VasEBoot_efi_system_table64
{
VasEBoot_efi_table_header_t hdr;
VasEBoot_efi_uint64_t firmware_vendor;
VasEBoot_efi_uint32_t firmware_revision;
VasEBoot_efi_uint32_t pad;
VasEBoot_efi_uint64_t console_in_handler;
VasEBoot_efi_uint64_t con_in;
VasEBoot_efi_uint64_t console_out_handler;
VasEBoot_efi_uint64_t con_out;
VasEBoot_efi_uint64_t standard_error_handle;
VasEBoot_efi_uint64_t std_err;
VasEBoot_efi_uint64_t runtime_services;
VasEBoot_efi_uint64_t boot_services;
VasEBoot_efi_uint64_t num_table_entries;
VasEBoot_efi_uint64_t configuration_table;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efi_system_table64 VasEBoot_efi_system_table64_t;
struct VasEBoot_efiemu_runtime_services32
{
VasEBoot_efi_table_header_t hdr;
VasEBoot_efi_uint32_t get_time;
VasEBoot_efi_uint32_t set_time;
VasEBoot_efi_uint32_t get_wakeup_time;
VasEBoot_efi_uint32_t set_wakeup_time;
VasEBoot_efi_uint32_t set_virtual_address_map;
VasEBoot_efi_uint32_t convert_pointer;
VasEBoot_efi_uint32_t get_variable;
VasEBoot_efi_uint32_t get_next_variable_name;
VasEBoot_efi_uint32_t set_variable;
VasEBoot_efi_uint32_t get_next_high_monotonic_count;
VasEBoot_efi_uint32_t reset_system;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efiemu_runtime_services32 VasEBoot_efiemu_runtime_services32_t;
struct VasEBoot_efiemu_runtime_services64
{
VasEBoot_efi_table_header_t hdr;
VasEBoot_efi_uint64_t get_time;
VasEBoot_efi_uint64_t set_time;
VasEBoot_efi_uint64_t get_wakeup_time;
VasEBoot_efi_uint64_t set_wakeup_time;
VasEBoot_efi_uint64_t set_virtual_address_map;
VasEBoot_efi_uint64_t convert_pointer;
VasEBoot_efi_uint64_t get_variable;
VasEBoot_efi_uint64_t get_next_variable_name;
VasEBoot_efi_uint64_t set_variable;
VasEBoot_efi_uint64_t get_next_high_monotonic_count;
VasEBoot_efi_uint64_t reset_system;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efiemu_runtime_services64 VasEBoot_efiemu_runtime_services64_t;
extern VasEBoot_efi_system_table32_t *VasEBoot_efiemu_system_table32;
extern VasEBoot_efi_system_table64_t *VasEBoot_efiemu_system_table64;
/* Convenience macros to access currently loaded efiemu */
#define VasEBoot_efiemu_system_table ((VasEBoot_efiemu_sizeof_uintn_t () == 8) \
? (void *) VasEBoot_efiemu_system_table64 \
: (void *) VasEBoot_efiemu_system_table32)
#define VAS_EBOOT_EFIEMU_SIZEOF_OF_UINTN (VasEBoot_efiemu_sizeof_uintn_t ())
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE(x) ((VasEBoot_efiemu_sizeof_uintn_t () == 8) \
? VasEBoot_efiemu_system_table64->x \
: VasEBoot_efiemu_system_table32->x)
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE_SET(x,y) ((VasEBoot_efiemu_sizeof_uintn_t () == 8)\
? (VasEBoot_efiemu_system_table64->x \
= (y)) \
: (VasEBoot_efiemu_system_table32->x \
= (y)))
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE_PTR(x) ((VasEBoot_efiemu_sizeof_uintn_t () == 8)\
? (void *) (VasEBoot_addr_t) \
(VasEBoot_efiemu_system_table64->x) \
: (void *) (VasEBoot_addr_t) \
(VasEBoot_efiemu_system_table32->x))
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE_VAR(x) ((VasEBoot_efiemu_sizeof_uintn_t () == 8) \
? (void *) \
&(VasEBoot_efiemu_system_table64->x) \
: (void *) \
&(VasEBoot_efiemu_system_table32->x))
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE_SIZEOF(x) \
((VasEBoot_efiemu_sizeof_uintn_t () == 8) \
? sizeof(VasEBoot_efiemu_system_table64->x)\
: sizeof(VasEBoot_efiemu_system_table32->x))
#define VAS_EBOOT_EFIEMU_SYSTEM_TABLE_SIZEOF_TOTAL ((VasEBoot_efiemu_sizeof_uintn_t () == 8) ? sizeof(*VasEBoot_efiemu_system_table64):sizeof(*VasEBoot_efiemu_system_table32))
/* ELF management definitions and functions */
struct VasEBoot_efiemu_segment
{
struct VasEBoot_efiemu_segment *next;
VasEBoot_size_t size;
unsigned section;
int handle;
int ptv_rel_needed;
VasEBoot_off_t off;
void *srcptr;
};
typedef struct VasEBoot_efiemu_segment *VasEBoot_efiemu_segment_t;
struct VasEBoot_efiemu_elf_sym
{
int handle;
VasEBoot_off_t off;
unsigned section;
};
int VasEBoot_efiemu_check_header32 (void *ehdr, VasEBoot_size_t size);
int VasEBoot_efiemu_check_header64 (void *ehdr, VasEBoot_size_t size);
VasEBoot_err_t VasEBoot_efiemu_loadcore_init32 (void *core,
const char *filename,
VasEBoot_size_t core_size,
VasEBoot_efiemu_segment_t *segments);
VasEBoot_err_t VasEBoot_efiemu_loadcore_init64 (void *core, const char *filename,
VasEBoot_size_t core_size,
VasEBoot_efiemu_segment_t *segments);
VasEBoot_err_t VasEBoot_efiemu_loadcore_load32 (void *core,
VasEBoot_size_t core_size,
VasEBoot_efiemu_segment_t segments);
VasEBoot_err_t VasEBoot_efiemu_loadcore_load64 (void *core,
VasEBoot_size_t core_size,
VasEBoot_efiemu_segment_t segments);
VasEBoot_err_t VasEBoot_efiemu_loadcore_unload32 (void);
VasEBoot_err_t VasEBoot_efiemu_loadcore_unload64 (void);
VasEBoot_err_t VasEBoot_efiemu_loadcore_unload(void);
VasEBoot_err_t VasEBoot_efiemu_loadcore_init (VasEBoot_file_t file,
const char *filename);
VasEBoot_err_t VasEBoot_efiemu_loadcore_load (void);
/* Configuration tables manipulation. Definitions and functions */
struct VasEBoot_efiemu_configuration_table
{
struct VasEBoot_efiemu_configuration_table *next;
VasEBoot_guid_t guid;
void * (*get_table) (void *data);
void (*unload) (void *data);
void *data;
};
struct VasEBoot_efiemu_configuration_table32
{
VasEBoot_packed_guid_t vendor_guid;
VasEBoot_efi_uint32_t vendor_table;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efiemu_configuration_table32 VasEBoot_efiemu_configuration_table32_t;
struct VasEBoot_efiemu_configuration_table64
{
VasEBoot_packed_guid_t vendor_guid;
VasEBoot_efi_uint64_t vendor_table;
} VAS_EBOOT_PACKED;
typedef struct VasEBoot_efiemu_configuration_table64 VasEBoot_efiemu_configuration_table64_t;
VasEBoot_err_t VasEBoot_efiemu_unregister_configuration_table (VasEBoot_guid_t guid);
VasEBoot_err_t
VasEBoot_efiemu_register_configuration_table (VasEBoot_guid_t guid,
void * (*get_table) (void *data),
void (*unload) (void *data),
void *data);
/* Memory management functions */
int VasEBoot_efiemu_request_memalign (VasEBoot_size_t align, VasEBoot_size_t size,
VasEBoot_efi_memory_type_t type);
void *VasEBoot_efiemu_mm_obtain_request (int handle);
VasEBoot_err_t VasEBoot_efiemu_mm_unload (void);
VasEBoot_err_t VasEBoot_efiemu_mm_do_alloc (void);
VasEBoot_err_t VasEBoot_efiemu_mm_init (void);
void VasEBoot_efiemu_mm_return_request (int handle);
VasEBoot_efi_memory_type_t VasEBoot_efiemu_mm_get_type (int handle);
/* Drop-in replacements for VasEBoot_efi_* and VasEBoot_machine_* */
int VasEBoot_efiemu_get_memory_map (VasEBoot_efi_uintn_t *memory_map_size,
VasEBoot_efi_memory_descriptor_t *memory_map,
VasEBoot_efi_uintn_t *map_key,
VasEBoot_efi_uintn_t *descriptor_size,
VasEBoot_efi_uint32_t *descriptor_version);
VasEBoot_err_t
VasEBoot_efiemu_finish_boot_services (VasEBoot_efi_uintn_t *memory_map_size,
VasEBoot_efi_memory_descriptor_t *memory_map,
VasEBoot_efi_uintn_t *map_key,
VasEBoot_efi_uintn_t *descriptor_size,
VasEBoot_efi_uint32_t *descriptor_version);
VasEBoot_err_t
VasEBoot_efiemu_mmap_iterate (VasEBoot_memory_hook_t hook, void *hook_data);
int VasEBoot_efiemu_sizeof_uintn_t (void);
VasEBoot_err_t
VasEBoot_efiemu_get_lower_upper_memory (VasEBoot_uint64_t *lower, VasEBoot_uint64_t *upper);
/* efiemu main control definitions and functions*/
typedef enum {VAS_EBOOT_EFIEMU_NOTLOADED,
VAS_EBOOT_EFIEMU32, VAS_EBOOT_EFIEMU64} VasEBoot_efiemu_mode_t;
struct VasEBoot_efiemu_prepare_hook
{
struct VasEBoot_efiemu_prepare_hook *next;
VasEBoot_err_t (*hook) (void *data);
void (*unload) (void *data);
void *data;
};
VasEBoot_err_t VasEBoot_efiemu_prepare32 (struct VasEBoot_efiemu_prepare_hook
*prepare_hooks,
struct VasEBoot_efiemu_configuration_table
*config_tables);
VasEBoot_err_t VasEBoot_efiemu_prepare64 (struct VasEBoot_efiemu_prepare_hook
*prepare_hooks,
struct VasEBoot_efiemu_configuration_table
*config_tables);
VasEBoot_err_t VasEBoot_efiemu_unload (void);
VasEBoot_err_t VasEBoot_efiemu_prepare (void);
VasEBoot_err_t
VasEBoot_efiemu_register_prepare_hook (VasEBoot_err_t (*hook) (void *data),
void (*unload) (void *data),
void *data);
/* symbols and pointers */
VasEBoot_err_t VasEBoot_efiemu_alloc_syms (void);
VasEBoot_err_t VasEBoot_efiemu_request_symbols (int num);
VasEBoot_err_t VasEBoot_efiemu_resolve_symbol (const char *name,
int *handle, VasEBoot_off_t *off);
VasEBoot_err_t VasEBoot_efiemu_register_symbol (const char *name,
int handle, VasEBoot_off_t off);
void VasEBoot_efiemu_free_syms (void);
VasEBoot_err_t VasEBoot_efiemu_write_value (void * addr, VasEBoot_uint32_t value,
int plus_handle,
int minus_handle, int ptv_needed, int size);
VasEBoot_err_t VasEBoot_efiemu_write_sym_markers (void);
VasEBoot_err_t VasEBoot_efiemu_pnvram (void);
const char *VasEBoot_efiemu_get_default_core_name (void);
void VasEBoot_efiemu_pnvram_cmd_unregister (void);
VasEBoot_err_t VasEBoot_efiemu_autocore (void);
VasEBoot_err_t VasEBoot_efiemu_crc32 (void);
VasEBoot_err_t VasEBoot_efiemu_crc64 (void);
VasEBoot_err_t
VasEBoot_efiemu_set_virtual_address_map (VasEBoot_efi_uintn_t memory_map_size,
VasEBoot_efi_uintn_t descriptor_size,
VasEBoot_efi_uint32_t descriptor_version
__attribute__ ((unused)),
VasEBoot_efi_memory_descriptor_t *virtual_map);
VasEBoot_err_t VasEBoot_machine_efiemu_init_tables (void);
#endif /* ! VAS_EBOOT_EFI_EMU_HEADER */