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