rm efipath

This commit is contained in:
a1ive 2025-02-11 11:23:41 +09:00
parent 4512426e9a
commit 77ac605bda
No known key found for this signature in database
GPG Key ID: DA9BACF4F462B55D
10 changed files with 117 additions and 335 deletions

View File

@ -8,7 +8,7 @@ SBAT_GENERATION := 1
#
OBJECTS := prefix.o startup.o callback.o main.o vsprintf.o string.o peloader.o
OBJECTS += int13.o vdisk.o cpio.o stdio.o die.o efi.o efimain.o
OBJECTS += efiguid.o efifile.o efipath.o efiboot.o efiblock.o cmdline.o
OBJECTS += efifile.o efiboot.o efiblock.o cmdline.o
OBJECTS += cookie.o paging.o memmap.o
OBJECTS += reg.o charset.o bcd.o fsuuid.o gpt.o msdos.o
OBJECTS += biosdisk.o efidisk.o payload.o

View File

@ -30,7 +30,6 @@
#include "ntloader.h"
#include "vdisk.h"
#include "efi.h"
#include "efipath.h"
#include "efiblock.h"
/** A block I/O device */
@ -131,53 +130,60 @@ efi_flush_blocks (EFI_BLOCK_IO_PROTOCOL *this)
}
/** GUID used in vendor device path */
#define EFIBLOCK_GUID { \
0x1322d197, 0x15dc, 0x4a45, \
{ 0xa6, 0xa4, 0xfa, 0x57, 0x05, 0x4e, 0xa6, 0x14 } \
}
#define EFIBLOCK_GUID \
{ \
0x1322d197, 0x15dc, 0x4a45, \
{ 0xa6, 0xa4, 0xfa, 0x57, 0x05, 0x4e, 0xa6, 0x14 } \
}
/**
* Initialise vendor device path
*
* @v name Variable name
*/
#define EFIBLOCK_DEVPATH_VENDOR_INIT(name) { \
.Header = EFI_DEVPATH_INIT (name, HARDWARE_DEVICE_PATH, \
HW_VENDOR_DP), \
.Guid = EFIBLOCK_GUID, \
}
#define EFIBLOCK_DEVPATH_VENDOR_INIT(name) \
{ \
.Header = EFI_DEVPATH_INIT (name, \
HARDWARE_DEVICE_PATH, \
HW_VENDOR_DP), \
.Guid = EFIBLOCK_GUID, \
}
/**
* Initialise ATA device path
*
* @v name Variable name
*/
#define EFIBLOCK_DEVPATH_ATA_INIT(name) { \
.Header = EFI_DEVPATH_INIT (name, MESSAGING_DEVICE_PATH, \
MSG_ATAPI_DP), \
.PrimarySecondary = 0, \
.SlaveMaster = 0, \
.Lun = 0, \
}
#define EFIBLOCK_DEVPATH_ATA_INIT(name) \
{ \
.Header = EFI_DEVPATH_INIT (name, \
MESSAGING_DEVICE_PATH, \
MSG_ATAPI_DP), \
.PrimarySecondary = 0, \
.SlaveMaster = 0, \
.Lun = 0, \
}
/**
* Initialise hard disk device path
*
* @v name Variable name
*/
#define EFIBLOCK_DEVPATH_HD_INIT(name) { \
.Header = EFI_DEVPATH_INIT (name, MEDIA_DEVICE_PATH, \
MEDIA_HARDDRIVE_DP), \
.PartitionNumber = 1, \
.PartitionStart = VDISK_PARTITION_LBA, \
.PartitionSize = VDISK_PARTITION_COUNT, \
.Signature[0] = ((VDISK_MBR_SIGNATURE >> 0) & 0xff), \
.Signature[1] = ((VDISK_MBR_SIGNATURE >> 8) & 0xff), \
.Signature[2] = ((VDISK_MBR_SIGNATURE >> 16) & 0xff), \
.Signature[3] = ((VDISK_MBR_SIGNATURE >> 24) & 0xff), \
.MBRType = MBR_TYPE_PCAT, \
.SignatureType = SIGNATURE_TYPE_MBR, \
}
#define EFIBLOCK_DEVPATH_HD_INIT(name) \
{ \
.Header = EFI_DEVPATH_INIT (name, \
MEDIA_DEVICE_PATH, \
MEDIA_HARDDRIVE_DP), \
.PartitionNumber = 1, \
.PartitionStart = VDISK_PARTITION_LBA, \
.PartitionSize = VDISK_PARTITION_COUNT, \
.Signature[0] = ((VDISK_MBR_SIGNATURE >> 0) & 0xff), \
.Signature[1] = ((VDISK_MBR_SIGNATURE >> 8) & 0xff), \
.Signature[2] = ((VDISK_MBR_SIGNATURE >> 16) & 0xff), \
.Signature[3] = ((VDISK_MBR_SIGNATURE >> 24) & 0xff), \
.MBRType = MBR_TYPE_PCAT, \
.SignatureType = SIGNATURE_TYPE_MBR, \
}
/** Virtual disk media */
static EFI_BLOCK_IO_MEDIA efi_vdisk_media =
@ -206,7 +212,8 @@ static struct
/** Virtual disk device */
static struct efi_block efi_vdisk =
{
.block = {
.block =
{
.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION,
.Media = &efi_vdisk_media,
.Reset = efi_reset_blocks,
@ -248,7 +255,8 @@ static struct
/** Virtual partition device */
static struct efi_block efi_vpartition =
{
.block = {
.block =
{
.Revision = EFI_BLOCK_IO_PROTOCOL_REVISION,
.Media = &efi_vpartition_media,
.Reset = efi_reset_blocks,
@ -286,8 +294,10 @@ void efi_install (EFI_HANDLE *vdisk, EFI_HANDLE *vpartition)
/* Install virtual partition */
if ((efirc = bs->InstallMultipleProtocolInterfaces (
vpartition,
&efi_block_io_protocol_guid, &efi_vpartition.block,
&efi_device_path_protocol_guid, efi_vpartition.path,
&efi_block_io_protocol_guid,
&efi_vpartition.block,
&efi_device_path_protocol_guid,
efi_vpartition.path,
NULL)) != 0)
{
die ("Could not install partition block I/O protocols: %#lx\n",
@ -313,7 +323,8 @@ static struct
.vendor = EFIBLOCK_DEVPATH_VENDOR_INIT (efi_bootmgfw_path.vendor),
.ata = EFIBLOCK_DEVPATH_ATA_INIT (efi_bootmgfw_path.ata),
.hd = EFIBLOCK_DEVPATH_HD_INIT (efi_bootmgfw_path.hd),
.file = {
.file =
{
.header = EFI_DEVPATH_INIT (efi_bootmgfw_path.file,
MEDIA_DEVICE_PATH,
MEDIA_FILEPATH_DP),
@ -323,4 +334,5 @@ static struct
};
/** Boot image path */
EFI_DEVICE_PATH_PROTOCOL *bootmgfw_path = &efi_bootmgfw_path.vendor.Header;
EFI_DEVICE_PATH_PROTOCOL *bootmgfw_path =
&efi_bootmgfw_path.vendor.Header;

View File

@ -30,72 +30,8 @@
#include "cmdline.h"
#include "vdisk.h"
#include "efi.h"
#include "efi/Protocol/GraphicsOutput.h"
#include "efipath.h"
#include "efiboot.h"
#if 0
/** Original OpenProtocol() method */
static EFI_OPEN_PROTOCOL orig_open_protocol;
/** Dummy "opening graphics output protocol blocked once" protocol GUID */
static EFI_GUID efi_graphics_output_protocol_blocked_guid =
{
0xbd1598bf, 0x8e65, 0x47e0,
{ 0x80, 0x01, 0xe4, 0x62, 0x4c, 0xab, 0xa4, 0x7f }
};
/** Dummy "opening graphics output protocol blocked once" protocol instance */
static uint8_t efi_graphics_output_protocol_blocked;
/**
* Intercept OpenProtocol()
*
* @v handle EFI handle
* @v protocol Protocol GUID
* @v interface Opened interface
* @v agent_handle Agent handle
* @v controller_handle Controller handle
* @v attributes Attributes
* @ret efirc EFI status code
*/
static EFI_STATUS EFIAPI
efi_open_protocol_wrapper (EFI_HANDLE handle, EFI_GUID *protocol,
VOID **interface, EFI_HANDLE agent_handle,
EFI_HANDLE controller_handle, UINT32 attributes)
{
EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
EFI_STATUS efirc;
/* Open the protocol */
if ((efirc = orig_open_protocol (handle, protocol, interface,
agent_handle, controller_handle,
attributes)) != 0)
return efirc;
/* Block first attempt by bootmgfw.efi to open each
* EFI_GRAPHICS_OUTPUT_PROTOCOL. This forces error messages
* to be displayed in text mode (thereby avoiding the totally
* blank error screen if the fonts are missing). We must
* allow subsequent attempts to succeed, otherwise the OS will
* fail to boot.
*/
if ((memcmp (protocol, &efi_graphics_output_protocol_guid,
sizeof (*protocol)) == 0) &&
(bs->InstallMultipleProtocolInterfaces (
&handle,
&efi_graphics_output_protocol_blocked_guid,
&efi_graphics_output_protocol_blocked,
NULL) == 0))
{
DBG ("Forcing text mode output\n");
return EFI_INVALID_PARAMETER;
}
return 0;
}
#endif
/**
* Boot from EFI device
*
@ -119,12 +55,13 @@ void efi_boot (EFI_DEVICE_PATH_PROTOCOL *path,
/* Allocate memory */
pages = ((nt_cmdline->bootmgr_length + PAGE_SIZE - 1) / PAGE_SIZE);
if ((efirc = bs->AllocatePages (AllocateAnyPages,
EfiBootServicesData, pages,
&phys)) != 0)
efirc = bs->AllocatePages (AllocateAnyPages,
EfiBootServicesData, pages,
&phys);
if (efirc != 0)
{
die ("Could not allocate %d pages: %#lx\n",
pages, ((unsigned long) efirc));
pages, ((unsigned long) efirc));
}
data = ((void *) (intptr_t) phys);
@ -133,8 +70,9 @@ void efi_boot (EFI_DEVICE_PATH_PROTOCOL *path,
memcpy (data, nt_cmdline->bootmgr, nt_cmdline->bootmgr_length);
/* Load image */
if ((efirc = bs->LoadImage (FALSE, efi_image_handle, path, data,
nt_cmdline->bootmgr_length, &handle)) != 0)
efirc = bs->LoadImage (FALSE, efi_image_handle, path, data,
nt_cmdline->bootmgr_length, &handle);
if (efirc != 0)
{
die ("Could not load bootmgfw.efi: %#lx\n",
((unsigned long) efirc));
@ -142,12 +80,13 @@ void efi_boot (EFI_DEVICE_PATH_PROTOCOL *path,
DBG ("Loaded bootmgfw.efi\n");
/* Get loaded image protocol */
if ((efirc = bs->OpenProtocol (handle,
&efi_loaded_image_protocol_guid,
&loaded.intf, efi_image_handle, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL))!=0)
efirc = bs->OpenProtocol (handle,
&efi_loaded_image_protocol_guid,
&loaded.intf, efi_image_handle, NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL);
if (efirc != 0)
{
die ("Could not get loaded image protocol for bootmgfw.efi: %#lx\n",
die ("Could not get loaded image protocol: %#lx\n",
((unsigned long) efirc));
}
@ -155,18 +94,10 @@ void efi_boot (EFI_DEVICE_PATH_PROTOCOL *path,
if (loaded.image->DeviceHandle != device)
{
DBG ("Forcing correct DeviceHandle (%p->%p)\n",
loaded.image->DeviceHandle, device);
loaded.image->DeviceHandle, device);
loaded.image->DeviceHandle = device;
}
#if 0
/* Intercept calls to OpenProtocol() */
orig_open_protocol =
loaded.image->SystemTable->BootServices->OpenProtocol;
loaded.image->SystemTable->BootServices->OpenProtocol =
efi_open_protocol_wrapper;
#endif
/* Start image */
if ((efirc = bs->StartImage (handle, NULL, NULL)) != 0)
{

View File

@ -34,7 +34,6 @@
#include "payload.h"
#include "efi.h"
#include "efifile.h"
#include "efipath.h"
#include "efi/Protocol/LoadFile2.h"
#include "efi/Guid/LinuxEfiInitrdMedia.h"

View File

@ -1,58 +0,0 @@
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* EFI GUIDs
*
*/
#include "ntloader.h"
#include "efi.h"
#include "efi/Protocol/BlockIo.h"
#include "efi/Protocol/DevicePath.h"
#include "efi/Protocol/GraphicsOutput.h"
#include "efi/Protocol/LoadedImage.h"
#include "efi/Protocol/SimpleFileSystem.h"
#include "efi/Protocol/LoadFile2.h"
/** Block I/O protocol GUID */
EFI_GUID efi_block_io_protocol_guid
= EFI_BLOCK_IO_PROTOCOL_GUID;
/** Device path protocol GUID */
EFI_GUID efi_device_path_protocol_guid
= EFI_DEVICE_PATH_PROTOCOL_GUID;
/** Graphics output protocol GUID */
EFI_GUID efi_graphics_output_protocol_guid
= EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
/** Loaded image protocol GUID */
EFI_GUID efi_loaded_image_protocol_guid
= EFI_LOADED_IMAGE_PROTOCOL_GUID;
/** Simple file system protocol GUID */
EFI_GUID efi_simple_file_system_protocol_guid
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
/** Load File 2 protocol GUID */
EFI_GUID efi_load_file2_protocol_guid
= EFI_LOAD_FILE2_PROTOCOL_GUID;

View File

@ -33,6 +33,11 @@
#include "efiboot.h"
#include "efidisk.h"
#include "bcd.h"
#include "efi/Protocol/BlockIo.h"
#include "efi/Protocol/DevicePath.h"
#include "efi/Protocol/LoadedImage.h"
#include "efi/Protocol/SimpleFileSystem.h"
#include "efi/Protocol/LoadFile2.h"
/** SBAT section attributes */
#define __sbat __attribute__ ((section (".sbat"), aligned (512)))
@ -55,6 +60,26 @@
/** SBAT metadata (with no terminating NUL) */
const char sbat[ sizeof (SBAT_CSV) - 1 ] __sbat = SBAT_CSV;
/** Block I/O protocol GUID */
EFI_GUID efi_block_io_protocol_guid
= EFI_BLOCK_IO_PROTOCOL_GUID;
/** Device path protocol GUID */
EFI_GUID efi_device_path_protocol_guid
= EFI_DEVICE_PATH_PROTOCOL_GUID;
/** Loaded image protocol GUID */
EFI_GUID efi_loaded_image_protocol_guid
= EFI_LOADED_IMAGE_PROTOCOL_GUID;
/** Simple file system protocol GUID */
EFI_GUID efi_simple_file_system_protocol_guid
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_GUID;
/** Load File 2 protocol GUID */
EFI_GUID efi_load_file2_protocol_guid
= EFI_LOAD_FILE2_PROTOCOL_GUID;
/**
* Process command line
*
@ -102,8 +127,7 @@ EFI_STATUS EFIAPI efi_main (EFI_HANDLE image_handle,
init_cookie();
/* Print welcome banner */
printf ("\n\nntloader " VERSION " -- Windows NT6+ OS/VHD/WIM "
"loader -- https://github.com/grub4dos/ntloader\n\n");
printf ("\n\nntloader " VERSION "\n\n");
/* Get loaded image protocol */
if ((efirc = bs->OpenProtocol (image_handle,

View File

@ -1,48 +0,0 @@
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* EFI device paths
*
*/
#include "ntloader.h"
#include "efi.h"
#include "efipath.h"
/**
* Find end of device path
*
* @v path Path to device
* @ret path_end End of device path
*/
EFI_DEVICE_PATH_PROTOCOL *efi_devpath_end (EFI_DEVICE_PATH_PROTOCOL *path)
{
while (path->Type != END_DEVICE_PATH_TYPE)
{
path = (((void *) path) +
/* There's this amazing new-fangled thing known as
* a UINT16, but who wants to use one of those? */
((path->Length[1] << 8) | path->Length[0]));
}
return path;
}

View File

@ -39,13 +39,38 @@
#include "efi/Uefi.h"
#include "efi/Protocol/LoadedImage.h"
#include "efi/Protocol/DevicePath.h"
/**
* Initialise device path
*
* @v name Variable name
* @v type Type
* @v subtype Subtype
*/
#define EFI_DEVPATH_INIT(name, type, subtype) \
{ \
.Type = (type), \
.SubType = (subtype), \
.Length[0] = (sizeof (name) & 0xff), \
.Length[1] = (sizeof (name) >> 8), \
}
/**
* Initialise device path end
*
* @v name Variable name
*/
#define EFI_DEVPATH_END_INIT(name) \
EFI_DEVPATH_INIT (name, \
END_DEVICE_PATH_TYPE, \
END_ENTIRE_DEVICE_PATH_SUBTYPE)
extern EFI_SYSTEM_TABLE *efi_systab;
extern EFI_HANDLE efi_image_handle;
extern EFI_GUID efi_block_io_protocol_guid;
extern EFI_GUID efi_device_path_protocol_guid;
extern EFI_GUID efi_graphics_output_protocol_guid;
extern EFI_GUID efi_loaded_image_protocol_guid;
extern EFI_GUID efi_simple_file_system_protocol_guid;
extern EFI_GUID efi_load_file2_protocol_guid;

View File

@ -1,90 +0,0 @@
#ifndef _EFIPATH_H
#define _EFIPATH_H
/*
* Copyright (C) 2014 Michael Brown <mbrown@fensystems.co.uk>.
*
* This program 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 2 of the
* License, or (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
/**
* @file
*
* EFI device paths
*
*/
#include "efi.h"
#include "efi/Protocol/DevicePath.h"
/**
* Initialise device path
*
* @v name Variable name
* @v type Type
* @v subtype Subtype
*/
#define EFI_DEVPATH_INIT(name, type, subtype) \
{ \
.Type = (type), \
.SubType = (subtype), \
.Length[0] = (sizeof (name) & 0xff), \
.Length[1] = (sizeof (name) >> 8), \
}
/**
* Initialise device path
*
* @v path Device path
* @v type Type
* @v subtype Subtype
* @v len Length
*/
static inline __attribute__ ((always_inline)) void
efi_devpath_init (EFI_DEVICE_PATH_PROTOCOL *path, unsigned int type,
unsigned int subtype, size_t len)
{
path->Type = type;
path->SubType = subtype;
path->Length[0] = (len & 0xff);
path->Length[1] = (len >> 8);
}
/**
* Initialise device path end
*
* @v name Variable name
*/
#define EFI_DEVPATH_END_INIT(name) \
EFI_DEVPATH_INIT (name, END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE)
/**
* Initialise device path end
*
* @v path Device path
*/
static inline __attribute__ ((always_inline)) void
efi_devpath_end_init (EFI_DEVICE_PATH_PROTOCOL *path)
{
efi_devpath_init (path, END_DEVICE_PATH_TYPE,
END_ENTIRE_DEVICE_PATH_SUBTYPE, sizeof (*path));
}
extern EFI_DEVICE_PATH_PROTOCOL *
efi_devpath_end (EFI_DEVICE_PATH_PROTOCOL *path);
#endif /* _EFIPATH_H */

15
main.c
View File

@ -97,18 +97,6 @@ static void call_interrupt_wrapper (struct bootapp_callback_params *params)
disable_paging (&state);
}
#if 0
else if ((params->vector.interrupt == 0x10) &&
(params->ax == 0x4f01))
{
/* Mark all VESA video modes as unsupported */
uint16_t *attributes = REAL_PTR (params->es, params->di);
call_interrupt (params);
*attributes &= ~0x0001;
}
#endif
else
{
@ -253,8 +241,7 @@ int main (void)
init_cookie();
/* Print welcome banner */
printf ("\n\nntloader " VERSION " -- Windows NT6+ OS/VHD/WIM "
"loader -- https://github.com/grub4dos/ntloader\n\n");
printf ("\n\nntloader " VERSION "\n\n");
/* Process command line */
process_cmdline (cmdline);