2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: ntoskrnl/ke/arm/thrdini.c
5 * PURPOSE: Implements thread context setup and startup for ARM machines
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 typedef struct _KUINIT_FRAME
19 KEXCEPTION_FRAME CtxSwitchFrame
;
20 KEXCEPTION_FRAME ExceptionFrame
;
21 KTRAP_FRAME TrapFrame
;
22 } KUINIT_FRAME
, *PKUINIT_FRAME
;
24 typedef struct _KKINIT_FRAME
26 KEXCEPTION_FRAME CtxSwitchFrame
;
27 } KKINIT_FRAME
, *PKKINIT_FRAME
;
29 /* FUNCTIONS ******************************************************************/
33 KiThreadStartup(VOID
);
37 KeArmInitThreadWithContext(IN PKTHREAD Thread
,
38 IN PKSYSTEM_ROUTINE SystemRoutine
,
39 IN PKSTART_ROUTINE StartRoutine
,
40 IN PVOID StartContext
,
41 IN PCONTEXT ContextPointer
)
43 PKTRAP_FRAME TrapFrame
;
44 PKEXCEPTION_FRAME ExceptionFrame
= NULL
, CtxSwitchFrame
;
47 // Check if this is a user thread
52 // Setup the initial frame
54 PKUINIT_FRAME InitFrame
;
55 InitFrame
= (PKUINIT_FRAME
)((ULONG_PTR
)Thread
->InitialStack
-
56 sizeof(KUINIT_FRAME
));
59 // Setup the Trap Frame and Exception frame
61 TrapFrame
= &InitFrame
->TrapFrame
;
62 ExceptionFrame
= &InitFrame
->ExceptionFrame
;
65 // Zero out the trap frame and exception frame
67 RtlZeroMemory(TrapFrame
, sizeof(KTRAP_FRAME
));
68 RtlZeroMemory(ExceptionFrame
, sizeof(KEXCEPTION_FRAME
));
71 // Set up a trap frame from the context
73 KeContextToTrapFrame(ContextPointer
,
76 ContextPointer
->ContextFlags
| CONTEXT_CONTROL
,
80 // Set the previous mode as user
82 //TrapFrame->PreviousMode = UserMode;
83 Thread
->PreviousMode
= UserMode
;
86 // Clear the return address
88 ExceptionFrame
->Lr
= 0;
91 // Context switch frame to setup below
93 CtxSwitchFrame
= &InitFrame
->CtxSwitchFrame
;
98 // Set up the Initial Frame for the system thread
100 PKKINIT_FRAME InitFrame
;
101 InitFrame
= (PKKINIT_FRAME
)((ULONG_PTR
)Thread
->InitialStack
-
102 sizeof(KKINIT_FRAME
));
105 // Set the previous mode as kernel
107 Thread
->PreviousMode
= KernelMode
;
110 // Context switch frame to setup below
112 CtxSwitchFrame
= &InitFrame
->CtxSwitchFrame
;
116 // Now setup the context switch frame
118 CtxSwitchFrame
->Lr
= (ULONG
)KiThreadStartup
;
119 CtxSwitchFrame
->R11
= (ULONG
)(ExceptionFrame
? ExceptionFrame
: CtxSwitchFrame
);
122 // Set the parameters
124 CtxSwitchFrame
->R4
= (ULONG
)ContextPointer
;
125 CtxSwitchFrame
->R5
= (ULONG
)StartContext
;
126 CtxSwitchFrame
->R6
= (ULONG
)StartRoutine
;
127 CtxSwitchFrame
->R7
= (ULONG
)SystemRoutine
;
130 // Save back the new value of the kernel stack
132 Thread
->KernelStack
= (PVOID
)CtxSwitchFrame
;
133 DPRINT1("NEW THREAD %p WITH EX FRAME AT: %p\n", Thread
, Thread
->KernelStack
);