Author: sserapion Date: Thu Dec 24 05:12:02 2009 New Revision: 44749
URL: http://svn.reactos.org/svn/reactos?rev=44749&view=rev Log: [ntoskrnl] - enable KdpEnableSafeMem for amd64 - unhack ExInitPoolLookasidePointers - hackplement KiInitializeContextThread - Remove extended eflag code from kdb, its useless. - Rewrite KdbpCmdGdtLdtIdt - Enable KdbpCmdTss - misc kdb fixes.
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ex/lookas.c branches/ros-amd64-bringup/reactos/ntoskrnl/kd/kdinit.c branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/kdb_cli.c branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/thrdini.c
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ex/lookas.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ex/lookas.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ex/lookas.c [iso-8859-1] Thu Dec 24 05:12:02 2009 @@ -72,24 +72,16 @@ InitializeSListHead(&Entry->ListHead);
/* Bind to PRCB */ -#ifdef _M_AMD64 - DPRINT1("Something is missing here, Prcb = %p\n", Prcb); - // FIXME -#else Prcb->PPNPagedLookasideList[i].P = Entry; Prcb->PPNPagedLookasideList[i].L = Entry; -#endif + /* Initialize the paged list */ Entry = &ExpSmallPagedPoolLookasideLists[i]; InitializeSListHead(&Entry->ListHead);
/* Bind to PRCB */ -#ifdef _M_AMD64 - // FIXME -#else Prcb->PPPagedLookasideList[i].P = Entry; Prcb->PPPagedLookasideList[i].L = Entry; -#endif } }
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/kd/kdinit.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/kd/kdinit.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/kd/kdinit.c [iso-8859-1] Thu Dec 24 05:12:02 2009 @@ -249,7 +249,7 @@ } else /* BootPhase > 0 */ { -#ifdef _M_IX86 +#if defined(_M_IX86) || defined(_M_AMD64) KdpEnableSafeMem(); #endif }
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/kdb_cli.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/kdbg/kdb_cli.c [iso-8859-1] Thu Dec 24 05:12:02 2009 @@ -602,21 +602,13 @@ { PKTRAP_FRAME Tf = &KdbCurrentTrapFrame->Tf; INT i; - const PCHAR EflagsBits[64] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5", + const PCHAR EflagsBits[32] = { " CF", NULL, " PF", " BIT3", " AF", " BIT5", " ZF", " SF", " TF", " IF", " DF", " OF", NULL, NULL, " NT", " BIT15", " RF", " VF", " AC", " VIF", " VIP", " ID", " BIT22", " BIT23", " BIT24", " BIT25", " BIT26", - " BIT27", " BIT28", " BIT29", " BIT30", - " BIT31", " BIT32", " BIT33", " BIT34", - " BIT35", " BIT36", " BIT37", " BIT38", - " BIT39", " BIT40", " BIT41", " BIT42", - " BIT43", " BIT44", " BIT45", " BIT46", - " BIT47", " BIT48", " BIT49", " BIT50", - " BIT51", " BIT52", " BIT53", " BIT54", - " BIT55", " BIT56", " BIT57", " BIT58", - " BIT59", " BIT60", " BIT61", " BIT62", - " BIT63", + " BIT27", " BIT28", " BIT29", " BIT30" + };
if (Argv[0][0] == 'r') /* regs */ @@ -654,11 +646,7 @@ #endif KdbpPrint("EFLAGS 0x%08x ", Tf->EFlags);
-#ifdef _M_IX86 for (i = 0; i < 32; i++) -#elif defined(_M_AMD64) - for (i = 0; i < 64; i++) -#endif { if (i == 1) { @@ -1591,19 +1579,21 @@
/*!\brief Displays GDT, LDT or IDTd. */ +#ifdef _M_AMD64 static BOOLEAN KdbpCmdGdtLdtIdt( ULONG Argc, PCHAR Argv[]) { KDESCRIPTOR Reg; - ULONG SegDesc[2]; - ULONG SegBase; + KIDTENTRY IdtEntry; + KGDTENTRY GdtEntry; + ULONG_PTR SegBase; ULONG SegLimit; PCHAR SegType; USHORT SegSel; UCHAR Type, Dpl; - INT i; + INT i = 0; ULONG ul;
if (Argv[0][0] == 'i') @@ -1617,49 +1607,53 @@ return TRUE; }
- KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg.Base, Reg.Limit); + KdbpPrint("IDT Base: 0x%p Limit: 0x%04x\n", Reg.Base, Reg.Limit); KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
- for (i = 0; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8) - { - if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc)))) - { - KdbpPrint("Couldn't access memory at 0x%08x!\n", (ULONG_PTR)Reg.Base + i); + while (i < (Reg.Limit)/sizeof(IdtEntry)) + { + if (!NT_SUCCESS(KdbpSafeReadMemory(&IdtEntry, (PVOID)((ULONG_PTR)Reg.Base +(i *sizeof(IdtEntry))), sizeof(IdtEntry)))) + { + KdbpPrint("Couldn't access memory at 0x%x!\n", (ULONG_PTR)Reg.Base + sizeof(IdtEntry)); return TRUE; }
- Dpl = ((SegDesc[1] >> 13) & 3); - if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */ + Dpl = IdtEntry.Dpl; + if (IdtEntry.Type == 0x5) /* Task gate */ SegType = "TASKGATE"; - else if ((SegDesc[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */ + else if (IdtEntry.Type == 0xE) /* 32 bit Interrupt gate */ SegType = "INTGATE32"; - else if ((SegDesc[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */ + else if (IdtEntry.Type == 0x6) /* 16 bit Interrupt gate */ SegType = "INTGATE16"; - else if ((SegDesc[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */ + else if (IdtEntry.Type == 0xF) /* 32 bit Trap gate */ SegType = "TRAPGATE32"; - else if ((SegDesc[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */ + else if (IdtEntry.Type == 0x7) /* 16 bit Trap gate */ SegType = "TRAPGATE16"; else SegType = "UNKNOWN";
- if ((SegDesc[1] & (1 << 15)) == 0) /* not present */ + if (IdtEntry.Present == 0) /* not present */ { KdbpPrint(" %03d %-10s [NP] [NP] %02d\n", - i / 8, SegType, Dpl); - } - else if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */ - { - SegSel = SegDesc[0] >> 16; + i, SegType, Dpl); + } + else if (IdtEntry.Type == 0x5) /* Task gate */ + { + SegSel = IdtEntry.Selector; KdbpPrint(" %03d %-10s 0x%04x %02d\n", - i / 8, SegType, SegSel, Dpl); + i, SegType, SegSel, Dpl); } else { - SegSel = SegDesc[0] >> 16; - SegBase = (SegDesc[1] & 0xffff0000) | (SegDesc[0] & 0x0000ffff); - KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n", - i / 8, SegType, SegSel, SegBase, Dpl); - } + SegSel = IdtEntry.Selector; + SegBase = (ULONG64)IdtEntry.OffsetLow | + (ULONG64)IdtEntry.OffsetMiddle << 16 | + (ULONG64)IdtEntry.OffsetHigh << 32; + + KdbpPrint(" %03d %-10s 0x%04x 0x%p %02d\n", + i , SegType, SegSel, SegBase, Dpl); + } + i++; } } else @@ -1669,25 +1663,17 @@ if (Argv[0][0] == 'g') { /* Read GDTR */ -#ifdef _M_IX86 - Ke386GetGlobalDescriptorTable(&Reg.Limit); -#elif defined(_M_AMD64) __sgdt(&Reg.Limit); -#endif - i = 8; + } else { ASSERT(Argv[0][0] == 'l');
/* Read LDTR */ -#ifdef _M_IX86 - Reg.Limit = Ke386GetLocalDescriptorTable(); -#elif defined(_M_AMD64) - __sldt(&Reg.Limit); -#endif + __sldt(&Reg.Limit); + Reg.Base = 0; - i = 0; ul = 1 << 2; }
@@ -1698,28 +1684,27 @@ return TRUE; }
- KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n", + KdbpPrint("%cDT Base: 0x%p Limit: 0x%04x\n", Argv[0][0] == 'g' ? 'G' : 'L', Reg.Base, Reg.Limit); KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
- for (; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8) - { - if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc)))) - { - KdbpPrint("Couldn't access memory at 0x%08x!\n", (ULONG_PTR)Reg.Base + i); + while (i < (Reg.Limit)/sizeof(GdtEntry)) + { + if (!NT_SUCCESS(KdbpSafeReadMemory(&GdtEntry, (PVOID)((ULONG_PTR)Reg.Base +(i * 8)), sizeof(GdtEntry)))) + { + KdbpPrint("Couldn't access memory at 0x%p!\n", (ULONG_PTR)Reg.Base + i); return TRUE; }
- Dpl = ((SegDesc[1] >> 13) & 3); - Type = ((SegDesc[1] >> 8) & 0xf); - - SegBase = SegDesc[0] >> 16; - SegBase |= (SegDesc[1] & 0xff) << 16; - SegBase |= SegDesc[1] & 0xff000000; - SegLimit = SegDesc[0] & 0x0000ffff; - SegLimit |= (SegDesc[1] >> 16) & 0xf; - - if ((SegDesc[1] & (1 << 23)) != 0) + Dpl = GdtEntry.Bits.Dpl; + Type = GdtEntry.Bits.Type; + + SegBase = (ULONG_PTR)KiGetGdtDescriptorBase(&GdtEntry); + + SegLimit = GdtEntry.LimitLow; + SegLimit |= (ULONG64)GdtEntry.Bits.LimitHigh << 32; + + if (GdtEntry.Bits.DefaultBig != 0) { SegLimit *= 4096; SegLimit += 4095; @@ -1729,7 +1714,7 @@ SegLimit++; }
- if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */ + if (GdtEntry.Bits.System == 1) /* System segment */ { switch (Type) { @@ -1755,6 +1740,230 @@ SegLimit = 0; } } + else if ((Type & (1 << 3)) == 0) /* Data segment */ + { + if (GdtEntry.Bits.LongMode != 0) + SegType = "DATA32"; + else + SegType = "DATA16"; + } + else /* Code segment */ + { + if (GdtEntry.Bits.LongMode != 0) + SegType = "CODE32"; + else + SegType = "CODE16"; + } + + if (GdtEntry.Bits.Present == 0) /* not present */ + { + KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n", + i, i | Dpl | ul, SegType, Dpl); + } + else + { + KdbpPrint(" %03d 0x%04x %-11s 0x%p 0x%08x %02d ", + i, i | Dpl | ul, SegType, SegBase, SegLimit, Dpl); + + if (GdtEntry.Bits.System == 1) /* System segment */ + { + /* FIXME: Display system segment */ + /* they are twice as big as regular segments */ + i++; + } + else if ((Type & (1 << 3)) == 0) /* Data segment */ + { + if ((Type & (1 << 2)) != 0) /* Expand-down */ + KdbpPrint(" E"); + + KdbpPrint((Type & (1 << 1)) ? " R/W" : " R"); + + if ((Type & (1 >> 1)) != 0) + KdbpPrint(" A"); + } + else /* Code segment */ + { + if ((Type & (1 << 2)) != 0) /* Conforming */ + KdbpPrint(" C"); + + KdbpPrint((Type & (1 << 1)) ? " R/X" : " X"); + + if ((Type & (1 << 1)) != 0) + KdbpPrint(" A"); + } + + if ((GdtEntry.Bits.LimitHigh & (1 << 3)) != 0) + KdbpPrint(" AVL"); + + KdbpPrint("\n"); + } + i++; + } + } + + return TRUE; +} +#endif + +/*!\brief Displays GDT, LDT or IDTd. + */ +#ifdef _M_IX86 +static BOOLEAN +KdbpCmdGdtLdtIdt( + ULONG Argc, + PCHAR Argv[]) +{ + KDESCRIPTOR Reg; + ULONG SegDesc[2]; + ULONG SegBase; + ULONG SegLimit; + PCHAR SegType; + USHORT SegSel; + UCHAR Type, Dpl; + INT i; + ULONG ul; + + if (Argv[0][0] == 'i') + { + /* Read IDTR */ + __sidt(&Reg.Limit); + + if (Reg.Limit < 7) + { + KdbpPrint("Interrupt descriptor table is empty.\n"); + return TRUE; + } + + KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg.Base, Reg.Limit); + KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n"); + + for (i = 0; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8) + { + if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc)))) + { + KdbpPrint("Couldn't access memory at 0x%08x!\n", (ULONG_PTR)Reg.Base + i); + return TRUE; + } + + Dpl = ((SegDesc[1] >> 13) & 3); + if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */ + SegType = "TASKGATE"; + else if ((SegDesc[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */ + SegType = "INTGATE32"; + else if ((SegDesc[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */ + SegType = "INTGATE16"; + else if ((SegDesc[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */ + SegType = "TRAPGATE32"; + else if ((SegDesc[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */ + SegType = "TRAPGATE16"; + else + SegType = "UNKNOWN"; + + if ((SegDesc[1] & (1 << 15)) == 0) /* not present */ + { + KdbpPrint(" %03d %-10s [NP] [NP] %02d\n", + i / 8, SegType, Dpl); + } + else if ((SegDesc[1] & 0x1f00) == 0x0500) /* Task gate */ + { + SegSel = SegDesc[0] >> 16; + KdbpPrint(" %03d %-10s 0x%04x %02d\n", + i / 8, SegType, SegSel, Dpl); + } + else + { + SegSel = SegDesc[0] >> 16; + SegBase = (SegDesc[1] & 0xffff0000) | (SegDesc[0] & 0x0000ffff); + KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n", + i / 8, SegType, SegSel, SegBase, Dpl); + } + } + } + else + { + ul = 0; + + if (Argv[0][0] == 'g') + { + /* Read GDTR */ + Ke386GetGlobalDescriptorTable(&Reg.Limit); + i = 8; + } + else + { + ASSERT(Argv[0][0] == 'l'); + + /* Read LDTR */ + Reg.Limit = Ke386GetLocalDescriptorTable(); + Reg.Base = 0; + i = 0; + ul = 1 << 2; + } + + if (Reg.Limit < 7) + { + KdbpPrint("%s descriptor table is empty.\n", + Argv[0][0] == 'g' ? "Global" : "Local"); + return TRUE; + } + + KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n", + Argv[0][0] == 'g' ? 'G' : 'L', Reg.Base, Reg.Limit); + KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n"); + + for (; (i + sizeof(SegDesc) - 1) <= Reg.Limit; i += 8) + { + if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc, (PVOID)((ULONG_PTR)Reg.Base + i), sizeof(SegDesc)))) + { + KdbpPrint("Couldn't access memory at 0x%08x!\n", (ULONG_PTR)Reg.Base + i); + return TRUE; + } + + Dpl = ((SegDesc[1] >> 13) & 3); + Type = ((SegDesc[1] >> 8) & 0xf); + + SegBase = SegDesc[0] >> 16; + SegBase |= (SegDesc[1] & 0xff) << 16; + SegBase |= SegDesc[1] & 0xff000000; + SegLimit = SegDesc[0] & 0x0000ffff; + SegLimit |= (SegDesc[1] >> 16) & 0xf; + + if ((SegDesc[1] & (1 << 23)) != 0) + { + SegLimit *= 4096; + SegLimit += 4095; + } + else + { + SegLimit++; + } + + if ((SegDesc[1] & (1 << 12)) == 0) /* System segment */ + { + switch (Type) + { + case 1: SegType = "TSS16(Avl)"; break; + case 2: SegType = "LDT"; break; + case 3: SegType = "TSS16(Busy)"; break; + case 4: SegType = "CALLGATE16"; break; + case 5: SegType = "TASKGATE"; break; + case 6: SegType = "INTGATE16"; break; + case 7: SegType = "TRAPGATE16"; break; + case 9: SegType = "TSS32(Avl)"; break; + case 11: SegType = "TSS32(Busy)"; break; + case 12: SegType = "CALLGATE32"; break; + case 14: SegType = "INTGATE32"; break; + case 15: SegType = "INTGATE32"; break; + default: SegType = "UNKNOWN"; break; + } + + if (!(Type >= 1 && Type <= 3) && + Type != 9 && Type != 11) + { + SegBase = 0; + SegLimit = 0; + } + } else if ((SegDesc[1] & (1 << 11)) == 0) /* Data segment */ { if ((SegDesc[1] & (1 << 22)) != 0) @@ -1815,6 +2024,7 @@
return TRUE; } +#endif
/*!\brief Displays the KPCR */ @@ -1862,21 +2072,21 @@ Pcr->VdmAlert, Pcr->SecondLevelCacheSize, Pcr->InterruptMode); #elif defined(_M_AMD64) KdbpPrint("Current PCR is at 0x%x.\n", (INT_PTR)Pcr); - KdbpPrint(" Tib.ExceptionList: 0x%x\n" - " Tib.StackBase: 0x%x\n" + KdbpPrint(" Tib.ExceptionList: 0x%p\n" + " Tib.StackBase: 0x%p\n" " Tib.StackLimit: 0x%x\n" - " Tib.SubSystemTib: 0x%x\n" + " Tib.SubSystemTib: 0x%p\n" " Tib.FiberData/Version: 0x%x\n" - " Tib.ArbitraryUserPointer: 0x%x\n" - " Tib.Self: 0x%x\n" - " Self: 0x%x\n" - " PCRCB: 0x%x\n" + " Tib.ArbitraryUserPointer: 0x%p\n" + " Tib.Self: 0x%p\n" + " Self: 0x%p\n" + " PCRCB: 0x%p\n" " Irql: 0x%x\n" " KdVersionBlock: 0x%08x\n" - " IDT: 0x%08x\n" - " GDT: 0x%08x\n" - " TSS: 0x%08x\n" - " UserRsp: 0x%08x\n" + " IDT: 0x%p\n" + " GDT: 0x%p\n" + " TSS: 0x%p\n" + " UserRsp: 0x%p\n" " MajorVersion: 0x%04x\n" " MinorVersion: 0x%04x\n" " StallScaleFactor: 0x%08x\n" @@ -1902,8 +2112,8 @@ #ifdef _M_IX86 KTSS *Tss = KeGetPcr()->TSS;
- KdbpPrint("Current TSS is at 0x%08x.\n", (INT)Tss); - KdbpPrint(" Eip: 0x%08x\n" + KdbpPrint("Current TSS is at 0x%p.\n", (INT_PTR)Tss); + KdbpPrint(" Eip: 0x%p\n" " Es: 0x%04x\n" " Cs: 0x%04x\n" " Ss: 0x%04x\n" @@ -1912,10 +2122,18 @@ " Gs: 0x%04x\n" " IoMapBase: 0x%04x\n", Tss->Eip, Tss->Es, Tss->Cs, Tss->Ds, Tss->Fs, Tss->Gs, Tss->IoMapBase); - +#elif defined(_M_AMD64) + KTSS *Tss = KeGetPcr()->TssBase; + + KdbpPrint("Current TSS is at 0x%p.\n", (INT_PTR)Tss); + KdbpPrint(" Rsp0: 0x%p\n" + " Rsp1: 0x%p\n" + " Rsp2: 0x%p\n" + " Ist: 0x%p\n" + " IoMapBase: 0x%04x\n", + Tss->Rsp0, Tss->Rsp1, Tss->Rsp2, Tss->Ist, Tss->IoMapBase); +#endif return TRUE; -#endif - return FALSE; }
/*!\brief Bugchecks the system.
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/kiinit.c [iso-8859-1] Thu Dec 24 05:12:02 2009 @@ -714,7 +714,10 @@ if (KdPollBreakIn()) DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C);
/* Hack! Wait for the debugger! */ - //while (!KdPollBreakIn()); +#ifdef _WINKD_ + while (!KdPollBreakIn()); + DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C); +#endif
}
Modified: branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/thrdini.c URL: http://svn.reactos.org/svn/reactos/branches/ros-amd64-bringup/reactos/ntoskr... ============================================================================== --- branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/thrdini.c [iso-8859-1] (original) +++ branches/ros-amd64-bringup/reactos/ntoskrnl/ke/amd64/thrdini.c [iso-8859-1] Thu Dec 24 05:12:02 2009 @@ -11,7 +11,7 @@ #include <ntoskrnl.h> #define NDEBUG #include <debug.h> -#if 0 + typedef struct _KSWITCHFRAME { PVOID ExceptionList; @@ -32,16 +32,16 @@ KSWITCHFRAME CtxSwitchFrame; KSTART_FRAME StartFrame; KTRAP_FRAME TrapFrame; - FX_SAVE_AREA FxSaveArea; + //FX_SAVE_AREA FxSaveArea; } KUINIT_FRAME, *PKUINIT_FRAME;
typedef struct _KKINIT_FRAME { KSWITCHFRAME CtxSwitchFrame; KSTART_FRAME StartFrame; - FX_SAVE_AREA FxSaveArea; + //FX_SAVE_AREA FxSaveArea; } KKINIT_FRAME, *PKKINIT_FRAME; -#endif + /* FUNCTIONS *****************************************************************/
VOID @@ -52,10 +52,8 @@ IN PVOID StartContext, IN PCONTEXT ContextPointer) { - FrLdrDbgPrint("KiInitializeContextThread stub\n"); -#if 0 - PFX_SAVE_AREA FxSaveArea; - PFXSAVE_FORMAT FxSaveFormat; + //PFX_SAVE_AREA FxSaveArea; + //PFXSAVE_FORMAT FxSaveFormat; PKSTART_FRAME StartFrame; PKSWITCHFRAME CtxSwitchFrame; PKTRAP_FRAME TrapFrame; @@ -78,60 +76,60 @@
/* Zero out the trap frame and save area */ RtlZeroMemory(&InitFrame->TrapFrame, - KTRAP_FRAME_LENGTH + sizeof(FX_SAVE_AREA)); + KTRAP_FRAME_LENGTH);
/* Setup the Fx Area */ - FxSaveArea = &InitFrame->FxSaveArea; + //FxSaveArea = &InitFrame->FxSaveArea;
/* Check if we support FXsr */ - if (KeI386FxsrPresent) - { - /* Get the FX Save Format Area */ - FxSaveFormat = (PFXSAVE_FORMAT)Context->ExtendedRegisters; - - /* Set an initial state */ - FxSaveFormat->ControlWord = 0x27F; - FxSaveFormat->StatusWord = 0; - FxSaveFormat->TagWord = 0; - FxSaveFormat->ErrorOffset = 0; - FxSaveFormat->ErrorSelector = 0; - FxSaveFormat->DataOffset = 0; - FxSaveFormat->DataSelector = 0; - FxSaveFormat->MXCsr = 0x1F80; - } - else - { - /* Setup the regular save area */ - Context->FloatSave.ControlWord = 0x27F; - Context->FloatSave.StatusWord = 0; - Context->FloatSave.TagWord = -1; - Context->FloatSave.ErrorOffset = 0; - Context->FloatSave.ErrorSelector = 0; - Context->FloatSave.DataOffset =0; - Context->FloatSave.DataSelector = 0; - } +// if (KeI386FxsrPresent) +// { +// /* Get the FX Save Format Area */ +// FxSaveFormat = (PFXSAVE_FORMAT)Context->ExtendedRegisters; +// +// /* Set an initial state */ +// FxSaveFormat->ControlWord = 0x27F; +// FxSaveFormat->StatusWord = 0; +// FxSaveFormat->TagWord = 0; +// FxSaveFormat->ErrorOffset = 0; +// FxSaveFormat->ErrorSelector = 0; +// FxSaveFormat->DataOffset = 0; +// FxSaveFormat->DataSelector = 0; +// FxSaveFormat->MXCsr = 0x1F80; +// } +// else +// { +// /* Setup the regular save area */ +// Context->FloatSave.ControlWord = 0x27F; +// Context->FloatSave.StatusWord = 0; +// Context->FloatSave.TagWord = -1; +// Context->FloatSave.ErrorOffset = 0; +// Context->FloatSave.ErrorSelector = 0; +// Context->FloatSave.DataOffset =0; +// Context->FloatSave.DataSelector = 0; +// }
/* Check if the CPU has NPX */ if (KeI386NpxPresent) { /* Set an intial NPX State */ - Context->FloatSave.Cr0NpxState = 0; - FxSaveArea->Cr0NpxState = 0; - FxSaveArea->NpxSavedCpu = 0; + //Context->FloatSave.Cr0NpxState = 0; + //FxSaveArea->Cr0NpxState = 0; + //FxSaveArea->NpxSavedCpu = 0;
/* Now set the context flags depending on XMM support */ - ContextFlags |= (KeI386FxsrPresent) ? CONTEXT_EXTENDED_REGISTERS : - CONTEXT_FLOATING_POINT; + //ContextFlags |= (KeI386FxsrPresent) ? CONTEXT_EXTENDED_REGISTERS : + // CONTEXT_FLOATING_POINT;
/* Set the Thread's NPX State */ - Thread->NpxState = NPX_STATE_NOT_LOADED; + Thread->NpxState = 0xA; Thread->DispatcherHeader.NpxIrql = PASSIVE_LEVEL; } else { /* We'll use emulation */ - FxSaveArea->Cr0NpxState = CR0_EM; - Thread->NpxState = NPX_STATE_NOT_LOADED &~ CR0_MP; + //FxSaveArea->Cr0NpxState = CR0_EM; + Thread->NpxState = 0xA &~ CR0_MP; }
/* Disable any debug regiseters */ @@ -148,19 +146,16 @@ UserMode);
/* Set SS, DS, ES's RPL Mask properly */ - TrapFrame->HardwareSegSs |= RPL_MASK; + TrapFrame->SegSs |= RPL_MASK; TrapFrame->SegDs |= RPL_MASK; TrapFrame->SegEs |= RPL_MASK; TrapFrame->Dr7 = 0;
- /* Set the debug mark */ - TrapFrame->DbgArgMark = 0xBADB0D00; - /* Set the previous mode as user */ - TrapFrame->PreviousPreviousMode = UserMode; + TrapFrame->PreviousMode = UserMode;
/* Terminate the Exception Handler List */ - TrapFrame->ExceptionList = EXCEPTION_CHAIN_END; + TrapFrame->ExceptionFrame = 0;
/* Setup the Stack for KiThreadStartup and Context Switching */ StartFrame = &InitFrame->StartFrame; @@ -180,25 +175,26 @@ sizeof(KKINIT_FRAME));
/* Setup the Fx Area */ - FxSaveArea = &InitFrame->FxSaveArea; - RtlZeroMemory(FxSaveArea, sizeof(FX_SAVE_AREA)); + //FxSaveArea = &InitFrame->FxSaveArea; + //RtlZeroMemory(FxSaveArea, sizeof(FX_SAVE_AREA));
/* Check if we have Fxsr support */ if (KeI386FxsrPresent) { - /* Set the stub FX area */ - FxSaveArea->U.FxArea.ControlWord = 0x27F; - FxSaveArea->U.FxArea.MXCsr = 0x1F80; + DPRINT1("FxsrPresent but did nothing\n"); +// /* Set the stub FX area */ +// FxSaveArea->U.FxArea.ControlWord = 0x27F; +// FxSaveArea->U.FxArea.MXCsr = 0x1F80; +// } +// else +// { +// /* Set the stub FN area */ +// FxSaveArea->U.FnArea.ControlWord = 0x27F; +// FxSaveArea->U.FnArea.TagWord = -1; } - else - { - /* Set the stub FN area */ - FxSaveArea->U.FnArea.ControlWord = 0x27F; - FxSaveArea->U.FnArea.TagWord = -1; - }
/* No NPX State */ - Thread->NpxState = NPX_STATE_NOT_LOADED; + Thread->NpxState = 0xA;
/* Setup the Stack for KiThreadStartup and Context Switching */ StartFrame = &InitFrame->StartFrame; @@ -223,7 +219,7 @@
/* Save back the new value of the kernel stack. */ Thread->KernelStack = (PVOID)CtxSwitchFrame; -#endif + }
/* EOF */