ReactOS  0.4.15-dev-1070-ge1a01de
ctxswitch.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
#include <ppcmmu/mmu.h>
Include dependency graph for ctxswitch.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI KiThreadStartup (PKSYSTEM_ROUTINE SystemRoutine, PKSTART_ROUTINE StartRoutine, PVOID StartContext, BOOLEAN UserThread, KTRAP_FRAME TrapFrame)
 
VOID KiDecrementerTrapFinish (PKTRAP_FRAME TrapFrame)
 
VOID FASTCALL KiQueueReadyThread (IN PKTHREAD Thread, IN PKPRCB Prcb)
 
VOID NTAPI KiDecrementerTrap (PKTRAP_FRAME TrapFrame)
 

Variables

PKTHREAD KiLastThread = NULL
 
PKTRAP_FRAME KiLastThreadTrapFrame = NULL
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file ctxswitch.c.

Function Documentation

◆ KiDecrementerTrap()

VOID NTAPI KiDecrementerTrap ( PKTRAP_FRAME  TrapFrame)

Definition at line 85 of file ctxswitch.c.

86 {
87  KIRQL Irql;
88  PKPRCB Prcb = KeGetPcr()->Prcb;
89  if (!KiLastThread)
91 
92  if (KiLastThread->State == Running)
94 
96  KiLastThreadTrapFrame = Prcb->IdleThread->TrapFrame;
97 
98  TrapFrame->OldIrql = KeGetCurrentIrql();
99  *KiLastThreadTrapFrame = *TrapFrame;
100 
101  if (Prcb->NextThread)
102  {
103  Prcb->CurrentThread = Prcb->NextThread;
104  Prcb->NextThread = NULL;
105  }
106  else
107  Prcb->CurrentThread = Prcb->IdleThread;
108 
109  Prcb->CurrentThread->State = Running;
110 
111  KiLastThreadTrapFrame = Prcb->CurrentThread->TrapFrame;
112  KiLastThread = Prcb->CurrentThread;
113 
114  *TrapFrame = *KiLastThreadTrapFrame;
116 
117  if (Irql > TrapFrame->OldIrql)
118  KfRaiseIrql(Irql);
119  else if (Irql < TrapFrame->OldIrql)
120  KfLowerIrql(Irql);
121 
122  /* When we return, we'll go through rfi and be in new thread land */
123  __asm__("mtdec %0" : : "r" (0x1000000)); // Reset the trap
124 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
PKTRAP_FRAME KiLastThreadTrapFrame
Definition: ctxswitch.c:81
_Out_ PKIRQL Irql
Definition: csq.h:179
struct _KTHREAD * NextThread
Definition: ketypes.h:567
#define KeGetPcr()
Definition: ke.h:25
VOID FASTCALL KiQueueReadyThread(IN PKTHREAD Thread, IN PKPRCB Prcb)
Definition: thrdschd.c:70
UCHAR KIRQL
Definition: env_spec_w32.h:591
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
struct _KTHREAD * CurrentThread
Definition: ketypes.h:566
smooth NULL
Definition: ftsmooth.c:416
PKTHREAD KiLastThread
Definition: ctxswitch.c:80
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:790
struct _KTHREAD * IdleThread
Definition: ketypes.h:568
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
UCHAR OldIrql
Definition: ketypes.h:96
volatile UCHAR State
Definition: ketypes.h:1679
#define KeGetCurrentThread
Definition: hal.h:44

◆ KiDecrementerTrapFinish()

VOID KiDecrementerTrapFinish ( PKTRAP_FRAME  TrapFrame)

◆ KiQueueReadyThread()

VOID FASTCALL KiQueueReadyThread ( IN PKTHREAD  Thread,
IN PKPRCB  Prcb 
)

Definition at line 70 of file thrdschd.c.

72 {
73  /* Call the macro. We keep the API for compatibility with ASM code */
75 }
FORCEINLINE VOID KxQueueReadyThread(IN PKTHREAD Thread, IN PKPRCB Prcb)
Definition: ke_x.h:1347
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653

Referenced by KiDecrementerTrap().

◆ KiThreadStartup()

VOID NTAPI KiThreadStartup ( PKSYSTEM_ROUTINE  SystemRoutine,
PKSTART_ROUTINE  StartRoutine,
PVOID  StartContext,
BOOLEAN  UserThread,
KTRAP_FRAME  TrapFrame 
)

Definition at line 50 of file ctxswitch.c.

55 {
57  __asm__("mr 0,%0\n\t"
58  "mr 3,%1\n\t"
59  "mr 4,%2\n\t"
60  "mr 5,%3\n\t"
61  "mr 6,%4\n\t"
62  "sc" : :
63  "r" (0xf0000), /* Thread start function */
64  "r" (SystemRoutine),
65  "r" (StartRoutine),
66  "r" (StartContext),
67  "r" (UserThread));
69 }
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define PsGetCurrentThread()
Definition: env_spec_w32.h:81
_In_ ULONG _In_opt_ POBJECT_ATTRIBUTES _In_opt_ HANDLE _Out_opt_ PCLIENT_ID _In_ PKSTART_ROUTINE StartRoutine
Definition: psfuncs.h:87
#define TRUE
Definition: types.h:120
#define STATUS_THREAD_IS_TERMINATING
Definition: ntstatus.h:311
__asm__("\t.globl GetPhys\n" "GetPhys:\t\n" "mflr 0\n\t" "stwu 0,-16(1)\n\t" "mfmsr 5\n\t" "andi. 6,5,0xffef\n\t" "mtmsr 6\n\t" "isync\n\t" "sync\n\t" "lwz 3,0(3)\n\t" "mtmsr 5\n\t" "isync\n\t" "sync\n\t" "lwz 0,0(1)\n\t" "addi 1,1,16\n\t" "mtlr 0\n\t" "blr")
NTSTATUS NTAPI PspTerminateThreadByPointer(IN PETHREAD Thread, IN NTSTATUS ExitStatus, IN BOOLEAN bSelf)
Definition: kill.c:987
#define APC_LEVEL
Definition: env_spec_w32.h:695

Variable Documentation

◆ KiLastThread

PKTHREAD KiLastThread = NULL

Definition at line 80 of file ctxswitch.c.

Referenced by KiDecrementerTrap().

◆ KiLastThreadTrapFrame

PKTRAP_FRAME KiLastThreadTrapFrame = NULL

Definition at line 81 of file ctxswitch.c.

Referenced by KiDecrementerTrap().