9 #include "qemu-common.h"
10 #include "host-utils.h"
11 #if !defined(CONFIG_USER_ONLY)
12 #include "hw/loader.h"
15 static uint32_t cortexa9_cp15_c0_c1
[8] =
16 { 0x1031, 0x11, 0x000, 0, 0x00100103, 0x20000000, 0x01230000, 0x00002111 };
18 static uint32_t cortexa9_cp15_c0_c2
[8] =
19 { 0x00101111, 0x13112111, 0x21232041, 0x11112131, 0x00111142, 0, 0, 0 };
21 static uint32_t cortexa8_cp15_c0_c1
[8] =
22 { 0x1031, 0x11, 0x400, 0, 0x31100003, 0x20000000, 0x01202000, 0x11 };
24 static uint32_t cortexa8_cp15_c0_c2
[8] =
25 { 0x00101111, 0x12112111, 0x21232031, 0x11112131, 0x00111142, 0, 0, 0 };
27 static uint32_t mpcore_cp15_c0_c1
[8] =
28 { 0x111, 0x1, 0, 0x2, 0x01100103, 0x10020302, 0x01222000, 0 };
30 static uint32_t mpcore_cp15_c0_c2
[8] =
31 { 0x00100011, 0x12002111, 0x11221011, 0x01102131, 0x141, 0, 0, 0 };
33 static uint32_t arm1136_cp15_c0_c1
[8] =
34 { 0x111, 0x1, 0x2, 0x3, 0x01130003, 0x10030302, 0x01222110, 0 };
36 static uint32_t arm1136_cp15_c0_c2
[8] =
37 { 0x00140011, 0x12002111, 0x11231111, 0x01102131, 0x141, 0, 0, 0 };
39 static uint32_t cpu_arm_find_by_name(const char *name
);
41 static inline void set_feature(CPUARMState
*env
, int feature
)
43 env
->features
|= 1u << feature
;
46 static void cpu_reset_model_id(CPUARMState
*env
, uint32_t id
)
48 env
->cp15
.c0_cpuid
= id
;
50 case ARM_CPUID_ARM926
:
51 set_feature(env
, ARM_FEATURE_VFP
);
52 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41011090;
53 env
->cp15
.c0_cachetype
= 0x1dd20d2;
54 env
->cp15
.c1_sys
= 0x00090078;
56 case ARM_CPUID_ARM946
:
57 set_feature(env
, ARM_FEATURE_MPU
);
58 env
->cp15
.c0_cachetype
= 0x0f004006;
59 env
->cp15
.c1_sys
= 0x00000078;
61 case ARM_CPUID_ARM1026
:
62 set_feature(env
, ARM_FEATURE_VFP
);
63 set_feature(env
, ARM_FEATURE_AUXCR
);
64 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410110a0;
65 env
->cp15
.c0_cachetype
= 0x1dd20d2;
66 env
->cp15
.c1_sys
= 0x00090078;
68 case ARM_CPUID_ARM1136_R2
:
69 case ARM_CPUID_ARM1136
:
70 set_feature(env
, ARM_FEATURE_V6
);
71 set_feature(env
, ARM_FEATURE_VFP
);
72 set_feature(env
, ARM_FEATURE_AUXCR
);
73 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
74 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
75 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
76 memcpy(env
->cp15
.c0_c1
, arm1136_cp15_c0_c1
, 8 * sizeof(uint32_t));
77 memcpy(env
->cp15
.c0_c2
, arm1136_cp15_c0_c2
, 8 * sizeof(uint32_t));
78 env
->cp15
.c0_cachetype
= 0x1dd20d2;
80 case ARM_CPUID_ARM11MPCORE
:
81 set_feature(env
, ARM_FEATURE_V6
);
82 set_feature(env
, ARM_FEATURE_V6K
);
83 set_feature(env
, ARM_FEATURE_VFP
);
84 set_feature(env
, ARM_FEATURE_AUXCR
);
85 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
86 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
87 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
88 memcpy(env
->cp15
.c0_c1
, mpcore_cp15_c0_c1
, 8 * sizeof(uint32_t));
89 memcpy(env
->cp15
.c0_c2
, mpcore_cp15_c0_c2
, 8 * sizeof(uint32_t));
90 env
->cp15
.c0_cachetype
= 0x1dd20d2;
92 case ARM_CPUID_CORTEXA8
:
93 set_feature(env
, ARM_FEATURE_V6
);
94 set_feature(env
, ARM_FEATURE_V6K
);
95 set_feature(env
, ARM_FEATURE_V7
);
96 set_feature(env
, ARM_FEATURE_AUXCR
);
97 set_feature(env
, ARM_FEATURE_THUMB2
);
98 set_feature(env
, ARM_FEATURE_VFP
);
99 set_feature(env
, ARM_FEATURE_VFP3
);
100 set_feature(env
, ARM_FEATURE_NEON
);
101 set_feature(env
, ARM_FEATURE_THUMB2EE
);
102 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410330c0;
103 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
104 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00011100;
105 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c1
, 8 * sizeof(uint32_t));
106 memcpy(env
->cp15
.c0_c2
, cortexa8_cp15_c0_c2
, 8 * sizeof(uint32_t));
107 env
->cp15
.c0_cachetype
= 0x82048004;
108 env
->cp15
.c0_clid
= (1 << 27) | (2 << 24) | 3;
109 env
->cp15
.c0_ccsid
[0] = 0xe007e01a; /* 16k L1 dcache. */
110 env
->cp15
.c0_ccsid
[1] = 0x2007e01a; /* 16k L1 icache. */
111 env
->cp15
.c0_ccsid
[2] = 0xf0000000; /* No L2 icache. */
113 case ARM_CPUID_CORTEXA9
:
114 set_feature(env
, ARM_FEATURE_V6
);
115 set_feature(env
, ARM_FEATURE_V6K
);
116 set_feature(env
, ARM_FEATURE_V7
);
117 set_feature(env
, ARM_FEATURE_AUXCR
);
118 set_feature(env
, ARM_FEATURE_THUMB2
);
119 set_feature(env
, ARM_FEATURE_VFP
);
120 set_feature(env
, ARM_FEATURE_VFP3
);
121 set_feature(env
, ARM_FEATURE_VFP_FP16
);
122 set_feature(env
, ARM_FEATURE_NEON
);
123 set_feature(env
, ARM_FEATURE_THUMB2EE
);
124 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41034000; /* Guess */
125 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
126 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x01111111;
127 memcpy(env
->cp15
.c0_c1
, cortexa9_cp15_c0_c1
, 8 * sizeof(uint32_t));
128 memcpy(env
->cp15
.c0_c2
, cortexa9_cp15_c0_c2
, 8 * sizeof(uint32_t));
129 env
->cp15
.c0_cachetype
= 0x80038003;
130 env
->cp15
.c0_clid
= (1 << 27) | (1 << 24) | 3;
131 env
->cp15
.c0_ccsid
[0] = 0xe00fe015; /* 16k L1 dcache. */
132 env
->cp15
.c0_ccsid
[1] = 0x200fe015; /* 16k L1 icache. */
134 case ARM_CPUID_CORTEXM3
:
135 set_feature(env
, ARM_FEATURE_V6
);
136 set_feature(env
, ARM_FEATURE_THUMB2
);
137 set_feature(env
, ARM_FEATURE_V7
);
138 set_feature(env
, ARM_FEATURE_M
);
139 set_feature(env
, ARM_FEATURE_DIV
);
141 case ARM_CPUID_ANY
: /* For userspace emulation. */
142 set_feature(env
, ARM_FEATURE_V6
);
143 set_feature(env
, ARM_FEATURE_V6K
);
144 set_feature(env
, ARM_FEATURE_V7
);
145 set_feature(env
, ARM_FEATURE_THUMB2
);
146 set_feature(env
, ARM_FEATURE_VFP
);
147 set_feature(env
, ARM_FEATURE_VFP3
);
148 set_feature(env
, ARM_FEATURE_VFP_FP16
);
149 set_feature(env
, ARM_FEATURE_NEON
);
150 set_feature(env
, ARM_FEATURE_THUMB2EE
);
151 set_feature(env
, ARM_FEATURE_DIV
);
153 case ARM_CPUID_TI915T
:
154 case ARM_CPUID_TI925T
:
155 set_feature(env
, ARM_FEATURE_OMAPCP
);
156 env
->cp15
.c0_cpuid
= ARM_CPUID_TI925T
; /* Depends on wiring. */
157 env
->cp15
.c0_cachetype
= 0x5109149;
158 env
->cp15
.c1_sys
= 0x00000070;
159 env
->cp15
.c15_i_max
= 0x000;
160 env
->cp15
.c15_i_min
= 0xff0;
162 case ARM_CPUID_PXA250
:
163 case ARM_CPUID_PXA255
:
164 case ARM_CPUID_PXA260
:
165 case ARM_CPUID_PXA261
:
166 case ARM_CPUID_PXA262
:
167 set_feature(env
, ARM_FEATURE_XSCALE
);
168 /* JTAG_ID is ((id << 28) | 0x09265013) */
169 env
->cp15
.c0_cachetype
= 0xd172172;
170 env
->cp15
.c1_sys
= 0x00000078;
172 case ARM_CPUID_PXA270_A0
:
173 case ARM_CPUID_PXA270_A1
:
174 case ARM_CPUID_PXA270_B0
:
175 case ARM_CPUID_PXA270_B1
:
176 case ARM_CPUID_PXA270_C0
:
177 case ARM_CPUID_PXA270_C5
:
178 set_feature(env
, ARM_FEATURE_XSCALE
);
179 /* JTAG_ID is ((id << 28) | 0x09265013) */
180 set_feature(env
, ARM_FEATURE_IWMMXT
);
181 env
->iwmmxt
.cregs
[ARM_IWMMXT_wCID
] = 0x69051000 | 'Q';
182 env
->cp15
.c0_cachetype
= 0xd172172;
183 env
->cp15
.c1_sys
= 0x00000078;
186 cpu_abort(env
, "Bad CPU ID: %x\n", id
);
191 void cpu_reset(CPUARMState
*env
)
195 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
196 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
197 log_cpu_state(env
, 0);
200 id
= env
->cp15
.c0_cpuid
;
201 memset(env
, 0, offsetof(CPUARMState
, breakpoints
));
203 cpu_reset_model_id(env
, id
);
204 #if defined (CONFIG_USER_ONLY)
205 env
->uncached_cpsr
= ARM_CPU_MODE_USR
;
206 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 1 << 30;
208 /* SVC mode with interrupts disabled. */
209 env
->uncached_cpsr
= ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
210 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
211 clear at reset. Initial SP and PC are loaded from ROM. */
215 env
->uncached_cpsr
&= ~CPSR_I
;
218 /* We should really use ldl_phys here, in case the guest
219 modified flash and reset itself. However images
220 loaded via -kenrel have not been copied yet, so load the
221 values directly from there. */
222 env
->regs
[13] = ldl_p(rom
);
225 env
->regs
[15] = pc
& ~1;
228 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 0;
229 env
->cp15
.c2_base_mask
= 0xffffc000u
;
234 static int vfp_gdb_get_reg(CPUState
*env
, uint8_t *buf
, int reg
)
238 /* VFP data registers are always little-endian. */
239 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
241 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
244 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
245 /* Aliases for Q regs. */
248 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
249 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
253 switch (reg
- nregs
) {
254 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
255 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
256 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
261 static int vfp_gdb_set_reg(CPUState
*env
, uint8_t *buf
, int reg
)
265 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
267 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
270 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
273 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
274 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
278 switch (reg
- nregs
) {
279 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
280 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
281 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
) & (1 << 30); return 4;
286 CPUARMState
*cpu_arm_init(const char *cpu_model
)
290 static int inited
= 0;
292 id
= cpu_arm_find_by_name(cpu_model
);
295 env
= qemu_mallocz(sizeof(CPUARMState
));
299 arm_translate_init();
302 env
->cpu_model_str
= cpu_model
;
303 env
->cp15
.c0_cpuid
= id
;
305 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
306 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
307 51, "arm-neon.xml", 0);
308 } else if (arm_feature(env
, ARM_FEATURE_VFP3
)) {
309 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
310 35, "arm-vfp3.xml", 0);
311 } else if (arm_feature(env
, ARM_FEATURE_VFP
)) {
312 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
313 19, "arm-vfp.xml", 0);
324 static const struct arm_cpu_t arm_cpu_names
[] = {
325 { ARM_CPUID_ARM926
, "arm926"},
326 { ARM_CPUID_ARM946
, "arm946"},
327 { ARM_CPUID_ARM1026
, "arm1026"},
328 { ARM_CPUID_ARM1136
, "arm1136"},
329 { ARM_CPUID_ARM1136_R2
, "arm1136-r2"},
330 { ARM_CPUID_ARM11MPCORE
, "arm11mpcore"},
331 { ARM_CPUID_CORTEXM3
, "cortex-m3"},
332 { ARM_CPUID_CORTEXA8
, "cortex-a8"},
333 { ARM_CPUID_CORTEXA9
, "cortex-a9"},
334 { ARM_CPUID_TI925T
, "ti925t" },
335 { ARM_CPUID_PXA250
, "pxa250" },
336 { ARM_CPUID_PXA255
, "pxa255" },
337 { ARM_CPUID_PXA260
, "pxa260" },
338 { ARM_CPUID_PXA261
, "pxa261" },
339 { ARM_CPUID_PXA262
, "pxa262" },
340 { ARM_CPUID_PXA270
, "pxa270" },
341 { ARM_CPUID_PXA270_A0
, "pxa270-a0" },
342 { ARM_CPUID_PXA270_A1
, "pxa270-a1" },
343 { ARM_CPUID_PXA270_B0
, "pxa270-b0" },
344 { ARM_CPUID_PXA270_B1
, "pxa270-b1" },
345 { ARM_CPUID_PXA270_C0
, "pxa270-c0" },
346 { ARM_CPUID_PXA270_C5
, "pxa270-c5" },
347 { ARM_CPUID_ANY
, "any"},
351 void arm_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
355 (*cpu_fprintf
)(f
, "Available CPUs:\n");
356 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
357 (*cpu_fprintf
)(f
, " %s\n", arm_cpu_names
[i
].name
);
361 /* return 0 if not found */
362 static uint32_t cpu_arm_find_by_name(const char *name
)
368 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
369 if (strcmp(name
, arm_cpu_names
[i
].name
) == 0) {
370 id
= arm_cpu_names
[i
].id
;
377 void cpu_arm_close(CPUARMState
*env
)
382 uint32_t cpsr_read(CPUARMState
*env
)
386 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
387 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
388 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
389 | ((env
->condexec_bits
& 0xfc) << 8)
393 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
)
395 if (mask
& CPSR_NZCV
) {
396 env
->ZF
= (~val
) & CPSR_Z
;
398 env
->CF
= (val
>> 29) & 1;
399 env
->VF
= (val
<< 3) & 0x80000000;
402 env
->QF
= ((val
& CPSR_Q
) != 0);
404 env
->thumb
= ((val
& CPSR_T
) != 0);
405 if (mask
& CPSR_IT_0_1
) {
406 env
->condexec_bits
&= ~3;
407 env
->condexec_bits
|= (val
>> 25) & 3;
409 if (mask
& CPSR_IT_2_7
) {
410 env
->condexec_bits
&= 3;
411 env
->condexec_bits
|= (val
>> 8) & 0xfc;
413 if (mask
& CPSR_GE
) {
414 env
->GE
= (val
>> 16) & 0xf;
417 if ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
) {
418 switch_mode(env
, val
& CPSR_M
);
420 mask
&= ~CACHED_CPSR_BITS
;
421 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
424 /* Sign/zero extend */
425 uint32_t HELPER(sxtb16
)(uint32_t x
)
428 res
= (uint16_t)(int8_t)x
;
429 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
433 uint32_t HELPER(uxtb16
)(uint32_t x
)
436 res
= (uint16_t)(uint8_t)x
;
437 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
441 uint32_t HELPER(clz
)(uint32_t x
)
446 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
450 if (num
== INT_MIN
&& den
== -1)
455 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
462 uint32_t HELPER(rbit
)(uint32_t x
)
464 x
= ((x
& 0xff000000) >> 24)
465 | ((x
& 0x00ff0000) >> 8)
466 | ((x
& 0x0000ff00) << 8)
467 | ((x
& 0x000000ff) << 24);
468 x
= ((x
& 0xf0f0f0f0) >> 4)
469 | ((x
& 0x0f0f0f0f) << 4);
470 x
= ((x
& 0x88888888) >> 3)
471 | ((x
& 0x44444444) >> 1)
472 | ((x
& 0x22222222) << 1)
473 | ((x
& 0x11111111) << 3);
477 uint32_t HELPER(abs
)(uint32_t x
)
479 return ((int32_t)x
< 0) ? -x
: x
;
482 #if defined(CONFIG_USER_ONLY)
484 void do_interrupt (CPUState
*env
)
486 env
->exception_index
= -1;
489 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
490 int mmu_idx
, int is_softmmu
)
493 env
->exception_index
= EXCP_PREFETCH_ABORT
;
494 env
->cp15
.c6_insn
= address
;
496 env
->exception_index
= EXCP_DATA_ABORT
;
497 env
->cp15
.c6_data
= address
;
502 /* These should probably raise undefined insn exceptions. */
503 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
505 int op1
= (insn
>> 8) & 0xf;
506 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
510 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
512 int op1
= (insn
>> 8) & 0xf;
513 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
517 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
519 cpu_abort(env
, "cp15 insn %08x\n", insn
);
522 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
524 cpu_abort(env
, "cp15 insn %08x\n", insn
);
527 /* These should probably raise undefined insn exceptions. */
528 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
530 cpu_abort(env
, "v7m_mrs %d\n", reg
);
533 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
535 cpu_abort(env
, "v7m_mrs %d\n", reg
);
539 void switch_mode(CPUState
*env
, int mode
)
541 if (mode
!= ARM_CPU_MODE_USR
)
542 cpu_abort(env
, "Tried to switch out of user mode\n");
545 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
547 cpu_abort(env
, "banked r13 write\n");
550 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
552 cpu_abort(env
, "banked r13 read\n");
558 extern int semihosting_enabled
;
560 /* Map CPU modes onto saved register banks. */
561 static inline int bank_number (int mode
)
564 case ARM_CPU_MODE_USR
:
565 case ARM_CPU_MODE_SYS
:
567 case ARM_CPU_MODE_SVC
:
569 case ARM_CPU_MODE_ABT
:
571 case ARM_CPU_MODE_UND
:
573 case ARM_CPU_MODE_IRQ
:
575 case ARM_CPU_MODE_FIQ
:
578 cpu_abort(cpu_single_env
, "Bad mode %x\n", mode
);
582 void switch_mode(CPUState
*env
, int mode
)
587 old_mode
= env
->uncached_cpsr
& CPSR_M
;
588 if (mode
== old_mode
)
591 if (old_mode
== ARM_CPU_MODE_FIQ
) {
592 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
593 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
594 } else if (mode
== ARM_CPU_MODE_FIQ
) {
595 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
596 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
599 i
= bank_number(old_mode
);
600 env
->banked_r13
[i
] = env
->regs
[13];
601 env
->banked_r14
[i
] = env
->regs
[14];
602 env
->banked_spsr
[i
] = env
->spsr
;
604 i
= bank_number(mode
);
605 env
->regs
[13] = env
->banked_r13
[i
];
606 env
->regs
[14] = env
->banked_r14
[i
];
607 env
->spsr
= env
->banked_spsr
[i
];
610 static void v7m_push(CPUARMState
*env
, uint32_t val
)
613 stl_phys(env
->regs
[13], val
);
616 static uint32_t v7m_pop(CPUARMState
*env
)
619 val
= ldl_phys(env
->regs
[13]);
624 /* Switch to V7M main or process stack pointer. */
625 static void switch_v7m_sp(CPUARMState
*env
, int process
)
628 if (env
->v7m
.current_sp
!= process
) {
629 tmp
= env
->v7m
.other_sp
;
630 env
->v7m
.other_sp
= env
->regs
[13];
632 env
->v7m
.current_sp
= process
;
636 static void do_v7m_exception_exit(CPUARMState
*env
)
641 type
= env
->regs
[15];
642 if (env
->v7m
.exception
!= 0)
643 armv7m_nvic_complete_irq(env
->nvic
, env
->v7m
.exception
);
645 /* Switch to the target stack. */
646 switch_v7m_sp(env
, (type
& 4) != 0);
648 env
->regs
[0] = v7m_pop(env
);
649 env
->regs
[1] = v7m_pop(env
);
650 env
->regs
[2] = v7m_pop(env
);
651 env
->regs
[3] = v7m_pop(env
);
652 env
->regs
[12] = v7m_pop(env
);
653 env
->regs
[14] = v7m_pop(env
);
654 env
->regs
[15] = v7m_pop(env
);
656 xpsr_write(env
, xpsr
, 0xfffffdff);
657 /* Undo stack alignment. */
660 /* ??? The exception return type specifies Thread/Handler mode. However
661 this is also implied by the xPSR value. Not sure what to do
662 if there is a mismatch. */
663 /* ??? Likewise for mismatches between the CONTROL register and the stack
667 static void do_interrupt_v7m(CPUARMState
*env
)
669 uint32_t xpsr
= xpsr_read(env
);
674 if (env
->v7m
.current_sp
)
676 if (env
->v7m
.exception
== 0)
679 /* For exceptions we just mark as pending on the NVIC, and let that
681 /* TODO: Need to escalate if the current priority is higher than the
682 one we're raising. */
683 switch (env
->exception_index
) {
685 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_USAGE
);
689 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_SVC
);
691 case EXCP_PREFETCH_ABORT
:
692 case EXCP_DATA_ABORT
:
693 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_MEM
);
696 if (semihosting_enabled
) {
698 nr
= lduw_code(env
->regs
[15]) & 0xff;
701 env
->regs
[0] = do_arm_semihosting(env
);
705 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_DEBUG
);
708 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->nvic
);
710 case EXCP_EXCEPTION_EXIT
:
711 do_v7m_exception_exit(env
);
714 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
715 return; /* Never happens. Keep compiler happy. */
718 /* Align stack pointer. */
719 /* ??? Should only do this if Configuration Control Register
720 STACKALIGN bit is set. */
721 if (env
->regs
[13] & 4) {
725 /* Switch to the handler mode. */
727 v7m_push(env
, env
->regs
[15]);
728 v7m_push(env
, env
->regs
[14]);
729 v7m_push(env
, env
->regs
[12]);
730 v7m_push(env
, env
->regs
[3]);
731 v7m_push(env
, env
->regs
[2]);
732 v7m_push(env
, env
->regs
[1]);
733 v7m_push(env
, env
->regs
[0]);
734 switch_v7m_sp(env
, 0);
735 env
->uncached_cpsr
&= ~CPSR_IT
;
737 addr
= ldl_phys(env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
738 env
->regs
[15] = addr
& 0xfffffffe;
739 env
->thumb
= addr
& 1;
742 /* Handle a CPU exception. */
743 void do_interrupt(CPUARMState
*env
)
751 do_interrupt_v7m(env
);
754 /* TODO: Vectored interrupt controller. */
755 switch (env
->exception_index
) {
757 new_mode
= ARM_CPU_MODE_UND
;
766 if (semihosting_enabled
) {
767 /* Check for semihosting interrupt. */
769 mask
= lduw_code(env
->regs
[15] - 2) & 0xff;
771 mask
= ldl_code(env
->regs
[15] - 4) & 0xffffff;
773 /* Only intercept calls from privileged modes, to provide some
774 semblance of security. */
775 if (((mask
== 0x123456 && !env
->thumb
)
776 || (mask
== 0xab && env
->thumb
))
777 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
778 env
->regs
[0] = do_arm_semihosting(env
);
782 new_mode
= ARM_CPU_MODE_SVC
;
785 /* The PC already points to the next instruction. */
789 /* See if this is a semihosting syscall. */
790 if (env
->thumb
&& semihosting_enabled
) {
791 mask
= lduw_code(env
->regs
[15]) & 0xff;
793 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
795 env
->regs
[0] = do_arm_semihosting(env
);
799 /* Fall through to prefetch abort. */
800 case EXCP_PREFETCH_ABORT
:
801 new_mode
= ARM_CPU_MODE_ABT
;
803 mask
= CPSR_A
| CPSR_I
;
806 case EXCP_DATA_ABORT
:
807 new_mode
= ARM_CPU_MODE_ABT
;
809 mask
= CPSR_A
| CPSR_I
;
813 new_mode
= ARM_CPU_MODE_IRQ
;
815 /* Disable IRQ and imprecise data aborts. */
816 mask
= CPSR_A
| CPSR_I
;
820 new_mode
= ARM_CPU_MODE_FIQ
;
822 /* Disable FIQ, IRQ and imprecise data aborts. */
823 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
827 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
828 return; /* Never happens. Keep compiler happy. */
831 if (env
->cp15
.c1_sys
& (1 << 13)) {
834 switch_mode (env
, new_mode
);
835 env
->spsr
= cpsr_read(env
);
837 env
->condexec_bits
= 0;
838 /* Switch to the new mode, and to the correct instruction set. */
839 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
840 env
->uncached_cpsr
|= mask
;
841 env
->thumb
= (env
->cp15
.c1_sys
& (1 << 30)) != 0;
842 env
->regs
[14] = env
->regs
[15] + offset
;
843 env
->regs
[15] = addr
;
844 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
847 /* Check section/page access permissions.
848 Returns the page protection flags, or zero if the access is not
850 static inline int check_ap(CPUState
*env
, int ap
, int domain
, int access_type
,
856 return PAGE_READ
| PAGE_WRITE
;
858 if (access_type
== 1)
865 if (access_type
== 1)
867 switch ((env
->cp15
.c1_sys
>> 8) & 3) {
869 return is_user
? 0 : PAGE_READ
;
876 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
881 return PAGE_READ
| PAGE_WRITE
;
883 return PAGE_READ
| PAGE_WRITE
;
884 case 4: /* Reserved. */
887 return is_user
? 0 : prot_ro
;
891 if (!arm_feature (env
, ARM_FEATURE_V7
))
899 static uint32_t get_level1_table_address(CPUState
*env
, uint32_t address
)
903 if (address
& env
->cp15
.c2_mask
)
904 table
= env
->cp15
.c2_base1
& 0xffffc000;
906 table
= env
->cp15
.c2_base0
& env
->cp15
.c2_base_mask
;
908 table
|= (address
>> 18) & 0x3ffc;
912 static int get_phys_addr_v5(CPUState
*env
, uint32_t address
, int access_type
,
913 int is_user
, uint32_t *phys_ptr
, int *prot
,
914 target_ulong
*page_size
)
924 /* Pagetable walk. */
925 /* Lookup l1 descriptor. */
926 table
= get_level1_table_address(env
, address
);
927 desc
= ldl_phys(table
);
929 domain
= (env
->cp15
.c3
>> ((desc
>> 4) & 0x1e)) & 3;
931 /* Section translation fault. */
935 if (domain
== 0 || domain
== 2) {
937 code
= 9; /* Section domain fault. */
939 code
= 11; /* Page domain fault. */
944 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
945 ap
= (desc
>> 10) & 3;
947 *page_size
= 1024 * 1024;
949 /* Lookup l2 entry. */
951 /* Coarse pagetable. */
952 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
954 /* Fine pagetable. */
955 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
957 desc
= ldl_phys(table
);
959 case 0: /* Page translation fault. */
962 case 1: /* 64k page. */
963 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
964 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
965 *page_size
= 0x10000;
967 case 2: /* 4k page. */
968 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
969 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
972 case 3: /* 1k page. */
974 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
975 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
977 /* Page translation fault. */
982 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
984 ap
= (desc
>> 4) & 3;
988 /* Never happens, but compiler isn't smart enough to tell. */
993 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
995 /* Access permission fault. */
999 *phys_ptr
= phys_addr
;
1002 return code
| (domain
<< 4);
1005 static int get_phys_addr_v6(CPUState
*env
, uint32_t address
, int access_type
,
1006 int is_user
, uint32_t *phys_ptr
, int *prot
,
1007 target_ulong
*page_size
)
1018 /* Pagetable walk. */
1019 /* Lookup l1 descriptor. */
1020 table
= get_level1_table_address(env
, address
);
1021 desc
= ldl_phys(table
);
1024 /* Section translation fault. */
1028 } else if (type
== 2 && (desc
& (1 << 18))) {
1032 /* Section or page. */
1033 domain
= (desc
>> 4) & 0x1e;
1035 domain
= (env
->cp15
.c3
>> domain
) & 3;
1036 if (domain
== 0 || domain
== 2) {
1038 code
= 9; /* Section domain fault. */
1040 code
= 11; /* Page domain fault. */
1044 if (desc
& (1 << 18)) {
1046 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
1047 *page_size
= 0x1000000;
1050 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
1051 *page_size
= 0x100000;
1053 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
1054 xn
= desc
& (1 << 4);
1057 /* Lookup l2 entry. */
1058 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
1059 desc
= ldl_phys(table
);
1060 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
1062 case 0: /* Page translation fault. */
1065 case 1: /* 64k page. */
1066 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
1067 xn
= desc
& (1 << 15);
1068 *page_size
= 0x10000;
1070 case 2: case 3: /* 4k page. */
1071 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
1073 *page_size
= 0x1000;
1076 /* Never happens, but compiler isn't smart enough to tell. */
1081 if (xn
&& access_type
== 2)
1084 /* The simplified model uses AP[0] as an access control bit. */
1085 if ((env
->cp15
.c1_sys
& (1 << 29)) && (ap
& 1) == 0) {
1086 /* Access flag fault. */
1087 code
= (code
== 15) ? 6 : 3;
1090 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1092 /* Access permission fault. */
1098 *phys_ptr
= phys_addr
;
1101 return code
| (domain
<< 4);
1104 static int get_phys_addr_mpu(CPUState
*env
, uint32_t address
, int access_type
,
1105 int is_user
, uint32_t *phys_ptr
, int *prot
)
1111 *phys_ptr
= address
;
1112 for (n
= 7; n
>= 0; n
--) {
1113 base
= env
->cp15
.c6_region
[n
];
1114 if ((base
& 1) == 0)
1116 mask
= 1 << ((base
>> 1) & 0x1f);
1117 /* Keep this shift separate from the above to avoid an
1118 (undefined) << 32. */
1119 mask
= (mask
<< 1) - 1;
1120 if (((base
^ address
) & ~mask
) == 0)
1126 if (access_type
== 2) {
1127 mask
= env
->cp15
.c5_insn
;
1129 mask
= env
->cp15
.c5_data
;
1131 mask
= (mask
>> (n
* 4)) & 0xf;
1138 *prot
= PAGE_READ
| PAGE_WRITE
;
1143 *prot
|= PAGE_WRITE
;
1146 *prot
= PAGE_READ
| PAGE_WRITE
;
1157 /* Bad permission. */
1164 static inline int get_phys_addr(CPUState
*env
, uint32_t address
,
1165 int access_type
, int is_user
,
1166 uint32_t *phys_ptr
, int *prot
,
1167 target_ulong
*page_size
)
1169 /* Fast Context Switch Extension. */
1170 if (address
< 0x02000000)
1171 address
+= env
->cp15
.c13_fcse
;
1173 if ((env
->cp15
.c1_sys
& 1) == 0) {
1174 /* MMU/MPU disabled. */
1175 *phys_ptr
= address
;
1176 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
1177 *page_size
= TARGET_PAGE_SIZE
;
1179 } else if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1180 *page_size
= TARGET_PAGE_SIZE
;
1181 return get_phys_addr_mpu(env
, address
, access_type
, is_user
, phys_ptr
,
1183 } else if (env
->cp15
.c1_sys
& (1 << 23)) {
1184 return get_phys_addr_v6(env
, address
, access_type
, is_user
, phys_ptr
,
1187 return get_phys_addr_v5(env
, address
, access_type
, is_user
, phys_ptr
,
1192 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
,
1193 int access_type
, int mmu_idx
, int is_softmmu
)
1196 target_ulong page_size
;
1200 is_user
= mmu_idx
== MMU_USER_IDX
;
1201 ret
= get_phys_addr(env
, address
, access_type
, is_user
, &phys_addr
, &prot
,
1204 /* Map a single [sub]page. */
1205 phys_addr
&= ~(uint32_t)0x3ff;
1206 address
&= ~(uint32_t)0x3ff;
1207 tlb_set_page (env
, address
, phys_addr
, prot
, mmu_idx
, page_size
);
1211 if (access_type
== 2) {
1212 env
->cp15
.c5_insn
= ret
;
1213 env
->cp15
.c6_insn
= address
;
1214 env
->exception_index
= EXCP_PREFETCH_ABORT
;
1216 env
->cp15
.c5_data
= ret
;
1217 if (access_type
== 1 && arm_feature(env
, ARM_FEATURE_V6
))
1218 env
->cp15
.c5_data
|= (1 << 11);
1219 env
->cp15
.c6_data
= address
;
1220 env
->exception_index
= EXCP_DATA_ABORT
;
1225 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
1228 target_ulong page_size
;
1232 ret
= get_phys_addr(env
, addr
, 0, 0, &phys_addr
, &prot
, &page_size
);
1240 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1242 int cp_num
= (insn
>> 8) & 0xf;
1243 int cp_info
= (insn
>> 5) & 7;
1244 int src
= (insn
>> 16) & 0xf;
1245 int operand
= insn
& 0xf;
1247 if (env
->cp
[cp_num
].cp_write
)
1248 env
->cp
[cp_num
].cp_write(env
->cp
[cp_num
].opaque
,
1249 cp_info
, src
, operand
, val
);
1252 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
1254 int cp_num
= (insn
>> 8) & 0xf;
1255 int cp_info
= (insn
>> 5) & 7;
1256 int dest
= (insn
>> 16) & 0xf;
1257 int operand
= insn
& 0xf;
1259 if (env
->cp
[cp_num
].cp_read
)
1260 return env
->cp
[cp_num
].cp_read(env
->cp
[cp_num
].opaque
,
1261 cp_info
, dest
, operand
);
1265 /* Return basic MPU access permission bits. */
1266 static uint32_t simple_mpu_ap_bits(uint32_t val
)
1273 for (i
= 0; i
< 16; i
+= 2) {
1274 ret
|= (val
>> i
) & mask
;
1280 /* Pad basic MPU access permission bits to extended format. */
1281 static uint32_t extended_mpu_ap_bits(uint32_t val
)
1288 for (i
= 0; i
< 16; i
+= 2) {
1289 ret
|= (val
& mask
) << i
;
1295 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1301 op1
= (insn
>> 21) & 7;
1302 op2
= (insn
>> 5) & 7;
1304 switch ((insn
>> 16) & 0xf) {
1307 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1309 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1311 if (arm_feature(env
, ARM_FEATURE_V7
)
1312 && op1
== 2 && crm
== 0 && op2
== 0) {
1313 env
->cp15
.c0_cssel
= val
& 0xf;
1317 case 1: /* System configuration. */
1318 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1322 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) || crm
== 0)
1323 env
->cp15
.c1_sys
= val
;
1324 /* ??? Lots of these bits are not implemented. */
1325 /* This may enable/disable the MMU, so do a TLB flush. */
1328 case 1: /* Auxiliary cotrol register. */
1329 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1330 env
->cp15
.c1_xscaleauxcr
= val
;
1333 /* Not implemented. */
1336 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1338 if (env
->cp15
.c1_coproc
!= val
) {
1339 env
->cp15
.c1_coproc
= val
;
1340 /* ??? Is this safe when called from within a TB? */
1348 case 2: /* MMU Page table control / MPU cache control. */
1349 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1352 env
->cp15
.c2_data
= val
;
1355 env
->cp15
.c2_insn
= val
;
1363 env
->cp15
.c2_base0
= val
;
1366 env
->cp15
.c2_base1
= val
;
1370 env
->cp15
.c2_control
= val
;
1371 env
->cp15
.c2_mask
= ~(((uint32_t)0xffffffffu
) >> val
);
1372 env
->cp15
.c2_base_mask
= ~((uint32_t)0x3fffu
>> val
);
1379 case 3: /* MMU Domain access control / MPU write buffer control. */
1381 tlb_flush(env
, 1); /* Flush TLB as domain not tracked in TLB */
1383 case 4: /* Reserved. */
1385 case 5: /* MMU Fault status / MPU access permission. */
1386 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1390 if (arm_feature(env
, ARM_FEATURE_MPU
))
1391 val
= extended_mpu_ap_bits(val
);
1392 env
->cp15
.c5_data
= val
;
1395 if (arm_feature(env
, ARM_FEATURE_MPU
))
1396 val
= extended_mpu_ap_bits(val
);
1397 env
->cp15
.c5_insn
= val
;
1400 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1402 env
->cp15
.c5_data
= val
;
1405 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1407 env
->cp15
.c5_insn
= val
;
1413 case 6: /* MMU Fault address / MPU base/size. */
1414 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1417 env
->cp15
.c6_region
[crm
] = val
;
1419 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1423 env
->cp15
.c6_data
= val
;
1425 case 1: /* ??? This is WFAR on armv6 */
1427 env
->cp15
.c6_insn
= val
;
1434 case 7: /* Cache control. */
1435 env
->cp15
.c15_i_max
= 0x000;
1436 env
->cp15
.c15_i_min
= 0xff0;
1437 /* No cache, so nothing to do. */
1438 /* ??? MPCore has VA to PA translation functions. */
1440 case 8: /* MMU TLB control. */
1442 case 0: /* Invalidate all. */
1445 case 1: /* Invalidate single TLB entry. */
1446 tlb_flush_page(env
, val
& TARGET_PAGE_MASK
);
1448 case 2: /* Invalidate on ASID. */
1449 tlb_flush(env
, val
== 0);
1451 case 3: /* Invalidate single entry on MVA. */
1452 /* ??? This is like case 1, but ignores ASID. */
1460 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1463 case 0: /* Cache lockdown. */
1465 case 0: /* L1 cache. */
1468 env
->cp15
.c9_data
= val
;
1471 env
->cp15
.c9_insn
= val
;
1477 case 1: /* L2 cache. */
1478 /* Ignore writes to L2 lockdown/auxiliary registers. */
1484 case 1: /* TCM memory region registers. */
1485 /* Not implemented. */
1491 case 10: /* MMU TLB lockdown. */
1492 /* ??? TLB lockdown not implemented. */
1494 case 12: /* Reserved. */
1496 case 13: /* Process ID. */
1499 /* Unlike real hardware the qemu TLB uses virtual addresses,
1500 not modified virtual addresses, so this causes a TLB flush.
1502 if (env
->cp15
.c13_fcse
!= val
)
1504 env
->cp15
.c13_fcse
= val
;
1507 /* This changes the ASID, so do a TLB flush. */
1508 if (env
->cp15
.c13_context
!= val
1509 && !arm_feature(env
, ARM_FEATURE_MPU
))
1511 env
->cp15
.c13_context
= val
;
1517 case 14: /* Reserved. */
1519 case 15: /* Implementation specific. */
1520 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1521 if (op2
== 0 && crm
== 1) {
1522 if (env
->cp15
.c15_cpar
!= (val
& 0x3fff)) {
1523 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
1525 env
->cp15
.c15_cpar
= val
& 0x3fff;
1531 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1535 case 1: /* Set TI925T configuration. */
1536 env
->cp15
.c15_ticonfig
= val
& 0xe7;
1537 env
->cp15
.c0_cpuid
= (val
& (1 << 5)) ? /* OS_TYPE bit */
1538 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
1540 case 2: /* Set I_max. */
1541 env
->cp15
.c15_i_max
= val
;
1543 case 3: /* Set I_min. */
1544 env
->cp15
.c15_i_min
= val
;
1546 case 4: /* Set thread-ID. */
1547 env
->cp15
.c15_threadid
= val
& 0xffff;
1549 case 8: /* Wait-for-interrupt (deprecated). */
1550 cpu_interrupt(env
, CPU_INTERRUPT_HALT
);
1560 /* ??? For debugging only. Should raise illegal instruction exception. */
1561 cpu_abort(env
, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1562 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1565 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
1571 op1
= (insn
>> 21) & 7;
1572 op2
= (insn
>> 5) & 7;
1574 switch ((insn
>> 16) & 0xf) {
1575 case 0: /* ID codes. */
1581 case 0: /* Device ID. */
1582 return env
->cp15
.c0_cpuid
;
1583 case 1: /* Cache Type. */
1584 return env
->cp15
.c0_cachetype
;
1585 case 2: /* TCM status. */
1587 case 3: /* TLB type register. */
1588 return 0; /* No lockable TLB entries. */
1589 case 5: /* CPU ID */
1590 if (ARM_CPUID(env
) == ARM_CPUID_CORTEXA9
) {
1591 return env
->cpu_index
| 0x80000900;
1593 return env
->cpu_index
;
1599 if (!arm_feature(env
, ARM_FEATURE_V6
))
1601 return env
->cp15
.c0_c1
[op2
];
1603 if (!arm_feature(env
, ARM_FEATURE_V6
))
1605 return env
->cp15
.c0_c2
[op2
];
1606 case 3: case 4: case 5: case 6: case 7:
1612 /* These registers aren't documented on arm11 cores. However
1613 Linux looks at them anyway. */
1614 if (!arm_feature(env
, ARM_FEATURE_V6
))
1618 if (!arm_feature(env
, ARM_FEATURE_V7
))
1623 return env
->cp15
.c0_ccsid
[env
->cp15
.c0_cssel
];
1625 return env
->cp15
.c0_clid
;
1631 if (op2
!= 0 || crm
!= 0)
1633 return env
->cp15
.c0_cssel
;
1637 case 1: /* System configuration. */
1638 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1641 case 0: /* Control register. */
1642 return env
->cp15
.c1_sys
;
1643 case 1: /* Auxiliary control register. */
1644 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1645 return env
->cp15
.c1_xscaleauxcr
;
1646 if (!arm_feature(env
, ARM_FEATURE_AUXCR
))
1648 switch (ARM_CPUID(env
)) {
1649 case ARM_CPUID_ARM1026
:
1651 case ARM_CPUID_ARM1136
:
1652 case ARM_CPUID_ARM1136_R2
:
1654 case ARM_CPUID_ARM11MPCORE
:
1656 case ARM_CPUID_CORTEXA8
:
1658 case ARM_CPUID_CORTEXA9
:
1663 case 2: /* Coprocessor access register. */
1664 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1666 return env
->cp15
.c1_coproc
;
1670 case 2: /* MMU Page table control / MPU cache control. */
1671 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1674 return env
->cp15
.c2_data
;
1677 return env
->cp15
.c2_insn
;
1685 return env
->cp15
.c2_base0
;
1687 return env
->cp15
.c2_base1
;
1689 return env
->cp15
.c2_control
;
1694 case 3: /* MMU Domain access control / MPU write buffer control. */
1695 return env
->cp15
.c3
;
1696 case 4: /* Reserved. */
1698 case 5: /* MMU Fault status / MPU access permission. */
1699 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1703 if (arm_feature(env
, ARM_FEATURE_MPU
))
1704 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1705 return env
->cp15
.c5_data
;
1707 if (arm_feature(env
, ARM_FEATURE_MPU
))
1708 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1709 return env
->cp15
.c5_insn
;
1711 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1713 return env
->cp15
.c5_data
;
1715 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1717 return env
->cp15
.c5_insn
;
1721 case 6: /* MMU Fault address. */
1722 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1725 return env
->cp15
.c6_region
[crm
];
1727 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1731 return env
->cp15
.c6_data
;
1733 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1734 /* Watchpoint Fault Adrress. */
1735 return 0; /* Not implemented. */
1737 /* Instruction Fault Adrress. */
1738 /* Arm9 doesn't have an IFAR, but implementing it anyway
1739 shouldn't do any harm. */
1740 return env
->cp15
.c6_insn
;
1743 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1744 /* Instruction Fault Adrress. */
1745 return env
->cp15
.c6_insn
;
1753 case 7: /* Cache control. */
1754 /* FIXME: Should only clear Z flag if destination is r15. */
1757 case 8: /* MMU TLB control. */
1759 case 9: /* Cache lockdown. */
1761 case 0: /* L1 cache. */
1762 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1766 return env
->cp15
.c9_data
;
1768 return env
->cp15
.c9_insn
;
1772 case 1: /* L2 cache */
1775 /* L2 Lockdown and Auxiliary control. */
1780 case 10: /* MMU TLB lockdown. */
1781 /* ??? TLB lockdown not implemented. */
1783 case 11: /* TCM DMA control. */
1784 case 12: /* Reserved. */
1786 case 13: /* Process ID. */
1789 return env
->cp15
.c13_fcse
;
1791 return env
->cp15
.c13_context
;
1795 case 14: /* Reserved. */
1797 case 15: /* Implementation specific. */
1798 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1799 if (op2
== 0 && crm
== 1)
1800 return env
->cp15
.c15_cpar
;
1804 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1808 case 1: /* Read TI925T configuration. */
1809 return env
->cp15
.c15_ticonfig
;
1810 case 2: /* Read I_max. */
1811 return env
->cp15
.c15_i_max
;
1812 case 3: /* Read I_min. */
1813 return env
->cp15
.c15_i_min
;
1814 case 4: /* Read thread-ID. */
1815 return env
->cp15
.c15_threadid
;
1816 case 8: /* TI925T_status */
1819 /* TODO: Peripheral port remap register:
1820 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt
1821 * controller base address at $rn & ~0xfff and map size of
1822 * 0x200 << ($rn & 0xfff), when MMU is off. */
1828 /* ??? For debugging only. Should raise illegal instruction exception. */
1829 cpu_abort(env
, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
1830 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1834 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
1836 env
->banked_r13
[bank_number(mode
)] = val
;
1839 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
1841 return env
->banked_r13
[bank_number(mode
)];
1844 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
1848 return xpsr_read(env
) & 0xf8000000;
1850 return xpsr_read(env
) & 0xf80001ff;
1852 return xpsr_read(env
) & 0xff00fc00;
1854 return xpsr_read(env
) & 0xff00fdff;
1856 return xpsr_read(env
) & 0x000001ff;
1858 return xpsr_read(env
) & 0x0700fc00;
1860 return xpsr_read(env
) & 0x0700edff;
1862 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
1864 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
1865 case 16: /* PRIMASK */
1866 return (env
->uncached_cpsr
& CPSR_I
) != 0;
1867 case 17: /* FAULTMASK */
1868 return (env
->uncached_cpsr
& CPSR_F
) != 0;
1869 case 18: /* BASEPRI */
1870 case 19: /* BASEPRI_MAX */
1871 return env
->v7m
.basepri
;
1872 case 20: /* CONTROL */
1873 return env
->v7m
.control
;
1875 /* ??? For debugging only. */
1876 cpu_abort(env
, "Unimplemented system register read (%d)\n", reg
);
1881 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
1885 xpsr_write(env
, val
, 0xf8000000);
1888 xpsr_write(env
, val
, 0xf8000000);
1891 xpsr_write(env
, val
, 0xfe00fc00);
1894 xpsr_write(env
, val
, 0xfe00fc00);
1897 /* IPSR bits are readonly. */
1900 xpsr_write(env
, val
, 0x0600fc00);
1903 xpsr_write(env
, val
, 0x0600fc00);
1906 if (env
->v7m
.current_sp
)
1907 env
->v7m
.other_sp
= val
;
1909 env
->regs
[13] = val
;
1912 if (env
->v7m
.current_sp
)
1913 env
->regs
[13] = val
;
1915 env
->v7m
.other_sp
= val
;
1917 case 16: /* PRIMASK */
1919 env
->uncached_cpsr
|= CPSR_I
;
1921 env
->uncached_cpsr
&= ~CPSR_I
;
1923 case 17: /* FAULTMASK */
1925 env
->uncached_cpsr
|= CPSR_F
;
1927 env
->uncached_cpsr
&= ~CPSR_F
;
1929 case 18: /* BASEPRI */
1930 env
->v7m
.basepri
= val
& 0xff;
1932 case 19: /* BASEPRI_MAX */
1934 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
1935 env
->v7m
.basepri
= val
;
1937 case 20: /* CONTROL */
1938 env
->v7m
.control
= val
& 3;
1939 switch_v7m_sp(env
, (val
& 2) != 0);
1942 /* ??? For debugging only. */
1943 cpu_abort(env
, "Unimplemented system register write (%d)\n", reg
);
1948 void cpu_arm_set_cp_io(CPUARMState
*env
, int cpnum
,
1949 ARMReadCPFunc
*cp_read
, ARMWriteCPFunc
*cp_write
,
1952 if (cpnum
< 0 || cpnum
> 14) {
1953 cpu_abort(env
, "Bad coprocessor number: %i\n", cpnum
);
1957 env
->cp
[cpnum
].cp_read
= cp_read
;
1958 env
->cp
[cpnum
].cp_write
= cp_write
;
1959 env
->cp
[cpnum
].opaque
= opaque
;
1964 /* Note that signed overflow is undefined in C. The following routines are
1965 careful to use unsigned types where modulo arithmetic is required.
1966 Failure to do so _will_ break on newer gcc. */
1968 /* Signed saturating arithmetic. */
1970 /* Perform 16-bit signed saturating addition. */
1971 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
1976 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
1985 /* Perform 8-bit signed saturating addition. */
1986 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
1991 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
2000 /* Perform 16-bit signed saturating subtraction. */
2001 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
2006 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
2015 /* Perform 8-bit signed saturating subtraction. */
2016 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
2021 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
2030 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
2031 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
2032 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
2033 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
2036 #include "op_addsub.h"
2038 /* Unsigned saturating arithmetic. */
2039 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
2048 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
2056 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
2065 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
2073 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
2074 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
2075 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
2076 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
2079 #include "op_addsub.h"
2081 /* Signed modulo arithmetic. */
2082 #define SARITH16(a, b, n, op) do { \
2084 sum = (int16_t)((uint16_t)(a) op (uint16_t)(b)); \
2085 RESULT(sum, n, 16); \
2087 ge |= 3 << (n * 2); \
2090 #define SARITH8(a, b, n, op) do { \
2092 sum = (int8_t)((uint8_t)(a) op (uint8_t)(b)); \
2093 RESULT(sum, n, 8); \
2099 #define ADD16(a, b, n) SARITH16(a, b, n, +)
2100 #define SUB16(a, b, n) SARITH16(a, b, n, -)
2101 #define ADD8(a, b, n) SARITH8(a, b, n, +)
2102 #define SUB8(a, b, n) SARITH8(a, b, n, -)
2106 #include "op_addsub.h"
2108 /* Unsigned modulo arithmetic. */
2109 #define ADD16(a, b, n) do { \
2111 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
2112 RESULT(sum, n, 16); \
2113 if ((sum >> 16) == 1) \
2114 ge |= 3 << (n * 2); \
2117 #define ADD8(a, b, n) do { \
2119 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
2120 RESULT(sum, n, 8); \
2121 if ((sum >> 8) == 1) \
2125 #define SUB16(a, b, n) do { \
2127 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
2128 RESULT(sum, n, 16); \
2129 if ((sum >> 16) == 0) \
2130 ge |= 3 << (n * 2); \
2133 #define SUB8(a, b, n) do { \
2135 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
2136 RESULT(sum, n, 8); \
2137 if ((sum >> 8) == 0) \
2144 #include "op_addsub.h"
2146 /* Halved signed arithmetic. */
2147 #define ADD16(a, b, n) \
2148 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
2149 #define SUB16(a, b, n) \
2150 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
2151 #define ADD8(a, b, n) \
2152 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
2153 #define SUB8(a, b, n) \
2154 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
2157 #include "op_addsub.h"
2159 /* Halved unsigned arithmetic. */
2160 #define ADD16(a, b, n) \
2161 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2162 #define SUB16(a, b, n) \
2163 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2164 #define ADD8(a, b, n) \
2165 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2166 #define SUB8(a, b, n) \
2167 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2170 #include "op_addsub.h"
2172 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
2180 /* Unsigned sum of absolute byte differences. */
2181 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
2184 sum
= do_usad(a
, b
);
2185 sum
+= do_usad(a
>> 8, b
>> 8);
2186 sum
+= do_usad(a
>> 16, b
>>16);
2187 sum
+= do_usad(a
>> 24, b
>> 24);
2191 /* For ARMv6 SEL instruction. */
2192 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
2205 return (a
& mask
) | (b
& ~mask
);
2208 uint32_t HELPER(logicq_cc
)(uint64_t val
)
2210 return (val
>> 32) | (val
!= 0);
2213 /* VFP support. We follow the convention used for VFP instrunctions:
2214 Single precition routines have a "s" suffix, double precision a
2217 /* Convert host exception flags to vfp form. */
2218 static inline int vfp_exceptbits_from_host(int host_bits
)
2220 int target_bits
= 0;
2222 if (host_bits
& float_flag_invalid
)
2224 if (host_bits
& float_flag_divbyzero
)
2226 if (host_bits
& float_flag_overflow
)
2228 if (host_bits
& float_flag_underflow
)
2230 if (host_bits
& float_flag_inexact
)
2231 target_bits
|= 0x10;
2235 uint32_t HELPER(vfp_get_fpscr
)(CPUState
*env
)
2240 fpscr
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & 0xffc8ffff)
2241 | (env
->vfp
.vec_len
<< 16)
2242 | (env
->vfp
.vec_stride
<< 20);
2243 i
= get_float_exception_flags(&env
->vfp
.fp_status
);
2244 fpscr
|= vfp_exceptbits_from_host(i
);
2248 /* Convert vfp exception flags to target form. */
2249 static inline int vfp_exceptbits_to_host(int target_bits
)
2253 if (target_bits
& 1)
2254 host_bits
|= float_flag_invalid
;
2255 if (target_bits
& 2)
2256 host_bits
|= float_flag_divbyzero
;
2257 if (target_bits
& 4)
2258 host_bits
|= float_flag_overflow
;
2259 if (target_bits
& 8)
2260 host_bits
|= float_flag_underflow
;
2261 if (target_bits
& 0x10)
2262 host_bits
|= float_flag_inexact
;
2266 void HELPER(vfp_set_fpscr
)(CPUState
*env
, uint32_t val
)
2271 changed
= env
->vfp
.xregs
[ARM_VFP_FPSCR
];
2272 env
->vfp
.xregs
[ARM_VFP_FPSCR
] = (val
& 0xffc8ffff);
2273 env
->vfp
.vec_len
= (val
>> 16) & 7;
2274 env
->vfp
.vec_stride
= (val
>> 20) & 3;
2277 if (changed
& (3 << 22)) {
2278 i
= (val
>> 22) & 3;
2281 i
= float_round_nearest_even
;
2287 i
= float_round_down
;
2290 i
= float_round_to_zero
;
2293 set_float_rounding_mode(i
, &env
->vfp
.fp_status
);
2295 if (changed
& (1 << 24))
2296 set_flush_to_zero((val
& (1 << 24)) != 0, &env
->vfp
.fp_status
);
2297 if (changed
& (1 << 25))
2298 set_default_nan_mode((val
& (1 << 25)) != 0, &env
->vfp
.fp_status
);
2300 i
= vfp_exceptbits_to_host((val
>> 8) & 0x1f);
2301 set_float_exception_flags(i
, &env
->vfp
.fp_status
);
2304 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
2306 #define VFP_BINOP(name) \
2307 float32 VFP_HELPER(name, s)(float32 a, float32 b, CPUState *env) \
2309 return float32_ ## name (a, b, &env->vfp.fp_status); \
2311 float64 VFP_HELPER(name, d)(float64 a, float64 b, CPUState *env) \
2313 return float64_ ## name (a, b, &env->vfp.fp_status); \
2321 float32
VFP_HELPER(neg
, s
)(float32 a
)
2323 return float32_chs(a
);
2326 float64
VFP_HELPER(neg
, d
)(float64 a
)
2328 return float64_chs(a
);
2331 float32
VFP_HELPER(abs
, s
)(float32 a
)
2333 return float32_abs(a
);
2336 float64
VFP_HELPER(abs
, d
)(float64 a
)
2338 return float64_abs(a
);
2341 float32
VFP_HELPER(sqrt
, s
)(float32 a
, CPUState
*env
)
2343 return float32_sqrt(a
, &env
->vfp
.fp_status
);
2346 float64
VFP_HELPER(sqrt
, d
)(float64 a
, CPUState
*env
)
2348 return float64_sqrt(a
, &env
->vfp
.fp_status
);
2351 /* XXX: check quiet/signaling case */
2352 #define DO_VFP_cmp(p, type) \
2353 void VFP_HELPER(cmp, p)(type a, type b, CPUState *env) \
2356 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
2357 case 0: flags = 0x6; break; \
2358 case -1: flags = 0x8; break; \
2359 case 1: flags = 0x2; break; \
2360 default: case 2: flags = 0x3; break; \
2362 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2363 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2365 void VFP_HELPER(cmpe, p)(type a, type b, CPUState *env) \
2368 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
2369 case 0: flags = 0x6; break; \
2370 case -1: flags = 0x8; break; \
2371 case 1: flags = 0x2; break; \
2372 default: case 2: flags = 0x3; break; \
2374 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2375 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2377 DO_VFP_cmp(s
, float32
)
2378 DO_VFP_cmp(d
, float64
)
2381 /* Helper routines to perform bitwise copies between float and int. */
2382 static inline float32
vfp_itos(uint32_t i
)
2393 static inline uint32_t vfp_stoi(float32 s
)
2404 static inline float64
vfp_itod(uint64_t i
)
2415 static inline uint64_t vfp_dtoi(float64 d
)
2426 /* Integer to float conversion. */
2427 float32
VFP_HELPER(uito
, s
)(float32 x
, CPUState
*env
)
2429 return uint32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2432 float64
VFP_HELPER(uito
, d
)(float32 x
, CPUState
*env
)
2434 return uint32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2437 float32
VFP_HELPER(sito
, s
)(float32 x
, CPUState
*env
)
2439 return int32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2442 float64
VFP_HELPER(sito
, d
)(float32 x
, CPUState
*env
)
2444 return int32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2447 /* Float to integer conversion. */
2448 float32
VFP_HELPER(toui
, s
)(float32 x
, CPUState
*env
)
2450 return vfp_itos(float32_to_uint32(x
, &env
->vfp
.fp_status
));
2453 float32
VFP_HELPER(toui
, d
)(float64 x
, CPUState
*env
)
2455 return vfp_itos(float64_to_uint32(x
, &env
->vfp
.fp_status
));
2458 float32
VFP_HELPER(tosi
, s
)(float32 x
, CPUState
*env
)
2460 return vfp_itos(float32_to_int32(x
, &env
->vfp
.fp_status
));
2463 float32
VFP_HELPER(tosi
, d
)(float64 x
, CPUState
*env
)
2465 return vfp_itos(float64_to_int32(x
, &env
->vfp
.fp_status
));
2468 float32
VFP_HELPER(touiz
, s
)(float32 x
, CPUState
*env
)
2470 return vfp_itos(float32_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2473 float32
VFP_HELPER(touiz
, d
)(float64 x
, CPUState
*env
)
2475 return vfp_itos(float64_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2478 float32
VFP_HELPER(tosiz
, s
)(float32 x
, CPUState
*env
)
2480 return vfp_itos(float32_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2483 float32
VFP_HELPER(tosiz
, d
)(float64 x
, CPUState
*env
)
2485 return vfp_itos(float64_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2488 /* floating point conversion */
2489 float64
VFP_HELPER(fcvtd
, s
)(float32 x
, CPUState
*env
)
2491 return float32_to_float64(x
, &env
->vfp
.fp_status
);
2494 float32
VFP_HELPER(fcvts
, d
)(float64 x
, CPUState
*env
)
2496 return float64_to_float32(x
, &env
->vfp
.fp_status
);
2499 /* VFP3 fixed point conversion. */
2500 #define VFP_CONV_FIX(name, p, ftype, itype, sign) \
2501 ftype VFP_HELPER(name##to, p)(ftype x, uint32_t shift, CPUState *env) \
2504 tmp = sign##int32_to_##ftype ((itype)vfp_##p##toi(x), \
2505 &env->vfp.fp_status); \
2506 return ftype##_scalbn(tmp, -(int)shift, &env->vfp.fp_status); \
2508 ftype VFP_HELPER(to##name, p)(ftype x, uint32_t shift, CPUState *env) \
2511 tmp = ftype##_scalbn(x, shift, &env->vfp.fp_status); \
2512 return vfp_ito##p((itype)ftype##_to_##sign##int32_round_to_zero(tmp, \
2513 &env->vfp.fp_status)); \
2516 VFP_CONV_FIX(sh
, d
, float64
, int16
, )
2517 VFP_CONV_FIX(sl
, d
, float64
, int32
, )
2518 VFP_CONV_FIX(uh
, d
, float64
, uint16
, u
)
2519 VFP_CONV_FIX(ul
, d
, float64
, uint32
, u
)
2520 VFP_CONV_FIX(sh
, s
, float32
, int16
, )
2521 VFP_CONV_FIX(sl
, s
, float32
, int32
, )
2522 VFP_CONV_FIX(uh
, s
, float32
, uint16
, u
)
2523 VFP_CONV_FIX(ul
, s
, float32
, uint32
, u
)
2526 /* Half precision conversions. */
2527 float32
HELPER(vfp_fcvt_f16_to_f32
)(uint32_t a
, CPUState
*env
)
2529 float_status
*s
= &env
->vfp
.fp_status
;
2530 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
2531 return float16_to_float32(a
, ieee
, s
);
2534 uint32_t HELPER(vfp_fcvt_f32_to_f16
)(float32 a
, CPUState
*env
)
2536 float_status
*s
= &env
->vfp
.fp_status
;
2537 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
2538 return float32_to_float16(a
, ieee
, s
);
2541 float32
HELPER(recps_f32
)(float32 a
, float32 b
, CPUState
*env
)
2543 float_status
*s
= &env
->vfp
.fp_status
;
2544 float32 two
= int32_to_float32(2, s
);
2545 return float32_sub(two
, float32_mul(a
, b
, s
), s
);
2548 float32
HELPER(rsqrts_f32
)(float32 a
, float32 b
, CPUState
*env
)
2550 float_status
*s
= &env
->vfp
.fp_status
;
2551 float32 three
= int32_to_float32(3, s
);
2552 return float32_sub(three
, float32_mul(a
, b
, s
), s
);
2557 /* TODO: The architecture specifies the value that the estimate functions
2558 should return. We return the exact reciprocal/root instead. */
2559 float32
HELPER(recpe_f32
)(float32 a
, CPUState
*env
)
2561 float_status
*s
= &env
->vfp
.fp_status
;
2562 float32 one
= int32_to_float32(1, s
);
2563 return float32_div(one
, a
, s
);
2566 float32
HELPER(rsqrte_f32
)(float32 a
, CPUState
*env
)
2568 float_status
*s
= &env
->vfp
.fp_status
;
2569 float32 one
= int32_to_float32(1, s
);
2570 return float32_div(one
, float32_sqrt(a
, s
), s
);
2573 uint32_t HELPER(recpe_u32
)(uint32_t a
, CPUState
*env
)
2575 float_status
*s
= &env
->vfp
.fp_status
;
2577 tmp
= int32_to_float32(a
, s
);
2578 tmp
= float32_scalbn(tmp
, -32, s
);
2579 tmp
= helper_recpe_f32(tmp
, env
);
2580 tmp
= float32_scalbn(tmp
, 31, s
);
2581 return float32_to_int32(tmp
, s
);
2584 uint32_t HELPER(rsqrte_u32
)(uint32_t a
, CPUState
*env
)
2586 float_status
*s
= &env
->vfp
.fp_status
;
2588 tmp
= int32_to_float32(a
, s
);
2589 tmp
= float32_scalbn(tmp
, -32, s
);
2590 tmp
= helper_rsqrte_f32(tmp
, env
);
2591 tmp
= float32_scalbn(tmp
, 31, s
);
2592 return float32_to_int32(tmp
, s
);
2595 void HELPER(set_teecr
)(CPUState
*env
, uint32_t val
)
2598 if (env
->teecr
!= val
) {