Create new stack and then boot XTOS, export more routines with the loader protocol
Some checks failed
ci/woodpecker/push/build Pipeline failed
Some checks failed
ci/woodpecker/push/build Pipeline failed
This commit is contained in:
parent
d50fb7c37d
commit
900e86c9da
@ -22,12 +22,16 @@
|
|||||||
#define _XT32 1
|
#define _XT32 1
|
||||||
#define EFI_ERROR_MASK 0x80000000
|
#define EFI_ERROR_MASK 0x80000000
|
||||||
#define XTOS_KERNEL_ADDRESS 0x81800000
|
#define XTOS_KERNEL_ADDRESS 0x81800000
|
||||||
|
#define XTOS_KERNEL_STACK_SIZE 8
|
||||||
|
#define XTOS_VIRTUAL_MEMORY_AREA 0x80000000
|
||||||
#elif defined(__amd64__) || defined(__x86_64__)
|
#elif defined(__amd64__) || defined(__x86_64__)
|
||||||
#define _ARCH amd64
|
#define _ARCH amd64
|
||||||
#define _ARCH_AMD64 1
|
#define _ARCH_AMD64 1
|
||||||
#define _XT64 1
|
#define _XT64 1
|
||||||
#define EFI_ERROR_MASK 0x8000000000000000
|
#define EFI_ERROR_MASK 0x8000000000000000
|
||||||
#define XTOS_KERNEL_ADDRESS 0xFFFFF80800000000
|
#define XTOS_KERNEL_ADDRESS 0xFFFFF80800000000
|
||||||
|
#define XTOS_KERNEL_STACK_SIZE 8
|
||||||
|
#define XTOS_VIRTUAL_MEMORY_AREA 0xFFFFF80000000000
|
||||||
#else
|
#else
|
||||||
#error Unknown architecture
|
#error Unknown architecture
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,10 +14,15 @@
|
|||||||
|
|
||||||
|
|
||||||
/* Loader protocol routine pointers */
|
/* Loader protocol routine pointers */
|
||||||
|
typedef EFI_STATUS (*PBL_ADD_VIRTUAL_MEMORY_MAPPING)(IN PLIST_ENTRY MemoryMappings, IN PVOID VirtualAddress, IN PVOID PhysicalAddress, IN UINT NumberOfPages, LOADER_MEMORY_TYPE MemoryType);
|
||||||
typedef EFI_STATUS (*PBL_ALLOCATE_PAGES)(IN UINT64 Size, OUT PEFI_PHYSICAL_ADDRESS Memory);
|
typedef EFI_STATUS (*PBL_ALLOCATE_PAGES)(IN UINT64 Size, OUT PEFI_PHYSICAL_ADDRESS Memory);
|
||||||
typedef EFI_STATUS (*PBL_ALLOCATE_POOL)(IN UINT_PTR Size, OUT PVOID *Memory);
|
typedef EFI_STATUS (*PBL_ALLOCATE_POOL)(IN UINT_PTR Size, OUT PVOID *Memory);
|
||||||
typedef EFI_STATUS (*PBL_FREE_PAGES)(IN UINT64 Size, IN EFI_PHYSICAL_ADDRESS Memory);
|
typedef EFI_STATUS (*PBL_FREE_PAGES)(IN UINT64 Size, IN EFI_PHYSICAL_ADDRESS Memory);
|
||||||
typedef EFI_STATUS (*PBL_FREE_POOL)(IN PVOID Memory);
|
typedef EFI_STATUS (*PBL_FREE_POOL)(IN PVOID Memory);
|
||||||
|
typedef EFI_STATUS (*PBL_GET_MEMORY_MAP)(OUT PEFI_MEMORY_DESCRIPTOR *MemoryMap, OUT PUINT_PTR MapKey, OUT PUINT_PTR DescriptorSize, OUT PUINT_PTR DescriptorCount);
|
||||||
|
typedef EFI_STATUS (*PBL_INIT_VIRTUAL_MEMORY)(IN OUT PLIST_ENTRY MemoryMappings, IN OUT PVOID *MemoryMapAddress);
|
||||||
|
typedef EFI_STATUS (*PBL_MAP_VIRTUAL_MEMORY)(IN PLIST_ENTRY MemoryMappings, IN UINT_PTR VirtualAddress, IN UINT_PTR PhysicalAddress, IN UINT NumberOfPages, IN OUT PVOID *PtePointer);
|
||||||
|
typedef VOID (*PBL_GET_STACK)(OUT PVOID *Stack);
|
||||||
typedef VOID (*PBL_DBG_PRINT)(IN PUINT16 Format, IN ...);
|
typedef VOID (*PBL_DBG_PRINT)(IN PUINT16 Format, IN ...);
|
||||||
typedef VOID (*PBL_EFI_PRINT)(IN PUINT16 Format, IN ...);
|
typedef VOID (*PBL_EFI_PRINT)(IN PUINT16 Format, IN ...);
|
||||||
typedef EFI_STATUS (*PBL_CLOSE_VOLUME)(IN PEFI_HANDLE VolumeHandle);
|
typedef EFI_STATUS (*PBL_CLOSE_VOLUME)(IN PEFI_HANDLE VolumeHandle);
|
||||||
@ -26,10 +31,15 @@ typedef EFI_STATUS (*PBL_OPEN_VOLUME)(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath, O
|
|||||||
/* EFI XT Boot Loader Protocol */
|
/* EFI XT Boot Loader Protocol */
|
||||||
typedef struct _XT_BOOT_LOADER_PROTOCOL
|
typedef struct _XT_BOOT_LOADER_PROTOCOL
|
||||||
{
|
{
|
||||||
|
PBL_ADD_VIRTUAL_MEMORY_MAPPING AddVirtualMemoryMapping;
|
||||||
PBL_ALLOCATE_PAGES AllocatePages;
|
PBL_ALLOCATE_PAGES AllocatePages;
|
||||||
PBL_ALLOCATE_POOL AllocatePool;
|
PBL_ALLOCATE_POOL AllocatePool;
|
||||||
PBL_FREE_PAGES FreePages;
|
PBL_FREE_PAGES FreePages;
|
||||||
PBL_FREE_POOL FreePool;
|
PBL_FREE_POOL FreePool;
|
||||||
|
PBL_GET_MEMORY_MAP GetMemoryMap;
|
||||||
|
PBL_INIT_VIRTUAL_MEMORY InitializeVirtualMemory;
|
||||||
|
PBL_MAP_VIRTUAL_MEMORY MapVirtualMemory;
|
||||||
|
PBL_GET_STACK GetStack;
|
||||||
PBL_DBG_PRINT DbgPrint;
|
PBL_DBG_PRINT DbgPrint;
|
||||||
PBL_EFI_PRINT EfiPrint;
|
PBL_EFI_PRINT EfiPrint;
|
||||||
PBL_CLOSE_VOLUME CloseVolume;
|
PBL_CLOSE_VOLUME CloseVolume;
|
||||||
|
@ -26,6 +26,9 @@ EXTERN PEFI_SYSTEM_TABLE EfiSystemTable;
|
|||||||
/* EFI Secure Boot status */
|
/* EFI Secure Boot status */
|
||||||
EXTERN INT_PTR EfiSecureBoot;
|
EXTERN INT_PTR EfiSecureBoot;
|
||||||
|
|
||||||
|
/* New bootloader stack */
|
||||||
|
EXTERN PVOID EfiLoaderStack;
|
||||||
|
|
||||||
/* Serial port configuration */
|
/* Serial port configuration */
|
||||||
EXTERN CPPORT EfiSerialPort;
|
EXTERN CPPORT EfiSerialPort;
|
||||||
|
|
||||||
@ -103,6 +106,8 @@ BlGetMemoryMap(OUT PEFI_MEMORY_DESCRIPTOR *MemoryMap,
|
|||||||
OUT PUINT_PTR DescriptorSize,
|
OUT PUINT_PTR DescriptorSize,
|
||||||
OUT PUINT_PTR DescriptorCount);
|
OUT PUINT_PTR DescriptorCount);
|
||||||
|
|
||||||
|
VOID BlGetStackPointer(OUT PVOID *Stack);
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlGetVolumeDevicePath(IN PUCHAR SystemPath,
|
BlGetVolumeDevicePath(IN PUCHAR SystemPath,
|
||||||
OUT PEFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
OUT PEFI_DEVICE_PATH_PROTOCOL *DevicePath,
|
||||||
@ -131,6 +136,9 @@ BlOpenVolume(IN PEFI_DEVICE_PATH_PROTOCOL DevicePath,
|
|||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlRegisterXtLoaderProtocol();
|
BlRegisterXtLoaderProtocol();
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BlStartNewStack();
|
||||||
|
|
||||||
EFI_STATUS
|
EFI_STATUS
|
||||||
BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
||||||
IN PEFI_SYSTEM_TABLE SystemTable);
|
IN PEFI_SYSTEM_TABLE SystemTable);
|
||||||
|
@ -21,9 +21,18 @@ PEFI_SYSTEM_TABLE EfiSystemTable;
|
|||||||
/* EFI Secure Boot status */
|
/* EFI Secure Boot status */
|
||||||
INT_PTR EfiSecureBoot;
|
INT_PTR EfiSecureBoot;
|
||||||
|
|
||||||
|
/* New bootloader stack */
|
||||||
|
PVOID EfiLoaderStack;
|
||||||
|
|
||||||
/* Serial port configuration */
|
/* Serial port configuration */
|
||||||
CPPORT EfiSerialPort;
|
CPPORT EfiSerialPort;
|
||||||
|
|
||||||
|
|
||||||
|
VOID BlGetStackPointer(OUT PVOID *Stack)
|
||||||
|
{
|
||||||
|
*Stack = EfiLoaderStack;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine loads XTLDR EFI modules.
|
* This routine loads XTLDR EFI modules.
|
||||||
*
|
*
|
||||||
@ -316,10 +325,15 @@ BlRegisterXtLoaderProtocol()
|
|||||||
EFI_HANDLE Handle = NULL;
|
EFI_HANDLE Handle = NULL;
|
||||||
|
|
||||||
/* Set all routines available via loader protocol */
|
/* Set all routines available via loader protocol */
|
||||||
|
EfiLdrProtocol.AddVirtualMemoryMapping = BlAddVirtualMemoryMapping;
|
||||||
EfiLdrProtocol.AllocatePages = BlEfiMemoryAllocatePages;
|
EfiLdrProtocol.AllocatePages = BlEfiMemoryAllocatePages;
|
||||||
EfiLdrProtocol.AllocatePool = BlEfiMemoryAllocatePool;
|
EfiLdrProtocol.AllocatePool = BlEfiMemoryAllocatePool;
|
||||||
EfiLdrProtocol.FreePages = BlEfiMemoryFreePages;
|
EfiLdrProtocol.FreePages = BlEfiMemoryFreePages;
|
||||||
EfiLdrProtocol.FreePool = BlEfiMemoryFreePool;
|
EfiLdrProtocol.FreePool = BlEfiMemoryFreePool;
|
||||||
|
EfiLdrProtocol.GetMemoryMap = BlGetMemoryMap;
|
||||||
|
EfiLdrProtocol.InitializeVirtualMemory = BlInitializeVirtualMemory;
|
||||||
|
EfiLdrProtocol.MapVirtualMemory = BlMapVirtualMemory;
|
||||||
|
EfiLdrProtocol.GetStack = BlGetStackPointer;
|
||||||
EfiLdrProtocol.DbgPrint = BlDbgPrint;
|
EfiLdrProtocol.DbgPrint = BlDbgPrint;
|
||||||
EfiLdrProtocol.EfiPrint = BlEfiPrint;
|
EfiLdrProtocol.EfiPrint = BlEfiPrint;
|
||||||
EfiLdrProtocol.CloseVolume = BlCloseVolume;
|
EfiLdrProtocol.CloseVolume = BlCloseVolume;
|
||||||
@ -331,6 +345,27 @@ BlRegisterXtLoaderProtocol()
|
|||||||
&EfiLdrProtocol);
|
&EfiLdrProtocol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EFI_STATUS
|
||||||
|
BlStartNewStack()
|
||||||
|
{
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
|
/* Boot XTOS */
|
||||||
|
Status = BlLoadXtSystem();
|
||||||
|
if(Status != STATUS_EFI_SUCCESS)
|
||||||
|
{
|
||||||
|
/* Boot process failed */
|
||||||
|
BlEfiPrint(L"Failed to start XT OS (Status code: %lx)!\n", Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Infinite bootloader loop */
|
||||||
|
BlEfiPrint(L"System halted!");
|
||||||
|
for(;;);
|
||||||
|
|
||||||
|
/* Return success */
|
||||||
|
return STATUS_EFI_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine is the entry point of the XT EFI boot loader.
|
* This routine is the entry point of the XT EFI boot loader.
|
||||||
*
|
*
|
||||||
@ -400,15 +435,11 @@ BlStartXtLoader(IN EFI_HANDLE ImageHandle,
|
|||||||
/* Discover and enumerate EFI block devices */
|
/* Discover and enumerate EFI block devices */
|
||||||
BlEnumerateEfiBlockDevices();
|
BlEnumerateEfiBlockDevices();
|
||||||
|
|
||||||
/* Boot XTOS */
|
/* Create new bootloader stack */
|
||||||
Status = BlLoadXtSystem();
|
BlCreateStack(&EfiLoaderStack, XTOS_KERNEL_STACK_SIZE, &BlStartNewStack);
|
||||||
if(Status != STATUS_EFI_SUCCESS)
|
|
||||||
{
|
|
||||||
/* Boot process failed */
|
|
||||||
BlEfiPrint(L"Failed to start XT OS (Status code: %lx)!\n", Status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Infinite bootloader loop */
|
/* Infinite bootloader loop */
|
||||||
|
BlDbgPrint(L"ERROR: Unexpected exception occurred, probably did not create a new stack");
|
||||||
BlEfiPrint(L"System halted!");
|
BlEfiPrint(L"System halted!");
|
||||||
for(;;);
|
for(;;);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user