9 #include "qemu-common.h"
10 #include "host-utils.h"
11 #if !defined(CONFIG_USER_ONLY)
12 #include "hw/loader.h"
15 static uint32_t cortexa9_cp15_c0_c1
[8] =
16 { 0x1031, 0x11, 0x000, 0, 0x00100103, 0x20000000, 0x01230000, 0x00002111 };
18 static uint32_t cortexa9_cp15_c0_c2
[8] =
19 { 0x00101111, 0x13112111, 0x21232041, 0x11112131, 0x00111142, 0, 0, 0 };
21 static uint32_t cortexa8_cp15_c0_c1
[8] =
22 { 0x1031, 0x11, 0x400, 0, 0x31100003, 0x20000000, 0x01202000, 0x11 };
24 static uint32_t cortexa8_cp15_c0_c2
[8] =
25 { 0x00101111, 0x12112111, 0x21232031, 0x11112131, 0x00111142, 0, 0, 0 };
27 static uint32_t mpcore_cp15_c0_c1
[8] =
28 { 0x111, 0x1, 0, 0x2, 0x01100103, 0x10020302, 0x01222000, 0 };
30 static uint32_t mpcore_cp15_c0_c2
[8] =
31 { 0x00100011, 0x12002111, 0x11221011, 0x01102131, 0x141, 0, 0, 0 };
33 static uint32_t arm1136_cp15_c0_c1
[8] =
34 { 0x111, 0x1, 0x2, 0x3, 0x01130003, 0x10030302, 0x01222110, 0 };
36 static uint32_t arm1136_cp15_c0_c2
[8] =
37 { 0x00140011, 0x12002111, 0x11231111, 0x01102131, 0x141, 0, 0, 0 };
39 static uint32_t cpu_arm_find_by_name(const char *name
);
41 static inline void set_feature(CPUARMState
*env
, int feature
)
43 env
->features
|= 1u << feature
;
46 static void cpu_reset_model_id(CPUARMState
*env
, uint32_t id
)
48 env
->cp15
.c0_cpuid
= id
;
50 case ARM_CPUID_ARM926
:
51 set_feature(env
, ARM_FEATURE_VFP
);
52 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41011090;
53 env
->cp15
.c0_cachetype
= 0x1dd20d2;
54 env
->cp15
.c1_sys
= 0x00090078;
56 case ARM_CPUID_ARM946
:
57 set_feature(env
, ARM_FEATURE_MPU
);
58 env
->cp15
.c0_cachetype
= 0x0f004006;
59 env
->cp15
.c1_sys
= 0x00000078;
61 case ARM_CPUID_ARM1026
:
62 set_feature(env
, ARM_FEATURE_VFP
);
63 set_feature(env
, ARM_FEATURE_AUXCR
);
64 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410110a0;
65 env
->cp15
.c0_cachetype
= 0x1dd20d2;
66 env
->cp15
.c1_sys
= 0x00090078;
68 case ARM_CPUID_ARM1136_R2
:
69 case ARM_CPUID_ARM1136
:
70 set_feature(env
, ARM_FEATURE_V6
);
71 set_feature(env
, ARM_FEATURE_VFP
);
72 set_feature(env
, ARM_FEATURE_AUXCR
);
73 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
74 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
75 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
76 memcpy(env
->cp15
.c0_c1
, arm1136_cp15_c0_c1
, 8 * sizeof(uint32_t));
77 memcpy(env
->cp15
.c0_c2
, arm1136_cp15_c0_c2
, 8 * sizeof(uint32_t));
78 env
->cp15
.c0_cachetype
= 0x1dd20d2;
80 case ARM_CPUID_ARM11MPCORE
:
81 set_feature(env
, ARM_FEATURE_V6
);
82 set_feature(env
, ARM_FEATURE_V6K
);
83 set_feature(env
, ARM_FEATURE_VFP
);
84 set_feature(env
, ARM_FEATURE_AUXCR
);
85 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
86 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
87 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
88 memcpy(env
->cp15
.c0_c1
, mpcore_cp15_c0_c1
, 8 * sizeof(uint32_t));
89 memcpy(env
->cp15
.c0_c2
, mpcore_cp15_c0_c2
, 8 * sizeof(uint32_t));
90 env
->cp15
.c0_cachetype
= 0x1dd20d2;
92 case ARM_CPUID_CORTEXA8
:
93 set_feature(env
, ARM_FEATURE_V6
);
94 set_feature(env
, ARM_FEATURE_V6K
);
95 set_feature(env
, ARM_FEATURE_V7
);
96 set_feature(env
, ARM_FEATURE_AUXCR
);
97 set_feature(env
, ARM_FEATURE_THUMB2
);
98 set_feature(env
, ARM_FEATURE_VFP
);
99 set_feature(env
, ARM_FEATURE_VFP3
);
100 set_feature(env
, ARM_FEATURE_NEON
);
101 set_feature(env
, ARM_FEATURE_THUMB2EE
);
102 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410330c0;
103 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
104 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00011100;
105 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c1
, 8 * sizeof(uint32_t));
106 memcpy(env
->cp15
.c0_c2
, cortexa8_cp15_c0_c2
, 8 * sizeof(uint32_t));
107 env
->cp15
.c0_cachetype
= 0x82048004;
108 env
->cp15
.c0_clid
= (1 << 27) | (2 << 24) | 3;
109 env
->cp15
.c0_ccsid
[0] = 0xe007e01a; /* 16k L1 dcache. */
110 env
->cp15
.c0_ccsid
[1] = 0x2007e01a; /* 16k L1 icache. */
111 env
->cp15
.c0_ccsid
[2] = 0xf0000000; /* No L2 icache. */
113 case ARM_CPUID_CORTEXA9
:
114 set_feature(env
, ARM_FEATURE_V6
);
115 set_feature(env
, ARM_FEATURE_V6K
);
116 set_feature(env
, ARM_FEATURE_V7
);
117 set_feature(env
, ARM_FEATURE_AUXCR
);
118 set_feature(env
, ARM_FEATURE_THUMB2
);
119 set_feature(env
, ARM_FEATURE_VFP
);
120 set_feature(env
, ARM_FEATURE_VFP3
);
121 set_feature(env
, ARM_FEATURE_VFP_FP16
);
122 set_feature(env
, ARM_FEATURE_NEON
);
123 set_feature(env
, ARM_FEATURE_THUMB2EE
);
124 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41034000; /* Guess */
125 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
126 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x01111111;
127 memcpy(env
->cp15
.c0_c1
, cortexa9_cp15_c0_c1
, 8 * sizeof(uint32_t));
128 memcpy(env
->cp15
.c0_c2
, cortexa9_cp15_c0_c2
, 8 * sizeof(uint32_t));
129 env
->cp15
.c0_cachetype
= 0x80038003;
130 env
->cp15
.c0_clid
= (1 << 27) | (1 << 24) | 3;
131 env
->cp15
.c0_ccsid
[0] = 0xe00fe015; /* 16k L1 dcache. */
132 env
->cp15
.c0_ccsid
[1] = 0x200fe015; /* 16k L1 icache. */
134 case ARM_CPUID_CORTEXM3
:
135 set_feature(env
, ARM_FEATURE_V6
);
136 set_feature(env
, ARM_FEATURE_THUMB2
);
137 set_feature(env
, ARM_FEATURE_V7
);
138 set_feature(env
, ARM_FEATURE_M
);
139 set_feature(env
, ARM_FEATURE_DIV
);
141 case ARM_CPUID_ANY
: /* For userspace emulation. */
142 set_feature(env
, ARM_FEATURE_V6
);
143 set_feature(env
, ARM_FEATURE_V6K
);
144 set_feature(env
, ARM_FEATURE_V7
);
145 set_feature(env
, ARM_FEATURE_THUMB2
);
146 set_feature(env
, ARM_FEATURE_VFP
);
147 set_feature(env
, ARM_FEATURE_VFP3
);
148 set_feature(env
, ARM_FEATURE_VFP_FP16
);
149 set_feature(env
, ARM_FEATURE_NEON
);
150 set_feature(env
, ARM_FEATURE_THUMB2EE
);
151 set_feature(env
, ARM_FEATURE_DIV
);
153 case ARM_CPUID_TI915T
:
154 case ARM_CPUID_TI925T
:
155 set_feature(env
, ARM_FEATURE_OMAPCP
);
156 env
->cp15
.c0_cpuid
= ARM_CPUID_TI925T
; /* Depends on wiring. */
157 env
->cp15
.c0_cachetype
= 0x5109149;
158 env
->cp15
.c1_sys
= 0x00000070;
159 env
->cp15
.c15_i_max
= 0x000;
160 env
->cp15
.c15_i_min
= 0xff0;
162 case ARM_CPUID_PXA250
:
163 case ARM_CPUID_PXA255
:
164 case ARM_CPUID_PXA260
:
165 case ARM_CPUID_PXA261
:
166 case ARM_CPUID_PXA262
:
167 set_feature(env
, ARM_FEATURE_XSCALE
);
168 /* JTAG_ID is ((id << 28) | 0x09265013) */
169 env
->cp15
.c0_cachetype
= 0xd172172;
170 env
->cp15
.c1_sys
= 0x00000078;
172 case ARM_CPUID_PXA270_A0
:
173 case ARM_CPUID_PXA270_A1
:
174 case ARM_CPUID_PXA270_B0
:
175 case ARM_CPUID_PXA270_B1
:
176 case ARM_CPUID_PXA270_C0
:
177 case ARM_CPUID_PXA270_C5
:
178 set_feature(env
, ARM_FEATURE_XSCALE
);
179 /* JTAG_ID is ((id << 28) | 0x09265013) */
180 set_feature(env
, ARM_FEATURE_IWMMXT
);
181 env
->iwmmxt
.cregs
[ARM_IWMMXT_wCID
] = 0x69051000 | 'Q';
182 env
->cp15
.c0_cachetype
= 0xd172172;
183 env
->cp15
.c1_sys
= 0x00000078;
186 cpu_abort(env
, "Bad CPU ID: %x\n", id
);
191 void cpu_reset(CPUARMState
*env
)
195 if (qemu_loglevel_mask(CPU_LOG_RESET
)) {
196 qemu_log("CPU Reset (CPU %d)\n", env
->cpu_index
);
197 log_cpu_state(env
, 0);
200 id
= env
->cp15
.c0_cpuid
;
201 memset(env
, 0, offsetof(CPUARMState
, breakpoints
));
203 cpu_reset_model_id(env
, id
);
204 #if defined (CONFIG_USER_ONLY)
205 env
->uncached_cpsr
= ARM_CPU_MODE_USR
;
206 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 1 << 30;
208 /* SVC mode with interrupts disabled. */
209 env
->uncached_cpsr
= ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
211 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
212 clear at reset. Initial SP and PC are loaded from ROM. */
216 env
->uncached_cpsr
&= ~CPSR_I
;
219 /* We should really use ldl_phys here, in case the guest
220 modified flash and reset itself. However images
221 loaded via -kenrel have not been copied yet, so load the
222 values directly from there. */
223 env
->regs
[13] = ldl_p(rom
);
226 env
->regs
[15] = pc
& ~1;
229 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 0;
230 env
->cp15
.c2_base_mask
= 0xffffc000u
;
235 static int vfp_gdb_get_reg(CPUState
*env
, uint8_t *buf
, int reg
)
239 /* VFP data registers are always little-endian. */
240 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
242 stfq_le_p(buf
, env
->vfp
.regs
[reg
]);
245 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
246 /* Aliases for Q regs. */
249 stfq_le_p(buf
, env
->vfp
.regs
[(reg
- 32) * 2]);
250 stfq_le_p(buf
+ 8, env
->vfp
.regs
[(reg
- 32) * 2 + 1]);
254 switch (reg
- nregs
) {
255 case 0: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSID
]); return 4;
256 case 1: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPSCR
]); return 4;
257 case 2: stl_p(buf
, env
->vfp
.xregs
[ARM_VFP_FPEXC
]); return 4;
262 static int vfp_gdb_set_reg(CPUState
*env
, uint8_t *buf
, int reg
)
266 nregs
= arm_feature(env
, ARM_FEATURE_VFP3
) ? 32 : 16;
268 env
->vfp
.regs
[reg
] = ldfq_le_p(buf
);
271 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
274 env
->vfp
.regs
[(reg
- 32) * 2] = ldfq_le_p(buf
);
275 env
->vfp
.regs
[(reg
- 32) * 2 + 1] = ldfq_le_p(buf
+ 8);
279 switch (reg
- nregs
) {
280 case 0: env
->vfp
.xregs
[ARM_VFP_FPSID
] = ldl_p(buf
); return 4;
281 case 1: env
->vfp
.xregs
[ARM_VFP_FPSCR
] = ldl_p(buf
); return 4;
282 case 2: env
->vfp
.xregs
[ARM_VFP_FPEXC
] = ldl_p(buf
) & (1 << 30); return 4;
287 CPUARMState
*cpu_arm_init(const char *cpu_model
)
291 static int inited
= 0;
293 id
= cpu_arm_find_by_name(cpu_model
);
296 env
= qemu_mallocz(sizeof(CPUARMState
));
300 arm_translate_init();
303 env
->cpu_model_str
= cpu_model
;
304 env
->cp15
.c0_cpuid
= id
;
306 if (arm_feature(env
, ARM_FEATURE_NEON
)) {
307 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
308 51, "arm-neon.xml", 0);
309 } else if (arm_feature(env
, ARM_FEATURE_VFP3
)) {
310 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
311 35, "arm-vfp3.xml", 0);
312 } else if (arm_feature(env
, ARM_FEATURE_VFP
)) {
313 gdb_register_coprocessor(env
, vfp_gdb_get_reg
, vfp_gdb_set_reg
,
314 19, "arm-vfp.xml", 0);
325 static const struct arm_cpu_t arm_cpu_names
[] = {
326 { ARM_CPUID_ARM926
, "arm926"},
327 { ARM_CPUID_ARM946
, "arm946"},
328 { ARM_CPUID_ARM1026
, "arm1026"},
329 { ARM_CPUID_ARM1136
, "arm1136"},
330 { ARM_CPUID_ARM1136_R2
, "arm1136-r2"},
331 { ARM_CPUID_ARM11MPCORE
, "arm11mpcore"},
332 { ARM_CPUID_CORTEXM3
, "cortex-m3"},
333 { ARM_CPUID_CORTEXA8
, "cortex-a8"},
334 { ARM_CPUID_CORTEXA9
, "cortex-a9"},
335 { ARM_CPUID_TI925T
, "ti925t" },
336 { ARM_CPUID_PXA250
, "pxa250" },
337 { ARM_CPUID_PXA255
, "pxa255" },
338 { ARM_CPUID_PXA260
, "pxa260" },
339 { ARM_CPUID_PXA261
, "pxa261" },
340 { ARM_CPUID_PXA262
, "pxa262" },
341 { ARM_CPUID_PXA270
, "pxa270" },
342 { ARM_CPUID_PXA270_A0
, "pxa270-a0" },
343 { ARM_CPUID_PXA270_A1
, "pxa270-a1" },
344 { ARM_CPUID_PXA270_B0
, "pxa270-b0" },
345 { ARM_CPUID_PXA270_B1
, "pxa270-b1" },
346 { ARM_CPUID_PXA270_C0
, "pxa270-c0" },
347 { ARM_CPUID_PXA270_C5
, "pxa270-c5" },
348 { ARM_CPUID_ANY
, "any"},
352 void arm_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
356 (*cpu_fprintf
)(f
, "Available CPUs:\n");
357 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
358 (*cpu_fprintf
)(f
, " %s\n", arm_cpu_names
[i
].name
);
362 /* return 0 if not found */
363 static uint32_t cpu_arm_find_by_name(const char *name
)
369 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
370 if (strcmp(name
, arm_cpu_names
[i
].name
) == 0) {
371 id
= arm_cpu_names
[i
].id
;
378 void cpu_arm_close(CPUARMState
*env
)
383 uint32_t cpsr_read(CPUARMState
*env
)
387 return env
->uncached_cpsr
| (env
->NF
& 0x80000000) | (ZF
<< 30) |
388 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
389 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
390 | ((env
->condexec_bits
& 0xfc) << 8)
394 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
)
396 if (mask
& CPSR_NZCV
) {
397 env
->ZF
= (~val
) & CPSR_Z
;
399 env
->CF
= (val
>> 29) & 1;
400 env
->VF
= (val
<< 3) & 0x80000000;
403 env
->QF
= ((val
& CPSR_Q
) != 0);
405 env
->thumb
= ((val
& CPSR_T
) != 0);
406 if (mask
& CPSR_IT_0_1
) {
407 env
->condexec_bits
&= ~3;
408 env
->condexec_bits
|= (val
>> 25) & 3;
410 if (mask
& CPSR_IT_2_7
) {
411 env
->condexec_bits
&= 3;
412 env
->condexec_bits
|= (val
>> 8) & 0xfc;
414 if (mask
& CPSR_GE
) {
415 env
->GE
= (val
>> 16) & 0xf;
418 if ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
) {
419 switch_mode(env
, val
& CPSR_M
);
421 mask
&= ~CACHED_CPSR_BITS
;
422 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
425 /* Sign/zero extend */
426 uint32_t HELPER(sxtb16
)(uint32_t x
)
429 res
= (uint16_t)(int8_t)x
;
430 res
|= (uint32_t)(int8_t)(x
>> 16) << 16;
434 uint32_t HELPER(uxtb16
)(uint32_t x
)
437 res
= (uint16_t)(uint8_t)x
;
438 res
|= (uint32_t)(uint8_t)(x
>> 16) << 16;
442 uint32_t HELPER(clz
)(uint32_t x
)
447 int32_t HELPER(sdiv
)(int32_t num
, int32_t den
)
451 if (num
== INT_MIN
&& den
== -1)
456 uint32_t HELPER(udiv
)(uint32_t num
, uint32_t den
)
463 uint32_t HELPER(rbit
)(uint32_t x
)
465 x
= ((x
& 0xff000000) >> 24)
466 | ((x
& 0x00ff0000) >> 8)
467 | ((x
& 0x0000ff00) << 8)
468 | ((x
& 0x000000ff) << 24);
469 x
= ((x
& 0xf0f0f0f0) >> 4)
470 | ((x
& 0x0f0f0f0f) << 4);
471 x
= ((x
& 0x88888888) >> 3)
472 | ((x
& 0x44444444) >> 1)
473 | ((x
& 0x22222222) << 1)
474 | ((x
& 0x11111111) << 3);
478 uint32_t HELPER(abs
)(uint32_t x
)
480 return ((int32_t)x
< 0) ? -x
: x
;
483 #if defined(CONFIG_USER_ONLY)
485 void do_interrupt (CPUState
*env
)
487 env
->exception_index
= -1;
490 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
491 int mmu_idx
, int is_softmmu
)
494 env
->exception_index
= EXCP_PREFETCH_ABORT
;
495 env
->cp15
.c6_insn
= address
;
497 env
->exception_index
= EXCP_DATA_ABORT
;
498 env
->cp15
.c6_data
= address
;
503 /* These should probably raise undefined insn exceptions. */
504 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
506 int op1
= (insn
>> 8) & 0xf;
507 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
511 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
513 int op1
= (insn
>> 8) & 0xf;
514 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
518 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
520 cpu_abort(env
, "cp15 insn %08x\n", insn
);
523 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
525 cpu_abort(env
, "cp15 insn %08x\n", insn
);
528 /* These should probably raise undefined insn exceptions. */
529 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
531 cpu_abort(env
, "v7m_mrs %d\n", reg
);
534 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
536 cpu_abort(env
, "v7m_mrs %d\n", reg
);
540 void switch_mode(CPUState
*env
, int mode
)
542 if (mode
!= ARM_CPU_MODE_USR
)
543 cpu_abort(env
, "Tried to switch out of user mode\n");
546 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
548 cpu_abort(env
, "banked r13 write\n");
551 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
553 cpu_abort(env
, "banked r13 read\n");
559 extern int semihosting_enabled
;
561 /* Map CPU modes onto saved register banks. */
562 static inline int bank_number (int mode
)
565 case ARM_CPU_MODE_USR
:
566 case ARM_CPU_MODE_SYS
:
568 case ARM_CPU_MODE_SVC
:
570 case ARM_CPU_MODE_ABT
:
572 case ARM_CPU_MODE_UND
:
574 case ARM_CPU_MODE_IRQ
:
576 case ARM_CPU_MODE_FIQ
:
579 cpu_abort(cpu_single_env
, "Bad mode %x\n", mode
);
583 void switch_mode(CPUState
*env
, int mode
)
588 old_mode
= env
->uncached_cpsr
& CPSR_M
;
589 if (mode
== old_mode
)
592 if (old_mode
== ARM_CPU_MODE_FIQ
) {
593 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
594 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
595 } else if (mode
== ARM_CPU_MODE_FIQ
) {
596 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
597 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
600 i
= bank_number(old_mode
);
601 env
->banked_r13
[i
] = env
->regs
[13];
602 env
->banked_r14
[i
] = env
->regs
[14];
603 env
->banked_spsr
[i
] = env
->spsr
;
605 i
= bank_number(mode
);
606 env
->regs
[13] = env
->banked_r13
[i
];
607 env
->regs
[14] = env
->banked_r14
[i
];
608 env
->spsr
= env
->banked_spsr
[i
];
611 static void v7m_push(CPUARMState
*env
, uint32_t val
)
614 stl_phys(env
->regs
[13], val
);
617 static uint32_t v7m_pop(CPUARMState
*env
)
620 val
= ldl_phys(env
->regs
[13]);
625 /* Switch to V7M main or process stack pointer. */
626 static void switch_v7m_sp(CPUARMState
*env
, int process
)
629 if (env
->v7m
.current_sp
!= process
) {
630 tmp
= env
->v7m
.other_sp
;
631 env
->v7m
.other_sp
= env
->regs
[13];
633 env
->v7m
.current_sp
= process
;
637 static void do_v7m_exception_exit(CPUARMState
*env
)
642 type
= env
->regs
[15];
643 if (env
->v7m
.exception
!= 0)
644 armv7m_nvic_complete_irq(env
->nvic
, env
->v7m
.exception
);
646 /* Switch to the target stack. */
647 switch_v7m_sp(env
, (type
& 4) != 0);
649 env
->regs
[0] = v7m_pop(env
);
650 env
->regs
[1] = v7m_pop(env
);
651 env
->regs
[2] = v7m_pop(env
);
652 env
->regs
[3] = v7m_pop(env
);
653 env
->regs
[12] = v7m_pop(env
);
654 env
->regs
[14] = v7m_pop(env
);
655 env
->regs
[15] = v7m_pop(env
);
657 xpsr_write(env
, xpsr
, 0xfffffdff);
658 /* Undo stack alignment. */
661 /* ??? The exception return type specifies Thread/Handler mode. However
662 this is also implied by the xPSR value. Not sure what to do
663 if there is a mismatch. */
664 /* ??? Likewise for mismatches between the CONTROL register and the stack
668 static void do_interrupt_v7m(CPUARMState
*env
)
670 uint32_t xpsr
= xpsr_read(env
);
675 if (env
->v7m
.current_sp
)
677 if (env
->v7m
.exception
== 0)
680 /* For exceptions we just mark as pending on the NVIC, and let that
682 /* TODO: Need to escalate if the current priority is higher than the
683 one we're raising. */
684 switch (env
->exception_index
) {
686 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_USAGE
);
690 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_SVC
);
692 case EXCP_PREFETCH_ABORT
:
693 case EXCP_DATA_ABORT
:
694 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_MEM
);
697 if (semihosting_enabled
) {
699 nr
= lduw_code(env
->regs
[15]) & 0xff;
702 env
->regs
[0] = do_arm_semihosting(env
);
706 armv7m_nvic_set_pending(env
->nvic
, ARMV7M_EXCP_DEBUG
);
709 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->nvic
);
711 case EXCP_EXCEPTION_EXIT
:
712 do_v7m_exception_exit(env
);
715 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
716 return; /* Never happens. Keep compiler happy. */
719 /* Align stack pointer. */
720 /* ??? Should only do this if Configuration Control Register
721 STACKALIGN bit is set. */
722 if (env
->regs
[13] & 4) {
726 /* Switch to the handler mode. */
728 v7m_push(env
, env
->regs
[15]);
729 v7m_push(env
, env
->regs
[14]);
730 v7m_push(env
, env
->regs
[12]);
731 v7m_push(env
, env
->regs
[3]);
732 v7m_push(env
, env
->regs
[2]);
733 v7m_push(env
, env
->regs
[1]);
734 v7m_push(env
, env
->regs
[0]);
735 switch_v7m_sp(env
, 0);
736 env
->uncached_cpsr
&= ~CPSR_IT
;
738 addr
= ldl_phys(env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
739 env
->regs
[15] = addr
& 0xfffffffe;
740 env
->thumb
= addr
& 1;
743 /* Handle a CPU exception. */
744 void do_interrupt(CPUARMState
*env
)
752 do_interrupt_v7m(env
);
755 /* TODO: Vectored interrupt controller. */
756 switch (env
->exception_index
) {
758 new_mode
= ARM_CPU_MODE_UND
;
767 if (semihosting_enabled
) {
768 /* Check for semihosting interrupt. */
770 mask
= lduw_code(env
->regs
[15] - 2) & 0xff;
772 mask
= ldl_code(env
->regs
[15] - 4) & 0xffffff;
774 /* Only intercept calls from privileged modes, to provide some
775 semblance of security. */
776 if (((mask
== 0x123456 && !env
->thumb
)
777 || (mask
== 0xab && env
->thumb
))
778 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
779 env
->regs
[0] = do_arm_semihosting(env
);
783 new_mode
= ARM_CPU_MODE_SVC
;
786 /* The PC already points to the next instruction. */
790 /* See if this is a semihosting syscall. */
791 if (env
->thumb
&& semihosting_enabled
) {
792 mask
= lduw_code(env
->regs
[15]) & 0xff;
794 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
796 env
->regs
[0] = do_arm_semihosting(env
);
800 /* Fall through to prefetch abort. */
801 case EXCP_PREFETCH_ABORT
:
802 new_mode
= ARM_CPU_MODE_ABT
;
804 mask
= CPSR_A
| CPSR_I
;
807 case EXCP_DATA_ABORT
:
808 new_mode
= ARM_CPU_MODE_ABT
;
810 mask
= CPSR_A
| CPSR_I
;
814 new_mode
= ARM_CPU_MODE_IRQ
;
816 /* Disable IRQ and imprecise data aborts. */
817 mask
= CPSR_A
| CPSR_I
;
821 new_mode
= ARM_CPU_MODE_FIQ
;
823 /* Disable FIQ, IRQ and imprecise data aborts. */
824 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
828 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
829 return; /* Never happens. Keep compiler happy. */
832 if (env
->cp15
.c1_sys
& (1 << 13)) {
835 switch_mode (env
, new_mode
);
836 env
->spsr
= cpsr_read(env
);
838 env
->condexec_bits
= 0;
839 /* Switch to the new mode, and to the correct instruction set. */
840 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
841 env
->uncached_cpsr
|= mask
;
842 env
->thumb
= (env
->cp15
.c1_sys
& (1 << 30)) != 0;
843 env
->regs
[14] = env
->regs
[15] + offset
;
844 env
->regs
[15] = addr
;
845 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
848 /* Check section/page access permissions.
849 Returns the page protection flags, or zero if the access is not
851 static inline int check_ap(CPUState
*env
, int ap
, int domain
, int access_type
,
857 return PAGE_READ
| PAGE_WRITE
;
859 if (access_type
== 1)
866 if (access_type
== 1)
868 switch ((env
->cp15
.c1_sys
>> 8) & 3) {
870 return is_user
? 0 : PAGE_READ
;
877 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
882 return PAGE_READ
| PAGE_WRITE
;
884 return PAGE_READ
| PAGE_WRITE
;
885 case 4: /* Reserved. */
888 return is_user
? 0 : prot_ro
;
892 if (!arm_feature (env
, ARM_FEATURE_V7
))
900 static uint32_t get_level1_table_address(CPUState
*env
, uint32_t address
)
904 if (address
& env
->cp15
.c2_mask
)
905 table
= env
->cp15
.c2_base1
& 0xffffc000;
907 table
= env
->cp15
.c2_base0
& env
->cp15
.c2_base_mask
;
909 table
|= (address
>> 18) & 0x3ffc;
913 static int get_phys_addr_v5(CPUState
*env
, uint32_t address
, int access_type
,
914 int is_user
, uint32_t *phys_ptr
, int *prot
,
915 target_ulong
*page_size
)
925 /* Pagetable walk. */
926 /* Lookup l1 descriptor. */
927 table
= get_level1_table_address(env
, address
);
928 desc
= ldl_phys(table
);
930 domain
= (env
->cp15
.c3
>> ((desc
>> 4) & 0x1e)) & 3;
932 /* Section translation fault. */
936 if (domain
== 0 || domain
== 2) {
938 code
= 9; /* Section domain fault. */
940 code
= 11; /* Page domain fault. */
945 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
946 ap
= (desc
>> 10) & 3;
948 *page_size
= 1024 * 1024;
950 /* Lookup l2 entry. */
952 /* Coarse pagetable. */
953 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
955 /* Fine pagetable. */
956 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
958 desc
= ldl_phys(table
);
960 case 0: /* Page translation fault. */
963 case 1: /* 64k page. */
964 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
965 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
966 *page_size
= 0x10000;
968 case 2: /* 4k page. */
969 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
970 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
973 case 3: /* 1k page. */
975 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
976 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
978 /* Page translation fault. */
983 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
985 ap
= (desc
>> 4) & 3;
989 /* Never happens, but compiler isn't smart enough to tell. */
994 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
996 /* Access permission fault. */
1000 *phys_ptr
= phys_addr
;
1003 return code
| (domain
<< 4);
1006 static int get_phys_addr_v6(CPUState
*env
, uint32_t address
, int access_type
,
1007 int is_user
, uint32_t *phys_ptr
, int *prot
,
1008 target_ulong
*page_size
)
1019 /* Pagetable walk. */
1020 /* Lookup l1 descriptor. */
1021 table
= get_level1_table_address(env
, address
);
1022 desc
= ldl_phys(table
);
1025 /* Section translation fault. */
1029 } else if (type
== 2 && (desc
& (1 << 18))) {
1033 /* Section or page. */
1034 domain
= (desc
>> 4) & 0x1e;
1036 domain
= (env
->cp15
.c3
>> domain
) & 3;
1037 if (domain
== 0 || domain
== 2) {
1039 code
= 9; /* Section domain fault. */
1041 code
= 11; /* Page domain fault. */
1045 if (desc
& (1 << 18)) {
1047 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
1048 *page_size
= 0x1000000;
1051 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
1052 *page_size
= 0x100000;
1054 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
1055 xn
= desc
& (1 << 4);
1058 /* Lookup l2 entry. */
1059 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
1060 desc
= ldl_phys(table
);
1061 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
1063 case 0: /* Page translation fault. */
1066 case 1: /* 64k page. */
1067 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
1068 xn
= desc
& (1 << 15);
1069 *page_size
= 0x10000;
1071 case 2: case 3: /* 4k page. */
1072 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
1074 *page_size
= 0x1000;
1077 /* Never happens, but compiler isn't smart enough to tell. */
1082 if (xn
&& access_type
== 2)
1085 /* The simplified model uses AP[0] as an access control bit. */
1086 if ((env
->cp15
.c1_sys
& (1 << 29)) && (ap
& 1) == 0) {
1087 /* Access flag fault. */
1088 code
= (code
== 15) ? 6 : 3;
1091 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
1093 /* Access permission fault. */
1099 *phys_ptr
= phys_addr
;
1102 return code
| (domain
<< 4);
1105 static int get_phys_addr_mpu(CPUState
*env
, uint32_t address
, int access_type
,
1106 int is_user
, uint32_t *phys_ptr
, int *prot
)
1112 *phys_ptr
= address
;
1113 for (n
= 7; n
>= 0; n
--) {
1114 base
= env
->cp15
.c6_region
[n
];
1115 if ((base
& 1) == 0)
1117 mask
= 1 << ((base
>> 1) & 0x1f);
1118 /* Keep this shift separate from the above to avoid an
1119 (undefined) << 32. */
1120 mask
= (mask
<< 1) - 1;
1121 if (((base
^ address
) & ~mask
) == 0)
1127 if (access_type
== 2) {
1128 mask
= env
->cp15
.c5_insn
;
1130 mask
= env
->cp15
.c5_data
;
1132 mask
= (mask
>> (n
* 4)) & 0xf;
1139 *prot
= PAGE_READ
| PAGE_WRITE
;
1144 *prot
|= PAGE_WRITE
;
1147 *prot
= PAGE_READ
| PAGE_WRITE
;
1158 /* Bad permission. */
1165 static inline int get_phys_addr(CPUState
*env
, uint32_t address
,
1166 int access_type
, int is_user
,
1167 uint32_t *phys_ptr
, int *prot
,
1168 target_ulong
*page_size
)
1170 /* Fast Context Switch Extension. */
1171 if (address
< 0x02000000)
1172 address
+= env
->cp15
.c13_fcse
;
1174 if ((env
->cp15
.c1_sys
& 1) == 0) {
1175 /* MMU/MPU disabled. */
1176 *phys_ptr
= address
;
1177 *prot
= PAGE_READ
| PAGE_WRITE
| PAGE_EXEC
;
1178 *page_size
= TARGET_PAGE_SIZE
;
1180 } else if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1181 *page_size
= TARGET_PAGE_SIZE
;
1182 return get_phys_addr_mpu(env
, address
, access_type
, is_user
, phys_ptr
,
1184 } else if (env
->cp15
.c1_sys
& (1 << 23)) {
1185 return get_phys_addr_v6(env
, address
, access_type
, is_user
, phys_ptr
,
1188 return get_phys_addr_v5(env
, address
, access_type
, is_user
, phys_ptr
,
1193 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
,
1194 int access_type
, int mmu_idx
, int is_softmmu
)
1197 target_ulong page_size
;
1201 is_user
= mmu_idx
== MMU_USER_IDX
;
1202 ret
= get_phys_addr(env
, address
, access_type
, is_user
, &phys_addr
, &prot
,
1205 /* Map a single [sub]page. */
1206 phys_addr
&= ~(uint32_t)0x3ff;
1207 address
&= ~(uint32_t)0x3ff;
1208 tlb_set_page (env
, address
, phys_addr
, prot
, mmu_idx
, page_size
);
1212 if (access_type
== 2) {
1213 env
->cp15
.c5_insn
= ret
;
1214 env
->cp15
.c6_insn
= address
;
1215 env
->exception_index
= EXCP_PREFETCH_ABORT
;
1217 env
->cp15
.c5_data
= ret
;
1218 if (access_type
== 1 && arm_feature(env
, ARM_FEATURE_V6
))
1219 env
->cp15
.c5_data
|= (1 << 11);
1220 env
->cp15
.c6_data
= address
;
1221 env
->exception_index
= EXCP_DATA_ABORT
;
1226 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
1229 target_ulong page_size
;
1233 ret
= get_phys_addr(env
, addr
, 0, 0, &phys_addr
, &prot
, &page_size
);
1241 void HELPER(set_cp
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1243 int cp_num
= (insn
>> 8) & 0xf;
1244 int cp_info
= (insn
>> 5) & 7;
1245 int src
= (insn
>> 16) & 0xf;
1246 int operand
= insn
& 0xf;
1248 if (env
->cp
[cp_num
].cp_write
)
1249 env
->cp
[cp_num
].cp_write(env
->cp
[cp_num
].opaque
,
1250 cp_info
, src
, operand
, val
);
1253 uint32_t HELPER(get_cp
)(CPUState
*env
, uint32_t insn
)
1255 int cp_num
= (insn
>> 8) & 0xf;
1256 int cp_info
= (insn
>> 5) & 7;
1257 int dest
= (insn
>> 16) & 0xf;
1258 int operand
= insn
& 0xf;
1260 if (env
->cp
[cp_num
].cp_read
)
1261 return env
->cp
[cp_num
].cp_read(env
->cp
[cp_num
].opaque
,
1262 cp_info
, dest
, operand
);
1266 /* Return basic MPU access permission bits. */
1267 static uint32_t simple_mpu_ap_bits(uint32_t val
)
1274 for (i
= 0; i
< 16; i
+= 2) {
1275 ret
|= (val
>> i
) & mask
;
1281 /* Pad basic MPU access permission bits to extended format. */
1282 static uint32_t extended_mpu_ap_bits(uint32_t val
)
1289 for (i
= 0; i
< 16; i
+= 2) {
1290 ret
|= (val
& mask
) << i
;
1296 void HELPER(set_cp15
)(CPUState
*env
, uint32_t insn
, uint32_t val
)
1302 op1
= (insn
>> 21) & 7;
1303 op2
= (insn
>> 5) & 7;
1305 switch ((insn
>> 16) & 0xf) {
1308 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1310 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1312 if (arm_feature(env
, ARM_FEATURE_V7
)
1313 && op1
== 2 && crm
== 0 && op2
== 0) {
1314 env
->cp15
.c0_cssel
= val
& 0xf;
1318 case 1: /* System configuration. */
1319 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1323 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) || crm
== 0)
1324 env
->cp15
.c1_sys
= val
;
1325 /* ??? Lots of these bits are not implemented. */
1326 /* This may enable/disable the MMU, so do a TLB flush. */
1329 case 1: /* Auxiliary cotrol register. */
1330 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1331 env
->cp15
.c1_xscaleauxcr
= val
;
1334 /* Not implemented. */
1337 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1339 if (env
->cp15
.c1_coproc
!= val
) {
1340 env
->cp15
.c1_coproc
= val
;
1341 /* ??? Is this safe when called from within a TB? */
1349 case 2: /* MMU Page table control / MPU cache control. */
1350 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1353 env
->cp15
.c2_data
= val
;
1356 env
->cp15
.c2_insn
= val
;
1364 env
->cp15
.c2_base0
= val
;
1367 env
->cp15
.c2_base1
= val
;
1371 env
->cp15
.c2_control
= val
;
1372 env
->cp15
.c2_mask
= ~(((uint32_t)0xffffffffu
) >> val
);
1373 env
->cp15
.c2_base_mask
= ~((uint32_t)0x3fffu
>> val
);
1380 case 3: /* MMU Domain access control / MPU write buffer control. */
1382 tlb_flush(env
, 1); /* Flush TLB as domain not tracked in TLB */
1384 case 4: /* Reserved. */
1386 case 5: /* MMU Fault status / MPU access permission. */
1387 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1391 if (arm_feature(env
, ARM_FEATURE_MPU
))
1392 val
= extended_mpu_ap_bits(val
);
1393 env
->cp15
.c5_data
= val
;
1396 if (arm_feature(env
, ARM_FEATURE_MPU
))
1397 val
= extended_mpu_ap_bits(val
);
1398 env
->cp15
.c5_insn
= val
;
1401 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1403 env
->cp15
.c5_data
= val
;
1406 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1408 env
->cp15
.c5_insn
= val
;
1414 case 6: /* MMU Fault address / MPU base/size. */
1415 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1418 env
->cp15
.c6_region
[crm
] = val
;
1420 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1424 env
->cp15
.c6_data
= val
;
1426 case 1: /* ??? This is WFAR on armv6 */
1428 env
->cp15
.c6_insn
= val
;
1435 case 7: /* Cache control. */
1436 env
->cp15
.c15_i_max
= 0x000;
1437 env
->cp15
.c15_i_min
= 0xff0;
1438 /* No cache, so nothing to do. */
1439 /* ??? MPCore has VA to PA translation functions. */
1441 case 8: /* MMU TLB control. */
1443 case 0: /* Invalidate all. */
1446 case 1: /* Invalidate single TLB entry. */
1447 tlb_flush_page(env
, val
& TARGET_PAGE_MASK
);
1449 case 2: /* Invalidate on ASID. */
1450 tlb_flush(env
, val
== 0);
1452 case 3: /* Invalidate single entry on MVA. */
1453 /* ??? This is like case 1, but ignores ASID. */
1461 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1464 case 0: /* Cache lockdown. */
1466 case 0: /* L1 cache. */
1469 env
->cp15
.c9_data
= val
;
1472 env
->cp15
.c9_insn
= val
;
1478 case 1: /* L2 cache. */
1479 /* Ignore writes to L2 lockdown/auxiliary registers. */
1485 case 1: /* TCM memory region registers. */
1486 /* Not implemented. */
1492 case 10: /* MMU TLB lockdown. */
1493 /* ??? TLB lockdown not implemented. */
1495 case 12: /* Reserved. */
1497 case 13: /* Process ID. */
1500 /* Unlike real hardware the qemu TLB uses virtual addresses,
1501 not modified virtual addresses, so this causes a TLB flush.
1503 if (env
->cp15
.c13_fcse
!= val
)
1505 env
->cp15
.c13_fcse
= val
;
1508 /* This changes the ASID, so do a TLB flush. */
1509 if (env
->cp15
.c13_context
!= val
1510 && !arm_feature(env
, ARM_FEATURE_MPU
))
1512 env
->cp15
.c13_context
= val
;
1518 case 14: /* Reserved. */
1520 case 15: /* Implementation specific. */
1521 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1522 if (op2
== 0 && crm
== 1) {
1523 if (env
->cp15
.c15_cpar
!= (val
& 0x3fff)) {
1524 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
1526 env
->cp15
.c15_cpar
= val
& 0x3fff;
1532 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1536 case 1: /* Set TI925T configuration. */
1537 env
->cp15
.c15_ticonfig
= val
& 0xe7;
1538 env
->cp15
.c0_cpuid
= (val
& (1 << 5)) ? /* OS_TYPE bit */
1539 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
1541 case 2: /* Set I_max. */
1542 env
->cp15
.c15_i_max
= val
;
1544 case 3: /* Set I_min. */
1545 env
->cp15
.c15_i_min
= val
;
1547 case 4: /* Set thread-ID. */
1548 env
->cp15
.c15_threadid
= val
& 0xffff;
1550 case 8: /* Wait-for-interrupt (deprecated). */
1551 cpu_interrupt(env
, CPU_INTERRUPT_HALT
);
1561 /* ??? For debugging only. Should raise illegal instruction exception. */
1562 cpu_abort(env
, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1563 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1566 uint32_t HELPER(get_cp15
)(CPUState
*env
, uint32_t insn
)
1572 op1
= (insn
>> 21) & 7;
1573 op2
= (insn
>> 5) & 7;
1575 switch ((insn
>> 16) & 0xf) {
1576 case 0: /* ID codes. */
1582 case 0: /* Device ID. */
1583 return env
->cp15
.c0_cpuid
;
1584 case 1: /* Cache Type. */
1585 return env
->cp15
.c0_cachetype
;
1586 case 2: /* TCM status. */
1588 case 3: /* TLB type register. */
1589 return 0; /* No lockable TLB entries. */
1590 case 5: /* CPU ID */
1591 if (ARM_CPUID(env
) == ARM_CPUID_CORTEXA9
) {
1592 return env
->cpu_index
| 0x80000900;
1594 return env
->cpu_index
;
1600 if (!arm_feature(env
, ARM_FEATURE_V6
))
1602 return env
->cp15
.c0_c1
[op2
];
1604 if (!arm_feature(env
, ARM_FEATURE_V6
))
1606 return env
->cp15
.c0_c2
[op2
];
1607 case 3: case 4: case 5: case 6: case 7:
1613 /* These registers aren't documented on arm11 cores. However
1614 Linux looks at them anyway. */
1615 if (!arm_feature(env
, ARM_FEATURE_V6
))
1619 if (!arm_feature(env
, ARM_FEATURE_V7
))
1624 return env
->cp15
.c0_ccsid
[env
->cp15
.c0_cssel
];
1626 return env
->cp15
.c0_clid
;
1632 if (op2
!= 0 || crm
!= 0)
1634 return env
->cp15
.c0_cssel
;
1638 case 1: /* System configuration. */
1639 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1642 case 0: /* Control register. */
1643 return env
->cp15
.c1_sys
;
1644 case 1: /* Auxiliary control register. */
1645 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1646 return env
->cp15
.c1_xscaleauxcr
;
1647 if (!arm_feature(env
, ARM_FEATURE_AUXCR
))
1649 switch (ARM_CPUID(env
)) {
1650 case ARM_CPUID_ARM1026
:
1652 case ARM_CPUID_ARM1136
:
1653 case ARM_CPUID_ARM1136_R2
:
1655 case ARM_CPUID_ARM11MPCORE
:
1657 case ARM_CPUID_CORTEXA8
:
1659 case ARM_CPUID_CORTEXA9
:
1664 case 2: /* Coprocessor access register. */
1665 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1667 return env
->cp15
.c1_coproc
;
1671 case 2: /* MMU Page table control / MPU cache control. */
1672 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1675 return env
->cp15
.c2_data
;
1678 return env
->cp15
.c2_insn
;
1686 return env
->cp15
.c2_base0
;
1688 return env
->cp15
.c2_base1
;
1690 return env
->cp15
.c2_control
;
1695 case 3: /* MMU Domain access control / MPU write buffer control. */
1696 return env
->cp15
.c3
;
1697 case 4: /* Reserved. */
1699 case 5: /* MMU Fault status / MPU access permission. */
1700 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1704 if (arm_feature(env
, ARM_FEATURE_MPU
))
1705 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1706 return env
->cp15
.c5_data
;
1708 if (arm_feature(env
, ARM_FEATURE_MPU
))
1709 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1710 return env
->cp15
.c5_insn
;
1712 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1714 return env
->cp15
.c5_data
;
1716 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1718 return env
->cp15
.c5_insn
;
1722 case 6: /* MMU Fault address. */
1723 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1726 return env
->cp15
.c6_region
[crm
];
1728 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1732 return env
->cp15
.c6_data
;
1734 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1735 /* Watchpoint Fault Adrress. */
1736 return 0; /* Not implemented. */
1738 /* Instruction Fault Adrress. */
1739 /* Arm9 doesn't have an IFAR, but implementing it anyway
1740 shouldn't do any harm. */
1741 return env
->cp15
.c6_insn
;
1744 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1745 /* Instruction Fault Adrress. */
1746 return env
->cp15
.c6_insn
;
1754 case 7: /* Cache control. */
1755 /* FIXME: Should only clear Z flag if destination is r15. */
1758 case 8: /* MMU TLB control. */
1760 case 9: /* Cache lockdown. */
1762 case 0: /* L1 cache. */
1763 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1767 return env
->cp15
.c9_data
;
1769 return env
->cp15
.c9_insn
;
1773 case 1: /* L2 cache */
1776 /* L2 Lockdown and Auxiliary control. */
1781 case 10: /* MMU TLB lockdown. */
1782 /* ??? TLB lockdown not implemented. */
1784 case 11: /* TCM DMA control. */
1785 case 12: /* Reserved. */
1787 case 13: /* Process ID. */
1790 return env
->cp15
.c13_fcse
;
1792 return env
->cp15
.c13_context
;
1796 case 14: /* Reserved. */
1798 case 15: /* Implementation specific. */
1799 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1800 if (op2
== 0 && crm
== 1)
1801 return env
->cp15
.c15_cpar
;
1805 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1809 case 1: /* Read TI925T configuration. */
1810 return env
->cp15
.c15_ticonfig
;
1811 case 2: /* Read I_max. */
1812 return env
->cp15
.c15_i_max
;
1813 case 3: /* Read I_min. */
1814 return env
->cp15
.c15_i_min
;
1815 case 4: /* Read thread-ID. */
1816 return env
->cp15
.c15_threadid
;
1817 case 8: /* TI925T_status */
1820 /* TODO: Peripheral port remap register:
1821 * On OMAP2 mcr p15, 0, rn, c15, c2, 4 sets up the interrupt
1822 * controller base address at $rn & ~0xfff and map size of
1823 * 0x200 << ($rn & 0xfff), when MMU is off. */
1829 /* ??? For debugging only. Should raise illegal instruction exception. */
1830 cpu_abort(env
, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
1831 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1835 void HELPER(set_r13_banked
)(CPUState
*env
, uint32_t mode
, uint32_t val
)
1837 env
->banked_r13
[bank_number(mode
)] = val
;
1840 uint32_t HELPER(get_r13_banked
)(CPUState
*env
, uint32_t mode
)
1842 return env
->banked_r13
[bank_number(mode
)];
1845 uint32_t HELPER(v7m_mrs
)(CPUState
*env
, uint32_t reg
)
1849 return xpsr_read(env
) & 0xf8000000;
1851 return xpsr_read(env
) & 0xf80001ff;
1853 return xpsr_read(env
) & 0xff00fc00;
1855 return xpsr_read(env
) & 0xff00fdff;
1857 return xpsr_read(env
) & 0x000001ff;
1859 return xpsr_read(env
) & 0x0700fc00;
1861 return xpsr_read(env
) & 0x0700edff;
1863 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
1865 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
1866 case 16: /* PRIMASK */
1867 return (env
->uncached_cpsr
& CPSR_I
) != 0;
1868 case 17: /* FAULTMASK */
1869 return (env
->uncached_cpsr
& CPSR_F
) != 0;
1870 case 18: /* BASEPRI */
1871 case 19: /* BASEPRI_MAX */
1872 return env
->v7m
.basepri
;
1873 case 20: /* CONTROL */
1874 return env
->v7m
.control
;
1876 /* ??? For debugging only. */
1877 cpu_abort(env
, "Unimplemented system register read (%d)\n", reg
);
1882 void HELPER(v7m_msr
)(CPUState
*env
, uint32_t reg
, uint32_t val
)
1886 xpsr_write(env
, val
, 0xf8000000);
1889 xpsr_write(env
, val
, 0xf8000000);
1892 xpsr_write(env
, val
, 0xfe00fc00);
1895 xpsr_write(env
, val
, 0xfe00fc00);
1898 /* IPSR bits are readonly. */
1901 xpsr_write(env
, val
, 0x0600fc00);
1904 xpsr_write(env
, val
, 0x0600fc00);
1907 if (env
->v7m
.current_sp
)
1908 env
->v7m
.other_sp
= val
;
1910 env
->regs
[13] = val
;
1913 if (env
->v7m
.current_sp
)
1914 env
->regs
[13] = val
;
1916 env
->v7m
.other_sp
= val
;
1918 case 16: /* PRIMASK */
1920 env
->uncached_cpsr
|= CPSR_I
;
1922 env
->uncached_cpsr
&= ~CPSR_I
;
1924 case 17: /* FAULTMASK */
1926 env
->uncached_cpsr
|= CPSR_F
;
1928 env
->uncached_cpsr
&= ~CPSR_F
;
1930 case 18: /* BASEPRI */
1931 env
->v7m
.basepri
= val
& 0xff;
1933 case 19: /* BASEPRI_MAX */
1935 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
1936 env
->v7m
.basepri
= val
;
1938 case 20: /* CONTROL */
1939 env
->v7m
.control
= val
& 3;
1940 switch_v7m_sp(env
, (val
& 2) != 0);
1943 /* ??? For debugging only. */
1944 cpu_abort(env
, "Unimplemented system register write (%d)\n", reg
);
1949 void cpu_arm_set_cp_io(CPUARMState
*env
, int cpnum
,
1950 ARMReadCPFunc
*cp_read
, ARMWriteCPFunc
*cp_write
,
1953 if (cpnum
< 0 || cpnum
> 14) {
1954 cpu_abort(env
, "Bad coprocessor number: %i\n", cpnum
);
1958 env
->cp
[cpnum
].cp_read
= cp_read
;
1959 env
->cp
[cpnum
].cp_write
= cp_write
;
1960 env
->cp
[cpnum
].opaque
= opaque
;
1965 /* Note that signed overflow is undefined in C. The following routines are
1966 careful to use unsigned types where modulo arithmetic is required.
1967 Failure to do so _will_ break on newer gcc. */
1969 /* Signed saturating arithmetic. */
1971 /* Perform 16-bit signed saturating addition. */
1972 static inline uint16_t add16_sat(uint16_t a
, uint16_t b
)
1977 if (((res
^ a
) & 0x8000) && !((a
^ b
) & 0x8000)) {
1986 /* Perform 8-bit signed saturating addition. */
1987 static inline uint8_t add8_sat(uint8_t a
, uint8_t b
)
1992 if (((res
^ a
) & 0x80) && !((a
^ b
) & 0x80)) {
2001 /* Perform 16-bit signed saturating subtraction. */
2002 static inline uint16_t sub16_sat(uint16_t a
, uint16_t b
)
2007 if (((res
^ a
) & 0x8000) && ((a
^ b
) & 0x8000)) {
2016 /* Perform 8-bit signed saturating subtraction. */
2017 static inline uint8_t sub8_sat(uint8_t a
, uint8_t b
)
2022 if (((res
^ a
) & 0x80) && ((a
^ b
) & 0x80)) {
2031 #define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
2032 #define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
2033 #define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
2034 #define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
2037 #include "op_addsub.h"
2039 /* Unsigned saturating arithmetic. */
2040 static inline uint16_t add16_usat(uint16_t a
, uint16_t b
)
2049 static inline uint16_t sub16_usat(uint16_t a
, uint16_t b
)
2057 static inline uint8_t add8_usat(uint8_t a
, uint8_t b
)
2066 static inline uint8_t sub8_usat(uint8_t a
, uint8_t b
)
2074 #define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
2075 #define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
2076 #define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
2077 #define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
2080 #include "op_addsub.h"
2082 /* Signed modulo arithmetic. */
2083 #define SARITH16(a, b, n, op) do { \
2085 sum = (int16_t)((uint16_t)(a) op (uint16_t)(b)); \
2086 RESULT(sum, n, 16); \
2088 ge |= 3 << (n * 2); \
2091 #define SARITH8(a, b, n, op) do { \
2093 sum = (int8_t)((uint8_t)(a) op (uint8_t)(b)); \
2094 RESULT(sum, n, 8); \
2100 #define ADD16(a, b, n) SARITH16(a, b, n, +)
2101 #define SUB16(a, b, n) SARITH16(a, b, n, -)
2102 #define ADD8(a, b, n) SARITH8(a, b, n, +)
2103 #define SUB8(a, b, n) SARITH8(a, b, n, -)
2107 #include "op_addsub.h"
2109 /* Unsigned modulo arithmetic. */
2110 #define ADD16(a, b, n) do { \
2112 sum = (uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b); \
2113 RESULT(sum, n, 16); \
2114 if ((sum >> 16) == 1) \
2115 ge |= 3 << (n * 2); \
2118 #define ADD8(a, b, n) do { \
2120 sum = (uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b); \
2121 RESULT(sum, n, 8); \
2122 if ((sum >> 8) == 1) \
2126 #define SUB16(a, b, n) do { \
2128 sum = (uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b); \
2129 RESULT(sum, n, 16); \
2130 if ((sum >> 16) == 0) \
2131 ge |= 3 << (n * 2); \
2134 #define SUB8(a, b, n) do { \
2136 sum = (uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b); \
2137 RESULT(sum, n, 8); \
2138 if ((sum >> 8) == 0) \
2145 #include "op_addsub.h"
2147 /* Halved signed arithmetic. */
2148 #define ADD16(a, b, n) \
2149 RESULT(((int32_t)(int16_t)(a) + (int32_t)(int16_t)(b)) >> 1, n, 16)
2150 #define SUB16(a, b, n) \
2151 RESULT(((int32_t)(int16_t)(a) - (int32_t)(int16_t)(b)) >> 1, n, 16)
2152 #define ADD8(a, b, n) \
2153 RESULT(((int32_t)(int8_t)(a) + (int32_t)(int8_t)(b)) >> 1, n, 8)
2154 #define SUB8(a, b, n) \
2155 RESULT(((int32_t)(int8_t)(a) - (int32_t)(int8_t)(b)) >> 1, n, 8)
2158 #include "op_addsub.h"
2160 /* Halved unsigned arithmetic. */
2161 #define ADD16(a, b, n) \
2162 RESULT(((uint32_t)(uint16_t)(a) + (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2163 #define SUB16(a, b, n) \
2164 RESULT(((uint32_t)(uint16_t)(a) - (uint32_t)(uint16_t)(b)) >> 1, n, 16)
2165 #define ADD8(a, b, n) \
2166 RESULT(((uint32_t)(uint8_t)(a) + (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2167 #define SUB8(a, b, n) \
2168 RESULT(((uint32_t)(uint8_t)(a) - (uint32_t)(uint8_t)(b)) >> 1, n, 8)
2171 #include "op_addsub.h"
2173 static inline uint8_t do_usad(uint8_t a
, uint8_t b
)
2181 /* Unsigned sum of absolute byte differences. */
2182 uint32_t HELPER(usad8
)(uint32_t a
, uint32_t b
)
2185 sum
= do_usad(a
, b
);
2186 sum
+= do_usad(a
>> 8, b
>> 8);
2187 sum
+= do_usad(a
>> 16, b
>>16);
2188 sum
+= do_usad(a
>> 24, b
>> 24);
2192 /* For ARMv6 SEL instruction. */
2193 uint32_t HELPER(sel_flags
)(uint32_t flags
, uint32_t a
, uint32_t b
)
2206 return (a
& mask
) | (b
& ~mask
);
2209 uint32_t HELPER(logicq_cc
)(uint64_t val
)
2211 return (val
>> 32) | (val
!= 0);
2214 /* VFP support. We follow the convention used for VFP instrunctions:
2215 Single precition routines have a "s" suffix, double precision a
2218 /* Convert host exception flags to vfp form. */
2219 static inline int vfp_exceptbits_from_host(int host_bits
)
2221 int target_bits
= 0;
2223 if (host_bits
& float_flag_invalid
)
2225 if (host_bits
& float_flag_divbyzero
)
2227 if (host_bits
& float_flag_overflow
)
2229 if (host_bits
& float_flag_underflow
)
2231 if (host_bits
& float_flag_inexact
)
2232 target_bits
|= 0x10;
2236 uint32_t HELPER(vfp_get_fpscr
)(CPUState
*env
)
2241 fpscr
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & 0xffc8ffff)
2242 | (env
->vfp
.vec_len
<< 16)
2243 | (env
->vfp
.vec_stride
<< 20);
2244 i
= get_float_exception_flags(&env
->vfp
.fp_status
);
2245 fpscr
|= vfp_exceptbits_from_host(i
);
2249 /* Convert vfp exception flags to target form. */
2250 static inline int vfp_exceptbits_to_host(int target_bits
)
2254 if (target_bits
& 1)
2255 host_bits
|= float_flag_invalid
;
2256 if (target_bits
& 2)
2257 host_bits
|= float_flag_divbyzero
;
2258 if (target_bits
& 4)
2259 host_bits
|= float_flag_overflow
;
2260 if (target_bits
& 8)
2261 host_bits
|= float_flag_underflow
;
2262 if (target_bits
& 0x10)
2263 host_bits
|= float_flag_inexact
;
2267 void HELPER(vfp_set_fpscr
)(CPUState
*env
, uint32_t val
)
2272 changed
= env
->vfp
.xregs
[ARM_VFP_FPSCR
];
2273 env
->vfp
.xregs
[ARM_VFP_FPSCR
] = (val
& 0xffc8ffff);
2274 env
->vfp
.vec_len
= (val
>> 16) & 7;
2275 env
->vfp
.vec_stride
= (val
>> 20) & 3;
2278 if (changed
& (3 << 22)) {
2279 i
= (val
>> 22) & 3;
2282 i
= float_round_nearest_even
;
2288 i
= float_round_down
;
2291 i
= float_round_to_zero
;
2294 set_float_rounding_mode(i
, &env
->vfp
.fp_status
);
2296 if (changed
& (1 << 24))
2297 set_flush_to_zero((val
& (1 << 24)) != 0, &env
->vfp
.fp_status
);
2298 if (changed
& (1 << 25))
2299 set_default_nan_mode((val
& (1 << 25)) != 0, &env
->vfp
.fp_status
);
2301 i
= vfp_exceptbits_to_host((val
>> 8) & 0x1f);
2302 set_float_exception_flags(i
, &env
->vfp
.fp_status
);
2305 #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p))
2307 #define VFP_BINOP(name) \
2308 float32 VFP_HELPER(name, s)(float32 a, float32 b, CPUState *env) \
2310 return float32_ ## name (a, b, &env->vfp.fp_status); \
2312 float64 VFP_HELPER(name, d)(float64 a, float64 b, CPUState *env) \
2314 return float64_ ## name (a, b, &env->vfp.fp_status); \
2322 float32
VFP_HELPER(neg
, s
)(float32 a
)
2324 return float32_chs(a
);
2327 float64
VFP_HELPER(neg
, d
)(float64 a
)
2329 return float64_chs(a
);
2332 float32
VFP_HELPER(abs
, s
)(float32 a
)
2334 return float32_abs(a
);
2337 float64
VFP_HELPER(abs
, d
)(float64 a
)
2339 return float64_abs(a
);
2342 float32
VFP_HELPER(sqrt
, s
)(float32 a
, CPUState
*env
)
2344 return float32_sqrt(a
, &env
->vfp
.fp_status
);
2347 float64
VFP_HELPER(sqrt
, d
)(float64 a
, CPUState
*env
)
2349 return float64_sqrt(a
, &env
->vfp
.fp_status
);
2352 /* XXX: check quiet/signaling case */
2353 #define DO_VFP_cmp(p, type) \
2354 void VFP_HELPER(cmp, p)(type a, type b, CPUState *env) \
2357 switch(type ## _compare_quiet(a, b, &env->vfp.fp_status)) { \
2358 case 0: flags = 0x6; break; \
2359 case -1: flags = 0x8; break; \
2360 case 1: flags = 0x2; break; \
2361 default: case 2: flags = 0x3; break; \
2363 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2364 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2366 void VFP_HELPER(cmpe, p)(type a, type b, CPUState *env) \
2369 switch(type ## _compare(a, b, &env->vfp.fp_status)) { \
2370 case 0: flags = 0x6; break; \
2371 case -1: flags = 0x8; break; \
2372 case 1: flags = 0x2; break; \
2373 default: case 2: flags = 0x3; break; \
2375 env->vfp.xregs[ARM_VFP_FPSCR] = (flags << 28) \
2376 | (env->vfp.xregs[ARM_VFP_FPSCR] & 0x0fffffff); \
2378 DO_VFP_cmp(s
, float32
)
2379 DO_VFP_cmp(d
, float64
)
2382 /* Helper routines to perform bitwise copies between float and int. */
2383 static inline float32
vfp_itos(uint32_t i
)
2394 static inline uint32_t vfp_stoi(float32 s
)
2405 static inline float64
vfp_itod(uint64_t i
)
2416 static inline uint64_t vfp_dtoi(float64 d
)
2427 /* Integer to float conversion. */
2428 float32
VFP_HELPER(uito
, s
)(float32 x
, CPUState
*env
)
2430 return uint32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2433 float64
VFP_HELPER(uito
, d
)(float32 x
, CPUState
*env
)
2435 return uint32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2438 float32
VFP_HELPER(sito
, s
)(float32 x
, CPUState
*env
)
2440 return int32_to_float32(vfp_stoi(x
), &env
->vfp
.fp_status
);
2443 float64
VFP_HELPER(sito
, d
)(float32 x
, CPUState
*env
)
2445 return int32_to_float64(vfp_stoi(x
), &env
->vfp
.fp_status
);
2448 /* Float to integer conversion. */
2449 float32
VFP_HELPER(toui
, s
)(float32 x
, CPUState
*env
)
2451 return vfp_itos(float32_to_uint32(x
, &env
->vfp
.fp_status
));
2454 float32
VFP_HELPER(toui
, d
)(float64 x
, CPUState
*env
)
2456 return vfp_itos(float64_to_uint32(x
, &env
->vfp
.fp_status
));
2459 float32
VFP_HELPER(tosi
, s
)(float32 x
, CPUState
*env
)
2461 return vfp_itos(float32_to_int32(x
, &env
->vfp
.fp_status
));
2464 float32
VFP_HELPER(tosi
, d
)(float64 x
, CPUState
*env
)
2466 return vfp_itos(float64_to_int32(x
, &env
->vfp
.fp_status
));
2469 float32
VFP_HELPER(touiz
, s
)(float32 x
, CPUState
*env
)
2471 return vfp_itos(float32_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2474 float32
VFP_HELPER(touiz
, d
)(float64 x
, CPUState
*env
)
2476 return vfp_itos(float64_to_uint32_round_to_zero(x
, &env
->vfp
.fp_status
));
2479 float32
VFP_HELPER(tosiz
, s
)(float32 x
, CPUState
*env
)
2481 return vfp_itos(float32_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2484 float32
VFP_HELPER(tosiz
, d
)(float64 x
, CPUState
*env
)
2486 return vfp_itos(float64_to_int32_round_to_zero(x
, &env
->vfp
.fp_status
));
2489 /* floating point conversion */
2490 float64
VFP_HELPER(fcvtd
, s
)(float32 x
, CPUState
*env
)
2492 return float32_to_float64(x
, &env
->vfp
.fp_status
);
2495 float32
VFP_HELPER(fcvts
, d
)(float64 x
, CPUState
*env
)
2497 return float64_to_float32(x
, &env
->vfp
.fp_status
);
2500 /* VFP3 fixed point conversion. */
2501 #define VFP_CONV_FIX(name, p, ftype, itype, sign) \
2502 ftype VFP_HELPER(name##to, p)(ftype x, uint32_t shift, CPUState *env) \
2505 tmp = sign##int32_to_##ftype ((itype)vfp_##p##toi(x), \
2506 &env->vfp.fp_status); \
2507 return ftype##_scalbn(tmp, -(int)shift, &env->vfp.fp_status); \
2509 ftype VFP_HELPER(to##name, p)(ftype x, uint32_t shift, CPUState *env) \
2512 tmp = ftype##_scalbn(x, shift, &env->vfp.fp_status); \
2513 return vfp_ito##p((itype)ftype##_to_##sign##int32_round_to_zero(tmp, \
2514 &env->vfp.fp_status)); \
2517 VFP_CONV_FIX(sh
, d
, float64
, int16
, )
2518 VFP_CONV_FIX(sl
, d
, float64
, int32
, )
2519 VFP_CONV_FIX(uh
, d
, float64
, uint16
, u
)
2520 VFP_CONV_FIX(ul
, d
, float64
, uint32
, u
)
2521 VFP_CONV_FIX(sh
, s
, float32
, int16
, )
2522 VFP_CONV_FIX(sl
, s
, float32
, int32
, )
2523 VFP_CONV_FIX(uh
, s
, float32
, uint16
, u
)
2524 VFP_CONV_FIX(ul
, s
, float32
, uint32
, u
)
2527 /* Half precision conversions. */
2528 float32
HELPER(vfp_fcvt_f16_to_f32
)(uint32_t a
, CPUState
*env
)
2530 float_status
*s
= &env
->vfp
.fp_status
;
2531 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
2532 return float16_to_float32(a
, ieee
, s
);
2535 uint32_t HELPER(vfp_fcvt_f32_to_f16
)(float32 a
, CPUState
*env
)
2537 float_status
*s
= &env
->vfp
.fp_status
;
2538 int ieee
= (env
->vfp
.xregs
[ARM_VFP_FPSCR
] & (1 << 26)) == 0;
2539 return float32_to_float16(a
, ieee
, s
);
2542 float32
HELPER(recps_f32
)(float32 a
, float32 b
, CPUState
*env
)
2544 float_status
*s
= &env
->vfp
.fp_status
;
2545 float32 two
= int32_to_float32(2, s
);
2546 return float32_sub(two
, float32_mul(a
, b
, s
), s
);
2549 float32
HELPER(rsqrts_f32
)(float32 a
, float32 b
, CPUState
*env
)
2551 float_status
*s
= &env
->vfp
.fp_status
;
2552 float32 three
= int32_to_float32(3, s
);
2553 return float32_sub(three
, float32_mul(a
, b
, s
), s
);
2558 /* TODO: The architecture specifies the value that the estimate functions
2559 should return. We return the exact reciprocal/root instead. */
2560 float32
HELPER(recpe_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
, a
, s
);
2567 float32
HELPER(rsqrte_f32
)(float32 a
, CPUState
*env
)
2569 float_status
*s
= &env
->vfp
.fp_status
;
2570 float32 one
= int32_to_float32(1, s
);
2571 return float32_div(one
, float32_sqrt(a
, s
), s
);
2574 uint32_t HELPER(recpe_u32
)(uint32_t a
, CPUState
*env
)
2576 float_status
*s
= &env
->vfp
.fp_status
;
2578 tmp
= int32_to_float32(a
, s
);
2579 tmp
= float32_scalbn(tmp
, -32, s
);
2580 tmp
= helper_recpe_f32(tmp
, env
);
2581 tmp
= float32_scalbn(tmp
, 31, s
);
2582 return float32_to_int32(tmp
, s
);
2585 uint32_t HELPER(rsqrte_u32
)(uint32_t a
, CPUState
*env
)
2587 float_status
*s
= &env
->vfp
.fp_status
;
2589 tmp
= int32_to_float32(a
, s
);
2590 tmp
= float32_scalbn(tmp
, -32, s
);
2591 tmp
= helper_rsqrte_f32(tmp
, env
);
2592 tmp
= float32_scalbn(tmp
, 31, s
);
2593 return float32_to_int32(tmp
, s
);
2596 void HELPER(set_teecr
)(CPUState
*env
, uint32_t val
)
2599 if (env
->teecr
!= val
) {