Statistics
| Branch: | Revision:

root / target-ppc / op_helper.h @ 5356c7b5

History | View | Annotate | Download (11 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
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
#if defined(TARGET_PPC64)
61
void do_store_pri (int prio);
62
#endif
63
void do_load_fpscr (void);
64
void do_store_fpscr (uint32_t mask);
65
target_ulong ppc_load_dump_spr (int sprn);
66
void ppc_store_dump_spr (int sprn, target_ulong val);
67

    
68
/* Integer arithmetic helpers */
69
void do_adde (void);
70
void do_addmeo (void);
71
void do_divwo (void);
72
void do_divwuo (void);
73
void do_mullwo (void);
74
void do_nego (void);
75
void do_subfe (void);
76
void do_subfmeo (void);
77
void do_subfzeo (void);
78
void do_sraw (void);
79
#if defined(TARGET_PPC64)
80
void do_adde_64 (void);
81
void do_addmeo_64 (void);
82
void do_imul64 (uint64_t *tl, uint64_t *th);
83
void do_mul64 (uint64_t *tl, uint64_t *th);
84
void do_divdo (void);
85
void do_divduo (void);
86
void do_mulldo (void);
87
void do_nego_64 (void);
88
void do_subfe_64 (void);
89
void do_subfmeo_64 (void);
90
void do_subfzeo_64 (void);
91
void do_srad (void);
92
#endif
93
void do_popcntb (void);
94
#if defined(TARGET_PPC64)
95
void do_popcntb_64 (void);
96
#endif
97

    
98
/* Floating-point arithmetic helpers */
99
void do_fsqrt (void);
100
void do_fre (void);
101
void do_fres (void);
102
void do_frsqrte (void);
103
void do_fsel (void);
104
#if USE_PRECISE_EMULATION
105
void do_fmadd (void);
106
void do_fmsub (void);
107
#endif
108
void do_fnmadd (void);
109
void do_fnmsub (void);
110
void do_fctiw (void);
111
void do_fctiwz (void);
112
#if defined(TARGET_PPC64)
113
void do_fcfid (void);
114
void do_fctid (void);
115
void do_fctidz (void);
116
#endif
117
void do_frin (void);
118
void do_friz (void);
119
void do_frip (void);
120
void do_frim (void);
121
void do_fcmpu (void);
122
void do_fcmpo (void);
123

    
124
/* Misc */
125
void do_tw (int flags);
126
#if defined(TARGET_PPC64)
127
void do_td (int flags);
128
#endif
129
#if !defined(CONFIG_USER_ONLY)
130
void do_rfi (void);
131
#if defined(TARGET_PPC64)
132
void do_rfid (void);
133
#endif
134
#if defined(TARGET_PPC64H)
135
void do_hrfid (void);
136
#endif
137
void do_load_6xx_tlb (int is_code);
138
#endif
139

    
140
/* POWER / PowerPC 601 specific helpers */
141
void do_store_601_batu (int nr);
142
void do_POWER_abso (void);
143
void do_POWER_clcs (void);
144
void do_POWER_div (void);
145
void do_POWER_divo (void);
146
void do_POWER_divs (void);
147
void do_POWER_divso (void);
148
void do_POWER_dozo (void);
149
void do_POWER_maskg (void);
150
void do_POWER_mulo (void);
151
#if !defined(CONFIG_USER_ONLY)
152
void do_POWER_rac (void);
153
void do_POWER_rfsvc (void);
154
#endif
155

    
156
/* PowerPC 602 specific helper */
157
#if !defined(CONFIG_USER_ONLY)
158
void do_op_602_mfrom (void);
159
#endif
160

    
161
/* PowerPC 440 specific helpers */
162
#if !defined(CONFIG_USER_ONLY)
163
void do_440_tlbre (int word);
164
void do_440_tlbwe (int word);
165
#endif
166

    
167
/* PowerPC 4xx specific helpers */
168
void do_405_check_ov (void);
169
void do_405_check_sat (void);
170
void do_load_dcr (void);
171
void do_store_dcr (void);
172
#if !defined(CONFIG_USER_ONLY)
173
void do_40x_rfci (void);
174
void do_rfci (void);
175
void do_rfdi (void);
176
void do_rfmci (void);
177
void do_4xx_tlbre_lo (void);
178
void do_4xx_tlbre_hi (void);
179
void do_4xx_tlbwe_lo (void);
180
void do_4xx_tlbwe_hi (void);
181
#endif
182

    
183
/* PowerPC 440 specific helpers */
184
void do_440_dlmzb (void);
185

    
186
/* PowerPC 403 specific helpers */
187
#if !defined(CONFIG_USER_ONLY)
188
void do_load_403_pb (int num);
189
void do_store_403_pb (int num);
190
#endif
191

    
192
#if defined(TARGET_PPCEMB)
193
/* SPE extension helpers */
194
void do_brinc (void);
195
/* Fixed-point vector helpers */
196
void do_evabs (void);
197
void do_evaddw (void);
198
void do_evcntlsw (void);
199
void do_evcntlzw (void);
200
void do_evneg (void);
201
void do_evrlw (void);
202
void do_evsel (void);
203
void do_evrndw (void);
204
void do_evslw (void);
205
void do_evsrws (void);
206
void do_evsrwu (void);
207
void do_evsubfw (void);
208
void do_evcmpeq (void);
209
void do_evcmpgts (void);
210
void do_evcmpgtu (void);
211
void do_evcmplts (void);
212
void do_evcmpltu (void);
213

    
214
/* Single precision floating-point helpers */
215
void do_efscmplt (void);
216
void do_efscmpgt (void);
217
void do_efscmpeq (void);
218
void do_efscfsf (void);
219
void do_efscfuf (void);
220
void do_efsctsf (void);
221
void do_efsctuf (void);
222

    
223
void do_efscfsi (void);
224
void do_efscfui (void);
225
void do_efsctsi (void);
226
void do_efsctui (void);
227
void do_efsctsiz (void);
228
void do_efsctuiz (void);
229

    
230
/* Double precision floating-point helpers */
231
void do_efdcmplt (void);
232
void do_efdcmpgt (void);
233
void do_efdcmpeq (void);
234
void do_efdcfsf (void);
235
void do_efdcfuf (void);
236
void do_efdctsf (void);
237
void do_efdctuf (void);
238

    
239
void do_efdcfsi (void);
240
void do_efdcfui (void);
241
void do_efdctsi (void);
242
void do_efdctui (void);
243
void do_efdctsiz (void);
244
void do_efdctuiz (void);
245

    
246
void do_efdcfs (void);
247
void do_efscfd (void);
248

    
249
/* Floating-point vector helpers */
250
void do_evfsabs (void);
251
void do_evfsnabs (void);
252
void do_evfsneg (void);
253
void do_evfsadd (void);
254
void do_evfssub (void);
255
void do_evfsmul (void);
256
void do_evfsdiv (void);
257
void do_evfscmplt (void);
258
void do_evfscmpgt (void);
259
void do_evfscmpeq (void);
260
void do_evfststlt (void);
261
void do_evfststgt (void);
262
void do_evfststeq (void);
263
void do_evfscfsi (void);
264
void do_evfscfui (void);
265
void do_evfscfsf (void);
266
void do_evfscfuf (void);
267
void do_evfsctsf (void);
268
void do_evfsctuf (void);
269
void do_evfsctsi (void);
270
void do_evfsctui (void);
271
void do_evfsctsiz (void);
272
void do_evfsctuiz (void);
273
#endif /* defined(TARGET_PPCEMB) */
274

    
275
/* Inlined helpers: used in micro-operation as well as helpers */
276
/* Generic fixed-point helpers */
277
static inline int _do_cntlzw (uint32_t val)
278
{
279
    int cnt = 0;
280
    if (!(val & 0xFFFF0000UL)) {
281
        cnt += 16;
282
        val <<= 16;
283
    }
284
    if (!(val & 0xFF000000UL)) {
285
        cnt += 8;
286
        val <<= 8;
287
    }
288
    if (!(val & 0xF0000000UL)) {
289
        cnt += 4;
290
        val <<= 4;
291
    }
292
    if (!(val & 0xC0000000UL)) {
293
        cnt += 2;
294
        val <<= 2;
295
    }
296
    if (!(val & 0x80000000UL)) {
297
        cnt++;
298
        val <<= 1;
299
    }
300
    if (!(val & 0x80000000UL)) {
301
        cnt++;
302
    }
303
    return cnt;
304
}
305

    
306
static inline int _do_cntlzd (uint64_t val)
307
{
308
    int cnt = 0;
309
#if HOST_LONG_BITS == 64
310
    if (!(val & 0xFFFFFFFF00000000ULL)) {
311
        cnt += 32;
312
        val <<= 32;
313
    }
314
    if (!(val & 0xFFFF000000000000ULL)) {
315
        cnt += 16;
316
        val <<= 16;
317
    }
318
    if (!(val & 0xFF00000000000000ULL)) {
319
        cnt += 8;
320
        val <<= 8;
321
    }
322
    if (!(val & 0xF000000000000000ULL)) {
323
        cnt += 4;
324
        val <<= 4;
325
    }
326
    if (!(val & 0xC000000000000000ULL)) {
327
        cnt += 2;
328
        val <<= 2;
329
    }
330
    if (!(val & 0x8000000000000000ULL)) {
331
        cnt++;
332
        val <<= 1;
333
    }
334
    if (!(val & 0x8000000000000000ULL)) {
335
        cnt++;
336
    }
337
#else
338
    /* Make it easier on 32 bits host machines */
339
    if (!(val >> 32))
340
        cnt = _do_cntlzw(val) + 32;
341
    else
342
        cnt = _do_cntlzw(val >> 32);
343
#endif
344
    return cnt;
345
}
346

    
347
#if defined(TARGET_PPCEMB)
348
/* SPE extension */
349
/* Single precision floating-point helpers */
350
static inline uint32_t _do_efsabs (uint32_t val)
351
{
352
    return val & ~0x80000000;
353
}
354
static inline uint32_t _do_efsnabs (uint32_t val)
355
{
356
    return val | 0x80000000;
357
}
358
static inline uint32_t _do_efsneg (uint32_t val)
359
{
360
    return val ^ 0x80000000;
361
}
362
static inline uint32_t _do_efsadd (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_add(u1.f, u2.f, &env->spe_status);
371
    return u1.u;
372
}
373
static inline uint32_t _do_efssub (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_sub(u1.f, u2.f, &env->spe_status);
382
    return u1.u;
383
}
384
static inline uint32_t _do_efsmul (uint32_t op1, uint32_t op2)
385
{
386
    union {
387
        uint32_t u;
388
        float32 f;
389
    } u1, u2;
390
    u1.u = op1;
391
    u2.u = op2;
392
    u1.f = float32_mul(u1.f, u2.f, &env->spe_status);
393
    return u1.u;
394
}
395
static inline uint32_t _do_efsdiv (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
    u1.f = float32_div(u1.f, u2.f, &env->spe_status);
404
    return u1.u;
405
}
406

    
407
static inline int _do_efststlt (uint32_t op1, uint32_t op2)
408
{
409
    union {
410
        uint32_t u;
411
        float32 f;
412
    } u1, u2;
413
    u1.u = op1;
414
    u2.u = op2;
415
    return float32_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0;
416
}
417
static inline int _do_efststgt (uint32_t op1, uint32_t op2)
418
{
419
    union {
420
        uint32_t u;
421
        float32 f;
422
    } u1, u2;
423
    u1.u = op1;
424
    u2.u = op2;
425
    return float32_le(u1.f, u2.f, &env->spe_status) ? 0 : 1;
426
}
427
static inline int _do_efststeq (uint32_t op1, uint32_t op2)
428
{
429
    union {
430
        uint32_t u;
431
        float32 f;
432
    } u1, u2;
433
    u1.u = op1;
434
    u2.u = op2;
435
    return float32_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0;
436
}
437
/* Double precision floating-point helpers */
438
static inline int _do_efdtstlt (uint64_t op1, uint64_t op2)
439
{
440
    union {
441
        uint64_t u;
442
        float64 f;
443
    } u1, u2;
444
    u1.u = op1;
445
    u2.u = op2;
446
    return float64_lt(u1.f, u2.f, &env->spe_status) ? 1 : 0;
447
}
448
static inline int _do_efdtstgt (uint64_t op1, uint64_t op2)
449
{
450
    union {
451
        uint64_t u;
452
        float64 f;
453
    } u1, u2;
454
    u1.u = op1;
455
    u2.u = op2;
456
    return float64_le(u1.f, u2.f, &env->spe_status) ? 0 : 1;
457
}
458
static inline int _do_efdtsteq (uint64_t op1, uint64_t op2)
459
{
460
    union {
461
        uint64_t u;
462
        float64 f;
463
    } u1, u2;
464
    u1.u = op1;
465
    u2.u = op2;
466
    return float64_eq(u1.f, u2.f, &env->spe_status) ? 1 : 0;
467
}
468
#endif /* defined(TARGET_PPCEMB) */
469
#endif