Skip to content

Commit

Permalink
Fix bootloader
Browse files Browse the repository at this point in the history
Fix bootloader
  • Loading branch information
andyvand committed Jan 28, 2024
1 parent d9a88c2 commit bc625bb
Show file tree
Hide file tree
Showing 18 changed files with 2,482 additions and 516 deletions.
96 changes: 67 additions & 29 deletions src/boot/BootArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ STATIC CHAR8 CONST* BlpRootUUIDFromDisk(EFI_HANDLE deviceHandle, CHAR8* uuidBuff
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return (const CHAR8 *)NULL;
return rootUUID;
#endif

//
Expand All @@ -101,7 +101,7 @@ STATIC CHAR8 CONST* BlpRootUUIDFromDisk(EFI_HANDLE deviceHandle, CHAR8* uuidBuff
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return (const CHAR8 *)NULL;
return rootUUID;
#endif

//
Expand All @@ -112,7 +112,7 @@ STATIC CHAR8 CONST* BlpRootUUIDFromDisk(EFI_HANDLE deviceHandle, CHAR8* uuidBuff
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return (const CHAR8 *)NULL;
return rootUUID;
#endif

//
Expand All @@ -129,7 +129,7 @@ STATIC CHAR8 CONST* BlpRootUUIDFromDisk(EFI_HANDLE deviceHandle, CHAR8* uuidBuff
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return (const CHAR8 *)NULL;
return rootUUID;
#endif
}

Expand All @@ -143,7 +143,7 @@ STATIC CHAR8 CONST* BlpRootUUIDFromDisk(EFI_HANDLE deviceHandle, CHAR8* uuidBuff
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return (const CHAR8 *)NULL;
return rootUUID;
#endif

//
Expand Down Expand Up @@ -353,6 +353,10 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
try_leave(status = EFI_OUT_OF_RESOURCES);
#else
status = EFI_OUT_OF_RESOURCES;

if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}
Expand Down Expand Up @@ -414,29 +418,41 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
try_leave(status = EFI_OUT_OF_RESOURCES);
#else
status = EFI_OUT_OF_RESOURCES;

if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// compatible = ACPI
//
if(EFI_ERROR(status = DevTreeAddProperty(rootNode, CHAR8_CONST_STRING("compatible"), "ACPI", 5, FALSE)))
if(EFI_ERROR(status = DevTreeAddProperty(rootNode, CHAR8_CONST_STRING("compatible"), "ACPI", 5, FALSE))) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// model = ACPI
//
if(EFI_ERROR(status = DevTreeAddProperty(rootNode, CHAR8_CONST_STRING("model"), "ACPI", 5, FALSE)))
if(EFI_ERROR(status = DevTreeAddProperty(rootNode, CHAR8_CONST_STRING("model"), "ACPI", 5, FALSE))) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// get chosen node
Expand All @@ -447,6 +463,10 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
try_leave(status = EFI_OUT_OF_RESOURCES);
#else
status = EFI_OUT_OF_RESOURCES;

if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}
Expand All @@ -460,6 +480,10 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
try_leave(status = EFI_OUT_OF_RESOURCES);
#else
status = EFI_OUT_OF_RESOURCES;

if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}
Expand Down Expand Up @@ -538,29 +562,40 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// add boot device path
//
if(EFI_ERROR(status = DevTreeAddProperty(chosenNode, CHAR8_CONST_STRING("boot-device-path"), bootDevicePath, static_cast<UINT32>(DevPathGetSize(bootDevicePath)), FALSE)))
if(EFI_ERROR(status = DevTreeAddProperty(chosenNode, CHAR8_CONST_STRING("boot-device-path"), bootDevicePath, static_cast<UINT32>(DevPathGetSize(bootDevicePath)), FALSE))) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// add boot file path
//
if(EFI_ERROR(status = DevTreeAddProperty(chosenNode, CHAR8_CONST_STRING("boot-file-path"), bootFilePath, static_cast<UINT32>(DevPathGetSize(bootFilePath)), FALSE)))
if(EFI_ERROR(status = DevTreeAddProperty(chosenNode, CHAR8_CONST_STRING("boot-file-path"), bootFilePath, static_cast<UINT32>(DevPathGetSize(bootFilePath)), FALSE))) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}

