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>
31 #include <ddk/i386/tss.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
87 * FIXME: Save debugging state.
91 * FIXME: Save floating point state.
98 movl %esp, KTHREAD_KERNEL_STACK(%ebx)
100 movl KTHREAD_KERNEL_STACK(%ebx), %esp
101 movl KTHREAD_STACK_LIMIT(%ebx), %edi
104 * Set the stack pointer in this processors TSS
106 movl KTHREAD_INITIAL_STACK(%ebx), %eax
107 movl %fs:KPCR_TSS, %esi
108 movl %eax, KTSS_ESP0(%esi)
111 * Change the address space
113 movl ETHREAD_THREADS_PROCESS(%ebx), %ebx
114 movl KPROCESS_DIRECTORY_TABLE_BASE(%ebx), %eax
118 * Set up the PDE for the top of the new stack.
123 movl 0xF03C0000(,%esi, 4), %eax
126 movl _MmGlobalKernelPageDirectory(,%esi, 4), %eax
127 movl %eax, 0xF03C0000(,%esi, 4)
131 cmp $(MM_STACK_SIZE / 4096), %ebx
135 * FIXME: Restore floating point state
139 * FIXME: Restore debugging state
143 * Exit the critical section
148 * Restore the saved register and exit