]>
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>.
5 * Copyright (c) 2009-2012 PetaLogix Qld Pty Ltd.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
23 #include "dyngen-exec.h"
25 #include "host-utils.h"
29 #if !defined(CONFIG_USER_ONLY)
30 #include "softmmu_exec.h"
32 #define MMUSUFFIX _mmu
34 #include "softmmu_template.h"
36 #include "softmmu_template.h"
38 #include "softmmu_template.h"
40 #include "softmmu_template.h"
42 /* Try to fill the TLB and return an exception if error. If retaddr is
43 NULL, it means that the function was called in C code (i.e. not
44 from generated code or from helper.c) */
45 /* XXX: fix it to restore all registers */
46 void tlb_fill(CPUMBState
*env1
, target_ulong addr
, int is_write
, int mmu_idx
,
50 CPUMBState
*saved_env
;
57 ret
= cpu_mb_handle_mmu_fault(env
, addr
, is_write
, mmu_idx
);
60 /* now we have a real cpu fault */
61 pc
= (unsigned long)retaddr
;
64 /* the PC is inside the translated code. It means that we have
65 a virtual CPU fault */
66 cpu_restore_state(tb
, env
, pc
);
75 void helper_put(uint32_t id
, uint32_t ctrl
, uint32_t data
)
77 int test
= ctrl
& STREAM_TEST
;
78 int atomic
= ctrl
& STREAM_ATOMIC
;
79 int control
= ctrl
& STREAM_CONTROL
;
80 int nonblock
= ctrl
& STREAM_NONBLOCK
;
81 int exception
= ctrl
& STREAM_EXCEPTION
;
83 qemu_log("Unhandled stream put to stream-id=%d data=%x %s%s%s%s%s\n",
92 uint32_t helper_get(uint32_t id
, uint32_t ctrl
)
94 int test
= ctrl
& STREAM_TEST
;
95 int atomic
= ctrl
& STREAM_ATOMIC
;
96 int control
= ctrl
& STREAM_CONTROL
;
97 int nonblock
= ctrl
& STREAM_NONBLOCK
;
98 int exception
= ctrl
& STREAM_EXCEPTION
;
100 qemu_log("Unhandled stream get from stream-id=%d %s%s%s%s%s\n",
104 exception
? "e" : "",
107 return 0xdead0000 | id
;
110 void helper_raise_exception(uint32_t index
)
112 env
->exception_index
= index
;
116 void helper_debug(void)
120 qemu_log("PC=%8.8x\n", env
->sregs
[SR_PC
]);
121 qemu_log("rmsr=%x resr=%x rear=%x debug[%x] imm=%x iflags=%x\n",
122 env
->sregs
[SR_MSR
], env
->sregs
[SR_ESR
], env
->sregs
[SR_EAR
],
123 env
->debug
, env
->imm
, env
->iflags
);
124 qemu_log("btaken=%d btarget=%x mode=%s(saved=%s) eip=%d ie=%d\n",
125 env
->btaken
, env
->btarget
,
126 (env
->sregs
[SR_MSR
] & MSR_UM
) ? "user" : "kernel",
127 (env
->sregs
[SR_MSR
] & MSR_UMS
) ? "user" : "kernel",
128 (env
->sregs
[SR_MSR
] & MSR_EIP
),
129 (env
->sregs
[SR_MSR
] & MSR_IE
));
130 for (i
= 0; i
< 32; i
++) {
131 qemu_log("r%2.2d=%8.8x ", i
, env
->regs
[i
]);
132 if ((i
+ 1) % 4 == 0)
138 static inline uint32_t compute_carry(uint32_t a
, uint32_t b
, uint32_t cin
)
142 if ((b
== ~0) && cin
)
144 else if ((~0 - a
) < (b
+ cin
))
149 uint32_t helper_cmp(uint32_t a
, uint32_t b
)
154 if ((b
& 0x80000000) ^ (a
& 0x80000000))
155 t
= (t
& 0x7fffffff) | (b
& 0x80000000);
159 uint32_t helper_cmpu(uint32_t a
, uint32_t b
)
164 if ((b
& 0x80000000) ^ (a
& 0x80000000))
165 t
= (t
& 0x7fffffff) | (a
& 0x80000000);
169 uint32_t helper_clz(uint32_t t0
)
174 uint32_t helper_carry(uint32_t a
, uint32_t b
, uint32_t cf
)
177 ncf
= compute_carry(a
, b
, cf
);
181 static inline int div_prepare(uint32_t a
, uint32_t b
)
184 env
->sregs
[SR_MSR
] |= MSR_DZ
;
186 if ((env
->sregs
[SR_MSR
] & MSR_EE
)
187 && !(env
->pvr
.regs
[2] & PVR2_DIV_ZERO_EXC_MASK
)) {
188 env
->sregs
[SR_ESR
] = ESR_EC_DIVZERO
;
189 helper_raise_exception(EXCP_HW_EXCP
);
193 env
->sregs
[SR_MSR
] &= ~MSR_DZ
;
197 uint32_t helper_divs(uint32_t a
, uint32_t b
)
199 if (!div_prepare(a
, b
))
201 return (int32_t)a
/ (int32_t)b
;
204 uint32_t helper_divu(uint32_t a
, uint32_t b
)
206 if (!div_prepare(a
, b
))
211 /* raise FPU exception. */
212 static void raise_fpu_exception(void)
214 env
->sregs
[SR_ESR
] = ESR_EC_FPU
;
215 helper_raise_exception(EXCP_HW_EXCP
);
218 static void update_fpu_flags(int flags
)
222 if (flags
& float_flag_invalid
) {
223 env
->sregs
[SR_FSR
] |= FSR_IO
;
226 if (flags
& float_flag_divbyzero
) {
227 env
->sregs
[SR_FSR
] |= FSR_DZ
;
230 if (flags
& float_flag_overflow
) {
231 env
->sregs
[SR_FSR
] |= FSR_OF
;
234 if (flags
& float_flag_underflow
) {
235 env
->sregs
[SR_FSR
] |= FSR_UF
;
239 && (env
->pvr
.regs
[2] & PVR2_FPU_EXC_MASK
)
240 && (env
->sregs
[SR_MSR
] & MSR_EE
)) {
241 raise_fpu_exception();
245 uint32_t helper_fadd(uint32_t a
, uint32_t b
)
247 CPU_FloatU fd
, fa
, fb
;
250 set_float_exception_flags(0, &env
->fp_status
);
253 fd
.f
= float32_add(fa
.f
, fb
.f
, &env
->fp_status
);
255 flags
= get_float_exception_flags(&env
->fp_status
);
256 update_fpu_flags(flags
);
260 uint32_t helper_frsub(uint32_t a
, uint32_t b
)
262 CPU_FloatU fd
, fa
, fb
;
265 set_float_exception_flags(0, &env
->fp_status
);
268 fd
.f
= float32_sub(fb
.f
, fa
.f
, &env
->fp_status
);
269 flags
= get_float_exception_flags(&env
->fp_status
);
270 update_fpu_flags(flags
);
274 uint32_t helper_fmul(uint32_t a
, uint32_t b
)
276 CPU_FloatU fd
, fa
, fb
;
279 set_float_exception_flags(0, &env
->fp_status
);
282 fd
.f
= float32_mul(fa
.f
, fb
.f
, &env
->fp_status
);
283 flags
= get_float_exception_flags(&env
->fp_status
);
284 update_fpu_flags(flags
);
289 uint32_t helper_fdiv(uint32_t a
, uint32_t b
)
291 CPU_FloatU fd
, fa
, fb
;
294 set_float_exception_flags(0, &env
->fp_status
);
297 fd
.f
= float32_div(fb
.f
, fa
.f
, &env
->fp_status
);
298 flags
= get_float_exception_flags(&env
->fp_status
);
299 update_fpu_flags(flags
);
304 uint32_t helper_fcmp_un(uint32_t a
, uint32_t b
)
312 if (float32_is_signaling_nan(fa
.f
) || float32_is_signaling_nan(fb
.f
)) {
313 update_fpu_flags(float_flag_invalid
);
317 if (float32_is_quiet_nan(fa
.f
) || float32_is_quiet_nan(fb
.f
)) {
324 uint32_t helper_fcmp_lt(uint32_t a
, uint32_t b
)
330 set_float_exception_flags(0, &env
->fp_status
);
333 r
= float32_lt(fb
.f
, fa
.f
, &env
->fp_status
);
334 flags
= get_float_exception_flags(&env
->fp_status
);
335 update_fpu_flags(flags
& float_flag_invalid
);
340 uint32_t helper_fcmp_eq(uint32_t a
, uint32_t b
)
346 set_float_exception_flags(0, &env
->fp_status
);
349 r
= float32_eq_quiet(fa
.f
, fb
.f
, &env
->fp_status
);
350 flags
= get_float_exception_flags(&env
->fp_status
);
351 update_fpu_flags(flags
& float_flag_invalid
);
356 uint32_t helper_fcmp_le(uint32_t a
, uint32_t b
)
364 set_float_exception_flags(0, &env
->fp_status
);
365 r
= float32_le(fa
.f
, fb
.f
, &env
->fp_status
);
366 flags
= get_float_exception_flags(&env
->fp_status
);
367 update_fpu_flags(flags
& float_flag_invalid
);
373 uint32_t helper_fcmp_gt(uint32_t a
, uint32_t b
)
380 set_float_exception_flags(0, &env
->fp_status
);
381 r
= float32_lt(fa
.f
, fb
.f
, &env
->fp_status
);
382 flags
= get_float_exception_flags(&env
->fp_status
);
383 update_fpu_flags(flags
& float_flag_invalid
);
387 uint32_t helper_fcmp_ne(uint32_t a
, uint32_t b
)
394 set_float_exception_flags(0, &env
->fp_status
);
395 r
= !float32_eq_quiet(fa
.f
, fb
.f
, &env
->fp_status
);
396 flags
= get_float_exception_flags(&env
->fp_status
);
397 update_fpu_flags(flags
& float_flag_invalid
);
402 uint32_t helper_fcmp_ge(uint32_t a
, uint32_t b
)
409 set_float_exception_flags(0, &env
->fp_status
);
410 r
= !float32_lt(fa
.f
, fb
.f
, &env
->fp_status
);
411 flags
= get_float_exception_flags(&env
->fp_status
);
412 update_fpu_flags(flags
& float_flag_invalid
);
417 uint32_t helper_flt(uint32_t a
)
422 fd
.f
= int32_to_float32(fa
.l
, &env
->fp_status
);
426 uint32_t helper_fint(uint32_t a
)
432 set_float_exception_flags(0, &env
->fp_status
);
434 r
= float32_to_int32(fa
.f
, &env
->fp_status
);
435 flags
= get_float_exception_flags(&env
->fp_status
);
436 update_fpu_flags(flags
);
441 uint32_t helper_fsqrt(uint32_t a
)
446 set_float_exception_flags(0, &env
->fp_status
);
448 fd
.l
= float32_sqrt(fa
.f
, &env
->fp_status
);
449 flags
= get_float_exception_flags(&env
->fp_status
);
450 update_fpu_flags(flags
);
455 uint32_t helper_pcmpbf(uint32_t a
, uint32_t b
)
458 uint32_t mask
= 0xff000000;
460 for (i
= 0; i
< 4; i
++) {
461 if ((a
& mask
) == (b
& mask
))
468 void helper_memalign(uint32_t addr
, uint32_t dr
, uint32_t wr
, uint32_t mask
)
471 qemu_log_mask(CPU_LOG_INT
,
472 "unaligned access addr=%x mask=%x, wr=%d dr=r%d\n",
474 env
->sregs
[SR_EAR
] = addr
;
475 env
->sregs
[SR_ESR
] = ESR_EC_UNALIGNED_DATA
| (wr
<< 10) \
478 env
->sregs
[SR_ESR
] |= 1 << 11;
480 if (!(env
->sregs
[SR_MSR
] & MSR_EE
)) {
483 helper_raise_exception(EXCP_HW_EXCP
);
487 void helper_stackprot(uint32_t addr
)
489 if (addr
< env
->slr
|| addr
> env
->shr
) {
490 qemu_log("Stack protector violation at %x %x %x\n",
491 addr
, env
->slr
, env
->shr
);
492 env
->sregs
[SR_EAR
] = addr
;
493 env
->sregs
[SR_ESR
] = ESR_EC_STACKPROT
;
494 helper_raise_exception(EXCP_HW_EXCP
);
498 #if !defined(CONFIG_USER_ONLY)
499 /* Writes/reads to the MMU's special regs end up here. */
500 uint32_t helper_mmu_read(uint32_t rn
)
502 return mmu_read(env
, rn
);
505 void helper_mmu_write(uint32_t rn
, uint32_t v
)
507 mmu_write(env
, rn
, v
);
510 void cpu_unassigned_access(CPUMBState
*env1
, target_phys_addr_t addr
,
511 int is_write
, int is_exec
, int is_asi
, int size
)
513 CPUMBState
*saved_env
;
518 qemu_log_mask(CPU_LOG_INT
, "Unassigned " TARGET_FMT_plx
" wr=%d exe=%d\n",
519 addr
, is_write
, is_exec
);
520 if (!(env
->sregs
[SR_MSR
] & MSR_EE
)) {
525 env
->sregs
[SR_EAR
] = addr
;
527 if ((env
->pvr
.regs
[2] & PVR2_IOPB_BUS_EXC_MASK
)) {
528 env
->sregs
[SR_ESR
] = ESR_EC_INSN_BUS
;
529 helper_raise_exception(EXCP_HW_EXCP
);
532 if ((env
->pvr
.regs
[2] & PVR2_DOPB_BUS_EXC_MASK
)) {
533 env
->sregs
[SR_ESR
] = ESR_EC_DATA_BUS
;
534 helper_raise_exception(EXCP_HW_EXCP
);