Statistics
| Branch: | Revision:

root / target-mips / op.c @ 9278480e

History | View | Annotate | Download (58.1 kB)

1 6af0bf9c bellard
/*
2 6af0bf9c bellard
 *  MIPS emulation micro-operations for qemu.
3 5fafdf24 ths
 *
4 6af0bf9c bellard
 *  Copyright (c) 2004-2005 Jocelyn Mayer
5 6ea83fed bellard
 *  Copyright (c) 2006 Marius Groeger (FPU operations)
6 93b12ccc ths
 *  Copyright (c) 2007 Thiemo Seufer (64-bit FPU support)
7 6af0bf9c bellard
 *
8 6af0bf9c bellard
 * This library is free software; you can redistribute it and/or
9 6af0bf9c bellard
 * modify it under the terms of the GNU Lesser General Public
10 6af0bf9c bellard
 * License as published by the Free Software Foundation; either
11 6af0bf9c bellard
 * version 2 of the License, or (at your option) any later version.
12 6af0bf9c bellard
 *
13 6af0bf9c bellard
 * This library is distributed in the hope that it will be useful,
14 6af0bf9c bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 6af0bf9c bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 6af0bf9c bellard
 * Lesser General Public License for more details.
17 6af0bf9c bellard
 *
18 6af0bf9c bellard
 * You should have received a copy of the GNU Lesser General Public
19 6af0bf9c bellard
 * License along with this library; if not, write to the Free Software
20 6af0bf9c bellard
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21 6af0bf9c bellard
 */
22 6af0bf9c bellard
23 6af0bf9c bellard
#include "config.h"
24 6af0bf9c bellard
#include "exec.h"
25 6af0bf9c bellard
26 1b351e52 bellard
#ifndef CALL_FROM_TB0
27 5a5012ec ths
#define CALL_FROM_TB0(func) func()
28 1b351e52 bellard
#endif
29 1b351e52 bellard
#ifndef CALL_FROM_TB1
30 5a5012ec ths
#define CALL_FROM_TB1(func, arg0) func(arg0)
31 1b351e52 bellard
#endif
32 1b351e52 bellard
#ifndef CALL_FROM_TB1_CONST16
33 5a5012ec ths
#define CALL_FROM_TB1_CONST16(func, arg0) CALL_FROM_TB1(func, arg0)
34 1b351e52 bellard
#endif
35 1b351e52 bellard
#ifndef CALL_FROM_TB2
36 5a5012ec ths
#define CALL_FROM_TB2(func, arg0, arg1) func(arg0, arg1)
37 1b351e52 bellard
#endif
38 1b351e52 bellard
#ifndef CALL_FROM_TB2_CONST16
39 1b351e52 bellard
#define CALL_FROM_TB2_CONST16(func, arg0, arg1)     \
40 5a5012ec ths
        CALL_FROM_TB2(func, arg0, arg1)
41 1b351e52 bellard
#endif
42 1b351e52 bellard
#ifndef CALL_FROM_TB3
43 5a5012ec ths
#define CALL_FROM_TB3(func, arg0, arg1, arg2) func(arg0, arg1, arg2)
44 1b351e52 bellard
#endif
45 1b351e52 bellard
#ifndef CALL_FROM_TB4
46 1b351e52 bellard
#define CALL_FROM_TB4(func, arg0, arg1, arg2, arg3) \
47 5a5012ec ths
        func(arg0, arg1, arg2, arg3)
48 1b351e52 bellard
#endif
49 1b351e52 bellard
50 6af0bf9c bellard
#define REG 1
51 6af0bf9c bellard
#include "op_template.c"
52 6af0bf9c bellard
#undef REG
53 6af0bf9c bellard
#define REG 2
54 6af0bf9c bellard
#include "op_template.c"
55 6af0bf9c bellard
#undef REG
56 6af0bf9c bellard
#define REG 3
57 6af0bf9c bellard
#include "op_template.c"
58 6af0bf9c bellard
#undef REG
59 6af0bf9c bellard
#define REG 4
60 6af0bf9c bellard
#include "op_template.c"
61 6af0bf9c bellard
#undef REG
62 6af0bf9c bellard
#define REG 5
63 6af0bf9c bellard
#include "op_template.c"
64 6af0bf9c bellard
#undef REG
65 6af0bf9c bellard
#define REG 6
66 6af0bf9c bellard
#include "op_template.c"
67 6af0bf9c bellard
#undef REG
68 6af0bf9c bellard
#define REG 7
69 6af0bf9c bellard
#include "op_template.c"
70 6af0bf9c bellard
#undef REG
71 6af0bf9c bellard
#define REG 8
72 6af0bf9c bellard
#include "op_template.c"
73 6af0bf9c bellard
#undef REG
74 6af0bf9c bellard
#define REG 9
75 6af0bf9c bellard
#include "op_template.c"
76 6af0bf9c bellard
#undef REG
77 6af0bf9c bellard
#define REG 10
78 6af0bf9c bellard
#include "op_template.c"
79 6af0bf9c bellard
#undef REG
80 6af0bf9c bellard
#define REG 11
81 6af0bf9c bellard
#include "op_template.c"
82 6af0bf9c bellard
#undef REG
83 6af0bf9c bellard
#define REG 12
84 6af0bf9c bellard
#include "op_template.c"
85 6af0bf9c bellard
#undef REG
86 6af0bf9c bellard
#define REG 13
87 6af0bf9c bellard
#include "op_template.c"
88 6af0bf9c bellard
#undef REG
89 6af0bf9c bellard
#define REG 14
90 6af0bf9c bellard
#include "op_template.c"
91 6af0bf9c bellard
#undef REG
92 6af0bf9c bellard
#define REG 15
93 6af0bf9c bellard
#include "op_template.c"
94 6af0bf9c bellard
#undef REG
95 6af0bf9c bellard
#define REG 16
96 6af0bf9c bellard
#include "op_template.c"
97 6af0bf9c bellard
#undef REG
98 6af0bf9c bellard
#define REG 17
99 6af0bf9c bellard
#include "op_template.c"
100 6af0bf9c bellard
#undef REG
101 6af0bf9c bellard
#define REG 18
102 6af0bf9c bellard
#include "op_template.c"
103 6af0bf9c bellard
#undef REG
104 6af0bf9c bellard
#define REG 19
105 6af0bf9c bellard
#include "op_template.c"
106 6af0bf9c bellard
#undef REG
107 6af0bf9c bellard
#define REG 20
108 6af0bf9c bellard
#include "op_template.c"
109 6af0bf9c bellard
#undef REG
110 6af0bf9c bellard
#define REG 21
111 6af0bf9c bellard
#include "op_template.c"
112 6af0bf9c bellard
#undef REG
113 6af0bf9c bellard
#define REG 22
114 6af0bf9c bellard
#include "op_template.c"
115 6af0bf9c bellard
#undef REG
116 6af0bf9c bellard
#define REG 23
117 6af0bf9c bellard
#include "op_template.c"
118 6af0bf9c bellard
#undef REG
119 6af0bf9c bellard
#define REG 24
120 6af0bf9c bellard
#include "op_template.c"
121 6af0bf9c bellard
#undef REG
122 6af0bf9c bellard
#define REG 25
123 6af0bf9c bellard
#include "op_template.c"
124 6af0bf9c bellard
#undef REG
125 6af0bf9c bellard
#define REG 26
126 6af0bf9c bellard
#include "op_template.c"
127 6af0bf9c bellard
#undef REG
128 6af0bf9c bellard
#define REG 27
129 6af0bf9c bellard
#include "op_template.c"
130 6af0bf9c bellard
#undef REG
131 6af0bf9c bellard
#define REG 28
132 6af0bf9c bellard
#include "op_template.c"
133 6af0bf9c bellard
#undef REG
134 6af0bf9c bellard
#define REG 29
135 6af0bf9c bellard
#include "op_template.c"
136 6af0bf9c bellard
#undef REG
137 6af0bf9c bellard
#define REG 30
138 6af0bf9c bellard
#include "op_template.c"
139 6af0bf9c bellard
#undef REG
140 6af0bf9c bellard
#define REG 31
141 6af0bf9c bellard
#include "op_template.c"
142 6af0bf9c bellard
#undef REG
143 6af0bf9c bellard
144 c570fd16 ths
#define TN
145 6af0bf9c bellard
#include "op_template.c"
146 6af0bf9c bellard
#undef TN
147 6af0bf9c bellard
148 5a5012ec ths
#define FREG 0
149 6ea83fed bellard
#include "fop_template.c"
150 5a5012ec ths
#undef FREG
151 5a5012ec ths
#define FREG 1
152 6ea83fed bellard
#include "fop_template.c"
153 5a5012ec ths
#undef FREG
154 5a5012ec ths
#define FREG 2
155 6ea83fed bellard
#include "fop_template.c"
156 5a5012ec ths
#undef FREG
157 5a5012ec ths
#define FREG 3
158 6ea83fed bellard
#include "fop_template.c"
159 5a5012ec ths
#undef FREG
160 5a5012ec ths
#define FREG 4
161 6ea83fed bellard
#include "fop_template.c"
162 5a5012ec ths
#undef FREG
163 5a5012ec ths
#define FREG 5
164 6ea83fed bellard
#include "fop_template.c"
165 5a5012ec ths
#undef FREG
166 5a5012ec ths
#define FREG 6
167 6ea83fed bellard
#include "fop_template.c"
168 5a5012ec ths
#undef FREG
169 5a5012ec ths
#define FREG 7
170 6ea83fed bellard
#include "fop_template.c"
171 5a5012ec ths
#undef FREG
172 5a5012ec ths
#define FREG 8
173 6ea83fed bellard
#include "fop_template.c"
174 5a5012ec ths
#undef FREG
175 5a5012ec ths
#define FREG 9
176 6ea83fed bellard
#include "fop_template.c"
177 5a5012ec ths
#undef FREG
178 5a5012ec ths
#define FREG 10
179 6ea83fed bellard
#include "fop_template.c"
180 5a5012ec ths
#undef FREG
181 5a5012ec ths
#define FREG 11
182 6ea83fed bellard
#include "fop_template.c"
183 5a5012ec ths
#undef FREG
184 5a5012ec ths
#define FREG 12
185 6ea83fed bellard
#include "fop_template.c"
186 5a5012ec ths
#undef FREG
187 5a5012ec ths
#define FREG 13
188 6ea83fed bellard
#include "fop_template.c"
189 5a5012ec ths
#undef FREG
190 5a5012ec ths
#define FREG 14
191 6ea83fed bellard
#include "fop_template.c"
192 5a5012ec ths
#undef FREG
193 5a5012ec ths
#define FREG 15
194 6ea83fed bellard
#include "fop_template.c"
195 5a5012ec ths
#undef FREG
196 5a5012ec ths
#define FREG 16
197 6ea83fed bellard
#include "fop_template.c"
198 5a5012ec ths
#undef FREG
199 5a5012ec ths
#define FREG 17
200 6ea83fed bellard
#include "fop_template.c"
201 5a5012ec ths
#undef FREG
202 5a5012ec ths
#define FREG 18
203 6ea83fed bellard
#include "fop_template.c"
204 5a5012ec ths
#undef FREG
205 5a5012ec ths
#define FREG 19
206 6ea83fed bellard
#include "fop_template.c"
207 5a5012ec ths
#undef FREG
208 5a5012ec ths
#define FREG 20
209 6ea83fed bellard
#include "fop_template.c"
210 5a5012ec ths
#undef FREG
211 5a5012ec ths
#define FREG 21
212 6ea83fed bellard
#include "fop_template.c"
213 5a5012ec ths
#undef FREG
214 5a5012ec ths
#define FREG 22
215 6ea83fed bellard
#include "fop_template.c"
216 5a5012ec ths
#undef FREG
217 5a5012ec ths
#define FREG 23
218 6ea83fed bellard
#include "fop_template.c"
219 5a5012ec ths
#undef FREG
220 5a5012ec ths
#define FREG 24
221 6ea83fed bellard
#include "fop_template.c"
222 5a5012ec ths
#undef FREG
223 5a5012ec ths
#define FREG 25
224 6ea83fed bellard
#include "fop_template.c"
225 5a5012ec ths
#undef FREG
226 5a5012ec ths
#define FREG 26
227 6ea83fed bellard
#include "fop_template.c"
228 5a5012ec ths
#undef FREG
229 5a5012ec ths
#define FREG 27
230 6ea83fed bellard
#include "fop_template.c"
231 5a5012ec ths
#undef FREG
232 5a5012ec ths
#define FREG 28
233 6ea83fed bellard
#include "fop_template.c"
234 5a5012ec ths
#undef FREG
235 5a5012ec ths
#define FREG 29
236 6ea83fed bellard
#include "fop_template.c"
237 5a5012ec ths
#undef FREG
238 5a5012ec ths
#define FREG 30
239 6ea83fed bellard
#include "fop_template.c"
240 5a5012ec ths
#undef FREG
241 5a5012ec ths
#define FREG 31
242 6ea83fed bellard
#include "fop_template.c"
243 5a5012ec ths
#undef FREG
244 6ea83fed bellard
245 6ea83fed bellard
#define FTN
246 6ea83fed bellard
#include "fop_template.c"
247 6ea83fed bellard
#undef FTN
248 6ea83fed bellard
249 6af0bf9c bellard
void op_dup_T0 (void)
250 6af0bf9c bellard
{
251 6af0bf9c bellard
    T2 = T0;
252 6af0bf9c bellard
    RETURN();
253 6af0bf9c bellard
}
254 6af0bf9c bellard
255 6af0bf9c bellard
void op_load_HI (void)
256 6af0bf9c bellard
{
257 ead9360e ths
    T0 = env->HI[PARAM1][env->current_tc];
258 6af0bf9c bellard
    RETURN();
259 6af0bf9c bellard
}
260 6af0bf9c bellard
261 6af0bf9c bellard
void op_store_HI (void)
262 6af0bf9c bellard
{
263 ead9360e ths
    env->HI[PARAM1][env->current_tc] = T0;
264 6af0bf9c bellard
    RETURN();
265 6af0bf9c bellard
}
266 6af0bf9c bellard
267 6af0bf9c bellard
void op_load_LO (void)
268 6af0bf9c bellard
{
269 ead9360e ths
    T0 = env->LO[PARAM1][env->current_tc];
270 6af0bf9c bellard
    RETURN();
271 6af0bf9c bellard
}
272 6af0bf9c bellard
273 6af0bf9c bellard
void op_store_LO (void)
274 6af0bf9c bellard
{
275 ead9360e ths
    env->LO[PARAM1][env->current_tc] = T0;
276 6af0bf9c bellard
    RETURN();
277 6af0bf9c bellard
}
278 6af0bf9c bellard
279 6af0bf9c bellard
/* Load and store */
280 6af0bf9c bellard
#define MEMSUFFIX _raw
281 6af0bf9c bellard
#include "op_mem.c"
282 6af0bf9c bellard
#undef MEMSUFFIX
283 6af0bf9c bellard
#if !defined(CONFIG_USER_ONLY)
284 6af0bf9c bellard
#define MEMSUFFIX _user
285 6af0bf9c bellard
#include "op_mem.c"
286 6af0bf9c bellard
#undef MEMSUFFIX
287 6af0bf9c bellard
288 6af0bf9c bellard
#define MEMSUFFIX _kernel
289 6af0bf9c bellard
#include "op_mem.c"
290 6af0bf9c bellard
#undef MEMSUFFIX
291 6af0bf9c bellard
#endif
292 6af0bf9c bellard
293 a6763a58 ths
/* Addresses computation */
294 a6763a58 ths
void op_addr_add (void)
295 a6763a58 ths
{
296 a6763a58 ths
/* For compatibility with 32-bit code, data reference in user mode
297 a6763a58 ths
   with Status_UX = 0 should be casted to 32-bit and sign extended.
298 a6763a58 ths
   See the MIPS64 PRA manual, section 4.10. */
299 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
300 996ba2cc ths
    if ((env->hflags & MIPS_HFLAG_UM) &&
301 a6763a58 ths
        !(env->CP0_Status & (1 << CP0St_UX)))
302 a6763a58 ths
        T0 = (int64_t)(int32_t)(T0 + T1);
303 a6763a58 ths
    else
304 a6763a58 ths
#endif
305 a6763a58 ths
        T0 += T1;
306 a6763a58 ths
    RETURN();
307 a6763a58 ths
}
308 a6763a58 ths
309 6af0bf9c bellard
/* Arithmetic */
310 6af0bf9c bellard
void op_add (void)
311 6af0bf9c bellard
{
312 5dc4b744 ths
    T0 = (int32_t)((int32_t)T0 + (int32_t)T1);
313 6af0bf9c bellard
    RETURN();
314 6af0bf9c bellard
}
315 6af0bf9c bellard
316 6af0bf9c bellard
void op_addo (void)
317 6af0bf9c bellard
{
318 6af0bf9c bellard
    target_ulong tmp;
319 6af0bf9c bellard
320 c570fd16 ths
    tmp = (int32_t)T0;
321 c570fd16 ths
    T0 = (int32_t)T0 + (int32_t)T1;
322 76e050c2 bellard
    if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 31) {
323 c570fd16 ths
        /* operands of same sign, result different sign */
324 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
325 6af0bf9c bellard
    }
326 5dc4b744 ths
    T0 = (int32_t)T0;
327 6af0bf9c bellard
    RETURN();
328 6af0bf9c bellard
}
329 6af0bf9c bellard
330 6af0bf9c bellard
void op_sub (void)
331 6af0bf9c bellard
{
332 5dc4b744 ths
    T0 = (int32_t)((int32_t)T0 - (int32_t)T1);
333 6af0bf9c bellard
    RETURN();
334 6af0bf9c bellard
}
335 6af0bf9c bellard
336 6af0bf9c bellard
void op_subo (void)
337 6af0bf9c bellard
{
338 6af0bf9c bellard
    target_ulong tmp;
339 6af0bf9c bellard
340 c570fd16 ths
    tmp = (int32_t)T0;
341 6af0bf9c bellard
    T0 = (int32_t)T0 - (int32_t)T1;
342 76e050c2 bellard
    if (((tmp ^ T1) & (tmp ^ T0)) >> 31) {
343 c570fd16 ths
        /* operands of different sign, first operand and result different sign */
344 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
345 6af0bf9c bellard
    }
346 5dc4b744 ths
    T0 = (int32_t)T0;
347 6af0bf9c bellard
    RETURN();
348 6af0bf9c bellard
}
349 6af0bf9c bellard
350 6af0bf9c bellard
void op_mul (void)
351 6af0bf9c bellard
{
352 5dc4b744 ths
    T0 = (int32_t)((int32_t)T0 * (int32_t)T1);
353 6af0bf9c bellard
    RETURN();
354 6af0bf9c bellard
}
355 6af0bf9c bellard
356 80c27194 ths
#if HOST_LONG_BITS < 64
357 80c27194 ths
void op_div (void)
358 80c27194 ths
{
359 80c27194 ths
    CALL_FROM_TB0(do_div);
360 80c27194 ths
    RETURN();
361 80c27194 ths
}
362 80c27194 ths
#else
363 6af0bf9c bellard
void op_div (void)
364 6af0bf9c bellard
{
365 6af0bf9c bellard
    if (T1 != 0) {
366 ead9360e ths
        env->LO[0][env->current_tc] = (int32_t)((int64_t)(int32_t)T0 / (int32_t)T1);
367 ead9360e ths
        env->HI[0][env->current_tc] = (int32_t)((int64_t)(int32_t)T0 % (int32_t)T1);
368 6af0bf9c bellard
    }
369 6af0bf9c bellard
    RETURN();
370 6af0bf9c bellard
}
371 80c27194 ths
#endif
372 6af0bf9c bellard
373 6af0bf9c bellard
void op_divu (void)
374 6af0bf9c bellard
{
375 6af0bf9c bellard
    if (T1 != 0) {
376 ead9360e ths
        env->LO[0][env->current_tc] = (int32_t)((uint32_t)T0 / (uint32_t)T1);
377 ead9360e ths
        env->HI[0][env->current_tc] = (int32_t)((uint32_t)T0 % (uint32_t)T1);
378 c570fd16 ths
    }
379 c570fd16 ths
    RETURN();
380 c570fd16 ths
}
381 c570fd16 ths
382 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
383 c570fd16 ths
/* Arithmetic */
384 c570fd16 ths
void op_dadd (void)
385 c570fd16 ths
{
386 c570fd16 ths
    T0 += T1;
387 c570fd16 ths
    RETURN();
388 c570fd16 ths
}
389 c570fd16 ths
390 c570fd16 ths
void op_daddo (void)
391 c570fd16 ths
{
392 c570fd16 ths
    target_long tmp;
393 c570fd16 ths
394 c570fd16 ths
    tmp = T0;
395 c570fd16 ths
    T0 += T1;
396 c570fd16 ths
    if (((tmp ^ T1 ^ (-1)) & (T0 ^ T1)) >> 63) {
397 c570fd16 ths
        /* operands of same sign, result different sign */
398 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
399 c570fd16 ths
    }
400 c570fd16 ths
    RETURN();
401 c570fd16 ths
}
402 c570fd16 ths
403 c570fd16 ths
void op_dsub (void)
404 c570fd16 ths
{
405 c570fd16 ths
    T0 -= T1;
406 c570fd16 ths
    RETURN();
407 c570fd16 ths
}
408 c570fd16 ths
409 c570fd16 ths
void op_dsubo (void)
410 c570fd16 ths
{
411 c570fd16 ths
    target_long tmp;
412 c570fd16 ths
413 c570fd16 ths
    tmp = T0;
414 c570fd16 ths
    T0 = (int64_t)T0 - (int64_t)T1;
415 c570fd16 ths
    if (((tmp ^ T1) & (tmp ^ T0)) >> 63) {
416 c570fd16 ths
        /* operands of different sign, first operand and result different sign */
417 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_OVERFLOW);
418 c570fd16 ths
    }
