- Use real NT KPCR address (0xFFDFF000).

- Remove all hacked KPCR_BASE definitions.
- Make FreeLDR give address of PageDirectoryStart/End addresses. This was being ignored/incorrect until now and the page directory could've gotten overwritten.
- Properly setup the HAL PDE, instead of having different PDEs for KUSER_SHARED_DATA, KPCR and ACPI I/O.
- Do not over-write shared user data with ACPI I/O anymore. This was probably a bad idea.
- Do not mark almost a meg of space as KPCR_USERD_SHARED data anymore, and don't mess up the CPU TLB anymore.
- Give a dedicated page to KUSER_SHARED_DATA (Page 2, physical address 0x2000) right after the KPCR, isntead of a random address that probably ended up overwritten later during the OS's lifetime.
- Fix FS selector in the GDT.
- Remove hack in Trap Fault Handler.
- Add a little hack to allow mapping Page 2 into user-space even though it's marked as used, this is for the Shared User Data page.

svn path=/trunk/; revision=28852
This commit is contained in:
Aleksey Bragin 2007-09-04 18:19:59 +00:00
parent 7a0b809846
commit 301681680f
16 changed files with 59 additions and 170 deletions

View file

@ -175,20 +175,10 @@ FrLdrSetupPageDirectory(VOID)
PageDir->Pde[HyperspacePageTableIndex].Write = 1;
PageDir->Pde[HyperspacePageTableIndex].PageFrameNumber = PaPtrToPfn(hyperspace_pagetable);
/* Set up the Apic PDE */
PageDir->Pde[ApicPageTableIndex].Valid = 1;
PageDir->Pde[ApicPageTableIndex].Write = 1;
PageDir->Pde[ApicPageTableIndex].PageFrameNumber = PaPtrToPfn(apic_pagetable);
/* Set up the KPCR PDE */
PageDir->Pde[KpcrPageTableIndex].Valid = 1;
PageDir->Pde[KpcrPageTableIndex].Write = 1;
PageDir->Pde[KpcrPageTableIndex].PageFrameNumber = PaPtrToPfn(kpcr_pagetable);
/* Set up the KUSER PDE */
PageDir->Pde[KuserPageTableIndex].Valid = 1;
PageDir->Pde[KuserPageTableIndex].Write = 1;
PageDir->Pde[KuserPageTableIndex].PageFrameNumber = PaPtrToPfn(kuser_pagetable);
/* Set up the HAL PDE */
PageDir->Pde[HalPageTableIndex].Valid = 1;
PageDir->Pde[HalPageTableIndex].Write = 1;
PageDir->Pde[HalPageTableIndex].PageFrameNumber = PaPtrToPfn(apic_pagetable);
/* Set up Low Memory PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&lowmem_pagetable;
@ -209,35 +199,28 @@ FrLdrSetupPageDirectory(VOID)
PageDir->Pde[i].PageFrameNumber = PaToPfn(KERNEL_BASE_PHYS + i * PAGE_SIZE);
}
/* Set up APIC PTEs */
/* Setup APIC Base */
PageDir = (PPAGE_DIRECTORY_X86)&apic_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].CacheDisable = 1;
PageDir->Pde[0].WriteThrough = 1;
PageDir->Pde[0].PageFrameNumber = PaToPfn(APIC_BASE);
PageDir->Pde[0].PageFrameNumber = PaToPfn(HAL_BASE);
PageDir->Pde[0x200].Valid = 1;
PageDir->Pde[0x200].Write = 1;
PageDir->Pde[0x200].CacheDisable = 1;
PageDir->Pde[0x200].WriteThrough = 1;
PageDir->Pde[0x200].PageFrameNumber = PaToPfn(APIC_BASE + KERNEL_BASE_PHYS);
PageDir->Pde[0x200].PageFrameNumber = PaToPfn(HAL_BASE + KERNEL_BASE_PHYS);
/* Set up KPCR PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kpcr_pagetable;
PageDir->Pde[0].Valid = 1;
PageDir->Pde[0].Write = 1;
PageDir->Pde[0].PageFrameNumber = 1;
/* Setup KUSER_SHARED_DATA Base */
PageDir->Pde[0x1F0].Valid = 1;
PageDir->Pde[0x1F0].Write = 1;
PageDir->Pde[0x1F0].PageFrameNumber = 2;
/* Setup KUSER PTEs */
PageDir = (PPAGE_DIRECTORY_X86)&kuser_pagetable;
for (i = 0; i < 1024; i++)
{
/* SEetup each entry */
PageDir->Pde[i].Valid = 1;
PageDir->Pde[i].Write = 1;
PageDir->Pde[i].Owner = 1;
PageDir->Pde[i].PageFrameNumber = PaToPfn(KI_USER_SHARED_DATA + i * PAGE_SIZE);
}
/* Setup KPCR Base*/
PageDir->Pde[0x1FF].Valid = 1;
PageDir->Pde[0x1FF].Write = 1;
PageDir->Pde[0x1FF].PageFrameNumber = 1;
}
PLOADER_MODULE

