* FILE: ntoskrnl/ex/init.c
* PURPOSE: Executive Initialization Code
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
- * Eric Kohl (ekohl@rz-online.de)
+ * Eric Kohl
*/
/* INCLUDES ******************************************************************/
#include <ntoskrnl.h>
#define NDEBUG
#include <debug.h>
-#include "ntstrsafe.h"
+
+/* Temporary hack */
+BOOLEAN
+NTAPI
+MmArmInitSystem(
+ IN ULONG Phase,
+ IN PLOADER_PARAMETER_BLOCK LoaderBlock
+);
typedef struct _INIT_BUFFER
{
#endif
/* NT System Info */
-ULONG NtGlobalFlag;
+ULONG NtGlobalFlag = 0;
ULONG ExSuiteMask;
/* Cm Version Info */
NTSTATUS
NTAPI
+INIT_FUNCTION
ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
UNICODE_STRING LinkName;
VOID
NTAPI
+INIT_FUNCTION
ExpInitNls(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
LARGE_INTEGER SectionSize;
KernelMode,
&ExpNlsSectionPointer,
NULL);
- ZwClose(NlsSection);
+ ObCloseHandle(NlsSection, KernelMode);
if (!NT_SUCCESS(Status))
{
/* Failed */
}
/* Copy the codepage data in its new location. */
+ ASSERT(SectionBase > MmSystemRangeStart);
RtlCopyMemory(SectionBase, ExpNlsTableBase, ExpNlsTableSize);
/* Free the previously allocated buffer and set the new location */
VOID
NTAPI
+INIT_FUNCTION
ExpLoadInitialProcess(IN PINIT_BUFFER InitBuffer,
OUT PRTL_USER_PROCESS_PARAMETERS *ProcessParameters,
OUT PCHAR *ProcessEnvironment)
ULONG
NTAPI
+INIT_FUNCTION
ExComputeTickCountMultiplier(IN ULONG ClockIncrement)
{
ULONG MsRemainder = 0, MsIncrement;
BOOLEAN
NTAPI
+INIT_FUNCTION
ExpInitSystemPhase0(VOID)
{
/* Initialize EXRESOURCE Support */
BOOLEAN
NTAPI
+INIT_FUNCTION
ExpInitSystemPhase1(VOID)
{
/* Initialize worker threads */
BOOLEAN
NTAPI
+INIT_FUNCTION
ExInitSystem(VOID)
{
/* Check the initialization phase */
BOOLEAN
NTAPI
+INIT_FUNCTION
ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PLOADER_PARAMETER_EXTENSION Extension;
VOID
NTAPI
+INIT_FUNCTION
ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
ULONG i = 0;
VOID
NTAPI
+INIT_FUNCTION
+ExBurnMemory(IN PLOADER_PARAMETER_BLOCK LoaderBlock,
+ IN ULONG PagesToDestroy,
+ IN TYPE_OF_MEMORY MemoryType)
+{
+ PLIST_ENTRY ListEntry;
+ PMEMORY_ALLOCATION_DESCRIPTOR MemDescriptor;
+
+ DPRINT1("Burn RAM amount: %d pages\n", PagesToDestroy);
+
+ /* Loop the memory descriptors, beginning at the end */
+ for (ListEntry = LoaderBlock->MemoryDescriptorListHead.Blink;
+ ListEntry != &LoaderBlock->MemoryDescriptorListHead;
+ ListEntry = ListEntry->Blink)
+ {
+ /* Get the memory descriptor structure */
+ MemDescriptor = CONTAINING_RECORD(ListEntry,
+ MEMORY_ALLOCATION_DESCRIPTOR,
+ ListEntry);
+
+ /* Is memory free there or is it temporary? */
+ if (MemDescriptor->MemoryType == LoaderFree ||
+ MemDescriptor->MemoryType == LoaderFirmwareTemporary)
+ {
+ /* Check if the descriptor has more pages than we want */
+ if (MemDescriptor->PageCount > PagesToDestroy)
+ {
+ /* Change block's page count, ntoskrnl doesn't care much */
+ MemDescriptor->PageCount -= PagesToDestroy;
+ break;
+ }
+ else
+ {
+ /* Change block type */
+ MemDescriptor->MemoryType = MemoryType;
+ PagesToDestroy -= MemDescriptor->PageCount;
+
+ /* Check if we are done */
+ if (PagesToDestroy == 0) break;
+ }
+ }
+ }
+}
+
+VOID
+NTAPI
+INIT_FUNCTION
ExpInitializeExecutive(IN ULONG Cpu,
IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
PCHAR CommandLine, PerfMem;
ULONG PerfMemUsed;
PLDR_DATA_TABLE_ENTRY NtosEntry;
- PRTL_MESSAGE_RESOURCE_ENTRY MsgEntry;
+ PMESSAGE_RESOURCE_ENTRY MsgEntry;
ANSI_STRING CsdString;
- SIZE_T Remaining = 0;
+ size_t Remaining = 0;
PCHAR RcEnd = NULL;
CHAR VersionBuffer [65];
{
/* Read the number of pages we'll use */
PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
- if (PerfMem)
- {
- /* FIXME: TODO */
- DPRINT1("Burnable memory support not yet present."
- "/BURNMEM option ignored.\n");
- }
+ if (PerfMemUsed) ExBurnMemory(LoaderBlock, PerfMemUsed, LoaderBad);
}
}
}
}
/* Make sure interrupts are active now */
-// FIXME HAX!!!
- //_enable();
+ _enable();
/* Clear the crypto exponent */
SharedUserData->CryptoExponent = 0;
if (CmNtCSDReleaseType == 1) CmNtSpBuildNumber |= 1830 << 16;
}
+ /* Add loaded CmNtGlobalFlag value */
+ NtGlobalFlag |= CmNtGlobalFlag;
+
/* Initialize the executive at phase 0 */
if (!ExInitSystem()) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Initialize the memory manager at phase 0 */
- if (!MmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
+ if (!MmArmInitSystem(0, LoaderBlock)) KeBugCheck(PHASE0_INITIALIZATION_FAILED);
/* Load boot symbols */
ExpLoadBootSymbols(LoaderBlock);
if (NT_SUCCESS(Status))
{
/* Setup the string */
- RtlInitAnsiString(&CsdString, MsgEntry->Text);
+ RtlInitAnsiString(&CsdString, (PCHAR)MsgEntry->Text);
/* Remove trailing newline */
while ((CsdString.Length > 0) &&
SharedUserData->NtMinorVersion = NtMinorVersion;
/* Set the machine type */
- SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_ARCHITECTURE;
- SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_ARCHITECTURE;
+ SharedUserData->ImageNumberLow = IMAGE_FILE_MACHINE_NATIVE;
+ SharedUserData->ImageNumberHigh = IMAGE_FILE_MACHINE_NATIVE;
}
VOID
NTAPI
+INIT_FUNCTION
Phase1InitializationDiscard(IN PVOID Context)
{
PLOADER_PARAMETER_BLOCK LoaderBlock = Context;
LARGE_INTEGER SystemBootTime, UniversalBootTime, OldTime, Timeout;
BOOLEAN SosEnabled, NoGuiBoot, ResetBias = FALSE, AlternateShell = FALSE;
PLDR_DATA_TABLE_ENTRY NtosEntry;
- PRTL_MESSAGE_RESOURCE_ENTRY MsgEntry;
+ PMESSAGE_RESOURCE_ENTRY MsgEntry;
PCHAR CommandLine, Y2KHackRequired, SafeBoot, Environment;
PCHAR StringBuffer, EndBuffer, BeginBuffer, MpString = "";
PINIT_BUFFER InitBuffer;
ANSI_STRING TempString;
- ULONG LastTzBias, Size, YearHack = 0, Disposition, MessageCode = 0;
- SIZE_T Length;
+ ULONG LastTzBias, Length, YearHack = 0, Disposition, MessageCode = 0;
+ SIZE_T Size;
+ size_t Remaining;
PRTL_USER_PROCESS_INFORMATION ProcessInfo;
KEY_VALUE_PARTIAL_INFORMATION KeyPartialInfo;
UNICODE_STRING KeyName, DebugString;
StringBuffer = InitBuffer->VersionBuffer;
BeginBuffer = StringBuffer;
EndBuffer = StringBuffer;
- Length = 256;
+ Remaining = sizeof(InitBuffer->VersionBuffer);
if (CmCSDVersionString.Length)
{
/* Print the version string */
Status = RtlStringCbPrintfExA(StringBuffer,
- 255,
+ Remaining,
&EndBuffer,
- &Length,
+ &Remaining,
0,
": %wZ",
&CmCSDVersionString);
else
{
/* No version */
- Length = 255;
+ *EndBuffer++ = ANSI_NULL; /* Null-terminate the string */
+ --Remaining;
}
- /* Null-terminate the string */
- *EndBuffer++ = ANSI_NULL;
-
/* Build the version number */
StringBuffer = InitBuffer->VersionNumber;
Status = RtlStringCbPrintfA(StringBuffer,
- 24,
+ sizeof(InitBuffer->VersionNumber),
"%u.%u",
VER_PRODUCTMAJORVERSION,
VER_PRODUCTMINORVERSION);
{
/* Create the banner message */
Status = RtlStringCbPrintfA(EndBuffer,
- Length,
- MsgEntry->Text,
+ Remaining,
+ (PCHAR)MsgEntry->Text,
StringBuffer,
NtBuildNumber & 0xFFFF,
BeginBuffer);
else
{
/* Use hard-coded banner message */
- Status = RtlStringCbCopyA(EndBuffer, Length, "REACTOS (R)\n");
+ Status = RtlStringCbCopyA(EndBuffer, Remaining, "REACTOS (R)\n");
if (!NT_SUCCESS(Status))
{
/* Bugcheck */
/* Create the string */
StringBuffer = InitBuffer->VersionBuffer;
Status = RtlStringCbPrintfA(StringBuffer,
- 256,
+ sizeof(InitBuffer->VersionBuffer),
NT_SUCCESS(MsgStatus) ?
- MsgEntry->Text :
+ (PCHAR)MsgEntry->Text :
"%u System Processor [%u MB Memory] %Z\n",
KeNumberProcessors,
Size,
if (!MmInitSystem(1, LoaderBlock)) KeBugCheck(MEMORY1_INITIALIZATION_FAILED);
/* Create NLS section */
- ExpInitNls(KeLoaderBlock);
+ ExpInitNls(LoaderBlock);
/* Initialize Cache Views */
if (!CcInitializeCacheManager()) KeBugCheck(CACHE_INITIALIZATION_FAILED);
else if (!strncmp(SafeBoot, "NETWORK", 7))
{
/* With Networking */
- InitSafeBootMode = 1;
+ InitSafeBootMode = 2;
SafeBoot += 7;
MessageCode = BOOTING_IN_SAFEMODE_NETWORK;
}
if (NT_SUCCESS(Status))
{
/* Display it */
- InbvDisplayString(MsgEntry->Text);
+ InbvDisplayString((PCHAR)MsgEntry->Text);
}
}
}
if (NT_SUCCESS(Status))
{
/* Display it */
- InbvDisplayString(MsgEntry->Text);
+ InbvDisplayString((PCHAR)MsgEntry->Text);
}
/* Setup boot logging */
KeyValuePartialInformation,
&KeyPartialInfo,
sizeof(KeyPartialInfo),
- &Size);
+ &Length);
if (!NT_SUCCESS(Status)) AlternateShell = FALSE;
}
NtClose(OptionHandle);
}
- /* Unmap Low memory, and initialize the MPW and Balancer Thread */
- MmInitSystem(2, LoaderBlock);
+ /* FIXME: This doesn't do anything for now */
+ MmArmInitSystem(2, LoaderBlock);
/* Update progress bar */
InbvUpdateProgressBar(80);
InbvUpdateProgressBar(90);
/* Launch initial process */
+ DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
ProcessInfo = &InitBuffer->ProcessInfo;
ExpLoadInitialProcess(InitBuffer, &ProcessParameters, &Environment);
ZwClose(ProcessInfo->ProcessHandle);
/* Free the initial process environment */
- Length = 0;
+ Size = 0;
ZwFreeVirtualMemory(NtCurrentProcess(),
(PVOID*)&Environment,
- &Length,
+ &Size,
MEM_RELEASE);
/* Free the initial process parameters */
- Length = 0;
+ Size = 0;
ZwFreeVirtualMemory(NtCurrentProcess(),
(PVOID*)&ProcessParameters,
- &Length,
+ &Size,
MEM_RELEASE);
/* Increase init phase */
/* Free the boot buffer */
ExFreePool(InitBuffer);
+ DPRINT1("Free non-cache pages: %lx\n", MmAvailablePages + MiMemoryConsumers[MC_CACHE].PagesUsed);
}
VOID
Phase1InitializationDiscard(Context);
/* Jump into zero page thread */
- MmZeroPageThreadMain(NULL);
+ MmZeroPageThread();
}