4 * Copyright (c) 2005-2007 CodeSourcery, LLC
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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 void raise_exception(int tt)
25 env->exception_index = tt;
31 spinlock_t global_cpu_lock = SPIN_LOCK_UNLOCKED;
35 spin_lock(&global_cpu_lock);
40 spin_unlock(&global_cpu_lock);
43 uint32_t HELPER(neon_tbl)(uint32_t ireg, uint32_t def,
44 uint32_t rn, uint32_t maxindex)
51 table = (uint64_t *)&env->vfp.regs[rn];
53 for (shift = 0; shift < 32; shift += 8) {
54 index = (ireg >> shift) & 0xff;
55 if (index < maxindex) {
56 tmp = (table[index >> 3] >> (index & 7)) & 0xff;
59 val |= def & (0xff << shift);
65 #if !defined(CONFIG_USER_ONLY)
67 #define MMUSUFFIX _mmu
69 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
71 # define GETPC() (__builtin_return_address(0))
75 #include "softmmu_template.h"
78 #include "softmmu_template.h"
81 #include "softmmu_template.h"
84 #include "softmmu_template.h"
86 /* try to fill the TLB and return an exception if error. If retaddr is
87 NULL, it means that the function was called in C code (i.e. not
88 from generated code or from helper.c) */
89 /* XXX: fix it to restore all registers */
90 void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
97 /* XXX: hack to restore env in all cases, even if not called from
100 env = cpu_single_env;
101 ret = cpu_arm_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
102 if (__builtin_expect(ret, 0)) {
104 /* now we have a real cpu fault */
105 pc = (unsigned long)retaddr;
108 /* the PC is inside the translated code. It means that we have
109 a virtual CPU fault */
110 cpu_restore_state(tb, env, pc, NULL);
113 raise_exception(env->exception_index);
119 #define SIGNBIT (uint32_t)0x80000000
120 uint32_t HELPER(add_setq)(uint32_t a, uint32_t b)
122 uint32_t res = a + b;
123 if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT))
128 uint32_t HELPER(add_saturate)(uint32_t a, uint32_t b)
130 uint32_t res = a + b;
131 if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) {
133 res = ~(((int32_t)a >> 31) ^ SIGNBIT);
138 uint32_t HELPER(sub_saturate)(uint32_t a, uint32_t b)
140 uint32_t res = a - b;
141 if (((res ^ a) & SIGNBIT) && ((a ^ b) & SIGNBIT)) {
143 res = ~(((int32_t)a >> 31) ^ SIGNBIT);
148 uint32_t HELPER(double_saturate)(int32_t val)
151 if (val >= 0x40000000) {
154 } else if (val <= (int32_t)0xc0000000) {
163 uint32_t HELPER(add_usaturate)(uint32_t a, uint32_t b)
165 uint32_t res = a + b;
173 uint32_t HELPER(sub_usaturate)(uint32_t a, uint32_t b)
175 uint32_t res = a - b;
183 /* Signed saturation. */
184 static inline uint32_t do_ssat(int32_t val, int shift)
191 mask = (1u << shift) - 1;
195 } else if (top < -1) {
202 /* Unsigned saturation. */
203 static inline uint32_t do_usat(int32_t val, int shift)
208 max = (1u << shift) - 1;
212 } else if (val > max) {
219 /* Signed saturate. */
220 uint32_t HELPER(ssat)(uint32_t x, uint32_t shift)
222 return do_ssat(x, shift);
225 /* Dual halfword signed saturate. */
226 uint32_t HELPER(ssat16)(uint32_t x, uint32_t shift)
230 res = (uint16_t)do_ssat((int16_t)x, shift);
231 res |= do_ssat(((int32_t)x) >> 16, shift) << 16;
235 /* Unsigned saturate. */
236 uint32_t HELPER(usat)(uint32_t x, uint32_t shift)
238 return do_usat(x, shift);
241 /* Dual halfword unsigned saturate. */
242 uint32_t HELPER(usat16)(uint32_t x, uint32_t shift)
246 res = (uint16_t)do_usat((int16_t)x, shift);
247 res |= do_usat(((int32_t)x) >> 16, shift) << 16;
251 void HELPER(wfi)(void)
253 env->exception_index = EXCP_HLT;
258 void HELPER(exception)(uint32_t excp)
260 env->exception_index = excp;
264 uint32_t HELPER(cpsr_read)(void)
266 return cpsr_read(env) & ~CPSR_EXEC;
269 void HELPER(cpsr_write)(uint32_t val, uint32_t mask)
271 cpsr_write(env, val, mask);
274 /* Access to user mode registers from privileged modes. */
275 uint32_t HELPER(get_user_reg)(uint32_t regno)
280 val = env->banked_r13[0];
281 } else if (regno == 14) {
282 val = env->banked_r14[0];
283 } else if (regno >= 8
284 && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
285 val = env->usr_regs[regno - 8];
287 val = env->regs[regno];
292 void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
295 env->banked_r13[0] = val;
296 } else if (regno == 14) {
297 env->banked_r14[0] = val;
298 } else if (regno >= 8
299 && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
300 env->usr_regs[regno - 8] = val;
302 env->regs[regno] = val;
306 /* ??? Flag setting arithmetic is awkward because we need to do comparisons.
307 The only way to do that in TCG is a conditional branch, which clobbers
308 all our temporaries. For now implement these as helper functions. */
310 uint32_t HELPER (add_cc)(uint32_t a, uint32_t b)
315 env->CF = result < a;
316 env->VF = (a ^ b ^ -1) & (a ^ result);
320 uint32_t HELPER(adc_cc)(uint32_t a, uint32_t b)
325 env->CF = result < a;
328 env->CF = result <= a;
330 env->VF = (a ^ b ^ -1) & (a ^ result);
335 uint32_t HELPER(sub_cc)(uint32_t a, uint32_t b)
341 env->VF = (a ^ b) & (a ^ result);
345 uint32_t HELPER(sbc_cc)(uint32_t a, uint32_t b)
355 env->VF = (a ^ b) & (a ^ result);
360 /* Similarly for variable shift instructions. */
362 uint32_t HELPER(shl)(uint32_t x, uint32_t i)
364 int shift = i & 0xff;
370 uint32_t HELPER(shr)(uint32_t x, uint32_t i)
372 int shift = i & 0xff;
375 return (uint32_t)x >> shift;
378 uint32_t HELPER(sar)(uint32_t x, uint32_t i)
380 int shift = i & 0xff;
383 return (int32_t)x >> shift;
386 uint32_t HELPER(ror)(uint32_t x, uint32_t i)
388 int shift = i & 0xff;
391 return (x >> shift) | (x << (32 - shift));
394 uint32_t HELPER(shl_cc)(uint32_t x, uint32_t i)
396 int shift = i & 0xff;
403 } else if (shift != 0) {
404 env->CF = (x >> (32 - shift)) & 1;
410 uint32_t HELPER(shr_cc)(uint32_t x, uint32_t i)
412 int shift = i & 0xff;
415 env->CF = (x >> 31) & 1;
419 } else if (shift != 0) {
420 env->CF = (x >> (shift - 1)) & 1;
426 uint32_t HELPER(sar_cc)(uint32_t x, uint32_t i)
428 int shift = i & 0xff;
430 env->CF = (x >> 31) & 1;
431 return (int32_t)x >> 31;
432 } else if (shift != 0) {
433 env->CF = (x >> (shift - 1)) & 1;
434 return (int32_t)x >> shift;
439 uint32_t HELPER(ror_cc)(uint32_t x, uint32_t i)
443 shift = shift1 & 0x1f;
446 env->CF = (x >> 31) & 1;
449 env->CF = (x >> (shift - 1)) & 1;
450 return ((uint32_t)x >> shift) | (x << (32 - shift));