blob: 27f58c2be12b56ab06e9d4f96b3b84b8f738d8ce [file] [log] [blame]
bellard6af0bf92005-07-02 14:58:51 +00001/*
2 * MIPS emulation helpers for qemu.
ths5fafdf22007-09-16 21:08:06 +00003 *
bellard6af0bf92005-07-02 14:58:51 +00004 * Copyright (c) 2004-2005 Jocelyn Mayer
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
ths2d0e9442007-04-02 15:54:05 +000020#include <stdlib.h>
bellard6af0bf92005-07-02 14:58:51 +000021#include "exec.h"
22
ths05f778c2007-10-27 13:05:54 +000023#include "host-utils.h"
24
pbrooka7812ae2008-11-17 14:43:54 +000025#include "helper.h"
bellard6af0bf92005-07-02 14:58:51 +000026/*****************************************************************************/
27/* Exceptions processing helpers */
bellard6af0bf92005-07-02 14:58:51 +000028
bellard6af0bf92005-07-02 14:58:51 +000029void do_raise_exception_err (uint32_t exception, int error_code)
30{
31#if 1
32 if (logfile && exception < 0x100)
33 fprintf(logfile, "%s: %d %d\n", __func__, exception, error_code);
34#endif
35 env->exception_index = exception;
36 env->error_code = error_code;
bellard6af0bf92005-07-02 14:58:51 +000037 cpu_loop_exit();
38}
39
bellard6af0bf92005-07-02 14:58:51 +000040void do_raise_exception (uint32_t exception)
41{
42 do_raise_exception_err(exception, 0);
43}
44
ths48d38ca2008-05-18 22:50:49 +000045void do_interrupt_restart (void)
46{
47 if (!(env->CP0_Status & (1 << CP0St_EXL)) &&
48 !(env->CP0_Status & (1 << CP0St_ERL)) &&
49 !(env->hflags & MIPS_HFLAG_DM) &&
50 (env->CP0_Status & (1 << CP0St_IE)) &&
51 (env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask)) {
52 env->CP0_Cause &= ~(0x1f << CP0Ca_EC);
53 do_raise_exception(EXCP_EXT_INTERRUPT);
54 }
55}
56
bellard4ad40f32005-12-05 19:59:36 +000057void do_restore_state (void *pc_ptr)
58{
bellarda6079222008-05-10 15:42:17 +000059 TranslationBlock *tb;
60 unsigned long pc = (unsigned long) pc_ptr;
61
62 tb = tb_find_pc (pc);
63 if (tb) {
64 cpu_restore_state (tb, env, pc, NULL);
65 }
bellard4ad40f32005-12-05 19:59:36 +000066}
67
thsbe24bb42008-06-23 12:57:09 +000068target_ulong do_clo (target_ulong t0)
ths30898802008-05-21 02:04:15 +000069{
thsbe24bb42008-06-23 12:57:09 +000070 return clo32(t0);
ths30898802008-05-21 02:04:15 +000071}
72
thsbe24bb42008-06-23 12:57:09 +000073target_ulong do_clz (target_ulong t0)
ths30898802008-05-21 02:04:15 +000074{
thsbe24bb42008-06-23 12:57:09 +000075 return clz32(t0);
ths30898802008-05-21 02:04:15 +000076}
77
thsd26bc212007-11-08 18:05:37 +000078#if defined(TARGET_MIPS64)
thsbe24bb42008-06-23 12:57:09 +000079target_ulong do_dclo (target_ulong t0)
thsc570fd12006-12-21 01:19:56 +000080{
thsbe24bb42008-06-23 12:57:09 +000081 return clo64(t0);
thsc570fd12006-12-21 01:19:56 +000082}
83
thsbe24bb42008-06-23 12:57:09 +000084target_ulong do_dclz (target_ulong t0)
thsc570fd12006-12-21 01:19:56 +000085{
thsbe24bb42008-06-23 12:57:09 +000086 return clz64(t0);
thsc570fd12006-12-21 01:19:56 +000087}
thsd26bc212007-11-08 18:05:37 +000088#endif /* TARGET_MIPS64 */
thsc570fd12006-12-21 01:19:56 +000089
bellard6af0bf92005-07-02 14:58:51 +000090/* 64 bits arithmetic for 32 bits hosts */
thsc904ef02008-07-23 16:16:31 +000091static inline uint64_t get_HILO (void)
bellard6af0bf92005-07-02 14:58:51 +000092{
thsb5dc7732008-06-27 10:02:35 +000093 return ((uint64_t)(env->active_tc.HI[0]) << 32) | (uint32_t)env->active_tc.LO[0];
bellard6af0bf92005-07-02 14:58:51 +000094}
95
thsc904ef02008-07-23 16:16:31 +000096static inline void set_HILO (uint64_t HILO)
bellard6af0bf92005-07-02 14:58:51 +000097{
thsb5dc7732008-06-27 10:02:35 +000098 env->active_tc.LO[0] = (int32_t)HILO;
99 env->active_tc.HI[0] = (int32_t)(HILO >> 32);
bellard6af0bf92005-07-02 14:58:51 +0000100}
101
thsc904ef02008-07-23 16:16:31 +0000102static inline void set_HIT0_LO (target_ulong t0, uint64_t HILO)
thse9c71dd2007-12-25 20:46:56 +0000103{
thsb5dc7732008-06-27 10:02:35 +0000104 env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
105 t0 = env->active_tc.HI[0] = (int32_t)(HILO >> 32);
thse9c71dd2007-12-25 20:46:56 +0000106}
107
thsc904ef02008-07-23 16:16:31 +0000108static inline void set_HI_LOT0 (target_ulong t0, uint64_t HILO)
thse9c71dd2007-12-25 20:46:56 +0000109{
thsb5dc7732008-06-27 10:02:35 +0000110 t0 = env->active_tc.LO[0] = (int32_t)(HILO & 0xFFFFFFFF);
111 env->active_tc.HI[0] = (int32_t)(HILO >> 32);
thse9c71dd2007-12-25 20:46:56 +0000112}
113
ths92af06d2008-06-20 14:35:19 +0000114#if TARGET_LONG_BITS > HOST_LONG_BITS
thsbe24bb42008-06-23 12:57:09 +0000115void do_madd (target_ulong t0, target_ulong t1)
bellard6af0bf92005-07-02 14:58:51 +0000116{
117 int64_t tmp;
118
thsbe24bb42008-06-23 12:57:09 +0000119 tmp = ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
bellard6af0bf92005-07-02 14:58:51 +0000120 set_HILO((int64_t)get_HILO() + tmp);
121}
122
thsbe24bb42008-06-23 12:57:09 +0000123void do_maddu (target_ulong t0, target_ulong t1)
bellard6af0bf92005-07-02 14:58:51 +0000124{
125 uint64_t tmp;
126
thsbe24bb42008-06-23 12:57:09 +0000127 tmp = ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
bellard6af0bf92005-07-02 14:58:51 +0000128 set_HILO(get_HILO() + tmp);
129}
130
thsbe24bb42008-06-23 12:57:09 +0000131void do_msub (target_ulong t0, target_ulong t1)
bellard6af0bf92005-07-02 14:58:51 +0000132{
133 int64_t tmp;
134
thsbe24bb42008-06-23 12:57:09 +0000135 tmp = ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
bellard6af0bf92005-07-02 14:58:51 +0000136 set_HILO((int64_t)get_HILO() - tmp);
137}
138
thsbe24bb42008-06-23 12:57:09 +0000139void do_msubu (target_ulong t0, target_ulong t1)
bellard6af0bf92005-07-02 14:58:51 +0000140{
141 uint64_t tmp;
142
thsbe24bb42008-06-23 12:57:09 +0000143 tmp = ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
bellard6af0bf92005-07-02 14:58:51 +0000144 set_HILO(get_HILO() - tmp);
145}
ths92af06d2008-06-20 14:35:19 +0000146#endif /* TARGET_LONG_BITS > HOST_LONG_BITS */
thse9c71dd2007-12-25 20:46:56 +0000147
148/* Multiplication variants of the vr54xx. */
thsbe24bb42008-06-23 12:57:09 +0000149target_ulong do_muls (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000150{
thsbe24bb42008-06-23 12:57:09 +0000151 set_HI_LOT0(t0, 0 - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
152
153 return t0;
thse9c71dd2007-12-25 20:46:56 +0000154}
155
thsbe24bb42008-06-23 12:57:09 +0000156target_ulong do_mulsu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000157{
thsbe24bb42008-06-23 12:57:09 +0000158 set_HI_LOT0(t0, 0 - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
159
160 return t0;
thse9c71dd2007-12-25 20:46:56 +0000161}
162
thsbe24bb42008-06-23 12:57:09 +0000163target_ulong do_macc (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000164{
thsbe24bb42008-06-23 12:57:09 +0000165 set_HI_LOT0(t0, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
166
167 return t0;
thse9c71dd2007-12-25 20:46:56 +0000168}
169
thsbe24bb42008-06-23 12:57:09 +0000170target_ulong do_macchi (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000171{
thsbe24bb42008-06-23 12:57:09 +0000172 set_HIT0_LO(t0, ((int64_t)get_HILO()) + ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
173
174 return t0;
thse9c71dd2007-12-25 20:46:56 +0000175}
176
thsbe24bb42008-06-23 12:57:09 +0000177target_ulong do_maccu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000178{
thsbe24bb42008-06-23 12:57:09 +0000179 set_HI_LOT0(t0, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
180
181 return t0;
thse9c71dd2007-12-25 20:46:56 +0000182}
183
thsbe24bb42008-06-23 12:57:09 +0000184target_ulong do_macchiu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000185{
thsbe24bb42008-06-23 12:57:09 +0000186 set_HIT0_LO(t0, ((uint64_t)get_HILO()) + ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
187
188 return t0;
thse9c71dd2007-12-25 20:46:56 +0000189}
190
thsbe24bb42008-06-23 12:57:09 +0000191target_ulong do_msac (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000192{
thsbe24bb42008-06-23 12:57:09 +0000193 set_HI_LOT0(t0, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
194
195 return t0;
thse9c71dd2007-12-25 20:46:56 +0000196}
197
thsbe24bb42008-06-23 12:57:09 +0000198target_ulong do_msachi (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000199{
thsbe24bb42008-06-23 12:57:09 +0000200 set_HIT0_LO(t0, ((int64_t)get_HILO()) - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
201
202 return t0;
thse9c71dd2007-12-25 20:46:56 +0000203}
204
thsbe24bb42008-06-23 12:57:09 +0000205target_ulong do_msacu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000206{
thsbe24bb42008-06-23 12:57:09 +0000207 set_HI_LOT0(t0, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
208
209 return t0;
thse9c71dd2007-12-25 20:46:56 +0000210}
211
thsbe24bb42008-06-23 12:57:09 +0000212target_ulong do_msachiu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000213{
thsbe24bb42008-06-23 12:57:09 +0000214 set_HIT0_LO(t0, ((uint64_t)get_HILO()) - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
215
216 return t0;
thse9c71dd2007-12-25 20:46:56 +0000217}
218
thsbe24bb42008-06-23 12:57:09 +0000219target_ulong do_mulhi (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000220{
thsbe24bb42008-06-23 12:57:09 +0000221 set_HIT0_LO(t0, (int64_t)(int32_t)t0 * (int64_t)(int32_t)t1);
222
223 return t0;
thse9c71dd2007-12-25 20:46:56 +0000224}
225
thsbe24bb42008-06-23 12:57:09 +0000226target_ulong do_mulhiu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000227{
thsbe24bb42008-06-23 12:57:09 +0000228 set_HIT0_LO(t0, (uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1);
229
230 return t0;
thse9c71dd2007-12-25 20:46:56 +0000231}
232
thsbe24bb42008-06-23 12:57:09 +0000233target_ulong do_mulshi (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000234{
thsbe24bb42008-06-23 12:57:09 +0000235 set_HIT0_LO(t0, 0 - ((int64_t)(int32_t)t0 * (int64_t)(int32_t)t1));
236
237 return t0;
thse9c71dd2007-12-25 20:46:56 +0000238}
239
thsbe24bb42008-06-23 12:57:09 +0000240target_ulong do_mulshiu (target_ulong t0, target_ulong t1)
thse9c71dd2007-12-25 20:46:56 +0000241{
thsbe24bb42008-06-23 12:57:09 +0000242 set_HIT0_LO(t0, 0 - ((uint64_t)(uint32_t)t0 * (uint64_t)(uint32_t)t1));
243
244 return t0;
thse9c71dd2007-12-25 20:46:56 +0000245}
bellard6af0bf92005-07-02 14:58:51 +0000246
ths214c4652008-06-12 12:43:29 +0000247#ifdef TARGET_MIPS64
thsbe24bb42008-06-23 12:57:09 +0000248void do_dmult (target_ulong t0, target_ulong t1)
ths214c4652008-06-12 12:43:29 +0000249{
thsb5dc7732008-06-27 10:02:35 +0000250 muls64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), t0, t1);
ths214c4652008-06-12 12:43:29 +0000251}
252
thsbe24bb42008-06-23 12:57:09 +0000253void do_dmultu (target_ulong t0, target_ulong t1)
ths214c4652008-06-12 12:43:29 +0000254{
thsb5dc7732008-06-27 10:02:35 +0000255 mulu64(&(env->active_tc.LO[0]), &(env->active_tc.HI[0]), t0, t1);
ths214c4652008-06-12 12:43:29 +0000256}
257#endif
258
thsc8c22272008-06-20 15:12:14 +0000259#ifdef TARGET_WORDS_BIGENDIAN
260#define GET_LMASK(v) ((v) & 3)
261#define GET_OFFSET(addr, offset) (addr + (offset))
262#else
263#define GET_LMASK(v) (((v) & 3) ^ 3)
264#define GET_OFFSET(addr, offset) (addr - (offset))
265#endif
266
thsbe24bb42008-06-23 12:57:09 +0000267target_ulong do_lwl(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000268{
269 target_ulong tmp;
270
271#ifdef CONFIG_USER_ONLY
272#define ldfun ldub_raw
273#else
274 int (*ldfun)(target_ulong);
275
276 switch (mem_idx)
277 {
278 case 0: ldfun = ldub_kernel; break;
279 case 1: ldfun = ldub_super; break;
280 default:
281 case 2: ldfun = ldub_user; break;
282 }
283#endif
thsbe24bb42008-06-23 12:57:09 +0000284 tmp = ldfun(t0);
285 t1 = (t1 & 0x00FFFFFF) | (tmp << 24);
thsc8c22272008-06-20 15:12:14 +0000286
thsbe24bb42008-06-23 12:57:09 +0000287 if (GET_LMASK(t0) <= 2) {
288 tmp = ldfun(GET_OFFSET(t0, 1));
289 t1 = (t1 & 0xFF00FFFF) | (tmp << 16);
thsc8c22272008-06-20 15:12:14 +0000290 }
291
thsbe24bb42008-06-23 12:57:09 +0000292 if (GET_LMASK(t0) <= 1) {
293 tmp = ldfun(GET_OFFSET(t0, 2));
294 t1 = (t1 & 0xFFFF00FF) | (tmp << 8);
thsc8c22272008-06-20 15:12:14 +0000295 }
296
thsbe24bb42008-06-23 12:57:09 +0000297 if (GET_LMASK(t0) == 0) {
298 tmp = ldfun(GET_OFFSET(t0, 3));
299 t1 = (t1 & 0xFFFFFF00) | tmp;
thsc8c22272008-06-20 15:12:14 +0000300 }
thsbe24bb42008-06-23 12:57:09 +0000301 return (int32_t)t1;
thsc8c22272008-06-20 15:12:14 +0000302}
303
thsbe24bb42008-06-23 12:57:09 +0000304target_ulong do_lwr(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000305{
306 target_ulong tmp;
307
308#ifdef CONFIG_USER_ONLY
309#define ldfun ldub_raw
310#else
311 int (*ldfun)(target_ulong);
312
313 switch (mem_idx)
314 {
315 case 0: ldfun = ldub_kernel; break;
316 case 1: ldfun = ldub_super; break;
317 default:
318 case 2: ldfun = ldub_user; break;
319 }
320#endif
thsbe24bb42008-06-23 12:57:09 +0000321 tmp = ldfun(t0);
322 t1 = (t1 & 0xFFFFFF00) | tmp;
thsc8c22272008-06-20 15:12:14 +0000323
thsbe24bb42008-06-23 12:57:09 +0000324 if (GET_LMASK(t0) >= 1) {
325 tmp = ldfun(GET_OFFSET(t0, -1));
326 t1 = (t1 & 0xFFFF00FF) | (tmp << 8);
thsc8c22272008-06-20 15:12:14 +0000327 }
328
thsbe24bb42008-06-23 12:57:09 +0000329 if (GET_LMASK(t0) >= 2) {
330 tmp = ldfun(GET_OFFSET(t0, -2));
331 t1 = (t1 & 0xFF00FFFF) | (tmp << 16);
thsc8c22272008-06-20 15:12:14 +0000332 }
333
thsbe24bb42008-06-23 12:57:09 +0000334 if (GET_LMASK(t0) == 3) {
335 tmp = ldfun(GET_OFFSET(t0, -3));
336 t1 = (t1 & 0x00FFFFFF) | (tmp << 24);
thsc8c22272008-06-20 15:12:14 +0000337 }
thsbe24bb42008-06-23 12:57:09 +0000338 return (int32_t)t1;
thsc8c22272008-06-20 15:12:14 +0000339}
340
thsbe24bb42008-06-23 12:57:09 +0000341void do_swl(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000342{
343#ifdef CONFIG_USER_ONLY
344#define stfun stb_raw
345#else
346 void (*stfun)(target_ulong, int);
347
348 switch (mem_idx)
349 {
350 case 0: stfun = stb_kernel; break;
351 case 1: stfun = stb_super; break;
352 default:
353 case 2: stfun = stb_user; break;
354 }
355#endif
thsbe24bb42008-06-23 12:57:09 +0000356 stfun(t0, (uint8_t)(t1 >> 24));
thsc8c22272008-06-20 15:12:14 +0000357
thsbe24bb42008-06-23 12:57:09 +0000358 if (GET_LMASK(t0) <= 2)
359 stfun(GET_OFFSET(t0, 1), (uint8_t)(t1 >> 16));
thsc8c22272008-06-20 15:12:14 +0000360
thsbe24bb42008-06-23 12:57:09 +0000361 if (GET_LMASK(t0) <= 1)
362 stfun(GET_OFFSET(t0, 2), (uint8_t)(t1 >> 8));
thsc8c22272008-06-20 15:12:14 +0000363
thsbe24bb42008-06-23 12:57:09 +0000364 if (GET_LMASK(t0) == 0)
365 stfun(GET_OFFSET(t0, 3), (uint8_t)t1);
thsc8c22272008-06-20 15:12:14 +0000366}
367
thsbe24bb42008-06-23 12:57:09 +0000368void do_swr(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000369{
370#ifdef CONFIG_USER_ONLY
371#define stfun stb_raw
372#else
373 void (*stfun)(target_ulong, int);
374
375 switch (mem_idx)
376 {
377 case 0: stfun = stb_kernel; break;
378 case 1: stfun = stb_super; break;
379 default:
380 case 2: stfun = stb_user; break;
381 }
382#endif
thsbe24bb42008-06-23 12:57:09 +0000383 stfun(t0, (uint8_t)t1);
thsc8c22272008-06-20 15:12:14 +0000384
thsbe24bb42008-06-23 12:57:09 +0000385 if (GET_LMASK(t0) >= 1)
386 stfun(GET_OFFSET(t0, -1), (uint8_t)(t1 >> 8));
thsc8c22272008-06-20 15:12:14 +0000387
thsbe24bb42008-06-23 12:57:09 +0000388 if (GET_LMASK(t0) >= 2)
389 stfun(GET_OFFSET(t0, -2), (uint8_t)(t1 >> 16));
thsc8c22272008-06-20 15:12:14 +0000390
thsbe24bb42008-06-23 12:57:09 +0000391 if (GET_LMASK(t0) == 3)
392 stfun(GET_OFFSET(t0, -3), (uint8_t)(t1 >> 24));
thsc8c22272008-06-20 15:12:14 +0000393}
394
395#if defined(TARGET_MIPS64)
396/* "half" load and stores. We must do the memory access inline,
397 or fault handling won't work. */
398
399#ifdef TARGET_WORDS_BIGENDIAN
400#define GET_LMASK64(v) ((v) & 7)
401#else
402#define GET_LMASK64(v) (((v) & 7) ^ 7)
403#endif
404
thsbe24bb42008-06-23 12:57:09 +0000405target_ulong do_ldl(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000406{
407 uint64_t tmp;
408
409#ifdef CONFIG_USER_ONLY
410#define ldfun ldub_raw
411#else
thsbe24bb42008-06-23 12:57:09 +0000412 int (*ldfun)(target_ulong);
thsc8c22272008-06-20 15:12:14 +0000413
414 switch (mem_idx)
415 {
416 case 0: ldfun = ldub_kernel; break;
417 case 1: ldfun = ldub_super; break;
418 default:
419 case 2: ldfun = ldub_user; break;
420 }
421#endif
thsbe24bb42008-06-23 12:57:09 +0000422 tmp = ldfun(t0);
423 t1 = (t1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
thsc8c22272008-06-20 15:12:14 +0000424
thsbe24bb42008-06-23 12:57:09 +0000425 if (GET_LMASK64(t0) <= 6) {
426 tmp = ldfun(GET_OFFSET(t0, 1));
427 t1 = (t1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
thsc8c22272008-06-20 15:12:14 +0000428 }
429
thsbe24bb42008-06-23 12:57:09 +0000430 if (GET_LMASK64(t0) <= 5) {
431 tmp = ldfun(GET_OFFSET(t0, 2));
432 t1 = (t1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
thsc8c22272008-06-20 15:12:14 +0000433 }
434
thsbe24bb42008-06-23 12:57:09 +0000435 if (GET_LMASK64(t0) <= 4) {
436 tmp = ldfun(GET_OFFSET(t0, 3));
437 t1 = (t1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
thsc8c22272008-06-20 15:12:14 +0000438 }
439
thsbe24bb42008-06-23 12:57:09 +0000440 if (GET_LMASK64(t0) <= 3) {
441 tmp = ldfun(GET_OFFSET(t0, 4));
442 t1 = (t1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
thsc8c22272008-06-20 15:12:14 +0000443 }
444
thsbe24bb42008-06-23 12:57:09 +0000445 if (GET_LMASK64(t0) <= 2) {
446 tmp = ldfun(GET_OFFSET(t0, 5));
447 t1 = (t1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
thsc8c22272008-06-20 15:12:14 +0000448 }
449
thsbe24bb42008-06-23 12:57:09 +0000450 if (GET_LMASK64(t0) <= 1) {
451 tmp = ldfun(GET_OFFSET(t0, 6));
452 t1 = (t1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
thsc8c22272008-06-20 15:12:14 +0000453 }
454
thsbe24bb42008-06-23 12:57:09 +0000455 if (GET_LMASK64(t0) == 0) {
456 tmp = ldfun(GET_OFFSET(t0, 7));
457 t1 = (t1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
thsc8c22272008-06-20 15:12:14 +0000458 }
thsbe24bb42008-06-23 12:57:09 +0000459
460 return t1;
thsc8c22272008-06-20 15:12:14 +0000461}
462
thsbe24bb42008-06-23 12:57:09 +0000463target_ulong do_ldr(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000464{
465 uint64_t tmp;
466
467#ifdef CONFIG_USER_ONLY
468#define ldfun ldub_raw
469#else
thsbe24bb42008-06-23 12:57:09 +0000470 int (*ldfun)(target_ulong);
thsc8c22272008-06-20 15:12:14 +0000471
472 switch (mem_idx)
473 {
474 case 0: ldfun = ldub_kernel; break;
475 case 1: ldfun = ldub_super; break;
476 default:
477 case 2: ldfun = ldub_user; break;
478 }
479#endif
thsbe24bb42008-06-23 12:57:09 +0000480 tmp = ldfun(t0);
481 t1 = (t1 & 0xFFFFFFFFFFFFFF00ULL) | tmp;
thsc8c22272008-06-20 15:12:14 +0000482
thsbe24bb42008-06-23 12:57:09 +0000483 if (GET_LMASK64(t0) >= 1) {
484 tmp = ldfun(GET_OFFSET(t0, -1));
485 t1 = (t1 & 0xFFFFFFFFFFFF00FFULL) | (tmp << 8);
thsc8c22272008-06-20 15:12:14 +0000486 }
487
thsbe24bb42008-06-23 12:57:09 +0000488 if (GET_LMASK64(t0) >= 2) {
489 tmp = ldfun(GET_OFFSET(t0, -2));
490 t1 = (t1 & 0xFFFFFFFFFF00FFFFULL) | (tmp << 16);
thsc8c22272008-06-20 15:12:14 +0000491 }
492
thsbe24bb42008-06-23 12:57:09 +0000493 if (GET_LMASK64(t0) >= 3) {
494 tmp = ldfun(GET_OFFSET(t0, -3));
495 t1 = (t1 & 0xFFFFFFFF00FFFFFFULL) | (tmp << 24);
thsc8c22272008-06-20 15:12:14 +0000496 }
497
thsbe24bb42008-06-23 12:57:09 +0000498 if (GET_LMASK64(t0) >= 4) {
499 tmp = ldfun(GET_OFFSET(t0, -4));
500 t1 = (t1 & 0xFFFFFF00FFFFFFFFULL) | (tmp << 32);
thsc8c22272008-06-20 15:12:14 +0000501 }
502
thsbe24bb42008-06-23 12:57:09 +0000503 if (GET_LMASK64(t0) >= 5) {
504 tmp = ldfun(GET_OFFSET(t0, -5));
505 t1 = (t1 & 0xFFFF00FFFFFFFFFFULL) | (tmp << 40);
thsc8c22272008-06-20 15:12:14 +0000506 }
507
thsbe24bb42008-06-23 12:57:09 +0000508 if (GET_LMASK64(t0) >= 6) {
509 tmp = ldfun(GET_OFFSET(t0, -6));
510 t1 = (t1 & 0xFF00FFFFFFFFFFFFULL) | (tmp << 48);
thsc8c22272008-06-20 15:12:14 +0000511 }
512
thsbe24bb42008-06-23 12:57:09 +0000513 if (GET_LMASK64(t0) == 7) {
514 tmp = ldfun(GET_OFFSET(t0, -7));
515 t1 = (t1 & 0x00FFFFFFFFFFFFFFULL) | (tmp << 56);
thsc8c22272008-06-20 15:12:14 +0000516 }
thsbe24bb42008-06-23 12:57:09 +0000517
518 return t1;
thsc8c22272008-06-20 15:12:14 +0000519}
520
thsbe24bb42008-06-23 12:57:09 +0000521void do_sdl(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000522{
523#ifdef CONFIG_USER_ONLY
524#define stfun stb_raw
525#else
526 void (*stfun)(target_ulong, int);
527
528 switch (mem_idx)
529 {
530 case 0: stfun = stb_kernel; break;
531 case 1: stfun = stb_super; break;
532 default:
533 case 2: stfun = stb_user; break;
534 }
535#endif
thsbe24bb42008-06-23 12:57:09 +0000536 stfun(t0, (uint8_t)(t1 >> 56));
thsc8c22272008-06-20 15:12:14 +0000537
thsbe24bb42008-06-23 12:57:09 +0000538 if (GET_LMASK64(t0) <= 6)
539 stfun(GET_OFFSET(t0, 1), (uint8_t)(t1 >> 48));
thsc8c22272008-06-20 15:12:14 +0000540
thsbe24bb42008-06-23 12:57:09 +0000541 if (GET_LMASK64(t0) <= 5)
542 stfun(GET_OFFSET(t0, 2), (uint8_t)(t1 >> 40));
thsc8c22272008-06-20 15:12:14 +0000543
thsbe24bb42008-06-23 12:57:09 +0000544 if (GET_LMASK64(t0) <= 4)
545 stfun(GET_OFFSET(t0, 3), (uint8_t)(t1 >> 32));
thsc8c22272008-06-20 15:12:14 +0000546
thsbe24bb42008-06-23 12:57:09 +0000547 if (GET_LMASK64(t0) <= 3)
548 stfun(GET_OFFSET(t0, 4), (uint8_t)(t1 >> 24));
thsc8c22272008-06-20 15:12:14 +0000549
thsbe24bb42008-06-23 12:57:09 +0000550 if (GET_LMASK64(t0) <= 2)
551 stfun(GET_OFFSET(t0, 5), (uint8_t)(t1 >> 16));
thsc8c22272008-06-20 15:12:14 +0000552
thsbe24bb42008-06-23 12:57:09 +0000553 if (GET_LMASK64(t0) <= 1)
554 stfun(GET_OFFSET(t0, 6), (uint8_t)(t1 >> 8));
thsc8c22272008-06-20 15:12:14 +0000555
thsbe24bb42008-06-23 12:57:09 +0000556 if (GET_LMASK64(t0) <= 0)
557 stfun(GET_OFFSET(t0, 7), (uint8_t)t1);
thsc8c22272008-06-20 15:12:14 +0000558}
559
thsbe24bb42008-06-23 12:57:09 +0000560void do_sdr(target_ulong t0, target_ulong t1, int mem_idx)
thsc8c22272008-06-20 15:12:14 +0000561{
562#ifdef CONFIG_USER_ONLY
563#define stfun stb_raw
564#else
565 void (*stfun)(target_ulong, int);
566
567 switch (mem_idx)
568 {
569 case 0: stfun = stb_kernel; break;
570 case 1: stfun = stb_super; break;
571 default:
572 case 2: stfun = stb_user; break;
573 }
574#endif
thsbe24bb42008-06-23 12:57:09 +0000575 stfun(t0, (uint8_t)t1);
thsc8c22272008-06-20 15:12:14 +0000576
thsbe24bb42008-06-23 12:57:09 +0000577 if (GET_LMASK64(t0) >= 1)
578 stfun(GET_OFFSET(t0, -1), (uint8_t)(t1 >> 8));
thsc8c22272008-06-20 15:12:14 +0000579
thsbe24bb42008-06-23 12:57:09 +0000580 if (GET_LMASK64(t0) >= 2)
581 stfun(GET_OFFSET(t0, -2), (uint8_t)(t1 >> 16));
thsc8c22272008-06-20 15:12:14 +0000582
thsbe24bb42008-06-23 12:57:09 +0000583 if (GET_LMASK64(t0) >= 3)
584 stfun(GET_OFFSET(t0, -3), (uint8_t)(t1 >> 24));
thsc8c22272008-06-20 15:12:14 +0000585
thsbe24bb42008-06-23 12:57:09 +0000586 if (GET_LMASK64(t0) >= 4)
587 stfun(GET_OFFSET(t0, -4), (uint8_t)(t1 >> 32));
thsc8c22272008-06-20 15:12:14 +0000588
thsbe24bb42008-06-23 12:57:09 +0000589 if (GET_LMASK64(t0) >= 5)
590 stfun(GET_OFFSET(t0, -5), (uint8_t)(t1 >> 40));
thsc8c22272008-06-20 15:12:14 +0000591
thsbe24bb42008-06-23 12:57:09 +0000592 if (GET_LMASK64(t0) >= 6)
593 stfun(GET_OFFSET(t0, -6), (uint8_t)(t1 >> 48));
thsc8c22272008-06-20 15:12:14 +0000594
thsbe24bb42008-06-23 12:57:09 +0000595 if (GET_LMASK64(t0) == 7)
596 stfun(GET_OFFSET(t0, -7), (uint8_t)(t1 >> 56));
thsc8c22272008-06-20 15:12:14 +0000597}
598#endif /* TARGET_MIPS64 */
599
ths0eaef5a2008-07-23 16:14:22 +0000600#ifndef CONFIG_USER_ONLY
bellard6af0bf92005-07-02 14:58:51 +0000601/* CP0 helpers */
ths1a3fd9c2008-06-24 21:58:35 +0000602target_ulong do_mfc0_mvpcontrol (void)
thsf1aa6322008-06-09 07:13:38 +0000603{
thsbe24bb42008-06-23 12:57:09 +0000604 return env->mvp->CP0_MVPControl;
thsf1aa6322008-06-09 07:13:38 +0000605}
606
ths1a3fd9c2008-06-24 21:58:35 +0000607target_ulong do_mfc0_mvpconf0 (void)
thsf1aa6322008-06-09 07:13:38 +0000608{
thsbe24bb42008-06-23 12:57:09 +0000609 return env->mvp->CP0_MVPConf0;
thsf1aa6322008-06-09 07:13:38 +0000610}
611
ths1a3fd9c2008-06-24 21:58:35 +0000612target_ulong do_mfc0_mvpconf1 (void)
thsf1aa6322008-06-09 07:13:38 +0000613{
thsbe24bb42008-06-23 12:57:09 +0000614 return env->mvp->CP0_MVPConf1;
thsf1aa6322008-06-09 07:13:38 +0000615}
616
ths1a3fd9c2008-06-24 21:58:35 +0000617target_ulong do_mfc0_random (void)
bellard6af0bf92005-07-02 14:58:51 +0000618{
thsbe24bb42008-06-23 12:57:09 +0000619 return (int32_t)cpu_mips_get_random(env);
ths873eb012006-12-06 17:59:07 +0000620}
bellard6af0bf92005-07-02 14:58:51 +0000621
ths1a3fd9c2008-06-24 21:58:35 +0000622target_ulong do_mfc0_tcstatus (void)
thsf1aa6322008-06-09 07:13:38 +0000623{
thsb5dc7732008-06-27 10:02:35 +0000624 return env->active_tc.CP0_TCStatus;
thsf1aa6322008-06-09 07:13:38 +0000625}
626
ths1a3fd9c2008-06-24 21:58:35 +0000627target_ulong do_mftc0_tcstatus(void)
thsf1aa6322008-06-09 07:13:38 +0000628{
629 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
630
thsb5dc7732008-06-27 10:02:35 +0000631 if (other_tc == env->current_tc)
632 return env->active_tc.CP0_TCStatus;
633 else
634 return env->tcs[other_tc].CP0_TCStatus;
thsf1aa6322008-06-09 07:13:38 +0000635}
636
ths1a3fd9c2008-06-24 21:58:35 +0000637target_ulong do_mfc0_tcbind (void)
thsf1aa6322008-06-09 07:13:38 +0000638{
thsb5dc7732008-06-27 10:02:35 +0000639 return env->active_tc.CP0_TCBind;
thsf1aa6322008-06-09 07:13:38 +0000640}
641
ths1a3fd9c2008-06-24 21:58:35 +0000642target_ulong do_mftc0_tcbind(void)
thsf1aa6322008-06-09 07:13:38 +0000643{
644 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
645
thsb5dc7732008-06-27 10:02:35 +0000646 if (other_tc == env->current_tc)
647 return env->active_tc.CP0_TCBind;
648 else
649 return env->tcs[other_tc].CP0_TCBind;
thsf1aa6322008-06-09 07:13:38 +0000650}
651
ths1a3fd9c2008-06-24 21:58:35 +0000652target_ulong do_mfc0_tcrestart (void)
thsf1aa6322008-06-09 07:13:38 +0000653{
thsb5dc7732008-06-27 10:02:35 +0000654 return env->active_tc.PC;
thsf1aa6322008-06-09 07:13:38 +0000655}
656
ths1a3fd9c2008-06-24 21:58:35 +0000657target_ulong do_mftc0_tcrestart(void)
thsf1aa6322008-06-09 07:13:38 +0000658{
659 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
660
thsb5dc7732008-06-27 10:02:35 +0000661 if (other_tc == env->current_tc)
662 return env->active_tc.PC;
663 else
664 return env->tcs[other_tc].PC;
thsf1aa6322008-06-09 07:13:38 +0000665}
666
ths1a3fd9c2008-06-24 21:58:35 +0000667target_ulong do_mfc0_tchalt (void)
thsf1aa6322008-06-09 07:13:38 +0000668{
thsb5dc7732008-06-27 10:02:35 +0000669 return env->active_tc.CP0_TCHalt;
thsf1aa6322008-06-09 07:13:38 +0000670}
671
ths1a3fd9c2008-06-24 21:58:35 +0000672target_ulong do_mftc0_tchalt(void)
thsf1aa6322008-06-09 07:13:38 +0000673{
674 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
675
thsb5dc7732008-06-27 10:02:35 +0000676 if (other_tc == env->current_tc)
677 return env->active_tc.CP0_TCHalt;
678 else
679 return env->tcs[other_tc].CP0_TCHalt;
thsf1aa6322008-06-09 07:13:38 +0000680}
681
ths1a3fd9c2008-06-24 21:58:35 +0000682target_ulong do_mfc0_tccontext (void)
thsf1aa6322008-06-09 07:13:38 +0000683{
thsb5dc7732008-06-27 10:02:35 +0000684 return env->active_tc.CP0_TCContext;
thsf1aa6322008-06-09 07:13:38 +0000685}
686
ths1a3fd9c2008-06-24 21:58:35 +0000687target_ulong do_mftc0_tccontext(void)
thsf1aa6322008-06-09 07:13:38 +0000688{
689 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
690
thsb5dc7732008-06-27 10:02:35 +0000691 if (other_tc == env->current_tc)
692 return env->active_tc.CP0_TCContext;
693 else
694 return env->tcs[other_tc].CP0_TCContext;
thsf1aa6322008-06-09 07:13:38 +0000695}
696
ths1a3fd9c2008-06-24 21:58:35 +0000697target_ulong do_mfc0_tcschedule (void)
thsf1aa6322008-06-09 07:13:38 +0000698{
thsb5dc7732008-06-27 10:02:35 +0000699 return env->active_tc.CP0_TCSchedule;
thsf1aa6322008-06-09 07:13:38 +0000700}
701
ths1a3fd9c2008-06-24 21:58:35 +0000702target_ulong do_mftc0_tcschedule(void)
thsf1aa6322008-06-09 07:13:38 +0000703{
704 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
705
thsb5dc7732008-06-27 10:02:35 +0000706 if (other_tc == env->current_tc)
707 return env->active_tc.CP0_TCSchedule;
708 else
709 return env->tcs[other_tc].CP0_TCSchedule;
thsf1aa6322008-06-09 07:13:38 +0000710}
711
ths1a3fd9c2008-06-24 21:58:35 +0000712target_ulong do_mfc0_tcschefback (void)
thsf1aa6322008-06-09 07:13:38 +0000713{
thsb5dc7732008-06-27 10:02:35 +0000714 return env->active_tc.CP0_TCScheFBack;
thsf1aa6322008-06-09 07:13:38 +0000715}
716
ths1a3fd9c2008-06-24 21:58:35 +0000717target_ulong do_mftc0_tcschefback(void)
thsf1aa6322008-06-09 07:13:38 +0000718{
719 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
720
thsb5dc7732008-06-27 10:02:35 +0000721 if (other_tc == env->current_tc)
722 return env->active_tc.CP0_TCScheFBack;
723 else
724 return env->tcs[other_tc].CP0_TCScheFBack;
thsf1aa6322008-06-09 07:13:38 +0000725}
726
ths1a3fd9c2008-06-24 21:58:35 +0000727target_ulong do_mfc0_count (void)
ths873eb012006-12-06 17:59:07 +0000728{
thsbe24bb42008-06-23 12:57:09 +0000729 return (int32_t)cpu_mips_get_count(env);
bellard6af0bf92005-07-02 14:58:51 +0000730}
731
ths1a3fd9c2008-06-24 21:58:35 +0000732target_ulong do_mftc0_entryhi(void)
thsf1aa6322008-06-09 07:13:38 +0000733{
734 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
thsb5dc7732008-06-27 10:02:35 +0000735 int32_t tcstatus;
thsf1aa6322008-06-09 07:13:38 +0000736
thsb5dc7732008-06-27 10:02:35 +0000737 if (other_tc == env->current_tc)
738 tcstatus = env->active_tc.CP0_TCStatus;
739 else
740 tcstatus = env->tcs[other_tc].CP0_TCStatus;
741
742 return (env->CP0_EntryHi & ~0xff) | (tcstatus & 0xff);
thsf1aa6322008-06-09 07:13:38 +0000743}
744
ths1a3fd9c2008-06-24 21:58:35 +0000745target_ulong do_mftc0_status(void)
thsf1aa6322008-06-09 07:13:38 +0000746{
747 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
ths1a3fd9c2008-06-24 21:58:35 +0000748 target_ulong t0;
thsb5dc7732008-06-27 10:02:35 +0000749 int32_t tcstatus;
750
751 if (other_tc == env->current_tc)
752 tcstatus = env->active_tc.CP0_TCStatus;
753 else
754 tcstatus = env->tcs[other_tc].CP0_TCStatus;
thsf1aa6322008-06-09 07:13:38 +0000755
thsbe24bb42008-06-23 12:57:09 +0000756 t0 = env->CP0_Status & ~0xf1000018;
757 t0 |= tcstatus & (0xf << CP0TCSt_TCU0);
758 t0 |= (tcstatus & (1 << CP0TCSt_TMX)) >> (CP0TCSt_TMX - CP0St_MX);
759 t0 |= (tcstatus & (0x3 << CP0TCSt_TKSU)) >> (CP0TCSt_TKSU - CP0St_KSU);
760
761 return t0;
thsf1aa6322008-06-09 07:13:38 +0000762}
763
ths1a3fd9c2008-06-24 21:58:35 +0000764target_ulong do_mfc0_lladdr (void)
thsf1aa6322008-06-09 07:13:38 +0000765{
thsbe24bb42008-06-23 12:57:09 +0000766 return (int32_t)env->CP0_LLAddr >> 4;
thsf1aa6322008-06-09 07:13:38 +0000767}
768
ths1a3fd9c2008-06-24 21:58:35 +0000769target_ulong do_mfc0_watchlo (uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +0000770{
thsbe24bb42008-06-23 12:57:09 +0000771 return (int32_t)env->CP0_WatchLo[sel];
thsf1aa6322008-06-09 07:13:38 +0000772}
773
ths1a3fd9c2008-06-24 21:58:35 +0000774target_ulong do_mfc0_watchhi (uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +0000775{
thsbe24bb42008-06-23 12:57:09 +0000776 return env->CP0_WatchHi[sel];
thsf1aa6322008-06-09 07:13:38 +0000777}
778
ths1a3fd9c2008-06-24 21:58:35 +0000779target_ulong do_mfc0_debug (void)
thsf1aa6322008-06-09 07:13:38 +0000780{
ths1a3fd9c2008-06-24 21:58:35 +0000781 target_ulong t0 = env->CP0_Debug;
thsf1aa6322008-06-09 07:13:38 +0000782 if (env->hflags & MIPS_HFLAG_DM)
thsbe24bb42008-06-23 12:57:09 +0000783 t0 |= 1 << CP0DB_DM;
784
785 return t0;
thsf1aa6322008-06-09 07:13:38 +0000786}
787
ths1a3fd9c2008-06-24 21:58:35 +0000788target_ulong do_mftc0_debug(void)
thsf1aa6322008-06-09 07:13:38 +0000789{
790 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
thsb5dc7732008-06-27 10:02:35 +0000791 int32_t tcstatus;
792
793 if (other_tc == env->current_tc)
794 tcstatus = env->active_tc.CP0_Debug_tcstatus;
795 else
796 tcstatus = env->tcs[other_tc].CP0_Debug_tcstatus;
thsf1aa6322008-06-09 07:13:38 +0000797
798 /* XXX: Might be wrong, check with EJTAG spec. */
thsbe24bb42008-06-23 12:57:09 +0000799 return (env->CP0_Debug & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
thsb5dc7732008-06-27 10:02:35 +0000800 (tcstatus & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
thsf1aa6322008-06-09 07:13:38 +0000801}
802
803#if defined(TARGET_MIPS64)
ths1a3fd9c2008-06-24 21:58:35 +0000804target_ulong do_dmfc0_tcrestart (void)
thsf1aa6322008-06-09 07:13:38 +0000805{
thsb5dc7732008-06-27 10:02:35 +0000806 return env->active_tc.PC;
thsf1aa6322008-06-09 07:13:38 +0000807}
808
ths1a3fd9c2008-06-24 21:58:35 +0000809target_ulong do_dmfc0_tchalt (void)
thsf1aa6322008-06-09 07:13:38 +0000810{
thsb5dc7732008-06-27 10:02:35 +0000811 return env->active_tc.CP0_TCHalt;
thsf1aa6322008-06-09 07:13:38 +0000812}
813
ths1a3fd9c2008-06-24 21:58:35 +0000814target_ulong do_dmfc0_tccontext (void)
thsf1aa6322008-06-09 07:13:38 +0000815{
thsb5dc7732008-06-27 10:02:35 +0000816 return env->active_tc.CP0_TCContext;
thsf1aa6322008-06-09 07:13:38 +0000817}
818
ths1a3fd9c2008-06-24 21:58:35 +0000819target_ulong do_dmfc0_tcschedule (void)
thsf1aa6322008-06-09 07:13:38 +0000820{
thsb5dc7732008-06-27 10:02:35 +0000821 return env->active_tc.CP0_TCSchedule;
thsf1aa6322008-06-09 07:13:38 +0000822}
823
ths1a3fd9c2008-06-24 21:58:35 +0000824target_ulong do_dmfc0_tcschefback (void)
thsf1aa6322008-06-09 07:13:38 +0000825{
thsb5dc7732008-06-27 10:02:35 +0000826 return env->active_tc.CP0_TCScheFBack;
thsf1aa6322008-06-09 07:13:38 +0000827}
828
ths1a3fd9c2008-06-24 21:58:35 +0000829target_ulong do_dmfc0_lladdr (void)
thsf1aa6322008-06-09 07:13:38 +0000830{
thsbe24bb42008-06-23 12:57:09 +0000831 return env->CP0_LLAddr >> 4;
thsf1aa6322008-06-09 07:13:38 +0000832}
833
ths1a3fd9c2008-06-24 21:58:35 +0000834target_ulong do_dmfc0_watchlo (uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +0000835{
thsbe24bb42008-06-23 12:57:09 +0000836 return env->CP0_WatchLo[sel];
thsf1aa6322008-06-09 07:13:38 +0000837}
838#endif /* TARGET_MIPS64 */
839
thsbe24bb42008-06-23 12:57:09 +0000840void do_mtc0_index (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000841{
842 int num = 1;
843 unsigned int tmp = env->tlb->nb_tlb;
844
845 do {
846 tmp >>= 1;
847 num <<= 1;
848 } while (tmp);
thsbe24bb42008-06-23 12:57:09 +0000849 env->CP0_Index = (env->CP0_Index & 0x80000000) | (t0 & (num - 1));
thsf1aa6322008-06-09 07:13:38 +0000850}
851
thsbe24bb42008-06-23 12:57:09 +0000852void do_mtc0_mvpcontrol (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000853{
854 uint32_t mask = 0;
855 uint32_t newval;
856
857 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP))
858 mask |= (1 << CP0MVPCo_CPA) | (1 << CP0MVPCo_VPC) |
859 (1 << CP0MVPCo_EVP);
860 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
861 mask |= (1 << CP0MVPCo_STLB);
thsbe24bb42008-06-23 12:57:09 +0000862 newval = (env->mvp->CP0_MVPControl & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +0000863
864 // TODO: Enable/disable shared TLB, enable/disable VPEs.
865
866 env->mvp->CP0_MVPControl = newval;
867}
868
thsbe24bb42008-06-23 12:57:09 +0000869void do_mtc0_vpecontrol (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000870{
871 uint32_t mask;
872 uint32_t newval;
873
874 mask = (1 << CP0VPECo_YSI) | (1 << CP0VPECo_GSI) |
875 (1 << CP0VPECo_TE) | (0xff << CP0VPECo_TargTC);
thsbe24bb42008-06-23 12:57:09 +0000876 newval = (env->CP0_VPEControl & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +0000877
878 /* Yield scheduler intercept not implemented. */
879 /* Gating storage scheduler intercept not implemented. */
880
881 // TODO: Enable/disable TCs.
882
883 env->CP0_VPEControl = newval;
884}
885
thsbe24bb42008-06-23 12:57:09 +0000886void do_mtc0_vpeconf0 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000887{
888 uint32_t mask = 0;
889 uint32_t newval;
890
891 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_MVP)) {
892 if (env->CP0_VPEConf0 & (1 << CP0VPEC0_VPA))
893 mask |= (0xff << CP0VPEC0_XTC);
894 mask |= (1 << CP0VPEC0_MVP) | (1 << CP0VPEC0_VPA);
895 }
thsbe24bb42008-06-23 12:57:09 +0000896 newval = (env->CP0_VPEConf0 & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +0000897
898 // TODO: TC exclusive handling due to ERL/EXL.
899
900 env->CP0_VPEConf0 = newval;
901}
902
thsbe24bb42008-06-23 12:57:09 +0000903void do_mtc0_vpeconf1 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000904{
905 uint32_t mask = 0;
906 uint32_t newval;
907
908 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
909 mask |= (0xff << CP0VPEC1_NCX) | (0xff << CP0VPEC1_NCP2) |
910 (0xff << CP0VPEC1_NCP1);
thsbe24bb42008-06-23 12:57:09 +0000911 newval = (env->CP0_VPEConf1 & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +0000912
913 /* UDI not implemented. */
914 /* CP2 not implemented. */
915
916 // TODO: Handle FPU (CP1) binding.
917
918 env->CP0_VPEConf1 = newval;
919}
920
thsbe24bb42008-06-23 12:57:09 +0000921void do_mtc0_yqmask (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000922{
923 /* Yield qualifier inputs not implemented. */
924 env->CP0_YQMask = 0x00000000;
925}
926
thsbe24bb42008-06-23 12:57:09 +0000927void do_mtc0_vpeopt (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000928{
thsbe24bb42008-06-23 12:57:09 +0000929 env->CP0_VPEOpt = t0 & 0x0000ffff;
thsf1aa6322008-06-09 07:13:38 +0000930}
931
thsbe24bb42008-06-23 12:57:09 +0000932void do_mtc0_entrylo0 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000933{
934 /* Large physaddr (PABITS) not implemented */
935 /* 1k pages not implemented */
thsbe24bb42008-06-23 12:57:09 +0000936 env->CP0_EntryLo0 = t0 & 0x3FFFFFFF;
thsf1aa6322008-06-09 07:13:38 +0000937}
938
thsbe24bb42008-06-23 12:57:09 +0000939void do_mtc0_tcstatus (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000940{
941 uint32_t mask = env->CP0_TCStatus_rw_bitmask;
942 uint32_t newval;
943
thsb5dc7732008-06-27 10:02:35 +0000944 newval = (env->active_tc.CP0_TCStatus & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +0000945
946 // TODO: Sync with CP0_Status.
947
thsb5dc7732008-06-27 10:02:35 +0000948 env->active_tc.CP0_TCStatus = newval;
thsf1aa6322008-06-09 07:13:38 +0000949}
950
thsbe24bb42008-06-23 12:57:09 +0000951void do_mttc0_tcstatus (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000952{
953 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
954
955 // TODO: Sync with CP0_Status.
956
thsb5dc7732008-06-27 10:02:35 +0000957 if (other_tc == env->current_tc)
958 env->active_tc.CP0_TCStatus = t0;
959 else
960 env->tcs[other_tc].CP0_TCStatus = t0;
thsf1aa6322008-06-09 07:13:38 +0000961}
962
thsbe24bb42008-06-23 12:57:09 +0000963void do_mtc0_tcbind (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000964{
965 uint32_t mask = (1 << CP0TCBd_TBE);
966 uint32_t newval;
967
968 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
969 mask |= (1 << CP0TCBd_CurVPE);
thsb5dc7732008-06-27 10:02:35 +0000970 newval = (env->active_tc.CP0_TCBind & ~mask) | (t0 & mask);
971 env->active_tc.CP0_TCBind = newval;
thsf1aa6322008-06-09 07:13:38 +0000972}
973
thsbe24bb42008-06-23 12:57:09 +0000974void do_mttc0_tcbind (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000975{
976 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
977 uint32_t mask = (1 << CP0TCBd_TBE);
978 uint32_t newval;
979
980 if (env->mvp->CP0_MVPControl & (1 << CP0MVPCo_VPC))
981 mask |= (1 << CP0TCBd_CurVPE);
thsb5dc7732008-06-27 10:02:35 +0000982 if (other_tc == env->current_tc) {
983 newval = (env->active_tc.CP0_TCBind & ~mask) | (t0 & mask);
984 env->active_tc.CP0_TCBind = newval;
985 } else {
986 newval = (env->tcs[other_tc].CP0_TCBind & ~mask) | (t0 & mask);
987 env->tcs[other_tc].CP0_TCBind = newval;
988 }
thsf1aa6322008-06-09 07:13:38 +0000989}
990
thsbe24bb42008-06-23 12:57:09 +0000991void do_mtc0_tcrestart (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +0000992{
thsb5dc7732008-06-27 10:02:35 +0000993 env->active_tc.PC = t0;
994 env->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
thsf1aa6322008-06-09 07:13:38 +0000995 env->CP0_LLAddr = 0ULL;
996 /* MIPS16 not implemented. */
997}
998
thsbe24bb42008-06-23 12:57:09 +0000999void do_mttc0_tcrestart (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001000{
1001 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1002
thsb5dc7732008-06-27 10:02:35 +00001003 if (other_tc == env->current_tc) {
1004 env->active_tc.PC = t0;
1005 env->active_tc.CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1006 env->CP0_LLAddr = 0ULL;
1007 /* MIPS16 not implemented. */
1008 } else {
1009 env->tcs[other_tc].PC = t0;
1010 env->tcs[other_tc].CP0_TCStatus &= ~(1 << CP0TCSt_TDS);
1011 env->CP0_LLAddr = 0ULL;
1012 /* MIPS16 not implemented. */
1013 }
thsf1aa6322008-06-09 07:13:38 +00001014}
1015
thsbe24bb42008-06-23 12:57:09 +00001016void do_mtc0_tchalt (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001017{
thsb5dc7732008-06-27 10:02:35 +00001018 env->active_tc.CP0_TCHalt = t0 & 0x1;
thsf1aa6322008-06-09 07:13:38 +00001019
1020 // TODO: Halt TC / Restart (if allocated+active) TC.
1021}
1022
thsbe24bb42008-06-23 12:57:09 +00001023void do_mttc0_tchalt (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001024{
1025 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1026
1027 // TODO: Halt TC / Restart (if allocated+active) TC.
1028
thsb5dc7732008-06-27 10:02:35 +00001029 if (other_tc == env->current_tc)
1030 env->active_tc.CP0_TCHalt = t0;
1031 else
1032 env->tcs[other_tc].CP0_TCHalt = t0;
thsf1aa6322008-06-09 07:13:38 +00001033}
1034
thsbe24bb42008-06-23 12:57:09 +00001035void do_mtc0_tccontext (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001036{
thsb5dc7732008-06-27 10:02:35 +00001037 env->active_tc.CP0_TCContext = t0;
thsf1aa6322008-06-09 07:13:38 +00001038}
1039
thsbe24bb42008-06-23 12:57:09 +00001040void do_mttc0_tccontext (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001041{
1042 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1043
thsb5dc7732008-06-27 10:02:35 +00001044 if (other_tc == env->current_tc)
1045 env->active_tc.CP0_TCContext = t0;
1046 else
1047 env->tcs[other_tc].CP0_TCContext = t0;
thsf1aa6322008-06-09 07:13:38 +00001048}
1049
thsbe24bb42008-06-23 12:57:09 +00001050void do_mtc0_tcschedule (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001051{
thsb5dc7732008-06-27 10:02:35 +00001052 env->active_tc.CP0_TCSchedule = t0;
thsf1aa6322008-06-09 07:13:38 +00001053}
1054
thsbe24bb42008-06-23 12:57:09 +00001055void do_mttc0_tcschedule (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001056{
1057 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1058
thsb5dc7732008-06-27 10:02:35 +00001059 if (other_tc == env->current_tc)
1060 env->active_tc.CP0_TCSchedule = t0;
1061 else
1062 env->tcs[other_tc].CP0_TCSchedule = t0;
thsf1aa6322008-06-09 07:13:38 +00001063}
1064
thsbe24bb42008-06-23 12:57:09 +00001065void do_mtc0_tcschefback (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001066{
thsb5dc7732008-06-27 10:02:35 +00001067 env->active_tc.CP0_TCScheFBack = t0;
thsf1aa6322008-06-09 07:13:38 +00001068}
1069
thsbe24bb42008-06-23 12:57:09 +00001070void do_mttc0_tcschefback (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001071{
1072 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1073
thsb5dc7732008-06-27 10:02:35 +00001074 if (other_tc == env->current_tc)
1075 env->active_tc.CP0_TCScheFBack = t0;
1076 else
1077 env->tcs[other_tc].CP0_TCScheFBack = t0;
thsf1aa6322008-06-09 07:13:38 +00001078}
1079
thsbe24bb42008-06-23 12:57:09 +00001080void do_mtc0_entrylo1 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001081{
1082 /* Large physaddr (PABITS) not implemented */
1083 /* 1k pages not implemented */
thsbe24bb42008-06-23 12:57:09 +00001084 env->CP0_EntryLo1 = t0 & 0x3FFFFFFF;
thsf1aa6322008-06-09 07:13:38 +00001085}
1086
thsbe24bb42008-06-23 12:57:09 +00001087void do_mtc0_context (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001088{
thsbe24bb42008-06-23 12:57:09 +00001089 env->CP0_Context = (env->CP0_Context & 0x007FFFFF) | (t0 & ~0x007FFFFF);
thsf1aa6322008-06-09 07:13:38 +00001090}
1091
thsbe24bb42008-06-23 12:57:09 +00001092void do_mtc0_pagemask (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001093{
1094 /* 1k pages not implemented */
thsbe24bb42008-06-23 12:57:09 +00001095 env->CP0_PageMask = t0 & (0x1FFFFFFF & (TARGET_PAGE_MASK << 1));
thsf1aa6322008-06-09 07:13:38 +00001096}
1097
thsbe24bb42008-06-23 12:57:09 +00001098void do_mtc0_pagegrain (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001099{
1100 /* SmartMIPS not implemented */
1101 /* Large physaddr (PABITS) not implemented */
1102 /* 1k pages not implemented */
1103 env->CP0_PageGrain = 0;
1104}
1105
thsbe24bb42008-06-23 12:57:09 +00001106void do_mtc0_wired (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001107{
thsbe24bb42008-06-23 12:57:09 +00001108 env->CP0_Wired = t0 % env->tlb->nb_tlb;
thsf1aa6322008-06-09 07:13:38 +00001109}
1110
thsbe24bb42008-06-23 12:57:09 +00001111void do_mtc0_srsconf0 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001112{
thsbe24bb42008-06-23 12:57:09 +00001113 env->CP0_SRSConf0 |= t0 & env->CP0_SRSConf0_rw_bitmask;
thsf1aa6322008-06-09 07:13:38 +00001114}
1115
thsbe24bb42008-06-23 12:57:09 +00001116void do_mtc0_srsconf1 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001117{
thsbe24bb42008-06-23 12:57:09 +00001118 env->CP0_SRSConf1 |= t0 & env->CP0_SRSConf1_rw_bitmask;
thsf1aa6322008-06-09 07:13:38 +00001119}
1120
thsbe24bb42008-06-23 12:57:09 +00001121void do_mtc0_srsconf2 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001122{
thsbe24bb42008-06-23 12:57:09 +00001123 env->CP0_SRSConf2 |= t0 & env->CP0_SRSConf2_rw_bitmask;
thsf1aa6322008-06-09 07:13:38 +00001124}
1125
thsbe24bb42008-06-23 12:57:09 +00001126void do_mtc0_srsconf3 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001127{
thsbe24bb42008-06-23 12:57:09 +00001128 env->CP0_SRSConf3 |= t0 & env->CP0_SRSConf3_rw_bitmask;
thsf1aa6322008-06-09 07:13:38 +00001129}
1130
thsbe24bb42008-06-23 12:57:09 +00001131void do_mtc0_srsconf4 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001132{
thsbe24bb42008-06-23 12:57:09 +00001133 env->CP0_SRSConf4 |= t0 & env->CP0_SRSConf4_rw_bitmask;
thsf1aa6322008-06-09 07:13:38 +00001134}
1135
thsbe24bb42008-06-23 12:57:09 +00001136void do_mtc0_hwrena (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001137{
thsbe24bb42008-06-23 12:57:09 +00001138 env->CP0_HWREna = t0 & 0x0000000F;
thsf1aa6322008-06-09 07:13:38 +00001139}
1140
thsbe24bb42008-06-23 12:57:09 +00001141void do_mtc0_count (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001142{
thsbe24bb42008-06-23 12:57:09 +00001143 cpu_mips_store_count(env, t0);
thsf1aa6322008-06-09 07:13:38 +00001144}
1145
thsbe24bb42008-06-23 12:57:09 +00001146void do_mtc0_entryhi (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001147{
1148 target_ulong old, val;
1149
1150 /* 1k pages not implemented */
thsbe24bb42008-06-23 12:57:09 +00001151 val = t0 & ((TARGET_PAGE_MASK << 1) | 0xFF);
thsf1aa6322008-06-09 07:13:38 +00001152#if defined(TARGET_MIPS64)
1153 val &= env->SEGMask;
1154#endif
1155 old = env->CP0_EntryHi;
1156 env->CP0_EntryHi = val;
1157 if (env->CP0_Config3 & (1 << CP0C3_MT)) {
thsb5dc7732008-06-27 10:02:35 +00001158 uint32_t tcst = env->active_tc.CP0_TCStatus & ~0xff;
1159 env->active_tc.CP0_TCStatus = tcst | (val & 0xff);
thsf1aa6322008-06-09 07:13:38 +00001160 }
1161 /* If the ASID changes, flush qemu's TLB. */
1162 if ((old & 0xFF) != (val & 0xFF))
1163 cpu_mips_tlb_flush(env, 1);
1164}
1165
thsbe24bb42008-06-23 12:57:09 +00001166void do_mttc0_entryhi(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001167{
1168 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
thsb5dc7732008-06-27 10:02:35 +00001169 int32_t tcstatus;
thsf1aa6322008-06-09 07:13:38 +00001170
thsbe24bb42008-06-23 12:57:09 +00001171 env->CP0_EntryHi = (env->CP0_EntryHi & 0xff) | (t0 & ~0xff);
thsb5dc7732008-06-27 10:02:35 +00001172 if (other_tc == env->current_tc) {
1173 tcstatus = (env->active_tc.CP0_TCStatus & ~0xff) | (t0 & 0xff);
1174 env->active_tc.CP0_TCStatus = tcstatus;
1175 } else {
1176 tcstatus = (env->tcs[other_tc].CP0_TCStatus & ~0xff) | (t0 & 0xff);
1177 env->tcs[other_tc].CP0_TCStatus = tcstatus;
1178 }
thsf1aa6322008-06-09 07:13:38 +00001179}
1180
thsbe24bb42008-06-23 12:57:09 +00001181void do_mtc0_compare (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001182{
thsbe24bb42008-06-23 12:57:09 +00001183 cpu_mips_store_compare(env, t0);
thsf1aa6322008-06-09 07:13:38 +00001184}
1185
thsbe24bb42008-06-23 12:57:09 +00001186void do_mtc0_status (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001187{
1188 uint32_t val, old;
1189 uint32_t mask = env->CP0_Status_rw_bitmask;
1190
thsbe24bb42008-06-23 12:57:09 +00001191 val = t0 & mask;
thsf1aa6322008-06-09 07:13:38 +00001192 old = env->CP0_Status;
1193 env->CP0_Status = (env->CP0_Status & ~mask) | val;
1194 compute_hflags(env);
1195 if (loglevel & CPU_LOG_EXEC)
1196 do_mtc0_status_debug(old, val);
1197 cpu_mips_update_irq(env);
1198}
1199
thsbe24bb42008-06-23 12:57:09 +00001200void do_mttc0_status(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001201{
1202 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
thsb5dc7732008-06-27 10:02:35 +00001203 int32_t tcstatus = env->tcs[other_tc].CP0_TCStatus;
thsf1aa6322008-06-09 07:13:38 +00001204
thsbe24bb42008-06-23 12:57:09 +00001205 env->CP0_Status = t0 & ~0xf1000018;
1206 tcstatus = (tcstatus & ~(0xf << CP0TCSt_TCU0)) | (t0 & (0xf << CP0St_CU0));
1207 tcstatus = (tcstatus & ~(1 << CP0TCSt_TMX)) | ((t0 & (1 << CP0St_MX)) << (CP0TCSt_TMX - CP0St_MX));
1208 tcstatus = (tcstatus & ~(0x3 << CP0TCSt_TKSU)) | ((t0 & (0x3 << CP0St_KSU)) << (CP0TCSt_TKSU - CP0St_KSU));
thsb5dc7732008-06-27 10:02:35 +00001209 if (other_tc == env->current_tc)
1210 env->active_tc.CP0_TCStatus = tcstatus;
1211 else
1212 env->tcs[other_tc].CP0_TCStatus = tcstatus;
thsf1aa6322008-06-09 07:13:38 +00001213}
1214
thsbe24bb42008-06-23 12:57:09 +00001215void do_mtc0_intctl (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001216{
1217 /* vectored interrupts not implemented, no performance counters. */
thsbe24bb42008-06-23 12:57:09 +00001218 env->CP0_IntCtl = (env->CP0_IntCtl & ~0x000002e0) | (t0 & 0x000002e0);
thsf1aa6322008-06-09 07:13:38 +00001219}
1220
thsbe24bb42008-06-23 12:57:09 +00001221void do_mtc0_srsctl (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001222{
1223 uint32_t mask = (0xf << CP0SRSCtl_ESS) | (0xf << CP0SRSCtl_PSS);
thsbe24bb42008-06-23 12:57:09 +00001224 env->CP0_SRSCtl = (env->CP0_SRSCtl & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +00001225}
1226
thsbe24bb42008-06-23 12:57:09 +00001227void do_mtc0_cause (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001228{
1229 uint32_t mask = 0x00C00300;
1230 uint32_t old = env->CP0_Cause;
1231
1232 if (env->insn_flags & ISA_MIPS32R2)
1233 mask |= 1 << CP0Ca_DC;
1234
thsbe24bb42008-06-23 12:57:09 +00001235 env->CP0_Cause = (env->CP0_Cause & ~mask) | (t0 & mask);
thsf1aa6322008-06-09 07:13:38 +00001236
1237 if ((old ^ env->CP0_Cause) & (1 << CP0Ca_DC)) {
1238 if (env->CP0_Cause & (1 << CP0Ca_DC))
1239 cpu_mips_stop_count(env);
1240 else
1241 cpu_mips_start_count(env);
1242 }
1243
1244 /* Handle the software interrupt as an hardware one, as they
1245 are very similar */
thsbe24bb42008-06-23 12:57:09 +00001246 if (t0 & CP0Ca_IP_mask) {
thsf1aa6322008-06-09 07:13:38 +00001247 cpu_mips_update_irq(env);
1248 }
1249}
1250
thsbe24bb42008-06-23 12:57:09 +00001251void do_mtc0_ebase (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001252{
1253 /* vectored interrupts not implemented */
1254 /* Multi-CPU not implemented */
thsbe24bb42008-06-23 12:57:09 +00001255 env->CP0_EBase = 0x80000000 | (t0 & 0x3FFFF000);
thsf1aa6322008-06-09 07:13:38 +00001256}
1257
thsbe24bb42008-06-23 12:57:09 +00001258void do_mtc0_config0 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001259{
thsbe24bb42008-06-23 12:57:09 +00001260 env->CP0_Config0 = (env->CP0_Config0 & 0x81FFFFF8) | (t0 & 0x00000007);
thsf1aa6322008-06-09 07:13:38 +00001261}
1262
thsbe24bb42008-06-23 12:57:09 +00001263void do_mtc0_config2 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001264{
1265 /* tertiary/secondary caches not implemented */
1266 env->CP0_Config2 = (env->CP0_Config2 & 0x8FFF0FFF);
1267}
1268
thsbe24bb42008-06-23 12:57:09 +00001269void do_mtc0_watchlo (target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001270{
1271 /* Watch exceptions for instructions, data loads, data stores
1272 not implemented. */
thsbe24bb42008-06-23 12:57:09 +00001273 env->CP0_WatchLo[sel] = (t0 & ~0x7);
thsf1aa6322008-06-09 07:13:38 +00001274}
1275
thsbe24bb42008-06-23 12:57:09 +00001276void do_mtc0_watchhi (target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001277{
thsbe24bb42008-06-23 12:57:09 +00001278 env->CP0_WatchHi[sel] = (t0 & 0x40FF0FF8);
1279 env->CP0_WatchHi[sel] &= ~(env->CP0_WatchHi[sel] & t0 & 0x7);
thsf1aa6322008-06-09 07:13:38 +00001280}
1281
thsbe24bb42008-06-23 12:57:09 +00001282void do_mtc0_xcontext (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001283{
1284 target_ulong mask = (1ULL << (env->SEGBITS - 7)) - 1;
thsbe24bb42008-06-23 12:57:09 +00001285 env->CP0_XContext = (env->CP0_XContext & mask) | (t0 & ~mask);
thsf1aa6322008-06-09 07:13:38 +00001286}
1287
thsbe24bb42008-06-23 12:57:09 +00001288void do_mtc0_framemask (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001289{
thsbe24bb42008-06-23 12:57:09 +00001290 env->CP0_Framemask = t0; /* XXX */
thsf1aa6322008-06-09 07:13:38 +00001291}
1292
thsbe24bb42008-06-23 12:57:09 +00001293void do_mtc0_debug (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001294{
thsbe24bb42008-06-23 12:57:09 +00001295 env->CP0_Debug = (env->CP0_Debug & 0x8C03FC1F) | (t0 & 0x13300120);
1296 if (t0 & (1 << CP0DB_DM))
thsf1aa6322008-06-09 07:13:38 +00001297 env->hflags |= MIPS_HFLAG_DM;
1298 else
1299 env->hflags &= ~MIPS_HFLAG_DM;
1300}
1301
thsbe24bb42008-06-23 12:57:09 +00001302void do_mttc0_debug(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001303{
1304 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
thsb5dc7732008-06-27 10:02:35 +00001305 uint32_t val = t0 & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt));
thsf1aa6322008-06-09 07:13:38 +00001306
1307 /* XXX: Might be wrong, check with EJTAG spec. */
thsb5dc7732008-06-27 10:02:35 +00001308 if (other_tc == env->current_tc)
1309 env->active_tc.CP0_Debug_tcstatus = val;
1310 else
1311 env->tcs[other_tc].CP0_Debug_tcstatus = val;
thsf1aa6322008-06-09 07:13:38 +00001312 env->CP0_Debug = (env->CP0_Debug & ((1 << CP0DB_SSt) | (1 << CP0DB_Halt))) |
thsbe24bb42008-06-23 12:57:09 +00001313 (t0 & ~((1 << CP0DB_SSt) | (1 << CP0DB_Halt)));
thsf1aa6322008-06-09 07:13:38 +00001314}
1315
thsbe24bb42008-06-23 12:57:09 +00001316void do_mtc0_performance0 (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001317{
thsbe24bb42008-06-23 12:57:09 +00001318 env->CP0_Performance0 = t0 & 0x000007ff;
thsf1aa6322008-06-09 07:13:38 +00001319}
1320
thsbe24bb42008-06-23 12:57:09 +00001321void do_mtc0_taglo (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001322{
thsbe24bb42008-06-23 12:57:09 +00001323 env->CP0_TagLo = t0 & 0xFFFFFCF6;
thsf1aa6322008-06-09 07:13:38 +00001324}
1325
thsbe24bb42008-06-23 12:57:09 +00001326void do_mtc0_datalo (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001327{
thsbe24bb42008-06-23 12:57:09 +00001328 env->CP0_DataLo = t0; /* XXX */
thsf1aa6322008-06-09 07:13:38 +00001329}
1330
thsbe24bb42008-06-23 12:57:09 +00001331void do_mtc0_taghi (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001332{
thsbe24bb42008-06-23 12:57:09 +00001333 env->CP0_TagHi = t0; /* XXX */
thsf1aa6322008-06-09 07:13:38 +00001334}
1335
thsbe24bb42008-06-23 12:57:09 +00001336void do_mtc0_datahi (target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001337{
thsbe24bb42008-06-23 12:57:09 +00001338 env->CP0_DataHi = t0; /* XXX */
thsf1aa6322008-06-09 07:13:38 +00001339}
1340
ths8c0fdd82006-12-06 18:19:33 +00001341void do_mtc0_status_debug(uint32_t old, uint32_t val)
bellard6af0bf92005-07-02 14:58:51 +00001342{
thsf41c52f2007-04-06 18:46:01 +00001343 fprintf(logfile, "Status %08x (%08x) => %08x (%08x) Cause %08x",
1344 old, old & env->CP0_Cause & CP0Ca_IP_mask,
1345 val, val & env->CP0_Cause & CP0Ca_IP_mask,
1346 env->CP0_Cause);
ths623a9302007-10-28 19:45:05 +00001347 switch (env->hflags & MIPS_HFLAG_KSU) {
1348 case MIPS_HFLAG_UM: fputs(", UM\n", logfile); break;
1349 case MIPS_HFLAG_SM: fputs(", SM\n", logfile); break;
1350 case MIPS_HFLAG_KM: fputs("\n", logfile); break;
1351 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
1352 }
ths8c0fdd82006-12-06 18:19:33 +00001353}
bellard6af0bf92005-07-02 14:58:51 +00001354
ths8c0fdd82006-12-06 18:19:33 +00001355void do_mtc0_status_irqraise_debug(void)
1356{
1357 fprintf(logfile, "Raise pending IRQs\n");
bellard6af0bf92005-07-02 14:58:51 +00001358}
thsf1aa6322008-06-09 07:13:38 +00001359#endif /* !CONFIG_USER_ONLY */
bellard6af0bf92005-07-02 14:58:51 +00001360
thsf1aa6322008-06-09 07:13:38 +00001361/* MIPS MT functions */
aurel32add69062008-11-11 11:34:39 +00001362target_ulong do_mftgpr(uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001363{
1364 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1365
thsb5dc7732008-06-27 10:02:35 +00001366 if (other_tc == env->current_tc)
1367 return env->active_tc.gpr[sel];
1368 else
1369 return env->tcs[other_tc].gpr[sel];
thsf1aa6322008-06-09 07:13:38 +00001370}
1371
aurel32add69062008-11-11 11:34:39 +00001372target_ulong do_mftlo(uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001373{
1374 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1375
thsb5dc7732008-06-27 10:02:35 +00001376 if (other_tc == env->current_tc)
1377 return env->active_tc.LO[sel];
1378 else
1379 return env->tcs[other_tc].LO[sel];
thsf1aa6322008-06-09 07:13:38 +00001380}
1381
aurel32add69062008-11-11 11:34:39 +00001382target_ulong do_mfthi(uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001383{
1384 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1385
thsb5dc7732008-06-27 10:02:35 +00001386 if (other_tc == env->current_tc)
1387 return env->active_tc.HI[sel];
1388 else
1389 return env->tcs[other_tc].HI[sel];
thsf1aa6322008-06-09 07:13:38 +00001390}
1391
aurel32add69062008-11-11 11:34:39 +00001392target_ulong do_mftacx(uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001393{
1394 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1395
thsb5dc7732008-06-27 10:02:35 +00001396 if (other_tc == env->current_tc)
1397 return env->active_tc.ACX[sel];
1398 else
1399 return env->tcs[other_tc].ACX[sel];
thsf1aa6322008-06-09 07:13:38 +00001400}
1401
aurel32add69062008-11-11 11:34:39 +00001402target_ulong do_mftdsp(void)
thsf1aa6322008-06-09 07:13:38 +00001403{
1404 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1405
thsb5dc7732008-06-27 10:02:35 +00001406 if (other_tc == env->current_tc)
1407 return env->active_tc.DSPControl;
1408 else
1409 return env->tcs[other_tc].DSPControl;
thsf1aa6322008-06-09 07:13:38 +00001410}
1411
thsbe24bb42008-06-23 12:57:09 +00001412void do_mttgpr(target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001413{
1414 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1415
thsb5dc7732008-06-27 10:02:35 +00001416 if (other_tc == env->current_tc)
1417 env->active_tc.gpr[sel] = t0;
1418 else
1419 env->tcs[other_tc].gpr[sel] = t0;
thsf1aa6322008-06-09 07:13:38 +00001420}
1421
thsbe24bb42008-06-23 12:57:09 +00001422void do_mttlo(target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001423{
1424 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1425
thsb5dc7732008-06-27 10:02:35 +00001426 if (other_tc == env->current_tc)
1427 env->active_tc.LO[sel] = t0;
1428 else
1429 env->tcs[other_tc].LO[sel] = t0;
thsf1aa6322008-06-09 07:13:38 +00001430}
1431
thsbe24bb42008-06-23 12:57:09 +00001432void do_mtthi(target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001433{
1434 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1435
thsb5dc7732008-06-27 10:02:35 +00001436 if (other_tc == env->current_tc)
1437 env->active_tc.HI[sel] = t0;
1438 else
1439 env->tcs[other_tc].HI[sel] = t0;
thsf1aa6322008-06-09 07:13:38 +00001440}
1441
thsbe24bb42008-06-23 12:57:09 +00001442void do_mttacx(target_ulong t0, uint32_t sel)
thsf1aa6322008-06-09 07:13:38 +00001443{
1444 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1445
thsb5dc7732008-06-27 10:02:35 +00001446 if (other_tc == env->current_tc)
1447 env->active_tc.ACX[sel] = t0;
1448 else
1449 env->tcs[other_tc].ACX[sel] = t0;
thsf1aa6322008-06-09 07:13:38 +00001450}
1451
thsbe24bb42008-06-23 12:57:09 +00001452void do_mttdsp(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001453{
1454 int other_tc = env->CP0_VPEControl & (0xff << CP0VPECo_TargTC);
1455
thsb5dc7732008-06-27 10:02:35 +00001456 if (other_tc == env->current_tc)
1457 env->active_tc.DSPControl = t0;
1458 else
1459 env->tcs[other_tc].DSPControl = t0;
thsf1aa6322008-06-09 07:13:38 +00001460}
1461
1462/* MIPS MT functions */
thsbe24bb42008-06-23 12:57:09 +00001463target_ulong do_dmt(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001464{
1465 // TODO
thsbe24bb42008-06-23 12:57:09 +00001466 t0 = 0;
1467 // rt = t0
1468
1469 return t0;
thsf1aa6322008-06-09 07:13:38 +00001470}
1471
thsbe24bb42008-06-23 12:57:09 +00001472target_ulong do_emt(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001473{
1474 // TODO
thsbe24bb42008-06-23 12:57:09 +00001475 t0 = 0;
1476 // rt = t0
1477
1478 return t0;
thsf1aa6322008-06-09 07:13:38 +00001479}
1480
thsbe24bb42008-06-23 12:57:09 +00001481target_ulong do_dvpe(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001482{
1483 // TODO
thsbe24bb42008-06-23 12:57:09 +00001484 t0 = 0;
1485 // rt = t0
1486
1487 return t0;
thsf1aa6322008-06-09 07:13:38 +00001488}
1489
thsbe24bb42008-06-23 12:57:09 +00001490target_ulong do_evpe(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001491{
1492 // TODO
thsbe24bb42008-06-23 12:57:09 +00001493 t0 = 0;
1494 // rt = t0
1495
1496 return t0;
thsf1aa6322008-06-09 07:13:38 +00001497}
1498
ths6c5c1e22008-06-24 15:12:27 +00001499void do_fork(target_ulong t0, target_ulong t1)
thsf1aa6322008-06-09 07:13:38 +00001500{
thsbe24bb42008-06-23 12:57:09 +00001501 // t0 = rt, t1 = rs
1502 t0 = 0;
thsf1aa6322008-06-09 07:13:38 +00001503 // TODO: store to TC register
1504}
1505
thsbe24bb42008-06-23 12:57:09 +00001506target_ulong do_yield(target_ulong t0)
thsf1aa6322008-06-09 07:13:38 +00001507{
thsbe24bb42008-06-23 12:57:09 +00001508 if (t0 < 0) {
thsf1aa6322008-06-09 07:13:38 +00001509 /* No scheduling policy implemented. */
thsbe24bb42008-06-23 12:57:09 +00001510 if (t0 != -2) {
thsf1aa6322008-06-09 07:13:38 +00001511 if (env->CP0_VPEControl & (1 << CP0VPECo_YSI) &&
thsb5dc7732008-06-27 10:02:35 +00001512 env->active_tc.CP0_TCStatus & (1 << CP0TCSt_DT)) {
thsf1aa6322008-06-09 07:13:38 +00001513 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1514 env->CP0_VPEControl |= 4 << CP0VPECo_EXCPT;
1515 do_raise_exception(EXCP_THREAD);
1516 }
1517 }
thsbe24bb42008-06-23 12:57:09 +00001518 } else if (t0 == 0) {
thsf1aa6322008-06-09 07:13:38 +00001519 if (0 /* TODO: TC underflow */) {
1520 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1521 do_raise_exception(EXCP_THREAD);
1522 } else {
1523 // TODO: Deallocate TC
1524 }
thsbe24bb42008-06-23 12:57:09 +00001525 } else if (t0 > 0) {
thsf1aa6322008-06-09 07:13:38 +00001526 /* Yield qualifier inputs not implemented. */
1527 env->CP0_VPEControl &= ~(0x7 << CP0VPECo_EXCPT);
1528 env->CP0_VPEControl |= 2 << CP0VPECo_EXCPT;
1529 do_raise_exception(EXCP_THREAD);
1530 }
thsbe24bb42008-06-23 12:57:09 +00001531 return env->CP0_YQMask;
thsf1aa6322008-06-09 07:13:38 +00001532}
1533
thsf1aa6322008-06-09 07:13:38 +00001534#ifndef CONFIG_USER_ONLY
bellard6af0bf92005-07-02 14:58:51 +00001535/* TLB management */
ths814b9a42006-12-06 17:42:40 +00001536void cpu_mips_tlb_flush (CPUState *env, int flush_global)
1537{
1538 /* Flush qemu's TLB and discard all shadowed entries. */
1539 tlb_flush (env, flush_global);
thsead93602007-09-06 00:18:15 +00001540 env->tlb->tlb_in_use = env->tlb->nb_tlb;
ths814b9a42006-12-06 17:42:40 +00001541}
1542
ths29929e32007-05-13 13:49:44 +00001543static void r4k_mips_tlb_flush_extra (CPUState *env, int first)
ths814b9a42006-12-06 17:42:40 +00001544{
1545 /* Discard entries from env->tlb[first] onwards. */
thsead93602007-09-06 00:18:15 +00001546 while (env->tlb->tlb_in_use > first) {
1547 r4k_invalidate_tlb(env, --env->tlb->tlb_in_use, 0);
ths814b9a42006-12-06 17:42:40 +00001548 }
1549}
1550
ths29929e32007-05-13 13:49:44 +00001551static void r4k_fill_tlb (int idx)
bellard6af0bf92005-07-02 14:58:51 +00001552{
ths29929e32007-05-13 13:49:44 +00001553 r4k_tlb_t *tlb;
bellard6af0bf92005-07-02 14:58:51 +00001554
1555 /* XXX: detect conflicting TLBs and raise a MCHECK exception when needed */
thsead93602007-09-06 00:18:15 +00001556 tlb = &env->tlb->mmu.r4k.tlb[idx];
thsf2e9ebe2007-05-13 14:07:26 +00001557 tlb->VPN = env->CP0_EntryHi & (TARGET_PAGE_MASK << 1);
thsd26bc212007-11-08 18:05:37 +00001558#if defined(TARGET_MIPS64)
thse034e2c2007-06-23 18:04:12 +00001559 tlb->VPN &= env->SEGMask;
ths100ce982007-05-13 19:22:13 +00001560#endif
pbrook98c1b822006-03-11 16:20:36 +00001561 tlb->ASID = env->CP0_EntryHi & 0xFF;
ths3b1c8be2007-01-22 20:50:42 +00001562 tlb->PageMask = env->CP0_PageMask;
bellard6af0bf92005-07-02 14:58:51 +00001563 tlb->G = env->CP0_EntryLo0 & env->CP0_EntryLo1 & 1;
pbrook98c1b822006-03-11 16:20:36 +00001564 tlb->V0 = (env->CP0_EntryLo0 & 2) != 0;
1565 tlb->D0 = (env->CP0_EntryLo0 & 4) != 0;
1566 tlb->C0 = (env->CP0_EntryLo0 >> 3) & 0x7;
bellard6af0bf92005-07-02 14:58:51 +00001567 tlb->PFN[0] = (env->CP0_EntryLo0 >> 6) << 12;
pbrook98c1b822006-03-11 16:20:36 +00001568 tlb->V1 = (env->CP0_EntryLo1 & 2) != 0;
1569 tlb->D1 = (env->CP0_EntryLo1 & 4) != 0;
1570 tlb->C1 = (env->CP0_EntryLo1 >> 3) & 0x7;
bellard6af0bf92005-07-02 14:58:51 +00001571 tlb->PFN[1] = (env->CP0_EntryLo1 >> 6) << 12;
1572}
1573
ths29929e32007-05-13 13:49:44 +00001574void r4k_do_tlbwi (void)
bellard6af0bf92005-07-02 14:58:51 +00001575{
aurel32bbc0d792008-09-14 17:09:56 +00001576 int idx;
1577
1578 idx = (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb;
1579
ths814b9a42006-12-06 17:42:40 +00001580 /* Discard cached TLB entries. We could avoid doing this if the
1581 tlbwi is just upgrading access permissions on the current entry;
1582 that might be a further win. */
thsead93602007-09-06 00:18:15 +00001583 r4k_mips_tlb_flush_extra (env, env->tlb->nb_tlb);
ths814b9a42006-12-06 17:42:40 +00001584
aurel32bbc0d792008-09-14 17:09:56 +00001585 r4k_invalidate_tlb(env, idx, 0);
1586 r4k_fill_tlb(idx);
bellard6af0bf92005-07-02 14:58:51 +00001587}
1588
ths29929e32007-05-13 13:49:44 +00001589void r4k_do_tlbwr (void)
bellard6af0bf92005-07-02 14:58:51 +00001590{
1591 int r = cpu_mips_get_random(env);
1592
ths29929e32007-05-13 13:49:44 +00001593 r4k_invalidate_tlb(env, r, 1);
1594 r4k_fill_tlb(r);
bellard6af0bf92005-07-02 14:58:51 +00001595}
1596
ths29929e32007-05-13 13:49:44 +00001597void r4k_do_tlbp (void)
bellard6af0bf92005-07-02 14:58:51 +00001598{
ths29929e32007-05-13 13:49:44 +00001599 r4k_tlb_t *tlb;
thsf2e9ebe2007-05-13 14:07:26 +00001600 target_ulong mask;
bellard6af0bf92005-07-02 14:58:51 +00001601 target_ulong tag;
thsf2e9ebe2007-05-13 14:07:26 +00001602 target_ulong VPN;
bellard6af0bf92005-07-02 14:58:51 +00001603 uint8_t ASID;
1604 int i;
1605
bellard3d9fb9fe2006-05-22 22:13:29 +00001606 ASID = env->CP0_EntryHi & 0xFF;
thsead93602007-09-06 00:18:15 +00001607 for (i = 0; i < env->tlb->nb_tlb; i++) {
1608 tlb = &env->tlb->mmu.r4k.tlb[i];
thsf2e9ebe2007-05-13 14:07:26 +00001609 /* 1k pages are not supported. */
1610 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
1611 tag = env->CP0_EntryHi & ~mask;
1612 VPN = tlb->VPN & ~mask;
bellard6af0bf92005-07-02 14:58:51 +00001613 /* Check ASID, virtual page number & size */
thsf2e9ebe2007-05-13 14:07:26 +00001614 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
bellard6af0bf92005-07-02 14:58:51 +00001615 /* TLB match */
ths9c2149c2007-01-23 22:45:22 +00001616 env->CP0_Index = i;
bellard6af0bf92005-07-02 14:58:51 +00001617 break;
1618 }
1619 }
thsead93602007-09-06 00:18:15 +00001620 if (i == env->tlb->nb_tlb) {
ths814b9a42006-12-06 17:42:40 +00001621 /* No match. Discard any shadow entries, if any of them match. */
thsead93602007-09-06 00:18:15 +00001622 for (i = env->tlb->nb_tlb; i < env->tlb->tlb_in_use; i++) {
1623 tlb = &env->tlb->mmu.r4k.tlb[i];
thsf2e9ebe2007-05-13 14:07:26 +00001624 /* 1k pages are not supported. */
1625 mask = tlb->PageMask | ~(TARGET_PAGE_MASK << 1);
1626 tag = env->CP0_EntryHi & ~mask;
1627 VPN = tlb->VPN & ~mask;
ths814b9a42006-12-06 17:42:40 +00001628 /* Check ASID, virtual page number & size */
thsf2e9ebe2007-05-13 14:07:26 +00001629 if ((tlb->G == 1 || tlb->ASID == ASID) && VPN == tag) {
ths29929e32007-05-13 13:49:44 +00001630 r4k_mips_tlb_flush_extra (env, i);
ths814b9a42006-12-06 17:42:40 +00001631 break;
1632 }
1633 }
1634
ths9c2149c2007-01-23 22:45:22 +00001635 env->CP0_Index |= 0x80000000;
bellard6af0bf92005-07-02 14:58:51 +00001636 }
1637}
1638
ths29929e32007-05-13 13:49:44 +00001639void r4k_do_tlbr (void)
bellard6af0bf92005-07-02 14:58:51 +00001640{
ths29929e32007-05-13 13:49:44 +00001641 r4k_tlb_t *tlb;
pbrook09c56b82006-03-11 16:39:23 +00001642 uint8_t ASID;
aurel32bbc0d792008-09-14 17:09:56 +00001643 int idx;
bellard6af0bf92005-07-02 14:58:51 +00001644
pbrook09c56b82006-03-11 16:39:23 +00001645 ASID = env->CP0_EntryHi & 0xFF;
aurel32bbc0d792008-09-14 17:09:56 +00001646 idx = (env->CP0_Index & ~0x80000000) % env->tlb->nb_tlb;
1647 tlb = &env->tlb->mmu.r4k.tlb[idx];
bellard4ad40f32005-12-05 19:59:36 +00001648
1649 /* If this will change the current ASID, flush qemu's TLB. */
ths814b9a42006-12-06 17:42:40 +00001650 if (ASID != tlb->ASID)
1651 cpu_mips_tlb_flush (env, 1);
1652
thsead93602007-09-06 00:18:15 +00001653 r4k_mips_tlb_flush_extra(env, env->tlb->nb_tlb);
bellard4ad40f32005-12-05 19:59:36 +00001654
bellard6af0bf92005-07-02 14:58:51 +00001655 env->CP0_EntryHi = tlb->VPN | tlb->ASID;
ths3b1c8be2007-01-22 20:50:42 +00001656 env->CP0_PageMask = tlb->PageMask;
ths7495fd02007-01-01 20:32:08 +00001657 env->CP0_EntryLo0 = tlb->G | (tlb->V0 << 1) | (tlb->D0 << 2) |
1658 (tlb->C0 << 3) | (tlb->PFN[0] >> 6);
1659 env->CP0_EntryLo1 = tlb->G | (tlb->V1 << 1) | (tlb->D1 << 2) |
1660 (tlb->C1 << 3) | (tlb->PFN[1] >> 6);
bellard6af0bf92005-07-02 14:58:51 +00001661}
bellard6af0bf92005-07-02 14:58:51 +00001662
pbrooka7812ae2008-11-17 14:43:54 +00001663void do_tlbwi(void)
1664{
1665 env->tlb->do_tlbwi();
1666}
1667
1668void do_tlbwr(void)
1669{
1670 env->tlb->do_tlbwr();
1671}
1672
1673void do_tlbp(void)
1674{
1675 env->tlb->do_tlbp();
1676}
1677
1678void do_tlbr(void)
1679{
1680 env->tlb->do_tlbr();
1681}
1682
ths2b0233a2008-06-12 12:42:35 +00001683/* Specials */
ths27961882008-06-27 10:03:42 +00001684target_ulong do_di (void)
ths2b0233a2008-06-12 12:42:35 +00001685{
ths27961882008-06-27 10:03:42 +00001686 target_ulong t0 = env->CP0_Status;
1687
thsbe24bb42008-06-23 12:57:09 +00001688 env->CP0_Status = t0 & ~(1 << CP0St_IE);
ths2b0233a2008-06-12 12:42:35 +00001689 cpu_mips_update_irq(env);
thsbe24bb42008-06-23 12:57:09 +00001690
1691 return t0;
ths2b0233a2008-06-12 12:42:35 +00001692}
1693
ths27961882008-06-27 10:03:42 +00001694target_ulong do_ei (void)
ths2b0233a2008-06-12 12:42:35 +00001695{
ths27961882008-06-27 10:03:42 +00001696 target_ulong t0 = env->CP0_Status;
1697
thsbe24bb42008-06-23 12:57:09 +00001698 env->CP0_Status = t0 | (1 << CP0St_IE);
ths2b0233a2008-06-12 12:42:35 +00001699 cpu_mips_update_irq(env);
thsbe24bb42008-06-23 12:57:09 +00001700
1701 return t0;
ths2b0233a2008-06-12 12:42:35 +00001702}
1703
aurel32cd5158e2008-12-07 23:26:24 +00001704static void debug_pre_eret (void)
bellard6af0bf92005-07-02 14:58:51 +00001705{
thsf41c52f2007-04-06 18:46:01 +00001706 fprintf(logfile, "ERET: PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
thsb5dc7732008-06-27 10:02:35 +00001707 env->active_tc.PC, env->CP0_EPC);
thsf41c52f2007-04-06 18:46:01 +00001708 if (env->CP0_Status & (1 << CP0St_ERL))
1709 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
1710 if (env->hflags & MIPS_HFLAG_DM)
1711 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
1712 fputs("\n", logfile);
1713}
1714
aurel32cd5158e2008-12-07 23:26:24 +00001715static void debug_post_eret (void)
thsf41c52f2007-04-06 18:46:01 +00001716{
ths744e0912007-04-13 22:30:36 +00001717 fprintf(logfile, " => PC " TARGET_FMT_lx " EPC " TARGET_FMT_lx,
thsb5dc7732008-06-27 10:02:35 +00001718 env->active_tc.PC, env->CP0_EPC);
thsf41c52f2007-04-06 18:46:01 +00001719 if (env->CP0_Status & (1 << CP0St_ERL))
1720 fprintf(logfile, " ErrorEPC " TARGET_FMT_lx, env->CP0_ErrorEPC);
1721 if (env->hflags & MIPS_HFLAG_DM)
1722 fprintf(logfile, " DEPC " TARGET_FMT_lx, env->CP0_DEPC);
ths623a9302007-10-28 19:45:05 +00001723 switch (env->hflags & MIPS_HFLAG_KSU) {
1724 case MIPS_HFLAG_UM: fputs(", UM\n", logfile); break;
1725 case MIPS_HFLAG_SM: fputs(", SM\n", logfile); break;
1726 case MIPS_HFLAG_KM: fputs("\n", logfile); break;
1727 default: cpu_abort(env, "Invalid MMU mode!\n"); break;
1728 }
bellard6af0bf92005-07-02 14:58:51 +00001729}
1730
ths6c5c1e22008-06-24 15:12:27 +00001731void do_eret (void)
ths2b0233a2008-06-12 12:42:35 +00001732{
1733 if (loglevel & CPU_LOG_EXEC)
1734 debug_pre_eret();
1735 if (env->CP0_Status & (1 << CP0St_ERL)) {
thsb5dc7732008-06-27 10:02:35 +00001736 env->active_tc.PC = env->CP0_ErrorEPC;
ths2b0233a2008-06-12 12:42:35 +00001737 env->CP0_Status &= ~(1 << CP0St_ERL);
1738 } else {
thsb5dc7732008-06-27 10:02:35 +00001739 env->active_tc.PC = env->CP0_EPC;
ths2b0233a2008-06-12 12:42:35 +00001740 env->CP0_Status &= ~(1 << CP0St_EXL);
1741 }
1742 compute_hflags(env);
1743 if (loglevel & CPU_LOG_EXEC)
1744 debug_post_eret();
1745 env->CP0_LLAddr = 1;
1746}
1747
ths6c5c1e22008-06-24 15:12:27 +00001748void do_deret (void)
ths2b0233a2008-06-12 12:42:35 +00001749{
1750 if (loglevel & CPU_LOG_EXEC)
1751 debug_pre_eret();
thsb5dc7732008-06-27 10:02:35 +00001752 env->active_tc.PC = env->CP0_DEPC;
ths2b0233a2008-06-12 12:42:35 +00001753 env->hflags &= MIPS_HFLAG_DM;
1754 compute_hflags(env);
1755 if (loglevel & CPU_LOG_EXEC)
1756 debug_post_eret();
1757 env->CP0_LLAddr = 1;
1758}
ths0eaef5a2008-07-23 16:14:22 +00001759#endif /* !CONFIG_USER_ONLY */
ths2b0233a2008-06-12 12:42:35 +00001760
ths27961882008-06-27 10:03:42 +00001761target_ulong do_rdhwr_cpunum(void)
ths2b0233a2008-06-12 12:42:35 +00001762{
1763 if ((env->hflags & MIPS_HFLAG_CP0) ||
1764 (env->CP0_HWREna & (1 << 0)))
ths27961882008-06-27 10:03:42 +00001765 return env->CP0_EBase & 0x3ff;
ths2b0233a2008-06-12 12:42:35 +00001766 else
1767 do_raise_exception(EXCP_RI);
thsbe24bb42008-06-23 12:57:09 +00001768
ths27961882008-06-27 10:03:42 +00001769 return 0;
ths2b0233a2008-06-12 12:42:35 +00001770}
1771
ths27961882008-06-27 10:03:42 +00001772target_ulong do_rdhwr_synci_step(void)
ths2b0233a2008-06-12 12:42:35 +00001773{
1774 if ((env->hflags & MIPS_HFLAG_CP0) ||
1775 (env->CP0_HWREna & (1 << 1)))
ths27961882008-06-27 10:03:42 +00001776 return env->SYNCI_Step;
ths2b0233a2008-06-12 12:42:35 +00001777 else
1778 do_raise_exception(EXCP_RI);
thsbe24bb42008-06-23 12:57:09 +00001779
ths27961882008-06-27 10:03:42 +00001780 return 0;
ths2b0233a2008-06-12 12:42:35 +00001781}
1782
ths27961882008-06-27 10:03:42 +00001783target_ulong do_rdhwr_cc(void)
ths2b0233a2008-06-12 12:42:35 +00001784{
1785 if ((env->hflags & MIPS_HFLAG_CP0) ||
1786 (env->CP0_HWREna & (1 << 2)))
ths27961882008-06-27 10:03:42 +00001787 return env->CP0_Count;
ths2b0233a2008-06-12 12:42:35 +00001788 else
1789 do_raise_exception(EXCP_RI);
thsbe24bb42008-06-23 12:57:09 +00001790
ths27961882008-06-27 10:03:42 +00001791 return 0;
ths2b0233a2008-06-12 12:42:35 +00001792}
1793
ths27961882008-06-27 10:03:42 +00001794target_ulong do_rdhwr_ccres(void)
ths2b0233a2008-06-12 12:42:35 +00001795{
1796 if ((env->hflags & MIPS_HFLAG_CP0) ||
1797 (env->CP0_HWREna & (1 << 3)))
ths27961882008-06-27 10:03:42 +00001798 return env->CCRes;
ths2b0233a2008-06-12 12:42:35 +00001799 else
1800 do_raise_exception(EXCP_RI);
thsbe24bb42008-06-23 12:57:09 +00001801
ths27961882008-06-27 10:03:42 +00001802 return 0;
ths2b0233a2008-06-12 12:42:35 +00001803}
1804
bellard6af0bf92005-07-02 14:58:51 +00001805void do_pmon (int function)
1806{
1807 function /= 2;
1808 switch (function) {
1809 case 2: /* TODO: char inbyte(int waitflag); */
thsb5dc7732008-06-27 10:02:35 +00001810 if (env->active_tc.gpr[4] == 0)
1811 env->active_tc.gpr[2] = -1;
bellard6af0bf92005-07-02 14:58:51 +00001812 /* Fall through */
1813 case 11: /* TODO: char inbyte (void); */
thsb5dc7732008-06-27 10:02:35 +00001814 env->active_tc.gpr[2] = -1;
bellard6af0bf92005-07-02 14:58:51 +00001815 break;
1816 case 3:
1817 case 12:
thsb5dc7732008-06-27 10:02:35 +00001818 printf("%c", (char)(env->active_tc.gpr[4] & 0xFF));
bellard6af0bf92005-07-02 14:58:51 +00001819 break;
1820 case 17:
1821 break;
1822 case 158:
1823 {
thsb5dc7732008-06-27 10:02:35 +00001824 unsigned char *fmt = (void *)(unsigned long)env->active_tc.gpr[4];
bellard6af0bf92005-07-02 14:58:51 +00001825 printf("%s", fmt);
1826 }
1827 break;
1828 }
1829}
bellarde37e8632005-07-04 22:17:33 +00001830
ths08ba7962008-06-12 03:15:13 +00001831void do_wait (void)
1832{
1833 env->halted = 1;
1834 do_raise_exception(EXCP_HLT);
1835}
1836
ths5fafdf22007-09-16 21:08:06 +00001837#if !defined(CONFIG_USER_ONLY)
bellarde37e8632005-07-04 22:17:33 +00001838
bellard4ad40f32005-12-05 19:59:36 +00001839static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr);
1840
bellarde37e8632005-07-04 22:17:33 +00001841#define MMUSUFFIX _mmu
bellard4ad40f32005-12-05 19:59:36 +00001842#define ALIGNED_ONLY
bellarde37e8632005-07-04 22:17:33 +00001843
1844#define SHIFT 0
1845#include "softmmu_template.h"
1846
1847#define SHIFT 1
1848#include "softmmu_template.h"
1849
1850#define SHIFT 2
1851#include "softmmu_template.h"
1852
1853#define SHIFT 3
1854#include "softmmu_template.h"
1855
bellard4ad40f32005-12-05 19:59:36 +00001856static void do_unaligned_access (target_ulong addr, int is_write, int is_user, void *retaddr)
1857{
1858 env->CP0_BadVAddr = addr;
1859 do_restore_state (retaddr);
1860 do_raise_exception ((is_write == 1) ? EXCP_AdES : EXCP_AdEL);
1861}
1862
j_mayer6ebbf392007-10-14 07:07:08 +00001863void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
bellarde37e8632005-07-04 22:17:33 +00001864{
1865 TranslationBlock *tb;
1866 CPUState *saved_env;
1867 unsigned long pc;
1868 int ret;
1869
1870 /* XXX: hack to restore env in all cases, even if not called from
1871 generated code */
1872 saved_env = env;
1873 env = cpu_single_env;
j_mayer6ebbf392007-10-14 07:07:08 +00001874 ret = cpu_mips_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
bellarde37e8632005-07-04 22:17:33 +00001875 if (ret) {
1876 if (retaddr) {
1877 /* now we have a real cpu fault */
1878 pc = (unsigned long)retaddr;
1879 tb = tb_find_pc(pc);
1880 if (tb) {
1881 /* the PC is inside the translated code. It means that we have
1882 a virtual CPU fault */
1883 cpu_restore_state(tb, env, pc, NULL);
1884 }
1885 }
1886 do_raise_exception_err(env->exception_index, env->error_code);
1887 }
1888 env = saved_env;
1889}
1890
ths647de6c2007-10-20 19:45:44 +00001891void do_unassigned_access(target_phys_addr_t addr, int is_write, int is_exec,
blueswir1e18231a2008-10-06 18:46:28 +00001892 int unused, int size)
ths647de6c2007-10-20 19:45:44 +00001893{
1894 if (is_exec)
1895 do_raise_exception(EXCP_IBE);
1896 else
1897 do_raise_exception(EXCP_DBE);
1898}
thsf1aa6322008-06-09 07:13:38 +00001899#endif /* !CONFIG_USER_ONLY */
thsfd4a04e2007-05-18 11:55:54 +00001900
1901/* Complex FPU operations which may need stack space. */
1902
pbrookf090c9d2007-11-18 14:33:24 +00001903#define FLOAT_ONE32 make_float32(0x3f8 << 20)
1904#define FLOAT_ONE64 make_float64(0x3ffULL << 52)
1905#define FLOAT_TWO32 make_float32(1 << 30)
1906#define FLOAT_TWO64 make_float64(1ULL << 62)
ths54454092007-09-29 19:19:59 +00001907#define FLOAT_QNAN32 0x7fbfffff
1908#define FLOAT_QNAN64 0x7ff7ffffffffffffULL
1909#define FLOAT_SNAN32 0x7fffffff
1910#define FLOAT_SNAN64 0x7fffffffffffffffULL
ths8dfdb872007-06-26 20:26:03 +00001911
thsfd4a04e2007-05-18 11:55:54 +00001912/* convert MIPS rounding mode in FCR31 to IEEE library */
1913unsigned int ieee_rm[] = {
1914 float_round_nearest_even,
1915 float_round_to_zero,
1916 float_round_up,
1917 float_round_down
1918};
1919
1920#define RESTORE_ROUNDING_MODE \
thsf01be152008-09-18 11:57:27 +00001921 set_float_rounding_mode(ieee_rm[env->active_fpu.fcr31 & 3], &env->active_fpu.fp_status)
thsfd4a04e2007-05-18 11:55:54 +00001922
ths6c5c1e22008-06-24 15:12:27 +00001923target_ulong do_cfc1 (uint32_t reg)
thsfd4a04e2007-05-18 11:55:54 +00001924{
ths6c5c1e22008-06-24 15:12:27 +00001925 target_ulong t0;
1926
thsead93602007-09-06 00:18:15 +00001927 switch (reg) {
1928 case 0:
thsf01be152008-09-18 11:57:27 +00001929 t0 = (int32_t)env->active_fpu.fcr0;
thsead93602007-09-06 00:18:15 +00001930 break;
1931 case 25:
thsf01be152008-09-18 11:57:27 +00001932 t0 = ((env->active_fpu.fcr31 >> 24) & 0xfe) | ((env->active_fpu.fcr31 >> 23) & 0x1);
thsead93602007-09-06 00:18:15 +00001933 break;
1934 case 26:
thsf01be152008-09-18 11:57:27 +00001935 t0 = env->active_fpu.fcr31 & 0x0003f07c;
thsead93602007-09-06 00:18:15 +00001936 break;
1937 case 28:
thsf01be152008-09-18 11:57:27 +00001938 t0 = (env->active_fpu.fcr31 & 0x00000f83) | ((env->active_fpu.fcr31 >> 22) & 0x4);
thsead93602007-09-06 00:18:15 +00001939 break;
1940 default:
thsf01be152008-09-18 11:57:27 +00001941 t0 = (int32_t)env->active_fpu.fcr31;
thsead93602007-09-06 00:18:15 +00001942 break;
1943 }
thsbe24bb42008-06-23 12:57:09 +00001944
1945 return t0;
thsead93602007-09-06 00:18:15 +00001946}
1947
thsbe24bb42008-06-23 12:57:09 +00001948void do_ctc1 (target_ulong t0, uint32_t reg)
thsead93602007-09-06 00:18:15 +00001949{
1950 switch(reg) {
thsfd4a04e2007-05-18 11:55:54 +00001951 case 25:
thsbe24bb42008-06-23 12:57:09 +00001952 if (t0 & 0xffffff00)
thsfd4a04e2007-05-18 11:55:54 +00001953 return;
thsf01be152008-09-18 11:57:27 +00001954 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0x017fffff) | ((t0 & 0xfe) << 24) |
thsbe24bb42008-06-23 12:57:09 +00001955 ((t0 & 0x1) << 23);
thsfd4a04e2007-05-18 11:55:54 +00001956 break;
1957 case 26:
thsbe24bb42008-06-23 12:57:09 +00001958 if (t0 & 0x007c0000)
thsfd4a04e2007-05-18 11:55:54 +00001959 return;
thsf01be152008-09-18 11:57:27 +00001960 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfffc0f83) | (t0 & 0x0003f07c);
thsfd4a04e2007-05-18 11:55:54 +00001961 break;
1962 case 28:
thsbe24bb42008-06-23 12:57:09 +00001963 if (t0 & 0x007c0000)
thsfd4a04e2007-05-18 11:55:54 +00001964 return;
thsf01be152008-09-18 11:57:27 +00001965 env->active_fpu.fcr31 = (env->active_fpu.fcr31 & 0xfefff07c) | (t0 & 0x00000f83) |
thsbe24bb42008-06-23 12:57:09 +00001966 ((t0 & 0x4) << 22);
thsfd4a04e2007-05-18 11:55:54 +00001967 break;
1968 case 31:
thsbe24bb42008-06-23 12:57:09 +00001969 if (t0 & 0x007c0000)
thsfd4a04e2007-05-18 11:55:54 +00001970 return;
thsf01be152008-09-18 11:57:27 +00001971 env->active_fpu.fcr31 = t0;
thsfd4a04e2007-05-18 11:55:54 +00001972 break;
1973 default:
1974 return;
1975 }
1976 /* set rounding mode */
1977 RESTORE_ROUNDING_MODE;
thsf01be152008-09-18 11:57:27 +00001978 set_float_exception_flags(0, &env->active_fpu.fp_status);
1979 if ((GET_FP_ENABLE(env->active_fpu.fcr31) | 0x20) & GET_FP_CAUSE(env->active_fpu.fcr31))
thsfd4a04e2007-05-18 11:55:54 +00001980 do_raise_exception(EXCP_FPE);
1981}
1982
thsc904ef02008-07-23 16:16:31 +00001983static inline char ieee_ex_to_mips(char xcpt)
thsfd4a04e2007-05-18 11:55:54 +00001984{
1985 return (xcpt & float_flag_inexact) >> 5 |
1986 (xcpt & float_flag_underflow) >> 3 |
1987 (xcpt & float_flag_overflow) >> 1 |
1988 (xcpt & float_flag_divbyzero) << 1 |
1989 (xcpt & float_flag_invalid) << 4;
1990}
1991
thsc904ef02008-07-23 16:16:31 +00001992static inline char mips_ex_to_ieee(char xcpt)
thsfd4a04e2007-05-18 11:55:54 +00001993{
1994 return (xcpt & FP_INEXACT) << 5 |
1995 (xcpt & FP_UNDERFLOW) << 3 |
1996 (xcpt & FP_OVERFLOW) << 1 |
1997 (xcpt & FP_DIV0) >> 1 |
1998 (xcpt & FP_INVALID) >> 4;
1999}
2000
thsc904ef02008-07-23 16:16:31 +00002001static inline void update_fcr31(void)
thsfd4a04e2007-05-18 11:55:54 +00002002{
thsf01be152008-09-18 11:57:27 +00002003 int tmp = ieee_ex_to_mips(get_float_exception_flags(&env->active_fpu.fp_status));
thsfd4a04e2007-05-18 11:55:54 +00002004
thsf01be152008-09-18 11:57:27 +00002005 SET_FP_CAUSE(env->active_fpu.fcr31, tmp);
2006 if (GET_FP_ENABLE(env->active_fpu.fcr31) & tmp)
thsfd4a04e2007-05-18 11:55:54 +00002007 do_raise_exception(EXCP_FPE);
2008 else
thsf01be152008-09-18 11:57:27 +00002009 UPDATE_FP_FLAGS(env->active_fpu.fcr31, tmp);
thsfd4a04e2007-05-18 11:55:54 +00002010}
2011
thsa16336e2008-06-19 18:35:02 +00002012/* Float support.
2013 Single precition routines have a "s" suffix, double precision a
2014 "d" suffix, 32bit integer "w", 64bit integer "l", paired single "ps",
2015 paired single lower "pl", paired single upper "pu". */
2016
thsa16336e2008-06-19 18:35:02 +00002017/* unary operations, modifying fp status */
thsb6d96be2008-07-09 11:05:10 +00002018uint64_t do_float_sqrt_d(uint64_t fdt0)
thsfd4a04e2007-05-18 11:55:54 +00002019{
thsf01be152008-09-18 11:57:27 +00002020 return float64_sqrt(fdt0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002021}
2022
thsb6d96be2008-07-09 11:05:10 +00002023uint32_t do_float_sqrt_s(uint32_t fst0)
thsfd4a04e2007-05-18 11:55:54 +00002024{
thsf01be152008-09-18 11:57:27 +00002025 return float32_sqrt(fst0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002026}
2027
thsb6d96be2008-07-09 11:05:10 +00002028uint64_t do_float_cvtd_s(uint32_t fst0)
thsfd4a04e2007-05-18 11:55:54 +00002029{
thsb6d96be2008-07-09 11:05:10 +00002030 uint64_t fdt2;
2031
thsf01be152008-09-18 11:57:27 +00002032 set_float_exception_flags(0, &env->active_fpu.fp_status);
2033 fdt2 = float32_to_float64(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002034 update_fcr31();
2035 return fdt2;
2036}
2037
2038uint64_t do_float_cvtd_w(uint32_t wt0)
2039{
2040 uint64_t fdt2;
2041
thsf01be152008-09-18 11:57:27 +00002042 set_float_exception_flags(0, &env->active_fpu.fp_status);
2043 fdt2 = int32_to_float64(wt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002044 update_fcr31();
2045 return fdt2;
2046}
2047
2048uint64_t do_float_cvtd_l(uint64_t dt0)
2049{
2050 uint64_t fdt2;
2051
thsf01be152008-09-18 11:57:27 +00002052 set_float_exception_flags(0, &env->active_fpu.fp_status);
2053 fdt2 = int64_to_float64(dt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002054 update_fcr31();
2055 return fdt2;
2056}
2057
2058uint64_t do_float_cvtl_d(uint64_t fdt0)
2059{
2060 uint64_t dt2;
2061
thsf01be152008-09-18 11:57:27 +00002062 set_float_exception_flags(0, &env->active_fpu.fp_status);
2063 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002064 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002065 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002066 dt2 = FLOAT_SNAN64;
2067 return dt2;
2068}
2069
2070uint64_t do_float_cvtl_s(uint32_t fst0)
2071{
2072 uint64_t dt2;
2073
thsf01be152008-09-18 11:57:27 +00002074 set_float_exception_flags(0, &env->active_fpu.fp_status);
2075 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002076 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002077 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002078 dt2 = FLOAT_SNAN64;
2079 return dt2;
2080}
2081
2082uint64_t do_float_cvtps_pw(uint64_t dt0)
2083{
2084 uint32_t fst2;
2085 uint32_t fsth2;
2086
thsf01be152008-09-18 11:57:27 +00002087 set_float_exception_flags(0, &env->active_fpu.fp_status);
2088 fst2 = int32_to_float32(dt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2089 fsth2 = int32_to_float32(dt0 >> 32, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002090 update_fcr31();
2091 return ((uint64_t)fsth2 << 32) | fst2;
2092}
2093
2094uint64_t do_float_cvtpw_ps(uint64_t fdt0)
2095{
2096 uint32_t wt2;
2097 uint32_t wth2;
2098
thsf01be152008-09-18 11:57:27 +00002099 set_float_exception_flags(0, &env->active_fpu.fp_status);
2100 wt2 = float32_to_int32(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2101 wth2 = float32_to_int32(fdt0 >> 32, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002102 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002103 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID)) {
thsb6d96be2008-07-09 11:05:10 +00002104 wt2 = FLOAT_SNAN32;
2105 wth2 = FLOAT_SNAN32;
2106 }
2107 return ((uint64_t)wth2 << 32) | wt2;
2108}
2109
2110uint32_t do_float_cvts_d(uint64_t fdt0)
2111{
2112 uint32_t fst2;
2113
thsf01be152008-09-18 11:57:27 +00002114 set_float_exception_flags(0, &env->active_fpu.fp_status);
2115 fst2 = float64_to_float32(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002116 update_fcr31();
2117 return fst2;
2118}
2119
2120uint32_t do_float_cvts_w(uint32_t wt0)
2121{
2122 uint32_t fst2;
2123
thsf01be152008-09-18 11:57:27 +00002124 set_float_exception_flags(0, &env->active_fpu.fp_status);
2125 fst2 = int32_to_float32(wt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002126 update_fcr31();
2127 return fst2;
2128}
2129
2130uint32_t do_float_cvts_l(uint64_t dt0)
2131{
2132 uint32_t fst2;
2133
thsf01be152008-09-18 11:57:27 +00002134 set_float_exception_flags(0, &env->active_fpu.fp_status);
2135 fst2 = int64_to_float32(dt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002136 update_fcr31();
2137 return fst2;
2138}
2139
2140uint32_t do_float_cvts_pl(uint32_t wt0)
2141{
2142 uint32_t wt2;
2143
thsf01be152008-09-18 11:57:27 +00002144 set_float_exception_flags(0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002145 wt2 = wt0;
2146 update_fcr31();
2147 return wt2;
2148}
2149
2150uint32_t do_float_cvts_pu(uint32_t wth0)
2151{
2152 uint32_t wt2;
2153
thsf01be152008-09-18 11:57:27 +00002154 set_float_exception_flags(0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002155 wt2 = wth0;
2156 update_fcr31();
2157 return wt2;
2158}
2159
2160uint32_t do_float_cvtw_s(uint32_t fst0)
2161{
2162 uint32_t wt2;
2163
thsf01be152008-09-18 11:57:27 +00002164 set_float_exception_flags(0, &env->active_fpu.fp_status);
2165 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002166 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002167 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002168 wt2 = FLOAT_SNAN32;
2169 return wt2;
2170}
2171
2172uint32_t do_float_cvtw_d(uint64_t fdt0)
2173{
2174 uint32_t wt2;
2175
thsf01be152008-09-18 11:57:27 +00002176 set_float_exception_flags(0, &env->active_fpu.fp_status);
2177 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002178 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002179 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002180 wt2 = FLOAT_SNAN32;
2181 return wt2;
2182}
2183
2184uint64_t do_float_roundl_d(uint64_t fdt0)
2185{
2186 uint64_t dt2;
2187
thsf01be152008-09-18 11:57:27 +00002188 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2189 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002190 RESTORE_ROUNDING_MODE;
2191 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002192 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002193 dt2 = FLOAT_SNAN64;
2194 return dt2;
thsfd4a04e2007-05-18 11:55:54 +00002195}
2196
thsb6d96be2008-07-09 11:05:10 +00002197uint64_t do_float_roundl_s(uint32_t fst0)
thsfd4a04e2007-05-18 11:55:54 +00002198{
thsb6d96be2008-07-09 11:05:10 +00002199 uint64_t dt2;
2200
thsf01be152008-09-18 11:57:27 +00002201 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2202 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002203 RESTORE_ROUNDING_MODE;
thsfd4a04e2007-05-18 11:55:54 +00002204 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002205 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002206 dt2 = FLOAT_SNAN64;
2207 return dt2;
thsfd4a04e2007-05-18 11:55:54 +00002208}
2209
thsb6d96be2008-07-09 11:05:10 +00002210uint32_t do_float_roundw_d(uint64_t fdt0)
thsfd4a04e2007-05-18 11:55:54 +00002211{
thsb6d96be2008-07-09 11:05:10 +00002212 uint32_t wt2;
2213
thsf01be152008-09-18 11:57:27 +00002214 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2215 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002216 RESTORE_ROUNDING_MODE;
2217 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002218 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002219 wt2 = FLOAT_SNAN32;
2220 return wt2;
thsfd4a04e2007-05-18 11:55:54 +00002221}
2222
thsb6d96be2008-07-09 11:05:10 +00002223uint32_t do_float_roundw_s(uint32_t fst0)
thsfd4a04e2007-05-18 11:55:54 +00002224{
thsb6d96be2008-07-09 11:05:10 +00002225 uint32_t wt2;
2226
thsf01be152008-09-18 11:57:27 +00002227 set_float_rounding_mode(float_round_nearest_even, &env->active_fpu.fp_status);
2228 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002229 RESTORE_ROUNDING_MODE;
2230 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002231 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002232 wt2 = FLOAT_SNAN32;
2233 return wt2;
thsfd4a04e2007-05-18 11:55:54 +00002234}
thsb6d96be2008-07-09 11:05:10 +00002235
2236uint64_t do_float_truncl_d(uint64_t fdt0)
thsfd4a04e2007-05-18 11:55:54 +00002237{
thsb6d96be2008-07-09 11:05:10 +00002238 uint64_t dt2;
2239
thsf01be152008-09-18 11:57:27 +00002240 dt2 = float64_to_int64_round_to_zero(fdt0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002241 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002242 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002243 dt2 = FLOAT_SNAN64;
2244 return dt2;
thsfd4a04e2007-05-18 11:55:54 +00002245}
thsb6d96be2008-07-09 11:05:10 +00002246
2247uint64_t do_float_truncl_s(uint32_t fst0)
thsfd4a04e2007-05-18 11:55:54 +00002248{
thsb6d96be2008-07-09 11:05:10 +00002249 uint64_t dt2;
2250
thsf01be152008-09-18 11:57:27 +00002251 dt2 = float32_to_int64_round_to_zero(fst0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002252 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002253 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002254 dt2 = FLOAT_SNAN64;
2255 return dt2;
thsfd4a04e2007-05-18 11:55:54 +00002256}
thsb6d96be2008-07-09 11:05:10 +00002257
2258uint32_t do_float_truncw_d(uint64_t fdt0)
thsfd4a04e2007-05-18 11:55:54 +00002259{
thsb6d96be2008-07-09 11:05:10 +00002260 uint32_t wt2;
2261
thsf01be152008-09-18 11:57:27 +00002262 wt2 = float64_to_int32_round_to_zero(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002263 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002264 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002265 wt2 = FLOAT_SNAN32;
2266 return wt2;
2267}
2268
2269uint32_t do_float_truncw_s(uint32_t fst0)
2270{
2271 uint32_t wt2;
2272
thsf01be152008-09-18 11:57:27 +00002273 wt2 = float32_to_int32_round_to_zero(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002274 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002275 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002276 wt2 = FLOAT_SNAN32;
2277 return wt2;
2278}
2279
2280uint64_t do_float_ceill_d(uint64_t fdt0)
2281{
2282 uint64_t dt2;
2283
thsf01be152008-09-18 11:57:27 +00002284 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2285 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
thsfd4a04e2007-05-18 11:55:54 +00002286 RESTORE_ROUNDING_MODE;
2287 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002288 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002289 dt2 = FLOAT_SNAN64;
2290 return dt2;
2291}
2292
2293uint64_t do_float_ceill_s(uint32_t fst0)
2294{
2295 uint64_t dt2;
2296
thsf01be152008-09-18 11:57:27 +00002297 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2298 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002299 RESTORE_ROUNDING_MODE;
2300 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002301 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002302 dt2 = FLOAT_SNAN64;
2303 return dt2;
2304}
2305
2306uint32_t do_float_ceilw_d(uint64_t fdt0)
2307{
2308 uint32_t wt2;
2309
thsf01be152008-09-18 11:57:27 +00002310 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2311 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002312 RESTORE_ROUNDING_MODE;
2313 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002314 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002315 wt2 = FLOAT_SNAN32;
2316 return wt2;
2317}
2318
2319uint32_t do_float_ceilw_s(uint32_t fst0)
2320{
2321 uint32_t wt2;
2322
thsf01be152008-09-18 11:57:27 +00002323 set_float_rounding_mode(float_round_up, &env->active_fpu.fp_status);
2324 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002325 RESTORE_ROUNDING_MODE;
2326 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002327 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002328 wt2 = FLOAT_SNAN32;
2329 return wt2;
2330}
2331
2332uint64_t do_float_floorl_d(uint64_t fdt0)
2333{
2334 uint64_t dt2;
2335
thsf01be152008-09-18 11:57:27 +00002336 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2337 dt2 = float64_to_int64(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002338 RESTORE_ROUNDING_MODE;
2339 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002340 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002341 dt2 = FLOAT_SNAN64;
2342 return dt2;
2343}
2344
2345uint64_t do_float_floorl_s(uint32_t fst0)
2346{
2347 uint64_t dt2;
2348
thsf01be152008-09-18 11:57:27 +00002349 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2350 dt2 = float32_to_int64(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002351 RESTORE_ROUNDING_MODE;
2352 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002353 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002354 dt2 = FLOAT_SNAN64;
2355 return dt2;
2356}
2357
2358uint32_t do_float_floorw_d(uint64_t fdt0)
2359{
2360 uint32_t wt2;
2361
thsf01be152008-09-18 11:57:27 +00002362 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2363 wt2 = float64_to_int32(fdt0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002364 RESTORE_ROUNDING_MODE;
2365 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002366 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002367 wt2 = FLOAT_SNAN32;
2368 return wt2;
2369}
2370
2371uint32_t do_float_floorw_s(uint32_t fst0)
2372{
2373 uint32_t wt2;
2374
thsf01be152008-09-18 11:57:27 +00002375 set_float_rounding_mode(float_round_down, &env->active_fpu.fp_status);
2376 wt2 = float32_to_int32(fst0, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002377 RESTORE_ROUNDING_MODE;
2378 update_fcr31();
thsf01be152008-09-18 11:57:27 +00002379 if (GET_FP_CAUSE(env->active_fpu.fcr31) & (FP_OVERFLOW | FP_INVALID))
thsb6d96be2008-07-09 11:05:10 +00002380 wt2 = FLOAT_SNAN32;
2381 return wt2;
thsfd4a04e2007-05-18 11:55:54 +00002382}
2383
thsa16336e2008-06-19 18:35:02 +00002384/* unary operations, not modifying fp status */
thsb6d96be2008-07-09 11:05:10 +00002385#define FLOAT_UNOP(name) \
2386uint64_t do_float_ ## name ## _d(uint64_t fdt0) \
2387{ \
2388 return float64_ ## name(fdt0); \
2389} \
2390uint32_t do_float_ ## name ## _s(uint32_t fst0) \
2391{ \
2392 return float32_ ## name(fst0); \
2393} \
2394uint64_t do_float_ ## name ## _ps(uint64_t fdt0) \
2395{ \
2396 uint32_t wt0; \
2397 uint32_t wth0; \
2398 \
2399 wt0 = float32_ ## name(fdt0 & 0XFFFFFFFF); \
2400 wth0 = float32_ ## name(fdt0 >> 32); \
2401 return ((uint64_t)wth0 << 32) | wt0; \
thsa16336e2008-06-19 18:35:02 +00002402}
2403FLOAT_UNOP(abs)
2404FLOAT_UNOP(chs)
2405#undef FLOAT_UNOP
2406
ths8dfdb872007-06-26 20:26:03 +00002407/* MIPS specific unary operations */
thsb6d96be2008-07-09 11:05:10 +00002408uint64_t do_float_recip_d(uint64_t fdt0)
ths8dfdb872007-06-26 20:26:03 +00002409{
thsb6d96be2008-07-09 11:05:10 +00002410 uint64_t fdt2;
2411
thsf01be152008-09-18 11:57:27 +00002412 set_float_exception_flags(0, &env->active_fpu.fp_status);
2413 fdt2 = float64_div(FLOAT_ONE64, fdt0, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002414 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002415 return fdt2;
ths8dfdb872007-06-26 20:26:03 +00002416}
ths57fa1fb2007-05-19 20:29:41 +00002417
thsb6d96be2008-07-09 11:05:10 +00002418uint32_t do_float_recip_s(uint32_t fst0)
ths8dfdb872007-06-26 20:26:03 +00002419{
thsb6d96be2008-07-09 11:05:10 +00002420 uint32_t fst2;
2421
thsf01be152008-09-18 11:57:27 +00002422 set_float_exception_flags(0, &env->active_fpu.fp_status);
2423 fst2 = float32_div(FLOAT_ONE32, fst0, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002424 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002425 return fst2;
ths8dfdb872007-06-26 20:26:03 +00002426}
2427
thsb6d96be2008-07-09 11:05:10 +00002428uint64_t do_float_rsqrt_d(uint64_t fdt0)
ths8dfdb872007-06-26 20:26:03 +00002429{
thsb6d96be2008-07-09 11:05:10 +00002430 uint64_t fdt2;
2431
thsf01be152008-09-18 11:57:27 +00002432 set_float_exception_flags(0, &env->active_fpu.fp_status);
2433 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
2434 fdt2 = float64_div(FLOAT_ONE64, fdt2, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002435 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002436 return fdt2;
ths8dfdb872007-06-26 20:26:03 +00002437}
2438
thsb6d96be2008-07-09 11:05:10 +00002439uint32_t do_float_rsqrt_s(uint32_t fst0)
ths8dfdb872007-06-26 20:26:03 +00002440{
thsb6d96be2008-07-09 11:05:10 +00002441 uint32_t fst2;
2442
thsf01be152008-09-18 11:57:27 +00002443 set_float_exception_flags(0, &env->active_fpu.fp_status);
2444 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
2445 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002446 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002447 return fst2;
ths8dfdb872007-06-26 20:26:03 +00002448}
thsb6d96be2008-07-09 11:05:10 +00002449
2450uint64_t do_float_recip1_d(uint64_t fdt0)
ths8dfdb872007-06-26 20:26:03 +00002451{
thsb6d96be2008-07-09 11:05:10 +00002452 uint64_t fdt2;
2453
thsf01be152008-09-18 11:57:27 +00002454 set_float_exception_flags(0, &env->active_fpu.fp_status);
2455 fdt2 = float64_div(FLOAT_ONE64, fdt0, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002456 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002457 return fdt2;
ths8dfdb872007-06-26 20:26:03 +00002458}
thsb6d96be2008-07-09 11:05:10 +00002459
2460uint32_t do_float_recip1_s(uint32_t fst0)
ths8dfdb872007-06-26 20:26:03 +00002461{
thsb6d96be2008-07-09 11:05:10 +00002462 uint32_t fst2;
2463
thsf01be152008-09-18 11:57:27 +00002464 set_float_exception_flags(0, &env->active_fpu.fp_status);
2465 fst2 = float32_div(FLOAT_ONE32, fst0, &env->active_fpu.fp_status);
ths8dfdb872007-06-26 20:26:03 +00002466 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002467 return fst2;
ths8dfdb872007-06-26 20:26:03 +00002468}
ths57fa1fb2007-05-19 20:29:41 +00002469
thsb6d96be2008-07-09 11:05:10 +00002470uint64_t do_float_recip1_ps(uint64_t fdt0)
2471{
2472 uint32_t fst2;
2473 uint32_t fsth2;
2474
thsf01be152008-09-18 11:57:27 +00002475 set_float_exception_flags(0, &env->active_fpu.fp_status);
2476 fst2 = float32_div(FLOAT_ONE32, fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2477 fsth2 = float32_div(FLOAT_ONE32, fdt0 >> 32, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002478 update_fcr31();
2479 return ((uint64_t)fsth2 << 32) | fst2;
2480}
2481
2482uint64_t do_float_rsqrt1_d(uint64_t fdt0)
2483{
2484 uint64_t fdt2;
2485
thsf01be152008-09-18 11:57:27 +00002486 set_float_exception_flags(0, &env->active_fpu.fp_status);
2487 fdt2 = float64_sqrt(fdt0, &env->active_fpu.fp_status);
2488 fdt2 = float64_div(FLOAT_ONE64, fdt2, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002489 update_fcr31();
2490 return fdt2;
2491}
2492
2493uint32_t do_float_rsqrt1_s(uint32_t fst0)
2494{
2495 uint32_t fst2;
2496
thsf01be152008-09-18 11:57:27 +00002497 set_float_exception_flags(0, &env->active_fpu.fp_status);
2498 fst2 = float32_sqrt(fst0, &env->active_fpu.fp_status);
2499 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002500 update_fcr31();
2501 return fst2;
2502}
2503
2504uint64_t do_float_rsqrt1_ps(uint64_t fdt0)
2505{
2506 uint32_t fst2;
2507 uint32_t fsth2;
2508
thsf01be152008-09-18 11:57:27 +00002509 set_float_exception_flags(0, &env->active_fpu.fp_status);
2510 fst2 = float32_sqrt(fdt0 & 0XFFFFFFFF, &env->active_fpu.fp_status);
2511 fsth2 = float32_sqrt(fdt0 >> 32, &env->active_fpu.fp_status);
2512 fst2 = float32_div(FLOAT_ONE32, fst2, &env->active_fpu.fp_status);
2513 fsth2 = float32_div(FLOAT_ONE32, fsth2, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002514 update_fcr31();
2515 return ((uint64_t)fsth2 << 32) | fst2;
2516}
2517
2518#define FLOAT_OP(name, p) void do_float_##name##_##p(void)
2519
thsfd4a04e2007-05-18 11:55:54 +00002520/* binary operations */
thsb6d96be2008-07-09 11:05:10 +00002521#define FLOAT_BINOP(name) \
2522uint64_t do_float_ ## name ## _d(uint64_t fdt0, uint64_t fdt1) \
2523{ \
2524 uint64_t dt2; \
2525 \
thsf01be152008-09-18 11:57:27 +00002526 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2527 dt2 = float64_ ## name (fdt0, fdt1, &env->active_fpu.fp_status); \
thsead93602007-09-06 00:18:15 +00002528 update_fcr31(); \
thsf01be152008-09-18 11:57:27 +00002529 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
thsb6d96be2008-07-09 11:05:10 +00002530 dt2 = FLOAT_QNAN64; \
2531 return dt2; \
2532} \
2533 \
2534uint32_t do_float_ ## name ## _s(uint32_t fst0, uint32_t fst1) \
2535{ \
2536 uint32_t wt2; \
2537 \
thsf01be152008-09-18 11:57:27 +00002538 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2539 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
thsead93602007-09-06 00:18:15 +00002540 update_fcr31(); \
thsf01be152008-09-18 11:57:27 +00002541 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) \
thsb6d96be2008-07-09 11:05:10 +00002542 wt2 = FLOAT_QNAN32; \
2543 return wt2; \
2544} \
2545 \
2546uint64_t do_float_ ## name ## _ps(uint64_t fdt0, uint64_t fdt1) \
2547{ \
2548 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2549 uint32_t fsth0 = fdt0 >> 32; \
2550 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2551 uint32_t fsth1 = fdt1 >> 32; \
2552 uint32_t wt2; \
2553 uint32_t wth2; \
2554 \
thsf01be152008-09-18 11:57:27 +00002555 set_float_exception_flags(0, &env->active_fpu.fp_status); \
2556 wt2 = float32_ ## name (fst0, fst1, &env->active_fpu.fp_status); \
2557 wth2 = float32_ ## name (fsth0, fsth1, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002558 update_fcr31(); \
thsf01be152008-09-18 11:57:27 +00002559 if (GET_FP_CAUSE(env->active_fpu.fcr31) & FP_INVALID) { \
thsb6d96be2008-07-09 11:05:10 +00002560 wt2 = FLOAT_QNAN32; \
2561 wth2 = FLOAT_QNAN32; \
2562 } \
2563 return ((uint64_t)wth2 << 32) | wt2; \
thsfd4a04e2007-05-18 11:55:54 +00002564}
thsb6d96be2008-07-09 11:05:10 +00002565
thsfd4a04e2007-05-18 11:55:54 +00002566FLOAT_BINOP(add)
2567FLOAT_BINOP(sub)
2568FLOAT_BINOP(mul)
2569FLOAT_BINOP(div)
2570#undef FLOAT_BINOP
2571
thsa16336e2008-06-19 18:35:02 +00002572/* ternary operations */
thsb6d96be2008-07-09 11:05:10 +00002573#define FLOAT_TERNOP(name1, name2) \
2574uint64_t do_float_ ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2575 uint64_t fdt2) \
2576{ \
thsf01be152008-09-18 11:57:27 +00002577 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2578 return float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002579} \
2580 \
2581uint32_t do_float_ ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2582 uint32_t fst2) \
2583{ \
thsf01be152008-09-18 11:57:27 +00002584 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2585 return float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002586} \
2587 \
2588uint64_t do_float_ ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1, \
2589 uint64_t fdt2) \
2590{ \
2591 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2592 uint32_t fsth0 = fdt0 >> 32; \
2593 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2594 uint32_t fsth1 = fdt1 >> 32; \
2595 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2596 uint32_t fsth2 = fdt2 >> 32; \
2597 \
thsf01be152008-09-18 11:57:27 +00002598 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2599 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2600 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2601 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002602 return ((uint64_t)fsth2 << 32) | fst2; \
thsa16336e2008-06-19 18:35:02 +00002603}
thsb6d96be2008-07-09 11:05:10 +00002604
thsa16336e2008-06-19 18:35:02 +00002605FLOAT_TERNOP(mul, add)
2606FLOAT_TERNOP(mul, sub)
2607#undef FLOAT_TERNOP
2608
2609/* negated ternary operations */
thsb6d96be2008-07-09 11:05:10 +00002610#define FLOAT_NTERNOP(name1, name2) \
2611uint64_t do_float_n ## name1 ## name2 ## _d(uint64_t fdt0, uint64_t fdt1, \
2612 uint64_t fdt2) \
2613{ \
thsf01be152008-09-18 11:57:27 +00002614 fdt0 = float64_ ## name1 (fdt0, fdt1, &env->active_fpu.fp_status); \
2615 fdt2 = float64_ ## name2 (fdt0, fdt2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002616 return float64_chs(fdt2); \
2617} \
2618 \
2619uint32_t do_float_n ## name1 ## name2 ## _s(uint32_t fst0, uint32_t fst1, \
2620 uint32_t fst2) \
2621{ \
thsf01be152008-09-18 11:57:27 +00002622 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2623 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002624 return float32_chs(fst2); \
2625} \
2626 \
2627uint64_t do_float_n ## name1 ## name2 ## _ps(uint64_t fdt0, uint64_t fdt1,\
2628 uint64_t fdt2) \
2629{ \
2630 uint32_t fst0 = fdt0 & 0XFFFFFFFF; \
2631 uint32_t fsth0 = fdt0 >> 32; \
2632 uint32_t fst1 = fdt1 & 0XFFFFFFFF; \
2633 uint32_t fsth1 = fdt1 >> 32; \
2634 uint32_t fst2 = fdt2 & 0XFFFFFFFF; \
2635 uint32_t fsth2 = fdt2 >> 32; \
2636 \
thsf01be152008-09-18 11:57:27 +00002637 fst0 = float32_ ## name1 (fst0, fst1, &env->active_fpu.fp_status); \
2638 fsth0 = float32_ ## name1 (fsth0, fsth1, &env->active_fpu.fp_status); \
2639 fst2 = float32_ ## name2 (fst0, fst2, &env->active_fpu.fp_status); \
2640 fsth2 = float32_ ## name2 (fsth0, fsth2, &env->active_fpu.fp_status); \
thsb6d96be2008-07-09 11:05:10 +00002641 fst2 = float32_chs(fst2); \
2642 fsth2 = float32_chs(fsth2); \
2643 return ((uint64_t)fsth2 << 32) | fst2; \
thsa16336e2008-06-19 18:35:02 +00002644}
thsb6d96be2008-07-09 11:05:10 +00002645
thsa16336e2008-06-19 18:35:02 +00002646FLOAT_NTERNOP(mul, add)
2647FLOAT_NTERNOP(mul, sub)
2648#undef FLOAT_NTERNOP
2649
ths8dfdb872007-06-26 20:26:03 +00002650/* MIPS specific binary operations */
thsb6d96be2008-07-09 11:05:10 +00002651uint64_t do_float_recip2_d(uint64_t fdt0, uint64_t fdt2)
ths8dfdb872007-06-26 20:26:03 +00002652{
thsf01be152008-09-18 11:57:27 +00002653 set_float_exception_flags(0, &env->active_fpu.fp_status);
2654 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
2655 fdt2 = float64_chs(float64_sub(fdt2, FLOAT_ONE64, &env->active_fpu.fp_status));
ths8dfdb872007-06-26 20:26:03 +00002656 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002657 return fdt2;
ths8dfdb872007-06-26 20:26:03 +00002658}
2659
thsb6d96be2008-07-09 11:05:10 +00002660uint32_t do_float_recip2_s(uint32_t fst0, uint32_t fst2)
ths8dfdb872007-06-26 20:26:03 +00002661{
thsf01be152008-09-18 11:57:27 +00002662 set_float_exception_flags(0, &env->active_fpu.fp_status);
2663 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
2664 fst2 = float32_chs(float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status));
ths8dfdb872007-06-26 20:26:03 +00002665 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002666 return fst2;
ths8dfdb872007-06-26 20:26:03 +00002667}
ths57fa1fb2007-05-19 20:29:41 +00002668
thsb6d96be2008-07-09 11:05:10 +00002669uint64_t do_float_recip2_ps(uint64_t fdt0, uint64_t fdt2)
thsfd4a04e2007-05-18 11:55:54 +00002670{
thsb6d96be2008-07-09 11:05:10 +00002671 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
2672 uint32_t fsth0 = fdt0 >> 32;
2673 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
2674 uint32_t fsth2 = fdt2 >> 32;
2675
thsf01be152008-09-18 11:57:27 +00002676 set_float_exception_flags(0, &env->active_fpu.fp_status);
2677 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
2678 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
2679 fst2 = float32_chs(float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status));
2680 fsth2 = float32_chs(float32_sub(fsth2, FLOAT_ONE32, &env->active_fpu.fp_status));
thsfd4a04e2007-05-18 11:55:54 +00002681 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002682 return ((uint64_t)fsth2 << 32) | fst2;
thsfd4a04e2007-05-18 11:55:54 +00002683}
2684
thsb6d96be2008-07-09 11:05:10 +00002685uint64_t do_float_rsqrt2_d(uint64_t fdt0, uint64_t fdt2)
ths57fa1fb2007-05-19 20:29:41 +00002686{
thsf01be152008-09-18 11:57:27 +00002687 set_float_exception_flags(0, &env->active_fpu.fp_status);
2688 fdt2 = float64_mul(fdt0, fdt2, &env->active_fpu.fp_status);
2689 fdt2 = float64_sub(fdt2, FLOAT_ONE64, &env->active_fpu.fp_status);
2690 fdt2 = float64_chs(float64_div(fdt2, FLOAT_TWO64, &env->active_fpu.fp_status));
ths57fa1fb2007-05-19 20:29:41 +00002691 update_fcr31();
thsb6d96be2008-07-09 11:05:10 +00002692 return fdt2;
2693}
2694
2695uint32_t do_float_rsqrt2_s(uint32_t fst0, uint32_t fst2)
2696{
thsf01be152008-09-18 11:57:27 +00002697 set_float_exception_flags(0, &env->active_fpu.fp_status);
2698 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
2699 fst2 = float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status);
2700 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32, &env->active_fpu.fp_status));
thsb6d96be2008-07-09 11:05:10 +00002701 update_fcr31();
2702 return fst2;
2703}
2704
2705uint64_t do_float_rsqrt2_ps(uint64_t fdt0, uint64_t fdt2)
2706{
2707 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
2708 uint32_t fsth0 = fdt0 >> 32;
2709 uint32_t fst2 = fdt2 & 0XFFFFFFFF;
2710 uint32_t fsth2 = fdt2 >> 32;
2711
thsf01be152008-09-18 11:57:27 +00002712 set_float_exception_flags(0, &env->active_fpu.fp_status);
2713 fst2 = float32_mul(fst0, fst2, &env->active_fpu.fp_status);
2714 fsth2 = float32_mul(fsth0, fsth2, &env->active_fpu.fp_status);
2715 fst2 = float32_sub(fst2, FLOAT_ONE32, &env->active_fpu.fp_status);
2716 fsth2 = float32_sub(fsth2, FLOAT_ONE32, &env->active_fpu.fp_status);
2717 fst2 = float32_chs(float32_div(fst2, FLOAT_TWO32, &env->active_fpu.fp_status));
2718 fsth2 = float32_chs(float32_div(fsth2, FLOAT_TWO32, &env->active_fpu.fp_status));
thsb6d96be2008-07-09 11:05:10 +00002719 update_fcr31();
2720 return ((uint64_t)fsth2 << 32) | fst2;
2721}
2722
2723uint64_t do_float_addr_ps(uint64_t fdt0, uint64_t fdt1)
2724{
2725 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
2726 uint32_t fsth0 = fdt0 >> 32;
2727 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
2728 uint32_t fsth1 = fdt1 >> 32;
2729 uint32_t fst2;
2730 uint32_t fsth2;
2731
thsf01be152008-09-18 11:57:27 +00002732 set_float_exception_flags(0, &env->active_fpu.fp_status);
2733 fst2 = float32_add (fst0, fsth0, &env->active_fpu.fp_status);
2734 fsth2 = float32_add (fst1, fsth1, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002735 update_fcr31();
2736 return ((uint64_t)fsth2 << 32) | fst2;
2737}
2738
2739uint64_t do_float_mulr_ps(uint64_t fdt0, uint64_t fdt1)
2740{
2741 uint32_t fst0 = fdt0 & 0XFFFFFFFF;
2742 uint32_t fsth0 = fdt0 >> 32;
2743 uint32_t fst1 = fdt1 & 0XFFFFFFFF;
2744 uint32_t fsth1 = fdt1 >> 32;
2745 uint32_t fst2;
2746 uint32_t fsth2;
2747
thsf01be152008-09-18 11:57:27 +00002748 set_float_exception_flags(0, &env->active_fpu.fp_status);
2749 fst2 = float32_mul (fst0, fsth0, &env->active_fpu.fp_status);
2750 fsth2 = float32_mul (fst1, fsth1, &env->active_fpu.fp_status);
thsb6d96be2008-07-09 11:05:10 +00002751 update_fcr31();
2752 return ((uint64_t)fsth2 << 32) | fst2;
ths57fa1fb2007-05-19 20:29:41 +00002753}
2754
ths8dfdb872007-06-26 20:26:03 +00002755/* compare operations */
thsb6d96be2008-07-09 11:05:10 +00002756#define FOP_COND_D(op, cond) \
2757void do_cmp_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2758{ \
2759 int c = cond; \
2760 update_fcr31(); \
2761 if (c) \
thsf01be152008-09-18 11:57:27 +00002762 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002763 else \
thsf01be152008-09-18 11:57:27 +00002764 CLEAR_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002765} \
2766void do_cmpabs_d_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2767{ \
2768 int c; \
2769 fdt0 = float64_abs(fdt0); \
2770 fdt1 = float64_abs(fdt1); \
2771 c = cond; \
2772 update_fcr31(); \
2773 if (c) \
thsf01be152008-09-18 11:57:27 +00002774 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002775 else \
thsf01be152008-09-18 11:57:27 +00002776 CLEAR_FP_COND(cc, env->active_fpu); \
thsfd4a04e2007-05-18 11:55:54 +00002777}
2778
aurel32cd5158e2008-12-07 23:26:24 +00002779static int float64_is_unordered(int sig, float64 a, float64 b STATUS_PARAM)
thsfd4a04e2007-05-18 11:55:54 +00002780{
2781 if (float64_is_signaling_nan(a) ||
2782 float64_is_signaling_nan(b) ||
2783 (sig && (float64_is_nan(a) || float64_is_nan(b)))) {
2784 float_raise(float_flag_invalid, status);
2785 return 1;
2786 } else if (float64_is_nan(a) || float64_is_nan(b)) {
2787 return 1;
2788 } else {
2789 return 0;
2790 }
2791}
2792
2793/* NOTE: the comma operator will make "cond" to eval to false,
2794 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002795FOP_COND_D(f, (float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status), 0))
2796FOP_COND_D(un, float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status))
2797FOP_COND_D(eq, !float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) && float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
2798FOP_COND_D(ueq, float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) || float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
2799FOP_COND_D(olt, !float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) && float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
2800FOP_COND_D(ult, float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) || float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
2801FOP_COND_D(ole, !float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) && float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
2802FOP_COND_D(ule, float64_is_unordered(0, fdt1, fdt0, &env->active_fpu.fp_status) || float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
thsfd4a04e2007-05-18 11:55:54 +00002803/* NOTE: the comma operator will make "cond" to eval to false,
2804 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002805FOP_COND_D(sf, (float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status), 0))
2806FOP_COND_D(ngle,float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status))
2807FOP_COND_D(seq, !float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) && float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
2808FOP_COND_D(ngl, float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) || float64_eq(fdt0, fdt1, &env->active_fpu.fp_status))
2809FOP_COND_D(lt, !float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) && float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
2810FOP_COND_D(nge, float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) || float64_lt(fdt0, fdt1, &env->active_fpu.fp_status))
2811FOP_COND_D(le, !float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) && float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
2812FOP_COND_D(ngt, float64_is_unordered(1, fdt1, fdt0, &env->active_fpu.fp_status) || float64_le(fdt0, fdt1, &env->active_fpu.fp_status))
thsfd4a04e2007-05-18 11:55:54 +00002813
thsb6d96be2008-07-09 11:05:10 +00002814#define FOP_COND_S(op, cond) \
2815void do_cmp_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2816{ \
2817 int c = cond; \
2818 update_fcr31(); \
2819 if (c) \
thsf01be152008-09-18 11:57:27 +00002820 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002821 else \
thsf01be152008-09-18 11:57:27 +00002822 CLEAR_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002823} \
2824void do_cmpabs_s_ ## op (uint32_t fst0, uint32_t fst1, int cc) \
2825{ \
2826 int c; \
2827 fst0 = float32_abs(fst0); \
2828 fst1 = float32_abs(fst1); \
2829 c = cond; \
2830 update_fcr31(); \
2831 if (c) \
thsf01be152008-09-18 11:57:27 +00002832 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002833 else \
thsf01be152008-09-18 11:57:27 +00002834 CLEAR_FP_COND(cc, env->active_fpu); \
thsfd4a04e2007-05-18 11:55:54 +00002835}
2836
aurel32cd5158e2008-12-07 23:26:24 +00002837static flag float32_is_unordered(int sig, float32 a, float32 b STATUS_PARAM)
thsfd4a04e2007-05-18 11:55:54 +00002838{
thsfd4a04e2007-05-18 11:55:54 +00002839 if (float32_is_signaling_nan(a) ||
2840 float32_is_signaling_nan(b) ||
2841 (sig && (float32_is_nan(a) || float32_is_nan(b)))) {
2842 float_raise(float_flag_invalid, status);
2843 return 1;
2844 } else if (float32_is_nan(a) || float32_is_nan(b)) {
2845 return 1;
2846 } else {
2847 return 0;
2848 }
2849}
2850
2851/* NOTE: the comma operator will make "cond" to eval to false,
2852 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002853FOP_COND_S(f, (float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status), 0))
2854FOP_COND_S(un, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status))
2855FOP_COND_S(eq, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_eq(fst0, fst1, &env->active_fpu.fp_status))
2856FOP_COND_S(ueq, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status))
2857FOP_COND_S(olt, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_lt(fst0, fst1, &env->active_fpu.fp_status))
2858FOP_COND_S(ult, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status))
2859FOP_COND_S(ole, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_le(fst0, fst1, &env->active_fpu.fp_status))
2860FOP_COND_S(ule, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status))
thsfd4a04e2007-05-18 11:55:54 +00002861/* NOTE: the comma operator will make "cond" to eval to false,
2862 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002863FOP_COND_S(sf, (float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status), 0))
2864FOP_COND_S(ngle,float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status))
2865FOP_COND_S(seq, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_eq(fst0, fst1, &env->active_fpu.fp_status))
2866FOP_COND_S(ngl, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status))
2867FOP_COND_S(lt, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_lt(fst0, fst1, &env->active_fpu.fp_status))
2868FOP_COND_S(nge, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status))
2869FOP_COND_S(le, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_le(fst0, fst1, &env->active_fpu.fp_status))
2870FOP_COND_S(ngt, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status))
thsfd4a04e2007-05-18 11:55:54 +00002871
thsb6d96be2008-07-09 11:05:10 +00002872#define FOP_COND_PS(op, condl, condh) \
2873void do_cmp_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2874{ \
2875 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2876 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2877 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2878 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2879 int cl = condl; \
2880 int ch = condh; \
2881 \
2882 update_fcr31(); \
2883 if (cl) \
thsf01be152008-09-18 11:57:27 +00002884 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002885 else \
thsf01be152008-09-18 11:57:27 +00002886 CLEAR_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002887 if (ch) \
thsf01be152008-09-18 11:57:27 +00002888 SET_FP_COND(cc + 1, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002889 else \
thsf01be152008-09-18 11:57:27 +00002890 CLEAR_FP_COND(cc + 1, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002891} \
2892void do_cmpabs_ps_ ## op (uint64_t fdt0, uint64_t fdt1, int cc) \
2893{ \
2894 uint32_t fst0 = float32_abs(fdt0 & 0XFFFFFFFF); \
2895 uint32_t fsth0 = float32_abs(fdt0 >> 32); \
2896 uint32_t fst1 = float32_abs(fdt1 & 0XFFFFFFFF); \
2897 uint32_t fsth1 = float32_abs(fdt1 >> 32); \
2898 int cl = condl; \
2899 int ch = condh; \
2900 \
2901 update_fcr31(); \
2902 if (cl) \
thsf01be152008-09-18 11:57:27 +00002903 SET_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002904 else \
thsf01be152008-09-18 11:57:27 +00002905 CLEAR_FP_COND(cc, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002906 if (ch) \
thsf01be152008-09-18 11:57:27 +00002907 SET_FP_COND(cc + 1, env->active_fpu); \
thsb6d96be2008-07-09 11:05:10 +00002908 else \
thsf01be152008-09-18 11:57:27 +00002909 CLEAR_FP_COND(cc + 1, env->active_fpu); \
thsfd4a04e2007-05-18 11:55:54 +00002910}
2911
2912/* NOTE: the comma operator will make "cond" to eval to false,
2913 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002914FOP_COND_PS(f, (float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status), 0),
2915 (float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status), 0))
2916FOP_COND_PS(un, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status),
2917 float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status))
2918FOP_COND_PS(eq, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_eq(fst0, fst1, &env->active_fpu.fp_status),
2919 !float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) && float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
2920FOP_COND_PS(ueq, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status),
2921 float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) || float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
2922FOP_COND_PS(olt, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_lt(fst0, fst1, &env->active_fpu.fp_status),
2923 !float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) && float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
2924FOP_COND_PS(ult, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status),
2925 float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) || float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
2926FOP_COND_PS(ole, !float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) && float32_le(fst0, fst1, &env->active_fpu.fp_status),
2927 !float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) && float32_le(fsth0, fsth1, &env->active_fpu.fp_status))
2928FOP_COND_PS(ule, float32_is_unordered(0, fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status),
2929 float32_is_unordered(0, fsth1, fsth0, &env->active_fpu.fp_status) || float32_le(fsth0, fsth1, &env->active_fpu.fp_status))
thsfd4a04e2007-05-18 11:55:54 +00002930/* NOTE: the comma operator will make "cond" to eval to false,
2931 * but float*_is_unordered() is still called. */
thsf01be152008-09-18 11:57:27 +00002932FOP_COND_PS(sf, (float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status), 0),
2933 (float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status), 0))
2934FOP_COND_PS(ngle,float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status),
2935 float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status))
2936FOP_COND_PS(seq, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_eq(fst0, fst1, &env->active_fpu.fp_status),
2937 !float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) && float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
2938FOP_COND_PS(ngl, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_eq(fst0, fst1, &env->active_fpu.fp_status),
2939 float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) || float32_eq(fsth0, fsth1, &env->active_fpu.fp_status))
2940FOP_COND_PS(lt, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_lt(fst0, fst1, &env->active_fpu.fp_status),
2941 !float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) && float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
2942FOP_COND_PS(nge, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_lt(fst0, fst1, &env->active_fpu.fp_status),
2943 float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) || float32_lt(fsth0, fsth1, &env->active_fpu.fp_status))
2944FOP_COND_PS(le, !float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) && float32_le(fst0, fst1, &env->active_fpu.fp_status),
2945 !float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) && float32_le(fsth0, fsth1, &env->active_fpu.fp_status))
2946FOP_COND_PS(ngt, float32_is_unordered(1, fst1, fst0, &env->active_fpu.fp_status) || float32_le(fst0, fst1, &env->active_fpu.fp_status),
2947 float32_is_unordered(1, fsth1, fsth0, &env->active_fpu.fp_status) || float32_le(fsth0, fsth1, &env->active_fpu.fp_status))