Skip to content

Commit 00210fa

Browse files
[APPLETV][FREELDR] Misc code cleanup
1 parent 7777ee0 commit 00210fa

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed

boot/freeldr/freeldr/arch/i386/appletv/appletvhw.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ extern UCHAR PcBiosDiskCount; /* hwdisk.c */
2424
extern UINT32 FreeldrDescCount; /* appletvmem.c */
2525
extern BIOS_MEMORY_MAP BiosMap[MAX_BIOS_DESCRIPTORS]; /* appletvmem.c */
2626

27-
extern USHORT WinLdrDetectVersion(VOID);
28-
2927
BOOLEAN AcpiPresent = FALSE;
3028

31-
EFI_SYSTEM_TABLE *GlobalSystemTable;
29+
static unsigned int delay_count = 1;
30+
31+
PCHAR GetHarddiskIdentifier(UCHAR DriveNumber); /* hwdisk.c */
32+
USHORT WinLdrDetectVersion(VOID); /* winldr.c */
3233

3334
/* Maximum number of COM and LPT ports */
3435
#define MAX_COM_PORTS 4
@@ -94,11 +95,6 @@ EFI_SYSTEM_TABLE *GlobalSystemTable;
9495
#define HZ (100)
9596
#define LATCH (CLOCK_TICK_RATE / HZ)
9697

97-
static unsigned int delay_count = 1;
98-
99-
PCHAR
100-
GetHarddiskIdentifier(UCHAR DriveNumber); /* hwdisk.c */
101-
10298
#define SMBIOS_TABLE_GUID \
10399
{ \
104100
0xeb9d2d31, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } \
@@ -165,6 +161,7 @@ WaitFor8254Wraparound(VOID)
165161
while (Delta < 300);
166162
}
167163

