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