[ros-diffs] [ion] 74546: BL Library now works 100% in paging, protected mode. A picture is worth a thousand commits: http://i.imgur.com/Zx2nQ6x.jpg [BOOTLIB]: Add support for protocol open/close/looku

2017-05-14 Thread ion
Author: ion
Date: Mon May 15 01:38:49 2017
New Revision: 74546

URL: http://svn.reactos.org/svn/reactos?rev=74546=rev
Log:
BL Library now works 100% in paging, protected mode. A picture is worth a 
thousand commits: http://i.imgur.com/Zx2nQ6x.jpg
[BOOTLIB]: Add support for protocol open/close/lookup while paging and 
protected mode is enabled.
[BOOTLIB]: Implement support for dozens of UEFI functions while under protected 
mode.
[BOOTLIB]: Fix bugs in existing UEFI functions which were switching to 
_protected_ mode instead of _real mode_ before making the UEFI call.
[BOOTLIB]: Free dynamic descriptor in MmMdFreeDescriptor.
[BOOTLIB]: Implement BlHtDelete.
[BOOTLIB]: Implement re-initialize-all path in DsppInitialize.
[BOOTLIB]: Fix small bug in BlDisplayInvalidateOemBitmap
[BOOTLIB]: Fix bigger bug in BlDisplayGetOemBitmap :)

Modified:
trunk/reactos/boot/environ/app/rosload/rosload.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/io/display/efi/gop.c
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/platform/time.c

[This mail would be too long, it was shortened to contain the URLs only.]

Modified: trunk/reactos/boot/environ/app/rosload/rosload.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/rosload/rosload.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/io/display/display.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/display/display.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/io/display/efi/gop.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/display/efi/gop.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/misc/util.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/util.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=74546=74545=74546=diff

Modified: trunk/reactos/boot/environ/lib/platform/time.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/platform/time.c?rev=74546=74545=74546=diff




[ros-diffs] [ion] 74545: Virtual memory works baby! Virtual Heap at 0x80000000 fully enabled. Next up, EFI Protocols with Paging Enabled. [BOOTLIB]: Fix dumb bug in BlMmIsTranslationEnabled which woul

2017-05-14 Thread ion
Author: ion
Date: Sun May 14 16:07:21 2017
New Revision: 74545

URL: http://svn.reactos.org/svn/reactos?rev=74545=rev
Log:
Virtual memory works baby! Virtual Heap at 0x8000 fully enabled. Next up, 
EFI Protocols with Paging Enabled.
[BOOTLIB]: Fix dumb bug in BlMmIsTranslationEnabled which would always return 
FALSE.
[BOOTLIB]: Fix dumber bug in MmDefInitializeTranslation which was freeing the 
page directories and self-map pages even in the success path. Causing us to 
zero out paging structures...
[BOOTLIB]: Cleanup and extend MmMdDbgDumpList for internal use, and add 
MmMdListPointerToName as another debug function.
[BOOTLIB]: Add a few more checkpoints in unimplemented paths.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.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?rev=74545=74544=74545=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun May 14 
16:07:21 2017
@@ -2023,9 +2023,10 @@
 
 VOID
 MmMdDbgDumpList (
-_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList
+_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+_In_opt_ ULONG MaxCount
 );
-
+
 VOID
 MmMdInitializeList (
 _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=74545=74544=74545=diff
==
--- 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] 
Sun May 14 16:07:21 2017
@@ -176,6 +176,8 @@
 {
 /* We need complex tracking to make this work */
 //Status = EfiVmOpenProtocol(Handle, Protocol, Interface);
+EfiPrintf(L"Paging path hit!\r\n");
+EfiStall(100);
 Status = STATUS_NOT_SUPPORTED;
 }
 else
@@ -185,6 +187,8 @@
 if (OldMode != BlRealMode)
 {
 /* FIXME: Not yet implemented */
+EfiPrintf(L"Paging path hit!\r\n");
+EfiStall(100);
 return STATUS_NOT_IMPLEMENTED;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=74545=74544=74545=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Sun May 14 
16:07:21 2017
@@ -1267,7 +1267,7 @@
 /* Don't let the base overflow */
 if (VirtualMin > VirtualMax)
 {
-return 0;
+return FALSE;
 }
 
 /* Adjust the base by the alignment delta */
@@ -1277,7 +1277,7 @@
 if (((VirtualMin + Pages - 1) < VirtualMin) ||
 ((VirtualMin + Pages - 1) > VirtualMax))
 {
-return 0;
+return FALSE;
 }
 
 /* Finally, pick the correct address based on direction */
@@ -1302,7 +1302,7 @@
 if Flags & 0xFF) & (Descriptor->Flags & 0xFF)) != (Flags & 0xFF)) ||
 (((Flags & 0xFF00) & (Descriptor->Flags & 0xFF00)) != (Flags & 
0xFF00)))
 {
-EfiPrintf(L"Incorrect memory attributes\r\n");
+//EfiPrintf(L"Incorrect memory attributes\r\n");
 return FALSE;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/heapalloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/heapalloc.c?rev=74545=74544=74545=diff
==
--- trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] Sun May 14 
16:07:21 2017
@@ -155,6 +155,8 @@
0);
 if (!NT_SUCCESS(Status))
 {
+EfiPrintf(L"HEAP ALLOCATION FAILED\r\n");
+EfiStall(100);
 return Status;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=74545=74544=74545=diff
==
--- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c  [iso-8859-

[ros-diffs] [ion] 74542: [BOOTLIB]: Implement MmMdTruncateDescriptors [BOOTLIB]: Implement MmPaTruncateMemory and call it during paging initialization to remove > 4GB memory.c [BOOTLIB]: Implement Blp

2017-05-13 Thread ion
Author: ion
Date: Sun May 14 00:39:30 2017
New Revision: 74542

URL: http://svn.reactos.org/svn/reactos?rev=74542=rev
Log:
[BOOTLIB]: Implement MmMdTruncateDescriptors
[BOOTLIB]: Implement MmPaTruncateMemory and call it during paging 
initialization to remove > 4GB memory.c
[BOOTLIB]: Implement BlpMmInitializeConstraints if those BCD options are used.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.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?rev=74542=74541=74542=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun May 14 
00:39:30 2017
@@ -2088,6 +2088,13 @@
 _In_ ULONG Flags
 );
 
+NTSTATUS
+MmMdTruncateDescriptors (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
+_In_ PBL_MEMORY_DESCRIPTOR_LIST NewList,
+_In_ ULONGLONG BasePage
+);
+
 VOID
 MmMdRemoveDescriptorFromList (
 _In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
@@ -2122,6 +2129,11 @@
 );
 
 /* PAGE ALLOCATOR ROUTINES ***/
+
+NTSTATUS
+MmPaTruncateMemory (
+_In_ ULONGLONG BasePage
+);
 
 NTSTATUS
 BlMmAllocatePhysicalPages(

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=74542=74541=74542=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Sun May 14 
00:39:30 2017
@@ -406,6 +406,82 @@
 /* Increment the count and return the descriptor */
 MmGlobalMemoryDescriptorsUsed++;
 return MemoryDescriptor;
+}
+
+NTSTATUS
+MmMdTruncateDescriptors (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
+_In_ PBL_MEMORY_DESCRIPTOR_LIST NewList,
+_In_ ULONGLONG BasePage
+)
+{
+PLIST_ENTRY ListHead, NextEntry;
+PBL_MEMORY_DESCRIPTOR Descriptor, NewDescriptor;
+ULONGLONG FoundEndPage;
+
+/* Search the descriptor list */
+ListHead = MdList->First;
+NextEntry = ListHead->Flink;
+while (NextEntry != ListHead)
+{
+/* Get the current descriptor */
+Descriptor = CONTAINING_RECORD(NextEntry,
+   BL_MEMORY_DESCRIPTOR,
+   ListEntry);
+
+/* Go to the next entry in case we have to remove */
+NextEntry = NextEntry->Flink;
+
+/* Don't touch anything else but free RAM */
+if (((Descriptor->Type >> BL_MEMORY_CLASS_SHIFT) == BlSystemClass) &&
+(Descriptor->Type != BlConventionalMemory))
+{
+continue;
+}
+
+/* Check if this page is within the descriptor's region */
+FoundEndPage = Descriptor->BasePage + Descriptor->PageCount;
+if (BasePage > Descriptor->BasePage)
+{
+/* Check if it doesn't go beyond the descriptor */
+if (BasePage < FoundEndPage)
+{
+/* Create a new descriptor to describe this region */
+EfiPrintf(L"Truncating descriptor type %lx base: %llx end: 
%llx\r\n",
+  Descriptor->Type, Descriptor->BasePage, 
FoundEndPage);
+NewDescriptor = 
MmMdInitByteGranularDescriptor(Descriptor->Flags,
+   
Descriptor->Type,
+   BasePage,
+   0,
+   FoundEndPage - 
BasePage);
+if (!NewDescriptor)
+{
+return STATUS_NO_MEMORY;
+}
+
+/* Cut off this descriptor to make it shorter */
+Descriptor->PageCount = BasePage - Descriptor->BasePage;
+
+/* Add the region to the new list */
+MmMdAddDescriptorToList(NewList,
+NewDescriptor,
+BL_MM_ADD_DESCRIPTOR_COALESCE_FLAG);
+}
+}
+else
+{
+/* This whole descriptor covers the truncated area */
+EfiPrintf(L"Truncating descriptor type %lx base: %llx end: 
%llx\r\n",
+  Descriptor->Type, Descriptor->BasePage, FoundEndPage);
+MmMdRemoveDescriptorFromList(MdList, Descriptor);
+ 

[ros-diffs] [ion] 74541: [BOOTLIB]: Complete implementation of MmMdRemoveRegionFromMdlEx

2017-05-13 Thread ion
Author: ion
Date: Sun May 14 00:11:48 2017
New Revision: 74541

URL: http://svn.reactos.org/svn/reactos?rev=74541=rev
Log:
[BOOTLIB]: Complete implementation of MmMdRemoveRegionFromMdlEx

Modified:
trunk/reactos/boot/environ/lib/mm/descriptor.c

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=74541=74540=74541=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Sun May 14 
00:11:48 2017
@@ -390,6 +390,7 @@
 if (MmGlobalMemoryDescriptorsUsed >= MmGlobalMemoryDescriptorCount)
 {
 EfiPrintf(L"Out of descriptors!\r\n");
+EfiStall(100);
 return NULL;
 }
 
@@ -409,9 +410,9 @@
 
 BOOLEAN
 MmMdpTruncateDescriptor (
-__in PBL_MEMORY_DESCRIPTOR_LIST MdList,
-__in PBL_MEMORY_DESCRIPTOR MemoryDescriptor,
-__in ULONG Flags
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
+_In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor,
+_In_ ULONG Flags
 )
 {
 PBL_MEMORY_DESCRIPTOR NextDescriptor, PreviousDescriptor;
@@ -435,12 +436,14 @@
 if ((PreviousEntry != MdList->First) && (MemoryDescriptor->BasePage < 
PreviousEndPage))
 {
 EfiPrintf(L"Overlap detected -- this is unexpected on x86/x64 
platforms\r\n");
+EfiStall(100);
 }
 
 /* Check for forward overlap */
 if ((NextEntry != MdList->First) && (NextDescriptor->BasePage < EndPage))
 {
 EfiPrintf(L"Overlap detected -- this is unexpected on x86/x64 
platforms\r\n");
+EfiStall(100);
 }
 
 /* Nothing to do */
@@ -449,9 +452,9 @@
 
 BOOLEAN
 MmMdpCoalesceDescriptor (
-__in PBL_MEMORY_DESCRIPTOR_LIST MdList,
-__in PBL_MEMORY_DESCRIPTOR MemoryDescriptor,
-__in ULONG Flags
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
+_In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor,
+_In_ ULONG Flags
 )
 {
 PBL_MEMORY_DESCRIPTOR NextDescriptor, PreviousDescriptor;
@@ -623,28 +626,25 @@
 BOOLEAN HaveNewList, UseVirtualPage;
 NTSTATUS Status;
 PLIST_ENTRY ListHead, NextEntry;
-PBL_MEMORY_DESCRIPTOR Descriptor;
-//BL_MEMORY_DESCRIPTOR NewDescriptor;
+PBL_MEMORY_DESCRIPTOR Descriptor, NewDescriptor, ListDescriptor;
+BL_MEMORY_DESCRIPTOR OldDescriptor;
 ULONGLONG RegionSize;
-ULONGLONG FoundBasePage, FoundEndPage, FoundPageCount, EndPage;
+ULONGLONG FoundBasePage, FoundEndPage, FoundPageCount, EndPage, 
VirtualPage;
 
 /* Set initial status */
 Status = STATUS_SUCCESS;
+ListDescriptor = NULL;
+NewDescriptor = NULL;
+HaveNewList = FALSE;
 
 /* Check if removed descriptors should go into a new list */
 if (NewMdList != NULL)
 {
 /* Initialize it */
-MmMdInitializeListHead(NewMdList);
-NewMdList->Type = MdList->Type;
+MmMdInitializeList(NewMdList, MdList->Type, NULL);
 
 /* Remember for later */
 HaveNewList = TRUE;
-}
-else
-{
-/* For later */
-HaveNewList = FALSE;
 }
 
 /* Is the region being removed physical? */
@@ -684,7 +684,7 @@
 EndPage = PageCount + BasePage;
 
 /* Make a copy of the original descriptor */
-//NewDescriptor = *Descriptor; // FIXME: Need to use this somewhere...
+OldDescriptor = *Descriptor;
 
 /* Check if the region to be removed starts after the found region 
starts */
 if ((BasePage > FoundBasePage) || (FoundBasePage >= EndPage))
@@ -695,13 +695,14 @@
 /* Check if the found region starts after the region or ends 
before the region */
 if ((FoundBasePage >= BasePage) || (EndPage >= FoundEndPage))
 {
-/* This descriptor doesn't cover any part of the range -- 
nothing to do */
-NOTHING;
+/* This is a fully-mapped descriptor -- change nothing */
+OldDescriptor.PageCount = 0;
 }
 else
 {
 /* This descriptor fully covers the entire allocation */
 FoundBasePage = Descriptor->BasePage;
+VirtualPage = Descriptor->VirtualPage;
 FoundPageCount = BasePage - FoundBasePage;
 
 /* This is how many pages we will eat away from the 
descriptor */
@@ -710,29 +711,40 @@
 /* Update the descriptor to account for the consumed pages 
*/
 Descriptor->BasePage += RegionSize;
 Descriptor->PageCount -= RegionSize;
-if (Descriptor->VirtualPage)
+   

[ros-diffs] [ion] 74536: [BOOTLIB]: Separate free and zero memory, and code vs data runtime data, as newer bootlibs do. [BOOTLIB]: Fix bugs in MmMdpHasPrecedence and cleanup. [BOOTLIB]: Fix bug in MmM

2017-05-13 Thread ion
Author: ion
Date: Sat May 13 19:32:26 2017
New Revision: 74536

URL: http://svn.reactos.org/svn/reactos?rev=74536=rev
Log:
[BOOTLIB]: Separate free and zero memory, and code vs data runtime data, as 
newer bootlibs do.
[BOOTLIB]: Fix bugs in MmMdpHasPrecedence and cleanup.
[BOOTLIB]: Fix bug in MmMdFreeDescriptor.
[BOOTLIB]: Cleanup MmMdpSaveCurrentListPointer.
[BOOTLIB]: Fix bug in MmMdpCoalesceDescriptor.
[BOOTLIB]: Fix multiple bugs in MmMdAddDescriptorToList, and cleanup.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=74536=74535=74536=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sat May 13 
19:32:26 2017
@@ -329,12 +329,14 @@
 BlUnusableMemory = 0xF002,
 BlReservedMemory = 0xF003,
 BlEfiBootMemory = 0xF004,
-BlEfiRuntimeMemory = 0xF006,
+BlConventionalZeroedMemory = 0xF05,
+BlEfiRuntimeCodeMemory = 0xF006,
 BlAcpiReclaimMemory = 0xF008,
 BlAcpiNvsMemory = 0xF009,
 BlDeviceIoMemory = 0xF00A,
 BlDevicePortMemory = 0xF00B,
 BlPalMemory = 0xF00C,
+BlEfiRuntimeDataMemory = 0xF00E,
 } BL_MEMORY_TYPE;
 
 typedef enum _BL_MEMORY_ATTR

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=74536=74535=74536=diff
==
--- 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] 
Sat May 13 19:32:26 2017
@@ -1343,8 +1343,11 @@
 break;
 
 case EfiRuntimeServicesCode:
+OsType = BlEfiRuntimeCodeMemory;
+break;
+
 case EfiRuntimeServicesData:
-OsType = BlEfiRuntimeMemory;
+OsType = BlEfiRuntimeDataMemory;
 break;
 
 case EfiConventionalMemory:

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=74536=74535=74536=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Sat May 13 
19:32:26 2017
@@ -26,13 +26,38 @@
 BlDeviceIoMemory,
 BlDevicePortMemory,
 BlPalMemory,
-BlEfiRuntimeMemory,
+BlEfiRuntimeCodeMemory,
+BlEfiRuntimeDataMemory,
 BlAcpiNvsMemory,
 BlAcpiReclaimMemory,
-BlEfiBootMemory
+BlEfiBootMemory,
+BlConventionalMemory,
+BlConventionalZeroedMemory
 };
 
 /* FUNCTIONS */
+
+LONG
+MmMdpLookupTypePrecedenceIndex (
+_In_ BL_MEMORY_TYPE Type
+)
+{
+ULONG i;
+
+/* Check the precedence array */
+for (i = 0; i < RTL_NUMBER_OF(MmPlatformMemoryTypePrecedence); i++)
+{
+/* Check for a match */
+if (MmPlatformMemoryTypePrecedence[i] == Type)
+{
+/* Return the index */
+return i;
+}
+}
+
+/* Invalid index type */
+return -1;
+}
 
 /* The order is Conventional > Other > System > Loader > Application  */
 BOOLEAN
@@ -44,14 +69,14 @@
 BL_MEMORY_CLASS Class1, Class2;
 ULONG i, j;
 
+/* It isn't free RAM, but the comparator is -- it succeeds it */
+if (Type2 == BlConventionalMemory)
+{
+return TRUE;
+}
+
 /* Descriptor is free RAM -- it precedes */
 if (Type1 == BlConventionalMemory)
-{
-return TRUE;
-}
-
-/* It isn't free RAM, but the comparator is -- it succeeds it */
-if (Type2 == BlConventionalMemory)
 {
 return FALSE;
 }
@@ -77,55 +102,30 @@
 /* Descriptor is system class */
 if (Class1 == BlSystemClass)
 {
-/* And so is the other guy... */
-if (Class2 == BlSystemClass)
-{
-i = 0;
-j = 0;
-
-/* Scan for the descriptor's system precedence index */
-do
-{
-if (MmPlatformMemoryTypePrecedence[j] == Type1)
-{
-break;
-}
-} while (++j < RTL_NUMBER_OF(MmPlatformMemoryTypePrecedence));
-
-/* Use an invalid index if one wasn't found */
-if (j == RTL_NUMBER_OF(MmPlatformMemoryTypePrecedence))
-{
-

[ros-diffs] [ion] 74519: Fully working x86 paging support! [BOOTLIB]: Fix a critical bug in BlpArchSwitchContext which was not switching to Firmware mode once paging was enabled. [BOOTLIB]: Fix a crit

2017-05-10 Thread ion
Author: ion
Date: Wed May 10 14:38:34 2017
New Revision: 74519

URL: http://svn.reactos.org/svn/reactos?rev=74519=rev
Log:
Fully working x86 paging support!
[BOOTLIB]: Fix a critical bug in BlpArchSwitchContext which was not switching 
to Firmware mode once paging was enabled.
[BOOTLIB]: Fix a critical bug in OslMain which was incorrectly setting 
BL_LIBRARY_INITIALIZATION_COMPLETED instead of BL_LIBRARY_FLAG_REINITIALIZE_ALL 
and causing all sorts of failure paths.
[BOOTLIB]: MmDefInitializeTranslation now turns on paging.
[BOOTLIB]: Implement TrpGenerateMappingTracker and BlpArchEnableTranslation
[BOOTLIB]: BlMmMapPhysicalAddressEx now works with paging enabled, and 
correctly finds mapped memory to use from the virtual MDLs.
[BOOTLIB]: MmPapAllocateRegionFromMdl now handles virtual allocations from 
MmMdlMappedUnallocated.
[BOOTLIB]: MmPapAllocatePagesInRange now handles BlMemoryKernelRange (KSEG0) 
allocations.
[BOOTLIB]: MmMdFindSatisfyingRegion now handles virtual descriptors as well, 
and handles alignment better.

Modified:
trunk/reactos/boot/environ/app/rosload/rosload.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/arch/i386/arch.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/app/rosload/rosload.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/rosload/rosload.c?rev=74519=74518=74519=diff
==
--- trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] Wed May 10 
14:38:34 2017
@@ -39,10 +39,11 @@
 /* Setup the boot library parameters for this application */
 BlSetupDefaultParameters();
 LibraryParameters.TranslationType = BlVirtual;
-LibraryParameters.LibraryFlags = BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED;
+LibraryParameters.LibraryFlags = 
BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE |
+ BL_LIBRARY_FLAG_REINITIALIZE_ALL;
 LibraryParameters.MinimumAllocationCount = 1024;
 LibraryParameters.MinimumHeapSize = 2 * 1024 * 1024;
-LibraryParameters.HeapAllocationAttributes = 0x2;
+LibraryParameters.HeapAllocationAttributes = BlMemoryKernelRange;
 LibraryParameters.FontBaseDirectory = L"\\Reactos\\Boot\\Fonts";
 LibraryParameters.DescriptorCount = 512;
 Status = BlInitializeLibrary(BootParameters, );

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=74519=74518=74519=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Wed May 10 
14:38:34 2017
@@ -2005,6 +2005,11 @@
 VOID
 BlpArchSwitchContext (
 _In_ BL_ARCH_MODE NewMode
+);
+
+VOID
+BlpArchEnableTranslation (
+VOID
 );
 
 VOID

Modified: trunk/reactos/boot/environ/lib/arch/i386/arch.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/arch/i386/arch.c?rev=74519=74518=74519=diff
==
--- trunk/reactos/boot/environ/lib/arch/i386/arch.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/arch/i386/arch.c [iso-8859-1] Wed May 10 
14:38:34 2017
@@ -171,7 +171,10 @@
 
 /* In real mode, use EFI, otherwise, use the application mode */
 Context = 
-if (NewMode != BlProtectedMode) Context = 
+if (NewMode != BlRealMode)
+{
+Context = 
+}
 
 /* Are we in a different mode? */
 if (CurrentExecutionContext->Mode != NewMode)
@@ -179,6 +182,40 @@
 /* Switch to the new one */
 ArchSwitchContext(Context, CurrentExecutionContext);
 CurrentExecutionContext = Context;
+}
+}
+
+VOID
+BlpArchEnableTranslation (
+VOID
+)
+{
+PBL_ARCH_CONTEXT Context;
+
+/* Does the current execution context already have paging enabled? */
+Context = CurrentExecutionContext;
+if (!(Context->ContextFlags & BL_CONTEXT_PAGING_ON))
+{
+/* No -- does it have interrupts enabled? */
+if (Context->ContextFlags & BL_CONTEXT_INTERRUPTS_ON)
+{
+/* Disable them */
+_disable();
+Context->ContextFlags &= ~BL_CONTEXT_INTERRUPTS_ON;
+}
+
+/* Are we enabling PAE? */
+if (Context->TranslationType == BlPae)
+{
+/* Make sure CR4 reflects this */
+__writecr4(__readcr4() | CR4_PAE);
+}
+
+/* Enable paging in the CPU */
+__writecr0(__readcr0() | CR0_PG);
+
+/* Reflect that 

[ros-diffs] [ion] 73801: [BOOTLIB]: Fix assembly file containing Archx86TransferTo32BitApplicationAsm to use assume:nothing, otherwise we end up with SS segment overrides everywhere. [BOOTLIB]: Correc

2017-02-14 Thread ion
Author: ion
Date: Wed Feb 15 00:53:15 2017
New Revision: 73801

URL: http://svn.reactos.org/svn/reactos?rev=73801=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?rev=73801=73800=73801=diff
==
--- 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/transfer.s?rev=73801=73800=73801=diff
==
--- 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/efi/firmware.c?rev=73801=73800=73801=diff
==
--- 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/display/display.c?rev=73801=73800=73801=diff
==
--- 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/desc

[ros-diffs] [ion] 73797: [BOOTLIB]: Clarify some attributes now that their meaning is clearer. [BOOTLIB]: Implement MmSelectMappingAddress and fix its prototype. [BOOTLIB]: Implement MmPapPageAllocato

2017-02-13 Thread ion
Author: ion
Date: Mon Feb 13 23:47:06 2017
New Revision: 73797

URL: http://svn.reactos.org/svn/reactos?rev=73797=rev
Log:
[BOOTLIB]: Clarify some attributes now that their meaning is clearer.
[BOOTLIB]: Implement MmSelectMappingAddress and fix its prototype.
[BOOTLIB]: Implement MmPapPageAllocatorExtend and fix MmPapAllocatePagesInRange 
to use it.
We are trying to choose VA 0 for PA 0x8000 and currently fail due to conflicts. 
TBD.

Modified:
trunk/reactos/boot/environ/include/bl.h
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?rev=73797=73796=73797=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb 13 
23:47:06 2017
@@ -362,11 +362,11 @@
 //
 // Memory Allocation Attributes
 //
-BlMemoryUnknown =   0x0001,
-BlMemoryNonFixed =  0x0002,
+BlMemoryLargePages =0x0001,
+BlMemoryKernelRange =   0x0002,
 BlMemoryFixed = 0x0004,
 BlMemoryBelow1MB =  0x0008,
-BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed 
| BlMemoryBelow1MB | BlMemoryUnknown,
+BlMemoryValidAllocationAttributes   = BlMemoryKernelRange | 
BlMemoryFixed | BlMemoryBelow1MB | BlMemoryLargePages,
 BlMemoryValidAllocationAttributeMask= 0x00FF,
 
 //
@@ -2194,6 +2194,7 @@
 NTSTATUS
 MmSelectMappingAddress (
 _Out_ PVOID* MappingAddress,
+_In_ PVOID PreferredAddress,
 _In_ ULONGLONG Size,
 _In_ ULONG AllocationAttributes,
 _In_ ULONG Flags,
@@ -2721,5 +2722,7 @@
 extern BL_MEMORY_DESCRIPTOR_LIST MmMdlMappingTrackers;
 extern ULONGLONG BlpTimePerformanceFrequency;
 extern LIST_ENTRY RegisteredFileSystems;
+extern BL_ADDRESS_RANGE MmArchKsegAddressRange;
+extern ULONG_PTR MmArchTopOfApplicationAddressSpace;
 
 #endif

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=73797=73796=73797=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Mon Feb 13 
23:47:06 2017
@@ -1104,7 +1104,7 @@
 }
 
 /* Bail out if the allocation flags don't match */
-if (((Flags ^ Descriptor->Flags) & (BlMemoryRuntime | BlMemoryBelow1MB | 
BlMemoryUnknown)))
+if (((Flags ^ Descriptor->Flags) & (BlMemoryRuntime | BlMemoryBelow1MB | 
BlMemoryLargePages)))
 {
 //EfiPrintf(L"Incorrect memory allocation flags\r\n");
 return FALSE;

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73797=73796=73797=diff
==
--- 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] Mon Feb 13 
23:47:06 2017
@@ -490,29 +490,6 @@
 }
 
 NTSTATUS
-MmSelectMappingAddress (
-_Out_ PVOID* MappingAddress,
-_In_ ULONGLONG Size,
-_In_ ULONG AllocationAttributes,
-_In_ ULONG Flags,
-_In_ PHYSICAL_ADDRESS PhysicalAddress
-)
-{
-/* Are we in physical mode? */
-if (MmTranslationType == BlNone)
-{
-/* Just return the physical address as the mapping address */
-*MappingAddress = (PVOID)PhysicalAddress.LowPart;
-return STATUS_SUCCESS;
-}
-
-/* We don't support virtual memory yet @TODO */
-EfiPrintf(L"not yet implemented in %S\r\n", __FUNCTION__);
-EfiStall(100);
-return STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS
 MmMapPhysicalAddress (
 _Inout_ PPHYSICAL_ADDRESS PhysicalAddressPtr,
 _Inout_ PVOID* VirtualAddressPtr,

Modified: trunk/reactos/boot/environ/lib/mm/mm.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?rev=73797=73796=73797=diff
==
--- trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] Mon Feb 13 
23:47:06 2017
@@ -164,7 +164,7 @@
 
 /* Check for invalid requirement flag, if one is present */
 if (((Flags & BlMemoryValidAllocationAttributes) != BlMemoryFixed) &&
-((Flags & BlMemoryValidAllocationAttributes) != BlMemoryNonFixed) &&
+((Flags & BlMemoryValidAl

[ros-diffs] [ion] 73742: [BOOTLIB]: Implement MmFwGetMemoryMap when virtual memory is being enabled. [BOOTLIB]: Implement MmPapAllocatePagesInRange when virtual memory is being enabled. What's left no

2017-02-06 Thread ion
Author: ion
Date: Tue Feb  7 04:26:21 2017
New Revision: 73742

URL: http://svn.reactos.org/svn/reactos?rev=73742=rev
Log:
[BOOTLIB]: Implement MmFwGetMemoryMap when virtual memory is being enabled.
[BOOTLIB]: Implement MmPapAllocatePagesInRange when virtual memory is being 
enabled.
What's left now is implementing extension for the PA allocator when VM is 
enabled.

Modified:
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73742=73741=73742=diff
==
--- 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] 
Tue Feb  7 04:26:21 2017
@@ -1402,6 +1402,7 @@
 BL_MEMORY_TYPE MemoryType;
 PBL_MEMORY_DESCRIPTOR Descriptor;
 BL_MEMORY_ATTR Attribute;
+PVOID LibraryBuffer;
 
 /* Initialize EFI memory map attributes */
 EfiMemoryMapSize = MapKey = DescriptorSize = DescriptorVersion = 0;
@@ -1435,7 +1436,6 @@
 if (Status != STATUS_BUFFER_TOO_SMALL)
 {
 /* This should've failed because our buffer was too small, nothing 
else */
-EfiPrintf(L"Got strange EFI status for memory map: %lx\r\n", Status);
 if (NT_SUCCESS(Status))
 {
 Status = STATUS_UNSUCCESSFUL;
@@ -1512,8 +1512,30 @@
 }
 else
 {
-/* We don't support this path yet */
-Status = STATUS_NOT_IMPLEMENTED;
+/* Round the map to pages */
+Pages = BYTES_TO_PAGES(EfiMemoryMapSize);
+
+/* Allocate a large enough buffer */
+Status = MmPapAllocatePagesInRange(,
+   BlLoaderData,
+   Pages,
+   0,
+   0,
+   0,
+   0);
+if (!NT_SUCCESS(Status))
+{
+EfiPrintf(L"Failed to allocate mapped VM for EFI map: %lx\r\n", 
Status);
+goto Quickie;
+}
+
+/* Call EFI to get the memory map */
+EfiMemoryMap = LibraryBuffer;
+Status = EfiGetMemoryMap(,
+ LibraryBuffer,
+ ,
+ ,
+ );
 }
 
 /* So far so good? */
@@ -1786,6 +1808,12 @@
 if (EfiBuffer != 0)
 {
 EfiFreePages(Pages, EfiBuffer);
+}
+
+/* Free the library-allocated buffer, if we had one */
+if (LibraryBuffer != 0)
+{
+MmPapFreePages(LibraryBuffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 }
 
 /* On failure, free the memory map if one was passed in */

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73742=73741=73742=diff
==
--- 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] Tue Feb  7 
04:26:21 2017
@@ -680,9 +680,10 @@
 BL_MEMORY_DESCRIPTOR_LIST FirmwareMdl;
 PLIST_ENTRY Head, NextEntry;
 
-/* In phase 1 we don't initialize deferred mappings*/
+/* Check which phase this is */
 if (Phase == 1)
 {
+/* In phase 1 we don't initialize deferred mappings */
 DoDeferred = FALSE;
 }
 else
@@ -693,6 +694,7 @@
 return STATUS_SUCCESS;
 }
 
+/* We'll do deferred descriptors in phase 2 */
 DoDeferred = TRUE;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=73742=73741=73742=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Tue Feb  7 
04:26:21 2017
@@ -95,7 +95,7 @@
 ULONGLONG LocalEndPage, FoundEndPage, LocalVirtualEndPage;
 
 /* Check if any parameters were not passed in correctly */
-if ( !(CurrentList) || !(Request) || (!(NewList) && !(Descriptor)))
+if (!(CurrentList) || !(Request) || (!(NewList) && !(Descriptor)))
 {
 return STATUS_INVALID_PARAMETER;
 }
@@ -298,8 +298,15 @@
 return Status;
 }
 
-/* Nope, we have to hunt for it elsewhere */
-EfiPrintf(L"TODO\r\n");
+/* Are we failing due to some attributes? */
+if (Request

[ros-diffs] [ion] 73741: [BOOTLIB]: Finish implementing Mmx86pMapMemoryRegions.

2017-02-06 Thread ion
Author: ion
Date: Tue Feb  7 03:34:49 2017
New Revision: 73741

URL: http://svn.reactos.org/svn/reactos?rev=73741=rev
Log:
[BOOTLIB]: Finish implementing Mmx86pMapMemoryRegions.

Modified:
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73741=73740=73741=diff
==
--- 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] Tue Feb  7 
03:34:49 2017
@@ -677,6 +677,8 @@
 ULONGLONG Size;
 NTSTATUS Status;
 PVOID VirtualAddress;
+BL_MEMORY_DESCRIPTOR_LIST FirmwareMdl;
+PLIST_ENTRY Head, NextEntry;
 
 /* In phase 1 we don't initialize deferred mappings*/
 if (Phase == 1)
@@ -756,10 +758,59 @@
 /* In phase 1, also do UEFI mappings */
 if (Phase != 2)
 {
-EfiPrintf(L"Phase 1 TODO UEFI mappings \r\n");
-}
-
-return STATUS_NOT_IMPLEMENTED;
+/* Get the memory map */
+MmMdInitializeListHead();
+Status = MmFwGetMemoryMap(, BL_MM_FLAG_REQUEST_COALESCING);
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
+
+/* Iterate over it */
+Head = FirmwareMdl.First;
+NextEntry = Head->Flink;
+while (NextEntry != Head)
+{
+/* Check if this is a UEFI-related descriptor, unless it's the 
self-map page */
+Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, 
ListEntry);
+if (((Descriptor->Type == BlEfiBootMemory) ||
+ (Descriptor->Type == BlEfiRuntimeMemory) ||
+ (Descriptor->Type == BlLoaderMemory)) &&
+((Descriptor->BasePage << PAGE_SHIFT) != 
Mmx86SelfMapBase.QuadPart))
+{
+/* Identity-map it */
+PhysicalAddress.QuadPart = Descriptor->BasePage << PAGE_SHIFT;
+Status = 
Mmx86MapInitStructure((PVOID)((ULONG_PTR)Descriptor->BasePage << PAGE_SHIFT),
+   Descriptor->PageCount << 
PAGE_SHIFT,
+   PhysicalAddress);
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
+}
+
+/* Move to the next descriptor */
+NextEntry = NextEntry->Flink;
+}
+
+/* Reset */
+NextEntry = Head->Flink;
+while (NextEntry != Head)
+{
+/* Get the descriptor */
+Descriptor = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, 
ListEntry);
+
+/* Skip to the next entry before we free */
+NextEntry = NextEntry->Flink;
+
+/* Remove and free it */
+MmMdRemoveDescriptorFromList(, Descriptor);
+MmMdFreeDescriptor(Descriptor);
+}
+}
+
+/* All library mappings identity mapped now */
+return STATUS_SUCCESS;
 }
 
 NTSTATUS
@@ -1114,14 +1165,17 @@
 
 case BlPae:
 
+/* We don't support PAE */
 Status = STATUS_NOT_SUPPORTED;
 break;
 
 default:
+
+/* Invalid architecture type*/
 Status = STATUS_INVALID_PARAMETER;
 break;
 }
 
+/* Back to caller */
 return Status;
-
-}
+}




[ros-diffs] [ion] 73740: [BOOTLIB]: Implement most of Mmx86pMapMemoryRegions. Just missing the UEFI mappings now.

2017-02-06 Thread ion
Author: ion
Date: Tue Feb  7 01:52:57 2017
New Revision: 73740

URL: http://svn.reactos.org/svn/reactos?rev=73740=rev
Log:
[BOOTLIB]: Implement most of Mmx86pMapMemoryRegions. Just missing the UEFI 
mappings now.

Modified:
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73740=73739=73740=diff
==
--- 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] Tue Feb  7 
01:52:57 2017
@@ -168,39 +168,6 @@
 )
 {
 EfiPrintf(L"Supposed to zero shit\r\n");
-return STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS
-Mmx86pMapMemoryRegions (
-_In_ ULONG Phase,
-_In_ PBL_MEMORY_DATA MemoryData
-)
-{
-BOOLEAN DoDeferred;
-
-/* In phase 1 we don't initialize deferred mappings*/
-if (Phase == 1)
-{
-DoDeferred = 0;
-}
-else
-{
-/* Don't do anything if there's nothing to initialize */
-if (!MmDeferredMappingCount)
-{
-return STATUS_SUCCESS;
-}
-
-DoDeferred = 1;
-}
-
-if (DoDeferred)
-{
-EfiPrintf(L"Deferred todo\r\n");
-}
-
-EfiPrintf(L"Phase 1 TODO\r\n");
 return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -697,6 +664,105 @@
 }
 
 NTSTATUS
+Mmx86pMapMemoryRegions (
+_In_ ULONG Phase,
+_In_ PBL_MEMORY_DATA MemoryData
+)
+{
+BOOLEAN DoDeferred;
+ULONG DescriptorCount;
+PBL_MEMORY_DESCRIPTOR Descriptor;
+ULONG FinalOffset;
+PHYSICAL_ADDRESS PhysicalAddress;
+ULONGLONG Size;
+NTSTATUS Status;
+PVOID VirtualAddress;
+
+/* In phase 1 we don't initialize deferred mappings*/
+if (Phase == 1)
+{
+DoDeferred = FALSE;
+}
+else
+{
+/* Don't do anything if there's nothing to initialize */
+if (!MmDeferredMappingCount)
+{
+return STATUS_SUCCESS;
+}
+
+DoDeferred = TRUE;
+}
+
+/*
+* Because BL supports cross x86-x64 application launches and a LIST_ENTRY
+* is of variable size, care must be taken here to ensure that we see a
+* consistent view of descriptors. BL uses some offset magic to figure out
+* where the data actually starts, since everything is ULONGLONG past the
+* LIST_ENTRY itself
+*/
+FinalOffset = MemoryData->MdListOffset + MemoryData->DescriptorOffset;
+Descriptor = (PBL_MEMORY_DESCRIPTOR)((ULONG_PTR)MemoryData + FinalOffset -
+ FIELD_OFFSET(BL_MEMORY_DESCRIPTOR, 
BasePage));
+
+/* Scan all of them */
+DescriptorCount = MemoryData->DescriptorCount;
+while (DescriptorCount != 0)
+{
+/* Ignore application data */
+if (Descriptor->Type != BlApplicationData)
+{
+/* If this is a ramdisk, do it in phase 2 */
+if ((Descriptor->Type == BlLoaderRamDisk) == DoDeferred)
+{
+/* Get the current physical address and size */
+PhysicalAddress.QuadPart = Descriptor->BasePage << PAGE_SHIFT;
+Size = Descriptor->PageCount << PAGE_SHIFT;
+
+/* Check if it was already mapped */
+if (Descriptor->VirtualPage)
+{
+/* Use the existing address */
+VirtualAddress = 
(PVOID)(ULONG_PTR)(Descriptor->VirtualPage << PAGE_SHIFT);
+}
+else
+{
+/* Use the physical address */
+VirtualAddress = 
(PVOID)(ULONG_PTR)PhysicalAddress.QuadPart;
+}
+
+/* Crete the mapping */
+Status = Mmx86MapInitStructure(VirtualAddress,
+   Size,
+   PhysicalAddress);
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
+}
+
+/* Check if we're in phase 1 and deferring RAM disk */
+if ((Phase == 1) && (Descriptor->Type == BlLoaderRamDisk))
+{
+MmDeferredMappingCount++;
+}
+}
+
+/* Move on to the next descriptor */
+DescriptorCount--;
+Descriptor = (PBL_MEMORY_DESCRIPTOR)((ULONG_PTR)Descriptor + 
MemoryData->DescriptorSize);
+}
+
+/* In phase 1, also do UEFI mappings */
+if (Phase != 2)
+{
+EfiPrintf(L"Phase 1 TODO UEFI mappings \r\n");
+}
+
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
 Mmx86InitializeMemoryMap (
 _In_ ULONG Phase,
 _In_ PBL_MEMORY_DATA MemoryData
@@ -766,8 +832,7 @@
 }
 
 /*

[ros-diffs] [ion] 73739: [BOOTLIB]: Don't use PTE_BASE/PDE_BASE in bootlib. Use MmPteBase and MmPdeBase instead. [BOOTLIB]: Implement MmDefpMapPhysicalAddress, MmDefpTranslateVirtualAddress. Fix defin

2017-02-06 Thread ion
Author: ion
Date: Tue Feb  7 01:35:11 2017
New Revision: 73739

URL: http://svn.reactos.org/svn/reactos?rev=73739=rev
Log:
[BOOTLIB]: Don't use PTE_BASE/PDE_BASE in bootlib. Use MmPteBase and MmPdeBase 
instead.
[BOOTLIB]: Implement MmDefpMapPhysicalAddress, MmDefpTranslateVirtualAddress. 
Fix definition of Mmx86MapPhysicalAddress.

Modified:
trunk/reactos/boot/environ/lib/firmware/efi/firmware.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/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73739=73738=73739=diff
==
--- 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] 
Tue Feb  7 01:35:11 2017
@@ -1446,7 +1446,6 @@
 /* Add 4 more descriptors just in case things changed */
 EfiMemoryMapSize += (4 * DescriptorSize);
 Pages = BYTES_TO_PAGES(EfiMemoryMapSize);
-EfiPrintf(L"Memory map size: %lx bytes, %d pages\r\n", EfiMemoryMapSize, 
Pages);
 
 /* Should we use EFI to grab memory? */
 if (UseEfiBuffer)

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73739=73738=73739=diff
==
--- 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] Tue Feb  7 
01:35:11 2017
@@ -10,7 +10,16 @@
 
 #include "bl.h"
 #include "bcd.h"
-#include "../../../../../ntoskrnl/include/internal/i386/mm.h"
+
+#define PTE_BASE0xC000
+
+//
+// Specific PDE/PTE macros to be used inside the boot library environment
+//
+#define MiAddressToPte(x)   ((PMMPTE)(ULONG)(x)) >> 12) << 2) + 
(ULONG_PTR)MmPteBase))
+#define MiAddressToPde(x)   ((PMMPDE)(ULONG)(x)) >> 22) << 2) + 
(ULONG_PTR)MmPdeBase))
+#define MiAddressToPteOffset(x) ULONG)(x)) << 10) >> 22)
+#define MiAddressToPdeOffset(x) (((ULONG)(x)) / (1024 * PAGE_SIZE))
 
 /* DATA VARIABLES /
 
@@ -81,7 +90,7 @@
 
 typedef NTSTATUS
 (*PBL_MM_MAP_PHYSICAL_ADDRESS) (
-_In_ PPHYSICAL_ADDRESS PhysicalAddress,
+_In_ PHYSICAL_ADDRESS PhysicalAddress,
 _Out_ PVOID VirtualAddress,
 _In_ ULONG Size,
 _In_ ULONG CacheAttributes
@@ -111,6 +120,16 @@
 
 /* FUNCTIONS */
 
+BOOLEAN
+BlMmIsTranslationEnabled (
+VOID
+)
+{
+/* Return if paging is on */
+return ((CurrentExecutionContext) &&
+(CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON));
+}
+
 VOID
 MmArchNullFunction (
 VOID
@@ -277,14 +296,152 @@
 
 NTSTATUS
 MmDefpMapPhysicalAddress (
-_In_ PPHYSICAL_ADDRESS PhysicalAddress,
-_Out_ PVOID VirtualAddress,
+_In_ PHYSICAL_ADDRESS PhysicalAddress,
+_In_ PVOID VirtualAddress,
 _In_ ULONG Size,
 _In_ ULONG CacheAttributes
 )
 {
-EfiPrintf(L"No map\r\n");
-return STATUS_NOT_IMPLEMENTED;
+BOOLEAN Enabled;
+ULONG i, PageCount, PdeOffset;
+ULONGLONG CurrentAddress;
+PMMPDE Pde;
+PMMPTE Pte;
+PMMPTE PageTable;
+PHYSICAL_ADDRESS PageTableAddress;
+NTSTATUS Status;
+
+/* Check if paging is on yet */
+Enabled = BlMmIsTranslationEnabled();
+
+/* Get the physical address aligned */
+CurrentAddress = (PhysicalAddress.QuadPart >> PAGE_SHIFT) << PAGE_SHIFT;
+
+/* Get the number of pages and loop through each one */
+PageCount = Size >> PAGE_SHIFT;
+for (i = 0; i < PageCount; i++)
+{
+/* Check if translation already exists for this page */
+if (Mmx86TranslateVirtualAddress(VirtualAddress, NULL, NULL))
+{
+/* Ignore it and move to the next one */
+VirtualAddress = (PVOID)((ULONG_PTR)VirtualAddress + PAGE_SIZE);
+CurrentAddress += PAGE_SIZE;
+continue;
+}
+
+/* Get the PDE offset */
+PdeOffset = MiAddressToPdeOffset(VirtualAddress);
+
+/* Check if paging is actually turned on */
+if (Enabled)
+{
+/* Get the PDE entry using the self-map */
+Pde = MiAddressToPde(VirtualAddress);
+}
+else
+{
+/* Get it using our physical mappings */
+Pde = [PdeOffset];
+PageTable = (PMMPDE)(Pde->u.Hard.PageFrameNumber << PAGE_SHIFT);
+}
+
+/* Check if we don't yet have a PDE */
+

[ros-diffs] [ion] 73738: [BOOTLIB]: Implement BlMmIsTranslationEnabled and MmMapPhysicalAddress. MmDefpMapPhysicalAddress is missing at this point.

2017-02-06 Thread ion
Author: ion
Date: Mon Feb  6 23:13:47 2017
New Revision: 73738

URL: http://svn.reactos.org/svn/reactos?rev=73738=rev
Log:
[BOOTLIB]: Implement BlMmIsTranslationEnabled and MmMapPhysicalAddress. 
MmDefpMapPhysicalAddress is missing at this point.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73738=73737=73738=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb  6 
23:13:47 2017
@@ -2192,9 +2192,18 @@
 /* VIRTUAL MEMORY ROUTINES ***/
 
 NTSTATUS
+MmSelectMappingAddress (
+_Out_ PVOID* MappingAddress,
+_In_ ULONGLONG Size,
+_In_ ULONG AllocationAttributes,
+_In_ ULONG Flags,
+_In_ PHYSICAL_ADDRESS PhysicalAddress
+);
+
+NTSTATUS
 MmMapPhysicalAddress (
 _Inout_ PPHYSICAL_ADDRESS PhysicalAddress,
-_Out_ PVOID VirtualAddress,
+_Out_ PVOID* VirtualAddress,
 _Inout_ PULONGLONG Size,
 _In_ ULONG CacheAttributes
 );

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73738=73737=73738=diff
==
--- 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] Mon Feb  6 
23:13:47 2017
@@ -296,6 +296,152 @@
 {
 EfiPrintf(L"No translate\r\n");
 return FALSE;
+}
+
+NTSTATUS
+MmSelectMappingAddress (
+_Out_ PVOID* MappingAddress,
+_In_ ULONGLONG Size,
+_In_ ULONG AllocationAttributes,
+_In_ ULONG Flags,
+_In_ PHYSICAL_ADDRESS PhysicalAddress
+)
+{
+/* Are we in physical mode? */
+if (MmTranslationType == BlNone)
+{
+/* Just return the physical address as the mapping address */
+*MappingAddress = (PVOID)PhysicalAddress.LowPart;
+return STATUS_SUCCESS;
+}
+
+/* We don't support virtual memory yet @TODO */
+#ifdef _MSC_VER // Fuck gcc.
+EfiPrintf(L"not yet implemented in " __FUNCTION__ "\r\n");
+EfiStall(100);
+#endif
+return STATUS_NOT_IMPLEMENTED;
+}
+
+BOOLEAN
+BlMmIsTranslationEnabled (
+VOID
+)
+{
+/* Return if paging is on */
+return ((CurrentExecutionContext) &&
+(CurrentExecutionContext->Mode & BL_CONTEXT_PAGING_ON));
+}
+
+NTSTATUS
+MmMapPhysicalAddress (
+_Inout_ PPHYSICAL_ADDRESS PhysicalAddressPtr,
+_Inout_ PVOID* VirtualAddressPtr,
+_Inout_ PULONGLONG SizePtr,
+_In_ ULONG CacheAttributes
+)
+{
+ULONGLONG Size, TotalSize;
+ULONGLONG PhysicalAddress;
+PVOID VirtualAddress;
+PHYSICAL_ADDRESS TranslatedAddress;
+ULONG_PTR CurrentAddress, VirtualAddressEnd;
+NTSTATUS Status;
+
+/* Fail if any parameters are missing */
+if (!(PhysicalAddressPtr) || !(VirtualAddressPtr) || !(SizePtr))
+{
+return STATUS_INVALID_PARAMETER;
+}
+
+/* Fail if the size is over 32-bits */
+Size = *SizePtr;
+if (Size > 0x)
+{
+return STATUS_INVALID_PARAMETER;
+}
+
+/* Nothing to do if we're in physical mode */
+if (MmTranslationType == BlNone)
+{
+return STATUS_SUCCESS;
+}
+
+/* Can't use virtual memory in real mode */
+if (CurrentExecutionContext->Mode == BlRealMode)
+{
+return STATUS_UNSUCCESSFUL;
+}
+
+/* Capture the current virtual and physical addresses */
+VirtualAddress = *VirtualAddressPtr;
+PhysicalAddress = PhysicalAddressPtr->QuadPart;
+
+/* Check if a physical address was requested */
+if (PhysicalAddress != 0x)
+{
+/* Round down the base addresses */
+PhysicalAddress = PAGE_ROUND_DOWN(PhysicalAddress);
+VirtualAddress = (PVOID)PAGE_ROUND_DOWN(VirtualAddress);
+
+/* Round up the size */
+TotalSize = ROUND_TO_PAGES(PhysicalAddressPtr->QuadPart -
+   PhysicalAddress +
+   Size);
+
+/* Loop every virtual page */
+CurrentAddress = (ULONG_PTR)VirtualAddress;
+VirtualAddressEnd = CurrentAddress + TotalSize - 1;
+while (CurrentAddress < VirtualAddressEnd)
+{
+/* Get the physical page of this virtual page */
+if (MmArchTranslateVirtualAddress((PVOID)CurrentAddress,
+  ,
+  ))
+{
+/* Make sure the physical page of the virtual page, matches 
our page */
+if (Transla

[ros-diffs] [ion] 73734: [BOOTLIB]: Finish implementation of MmMdRemoveRegionFromMdlEx for other straddling scenarios. [BOOTLIB]: Implement Mmx86MapInitStructure and most of Mmx86InitializeMemoryMap.

2017-02-06 Thread ion
Author: ion
Date: Mon Feb  6 22:11:21 2017
New Revision: 73734

URL: http://svn.reactos.org/svn/reactos?rev=73734=rev
Log:
[BOOTLIB]: Finish implementation of MmMdRemoveRegionFromMdlEx for other 
straddling scenarios.
[BOOTLIB]: Implement Mmx86MapInitStructure and most of Mmx86InitializeMemoryMap.
[BOOTLIB]: Continue implementation of MmDefInitializeTranslation.
[BOOTLIB]: More explicitly mark paths which are not yet implemented for paging 
mode yet (but only on compilers that don't give compiler errors when trying to 
use __FUNCTION__.

Modified:
trunk/reactos/boot/environ/include/bl.h
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?rev=73734=73733=73734=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb  6 
22:11:21 2017
@@ -2190,6 +2190,20 @@
 );
 
 /* VIRTUAL MEMORY ROUTINES ***/
+
+NTSTATUS
+MmMapPhysicalAddress (
+_Inout_ PPHYSICAL_ADDRESS PhysicalAddress,
+_Out_ PVOID VirtualAddress,
+_Inout_ PULONGLONG Size,
+_In_ ULONG CacheAttributes
+);
+
+NTSTATUS
+MmUnmapVirtualAddress (
+_Inout_ PVOID* VirtualAddress,
+_Inout_ PULONGLONG Size
+);
 
 NTSTATUS
 BlMmMapPhysicalAddressEx (

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=73734=73733=73734=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Mon Feb  6 
22:11:21 2017
@@ -698,16 +698,47 @@
 }
 else
 {
-/* This descriptor covers the head of the allocation 
@TODO: FIXME */
-EfiPrintf(L"FIXME: Descriptor covers the head of the 
region\r\n");
-EfiStall(100);
+/* This descriptor fully covers the entire allocation */
+FoundBasePage = Descriptor->BasePage;
+FoundPageCount = BasePage - FoundBasePage;
+
+/* This is how many pages we will eat away from the 
descriptor */
+RegionSize = FoundPageCount + PageCount;
+
+/* Update the descriptor to account for the consumed pages 
*/
+Descriptor->BasePage += RegionSize;
+Descriptor->PageCount -= RegionSize;
+if (Descriptor->VirtualPage)
+{
+Descriptor->VirtualPage += RegionSize;
+}
+
+/* Initialize a descriptor for the start of the region */
+Descriptor = 
MmMdInitByteGranularDescriptor(Descriptor->Flags,
+
Descriptor->Type,
+FoundBasePage,
+
Descriptor->VirtualPage,
+
FoundPageCount);
+if (!Descriptor)
+{
+Status = STATUS_NO_MEMORY;
+goto Quickie;
+}
+
+/* Add it into the list */
+Status = MmMdAddDescriptorToList(MdList, Descriptor, 
Flags);
+if (!NT_SUCCESS(Status))
+{
+Status = STATUS_NO_MEMORY;
+goto Quickie;
+}
 }
 }
 else
 {
-/* This descriptor contains the entire allocation @TODO: FIXME 
*/
-EfiPrintf(L"FIXME: Descriptor contains the entire region\r\n");
-EfiStall(100);
+/* This descriptor contains the entire allocation */
+RegionSize = FoundEndPage - BasePage;
+Descriptor->PageCount -= RegionSize;
 }
 
 /* Keep going */
@@ -724,14 +755,14 @@
  *
  * So first, figure out if we cover the entire end or not
  */
-if (EndPage > FoundEndPage)
+if (EndPage < FoundEndPage)
 {
 /* The allocation goes past the end of this descriptor */
-EndPage = 

[ros-diffs] [ion] 73732: [BOOTLIB]: Don't use __getcallerseflags() in Archx86IsCpuidSupported -- __readeflags should be good enough.

2017-02-06 Thread ion
Author: ion
Date: Mon Feb  6 19:34:15 2017
New Revision: 73732

URL: http://svn.reactos.org/svn/reactos?rev=73732=rev
Log:
[BOOTLIB]: Don't use __getcallerseflags() in Archx86IsCpuidSupported -- 
__readeflags should be good enough.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73732=73731=73732=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb  6 
19:34:15 2017
@@ -1562,6 +1562,11 @@
 _Out_opt_ PLARGE_INTEGER Frequency
 );
 
+ULONGLONG
+BlArchGetPerformanceCounter (
+VOID
+);
+
 /* RESOURCE LOCALE INTERNATIONALIZATION ROUTINES */
 
 NTSTATUS
@@ -1654,6 +1659,18 @@
 );
 
 /* UTILITY ROUTINES **/
+
+VOID
+BlArchCpuId (
+_In_ ULONG Function,
+_In_ ULONG SubFunction,
+_Out_ INT* Result
+);
+
+BOOLEAN
+BlArchIsCpuIdFunctionSupported (
+_In_ ULONG Function
+);
 
 VOID
 BlUtlUpdateProgress (

Modified: trunk/reactos/boot/environ/lib/misc/util.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/util.c?rev=73732=73731=73732=diff
==
--- trunk/reactos/boot/environ/lib/misc/util.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/util.c  [iso-8859-1] Mon Feb  6 
19:34:15 2017
@@ -776,3 +776,91 @@
 
 return PartialSum;
 }
+
+BOOLEAN
+Archx86IsCpuidSupported (
+VOID
+)
+{
+ULONG CallerFlags, Flags;
+
+/* Read the original flags, and add the CPUID bit */
+CallerFlags = __readeflags() ^ 0x20;
+__writeeflags(CallerFlags);
+
+/* Read our flags now */
+Flags = __readeflags();
+
+/* Check if the bit stuck */
+return (((CallerFlags ^ Flags) >> 21) & 1) ^ 1;
+}
+
+BOOLEAN
+BlArchIsCpuIdFunctionSupported (
+_In_ ULONG Function
+)
+{
+BOOLEAN Supported;
+INT CpuInfo[4];
+
+/* Check if the CPU supports this instruction */
+Supported = Archx86IsCpuidSupported();
+if (!Supported)
+{
+return FALSE;
+}
+
+/* Check if it's the extended function */
+if (Function >= 0x8000)
+{
+/* Check if extended functions are supported */
+__cpuid(CpuInfo, 0x8000);
+if ((CpuInfo[0] & 0xFF00) != 0x8000)
+{
+/* Nope */
+return FALSE;
+}
+}
+else
+{
+/* It's a regular function, get the maximum one supported */
+__cpuid(CpuInfo, 0);
+}
+
+/* Check if our function is within bounds */
+if (Function <= CpuInfo[0])
+{
+return TRUE;
+}
+
+/* Nope */
+return FALSE;
+}
+
+ULONGLONG
+BlArchGetPerformanceCounter (
+VOID
+)
+{
+INT CpuInfo[4];
+
+/* Serialize with CPUID, if it exists */
+if (Archx86IsCpuidSupported())
+{
+BlArchCpuId(0, 0, CpuInfo);
+}
+
+/* Read the TSC */
+return __rdtsc();
+}
+
+VOID
+BlArchCpuId (
+_In_ ULONG Function,
+_In_ ULONG SubFunction,
+_Out_ INT* Result
+)
+{
+/* Use the intrinsic */
+__cpuidex(Result, Function, SubFunction);
+}

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73732=73731=73732=diff
==
--- 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] Mon Feb  6 
19:34:15 2017
@@ -225,94 +225,6 @@
 
 /* Success is if we found a descriptor */
 return Descriptor != NULL;
-}
-
-BOOLEAN
-Archx86IsCpuidSupported (
-VOID
-)
-{
-ULONG CallerFlags, Flags;
-
-/* Read the original flags, and add the CPUID bit */
-CallerFlags = __getcallerseflags() ^ 0x20;
-__writeeflags(CallerFlags);
-
-/* Read our flags now */
-Flags = __readeflags();
-
-/* Check if the bit stuck */
-return (((CallerFlags ^ Flags) >> 21) & 1) ^ 1;
-}
-
-BOOLEAN
-BlArchIsCpuIdFunctionSupported (
-_In_ ULONG Function
-)
-{
-BOOLEAN Supported;
-INT CpuInfo[4];
-
-/* Check if the CPU supports this instruction */
-Supported = Archx86IsCpuidSupported();
-if (!Supported)
-{
-return FALSE;
-}
-
-/* Check if it's the extended function */
-if (Function >= 0x8000)
-{
-/* Check if extended functions are supported */
-__cpuid(CpuInfo, 0x8000);
-if ((CpuInfo[0] & 0xFF00) != 0x8000

[ros-diffs] [ion] 73730: Cleanly compiles with both VS/GCC on my system even though bcd.h is not included. I have no idea how. Evidence in IRC channel.

2017-02-06 Thread ion
Author: ion
Date: Mon Feb  6 19:21:01 2017
New Revision: 73730

URL: http://svn.reactos.org/svn/reactos?rev=73730=rev
Log:
Cleanly compiles with both VS/GCC on my system even though bcd.h is not 
included. I have no idea how. Evidence in IRC channel.

Modified:
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73730=73729=73730=diff
==
--- 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] Mon Feb  6 
19:21:01 2017
@@ -9,6 +9,7 @@
 /* INCLUDES **/
 
 #include "bl.h"
+#include "bcd.h"
 
 /* DATA VARIABLES /
 




[ros-diffs] [ion] 73729: [BOOTLIB]: Implement MmPaReserveSelfMapPages, MmPaReleaseSelfMapPages [BOOTLIB]: Stub MmDefMoveVirtualAddressRange, MmDefZeroVirtualAddressRange, MmDefRelocateSelfMap, MmDefpD

2017-02-06 Thread ion
Author: ion
Date: Mon Feb  6 19:07:17 2017
New Revision: 73729

URL: http://svn.reactos.org/svn/reactos?rev=73729=rev
Log:
[BOOTLIB]: Implement MmPaReserveSelfMapPages, MmPaReleaseSelfMapPages
[BOOTLIB]: Stub MmDefMoveVirtualAddressRange, MmDefZeroVirtualAddressRange, 
MmDefRelocateSelfMap, MmDefpDestroySelfMap, MmDefpUnmapVirtualAddress, 
MmDefpRemapVirtualAddress, MmDefpMapPhysicalAddress, 
MmDefpTranslateVirtualAddress, 
[BOOTLIB]: Implement MmDefpFlushTlbEntry, MmDefpFlushTlb
[BOOTLIB]: Implement MmPaReleaseSelfMapPages, MmPaReserveSelfMapPages.
[BOOTLIB]: Implement Archx86IsCpuidSupported, BlArchIsCpuIdFunctionSupported, 
BlArchCpuId, BlArchGetPerformanceCounter.
[BOOTLIB]: Implement MmArchInitialize.
[BOOTLIB]: Implement most of MmDefInitializeTranslation. Almost ready to turn 
on paging.

Modified:
trunk/reactos/boot/environ/include/bl.h
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?rev=73729=73728=73729=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb  6 
19:07:17 2017
@@ -223,6 +223,7 @@
 {
 BlMdPhysical,
 BlMdVirtual,
+BlMdTracker
 } BL_MEMORY_DESCRIPTOR_TYPE;
 
 typedef enum _BL_TRANSLATION_TYPE
@@ -2114,6 +2115,17 @@
 _In_ ULONG RangeType
 );
 
+NTSTATUS
+MmPaReleaseSelfMapPages (
+_In_ PHYSICAL_ADDRESS Address
+);
+
+NTSTATUS
+MmPaReserveSelfMapPages (
+_Inout_ PPHYSICAL_ADDRESS PhysicalAddress,
+_In_ ULONG Alignment,
+_In_ ULONG PageCount
+);
 NTSTATUS
 BlMmFreePhysicalPages (
 _In_ PHYSICAL_ADDRESS Address

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=73729=73728=73729=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Mon Feb  6 
19:07:17 2017
@@ -680,7 +680,6 @@
 FoundPageCount = Descriptor->PageCount;
 FoundEndPage = FoundBasePage + FoundPageCount;
 EndPage = PageCount + BasePage;
-//EarlyPrint(L"Looking for Region 0x%08I64X-0x%08I64X in 
0x%08I64X-0x%08I64X\r\n", BasePage, EndPage, FoundBasePage, FoundEndPage);
 
 /* Make a copy of the original descriptor */
 RtlCopyMemory(, NextEntry, sizeof(NewDescriptor));
@@ -694,19 +693,21 @@
 /* Check if the found region starts after the region or ends 
before the region */
 if ((FoundBasePage >= BasePage) || (EndPage >= FoundEndPage))
 {
-/* This descriptor doesn't cover any part of the range */
-//EarlyPrint(L"No part of this descriptor contains the 
region\r\n");
+/* This descriptor doesn't cover any part of the range -- 
nothing to do */
+NOTHING;
 }
 else
 {
-/* This descriptor covers the head of the allocation */
-//EarlyPrint(L"Descriptor covers the head of the 
region\r\n");
+/* This descriptor covers the head of the allocation 
@TODO: FIXME */
+EfiPrintf(L"FIXME: Descriptor covers the head of the 
region\r\n");
+EfiStall(100);
 }
 }
 else
 {
-/* This descriptor contains the entire allocation */
-//EarlyPrint(L"Descriptor contains the entire region\r\n");
+/* This descriptor contains the entire allocation @TODO: FIXME 
*/
+EfiPrintf(L"FIXME: Descriptor contains the entire region\r\n");
+EfiStall(100);
 }
 
 /* Keep going */
@@ -747,7 +748,6 @@
 if (!Descriptor->PageCount)
 {
 /* Remove it */
-//EarlyPrint(L"Entire descriptor consumed\r\n");
 MmMdRemoveDescriptorFromList(MdList, Descriptor);
 MmMdFreeDescriptor(Descriptor);
 

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73729=73728=73729=diff
==
--- trunk/reactos/boot/environ/lib/mm/i386/mmx86.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/i386/mmx86.c  [i

[ros-diffs] [ion] 73722: [BOOTLIB]: Clarify that BlMemoryReserved == BlMemoryBelow1MB [BOOTLIB]: Implement EfiAllocatePages, EfiFreePages for Protected Mode. [BOOTLIB]: Fix a "Todo" in MmFwGetMemoryMa

2017-02-05 Thread ion
Author: ion
Date: Mon Feb  6 03:14:14 2017
New Revision: 73722

URL: http://svn.reactos.org/svn/reactos?rev=73722=rev
Log:
[BOOTLIB]: Clarify that BlMemoryReserved == BlMemoryBelow1MB
[BOOTLIB]: Implement EfiAllocatePages, EfiFreePages for Protected Mode.
[BOOTLIB]: Fix a "Todo" in MmFwGetMemoryMap: We now free the EFI buffer used 
for the memory map itself, and unmap it from the memory map (which would show 
it as 'in-use' while we're dumping it).

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73722=73721=73722=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Feb  6 
03:14:14 2017
@@ -1035,11 +1035,11 @@
 AddressRange.Maximum = 0xF;
 AddressRange.Minimum = 0;
 
-/* Allocate one reserved page with the "reserved" attribute */
+/* Allocate one reserved page with the "below 1MB" attribute */
 Status = MmPapAllocatePhysicalPagesInRange(,
BlApplicationReserved,
1,
-   BlMemoryReserved,
+   BlMemoryBelow1MB,
0,
,
,

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73722=73721=73722=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Feb  6 
03:14:14 2017
@@ -364,8 +364,8 @@
 BlMemoryUnknown =   0x0001,
 BlMemoryNonFixed =  0x0002,
 BlMemoryFixed = 0x0004,
-BlMemoryReserved =  0x0008,
-BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed 
| BlMemoryReserved | BlMemoryUnknown,
+BlMemoryBelow1MB =  0x0008,
+BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed 
| BlMemoryBelow1MB | BlMemoryUnknown,
 BlMemoryValidAllocationAttributeMask= 0x00FF,
 
 //
@@ -2006,6 +2006,13 @@
 PBL_MEMORY_DESCRIPTOR
 MmMdFindDescriptor (
 _In_ ULONG WhichList,
+_In_ ULONG Flags,
+_In_ ULONGLONG Page
+);
+
+PBL_MEMORY_DESCRIPTOR
+MmMdFindDescriptorFromMdl (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList,
 _In_ ULONG Flags,
 _In_ ULONGLONG Page
 );

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73722=73721=73722=diff
==
--- 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] 
Mon Feb  6 03:14:14 2017
@@ -617,8 +617,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 */
@@ -1118,13 +1118,18 @@
 {
 BL_ARCH_MODE OldMode;
 EFI_STATUS EfiStatus;
+PHYSICAL_ADDRESS MemoryPhysical;
 
 /* Are we in protected mode? */
 OldMode = CurrentExecutionContext->Mode;
 if (OldMode != BlRealMode)
 {
-/* FIXME: Not yet implemented */
-return STATUS_NOT_IMPLEMENTED;
+/* Translate output address */
+BlMmTranslateVirtualAddress(Memory, );
+Memory = (EFI_PHYSICAL_ADDRESS*)MemoryPhysical.LowPart;
+
+/* Switch to real mode */
+BlpArchSwitchContext(BlProtectedMode);
 }
 
 /* Make the EFI call */
@@ -1387,7 +1392,7 @@
 BL_LIBRARY_PARAMETERS LibraryParameters = BlpLibraryParameters;
 BOOLEAN UseEfiBuffer, HaveRamDisk;
 NTSTATUS Status;
-ULONGLONG Pages, StartPage, EndPage;
+ULONGLONG Pages, StartPage, EndPage, EfiBufferPage;
 UINTN EfiMemoryMapSize, MapKey, DescriptorSize, DescriptorVersion;
 EFI_PHYSICAL_ADDRESS EfiBuffer = 0;
 EFI_MEMORY_DESCRIPTOR* EfiMemoryMap;
@@ -1650,9 +1655,8 @@
 /* Check 

[ros-diffs] [ion] 73721: [BOOTLIB]: Implement MmArchTranslateVirtualAddress for non-paging mode. Stub Mmx86TranslateVirtualAddress. [BOOTLIB]: Support EfiPrintf in Protected mode. [BOOTLIB]: Support E

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 22:34:47 2017
New Revision: 73721

URL: http://svn.reactos.org/svn/reactos?rev=73721=rev
Log:
[BOOTLIB]: Implement MmArchTranslateVirtualAddress for non-paging mode. Stub 
Mmx86TranslateVirtualAddress.
[BOOTLIB]: Support EfiPrintf in Protected mode.
[BOOTLIB]: Support EfiGetMemoryMap in Protected Mode.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.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?rev=73721=73720=73721=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
22:34:47 2017
@@ -2173,6 +2173,13 @@
 BlMmTranslateVirtualAddress (
 _In_ PVOID VirtualAddress,
 _Out_ PPHYSICAL_ADDRESS PhysicalAddress
+);
+
+BOOLEAN
+MmArchTranslateVirtualAddress (
+_In_ PVOID VirtualAddress,
+_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
+_Out_opt_ PULONG CachingFlags
 );
 
 /* BLOCK ALLOCATOR ROUTINES **/

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73721=73720=73721=diff
==
--- 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] 
Sun Feb  5 22:34:47 2017
@@ -143,12 +143,17 @@
 }
 else
 {
-/* FIXME: @TODO: Not yet supported */
-// FIXME: Hack while we are in early rosload mode
+/* Switch to real mode */
+BlpArchSwitchContext(BlRealMode);
+
+/* Call EFI directly */
 if (EfiConOut != NULL)
 {
 EfiConOut->OutputString(EfiConOut, BlScratchBuffer);
 }
+
+/* Switch back to protected mode */
+BlpArchSwitchContext(BlProtectedMode);
 }
 
 /* All done */
@@ -559,13 +564,27 @@
 {
 BL_ARCH_MODE OldMode;
 EFI_STATUS EfiStatus;
-
-/* Are we in protected mode? */
-OldMode = CurrentExecutionContext->Mode;
-if (OldMode != BlRealMode)
-{
-/* FIXME: Not yet implemented */
-return STATUS_NOT_IMPLEMENTED;
+PHYSICAL_ADDRESS MemoryMapSizePhysical, MemoryMapPhysical, MapKeyPhysical;
+PHYSICAL_ADDRESS DescriptorSizePhysical, DescriptorVersionPhysical;
+
+/* Are we in protected mode? */
+OldMode = CurrentExecutionContext->Mode;
+if (OldMode != BlRealMode)
+{
+/* Convert all of the addresses to physical */
+BlMmTranslateVirtualAddress(MemoryMapSize, );
+MemoryMapSize = (UINTN*)MemoryMapSizePhysical.LowPart;
+BlMmTranslateVirtualAddress(MemoryMap, );
+MemoryMap = (EFI_MEMORY_DESCRIPTOR*)MemoryMapPhysical.LowPart;
+BlMmTranslateVirtualAddress(MapKey, );
+MapKey = (UINTN*)MapKeyPhysical.LowPart;
+BlMmTranslateVirtualAddress(DescriptorSize, );
+DescriptorSize = (UINTN*)DescriptorSizePhysical.LowPart;
+BlMmTranslateVirtualAddress(DescriptorVersion, 
);
+DescriptorVersion = (UINTN*)DescriptorVersionPhysical.LowPart;
+
+/* Switch to real mode */
+BlpArchSwitchContext(BlProtectedMode);
 }
 
 /* Make the EFI call */

Modified: trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/i386/mmx86.c?rev=73721=73720=73721=diff
==
--- 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] Sun Feb  5 
22:34:47 2017
@@ -78,6 +78,59 @@
 return STATUS_NOT_IMPLEMENTED;
 }
 
+BOOLEAN
+Mmx86TranslateVirtualAddress (
+_In_ PVOID VirtualAddress,
+_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress,
+_Out_opt_ PULONG CachingFlags
+)
+{
+EfiPrintf(L"paging  TODO\r\n");
+return FALSE;
+}
+
+BOOLEAN
+MmArchTranslateVirtualAddress (
+_In_ PVOID VirtualAddress, 
+_Out_opt_ PPHYSICAL_ADDRESS PhysicalAddress, 
+_Out_opt_ PULONG CachingFlags
+)
+{
+PBL_MEMORY_DESCRIPTOR Descriptor;
+
+/* Check if paging is on */
+if ((CurrentExecutionContext) &&
+(CurrentExecutionContext->ContextFlags & BL_CONTEXT_PAGING_ON))
+{
+/* Yes -- we have to translate this from virtual */
+return Mmx86TranslateVirtualAddress(VirtualAddress,
+ 

[ros-diffs] [ion] 73720: [BOOTMGR]: Fix more gcc warnings. Maybe we should stop building GCC with /Wall but MSVC with /Wnothing? [BOOTLIB]: Hack EfiPrintf temporarily so we can get print outs even in

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 22:17:07 2017
New Revision: 73720

URL: http://svn.reactos.org/svn/reactos?rev=73720=rev
Log:
[BOOTMGR]: Fix more gcc warnings. Maybe we should stop building GCC with /Wall 
but MSVC with /Wnothing?
[BOOTLIB]: Hack EfiPrintf temporarily so we can get print outs even in 
"Protected mode".
[ROSLOAD]: Begin implementation. First, many bootlib fixes needed.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/rosload/rosload.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/mm.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73720=73719=73720=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Feb  5 
22:17:07 2017
@@ -2901,7 +2901,6 @@
 {
 NTSTATUS Status;
 PHYSICAL_ADDRESS PhysicalAddress, PhysicalAddress2;
-PBL_MEMORY_DESCRIPTOR Found;
 
 /* Allocate 1 physical page */
 PhysicalAddress.QuadPart = 0;
@@ -2913,7 +2912,7 @@
 }
 
 /* Write some data */
-*(PULONG)PhysicalAddress.QuadPart = 0x5151;
+*(PULONG)((ULONG_PTR)PhysicalAddress.QuadPart) = 0x5151;
 
 /* Free it */
 Status = BlMmFreePhysicalPages(PhysicalAddress);
@@ -2940,9 +2939,9 @@
 }
 
 /* The data should still be there, since zero-ing is not on for 
bootmgr */
-if (*(PULONG)PhysicalAddress2.QuadPart != 0x5151)
-{
-EfiPrintf(L"FAIL: Non-matching data: %lx %lx\r\n", 0x5151, 
*(PULONG)PhysicalAddress2.QuadPart);
+if (*(PULONG)((ULONG_PTR)PhysicalAddress2.QuadPart) != 0x5151)
+{
+EfiPrintf(L"FAIL: Non-matching data: %lx %lx\r\n", 0x5151, 
*(PULONG)((ULONG_PTR)PhysicalAddress2.QuadPart));
 EfiStall(1);
 }
 

Modified: trunk/reactos/boot/environ/app/rosload/rosload.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/rosload/rosload.c?rev=73720=73719=73720=diff
==
--- trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] Sun Feb  5 
22:17:07 2017
@@ -47,8 +47,7 @@
 LibraryParameters.DescriptorCount = 512;
 Status = BlInitializeLibrary(BootParameters, );
 
-//EfiPrintf(L"ReactOS UEFI OS Loader Initializing...\r\n");
-EfiConOut->OutputString(EfiConOut, L"ReactOS UEFI OS Loader 
Initializing...\r\n");
+EfiPrintf(L"ReactOS UEFI OS Loader Initializing...\r\n");
 return Status;
 }
 

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73720=73719=73720=diff
==
--- 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] 
Sun Feb  5 22:17:07 2017
@@ -144,6 +144,11 @@
 else
 {
 /* FIXME: @TODO: Not yet supported */
+// FIXME: Hack while we are in early rosload mode
+if (EfiConOut != NULL)
+{
+EfiConOut->OutputString(EfiConOut, BlScratchBuffer);
+}
 }
 
 /* All done */

Modified: trunk/reactos/boot/environ/lib/mm/mm.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?rev=73720=73719=73720=diff
==
--- trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] Sun Feb  5 
22:17:07 2017
@@ -349,6 +349,7 @@
 LibraryParameters->MinimumAllocationCount);
 if (!NT_SUCCESS(Status))
 {
+EfiPrintf(L"PA Mm init failed: %lx\r\n", Status);
 goto Quickie;
 }
 
@@ -356,6 +357,7 @@
 Status = MmTrInitialize();
 if (!NT_SUCCESS(Status))
 {
+EfiPrintf(L"TR Mm init failed: %lx\r\n", Status);
 //MmArchDestroy();
 //MmPaDestroy(1);
 goto Quickie;
@@ -380,6 +382,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Kill everything set setup so far */
+EfiPrintf(L"Phase 1 Mm init failed: %lx\r\n", Status);
 //MmPaDestroy(0);
 //MmTrDestroy();
 //MmArchDestroy();
@@ -415,6 +418,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Go back to static descriptors and kill the heap */
+ 

[ros-diffs] [ion] 73719: [BOOTLIB]: Fix bug in MmPapFreePhysicalPages.

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 22:03:27 2017
New Revision: 73719

URL: http://svn.reactos.org/svn/reactos?rev=73719=rev
Log:
[BOOTLIB]: Fix bug in MmPapFreePhysicalPages.

Modified:
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=73719=73718=73719=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Sun Feb  5 
22:03:27 2017
@@ -712,7 +712,7 @@
 else if (!DontFree)
 {
 /* Caller wants memory to be freed -- should we zero it? */
-if (!(HasPageData) &
+if (!(HasPageData) &&
 (LibraryParameters.LibraryFlags &
  BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE))
 {




[ros-diffs] [ion] 73718: [BOOTMGR]: Finish alloc/free test. It shows that it seems? to be working ok? :-) [BOOTLIB]: Wrap-up implementation of MmPapFreePhysicalPages. We no longer leak RAM.

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 22:02:24 2017
New Revision: 73718

URL: http://svn.reactos.org/svn/reactos?rev=73718=rev
Log:
[BOOTMGR]: Finish alloc/free test. It shows that it seems? to be working ok? :-)
[BOOTLIB]: Wrap-up implementation of MmPapFreePhysicalPages. We no longer leak 
RAM.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73718=73717=73718=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Feb  5 
22:02:24 2017
@@ -2900,22 +2900,60 @@
 EfiPrintf(L"Performing memory allocator tests...\r\n");
 {
 NTSTATUS Status;
-PHYSICAL_ADDRESS PhysicalAddress;
+PHYSICAL_ADDRESS PhysicalAddress, PhysicalAddress2;
 PBL_MEMORY_DESCRIPTOR Found;
 
 /* Allocate 1 physical page */
 PhysicalAddress.QuadPart = 0;
 Status = BlMmAllocatePhysicalPages(, BlLoaderData, 1, 
0, 1);
-EfiPrintf(L"Allocation status: %lx at address: %llx\r\n", Status, 
PhysicalAddress.QuadPart);
-EfiStall(1);
-
-Found = MmMdFindDescriptor(BL_MM_INCLUDE_UNMAPPED_ALLOCATED, 0, 
PhysicalAddress.QuadPart >> PAGE_SHIFT);
-EfiPrintf(L"Found descriptor: %p %llx\r\n", Found, Found->BasePage);
-
+if (Status != STATUS_SUCCESS)
+{
+EfiPrintf(L"FAIL: Allocation status: %lx at address: %llx\r\n", 
Status, PhysicalAddress.QuadPart);
+EfiStall(1);
+}
+
+/* Write some data */
+*(PULONG)PhysicalAddress.QuadPart = 0x5151;
+
+/* Free it */
 Status = BlMmFreePhysicalPages(PhysicalAddress);
-EfiPrintf(L"Memory free status: %lx\r\n", Status);
-}
-
+if (Status != STATUS_SUCCESS)
+{
+EfiPrintf(L"FAIL: Memory free status: %lx\r\n", Status);
+EfiStall(1);
+}
+
+/* Allocate a page again */
+PhysicalAddress2.QuadPart = 0;
+Status = BlMmAllocatePhysicalPages(, BlLoaderData, 1, 
0, 1);
+if (Status != STATUS_SUCCESS)
+{
+EfiPrintf(L"FAIL: Allocation status: %lx at address: %llx\r\n", 
Status, PhysicalAddress2.QuadPart);
+EfiStall(1);
+}
+
+/* It should've given us the same page, since we freed it */
+if (PhysicalAddress.QuadPart != PhysicalAddress2.QuadPart)
+{
+EfiPrintf(L"FAIL: Non-matching addresses: %llx %llx\r\n", 
PhysicalAddress.QuadPart, PhysicalAddress2.QuadPart);
+EfiStall(1);
+}
+
+/* The data should still be there, since zero-ing is not on for 
bootmgr */
+if (*(PULONG)PhysicalAddress2.QuadPart != 0x5151)
+{
+EfiPrintf(L"FAIL: Non-matching data: %lx %lx\r\n", 0x5151, 
*(PULONG)PhysicalAddress2.QuadPart);
+EfiStall(1);
+}
+
+/* And free the second page again */
+Status = BlMmFreePhysicalPages(PhysicalAddress);
+if (Status != STATUS_SUCCESS)
+{
+EfiPrintf(L"FAIL: Memory free status: %lx\r\n", Status);
+EfiStall(1);
+}
+}
 
 /* Write out the first XML tag */
 BlXmiWrite(L"");

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=73718=73717=73718=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Sun Feb  5 
22:02:24 2017
@@ -740,9 +740,43 @@
 Flags |= BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG;
 }
 
-/* TBD */
-EfiPrintf(L"Leaking memory: %p!\r\n", Address.QuadPart);
-return STATUS_SUCCESS;
+/* Check if the entire allocation is being free*/
+if (PageCount == Descriptor->PageCount)
+{
+/* Remove the descriptor from the allocated list */
+MmMdRemoveDescriptorFromList(, Descriptor);
+
+/* Mark the entire descriptor as free */
+Descriptor->Type = BlConventionalMemory;
+}
+else
+{
+/* Init a descriptor for what we're actually freeing */
+Descriptor = MmMdInitByteGranularDescriptor(Descriptor->Flags,
+BlConventionalMemory,
+Page,
+0,
+

[ros-diffs] [ion] 73716: [BOOTMGR]: Fix bug in test. [BOOTLIB]: Fix bug in MmMdFindDescriptorFromMdl. [BOOTLIB]: Implement MmFwFreePages. [BOOTLIB]: Implement most of MmPapFreePhysicalPages. The rest

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 21:50:14 2017
New Revision: 73716

URL: http://svn.reactos.org/svn/reactos?rev=73716=rev
Log:
[BOOTMGR]: Fix bug in test.
[BOOTLIB]: Fix bug in MmMdFindDescriptorFromMdl.
[BOOTLIB]: Implement MmFwFreePages.
[BOOTLIB]: Implement most of MmPapFreePhysicalPages. The rest is coming next.
[BOOTMGR]: Add test for alloc/free.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/fwutil.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73716=73715=73716=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Feb  5 
21:50:14 2017
@@ -2902,12 +2902,6 @@
 NTSTATUS Status;
 PHYSICAL_ADDRESS PhysicalAddress;
 PBL_MEMORY_DESCRIPTOR Found;
-PBL_MEMORY_DESCRIPTOR
-MmMdFindDescriptor (
-_In_ ULONG WhichList,
-_In_ ULONG Flags,
-_In_ ULONGLONG Page
-);
 
 /* Allocate 1 physical page */
 PhysicalAddress.QuadPart = 0;
@@ -2915,8 +2909,11 @@
 EfiPrintf(L"Allocation status: %lx at address: %llx\r\n", Status, 
PhysicalAddress.QuadPart);
 EfiStall(1);
 
-Found = MmMdFindDescriptor(BL_MM_INCLUDE_UNMAPPED_ALLOCATED, 0, 
PhysicalAddress.QuadPart);
+Found = MmMdFindDescriptor(BL_MM_INCLUDE_UNMAPPED_ALLOCATED, 0, 
PhysicalAddress.QuadPart >> PAGE_SHIFT);
 EfiPrintf(L"Found descriptor: %p %llx\r\n", Found, Found->BasePage);
+
+Status = BlMmFreePhysicalPages(PhysicalAddress);
+EfiPrintf(L"Memory free status: %lx\r\n", Status);
 }
 
 

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73716=73715=73716=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
21:50:14 2017
@@ -122,6 +122,7 @@
 #define BL_MM_REQUEST_DEFAULT_TYPE  1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE 2
 
+#define BL_MM_REMOVE_PHYSICAL_REGION_FLAG   0x4000
 #define BL_MM_REMOVE_VIRTUAL_REGION_FLAG0x8000
 
 #define BL_LIBRARY_FLAG_NO_DISPLAY  0x01
@@ -374,9 +375,10 @@
 BlMemoryCoalesced = 0x0200,
 BlMemoryUpdate =0x0400,
 BlMemoryNonFirmware =   0x0800,
+BlMemoryPersistent =0x1000,
 BlMemorySpecial =   0x2000,
 BlMemoryFirmware =  0x8000,
-BlMemoryValidTypeAttributes = BlMemoryRuntime | 
BlMemoryCoalesced | BlMemoryUpdate | BlMemoryNonFirmware | BlMemorySpecial | 
BlMemoryFirmware,
+BlMemoryValidTypeAttributes = BlMemoryRuntime | 
BlMemoryCoalesced | BlMemoryUpdate | BlMemoryNonFirmware | BlMemoryPersistent | 
BlMemorySpecial | BlMemoryFirmware,
 BlMemoryValidTypeAttributeMask  = 0xFF00,
 } BL_MEMORY_ATTR;
 
@@ -1541,6 +1543,12 @@
 _Out_ PPHYSICAL_ADDRESS FoundRsdt
 );
 
+NTSTATUS
+EfiFreePages (
+_In_ ULONG Pages,
+_In_ EFI_PHYSICAL_ADDRESS PhysicalAddress
+);
+
 /* PLATFORM TIMER ROUTINES ***/
 
 NTSTATUS
@@ -1709,6 +1717,12 @@
 VOID
 BlFwReboot (
 VOID
+);
+
+NTSTATUS
+MmFwFreePages (
+_In_ ULONG BasePage,
+_In_ ULONG PageCount
 );
 
 PGUID
@@ -1987,6 +2001,13 @@
 _In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
 _In_ ULONG Type,
 _In_ PLIST_ENTRY ListHead
+);
+
+PBL_MEMORY_DESCRIPTOR
+MmMdFindDescriptor (
+_In_ ULONG WhichList,
+_In_ ULONG Flags,
+_In_ ULONGLONG Page
 );
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/firmware/fwutil.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/fwutil.c?rev=73716=73715=73716=diff
==
--- trunk/reactos/boot/environ/lib/firmware/fwutil.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/firmware/fwutil.c[iso-8859-1] Sun Feb  5 
21:50:14 2017
@@ -24,3 +24,12 @@
 EfiResetSystem(EfiResetCold);
 }
 
+NTSTATUS
+MmFwFreePages (
+_In_ ULONG BasePage,
+_In_ ULONG PageCount
+)
+{
+/* Free the pages */
+return EfiFreePages(PageCount, BasePage << PAGE_SHIFT);
+}

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/

[ros-diffs] [ion] 73713: [BOOTLIB]: Fix GCC build. Maybe I should stop using MSVC.

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 20:52:00 2017
New Revision: 73713

URL: http://svn.reactos.org/svn/reactos?rev=73713=rev
Log:
[BOOTLIB]: Fix GCC build. Maybe I should stop using MSVC.

Modified:
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=73713=73712=73713=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Sun Feb  5 
20:52:00 2017
@@ -652,7 +652,7 @@
 }
 
 /* Free it from there */
-PhysicalAddress.QuadPart = (ULONGLONG)Address;
+PhysicalAddress.QuadPart = (ULONG_PTR)Address;
 return MmPapFreePhysicalPages(WhichList, 0, PhysicalAddress);
 }
 




[ros-diffs] [ion] 73712: [BOOTMGR]: Add the basics of some memory allocator/descriptor tests. [BOOTLIB]: Implement MmMdFindDescriptorFromMdl (broken?) [BOOTLIB]: Implement MmMdFindDescriptor. [BOOTLIB

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 19:55:49 2017
New Revision: 73712

URL: http://svn.reactos.org/svn/reactos?rev=73712=rev
Log:
[BOOTMGR]: Add the basics of some memory allocator/descriptor tests.
[BOOTLIB]: Implement MmMdFindDescriptorFromMdl (broken?)
[BOOTLIB]: Implement MmMdFindDescriptor.
[BOOTLIB]: Implement BlMmFreePhysicalPages.
[BOOTLIB]: Implement MmPapFreePages for physical memory translation scenario 
only.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73712=73711=73712=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Feb  5 
19:55:49 2017
@@ -2895,6 +2895,31 @@
 }
 }
 
+
+/* TEST MODE */
+EfiPrintf(L"Performing memory allocator tests...\r\n");
+{
+NTSTATUS Status;
+PHYSICAL_ADDRESS PhysicalAddress;
+PBL_MEMORY_DESCRIPTOR Found;
+PBL_MEMORY_DESCRIPTOR
+MmMdFindDescriptor (
+_In_ ULONG WhichList,
+_In_ ULONG Flags,
+_In_ ULONGLONG Page
+);
+
+/* Allocate 1 physical page */
+PhysicalAddress.QuadPart = 0;
+Status = BlMmAllocatePhysicalPages(, BlLoaderData, 1, 
0, 1);
+EfiPrintf(L"Allocation status: %lx at address: %llx\r\n", Status, 
PhysicalAddress.QuadPart);
+EfiStall(1);
+
+Found = MmMdFindDescriptor(BL_MM_INCLUDE_UNMAPPED_ALLOCATED, 0, 
PhysicalAddress.QuadPart);
+EfiPrintf(L"Found descriptor: %p %llx\r\n", Found, Found->BasePage);
+}
+
+
 /* Write out the first XML tag */
 BlXmiWrite(L"");
 

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73712=73711=73712=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
19:55:49 2017
@@ -669,7 +669,6 @@
 (*PBL_DEVICE_CREATE) (
 VOID
 );
-
 
 /* DATA STRUCTURES ***/
 

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=73712=73711=73712=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Sun Feb  5 
19:55:49 2017
@@ -779,6 +779,204 @@
 return Status;
 }
 
+PBL_MEMORY_DESCRIPTOR
+MmMdFindDescriptorFromMdl (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList, 
+_In_ ULONG Flags, 
+_In_ ULONGLONG Page
+)
+{
+BOOLEAN IsVirtual;
+PLIST_ENTRY NextEntry, ListHead;
+PBL_MEMORY_DESCRIPTOR Current;
+ULONGLONG BasePage;
+
+/* Assume physical */
+IsVirtual = FALSE;
+
+/* Check if the caller wants physical memory */
+if (!(Flags & BL_MM_REMOVE_VIRTUAL_REGION_FLAG))
+{
+/* Check if this is a virtual memory list */
+if (MdList->Type == BlMdVirtual)
+{
+/* We won't find anything */
+return NULL;
+}
+}
+else if (MdList->Type == BlMdPhysical)
+{
+/* Otherwise, caller wants virtual, but this is a physical list */
+IsVirtual = TRUE;
+NextEntry = MdList->First->Flink;
+}
+
+/* Check if this is a physical search */
+if (!IsVirtual)
+{
+/* Check if we can use the current pointer */
+NextEntry = MdList->This;
+if (!NextEntry)
+{
+/* We can't -- start at the beginning */
+NextEntry = MdList->First->Flink;
+}
+else
+{
+/* If the page is below the current pointer, restart */
+Current = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, 
ListEntry);
+if (Page < Current->BasePage)
+{
+NextEntry = MdList->First->Flink;
+}
+}
+}
+
+/* Loop the list of descriptors */
+ListHead = MdList->First;
+while (NextEntry != ListHead)
+{
+/* Get the current one */
+Current = CONTAINING_RECORD(NextEntry, BL_MEMORY_DESCRIPTOR, 
ListEntry);
+
+/* Check if we are looking for virtual memory */
+if (IsVirtual)
+{
+/* Use the bas

[ros-diffs] [ion] 73707: [BOOTLIB]: Stub MmPapFreePages [BOOTLIB]: Implement BlImgUnallocateImageBuffer [BOOTLIB]: Stub BlMmTranslateVirtualAddress

2017-02-05 Thread ion
Author: ion
Date: Sun Feb  5 15:14:44 2017
New Revision: 73707

URL: http://svn.reactos.org/svn/reactos?rev=73707=rev
Log:
[BOOTLIB]: Stub MmPapFreePages
[BOOTLIB]: Implement BlImgUnallocateImageBuffer
[BOOTLIB]: Stub BlMmTranslateVirtualAddress

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/misc/bootreg.c
trunk/reactos/boot/environ/lib/misc/image.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?rev=73707=73706=73707=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
15:14:44 2017
@@ -2093,6 +2093,12 @@
 );
 
 NTSTATUS
+MmPapFreePages (
+_In_ PVOID Address,
+_In_ ULONG WhichList
+);
+
+NTSTATUS
 MmPapAllocatePagesInRange (
 _Inout_ PVOID* PhysicalAddress,
 _In_ BL_MEMORY_TYPE MemoryType,
@@ -2141,6 +2147,12 @@
 BlMmUnmapVirtualAddressEx (
 _In_ PVOID VirtualAddress,
 _In_ ULONGLONG Size
+);
+
+BOOLEAN
+BlMmTranslateVirtualAddress (
+_In_ PVOID VirtualAddress,
+_Out_ PPHYSICAL_ADDRESS PhysicalAddress
 );
 
 /* BLOCK ALLOCATOR ROUTINES **/

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=73707=73706=73707=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Sun Feb  5 
15:14:44 2017
@@ -214,9 +214,7 @@
 
 if (*BufferSize)
 {
-EfiPrintf(L"Aligned free not yet implemented\r\n");
-Status = STATUS_NOT_IMPLEMENTED;
-//Status = MmPapFreePages(*Buffer, 1);
+Status = MmPapFreePages(*Buffer, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
 *Buffer = NULL;
 *BufferSize = 0;
@@ -1881,8 +1879,7 @@
 /* Free the prefetch buffer is one was allocated */
 if (BlockIopPrefetchBuffer)
 {
-EfiPrintf(L"Failure path not implemented %lx\r\n", Status);
-//MmPapFreePages(BlockIopPrefetchBuffer, 1);
+MmPapFreePages(BlockIopPrefetchBuffer, 
BL_MM_INCLUDE_MAPPED_ALLOCATED);
 }
 }
 

Modified: trunk/reactos/boot/environ/lib/misc/bootreg.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bootreg.c?rev=73707=73706=73707=diff
==
--- trunk/reactos/boot/environ/lib/misc/bootreg.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/bootreg.c   [iso-8859-1] Sun Feb  5 
15:14:44 2017
@@ -163,8 +163,7 @@
 }
 
 /* Unmap the hive */
-//MmPapFreePages(KeyHive->ImageBase, 1);
-EfiPrintf(L"Leaking hive memory\r\n");
+MmPapFreePages(KeyHive->BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
 /* Free the hive and hive path */
 BlMmFreeHeap(KeyHive->FilePath);
@@ -516,8 +515,7 @@
 RtlCopyMemory(NewBaseBlock, BaseBlock, HiveSize);
 
 /* Free the old data */
-EfiPrintf(L"Leaking old hive buffer\r\n");
-//MmPapFreePages(BaseBlock, 1);
+MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 
 /* Update our pointers */
 BaseBlock = NewBaseBlock;
@@ -607,8 +605,7 @@
 /* If we had logging data, free it */
 if (LogData)
 {
-EfiPrintf(L"Leaking log buffer\r\n");
-//MmPapFreePages(LogData, 1);
+MmPapFreePages(LogData, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 }
 
 /* Check if this is the failure path */
@@ -617,8 +614,7 @@
 /* If we mapped the hive, free it */
 if (BaseBlock)
 {
-EfiPrintf(L"Leaking base block on failure\r\n");
-//MmPapFreePages(BaseBlock, 1u);
+MmPapFreePages(BaseBlock, BL_MM_INCLUDE_MAPPED_ALLOCATED);
 }
 
 /* If we opened the device, close it */

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73707=73706=73707=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sun Feb  5 
15:14:44 2017
@@ -194,8 +194,7 @@
 if (File->Flags & BL_IMG_REMOTE_FILE)
 {
 /* Then only free the memory in that scenario */
-Ef

[ros-diffs] [ion] 73693: [ROSLOAD]: Implement most of OslMain, which will try to initialize BootLib in Virtual Protected Mode (mostly unimplemented). [BOOTLIB]: Fix GCC build. Bootmgr now correctly sw

2017-02-04 Thread ion
Author: ion
Date: Sun Feb  5 06:02:11 2017
New Revision: 73693

URL: http://svn.reactos.org/svn/reactos?rev=73693=rev
Log:
[ROSLOAD]: Implement most of OslMain, which will try to initialize BootLib in 
Virtual Protected Mode (mostly unimplemented).
[BOOTLIB]: Fix GCC build.
Bootmgr now correctly switches execution into rosload, which must now be 
implemented.

Modified:
trunk/reactos/boot/environ/app/rosload/rosload.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/app/rosload/rosload.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/rosload/rosload.c?rev=73693=73692=73693=diff
==
--- trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/rosload/rosload.c[iso-8859-1] Sun Feb  5 
06:02:11 2017
@@ -33,7 +33,22 @@
 _In_ PBOOT_APPLICATION_PARAMETER_BLOCK BootParameters
 )
 {
-EfiPrintf(L"ReactOS UEFI OS Loader Initializing...\r\n");
-return STATUS_NOT_IMPLEMENTED;
+BL_LIBRARY_PARAMETERS LibraryParameters;
+NTSTATUS Status;
+
+/* Setup the boot library parameters for this application */
+BlSetupDefaultParameters();
+LibraryParameters.TranslationType = BlVirtual;
+LibraryParameters.LibraryFlags = BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED;
+LibraryParameters.MinimumAllocationCount = 1024;
+LibraryParameters.MinimumHeapSize = 2 * 1024 * 1024;
+LibraryParameters.HeapAllocationAttributes = 0x2;
+LibraryParameters.FontBaseDirectory = L"\\Reactos\\Boot\\Fonts";
+LibraryParameters.DescriptorCount = 512;
+Status = BlInitializeLibrary(BootParameters, );
+
+//EfiPrintf(L"ReactOS UEFI OS Loader Initializing...\r\n");
+EfiConOut->OutputString(EfiConOut, L"ReactOS UEFI OS Loader 
Initializing...\r\n");
+return Status;
 }
 

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73693=73692=73693=diff
==
--- 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] 
Sun Feb  5 06:02:11 2017
@@ -1758,7 +1758,7 @@
 /* FIXME: Not supported */
 Status = STATUS_NOT_SUPPORTED;
 }
-else if (FirmwareData->Version >= 2)
+else if (FirmwareData->Version >= BL_FIRMWARE_DESCRIPTOR_VERSION)
 {
 /* Version 2 -- save the data */
 EfiFirmwareData = *FirmwareData;

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73693=73692=73693=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sun Feb  5 
06:02:11 2017
@@ -22,7 +22,7 @@
 KDESCRIPTOR BootAppGdtRegister;
 KDESCRIPTOR BootAppIdtRegister;
 PVOID BootApp32EntryRoutine;
-PVOID BootApp32Parameters;
+PBOOT_APPLICATION_PARAMETER_BLOCK BootApp32Parameters;
 PVOID BootApp32Stack;
 
 /* FUNCTIONS */
@@ -1710,7 +1710,7 @@
 ParameterBlock->Signature[1] = BOOT_APPLICATION_SIGNATURE_2;
 ParameterBlock->MemoryTranslationType = MmTranslationType;
 ParameterBlock->ImageType = IMAGE_FILE_MACHINE_I386;
-ParameterBlock->ImageBase = (ULONGLONG)ImageBase;
+ParameterBlock->ImageBase = (ULONG_PTR)ImageBase;
 ParameterBlock->ImageSize = NtHeaders->OptionalHeader.SizeOfImage;
 
 /* Get the offset to the memory data */
@@ -1870,9 +1870,6 @@
 /* Disable the kernel debugger */
 BlBdStop();
 #endif
-/* Not yet implemented. This is the last step! */
-EfiPrintf(L"EFI APPLICATION START!!!\r\n");
-
 /* Make it so */
 Archx86TransferTo32BitApplicationAsm();
 




[ros-diffs] [ion] 73692: [BOOTLIB]: Implement BlFwGetParameters. [BOOTLIB]: Implement ImgpCopyApplicationBootDevice except for partition devices; [BOOTLIB]: Implement ImgpInitializeBootApplicationPara

2017-02-04 Thread ion
Author: ion
Date: Sun Feb  5 05:35:44 2017
New Revision: 73692

URL: http://svn.reactos.org/svn/reactos?rev=73692=rev
Log:
[BOOTLIB]: Implement BlFwGetParameters.
[BOOTLIB]: Implement ImgpCopyApplicationBootDevice except for partition devices;
[BOOTLIB]: Implement ImgpInitializeBootApplicationParameters.
[BOOTLIB]: Fix bug in BlMmGetMemoryMap.
[BOOTLIB]: Simplify MmMdCopyList.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/mm/descriptor.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?rev=73692=73691=73692=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
05:35:44 2017
@@ -183,7 +183,6 @@
 #define BL_LOAD_PE_IMG_CHECK_FORCED_INTEGRITY   0x200
 #define BL_LOAD_PE_IMG_IGNORE_CHECKSUM_MISMATCH 0x1
 #define BL_LOAD_PE_IMG_VALIDATE_ORIGINAL_FILENAME   0x40
-
 
 #define BL_UTL_CHECKSUM_COMPLEMENT  0x1
 #define BL_UTL_CHECKSUM_ROTATE  0x2
@@ -1402,6 +1401,11 @@
 EfiPrintf (
 _In_ PWCHAR Format,
 ...
+);
+
+NTSTATUS
+BlFwGetParameters(
+_In_ PBL_FIRMWARE_DESCRIPTOR Parameters
 );
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=73692=73691=73692=diff
==
--- 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] 
Sun Feb  5 05:35:44 2017
@@ -1782,6 +1782,22 @@
 
 /* Return the initialization state */
 return Status;
+}
+
+NTSTATUS
+BlFwGetParameters (
+_In_ PBL_FIRMWARE_DESCRIPTOR Parameters
+)
+{
+/* Make sure we got an argument */
+if (!Parameters)
+{
+return STATUS_INVALID_PARAMETER;
+}
+
+/* Copy the static data */
+*Parameters = *EfiFirmwareParameters;
+return STATUS_SUCCESS;
 }
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73692=73691=73692=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sun Feb  5 
05:35:44 2017
@@ -1605,6 +1605,26 @@
 }
 
 NTSTATUS
+ImgpCopyApplicationBootDevice (
+__in PBL_DEVICE_DESCRIPTOR DestinationDevice,
+__in PBL_DEVICE_DESCRIPTOR SourceDevice
+)
+{
+/* Is this a partition device? */
+if (SourceDevice->DeviceType != PartitionDevice)
+{
+/* It's not -- a simple copy will do */
+RtlCopyMemory(DestinationDevice, SourceDevice, SourceDevice->Size);
+return STATUS_SUCCESS;
+}
+
+/* TODO */
+EfiPrintf(L"Partition copy not supported\r\n");
+return STATUS_NOT_IMPLEMENTED;
+
+}
+
+NTSTATUS
 ImgpInitializeBootApplicationParameters (
 _In_ PBL_IMAGE_PARAMETERS ImageParameters,
 _In_ PBL_APPLICATION_ENTRY AppEntry,
@@ -1616,6 +1636,13 @@
 PIMAGE_NT_HEADERS NtHeaders;
 BL_IMAGE_PARAMETERS MemoryParameters;
 LIST_ENTRY MemoryList;
+PBL_FIRMWARE_DESCRIPTOR FirmwareParameters;
+PBL_DEVICE_DESCRIPTOR BootDevice;
+PBL_MEMORY_DATA MemoryData;
+PBL_APPLICATION_ENTRY BootAppEntry;
+PBL_RETURN_ARGUMENTS ReturnArguments;
+PBOOT_APPLICATION_PARAMETER_BLOCK ParameterBlock;
+ULONG EntrySize, BufferSize;
 
 /* Get the image headers and validate it */
 Status = RtlImageNtHeaderEx(0, ImageBase, ImageSize, );
@@ -1636,10 +1663,138 @@
   0);
 if ((Status != STATUS_BUFFER_TOO_SMALL) && (Status != STATUS_SUCCESS))
 {
+/* We failed due to an unknown reason -- bail out */
 return Status;
 }
 
-EfiPrintf(L"Memory map needs %lx bytes\n", MemoryParameters.BufferSize);
+/* Compute the list of the BCD plus the application entry */
+EntrySize = BlGetBootOptionListSize(>BcdData) +
+FIELD_OFFSET(BL_APPLICATION_ENTRY, BcdData);
+
+/* Compute the total size required for the entire structure */
+BufferSize = EntrySize +
+ BlpBootDevice->Size +
+ MemoryParameters.BufferSize +
+ sizeof(*ReturnArguments) +
+ sizeof(*MemoryData) + 
+ sizeof(*FirmwareParameters) + 
+ sizeof(*ParameterBlock);
+
+  

[ros-diffs] [ion] 73691: [BOOTLIB]: Implement BlMmGetMemoryMap. [BOOTLIB]: Implement MmMdCountList, MmMdInitializeList, MmMdCopyList [BOOTLIB]: Bugfixes.

2017-02-04 Thread ion
Author: ion
Date: Sun Feb  5 01:54:52 2017
New Revision: 73691

URL: http://svn.reactos.org/svn/reactos?rev=73691=rev
Log:
[BOOTLIB]: Implement BlMmGetMemoryMap.
[BOOTLIB]: Implement MmMdCountList, MmMdInitializeList, MmMdCopyList
[BOOTLIB]: Bugfixes.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/mm/descriptor.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?rev=73691=73690=73691=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
01:54:52 2017
@@ -91,6 +91,7 @@
 #define BL_MM_ADD_DESCRIPTOR_TRUNCATE_FLAG  0x02
 #define BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG0x10
 #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG0x20
+#define BL_MM_ADD_DESCRIPTOR_ALLOCATE_FLAG  0x1000
 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG   0x2000
 
 #define BL_MM_INCLUDE_MAPPED_ALLOCATED  0x01
@@ -101,7 +102,22 @@
 #define BL_MM_INCLUDE_BAD_MEMORY0x20
 #define BL_MM_INCLUDE_FIRMWARE_MEMORY   0x40
 #define BL_MM_INCLUDE_TRUNCATED_MEMORY  0x80
-#define BL_MM_INCLUDE_PERSISTEND_MEMORY 0x100
+#define BL_MM_INCLUDE_PERSISTENT_MEMORY 0x100
+#define BL_MM_INCLUDE_FIRMWARE_MEMORY_2 0x200
+
+#define BL_MM_INCLUDE_NO_FIRMWARE_MEMORY
(BL_MM_INCLUDE_PERSISTENT_MEMORY | \
+ 
BL_MM_INCLUDE_TRUNCATED_MEMORY | \
+ 
BL_MM_INCLUDE_BAD_MEMORY | \
+ 
BL_MM_INCLUDE_RESERVED_ALLOCATED | \
+ 
BL_MM_INCLUDE_UNMAPPED_UNALLOCATED | \
+ 
BL_MM_INCLUDE_UNMAPPED_ALLOCATED | \
+ 
BL_MM_INCLUDE_MAPPED_UNALLOCATED | \
+ 
BL_MM_INCLUDE_MAPPED_ALLOCATED)
+C_ASSERT(BL_MM_INCLUDE_NO_FIRMWARE_MEMORY == 0x1BF);
+
+#define BL_MM_INCLUDE_ONLY_FIRMWARE_MEMORY  
(BL_MM_INCLUDE_FIRMWARE_MEMORY_2 | \
+ 
BL_MM_INCLUDE_FIRMWARE_MEMORY)
+C_ASSERT(BL_MM_INCLUDE_ONLY_FIRMWARE_MEMORY == 0x240);
 
 #define BL_MM_REQUEST_DEFAULT_TYPE  1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE 2
@@ -1285,6 +1301,7 @@
 InitializeListHead(>ListHead);
 List->First = >ListHead;
 List->This = NULL;
+List->Type = 0;
 }
 
 /* INITIALIZATION ROUTINES ***/
@@ -1961,6 +1978,28 @@
 );
 
 /* MEMORY DESCRIPTOR ROUTINES /
+
+VOID
+MmMdInitializeList (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST DescriptorList,
+_In_ ULONG Type,
+_In_ PLIST_ENTRY ListHead
+);
+
+NTSTATUS
+MmMdCopyList (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST DestinationList,
+_In_ PBL_MEMORY_DESCRIPTOR_LIST SourceList,
+_In_opt_ PBL_MEMORY_DESCRIPTOR ListDescriptor,
+_Out_ PULONG ActualCount,
+_In_ ULONG Count,
+_In_ ULONG Flags
+);
+
+ULONG
+MmMdCountList (
+_In_ PBL_MEMORY_DESCRIPTOR_LIST MdList
+);
 
 VOID
 MmMdFreeList(
@@ -2074,6 +2113,14 @@
 NTSTATUS
 BlMmRemoveBadMemory (
 VOID
+);
+
+NTSTATUS
+BlMmGetMemoryMap (
+_In_ PLIST_ENTRY MemoryMap,
+_In_ PBL_IMAGE_PARAMETERS MemoryParameters,
+_In_ ULONG WhichTypes,
+_In_ ULONG Flags
 );
 
 /* VIRTUAL MEMORY ROUTINES ***/
@@ -2558,7 +2605,18 @@
 extern PVOID DspRemoteInputConsole;
 extern PVOID DspLocalInputConsole;
 extern WCHAR BlScratchBuffer[8192];
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedAllocated;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlMappedUnallocated;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlFwAllocationTracker;
 extern BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedAllocated;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlUnmappedUnallocated;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlReservedAllocated;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlBadMemory;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlTruncatedMemory;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlPersistentMemory;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlCompleteBadMemory;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlFreeVirtual;
+extern BL_MEMORY_DESCRIPTOR_LIST MmMdlMappingTrackers;
 extern ULONGLONG BlpTimePerformanceFrequency;
 extern LIST_ENTRY RegisteredFileSystems;
 

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/sv

[ros-diffs] [ion] 73689: [BOOTLIB]: Fix from hermes for BlReplaceBootOptions [BOOTLIB]: More WIP transfer code.

2017-02-04 Thread ion
Author: ion
Date: Sun Feb  5 00:05:19 2017
New Revision: 73689

URL: http://svn.reactos.org/svn/reactos?rev=73689=rev
Log:
[BOOTLIB]: Fix from hermes for BlReplaceBootOptions
[BOOTLIB]: More WIP transfer code.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/bcdopt.c
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/misc/util.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73689=73688=73689=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Feb  5 
00:05:19 2017
@@ -92,6 +92,16 @@
 #define BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG0x10
 #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG0x20
 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG   0x2000
+
+#define BL_MM_INCLUDE_MAPPED_ALLOCATED  0x01
+#define BL_MM_INCLUDE_MAPPED_UNALLOCATED0x02
+#define BL_MM_INCLUDE_UNMAPPED_ALLOCATED0x04
+#define BL_MM_INCLUDE_UNMAPPED_UNALLOCATED  0x08
+#define BL_MM_INCLUDE_RESERVED_ALLOCATED0x10
+#define BL_MM_INCLUDE_BAD_MEMORY0x20
+#define BL_MM_INCLUDE_FIRMWARE_MEMORY   0x40
+#define BL_MM_INCLUDE_TRUNCATED_MEMORY  0x80
+#define BL_MM_INCLUDE_PERSISTEND_MEMORY 0x100
 
 #define BL_MM_REQUEST_DEFAULT_TYPE  1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE 2

Modified: trunk/reactos/boot/environ/lib/misc/bcdopt.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcdopt.c?rev=73689=73688=73689=diff
==
--- trunk/reactos/boot/environ/lib/misc/bcdopt.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/bcdopt.c[iso-8859-1] Sun Feb  5 
00:05:19 2017
@@ -821,14 +821,15 @@
 NTSTATUS
 BlReplaceBootOptions (
 _In_ PBL_LOADED_APPLICATION_ENTRY AppEntry,
-_In_ PBL_BCD_OPTION NewOptions
-)
-{
-NTSTATUS Status;
-ULONG Size;
+_In_ PBL_BCD_OPTION OldOptions
+)
+{
+NTSTATUS Status;
+ULONG OptionSize;
+PBL_BCD_OPTION NewOptions;
 
 /* Make sure there's something to replace with */
-if (!NewOptions)
+if (!OldOptions)
 {
 return STATUS_INVALID_PARAMETER;
 }
@@ -849,17 +850,17 @@
 AppEntry->BcdData = NULL;
 
 /* Get the size of the new list of options */
-Size = BlGetBootOptionListSize(NewOptions);
+OptionSize = BlGetBootOptionListSize(OldOptions);
 
 /* Allocate a copy of the new list */
-NewOptions = BlMmAllocateHeap(Size);
+NewOptions = BlMmAllocateHeap(OptionSize);
 if (!NewOptions)
 {
 return STATUS_NO_MEMORY;
 }
 
 /* Copy it in */
-RtlCopyMemory(NewOptions, NewOptions, Size);
+RtlCopyMemory(NewOptions, OldOptions, OptionSize);
 
 /* Set it as the new set of options and return */
 AppEntry->Flags |= BL_APPLICATION_ENTRY_BCD_OPTIONS_INTERNAL;

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73689=73688=73689=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sun Feb  5 
00:05:19 2017
@@ -1605,6 +1605,17 @@
 }
 
 NTSTATUS
+BlMmGetMemoryMap (
+_In_ PLIST_ENTRY MemoryMap,
+_In_ PBL_IMAGE_PARAMETERS ImageParameters,
+_In_ ULONG WhichTypes,
+_In_ ULONG Flags
+)
+{
+return STATUS_SUCCESS;
+}
+
+NTSTATUS
 ImgpInitializeBootApplicationParameters (
 _In_ PBL_IMAGE_PARAMETERS ImageParameters,
 _In_ PBL_APPLICATION_ENTRY AppEntry,
@@ -1612,6 +1623,32 @@
 _In_ ULONG ImageSize
 )
 {
+NTSTATUS Status;
+PIMAGE_NT_HEADERS NtHeaders;
+BL_IMAGE_PARAMETERS MemoryParameters;
+LIST_ENTRY MemoryList;
+
+Status = RtlImageNtHeaderEx(0, ImageBase, ImageSize, );
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
+
+MemoryParameters.BufferSize = 0;
+
+Status = BlMmGetMemoryMap(,
+  ,
+  BL_MM_INCLUDE_FIRMWARE_MEMORY |
+  BL_MM_INCLUDE_MAPPED_ALLOCATED |
+  BL_MM_INCLUDE_MAPPED_UNALLOCATED |
+  BL_MM_INCLUDE_UNMAPPED_ALLOCATED |
+  BL_MM_INCLUDE_RESERVED_ALLOCATED,
+  0);
+if ((Status != STATUS_BUFFER_TOO_SMALL) && (Status != STATUS_SUCCESS))
+{
+return Status;
+}
+
 return STATUS_SUCCESS;
 }
 
@@ -16

[ros-diffs] [ion] 73687: [BOOTLIB]: Begin adding support for transferring to newly loaded i386 image.

2017-02-04 Thread ion
Author: ion
Date: Sat Feb  4 21:59:52 2017
New Revision: 73687

URL: http://svn.reactos.org/svn/reactos?rev=73687=rev
Log:
[BOOTLIB]: Begin adding support for transferring to newly loaded i386 image.

Added:
trunk/reactos/boot/environ/lib/arch/i386/transfer.s   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=73687=73686=73687=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Sat Feb  4 
21:59:52 2017
@@ -45,7 +45,7 @@
 
 if(ARCH STREQUAL "i386")
 list(APPEND BOOTLIB_ASM_SOURCE
- #lib/arch/i386/foo.asm
+ lib/arch/i386/transfer.s
  )
 list(APPEND BOOTLIB_SOURCE
  lib/arch/i386/arch.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=73687=73686=73687=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sat Feb  4 
21:59:52 2017
@@ -283,6 +283,7 @@
 BlLoaderPageDirectory = 0xD006,
 BlLoaderReferencePage = 0xD007,
 BlLoaderRamDisk = 0xD008,
+BlLoaderArchData = 0xD009,
 BlLoaderData = 0xD00A,
 BlLoaderRegistry = 0xD00B,
 BlLoaderBlockMemory = 0xD00C,
@@ -1180,6 +1181,13 @@
 ULONG ImageSize;
 } BL_IMAGE_APPLICATION_ENTRY, *PBL_IMAGE_APPLICATION_ENTRY;
 
+typedef struct _BL_IMAGE_PARAMETERS
+{
+PVOID Buffer;
+ULONG ActualSize;
+ULONG BufferSize;
+} BL_IMAGE_PARAMETERS, *PBL_IMAGE_PARAMETERS;
+
 typedef struct _BL_DEFERRED_FONT_FILE
 {
 LIST_ENTRY ListEntry;
@@ -1935,6 +1943,11 @@
 VOID
 BlpArchSwitchContext (
 _In_ BL_ARCH_MODE NewMode
+);
+
+VOID
+Archx86TransferTo32BitApplicationAsm (
+VOID
 );
 
 /* MEMORY DESCRIPTOR ROUTINES /

Added: trunk/reactos/boot/environ/lib/arch/i386/transfer.s
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/arch/i386/transfer.s?rev=73687
==
--- trunk/reactos/boot/environ/lib/arch/i386/transfer.s (added)
+++ trunk/reactos/boot/environ/lib/arch/i386/transfer.s [iso-8859-1] Sat Feb  4 
21:59:52 2017
@@ -0,0 +1,81 @@
+/*
+ * COPYRIGHT:   See COPYING.ARM in the top level directory
+ * PROJECT: ReactOS UEFI Boot Library
+ * FILE:boot/environ/lib/arch/transfer.asm
+ * PURPOSE: Boot Library i386 Transfer Functions
+ * PROGRAMMER:  Alex Ionescu (alex.ione...@reactos.org)
+ */
+
+/* INCLUDES **/
+
+#include 
+#include 
+
+EXTERN _GdtRegister:DWORD
+EXTERN _IdtRegister:DWORD
+EXTERN _BootAppGdtRegister:DWORD
+EXTERN _BootAppIdtRegister:DWORD
+EXTERN _BootApp32Stack:DWORD
+EXTERN _BootApp32EntryRoutine:DWORD
+EXTERN _BootApp32Parameters:DWORD
+
+/* FUNCTIONS /
+.code
+
+PUBLIC _Archx86TransferTo32BitApplicationAsm
+_Archx86TransferTo32BitApplicationAsm:
+
+/* Save non-volatile registers */
+push ebp
+push esi
+push edi
+push ebx
+ 
+/* Save data segments */
+push es
+push ds
+
+/* Save the old stack */
+mov ebx, esp
+
+/* Save current GDT/IDT, then load new one */
+sgdt fword ptr _GdtRegister
+sidt fword ptr _IdtRegister
+lgdt fword ptr _BootAppGdtRegister
+lidt fword ptr _BootAppIdtRegister
+
+/* Load the new stack */
+xor ebp, ebp
+mov esp, _BootApp32Stack
+
+/* Push old stack onto new stack */
+push ebx
+
+/* Call the entry routine, passing the parameters */
+mov eax, _BootApp32Parameters
+push eax
+mov eax, _BootApp32EntryRoutine
+call eax
+
+/* Retore old stack */
+pop ebx
+mov esp, ebx
+
+/* Restore old GDT/IDT */
+lgdt fword ptr _GdtRegister
+lidt fword ptr _IdtRegister
+
+/* Retore old segments */
+pop ds
+pop es
+
+/* Retore non-volatiles */
+pop ebx
+pop edi
+pop esi
+pop ebp
+
+/* All done */
+retn
+
+END

Propchange: trunk/reactos/boot/environ/lib/arch/i386/transfer.s
--
svn:eol-style = native

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73687=73686=73687=diff
==

[ros-diffs] [ion] 73685: [BOOTLIB]: Super cool that y'all went and fixed typos in the codebase, but fixing UEFI Official Specification Headers in our source tree is a bit much. Please submit a pull re

2017-02-04 Thread ion
Author: ion
Date: Sat Feb  4 20:45:02 2017
New Revision: 73685

URL: http://svn.reactos.org/svn/reactos?rev=73685=rev
Log:
[BOOTLIB]: Super cool that y'all went and fixed typos in the codebase, but 
fixing UEFI Official Specification Headers in our source tree is a bit much. 
Please submit a pull request to EDK-II if you'd like.

Modified:
trunk/reactos/boot/environ/include/efi/BlockIo.h
trunk/reactos/boot/environ/include/efi/ProcessorBind.h
trunk/reactos/boot/environ/include/efi/SimpleTextOut.h
trunk/reactos/boot/environ/include/efi/UefiSpec.h
trunk/reactos/boot/environ/include/efi/UgaDraw.h

Modified: trunk/reactos/boot/environ/include/efi/BlockIo.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/efi/BlockIo.h?rev=73685=73684=73685=diff
==
--- trunk/reactos/boot/environ/include/efi/BlockIo.h[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/efi/BlockIo.h[iso-8859-1] Sat Feb  4 
20:45:02 2017
@@ -96,7 +96,7 @@
   @retval EFI_WRITE_PROTECTED   The device can not be written to.
   @retval EFI_DEVICE_ERROR  The device reported an error while performing 
the write.
   @retval EFI_NO_MEDIA  There is no media in the device.
-  @retval EFI_MEDIA_CHANGED The MediaId does not match the current device.
+  @retval EFI_MEDIA_CHNAGED The MediaId does not matched the current 
device.
   @retval EFI_BAD_BUFFER_SIZE   The Buffer was not a multiple of the block 
size of the device.
   @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not 
valid, 
 or the buffer is not on proper alignment.
@@ -118,7 +118,7 @@
   @param  This  Indicates a pointer to the calling context.
 
   @retval EFI_SUCCESS   All outstanding data was written to the device
-  @retval EFI_DEVICE_ERROR  The device reported an error while writing back 
the data
+  @retval EFI_DEVICE_ERROR  The device reported an error while writting back 
the data
   @retval EFI_NO_MEDIA  There is no media in the device.
 
 **/
@@ -133,7 +133,7 @@
 **/
 typedef struct {
   ///
-  /// The current media Id. If the media changes, this value is changed.
+  /// The curent media Id. If the media changes, this value is changed.
   ///
   UINT32  MediaId; 

@@ -144,7 +144,7 @@
   
   ///
   /// TRUE if there is a media currently present in the device;
-  /// otherwise, FALSE. THis field shows the media present status
+  /// othersise, FALSE. THis field shows the media present status
   /// as of the most recent ReadBlocks() or WriteBlocks() call.  
   ///
   BOOLEAN MediaPresent;

Modified: trunk/reactos/boot/environ/include/efi/ProcessorBind.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/efi/ProcessorBind.h?rev=73685=73684=73685=diff
==
--- trunk/reactos/boot/environ/include/efi/ProcessorBind.h  [iso-8859-1] 
(original)
+++ trunk/reactos/boot/environ/include/efi/ProcessorBind.h  [iso-8859-1] 
Sat Feb  4 20:45:02 2017
@@ -79,7 +79,7 @@
 #pragma warning ( disable : 4057 )
 
 //
-// ASSERT(FALSE) or while (TRUE) are legal constructs so suppress this warning
+// ASSERT(FALSE) or while (TRUE) are legal constructes so supress this warning
 //
 #pragma warning ( disable : 4127 )
 

Modified: trunk/reactos/boot/environ/include/efi/SimpleTextOut.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/efi/SimpleTextOut.h?rev=73685=73684=73685=diff
==
--- trunk/reactos/boot/environ/include/efi/SimpleTextOut.h  [iso-8859-1] 
(original)
+++ trunk/reactos/boot/environ/include/efi/SimpleTextOut.h  [iso-8859-1] 
Sat Feb  4 20:45:02 2017
@@ -146,10 +146,10 @@
 #define EFI_WIDE_ATTRIBUTE  0x80
 
 /**
-Reset the text output device hardware and optionally run diagnostics
+Reset the text output device hardware and optionaly run diagnostics
 
 @param  This The protocol instance pointer.
-@param  ExtendedVerification Driver may perform more exhaustive verification
+@param  ExtendedVerification Driver may perform more exhaustive verfication
 operation of the device during reset.
 
 @retval EFI_SUCCESS  The text output device was reset.
@@ -368,7 +368,7 @@
 ///
 INT32   CursorRow;
 ///
-/// The cursor is currently visible or not.
+/// The cursor is currently visbile or not.
 ///
 BOOLEAN CursorVisible;
 } EFI_SIMPLE_TEXT_OUTPUT_MODE;

Modified: trunk/reactos/boot/environ/include/efi/UefiSpec.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/efi/UefiSpec.h?rev=73685=73684=73685=diff
==
--- trunk/reactos/boot/environ/include/efi/UefiSpec.h   [iso-8859-1] (original)
+++ trunk/reactos/boot

[ros-diffs] [ion] 73684: [BOOTMGR]: ThFabba making me jealous. Fix a logic bug that Coverity *didn't* find. Ha. I'm better. [BOOTLIB]: Apply the "Fuck You Binutils" hack only for ld-generated files, t

2017-02-04 Thread ion
Author: ion
Date: Sat Feb  4 19:45:38 2017
New Revision: 73684

URL: http://svn.reactos.org/svn/reactos?rev=73684=rev
Log:
[BOOTMGR]: ThFabba making me jealous. Fix a logic bug that Coverity *didn't* 
find. Ha. I'm better.
[BOOTLIB]: Apply the "Fuck You Binutils" hack only for ld-generated files, to 
unbreak MSVC UEFI boot.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=73684=73683=73684=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sat Feb  4 
19:45:38 2017
@@ -2276,7 +2276,7 @@
BcdLibraryDevice_ApplicationDevice,
,
NULL);
-if (NT_SUCCESS(Status))
+if (!NT_SUCCESS(Status))
 {
 /* Force re-enumeration */
 Status = BlFwEnumerateDevice(AppDevice);

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=73684=73683=73684=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Sat Feb  4 
19:45:38 2017
@@ -883,7 +883,6 @@
 
 /* Record our current position (right after the headers) */
 EndOfHeaders = (ULONG_PTR)VirtualAddress + HeaderSize;
-EfiPrintf(L"here\r\n");
 
 /* Get the first section and iterate through each one */
 Section = IMAGE_FIRST_SECTION(NtHeaders);
@@ -981,17 +980,20 @@
 if (!First)
 {
 /* FUCK YOU BINUTILS */
-if ((*(PULONG)>Name == 'ler.') && (RawSize < 
AlignSize))
+if (NtHeaders->OptionalHeader.MajorLinkerVersion < 7)
 {
-/* Piece of shit won't build relocations when you tell it 
to,
- * either by using --emit-relocs or --dynamicbase. People 
online
- * have found out that by using -pie-executable you can 
get this
- * to happen, but then it turns out that the .reloc 
section is
- * incorrectly sized, and results in a corrupt PE. 
However, they
- * still compute the checksum using the correct value. 
What idiots.
- */
-WorkaroundForBinutils = AlignSize - RawSize;
-AlignSize -= WorkaroundForBinutils;
+if ((*(PULONG)>Name == 'ler.') && (RawSize < 
AlignSize))
+{
+/* Piece of shit won't build relocations when you tell 
it to,
+ * either by using --emit-relocs or --dynamicbase. 
People online
+ * have found out that by using -pie-executable you 
can get this
+ * to happen, but then it turns out that the .reloc 
section is
+ * incorrectly sized, and results in a corrupt PE. 
However, they
+ * still compute the checksum using the correct value. 
What idiots.
+ */
+WorkaroundForBinutils = AlignSize - RawSize;
+AlignSize -= WorkaroundForBinutils;
+}
 }
 
 /* Yes, read the section data */




[ros-diffs] [ion] 73682: [CONFIGURE]: Better fix thanks to gigaherz.

2017-02-04 Thread ion
Author: ion
Date: Sat Feb  4 18:55:47 2017
New Revision: 73682

URL: http://svn.reactos.org/svn/reactos?rev=73682=rev
Log:
[CONFIGURE]: Better fix thanks to gigaherz.

Modified:
trunk/reactos/configure.cmd

Modified: trunk/reactos/configure.cmd
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/configure.cmd?rev=73682=73681=73682=diff
==
--- trunk/reactos/configure.cmd [iso-8859-1] (original)
+++ trunk/reactos/configure.cmd [iso-8859-1] Sat Feb  4 18:55:47 2017
@@ -58,7 +58,7 @@
 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
-cl 2>&1 | find "19.10." > NUL && set VS_VERSION=14
+cl 2>&1 | find "19.10." > NUL && set VS_VERSION=15
 if not defined VS_VERSION (
 echo Error: Visual Studio version too old or version detection failed.
 endlocal
@@ -147,6 +147,15 @@
 ) else (
 set CMAKE_GENERATOR="Visual Studio 14"
 )
+) else if "!VS_VERSION!" == "15" (
+if "!ARCH!" == "amd64" (
+set CMAKE_GENERATOR="Visual Studio 15 Win64"
+) else if "!ARCH!" == "arm" (
+set CMAKE_GENERATOR="Visual Studio 15 ARM"
+set CMAKE_GENERATOR_HOST="Visual Studio 15"
+) else (
+set CMAKE_GENERATOR="Visual Studio 15"
+)
 )
 ) else if /I "%1" == "RTC" (
 echo Runtime checks enabled




[ros-diffs] [ion] 73680: [CONFIGURE]: Hack-support VS15 (VS 2017)

2017-02-04 Thread ion
Author: ion
Date: Sat Feb  4 17:59:32 2017
New Revision: 73680

URL: http://svn.reactos.org/svn/reactos?rev=73680=rev
Log:
[CONFIGURE]: Hack-support VS15 (VS 2017)

Modified:
trunk/reactos/configure.cmd

Modified: trunk/reactos/configure.cmd
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/configure.cmd?rev=73680=73679=73680=diff
==
--- trunk/reactos/configure.cmd [iso-8859-1] (original)
+++ trunk/reactos/configure.cmd [iso-8859-1] Sat Feb  4 17:59:32 2017
@@ -58,6 +58,7 @@
 cl 2>&1 | find "17.00." > NUL && set VS_VERSION=11
 cl 2>&1 | find "18.00." > NUL && set VS_VERSION=12
 cl 2>&1 | find "19.00." > NUL && set VS_VERSION=14
+cl 2>&1 | find "19.10." > NUL && set VS_VERSION=14
 if not defined VS_VERSION (
 echo Error: Visual Studio version too old or version detection failed.
 endlocal




[ros-diffs] [ion] 72896: [NTOS]: Handle two complex failure paths, one of which is apparently easily reproducible by ntdll:om test (I'm guessing some invalid object attribute). Thanks to Amine and len

2016-10-02 Thread ion
Author: ion
Date: Mon Oct  3 03:30:11 2016
New Revision: 72896

URL: http://svn.reactos.org/svn/reactos?rev=72896=rev
Log:
[NTOS]: Handle two complex failure paths, one of which is apparently easily 
reproducible by ntdll:om test (I'm guessing some invalid object attribute). 
Thanks to Amine and lentin. Haven't tested this, but hopefully fixes things 
(and doesn't leak).

Modified:
trunk/reactos/ntoskrnl/mm/ARM3/section.c

Modified: trunk/reactos/ntoskrnl/mm/ARM3/section.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/ARM3/section.c?rev=72896=72895=72896=diff
==
--- trunk/reactos/ntoskrnl/mm/ARM3/section.c[iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/ARM3/section.c[iso-8859-1] Mon Oct  3 
03:30:11 2016
@@ -2419,6 +2419,7 @@
 BOOLEAN FileLock = FALSE, KernelCall = FALSE;
 KIRQL OldIrql;
 PFILE_OBJECT File;
+BOOLEAN UserRefIncremented = FALSE;
 PVOID PreviousSectionPointer;
 
 /* Make the same sanity checks that the Nt interface should've validated */
@@ -2516,6 +2517,7 @@
 
 /* Write down that this CA is being created, and set it */
 ControlArea->u.Flags.BeingCreated = TRUE;
+ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
 PreviousSectionPointer = File->SectionObjectPointer;
 File->SectionObjectPointer->DataSectionObject = ControlArea;
 
@@ -2535,8 +2537,47 @@
  SectionPageProtection,
  AllocationAttributes,
  KernelCall);
+if (!NT_SUCCESS(Status))
+{
+/* Lock the PFN database while we play with the section pointers */
+OldIrql = KeAcquireQueuedSpinLock(LockQueuePfnLock);
+
+/* Reset the waiting-for-deletion event */
+ASSERT(ControlArea->WaitingForDeletion == NULL);
+ControlArea->WaitingForDeletion = NULL;
+
+/* Set the file pointer NULL flag */
+ASSERT(ControlArea->u.Flags.FilePointerNull == 0);
+ControlArea->u.Flags.FilePointerNull = TRUE;
+
+/* Delete the data section object */
+ASSERT((AllocationAttributes & SEC_IMAGE) == 0);
+File->SectionObjectPointer->DataSectionObject = NULL;
+
+/* No longer being created */
+ControlArea->u.Flags.BeingCreated = FALSE;
+
+/* We can release the PFN lock now */
+KeReleaseQueuedSpinLock(LockQueuePfnLock, OldIrql);
+
+/* Check if we locked and set the IRP */
+if (FileLock)
+{
+/* Undo */
+IoSetTopLevelIrp(NULL);
+//FsRtlReleaseFile(File);
+}
+
+/* Free the control area and de-ref the file object */
+ExFreePool(ControlArea);
+ObDereferenceObject(File);
+
+/* All done */
+return Status;
+}
+
+/* On success, we expect this */
 ASSERT(PreviousSectionPointer == File->SectionObjectPointer);
-ASSERT(NT_SUCCESS(Status));
 
 /* Check if a maximum size was specified */
 if (!InputMaximumSize->QuadPart)
@@ -2568,7 +2609,9 @@
 /* Set the size here, and read the control area */
 Section.SizeOfSection.QuadPart = NewSegment->SizeOfSegment;
 ControlArea = NewSegment->ControlArea;
-ASSERT(ControlArea->u.Flags.BeingCreated == 1);
+
+/* MiCreatePagingFileMap increments user references */
+UserRefIncremented = TRUE;
 }
 
 /* Did we already have a segment? */
@@ -2613,16 +2656,16 @@
 /* Check if this is a user-mode read-write non-image file mapping */
 if (!(FileObject) &&
 (SectionPageProtection & (PAGE_READWRITE | PAGE_EXECUTE_READWRITE)) &&
-(ControlArea->u.Flags.Image == 0) &&
-(ControlArea->FilePointer != NULL))
+!(ControlArea->u.Flags.Image) &&
+(ControlArea->FilePointer))
 {
 /* Add a reference and set the flag */
-Section.u.Flags.UserWritable = 1;
-InterlockedIncrement((PLONG)>WritableUserReferences);
+Section.u.Flags.UserWritable = TRUE;
+InterlockedIncrement((volatile 
LONG*)>WritableUserReferences);
 }
 
 /* Check for image mappings or page file mappings */
-if ((ControlArea->u.Flags.Image == 1) || !(ControlArea->FilePointer))
+if ((ControlArea->u.Flags.Image) || !(ControlArea->FilePointer))
 {
 /* Charge the segment size, and allocate a subsection */
 PagedCharge = sizeof(SECTION) + NewSegment->TotalNumberOfPtes * 
sizeof(MMPTE);
@@ -2657,7 +2700,39 @@
 PagedCharge,
 NonPagedCharge,
 (PVOID*));
-ASSERT(NT_SUCC

[ros-diffs] [ion] 70633: [BOOTLIB]: Cleanup, less magic.

2016-01-21 Thread ion
Author: ion
Date: Thu Jan 21 15:47:14 2016
New Revision: 70633

URL: http://svn.reactos.org/svn/reactos?rev=70633=rev
Log:
[BOOTLIB]: Cleanup, less magic.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/misc/util.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70633=70632=70633=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Jan 21 
15:47:14 2016
@@ -154,6 +154,12 @@
 #define BL_LOAD_PE_IMG_COMPUTE_HASH 0x10
 #define BL_LOAD_PE_IMG_CHECK_SUBSYSTEM  0x80
 #define BL_LOAD_PE_IMG_CHECK_FORCED_INTEGRITY   0x200
+
+#define BL_UTL_CHECKSUM_COMPLEMENT  0x1
+#define BL_UTL_CHECKSUM_ROTATE  0x2
+#define BL_UTL_CHECKSUM_NEGATE  0x4
+#define BL_UTL_CHECKSUM_UCHAR_BUFFER0x01
+#define BL_UTL_CHECKSUM_USHORT_BUFFER   0x02
 
 /* ENUMERATIONS **/
 
@@ -1618,6 +1624,14 @@
 NTSTATUS
 BlUtlRegisterProgressRoutine (
 VOID
+);
+
+ULONG
+BlUtlCheckSum (
+_In_ ULONG PartialSum,
+_In_ PUCHAR Buffer,
+_In_ ULONG Length,
+_In_ ULONG Flags
 );
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=70633=70632=70633=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Thu Jan 21 
15:47:14 2016
@@ -649,54 +649,6 @@
 
 /* Unallocate the image buffer */
 return BlImgUnallocateImageBuffer(ImageBase, ImageSize, ImageFlags);
-}
-
-unsigned int  BlUtlCheckSum(unsigned int PartialSum, PUCHAR Source, unsigned 
int Length, unsigned int Flags)
-{
-unsigned int Type; // eax@1
-int Type1; // eax@1
-unsigned int AlignedLength; // ebx@3
-unsigned int i; // ebx@21 MAPDST
-
-Type = Flags & 3;
-Type1 = Type - 1;
-if (Type1)
-{
-if (Type1 == 1)
-{
-PartialSum = (unsigned __int16)PartialSum;
-AlignedLength = Length & ~1;
-if (Length & ~1)
-{
-i = 0;
-do
-{
-PartialSum += *(unsigned __int16 *)[i];
-if (Flags & 0x1)
-PartialSum = (unsigned __int16)((PartialSum >> 16) + 
PartialSum);
-i += 2;
-} while (i < AlignedLength);
-}
-
-if (Length != AlignedLength)
-{
-PartialSum += (unsigned __int8)Source[AlignedLength];
-if (Flags & 0x1)
-PartialSum = (unsigned __int16)((PartialSum >> 16) + 
PartialSum);
-}
-if (Flags & 0x4)
-return ~PartialSum;
-PartialSum = (unsigned __int16)PartialSum;
-}
-}
-else
-{
-EfiPrintf(L"checksum type not supported\r\n");
-}
-
-if (Flags & 0x4)
-return ~PartialSum;
-return PartialSum;
 }
 
 NTSTATUS
@@ -921,7 +873,11 @@
 NtHeaders->OptionalHeader.CheckSum = 0;
 
 /* Calculate the checksum of the header, and restore the original one */
-PartialSum = BlUtlCheckSum(0, VirtualAddress, HeaderSize, 0x10002);
+PartialSum = BlUtlCheckSum(0,
+   VirtualAddress,
+   HeaderSize,
+   BL_UTL_CHECKSUM_COMPLEMENT |
+   BL_UTL_CHECKSUM_USHORT_BUFFER);
 NtHeaders->OptionalHeader.CheckSum = CheckSum;
 
 /* Record our current position (right after the headers) */
@@ -1037,7 +993,8 @@
 PartialSum = BlUtlCheckSum(PartialSum,
(PUCHAR)SectionStart,
AlignSize,
-   0x10002);
+   BL_UTL_CHECKSUM_COMPLEMENT |
+   BL_UTL_CHECKSUM_USHORT_BUFFER);
 }
 }
 
@@ -1114,7 +1071,8 @@
 PartialSum = BlUtlCheckSum(PartialSum,
LocalBuffer,
BytesRead,
-   0x10002);
+   BL_UTL_CHECKSUM_COMPLEMENT |
+   BL_UTL_CHECKSUM_USHORT_BUFFER);
 }
 
  

[ros-diffs] [ion] 70634: [RTL/NDK]: For some strange reason, we were missing LdrRelocateImage. Also we had the right type for LdrRelocateImageWithBias, but not the former. Fix that. [BOOTLIB]: Finish

2016-01-21 Thread ion
Author: ion
Date: Thu Jan 21 16:16:12 2016
New Revision: 70634

URL: http://svn.reactos.org/svn/reactos?rev=70634=rev
Log:
[RTL/NDK]: For some strange reason, we were missing LdrRelocateImage. Also we 
had the right type for LdrRelocateImageWithBias, but not the former. Fix that.
[BOOTLIB]: Finish the rest of the image loader. However, relocations appear to 
fail.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/include/ndk/ldrfuncs.h
trunk/reactos/lib/rtl/image.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70634=70633=70634=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Jan 21 
16:16:12 2016
@@ -153,7 +153,11 @@
 #define BL_LOAD_PE_IMG_EXISTING_BUFFER  
BL_LOAD_IMG_EXISTING_BUFFER 
 #define BL_LOAD_PE_IMG_COMPUTE_HASH 0x10
 #define BL_LOAD_PE_IMG_CHECK_SUBSYSTEM  0x80
+#define BL_LOAD_PE_IMG_SKIP_RELOCATIONS 0x100
 #define BL_LOAD_PE_IMG_CHECK_FORCED_INTEGRITY   0x200
+#define BL_LOAD_PE_IMG_IGNORE_CHECKSUM_MISMATCH 0x1
+#define BL_LOAD_PE_IMG_VALIDATE_ORIGINAL_FILENAME   0x40
+
 
 #define BL_UTL_CHECKSUM_COMPLEMENT  0x1
 #define BL_UTL_CHECKSUM_ROTATE  0x2

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=70634=70633=70634=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Thu Jan 21 
16:16:12 2016
@@ -656,33 +656,27 @@
 _In_ PBL_IMG_FILE ImageFile,
 _In_ BL_MEMORY_TYPE MemoryType,
 _Inout_ PVOID* ImageBase,
-_Out_ PULONG ImageSize,
+_Out_opt_ PULONG ImageSize,
 _Inout_opt_ PVOID Hash,
 _In_ ULONG Flags
 )
 {
 NTSTATUS Status;
 ULONG FileSize, HeaderSize;
-PVOID ImageBuffer;
 BL_IMG_FILE LocalFileBuffer;
 PBL_IMG_FILE LocalFile;
-PVOID VirtualAddress;
+PVOID VirtualAddress, PreferredBase, ImageBuffer, CertBuffer, HashBuffer;
 ULONGLONG VirtualSize;
+PIMAGE_DATA_DIRECTORY CertDirectory;
 PHYSICAL_ADDRESS PhysicalAddress;
 PIMAGE_NT_HEADERS NtHeaders;
-USHORT SectionCount;
-USHORT CheckSum, PartialSum;
+USHORT SectionCount, CheckSum, PartialSum, FinalSum;
 PIMAGE_SECTION_HEADER Section;
-ULONG_PTR EndOfHeaders, SectionStart;
-ULONG i;
-BOOLEAN First;
-ULONG_PTR Slack, SectionEnd;
-ULONG SectionSize, RawSize;
-ULONG BytesRead, RemainingLength;
+ULONG_PTR EndOfHeaders, SectionStart, Slack, SectionEnd;
+ULONG i, SectionSize, RawSize, BytesRead, RemainingLength, Offset, 
AlignSize;
+BOOLEAN First, ImageHashValid;
 UCHAR LocalBuffer[1024];
-USHORT FinalSum;
-ULONG Offset;
-ULONG AlignSize;
+UCHAR TrustedBootInformation[52];
 
 /* Initialize locals */
 LocalFile = NULL;
@@ -690,8 +684,13 @@
 FileSize = 0;
 First = FALSE;
 VirtualAddress = NULL;
+CertBuffer = NULL;
+CertDirectory = NULL;
+HashBuffer = NULL;
 Offset = 0;
 VirtualSize = 0;
+ImageHashValid = FALSE;
+RtlZeroMemory(, sizeof(TrustedBootInformation));
 
 /* Get the size of the image */
 Status = ImgpGetFileSize(ImageFile, );
@@ -1084,18 +1083,98 @@
 }
 
 /* If the checksum doesn't match, and caller is enforcing, bail out */
-EfiPrintf(L"Final checksum: %lx. Original: %lx\r\n", FinalSum, 
CheckSum);
-if ((FinalSum != CheckSum) && !(Flags & 0x1))
+if ((FinalSum != CheckSum) &&
+!(Flags & BL_LOAD_PE_IMG_IGNORE_CHECKSUM_MISMATCH))
 {
 Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
 goto Quickie;
 }
 }
 
+/* Check if the .rsrc section should be checked with the filename */
+if (Flags & BL_LOAD_PE_IMG_VALIDATE_ORIGINAL_FILENAME)
+{
+EfiPrintf(L"Not yet supported\r\n");
+Status = 0xC0430007; // STATUS_SECUREBOOT_FILE_REPLACED
+goto Quickie;
+}
+
+/* Check if we should relocate */
+if (!(Flags & BL_LOAD_PE_IMG_SKIP_RELOCATIONS))
+{
+/* Check if we loaded at a different address */
+PreferredBase = (PVOID)NtHeaders->OptionalHeader.ImageBase;
+if (VirtualAddress != PreferredBase)
+{
+/* Yep -- do relocations */
+Status = LdrRelocateImage(VirtualAddress,
+  "Boot Environment Lib

[ros-diffs] [ion] 70632: [BOOTLIB]: Implement checksum calculation for PE header sum. [BOOTLIB]: Implement most of ImgpLoadPEImage. The checksum of the mapped image file matches the checksum in the fl

2016-01-20 Thread ion
Author: ion
Date: Thu Jan 21 05:16:40 2016
New Revision: 70632

URL: http://svn.reactos.org/svn/reactos?rev=70632=rev
Log:
[BOOTLIB]: Implement checksum calculation for PE header sum.
[BOOTLIB]: Implement most of ImgpLoadPEImage. The checksum of the mapped image 
file matches the checksum in the flat PE file, meaning our load loop works as 
designed.
Next step are relocations and we'll be done.

Modified:
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=70632=70631=70632=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Thu Jan 21 
05:16:40 2016
@@ -651,6 +651,54 @@
 return BlImgUnallocateImageBuffer(ImageBase, ImageSize, ImageFlags);
 }
 
+unsigned int  BlUtlCheckSum(unsigned int PartialSum, PUCHAR Source, unsigned 
int Length, unsigned int Flags)
+{
+unsigned int Type; // eax@1
+int Type1; // eax@1
+unsigned int AlignedLength; // ebx@3
+unsigned int i; // ebx@21 MAPDST
+
+Type = Flags & 3;
+Type1 = Type - 1;
+if (Type1)
+{
+if (Type1 == 1)
+{
+PartialSum = (unsigned __int16)PartialSum;
+AlignedLength = Length & ~1;
+if (Length & ~1)
+{
+i = 0;
+do
+{
+PartialSum += *(unsigned __int16 *)[i];
+if (Flags & 0x1)
+PartialSum = (unsigned __int16)((PartialSum >> 16) + 
PartialSum);
+i += 2;
+} while (i < AlignedLength);
+}
+
+if (Length != AlignedLength)
+{
+PartialSum += (unsigned __int8)Source[AlignedLength];
+if (Flags & 0x1)
+PartialSum = (unsigned __int16)((PartialSum >> 16) + 
PartialSum);
+}
+if (Flags & 0x4)
+return ~PartialSum;
+PartialSum = (unsigned __int16)PartialSum;
+}
+}
+else
+{
+EfiPrintf(L"checksum type not supported\r\n");
+}
+
+if (Flags & 0x4)
+return ~PartialSum;
+return PartialSum;
+}
+
 NTSTATUS
 ImgpLoadPEImage (
 _In_ PBL_IMG_FILE ImageFile,
@@ -670,11 +718,28 @@
 ULONGLONG VirtualSize;
 PHYSICAL_ADDRESS PhysicalAddress;
 PIMAGE_NT_HEADERS NtHeaders;
+USHORT SectionCount;
+USHORT CheckSum, PartialSum;
+PIMAGE_SECTION_HEADER Section;
+ULONG_PTR EndOfHeaders, SectionStart;
+ULONG i;
+BOOLEAN First;
+ULONG_PTR Slack, SectionEnd;
+ULONG SectionSize, RawSize;
+ULONG BytesRead, RemainingLength;
+UCHAR LocalBuffer[1024];
+USHORT FinalSum;
+ULONG Offset;
+ULONG AlignSize;
 
 /* Initialize locals */
 LocalFile = NULL;
 ImageBuffer = NULL;
 FileSize = 0;
+First = FALSE;
+VirtualAddress = NULL;
+Offset = 0;
+VirtualSize = 0;
 
 /* Get the size of the image */
 Status = ImgpGetFileSize(ImageFile, );
@@ -846,6 +911,229 @@
 goto Quickie;
 }
 
+First = FALSE;
+
+/* Record how many sections we have */
+SectionCount = NtHeaders->FileHeader.NumberOfSections;
+
+/* Capture the current checksum and reset it */
+CheckSum = NtHeaders->OptionalHeader.CheckSum;
+NtHeaders->OptionalHeader.CheckSum = 0;
+
+/* Calculate the checksum of the header, and restore the original one */
+PartialSum = BlUtlCheckSum(0, VirtualAddress, HeaderSize, 0x10002);
+NtHeaders->OptionalHeader.CheckSum = CheckSum;
+
+/* Record our current position (right after the headers) */
+EndOfHeaders = (ULONG_PTR)VirtualAddress + HeaderSize;
+
+/* Get the first section and iterate through each one */
+Section = IMAGE_FIRST_SECTION(NtHeaders);
+for (i = 0; i < SectionCount; i++)
+{
+/* Compute where this section starts */
+SectionStart = (ULONG_PTR)VirtualAddress + Section->VirtualAddress;
+
+/* Make sure that the section fits within the image */
+if ((VirtualSize < Section->VirtualAddress) ||
+((PVOID)SectionStart < VirtualAddress))
+{
+Status = STATUS_INVALID_IMAGE_FORMAT;
+goto Quickie;
+}
+
+/* Check if there's slack space between header end and the section */
+if (!(First) && (EndOfHeaders < SectionStart))
+{
+/* Zero it out */
+Slack = SectionStart - EndOfHeaders;
+RtlZeroMemory((PVOID)EndOfHeaders, Slack);
+}
+
+/* Get the section virtual size and the raw size */
+SectionSize = Section->Misc.VirtualSize;
+RawSize = Section->SizeOf

[ros-diffs] [ion] 70630: [ROSLOAD]: SUBSYSTEM_WINDOWS_BOOT_APPLICATION is 16, not 14.

2016-01-20 Thread ion
Author: ion
Date: Wed Jan 20 17:00:51 2016
New Revision: 70630

URL: http://svn.reactos.org/svn/reactos?rev=70630=rev
Log:
[ROSLOAD]: SUBSYSTEM_WINDOWS_BOOT_APPLICATION is 16, not 14.

Modified:
trunk/reactos/boot/environ/CMakeLists.txt

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=70630=70629=70630=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Wed Jan 20 
17:00:51 2016
@@ -123,7 +123,7 @@
 if(MSVC)
 set_subsystem(rosload BOOT_APPLICATION)
 else()
-set_subsystem(rosload 14)
+set_subsystem(rosload 16)
 endif()
 
 set_entrypoint(rosload OslMain@4)




[ros-diffs] [ion] 70629: [BOOTLIB]: Begin PE loader. Works so far. Next up is loading the sections, zeroing out the .bss, and computing checksum.

2016-01-20 Thread ion
Author: ion
Date: Wed Jan 20 17:00:18 2016
New Revision: 70629

URL: http://svn.reactos.org/svn/reactos?rev=70629=rev
Log:
[BOOTLIB]: Begin PE loader. Works so far. Next up is loading the sections, 
zeroing out the .bss, and computing checksum.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70629=70628=70629=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Wed Jan 20 
17:00:18 2016
@@ -147,6 +147,13 @@
 #define BL_LOAD_IMG_UNKNOWN_BUFFER_FLAG 0x08
 #define BL_LOAD_IMG_COMPUTE_SIGNATURE   0x10
 #define BL_LOAD_IMG_COMPUTE_HASH0x4
+
+#define BL_LOAD_PE_IMG_VIRTUAL_BUFFER   
BL_LOAD_IMG_VIRTUAL_BUFFER
+#define BL_LOAD_PE_IMG_CHECK_MACHINE0x02
+#define BL_LOAD_PE_IMG_EXISTING_BUFFER  
BL_LOAD_IMG_EXISTING_BUFFER 
+#define BL_LOAD_PE_IMG_COMPUTE_HASH 0x10
+#define BL_LOAD_PE_IMG_CHECK_SUBSYSTEM  0x80
+#define BL_LOAD_PE_IMG_CHECK_FORCED_INTEGRITY   0x200
 
 /* ENUMERATIONS **/
 

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=70629=70628=70629=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Wed Jan 20 
17:00:18 2016
@@ -655,15 +655,240 @@
 ImgpLoadPEImage (
 _In_ PBL_IMG_FILE ImageFile,
 _In_ BL_MEMORY_TYPE MemoryType,
-_Out_ PVOID* ImageBase,
+_Inout_ PVOID* ImageBase,
 _Out_ PULONG ImageSize,
-_Out_ PVOID Hash,
+_Inout_opt_ PVOID Hash,
 _In_ ULONG Flags
 )
 {
-/* Micro-PE loader (no imports/exports/etc) */
-EfiPrintf(L"PE not implemented\r\n");
-return STATUS_NOT_IMPLEMENTED;
+NTSTATUS Status;
+ULONG FileSize, HeaderSize;
+PVOID ImageBuffer;
+BL_IMG_FILE LocalFileBuffer;
+PBL_IMG_FILE LocalFile;
+PVOID VirtualAddress;
+ULONGLONG VirtualSize;
+PHYSICAL_ADDRESS PhysicalAddress;
+PIMAGE_NT_HEADERS NtHeaders;
+
+/* Initialize locals */
+LocalFile = NULL;
+ImageBuffer = NULL;
+FileSize = 0;
+
+/* Get the size of the image */
+Status = ImgpGetFileSize(ImageFile, );
+if (!NT_SUCCESS(Status))
+{
+return STATUS_FILE_INVALID;
+}
+
+/* Allocate a flat buffer for it */
+Status = BlImgAllocateImageBuffer(, BlLoaderData, FileSize, 0);
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Read the whole file flat for now */
+Status = ImgpReadAtFileOffset(ImageFile, FileSize, 0, ImageBuffer, NULL);
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Build a local file handle */
+LocalFile = 
+LocalFileBuffer.FileName = ImageFile->FileName;
+LocalFileBuffer.Flags = BL_IMG_MEMORY_FILE | BL_IMG_VALID_FILE;
+LocalFileBuffer.BaseAddress = ImageBuffer;
+LocalFileBuffer.FileSize = FileSize;
+
+/* Get the NT headers of the file */
+Status = RtlImageNtHeaderEx(0, ImageBuffer, FileSize, );
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Check if we should validate the machine type */
+if (Flags & BL_LOAD_PE_IMG_CHECK_MACHINE)
+{
+/* Is it different than our current machine type? */
+#if _M_AMD64
+if (NtHeaders->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64)
+#else
+if (NtHeaders->FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
+#endif
+{
+/* Is it x86 (implying we are x64) ? */
+if (NtHeaders->FileHeader.Machine == IMAGE_FILE_MACHINE_I386)
+{
+/* Return special error code */
+Status = STATUS_INVALID_IMAGE_WIN_32;
+}
+else if (NtHeaders->FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64)
+{
+/* Otherwise, it's x64 but we are x86 */
+Status = STATUS_INVALID_IMAGE_WIN_64;
+}
+else
+{
+/* Or it's ARM or something... */
+Status = STATUS_INVALID_IMAGE_FORMAT;
+}
+
+/* Return with the distinguished error code */
+goto Quickie;
+}
+}
+
+/* Check if we should validate the subsystem */
+if (Flags & BL_LOAD_PE_IMG_CHECK_SUBSYSTEM)
+{
+/* It must be a Windows boot Application */
+if (Nt

[ros-diffs] [ion] 70631: [DDK]: SVN isn't GIT alex. It's not smart enough to commit the entire tree, only the place where you right-clicked.

2016-01-20 Thread ion
Author: ion
Date: Wed Jan 20 17:01:53 2016
New Revision: 70631

URL: http://svn.reactos.org/svn/reactos?rev=70631=rev
Log:
[DDK]: SVN isn't GIT alex. It's not smart enough to commit the entire tree, 
only the place where you right-clicked.

Modified:
trunk/reactos/include/ddk/ntimage.h

Modified: trunk/reactos/include/ddk/ntimage.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/ntimage.h?rev=70631=70630=70631=diff
==
--- trunk/reactos/include/ddk/ntimage.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/ntimage.h [iso-8859-1] Wed Jan 20 17:01:53 2016
@@ -430,16 +430,38 @@
((NtHeader))->FileHeader.SizeOfOptionalHeader))
 
 //
+// Subsystems
+//
+#define IMAGE_SUBSYSTEM_UNKNOWN 0 
+#define IMAGE_SUBSYSTEM_NATIVE  1
+#define IMAGE_SUBSYSTEM_WINDOWS_GUI 2
+#define IMAGE_SUBSYSTEM_WINDOWS_CUI 3
+#define IMAGE_SUBSYSTEM_OS2_CUI 5
+#define IMAGE_SUBSYSTEM_POSIX_CUI   7
+#define IMAGE_SUBSYSTEM_NATIVE_WINDOWS  8
+#define IMAGE_SUBSYSTEM_WINDOWS_CE_GUI  9
+#define IMAGE_SUBSYSTEM_EFI_APPLICATION 10
+#define IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER 11
+#define IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER  12
+#define IMAGE_SUBSYSTEM_EFI_ROM 13
+#define IMAGE_SUBSYSTEM_XBOX14
+#define IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION16
+#define IMAGE_SUBSYSTEM_XBOX_CODE_CATALOG   17
+
+//
 // Dll Characteristics
 //
-#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE  0x0040
-#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY   0x0080
-#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT 0x0100
-#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION  0x0200
-#define IMAGE_DLLCHARACTERISTICS_NO_SEH0x0400
-#define IMAGE_DLLCHARACTERISTICS_NO_BIND   0x0800
-#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER0x2000
-#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE 0x8000
+#define IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA0x0020
+#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE   0x0040
+#define IMAGE_DLLCHARACTERISTICS_FORCE_INTEGRITY0x0080
+#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT  0x0100
+#define IMAGE_DLLCHARACTERISTICS_NO_ISOLATION   0x0200
+#define IMAGE_DLLCHARACTERISTICS_NO_SEH 0x0400
+#define IMAGE_DLLCHARACTERISTICS_NO_BIND0x0800
+#define IMAGE_DLLCHARACTERISTICS_APPCONTAINER   0x1000
+#define IMAGE_DLLCHARACTERISTICS_WDM_DRIVER 0x2000
+#define IMAGE_DLLCHARACTERISTICS_GUARD_CF   0x4000
+#define IMAGE_DLLCHARACTERISTICS_TERMINAL_SERVER_AWARE  0x8000
 
 //
 // Loader Flags




[ros-diffs] [ion] 70618: [BOOTMGR]: Support for launching a recovery sequence. [BOOTMGR]: Stub support for boot errors. [BOOTMGR]: Stubplement support for device creation for boot applications (only f

2016-01-19 Thread ion
Author: ion
Date: Tue Jan 19 18:21:54 2016
New Revision: 70618

URL: http://svn.reactos.org/svn/reactos?rev=70618=rev
Log:
[BOOTMGR]: Support for launching a recovery sequence.
[BOOTMGR]: Stub support for boot errors.
[BOOTMGR]: Stubplement support for device creation for boot applications (only 
for fully specified devices)
[BOOTMGR]: Implement support for execution transfer, including recovery 
mode/sequence.
[BOOTMGR]: Implement support for launching a boot entry.
[BOOTLIB]: Support for EFI Firmware device enumeration, driver attachment, and 
comparison.
[BOOTLIB]: Support for appending BOOLEAN or INTEGER BCD options.
Next step is the PE loader.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/misc/bcdopt.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70618=70617=70618=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Tue Jan 19 
18:21:54 2016
@@ -1,7 +1,7 @@
 /*
  * COPYRIGHT:   See COPYING.ARM in the top level directory
  * PROJECT: ReactOS UEFI Boot Manager
- * FILE:boot/environ/app/bootmgr/bootmgr.c
+ * FILE:boot/environ/app/bootmgr/bootmgr.cla
  * PURPOSE: Boot Manager Entrypoint
  * PROGRAMMER:  Alex Ionescu (alex.ione...@reactos.org)
  */
@@ -2033,13 +2033,562 @@
 BmpLaunchBootEntry (
 _In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
 _Out_ PULONG EntryIndex,
-_In_ ULONG Unknown,
+_In_ ULONG LaunchCode,
 _In_ BOOLEAN LaunchWinRe
-)
-{
-EfiPrintf(L"Boot launch not yet implemented\r\n");
-EfiStall(10);
+);
+
+NTSTATUS 
+BmLaunchRecoverySequence (
+_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
+_In_ ULONG LaunchCode
+)
+{
+NTSTATUS Status;
+PBL_LOADED_APPLICATION_ENTRY RecoveryEntry;
+HANDLE BcdHandle;
+PGUID RecoverySequence;
+ULONG Count, i, RecoveryIndex, SequenceCount;
+PBL_LOADED_APPLICATION_ENTRY* Sequence;
+
+RecoveryIndex = 0;
+Sequence = NULL;
+RecoverySequence = NULL;
+Count = 0;
+BcdHandle = NULL;
+
+Status = BmOpenDataStore();
+if (NT_SUCCESS(Status))
+{
+Status = BlGetBootOptionGuidList(BootEntry->BcdData,
+ BcdLibraryObjectList_RecoverySequence,
+ ,
+ );
+if (NT_SUCCESS(Status))
+{
+Status = BmGetBootSequence(BcdHandle,
+   RecoverySequence,
+   SequenceCount,
+   BL_APPLICATION_ENTRY_RECOVERY,
+   ,
+   );
+if (NT_SUCCESS(Status))
+{
+if (BcdHandle)
+{
+BmCloseDataStore(BcdHandle);
+}
+
+for (i = 0; i < Count; ++i)
+{
+if (LaunchCode == 2 || LaunchCode == 5)
+{
+BlRemoveBootOption(Sequence[i]->BcdData, 
BcdLibraryInteger_DisplayMessageOverride);
+BlAppendBootOptionInteger(Sequence[i],
+  
BcdLibraryInteger_DisplayMessageOverride,
+  4);
+}
+else if (LaunchCode == 3)
+{
+BlRemoveBootOption(Sequence[i]->BcdData, 
BcdLibraryInteger_DisplayMessageOverride);
+BlAppendBootOptionInteger(Sequence[i],
+  
BcdLibraryInteger_DisplayMessageOverride,
+  10);
+}
+
+Status = BmpLaunchBootEntry(Sequence[i], NULL, LaunchCode, 
FALSE);
+if (!NT_SUCCESS(Status))
+{
+break;
+}
+}
+}
+
+if (Sequence)
+{
+for (RecoveryIndex = 0; RecoveryIndex < Count; RecoveryIndex++)
+{
+RecoveryEntry = Sequence[RecoveryIndex];
+if (RecoveryEntry)
+{
+BlDestroyBootEntry(RecoveryEntry);
+}
+}
+BlMmFreeHeap(Sequence);
+}
+}
+
+   

[ros-diffs] [ion] 70621: [BOOTLIB]: Rough sketches of BlImgLoadBootApplication, BlImgStartBootApplication, BlImgUnLoadBootApplication.

2016-01-19 Thread ion
Author: ion
Date: Wed Jan 20 01:28:50 2016
New Revision: 70621

URL: http://svn.reactos.org/svn/reactos?rev=70621=rev
Log:
[BOOTLIB]: Rough sketches of BlImgLoadBootApplication, 
BlImgStartBootApplication, BlImgUnLoadBootApplication.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/platform/time.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70621=70620=70621=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Wed Jan 20 
01:28:50 2016
@@ -1083,30 +1083,6 @@
 return STATUS_SUCCESS;
 }
 
-VOID
-BlImgQueryCodeIntegrityBootOptions (
-_In_ PBL_LOADED_APPLICATION_ENTRY ApplicationEntry,
-_Out_ PBOOLEAN IntegrityChecksDisabled, 
-_Out_ PBOOLEAN TestSigningEnabled
-)
-{
-
-NTSTATUS Status;
-BOOLEAN Value;
-
-/* Check if /DISABLEINTEGRITYCHECKS is on */
-Status = BlGetBootOptionBoolean(ApplicationEntry->BcdData,
-BcdLibraryBoolean_DisableIntegrityChecks,
-);
-*IntegrityChecksDisabled = NT_SUCCESS(Status) && (Value);
-
-/* Check if /TESTSIGNING is on */
-Status = BlGetBootOptionBoolean(ApplicationEntry->BcdData,
-
BcdLibraryBoolean_AllowPrereleaseSignatures,
-);
-*TestSigningEnabled = NT_SUCCESS(Status) && (Value);
-}
-
 NTSTATUS
 BmFwVerifySelfIntegrity (
 VOID
@@ -2212,38 +2188,6 @@
 return STATUS_SUCCESS;
 }
 
-/* MOVE TO IMAGe.C */
-NTSTATUS
-BlImgLoadBootApplication (
-_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
-_Out_ PHANDLE AppHandle
-)
-{
-EfiPrintf(L"Loading application %p\r\n", BootEntry);
-
-return STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS
-BlImgStartBootApplication (
-_In_ HANDLE AppHandle,
-_Inout_ PBL_RETURN_ARGUMENTS ReturnArguments
-)
-{
-EfiPrintf(L"Starting application %p\r\n", AppHandle);
-
-return STATUS_NOT_IMPLEMENTED;
-}
-
-NTSTATUS
-BlImgUnloadBootApplication (
-_In_ HANDLE AppHandle
-)
-{
-EfiPrintf(L"Unloading application %p\r\n", AppHandle);
-
-return STATUS_NOT_IMPLEMENTED;
-}
 
 NTSTATUS
 BmpTransferExecution (
@@ -2257,7 +2201,7 @@
 PBL_DEVICE_DESCRIPTOR AppDevice;
 BL_RETURN_ARGUMENTS ReturnArgs;
 BOOLEAN AdvancedOptions;
-HANDLE AppHandle;
+ULONG AppHandle;
 
 Status = BlGetBootOptionString(BootEntry->BcdData,
BcdLibraryString_ApplicationPath,

Modified: trunk/reactos/boot/environ/include/bcd.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bcd.h?rev=70621=70620=70621=diff
==
--- trunk/reactos/boot/environ/include/bcd.h[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bcd.h[iso-8859-1] Wed Jan 20 
01:28:50 2016
@@ -94,6 +94,7 @@
 BcdLibraryInteger_GraphicsResolution = 0x1552,
 BcdLibraryInteger_DisplayMessage = 0x1565, /* Undocumented */
 BcdLibraryInteger_DisplayMessageOverride = 0x1566, /* Undocumented */
+BcdLibraryInteger_UndocumentedMagic = 0x1575, /* Undocumented magic */
 BcdLibraryBoolean_RestartOnFailure = 0x1653,
 BcdLibraryBoolean_GraphicsForceHighestMode = 0x1654,
 BcdLibraryBoolean_IsolatedExecutionContext = 0x1660,

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70621=70620=70621=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Wed Jan 20 
01:28:50 2016
@@ -1139,6 +1139,13 @@
 PWCHAR FileName;
 } BL_IMG_FILE, *PBL_IMG_FILE;
 
+typedef struct _BL_IMAGE_APPLICATION_ENTRY
+{
+PBL_APPLICATION_ENTRY AppEntry;
+PVOID ImageBase;
+ULONG ImageSize;
+} BL_IMAGE_APPLICATION_ENTRY, *PBL_IMAGE_APPLICATION_ENTRY;
+
 typedef struct _BL_DEFERRED_FONT_FILE
 {
 LIST_ENTRY ListEntry;
@@ -1464,6 +1471,11 @@
 VOID
 );
 
+ULONGLONG
+BlTimeQueryPerformanceCounter (
+_Out_opt_ PLARGE_INTEGER Frequency
+);
+
 /* RESOURCE LOCALE INTERNATIONALIZATION ROUTINES */
 
 NTSTATUS
@@ -2134,6 +2146,30 @@
 BlImgFindSection (
 _In_ PVOID ImageBase,
 _In_ ULONG ImageSize
+);
+
+NTSTATUS
+BlImgLoadBootApplication (
+

[ros-diffs] [ion] 70623: [BOOTMGR]: Cleanup, less magic, one bug fix.

2016-01-19 Thread ion
Author: ion
Date: Wed Jan 20 02:58:39 2016
New Revision: 70623

URL: http://svn.reactos.org/svn/reactos?rev=70623=rev
Log:
[BOOTMGR]: Cleanup, less magic, one bug fix.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/include/bl.h

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70623=70622=70623=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Wed Jan 20 
02:58:39 2016
@@ -2005,533 +2005,708 @@
 return Status;
 }
 
+NTSTATUS 
+BmLaunchRecoverySequence (
+_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
+_In_ ULONG LaunchCode
+)
+{
+NTSTATUS Status;
+PBL_LOADED_APPLICATION_ENTRY RecoveryEntry;
+HANDLE BcdHandle;
+PGUID RecoverySequence;
+ULONG Count, i, RecoveryIndex, SequenceCount;
+PBL_LOADED_APPLICATION_ENTRY* Sequence;
+
+/* Initialize locals */
+RecoveryIndex = 0;
+Sequence = NULL;
+RecoverySequence = NULL;
+Count = 0;
+BcdHandle = NULL;
+
+/* Open the BCD*/
+Status = BmOpenDataStore();
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Get the recovery sequence list */
+Status = BlGetBootOptionGuidList(BootEntry->BcdData,
+ BcdLibraryObjectList_RecoverySequence,
+ ,
+ );
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Get the sequence of boot entries out of it */
+Status = BmGetBootSequence(BcdHandle,
+   RecoverySequence,
+   SequenceCount,
+   BL_APPLICATION_ENTRY_RECOVERY,
+   ,
+   );
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+/* Was the BCD open? */
+if (BcdHandle)
+{
+/* Close it */
+BmCloseDataStore(BcdHandle);
+}
+
+/* Now go over every entry in the sequence */
+for (i = 0; i < Count; ++i)
+{
+/* Check the code for this recovery launch */
+if (LaunchCode == 2 || LaunchCode == 5)
+{
+/* Remove the override if there is one, and set it to 4 */
+BlRemoveBootOption(Sequence[i]->BcdData, 
BcdLibraryInteger_DisplayMessageOverride);
+BlAppendBootOptionInteger(Sequence[i],
+  BcdLibraryInteger_DisplayMessageOverride,
+  4);
+}
+else if (LaunchCode == 3)
+{
+/* Remove the override if there is one, and set it to 10 */
+BlRemoveBootOption(Sequence[i]->BcdData, 
BcdLibraryInteger_DisplayMessageOverride);
+BlAppendBootOptionInteger(Sequence[i],
+
BcdLibraryInteger_DisplayMessageOverride,
+10);
+}
+
+/* Launch the boot entry for this part of the recovery sequence */
+Status = BmpLaunchBootEntry(Sequence[i], NULL, LaunchCode, FALSE);
+if (!NT_SUCCESS(Status))
+{
+break;
+}
+}
+
+Quickie:
+/* Did we have a sequence of entries? */
+if (Sequence)
+{   
+/* Loop through each one */
+for (RecoveryIndex = 0; RecoveryIndex < Count; RecoveryIndex++)
+{
+/* Does this index have an allocated boot entry? */
+RecoveryEntry = Sequence[RecoveryIndex];
+if (RecoveryEntry)
+{
+/* Destroy it */
+BlDestroyBootEntry(RecoveryEntry);
+}
+}
+
+/* Free the sequence itself */
+BlMmFreeHeap(Sequence);
+}
+
+/* Was there a sequence list? */
+if (RecoverySequence)
+{
+/* Free it */
+BlMmFreeHeap(RecoverySequence);
+}
+  
+/* Return back to caller */
+return Status;
+}
+
+ULONG
+BmDisplayDumpError (
+_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
+_In_ ULONG LaunchCode
+)
+{
+ULONG BootError;
+NTSTATUS Status;
+BOOLEAN Restart, NoError;
+
+/* Assume we'll just reboot */
+BootError = Reboot;
+
+/* Should we reboot? */
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+BcdLibraryBoolean_RestartOnFailure,
+);
+if ((NT_SUCCESS(Status)) && (Restart))
+{
+return BootError;
+}
+
+/* Should we not show errors, and thus, reboot? */
+Status = BlGetBootOptionBoolean(BlpA

[ros-diffs] [ion] 70625: [HIVEBCD/BOOTMGR]: Prep work

2016-01-19 Thread ion
Author: ion
Date: Wed Jan 20 03:53:59 2016
New Revision: 70625

URL: http://svn.reactos.org/svn/reactos?rev=70625=rev
Log:
[HIVEBCD/BOOTMGR]: Prep work

Modified:
trunk/reactos/boot/bootdata/hivebcd.inf
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c

Modified: trunk/reactos/boot/bootdata/hivebcd.inf
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivebcd.inf?rev=70625=70624=70625=diff
==
--- trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] (original)
+++ trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] Wed Jan 20 
03:53:59 2016
@@ -31,34 +31,15 @@
 00,00,00,00,\
 
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
-BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1202","Element",,"\windows\system32\boot\winload.efi"
  ; path
+BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1202","Element",,"\reactos\system32\boot\rosload.efi"
  ; path
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1204","Element",,"ReactOS
 Setup"   ; description
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1205","Element",,"en-US"
   ; locale="en-US"
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1406","Element",0x1,"{6efb52bf-1766-41db-a6b3-0ee5eff72bd7}"
   ; inherit={bootloadersettings}
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1660","Element",0x1,0x01
   ; isolatedcontext=Yes
-BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\2202","Element",,"\windows"
; systemroot=\Windows
+BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\2202","Element",,"\reactos"
; systemroot=\Windows
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\2610","Element",0x1,0x01
   ; detecthal=Yes
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\2622","Element",0x1,0x01
   ; winpe=Yes
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\26b0","Element",0x1,0x01
   ; ems=Yes
-
-;
-; ReactOS Memory Tester
-;
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Description","Type",0x00010001,0x1025
   ; identifier={memdiag}
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1101","Element",0x1,\
  ; device=boot
-00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
-05,00,00,00,\
-00,00,00,00,\
-48,00,00,00,\
-00,00,00,00,\
-00,00,00,00,\
-
00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
-00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1202","Element",,"\EFI\BOOT\MEMTEST.EFI"
   ; path
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1204","Element",,"ReactOS
 Memory Diagnostics"  ; description
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1205","Element",,"en-US"
   ; locale="en-US"
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1406","Element",0x1,"{7ea2e1ac-2e61-4728-aaa3-896d9d0a9f0e}"
   ; inherit={globalsettings}
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\160b","Element",0x1,0x01
   ; allowbadmemoryaccess=Yes
 
 ;
 ; Global Settings

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70625=70624=70625=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1

[ros-diffs] [ion] 70622: [BOOTLIB]: Fix build

2016-01-19 Thread ion
Author: ion
Date: Wed Jan 20 01:29:59 2016
New Revision: 70622

URL: http://svn.reactos.org/svn/reactos?rev=70622=rev
Log:
[BOOTLIB]: Fix build

Modified:
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/lib/misc/image.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/image.c?rev=70622=70621=70622=diff
==
--- trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/image.c [iso-8859-1] Wed Jan 20 
01:29:59 2016
@@ -922,6 +922,17 @@
 }
 
 NTSTATUS
+ImgArchEfiStartBootApplication (
+_In_ PBL_APPLICATION_ENTRY AppEntry,
+_In_ PVOID ImageBase,
+_In_ ULONG ImageSize,
+_In_ PBL_RETURN_ARGUMENTS ReturnArguments
+)
+{
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
 BlImgStartBootApplication (
 _In_ ULONG AppHandle,
 _Inout_opt_ PBL_RETURN_ARGUMENTS ReturnArguments




[ros-diffs] [ion] 70615: [BOOTMGR]: Implement support for getting the default boot entry, the current boot menu policy, and finish implementation of getting the selected boot entry. [BOOTMGR]: Stubple

2016-01-18 Thread ion
Author: ion
Date: Mon Jan 18 18:16:49 2016
New Revision: 70615

URL: http://svn.reactos.org/svn/reactos?rev=70615=rev
Log:
[BOOTMGR]: Implement support for getting the default boot entry, the current 
boot menu policy, and finish implementation of getting the selected boot entry.
[BOOTMGR]: Stubplement support for catching keystrokes right before boot (such 
as F8, F10). No key input is actually read.
Boot Manager now attempts to load the winload entry as part of 
BmpLaunchBootEntry.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70615=70614=70615=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Jan 18 
18:16:49 2016
@@ -32,6 +32,10 @@
 PWCHAR ParentFileName = L"";
 
 BOOLEAN BmDisplayStateCached;
+PBL_LOADED_APPLICATION_ENTRY* BmpFailedBootEntries;
+PBL_LOADED_APPLICATION_ENTRY BmpSelectedBootEntry;
+BOOLEAN BmBootEntryOverridePresent;
+BOOLEAN BmpDisplayBootMenu;
 
 /* FUNCTIONS */
 
@@ -1652,10 +1656,186 @@
 return Status;
 }
 
+VOID
+BmpGetDefaultBootEntry (
+_In_ PBL_LOADED_APPLICATION_ENTRY* Sequence,
+_In_ ULONG Count,
+_Out_ PBL_LOADED_APPLICATION_ENTRY* DefaultEntry,
+_Out_ PULONG DefaultIndex
+)
+{
+GUID DefaultObject;
+NTSTATUS Status;
+ULONG BootIndex;
+
+/* Assume no default */
+*DefaultEntry = *Sequence;
+*DefaultIndex = 0;
+
+/* Nothing to do if there's just one entry */
+if (Count == 1)
+{
+return;
+}
+
+/* Get the default object, bail out if there isn't one */
+Status = BlGetBootOptionGuid(BlpApplicationEntry.BcdData,
+ BcdBootMgrObject_DefaultObject,
+ );
+if (!(NT_SUCCESS(Status)) || !(Count))
+{
+return;
+}
+
+/* Scan the boot sequence */
+for (BootIndex = 0; BootIndex < Count; BootIndex++)
+{
+/* Find one that matches the default */
+if (RtlEqualMemory([BootIndex]->Guid,
+   ,
+   sizeof(GUID)))
+{
+/* Return it */
+*DefaultEntry = Sequence[BootIndex];
+*DefaultIndex = BootIndex;
+return;
+}
+}
+}
+
+BL_MENU_POLICY
+BmGetBootMenuPolicy (
+_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry
+)
+{
+NTSTATUS Status;
+BOOLEAN EmsEnabled;
+ULONGLONG BootMenuPolicy;
+ULONG OptionId;
+
+/* Check if EMS is enabled */
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+BcdOSLoaderBoolean_EmsEnabled,
+);
+if ((NT_SUCCESS(Status)) && (EmsEnabled))
+{
+/* No boot menu */
+return MenuPolicyLegacy;
+}
+
+/* Check what entry we are looking at */
+if (!BootEntry)
+{
+/* No entry, pick the selected one */
+BootEntry = BmpSelectedBootEntry;
+}
+
+/* Do we still not have an entry? */
+if (!BootEntry)
+{
+/* Show the menu */
+return MenuPolicyStandard;
+}
+
+/* Check if this is an OS loader */
+BootMenuPolicy = 0;
+if (BootEntry->Flags & BL_APPLICATION_ENTRY_WINLOAD)
+{
+/* Use the correct option ID */
+OptionId = BcdOSLoaderInteger_BootMenuPolicy;
+}
+else
+{
+/* Check if this is an OS resumer */
+if (!(BootEntry->Flags & BL_APPLICATION_ENTRY_WINRESUME))
+{
+/* Nope, so no reason for a menu */
+return MenuPolicyLegacy;
+}
+
+/* Use the correct opetion ID */
+OptionId = BcdResumeInteger_BootMenuPolicy;
+}
+
+/* Check the option ID for the boot menu policy */
+Status = BlGetBootOptionInteger(BootEntry->BcdData,
+OptionId,
+);
+if (NT_SUCCESS(Status))
+{
+/* We have one, return it */
+return BootMenuPolicy;
+}
+
+/* No policy, so assume no menu */
+return MenuPolicyLegacy;
+}
+
+VOID
+BmDisplayGetBootMenuStatus (
+_Out_ PL_MENU_STATUS MenuStatus
+)
+{
+/* For now, don't support key input at all */
+MenuStatus->AsULong = 0;
+MenuStatus->OemKey = UNICODE_NULL;
+MenuStatus->BootIndex = -1;
+}
+
+NTSTATUS
+BmProcessCustomAction (
+_In_ HANDLE BcdHandle,
+_In_ PWCHAR ActionKey
+)
+{
+EfiPrintf(L"Custom actions not yet handled\r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+
+VOID

[ros-diffs] [ion] 70614: [HIVEBCD]: Fix wrong element type for application device element. [BOOTMGR]: Implement boot sequence population. We correctly detect our winload.efi entry in the BCD hive. [BO

2016-01-18 Thread ion
Author: ion
Date: Mon Jan 18 16:54:44 2016
New Revision: 70614

URL: http://svn.reactos.org/svn/reactos?rev=70614=rev
Log:
[HIVEBCD]: Fix wrong element type for application device element.
[BOOTMGR]: Implement boot sequence population. We correctly detect our 
winload.efi entry in the BCD hive.
[BOOTMGR]: Document more application entry flags.
[BOOTLIB]: Document and implement BCD object description parsing. Based off BCD 
Reference Guide / Geoff Chappel's website.
[BOOTLIB]: Add support for appending a boot option to an entry.

Modified:
trunk/reactos/boot/bootdata/hivebcd.inf
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/bcd.c
trunk/reactos/boot/environ/lib/misc/bcdopt.c
trunk/reactos/boot/environ/lib/misc/bootreg.c

Modified: trunk/reactos/boot/bootdata/hivebcd.inf
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivebcd.inf?rev=70614=70613=70614=diff
==
--- trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] (original)
+++ trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] Mon Jan 18 
16:54:44 2016
@@ -22,7 +22,7 @@
 ; ReactOS Boot Loader
 ;
 
BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Description","Type",0x00010001,0x1023
   ; identifier={winload}
-BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1111","Element",0x1,\
  ; device=boot
+BCD,"BCD\Objects\{7619dcc9-fafe-11d9-b411-000476eba25f}\Elements\1101","Element",0x1,\
  ; device=boot
 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
 05,00,00,00,\
 00,00,00,00,\
@@ -45,7 +45,7 @@
 ; ReactOS Memory Tester
 ;
 
BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Description","Type",0x00010001,0x1025
   ; identifier={memdiag}
-BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1111","Element",0x1,\
  ; device=boot
+BCD,"BCD\Objects\{b2721d73-1db4-4c62-bf78-c548a880142d}\Elements\1101","Element",0x1,\
  ; device=boot
 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,\
 05,00,00,00,\
 00,00,00,00,\

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70614=70613=70614=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Jan 18 
16:54:44 2016
@@ -121,7 +121,6 @@
 /* Start going through each option */
 PreviousOption = NULL;
 Option = Options;
-EfiPrintf(L"BCD Options found: %d\r\n", ElementCount);
 for (i = 0; i < ElementCount; i++)
 {
 /* Read the header and type */
@@ -1231,6 +1230,40 @@
 }
 
 NTSTATUS
+BmGetEntryDescription (
+_In_ HANDLE BcdHandle,
+_In_ PGUID ObjectId,
+_Out_ PBCD_OBJECT_DESCRIPTION Description
+)
+{
+NTSTATUS Status;
+HANDLE ObjectHandle;
+
+/* Open the BCD object */
+Status = BcdOpenObject(BcdHandle, ObjectId, );
+if (NT_SUCCESS(Status))
+{
+/* Make sure the caller passed this argument in */
+if (!Description)
+{
+/* Fail otherwise */
+Status = STATUS_INVALID_PARAMETER;
+}
+else
+{
+/* Query the description from the BCD interface */
+Status = BiGetObjectDescription(ObjectHandle, Description);
+}
+
+/* Close the object key */
+BiCloseKey(ObjectHandle);
+}
+
+/* Return the result back */
+return Status;
+}
+
+NTSTATUS
 BmpPopulateBootEntryList (
 _In_ HANDLE BcdHandle,
 _In_ PGUID SequenceList,
@@ -1239,10 +1272,211 @@
 _Out_ PULONG SequenceCount
 )
 {
-EfiPrintf(L"Boot population not yet supported\r\n");
-*SequenceCount = 0;
-*BootSequence = NULL;
-return STATUS_NOT_IMPLEMENTED;
+NTSTATUS Status;
+ULONG BootIndex, i, OptionSize;
+PBL_LOADED_APPLICATION_ENTRY BootEntry;
+PBL_BCD_OPTION Options;
+BCD_OBJECT_DESCRIPTION Description;
+BcdObjectType ObjectType;
+BOOLEAN HavePath, IsWinPe, SoftReboot;
+PWCHAR LoaderPath;
+
+/* Initialize locals */
+Options = NULL;
+BootIndex = 0;
+Status = STATUS_NOT_FOUND;
+
+/* Loop through every element in the sequence */
+for (i = 0; i < *SequenceCou

[ros-diffs] [ion] 70611: [BOOTMGFW]: Implement BmEnumerateBootEntries. [BOOTLIB]: Implement BlGetOptionGuid. All BCD option APIs should now be implemented. [BOOTLIB]: Fix memory corruption + out-of-bo

2016-01-17 Thread ion
Author: ion
Date: Mon Jan 18 05:26:10 2016
New Revision: 70611

URL: http://svn.reactos.org/svn/reactos?rev=70611=rev
Log:
[BOOTMGFW]: Implement BmEnumerateBootEntries.
[BOOTLIB]: Implement BlGetOptionGuid. All BCD option APIs should now be 
implemented.
[BOOTLIB]: Fix memory corruption + out-of-bounds bugs in BlAppendBootOptions, 
which made the BCD options remain empty.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/misc/bcdopt.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70611=70610=70611=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Jan 18 
05:26:10 2016
@@ -696,7 +696,7 @@
 /* Check if boot.ini data needs to be freed */
 if (BmBootIniUsed)
 {
-EfiPrintf(L"Not handled\r\n");
+EfiPrintf(L"Boot.ini not handled\r\n");
 }
 
 /* Dereference the hive and close the key */
@@ -756,7 +756,7 @@
 if (NT_SUCCESS(Status))
 {
 /* We don't handle custom BCDs yet */
-EfiPrintf(L"Not handled: %s\r\n", BcdPath);
+EfiPrintf(L"Custom BCD Not handled: %s\r\n", BcdPath);
 Status = STATUS_NOT_IMPLEMENTED;
 goto Quickie;
 }
@@ -765,7 +765,7 @@
 if (BcdDevice->DeviceType == UdpDevice)
 {
 /* Nope. Nope. Nope */
-EfiPrintf(L"Not handled\r\n");
+EfiPrintf(L"UDP device Not handled\r\n");
 Status = STATUS_NOT_IMPLEMENTED;
 goto Quickie;
 }
@@ -920,7 +920,7 @@
 
 /* The BSD is open. Start doing stuff to it */
 EfiPrintf(L"Unimplemented BSD path\r\n");
-Status =  STATUS_NOT_IMPLEMENTED;
+Status = STATUS_NOT_IMPLEMENTED;
 
 FailurePath:
 /* Close the BSD if we had it open */
@@ -1239,7 +1239,7 @@
 _Out_ PULONG SequenceCount
 )
 {
-EfiPrintf(L"Fixed sequences not yet supported\r\n");
+EfiPrintf(L"Boot population not yet supported\r\n");
 *SequenceCount = 0;
 *BootSequence = NULL;
 return STATUS_NOT_IMPLEMENTED;
@@ -1292,14 +1292,130 @@
 NTSTATUS
 BmEnumerateBootEntries (
 _In_ HANDLE BcdHandle,
-_Out_ PBL_LOADED_APPLICATION_ENTRY **Sequence,
+_Out_ PBL_LOADED_APPLICATION_ENTRY **BootSequence,
 _Out_ PULONG SequenceCount
 )
 {
-EfiPrintf(L"Boot enumeration not yet implemented\r\n");
-*Sequence = NULL;
-*SequenceCount = 0;
-return STATUS_NOT_IMPLEMENTED;
+NTSTATUS Status;
+ULONG BootIndex, BootIniCount, BootEntryCount, BcdCount;
+PBL_LOADED_APPLICATION_ENTRY* Sequence;
+PGUID DisplayOrder;
+GUID DefaultObject;
+BOOLEAN UseDisplayList;
+
+/* Initialize locals */
+BootIndex = 0;
+
+/* First try to get the display list, if any */
+UseDisplayList = TRUE;
+Status = BlGetBootOptionGuidList(BlpApplicationEntry.BcdData,
+ BcdBootMgrObjectList_DisplayOrder,
+ ,
+ );
+if (!NT_SUCCESS(Status))
+{
+/* No list, get the default entry instead */
+Status = BlGetBootOptionGuid(BlpApplicationEntry.BcdData,
+ BcdBootMgrObject_DefaultObject,
+ );
+if (NT_SUCCESS(Status))
+{
+/* Set the array to just our entry */
+UseDisplayList = FALSE;
+BcdCount = 1;
+DisplayOrder = 
+}
+else
+{
+/* No default list either, return success but no entries */
+*BootSequence = NULL;
+*SequenceCount = 0;
+Status = STATUS_SUCCESS;
+DisplayOrder = NULL;
+goto Quickie;
+}
+}
+
+/* Check if boot.ini was used */
+BootIniCount = 0;
+if (BmBootIniUsed)
+{
+/* Get the entries from it */
+EfiPrintf(L"Boot.ini not supported\r\n");
+BootIniCount = 0;//BmBootIniGetEntryCount();
+}
+
+/* Allocate an array large enough for the combined boot entries */
+BootEntryCount = BootIniCount + BcdCount;
+Sequence = BlMmAllocateHeap(BootEntryCount * sizeof(*Sequence));
+if (!Sequence)
+{
+Status = STATUS_NO_MEMORY;
+goto Quickie;
+}
+
+/* Zero it out */
+RtlZeroMemory(Sequence, BootEntryCount * sizeof(*Sequence));
+
+/* Check if we had BCD entries */
+if (BcdCount)
+{
+/* Populate the list of bootable entries */
+Status = BmpPopulateBootEntryList(BcdHandle,
+  Displ

[ros-diffs] [ion] 70609: [CMLIB/NTOSKRNL]: Move key deletion functions to cmlib, so that UEFI boot library can use them. [BOOTLIB]: Implement BCD element deletion (bootreg: implement key deletion) [BO

2016-01-17 Thread ion
Author: ion
Date: Sun Jan 17 21:48:00 2016
New Revision: 70609

URL: http://svn.reactos.org/svn/reactos?rev=70609=rev
Log:
[CMLIB/NTOSKRNL]: Move key deletion functions to cmlib, so that UEFI boot 
library can use them.
[BOOTLIB]: Implement BCD element deletion (bootreg: implement key deletion)
[BOOTMGR]: Implement BL_FATAL_ERROR_BCD_ENTRIES fatal error.
[BOOTMGR]: Stubplement support for memory list data parsing (when memtest.efi 
will run), and stubplement support for boot persistent data blobs.
[BOOTMGR]: Stubplement boot sequence support, create stub for boot entry 
population.
[BOOTMGR]: Stubplement boot entry selection, create stub for boot entry 
enumeration.
Mostly factoring-level changes to get us closer to the needed code paths.

Added:
trunk/reactos/lib/cmlib/cmkeydel.c
  - copied, changed from r70605, trunk/reactos/ntoskrnl/config/cmkeydel.c
Removed:
trunk/reactos/ntoskrnl/config/cmkeydel.c
Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/misc/bcd.c
trunk/reactos/boot/environ/lib/misc/bootreg.c
trunk/reactos/lib/cmlib/CMakeLists.txt
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/ntoskrnl/include/internal/cm.h
trunk/reactos/ntoskrnl/ntos.cmake

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70609=70608=70609=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Jan 17 
21:48:00 2016
@@ -550,6 +550,23 @@
 ErrorResourceId = 9002;
 break;
 
+case BL_FATAL_ERROR_BCD_ENTRIES:
+
+/* File name is in parameter 1 */
+FileName = (PWCHAR)Parameter1;
+
+/* The NTSTATUS code is in parameter 2*/
+ErrorStatus = (NTSTATUS)Parameter2;
+
+/* Build the error string */
+swprintf(FormatString,
+ L"\nNo valid entries found in the boot configuration data 
file %s\n",
+ FileName);
+
+/* Select the resource ID message */
+ErrorResourceId = 9007;
+break;
+
 case BL_FATAL_ERROR_BCD_PARSE:
 
 /* File name isin parameter 1 */
@@ -1168,7 +1185,22 @@
 VOID
 )
 {
-EfiPrintf(L"Bad page list persistence \r\n");
+BL_PD_DATA_BLOB BadMemoryData;
+NTSTATUS Status;
+
+/* Try to get the memory data from the memtest application */
+BadMemoryData.BlobSize = 0;
+BadMemoryData.Data = NULL;
+BadMemoryData.DataSize = 0;
+Status = BlPdQueryData(, NULL, );
+if (Status != STATUS_BUFFER_TOO_SMALL)
+{
+/* No results, or some other error */
+return Status;
+}
+
+/* Not yet implemented */
+EfiPrintf(L"Bad page list persistence not implemented\r\n");
 return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1179,7 +1211,37 @@
 _In_ ULONG Type
 )
 {
-EfiPrintf(L"Key BCD delete not yet implemented\r\n");
+HANDLE ObjectHandle;
+NTSTATUS Status;
+
+/* Open the object */
+Status = BcdOpenObject(BcdHandle, ObjectId, );
+if (NT_SUCCESS(Status))
+{
+/* Delete the element */
+BcdDeleteElement(ObjectHandle, Type);
+
+/* Close the object and set success */
+BiCloseKey(ObjectHandle);
+Status = STATUS_SUCCESS;
+}
+
+/* Return the result */
+return Status;
+}
+
+NTSTATUS
+BmpPopulateBootEntryList (
+_In_ HANDLE BcdHandle,
+_In_ PGUID SequenceList,
+_In_ ULONG Flags,
+_Out_ PBL_LOADED_APPLICATION_ENTRY* BootSequence,
+_Out_ PULONG SequenceCount
+)
+{
+EfiPrintf(L"Fixed sequences not yet supported\r\n");
+*SequenceCount = 0;
+*BootSequence = NULL;
 return STATUS_NOT_IMPLEMENTED;
 }
 
@@ -1193,9 +1255,50 @@
 _Out_ PULONG SequenceCount
 )
 {
-EfiPrintf(L"Fixed sequences not yet supported\r\n");
+PBL_LOADED_APPLICATION_ENTRY* Sequence;
+ULONG Count;
+NTSTATUS Status;
+
+/* Allocate the sequence list */
+Sequence = BlMmAllocateHeap(SequenceListCount * sizeof(*Sequence));
+if (!Sequence)
+{
+return STATUS_NO_MEMORY;
+}
+
+/* Populate the sequence list */
+Status = BmpPopulateBootEntryList(BcdHandle,
+  SequenceList,
+  Flags,
+  Sequence,
+  );
+if (!NT_SUCCESS(Status))
+{
+/* Free the list on failure */
+BlMmFreeHeap(Sequence);
+}
+else
+{
+   

[ros-diffs] [ion] 70556: [BOOTMGFW]: Implement the final boot selection & launch loop. [BOOTMLIB]: Implement a few more BCD option functions. Minus a PE loader (BmpLaunchBootEntry) and some more BCD p

2016-01-08 Thread ion
Author: ion
Date: Sat Jan  9 05:39:18 2016
New Revision: 70556

URL: http://svn.reactos.org/svn/reactos?rev=70556=rev
Log:
[BOOTMGFW]: Implement the final boot selection & launch loop.
[BOOTMLIB]: Implement a few more BCD option functions.
Minus a PE loader (BmpLaunchBootEntry) and some more BCD parsing 
(BmpGetSelectedBootEntry) with some glue in between, the UEFI Boot Manager is 
nearly done. Once it is, it will be time to implement the actual loader -- 
Winload.efi. The good news is that we'll have all of bootlib already good to go 
(with all its hacks). The bad news is that Winload will turn on paging, so all 
those unimplemented paths and UEFI mode switches will have to be made to work.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/misc/bcdopt.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70556=70555=70556=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sat Jan  9 
05:39:18 2016
@@ -1163,6 +1163,66 @@
 return STATUS_NOT_IMPLEMENTED;
 }
 
+NTSTATUS
+BmpProcessBadMemory (
+VOID
+)
+{
+EfiPrintf(L"Bad page list persistence \r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+BmPurgeOption (
+_In_ HANDLE BcdHandle,
+_In_ PGUID ObjectId,
+_In_ ULONG Type
+)
+{
+EfiPrintf(L"Key BCD delete not yet implemented\r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+BmGetBootSequence (
+_In_ HANDLE BcdHandle,
+_In_ PGUID SequenceList,
+_In_ ULONG SequenceListCount,
+_In_ ULONG Flags,
+_Out_ PBL_LOADED_APPLICATION_ENTRY** BootSequence,
+_Out_ PULONG SequenceCount
+)
+{
+EfiPrintf(L"Fixed sequences not yet supported\r\n");
+*SequenceCount = 0;
+*BootSequence = NULL;
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+BmpGetSelectedBootEntry (
+_In_ HANDLE BcdHandle,
+_Out_ PBL_LOADED_APPLICATION_ENTRY *SelectedBootEntry,
+_Out_ PULONG EntryIndex,
+_Out_ PBOOLEAN ExitBootManager
+)
+{
+EfiPrintf(L"Boot selection not yet implemented\r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+BmpLaunchBootEntry (
+_In_ PBL_LOADED_APPLICATION_ENTRY BootEntry,
+_Out_ PULONG EntryIndex,
+_In_ ULONG Unknown,
+_In_ BOOLEAN LaunchWinRe
+)
+{
+EfiPrintf(L"Boot launch not yet implemented\r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+
 /*++
  * @name BmMain
  *
@@ -1189,12 +1249,18 @@
 PBL_BCD_OPTION EarlyOptions;
 PWCHAR Stylesheet;
 BOOLEAN XmlLoaded, DisableIntegrity, TestSigning, PersistBootSequence;
-BOOLEAN RebootOnError, CustomActions, ContinueLoop;
-ULONG SequenceId, SequenceCount;
-PGUID BootSequences;
-//PBL_LOADED_APPLICATION_ENTRY* BootEntries;
-//PBL_LOADED_APPLICATION_ENTRY BootEntry;
-
+BOOLEAN RebootOnError, CustomActions;
+ULONG SequenceId;
+PBL_LOADED_APPLICATION_ENTRY BootEntry;
+PGUID SequenceList;
+ULONG SequenceListCount;
+PBL_LOADED_APPLICATION_ENTRY* BootSequence;
+ULONG BootIndex;
+BOOLEAN ExitBootManager;
+BOOLEAN BootFailed;
+BOOLEAN BootOk;
+ULONG SequenceCount;
+BOOLEAN GetEntry;
 EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\r\n");
 
 /* Reading the BCD can change this later on */
@@ -1401,49 +1467,190 @@
 
 /* At last, enter the boot selection stage */
 SequenceId = 0;
-do
-{
-ContinueLoop = FALSE;
-
-/* Get the list of boot sequences */
-SequenceCount = 0;
-Status = BlGetBootOptionGuidList(BlpApplicationEntry.BcdData,
- BcdBootMgrObjectList_BootSequence,
- ,
- );
-EfiPrintf(L"Count: %d\r\n", SequenceCount);
-EfiStall(100);
+GetEntry = FALSE;
+BootFailed = FALSE;
+SequenceList = NULL;
+BootSequence = NULL;
+SequenceCount = 0;
+while (1)
+{
+/* We don't have a boot entry nor a sequence ID */
+BootEntry = NULL;
+BootOk = FALSE;
+
+/* Do we have a hardcoded boot sequence set? */
+if (!(BootSequence) && !(GetEntry))
+{
+/* Not yet, read the BCD to see if one is there */
+Status = BlGetBootOptionGuidList(BlpApplicationEntry.BcdData,
+ BcdBootMgrObjectList_BootSequence,
+ ,
+ );
+if (NT_SUCCESS(Status))
+{
+

[ros-diffs] [ion] 70538: [ACPI.H]: Fix broken definition of RSDP_SIGNATURE [ACPI.H]: Add BGRT_TABLE definition.

2016-01-07 Thread ion
Author: ion
Date: Thu Jan  7 23:25:49 2016
New Revision: 70538

URL: http://svn.reactos.org/svn/reactos?rev=70538=rev
Log:
[ACPI.H]: Fix broken definition of RSDP_SIGNATURE
[ACPI.H]: Add BGRT_TABLE definition.

Modified:
trunk/reactos/include/reactos/drivers/acpi/acpi.h

Modified: trunk/reactos/include/reactos/drivers/acpi/acpi.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/reactos/drivers/acpi/acpi.h?rev=70538=70537=70538=diff
==
--- trunk/reactos/include/reactos/drivers/acpi/acpi.h   [iso-8859-1] (original)
+++ trunk/reactos/include/reactos/drivers/acpi/acpi.h   [iso-8859-1] Thu Jan  7 
23:25:49 2016
@@ -40,11 +40,26 @@
 #define BOOT_SIGNATURE 'TOOB'
 #define SRAT_SIGNATURE 'TARS'
 #define WDRT_SIGNATURE 'TRDW'
+#define BGRT_SIGNATURE  0x54524742 // "BGRT"
 
 //
 // FADT Flags
 //
-#define ACPI_TMR_VAL_EXT 0x100
+#define ACPI_TMR_VAL_EXT   0x100
+
+//
+// BGRT Flags
+//
+#define BGRT_STATUS_IMAGE_VALID 0x01
+
+//
+// BGRT Image Types
+//
+typedef enum _BGRT_IMAGE_TYPE
+{
+BgrtImageTypeBitmap,
+BgrtImageTypeMax
+} BGRT_IMAGE_TYPE, *PBGRT_IMAGE_TYPE;
 
 //
 // ACPI Generic Register Address
@@ -67,8 +82,12 @@
 ULONGLONG Signature;
 UCHAR Checksum;
 UCHAR OEMID[6];
-UCHAR Reserved[1];
+UCHAR Revision;
 ULONG RsdtAddress;
+ULONG Length;
+PHYSICAL_ADDRESS XsdtAddress;
+UCHAR XChecksum;
+UCHAR Reserved[3];
 } RSDP;
 typedef RSDP *PRSDP;
 
@@ -219,4 +238,15 @@
 ULONG Reserved[2];
 } ACPI_SRAT, *PACPI_SRAT;
 
+typedef struct _BGRT_TABLE
+{
+DESCRIPTION_HEADER Header;
+USHORT Version;
+UCHAR Status;
+UCHAR ImageType;
+ULONGLONG LogoAddress;
+ULONG OffsetX;
+ULONG OffsetY;
+} BGRT_TABLE, *PBGRT_TABLE;
+
 /* EOF */




[ros-diffs] [ion] 70542: Three tiny squirmy subtle bugs combined themselves with the bug that was just fixed to make bootmgfw believe it was being booted from a raw removable disk (floppy). Because bo

2016-01-07 Thread ion
Author: ion
Date: Fri Jan  8 01:18:08 2016
New Revision: 70542

URL: http://svn.reactos.org/svn/reactos?rev=70542=rev
Log:
Three tiny squirmy subtle bugs combined themselves with the bug that was just 
fixed to make bootmgfw believe it was being booted from a raw removable disk 
(floppy). Because bootmgfw now correctly enumerates boot devices and detects 
the DVD/CDROM media, it could no longer 'find itself', believing it was on a 
floppy.
[BOOTLIB]: When failing to find a block device, keep going searching for more, 
instead of giving up (critical, because the CDROM FAT12 image is now device 
path #1, not #0).
[BOOTMGR]: Correctly use the right logical operator in EfiInitpGetDeviceNode to 
get the deepest-level media device node. We now get the CDROM node, not the raw 
node.
[CDMAKE]: Don't actually create an EFI/BOOT directory on the CDROM itself, but 
rather in the FAT12 image. Otherwise, this can confuse UEFI implementations to 
boot the boot manager off the raw CDROM, instead of the FAT12 image on the 
CDROM.

Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/lib/io/device.c

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=70542=70541=70542=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Fri Jan  8 
01:18:08 2016
@@ -105,5 +105,3 @@
 
 add_dependencies(bootmgfw asm bugcodes)
 
-add_cd_file(TARGET bootmgfw FILE ${_bootmgfw_output_file} DESTINATION efi/boot 
NO_CAB FOR bootcd regtest NAME_ON_CD boot${EFI_PLATFORM_ID}.efi)
-

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70542=70541=70542=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Fri Jan  8 
01:18:08 2016
@@ -1263,7 +1263,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Signature invalid, fail boot */
-   // goto Failure;
+goto Failure;
 }
 }
 

Modified: trunk/reactos/boot/environ/app/bootmgr/efiemu.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/efiemu.c?rev=70542=70541=70542=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] Fri Jan  8 
01:18:08 2016
@@ -319,7 +319,7 @@
 
 /* Loop each device path, until we get to the end or to a file path device 
node */
 for ((NextPath = NextDevicePathNode(DevicePath));
- !(IsDevicePathEndType(NextPath)) && ((NextPath->Type != 
MEDIA_DEVICE_PATH) &&
+ !(IsDevicePathEndType(NextPath)) && ((NextPath->Type != 
MEDIA_DEVICE_PATH) ||
   (NextPath->SubType != 
MEDIA_FILEPATH_DP));
  (NextPath = NextDevicePathNode(NextPath)))
 {

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=70542=70541=70542=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Fri Jan  8 
01:18:08 2016
@@ -1276,7 +1276,7 @@
 if (!NT_SUCCESS(Status))
 {
 EfiPrintf(L"EFI create failed: %lx\n", Status);
-break;
+continue;
 }
 
 /* Add the device entry to the device table */




[ros-diffs] [ion] 70543: [BOOTMGFW]: Implement additional startup logic [BOOTLIB]: Implement initial SecureBoot support. [BOOTLIB]: Implement UEFI Variable query support.

2016-01-07 Thread ion
Author: ion
Date: Fri Jan  8 06:03:55 2016
New Revision: 70543

URL: http://svn.reactos.org/svn/reactos?rev=70543=rev
Log:
[BOOTMGFW]: Implement additional startup logic
[BOOTLIB]: Implement initial SecureBoot support.
[BOOTLIB]: Implement UEFI Variable query support.

Added:
trunk/reactos/boot/environ/include/efi/GlobalVariable.h   (with props)
Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/misc/util.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70543=70542=70543=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Fri Jan  8 
06:03:55 2016
@@ -1042,6 +1042,16 @@
 }
 
 NTSTATUS
+BlXmiWrite (
+_In_ PWCHAR XmlTag
+)
+{
+/* Sigh */
+EfiPrintf(L"XML: %s\r\n", XmlTag);
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
 BlXmiInitialize (
 _In_ PWCHAR Stylesheet
 )
@@ -1082,15 +1092,75 @@
 VOID
 )
 {
-EfiPrintf(L"Device Type %d Local Type %d\r\n", BlpBootDevice->DeviceType, 
BlpBootDevice->Local.Type);
+/* Check if we're booted by UEFI off the DVD directlry */
 if ((BlpBootDevice->DeviceType == LocalDevice) &&
 (BlpBootDevice->Local.Type == CdRomDevice) &&
 (BlpApplicationFlags & BL_APPLICATION_FLAG_CONVERTED_FROM_EFI))
 {
+/* Windows actually bypasses integrity checks in this case. Works for 
us */
 return STATUS_SUCCESS;
 }
 
+/* Our binaries aren't signed, so always return failure */
 return 0xC428;
+}
+
+NTSTATUS
+BmFwRegisterRevocationList (
+VOID
+)
+{
+NTSTATUS Status;
+BOOLEAN SecureBootEnabled;
+
+/* Is SecureBoot enabled? */
+Status = BlSecureBootIsEnabled();
+if ((NT_SUCCESS(Status)) && (SecureBootEnabled))
+{
+EfiPrintf(L"SB not implemented revok\r\n");
+return STATUS_NOT_IMPLEMENTED;
+}
+else
+{
+/* Nothing to do without SecureBoot */
+Status = STATUS_SUCCESS;
+}
+
+/* Return revocation result back to caller */
+return Status;
+}
+
+NTSTATUS
+BmResumeFromHibernate (
+_Out_ PHANDLE BcdResumeHandle
+)
+{
+NTSTATUS Status;
+BOOLEAN AttemptResume;
+
+/* Should we attempt to resume from hibernation? */
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+BcdBootMgrBoolean_AttemptResume,
+);
+if (!NT_SUCCESS(Status))
+{
+/* Nope. Is automatic restart on crash enabled? */
+AttemptResume = FALSE;
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+
BcdOSLoaderBoolean_DisableCrashAutoReboot,
+);
+AttemptResume = (NT_SUCCESS(Status) && (AttemptResume));
+}
+
+/* Don't do anything if there's no need to resume anything */
+if (!AttemptResume)
+{
+return STATUS_SUCCESS;
+}
+
+/* Not yet implemented */
+EfiPrintf(L"Resume not supported\r\n");
+return STATUS_NOT_IMPLEMENTED;
 }
 
 /*++
@@ -1116,7 +1186,7 @@
 PBL_RETURN_ARGUMENTS ReturnArguments;
 BOOLEAN RebootOnError;
 PGUID AppIdentifier;
-HANDLE BcdHandle;
+HANDLE BcdHandle, ResumeBcdHandle;
 PBL_BCD_OPTION EarlyOptions;
 PWCHAR Stylesheet;
 BOOLEAN XmlLoaded, DisableIntegrity, TestSigning;
@@ -1267,14 +1337,36 @@
 }
 }
 
-//BlXmiWrite(L"");
-
-//BlSecureBootCheckForFactoryReset();
+/* Write out the first XML tag */
+BlXmiWrite(L"");
+
+/* Check for factory resset */
+BlSecureBootCheckForFactoryReset();
+
+/* Load the revocation list */
+Status = BmFwRegisterRevocationList();
+if (!NT_SUCCESS(Status))
+{
+goto Failure;
+}
+
+/* Register our custom progress routine */
+BlUtlRegisterProgressRoutine();
+
+/* Display state is not currently cached */
+BmDisplayStateCached = FALSE;
+
+/* Check if w need to resume from hibernate */
+Status = BmResumeFromHibernate();
+if (!NT_SUCCESS(Status))
+{
+goto Failure;
+}
 
 
 /* do more stuff!! */
-EfiPrintf(BlResourceFindMessage(BM_MSG_TEST));
-EfiPrintf(Stylesheet);
+//EfiPrintf(BlResourceFindMessage(BM_MSG_TEST));
+//EfiPrintf(Stylesheet);
 EfiStall(1000);
 
 Failure:

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70543=70542=70543=diff
==

[ros-diffs] [ion] 70544: [BOOTMGFW]: Last few straggling initialization checks. [BOOTMGFW]: Recover the boot sequence from the BCD and entire the boot selection stage. Now the fun begins.

2016-01-07 Thread ion
Author: ion
Date: Fri Jan  8 06:19:14 2016
New Revision: 70544

URL: http://svn.reactos.org/svn/reactos?rev=70544=rev
Log:
[BOOTMGFW]: Last few straggling initialization checks.
[BOOTMGFW]: Recover the boot sequence from the BCD and entire the boot 
selection stage. Now the fun begins.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70544=70543=70544=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Fri Jan  8 
06:19:14 2016
@@ -1184,12 +1184,16 @@
 NTSTATUS Status, LibraryStatus;
 BL_LIBRARY_PARAMETERS LibraryParameters;
 PBL_RETURN_ARGUMENTS ReturnArguments;
-BOOLEAN RebootOnError;
 PGUID AppIdentifier;
 HANDLE BcdHandle, ResumeBcdHandle;
 PBL_BCD_OPTION EarlyOptions;
 PWCHAR Stylesheet;
-BOOLEAN XmlLoaded, DisableIntegrity, TestSigning;
+BOOLEAN XmlLoaded, DisableIntegrity, TestSigning, PersistBootSequence;
+BOOLEAN RebootOnError, CustomActions, ContinueLoop;
+ULONG SequenceId, SequenceCount;
+PGUID BootSequences;
+//PBL_LOADED_APPLICATION_ENTRY* BootEntries;
+//PBL_LOADED_APPLICATION_ENTRY BootEntry;
 
 EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\n");
 
@@ -1324,8 +1328,8 @@
 
 /* Check if any bypass options are enabled */
 BlImgQueryCodeIntegrityBootOptions(,
-,
-);
+   ,
+   );
 if (!DisableIntegrity)
 {
 /* Integrity checks are enabled, so validate our signature */
@@ -1363,11 +1367,69 @@
 goto Failure;
 }
 
-
-/* do more stuff!! */
-//EfiPrintf(BlResourceFindMessage(BM_MSG_TEST));
-//EfiPrintf(Stylesheet);
-EfiStall(1000);
+#ifdef BL_NET_SUPPORT
+/* Register multicast printing routine */
+BlUtlRegisterMulticastRoutine();
+#endif
+
+/* Check if restart on failure is enabled */
+BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+   BcdLibraryBoolean_RestartOnFailure,
+   );
+
+/* Check if the boot sequence is persisted */
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+BcdBootMgrBoolean_PersistBootSequence,
+);
+if (!NT_SUCCESS(Status))
+{
+/* It usually is */
+PersistBootSequence = TRUE;
+}
+
+/* Check if there's custom actions to take */
+Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
+
BcdBootMgrBoolean_ProcessCustomActionsFirst,
+);
+if ((NT_SUCCESS(Status)) && (CustomActions))
+{
+/* We don't suppport this yet */
+EfiPrintf(L"Not implemented\r\n");
+Status = STATUS_NOT_IMPLEMENTED;
+goto Failure;
+}
+
+/* At last, enter the boot selection stage */
+SequenceId = 0;
+do
+{
+ContinueLoop = FALSE;
+
+/* Get the list of boot sequences */
+SequenceCount = 0;
+Status = BlGetBootOptionGuidList(BlpApplicationEntry.BcdData,
+ BcdBootMgrObjectList_BootSequence,
+ ,
+ );
+EfiPrintf(L"Count: %d\r\n", SequenceCount);
+EfiStall(100);
+if (!NT_SUCCESS(Status))
+{
+//goto GetEntry;
+}
+
+if (NT_SUCCESS(Status))
+{
+continue;
+}
+
+if (RebootOnError)
+{
+break;
+}
+
+SequenceId++;
+} while (ContinueLoop);
 
 Failure:
 /* Check if we got here due to an internal error */




[ros-diffs] [ion] 70516: [BOOTLIB]: More debug print cleanups [BOOTLIB]: Fix incorrect use of flag introduced a few revisions ago. This fixes <1MB RAM descriptors. [BOOTLIB]: Enable BmFwMemoryInitiali

2016-01-06 Thread ion
Author: ion
Date: Thu Jan  7 05:30:18 2016
New Revision: 70516

URL: http://svn.reactos.org/svn/reactos?rev=70516=rev
Log:
[BOOTLIB]: More debug print cleanups
[BOOTLIB]: Fix incorrect use of flag introduced a few revisions ago. This fixes 
<1MB RAM descriptors.
[BOOTLIB]: Enable BmFwMemoryInitialize, since it works now.
All (known) bugs are fixed, bootmgr is back on track.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/etfs.c
trunk/reactos/boot/environ/lib/io/file.c
trunk/reactos/boot/environ/lib/mm/descriptor.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70516=70515=70516=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Thu Jan  7 
05:30:18 2016
@@ -1151,7 +1151,7 @@
 }
 
 /* Initialize firmware-specific memory regions */
-//BmFwMemoryInitialize();
+BmFwMemoryInitialize();
 
 /* Initialize the boot status data log (BSD) */
 BmpInitializeBootStatusDataLog();
@@ -1168,7 +1168,7 @@
 
 /* do more stuff!! */
 EfiPrintf(BlResourceFindMessage(BM_MSG_TEST));
-EfiPrintf(Stylesheet);
+//EfiPrintf(Stylesheet);
 EfiStall(1000);
 
 //Failure:

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70516=70515=70516=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Jan  7 
05:30:18 2016
@@ -287,10 +287,11 @@
 //
 // Memory Allocation Attributes
 //
+BlMemoryUnknown =   0x0001,
 BlMemoryNonFixed =  0x0002,
 BlMemoryFixed = 0x0004,
 BlMemoryReserved =  0x0008,
-BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed 
| BlMemoryReserved,
+BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed 
| BlMemoryReserved | BlMemoryUnknown,
 BlMemoryValidAllocationAttributeMask= 0x00FF,
 
 //

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=70516=70515=70516=diff
==
--- 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] 
Thu Jan  7 05:30:18 2016
@@ -1269,7 +1269,8 @@
 if (Descriptor->Type == BlConventionalMemory)
 {
 /* Set the reserved flag on the descriptor */
-Descriptor->Flags |= BlReservedMemory;
+EfiPrintf(L"Adding magic flag\r\n");
+Descriptor->Flags |= BlMemoryReserved;
 }
 
 /* Add this descriptor into the list */
@@ -1313,7 +1314,8 @@
 if ((Descriptor->Type == BlConventionalMemory) && (EndPage <= 0x100))
 {
 /* Set the reserved flag on the descriptor */
-Descriptor->Flags |= BlReservedMemory;
+EfiPrintf(L"Adding magic flag\r\n");
+Descriptor->Flags |= BlMemoryReserved;
 }
 
 /* Add the descriptor to the list, requesting coalescing as asked */

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=70516=70515=70516=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Thu Jan  7 
05:30:18 2016
@@ -301,7 +301,7 @@
 }
 
 Alignment = BlockDevice->Alignment;
-if (!Alignment || !((Alignment - 1) & (ULONG_PTR)Buffer))
+if (!(Alignment) || !((Alignment - 1) & (ULONG_PTR)Buffer))
 {
 Status = BlockIopFirmwareOperation(DeviceEntry,
Buffer,
@@ -317,7 +317,6 @@
 return STATUS_SUCCESS;
 }
 
-EfiPrintf(L"Firmware alignment fixup required\r\n");
 Status = BlockIopAllocateAlignedBuffer(,
,
BufferSize,
@@ -820,11 +819,6 @@
 
 /* Get information on the block media */
 Media = BlockDevic

[ros-diffs] [ion] 70514: [BOOTLIB]: Add support for initializing the input console object. [BOOTLIB]: Add a bunch more graphical console support functions. [BOOTLIB]: Cleanup some older graphics-relat

2016-01-06 Thread ion
Author: ion
Date: Thu Jan  7 04:28:13 2016
New Revision: 70514

URL: http://svn.reactos.org/svn/reactos?rev=70514=rev
Log:
[BOOTLIB]: Add support for initializing the input console object.
[BOOTLIB]: Add a bunch more graphical console support functions.
[BOOTLIB]: Cleanup some older graphics-related code.
[BOOTLIB]: Support graphics re-initialization. We now correctly fallback to 
text mode since font loading is not implemented.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/io/display/efi/guicons.c
trunk/reactos/boot/environ/lib/io/display/efi/textcons.c
trunk/reactos/boot/environ/lib/io/display/guicons.c
trunk/reactos/boot/environ/lib/io/display/textcons.c
trunk/reactos/boot/environ/lib/misc/font.c
trunk/reactos/boot/environ/lib/misc/resource.c
trunk/reactos/boot/environ/lib/mm/descriptor.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70514=70513=70514=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Jan  7 
04:28:13 2016
@@ -394,8 +394,12 @@
 
 struct _BL_TEXT_CONSOLE;
 struct _BL_DISPLAY_STATE;
-typedef
-NTSTATUS
+struct _BL_DISPLAY_MODE;
+struct _BL_INPUT_CONSOLE;
+struct _BL_REMOTE_CONSOLE;
+struct _BL_GRAPHICS_CONSOLE;
+typedef
+VOID
 (*PCONSOLE_DESTRUCT) (
 _In_ struct _BL_TEXT_CONSOLE* Console
 );
@@ -442,6 +446,33 @@
 _In_ struct _BL_TEXT_CONSOLE* Console,
 _In_ ULONG Attribute
 );
+
+typedef
+BOOLEAN
+(*PCONSOLE_IS_ENABLED) (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_GET_GRAPHICAL_RESOLUTION) (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_Out_ struct _BL_DISPLAY_MODE* DisplayMode
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_SET_GRAPHICAL_RESOLUTION) (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_In_ struct _BL_DISPLAY_MODE DisplayMode
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_ENABLE) (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_In_ BOOLEAN Enable
+);
 
 typedef
 NTSTATUS
@@ -875,6 +906,12 @@
 typedef struct _BL_GRAPHICS_CONSOLE_VTABLE
 {
 BL_TEXT_CONSOLE_VTABLE Text;
+PCONSOLE_IS_ENABLED IsEnabled;
+PCONSOLE_ENABLE Enable;
+PVOID GetConsoleResolution;
+PCONSOLE_GET_GRAPHICAL_RESOLUTION GetGraphicalResolution;
+PCONSOLE_GET_GRAPHICAL_RESOLUTION GetOriginalResolution;
+PCONSOLE_SET_GRAPHICAL_RESOLUTION SetOriginalResolution;
 /// more for graphics ///
 } BL_GRAPHICS_CONSOLE_VTABLE, *PBL_GRAPHICS_CONSOLE_VTABLE;
 
@@ -888,6 +925,25 @@
 ULONG Mode;
 EFI_SIMPLE_TEXT_OUTPUT_MODE OldMode;
 } BL_TEXT_CONSOLE, *PBL_TEXT_CONSOLE;
+
+typedef struct _BL_INPUT_CONSOLE_VTABLE
+{
+PCONSOLE_DESTRUCT Destruct;
+PCONSOLE_REINITIALIZE Reinitialize;
+//PCONSOLE_IS_KEY_PENDING IsKeyPending;
+//PCONSOLE_READ_INPUT ReadInput;
+//PCONSOLE_ERASE_BUFFER EraseBuffer;
+//PCONSOLE_FILL_BUFFER FillBuffer;
+} BL_INPUT_CONSOLE_VTABLE, *PBL_INPUT_CONSOLE_VTABLE;
+
+typedef struct _BL_INPUT_CONSOLE
+{
+PBL_INPUT_CONSOLE_VTABLE Callbacks;
+PULONG Buffer;
+PULONG DataStart;
+PULONG DataEnd;
+PULONG EndBuffer;
+} BL_INPUT_CONSOLE, *PBL_INPUT_CONSOLE;
 
 typedef enum _BL_GRAPHICS_CONSOLE_TYPE
 {
@@ -1186,6 +1242,16 @@
 );
 
 NTSTATUS
+EfiConInExReset (
+VOID
+);
+
+NTSTATUS
+EfiConInReset (
+VOID
+);
+
+NTSTATUS
 EfiConOutQueryMode (
 _In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
 _In_ ULONG Mode,
@@ -1871,9 +1937,59 @@
 _Out_ PULONG FileId
 );
 
+/* INPUT CONSOLE ROUTINES /
+
+VOID
+ConsoleInputLocalDestruct (
+_In_ struct _BL_INPUT_CONSOLE* Console
+);
+
+NTSTATUS
+ConsoleInputBaseReinitialize (
+_In_ struct _BL_INPUT_CONSOLE* Console
+);
+
+NTSTATUS
+ConsoleCreateLocalInputCnsole (
+VOID
+);
+
 /* TEXT CONSOLE ROUTINES */
 
-NTSTATUS
+VOID
+ConsoleGraphicalDestruct (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console
+);
+
+NTSTATUS
+ConsoleGraphicalReinitialize (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console
+);
+
+BOOLEAN
+ConsoleGraphicalIsEnabled (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console
+);
+
+NTSTATUS
+ConsoleGraphicalGetGraphicalResolution (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_In_ PBL_DISPLAY_MODE DisplayMode
+);
+
+NTSTATUS
+ConsoleGraphicalGetOriginalResolution (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_In_ PBL_DISPLAY_MODE DisplayMode
+);
+
+NTSTATUS
+ConsoleGraphicalEnable (
+_In_ struct _BL_GRAPHICS_CONSOLE* Console,
+_In_ BOOLEAN Enable
+);
+
+VOID
 ConsoleTextLocalDestruct

[ros-diffs] [ion] 70515: [BOOTLIB]: Cleanup some debug prints. [BOOTLIB]: Fix two big device I/O bugs (it's a miracle it worked) [BOOTLIB]: Use defined constants and comment some more device I/O code.

2016-01-06 Thread ion
Author: ion
Date: Thu Jan  7 05:14:26 2016
New Revision: 70515

URL: http://svn.reactos.org/svn/reactos?rev=70515=rev
Log:
[BOOTLIB]: Cleanup some debug prints.
[BOOTLIB]: Fix two big device I/O bugs (it's a miracle it worked)
[BOOTLIB]: Use defined constants and comment some more device I/O code.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/etfs.c
trunk/reactos/boot/environ/lib/io/fat.c
trunk/reactos/boot/environ/lib/io/file.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70515=70514=70515=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -315,7 +315,10 @@
 DeviceHandle = -1;
 
 /* Try to open the boot device */
-Status = BlpDeviceOpen(BlpBootDevice, 1u, 0, );
+Status = BlpDeviceOpen(BlpBootDevice,
+   BL_DEVICE_READ_ACCESS,
+   0, 
+   );
 if (!NT_SUCCESS(Status))
 {
 EfiPrintf(L"Device open failed: %lx\r\n", Status);
@@ -327,7 +330,6 @@
 BcdDirectory = BcdPath.Buffer;
 if (!NT_SUCCESS(Status))
 {
-EfiPrintf(L"path failed: %lx\n", Status);
 goto Quickie;
 }
 
@@ -351,8 +353,10 @@
 wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR));
 
 /* Try to open the file */
-EfiPrintf(L"Opening: %s\r\n", FinalPath);
-Status = BlFileOpen(DeviceHandle, FinalPath, 1, );
+Status = BlFileOpen(DeviceHandle,
+FinalPath,
+BL_FILE_READ_ACCESS,
+);
 if (!NT_SUCCESS(Status))
 {
 BootDirectory = BcdDirectory;

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=70515=70514=70515=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -603,28 +603,32 @@
 {
 PBL_DEVICE_ENTRY DeviceEntry;
 
-if (!(DeviceInformation))
+/* This parameter is not optional */
+if (!DeviceInformation)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Make sure the device ID is valid */
 if (DmTableEntries <= DeviceId)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Get the device entry */
 DeviceEntry = DmDeviceTable[DeviceId];
 if (!DeviceEntry)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
-if (!(DeviceEntry->Flags & 1))
+/* Make sure the device is open */
+if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED))
 {
 return STATUS_INVALID_PARAMETER;
 }
 
-DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType;
+/* Set the device information */
 return DeviceEntry->Callbacks.SetInformation(DeviceEntry, 
DeviceInformation);
 }
 
@@ -636,27 +640,32 @@
 {
 PBL_DEVICE_ENTRY DeviceEntry;
 
-if (!(DeviceInformation))
+/* This parameter is not optional */
+if (!DeviceInformation)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Make sure the device ID is valid */
 if (DmTableEntries <= DeviceId)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Get the device entry */
 DeviceEntry = DmDeviceTable[DeviceId];
 if (!DeviceEntry)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
-if (!(DeviceEntry->Flags & 1))
+/* Make sure the device is open */
+if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED))
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Return the device information */
 DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType;
 return DeviceEntry->Callbacks.GetInformation(DeviceEntry, 
DeviceInformation);
 }
@@ -666,40 +675,51 @@
 _In_ ULONG DeviceId,
 _In_ PVOID Buffer,
 _In_ ULONG Size,
-_Out_ PULONG BytesRead
+_Out_opt_ PULONG BytesRead
 )
 {
 PBL_DEVICE_ENTRY DeviceEntry;
 NTSTATUS Status;
 ULONG BytesTransferred;
 
+/* Make sure we have a buffer, and the device ID is valid */
 if (!(Buffer) || (DmTableEntries <= DeviceId))
 {
 return STATUS_INVALID_PARAMETER;
 }
 
+/* Get the device entry for it */
 DeviceEntry = DmDeviceTable[DeviceId];
 if (!DeviceEntry)
 {
 return STATUS_INVALID_PARAMETER;
 }
 
-if (!(DeviceEntry->Flags & 1) || !(DeviceEntry->Flags & 2))

[ros-diffs] [ion] 70494: [DDK]: Add IMAGE_RESOURCE_DIRECTORY_ENTRY to NTIMAGE.H. I shudder to think how our current code currently parses resource directories without this.

2016-01-05 Thread ion
Author: ion
Date: Tue Jan  5 17:12:14 2016
New Revision: 70494

URL: http://svn.reactos.org/svn/reactos?rev=70494=rev
Log:
[DDK]: Add IMAGE_RESOURCE_DIRECTORY_ENTRY to NTIMAGE.H. I shudder to think how 
our current code currently parses resource directories without this.

Modified:
trunk/reactos/include/ddk/ntimage.h

Modified: trunk/reactos/include/ddk/ntimage.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ddk/ntimage.h?rev=70494=70493=70494=diff
==
--- trunk/reactos/include/ddk/ntimage.h [iso-8859-1] (original)
+++ trunk/reactos/include/ddk/ntimage.h [iso-8859-1] Tue Jan  5 17:12:14 2016
@@ -175,6 +175,27 @@
   USHORT NumberOfNamedEntries;
   USHORT NumberOfIdEntries;
 } IMAGE_RESOURCE_DIRECTORY, *PIMAGE_RESOURCE_DIRECTORY;
+
+#define IMAGE_RESOURCE_NAME_IS_STRING0x8000
+#define IMAGE_RESOURCE_DATA_IS_DIRECTORY 0x8000
+
+typedef struct _IMAGE_RESOURCE_DIRECTORY_ENTRY {
+  _ANONYMOUS_UNION union {
+_ANONYMOUS_STRUCT struct {
+  ULONG NameOffset:31;
+  ULONG NameIsString:1;
+} DUMMYSTRUCTNAME;
+ULONG Name;
+USHORT Id;
+  } DUMMYUNIONNAME;
+  _ANONYMOUS_UNION union {
+  ULONG OffsetToData;
+_ANONYMOUS_STRUCT struct {
+ULONG OffsetToDirectory:31;
+  ULONG DataIsDirectory:1;
+} DUMMYSTRUCTNAME2;
+  } DUMMYUNIONNAME2;
+} IMAGE_RESOURCE_DIRECTORY_ENTRY, *PIMAGE_RESOURCE_DIRECTORY_ENTRY;
 
 typedef struct _IMAGE_RESOURCE_DIRECTORY_STRING {
   USHORT Length;




[ros-diffs] [ion] 70504: [BOOTLIB]: Add very early work around font loading. [BOOTLIB]: Add mostly full support for resource and locale management. [BOOTLIB]: Stub out bootstat.dat (Boot Status Data L

2016-01-05 Thread ion
Author: ion
Date: Wed Jan  6 04:43:23 2016
New Revision: 70504

URL: http://svn.reactos.org/svn/reactos?rev=70504=rev
Log:
[BOOTLIB]: Add very early work around font loading.
[BOOTLIB]: Add mostly full support for resource and locale management.
[BOOTLIB]: Stub out bootstat.dat (Boot Status Data Log) support.
[BOOTLIB]: Some refactoring.
[BOOTMGFW]: Add a message table with a few initial strings. Also add an empty 
bootmgr.xsl stylesheet. We'll have to see what we want/need to do here.
[BOOTMGFW]: Correctly loading HTML and message table resource data, and add a 
few other additional initialization calls.
Next steps are to re-visit graphics code to support re-initialization.

Added:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.rc   (with props)
trunk/reactos/boot/environ/app/bootmgr/bootmgr.xsl   (with props)
trunk/reactos/boot/environ/lib/firmware/fwutil.c   (with props)
trunk/reactos/boot/environ/lib/misc/font.c   (with props)
trunk/reactos/boot/environ/lib/misc/resource.c   (with props)
trunk/reactos/include/reactos/mc/bootmsg.mc   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/misc/image.c
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/include/reactos/mc/CMakeLists.txt

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=70504=70503=70504=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Wed Jan  6 
04:43:23 2016
@@ -16,6 +16,9 @@
  lib/misc/bootreg.c
  lib/misc/util.c
  lib/misc/image.c
+ lib/misc/resource.c
+ lib/misc/font.c
+ lib/firmware/fwutil.c
  lib/firmware/efi/firmware.c
  lib/mm/mm.c
  lib/mm/pagealloc.c
@@ -65,7 +68,7 @@
 add_asm_files(bootlib_asm ${BOOTLIB_ASM_SOURCE})
 add_library(bootlib ${BOOTLIB_SOURCE} ${bootlib_asm})
 add_pch(bootlib app/bootmgr/bootmgr.h BOOTLIB_SOURCE)
-add_dependencies(bootlib bugcodes xdk)
+add_dependencies(bootlib bugcodes bootmsg xdk)
 
 list(APPEND BOOTMGR_BASE_SOURCE
  app/bootmgr/efiemu.c
@@ -73,7 +76,7 @@
  app/bootmgr/rtlcompat.c
  )
 
-add_executable(bootmgfw ${BOOTMGR_BASE_SOURCE})
+add_executable(bootmgfw ${BOOTMGR_BASE_SOURCE} app/bootmgr/bootmgr.rc)
 set_target_properties(bootmgfw PROPERTIES SUFFIX ".efi")
 
 if(MSVC)

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70504=70503=70504=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Wed Jan  6 
04:43:23 2016
@@ -844,6 +844,191 @@
 return Status;
 }
 
+typedef struct _BL_BSD_LOG_OBJECT
+{
+ULONG DeviceId;
+ULONG FileId;
+ULONG Unknown;
+ULONG Size;
+ULONG Flags;
+} BL_BSD_LOG_OBJECT, *PBL_BSD_LOG_OBJECT;
+
+BL_BSD_LOG_OBJECT BsdpLogObject;
+BOOLEAN BsdpLogObjectInitialized;
+
+VOID
+BlBsdInitializeLog (
+_In_ PBL_DEVICE_DESCRIPTOR LogDevice,
+_In_ PWCHAR LogPath,
+_In_ ULONG Flags
+)
+{
+NTSTATUS Status;
+
+/* Don't initialize twice */
+if (BsdpLogObjectInitialized)
+{
+return;
+}
+
+/* Set invalid IDs for now */
+BsdpLogObject.DeviceId = -1;
+BsdpLogObject.FileId = -1;
+
+/* Open the BSD device */
+Status = BlpDeviceOpen(LogDevice,
+   BL_DEVICE_READ_ACCESS | BL_DEVICE_WRITE_ACCESS,
+   0,
+   );
+if (!NT_SUCCESS(Status))
+{
+/* Welp that didn't work */
+goto FailurePath;
+}
+
+/* Now open the BSD itself */
+Status = BlFileOpen(BsdpLogObject.DeviceId,
+LogPath,
+BL_FILE_READ_ACCESS | BL_FILE_WRITE_ACCESS,
+);
+if (!NT_SUCCESS(Status))
+{
+/* D'oh */
+goto FailurePath;
+}
+
+/* The BSD is open. Start doing stuff to it */
+EfiPrintf(L"Unimplemented BSD path\r\n");
+Status =  STATUS_NOT_IMPLEMENTED;
+
+FailurePath:
+/* Close the BSD if we had it open */
+if (BsdpLogObject.FileId != -1)
+{
+BlFileClose(BsdpLogObject.FileId);
+}
+
+/* Close the devi

[ros-diffs] [ion] 70489: [CMLIB]: Move Value functions to CMLIB as well, so that they can be shared with the new boot code.

2016-01-04 Thread ion
Author: ion
Date: Tue Jan  5 01:51:54 2016
New Revision: 70489

URL: http://svn.reactos.org/svn/reactos?rev=70489=rev
Log:
[CMLIB]: Move Value functions to CMLIB as well, so that they can be shared with 
the new boot code.

Added:
trunk/reactos/lib/cmlib/cmvalue.c
  - copied, changed from r70480, trunk/reactos/ntoskrnl/config/cmvalue.c
Removed:
trunk/reactos/ntoskrnl/config/cmvalue.c
Modified:
trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c
trunk/reactos/lib/cmlib/CMakeLists.txt
trunk/reactos/lib/cmlib/cmdata.h
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/ntoskrnl/config/cmapi.c
trunk/reactos/ntoskrnl/include/internal/cm_x.h
trunk/reactos/ntoskrnl/ntos.cmake

Modified: trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c?rev=70489=70488=70489=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c  [iso-8859-1] Tue Jan  5 
01:51:54 2016
@@ -75,3 +75,15 @@
 {
 return 0;
 }
+
+VOID
+NTAPI
+KeBugCheckEx(
+_In_ ULONG BugCheckCode,
+_In_ ULONG_PTR BugCheckParameter1,
+_In_ ULONG_PTR BugCheckParameter2,
+_In_ ULONG_PTR BugCheckParameter3,
+_In_ ULONG_PTR BugCheckParameter4)
+{
+__assume(0);
+}

Modified: trunk/reactos/lib/cmlib/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/CMakeLists.txt?rev=70489=70488=70489=diff
==
--- trunk/reactos/lib/cmlib/CMakeLists.txt  [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/CMakeLists.txt  [iso-8859-1] Tue Jan  5 
01:51:54 2016
@@ -9,6 +9,7 @@
 cmindex.c
 cmname.c
 cmtools.c
+cmvalue.c
 hivebin.c
 hivecell.c
 hiveinit.c

Modified: trunk/reactos/lib/cmlib/cmdata.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmdata.h?rev=70489=70488=70489=diff
==
--- trunk/reactos/lib/cmlib/cmdata.h[iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmdata.h[iso-8859-1] Tue Jan  5 01:51:54 2016
@@ -47,6 +47,13 @@
 // CM_KEY_VALUE Flags
 //
 #define VALUE_COMP_NAME 0x0001
+
+//
+// CM_KEY_VALUE Types
+//
+#define CM_KEY_VALUE_SMALL  0x4
+#define CM_KEY_VALUE_BIG0x3FD8
+#define CM_KEY_VALUE_SPECIAL_SIZE   0x8000
 
 #include 
 

Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=70489=70488=70489=diff
==
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Tue Jan  5 01:51:54 2016
@@ -160,6 +160,7 @@
 #include 
 #include "hivedata.h"
 #include "cmdata.h"
+#include "bugcodes.h"
 
 #if defined(_TYPEDEFS_HOST_H) || defined(__FREELDR_H)
 
@@ -253,6 +254,56 @@
 
 extern ULONG CmlibTraceLevel;
 
+//
+// Hack since bigkeys are not yet supported
+//
+#define ASSERT_VALUE_BIG(h, s)  \
+ASSERTMSG("Big keys not supported!", !CmpIsKeyValueBig(h, s));
+
+//
+// Returns whether or not this is a small valued key
+//
+static inline
+BOOLEAN
+CmpIsKeyValueSmall(OUT PULONG RealLength,
+   IN ULONG Length)
+{
+/* Check if the length has the special size value */
+if (Length >= CM_KEY_VALUE_SPECIAL_SIZE)
+{
+/* It does, so this is a small key: return the real length */
+*RealLength = Length - CM_KEY_VALUE_SPECIAL_SIZE;
+return TRUE;
+}
+
+/* This is not a small key, return the length we read */
+*RealLength = Length;
+return FALSE;
+}
+
+//
+// Returns whether or not this is a big valued key
+//
+static inline
+BOOLEAN
+CmpIsKeyValueBig(IN PHHIVE Hive,
+ IN ULONG Length)
+{
+/* Check if the hive is XP Beta 1 or newer */
+if (Hive->Version >= HSYS_WHISTLER_BETA1)
+{
+/* Check if the key length is valid for a big value key */
+if ((Length < CM_KEY_VALUE_SPECIAL_SIZE) && (Length > 
CM_KEY_VALUE_BIG))
+{
+/* Yes, this value is big */
+return TRUE;
+}
+}
+
+/* Not a big value key */
+return FALSE;
+}
+
 /*
  * Public Hive functions.
  */

Copied: trunk/reactos/lib/cmlib/cmvalue.c (from r70480, 
trunk/reactos/ntoskrnl/config/cmvalue.c)
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmvalue.c?p2=trunk/reactos/lib/cmlib/cmvalue.c=trunk/reactos/ntoskrnl/config/cmvalue.c=70480=70489=70489=diff
===

[ros-diffs] [ion] 70490: [CMLIB]: Attempt fix for Linux hosts.

2016-01-04 Thread ion
Author: ion
Date: Tue Jan  5 01:55:40 2016
New Revision: 70490

URL: http://svn.reactos.org/svn/reactos?rev=70490=rev
Log:
[CMLIB]: Attempt fix for Linux hosts.

Modified:
trunk/reactos/lib/cmlib/cmlib.h

Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=70490=70489=70490=diff
==
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Tue Jan  5 01:55:40 2016
@@ -101,6 +101,7 @@
 #define CMLTRACE(x, ...)
 #undef PAGED_CODE
 #define PAGED_CODE()
+#define REGISTRY_ERROR   ((ULONG)0x0051L)
 #else
 //
 // Debug/Tracing support
@@ -118,6 +119,7 @@
 
 #include 
 #include 
+#include 
 #undef PAGED_CODE
 #define PAGED_CODE()
 
@@ -160,7 +162,6 @@
 #include 
 #include "hivedata.h"
 #include "cmdata.h"
-#include "bugcodes.h"
 
 #if defined(_TYPEDEFS_HOST_H) || defined(__FREELDR_H)
 




[ros-diffs] [ion] 70491: [BOOTMGFW]: Implement the rtlcompat functions, so that Rtl string functions will actually work. [HIVEBCD]: Start filling out a minimalistic BCD Hive layout to try out the BCD

2016-01-04 Thread ion
Author: ion
Date: Tue Jan  5 05:12:01 2016
New Revision: 70491

URL: http://svn.reactos.org/svn/reactos?rev=70491=rev
Log:
[BOOTMGFW]: Implement the rtlcompat functions, so that Rtl string functions 
will actually work.
[HIVEBCD]: Start filling out a minimalistic BCD Hive layout to try out the BCD 
parsing/conversion code in my WC.

Modified:
trunk/reactos/boot/bootdata/hivebcd.inf
trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c

Modified: trunk/reactos/boot/bootdata/hivebcd.inf
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivebcd.inf?rev=70491=70490=70491=diff
==
--- trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] (original)
+++ trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] Tue Jan  5 
05:12:01 2016
@@ -6,6 +6,11 @@
 BCD,"BCD\Description\Control","System",0x00010003,1
 BCD,"BCD\Description\Control","TreatAtSystem",0x00010003,1
 BCD,"BCD\Description\Control","KeyName",2,"BCD"
-BCD,"BCD\Objects",,0x0012
+
+BCD,"BCD\Objects\{9dea862c-5cdd-4e70-acc1-f32b344d4795}\Description","Type",0x00010003,0x1012
+
+BCD,"BCD\Objects\{9dea862c-5cdd-4e70-acc1-f32b344d4795}\Elements\1202","Element",2,"\EFI\BOOT\BOOTIA32.EFI"
+BCD,"BCD\Objects\{9dea862c-5cdd-4e70-acc1-f32b344d4795}\Elements\1204","Element",2,"ReactOS
 Boot Manager"
+BCD,"BCD\Objects\{9dea862c-5cdd-4e70-acc1-f32b344d4795}\Elements\1205","Element",2,"en-US"
 
 ; EOF

Modified: trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c?rev=70491=70490=70491=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/rtlcompat.c  [iso-8859-1] Tue Jan  5 
05:12:01 2016
@@ -30,7 +30,8 @@
 _In_ ULONG Tag
 )
 {
-return NULL;
+UNREFERENCED_PARAMETER(Tag);
+return BlMmAllocateHeap(Bytes);
 }
 
 VOID
@@ -40,7 +41,8 @@
 _In_ ULONG Tag
 )
 {
-return;
+UNREFERENCED_PARAMETER(Tag);
+BlMmFreeHeap(Mem);
 }
 
 NTSTATUS
@@ -64,7 +66,11 @@
 IN PCHAR Message OPTIONAL
 )
 {
-
+EfiPrintf(L"*** ASSERTION %s FAILED AT %d in %s (%s) ***\r \n",
+  FailedAssertion,
+  LineNumber,
+  FileName,
+  Message);
 }
 
 ULONG
@@ -73,6 +79,7 @@
 ...
 )
 {
+EfiPrintf(L"%s\r\n", Format);
 return 0;
 }
 




[ros-diffs] [ion] 70492: [BOOTLIB]: Separate out bcd.c into bcdopt.c, bootreg.c and bcd.c [BOOTLIB]: Implement routines to enumerate subkeys and to read a key value. [BOOTLIB]: Implement routines to p

2016-01-04 Thread ion
Author: ion
Date: Tue Jan  5 06:09:22 2016
New Revision: 70492

URL: http://svn.reactos.org/svn/reactos?rev=70492=rev
Log:
[BOOTLIB]: Separate out bcd.c into bcdopt.c, bootreg.c and bcd.c
[BOOTLIB]: Implement routines to enumerate subkeys and to read a key value.
[BOOTLIB]: Implement routines to parse, enumerate, and convert registry data 
into BCD elements, and to convert BCD elements into boot library BCD options.
[BOOTLIB/BOOTMGFW]: Lots of cleanups, mainly around the fact we now use 
ntintsafe.h instead of the manually self-inlined code from before, and from 
documenting additional flag values, and from using our newfound BCD powers.
[BOOTMGFW]: Implement BmGetOptionList, BmpUpdateApplicationOptions.
[BOOTMGFW]: Prepare for post-BCD library reinitialization. We correctly read 
the 3 BCD options so far in the hive.

Added:
trunk/reactos/boot/environ/lib/misc/bcdopt.c   (with props)
trunk/reactos/boot/environ/lib/misc/bootreg.c   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/misc/bcd.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

[This mail would be too long, it was shortened to contain the URLs only.]

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.h?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/include/bcd.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bcd.h?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/lib/bootlib.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/bootlib.c?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/lib/io/display/display.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/display/display.c?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/lib/misc/bcd.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcd.c?rev=70492=70491=70492=diff

Added: trunk/reactos/boot/environ/lib/misc/bcdopt.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcdopt.c?rev=70492

Added: trunk/reactos/boot/environ/lib/misc/bootreg.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bootreg.c?rev=70492

Modified: trunk/reactos/boot/environ/lib/mm/mm.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?rev=70492=70491=70492=diff

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=70492=70491=70492=diff




[ros-diffs] [ion] 70483: [NDK]: Document RtlPushFrame, RtlPopFrame, RtlGetFrame. [NDK]: Add TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED, TEB_ACTIVE_FRAME_EX, TEB_ACTIVE_FRAME_CONTEXT_EX from the CoreCLR so

2016-01-03 Thread ion
Author: ion
Date: Sun Jan  3 16:23:38 2016
New Revision: 70483

URL: http://svn.reactos.org/svn/reactos?rev=70483=rev
Log:
[NDK]: Document RtlPushFrame, RtlPopFrame, RtlGetFrame.
[NDK]: Add TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED, TEB_ACTIVE_FRAME_EX, 
TEB_ACTIVE_FRAME_CONTEXT_EX from the CoreCLR sources (clrnt.h)
[RTL]: Implement RtlPushFrame, RtlPopFrame, RtlGetFrame.
[NTDLL]: Export the above.
[RTL]: Fix MSVC warning after someone's earlier WINE merge.

Modified:
trunk/reactos/dll/ntdll/def/ntdll.spec
trunk/reactos/include/ndk/pstypes.h
trunk/reactos/include/ndk/rtlfuncs.h
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/lib/rtl/actctx.c
trunk/reactos/lib/rtl/debug.c

Modified: trunk/reactos/dll/ntdll/def/ntdll.spec
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/ntdll/def/ntdll.spec?rev=70483=70482=70483=diff
==
--- trunk/reactos/dll/ntdll/def/ntdll.spec  [iso-8859-1] (original)
+++ trunk/reactos/dll/ntdll/def/ntdll.spec  [iso-8859-1] Sun Jan  3 
16:23:38 2016
@@ -655,7 +655,7 @@
 653 stdcall RtlGetDaclSecurityDescriptor(ptr ptr ptr ptr)
 654 stdcall RtlGetElementGenericTable(ptr long)
 655 stdcall RtlGetElementGenericTableAvl(ptr long)
-# stdcall RtlGetFrame
+656 stdcall RtlGetFrame()
 657 stdcall RtlGetFullPathName_U(wstr long ptr ptr)
 658 stdcall RtlGetFullPathName_UstrEx(ptr ptr ptr ptr ptr ptr ptr ptr)
 659 stdcall RtlGetGroupSecurityDescriptor(ptr ptr ptr)
@@ -797,11 +797,11 @@
 792 stdcall RtlOpenCurrentUser(long ptr)
 793 stdcall RtlPcToFileHeader(ptr ptr)
 794 stdcall RtlPinAtomInAtomTable(ptr long)
-# stdcall RtlPopFrame
+795 stdcall RtlPopFrame(ptr)
 796 stdcall RtlPrefixString(ptr ptr long)
 797 stdcall RtlPrefixUnicodeString(ptr ptr long)
 798 stdcall RtlProtectHeap(ptr long)
-# stdcall RtlPushFrame
+799 stdcall RtlPushFrame(ptr)r
 800 stdcall RtlQueryAtomInAtomTable(ptr long ptr ptr ptr ptr)
 801 stdcall RtlQueryDepthSList(ptr)
 802 stdcall RtlQueryEnvironmentVariable_U(ptr ptr ptr)

Modified: trunk/reactos/include/ndk/pstypes.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/pstypes.h?rev=70483=70482=70483=diff
==
--- trunk/reactos/include/ndk/pstypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/pstypes.h [iso-8859-1] Sun Jan  3 16:23:38 2016
@@ -181,6 +181,11 @@
 // TLS Slots
 //
 #define TLS_MINIMUM_AVAILABLE   64
+
+//
+// TEB Active Frame Flags
+//
+#define TEB_ACTIVE_FRAME_CONTEXT_FLAG_EXTENDED 0x1
 
 //
 // Job Access Types
@@ -684,13 +689,29 @@
 ULONG Flags;
 LPSTR FrameName;
 } TEB_ACTIVE_FRAME_CONTEXT, *PTEB_ACTIVE_FRAME_CONTEXT;
+typedef const struct _TEB_ACTIVE_FRAME_CONTEXT *PCTEB_ACTIVE_FRAME_CONTEXT;
+
+typedef struct _TEB_ACTIVE_FRAME_CONTEXT_EX
+{
+TEB_ACTIVE_FRAME_CONTEXT BasicContext;
+PCSTR SourceLocation;
+} TEB_ACTIVE_FRAME_CONTEXT_EX, *PTEB_ACTIVE_FRAME_CONTEXT_EX;
+typedef const struct _TEB_ACTIVE_FRAME_CONTEXT_EX 
*PCTEB_ACTIVE_FRAME_CONTEXT_EX;
 
 typedef struct _TEB_ACTIVE_FRAME
 {
 ULONG Flags;
 struct _TEB_ACTIVE_FRAME *Previous;
-PTEB_ACTIVE_FRAME_CONTEXT Context;
+PCTEB_ACTIVE_FRAME_CONTEXT Context;
 } TEB_ACTIVE_FRAME, *PTEB_ACTIVE_FRAME;
+typedef const struct _TEB_ACTIVE_FRAME *PCTEB_ACTIVE_FRAME;
+
+typedef struct _TEB_ACTIVE_FRAME_EX
+{
+TEB_ACTIVE_FRAME BasicFrame;
+PVOID ExtensionIdentifier;
+} TEB_ACTIVE_FRAME_EX, *PTEB_ACTIVE_FRAME_EX;
+typedef const struct _TEB_ACTIVE_FRAME_EX *PCTEB_ACTIVE_FRAME_EX;
 
 typedef struct _CLIENT_ID32
 {

Modified: trunk/reactos/include/ndk/rtlfuncs.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/rtlfuncs.h?rev=70483=70482=70483=diff
==
--- trunk/reactos/include/ndk/rtlfuncs.h[iso-8859-1] (original)
+++ trunk/reactos/include/ndk/rtlfuncs.h[iso-8859-1] Sun Jan  3 
16:23:38 2016
@@ -3004,6 +3004,30 @@
 _In_ USHORT CompressionFormatAndEngine,
 _Out_ PULONG CompressBufferWorkSpaceSize,
 _Out_ PULONG CompressFragmentWorkSpaceSize
+);
+
+//
+// Frame Functions
+//
+NTSYSAPI
+VOID
+NTAPI
+RtlPopFrame(
+_In_ PTEB_ACTIVE_FRAME Frame
+);
+
+NTSYSAPI
+VOID
+NTAPI
+RtlPushFrame(
+_In_ PTEB_ACTIVE_FRAME Frame
+);
+
+NTSYSAPI
+PTEB_ACTIVE_FRAME
+NTAPI
+RtlGetFrame(
+VOID
 );
 
 //

Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=70483=70482=70483=diff
==
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Sun Jan  3 16:23:38 2016
@@ -455,6 +455,32 @@
 IN PCUNICODE_STRING SearchName
 );
 
+HCELL_INDEX
+NTAPI
+CmpFindSubKeyByNumber(
+IN PHHIVE Hive,
+IN PCM_KEY_NODE Node,
+IN ULONG Number

[ros-diffs] [ion] 69453: [HIVEBCD]: - The Objects key is in the root, not under Description. [MKHIVE]: - Make it *actually* build a BCD hive. It was doing nothing before, because it turns out that irr

2015-10-05 Thread ion
Author: ion
Date: Mon Oct  5 07:22:11 2015
New Revision: 69453

URL: http://svn.reactos.org/svn/reactos?rev=69453=rev
Log:
[HIVEBCD]:
- The Objects key is in the root, not under Description.
[MKHIVE]:
- Make it *actually* build a BCD hive. It was doing nothing before, because it 
turns out that irrespective of what appear to be dynamic, command-line driven 
behavior modes, all of mkhive's logic is deeply tied together through C-level 
changes and knowledge. (for example, that's why calling it with a single .inf, 
it still wants to build 6 hives for you). There were also some copy/pasta bugs 
in the BCD handling code, now fixed.

Modified:
trunk/reactos/boot/bootdata/hivebcd.inf
trunk/reactos/tools/mkhive/mkhive.c
trunk/reactos/tools/mkhive/reginf.c
trunk/reactos/tools/mkhive/registry.c
trunk/reactos/tools/mkhive/registry.h

Modified: trunk/reactos/boot/bootdata/hivebcd.inf
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivebcd.inf?rev=69453=69452=69453=diff
==
--- trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] (original)
+++ trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] Mon Oct  5 
07:22:11 2015
@@ -3,9 +3,9 @@
 
 [AddReg]
 
-HKLM,"BCD\Description\Control","System",0x00010003,1
-HKLM,"BCD\Description\Control","TreatAtSystem",0x00010003,1
-HKLM,"BCD\Description\Control","KeyName",2,"BCD"
-HKLM,"BCD\Description\Objects",,0x0012
+BCD,"BCD\Description\Control","System",0x00010003,1
+BCD,"BCD\Description\Control","TreatAtSystem",0x00010003,1
+BCD,"BCD\Description\Control","KeyName",2,"BCD"
+BCD,"BCD\Objects",,0x0012
 
 ; EOF

Modified: trunk/reactos/tools/mkhive/mkhive.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.c?rev=69453=69452=69453=diff
==
--- trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] Mon Oct  5 07:22:11 2015
@@ -146,7 +146,7 @@
 convert_path (FileName, argv[1]);
 strcat (FileName, DIR_SEPARATOR_STRING);
 strcat (FileName, "BCD");
-if (!ExportBinaryHive (FileName, ))
+if (!ExportBinaryHive (FileName, ))
 {
 return 1;
 }

Modified: trunk/reactos/tools/mkhive/reginf.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/reginf.c?rev=69453=69452=69453=diff
==
--- trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/reginf.c [iso-8859-1] Mon Oct  5 07:22:11 2015
@@ -53,11 +53,13 @@
 static const WCHAR HKLM[] = {'H','K','L','M',0};
 static const WCHAR HKU[] = {'H','K','U',0};
 static const WCHAR HKR[] = {'H','K','R',0};
+static const WCHAR BCD[] = {'B','C','D',0};
 
 static const WCHAR HKCRPath[] = 
{'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\','S','O','F','T','W','A','R','E','\\','C','l','a','s','s','e','s','\\',0};
 static const WCHAR HKCUPath[] = 
{'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\','.','D','E','F','A','U','L','T','\\',0};
 static const WCHAR HKLMPath[] = 
{'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',0};
 static const WCHAR HKUPath[] = 
{'\\','R','e','g','i','s','t','r','y','\\','U','s','e','r','\\',0};
+static const WCHAR BCDPath[] = 
{'\\','R','e','g','i','s','t','r','y','\\','M','a','c','h','i','n','e','\\',0};
 
 static const WCHAR AddReg[] = {'A','d','d','R','e','g',0};
 static const WCHAR DelReg[] = {'D','e','l','R','e','g',0};
@@ -88,6 +90,12 @@
 if (!strcmpiW (Name, HKU))
 {
 strcpyW (Name, HKUPath);
+return TRUE;
+}
+
+if (!strcmpiW (Name, BCD))
+{
+strcpyW (Name, BCDPath);
 return TRUE;
 }
 

Modified: trunk/reactos/tools/mkhive/registry.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/registry.c?rev=69453=69452=69453=diff
==
--- trunk/reactos/tools/mkhive/registry.c   [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/registry.c   [iso-8859-1] Mon Oct  5 
07:22:11 2015
@@ -47,6 +47,7 @@
 CMHIVE SecurityHive; /* \Registry\Machine\SECURITY */
 CMHIVE SoftwareHive; /* \Registry\Machine\SOFTWARE */
 CMHIVE SystemHive;   /* \Registry\Machine\SYSTEM */
+CMHIVE BcdHive;  /* \Registry\Machine\BCD */
 
 static PMEMKEY
 CreateInMemoryStructure(
@@ -552,6 +553,11 @@
 ,
 L"Registry\\Machine\\SOFTWARE");
 
+/* Create BCD key */
+ConnectRegistry(NULL,
+  

[ros-diffs] [ion] 69454: [BOOTLIB]: - Implement BiInitializeAndValidateHive, BiLoadHive. Leveraging our existing cmlib and the previously committed code, we are now able to read the BCD file, parse it

2015-10-05 Thread ion
Author: ion
Date: Mon Oct  5 07:25:27 2015
New Revision: 69454

URL: http://svn.reactos.org/svn/reactos?rev=69454=rev
Log:
[BOOTLIB]:
- Implement BiInitializeAndValidateHive, BiLoadHive. Leveraging our existing 
cmlib and the previously committed code, we are now able to read the BCD file, 
parse it as a registry hive, and lookup the BCD Objects subkey! The BCD Data 
Store is now available to the Boot Manager (which also validates that reading 
from ETFS works).

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/lib/misc/bcd.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69454=69453=69454=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Oct  5 
07:25:27 2015
@@ -373,7 +373,7 @@
 
 /* Build the error string */
 swprintf(FormatString,
- L"\nAn error occurred (%08x) while attempting"
+ L"\nAn error occurred (%08x) while attempting "
  L"to read the boot configuration data file %s\n",
  ErrorStatus,
  Buffer);
@@ -685,7 +685,7 @@
 PBL_RETURN_ARGUMENTS ReturnArguments;
 BOOLEAN RebootOnError;
 PGUID AppIdentifier;
-   // HANDLE BcdHandle;
+HANDLE BcdHandle;
 
 EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\n");
 
@@ -733,8 +733,8 @@
 BmFwInitializeBootDirectoryPath();
 
 /* Load and initialize the boot configuration database (BCD) */
-//Status = BmOpenDataStore();
-//EfiPrintf(L"BCD Open: %lx\r\n", Status);
+Status = BmOpenDataStore();
+EfiPrintf(L"BCD Open: %lx\r\n", Status);
 
 /* do more stuff!! */
 EfiPrintf(L"We are A-OK!\r\n");

Modified: trunk/reactos/boot/environ/lib/misc/bcd.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcd.c?rev=69454=69453=69454=diff
==
--- trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] Mon Oct  5 
07:25:27 2015
@@ -451,15 +451,18 @@
 return Status;
 }
 
-#define BI_FLUSH_HIVE   0x01
+#define BI_FLUSH_HIVE   0x01
+#define BI_HIVE_WRITEABLE   0x02
 
 typedef struct _BI_KEY_HIVE
 {
-PVOID ImageBase;
+PHBASE_BLOCK BaseBlock;
+ULONG HiveSize;
 PBL_FILE_PATH_DESCRIPTOR FilePath;
 CMHIVE Hive;
 LONG ReferenceCount;
 ULONG Flags;
+PCM_KEY_NODE RootNode;
 } BI_KEY_HIVE, *PBI_KEY_HIVE;
 
 typedef struct _BI_KEY_OBJECT
@@ -646,7 +649,7 @@
 }
 
 /* We found it -- get the key node out of it */
-ParentNode = (PCM_KEY_NODE)Hive->GetCellRoutine(Hive, KeyCell);
+ParentNode = (PCM_KEY_NODE)HvGetCell(Hive, KeyCell);
 if (!ParentNode)
 {
 Status = STATUS_REGISTRY_CORRUPT;
@@ -699,16 +702,386 @@
 return Status;
 }
 
+BOOLEAN BiHiveHashLibraryInitialized;
+ULONGLONG HvSymcryptSeed;
+
+BOOLEAN
+HvIsInPlaceBaseBlockValid (
+_In_ PHBASE_BLOCK BaseBlock
+)
+{
+ULONG HiveLength, HeaderSum;
+BOOLEAN Valid;
+
+/* Assume failure */
+Valid = FALSE;
+
+/* Check for incorrect signature, type, version, or format */
+if ((BaseBlock->Signature == 'fger') &&
+(BaseBlock->Type == 0) &&
+(BaseBlock->Major <= 1) &&
+(BaseBlock->Minor <= 5) &&
+(BaseBlock->Minor >= 3) &&
+(BaseBlock->Format == 1))
+{
+/* Check for invalid hive size */
+HiveLength = BaseBlock->Length;
+if (HiveLength)
+{
+/* Check for misaligned or too large hive size */
+if (!(HiveLength & 0xFFF) && HiveLength <= 0x7FFFE000)
+{
+/* Check for invalid header checksum */
+HeaderSum = HvpHiveHeaderChecksum(BaseBlock);
+if (HeaderSum == BaseBlock->CheckSum)
+{
+/* All good */
+Valid = TRUE;
+}
+}
+}
+}
+
+/* Return validity */
+return Valid;
+}
+
+NTSTATUS
+BiInitializeAndValidateHive (
+_In_ PBI_KEY_HIVE Hive
+)
+{
+ULONG HiveSize;
+NTSTATUS Status;
+
+/* Make sure the hive is at least the size of a base block */
+if (Hive->HiveSize < sizeof(HBASE_BLOCK))
+{
+return STATUS_REGISTRY_CORRUPT;
+}
+
+/* Make sure that the base block accurately describes the size of the hive 
*/
+HiveSize = Hive->BaseBlock->Length + sizeof(HBASE_BLOCK);
+if ((HiveSiz

[ros-diffs] [ion] 69442: [FS_REC]: Guard against ROUND_UP/DOWN already being defined.

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 17:14:24 2015
New Revision: 69442

URL: http://svn.reactos.org/svn/reactos?rev=69442=rev
Log:
[FS_REC]: Guard against ROUND_UP/DOWN already being defined.

Modified:
trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h

Modified: trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h?rev=69442=69441=69442=diff
==
--- trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h   [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/fs_rec/fs_rec.h   [iso-8859-1] Sun Oct  4 
17:14:24 2015
@@ -20,11 +20,13 @@
 #define UDFS_AVDP_SECTOR   256
 
 /* Non-standard rounding macros */
+#ifndef ROUND_UP
 #define ROUND_UP(n, align) \
 ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
 
 #define ROUND_DOWN(n, align) \
 (((ULONG)n) & ~((align) - 1l))
+#endif
 
 /* Conversion types and macros taken from internal ntifs headers */
 typedef union _UCHAR1




[ros-diffs] [ion] 69441: [NTOSKRNL]: Jerome _was_ nice enough to make our cells ordered (64222).

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 17:13:38 2015
New Revision: 69441

URL: http://svn.reactos.org/svn/reactos?rev=69441=rev
Log:
[NTOSKRNL]: Jerome _was_ nice enough to make our cells ordered (64222).

Modified:
trunk/reactos/ntoskrnl/config/cmindex.c

Modified: trunk/reactos/ntoskrnl/config/cmindex.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmindex.c?rev=69441=69440=69441=diff
==
--- trunk/reactos/ntoskrnl/config/cmindex.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmindex.c [iso-8859-1] Sun Oct  4 
17:13:38 2015
@@ -11,8 +11,6 @@
 #include "ntoskrnl.h"
 #define NDEBUG
 #include "debug.h"
-
-#define SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
 
 /* GLOBALS ***/
 
@@ -161,9 +159,7 @@
 while (TRUE)
 {
 /* Choose next entry */
-#ifdef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
 i = ((High - Low) / 2) + Low;
-#endif
 
 /* Get the leaf cell and then the leaf itself */
 LeafCell = Index->List[i];
@@ -193,7 +189,6 @@
 goto Return;
 }
 
-#ifdef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
 /* Check for negative result */
 if (Result < 0)
 {
@@ -232,7 +227,6 @@
 /* Update the base to this index, since we know it's not 
lower. */
 Low = i;
 }
-#endif
 }
 else
 {
@@ -247,16 +241,6 @@
 
 /* Release the leaf cell */
 HvReleaseCell(Hive, LeafCell);
-
-#ifndef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
-/* Go to the next index, and return failure if we reach the end */
-if (++i > High)
-{
-/* Return failure */
-*SubKey = HCELL_NIL;
-return 0;
-}
-#endif
 }
 
 /* Make sure we got here for the right reasons */
@@ -386,11 +370,7 @@
 
 /* Get the upper bound and middle entry */
 High = Index->Count - 1;
-#ifdef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
 i = High / 2;
-#else
-i = 0;
-#endif
 
 /* Check if we don't actually have any entries */
 if (!Index->Count)
@@ -415,7 +395,6 @@
 /* Check if we got lucky and found it */
 if (!Result) return i;
 
-#ifdef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
 /* Check if the result is below us */
 if (Result < 0)
 {
@@ -435,14 +414,6 @@
 
 /* Set the new index */
 i = ((High - Low) / 2) + Low;
-#else
-if (++i > High)
-{
-/* Return failure */
-*SubKey = HCELL_NIL;
-return 0;
-}
-#endif
 }
 
 /*
@@ -735,33 +706,6 @@
 /* Check if this is another index root */
 if (IndexRoot->Signature == CM_KEY_INDEX_ROOT)
 {
-
-#ifndef SOMEONE_WAS_NICE_ENOUGH_TO_MAKE_OUR_CELLS_LEXICALLY_SORTED
-/* CmpFindSubKeyInRoot is useless for actually finding the 
correct leaf when keys are not sorted */
-LONG ii;
-PCM_KEY_INDEX Leaf;
-/* Loop through each leaf in the index root */
-for (ii=0; iiCount; ii++)
-{
-Leaf = HvGetCell(Hive, IndexRoot->List[ii]);
-if (Leaf)
-{
-Found = CmpFindSubKeyInLeaf(Hive, Leaf, SearchName, 
);
-HvReleaseCell(Hive, IndexRoot->List[ii]);
-if (Found & 0x8000)
-{
-HvReleaseCell(Hive, CellToRelease);
-return HCELL_NIL;
-}
-
-if (SubKey != HCELL_NIL)
-{
-HvReleaseCell(Hive, CellToRelease);
-return SubKey;
-}
-}
- }
-#endif
 /* Lookup the name in the root */
 Found = CmpFindSubKeyInRoot(Hive,
 IndexRoot,




[ros-diffs] [ion] 69444: [CMLIB/NTOSKRNL]: - Move cmindex.c and cmname.c to cmlib, because bootmgr/winload use the kernel's cm implementation, unlike our freeldr which uses an almost copy-pasted-but-n

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 20:18:49 2015
New Revision: 69444

URL: http://svn.reactos.org/svn/reactos?rev=69444=rev
Log:
[CMLIB/NTOSKRNL]:
- Move cmindex.c and cmname.c to cmlib, because bootmgr/winload use the 
kernel's cm implementation, unlike our freeldr which uses an almost 
copy-pasted-but-not-shared-because-hey-why-not-have-to-fix-the-bugs-in-two-places-instead-of-just-one
 implementation.
- Minor fixes to headers to allow those two files to be used/built outside of 
ntoskrnl.

Added:
trunk/reactos/lib/cmlib/cmindex.c   (with props)
trunk/reactos/lib/cmlib/cmname.c   (with props)
Removed:
trunk/reactos/ntoskrnl/config/cmindex.c
trunk/reactos/ntoskrnl/config/cmname.c
Modified:
trunk/reactos/lib/cmlib/CMakeLists.txt
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/ntoskrnl/ntos.cmake

[This mail would be too long, it was shortened to contain the URLs only.]

Modified: trunk/reactos/lib/cmlib/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/CMakeLists.txt?rev=69444=69443=69444=diff

Added: trunk/reactos/lib/cmlib/cmindex.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmindex.c?rev=69444

Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=69444=69443=69444=diff

Added: trunk/reactos/lib/cmlib/cmname.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmname.c?rev=69444

Removed: trunk/reactos/ntoskrnl/config/cmindex.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmindex.c?rev=69443

Removed: trunk/reactos/ntoskrnl/config/cmname.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmname.c?rev=69443

Modified: trunk/reactos/ntoskrnl/ntos.cmake
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntos.cmake?rev=69444=69443=69444=diff




[ros-diffs] [ion] 69447: [BOOTLIB]: - WIP work to begin reading, parsing, mounting and loading the BCD hive into a data store. Untested, has missing pieces. - Implement BlFileSet/GetInformation, BlFil

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 21:07:12 2015
New Revision: 69447

URL: http://svn.reactos.org/svn/reactos?rev=69447=rev
Log:
[BOOTLIB]:
- WIP work to begin reading, parsing, mounting and loading the BCD hive into a 
data store. Untested, has missing pieces.
- Implement BlFileSet/GetInformation, BlFileReadEx, BlFileReadAtOffsetEx and 
helper structures/functions. Document multiple previously unknown/magic flags.
- Implement BlMmAllocatePhysicalPages. Stub BlMmFreePhysicalPages.
- Implement MmUnmapVirtualAddress, BlMmUnmapVirtualAddressEx when operating in 
real mode.
- Implement ImgpGetFileSize, ImgpReadFileAtOffset, ImgpOpenFile, ImgpCloseFile, 
BlImgAllocateImageBuffer, BlImgLoadImageWithProgress2.
- Implement BdDebuggerInitialized, BlBdDebuggerEnabled, BlStatusPrint, 
BlStatuserror. Stub BlBdPullRemoteFile.
- Implement BlGetBootOptionDevice.
- Implement BiReferenceHive, BiDereferenceHive, BiCloseKey, BiOpenKey. Stub 
BiFlushKey, BiLoadHive.
- Implement BiAddStoreFromFile, BcdOpenStoreFromFile.
- Stub BlUtlUpdateProcess and BlResourceFindMessage.
- Other misc. cleanups.
[BOOTMGR]:
- Implement BmpFatalErrorMessageFilter, BmErrorPurge, BmpErrorLog, 
BmFatalErrorEx.
- Implement BmpFwGetFullPath.
- Implement BmOpenDataStore.
- Stub BmOpenBootIni

Added:
trunk/reactos/boot/environ/lib/misc/debug.c   (with props)
trunk/reactos/boot/environ/lib/misc/image.c   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/include/bcd.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/file.c
trunk/reactos/boot/environ/lib/misc/bcd.c
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=69447=69446=69447=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Sun Oct  4 
21:07:12 2015
@@ -10,8 +10,10 @@
 list(APPEND BOOTLIB_SOURCE
  app/bootmgr/bootmgr.h
  lib/bootlib.c
+ lib/misc/debug.c
  lib/misc/bcd.c
  lib/misc/util.c
+ lib/misc/image.c
  lib/firmware/efi/firmware.c
  lib/mm/mm.c
  lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69447=69446=69447=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Sun Oct  4 
21:07:12 2015
@@ -22,6 +22,14 @@
 ULONGLONG PostTime;
 GUID BmApplicationIdentifier;
 PWCHAR BootDirectory;
+
+BL_BOOT_ERROR BmpErrorBuffer;
+PBL_BOOT_ERROR BmpInternalBootError;
+BL_PACKED_BOOT_ERROR BmpPackedBootError;
+
+BOOLEAN BmBootIniUsed;
+WCHAR BmpFileNameBuffer[128];
+PWCHAR ParentFileName = L"";
 
 /* FUNCTIONS */
 
@@ -120,8 +128,8 @@
 
 /* All done! */
 return Status;
-
-}
+}
+
 NTSTATUS
 BmFwInitializeBootDirectoryPath (
 VOID
@@ -187,6 +195,7 @@
 goto Quickie;
 }
 
+/* Save the boot directory */
 BootDirectory = L"\\EFI\\Microsoft\\Boot";
 
 Quickie:
@@ -216,6 +225,441 @@
 return Status;
 }
 
+NTSTATUS
+BmOpenBootIni (
+VOID
+)
+{
+/* Don't yet handled boot.ini */
+return STATUS_NOT_FOUND;
+}
+
+ULONG
+BmpFatalErrorMessageFilter (
+_In_ NTSTATUS ErrorStatus,
+_Out_ PULONG ErrorResourceId
+)
+{
+ULONG Result;
+
+/* Assume no message for now, check for known status message */
+Result = 0;
+switch (ErrorStatus)
+{
+/* Convert each status to a resource ID */
+case STATUS_UNEXPECTED_IO_ERROR:
+*ErrorResourceId = 9017;
+Result = 1;
+break;
+case STATUS_IMAGE_CHECKSUM_MISMATCH:
+*ErrorResourceId = 9018;
+break;
+case STATUS_INVALID_IMAGE_WIN_64:
+*ErrorResourceId = 9016;
+break;
+case 0xC428:
+*ErrorResourceId = 9019;
+Result = 2;
+break;
+case 0xC021:
+*ErrorResourceId = 9013;
+break;
+}
+
+/* Return the type of message */
+return Result;
+}
+
+VOID
+BmErrorPurge (
+VOID
+)
+{
+/* Check if a boot error is present */
+if (BmpPackedBootError.BootError)
+{
+/* Purge it */
+BlMmFreeHeap(BmpPackedBootError.BootError);
+BmpPackedBootEr

[ros-diffs] [ion] 69446: [CMLIB]: - Missing header change from previous commit.

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 20:24:52 2015
New Revision: 69446

URL: http://svn.reactos.org/svn/reactos?rev=69446=rev
Log:
[CMLIB]:
- Missing header change from previous commit.

Modified:
trunk/reactos/lib/cmlib/cmlib.h

Modified: trunk/reactos/lib/cmlib/cmlib.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=69446=69445=69446=diff
==
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Sun Oct  4 20:24:52 2015
@@ -99,6 +99,8 @@
 #define EX_PUSH_LOCK PULONG_PTR
 
 #define CMLTRACE(x, ...)
+#undef PAGED_CODE
+#define PAGED_CODE()
 #else
 //
 // Debug/Tracing support




[ros-diffs] [ion] 69445: [MKHIVE]: - Whoever wrote mkhive ran into the problem I just did, and realized hey-i-dont-fucking-want-to-use-that-almost-copy-pasted-but-not-shared-code-so-why-dont-i-use-the

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 20:23:25 2015
New Revision: 69445

URL: http://svn.reactos.org/svn/reactos?rev=69445=rev
Log:
[MKHIVE]:
- Whoever wrote mkhive ran into the problem I just did, and realized 
hey-i-dont-fucking-want-to-use-that-almost-copy-pasted-but-not-shared-code-so-why-dont-i-use-the-good-kernel-code-instead...
 but instead of taking the time to create a fucking library like I just did 
(cause that would be hard man, and fixing headers n' shit), just hard-coded the 
paths to the kernel files directly like a lazy shit. Fix mkhive to just rely on 
cmlib, which now has the files shared there.

Removed:
trunk/reactos/tools/mkhive/cmindex.c
trunk/reactos/tools/mkhive/cmname.c
Modified:
trunk/reactos/tools/mkhive/CMakeLists.txt

Modified: trunk/reactos/tools/mkhive/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/CMakeLists.txt?rev=69445=69444=69445=diff
==
--- trunk/reactos/tools/mkhive/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/CMakeLists.txt   [iso-8859-1] Sun Oct  4 
20:23:25 2015
@@ -9,8 +9,6 @@
 list(APPEND SOURCE
 binhive.c
 cmi.c
-cmindex.c
-cmname.c
 mkhive.c
 reginf.c
 registry.c

Removed: trunk/reactos/tools/mkhive/cmindex.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/cmindex.c?rev=69444
==
--- trunk/reactos/tools/mkhive/cmindex.c[iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/cmindex.c(removed)
@@ -1 +0,0 @@
-#include "../../ntoskrnl/config/cmindex.c"

Removed: trunk/reactos/tools/mkhive/cmname.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/cmname.c?rev=69444
==
--- trunk/reactos/tools/mkhive/cmname.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/cmname.c (removed)
@@ -1 +0,0 @@
-#include "../../ntoskrnl/config/cmname.c"




[ros-diffs] [ion] 69448: People's local builds use PCH by default, rosbuilds do not. A recipe for success.

2015-10-04 Thread ion
Author: ion
Date: Sun Oct  4 21:11:48 2015
New Revision: 69448

URL: http://svn.reactos.org/svn/reactos?rev=69448=rev
Log:
People's local builds use PCH by default, rosbuilds do not. A recipe for 
success.

Modified:
trunk/reactos/boot/environ/lib/misc/bcd.c

Modified: trunk/reactos/boot/environ/lib/misc/bcd.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcd.c?rev=69448=69447=69448=diff
==
--- trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] Sun Oct  4 
21:11:48 2015
@@ -9,6 +9,7 @@
 /* INCLUDES **/
 
 #include "bl.h"
+#include 
 
 /* FUNCTIONS */
 




[ros-diffs] [ion] 69450: [BOOTLIB]: - Fix BCD bugs.

2015-10-04 Thread ion
Author: ion
Date: Mon Oct  5 01:02:56 2015
New Revision: 69450

URL: http://svn.reactos.org/svn/reactos?rev=69450=rev
Log:
[BOOTLIB]:
- Fix BCD bugs.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/lib/misc/bcd.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69450=69449=69450=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Oct  5 
01:02:56 2015
@@ -505,6 +505,7 @@
 PVOID FinalBuffer;
 UNICODE_STRING BcdString;
 
+/* Initialize variables */
 PathBuffer = NULL;
 BcdDevice = NULL;
 BcdPath = NULL;
@@ -559,6 +560,7 @@
 
 /* Otherwise, compute the hardcoded path of the BCD */
 Status = BmpFwGetFullPath(L"\\BCD", );
+EfiPrintf(L"Status: %lx %s\r\n", Status, FullPath);
 if (!NT_SUCCESS(Status))
 {
 /* User the raw path */

Modified: trunk/reactos/boot/environ/app/bootmgr/efiemu.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/efiemu.c?rev=69450=69449=69450=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] Mon Oct  5 
01:02:56 2015
@@ -803,7 +803,7 @@
 /* Calculate where the next option should go */
 Option = (PVOID)((ULONG_PTR)Option + Size);
 
-/* Convert the path oprtion */
+/* Convert the path option */
 Status = EfiInitpConvertEfiFilePath(OsDevicePath,
 BcdOSLoaderString_SystemRoot,
 Option,

Modified: trunk/reactos/boot/environ/lib/misc/bcd.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/bcd.c?rev=69450=69449=69450=diff
==
--- trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/bcd.c   [iso-8859-1] Mon Oct  5 
01:02:56 2015
@@ -20,7 +20,7 @@
 )
 {
 ULONG_PTR NextOption = 0, ListOption;
-PBL_BCD_OPTION Option;
+PBL_BCD_OPTION Option, FoundOption;
 
 /* No options, bail out */
 if (!List)
@@ -29,12 +29,14 @@
 }
 
 /* Loop while we find an option */
-while (TRUE)
+FoundOption = NULL;
+do
 {
 /* Get the next option and see if it matches the type */
 Option = (PBL_BCD_OPTION)((ULONG_PTR)List + NextOption);
 if ((Option->Type == Type) && !(Option->Empty))
 {
+FoundOption = Option;
 break;
 }
 
@@ -49,20 +51,18 @@
 Option = MiscGetBootOption((PBL_BCD_OPTION)((ULONG_PTR)Option +
ListOption),
Type);
-
-/* Found one, return it */
 if (Option)
 {
-return Option;
+/* Return it */
+FoundOption = Option;
+break;
 }
 }
-}
-
-/* We found the option, return it */
-return Option;
-}
-
-
+} while (NextOption);
+
+/* Return the option that was found, if any */
+return FoundOption;
+}
 
 /*++
  * @name BlGetBootOptionListSize
@@ -94,7 +94,7 @@
 
 /* Update the offset */
 NextOffset = NextOption->NextEntryOffset;
-} while (NextOffset != 0);
+} while (NextOffset);
 
 /* Return final computed size */
 return Size;
@@ -119,7 +119,7 @@
 ULONG Size, Offset;
 
 /* Check if there's any data */
-if (BcdOption->DataOffset != 0)
+if (BcdOption->DataOffset)
 {
 /* Add the size of the data */
 Size = BcdOption->DataOffset + BcdOption->DataSize;
@@ -132,7 +132,7 @@
 
 /* Any associated options? */
 Offset = BcdOption->ListOffset;
-if (Offset != 0)
+if (Offset)
 {
 /* Go get those too */
 Size += BlGetBootOptionListSize((PVOID)((ULONG_PTR)BcdOption + 
Offset));
@@ -167,11 +167,13 @@
 {
 /* Extract the string */
 String = (PWCHAR)((ULONG_PTR)Option + Option->DataOffset);
+Status = STATUS_SUCCESS;
 }
 else
 {
 /* No string is present */
 String = NULL;
+Status = STATUS_NOT_FOUND;
 }
 
 /* Compute the data size */
@@ -182,9 +184,7 @@
 AppIdentifier = BlGetApplicationIdentifier();
 Status = BlpBootOptionCallbackString(AppIdentifier, Type, String, 
StringLength, , );
 #else
-Status = STATUS_SUCCESS

[ros-diffs] [ion] 69451: [BOOTLIB]: - Fix a regression - Add a few more flags - Don't look for BCD in "Microsoft" directory

2015-10-04 Thread ion
Author: ion
Date: Mon Oct  5 04:51:32 2015
New Revision: 69451

URL: http://svn.reactos.org/svn/reactos?rev=69451=rev
Log:
[BOOTLIB]:
- Fix a regression
- Add a few more flags
- Don't look for BCD in "Microsoft" directory

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/etfs.c
trunk/reactos/boot/environ/lib/io/file.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69451=69450=69451=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Oct  5 
04:51:32 2015
@@ -196,7 +196,7 @@
 }
 
 /* Save the boot directory */
-BootDirectory = L"\\EFI\\Microsoft\\Boot";
+BootDirectory = L"\\EFI\\Boot"; /* Should be EFI\\ReactOS\\Boot */
 
 Quickie:
 /* Free all the allocations we made */
@@ -560,7 +560,6 @@
 
 /* Otherwise, compute the hardcoded path of the BCD */
 Status = BmpFwGetFullPath(L"\\BCD", );
-EfiPrintf(L"Status: %lx %s\r\n", Status, FullPath);
 if (!NT_SUCCESS(Status))
 {
 /* User the raw path */
@@ -686,7 +685,7 @@
 PBL_RETURN_ARGUMENTS ReturnArguments;
 BOOLEAN RebootOnError;
 PGUID AppIdentifier;
-HANDLE BcdHandle;
+   // HANDLE BcdHandle;
 
 EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\n");
 
@@ -734,8 +733,8 @@
 BmFwInitializeBootDirectoryPath();
 
 /* Load and initialize the boot configuration database (BCD) */
-Status = BmOpenDataStore();
-EfiPrintf(L"BCD Open: %lx\r\n", Status);
+//Status = BmOpenDataStore();
+//EfiPrintf(L"BCD Open: %lx\r\n", Status);
 
 /* do more stuff!! */
 EfiPrintf(L"We are A-OK!\r\n");

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69451=69450=69451=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Oct  5 
04:51:32 2015
@@ -93,6 +93,9 @@
 #define BL_FILE_WRITE_ACCESS0x02
 #define BL_DIRECTORY_ACCESS 0x04
 #define BL_UNKNOWN_ACCESS   0x10
+
+#define BL_DEVICE_READ_ACCESS   0x01
+#define BL_DEVICE_WRITE_ACCESS  0x02
 
 #define BL_DEVICE_ENTRY_OPENED  0x01
 #define BL_DEVICE_ENTRY_READ_ACCESS 0x02
@@ -226,6 +229,7 @@
 BlLoaderReferencePage = 0xD007,
 BlLoaderRamDisk = 0xD008,
 BlLoaderData = 0xD00A,
+BlLoaderRegistry = 0xD00B,
 BlLoaderBlockMemory = 0xD00C,
 BlLoaderSelfMap = 0xD00F,
 
@@ -1639,6 +1643,21 @@
 _Out_ PULONG BytesRead
 );
 
+/* IMAGE ROUTINES /
+
+NTSTATUS
+BlImgLoadImageWithProgress2 (
+_In_ ULONG DeviceId,
+_In_ BL_MEMORY_TYPE MemoryType,
+_In_ PWCHAR FileName,
+_Inout_ PVOID* MappedBase,
+_Inout_ PULONG MappedSize,
+_In_ ULONG ImageFlags,
+_In_ BOOLEAN ShowProgress,
+_Out_opt_ PUCHAR* HashBuffer,
+_Out_opt_ PULONG HashSize
+);
+
 /* FILE I/O ROUTINES */
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=69451=69450=69451=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Mon Oct  5 
04:51:32 2015
@@ -1914,8 +1914,8 @@
 goto Quickie;
 }
 
-/* Check for unsupported flags */
-if (!(Flags & 3))
+/* Make sure both read and write access are set */
+if (!(Flags & (BL_DEVICE_READ_ACCESS | BL_DEVICE_WRITE_ACCESS)))
 {
 /* Bail out */
 Status = STATUS_INVALID_PARAMETER;
@@ -1982,7 +1982,9 @@
 /* Fill it out */
 RtlZeroMemory(DeviceEntry, sizeof(*DeviceEntry));
 DeviceEntry->ReferenceCount = 1;
-DeviceEntry->Flags |= 7;
+DeviceEntry->Flags |= (BL_DEVICE_ENTRY_OPENED |
+   BL_DEVICE_ENTRY_READ_ACCESS |
+   BL_DEVICE_ENTRY_WRITE_ACCESS);
 DeviceEntry->Unknown = Unknown;
 
 /* Save flag 8 if needed */

Modified: trunk/reactos/boot/environ/lib/io/etfs.

[ros-diffs] [ion] 69452: [BOOTLIB]: - Fix multiple bugs in ETFS code (confusion between file offset vs. disk offset) - Implement EtfsGetInformation, EtfsSetInformation, and fix ETFS_FILE definition to

2015-10-04 Thread ion
Author: ion
Date: Mon Oct  5 05:53:40 2015
New Revision: 69452

URL: http://svn.reactos.org/svn/reactos?rev=69452=rev
Log:
[BOOTLIB]:
- Fix multiple bugs in ETFS code (confusion between file offset vs. disk offset)
- Implement EtfsGetInformation, EtfsSetInformation, and fix ETFS_FILE 
definition to make this easy.
- Implement EtfsRead.
- Fix multiple bugs in file I/O code (swapped/reversed validation checks)
- Make BlStatusPrint call EfiPrintf on debug builds, even without BD.
- Add some additional error logging.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/etfs.c
trunk/reactos/boot/environ/lib/io/file.c
trunk/reactos/boot/environ/lib/misc/debug.c
trunk/reactos/boot/environ/lib/misc/image.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.h?rev=69452=69451=69452=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.h[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.h[iso-8859-1] Mon Oct  5 
05:53:40 2015
@@ -49,7 +49,7 @@
 ULONG Size;
 } BL_PACKED_BOOT_ERROR, *PBL_PACKED_BOOT_ERROR;
 
-#define BL_FATAL_ERROR_BCD_READ 0x02
+#define BL_FATAL_ERROR_BCD_READ 0x01
 
 /* FUNCTIONS */
 

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69452=69451=69452=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Oct  5 
05:53:40 2015
@@ -321,7 +321,7 @@
 _In_ struct _BL_FILE_ENTRY* FileEntry,
 _In_ PVOID Buffer,
 _In_ ULONG Size,
-_Out_ PULONG BytesRead
+_Out_opt_ PULONG BytesRead
 );
 
 typedef
@@ -786,8 +786,10 @@
 
 typedef struct _BL_FILE_INFORMATION
 {
-ULONGLONG FileSize;
-ULONGLONG CurrentOffset;
+ULONGLONG Size;
+ULONGLONG Offset;
+PWCHAR FsName;
+ULONG Flags;
 } BL_FILE_INFORMATION, *PBL_FILE_INFORMATION;
 
 typedef struct _BL_FILE_CALLBACKS
@@ -809,7 +811,7 @@
 ULONG Flags;
 ULONG ReferenceCount;
 ULONG Unknown;
-ULONGLONG Unknown1;
+ULONGLONG TotalBytesRead;
 ULONGLONG Unknown2;
 BL_FILE_CALLBACKS Callbacks;
 PVOID FsSpecificData;

Modified: trunk/reactos/boot/environ/lib/io/etfs.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/etfs.c?rev=69452=69451=69452=diff
==
--- trunk/reactos/boot/environ/lib/io/etfs.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/etfs.c[iso-8859-1] Mon Oct  5 
05:53:40 2015
@@ -36,12 +36,12 @@
 
 typedef struct _BL_ETFS_FILE
 {
+ULONG DiskOffset;
 ULONG DirOffset;
 ULONG DirEntOffset;
-ULONGLONG Size;
-ULONGLONG Offset;
-PWCHAR FsName;
-ULONG Flags;
+
+BL_FILE_INFORMATION;
+
 ULONG DeviceId;
 } BL_ETFS_FILE, *PBL_ETFS_FILE;
 
@@ -56,9 +56,35 @@
 _Out_ PBL_FILE_ENTRY *FileEntry
 );
 
+NTSTATUS
+EtfsGetInformation (
+_In_ PBL_FILE_ENTRY FileEntry,
+_Out_ PBL_FILE_INFORMATION FileInfo
+);
+
+NTSTATUS
+EtfsSetInformation (
+_In_ PBL_FILE_ENTRY FileEntry,
+_In_ PBL_FILE_INFORMATION FileInfo
+);
+
+NTSTATUS
+EtfsRead (
+_In_ PBL_FILE_ENTRY FileEntry,
+_In_ PVOID Buffer,
+_In_ ULONG Size,
+_Out_opt_ PULONG BytesReturned
+);
+
 BL_FILE_CALLBACKS EtfsFunctionTable =
 {
 EtfsOpen,
+NULL,
+EtfsRead,
+NULL,
+NULL,
+EtfsGetInformation,
+EtfsSetInformation
 };
 
 /* FUNCTIONS */
@@ -205,7 +231,7 @@
 
 EtfsFile = DirectoryEntry->FsSpecificData;
 DeviceId = EtfsFile->DeviceId;
-FileOffset = EtfsFile->Offset;
+FileOffset = EtfsFile->DiskOffset;
 EtfsDevice = EtfsDeviceTable[DeviceId];
 
 DirectoryOffset = *DirentOffset;
@@ -362,7 +388,7 @@
 DirentOffset = EtfsFile->DirEntOffset;
 
 if ((KeepOffset) ||
-(ALIGN_DOWN_BY((DirentOffset + EtfsFile->Offset), CD_SECTOR_SIZE) ==
+(ALIGN_DOWN_BY((DirentOffset + EtfsFile->DiskOffset), CD_SECTOR_SIZE) 
==
  EtfsDevice->Offset))
 {
 Status = EtfspGetDirent(DirectoryEntry, , );
@@ -404,6 +430,108 @@
 }
 
 return Status;
+}
+
+NTSTATUS
+EtfsRead (
+_In_ PBL_FILE_ENTRY FileEntry,
+_In_ PVOID Buffer, 
+_In_ ULONG Size,
+_Out_opt_ PULONG BytesReturned
+)
+{
+ULONG BytesRead;
+PBL_ETFS_FILE EtfsFile;
+NTSTATUS Status;
+
+/* Assume failure for now */
+BytesRead = 0;
+
+/* Make sure that the read is with

[ros-diffs] [ion] 69340: [NDK]: Add OB_FLAG_KERNEL_EXCLUSIVE and OBJ_KERNEL_EXCLUSIVE flags [NTOSKRNL]: Add a helper function such that user-mode cannot pass certain kernel-only object attributes to O

2015-09-23 Thread ion
Author: ion
Date: Thu Sep 24 02:40:30 2015
New Revision: 69340

URL: http://svn.reactos.org/svn/reactos?rev=69340=rev
Log:
[NDK]: Add OB_FLAG_KERNEL_EXCLUSIVE and OBJ_KERNEL_EXCLUSIVE flags
[NTOSKRNL]: Add a helper function such that user-mode cannot pass certain 
kernel-only object attributes to ObOpenObjectByPointer.
[NTOSKRNL]: Make \Device\PhysicalMemory OBJ_KERNEL_EXCLUSIVE
[NTOSKRNL]: Deny access to user-mode when opening a handle to an object with 
OBJ_KERNEL_EXCLUSIVE
[NTOSKRNL]: Fix NtOpenProcess, NtOpenThread, NtOpenThreadTokenEx, 
NtOpenProcessTokenEx to use the helper function. Should fix Rtl using 
OBJ_KERNEL_HANDLE in user-mode.
Thanks to ThFabba for finding out these bugs, and the hbelusca for adding a 
missing check to NtOpenProcessTokenEx.

Modified:
trunk/reactos/include/ndk/obtypes.h
trunk/reactos/ntoskrnl/include/internal/ob_x.h
trunk/reactos/ntoskrnl/mm/section.c
trunk/reactos/ntoskrnl/ob/obhandle.c
trunk/reactos/ntoskrnl/ob/oblife.c
trunk/reactos/ntoskrnl/ob/obname.c
trunk/reactos/ntoskrnl/ps/process.c
trunk/reactos/ntoskrnl/ps/security.c
trunk/reactos/ntoskrnl/ps/thread.c
trunk/reactos/ntoskrnl/se/token.c

Modified: trunk/reactos/include/ndk/obtypes.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/obtypes.h?rev=69340=69339=69340=diff
==
--- trunk/reactos/include/ndk/obtypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/obtypes.h [iso-8859-1] Thu Sep 24 02:40:30 2015
@@ -86,6 +86,12 @@
 #else
 
 //
+// Undocumented Attribute for Kernel-Only Access
+//
+#define OBJ_KERNEL_EXCLUSIVE0x0001L
+#define OBJ_VALID_KERNEL_ATTRIBUTES (OBJ_VALID_ATTRIBUTES | \
+ OBJ_KERNEL_EXCLUSIVE)
+//
 // Object Flags
 //
 #define OB_FLAG_CREATE_INFO 0x01
@@ -96,6 +102,11 @@
 #define OB_FLAG_SECURITY0x20
 #define OB_FLAG_SINGLE_PROCESS  0x40
 #define OB_FLAG_DEFER_DELETE0x80
+
+//
+// Object Flags encoded in "QueryReferences" field
+//
+#define OB_FLAG_KERNEL_EXCLUSIVE0x4000
 
 #define OBJECT_TO_OBJECT_HEADER(o)  \
 CONTAINING_RECORD((o), OBJECT_HEADER, Body)

Modified: trunk/reactos/ntoskrnl/include/internal/ob_x.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/ob_x.h?rev=69340=69339=69340=diff
==
--- trunk/reactos/ntoskrnl/include/internal/ob_x.h  [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ob_x.h  [iso-8859-1] Thu Sep 24 
02:40:30 2015
@@ -16,6 +16,24 @@
 #define OBP_LOCK_STATE_INITIALIZED  0x1234
 
 #define OBP_NAME_LOOKASIDE_MAX_SIZE 248
+
+FORCEINLINE
+ULONG
+ObpValidateAttributes(IN ULONG Attributes,
+  IN KPROCESSOR_MODE PreviousMode)
+{
+if (PreviousMode == KernelMode)
+{
+/* For kernel, allow any valid attributes */
+return Attributes & OBJ_VALID_KERNEL_ATTRIBUTES;
+}
+else
+{
+/* For user, mask out kernel-only attributes */
+return (Attributes & OBJ_VALID_ATTRIBUTES) &
+   ~(OBJ_KERNEL_HANDLE);
+}
+}
 
 FORCEINLINE
 ULONG

Modified: trunk/reactos/ntoskrnl/mm/section.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/mm/section.c?rev=69340=69339=69340=diff
==
--- trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/mm/section.c [iso-8859-1] Thu Sep 24 02:40:30 2015
@@ -2756,7 +2756,7 @@
 SectionSize.QuadPart = 0x;
 InitializeObjectAttributes(,
,
-   OBJ_PERMANENT,
+   OBJ_PERMANENT | OBJ_KERNEL_EXCLUSIVE,
NULL,
NULL);
 Status = MmCreateSection((PVOID),

Modified: trunk/reactos/ntoskrnl/ob/obhandle.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ob/obhandle.c?rev=69340=69339=69340=diff
==
--- trunk/reactos/ntoskrnl/ob/obhandle.c[iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ob/obhandle.c[iso-8859-1] Thu Sep 24 
02:40:30 2015
@@ -807,6 +807,7 @@
 KIRQL CalloutIrql;
 KPROCESSOR_MODE ProbeMode;
 ULONG Total;
+POBJECT_HEADER_NAME_INFO NameInfo;
 PAGED_CODE();
 
 /* Get the object header and type */
@@ -868,6 +869,16 @@
  (OBJECT_HEADER_TO_EXCLUSIVE_PROCESS(ObjectHeader)))
 {
 /* Caller didn't want exclusive access, but the object is exclusive */
+Status = STATUS_ACCESS_DENIED;
+goto Quickie;
+}
+
+/* Check for e

[ros-diffs] [ion] 69324: [NTOSKRNL]: Properly respect the registry's Win32PrioritySeparation value instead of ignoring it. [NTOSKRNL]: Actually apply the foreground priority boost to threads in a fore

2015-09-22 Thread ion
Author: ion
Date: Wed Sep 23 05:10:58 2015
New Revision: 69324

URL: http://svn.reactos.org/svn/reactos?rev=69324=rev
Log:
[NTOSKRNL]: Properly respect the registry's Win32PrioritySeparation value 
instead of ignoring it.
[NTOSKRNL]: Actually apply the foreground priority boost to threads in a 
foreground process.
[NTOSKRNL]: Correctly handle the case where the quantum length and 
fixed/variable flag are set to "default", instead of falling back into the 
server case.
Thanks to WINSRV doing the right thing, ReactOS console apps now receive the 
priority separation boost. However, my tests show that it doesn't last as long 
as it should on Windows (quantums too short? bug in priority decrement?). Also, 
since Win32k.sys doesn't tell the kernel about foreground GUI apps, they don't 
get the boost. Someone needs to add a NtSetInformationProcess call in whatever 
win32k function determines active focus.
Dedicated to ThFabba who needs to write some tests ;-)

Modified:
trunk/reactos/include/ndk/pstypes.h
trunk/reactos/ntoskrnl/config/cmdata.c
trunk/reactos/ntoskrnl/include/internal/ps.h
trunk/reactos/ntoskrnl/io/iomgr/driver.c
trunk/reactos/ntoskrnl/ke/thrdschd.c
trunk/reactos/ntoskrnl/ps/process.c

Modified: trunk/reactos/include/ndk/pstypes.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/pstypes.h?rev=69324=69323=69324=diff
==
--- trunk/reactos/include/ndk/pstypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/pstypes.h [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -129,8 +129,11 @@
 //
 // Process Priority Separation Values (OR)
 //
-#define PSP_VARIABLE_QUANTUMS   4
-#define PSP_LONG_QUANTUMS   16
+#define PSP_DEFAULT_QUANTUMS0x00
+#define PSP_VARIABLE_QUANTUMS   0x04
+#define PSP_FIXED_QUANTUMS  0x08
+#define PSP_LONG_QUANTUMS   0x10
+#define PSP_SHORT_QUANTUMS  0x20
 
 #ifndef NTOS_MODE_USER
 //

Modified: trunk/reactos/ntoskrnl/config/cmdata.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmdata.c?rev=69324=69323=69324=diff
==
--- trunk/reactos/ntoskrnl/config/cmdata.c  [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmdata.c  [iso-8859-1] Wed Sep 23 
05:10:58 2015
@@ -765,7 +765,7 @@
 {
 L"PriorityControl",
 L"Win32PrioritySeparation",
-,
+,
 NULL,
 NULL
 },

Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/ps.h?rev=69324=69323=69324=diff
==
--- trunk/reactos/ntoskrnl/include/internal/ps.h[iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ps.h[iso-8859-1] Wed Sep 23 
05:10:58 2015
@@ -452,6 +452,7 @@
 extern BOOLEAN PspUseJobSchedulingClasses;
 extern CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES];
 extern ULONG PsRawPrioritySeparation;
+extern ULONG PsPrioritySeparation;
 extern POBJECT_TYPE _PsThreadType, _PsProcessType;
 extern PTOKEN PspBootAccessToken;
 extern GENERIC_MAPPING PspJobMapping;

Modified: trunk/reactos/ntoskrnl/io/iomgr/driver.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/driver.c?rev=69324=69323=69324=diff
==
--- trunk/reactos/ntoskrnl/io/iomgr/driver.c[iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/driver.c[iso-8859-1] Wed Sep 23 
05:10:58 2015
@@ -1495,7 +1495,7 @@
 /* Create a random name and set up the string*/
 NameLength = (USHORT)swprintf(NameBuffer,
   DRIVER_ROOT_NAME L"%08u",
-  KeTickCount);
+  KeTickCount.LowPart);
 LocalDriverName.Length = NameLength * sizeof(WCHAR);
 LocalDriverName.MaximumLength = LocalDriverName.Length + 
sizeof(UNICODE_NULL);
 LocalDriverName.Buffer = NameBuffer;

Modified: trunk/reactos/ntoskrnl/ke/thrdschd.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/thrdschd.c?rev=69324=69323=69324=diff
==
--- trunk/reactos/ntoskrnl/ke/thrdschd.c[iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/thrdschd.c[iso-8859-1] Wed Sep 23 
05:10:58 2015
@@ -171,6 +171,14 @@
 
 /* Calculate the new priority after the increment */
 OldPriority = Thread->BasePriority + Thread->AdjustIncrement;
+
+/* Check if this is a foreground process */
+if (CONTAINING_R

[ros-diffs] [ion] 69189: [BOOTMGFW] - Additional El Torito support. We now parse the EFI, BOOT directories, and find/open the BCD file, and get a handle to it!

2015-09-12 Thread ion
Author: ion
Date: Sat Sep 12 08:57:42 2015
New Revision: 69189

URL: http://svn.reactos.org/svn/reactos?rev=69189=rev
Log:
[BOOTMGFW]
- Additional El Torito support. We now parse the EFI, BOOT directories, and 
find/open the BCD file, and get a handle to it!

Modified:
trunk/reactos/boot/environ/lib/io/etfs.c

Modified: trunk/reactos/boot/environ/lib/io/etfs.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/etfs.c?rev=69189=69188=69189=diff
==
--- trunk/reactos/boot/environ/lib/io/etfs.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/etfs.c[iso-8859-1] Sat Sep 12 
08:57:42 2015
@@ -23,25 +23,26 @@
 
 /* DATA VARIABLES /
 
-typedef struct _BL_ETFS_CONTEXT
+typedef struct _BL_ETFS_DEVICE
 {
 ULONG RootDirOffset;
 ULONG RootDirSize;
 ULONG BlockSize;
 ULONG VolumeSize;
 BOOLEAN IsIso;
-PRAW_ISO_VD MemoryBlock;
+PUCHAR MemoryBlock;
 ULONG Offset;
-} BL_ETFS_CONTEXT, *PBL_ETFS_CONTEXT;
+} BL_ETFS_DEVICE, *PBL_ETFS_DEVICE;
 
 typedef struct _BL_ETFS_FILE
 {
+ULONG DirOffset;
+ULONG DirEntOffset;
+ULONGLONG Size;
+ULONGLONG Offset;
+PWCHAR FsName;
 ULONG Flags;
 ULONG DeviceId;
-ULONG Offset;
-ULONG Unknown;
-ULONGLONG Size;
-PWCHAR FsName;
 } BL_ETFS_FILE, *PBL_ETFS_FILE;
 
 ULONG EtfsDeviceTableEntries;
@@ -62,6 +63,349 @@
 
 /* FUNCTIONS */
 
+VOID
+EtfspGetDirectoryInfo (
+_In_ PBL_ETFS_DEVICE EtfsDevice,
+_In_ PRAW_DIR_REC DirEntry,
+_Out_ PULONG FileOffset,
+_Out_ PULONG FileSize,
+_Out_opt_ PBOOLEAN IsDirectory
+)
+{
+ULONG SectorOffset;
+BOOLEAN IsDir;
+
+*FileOffset = *(PULONG)DirEntry->FileLoc * EtfsDevice->BlockSize;
+*FileOffset += (DirEntry->XarLen * EtfsDevice->BlockSize);
+
+SectorOffset = ALIGN_DOWN_BY(*FileOffset, CD_SECTOR_SIZE);
+
+*FileSize = *(PULONG)DirEntry->DataLen;
+
+IsDir = DE_FILE_FLAGS(EtfsDevice->IsIso, DirEntry) & ISO_ATTR_DIRECTORY;
+if (IsDir)
+{
+*FileSize += ALIGN_UP_BY(SectorOffset, CD_SECTOR_SIZE) - SectorOffset;
+}
+
+if (IsDirectory)
+{
+*IsDirectory = IsDir;
+}
+}
+
+USHORT
+EtfspGetDirentNameLength (
+_In_ PRAW_DIR_REC DirEntry
+)
+{
+USHORT Length, RealLength;
+PUCHAR Pos;
+
+RealLength = Length = DirEntry->FileIdLen;
+for (Pos = >FileIdLen + Length; Length; --Pos)
+{
+--Length;
+
+if (*Pos == ';')
+{
+RealLength = Length;
+break;
+}
+}
+
+Length = RealLength;
+for (Pos = >FileIdLen + Length; Length; --Pos)
+{
+--Length;
+
+if (*Pos != '.')
+{
+break;
+}
+
+RealLength = Length;
+}
+
+return RealLength;
+}
+
+LONG
+EtfspCompareNames (
+__in PSTRING Name1,
+__in PUNICODE_STRING Name2
+)
+{
+ULONG i, l1, l2, l;
+
+l1 = Name1->Length;
+l2 = Name2->Length / sizeof(WCHAR);
+l = min(l1, l2);
+
+for (i = 0; i < l; i++)
+{
+if (toupper(Name1->Buffer[i]) != toupper(Name2->Buffer[i]))
+{
+return toupper(Name1->Buffer[i]) - toupper(Name2->Buffer[i]);
+}
+}
+
+if (l2 <= l1)
+{
+return l2 < l1;
+}
+else
+{
+return -1;
+}
+}
+
+BOOLEAN
+EtfspFileMatch (
+_In_ PRAW_DIR_REC DirEntry,
+_In_ PUNICODE_STRING FileName
+)
+{
+BOOLEAN Match;
+USHORT Length;
+ANSI_STRING DirName;
+
+if ((DirEntry->FileIdLen != 1) ||
+((DirEntry->FileId[0] != 0) && (DirEntry->FileId[0] != 1)))
+{
+Length = EtfspGetDirentNameLength(DirEntry);
+DirName.Length = Length;
+DirName.MaximumLength = Length;
+DirName.Buffer = (PCHAR)DirEntry->FileId;
+
+Match = EtfspCompareNames(, FileName);
+}
+else
+{
+Match = -1;
+}
+return Match;
+}
+
+NTSTATUS
+EtfspGetDirent (
+_In_ PBL_FILE_ENTRY DirectoryEntry,
+_Out_ PRAW_DIR_REC *DirEntry,
+_Inout_ PULONG DirentOffset
+)
+{
+PBL_ETFS_FILE EtfsFile;
+ULONG FileOffset, DirectoryOffset, AlignedOffset, RemainderOffset;
+ULONG DeviceId, ReadSize, DirLen;
+PBL_ETFS_DEVICE EtfsDevice;
+BOOLEAN NeedRead, IsMulti;
+NTSTATUS result;
+PRAW_DIR_REC DirEnt;
+PUCHAR MemoryBlock;
+
+EtfsFile = DirectoryEntry->FsSpecificData;
+DeviceId = EtfsFile->DeviceId;
+FileOffset = EtfsFile->Offset;
+EtfsDevice = EtfsDeviceTable[DeviceId];
+
+DirectoryOffset = *DirentOffset;
+MemoryBlock = EtfsDevice->MemoryBlock;
+
+IsMulti = 0;
+
+AlignedOffset = (FileOffset + *DirentOffset) & ~CD_SECTOR_SIZE;
+RemainderOffset = *DirentOffset + FileO

[ros-diffs] [ion] 69178: [BOOTMGFW] - Implement Block I/O read operations & related functions. Code needs cleanup, TBD. - Unfortunately, I wish I could say it works, but it seems like all we get back

2015-09-10 Thread ion
Author: ion
Date: Thu Sep 10 23:13:31 2015
New Revision: 69178

URL: http://svn.reactos.org/svn/reactos?rev=69178=rev
Log:
[BOOTMGFW]
- Implement Block I/O read operations & related functions. Code needs cleanup, 
TBD.
- Unfortunately, I wish I could say it works, but it seems like all we get back 
are zeroes (from EFI itself). I suspect we are reading from the wrong device -- 
will have to investigate for a bit.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/fat.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69178=69177=69178=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Sep 10 
23:13:31 2015
@@ -898,7 +898,7 @@
 BL_PARTITION_TYPE PartitionType;
 ULONG BlockSize;
 ULONG Alignment;
-ULONGLONG MaxBlock;
+ULONGLONG LastBlock;
 ULONGLONG Offset;
 ULONG Block;
 struct
@@ -929,7 +929,7 @@
 typedef struct _BL_BLOCK_DEVICE
 {
 BL_BLOCK_DEVICE_INFORMATION;
-ULONGLONG LastBlock;
+ULONGLONG StartOffset;
 EFI_BLOCK_IO* Protocol;
 EFI_HANDLE Handle;
 } BL_BLOCK_DEVICE, *PBL_BLOCK_DEVICE;

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=69178=69177=69178=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Thu Sep 10 
23:13:31 2015
@@ -73,18 +73,488 @@
 _Out_ PBL_DEVICE_INFORMATION DeviceInformation
 );
 
+NTSTATUS
+BlockIoRead (
+_In_ PBL_DEVICE_ENTRY DeviceEntry,
+_In_ PVOID Buffer,
+_In_ ULONG Size,
+_Out_ PULONG BytesRead
+);
+
 BL_DEVICE_CALLBACKS BlockIoDeviceFunctionTable =
 {
 NULL,
 BlockIoOpen,
 NULL,
-NULL,
+BlockIoRead,
 NULL,
 BlockIoGetInformation,
 BlockIoSetInformation
 };
 
 NTSTATUS
+BlockIoFirmwareWrite (
+_In_ PBL_BLOCK_DEVICE BlockDevice,
+_In_ PVOID Buffer,
+_In_ ULONGLONG Block,
+_In_ ULONGLONG BlockCount
+)
+{
+return STATUS_NOT_IMPLEMENTED;
+}
+
+NTSTATUS
+BlockIoFirmwareRead (
+_In_ PBL_BLOCK_DEVICE BlockDevice,
+_In_ PVOID Buffer,
+_In_ ULONGLONG Block,
+_In_ ULONGLONG BlockCount
+)
+{
+NTSTATUS Status;
+EFI_BLOCK_IO *BlockProtocol;
+BL_ARCH_MODE OldMode;
+EFI_STATUS EfiStatus;
+ULONG FailureCount;
+
+for (FailureCount = 0, Status = STATUS_SUCCESS;
+ FailureCount < 2 && NT_SUCCESS(Status);
+ FailureCount++)
+{
+BlockProtocol = BlockDevice->Protocol;
+
+OldMode = CurrentExecutionContext->Mode;
+if (CurrentExecutionContext->Mode != 1)
+{
+Status = STATUS_NOT_IMPLEMENTED;
+break;
+}
+
+EfiPrintf(L"EFI Reading BLOCK %d off media %lx (%d blocks)\r\n",
+ Block, BlockProtocol->Media->MediaId, BlockCount);
+EfiStatus = BlockProtocol->ReadBlocks(BlockProtocol,
+  BlockProtocol->Media->MediaId,
+  Block,
+  BlockProtocol->Media->BlockSize 
* BlockCount,
+  Buffer);
+if (EfiStatus == EFI_SUCCESS)
+{
+EfiPrintf(L"EFI Read complete into buffer\r\n");
+EfiPrintf(L"Buffer data: %lx %lx %lx %lx\r\n", *(PULONG)Buffer, 
*((PULONG)Buffer + 1), *((PULONG)Buffer + 2), *((PULONG)Buffer + 3));
+}
+
+if (OldMode != 1)
+{
+BlpArchSwitchContext(OldMode);
+}
+
+Status = EfiGetNtStatusCode(EfiStatus);
+if (Status != STATUS_MEDIA_CHANGED)
+{
+break;
+}
+
+EfiCloseProtocol(BlockDevice->Handle, );
+
+Status = EfiOpenProtocol(BlockDevice->Handle,
+ ,
+ (PVOID*)BlockDevice->Protocol);
+}
+
+return Status;
+}
+
+NTSTATUS
+BlockIopFirmwareOperation (
+PBL_DEVICE_ENTRY DeviceEntry,
+_In_ PVOID Buffer,
+_In_ ULONGLONG Block,
+_In_ ULONGLONG BlockCount,
+_In_ ULONG OperationType
+)
+{
+ULONG FailureCount;
+PBL_BLOCK_DEVICE BlockDevice;
+NTSTATUS Status;
+
+BlockDevice = DeviceEntry->DeviceSpecificData;
+
+if (OperationType == 1)
+{
+for (FailureCount = 0; FailureCount < 3; FailureCount++)
+{
+Status = BlockIoFirmwareWrite(BlockDevice, Buffer, Block, 
BlockCount);
+if (Stat

[ros-diffs] [ion] 69181: [BOOTMGFW] - Hey Arch, your buddies gave you ETFS support for native EFI boot, of course reading sector 0 is all zeroes, you're not on FAT, you idiot! ETFS has data at sector

2015-09-10 Thread ion
Author: ion
Date: Fri Sep 11 04:33:24 2015
New Revision: 69181

URL: http://svn.reactos.org/svn/reactos?rev=69181=rev
Log:
[BOOTMGFW]
- Hey Arch, your buddies gave you ETFS support for native EFI boot, of course 
reading sector 0 is all zeroes, you're not on FAT, you idiot! ETFS has data at 
sector 16 and 17.
- Implement beginning of ETFS support. We correctly mount the reactOS boot cd 
as ETFS and open the root directory entry!

Added:
trunk/reactos/boot/environ/lib/io/etfs.c   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/fat.c
trunk/reactos/boot/environ/lib/io/file.c

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=69181=69180=69181=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Fri Sep 11 
04:33:24 2015
@@ -20,6 +20,7 @@
  lib/mm/descriptor.c
  lib/platform/time.c
  lib/io/blkcache.c
+ lib/io/etfs.c
  lib/io/io.c
  lib/io/device.c
  lib/io/file.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69181=69180=69181=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Fri Sep 11 
04:33:24 2015
@@ -269,9 +269,9 @@
 typedef
 NTSTATUS
 (*PBL_FILE_OPEN) (
-_In_ struct _BL_FILE_ENTRY* ParentFileEntry,
+_In_ struct _BL_FILE_ENTRY* Directory,
 _In_ PWCHAR FileName,
-_In_ ULONG OpenFlags,
+_In_ ULONG Flags,
 _Out_ struct _BL_FILE_ENTRY** FileEntry
 );
 
@@ -758,16 +758,17 @@
 
 typedef struct _BL_FILE_ENTRY
 {
+PWCHAR FilePath;
+ULONG DeviceId;
+ULONG FileId;
+ULONG Flags;
 ULONG ReferenceCount;
-ULONG FileId;
-ULONG DeviceId;
-ULONG Flags;
-PWCHAR FilePath;
 ULONG Unknown;
-ULONG Unknown1;
-ULONG Unknown2;
+ULONGLONG Unknown1;
+ULONGLONG Unknown2;
 BL_FILE_CALLBACKS Callbacks;
-PBL_FILE_DESTROY_CALLBACK DestroyCallback;
+//PBL_FILE_DESTROY_CALLBACK DestroyCallback;
+PVOID FsSpecificData;
 } BL_FILE_ENTRY, *PBL_FILE_ENTRY;
 
 typedef struct _BL_FILE_SYSTEM_ENTRY
@@ -1225,6 +1226,18 @@
 _Out_ PBL_FILE_ENTRY* FileEntry
 );
 
+NTSTATUS
+EtfsInitialize (
+VOID
+);
+
+NTSTATUS
+EtfsMount (
+_In_ ULONG DeviceId,
+_In_ ULONG Unknown,
+_Out_ PBL_FILE_ENTRY* FileEntry
+);
+
 /* UTILITY ROUTINES **/
 
 EFI_STATUS

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=69181=69180=69181=diff
==
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Fri Sep 11 
04:33:24 2015
@@ -130,8 +130,8 @@
 break;
 }
 
-EfiPrintf(L"EFI Reading BLOCK %d off media %lx (%d blocks)\r\n",
- Block, BlockProtocol->Media->MediaId, BlockCount);
+//EfiPrintf(L"EFI Reading BLOCK %d off media %lx (%d blocks)\r\n",
+ //Block, BlockProtocol->Media->MediaId, BlockCount);
 EfiStatus = BlockProtocol->ReadBlocks(BlockProtocol,
   BlockProtocol->Media->MediaId,
   Block,
@@ -139,8 +139,8 @@
   Buffer);
 if (EfiStatus == EFI_SUCCESS)
 {
-EfiPrintf(L"EFI Read complete into buffer\r\n");
-EfiPrintf(L"Buffer data: %lx %lx %lx %lx\r\n", *(PULONG)Buffer, 
*((PULONG)Buffer + 1), *((PULONG)Buffer + 2), *((PULONG)Buffer + 3));
+//EfiPrintf(L"EFI Read complete into buffer\r\n");
+//EfiPrintf(L"Buffer data: %lx %lx %lx %lx\r\n", *(PULONG)Buffer, 
*((PULONG)Buffer + 1), *((PULONG)Buffer + 2), *((PULONG)Buffer + 3));
 }
 
 if (OldMode != 1)

Added: trunk/reactos/boot/environ/lib/io/etfs.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/etfs.c?rev=69181
==
--- trunk/reactos/boot/environ/lib/io/etfs.c(added)
+++ trunk/reactos/boot/environ/lib/io/etfs.c[iso-8859-1] Fri Sep 11 
04:33:24 2015
@@ -0,0 +1,433 @@
+/*
+ * COPYRIGHT:   See COPYING.ARM in the top level directory
+ * PROJECT: 

[ros-diffs] [ion] 69180: [CDFS_NEW] - Resurrect back 7 years later (revert commit 34622). - Add correct MS-PL (Public) License. Not added to build/used, but I need some of the headers/data structures

2015-09-10 Thread ion
Author: ion
Date: Fri Sep 11 04:02:21 2015
New Revision: 69180

URL: http://svn.reactos.org/svn/reactos?rev=69180=rev
Log:
[CDFS_NEW]
- Resurrect back 7 years later (revert commit 34622).
- Add correct MS-PL (Public) License. Not added to build/used, but I need some 
of the headers/data structures in here.
- Source: 
https://github.com/Microsoft/Windows-driver-samples/blob/master/filesys/cdfs

Added:
trunk/reactos/drivers/filesystems/cdfs_new/
  - copied from r34621, trunk/reactos/drivers/filesystems/cdfs_new/
trunk/reactos/drivers/filesystems/cdfs_new/LICENSE   (with props)
Removed:
trunk/reactos/drivers/filesystems/cdfs_new/cdfs.rbuild

Added: trunk/reactos/drivers/filesystems/cdfs_new/LICENSE
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs_new/LICENSE?rev=69180
==
--- trunk/reactos/drivers/filesystems/cdfs_new/LICENSE  (added)
+++ trunk/reactos/drivers/filesystems/cdfs_new/LICENSE  [iso-8859-1] Fri Sep 11 
04:02:21 2015
@@ -0,0 +1,23 @@
+The Microsoft Public License (MS-PL)
+Copyright (c) 2015 Microsoft
+
+This license governs use of the accompanying software. If you use the 
software, you
+ accept this license. If you do not accept the license, do not use the 
software.
+
+1. Definitions
+ The terms "reproduce," "reproduction," "derivative works," and "distribution" 
have the
+ same meaning here as under U.S. copyright law.
+ A "contribution" is the original software, or any additions or changes to the 
software.
+ A "contributor" is any person that distributes its contribution under this 
license.
+ "Licensed patents" are a contributor's patent claims that read directly on 
its contribution.
+
+2. Grant of Rights
+ (A) Copyright Grant- Subject to the terms of this license, including the 
license conditions and limitations in section 3, each contributor grants you a 
non-exclusive, worldwide, royalty-free copyright license to reproduce its 
contribution, prepare derivative works of its contribution, and distribute its 
contribution or any derivative works that you create.
+ (B) Patent Grant- Subject to the terms of this license, including the license 
conditions and limitations in section 3, each contributor grants you a 
non-exclusive, worldwide, royalty-free license under its licensed patents to 
make, have made, use, sell, offer for sale, import, and/or otherwise dispose of 
its contribution in the software or derivative works of the contribution in the 
software.
+
+3. Conditions and Limitations
+ (A) No Trademark License- This license does not grant you rights to use any 
contributors' name, logo, or trademarks.
+ (B) If you bring a patent claim against any contributor over patents that you 
claim are infringed by the software, your patent license from such contributor 
to the software ends automatically.
+ (C) If you distribute any portion of the software, you must retain all 
copyright, patent, trademark, and attribution notices that are present in the 
software.
+ (D) If you distribute any portion of the software in source code form, you 
may do so only under this license by including a complete copy of this license 
with your distribution. If you distribute any portion of the software in 
compiled or object code form, you may only do so under a license that complies 
with this license.
+ (E) The software is licensed "as-is." You bear the risk of using it. The 
contributors give no express warranties, guarantees or conditions. You may have 
additional consumer rights under your local laws which this license cannot 
change. To the extent permitted under your local laws, the contributors exclude 
the implied warranties of merchantability, fitness for a particular purpose and 
non-infringement.

Propchange: trunk/reactos/drivers/filesystems/cdfs_new/LICENSE
--
svn:eol-style = native

Removed: trunk/reactos/drivers/filesystems/cdfs_new/cdfs.rbuild
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/cdfs_new/cdfs.rbuild?rev=34621
==
--- trunk/reactos/drivers/filesystems/cdfs_new/cdfs.rbuild  [iso-8859-1] 
(original)
+++ trunk/reactos/drivers/filesystems/cdfs_new/cdfs.rbuild  (removed)
@@ -1,36 +0,0 @@
-
-
-
-   
-   .
-   ntoskrnl
-   hal
-allocsup.c
-cachesup.c
-cddata.c
-cdinit.c
-cleanup.c
-close.c
-create.c
-devctrl.c
-deviosup.c
-dirctrl.c
-dirsup.c
-fileinfo.c
-filobsup.c
-fsctrl.c
-fspdisp.c
-lockctrl.c
-namesup.c
-pathsup.c
-pnp.c
-prefxsup.c
-read.c
-resrcsup.c
-strucsup.c
-verfysup.c
-volinfo.c
-workque.c
-   cdfs.rc
-   cdprocs.h
-




[ros-diffs] [ion] 69149: [BOOTMGFW] - Fix a bunch of bugs

2015-09-09 Thread ion
Author: ion
Date: Wed Sep  9 14:59:29 2015
New Revision: 69149

URL: http://svn.reactos.org/svn/reactos?rev=69149=rev
Log:
[BOOTMGFW]
- Fix a bunch of bugs

Modified:
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/lib/misc/util.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/misc/util.c?rev=69149=69148=69149=diff
==
--- trunk/reactos/boot/environ/lib/misc/util.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/misc/util.c  [iso-8859-1] Wed Sep  9 
14:59:29 2015
@@ -201,17 +201,17 @@
 )
 {
 PVOID Entry = NULL;
-ULONG Index = 0;
+ULONG Index;
 BOOLEAN Result;
 
 /* Check for invalid parameters */
-if (!(Table) || !(EntryIndex) || !(Count))
+if (!(Table) || !(EntryIndex))
 {
 return Entry;
 }
 
 /* Loop each entry in the table */
-while (Index < Count)
+for (Index = 0; Index < Count;  Index++)
 {
 /* Check if this entry is filled out */
 if (Table[Index])

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=69149=69148=69149=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Wed Sep  9 
14:59:29 2015
@@ -751,7 +751,7 @@
 /* Bail out if the type doesn't match */
 if (Descriptor->Type != MemoryType)
 {
-//EarlyPrint(L"Incorrect descriptor type\r\n");
+//EfiPrintf(L"Incorrect descriptor type: %lx %lx\r\n", 
Descriptor->Type, MemoryType);
 return FALSE;
 }
 
@@ -761,7 +761,7 @@
 NewDescriptor->Type = Descriptor->Type;
 NewDescriptor->VirtualPage = VirtualPage;
 NewDescriptor->Flags = Descriptor->Flags;
-//EarlyPrint(L"Found a matching descriptor: %08I64X with %08I64X 
pages\r\n", BasePage, Pages);
+//EfiPrintf(L"Found a matching descriptor: %08I64X with %08I64X 
pages\r\n", BasePage, Pages);
 return TRUE;
 }
 
@@ -795,8 +795,8 @@
 }
 
 /* Save the links */
-OldFlink = OldDescriptor->ListEntry.Blink;
-OldBlink = OldDescriptor->ListEntry.Flink;
+OldBlink = OldDescriptor->ListEntry.Blink;
+OldFlink = OldDescriptor->ListEntry.Flink;
 
 /* Make the copy */
 *Descriptor = *OldDescriptor;

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=69149=69148=69149=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Wed Sep  9 
14:59:29 2015
@@ -84,13 +84,13 @@
 ListHead = CurrentList->First;
 if (Request->Type & BL_MM_REQUEST_TOP_DOWN_TYPE)
 {
+NextEntry = ListHead->Blink;
+TopDown = TRUE;
+}
+else
+{
 NextEntry = ListHead->Flink;
 TopDown = FALSE;
-}
-else
-{
-NextEntry = ListHead->Blink;
-TopDown = TRUE;
 }
 
 /* Loop through the list */




[ros-diffs] [ion] 69156: [EFI] - Add BCD creation. - Add BCD to bootcd, and also to EFISYS.BIN. Verified the BCD is now present on the EFI partition.

2015-09-09 Thread ion
Author: ion
Date: Wed Sep  9 18:43:09 2015
New Revision: 69156

URL: http://svn.reactos.org/svn/reactos?rev=69156=rev
Log:
[EFI]
- Add BCD creation.
- Add BCD to bootcd, and also to EFISYS.BIN. Verified the BCD is now present on 
the EFI partition.

Added:
trunk/reactos/boot/bootdata/hivebcd.inf   (with props)
Modified:
trunk/reactos/boot/CMakeLists.txt
trunk/reactos/boot/bootdata/CMakeLists.txt
trunk/reactos/cmake/CMakeMacros.cmake
trunk/reactos/tools/mkhive/mkhive.c

Modified: trunk/reactos/boot/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/CMakeLists.txt?rev=69156=69155=69156=diff
==
--- trunk/reactos/boot/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/CMakeLists.txt   [iso-8859-1] Wed Sep  9 18:43:09 2015
@@ -16,7 +16,7 @@
 endif()
 
 add_custom_target(efisys
-COMMAND native-fatten ${CMAKE_CURRENT_BINARY_DIR}/efisys.bin -format 2880 
EFIBOOT -boot ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/fat.bin -mkdir EFI 
-mkdir EFI/BOOT -add $ EFI/BOOT/boot${EFI_PLATFORM_ID}.efi
+COMMAND native-fatten ${CMAKE_CURRENT_BINARY_DIR}/efisys.bin -format 2880 
EFIBOOT -boot ${CMAKE_CURRENT_BINARY_DIR}/freeldr/bootsect/fat.bin -mkdir EFI 
-mkdir EFI/BOOT -add $ 
EFI/BOOT/boot${EFI_PLATFORM_ID}.efi -add ${CMAKE_BINARY_DIR}/boot/bootdata/BCD 
EFI/BOOT/BCD
 DEPENDS native-fatten bootmgfw fat
 VERBATIM)
 

Modified: trunk/reactos/boot/bootdata/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/CMakeLists.txt?rev=69156=69155=69156=diff
==
--- trunk/reactos/boot/bootdata/CMakeLists.txt  [iso-8859-1] (original)
+++ trunk/reactos/boot/bootdata/CMakeLists.txt  [iso-8859-1] Wed Sep  9 
18:43:09 2015
@@ -10,7 +10,8 @@
 hivecls.inf
 hivedef.inf
 hivesft.inf
-hivesys.inf)
+hivesys.inf
+hivebcd.inf)
 
 
 #regtest

Added: trunk/reactos/boot/bootdata/hivebcd.inf
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/bootdata/hivebcd.inf?rev=69156
==
--- trunk/reactos/boot/bootdata/hivebcd.inf (added)
+++ trunk/reactos/boot/bootdata/hivebcd.inf [iso-8859-1] Wed Sep  9 
18:43:09 2015
@@ -0,0 +1,11 @@
+[Version]
+Signature = "$ReactOS$"
+
+[AddReg]
+
+HKLM,"BCD\Description\Control","System",0x00010003,1
+HKLM,"BCD\Description\Control","TreatAtSystem",0x00010003,1
+HKLM,"BCD\Description\Control","KeyName",2,"BCD"
+HKLM,"BCD\Description\Objects",,0x0012
+
+; EOF

Propchange: trunk/reactos/boot/bootdata/hivebcd.inf
--
svn:eol-style = native

Modified: trunk/reactos/cmake/CMakeMacros.cmake
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/cmake/CMakeMacros.cmake?rev=69156=69155=69156=diff
==
--- trunk/reactos/cmake/CMakeMacros.cmake   [iso-8859-1] (original)
+++ trunk/reactos/cmake/CMakeMacros.cmake   [iso-8859-1] Wed Sep  9 
18:43:09 2015
@@ -793,6 +793,22 @@
 DESTINATION reactos/system32/config
 FOR livecd)
 
+# BCD Hive
+add_custom_command(
+OUTPUT ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
+COMMAND native-mkhive ${CMAKE_BINARY_DIR}/boot/bootdata/ 
${CMAKE_BINARY_DIR}/boot/bootdata/hivebcd_utf16.inf
+DEPENDS native-mkhive ${CMAKE_SOURCE_DIR}/boot/bootdata/hivebcd.inf)
+
+add_custom_target(bcd_hive
+DEPENDS ${CMAKE_BINARY_DIR}/boot/bootdata/BCD)
+
+add_cd_file(
+FILE ${CMAKE_BINARY_DIR}/boot/bootdata/BCD
+TARGET bcd_hive
+DESTINATION efi/boot
+NO_CAB
+FOR bootcd regtest livecd)
+
 endfunction()
 
 if(KDBG)

Modified: trunk/reactos/tools/mkhive/mkhive.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.c?rev=69156=69155=69156=diff
==
--- trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] Wed Sep  9 18:43:09 2015
@@ -143,6 +143,14 @@
 return 1;
 }
 
+convert_path (FileName, argv[1]);
+strcat (FileName, DIR_SEPARATOR_STRING);
+strcat (FileName, "bcd");
+if (!ExportBinaryHive (FileName, ))
+{
+return 1;
+}
+
 RegShutdownRegistry ();
 
 printf ("  Done.\n");




[ros-diffs] [ion] 69157: [EFI] - Case sensitivity?

2015-09-09 Thread ion
Author: ion
Date: Wed Sep  9 18:45:51 2015
New Revision: 69157

URL: http://svn.reactos.org/svn/reactos?rev=69157=rev
Log:
[EFI]
- Case sensitivity?

Modified:
trunk/reactos/tools/mkhive/mkhive.c

Modified: trunk/reactos/tools/mkhive/mkhive.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/mkhive/mkhive.c?rev=69157=69156=69157=diff
==
--- trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] (original)
+++ trunk/reactos/tools/mkhive/mkhive.c [iso-8859-1] Wed Sep  9 18:45:51 2015
@@ -145,7 +145,7 @@
 
 convert_path (FileName, argv[1]);
 strcat (FileName, DIR_SEPARATOR_STRING);
-strcat (FileName, "bcd");
+strcat (FileName, "BCD");
 if (!ExportBinaryHive (FileName, ))
 {
 return 1;




[ros-diffs] [ion] 69155: - Implement BmpFwGetApplicationDirectoryPath and most of BmFwInitializeBootDirectoryPath. - Implement boolean, integer, and string BCD reading. - Fix a more bugs. - We are now

2015-09-09 Thread ion
Author: ion
Date: Wed Sep  9 18:09:04 2015
New Revision: 69155

URL: http://svn.reactos.org/svn/reactos?rev=69155=rev
Log:
- Implement BmpFwGetApplicationDirectoryPath and most of 
BmFwInitializeBootDirectoryPath.
- Implement boolean, integer, and string BCD reading.
- Fix a more bugs.
- We are now ready to open the BCD hive!

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/bootmgr.h
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/misc/bcd.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69155=69154=69155=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Wed Sep  9 
18:09:04 2015
@@ -12,7 +12,6 @@
 
 /* DATA VARIABLES /
 
-#include 
 DEFINE_GUID(GUID_WINDOWS_BOOTMGR,
 0x9DEA862C,
 0x5CDD,
@@ -26,6 +25,103 @@
 
 /* FUNCTIONS */
 
+NTSTATUS
+BmpFwGetApplicationDirectoryPath (
+_In_ PUNICODE_STRING ApplicationDirectoryPath
+)
+{
+NTSTATUS Status;
+ULONG i, AppPathLength;
+PWCHAR ApplicationPath, PathCopy;
+
+/* Clear the incoming string */
+ApplicationDirectoryPath->Length = 0;
+ApplicationDirectoryPath->MaximumLength = 0;
+ApplicationDirectoryPath->Buffer = 0;
+
+/* Get the boot application path */
+ApplicationPath = NULL;
+Status = BlGetBootOptionString(BlpApplicationEntry.BcdData,
+   BcdLibraryString_ApplicationPath,
+   );
+if (NT_SUCCESS(Status))
+{
+/* Calculate the length of the application path */
+for (i = wcslen(ApplicationPath) - 1; i > 0; i--)
+{
+/* Keep going until the path separator */
+if (ApplicationPath[i] == OBJ_NAME_PATH_SEPARATOR)
+{
+break;
+}
+}
+
+/* Check if we have space for one more character */
+AppPathLength = i + 1;
+if (AppPathLength < i)
+{
+/* Nope, we'll overflow */
+AppPathLength = -1;
+Status = STATUS_INTEGER_OVERFLOW;
+}
+else
+{
+/* Go ahead */
+Status = STATUS_SUCCESS;
+}
+
+/* No overflow? */
+if (NT_SUCCESS(Status))
+{
+/* Check if it's safe to multiply by two */
+if ((AppPathLength * sizeof(WCHAR)) > 0x)
+{
+/* Nope */
+AppPathLength = -1;
+Status = STATUS_INTEGER_OVERFLOW;
+}
+else
+{
+/* We're good, do the multiplication */
+Status = STATUS_SUCCESS;
+AppPathLength *= sizeof(WCHAR);
+}
+
+/* Allocate a copy for the string */
+if (NT_SUCCESS(Status))
+{
+PathCopy = BlMmAllocateHeap(AppPathLength);
+if (PathCopy)
+{
+/* NULL-terminate it */
+RtlCopyMemory(PathCopy,
+  ApplicationPath,
+  AppPathLength - sizeof(UNICODE_NULL));
+PathCopy[AppPathLength] = UNICODE_NULL;
+
+/* Finally, initialize the outoing string */
+RtlInitUnicodeString(ApplicationDirectoryPath, PathCopy);
+}
+else
+{
+/* No memory, fail */
+Status = STATUS_NO_MEMORY;
+}
+}
+}
+}
+
+/* Check if we had an application path */
+if (ApplicationPath)
+{
+/* No longer need this, free it */
+BlMmFreeHeap(ApplicationPath);
+}
+
+/* All done! */
+return Status;
+
+}
 NTSTATUS
 BmFwInitializeBootDirectoryPath (
 VOID
@@ -34,13 +130,13 @@
 PWCHAR FinalPath;
 NTSTATUS Status;
 PWCHAR BcdDirectory;
-   // UNICODE_STRING BcdPath;
-//ULONG FinalSize;
+UNICODE_STRING BcdPath;
+ULONG FinalSize;
 ULONG FileHandle, DeviceHandle;
 
 /* Initialize everything for failure */
-   // BcdPath.MaximumLength = 0;
-   // BcdPath.Buffer = NULL;
+BcdPath.MaximumLength = 0;
+BcdPath.Buffer = NULL;
 BcdDirectory = NULL;
 FinalPath = NULL;
 FileHandle = -1;
@@ -51,39 +147,40 @@
 if (!NT_SUCCESS(Status))
 {
 EfiPrintf(L"Device open failed: %lx\r\n", Status);
-EfiStall(200);
-goto Quickie;
-}
-

[ros-diffs] [ion] 69142: [BOOTMGFW] - 1.5KLOC code dump of current device block I/O handling. Totally untested and broken, just a checkpoint for now. - Implement most of Hash Table Utility Functions.

2015-09-08 Thread ion
Author: ion
Date: Wed Sep  9 05:48:50 2015
New Revision: 69142

URL: http://svn.reactos.org/svn/reactos?rev=69142=rev
Log:
[BOOTMGFW]
- 1.5KLOC code dump of current device block I/O handling. Totally untested and 
broken, just a checkpoint for now.
- Implement most of Hash Table Utility Functions.
- Implement parts of Block Allocator.
- Finish Implementation of Generic Table Utility Functions.
- Fix some EFI device emulation code.
- Temporarily disable freeing from heap while I figure out what's corrupting it.

Added:
trunk/reactos/boot/environ/include/efi/BlockIo.h   (with props)
Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/io/display/emscons.c
trunk/reactos/boot/environ/lib/io/io.c
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/blkalloc.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69142=69141=69142=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Wed Sep  9 
05:48:50 2015
@@ -22,43 +22,42 @@
 ULONGLONG ApplicationStartTime;
 ULONGLONG PostTime;
 GUID BmApplicationIdentifier;
+PWCHAR BootDirectory;
 
 /* FUNCTIONS */
 
-PGUID
-BlGetApplicationIdentifier (
+NTSTATUS
+BmFwInitializeBootDirectoryPath (
 VOID
 )
 {
-return NULL;
-}
-
-PWCHAR BootDirectory;
-
-NTSTATUS
-BmFwInitializeBootDirectoryPath()
-{
-#if 0
 PWCHAR FinalPath;
 NTSTATUS Status;
 PWCHAR BcdDirectory;
-UNICODE_STRING BcdPath;
-ULONG FinalSize, FileHandle, DeviceHandle;
-
-BcdPath.MaximumLength = 0;
-BcdPath.Buffer = NULL;
-
+   // UNICODE_STRING BcdPath;
+//ULONG FinalSize;
+ULONG FileHandle, DeviceHandle;
+
+/* Initialize everything for failure */
+   // BcdPath.MaximumLength = 0;
+   // BcdPath.Buffer = NULL;
+BcdDirectory = NULL;
 FinalPath = NULL;
-
 FileHandle = -1;
 DeviceHandle = -1;
 
+/* Try to open the boot device */
 Status = BlpDeviceOpen(BlpBootDevice, 1u, 0, );
 if (!NT_SUCCESS(Status))
 {
 goto Quickie;
 }
 
+/* For now, do nothing */
+EfiPrintf(L"Successfully opened boot device: %lx\r\n", DeviceHandle);
+EfiStall(200);
+
+#if 0
 Status = BmpFwGetApplicationDirectoryPath();
 BcdDirectory = BcdPath.Buffer;
 if (!NT_SUCCESS(Status))
@@ -91,8 +90,10 @@
 }
 
 BootDirectory = L"\\EFI\\Microsoft\\Boot";
+#endif
 
 Quickie:
+/* Free all the allocations we made */
 if (BcdDirectory)
 {
 Status = BlMmFreeHeap(BcdDirectory);
@@ -101,18 +102,21 @@
 {
 Status = BlMmFreeHeap(FinalPath);
 }
+
+/* Close the BCD file */
 if (FileHandle != -1)
 {
-Status = BlFileClose(FileHandle);
-}
+//Status = BlFileClose(FileHandle);
+}
+
+/* Close the boot device */
 if (DeviceHandle != -1)
 {
 Status = BlDeviceClose(DeviceHandle);
 }
+
+/* Return back to the caller */
 return Status;
-#else
-return STATUS_NOT_IMPLEMENTED;
-#endif
 }
 
 
@@ -172,6 +176,9 @@
 goto Quickie;
 }
 
+EfiPrintf(L"We are A-OK!\n");
+EfiStall(1000);
+
 /* Get the application identifier */
 AppIdentifier = BlGetApplicationIdentifier();
 if (!AppIdentifier)

Modified: trunk/reactos/boot/environ/app/bootmgr/efiemu.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/efiemu.c?rev=69142=69141=69142=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] Wed Sep  9 
05:48:50 2015
@@ -253,7 +253,10 @@
   FilePath->PathName,
   StringLength,
   );
-if (!NT_SUCCESS(Status)) return Status;
+if (!NT_SUCCESS(Status))
+{
+return Status;
+}
 
 /* Increase the size of the data, consume buffer space */
 DataSize += BytesAppended;
@@ -345,7 +348,7 @@
  *
  *--*/
 NTSTATUS
-EfiInitTranslateDevicePath(
+EfiInitTranslateDevicePath (
 

[ros-diffs] [ion] 69141: [CDMAKE] - Fix Build on VS2015

2015-09-08 Thread ion
Author: ion
Date: Wed Sep  9 04:58:25 2015
New Revision: 69141

URL: http://svn.reactos.org/svn/reactos?rev=69141=rev
Log:
[CDMAKE]
- Fix Build on VS2015

Modified:
trunk/reactos/tools/cdmake/cdmake.c

Modified: trunk/reactos/tools/cdmake/cdmake.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/cdmake/cdmake.c?rev=69141=69140=69141=diff
==
--- trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] (original)
+++ trunk/reactos/tools/cdmake/cdmake.c [iso-8859-1] Wed Sep  9 04:58:25 2015
@@ -1851,6 +1851,7 @@
 Program execution starts here.
 -*/
 
+#if (defined(__GNUC__) || (_MSC_VER < 1900))
 char* strtok_s(char *str, const char *delim, char **ctx)
 {
 if (delim == NULL || ctx == NULL || (str == NULL && *ctx == NULL))
@@ -1874,6 +1875,7 @@
 
 return str;
 }
+#endif
 
 int main(int argc, char **argv)
 {




[ros-diffs] [ion] 69078: [BOOTMGFW] - Fix text console bugs. It works now both when already at 80x25, as well as when using UEFI Shell to switch to 100x31 first. Tested with Virtual Box.

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 06:00:37 2015
New Revision: 69078

URL: http://svn.reactos.org/svn/reactos?rev=69078=rev
Log:
[BOOTMGFW]
- Fix text console bugs. It works now both when already at 80x25, as well as 
when using UEFI Shell to switch to 100x31 first. Tested with Virtual Box.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c
trunk/reactos/boot/environ/lib/platform/display.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69078=69077=69078=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Sep  7 
06:00:37 2015
@@ -55,6 +55,7 @@
 Status = BlInitializeLibrary(BootParameters, );
 
 EarlyPrint(L"ReactOS UEFI Boot Manager Exiting: %lx\n", Status);
+EfiStall(300);
 return Status;
 }
 

Modified: trunk/reactos/boot/environ/lib/bootlib.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/bootlib.c?rev=69078=69077=69078=diff
==
--- trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] Mon Sep  7 
06:00:37 2015
@@ -347,7 +347,6 @@
 Status = STATUS_SUCCESS;
 
 Quickie:
-EarlyPrint(L"Exiting init: %lx\n", Status);
 return Status;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/heapalloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/heapalloc.c?rev=69078=69077=69078=diff
==
--- trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] Mon Sep  7 
06:00:37 2015
@@ -537,7 +537,6 @@
 {
 /* The heap is ready! */
 HapInitializationStatus = 1;
-EarlyPrint(L"Heap Allocator Initialized!\n");
 Status = STATUS_SUCCESS;
 }
 

Modified: trunk/reactos/boot/environ/lib/mm/pagealloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/pagealloc.c?rev=69078=69077=69078=diff
==
--- trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/pagealloc.c   [iso-8859-1] Mon Sep  7 
06:00:37 2015
@@ -560,7 +560,6 @@
 if (NT_SUCCESS(Status))
 {
 /* The Page Allocator has initialized */
-EarlyPrint(L"Page Allocator initialized\n");
 PapInitializationStatus = TRUE;
 Status = STATUS_SUCCESS;
 }

Modified: trunk/reactos/boot/environ/lib/platform/display.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/platform/display.c?rev=69078=69077=69078=diff
==
--- trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] Mon Sep  7 
06:00:37 2015
@@ -147,7 +147,7 @@
 
 BL_DISPLAY_MODE ConsoleTextResolutionList[1] =
 {
-{80, 31, 80}
+{80, 25, 80}
 };
 
 NTSTATUS
@@ -231,14 +231,15 @@
 while (List != ListEnd)
 {
 /* Does this resolution match? */
-if ((Mode->HRes != List->HRes) || (Mode->VRes != List->VRes))
-{
-/* Try another one*/
-List++;
-}
-
-/* Yep -- we got a match */
-return TRUE;
+if ((Mode->HRes == List->HRes) && (Mode->VRes == List->VRes))
+{
+/* Yep -- we got a match */
+return TRUE;
+
+}
+
+/* Try another one*/
+List++;
 }
 
 /* No matches were found */
@@ -250,6 +251,7 @@
 _In_ UINT32 Attributes
 )
 {
+/* Read the foreground color attribute and convert to CGA color index */
 switch (Attributes & 0x0F)
 {
 case EFI_BLACK:
@@ -293,6 +295,7 @@
 _In_ UINT32 Attributes
 )
 {
+/* Read the background color attribute and convert to CGA color index */
 switch (Attributes & 0xF0)
 {
 case EFI_BACKGROUND_MAGENTA:
@@ -301,8 +304,8 @@
 return Brown;
 case EFI_BACKGROUND_LIGHTGRAY:
 return White;
+case EFI_BACKGROUND_BLACK:
 default:
-case EFI_BACKGROUND_BLACK:
 return Black;
 case EFI_BACKGROUND_RED:
 return Red;
@@ -320,6 +323,7 @@
 _In_ BL_COLOR Color
 )
 {
+/* Co

[ros-diffs] [ion] 69094: [BOOTMGFW] - Start GOP graphics console support. Checkpoint commit, currently WIP, untested. - Cleanup memory allocation/type/caching flags in a single unified enumeration. -

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 17:35:59 2015
New Revision: 69094

URL: http://svn.reactos.org/svn/reactos?rev=69094=rev
Log:
[BOOTMGFW]
- Start GOP graphics console support. Checkpoint commit, currently WIP, 
untested.
- Cleanup memory allocation/type/caching flags in a single unified enumeration.
- Implement memory mapping functions for physical real mode only.

Added:
trunk/reactos/boot/environ/include/efi/GraphicsOutput.h   (with props)
trunk/reactos/boot/environ/include/efi/UgaDraw.h   (with props)
Modified:
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/mm/pagealloc.c
trunk/reactos/boot/environ/lib/platform/display.c

Modified: trunk/reactos/boot/environ/app/bootmgr/efiemu.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/efiemu.c?rev=69094=69093=69094=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/efiemu.c [iso-8859-1] Mon Sep  7 
17:35:59 2015
@@ -24,9 +24,6 @@
 /* DATA VARIABLES /
 
 ULONG BlpApplicationFlags;
-
-GUID EfiLoadedImageProtocol = EFI_LOADED_IMAGE_PROTOCOL_GUID;
-GUID EfiDevicePathProtocol = EFI_DEVICE_PATH_PROTOCOL_GUID;
 
 BOOT_APPLICATION_PARAMETER_BLOCK_SCRATCH EfiInitScratch;
 

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69094=69093=69094=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Sep  7 
17:35:59 2015
@@ -26,6 +26,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 VOID
 EarlyPrint(_In_ PWCHAR Format, ...);
@@ -60,13 +62,6 @@
 #define BL_MM_ADD_DESCRIPTOR_NEVER_COALESCE_FLAG0x10
 #define BL_MM_ADD_DESCRIPTOR_NEVER_TRUNCATE_FLAG0x20
 #define BL_MM_ADD_DESCRIPTOR_UPDATE_LIST_POINTER_FLAG   0x2000
-
-#define BL_MM_DESCRIPTOR_REQUIRES_FIXED_FLAG0x4
-#define BL_MM_DESCRIPTOR_REQUIRES_COALESCING_FLAG   0x200
-#define BL_MM_DESCRIPTOR_REQUIRES_UPDATING_FLAG 0x400
-#define BL_MM_DESCRIPTOR_NEVER_USE_FIRMWARE_FLAG0x800
-#define BL_MM_DESCRIPTOR_SPECIAL_PAGES_FLAG 0x2000
-#define BL_MM_DESCRIPTOR_CAME_FROM_FIRMWARE_FLAG0x8000
 
 #define BL_MM_REQUEST_DEFAULT_TYPE  1
 #define BL_MM_REQUEST_TOP_DOWN_TYPE 2
@@ -193,15 +188,45 @@
 
 typedef enum _BL_MEMORY_ATTR
 {
-BlMemoryUncached = 1,
-BlMemoryWriteCombined = 2,
-BlMemoryWriteThrough = 4,
-BlMemoryWriteBack = 8,
-BlMemoryUncachedExported = 0x10,
-BlMemoryWriteProtected = 0x100,
-BlMemoryReadProtected = 0x200,
-BlMemoryExecuteProtected = 0x400,
-BlMemoryRuntime = 0x100
+//
+// Memory Caching Attributes
+//
+BlMemoryUncached =  0x0001,
+BlMemoryWriteCombined = 0x0002,
+BlMemoryWriteThrough =  0x0004,
+BlMemoryWriteBack = 0x0008,
+BlMemoryUncachedExported =  0x0010,
+BlMemoryValidCacheAttributes= BlMemoryUncached | 
BlMemoryWriteCombined | BlMemoryWriteThrough | BlMemoryWriteBack | 
BlMemoryUncachedExported,
+BlMemoryValidCacheAttributeMask = 0x00FF,
+
+//
+// Memory Protection Attributes
+//
+BlMemoryWriteProtected =0x0100,
+BlMemoryReadProtected = 0x0200,
+BlMemoryExecuteProtected =  0x0400,
+BlMemoryValidProtectionAttributes   = BlMemoryWriteProtected | 
BlMemoryReadProtected | BlMemoryExecuteProtected,
+BlMemoryValidProtectionAttributeMask= 0xFF00,
+
+//
+// Memory Allocation Attributes
+//
+BlMemoryNonFixed =  0x0002,
+BlMemoryFixed = 0x0004,
+BlMemoryValidAllocationAttributes   = BlMemoryNonFixed | BlMemoryFixed,
+BlMemoryValidAllocationAttributeMask= 0x00FF,
+
+//
+// Memory Type Attributes
+//
+BlMemoryRuntime =   0x0100,
+BlMemoryCoalesced = 0x0200,
+BlMemoryUpdate =0x0400,
+BlMemoryNonFirmware =   0x0800,
+BlMemorySpecial =   0x2000,
+BlMemoryFirmware =  0x8000,
+BlMemoryValidTypeAttributes = BlMemoryRuntime | 
BlMemoryCoalesced | BlMemoryUpdate | BlMemoryNonFirmware | BlMemorySpecial | 
BlMemoryFirmware,
+BlMemoryValidTypeAttributeMask  = 0xFF00,
 } BL_MEMORY_ATTR

[ros-diffs] [ion] 69103: [BOOTMGFW] - EarlyPrint -> EfiPrintf, as it seems BL actually has this after all :) Change all callers to conform to it. - Add common exit/failure path in BmMain. Now the fun

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 23:31:08 2015
New Revision: 69103

URL: http://svn.reactos.org/svn/reactos?rev=69103=rev
Log:
[BOOTMGFW]
- EarlyPrint -> EfiPrintf, as it seems BL actually has this after all :) Change 
all callers to conform to it.
- Add common exit/failure path in BmMain. Now the fun begins.

Modified:
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/io/display/display.c
trunk/reactos/boot/environ/lib/io/display/efi/gop.c
trunk/reactos/boot/environ/lib/io/display/efi/guicons.c
trunk/reactos/boot/environ/lib/io/display/efi/textcons.c
trunk/reactos/boot/environ/lib/io/display/efi/uga.c
trunk/reactos/boot/environ/lib/io/display/guicons.c
trunk/reactos/boot/environ/lib/io/display/textcons.c
trunk/reactos/boot/environ/lib/misc/util.c
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/heapalloc.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
trunk/reactos/boot/environ/lib/platform/time.c

Modified: trunk/reactos/boot/environ/lib/bootlib.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/bootlib.c?rev=69103=69102=69103=diff
==
--- trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] Mon Sep  7 
23:31:08 2015
@@ -23,28 +23,6 @@
 LIST_ENTRY BlBadpListHead;
 
 /* FUNCTIONS */
-
-/* HACKKKYYY */
-EFI_SYSTEM_TABLE* g_SystemTable;
-
-VOID
-EarlyPrint(_In_ PWCHAR Format, ...)
-{
-WCHAR buffer[1024];
-va_list args;
-
-va_start(args, Format);
-
-vswprintf(buffer, Format, args);
-
-g_SystemTable->ConOut->OutputString(g_SystemTable->ConOut, L"\r");
-g_SystemTable->ConOut->OutputString(g_SystemTable->ConOut, buffer);
-
-g_SystemTable->BootServices->Stall(20);
-
-va_end(args);
-}
-/* END HACKKKYYY */
 
 /*++
  * @name InitializeLibrary
@@ -131,7 +109,7 @@
  LibraryParameters);
 if (!NT_SUCCESS(Status))
 {
-EarlyPrint(L"MM init failed!\n");
+EfiPrintf(L"MM init failed!\r\n");
 goto Quickie;
 }
 
@@ -141,7 +119,7 @@
 {
 /* Destroy memory manager in phase 1 */
 //BlpMmDestroy(1);
-EarlyPrint(L"Firmware2 init failed!\n");
+EfiPrintf(L"Firmware2 init failed!\r\n");
 return Status;
 }
 
@@ -163,7 +141,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Destroy memory manager in phase 1 */
-EarlyPrint(L"TSC calibration failed\n");
+EfiPrintf(L"TSC calibration failed\r\n");
 //BlpMmDestroy(1);
 return Status;
 }
@@ -174,7 +152,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Destroy memory manager in phase 1 */
-EarlyPrint(L"Arch2 init failed\n");
+EfiPrintf(L"Arch2 init failed\r\n");
 //BlpMmDestroy(1);
 return Status;
 }
@@ -195,7 +173,7 @@
 if (!NT_SUCCESS(Status))
 {
 /* Destroy memory manager in phase 1 and the event manager */
-EarlyPrint(L"IO init failed\n");
+EfiPrintf(L"IO init failed\r\n");
 #ifdef BL_TPM_SUPPORT
 if (EnSubsystemInitialized)
 {
@@ -240,7 +218,7 @@
 }
 #endif
 //BlpMmDestroy(1);
-EarlyPrint(L"Util init failed\n");
+EfiPrintf(L"Util init failed\r\n");
 return Status;
 }
 
@@ -407,3 +385,11 @@
 return Status;
 }
 
+VOID
+BlDestroyLibrary (
+VOID
+)
+{
+EfiPrintf(L"Destroy not yet implemented\r\n");
+return;
+}

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=69103=69102=69103=diff
==
--- 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] 
Mon Sep  7 23:31:08 2015
@@ -30,7 +30,37 @@
 EFI_GUID EfiDevicePathProtocol = EFI_DEVICE_PATH_PROTOCOL_GUID;
 EFI_GUID EfiSimpleTextInputExProtocol = EFI_SIMPLE_TEXT_INPUT_EX_PROTOCOL_GUID;
 
+WCHAR BlScratchBuffer[8192];
+
 /* FUNCTIONS */
+
+VOID
+EfiPrintf (
+_In_ PWCHAR Format,
+...
+)
+{
+va_list args;
+va_start(args, Format);
+
+/* Capture the buffer in our scratch pad, and NULL-terminate */
+vsnwprintf(BlScratchBuffer, RTL_NUMBER_OF(BlScratchBuffer

[ros-diffs] [ion] 69104: [BOOTMGFW] - And again with the fucking non-recursion.

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 23:48:21 2015
New Revision: 69104

URL: http://svn.reactos.org/svn/reactos?rev=69104=rev
Log:
[BOOTMGFW]
- And again with the fucking non-recursion.

Modified:
trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
trunk/reactos/boot/environ/app/bootmgr/efiemu.c
trunk/reactos/boot/environ/include/bl.h

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=69104=69103=69104=diff
==
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c[iso-8859-1] Mon Sep  7 
23:48:21 2015
@@ -12,10 +12,109 @@
 
 /* DATA VARIABLES /
 
+#include 
+DEFINE_GUID(GUID_WINDOWS_BOOTMGR,
+0x9DEA862C,
+0x5CDD,
+0x4E70,
+0xAC, 0xC1, 0xF3, 0x2B, 0x34, 0x4D, 0x47, 0x95);
+
 ULONGLONG ApplicationStartTime;
 ULONGLONG PostTime;
+GUID BmApplicationIdentifier;
 
 /* FUNCTIONS */
+
+PGUID
+BlGetApplicationIdentifier (
+VOID
+)
+{
+return NULL;
+}
+
+PWCHAR BootDirectory;
+
+NTSTATUS
+BmFwInitializeBootDirectoryPath()
+{
+#if 0
+PWCHAR FinalPath;
+NTSTATUS Status;
+PWCHAR BcdDirectory;
+UNICODE_STRING BcdPath;
+ULONG FinalSize, FileHandle, DeviceHandle;
+
+BcdPath.MaximumLength = 0;
+BcdPath.Buffer = NULL;
+
+FinalPath = NULL;
+
+FileHandle = -1;
+DeviceHandle = -1;
+
+Status = BlpDeviceOpen(BlpBootDevice, 1u, 0, );
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+Status = BmpFwGetApplicationDirectoryPath();
+BcdDirectory = BcdPath.Buffer;
+if (!NT_SUCCESS(Status))
+{
+goto Quickie;
+}
+
+FinalSize = BcdPath.MaximumLength + sizeof(L"\\BCD") - 
sizeof(UNICODE_NULL);
+if (FinalSize < BcdPath.MaximumLength)
+{
+goto Quickie;
+}
+
+FinalPath = BlMmAllocateHeap(FinalSize);
+if (!FinalPath)
+{
+goto Quickie;
+}
+
+RtlZeroMemory(FinalPath, FinalSize);
+RtlCopyMemory(FinalPath, BcdDirectory, BcdPath.MaximumLength);
+wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR));
+
+EfiPrintf(L"Opening: %s\r\n", FinalPath);
+Status = BlFileOpen(DeviceHandle, FinalPath, 1u, );
+if (!NT_SUCCESS(Status))
+{
+BootDirectory = BcdDirectory;
+goto Quickie;
+}
+
+BootDirectory = L"\\EFI\\Microsoft\\Boot";
+
+Quickie:
+if (BcdDirectory)
+{
+Status = BlMmFreeHeap(BcdDirectory);
+}
+if (FinalPath)
+{
+Status = BlMmFreeHeap(FinalPath);
+}
+if (FileHandle != -1)
+{
+Status = BlFileClose(FileHandle);
+}
+if (DeviceHandle != -1)
+{
+Status = BlDeviceClose(DeviceHandle);
+}
+return Status;
+#else
+return STATUS_NOT_IMPLEMENTED;
+#endif
+}
+
 
 /*++
  * @name BmMain
@@ -37,8 +136,15 @@
 {
 NTSTATUS Status;
 BL_LIBRARY_PARAMETERS LibraryParameters;
-
-EarlyPrint(L"ReactOS UEFI Boot Manager Initializing...\n");
+PBL_RETURN_ARGUMENTS ReturnArguments;
+BOOLEAN RebootOnError;
+PGUID AppIdentifier;
+//HANDLE BcdHandle;
+
+EfiPrintf(L"ReactOS UEFI Boot Manager Initializing...\n");
+
+/* Reading the BCD can change this later on */
+RebootOnError = FALSE;
 
 /* Save the start/end-of-POST time */
 ApplicationStartTime = __rdtsc();
@@ -53,9 +159,59 @@
 
 /* Initialize the boot library */
 Status = BlInitializeLibrary(BootParameters, );
-
-EarlyPrint(L"ReactOS UEFI Boot Manager Exiting: %lx\n", Status);
-EfiStall(300);
+if (!NT_SUCCESS(Status))
+{
+/* Check for failure due to invalid application entry */
+if (Status != STATUS_INVALID_PARAMETER_9)
+{
+/* Specifically print out what happened */
+EfiPrintf(L"BlInitializeLibrary failed 0x%x\r\n", Status);
+}
+
+/* Go to exit path */
+goto Quickie;
+}
+
+/* Get the application identifier */
+AppIdentifier = BlGetApplicationIdentifier();
+if (!AppIdentifier)
+{
+/* None was given, so set our default one */
+AppIdentifier = (PGUID)_WINDOWS_BOOTMGR;
+}
+
+/* Save our identifier */
+BmApplicationIdentifier = *AppIdentifier;
+
+/* Initialize the file system to open a handle to our root boot directory 
*/
+BmFwInitializeBootDirectoryPath();
+
+//Status = BmOpenDataStore();
+
+EfiPrintf(L"We are A-OK!\n");
+EfiStall(1000);
+
+Quickie:
+/* Check if we should reboot */
+if ((RebootOnError) ||
+(BlpApplicationEntry.Flags & BL_APPLICATION_ENTRY_REBOOT_ON_ERROR))
+{
+ 

[ros-diffs] [ion] 69098: [BOOTMGFW] - Fix heap bugs, thanks to Thomas! - Now only the last heap operation shows corruption.

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 19:06:14 2015
New Revision: 69098

URL: http://svn.reactos.org/svn/reactos?rev=69098=rev
Log:
[BOOTMGFW]
- Fix heap bugs, thanks to Thomas!
- Now only the last heap operation shows corruption.

Modified:
trunk/reactos/boot/environ/lib/mm/blkalloc.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c

Modified: trunk/reactos/boot/environ/lib/mm/blkalloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/blkalloc.c?rev=69098=69097=69098=diff
==
--- trunk/reactos/boot/environ/lib/mm/blkalloc.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/blkalloc.c[iso-8859-1] Mon Sep  7 
19:06:14 2015
@@ -19,7 +19,7 @@
 typedef struct _BL_BLOCK_DESCRIPTOR
 {
 LIST_ENTRY NextEntry;
-UCHAR Unknown[50 - sizeof(LIST_ENTRY)];
+UCHAR Unknown[0x50 - sizeof(LIST_ENTRY)];
 } BL_BLOCK_DESCRIPTOR, *PBL_BLOCK_DESCRIPTOR;
 
 /* FUNCTIONS */

Modified: trunk/reactos/boot/environ/lib/mm/heapalloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/heapalloc.c?rev=69098=69097=69098=diff
==
--- trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/heapalloc.c   [iso-8859-1] Mon Sep  7 
19:06:14 2015
@@ -83,6 +83,19 @@
 return (ULONG_PTR)MmHapDecodeLink(Entry->BufferNext) - (ULONG_PTR)Entry;
 }
 
+FORCEINLINE
+ULONG
+MmHapUserBufferSize (
+_In_ PVOID FreeEntry
+)
+{
+PBL_FREE_HEAP_ENTRY Entry = FreeEntry;
+
+/* Get the size of the buffer as the user sees it */
+return MmHapBufferSize(Entry) - FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer);
+}
+
+
 /* FUNCTIONS */
 
 NTSTATUS
@@ -97,7 +110,7 @@
 
 /* Compute a new heap, and add 2 more pages for the free list */
 HeapSize = ExtendSize + (2 * PAGE_SIZE);
-if ((ExtendSize + (2 * PAGE_SIZE)) < ExtendSize)
+if (HeapSize < ExtendSize)
 {
 return STATUS_INTEGER_OVERFLOW;
 }
@@ -188,7 +201,10 @@
 ULONG BucketIndex = 0;
 
 /* Use the last bucket if this is a large allocation */
-if (Size >= PAGE_SIZE) return 7;
+if (Size >= PAGE_SIZE)
+{
+return 7;
+}
 
 /* Otherwise, use a higher index for each new power of two */
 while (Size >> BucketIndex)
@@ -196,7 +212,7 @@
 BucketIndex++;
 }
 
-/* Allocations are at least 8 bytes (2^3 = 4th index) */
+/* Allocations are at least 16 bytes (2^4 = 5th index) */
 return BucketIndex - 5;
 }
 
@@ -347,7 +363,10 @@
 
 /* Get the previous entry and check if it's free */
 Prev = MmHapDecodeLink(FreeEntry->BufferPrevious);
-if (!(Prev) || !(Prev->BufferNext.BufferFree)) return FreeEntry;
+if (!(Prev) || !(Prev->BufferNext.BufferFree))
+{
+return FreeEntry;
+}
 
 /* It's free, so remove it */
 Prev = MmHapRemoveBufferFromFreeList(Prev);
@@ -391,7 +410,7 @@
 !(Flags))
 {
 /* Yep, zero it out */
-RtlZeroMemory(Entry->Buffer, MmHapBufferSize(Entry));
+RtlZeroMemory(Entry->Buffer, MmHapUserBufferSize(Entry));
 }
 
 /* Now mark the entry as free */
@@ -560,8 +579,8 @@
 }
 
 /* Align the buffer size to the minimum size required */
-BufferSize = ALIGN_UP(Size + sizeof(BL_BUSY_HEAP_ENTRY),
-  sizeof(BL_BUSY_HEAP_ENTRY));
+BufferSize = ALIGN_UP(Size + FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer),
+  FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer));
 
 /* Watch out for overflow */
 if (BufferSize <= Size)
@@ -598,7 +617,8 @@
 NextEntry = (PBL_BUSY_HEAP_ENTRY)((ULONG_PTR)FreeEntry + 
BufferSize);
 
 if ((NextEntry >= FreeEntry) &&
-((ULONG_PTR)NextEntry <= Heap->HeapLimit - 
sizeof(BL_BUSY_HEAP_ENTRY)))
+((ULONG_PTR)NextEntry <=
+ Heap->HeapLimit - FIELD_OFFSET(BL_BUSY_HEAP_ENTRY, Buffer)))
 {
 /* Update the heap top pointer past this allocation */
 Heap->HeapStart = NextEntry;
@@ -607,7 +627,7 @@
 FreeEntry->BufferNext.P = Heap->HeapStart;
 
 /* And make the free heap entry point back to us */
-Heap->HeapStart->BufferNext.P = FreeEntry;
+Heap->HeapStart->BufferPrevious.P = FreeEntry;
 
 /* Mark the heap entry as being free and on the heap */
 Heap->HeapStart->BufferNext.BufferFree = 1;




[ros-diffs] [ion] 69097: [BOOTMGFW] - Last round of display fixes. GOP works now -- fill out the frame buffer with gray as a test (tested in VirtualBox). - Now to fix the heap.

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 18:45:09 2015
New Revision: 69097

URL: http://svn.reactos.org/svn/reactos?rev=69097=rev
Log:
[BOOTMGFW]
- Last round of display fixes. GOP works now -- fill out the frame buffer with 
gray as a test (tested in VirtualBox).
- Now to fix the heap.

Modified:
trunk/reactos/boot/environ/lib/mm/descriptor.c
trunk/reactos/boot/environ/lib/mm/mm.c
trunk/reactos/boot/environ/lib/platform/display.c

Modified: trunk/reactos/boot/environ/lib/mm/descriptor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/descriptor.c?rev=69097=69096=69097=diff
==
--- trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/descriptor.c  [iso-8859-1] Mon Sep  7 
18:45:09 2015
@@ -770,18 +770,46 @@
 VOID
 )
 {
+PBL_MEMORY_DESCRIPTOR Descriptor, OldDescriptor;
 ULONG Index = 0;
+PLIST_ENTRY OldFlink, OldBlink;
 
 /* Make sure we're not int middle of a call using a descriptor */
+EarlyPrint(L"Call depth is %d\n", MmDescriptorCallTreeCount);
 if (MmDescriptorCallTreeCount != 1)
 {
 return;
 }
 
 /* Loop every current global descriptor */
+EarlyPrint(L"MmGlobalMemoryDescriptorsUsed: %d\n", 
MmGlobalMemoryDescriptorsUsed);
 while (Index < MmGlobalMemoryDescriptorsUsed)
 {
-EarlyPrint(L"Global descriptors not yet supported\n");
+/* Does it have any valid pageS? */
+OldDescriptor = [Index];
+if (OldDescriptor->PageCount)
+{
+/* Allocate a copy of it */
+Descriptor = BlMmAllocateHeap(sizeof(*Descriptor));
+if (!Descriptor)
+{
+return;
+}
+
+/* Save the links */
+OldFlink = OldDescriptor->ListEntry.Blink;
+OldBlink = OldDescriptor->ListEntry.Flink;
+
+/* Make the copy */
+*Descriptor = *OldDescriptor;
+
+/* Fix the links */
+OldBlink->Flink = >ListEntry;
+OldFlink->Blink = >ListEntry;
+
+/* Zero the descriptor */
+RtlZeroMemory(OldDescriptor, sizeof(*OldDescriptor));
+}
 
 /* Keep going */
 Index++;

Modified: trunk/reactos/boot/environ/lib/mm/mm.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/mm.c?rev=69097=69096=69097=diff
==
--- trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/mm.c  [iso-8859-1] Mon Sep  7 
18:45:09 2015
@@ -304,7 +304,7 @@
 /* Go back to static descriptors and kill the heap */
 //MmMdpSwitchToStaticDescriptors();
 //HapInitializationStatus = 0;
-++MmDescriptorCallTreeCount;
+//++MmDescriptorCallTreeCount;
 
 /* Destroy the Phase 1 initialization */
 //MmPaDestroy(0);
@@ -315,7 +315,7 @@
 
 Quickie:
 /* Free the memory descriptors and return the initialization state */
-//MmMdFreeGlobalDescriptors();
+MmMdFreeGlobalDescriptors();
 --MmDescriptorCallTreeCount;
 return Status;
 }

Modified: trunk/reactos/boot/environ/lib/platform/display.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/platform/display.c?rev=69097=69096=69097=diff
==
--- trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] Mon Sep  7 
18:45:09 2015
@@ -146,17 +146,12 @@
 typedef struct _BL_GRAPHICS_CONSOLE
 {
 BL_TEXT_CONSOLE TextConsole;
-
 BL_DISPLAY_MODE DisplayMode;
-
 ULONG PixelDepth;
-
 ULONG FgColor;
 ULONG BgColor;
-
 BL_DISPLAY_MODE OldDisplayMode;
 ULONG OldPixelDepth;
-
 EFI_HANDLE Handle;
 BL_GRAPHICS_CONSOLE_TYPE Type;
 EFI_GRAPHICS_OUTPUT_PROTOCOL* Protocol;
@@ -166,6 +161,11 @@
 ULONG Mode;
 ULONG OldMode;
 } BL_GRAPHICS_CONSOLE, *PBL_GRAPHICS_CONSOLE;
+
+typedef struct _BL_REMOTE_CONSOLE
+{
+BL_TEXT_CONSOLE TextConsole;
+} BL_REMOTE_CONSOLE, *PBL_REMOTE_CONSOLE;
 
 PVOID BfiCachedStrikeData;
 LIST_ENTRY BfiDeferredListHead;
@@ -1343,6 +1343,49 @@
 }
 
 NTSTATUS
+ConsoleRemoteConstruct (
+_In_ PBL_REMOTE_CONSOLE RemoteConsole
+)
+{
+#ifdef BL_EMS_SUPPORT
+#error Implement me
+#else
+/* We don't support EMS for now */
+return STATUS_NOT_IMPLEMENTED;
+#endif
+}
+
+NTSTATUS
+ConsoleCreateRemoteConsole (
+_In_ PBL_TEXT_CONSOLE* TextConsole
+)
+{
+PBL_REMOTE_CONSOLE RemoteConsole;
+NTSTATUS Status;
+
+/* Allocate the remote console */
+RemoteConsole = BlMmAllocateHeap(sizeof(*RemoteConsole));
+if (!RemoteConsole)
+{
+return STA

[ros-diffs] [ion] 69100: [BOOTMGFW] - Forgot that SVN doesn't traverse up.

2015-09-07 Thread ion
Author: ion
Date: Mon Sep  7 19:46:50 2015
New Revision: 69100

URL: http://svn.reactos.org/svn/reactos?rev=69100=rev
Log:
[BOOTMGFW]
- Forgot that SVN doesn't traverse up.

Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/include/bl.h

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=69100=69099=69100=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Mon Sep  7 
19:46:50 2015
@@ -23,7 +23,14 @@
  lib/io/device.c
  lib/io/file.c
  lib/io/fat.c
- lib/platform/display.c)
+ lib/io/display/display.c
+ lib/io/display/emscons.c
+ lib/io/display/guicons.c
+ lib/io/display/textcons.c
+ lib/io/display/efi/textcons.c
+ lib/io/display/efi/guicons.c
+ lib/io/display/efi/gop.c
+ lib/io/display/efi/uga.c)
 
 if(ARCH STREQUAL "i386")
 list(APPEND BOOTLIB_ASM_SOURCE

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69100=69099=69100=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Sep  7 
19:46:50 2015
@@ -75,11 +75,34 @@
 #define BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED0x20
 #define BL_LIBRARY_FLAG_NO_GRAPHICS_CONSOLE 0x800
 
+#define BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG  0x01
+#define BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG   0x02
+
 #define BL_FS_REGISTER_AT_HEAD_FLAG 1
 
 #define BL_MEMORY_CLASS_SHIFT   28
 
 /* ENUMERATIONS **/
+
+typedef enum _BL_COLOR
+{
+Black,
+Blue,
+Green,
+Cyan,
+Red,
+Magenta,
+Brown,
+LtGray,
+Gray,
+LtBlue,
+LtGreen,
+LtCyan,
+LtRed,
+LtMagenta,
+Yellow,
+White
+} BL_COLOR, *PBL_COLOR;
 
 typedef enum _BL_MEMORY_DESCRIPTOR_TYPE
 {
@@ -259,6 +282,65 @@
 NTSTATUS
 (*PBL_FILE_DESTROY_CALLBACK) (
 _In_ PVOID Entry
+);
+
+struct _BL_TEXT_CONSOLE;
+struct _BL_DISPLAY_STATE;
+typedef
+NTSTATUS
+(*PCONSOLE_DESTRUCT) (
+_In_ struct _BL_TEXT_CONSOLE* Console
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_REINITIALIZE) (
+_In_ struct _BL_TEXT_CONSOLE* Console
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_GET_TEXT_STATE) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_Out_ struct _BL_DISPLAY_STATE* TextState
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_SET_TEXT_STATE) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_In_ ULONG Flags,
+_In_ struct _BL_DISPLAY_STATE* TextState
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_GET_TEXT_RESOLUTION) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_Out_ PULONG TextResolution
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_SET_TEXT_RESOLUTION) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_In_ ULONG NewTextResolution,
+_Out_ PULONG OldTextResolution
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_CLEAR_TEXT) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_In_ ULONG Attribute
+);
+
+typedef
+NTSTATUS
+(*PCONSOLE_WRITE_TEXT) (
+_In_ struct _BL_TEXT_CONSOLE* Console,
+_In_ PCHAR Text,
+_In_ ULONG Attribute
 );
 
 /* DATA STRUCTURES ***/
@@ -509,6 +591,81 @@
 PBL_FS_PURGE_CALLBACK Purge;
 } BL_FILE_SYSTEM_REGISTRATION_TABLE;
 
+typedef struct _BL_DISPLAY_STATE
+{
+ULONG BgColor;
+ULONG FgColor;
+ULONG XPos;
+ULONG YPos;
+ULONG CursorVisible;
+} BL_DISPLAY_STATE, *PBL_DISPLAY_STATE;
+
+typedef struct _BL_DISPLAY_MODE
+{
+ULONG HRes;
+ULONG VRes;
+ULONG HRes2;
+} BL_DISPLAY_MODE, *PBL_DISPLAY_MODE;
+
+typedef struct _BL_TEXT_CONSOLE_VTABLE
+{
+PCONSOLE_DESTRUCT Destruct;
+PCONSOLE_REINITIALIZE Reinitialize;
+PCONSOLE_GET_TEXT_STATE GetTextState;
+PCONSOLE_SET_TEXT_STATE SetTextState;
+PCONSOLE_GET_TEXT_RESOLUTION GetTextResolution;
+PCONSOLE_SET_TEXT_RESOLUTION SetTextResolution;
+PCONSOLE_CLEAR_TEXT ClearText;
+PCONSOLE_WRITE_TEXT WriteText;
+} BL_TEXT_CONSOLE_VTABLE, *PBL_TEXT_CONSOLE_VTABLE;
+
+typedef struct _BL_GRAPHICS_CONSOLE_VTABLE
+{
+BL_TEXT_CONSOLE_VTABLE Text;
+/// more for graphics ///
+} BL_GRAPHICS_CONSOLE_VTABLE, *PBL_GRAPHICS_CONSOLE_VTABLE;
+
+typedef struct _BL_TEXT_CONSOLE
+{
+PBL_TEXT_CONSOLE_VTABLE Callbacks;
+BL_DISPLAY_STATE State;
+BL_DISPLAY_MODE DisplayMode;
+BOOLEAN Active;
+EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL* Protocol;
+ULONG Mode;
+EFI_SIMPLE_TEXT_OUTPUT_MODE OldMode;
+} BL_TEXT_CONSOLE, *PBL_TEXT_CONSOLE;
+
+typedef enum _BL_GRAPHICS_CO

[ros-diffs] [ion] 69076: [BOOTMGFW] - Checkpoint commit of about 1000+ lines of text console support code. Right now, it's very disorganized and not tested. - Write out the rest of the initialization

2015-09-06 Thread ion
Author: ion
Date: Mon Sep  7 04:37:01 2015
New Revision: 69076

URL: http://svn.reactos.org/svn/reactos?rev=69076=rev
Log:
[BOOTMGFW]
- Checkpoint commit of about 1000+ lines of text console support code. Right 
now, it's very disorganized and not tested.
- Write out the rest of the initialization path. Almost everything else is only 
for Boot Debugging, BitLocker, TPM, PXE... 

Added:
trunk/reactos/boot/environ/lib/platform/display.c   (with props)
Modified:
trunk/reactos/boot/environ/CMakeLists.txt
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c

Modified: trunk/reactos/boot/environ/CMakeLists.txt
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/CMakeLists.txt?rev=69076=69075=69076=diff
==
--- trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/CMakeLists.txt   [iso-8859-1] Mon Sep  7 
04:37:01 2015
@@ -22,7 +22,8 @@
  lib/io/io.c
  lib/io/device.c
  lib/io/file.c
- lib/io/fat.c)
+ lib/io/fat.c
+ lib/platform/display.c)
 
 if(ARCH STREQUAL "i386")
 list(APPEND BOOTLIB_ASM_SOURCE

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69076=69075=69076=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Sep  7 
04:37:01 2015
@@ -73,10 +73,12 @@
 
 #define BL_MM_REMOVE_VIRTUAL_REGION_FLAG0x8000
 
+#define BL_LIBRARY_FLAG_NO_DISPLAY  0x01
 #define BL_LIBRARY_FLAG_REINITIALIZE0x02
 #define BL_LIBRARY_FLAG_REINITIALIZE_ALL0x04
 #define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE   0x10
 #define BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED0x20
+#define BL_LIBRARY_FLAG_NO_GRAPHICS_CONSOLE 0x800
 
 #define BL_FS_REGISTER_AT_HEAD_FLAG 1
 
@@ -595,6 +597,11 @@
 VOID
 );
 
+NTSTATUS
+BlpDisplayInitialize (
+_In_ ULONG Flags
+);
+
 /* FIRMWARE ROUTINES */
 
 NTSTATUS
@@ -607,6 +614,45 @@
 NTSTATUS
 EfiStall (
 _In_ ULONG StallTime
+);
+
+NTSTATUS
+EfiConOutQueryMode (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_In_ ULONG Mode,
+_In_ PULONG Columns,
+_In_ PULONG Rows
+);
+
+NTSTATUS
+EfiConOutSetMode (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_In_ ULONG Mode
+);
+
+VOID
+EfiConOutReadCurrentMode (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_Out_ EFI_SIMPLE_TEXT_OUTPUT_MODE* Mode
+);
+
+NTSTATUS
+EfiConOutSetAttribute (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_In_ ULONG Attribute
+);
+
+NTSTATUS
+EfiConOutSetCursorPosition (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_In_ ULONG Column,
+_In_ ULONG Row
+);
+
+NTSTATUS
+EfiConOutEnableCursor (
+_In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
+_In_ BOOLEAN Visible
 );
 
 /* PLATFORM TIMER ROUTINES ***/
@@ -739,11 +785,21 @@
 _In_ PVOID Buffer
 );
 
+/* DISPLAY ROUTINES **/
+
+VOID
+BlDisplayGetTextCellResolution (
+_Out_ PULONG TextWidth,
+_Out_ PULONG TextHeight
+);
+
 extern ULONG MmDescriptorCallTreeCount;
 extern ULONG BlpApplicationFlags;
 extern BL_LIBRARY_PARAMETERS BlpLibraryParameters;
 extern BL_TRANSLATION_TYPE  MmTranslationType;
 extern PBL_ARCH_CONTEXT CurrentExecutionContext;
 extern PBL_DEVICE_DESCRIPTOR BlpBootDevice;
+extern BL_APPLICATION_ENTRY BlpApplicationEntry;
+extern SIMPLE_TEXT_OUTPUT_INTERFACE *EfiConOut;
 
 #endif

Modified: trunk/reactos/boot/environ/lib/bootlib.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/bootlib.c?rev=69076=69075=69076=diff
==
--- trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] Mon Sep  7 
04:37:01 2015
@@ -18,8 +18,9 @@
 PBOOT_APPLICATION_PARAMETER_BLOCK BlpApplicationParameters;
 BL_APPLICATION_ENTRY BlpApplicationEntry;
 BOOLEAN BlpLibraryParametersInitialized;
-BOOLEAN EnSubsystemInitialized;
-LIST_ENTRY EnEventNotificationList;
+
+ULONG PdPersistAllocations;
+LIST_ENTRY BlBadpListHead;
 
 /* FUNCTIONS */
 
@@ -178,34 +179,46 @@
 return Status;
 }
 
-#if 0
+#ifdef BL_TPM_SUPPORT
 /* Initialize support for Trusted Platform Module v1.2 */
 BlpTpmInitialize();
 #endif
 
+#ifdef BL_T

[ros-diffs] [ion] 69077: [BOOTMGFW] - Build fixes for GCC

2015-09-06 Thread ion
Author: ion
Date: Mon Sep  7 04:42:34 2015
New Revision: 69077

URL: http://svn.reactos.org/svn/reactos?rev=69077=rev
Log:
[BOOTMGFW]
- Build fixes for GCC

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/bootlib.c
trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
trunk/reactos/boot/environ/lib/platform/display.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69077=69076=69077=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Mon Sep  7 
04:42:34 2015
@@ -620,8 +620,8 @@
 EfiConOutQueryMode (
 _In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
 _In_ ULONG Mode,
-_In_ PULONG Columns,
-_In_ PULONG Rows
+_In_ UINTN* Columns,
+_In_ UINTN* Rows
 );
 
 NTSTATUS

Modified: trunk/reactos/boot/environ/lib/bootlib.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/bootlib.c?rev=69077=69076=69077=diff
==
--- trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/bootlib.c[iso-8859-1] Mon Sep  7 
04:42:34 2015
@@ -190,7 +190,7 @@
 InitializeListHead();
 #endif
 
-/* Initialize the I/O Manager */i
+/* Initialize the I/O Manager */
 Status = BlpIoInitialize();
 if (!NT_SUCCESS(Status))
 {

Modified: trunk/reactos/boot/environ/lib/firmware/efi/firmware.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/firmware/efi/firmware.c?rev=69077=69076=69077=diff
==
--- 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] 
Mon Sep  7 04:42:34 2015
@@ -251,8 +251,8 @@
 EfiConOutQueryMode (
 _In_ SIMPLE_TEXT_OUTPUT_INTERFACE *TextInterface,
 _In_ ULONG Mode,
-_In_ PULONG Columns,
-_In_ PULONG Rows
+_In_ UINTN* Columns,
+_In_ UINTN* Rows
 )
 {
 BL_ARCH_MODE OldMode;
@@ -407,7 +407,6 @@
 )
 {
 BL_ARCH_MODE OldMode;
-EFI_STATUS EfiStatus;
 
 /* Are we in protected mode? */
 OldMode = CurrentExecutionContext->Mode;

Modified: trunk/reactos/boot/environ/lib/platform/display.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/platform/display.c?rev=69077=69076=69077=diff
==
--- trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/platform/display.c   [iso-8859-1] Mon Sep  7 
04:42:34 2015
@@ -535,7 +535,8 @@
 )
 {
 EFI_SIMPLE_TEXT_OUTPUT_MODE ModeInfo;
-ULONG MaxMode, MaxQueriedMode, Mode, HRes, VRes, i, MatchingMode;
+ULONG MaxMode, MaxQueriedMode, Mode, i, MatchingMode;
+UINTN HRes, VRes;
 ULONGLONG ModeListSize;
 PBL_DISPLAY_MODE ModeEntry, ModeList, SupportedModeEntry;
 NTSTATUS Status;
@@ -632,7 +633,8 @@
 {
 BL_DISPLAY_MODE DisplayMode;
 EFI_SIMPLE_TEXT_OUTPUT_MODE CurrentMode, NewMode;
-ULONG HRes, VRes, Mode;
+UINTN HRes, VRes;
+ULONG Mode;
 NTSTATUS Status;
 
 /* Read the current mode and its settings */
@@ -834,12 +836,12 @@
 )
 {
 BL_LIBRARY_PARAMETERS LibraryParameters = BlpLibraryParameters;
-BOOLEAN NoGraphics, HighestMode;
+BOOLEAN NoGraphics;// , HighestMode;
 NTSTATUS Status;
 PBL_DISPLAY_MODE DisplayMode;
-ULONG GraphicsResolution;
+//ULONG GraphicsResolution;
 PVOID GraphicsConsole;
-PVOID RemoteConsole;
+   // PVOID RemoteConsole;
 PBL_TEXT_CONSOLE TextConsole;
 
 /* Initialize font data */
@@ -887,7 +889,7 @@
 BcdLibraryInteger_GraphicsResolution,
 );
 #else
-GraphicsResolution = 0;
+//GraphicsResolution = 0;
 Status = STATUS_NOT_FOUND;
 #endif
 if (NT_SUCCESS(Status))
@@ -902,7 +904,7 @@
 
BcdLibraryBoolean_GraphicsForceHighestMode,
 );
 #else
-HighestMode = 0;
+//HighestMode = 0;
 Status = STATUS_NOT_FOUND;
 #endif
 if (NT_SUCCESS(Status))
@@ -952,7 +954,7 @@
 DspGraphicalConsole = NULL;
 
 /* If we don't have a text console, go get a remote console */
-RemoteConsole = NULL;
+//RemoteConsole = NULL;
 if (!TextConsole)
 {
 EarlyPrint(L"Display path not handled\n");




[ros-diffs] [ion] 69068: [BOOTMGFW]: - Add heap implementation, continuing from my work last year. Seems to be pretty broken, next steps are fixing it. - Implement block allocator initialization (need

2015-09-06 Thread ion
Author: ion
Date: Sun Sep  6 19:56:47 2015
New Revision: 69068

URL: http://svn.reactos.org/svn/reactos?rev=69068=rev
Log:
[BOOTMGFW]:
- Add heap implementation, continuing from my work last year. Seems to be 
pretty broken, next steps are fixing it.
- Implement block allocator initialization (needs heap).
- Implement a few other missing initialization paths.

Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/mm/blkalloc.c
trunk/reactos/boot/environ/lib/mm/heapalloc.c
trunk/reactos/boot/environ/lib/mm/i386/mmx86.c
trunk/reactos/boot/environ/lib/mm/mm.c

Modified: trunk/reactos/boot/environ/include/bl.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?rev=69068=69067=69068=diff
==
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Sun Sep  6 
19:56:47 2015
@@ -75,6 +75,7 @@
 
 #define BL_LIBRARY_FLAG_REINITIALIZE0x02
 #define BL_LIBRARY_FLAG_REINITIALIZE_ALL0x04
+#define BL_LIBRARY_FLAG_ZERO_HEAP_ALLOCATIONS_ON_FREE   0x10
 #define BL_LIBRARY_FLAG_INITIALIZATION_COMPLETED0x20
 
 #define BL_MEMORY_CLASS_SHIFT   28
@@ -481,43 +482,6 @@
 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
 );
 
-/* FIRMWARE ROUTINES */
-
-NTSTATUS
-EfiAllocatePages (
-_In_ ULONG Type,
-_In_ ULONG Pages,
-_Inout_ EFI_PHYSICAL_ADDRESS* Memory
-);
-
-/* UTILITY ROUTINES **/
-
-EFI_STATUS
-EfiGetEfiStatusCode(
-_In_ NTSTATUS Status
-);
-
-NTSTATUS
-EfiGetNtStatusCode (
-_In_ EFI_STATUS EfiStatus
-);
-
-/* BCD ROUTINES **/
-
-ULONG
-BlGetBootOptionSize (
-_In_ PBL_BCD_OPTION BcdOption
-);
-
-/* CONTEXT ROUTINES **/
-
-VOID
-BlpArchSwitchContext (
-_In_ BL_ARCH_MODE NewMode
-);
-
-/* MEMORY MANAGER ROUTINES ***/
-
 NTSTATUS
 MmBaInitialize (
 VOID
@@ -549,11 +513,42 @@
 _In_ PBL_LIBRARY_PARAMETERS LibraryParameters
 );
 
-NTSTATUS
-MmFwGetMemoryMap (
-_Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap,
-_In_ ULONG Flags
-);
+/* FIRMWARE ROUTINES */
+
+NTSTATUS
+EfiAllocatePages (
+_In_ ULONG Type,
+_In_ ULONG Pages,
+_Inout_ EFI_PHYSICAL_ADDRESS* Memory
+);
+
+/* UTILITY ROUTINES **/
+
+EFI_STATUS
+EfiGetEfiStatusCode(
+_In_ NTSTATUS Status
+);
+
+NTSTATUS
+EfiGetNtStatusCode (
+_In_ EFI_STATUS EfiStatus
+);
+
+/* BCD ROUTINES **/
+
+ULONG
+BlGetBootOptionSize (
+_In_ PBL_BCD_OPTION BcdOption
+);
+
+/* CONTEXT ROUTINES **/
+
+VOID
+BlpArchSwitchContext (
+_In_ BL_ARCH_MODE NewMode
+);
+
+/* MEMORY DESCRIPTOR ROUTINES /
 
 VOID
 MmMdFreeList(
@@ -614,6 +609,8 @@
 _In_ PBL_MEMORY_DESCRIPTOR MemoryDescriptor
 );
 
+/* PAGE ALLOCATOR ROUTINES ***/
+
 NTSTATUS
 MmPapAllocatePagesInRange (
 _Inout_ PULONG PhysicalAddress,
@@ -625,6 +622,19 @@
 _In_ ULONG Type
 );
 
+NTSTATUS
+MmFwGetMemoryMap (
+_Out_ PBL_MEMORY_DESCRIPTOR_LIST MemoryMap,
+_In_ ULONG Flags
+);
+
+/* HEAP ALLOCATOR ROUTINES ***/
+
+PVOID
+BlMmAllocateHeap (
+_In_ ULONG Size
+);
+
 extern ULONG MmDescriptorCallTreeCount;
 extern ULONG BlpApplicationFlags;
 extern BL_LIBRARY_PARAMETERS BlpLibraryParameters;

Modified: trunk/reactos/boot/environ/lib/mm/blkalloc.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/mm/blkalloc.c?rev=69068=69067=69068=diff
==
--- trunk/reactos/boot/environ/lib/mm/blkalloc.c[iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/mm/blkalloc.c[iso-8859-1] Sun Sep  6 
19:56:47 2015
@@ -12,6 +12,15 @@
 
 /* DATA VARIABLES /
 
+PVOID MmBlockAllocatorTable;
+ULONG MmBlockAllocatorTableEntries;
+BOOLEAN MmBlockAllocatorInitialized;
+
+typedef struct _BL_BLOCK_DESCRIPTOR
+{
+LIST_ENTRY NextEntry;
+UCHAR Unknown[50 - sizeof(LIST_ENTRY)];
+} BL_BLOCK_DESCRIPTOR, *PBL_BLOCK_DESCRIPTOR;
 
 /* FUNCTIONS */
 
@@ -20,5 +29,27 @@
 VOID
 )
 {
-return STATUS_NOT_IMPLEMENTED;
+NTSTATUS Status;
+ULONG Size

  1   2   3   4   5   6   >