]>
git.proxmox.com Git - qemu.git/blob - target-arm/helper.c
9 static uint32_t cortexa8_cp15_c0_c1
[8] =
10 { 0x1031, 0x11, 0x400, 0, 0x31100003, 0x20000000, 0x01202000, 0x11 };
12 static uint32_t cortexa8_cp15_c0_c2
[8] =
13 { 0x00101111, 0x12112111, 0x21232031, 0x11112131, 0x00111142, 0, 0, 0 };
15 static uint32_t mpcore_cp15_c0_c1
[8] =
16 { 0x111, 0x1, 0, 0x2, 0x01100103, 0x10020302, 0x01222000, 0 };
18 static uint32_t mpcore_cp15_c0_c2
[8] =
19 { 0x00100011, 0x12002111, 0x11221011, 0x01102131, 0x141, 0, 0, 0 };
21 static uint32_t arm1136_cp15_c0_c1
[8] =
22 { 0x111, 0x1, 0x2, 0x3, 0x01130003, 0x10030302, 0x01222110, 0 };
24 static uint32_t arm1136_cp15_c0_c2
[8] =
25 { 0x00140011, 0x12002111, 0x11231111, 0x01102131, 0x141, 0, 0, 0 };
27 static uint32_t cpu_arm_find_by_name(const char *name
);
29 static inline void set_feature(CPUARMState
*env
, int feature
)
31 env
->features
|= 1u << feature
;
34 static void cpu_reset_model_id(CPUARMState
*env
, uint32_t id
)
36 env
->cp15
.c0_cpuid
= id
;
38 case ARM_CPUID_ARM926
:
39 set_feature(env
, ARM_FEATURE_VFP
);
40 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x41011090;
41 env
->cp15
.c0_cachetype
= 0x1dd20d2;
42 env
->cp15
.c1_sys
= 0x00090078;
44 case ARM_CPUID_ARM946
:
45 set_feature(env
, ARM_FEATURE_MPU
);
46 env
->cp15
.c0_cachetype
= 0x0f004006;
47 env
->cp15
.c1_sys
= 0x00000078;
49 case ARM_CPUID_ARM1026
:
50 set_feature(env
, ARM_FEATURE_VFP
);
51 set_feature(env
, ARM_FEATURE_AUXCR
);
52 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410110a0;
53 env
->cp15
.c0_cachetype
= 0x1dd20d2;
54 env
->cp15
.c1_sys
= 0x00090078;
56 case ARM_CPUID_ARM1136
:
57 set_feature(env
, ARM_FEATURE_V6
);
58 set_feature(env
, ARM_FEATURE_VFP
);
59 set_feature(env
, ARM_FEATURE_AUXCR
);
60 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
61 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
62 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
63 memcpy(env
->cp15
.c0_c1
, arm1136_cp15_c0_c1
, 8 * sizeof(uint32_t));
64 memcpy(env
->cp15
.c0_c1
, arm1136_cp15_c0_c2
, 8 * sizeof(uint32_t));
65 env
->cp15
.c0_cachetype
= 0x1dd20d2;
67 case ARM_CPUID_ARM11MPCORE
:
68 set_feature(env
, ARM_FEATURE_V6
);
69 set_feature(env
, ARM_FEATURE_V6K
);
70 set_feature(env
, ARM_FEATURE_VFP
);
71 set_feature(env
, ARM_FEATURE_AUXCR
);
72 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410120b4;
73 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11111111;
74 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00000000;
75 memcpy(env
->cp15
.c0_c1
, mpcore_cp15_c0_c1
, 8 * sizeof(uint32_t));
76 memcpy(env
->cp15
.c0_c1
, mpcore_cp15_c0_c2
, 8 * sizeof(uint32_t));
77 env
->cp15
.c0_cachetype
= 0x1dd20d2;
79 case ARM_CPUID_CORTEXA8
:
80 set_feature(env
, ARM_FEATURE_V6
);
81 set_feature(env
, ARM_FEATURE_V6K
);
82 set_feature(env
, ARM_FEATURE_V7
);
83 set_feature(env
, ARM_FEATURE_AUXCR
);
84 set_feature(env
, ARM_FEATURE_THUMB2
);
85 set_feature(env
, ARM_FEATURE_VFP
);
86 set_feature(env
, ARM_FEATURE_VFP3
);
87 set_feature(env
, ARM_FEATURE_NEON
);
88 env
->vfp
.xregs
[ARM_VFP_FPSID
] = 0x410330c0;
89 env
->vfp
.xregs
[ARM_VFP_MVFR0
] = 0x11110222;
90 env
->vfp
.xregs
[ARM_VFP_MVFR1
] = 0x00011100;
91 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c1
, 8 * sizeof(uint32_t));
92 memcpy(env
->cp15
.c0_c1
, cortexa8_cp15_c0_c2
, 8 * sizeof(uint32_t));
93 env
->cp15
.c0_cachetype
= 0x1dd20d2;
95 case ARM_CPUID_CORTEXM3
:
96 set_feature(env
, ARM_FEATURE_V6
);
97 set_feature(env
, ARM_FEATURE_THUMB2
);
98 set_feature(env
, ARM_FEATURE_V7
);
99 set_feature(env
, ARM_FEATURE_M
);
100 set_feature(env
, ARM_FEATURE_DIV
);
102 case ARM_CPUID_ANY
: /* For userspace emulation. */
103 set_feature(env
, ARM_FEATURE_V6
);
104 set_feature(env
, ARM_FEATURE_V6K
);
105 set_feature(env
, ARM_FEATURE_V7
);
106 set_feature(env
, ARM_FEATURE_THUMB2
);
107 set_feature(env
, ARM_FEATURE_VFP
);
108 set_feature(env
, ARM_FEATURE_VFP3
);
109 set_feature(env
, ARM_FEATURE_NEON
);
110 set_feature(env
, ARM_FEATURE_DIV
);
112 case ARM_CPUID_TI915T
:
113 case ARM_CPUID_TI925T
:
114 set_feature(env
, ARM_FEATURE_OMAPCP
);
115 env
->cp15
.c0_cpuid
= ARM_CPUID_TI925T
; /* Depends on wiring. */
116 env
->cp15
.c0_cachetype
= 0x5109149;
117 env
->cp15
.c1_sys
= 0x00000070;
118 env
->cp15
.c15_i_max
= 0x000;
119 env
->cp15
.c15_i_min
= 0xff0;
121 case ARM_CPUID_PXA250
:
122 case ARM_CPUID_PXA255
:
123 case ARM_CPUID_PXA260
:
124 case ARM_CPUID_PXA261
:
125 case ARM_CPUID_PXA262
:
126 set_feature(env
, ARM_FEATURE_XSCALE
);
127 /* JTAG_ID is ((id << 28) | 0x09265013) */
128 env
->cp15
.c0_cachetype
= 0xd172172;
129 env
->cp15
.c1_sys
= 0x00000078;
131 case ARM_CPUID_PXA270_A0
:
132 case ARM_CPUID_PXA270_A1
:
133 case ARM_CPUID_PXA270_B0
:
134 case ARM_CPUID_PXA270_B1
:
135 case ARM_CPUID_PXA270_C0
:
136 case ARM_CPUID_PXA270_C5
:
137 set_feature(env
, ARM_FEATURE_XSCALE
);
138 /* JTAG_ID is ((id << 28) | 0x09265013) */
139 set_feature(env
, ARM_FEATURE_IWMMXT
);
140 env
->iwmmxt
.cregs
[ARM_IWMMXT_wCID
] = 0x69051000 | 'Q';
141 env
->cp15
.c0_cachetype
= 0xd172172;
142 env
->cp15
.c1_sys
= 0x00000078;
145 cpu_abort(env
, "Bad CPU ID: %x\n", id
);
150 void cpu_reset(CPUARMState
*env
)
153 id
= env
->cp15
.c0_cpuid
;
154 memset(env
, 0, offsetof(CPUARMState
, breakpoints
));
156 cpu_reset_model_id(env
, id
);
157 #if defined (CONFIG_USER_ONLY)
158 env
->uncached_cpsr
= ARM_CPU_MODE_USR
;
159 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 1 << 30;
161 /* SVC mode with interrupts disabled. */
162 env
->uncached_cpsr
= ARM_CPU_MODE_SVC
| CPSR_A
| CPSR_F
| CPSR_I
;
163 /* On ARMv7-M the CPSR_I is the value of the PRIMASK register, and is
166 env
->uncached_cpsr
&= ~CPSR_I
;
167 env
->vfp
.xregs
[ARM_VFP_FPEXC
] = 0;
173 CPUARMState
*cpu_arm_init(const char *cpu_model
)
178 id
= cpu_arm_find_by_name(cpu_model
);
181 env
= qemu_mallocz(sizeof(CPUARMState
));
185 env
->cp15
.c0_cpuid
= id
;
195 static const struct arm_cpu_t arm_cpu_names
[] = {
196 { ARM_CPUID_ARM926
, "arm926"},
197 { ARM_CPUID_ARM946
, "arm946"},
198 { ARM_CPUID_ARM1026
, "arm1026"},
199 { ARM_CPUID_ARM1136
, "arm1136"},
200 { ARM_CPUID_ARM11MPCORE
, "arm11mpcore"},
201 { ARM_CPUID_CORTEXM3
, "cortex-m3"},
202 { ARM_CPUID_CORTEXA8
, "cortex-a8"},
203 { ARM_CPUID_TI925T
, "ti925t" },
204 { ARM_CPUID_PXA250
, "pxa250" },
205 { ARM_CPUID_PXA255
, "pxa255" },
206 { ARM_CPUID_PXA260
, "pxa260" },
207 { ARM_CPUID_PXA261
, "pxa261" },
208 { ARM_CPUID_PXA262
, "pxa262" },
209 { ARM_CPUID_PXA270
, "pxa270" },
210 { ARM_CPUID_PXA270_A0
, "pxa270-a0" },
211 { ARM_CPUID_PXA270_A1
, "pxa270-a1" },
212 { ARM_CPUID_PXA270_B0
, "pxa270-b0" },
213 { ARM_CPUID_PXA270_B1
, "pxa270-b1" },
214 { ARM_CPUID_PXA270_C0
, "pxa270-c0" },
215 { ARM_CPUID_PXA270_C5
, "pxa270-c5" },
216 { ARM_CPUID_ANY
, "any"},
220 void arm_cpu_list(FILE *f
, int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...))
224 (*cpu_fprintf
)(f
, "Available CPUs:\n");
225 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
226 (*cpu_fprintf
)(f
, " %s\n", arm_cpu_names
[i
].name
);
230 /* return 0 if not found */
231 static uint32_t cpu_arm_find_by_name(const char *name
)
237 for (i
= 0; arm_cpu_names
[i
].name
; i
++) {
238 if (strcmp(name
, arm_cpu_names
[i
].name
) == 0) {
239 id
= arm_cpu_names
[i
].id
;
246 void cpu_arm_close(CPUARMState
*env
)
251 /* Polynomial multiplication is like integer multiplcation except the
252 partial products are XORed, not added. */
253 uint32_t helper_neon_mul_p8(uint32_t op1
, uint32_t op2
)
265 mask
|= (0xff << 16);
267 mask
|= (0xff << 24);
268 result
^= op2
& mask
;
269 op1
= (op1
>> 1) & 0x7f7f7f7f;
270 op2
= (op2
<< 1) & 0xfefefefe;
275 uint32_t cpsr_read(CPUARMState
*env
)
278 ZF
= (env
->NZF
== 0);
279 return env
->uncached_cpsr
| (env
->NZF
& 0x80000000) | (ZF
<< 30) |
280 (env
->CF
<< 29) | ((env
->VF
& 0x80000000) >> 3) | (env
->QF
<< 27)
281 | (env
->thumb
<< 5) | ((env
->condexec_bits
& 3) << 25)
282 | ((env
->condexec_bits
& 0xfc) << 8)
286 void cpsr_write(CPUARMState
*env
, uint32_t val
, uint32_t mask
)
288 /* NOTE: N = 1 and Z = 1 cannot be stored currently */
289 if (mask
& CPSR_NZCV
) {
290 env
->NZF
= (val
& 0xc0000000) ^ 0x40000000;
291 env
->CF
= (val
>> 29) & 1;
292 env
->VF
= (val
<< 3) & 0x80000000;
295 env
->QF
= ((val
& CPSR_Q
) != 0);
297 env
->thumb
= ((val
& CPSR_T
) != 0);
298 if (mask
& CPSR_IT_0_1
) {
299 env
->condexec_bits
&= ~3;
300 env
->condexec_bits
|= (val
>> 25) & 3;
302 if (mask
& CPSR_IT_2_7
) {
303 env
->condexec_bits
&= 3;
304 env
->condexec_bits
|= (val
>> 8) & 0xfc;
306 if (mask
& CPSR_GE
) {
307 env
->GE
= (val
>> 16) & 0xf;
310 if ((env
->uncached_cpsr
^ val
) & mask
& CPSR_M
) {
311 switch_mode(env
, val
& CPSR_M
);
313 mask
&= ~CACHED_CPSR_BITS
;
314 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~mask
) | (val
& mask
);
317 #if defined(CONFIG_USER_ONLY)
319 void do_interrupt (CPUState
*env
)
321 env
->exception_index
= -1;
324 /* Structure used to record exclusive memory locations. */
325 typedef struct mmon_state
{
326 struct mmon_state
*next
;
327 CPUARMState
*cpu_env
;
331 /* Chain of current locks. */
332 static mmon_state
* mmon_head
= NULL
;
334 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
, int rw
,
335 int mmu_idx
, int is_softmmu
)
338 env
->exception_index
= EXCP_PREFETCH_ABORT
;
339 env
->cp15
.c6_insn
= address
;
341 env
->exception_index
= EXCP_DATA_ABORT
;
342 env
->cp15
.c6_data
= address
;
347 static void allocate_mmon_state(CPUState
*env
)
349 env
->mmon_entry
= malloc(sizeof (mmon_state
));
350 if (!env
->mmon_entry
)
352 memset (env
->mmon_entry
, 0, sizeof (mmon_state
));
353 env
->mmon_entry
->cpu_env
= env
;
354 mmon_head
= env
->mmon_entry
;
357 /* Flush any monitor locks for the specified address. */
358 static void flush_mmon(uint32_t addr
)
362 for (mon
= mmon_head
; mon
; mon
= mon
->next
)
364 if (mon
->addr
!= addr
)
372 /* Mark an address for exclusive access. */
373 void helper_mark_exclusive(CPUState
*env
, uint32_t addr
)
375 if (!env
->mmon_entry
)
376 allocate_mmon_state(env
);
377 /* Clear any previous locks. */
379 env
->mmon_entry
->addr
= addr
;
382 /* Test if an exclusive address is still exclusive. Returns zero
383 if the address is still exclusive. */
384 int helper_test_exclusive(CPUState
*env
, uint32_t addr
)
388 if (!env
->mmon_entry
)
390 if (env
->mmon_entry
->addr
== addr
)
398 void helper_clrex(CPUState
*env
)
400 if (!(env
->mmon_entry
&& env
->mmon_entry
->addr
))
402 flush_mmon(env
->mmon_entry
->addr
);
405 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
410 /* These should probably raise undefined insn exceptions. */
411 void helper_set_cp(CPUState
*env
, uint32_t insn
, uint32_t val
)
413 int op1
= (insn
>> 8) & 0xf;
414 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
418 uint32_t helper_get_cp(CPUState
*env
, uint32_t insn
)
420 int op1
= (insn
>> 8) & 0xf;
421 cpu_abort(env
, "cp%i insn %08x\n", op1
, insn
);
425 void helper_set_cp15(CPUState
*env
, uint32_t insn
, uint32_t val
)
427 cpu_abort(env
, "cp15 insn %08x\n", insn
);
430 uint32_t helper_get_cp15(CPUState
*env
, uint32_t insn
)
432 cpu_abort(env
, "cp15 insn %08x\n", insn
);
436 /* These should probably raise undefined insn exceptions. */
437 void helper_v7m_msr(CPUState
*env
, int reg
, uint32_t val
)
439 cpu_abort(env
, "v7m_mrs %d\n", reg
);
442 uint32_t helper_v7m_mrs(CPUState
*env
, int reg
)
444 cpu_abort(env
, "v7m_mrs %d\n", reg
);
448 void switch_mode(CPUState
*env
, int mode
)
450 if (mode
!= ARM_CPU_MODE_USR
)
451 cpu_abort(env
, "Tried to switch out of user mode\n");
454 void helper_set_r13_banked(CPUState
*env
, int mode
, uint32_t val
)
456 cpu_abort(env
, "banked r13 write\n");
459 uint32_t helper_get_r13_banked(CPUState
*env
, int mode
)
461 cpu_abort(env
, "banked r13 read\n");
467 extern int semihosting_enabled
;
469 /* Map CPU modes onto saved register banks. */
470 static inline int bank_number (int mode
)
473 case ARM_CPU_MODE_USR
:
474 case ARM_CPU_MODE_SYS
:
476 case ARM_CPU_MODE_SVC
:
478 case ARM_CPU_MODE_ABT
:
480 case ARM_CPU_MODE_UND
:
482 case ARM_CPU_MODE_IRQ
:
484 case ARM_CPU_MODE_FIQ
:
487 cpu_abort(cpu_single_env
, "Bad mode %x\n", mode
);
491 void switch_mode(CPUState
*env
, int mode
)
496 old_mode
= env
->uncached_cpsr
& CPSR_M
;
497 if (mode
== old_mode
)
500 if (old_mode
== ARM_CPU_MODE_FIQ
) {
501 memcpy (env
->fiq_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
502 memcpy (env
->regs
+ 8, env
->usr_regs
, 5 * sizeof(uint32_t));
503 } else if (mode
== ARM_CPU_MODE_FIQ
) {
504 memcpy (env
->usr_regs
, env
->regs
+ 8, 5 * sizeof(uint32_t));
505 memcpy (env
->regs
+ 8, env
->fiq_regs
, 5 * sizeof(uint32_t));
508 i
= bank_number(old_mode
);
509 env
->banked_r13
[i
] = env
->regs
[13];
510 env
->banked_r14
[i
] = env
->regs
[14];
511 env
->banked_spsr
[i
] = env
->spsr
;
513 i
= bank_number(mode
);
514 env
->regs
[13] = env
->banked_r13
[i
];
515 env
->regs
[14] = env
->banked_r14
[i
];
516 env
->spsr
= env
->banked_spsr
[i
];
519 static void v7m_push(CPUARMState
*env
, uint32_t val
)
522 stl_phys(env
->regs
[13], val
);
525 static uint32_t v7m_pop(CPUARMState
*env
)
528 val
= ldl_phys(env
->regs
[13]);
533 /* Switch to V7M main or process stack pointer. */
534 static void switch_v7m_sp(CPUARMState
*env
, int process
)
537 if (env
->v7m
.current_sp
!= process
) {
538 tmp
= env
->v7m
.other_sp
;
539 env
->v7m
.other_sp
= env
->regs
[13];
541 env
->v7m
.current_sp
= process
;
545 static void do_v7m_exception_exit(CPUARMState
*env
)
550 type
= env
->regs
[15];
551 if (env
->v7m
.exception
!= 0)
552 armv7m_nvic_complete_irq(env
->v7m
.nvic
, env
->v7m
.exception
);
554 /* Switch to the target stack. */
555 switch_v7m_sp(env
, (type
& 4) != 0);
557 env
->regs
[0] = v7m_pop(env
);
558 env
->regs
[1] = v7m_pop(env
);
559 env
->regs
[2] = v7m_pop(env
);
560 env
->regs
[3] = v7m_pop(env
);
561 env
->regs
[12] = v7m_pop(env
);
562 env
->regs
[14] = v7m_pop(env
);
563 env
->regs
[15] = v7m_pop(env
);
565 xpsr_write(env
, xpsr
, 0xfffffdff);
566 /* Undo stack alignment. */
569 /* ??? The exception return type specifies Thread/Handler mode. However
570 this is also implied by the xPSR value. Not sure what to do
571 if there is a mismatch. */
572 /* ??? Likewise for mismatches between the CONTROL register and the stack
576 void do_interrupt_v7m(CPUARMState
*env
)
578 uint32_t xpsr
= xpsr_read(env
);
583 if (env
->v7m
.current_sp
)
585 if (env
->v7m
.exception
== 0)
588 /* For exceptions we just mark as pending on the NVIC, and let that
590 /* TODO: Need to escalate if the current priority is higher than the
591 one we're raising. */
592 switch (env
->exception_index
) {
594 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_USAGE
);
598 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_SVC
);
600 case EXCP_PREFETCH_ABORT
:
601 case EXCP_DATA_ABORT
:
602 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_MEM
);
605 if (semihosting_enabled
) {
607 nr
= lduw_code(env
->regs
[15]) & 0xff;
610 env
->regs
[0] = do_arm_semihosting(env
);
614 armv7m_nvic_set_pending(env
->v7m
.nvic
, ARMV7M_EXCP_DEBUG
);
617 env
->v7m
.exception
= armv7m_nvic_acknowledge_irq(env
->v7m
.nvic
);
619 case EXCP_EXCEPTION_EXIT
:
620 do_v7m_exception_exit(env
);
623 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
624 return; /* Never happens. Keep compiler happy. */
627 /* Align stack pointer. */
628 /* ??? Should only do this if Configuration Control Register
629 STACKALIGN bit is set. */
630 if (env
->regs
[13] & 4) {
634 /* Switch to the hander mode. */
636 v7m_push(env
, env
->regs
[15]);
637 v7m_push(env
, env
->regs
[14]);
638 v7m_push(env
, env
->regs
[12]);
639 v7m_push(env
, env
->regs
[3]);
640 v7m_push(env
, env
->regs
[2]);
641 v7m_push(env
, env
->regs
[1]);
642 v7m_push(env
, env
->regs
[0]);
643 switch_v7m_sp(env
, 0);
644 env
->uncached_cpsr
&= ~CPSR_IT
;
646 addr
= ldl_phys(env
->v7m
.vecbase
+ env
->v7m
.exception
* 4);
647 env
->regs
[15] = addr
& 0xfffffffe;
648 env
->thumb
= addr
& 1;
651 /* Handle a CPU exception. */
652 void do_interrupt(CPUARMState
*env
)
660 do_interrupt_v7m(env
);
663 /* TODO: Vectored interrupt controller. */
664 switch (env
->exception_index
) {
666 new_mode
= ARM_CPU_MODE_UND
;
675 if (semihosting_enabled
) {
676 /* Check for semihosting interrupt. */
678 mask
= lduw_code(env
->regs
[15] - 2) & 0xff;
680 mask
= ldl_code(env
->regs
[15] - 4) & 0xffffff;
682 /* Only intercept calls from privileged modes, to provide some
683 semblance of security. */
684 if (((mask
== 0x123456 && !env
->thumb
)
685 || (mask
== 0xab && env
->thumb
))
686 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
687 env
->regs
[0] = do_arm_semihosting(env
);
691 new_mode
= ARM_CPU_MODE_SVC
;
694 /* The PC already points to the next instructon. */
698 /* See if this is a semihosting syscall. */
699 if (env
->thumb
&& semihosting_enabled
) {
700 mask
= lduw_code(env
->regs
[15]) & 0xff;
702 && (env
->uncached_cpsr
& CPSR_M
) != ARM_CPU_MODE_USR
) {
704 env
->regs
[0] = do_arm_semihosting(env
);
708 /* Fall through to prefetch abort. */
709 case EXCP_PREFETCH_ABORT
:
710 new_mode
= ARM_CPU_MODE_ABT
;
712 mask
= CPSR_A
| CPSR_I
;
715 case EXCP_DATA_ABORT
:
716 new_mode
= ARM_CPU_MODE_ABT
;
718 mask
= CPSR_A
| CPSR_I
;
722 new_mode
= ARM_CPU_MODE_IRQ
;
724 /* Disable IRQ and imprecise data aborts. */
725 mask
= CPSR_A
| CPSR_I
;
729 new_mode
= ARM_CPU_MODE_FIQ
;
731 /* Disable FIQ, IRQ and imprecise data aborts. */
732 mask
= CPSR_A
| CPSR_I
| CPSR_F
;
736 cpu_abort(env
, "Unhandled exception 0x%x\n", env
->exception_index
);
737 return; /* Never happens. Keep compiler happy. */
740 if (env
->cp15
.c1_sys
& (1 << 13)) {
743 switch_mode (env
, new_mode
);
744 env
->spsr
= cpsr_read(env
);
746 env
->condexec_bits
= 0;
747 /* Switch to the new mode, and switch to Arm mode. */
748 /* ??? Thumb interrupt handlers not implemented. */
749 env
->uncached_cpsr
= (env
->uncached_cpsr
& ~CPSR_M
) | new_mode
;
750 env
->uncached_cpsr
|= mask
;
752 env
->regs
[14] = env
->regs
[15] + offset
;
753 env
->regs
[15] = addr
;
754 env
->interrupt_request
|= CPU_INTERRUPT_EXITTB
;
757 /* Check section/page access permissions.
758 Returns the page protection flags, or zero if the access is not
760 static inline int check_ap(CPUState
*env
, int ap
, int domain
, int access_type
,
766 return PAGE_READ
| PAGE_WRITE
;
768 if (access_type
== 1)
775 if (access_type
== 1)
777 switch ((env
->cp15
.c1_sys
>> 8) & 3) {
779 return is_user
? 0 : PAGE_READ
;
786 return is_user
? 0 : PAGE_READ
| PAGE_WRITE
;
791 return PAGE_READ
| PAGE_WRITE
;
793 return PAGE_READ
| PAGE_WRITE
;
794 case 4: case 7: /* Reserved. */
797 return is_user
? 0 : prot_ro
;
805 static int get_phys_addr_v5(CPUState
*env
, uint32_t address
, int access_type
,
806 int is_user
, uint32_t *phys_ptr
, int *prot
)
816 /* Pagetable walk. */
817 /* Lookup l1 descriptor. */
818 if (address
& env
->cp15
.c2_mask
)
819 table
= env
->cp15
.c2_base1
;
821 table
= env
->cp15
.c2_base0
;
822 table
= (table
& 0xffffc000) | ((address
>> 18) & 0x3ffc);
823 desc
= ldl_phys(table
);
825 domain
= (env
->cp15
.c3
>> ((desc
>> 4) & 0x1e)) & 3;
827 /* Secton translation fault. */
831 if (domain
== 0 || domain
== 2) {
833 code
= 9; /* Section domain fault. */
835 code
= 11; /* Page domain fault. */
840 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
841 ap
= (desc
>> 10) & 3;
844 /* Lookup l2 entry. */
846 /* Coarse pagetable. */
847 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
849 /* Fine pagetable. */
850 table
= (desc
& 0xfffff000) | ((address
>> 8) & 0xffc);
852 desc
= ldl_phys(table
);
854 case 0: /* Page translation fault. */
857 case 1: /* 64k page. */
858 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
859 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
861 case 2: /* 4k page. */
862 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
863 ap
= (desc
>> (4 + ((address
>> 13) & 6))) & 3;
865 case 3: /* 1k page. */
867 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
868 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
870 /* Page translation fault. */
875 phys_addr
= (desc
& 0xfffffc00) | (address
& 0x3ff);
877 ap
= (desc
>> 4) & 3;
880 /* Never happens, but compiler isn't smart enough to tell. */
885 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
887 /* Access permission fault. */
890 *phys_ptr
= phys_addr
;
893 return code
| (domain
<< 4);
896 static int get_phys_addr_v6(CPUState
*env
, uint32_t address
, int access_type
,
897 int is_user
, uint32_t *phys_ptr
, int *prot
)
908 /* Pagetable walk. */
909 /* Lookup l1 descriptor. */
910 if (address
& env
->cp15
.c2_mask
)
911 table
= env
->cp15
.c2_base1
;
913 table
= env
->cp15
.c2_base0
;
914 table
= (table
& 0xffffc000) | ((address
>> 18) & 0x3ffc);
915 desc
= ldl_phys(table
);
918 /* Secton translation fault. */
922 } else if (type
== 2 && (desc
& (1 << 18))) {
926 /* Section or page. */
927 domain
= (desc
>> 4) & 0x1e;
929 domain
= (env
->cp15
.c3
>> domain
) & 3;
930 if (domain
== 0 || domain
== 2) {
932 code
= 9; /* Section domain fault. */
934 code
= 11; /* Page domain fault. */
938 if (desc
& (1 << 18)) {
940 phys_addr
= (desc
& 0xff000000) | (address
& 0x00ffffff);
943 phys_addr
= (desc
& 0xfff00000) | (address
& 0x000fffff);
945 ap
= ((desc
>> 10) & 3) | ((desc
>> 13) & 4);
946 xn
= desc
& (1 << 4);
949 /* Lookup l2 entry. */
950 table
= (desc
& 0xfffffc00) | ((address
>> 10) & 0x3fc);
951 desc
= ldl_phys(table
);
952 ap
= ((desc
>> 4) & 3) | ((desc
>> 7) & 4);
954 case 0: /* Page translation fault. */
957 case 1: /* 64k page. */
958 phys_addr
= (desc
& 0xffff0000) | (address
& 0xffff);
959 xn
= desc
& (1 << 15);
961 case 2: case 3: /* 4k page. */
962 phys_addr
= (desc
& 0xfffff000) | (address
& 0xfff);
966 /* Never happens, but compiler isn't smart enough to tell. */
971 if (xn
&& access_type
== 2)
974 *prot
= check_ap(env
, ap
, domain
, access_type
, is_user
);
976 /* Access permission fault. */
979 *phys_ptr
= phys_addr
;
982 return code
| (domain
<< 4);
985 static int get_phys_addr_mpu(CPUState
*env
, uint32_t address
, int access_type
,
986 int is_user
, uint32_t *phys_ptr
, int *prot
)
993 for (n
= 7; n
>= 0; n
--) {
994 base
= env
->cp15
.c6_region
[n
];
997 mask
= 1 << ((base
>> 1) & 0x1f);
998 /* Keep this shift separate from the above to avoid an
999 (undefined) << 32. */
1000 mask
= (mask
<< 1) - 1;
1001 if (((base
^ address
) & ~mask
) == 0)
1007 if (access_type
== 2) {
1008 mask
= env
->cp15
.c5_insn
;
1010 mask
= env
->cp15
.c5_data
;
1012 mask
= (mask
>> (n
* 4)) & 0xf;
1019 *prot
= PAGE_READ
| PAGE_WRITE
;
1024 *prot
|= PAGE_WRITE
;
1027 *prot
= PAGE_READ
| PAGE_WRITE
;
1038 /* Bad permission. */
1044 static inline int get_phys_addr(CPUState
*env
, uint32_t address
,
1045 int access_type
, int is_user
,
1046 uint32_t *phys_ptr
, int *prot
)
1048 /* Fast Context Switch Extension. */
1049 if (address
< 0x02000000)
1050 address
+= env
->cp15
.c13_fcse
;
1052 if ((env
->cp15
.c1_sys
& 1) == 0) {
1053 /* MMU/MPU disabled. */
1054 *phys_ptr
= address
;
1055 *prot
= PAGE_READ
| PAGE_WRITE
;
1057 } else if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1058 return get_phys_addr_mpu(env
, address
, access_type
, is_user
, phys_ptr
,
1060 } else if (env
->cp15
.c1_sys
& (1 << 23)) {
1061 return get_phys_addr_v6(env
, address
, access_type
, is_user
, phys_ptr
,
1064 return get_phys_addr_v5(env
, address
, access_type
, is_user
, phys_ptr
,
1069 int cpu_arm_handle_mmu_fault (CPUState
*env
, target_ulong address
,
1070 int access_type
, int mmu_idx
, int is_softmmu
)
1076 is_user
= mmu_idx
== MMU_USER_IDX
;
1077 ret
= get_phys_addr(env
, address
, access_type
, is_user
, &phys_addr
, &prot
);
1079 /* Map a single [sub]page. */
1080 phys_addr
&= ~(uint32_t)0x3ff;
1081 address
&= ~(uint32_t)0x3ff;
1082 return tlb_set_page (env
, address
, phys_addr
, prot
, mmu_idx
,
1086 if (access_type
== 2) {
1087 env
->cp15
.c5_insn
= ret
;
1088 env
->cp15
.c6_insn
= address
;
1089 env
->exception_index
= EXCP_PREFETCH_ABORT
;
1091 env
->cp15
.c5_data
= ret
;
1092 if (access_type
== 1 && arm_feature(env
, ARM_FEATURE_V6
))
1093 env
->cp15
.c5_data
|= (1 << 11);
1094 env
->cp15
.c6_data
= address
;
1095 env
->exception_index
= EXCP_DATA_ABORT
;
1100 target_phys_addr_t
cpu_get_phys_page_debug(CPUState
*env
, target_ulong addr
)
1106 ret
= get_phys_addr(env
, addr
, 0, 0, &phys_addr
, &prot
);
1114 /* Not really implemented. Need to figure out a sane way of doing this.
1115 Maybe add generic watchpoint support and use that. */
1117 void helper_mark_exclusive(CPUState
*env
, uint32_t addr
)
1119 env
->mmon_addr
= addr
;
1122 int helper_test_exclusive(CPUState
*env
, uint32_t addr
)
1124 return (env
->mmon_addr
!= addr
);
1127 void helper_clrex(CPUState
*env
)
1129 env
->mmon_addr
= -1;
1132 void helper_set_cp(CPUState
*env
, uint32_t insn
, uint32_t val
)
1134 int cp_num
= (insn
>> 8) & 0xf;
1135 int cp_info
= (insn
>> 5) & 7;
1136 int src
= (insn
>> 16) & 0xf;
1137 int operand
= insn
& 0xf;
1139 if (env
->cp
[cp_num
].cp_write
)
1140 env
->cp
[cp_num
].cp_write(env
->cp
[cp_num
].opaque
,
1141 cp_info
, src
, operand
, val
);
1144 uint32_t helper_get_cp(CPUState
*env
, uint32_t insn
)
1146 int cp_num
= (insn
>> 8) & 0xf;
1147 int cp_info
= (insn
>> 5) & 7;
1148 int dest
= (insn
>> 16) & 0xf;
1149 int operand
= insn
& 0xf;
1151 if (env
->cp
[cp_num
].cp_read
)
1152 return env
->cp
[cp_num
].cp_read(env
->cp
[cp_num
].opaque
,
1153 cp_info
, dest
, operand
);
1157 /* Return basic MPU access permission bits. */
1158 static uint32_t simple_mpu_ap_bits(uint32_t val
)
1165 for (i
= 0; i
< 16; i
+= 2) {
1166 ret
|= (val
>> i
) & mask
;
1172 /* Pad basic MPU access permission bits to extended format. */
1173 static uint32_t extended_mpu_ap_bits(uint32_t val
)
1180 for (i
= 0; i
< 16; i
+= 2) {
1181 ret
|= (val
& mask
) << i
;
1187 void helper_set_cp15(CPUState
*env
, uint32_t insn
, uint32_t val
)
1193 op1
= (insn
>> 21) & 7;
1194 op2
= (insn
>> 5) & 7;
1196 switch ((insn
>> 16) & 0xf) {
1198 if (((insn
>> 21) & 7) == 2) {
1199 /* ??? Select cache level. Ignore. */
1203 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1205 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1208 case 1: /* System configuration. */
1209 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1213 if (!arm_feature(env
, ARM_FEATURE_XSCALE
) || crm
== 0)
1214 env
->cp15
.c1_sys
= val
;
1215 /* ??? Lots of these bits are not implemented. */
1216 /* This may enable/disable the MMU, so do a TLB flush. */
1219 case 1: /* Auxiliary cotrol register. */
1220 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1221 env
->cp15
.c1_xscaleauxcr
= val
;
1224 /* Not implemented. */
1227 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1229 env
->cp15
.c1_coproc
= val
;
1230 /* ??? Is this safe when called from within a TB? */
1237 case 2: /* MMU Page table control / MPU cache control. */
1238 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1241 env
->cp15
.c2_data
= val
;
1244 env
->cp15
.c2_insn
= val
;
1252 env
->cp15
.c2_base0
= val
;
1255 env
->cp15
.c2_base1
= val
;
1258 env
->cp15
.c2_mask
= ~(((uint32_t)0xffffffffu
) >> val
);
1265 case 3: /* MMU Domain access control / MPU write buffer control. */
1267 tlb_flush(env
, 1); /* Flush TLB as domain not tracked in TLB */
1269 case 4: /* Reserved. */
1271 case 5: /* MMU Fault status / MPU access permission. */
1272 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1276 if (arm_feature(env
, ARM_FEATURE_MPU
))
1277 val
= extended_mpu_ap_bits(val
);
1278 env
->cp15
.c5_data
= val
;
1281 if (arm_feature(env
, ARM_FEATURE_MPU
))
1282 val
= extended_mpu_ap_bits(val
);
1283 env
->cp15
.c5_insn
= val
;
1286 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1288 env
->cp15
.c5_data
= val
;
1291 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1293 env
->cp15
.c5_insn
= val
;
1299 case 6: /* MMU Fault address / MPU base/size. */
1300 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1303 env
->cp15
.c6_region
[crm
] = val
;
1305 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1309 env
->cp15
.c6_data
= val
;
1311 case 1: /* ??? This is WFAR on armv6 */
1313 env
->cp15
.c6_insn
= val
;
1320 case 7: /* Cache control. */
1321 env
->cp15
.c15_i_max
= 0x000;
1322 env
->cp15
.c15_i_min
= 0xff0;
1323 /* No cache, so nothing to do. */
1324 /* ??? MPCore has VA to PA translation functions. */
1326 case 8: /* MMU TLB control. */
1328 case 0: /* Invalidate all. */
1331 case 1: /* Invalidate single TLB entry. */
1333 /* ??? This is wrong for large pages and sections. */
1334 /* As an ugly hack to make linux work we always flush a 4K
1337 tlb_flush_page(env
, val
);
1338 tlb_flush_page(env
, val
+ 0x400);
1339 tlb_flush_page(env
, val
+ 0x800);
1340 tlb_flush_page(env
, val
+ 0xc00);
1345 case 2: /* Invalidate on ASID. */
1346 tlb_flush(env
, val
== 0);
1348 case 3: /* Invalidate single entry on MVA. */
1349 /* ??? This is like case 1, but ignores ASID. */
1357 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1360 case 0: /* Cache lockdown. */
1362 case 0: /* L1 cache. */
1365 env
->cp15
.c9_data
= val
;
1368 env
->cp15
.c9_insn
= val
;
1374 case 1: /* L2 cache. */
1375 /* Ignore writes to L2 lockdown/auxiliary registers. */
1381 case 1: /* TCM memory region registers. */
1382 /* Not implemented. */
1388 case 10: /* MMU TLB lockdown. */
1389 /* ??? TLB lockdown not implemented. */
1391 case 12: /* Reserved. */
1393 case 13: /* Process ID. */
1396 /* Unlike real hardware the qemu TLB uses virtual addresses,
1397 not modified virtual addresses, so this causes a TLB flush.
1399 if (env
->cp15
.c13_fcse
!= val
)
1401 env
->cp15
.c13_fcse
= val
;
1404 /* This changes the ASID, so do a TLB flush. */
1405 if (env
->cp15
.c13_context
!= val
1406 && !arm_feature(env
, ARM_FEATURE_MPU
))
1408 env
->cp15
.c13_context
= val
;
1411 env
->cp15
.c13_tls1
= val
;
1414 env
->cp15
.c13_tls2
= val
;
1417 env
->cp15
.c13_tls3
= val
;
1423 case 14: /* Reserved. */
1425 case 15: /* Implementation specific. */
1426 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1427 if (op2
== 0 && crm
== 1) {
1428 if (env
->cp15
.c15_cpar
!= (val
& 0x3fff)) {
1429 /* Changes cp0 to cp13 behavior, so needs a TB flush. */
1431 env
->cp15
.c15_cpar
= val
& 0x3fff;
1437 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1441 case 1: /* Set TI925T configuration. */
1442 env
->cp15
.c15_ticonfig
= val
& 0xe7;
1443 env
->cp15
.c0_cpuid
= (val
& (1 << 5)) ? /* OS_TYPE bit */
1444 ARM_CPUID_TI915T
: ARM_CPUID_TI925T
;
1446 case 2: /* Set I_max. */
1447 env
->cp15
.c15_i_max
= val
;
1449 case 3: /* Set I_min. */
1450 env
->cp15
.c15_i_min
= val
;
1452 case 4: /* Set thread-ID. */
1453 env
->cp15
.c15_threadid
= val
& 0xffff;
1455 case 8: /* Wait-for-interrupt (deprecated). */
1456 cpu_interrupt(env
, CPU_INTERRUPT_HALT
);
1466 /* ??? For debugging only. Should raise illegal instruction exception. */
1467 cpu_abort(env
, "Unimplemented cp15 register write (c%d, c%d, {%d, %d})\n",
1468 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1471 uint32_t helper_get_cp15(CPUState
*env
, uint32_t insn
)
1477 op1
= (insn
>> 21) & 7;
1478 op2
= (insn
>> 5) & 7;
1480 switch ((insn
>> 16) & 0xf) {
1481 case 0: /* ID codes. */
1487 case 0: /* Device ID. */
1488 return env
->cp15
.c0_cpuid
;
1489 case 1: /* Cache Type. */
1490 return env
->cp15
.c0_cachetype
;
1491 case 2: /* TCM status. */
1493 case 3: /* TLB type register. */
1494 return 0; /* No lockable TLB entries. */
1495 case 5: /* CPU ID */
1496 return env
->cpu_index
;
1501 if (!arm_feature(env
, ARM_FEATURE_V6
))
1503 return env
->cp15
.c0_c1
[op2
];
1505 if (!arm_feature(env
, ARM_FEATURE_V6
))
1507 return env
->cp15
.c0_c2
[op2
];
1508 case 3: case 4: case 5: case 6: case 7:
1514 /* These registers aren't documented on arm11 cores. However
1515 Linux looks at them anyway. */
1516 if (!arm_feature(env
, ARM_FEATURE_V6
))
1520 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1526 case 1: /* System configuration. */
1527 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1530 case 0: /* Control register. */
1531 return env
->cp15
.c1_sys
;
1532 case 1: /* Auxiliary control register. */
1533 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1534 return env
->cp15
.c1_xscaleauxcr
;
1535 if (!arm_feature(env
, ARM_FEATURE_AUXCR
))
1537 switch (ARM_CPUID(env
)) {
1538 case ARM_CPUID_ARM1026
:
1540 case ARM_CPUID_ARM1136
:
1542 case ARM_CPUID_ARM11MPCORE
:
1544 case ARM_CPUID_CORTEXA8
:
1549 case 2: /* Coprocessor access register. */
1550 if (arm_feature(env
, ARM_FEATURE_XSCALE
))
1552 return env
->cp15
.c1_coproc
;
1556 case 2: /* MMU Page table control / MPU cache control. */
1557 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1560 return env
->cp15
.c2_data
;
1563 return env
->cp15
.c2_insn
;
1571 return env
->cp15
.c2_base0
;
1573 return env
->cp15
.c2_base1
;
1579 mask
= env
->cp15
.c2_mask
;
1590 case 3: /* MMU Domain access control / MPU write buffer control. */
1591 return env
->cp15
.c3
;
1592 case 4: /* Reserved. */
1594 case 5: /* MMU Fault status / MPU access permission. */
1595 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1599 if (arm_feature(env
, ARM_FEATURE_MPU
))
1600 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1601 return env
->cp15
.c5_data
;
1603 if (arm_feature(env
, ARM_FEATURE_MPU
))
1604 return simple_mpu_ap_bits(env
->cp15
.c5_data
);
1605 return env
->cp15
.c5_insn
;
1607 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1609 return env
->cp15
.c5_data
;
1611 if (!arm_feature(env
, ARM_FEATURE_MPU
))
1613 return env
->cp15
.c5_insn
;
1617 case 6: /* MMU Fault address. */
1618 if (arm_feature(env
, ARM_FEATURE_MPU
)) {
1621 return env
->cp15
.c6_region
[crm
];
1623 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1627 return env
->cp15
.c6_data
;
1629 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1630 /* Watchpoint Fault Adrress. */
1631 return 0; /* Not implemented. */
1633 /* Instruction Fault Adrress. */
1634 /* Arm9 doesn't have an IFAR, but implementing it anyway
1635 shouldn't do any harm. */
1636 return env
->cp15
.c6_insn
;
1639 if (arm_feature(env
, ARM_FEATURE_V6
)) {
1640 /* Instruction Fault Adrress. */
1641 return env
->cp15
.c6_insn
;
1649 case 7: /* Cache control. */
1650 /* ??? This is for test, clean and invaidate operations that set the
1651 Z flag. We can't represent N = Z = 1, so it also clears
1652 the N flag. Oh well. */
1655 case 8: /* MMU TLB control. */
1657 case 9: /* Cache lockdown. */
1659 case 0: /* L1 cache. */
1660 if (arm_feature(env
, ARM_FEATURE_OMAPCP
))
1664 return env
->cp15
.c9_data
;
1666 return env
->cp15
.c9_insn
;
1670 case 1: /* L2 cache */
1673 /* L2 Lockdown and Auxiliary control. */
1678 case 10: /* MMU TLB lockdown. */
1679 /* ??? TLB lockdown not implemented. */
1681 case 11: /* TCM DMA control. */
1682 case 12: /* Reserved. */
1684 case 13: /* Process ID. */
1687 return env
->cp15
.c13_fcse
;
1689 return env
->cp15
.c13_context
;
1691 return env
->cp15
.c13_tls1
;
1693 return env
->cp15
.c13_tls2
;
1695 return env
->cp15
.c13_tls3
;
1699 case 14: /* Reserved. */
1701 case 15: /* Implementation specific. */
1702 if (arm_feature(env
, ARM_FEATURE_XSCALE
)) {
1703 if (op2
== 0 && crm
== 1)
1704 return env
->cp15
.c15_cpar
;
1708 if (arm_feature(env
, ARM_FEATURE_OMAPCP
)) {
1712 case 1: /* Read TI925T configuration. */
1713 return env
->cp15
.c15_ticonfig
;
1714 case 2: /* Read I_max. */
1715 return env
->cp15
.c15_i_max
;
1716 case 3: /* Read I_min. */
1717 return env
->cp15
.c15_i_min
;
1718 case 4: /* Read thread-ID. */
1719 return env
->cp15
.c15_threadid
;
1720 case 8: /* TI925T_status */
1728 /* ??? For debugging only. Should raise illegal instruction exception. */
1729 cpu_abort(env
, "Unimplemented cp15 register read (c%d, c%d, {%d, %d})\n",
1730 (insn
>> 16) & 0xf, crm
, op1
, op2
);
1734 void helper_set_r13_banked(CPUState
*env
, int mode
, uint32_t val
)
1736 env
->banked_r13
[bank_number(mode
)] = val
;
1739 uint32_t helper_get_r13_banked(CPUState
*env
, int mode
)
1741 return env
->banked_r13
[bank_number(mode
)];
1744 uint32_t helper_v7m_mrs(CPUState
*env
, int reg
)
1748 return xpsr_read(env
) & 0xf8000000;
1750 return xpsr_read(env
) & 0xf80001ff;
1752 return xpsr_read(env
) & 0xff00fc00;
1754 return xpsr_read(env
) & 0xff00fdff;
1756 return xpsr_read(env
) & 0x000001ff;
1758 return xpsr_read(env
) & 0x0700fc00;
1760 return xpsr_read(env
) & 0x0700edff;
1762 return env
->v7m
.current_sp
? env
->v7m
.other_sp
: env
->regs
[13];
1764 return env
->v7m
.current_sp
? env
->regs
[13] : env
->v7m
.other_sp
;
1765 case 16: /* PRIMASK */
1766 return (env
->uncached_cpsr
& CPSR_I
) != 0;
1767 case 17: /* FAULTMASK */
1768 return (env
->uncached_cpsr
& CPSR_F
) != 0;
1769 case 18: /* BASEPRI */
1770 case 19: /* BASEPRI_MAX */
1771 return env
->v7m
.basepri
;
1772 case 20: /* CONTROL */
1773 return env
->v7m
.control
;
1775 /* ??? For debugging only. */
1776 cpu_abort(env
, "Unimplemented system register read (%d)\n", reg
);
1781 void helper_v7m_msr(CPUState
*env
, int reg
, uint32_t val
)
1785 xpsr_write(env
, val
, 0xf8000000);
1788 xpsr_write(env
, val
, 0xf8000000);
1791 xpsr_write(env
, val
, 0xfe00fc00);
1794 xpsr_write(env
, val
, 0xfe00fc00);
1797 /* IPSR bits are readonly. */
1800 xpsr_write(env
, val
, 0x0600fc00);
1803 xpsr_write(env
, val
, 0x0600fc00);
1806 if (env
->v7m
.current_sp
)
1807 env
->v7m
.other_sp
= val
;
1809 env
->regs
[13] = val
;
1812 if (env
->v7m
.current_sp
)
1813 env
->regs
[13] = val
;
1815 env
->v7m
.other_sp
= val
;
1817 case 16: /* PRIMASK */
1819 env
->uncached_cpsr
|= CPSR_I
;
1821 env
->uncached_cpsr
&= ~CPSR_I
;
1823 case 17: /* FAULTMASK */
1825 env
->uncached_cpsr
|= CPSR_F
;
1827 env
->uncached_cpsr
&= ~CPSR_F
;
1829 case 18: /* BASEPRI */
1830 env
->v7m
.basepri
= val
& 0xff;
1832 case 19: /* BASEPRI_MAX */
1834 if (val
!= 0 && (val
< env
->v7m
.basepri
|| env
->v7m
.basepri
== 0))
1835 env
->v7m
.basepri
= val
;
1837 case 20: /* CONTROL */
1838 env
->v7m
.control
= val
& 3;
1839 switch_v7m_sp(env
, (val
& 2) != 0);
1842 /* ??? For debugging only. */
1843 cpu_abort(env
, "Unimplemented system register write (%d)\n", reg
);
1848 void cpu_arm_set_cp_io(CPUARMState
*env
, int cpnum
,
1849 ARMReadCPFunc
*cp_read
, ARMWriteCPFunc
*cp_write
,
1852 if (cpnum
< 0 || cpnum
> 14) {
1853 cpu_abort(env
, "Bad coprocessor number: %i\n", cpnum
);
1857 env
->cp
[cpnum
].cp_read
= cp_read
;
1858 env
->cp
[cpnum
].cp_write
= cp_write
;
1859 env
->cp
[cpnum
].opaque
= opaque
;