stand/efi: move G(x) and M(x) macros to loader_efi.h

These are often needed for copying to the staging area or just general
page table calculations on amd64.

Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/1446
This commit is contained in:
Ahmad Khalifa 2024-09-27 19:01:27 +03:00 committed by Warner Losh
parent a2c48b865e
commit ea0f267c8b
5 changed files with 12 additions and 16 deletions

View file

@ -101,8 +101,7 @@ elf64_exec(struct preloaded_file *fp)
ehdr = (Elf_Ehdr *)&(md->md_data);
trampcode = copy_staging == COPY_STAGING_ENABLE ?
(vm_offset_t)0x0000000040000000 /* 1G */ :
(vm_offset_t)0x0000000100000000; /* 4G */;
(vm_offset_t)G(1) : (vm_offset_t)G(4);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 1,
(EFI_PHYSICAL_ADDRESS *)&trampcode);
if (EFI_ERROR(err)) {
@ -117,7 +116,7 @@ elf64_exec(struct preloaded_file *fp)
trampoline = (void *)trampcode;
if (copy_staging == COPY_STAGING_ENABLE) {
PT4 = (pml4_entry_t *)0x0000000040000000; /* 1G */
PT4 = (pml4_entry_t *)G(1);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 3,
(EFI_PHYSICAL_ADDRESS *)&PT4);
if (EFI_ERROR(err)) {
@ -154,11 +153,11 @@ elf64_exec(struct preloaded_file *fp)
/*
* The L2 page slots are mapped with 2MB pages for 1GB.
*/
PT2[i] = (pd_entry_t)i * (2 * 1024 * 1024);
PT2[i] = (pd_entry_t)i * M(2);
PT2[i] |= PG_V | PG_RW | PG_PS;
}
} else {
PT4 = (pml4_entry_t *)0x0000000100000000; /* 4G */
PT4 = (pml4_entry_t *)G(4);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 9,
(EFI_PHYSICAL_ADDRESS *)&PT4);
if (EFI_ERROR(err)) {

View file

@ -71,9 +71,6 @@ struct gdtr {
#define GDT_RW 0x00020000000000
#define GDT_L 0x20000000000000
#define M(x) ((x) * 1024 * 1024)
#define G(x) (1ULL * (x) * 1024 * 1024 * 1024)
typedef uint64_t p4_entry_t;
typedef uint64_t p3_entry_t;
typedef uint64_t p2_entry_t;

View file

@ -35,9 +35,6 @@
#include "loader_efi.h"
#define M(x) ((x) * 1024 * 1024)
#define G(x) (1ULL * (x) * 1024 * 1024 * 1024)
#if defined(__amd64__)
#include <machine/cpufunc.h>
#include <machine/specialreg.h>

View file

@ -41,6 +41,10 @@ enum {
extern int copy_staging;
#endif
/* Useful for various calculations */
#define M(x) ((x) * 1024 * 1024)
#define G(x) (1ULL * (x) * 1024 * 1024 * 1024)
extern EFI_LOADED_IMAGE *boot_img;
int efi_autoload(void);

View file

@ -209,8 +209,7 @@ elf64_exec(struct preloaded_file *fp)
#ifdef EFI
trampcode = copy_staging == COPY_STAGING_ENABLE ?
(vm_offset_t)0x0000000040000000 /* 1G */ :
(vm_offset_t)0x0000000100000000; /* 4G */;
(vm_offset_t)G(1) : (vm_offset_t)G(4);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 1,
(EFI_PHYSICAL_ADDRESS *)&trampcode);
if (EFI_ERROR(err)) {
@ -234,7 +233,7 @@ elf64_exec(struct preloaded_file *fp)
#ifdef EFI
if (copy_staging == COPY_STAGING_ENABLE) {
PT4 = (pml4_entry_t *)0x0000000040000000; /* 1G */
PT4 = (pml4_entry_t *)G(1);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 3,
(EFI_PHYSICAL_ADDRESS *)&PT4);
if (EFI_ERROR(err)) {
@ -271,11 +270,11 @@ elf64_exec(struct preloaded_file *fp)
/*
* The L2 page slots are mapped with 2MB pages for 1GB.
*/
PT2[i] = (pd_entry_t)i * (2 * 1024 * 1024);
PT2[i] = (pd_entry_t)i * M(2);
PT2[i] |= PG_V | PG_RW | PG_PS;
}
} else {
PT4 = (pml4_entry_t *)0x0000000100000000; /* 4G */
PT4 = (pml4_entry_t *)G(4);
err = BS->AllocatePages(AllocateMaxAddress, EfiLoaderData, 9,
(EFI_PHYSICAL_ADDRESS *)&PT4);
if (EFI_ERROR(err)) {