[BOOT] Huge refactor
This commit is contained in:
@@ -16,311 +16,16 @@ Abstract:
|
||||
#ifndef _BOOTMGR_H
|
||||
#define _BOOTMGR_H
|
||||
|
||||
#include <nt.h>
|
||||
#include "efi.h"
|
||||
|
||||
//
|
||||
// Set machine type.
|
||||
//
|
||||
#if defined(__x86_64__)
|
||||
#define BOOT_MACHINE_TYPE IMAGE_FILE_MACHINE_AMD64
|
||||
#elif defined(__i386__)
|
||||
#define BOOT_MACHINE_TYPE IMAGE_FILE_MACHINE_I386
|
||||
#endif
|
||||
|
||||
//
|
||||
// Use EFI page size.
|
||||
//
|
||||
#define PAGE_SIZE EFI_PAGE_SIZE
|
||||
#define PAGE_SHIFT EFI_PAGE_SHIFT
|
||||
|
||||
//
|
||||
// Address translation types.
|
||||
//
|
||||
#define BOOT_TRANSLATION_TYPE_NONE 0
|
||||
#define BOOT_TRANSLATION_TYPE_MAX 1
|
||||
|
||||
#define BOOT_INPUT_PARAMETERS_SIGNATURE 0x50504120544f4f42 /* "BOOT APP" */
|
||||
#define BOOT_INPUT_PARAMETERS_VERSION 2
|
||||
|
||||
typedef struct {
|
||||
ULONGLONG Signature;
|
||||
ULONG Version;
|
||||
ULONG Size;
|
||||
|
||||
//
|
||||
// Machine information.
|
||||
//
|
||||
ULONG MachineType;
|
||||
ULONG TranslationType;
|
||||
|
||||
//
|
||||
// Image information.
|
||||
//
|
||||
PVOID ImageBase;
|
||||
ULONG ImageSize;
|
||||
|
||||
//
|
||||
// Offsets to ancillary structures.
|
||||
//
|
||||
ULONG MemoryInfoOffset;
|
||||
ULONG ApplicationEntryOffset;
|
||||
ULONG BootDeviceOffset;
|
||||
ULONG FirmwareDataOffset;
|
||||
ULONG ReturnDataOffset;
|
||||
ULONG PlatformDataOffset;
|
||||
} BOOT_INPUT_PARAMETERS, *PBOOT_INPUT_PARAMETERS;
|
||||
|
||||
typedef struct {
|
||||
ULONG Type;
|
||||
ULONG DataOffset;
|
||||
ULONG DataSize;
|
||||
ULONG OtherOptionsOffset;
|
||||
ULONG NextOptionOffset;
|
||||
BOOLEAN IsInvalid;
|
||||
UCHAR Unknown[3];
|
||||
} BOOT_APPLICATION_OPTION, *PBOOT_APPLICATION_OPTION;
|
||||
|
||||
#define BOOT_INPUT_APPLICATION_ENTRY_SIGNATURE 0x544e4550415442 /* "BTAPENT" */
|
||||
|
||||
#define BOOT_INPUT_APPLICATION_ENTRY_NO_BCD_IDENTIFIER 0x01
|
||||
|
||||
typedef struct {
|
||||
ULONGLONG Signature;
|
||||
ULONG Attributes;
|
||||
GUID BcdIdentifier;
|
||||
UCHAR Unknown[16];
|
||||
BOOT_APPLICATION_OPTION Options;
|
||||
} BOOT_INPUT_APPLICATION_ENTRY, *PBOOT_INPUT_APPLICATION_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
ULONG Attributes;
|
||||
GUID BcdIdentifier;
|
||||
PBOOT_APPLICATION_OPTION Options;
|
||||
} BOOT_APPLICATION_ENTRY, *PBOOT_APPLICATION_ENTRY;
|
||||
|
||||
#define BOOT_MEMORY_INFO_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
ULONG Version;
|
||||
ULONG MdlOffset;
|
||||
ULONG DescriptorCount;
|
||||
ULONG DescriptorSize;
|
||||
ULONG FirstPageOffset;
|
||||
} BOOT_MEMORY_INFO, *PBOOT_MEMORY_INFO;
|
||||
|
||||
//
|
||||
// Memory descriptor caching attributes.
|
||||
//
|
||||
#define MEMORY_ATTRIBUTE_UC 0x0000000000000001
|
||||
#define MEMORY_ATTRIBUTE_WC 0x0000000000000002
|
||||
#define MEMORY_ATTRIBUTE_WT 0x0000000000000004
|
||||
#define MEMORY_ATTRIBUTE_WB 0x0000000000000008
|
||||
#define MEMORY_ATTRIBUTE_UCE 0x0000000000000010
|
||||
|
||||
//
|
||||
// Memory descriptor protection attributes.
|
||||
//
|
||||
#define MEMORY_ATTRIBUTE_WP 0x000000000000100
|
||||
#define MEMORY_ATTRIBUTE_RP 0x000000000000200
|
||||
#define MEMORY_ATTRIBUTE_XP 0x000000000000400
|
||||
|
||||
//
|
||||
// Memory descriptor location attributes.
|
||||
//
|
||||
#define MEMORY_ATTRIBUTE_BELOW_1MIB 0x80000
|
||||
|
||||
//
|
||||
// Memory descriptor runtime mapping attributes.
|
||||
//
|
||||
#define MEMORY_ATTRIBUTE_RUNTIME 0x1000000
|
||||
|
||||
#define MEMORY_CLASS_APPLICATION 0xD
|
||||
#define MEMORY_CLASS_LIBRARY 0xE
|
||||
#define MEMORY_CLASS_SYSTEM 0xF
|
||||
|
||||
#define MEMORY_TYPE_BOOT_APPLICATION 0xD0000002
|
||||
#define MEMORY_TYPE_BOOT_APPLICATION_2 0xD0000013
|
||||
#define MEMORY_TYPE_FREE 0xF0000001
|
||||
#define MEMORY_TYPE_UNUSABLE 0xF0000002
|
||||
#define MEMORY_TYPE_RESERVED 0xF0000003
|
||||
#define MEMORY_TYPE_BOOT_SERVICES 0xF0000004
|
||||
#define MEMORY_TYPE_FREE_ZEROED 0xF0000005
|
||||
#define MEMORY_TYPE_RUNTIME_SERVICES_CODE 0xF0000006
|
||||
#define MEMORY_TYPE_PERSISTENT 0xF0000007
|
||||
#define MEMORY_TYPE_ACPI_RECLAIM 0xF0000008
|
||||
#define MEMORY_TYPE_ACPI_NVS 0xF0000009
|
||||
#define MEMORY_TYPE_MMIO 0xF000000A
|
||||
#define MEMORY_TYPE_MMIO_PORT_SPACE 0xF000000B
|
||||
#define MEMORY_TYPE_PAL_CODE 0xF000000C
|
||||
#define MEMORY_TYPE_RUNTIME_SERVICES_DATA 0xF000000E
|
||||
|
||||
typedef ULONG MEMORY_TYPE;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY ListEntry;
|
||||
|
||||
ULONGLONG FirstPage;
|
||||
ULONGLONG MappedFirstPage;
|
||||
ULONG PageCount;
|
||||
|
||||
ULONG Attributes;
|
||||
MEMORY_TYPE Type;
|
||||
} MEMORY_DESCRIPTOR, *PMEMORY_DESCRIPTOR;
|
||||
|
||||
typedef enum {
|
||||
MDL_TYPE_PHYSICAL,
|
||||
MDL_TYPE_VIRTUAL
|
||||
} MEMORY_DESCRIPTOR_LIST_TYPE;
|
||||
|
||||
typedef struct {
|
||||
LIST_ENTRY ListEntry;
|
||||
|
||||
PLIST_ENTRY Head;
|
||||
PLIST_ENTRY Current;
|
||||
MEMORY_DESCRIPTOR_LIST_TYPE Type;
|
||||
} MEMORY_DESCRIPTOR_LIST, *PMEMORY_DESCRIPTOR_LIST;
|
||||
|
||||
#define BOOT_FIRMWARE_DATA_VERSION 2
|
||||
|
||||
typedef struct {
|
||||
ULONG Version;
|
||||
ULONG Reserved;
|
||||
EFI_HANDLE ImageHandle;
|
||||
EFI_SYSTEM_TABLE *SystemTable;
|
||||
} BOOT_FIRMWARE_DATA, *PBOOT_FIRMWARE_DATA;
|
||||
|
||||
#define BOOT_RETURN_DATA_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
ULONG Version;
|
||||
NTSTATUS Status;
|
||||
ULONG Flags;
|
||||
} BOOT_RETURN_DATA, *PBOOT_RETURN_DATA;
|
||||
|
||||
typedef struct {
|
||||
LARGE_INTEGER ImageBase;
|
||||
ULONG ImageSize;
|
||||
ULONG ImageOffset;
|
||||
} BOOT_RAMDISK_IDENTIFIER, *PBOOT_RAMDISK_IDENTIFIER;
|
||||
|
||||
#define BOOT_HARDDRIVE_PARTITION_TYPE_GPT 0x00
|
||||
#define BOOT_HARDDRIVE_PARTITION_TYPE_MBR 0x01
|
||||
#define BOOT_HARDDRIVE_PARTITION_TYPE_RAW 0x02
|
||||
|
||||
typedef struct {
|
||||
ULONG PartitionType;
|
||||
|
||||
union {
|
||||
struct {
|
||||
ULONG Signature;
|
||||
} Mbr;
|
||||
|
||||
struct {
|
||||
GUID Signature;
|
||||
} Gpt;
|
||||
|
||||
struct {
|
||||
ULONG DriveNumber;
|
||||
} Raw;
|
||||
};
|
||||
} BOOT_HARDDRIVE_IDENTIFIER, *PBOOT_HARDDRIVE_IDENTIFIER;
|
||||
|
||||
typedef struct {
|
||||
ULONG DriveNumber;
|
||||
} BOOT_CDROM_IDENTIFIER, *PBOOT_CDROM_IDENTIFIER;
|
||||
|
||||
#define BOOT_BLOCK_DEVICE_TYPE_HARDDRIVE 0x00
|
||||
#define BOOT_BLOCK_DEVICE_TYPE_CDROM 0x02
|
||||
#define BOOT_BLOCK_DEVICE_TYPE_RAMDISK 0x03
|
||||
|
||||
typedef struct {
|
||||
ULONG Type;
|
||||
|
||||
union {
|
||||
BOOT_RAMDISK_IDENTIFIER Ramdisk;
|
||||
BOOT_HARDDRIVE_IDENTIFIER Harddrive;
|
||||
BOOT_CDROM_IDENTIFIER Cdrom;
|
||||
};
|
||||
} BOOT_BLOCK_IDENTIFIER, *PBOOT_BLOCK_IDENTIFIER;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
ULONG PartitionNumber;
|
||||
} Mbr;
|
||||
|
||||
struct {
|
||||
GUID PartitionIdentifier;
|
||||
} Gpt;
|
||||
|
||||
struct {
|
||||
ULONG BootEntry;
|
||||
} ElTorito;
|
||||
};
|
||||
|
||||
BOOT_BLOCK_IDENTIFIER Parent;
|
||||
} BOOT_PARTITION_IDENTIFIER, *PBOOT_PARTITION_IDENTIFIER;
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
struct {
|
||||
PVOID PartitionOffset;
|
||||
} Mbr;
|
||||
|
||||
struct {
|
||||
GUID PartitionIdentifier;
|
||||
} Gpt;
|
||||
|
||||
struct {
|
||||
ULONG BootEntry;
|
||||
} ElTorito;
|
||||
};
|
||||
|
||||
BOOT_BLOCK_IDENTIFIER Parent;
|
||||
} BOOT_PARTITION_IDENTIFIER_EX, *PBOOT_PARTITION_IDENTIFIER_EX;
|
||||
|
||||
#define BOOT_DEVICE_TYPE_BLOCK 0x00
|
||||
#define BOOT_DEVICE_TYPE_PARTITION 0x02
|
||||
#define BOOT_DEVICE_TYPE_PARTITION_EX 0x06
|
||||
|
||||
#define BOOT_DEVICE_ATTRIBUTE_NO_PARENT_SIGNATURE 0x04
|
||||
|
||||
typedef struct {
|
||||
ULONG Type;
|
||||
ULONG Attributes;
|
||||
ULONG Size;
|
||||
ULONG Pad;
|
||||
|
||||
union {
|
||||
BOOT_BLOCK_IDENTIFIER Block;
|
||||
BOOT_PARTITION_IDENTIFIER Partition;
|
||||
BOOT_PARTITION_IDENTIFIER_EX PartitionEx;
|
||||
};
|
||||
} BOOT_DEVICE, *PBOOT_DEVICE;
|
||||
|
||||
#define BCDE_DATA_FORMAT_MASK 0x0F000000
|
||||
|
||||
#define BCDE_DATA_FORMAT_DEVICE 1
|
||||
|
||||
typedef enum {
|
||||
BCDE_DATA_TYPE_APPLICATION_DEVICE = 0x11000001,
|
||||
BCDE_DATA_TYPE_APPLICATION_PATH = 0x22000002
|
||||
} BCDE_DATA_TYPE;
|
||||
|
||||
typedef struct {
|
||||
GUID OtherOptions;
|
||||
BOOT_DEVICE Device;
|
||||
} BCDE_DEVICE, *PBCDE_DEVICE;
|
||||
#include "bootlib.h"
|
||||
|
||||
NTSTATUS
|
||||
BmOpenDataStore (
|
||||
IN OUT PHANDLE DataStore
|
||||
IN OUT PHANDLE Handle
|
||||
);
|
||||
|
||||
NTSTATUS
|
||||
BmMain (
|
||||
IN PBOOT_INPUT_PARAMETERS InputParameters
|
||||
IN PBOOT_APPLICATION_PARAMETERS ApplicationParameters
|
||||
);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user