//
// Boot != Root key for firmware's /chosen
Expand All @@ -572,7 +607,10 @@ EFI_STATUS BlInitializeBootArgs(EFI_DEVICE_PATH_PROTOCOL* bootDevicePath, EFI_DE
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
if(EFI_ERROR(status))
MmFreeKernelMemory(virtualAddress, physicalAddress);

return status;
#endif
}
}
Expand Down Expand Up @@ -693,7 +731,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand All @@ -703,7 +741,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand All @@ -713,7 +751,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand All @@ -727,7 +765,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

bootArgs->KeyStoreDataStart = static_cast<UINT32>(keyStorePhysicalAddress);
Expand All @@ -742,7 +780,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand Down Expand Up @@ -773,7 +811,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand All @@ -799,7 +837,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand Down Expand Up @@ -855,7 +893,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

if(currentSize > memoryMapSize)
Expand All @@ -882,7 +920,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand All @@ -900,7 +938,7 @@ EFI_STATUS BlFinalizeBootArgs(BOOT_ARGS* bootArgs, CHAR8 CONST* kernelCommandLin
#if defined(_MSC_VER)
try_leave(NOTHING);
#else
return -1;
return status;
#endif

//
Expand Down
53 changes: 41 additions & 12 deletions src/boot/BootDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1520,12 +1520,19 @@ EFI_STATUS BdInitialize(CHAR8 CONST* loaderOptions)
//
// Already initialised.
//
if (BdSubsystemInitialized || !loaderOptions || !loaderOptions[0])
if (BdSubsystemInitialized || !loaderOptions || !loaderOptions[0]) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if (EFI_ERROR(status))
{
BdpCloseDebuggerDevice();
BdpFreeDataTableEntry(&BdModuleDataTableEntry);
}

return status;
#endif
}

//
// Case on debug type.
Expand All @@ -1550,19 +1557,30 @@ EFI_STATUS BdInitialize(CHAR8 CONST* loaderOptions)
try_leave(status = EFI_SUCCESS);
#else
status = EFI_SUCCESS;

if (EFI_ERROR(status))
{
BdpCloseDebuggerDevice();
BdpFreeDataTableEntry(&BdModuleDataTableEntry);
}

return status;
#endif
}

//
// Setup debug device failed.
//
if (EFI_ERROR(status))
if (EFI_ERROR(status)) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
BdpCloseDebuggerDevice();
BdpFreeDataTableEntry(&BdModuleDataTableEntry);

return status;
#endif
}

//
// Initialise breakpoint table.
Expand All @@ -1574,12 +1592,19 @@ EFI_STATUS BdInitialize(CHAR8 CONST* loaderOptions)
//
BdBreakpointInstruction = KDP_BREAKPOINT_VALUE;
BdDebugTrap = (BdDebugRoutine)&BdTrap;
if (EFI_ERROR(status = BdpPopulateDataTableEntry(&BdModuleDataTableEntry)))
if (EFI_ERROR(status = BdpPopulateDataTableEntry(&BdModuleDataTableEntry))) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
if (EFI_ERROR(status))
{
BdpCloseDebuggerDevice();
BdpFreeDataTableEntry(&BdModuleDataTableEntry);
}

return status;
#endif
}

//
// Link debugger module to modules list.
Expand All @@ -1592,12 +1617,16 @@ EFI_STATUS BdInitialize(CHAR8 CONST* loaderOptions)
//
// Initialise arch.
//
if (EFI_ERROR(status = BdArchInitialize()))
if (EFI_ERROR(status = BdArchInitialize())) {
#if defined(_MSC_VER)
try_leave(NOTHING);
try_leave(NOTHING);
#else
return -1;
BdpCloseDebuggerDevice();
BdpFreeDataTableEntry(&BdModuleDataTableEntry);

return status;
#endif
}

//
// Start debugger.
Expand Down
Loading

0 comments on commit bc625bb

Please sign in to comment.