From edde39b36886c1392dcfe670bab178ecb2bfaf4e Mon Sep 17 00:00:00 2001 From: "Zheng, Gen" Date: Thu, 29 Mar 2018 10:59:48 +0800 Subject: [PATCH] UEFI: header file cleanup Move the header content from boot.c to boot.h Signed-off-by: Zheng, Gen --- bsp/uefi/efi/boot.c | 39 ----------------------- bsp/uefi/efi/boot.h | 77 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 39 deletions(-) diff --git a/bsp/uefi/efi/boot.c b/bsp/uefi/efi/boot.c index 4500de85d..dc9f1f83e 100644 --- a/bsp/uefi/efi/boot.c +++ b/bsp/uefi/efi/boot.c @@ -36,15 +36,6 @@ #include "efilinux.h" #include "stdlib.h" #include "boot.h" -#include "multiboot.h" - -#define ERROR_STRING_LENGTH 32 -#define EFI_LOADER_SIGNATURE "EL64" - -#define ACPI_XSDT_ENTRY_SIZE (sizeof (UINT64)) -#define ACPI_NAME_SIZE 4 -#define ACPI_OEM_ID_SIZE 6 -#define ACPI_OEM_TABLE_ID_SIZE 8 EFI_SYSTEM_TABLE *sys_table; EFI_BOOT_SERVICES *boot; @@ -128,36 +119,6 @@ static void print_ch(char *str) } #endif - - - -struct acpi_table_rsdp { - char signature[8]; /* ACPI signature, contains "RSD PTR " */ - UINT8 checksum; /* ACPI 1.0 checksum */ - char oem_id[ACPI_OEM_ID_SIZE]; /* OEM identification */ - UINT8 revision; /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */ - UINT32 rsdt_physical_address; /* 32-bit physical address of the RSDT */ - UINT32 length; /* Table length in bytes, including header (ACPI 2.0+) */ - UINT64 xsdt_physical_address; /* 64-bit physical address of the XSDT (ACPI 2.0+) */ - UINT8 extended_checksum; /* Checksum of entire table (ACPI 2.0+) */ - UINT8 reserved[3]; /* Reserved, must be zero */ -}; - -struct acpi_table_header { - char signature[ACPI_NAME_SIZE]; /* ASCII table signature */ - UINT32 length; /* Length of table in bytes, including this header */ - UINT8 revision; /* ACPI Specification minor version number */ - UINT8 checksum; /* To make sum of entire table == 0 */ - char oem_id[ACPI_OEM_ID_SIZE]; /* ASCII OEM identification */ - char oem_table_id[ACPI_OEM_TABLE_ID_SIZE]; /* ASCII OEM table identification */ - UINT32 oem_revision; /* OEM revision number */ - char asl_compiler_id[ACPI_NAME_SIZE]; /* ASCII ASL compiler vendor ID */ - UINT32 asl_compiler_revision; /* ASL compiler version */ -}; - -typedef void(*hv_func)(int, struct multiboot_info*); -EFI_IMAGE_ENTRY_POINT get_pe_entry(CHAR8 *base); - static inline void hv_jump(EFI_PHYSICAL_ADDRESS hv_start, struct multiboot_info *mbi, struct efi_ctx *efi_ctx) { diff --git a/bsp/uefi/efi/boot.h b/bsp/uefi/efi/boot.h index d6b8aae5b..2968a4c84 100644 --- a/bsp/uefi/efi/boot.h +++ b/bsp/uefi/efi/boot.h @@ -35,6 +35,7 @@ #define __ACRNBOOT_H__ #include +#include "multiboot.h" #define E820_RAM 1 #define E820_RESERVED 2 @@ -42,7 +43,32 @@ #define E820_NVS 4 #define E820_UNUSABLE 5 +#define ERROR_STRING_LENGTH 32 +#define EFI_LOADER_SIGNATURE "EL64" + +#define ACPI_XSDT_ENTRY_SIZE (sizeof(UINT64)) +#define ACPI_NAME_SIZE 4 +#define ACPI_OEM_ID_SIZE 6 +#define ACPI_OEM_TABLE_ID_SIZE 8 + +#define MSR_IA32_PAT 0x00000277 /* PAT */ +#define MSR_IA32_EFER 0xC0000080 +#define MSR_IA32_FS_BASE 0xC0000100 +#define MSR_IA32_GS_BASE 0xC0000101 +#define MSR_IA32_SYSENTER_ESP 0x00000175 /* ESP for sysenter */ +#define MSR_IA32_SYSENTER_EIP 0x00000176 /* EIP for sysenter */ + +/* Read MSR */ +#define CPU_MSR_READ(reg, msr_val_ptr) \ +{ \ + uint32_t msrl, msrh; \ + asm volatile ("rdmsr" : "=a"(msrl), \ + "=d"(msrh) : "c" (reg)); \ + *msr_val_ptr = ((uint64_t)msrh<<32) | msrl; \ +} + EFI_STATUS get_pe_section(CHAR8 *base, char *section, UINTN *vaddr, UINTN *size); +typedef void(*hv_func)(int, struct multiboot_info*); struct efi_info { UINT32 efi_loader_signature; @@ -104,5 +130,56 @@ struct efi_ctx { uint64_t r15; }__attribute__((packed)); +struct acpi_table_rsdp { + /* ACPI signature, contains "RSD PTR " */ + char signature[8]; + /* ACPI 1.0 checksum */ + UINT8 checksum; + /* OEM identification */ + char oem_id[ACPI_OEM_ID_SIZE]; + /* Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ */ + UINT8 revision; + /* 32-bit physical address of the RSDT */ + UINT32 rsdt_physical_address; + /* Table length in bytes, including header (ACPI 2.0+) */ + UINT32 length; + /* 64-bit physical address of the XSDT (ACPI 2.0+) */ + UINT64 xsdt_physical_address; + /* Checksum of entire table (ACPI 2.0+) */ + UINT8 extended_checksum; + /* Reserved, must be zero */ + UINT8 reserved[3]; +}; + +struct acpi_table_header { + /* ASCII table signature */ + char signature[ACPI_NAME_SIZE]; + /* Length of table in bytes, including this header */ + UINT32 length; + /* ACPI Specification minor version number */ + UINT8 revision; + /* To make sum of entire table == 0 */ + UINT8 checksum; + /* ASCII OEM identification */ + char oem_id[ACPI_OEM_ID_SIZE]; + /* ASCII OEM table identification */ + char oem_table_id[ACPI_OEM_TABLE_ID_SIZE]; + /* OEM revision number */ + UINT32 oem_revision; + /* ASCII ASL compiler vendor ID */ + char asl_compiler_id[ACPI_NAME_SIZE]; + /* ASL compiler version */ + UINT32 asl_compiler_revision; +}; + +static inline uint64_t +msr_read(uint32_t reg_num) +{ + uint64_t msr_val; + + CPU_MSR_READ(reg_num, &msr_val); + return msr_val; +} + #endif