Author: greatlrd Date: Tue Aug 7 03:55:35 2007 New Revision: 28205
URL: http://svn.reactos.org/svn/reactos?rev=28205&view=rev Log: Remove init.s and put Thomas's code into boot.s, so we don't have 2 files for the same purpose. Write the few lines of C code that were part of the "final" code into boot.S as well, to avoid yet another trampoline jump. and Thanks again to Thomas for finding and fixing the bug.
Modified: trunk/reactos/include/ndk/asm.h trunk/reactos/ntoskrnl/include/internal/ke.h trunk/reactos/ntoskrnl/ke/i386/boot.S trunk/reactos/ntoskrnl/ke/i386/init.S trunk/reactos/ntoskrnl/ke/i386/kiinit.c trunk/reactos/ntoskrnl/ntoskrnl.rbuild
Modified: trunk/reactos/include/ndk/asm.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/asm.h?rev=28205... ============================================================================== --- trunk/reactos/include/ndk/asm.h (original) +++ trunk/reactos/include/ndk/asm.h Tue Aug 7 03:55:35 2007 @@ -113,6 +113,7 @@ #define KTHREAD_WAIT_IRQL 0x4E #define KTHREAD_NEXT_PROCESSOR 0x40 #define KTHREAD_WAIT_REASON 0x5A +#define KTHREAD_PRIORITY 0x5B #define KTHREAD_SWAP_BUSY 0x5D #define KTHREAD_SERVICE_TABLE 0x118 #define KTHREAD_PREVIOUS_MODE 0xD7 @@ -611,3 +612,4 @@ #endif // !_ASM_H
+
Modified: trunk/reactos/ntoskrnl/include/internal/ke.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/k... ============================================================================== --- trunk/reactos/ntoskrnl/include/internal/ke.h (original) +++ trunk/reactos/ntoskrnl/include/internal/ke.h Tue Aug 7 03:55:35 2007 @@ -831,6 +831,17 @@
VOID NTAPI +KiSetupStackAndInitializeKernel( + IN PKPROCESS InitProcess, + IN PKTHREAD InitThread, + IN PVOID IdleStack, + IN PKPRCB Prcb, + IN CCHAR Number, + IN PLOADER_PARAMETER_BLOCK LoaderBlock +); + +VOID +NTAPI KiInitSpinLocks( IN PKPRCB Prcb, IN CCHAR Number
Modified: trunk/reactos/ntoskrnl/ke/i386/boot.S URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/boot.S?rev... ============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/boot.S (original) +++ trunk/reactos/ntoskrnl/ke/i386/boot.S Tue Aug 7 03:55:35 2007 @@ -1,8 +1,9 @@ /* * FILE: ntoskrnl/ke/i386/boot.S * COPYRIGHT: See COPYING in the top level directory - * PURPOSE: FreeLDR Wrapper Bootstrap Code - * PROGRAMMER: Alex Ionescu (alex@relsoft.net) + * PURPOSE: FreeLDR Wrapper Bootstrap Code and Bootstrap Trampoline + * PROGRAMMERs: Alex Ionescu (alex@relsoft.net) + * Thomas Weidenmueller w3seek@reactos.org */
/* INCLUDES ******************************************************************/ @@ -38,3 +39,41 @@ /* FREELDR Boot: Cal the FreeLDR wrapper */ jmp @KiRosPrepareForSystemStartup@8 .endfunc + +.globl _KiSetupStackAndInitializeKernel@24 +.func KiSetupStackAndInitializeKernel@24 +_KiSetupStackAndInitializeKernel@24: + + /* Save current stack */ + mov esi, esp + + /* Setup the new stack */ + mov esp, [esp+12] + sub esp, NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH + push CR0_EM + CR0_TS + CR0_MP + + /* Copy all parameters to the new stack */ + push [esi+24] + push [esi+20] + push [esi+16] + push [esi+12] + push [esi+8] + push [esi+4] + xor ebp, ebp + call _KiInitializeKernel@24 + + /* Set the priority of this thread to 0 */ + mov ebx, PCR[KPCR_CURRENT_THREAD] + mov byte ptr [ebx+KTHREAD_PRIORITY], 0 + + /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */ + sti + mov ecx, DISPATCH_LEVEL + call @KfLowerIrql@4 + + /* Set the right wait IRQL */ + mov byte ptr [ebx+KTHREAD_WAIT_IRQL], DISPATCH_LEVEL; + + /* Jump into the idle loop */ + jmp @KiIdleLoop@0 +.endfunc
Modified: trunk/reactos/ntoskrnl/ke/i386/init.S URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/init.S?rev... ============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/init.S (original) +++ trunk/reactos/ntoskrnl/ke/i386/init.S Tue Aug 7 03:55:35 2007 @@ -1,39 +1,0 @@ -/* - * FILE: ntoskrnl/ke/i386/init.S - * COPYRIGHT: See COPYING in the top level directory - * PURPOSE: Kernel Initialization - * PROGRAMMER: Thomas Weidenmueller w3seek@reactos.org - */ - -/* INCLUDES ******************************************************************/ - -#include <asm.h> -#include <internal/i386/asmmacro.S> -.intel_syntax noprefix - -/* FUNCTIONS ******************************************************************/ - -.text -.globl _KiSetupStackAndInitializeKernel@24 -.func KiSetupStackAndInitializeKernel@24 -_KiSetupStackAndInitializeKernel@24: - - mov esi, esp - - /* Setup the new stack */ - mov esp, [esp + 12] - sub esp, NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH - push CR0_EM + CR0_TS + CR0_MP - - /* Copy all parameters to the new stack */ - push [esi + 24] - push [esi + 20] - push [esi + 16] - push [esi + 12] - push [esi + 8] - push [esi + 4] - xor ebp, ebp - call _KiInitializeKernel@24 - - jmp _KiSystemStartupFinal@0 -.endfunc
Modified: trunk/reactos/ntoskrnl/ke/i386/kiinit.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/i386/kiinit.c?r... ============================================================================== --- trunk/reactos/ntoskrnl/ke/i386/kiinit.c (original) +++ trunk/reactos/ntoskrnl/ke/i386/kiinit.c Tue Aug 7 03:55:35 2007 @@ -11,16 +11,6 @@ #include <ntoskrnl.h> #define NDEBUG #include <debug.h> - - -VOID -NTAPI -KiSetupStackAndInitializeKernel(IN PKPROCESS InitProcess, - IN PKTHREAD InitThread, - IN PVOID IdleStack, - IN PKPRCB Prcb, - IN CCHAR Number, - IN PLOADER_PARAMETER_BLOCK LoaderBlock);
/* GLOBALS *******************************************************************/
@@ -765,41 +755,11 @@ /* Align stack and make space for the trap frame and NPX frame */ InitialStack &= ~(KTRAP_FRAME_ALIGN - 1);
- /* NOTE: We cannot setup the stack using inline assembly and then later assume - that the compiler is smart enough to figure out how the stack layout - changed! This is to avoid generating wrong code. We cannot directly - call KiInitializeKernel from here! */ - + /* Switch to new kernel stack and start kernel bootstrapping */ KiSetupStackAndInitializeKernel(&KiInitialProcess.Pcb, InitialThread, (PVOID)InitialStack, (PKPRCB)__readfsdword(KPCR_PRCB), (CCHAR)Cpu, KeLoaderBlock); - - /* NOTE: KiSetupStackAndInitializeKernel never returns! Do NOT add any code here! */ - ASSERT(FALSE); } - -VOID -NTAPI -KiSystemStartupFinal(VOID) -{ - /* NOTE: This routine is called after setting up the stack in KiSystemStartup! - This code cannot be moved to KiSystemStartup because it cannot be assumed - that the compiler can generate working code after modifying ESP/EBP - using inline assembly! */ - - /* Set the priority of this thread to 0 */ - KeGetCurrentThread()->Priority = 0; - - /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */ - _enable(); - KfLowerIrql(DISPATCH_LEVEL); - - /* Set the right wait IRQL */ - KeGetCurrentThread()->WaitIrql = DISPATCH_LEVEL; - - /* Jump into the idle loop */ - KiIdleLoop(); -}
Modified: trunk/reactos/ntoskrnl/ntoskrnl.rbuild URL: http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ntoskrnl.rbuild?re... ============================================================================== --- trunk/reactos/ntoskrnl/ntoskrnl.rbuild (original) +++ trunk/reactos/ntoskrnl/ntoskrnl.rbuild Tue Aug 7 03:55:35 2007 @@ -37,7 +37,6 @@ <file>cpu.c</file> <file>ctxswitch.S</file> <file>exp.c</file> - <file>init.S</file> <file>irqobj.c</file> <file>kiinit.c</file> <file>ldt.c</file>