bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * ARM virtual CPU header |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 4 | * Copyright (c) 2003 Fabrice Bellard |
| 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 | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 18 | */ |
| 19 | #ifndef CPU_ARM_H |
| 20 | #define CPU_ARM_H |
| 21 | |
bellard | 3cf1e03 | 2004-01-24 15:19:09 +0000 | [diff] [blame] | 22 | #define TARGET_LONG_BITS 32 |
| 23 | |
ths | 9042c0e | 2006-12-23 14:18:40 +0000 | [diff] [blame] | 24 | #define ELF_MACHINE EM_ARM |
| 25 | |
Andreas Färber | 9349b4f | 2012-03-14 01:38:32 +0100 | [diff] [blame] | 26 | #define CPUArchState struct CPUARMState |
pbrook | c276471 | 2009-03-07 15:24:59 +0000 | [diff] [blame] | 27 | |
Stefan Weil | 9a78eea | 2010-10-22 23:03:33 +0200 | [diff] [blame] | 28 | #include "config.h" |
| 29 | #include "qemu-common.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 30 | #include "exec/cpu-defs.h" |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 31 | |
Paolo Bonzini | 6b4c305 | 2012-10-24 13:12:00 +0200 | [diff] [blame] | 32 | #include "fpu/softfloat.h" |
bellard | 53cd663 | 2005-03-13 18:50:23 +0000 | [diff] [blame] | 33 | |
bellard | 1fddef4 | 2005-04-17 19:16:13 +0000 | [diff] [blame] | 34 | #define TARGET_HAS_ICE 1 |
| 35 | |
bellard | b8a9e8f | 2005-02-07 23:10:07 +0000 | [diff] [blame] | 36 | #define EXCP_UDEF 1 /* undefined instruction */ |
| 37 | #define EXCP_SWI 2 /* software interrupt */ |
| 38 | #define EXCP_PREFETCH_ABORT 3 |
| 39 | #define EXCP_DATA_ABORT 4 |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 40 | #define EXCP_IRQ 5 |
| 41 | #define EXCP_FIQ 6 |
pbrook | 06c949e | 2006-02-04 19:35:26 +0000 | [diff] [blame] | 42 | #define EXCP_BKPT 7 |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 43 | #define EXCP_EXCEPTION_EXIT 8 /* Return from v7M exception. */ |
pbrook | fbb4a2e | 2008-05-29 00:20:44 +0000 | [diff] [blame] | 44 | #define EXCP_KERNEL_TRAP 9 /* Jumped to kernel code page. */ |
Paul Brook | 426f5ab | 2009-11-22 21:35:13 +0000 | [diff] [blame] | 45 | #define EXCP_STREX 10 |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 46 | |
| 47 | #define ARMV7M_EXCP_RESET 1 |
| 48 | #define ARMV7M_EXCP_NMI 2 |
| 49 | #define ARMV7M_EXCP_HARD 3 |
| 50 | #define ARMV7M_EXCP_MEM 4 |
| 51 | #define ARMV7M_EXCP_BUS 5 |
| 52 | #define ARMV7M_EXCP_USAGE 6 |
| 53 | #define ARMV7M_EXCP_SVC 11 |
| 54 | #define ARMV7M_EXCP_DEBUG 12 |
| 55 | #define ARMV7M_EXCP_PENDSV 14 |
| 56 | #define ARMV7M_EXCP_SYSTICK 15 |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 57 | |
Richard Henderson | 403946c | 2011-05-04 13:34:29 -0700 | [diff] [blame] | 58 | /* ARM-specific interrupt pending bits. */ |
| 59 | #define CPU_INTERRUPT_FIQ CPU_INTERRUPT_TGT_EXT_1 |
| 60 | |
| 61 | |
balrog | c171313 | 2007-04-30 01:26:42 +0000 | [diff] [blame] | 62 | typedef void ARMWriteCPFunc(void *opaque, int cp_info, |
| 63 | int srcreg, int operand, uint32_t value); |
| 64 | typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info, |
| 65 | int dstreg, int operand); |
| 66 | |
balrog | f93eb9f | 2008-04-14 20:27:51 +0000 | [diff] [blame] | 67 | struct arm_boot_info; |
| 68 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 69 | #define NB_MMU_MODES 2 |
| 70 | |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 71 | /* We currently assume float and double are IEEE single and double |
| 72 | precision respectively. |
| 73 | Doing runtime conversions is tricky because VFP registers may contain |
| 74 | integer values (eg. as the result of a FTOSI instruction). |
bellard | 8e96005 | 2005-04-07 19:42:46 +0000 | [diff] [blame] | 75 | s<2n> maps to the least significant half of d<n> |
| 76 | s<2n+1> maps to the most significant half of d<n> |
| 77 | */ |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 78 | |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 79 | typedef struct CPUARMState { |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 80 | /* Regs for current mode. */ |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 81 | uint32_t regs[16]; |
Peter Maydell | b90372a | 2012-08-06 17:42:18 +0100 | [diff] [blame] | 82 | /* Frequently accessed CPSR bits are stored separately for efficiency. |
pbrook | d37aca6 | 2006-10-22 11:54:30 +0000 | [diff] [blame] | 83 | This contains all the other bits. Use cpsr_{read,write} to access |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 84 | the whole CPSR. */ |
| 85 | uint32_t uncached_cpsr; |
| 86 | uint32_t spsr; |
| 87 | |
| 88 | /* Banked registers. */ |
| 89 | uint32_t banked_spsr[6]; |
| 90 | uint32_t banked_r13[6]; |
| 91 | uint32_t banked_r14[6]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 92 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 93 | /* These hold r8-r12. */ |
| 94 | uint32_t usr_regs[5]; |
| 95 | uint32_t fiq_regs[5]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 96 | |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 97 | /* cpsr flag cache for faster execution */ |
| 98 | uint32_t CF; /* 0 or 1 */ |
| 99 | uint32_t VF; /* V is the bit 31. All other bits are undefined */ |
pbrook | 6fbe23d | 2008-04-01 17:19:11 +0000 | [diff] [blame] | 100 | uint32_t NF; /* N is bit 31. All other bits are undefined. */ |
| 101 | uint32_t ZF; /* Z set if zero. */ |
bellard | 99c475a | 2005-01-31 20:45:13 +0000 | [diff] [blame] | 102 | uint32_t QF; /* 0 or 1 */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 103 | uint32_t GE; /* cpsr[19:16] */ |
pbrook | b26eefb | 2008-03-31 03:44:26 +0000 | [diff] [blame] | 104 | uint32_t thumb; /* cpsr[5]. 0 = arm mode, 1 = thumb mode. */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 105 | uint32_t condexec_bits; /* IT bits. cpsr[15:10,26:25]. */ |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 106 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 107 | /* System control coprocessor (cp15) */ |
| 108 | struct { |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 109 | uint32_t c0_cpuid; |
pbrook | a49ea27 | 2008-12-19 13:37:53 +0000 | [diff] [blame] | 110 | uint32_t c0_cssel; /* Cache size selection. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 111 | uint32_t c1_sys; /* System control register. */ |
| 112 | uint32_t c1_coproc; /* Coprocessor access register. */ |
balrog | 610c3c8 | 2007-06-24 12:09:48 +0000 | [diff] [blame] | 113 | uint32_t c1_xscaleauxcr; /* XScale auxiliary control register. */ |
Rob Herring | 2be2762 | 2012-01-13 17:25:08 +0000 | [diff] [blame] | 114 | uint32_t c1_scr; /* secure config register. */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 115 | uint32_t c2_base0; /* MMU translation table base 0. */ |
Peter Maydell | 891a2fe | 2012-07-12 10:59:09 +0000 | [diff] [blame] | 116 | uint32_t c2_base0_hi; /* MMU translation table base 0, high 32 bits */ |
| 117 | uint32_t c2_base1; /* MMU translation table base 0. */ |
| 118 | uint32_t c2_base1_hi; /* MMU translation table base 1, high 32 bits */ |
pbrook | b2fa179 | 2008-10-22 19:22:30 +0000 | [diff] [blame] | 119 | uint32_t c2_control; /* MMU translation table base control. */ |
| 120 | uint32_t c2_mask; /* MMU translation table base selection mask. */ |
| 121 | uint32_t c2_base_mask; /* MMU translation table base 0 mask. */ |
pbrook | ce81986 | 2007-05-08 02:30:40 +0000 | [diff] [blame] | 122 | uint32_t c2_data; /* MPU data cachable bits. */ |
| 123 | uint32_t c2_insn; /* MPU instruction cachable bits. */ |
| 124 | uint32_t c3; /* MMU domain access control register |
| 125 | MPU write buffer control. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 126 | uint32_t c5_insn; /* Fault status registers. */ |
| 127 | uint32_t c5_data; |
pbrook | ce81986 | 2007-05-08 02:30:40 +0000 | [diff] [blame] | 128 | uint32_t c6_region[8]; /* MPU base/size registers. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 129 | uint32_t c6_insn; /* Fault address registers. */ |
| 130 | uint32_t c6_data; |
Adam Lackorzynski | f8bf860 | 2011-03-05 13:51:44 +0100 | [diff] [blame] | 131 | uint32_t c7_par; /* Translation result. */ |
Peter Maydell | 891a2fe | 2012-07-12 10:59:09 +0000 | [diff] [blame] | 132 | uint32_t c7_par_hi; /* Translation result, high 32 bits */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 133 | uint32_t c9_insn; /* Cache lockdown registers. */ |
| 134 | uint32_t c9_data; |
Peter Maydell | 74594c9 | 2011-03-22 12:16:16 +0000 | [diff] [blame] | 135 | uint32_t c9_pmcr; /* performance monitor control register */ |
| 136 | uint32_t c9_pmcnten; /* perf monitor counter enables */ |
| 137 | uint32_t c9_pmovsr; /* perf monitor overflow status */ |
| 138 | uint32_t c9_pmxevtyper; /* perf monitor event type */ |
| 139 | uint32_t c9_pmuserenr; /* perf monitor user enable */ |
| 140 | uint32_t c9_pminten; /* perf monitor interrupt enables */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 141 | uint32_t c13_fcse; /* FCSE PID. */ |
| 142 | uint32_t c13_context; /* Context ID. */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 143 | uint32_t c13_tls1; /* User RW Thread register. */ |
| 144 | uint32_t c13_tls2; /* User RO Thread register. */ |
| 145 | uint32_t c13_tls3; /* Privileged Thread register. */ |
balrog | c171313 | 2007-04-30 01:26:42 +0000 | [diff] [blame] | 146 | uint32_t c15_cpar; /* XScale Coprocessor Access Register */ |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 147 | uint32_t c15_ticonfig; /* TI925T configuration byte. */ |
| 148 | uint32_t c15_i_max; /* Maximum D-cache dirty line index. */ |
| 149 | uint32_t c15_i_min; /* Minimum D-cache dirty line index. */ |
| 150 | uint32_t c15_threadid; /* TI debugger thread-ID. */ |
Mark Langsdorf | 7da362d | 2012-01-05 15:49:06 +0000 | [diff] [blame] | 151 | uint32_t c15_config_base_address; /* SCU base address. */ |
| 152 | uint32_t c15_diagnostic; /* diagnostic register */ |
| 153 | uint32_t c15_power_diagnostic; |
| 154 | uint32_t c15_power_control; /* power control */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 155 | } cp15; |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 156 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 157 | struct { |
| 158 | uint32_t other_sp; |
| 159 | uint32_t vecbase; |
| 160 | uint32_t basepri; |
| 161 | uint32_t control; |
| 162 | int current_sp; |
| 163 | int exception; |
| 164 | int pending_exception; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 165 | } v7m; |
| 166 | |
pbrook | fe1479c | 2008-12-19 13:18:36 +0000 | [diff] [blame] | 167 | /* Thumb-2 EE state. */ |
| 168 | uint32_t teecr; |
| 169 | uint32_t teehbr; |
| 170 | |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 171 | /* VFP coprocessor state. */ |
| 172 | struct { |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 173 | float64 regs[32]; |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 174 | |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 175 | uint32_t xregs[16]; |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 176 | /* We store these fpcsr fields separately for convenience. */ |
| 177 | int vec_len; |
| 178 | int vec_stride; |
| 179 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 180 | /* scratch space when Tn are not sufficient. */ |
| 181 | uint32_t scratch[8]; |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 182 | |
Peter Maydell | 3a492f3 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 183 | /* fp_status is the "normal" fp status. standard_fp_status retains |
| 184 | * values corresponding to the ARM "Standard FPSCR Value", ie |
| 185 | * default-NaN, flush-to-zero, round-to-nearest and is used by |
| 186 | * any operations (generally Neon) which the architecture defines |
| 187 | * as controlled by the standard FPSCR value rather than the FPSCR. |
| 188 | * |
| 189 | * To avoid having to transfer exception bits around, we simply |
| 190 | * say that the FPSCR cumulative exception flags are the logical |
| 191 | * OR of the flags in the two fp statuses. This relies on the |
| 192 | * only thing which needs to read the exception flags being |
| 193 | * an explicit FPSCR read. |
| 194 | */ |
bellard | 53cd663 | 2005-03-13 18:50:23 +0000 | [diff] [blame] | 195 | float_status fp_status; |
Peter Maydell | 3a492f3 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 196 | float_status standard_fp_status; |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 197 | } vfp; |
Paul Brook | 426f5ab | 2009-11-22 21:35:13 +0000 | [diff] [blame] | 198 | uint32_t exclusive_addr; |
| 199 | uint32_t exclusive_val; |
| 200 | uint32_t exclusive_high; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 201 | #if defined(CONFIG_USER_ONLY) |
Paul Brook | 426f5ab | 2009-11-22 21:35:13 +0000 | [diff] [blame] | 202 | uint32_t exclusive_test; |
| 203 | uint32_t exclusive_info; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 204 | #endif |
bellard | b7bcbe9 | 2005-02-22 19:27:29 +0000 | [diff] [blame] | 205 | |
balrog | 18c9b56 | 2007-04-30 02:02:17 +0000 | [diff] [blame] | 206 | /* iwMMXt coprocessor state. */ |
| 207 | struct { |
| 208 | uint64_t regs[16]; |
| 209 | uint64_t val; |
| 210 | |
| 211 | uint32_t cregs[16]; |
| 212 | } iwmmxt; |
| 213 | |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 214 | /* For mixed endian mode. */ |
| 215 | bool bswap_code; |
| 216 | |
pbrook | ce4defa | 2006-02-09 16:49:55 +0000 | [diff] [blame] | 217 | #if defined(CONFIG_USER_ONLY) |
| 218 | /* For usermode syscall translation. */ |
| 219 | int eabi; |
| 220 | #endif |
| 221 | |
bellard | a316d33 | 2005-11-20 10:32:34 +0000 | [diff] [blame] | 222 | CPU_COMMON |
| 223 | |
balrog | 9d55199 | 2007-04-30 02:24:42 +0000 | [diff] [blame] | 224 | /* These fields after the common ones so they are preserved on reset. */ |
Lars Munch | 9ba8c3f | 2010-05-08 22:42:43 +0200 | [diff] [blame] | 225 | |
Peter Maydell | 581be09 | 2012-04-20 17:58:31 +0000 | [diff] [blame] | 226 | /* Internal CPU feature flags. */ |
Peter Maydell | 918f5dc | 2012-07-12 10:59:06 +0000 | [diff] [blame] | 227 | uint64_t features; |
Peter Maydell | 581be09 | 2012-04-20 17:58:31 +0000 | [diff] [blame] | 228 | |
Paul Brook | 983fe82 | 2010-04-05 19:34:51 +0100 | [diff] [blame] | 229 | void *nvic; |
Stefan Weil | 462a8bc | 2011-06-23 17:53:48 +0200 | [diff] [blame] | 230 | const struct arm_boot_info *boot_info; |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 231 | } CPUARMState; |
| 232 | |
Andreas Färber | 778c3a0 | 2012-04-20 07:39:14 +0000 | [diff] [blame] | 233 | #include "cpu-qom.h" |
| 234 | |
| 235 | ARMCPU *cpu_arm_init(const char *cpu_model); |
pbrook | b26eefb | 2008-03-31 03:44:26 +0000 | [diff] [blame] | 236 | void arm_translate_init(void); |
Andreas Färber | 1496926 | 2013-01-05 10:18:18 +0100 | [diff] [blame] | 237 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu); |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 238 | int cpu_arm_exec(CPUARMState *s); |
Christoffer Dall | 494b00c | 2013-03-05 00:34:41 +0000 | [diff] [blame] | 239 | int bank_number(int mode); |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 240 | void switch_mode(CPUARMState *, int); |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 241 | uint32_t do_arm_semihosting(CPUARMState *env); |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 242 | |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 243 | /* you can call this signal handler from your SIGBUS and SIGSEGV |
| 244 | signal handlers to inform the virtual CPU of exceptions. non zero |
| 245 | is returned if the signal was handled by the virtual CPU. */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 246 | int cpu_arm_signal_handler(int host_signum, void *pinfo, |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 247 | void *puc); |
aurel32 | 84a031c | 2009-02-07 15:19:20 +0000 | [diff] [blame] | 248 | int cpu_arm_handle_mmu_fault (CPUARMState *env, target_ulong address, int rw, |
Blue Swirl | 97b348e | 2011-08-01 16:12:17 +0000 | [diff] [blame] | 249 | int mmu_idx); |
Nathan Froyd | 0b5c1ce | 2009-08-10 13:37:36 -0700 | [diff] [blame] | 250 | #define cpu_handle_mmu_fault cpu_arm_handle_mmu_fault |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 251 | |
pbrook | fbb4a2e | 2008-05-29 00:20:44 +0000 | [diff] [blame] | 252 | static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls) |
| 253 | { |
| 254 | env->cp15.c13_tls2 = newtls; |
| 255 | } |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 256 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 257 | #define CPSR_M (0x1f) |
| 258 | #define CPSR_T (1 << 5) |
| 259 | #define CPSR_F (1 << 6) |
| 260 | #define CPSR_I (1 << 7) |
| 261 | #define CPSR_A (1 << 8) |
| 262 | #define CPSR_E (1 << 9) |
| 263 | #define CPSR_IT_2_7 (0xfc00) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 264 | #define CPSR_GE (0xf << 16) |
| 265 | #define CPSR_RESERVED (0xf << 20) |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 266 | #define CPSR_J (1 << 24) |
| 267 | #define CPSR_IT_0_1 (3 << 25) |
| 268 | #define CPSR_Q (1 << 27) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 269 | #define CPSR_V (1 << 28) |
| 270 | #define CPSR_C (1 << 29) |
| 271 | #define CPSR_Z (1 << 30) |
| 272 | #define CPSR_N (1 << 31) |
| 273 | #define CPSR_NZCV (CPSR_N | CPSR_Z | CPSR_C | CPSR_V) |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 274 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 275 | #define CPSR_IT (CPSR_IT_0_1 | CPSR_IT_2_7) |
| 276 | #define CACHED_CPSR_BITS (CPSR_T | CPSR_GE | CPSR_IT | CPSR_Q | CPSR_NZCV) |
| 277 | /* Bits writable in user mode. */ |
| 278 | #define CPSR_USER (CPSR_NZCV | CPSR_Q | CPSR_GE) |
| 279 | /* Execution state bits. MRS read as zero, MSR writes ignored. */ |
| 280 | #define CPSR_EXEC (CPSR_T | CPSR_IT | CPSR_J) |
| 281 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 282 | /* Return the current CPSR value. */ |
balrog | 2f4a40e | 2007-11-13 01:50:15 +0000 | [diff] [blame] | 283 | uint32_t cpsr_read(CPUARMState *env); |
| 284 | /* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */ |
| 285 | void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask); |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 286 | |
| 287 | /* Return the current xPSR value. */ |
| 288 | static inline uint32_t xpsr_read(CPUARMState *env) |
| 289 | { |
| 290 | int ZF; |
pbrook | 6fbe23d | 2008-04-01 17:19:11 +0000 | [diff] [blame] | 291 | ZF = (env->ZF == 0); |
| 292 | return (env->NF & 0x80000000) | (ZF << 30) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 293 | | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27) |
| 294 | | (env->thumb << 24) | ((env->condexec_bits & 3) << 25) |
| 295 | | ((env->condexec_bits & 0xfc) << 8) |
| 296 | | env->v7m.exception; |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 297 | } |
| 298 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 299 | /* Set the xPSR. Note that some bits of mask must be all-set or all-clear. */ |
| 300 | static inline void xpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) |
| 301 | { |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 302 | if (mask & CPSR_NZCV) { |
pbrook | 6fbe23d | 2008-04-01 17:19:11 +0000 | [diff] [blame] | 303 | env->ZF = (~val) & CPSR_Z; |
| 304 | env->NF = val; |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 305 | env->CF = (val >> 29) & 1; |
| 306 | env->VF = (val << 3) & 0x80000000; |
| 307 | } |
| 308 | if (mask & CPSR_Q) |
| 309 | env->QF = ((val & CPSR_Q) != 0); |
| 310 | if (mask & (1 << 24)) |
| 311 | env->thumb = ((val & (1 << 24)) != 0); |
| 312 | if (mask & CPSR_IT_0_1) { |
| 313 | env->condexec_bits &= ~3; |
| 314 | env->condexec_bits |= (val >> 25) & 3; |
| 315 | } |
| 316 | if (mask & CPSR_IT_2_7) { |
| 317 | env->condexec_bits &= 3; |
| 318 | env->condexec_bits |= (val >> 8) & 0xfc; |
| 319 | } |
| 320 | if (mask & 0x1ff) { |
| 321 | env->v7m.exception = val & 0x1ff; |
| 322 | } |
| 323 | } |
| 324 | |
Peter Maydell | 0165329 | 2010-11-24 15:20:04 +0000 | [diff] [blame] | 325 | /* Return the current FPSCR value. */ |
| 326 | uint32_t vfp_get_fpscr(CPUARMState *env); |
| 327 | void vfp_set_fpscr(CPUARMState *env, uint32_t val); |
| 328 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 329 | enum arm_cpu_mode { |
| 330 | ARM_CPU_MODE_USR = 0x10, |
| 331 | ARM_CPU_MODE_FIQ = 0x11, |
| 332 | ARM_CPU_MODE_IRQ = 0x12, |
| 333 | ARM_CPU_MODE_SVC = 0x13, |
| 334 | ARM_CPU_MODE_ABT = 0x17, |
| 335 | ARM_CPU_MODE_UND = 0x1b, |
| 336 | ARM_CPU_MODE_SYS = 0x1f |
| 337 | }; |
| 338 | |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 339 | /* VFP system registers. */ |
| 340 | #define ARM_VFP_FPSID 0 |
| 341 | #define ARM_VFP_FPSCR 1 |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 342 | #define ARM_VFP_MVFR1 6 |
| 343 | #define ARM_VFP_MVFR0 7 |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 344 | #define ARM_VFP_FPEXC 8 |
| 345 | #define ARM_VFP_FPINST 9 |
| 346 | #define ARM_VFP_FPINST2 10 |
| 347 | |
balrog | 18c9b56 | 2007-04-30 02:02:17 +0000 | [diff] [blame] | 348 | /* iwMMXt coprocessor control registers. */ |
| 349 | #define ARM_IWMMXT_wCID 0 |
| 350 | #define ARM_IWMMXT_wCon 1 |
| 351 | #define ARM_IWMMXT_wCSSF 2 |
| 352 | #define ARM_IWMMXT_wCASF 3 |
| 353 | #define ARM_IWMMXT_wCGR0 8 |
| 354 | #define ARM_IWMMXT_wCGR1 9 |
| 355 | #define ARM_IWMMXT_wCGR2 10 |
| 356 | #define ARM_IWMMXT_wCGR3 11 |
| 357 | |
Benoit Canet | ce854d7 | 2011-11-09 07:32:59 +0000 | [diff] [blame] | 358 | /* If adding a feature bit which corresponds to a Linux ELF |
| 359 | * HWCAP bit, remember to update the feature-bit-to-hwcap |
| 360 | * mapping in linux-user/elfload.c:get_elf_hwcap(). |
| 361 | */ |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 362 | enum arm_features { |
| 363 | ARM_FEATURE_VFP, |
balrog | c171313 | 2007-04-30 01:26:42 +0000 | [diff] [blame] | 364 | ARM_FEATURE_AUXCR, /* ARM1026 Auxiliary control register. */ |
| 365 | ARM_FEATURE_XSCALE, /* Intel XScale extensions. */ |
pbrook | ce81986 | 2007-05-08 02:30:40 +0000 | [diff] [blame] | 366 | ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension. */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 367 | ARM_FEATURE_V6, |
| 368 | ARM_FEATURE_V6K, |
| 369 | ARM_FEATURE_V7, |
| 370 | ARM_FEATURE_THUMB2, |
balrog | c3d2689 | 2007-07-29 17:57:26 +0000 | [diff] [blame] | 371 | ARM_FEATURE_MPU, /* Only has Memory Protection Unit, not full MMU. */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 372 | ARM_FEATURE_VFP3, |
Paul Brook | 6001149 | 2009-11-19 16:45:20 +0000 | [diff] [blame] | 373 | ARM_FEATURE_VFP_FP16, |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 374 | ARM_FEATURE_NEON, |
Peter Maydell | 4778999 | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 375 | ARM_FEATURE_THUMB_DIV, /* divide supported in Thumb encoding */ |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 376 | ARM_FEATURE_M, /* Microcontroller profile. */ |
pbrook | fe1479c | 2008-12-19 13:18:36 +0000 | [diff] [blame] | 377 | ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling. */ |
Peter Maydell | e1bbf44 | 2011-02-03 19:43:22 +0000 | [diff] [blame] | 378 | ARM_FEATURE_THUMB2EE, |
Dmitry Eremin-Solenikov | be5e7a7 | 2011-04-04 17:38:44 +0400 | [diff] [blame] | 379 | ARM_FEATURE_V7MP, /* v7 Multiprocessing Extensions */ |
| 380 | ARM_FEATURE_V4T, |
| 381 | ARM_FEATURE_V5, |
Dmitry Eremin-Solenikov | 5bc95aa | 2011-04-19 18:56:45 +0400 | [diff] [blame] | 382 | ARM_FEATURE_STRONGARM, |
Peter Maydell | 906879a | 2011-07-20 10:32:55 +0000 | [diff] [blame] | 383 | ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */ |
Peter Maydell | b8b8ea0 | 2011-10-19 16:14:06 +0000 | [diff] [blame] | 384 | ARM_FEATURE_ARM_DIV, /* divide supported in ARM encoding */ |
Peter Maydell | da97f52 | 2011-10-19 16:14:07 +0000 | [diff] [blame] | 385 | ARM_FEATURE_VFP4, /* VFPv4 (implies that NEON is v2) */ |
Peter Maydell | 0383ac0 | 2012-01-25 12:42:29 +0000 | [diff] [blame] | 386 | ARM_FEATURE_GENERIC_TIMER, |
Andrew Towers | 06ed5d6 | 2012-03-29 02:41:08 +0000 | [diff] [blame] | 387 | ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */ |
Peter Maydell | 1047b9d | 2012-06-20 11:57:15 +0000 | [diff] [blame] | 388 | ARM_FEATURE_DUMMY_C15_REGS, /* RAZ/WI all of cp15 crn=15 */ |
Peter Maydell | c480421 | 2012-06-20 11:57:17 +0000 | [diff] [blame] | 389 | ARM_FEATURE_CACHE_TEST_CLEAN, /* 926/1026 style test-and-clean ops */ |
| 390 | ARM_FEATURE_CACHE_DIRTY_REG, /* 1136/1176 cache dirty status register */ |
| 391 | ARM_FEATURE_CACHE_BLOCK_OPS, /* v6 optional cache block operations */ |
Peter Maydell | 81bdde9 | 2012-06-20 11:57:20 +0000 | [diff] [blame] | 392 | ARM_FEATURE_MPIDR, /* has cp15 MPIDR */ |
Peter Maydell | de9b05b | 2012-07-12 10:59:05 +0000 | [diff] [blame] | 393 | ARM_FEATURE_PXN, /* has Privileged Execute Never bit */ |
| 394 | ARM_FEATURE_LPAE, /* has Large Physical Address Extension */ |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | static inline int arm_feature(CPUARMState *env, int feature) |
| 398 | { |
Peter Maydell | 918f5dc | 2012-07-12 10:59:06 +0000 | [diff] [blame] | 399 | return (env->features & (1ULL << feature)) != 0; |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 400 | } |
| 401 | |
Stefan Weil | 9a78eea | 2010-10-22 23:03:33 +0200 | [diff] [blame] | 402 | void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf); |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 403 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 404 | /* Interface between CPU and Interrupt controller. */ |
| 405 | void armv7m_nvic_set_pending(void *opaque, int irq); |
| 406 | int armv7m_nvic_acknowledge_irq(void *opaque); |
| 407 | void armv7m_nvic_complete_irq(void *opaque, int irq); |
| 408 | |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 409 | /* Interface for defining coprocessor registers. |
| 410 | * Registers are defined in tables of arm_cp_reginfo structs |
| 411 | * which are passed to define_arm_cp_regs(). |
| 412 | */ |
| 413 | |
| 414 | /* When looking up a coprocessor register we look for it |
| 415 | * via an integer which encodes all of: |
| 416 | * coprocessor number |
| 417 | * Crn, Crm, opc1, opc2 fields |
| 418 | * 32 or 64 bit register (ie is it accessed via MRC/MCR |
| 419 | * or via MRRC/MCRR?) |
| 420 | * We allow 4 bits for opc1 because MRRC/MCRR have a 4 bit field. |
| 421 | * (In this case crn and opc2 should be zero.) |
| 422 | */ |
| 423 | #define ENCODE_CP_REG(cp, is64, crn, crm, opc1, opc2) \ |
| 424 | (((cp) << 16) | ((is64) << 15) | ((crn) << 11) | \ |
| 425 | ((crm) << 7) | ((opc1) << 3) | (opc2)) |
| 426 | |
Peter Maydell | 4b6a83f | 2012-06-20 11:57:06 +0000 | [diff] [blame] | 427 | /* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a |
| 428 | * special-behaviour cp reg and bits [15..8] indicate what behaviour |
| 429 | * it has. Otherwise it is a simple cp reg, where CONST indicates that |
| 430 | * TCG can assume the value to be constant (ie load at translate time) |
| 431 | * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END |
| 432 | * indicates that the TB should not be ended after a write to this register |
| 433 | * (the default is that the TB ends after cp writes). OVERRIDE permits |
| 434 | * a register definition to override a previous definition for the |
| 435 | * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the |
| 436 | * old must have the OVERRIDE bit set. |
| 437 | */ |
| 438 | #define ARM_CP_SPECIAL 1 |
| 439 | #define ARM_CP_CONST 2 |
| 440 | #define ARM_CP_64BIT 4 |
| 441 | #define ARM_CP_SUPPRESS_TB_END 8 |
| 442 | #define ARM_CP_OVERRIDE 16 |
| 443 | #define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8)) |
| 444 | #define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8)) |
| 445 | #define ARM_LAST_SPECIAL ARM_CP_WFI |
| 446 | /* Used only as a terminator for ARMCPRegInfo lists */ |
| 447 | #define ARM_CP_SENTINEL 0xffff |
| 448 | /* Mask of only the flag bits in a type field */ |
| 449 | #define ARM_CP_FLAG_MASK 0x1f |
| 450 | |
| 451 | /* Return true if cptype is a valid type field. This is used to try to |
| 452 | * catch errors where the sentinel has been accidentally left off the end |
| 453 | * of a list of registers. |
| 454 | */ |
| 455 | static inline bool cptype_valid(int cptype) |
| 456 | { |
| 457 | return ((cptype & ~ARM_CP_FLAG_MASK) == 0) |
| 458 | || ((cptype & ARM_CP_SPECIAL) && |
| 459 | (cptype <= ARM_LAST_SPECIAL)); |
| 460 | } |
| 461 | |
| 462 | /* Access rights: |
| 463 | * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM |
| 464 | * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and |
| 465 | * PL2 (hyp). The other level which has Read and Write bits is Secure PL1 |
| 466 | * (ie any of the privileged modes in Secure state, or Monitor mode). |
| 467 | * If a register is accessible in one privilege level it's always accessible |
| 468 | * in higher privilege levels too. Since "Secure PL1" also follows this rule |
| 469 | * (ie anything visible in PL2 is visible in S-PL1, some things are only |
| 470 | * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the |
| 471 | * terminology a little and call this PL3. |
| 472 | * |
| 473 | * If access permissions for a register are more complex than can be |
| 474 | * described with these bits, then use a laxer set of restrictions, and |
| 475 | * do the more restrictive/complex check inside a helper function. |
| 476 | */ |
| 477 | #define PL3_R 0x80 |
| 478 | #define PL3_W 0x40 |
| 479 | #define PL2_R (0x20 | PL3_R) |
| 480 | #define PL2_W (0x10 | PL3_W) |
| 481 | #define PL1_R (0x08 | PL2_R) |
| 482 | #define PL1_W (0x04 | PL2_W) |
| 483 | #define PL0_R (0x02 | PL1_R) |
| 484 | #define PL0_W (0x01 | PL1_W) |
| 485 | |
| 486 | #define PL3_RW (PL3_R | PL3_W) |
| 487 | #define PL2_RW (PL2_R | PL2_W) |
| 488 | #define PL1_RW (PL1_R | PL1_W) |
| 489 | #define PL0_RW (PL0_R | PL0_W) |
| 490 | |
| 491 | static inline int arm_current_pl(CPUARMState *env) |
| 492 | { |
| 493 | if ((env->uncached_cpsr & 0x1f) == ARM_CPU_MODE_USR) { |
| 494 | return 0; |
| 495 | } |
| 496 | /* We don't currently implement the Virtualization or TrustZone |
| 497 | * extensions, so PL2 and PL3 don't exist for us. |
| 498 | */ |
| 499 | return 1; |
| 500 | } |
| 501 | |
| 502 | typedef struct ARMCPRegInfo ARMCPRegInfo; |
| 503 | |
| 504 | /* Access functions for coprocessor registers. These should return |
| 505 | * 0 on success, or one of the EXCP_* constants if access should cause |
| 506 | * an exception (in which case *value is not written). |
| 507 | */ |
| 508 | typedef int CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque, |
| 509 | uint64_t *value); |
| 510 | typedef int CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque, |
| 511 | uint64_t value); |
| 512 | /* Hook function for register reset */ |
| 513 | typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque); |
| 514 | |
| 515 | #define CP_ANY 0xff |
| 516 | |
| 517 | /* Definition of an ARM coprocessor register */ |
| 518 | struct ARMCPRegInfo { |
| 519 | /* Name of register (useful mainly for debugging, need not be unique) */ |
| 520 | const char *name; |
| 521 | /* Location of register: coprocessor number and (crn,crm,opc1,opc2) |
| 522 | * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a |
| 523 | * 'wildcard' field -- any value of that field in the MRC/MCR insn |
| 524 | * will be decoded to this register. The register read and write |
| 525 | * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2 |
| 526 | * used by the program, so it is possible to register a wildcard and |
| 527 | * then behave differently on read/write if necessary. |
| 528 | * For 64 bit registers, only crm and opc1 are relevant; crn and opc2 |
| 529 | * must both be zero. |
| 530 | */ |
| 531 | uint8_t cp; |
| 532 | uint8_t crn; |
| 533 | uint8_t crm; |
| 534 | uint8_t opc1; |
| 535 | uint8_t opc2; |
| 536 | /* Register type: ARM_CP_* bits/values */ |
| 537 | int type; |
| 538 | /* Access rights: PL*_[RW] */ |
| 539 | int access; |
| 540 | /* The opaque pointer passed to define_arm_cp_regs_with_opaque() when |
| 541 | * this register was defined: can be used to hand data through to the |
| 542 | * register read/write functions, since they are passed the ARMCPRegInfo*. |
| 543 | */ |
| 544 | void *opaque; |
| 545 | /* Value of this register, if it is ARM_CP_CONST. Otherwise, if |
| 546 | * fieldoffset is non-zero, the reset value of the register. |
| 547 | */ |
| 548 | uint64_t resetvalue; |
| 549 | /* Offset of the field in CPUARMState for this register. This is not |
| 550 | * needed if either: |
| 551 | * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs |
| 552 | * 2. both readfn and writefn are specified |
| 553 | */ |
| 554 | ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */ |
| 555 | /* Function for handling reads of this register. If NULL, then reads |
| 556 | * will be done by loading from the offset into CPUARMState specified |
| 557 | * by fieldoffset. |
| 558 | */ |
| 559 | CPReadFn *readfn; |
| 560 | /* Function for handling writes of this register. If NULL, then writes |
| 561 | * will be done by writing to the offset into CPUARMState specified |
| 562 | * by fieldoffset. |
| 563 | */ |
| 564 | CPWriteFn *writefn; |
| 565 | /* Function for resetting the register. If NULL, then reset will be done |
| 566 | * by writing resetvalue to the field specified in fieldoffset. If |
| 567 | * fieldoffset is 0 then no reset will be done. |
| 568 | */ |
| 569 | CPResetFn *resetfn; |
| 570 | }; |
| 571 | |
| 572 | /* Macros which are lvalues for the field in CPUARMState for the |
| 573 | * ARMCPRegInfo *ri. |
| 574 | */ |
| 575 | #define CPREG_FIELD32(env, ri) \ |
| 576 | (*(uint32_t *)((char *)(env) + (ri)->fieldoffset)) |
| 577 | #define CPREG_FIELD64(env, ri) \ |
| 578 | (*(uint64_t *)((char *)(env) + (ri)->fieldoffset)) |
| 579 | |
| 580 | #define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL } |
| 581 | |
| 582 | void define_arm_cp_regs_with_opaque(ARMCPU *cpu, |
| 583 | const ARMCPRegInfo *regs, void *opaque); |
| 584 | void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
| 585 | const ARMCPRegInfo *regs, void *opaque); |
| 586 | static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs) |
| 587 | { |
| 588 | define_arm_cp_regs_with_opaque(cpu, regs, 0); |
| 589 | } |
| 590 | static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs) |
| 591 | { |
| 592 | define_one_arm_cp_reg_with_opaque(cpu, regs, 0); |
| 593 | } |
| 594 | const ARMCPRegInfo *get_arm_cp_reginfo(ARMCPU *cpu, uint32_t encoded_cp); |
| 595 | |
| 596 | /* CPWriteFn that can be used to implement writes-ignored behaviour */ |
| 597 | int arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri, |
| 598 | uint64_t value); |
| 599 | /* CPReadFn that can be used for read-as-zero behaviour */ |
| 600 | int arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t *value); |
| 601 | |
| 602 | static inline bool cp_access_ok(CPUARMState *env, |
| 603 | const ARMCPRegInfo *ri, int isread) |
| 604 | { |
| 605 | return (ri->access >> ((arm_current_pl(env) * 2) + isread)) & 1; |
| 606 | } |
| 607 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 608 | /* Does the core conform to the the "MicroController" profile. e.g. Cortex-M3. |
| 609 | Note the M in older cores (eg. ARM7TDMI) stands for Multiply. These are |
| 610 | conventional cores (ie. Application or Realtime profile). */ |
| 611 | |
| 612 | #define IS_M(env) arm_feature(env, ARM_FEATURE_M) |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 613 | |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 614 | #define ARM_CPUID_TI915T 0x54029152 |
| 615 | #define ARM_CPUID_TI925T 0x54029252 |
pbrook | 40f137e | 2006-02-20 00:33:36 +0000 | [diff] [blame] | 616 | |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 617 | #if defined(CONFIG_USER_ONLY) |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 618 | #define TARGET_PAGE_BITS 12 |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 619 | #else |
| 620 | /* The ARM MMU allows 1k pages. */ |
| 621 | /* ??? Linux doesn't actually use these, and they're deprecated in recent |
balrog | 82d1797 | 2007-07-24 01:07:44 +0000 | [diff] [blame] | 622 | architecture revisions. Maybe a configure option to disable them. */ |
bellard | b5ff1b3 | 2005-11-26 10:38:39 +0000 | [diff] [blame] | 623 | #define TARGET_PAGE_BITS 10 |
| 624 | #endif |
ths | 9467d44 | 2007-06-03 21:02:38 +0000 | [diff] [blame] | 625 | |
Peter Maydell | 3cc0cd6 | 2012-07-12 10:59:03 +0000 | [diff] [blame] | 626 | #define TARGET_PHYS_ADDR_SPACE_BITS 40 |
Richard Henderson | 5270589 | 2010-03-10 14:33:23 -0800 | [diff] [blame] | 627 | #define TARGET_VIRT_ADDR_SPACE_BITS 32 |
| 628 | |
Peter Maydell | ad37ad5 | 2012-05-10 12:56:09 +0000 | [diff] [blame] | 629 | static inline CPUARMState *cpu_init(const char *cpu_model) |
| 630 | { |
| 631 | ARMCPU *cpu = cpu_arm_init(cpu_model); |
| 632 | if (cpu) { |
| 633 | return &cpu->env; |
| 634 | } |
| 635 | return NULL; |
| 636 | } |
| 637 | |
ths | 9467d44 | 2007-06-03 21:02:38 +0000 | [diff] [blame] | 638 | #define cpu_exec cpu_arm_exec |
| 639 | #define cpu_gen_code cpu_arm_gen_code |
| 640 | #define cpu_signal_handler cpu_arm_signal_handler |
j_mayer | c732abe | 2007-10-12 06:47:46 +0000 | [diff] [blame] | 641 | #define cpu_list arm_cpu_list |
ths | 9467d44 | 2007-06-03 21:02:38 +0000 | [diff] [blame] | 642 | |
Peter Maydell | 891a2fe | 2012-07-12 10:59:09 +0000 | [diff] [blame] | 643 | #define CPU_SAVE_VERSION 9 |
pbrook | 9ee6e8b | 2007-11-11 00:04:49 +0000 | [diff] [blame] | 644 | |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 645 | /* MMU modes definitions */ |
| 646 | #define MMU_MODE0_SUFFIX _kernel |
| 647 | #define MMU_MODE1_SUFFIX _user |
| 648 | #define MMU_USER_IDX 1 |
Andreas Färber | 0ecb72a | 2012-03-14 01:38:21 +0100 | [diff] [blame] | 649 | static inline int cpu_mmu_index (CPUARMState *env) |
j_mayer | 6ebbf39 | 2007-10-14 07:07:08 +0000 | [diff] [blame] | 650 | { |
| 651 | return (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_USR ? 1 : 0; |
| 652 | } |
| 653 | |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 654 | #if defined(CONFIG_USER_ONLY) |
Andreas Färber | 0ecb72a | 2012-03-14 01:38:21 +0100 | [diff] [blame] | 655 | static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp) |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 656 | { |
pbrook | f8ed707 | 2008-05-30 17:54:15 +0000 | [diff] [blame] | 657 | if (newsp) |
pbrook | 6e68e07 | 2008-05-30 17:22:15 +0000 | [diff] [blame] | 658 | env->regs[13] = newsp; |
| 659 | env->regs[0] = 0; |
| 660 | } |
| 661 | #endif |
| 662 | |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 663 | #include "exec/cpu-all.h" |
aliguori | 622ed36 | 2008-11-18 19:36:03 +0000 | [diff] [blame] | 664 | |
Peter Maydell | a170576 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 665 | /* Bit usage in the TB flags field: */ |
| 666 | #define ARM_TBFLAG_THUMB_SHIFT 0 |
| 667 | #define ARM_TBFLAG_THUMB_MASK (1 << ARM_TBFLAG_THUMB_SHIFT) |
| 668 | #define ARM_TBFLAG_VECLEN_SHIFT 1 |
| 669 | #define ARM_TBFLAG_VECLEN_MASK (0x7 << ARM_TBFLAG_VECLEN_SHIFT) |
| 670 | #define ARM_TBFLAG_VECSTRIDE_SHIFT 4 |
| 671 | #define ARM_TBFLAG_VECSTRIDE_MASK (0x3 << ARM_TBFLAG_VECSTRIDE_SHIFT) |
| 672 | #define ARM_TBFLAG_PRIV_SHIFT 6 |
| 673 | #define ARM_TBFLAG_PRIV_MASK (1 << ARM_TBFLAG_PRIV_SHIFT) |
| 674 | #define ARM_TBFLAG_VFPEN_SHIFT 7 |
| 675 | #define ARM_TBFLAG_VFPEN_MASK (1 << ARM_TBFLAG_VFPEN_SHIFT) |
| 676 | #define ARM_TBFLAG_CONDEXEC_SHIFT 8 |
| 677 | #define ARM_TBFLAG_CONDEXEC_MASK (0xff << ARM_TBFLAG_CONDEXEC_SHIFT) |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 678 | #define ARM_TBFLAG_BSWAP_CODE_SHIFT 16 |
| 679 | #define ARM_TBFLAG_BSWAP_CODE_MASK (1 << ARM_TBFLAG_BSWAP_CODE_SHIFT) |
| 680 | /* Bits 31..17 are currently unused. */ |
Peter Maydell | a170576 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 681 | |
| 682 | /* some convenience accessor macros */ |
| 683 | #define ARM_TBFLAG_THUMB(F) \ |
| 684 | (((F) & ARM_TBFLAG_THUMB_MASK) >> ARM_TBFLAG_THUMB_SHIFT) |
| 685 | #define ARM_TBFLAG_VECLEN(F) \ |
| 686 | (((F) & ARM_TBFLAG_VECLEN_MASK) >> ARM_TBFLAG_VECLEN_SHIFT) |
| 687 | #define ARM_TBFLAG_VECSTRIDE(F) \ |
| 688 | (((F) & ARM_TBFLAG_VECSTRIDE_MASK) >> ARM_TBFLAG_VECSTRIDE_SHIFT) |
| 689 | #define ARM_TBFLAG_PRIV(F) \ |
| 690 | (((F) & ARM_TBFLAG_PRIV_MASK) >> ARM_TBFLAG_PRIV_SHIFT) |
| 691 | #define ARM_TBFLAG_VFPEN(F) \ |
| 692 | (((F) & ARM_TBFLAG_VFPEN_MASK) >> ARM_TBFLAG_VFPEN_SHIFT) |
| 693 | #define ARM_TBFLAG_CONDEXEC(F) \ |
| 694 | (((F) & ARM_TBFLAG_CONDEXEC_MASK) >> ARM_TBFLAG_CONDEXEC_SHIFT) |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 695 | #define ARM_TBFLAG_BSWAP_CODE(F) \ |
| 696 | (((F) & ARM_TBFLAG_BSWAP_CODE_MASK) >> ARM_TBFLAG_BSWAP_CODE_SHIFT) |
Peter Maydell | a170576 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 697 | |
Andreas Färber | 0ecb72a | 2012-03-14 01:38:21 +0100 | [diff] [blame] | 698 | static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, |
aliguori | 6b91754 | 2008-11-18 19:46:41 +0000 | [diff] [blame] | 699 | target_ulong *cs_base, int *flags) |
| 700 | { |
Peter Maydell | 05ed9a9 | 2011-01-14 20:39:19 +0100 | [diff] [blame] | 701 | int privmode; |
aliguori | 6b91754 | 2008-11-18 19:46:41 +0000 | [diff] [blame] | 702 | *pc = env->regs[15]; |
| 703 | *cs_base = 0; |
Peter Maydell | a170576 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 704 | *flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT) |
| 705 | | (env->vfp.vec_len << ARM_TBFLAG_VECLEN_SHIFT) |
| 706 | | (env->vfp.vec_stride << ARM_TBFLAG_VECSTRIDE_SHIFT) |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 707 | | (env->condexec_bits << ARM_TBFLAG_CONDEXEC_SHIFT) |
| 708 | | (env->bswap_code << ARM_TBFLAG_BSWAP_CODE_SHIFT); |
Peter Maydell | 05ed9a9 | 2011-01-14 20:39:19 +0100 | [diff] [blame] | 709 | if (arm_feature(env, ARM_FEATURE_M)) { |
| 710 | privmode = !((env->v7m.exception == 0) && (env->v7m.control & 1)); |
| 711 | } else { |
| 712 | privmode = (env->uncached_cpsr & CPSR_M) != ARM_CPU_MODE_USR; |
| 713 | } |
| 714 | if (privmode) { |
Peter Maydell | a170576 | 2011-01-14 20:39:18 +0100 | [diff] [blame] | 715 | *flags |= ARM_TBFLAG_PRIV_MASK; |
| 716 | } |
| 717 | if (env->vfp.xregs[ARM_VFP_FPEXC] & (1 << 30)) { |
| 718 | *flags |= ARM_TBFLAG_VFPEN_MASK; |
| 719 | } |
aliguori | 6b91754 | 2008-11-18 19:46:41 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Andreas Färber | 3993c6b | 2012-05-03 06:43:49 +0200 | [diff] [blame] | 722 | static inline bool cpu_has_work(CPUState *cpu) |
Blue Swirl | f081c76 | 2011-05-21 07:10:23 +0000 | [diff] [blame] | 723 | { |
Andreas Färber | 259186a | 2013-01-17 18:51:17 +0100 | [diff] [blame] | 724 | return cpu->interrupt_request & |
Blue Swirl | f081c76 | 2011-05-21 07:10:23 +0000 | [diff] [blame] | 725 | (CPU_INTERRUPT_FIQ | CPU_INTERRUPT_HARD | CPU_INTERRUPT_EXITTB); |
| 726 | } |
| 727 | |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 728 | #include "exec/exec-all.h" |
Blue Swirl | f081c76 | 2011-05-21 07:10:23 +0000 | [diff] [blame] | 729 | |
Andreas Färber | 0ecb72a | 2012-03-14 01:38:21 +0100 | [diff] [blame] | 730 | static inline void cpu_pc_from_tb(CPUARMState *env, TranslationBlock *tb) |
Blue Swirl | f081c76 | 2011-05-21 07:10:23 +0000 | [diff] [blame] | 731 | { |
| 732 | env->regs[15] = tb->pc; |
| 733 | } |
| 734 | |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 735 | /* Load an instruction and return it in the standard little-endian order */ |
Blue Swirl | d31dd73 | 2012-09-04 20:25:59 +0000 | [diff] [blame] | 736 | static inline uint32_t arm_ldl_code(CPUARMState *env, uint32_t addr, |
| 737 | bool do_swap) |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 738 | { |
Blue Swirl | d31dd73 | 2012-09-04 20:25:59 +0000 | [diff] [blame] | 739 | uint32_t insn = cpu_ldl_code(env, addr); |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 740 | if (do_swap) { |
| 741 | return bswap32(insn); |
| 742 | } |
| 743 | return insn; |
| 744 | } |
| 745 | |
| 746 | /* Ditto, for a halfword (Thumb) instruction */ |
Blue Swirl | d31dd73 | 2012-09-04 20:25:59 +0000 | [diff] [blame] | 747 | static inline uint16_t arm_lduw_code(CPUARMState *env, uint32_t addr, |
| 748 | bool do_swap) |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 749 | { |
Blue Swirl | d31dd73 | 2012-09-04 20:25:59 +0000 | [diff] [blame] | 750 | uint16_t insn = cpu_lduw_code(env, addr); |
Paul Brook | d8fd295 | 2012-03-30 18:02:50 +0100 | [diff] [blame] | 751 | if (do_swap) { |
| 752 | return bswap16(insn); |
| 753 | } |
| 754 | return insn; |
| 755 | } |
| 756 | |
bellard | 2c0262a | 2003-09-30 20:34:21 +0000 | [diff] [blame] | 757 | #endif |