3 * Copyright (C) 2000 David Welch <welch@cwcom.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * FILE: ntoskrnl/ke/i386/tskswitch.S
21 * PURPOSE: Microkernel thread support
22 * PROGRAMMER: David Welch (welch@cwcom.net)
27 /* INCLUDES ******************************************************************/
29 #include <internal/i386/segment.h>
30 #include <internal/ps.h>
32 #include <internal/ntoskrnl.h>
34 /* FUNCTIONS ****************************************************************/
36 .globl _Ki386ContextSwitch
39 * FUNCTIONS: Switches to another thread's context
41 * Thread = Thread to switch to
42 * OldThread = Thread to switch from
48 * Save callee save registers.
55 * This is a critical section for this processor.
60 * Get the pointer to the new thread.
65 * Set the base of the TEB selector to the base of the TEB for
69 pushl KTHREAD_TEB(%ebx)
71 call _KeSetBaseGdtSelector
76 * Load the PCR selector.
78 movl $PCR_SELECTOR, %eax
82 * Set the current thread information in the PCR.
84 movl %ebx, %fs:KPCR_CURRENT_THREAD
90 movl KTHREAD_APCSTATE_PROCESS(%ebx), %edi
91 testw $0xFFFF, KPROCESS_LDT_DESCRIPTOR0(%edi)
94 pushl KPROCESS_LDT_DESCRIPTOR1(%edi)
95 pushl KPROCESS_LDT_DESCRIPTOR0(%edi)
97 call _KeSetGdtSelector
100 movl $LDT_SELECTOR, %eax
106 * Load up the iomap offset for this thread in
107 * preparation for setting it below.
109 movl KPROCESS_IOPM_OFFSET(%edi), %eax
112 * FIXME: Save debugging state.
116 * FIXME: Save floating point state.
123 movl %esp, KTHREAD_KERNEL_STACK(%ebx)
125 movl KTHREAD_KERNEL_STACK(%ebx), %esp
126 movl KTHREAD_STACK_LIMIT(%ebx), %edi
129 * Set the stack pointer in this processors TSS
131 movl %fs:KPCR_TSS, %esi
134 * Set current IOPM offset in the TSS
136 movw %ax, KTSS_IOMAPBASE(%esi)
138 movl KTHREAD_INITIAL_STACK(%ebx), %eax
139 movl %eax, KTSS_ESP0(%esi)
142 * Change the address space
144 movl KTHREAD_APCSTATE_PROCESS(%ebx), %ebx
145 movl KPROCESS_DIRECTORY_TABLE_BASE(%ebx), %eax
149 * FIXME: Restore floating point state
153 * FIXME: Restore debugging state
157 * Exit the critical section
162 call _KeReleaseSpinLockFromDpcLevel@4
164 cmpl $0, _PiNrThreadsAwaitingReaping
166 call _PiWakeupReaperThread@0
170 * Restore the saved register and exit