419 c570fd16 ths
    RETURN();
420 c570fd16 ths
}
421 c570fd16 ths
422 c570fd16 ths
void op_dmul (void)
423 c570fd16 ths
{
424 c570fd16 ths
    T0 = (int64_t)T0 * (int64_t)T1;
425 c570fd16 ths
    RETURN();
426 c570fd16 ths
}
427 c570fd16 ths
428 c570fd16 ths
/* Those might call libgcc functions.  */
429 c570fd16 ths
void op_ddiv (void)
430 c570fd16 ths
{
431 c570fd16 ths
    do_ddiv();
432 c570fd16 ths
    RETURN();
433 c570fd16 ths
}
434 c570fd16 ths
435 80c27194 ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
436 c570fd16 ths
void op_ddivu (void)
437 c570fd16 ths
{
438 c570fd16 ths
    do_ddivu();
439 c570fd16 ths
    RETURN();
440 c570fd16 ths
}
441 c570fd16 ths
#else
442 c570fd16 ths
void op_ddivu (void)
443 c570fd16 ths
{
444 c570fd16 ths
    if (T1 != 0) {
445 ead9360e ths
        env->LO[0][env->current_tc] = T0 / T1;
446 ead9360e ths
        env->HI[0][env->current_tc] = T0 % T1;
447 6af0bf9c bellard
    }
448 6af0bf9c bellard
    RETURN();
449 6af0bf9c bellard
}
450 c570fd16 ths
#endif
451 540635ba ths
#endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
452 6af0bf9c bellard
453 6af0bf9c bellard
/* Logical */
454 6af0bf9c bellard
void op_and (void)
455 6af0bf9c bellard
{
456 6af0bf9c bellard
    T0 &= T1;
457 6af0bf9c bellard
    RETURN();
458 6af0bf9c bellard
}
459 6af0bf9c bellard
460 6af0bf9c bellard
void op_nor (void)
461 6af0bf9c bellard
{
462 6af0bf9c bellard
    T0 = ~(T0 | T1);
463 6af0bf9c bellard
    RETURN();
464 6af0bf9c bellard
}
465 6af0bf9c bellard
466 6af0bf9c bellard
void op_or (void)
467 6af0bf9c bellard
{
468 6af0bf9c bellard
    T0 |= T1;
469 6af0bf9c bellard
    RETURN();
470 6af0bf9c bellard
}
471 6af0bf9c bellard
472 6af0bf9c bellard
void op_xor (void)
473 6af0bf9c bellard
{
474 6af0bf9c bellard
    T0 ^= T1;
475 6af0bf9c bellard
    RETURN();
476 6af0bf9c bellard
}
477 6af0bf9c bellard
478 6af0bf9c bellard
void op_sll (void)
479 6af0bf9c bellard
{
480 5a63bcb2 ths
    T0 = (int32_t)((uint32_t)T0 << T1);
481 6af0bf9c bellard
    RETURN();
482 6af0bf9c bellard
}
483 6af0bf9c bellard
484 6af0bf9c bellard
void op_sra (void)
485 6af0bf9c bellard
{
486 5a63bcb2 ths
    T0 = (int32_t)((int32_t)T0 >> T1);
487 6af0bf9c bellard
    RETURN();
488 6af0bf9c bellard
}
489 6af0bf9c bellard
490 6af0bf9c bellard
void op_srl (void)
491 6af0bf9c bellard
{
492 5a63bcb2 ths
    T0 = (int32_t)((uint32_t)T0 >> T1);
493 6af0bf9c bellard
    RETURN();
494 6af0bf9c bellard
}
495 6af0bf9c bellard
496 7a387fff ths
void op_rotr (void)
497 7a387fff ths
{
498 7a387fff ths
    target_ulong tmp;
499 7a387fff ths
500 7a387fff ths
    if (T1) {
501 5a63bcb2 ths
       tmp = (int32_t)((uint32_t)T0 << (0x20 - T1));
502 5a63bcb2 ths
       T0 = (int32_t)((uint32_t)T0 >> T1) | tmp;
503 5a63bcb2 ths
    }
504 7a387fff ths
    RETURN();
505 7a387fff ths
}
506 7a387fff ths
507 6af0bf9c bellard
void op_sllv (void)
508 6af0bf9c bellard
{
509 5dc4b744 ths
    T0 = (int32_t)((uint32_t)T1 << ((uint32_t)T0 & 0x1F));
510 6af0bf9c bellard
    RETURN();
511 6af0bf9c bellard
}
512 6af0bf9c bellard
513 6af0bf9c bellard
void op_srav (void)
514 6af0bf9c bellard
{
515 5dc4b744 ths
    T0 = (int32_t)((int32_t)T1 >> (T0 & 0x1F));
516 6af0bf9c bellard
    RETURN();
517 6af0bf9c bellard
}
518 6af0bf9c bellard
519 6af0bf9c bellard
void op_srlv (void)
520 6af0bf9c bellard
{
521 5dc4b744 ths
    T0 = (int32_t)((uint32_t)T1 >> (T0 & 0x1F));
522 6af0bf9c bellard
    RETURN();
523 6af0bf9c bellard
}
524 6af0bf9c bellard
525 7a387fff ths
void op_rotrv (void)
526 7a387fff ths
{
527 7a387fff ths
    target_ulong tmp;
528 7a387fff ths
529 7a387fff ths
    T0 &= 0x1F;
530 7a387fff ths
    if (T0) {
531 5dc4b744 ths
       tmp = (int32_t)((uint32_t)T1 << (0x20 - T0));
532 5dc4b744 ths
       T0 = (int32_t)((uint32_t)T1 >> T0) | tmp;
533 7a387fff ths
    } else
534 7a387fff ths
       T0 = T1;
535 7a387fff ths
    RETURN();
536 7a387fff ths
}
537 7a387fff ths
538 6af0bf9c bellard
void op_clo (void)
539 6af0bf9c bellard
{
540 6af0bf9c bellard
    int n;
541 6af0bf9c bellard
542 c570fd16 ths
    if (T0 == ~((target_ulong)0)) {
543 6af0bf9c bellard
        T0 = 32;
544 6af0bf9c bellard
    } else {
545 6af0bf9c bellard
        for (n = 0; n < 32; n++) {
546 9278480e ths
            if (!(((int32_t)T0) & (1 << 31)))
547 6af0bf9c bellard
                break;
548 9278480e ths
            T0 <<= 1;
549 6af0bf9c bellard
        }
550 6af0bf9c bellard
        T0 = n;
551 6af0bf9c bellard
    }
552 6af0bf9c bellard
    RETURN();
553 6af0bf9c bellard
}
554 6af0bf9c bellard
555 6af0bf9c bellard
void op_clz (void)
556 6af0bf9c bellard
{
557 6af0bf9c bellard
    int n;
558 6af0bf9c bellard
559 6af0bf9c bellard
    if (T0 == 0) {
560 6af0bf9c bellard
        T0 = 32;
561 6af0bf9c bellard
    } else {
562 6af0bf9c bellard
        for (n = 0; n < 32; n++) {
563 6af0bf9c bellard
            if (T0 & (1 << 31))
564 6af0bf9c bellard
                break;
565 9278480e ths
            T0 <<= 1;
566 6af0bf9c bellard
        }
567 6af0bf9c bellard
        T0 = n;
568 6af0bf9c bellard
    }
569 6af0bf9c bellard
    RETURN();
570 6af0bf9c bellard
}
571 6af0bf9c bellard
572 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
573 c570fd16 ths
574 c570fd16 ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
575 c570fd16 ths
/* Those might call libgcc functions.  */
576 c570fd16 ths
void op_dsll (void)
577 6af0bf9c bellard
{
578 c570fd16 ths
    CALL_FROM_TB0(do_dsll);
579 c570fd16 ths
    RETURN();
580 6af0bf9c bellard
}
581 6af0bf9c bellard
582 c570fd16 ths
void op_dsll32 (void)
583 6af0bf9c bellard
{
584 c570fd16 ths
    CALL_FROM_TB0(do_dsll32);
585 c570fd16 ths
    RETURN();
586 6af0bf9c bellard
}
587 6af0bf9c bellard
588 c570fd16 ths
void op_dsra (void)
589 6af0bf9c bellard
{
590 c570fd16 ths
    CALL_FROM_TB0(do_dsra);
591 6af0bf9c bellard
    RETURN();
592 6af0bf9c bellard
}
593 6af0bf9c bellard
594 c570fd16 ths
void op_dsra32 (void)
595 6af0bf9c bellard
{
596 c570fd16 ths
    CALL_FROM_TB0(do_dsra32);
597 6af0bf9c bellard
    RETURN();
598 6af0bf9c bellard
}
599 6af0bf9c bellard
600 c570fd16 ths
void op_dsrl (void)
601 6af0bf9c bellard
{
602 c570fd16 ths
    CALL_FROM_TB0(do_dsrl);
603 c570fd16 ths
    RETURN();
604 c570fd16 ths
}
605 6af0bf9c bellard
606 c570fd16 ths
void op_dsrl32 (void)
607 c570fd16 ths
{
608 c570fd16 ths
    CALL_FROM_TB0(do_dsrl32);
609 6af0bf9c bellard
    RETURN();
610 6af0bf9c bellard
}
611 6af0bf9c bellard
612 c570fd16 ths
void op_drotr (void)
613 6af0bf9c bellard
{
614 c570fd16 ths
    CALL_FROM_TB0(do_drotr);
615 c570fd16 ths
    RETURN();
616 c570fd16 ths
}
617 6af0bf9c bellard
618 c570fd16 ths
void op_drotr32 (void)
619 c570fd16 ths
{
620 c570fd16 ths
    CALL_FROM_TB0(do_drotr32);
621 6af0bf9c bellard
    RETURN();
622 6af0bf9c bellard
}
623 6af0bf9c bellard
624 c570fd16 ths
void op_dsllv (void)
625 6af0bf9c bellard
{
626 c570fd16 ths
    CALL_FROM_TB0(do_dsllv);
627 c570fd16 ths
    RETURN();
628 c570fd16 ths
}
629 6af0bf9c bellard
630 c570fd16 ths
void op_dsrav (void)
631 c570fd16 ths
{
632 c570fd16 ths
    CALL_FROM_TB0(do_dsrav);
633 6af0bf9c bellard
    RETURN();
634 6af0bf9c bellard
}
635 6af0bf9c bellard
636 c570fd16 ths
void op_dsrlv (void)
637 6af0bf9c bellard
{
638 c570fd16 ths
    CALL_FROM_TB0(do_dsrlv);
639 c570fd16 ths
    RETURN();
640 c570fd16 ths
}
641 6af0bf9c bellard
642 c570fd16 ths
void op_drotrv (void)
643 c570fd16 ths
{
644 c570fd16 ths
    CALL_FROM_TB0(do_drotrv);
645 6af0bf9c bellard
    RETURN();
646 6af0bf9c bellard
}
647 c570fd16 ths
648 c570fd16 ths
#else /* TARGET_LONG_BITS > HOST_LONG_BITS */
649 c570fd16 ths
650 c570fd16 ths
void op_dsll (void)
651 c570fd16 ths
{
652 c570fd16 ths
    T0 = T0 << T1;
653 c570fd16 ths
    RETURN();
654 c570fd16 ths
}
655 c570fd16 ths
656 c570fd16 ths
void op_dsll32 (void)
657 c570fd16 ths
{
658 c570fd16 ths
    T0 = T0 << (T1 + 32);
659 c570fd16 ths
    RETURN();
660 c570fd16 ths
}
661 c570fd16 ths
662 c570fd16 ths
void op_dsra (void)
663 c570fd16 ths
{
664 c570fd16 ths
    T0 = (int64_t)T0 >> T1;
665 c570fd16 ths
    RETURN();
666 c570fd16 ths
}
667 c570fd16 ths
668 c570fd16 ths
void op_dsra32 (void)
669 c570fd16 ths
{
670 c570fd16 ths
    T0 = (int64_t)T0 >> (T1 + 32);
671 c570fd16 ths
    RETURN();
672 c570fd16 ths
}
673 c570fd16 ths
674 c570fd16 ths
void op_dsrl (void)
675 c570fd16 ths
{
676 c570fd16 ths
    T0 = T0 >> T1;
677 c570fd16 ths
    RETURN();
678 c570fd16 ths
}
679 c570fd16 ths
680 c570fd16 ths
void op_dsrl32 (void)
681 c570fd16 ths
{
682 c570fd16 ths
    T0 = T0 >> (T1 + 32);
683 c570fd16 ths
    RETURN();
684 c570fd16 ths
}
685 c570fd16 ths
686 c570fd16 ths
void op_drotr (void)
687 c570fd16 ths
{
688 c570fd16 ths
    target_ulong tmp;
689 c570fd16 ths
690 c570fd16 ths
    if (T1) {
691 c570fd16 ths
       tmp = T0 << (0x40 - T1);
692 c570fd16 ths
       T0 = (T0 >> T1) | tmp;
693 5a63bcb2 ths
    }
694 c570fd16 ths
    RETURN();
695 c570fd16 ths
}
696 c570fd16 ths
697 c570fd16 ths
void op_drotr32 (void)
698 c570fd16 ths
{
699 c570fd16 ths
    target_ulong tmp;
700 c570fd16 ths
701 c570fd16 ths
    if (T1) {
702 c570fd16 ths
       tmp = T0 << (0x40 - (32 + T1));
703 c570fd16 ths
       T0 = (T0 >> (32 + T1)) | tmp;
704 5a63bcb2 ths
    }
705 c570fd16 ths
    RETURN();
706 c570fd16 ths
}
707 c570fd16 ths
708 c570fd16 ths
void op_dsllv (void)
709 c570fd16 ths
{
710 c570fd16 ths
    T0 = T1 << (T0 & 0x3F);
711 c570fd16 ths
    RETURN();
712 c570fd16 ths
}
713 c570fd16 ths
714 c570fd16 ths
void op_dsrav (void)
715 c570fd16 ths
{
716 c570fd16 ths
    T0 = (int64_t)T1 >> (T0 & 0x3F);
717 c570fd16 ths
    RETURN();
718 c570fd16 ths
}
719 c570fd16 ths
720 c570fd16 ths
void op_dsrlv (void)
721 c570fd16 ths
{
722 c570fd16 ths
    T0 = T1 >> (T0 & 0x3F);
723 c570fd16 ths
    RETURN();
724 c570fd16 ths
}
725 c570fd16 ths
726 c570fd16 ths
void op_drotrv (void)
727 c570fd16 ths
{
728 c570fd16 ths
    target_ulong tmp;
729 c570fd16 ths
730 c570fd16 ths
    T0 &= 0x3F;
731 c570fd16 ths
    if (T0) {
732 c570fd16 ths
       tmp = T1 << (0x40 - T0);
733 c570fd16 ths
       T0 = (T1 >> T0) | tmp;
734 c570fd16 ths
    } else
735 c570fd16 ths
       T0 = T1;
736 c570fd16 ths
    RETURN();
737 c570fd16 ths
}
738 c570fd16 ths
#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
739 c570fd16 ths
740 c570fd16 ths
void op_dclo (void)
741 c570fd16 ths
{
742 c570fd16 ths
    int n;
743 c570fd16 ths
744 c570fd16 ths
    if (T0 == ~((target_ulong)0)) {
745 c570fd16 ths
        T0 = 64;
746 c570fd16 ths
    } else {
747 c570fd16 ths
        for (n = 0; n < 64; n++) {
748 c570fd16 ths
            if (!(T0 & (1ULL << 63)))
749 c570fd16 ths
                break;
750 9278480e ths
            T0 <<= 1;
751 c570fd16 ths
        }
752 c570fd16 ths
        T0 = n;
753 c570fd16 ths
    }
754 c570fd16 ths
    RETURN();
755 c570fd16 ths
}
756 c570fd16 ths
757 c570fd16 ths
void op_dclz (void)
758 c570fd16 ths
{
759 c570fd16 ths
    int n;
760 c570fd16 ths
761 c570fd16 ths
    if (T0 == 0) {
762 c570fd16 ths
        T0 = 64;
763 c570fd16 ths
    } else {
764 c570fd16 ths
        for (n = 0; n < 64; n++) {
765 c570fd16 ths
            if (T0 & (1ULL << 63))
766 c570fd16 ths
                break;
767 9278480e ths
            T0 <<= 1;
768 c570fd16 ths
        }
769 c570fd16 ths
        T0 = n;
770 c570fd16 ths
    }
771 c570fd16 ths
    RETURN();
772 c570fd16 ths
}
773 540635ba ths
#endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
774 c570fd16 ths
775 c570fd16 ths
/* 64 bits arithmetic */
776 c570fd16 ths
#if TARGET_LONG_BITS > HOST_LONG_BITS
777 6af0bf9c bellard
void op_mult (void)
778 6af0bf9c bellard
{
779 6af0bf9c bellard
    CALL_FROM_TB0(do_mult);
780 6af0bf9c bellard
    RETURN();
781 6af0bf9c bellard
}
782 6af0bf9c bellard
783 6af0bf9c bellard
void op_multu (void)
784 6af0bf9c bellard
{
785 6af0bf9c bellard
    CALL_FROM_TB0(do_multu);
786 6af0bf9c bellard
    RETURN();
787 6af0bf9c bellard
}
788 6af0bf9c bellard
789 6af0bf9c bellard
void op_madd (void)
790 6af0bf9c bellard
{
791 6af0bf9c bellard
    CALL_FROM_TB0(do_madd);
792 6af0bf9c bellard
    RETURN();
793 6af0bf9c bellard
}
794 6af0bf9c bellard
795 6af0bf9c bellard
void op_maddu (void)
796 6af0bf9c bellard
{
797 6af0bf9c bellard
    CALL_FROM_TB0(do_maddu);
798 6af0bf9c bellard
    RETURN();
799 6af0bf9c bellard
}
800 6af0bf9c bellard
801 6af0bf9c bellard
void op_msub (void)
802 6af0bf9c bellard
{
803 6af0bf9c bellard
    CALL_FROM_TB0(do_msub);
804 6af0bf9c bellard
    RETURN();
805 6af0bf9c bellard
}
806 6af0bf9c bellard
807 6af0bf9c bellard
void op_msubu (void)
808 6af0bf9c bellard
{
809 6af0bf9c bellard
    CALL_FROM_TB0(do_msubu);
810 6af0bf9c bellard
    RETURN();
811 6af0bf9c bellard
}
812 c570fd16 ths
813 c570fd16 ths
#else /* TARGET_LONG_BITS > HOST_LONG_BITS */
814 c570fd16 ths
815 aa343735 ths
static always_inline uint64_t get_HILO (void)
816 c570fd16 ths
{
817 ead9360e ths
    return ((uint64_t)env->HI[0][env->current_tc] << 32) |
818 ead9360e ths
            ((uint64_t)(uint32_t)env->LO[0][env->current_tc]);
819 c570fd16 ths
}
820 c570fd16 ths
821 aa343735 ths
static always_inline void set_HILO (uint64_t HILO)
822 c570fd16 ths
{
823 ead9360e ths
    env->LO[0][env->current_tc] = (int32_t)(HILO & 0xFFFFFFFF);
824 ead9360e ths
    env->HI[0][env->current_tc] = (int32_t)(HILO >> 32);
825 c570fd16 ths
}
826 c570fd16 ths
827 c570fd16 ths
void op_mult (void)
828 c570fd16 ths
{
829 c570fd16 ths
    set_HILO((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
830 c570fd16 ths
    RETURN();
831 c570fd16 ths
}
832 c570fd16 ths
833 c570fd16 ths
void op_multu (void)
834 c570fd16 ths
{
835 c570fd16 ths
    set_HILO((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
836 c570fd16 ths
    RETURN();
837 c570fd16 ths
}
838 c570fd16 ths
839 c570fd16 ths
void op_madd (void)
840 c570fd16 ths
{
841 c570fd16 ths
    int64_t tmp;
842 c570fd16 ths
843 c570fd16 ths
    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
844 c570fd16 ths
    set_HILO((int64_t)get_HILO() + tmp);
845 c570fd16 ths
    RETURN();
846 c570fd16 ths
}
847 c570fd16 ths
848 c570fd16 ths
void op_maddu (void)
849 c570fd16 ths
{
850 c570fd16 ths
    uint64_t tmp;
851 c570fd16 ths
852 c570fd16 ths
    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
853 c570fd16 ths
    set_HILO(get_HILO() + tmp);
854 c570fd16 ths
    RETURN();
855 c570fd16 ths
}
856 c570fd16 ths
857 c570fd16 ths
void op_msub (void)
858 c570fd16 ths
{
859 c570fd16 ths
    int64_t tmp;
860 c570fd16 ths
861 c570fd16 ths
    tmp = ((int64_t)(int32_t)T0 * (int64_t)(int32_t)T1);
862 c570fd16 ths
    set_HILO((int64_t)get_HILO() - tmp);
863 c570fd16 ths
    RETURN();
864 c570fd16 ths
}
865 c570fd16 ths
866 c570fd16 ths
void op_msubu (void)
867 c570fd16 ths
{
868 c570fd16 ths
    uint64_t tmp;
869 c570fd16 ths
870 c570fd16 ths
    tmp = ((uint64_t)(uint32_t)T0 * (uint64_t)(uint32_t)T1);
871 c570fd16 ths
    set_HILO(get_HILO() - tmp);
872 c570fd16 ths
    RETURN();
873 c570fd16 ths
}
874 c570fd16 ths
#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
875 c570fd16 ths
876 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
877 c570fd16 ths
void op_dmult (void)
878 c570fd16 ths
{
879 ead9360e ths
    CALL_FROM_TB4(muls64, &(env->HI[0][env->current_tc]), &(env->LO[0][env->current_tc]), T0, T1);
880 c570fd16 ths
    RETURN();
881 c570fd16 ths
}
882 c570fd16 ths
883 c570fd16 ths
void op_dmultu (void)
884 c570fd16 ths
{
885 ead9360e ths
    CALL_FROM_TB4(mulu64, &(env->HI[0][env->current_tc]), &(env->LO[0][env->current_tc]), T0, T1);
886 c570fd16 ths
    RETURN();
887 c570fd16 ths
}
888 6af0bf9c bellard
#endif
889 6af0bf9c bellard
890 6af0bf9c bellard
/* Conditional moves */
891 6af0bf9c bellard
void op_movn (void)
892 6af0bf9c bellard
{
893 6af0bf9c bellard
    if (T1 != 0)
894 ead9360e ths
        env->gpr[PARAM1][env->current_tc] = T0;
895 6af0bf9c bellard
    RETURN();
896 6af0bf9c bellard
}
897 6af0bf9c bellard
898 6af0bf9c bellard
void op_movz (void)
899 6af0bf9c bellard
{
900 6af0bf9c bellard
    if (T1 == 0)
901 ead9360e ths
        env->gpr[PARAM1][env->current_tc] = T0;
902 6af0bf9c bellard
    RETURN();
903 6af0bf9c bellard
}
904 6af0bf9c bellard
905 7a387fff ths
void op_movf (void)
906 7a387fff ths
{
907 ead9360e ths
    if (!(env->fpu->fcr31 & PARAM1))
908 5a5012ec ths
        T0 = T1;
909 7a387fff ths
    RETURN();
910 7a387fff ths
}
911 7a387fff ths
912 7a387fff ths
void op_movt (void)
913 7a387fff ths
{
914 ead9360e ths
    if (env->fpu->fcr31 & PARAM1)
915 5a5012ec ths
        T0 = T1;
916 7a387fff ths
    RETURN();
917 7a387fff ths
}
918 7a387fff ths
919 6af0bf9c bellard
/* Tests */
920 6af0bf9c bellard
#define OP_COND(name, cond) \
921 6af0bf9c bellard
void glue(op_, name) (void) \
922 6af0bf9c bellard
{                           \
923 6af0bf9c bellard
    if (cond) {             \
924 6af0bf9c bellard
        T0 = 1;             \
925 6af0bf9c bellard
    } else {                \
926 6af0bf9c bellard
        T0 = 0;             \
927 6af0bf9c bellard
    }                       \
928 6af0bf9c bellard
    RETURN();               \
929 6af0bf9c bellard
}
930 6af0bf9c bellard
931 6af0bf9c bellard
OP_COND(eq, T0 == T1);
932 6af0bf9c bellard
OP_COND(ne, T0 != T1);
933 f469b9db ths
OP_COND(ge, (target_long)T0 >= (target_long)T1);
934 6af0bf9c bellard
OP_COND(geu, T0 >= T1);
935 f469b9db ths
OP_COND(lt, (target_long)T0 < (target_long)T1);
936 6af0bf9c bellard
OP_COND(ltu, T0 < T1);
937 f469b9db ths
OP_COND(gez, (target_long)T0 >= 0);
938 f469b9db ths
OP_COND(gtz, (target_long)T0 > 0);
939 f469b9db ths
OP_COND(lez, (target_long)T0 <= 0);
940 f469b9db ths
OP_COND(ltz, (target_long)T0 < 0);
941 6af0bf9c bellard
942 7a387fff ths
/* Branches */
943 c53be334 bellard
void OPPROTO op_goto_tb0(void)
944 c53be334 bellard
{
945 c53be334 bellard
    GOTO_TB(op_goto_tb0, PARAM1, 0);
946 7a387fff ths
    RETURN();
947 c53be334 bellard
}
948 c53be334 bellard
949 c53be334 bellard
void OPPROTO op_goto_tb1(void)
950 c53be334 bellard
{
951 c53be334 bellard
    GOTO_TB(op_goto_tb1, PARAM1, 1);
952 7a387fff ths
    RETURN();
953 c53be334 bellard
}
954 6af0bf9c bellard
955 6af0bf9c bellard
/* Branch to register */
956 6af0bf9c bellard
void op_save_breg_target (void)
957 6af0bf9c bellard
{
958 6af0bf9c bellard
    env->btarget = T2;
959 7a387fff ths
    RETURN();
960 6af0bf9c bellard
}
961 6af0bf9c bellard
962 6af0bf9c bellard
void op_restore_breg_target (void)
963 6af0bf9c bellard
{
964 6af0bf9c bellard
    T2 = env->btarget;
965 7a387fff ths
    RETURN();
966 6af0bf9c bellard
}
967 6af0bf9c bellard
968 6af0bf9c bellard
void op_breg (void)
969 6af0bf9c bellard
{
970 ead9360e ths
    env->PC[env->current_tc] = T2;
971 6af0bf9c bellard
    RETURN();
972 6af0bf9c bellard
}
973 6af0bf9c bellard
974 6af0bf9c bellard
void op_save_btarget (void)
975 6af0bf9c bellard
{
976 6af0bf9c bellard
    env->btarget = PARAM1;
977 6af0bf9c bellard
    RETURN();
978 6af0bf9c bellard
}
979 6af0bf9c bellard
980 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
981 9b9e4393 ths
void op_save_btarget64 (void)
982 9b9e4393 ths
{
983 9b9e4393 ths
    env->btarget = ((uint64_t)PARAM1 << 32) | (uint32_t)PARAM2;
984 9b9e4393 ths
    RETURN();
985 9b9e4393 ths
}
986 9b9e4393 ths
#endif
987 9b9e4393 ths
988 6af0bf9c bellard
/* Conditional branch */
989 6af0bf9c bellard
void op_set_bcond (void)
990 6af0bf9c bellard
{
991 6af0bf9c bellard
    T2 = T0;
992 6af0bf9c bellard
    RETURN();
993 6af0bf9c bellard
}
994 6af0bf9c bellard
995 6af0bf9c bellard
void op_save_bcond (void)
996 6af0bf9c bellard
{
997 6af0bf9c bellard
    env->bcond = T2;
998 6af0bf9c bellard
    RETURN();
999 6af0bf9c bellard
}
1000 6af0bf9c bellard
1001 6af0bf9c bellard
void op_restore_bcond (void)
1002 6af0bf9c bellard
{
1003 6af0bf9c bellard
    T2 = env->bcond;
1004 6af0bf9c bellard
    RETURN();
1005 6af0bf9c bellard
}
1006 6af0bf9c bellard
1007 c53be334 bellard
void op_jnz_T2 (void)
1008 6af0bf9c bellard
{
1009 c53be334 bellard
    if (T2)
1010 c53be334 bellard
        GOTO_LABEL_PARAM(1);
1011 6af0bf9c bellard
    RETURN();
1012 6af0bf9c bellard
}
1013 6af0bf9c bellard
1014 6af0bf9c bellard
/* CP0 functions */
1015 873eb012 ths
void op_mfc0_index (void)
1016 6af0bf9c bellard
{
1017 9c2149c8 ths
    T0 = env->CP0_Index;
1018 873eb012 ths
    RETURN();
1019 873eb012 ths
}
1020 873eb012 ths
1021 ead9360e ths
void op_mfc0_mvpcontrol (void)
1022 ead9360e ths
{
1023 ead9360e ths
    T0 = env->mvp->CP0_MVPControl;
1024 ead9360e ths
    RETURN();
1025 ead9360e ths
}
1026 ead9360e ths
1027 ead9360e ths
void op_mfc0_mvpconf0 (void)
1028 ead9360e ths
{
1029 ead9360e ths
    T0 = env->mvp->CP0_MVPConf0;
1030 ead9360e ths
    RETURN();
1031 ead9360e ths
}
1032 ead9360e ths
1033 ead9360e ths
void op_mfc0_mvpconf1 (void)
1034 ead9360e ths
{
1035 ead9360e ths
    T0 = env->mvp->CP0_MVPConf1;
1036 ead9360e ths
    RETURN();
1037 ead9360e ths
}
1038 ead9360e ths
1039 873eb012 ths
void op_mfc0_random (void)
1040 873eb012 ths
{
1041 873eb012 ths
    CALL_FROM_TB0(do_mfc0_random);
1042 873eb012 ths
    RETURN();
1043 873eb012 ths
}
1044 873eb012 ths
1045 ead9360e ths
void op_mfc0_vpecontrol (void)
1046 ead9360e ths
{
1047 ead9360e ths
    T0 = env->CP0_VPEControl;
1048 ead9360e ths
    RETURN();
1049 ead9360e ths
}
1050 ead9360e ths
1051 ead9360e ths
void op_mfc0_vpeconf0 (void)
1052 ead9360e ths
{
1053 ead9360e ths
    T0 = env->CP0_VPEConf0;
1054 ead9360e ths
    RETURN();
1055 ead9360e ths
}
1056 ead9360e ths
1057 ead9360e ths
void op_mfc0_vpeconf1 (void)
1058 ead9360e ths
{
1059 ead9360e ths
    T0 = env->CP0_VPEConf1;
1060 ead9360e ths
    RETURN();
1061 ead9360e ths
}
1062 ead9360e ths
1063 ead9360e ths
void op_mfc0_yqmask (void)
1064 ead9360e ths
{
1065 ead9360e ths
    T0 = env->CP0_YQMask;
1066 ead9360e ths
    RETURN();
1067 ead9360e ths
}
1068 ead9360e ths
1069 ead9360e ths
void op_mfc0_vpeschedule (void)
1070 ead9360e ths
{
1071 ead9360e ths
    T0 = env->CP0_VPESchedule;
1072 ead9360e ths
    RETURN();
1073 ead9360e ths
}
1074 ead9360e ths
1075 ead9360e ths
void op_mfc0_vpeschefback (void)
1076 ead9360e ths
{
1077 ead9360e ths
    T0 = env->CP0_VPEScheFBack;
1078 ead9360e ths
    RETURN();
1079 ead9360e ths
}
1080 ead9360e ths
1081 ead9360e ths
void op_mfc0_vpeopt (void)
1082 ead9360e ths
{
1083 ead9360e ths
    T0 = env->CP0_VPEOpt;
1084 ead9360e ths
    RETURN();
1085 ead9360e ths
}
1086 ead9360e ths
1087 873eb012 ths
void op_mfc0_entrylo0 (void)
1088 873eb012 ths
{
1089 9c2149c8 ths
    T0 = (int32_t)env->CP0_EntryLo0;
1090 873eb012 ths
    RETURN();
1091 873eb012 ths
}
1092 873eb012 ths
1093 ead9360e ths
void op_mfc0_tcstatus (void)
1094 ead9360e ths
{
1095 ead9360e ths
    T0 = env->CP0_TCStatus[env->current_tc];
1096 ead9360e ths
    RETURN();
1097 ead9360e ths
}
1098 ead9360e ths
1099 ead9360e ths
void op_mftc0_tcstatus(void)
1100 ead9360e ths
{
1101 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1102 ead9360e ths
1103 ead9360e ths
    T0 = env->CP0_TCStatus[other_tc];
1104 ead9360e ths
    RETURN();
1105 ead9360e ths
}
1106 ead9360e ths
1107 ead9360e ths
void op_mfc0_tcbind (void)
1108 ead9360e ths
{
1109 ead9360e ths
    T0 = env->CP0_TCBind[env->current_tc];
1110 ead9360e ths
    RETURN();
1111 ead9360e ths
}
1112 ead9360e ths
1113 ead9360e ths
void op_mftc0_tcbind(void)
1114 ead9360e ths
{
1115 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1116 ead9360e ths
1117 ead9360e ths
    T0 = env->CP0_TCBind[other_tc];
1118 ead9360e ths
    RETURN();
1119 ead9360e ths
}
1120 ead9360e ths
1121 ead9360e ths
void op_mfc0_tcrestart (void)
1122 ead9360e ths
{
1123 ead9360e ths
    T0 = env->PC[env->current_tc];
1124 ead9360e ths
    RETURN();
1125 ead9360e ths
}
1126 ead9360e ths
1127 ead9360e ths
void op_mftc0_tcrestart(void)
1128 ead9360e ths
{
1129 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1130 ead9360e ths
1131 ead9360e ths
    T0 = env->PC[other_tc];
1132 ead9360e ths
    RETURN();
1133 ead9360e ths
}
1134 ead9360e ths
1135 ead9360e ths
void op_mfc0_tchalt (void)
1136 ead9360e ths
{
1137 ead9360e ths
    T0 = env->CP0_TCHalt[env->current_tc];
1138 ead9360e ths
    RETURN();
1139 ead9360e ths
}
1140 ead9360e ths
1141 ead9360e ths
void op_mftc0_tchalt(void)
1142 ead9360e ths
{
1143 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1144 ead9360e ths
1145 ead9360e ths
    T0 = env->CP0_TCHalt[other_tc];
1146 ead9360e ths
    RETURN();
1147 ead9360e ths
}
1148 ead9360e ths
1149 ead9360e ths
void op_mfc0_tccontext (void)
1150 ead9360e ths
{
1151 ead9360e ths
    T0 = env->CP0_TCContext[env->current_tc];
1152 ead9360e ths
    RETURN();
1153 ead9360e ths
}
1154 ead9360e ths
1155 ead9360e ths
void op_mftc0_tccontext(void)
1156 ead9360e ths
{
1157 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1158 ead9360e ths
1159 ead9360e ths
    T0 = env->CP0_TCContext[other_tc];
1160 ead9360e ths
    RETURN();
1161 ead9360e ths
}
1162 ead9360e ths
1163 ead9360e ths
void op_mfc0_tcschedule (void)
1164 ead9360e ths
{
1165 ead9360e ths
    T0 = env->CP0_TCSchedule[env->current_tc];
1166 ead9360e ths
    RETURN();
1167 ead9360e ths
}
1168 ead9360e ths
1169 ead9360e ths
void op_mftc0_tcschedule(void)
1170 ead9360e ths
{
1171 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1172 ead9360e ths
1173 ead9360e ths
    T0 = env->CP0_TCSchedule[other_tc];
1174 ead9360e ths
    RETURN();
1175 ead9360e ths
}
1176 ead9360e ths
1177 ead9360e ths
void op_mfc0_tcschefback (void)
1178 ead9360e ths
{
1179 ead9360e ths
    T0 = env->CP0_TCScheFBack[env->current_tc];
1180 ead9360e ths
    RETURN();
1181 ead9360e ths
}
1182 ead9360e ths
1183 ead9360e ths
void op_mftc0_tcschefback(void)
1184 ead9360e ths
{
1185 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1186 ead9360e ths
1187 ead9360e ths
    T0 = env->CP0_TCScheFBack[other_tc];
1188 ead9360e ths
    RETURN();
1189 ead9360e ths
}
1190 ead9360e ths
1191 873eb012 ths
void op_mfc0_entrylo1 (void)
1192 873eb012 ths
{
1193 9c2149c8 ths
    T0 = (int32_t)env->CP0_EntryLo1;
1194 873eb012 ths
    RETURN();
1195 873eb012 ths
}
1196 873eb012 ths
1197 873eb012 ths
void op_mfc0_context (void)
1198 873eb012 ths
{
1199 9c2149c8 ths
    T0 = (int32_t)env->CP0_Context;
1200 873eb012 ths
    RETURN();
1201 873eb012 ths
}
1202 873eb012 ths
1203 873eb012 ths
void op_mfc0_pagemask (void)
1204 873eb012 ths
{
1205 9c2149c8 ths
    T0 = env->CP0_PageMask;
1206 873eb012 ths
    RETURN();
1207 873eb012 ths
}
1208 873eb012 ths
1209 7a387fff ths
void op_mfc0_pagegrain (void)
1210 7a387fff ths
{
1211 9c2149c8 ths
    T0 = env->CP0_PageGrain;
1212 7a387fff ths
    RETURN();
1213 7a387fff ths
}
1214 7a387fff ths
1215 873eb012 ths
void op_mfc0_wired (void)
1216 873eb012 ths
{
1217 9c2149c8 ths
    T0 = env->CP0_Wired;
1218 873eb012 ths
    RETURN();
1219 873eb012 ths
}
1220 873eb012 ths
1221 ead9360e ths
void op_mfc0_srsconf0 (void)
1222 ead9360e ths
{
1223 ead9360e ths
    T0 = env->CP0_SRSConf0;
1224 ead9360e ths
    RETURN();
1225 ead9360e ths
}
1226 ead9360e ths
1227 ead9360e ths
void op_mfc0_srsconf1 (void)
1228 ead9360e ths
{
1229 ead9360e ths
    T0 = env->CP0_SRSConf1;
1230 ead9360e ths
    RETURN();
1231 ead9360e ths
}
1232 ead9360e ths
1233 ead9360e ths
void op_mfc0_srsconf2 (void)
1234 ead9360e ths
{
1235 ead9360e ths
    T0 = env->CP0_SRSConf2;
1236 ead9360e ths
    RETURN();
1237 ead9360e ths
}
1238 ead9360e ths
1239 ead9360e ths
void op_mfc0_srsconf3 (void)
1240 ead9360e ths
{
1241 ead9360e ths
    T0 = env->CP0_SRSConf3;
1242 ead9360e ths
    RETURN();
1243 ead9360e ths
}
1244 ead9360e ths
1245 ead9360e ths
void op_mfc0_srsconf4 (void)
1246 ead9360e ths
{
1247 ead9360e ths
    T0 = env->CP0_SRSConf4;
1248 ead9360e ths
    RETURN();
1249 ead9360e ths
}
1250 ead9360e ths
1251 7a387fff ths
void op_mfc0_hwrena (void)
1252 7a387fff ths
{
1253 9c2149c8 ths
    T0 = env->CP0_HWREna;
1254 7a387fff ths
    RETURN();
1255 7a387fff ths
}
1256 7a387fff ths
1257 873eb012 ths
void op_mfc0_badvaddr (void)
1258 873eb012 ths
{
1259 9c2149c8 ths
    T0 = (int32_t)env->CP0_BadVAddr;
1260 873eb012 ths
    RETURN();
1261 873eb012 ths
}
1262 873eb012 ths
1263 873eb012 ths
void op_mfc0_count (void)
1264 873eb012 ths
{
1265 873eb012 ths
    CALL_FROM_TB0(do_mfc0_count);
1266 873eb012 ths
    RETURN();
1267 873eb012 ths
}
1268 873eb012 ths
1269 873eb012 ths
void op_mfc0_entryhi (void)
1270 873eb012 ths
{
1271 9c2149c8 ths
    T0 = (int32_t)env->CP0_EntryHi;
1272 873eb012 ths
    RETURN();
1273 873eb012 ths
}
1274 873eb012 ths
1275 ead9360e ths
void op_mftc0_entryhi(void)
1276 ead9360e ths
{
1277 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1278 ead9360e ths
1279 ead9360e ths
    T0 = (env->CP0_EntryHi & ~0xff) | (env->CP0_TCStatus[other_tc] & 0xff);
1280 ead9360e ths
    RETURN();
1281 ead9360e ths
}
1282 ead9360e ths
1283 873eb012 ths
void op_mfc0_compare (void)
1284 873eb012 ths
{
1285 9c2149c8 ths
    T0 = env->CP0_Compare;
1286 873eb012 ths
    RETURN();
1287 873eb012 ths
}
1288 873eb012 ths
1289 873eb012 ths
void op_mfc0_status (void)
1290 873eb012 ths
{
1291 9c2149c8 ths
    T0 = env->CP0_Status;
1292 873eb012 ths
    RETURN();
1293 873eb012 ths
}
1294 873eb012 ths
1295 ead9360e ths
void op_mftc0_status(void)
1296 ead9360e ths
{
1297 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1298 ead9360e ths
    uint32_t tcstatus = env->CP0_TCStatus[other_tc];
1299 ead9360e ths
1300 ead9360e ths
    T0 = env->CP0_Status & ~0xf1000018;
1301 ead9360e ths
    T0 |= tcstatus & (0xf << CP0TCSt_TCU0);
1302 ead9360e ths
    T0 |= (tcstatus & (1 << CP0TCSt_TMX)) >> (CP0TCSt_TMX - CP0St_MX);
1303 ead9360e ths
    T0 |= (tcstatus & (0x3 << CP0TCSt_TKSU)) >> (CP0TCSt_TKSU - CP0St_R0);
1304 ead9360e ths
    RETURN();
1305 ead9360e ths
}
1306 ead9360e ths
1307 7a387fff ths
void op_mfc0_intctl (void)
1308 7a387fff ths
{
1309 9c2149c8 ths
    T0 = env->CP0_IntCtl;
1310 7a387fff ths
    RETURN();
1311 7a387fff ths
}
1312 7a387fff ths
1313 7a387fff ths
void op_mfc0_srsctl (void)
1314 7a387fff ths
{
1315 9c2149c8 ths
    T0 = env->CP0_SRSCtl;
1316 9c2149c8 ths
    RETURN();
1317 9c2149c8 ths
}
1318 9c2149c8 ths
1319 9c2149c8 ths
void op_mfc0_srsmap (void)
1320 9c2149c8 ths
{
1321 9c2149c8 ths
    T0 = env->CP0_SRSMap;
1322 7a387fff ths
    RETURN();
1323 7a387fff ths
}
1324 7a387fff ths
1325 873eb012 ths
void op_mfc0_cause (void)
1326 873eb012 ths
{
1327 9c2149c8 ths
    T0 = env->CP0_Cause;
1328 873eb012 ths
    RETURN();
1329 873eb012 ths
}
1330 873eb012 ths
1331 873eb012 ths
void op_mfc0_epc (void)
1332 873eb012 ths
{
1333 9c2149c8 ths
    T0 = (int32_t)env->CP0_EPC;
1334 873eb012 ths
    RETURN();
1335 873eb012 ths
}
1336 873eb012 ths
1337 873eb012 ths
void op_mfc0_prid (void)
1338 873eb012 ths
{
1339 9c2149c8 ths
    T0 = env->CP0_PRid;
1340 873eb012 ths
    RETURN();
1341 873eb012 ths
}
1342 873eb012 ths
1343 7a387fff ths
void op_mfc0_ebase (void)
1344 7a387fff ths
{
1345 b29a0341 ths
    T0 = env->CP0_EBase;
1346 7a387fff ths
    RETURN();
1347 7a387fff ths
}
1348 7a387fff ths
1349 873eb012 ths
void op_mfc0_config0 (void)
1350 873eb012 ths
{
1351 9c2149c8 ths
    T0 = env->CP0_Config0;
1352 873eb012 ths
    RETURN();
1353 873eb012 ths
}
1354 873eb012 ths
1355 873eb012 ths
void op_mfc0_config1 (void)
1356 873eb012 ths
{
1357 9c2149c8 ths
    T0 = env->CP0_Config1;
1358 873eb012 ths
    RETURN();
1359 873eb012 ths
}
1360 873eb012 ths
1361 7a387fff ths
void op_mfc0_config2 (void)
1362 7a387fff ths
{
1363 9c2149c8 ths
    T0 = env->CP0_Config2;
1364 7a387fff ths
    RETURN();
1365 7a387fff ths
}
1366 7a387fff ths
1367 7a387fff ths
void op_mfc0_config3 (void)
1368 7a387fff ths
{
1369 9c2149c8 ths
    T0 = env->CP0_Config3;
1370 7a387fff ths
    RETURN();
1371 7a387fff ths
}
1372 7a387fff ths
1373 e397ee33 ths
void op_mfc0_config6 (void)
1374 e397ee33 ths
{
1375 e397ee33 ths
    T0 = env->CP0_Config6;
1376 e397ee33 ths
    RETURN();
1377 e397ee33 ths
}
1378 e397ee33 ths
1379 e397ee33 ths
void op_mfc0_config7 (void)
1380 e397ee33 ths
{
1381 e397ee33 ths
    T0 = env->CP0_Config7;
1382 e397ee33 ths
    RETURN();
1383 e397ee33 ths
}
1384 e397ee33 ths
1385 873eb012 ths
void op_mfc0_lladdr (void)
1386 873eb012 ths
{
1387 9c2149c8 ths
    T0 = (int32_t)env->CP0_LLAddr >> 4;
1388 873eb012 ths
    RETURN();
1389 873eb012 ths
}
1390 873eb012 ths
1391 fd88b6ab ths
void op_mfc0_watchlo (void)
1392 873eb012 ths
{
1393 fd88b6ab ths
    T0 = (int32_t)env->CP0_WatchLo[PARAM1];
1394 873eb012 ths
    RETURN();
1395 873eb012 ths
}
1396 873eb012 ths
1397 fd88b6ab ths
void op_mfc0_watchhi (void)
1398 873eb012 ths
{
1399 fd88b6ab ths
    T0 = env->CP0_WatchHi[PARAM1];
1400 873eb012 ths
    RETURN();
1401 873eb012 ths
}
1402 873eb012 ths
1403 7a387fff ths
void op_mfc0_xcontext (void)
1404 7a387fff ths
{
1405 9c2149c8 ths
    T0 = (int32_t)env->CP0_XContext;
1406 7a387fff ths
    RETURN();
1407 7a387fff ths
}
1408 7a387fff ths
1409 7a387fff ths
void op_mfc0_framemask (void)
1410 7a387fff ths
{
1411 7a387fff ths
    T0 = env->CP0_Framemask;
1412 7a387fff ths
    RETURN();
1413 7a387fff ths
}
1414 7a387fff ths
1415 873eb012 ths
void op_mfc0_debug (void)
1416 873eb012 ths
{
1417 9c2149c8 ths
    T0 = env->CP0_Debug;
1418 873eb012 ths
    if (env->hflags & MIPS_HFLAG_DM)
1419 873eb012 ths
        T0 |= 1 << CP0DB_DM;
1420 873eb012 ths
    RETURN();
1421 873eb012 ths
}
1422 873eb012 ths
1423 ead9360e ths
void op_mftc0_debug(void)
1424 ead9360e ths
{
1425 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1426 ead9360e ths
1427 ead9360e ths
    /* XXX: Might be wrong, check with EJTAG spec. */
1428 ead9360e ths
    T0 = (env->CP0_Debug & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
1429 ead9360e ths
         (env->CP0_Debug_tcstatus[other_tc] &
1430 ead9360e ths
          ((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
1431 ead9360e ths
    RETURN();
1432 ead9360e ths
}
1433 ead9360e ths
1434 873eb012 ths
void op_mfc0_depc (void)
1435 873eb012 ths
{
1436 9c2149c8 ths
    T0 = (int32_t)env->CP0_DEPC;
1437 873eb012 ths
    RETURN();
1438 873eb012 ths
}
1439 873eb012 ths
1440 7a387fff ths
void op_mfc0_performance0 (void)
1441 7a387fff ths
{
1442 9c2149c8 ths
    T0 = env->CP0_Performance0;
1443 7a387fff ths
    RETURN();
1444 7a387fff ths
}
1445 7a387fff ths
1446 873eb012 ths
void op_mfc0_taglo (void)
1447 873eb012 ths
{
1448 9c2149c8 ths
    T0 = env->CP0_TagLo;
1449 873eb012 ths
    RETURN();
1450 873eb012 ths
}
1451 873eb012 ths
1452 873eb012 ths
void op_mfc0_datalo (void)
1453 873eb012 ths
{
1454 9c2149c8 ths
    T0 = env->CP0_DataLo;
1455 873eb012 ths
    RETURN();
1456 873eb012 ths
}
1457 873eb012 ths
1458 7a387fff ths
void op_mfc0_taghi (void)
1459 7a387fff ths
{
1460 9c2149c8 ths
    T0 = env->CP0_TagHi;
1461 7a387fff ths
    RETURN();
1462 7a387fff ths
}
1463 7a387fff ths
1464 7a387fff ths
void op_mfc0_datahi (void)
1465 7a387fff ths
{
1466 9c2149c8 ths
    T0 = env->CP0_DataHi;
1467 7a387fff ths
    RETURN();
1468 7a387fff ths
}
1469 7a387fff ths
1470 873eb012 ths
void op_mfc0_errorepc (void)
1471 873eb012 ths
{
1472 9c2149c8 ths
    T0 = (int32_t)env->CP0_ErrorEPC;
1473 873eb012 ths
    RETURN();
1474 873eb012 ths
}
1475 873eb012 ths
1476 873eb012 ths
void op_mfc0_desave (void)
1477 873eb012 ths
{
1478 9c2149c8 ths
    T0 = env->CP0_DESAVE;
1479 6af0bf9c bellard
    RETURN();
1480 6af0bf9c bellard
}
1481 6af0bf9c bellard
1482 8c0fdd85 ths
void op_mtc0_index (void)
1483 6af0bf9c bellard
{
1484 ead9360e ths
    env->CP0_Index = (env->CP0_Index & 0x80000000) | (T0 % env->tlb->nb_tlb);
1485 ead9360e ths
    RETURN();
1486 ead9360e ths
}
1487 ead9360e ths
1488 ead9360e ths
void op_mtc0_mvpcontrol (void)
1489 ead9360e ths
{
1490 ead9360e ths
    uint32_t mask = 0;
1491 ead9360e ths
    uint32_t newval;
1492 ead9360e ths
1493 ead9360e ths
    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))
1494 ead9360e ths
        mask |= (1 << CP0MVPCo_CPA) | (1 << CP0MVPCo_VPC) |
1495 ead9360e ths
                (1 << CP0MVPCo_EVP);
1496 ead9360e ths
    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1497 ead9360e ths
        mask |= (1 << CP0MVPCo_STLB);
1498 ead9360e ths
    newval = (env->mvp->CP0_MVPControl & ~mask) | (T0 & mask);
1499 ead9360e ths
1500 ead9360e ths
    // TODO: Enable/disable shared TLB, enable/disable VPEs.
1501 ead9360e ths
1502 ead9360e ths
    env->mvp->CP0_MVPControl = newval;
1503 ead9360e ths
    RETURN();
1504 ead9360e ths
}
1505 ead9360e ths
1506 ead9360e ths
void op_mtc0_vpecontrol (void)
1507 ead9360e ths
{
1508 ead9360e ths
    uint32_t mask;
1509 ead9360e ths
    uint32_t newval;
1510 ead9360e ths
1511 ead9360e ths
    mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
1512 ead9360e ths
           (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
1513 ead9360e ths
    newval = (env->CP0_VPEControl & ~mask) | (T0 & mask);
1514 ead9360e ths
1515 ead9360e ths
    /* Yield scheduler intercept not implemented. */
1516 ead9360e ths
    /* Gating storage scheduler intercept not implemented. */
1517 ead9360e ths
1518 ead9360e ths
    // TODO: Enable/disable TCs.
1519 ead9360e ths
1520 ead9360e ths
    env->CP0_VPEControl = newval;
1521 ead9360e ths
    RETURN();
1522 ead9360e ths
}
1523 ead9360e ths
1524 ead9360e ths
void op_mtc0_vpeconf0 (void)
1525 ead9360e ths
{
1526 ead9360e ths
    uint32_t mask = 0;
1527 ead9360e ths
    uint32_t newval;
1528 ead9360e ths
1529 ead9360e ths
    if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
1530 ead9360e ths
        if (env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))
1531 ead9360e ths
            mask |= (0xff << CP0VPEC0_XTC);
1532 ead9360e ths
        mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
1533 ead9360e ths
    }
1534 ead9360e ths
    newval = (env->CP0_VPEConf0 & ~mask) | (T0 & mask);
1535 ead9360e ths
1536 ead9360e ths
    // TODO: TC exclusive handling due to ERL/EXL.
1537 ead9360e ths
1538 ead9360e ths
    env->CP0_VPEConf0 = newval;
1539 ead9360e ths
    RETURN();
1540 ead9360e ths
}
1541 ead9360e ths
1542 ead9360e ths
void op_mtc0_vpeconf1 (void)
1543 ead9360e ths
{
1544 ead9360e ths
    uint32_t mask = 0;
1545 ead9360e ths
    uint32_t newval;
1546 ead9360e ths
1547 ead9360e ths
    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1548 ead9360e ths
        mask |= (0xff << CP0VPEC1_NCX) | (0xff << CP0VPEC1_NCP2) |
1549 ead9360e ths
                (0xff << CP0VPEC1_NCP1);
1550 ead9360e ths
    newval = (env->CP0_VPEConf1 & ~mask) | (T0 & mask);
1551 ead9360e ths
1552 ead9360e ths
    /* UDI not implemented. */
1553 ead9360e ths
    /* CP2 not implemented. */
1554 ead9360e ths
1555 ead9360e ths
    // TODO: Handle FPU (CP1) binding.
1556 ead9360e ths
1557 ead9360e ths
    env->CP0_VPEConf1 = newval;
1558 ead9360e ths
    RETURN();
1559 ead9360e ths
}
1560 ead9360e ths
1561 ead9360e ths
void op_mtc0_yqmask (void)
1562 ead9360e ths
{
1563 ead9360e ths
    /* Yield qualifier inputs not implemented. */
1564 ead9360e ths
    env->CP0_YQMask = 0x00000000;
1565 ead9360e ths
    RETURN();
1566 ead9360e ths
}
1567 ead9360e ths
1568 ead9360e ths
void op_mtc0_vpeschedule (void)
1569 ead9360e ths
{
1570 ead9360e ths
    env->CP0_VPESchedule = T0;
1571 ead9360e ths
    RETURN();
1572 ead9360e ths
}
1573 ead9360e ths
1574 ead9360e ths
void op_mtc0_vpeschefback (void)
1575 ead9360e ths
{
1576 ead9360e ths
    env->CP0_VPEScheFBack = T0;
1577 ead9360e ths
    RETURN();
1578 ead9360e ths
}
1579 ead9360e ths
1580 ead9360e ths
void op_mtc0_vpeopt (void)
1581 ead9360e ths
{
1582 ead9360e ths
    env->CP0_VPEOpt = T0 & 0x0000ffff;
1583 8c0fdd85 ths
    RETURN();
1584 8c0fdd85 ths
}
1585 8c0fdd85 ths
1586 8c0fdd85 ths
void op_mtc0_entrylo0 (void)
1587 8c0fdd85 ths
{
1588 7a387fff ths
    /* Large physaddr not implemented */
1589 7a387fff ths
    /* 1k pages not implemented */
1590 f1b0aa5d ths
    env->CP0_EntryLo0 = T0 & 0x3FFFFFFF;
1591 8c0fdd85 ths
    RETURN();
1592 8c0fdd85 ths
}
1593 8c0fdd85 ths
1594 ead9360e ths
void op_mtc0_tcstatus (void)
1595 ead9360e ths
{
1596 ead9360e ths
    uint32_t mask = env->CP0_TCStatus_rw_bitmask;
1597 ead9360e ths
    uint32_t newval;
1598 ead9360e ths
1599 ead9360e ths
    newval = (env->CP0_TCStatus[env->current_tc] & ~mask) | (T0 & mask);
1600 ead9360e ths
1601 ead9360e ths
    // TODO: Sync with CP0_Status.
1602 ead9360e ths
1603 ead9360e ths
    env->CP0_TCStatus[env->current_tc] = newval;
1604 ead9360e ths
    RETURN();
1605 ead9360e ths
}
1606 ead9360e ths
1607 ead9360e ths
void op_mttc0_tcstatus (void)
1608 ead9360e ths
{
1609 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1610 ead9360e ths
1611 ead9360e ths
    // TODO: Sync with CP0_Status.
1612 ead9360e ths
1613 ead9360e ths
    env->CP0_TCStatus[other_tc] = T0;
1614 ead9360e ths
    RETURN();
1615 ead9360e ths
}
1616 ead9360e ths
1617 ead9360e ths
void op_mtc0_tcbind (void)
1618 ead9360e ths
{
1619 ead9360e ths
    uint32_t mask = (1 << CP0TCBd_TBE);
1620 ead9360e ths
    uint32_t newval;
1621 ead9360e ths
1622 ead9360e ths
    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1623 ead9360e ths
        mask |= (1 << CP0TCBd_CurVPE);
1624 ead9360e ths
    newval = (env->CP0_TCBind[env->current_tc] & ~mask) | (T0 & mask);
1625 ead9360e ths
    env->CP0_TCBind[env->current_tc] = newval;
1626 ead9360e ths
    RETURN();
1627 ead9360e ths
}
1628 ead9360e ths
1629 ead9360e ths
void op_mttc0_tcbind (void)
1630 ead9360e ths
{
1631 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1632 ead9360e ths
    uint32_t mask = (1 << CP0TCBd_TBE);
1633 ead9360e ths
    uint32_t newval;
1634 ead9360e ths
1635 ead9360e ths
    if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
1636 ead9360e ths
        mask |= (1 << CP0TCBd_CurVPE);
1637 ead9360e ths
    newval = (env->CP0_TCBind[other_tc] & ~mask) | (T0 & mask);
1638 ead9360e ths
    env->CP0_TCBind[other_tc] = newval;
1639 ead9360e ths
    RETURN();
1640 ead9360e ths
}
1641 ead9360e ths
1642 ead9360e ths
void op_mtc0_tcrestart (void)
1643 ead9360e ths
{
1644 ead9360e ths
    env->PC[env->current_tc] = T0;
1645 ead9360e ths
    env->CP0_TCStatus[env->current_tc] &= ~(1 << CP0TCSt_TDS);
1646 ead9360e ths
    env->CP0_LLAddr = 0ULL;
1647 ead9360e ths
    /* MIPS16 not implemented. */
1648 ead9360e ths
    RETURN();
1649 ead9360e ths
}
1650 ead9360e ths
1651 ead9360e ths
void op_mttc0_tcrestart (void)
1652 ead9360e ths
{
1653 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1654 ead9360e ths
1655 ead9360e ths
    env->PC[other_tc] = T0;
1656 ead9360e ths
    env->CP0_TCStatus[other_tc] &= ~(1 << CP0TCSt_TDS);
1657 ead9360e ths
    env->CP0_LLAddr = 0ULL;
1658 ead9360e ths
    /* MIPS16 not implemented. */
1659 ead9360e ths
    RETURN();
1660 ead9360e ths
}
1661 ead9360e ths
1662 ead9360e ths
void op_mtc0_tchalt (void)
1663 ead9360e ths
{
1664 ead9360e ths
    env->CP0_TCHalt[env->current_tc] = T0 & 0x1;
1665 ead9360e ths
1666 ead9360e ths
    // TODO: Halt TC / Restart (if allocated+active) TC.
1667 ead9360e ths
1668 ead9360e ths
    RETURN();
1669 ead9360e ths
}
1670 ead9360e ths
1671 ead9360e ths
void op_mttc0_tchalt (void)
1672 ead9360e ths
{
1673 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1674 ead9360e ths
1675 ead9360e ths
    // TODO: Halt TC / Restart (if allocated+active) TC.
1676 ead9360e ths
1677 ead9360e ths
    env->CP0_TCHalt[other_tc] = T0;
1678 ead9360e ths
    RETURN();
1679 ead9360e ths
}
1680 ead9360e ths
1681 ead9360e ths
void op_mtc0_tccontext (void)
1682 ead9360e ths
{
1683 ead9360e ths
    env->CP0_TCContext[env->current_tc] = T0;
1684 ead9360e ths
    RETURN();
1685 ead9360e ths
}
1686 ead9360e ths
1687 ead9360e ths
void op_mttc0_tccontext (void)
1688 ead9360e ths
{
1689 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1690 ead9360e ths
1691 ead9360e ths
    env->CP0_TCContext[other_tc] = T0;
1692 ead9360e ths
    RETURN();
1693 ead9360e ths
}
1694 ead9360e ths
1695 ead9360e ths
void op_mtc0_tcschedule (void)
1696 ead9360e ths
{
1697 ead9360e ths
    env->CP0_TCSchedule[env->current_tc] = T0;
1698 ead9360e ths
    RETURN();
1699 ead9360e ths
}
1700 ead9360e ths
1701 ead9360e ths
void op_mttc0_tcschedule (void)
1702 ead9360e ths
{
1703 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1704 ead9360e ths
1705 ead9360e ths
    env->CP0_TCSchedule[other_tc] = T0;
1706 ead9360e ths
    RETURN();
1707 ead9360e ths
}
1708 ead9360e ths
1709 ead9360e ths
void op_mtc0_tcschefback (void)
1710 ead9360e ths
{
1711 ead9360e ths
    env->CP0_TCScheFBack[env->current_tc] = T0;
1712 ead9360e ths
    RETURN();
1713 ead9360e ths
}
1714 ead9360e ths
1715 ead9360e ths
void op_mttc0_tcschefback (void)
1716 ead9360e ths
{
1717 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1718 ead9360e ths
1719 ead9360e ths
    env->CP0_TCScheFBack[other_tc] = T0;
1720 ead9360e ths
    RETURN();
1721 ead9360e ths
}
1722 ead9360e ths
1723 8c0fdd85 ths
void op_mtc0_entrylo1 (void)
1724 8c0fdd85 ths
{
1725 7a387fff ths
    /* Large physaddr not implemented */
1726 7a387fff ths
    /* 1k pages not implemented */
1727 f1b0aa5d ths
    env->CP0_EntryLo1 = T0 & 0x3FFFFFFF;
1728 8c0fdd85 ths
    RETURN();
1729 8c0fdd85 ths
}
1730 8c0fdd85 ths
1731 8c0fdd85 ths
void op_mtc0_context (void)
1732 8c0fdd85 ths
{
1733 534ce69f ths
    env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (T0 & ~0x007FFFFF);
1734 8c0fdd85 ths
    RETURN();
1735 8c0fdd85 ths
}
1736 8c0fdd85 ths
1737 8c0fdd85 ths
void op_mtc0_pagemask (void)
1738 8c0fdd85 ths
{
1739 7a387fff ths
    /* 1k pages not implemented */
1740 f2e9ebef ths
    env->CP0_PageMask = T0 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
1741 7a387fff ths
    RETURN();
1742 7a387fff ths
}
1743 7a387fff ths
1744 7a387fff ths
void op_mtc0_pagegrain (void)
1745 7a387fff ths
{
1746 7a387fff ths
    /* SmartMIPS not implemented */
1747 7a387fff ths
    /* Large physaddr not implemented */
1748 7a387fff ths
    /* 1k pages not implemented */
1749 7a387fff ths
    env->CP0_PageGrain = 0;
1750 8c0fdd85 ths
    RETURN();
1751 8c0fdd85 ths
}
1752 8c0fdd85 ths
1753 8c0fdd85 ths
void op_mtc0_wired (void)
1754 8c0fdd85 ths
{
1755 ead9360e ths
    env->CP0_Wired = T0 % env->tlb->nb_tlb;
1756 ead9360e ths
    RETURN();
1757 ead9360e ths
}
1758 ead9360e ths
1759 ead9360e ths
void op_mtc0_srsconf0 (void)
1760 ead9360e ths
{
1761 ead9360e ths
    env->CP0_SRSConf0 |= T0 & env->CP0_SRSConf0_rw_bitmask;
1762 ead9360e ths
    RETURN();
1763 ead9360e ths
}
1764 ead9360e ths
1765 ead9360e ths
void op_mtc0_srsconf1 (void)
1766 ead9360e ths
{
1767 ead9360e ths
    env->CP0_SRSConf1 |= T0 & env->CP0_SRSConf1_rw_bitmask;
1768 ead9360e ths
    RETURN();
1769 ead9360e ths
}
1770 ead9360e ths
1771 ead9360e ths
void op_mtc0_srsconf2 (void)
1772 ead9360e ths
{
1773 ead9360e ths
    env->CP0_SRSConf2 |= T0 & env->CP0_SRSConf2_rw_bitmask;
1774 ead9360e ths
    RETURN();
1775 ead9360e ths
}
1776 ead9360e ths
1777 ead9360e ths
void op_mtc0_srsconf3 (void)
1778 ead9360e ths
{
1779 ead9360e ths
    env->CP0_SRSConf3 |= T0 & env->CP0_SRSConf3_rw_bitmask;
1780 ead9360e ths
    RETURN();
1781 ead9360e ths
}
1782 ead9360e ths
1783 ead9360e ths
void op_mtc0_srsconf4 (void)
1784 ead9360e ths
{
1785 ead9360e ths
    env->CP0_SRSConf4 |= T0 & env->CP0_SRSConf4_rw_bitmask;
1786 7a387fff ths
    RETURN();
1787 7a387fff ths
}
1788 7a387fff ths
1789 7a387fff ths
void op_mtc0_hwrena (void)
1790 7a387fff ths
{
1791 7a387fff ths
    env->CP0_HWREna = T0 & 0x0000000F;
1792 8c0fdd85 ths
    RETURN();
1793 8c0fdd85 ths
}
1794 8c0fdd85 ths
1795 8c0fdd85 ths
void op_mtc0_count (void)
1796 8c0fdd85 ths
{
1797 8c0fdd85 ths
    CALL_FROM_TB2(cpu_mips_store_count, env, T0);
1798 8c0fdd85 ths
    RETURN();
1799 8c0fdd85 ths
}
1800 8c0fdd85 ths
1801 8c0fdd85 ths
void op_mtc0_entryhi (void)
1802 8c0fdd85 ths
{
1803 0feef828 ths
    target_ulong old, val;
1804 8c0fdd85 ths
1805 7a387fff ths
    /* 1k pages not implemented */
1806 100ce988 ths
    val = T0 & ((TARGET_PAGE_MASK << 1) | 0xFF);
1807 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
1808 e034e2c3 ths
    val &= env->SEGMask;
1809 100ce988 ths
#endif
1810 8c0fdd85 ths
    old = env->CP0_EntryHi;
1811 8c0fdd85 ths
    env->CP0_EntryHi = val;
1812 ead9360e ths
    if (env->CP0_Config3 & (1 << CP0C3_MT)) {
1813 ead9360e ths
        uint32_t tcst = env->CP0_TCStatus[env->current_tc] & ~0xff;
1814 ead9360e ths
        env->CP0_TCStatus[env->current_tc] = tcst | (val & 0xff);
1815 ead9360e ths
    }
1816 8c0fdd85 ths
    /* If the ASID changes, flush qemu's TLB.  */
1817 8c0fdd85 ths
    if ((old & 0xFF) != (val & 0xFF))
1818 8c0fdd85 ths
        CALL_FROM_TB2(cpu_mips_tlb_flush, env, 1);
1819 8c0fdd85 ths
    RETURN();
1820 8c0fdd85 ths
}
1821 8c0fdd85 ths
1822 ead9360e ths
void op_mttc0_entryhi(void)
1823 ead9360e ths
{
1824 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1825 ead9360e ths
1826 ead9360e ths
    env->CP0_EntryHi = (env->CP0_EntryHi & 0xff) | (T0 & ~0xff);
1827 ead9360e ths
    env->CP0_TCStatus[other_tc] = (env->CP0_TCStatus[other_tc] & ~0xff) | (T0 & 0xff);
1828 ead9360e ths
    RETURN();
1829 ead9360e ths
}
1830 ead9360e ths
1831 8c0fdd85 ths
void op_mtc0_compare (void)
1832 8c0fdd85 ths
{
1833 8c0fdd85 ths
    CALL_FROM_TB2(cpu_mips_store_compare, env, T0);
1834 8c0fdd85 ths
    RETURN();
1835 8c0fdd85 ths
}
1836 8c0fdd85 ths
1837 8c0fdd85 ths
void op_mtc0_status (void)
1838 8c0fdd85 ths
{
1839 4de9b249 ths
    uint32_t val, old;
1840 ead9360e ths
    uint32_t mask = env->CP0_Status_rw_bitmask;
1841 8c0fdd85 ths
1842 f1b0aa5d ths
    val = T0 & mask;
1843 8c0fdd85 ths
    old = env->CP0_Status;
1844 5a5012ec ths
    env->CP0_Status = (env->CP0_Status & ~mask) | val;
1845 08fa4bab ths
    CALL_FROM_TB1(compute_hflags, env);
1846 f41c52f1 ths
    if (loglevel & CPU_LOG_EXEC)
1847 f41c52f1 ths
        CALL_FROM_TB2(do_mtc0_status_debug, old, val);
1848 4de9b249 ths
    CALL_FROM_TB1(cpu_mips_update_irq, env);
1849 8c0fdd85 ths
    RETURN();
1850 8c0fdd85 ths
}
1851 8c0fdd85 ths
1852 ead9360e ths
void op_mttc0_status(void)
1853 ead9360e ths
{
1854 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1855 ead9360e ths
    uint32_t tcstatus = env->CP0_TCStatus[other_tc];
1856 ead9360e ths
1857 ead9360e ths
    env->CP0_Status = T0 & ~0xf1000018;
1858 ead9360e ths
    tcstatus = (tcstatus & ~(0xf << CP0TCSt_TCU0)) | (T0 & (0xf << CP0St_CU0));
1859 ead9360e ths
    tcstatus = (tcstatus & ~(1 << CP0TCSt_TMX)) | ((T0 & (1 << CP0St_MX)) << (CP0TCSt_TMX - CP0St_MX));
1860 ead9360e ths
    tcstatus = (tcstatus & ~(0x3 << CP0TCSt_TKSU)) | ((T0 & (0x3 << CP0St_R0)) << (CP0TCSt_TKSU - CP0St_R0));
1861 ead9360e ths
    env->CP0_TCStatus[other_tc] = tcstatus;
1862 ead9360e ths
    RETURN();
1863 ead9360e ths
}
1864 ead9360e ths
1865 7a387fff ths
void op_mtc0_intctl (void)
1866 7a387fff ths
{
1867 42532189 ths
    /* vectored interrupts not implemented, no performance counters. */
1868 42532189 ths
    env->CP0_IntCtl = (env->CP0_IntCtl & ~0x000002e0) | (T0 & 0x000002e0);
1869 7a387fff ths
    RETURN();
1870 7a387fff ths
}
1871 7a387fff ths
1872 7a387fff ths
void op_mtc0_srsctl (void)
1873 7a387fff ths
{
1874 ead9360e ths
    uint32_t mask = (0xf << CP0SRSCtl_ESS) | (0xf << CP0SRSCtl_PSS);
1875 ead9360e ths
    env->CP0_SRSCtl = (env->CP0_SRSCtl & ~mask) | (T0 & mask);
1876 7a387fff ths
    RETURN();
1877 7a387fff ths
}
1878 7a387fff ths
1879 9c2149c8 ths
void op_mtc0_srsmap (void)
1880 9c2149c8 ths
{
1881 ead9360e ths
    env->CP0_SRSMap = T0;
1882 9c2149c8 ths
    RETURN();
1883 9c2149c8 ths
}
1884 9c2149c8 ths
1885 8c0fdd85 ths
void op_mtc0_cause (void)
1886 8c0fdd85 ths
{
1887 39d51eb8 ths
    uint32_t mask = 0x00C00300;
1888 42532189 ths
    uint32_t old = env->CP0_Cause;
1889 39d51eb8 ths
1890 e189e748 ths
    if (env->insn_flags & ISA_MIPS32R2)
1891 39d51eb8 ths
        mask |= 1 << CP0Ca_DC;
1892 39d51eb8 ths
1893 e58c8ba5 ths
    env->CP0_Cause = (env->CP0_Cause & ~mask) | (T0 & mask);
1894 8c0fdd85 ths
1895 42532189 ths
    if ((old ^ env->CP0_Cause) & (1 << CP0Ca_DC)) {
1896 42532189 ths
        if (env->CP0_Cause & (1 << CP0Ca_DC))
1897 42532189 ths
            CALL_FROM_TB1(cpu_mips_stop_count, env);
1898 42532189 ths
        else
1899 42532189 ths
            CALL_FROM_TB1(cpu_mips_start_count, env);
1900 42532189 ths
    }
1901 42532189 ths
1902 4de9b249 ths
    /* Handle the software interrupt as an hardware one, as they
1903 4de9b249 ths
       are very similar */
1904 4de9b249 ths
    if (T0 & CP0Ca_IP_mask) {
1905 4de9b249 ths
        CALL_FROM_TB1(cpu_mips_update_irq, env);
1906 8c0fdd85 ths
    }
1907 8c0fdd85 ths
    RETURN();
1908 8c0fdd85 ths
}
1909 8c0fdd85 ths
1910 8c0fdd85 ths
void op_mtc0_epc (void)
1911 8c0fdd85 ths
{
1912 f1b0aa5d ths
    env->CP0_EPC = T0;
1913 8c0fdd85 ths
    RETURN();
1914 8c0fdd85 ths
}
1915 8c0fdd85 ths
1916 7a387fff ths
void op_mtc0_ebase (void)
1917 7a387fff ths
{
1918 7a387fff ths
    /* vectored interrupts not implemented */
1919 7a387fff ths
    /* Multi-CPU not implemented */
1920 b29a0341 ths
    env->CP0_EBase = 0x80000000 | (T0 & 0x3FFFF000);
1921 7a387fff ths
    RETURN();
1922 7a387fff ths
}
1923 7a387fff ths
1924 8c0fdd85 ths
void op_mtc0_config0 (void)
1925 8c0fdd85 ths
{
1926 7bfd934a ths
    env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (T0 & 0x00000007);
1927 8c0fdd85 ths
    RETURN();
1928 8c0fdd85 ths
}
1929 8c0fdd85 ths
1930 7a387fff ths
void op_mtc0_config2 (void)
1931 7a387fff ths
{
1932 7a387fff ths
    /* tertiary/secondary caches not implemented */
1933 7a387fff ths
    env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
1934 7a387fff ths
    RETURN();
1935 7a387fff ths
}
1936 7a387fff ths
1937 fd88b6ab ths
void op_mtc0_watchlo (void)
1938 8c0fdd85 ths
{
1939 4e7a4a4e ths
    /* Watch exceptions for instructions, data loads, data stores
1940 4e7a4a4e ths
       not implemented. */
1941 fd88b6ab ths
    env->CP0_WatchLo[PARAM1] = (T0 & ~0x7);
1942 8c0fdd85 ths
    RETURN();
1943 8c0fdd85 ths
}
1944 8c0fdd85 ths
1945 fd88b6ab ths
void op_mtc0_watchhi (void)
1946 8c0fdd85 ths
{
1947 fd88b6ab ths
    env->CP0_WatchHi[PARAM1] = (T0 & 0x40FF0FF8);
1948 fd88b6ab ths
    env->CP0_WatchHi[PARAM1] &= ~(env->CP0_WatchHi[PARAM1] & T0 & 0x7);
1949 8c0fdd85 ths
    RETURN();
1950 8c0fdd85 ths
}
1951 8c0fdd85 ths
1952 ead9360e ths
void op_mtc0_xcontext (void)
1953 ead9360e ths
{
1954 ead9360e ths
    target_ulong mask = (1ULL << (env->SEGBITS - 7)) - 1;
1955 ead9360e ths
    env->CP0_XContext = (env->CP0_XContext & mask) | (T0 & ~mask);
1956 ead9360e ths
    RETURN();
1957 ead9360e ths
}
1958 ead9360e ths
1959 7a387fff ths
void op_mtc0_framemask (void)
1960 7a387fff ths
{
1961 7a387fff ths
    env->CP0_Framemask = T0; /* XXX */
1962 7a387fff ths
    RETURN();
1963 7a387fff ths
}
1964 7a387fff ths
1965 8c0fdd85 ths
void op_mtc0_debug (void)
1966 8c0fdd85 ths
{
1967 8c0fdd85 ths
    env->CP0_Debug = (env->CP0_Debug & 0x8C03FC1F) | (T0 & 0x13300120);
1968 8c0fdd85 ths
    if (T0 & (1 << CP0DB_DM))
1969 8c0fdd85 ths
        env->hflags |= MIPS_HFLAG_DM;
1970 8c0fdd85 ths
    else
1971 8c0fdd85 ths
        env->hflags &= ~MIPS_HFLAG_DM;
1972 8c0fdd85 ths
    RETURN();
1973 8c0fdd85 ths
}
1974 8c0fdd85 ths
1975 ead9360e ths
void op_mttc0_debug(void)
1976 ead9360e ths
{
1977 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1978 ead9360e ths
1979 ead9360e ths
    /* XXX: Might be wrong, check with EJTAG spec. */
1980 ead9360e ths
    env->CP0_Debug_tcstatus[other_tc] = T0 & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt));
1981 ead9360e ths
    env->CP0_Debug = (env->CP0_Debug & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
1982 ead9360e ths
                     (T0 & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
1983 ead9360e ths
    RETURN();
1984 ead9360e ths
}
1985 ead9360e ths
1986 8c0fdd85 ths
void op_mtc0_depc (void)
1987 8c0fdd85 ths
{
1988 f1b0aa5d ths
    env->CP0_DEPC = T0;
1989 8c0fdd85 ths
    RETURN();
1990 8c0fdd85 ths
}
1991 8c0fdd85 ths
1992 7a387fff ths
void op_mtc0_performance0 (void)
1993 7a387fff ths
{
1994 7a387fff ths
    env->CP0_Performance0 = T0; /* XXX */
1995 7a387fff ths
    RETURN();
1996 7a387fff ths
}
1997 7a387fff ths
1998 8c0fdd85 ths
void op_mtc0_taglo (void)
1999 8c0fdd85 ths
{
2000 9c2149c8 ths
    env->CP0_TagLo = T0 & 0xFFFFFCF6;
2001 8c0fdd85 ths
    RETURN();
2002 8c0fdd85 ths
}
2003 8c0fdd85 ths
2004 7a387fff ths
void op_mtc0_datalo (void)
2005 7a387fff ths
{
2006 7a387fff ths
    env->CP0_DataLo = T0; /* XXX */
2007 7a387fff ths
    RETURN();
2008 7a387fff ths
}
2009 7a387fff ths
2010 7a387fff ths
void op_mtc0_taghi (void)
2011 7a387fff ths
{
2012 7a387fff ths
    env->CP0_TagHi = T0; /* XXX */
2013 7a387fff ths
    RETURN();
2014 7a387fff ths
}
2015 7a387fff ths
2016 7a387fff ths
void op_mtc0_datahi (void)
2017 7a387fff ths
{
2018 7a387fff ths
    env->CP0_DataHi = T0; /* XXX */
2019 7a387fff ths
    RETURN();
2020 7a387fff ths
}
2021 7a387fff ths
2022 8c0fdd85 ths
void op_mtc0_errorepc (void)
2023 8c0fdd85 ths
{
2024 f1b0aa5d ths
    env->CP0_ErrorEPC = T0;
2025 8c0fdd85 ths
    RETURN();
2026 8c0fdd85 ths
}
2027 8c0fdd85 ths
2028 8c0fdd85 ths
void op_mtc0_desave (void)
2029 8c0fdd85 ths
{
2030 8c0fdd85 ths
    env->CP0_DESAVE = T0;
2031 6af0bf9c bellard
    RETURN();
2032 6af0bf9c bellard
}
2033 6af0bf9c bellard
2034 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
2035 ead9360e ths
void op_dmfc0_yqmask (void)
2036 f1b0aa5d ths
{
2037 ead9360e ths
    T0 = env->CP0_YQMask;
2038 ead9360e ths
    RETURN();
2039 ead9360e ths
}
2040 ead9360e ths
2041 ead9360e ths
void op_dmfc0_vpeschedule (void)
2042 ead9360e ths
{
2043 ead9360e ths
    T0 = env->CP0_VPESchedule;
2044 ead9360e ths
    RETURN();
2045 ead9360e ths
}
2046 ead9360e ths
2047 ead9360e ths
void op_dmfc0_vpeschefback (void)
2048 ead9360e ths
{
2049 ead9360e ths
    T0 = env->CP0_VPEScheFBack;
2050 f1b0aa5d ths
    RETURN();
2051 f1b0aa5d ths
}
2052 f1b0aa5d ths
2053 9c2149c8 ths
void op_dmfc0_entrylo0 (void)
2054 9c2149c8 ths
{
2055 9c2149c8 ths
    T0 = env->CP0_EntryLo0;
2056 9c2149c8 ths
    RETURN();
2057 9c2149c8 ths
}
2058 9c2149c8 ths
2059 ead9360e ths
void op_dmfc0_tcrestart (void)
2060 ead9360e ths
{
2061 ead9360e ths
    T0 = env->PC[env->current_tc];
2062 ead9360e ths
    RETURN();
2063 ead9360e ths
}
2064 ead9360e ths
2065 ead9360e ths
void op_dmfc0_tchalt (void)
2066 ead9360e ths
{
2067 ead9360e ths
    T0 = env->CP0_TCHalt[env->current_tc];
2068 ead9360e ths
    RETURN();
2069 ead9360e ths
}
2070 ead9360e ths
2071 ead9360e ths
void op_dmfc0_tccontext (void)
2072 ead9360e ths
{
2073 ead9360e ths
    T0 = env->CP0_TCContext[env->current_tc];
2074 ead9360e ths
    RETURN();
2075 ead9360e ths
}
2076 ead9360e ths
2077 ead9360e ths
void op_dmfc0_tcschedule (void)
2078 ead9360e ths
{
2079 ead9360e ths
    T0 = env->CP0_TCSchedule[env->current_tc];
2080 ead9360e ths
    RETURN();
2081 ead9360e ths
}
2082 ead9360e ths
2083 ead9360e ths
void op_dmfc0_tcschefback (void)
2084 ead9360e ths
{
2085 ead9360e ths
    T0 = env->CP0_TCScheFBack[env->current_tc];
2086 ead9360e ths
    RETURN();
2087 ead9360e ths
}
2088 ead9360e ths
2089 9c2149c8 ths
void op_dmfc0_entrylo1 (void)
2090 9c2149c8 ths
{
2091 9c2149c8 ths
    T0 = env->CP0_EntryLo1;
2092 9c2149c8 ths
    RETURN();
2093 9c2149c8 ths
}
2094 9c2149c8 ths
2095 9c2149c8 ths
void op_dmfc0_context (void)
2096 9c2149c8 ths
{
2097 9c2149c8 ths
    T0 = env->CP0_Context;
2098 9c2149c8 ths
    RETURN();
2099 9c2149c8 ths
}
2100 9c2149c8 ths
2101 9c2149c8 ths
void op_dmfc0_badvaddr (void)
2102 9c2149c8 ths
{
2103 9c2149c8 ths
    T0 = env->CP0_BadVAddr;
2104 9c2149c8 ths
    RETURN();
2105 9c2149c8 ths
}
2106 9c2149c8 ths
2107 9c2149c8 ths
void op_dmfc0_entryhi (void)
2108 9c2149c8 ths
{
2109 9c2149c8 ths
    T0 = env->CP0_EntryHi;
2110 9c2149c8 ths
    RETURN();
2111 9c2149c8 ths
}
2112 9c2149c8 ths
2113 9c2149c8 ths
void op_dmfc0_epc (void)
2114 9c2149c8 ths
{
2115 9c2149c8 ths
    T0 = env->CP0_EPC;
2116 9c2149c8 ths
    RETURN();
2117 9c2149c8 ths
}
2118 9c2149c8 ths
2119 9c2149c8 ths
void op_dmfc0_lladdr (void)
2120 9c2149c8 ths
{
2121 9c2149c8 ths
    T0 = env->CP0_LLAddr >> 4;
2122 9c2149c8 ths
    RETURN();
2123 9c2149c8 ths
}
2124 9c2149c8 ths
2125 fd88b6ab ths
void op_dmfc0_watchlo (void)
2126 9c2149c8 ths
{
2127 fd88b6ab ths
    T0 = env->CP0_WatchLo[PARAM1];
2128 9c2149c8 ths
    RETURN();
2129 9c2149c8 ths
}
2130 9c2149c8 ths
2131 9c2149c8 ths
void op_dmfc0_xcontext (void)
2132 9c2149c8 ths
{
2133 9c2149c8 ths
    T0 = env->CP0_XContext;
2134 9c2149c8 ths
    RETURN();
2135 9c2149c8 ths
}
2136 9c2149c8 ths
2137 9c2149c8 ths
void op_dmfc0_depc (void)
2138 9c2149c8 ths
{
2139 9c2149c8 ths
    T0 = env->CP0_DEPC;
2140 9c2149c8 ths
    RETURN();
2141 9c2149c8 ths
}
2142 9c2149c8 ths
2143 9c2149c8 ths
void op_dmfc0_errorepc (void)
2144 9c2149c8 ths
{
2145 9c2149c8 ths
    T0 = env->CP0_ErrorEPC;
2146 9c2149c8 ths
    RETURN();
2147 9c2149c8 ths
}
2148 540635ba ths
#endif /* TARGET_MIPSN32 || TARGET_MIPS64 */
2149 9c2149c8 ths
2150 ead9360e ths
/* MIPS MT functions */
2151 ead9360e ths
void op_mftgpr(void)
2152 ead9360e ths
{
2153 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2154 ead9360e ths
2155 ead9360e ths
    T0 = env->gpr[PARAM1][other_tc];
2156 ead9360e ths
    RETURN();
2157 ead9360e ths
}
2158 ead9360e ths
2159 ead9360e ths
void op_mftlo(void)
2160 ead9360e ths
{
2161 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2162 ead9360e ths
2163 ead9360e ths
    T0 = env->LO[PARAM1][other_tc];
2164 ead9360e ths
    RETURN();
2165 ead9360e ths
}
2166 ead9360e ths
2167 ead9360e ths
void op_mfthi(void)
2168 ead9360e ths
{
2169 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2170 ead9360e ths
2171 ead9360e ths
    T0 = env->HI[PARAM1][other_tc];
2172 ead9360e ths
    RETURN();
2173 ead9360e ths
}
2174 ead9360e ths
2175 ead9360e ths
void op_mftacx(void)
2176 ead9360e ths
{
2177 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2178 ead9360e ths
2179 ead9360e ths
    T0 = env->ACX[PARAM1][other_tc];
2180 ead9360e ths
    RETURN();
2181 ead9360e ths
}
2182 ead9360e ths
2183 ead9360e ths
void op_mftdsp(void)
2184 ead9360e ths
{
2185 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2186 ead9360e ths
2187 ead9360e ths
    T0 = env->DSPControl[other_tc];
2188 ead9360e ths
    RETURN();
2189 ead9360e ths
}
2190 ead9360e ths
2191 ead9360e ths
void op_mttgpr(void)
2192 ead9360e ths
{
2193 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2194 ead9360e ths
2195 ead9360e ths
    T0 = env->gpr[PARAM1][other_tc];
2196 ead9360e ths
    RETURN();
2197 ead9360e ths
}
2198 ead9360e ths
2199 ead9360e ths
void op_mttlo(void)
2200 ead9360e ths
{
2201 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2202 ead9360e ths
2203 ead9360e ths
    T0 = env->LO[PARAM1][other_tc];
2204 ead9360e ths
    RETURN();
2205 ead9360e ths
}
2206 ead9360e ths
2207 ead9360e ths
void op_mtthi(void)
2208 ead9360e ths
{
2209 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2210 ead9360e ths
2211 ead9360e ths
    T0 = env->HI[PARAM1][other_tc];
2212 ead9360e ths
    RETURN();
2213 ead9360e ths
}
2214 ead9360e ths
2215 ead9360e ths
void op_mttacx(void)
2216 ead9360e ths
{
2217 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2218 ead9360e ths
2219 ead9360e ths
    T0 = env->ACX[PARAM1][other_tc];
2220 ead9360e ths
    RETURN();
2221 ead9360e ths
}
2222 ead9360e ths
2223 ead9360e ths
void op_mttdsp(void)
2224 ead9360e ths
{
2225 ead9360e ths
    int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
2226 ead9360e ths
2227 ead9360e ths
    T0 = env->DSPControl[other_tc];
2228 ead9360e ths
    RETURN();
2229 ead9360e ths
}
2230 ead9360e ths
2231 ead9360e ths
2232 ead9360e ths
void op_dmt(void)
2233 ead9360e ths
{
2234 ead9360e ths
    // TODO
2235 ead9360e ths
    T0 = 0;
2236 ead9360e ths
    // rt = T0
2237 ead9360e ths
    RETURN();
2238 ead9360e ths
}
2239 ead9360e ths
2240 ead9360e ths
void op_emt(void)
2241 ead9360e ths
{
2242 ead9360e ths
    // TODO
2243 ead9360e ths
    T0 = 0;
2244 ead9360e ths
    // rt = T0
2245 ead9360e ths
    RETURN();
2246 ead9360e ths
}
2247 ead9360e ths
2248 ead9360e ths
void op_dvpe(void)
2249 ead9360e ths
{
2250 ead9360e ths
    // TODO
2251 ead9360e ths
    T0 = 0;
2252 ead9360e ths
    // rt = T0
2253 ead9360e ths
    RETURN();
2254 ead9360e ths
}
2255 ead9360e ths
2256 ead9360e ths
void op_evpe(void)
2257 ead9360e ths
{
2258 ead9360e ths
    // TODO
2259 ead9360e ths
    T0 = 0;
2260 ead9360e ths
    // rt = T0
2261 ead9360e ths
    RETURN();
2262 ead9360e ths
}
2263 ead9360e ths
2264 ead9360e ths
void op_fork(void)
2265 ead9360e ths
{
2266 ead9360e ths
    // T0 = rt, T1 = rs
2267 ead9360e ths
    T0 = 0;
2268 ead9360e ths
    // TODO: store to TC register
2269 ead9360e ths
    RETURN();
2270 ead9360e ths
}
2271 ead9360e ths
2272 ead9360e ths
void op_yield(void)
2273 ead9360e ths
{
2274 ead9360e ths
    if (T0 < 0) {
2275 ead9360e ths
        /* No scheduling policy implemented. */
2276 ead9360e ths
        if (T0 != -2) {
2277 ead9360e ths
            if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
2278 ead9360e ths
                env->CP0_TCStatus[env->current_tc] & (1 << CP0TCSt_DT)) {
2279 ead9360e ths
                env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
2280 ead9360e ths
                env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
2281 ead9360e ths
                CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
2282 ead9360e ths
            }
2283 ead9360e ths
        }
2284 ead9360e ths
    } else if (T0 == 0) {
2285 ead9360e ths
        if (0 /* TODO: TC underflow */) {
2286 ead9360e ths
            env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
2287 ead9360e ths
            CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
2288 ead9360e ths
        } else {
2289 ead9360e ths
            // TODO: Deallocate TC
2290 ead9360e ths
        }
2291 ead9360e ths
    } else if (T0 > 0) {
2292 ead9360e ths
        /* Yield qualifier inputs not implemented. */
2293 ead9360e ths
        env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
2294 ead9360e ths
        env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
2295 ead9360e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_THREAD);
2296 ead9360e ths
    }
2297 ead9360e ths
    T0 = env->CP0_YQMask;
2298 ead9360e ths
    RETURN();
2299 ead9360e ths
}
2300 ead9360e ths
2301 5a5012ec ths
/* CP1 functions */
2302 6ea83fed bellard
#if 0
2303 6ea83fed bellard
# define DEBUG_FPU_STATE() CALL_FROM_TB1(dump_fpu, env)
2304 6ea83fed bellard
#else
2305 6ea83fed bellard
# define DEBUG_FPU_STATE() do { } while(0)
2306 6ea83fed bellard
#endif
2307 6ea83fed bellard
2308 5a5012ec ths
void op_cfc1 (void)
2309 5a5012ec ths
{
2310 ead9360e ths
    CALL_FROM_TB1(do_cfc1, PARAM1);
2311 5a5012ec ths
    DEBUG_FPU_STATE();
2312 5a5012ec ths
    RETURN();
2313 5a5012ec ths
}
2314 5a5012ec ths
2315 5a5012ec ths
void op_ctc1 (void)
2316 5a5012ec ths
{
2317 ead9360e ths
    CALL_FROM_TB1(do_ctc1, PARAM1);
2318 6ea83fed bellard
    DEBUG_FPU_STATE();
2319 6ea83fed bellard
    RETURN();
2320 6ea83fed bellard
}
2321 6ea83fed bellard
2322 6ea83fed bellard
void op_mfc1 (void)
2323 6ea83fed bellard
{
2324 6ea83fed bellard
    T0 = WT0;
2325 6ea83fed bellard
    DEBUG_FPU_STATE();
2326 6ea83fed bellard
    RETURN();
2327 6ea83fed bellard
}
2328 6ea83fed bellard
2329 6ea83fed bellard
void op_mtc1 (void)
2330 6ea83fed bellard
{
2331 6ea83fed bellard
    WT0 = T0;
2332 6ea83fed bellard
    DEBUG_FPU_STATE();
2333 6ea83fed bellard
    RETURN();
2334 6ea83fed bellard
}
2335 6ea83fed bellard
2336 5a5012ec ths
void op_dmfc1 (void)
2337 5a5012ec ths
{
2338 5a5012ec ths
    T0 = DT0;
2339 5a5012ec ths
    DEBUG_FPU_STATE();
2340 5a5012ec ths
    RETURN();
2341 5a5012ec ths
}
2342 5a5012ec ths
2343 5a5012ec ths
void op_dmtc1 (void)
2344 5a5012ec ths
{
2345 5a5012ec ths
    DT0 = T0;
2346 5a5012ec ths
    DEBUG_FPU_STATE();
2347 5a5012ec ths
    RETURN();
2348 5a5012ec ths
}
2349 5a5012ec ths
2350 5a5012ec ths
void op_mfhc1 (void)
2351 5a5012ec ths
{
2352 5a5012ec ths
    T0 = WTH0;
2353 5a5012ec ths
    DEBUG_FPU_STATE();
2354 5a5012ec ths
    RETURN();
2355 5a5012ec ths
}
2356 5a5012ec ths
2357 5a5012ec ths
void op_mthc1 (void)
2358 5a5012ec ths
{
2359 5a5012ec ths
    WTH0 = T0;
2360 5a5012ec ths
    DEBUG_FPU_STATE();
2361 5a5012ec ths
    RETURN();
2362 5a5012ec ths
}
2363 5a5012ec ths
2364 6ea83fed bellard
/* Float support.
2365 6ea83fed bellard
   Single precition routines have a "s" suffix, double precision a
2366 5a5012ec ths
   "d" suffix, 32bit integer "w", 64bit integer "l", paired singe "ps",
2367 5a5012ec ths
   paired single lowwer "pl", paired single upper "pu".  */
2368 6ea83fed bellard
2369 6ea83fed bellard
#define FLOAT_OP(name, p) void OPPROTO op_float_##name##_##p(void)
2370 6ea83fed bellard
2371 dd016883 bellard
FLOAT_OP(cvtd, s)
2372 dd016883 bellard
{
2373 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtd_s);
2374 dd016883 bellard
    DEBUG_FPU_STATE();
2375 dd016883 bellard
    RETURN();
2376 dd016883 bellard
}
2377 6ea83fed bellard
FLOAT_OP(cvtd, w)
2378 6ea83fed bellard
{
2379 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtd_w);
2380 5a5012ec ths
    DEBUG_FPU_STATE();
2381 5a5012ec ths
    RETURN();
2382 5a5012ec ths
}
2383 5a5012ec ths
FLOAT_OP(cvtd, l)
2384 5a5012ec ths
{
2385 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtd_l);
2386 5a5012ec ths
    DEBUG_FPU_STATE();
2387 5a5012ec ths
    RETURN();
2388 5a5012ec ths
}
2389 5a5012ec ths
FLOAT_OP(cvtl, d)
2390 5a5012ec ths
{
2391 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtl_d);
2392 5a5012ec ths
    DEBUG_FPU_STATE();
