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 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410330c0;
92 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
93 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00011100;
94 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c1
, 8 * sizeof(uint32_t));
95 memcpy(env
->cp15
.c0_c2
, cortexa8_cp15_c0_c2
, 8 * sizeof(uint32_t));
96 env
->cp15
.c0_cachetype
= 0x1dd20d2;
98 case ARM_CPUID_CORTEXM3
:
99 set_feature(env
, ARM_FEATURE_V6
);
100 set_feature(env
, ARM_FEATURE_THUMB2
);
101 set_feature(env
, ARM_FEATURE_V7
);
102 set_feature(env
, ARM_FEATURE_M
);
103 set_feature(env
, ARM_FEATURE_DIV
);
105 case ARM_CPUID_ANY
: /* For userspace emulation. */
106 set_feature(env
, ARM_FEATURE_V6
);
107 set_feature(env
, ARM_FEATURE_V6K
);
108 set_feature(env
, ARM_FEATURE_V7
);
109 set_feature(env
, ARM_FEATURE_THUMB2
);
110 set_feature(env
, ARM_FEATURE_VFP
);
111 set_feature(env
, ARM_FEATURE_VFP3
);
112 set_feature(env
, ARM_FEATURE_NEON
);
113 set_feature(env
, ARM_FEATURE_DIV
);
115 case ARM_CPUID_TI915T
:
116 case ARM_CPUID_TI925T
:
117 set_feature(env
, ARM_FEATURE_OMAPCP
);
118 env
->cp15
.c0_cpuid
= ARM_CPUID_TI925T
; /* Depends on wiring. */
119 env
->cp15
.c0_cachetype
= 0x5109149;
120 env
->cp15
.c1_sys
= 0x00000070;
121 env
->cp15
.c15_i_max
= 0x000;
122 env
->cp15
.c15_i_min
= 0xff0;
124 case ARM_CPUID_PXA250
:
125 case ARM_CPUID_PXA255
:
126 case ARM_CPUID_PXA260
:
127 case ARM_CPUID_PXA261
:
128 case ARM_CPUID_PXA262
:
129 set_feature(env
, ARM_FEATURE_XSCALE
);
130 /* JTAG_ID is ((id << 28) | 0x09265013) */
131 env
->cp15
.c0_cachetype
= 0xd172172;
132 env
->cp15
.c1_sys
= 0x00000078;
134 case ARM_CPUID_PXA270_A0
:
135 case ARM_CPUID_PXA270_A1
:
136 case ARM_CPUID_PXA270_B0
:
137 case ARM_CPUID_PXA270_B1
:
138 case ARM_CPUID_PXA270_C0
:
139 case ARM_CPUID_PXA270_C5
:
140 set_feature(env
, ARM_FEATURE_XSCALE
);
141 /* JTAG_ID is ((id << 28) | 0x09265013) */
142 set_feature(env
, ARM_FEATURE_IWMMXT
);
143 env
->iwmmxt
.cregs
[ARM_IWMMXT_wCID
] = 0x69051000 | 'Q';
144 env
->cp15
.c0_cachetype
= 0xd172172;
145 env
->cp15
.c1_sys
= 0x00000078;
148 cpu_abort(env
, "Bad CPU ID: %x\n", id
);
153 void cpu_reset(CPUARMState
*env
)
156 id
= env
->cp15
.c0_cpuid
;
157 memset(env
, 0, offsetof(CPUARMState
, breakpoints
));
159 cpu_reset_model_id(env
, id
);
160 #if defined (CONFIG_USER_ONLY)
161 env
->uncached_cpsr
= ARM_CPU_MODE_USR
;
162 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 1 << 30;
164 /* SVC mode with interrupts disabled. */
165 env
->uncached_cpsr
= ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
166 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
169 env
->uncached_cpsr
&= ~CPSR_I
;
170 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 0;
171 env
->cp15
.c2_base_mask
= 0xffffc000u
;
177 static int vfp_gdb_get_reg(CPUState
*env
, uint8_t *buf
, int reg
)
181 /* VFP data registers are always little-endian. */
182 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
184 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
187 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
188 /* Aliases for Q regs. */
191 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
192 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
196 switch (reg
- nregs
) {
197 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
198 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
199 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
204 static int vfp_gdb_set_reg(CPUState
*env
, uint8_t *buf
, int reg
)
208 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
210 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
213 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
216 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
217 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
221 switch (reg
- nregs
) {
222 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
223 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
224 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
); return 4;
229 CPUARMState
*cpu_arm_init(const char *cpu_model
)
233 static int inited
= 0;
235 id
= cpu_arm_find_by_name(cpu_model
);
238 env
= qemu_mallocz(sizeof(CPUARMState
));
244 arm_translate_init();
247 env
->cpu_model_str
= cpu_model
;
248 env
->cp15
.c0_cpuid
= id
;
250 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
251 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
252 51, "arm-neon.xml", 0);
253 } else if (arm_feature(env
, ARM_FEATURE_VFP3
)) {
254 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
255 35, "arm-vfp3.xml", 0);
256 } else if (arm_feature(env
, ARM_FEATURE_VFP
)) {
257 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
258 19, "arm-vfp.xml", 0);
268 static const struct arm_cpu_t arm_cpu_names
[] = {
269 { ARM_CPUID_ARM926
, "arm926"},
270 { ARM_CPUID_ARM946
, "arm946"},
271 { ARM_CPUID_ARM1026
, "arm1026"},
272 { ARM_CPUID_ARM1136
, "arm1136"},
273 { ARM_CPUID_ARM1136_R2
, "arm1136-r2"},
274 { ARM_CPUID_ARM11MPCORE
, "arm11mpcore"},
275 { ARM_CPUID_CORTEXM3
, "cortex-m3"},
276 { ARM_CPUID_CORTEXA8
, "cortex-a8"},
277 { ARM_CPUID_TI925T
, "ti925t" },
278 { ARM_CPUID_PXA250
, "pxa250" },
279 { ARM_CPUID_PXA255
, "pxa255" },
280 { ARM_CPUID_PXA260
, "pxa260" },
281 { ARM_CPUID_PXA261
, "pxa261" },
282 { ARM_CPUID_PXA262
, "pxa262" },
283 { ARM_CPUID_PXA270
, "pxa270" },
284 { ARM_CPUID_PXA270_A0
, "pxa270-a0" },
285 { ARM_CPUID_PXA270_A1
, "pxa270-a1" },
286 { ARM_CPUID_PXA270_B0
, "pxa270-b0" },
287 { ARM_CPUID_PXA270_B1
, "pxa270-b1" },
288 { ARM_CPUID_PXA270_C0
, "pxa270-c0" },
289 { ARM_CPUID_PXA270_C5
, "pxa270-c5" },
290 { ARM_CPUID_ANY
, "any"},
294 void arm_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
298 (*cpu_fprintf
)(f
, "Available CPUs:\n");
299 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
300 (*cpu_fprintf
)(f
, " %s\n", arm_cpu_names
[i
].name
);
304 /* return 0 if not found */
305 static uint32_t cpu_arm_find_by_name(const char *name
)
311 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
312 if (strcmp(name
, arm_cpu_names
[i
].name
) == 0) {
313 id
= arm_cpu_names
[i
].id
;
320 void cpu_arm_close(CPUARMState
*env
)
325 uint32_t cpsr_read(CPUARMState
*env
)
329 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
330 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
331 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
332 | ((env
->condexec_bits
& 0xfc) << 8)
336 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
)
338 if (mask
& CPSR_NZCV
) {
339 env
->ZF
= (~val
) & CPSR_Z
;
341 env
->CF
= (val
>> 29) & 1;
342 env
->VF
= (val
<< 3) & 0x80000000;
345 env
->QF
= ((val
& CPSR_Q
) != 0);
347 env
->thumb
= ((val
& CPSR_T
) != 0);
348 if (mask
& CPSR_IT_0_1
) {
349 env
->condexec_bits
&= ~3;
350 env
->condexec_bits
|= (val
>> 25) & 3;
352 if (mask
& CPSR_IT_2_7
) {
353 env
->condexec_bits
&= 3;
354 env
->condexec_bits
|= (val
>> 8) & 0xfc;
356 if (mask
& CPSR_GE
) {
357 env
->GE
= (val
>> 16) & 0xf;
360 if ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
) {
361 switch_mode(env
, val
& CPSR_M
);
363 mask
&= ~CACHED_CPSR_BITS
;
364 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
367 /* Sign/zero extend */
368 uint32_t HELPER(sxtb16
)(uint32_t x
)
371 res
= (uint16_t)(int8_t)x
;
372 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
376 uint32_t HELPER(uxtb16
)(uint32_t x
)
379 res
= (uint16_t)(uint8_t)x
;
380 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
384 uint32_t HELPER(clz
)(uint32_t x
)
387 for (count
= 32; x
; count
--)
392 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
399 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
406 uint32_t HELPER(rbit
)(uint32_t x
)
408 x
= ((x
& 0xff000000) >> 24)
409 | ((x
& 0x00ff0000) >> 8)
410 | ((x
& 0x0000ff00) << 8)
411 | ((x
& 0x000000ff) << 24);
412 x
= ((x
& 0xf0f0f0f0) >> 4)
413 | ((x
& 0x0f0f0f0f) << 4);
414 x
= ((x
& 0x88888888) >> 3)
415 | ((x
& 0x44444444) >> 1)
416 | ((x
& 0x22222222) << 1)
417 | ((x
& 0x11111111) << 3);
421 uint32_t HELPER(abs
)(uint32_t x
)
423 return ((int32_t)x
< 0) ? -x
: x
;
426 #if defined(CONFIG_USER_ONLY)
428 void do_interrupt (CPUState
*env
)
430 env
->exception_index
= -1;
433 /* Structure used to record exclusive memory locations. */
434 typedef struct mmon_state
{
435 struct mmon_state
*next
;
436 CPUARMState
*cpu_env
;
440 /* Chain of current locks. */
441 static mmon_state
* mmon_head
= NULL
;
443 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
444 int mmu_idx
, int is_softmmu
)
447 env
->exception_index
= EXCP_PREFETCH_ABORT
;
448 env
->cp15
.c6_insn
= address
;
450 env
->exception_index
= EXCP_DATA_ABORT
;
451 env
->cp15
.c6_data
= address
;
456 static void allocate_mmon_state(CPUState
*env
)
458 env
->mmon_entry
= malloc(sizeof (mmon_state
));
459 if (!env
->mmon_entry
)
461 memset (env
->mmon_entry
, 0, sizeof (mmon_state
));
462 env
->mmon_entry
->cpu_env
= env
;
463 mmon_head
= env
->mmon_entry
;
466 /* Flush any monitor locks for the specified address. */
467 static void flush_mmon(uint32_t addr
)
471 for (mon
= mmon_head
; mon
; mon
= mon
->next
)
473 if (mon
->addr
!= addr
)
481 /* Mark an address for exclusive access. */
482 void HELPER(mark_exclusive
)(CPUState
*env
, uint32_t addr
)
484 if (!env
->mmon_entry
)
485 allocate_mmon_state(env
);
486 /* Clear any previous locks. */
488 env
->mmon_entry
->addr
= addr
;
491 /* Test if an exclusive address is still exclusive. Returns zero
492 if the address is still exclusive. */
493 uint32_t HELPER(test_exclusive
)(CPUState
*env
, uint32_t addr
)
497 if (!env
->mmon_entry
)
499 if (env
->mmon_entry
->addr
== addr
)
507 void HELPER(clrex
)(CPUState
*env
)
509 if (!(env
->mmon_entry
&& env
->mmon_entry
->addr
))
511 flush_mmon(env
->mmon_entry
->addr
);
514 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
519 /* These should probably raise undefined insn exceptions. */
520 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
522 int op1
= (insn
>> 8) & 0xf;
523 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
527 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
529 int op1
= (insn
>> 8) & 0xf;
530 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
534 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
536 cpu_abort(env
, "cp15 insn %08x\n", insn
);
539 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
541 cpu_abort(env
, "cp15 insn %08x\n", insn
);
545 /* These should probably raise undefined insn exceptions. */
546 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
548 cpu_abort(env
, "v7m_mrs %d\n", reg
);
551 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
553 cpu_abort(env
, "v7m_mrs %d\n", reg
);
557 void switch_mode(CPUState
*env
, int mode
)
559 if (mode
!= ARM_CPU_MODE_USR
)
560 cpu_abort(env
, "Tried to switch out of user mode\n");
563 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
565 cpu_abort(env
, "banked r13 write\n");
568 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
570 cpu_abort(env
, "banked r13 read\n");
576 extern int semihosting_enabled
;
578 /* Map CPU modes onto saved register banks. */
579 static inline int bank_number (int mode
)
582 case ARM_CPU_MODE_USR
:
583 case ARM_CPU_MODE_SYS
:
585 case ARM_CPU_MODE_SVC
:
587 case ARM_CPU_MODE_ABT
:
589 case ARM_CPU_MODE_UND
:
591 case ARM_CPU_MODE_IRQ
:
593 case ARM_CPU_MODE_FIQ
:
596 cpu_abort(cpu_single_env
, "Bad mode %x\n", mode
);
600 void switch_mode(CPUState
*env
, int mode
)
605 old_mode
= env
->uncached_cpsr
& CPSR_M
;
606 if (mode
== old_mode
)
609 if (old_mode
== ARM_CPU_MODE_FIQ
) {
610 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
611 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
612 } else if (mode
== ARM_CPU_MODE_FIQ
) {
613 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
614 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
617 i
= bank_number(old_mode
);
618 env
->banked_r13
[i
] = env
->regs
[13];
619 env
->banked_r14
[i
] = env
->regs
[14];
620 env
->banked_spsr
[i
] = env
->spsr
;
622 i
= bank_number(mode
);
623 env
->regs
[13] = env
->banked_r13
[i
];
624 env
->regs
[14] = env
->banked_r14
[i
];
625 env
->spsr
= env
->banked_spsr
[i
];
628 static void v7m_push(CPUARMState
*env
, uint32_t val
)
631 stl_phys(env
->regs
[13], val
);
634 static uint32_t v7m_pop(CPUARMState
*env
)
637 val
= ldl_phys(env
->regs
[13]);
642 /* Switch to V7M main or process stack pointer. */
643 static void switch_v7m_sp(CPUARMState
*env
, int process
)
646 if (env
->v7m
.current_sp
!= process
) {
647 tmp
= env
->v7m
.other_sp
;
648 env
->v7m
.other_sp
= env
->regs
[13];
650 env
->v7m
.current_sp
= process
;
654 static void do_v7m_exception_exit(CPUARMState
*env
)
659 type
= env
->regs
[15];
660 if (env
->v7m
.exception
!= 0)
661 armv7m_nvic_complete_irq(env
->v7m
.nvic
, env
->v7m
.exception
);
663 /* Switch to the target stack. */
664 switch_v7m_sp(env
, (type
& 4) != 0);
666 env
->regs
[0] = v7m_pop(env
);
667 env
->regs
[1] = v7m_pop(env
);
668 env
->regs
[2] = v7m_pop(env
);
669 env
->regs
[3] = v7m_pop(env
);
670 env
->regs
[12] = v7m_pop(env
);
671 env
->regs
[14] = v7m_pop(env
);
672 env
->regs
[15] = v7m_pop(env
);
674 xpsr_write(env
, xpsr
, 0xfffffdff);
675 /* Undo stack alignment. */
678 /* ??? The exception return type specifies Thread/Handler mode. However
679 this is also implied by the xPSR value. Not sure what to do
680 if there is a mismatch. */
681 /* ??? Likewise for mismatches between the CONTROL register and the stack
685 void do_interrupt_v7m(CPUARMState
*env
)
687 uint32_t xpsr
= xpsr_read(env
);
692 if (env
->v7m
.current_sp
)
694 if (env
->v7m
.exception
== 0)
697 /* For exceptions we just mark as pending on the NVIC, and let that
699 /* TODO: Need to escalate if the current priority is higher than the
700 one we're raising. */
701 switch (env
->exception_index
) {
703 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_USAGE
);
707 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_SVC
);
709 case EXCP_PREFETCH_ABORT
:
710 case EXCP_DATA_ABORT
:
711 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_MEM
);
714 if (semihosting_enabled
) {
716 nr
= lduw_code(env
->regs
[15]) & 0xff;
719 env
->regs
[0] = do_arm_semihosting(env
);
723 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_DEBUG
);
726 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->v7m
.nvic
);
728 case EXCP_EXCEPTION_EXIT
:
729 do_v7m_exception_exit(env
);
732 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
733 return; /* Never happens. Keep compiler happy. */
736 /* Align stack pointer. */
737 /* ??? Should only do this if Configuration Control Register
738 STACKALIGN bit is set. */
739 if (env
->regs
[13] & 4) {
743 /* Switch to the handler mode. */
745 v7m_push(env
, env
->regs
[15]);
746 v7m_push(env
, env
->regs
[14]);
747 v7m_push(env
, env
->regs
[12]);
748 v7m_push(env
, env
->regs
[3]);
749 v7m_push(env
, env
->regs
[2]);
750 v7m_push(env
, env
->regs
[1]);
751 v7m_push(env
, env
->regs
[0]);
752 switch_v7m_sp(env
, 0);
753 env
->uncached_cpsr
&= ~CPSR_IT
;
755 addr
= ldl_phys(env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
756 env
->regs
[15] = addr
& 0xfffffffe;
757 env
->thumb
= addr
& 1;
760 /* Handle a CPU exception. */
761 void do_interrupt(CPUARMState
*env
)
769 do_interrupt_v7m(env
);
772 /* TODO: Vectored interrupt controller. */
773 switch (env
->exception_index
) {
775 new_mode
= ARM_CPU_MODE_UND
;
784 if (semihosting_enabled
) {
785 /* Check for semihosting interrupt. */
787 mask
= lduw_code(env
->regs
[15] - 2) & 0xff;
789 mask
= ldl_code(env
->regs
[15] - 4) & 0xffffff;
791 /* Only intercept calls from privileged modes, to provide some
792 semblance of security. */
793 if (((mask
== 0x123456 && !env
->thumb
)
794 || (mask
== 0xab && env
->thumb
))
795 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
796 env
->regs
[0] = do_arm_semihosting(env
);
800 new_mode
= ARM_CPU_MODE_SVC
;
803 /* The PC already points to the next instruction. */
807 /* See if this is a semihosting syscall. */
808 if (env
->thumb
&& semihosting_enabled
) {
809 mask
= lduw_code(env
->regs
[15]) & 0xff;
811 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
813 env
->regs
[0] = do_arm_semihosting(env
);
817 /* Fall through to prefetch abort. */
818 case EXCP_PREFETCH_ABORT
:
819 new_mode
= ARM_CPU_MODE_ABT
;
821 mask
= CPSR_A
| CPSR_I
;
824 case EXCP_DATA_ABORT
:
825 new_mode
= ARM_CPU_MODE_ABT
;
827 mask
= CPSR_A
| CPSR_I
;
831 new_mode
= ARM_CPU_MODE_IRQ
;
833 /* Disable IRQ and imprecise data aborts. */
834 mask
= CPSR_A
| CPSR_I
;
838 new_mode
= ARM_CPU_MODE_FIQ
;
840 /* Disable FIQ, IRQ and imprecise data aborts. */
841 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
845 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
846 return; /* Never happens. Keep compiler happy. */
849 if (env
->cp15
.c1_sys
& (1 << 13)) {
852 switch_mode (env
, new_mode
);
853 env
->spsr
= cpsr_read(env
);
855 env
->condexec_bits
= 0;
856 /* Switch to the new mode, and switch to Arm mode. */
857 /* ??? Thumb interrupt handlers not implemented. */
858 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
859 env
->uncached_cpsr
|= mask
;
861 env
->regs
[14] = env
->regs
[15] + offset
;
862 env
->regs
[15] = addr
;
863 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
866 /* Check section/page access permissions.
867 Returns the page protection flags, or zero if the access is not
869 static inline int check_ap(CPUState
*env
, int ap
, int domain
, int access_type
,
875 return PAGE_READ
| PAGE_WRITE
;
877 if (access_type
== 1)
884 if (access_type
== 1)
886 switch ((env
->cp15
.c1_sys
>> 8) & 3) {
888 return is_user
? 0 : PAGE_READ
;
895 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
900 return PAGE_READ
| PAGE_WRITE
;
902 return PAGE_READ
| PAGE_WRITE
;
903 case 4: case 7: /* Reserved. */
906 return is_user
? 0 : prot_ro
;
914 static uint32_t get_level1_table_address(CPUState
*env
, uint32_t address
)
918 if (address
& env
->cp15
.c2_mask
)
919 table
= env
->cp15
.c2_base1
& 0xffffc000;
921 table
= env
->cp15
.c2_base0
& env
->cp15
.c2_base_mask
;
923 table
|= (address
>> 18) & 0x3ffc;
927 static int get_phys_addr_v5(CPUState
*env
, uint32_t address
, int access_type
,
928 int is_user
, uint32_t *phys_ptr
, int *prot
)
938 /* Pagetable walk. */
939 /* Lookup l1 descriptor. */
940 table
= get_level1_table_address(env
, address
);
941 desc
= ldl_phys(table
);
943 domain
= (env
->cp15
.c3
>> ((desc
>> 4) & 0x1e)) & 3;
945 /* Section translation fault. */
949 if (domain
== 0 || domain
== 2) {
951 code
= 9; /* Section domain fault. */
953 code
= 11; /* Page domain fault. */
958 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
959 ap
= (desc
>> 10) & 3;
962 /* Lookup l2 entry. */
964 /* Coarse pagetable. */
965 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
967 /* Fine pagetable. */
968 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
970 desc
= ldl_phys(table
);
972 case 0: /* Page translation fault. */
975 case 1: /* 64k page. */
976 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
977 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
979 case 2: /* 4k page. */
980 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
981 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
983 case 3: /* 1k page. */
985 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
986 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
988 /* Page translation fault. */
993 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
995 ap
= (desc
>> 4) & 3;
998 /* Never happens, but compiler isn't smart enough to tell. */
1003 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1005 /* Access permission fault. */
1008 *phys_ptr
= phys_addr
;
1011 return code
| (domain
<< 4);
1014 static int get_phys_addr_v6(CPUState
*env
, uint32_t address
, int access_type
,
1015 int is_user
, uint32_t *phys_ptr
, int *prot
)
1026 /* Pagetable walk. */
1027 /* Lookup l1 descriptor. */
1028 table
= get_level1_table_address(env
, address
);
1029 desc
= ldl_phys(table
);
1032 /* Section translation fault. */
1036 } else if (type
== 2 && (desc
& (1 << 18))) {
1040 /* Section or page. */
1041 domain
= (desc
>> 4) & 0x1e;
1043 domain
= (env
->cp15
.c3
>> domain
) & 3;
1044 if (domain
== 0 || domain
== 2) {
1046 code
= 9; /* Section domain fault. */
1048 code
= 11; /* Page domain fault. */
1052 if (desc
& (1 << 18)) {
1054 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
1057 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
1059 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
1060 xn
= desc
& (1 << 4);
1063 /* Lookup l2 entry. */
1064 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
1065 desc
= ldl_phys(table
);
1066 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
1068 case 0: /* Page translation fault. */
1071 case 1: /* 64k page. */
1072 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
1073 xn
= desc
& (1 << 15);
1075 case 2: case 3: /* 4k page. */
1076 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
1080 /* Never happens, but compiler isn't smart enough to tell. */
1085 if (xn
&& access_type
== 2)
1088 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1090 /* Access permission fault. */
1093 *phys_ptr
= phys_addr
;
1096 return code
| (domain
<< 4);
1099 static int get_phys_addr_mpu(CPUState
*env
, uint32_t address
, int access_type
,
1100 int is_user
, uint32_t *phys_ptr
, int *prot
)
1106 *phys_ptr
= address
;
1107 for (n
= 7; n
>= 0; n
--) {
1108 base
= env
->cp15
.c6_region
[n
];
1109 if ((base
& 1) == 0)
1111 mask
= 1 << ((base
>> 1) & 0x1f);
1112 /* Keep this shift separate from the above to avoid an
1113 (undefined) << 32. */
1114 mask
= (mask
<< 1) - 1;
1115 if (((base
^ address
) & ~mask
) == 0)
1121 if (access_type
== 2) {
1122 mask
= env
->cp15
.c5_insn
;
1124 mask
= env
->cp15
.c5_data
;
1126 mask
= (mask
>> (n
* 4)) & 0xf;
1133 *prot
= PAGE_READ
| PAGE_WRITE
;
1138 *prot
|= PAGE_WRITE
;
1141 *prot
= PAGE_READ
| PAGE_WRITE
;
1152 /* Bad permission. */
1158 static inline int get_phys_addr(CPUState
*env
, uint32_t address
,
1159 int access_type
, int is_user
,
1160 uint32_t *phys_ptr
, int *prot
)
1162 /* Fast Context Switch Extension. */
1163 if (address
< 0x02000000)
1164 address
+= env
->cp15
.c13_fcse
;
1166 if ((env
->cp15
.c1_sys
& 1) == 0) {
1167 /* MMU/MPU disabled. */
1168 *phys_ptr
= address
;
1169 *prot
= PAGE_READ
| PAGE_WRITE
;
1171 } else if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1172 return get_phys_addr_mpu(env
, address
, access_type
, is_user
, phys_ptr
,
1174 } else if (env
->cp15
.c1_sys
& (1 << 23)) {
1175 return get_phys_addr_v6(env
, address
, access_type
, is_user
, phys_ptr
,
1178 return get_phys_addr_v5(env
, address
, access_type
, is_user
, phys_ptr
,
1183 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
,
1184 int access_type
, int mmu_idx
, int is_softmmu
)
1190 is_user
= mmu_idx
== MMU_USER_IDX
;
1191 ret
= get_phys_addr(env
, address
, access_type
, is_user
, &phys_addr
, &prot
);
1193 /* Map a single [sub]page. */
1194 phys_addr
&= ~(uint32_t)0x3ff;
1195 address
&= ~(uint32_t)0x3ff;
1196 return tlb_set_page (env
, address
, phys_addr
, prot
, mmu_idx
,
1200 if (access_type
== 2) {
1201 env
->cp15
.c5_insn
= ret
;
1202 env
->cp15
.c6_insn
= address
;
1203 env
->exception_index
= EXCP_PREFETCH_ABORT
;
1205 env
->cp15
.c5_data
= ret
;
1206 if (access_type
== 1 && arm_feature(env
, ARM_FEATURE_V6
))
1207 env
->cp15
.c5_data
|= (1 << 11);
1208 env
->cp15
.c6_data
= address
;
1209 env
->exception_index
= EXCP_DATA_ABORT
;
1214 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
1220 ret
= get_phys_addr(env
, addr
, 0, 0, &phys_addr
, &prot
);
1228 /* Not really implemented. Need to figure out a sane way of doing this.
1229 Maybe add generic watchpoint support and use that. */
1231 void HELPER(mark_exclusive
)(CPUState
*env
, uint32_t addr
)
1233 env
->mmon_addr
= addr
;
1236 uint32_t HELPER(test_exclusive
)(CPUState
*env
, uint32_t addr
)
1238 return (env
->mmon_addr
!= addr
);
1241 void HELPER(clrex
)(CPUState
*env
)
1243 env
->mmon_addr
= -1;
1246 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1248 int cp_num
= (insn
>> 8) & 0xf;
1249 int cp_info
= (insn
>> 5) & 7;
1250 int src
= (insn
>> 16) & 0xf;
1251 int operand
= insn
& 0xf;
1253 if (env
->cp
[cp_num
].cp_write
)
1254 env
->cp
[cp_num
].cp_write(env
->cp
[cp_num
].opaque
,
1255 cp_info
, src
, operand
, val
);
1258 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
1260 int cp_num
= (insn
>> 8) & 0xf;
1261 int cp_info
= (insn
>> 5) & 7;
1262 int dest
= (insn
>> 16) & 0xf;
1263 int operand
= insn
& 0xf;
1265 if (env
->cp
[cp_num
].cp_read
)
1266 return env
->cp
[cp_num
].cp_read(env
->cp
[cp_num
].opaque
,
1267 cp_info
, dest
, operand
);
1271 /* Return basic MPU access permission bits. */
1272 static uint32_t simple_mpu_ap_bits(uint32_t val
)
1279 for (i
= 0; i
< 16; i
+= 2) {
1280 ret
|= (val
>> i
) & mask
;
1286 /* Pad basic MPU access permission bits to extended format. */
1287 static uint32_t extended_mpu_ap_bits(uint32_t val
)
1294 for (i
= 0; i
< 16; i
+= 2) {
1295 ret
|= (val
& mask
) << i
;
1301 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1307 op1
= (insn
>> 21) & 7;
1308 op2
= (insn
>> 5) & 7;
1310 switch ((insn
>> 16) & 0xf) {
1312 if (((insn
>> 21) & 7) == 2) {
1313 /* ??? Select cache level. Ignore. */
1317 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1319 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1322 case 1: /* System configuration. */
1323 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1327 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) || crm
== 0)
1328 env
->cp15
.c1_sys
= val
;
1329 /* ??? Lots of these bits are not implemented. */
1330 /* This may enable/disable the MMU, so do a TLB flush. */
1333 case 1: /* Auxiliary cotrol register. */
1334 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1335 env
->cp15
.c1_xscaleauxcr
= val
;
1338 /* Not implemented. */
1341 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1343 if (env
->cp15
.c1_coproc
!= val
) {
1344 env
->cp15
.c1_coproc
= val
;
1345 /* ??? Is this safe when called from within a TB? */
1353 case 2: /* MMU Page table control / MPU cache control. */
1354 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1357 env
->cp15
.c2_data
= val
;
1360 env
->cp15
.c2_insn
= val
;
1368 env
->cp15
.c2_base0
= val
;
1371 env
->cp15
.c2_base1
= val
;
1375 env
->cp15
.c2_control
= val
;
1376 env
->cp15
.c2_mask
= ~(((uint32_t)0xffffffffu
) >> val
);
1377 env
->cp15
.c2_base_mask
= ~((uint32_t)0x3fffu
>> val
);
1384 case 3: /* MMU Domain access control / MPU write buffer control. */
1386 tlb_flush(env
, 1); /* Flush TLB as domain not tracked in TLB */
1388 case 4: /* Reserved. */
1390 case 5: /* MMU Fault status / MPU access permission. */
1391 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1395 if (arm_feature(env
, ARM_FEATURE_MPU
))
1396 val
= extended_mpu_ap_bits(val
);
1397 env
->cp15
.c5_data
= val
;
1400 if (arm_feature(env
, ARM_FEATURE_MPU
))
1401 val
= extended_mpu_ap_bits(val
);
1402 env
->cp15
.c5_insn
= val
;
1405 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1407 env
->cp15
.c5_data
= val
;
1410 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1412 env
->cp15
.c5_insn
= val
;
1418 case 6: /* MMU Fault address / MPU base/size. */
1419 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1422 env
->cp15
.c6_region
[crm
] = val
;
1424 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1428 env
->cp15
.c6_data
= val
;
1430 case 1: /* ??? This is WFAR on armv6 */
1432 env
->cp15
.c6_insn
= val
;
1439 case 7: /* Cache control. */
1440 env
->cp15
.c15_i_max
= 0x000;
1441 env
->cp15
.c15_i_min
= 0xff0;
1442 /* No cache, so nothing to do. */
1443 /* ??? MPCore has VA to PA translation functions. */
1445 case 8: /* MMU TLB control. */
1447 case 0: /* Invalidate all. */
1450 case 1: /* Invalidate single TLB entry. */
1452 /* ??? This is wrong for large pages and sections. */
1453 /* As an ugly hack to make linux work we always flush a 4K
1456 tlb_flush_page(env
, val
);
1457 tlb_flush_page(env
, val
+ 0x400);
1458 tlb_flush_page(env
, val
+ 0x800);
1459 tlb_flush_page(env
, val
+ 0xc00);
1464 case 2: /* Invalidate on ASID. */
1465 tlb_flush(env
, val
== 0);
1467 case 3: /* Invalidate single entry on MVA. */
1468 /* ??? This is like case 1, but ignores ASID. */
1476 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1479 case 0: /* Cache lockdown. */
1481 case 0: /* L1 cache. */
1484 env
->cp15
.c9_data
= val
;
1487 env
->cp15
.c9_insn
= val
;
1493 case 1: /* L2 cache. */
1494 /* Ignore writes to L2 lockdown/auxiliary registers. */
1500 case 1: /* TCM memory region registers. */
1501 /* Not implemented. */
1507 case 10: /* MMU TLB lockdown. */
1508 /* ??? TLB lockdown not implemented. */
1510 case 12: /* Reserved. */
1512 case 13: /* Process ID. */
1515 /* Unlike real hardware the qemu TLB uses virtual addresses,
1516 not modified virtual addresses, so this causes a TLB flush.
1518 if (env
->cp15
.c13_fcse
!= val
)
1520 env
->cp15
.c13_fcse
= val
;
1523 /* This changes the ASID, so do a TLB flush. */
1524 if (env
->cp15
.c13_context
!= val
1525 && !arm_feature(env
, ARM_FEATURE_MPU
))
1527 env
->cp15
.c13_context
= val
;
1530 env
->cp15
.c13_tls1
= val
;
1533 env
->cp15
.c13_tls2
= val
;
1536 env
->cp15
.c13_tls3
= val
;
1542 case 14: /* Reserved. */
1544 case 15: /* Implementation specific. */
1545 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1546 if (op2
== 0 && crm
== 1) {
1547 if (env
->cp15
.c15_cpar
!= (val
& 0x3fff)) {
1548 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
1550 env
->cp15
.c15_cpar
= val
& 0x3fff;
1556 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1560 case 1: /* Set TI925T configuration. */
1561 env
->cp15
.c15_ticonfig
= val
& 0xe7;
1562 env
->cp15
.c0_cpuid
= (val
& (1 << 5)) ? /* OS_TYPE bit */
1563 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
1565 case 2: /* Set I_max. */
1566 env
->cp15
.c15_i_max
= val
;
1568 case 3: /* Set I_min. */
1569 env
->cp15
.c15_i_min
= val
;
1571 case 4: /* Set thread-ID. */
1572 env
->cp15
.c15_threadid
= val
& 0xffff;
1574 case 8: /* Wait-for-interrupt (deprecated). */
1575 cpu_interrupt(env
, CPU_INTERRUPT_HALT
);
1585 /* ??? For debugging only. Should raise illegal instruction exception. */
1586 cpu_abort(env
, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1587 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1590 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
1596 op1
= (insn
>> 21) & 7;
1597 op2
= (insn
>> 5) & 7;
1599 switch ((insn
>> 16) & 0xf) {
1600 case 0: /* ID codes. */
1606 case 0: /* Device ID. */
1607 return env
->cp15
.c0_cpuid
;
1608 case 1: /* Cache Type. */
1609 return env
->cp15
.c0_cachetype
;
1610 case 2: /* TCM status. */
1612 case 3: /* TLB type register. */
1613 return 0; /* No lockable TLB entries. */
1614 case 5: /* CPU ID */
1615 return env
->cpu_index
;
1620 if (!arm_feature(env
, ARM_FEATURE_V6
))
1622 return env
->cp15
.c0_c1
[op2
];
1624 if (!arm_feature(env
, ARM_FEATURE_V6
))
1626 return env
->cp15
.c0_c2
[op2
];
1627 case 3: case 4: case 5: case 6: case 7:
1633 /* These registers aren't documented on arm11 cores. However
1634 Linux looks at them anyway. */
1635 if (!arm_feature(env
, ARM_FEATURE_V6
))
1639 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1645 case 1: /* System configuration. */
1646 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1649 case 0: /* Control register. */
1650 return env
->cp15
.c1_sys
;
1651 case 1: /* Auxiliary control register. */
1652 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1653 return env
->cp15
.c1_xscaleauxcr
;
1654 if (!arm_feature(env
, ARM_FEATURE_AUXCR
))
1656 switch (ARM_CPUID(env
)) {
1657 case ARM_CPUID_ARM1026
:
1659 case ARM_CPUID_ARM1136
:
1660 case ARM_CPUID_ARM1136_R2
:
1662 case ARM_CPUID_ARM11MPCORE
:
1664 case ARM_CPUID_CORTEXA8
:
1669 case 2: /* Coprocessor access register. */
1670 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1672 return env
->cp15
.c1_coproc
;
1676 case 2: /* MMU Page table control / MPU cache control. */
1677 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1680 return env
->cp15
.c2_data
;
1683 return env
->cp15
.c2_insn
;
1691 return env
->cp15
.c2_base0
;
1693 return env
->cp15
.c2_base1
;
1695 return env
->cp15
.c2_control
;
1700 case 3: /* MMU Domain access control / MPU write buffer control. */
1701 return env
->cp15
.c3
;
1702 case 4: /* Reserved. */
1704 case 5: /* MMU Fault status / MPU access permission. */
1705 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1709 if (arm_feature(env
, ARM_FEATURE_MPU
))
1710 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1711 return env
->cp15
.c5_data
;
1713 if (arm_feature(env
, ARM_FEATURE_MPU
))
1714 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1715 return env
->cp15
.c5_insn
;
1717 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1719 return env
->cp15
.c5_data
;
1721 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1723 return env
->cp15
.c5_insn
;
1727 case 6: /* MMU Fault address. */
1728 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1731 return env
->cp15
.c6_region
[crm
];
1733 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1737 return env
->cp15
.c6_data
;
1739 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1740 /* Watchpoint Fault Adrress. */
1741 return 0; /* Not implemented. */
1743 /* Instruction Fault Adrress. */
1744 /* Arm9 doesn't have an IFAR, but implementing it anyway
1745 shouldn't do any harm. */
1746 return env
->cp15
.c6_insn
;
1749 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1750 /* Instruction Fault Adrress. */
1751 return env
->cp15
.c6_insn
;
1759 case 7: /* Cache control. */
1760 /* FIXME: Should only clear Z flag if destination is r15. */
1763 case 8: /* MMU TLB control. */
1765 case 9: /* Cache lockdown. */
1767 case 0: /* L1 cache. */
1768 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1772 return env
->cp15
.c9_data
;
1774 return env
->cp15
.c9_insn
;
1778 case 1: /* L2 cache */
1781 /* L2 Lockdown and Auxiliary control. */
1786 case 10: /* MMU TLB lockdown. */
1787 /* ??? TLB lockdown not implemented. */
1789 case 11: /* TCM DMA control. */
1790 case 12: /* Reserved. */
1792 case 13: /* Process ID. */
1795 return env
->cp15
.c13_fcse
;
1797 return env
->cp15
.c13_context
;
1799 return env
->cp15
.c13_tls1
;
1801 return env
->cp15
.c13_tls2
;
1803 return env
->cp15
.c13_tls3
;
1807 case 14: /* Reserved. */
1809 case 15: /* Implementation specific. */
1810 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1811 if (op2
== 0 && crm
== 1)
1812 return env
->cp15
.c15_cpar
;
1816 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1820 case 1: /* Read TI925T configuration. */
1821 return env
->cp15
.c15_ticonfig
;
1822 case 2: /* Read I_max. */
1823 return env
->cp15
.c15_i_max
;
1824 case 3: /* Read I_min. */
1825 return env
->cp15
.c15_i_min
;
1826 case 4: /* Read thread-ID. */
1827 return env
->cp15
.c15_threadid
;
1828 case 8: /* TI925T_status */
1831 /* TODO: Peripheral port remap register:
1832 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt
1833 * controller base address at $rn & ~0xfff and map size of
1834 * 0x200 << ($rn & 0xfff), when MMU is off. */
1840 /* ??? For debugging only. Should raise illegal instruction exception. */
1841 cpu_abort(env
, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
1842 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1846 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
1848 env
->banked_r13
[bank_number(mode
)] = val
;
1851 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
1853 return env
->banked_r13
[bank_number(mode
)];
1856 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
1860 return xpsr_read(env
) & 0xf8000000;
1862 return xpsr_read(env
) & 0xf80001ff;
1864 return xpsr_read(env
) & 0xff00fc00;
1866 return xpsr_read(env
) & 0xff00fdff;
1868 return xpsr_read(env
) & 0x000001ff;
1870 return xpsr_read(env
) & 0x0700fc00;
1872 return xpsr_read(env
) & 0x0700edff;
1874 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
1876 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
1877 case 16: /* PRIMASK */
1878 return (env
->uncached_cpsr
& CPSR_I
) != 0;
1879 case 17: /* FAULTMASK */
1880 return (env
->uncached_cpsr
& CPSR_F
) != 0;
1881 case 18: /* BASEPRI */
1882 case 19: /* BASEPRI_MAX */
1883 return env
->v7m
.basepri
;
1884 case 20: /* CONTROL */
1885 return env
->v7m
.control
;
1887 /* ??? For debugging only. */
1888 cpu_abort(env
, "Unimplemented system register read (%d)\n", reg
);
1893 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
1897 xpsr_write(env
, val
, 0xf8000000);
1900 xpsr_write(env
, val
, 0xf8000000);
1903 xpsr_write(env
, val
, 0xfe00fc00);
1906 xpsr_write(env
, val
, 0xfe00fc00);
1909 /* IPSR bits are readonly. */
1912 xpsr_write(env
, val
, 0x0600fc00);
1915 xpsr_write(env
, val
, 0x0600fc00);
1918 if (env
->v7m
.current_sp
)
1919 env
->v7m
.other_sp
= val
;
1921 env
->regs
[13] = val
;
1924 if (env
->v7m
.current_sp
)
1925 env
->regs
[13] = val
;
1927 env
->v7m
.other_sp
= val
;
1929 case 16: /* PRIMASK */
1931 env
->uncached_cpsr
|= CPSR_I
;
1933 env
->uncached_cpsr
&= ~CPSR_I
;
1935 case 17: /* FAULTMASK */
1937 env
->uncached_cpsr
|= CPSR_F
;
1939 env
->uncached_cpsr
&= ~CPSR_F
;
1941 case 18: /* BASEPRI */
1942 env
->v7m
.basepri
= val
& 0xff;
1944 case 19: /* BASEPRI_MAX */
1946 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
1947 env
->v7m
.basepri
= val
;
1949 case 20: /* CONTROL */
1950 env
->v7m
.control
= val
& 3;
1951 switch_v7m_sp(env
, (val
& 2) != 0);
1954 /* ??? For debugging only. */
1955 cpu_abort(env
, "Unimplemented system register write (%d)\n", reg
);
1960 void cpu_arm_set_cp_io(CPUARMState
*env
, int cpnum
,
1961 ARMReadCPFunc
*cp_read
, ARMWriteCPFunc
*cp_write
,
1964 if (cpnum
< 0 || cpnum
> 14) {
1965 cpu_abort(env
, "Bad coprocessor number: %i\n", cpnum
);
1969 env
->cp
[cpnum
].cp_read
= cp_read
;
1970 env
->cp
[cpnum
].cp_write
= cp_write
;
1971 env
->cp
[cpnum
].opaque
= opaque
;
1976 /* Note that signed overflow is undefined in C. The following routines are
1977 careful to use unsigned types where modulo arithmetic is required.
1978 Failure to do so _will_ break on newer gcc. */
1980 /* Signed saturating arithmetic. */
1982 /* Perform 16-bit signed saturating addition. */
1983 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
1988 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
1997 /* Perform 8-bit signed saturating addition. */
1998 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
2003 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
2012 /* Perform 16-bit signed saturating subtraction. */
2013 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
2018 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
2027 /* Perform 8-bit signed saturating subtraction. */
2028 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
2033 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
2042 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
2043 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
2044 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
2045 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
2048 #include "op_addsub.h"
2050 /* Unsigned saturating arithmetic. */
2051 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
2060 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
2068 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
2077 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
2085 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
2086 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
2087 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
2088 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
2091 #include "op_addsub.h"
2093 /* Signed modulo arithmetic. */
2094 #define SARITH16(a, b, n, op) do { \
2096 sum = (int16_t)((uint16_t)(a) op (uint16_t)(b)); \
2097 RESULT(sum, n, 16); \
2099 ge |= 3 << (n * 2); \
2102 #define SARITH8(a, b, n, op) do { \
2104 sum = (int8_t)((uint8_t)(a) op (uint8_t)(b)); \
2105 RESULT(sum, n, 8); \
2111 #define ADD16(a, b, n) SARITH16(a, b, n, +)
2112 #define SUB16(a, b, n) SARITH16(a, b, n, -)
2113 #define ADD8(a, b, n) SARITH8(a, b, n, +)
2114 #define SUB8(a, b, n) SARITH8(a, b, n, -)
2118 #include "op_addsub.h"
2120 /* Unsigned modulo arithmetic. */
2121 #define ADD16(a, b, n) do { \
2123 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
2124 RESULT(sum, n, 16); \
2125 if ((sum >> 16) == 1) \
2126 ge |= 3 << (n * 2); \
2129 #define ADD8(a, b, n) do { \
2131 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
2132 RESULT(sum, n, 8); \
2133 if ((sum >> 8) == 1) \
2137 #define SUB16(a, b, n) do { \
2139 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
2140 RESULT(sum, n, 16); \
2141 if ((sum >> 16) == 0) \
2142 ge |= 3 << (n * 2); \
2145 #define SUB8(a, b, n) do { \
2147 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
2148 RESULT(sum, n, 8); \
2149 if ((sum >> 8) == 0) \
2156 #include "op_addsub.h"
2158 /* Halved signed arithmetic. */
2159 #define ADD16(a, b, n) \
2160 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
2161 #define SUB16(a, b, n) \
2162 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
2163 #define ADD8(a, b, n) \
2164 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
2165 #define SUB8(a, b, n) \
2166 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
2169 #include "op_addsub.h"
2171 /* Halved unsigned arithmetic. */
2172 #define ADD16(a, b, n) \
2173 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2174 #define SUB16(a, b, n) \
2175 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2176 #define ADD8(a, b, n) \
2177 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2178 #define SUB8(a, b, n) \
2179 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2182 #include "op_addsub.h"
2184 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
2192 /* Unsigned sum of absolute byte differences. */
2193 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
2196 sum
= do_usad(a
, b
);
2197 sum
+= do_usad(a
>> 8, b
>> 8);
2198 sum
+= do_usad(a
>> 16, b
>>16);
2199 sum
+= do_usad(a
>> 24, b
>> 24);
2203 /* For ARMv6 SEL instruction. */
2204 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
2217 return (a
& mask
) | (b
& ~mask
);
2220 uint32_t HELPER(logicq_cc
)(uint64_t val
)
2222 return (val
>> 32) | (val
!= 0);
2225 /* VFP support. We follow the convention used for VFP instrunctions:
2226 Single precition routines have a "s" suffix, double precision a
2229 /* Convert host exception flags to vfp form. */
2230 static inline int vfp_exceptbits_from_host(int host_bits
)
2232 int target_bits
= 0;
2234 if (host_bits
& float_flag_invalid
)
2236 if (host_bits
& float_flag_divbyzero
)
2238 if (host_bits
& float_flag_overflow
)
2240 if (host_bits
& float_flag_underflow
)
2242 if (host_bits
& float_flag_inexact
)
2243 target_bits
|= 0x10;
2247 uint32_t HELPER(vfp_get_fpscr
)(CPUState
*env
)
2252 fpscr
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & 0xffc8ffff)
2253 | (env
->vfp
.vec_len
<< 16)
2254 | (env
->vfp
.vec_stride
<< 20);
2255 i
= get_float_exception_flags(&env
->vfp
.fp_status
);
2256 fpscr
|= vfp_exceptbits_from_host(i
);
2260 /* Convert vfp exception flags to target form. */
2261 static inline int vfp_exceptbits_to_host(int target_bits
)
2265 if (target_bits
& 1)
2266 host_bits
|= float_flag_invalid
;
2267 if (target_bits
& 2)
2268 host_bits
|= float_flag_divbyzero
;
2269 if (target_bits
& 4)
2270 host_bits
|= float_flag_overflow
;
2271 if (target_bits
& 8)
2272 host_bits
|= float_flag_underflow
;
2273 if (target_bits
& 0x10)
2274 host_bits
|= float_flag_inexact
;
2278 void HELPER(vfp_set_fpscr
)(CPUState
*env
, uint32_t val
)
2283 changed
= env
->vfp
.xregs
[ARM_VFP_FPSCR
];
2284 env
->vfp
.xregs
[ARM_VFP_FPSCR
] = (val
& 0xffc8ffff);
2285 env
->vfp
.vec_len
= (val
>> 16) & 7;
2286 env
->vfp
.vec_stride
= (val
>> 20) & 3;
2289 if (changed
& (3 << 22)) {
2290 i
= (val
>> 22) & 3;
2293 i
= float_round_nearest_even
;
2299 i
= float_round_down
;
2302 i
= float_round_to_zero
;
2305 set_float_rounding_mode(i
, &env
->vfp
.fp_status
);
2308 i
= vfp_exceptbits_to_host((val
>> 8) & 0x1f);
2309 set_float_exception_flags(i
, &env
->vfp
.fp_status
);
2310 /* XXX: FZ and DN are not implemented. */
2313 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
2315 #define VFP_BINOP(name) \
2316 float32 VFP_HELPER(name, s)(float32 a, float32 b, CPUState *env) \
2318 return float32_ ## name (a, b, &env->vfp.fp_status); \
2320 float64 VFP_HELPER(name, d)(float64 a, float64 b, CPUState *env) \
2322 return float64_ ## name (a, b, &env->vfp.fp_status); \
2330 float32
VFP_HELPER(neg
, s
)(float32 a
)
2332 return float32_chs(a
);
2335 float64
VFP_HELPER(neg
, d
)(float64 a
)
2337 return float64_chs(a
);
2340 float32
VFP_HELPER(abs
, s
)(float32 a
)
2342 return float32_abs(a
);
2345 float64
VFP_HELPER(abs
, d
)(float64 a
)
2347 return float64_abs(a
);
2350 float32
VFP_HELPER(sqrt
, s
)(float32 a
, CPUState
*env
)
2352 return float32_sqrt(a
, &env
->vfp
.fp_status
);
2355 float64
VFP_HELPER(sqrt
, d
)(float64 a
, CPUState
*env
)
2357 return float64_sqrt(a
, &env
->vfp
.fp_status
);
2360 /* XXX: check quiet/signaling case */
2361 #define DO_VFP_cmp(p, type) \
2362 void VFP_HELPER(cmp, p)(type a, type b, CPUState *env) \
2365 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
2366 case 0: flags = 0x6; break; \
2367 case -1: flags = 0x8; break; \
2368 case 1: flags = 0x2; break; \
2369 default: case 2: flags = 0x3; break; \
2371 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2372 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2374 void VFP_HELPER(cmpe, p)(type a, type b, CPUState *env) \
2377 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
2378 case 0: flags = 0x6; break; \
2379 case -1: flags = 0x8; break; \
2380 case 1: flags = 0x2; break; \
2381 default: case 2: flags = 0x3; break; \
2383 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2384 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2386 DO_VFP_cmp(s
, float32
)
2387 DO_VFP_cmp(d
, float64
)
2390 /* Helper routines to perform bitwise copies between float and int. */
2391 static inline float32
vfp_itos(uint32_t i
)
2402 static inline uint32_t vfp_stoi(float32 s
)
2413 static inline float64
vfp_itod(uint64_t i
)
2424 static inline uint64_t vfp_dtoi(float64 d
)
2435 /* Integer to float conversion. */
2436 float32
VFP_HELPER(uito
, s
)(float32 x
, CPUState
*env
)
2438 return uint32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2441 float64
VFP_HELPER(uito
, d
)(float32 x
, CPUState
*env
)
2443 return uint32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2446 float32
VFP_HELPER(sito
, s
)(float32 x
, CPUState
*env
)
2448 return int32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2451 float64
VFP_HELPER(sito
, d
)(float32 x
, CPUState
*env
)
2453 return int32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2456 /* Float to integer conversion. */
2457 float32
VFP_HELPER(toui
, s
)(float32 x
, CPUState
*env
)
2459 return vfp_itos(float32_to_uint32(x
, &env
->vfp
.fp_status
));
2462 float32
VFP_HELPER(toui
, d
)(float64 x
, CPUState
*env
)
2464 return vfp_itos(float64_to_uint32(x
, &env
->vfp
.fp_status
));
2467 float32
VFP_HELPER(tosi
, s
)(float32 x
, CPUState
*env
)
2469 return vfp_itos(float32_to_int32(x
, &env
->vfp
.fp_status
));
2472 float32
VFP_HELPER(tosi
, d
)(float64 x
, CPUState
*env
)
2474 return vfp_itos(float64_to_int32(x
, &env
->vfp
.fp_status
));
2477 float32
VFP_HELPER(touiz
, s
)(float32 x
, CPUState
*env
)
2479 return vfp_itos(float32_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2482 float32
VFP_HELPER(touiz
, d
)(float64 x
, CPUState
*env
)
2484 return vfp_itos(float64_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2487 float32
VFP_HELPER(tosiz
, s
)(float32 x
, CPUState
*env
)
2489 return vfp_itos(float32_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2492 float32
VFP_HELPER(tosiz
, d
)(float64 x
, CPUState
*env
)
2494 return vfp_itos(float64_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2497 /* floating point conversion */
2498 float64
VFP_HELPER(fcvtd
, s
)(float32 x
, CPUState
*env
)
2500 return float32_to_float64(x
, &env
->vfp
.fp_status
);
2503 float32
VFP_HELPER(fcvts
, d
)(float64 x
, CPUState
*env
)
2505 return float64_to_float32(x
, &env
->vfp
.fp_status
);
2508 /* VFP3 fixed point conversion. */
2509 #define VFP_CONV_FIX(name, p, ftype, itype, sign) \
2510 ftype VFP_HELPER(name##to, p)(ftype x, uint32_t shift, CPUState *env) \
2513 tmp = sign##int32_to_##ftype ((itype)vfp_##p##toi(x), \
2514 &env->vfp.fp_status); \
2515 return ftype##_scalbn(tmp, shift, &env->vfp.fp_status); \
2517 ftype VFP_HELPER(to##name, p)(ftype x, uint32_t shift, CPUState *env) \
2520 tmp = ftype##_scalbn(x, shift, &env->vfp.fp_status); \
2521 return vfp_ito##p((itype)ftype##_to_##sign##int32_round_to_zero(tmp, \
2522 &env->vfp.fp_status)); \
2525 VFP_CONV_FIX(sh
, d
, float64
, int16
, )
2526 VFP_CONV_FIX(sl
, d
, float64
, int32
, )
2527 VFP_CONV_FIX(uh
, d
, float64
, uint16
, u
)
2528 VFP_CONV_FIX(ul
, d
, float64
, uint32
, u
)
2529 VFP_CONV_FIX(sh
, s
, float32
, int16
, )
2530 VFP_CONV_FIX(sl
, s
, float32
, int32
, )
2531 VFP_CONV_FIX(uh
, s
, float32
, uint16
, u
)
2532 VFP_CONV_FIX(ul
, s
, float32
, uint32
, u
)
2535 float32
HELPER(recps_f32
)(float32 a
, float32 b
, CPUState
*env
)
2537 float_status
*s
= &env
->vfp
.fp_status
;
2538 float32 two
= int32_to_float32(2, s
);
2539 return float32_sub(two
, float32_mul(a
, b
, s
), s
);
2542 float32
HELPER(rsqrts_f32
)(float32 a
, float32 b
, CPUState
*env
)
2544 float_status
*s
= &env
->vfp
.fp_status
;
2545 float32 three
= int32_to_float32(3, s
);
2546 return float32_sub(three
, float32_mul(a
, b
, s
), s
);
2551 /* TODO: The architecture specifies the value that the estimate functions
2552 should return. We return the exact reciprocal/root instead. */
2553 float32
HELPER(recpe_f32
)(float32 a
, CPUState
*env
)
2555 float_status
*s
= &env
->vfp
.fp_status
;
2556 float32 one
= int32_to_float32(1, s
);
2557 return float32_div(one
, a
, s
);
2560 float32
HELPER(rsqrte_f32
)(float32 a
, CPUState
*env
)
2562 float_status
*s
= &env
->vfp
.fp_status
;
2563 float32 one
= int32_to_float32(1, s
);
2564 return float32_div(one
, float32_sqrt(a
, s
), s
);
2567 uint32_t HELPER(recpe_u32
)(uint32_t a
, CPUState
*env
)
2569 float_status
*s
= &env
->vfp
.fp_status
;
2571 tmp
= int32_to_float32(a
, s
);
2572 tmp
= float32_scalbn(tmp
, -32, s
);
2573 tmp
= helper_recpe_f32(tmp
, env
);
2574 tmp
= float32_scalbn(tmp
, 31, s
);
2575 return float32_to_int32(tmp
, s
);
2578 uint32_t HELPER(rsqrte_u32
)(uint32_t a
, CPUState
*env
)
2580 float_status
*s
= &env
->vfp
.fp_status
;
2582 tmp
= int32_to_float32(a
, s
);
2583 tmp
= float32_scalbn(tmp
, -32, s
);
2584 tmp
= helper_rsqrte_f32(tmp
, env
);
2585 tmp
= float32_scalbn(tmp
, 31, s
);
2586 return float32_to_int32(tmp
, s
);