View | Details | Raw Unified | Return to bug 240037 | Differences between
and this patch

Collapse All | Expand All

(-)emulators/qemu-sbruno/files/patch-1 (+58 lines)
Line 0 Link Here
1
https://lists.gnu.org/archive/html/qemu-arm/2019-01/msg00474.html
2
3
XXX mik enable read from qemu-user-mode
4
5
6
Although technically not visible to userspace the kernel does make
7
them visible via a trap and emulate ABI. We provide a new permission
8
mask (PL0U_R) which maps to PL0_R for CONFIG_USER builds and adjust
9
the minimum permission check accordingly.
10
11
Signed-off-by: Alex Bennée <address@hidden>
12
---
13
 target/arm/cpu.h    | 12 ++++++++++++
14
 target/arm/helper.c |  6 +++++-
15
 2 files changed, 17 insertions(+), 1 deletion(-)
16
17
diff --git a/target/arm/cpu.h b/target/arm/cpu.h
18
index ff81db420d..3b3c359cca 100644
19
--- target/arm/cpu.h
20
+++ target/arm/cpu.h
21
@@ -2202,6 +2202,18 @@ static inline bool cptype_valid(int cptype)
22
 #define PL0_R (0x02 | PL1_R)
23
 #define PL0_W (0x01 | PL1_W)
24
 
25
+/*
26
+ * For user-mode some registers are accessible to EL0 via a kernel
27
+ * trap-and-emulate ABI. In this case we define the read permissions
28
+ * as actually being PL0_R. However some bits of any given register
29
+ * may still be masked.
30
+ */
31
+//#ifdef CONFIG_USER_ONLY
32
+#define PL0U_R PL0_R
33
+//#else
34
+//#define PL0U_R PL1_R
35
+//#endif
36
+
37
 #define PL3_RW (PL3_R | PL3_W)
38
 #define PL2_RW (PL2_R | PL2_W)
39
 #define PL1_RW (PL1_R | PL1_W)
40
diff --git a/target/arm/helper.c b/target/arm/helper.c
41
index 92666e5208..42c1c0b144 100644
42
--- target/arm/helper.c
43
+++ target/arm/helper.c
44
@@ -6731,7 +6731,11 @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu,
45
     if (r->state != ARM_CP_STATE_AA32) {
46
         int mask = 0;
47
         switch (r->opc1) {
48
-        case 0: case 1: case 2:
49
+        case 0:
50
+            /* min_EL EL1, but some accessible to EL0 via kernel ABI */
51
+            mask = PL0U_R | PL1_RW;
52
+            break;
53
+        case 1: case 2:
54
             /* min_EL EL1 */
55
             mask = PL1_RW;
56
             break;
57
-- 
58
2.17.1
(-)emulators/qemu-sbruno/files/patch-2 (+125 lines)
Line 0 Link Here
1
--- target/arm/helper.c.orig	2019-12-12 03:59:10.000000000 +0100
2
+++ target/arm/helper.c	2020-01-15 14:06:54.190516000 +0100
3
@@ -2919,7 +2919,7 @@ static uint64_t mpidr_read(CPUARMState *env, const ARM
4
 static const ARMCPRegInfo mpidr_cp_reginfo[] = {
5
     { .name = "MPIDR", .state = ARM_CP_STATE_BOTH,
6
       .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 5,
7
-      .access = PL1_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW },
8
+      .access = PL0U_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW },
9
     REGINFO_SENTINEL
10
 };
11
 
12
@@ -4601,6 +4601,7 @@ static uint64_t id_pfr1_read(CPUARMState *env, const A
13
     return pfr1;
14
 }
15
 
16
+#ifndef CONFIG_USER_ONLY
17
 static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri)
18
 {
19
     ARMCPU *cpu = arm_env_get_cpu(env);
20
@@ -4611,6 +4612,7 @@ static uint64_t id_aa64pfr0_read(CPUARMState *env, con
21
     }
22
     return pfr0;
23
 }
24
+#endif
25
 
26
 void register_cp_regs_for_features(ARMCPU *cpu)
27
 {
28
@@ -4759,18 +4761,25 @@ void register_cp_regs_for_features(ARMCPU *cpu)
29
          * define new registers here.
30
          */
31
         ARMCPRegInfo v8_idregs[] = {
32
-            /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST because we don't
33
-             * know the right value for the GIC field until after we
34
-             * define these regs.
35
+            /* ID_AA64PFR0_EL1 is not a plain ARM_CP_CONST for system
36
+             * emulation because we don't know the right value for the
37
+             * GIC field until after we define these regs. For
38
+             * user-mode HWCAP_CPUID emulation the GIC bits are masked
39
+             * anyway.
40
              */
41
             { .name = "ID_AA64PFR0_EL1", .state = ARM_CP_STATE_AA64,
42
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 0,
43
+#ifndef CONFIG_USER_ONLY
44
               .access = PL1_R, .type = ARM_CP_NO_RAW,
45
               .readfn = id_aa64pfr0_read,
46
-              .writefn = arm_cp_write_ignore },
47
+#else
48
+              .access = PL0U_R, .type = ARM_CP_CONST,
49
+              .resetvalue = cpu->id_aa64pfr0 & 0x000f000f0ff0000ULL
50
+#endif
51
+            },
52
             { .name = "ID_AA64PFR1_EL1", .state = ARM_CP_STATE_AA64,
53
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 1,
54
-              .access = PL1_R, .type = ARM_CP_CONST,
55
+              .access = PL0U_R, .type = ARM_CP_CONST,
56
               .resetvalue = cpu->id_aa64pfr1},
57
             { .name = "ID_AA64PFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64,
58
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 2,
59
@@ -4798,7 +4807,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)
60
               .resetvalue = 0 },
61
             { .name = "ID_AA64DFR0_EL1", .state = ARM_CP_STATE_AA64,
62
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 0,
63
-              .access = PL1_R, .type = ARM_CP_CONST,
64
+              .access = PL0U_R, .type = ARM_CP_CONST,
65
               .resetvalue = cpu->id_aa64dfr0 },
66
             { .name = "ID_AA64DFR1_EL1", .state = ARM_CP_STATE_AA64,
67
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 5, .opc2 = 1,
68
@@ -4830,11 +4839,16 @@ void register_cp_regs_for_features(ARMCPU *cpu)
69
               .resetvalue = 0 },
70
             { .name = "ID_AA64ISAR0_EL1", .state = ARM_CP_STATE_AA64,
71
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 0,
72
-              .access = PL1_R, .type = ARM_CP_CONST,
73
-              .resetvalue = cpu->id_aa64isar0 },
74
+              .access = PL0U_R, .type = ARM_CP_CONST,
75
+#ifdef CONFIG_USER_ONLY
76
+              .resetvalue = cpu->id_aa64isar0 & 0x000fffffff0ffff0ULL
77
+#else
78
+              .resetvalue = cpu->id_aa64isar0
79
+#endif
80
+            },
81
             { .name = "ID_AA64ISAR1_EL1", .state = ARM_CP_STATE_AA64,
82
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 1,
83
-              .access = PL1_R, .type = ARM_CP_CONST,
84
+              .access = PL0U_R, .type = ARM_CP_CONST,
85
               .resetvalue = cpu->id_aa64isar1 },
