]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/cswitch.s
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / i386 / cswitch.s
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
ff6e181a
A
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
1c79356b 12 *
ff6e181a
A
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24 * @OSF_COPYRIGHT@
25 */
26/*
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51/*
52 */
53
1c79356b
A
54#include <platforms.h>
55
56#include <i386/asm.h>
57#include <i386/proc_reg.h>
58#include <assym.s>
59
1c79356b
A
60#ifdef SYMMETRY
61#include <sqt/asm_macros.h>
62#endif
63
64#if AT386
55e303ae 65#include <i386/mp.h>
1c79356b
A
66#endif /* AT386 */
67
68#define CX(addr, reg) addr(,reg,4)
69
1c79356b
A
70/*
71 * Context switch routines for i386.
72 */
73
74Entry(Load_context)
75 movl S_ARG0,%ecx /* get thread */
76 movl TH_KERNEL_STACK(%ecx),%ecx /* get kernel stack */
77 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%edx
78 /* point to stack top */
91447636
A
79 movl %ecx,%gs:CPU_ACTIVE_STACK /* store stack address */
80 movl %edx,%gs:CPU_KERNEL_STACK /* store stack top */
81
82 movl %edx,%esp
83 movl %edx,%ebp
1c79356b 84
1c79356b 85 xorl %eax,%eax /* return zero (no old thread) */
91447636
A
86 pushl %eax
87 call EXT(thread_continue)
1c79356b
A
88
89/*
90 * This really only has to save registers
91 * when there is no explicit continuation.
92 */
93
94Entry(Switch_context)
91447636 95 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
1c79356b
A
96
97 movl %ebx,KSS_EBX(%ecx) /* save registers */
98 movl %ebp,KSS_EBP(%ecx)
99 movl %edi,KSS_EDI(%ecx)
100 movl %esi,KSS_ESI(%ecx)
101 popl KSS_EIP(%ecx) /* save return PC */
102 movl %esp,KSS_ESP(%ecx) /* save SP */
103
55e303ae 104 movl 0(%esp),%eax /* return old thread */
91447636
A
105 movl 8(%esp),%ebx /* get new thread */
106 movl %ebx,%gs:CPU_ACTIVE_THREAD /* new thread is active */
107 movl TH_KERNEL_STACK(%ebx),%ecx /* get its kernel stack */
1c79356b
A
108 lea KERNEL_STACK_SIZE-IKS_SIZE-IEL_SIZE(%ecx),%ebx
109 /* point to stack top */
110
91447636
A
111 movl %ecx,%gs:CPU_ACTIVE_STACK /* set current stack */
112 movl %ebx,%gs:CPU_KERNEL_STACK /* set stack top */
1c79356b 113
55e303ae 114
91447636 115 movl $0,%gs:CPU_ACTIVE_KLOADED
55e303ae 116
1c79356b
A
117 movl KSS_ESP(%ecx),%esp /* switch stacks */
118 movl KSS_ESI(%ecx),%esi /* restore registers */
119 movl KSS_EDI(%ecx),%edi
120 movl KSS_EBP(%ecx),%ebp
121 movl KSS_EBX(%ecx),%ebx
122 jmp *KSS_EIP(%ecx) /* return old thread */
123
124Entry(Thread_continue)
125 pushl %eax /* push the thread argument */
126 xorl %ebp,%ebp /* zero frame pointer */
127 call *%ebx /* call real continuation */
128
1c79356b 129/*
91447636 130 * void machine_processor_shutdown(thread_t thread,
1c79356b
A
131 * void (*routine)(processor_t),
132 * processor_t processor)
133 *
134 * saves the kernel context of the thread,
135 * switches to the interrupt stack,
136 * continues the thread (with thread_continue),
137 * then runs routine on the interrupt stack.
138 *
139 * Assumes that the thread is a kernel thread (thus
140 * has no FPU state)
141 */
91447636
A
142Entry(machine_processor_shutdown)
143 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */
1c79356b
A
144 movl %ebx,KSS_EBX(%ecx) /* save registers */
145 movl %ebp,KSS_EBP(%ecx)
146 movl %edi,KSS_EDI(%ecx)
147 movl %esi,KSS_ESI(%ecx)
148 popl KSS_EIP(%ecx) /* save return PC */
149 movl %esp,KSS_ESP(%ecx) /* save SP */
150
151 movl 0(%esp),%eax /* get old thread */
1c79356b
A
152 movl %ecx,TH_KERNEL_STACK(%eax) /* save old stack */
153 movl 4(%esp),%ebx /* get routine to run next */
154 movl 8(%esp),%esi /* get its argument */
155
91447636 156 movl %gs:CPU_INT_STACK_TOP,%esp /* switch to interrupt stack */
1c79356b
A
157
158 pushl %esi /* push argument */
159 call *%ebx /* call routine to run */
160 hlt /* (should never return) */
161
1c79356b
A
162
163 .text
164
165 .globl EXT(locore_end)
166LEXT(locore_end)
167