- Fix ExInitPoolLookasidePointers and ExpInitailizeLookasideLists.

- Implement DbgLoadImageSymbols, Implement DebugService, and ExpLoadBootSymbols during phase 0 executive init to make KD load the symbols for all the boot drivers, and optionally breakpoint. Not yet useful since we don't have KD.
- Detect /BURNMEM and /PERFMEM and go all the way to determining the pages required, but warn the user that we don't support these flags yet.
- Detect FLG_KERNEL_STACK_TRACE_DB and FLG_ENABLE_EXCEPTION_LOGGING and warn that we don't support these yet.
- Add call to Cm to setup system variables, but disable until cm rewrite.
- Add PnP Manager initialization call and implement PnP Manager Phase 0 initialization (PiInitPhase0, PpInitializeDeviceReferenceTable), but this isn't used for now.
- Move MmInit2 to Phase 1 initialization, and initailize bootvid there as well.
- Add/Fix missing definitions, prototypes to NDK/NTIFS.

svn path=/trunk/; revision=25621
This commit is contained in:
Alex Ionescu 2007-01-24 19:48:34 +00:00
parent 0e1ec5f828
commit c307d73c12
13 changed files with 380 additions and 37 deletions

View file

@ -1534,6 +1534,16 @@ typedef struct _RTL_AVL_TABLE
PVOID TableContext;
} RTL_AVL_TABLE, *PRTL_AVL_TABLE;
NTSYSAPI
VOID
NTAPI
RtlInitializeGenericTableAvl(
PRTL_AVL_TABLE Table,
PRTL_AVL_COMPARE_ROUTINE CompareRoutine,
PRTL_AVL_ALLOCATE_ROUTINE AllocateRoutine,
PRTL_AVL_FREE_ROUTINE FreeRoutine,
PVOID TableContext
);
#if defined(USE_LPC6432)
#define LPC_CLIENT_ID CLIENT_ID64

View file

@ -161,4 +161,15 @@ typedef struct _SYSDBG_TRIAGE_DUMP
PHANDLE Handles;
} SYSDBG_TRIAGE_DUMP, *PSYSDBG_TRIAGE_DUMP;
//
// KD Structures
//
typedef struct _KD_SYMBOLS_INFO
{
PVOID BaseOfDll;
PVOID ProcessId;
ULONG CheckSum;
ULONG SizeOfImage;
} KD_SYMBOLS_INFO, *PKD_SYMBOLS_INFO;
#endif // _KDTYPES_H

View file

