d0b1e87755a8bb79cc4d37ae5ecab30dd6e6c56e
[reactos.git] / reactos / ntoskrnl / ke / i386 / boot.S
1 /*
2 * FILE: ntoskrnl/ke/i386/boot.S
3 * COPYRIGHT: See COPYING in the top level directory
4 * PURPOSE: FreeLDR Wrapper Bootstrap Code and Bootstrap Trampoline
5 * PROGRAMMERs: Alex Ionescu (alex@relsoft.net)
6 * Thomas Weidenmueller <w3seek@reactos.org>
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include <asm.h>
12 .intel_syntax noprefix
13
14 /* GLOBALS *******************************************************************/
15
16 .bss
17 .align 16
18
19 /* Kernel Boot Stack */
20 .globl _P0BootStack
21 .space KERNEL_STACK_SIZE
22 _P0BootStack:
23
24 /* Kernel Double-Fault and Temporary DPC Stack */
25 .globl _KiDoubleFaultStack
26 .space KERNEL_STACK_SIZE
27 _KiDoubleFaultStack:
28
29 /* FUNCTIONS *****************************************************************/
30
31 .text
32 .func NtProcessStartup
33 _NtProcessStartup:
34
35 /* NTLDR Boot: Call the main kernel initialization */
36 test dword ptr [esp+4], 0x80000000
37 jnz _KiSystemStartup@4
38
39 /* FREELDR Boot: Cal the FreeLDR wrapper */
40 jmp @KiRosPrepareForSystemStartup@8
41 .endfunc
42
43 .globl _KiSetupStackAndInitializeKernel@24
44 .func KiSetupStackAndInitializeKernel@24
45 _KiSetupStackAndInitializeKernel@24:
46
47 /* Save current stack */
48 mov esi, esp
49
50 /* Setup the new stack */
51 mov esp, [esp+12]
52 sub esp, NPX_FRAME_LENGTH + KTRAP_FRAME_ALIGN + KTRAP_FRAME_LENGTH
53 push CR0_EM + CR0_TS + CR0_MP
54
55 /* Copy all parameters to the new stack */
56 push [esi+24]
57 push [esi+20]
58 push [esi+16]
59 push [esi+12]
60 push [esi+8]
61 push [esi+4]
62 xor ebp, ebp
63 call _KiInitializeKernel@24
64
65 /* Set the priority of this thread to 0 */
66 mov ebx, PCR[KPCR_CURRENT_THREAD]
67 mov byte ptr [ebx+KTHREAD_PRIORITY], 0
68
69 /* Force interrupts enabled and lower IRQL back to DISPATCH_LEVEL */
70 sti
71 mov ecx, DISPATCH_LEVEL
72 call @KfLowerIrql@4
73
74 /* Set the right wait IRQL */
75 mov byte ptr [ebx+KTHREAD_WAIT_IRQL], DISPATCH_LEVEL;
76
77 /* Jump into the idle loop */
78 jmp @KiIdleLoop@0
79 .endfunc