2393 5a5012ec ths
    RETURN();
2394 5a5012ec ths
}
2395 5a5012ec ths
FLOAT_OP(cvtl, s)
2396 5a5012ec ths
{
2397 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtl_s);
2398 5a5012ec ths
    DEBUG_FPU_STATE();
2399 5a5012ec ths
    RETURN();
2400 5a5012ec ths
}
2401 5a5012ec ths
FLOAT_OP(cvtps, s)
2402 5a5012ec ths
{
2403 5a5012ec ths
    WT2 = WT0;
2404 5a5012ec ths
    WTH2 = WT1;
2405 5a5012ec ths
    DEBUG_FPU_STATE();
2406 5a5012ec ths
    RETURN();
2407 5a5012ec ths
}
2408 5a5012ec ths
FLOAT_OP(cvtps, pw)
2409 5a5012ec ths
{
2410 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtps_pw);
2411 5a5012ec ths
    DEBUG_FPU_STATE();
2412 5a5012ec ths
    RETURN();
2413 5a5012ec ths
}
2414 5a5012ec ths
FLOAT_OP(cvtpw, ps)
2415 5a5012ec ths
{
2416 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtpw_ps);
2417 6ea83fed bellard
    DEBUG_FPU_STATE();
2418 6ea83fed bellard
    RETURN();
