2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 #include <platforms.h>
64 #include <i386/proc_reg.h>
68 #include <sqt/asm_macros.h>
75 #define CX(addr, reg) addr(,reg,4)
78 * Context switch routines for i386.
82 movl S_ARG0,%ecx /* get thread */
83 movl TH_KERNEL_STACK(%ecx),%ecx /* get kernel stack */
84 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%edx
85 /* point to stack top */
86 movl %ecx,%gs:CPU_ACTIVE_STACK /* store stack address */
87 movl %edx,%gs:CPU_KERNEL_STACK /* store stack top */
92 xorl %eax,%eax /* return zero (no old thread) */
94 call EXT(thread_continue)
97 * This really only has to save registers
98 * when there is no explicit continuation.
101 Entry(Switch_context)
102 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
104 movl %ebx,KSS_EBX(%ecx) /* save registers */
105 movl %ebp,KSS_EBP(%ecx)
106 movl %edi,KSS_EDI(%ecx)
107 movl %esi,KSS_ESI(%ecx)
108 popl KSS_EIP(%ecx) /* save return PC */
109 movl %esp,KSS_ESP(%ecx) /* save SP */
111 movl 0(%esp),%eax /* return old thread */
112 movl 8(%esp),%ebx /* get new thread */
113 movl %ebx,%gs:CPU_ACTIVE_THREAD /* new thread is active */
114 movl TH_KERNEL_STACK(%ebx),%ecx /* get its kernel stack */
115 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%ebx
116 /* point to stack top */
118 movl %ecx,%gs:CPU_ACTIVE_STACK /* set current stack */
119 movl %ebx,%gs:CPU_KERNEL_STACK /* set stack top */
122 movl $0,%gs:CPU_ACTIVE_KLOADED
124 movl KSS_ESP(%ecx),%esp /* switch stacks */
125 movl KSS_ESI(%ecx),%esi /* restore registers */
126 movl KSS_EDI(%ecx),%edi
127 movl KSS_EBP(%ecx),%ebp
128 movl KSS_EBX(%ecx),%ebx
129 jmp *KSS_EIP(%ecx) /* return old thread */
131 Entry(Thread_continue)
132 pushl %eax /* push the thread argument */
133 xorl %ebp,%ebp /* zero frame pointer */
134 call *%ebx /* call real continuation */
137 * void machine_processor_shutdown(thread_t thread,
138 * void (*routine)(processor_t),
139 * processor_t processor)
141 * saves the kernel context of the thread,
142 * switches to the interrupt stack,
143 * continues the thread (with thread_continue),
144 * then runs routine on the interrupt stack.
146 * Assumes that the thread is a kernel thread (thus
149 Entry(machine_processor_shutdown)
150 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
151 movl %ebx,KSS_EBX(%ecx) /* save registers */
152 movl %ebp,KSS_EBP(%ecx)
153 movl %edi,KSS_EDI(%ecx)
154 movl %esi,KSS_ESI(%ecx)
155 popl KSS_EIP(%ecx) /* save return PC */
156 movl %esp,KSS_ESP(%ecx) /* save SP */
158 movl 0(%esp),%eax /* get old thread */
159 movl %ecx,TH_KERNEL_STACK(%eax) /* save old stack */
160 movl 4(%esp),%ebx /* get routine to run next */
161 movl 8(%esp),%esi /* get its argument */
163 movl %gs:CPU_INT_STACK_TOP,%esp /* switch to interrupt stack */
165 pushl %esi /* push argument */
166 call *%ebx /* call routine to run */
167 hlt /* (should never return) */
172 .globl EXT(locore_end)