mirror of
https://github.com/systemd/systemd.git
synced 2025-01-25 10:04:04 +03:00
stub: various modernizations to linux.c
Let's make some stuff const. Most importanly call AllocatePages() with a pointer to an EFI_PHYSICAL_ADDRESS instead of a pointer to a pointer. On 64bit this makes no difference, but on i386 this is simply not correct, since EFI_PHYSICAL_ADDRESS is 64bit there, even though pointers are 32bit.
This commit is contained in:
parent
a0a644be70
commit
0d43ce5266
@ -13,6 +13,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef VOID(*handover_f)(VOID *image, EFI_SYSTEM_TABLE *table, struct boot_params *params) __regparm0__;
|
typedef VOID(*handover_f)(VOID *image, EFI_SYSTEM_TABLE *table, struct boot_params *params) __regparm0__;
|
||||||
|
|
||||||
static VOID linux_efi_handover(EFI_HANDLE image, struct boot_params *params) {
|
static VOID linux_efi_handover(EFI_HANDLE image, struct boot_params *params) {
|
||||||
handover_f handover;
|
handover_f handover;
|
||||||
UINTN start = (UINTN)params->hdr.code32_start;
|
UINTN start = (UINTN)params->hdr.code32_start;
|
||||||
@ -31,16 +32,17 @@ EFI_STATUS linux_exec(EFI_HANDLE image,
|
|||||||
CHAR8 *cmdline, UINTN cmdline_len,
|
CHAR8 *cmdline, UINTN cmdline_len,
|
||||||
UINTN linux_addr,
|
UINTN linux_addr,
|
||||||
UINTN initrd_addr, UINTN initrd_size) {
|
UINTN initrd_addr, UINTN initrd_size) {
|
||||||
struct boot_params *image_params;
|
|
||||||
|
const struct boot_params *image_params;
|
||||||
struct boot_params *boot_params;
|
struct boot_params *boot_params;
|
||||||
UINT8 setup_sectors;
|
|
||||||
EFI_PHYSICAL_ADDRESS addr;
|
EFI_PHYSICAL_ADDRESS addr;
|
||||||
|
UINT8 setup_sectors;
|
||||||
EFI_STATUS err;
|
EFI_STATUS err;
|
||||||
|
|
||||||
assert(image);
|
assert(image);
|
||||||
assert(cmdline);
|
assert(cmdline);
|
||||||
|
|
||||||
image_params = (struct boot_params *) linux_addr;
|
image_params = (const struct boot_params *) linux_addr;
|
||||||
|
|
||||||
if (image_params->hdr.boot_flag != 0xAA55 ||
|
if (image_params->hdr.boot_flag != 0xAA55 ||
|
||||||
image_params->hdr.header != SETUP_MAGIC ||
|
image_params->hdr.header != SETUP_MAGIC ||
|
||||||
@ -48,22 +50,32 @@ EFI_STATUS linux_exec(EFI_HANDLE image,
|
|||||||
!image_params->hdr.relocatable_kernel)
|
!image_params->hdr.relocatable_kernel)
|
||||||
return EFI_LOAD_ERROR;
|
return EFI_LOAD_ERROR;
|
||||||
|
|
||||||
boot_params = (struct boot_params *) 0xFFFFFFFF;
|
addr = UINT32_MAX; /* Below the 32bit boundary */
|
||||||
err = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, EfiLoaderData,
|
err = uefi_call_wrapper(
|
||||||
EFI_SIZE_TO_PAGES(0x4000), (EFI_PHYSICAL_ADDRESS*) &boot_params);
|
BS->AllocatePages, 4,
|
||||||
|
AllocateMaxAddress,
|
||||||
|
EfiLoaderData,
|
||||||
|
EFI_SIZE_TO_PAGES(0x4000),
|
||||||
|
&addr);
|
||||||
if (EFI_ERROR(err))
|
if (EFI_ERROR(err))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
boot_params = (struct boot_params *) PHYSICAL_ADDRESS_TO_POINTER(addr);
|
||||||
ZeroMem(boot_params, 0x4000);
|
ZeroMem(boot_params, 0x4000);
|
||||||
CopyMem(&boot_params->hdr, &image_params->hdr, sizeof(struct setup_header));
|
boot_params->hdr = image_params->hdr;
|
||||||
boot_params->hdr.type_of_loader = 0xff;
|
boot_params->hdr.type_of_loader = 0xff;
|
||||||
setup_sectors = image_params->hdr.setup_sects > 0 ? image_params->hdr.setup_sects : 4;
|
setup_sectors = image_params->hdr.setup_sects > 0 ? image_params->hdr.setup_sects : 4;
|
||||||
boot_params->hdr.code32_start = (UINT32)linux_addr + (setup_sectors + 1) * 512;
|
boot_params->hdr.code32_start = (UINT32)linux_addr + (setup_sectors + 1) * 512;
|
||||||
|
|
||||||
if (cmdline) {
|
if (cmdline) {
|
||||||
addr = 0xA0000;
|
addr = 0xA0000;
|
||||||
err = uefi_call_wrapper(BS->AllocatePages, 4, AllocateMaxAddress, EfiLoaderData,
|
|
||||||
EFI_SIZE_TO_PAGES(cmdline_len + 1), &addr);
|
err = uefi_call_wrapper(
|
||||||
|
BS->AllocatePages, 4,
|
||||||
|
AllocateMaxAddress,
|
||||||
|
EfiLoaderData,
|
||||||
|
EFI_SIZE_TO_PAGES(cmdline_len + 1),
|
||||||
|
&addr);
|
||||||
if (EFI_ERROR(err))
|
if (EFI_ERROR(err))
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
@ -72,8 +84,8 @@ EFI_STATUS linux_exec(EFI_HANDLE image,
|
|||||||
boot_params->hdr.cmd_line_ptr = (UINT32) addr;
|
boot_params->hdr.cmd_line_ptr = (UINT32) addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_params->hdr.ramdisk_image = (UINT32)initrd_addr;
|
boot_params->hdr.ramdisk_image = (UINT32) initrd_addr;
|
||||||
boot_params->hdr.ramdisk_size = (UINT32)initrd_size;
|
boot_params->hdr.ramdisk_size = (UINT32) initrd_size;
|
||||||
|
|
||||||
linux_efi_handover(image, boot_params);
|
linux_efi_handover(image, boot_params);
|
||||||
return EFI_LOAD_ERROR;
|
return EFI_LOAD_ERROR;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user