2 * PROJECT: ReactOS Kernel
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: ntoskrnl/ke/arm/ctxswtch.s
5 * PURPOSE: Context Switch and Idle Thread on ARM
6 * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7 * ReactOS Portable Systems Group
17 * \name KiSwapContextInternal
20 * The KiSwapContextInternal routine switches context to another thread.
23 * Pointer to the KTHREAD to which the caller wishes to switch to.
26 * Pointer to the KTHREAD to which the caller wishes to switch from.
38 NESTED_ENTRY KiSwapContextInternal
40 /* Push a KSWITCH_FRAME on the stack */
41 stmdb sp!,{r2,r3,r11,lr} // FIXME: what is the 2nd field?
42 // PROLOG_PUSH {r2,r3,r11,lr}
44 PROLOG_END KiSwapContextInternal
46 /* Save kernel stack of old thread */
47 str sp, [r1, #ThKernelStack]
49 /* Save new thread in R11 */
52 //bl KiSwapContextSuspend
55 /* Load stack of new thread */
56 ldr sp, [r11, #ThKernelStack]
58 /* Reload APC bypass */
59 ldr r2, [sp, #SwApcBypass]
61 //bl KiSwapContextResume
64 /* Restore R2, R11 and return */
65 ldmia sp!,{r2,r3,r11,pc}
67 NESTED_END KiSwapContextInternal
74 * The KiSwapContext routine switches context to another thread.
78 * _In_ KIRQL WaitIrql,
79 * _Inout_ PKTHREAD CurrentThread);
81 * \param WaitIrql <r0>
84 * \param CurrentThread <r1>
85 * Pointer to the KTHREAD of the current thread.
88 * The WaitStatus of the Target Thread.
91 * This is a wrapper around KiSwapContextInternal which will save all the
92 * non-volatile registers so that the Internal function can use all of
93 * them. It will also save the old current thread and set the new one.
95 * The calling thread does not return after KiSwapContextInternal until
96 * another thread switches to it.
99 NESTED_ENTRY KiSwapContext
101 /* Push non-volatiles and return address on the stack */
102 stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,lr}
103 // PROLOG_PUSH {r4,r5,r6,r7,r8,r9,r10,r11,lr}
105 PROLOG_END KiSwapContext
107 /* Do the swap with the registers correctly setup */
108 mov32 r0, 0xFFDFF000 // FIXME: properly load the PCR into r0 (PCR should be in CP15, c3, TPIDRPRW)
109 ldr r0, [r0, #PcCurrentThread] /* Pointer to the new thread */
110 bl KiSwapContextInternal
112 /* Restore non-volatiles and return */
113 ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
115 NESTED_END KiSwapContext
119 NESTED_ENTRY KiThreadStartup
120 PROLOG_END KiThreadStartup
122 /* Lower IRQL to APC_LEVEL */
126 /* Set the start address and startup context */
131 /* The function must not return! */
134 NESTED_END KiThreadStartup
137 NESTED_ENTRY KiSwitchThreads
138 PROLOG_END KiSwitchThreads
143 NESTED_END KiSwitchThreads