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

Last change on this file since 9165349d was 3fe2155, checked in by Sebastian Huber <sebastian.huber@…>, on 02/01/19 at 09:00:36

Remove superfluous <rtems/system.h> includes

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