Code provision for PowerPC BookE MMU model support.
[qemu] / target-ppc / op_helper.h
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 void do_print_mem_EA (target_ulong EA);
54
55 /* Registers load and stores */
56 void do_load_cr (void);
57 void do_store_cr (uint32_t mask);
58 void do_load_xer (void);
59 void do_store_xer (void);
60 void do_load_fpscr (void);
61 void do_store_fpscr (uint32_t mask);
62 target_ulong ppc_load_dump_spr (int sprn);
63 void ppc_store_dump_spr (int sprn, target_ulong val);
64
65 /* Integer arithmetic helpers */
66 void do_adde (void);
67 void do_addmeo (void);
68 void do_divwo (void);
69 void do_divwuo (void);
70 void do_mullwo (void);
71 void do_nego (void);
72 void do_subfe (void);
73 void do_subfmeo (void);
74 void do_subfzeo (void);
75 void do_sraw (void);
76 #if defined(TARGET_PPC64)
77 void do_adde_64 (void);
78 void do_addmeo_64 (void);
79 void do_imul64 (uint64_t *tl, uint64_t *th);
80 void do_mul64 (uint64_t *tl, uint64_t *th);
81 void do_divdo (void);
82 void do_divduo (void);
83 void do_mulldo (void);
84 void do_nego_64 (void);
85 void do_subfe_64 (void);
86 void do_subfmeo_64 (void);
87 void do_subfzeo_64 (void);
88 void do_srad (void);
89 #endif
90 void do_popcntb (void);
91 #if defined(TARGET_PPC64)
92 void do_popcntb_64 (void);
93 #endif
94
95 /* Floating-point arithmetic helpers */
96 void do_fsqrt (void);
97 void do_fres (void);
98 void do_frsqrte (void);
99 void do_fsel (void);
100 #if USE_PRECISE_EMULATION
101 void do_fmadd (void);
102 void do_fmsub (void);
103 #endif
104 void do_fnmadd (void);
105 void do_fnmsub (void);
106 void do_fctiw (void);
107 void do_fctiwz (void);
108 #if defined(TARGET_PPC64)
109 void do_fcfid (void);
110 void do_fctid (void);
111 void do_fctidz (void);
112 #endif
113 void do_fcmpu (void);
114 void do_fcmpo (void);
115
116 /* Misc */
117 void do_tw (int flags);
118 #if defined(TARGET_PPC64)
119 void do_td (int flags);
120 #endif
121 #if !defined(CONFIG_USER_ONLY)
122 void do_rfi (void);
123 #if defined(TARGET_PPC64)
124 void do_rfid (void);
125 #endif
126 void do_tlbia (void);
127 void do_tlbie (void);
128 #if defined(TARGET_PPC64)
129 void do_tlbie_64 (void);
130 #endif
131 void do_load_6xx_tlb (int is_code);
132 #if defined(TARGET_PPC64)
133 void do_slbia (void);
134 void do_slbie (void);
135 #endif
136 #endif
137
138 /* POWER / PowerPC 601 specific helpers */
139 void do_store_601_batu (int nr);
140 void do_POWER_abso (void);
141 void do_POWER_clcs (void);
142 void do_POWER_div (void);
143 void do_POWER_divo (void);
144 void do_POWER_divs (void);
145 void do_POWER_divso (void);
146 void do_POWER_dozo (void);
147 void do_POWER_maskg (void);
148 void do_POWER_mulo (void);
149 #if !defined(CONFIG_USER_ONLY)
150 void do_POWER_rac (void);
151 void do_POWER_rfsvc (void);
152 #endif
153
154 /* PowerPC 602 specific helper */
155 #if !defined(CONFIG_USER_ONLY)
156 void do_op_602_mfrom (void);
157 #endif
158
159 /* PowerPC BookE specific helpers */
160 #if !defined(CONFIG_USER_ONLY)
161 void do_booke_tlbre0 (void);
162 void do_booke_tlbre1 (void);
163 void do_booke_tlbre2 (void);
164 void do_booke_tlbsx (void);
165 void do_booke_tlbsx_ (void);
166 void do_booke_tlbwe0 (void);
167 void do_booke_tlbwe1 (void);
168 void do_booke_tlbwe2 (void);
169 #endif
170
171 /* PowerPC 4xx specific helpers */
172 void do_405_check_ov (void);
173 void do_405_check_sat (void);
174 #if !defined(CONFIG_USER_ONLY)
175 void do_load_dcr (void);
176 void do_store_dcr (void);
177 void do_40x_rfci (void);
178 void do_rfci (void);
179 void do_rfdi (void);
180 void do_rfmci (void);
181 void do_4xx_tlbre_lo (void);
182 void do_4xx_tlbre_hi (void);
183 void do_4xx_tlbsx (void);
184 void do_4xx_tlbsx_ (void);
185 void do_4xx_tlbwe_lo (void);
186 void do_4xx_tlbwe_hi (void);
187 #endif
188
189 /* PowerPC 440 specific helpers */
190 void do_440_dlmzb (void);
191
192 /* PowerPC 403 specific helpers */
193 #if !defined(CONFIG_USER_ONLY)
194 void do_load_403_pb (int num);
195 void do_store_403_pb (int num);
196 #endif
197
198 #if defined(TARGET_PPCEMB)
199 /* SPE extension helpers */
200 void do_brinc (void);
201 /* Fixed-point vector helpers */
202 void do_evabs (void);
203 void do_evaddw (void);
204 void do_evcntlsw (void);
205 void do_evcntlzw (void);
206 void do_evneg (void);
207 void do_evrlw (void);
208 void do_evsel (void);
209 void do_evrndw (void);
210 void do_evslw (void);
211 void do_evsrws (void);
212 void do_evsrwu (void);
213 void do_evsubfw (void);
214 void do_evcmpeq (void);
215 void do_evcmpgts (void);
216 void do_evcmpgtu (void);
217 void do_evcmplts (void);
218 void do_evcmpltu (void);
219
220 /* Single precision floating-point helpers */
221 void do_efscmplt (void);
222 void do_efscmpgt (void);
223 void do_efscmpeq (void);
224 void do_efscfsf (void);
225 void do_efscfuf (void);
226 void do_efsctsf (void);
227 void do_efsctuf (void);
228
229 void do_efscfsi (void);
230 void do_efscfui (void);
231 void do_efsctsi (void);
232 void do_efsctui (void);
233 void do_efsctsiz (void);
234 void do_efsctuiz (void);
235
236 /* Double precision floating-point helpers */
237 void do_efdcmplt (void);
238 void do_efdcmpgt (void);
239 void do_efdcmpeq (void);
240 void do_efdcfsf (void);
241 void do_efdcfuf (void);
242 void do_efdctsf (void);
243 void do_efdctuf (void);
244
245 void do_efdcfsi (void);
246 void do_efdcfui (void);
247 void do_efdctsi (void);
248 void do_efdctui (void);
249 void do_efdctsiz (void);
250 void do_efdctuiz (void);
251
252 void do_efdcfs (void);
253 void do_efscfd (void);
254
255 /* Floating-point vector helpers */
256 void do_evfsabs (void);
257 void do_evfsnabs (void);
258 void do_evfsneg (void);
259 void do_evfsadd (void);
260 void do_evfssub (void);
261 void do_evfsmul (void);
262 void do_evfsdiv (void);
263 void do_evfscmplt (void);
264 void do_evfscmpgt (void);
265 void do_evfscmpeq (void);
266 void do_evfststlt (void);
267 void do_evfststgt (void);
268 void do_evfststeq (void);
269 void do_evfscfsi (void);
270 void do_evfscfui (void);
271 void do_evfscfsf (void);
272 void do_evfscfuf (void);
273 void do_evfsctsf (void);
274 void do_evfsctuf (void);
275 void do_evfsctsi (void);
276 void do_evfsctui (void);
277 void do_evfsctsiz (void);
278 void do_evfsctuiz (void);
279 #endif /* defined(TARGET_PPCEMB) */
280
281 /* Inlined helpers: used in micro-operation as well as helpers */
282 /* Generic fixed-point helpers */
283 static inline int _do_cntlzw (uint32_t val)
284 {
285     int cnt = 0;
286     if (!(val & 0xFFFF0000UL)) {
287         cnt += 16;
288         val <<= 16;
289     }
290     if (!(val & 0xFF000000UL)) {
291         cnt += 8;
292         val <<= 8;
293     }
294     if (!(val & 0xF0000000UL)) {
295         cnt += 4;
296         val <<= 4;
297     }
298     if (!(val & 0xC0000000UL)) {
299         cnt += 2;
300         val <<= 2;
301     }
302     if (!(val & 0x80000000UL)) {
303         cnt++;
304         val <<= 1;
305     }
306     if (!(val & 0x80000000UL)) {
307         cnt++;
308     }
309     return cnt;
310 }
311
312 static inline int _do_cntlzd (uint64_t val)
313 {
314     int cnt = 0;
315 #if HOST_LONG_BITS == 64
316     if (!(val & 0xFFFFFFFF00000000ULL)) {
317         cnt += 32;
318         val <<= 32;
319     }
320     if (!(val & 0xFFFF000000000000ULL)) {
321         cnt += 16;
322         val <<= 16;
323     }
324     if (!(val & 0xFF00000000000000ULL)) {
325         cnt += 8;
326         val <<= 8;
327     }
328     if (!(val & 0xF000000000000000ULL)) {
329         cnt += 4;
330         val <<= 4;
331     }
332     if (!(val & 0xC000000000000000ULL)) {
333         cnt += 2;
334         val <<= 2;
335     }
336     if (!(val & 0x8000000000000000ULL)) {
337         cnt++;
338         val <<= 1;
339     }
340     if (!(val & 0x8000000000000000ULL)) {
341         cnt++;
342     }
343 #else
344     /* Make it easier on 32 bits host machines */
345     if (!(val >> 32))
346         cnt = _do_cntlzw(val) + 32;
347     else
348         cnt = _do_cntlzw(val >> 32);
349 #endif
350     return cnt;
351 }
352
353 #if defined(TARGET_PPCEMB)
354 /* SPE extension */
355 /* Single precision floating-point helpers */
356 static inline uint32_t _do_efsabs (uint32_t val)
357 {
358     return val & ~0x80000000;
359 }
360 static inline uint32_t _do_efsnabs (uint32_t val)
361 {
362     return val | 0x80000000;
363 }
364 static inline uint32_t _do_efsneg (uint32_t val)
365 {
366     return val ^ 0x80000000;
367 }
368 static inline uint32_t _do_efsadd (uint32_t op1, uint32_t op2)
369 {
370     union {
371         uint32_t u;
372         float32 f;
373     } u1, u2;
374     u1.u = op1;
375     u2.u = op2;
376     u1.f = float32_add(u1.f, u2.f, &env->spe_status);
377     return u1.u;
378 }
379 static inline uint32_t _do_efssub (uint32_t op1, uint32_t op2)
380 {
381     union {
382         uint32_t u;
383         float32 f;
384     } u1, u2;
385     u1.u = op1;
386     u2.u = op2;
387     u1.f = float32_sub(u1.f, u2.f, &env->spe_status);
388     return u1.u;
389 }
390 static inline uint32_t _do_efsmul (uint32_t op1, uint32_t op2)
391 {
392     union {
393         uint32_t u;
394         float32 f;
395     } u1, u2;
396     u1.u = op1;
397     u2.u = op2;
398     u1.f = float32_mul(u1.f, u2.f, &env->spe_status);
399     return u1.u;
400 }
401 static inline uint32_t _do_efsdiv (uint32_t op1, uint32_t op2)
402 {
403     union {
404         uint32_t u;
405         float32 f;
406     } u1, u2;
407     u1.u = op1;
408     u2.u = op2;
409     u1.f = float32_div(u1.f, u2.f, &env->spe_status);
410     return u1.u;
411 }
412
413 static inline int _do_efststlt (uint32_t op1, uint32_t op2)
414 {
415     union {
416         uint32_t u;
417         float32 f;
418     } u1, u2;
419     u1.u = op1;
420     u2.u = op2;
421     return float32_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0;
422 }
423 static inline int _do_efststgt (uint32_t op1, uint32_t op2)
424 {
425     union {
426         uint32_t u;
427         float32 f;
428     } u1, u2;
429     u1.u = op1;
430     u2.u = op2;
431     return float32_le(u1.f, u2.f, &env->spe_status) ? 0 : 1;
432 }
433 static inline int _do_efststeq (uint32_t op1, uint32_t op2)
434 {
435     union {
436         uint32_t u;
437         float32 f;
438     } u1, u2;
439     u1.u = op1;
440     u2.u = op2;
441     return float32_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0;
442 }
443 /* Double precision floating-point helpers */
444 static inline int _do_efdtstlt (uint64_t op1, uint64_t op2)
445 {
446     union {
447         uint64_t u;
448         float64 f;
449     } u1, u2;
450     u1.u = op1;
451     u2.u = op2;
452     return float64_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0;
453 }
454 static inline int _do_efdtstgt (uint64_t op1, uint64_t op2)
455 {
456     union {
457         uint64_t u;
458         float64 f;
459     } u1, u2;
460     u1.u = op1;
461     u2.u = op2;
462     return float64_le(u1.f, u2.f, &env->spe_status) ? 0 : 1;
463 }
464 static inline int _do_efdtsteq (uint64_t op1, uint64_t op2)
465 {
466     union {
467         uint64_t u;
468         float64 f;
469     } u1, u2;
470     u1.u = op1;
471     u2.u = op2;
472     return float64_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0;
473 }
474 #endif /* defined(TARGET_PPCEMB) */
475 #endif