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