Author: ion
Date: Wed Feb 15 00:53:15 2017
New Revision: 73801
URL:
http://svn.reactos.org/svn/reactos?rev=73801&view=rev
Log:
[BOOTLIB]: Fix assembly file containing Archx86TransferTo32BitApplicationAsm to use
assume:nothing, otherwise we end up with SS segment overrides everywhere.
[BOOTLIB]: Correctly bias access to GDT/IDT registers by 2 bytes since this is a 48-bit
instruction. The loaded GDT/IDT was previously invalid and causing random GPFs.
[BOOTLIB]: Fix EfiStall in protected mode. It was previously not stalling.
[BOOTLIB]: Fix calculation in MmMapPhysicalAddress
[BOOTLIB]: Fix missing goto in MmSelectMappingAddress which broke the function in real
mode.
[BOOTLIB]: Fix incorrect ranges in MmSelectMappingAddress.
[BOOTLIB]: Fix incorrect offset calculation in MmSelectMappingAddress.
Now hitting (as expected), unimplemented virtual code path in BlMmMapPhysicalAddressEx.
Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/arch/i386/transfer.s
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c
Modified: trunk/reactos/boot/environ/include/bl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
==============================================================================
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Wed Feb 15 00:53:15 2017
@@ -2014,6 +2014,11 @@
/* MEMORY DESCRIPTOR ROUTINES ************************************************/
+VOID
+MmMdDbgDumpList (
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+);
+
VOID
MmMdInitializeList (
_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
Modified: trunk/reactos/boot/environ/lib/arch/i386/transfer.s
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/arch/i386…
==============================================================================
--- trunk/reactos/boot/environ/lib/arch/i386/transfer.s [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/arch/i386/transfer.s [iso-8859-1] Wed Feb 15 00:53:15
2017
@@ -21,6 +21,7 @@
/* FUNCTIONS ****************************************************************/
.code
+ASSUME nothing
PUBLIC _Archx86TransferTo32BitApplicationAsm
_Archx86TransferTo32BitApplicationAsm:
@@ -39,10 +40,10 @@
mov ebx, esp
/* Save current GDT/IDT, then load new one */
- sgdt _GdtRegister
- sidt _IdtRegister
- lgdt _BootAppGdtRegister
- lidt _BootAppIdtRegister
+ sgdt _GdtRegister+2
+ sidt _IdtRegister+2
+ lgdt _BootAppGdtRegister+2
+ lidt _BootAppIdtRegister+2
/* Load the new stack */
xor ebp, ebp
@@ -62,8 +63,8 @@
mov esp, ebx
/* Restore old GDT/IDT */
- lgdt _GdtRegister
- lidt _IdtRegister
+ lgdt _GdtRegister+2
+ lidt _IdtRegister+2
/* Retore old segments */
pop ds
Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/…
==============================================================================
--- trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/firmware/efi/firmware.c [iso-8859-1] Wed Feb 15
00:53:15 2017
@@ -646,8 +646,8 @@
OldMode = CurrentExecutionContext->Mode;
if (OldMode != BlRealMode)
{
- /* FIXME: Not yet implemented */
- return STATUS_NOT_IMPLEMENTED;
+ /* Switch to real mode */
+ BlpArchSwitchContext(BlProtectedMode);
}
/* Make the EFI call */
@@ -1406,6 +1406,7 @@
/* Initialize EFI memory map attributes */
EfiMemoryMapSize = MapKey = DescriptorSize = DescriptorVersion = 0;
+ LibraryBuffer = NULL;
/* Increment the nesting depth */
MmDescriptorCallTreeCount++;
Modified: trunk/reactos/boot/environ/lib/io/display/display.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/displa…
==============================================================================
--- trunk/reactos/boot/environ/lib/io/display/display.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/display/display.c [iso-8859-1] Wed Feb 15 00:53:15
2017
@@ -460,7 +460,6 @@
!(GraphicsConsole) ||
!(((PBL_GRAPHICS_CONSOLE_VTABLE)GraphicsConsole->TextConsole.Callbacks)->IsEnabled(GraphicsConsole)))
{
- EfiPrintf(L"Nothing to do for re-init\r\n");
return Status;
}
Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descri…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c [iso-8859-1] Wed Feb 15 00:53:15 2017
@@ -149,8 +149,8 @@
_In_ ULONG Count
)
{
- EfiPrintf(L"dynamic switch NOT SUPPORTED!!!\r\n");
- while (1);
+ EfiPrintf(L"Dynamic switch NOT SUPPORTED!!!\r\n");
+ EfiStall(10000000);
}
NTSTATUS
@@ -173,7 +173,8 @@
else
{
/* It's a dynamic descriptor, so free it */
- EfiPrintf(L"Dynamic descriptors not yet supported\r\n");
+ EfiPrintf(L"Freeing dynamic descriptors not yet supported\r\n");
+ EfiStall(10000000);
Status = STATUS_NOT_IMPLEMENTED;
}
@@ -1043,7 +1044,6 @@
/* Check for start overflow */
if (BaseMin > BaseMax)
{
- EfiPrintf(L"Descriptor overflow\r\n");
return FALSE;
}
@@ -1145,7 +1145,7 @@
/* Loop every current global descriptor */
while (Index < MmGlobalMemoryDescriptorsUsed)
{
- /* Does it have any valid pageS? */
+ /* Does it have any valid pages? */
OldDescriptor = &MmGlobalMemoryDescriptors[Index];
if (OldDescriptor->PageCount)
{
Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/m…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c [iso-8859-1] Wed Feb 15 00:53:15 2017
@@ -497,7 +497,7 @@
_In_ ULONG CacheAttributes
)
{
- ULONGLONG Size, TotalSize;
+ ULONGLONG Size;
ULONGLONG PhysicalAddress;
PVOID VirtualAddress;
PHYSICAL_ADDRESS TranslatedAddress;
@@ -541,13 +541,13 @@
VirtualAddress = (PVOID)PAGE_ROUND_DOWN(VirtualAddress);
/* Round up the size */
- TotalSize = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart -
- PhysicalAddress +
- Size);
+ Size = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart -
+ PhysicalAddress +
+ Size);
/* Loop every virtual page */
CurrentAddress = (ULONG_PTR)VirtualAddress;
- VirtualAddressEnd = CurrentAddress + TotalSize - 1;
+ VirtualAddressEnd = CurrentAddress + Size - 1;
while (CurrentAddress < VirtualAddressEnd)
{
/* Get the physical page of this virtual page */
@@ -564,6 +564,7 @@
EfiPrintf(L"Existing mapping exists: %lx vs %lx\r\n",
TranslatedAddress.QuadPart,
PhysicalAddress + (CurrentAddress -
(ULONG_PTR)VirtualAddress));
+ EfiStall(10000000);
return STATUS_INVALID_PARAMETER;
}
}
@@ -636,6 +637,44 @@
/* Return back to caller */
return Status;
+}
+
+VOID
+MmMdDbgDumpList (
+ _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+ )
+{
+ ULONGLONG EndPage, VirtualEndPage;
+ PBL_MEMORY_DESCRIPTOR MemoryDescriptor;
+ PLIST_ENTRY NextEntry;
+
+ NextEntry = DescriptorList->First->Flink;
+ while (NextEntry != DescriptorList->First)
+ {
+ MemoryDescriptor = CONTAINING_RECORD(NextEntry,
+ BL_MEMORY_DESCRIPTOR,
+ ListEntry);
+
+ EndPage = MemoryDescriptor->BasePage + MemoryDescriptor->PageCount;
+ if (MemoryDescriptor->VirtualPage != 0)
+ {
+ VirtualEndPage = MemoryDescriptor->VirtualPage +
MemoryDescriptor->PageCount;
+ }
+ else
+ {
+ VirtualEndPage = 0;
+ }
+
+ EfiPrintf(L"%p - [%08llx-%08llx @ %08llx-%08llx]:%x\r\n",
+ MemoryDescriptor,
+ MemoryDescriptor->BasePage << PAGE_SHIFT,
+ (EndPage << PAGE_SHIFT) - 1,
+ MemoryDescriptor->VirtualPage << PAGE_SHIFT,
+ VirtualEndPage ? (VirtualEndPage << PAGE_SHIFT) - 1 : 0,
+ (ULONG)MemoryDescriptor->Type);
+
+ NextEntry = NextEntry->Flink;
+ }
}
NTSTATUS
@@ -1126,7 +1165,7 @@
MmArchKsegAddressRange.Maximum = (ULONGLONG)~0;
/* Set the boot application top maximum */
- MmArchTopOfApplicationAddressSpace = 0x70000000;
+ MmArchTopOfApplicationAddressSpace = 0x70000000 - 1; // Windows bug
/* Initialize virtual address space translation */
Status = MmDefInitializeTranslation(MemoryData, TranslationType);
Modified: trunk/reactos/boot/environ/lib/mm/mm.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?r…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/mm.c [iso-8859-1] Wed Feb 15 00:53:15 2017
@@ -196,7 +196,6 @@
MapSize = Size;
CacheAttributes = ((Flags & BlMemoryValidCacheAttributeMask) != 0x20) ?
(Flags & BlMemoryValidCacheAttributeMask) : 0;
- EfiPrintf(L"Selected address: %p for %lx\r\n", MappingAddress,
MappedAddress.LowPart);
Status = MmMapPhysicalAddress(&MappedAddress,
&MappingAddress,
&MapSize,
@@ -215,7 +214,7 @@
if (MmTranslationType != BlNone)
{
/* We don't support virtual memory yet @TODO */
- EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__);
+ EfiPrintf(L"not yet implemented in BlMmMapPhysicalAddressEx\r\n");
EfiStall(1000000);
Status = STATUS_NOT_IMPLEMENTED;
goto Quickie;
Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pageal…
==============================================================================
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c [iso-8859-1] Wed Feb 15 00:53:15 2017
@@ -126,8 +126,8 @@
FoundDescriptor = CONTAINING_RECORD(NextEntry,
BL_MEMORY_DESCRIPTOR,
ListEntry);
-
- /* See if it matches the request */
+
+ /* See if it matches the request */
if (MmMdFindSatisfyingRegion(FoundDescriptor,
&LocalDescriptor,
Request->Pages,
@@ -1082,7 +1082,7 @@
/* Handle virtual memory scenario */
if (MmTranslationType != BlNone)
{
- EfiPrintf(L"Unimplemented virtual path\r\n");
+ EfiPrintf(L"Unimplemented free virtual path\r\n");
return STATUS_SUCCESS;
}
@@ -1519,6 +1519,7 @@
{
/* Just return the physical address as the mapping address */
PreferredAddress = (PVOID)PhysicalAddress.LowPart;
+ goto Success;
}
/* If no physical address, or caller wants a fixed address... */
@@ -1532,14 +1533,15 @@
if (AllocationAttributes & BlMemoryKernelRange)
{
/* Use kernel range */
- Request.BaseRange = MmArchKsegAddressRange;
+ Request.BaseRange.Minimum = MmArchKsegAddressRange.Minimum >> PAGE_SHIFT;
+ Request.BaseRange.Maximum = MmArchKsegAddressRange.Maximum >> PAGE_SHIFT;
Request.Type = BL_MM_REQUEST_DEFAULT_TYPE;
}
else
{
/* User user/application range */
- Request.BaseRange.Minimum = 0;
- Request.BaseRange.Maximum = MmArchTopOfApplicationAddressSpace;
+ Request.BaseRange.Minimum = 0 >> PAGE_SHIFT;
+ Request.BaseRange.Maximum = MmArchTopOfApplicationAddressSpace >>
PAGE_SHIFT;
Request.Type = BL_MM_REQUEST_TOP_DOWN_TYPE;
}
@@ -1569,8 +1571,7 @@
{
/* Add the offset to the returned virtual address */
PreferredAddress = (PVOID)((ULONG_PTR)PreferredAddress +
- PhysicalAddress.LowPart -
- BYTE_OFFSET(PhysicalAddress.LowPart));
+ BYTE_OFFSET(PhysicalAddress.QuadPart));
}
Success: