]>
git.proxmox.com Git - qemu.git/blob - target-microblaze/op_helper.c
2 * Microblaze helper routines.
4 * Copyright (c) 2009 Edgar E. Iglesias <edgar.iglesias@gmail.com>.
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.
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.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "host-utils.h"
27 #if !defined(CONFIG_USER_ONLY)
28 #define MMUSUFFIX _mmu
30 #include "softmmu_template.h"
32 #include "softmmu_template.h"
34 #include "softmmu_template.h"
36 #include "softmmu_template.h"
38 /* Try to fill the TLB and return an exception if error. If retaddr is
39 NULL, it means that the function was called in C code (i.e. not
40 from generated code or from helper.c) */
41 /* XXX: fix it to restore all registers */
42 void tlb_fill (target_ulong addr
, int is_write
, int mmu_idx
, void *retaddr
)
49 /* XXX: hack to restore env in all cases, even if not called from
54 ret
= cpu_mb_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
, 1);
57 /* now we have a real cpu fault */
58 pc
= (unsigned long)retaddr
;
61 /* the PC is inside the translated code. It means that we have
62 a virtual CPU fault */
63 cpu_restore_state(tb
, env
, pc
, NULL
);
72 void helper_raise_exception(uint32_t index
)
74 env
->exception_index
= index
;
78 void helper_debug(void)
82 qemu_log("PC=%8.8x\n", env
->sregs
[SR_PC
]);
83 qemu_log("rmsr=%x resr=%x rear=%x debug[%x] imm=%x iflags=%x\n",
84 env
->sregs
[SR_MSR
], env
->sregs
[SR_ESR
], env
->sregs
[SR_EAR
],
85 env
->debug
, env
->imm
, env
->iflags
);
86 qemu_log("btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
87 env
->btaken
, env
->btarget
,
88 (env
->sregs
[SR_MSR
] & MSR_UM
) ? "user" : "kernel",
89 (env
->sregs
[SR_MSR
] & MSR_UMS
) ? "user" : "kernel",
90 (env
->sregs
[SR_MSR
] & MSR_EIP
),
91 (env
->sregs
[SR_MSR
] & MSR_IE
));
92 for (i
= 0; i
< 32; i
++) {
93 qemu_log("r%2.2d=%8.8x ", i
, env
->regs
[i
]);
100 static inline uint32_t compute_carry(uint32_t a
, uint32_t b
, uint32_t cin
)
104 if ((b
== ~0) && cin
)
106 else if ((~0 - a
) < (b
+ cin
))
111 uint32_t helper_cmp(uint32_t a
, uint32_t b
)
116 if ((b
& 0x80000000) ^ (a
& 0x80000000))
117 t
= (t
& 0x7fffffff) | (b
& 0x80000000);
121 uint32_t helper_cmpu(uint32_t a
, uint32_t b
)
126 if ((b
& 0x80000000) ^ (a
& 0x80000000))
127 t
= (t
& 0x7fffffff) | (a
& 0x80000000);
131 uint32_t helper_addkc(uint32_t a
, uint32_t b
, uint32_t cf
)
137 ncf
= compute_carry(a
, b
, cf
);
141 static inline int div_prepare(uint32_t a
, uint32_t b
)
144 env
->sregs
[SR_MSR
] |= MSR_DZ
;
146 if ((env
->sregs
[SR_MSR
] & MSR_EE
)
147 && !(env
->pvr
.regs
[2] & PVR2_DIV_ZERO_EXC_MASK
)) {
148 env
->sregs
[SR_ESR
] = ESR_EC_DIVZERO
;
149 helper_raise_exception(EXCP_HW_EXCP
);
153 env
->sregs
[SR_MSR
] &= ~MSR_DZ
;
157 uint32_t helper_divs(uint32_t a
, uint32_t b
)
159 if (!div_prepare(a
, b
))
161 return (int32_t)a
/ (int32_t)b
;
164 uint32_t helper_divu(uint32_t a
, uint32_t b
)
166 if (!div_prepare(a
, b
))
171 /* raise FPU exception. */
172 static void raise_fpu_exception(void)
174 env
->sregs
[SR_ESR
] = ESR_EC_FPU
;
175 helper_raise_exception(EXCP_HW_EXCP
);
178 static void update_fpu_flags(int flags
)
182 if (flags
& float_flag_invalid
) {
183 env
->sregs
[SR_FSR
] |= FSR_IO
;
186 if (flags
& float_flag_divbyzero
) {
187 env
->sregs
[SR_FSR
] |= FSR_DZ
;
190 if (flags
& float_flag_overflow
) {
191 env
->sregs
[SR_FSR
] |= FSR_OF
;
194 if (flags
& float_flag_underflow
) {
195 env
->sregs
[SR_FSR
] |= FSR_UF
;
199 && (env
->pvr
.regs
[2] & PVR2_FPU_EXC_MASK
)
200 && (env
->sregs
[SR_MSR
] & MSR_EE
)) {
201 raise_fpu_exception();
205 uint32_t helper_fadd(uint32_t a
, uint32_t b
)
207 CPU_FloatU fd
, fa
, fb
;
210 set_float_exception_flags(0, &env
->fp_status
);
213 fd
.f
= float32_add(fa
.f
, fb
.f
, &env
->fp_status
);
215 flags
= get_float_exception_flags(&env
->fp_status
);
216 update_fpu_flags(flags
);
220 uint32_t helper_frsub(uint32_t a
, uint32_t b
)
222 CPU_FloatU fd
, fa
, fb
;
225 set_float_exception_flags(0, &env
->fp_status
);
228 fd
.f
= float32_sub(fb
.f
, fa
.f
, &env
->fp_status
);
229 flags
= get_float_exception_flags(&env
->fp_status
);
230 update_fpu_flags(flags
);
234 uint32_t helper_fmul(uint32_t a
, uint32_t b
)
236 CPU_FloatU fd
, fa
, fb
;
239 set_float_exception_flags(0, &env
->fp_status
);
242 fd
.f
= float32_mul(fa
.f
, fb
.f
, &env
->fp_status
);
243 flags
= get_float_exception_flags(&env
->fp_status
);
244 update_fpu_flags(flags
);
249 uint32_t helper_fdiv(uint32_t a
, uint32_t b
)
251 CPU_FloatU fd
, fa
, fb
;
254 set_float_exception_flags(0, &env
->fp_status
);
257 fd
.f
= float32_div(fb
.f
, fa
.f
, &env
->fp_status
);
258 flags
= get_float_exception_flags(&env
->fp_status
);
259 update_fpu_flags(flags
);
264 uint32_t helper_fcmp_un(uint32_t a
, uint32_t b
)
272 if (float32_is_signaling_nan(fa
.f
) || float32_is_signaling_nan(fb
.f
)) {
273 update_fpu_flags(float_flag_invalid
);
277 if (float32_is_quiet_nan(fa
.f
) || float32_is_quiet_nan(fb
.f
)) {
284 uint32_t helper_fcmp_lt(uint32_t a
, uint32_t b
)
290 set_float_exception_flags(0, &env
->fp_status
);
293 r
= float32_lt(fb
.f
, fa
.f
, &env
->fp_status
);
294 flags
= get_float_exception_flags(&env
->fp_status
);
295 update_fpu_flags(flags
& float_flag_invalid
);
300 uint32_t helper_fcmp_eq(uint32_t a
, uint32_t b
)
306 set_float_exception_flags(0, &env
->fp_status
);
309 r
= float32_eq(fa
.f
, fb
.f
, &env
->fp_status
);
310 flags
= get_float_exception_flags(&env
->fp_status
);
311 update_fpu_flags(flags
& float_flag_invalid
);
316 uint32_t helper_fcmp_le(uint32_t a
, uint32_t b
)
324 set_float_exception_flags(0, &env
->fp_status
);
325 r
= float32_le(fa
.f
, fb
.f
, &env
->fp_status
);
326 flags
= get_float_exception_flags(&env
->fp_status
);
327 update_fpu_flags(flags
& float_flag_invalid
);
333 uint32_t helper_fcmp_gt(uint32_t a
, uint32_t b
)
340 set_float_exception_flags(0, &env
->fp_status
);
341 r
= float32_lt(fa
.f
, fb
.f
, &env
->fp_status
);
342 flags
= get_float_exception_flags(&env
->fp_status
);
343 update_fpu_flags(flags
& float_flag_invalid
);
347 uint32_t helper_fcmp_ne(uint32_t a
, uint32_t b
)
354 set_float_exception_flags(0, &env
->fp_status
);
355 r
= !float32_eq(fa
.f
, fb
.f
, &env
->fp_status
);
356 flags
= get_float_exception_flags(&env
->fp_status
);
357 update_fpu_flags(flags
& float_flag_invalid
);
362 uint32_t helper_fcmp_ge(uint32_t a
, uint32_t b
)
369 set_float_exception_flags(0, &env
->fp_status
);
370 r
= !float32_lt(fa
.f
, fb
.f
, &env
->fp_status
);
371 flags
= get_float_exception_flags(&env
->fp_status
);
372 update_fpu_flags(flags
& float_flag_invalid
);
377 uint32_t helper_flt(uint32_t a
)
382 fd
.f
= int32_to_float32(fa
.l
, &env
->fp_status
);
386 uint32_t helper_fint(uint32_t a
)
392 set_float_exception_flags(0, &env
->fp_status
);
394 r
= float32_to_int32(fa
.f
, &env
->fp_status
);
395 flags
= get_float_exception_flags(&env
->fp_status
);
396 update_fpu_flags(flags
);
401 uint32_t helper_fsqrt(uint32_t a
)
406 set_float_exception_flags(0, &env
->fp_status
);
408 fd
.l
= float32_sqrt(fa
.f
, &env
->fp_status
);
409 flags
= get_float_exception_flags(&env
->fp_status
);
410 update_fpu_flags(flags
);
415 uint32_t helper_pcmpbf(uint32_t a
, uint32_t b
)
418 uint32_t mask
= 0xff000000;
420 for (i
= 0; i
< 4; i
++) {
421 if ((a
& mask
) == (b
& mask
))
428 void helper_memalign(uint32_t addr
, uint32_t dr
, uint32_t wr
, uint32_t mask
)
431 qemu_log_mask(CPU_LOG_INT
,
432 "unaligned access addr=%x mask=%x, wr=%d dr=r%d\n",
434 env
->sregs
[SR_EAR
] = addr
;
435 env
->sregs
[SR_ESR
] = ESR_EC_UNALIGNED_DATA
| (wr
<< 10) \
438 env
->sregs
[SR_ESR
] |= 1 << 11;
440 if (!(env
->sregs
[SR_MSR
] & MSR_EE
)) {
443 helper_raise_exception(EXCP_HW_EXCP
);
447 #if !defined(CONFIG_USER_ONLY)
448 /* Writes/reads to the MMU's special regs end up here. */
449 uint32_t helper_mmu_read(uint32_t rn
)
451 return mmu_read(env
, rn
);
454 void helper_mmu_write(uint32_t rn
, uint32_t v
)
456 mmu_write(env
, rn
, v
);
459 void do_unassigned_access(target_phys_addr_t addr
, int is_write
, int is_exec
,
460 int is_asi
, int size
)
464 if (!cpu_single_env
) {
469 /* XXX: hack to restore env in all cases, even if not called from
472 env
= cpu_single_env
;
473 qemu_log_mask(CPU_LOG_INT
, "Unassigned " TARGET_FMT_plx
" wr=%d exe=%d\n",
474 addr
, is_write
, is_exec
);
475 if (!(env
->sregs
[SR_MSR
] & MSR_EE
)) {
480 env
->sregs
[SR_EAR
] = addr
;
482 if ((env
->pvr
.regs
[2] & PVR2_IOPB_BUS_EXC_MASK
)) {
483 env
->sregs
[SR_ESR
] = ESR_EC_INSN_BUS
;
484 helper_raise_exception(EXCP_HW_EXCP
);
487 if ((env
->pvr
.regs
[2] & PVR2_DOPB_BUS_EXC_MASK
)) {
488 env
->sregs
[SR_ESR
] = ESR_EC_DATA_BUS
;
489 helper_raise_exception(EXCP_HW_EXCP
);