Author: tkreuzer
Date: Sun Mar 24 17:09:03 2013
New Revision: 58606
URL:
http://svn.reactos.org/svn/reactos?rev=58606&view=rev
Log:
[FREELDR]
- Set bugcheck data when the image is corrupt
- Add 2 more useful debug constants: DEBUG_WARN and DEBUG_ERR
- Use COM2 for debug output when _WINKD_ is defined
- Fix amd64 boot
Modified:
trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c
trunk/reactos/boot/freeldr/freeldr/debug.c
trunk/reactos/boot/freeldr/freeldr/include/mm.h
trunk/reactos/boot/freeldr/freeldr/mm/meminit.c
Modified: trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/arch/…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/arch/amd64/winldr.c [iso-8859-1] Sun Mar 24
17:09:03 2013
@@ -269,6 +269,7 @@
{
PKGDTENTRY64 Entry;
KDESCRIPTOR GdtDesc;
+ TRACE("Amd64SetupGdt(GdtBase = %p, TssBase = %p)\n", GdtBase, TssBase);
/* Setup KGDT64_NULL */
Entry = KiGetGdtEntry(GdtBase, KGDT64_NULL);
@@ -308,20 +309,22 @@
/* Set the new Gdt */
__lgdt(&GdtDesc.Limit);
- TRACE("Gdtr.Base = %p, num = %ld\n", GdtDesc.Base, NUM_GDT);
-
+ TRACE("Leave Amd64SetupGdt()\n");
}
VOID
Amd64SetupIdt(PVOID IdtBase)
{
KDESCRIPTOR IdtDesc, OldIdt;
+ ULONG Size;
+ TRACE("Amd64SetupIdt(IdtBase = %p)\n", IdtBase);
/* Get old IDT */
- __sidt(&OldIdt);
+ __sidt(&OldIdt.Limit);
/* Copy the old IDT */
- RtlCopyMemory(IdtBase, (PVOID)OldIdt.Base, OldIdt.Limit + 1);
+ Size = min(OldIdt.Limit + 1, NUM_IDT * sizeof(KIDTENTRY));
+ //RtlCopyMemory(IdtBase, (PVOID)OldIdt.Base, Size);
/* Setup the new IDT descriptor */
IdtDesc.Base = IdtBase;
@@ -329,8 +332,7 @@
/* Set the new IDT */
__lidt(&IdtDesc.Limit);
- TRACE("Idtr.Base = %p\n", IdtDesc.Base);
-
+ TRACE("Leave Amd64SetupIdt()\n");
}
VOID
@@ -354,7 +356,7 @@
Amd64SetupGdt(GdtIdt, KSEG0_BASE | (TssBasePage << MM_PAGE_SHIFT));
/* Copy old Idt and set idtr */
- Amd64SetupIdt((PVOID)((ULONG64)GdtIdt + 2048)); // HACK!
+ Amd64SetupIdt((PVOID)((ULONG64)GdtIdt + NUM_GDT * sizeof(KGDTENTRY)));
/* LDT is unused */
// __lldt(0);
@@ -390,7 +392,7 @@
TssBasePage = Tss >> MM_PAGE_SHIFT;
/* Allocate space for new GDT + IDT */
- BlockSize = NUM_GDT*sizeof(KGDTENTRY) + NUM_IDT*sizeof(KIDTENTRY);//FIXME: Use GDT/IDT
limits here?
+ BlockSize = NUM_GDT * sizeof(KGDTENTRY) + NUM_IDT * sizeof(KIDTENTRY);
NumPages = (BlockSize + MM_PAGE_SIZE - 1) >> MM_PAGE_SHIFT;
GdtIdt = (PKGDTENTRY)MmAllocateMemoryWithType(NumPages * MM_PAGE_SIZE,
LoaderMemoryData);
if (GdtIdt == NULL)
Modified: trunk/reactos/boot/freeldr/freeldr/debug.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/debug…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/debug.c [iso-8859-1] Sun Mar 24 17:09:03 2013
@@ -24,6 +24,8 @@
#if DBG && !defined(_M_ARM)
//#define DEBUG_ALL
+//#define DEBUG_WARN
+//#define DEBUG_ERR
//#define DEBUG_INIFILE
//#define DEBUG_REACTOS
//#define DEBUG_CUSTOM
@@ -49,7 +51,12 @@
//ULONG DebugPort = SCREEN;
//ULONG DebugPort = BOCHS;
//ULONG DebugPort = SCREEN|BOCHS;
+#ifdef _WINKD_
+/* COM1 is the WinDbg port */
+ULONG ComPort = COM2;
+#else
ULONG ComPort = COM1;
+#endif
//ULONG BaudRate = 19200;
ULONG BaudRate = 115200;
@@ -59,6 +66,10 @@
{
#if defined (DEBUG_ALL)
memset(DbgChannels, MAX_LEVEL, DBG_CHANNELS_COUNT);
+#elif defined (DEBUG_WARN)
+ memset(DbgChannels, WARN_LEVEL|FIXME_LEVEL|ERR_LEVEL, DBG_CHANNELS_COUNT);
+#elif defined (DEBUG_ERR)
+ memset(DbgChannels, ERR_LEVEL, DBG_CHANNELS_COUNT);
#else
memset(DbgChannels, 0, DBG_CHANNELS_COUNT);
#endif
Modified: trunk/reactos/boot/freeldr/freeldr/include/mm.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/inclu…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/include/mm.h [iso-8859-1] Sun Mar 24 17:09:03 2013
@@ -23,7 +23,12 @@
#ifdef __GNUC__
#define FREELDR_SECTION_COUNT 3
#else
+#ifdef _M_AMD64
+/* .text and .pdata */
+#define FREELDR_SECTION_COUNT 2
+#else
#define FREELDR_SECTION_COUNT 1
+#endif
#endif
typedef struct _FREELDR_MEMORY_DESCRIPTOR
Modified: trunk/reactos/boot/freeldr/freeldr/mm/meminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/freeldr/freeldr/mm/me…
==============================================================================
--- trunk/reactos/boot/freeldr/freeldr/mm/meminit.c [iso-8859-1] (original)
+++ trunk/reactos/boot/freeldr/freeldr/mm/meminit.c [iso-8859-1] Sun Mar 24 17:09:03 2013
@@ -174,7 +174,7 @@
NtHeaders = RtlImageNtHeader(&__ImageBase);
if (!NtHeaders)
{
- ERR("Coult not get NtHeaders!\n");
+ ERR("Could not get NtHeaders!\n");
return FALSE;
}
@@ -184,8 +184,14 @@
(FileHeader->NumberOfSections != FREELDR_SECTION_COUNT) ||
(FileHeader->PointerToSymbolTable != 0) ||
(FileHeader->NumberOfSymbols != 0) ||
- (FileHeader->SizeOfOptionalHeader != 0xE0))
- {
+ (FileHeader->SizeOfOptionalHeader != sizeof(IMAGE_OPTIONAL_HEADER)))
+ {
+ ERR("FreeLdr FileHeader is invalid.\n");
+ BugCheckInfo[0] = FileHeader->Machine;
+ BugCheckInfo[1] = FileHeader->NumberOfSections;
+ BugCheckInfo[2] = FileHeader->PointerToSymbolTable;
+ BugCheckInfo[3] = FileHeader->NumberOfSymbols;
+ BugCheckInfo[4] = FileHeader->SizeOfOptionalHeader;
return FALSE;
}
@@ -197,6 +203,12 @@
(OptionalHeader->SizeOfImage > MAX_FREELDR_PE_SIZE) ||
(OptionalHeader->SectionAlignment != OptionalHeader->FileAlignment))
{
+ ERR("FreeLdr OptionalHeader is invalid.\n");
+ BugCheckInfo[0] = 0x80000000 | (OptionalHeader->Subsystem << 16) |
OptionalHeader->Magic;
+ BugCheckInfo[1] = OptionalHeader->ImageBase;
+ BugCheckInfo[2] = OptionalHeader->SizeOfImage;
+ BugCheckInfo[3] = OptionalHeader->SectionAlignment;
+ BugCheckInfo[4] = OptionalHeader->FileAlignment;
return FALSE;
}