source: rtems/bsps/powerpc/shared/cpu_asm.S @ 9964895

5
Last change on this file since 9964895 was 7dbc43d, checked in by Sebastian Huber <sebastian.huber@…>, on 03/13/18 at 05:18:38

bsps/powerpc: Move basic support to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • Property mode set to 100644
File size: 15.6 KB
Line 
1/*  cpu_asm.s   1.1 - 95/12/04
2 *
3 *  This file contains the assembly code for the PowerPC implementation
4 *  of RTEMS.
5 *
6 *  Author:     Andrew Bray <andy@i-cubed.co.uk>
7 *
8 *  COPYRIGHT (c) 1995 by i-cubed ltd.
9 *
10 *  To anyone who acknowledges that this file is provided "AS IS"
11 *  without any express or implied warranty:
12 *      permission to use, copy, modify, and distribute this file
13 *      for any purpose is hereby granted without fee, provided that
14 *      the above copyright notice and this notice appears in all
15 *      copies, and that the name of i-cubed limited not be used in
16 *      advertising or publicity pertaining to distribution of the
17 *      software without specific, written prior permission.
18 *      i-cubed limited makes no representations about the suitability
19 *      of this software for any purpose.
20 *
21 *  Derived from c/src/exec/cpu/no_cpu/cpu_asm.c:
22 *
23 *  COPYRIGHT (c) 1989-1997.
24 *  On-Line Applications Research Corporation (OAR).
25 *
26 *  Copyright (c) 2011, 2017 embedded brains GmbH
27 *
28 *  The license and distribution terms for this file may in
29 *  the file LICENSE in this distribution or at
30 *  http://www.rtems.org/license/LICENSE.
31 */
32
33#include <rtems/asm.h>
34#include <rtems/powerpc/powerpc.h>
35#include <rtems/score/percpu.h>
36#include <libcpu/powerpc-utility.h>
37#include <bspopts.h>
38
39#ifdef BSP_USE_DATA_CACHE_BLOCK_TOUCH
40  #define DATA_CACHE_TOUCH(rega, regb) \
41        dcbt rega, regb
42#else
43  #define DATA_CACHE_TOUCH(rega, regb)
44#endif
45
46#if BSP_DATA_CACHE_ENABLED && PPC_DEFAULT_CACHE_LINE_SIZE == 32
47  #define DATA_CACHE_ZERO_AND_TOUCH(reg, offset) \
48        li reg, offset; dcbz reg, r3; DATA_CACHE_TOUCH(reg, r4)
49#else
50  #define DATA_CACHE_ZERO_AND_TOUCH(reg, offset)
51#endif
52
53#define PPC_CONTEXT_CACHE_LINE_0 (1 * PPC_DEFAULT_CACHE_LINE_SIZE)
54#define PPC_CONTEXT_CACHE_LINE_1 (2 * PPC_DEFAULT_CACHE_LINE_SIZE)
55#define PPC_CONTEXT_CACHE_LINE_2 (3 * PPC_DEFAULT_CACHE_LINE_SIZE)
56#define PPC_CONTEXT_CACHE_LINE_3 (4 * PPC_DEFAULT_CACHE_LINE_SIZE)
57#define PPC_CONTEXT_CACHE_LINE_4 (5 * PPC_DEFAULT_CACHE_LINE_SIZE)
58#define PPC_CONTEXT_CACHE_LINE_5 (6 * PPC_DEFAULT_CACHE_LINE_SIZE)
59
60        BEGIN_CODE
61
62#if PPC_HAS_FPU == 1
63
64/*
65 * Offsets for Context_Control_fp
66 */
67
68#if (PPC_HAS_DOUBLE==1)
69        .set    FP_SIZE,        8
70#define LDF     lfd
71#define STF     stfd
72#else
73        .set    FP_SIZE,        4
74#define LDF     lfs
75#define STF     stfs
76#endif
77
78        .set    FP_0, 0
79        .set    FP_1, (FP_0 + FP_SIZE)
80        .set    FP_2, (FP_1 + FP_SIZE)
81        .set    FP_3, (FP_2 + FP_SIZE)
82        .set    FP_4, (FP_3 + FP_SIZE)
83        .set    FP_5, (FP_4 + FP_SIZE)
84        .set    FP_6, (FP_5 + FP_SIZE)
85        .set    FP_7, (FP_6 + FP_SIZE)
86        .set    FP_8, (FP_7 + FP_SIZE)
87        .set    FP_9, (FP_8 + FP_SIZE)
88        .set    FP_10, (FP_9 + FP_SIZE)
89        .set    FP_11, (FP_10 + FP_SIZE)
90        .set    FP_12, (FP_11 + FP_SIZE)
91        .set    FP_13, (FP_12 + FP_SIZE)
92        .set    FP_14, (FP_13 + FP_SIZE)
93        .set    FP_15, (FP_14 + FP_SIZE)
94        .set    FP_16, (FP_15 + FP_SIZE)
95        .set    FP_17, (FP_16 + FP_SIZE)
96        .set    FP_18, (FP_17 + FP_SIZE)
97        .set    FP_19, (FP_18 + FP_SIZE)
98        .set    FP_20, (FP_19 + FP_SIZE)
99        .set    FP_21, (FP_20 + FP_SIZE)
100        .set    FP_22, (FP_21 + FP_SIZE)
101        .set    FP_23, (FP_22 + FP_SIZE)
102        .set    FP_24, (FP_23 + FP_SIZE)
103        .set    FP_25, (FP_24 + FP_SIZE)
104        .set    FP_26, (FP_25 + FP_SIZE)
105        .set    FP_27, (FP_26 + FP_SIZE)
106        .set    FP_28, (FP_27 + FP_SIZE)
107        .set    FP_29, (FP_28 + FP_SIZE)
108        .set    FP_30, (FP_29 + FP_SIZE)
109        .set    FP_31, (FP_30 + FP_SIZE)
110        .set    FP_FPSCR, (FP_31 + FP_SIZE)
111
112/*
113 *  _CPU_Context_save_fp_context
114 *
115 *  This routine is responsible for saving the FP context
116 *  at *fp_context_ptr.  If the point to load the FP context
117 *  from is changed then the pointer is modified by this routine.
118 *
119 *  Sometimes a macro implementation of this is in cpu.h which dereferences
120 *  the ** and a similarly named routine in this file is passed something
121 *  like a (Context_Control_fp *).  The general rule on making this decision
122 *  is to avoid writing assembly language.
123 */
124
125        ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER)
126        PUBLIC_PROC (_CPU_Context_save_fp)
127PROC (_CPU_Context_save_fp):
128/* A FP context switch may occur in an ISR or exception handler when the FPU is not
129 * available. Therefore, we must explicitely enable it here!
130 */
131#if !defined(PPC_DISABLE_MSR_ACCESS)
132        mfmsr   r4
133        andi.   r5,r4,MSR_FP
134        bne     1f
135        ori     r5,r4,MSR_FP
136        mtmsr   r5
137        isync
138#endif  /* END PPC_DISABLE_MSR_ACCESS */
139
1401:
141        lwz     r3, 0(r3)
142        STF     f0, FP_0(r3)
143        STF     f1, FP_1(r3)
144        STF     f2, FP_2(r3)
145        STF     f3, FP_3(r3)
146        STF     f4, FP_4(r3)
147        STF     f5, FP_5(r3)
148        STF     f6, FP_6(r3)
149        STF     f7, FP_7(r3)
150        STF     f8, FP_8(r3)
151        STF     f9, FP_9(r3)
152        STF     f10, FP_10(r3)
153        STF     f11, FP_11(r3)
154        STF     f12, FP_12(r3)
155        STF     f13, FP_13(r3)
156        STF     f14, FP_14(r3)
157        STF     f15, FP_15(r3)
158        STF     f16, FP_16(r3)
159        STF     f17, FP_17(r3)
160        STF     f18, FP_18(r3)
161        STF     f19, FP_19(r3)
162        STF     f20, FP_20(r3)
163        STF     f21, FP_21(r3)
164        STF     f22, FP_22(r3)
165        STF     f23, FP_23(r3)
166        STF     f24, FP_24(r3)
167        STF     f25, FP_25(r3)
168        STF     f26, FP_26(r3)
169        STF     f27, FP_27(r3)
170        STF     f28, FP_28(r3)
171        STF     f29, FP_29(r3)
172        STF     f30, FP_30(r3)
173        STF     f31, FP_31(r3)
174        mffs    f2
175        STF     f2, FP_FPSCR(r3)
176#if !defined(PPC_DISABLE_MSR_ACCESS)
177        bne     1f
178        mtmsr   r4
179        isync
180#endif  /* END PPC_DISABLE_MSR_ACCESS */
181
1821:
183        blr
184
185/*
186 *  _CPU_Context_restore_fp_context
187 *
188 *  This routine is responsible for restoring the FP context
189 *  at *fp_context_ptr.  If the point to load the FP context
190 *  from is changed then the pointer is modified by this routine.
191 *
192 *  Sometimes a macro implementation of this is in cpu.h which dereferences
193 *  the ** and a similarly named routine in this file is passed something
194 *  like a (Context_Control_fp *).  The general rule on making this decision
195 *  is to avoid writing assembly language.
196 */
197
198        ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER)
199        PUBLIC_PROC (_CPU_Context_restore_fp)
200PROC (_CPU_Context_restore_fp):
201        lwz     r3, 0(r3)
202/* A FP context switch may occur in an ISR or exception handler when the FPU is not
203 * available. Therefore, we must explicitely enable it here!
204 */
205#if !defined(PPC_DISABLE_MSR_ACCESS)
206        mfmsr   r4
207        andi.   r5,r4,MSR_FP
208        bne     1f
209        ori     r5,r4,MSR_FP
210        mtmsr   r5
211        isync
212#endif  /* END PPC_DISABLE_MSR_ACCESS */
213
2141:
215        LDF     f2, FP_FPSCR(r3)
216        mtfsf   255, f2
217        LDF     f0, FP_0(r3)
218        LDF     f1, FP_1(r3)
219        LDF     f2, FP_2(r3)
220        LDF     f3, FP_3(r3)
221        LDF     f4, FP_4(r3)
222        LDF     f5, FP_5(r3)
223        LDF     f6, FP_6(r3)
224        LDF     f7, FP_7(r3)
225        LDF     f8, FP_8(r3)
226        LDF     f9, FP_9(r3)
227        LDF     f10, FP_10(r3)
228        LDF     f11, FP_11(r3)
229        LDF     f12, FP_12(r3)
230        LDF     f13, FP_13(r3)
231        LDF     f14, FP_14(r3)
232        LDF     f15, FP_15(r3)
233        LDF     f16, FP_16(r3)
234        LDF     f17, FP_17(r3)
235        LDF     f18, FP_18(r3)
236        LDF     f19, FP_19(r3)
237        LDF     f20, FP_20(r3)
238        LDF     f21, FP_21(r3)
239        LDF     f22, FP_22(r3)
240        LDF     f23, FP_23(r3)
241        LDF     f24, FP_24(r3)
242        LDF     f25, FP_25(r3)
243        LDF     f26, FP_26(r3)
244        LDF     f27, FP_27(r3)
245        LDF     f28, FP_28(r3)
246        LDF     f29, FP_29(r3)
247        LDF     f30, FP_30(r3)
248        LDF     f31, FP_31(r3)
249        bne     1f
250#if !defined(PPC_DISABLE_MSR_ACCESS)
251        mtmsr   r4
252        isync
253#endif  /* END PPC_DISABLE_MSR_ACCESS */
254
2551:
256        blr
257#endif /* PPC_HAS_FPU == 1 */
258
259        ALIGN (PPC_CACHE_ALIGNMENT, PPC_CACHE_ALIGN_POWER)
260        PUBLIC_PROC (_CPU_Context_switch)
261PROC (_CPU_Context_switch):
262
263#ifdef BSP_USE_SYNC_IN_CONTEXT_SWITCH
264        sync
265        isync
266#endif
267
268        /* Align to a cache line */
269        clrrwi  r3, r3, PPC_DEFAULT_CACHE_LINE_POWER
270        clrrwi  r5, r4, PPC_DEFAULT_CACHE_LINE_POWER
271
272        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_0)
273
274#if PPC_CONTEXT_CACHE_LINE_2 <= PPC_CONTEXT_VOLATILE_SIZE
275        DATA_CACHE_ZERO_AND_TOUCH(r11, PPC_CONTEXT_CACHE_LINE_1)
276#endif
277
278        /* Save context to r3 */
279
280        GET_SELF_CPU_CONTROL    r12
281#if !defined(PPC_DISABLE_MSR_ACCESS)
282        mfmsr   r6
283#endif  /* END PPC_DISABLE_MSR_ACCESS */
284        mfcr    r7
285        mflr    r8
286        lwz     r11, PER_CPU_ISR_DISPATCH_DISABLE(r12)
287
288        /*
289         * We have to clear the reservation of the executing thread.  See also
290         * Book E section 6.1.6.2 "Atomic Update Primitives".  Recent GCC
291         * versions use atomic operations in the C++ library for example.  On
292         * SMP configurations the reservation is cleared later during the
293         * context switch.
294         */
295#if PPC_CONTEXT_OFFSET_GPR1 != PPC_CONTEXT_CACHE_LINE_0 \
296  || !BSP_DATA_CACHE_ENABLED \
297  || PPC_DEFAULT_CACHE_LINE_SIZE != 32
298        li      r10, PPC_CONTEXT_OFFSET_GPR1
299#endif
300#ifndef RTEMS_SMP
301        stwcx.  r1, r3, r10
302#endif
303
304        stw     r6, PPC_CONTEXT_OFFSET_MSR(r3)
305        stw     r7, PPC_CONTEXT_OFFSET_CR(r3)
306        PPC_REG_STORE   r1, PPC_CONTEXT_OFFSET_GPR1(r3)
307        PPC_REG_STORE   r8, PPC_CONTEXT_OFFSET_LR(r3)
308
309        PPC_GPR_STORE   r14, PPC_CONTEXT_OFFSET_GPR14(r3)
310        PPC_GPR_STORE   r15, PPC_CONTEXT_OFFSET_GPR15(r3)
311
312#if PPC_CONTEXT_OFFSET_GPR20 == PPC_CONTEXT_CACHE_LINE_2
313        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_2)
314#endif
315
316        PPC_GPR_STORE   r16, PPC_CONTEXT_OFFSET_GPR16(r3)
317        PPC_GPR_STORE   r17, PPC_CONTEXT_OFFSET_GPR17(r3)
318
319#if PPC_CONTEXT_OFFSET_GPR26 == PPC_CONTEXT_CACHE_LINE_2
320        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_2)
321#endif
322
323        PPC_GPR_STORE   r18, PPC_CONTEXT_OFFSET_GPR18(r3)
324        PPC_GPR_STORE   r19, PPC_CONTEXT_OFFSET_GPR19(r3)
325
326#if PPC_CONTEXT_OFFSET_GPR24 == PPC_CONTEXT_CACHE_LINE_3
327        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_3)
328#endif
329
330        PPC_GPR_STORE   r20, PPC_CONTEXT_OFFSET_GPR20(r3)
331        PPC_GPR_STORE   r21, PPC_CONTEXT_OFFSET_GPR21(r3)
332        PPC_GPR_STORE   r22, PPC_CONTEXT_OFFSET_GPR22(r3)
333        PPC_GPR_STORE   r23, PPC_CONTEXT_OFFSET_GPR23(r3)
334
335#if PPC_CONTEXT_OFFSET_GPR28 == PPC_CONTEXT_CACHE_LINE_4
336        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_4)
337#endif
338
339        PPC_GPR_STORE   r24, PPC_CONTEXT_OFFSET_GPR24(r3)
340        PPC_GPR_STORE   r25, PPC_CONTEXT_OFFSET_GPR25(r3)
341
342#if PPC_CONTEXT_OFFSET_V22 == PPC_CONTEXT_CACHE_LINE_2
343        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_2)
344#endif
345
346        PPC_GPR_STORE   r26, PPC_CONTEXT_OFFSET_GPR26(r3)
347        PPC_GPR_STORE   r27, PPC_CONTEXT_OFFSET_GPR27(r3)
348
349        PPC_GPR_STORE   r28, PPC_CONTEXT_OFFSET_GPR28(r3)
350        PPC_GPR_STORE   r29, PPC_CONTEXT_OFFSET_GPR29(r3)
351        PPC_GPR_STORE   r30, PPC_CONTEXT_OFFSET_GPR30(r3)
352        PPC_GPR_STORE   r31, PPC_CONTEXT_OFFSET_GPR31(r3)
353
354        stw     r11, PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE(r3)
355
356#ifdef PPC_MULTILIB_ALTIVEC
357        li      r9, PPC_CONTEXT_OFFSET_V20
358        stvx    v20, r3, r9
359        li      r9, PPC_CONTEXT_OFFSET_V21
360        stvx    v21, r3, r9
361
362#if PPC_CONTEXT_OFFSET_V26 == PPC_CONTEXT_CACHE_LINE_3
363        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_3)
364#endif
365
366        li      r9, PPC_CONTEXT_OFFSET_V22
367        stvx    v22, r3, r9
368        li      r9, PPC_CONTEXT_OFFSET_V23
369        stvx    v23, r3, r9
370        li      r9, PPC_CONTEXT_OFFSET_V24
371        stvx    v24, r3, r9
372        li      r9, PPC_CONTEXT_OFFSET_V25
373        stvx    v25, r3, r9
374
375#if PPC_CONTEXT_OFFSET_V30 == PPC_CONTEXT_CACHE_LINE_4
376        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_4)
377#endif
378
379        li      r9, PPC_CONTEXT_OFFSET_V26
380        stvx    v26, r3, r9
381        li      r9, PPC_CONTEXT_OFFSET_V27
382        stvx    v27, r3, r9
383        li      r9, PPC_CONTEXT_OFFSET_V28
384        stvx    v28, r3, r9
385        li      r9, PPC_CONTEXT_OFFSET_V29
386        stvx    v29, r3, r9
387
388#if PPC_CONTEXT_OFFSET_F17 == PPC_CONTEXT_CACHE_LINE_5
389        DATA_CACHE_ZERO_AND_TOUCH(r10, PPC_CONTEXT_CACHE_LINE_5)
390#endif
391
392        li      r9, PPC_CONTEXT_OFFSET_V30
393        stvx    v30, r3, r9
394        li      r9, PPC_CONTEXT_OFFSET_V31
395        stvx    v31, r3, r9
396        mfvrsave        r9
397        stw     r9, PPC_CONTEXT_OFFSET_VRSAVE(r3)
398#endif
399
400#ifdef PPC_MULTILIB_FPU
401        stfd    f14, PPC_CONTEXT_OFFSET_F14(r3)
402        stfd    f15, PPC_CONTEXT_OFFSET_F15(r3)
403        stfd    f16, PPC_CONTEXT_OFFSET_F16(r3)
404        stfd    f17, PPC_CONTEXT_OFFSET_F17(r3)
405        stfd    f18, PPC_CONTEXT_OFFSET_F18(r3)
406        stfd    f19, PPC_CONTEXT_OFFSET_F19(r3)
407        stfd    f20, PPC_CONTEXT_OFFSET_F20(r3)
408        stfd    f21, PPC_CONTEXT_OFFSET_F21(r3)
409        stfd    f22, PPC_CONTEXT_OFFSET_F22(r3)
410        stfd    f23, PPC_CONTEXT_OFFSET_F23(r3)
411        stfd    f24, PPC_CONTEXT_OFFSET_F24(r3)
412        stfd    f25, PPC_CONTEXT_OFFSET_F25(r3)
413        stfd    f26, PPC_CONTEXT_OFFSET_F26(r3)
414        stfd    f27, PPC_CONTEXT_OFFSET_F27(r3)
415        stfd    f28, PPC_CONTEXT_OFFSET_F28(r3)
416        stfd    f29, PPC_CONTEXT_OFFSET_F29(r3)
417        stfd    f30, PPC_CONTEXT_OFFSET_F30(r3)
418        stfd    f31, PPC_CONTEXT_OFFSET_F31(r3)
419#endif
420
421#ifdef RTEMS_SMP
422        /*
423         * The executing thread no longer executes on this processor.  Switch
424         * the stack to the temporary interrupt stack of this processor.  Mark
425         * the context of the executing thread as not executing.
426         */
427        msync
428
429        addi    r1, r12, PER_CPU_INTERRUPT_FRAME_AREA + CPU_INTERRUPT_FRAME_SIZE
430        li      r6, 0
431        stw     r6, PPC_CONTEXT_OFFSET_IS_EXECUTING(r3)
432
433.Lcheck_is_executing:
434
435        /* Check the is executing indicator of the heir context */
436        addi    r6, r5, PPC_CONTEXT_OFFSET_IS_EXECUTING
437        lwarx   r7, r0, r6
438        cmpwi   r7, 0
439        bne     .Lget_potential_new_heir
440
441        /* Try to update the is executing indicator of the heir context */
442        li      r7, 1
443        stwcx.  r7, r0, r6
444        bne     .Lget_potential_new_heir
445        isync
446#endif
447
448        /* Restore context from r5 */
449restore_context:
450
451#if defined(__ALTIVEC__) && !defined(PPC_MULTILIB_ALTIVEC)
452        mr      r4, r5
453        .extern _CPU_Context_switch_altivec
454        bl      _CPU_Context_switch_altivec
455#endif
456
457        lwz     r6, PPC_CONTEXT_OFFSET_MSR(r5)
458        lwz     r7, PPC_CONTEXT_OFFSET_CR(r5)
459        PPC_REG_LOAD    r1, PPC_CONTEXT_OFFSET_GPR1(r5)
460        PPC_REG_LOAD    r8, PPC_CONTEXT_OFFSET_LR(r5)
461
462        PPC_GPR_LOAD    r14, PPC_CONTEXT_OFFSET_GPR14(r5)
463        PPC_GPR_LOAD    r15, PPC_CONTEXT_OFFSET_GPR15(r5)
464
465        DATA_CACHE_TOUCH(r0, r1)
466
467        PPC_GPR_LOAD    r16, PPC_CONTEXT_OFFSET_GPR16(r5)
468        PPC_GPR_LOAD    r17, PPC_CONTEXT_OFFSET_GPR17(r5)
469        PPC_GPR_LOAD    r18, PPC_CONTEXT_OFFSET_GPR18(r5)
470        PPC_GPR_LOAD    r19, PPC_CONTEXT_OFFSET_GPR19(r5)
471
472        PPC_GPR_LOAD    r20, PPC_CONTEXT_OFFSET_GPR20(r5)
473        PPC_GPR_LOAD    r21, PPC_CONTEXT_OFFSET_GPR21(r5)
474        PPC_GPR_LOAD    r22, PPC_CONTEXT_OFFSET_GPR22(r5)
475        PPC_GPR_LOAD    r23, PPC_CONTEXT_OFFSET_GPR23(r5)
476
477        PPC_GPR_LOAD    r24, PPC_CONTEXT_OFFSET_GPR24(r5)
478        PPC_GPR_LOAD    r25, PPC_CONTEXT_OFFSET_GPR25(r5)
479        PPC_GPR_LOAD    r26, PPC_CONTEXT_OFFSET_GPR26(r5)
480        PPC_GPR_LOAD    r27, PPC_CONTEXT_OFFSET_GPR27(r5)
481
482        PPC_GPR_LOAD    r28, PPC_CONTEXT_OFFSET_GPR28(r5)
483        PPC_GPR_LOAD    r29, PPC_CONTEXT_OFFSET_GPR29(r5)
484        PPC_GPR_LOAD    r30, PPC_CONTEXT_OFFSET_GPR30(r5)
485        PPC_GPR_LOAD    r31, PPC_CONTEXT_OFFSET_GPR31(r5)
486
487#ifdef __powerpc64__
488        ld      r13, PPC_CONTEXT_OFFSET_TP(r5)
489#else
490        lwz     r2, PPC_CONTEXT_OFFSET_TP(r5)
491#endif
492        lwz     r11, PPC_CONTEXT_OFFSET_ISR_DISPATCH_DISABLE(r5)
493
494#ifdef PPC_MULTILIB_ALTIVEC
495        li      r9, PPC_CONTEXT_OFFSET_V20
496        lvx     v20, r5, r9
497        li      r9, PPC_CONTEXT_OFFSET_V21
498        lvx     v21, r5, r9
499        li      r9, PPC_CONTEXT_OFFSET_V22
500        lvx     v22, r5, r9
501        li      r9, PPC_CONTEXT_OFFSET_V23
502        lvx     v23, r5, r9
503        li      r9, PPC_CONTEXT_OFFSET_V24
504        lvx     v24, r5, r9
505        li      r9, PPC_CONTEXT_OFFSET_V25
506        lvx     v25, r5, r9
507        li      r9, PPC_CONTEXT_OFFSET_V26
508        lvx     v26, r5, r9
509        li      r9, PPC_CONTEXT_OFFSET_V27
510        lvx     v27, r5, r9
511        li      r9, PPC_CONTEXT_OFFSET_V28
512        lvx     v28, r5, r9
513        li      r9, PPC_CONTEXT_OFFSET_V29
514        lvx     v29, r5, r9
515        li      r9, PPC_CONTEXT_OFFSET_V30
516        lvx     v30, r5, r9
517        li      r9, PPC_CONTEXT_OFFSET_V31
518        lvx     v31, r5, r9
519        lwz     r9, PPC_CONTEXT_OFFSET_VRSAVE(r5)
520        mtvrsave        r9
521#endif
522
523#ifdef PPC_MULTILIB_FPU
524        lfd     f14, PPC_CONTEXT_OFFSET_F14(r5)
525        lfd     f15, PPC_CONTEXT_OFFSET_F15(r5)
526        lfd     f16, PPC_CONTEXT_OFFSET_F16(r5)
527        lfd     f17, PPC_CONTEXT_OFFSET_F17(r5)
528        lfd     f18, PPC_CONTEXT_OFFSET_F18(r5)
529        lfd     f19, PPC_CONTEXT_OFFSET_F19(r5)
530        lfd     f20, PPC_CONTEXT_OFFSET_F20(r5)
531        lfd     f21, PPC_CONTEXT_OFFSET_F21(r5)
532        lfd     f22, PPC_CONTEXT_OFFSET_F22(r5)
533        lfd     f23, PPC_CONTEXT_OFFSET_F23(r5)
534        lfd     f24, PPC_CONTEXT_OFFSET_F24(r5)
535        lfd     f25, PPC_CONTEXT_OFFSET_F25(r5)
536        lfd     f26, PPC_CONTEXT_OFFSET_F26(r5)
537        lfd     f27, PPC_CONTEXT_OFFSET_F27(r5)
538        lfd     f28, PPC_CONTEXT_OFFSET_F28(r5)
539        lfd     f29, PPC_CONTEXT_OFFSET_F29(r5)
540        lfd     f30, PPC_CONTEXT_OFFSET_F30(r5)
541        lfd     f31, PPC_CONTEXT_OFFSET_F31(r5)
542#endif
543
544        mtlr    r8
545        mtcr    r7
546#if !defined(PPC_DISABLE_MSR_ACCESS)
547        mtmsr   r6
548#endif  /* END PPC_DISABLE_MSR_ACCESS */
549        stw     r11, PER_CPU_ISR_DISPATCH_DISABLE(r12)
550
551#ifdef BSP_USE_SYNC_IN_CONTEXT_SWITCH
552        isync
553#endif
554
555        blr
556
557        PUBLIC_PROC (_CPU_Context_restore)
558PROC (_CPU_Context_restore):
559        /* Align to a cache line */
560        clrrwi  r5, r3, PPC_DEFAULT_CACHE_LINE_POWER
561
562        GET_SELF_CPU_CONTROL    r12
563
564#if defined(__ALTIVEC__) && !defined(PPC_MULTILIB_ALTIVEC)
565        li      r3, 0
566#endif
567
568        b       restore_context
569
570#ifdef RTEMS_SMP
571.Lget_potential_new_heir:
572
573        /* We may have a new heir */
574
575        /* Read the executing and heir */
576        PPC_REG_LOAD    r7, PER_CPU_OFFSET_EXECUTING(r12)
577        PPC_REG_LOAD    r8, PER_CPU_OFFSET_HEIR(r12)
578
579        /*
580         * Update the executing only if necessary to avoid cache line
581         * monopolization.
582         */
583        PPC_REG_CMP     r7, r8
584        beq     .Lcheck_is_executing
585
586        /* Calculate the heir context pointer */
587        sub     r7, r4, r7
588        add     r4, r8, r7
589        clrrwi  r5, r4, PPC_DEFAULT_CACHE_LINE_POWER
590
591        /* Update the executing */
592        PPC_REG_STORE   r8, PER_CPU_OFFSET_EXECUTING(r12)
593
594        b       .Lcheck_is_executing
595#endif
Note: See TracBrowser for help on using the repository browser.