From c84fd405bff4f94b76e24aefea49bf7b2dc65781 Mon Sep 17 00:00:00 2001 From: ReactOS Portable Systems Group Date: Wed, 11 Jun 2008 19:13:25 +0000 Subject: [PATCH] - We now implement a skeleton framework for context switching - The only things we do are swap the stack and then display the old/new thread/stack. - More work to be done to actually save the non-volatiles, prepare the thread state, and restore the volatiles for the new thread. - Then we will return to the saved return address, and we should be in Phase 1 with working thread switching/scheduling. svn path=/trunk/; revision=33935 --- reactos/ntoskrnl/include/internal/arm/ksarm.h | 5 ++ reactos/ntoskrnl/ke/arm/ctxswtch.s | 50 +++++++++++++++++++ reactos/ntoskrnl/ke/arm/stubs.c | 2 + reactos/ntoskrnl/ke/arm/stubs_asm.s | 3 -- reactos/ntoskrnl/ke/arm/trapc.c | 18 ++++++- reactos/ntoskrnl/ntoskrnl-generic.rbuild | 1 + 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 reactos/ntoskrnl/ke/arm/ctxswtch.s diff --git a/reactos/ntoskrnl/include/internal/arm/ksarm.h b/reactos/ntoskrnl/include/internal/arm/ksarm.h index 98b95061618..17c06dc67b2 100644 --- a/reactos/ntoskrnl/include/internal/arm/ksarm.h +++ b/reactos/ntoskrnl/include/internal/arm/ksarm.h @@ -55,6 +55,11 @@ */ .equ PcCurrentIrql, 0x14C +/* + * KTHREAD Offsets + */ +.equ ThKernelStack, 0x20 + #else /* diff --git a/reactos/ntoskrnl/ke/arm/ctxswtch.s b/reactos/ntoskrnl/ke/arm/ctxswtch.s new file mode 100644 index 00000000000..6b28048ed91 --- /dev/null +++ b/reactos/ntoskrnl/ke/arm/ctxswtch.s @@ -0,0 +1,50 @@ +/* + * PROJECT: ReactOS Kernel + * LICENSE: GPL - See COPYING in the top level directory + * FILE: ntoskrnl/ke/arm/ctxswtch.s + * PURPOSE: Context Switch and Idle Thread on ARM + * PROGRAMMERS: ReactOS Portable Systems Group + */ + + .title "ARM Context Switching" + .include "ntoskrnl/include/internal/arm/kxarm.h" + .include "ntoskrnl/include/internal/arm/ksarm.h" + + TEXTAREA + NESTED_ENTRY KiSwapContext + PROLOG_END KiSwapContext + // + // a1 = Old Thread + // a2 = New Thread + // + + // + // Save volatile registers for the OLD thread + // + + // + // Switch stacks + // + str sp, [a1, #ThKernelStack] + ldr sp, [a2, #ThKernelStack] + + // + // Call the C context switch code + // + bl KiSwapContextInternal + + // + // Restore volatile registers for the NEW thread + // + + // + // Jump to saved restore address + // + + // + // FIXME: TODO + // + b . + + ENTRY_END KiSwapContext + diff --git a/reactos/ntoskrnl/ke/arm/stubs.c b/reactos/ntoskrnl/ke/arm/stubs.c index 6eafcbecfcd..b18c76407ba 100644 --- a/reactos/ntoskrnl/ke/arm/stubs.c +++ b/reactos/ntoskrnl/ke/arm/stubs.c @@ -2,6 +2,8 @@ #define NDEBUG #include "debug.h" +CCHAR KeNumberProcessors; +ULONG KeDcacheFlushCount; ULONG KeActiveProcessors; ULONG KeProcessorArchitecture; ULONG KeProcessorLevel; diff --git a/reactos/ntoskrnl/ke/arm/stubs_asm.s b/reactos/ntoskrnl/ke/arm/stubs_asm.s index ea6442f09b7..8e2b242e01a 100644 --- a/reactos/ntoskrnl/ke/arm/stubs_asm.s +++ b/reactos/ntoskrnl/ke/arm/stubs_asm.s @@ -12,17 +12,14 @@ GENERATE_ARM_STUB _local_unwind2 // // Exported Ke Arch-Specific APIs // -GENERATE_ARM_STUB KiSwapContext GENERATE_ARM_STUB DbgBreakPointWithStatus GENERATE_ARM_STUB KeConnectInterrupt -GENERATE_ARM_STUB KeDcacheFlushCount GENERATE_ARM_STUB KeDisconnectInterrupt GENERATE_ARM_STUB KeFlushEntireTb GENERATE_ARM_STUB KeGetRecommendedSharedDataAlignment GENERATE_ARM_STUB KeIcacheFlushCount GENERATE_ARM_STUB KeInitializeInterrupt GENERATE_ARM_STUB KeInvalidateAllCaches -GENERATE_ARM_STUB KeNumberProcessors GENERATE_ARM_STUB KeQueryActiveProcessors GENERATE_ARM_STUB KeRaiseUserException GENERATE_ARM_STUB KeSaveStateForHibernate diff --git a/reactos/ntoskrnl/ke/arm/trapc.c b/reactos/ntoskrnl/ke/arm/trapc.c index 13da1a188ba..05e5f7dafd4 100644 --- a/reactos/ntoskrnl/ke/arm/trapc.c +++ b/reactos/ntoskrnl/ke/arm/trapc.c @@ -24,7 +24,6 @@ KiSystemCall( IN PULONG Arguments, IN ULONG ArgumentCount ); - /* FUNCTIONS ******************************************************************/ @@ -34,6 +33,18 @@ HalGetInterruptSource(VOID); VOID FASTCALL HalClearSoftwareInterrupt(IN KIRQL Request); +VOID +KiSwapContextInternal(IN PKTHREAD OldThread, + IN PKTHREAD NewThread) +{ + // + // FIXME: TODO + // + DPRINT1("Switching from: %p to %p\n", OldThread, NewThread); + DPRINT1("Stacks: %p %p\n", OldThread->KernelStack, NewThread->KernelStack); + while (TRUE); +} + VOID KiDispatchInterrupt(VOID) { @@ -107,9 +118,12 @@ KiDispatchInterrupt(VOID) // // Swap to the new thread + // On ARM we call KiSwapContext instead of KiSwapContextInternal, + // because we're calling this from C code and not assembly. + // This is similar to how it gets called for unwaiting, on x86 // DPRINT1("Swapping context!\n"); - //KiSwapContextInternal(); + KiSwapContext(OldThread, NewThread); while (TRUE); } } diff --git a/reactos/ntoskrnl/ntoskrnl-generic.rbuild b/reactos/ntoskrnl/ntoskrnl-generic.rbuild index 51c35f9c41a..b5e1fd572ce 100644 --- a/reactos/ntoskrnl/ntoskrnl-generic.rbuild +++ b/reactos/ntoskrnl/ntoskrnl-generic.rbuild @@ -63,6 +63,7 @@ boot.s arm_kprintf.c cpu.c + ctxswtch.s exp.c kiinit.c stubs_asm.s