source: rtems/cpukit/score/cpu/sh/context.c @ d66a6cb

4.104.11
Last change on this file since d66a6cb was d66a6cb, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 25, 2008 at 7:32:41 PM

2008-09-25 Joel Sherrill <joel.sherrill@…>

  • Makefile.am: Move duplicated context switch code to score/cpu. This has been used to run tests on the simulator BSP as SH1, SH2, and SH4.
  • context.c: New file.
  • Property mode set to 100644
File size: 5.1 KB
Line 
1/*
2 *  Authors: Ralf Corsepius (corsepiu@faw.uni-ulm.de) and
3 *           Bernd Becker (becker@faw.uni-ulm.de)
4 *
5 *  COPYRIGHT (c) 1997-1998, FAW Ulm, Germany
6 *
7 *  This program is distributed in the hope that it will be useful,
8 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
9 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 *
11 *  COPYRIGHT (c) 1998.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.com/license/LICENSE.
17 *
18 *  $Id$
19 */
20
21#include <rtems/system.h>
22#include <rtems/score/cpu.h>
23#include <rtems/score/isr.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/sh.h>
26
27/*
28 *  _CPU_Context_save_fp_context
29 *
30 *  This routine is responsible for saving the FP context
31 *  at *fp_context_ptr.  If the point to load the FP context
32 *  from is changed then the pointer is modified by this routine.
33 *
34 *  Sometimes a macro implementation of this is in cpu.h which dereferences
35 *  the ** and a similarly named routine in this file is passed something
36 *  like a (Context_Control_fp *).  The general rule on making this decision
37 *  is to avoid writing assembly language.
38 */
39
40void _CPU_Context_save_fp(
41  Context_Control_fp **fp_context_ptr
42)
43{
44#if SH_HAS_FPU
45
46asm volatile("\n\
47    mov.l   @%0,r4    \n\
48    add     %1,r4\n\
49    sts.l   fpscr,@-r4\n\
50    sts.l   fpul,@-r4\n\
51    lds     %2,fpscr\n\
52    fmov    dr14,@-r4\n\
53    fmov    dr12,@-r4\n\
54    fmov    dr10,@-r4\n\
55    fmov    dr8,@-r4\n\
56    fmov    dr6,@-r4\n\
57    fmov    dr4,@-r4\n\
58    fmov    dr2,@-r4\n\
59    fmov    dr0,@-r4\n\
60    "
61#ifdef SH4_USE_X_REGISTERS
62    "\
63    lds     %3,fpscr\n\
64    fmov    xd14,@-r4\n\
65    fmov    xd12,@-r4\n\
66    fmov    xd10,@-r4\n\
67    fmov    xd8,@-r4\n\
68    fmov    xd6,@-r4\n\
69    fmov    xd4,@-r4\n\
70    fmov    xd2,@-r4\n\
71    fmov    xd0,@-r4\n\
72    "
73#endif
74   "lds     %4,fpscr\n\
75   "
76    :
77    : "r"(fp_context_ptr), "r"(sizeof(Context_Control_fp)),
78      "r"(SH4_FPSCR_SZ), "r"(SH4_FPSCR_PR | SH4_FPSCR_SZ), "r"(SH4_FPSCR_PR)
79    : "r4", "r0");
80
81#endif
82
83}
84
85/*
86 *  _CPU_Context_restore_fp_context
87 *
88 *  This routine is responsible for restoring the FP context
89 *  at *fp_context_ptr.  If the point to load the FP context
90 *  from is changed then the pointer is modified by this routine.
91 *
92 *  Sometimes a macro implementation of this is in cpu.h which dereferences
93 *  the ** and a similarly named routine in this file is passed something
94 *  like a (Context_Control_fp *).  The general rule on making this decision
95 *  is to avoid writing assembly language.
96 */
97
98void _CPU_Context_restore_fp(
99  Context_Control_fp **fp_context_ptr
100)
101{
102
103#if SH_HAS_FPU
104
105asm volatile("\n\
106    mov.l   @%0,r4    \n\
107    "
108#ifdef SH4_USE_X_REGISTERS
109    "\n\
110    lds     %1,fpscr\n\
111    fmov    @r4+,xd0\n\
112    fmov    @r4+,xd2\n\
113    fmov    @r4+,xd4\n\
114    fmov    @r4+,xd6\n\
115    fmov    @r4+,xd8\n\
116    fmov    @r4+,xd10\n\
117    fmov    @r4+,xd12\n\
118    fmov    @r4+,xd14\n\
119    "
120#endif
121    "\n\
122    lds     %2,fpscr\n\
123    fmov    @r4+,dr0\n\
124    fmov    @r4+,dr2\n\
125    fmov    @r4+,dr4\n\
126    fmov    @r4+,dr6\n\
127    fmov    @r4+,dr8\n\
128    fmov    @r4+,dr10\n\
129    fmov    @r4+,dr12\n\
130    fmov    @r4+,dr14\n\
131    lds.l   @r4+,fpul\n\
132    lds.l   @r4+,fpscr\n\
133    " :
134    : "r"(fp_context_ptr), "r"(SH4_FPSCR_PR | SH4_FPSCR_SZ), "r"(SH4_FPSCR_SZ)
135    : "r4", "r0");
136#endif
137}
138
139/*  _CPU_Context_switch
140 *
141 *  This routine performs a normal non-FP context switch.
142 */
143
144/*  within __CPU_Context_switch:
145 *  _CPU_Context_switch
146 *  _CPU_Context_restore
147 *
148 *  This routine is generally used only to restart self in an
149 *  efficient manner.  It may simply be a label in _CPU_Context_switch.
150 *
151 * NOTE: It should be safe not to store r4, r5
152 *
153 * NOTE: It is doubtful if r0 is really needed to be stored
154 *
155 * NOTE: gbr is added, but should not be necessary, as it is
156 *      only used globally in this port.
157 */
158
159/*
160 * FIXME: This is an ugly hack, but we wanted to avoid recalculating
161 *        the offset each time Context_Control is changed
162 */
163void __CPU_Context_switch(
164  Context_Control  *run,        /* r4 */
165  Context_Control  *heir        /* r5 */
166)
167{
168
169asm volatile("\n\
170        .global __CPU_Context_switch\n\
171__CPU_Context_switch:\n\
172\n\
173        add     %0,r4\n\
174  \n\
175        stc.l   sr,@-r4\n\
176        stc.l   gbr,@-r4\n\
177        mov.l   r0,@-r4\n\
178        mov.l   r1,@-r4\n\
179        mov.l   r2,@-r4\n\
180        mov.l   r3,@-r4\n\
181\n\
182        mov.l   r6,@-r4\n\
183        mov.l   r7,@-r4\n\
184        mov.l   r8,@-r4\n\
185        mov.l   r9,@-r4\n\
186        mov.l   r10,@-r4\n\
187        mov.l   r11,@-r4\n\
188        mov.l   r12,@-r4\n\
189        mov.l   r13,@-r4\n\
190        mov.l   r14,@-r4\n\
191        sts.l   pr,@-r4\n\
192        sts.l   mach,@-r4\n\
193        sts.l   macl,@-r4\n\
194        mov.l   r15,@-r4\n\
195\n\
196        mov     r5, r4"
197  :: "i" (sizeof(Context_Control))
198  );
199
200  asm volatile("\n\
201        .global __CPU_Context_restore\n\
202__CPU_Context_restore:\n\
203        mov.l   @r4+,r15\n\
204        lds.l   @r4+,macl\n\
205        lds.l   @r4+,mach\n\
206        lds.l   @r4+,pr\n\
207        mov.l   @r4+,r14\n\
208        mov.l   @r4+,r13\n\
209        mov.l   @r4+,r12\n\
210        mov.l   @r4+,r11\n\
211        mov.l   @r4+,r10\n\
212        mov.l   @r4+,r9\n\
213        mov.l   @r4+,r8\n\
214        mov.l   @r4+,r7\n\
215        mov.l   @r4+,r6\n\
216\n\
217        mov.l   @r4+,r3\n\
218        mov.l   @r4+,r2\n\
219        mov.l   @r4+,r1\n\
220        mov.l   @r4+,r0\n\
221        ldc.l   @r4+,gbr\n\
222        ldc.l   @r4+,sr\n\
223\n\
224        rts\n\
225        nop" );
226}
Note: See TracBrowser for help on using the repository browser.