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 void helper_neon_tbl(int rn, int maxindex)
51 table = (uint64_t *)&env->vfp.regs[rn];
54 for (shift = 0; shift < 32; shift += 8) {
55 index = (T1 >> shift) & 0xff;
56 if (index <= maxindex) {
57 tmp = (table[index >> 3] >> (index & 7)) & 0xff;
60 val |= T0 & (0xff << shift);
66 #if !defined(CONFIG_USER_ONLY)
68 #define MMUSUFFIX _mmu
70 # define GETPC() ((void*)((unsigned long)__builtin_return_address(0) & 0x7fffffffUL))
72 # define GETPC() (__builtin_return_address(0))
76 #include "softmmu_template.h"
79 #include "softmmu_template.h"
82 #include "softmmu_template.h"
85 #include "softmmu_template.h"
87 /* try to fill the TLB and return an exception if error. If retaddr is
88 NULL, it means that the function was called in C code (i.e. not
89 from generated code or from helper.c) */
90 /* XXX: fix it to restore all registers */
91 void tlb_fill (target_ulong addr, int is_write, int mmu_idx, void *retaddr)
98 /* XXX: hack to restore env in all cases, even if not called from
101 env = cpu_single_env;
102 ret = cpu_arm_handle_mmu_fault(env, addr, is_write, mmu_idx, 1);
103 if (__builtin_expect(ret, 0)) {
105 /* now we have a real cpu fault */
106 pc = (unsigned long)retaddr;
109 /* the PC is inside the translated code. It means that we have
110 a virtual CPU fault */
111 cpu_restore_state(tb, env, pc, NULL);
114 raise_exception(env->exception_index);
120 #define SIGNBIT (uint32_t)0x80000000
121 uint32_t HELPER(add_setq)(uint32_t a, uint32_t b)
123 uint32_t res = a + b;
124 if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT))
129 uint32_t HELPER(add_saturate)(uint32_t a, uint32_t b)
131 uint32_t res = a + b;
132 if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) {
134 res = ~(((int32_t)a >> 31) ^ SIGNBIT);
139 uint32_t HELPER(sub_saturate)(uint32_t a, uint32_t b)
141 uint32_t res = a - b;
142 if (((res ^ a) & SIGNBIT) && ((a ^ b) & SIGNBIT)) {
144 res = ~(((int32_t)a >> 31) ^ SIGNBIT);
149 uint32_t HELPER(double_saturate)(int32_t val)
152 if (val >= 0x40000000) {
155 } else if (val <= (int32_t)0xc0000000) {
164 uint32_t HELPER(add_usaturate)(uint32_t a, uint32_t b)
166 uint32_t res = a + b;
174 uint32_t HELPER(sub_usaturate)(uint32_t a, uint32_t b)
176 uint32_t res = a - b;
184 /* Signed saturation. */
185 static inline uint32_t do_ssat(int32_t val, int shift)
192 mask = (1u << shift) - 1;
196 } else if (top < -1) {
203 /* Unsigned saturation. */
204 static inline uint32_t do_usat(int32_t val, int shift)
209 max = (1u << shift) - 1;
213 } else if (val > max) {
220 /* Signed saturate. */
221 uint32_t HELPER(ssat)(uint32_t x, uint32_t shift)
223 return do_ssat(x, shift);
226 /* Dual halfword signed saturate. */
227 uint32_t HELPER(ssat16)(uint32_t x, uint32_t shift)
231 res = (uint16_t)do_ssat((int16_t)x, shift);
232 res |= do_ssat(((int32_t)x) >> 16, shift) << 16;
236 /* Unsigned saturate. */
237 uint32_t HELPER(usat)(uint32_t x, uint32_t shift)
239 return do_usat(x, shift);
242 /* Dual halfword unsigned saturate. */
243 uint32_t HELPER(usat16)(uint32_t x, uint32_t shift)
247 res = (uint16_t)do_usat((int16_t)x, shift);
248 res |= do_usat(((int32_t)x) >> 16, shift) << 16;
252 void HELPER(wfi)(void)
254 env->exception_index = EXCP_HLT;
259 void HELPER(exception)(uint32_t excp)
261 env->exception_index = excp;
265 uint32_t HELPER(cpsr_read)(void)
267 return cpsr_read(env) & ~CPSR_EXEC;
270 void HELPER(cpsr_write)(uint32_t val, uint32_t mask)
272 cpsr_write(env, val, mask);
275 /* Access to user mode registers from privileged modes. */
276 uint32_t HELPER(get_user_reg)(uint32_t regno)
281 val = env->banked_r13[0];
282 } else if (regno == 14) {
283 val = env->banked_r14[0];
284 } else if (regno >= 8
285 && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
286 val = env->usr_regs[regno - 8];
288 val = env->regs[regno];
293 void HELPER(set_user_reg)(uint32_t regno, uint32_t val)
296 env->banked_r13[0] = val;
297 } else if (regno == 14) {
298 env->banked_r14[0] = val;
299 } else if (regno >= 8
300 && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) {
301 env->usr_regs[regno - 8] = val;
303 env->regs[regno] = val;