View file

@ -40,16 +40,12 @@
#define STARTUP_BASE 0xC0000000
#define HYPERSPACE_BASE 0xC0400000
#define HYPERSPACE_PAE_BASE 0xC0800000
#define APIC_BASE 0xFEC00000
#define KPCR_BASE 0xFF000000
#define HAL_BASE 0xFFC00000
#define LowMemPageTableIndex 0
#define StartupPageTableIndex (STARTUP_BASE >> 22)
#define HyperspacePageTableIndex (HYPERSPACE_BASE >> 22)
#define KpcrPageTableIndex (KPCR_BASE >> 22)
#define ApicPageTableIndex (APIC_BASE >> 22)
#define KuserPageTableIndex (KI_USER_SHARED_DATA >> 22)
#define HalPageTableIndex (HAL_BASE >> 22)
typedef struct _PAGE_DIRECTORY_X86
{

View file

@ -22,6 +22,9 @@
#include <freeldr.h>
#include <debug.h>
extern ULONG PageDirectoryStart;
extern ULONG PageDirectoryEnd;
ROS_LOADER_PARAMETER_BLOCK LoaderBlock;
char reactos_kernel_cmdline[255]; // Command line passed to kernel
LOADER_MODULE reactos_modules[64]; // Array to hold boot module info loaded for the kernel
@ -592,6 +595,8 @@ LoadAndBootReactOS(PCSTR OperatingSystemName)
* Setup multiboot information structure
*/
LoaderBlock.CommandLine = reactos_kernel_cmdline;
LoaderBlock.PageDirectoryStart = (ULONG)&PageDirectoryStart;
LoaderBlock.PageDirectoryEnd = (ULONG)&PageDirectoryEnd;
LoaderBlock.ModsCount = 0;
LoaderBlock.ModsAddr = reactos_modules;
LoaderBlock.DrivesAddr = reactos_arc_disk_info;

View file

@ -5,9 +5,6 @@
#ifndef __INTERNAL_HAL_HAL_H
#define __INTERNAL_HAL_HAL_H
/* Temporary hack */
#define KPCR_BASE 0xFF000000
#define HAL_APC_REQUEST 0
#define HAL_DPC_REQUEST 1

View file

@ -227,11 +227,7 @@ typedef struct _ADAPTER_OBJECT *PADAPTER_OBJECT;
#define ZwCurrentProcess() NtCurrentProcess()
#define NtCurrentThread() ( (HANDLE)(LONG_PTR) -2 )
#define ZwCurrentThread() NtCurrentThread()
#ifdef _REACTOS_
#define KIP0PCRADDRESS 0xff000000
#else
#define KIP0PCRADDRESS 0xffdff000
#endif
#define KERNEL_STACK_SIZE 12288
#define KERNEL_LARGE_STACK_SIZE 61440

View file

@ -29,7 +29,7 @@ Author:
#ifdef CONFIG_SMP
#define PCR fs:
#else
#define PCR ds:[0xFF000000]
#define PCR ds:[0xFFDFF000]
#endif
#endif
@ -613,3 +613,4 @@ Author:

View file

@ -904,7 +904,7 @@ QSI_DEF(SystemProcessorPerformanceInformation)
}
CurrentTime.QuadPart = KeQueryInterruptTime();
Prcb = ((PKPCR)KPCR_BASE)->Prcb;
Prcb = KeGetPcr()->Prcb;
for (i = 0; i < KeNumberProcessors; i++)
{
Spi->IdleTime.QuadPart = (Prcb->IdleThread->KernelTime + Prcb->IdleThread->UserTime) * 100000LL; // IdleTime
@ -1196,7 +1196,7 @@ QSI_DEF(SystemInterruptInformation)
ti = KeQueryTimeIncrement();
Prcb = ((PKPCR)KPCR_BASE)->Prcb;
Prcb = KeGetPcr()->Prcb;
for (i = 0; i < KeNumberProcessors; i++)
{
//sii->ContextSwitches = Prcb->KeContextSwitches;

View file

@ -60,7 +60,6 @@ typedef ULONG PFN_TYPE, *PPFN_TYPE;
#define NR_SECTION_PAGE_ENTRIES 1024
#define TEB_BASE 0x7FFDE000
#define KPCR_BASE 0xFF000000
/* Although Microsoft says this isn't hardcoded anymore,
they won't be able to change it. Stuff depends on it */

View file

@ -149,7 +149,7 @@ IopInitLookasideLists(VOID)
for (i = 0; i < KeNumberProcessors; i++)
{
/* Get the PRCB for this CPU */
Prcb = ((PKPCR)(KPCR_BASE + i * PAGE_SIZE))->Prcb;
Prcb = ((PKPCR)(KIP0PCRADDRESS + i * PAGE_SIZE))->Prcb;
DPRINT("Setting up lookaside for CPU: %x, PRCB: %p\n", i, Prcb);
/* Set the Large IRP List */

View file

@ -471,8 +471,8 @@ KiRosBuildOsMemoryMap(VOID)
Status = KiRosAllocateArcDescriptor(0, 1, MemoryFirmwarePermanent);
if (Status != STATUS_SUCCESS) return Status;
/* Build an entry for the KPCR (which we put in page 1) */
Status = KiRosAllocateArcDescriptor(1, 2, LoaderMemoryData);
/* Build an entry for the KPCR and KUSER_SHARED_DATA */
Status = KiRosAllocateArcDescriptor(1, 3, LoaderMemoryData);
if (Status != STATUS_SUCCESS) return Status;
/* Build an entry for the PDE and return the status */

View file

@ -38,7 +38,7 @@ KGDTENTRY KiBootGdt[256] =
{0xffff, 0x0000, {{0x00, 0xfb, 0xcf, 0x00}}}, /* KGDT_R3_CODE */
{0xffff, 0x0000, {{0x00, 0xf3, 0xcf, 0x00}}}, /* KGDT_R3_DATA*/
{0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_TSS */
{0x0fff, 0x0000, {{0x00, 0x93, 0xc0, 0xff}}}, /* KGDT_R0_PCR */
{0x0001, 0xf000, {{0xdf, 0x93, 0xc0, 0xff}}}, /* KGDT_R0_PCR */
{0x0fff, 0x0000, {{0x00, 0xf3, 0x40, 0x00}}}, /* KGDT_R3_TEB */
{0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_UNUSED */
{0x0000, 0x0000, {{0x00, 0x00, 0x00, 0x00}}}, /* KGDT_LDT */

View file

@ -428,7 +428,7 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
if (j == 0)
{
/*
* Page zero is reserved
* Page zero is reserved for the IVT
*/
MmPageArray[0].Flags.Type = MM_PHYSICAL_PAGE_BIOS;
MmPageArray[0].Flags.Consumer = MC_NPPOOL;
@ -452,6 +452,19 @@ MmInitializePageList(ULONG_PTR FirstPhysKernelAddress,
&MmPageArray[1].ListEntry);
MmStats.NrReservedPages++;
}
else if (j == 2)
{
/*
* Page two is reserved for the KUSER_SHARED_DATA
*/
MmPageArray[1].Flags.Type = MM_PHYSICAL_PAGE_BIOS;
MmPageArray[1].Flags.Consumer = MC_NPPOOL;
MmPageArray[1].Flags.Zero = 0;
MmPageArray[1].ReferenceCount = 0;
InsertTailList(&BiosPageListHead,
&MmPageArray[1].ListEntry);
MmStats.NrReservedPages++;
}
/* Protect the Page Directory. This will be changed in r3 */
else if (j >= (PdeStart / PAGE_SIZE) && j < (MmFreeLdrPageDirectoryEnd / PAGE_SIZE))
{

View file

@ -1924,11 +1924,19 @@ MmCreateVirtualMapping(PEPROCESS Process,
for (i = 0; i < PageCount; i++)
{
if (!MmIsUsablePage(Pages[i]))
{
/* Is this an attempt to map KUSER_SHARED_DATA? */
if ((Address == (PVOID)0x7FFE0000) && (PageCount == 1) && (Pages[0] == 2))
{
// allow
}
else
{
DPRINT1("Page at address %x not usable\n", PFN_TO_PTE(Pages[i]));
KEBUGCHECK(0);
}
}
}
return(MmCreateVirtualMappingUnsafe(Process,
Address,

View file

@ -193,17 +193,6 @@ MmNotPresentFault(KPROCESSOR_MODE Mode,
CPRINT("Page fault at high IRQL was %d, address %x\n", KeGetCurrentIrql(), Address);
return(STATUS_UNSUCCESSFUL);
}
if (PsGetCurrentProcess() == NULL)
{
/* Allow this! It lets us page alloc much earlier! It won't be needed
* after my init patch anyways
*/
DPRINT("No current process\n");
if (Address < (ULONG_PTR)MmSystemRangeStart)
{
return(STATUS_ACCESS_VIOLATION);
}
}
/*
* Find the memory area for the faulting address

View file

@ -77,10 +77,8 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
{
PVOID BaseAddress;
ULONG Length;
//ULONG ParamLength = KernelLength;
NTSTATUS Status;
PHYSICAL_ADDRESS BoundaryAddressMultiple;
PFN_TYPE Pfn;
PMEMORY_AREA MArea;
DPRINT("MmInitVirtualMemory(%x, %x)\n",LastKernelAddress, KernelLength);
@ -112,7 +110,7 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
*/
MiInitPageDirectoryMap();
BaseAddress = (PVOID)KPCR_BASE;
BaseAddress = (PVOID)KIP0PCRADDRESS;
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
@ -158,91 +156,6 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
0,
BoundaryAddressMultiple);
#if 0
DPRINT1("LD Vars: %lx %lx %lx %lx %lx %lx. Last: %lx\n",
&_image_base__,
&_text_start__,
&_text_end__,
&_init_start__,
&_init_end__,
&_bss_end__,
LastKernelAddress);
BaseAddress = (PVOID)&_image_base__;
DPRINT1("Non-LD Vars: %lx %lx %lx %lx %lx %lx. Last: %lx\n",
0,
0,
0,
0,
0,
0,
LastKernelAddress);
Length = PAGE_ROUND_UP(((ULONG_PTR)&_text_end__)) - (ULONG_PTR)&_image_base__;
ParamLength = ParamLength - Length;
/*
* No need to lock the address space at this point since no
* other threads are running.
*/
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
PAGE_EXECUTE_READ,
&MArea,
TRUE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG_PTR)&_text_end__));
ASSERT(BaseAddress == (PVOID)&_init_start__);
Length = PAGE_ROUND_UP(((ULONG_PTR)&_init_end__)) -
PAGE_ROUND_UP(((ULONG_PTR)&_text_end__));
ParamLength = ParamLength - Length;
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
PAGE_EXECUTE_READ,
&MArea,
TRUE,
0,
BoundaryAddressMultiple);
Length = PAGE_ROUND_UP(((ULONG_PTR)&_bss_end__)) -
PAGE_ROUND_UP(((ULONG_PTR)&_init_end__));
ParamLength = ParamLength - Length;
DPRINT("Length %x\n",Length);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG_PTR)&_init_end__));
DPRINT("BaseAddress %x\n",BaseAddress);
/*
* No need to lock the address space at this point since we are
* the only thread running.
*/
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
PAGE_READWRITE,
&MArea,
TRUE,
0,
BoundaryAddressMultiple);
BaseAddress = (PVOID)PAGE_ROUND_UP(((ULONG_PTR)&_bss_end__));
Length = LastKernelAddress - (ULONG_PTR)BaseAddress;
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
&BaseAddress,
Length,
PAGE_READWRITE,
&MArea,
TRUE,
0,
BoundaryAddressMultiple);
#endif
BaseAddress = MiNonPagedPoolStart;
MmCreateMemoryArea(MmGetKernelAddressSpace(),
MEMORY_AREA_SYSTEM,
@ -281,18 +194,7 @@ MmInitVirtualMemory(ULONG_PTR LastKernelAddress,
TRUE,
0,
BoundaryAddressMultiple);
Status = MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &Pfn);
MmSharedDataPagePhysicalAddress.QuadPart = Pfn << PAGE_SHIFT;
Status = MmCreateVirtualMapping(NULL,
(PVOID)KI_USER_SHARED_DATA,
PAGE_READWRITE,
&Pfn,
1);
if (!NT_SUCCESS(Status))
{
DbgPrint("Unable to create virtual mapping\n");
KEBUGCHECK(0);
}
MmSharedDataPagePhysicalAddress.QuadPart = 2 << PAGE_SHIFT;
RtlZeroMemory(BaseAddress, Length);
/*

View file

@ -67,7 +67,7 @@ ObInit2(VOID)
for (i = 0; i < KeNumberProcessors; i++)
{
/* Get the PRCB for this CPU */
Prcb = ((PKPCR)(KPCR_BASE + i * PAGE_SIZE))->Prcb;
Prcb = ((PKPCR)(KIP0PCRADDRESS + i * PAGE_SIZE))->Prcb;
/* Set the OBJECT_CREATE_INFORMATION List */
Prcb->PPLookasideList[LookasideCreateInfoList].L = &ObpCiLookasideList.L;