bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ARM helper routines |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 4 | * Copyright (c) 2005-2007 CodeSourcery, LLC |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 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 |
Blue Swirl | 8167ee8 | 2009-07-16 20:47:01 +0000 | [diff] [blame] | 17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 18 | */ |
Blue Swirl | 3e45717 | 2011-07-13 12:44:15 +0000 | [diff] [blame] | 19 | #include "cpu.h" |
LluĂs | 7b59220 | 2011-04-13 18:38:24 +0200 | [diff] [blame] | 20 | #include "helper.h" |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 21 | |
pbrook | ad69471 | 2008-03-31 03:48:30 +0000 | [diff] [blame] | 22 | #define SIGNBIT (uint32_t)0x80000000 |
| 23 | #define SIGNBIT64 ((uint64_t)1 << 63) |
| 24 | |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 25 | static void raise_exception(CPUARMState *env, int tt) |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 26 | { |
| 27 | env->exception_index = tt; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 28 | cpu_loop_exit(env); |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 31 | uint32_t HELPER(neon_tbl)(CPUARMState *env, uint32_t ireg, uint32_t def, |
pbrook | 8f8e3aa | 2008-03-31 03:48:01 +0000 | [diff] [blame] | 32 | uint32_t rn, uint32_t maxindex) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 33 | { |
| 34 | uint32_t val; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 35 | uint32_t tmp; |
| 36 | int index; |
| 37 | int shift; |
| 38 | uint64_t *table; |
| 39 | table = (uint64_t *)&env->vfp.regs[rn]; |
| 40 | val = 0; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 41 | for (shift = 0; shift < 32; shift += 8) { |
pbrook | 8f8e3aa | 2008-03-31 03:48:01 +0000 | [diff] [blame] | 42 | index = (ireg >> shift) & 0xff; |
| 43 | if (index < maxindex) { |
pbrook | 3018f25 | 2008-09-22 00:52:42 +0000 | [diff] [blame] | 44 | tmp = (table[index >> 3] >> ((index & 7) << 3)) & 0xff; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 45 | val |= tmp << shift; |
| 46 | } else { |
pbrook | 8f8e3aa | 2008-03-31 03:48:01 +0000 | [diff] [blame] | 47 | val |= def & (0xff << shift); |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
pbrook | 8f8e3aa | 2008-03-31 03:48:01 +0000 | [diff] [blame] | 50 | return val; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 51 | } |
| 52 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 53 | #if !defined(CONFIG_USER_ONLY) |
| 54 | |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 55 | #include "exec/softmmu_exec.h" |
Blue Swirl | 3e45717 | 2011-07-13 12:44:15 +0000 | [diff] [blame] | 56 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 57 | #define MMUSUFFIX _mmu |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 58 | |
| 59 | #define SHIFT 0 |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 60 | #include "exec/softmmu_template.h" |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 61 | |
| 62 | #define SHIFT 1 |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 63 | #include "exec/softmmu_template.h" |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 64 | |
| 65 | #define SHIFT 2 |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 66 | #include "exec/softmmu_template.h" |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 67 | |
| 68 | #define SHIFT 3 |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 69 | #include "exec/softmmu_template.h" |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 70 | |
| 71 | /* try to fill the TLB and return an exception if error. If retaddr is |
| 72 | NULL, it means that the function was called in C code (i.e. not |
| 73 | from generated code or from helper.c) */ |
Blue Swirl | d31dd73 | 2012-09-04 20:25:59 +0000 | [diff] [blame] | 74 | void tlb_fill(CPUARMState *env, target_ulong addr, int is_write, int mmu_idx, |
Blue Swirl | 2050396 | 2012-04-09 14:20:20 +0000 | [diff] [blame] | 75 | uintptr_t retaddr) |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 76 | { |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 77 | int ret; |
| 78 | |
Blue Swirl | 97b348e | 2011-08-01 16:12:17 +0000 | [diff] [blame] | 79 | ret = cpu_arm_handle_mmu_fault(env, addr, is_write, mmu_idx); |
ths | 551bd27 | 2008-07-03 17:57:36 +0000 | [diff] [blame] | 80 | if (unlikely(ret)) { |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 81 | if (retaddr) { |
| 82 | /* now we have a real cpu fault */ |
Blue Swirl | a8a826a | 2012-12-04 20:16:07 +0000 | [diff] [blame] | 83 | cpu_restore_state(env, retaddr); |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 84 | } |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 85 | raise_exception(env, env->exception_index); |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 86 | } |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 87 | } |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 88 | #endif |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 89 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 90 | uint32_t HELPER(add_setq)(CPUARMState *env, uint32_t a, uint32_t b) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 91 | { |
| 92 | uint32_t res = a + b; |
| 93 | if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) |
| 94 | env->QF = 1; |
| 95 | return res; |
| 96 | } |
| 97 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 98 | uint32_t HELPER(add_saturate)(CPUARMState *env, uint32_t a, uint32_t b) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 99 | { |
| 100 | uint32_t res = a + b; |
| 101 | if (((res ^ a) & SIGNBIT) && !((a ^ b) & SIGNBIT)) { |
| 102 | env->QF = 1; |
| 103 | res = ~(((int32_t)a >> 31) ^ SIGNBIT); |
| 104 | } |
| 105 | return res; |
| 106 | } |
| 107 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 108 | uint32_t HELPER(sub_saturate)(CPUARMState *env, uint32_t a, uint32_t b) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 109 | { |
| 110 | uint32_t res = a - b; |
| 111 | if (((res ^ a) & SIGNBIT) && ((a ^ b) & SIGNBIT)) { |
| 112 | env->QF = 1; |
| 113 | res = ~(((int32_t)a >> 31) ^ SIGNBIT); |
| 114 | } |
| 115 | return res; |
| 116 | } |
| 117 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 118 | uint32_t HELPER(double_saturate)(CPUARMState *env, int32_t val) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 119 | { |
| 120 | uint32_t res; |
| 121 | if (val >= 0x40000000) { |
| 122 | res = ~SIGNBIT; |
| 123 | env->QF = 1; |
| 124 | } else if (val <= (int32_t)0xc0000000) { |
| 125 | res = SIGNBIT; |
| 126 | env->QF = 1; |
| 127 | } else { |
| 128 | res = val << 1; |
| 129 | } |
| 130 | return res; |
| 131 | } |
| 132 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 133 | uint32_t HELPER(add_usaturate)(CPUARMState *env, uint32_t a, uint32_t b) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 134 | { |
| 135 | uint32_t res = a + b; |
| 136 | if (res < a) { |
| 137 | env->QF = 1; |
| 138 | res = ~0; |
| 139 | } |
| 140 | return res; |
| 141 | } |
| 142 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 143 | uint32_t HELPER(sub_usaturate)(CPUARMState *env, uint32_t a, uint32_t b) |
pbrook | 1497c96 | 2008-03-31 03:45:50 +0000 | [diff] [blame] | 144 | { |
| 145 | uint32_t res = a - b; |
| 146 | if (res > a) { |
| 147 | env->QF = 1; |
| 148 | res = 0; |
| 149 | } |
| 150 | return res; |
| 151 | } |
| 152 | |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 153 | /* Signed saturation. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 154 | static inline uint32_t do_ssat(CPUARMState *env, int32_t val, int shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 155 | { |
| 156 | int32_t top; |
| 157 | uint32_t mask; |
| 158 | |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 159 | top = val >> shift; |
| 160 | mask = (1u << shift) - 1; |
| 161 | if (top > 0) { |
| 162 | env->QF = 1; |
| 163 | return mask; |
| 164 | } else if (top < -1) { |
| 165 | env->QF = 1; |
| 166 | return ~mask; |
| 167 | } |
| 168 | return val; |
| 169 | } |
| 170 | |
| 171 | /* Unsigned saturation. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 172 | static inline uint32_t do_usat(CPUARMState *env, int32_t val, int shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 173 | { |
| 174 | uint32_t max; |
| 175 | |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 176 | max = (1u << shift) - 1; |
| 177 | if (val < 0) { |
| 178 | env->QF = 1; |
| 179 | return 0; |
| 180 | } else if (val > max) { |
| 181 | env->QF = 1; |
| 182 | return max; |
| 183 | } |
| 184 | return val; |
| 185 | } |
| 186 | |
| 187 | /* Signed saturate. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 188 | uint32_t HELPER(ssat)(CPUARMState *env, uint32_t x, uint32_t shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 189 | { |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 190 | return do_ssat(env, x, shift); |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /* Dual halfword signed saturate. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 194 | uint32_t HELPER(ssat16)(CPUARMState *env, uint32_t x, uint32_t shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 195 | { |
| 196 | uint32_t res; |
| 197 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 198 | res = (uint16_t)do_ssat(env, (int16_t)x, shift); |
| 199 | res |= do_ssat(env, ((int32_t)x) >> 16, shift) << 16; |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 200 | return res; |
| 201 | } |
| 202 | |
| 203 | /* Unsigned saturate. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 204 | uint32_t HELPER(usat)(CPUARMState *env, uint32_t x, uint32_t shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 205 | { |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 206 | return do_usat(env, x, shift); |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* Dual halfword unsigned saturate. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 210 | uint32_t HELPER(usat16)(CPUARMState *env, uint32_t x, uint32_t shift) |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 211 | { |
| 212 | uint32_t res; |
| 213 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 214 | res = (uint16_t)do_usat(env, (int16_t)x, shift); |
| 215 | res |= do_usat(env, ((int32_t)x) >> 16, shift) << 16; |
pbrook | 6ddbc6e | 2008-03-31 03:46:33 +0000 | [diff] [blame] | 216 | return res; |
| 217 | } |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 218 | |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 219 | void HELPER(wfi)(CPUARMState *env) |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 220 | { |
Andreas Färber | 259186a | 2013-01-17 18:51:17 +0100 | [diff] [blame] | 221 | CPUState *cs = CPU(arm_env_get_cpu(env)); |
| 222 | |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 223 | env->exception_index = EXCP_HLT; |
Andreas Färber | 259186a | 2013-01-17 18:51:17 +0100 | [diff] [blame] | 224 | cs->halted = 1; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 225 | cpu_loop_exit(env); |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 228 | void HELPER(exception)(CPUARMState *env, uint32_t excp) |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 229 | { |
| 230 | env->exception_index = excp; |
Blue Swirl | 1162c04 | 2011-05-14 12:52:35 +0000 | [diff] [blame] | 231 | cpu_loop_exit(env); |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 232 | } |
| 233 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 234 | uint32_t HELPER(cpsr_read)(CPUARMState *env) |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 235 | { |
| 236 | return cpsr_read(env) & ~CPSR_EXEC; |
| 237 | } |
| 238 | |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 239 | void HELPER(cpsr_write)(CPUARMState *env, uint32_t val, uint32_t mask) |
pbrook | d9ba483 | 2008-03-31 03:46:50 +0000 | [diff] [blame] | 240 | { |
| 241 | cpsr_write(env, val, mask); |
| 242 | } |
pbrook | b010980 | 2008-03-31 03:47:03 +0000 | [diff] [blame] | 243 | |
| 244 | /* Access to user mode registers from privileged modes. */ |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 245 | uint32_t HELPER(get_user_reg)(CPUARMState *env, uint32_t regno) |
pbrook | b010980 | 2008-03-31 03:47:03 +0000 | [diff] [blame] | 246 | { |
| 247 | uint32_t val; |
| 248 | |
| 249 | if (regno == 13) { |
| 250 | val = env->banked_r13[0]; |
| 251 | } else if (regno == 14) { |
| 252 | val = env->banked_r14[0]; |
| 253 | } else if (regno >= 8 |
| 254 | && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) { |
| 255 | val = env->usr_regs[regno - 8]; |
| 256 | } else { |
| 257 | val = env->regs[regno]; |
| 258 | } |
| 259 | return val; |
| 260 | } |
| 261 | |
Blue Swirl | 1ce94f8 | 2012-09-04 20:08:34 +0000 | [diff] [blame] | 262 | void HELPER(set_user_reg)(CPUARMState *env, uint32_t regno, uint32_t val) |
pbrook | b010980 | 2008-03-31 03:47:03 +0000 | [diff] [blame] | 263 | { |
| 264 | if (regno == 13) { |
| 265 | env->banked_r13[0] = val; |
| 266 | } else if (regno == 14) { |
| 267 | env->banked_r14[0] = val; |
| 268 | } else if (regno >= 8 |
| 269 | && (env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_FIQ) { |
| 270 | env->usr_regs[regno - 8] = val; |
| 271 | } else { |
| 272 | env->regs[regno] = val; |
| 273 | } |
| 274 | } |
| 275 | |
Peter Maydell | f59df3f | 2014-02-20 10:35:52 +0000 | [diff] [blame] | 276 | void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip) |
| 277 | { |
| 278 | const ARMCPRegInfo *ri = rip; |
| 279 | switch (ri->accessfn(env, ri)) { |
| 280 | case CP_ACCESS_OK: |
| 281 | return; |
| 282 | case CP_ACCESS_TRAP: |
| 283 | case CP_ACCESS_TRAP_UNCATEGORIZED: |
| 284 | /* These cases will eventually need to generate different |
| 285 | * syndrome information. |
| 286 | */ |
| 287 | break; |
| 288 | default: |
| 289 | g_assert_not_reached(); |
| 290 | } |
| 291 | raise_exception(env, EXCP_UDEF); |
| 292 | } |
| 293 | |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 294 | void HELPER(set_cp_reg)(CPUARMState *env, void *rip, uint32_t value) |
| 295 | { |
| 296 | const ARMCPRegInfo *ri = rip; |
Peter Maydell | c4241c7 | 2014-02-20 10:35:54 +0000 | [diff] [blame] | 297 | |
| 298 | ri->writefn(env, ri, value); |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | uint32_t HELPER(get_cp_reg)(CPUARMState *env, void *rip) |
| 302 | { |
| 303 | const ARMCPRegInfo *ri = rip; |
Peter Maydell | c4241c7 | 2014-02-20 10:35:54 +0000 | [diff] [blame] | 304 | |
| 305 | return ri->readfn(env, ri); |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | void HELPER(set_cp_reg64)(CPUARMState *env, void *rip, uint64_t value) |
| 309 | { |
| 310 | const ARMCPRegInfo *ri = rip; |
Peter Maydell | c4241c7 | 2014-02-20 10:35:54 +0000 | [diff] [blame] | 311 | |
| 312 | ri->writefn(env, ri, value); |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | uint64_t HELPER(get_cp_reg64)(CPUARMState *env, void *rip) |
| 316 | { |
| 317 | const ARMCPRegInfo *ri = rip; |
Peter Maydell | c4241c7 | 2014-02-20 10:35:54 +0000 | [diff] [blame] | 318 | |
| 319 | return ri->readfn(env, ri); |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Peter Maydell | 9cfa0b4 | 2014-02-26 17:20:06 +0000 | [diff] [blame] | 322 | void HELPER(msr_i_pstate)(CPUARMState *env, uint32_t op, uint32_t imm) |
| 323 | { |
| 324 | /* MSR_i to update PSTATE. This is OK from EL0 only if UMA is set. |
| 325 | * Note that SPSel is never OK from EL0; we rely on handle_msr_i() |
| 326 | * to catch that case at translate time. |
| 327 | */ |
| 328 | if (arm_current_pl(env) == 0 && !(env->cp15.c1_sys & SCTLR_UMA)) { |
| 329 | raise_exception(env, EXCP_UDEF); |
| 330 | } |
| 331 | |
| 332 | switch (op) { |
| 333 | case 0x05: /* SPSel */ |
| 334 | env->pstate = deposit32(env->pstate, 0, 1, imm); |
| 335 | break; |
| 336 | case 0x1e: /* DAIFSet */ |
| 337 | env->daif |= (imm << 6) & PSTATE_DAIF; |
| 338 | break; |
| 339 | case 0x1f: /* DAIFClear */ |
| 340 | env->daif &= ~((imm << 6) & PSTATE_DAIF); |
| 341 | break; |
| 342 | default: |
| 343 | g_assert_not_reached(); |
| 344 | } |
| 345 | } |
| 346 | |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 347 | /* ??? Flag setting arithmetic is awkward because we need to do comparisons. |
| 348 | The only way to do that in TCG is a conditional branch, which clobbers |
| 349 | all our temporaries. For now implement these as helper functions. */ |
| 350 | |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 351 | /* Similarly for variable shift instructions. */ |
| 352 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 353 | uint32_t HELPER(shl_cc)(CPUARMState *env, uint32_t x, uint32_t i) |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 354 | { |
| 355 | int shift = i & 0xff; |
| 356 | if (shift >= 32) { |
| 357 | if (shift == 32) |
| 358 | env->CF = x & 1; |
| 359 | else |
| 360 | env->CF = 0; |
| 361 | return 0; |
| 362 | } else if (shift != 0) { |
| 363 | env->CF = (x >> (32 - shift)) & 1; |
| 364 | return x << shift; |
| 365 | } |
| 366 | return x; |
| 367 | } |
| 368 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 369 | uint32_t HELPER(shr_cc)(CPUARMState *env, uint32_t x, uint32_t i) |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 370 | { |
| 371 | int shift = i & 0xff; |
| 372 | if (shift >= 32) { |
| 373 | if (shift == 32) |
| 374 | env->CF = (x >> 31) & 1; |
| 375 | else |
| 376 | env->CF = 0; |
| 377 | return 0; |
| 378 | } else if (shift != 0) { |
| 379 | env->CF = (x >> (shift - 1)) & 1; |
| 380 | return x >> shift; |
| 381 | } |
| 382 | return x; |
| 383 | } |
| 384 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 385 | uint32_t HELPER(sar_cc)(CPUARMState *env, uint32_t x, uint32_t i) |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 386 | { |
| 387 | int shift = i & 0xff; |
| 388 | if (shift >= 32) { |
| 389 | env->CF = (x >> 31) & 1; |
| 390 | return (int32_t)x >> 31; |
| 391 | } else if (shift != 0) { |
| 392 | env->CF = (x >> (shift - 1)) & 1; |
| 393 | return (int32_t)x >> shift; |
| 394 | } |
| 395 | return x; |
| 396 | } |
| 397 | |
Blue Swirl | 9ef3927 | 2012-09-04 20:19:15 +0000 | [diff] [blame] | 398 | uint32_t HELPER(ror_cc)(CPUARMState *env, uint32_t x, uint32_t i) |
pbrook | 8984bd2 | 2008-03-31 03:47:48 +0000 | [diff] [blame] | 399 | { |
| 400 | int shift1, shift; |
| 401 | shift1 = i & 0xff; |
| 402 | shift = shift1 & 0x1f; |
| 403 | if (shift == 0) { |
| 404 | if (shift1 != 0) |
| 405 | env->CF = (x >> 31) & 1; |
| 406 | return x; |
| 407 | } else { |
| 408 | env->CF = (x >> (shift - 1)) & 1; |
| 409 | return ((uint32_t)x >> shift) | (x << (32 - shift)); |
| 410 | } |
| 411 | } |