1/* 2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 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. 11 * 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 18 * under the License. 19 * 20 * @APPLE_LICENSE_HEADER_END@ 21 */ 22/* 23 * @OSF_COPYRIGHT@ 24 */ 25/* 26 * Mach Operating System 27 * Copyright (c) 1991,1990 Carnegie Mellon University 28 * All Rights Reserved. 29 * 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. 35 * 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. 39 * 40 * Carnegie Mellon requests users of this software to return to 41 * 42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 43 * School of Computer Science 44 * Carnegie Mellon University 45 * Pittsburgh PA 15213-3890 46 * 47 * any improvements or extensions that they make and grant Carnegie Mellon 48 * the rights to redistribute these changes. 49 */ 50/* 51 */ 52 53#include <platforms.h> 54 55#include <i386/asm.h> 56#include <i386/proc_reg.h> 57#include <assym.s> 58 59#ifdef SYMMETRY 60#include <sqt/asm_macros.h> 61#endif 62 63#if AT386 64#include <i386/mp.h> 65#endif /* AT386 */ 66 67#define CX(addr, reg) addr(,reg,4) 68 69/* 70 * Context switch routines for i386. 71 */ 72 73Entry(Load_context) 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 */ 80 81 movl %edx,%esp 82 movl %edx,%ebp 83 84 xorl %eax,%eax /* return zero (no old thread) */ 85 pushl %eax 86 call EXT(thread_continue) 87 88/* 89 * This really only has to save registers 90 * when there is no explicit continuation. 91 */ 92 93Entry(Switch_context) 94 movl %gs:CPU_ACTIVE_STACK,%ecx /* get old kernel stack */ 95 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 */ 102 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 */ 109 110 movl %ecx,%gs:CPU_ACTIVE_STACK /* set current stack */ 111 movl %ebx,%gs:CPU_KERNEL_STACK /* set stack top */ 112 113 114 movl $0,%gs:CPU_ACTIVE_KLOADED 115 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 */ 122 123Entry(Thread_continue) 124 pushl %eax /* push the thread argument */ 125 xorl %ebp,%ebp /* zero frame pointer */ 126 call *%ebx /* call real continuation */ 127 128/* 129 * void machine_processor_shutdown(thread_t thread, 130 * void (*routine)(processor_t), 131 * processor_t processor) 132 * 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. 137 * 138 * Assumes that the thread is a kernel thread (thus 139 * has no FPU state) 140 */ 141Entry(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 */ 149 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 */ 154 155 movl %gs:CPU_INT_STACK_TOP,%esp /* switch to interrupt stack */ 156 157 pushl %esi /* push argument */ 158 call *%ebx /* call routine to run */ 159 hlt /* (should never return) */ 160 161 162 .text 163 164 .globl EXT(locore_end) 165LEXT(locore_end) 166 167

