Skip to content

Commit

Permalink
[CODEREVIEW]
Browse files Browse the repository at this point in the history
Co-authored-by: Hermès BÉLUSCA - MAÏTO <[email protected]>
  • Loading branch information
DarkFire01 and HBelusca committed Oct 11, 2023
1 parent e04cbd3 commit a250e95
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 60 deletions.
17 changes: 6 additions & 11 deletions boot/freeldr/freeldr/arch/uefi/amd64/uefiasm.S
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ _exituefi:
push rdi
push rbx


/* Save the old stack */
mov rbx, rsp

Expand All @@ -46,6 +45,12 @@ _exituefi:
pop rsi
pop rbp

#ifdef _USE_ML
lgdt fword ptr [_gdtptr]
#else
lgdt cs:[_gdtptr][rip] /* GAS isn't my friend - avoid letting it generate absolute addressing */
#endif

/* All done */
ret

Expand All @@ -58,16 +63,6 @@ _changestack:
call ExecuteLoaderCleanly[rip]
ret

// void _changegdt(VOID)
PUBLIC _changegdt
_changegdt:
#ifdef _USE_ML
lgdt fword ptr [_gdtptr]
#else
lgdt cs:[_gdtptr][rip] /* GAS isn't my friend - avoid letting it generate absolute addressing */
#endif
ret

.align 8
gdt:
.word HEX(0000), HEX(0000), HEX(0000), HEX(0000) /* 00: NULL descriptor */
Expand Down
7 changes: 7 additions & 0 deletions boot/freeldr/freeldr/arch/uefi/i386/uefiasm.S
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ __exituefi:
pop esi
pop ebp

#ifdef _USE_ML
lidt fword ptr ds:[_i386idtptr]
lgdt fword ptr [_gdtptr]
#else
lgdt cs:[_gdtptr]
lidt _i386idtptr
#endif

/* All done */
ret
Expand Down
2 changes: 1 addition & 1 deletion boot/freeldr/freeldr/arch/uefi/uefildr.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ VOID __cdecl Reboot(VOID)
WARN("Stopping freeloader something has gone wrong - Freezing");
for(;;)
{

NOTHING;
}
}
#endif
49 changes: 2 additions & 47 deletions boot/freeldr/freeldr/arch/uefi/uefimem.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ EFI_HANDLE PublicBootHandle;
PVOID ExitStack;
PVOID EndofExitStack;

void _changegdt(VOID);
void _exituefi(VOID);

/* FUNCTIONS *****************************************************************/
Expand Down Expand Up @@ -89,56 +88,13 @@ VOID
UefiSetMemory(
_Inout_ PFREELDR_MEMORY_DESCRIPTOR MemoryMap,
_In_ ULONG_PTR BaseAddress,
_In_ PFN_COUNT Size,
_In_ PFN_COUNT SizeInPages,
_In_ TYPE_OF_MEMORY MemoryType)
{
ULONG_PTR BasePage, PageCount;

BasePage = BaseAddress / EFI_PAGE_SIZE;
PageCount = Size;

/* Add the memory descriptor */
FreeldrDescCount = AddMemoryDescriptor(MemoryMap,
UNUSED_MAX_DESCRIPTOR_COUNT,
BasePage,
PageCount,
MemoryType);
}

VOID
ReserveMemory(
_Inout_ PFREELDR_MEMORY_DESCRIPTOR MemoryMap,
_In_ ULONG_PTR BaseAddress,
_In_ PFN_NUMBER Size,
_In_ TYPE_OF_MEMORY MemoryType,
_In_ PCHAR Usage)
{
ULONG_PTR BasePage, PageCount;
ULONG i;

BasePage = BaseAddress / PAGE_SIZE;
PageCount = ADDRESS_AND_SIZE_TO_SPAN_PAGES(BaseAddress, Size);

for (i = 0; i < FreeldrDescCount; i++)
{
/* Check for conflicting descriptor */
if ((MemoryMap[i].BasePage < BasePage + PageCount) &&
(MemoryMap[i].BasePage + MemoryMap[i].PageCount > BasePage))
{
/* Check if the memory is free */
if (MemoryMap[i].MemoryType != LoaderFree)
{
FrLdrBugCheckWithMessage(
MEMORY_INIT_FAILURE,
__FILE__,
__LINE__,
"Failed to reserve memory in the range 0x%Ix - 0x%Ix for %s",
BaseAddress,
Size,
Usage);
}
}
}
PageCount = SizeInPages;

/* Add the memory descriptor */
FreeldrDescCount = AddMemoryDescriptor(MemoryMap,
Expand Down Expand Up @@ -327,5 +283,4 @@ VOID
UefiPrepareForReactOS(VOID)
{
_exituefi();
_changegdt();
}
6 changes: 5 additions & 1 deletion boot/freeldr/freeldr/uefi.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ add_executable(uefildr ${UEFILDR_BASE_SOURCE})
set_target_properties(uefildr PROPERTIES SUFFIX ".efi")

target_compile_definitions(uefildr PRIVATE UEFIBOOT)
set_image_base(uefildr 0x10000)

# On AMD64 we only map 1GB with freeloader, tell UEFI to keep us low!
if(ARCH STREQUAL "amd64")
set_image_base(uefildr 0x10000)
endif()

if(MSVC)
if(NOT ARCH STREQUAL "arm")
Expand Down

0 comments on commit a250e95

Please sign in to comment.