]>
Commit | Line | Data |
---|---|---|
2c0262af FB |
1 | /* |
2 | * ARM virtual CPU header | |
3 | * | |
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 | |
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 | |
19 | */ | |
20 | #ifndef CPU_ARM_H | |
21 | #define CPU_ARM_H | |
22 | ||
3cf1e035 FB |
23 | #define TARGET_LONG_BITS 32 |
24 | ||
9042c0e2 TS |
25 | #define ELF_MACHINE EM_ARM |
26 | ||
2c0262af FB |
27 | #include "cpu-defs.h" |
28 | ||
53cd6637 FB |
29 | #include "softfloat.h" |
30 | ||
1fddef4b FB |
31 | #define TARGET_HAS_ICE 1 |
32 | ||
b8a9e8f1 FB |
33 | #define EXCP_UDEF 1 /* undefined instruction */ |
34 | #define EXCP_SWI 2 /* software interrupt */ | |
35 | #define EXCP_PREFETCH_ABORT 3 | |
36 | #define EXCP_DATA_ABORT 4 | |
b5ff1b31 FB |
37 | #define EXCP_IRQ 5 |
38 | #define EXCP_FIQ 6 | |
06c949e6 | 39 | #define EXCP_BKPT 7 |
2c0262af | 40 | |
c1713132 AZ |
41 | typedef void ARMWriteCPFunc(void *opaque, int cp_info, |
42 | int srcreg, int operand, uint32_t value); | |
43 | typedef uint32_t ARMReadCPFunc(void *opaque, int cp_info, | |
44 | int dstreg, int operand); | |
45 | ||
b7bcbe95 FB |
46 | /* We currently assume float and double are IEEE single and double |
47 | precision respectively. | |
48 | Doing runtime conversions is tricky because VFP registers may contain | |
49 | integer values (eg. as the result of a FTOSI instruction). | |
8e96005d FB |
50 | s<2n> maps to the least significant half of d<n> |
51 | s<2n+1> maps to the most significant half of d<n> | |
52 | */ | |
b7bcbe95 | 53 | |
2c0262af | 54 | typedef struct CPUARMState { |
b5ff1b31 | 55 | /* Regs for current mode. */ |
2c0262af | 56 | uint32_t regs[16]; |
b5ff1b31 | 57 | /* Frequently accessed CPSR bits are stored separately for efficiently. |
d37aca66 | 58 | This contains all the other bits. Use cpsr_{read,write} to access |
b5ff1b31 FB |
59 | the whole CPSR. */ |
60 | uint32_t uncached_cpsr; | |
61 | uint32_t spsr; | |
62 | ||
63 | /* Banked registers. */ | |
64 | uint32_t banked_spsr[6]; | |
65 | uint32_t banked_r13[6]; | |
66 | uint32_t banked_r14[6]; | |
67 | ||
68 | /* These hold r8-r12. */ | |
69 | uint32_t usr_regs[5]; | |
70 | uint32_t fiq_regs[5]; | |
2c0262af FB |
71 | |
72 | /* cpsr flag cache for faster execution */ | |
73 | uint32_t CF; /* 0 or 1 */ | |
74 | uint32_t VF; /* V is the bit 31. All other bits are undefined */ | |
75 | uint32_t NZF; /* N is bit 31. Z is computed from NZF */ | |
99c475ab FB |
76 | uint32_t QF; /* 0 or 1 */ |
77 | ||
78 | int thumb; /* 0 = arm mode, 1 = thumb mode */ | |
2c0262af | 79 | |
b5ff1b31 FB |
80 | /* System control coprocessor (cp15) */ |
81 | struct { | |
40f137e1 | 82 | uint32_t c0_cpuid; |
c1713132 | 83 | uint32_t c0_cachetype; |
b5ff1b31 FB |
84 | uint32_t c1_sys; /* System control register. */ |
85 | uint32_t c1_coproc; /* Coprocessor access register. */ | |
ce819861 PB |
86 | uint32_t c2_base; /* MMU translation table base. */ |
87 | uint32_t c2_data; /* MPU data cachable bits. */ | |
88 | uint32_t c2_insn; /* MPU instruction cachable bits. */ | |
89 | uint32_t c3; /* MMU domain access control register | |
90 | MPU write buffer control. */ | |
b5ff1b31 FB |
91 | uint32_t c5_insn; /* Fault status registers. */ |
92 | uint32_t c5_data; | |
ce819861 | 93 | uint32_t c6_region[8]; /* MPU base/size registers. */ |
b5ff1b31 FB |
94 | uint32_t c6_insn; /* Fault address registers. */ |
95 | uint32_t c6_data; | |
96 | uint32_t c9_insn; /* Cache lockdown registers. */ | |
97 | uint32_t c9_data; | |
98 | uint32_t c13_fcse; /* FCSE PID. */ | |
99 | uint32_t c13_context; /* Context ID. */ | |
c1713132 | 100 | uint32_t c15_cpar; /* XScale Coprocessor Access Register */ |
b5ff1b31 | 101 | } cp15; |
40f137e1 | 102 | |
c1713132 AZ |
103 | /* Coprocessor IO used by peripherals */ |
104 | struct { | |
105 | ARMReadCPFunc *cp_read; | |
106 | ARMWriteCPFunc *cp_write; | |
107 | void *opaque; | |
108 | } cp[15]; | |
109 | ||
40f137e1 PB |
110 | /* Internal CPU feature flags. */ |
111 | uint32_t features; | |
112 | ||
2c0262af FB |
113 | /* exception/interrupt handling */ |
114 | jmp_buf jmp_env; | |
115 | int exception_index; | |
116 | int interrupt_request; | |
2c0262af | 117 | int user_mode_only; |
9332f9da | 118 | int halted; |
2c0262af | 119 | |
b7bcbe95 FB |
120 | /* VFP coprocessor state. */ |
121 | struct { | |
8e96005d | 122 | float64 regs[16]; |
b7bcbe95 | 123 | |
40f137e1 | 124 | uint32_t xregs[16]; |
b7bcbe95 FB |
125 | /* We store these fpcsr fields separately for convenience. */ |
126 | int vec_len; | |
127 | int vec_stride; | |
128 | ||
b7bcbe95 | 129 | /* Temporary variables if we don't have spare fp regs. */ |
53cd6637 FB |
130 | float32 tmp0s, tmp1s; |
131 | float64 tmp0d, tmp1d; | |
132 | ||
133 | float_status fp_status; | |
b7bcbe95 FB |
134 | } vfp; |
135 | ||
18c9b560 AZ |
136 | /* iwMMXt coprocessor state. */ |
137 | struct { | |
138 | uint64_t regs[16]; | |
139 | uint64_t val; | |
140 | ||
141 | uint32_t cregs[16]; | |
142 | } iwmmxt; | |
143 | ||
ce4defa0 PB |
144 | #if defined(CONFIG_USER_ONLY) |
145 | /* For usermode syscall translation. */ | |
146 | int eabi; | |
147 | #endif | |
148 | ||
a316d335 FB |
149 | CPU_COMMON |
150 | ||
9d551997 | 151 | /* These fields after the common ones so they are preserved on reset. */ |
f3d6b95e PB |
152 | int ram_size; |
153 | const char *kernel_filename; | |
154 | const char *kernel_cmdline; | |
155 | const char *initrd_filename; | |
156 | int board_id; | |
9d551997 | 157 | target_phys_addr_t loader_start; |
2c0262af FB |
158 | } CPUARMState; |
159 | ||
160 | CPUARMState *cpu_arm_init(void); | |
161 | int cpu_arm_exec(CPUARMState *s); | |
162 | void cpu_arm_close(CPUARMState *s); | |
b5ff1b31 FB |
163 | void do_interrupt(CPUARMState *); |
164 | void switch_mode(CPUARMState *, int); | |
165 | ||
2c0262af FB |
166 | /* you can call this signal handler from your SIGBUS and SIGSEGV |
167 | signal handlers to inform the virtual CPU of exceptions. non zero | |
168 | is returned if the signal was handled by the virtual CPU. */ | |
5a7b542b | 169 | int cpu_arm_signal_handler(int host_signum, void *pinfo, |
2c0262af FB |
170 | void *puc); |
171 | ||
b5ff1b31 FB |
172 | #define CPSR_M (0x1f) |
173 | #define CPSR_T (1 << 5) | |
174 | #define CPSR_F (1 << 6) | |
175 | #define CPSR_I (1 << 7) | |
176 | #define CPSR_A (1 << 8) | |
177 | #define CPSR_E (1 << 9) | |
178 | #define CPSR_IT_2_7 (0xfc00) | |
179 | /* Bits 20-23 reserved. */ | |
180 | #define CPSR_J (1 << 24) | |
181 | #define CPSR_IT_0_1 (3 << 25) | |
182 | #define CPSR_Q (1 << 27) | |
183 | #define CPSR_NZCV (0xf << 28) | |
184 | ||
185 | #define CACHED_CPSR_BITS (CPSR_T | CPSR_Q | CPSR_NZCV) | |
186 | /* Return the current CPSR value. */ | |
187 | static inline uint32_t cpsr_read(CPUARMState *env) | |
188 | { | |
189 | int ZF; | |
190 | ZF = (env->NZF == 0); | |
191 | return env->uncached_cpsr | (env->NZF & 0x80000000) | (ZF << 30) | | |
192 | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27) | |
193 | | (env->thumb << 5); | |
194 | } | |
195 | ||
196 | /* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */ | |
197 | static inline void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) | |
198 | { | |
199 | /* NOTE: N = 1 and Z = 1 cannot be stored currently */ | |
200 | if (mask & CPSR_NZCV) { | |
201 | env->NZF = (val & 0xc0000000) ^ 0x40000000; | |
202 | env->CF = (val >> 29) & 1; | |
203 | env->VF = (val << 3) & 0x80000000; | |
204 | } | |
205 | if (mask & CPSR_Q) | |
206 | env->QF = ((val & CPSR_Q) != 0); | |
207 | if (mask & CPSR_T) | |
208 | env->thumb = ((val & CPSR_T) != 0); | |
209 | ||
210 | if ((env->uncached_cpsr ^ val) & mask & CPSR_M) { | |
211 | switch_mode(env, val & CPSR_M); | |
212 | } | |
213 | mask &= ~CACHED_CPSR_BITS; | |
214 | env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask); | |
215 | } | |
216 | ||
217 | enum arm_cpu_mode { | |
218 | ARM_CPU_MODE_USR = 0x10, | |
219 | ARM_CPU_MODE_FIQ = 0x11, | |
220 | ARM_CPU_MODE_IRQ = 0x12, | |
221 | ARM_CPU_MODE_SVC = 0x13, | |
222 | ARM_CPU_MODE_ABT = 0x17, | |
223 | ARM_CPU_MODE_UND = 0x1b, | |
224 | ARM_CPU_MODE_SYS = 0x1f | |
225 | }; | |
226 | ||
40f137e1 PB |
227 | /* VFP system registers. */ |
228 | #define ARM_VFP_FPSID 0 | |
229 | #define ARM_VFP_FPSCR 1 | |
230 | #define ARM_VFP_FPEXC 8 | |
231 | #define ARM_VFP_FPINST 9 | |
232 | #define ARM_VFP_FPINST2 10 | |
233 | ||
18c9b560 AZ |
234 | /* iwMMXt coprocessor control registers. */ |
235 | #define ARM_IWMMXT_wCID 0 | |
236 | #define ARM_IWMMXT_wCon 1 | |
237 | #define ARM_IWMMXT_wCSSF 2 | |
238 | #define ARM_IWMMXT_wCASF 3 | |
239 | #define ARM_IWMMXT_wCGR0 8 | |
240 | #define ARM_IWMMXT_wCGR1 9 | |
241 | #define ARM_IWMMXT_wCGR2 10 | |
242 | #define ARM_IWMMXT_wCGR3 11 | |
243 | ||
40f137e1 PB |
244 | enum arm_features { |
245 | ARM_FEATURE_VFP, | |
c1713132 AZ |
246 | ARM_FEATURE_AUXCR, /* ARM1026 Auxiliary control register. */ |
247 | ARM_FEATURE_XSCALE, /* Intel XScale extensions. */ | |
ce819861 PB |
248 | ARM_FEATURE_IWMMXT, /* Intel iwMMXt extension. */ |
249 | ARM_FEATURE_MPU /* Only has Memory Protection Unit, not full MMU. */ | |
40f137e1 PB |
250 | }; |
251 | ||
252 | static inline int arm_feature(CPUARMState *env, int feature) | |
253 | { | |
254 | return (env->features & (1u << feature)) != 0; | |
255 | } | |
256 | ||
5adb4839 | 257 | void arm_cpu_list(void); |
3371d272 | 258 | void cpu_arm_set_model(CPUARMState *env, const char *name); |
40f137e1 | 259 | |
c1713132 AZ |
260 | void cpu_arm_set_cp_io(CPUARMState *env, int cpnum, |
261 | ARMReadCPFunc *cp_read, ARMWriteCPFunc *cp_write, | |
262 | void *opaque); | |
263 | ||
264 | #define ARM_CPUID_ARM1026 0x4106a262 | |
265 | #define ARM_CPUID_ARM926 0x41069265 | |
ce819861 | 266 | #define ARM_CPUID_ARM946 0x41059461 |
c1713132 AZ |
267 | #define ARM_CPUID_PXA250 0x69052100 |
268 | #define ARM_CPUID_PXA255 0x69052d00 | |
269 | #define ARM_CPUID_PXA260 0x69052903 | |
270 | #define ARM_CPUID_PXA261 0x69052d05 | |
271 | #define ARM_CPUID_PXA262 0x69052d06 | |
272 | #define ARM_CPUID_PXA270 0x69054110 | |
273 | #define ARM_CPUID_PXA270_A0 0x69054110 | |
274 | #define ARM_CPUID_PXA270_A1 0x69054111 | |
275 | #define ARM_CPUID_PXA270_B0 0x69054112 | |
276 | #define ARM_CPUID_PXA270_B1 0x69054113 | |
277 | #define ARM_CPUID_PXA270_C0 0x69054114 | |
278 | #define ARM_CPUID_PXA270_C5 0x69054117 | |
40f137e1 | 279 | |
b5ff1b31 | 280 | #if defined(CONFIG_USER_ONLY) |
2c0262af | 281 | #define TARGET_PAGE_BITS 12 |
b5ff1b31 FB |
282 | #else |
283 | /* The ARM MMU allows 1k pages. */ | |
284 | /* ??? Linux doesn't actually use these, and they're deprecated in recent | |
285 | architecture revisions. Maybe an a configure option to disable them. */ | |
286 | #define TARGET_PAGE_BITS 10 | |
287 | #endif | |
9467d44c TS |
288 | |
289 | #define CPUState CPUARMState | |
290 | #define cpu_init cpu_arm_init | |
291 | #define cpu_exec cpu_arm_exec | |
292 | #define cpu_gen_code cpu_arm_gen_code | |
293 | #define cpu_signal_handler cpu_arm_signal_handler | |
294 | ||
2c0262af FB |
295 | #include "cpu-all.h" |
296 | ||
297 | #endif |