2419 6ea83fed bellard
}
2420 dd016883 bellard
FLOAT_OP(cvts, d)
2421 dd016883 bellard
{
2422 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvts_d);
2423 dd016883 bellard
    DEBUG_FPU_STATE();
2424 dd016883 bellard
    RETURN();
2425 dd016883 bellard
}
2426 6ea83fed bellard
FLOAT_OP(cvts, w)
2427 6ea83fed bellard
{
2428 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvts_w);
2429 5a5012ec ths
    DEBUG_FPU_STATE();
2430 5a5012ec ths
    RETURN();
2431 5a5012ec ths
}
2432 5a5012ec ths
FLOAT_OP(cvts, l)
2433 5a5012ec ths
{
2434 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvts_l);
2435 5a5012ec ths
    DEBUG_FPU_STATE();
2436 5a5012ec ths
    RETURN();
2437 5a5012ec ths
}
2438 5a5012ec ths
FLOAT_OP(cvts, pl)
2439 5a5012ec ths
{
2440 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvts_pl);
2441 5a5012ec ths
    DEBUG_FPU_STATE();
2442 5a5012ec ths
    RETURN();
2443 5a5012ec ths
}
2444 5a5012ec ths
FLOAT_OP(cvts, pu)
2445 5a5012ec ths
{
2446 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvts_pu);
2447 6ea83fed bellard
    DEBUG_FPU_STATE();
