2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 #include <platforms.h>
56 #include <i386/proc_reg.h>
60 #include <sqt/asm_macros.h>
67 #define CX(addr, reg) addr(,reg,4)
70 * Context switch routines for i386.
74 movl S_ARG0,%ecx /* get thread */
75 movl TH_KERNEL_STACK(%ecx),%ecx /* get kernel stack */
76 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%edx
77 /* point to stack top */
78 movl %ecx,%gs:CPU_ACTIVE_STACK /* store stack address */
79 movl %edx,%gs:CPU_KERNEL_STACK /* store stack top */
84 xorl %eax,%eax /* return zero (no old thread) */
86 call EXT(thread_continue)
89 * This really only has to save registers
90 * when there is no explicit continuation.
94 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
96 movl %ebx,KSS_EBX(%ecx) /* save registers */
97 movl %ebp,KSS_EBP(%ecx)
98 movl %edi,KSS_EDI(%ecx)
99 movl %esi,KSS_ESI(%ecx)
100 popl KSS_EIP(%ecx) /* save return PC */
101 movl %esp,KSS_ESP(%ecx) /* save SP */
103 movl 0(%esp),%eax /* return old thread */
104 movl 8(%esp),%ebx /* get new thread */
105 movl %ebx,%gs:CPU_ACTIVE_THREAD /* new thread is active */
106 movl TH_KERNEL_STACK(%ebx),%ecx /* get its kernel stack */
107 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%ebx
108 /* point to stack top */
110 movl %ecx,%gs:CPU_ACTIVE_STACK /* set current stack */
111 movl %ebx,%gs:CPU_KERNEL_STACK /* set stack top */
114 movl $0,%gs:CPU_ACTIVE_KLOADED
116 movl KSS_ESP(%ecx),%esp /* switch stacks */
117 movl KSS_ESI(%ecx),%esi /* restore registers */
118 movl KSS_EDI(%ecx),%edi
119 movl KSS_EBP(%ecx),%ebp
120 movl KSS_EBX(%ecx),%ebx
121 jmp *KSS_EIP(%ecx) /* return old thread */
123 Entry(Thread_continue)
124 pushl %eax /* push the thread argument */
125 xorl %ebp,%ebp /* zero frame pointer */
126 call *%ebx /* call real continuation */
129 * void machine_processor_shutdown(thread_t thread,
130 * void (*routine)(processor_t),
131 * processor_t processor)
133 * saves the kernel context of the thread,
134 * switches to the interrupt stack,
135 * continues the thread (with thread_continue),
136 * then runs routine on the interrupt stack.
138 * Assumes that the thread is a kernel thread (thus
141 Entry(machine_processor_shutdown)
142 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
143 movl %ebx,KSS_EBX(%ecx) /* save registers */
144 movl %ebp,KSS_EBP(%ecx)
145 movl %edi,KSS_EDI(%ecx)
146 movl %esi,KSS_ESI(%ecx)
147 popl KSS_EIP(%ecx) /* save return PC */
148 movl %esp,KSS_ESP(%ecx) /* save SP */
150 movl 0(%esp),%eax /* get old thread */
151 movl %ecx,TH_KERNEL_STACK(%eax) /* save old stack */
152 movl 4(%esp),%ebx /* get routine to run next */
153 movl 8(%esp),%esi /* get its argument */
155 movl %gs:CPU_INT_STACK_TOP,%esp /* switch to interrupt stack */
157 pushl %esi /* push argument */
158 call *%ebx /* call routine to run */
159 hlt /* (should never return) */
164 .globl EXT(locore_end)