|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* HISTORY
26:
27: 1997/05/16 Rene Vega-- Cleanup sync/isync usage.
28: */
29:
30: /*
31: * Copyright 1996 1995 by Open Software Foundation, Inc. 1997 1996 1995 1994 1993 1992 1991
32: * All Rights Reserved
33: *
34: * Permission to use, copy, modify, and distribute this software and
35: * its documentation for any purpose and without fee is hereby granted,
36: * provided that the above copyright notice appears in all copies and
37: * that both the copyright notice and this permission notice appear in
38: * supporting documentation.
39: *
40: * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
41: * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
42: * FOR A PARTICULAR PURPOSE.
43: *
44: * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
45: * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
46: * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
47: * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
48: * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
49: */
50: /*
51: * MKLINUX-1.0DR2
52: */
53:
54: #include <machdep/ppc/asm.h>
55: #include <machdep/ppc/proc_reg.h>
56: #include <cpus.h>
57: #include <assym.h>
58: #include <debug.h>
59: #include <mach/ppc/vm_param.h>
60:
61: .text
62: .align 2
63:
64: /*
65: * void load_context(thread_t thread)
66: *
67: * Load the context for the first kernel thread, and go.
68: * TODO NMGS - assumes single CPU.
69: *
70: * NOTE - if DEBUG is set, the former routine is a piece
71: * of C capable of printing out debug info before calling the latter,
72: * otherwise both entry points are identical.
73: */
74:
75: #if DEBUG
76: ENTRY(Load_context, TAG_NO_FRAME_USED)
77: #else
78: ENTRY2(load_context, Load_context, TAG_NO_FRAME_USED)
79: #endif /* DEBUG */
80:
81: /*
82: * Since this is the first thread, we came in on the interrupt
83: * stack. The first thread never returns, so there is no need to
84: * worry about saving its frame, hence we can reset the istackptr
85: * back to the saved_state structure at it's top
86: */
87:
88: addis r11, 0, ha16(EXT(intstack_top_ss))
89: addi r11, r11, lo16(EXT(intstack_top_ss))
90: lwz r0, 0(r11)
91:
92: addis r11, 0, ha16(EXT(istackptr))
93: addi r11, r11, lo16(EXT(istackptr))
94: stw r0, 0(r11)
95:
96: /*
97: * get new thread pointer and set it into the active_threads pointer
98: *
99: * Never set any break points in these instructions since it
100: * may cause a kernel stack overflow. (warning from HP code)
101: */
102:
103: mfsprg r2, 0 /* HACK - need to get around r2 problem */
104: lwz r11, PP_CPU_DATA(r2)
105: stw ARG0, CPU_ACTIVE_THREAD(r11)
106:
107: /* Find the new stack and store it in active_stacks */
108:
109: lwz r1, THREAD_KERNEL_STACK(ARG0)
110: lwz r12, PP_ACTIVE_STACKS(r2)
111: stw r1, 0(r12)
112:
113: /*
114: * This is the end of the no break points region.
115: */
116:
117: /* Restore the callee save registers. The KS constants are
118: * from the bottom of the stack, pointing to a structure
119: * at the top of the stack
120: */
121: lwz r13, KS_R13(r1)
122: lwz r14, KS_R13+1*4(r1)
123: lwz r15, KS_R13+2*4(r1)
124: lwz r16, KS_R13+3*4(r1)
125: lwz r17, KS_R13+4*4(r1)
126: lwz r18, KS_R13+5*4(r1)
127: lwz r19, KS_R13+6*4(r1)
128: lwz r20, KS_R13+7*4(r1)
129: lwz r21, KS_R13+8*4(r1)
130: lwz r22, KS_R13+9*4(r1)
131: lwz r23, KS_R13+10*4(r1)
132: lwz r24, KS_R13+11*4(r1)
133: lwz r25, KS_R13+12*4(r1)
134: lwz r26, KS_R13+13*4(r1)
135: lwz r27, KS_R13+14*4(r1)
136: lwz r28, KS_R13+15*4(r1)
137: lwz r29, KS_R13+16*4(r1)
138: lwz r30, KS_R13+17*4(r1)
139: lwz r31, KS_R13+18*4(r1)
140:
141: /*
142: * Since this is the first thread, we make sure that thread_continue
143: * gets a zero as its argument.
144: */
145:
146: li ARG0, 0
147:
148: lwz r0, KS_CR(r1)
149: mtcrf 0xFF,r0
150: lwz r0, KS_LR(r1)
151: mtlr r0
152: lwz r1, KS_R1(r1) /* Load new stack pointer */
153: stw ARG0, FM_BACKPTR(r1) /* zero backptr */
154: blr /* Jump to the continuation */
155:
156: /* void Call_continuation( void (*continuation)(void), vm_offset_t stack_ptr)
157: */
158:
159: ENTRY(Call_continuation, TAG_NO_FRAME_USED)
160: mtlr r3
161: mr r1, r4 /* Load new stack pointer */
162: blr /* Jump to the continuation */
163:
164:
165:
166: /* struct thread_t Switch_context(thread_t old,
167: * void (*cont)(void),
168: * thread_t *new)
169: *
170: * Switch from one thread to another. If a continuation is supplied, then
171: * we do not need to save callee save registers.
172: *
173: * TODO NMGS Assumes single CPU
174: */
175:
176: ENTRY(Switch_context, TAG_NO_FRAME_USED)
177:
178: /*
179: * Get the old kernel stack, and store into the thread structure.
180: * See if a continuation is supplied, and skip state save if so.
181: * NB. Continuations are no longer used, so this test is omitted,
182: * as should the second argument, but it is in generic code.
183: * We always save state. This does not hurt even if continuations
184: * are put back in.
185: */
186:
187: stw r2, FM_TOC_SAVE(r1)
188: mfsprg r2, 0 /* HACK - need to get around r2 problem */
189: lwz r12, PP_ACTIVE_STACKS(r2)
190: cmpwi CR0, ARG1, 0 /* Continuation? */
191: lwz r11, 0(r12)
192: stw ARG1, THREAD_SWAPFUNC(ARG0)
193: stw r11, THREAD_KERNEL_STACK(ARG0)
194: bne CR0, .L_sw_ctx_no_save /* Yes, skip save */
195: /*
196: * Save all the callee save registers plus state.
197: */
198:
199: /* the KS_ constants point to the offset from the bottom of the
200: * stack to the ppc_kernel_state structure at the top, thus
201: * r11 can be used directly
202: */
203: stw r1, KS_R1(r11)
204: lwz r0, FM_TOC_SAVE(r1)
205: stw r0, KS_R2(r11)
206: stw r13, KS_R13(r11)
207: stw r14, KS_R13+1*4(r11)
208: stw r15, KS_R13+2*4(r11)
209: stw r16, KS_R13+3*4(r11)
210: stw r17, KS_R13+4*4(r11)
211: stw r18, KS_R13+5*4(r11)
212: stw r19, KS_R13+6*4(r11)
213: stw r20, KS_R13+7*4(r11)
214: stw r21, KS_R13+8*4(r11)
215: stw r22, KS_R13+9*4(r11)
216: stw r23, KS_R13+10*4(r11)
217: stw r24, KS_R13+11*4(r11)
218: stw r25, KS_R13+12*4(r11)
219: stw r26, KS_R13+13*4(r11)
220: stw r27, KS_R13+14*4(r11)
221: stw r28, KS_R13+15*4(r11)
222: stw r29, KS_R13+16*4(r11)
223: stw r30, KS_R13+17*4(r11)
224: stw r31, KS_R13+18*4(r11)
225:
226: mfcr r0
227: stw r0, KS_CR(r11)
228: mflr r0
229: stw r0, KS_LR(r11)
230:
231: /*
232: * Make the new thread the current thread.
233: */
234: .L_sw_ctx_no_save:
235:
236: lwz r11, PP_CPU_DATA(r2)
237: stw ARG2, CPU_ACTIVE_THREAD(r11)
238:
239: lwz r11, THREAD_KERNEL_STACK(ARG2)
240:
241: lwz r10, PP_ACTIVE_STACKS(r2)
242: stw r11, 0(r10)
243:
244: /*
245: * Restore all the callee save registers.
246: */
247: lwz r1, KS_R1(r11) /* Restore stack pointer */
248:
249: /* Restore the callee save registers */
250: lwz r13, KS_R13(r11)
251: lwz r14, KS_R13+1*4(r11)
252: lwz r15, KS_R13+2*4(r11)
253: lwz r16, KS_R13+3*4(r11)
254: lwz r17, KS_R13+4*4(r11)
255: lwz r18, KS_R13+5*4(r11)
256: lwz r19, KS_R13+6*4(r11)
257: lwz r20, KS_R13+7*4(r11)
258: lwz r21, KS_R13+8*4(r11)
259: lwz r22, KS_R13+9*4(r11)
260: lwz r23, KS_R13+10*4(r11)
261: lwz r24, KS_R13+11*4(r11)
262: lwz r25, KS_R13+12*4(r11)
263: lwz r26, KS_R13+13*4(r11)
264: lwz r27, KS_R13+14*4(r11)
265: lwz r28, KS_R13+15*4(r11)
266: lwz r29, KS_R13+16*4(r11)
267: lwz r30, KS_R13+17*4(r11)
268: lwz r31, KS_R13+18*4(r11)
269:
270: lwz r2, KS_R2(r11)
271: lwz r0, KS_CR(r11)
272: mtcrf 0xFF, r0
273: lwz r0, KS_LR(r11)
274: mtlr r0
275:
276: /* ARG0 still holds old thread pointer, we return this */
277:
278: blr /* Jump into the new thread */
279:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.