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

4.115
Last change on this file since 43e0599 was 43e0599, checked in by Mathew Kallada <matkallada@…>, on 12/02/12 at 21:23:57

score misc: Clean up Doxygen #13 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/8013205

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