164+
static
168165
PVOID
169166
FindUefiVendorTable(EFI_SYSTEM_TABLE *SystemTable, EFI_GUID Guid)
170167
{
@@ -836,25 +833,29 @@ DetectAcpiBios(PCONFIGURATION_COMPONENT_DATA SystemKey, ULONG *BusNumber)
836833
ULONG TableSize;
837834
USHORT WindowsVersion = 0;
838835
EFI_SYSTEM_TABLE *SystemTable;
836+
EFI_GUID Guid;
839837

840838
SystemTable = (EFI_SYSTEM_TABLE *) BootArgs->EfiSystemTable;
841839

842840
// Detect what version of NT we're running
841+
// Note: This information should probably be passed into HwDetect
843842
WindowsVersion = WinLdrDetectVersion();
844843
ASSERT(WindowsVersion != 0);
845844

846845
if (WindowsVersion >= _WIN32_WINNT_WINXP)
847846
{
848847
// Windows XP and later: Use ACPI 2.0 table.
849-
Rsdp = FindUefiVendorTable(SystemTable, (EFI_GUID) EFI_ACPI_20_TABLE_GUID);
848+
Guid = (EFI_GUID) EFI_ACPI_20_TABLE_GUID;
850849
}
851850
else
852851
{
853852
// Windows 2000 and earlier: Use ACPI 1.0 table.
854-
// Note: This breaks reboot and shutdown on the Apple TV and may be completely broken on newer
853+
// Note: This breaks software reboot on the Apple TV and may be completely broken on newer
855854
// devices.
856-
Rsdp = FindUefiVendorTable(SystemTable, (EFI_GUID) ACPI_10_TABLE_GUID);
855+
Guid = (EFI_GUID) ACPI_10_TABLE_GUID;
857856
}
857+
858+
Rsdp = FindUefiVendorTable(SystemTable, Guid);
858859

859860
if (Rsdp)
860861
{
@@ -1093,7 +1094,7 @@ DetectSmBios(VOID)
10931094
// Note: On most hardware, low memory is read-only and must be unlocked using either the
10941095
// EFI Legacy Region Protocol or PAM/MTRR; see UefiSeven/CSMWrap.
10951096
// The Apple TV is a notable exception.
1096-
memcpy((PVOID) SMBIOS_TABLE_LOW, SmBiosTable, sizeof(SMBIOS_TABLE_HEADER));
1097+
RtlCopyMemory((PVOID) SMBIOS_TABLE_LOW, SmBiosTable, sizeof(SMBIOS_TABLE_HEADER));
10971098
}
10981099

10991100
PCONFIGURATION_COMPONENT_DATA

boot/freeldr/freeldr/arch/i386/appletv/appletvmem.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ AddMemoryDescriptor(
2626
IN PFN_NUMBER PageCount,
2727
IN TYPE_OF_MEMORY MemoryType);
2828

29-
// we love statically allocated memory, don't we? :D
29+
// BIOS/E820 memory map, this is passed to Windows for ACPI support
3030
BIOS_MEMORY_MAP BiosMap[MAX_BIOS_DESCRIPTORS];
3131
UINT32 BiosMapNumberOfEntries = 0;
3232

@@ -193,6 +193,9 @@ BiosConvertToFreeldrType(BIOS_MEMORY_TYPE MemoryType)
193193
{
194194
case BiosMemoryUsable:
195195
return LoaderFree;
196+
// FIXME: does this break real hardware?
197+
case BiosMemoryAcpiReclaim:
198+
return LoaderFirmwareTemporary;
196199
case BiosMemoryReserved:
197200
return LoaderFirmwarePermanent;
198201
default:
@@ -208,8 +211,8 @@ BiosAddMemoryRegion(PBIOS_MEMORY_MAP MemoryMap,
208211
UINT64 Size,
209212
BIOS_MEMORY_TYPE Type)
210213
{
211-
UINT32 x = *BiosNumberOfEntries;
212-
if (x == MAX_BIOS_DESCRIPTORS)
214+
UINT32 NumEntries = *BiosNumberOfEntries;
215+
if (NumEntries == MAX_BIOS_DESCRIPTORS)
213216
{
214217
ERR("Too many entries!\n");
215218
FrLdrBugCheckWithMessage(
@@ -219,17 +222,17 @@ BiosAddMemoryRegion(PBIOS_MEMORY_MAP MemoryMap,
219222
"Cannot create more than 80 BIOS memory descriptors!");
220223
}
221224
// Add on to existing entry if we can
222-
if ((x > 0)
223-
&& (MemoryMap[x - 1].BaseAddress + MemoryMap[x - 1].Length == Start)
224-
&& (MemoryMap[x - 1].Type == Type))
225+
if ((NumEntries > 0)
226+
&& (MemoryMap[NumEntries - 1].BaseAddress + MemoryMap[NumEntries - 1].Length == Start)
227+
&& (MemoryMap[NumEntries - 1].Type == Type))
225228
{
226-
MemoryMap[x - 1].Length += Size;
229+
MemoryMap[NumEntries - 1].Length += Size;
227230
}
228231
else
229232
{
230-
MemoryMap[x].BaseAddress = Start;
231-
MemoryMap[x].Length = Size;
232-
MemoryMap[x].Type = Type;
233+
MemoryMap[NumEntries].BaseAddress = Start;
234+
MemoryMap[NumEntries].Length = Size;
235+
MemoryMap[NumEntries].Type = Type;
233236
(*BiosNumberOfEntries)++;
234237
}
235238
}
@@ -301,16 +304,10 @@ AppleTVMemGetMemoryMap(ULONG *MemoryMapSize)
301304
BiosConvertToFreeldrMap(BiosMapPtr,
302305
BiosMapNumberOfEntries);
303306

304-
// reserve some ranges to prevent windows bugs
305-
SetMemory(FreeldrMemMap, 0x000000, 0x01000, LoaderFirmwarePermanent); // Realmode IVT / BDA
306-
SetMemory(FreeldrMemMap, 0x0A0000, 0x50000, LoaderFirmwarePermanent); // Video memory
307-
SetMemory(FreeldrMemMap, 0x0F0000, 0x10000, LoaderSpecialMemory); // ROM
308-
SetMemory(FreeldrMemMap, 0xFFF000, 0x01000, LoaderSpecialMemory); // unusable memory (do we really need this?)
307+
// The first page should be reserved.
308+
SetMemory(FreeldrMemMap, 0x000000, 0x01000, LoaderSpecialMemory); // Realmode IVT / BDA
309309

310310
*MemoryMapSize = PcMemFinalizeMemoryMap(FreeldrMemMap);
311-
312-
// Prevent BootArgs from being overwritten (can this even happen?)
313-
SetMemory(FreeldrMemMap, (ULONG_PTR)BootArgs, sizeof(MACH_BOOTARGS), LoaderFirmwareTemporary);
314-
311+
315312
return FreeldrMemMap;
316313
}

0 commit comments

Comments
 (0)