6
6
#include "exec-all.h"
8
static inline void set_feature(CPUARMState *env, int feature)
10
env->features |= 1u << feature;
13
static void cpu_reset_model_id(CPUARMState *env, uint32_t id)
15
env->cp15.c0_cpuid = id;
17
case ARM_CPUID_ARM926:
18
set_feature(env, ARM_FEATURE_VFP);
19
env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090;
20
env->cp15.c0_cachetype = 0x1dd20d2;
21
env->cp15.c1_sys = 0x00090078;
23
case ARM_CPUID_ARM946:
24
set_feature(env, ARM_FEATURE_MPU);
25
env->cp15.c0_cachetype = 0x0f004006;
26
env->cp15.c1_sys = 0x00000078;
28
case ARM_CPUID_ARM1026:
29
set_feature(env, ARM_FEATURE_VFP);
30
set_feature(env, ARM_FEATURE_AUXCR);
31
env->vfp.xregs[ARM_VFP_FPSID] = 0x410110a0;
32
env->cp15.c0_cachetype = 0x1dd20d2;
33
env->cp15.c1_sys = 0x00090078;
35
case ARM_CPUID_TI915T:
36
case ARM_CPUID_TI925T:
37
set_feature(env, ARM_FEATURE_OMAPCP);
38
env->cp15.c0_cpuid = ARM_CPUID_TI925T; /* Depends on wiring. */
39
env->cp15.c0_cachetype = 0x5109149;
40
env->cp15.c1_sys = 0x00000070;
41
env->cp15.c15_i_max = 0x000;
42
env->cp15.c15_i_min = 0xff0;
44
case ARM_CPUID_PXA250:
45
case ARM_CPUID_PXA255:
46
case ARM_CPUID_PXA260:
47
case ARM_CPUID_PXA261:
48
case ARM_CPUID_PXA262:
49
set_feature(env, ARM_FEATURE_XSCALE);
50
/* JTAG_ID is ((id << 28) | 0x09265013) */
51
env->cp15.c0_cachetype = 0xd172172;
52
env->cp15.c1_sys = 0x00000078;
54
case ARM_CPUID_PXA270_A0:
55
case ARM_CPUID_PXA270_A1:
56
case ARM_CPUID_PXA270_B0:
57
case ARM_CPUID_PXA270_B1:
58
case ARM_CPUID_PXA270_C0:
59
case ARM_CPUID_PXA270_C5:
60
set_feature(env, ARM_FEATURE_XSCALE);
61
/* JTAG_ID is ((id << 28) | 0x09265013) */
62
set_feature(env, ARM_FEATURE_IWMMXT);
63
env->iwmmxt.cregs[ARM_IWMMXT_wCID] = 0x69051000 | 'Q';
64
env->cp15.c0_cachetype = 0xd172172;
65
env->cp15.c1_sys = 0x00000078;
68
cpu_abort(env, "Bad CPU ID: %x\n", id);
8
73
void cpu_reset(CPUARMState *env)
76
id = env->cp15.c0_cpuid;
77
memset(env, 0, offsetof(CPUARMState, breakpoints));
79
cpu_reset_model_id(env, id);
10
80
#if defined (CONFIG_USER_ONLY)
11
81
env->uncached_cpsr = ARM_CPU_MODE_USR;
12
82
env->vfp.xregs[ARM_VFP_FPEXC] = 1 << 30;
28
99
cpu_exec_init(env);
34
static inline void set_feature(CPUARMState *env, int feature)
109
static const struct arm_cpu_t arm_cpu_names[] = {
110
{ ARM_CPUID_ARM926, "arm926"},
111
{ ARM_CPUID_ARM946, "arm946"},
112
{ ARM_CPUID_ARM1026, "arm1026"},
113
{ ARM_CPUID_TI925T, "ti925t" },
114
{ ARM_CPUID_PXA250, "pxa250" },
115
{ ARM_CPUID_PXA255, "pxa255" },
116
{ ARM_CPUID_PXA260, "pxa260" },
117
{ ARM_CPUID_PXA261, "pxa261" },
118
{ ARM_CPUID_PXA262, "pxa262" },
119
{ ARM_CPUID_PXA270, "pxa270" },
120
{ ARM_CPUID_PXA270_A0, "pxa270-a0" },
121
{ ARM_CPUID_PXA270_A1, "pxa270-a1" },
122
{ ARM_CPUID_PXA270_B0, "pxa270-b0" },
123
{ ARM_CPUID_PXA270_B1, "pxa270-b1" },
124
{ ARM_CPUID_PXA270_C0, "pxa270-c0" },
125
{ ARM_CPUID_PXA270_C5, "pxa270-c5" },
129
void arm_cpu_list(void)
36
env->features |= 1u << feature;
133
printf ("Available CPUs:\n");
134
for (i = 0; arm_cpu_names[i].name; i++) {
135
printf(" %s\n", arm_cpu_names[i].name);
39
void cpu_arm_set_model(CPUARMState *env, uint32_t id)
139
void cpu_arm_set_model(CPUARMState *env, const char *name)
41
env->cp15.c0_cpuid = id;
43
case ARM_CPUID_ARM926:
44
set_feature(env, ARM_FEATURE_VFP);
45
env->vfp.xregs[ARM_VFP_FPSID] = 0x41011090;
47
case ARM_CPUID_ARM1026:
48
set_feature(env, ARM_FEATURE_VFP);
49
set_feature(env, ARM_FEATURE_AUXCR);
50
env->vfp.xregs[ARM_VFP_FPSID] = 0x410110a0;
53
cpu_abort(env, "Bad CPU ID: %x\n", id);
146
for (i = 0; arm_cpu_names[i].name; i++) {
147
if (strcmp(name, arm_cpu_names[i].name) == 0) {
148
id = arm_cpu_names[i].id;
153
cpu_abort(env, "Unknown CPU '%s'", name);
156
cpu_reset_model_id(env, id);
58
159
void cpu_arm_close(CPUARMState *env)
83
target_ulong cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
184
target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)
88
189
/* These should probably raise undefined insn exceptions. */
190
void helper_set_cp(CPUState *env, uint32_t insn, uint32_t val)
192
int op1 = (insn >> 8) & 0xf;
193
cpu_abort(env, "cp%i insn %08x\n", op1, insn);
197
uint32_t helper_get_cp(CPUState *env, uint32_t insn)
199
int op1 = (insn >> 8) & 0xf;
200
cpu_abort(env, "cp%i insn %08x\n", op1, insn);
89
204
void helper_set_cp15(CPUState *env, uint32_t insn, uint32_t val)
91
206
cpu_abort(env, "cp15 insn %08x\n", insn);
297
412
address += env->cp15.c13_fcse;
299
414
if ((env->cp15.c1_sys & 1) == 0) {
415
/* MMU/MPU disabled. */
301
416
*phys_ptr = address;
302
417
*prot = PAGE_READ | PAGE_WRITE;
418
} else if (arm_feature(env, ARM_FEATURE_MPU)) {
424
for (n = 7; n >= 0; n--) {
425
base = env->cp15.c6_region[n];
428
mask = 1 << ((base >> 1) & 0x1f);
429
/* Keep this shift separate from the above to avoid an
430
(undefined) << 32. */
431
mask = (mask << 1) - 1;
432
if (((base ^ address) & ~mask) == 0)
438
if (access_type == 2) {
439
mask = env->cp15.c5_insn;
441
mask = env->cp15.c5_data;
443
mask = (mask >> (n * 4)) & 0xf;
450
*prot = PAGE_READ | PAGE_WRITE;
458
*prot = PAGE_READ | PAGE_WRITE;
469
/* Bad permission. */
304
473
/* Pagetable walk. */
305
474
/* Lookup l1 descriptor. */
306
table = (env->cp15.c2 & 0xffffc000) | ((address >> 18) & 0x3ffc);
475
table = (env->cp15.c2_base & 0xffffc000) | ((address >> 18) & 0x3ffc);
307
476
desc = ldl_phys(table);
308
477
type = (desc & 3);
309
478
domain = (env->cp15.c3 >> ((desc >> 4) & 0x1e)) & 3;
409
588
return phys_addr;
591
void helper_set_cp(CPUState *env, uint32_t insn, uint32_t val)
593
int cp_num = (insn >> 8) & 0xf;
594
int cp_info = (insn >> 5) & 7;
595
int src = (insn >> 16) & 0xf;
596
int operand = insn & 0xf;
598
if (env->cp[cp_num].cp_write)
599
env->cp[cp_num].cp_write(env->cp[cp_num].opaque,
600
cp_info, src, operand, val);
603
uint32_t helper_get_cp(CPUState *env, uint32_t insn)
605
int cp_num = (insn >> 8) & 0xf;
606
int cp_info = (insn >> 5) & 7;
607
int dest = (insn >> 16) & 0xf;
608
int operand = insn & 0xf;
610
if (env->cp[cp_num].cp_read)
611
return env->cp[cp_num].cp_read(env->cp[cp_num].opaque,
612
cp_info, dest, operand);
616
/* Return basic MPU access permission bits. */
617
static uint32_t simple_mpu_ap_bits(uint32_t val)
624
for (i = 0; i < 16; i += 2) {
625
ret |= (val >> i) & mask;
631
/* Pad basic MPU access permission bits to extended format. */
632
static uint32_t extended_mpu_ap_bits(uint32_t val)
639
for (i = 0; i < 16; i += 2) {
640
ret |= (val & mask) << i;
412
646
void helper_set_cp15(CPUState *env, uint32_t insn, uint32_t val)
416
651
op2 = (insn >> 5) & 7;
417
653
switch ((insn >> 16) & 0xf) {
418
654
case 0: /* ID codes. */
655
if (arm_feature(env, ARM_FEATURE_XSCALE))
657
if (arm_feature(env, ARM_FEATURE_OMAPCP))
420
660
case 1: /* System configuration. */
661
if (arm_feature(env, ARM_FEATURE_OMAPCP))
423
env->cp15.c1_sys = val;
665
if (!arm_feature(env, ARM_FEATURE_XSCALE) || crm == 0)
666
env->cp15.c1_sys = val;
424
667
/* ??? Lots of these bits are not implemented. */
425
668
/* This may enable/disable the MMU, so do a TLB flush. */
426
669
tlb_flush(env, 1);
672
if (arm_feature(env, ARM_FEATURE_XSCALE)) {
673
env->cp15.c1_xscaleauxcr = val;
678
if (arm_feature(env, ARM_FEATURE_XSCALE))
429
680
env->cp15.c1_coproc = val;
430
681
/* ??? Is this safe when called from within a TB? */
436
case 2: /* MMU Page table control. */
688
case 2: /* MMU Page table control / MPU cache control. */
689
if (arm_feature(env, ARM_FEATURE_MPU)) {
692
env->cp15.c2_data = val;
695
env->cp15.c2_insn = val;
701
env->cp15.c2_base = val;
439
case 3: /* MMU Domain access control. */
704
case 3: /* MMU Domain access control / MPU write buffer control. */
440
705
env->cp15.c3 = val;
442
707
case 4: /* Reserved. */
444
case 5: /* MMU Fault status. */
709
case 5: /* MMU Fault status / MPU access permission. */
710
if (arm_feature(env, ARM_FEATURE_OMAPCP))
714
if (arm_feature(env, ARM_FEATURE_MPU))
715
val = extended_mpu_ap_bits(val);
447
716
env->cp15.c5_data = val;
719
if (arm_feature(env, ARM_FEATURE_MPU))
720
val = extended_mpu_ap_bits(val);
721
env->cp15.c5_insn = val;
724
if (!arm_feature(env, ARM_FEATURE_MPU))
726
env->cp15.c5_data = val;
729
if (!arm_feature(env, ARM_FEATURE_MPU))
450
731
env->cp15.c5_insn = val;
456
case 6: /* MMU Fault address. */
459
env->cp15.c6_data = val;
462
env->cp15.c6_insn = val;
737
case 6: /* MMU Fault address / MPU base/size. */
738
if (arm_feature(env, ARM_FEATURE_MPU)) {
741
env->cp15.c6_region[crm] = val;
743
if (arm_feature(env, ARM_FEATURE_OMAPCP))
747
env->cp15.c6_data = val;
750
env->cp15.c6_insn = val;
468
757
case 7: /* Cache control. */
758
env->cp15.c15_i_max = 0x000;
759
env->cp15.c15_i_min = 0xff0;
469
760
/* No cache, so nothing to do. */
471
762
case 8: /* MMU TLB control. */
532
836
case 14: /* Reserved. */
534
838
case 15: /* Implementation specific. */
535
/* ??? Internal registers not implemented. */
839
if (arm_feature(env, ARM_FEATURE_XSCALE)) {
840
if (op2 == 0 && crm == 1) {
841
if (env->cp15.c15_cpar != (val & 0x3fff)) {
842
/* Changes cp0 to cp13 behavior, so needs a TB flush. */
844
env->cp15.c15_cpar = val & 0x3fff;
850
if (arm_feature(env, ARM_FEATURE_OMAPCP)) {
854
case 1: /* Set TI925T configuration. */
855
env->cp15.c15_ticonfig = val & 0xe7;
856
env->cp15.c0_cpuid = (val & (1 << 5)) ? /* OS_TYPE bit */
857
ARM_CPUID_TI915T : ARM_CPUID_TI925T;
859
case 2: /* Set I_max. */
860
env->cp15.c15_i_max = val;
862
case 3: /* Set I_min. */
863
env->cp15.c15_i_min = val;
865
case 4: /* Set thread-ID. */
866
env->cp15.c15_threadid = val & 0xffff;
868
case 8: /* Wait-for-interrupt (deprecated). */
869
cpu_interrupt(env, CPU_INTERRUPT_HALT);
540
879
/* ??? For debugging only. Should raise illegal instruction exception. */
541
cpu_abort(env, "Unimplemented cp15 register read\n");
880
cpu_abort(env, "Unimplemented cp15 register write\n");
544
883
uint32_t helper_get_cp15(CPUState *env, uint32_t insn)
548
888
op2 = (insn >> 5) & 7;
549
890
switch ((insn >> 16) & 0xf) {
550
891
case 0: /* ID codes. */
552
893
default: /* Device ID. */
553
894
return env->cp15.c0_cpuid;
554
895
case 1: /* Cache Type. */
896
return env->cp15.c0_cachetype;
556
897
case 2: /* TCM status. */
898
if (arm_feature(env, ARM_FEATURE_XSCALE))
559
902
case 1: /* System configuration. */
903
if (arm_feature(env, ARM_FEATURE_OMAPCP))
561
906
case 0: /* Control register. */
562
907
return env->cp15.c1_sys;
563
908
case 1: /* Auxiliary control register. */
564
909
if (arm_feature(env, ARM_FEATURE_AUXCR))
911
if (arm_feature(env, ARM_FEATURE_XSCALE))
912
return env->cp15.c1_xscaleauxcr;
567
914
case 2: /* Coprocessor access register. */
915
if (arm_feature(env, ARM_FEATURE_XSCALE))
568
917
return env->cp15.c1_coproc;
572
case 2: /* MMU Page table control. */
574
case 3: /* MMU Domain access control. */
921
case 2: /* MMU Page table control / MPU cache control. */
922
if (arm_feature(env, ARM_FEATURE_MPU)) {
925
return env->cp15.c2_data;
928
return env->cp15.c2_insn;
934
return env->cp15.c2_base;
936
case 3: /* MMU Domain access control / MPU write buffer control. */
575
937
return env->cp15.c3;
576
938
case 4: /* Reserved. */
578
case 5: /* MMU Fault status. */
940
case 5: /* MMU Fault status / MPU access permission. */
941
if (arm_feature(env, ARM_FEATURE_OMAPCP))
945
if (arm_feature(env, ARM_FEATURE_MPU))
946
return simple_mpu_ap_bits(env->cp15.c5_data);
581
947
return env->cp15.c5_data;
949
if (arm_feature(env, ARM_FEATURE_MPU))
950
return simple_mpu_ap_bits(env->cp15.c5_data);
951
return env->cp15.c5_insn;
953
if (!arm_feature(env, ARM_FEATURE_MPU))
955
return env->cp15.c5_data;
957
if (!arm_feature(env, ARM_FEATURE_MPU))
583
959
return env->cp15.c5_insn;
587
case 6: /* MMU Fault address. */
590
return env->cp15.c6_data;
592
/* Arm9 doesn't have an IFAR, but implementing it anyway shouldn't
594
return env->cp15.c6_insn;
963
case 6: /* MMU Fault address / MPU base/size. */
964
if (arm_feature(env, ARM_FEATURE_MPU)) {
969
return env->cp15.c6_region[n];
971
if (arm_feature(env, ARM_FEATURE_OMAPCP))
975
return env->cp15.c6_data;
977
/* Arm9 doesn't have an IFAR, but implementing it anyway
978
shouldn't do any harm. */
979
return env->cp15.c6_insn;
598
984
case 7: /* Cache control. */
599
985
/* ??? This is for test, clean and invaidate operations that set the
600
Z flag. We can't represent N = Z = 1, so it also clears clears
986
Z flag. We can't represent N = Z = 1, so it also clears
601
987
the N flag. Oh well. */
604
990
case 8: /* MMU TLB control. */
606
992
case 9: /* Cache lockdown. */
993
if (arm_feature(env, ARM_FEATURE_OMAPCP))
609
997
return env->cp15.c9_data;
630
1018
case 14: /* Reserved. */
632
1020
case 15: /* Implementation specific. */
633
/* ??? Internal registers not implemented. */
1021
if (arm_feature(env, ARM_FEATURE_XSCALE)) {
1022
if (op2 == 0 && crm == 1)
1023
return env->cp15.c15_cpar;
1027
if (arm_feature(env, ARM_FEATURE_OMAPCP)) {
1031
case 1: /* Read TI925T configuration. */
1032
return env->cp15.c15_ticonfig;
1033
case 2: /* Read I_max. */
1034
return env->cp15.c15_i_max;
1035
case 3: /* Read I_min. */
1036
return env->cp15.c15_i_min;
1037
case 4: /* Read thread-ID. */
1038
return env->cp15.c15_threadid;
1039
case 8: /* TI925T_status */