root / target-arm / cpu.h @ 50d3eeae
History | View | Annotate | Download (6.8 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 | b7bcbe95 | bellard | /* We currently assume float and double are IEEE single and double
|
42 | b7bcbe95 | bellard | precision respectively.
|
43 | b7bcbe95 | bellard | Doing runtime conversions is tricky because VFP registers may contain
|
44 | b7bcbe95 | bellard | integer values (eg. as the result of a FTOSI instruction).
|
45 | 8e96005d | bellard | s<2n> maps to the least significant half of d<n>
|
46 | 8e96005d | bellard | s<2n+1> maps to the most significant half of d<n>
|
47 | 8e96005d | bellard | */
|
48 | b7bcbe95 | bellard | |
49 | 2c0262af | bellard | typedef struct CPUARMState { |
50 | b5ff1b31 | bellard | /* Regs for current mode. */
|
51 | 2c0262af | bellard | uint32_t regs[16];
|
52 | b5ff1b31 | bellard | /* Frequently accessed CPSR bits are stored separately for efficiently.
|
53 | d37aca66 | pbrook | This contains all the other bits. Use cpsr_{read,write} to access
|
54 | b5ff1b31 | bellard | the whole CPSR. */
|
55 | b5ff1b31 | bellard | uint32_t uncached_cpsr; |
56 | b5ff1b31 | bellard | uint32_t spsr; |
57 | b5ff1b31 | bellard | |
58 | b5ff1b31 | bellard | /* Banked registers. */
|
59 | b5ff1b31 | bellard | uint32_t banked_spsr[6];
|
60 | b5ff1b31 | bellard | uint32_t banked_r13[6];
|
61 | b5ff1b31 | bellard | uint32_t banked_r14[6];
|
62 | b5ff1b31 | bellard | |
63 | b5ff1b31 | bellard | /* These hold r8-r12. */
|
64 | b5ff1b31 | bellard | uint32_t usr_regs[5];
|
65 | b5ff1b31 | bellard | uint32_t fiq_regs[5];
|
66 | 2c0262af | bellard | |
67 | 2c0262af | bellard | /* cpsr flag cache for faster execution */
|
68 | 2c0262af | bellard | uint32_t CF; /* 0 or 1 */
|
69 | 2c0262af | bellard | uint32_t VF; /* V is the bit 31. All other bits are undefined */
|
70 | 2c0262af | bellard | uint32_t NZF; /* N is bit 31. Z is computed from NZF */
|
71 | 99c475ab | bellard | uint32_t QF; /* 0 or 1 */
|
72 | 99c475ab | bellard | |
73 | 99c475ab | bellard | int thumb; /* 0 = arm mode, 1 = thumb mode */ |
74 | 2c0262af | bellard | |
75 | b5ff1b31 | bellard | /* System control coprocessor (cp15) */
|
76 | b5ff1b31 | bellard | struct {
|
77 | 40f137e1 | pbrook | uint32_t c0_cpuid; |
78 | b5ff1b31 | bellard | uint32_t c1_sys; /* System control register. */
|
79 | b5ff1b31 | bellard | uint32_t c1_coproc; /* Coprocessor access register. */
|
80 | b5ff1b31 | bellard | uint32_t c2; /* MMU translation table base. */
|
81 | b5ff1b31 | bellard | uint32_t c3; /* MMU domain access control register. */
|
82 | b5ff1b31 | bellard | uint32_t c5_insn; /* Fault status registers. */
|
83 | b5ff1b31 | bellard | uint32_t c5_data; |
84 | b5ff1b31 | bellard | uint32_t c6_insn; /* Fault address registers. */
|
85 | b5ff1b31 | bellard | uint32_t c6_data; |
86 | b5ff1b31 | bellard | uint32_t c9_insn; /* Cache lockdown registers. */
|
87 | b5ff1b31 | bellard | uint32_t c9_data; |
88 | b5ff1b31 | bellard | uint32_t c13_fcse; /* FCSE PID. */
|
89 | b5ff1b31 | bellard | uint32_t c13_context; /* Context ID. */
|
90 | b5ff1b31 | bellard | } cp15; |
91 | 40f137e1 | pbrook | |
92 | 40f137e1 | pbrook | /* Internal CPU feature flags. */
|
93 | 40f137e1 | pbrook | uint32_t features; |
94 | 40f137e1 | pbrook | |
95 | 2c0262af | bellard | /* exception/interrupt handling */
|
96 | 2c0262af | bellard | jmp_buf jmp_env; |
97 | 2c0262af | bellard | int exception_index;
|
98 | 2c0262af | bellard | int interrupt_request;
|
99 | 2c0262af | bellard | int user_mode_only;
|
100 | 9332f9da | bellard | int halted;
|
101 | 2c0262af | bellard | |
102 | b7bcbe95 | bellard | /* VFP coprocessor state. */
|
103 | b7bcbe95 | bellard | struct {
|
104 | 8e96005d | bellard | float64 regs[16];
|
105 | b7bcbe95 | bellard | |
106 | 40f137e1 | pbrook | uint32_t xregs[16];
|
107 | b7bcbe95 | bellard | /* We store these fpcsr fields separately for convenience. */
|
108 | b7bcbe95 | bellard | int vec_len;
|
109 | b7bcbe95 | bellard | int vec_stride;
|
110 | b7bcbe95 | bellard | |
111 | b7bcbe95 | bellard | /* Temporary variables if we don't have spare fp regs. */
|
112 | 53cd6637 | bellard | float32 tmp0s, tmp1s; |
113 | 53cd6637 | bellard | float64 tmp0d, tmp1d; |
114 | 53cd6637 | bellard | |
115 | 53cd6637 | bellard | float_status fp_status; |
116 | b7bcbe95 | bellard | } vfp; |
117 | b7bcbe95 | bellard | |
118 | ce4defa0 | pbrook | #if defined(CONFIG_USER_ONLY)
|
119 | ce4defa0 | pbrook | /* For usermode syscall translation. */
|
120 | ce4defa0 | pbrook | int eabi;
|
121 | ce4defa0 | pbrook | #endif
|
122 | ce4defa0 | pbrook | |
123 | a316d335 | bellard | CPU_COMMON |
124 | a316d335 | bellard | |
125 | f3d6b95e | pbrook | /* These fields after the common ones so thes are preserved on reset. */
|
126 | f3d6b95e | pbrook | int ram_size;
|
127 | f3d6b95e | pbrook | const char *kernel_filename; |
128 | f3d6b95e | pbrook | const char *kernel_cmdline; |
129 | f3d6b95e | pbrook | const char *initrd_filename; |
130 | f3d6b95e | pbrook | int board_id;
|
131 | 2c0262af | bellard | } CPUARMState; |
132 | 2c0262af | bellard | |
133 | 2c0262af | bellard | CPUARMState *cpu_arm_init(void);
|
134 | 2c0262af | bellard | int cpu_arm_exec(CPUARMState *s);
|
135 | 2c0262af | bellard | void cpu_arm_close(CPUARMState *s);
|
136 | b5ff1b31 | bellard | void do_interrupt(CPUARMState *);
|
137 | b5ff1b31 | bellard | void switch_mode(CPUARMState *, int); |
138 | b5ff1b31 | bellard | |
139 | 2c0262af | bellard | /* you can call this signal handler from your SIGBUS and SIGSEGV
|
140 | 2c0262af | bellard | signal handlers to inform the virtual CPU of exceptions. non zero
|
141 | 2c0262af | bellard | is returned if the signal was handled by the virtual CPU. */
|
142 | 5a7b542b | ths | int cpu_arm_signal_handler(int host_signum, void *pinfo, |
143 | 2c0262af | bellard | void *puc);
|
144 | 2c0262af | bellard | |
145 | b5ff1b31 | bellard | #define CPSR_M (0x1f) |
146 | b5ff1b31 | bellard | #define CPSR_T (1 << 5) |
147 | b5ff1b31 | bellard | #define CPSR_F (1 << 6) |
148 | b5ff1b31 | bellard | #define CPSR_I (1 << 7) |
149 | b5ff1b31 | bellard | #define CPSR_A (1 << 8) |
150 | b5ff1b31 | bellard | #define CPSR_E (1 << 9) |
151 | b5ff1b31 | bellard | #define CPSR_IT_2_7 (0xfc00) |
152 | b5ff1b31 | bellard | /* Bits 20-23 reserved. */
|
153 | b5ff1b31 | bellard | #define CPSR_J (1 << 24) |
154 | b5ff1b31 | bellard | #define CPSR_IT_0_1 (3 << 25) |
155 | b5ff1b31 | bellard | #define CPSR_Q (1 << 27) |
156 | b5ff1b31 | bellard | #define CPSR_NZCV (0xf << 28) |
157 | b5ff1b31 | bellard | |
158 | b5ff1b31 | bellard | #define CACHED_CPSR_BITS (CPSR_T | CPSR_Q | CPSR_NZCV)
|
159 | b5ff1b31 | bellard | /* Return the current CPSR value. */
|
160 | b5ff1b31 | bellard | static inline uint32_t cpsr_read(CPUARMState *env) |
161 | b5ff1b31 | bellard | { |
162 | b5ff1b31 | bellard | int ZF;
|
163 | b5ff1b31 | bellard | ZF = (env->NZF == 0);
|
164 | b5ff1b31 | bellard | return env->uncached_cpsr | (env->NZF & 0x80000000) | (ZF << 30) | |
165 | b5ff1b31 | bellard | (env->CF << 29) | ((env->VF & 0x80000000) >> 3) | (env->QF << 27) |
166 | b5ff1b31 | bellard | | (env->thumb << 5);
|
167 | b5ff1b31 | bellard | } |
168 | b5ff1b31 | bellard | |
169 | b5ff1b31 | bellard | /* Set the CPSR. Note that some bits of mask must be all-set or all-clear. */
|
170 | b5ff1b31 | bellard | static inline void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask) |
171 | b5ff1b31 | bellard | { |
172 | b5ff1b31 | bellard | /* NOTE: N = 1 and Z = 1 cannot be stored currently */
|
173 | b5ff1b31 | bellard | if (mask & CPSR_NZCV) {
|
174 | b5ff1b31 | bellard | env->NZF = (val & 0xc0000000) ^ 0x40000000; |
175 | b5ff1b31 | bellard | env->CF = (val >> 29) & 1; |
176 | b5ff1b31 | bellard | env->VF = (val << 3) & 0x80000000; |
177 | b5ff1b31 | bellard | } |
178 | b5ff1b31 | bellard | if (mask & CPSR_Q)
|
179 | b5ff1b31 | bellard | env->QF = ((val & CPSR_Q) != 0);
|
180 | b5ff1b31 | bellard | if (mask & CPSR_T)
|
181 | b5ff1b31 | bellard | env->thumb = ((val & CPSR_T) != 0);
|
182 | b5ff1b31 | bellard | |
183 | b5ff1b31 | bellard | if ((env->uncached_cpsr ^ val) & mask & CPSR_M) {
|
184 | b5ff1b31 | bellard | switch_mode(env, val & CPSR_M); |
185 | b5ff1b31 | bellard | } |
186 | b5ff1b31 | bellard | mask &= ~CACHED_CPSR_BITS; |
187 | b5ff1b31 | bellard | env->uncached_cpsr = (env->uncached_cpsr & ~mask) | (val & mask); |
188 | b5ff1b31 | bellard | } |
189 | b5ff1b31 | bellard | |
190 | b5ff1b31 | bellard | enum arm_cpu_mode {
|
191 | b5ff1b31 | bellard | ARM_CPU_MODE_USR = 0x10,
|
192 | b5ff1b31 | bellard | ARM_CPU_MODE_FIQ = 0x11,
|
193 | b5ff1b31 | bellard | ARM_CPU_MODE_IRQ = 0x12,
|
194 | b5ff1b31 | bellard | ARM_CPU_MODE_SVC = 0x13,
|
195 | b5ff1b31 | bellard | ARM_CPU_MODE_ABT = 0x17,
|
196 | b5ff1b31 | bellard | ARM_CPU_MODE_UND = 0x1b,
|
197 | b5ff1b31 | bellard | ARM_CPU_MODE_SYS = 0x1f
|
198 | b5ff1b31 | bellard | }; |
199 | b5ff1b31 | bellard | |
200 | 40f137e1 | pbrook | /* VFP system registers. */
|
201 | 40f137e1 | pbrook | #define ARM_VFP_FPSID 0 |
202 | 40f137e1 | pbrook | #define ARM_VFP_FPSCR 1 |
203 | 40f137e1 | pbrook | #define ARM_VFP_FPEXC 8 |
204 | 40f137e1 | pbrook | #define ARM_VFP_FPINST 9 |
205 | 40f137e1 | pbrook | #define ARM_VFP_FPINST2 10 |
206 | 40f137e1 | pbrook | |
207 | 40f137e1 | pbrook | |
208 | 40f137e1 | pbrook | enum arm_features {
|
209 | 40f137e1 | pbrook | ARM_FEATURE_VFP, |
210 | 40f137e1 | pbrook | ARM_FEATURE_AUXCR /* ARM1026 Auxiliary control register. */
|
211 | 40f137e1 | pbrook | }; |
212 | 40f137e1 | pbrook | |
213 | 40f137e1 | pbrook | static inline int arm_feature(CPUARMState *env, int feature) |
214 | 40f137e1 | pbrook | { |
215 | 40f137e1 | pbrook | return (env->features & (1u << feature)) != 0; |
216 | 40f137e1 | pbrook | } |
217 | 40f137e1 | pbrook | |
218 | 5adb4839 | pbrook | void arm_cpu_list(void); |
219 | 3371d272 | pbrook | void cpu_arm_set_model(CPUARMState *env, const char *name); |
220 | 40f137e1 | pbrook | |
221 | 40f137e1 | pbrook | #define ARM_CPUID_ARM1026 0x4106a262 |
222 | 40f137e1 | pbrook | #define ARM_CPUID_ARM926 0x41069265 |
223 | 40f137e1 | pbrook | |
224 | b5ff1b31 | bellard | #if defined(CONFIG_USER_ONLY)
|
225 | 2c0262af | bellard | #define TARGET_PAGE_BITS 12 |
226 | b5ff1b31 | bellard | #else
|
227 | b5ff1b31 | bellard | /* The ARM MMU allows 1k pages. */
|
228 | b5ff1b31 | bellard | /* ??? Linux doesn't actually use these, and they're deprecated in recent
|
229 | b5ff1b31 | bellard | architecture revisions. Maybe an a configure option to disable them. */
|
230 | b5ff1b31 | bellard | #define TARGET_PAGE_BITS 10 |
231 | b5ff1b31 | bellard | #endif
|
232 | 2c0262af | bellard | #include "cpu-all.h" |
233 | 2c0262af | bellard | |
234 | 2c0262af | bellard | #endif |