@ -2502,7 +2502,17 @@ DbgPrompt(
VOID
NTAPI
DbgBreakPoint(VOID);
DbgBreakPoint(
VOID
);
NTSTATUS
NTAPI
DbgLoadImageSymbols(
IN PANSI_STRING Name,
IN PVOID Base,
IN ULONG ProcessId
);
//
// Generic Table Functions

View file

@ -315,15 +315,37 @@ DbgSetDebugFilterState(IN ULONG ComponentId,
}
/*
* @unimplemented
* @implemented
*/
NTSTATUS
NTAPI
DbgLoadImageSymbols(IN PUNICODE_STRING Name,
IN ULONG Base,
IN ULONG Unknown3)
DbgLoadImageSymbols(IN PANSI_STRING Name,
IN PVOID Base,
IN ULONG ProcessId)
{
UNIMPLEMENTED;
return STATUS_NOT_IMPLEMENTED;
PIMAGE_NT_HEADERS NtHeader;
KD_SYMBOLS_INFO SymbolInfo;
/* Setup the symbol data */
SymbolInfo.BaseOfDll = Base;
SymbolInfo.ProcessId = UlongToPtr(ProcessId);
/* Get NT Headers */
NtHeader = NULL; //RtlImageNtHeader(Base);
if (NtHeader)
{
/* Get the rest of the data */
SymbolInfo.CheckSum = NtHeader->OptionalHeader.CheckSum;
SymbolInfo.SizeOfImage = NtHeader->OptionalHeader.SizeOfImage;
}
else
{
/* No data available */
SymbolInfo.CheckSum = SymbolInfo.SizeOfImage = 0;
}
/* Load the symbols */
DebugService2(Name, &SymbolInfo, BREAKPOINT_LOAD_SYMBOLS);
return STATUS_SUCCESS;
}
/* EOF */

View file

@ -14,6 +14,7 @@
.globl _DbgBreakPointWithStatus@4
.globl _DbgUserBreakPoint@0
.globl _DebugService@20
.globl _DebugService2@12
.globl _DbgBreakPointNoBugCheck@0
/* FUNCTIONS ***************************************************************/
@ -38,6 +39,25 @@ _DbgBreakPointWithStatus@4:
ret 4
.endfunc
.func DebugService2@12
_DebugService2@12:
/* Setup the stack */
push ebp
mov ebp, esp
/* Call the interrupt */
mov eax, [ebp+16]
mov ecx, [ebp+8]
mov edx, [ebp+12]
int 0x2D
int 3
/* Restore stack */
pop ebp
ret 12
.endfunc
.func DebugService@20
_DebugService@20:

View file

@ -135,6 +135,12 @@ DebugService(IN ULONG Service,
IN PVOID Argument1,
IN PVOID Argument2);
NTSTATUS
NTAPI
DebugService2(IN PVOID Argument1,
IN PVOID Argument2,
IN ULONG Service);
/* Tags for the String Allocators */
#define TAG_USTR TAG('U', 'S', 'T', 'R')
#define TAG_ASTR TAG('A', 'S', 'T', 'R')

View file

@ -82,6 +82,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
/* Failed */
KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 1, 0, 0);
}
@ -102,6 +103,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
&ObjectAttributes);
if (!NT_SUCCESS(Status))
{
/* Failed */
KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 2, 0, 0);
}
@ -113,6 +115,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
Status = RtlAnsiStringToUnicodeString(&LinkName, &AnsiName, TRUE);
if (!NT_SUCCESS(Status))
{
/* Failed */
KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 3, 0, 0);
}
@ -154,6 +157,7 @@ ExpCreateSystemRootLink(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
/* Check if creating the link failed */
if (!NT_SUCCESS(Status))
{
/* Failed */
KeBugCheckEx(SYMBOLIC_INITIALIZATION_FAILED, Status, 5, 0, 0);
}
@ -667,6 +671,97 @@ ExpIsLoaderValid(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
return TRUE;
}
VOID
NTAPI
ExpLoadBootSymbols(IN PLOADER_PARAMETER_BLOCK LoaderBlock)
{
ULONG i = 0;
PLIST_ENTRY NextEntry;
ULONG Count, Length;
PWCHAR Name;
PLDR_DATA_TABLE_ENTRY LdrEntry;
BOOLEAN OverFlow = FALSE;
CHAR NameBuffer[256];
ANSI_STRING SymbolString;
/* Loop the driver list */
NextEntry = LoaderBlock->LoadOrderListHead.Flink;
while (NextEntry != &LoaderBlock->LoadOrderListHead)
{
/* Skip the first two images */
if (i >= 2)
{
/* Get the entry */
LdrEntry = CONTAINING_RECORD(NextEntry,
LDR_DATA_TABLE_ENTRY,
InLoadOrderLinks);
if (LdrEntry->FullDllName.Buffer[0] == L'\\')
{
/* We have a name, read its data */
Name = LdrEntry->FullDllName.Buffer;
Length = LdrEntry->FullDllName.Length / sizeof(WCHAR);
/* Check if our buffer can hold it */
if (sizeof(NameBuffer) < Length + sizeof(ANSI_NULL))
{
/* It's too long */
OverFlow = TRUE;
}
else
{
/* Copy the name */
for (Count = 0; Count < Length; Count++, Name++)
{
/* Copy the character */
NameBuffer[Count] = (CHAR)*Name;
}
/* Null-terminate */
NameBuffer[Count] = ANSI_NULL;
}
}
else
{
/* This should be a driver, check if it fits */
if (sizeof(NameBuffer) <
(sizeof("\\System32\\Drivers\\") +
NtSystemRoot.Length / sizeof(WCHAR) - sizeof(UNICODE_NULL) +
LdrEntry->BaseDllName.Length / sizeof(WCHAR) +
sizeof(ANSI_NULL)))
{
/* Buffer too small */
OverFlow = TRUE;
}
else
{
/* Otherwise build the name. HACKED for GCC :( */
sprintf(NameBuffer,
"%c\\System32\\Drivers\\%S",
SharedUserData->NtSystemRoot[2],
LdrEntry->BaseDllName.Buffer);
}
}
/* Check if the buffer was ok */
if (!OverFlow)
{
/* Initialize the ANSI_STRING for the debugger */
RtlInitString(&SymbolString, NameBuffer);
/* Load the symbols */
DbgLoadImageSymbols(&SymbolString, LdrEntry->DllBase, -1);
}
}
/* Go to the next entry */
i++;
NextEntry = NextEntry->Flink;
}
/* Check if we should break after symbol load */
if (KdBreakAfterSymbolLoad) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
}
VOID
NTAPI
ExpInitializeExecutive(IN ULONG Cpu,
@ -676,6 +771,8 @@ ExpInitializeExecutive(IN ULONG Cpu,
CHAR Buffer[256];
ANSI_STRING AnsiPath;
NTSTATUS Status;
PCHAR CommandLine, PerfMem;
ULONG PerfMemUsed;
/* Validate Loader */
if (!ExpIsLoaderValid(LoaderBlock))
@ -729,6 +826,50 @@ ExpInitializeExecutive(IN ULONG Cpu,
/* Set phase to 0 */
ExpInitializationPhase = 0;
/* Get boot command line */
CommandLine = LoaderBlock->LoadOptions;
if (CommandLine)
{
/* Upcase it for comparison and check if we're in performance mode */
_strupr(CommandLine);
PerfMem = strstr(CommandLine, "PERFMEM");
if (PerfMem)
{
/* Check if the user gave a number of bytes to use */
PerfMem = strstr(PerfMem, "=");
if (PerfMem)
{
/* Read the number of pages we'll use */
PerfMemUsed = atol(PerfMem + 1) * (1024 * 1024 / PAGE_SIZE);
if (PerfMem)
{
/* FIXME: TODO */
DPRINT1("BBT performance mode not yet supported."
"/PERFMEM option ignored.\n");
}
}
}
/* Check if we're burning memory */
PerfMem = strstr(CommandLine, "BURNMEMORY");
if (PerfMem)
{
/* Check if the user gave a number of bytes to use */
PerfMem = strstr(PerfMem, "=");
if (PerfMem)
{
/* 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");
}
}
}
}
/* Setup NLS Base and offsets */
NlsData = LoaderBlock->NlsData;
ExpNlsTableBase = NlsData->AnsiCodePageData;
@ -786,11 +927,14 @@ ExpInitializeExecutive(IN ULONG Cpu,
/* Setup bugcheck messages */
KiInitializeBugCheck();
/* Setup initial system settings (FIXME: Needs Cm Rewrite) */
//CmGetSystemControlValues(CommandLine, &CmControlVector);
/* Initialize the executive at phase 0 */
if (!ExInitSystem()) KEBUGCHECK(PHASE0_INITIALIZATION_FAILED);
/* Break into the Debugger if requested */
if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
/* Load boot symbols */
ExpLoadBootSymbols(LoaderBlock);
/* Set system ranges */
SharedUserData->Reserved1 = (ULONG_PTR)MmHighestUserAddress;
@ -799,6 +943,22 @@ ExpInitializeExecutive(IN ULONG Cpu,
/* Make a copy of the NLS Tables */
ExpInitNls(LoaderBlock);
/* Check if the user wants a kernel stack trace database */
if (NtGlobalFlag & FLG_KERNEL_STACK_TRACE_DB)
{
/* FIXME: TODO */
DPRINT1("Kernel-mode stack trace support not yet present."
"FLG_KERNEL_STACK_TRACE_DB flag ignored.\n");
}
/* Check if he wanted exception logging */
if (NtGlobalFlag & FLG_ENABLE_EXCEPTION_LOGGING)
{
/* FIXME: TODO */
DPRINT1("Kernel-mode exception logging support not yet present."
"FLG_ENABLE_EXCEPTION_LOGGING flag ignored.\n");
}
/* Initialize the Handle Table */
ExpInitializeHandleTables();
@ -827,15 +987,12 @@ ExpInitializeExecutive(IN ULONG Cpu,
/* Load basic Security for other Managers */
if (!SeInit()) KEBUGCHECK(SECURITY_INITIALIZATION_FAILED);
/* Set up Region Maps, Sections and the Paging File */
MmInit2();
/* Initialize the boot video. */
InbvDisplayInitialize();
/* Initialize the Process Manager */
if (!PsInitSystem()) KEBUGCHECK(PROCESS_INITIALIZATION_FAILED);
/* Initialize the PnP Manager */
if (!PpInitSystem()) KEBUGCHECK(PP0_INITIALIZATION_FAILED);
/* Initialize the User-Mode Debugging Subsystem */
DbgkInitialize();
@ -883,6 +1040,7 @@ ExPhase2Init(PVOID Context)
if (strstr(KeLoaderBlock->LoadOptions, "NOGUIBOOT")) NoGuiBoot = TRUE;
/* Display the boot screen image if not disabled */
InbvDisplayInitialize();
if (!ExpInTextModeSetup) InbvDisplayInitialize2(NoGuiBoot);
if (!NoGuiBoot) InbvDisplayBootLogo();
@ -890,6 +1048,9 @@ ExPhase2Init(PVOID Context)
if (NoGuiBoot) ExpDisplayNotice();
KdInitSystem(2, KeLoaderBlock);
/* Set up Region Maps, Sections and the Paging File */
MmInit2();
/* Initialize Power Subsystem in Phase 0 */
PoInit(0, AcpiTableDetected);

View file

@ -24,8 +24,8 @@ LIST_ENTRY ExpPagedLookasideListHead;
KSPIN_LOCK ExpPagedLookasideListLock;
LIST_ENTRY ExSystemLookasideListHead;
LIST_ENTRY ExPoolLookasideListHead;
NPAGED_LOOKASIDE_LIST ExpSmallNPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
PAGED_LOOKASIDE_LIST ExpSmallPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
GENERAL_LOOKASIDE ExpSmallNPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
GENERAL_LOOKASIDE ExpSmallPagedPoolLookasideLists[MAXIMUM_PROCESSORS];
/* PRIVATE FUNCTIONS *********************************************************/
@ -63,30 +63,27 @@ NTAPI
ExInitPoolLookasidePointers(VOID)
{
ULONG i;
PPP_LOOKASIDE_LIST Entry;
PNPAGED_LOOKASIDE_LIST ListEntry;
PPAGED_LOOKASIDE_LIST PagedListEntry;
PKPRCB Prcb = KeGetCurrentPrcb();
PGENERAL_LOOKASIDE Entry;
/* Loop for all CPUs */
/* Loop for all pool lists */
for (i = 0; i < MAXIMUM_PROCESSORS; i++)
{
/* Initialize the non-paged list */
ListEntry = &ExpSmallNPagedPoolLookasideLists[i];
InitializeSListHead(&ListEntry->L.ListHead);
Entry = &ExpSmallNPagedPoolLookasideLists[i];
InitializeSListHead(&Entry->ListHead);
/* Bind to PRCB */
Entry = &KeGetCurrentPrcb()->PPPagedLookasideList[i];
Entry->L = &ListEntry->L;
Entry->P = &ListEntry->L;
Prcb->PPNPagedLookasideList[i].P = Entry;
Prcb->PPNPagedLookasideList[i].L = Entry;
/* Initialize the paged list */
PagedListEntry = &ExpSmallPagedPoolLookasideLists[i];
InitializeSListHead(&PagedListEntry->L.ListHead);
Entry = &ExpSmallPagedPoolLookasideLists[i];
InitializeSListHead(&Entry->ListHead);
/* Bind to PRCB */
Entry = &KeGetCurrentPrcb()->PPNPagedLookasideList[i];
Entry->L = &PagedListEntry->L;
Entry->P = &PagedListEntry->L;
Prcb->PPPagedLookasideList[i].P = Entry;
Prcb->PPPagedLookasideList[i].L = Entry;
}
}
@ -94,7 +91,7 @@ VOID
NTAPI
ExpInitLookasideLists()
{
ULONG i, j;
ULONG i;
/* Initialize locks and lists */
InitializeListHead(&ExpNonPagedLookasideListHead);
@ -105,20 +102,20 @@ ExpInitLookasideLists()
KeInitializeSpinLock(&ExpPagedLookasideListLock);
/* Initialize the system lookaside lists */
for (i = 0, j = 1; i < (MAXIMUM_PROCESSORS - 1); j++, i++)
for (i = 0; i < MAXIMUM_PROCESSORS; i++)
{
/* Initialize the non-paged list */
ExInitializeSystemLookasideList(&ExpSmallNPagedPoolLookasideLists[i].L,
ExInitializeSystemLookasideList(&ExpSmallNPagedPoolLookasideLists[i],
NonPagedPool,
j * 8,
(i + 1) * 8,
TAG('P', 'o', 'o', 'l'),
256,
&ExPoolLookasideListHead);
/* Initialize the paged list */
ExInitializeSystemLookasideList(&ExpSmallPagedPoolLookasideLists[i].L,
ExInitializeSystemLookasideList(&ExpSmallPagedPoolLookasideLists[i],
PagedPool,
j * 8,
(i + 1) * 8,
TAG('P', 'o', 'o', 'l'),
256,
&ExPoolLookasideListHead);

View file

@ -441,6 +441,12 @@ PnpInit(
VOID
);
BOOLEAN
NTAPI
PpInitSystem(
VOID
);
VOID
PnpInit2(
VOID

View file

@ -15,6 +15,7 @@ struct _KD_DISPATCH_TABLE;
extern KD_PORT_INFORMATION GdbPortInfo;
extern BOOLEAN _KdDebuggerEnabled;
extern BOOLEAN _KdDebuggerNotPresent;
extern BOOLEAN KdBreakAfterSymbolLoad;
BOOLEAN
NTAPI

View file

@ -19,6 +19,11 @@
PDEVICE_NODE IopRootDeviceNode;
KSPIN_LOCK IopDeviceTreeLock;
ERESOURCE PpRegistryDeviceResource;
KGUARDED_MUTEX PpDeviceReferenceTableLock;
RTL_AVL_TABLE PpDeviceReferenceTable;
extern ULONG ExpInitializationPhase;
/* DATA **********************************************************************/
@ -3317,5 +3322,90 @@ PnpInit(VOID)
}
}
RTL_GENERIC_COMPARE_RESULTS
NTAPI
PiCompareInstancePath(IN PRTL_AVL_TABLE Table,
IN PVOID FirstStruct,
IN PVOID SecondStruct)
{
/* FIXME: TODO */
KEBUGCHECK(0);
return 0;
}
//
// The allocation function is called by the generic table package whenever
// it needs to allocate memory for the table.
//
PVOID
NTAPI
PiAllocateGenericTableEntry(IN PRTL_AVL_TABLE Table,
IN CLONG ByteSize)
{
/* FIXME: TODO */
KEBUGCHECK(0);
return NULL;
}
VOID
NTAPI
PiFreeGenericTableEntry(IN PRTL_AVL_TABLE Table,
IN PVOID Buffer)
{
/* FIXME: TODO */
KEBUGCHECK(0);
}
VOID
NTAPI
PpInitializeDeviceReferenceTable(VOID)
{
/* Setup the guarded mutex and AVL table */
KeInitializeGuardedMutex(&PpDeviceReferenceTableLock);
RtlInitializeGenericTableAvl(&PpDeviceReferenceTable,
PiCompareInstancePath,
PiAllocateGenericTableEntry,
PiFreeGenericTableEntry,
NULL);
}
BOOLEAN
NTAPI
PiInitPhase0(VOID)
{
/* Initialize the resource when accessing device registry data */
ExInitializeResourceLite(&PpRegistryDeviceResource);
/* Setup the device reference AVL table */
PpInitializeDeviceReferenceTable();
return TRUE;
}
BOOLEAN
NTAPI
PpInitSystem(VOID)
{
/* Check the initialization phase */
switch (ExpInitializationPhase)
{
case 0:
/* Do Phase 0 */
return PiInitPhase0();
case 1:
/* Do Phase 1 */
return FALSE;
//return PiInitPhase1();
default:
/* Don't know any other phase! Bugcheck! */
KeBugCheck(UNEXPECTED_INITIALIZATION_CALL);
return FALSE;
}
}
/* EOF */

View file

@ -17,6 +17,7 @@ BOOLEAN KdDebuggerEnabled = FALSE;
BOOLEAN KdEnteredDebugger = FALSE;
BOOLEAN KdDebuggerNotPresent = TRUE;
BOOLEAN KiEnableTimerWatchdog = FALSE;
BOOLEAN KdBreakAfterSymbolLoad = FALSE;
ULONG KiBugCheckData;
BOOLEAN KdpBreakPending;
VOID STDCALL PspDumpThreads(BOOLEAN SystemThreads);

View file

@ -1081,6 +1081,14 @@ Language=English
SPIN_LOCK_INIT_FAILURE
.
MessageId=0x8F
Severity=Success
Facility=System
SymbolicName=PP0_INITIALIZATION_FAILED
Language=English
PP0_INITIALIZATION_FAILED
.
MessageId=0x94
Severity=Success
Facility=System