86
             { .name = "ID_AA64ISAR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64,
87
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2,
88
@@ -4862,11 +4876,11 @@ void register_cp_regs_for_features(ARMCPU *cpu)
89
               .resetvalue = 0 },
90
             { .name = "ID_AA64MMFR0_EL1", .state = ARM_CP_STATE_AA64,
91
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 0,
92
-              .access = PL1_R, .type = ARM_CP_CONST,
93
+              .access = PL0U_R, .type = ARM_CP_CONST,
94
               .resetvalue = cpu->id_aa64mmfr0 },
95
             { .name = "ID_AA64MMFR1_EL1", .state = ARM_CP_STATE_AA64,
96
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 1,
97
-              .access = PL1_R, .type = ARM_CP_CONST,
98
+              .access = PL0U_R, .type = ARM_CP_CONST,
99
               .resetvalue = cpu->id_aa64mmfr1 },
100
             { .name = "ID_AA64MMFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64,
101
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 7, .opc2 = 2,
102
@@ -5160,7 +5174,7 @@ void register_cp_regs_for_features(ARMCPU *cpu)
103
         ARMCPRegInfo id_v8_midr_cp_reginfo[] = {
104
             { .name = "MIDR_EL1", .state = ARM_CP_STATE_BOTH,
105
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 0,
106
-              .access = PL1_R, .type = ARM_CP_NO_RAW, .resetvalue = cpu->midr,
107
+              .access = PL0U_R, .type = ARM_CP_NO_RAW, .resetvalue = cpu->midr,
108
               .fieldoffset = offsetof(CPUARMState, cp15.c0_cpuid),
109
               .readfn = midr_read },
110
             /* crn = 0 op1 = 0 crm = 0 op2 = 4,7 : AArch32 aliases of MIDR */
111
@@ -5172,7 +5186,13 @@ void register_cp_regs_for_features(ARMCPU *cpu)
112
               .access = PL1_R, .resetvalue = cpu->midr },
113
             { .name = "REVIDR_EL1", .state = ARM_CP_STATE_BOTH,
114
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 0, .opc2 = 6,
115
-              .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = cpu->revidr },
116
+#ifdef CONFIG_USER_ONLY
117
+              .access = PL0U_R, .type = ARM_CP_CONST,
118
+              .resetvalue = 0 /* HW_CPUID IMPDEF fields are 0 */ },
119
+#else
120
+              .access = PL1_R, .type = ARM_CP_CONST,
121
+              .resetvalue = cpu->revidr },
122
+#endif
123
             REGINFO_SENTINEL
124
         };
125
         ARMCPRegInfo id_cp_reginfo[] = {

Return to bug 240037