You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
x86/efi: Build our own EFI services pointer table
It's not possible to dereference the EFI System table directly when booting a 64-bit kernel on a 32-bit EFI firmware because the size of pointers don't match. In preparation for supporting the above use case, build a list of function pointers on boot so that callers don't have to worry about converting pointer sizes through multiple levels of indirection. Signed-off-by: Matt Fleming <matt.fleming@intel.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -103,4 +103,20 @@ struct efi_uga_draw_protocol {
|
||||
void *blt;
|
||||
};
|
||||
|
||||
struct efi_config {
|
||||
u64 image_handle;
|
||||
u64 table;
|
||||
u64 allocate_pool;
|
||||
u64 allocate_pages;
|
||||
u64 get_memory_map;
|
||||
u64 free_pool;
|
||||
u64 free_pages;
|
||||
u64 locate_handle;
|
||||
u64 handle_protocol;
|
||||
u64 exit_boot_services;
|
||||
u64 text_output;
|
||||
efi_status_t (*call)(unsigned long, ...);
|
||||
bool is64;
|
||||
} __packed;
|
||||
|
||||
#endif /* BOOT_COMPRESSED_EBOOT_H */
|
||||
|
||||
@@ -42,26 +42,53 @@ ENTRY(startup_32)
|
||||
ENTRY(efi_pe_entry)
|
||||
add $0x4, %esp
|
||||
|
||||
call 1f
|
||||
1: popl %esi
|
||||
subl $1b, %esi
|
||||
|
||||
popl %ecx
|
||||
movl %ecx, efi32_config(%esi) /* Handle */
|
||||
popl %ecx
|
||||
movl %ecx, efi32_config+8(%esi) /* EFI System table pointer */
|
||||
|
||||
/* Relocate efi_config->call() */
|
||||
leal efi32_config(%esi), %eax
|
||||
add %esi, 88(%eax)
|
||||
pushl %eax
|
||||
|
||||
call make_boot_params
|
||||
cmpl $0, %eax
|
||||
je 1f
|
||||
movl 0x4(%esp), %esi
|
||||
movl (%esp), %ecx
|
||||
je fail
|
||||
popl %ecx
|
||||
pushl %eax
|
||||
pushl %esi
|
||||
pushl %ecx
|
||||
sub $0x4, %esp
|
||||
jmp 2f /* Skip efi_config initialization */
|
||||
|
||||
ENTRY(efi_stub_entry)
|
||||
add $0x4, %esp
|
||||
popl %ecx
|
||||
popl %edx
|
||||
|
||||
call 1f
|
||||
1: popl %esi
|
||||
subl $1b, %esi
|
||||
|
||||
movl %ecx, efi32_config(%esi) /* Handle */
|
||||
movl %edx, efi32_config+8(%esi) /* EFI System table pointer */
|
||||
|
||||
/* Relocate efi_config->call() */
|
||||
leal efi32_config(%esi), %eax
|
||||
add %esi, 88(%eax)
|
||||
pushl %eax
|
||||
2:
|
||||
call efi_main
|
||||
cmpl $0, %eax
|
||||
movl %eax, %esi
|
||||
jne 2f
|
||||
1:
|
||||
fail:
|
||||
/* EFI init failed, so hang. */
|
||||
hlt
|
||||
jmp 1b
|
||||
jmp fail
|
||||
2:
|
||||
call 3f
|
||||
3:
|
||||
@@ -202,6 +229,13 @@ relocated:
|
||||
xorl %ebx, %ebx
|
||||
jmp *%eax
|
||||
|
||||
.data
|
||||
efi32_config:
|
||||
.fill 11,8,0
|
||||
.long efi_call_phys
|
||||
.long 0
|
||||
.byte 0
|
||||
|
||||
/*
|
||||
* Stack and heap for uncompression
|
||||
*/
|
||||
|
||||
@@ -209,26 +209,55 @@ ENTRY(startup_64)
|
||||
jmp preferred_addr
|
||||
|
||||
ENTRY(efi_pe_entry)
|
||||
mov %rcx, %rdi
|
||||
mov %rdx, %rsi
|
||||
pushq %rdi
|
||||
pushq %rsi
|
||||
movq %rcx, efi64_config(%rip) /* Handle */
|
||||
movq %rdx, efi64_config+8(%rip) /* EFI System table pointer */
|
||||
|
||||
leaq efi64_config(%rip), %rax
|
||||
movq %rax, efi_config(%rip)
|
||||
|
||||
call 1f
|
||||
1: popq %rbp
|
||||
subq $1b, %rbp
|
||||
|
||||
/*
|
||||
* Relocate efi_config->call().
|
||||
*/
|
||||
addq %rbp, efi64_config+88(%rip)
|
||||
|
||||
movq %rax, %rdi
|
||||
call make_boot_params
|
||||
cmpq $0,%rax
|
||||
je 1f
|
||||
mov %rax, %rdx
|
||||
popq %rsi
|
||||
popq %rdi
|
||||
je fail
|
||||
mov %rax, %rsi
|
||||
jmp 2f /* Skip the relocation */
|
||||
|
||||
ENTRY(efi_stub_entry)
|
||||
movq %rdi, efi64_config(%rip) /* Handle */
|
||||
movq %rsi, efi64_config+8(%rip) /* EFI System table pointer */
|
||||
|
||||
leaq efi64_config(%rip), %rax
|
||||
movq %rax, efi_config(%rip)
|
||||
|
||||
call 1f
|
||||
1: popq %rbp
|
||||
subq $1b, %rbp
|
||||
|
||||
/*
|
||||
* Relocate efi_config->call().
|
||||
*/
|
||||
movq efi_config(%rip), %rax
|
||||
addq %rbp, 88(%rax)
|
||||
movq %rdx, %rsi
|
||||
2:
|
||||
movq efi_config(%rip), %rdi
|
||||
call efi_main
|
||||
movq %rax,%rsi
|
||||
cmpq $0,%rax
|
||||
jne 2f
|
||||
1:
|
||||
fail:
|
||||
/* EFI init failed, so hang. */
|
||||
hlt
|
||||
jmp 1b
|
||||
jmp fail
|
||||
2:
|
||||
call 3f
|
||||
3:
|
||||
@@ -372,6 +401,14 @@ gdt:
|
||||
.quad 0x0000000000000000 /* TS continued */
|
||||
gdt_end:
|
||||
|
||||
efi_config:
|
||||
.quad 0
|
||||
|
||||
.global efi64_config
|
||||
efi64_config:
|
||||
.fill 11,8,0
|
||||
.quad efi_call6
|
||||
.byte 1
|
||||
/*
|
||||
* Stack and heap for uncompression
|
||||
*/
|
||||
|
||||
@@ -16,18 +16,6 @@ struct file_info {
|
||||
u64 size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static void efi_char16_printk(efi_system_table_t *sys_table_arg,
|
||||
efi_char16_t *str)
|
||||
{
|
||||
struct efi_simple_text_output_protocol *out;
|
||||
|
||||
out = (struct efi_simple_text_output_protocol *)sys_table_arg->con_out;
|
||||
efi_call_phys2(out->output_string, out, str);
|
||||
}
|
||||
|
||||
static void efi_printk(efi_system_table_t *sys_table_arg, char *str)
|
||||
{
|
||||
char *s8;
|
||||
@@ -65,20 +53,23 @@ again:
|
||||
* allocation which may be in a new descriptor region.
|
||||
*/
|
||||
*map_size += sizeof(*m);
|
||||
status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
|
||||
EFI_LOADER_DATA, *map_size, (void **)&m);
|
||||
status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
|
||||
*map_size, (void **)&m);
|
||||
if (status != EFI_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
status = efi_call_phys5(sys_table_arg->boottime->get_memory_map,
|
||||
map_size, m, &key, desc_size, &desc_version);
|
||||
*desc_size = 0;
|
||||
key = 0;
|
||||
status = efi_early->call(efi_early->get_memory_map, map_size, m,
|
||||
&key, desc_size, &desc_version);
|
||||
if (status == EFI_BUFFER_TOO_SMALL) {
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, m);
|
||||
efi_early->call(efi_early->free_pool, m);
|
||||
goto again;
|
||||
}
|
||||
|
||||
if (status != EFI_SUCCESS)
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, m);
|
||||
efi_early->call(efi_early->free_pool, m);
|
||||
|
||||
if (key_ptr && status == EFI_SUCCESS)
|
||||
*key_ptr = key;
|
||||
if (desc_ver && status == EFI_SUCCESS)
|
||||
@@ -158,9 +149,9 @@ again:
|
||||
if (!max_addr)
|
||||
status = EFI_NOT_FOUND;
|
||||
else {
|
||||
status = efi_call_phys4(sys_table_arg->boottime->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &max_addr);
|
||||
status = efi_early->call(efi_early->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &max_addr);
|
||||
if (status != EFI_SUCCESS) {
|
||||
max = max_addr;
|
||||
max_addr = 0;
|
||||
@@ -170,8 +161,7 @@ again:
|
||||
*addr = max_addr;
|
||||
}
|
||||
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, map);
|
||||
|
||||
efi_early->call(efi_early->free_pool, map);
|
||||
fail:
|
||||
return status;
|
||||
}
|
||||
@@ -231,9 +221,9 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
|
||||
if ((start + size) > end)
|
||||
continue;
|
||||
|
||||
status = efi_call_phys4(sys_table_arg->boottime->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &start);
|
||||
status = efi_early->call(efi_early->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &start);
|
||||
if (status == EFI_SUCCESS) {
|
||||
*addr = start;
|
||||
break;
|
||||
@@ -243,7 +233,7 @@ static efi_status_t efi_low_alloc(efi_system_table_t *sys_table_arg,
|
||||
if (i == map_size / desc_size)
|
||||
status = EFI_NOT_FOUND;
|
||||
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, map);
|
||||
efi_early->call(efi_early->free_pool, map);
|
||||
fail:
|
||||
return status;
|
||||
}
|
||||
@@ -257,7 +247,7 @@ static void efi_free(efi_system_table_t *sys_table_arg, unsigned long size,
|
||||
return;
|
||||
|
||||
nr_pages = round_up(size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
|
||||
efi_call_phys2(sys_table_arg->boottime->free_pages, addr, nr_pages);
|
||||
efi_early->call(efi_early->free_pages, addr, nr_pages);
|
||||
}
|
||||
|
||||
|
||||
@@ -276,9 +266,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
|
||||
{
|
||||
struct file_info *files;
|
||||
unsigned long file_addr;
|
||||
efi_guid_t fs_proto = EFI_FILE_SYSTEM_GUID;
|
||||
u64 file_size_total;
|
||||
efi_file_io_interface_t *io;
|
||||
efi_file_handle_t *fh;
|
||||
efi_status_t status;
|
||||
int nr_files;
|
||||
@@ -319,10 +307,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
|
||||
if (!nr_files)
|
||||
return EFI_SUCCESS;
|
||||
|
||||
status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
|
||||
EFI_LOADER_DATA,
|
||||
nr_files * sizeof(*files),
|
||||
(void **)&files);
|
||||
status = efi_early->call(efi_early->allocate_pool, EFI_LOADER_DATA,
|
||||
nr_files * sizeof(*files), (void **)&files);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to alloc mem for file handle list\n");
|
||||
goto fail;
|
||||
@@ -331,13 +317,8 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
|
||||
str = cmd_line;
|
||||
for (i = 0; i < nr_files; i++) {
|
||||
struct file_info *file;
|
||||
efi_file_handle_t *h;
|
||||
efi_file_info_t *info;
|
||||
efi_char16_t filename_16[256];
|
||||
unsigned long info_sz;
|
||||
efi_guid_t info_guid = EFI_FILE_INFO_ID;
|
||||
efi_char16_t *p;
|
||||
u64 file_sz;
|
||||
|
||||
str = strstr(str, option_string);
|
||||
if (!str)
|
||||
@@ -368,71 +349,18 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
|
||||
|
||||
/* Only open the volume once. */
|
||||
if (!i) {
|
||||
efi_boot_services_t *boottime;
|
||||
|
||||
boottime = sys_table_arg->boottime;
|
||||
|
||||
status = efi_call_phys3(boottime->handle_protocol,
|
||||
image->device_handle, &fs_proto,
|
||||
(void **)&io);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to handle fs_proto\n");
|
||||
status = efi_open_volume(sys_table_arg, image,
|
||||
(void **)&fh);
|
||||
if (status != EFI_SUCCESS)
|
||||
goto free_files;
|
||||
}
|
||||
|
||||
status = efi_call_phys2(io->open_volume, io, &fh);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to open volume\n");
|
||||
goto free_files;
|
||||
}
|
||||
}
|
||||
|
||||
status = efi_call_phys5(fh->open, fh, &h, filename_16,
|
||||
EFI_FILE_MODE_READ, (u64)0);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to open file: ");
|
||||
efi_char16_printk(sys_table_arg, filename_16);
|
||||
efi_printk(sys_table_arg, "\n");
|
||||
status = efi_file_size(sys_table_arg, fh, filename_16,
|
||||
(void **)&file->handle, &file->size);
|
||||
if (status != EFI_SUCCESS)
|
||||
goto close_handles;
|
||||
}
|
||||
|
||||
file->handle = h;
|
||||
|
||||
info_sz = 0;
|
||||
status = efi_call_phys4(h->get_info, h, &info_guid,
|
||||
&info_sz, NULL);
|
||||
if (status != EFI_BUFFER_TOO_SMALL) {
|
||||
efi_printk(sys_table_arg, "Failed to get file info size\n");
|
||||
goto close_handles;
|
||||
}
|
||||
|
||||
grow:
|
||||
status = efi_call_phys3(sys_table_arg->boottime->allocate_pool,
|
||||
EFI_LOADER_DATA, info_sz,
|
||||
(void **)&info);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to alloc mem for file info\n");
|
||||
goto close_handles;
|
||||
}
|
||||
|
||||
status = efi_call_phys4(h->get_info, h, &info_guid,
|
||||
&info_sz, info);
|
||||
if (status == EFI_BUFFER_TOO_SMALL) {
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool,
|
||||
info);
|
||||
goto grow;
|
||||
}
|
||||
|
||||
file_sz = info->file_size;
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, info);
|
||||
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to get file info\n");
|
||||
goto close_handles;
|
||||
}
|
||||
|
||||
file->size = file_sz;
|
||||
file_size_total += file_sz;
|
||||
file_size_total += file->size;
|
||||
}
|
||||
|
||||
if (file_size_total) {
|
||||
@@ -468,10 +396,10 @@ grow:
|
||||
chunksize = EFI_READ_CHUNK_SIZE;
|
||||
else
|
||||
chunksize = size;
|
||||
status = efi_call_phys3(fh->read,
|
||||
files[j].handle,
|
||||
&chunksize,
|
||||
(void *)addr);
|
||||
|
||||
status = efi_file_read(fh, files[j].handle,
|
||||
&chunksize,
|
||||
(void *)addr);
|
||||
if (status != EFI_SUCCESS) {
|
||||
efi_printk(sys_table_arg, "Failed to read file\n");
|
||||
goto free_file_total;
|
||||
@@ -480,12 +408,12 @@ grow:
|
||||
size -= chunksize;
|
||||
}
|
||||
|
||||
efi_call_phys1(fh->close, files[j].handle);
|
||||
efi_file_close(fh, files[j].handle);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, files);
|
||||
efi_early->call(efi_early->free_pool, files);
|
||||
|
||||
*load_addr = file_addr;
|
||||
*load_size = file_size_total;
|
||||
@@ -497,9 +425,9 @@ free_file_total:
|
||||
|
||||
close_handles:
|
||||
for (k = j; k < i; k++)
|
||||
efi_call_phys1(fh->close, files[k].handle);
|
||||
efi_file_close(fh, files[k].handle);
|
||||
free_files:
|
||||
efi_call_phys1(sys_table_arg->boottime->free_pool, files);
|
||||
efi_early->call(efi_early->free_pool, files);
|
||||
fail:
|
||||
*load_addr = 0;
|
||||
*load_size = 0;
|
||||
@@ -545,9 +473,9 @@ static efi_status_t efi_relocate_kernel(efi_system_table_t *sys_table_arg,
|
||||
* as possible while respecting the required alignment.
|
||||
*/
|
||||
nr_pages = round_up(alloc_size, EFI_PAGE_SIZE) / EFI_PAGE_SIZE;
|
||||
status = efi_call_phys4(sys_table_arg->boottime->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &efi_addr);
|
||||
status = efi_early->call(efi_early->allocate_pages,
|
||||
EFI_ALLOCATE_ADDRESS, EFI_LOADER_DATA,
|
||||
nr_pages, &efi_addr);
|
||||
new_addr = efi_addr;
|
||||
/*
|
||||
* If preferred address allocation failed allocate as low as
|
||||
|
||||
Reference in New Issue
Block a user