From 5a633f8fc9d59efd84bb1e665b3be3635d0b9800 Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Thu, 31 Aug 2006 17:10:58 +0000 Subject: [PATCH] - Remove some deprecated code and custom ROS exports/code. svn path=/trunk/; revision=23845 --- reactos/ntoskrnl/ex/init.c | 16 +-- reactos/ntoskrnl/ke/i386/gdt.c | 38 ------ reactos/ntoskrnl/ke/i386/kernel.c | 178 ---------------------------- reactos/ntoskrnl/ke/i386/main_asm.S | 2 +- reactos/ntoskrnl/ke/i386/tss.c | 143 ---------------------- reactos/ntoskrnl/ke/main.c | 56 +++------ reactos/ntoskrnl/ntoskrnl.def | 3 - 7 files changed, 21 insertions(+), 415 deletions(-) diff --git a/reactos/ntoskrnl/ex/init.c b/reactos/ntoskrnl/ex/init.c index 1f9b29c2ea8..4fdd8636fda 100644 --- a/reactos/ntoskrnl/ex/init.c +++ b/reactos/ntoskrnl/ex/init.c @@ -565,21 +565,7 @@ ExpInitializeExecutive(VOID) if (KdPollBreakIn()) DbgBreakPointWithStatus (DBG_STATUS_CONTROL_C); /* Initialize all processors */ - while (!HalAllProcessorsStarted()) { - - PVOID ProcessorStack; - - /* Set up the Kernel and Process Manager for this CPU */ - KePrepareForApplicationProcessorInit(KeNumberProcessors); - KeCreateApplicationProcessorIdleThread(KeNumberProcessors); - - /* Allocate a stack for use when booting the processor */ - ProcessorStack = RVA(Ki386InitialStackArray[((int)KeNumberProcessors)], KERNEL_STACK_SIZE); - - /* Tell HAL a new CPU is being started */ - HalStartNextProcessor(0, (ULONG)ProcessorStack - 2*sizeof(FX_SAVE_AREA)); - KeNumberProcessors++; - } + HalAllProcessorsStarted(); /* Do Phase 1 HAL Initalization */ HalInitSystem(1, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock); diff --git a/reactos/ntoskrnl/ke/i386/gdt.c b/reactos/ntoskrnl/ke/i386/gdt.c index a8334c90f78..0b4304ca298 100644 --- a/reactos/ntoskrnl/ke/i386/gdt.c +++ b/reactos/ntoskrnl/ke/i386/gdt.c @@ -49,12 +49,6 @@ static KSPIN_LOCK GdtLock; /* FUNCTIONS *****************************************************************/ -VOID -KiGdtPrepareForApplicationProcessorInit(ULONG Id) -{ - KiGdtArray[Id] = ExAllocatePool(NonPagedPool, sizeof(USHORT) * 4 * 11); -} - VOID KiInitializeGdt(PKPCR Pcr) { @@ -247,36 +241,4 @@ KeSetGdtSelector(ULONG Entry, KeReleaseSpinLock(&GdtLock, oldIrql); } -VOID -KeDumpGdtSelector(ULONG Entry) -{ - USHORT a, b, c, d; - ULONG RawLimit; - - a = KiBootGdt[Entry*4]; - b = KiBootGdt[Entry*4 + 1]; - c = KiBootGdt[Entry*4 + 2]; - d = KiBootGdt[Entry*4 + 3]; - - DbgPrint("Base: %x\n", b + ((c & 0xff) * (1 << 16)) + - ((d & 0xff00) * (1 << 16))); - RawLimit = a + ((d & 0xf) * (1 << 16)); - if (d & 0x80) - { - DbgPrint("Limit: %x\n", RawLimit * 4096); - } - else - { - DbgPrint("Limit: %x\n", RawLimit); - } - DbgPrint("Accessed: %d\n", (c & 0x100) >> 8); - DbgPrint("Type: %x\n", (c & 0xe00) >> 9); - DbgPrint("System: %d\n", (c & 0x1000) >> 12); - DbgPrint("DPL: %d\n", (c & 0x6000) >> 13); - DbgPrint("Present: %d\n", (c & 0x8000) >> 15); - DbgPrint("AVL: %x\n", (d & 0x10) >> 4); - DbgPrint("D: %d\n", (d & 0x40) >> 6); - DbgPrint("G: %d\n", (d & 0x80) >> 7); -} - /* EOF */ diff --git a/reactos/ntoskrnl/ke/i386/kernel.c b/reactos/ntoskrnl/ke/i386/kernel.c index c390e883189..c43669b5b92 100644 --- a/reactos/ntoskrnl/ke/i386/kernel.c +++ b/reactos/ntoskrnl/ke/i386/kernel.c @@ -41,8 +41,6 @@ static VOID INIT_FUNCTION Ki386GetCpuId(VOID); #if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, Ki386GetCpuId) -#pragma alloc_text(INIT, KeCreateApplicationProcessorIdleThread) -#pragma alloc_text(INIT, KePrepareForApplicationProcessorInit) #pragma alloc_text(INIT, KeInit1) #pragma alloc_text(INIT, KeInit2) #pragma alloc_text(INIT, Ki386SetProcessorFeatures) @@ -187,148 +185,6 @@ Ki386GetCpuId(VOID) } } -VOID -KeApplicationProcessorInitDispatcher(VOID) -{ - KIRQL oldIrql; - oldIrql = KeAcquireDispatcherDatabaseLock(); - IdleProcessorMask |= (1 << KeGetCurrentProcessorNumber()); - KeReleaseDispatcherDatabaseLock(oldIrql); -} - -VOID -INIT_FUNCTION -KeCreateApplicationProcessorIdleThread(ULONG Id) -{ - PETHREAD IdleThread; - PKPRCB Prcb = ((PKPCR)((ULONG_PTR)KPCR_BASE + Id * PAGE_SIZE))->Prcb; - - PsInitializeIdleOrFirstThread(PsIdleProcess, - &IdleThread, - NULL, - KernelMode, - FALSE); - IdleThread->Tcb.State = Running; - IdleThread->Tcb.FreezeCount = 0; - IdleThread->Tcb.Affinity = 1 << Id; - IdleThread->Tcb.UserAffinity = 1 << Id; - IdleThread->Tcb.Priority = LOW_PRIORITY; - IdleThread->Tcb.BasePriority = LOW_PRIORITY; - Prcb->IdleThread = &IdleThread->Tcb; - Prcb->CurrentThread = &IdleThread->Tcb; - - Ki386InitialStackArray[Id] = (PVOID)IdleThread->Tcb.StackLimit; - - DPRINT("IdleThread for Processor %d has PID %d\n", - Id, IdleThread->Cid.UniqueThread); -} - -VOID -INIT_FUNCTION -NTAPI -KePrepareForApplicationProcessorInit(ULONG Id) -{ - PFN_TYPE PrcPfn; - PKIPCR Pcr; - PKIPCR BootPcr; - - DPRINT("KePrepareForApplicationProcessorInit(Id %d)\n", Id); - - BootPcr = (PKIPCR)KPCR_BASE; - Pcr = (PKIPCR)((ULONG_PTR)KPCR_BASE + Id * PAGE_SIZE); - - MmRequestPageMemoryConsumer(MC_NPPOOL, TRUE, &PrcPfn); - MmCreateVirtualMappingForKernel((PVOID)Pcr, - PAGE_READWRITE, - &PrcPfn, - 1); - /* - * Create a PCR for this processor - */ - memset(Pcr, 0, PAGE_SIZE); - Pcr->Number = Id; - Pcr->SetMember = 1 << Id; - Pcr->NtTib.Self = &Pcr->NtTib; - Pcr->Self = (PKPCR)Pcr; - Pcr->Prcb = &Pcr->PrcbData; - Pcr->Irql = SYNCH_LEVEL; - - Pcr->PrcbData.SetMember = 1 << Id; - Pcr->PrcbData.MHz = BootPcr->PrcbData.MHz; - Pcr->StallScaleFactor = BootPcr->StallScaleFactor; - - /* Mark the end of the exception handler list */ - Pcr->NtTib.ExceptionList = (PVOID)-1; - - KiGdtPrepareForApplicationProcessorInit(Id); - - KeActiveProcessors |= 1 << Id; -} - -VOID -NTAPI -KeApplicationProcessorInit(VOID) -{ - ULONG Offset; - PKIPCR Pcr; - - DPRINT("KeApplicationProcessorInit()\n"); - - if (Ke386GlobalPagesEnabled) - { - /* Enable global pages */ - Ke386SetCr4(Ke386GetCr4() | X86_CR4_PGE); - } - - - Offset = InterlockedIncrementUL(&PcrsAllocated) - 1; - Pcr = (PKIPCR)((ULONG_PTR)KPCR_BASE + Offset * PAGE_SIZE); - - /* - * Initialize the GDT - */ - KiInitializeGdt((PKPCR)Pcr); - - /* Get processor information. */ - Ki386GetCpuId(); - - /* Check FPU/MMX/SSE support. */ - KiCheckFPU(); - - KeInitDpc(Pcr->Prcb); - InitializeListHead(&Pcr->PrcbData.WaitListHead); - - if (Pcr->PrcbData.FeatureBits & X86_FEATURE_SYSCALL) - { - extern void KiFastCallEntry(void); - - /* CS Selector of the target segment. */ - Ke386Wrmsr(0x174, KGDT_R0_CODE, 0); - /* Target ESP. */ - Ke386Wrmsr(0x175, 0, 0); - /* Target EIP. */ - Ke386Wrmsr(0x176, (ULONG_PTR)KiFastCallEntry, 0); - } - - /* - * It is now safe to process interrupts - */ - KeLowerIrql(DISPATCH_LEVEL); - - /* - * Initialize the TSS - */ - Ki386ApplicationProcessorInitializeTSS(); - - /* - * Initialize a default LDT - */ - Ki386InitializeLdt(); - - /* Now we can enable interrupts. */ - Ke386EnableInterrupts(); -} - VOID INIT_FUNCTION NTAPI @@ -423,42 +279,8 @@ KeInit1(PCHAR CommandLine, PULONG LastKernelAddress) } p1 = p2; } -#if 0 - /* - * FIXME: - * Make the detection of the noexecute feature more portable. - */ - if(KPCR->PrcbData.CpuType == 0xf && - RtlCompareMemory("AuthenticAMD", KPCR->PrcbData.VendorString, 12) == 12) - { - if (NoExecute) - { - ULONG Flags, l, h; - Ke386SaveFlags(Flags); - Ke386DisableInterrupts(); - - Ke386Rdmsr(0xc0000080, l, h); - l |= (1 << 11); - Ke386Wrmsr(0xc0000080, l, h); - Ke386NoExecute = TRUE; - Ke386RestoreFlags(Flags); - } - } - else - { - NoExecute=FALSE; - } -#endif Ke386Pae = Ke386GetCr4() & X86_CR4_PAE ? TRUE : FALSE; -#if 0 - /* Enable PAE mode */ - if ((Pae && (KPCR->PrcbData.FeatureBits & X86_FEATURE_PAE)) || NoExecute) - { - MiEnablePAE((PVOID*)LastKernelAddress); - Ke386PaeEnabled = TRUE; - } -#endif if (KPCR->PrcbData.FeatureBits & X86_FEATURE_SYSCALL) { extern void KiFastCallEntry(void); diff --git a/reactos/ntoskrnl/ke/i386/main_asm.S b/reactos/ntoskrnl/ke/i386/main_asm.S index cd8ee57d4db..c20f55a6ea6 100644 --- a/reactos/ntoskrnl/ke/i386/main_asm.S +++ b/reactos/ntoskrnl/ke/i386/main_asm.S @@ -64,7 +64,7 @@ _NtProcessStartup: * Call the application processor initialization code */ pushl $0 - call _KiSystemStartup + call _KiSystemStartup@4 .m1: /* Load the initial kernel stack */ diff --git a/reactos/ntoskrnl/ke/i386/tss.c b/reactos/ntoskrnl/ke/i386/tss.c index 0a4bcf4180b..88d8e81306d 100644 --- a/reactos/ntoskrnl/ke/i386/tss.c +++ b/reactos/ntoskrnl/ke/i386/tss.c @@ -40,149 +40,6 @@ extern VOID KiTrap8(VOID); /* FUNCTIONS *****************************************************************/ -BOOL STDCALL -Ke386IoSetAccessProcess(PEPROCESS Process, BOOL EnableDisable) -{ - KIRQL oldIrql; - USHORT Offset; - - if(EnableDisable > 1) return FALSE; - Offset = (EnableDisable) ? (USHORT) FIELD_OFFSET(KTSS, IoMaps) : 0xffff; - - oldIrql = KeRaiseIrqlToSynchLevel(); - Process->Pcb.IopmOffset = Offset; - - if(PsGetCurrentProcess() == Process) - { - KeGetCurrentKPCR()->TSS->IoMapBase = Offset; - } - - KeLowerIrql(oldIrql); - return TRUE; -} - - -BOOL STDCALL -Ke386SetIoAccessMap(DWORD MapNumber, PULONG IOMapStart) -{ - KIRQL oldIrql; - - if(MapNumber != 1) return FALSE; - - oldIrql = KeRaiseIrqlToSynchLevel(); - - memcpy(&KeGetCurrentKPCR()->TSS->IoMaps[0], - IOMapStart, - 0x2000); - - KeGetCurrentKPCR()->TSS->IoMapBase = KeGetCurrentProcess()->IopmOffset; - KeLowerIrql(oldIrql); - return TRUE; -} - -BOOL STDCALL -Ke386QueryIoAccessMap(DWORD MapNumber, PULONG IOMapStart) -{ - KIRQL oldIrql; - - if(MapNumber == 0x0) - { - memset(IOMapStart, 0xff, 0x2000); - return TRUE; - } else if(MapNumber != 1) return FALSE; - - oldIrql = KeRaiseIrqlToSynchLevel(); - - memcpy(IOMapStart, - &KeGetCurrentKPCR()->TSS->IoMaps[0], - 0x2000); - - KeLowerIrql(oldIrql); - return TRUE; -} - -VOID -Ki386ApplicationProcessorInitializeTSS(VOID) -{ - ULONG cr3_; - PKTSS Tss; - PKTSS TrapTss; - PVOID TrapStack; - ULONG Id; - PUSHORT Gdt; - ULONG base, length; - - Id = KeGetCurrentProcessorNumber(); - Gdt = KeGetCurrentKPCR()->GDT; - - Ke386GetPageTableDirectory(cr3_); - - Tss = ExAllocatePool(NonPagedPool, sizeof(KTSS)); - TrapTss = ExAllocatePool(NonPagedPool, sizeof(KTSSNOIOPM)); - TrapStack = ExAllocatePool(NonPagedPool, KERNEL_STACK_SIZE); - - Ki386TssArray[Id] = Tss; - Ki386TrapTssArray[Id] = (KTSSNOIOPM*)TrapTss; - Ki386TrapStackArray[Id] = TrapStack; - KeGetCurrentKPCR()->TSS = Tss; - - /* Initialize the boot TSS. */ - Tss->Esp0 = (ULONG)Ki386InitialStackArray[Id] + KERNEL_STACK_SIZE; /* FIXME: - sizeof(FX_SAVE_AREA)? */ - Tss->Ss0 = KGDT_R0_DATA; - Tss->IoMapBase = 0xFFFF; /* No i/o bitmap */ - Tss->LDT = 0; - - /* - * Initialize a descriptor for the TSS - */ - base = (ULONG)Tss; - length = sizeof(KTSS) - 1; - - Gdt[(KGDT_TSS / 2) + 0] = (USHORT)(length & 0xFFFF); - Gdt[(KGDT_TSS / 2) + 1] = (USHORT)(base & 0xFFFF); - Gdt[(KGDT_TSS / 2) + 2] = (USHORT)(((base & 0xFF0000) >> 16) | 0x8900); - Gdt[(KGDT_TSS / 2) + 3] = (USHORT)(((length & 0xF0000) >> 16) | - ((base & 0xFF000000) >> 16)); - - /* Initialize the TSS used for handling double faults. */ - TrapTss->Flags = 0; - TrapTss->Esp0 = ((ULONG)TrapStack + KERNEL_STACK_SIZE); /* FIXME: - sizeof(FX_SAVE_AREA)? */ - TrapTss->Ss0 = KGDT_R0_DATA; - TrapTss->Cs = KGDT_R0_CODE; - TrapTss->Eip = (ULONG)KiTrap8; - TrapTss->Ds = KGDT_R0_DATA; - TrapTss->Es = KGDT_R0_DATA; - TrapTss->Fs = KGDT_R0_PCR; - TrapTss->IoMapBase = 0xFFFF; /* No i/o bitmap */ - TrapTss->LDT = 0; - - /* - * Initialize a descriptor for the trap TSS. - */ - base = (ULONG)TrapTss; - length = sizeof(KTSSNOIOPM) - 1; - - Gdt[(KGDT_DF_TSS / 2) + 0] = (USHORT)(length & 0xFFFF); - Gdt[(KGDT_DF_TSS / 2) + 1] = (USHORT)(base & 0xFFFF); - Gdt[(KGDT_DF_TSS / 2) + 2] = (USHORT)(((base & 0xFF0000) >> 16) | 0x8900); - Gdt[(KGDT_DF_TSS / 2) + 3] = (USHORT)(((length & 0xF0000) >> 16) | - ((base & 0xFF000000) >> 16)); - - /* - * Load the task register - */ -#if defined(__GNUC__) - __asm__("ltr %%ax" - : /* no output */ - : "a" (KGDT_TSS)); -#elif defined(_MSC_VER) - __asm mov ax, KGDT_TSS - __asm ltr ax -#else -#error Unknown compiler for inline assembler -#endif -} - VOID INIT_FUNCTION Ki386BootInitializeTSS(VOID) { diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index 386993f6a44..3c27e734552 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -66,8 +66,6 @@ PLOADER_MODULE CachedModules[MaximumCachedModuleType]; extern unsigned int _image_base__; ULONG_PTR KERNEL_BASE = (ULONG_PTR)&_image_base__; -VOID INIT_FUNCTION _main(ULONG MultiBootMagic, PROS_LOADER_PARAMETER_BLOCK _LoaderBlock); - #if defined (ALLOC_PRAGMA) #pragma alloc_text(INIT, _main) #endif @@ -87,55 +85,39 @@ KeGetRecommendedSharedDataAlignment(VOID) } VOID -#ifdef __GNUC__ -__attribute((noinline)) -#endif +NTAPI KiSystemStartup(BOOLEAN BootProcessor) { DPRINT("KiSystemStartup(%d)\n", BootProcessor); - /* Initialize the Application Processor */ - if (!BootProcessor) KeApplicationProcessorInit(); - /* Initialize the Processor with HAL */ HalInitializeProcessor(KeNumberProcessors, (PLOADER_PARAMETER_BLOCK)&KeLoaderBlock); - /* Load the Kernel if this is the Boot CPU, else inialize the App CPU only */ - if (BootProcessor) { + /* Initialize the Kernel Executive */ + ExpInitializeExecutive(); - /* Initialize the Kernel Executive */ - ExpInitializeExecutive(); + /* Create the IOPM Save Area */ + Ki386IopmSaveArea = ExAllocatePoolWithTag(NonPagedPool, + PAGE_SIZE * 2, + TAG('K', 'e', ' ', ' ')); - /* Create the IOPM Save Area */ - Ki386IopmSaveArea = ExAllocatePoolWithTag(NonPagedPool, - PAGE_SIZE * 2, - TAG('K', 'e', ' ', ' ')); - - /* Free Initial Memory */ - MiFreeInitMemory(); + /* Free Initial Memory */ + MiFreeInitMemory(); /* Never returns */ #if 0 - /* FIXME: - * The initial thread isn't a real ETHREAD object, we cannot call PspExitThread. - */ - PspExitThread(STATUS_SUCCESS); + /* FIXME: + * The initial thread isn't a real ETHREAD object, we cannot call PspExitThread. + */ + PspExitThread(STATUS_SUCCESS); #else - while (1) { - LARGE_INTEGER Timeout; - Timeout.QuadPart = 0x7fffffffffffffffLL; - KeDelayExecutionThread(KernelMode, FALSE, &Timeout); - } -#endif - } else { - - /* Do application processor initialization */ - KeApplicationProcessorInitDispatcher(); - - /* Lower IRQL and go to Idle Thread */ - KeLowerIrql(PASSIVE_LEVEL); - PsIdleThreadMain(NULL); + while (1) + { + LARGE_INTEGER Timeout; + Timeout.QuadPart = 0x7fffffffffffffffLL; + KeDelayExecutionThread(KernelMode, FALSE, &Timeout); } +#endif /* Bug Check and loop forever if anything failed */ KEBUGCHECK(0); diff --git a/reactos/ntoskrnl/ntoskrnl.def b/reactos/ntoskrnl/ntoskrnl.def index 6823ac31202..952686596cb 100644 --- a/reactos/ntoskrnl/ntoskrnl.def +++ b/reactos/ntoskrnl/ntoskrnl.def @@ -513,9 +513,6 @@ KdPollBreakIn@0 KdPowerTransition@4 KdpServiceDispatcher@12 Ke386CallBios@8 -Ke386IoSetAccessProcess@8 -Ke386QueryIoAccessMap@8 -Ke386SetIoAccessMap@8 @KeAcquireGuardedMutex@4 @KeAcquireGuardedMutexUnsafe@4 KeAcquireSpinLockAtDpcLevel@4