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

4.115
Last change on this file since 05d72d5 was 05d72d5, checked in by Ralf Corsepius <ralf.corsepius@…>, on 02/11/11 at 08:56:10

2011-02-11 Ralf Corsépius <ralf.corsepius@…>

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