2448 6ea83fed bellard
    RETURN();
2449 6ea83fed bellard
}
2450 6ea83fed bellard
FLOAT_OP(cvtw, s)
2451 6ea83fed bellard
{
2452 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtw_s);
2453 6ea83fed bellard
    DEBUG_FPU_STATE();
2454 6ea83fed bellard
    RETURN();
2455 6ea83fed bellard
}
2456 6ea83fed bellard
FLOAT_OP(cvtw, d)
2457 6ea83fed bellard
{
2458 fd4a04eb ths
    CALL_FROM_TB0(do_float_cvtw_d);
2459 5a5012ec ths
    DEBUG_FPU_STATE();
2460 5a5012ec ths
    RETURN();
2461 5a5012ec ths
}
2462 5a5012ec ths
2463 5a5012ec ths
FLOAT_OP(pll, ps)
2464 5a5012ec ths
{
2465 5a5012ec ths
    DT2 = ((uint64_t)WT0 << 32) | WT1;
2466 5a5012ec ths
    DEBUG_FPU_STATE();
2467 5a5012ec ths
    RETURN();
2468 5a5012ec ths
}
2469 5a5012ec ths
FLOAT_OP(plu, ps)
2470 5a5012ec ths
{
2471 5a5012ec ths
    DT2 = ((uint64_t)WT0 << 32) | WTH1;
2472 5a5012ec ths
    DEBUG_FPU_STATE();
2473 5a5012ec ths
    RETURN();
2474 5a5012ec ths
}
2475 5a5012ec ths
FLOAT_OP(pul, ps)
2476 5a5012ec ths
{
2477 5a5012ec ths
    DT2 = ((uint64_t)WTH0 << 32) | WT1;
2478 5a5012ec ths
    DEBUG_FPU_STATE();
2479 5a5012ec ths
    RETURN();
2480 5a5012ec ths
}
2481 5a5012ec ths
FLOAT_OP(puu, ps)
2482 5a5012ec ths
{
2483 5a5012ec ths
    DT2 = ((uint64_t)WTH0 << 32) | WTH1;
2484 6ea83fed bellard
    DEBUG_FPU_STATE();
2485 6ea83fed bellard
    RETURN();
2486 6ea83fed bellard
}
2487 6ea83fed bellard
2488 fd4a04eb ths
#define FLOAT_ROUNDOP(op, ttype, stype)                    \
2489 fd4a04eb ths
FLOAT_OP(op ## ttype, stype)                               \
2490 fd4a04eb ths
{                                                          \
2491 fd4a04eb ths
    CALL_FROM_TB0(do_float_ ## op ## ttype ## _ ## stype); \
2492 fd4a04eb ths
    DEBUG_FPU_STATE();                                     \
2493 fd4a04eb ths
    RETURN();                                              \
2494 6ea83fed bellard
}
2495 6ea83fed bellard
2496 fd4a04eb ths
FLOAT_ROUNDOP(round, l, d)
2497 fd4a04eb ths
FLOAT_ROUNDOP(round, l, s)
2498 fd4a04eb ths
FLOAT_ROUNDOP(round, w, d)
2499 fd4a04eb ths
FLOAT_ROUNDOP(round, w, s)
2500 6ea83fed bellard
2501 fd4a04eb ths
FLOAT_ROUNDOP(trunc, l, d)
2502 fd4a04eb ths
FLOAT_ROUNDOP(trunc, l, s)
2503 fd4a04eb ths
FLOAT_ROUNDOP(trunc, w, d)
2504 fd4a04eb ths
FLOAT_ROUNDOP(trunc, w, s)
2505 6ea83fed bellard
2506 fd4a04eb ths
FLOAT_ROUNDOP(ceil, l, d)
2507 fd4a04eb ths
FLOAT_ROUNDOP(ceil, l, s)
2508 fd4a04eb ths
FLOAT_ROUNDOP(ceil, w, d)
2509 fd4a04eb ths
FLOAT_ROUNDOP(ceil, w, s)
2510 fd4a04eb ths
2511 fd4a04eb ths
FLOAT_ROUNDOP(floor, l, d)
2512 fd4a04eb ths
FLOAT_ROUNDOP(floor, l, s)
2513 fd4a04eb ths
FLOAT_ROUNDOP(floor, w, d)
2514 fd4a04eb ths
FLOAT_ROUNDOP(floor, w, s)
2515 fd4a04eb ths
#undef FLOAR_ROUNDOP
2516 6ea83fed bellard
2517 5a5012ec ths
FLOAT_OP(movf, d)
2518 5a5012ec ths
{
2519 ead9360e ths
    if (!(env->fpu->fcr31 & PARAM1))
2520 5a5012ec ths
        DT2 = DT0;
2521 5a5012ec ths
    DEBUG_FPU_STATE();
2522 5a5012ec ths
    RETURN();
2523 5a5012ec ths
}
2524 5a5012ec ths
FLOAT_OP(movf, s)
2525 5a5012ec ths
{
2526 ead9360e ths
    if (!(env->fpu->fcr31 & PARAM1))
2527 5a5012ec ths
        WT2 = WT0;
2528 5a5012ec ths
    DEBUG_FPU_STATE();
2529 5a5012ec ths
    RETURN();
2530 5a5012ec ths
}
2531 5a5012ec ths
FLOAT_OP(movf, ps)
2532 5a5012ec ths
{
2533 ead9360e ths
    if (!(env->fpu->fcr31 & PARAM1)) {
2534 5a5012ec ths
        WT2 = WT0;
2535 5a5012ec ths
        WTH2 = WTH0;
2536 5a5012ec ths
    }
2537 5a5012ec ths
    DEBUG_FPU_STATE();
2538 5a5012ec ths
    RETURN();
2539 5a5012ec ths
}
2540 5a5012ec ths
FLOAT_OP(movt, d)
2541 5a5012ec ths
{
2542 ead9360e ths
    if (env->fpu->fcr31 & PARAM1)
2543 5a5012ec ths
        DT2 = DT0;
2544 5a5012ec ths
    DEBUG_FPU_STATE();
2545 5a5012ec ths
    RETURN();
2546 5a5012ec ths
}
2547 5a5012ec ths
FLOAT_OP(movt, s)
2548 5a5012ec ths
{
2549 ead9360e ths
    if (env->fpu->fcr31 & PARAM1)
2550 5a5012ec ths
        WT2 = WT0;
2551 5a5012ec ths
    DEBUG_FPU_STATE();
2552 5a5012ec ths
    RETURN();
2553 5a5012ec ths
}
2554 5a5012ec ths
FLOAT_OP(movt, ps)
2555 5a5012ec ths
{
2556 ead9360e ths
    if (env->fpu->fcr31 & PARAM1) {
2557 5a5012ec ths
        WT2 = WT0;
2558 5a5012ec ths
        WTH2 = WTH0;
2559 5a5012ec ths
    }
2560 5a5012ec ths
    DEBUG_FPU_STATE();
2561 5a5012ec ths
    RETURN();
2562 5a5012ec ths
}
2563 5a5012ec ths
FLOAT_OP(movz, d)
2564 5a5012ec ths
{
2565 5a5012ec ths
    if (!T0)
2566 5a5012ec ths
        DT2 = DT0;
2567 5a5012ec ths
    DEBUG_FPU_STATE();
2568 5a5012ec ths
    RETURN();
2569 5a5012ec ths
}
2570 5a5012ec ths
FLOAT_OP(movz, s)
2571 5a5012ec ths
{
2572 5a5012ec ths
    if (!T0)
2573 5a5012ec ths
        WT2 = WT0;
2574 5a5012ec ths
    DEBUG_FPU_STATE();
2575 5a5012ec ths
    RETURN();
2576 5a5012ec ths
}
2577 5a5012ec ths
FLOAT_OP(movz, ps)
2578 5a5012ec ths
{
2579 5a5012ec ths
    if (!T0) {
2580 5a5012ec ths
        WT2 = WT0;
2581 5a5012ec ths
        WTH2 = WTH0;
2582 5a5012ec ths
    }
2583 5a5012ec ths
    DEBUG_FPU_STATE();
2584 5a5012ec ths
    RETURN();
2585 5a5012ec ths
}
2586 5a5012ec ths
FLOAT_OP(movn, d)
2587 5a5012ec ths
{
2588 5a5012ec ths
    if (T0)
2589 5a5012ec ths
        DT2 = DT0;
2590 5a5012ec ths
    DEBUG_FPU_STATE();
2591 5a5012ec ths
    RETURN();
2592 5a5012ec ths
}
2593 5a5012ec ths
FLOAT_OP(movn, s)
2594 5a5012ec ths
{
2595 5a5012ec ths
    if (T0)
2596 5a5012ec ths
        WT2 = WT0;
2597 5a5012ec ths
    DEBUG_FPU_STATE();
2598 5a5012ec ths
    RETURN();
2599 5a5012ec ths
}
2600 5a5012ec ths
FLOAT_OP(movn, ps)
2601 5a5012ec ths
{
2602 5a5012ec ths
    if (T0) {
2603 5a5012ec ths
        WT2 = WT0;
2604 5a5012ec ths
        WTH2 = WTH0;
2605 5a5012ec ths
    }
2606 5a5012ec ths
    DEBUG_FPU_STATE();
2607 5a5012ec ths
    RETURN();
2608 5a5012ec ths
}
2609 5a5012ec ths
2610 57fa1fb3 ths
/* operations calling helpers, for s, d and ps */
2611 57fa1fb3 ths
#define FLOAT_HOP(name) \
2612 6ea83fed bellard
FLOAT_OP(name, d)         \
2613 6ea83fed bellard
{                         \
2614 fd4a04eb ths
    CALL_FROM_TB0(do_float_ ## name ## _d);  \
2615 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2616 fbcc6828 ths
    RETURN();             \
2617 6ea83fed bellard
}                         \
2618 6ea83fed bellard
FLOAT_OP(name, s)         \
2619 6ea83fed bellard
{                         \
2620 fd4a04eb ths
    CALL_FROM_TB0(do_float_ ## name ## _s);  \
2621 5a5012ec ths
    DEBUG_FPU_STATE();    \
2622 fbcc6828 ths
    RETURN();             \
2623 5a5012ec ths
}                         \
2624 5a5012ec ths
FLOAT_OP(name, ps)        \
2625 5a5012ec ths
{                         \
2626 fd4a04eb ths
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
2627 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2628 fbcc6828 ths
    RETURN();             \
2629 6ea83fed bellard
}
2630 57fa1fb3 ths
FLOAT_HOP(add)
2631 57fa1fb3 ths
FLOAT_HOP(sub)
2632 57fa1fb3 ths
FLOAT_HOP(mul)
2633 57fa1fb3 ths
FLOAT_HOP(div)
2634 57fa1fb3 ths
FLOAT_HOP(recip2)
2635 57fa1fb3 ths
FLOAT_HOP(rsqrt2)
2636 57fa1fb3 ths
FLOAT_HOP(rsqrt1)
2637 57fa1fb3 ths
FLOAT_HOP(recip1)
2638 57fa1fb3 ths
#undef FLOAT_HOP
2639 57fa1fb3 ths
2640 57fa1fb3 ths
/* operations calling helpers, for s and d */
2641 57fa1fb3 ths
#define FLOAT_HOP(name)   \
2642 57fa1fb3 ths
FLOAT_OP(name, d)         \
2643 57fa1fb3 ths
{                         \
2644 57fa1fb3 ths
    CALL_FROM_TB0(do_float_ ## name ## _d);  \
2645 57fa1fb3 ths
    DEBUG_FPU_STATE();    \
2646 57fa1fb3 ths
    RETURN();             \
2647 57fa1fb3 ths
}                         \
2648 57fa1fb3 ths
FLOAT_OP(name, s)         \
2649 57fa1fb3 ths
{                         \
2650 57fa1fb3 ths
    CALL_FROM_TB0(do_float_ ## name ## _s);  \
2651 57fa1fb3 ths
    DEBUG_FPU_STATE();    \
2652 57fa1fb3 ths
    RETURN();             \
2653 57fa1fb3 ths
}
2654 57fa1fb3 ths
FLOAT_HOP(rsqrt)
2655 57fa1fb3 ths
FLOAT_HOP(recip)
2656 57fa1fb3 ths
#undef FLOAT_HOP
2657 6ea83fed bellard
2658 57fa1fb3 ths
/* operations calling helpers, for ps */
2659 57fa1fb3 ths
#define FLOAT_HOP(name)   \
2660 57fa1fb3 ths
FLOAT_OP(name, ps)        \
2661 57fa1fb3 ths
{                         \
2662 57fa1fb3 ths
    CALL_FROM_TB0(do_float_ ## name ## _ps); \
2663 57fa1fb3 ths
    DEBUG_FPU_STATE();    \
2664 57fa1fb3 ths
    RETURN();             \
2665 fbcc6828 ths
}
2666 57fa1fb3 ths
FLOAT_HOP(addr)
2667 57fa1fb3 ths
FLOAT_HOP(mulr)
2668 57fa1fb3 ths
#undef FLOAT_HOP
2669 fbcc6828 ths
2670 5a5012ec ths
/* ternary operations */
2671 5a5012ec ths
#define FLOAT_TERNOP(name1, name2) \
2672 5a5012ec ths
FLOAT_OP(name1 ## name2, d)        \
2673 5a5012ec ths
{                                  \
2674 ead9360e ths
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status);    \
2675 ead9360e ths
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status);    \
2676 5a5012ec ths
    DEBUG_FPU_STATE();             \
2677 fbcc6828 ths
    RETURN();                      \
2678 5a5012ec ths
}                                  \
2679 5a5012ec ths
FLOAT_OP(name1 ## name2, s)        \
2680 5a5012ec ths
{                                  \
2681 ead9360e ths
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
2682 ead9360e ths
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2683 5a5012ec ths
    DEBUG_FPU_STATE();             \
2684 fbcc6828 ths
    RETURN();                      \
2685 5a5012ec ths
}                                  \
2686 5a5012ec ths
FLOAT_OP(name1 ## name2, ps)       \
2687 5a5012ec ths
{                                  \
2688 ead9360e ths
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
2689 ead9360e ths
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
2690 ead9360e ths
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2691 ead9360e ths
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2692 5a5012ec ths
    DEBUG_FPU_STATE();             \
2693 fbcc6828 ths
    RETURN();                      \
2694 5a5012ec ths
}
2695 5a5012ec ths
FLOAT_TERNOP(mul, add)
2696 5a5012ec ths
FLOAT_TERNOP(mul, sub)
2697 5a5012ec ths
#undef FLOAT_TERNOP
2698 5a5012ec ths
2699 fbcc6828 ths
/* negated ternary operations */
2700 fbcc6828 ths
#define FLOAT_NTERNOP(name1, name2) \
2701 fbcc6828 ths
FLOAT_OP(n ## name1 ## name2, d)    \
2702 fbcc6828 ths
{                                   \
2703 ead9360e ths
    FDT0 = float64_ ## name1 (FDT0, FDT1, &env->fpu->fp_status);    \
2704 ead9360e ths
    FDT2 = float64_ ## name2 (FDT0, FDT2, &env->fpu->fp_status);    \
2705 fbcc6828 ths
    FDT2 ^= 1ULL << 63;             \
2706 fbcc6828 ths
    DEBUG_FPU_STATE();              \
2707 fbcc6828 ths
    RETURN();                       \
2708 fbcc6828 ths
}                                   \
2709 fbcc6828 ths
FLOAT_OP(n ## name1 ## name2, s)    \
2710 fbcc6828 ths
{                                   \
2711 ead9360e ths
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
2712 ead9360e ths
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2713 fbcc6828 ths
    FST2 ^= 1 << 31;                \
2714 fbcc6828 ths
    DEBUG_FPU_STATE();              \
2715 fbcc6828 ths
    RETURN();                       \
2716 fbcc6828 ths
}                                   \
2717 fbcc6828 ths
FLOAT_OP(n ## name1 ## name2, ps)   \
2718 fbcc6828 ths
{                                   \
2719 ead9360e ths
    FST0 = float32_ ## name1 (FST0, FST1, &env->fpu->fp_status);    \
2720 ead9360e ths
    FSTH0 = float32_ ## name1 (FSTH0, FSTH1, &env->fpu->fp_status); \
2721 ead9360e ths
    FST2 = float32_ ## name2 (FST0, FST2, &env->fpu->fp_status);    \
2722 ead9360e ths
    FSTH2 = float32_ ## name2 (FSTH0, FSTH2, &env->fpu->fp_status); \
2723 fbcc6828 ths
    FST2 ^= 1 << 31;                \
2724 fbcc6828 ths
    FSTH2 ^= 1 << 31;               \
2725 fbcc6828 ths
    DEBUG_FPU_STATE();              \
2726 fbcc6828 ths
    RETURN();                       \
2727 fbcc6828 ths
}
2728 fbcc6828 ths
FLOAT_NTERNOP(mul, add)
2729 fbcc6828 ths
FLOAT_NTERNOP(mul, sub)
2730 fbcc6828 ths
#undef FLOAT_NTERNOP
2731 fbcc6828 ths
2732 6ea83fed bellard
/* unary operations, modifying fp status  */
2733 6ea83fed bellard
#define FLOAT_UNOP(name)  \
2734 6ea83fed bellard
FLOAT_OP(name, d)         \
2735 6ea83fed bellard
{                         \
2736 ead9360e ths
    FDT2 = float64_ ## name(FDT0, &env->fpu->fp_status);   \
2737 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2738 fbcc6828 ths
    RETURN();                      \
2739 6ea83fed bellard
}                         \
2740 6ea83fed bellard
FLOAT_OP(name, s)         \
2741 6ea83fed bellard
{                         \
2742 ead9360e ths
    FST2 = float32_ ## name(FST0, &env->fpu->fp_status);   \
2743 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2744 57fa1fb3 ths
    RETURN();             \
2745 6ea83fed bellard
}
2746 6ea83fed bellard
FLOAT_UNOP(sqrt)
2747 6ea83fed bellard
#undef FLOAT_UNOP
2748 6ea83fed bellard
2749 6ea83fed bellard
/* unary operations, not modifying fp status  */
2750 6ea83fed bellard
#define FLOAT_UNOP(name)  \
2751 6ea83fed bellard
FLOAT_OP(name, d)         \
2752 6ea83fed bellard
{                         \
2753 6ea83fed bellard
    FDT2 = float64_ ## name(FDT0);   \
2754 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2755 fbcc6828 ths
    RETURN();             \
2756 6ea83fed bellard
}                         \
2757 6ea83fed bellard
FLOAT_OP(name, s)         \
2758 6ea83fed bellard
{                         \
2759 6ea83fed bellard
    FST2 = float32_ ## name(FST0);   \
2760 6ea83fed bellard
    DEBUG_FPU_STATE();    \
2761 fbcc6828 ths
    RETURN();             \
2762 5a5012ec ths
}                         \
2763 5a5012ec ths
FLOAT_OP(name, ps)        \
2764 5a5012ec ths
{                         \
2765 5a5012ec ths
    FST2 = float32_ ## name(FST0);   \
2766 5a5012ec ths
    FSTH2 = float32_ ## name(FSTH0); \
2767 5a5012ec ths
    DEBUG_FPU_STATE();    \
2768 fbcc6828 ths
    RETURN();             \
2769 6ea83fed bellard
}
2770 6ea83fed bellard
FLOAT_UNOP(abs)
2771 6ea83fed bellard
FLOAT_UNOP(chs)
2772 6ea83fed bellard
#undef FLOAT_UNOP
2773 6ea83fed bellard
2774 6ea83fed bellard
FLOAT_OP(mov, d)
2775 6ea83fed bellard
{
2776 6ea83fed bellard
    FDT2 = FDT0;
2777 6ea83fed bellard
    DEBUG_FPU_STATE();
2778 6ea83fed bellard
    RETURN();
2779 6ea83fed bellard
}
2780 6ea83fed bellard
FLOAT_OP(mov, s)
2781 6ea83fed bellard
{
2782 6ea83fed bellard
    FST2 = FST0;
2783 6ea83fed bellard
    DEBUG_FPU_STATE();
2784 6ea83fed bellard
    RETURN();
2785 6ea83fed bellard
}
2786 5a5012ec ths
FLOAT_OP(mov, ps)
2787 5a5012ec ths
{
2788 5a5012ec ths
    FST2 = FST0;
2789 5a5012ec ths
    FSTH2 = FSTH0;
2790 5a5012ec ths
    DEBUG_FPU_STATE();
2791 5a5012ec ths
    RETURN();
2792 5a5012ec ths
}
2793 5a5012ec ths
FLOAT_OP(alnv, ps)
2794 5a5012ec ths
{
2795 5a5012ec ths
    switch (T0 & 0x7) {
2796 5a5012ec ths
    case 0:
2797 5a5012ec ths
        FST2 = FST0;
2798 5a5012ec ths
        FSTH2 = FSTH0;
2799 5a5012ec ths
        break;
2800 5a5012ec ths
    case 4:
2801 5a5012ec ths
#ifdef TARGET_WORDS_BIGENDIAN
2802 5a5012ec ths
        FSTH2 = FST0;
2803 5a5012ec ths
        FST2 = FSTH1;
2804 5a5012ec ths
#else
2805 5a5012ec ths
        FSTH2 = FST1;
2806 5a5012ec ths
        FST2 = FSTH0;
2807 5a5012ec ths
#endif
2808 5a5012ec ths
        break;
2809 5a5012ec ths
    default: /* unpredictable */
2810 5a5012ec ths
        break;
2811 5a5012ec ths
    }
2812 5a5012ec ths
    DEBUG_FPU_STATE();
2813 5a5012ec ths
    RETURN();
2814 5a5012ec ths
}
2815 6ea83fed bellard
2816 6ea83fed bellard
#ifdef CONFIG_SOFTFLOAT
2817 6ea83fed bellard
#define clear_invalid() do {                                \
2818 ead9360e ths
    int flags = get_float_exception_flags(&env->fpu->fp_status); \
2819 6ea83fed bellard
    flags &= ~float_flag_invalid;                           \
2820 ead9360e ths
    set_float_exception_flags(flags, &env->fpu->fp_status);      \
2821 6ea83fed bellard
} while(0)
2822 6ea83fed bellard
#else
2823 6ea83fed bellard
#define clear_invalid() do { } while(0)
2824 6ea83fed bellard
#endif
2825 6ea83fed bellard
2826 6ea83fed bellard
extern void dump_fpu_s(CPUState *env);
2827 6ea83fed bellard
2828 fd4a04eb ths
#define CMP_OP(fmt, op)                                \
2829 fd4a04eb ths
void OPPROTO op_cmp ## _ ## fmt ## _ ## op(void)       \
2830 fd4a04eb ths
{                                                      \
2831 fd4a04eb ths
    CALL_FROM_TB1(do_cmp ## _ ## fmt ## _ ## op, PARAM1); \
2832 fd4a04eb ths
    DEBUG_FPU_STATE();                                 \
2833 fd4a04eb ths
    RETURN();                                          \
2834 fd4a04eb ths
}                                                      \
2835 fd4a04eb ths
void OPPROTO op_cmpabs ## _ ## fmt ## _ ## op(void)    \
2836 fd4a04eb ths
{                                                      \
2837 fd4a04eb ths
    CALL_FROM_TB1(do_cmpabs ## _ ## fmt ## _ ## op, PARAM1); \
2838 fd4a04eb ths
    DEBUG_FPU_STATE();                                 \
2839 fd4a04eb ths
    RETURN();                                          \
2840 fd4a04eb ths
}
2841 fd4a04eb ths
#define CMP_OPS(op)   \
2842 fd4a04eb ths
CMP_OP(d, op)         \
2843 fd4a04eb ths
CMP_OP(s, op)         \
2844 fd4a04eb ths
CMP_OP(ps, op)
2845 fd4a04eb ths
2846 fd4a04eb ths
CMP_OPS(f)
2847 fd4a04eb ths
CMP_OPS(un)
2848 fd4a04eb ths
CMP_OPS(eq)
2849 fd4a04eb ths
CMP_OPS(ueq)
2850 fd4a04eb ths
CMP_OPS(olt)
2851 fd4a04eb ths
CMP_OPS(ult)
2852 fd4a04eb ths
CMP_OPS(ole)
2853 fd4a04eb ths
CMP_OPS(ule)
2854 fd4a04eb ths
CMP_OPS(sf)
2855 fd4a04eb ths
CMP_OPS(ngle)
2856 fd4a04eb ths
CMP_OPS(seq)
2857 fd4a04eb ths
CMP_OPS(ngl)
2858 fd4a04eb ths
CMP_OPS(lt)
2859 fd4a04eb ths
CMP_OPS(nge)
2860 fd4a04eb ths
CMP_OPS(le)
2861 fd4a04eb ths
CMP_OPS(ngt)
2862 fd4a04eb ths
#undef CMP_OPS
2863 fd4a04eb ths
#undef CMP_OP
2864 6ea83fed bellard
2865 6ea83fed bellard
void op_bc1f (void)
2866 6ea83fed bellard
{
2867 ead9360e ths
    T0 = !!(~GET_FP_COND(env->fpu) & (0x1 << PARAM1));
2868 5a5012ec ths
    DEBUG_FPU_STATE();
2869 5a5012ec ths
    RETURN();
2870 5a5012ec ths
}
2871 fd4a04eb ths
void op_bc1any2f (void)
2872 5a5012ec ths
{
2873 ead9360e ths
    T0 = !!(~GET_FP_COND(env->fpu) & (0x3 << PARAM1));
2874 5a5012ec ths
    DEBUG_FPU_STATE();
2875 5a5012ec ths
    RETURN();
2876 5a5012ec ths
}
2877 fd4a04eb ths
void op_bc1any4f (void)
2878 5a5012ec ths
{
2879 ead9360e ths
    T0 = !!(~GET_FP_COND(env->fpu) & (0xf << PARAM1));
2880 6ea83fed bellard
    DEBUG_FPU_STATE();
2881 6ea83fed bellard
    RETURN();
2882 6ea83fed bellard
}
2883 6ea83fed bellard
2884 6ea83fed bellard
void op_bc1t (void)
2885 6ea83fed bellard
{
2886 ead9360e ths
    T0 = !!(GET_FP_COND(env->fpu) & (0x1 << PARAM1));
2887 5a5012ec ths
    DEBUG_FPU_STATE();
2888 5a5012ec ths
    RETURN();
2889 5a5012ec ths
}
2890 fd4a04eb ths
void op_bc1any2t (void)
2891 5a5012ec ths
{
2892 ead9360e ths
    T0 = !!(GET_FP_COND(env->fpu) & (0x3 << PARAM1));
2893 5a5012ec ths
    DEBUG_FPU_STATE();
2894 5a5012ec ths
    RETURN();
2895 5a5012ec ths
}
2896 fd4a04eb ths
void op_bc1any4t (void)
2897 5a5012ec ths
{
2898 ead9360e ths
    T0 = !!(GET_FP_COND(env->fpu) & (0xf << PARAM1));
2899 6ea83fed bellard
    DEBUG_FPU_STATE();
2900 6ea83fed bellard
    RETURN();
2901 6ea83fed bellard
}
2902 6ea83fed bellard
2903 6af0bf9c bellard
void op_tlbwi (void)
2904 6af0bf9c bellard
{
2905 ead9360e ths
    CALL_FROM_TB0(env->tlb->do_tlbwi);
2906 6af0bf9c bellard
    RETURN();
2907 6af0bf9c bellard
}
2908 6af0bf9c bellard
2909 6af0bf9c bellard
void op_tlbwr (void)
2910 6af0bf9c bellard
{
2911 ead9360e ths
    CALL_FROM_TB0(env->tlb->do_tlbwr);
2912 6af0bf9c bellard
    RETURN();
2913 6af0bf9c bellard
}
2914 6af0bf9c bellard
2915 6af0bf9c bellard
void op_tlbp (void)
2916 6af0bf9c bellard
{
2917 ead9360e ths
    CALL_FROM_TB0(env->tlb->do_tlbp);
2918 6af0bf9c bellard
    RETURN();
2919 6af0bf9c bellard
}
2920 6af0bf9c bellard
2921 6af0bf9c bellard
void op_tlbr (void)
2922 6af0bf9c bellard
{
2923 ead9360e ths
    CALL_FROM_TB0(env->tlb->do_tlbr);
2924 6af0bf9c bellard
    RETURN();
2925 6af0bf9c bellard
}
2926 6af0bf9c bellard
2927 6af0bf9c bellard
/* Specials */
2928 6f5b89a0 ths
#if defined (CONFIG_USER_ONLY)
2929 6f5b89a0 ths
void op_tls_value (void)
2930 6f5b89a0 ths
{
2931 5a5012ec ths
    T0 = env->tls_value;
2932 6f5b89a0 ths
}
2933 6f5b89a0 ths
#endif
2934 6f5b89a0 ths
2935 6af0bf9c bellard
void op_pmon (void)
2936 6af0bf9c bellard
{
2937 6af0bf9c bellard
    CALL_FROM_TB1(do_pmon, PARAM1);
2938 7a387fff ths
    RETURN();
2939 7a387fff ths
}
2940 7a387fff ths
2941 7a387fff ths
void op_di (void)
2942 7a387fff ths
{
2943 7a387fff ths
    T0 = env->CP0_Status;
2944 4de9b249 ths
    env->CP0_Status = T0 & ~(1 << CP0St_IE);
2945 4de9b249 ths
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2946 7a387fff ths
    RETURN();
2947 7a387fff ths
}
2948 7a387fff ths
2949 7a387fff ths
void op_ei (void)
2950 7a387fff ths
{
2951 7a387fff ths
    T0 = env->CP0_Status;
2952 4de9b249 ths
    env->CP0_Status = T0 | (1 << CP0St_IE);
2953 4de9b249 ths
    CALL_FROM_TB1(cpu_mips_update_irq, env);
2954 7a387fff ths
    RETURN();
2955 6af0bf9c bellard
}
2956 6af0bf9c bellard
2957 6af0bf9c bellard
void op_trap (void)
2958 6af0bf9c bellard
{
2959 6af0bf9c bellard
    if (T0) {
2960 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_TRAP);
2961 6af0bf9c bellard
    }
2962 6af0bf9c bellard
    RETURN();
2963 6af0bf9c bellard
}
2964 6af0bf9c bellard
2965 4ad40f36 bellard
void op_debug (void)
2966 4ad40f36 bellard
{
2967 7a387fff ths
    CALL_FROM_TB1(do_raise_exception, EXCP_DEBUG);
2968 7a387fff ths
    RETURN();
2969 4ad40f36 bellard
}
2970 4ad40f36 bellard
2971 6af0bf9c bellard
void op_set_lladdr (void)
2972 6af0bf9c bellard
{
2973 6af0bf9c bellard
    env->CP0_LLAddr = T2;
2974 7a387fff ths
    RETURN();
2975 6af0bf9c bellard
}
2976 6af0bf9c bellard
2977 f41c52f1 ths
void debug_pre_eret (void);
2978 f41c52f1 ths
void debug_post_eret (void);
2979 6af0bf9c bellard
void op_eret (void)
2980 6af0bf9c bellard
{
2981 f41c52f1 ths
    if (loglevel & CPU_LOG_EXEC)
2982 f41c52f1 ths
        CALL_FROM_TB0(debug_pre_eret);
2983 24c7b0e3 ths
    if (env->CP0_Status & (1 << CP0St_ERL)) {
2984 ead9360e ths
        env->PC[env->current_tc] = env->CP0_ErrorEPC;
2985 24c7b0e3 ths
        env->CP0_Status &= ~(1 << CP0St_ERL);
2986 51e11d9e bellard
    } else {
2987 ead9360e ths
        env->PC[env->current_tc] = env->CP0_EPC;
2988 24c7b0e3 ths
        env->CP0_Status &= ~(1 << CP0St_EXL);
2989 51e11d9e bellard
    }
2990 08fa4bab ths
    CALL_FROM_TB1(compute_hflags, env);
2991 f41c52f1 ths
    if (loglevel & CPU_LOG_EXEC)
2992 f41c52f1 ths
        CALL_FROM_TB0(debug_post_eret);
2993 6af0bf9c bellard
    env->CP0_LLAddr = 1;
2994 7a387fff ths
    RETURN();
2995 6af0bf9c bellard
}
2996 6af0bf9c bellard
2997 6af0bf9c bellard
void op_deret (void)
2998 6af0bf9c bellard
{
2999 f41c52f1 ths
    if (loglevel & CPU_LOG_EXEC)
3000 f41c52f1 ths
        CALL_FROM_TB0(debug_pre_eret);
3001 ead9360e ths
    env->PC[env->current_tc] = env->CP0_DEPC;
3002 08fa4bab ths
    env->hflags &= MIPS_HFLAG_DM;
3003 08fa4bab ths
    CALL_FROM_TB1(compute_hflags, env);
3004 f41c52f1 ths
    if (loglevel & CPU_LOG_EXEC)
3005 f41c52f1 ths
        CALL_FROM_TB0(debug_post_eret);
3006 24c7b0e3 ths
    env->CP0_LLAddr = 1;
3007 7a387fff ths
    RETURN();
3008 7a387fff ths
}
3009 7a387fff ths
3010 7a387fff ths
void op_rdhwr_cpunum(void)
3011 7a387fff ths
{
3012 387a8fe5 ths
    if ((env->hflags & MIPS_HFLAG_CP0) ||
3013 387a8fe5 ths
        (env->CP0_HWREna & (1 << 0)))
3014 1579a72e ths
        T0 = env->CP0_EBase & 0x3ff;
3015 7a387fff ths
    else
3016 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3017 7a387fff ths
    RETURN();
3018 7a387fff ths
}
3019 7a387fff ths
3020 7a387fff ths
void op_rdhwr_synci_step(void)
3021 7a387fff ths
{
3022 387a8fe5 ths
    if ((env->hflags & MIPS_HFLAG_CP0) ||
3023 387a8fe5 ths
        (env->CP0_HWREna & (1 << 1)))
3024 1579a72e ths
        T0 = env->SYNCI_Step;
3025 7a387fff ths
    else
3026 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3027 7a387fff ths
    RETURN();
3028 7a387fff ths
}
3029 7a387fff ths
3030 7a387fff ths
void op_rdhwr_cc(void)
3031 7a387fff ths
{
3032 387a8fe5 ths
    if ((env->hflags & MIPS_HFLAG_CP0) ||
3033 387a8fe5 ths
        (env->CP0_HWREna & (1 << 2)))
3034 1579a72e ths
        T0 = env->CP0_Count;
3035 7a387fff ths
    else
3036 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3037 7a387fff ths
    RETURN();
3038 7a387fff ths
}
3039 7a387fff ths
3040 7a387fff ths
void op_rdhwr_ccres(void)
3041 7a387fff ths
{
3042 387a8fe5 ths
    if ((env->hflags & MIPS_HFLAG_CP0) ||
3043 387a8fe5 ths
        (env->CP0_HWREna & (1 << 3)))
3044 1579a72e ths
        T0 = env->CCRes;
3045 7a387fff ths
    else
3046 1579a72e ths
        CALL_FROM_TB1(do_raise_exception, EXCP_RI);
3047 1579a72e ths
    RETURN();
3048 1579a72e ths
}
3049 1579a72e ths
3050 6af0bf9c bellard
void op_save_state (void)
3051 6af0bf9c bellard
{
3052 6af0bf9c bellard
    env->hflags = PARAM1;
3053 6af0bf9c bellard
    RETURN();
3054 6af0bf9c bellard
}
3055 6af0bf9c bellard
3056 6af0bf9c bellard
void op_save_pc (void)
3057 6af0bf9c bellard
{
3058 ead9360e ths
    env->PC[env->current_tc] = PARAM1;
3059 6af0bf9c bellard
    RETURN();
3060 6af0bf9c bellard
}
3061 6af0bf9c bellard
3062 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
3063 9b9e4393 ths
void op_save_pc64 (void)
3064 9b9e4393 ths
{
3065 ead9360e ths
    env->PC[env->current_tc] = ((uint64_t)PARAM1 << 32) | (uint32_t)PARAM2;
3066 9b9e4393 ths
    RETURN();
3067 9b9e4393 ths
}
3068 9b9e4393 ths
#endif
3069 9b9e4393 ths
3070 16c00cb2 ths
void op_interrupt_restart (void)
3071 16c00cb2 ths
{
3072 16c00cb2 ths
    if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
3073 16c00cb2 ths
        !(env->CP0_Status & (1 << CP0St_ERL)) &&
3074 16c00cb2 ths
        !(env->hflags & MIPS_HFLAG_DM) &&
3075 16c00cb2 ths
        (env->CP0_Status & (1 << CP0St_IE)) &&
3076 16c00cb2 ths
        (env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask)) {
3077 16c00cb2 ths
        env->CP0_Cause &= ~(0x1f << CP0Ca_EC);
3078 16c00cb2 ths
        CALL_FROM_TB1(do_raise_exception, EXCP_EXT_INTERRUPT);
3079 16c00cb2 ths
    }
3080 16c00cb2 ths
    RETURN();
3081 16c00cb2 ths
}
3082 16c00cb2 ths
3083 6af0bf9c bellard
void op_raise_exception (void)
3084 6af0bf9c bellard
{
3085 6af0bf9c bellard
    CALL_FROM_TB1(do_raise_exception, PARAM1);
3086 6af0bf9c bellard
    RETURN();
3087 6af0bf9c bellard
}
3088 6af0bf9c bellard
3089 6af0bf9c bellard
void op_raise_exception_err (void)
3090 6af0bf9c bellard
{
3091 6af0bf9c bellard
    CALL_FROM_TB2(do_raise_exception_err, PARAM1, PARAM2);
3092 6af0bf9c bellard
    RETURN();
3093 6af0bf9c bellard
}
3094 6af0bf9c bellard
3095 6af0bf9c bellard
void op_exit_tb (void)
3096 6af0bf9c bellard
{
3097 6af0bf9c bellard
    EXIT_TB();
3098 7a387fff ths
    RETURN();
3099 6af0bf9c bellard
}
3100 6af0bf9c bellard
3101 4ad40f36 bellard
void op_wait (void)
3102 4ad40f36 bellard
{
3103 4ad40f36 bellard
    env->halted = 1;
3104 4ad40f36 bellard
    CALL_FROM_TB1(do_raise_exception, EXCP_HLT);
3105 7a387fff ths
    RETURN();
3106 7a387fff ths
}
3107 7a387fff ths
3108 7a387fff ths
/* Bitfield operations. */
3109 7a387fff ths
void op_ext(void)
3110 7a387fff ths
{
3111 7a387fff ths
    unsigned int pos = PARAM1;
3112 7a387fff ths
    unsigned int size = PARAM2;
3113 7a387fff ths
3114 f757d6ff ths
    T0 = ((uint32_t)T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
3115 7a387fff ths
    RETURN();
3116 7a387fff ths
}
3117 7a387fff ths
3118 7a387fff ths
void op_ins(void)
3119 7a387fff ths
{
3120 7a387fff ths
    unsigned int pos = PARAM1;
3121 7a387fff ths
    unsigned int size = PARAM2;
3122 f757d6ff ths
    target_ulong mask = ((size < 32) ? ((1 << size) - 1) : ~0) << pos;
3123 7a387fff ths
3124 171b31e7 ths
    T0 = (T0 & ~mask) | (((uint32_t)T1 << pos) & mask);
3125 7a387fff ths
    RETURN();
3126 7a387fff ths
}
3127 7a387fff ths
3128 7a387fff ths
void op_wsbh(void)
3129 7a387fff ths
{
3130 7a387fff ths
    T0 = ((T1 << 8) & ~0x00FF00FF) | ((T1 >> 8) & 0x00FF00FF);
3131 7a387fff ths
    RETURN();
3132 7a387fff ths
}
3133 7a387fff ths
3134 540635ba ths
#if defined(TARGET_MIPSN32) || defined(TARGET_MIPS64)
3135 c570fd16 ths
void op_dext(void)
3136 c570fd16 ths
{
3137 c570fd16 ths
    unsigned int pos = PARAM1;
3138 c570fd16 ths
    unsigned int size = PARAM2;
3139 c570fd16 ths
3140 f757d6ff ths
    T0 = (T1 >> pos) & ((size < 32) ? ((1 << size) - 1) : ~0);
3141 c570fd16 ths
    RETURN();
3142 c570fd16 ths
}
3143 c570fd16 ths
3144 c570fd16 ths
void op_dins(void)
3145 c570fd16 ths
{
3146 c570fd16 ths
    unsigned int pos = PARAM1;
3147 c570fd16 ths
    unsigned int size = PARAM2;
3148 f757d6ff ths
    target_ulong mask = ((size < 32) ? ((1 << size) - 1) : ~0) << pos;
3149 c570fd16 ths
3150 171b31e7 ths
    T0 = (T0 & ~mask) | ((T1 << pos) & mask);
3151 c570fd16 ths
    RETURN();
3152 c570fd16 ths
}
3153 c570fd16 ths
3154 7a387fff ths
void op_dsbh(void)
3155 7a387fff ths
{
3156 7a387fff ths
    T0 = ((T1 << 8) & ~0x00FF00FF00FF00FFULL) | ((T1 >> 8) & 0x00FF00FF00FF00FFULL);
3157 7a387fff ths
    RETURN();
3158 7a387fff ths
}
3159 7a387fff ths
3160 7a387fff ths
void op_dshd(void)
3161 7a387fff ths
{
3162 7a387fff ths
    T0 = ((T1 << 16) & ~0x0000FFFF0000FFFFULL) | ((T1 >> 16) & 0x0000FFFF0000FFFFULL);
3163 7a387fff ths
    RETURN();
3164 7a387fff ths
}
3165 c570fd16 ths
#endif
3166 7a387fff ths
3167 7a387fff ths
void op_seb(void)
3168 7a387fff ths
{
3169 7a387fff ths
    T0 = ((T1 & 0xFF) ^ 0x80) - 0x80;
3170 7a387fff ths
    RETURN();
3171 7a387fff ths
}
3172 7a387fff ths
3173 7a387fff ths
void op_seh(void)
3174 7a387fff ths
{
3175 7a387fff ths
    T0 = ((T1 & 0xFFFF) ^ 0x8000) - 0x8000;
3176 7a387fff ths
    RETURN();
3177 4ad40f36 bellard
}