9 #include "qemu-common.h"
11 static uint32_t cortexa8_cp15_c0_c1
[8] =
12 { 0x1031, 0x11, 0x400, 0, 0x31100003, 0x20000000, 0x01202000, 0x11 };
14 static uint32_t cortexa8_cp15_c0_c2
[8] =
15 { 0x00101111, 0x12112111, 0x21232031, 0x11112131, 0x00111142, 0, 0, 0 };
17 static uint32_t mpcore_cp15_c0_c1
[8] =
18 { 0x111, 0x1, 0, 0x2, 0x01100103, 0x10020302, 0x01222000, 0 };
20 static uint32_t mpcore_cp15_c0_c2
[8] =
21 { 0x00100011, 0x12002111, 0x11221011, 0x01102131, 0x141, 0, 0, 0 };
23 static uint32_t arm1136_cp15_c0_c1
[8] =
24 { 0x111, 0x1, 0x2, 0x3, 0x01130003, 0x10030302, 0x01222110, 0 };
26 static uint32_t arm1136_cp15_c0_c2
[8] =
27 { 0x00140011, 0x12002111, 0x11231111, 0x01102131, 0x141, 0, 0, 0 };
29 static uint32_t cpu_arm_find_by_name(const char *name
);
31 static inline void set_feature(CPUARMState
*env
, int feature
)
33 env
->features
|= 1u << feature
;
36 static void cpu_reset_model_id(CPUARMState
*env
, uint32_t id
)
38 env
->cp15
.c0_cpuid
= id
;
40 case ARM_CPUID_ARM926
:
41 set_feature(env
, ARM_FEATURE_VFP
);
42 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41011090;
43 env
->cp15
.c0_cachetype
= 0x1dd20d2;
44 env
->cp15
.c1_sys
= 0x00090078;
46 case ARM_CPUID_ARM946
:
47 set_feature(env
, ARM_FEATURE_MPU
);
48 env
->cp15
.c0_cachetype
= 0x0f004006;
49 env
->cp15
.c1_sys
= 0x00000078;
51 case ARM_CPUID_ARM1026
:
52 set_feature(env
, ARM_FEATURE_VFP
);
53 set_feature(env
, ARM_FEATURE_AUXCR
);
54 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410110a0;
55 env
->cp15
.c0_cachetype
= 0x1dd20d2;
56 env
->cp15
.c1_sys
= 0x00090078;
58 case ARM_CPUID_ARM1136_R2
:
59 case ARM_CPUID_ARM1136
:
60 set_feature(env
, ARM_FEATURE_V6
);
61 set_feature(env
, ARM_FEATURE_VFP
);
62 set_feature(env
, ARM_FEATURE_AUXCR
);
63 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
64 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
65 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
66 memcpy(env
->cp15
.c0_c1
, arm1136_cp15_c0_c1
, 8 * sizeof(uint32_t));
67 memcpy(env
->cp15
.c0_c2
, arm1136_cp15_c0_c2
, 8 * sizeof(uint32_t));
68 env
->cp15
.c0_cachetype
= 0x1dd20d2;
70 case ARM_CPUID_ARM11MPCORE
:
71 set_feature(env
, ARM_FEATURE_V6
);
72 set_feature(env
, ARM_FEATURE_V6K
);
73 set_feature(env
, ARM_FEATURE_VFP
);
74 set_feature(env
, ARM_FEATURE_AUXCR
);
75 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
76 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
77 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
78 memcpy(env
->cp15
.c0_c1
, mpcore_cp15_c0_c1
, 8 * sizeof(uint32_t));
79 memcpy(env
->cp15
.c0_c2
, mpcore_cp15_c0_c2
, 8 * sizeof(uint32_t));
80 env
->cp15
.c0_cachetype
= 0x1dd20d2;
82 case ARM_CPUID_CORTEXA8
:
83 set_feature(env
, ARM_FEATURE_V6
);
84 set_feature(env
, ARM_FEATURE_V6K
);
85 set_feature(env
, ARM_FEATURE_V7
);
86 set_feature(env
, ARM_FEATURE_AUXCR
);
87 set_feature(env
, ARM_FEATURE_THUMB2
);
88 set_feature(env
, ARM_FEATURE_VFP
);
89 set_feature(env
, ARM_FEATURE_VFP3
);
90 set_feature(env
, ARM_FEATURE_NEON
);
91 set_feature(env
, ARM_FEATURE_THUMB2EE
);
92 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410330c0;
93 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
94 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00011100;
95 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c1
, 8 * sizeof(uint32_t));
96 memcpy(env
->cp15
.c0_c2
, cortexa8_cp15_c0_c2
, 8 * sizeof(uint32_t));
97 env
->cp15
.c0_cachetype
= 0x82048004;
98 env
->cp15
.c0_clid
= (1 << 27) | (2 << 24) | 3;
99 env
->cp15
.c0_ccsid
[0] = 0xe007e01a; /* 16k L1 dcache. */
100 env
->cp15
.c0_ccsid
[1] = 0x2007e01a; /* 16k L1 icache. */
101 env
->cp15
.c0_ccsid
[2] = 0xf0000000; /* No L2 icache. */
103 case ARM_CPUID_CORTEXM3
:
104 set_feature(env
, ARM_FEATURE_V6
);
105 set_feature(env
, ARM_FEATURE_THUMB2
);
106 set_feature(env
, ARM_FEATURE_V7
);
107 set_feature(env
, ARM_FEATURE_M
);
108 set_feature(env
, ARM_FEATURE_DIV
);
110 case ARM_CPUID_ANY
: /* For userspace emulation. */
111 set_feature(env
, ARM_FEATURE_V6
);
112 set_feature(env
, ARM_FEATURE_V6K
);
113 set_feature(env
, ARM_FEATURE_V7
);
114 set_feature(env
, ARM_FEATURE_THUMB2
);
115 set_feature(env
, ARM_FEATURE_VFP
);
116 set_feature(env
, ARM_FEATURE_VFP3
);
117 set_feature(env
, ARM_FEATURE_NEON
);
118 set_feature(env
, ARM_FEATURE_THUMB2EE
);
119 set_feature(env
, ARM_FEATURE_DIV
);
121 case ARM_CPUID_TI915T
:
122 case ARM_CPUID_TI925T
:
123 set_feature(env
, ARM_FEATURE_OMAPCP
);
124 env
->cp15
.c0_cpuid
= ARM_CPUID_TI925T
; /* Depends on wiring. */
125 env
->cp15
.c0_cachetype
= 0x5109149;
126 env
->cp15
.c1_sys
= 0x00000070;
127 env
->cp15
.c15_i_max
= 0x000;
128 env
->cp15
.c15_i_min
= 0xff0;
130 case ARM_CPUID_PXA250
:
131 case ARM_CPUID_PXA255
:
132 case ARM_CPUID_PXA260
:
133 case ARM_CPUID_PXA261
:
134 case ARM_CPUID_PXA262
:
135 set_feature(env
, ARM_FEATURE_XSCALE
);
136 /* JTAG_ID is ((id << 28) | 0x09265013) */
137 env
->cp15
.c0_cachetype
= 0xd172172;
138 env
->cp15
.c1_sys
= 0x00000078;
140 case ARM_CPUID_PXA270_A0
:
141 case ARM_CPUID_PXA270_A1
:
142 case ARM_CPUID_PXA270_B0
:
143 case ARM_CPUID_PXA270_B1
:
144 case ARM_CPUID_PXA270_C0
:
145 case ARM_CPUID_PXA270_C5
:
146 set_feature(env
, ARM_FEATURE_XSCALE
);
147 /* JTAG_ID is ((id << 28) | 0x09265013) */
148 set_feature(env
, ARM_FEATURE_IWMMXT
);
149 env
->iwmmxt
.cregs
[ARM_IWMMXT_wCID
] = 0x69051000 | 'Q';
150 env
->cp15
.c0_cachetype
= 0xd172172;
151 env
->cp15
.c1_sys
= 0x00000078;
154 cpu_abort(env
, "Bad CPU ID: %x\n", id
);
159 void cpu_reset(CPUARMState
*env
)
162 id
= env
->cp15
.c0_cpuid
;
163 memset(env
, 0, offsetof(CPUARMState
, breakpoints
));
165 cpu_reset_model_id(env
, id
);
166 #if defined (CONFIG_USER_ONLY)
167 env
->uncached_cpsr
= ARM_CPU_MODE_USR
;
168 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 1 << 30;
170 /* SVC mode with interrupts disabled. */
171 env
->uncached_cpsr
= ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
172 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
175 env
->uncached_cpsr
&= ~CPSR_I
;
176 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 0;
177 env
->cp15
.c2_base_mask
= 0xffffc000u
;
183 static int vfp_gdb_get_reg(CPUState
*env
, uint8_t *buf
, int reg
)
187 /* VFP data registers are always little-endian. */
188 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
190 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
193 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
194 /* Aliases for Q regs. */
197 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
198 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
202 switch (reg
- nregs
) {
203 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
204 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
205 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
210 static int vfp_gdb_set_reg(CPUState
*env
, uint8_t *buf
, int reg
)
214 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
216 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
219 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
222 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
223 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
227 switch (reg
- nregs
) {
228 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
229 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
230 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
); return 4;
235 CPUARMState
*cpu_arm_init(const char *cpu_model
)
239 static int inited
= 0;
241 id
= cpu_arm_find_by_name(cpu_model
);
244 env
= qemu_mallocz(sizeof(CPUARMState
));
250 arm_translate_init();
253 env
->cpu_model_str
= cpu_model
;
254 env
->cp15
.c0_cpuid
= id
;
256 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
257 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
258 51, "arm-neon.xml", 0);
259 } else if (arm_feature(env
, ARM_FEATURE_VFP3
)) {
260 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
261 35, "arm-vfp3.xml", 0);
262 } else if (arm_feature(env
, ARM_FEATURE_VFP
)) {
263 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
264 19, "arm-vfp.xml", 0);
274 static const struct arm_cpu_t arm_cpu_names
[] = {
275 { ARM_CPUID_ARM926
, "arm926"},
276 { ARM_CPUID_ARM946
, "arm946"},
277 { ARM_CPUID_ARM1026
, "arm1026"},
278 { ARM_CPUID_ARM1136
, "arm1136"},
279 { ARM_CPUID_ARM1136_R2
, "arm1136-r2"},
280 { ARM_CPUID_ARM11MPCORE
, "arm11mpcore"},
281 { ARM_CPUID_CORTEXM3
, "cortex-m3"},
282 { ARM_CPUID_CORTEXA8
, "cortex-a8"},
283 { ARM_CPUID_TI925T
, "ti925t" },
284 { ARM_CPUID_PXA250
, "pxa250" },
285 { ARM_CPUID_PXA255
, "pxa255" },
286 { ARM_CPUID_PXA260
, "pxa260" },
287 { ARM_CPUID_PXA261
, "pxa261" },
288 { ARM_CPUID_PXA262
, "pxa262" },
289 { ARM_CPUID_PXA270
, "pxa270" },
290 { ARM_CPUID_PXA270_A0
, "pxa270-a0" },
291 { ARM_CPUID_PXA270_A1
, "pxa270-a1" },
292 { ARM_CPUID_PXA270_B0
, "pxa270-b0" },
293 { ARM_CPUID_PXA270_B1
, "pxa270-b1" },
294 { ARM_CPUID_PXA270_C0
, "pxa270-c0" },
295 { ARM_CPUID_PXA270_C5
, "pxa270-c5" },
296 { ARM_CPUID_ANY
, "any"},
300 void arm_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
304 (*cpu_fprintf
)(f
, "Available CPUs:\n");
305 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
306 (*cpu_fprintf
)(f
, " %s\n", arm_cpu_names
[i
].name
);
310 /* return 0 if not found */
311 static uint32_t cpu_arm_find_by_name(const char *name
)
317 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
318 if (strcmp(name
, arm_cpu_names
[i
].name
) == 0) {
319 id
= arm_cpu_names
[i
].id
;
326 void cpu_arm_close(CPUARMState
*env
)
331 uint32_t cpsr_read(CPUARMState
*env
)
335 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
336 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
337 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
338 | ((env
->condexec_bits
& 0xfc) << 8)
342 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
)
344 if (mask
& CPSR_NZCV
) {
345 env
->ZF
= (~val
) & CPSR_Z
;
347 env
->CF
= (val
>> 29) & 1;
348 env
->VF
= (val
<< 3) & 0x80000000;
351 env
->QF
= ((val
& CPSR_Q
) != 0);
353 env
->thumb
= ((val
& CPSR_T
) != 0);
354 if (mask
& CPSR_IT_0_1
) {
355 env
->condexec_bits
&= ~3;
356 env
->condexec_bits
|= (val
>> 25) & 3;
358 if (mask
& CPSR_IT_2_7
) {
359 env
->condexec_bits
&= 3;
360 env
->condexec_bits
|= (val
>> 8) & 0xfc;
362 if (mask
& CPSR_GE
) {
363 env
->GE
= (val
>> 16) & 0xf;
366 if ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
) {
367 switch_mode(env
, val
& CPSR_M
);
369 mask
&= ~CACHED_CPSR_BITS
;
370 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
373 /* Sign/zero extend */
374 uint32_t HELPER(sxtb16
)(uint32_t x
)
377 res
= (uint16_t)(int8_t)x
;
378 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
382 uint32_t HELPER(uxtb16
)(uint32_t x
)
385 res
= (uint16_t)(uint8_t)x
;
386 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
390 uint32_t HELPER(clz
)(uint32_t x
)
393 for (count
= 32; x
; count
--)
398 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
405 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
412 uint32_t HELPER(rbit
)(uint32_t x
)
414 x
= ((x
& 0xff000000) >> 24)
415 | ((x
& 0x00ff0000) >> 8)
416 | ((x
& 0x0000ff00) << 8)
417 | ((x
& 0x000000ff) << 24);
418 x
= ((x
& 0xf0f0f0f0) >> 4)
419 | ((x
& 0x0f0f0f0f) << 4);
420 x
= ((x
& 0x88888888) >> 3)
421 | ((x
& 0x44444444) >> 1)
422 | ((x
& 0x22222222) << 1)
423 | ((x
& 0x11111111) << 3);
427 uint32_t HELPER(abs
)(uint32_t x
)
429 return ((int32_t)x
< 0) ? -x
: x
;
432 #if defined(CONFIG_USER_ONLY)
434 void do_interrupt (CPUState
*env
)
436 env
->exception_index
= -1;
439 /* Structure used to record exclusive memory locations. */
440 typedef struct mmon_state
{
441 struct mmon_state
*next
;
442 CPUARMState
*cpu_env
;
446 /* Chain of current locks. */
447 static mmon_state
* mmon_head
= NULL
;
449 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
450 int mmu_idx
, int is_softmmu
)
453 env
->exception_index
= EXCP_PREFETCH_ABORT
;
454 env
->cp15
.c6_insn
= address
;
456 env
->exception_index
= EXCP_DATA_ABORT
;
457 env
->cp15
.c6_data
= address
;
462 static void allocate_mmon_state(CPUState
*env
)
464 env
->mmon_entry
= malloc(sizeof (mmon_state
));
465 if (!env
->mmon_entry
)
467 memset (env
->mmon_entry
, 0, sizeof (mmon_state
));
468 env
->mmon_entry
->cpu_env
= env
;
469 mmon_head
= env
->mmon_entry
;
472 /* Flush any monitor locks for the specified address. */
473 static void flush_mmon(uint32_t addr
)
477 for (mon
= mmon_head
; mon
; mon
= mon
->next
)
479 if (mon
->addr
!= addr
)
487 /* Mark an address for exclusive access. */
488 void HELPER(mark_exclusive
)(CPUState
*env
, uint32_t addr
)
490 if (!env
->mmon_entry
)
491 allocate_mmon_state(env
);
492 /* Clear any previous locks. */
494 env
->mmon_entry
->addr
= addr
;
497 /* Test if an exclusive address is still exclusive. Returns zero
498 if the address is still exclusive. */
499 uint32_t HELPER(test_exclusive
)(CPUState
*env
, uint32_t addr
)
503 if (!env
->mmon_entry
)
505 if (env
->mmon_entry
->addr
== addr
)
513 void HELPER(clrex
)(CPUState
*env
)
515 if (!(env
->mmon_entry
&& env
->mmon_entry
->addr
))
517 flush_mmon(env
->mmon_entry
->addr
);
520 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
525 /* These should probably raise undefined insn exceptions. */
526 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
528 int op1
= (insn
>> 8) & 0xf;
529 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
533 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
535 int op1
= (insn
>> 8) & 0xf;
536 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
540 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
542 cpu_abort(env
, "cp15 insn %08x\n", insn
);
545 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
547 cpu_abort(env
, "cp15 insn %08x\n", insn
);
551 /* These should probably raise undefined insn exceptions. */
552 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
554 cpu_abort(env
, "v7m_mrs %d\n", reg
);
557 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
559 cpu_abort(env
, "v7m_mrs %d\n", reg
);
563 void switch_mode(CPUState
*env
, int mode
)
565 if (mode
!= ARM_CPU_MODE_USR
)
566 cpu_abort(env
, "Tried to switch out of user mode\n");
569 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
571 cpu_abort(env
, "banked r13 write\n");
574 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
576 cpu_abort(env
, "banked r13 read\n");
582 extern int semihosting_enabled
;
584 /* Map CPU modes onto saved register banks. */
585 static inline int bank_number (int mode
)
588 case ARM_CPU_MODE_USR
:
589 case ARM_CPU_MODE_SYS
:
591 case ARM_CPU_MODE_SVC
:
593 case ARM_CPU_MODE_ABT
:
595 case ARM_CPU_MODE_UND
:
597 case ARM_CPU_MODE_IRQ
:
599 case ARM_CPU_MODE_FIQ
:
602 cpu_abort(cpu_single_env
, "Bad mode %x\n", mode
);
606 void switch_mode(CPUState
*env
, int mode
)
611 old_mode
= env
->uncached_cpsr
& CPSR_M
;
612 if (mode
== old_mode
)
615 if (old_mode
== ARM_CPU_MODE_FIQ
) {
616 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
617 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
618 } else if (mode
== ARM_CPU_MODE_FIQ
) {
619 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
620 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
623 i
= bank_number(old_mode
);
624 env
->banked_r13
[i
] = env
->regs
[13];
625 env
->banked_r14
[i
] = env
->regs
[14];
626 env
->banked_spsr
[i
] = env
->spsr
;
628 i
= bank_number(mode
);
629 env
->regs
[13] = env
->banked_r13
[i
];
630 env
->regs
[14] = env
->banked_r14
[i
];
631 env
->spsr
= env
->banked_spsr
[i
];
634 static void v7m_push(CPUARMState
*env
, uint32_t val
)
637 stl_phys(env
->regs
[13], val
);
640 static uint32_t v7m_pop(CPUARMState
*env
)
643 val
= ldl_phys(env
->regs
[13]);
648 /* Switch to V7M main or process stack pointer. */
649 static void switch_v7m_sp(CPUARMState
*env
, int process
)
652 if (env
->v7m
.current_sp
!= process
) {
653 tmp
= env
->v7m
.other_sp
;
654 env
->v7m
.other_sp
= env
->regs
[13];
656 env
->v7m
.current_sp
= process
;
660 static void do_v7m_exception_exit(CPUARMState
*env
)
665 type
= env
->regs
[15];
666 if (env
->v7m
.exception
!= 0)
667 armv7m_nvic_complete_irq(env
->v7m
.nvic
, env
->v7m
.exception
);
669 /* Switch to the target stack. */
670 switch_v7m_sp(env
, (type
& 4) != 0);
672 env
->regs
[0] = v7m_pop(env
);
673 env
->regs
[1] = v7m_pop(env
);
674 env
->regs
[2] = v7m_pop(env
);
675 env
->regs
[3] = v7m_pop(env
);
676 env
->regs
[12] = v7m_pop(env
);
677 env
->regs
[14] = v7m_pop(env
);
678 env
->regs
[15] = v7m_pop(env
);
680 xpsr_write(env
, xpsr
, 0xfffffdff);
681 /* Undo stack alignment. */
684 /* ??? The exception return type specifies Thread/Handler mode. However
685 this is also implied by the xPSR value. Not sure what to do
686 if there is a mismatch. */
687 /* ??? Likewise for mismatches between the CONTROL register and the stack
691 void do_interrupt_v7m(CPUARMState
*env
)
693 uint32_t xpsr
= xpsr_read(env
);
698 if (env
->v7m
.current_sp
)
700 if (env
->v7m
.exception
== 0)
703 /* For exceptions we just mark as pending on the NVIC, and let that
705 /* TODO: Need to escalate if the current priority is higher than the
706 one we're raising. */
707 switch (env
->exception_index
) {
709 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_USAGE
);
713 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_SVC
);
715 case EXCP_PREFETCH_ABORT
:
716 case EXCP_DATA_ABORT
:
717 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_MEM
);
720 if (semihosting_enabled
) {
722 nr
= lduw_code(env
->regs
[15]) & 0xff;
725 env
->regs
[0] = do_arm_semihosting(env
);
729 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_DEBUG
);
732 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->v7m
.nvic
);
734 case EXCP_EXCEPTION_EXIT
:
735 do_v7m_exception_exit(env
);
738 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
739 return; /* Never happens. Keep compiler happy. */
742 /* Align stack pointer. */
743 /* ??? Should only do this if Configuration Control Register
744 STACKALIGN bit is set. */
745 if (env
->regs
[13] & 4) {
749 /* Switch to the handler mode. */
751 v7m_push(env
, env
->regs
[15]);
752 v7m_push(env
, env
->regs
[14]);
753 v7m_push(env
, env
->regs
[12]);
754 v7m_push(env
, env
->regs
[3]);
755 v7m_push(env
, env
->regs
[2]);
756 v7m_push(env
, env
->regs
[1]);
757 v7m_push(env
, env
->regs
[0]);
758 switch_v7m_sp(env
, 0);
759 env
->uncached_cpsr
&= ~CPSR_IT
;
761 addr
= ldl_phys(env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
762 env
->regs
[15] = addr
& 0xfffffffe;
763 env
->thumb
= addr
& 1;
766 /* Handle a CPU exception. */
767 void do_interrupt(CPUARMState
*env
)
775 do_interrupt_v7m(env
);
778 /* TODO: Vectored interrupt controller. */
779 switch (env
->exception_index
) {
781 new_mode
= ARM_CPU_MODE_UND
;
790 if (semihosting_enabled
) {
791 /* Check for semihosting interrupt. */
793 mask
= lduw_code(env
->regs
[15] - 2) & 0xff;
795 mask
= ldl_code(env
->regs
[15] - 4) & 0xffffff;
797 /* Only intercept calls from privileged modes, to provide some
798 semblance of security. */
799 if (((mask
== 0x123456 && !env
->thumb
)
800 || (mask
== 0xab && env
->thumb
))
801 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
802 env
->regs
[0] = do_arm_semihosting(env
);
806 new_mode
= ARM_CPU_MODE_SVC
;
809 /* The PC already points to the next instruction. */
813 /* See if this is a semihosting syscall. */
814 if (env
->thumb
&& semihosting_enabled
) {
815 mask
= lduw_code(env
->regs
[15]) & 0xff;
817 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
819 env
->regs
[0] = do_arm_semihosting(env
);
823 /* Fall through to prefetch abort. */
824 case EXCP_PREFETCH_ABORT
:
825 new_mode
= ARM_CPU_MODE_ABT
;
827 mask
= CPSR_A
| CPSR_I
;
830 case EXCP_DATA_ABORT
:
831 new_mode
= ARM_CPU_MODE_ABT
;
833 mask
= CPSR_A
| CPSR_I
;
837 new_mode
= ARM_CPU_MODE_IRQ
;
839 /* Disable IRQ and imprecise data aborts. */
840 mask
= CPSR_A
| CPSR_I
;
844 new_mode
= ARM_CPU_MODE_FIQ
;
846 /* Disable FIQ, IRQ and imprecise data aborts. */
847 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
851 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
852 return; /* Never happens. Keep compiler happy. */
855 if (env
->cp15
.c1_sys
& (1 << 13)) {
858 switch_mode (env
, new_mode
);
859 env
->spsr
= cpsr_read(env
);
861 env
->condexec_bits
= 0;
862 /* Switch to the new mode, and switch to Arm mode. */
863 /* ??? Thumb interrupt handlers not implemented. */
864 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
865 env
->uncached_cpsr
|= mask
;
867 env
->regs
[14] = env
->regs
[15] + offset
;
868 env
->regs
[15] = addr
;
869 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
872 /* Check section/page access permissions.
873 Returns the page protection flags, or zero if the access is not
875 static inline int check_ap(CPUState
*env
, int ap
, int domain
, int access_type
,
881 return PAGE_READ
| PAGE_WRITE
;
883 if (access_type
== 1)
890 if (access_type
== 1)
892 switch ((env
->cp15
.c1_sys
>> 8) & 3) {
894 return is_user
? 0 : PAGE_READ
;
901 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
906 return PAGE_READ
| PAGE_WRITE
;
908 return PAGE_READ
| PAGE_WRITE
;
909 case 4: /* Reserved. */
912 return is_user
? 0 : prot_ro
;
916 if (!arm_feature (env
, ARM_FEATURE_V7
))
924 static uint32_t get_level1_table_address(CPUState
*env
, uint32_t address
)
928 if (address
& env
->cp15
.c2_mask
)
929 table
= env
->cp15
.c2_base1
& 0xffffc000;
931 table
= env
->cp15
.c2_base0
& env
->cp15
.c2_base_mask
;
933 table
|= (address
>> 18) & 0x3ffc;
937 static int get_phys_addr_v5(CPUState
*env
, uint32_t address
, int access_type
,
938 int is_user
, uint32_t *phys_ptr
, int *prot
)
948 /* Pagetable walk. */
949 /* Lookup l1 descriptor. */
950 table
= get_level1_table_address(env
, address
);
951 desc
= ldl_phys(table
);
953 domain
= (env
->cp15
.c3
>> ((desc
>> 4) & 0x1e)) & 3;
955 /* Section translation fault. */
959 if (domain
== 0 || domain
== 2) {
961 code
= 9; /* Section domain fault. */
963 code
= 11; /* Page domain fault. */
968 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
969 ap
= (desc
>> 10) & 3;
972 /* Lookup l2 entry. */
974 /* Coarse pagetable. */
975 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
977 /* Fine pagetable. */
978 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
980 desc
= ldl_phys(table
);
982 case 0: /* Page translation fault. */
985 case 1: /* 64k page. */
986 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
987 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
989 case 2: /* 4k page. */
990 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
991 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
993 case 3: /* 1k page. */
995 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
996 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
998 /* Page translation fault. */
1003 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
1005 ap
= (desc
>> 4) & 3;
1008 /* Never happens, but compiler isn't smart enough to tell. */
1013 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1015 /* Access permission fault. */
1018 *phys_ptr
= phys_addr
;
1021 return code
| (domain
<< 4);
1024 static int get_phys_addr_v6(CPUState
*env
, uint32_t address
, int access_type
,
1025 int is_user
, uint32_t *phys_ptr
, int *prot
)
1036 /* Pagetable walk. */
1037 /* Lookup l1 descriptor. */
1038 table
= get_level1_table_address(env
, address
);
1039 desc
= ldl_phys(table
);
1042 /* Section translation fault. */
1046 } else if (type
== 2 && (desc
& (1 << 18))) {
1050 /* Section or page. */
1051 domain
= (desc
>> 4) & 0x1e;
1053 domain
= (env
->cp15
.c3
>> domain
) & 3;
1054 if (domain
== 0 || domain
== 2) {
1056 code
= 9; /* Section domain fault. */
1058 code
= 11; /* Page domain fault. */
1062 if (desc
& (1 << 18)) {
1064 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
1067 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
1069 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
1070 xn
= desc
& (1 << 4);
1073 /* Lookup l2 entry. */
1074 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
1075 desc
= ldl_phys(table
);
1076 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
1078 case 0: /* Page translation fault. */
1081 case 1: /* 64k page. */
1082 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
1083 xn
= desc
& (1 << 15);
1085 case 2: case 3: /* 4k page. */
1086 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
1090 /* Never happens, but compiler isn't smart enough to tell. */
1095 if (xn
&& access_type
== 2)
1098 /* The simplified model uses AP[0] as an access control bit. */
1099 if ((env
->cp15
.c1_sys
& (1 << 29)) && (ap
& 1) == 0) {
1100 /* Access flag fault. */
1101 code
= (code
== 15) ? 6 : 3;
1104 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1106 /* Access permission fault. */
1109 *phys_ptr
= phys_addr
;
1112 return code
| (domain
<< 4);
1115 static int get_phys_addr_mpu(CPUState
*env
, uint32_t address
, int access_type
,
1116 int is_user
, uint32_t *phys_ptr
, int *prot
)
1122 *phys_ptr
= address
;
1123 for (n
= 7; n
>= 0; n
--) {
1124 base
= env
->cp15
.c6_region
[n
];
1125 if ((base
& 1) == 0)
1127 mask
= 1 << ((base
>> 1) & 0x1f);
1128 /* Keep this shift separate from the above to avoid an
1129 (undefined) << 32. */
1130 mask
= (mask
<< 1) - 1;
1131 if (((base
^ address
) & ~mask
) == 0)
1137 if (access_type
== 2) {
1138 mask
= env
->cp15
.c5_insn
;
1140 mask
= env
->cp15
.c5_data
;
1142 mask
= (mask
>> (n
* 4)) & 0xf;
1149 *prot
= PAGE_READ
| PAGE_WRITE
;
1154 *prot
|= PAGE_WRITE
;
1157 *prot
= PAGE_READ
| PAGE_WRITE
;
1168 /* Bad permission. */
1174 static inline int get_phys_addr(CPUState
*env
, uint32_t address
,
1175 int access_type
, int is_user
,
1176 uint32_t *phys_ptr
, int *prot
)
1178 /* Fast Context Switch Extension. */
1179 if (address
< 0x02000000)
1180 address
+= env
->cp15
.c13_fcse
;
1182 if ((env
->cp15
.c1_sys
& 1) == 0) {
1183 /* MMU/MPU disabled. */
1184 *phys_ptr
= address
;
1185 *prot
= PAGE_READ
| PAGE_WRITE
;
1187 } else if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1188 return get_phys_addr_mpu(env
, address
, access_type
, is_user
, phys_ptr
,
1190 } else if (env
->cp15
.c1_sys
& (1 << 23)) {
1191 return get_phys_addr_v6(env
, address
, access_type
, is_user
, phys_ptr
,
1194 return get_phys_addr_v5(env
, address
, access_type
, is_user
, phys_ptr
,
1199 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
,
1200 int access_type
, int mmu_idx
, int is_softmmu
)
1206 is_user
= mmu_idx
== MMU_USER_IDX
;
1207 ret
= get_phys_addr(env
, address
, access_type
, is_user
, &phys_addr
, &prot
);
1209 /* Map a single [sub]page. */
1210 phys_addr
&= ~(uint32_t)0x3ff;
1211 address
&= ~(uint32_t)0x3ff;
1212 return tlb_set_page (env
, address
, phys_addr
, prot
, mmu_idx
,
1216 if (access_type
== 2) {
1217 env
->cp15
.c5_insn
= ret
;
1218 env
->cp15
.c6_insn
= address
;
1219 env
->exception_index
= EXCP_PREFETCH_ABORT
;
1221 env
->cp15
.c5_data
= ret
;
1222 if (access_type
== 1 && arm_feature(env
, ARM_FEATURE_V6
))
1223 env
->cp15
.c5_data
|= (1 << 11);
1224 env
->cp15
.c6_data
= address
;
1225 env
->exception_index
= EXCP_DATA_ABORT
;
1230 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
1236 ret
= get_phys_addr(env
, addr
, 0, 0, &phys_addr
, &prot
);
1244 /* Not really implemented. Need to figure out a sane way of doing this.
1245 Maybe add generic watchpoint support and use that. */
1247 void HELPER(mark_exclusive
)(CPUState
*env
, uint32_t addr
)
1249 env
->mmon_addr
= addr
;
1252 uint32_t HELPER(test_exclusive
)(CPUState
*env
, uint32_t addr
)
1254 return (env
->mmon_addr
!= addr
);
1257 void HELPER(clrex
)(CPUState
*env
)
1259 env
->mmon_addr
= -1;
1262 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1264 int cp_num
= (insn
>> 8) & 0xf;
1265 int cp_info
= (insn
>> 5) & 7;
1266 int src
= (insn
>> 16) & 0xf;
1267 int operand
= insn
& 0xf;
1269 if (env
->cp
[cp_num
].cp_write
)
1270 env
->cp
[cp_num
].cp_write(env
->cp
[cp_num
].opaque
,
1271 cp_info
, src
, operand
, val
);
1274 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
1276 int cp_num
= (insn
>> 8) & 0xf;
1277 int cp_info
= (insn
>> 5) & 7;
1278 int dest
= (insn
>> 16) & 0xf;
1279 int operand
= insn
& 0xf;
1281 if (env
->cp
[cp_num
].cp_read
)
1282 return env
->cp
[cp_num
].cp_read(env
->cp
[cp_num
].opaque
,
1283 cp_info
, dest
, operand
);
1287 /* Return basic MPU access permission bits. */
1288 static uint32_t simple_mpu_ap_bits(uint32_t val
)
1295 for (i
= 0; i
< 16; i
+= 2) {
1296 ret
|= (val
>> i
) & mask
;
1302 /* Pad basic MPU access permission bits to extended format. */
1303 static uint32_t extended_mpu_ap_bits(uint32_t val
)
1310 for (i
= 0; i
< 16; i
+= 2) {
1311 ret
|= (val
& mask
) << i
;
1317 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1323 op1
= (insn
>> 21) & 7;
1324 op2
= (insn
>> 5) & 7;
1326 switch ((insn
>> 16) & 0xf) {
1329 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1331 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1333 if (arm_feature(env
, ARM_FEATURE_V7
)
1334 && op1
== 2 && crm
== 0 && op2
== 0) {
1335 env
->cp15
.c0_cssel
= val
& 0xf;
1339 case 1: /* System configuration. */
1340 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1344 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) || crm
== 0)
1345 env
->cp15
.c1_sys
= val
;
1346 /* ??? Lots of these bits are not implemented. */
1347 /* This may enable/disable the MMU, so do a TLB flush. */
1350 case 1: /* Auxiliary cotrol register. */
1351 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1352 env
->cp15
.c1_xscaleauxcr
= val
;
1355 /* Not implemented. */
1358 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1360 if (env
->cp15
.c1_coproc
!= val
) {
1361 env
->cp15
.c1_coproc
= val
;
1362 /* ??? Is this safe when called from within a TB? */
1370 case 2: /* MMU Page table control / MPU cache control. */
1371 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1374 env
->cp15
.c2_data
= val
;
1377 env
->cp15
.c2_insn
= val
;
1385 env
->cp15
.c2_base0
= val
;
1388 env
->cp15
.c2_base1
= val
;
1392 env
->cp15
.c2_control
= val
;
1393 env
->cp15
.c2_mask
= ~(((uint32_t)0xffffffffu
) >> val
);
1394 env
->cp15
.c2_base_mask
= ~((uint32_t)0x3fffu
>> val
);
1401 case 3: /* MMU Domain access control / MPU write buffer control. */
1403 tlb_flush(env
, 1); /* Flush TLB as domain not tracked in TLB */
1405 case 4: /* Reserved. */
1407 case 5: /* MMU Fault status / MPU access permission. */
1408 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1412 if (arm_feature(env
, ARM_FEATURE_MPU
))
1413 val
= extended_mpu_ap_bits(val
);
1414 env
->cp15
.c5_data
= val
;
1417 if (arm_feature(env
, ARM_FEATURE_MPU
))
1418 val
= extended_mpu_ap_bits(val
);
1419 env
->cp15
.c5_insn
= val
;
1422 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1424 env
->cp15
.c5_data
= val
;
1427 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1429 env
->cp15
.c5_insn
= val
;
1435 case 6: /* MMU Fault address / MPU base/size. */
1436 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1439 env
->cp15
.c6_region
[crm
] = val
;
1441 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1445 env
->cp15
.c6_data
= val
;
1447 case 1: /* ??? This is WFAR on armv6 */
1449 env
->cp15
.c6_insn
= val
;
1456 case 7: /* Cache control. */
1457 env
->cp15
.c15_i_max
= 0x000;
1458 env
->cp15
.c15_i_min
= 0xff0;
1459 /* No cache, so nothing to do. */
1460 /* ??? MPCore has VA to PA translation functions. */
1462 case 8: /* MMU TLB control. */
1464 case 0: /* Invalidate all. */
1467 case 1: /* Invalidate single TLB entry. */
1469 /* ??? This is wrong for large pages and sections. */
1470 /* As an ugly hack to make linux work we always flush a 4K
1473 tlb_flush_page(env
, val
);
1474 tlb_flush_page(env
, val
+ 0x400);
1475 tlb_flush_page(env
, val
+ 0x800);
1476 tlb_flush_page(env
, val
+ 0xc00);
1481 case 2: /* Invalidate on ASID. */
1482 tlb_flush(env
, val
== 0);
1484 case 3: /* Invalidate single entry on MVA. */
1485 /* ??? This is like case 1, but ignores ASID. */
1493 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1496 case 0: /* Cache lockdown. */
1498 case 0: /* L1 cache. */
1501 env
->cp15
.c9_data
= val
;
1504 env
->cp15
.c9_insn
= val
;
1510 case 1: /* L2 cache. */
1511 /* Ignore writes to L2 lockdown/auxiliary registers. */
1517 case 1: /* TCM memory region registers. */
1518 /* Not implemented. */
1524 case 10: /* MMU TLB lockdown. */
1525 /* ??? TLB lockdown not implemented. */
1527 case 12: /* Reserved. */
1529 case 13: /* Process ID. */
1532 /* Unlike real hardware the qemu TLB uses virtual addresses,
1533 not modified virtual addresses, so this causes a TLB flush.
1535 if (env
->cp15
.c13_fcse
!= val
)
1537 env
->cp15
.c13_fcse
= val
;
1540 /* This changes the ASID, so do a TLB flush. */
1541 if (env
->cp15
.c13_context
!= val
1542 && !arm_feature(env
, ARM_FEATURE_MPU
))
1544 env
->cp15
.c13_context
= val
;
1547 env
->cp15
.c13_tls1
= val
;
1550 env
->cp15
.c13_tls2
= val
;
1553 env
->cp15
.c13_tls3
= val
;
1559 case 14: /* Reserved. */
1561 case 15: /* Implementation specific. */
1562 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1563 if (op2
== 0 && crm
== 1) {
1564 if (env
->cp15
.c15_cpar
!= (val
& 0x3fff)) {
1565 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
1567 env
->cp15
.c15_cpar
= val
& 0x3fff;
1573 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1577 case 1: /* Set TI925T configuration. */
1578 env
->cp15
.c15_ticonfig
= val
& 0xe7;
1579 env
->cp15
.c0_cpuid
= (val
& (1 << 5)) ? /* OS_TYPE bit */
1580 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
1582 case 2: /* Set I_max. */
1583 env
->cp15
.c15_i_max
= val
;
1585 case 3: /* Set I_min. */
1586 env
->cp15
.c15_i_min
= val
;
1588 case 4: /* Set thread-ID. */
1589 env
->cp15
.c15_threadid
= val
& 0xffff;
1591 case 8: /* Wait-for-interrupt (deprecated). */
1592 cpu_interrupt(env
, CPU_INTERRUPT_HALT
);
1602 /* ??? For debugging only. Should raise illegal instruction exception. */
1603 cpu_abort(env
, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1604 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1607 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
1613 op1
= (insn
>> 21) & 7;
1614 op2
= (insn
>> 5) & 7;
1616 switch ((insn
>> 16) & 0xf) {
1617 case 0: /* ID codes. */
1623 case 0: /* Device ID. */
1624 return env
->cp15
.c0_cpuid
;
1625 case 1: /* Cache Type. */
1626 return env
->cp15
.c0_cachetype
;
1627 case 2: /* TCM status. */
1629 case 3: /* TLB type register. */
1630 return 0; /* No lockable TLB entries. */
1631 case 5: /* CPU ID */
1632 return env
->cpu_index
;
1637 if (!arm_feature(env
, ARM_FEATURE_V6
))
1639 return env
->cp15
.c0_c1
[op2
];
1641 if (!arm_feature(env
, ARM_FEATURE_V6
))
1643 return env
->cp15
.c0_c2
[op2
];
1644 case 3: case 4: case 5: case 6: case 7:
1650 /* These registers aren't documented on arm11 cores. However
1651 Linux looks at them anyway. */
1652 if (!arm_feature(env
, ARM_FEATURE_V6
))
1656 if (!arm_feature(env
, ARM_FEATURE_V7
))
1661 return env
->cp15
.c0_ccsid
[env
->cp15
.c0_cssel
];
1663 return env
->cp15
.c0_clid
;
1669 if (op2
!= 0 || crm
!= 0)
1671 return env
->cp15
.c0_cssel
;
1675 case 1: /* System configuration. */
1676 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1679 case 0: /* Control register. */
1680 return env
->cp15
.c1_sys
;
1681 case 1: /* Auxiliary control register. */
1682 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1683 return env
->cp15
.c1_xscaleauxcr
;
1684 if (!arm_feature(env
, ARM_FEATURE_AUXCR
))
1686 switch (ARM_CPUID(env
)) {
1687 case ARM_CPUID_ARM1026
:
1689 case ARM_CPUID_ARM1136
:
1690 case ARM_CPUID_ARM1136_R2
:
1692 case ARM_CPUID_ARM11MPCORE
:
1694 case ARM_CPUID_CORTEXA8
:
1699 case 2: /* Coprocessor access register. */
1700 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1702 return env
->cp15
.c1_coproc
;
1706 case 2: /* MMU Page table control / MPU cache control. */
1707 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1710 return env
->cp15
.c2_data
;
1713 return env
->cp15
.c2_insn
;
1721 return env
->cp15
.c2_base0
;
1723 return env
->cp15
.c2_base1
;
1725 return env
->cp15
.c2_control
;
1730 case 3: /* MMU Domain access control / MPU write buffer control. */
1731 return env
->cp15
.c3
;
1732 case 4: /* Reserved. */
1734 case 5: /* MMU Fault status / MPU access permission. */
1735 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1739 if (arm_feature(env
, ARM_FEATURE_MPU
))
1740 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1741 return env
->cp15
.c5_data
;
1743 if (arm_feature(env
, ARM_FEATURE_MPU
))
1744 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1745 return env
->cp15
.c5_insn
;
1747 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1749 return env
->cp15
.c5_data
;
1751 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1753 return env
->cp15
.c5_insn
;
1757 case 6: /* MMU Fault address. */
1758 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1761 return env
->cp15
.c6_region
[crm
];
1763 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1767 return env
->cp15
.c6_data
;
1769 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1770 /* Watchpoint Fault Adrress. */
1771 return 0; /* Not implemented. */
1773 /* Instruction Fault Adrress. */
1774 /* Arm9 doesn't have an IFAR, but implementing it anyway
1775 shouldn't do any harm. */
1776 return env
->cp15
.c6_insn
;
1779 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1780 /* Instruction Fault Adrress. */
1781 return env
->cp15
.c6_insn
;
1789 case 7: /* Cache control. */
1790 /* FIXME: Should only clear Z flag if destination is r15. */
1793 case 8: /* MMU TLB control. */
1795 case 9: /* Cache lockdown. */
1797 case 0: /* L1 cache. */
1798 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1802 return env
->cp15
.c9_data
;
1804 return env
->cp15
.c9_insn
;
1808 case 1: /* L2 cache */
1811 /* L2 Lockdown and Auxiliary control. */
1816 case 10: /* MMU TLB lockdown. */
1817 /* ??? TLB lockdown not implemented. */
1819 case 11: /* TCM DMA control. */
1820 case 12: /* Reserved. */
1822 case 13: /* Process ID. */
1825 return env
->cp15
.c13_fcse
;
1827 return env
->cp15
.c13_context
;
1829 return env
->cp15
.c13_tls1
;
1831 return env
->cp15
.c13_tls2
;
1833 return env
->cp15
.c13_tls3
;
1837 case 14: /* Reserved. */
1839 case 15: /* Implementation specific. */
1840 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1841 if (op2
== 0 && crm
== 1)
1842 return env
->cp15
.c15_cpar
;
1846 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1850 case 1: /* Read TI925T configuration. */
1851 return env
->cp15
.c15_ticonfig
;
1852 case 2: /* Read I_max. */
1853 return env
->cp15
.c15_i_max
;
1854 case 3: /* Read I_min. */
1855 return env
->cp15
.c15_i_min
;
1856 case 4: /* Read thread-ID. */
1857 return env
->cp15
.c15_threadid
;
1858 case 8: /* TI925T_status */
1861 /* TODO: Peripheral port remap register:
1862 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt
1863 * controller base address at $rn & ~0xfff and map size of
1864 * 0x200 << ($rn & 0xfff), when MMU is off. */
1870 /* ??? For debugging only. Should raise illegal instruction exception. */
1871 cpu_abort(env
, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
1872 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1876 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
1878 env
->banked_r13
[bank_number(mode
)] = val
;
1881 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
1883 return env
->banked_r13
[bank_number(mode
)];
1886 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
1890 return xpsr_read(env
) & 0xf8000000;
1892 return xpsr_read(env
) & 0xf80001ff;
1894 return xpsr_read(env
) & 0xff00fc00;
1896 return xpsr_read(env
) & 0xff00fdff;
1898 return xpsr_read(env
) & 0x000001ff;
1900 return xpsr_read(env
) & 0x0700fc00;
1902 return xpsr_read(env
) & 0x0700edff;
1904 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
1906 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
1907 case 16: /* PRIMASK */
1908 return (env
->uncached_cpsr
& CPSR_I
) != 0;
1909 case 17: /* FAULTMASK */
1910 return (env
->uncached_cpsr
& CPSR_F
) != 0;
1911 case 18: /* BASEPRI */
1912 case 19: /* BASEPRI_MAX */
1913 return env
->v7m
.basepri
;
1914 case 20: /* CONTROL */
1915 return env
->v7m
.control
;
1917 /* ??? For debugging only. */
1918 cpu_abort(env
, "Unimplemented system register read (%d)\n", reg
);
1923 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
1927 xpsr_write(env
, val
, 0xf8000000);
1930 xpsr_write(env
, val
, 0xf8000000);
1933 xpsr_write(env
, val
, 0xfe00fc00);
1936 xpsr_write(env
, val
, 0xfe00fc00);
1939 /* IPSR bits are readonly. */
1942 xpsr_write(env
, val
, 0x0600fc00);
1945 xpsr_write(env
, val
, 0x0600fc00);
1948 if (env
->v7m
.current_sp
)
1949 env
->v7m
.other_sp
= val
;
1951 env
->regs
[13] = val
;
1954 if (env
->v7m
.current_sp
)
1955 env
->regs
[13] = val
;
1957 env
->v7m
.other_sp
= val
;
1959 case 16: /* PRIMASK */
1961 env
->uncached_cpsr
|= CPSR_I
;
1963 env
->uncached_cpsr
&= ~CPSR_I
;
1965 case 17: /* FAULTMASK */
1967 env
->uncached_cpsr
|= CPSR_F
;
1969 env
->uncached_cpsr
&= ~CPSR_F
;
1971 case 18: /* BASEPRI */
1972 env
->v7m
.basepri
= val
& 0xff;
1974 case 19: /* BASEPRI_MAX */
1976 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
1977 env
->v7m
.basepri
= val
;
1979 case 20: /* CONTROL */
1980 env
->v7m
.control
= val
& 3;
1981 switch_v7m_sp(env
, (val
& 2) != 0);
1984 /* ??? For debugging only. */
1985 cpu_abort(env
, "Unimplemented system register write (%d)\n", reg
);
1990 void cpu_arm_set_cp_io(CPUARMState
*env
, int cpnum
,
1991 ARMReadCPFunc
*cp_read
, ARMWriteCPFunc
*cp_write
,
1994 if (cpnum
< 0 || cpnum
> 14) {
1995 cpu_abort(env
, "Bad coprocessor number: %i\n", cpnum
);
1999 env
->cp
[cpnum
].cp_read
= cp_read
;
2000 env
->cp
[cpnum
].cp_write
= cp_write
;
2001 env
->cp
[cpnum
].opaque
= opaque
;
2006 /* Note that signed overflow is undefined in C. The following routines are
2007 careful to use unsigned types where modulo arithmetic is required.
2008 Failure to do so _will_ break on newer gcc. */
2010 /* Signed saturating arithmetic. */
2012 /* Perform 16-bit signed saturating addition. */
2013 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
2018 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
2027 /* Perform 8-bit signed saturating addition. */
2028 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
2033 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
2042 /* Perform 16-bit signed saturating subtraction. */
2043 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
2048 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
2057 /* Perform 8-bit signed saturating subtraction. */
2058 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
2063 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
2072 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
2073 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
2074 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
2075 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
2078 #include "op_addsub.h"
2080 /* Unsigned saturating arithmetic. */
2081 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
2090 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
2098 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
2107 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
2115 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
2116 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
2117 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
2118 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
2121 #include "op_addsub.h"
2123 /* Signed modulo arithmetic. */
2124 #define SARITH16(a, b, n, op) do { \
2126 sum = (int16_t)((uint16_t)(a) op (uint16_t)(b)); \
2127 RESULT(sum, n, 16); \
2129 ge |= 3 << (n * 2); \
2132 #define SARITH8(a, b, n, op) do { \
2134 sum = (int8_t)((uint8_t)(a) op (uint8_t)(b)); \
2135 RESULT(sum, n, 8); \
2141 #define ADD16(a, b, n) SARITH16(a, b, n, +)
2142 #define SUB16(a, b, n) SARITH16(a, b, n, -)
2143 #define ADD8(a, b, n) SARITH8(a, b, n, +)
2144 #define SUB8(a, b, n) SARITH8(a, b, n, -)
2148 #include "op_addsub.h"
2150 /* Unsigned modulo arithmetic. */
2151 #define ADD16(a, b, n) do { \
2153 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
2154 RESULT(sum, n, 16); \
2155 if ((sum >> 16) == 1) \
2156 ge |= 3 << (n * 2); \
2159 #define ADD8(a, b, n) do { \
2161 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
2162 RESULT(sum, n, 8); \
2163 if ((sum >> 8) == 1) \
2167 #define SUB16(a, b, n) do { \
2169 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
2170 RESULT(sum, n, 16); \
2171 if ((sum >> 16) == 0) \
2172 ge |= 3 << (n * 2); \
2175 #define SUB8(a, b, n) do { \
2177 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
2178 RESULT(sum, n, 8); \
2179 if ((sum >> 8) == 0) \
2186 #include "op_addsub.h"
2188 /* Halved signed arithmetic. */
2189 #define ADD16(a, b, n) \
2190 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
2191 #define SUB16(a, b, n) \
2192 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
2193 #define ADD8(a, b, n) \
2194 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
2195 #define SUB8(a, b, n) \
2196 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
2199 #include "op_addsub.h"
2201 /* Halved unsigned arithmetic. */
2202 #define ADD16(a, b, n) \
2203 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2204 #define SUB16(a, b, n) \
2205 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2206 #define ADD8(a, b, n) \
2207 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2208 #define SUB8(a, b, n) \
2209 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2212 #include "op_addsub.h"
2214 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
2222 /* Unsigned sum of absolute byte differences. */
2223 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
2226 sum
= do_usad(a
, b
);
2227 sum
+= do_usad(a
>> 8, b
>> 8);
2228 sum
+= do_usad(a
>> 16, b
>>16);
2229 sum
+= do_usad(a
>> 24, b
>> 24);
2233 /* For ARMv6 SEL instruction. */
2234 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
2247 return (a
& mask
) | (b
& ~mask
);
2250 uint32_t HELPER(logicq_cc
)(uint64_t val
)
2252 return (val
>> 32) | (val
!= 0);
2255 /* VFP support. We follow the convention used for VFP instrunctions:
2256 Single precition routines have a "s" suffix, double precision a
2259 /* Convert host exception flags to vfp form. */
2260 static inline int vfp_exceptbits_from_host(int host_bits
)
2262 int target_bits
= 0;
2264 if (host_bits
& float_flag_invalid
)
2266 if (host_bits
& float_flag_divbyzero
)
2268 if (host_bits
& float_flag_overflow
)
2270 if (host_bits
& float_flag_underflow
)
2272 if (host_bits
& float_flag_inexact
)
2273 target_bits
|= 0x10;
2277 uint32_t HELPER(vfp_get_fpscr
)(CPUState
*env
)
2282 fpscr
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & 0xffc8ffff)
2283 | (env
->vfp
.vec_len
<< 16)
2284 | (env
->vfp
.vec_stride
<< 20);
2285 i
= get_float_exception_flags(&env
->vfp
.fp_status
);
2286 fpscr
|= vfp_exceptbits_from_host(i
);
2290 /* Convert vfp exception flags to target form. */
2291 static inline int vfp_exceptbits_to_host(int target_bits
)
2295 if (target_bits
& 1)
2296 host_bits
|= float_flag_invalid
;
2297 if (target_bits
& 2)
2298 host_bits
|= float_flag_divbyzero
;
2299 if (target_bits
& 4)
2300 host_bits
|= float_flag_overflow
;
2301 if (target_bits
& 8)
2302 host_bits
|= float_flag_underflow
;
2303 if (target_bits
& 0x10)
2304 host_bits
|= float_flag_inexact
;
2308 void HELPER(vfp_set_fpscr
)(CPUState
*env
, uint32_t val
)
2313 changed
= env
->vfp
.xregs
[ARM_VFP_FPSCR
];
2314 env
->vfp
.xregs
[ARM_VFP_FPSCR
] = (val
& 0xffc8ffff);
2315 env
->vfp
.vec_len
= (val
>> 16) & 7;
2316 env
->vfp
.vec_stride
= (val
>> 20) & 3;
2319 if (changed
& (3 << 22)) {
2320 i
= (val
>> 22) & 3;
2323 i
= float_round_nearest_even
;
2329 i
= float_round_down
;
2332 i
= float_round_to_zero
;
2335 set_float_rounding_mode(i
, &env
->vfp
.fp_status
);
2337 if (changed
& (1 << 24))
2338 set_flush_to_zero((val
& (1 << 24)) != 0, &env
->vfp
.fp_status
);
2339 if (changed
& (1 << 25))
2340 set_default_nan_mode((val
& (1 << 25)) != 0, &env
->vfp
.fp_status
);
2342 i
= vfp_exceptbits_to_host((val
>> 8) & 0x1f);
2343 set_float_exception_flags(i
, &env
->vfp
.fp_status
);
2346 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
2348 #define VFP_BINOP(name) \
2349 float32 VFP_HELPER(name, s)(float32 a, float32 b, CPUState *env) \
2351 return float32_ ## name (a, b, &env->vfp.fp_status); \
2353 float64 VFP_HELPER(name, d)(float64 a, float64 b, CPUState *env) \
2355 return float64_ ## name (a, b, &env->vfp.fp_status); \
2363 float32
VFP_HELPER(neg
, s
)(float32 a
)
2365 return float32_chs(a
);
2368 float64
VFP_HELPER(neg
, d
)(float64 a
)
2370 return float64_chs(a
);
2373 float32
VFP_HELPER(abs
, s
)(float32 a
)
2375 return float32_abs(a
);
2378 float64
VFP_HELPER(abs
, d
)(float64 a
)
2380 return float64_abs(a
);
2383 float32
VFP_HELPER(sqrt
, s
)(float32 a
, CPUState
*env
)
2385 return float32_sqrt(a
, &env
->vfp
.fp_status
);
2388 float64
VFP_HELPER(sqrt
, d
)(float64 a
, CPUState
*env
)
2390 return float64_sqrt(a
, &env
->vfp
.fp_status
);
2393 /* XXX: check quiet/signaling case */
2394 #define DO_VFP_cmp(p, type) \
2395 void VFP_HELPER(cmp, p)(type a, type b, CPUState *env) \
2398 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
2399 case 0: flags = 0x6; break; \
2400 case -1: flags = 0x8; break; \
2401 case 1: flags = 0x2; break; \
2402 default: case 2: flags = 0x3; break; \
2404 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2405 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2407 void VFP_HELPER(cmpe, p)(type a, type b, CPUState *env) \
2410 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
2411 case 0: flags = 0x6; break; \
2412 case -1: flags = 0x8; break; \
2413 case 1: flags = 0x2; break; \
2414 default: case 2: flags = 0x3; break; \
2416 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2417 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2419 DO_VFP_cmp(s
, float32
)
2420 DO_VFP_cmp(d
, float64
)
2423 /* Helper routines to perform bitwise copies between float and int. */
2424 static inline float32
vfp_itos(uint32_t i
)
2435 static inline uint32_t vfp_stoi(float32 s
)
2446 static inline float64
vfp_itod(uint64_t i
)
2457 static inline uint64_t vfp_dtoi(float64 d
)
2468 /* Integer to float conversion. */
2469 float32
VFP_HELPER(uito
, s
)(float32 x
, CPUState
*env
)
2471 return uint32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2474 float64
VFP_HELPER(uito
, d
)(float32 x
, CPUState
*env
)
2476 return uint32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2479 float32
VFP_HELPER(sito
, s
)(float32 x
, CPUState
*env
)
2481 return int32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2484 float64
VFP_HELPER(sito
, d
)(float32 x
, CPUState
*env
)
2486 return int32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2489 /* Float to integer conversion. */
2490 float32
VFP_HELPER(toui
, s
)(float32 x
, CPUState
*env
)
2492 return vfp_itos(float32_to_uint32(x
, &env
->vfp
.fp_status
));
2495 float32
VFP_HELPER(toui
, d
)(float64 x
, CPUState
*env
)
2497 return vfp_itos(float64_to_uint32(x
, &env
->vfp
.fp_status
));
2500 float32
VFP_HELPER(tosi
, s
)(float32 x
, CPUState
*env
)
2502 return vfp_itos(float32_to_int32(x
, &env
->vfp
.fp_status
));
2505 float32
VFP_HELPER(tosi
, d
)(float64 x
, CPUState
*env
)
2507 return vfp_itos(float64_to_int32(x
, &env
->vfp
.fp_status
));
2510 float32
VFP_HELPER(touiz
, s
)(float32 x
, CPUState
*env
)
2512 return vfp_itos(float32_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2515 float32
VFP_HELPER(touiz
, d
)(float64 x
, CPUState
*env
)
2517 return vfp_itos(float64_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2520 float32
VFP_HELPER(tosiz
, s
)(float32 x
, CPUState
*env
)
2522 return vfp_itos(float32_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2525 float32
VFP_HELPER(tosiz
, d
)(float64 x
, CPUState
*env
)
2527 return vfp_itos(float64_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2530 /* floating point conversion */
2531 float64
VFP_HELPER(fcvtd
, s
)(float32 x
, CPUState
*env
)
2533 return float32_to_float64(x
, &env
->vfp
.fp_status
);
2536 float32
VFP_HELPER(fcvts
, d
)(float64 x
, CPUState
*env
)
2538 return float64_to_float32(x
, &env
->vfp
.fp_status
);
2541 /* VFP3 fixed point conversion. */
2542 #define VFP_CONV_FIX(name, p, ftype, itype, sign) \
2543 ftype VFP_HELPER(name##to, p)(ftype x, uint32_t shift, CPUState *env) \
2546 tmp = sign##int32_to_##ftype ((itype)vfp_##p##toi(x), \
2547 &env->vfp.fp_status); \
2548 return ftype##_scalbn(tmp, -(int)shift, &env->vfp.fp_status); \
2550 ftype VFP_HELPER(to##name, p)(ftype x, uint32_t shift, CPUState *env) \
2553 tmp = ftype##_scalbn(x, shift, &env->vfp.fp_status); \
2554 return vfp_ito##p((itype)ftype##_to_##sign##int32_round_to_zero(tmp, \
2555 &env->vfp.fp_status)); \
2558 VFP_CONV_FIX(sh
, d
, float64
, int16
, )
2559 VFP_CONV_FIX(sl
, d
, float64
, int32
, )
2560 VFP_CONV_FIX(uh
, d
, float64
, uint16
, u
)
2561 VFP_CONV_FIX(ul
, d
, float64
, uint32
, u
)
2562 VFP_CONV_FIX(sh
, s
, float32
, int16
, )
2563 VFP_CONV_FIX(sl
, s
, float32
, int32
, )
2564 VFP_CONV_FIX(uh
, s
, float32
, uint16
, u
)
2565 VFP_CONV_FIX(ul
, s
, float32
, uint32
, u
)
2568 float32
HELPER(recps_f32
)(float32 a
, float32 b
, CPUState
*env
)
2570 float_status
*s
= &env
->vfp
.fp_status
;
2571 float32 two
= int32_to_float32(2, s
);
2572 return float32_sub(two
, float32_mul(a
, b
, s
), s
);
2575 float32
HELPER(rsqrts_f32
)(float32 a
, float32 b
, CPUState
*env
)
2577 float_status
*s
= &env
->vfp
.fp_status
;
2578 float32 three
= int32_to_float32(3, s
);
2579 return float32_sub(three
, float32_mul(a
, b
, s
), s
);
2584 /* TODO: The architecture specifies the value that the estimate functions
2585 should return. We return the exact reciprocal/root instead. */
2586 float32
HELPER(recpe_f32
)(float32 a
, CPUState
*env
)
2588 float_status
*s
= &env
->vfp
.fp_status
;
2589 float32 one
= int32_to_float32(1, s
);
2590 return float32_div(one
, a
, s
);
2593 float32
HELPER(rsqrte_f32
)(float32 a
, CPUState
*env
)
2595 float_status
*s
= &env
->vfp
.fp_status
;
2596 float32 one
= int32_to_float32(1, s
);
2597 return float32_div(one
, float32_sqrt(a
, s
), s
);
2600 uint32_t HELPER(recpe_u32
)(uint32_t a
, CPUState
*env
)
2602 float_status
*s
= &env
->vfp
.fp_status
;
2604 tmp
= int32_to_float32(a
, s
);
2605 tmp
= float32_scalbn(tmp
, -32, s
);
2606 tmp
= helper_recpe_f32(tmp
, env
);
2607 tmp
= float32_scalbn(tmp
, 31, s
);
2608 return float32_to_int32(tmp
, s
);
2611 uint32_t HELPER(rsqrte_u32
)(uint32_t a
, CPUState
*env
)
2613 float_status
*s
= &env
->vfp
.fp_status
;
2615 tmp
= int32_to_float32(a
, s
);
2616 tmp
= float32_scalbn(tmp
, -32, s
);
2617 tmp
= helper_rsqrte_f32(tmp
, env
);
2618 tmp
= float32_scalbn(tmp
, 31, s
);
2619 return float32_to_int32(tmp
, s
);
2622 void HELPER(set_teecr
)(CPUState
*env
, uint32_t val
)
2625 if (env
->teecr
!= val
) {