root / target-ppc / op_helper.h @ 1698b741
History | View | Annotate | Download (10.5 kB)
1 |
/*
|
---|---|
2 |
* PowerPC emulation helpers header for qemu.
|
3 |
*
|
4 |
* Copyright (c) 2003-2007 Jocelyn Mayer
|
5 |
*
|
6 |
* This library is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU Lesser General Public
|
8 |
* License as published by the Free Software Foundation; either
|
9 |
* version 2 of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This library is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
* Lesser General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU Lesser General Public
|
17 |
* License along with this library; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19 |
*/
|
20 |
|
21 |
#if defined(MEMSUFFIX)
|
22 |
|
23 |
/* Memory load/store helpers */
|
24 |
void glue(do_lsw, MEMSUFFIX) (int dst); |
25 |
void glue(do_lsw_le, MEMSUFFIX) (int dst); |
26 |
void glue(do_stsw, MEMSUFFIX) (int src); |
27 |
void glue(do_stsw_le, MEMSUFFIX) (int src); |
28 |
void glue(do_lmw, MEMSUFFIX) (int dst); |
29 |
void glue(do_lmw_le, MEMSUFFIX) (int dst); |
30 |
void glue(do_stmw, MEMSUFFIX) (int src); |
31 |
void glue(do_stmw_le, MEMSUFFIX) (int src); |
32 |
void glue(do_icbi, MEMSUFFIX) (void); |
33 |
void glue(do_POWER_lscbx, MEMSUFFIX) (int dest, int ra, int rb); |
34 |
void glue(do_POWER2_lfq, MEMSUFFIX) (void); |
35 |
void glue(do_POWER2_lfq_le, MEMSUFFIX) (void); |
36 |
void glue(do_POWER2_stfq, MEMSUFFIX) (void); |
37 |
void glue(do_POWER2_stfq_le, MEMSUFFIX) (void); |
38 |
|
39 |
#if defined(TARGET_PPC64)
|
40 |
void glue(do_lsw_64, MEMSUFFIX) (int dst); |
41 |
void glue(do_lsw_le_64, MEMSUFFIX) (int dst); |
42 |
void glue(do_stsw_64, MEMSUFFIX) (int src); |
43 |
void glue(do_stsw_le_64, MEMSUFFIX) (int src); |
44 |
void glue(do_lmw_64, MEMSUFFIX) (int dst); |
45 |
void glue(do_lmw_le_64, MEMSUFFIX) (int dst); |
46 |
void glue(do_stmw_64, MEMSUFFIX) (int src); |
47 |
void glue(do_stmw_le_64, MEMSUFFIX) (int src); |
48 |
void glue(do_icbi_64, MEMSUFFIX) (void); |
49 |
#endif
|
50 |
|
51 |
#else
|
52 |
|
53 |
/* Registers load and stores */
|
54 |
void do_load_cr (void); |
55 |
void do_store_cr (uint32_t mask);
|
56 |
void do_load_xer (void); |
57 |
void do_store_xer (void); |
58 |
void do_load_fpscr (void); |
59 |
void do_store_fpscr (uint32_t mask);
|
60 |
|
61 |
/* Integer arithmetic helpers */
|
62 |
void do_adde (void); |
63 |
void do_addmeo (void); |
64 |
void do_divwo (void); |
65 |
void do_divwuo (void); |
66 |
void do_mullwo (void); |
67 |
void do_nego (void); |
68 |
void do_subfe (void); |
69 |
void do_subfmeo (void); |
70 |
void do_subfzeo (void); |
71 |
void do_sraw (void); |
72 |
#if defined(TARGET_PPC64)
|
73 |
void do_adde_64 (void); |
74 |
void do_addmeo_64 (void); |
75 |
void do_imul64 (uint64_t *tl, uint64_t *th);
|
76 |
void do_mul64 (uint64_t *tl, uint64_t *th);
|
77 |
void do_divdo (void); |
78 |
void do_divduo (void); |
79 |
void do_mulldo (void); |
80 |
void do_nego_64 (void); |
81 |
void do_subfe_64 (void); |
82 |
void do_subfmeo_64 (void); |
83 |
void do_subfzeo_64 (void); |
84 |
void do_srad (void); |
85 |
#endif
|
86 |
void do_popcntb (void); |
87 |
#if defined(TARGET_PPC64)
|
88 |
void do_popcntb_64 (void); |
89 |
#endif
|
90 |
|
91 |
/* Floating-point arithmetic helpers */
|
92 |
void do_fsqrt (void); |
93 |
void do_fres (void); |
94 |
void do_frsqrte (void); |
95 |
void do_fsel (void); |
96 |
void do_fnmadd (void); |
97 |
void do_fnmsub (void); |
98 |
void do_fctiw (void); |
99 |
void do_fctiwz (void); |
100 |
void do_fcmpu (void); |
101 |
void do_fcmpo (void); |
102 |
|
103 |
/* Misc */
|
104 |
void do_tw (int flags); |
105 |
#if defined(TARGET_PPC64)
|
106 |
void do_td (int flags); |
107 |
#endif
|
108 |
#if !defined(CONFIG_USER_ONLY)
|
109 |
void do_rfi (void); |
110 |
#if defined(TARGET_PPC64)
|
111 |
void do_rfi_32 (void); |
112 |
#endif
|
113 |
void do_tlbia (void); |
114 |
void do_tlbie (void); |
115 |
#if defined(TARGET_PPC64)
|
116 |
void do_tlbie_64 (void); |
117 |
#endif
|
118 |
void do_load_6xx_tlb (int is_code); |
119 |
#if defined(TARGET_PPC64)
|
120 |
void do_slbia (void); |
121 |
void do_slbie (void); |
122 |
#endif
|
123 |
#endif
|
124 |
|
125 |
/* POWER / PowerPC 601 specific helpers */
|
126 |
void do_store_601_batu (int nr); |
127 |
void do_POWER_abso (void); |
128 |
void do_POWER_clcs (void); |
129 |
void do_POWER_div (void); |
130 |
void do_POWER_divo (void); |
131 |
void do_POWER_divs (void); |
132 |
void do_POWER_divso (void); |
133 |
void do_POWER_dozo (void); |
134 |
void do_POWER_maskg (void); |
135 |
void do_POWER_mulo (void); |
136 |
#if !defined(CONFIG_USER_ONLY)
|
137 |
void do_POWER_rac (void); |
138 |
void do_POWER_rfsvc (void); |
139 |
#endif
|
140 |
|
141 |
/* PowerPC 602 specific helper */
|
142 |
#if !defined(CONFIG_USER_ONLY)
|
143 |
void do_op_602_mfrom (void); |
144 |
#endif
|
145 |
|
146 |
/* PowerPC 4xx specific helpers */
|
147 |
void do_405_check_ov (void); |
148 |
void do_405_check_sat (void); |
149 |
#if !defined(CONFIG_USER_ONLY)
|
150 |
void do_4xx_load_dcr (int dcrn); |
151 |
void do_4xx_store_dcr (int dcrn); |
152 |
void do_4xx_rfci (void); |
153 |
void do_4xx_tlbre_lo (void); |
154 |
void do_4xx_tlbre_hi (void); |
155 |
void do_4xx_tlbsx (void); |
156 |
void do_4xx_tlbsx_ (void); |
157 |
void do_4xx_tlbwe_lo (void); |
158 |
void do_4xx_tlbwe_hi (void); |
159 |
#endif
|
160 |
|
161 |
/* PowerPC 440 specific helpers */
|
162 |
void do_440_dlmzb (void); |
163 |
|
164 |
/* PowerPC 403 specific helpers */
|
165 |
#if !defined(CONFIG_USER_ONLY)
|
166 |
void do_load_403_pb (int num); |
167 |
void do_store_403_pb (int num); |
168 |
#endif
|
169 |
|
170 |
#if defined(TARGET_PPCSPE)
|
171 |
/* SPE extension helpers */
|
172 |
void do_brinc (void); |
173 |
/* Fixed-point vector helpers */
|
174 |
void do_evabs (void); |
175 |
void do_evaddw (void); |
176 |
void do_evcntlsw (void); |
177 |
void do_evcntlzw (void); |
178 |
void do_evneg (void); |
179 |
void do_evrlw (void); |
180 |
void do_evsel (void); |
181 |
void do_evrndw (void); |
182 |
void do_evslw (void); |
183 |
void do_evsrws (void); |
184 |
void do_evsrwu (void); |
185 |
void do_evsubfw (void); |
186 |
void do_evcmpeq (void); |
187 |
void do_evcmpgts (void); |
188 |
void do_evcmpgtu (void); |
189 |
void do_evcmplts (void); |
190 |
void do_evcmpltu (void); |
191 |
|
192 |
/* Single precision floating-point helpers */
|
193 |
void do_efscmplt (void); |
194 |
void do_efscmpgt (void); |
195 |
void do_efscmpeq (void); |
196 |
void do_efscfsf (void); |
197 |
void do_efscfuf (void); |
198 |
void do_efsctsf (void); |
199 |
void do_efsctuf (void); |
200 |
|
201 |
void do_efscfsi (void); |
202 |
void do_efscfui (void); |
203 |
void do_efsctsi (void); |
204 |
void do_efsctui (void); |
205 |
void do_efsctsiz (void); |
206 |
void do_efsctuiz (void); |
207 |
|
208 |
/* Double precision floating-point helpers */
|
209 |
void do_efdcmplt (void); |
210 |
void do_efdcmpgt (void); |
211 |
void do_efdcmpeq (void); |
212 |
void do_efdcfsf (void); |
213 |
void do_efdcfuf (void); |
214 |
void do_efdctsf (void); |
215 |
void do_efdctuf (void); |
216 |
|
217 |
void do_efdcfsi (void); |
218 |
void do_efdcfui (void); |
219 |
void do_efdctsi (void); |
220 |
void do_efdctui (void); |
221 |
void do_efdctsiz (void); |
222 |
void do_efdctuiz (void); |
223 |
|
224 |
void do_efdcfs (void); |
225 |
void do_efscfd (void); |
226 |
|
227 |
/* Floating-point vector helpers */
|
228 |
void do_evfsabs (void); |
229 |
void do_evfsnabs (void); |
230 |
void do_evfsneg (void); |
231 |
void do_evfsadd (void); |
232 |
void do_evfssub (void); |
233 |
void do_evfsmul (void); |
234 |
void do_evfsdiv (void); |
235 |
void do_evfscmplt (void); |
236 |
void do_evfscmpgt (void); |
237 |
void do_evfscmpeq (void); |
238 |
void do_evfststlt (void); |
239 |
void do_evfststgt (void); |
240 |
void do_evfststeq (void); |
241 |
void do_evfscfsi (void); |
242 |
void do_evfscfui (void); |
243 |
void do_evfscfsf (void); |
244 |
void do_evfscfuf (void); |
245 |
void do_evfsctsf (void); |
246 |
void do_evfsctuf (void); |
247 |
void do_evfsctsi (void); |
248 |
void do_evfsctui (void); |
249 |
void do_evfsctsiz (void); |
250 |
void do_evfsctuiz (void); |
251 |
#endif /* defined(TARGET_PPCSPE) */ |
252 |
|
253 |
/* Inlined helpers: used in micro-operation as well as helpers */
|
254 |
/* Generic fixed-point helpers */
|
255 |
static inline int _do_cntlzw (uint32_t val) |
256 |
{ |
257 |
int cnt = 0; |
258 |
if (!(val & 0xFFFF0000UL)) { |
259 |
cnt += 16;
|
260 |
val <<= 16;
|
261 |
} |
262 |
if (!(val & 0xFF000000UL)) { |
263 |
cnt += 8;
|
264 |
val <<= 8;
|
265 |
} |
266 |
if (!(val & 0xF0000000UL)) { |
267 |
cnt += 4;
|
268 |
val <<= 4;
|
269 |
} |
270 |
if (!(val & 0xC0000000UL)) { |
271 |
cnt += 2;
|
272 |
val <<= 2;
|
273 |
} |
274 |
if (!(val & 0x80000000UL)) { |
275 |
cnt++; |
276 |
val <<= 1;
|
277 |
} |
278 |
if (!(val & 0x80000000UL)) { |
279 |
cnt++; |
280 |
} |
281 |
return cnt;
|
282 |
} |
283 |
|
284 |
static inline int _do_cntlzd (uint64_t val) |
285 |
{ |
286 |
int cnt = 0; |
287 |
#if HOST_LONG_BITS == 64 |
288 |
if (!(val & 0xFFFFFFFF00000000ULL)) { |
289 |
cnt += 32;
|
290 |
val <<= 32;
|
291 |
} |
292 |
if (!(val & 0xFFFF000000000000ULL)) { |
293 |
cnt += 16;
|
294 |
val <<= 16;
|
295 |
} |
296 |
if (!(val & 0xFF00000000000000ULL)) { |
297 |
cnt += 8;
|
298 |
val <<= 8;
|
299 |
} |
300 |
if (!(val & 0xF000000000000000ULL)) { |
301 |
cnt += 4;
|
302 |
val <<= 4;
|
303 |
} |
304 |
if (!(val & 0xC000000000000000ULL)) { |
305 |
cnt += 2;
|
306 |
val <<= 2;
|
307 |
} |
308 |
if (!(val & 0x8000000000000000ULL)) { |
309 |
cnt++; |
310 |
val <<= 1;
|
311 |
} |
312 |
if (!(val & 0x8000000000000000ULL)) { |
313 |
cnt++; |
314 |
} |
315 |
#else
|
316 |
/* Make it easier on 32 bits host machines */
|
317 |
if (!(val >> 32)) |
318 |
cnt = _do_cntlzw(val) + 32;
|
319 |
else
|
320 |
cnt = _do_cntlzw(val >> 32);
|
321 |
#endif
|
322 |
return cnt;
|
323 |
} |
324 |
|
325 |
#if defined(TARGET_PPCSPE)
|
326 |
/* SPE extension */
|
327 |
/* Single precision floating-point helpers */
|
328 |
static inline uint32_t _do_efsabs (uint32_t val) |
329 |
{ |
330 |
return val & ~0x80000000; |
331 |
} |
332 |
static inline uint32_t _do_efsnabs (uint32_t val) |
333 |
{ |
334 |
return val | 0x80000000; |
335 |
} |
336 |
static inline uint32_t _do_efsneg (uint32_t val) |
337 |
{ |
338 |
return val ^ 0x80000000; |
339 |
} |
340 |
static inline uint32_t _do_efsadd (uint32_t op1, uint32_t op2) |
341 |
{ |
342 |
union {
|
343 |
uint32_t u; |
344 |
float32 f; |
345 |
} u1, u2; |
346 |
u1.u = op1; |
347 |
u2.u = op2; |
348 |
u1.f = float32_add(u1.f, u2.f, &env->spe_status); |
349 |
return u1.u;
|
350 |
} |
351 |
static inline uint32_t _do_efssub (uint32_t op1, uint32_t op2) |
352 |
{ |
353 |
union {
|
354 |
uint32_t u; |
355 |
float32 f; |
356 |
} u1, u2; |
357 |
u1.u = op1; |
358 |
u2.u = op2; |
359 |
u1.f = float32_sub(u1.f, u2.f, &env->spe_status); |
360 |
return u1.u;
|
361 |
} |
362 |
static inline uint32_t _do_efsmul (uint32_t op1, uint32_t op2) |
363 |
{ |
364 |
union {
|
365 |
uint32_t u; |
366 |
float32 f; |
367 |
} u1, u2; |
368 |
u1.u = op1; |
369 |
u2.u = op2; |
370 |
u1.f = float32_mul(u1.f, u2.f, &env->spe_status); |
371 |
return u1.u;
|
372 |
} |
373 |
static inline uint32_t _do_efsdiv (uint32_t op1, uint32_t op2) |
374 |
{ |
375 |
union {
|
376 |
uint32_t u; |
377 |
float32 f; |
378 |
} u1, u2; |
379 |
u1.u = op1; |
380 |
u2.u = op2; |
381 |
u1.f = float32_div(u1.f, u2.f, &env->spe_status); |
382 |
return u1.u;
|
383 |
} |
384 |
|
385 |
static inline int _do_efststlt (uint32_t op1, uint32_t op2) |
386 |
{ |
387 |
union {
|
388 |
uint32_t u; |
389 |
float32 f; |
390 |
} u1, u2; |
391 |
u1.u = op1; |
392 |
u2.u = op2; |
393 |
return float32_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0; |
394 |
} |
395 |
static inline int _do_efststgt (uint32_t op1, uint32_t op2) |
396 |
{ |
397 |
union {
|
398 |
uint32_t u; |
399 |
float32 f; |
400 |
} u1, u2; |
401 |
u1.u = op1; |
402 |
u2.u = op2; |
403 |
return float32_le(u1.f, u2.f, &env->spe_status) ? 0 : 1; |
404 |
} |
405 |
static inline int _do_efststeq (uint32_t op1, uint32_t op2) |
406 |
{ |
407 |
union {
|
408 |
uint32_t u; |
409 |
float32 f; |
410 |
} u1, u2; |
411 |
u1.u = op1; |
412 |
u2.u = op2; |
413 |
return float32_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0; |
414 |
} |
415 |
/* Double precision floating-point helpers */
|
416 |
static inline int _do_efdtstlt (uint64_t op1, uint64_t op2) |
417 |
{ |
418 |
union {
|
419 |
uint64_t u; |
420 |
float64 f; |
421 |
} u1, u2; |
422 |
u1.u = op1; |
423 |
u2.u = op2; |
424 |
return float64_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0; |
425 |
} |
426 |
static inline int _do_efdtstgt (uint64_t op1, uint64_t op2) |
427 |
{ |
428 |
union {
|
429 |
uint64_t u; |
430 |
float64 f; |
431 |
} u1, u2; |
432 |
u1.u = op1; |
433 |
u2.u = op2; |
434 |
return float64_le(u1.f, u2.f, &env->spe_status) ? 0 : 1; |
435 |
} |
436 |
static inline int _do_efdtsteq (uint64_t op1, uint64_t op2) |
437 |
{ |
438 |
union {
|
439 |
uint64_t u; |
440 |
float64 f; |
441 |
} u1, u2; |
442 |
u1.u = op1; |
443 |
u2.u = op2; |
444 |
return float64_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0; |
445 |
} |
446 |
#endif /* defined(TARGET_PPCSPE) */ |
447 |
#endif
|