1
The following changes since commit 2ecfc0657afa5d29a373271b342f704a1a3c6737:
1
The following changes since commit 0a301624c2f4ced3331ffd5bce85b4274fe132af:
2
2
3
Merge remote-tracking branch 'remotes/armbru/tags/pull-misc-2020-12-10' into staging (2020-12-10 17:01:05 +0000)
3
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20220208' into staging (2022-02-08 11:40:08 +0000)
4
4
5
are available in the Git repository at:
5
are available in the Git repository at:
6
6
7
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20201210
7
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220211
8
8
9
for you to fetch changes up to 9e2658d62ebc23efe7df43fc0e306f129510d874:
9
for you to fetch changes up to 5c1a101ef6b85537a4ade93c39ea81cadd5c246e:
10
10
11
accel/tcg: rename tcg-cpus functions to match module name (2020-12-10 17:44:10 -0600)
11
tests/tcg/multiarch: Add sigbus.c (2022-02-09 09:00:01 +1100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Split CpusAccel for tcg variants
14
Fix safe_syscall_base for sparc64.
15
Fix host signal handling for sparc64-linux.
16
Speedups for jump cache and work list probing.
17
Fix for exception replays.
18
Raise guest SIGBUS for user-only misaligned accesses.
15
19
16
----------------------------------------------------------------
20
----------------------------------------------------------------
17
Claudio Fontana (3):
21
Idan Horowitz (2):
18
accel/tcg: split CpusAccel into three TCG variants
22
accel/tcg: Optimize jump cache flush during tlb range flush
19
accel/tcg: split tcg_start_vcpu_thread
23
softmmu/cpus: Check if the cpu work list is empty atomically
20
accel/tcg: rename tcg-cpus functions to match module name
21
24
22
accel/tcg/tcg-cpus-icount.h | 17 ++
25
Pavel Dovgalyuk (1):
23
accel/tcg/tcg-cpus-rr.h | 21 ++
26
replay: use CF_NOIRQ for special exception-replaying TB
24
accel/tcg/tcg-cpus.h | 12 +-
25
accel/tcg/tcg-all.c | 13 +-
26
accel/tcg/tcg-cpus-icount.c | 147 +++++++++++++
27
accel/tcg/tcg-cpus-mttcg.c | 140 ++++++++++++
28
accel/tcg/tcg-cpus-rr.c | 305 ++++++++++++++++++++++++++
29
accel/tcg/tcg-cpus.c | 506 +-------------------------------------------
30
softmmu/icount.c | 2 +-
31
accel/tcg/meson.build | 9 +-
32
10 files changed, 670 insertions(+), 502 deletions(-)
33
create mode 100644 accel/tcg/tcg-cpus-icount.h
34
create mode 100644 accel/tcg/tcg-cpus-rr.h
35
create mode 100644 accel/tcg/tcg-cpus-icount.c
36
create mode 100644 accel/tcg/tcg-cpus-mttcg.c
37
create mode 100644 accel/tcg/tcg-cpus-rr.c
38
27
28
Richard Henderson (29):
29
common-user/host/sparc64: Fix safe_syscall_base
30
linux-user: Introduce host_signal_mask
31
linux-user: Introduce host_sigcontext
32
linux-user: Move sparc/host-signal.h to sparc64/host-signal.h
33
linux-user/include/host/sparc64: Fix host_sigcontext
34
tcg/i386: Support raising sigbus for user-only
35
tcg/aarch64: Support raising sigbus for user-only
36
tcg/ppc: Support raising sigbus for user-only
37
tcg/riscv: Support raising sigbus for user-only
38
tcg/s390x: Support raising sigbus for user-only
39
tcg/tci: Support raising sigbus for user-only
40
tcg/arm: Drop support for armv4 and armv5 hosts
41
tcg/arm: Remove use_armv5t_instructions
42
tcg/arm: Remove use_armv6_instructions
43
tcg/arm: Check alignment for ldrd and strd
44
tcg/arm: Support unaligned access for softmmu
45
tcg/arm: Reserve a register for guest_base
46
tcg/arm: Support raising sigbus for user-only
47
tcg/mips: Support unaligned access for user-only
48
tcg/mips: Support unaligned access for softmmu
49
tcg/sparc: Use tcg_out_movi_imm13 in tcg_out_addsub2_i64
50
tcg/sparc: Split out tcg_out_movi_imm32
51
tcg/sparc: Add scratch argument to tcg_out_movi_int
52
tcg/sparc: Improve code gen for shifted 32-bit constants
53
tcg/sparc: Convert patch_reloc to return bool
54
tcg/sparc: Use the constant pool for 64-bit constants
55
tcg/sparc: Add tcg_out_jmpl_const for better tail calls
56
tcg/sparc: Support unaligned access for user-only
57
tests/tcg/multiarch: Add sigbus.c
58
59
WANG Xuerui (2):
60
tcg/loongarch64: Fix fallout from recent MO_Q renaming
61
tcg/loongarch64: Support raising sigbus for user-only
62
63
linux-user/include/host/aarch64/host-signal.h | 16 +-
64
linux-user/include/host/alpha/host-signal.h | 14 +-
65
linux-user/include/host/arm/host-signal.h | 14 +-
66
linux-user/include/host/i386/host-signal.h | 14 +-
67
linux-user/include/host/loongarch64/host-signal.h | 14 +-
68
linux-user/include/host/mips/host-signal.h | 14 +-
69
linux-user/include/host/ppc/host-signal.h | 14 +-
70
linux-user/include/host/riscv/host-signal.h | 14 +-
71
linux-user/include/host/s390/host-signal.h | 14 +-
72
linux-user/include/host/sparc/host-signal.h | 63 ----
73
linux-user/include/host/sparc64/host-signal.h | 65 +++-
74
linux-user/include/host/x86_64/host-signal.h | 14 +-
75
tcg/aarch64/tcg-target.h | 2 -
76
tcg/arm/tcg-target.h | 6 +-
77
tcg/i386/tcg-target.h | 2 -
78
tcg/loongarch64/tcg-target.h | 2 -
79
tcg/mips/tcg-target.h | 2 -
80
tcg/ppc/tcg-target.h | 2 -
81
tcg/riscv/tcg-target.h | 2 -
82
tcg/s390x/tcg-target.h | 2 -
83
accel/tcg/cpu-exec.c | 3 +-
84
accel/tcg/cputlb.c | 9 +
85
linux-user/signal.c | 22 +-
86
softmmu/cpus.c | 7 +-
87
tcg/tci.c | 20 +-
88
tests/tcg/multiarch/sigbus.c | 68 ++++
89
tcg/aarch64/tcg-target.c.inc | 91 ++++-
90
tcg/arm/tcg-target.c.inc | 410 +++++++++-------------
91
tcg/i386/tcg-target.c.inc | 103 +++++-
92
tcg/loongarch64/tcg-target.c.inc | 73 +++-
93
tcg/mips/tcg-target.c.inc | 387 ++++++++++++++++++--
94
tcg/ppc/tcg-target.c.inc | 98 +++++-
95
tcg/riscv/tcg-target.c.inc | 63 +++-
96
tcg/s390x/tcg-target.c.inc | 59 +++-
97
tcg/sparc/tcg-target.c.inc | 348 +++++++++++++++---
98
common-user/host/sparc64/safe-syscall.inc.S | 5 +-
99
36 files changed, 1561 insertions(+), 495 deletions(-)
100
delete mode 100644 linux-user/include/host/sparc/host-signal.h
101
create mode 100644 tests/tcg/multiarch/sigbus.c
102
diff view generated by jsdifflib
New patch
1
Use the "retl" instead of "ret" instruction alias, since we
2
do not allocate a register window in this function.
1
3
4
Fix the offset to the first stacked parameter, which lies
5
beyond the register window save area.
6
7
Fixes: 95c021dac835 ("linux-user/host/sparc64: Add safe-syscall.inc.S")
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
---
10
common-user/host/sparc64/safe-syscall.inc.S | 5 +++--
11
1 file changed, 3 insertions(+), 2 deletions(-)
12
13
diff --git a/common-user/host/sparc64/safe-syscall.inc.S b/common-user/host/sparc64/safe-syscall.inc.S
14
index XXXXXXX..XXXXXXX 100644
15
--- a/common-user/host/sparc64/safe-syscall.inc.S
16
+++ b/common-user/host/sparc64/safe-syscall.inc.S
17
@@ -XXX,XX +XXX,XX @@
18
.type safe_syscall_end, @function
19
20
#define STACK_BIAS 2047
21
-#define PARAM(N) STACK_BIAS + N*8
22
+#define WINDOW_SIZE 16 * 8
23
+#define PARAM(N) STACK_BIAS + WINDOW_SIZE + N * 8
24
25
/*
26
* This is the entry point for making a system call. The calling
27
@@ -XXX,XX +XXX,XX @@ safe_syscall_end:
28
/* code path for having successfully executed the syscall */
29
bcs,pn %xcc, 1f
30
nop
31
- ret
32
+ retl
33
nop
34
35
/* code path when we didn't execute the syscall */
36
--
37
2.25.1
38
39
diff view generated by jsdifflib
New patch
1
1
Do not directly access the uc_sigmask member.
2
This is preparation for a sparc64 fix.
3
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
linux-user/include/host/aarch64/host-signal.h | 5 +++++
9
linux-user/include/host/alpha/host-signal.h | 5 +++++
10
linux-user/include/host/arm/host-signal.h | 5 +++++
11
linux-user/include/host/i386/host-signal.h | 5 +++++
12
.../include/host/loongarch64/host-signal.h | 5 +++++
13
linux-user/include/host/mips/host-signal.h | 5 +++++
14
linux-user/include/host/ppc/host-signal.h | 5 +++++
15
linux-user/include/host/riscv/host-signal.h | 5 +++++
16
linux-user/include/host/s390/host-signal.h | 5 +++++
17
linux-user/include/host/sparc/host-signal.h | 5 +++++
18
linux-user/include/host/x86_64/host-signal.h | 5 +++++
19
linux-user/signal.c | 18 ++++++++----------
20
12 files changed, 63 insertions(+), 10 deletions(-)
21
22
diff --git a/linux-user/include/host/aarch64/host-signal.h b/linux-user/include/host/aarch64/host-signal.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/linux-user/include/host/aarch64/host-signal.h
25
+++ b/linux-user/include/host/aarch64/host-signal.h
26
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
27
uc->uc_mcontext.pc = pc;
28
}
29
30
+static inline void *host_signal_mask(ucontext_t *uc)
31
+{
32
+ return &uc->uc_sigmask;
33
+}
34
+
35
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
36
{
37
struct _aarch64_ctx *hdr;
38
diff --git a/linux-user/include/host/alpha/host-signal.h b/linux-user/include/host/alpha/host-signal.h
39
index XXXXXXX..XXXXXXX 100644
40
--- a/linux-user/include/host/alpha/host-signal.h
41
+++ b/linux-user/include/host/alpha/host-signal.h
42
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
43
uc->uc_mcontext.sc_pc = pc;
44
}
45
46
+static inline void *host_signal_mask(ucontext_t *uc)
47
+{
48
+ return &uc->uc_sigmask;
49
+}
50
+
51
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
52
{
53
uint32_t *pc = (uint32_t *)host_signal_pc(uc);
54
diff --git a/linux-user/include/host/arm/host-signal.h b/linux-user/include/host/arm/host-signal.h
55
index XXXXXXX..XXXXXXX 100644
56
--- a/linux-user/include/host/arm/host-signal.h
57
+++ b/linux-user/include/host/arm/host-signal.h
58
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
59
uc->uc_mcontext.arm_pc = pc;
60
}
61
62
+static inline void *host_signal_mask(ucontext_t *uc)
63
+{
64
+ return &uc->uc_sigmask;
65
+}
66
+
67
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
68
{
69
/*
70
diff --git a/linux-user/include/host/i386/host-signal.h b/linux-user/include/host/i386/host-signal.h
71
index XXXXXXX..XXXXXXX 100644
72
--- a/linux-user/include/host/i386/host-signal.h
73
+++ b/linux-user/include/host/i386/host-signal.h
74
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
75
uc->uc_mcontext.gregs[REG_EIP] = pc;
76
}
77
78
+static inline void *host_signal_mask(ucontext_t *uc)
79
+{
80
+ return &uc->uc_sigmask;
81
+}
82
+
83
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
84
{
85
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
86
diff --git a/linux-user/include/host/loongarch64/host-signal.h b/linux-user/include/host/loongarch64/host-signal.h
87
index XXXXXXX..XXXXXXX 100644
88
--- a/linux-user/include/host/loongarch64/host-signal.h
89
+++ b/linux-user/include/host/loongarch64/host-signal.h
90
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
91
uc->uc_mcontext.__pc = pc;
92
}
93
94
+static inline void *host_signal_mask(ucontext_t *uc)
95
+{
96
+ return &uc->uc_sigmask;
97
+}
98
+
99
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
100
{
101
const uint32_t *pinsn = (const uint32_t *)host_signal_pc(uc);
102
diff --git a/linux-user/include/host/mips/host-signal.h b/linux-user/include/host/mips/host-signal.h
103
index XXXXXXX..XXXXXXX 100644
104
--- a/linux-user/include/host/mips/host-signal.h
105
+++ b/linux-user/include/host/mips/host-signal.h
106
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
107
uc->uc_mcontext.pc = pc;
108
}
109
110
+static inline void *host_signal_mask(ucontext_t *uc)
111
+{
112
+ return &uc->uc_sigmask;
113
+}
114
+
115
#if defined(__misp16) || defined(__mips_micromips)
116
#error "Unsupported encoding"
117
#endif
118
diff --git a/linux-user/include/host/ppc/host-signal.h b/linux-user/include/host/ppc/host-signal.h
119
index XXXXXXX..XXXXXXX 100644
120
--- a/linux-user/include/host/ppc/host-signal.h
121
+++ b/linux-user/include/host/ppc/host-signal.h
122
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
123
uc->uc_mcontext.regs->nip = pc;
124
}
125
126
+static inline void *host_signal_mask(ucontext_t *uc)
127
+{
128
+ return &uc->uc_sigmask;
129
+}
130
+
131
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
132
{
133
return uc->uc_mcontext.regs->trap != 0x400
134
diff --git a/linux-user/include/host/riscv/host-signal.h b/linux-user/include/host/riscv/host-signal.h
135
index XXXXXXX..XXXXXXX 100644
136
--- a/linux-user/include/host/riscv/host-signal.h
137
+++ b/linux-user/include/host/riscv/host-signal.h
138
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
139
uc->uc_mcontext.__gregs[REG_PC] = pc;
140
}
141
142
+static inline void *host_signal_mask(ucontext_t *uc)
143
+{
144
+ return &uc->uc_sigmask;
145
+}
146
+
147
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
148
{
149
/*
150
diff --git a/linux-user/include/host/s390/host-signal.h b/linux-user/include/host/s390/host-signal.h
151
index XXXXXXX..XXXXXXX 100644
152
--- a/linux-user/include/host/s390/host-signal.h
153
+++ b/linux-user/include/host/s390/host-signal.h
154
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
155
uc->uc_mcontext.psw.addr = pc;
156
}
157
158
+static inline void *host_signal_mask(ucontext_t *uc)
159
+{
160
+ return &uc->uc_sigmask;
161
+}
162
+
163
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
164
{
165
uint16_t *pinsn = (uint16_t *)host_signal_pc(uc);
166
diff --git a/linux-user/include/host/sparc/host-signal.h b/linux-user/include/host/sparc/host-signal.h
167
index XXXXXXX..XXXXXXX 100644
168
--- a/linux-user/include/host/sparc/host-signal.h
169
+++ b/linux-user/include/host/sparc/host-signal.h
170
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
171
#endif
172
}
173
174
+static inline void *host_signal_mask(ucontext_t *uc)
175
+{
176
+ return &uc->uc_sigmask;
177
+}
178
+
179
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
180
{
181
uint32_t insn = *(uint32_t *)host_signal_pc(uc);
182
diff --git a/linux-user/include/host/x86_64/host-signal.h b/linux-user/include/host/x86_64/host-signal.h
183
index XXXXXXX..XXXXXXX 100644
184
--- a/linux-user/include/host/x86_64/host-signal.h
185
+++ b/linux-user/include/host/x86_64/host-signal.h
186
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
187
uc->uc_mcontext.gregs[REG_RIP] = pc;
188
}
189
190
+static inline void *host_signal_mask(ucontext_t *uc)
191
+{
192
+ return &uc->uc_sigmask;
193
+}
194
+
195
static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
196
{
197
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
198
diff --git a/linux-user/signal.c b/linux-user/signal.c
199
index XXXXXXX..XXXXXXX 100644
200
--- a/linux-user/signal.c
201
+++ b/linux-user/signal.c
202
@@ -XXX,XX +XXX,XX @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
203
int guest_sig;
204
uintptr_t pc = 0;
205
bool sync_sig = false;
206
+ void *sigmask = host_signal_mask(uc);
207
208
/*
209
* Non-spoofed SIGSEGV and SIGBUS are synchronous, and need special
210
@@ -XXX,XX +XXX,XX @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
211
if (info->si_code == SEGV_ACCERR && h2g_valid(host_addr)) {
212
/* If this was a write to a TB protected page, restart. */
213
if (is_write &&
214
- handle_sigsegv_accerr_write(cpu, &uc->uc_sigmask,
215
- pc, guest_addr)) {
216
+ handle_sigsegv_accerr_write(cpu, sigmask, pc, guest_addr)) {
217
return;
218
}
219
220
@@ -XXX,XX +XXX,XX @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
221
}
222
}
223
224
- sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
225
+ sigprocmask(SIG_SETMASK, sigmask, NULL);
226
cpu_loop_exit_sigsegv(cpu, guest_addr, access_type, maperr, pc);
227
} else {
228
- sigprocmask(SIG_SETMASK, &uc->uc_sigmask, NULL);
229
+ sigprocmask(SIG_SETMASK, sigmask, NULL);
230
if (info->si_code == BUS_ADRALN) {
231
cpu_loop_exit_sigbus(cpu, guest_addr, access_type, pc);
232
}
233
@@ -XXX,XX +XXX,XX @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
234
* now and it getting out to the main loop. Signals will be
235
* unblocked again in process_pending_signals().
236
*
237
- * WARNING: we cannot use sigfillset() here because the uc_sigmask
238
+ * WARNING: we cannot use sigfillset() here because the sigmask
239
* field is a kernel sigset_t, which is much smaller than the
240
* libc sigset_t which sigfillset() operates on. Using sigfillset()
241
* would write 0xff bytes off the end of the structure and trash
242
* data on the struct.
243
- * We can't use sizeof(uc->uc_sigmask) either, because the libc
244
- * headers define the struct field with the wrong (too large) type.
245
*/
246
- memset(&uc->uc_sigmask, 0xff, SIGSET_T_SIZE);
247
- sigdelset(&uc->uc_sigmask, SIGSEGV);
248
- sigdelset(&uc->uc_sigmask, SIGBUS);
249
+ memset(sigmask, 0xff, SIGSET_T_SIZE);
250
+ sigdelset(sigmask, SIGSEGV);
251
+ sigdelset(sigmask, SIGBUS);
252
253
/* interrupt the virtual CPU as soon as possible */
254
cpu_exit(thread_cpu);
255
--
256
2.25.1
257
258
diff view generated by jsdifflib
New patch
1
Do not directly access ucontext_t as the third signal parameter.
2
This is preparation for a sparc64 fix.
1
3
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
linux-user/include/host/aarch64/host-signal.h | 13 ++++++++-----
9
linux-user/include/host/alpha/host-signal.h | 11 +++++++----
10
linux-user/include/host/arm/host-signal.h | 11 +++++++----
11
linux-user/include/host/i386/host-signal.h | 11 +++++++----
12
linux-user/include/host/loongarch64/host-signal.h | 11 +++++++----
13
linux-user/include/host/mips/host-signal.h | 11 +++++++----
14
linux-user/include/host/ppc/host-signal.h | 11 +++++++----
15
linux-user/include/host/riscv/host-signal.h | 11 +++++++----
16
linux-user/include/host/s390/host-signal.h | 11 +++++++----
17
linux-user/include/host/sparc/host-signal.h | 11 +++++++----
18
linux-user/include/host/x86_64/host-signal.h | 11 +++++++----
19
linux-user/signal.c | 4 ++--
20
12 files changed, 80 insertions(+), 47 deletions(-)
21
22
diff --git a/linux-user/include/host/aarch64/host-signal.h b/linux-user/include/host/aarch64/host-signal.h
23
index XXXXXXX..XXXXXXX 100644
24
--- a/linux-user/include/host/aarch64/host-signal.h
25
+++ b/linux-user/include/host/aarch64/host-signal.h
26
@@ -XXX,XX +XXX,XX @@
27
#ifndef AARCH64_HOST_SIGNAL_H
28
#define AARCH64_HOST_SIGNAL_H
29
30
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
31
+typedef ucontext_t host_sigcontext;
32
+
33
/* Pre-3.16 kernel headers don't have these, so provide fallback definitions */
34
#ifndef ESR_MAGIC
35
#define ESR_MAGIC 0x45535201
36
@@ -XXX,XX +XXX,XX @@ struct esr_context {
37
};
38
#endif
39
40
-static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc)
41
+static inline struct _aarch64_ctx *first_ctx(host_sigcontext *uc)
42
{
43
return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved;
44
}
45
@@ -XXX,XX +XXX,XX @@ static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr)
46
return (struct _aarch64_ctx *)((char *)hdr + hdr->size);
47
}
48
49
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
50
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
51
{
52
return uc->uc_mcontext.pc;
53
}
54
55
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
56
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
57
{
58
uc->uc_mcontext.pc = pc;
59
}
60
61
-static inline void *host_signal_mask(ucontext_t *uc)
62
+static inline void *host_signal_mask(host_sigcontext *uc)
63
{
64
return &uc->uc_sigmask;
65
}
66
67
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
68
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
69
{
70
struct _aarch64_ctx *hdr;
71
uint32_t insn;
72
diff --git a/linux-user/include/host/alpha/host-signal.h b/linux-user/include/host/alpha/host-signal.h
73
index XXXXXXX..XXXXXXX 100644
74
--- a/linux-user/include/host/alpha/host-signal.h
75
+++ b/linux-user/include/host/alpha/host-signal.h
76
@@ -XXX,XX +XXX,XX @@
77
#ifndef ALPHA_HOST_SIGNAL_H
78
#define ALPHA_HOST_SIGNAL_H
79
80
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
81
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
82
+typedef ucontext_t host_sigcontext;
83
+
84
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
85
{
86
return uc->uc_mcontext.sc_pc;
87
}
88
89
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
90
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
91
{
92
uc->uc_mcontext.sc_pc = pc;
93
}
94
95
-static inline void *host_signal_mask(ucontext_t *uc)
96
+static inline void *host_signal_mask(host_sigcontext *uc)
97
{
98
return &uc->uc_sigmask;
99
}
100
101
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
102
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
103
{
104
uint32_t *pc = (uint32_t *)host_signal_pc(uc);
105
uint32_t insn = *pc;
106
diff --git a/linux-user/include/host/arm/host-signal.h b/linux-user/include/host/arm/host-signal.h
107
index XXXXXXX..XXXXXXX 100644
108
--- a/linux-user/include/host/arm/host-signal.h
109
+++ b/linux-user/include/host/arm/host-signal.h
110
@@ -XXX,XX +XXX,XX @@
111
#ifndef ARM_HOST_SIGNAL_H
112
#define ARM_HOST_SIGNAL_H
113
114
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
115
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
116
+typedef ucontext_t host_sigcontext;
117
+
118
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
119
{
120
return uc->uc_mcontext.arm_pc;
121
}
122
123
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
124
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
125
{
126
uc->uc_mcontext.arm_pc = pc;
127
}
128
129
-static inline void *host_signal_mask(ucontext_t *uc)
130
+static inline void *host_signal_mask(host_sigcontext *uc)
131
{
132
return &uc->uc_sigmask;
133
}
134
135
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
136
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
137
{
138
/*
139
* In the FSR, bit 11 is WnR, assuming a v6 or
140
diff --git a/linux-user/include/host/i386/host-signal.h b/linux-user/include/host/i386/host-signal.h
141
index XXXXXXX..XXXXXXX 100644
142
--- a/linux-user/include/host/i386/host-signal.h
143
+++ b/linux-user/include/host/i386/host-signal.h
144
@@ -XXX,XX +XXX,XX @@
145
#ifndef I386_HOST_SIGNAL_H
146
#define I386_HOST_SIGNAL_H
147
148
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
149
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
150
+typedef ucontext_t host_sigcontext;
151
+
152
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
153
{
154
return uc->uc_mcontext.gregs[REG_EIP];
155
}
156
157
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
158
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
159
{
160
uc->uc_mcontext.gregs[REG_EIP] = pc;
161
}
162
163
-static inline void *host_signal_mask(ucontext_t *uc)
164
+static inline void *host_signal_mask(host_sigcontext *uc)
165
{
166
return &uc->uc_sigmask;
167
}
168
169
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
170
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
171
{
172
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
173
&& (uc->uc_mcontext.gregs[REG_ERR] & 0x2);
174
diff --git a/linux-user/include/host/loongarch64/host-signal.h b/linux-user/include/host/loongarch64/host-signal.h
175
index XXXXXXX..XXXXXXX 100644
176
--- a/linux-user/include/host/loongarch64/host-signal.h
177
+++ b/linux-user/include/host/loongarch64/host-signal.h
178
@@ -XXX,XX +XXX,XX @@
179
#ifndef LOONGARCH64_HOST_SIGNAL_H
180
#define LOONGARCH64_HOST_SIGNAL_H
181
182
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
183
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
184
+typedef ucontext_t host_sigcontext;
185
+
186
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
187
{
188
return uc->uc_mcontext.__pc;
189
}
190
191
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
192
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
193
{
194
uc->uc_mcontext.__pc = pc;
195
}
196
197
-static inline void *host_signal_mask(ucontext_t *uc)
198
+static inline void *host_signal_mask(host_sigcontext *uc)
199
{
200
return &uc->uc_sigmask;
201
}
202
203
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
204
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
205
{
206
const uint32_t *pinsn = (const uint32_t *)host_signal_pc(uc);
207
uint32_t insn = pinsn[0];
208
diff --git a/linux-user/include/host/mips/host-signal.h b/linux-user/include/host/mips/host-signal.h
209
index XXXXXXX..XXXXXXX 100644
210
--- a/linux-user/include/host/mips/host-signal.h
211
+++ b/linux-user/include/host/mips/host-signal.h
212
@@ -XXX,XX +XXX,XX @@
213
#ifndef MIPS_HOST_SIGNAL_H
214
#define MIPS_HOST_SIGNAL_H
215
216
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
217
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
218
+typedef ucontext_t host_sigcontext;
219
+
220
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
221
{
222
return uc->uc_mcontext.pc;
223
}
224
225
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
226
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
227
{
228
uc->uc_mcontext.pc = pc;
229
}
230
231
-static inline void *host_signal_mask(ucontext_t *uc)
232
+static inline void *host_signal_mask(host_sigcontext *uc)
233
{
234
return &uc->uc_sigmask;
235
}
236
@@ -XXX,XX +XXX,XX @@ static inline void *host_signal_mask(ucontext_t *uc)
237
#error "Unsupported encoding"
238
#endif
239
240
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
241
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
242
{
243
uint32_t insn = *(uint32_t *)host_signal_pc(uc);
244
245
diff --git a/linux-user/include/host/ppc/host-signal.h b/linux-user/include/host/ppc/host-signal.h
246
index XXXXXXX..XXXXXXX 100644
247
--- a/linux-user/include/host/ppc/host-signal.h
248
+++ b/linux-user/include/host/ppc/host-signal.h
249
@@ -XXX,XX +XXX,XX @@
250
#ifndef PPC_HOST_SIGNAL_H
251
#define PPC_HOST_SIGNAL_H
252
253
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
254
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
255
+typedef ucontext_t host_sigcontext;
256
+
257
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
258
{
259
return uc->uc_mcontext.regs->nip;
260
}
261
262
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
263
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
264
{
265
uc->uc_mcontext.regs->nip = pc;
266
}
267
268
-static inline void *host_signal_mask(ucontext_t *uc)
269
+static inline void *host_signal_mask(host_sigcontext *uc)
270
{
271
return &uc->uc_sigmask;
272
}
273
274
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
275
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
276
{
277
return uc->uc_mcontext.regs->trap != 0x400
278
&& (uc->uc_mcontext.regs->dsisr & 0x02000000);
279
diff --git a/linux-user/include/host/riscv/host-signal.h b/linux-user/include/host/riscv/host-signal.h
280
index XXXXXXX..XXXXXXX 100644
281
--- a/linux-user/include/host/riscv/host-signal.h
282
+++ b/linux-user/include/host/riscv/host-signal.h
283
@@ -XXX,XX +XXX,XX @@
284
#ifndef RISCV_HOST_SIGNAL_H
285
#define RISCV_HOST_SIGNAL_H
286
287
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
288
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
289
+typedef ucontext_t host_sigcontext;
290
+
291
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
292
{
293
return uc->uc_mcontext.__gregs[REG_PC];
294
}
295
296
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
297
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
298
{
299
uc->uc_mcontext.__gregs[REG_PC] = pc;
300
}
301
302
-static inline void *host_signal_mask(ucontext_t *uc)
303
+static inline void *host_signal_mask(host_sigcontext *uc)
304
{
305
return &uc->uc_sigmask;
306
}
307
308
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
309
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
310
{
311
/*
312
* Detect store by reading the instruction at the program counter.
313
diff --git a/linux-user/include/host/s390/host-signal.h b/linux-user/include/host/s390/host-signal.h
314
index XXXXXXX..XXXXXXX 100644
315
--- a/linux-user/include/host/s390/host-signal.h
316
+++ b/linux-user/include/host/s390/host-signal.h
317
@@ -XXX,XX +XXX,XX @@
318
#ifndef S390_HOST_SIGNAL_H
319
#define S390_HOST_SIGNAL_H
320
321
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
322
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
323
+typedef ucontext_t host_sigcontext;
324
+
325
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
326
{
327
return uc->uc_mcontext.psw.addr;
328
}
329
330
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
331
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
332
{
333
uc->uc_mcontext.psw.addr = pc;
334
}
335
336
-static inline void *host_signal_mask(ucontext_t *uc)
337
+static inline void *host_signal_mask(host_sigcontext *uc)
338
{
339
return &uc->uc_sigmask;
340
}
341
342
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
343
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
344
{
345
uint16_t *pinsn = (uint16_t *)host_signal_pc(uc);
346
347
diff --git a/linux-user/include/host/sparc/host-signal.h b/linux-user/include/host/sparc/host-signal.h
348
index XXXXXXX..XXXXXXX 100644
349
--- a/linux-user/include/host/sparc/host-signal.h
350
+++ b/linux-user/include/host/sparc/host-signal.h
351
@@ -XXX,XX +XXX,XX @@
352
#ifndef SPARC_HOST_SIGNAL_H
353
#define SPARC_HOST_SIGNAL_H
354
355
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
356
+/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
357
+typedef ucontext_t host_sigcontext;
358
+
359
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
360
{
361
#ifdef __arch64__
362
return uc->uc_mcontext.mc_gregs[MC_PC];
363
@@ -XXX,XX +XXX,XX @@ static inline uintptr_t host_signal_pc(ucontext_t *uc)
364
#endif
365
}
366
367
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
368
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
369
{
370
#ifdef __arch64__
371
uc->uc_mcontext.mc_gregs[MC_PC] = pc;
372
@@ -XXX,XX +XXX,XX @@ static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
373
#endif
374
}
375
376
-static inline void *host_signal_mask(ucontext_t *uc)
377
+static inline void *host_signal_mask(host_sigcontext *uc)
378
{
379
return &uc->uc_sigmask;
380
}
381
382
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
383
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
384
{
385
uint32_t insn = *(uint32_t *)host_signal_pc(uc);
386
387
diff --git a/linux-user/include/host/x86_64/host-signal.h b/linux-user/include/host/x86_64/host-signal.h
388
index XXXXXXX..XXXXXXX 100644
389
--- a/linux-user/include/host/x86_64/host-signal.h
390
+++ b/linux-user/include/host/x86_64/host-signal.h
391
@@ -XXX,XX +XXX,XX @@
392
#ifndef X86_64_HOST_SIGNAL_H
393
#define X86_64_HOST_SIGNAL_H
394
395
-static inline uintptr_t host_signal_pc(ucontext_t *uc)
396
+/* The third argument to a SA_SIGINFO handler is ucontext_t. */
397
+typedef ucontext_t host_sigcontext;
398
+
399
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
400
{
401
return uc->uc_mcontext.gregs[REG_RIP];
402
}
403
404
-static inline void host_signal_set_pc(ucontext_t *uc, uintptr_t pc)
405
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
406
{
407
uc->uc_mcontext.gregs[REG_RIP] = pc;
408
}
409
410
-static inline void *host_signal_mask(ucontext_t *uc)
411
+static inline void *host_signal_mask(host_sigcontext *uc)
412
{
413
return &uc->uc_sigmask;
414
}
415
416
-static inline bool host_signal_write(siginfo_t *info, ucontext_t *uc)
417
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
418
{
419
return uc->uc_mcontext.gregs[REG_TRAPNO] == 0xe
420
&& (uc->uc_mcontext.gregs[REG_ERR] & 0x2);
421
diff --git a/linux-user/signal.c b/linux-user/signal.c
422
index XXXXXXX..XXXXXXX 100644
423
--- a/linux-user/signal.c
424
+++ b/linux-user/signal.c
425
@@ -XXX,XX +XXX,XX @@ void queue_signal(CPUArchState *env, int sig, int si_type,
426
/* Adjust the signal context to rewind out of safe-syscall if we're in it */
427
static inline void rewind_if_in_safe_syscall(void *puc)
428
{
429
- ucontext_t *uc = (ucontext_t *)puc;
430
+ host_sigcontext *uc = (host_sigcontext *)puc;
431
uintptr_t pcreg = host_signal_pc(uc);
432
433
if (pcreg > (uintptr_t)safe_syscall_start
434
@@ -XXX,XX +XXX,XX @@ static void host_signal_handler(int host_sig, siginfo_t *info, void *puc)
435
CPUState *cpu = env_cpu(env);
436
TaskState *ts = cpu->opaque;
437
target_siginfo_t tinfo;
438
- ucontext_t *uc = puc;
439
+ host_sigcontext *uc = puc;
440
struct emulated_sigtable *k;
441
int guest_sig;
442
uintptr_t pc = 0;
443
--
444
2.25.1
445
446
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
We do not support sparc32 as a host, so there's no point in
2
sparc64 redirecting to sparc.
2
3
3
after the initial split into 3 tcg variants, we proceed to also
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
split tcg_start_vcpu_thread.
5
6
We actually split it in 2 this time, since the icount variant
7
just uses the round robin function.
8
9
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
10
Signed-off-by: Claudio Fontana <cfontana@suse.de>
11
Message-Id: <20201015143217.29337-3-cfontana@suse.de>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
---
6
---
14
accel/tcg/tcg-cpus-mttcg.h | 21 --------------
7
linux-user/include/host/sparc/host-signal.h | 71 -------------------
15
accel/tcg/tcg-cpus-rr.h | 3 +-
8
linux-user/include/host/sparc64/host-signal.h | 64 ++++++++++++++++-
16
accel/tcg/tcg-cpus.h | 1 -
9
2 files changed, 63 insertions(+), 72 deletions(-)
17
accel/tcg/tcg-all.c | 5 ++++
10
delete mode 100644 linux-user/include/host/sparc/host-signal.h
18
accel/tcg/tcg-cpus-icount.c | 2 +-
19
accel/tcg/tcg-cpus-mttcg.c | 29 +++++++++++++++++--
20
accel/tcg/tcg-cpus-rr.c | 39 +++++++++++++++++++++++--
21
accel/tcg/tcg-cpus.c | 58 -------------------------------------
22
8 files changed, 71 insertions(+), 87 deletions(-)
23
delete mode 100644 accel/tcg/tcg-cpus-mttcg.h
24
11
25
diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h
12
diff --git a/linux-user/include/host/sparc/host-signal.h b/linux-user/include/host/sparc/host-signal.h
26
deleted file mode 100644
13
deleted file mode 100644
27
index XXXXXXX..XXXXXXX
14
index XXXXXXX..XXXXXXX
28
--- a/accel/tcg/tcg-cpus-mttcg.h
15
--- a/linux-user/include/host/sparc/host-signal.h
29
+++ /dev/null
16
+++ /dev/null
30
@@ -XXX,XX +XXX,XX @@
17
@@ -XXX,XX +XXX,XX @@
31
-/*
18
-/*
32
- * QEMU TCG Multi Threaded vCPUs implementation
19
- * host-signal.h: signal info dependent on the host architecture
33
- *
20
- *
34
- * Copyright 2020 SUSE LLC
21
- * Copyright (c) 2003-2005 Fabrice Bellard
22
- * Copyright (c) 2021 Linaro Limited
35
- *
23
- *
36
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
24
- * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
37
- * See the COPYING file in the top-level directory.
25
- * See the COPYING file in the top-level directory.
38
- */
26
- */
39
-
27
-
40
-#ifndef TCG_CPUS_MTTCG_H
28
-#ifndef SPARC_HOST_SIGNAL_H
41
-#define TCG_CPUS_MTTCG_H
29
-#define SPARC_HOST_SIGNAL_H
42
-
30
-
43
-/*
31
-/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
44
- * In the multi-threaded case each vCPU has its own thread. The TLS
32
-typedef ucontext_t host_sigcontext;
45
- * variable current_cpu can be used deep in the code to find the
46
- * current CPUState for a given thread.
47
- */
48
-
33
-
49
-void *tcg_cpu_thread_fn(void *arg);
34
-static inline uintptr_t host_signal_pc(host_sigcontext *uc)
35
-{
36
-#ifdef __arch64__
37
- return uc->uc_mcontext.mc_gregs[MC_PC];
38
-#else
39
- return uc->uc_mcontext.gregs[REG_PC];
40
-#endif
41
-}
50
-
42
-
51
-#endif /* TCG_CPUS_MTTCG_H */
43
-static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
52
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
44
-{
45
-#ifdef __arch64__
46
- uc->uc_mcontext.mc_gregs[MC_PC] = pc;
47
-#else
48
- uc->uc_mcontext.gregs[REG_PC] = pc;
49
-#endif
50
-}
51
-
52
-static inline void *host_signal_mask(host_sigcontext *uc)
53
-{
54
- return &uc->uc_sigmask;
55
-}
56
-
57
-static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
58
-{
59
- uint32_t insn = *(uint32_t *)host_signal_pc(uc);
60
-
61
- if ((insn >> 30) == 3) {
62
- switch ((insn >> 19) & 0x3f) {
63
- case 0x05: /* stb */
64
- case 0x15: /* stba */
65
- case 0x06: /* sth */
66
- case 0x16: /* stha */
67
- case 0x04: /* st */
68
- case 0x14: /* sta */
69
- case 0x07: /* std */
70
- case 0x17: /* stda */
71
- case 0x0e: /* stx */
72
- case 0x1e: /* stxa */
73
- case 0x24: /* stf */
74
- case 0x34: /* stfa */
75
- case 0x27: /* stdf */
76
- case 0x37: /* stdfa */
77
- case 0x26: /* stqf */
78
- case 0x36: /* stqfa */
79
- case 0x25: /* stfsr */
80
- case 0x3c: /* casa */
81
- case 0x3e: /* casxa */
82
- return true;
83
- }
84
- }
85
- return false;
86
-}
87
-
88
-#endif
89
diff --git a/linux-user/include/host/sparc64/host-signal.h b/linux-user/include/host/sparc64/host-signal.h
53
index XXXXXXX..XXXXXXX 100644
90
index XXXXXXX..XXXXXXX 100644
54
--- a/accel/tcg/tcg-cpus-rr.h
91
--- a/linux-user/include/host/sparc64/host-signal.h
55
+++ b/accel/tcg/tcg-cpus-rr.h
92
+++ b/linux-user/include/host/sparc64/host-signal.h
56
@@ -XXX,XX +XXX,XX @@
93
@@ -1 +1,63 @@
57
/* Kick all RR vCPUs. */
94
-#include "../sparc/host-signal.h"
58
void qemu_cpu_kick_rr_cpus(CPUState *unused);
95
+/*
59
96
+ * host-signal.h: signal info dependent on the host architecture
60
-void *tcg_rr_cpu_thread_fn(void *arg);
97
+ *
61
+/* start the round robin vcpu thread */
98
+ * Copyright (c) 2003-2005 Fabrice Bellard
62
+void rr_start_vcpu_thread(CPUState *cpu);
99
+ * Copyright (c) 2021 Linaro Limited
63
100
+ *
64
#endif /* TCG_CPUS_RR_H */
101
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
65
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
102
+ * See the COPYING file in the top-level directory.
66
index XXXXXXX..XXXXXXX 100644
103
+ */
67
--- a/accel/tcg/tcg-cpus.h
68
+++ b/accel/tcg/tcg-cpus.h
69
@@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg;
70
extern const CpusAccel tcg_cpus_icount;
71
extern const CpusAccel tcg_cpus_rr;
72
73
-void tcg_start_vcpu_thread(CPUState *cpu);
74
void qemu_tcg_destroy_vcpu(CPUState *cpu);
75
int tcg_cpu_exec(CPUState *cpu);
76
void tcg_handle_interrupt(CPUState *cpu, int mask);
77
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
78
index XXXXXXX..XXXXXXX 100644
79
--- a/accel/tcg/tcg-all.c
80
+++ b/accel/tcg/tcg-all.c
81
@@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms)
82
tcg_exec_init(s->tb_size * 1024 * 1024);
83
mttcg_enabled = s->mttcg_enabled;
84
85
+ /*
86
+ * Initialize TCG regions
87
+ */
88
+ tcg_region_init();
89
+
104
+
90
if (mttcg_enabled) {
105
+#ifndef SPARC64_HOST_SIGNAL_H
91
cpus_register_accel(&tcg_cpus_mttcg);
106
+#define SPARC64_HOST_SIGNAL_H
92
} else if (icount_enabled()) {
107
+
93
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
108
+/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
94
index XXXXXXX..XXXXXXX 100644
109
+typedef ucontext_t host_sigcontext;
95
--- a/accel/tcg/tcg-cpus-icount.c
110
+
96
+++ b/accel/tcg/tcg-cpus-icount.c
111
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
97
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
98
}
99
100
const CpusAccel tcg_cpus_icount = {
101
- .create_vcpu_thread = tcg_start_vcpu_thread,
102
+ .create_vcpu_thread = rr_start_vcpu_thread,
103
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
104
105
.handle_interrupt = icount_handle_interrupt,
106
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
107
index XXXXXXX..XXXXXXX 100644
108
--- a/accel/tcg/tcg-cpus-mttcg.c
109
+++ b/accel/tcg/tcg-cpus-mttcg.c
110
@@ -XXX,XX +XXX,XX @@
111
#include "hw/boards.h"
112
113
#include "tcg-cpus.h"
114
-#include "tcg-cpus-mttcg.h"
115
116
/*
117
* In the multi-threaded case each vCPU has its own thread. The TLS
118
@@ -XXX,XX +XXX,XX @@
119
* current CPUState for a given thread.
120
*/
121
122
-void *tcg_cpu_thread_fn(void *arg)
123
+static void *tcg_cpu_thread_fn(void *arg)
124
{
125
CPUState *cpu = arg;
126
127
@@ -XXX,XX +XXX,XX @@ static void mttcg_kick_vcpu_thread(CPUState *cpu)
128
cpu_exit(cpu);
129
}
130
131
+static void mttcg_start_vcpu_thread(CPUState *cpu)
132
+{
112
+{
133
+ char thread_name[VCPU_THREAD_NAME_SIZE];
113
+ return uc->uc_mcontext.mc_gregs[MC_PC];
134
+
135
+ g_assert(tcg_enabled());
136
+
137
+ parallel_cpus = (current_machine->smp.max_cpus > 1);
138
+
139
+ cpu->thread = g_malloc0(sizeof(QemuThread));
140
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
141
+ qemu_cond_init(cpu->halt_cond);
142
+
143
+ /* create a thread per vCPU with TCG (MTTCG) */
144
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
145
+ cpu->cpu_index);
146
+
147
+ qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
148
+ cpu, QEMU_THREAD_JOINABLE);
149
+
150
+#ifdef _WIN32
151
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
152
+#endif
153
+}
114
+}
154
+
115
+
155
const CpusAccel tcg_cpus_mttcg = {
116
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
156
- .create_vcpu_thread = tcg_start_vcpu_thread,
157
+ .create_vcpu_thread = mttcg_start_vcpu_thread,
158
.kick_vcpu_thread = mttcg_kick_vcpu_thread,
159
160
.handle_interrupt = tcg_handle_interrupt,
161
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
162
index XXXXXXX..XXXXXXX 100644
163
--- a/accel/tcg/tcg-cpus-rr.c
164
+++ b/accel/tcg/tcg-cpus-rr.c
165
@@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void)
166
* elsewhere.
167
*/
168
169
-void *tcg_rr_cpu_thread_fn(void *arg)
170
+static void *tcg_rr_cpu_thread_fn(void *arg)
171
{
172
CPUState *cpu = arg;
173
174
@@ -XXX,XX +XXX,XX @@ void *tcg_rr_cpu_thread_fn(void *arg)
175
return NULL;
176
}
177
178
+void rr_start_vcpu_thread(CPUState *cpu)
179
+{
117
+{
180
+ char thread_name[VCPU_THREAD_NAME_SIZE];
118
+ uc->uc_mcontext.mc_gregs[MC_PC] = pc;
181
+ static QemuCond *single_tcg_halt_cond;
182
+ static QemuThread *single_tcg_cpu_thread;
183
+
184
+ g_assert(tcg_enabled());
185
+ parallel_cpus = false;
186
+
187
+ if (!single_tcg_cpu_thread) {
188
+ cpu->thread = g_malloc0(sizeof(QemuThread));
189
+ cpu->halt_cond = g_malloc0(sizeof(QemuCond));
190
+ qemu_cond_init(cpu->halt_cond);
191
+
192
+ /* share a single thread for all cpus with TCG */
193
+ snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
194
+ qemu_thread_create(cpu->thread, thread_name,
195
+ tcg_rr_cpu_thread_fn,
196
+ cpu, QEMU_THREAD_JOINABLE);
197
+
198
+ single_tcg_halt_cond = cpu->halt_cond;
199
+ single_tcg_cpu_thread = cpu->thread;
200
+#ifdef _WIN32
201
+ cpu->hThread = qemu_thread_get_handle(cpu->thread);
202
+#endif
203
+ } else {
204
+ /* we share the thread */
205
+ cpu->thread = single_tcg_cpu_thread;
206
+ cpu->halt_cond = single_tcg_halt_cond;
207
+ cpu->thread_id = first_cpu->thread_id;
208
+ cpu->can_do_io = 1;
209
+ cpu->created = true;
210
+ }
211
+}
119
+}
212
+
120
+
213
const CpusAccel tcg_cpus_rr = {
121
+static inline void *host_signal_mask(host_sigcontext *uc)
214
- .create_vcpu_thread = tcg_start_vcpu_thread,
122
+{
215
+ .create_vcpu_thread = rr_start_vcpu_thread,
123
+ return &uc->uc_sigmask;
216
.kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
124
+}
217
125
+
218
.handle_interrupt = tcg_handle_interrupt,
126
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
219
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
127
+{
220
index XXXXXXX..XXXXXXX 100644
128
+ uint32_t insn = *(uint32_t *)host_signal_pc(uc);
221
--- a/accel/tcg/tcg-cpus.c
129
+
222
+++ b/accel/tcg/tcg-cpus.c
130
+ if ((insn >> 30) == 3) {
223
@@ -XXX,XX +XXX,XX @@
131
+ switch ((insn >> 19) & 0x3f) {
224
#include "hw/boards.h"
132
+ case 0x05: /* stb */
225
133
+ case 0x15: /* stba */
226
#include "tcg-cpus.h"
134
+ case 0x06: /* sth */
227
-#include "tcg-cpus-mttcg.h"
135
+ case 0x16: /* stha */
228
-#include "tcg-cpus-rr.h"
136
+ case 0x04: /* st */
229
137
+ case 0x14: /* sta */
230
/* common functionality among all TCG variants */
138
+ case 0x07: /* std */
231
139
+ case 0x17: /* stda */
232
-void tcg_start_vcpu_thread(CPUState *cpu)
140
+ case 0x0e: /* stx */
233
-{
141
+ case 0x1e: /* stxa */
234
- char thread_name[VCPU_THREAD_NAME_SIZE];
142
+ case 0x24: /* stf */
235
- static QemuCond *single_tcg_halt_cond;
143
+ case 0x34: /* stfa */
236
- static QemuThread *single_tcg_cpu_thread;
144
+ case 0x27: /* stdf */
237
- static int tcg_region_inited;
145
+ case 0x37: /* stdfa */
238
-
146
+ case 0x26: /* stqf */
239
- assert(tcg_enabled());
147
+ case 0x36: /* stqfa */
240
- /*
148
+ case 0x25: /* stfsr */
241
- * Initialize TCG regions--once. Now is a good time, because:
149
+ case 0x3c: /* casa */
242
- * (1) TCG's init context, prologue and target globals have been set up.
150
+ case 0x3e: /* casxa */
243
- * (2) qemu_tcg_mttcg_enabled() works now (TCG init code runs before the
151
+ return true;
244
- * -accel flag is processed, so the check doesn't work then).
152
+ }
245
- */
153
+ }
246
- if (!tcg_region_inited) {
154
+ return false;
247
- tcg_region_inited = 1;
155
+}
248
- tcg_region_init();
156
+
249
- parallel_cpus = qemu_tcg_mttcg_enabled() && current_machine->smp.max_cpus > 1;
157
+#endif
250
- }
251
-
252
- if (qemu_tcg_mttcg_enabled() || !single_tcg_cpu_thread) {
253
- cpu->thread = g_malloc0(sizeof(QemuThread));
254
- cpu->halt_cond = g_malloc0(sizeof(QemuCond));
255
- qemu_cond_init(cpu->halt_cond);
256
-
257
- if (qemu_tcg_mttcg_enabled()) {
258
- /* create a thread per vCPU with TCG (MTTCG) */
259
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
260
- cpu->cpu_index);
261
-
262
- qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
263
- cpu, QEMU_THREAD_JOINABLE);
264
-
265
- } else {
266
- /* share a single thread for all cpus with TCG */
267
- snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
268
- qemu_thread_create(cpu->thread, thread_name,
269
- tcg_rr_cpu_thread_fn,
270
- cpu, QEMU_THREAD_JOINABLE);
271
-
272
- single_tcg_halt_cond = cpu->halt_cond;
273
- single_tcg_cpu_thread = cpu->thread;
274
- }
275
-#ifdef _WIN32
276
- cpu->hThread = qemu_thread_get_handle(cpu->thread);
277
-#endif
278
- } else {
279
- /* For non-MTTCG cases we share the thread */
280
- cpu->thread = single_tcg_cpu_thread;
281
- cpu->halt_cond = single_tcg_halt_cond;
282
- cpu->thread_id = first_cpu->thread_id;
283
- cpu->can_do_io = 1;
284
- cpu->created = true;
285
- }
286
-}
287
-
288
void qemu_tcg_destroy_vcpu(CPUState *cpu)
289
{
290
cpu_thread_signal_destroyed(cpu);
291
--
158
--
292
2.25.1
159
2.25.1
293
160
294
161
diff view generated by jsdifflib
New patch
1
Sparc64 is unique on linux in *not* passing ucontext_t as
2
the third argument to a SA_SIGINFO handler. It passes the
3
old struct sigcontext instead.
1
4
5
Set both pc and npc in host_signal_set_pc.
6
7
Fixes: 8b5bd461935b ("linux-user/host/sparc: Populate host_signal.h")
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
---
11
linux-user/include/host/sparc64/host-signal.h | 17 +++++++++--------
12
1 file changed, 9 insertions(+), 8 deletions(-)
13
14
diff --git a/linux-user/include/host/sparc64/host-signal.h b/linux-user/include/host/sparc64/host-signal.h
15
index XXXXXXX..XXXXXXX 100644
16
--- a/linux-user/include/host/sparc64/host-signal.h
17
+++ b/linux-user/include/host/sparc64/host-signal.h
18
@@ -XXX,XX +XXX,XX @@
19
#ifndef SPARC64_HOST_SIGNAL_H
20
#define SPARC64_HOST_SIGNAL_H
21
22
-/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
23
-typedef ucontext_t host_sigcontext;
24
+/* The third argument to a SA_SIGINFO handler is struct sigcontext. */
25
+typedef struct sigcontext host_sigcontext;
26
27
-static inline uintptr_t host_signal_pc(host_sigcontext *uc)
28
+static inline uintptr_t host_signal_pc(host_sigcontext *sc)
29
{
30
- return uc->uc_mcontext.mc_gregs[MC_PC];
31
+ return sc->sigc_regs.tpc;
32
}
33
34
-static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
35
+static inline void host_signal_set_pc(host_sigcontext *sc, uintptr_t pc)
36
{
37
- uc->uc_mcontext.mc_gregs[MC_PC] = pc;
38
+ sc->sigc_regs.tpc = pc;
39
+ sc->sigc_regs.tnpc = pc + 4;
40
}
41
42
-static inline void *host_signal_mask(host_sigcontext *uc)
43
+static inline void *host_signal_mask(host_sigcontext *sc)
44
{
45
- return &uc->uc_sigmask;
46
+ return &sc->sigc_mask;
47
}
48
49
static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
50
--
51
2.25.1
52
53
diff view generated by jsdifflib
New patch
1
From: Idan Horowitz <idan.horowitz@gmail.com>
1
2
3
When the length of the range is large enough, clearing the whole cache is
4
faster than iterating over the (possibly extremely large) set of pages
5
contained in the range.
6
7
This mimics the pre-existing similar optimization done on the flush of the
8
tlb itself.
9
10
Signed-off-by: Idan Horowitz <idan.horowitz@gmail.com>
11
Message-Id: <20220110164754.1066025-1-idan.horowitz@gmail.com>
12
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
13
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
14
---
15
accel/tcg/cputlb.c | 9 +++++++++
16
1 file changed, 9 insertions(+)
17
18
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/accel/tcg/cputlb.c
21
+++ b/accel/tcg/cputlb.c
22
@@ -XXX,XX +XXX,XX @@ static void tlb_flush_range_by_mmuidx_async_0(CPUState *cpu,
23
}
24
qemu_spin_unlock(&env_tlb(env)->c.lock);
25
26
+ /*
27
+ * If the length is larger than the jump cache size, then it will take
28
+ * longer to clear each entry individually than it will to clear it all.
29
+ */
30
+ if (d.len >= (TARGET_PAGE_SIZE * TB_JMP_CACHE_SIZE)) {
31
+ cpu_tb_jmp_cache_clear(cpu);
32
+ return;
33
+ }
34
+
35
for (target_ulong i = 0; i < d.len; i += TARGET_PAGE_SIZE) {
36
tb_flush_jmp_cache(cpu, d.addr + i);
37
}
38
--
39
2.25.1
40
41
diff view generated by jsdifflib
New patch
1
From: Idan Horowitz <idan.horowitz@gmail.com>
1
2
3
Instead of taking the lock of the cpu work list in order to check if it's
4
empty, we can just read the head pointer atomically. This decreases
5
cpu_work_list_empty's share from 5% to 1.3% in a profile of icount-enabled
6
aarch64-softmmu.
7
8
Signed-off-by: Idan Horowitz <idan.horowitz@gmail.com>
9
Message-Id: <20220114004358.299534-1-idan.horowitz@gmail.com>
10
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
softmmu/cpus.c | 7 +------
14
1 file changed, 1 insertion(+), 6 deletions(-)
15
16
diff --git a/softmmu/cpus.c b/softmmu/cpus.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/softmmu/cpus.c
19
+++ b/softmmu/cpus.c
20
@@ -XXX,XX +XXX,XX @@ bool cpu_is_stopped(CPUState *cpu)
21
22
bool cpu_work_list_empty(CPUState *cpu)
23
{
24
- bool ret;
25
-
26
- qemu_mutex_lock(&cpu->work_mutex);
27
- ret = QSIMPLEQ_EMPTY(&cpu->work_list);
28
- qemu_mutex_unlock(&cpu->work_mutex);
29
- return ret;
30
+ return QSIMPLEQ_EMPTY_ATOMIC(&cpu->work_list);
31
}
32
33
bool cpu_thread_is_idle(CPUState *cpu)
34
--
35
2.25.1
36
37
diff view generated by jsdifflib
New patch
1
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
1
2
3
Commit aff0e204cb1f1c036a496c94c15f5dfafcd9b4b4 introduced CF_NOIRQ usage,
4
but one case was forgotten. Record/replay uses one special TB which is not
5
really executed, but used to cause a correct exception in replay mode.
6
This patch adds CF_NOIRQ flag for such block.
7
8
Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgalyuk@ispras.ru>
9
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
10
Message-Id: <164362834054.1754532.7678416881159817273.stgit@pasha-ThinkPad-X280>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
accel/tcg/cpu-exec.c | 3 ++-
14
1 file changed, 2 insertions(+), 1 deletion(-)
15
16
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/accel/tcg/cpu-exec.c
19
+++ b/accel/tcg/cpu-exec.c
20
@@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
21
if (replay_has_exception()
22
&& cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) {
23
/* Execute just one insn to trigger exception pending in the log */
24
- cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT) | 1;
25
+ cpu->cflags_next_tb = (curr_cflags(cpu) & ~CF_USE_ICOUNT)
26
+ | CF_NOIRQ | 1;
27
}
28
#endif
29
return false;
30
--
31
2.25.1
32
33
diff view generated by jsdifflib
New patch
1
From: WANG Xuerui <git@xen0n.name>
1
2
3
Apparently we were left behind; just renaming MO_Q to MO_UQ is enough.
4
5
Fixes: fc313c64345453c7 ("exec/memop: Adding signedness to quad definitions")
6
Signed-off-by: WANG Xuerui <git@xen0n.name>
7
Message-Id: <20220206162106.1092364-1-i.qemu@xen0n.name>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
---
10
tcg/loongarch64/tcg-target.c.inc | 2 +-
11
1 file changed, 1 insertion(+), 1 deletion(-)
12
13
diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
14
index XXXXXXX..XXXXXXX 100644
15
--- a/tcg/loongarch64/tcg-target.c.inc
16
+++ b/tcg/loongarch64/tcg-target.c.inc
17
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_indexed(TCGContext *s, TCGReg rd, TCGReg rj,
18
case MO_SL:
19
tcg_out_opc_ldx_w(s, rd, rj, rk);
20
break;
21
- case MO_Q:
22
+ case MO_UQ:
23
tcg_out_opc_ldx_d(s, rd, rj, rk);
24
break;
25
default:
26
--
27
2.25.1
28
29
diff view generated by jsdifflib
New patch
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/i386/tcg-target.h | 2 -
5
tcg/i386/tcg-target.c.inc | 103 ++++++++++++++++++++++++++++++++++++--
6
2 files changed, 98 insertions(+), 7 deletions(-)
1
7
8
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
9
index XXXXXXX..XXXXXXX 100644
10
--- a/tcg/i386/tcg-target.h
11
+++ b/tcg/i386/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
13
14
#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe
15
16
-#ifdef CONFIG_SOFTMMU
17
#define TCG_TARGET_NEED_LDST_LABELS
18
-#endif
19
#define TCG_TARGET_NEED_POOL_LABELS
20
21
#endif
22
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/i386/tcg-target.c.inc
25
+++ b/tcg/i386/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@
27
* THE SOFTWARE.
28
*/
29
30
+#include "../tcg-ldst.c.inc"
31
#include "../tcg-pool.c.inc"
32
33
#ifdef CONFIG_DEBUG_TCG
34
@@ -XXX,XX +XXX,XX @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct)
35
#define OPC_VZEROUPPER (0x77 | P_EXT)
36
#define OPC_XCHG_ax_r32    (0x90)
37
38
-#define OPC_GRP3_Ev    (0xf7)
39
-#define OPC_GRP5    (0xff)
40
+#define OPC_GRP3_Eb (0xf6)
41
+#define OPC_GRP3_Ev (0xf7)
42
+#define OPC_GRP5 (0xff)
43
#define OPC_GRP14 (0x73 | P_EXT | P_DATA16)
44
45
/* Group 1 opcode extensions for 0x80-0x83.
46
@@ -XXX,XX +XXX,XX @@ static bool tcg_target_const_match(int64_t val, TCGType type, int ct)
47
#define SHIFT_SAR 7
48
49
/* Group 3 opcode extensions for 0xf6, 0xf7. To be used with OPC_GRP3. */
50
+#define EXT3_TESTi 0
51
#define EXT3_NOT 2
52
#define EXT3_NEG 3
53
#define EXT3_MUL 4
54
@@ -XXX,XX +XXX,XX @@ static void tcg_out_nopn(TCGContext *s, int n)
55
}
56
57
#if defined(CONFIG_SOFTMMU)
58
-#include "../tcg-ldst.c.inc"
59
-
60
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
61
* int mmu_idx, uintptr_t ra)
62
*/
63
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
64
tcg_out_jmp(s, qemu_st_helpers[opc & (MO_BSWAP | MO_SIZE)]);
65
return true;
66
}
67
-#elif TCG_TARGET_REG_BITS == 32
68
+#else
69
+
70
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
71
+ TCGReg addrhi, unsigned a_bits)
72
+{
73
+ unsigned a_mask = (1 << a_bits) - 1;
74
+ TCGLabelQemuLdst *label;
75
+
76
+ /*
77
+ * We are expecting a_bits to max out at 7, so we can usually use testb.
78
+ * For i686, we have to use testl for %esi/%edi.
79
+ */
80
+ if (a_mask <= 0xff && (TCG_TARGET_REG_BITS == 64 || addrlo < 4)) {
81
+ tcg_out_modrm(s, OPC_GRP3_Eb | P_REXB_RM, EXT3_TESTi, addrlo);
82
+ tcg_out8(s, a_mask);
83
+ } else {
84
+ tcg_out_modrm(s, OPC_GRP3_Ev, EXT3_TESTi, addrlo);
85
+ tcg_out32(s, a_mask);
86
+ }
87
+
88
+ /* jne slow_path */
89
+ tcg_out_opc(s, OPC_JCC_long + JCC_JNE, 0, 0, 0);
90
+
91
+ label = new_ldst_label(s);
92
+ label->is_ld = is_ld;
93
+ label->addrlo_reg = addrlo;
94
+ label->addrhi_reg = addrhi;
95
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr + 4);
96
+ label->label_ptr[0] = s->code_ptr;
97
+
98
+ s->code_ptr += 4;
99
+}
100
+
101
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
102
+{
103
+ /* resolve label address */
104
+ tcg_patch32(l->label_ptr[0], s->code_ptr - l->label_ptr[0] - 4);
105
+
106
+ if (TCG_TARGET_REG_BITS == 32) {
107
+ int ofs = 0;
108
+
109
+ tcg_out_st(s, TCG_TYPE_PTR, TCG_AREG0, TCG_REG_ESP, ofs);
110
+ ofs += 4;
111
+
112
+ tcg_out_st(s, TCG_TYPE_I32, l->addrlo_reg, TCG_REG_ESP, ofs);
113
+ ofs += 4;
114
+ if (TARGET_LONG_BITS == 64) {
115
+ tcg_out_st(s, TCG_TYPE_I32, l->addrhi_reg, TCG_REG_ESP, ofs);
116
+ ofs += 4;
117
+ }
118
+
119
+ tcg_out_pushi(s, (uintptr_t)l->raddr);
120
+ } else {
121
+ tcg_out_mov(s, TCG_TYPE_TL, tcg_target_call_iarg_regs[1],
122
+ l->addrlo_reg);
123
+ tcg_out_mov(s, TCG_TYPE_PTR, tcg_target_call_iarg_regs[0], TCG_AREG0);
124
+
125
+ tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RAX, (uintptr_t)l->raddr);
126
+ tcg_out_push(s, TCG_REG_RAX);
127
+ }
128
+
129
+ /* "Tail call" to the helper, with the return address back inline. */
130
+ tcg_out_jmp(s, (const void *)(l->is_ld ? helper_unaligned_ld
131
+ : helper_unaligned_st));
132
+ return true;
133
+}
134
+
135
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
136
+{
137
+ return tcg_out_fail_alignment(s, l);
138
+}
139
+
140
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
141
+{
142
+ return tcg_out_fail_alignment(s, l);
143
+}
144
+
145
+#if TCG_TARGET_REG_BITS == 32
146
# define x86_guest_base_seg 0
147
# define x86_guest_base_index -1
148
# define x86_guest_base_offset guest_base
149
@@ -XXX,XX +XXX,XX @@ static inline int setup_guest_base_seg(void)
150
return 0;
151
}
152
# endif
153
+#endif
154
#endif /* SOFTMMU */
155
156
static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg datalo, TCGReg datahi,
157
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
158
#if defined(CONFIG_SOFTMMU)
159
int mem_index;
160
tcg_insn_unit *label_ptr[2];
161
+#else
162
+ unsigned a_bits;
163
#endif
164
165
datalo = *args++;
166
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
167
add_qemu_ldst_label(s, true, is64, oi, datalo, datahi, addrlo, addrhi,
168
s->code_ptr, label_ptr);
169
#else
170
+ a_bits = get_alignment_bits(opc);
171
+ if (a_bits) {
172
+ tcg_out_test_alignment(s, true, addrlo, addrhi, a_bits);
173
+ }
174
+
175
tcg_out_qemu_ld_direct(s, datalo, datahi, addrlo, x86_guest_base_index,
176
x86_guest_base_offset, x86_guest_base_seg,
177
is64, opc);
178
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
179
#if defined(CONFIG_SOFTMMU)
180
int mem_index;
181
tcg_insn_unit *label_ptr[2];
182
+#else
183
+ unsigned a_bits;
184
#endif
185
186
datalo = *args++;
187
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
188
add_qemu_ldst_label(s, false, is64, oi, datalo, datahi, addrlo, addrhi,
189
s->code_ptr, label_ptr);
190
#else
191
+ a_bits = get_alignment_bits(opc);
192
+ if (a_bits) {
193
+ tcg_out_test_alignment(s, false, addrlo, addrhi, a_bits);
194
+ }
195
+
196
tcg_out_qemu_st_direct(s, datalo, datahi, addrlo, x86_guest_base_index,
197
x86_guest_base_offset, x86_guest_base_seg, opc);
198
#endif
199
--
200
2.25.1
201
202
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Signed-off-by: Claudio Fontana <cfontana@suse.de>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Message-Id: <20201015143217.29337-4-cfontana@suse.de>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
3
---
8
accel/tcg/tcg-cpus-icount.h | 6 +--
4
tcg/aarch64/tcg-target.h | 2 -
9
accel/tcg/tcg-cpus-rr.h | 2 +-
5
tcg/aarch64/tcg-target.c.inc | 91 +++++++++++++++++++++++++++++-------
10
accel/tcg/tcg-cpus.h | 6 +--
6
2 files changed, 74 insertions(+), 19 deletions(-)
11
accel/tcg/tcg-cpus-icount.c | 24 ++++++------
12
accel/tcg/tcg-cpus-mttcg.c | 10 ++---
13
accel/tcg/tcg-cpus-rr.c | 74 ++++++++++++++++++-------------------
14
accel/tcg/tcg-cpus.c | 6 +--
15
7 files changed, 64 insertions(+), 64 deletions(-)
16
7
17
diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h
8
diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
18
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
19
--- a/accel/tcg/tcg-cpus-icount.h
10
--- a/tcg/aarch64/tcg-target.h
20
+++ b/accel/tcg/tcg-cpus-icount.h
11
+++ b/tcg/aarch64/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ typedef enum {
13
14
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
15
16
-#ifdef CONFIG_SOFTMMU
17
#define TCG_TARGET_NEED_LDST_LABELS
18
-#endif
19
#define TCG_TARGET_NEED_POOL_LABELS
20
21
#endif /* AARCH64_TCG_TARGET_H */
22
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/aarch64/tcg-target.c.inc
25
+++ b/tcg/aarch64/tcg-target.c.inc
21
@@ -XXX,XX +XXX,XX @@
26
@@ -XXX,XX +XXX,XX @@
22
#ifndef TCG_CPUS_ICOUNT_H
27
* See the COPYING file in the top-level directory for details.
23
#define TCG_CPUS_ICOUNT_H
28
*/
24
29
25
-void handle_icount_deadline(void);
30
+#include "../tcg-ldst.c.inc"
26
-void prepare_icount_for_run(CPUState *cpu);
31
#include "../tcg-pool.c.inc"
27
-void process_icount_data(CPUState *cpu);
32
#include "qemu/bitops.h"
28
+void icount_handle_deadline(void);
33
29
+void icount_prepare_for_run(CPUState *cpu);
34
@@ -XXX,XX +XXX,XX @@ typedef enum {
30
+void icount_process_data(CPUState *cpu);
35
I3404_ANDI = 0x12000000,
31
36
I3404_ORRI = 0x32000000,
32
#endif /* TCG_CPUS_ICOUNT_H */
37
I3404_EORI = 0x52000000,
33
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
38
+ I3404_ANDSI = 0x72000000,
34
index XXXXXXX..XXXXXXX 100644
39
35
--- a/accel/tcg/tcg-cpus-rr.h
40
/* Move wide immediate instructions. */
36
+++ b/accel/tcg/tcg-cpus-rr.h
41
I3405_MOVN = 0x12800000,
37
@@ -XXX,XX +XXX,XX @@
42
@@ -XXX,XX +XXX,XX @@ static void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target)
38
#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
43
if (offset == sextract64(offset, 0, 26)) {
39
44
tcg_out_insn(s, 3206, B, offset);
40
/* Kick all RR vCPUs. */
45
} else {
41
-void qemu_cpu_kick_rr_cpus(CPUState *unused);
46
- tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP, (intptr_t)target);
42
+void rr_kick_vcpu_thread(CPUState *unused);
47
- tcg_out_insn(s, 3207, BR, TCG_REG_TMP);
43
48
+ /* Choose X9 as a call-clobbered non-LR temporary. */
44
/* start the round robin vcpu thread */
49
+ tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X9, (intptr_t)target);
45
void rr_start_vcpu_thread(CPUState *cpu);
50
+ tcg_out_insn(s, 3207, BR, TCG_REG_X9);
46
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
47
index XXXXXXX..XXXXXXX 100644
48
--- a/accel/tcg/tcg-cpus.h
49
+++ b/accel/tcg/tcg-cpus.h
50
@@ -XXX,XX +XXX,XX @@ extern const CpusAccel tcg_cpus_mttcg;
51
extern const CpusAccel tcg_cpus_icount;
52
extern const CpusAccel tcg_cpus_rr;
53
54
-void qemu_tcg_destroy_vcpu(CPUState *cpu);
55
-int tcg_cpu_exec(CPUState *cpu);
56
-void tcg_handle_interrupt(CPUState *cpu, int mask);
57
+void tcg_cpus_destroy(CPUState *cpu);
58
+int tcg_cpus_exec(CPUState *cpu);
59
+void tcg_cpus_handle_interrupt(CPUState *cpu, int mask);
60
61
#endif /* TCG_CPUS_H */
62
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
63
index XXXXXXX..XXXXXXX 100644
64
--- a/accel/tcg/tcg-cpus-icount.c
65
+++ b/accel/tcg/tcg-cpus-icount.c
66
@@ -XXX,XX +XXX,XX @@
67
#include "tcg-cpus-icount.h"
68
#include "tcg-cpus-rr.h"
69
70
-static int64_t tcg_get_icount_limit(void)
71
+static int64_t icount_get_limit(void)
72
{
73
int64_t deadline;
74
75
@@ -XXX,XX +XXX,XX @@ static int64_t tcg_get_icount_limit(void)
76
}
51
}
77
}
52
}
78
53
79
-static void notify_aio_contexts(void)
54
@@ -XXX,XX +XXX,XX @@ static void tcg_out_cltz(TCGContext *s, TCGType ext, TCGReg d,
80
+static void icount_notify_aio_contexts(void)
81
{
82
/* Wake up other AioContexts. */
83
qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
84
qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
85
}
86
87
-void handle_icount_deadline(void)
88
+void icount_handle_deadline(void)
89
{
90
assert(qemu_in_vcpu_thread());
91
int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
92
QEMU_TIMER_ATTR_ALL);
93
94
if (deadline == 0) {
95
- notify_aio_contexts();
96
+ icount_notify_aio_contexts();
97
}
55
}
98
}
56
}
99
57
100
-void prepare_icount_for_run(CPUState *cpu)
58
-#ifdef CONFIG_SOFTMMU
101
+void icount_prepare_for_run(CPUState *cpu)
59
-#include "../tcg-ldst.c.inc"
102
{
60
+static void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
103
int insns_left;
61
+{
104
62
+ ptrdiff_t offset = tcg_pcrel_diff(s, target);
105
/*
63
+ tcg_debug_assert(offset == sextract64(offset, 0, 21));
106
- * These should always be cleared by process_icount_data after
64
+ tcg_out_insn(s, 3406, ADR, rd, offset);
107
+ * These should always be cleared by icount_process_data after
65
+}
108
* each vCPU execution. However u16.high can be raised
66
109
- * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
67
+#ifdef CONFIG_SOFTMMU
110
+ * asynchronously by cpu_exit/cpu_interrupt/tcg_cpus_handle_interrupt
68
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
111
*/
69
* MemOpIdx oi, uintptr_t ra)
112
g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
70
*/
113
g_assert(cpu->icount_extra == 0);
71
@@ -XXX,XX +XXX,XX @@ static void * const qemu_st_helpers[MO_SIZE + 1] = {
114
72
#endif
115
- cpu->icount_budget = tcg_get_icount_limit();
73
};
116
+ cpu->icount_budget = icount_get_limit();
74
117
insns_left = MIN(0xffff, cpu->icount_budget);
75
-static inline void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
118
cpu_neg(cpu)->icount_decr.u16.low = insns_left;
76
-{
119
cpu->icount_extra = cpu->icount_budget - insns_left;
77
- ptrdiff_t offset = tcg_pcrel_diff(s, target);
120
@@ -XXX,XX +XXX,XX @@ void prepare_icount_for_run(CPUState *cpu)
78
- tcg_debug_assert(offset == sextract64(offset, 0, 21));
121
replay_mutex_lock();
79
- tcg_out_insn(s, 3406, ADR, rd, offset);
122
80
-}
123
if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
81
-
124
- notify_aio_contexts();
82
static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
125
+ icount_notify_aio_contexts();
83
{
126
}
84
MemOpIdx oi = lb->oi;
85
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, MemOp opc,
86
tcg_out_insn(s, 3202, B_C, TCG_COND_NE, 0);
127
}
87
}
128
88
129
-void process_icount_data(CPUState *cpu)
89
+#else
130
+void icount_process_data(CPUState *cpu)
90
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addr_reg,
131
{
91
+ unsigned a_bits)
132
/* Account for executed instructions */
92
+{
133
icount_update(cpu);
93
+ unsigned a_mask = (1 << a_bits) - 1;
134
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
94
+ TCGLabelQemuLdst *label = new_ldst_label(s);
135
{
95
+
136
int old_mask = cpu->interrupt_request;
96
+ label->is_ld = is_ld;
137
97
+ label->addrlo_reg = addr_reg;
138
- tcg_handle_interrupt(cpu, mask);
98
+
139
+ tcg_cpus_handle_interrupt(cpu, mask);
99
+ /* tst addr, #mask */
140
if (qemu_cpu_is_self(cpu) &&
100
+ tcg_out_logicali(s, I3404_ANDSI, 0, TCG_REG_XZR, addr_reg, a_mask);
141
!cpu->can_do_io
101
+
142
&& (mask & ~old_mask) != 0) {
102
+ label->label_ptr[0] = s->code_ptr;
143
@@ -XXX,XX +XXX,XX @@ static void icount_handle_interrupt(CPUState *cpu, int mask)
103
+
144
104
+ /* b.ne slow_path */
145
const CpusAccel tcg_cpus_icount = {
105
+ tcg_out_insn(s, 3202, B_C, TCG_COND_NE, 0);
146
.create_vcpu_thread = rr_start_vcpu_thread,
106
+
147
- .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
107
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr);
148
+ .kick_vcpu_thread = rr_kick_vcpu_thread,
108
+}
149
109
+
150
.handle_interrupt = icount_handle_interrupt,
110
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
151
.get_virtual_clock = icount_get,
111
+{
152
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
112
+ if (!reloc_pc19(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
153
index XXXXXXX..XXXXXXX 100644
113
+ return false;
154
--- a/accel/tcg/tcg-cpus-mttcg.c
114
+ }
155
+++ b/accel/tcg/tcg-cpus-mttcg.c
115
+
156
@@ -XXX,XX +XXX,XX @@
116
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_X1, l->addrlo_reg);
157
* current CPUState for a given thread.
117
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_X0, TCG_AREG0);
158
*/
118
+
159
119
+ /* "Tail call" to the helper, with the return address back inline. */
160
-static void *tcg_cpu_thread_fn(void *arg)
120
+ tcg_out_adr(s, TCG_REG_LR, l->raddr);
161
+static void *mttcg_cpu_thread_fn(void *arg)
121
+ tcg_out_goto_long(s, (const void *)(l->is_ld ? helper_unaligned_ld
162
{
122
+ : helper_unaligned_st));
163
CPUState *cpu = arg;
123
+ return true;
164
124
+}
165
@@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg)
125
+
166
if (cpu_can_run(cpu)) {
126
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
167
int r;
127
+{
168
qemu_mutex_unlock_iothread();
128
+ return tcg_out_fail_alignment(s, l);
169
- r = tcg_cpu_exec(cpu);
129
+}
170
+ r = tcg_cpus_exec(cpu);
130
+
171
qemu_mutex_lock_iothread();
131
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
172
switch (r) {
132
+{
173
case EXCP_DEBUG:
133
+ return tcg_out_fail_alignment(s, l);
174
@@ -XXX,XX +XXX,XX @@ static void *tcg_cpu_thread_fn(void *arg)
134
+}
175
qemu_wait_io_event(cpu);
135
#endif /* CONFIG_SOFTMMU */
176
} while (!cpu->unplug || cpu_can_run(cpu));
136
177
137
static void tcg_out_qemu_ld_direct(TCGContext *s, MemOp memop, TCGType ext,
178
- qemu_tcg_destroy_vcpu(cpu);
138
TCGReg data_r, TCGReg addr_r,
179
+ tcg_cpus_destroy(cpu);
139
TCGType otype, TCGReg off_r)
180
qemu_mutex_unlock_iothread();
140
{
181
rcu_unregister_thread();
141
- /* Byte swapping is left to middle-end expansion. */
182
return NULL;
142
- tcg_debug_assert((memop & MO_BSWAP) == 0);
183
@@ -XXX,XX +XXX,XX @@ static void mttcg_start_vcpu_thread(CPUState *cpu)
143
-
184
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "CPU %d/TCG",
144
switch (memop & MO_SSIZE) {
185
cpu->cpu_index);
145
case MO_UB:
186
146
tcg_out_ldst_r(s, I3312_LDRB, data_r, addr_r, otype, off_r);
187
- qemu_thread_create(cpu->thread, thread_name, tcg_cpu_thread_fn,
147
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, MemOp memop,
188
+ qemu_thread_create(cpu->thread, thread_name, mttcg_cpu_thread_fn,
148
TCGReg data_r, TCGReg addr_r,
189
cpu, QEMU_THREAD_JOINABLE);
149
TCGType otype, TCGReg off_r)
190
150
{
191
#ifdef _WIN32
151
- /* Byte swapping is left to middle-end expansion. */
192
@@ -XXX,XX +XXX,XX @@ const CpusAccel tcg_cpus_mttcg = {
152
- tcg_debug_assert((memop & MO_BSWAP) == 0);
193
.create_vcpu_thread = mttcg_start_vcpu_thread,
153
-
194
.kick_vcpu_thread = mttcg_kick_vcpu_thread,
154
switch (memop & MO_SIZE) {
195
155
case MO_8:
196
- .handle_interrupt = tcg_handle_interrupt,
156
tcg_out_ldst_r(s, I3312_STRB, data_r, addr_r, otype, off_r);
197
+ .handle_interrupt = tcg_cpus_handle_interrupt,
157
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
198
};
158
{
199
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
159
MemOp memop = get_memop(oi);
200
index XXXXXXX..XXXXXXX 100644
160
const TCGType otype = TARGET_LONG_BITS == 64 ? TCG_TYPE_I64 : TCG_TYPE_I32;
201
--- a/accel/tcg/tcg-cpus-rr.c
161
+
202
+++ b/accel/tcg/tcg-cpus-rr.c
162
+ /* Byte swapping is left to middle-end expansion. */
203
@@ -XXX,XX +XXX,XX @@
163
+ tcg_debug_assert((memop & MO_BSWAP) == 0);
204
#include "tcg-cpus-icount.h"
164
+
205
165
#ifdef CONFIG_SOFTMMU
206
/* Kick all RR vCPUs */
166
unsigned mem_index = get_mmuidx(oi);
207
-void qemu_cpu_kick_rr_cpus(CPUState *unused)
167
tcg_insn_unit *label_ptr;
208
+void rr_kick_vcpu_thread(CPUState *unused)
168
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
209
{
169
add_qemu_ldst_label(s, true, oi, ext, data_reg, addr_reg,
210
CPUState *cpu;
170
s->code_ptr, label_ptr);
211
171
#else /* !CONFIG_SOFTMMU */
212
@@ -XXX,XX +XXX,XX @@ void qemu_cpu_kick_rr_cpus(CPUState *unused)
172
+ unsigned a_bits = get_alignment_bits(memop);
213
* idleness is complete.
173
+ if (a_bits) {
214
*/
174
+ tcg_out_test_alignment(s, true, addr_reg, a_bits);
215
175
+ }
216
-static QEMUTimer *tcg_kick_vcpu_timer;
176
if (USE_GUEST_BASE) {
217
-static CPUState *tcg_current_rr_cpu;
177
tcg_out_qemu_ld_direct(s, memop, ext, data_reg,
218
+static QEMUTimer *rr_kick_vcpu_timer;
178
TCG_REG_GUEST_BASE, otype, addr_reg);
219
+static CPUState *rr_current_cpu;
179
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
220
180
{
221
#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
181
MemOp memop = get_memop(oi);
222
182
const TCGType otype = TARGET_LONG_BITS == 64 ? TCG_TYPE_I64 : TCG_TYPE_I32;
223
-static inline int64_t qemu_tcg_next_kick(void)
183
+
224
+static inline int64_t rr_next_kick_time(void)
184
+ /* Byte swapping is left to middle-end expansion. */
225
{
185
+ tcg_debug_assert((memop & MO_BSWAP) == 0);
226
return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
186
+
227
}
187
#ifdef CONFIG_SOFTMMU
228
188
unsigned mem_index = get_mmuidx(oi);
229
/* Kick the currently round-robin scheduled vCPU to next */
189
tcg_insn_unit *label_ptr;
230
-static void qemu_cpu_kick_rr_next_cpu(void)
190
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
231
+static void rr_kick_next_cpu(void)
191
add_qemu_ldst_label(s, false, oi, (memop & MO_SIZE)== MO_64,
232
{
192
data_reg, addr_reg, s->code_ptr, label_ptr);
233
CPUState *cpu;
193
#else /* !CONFIG_SOFTMMU */
234
do {
194
+ unsigned a_bits = get_alignment_bits(memop);
235
- cpu = qatomic_mb_read(&tcg_current_rr_cpu);
195
+ if (a_bits) {
236
+ cpu = qatomic_mb_read(&rr_current_cpu);
196
+ tcg_out_test_alignment(s, false, addr_reg, a_bits);
237
if (cpu) {
197
+ }
238
cpu_exit(cpu);
198
if (USE_GUEST_BASE) {
239
}
199
tcg_out_qemu_st_direct(s, memop, data_reg,
240
- } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
200
TCG_REG_GUEST_BASE, otype, addr_reg);
241
+ } while (cpu != qatomic_mb_read(&rr_current_cpu));
242
}
243
244
-static void kick_tcg_thread(void *opaque)
245
+static void rr_kick_thread(void *opaque)
246
{
247
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
248
- qemu_cpu_kick_rr_next_cpu();
249
+ timer_mod(rr_kick_vcpu_timer, rr_next_kick_time());
250
+ rr_kick_next_cpu();
251
}
252
253
-static void start_tcg_kick_timer(void)
254
+static void rr_start_kick_timer(void)
255
{
256
- if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
257
- tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
258
- kick_tcg_thread, NULL);
259
+ if (!rr_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
260
+ rr_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
261
+ rr_kick_thread, NULL);
262
}
263
- if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
264
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
265
+ if (rr_kick_vcpu_timer && !timer_pending(rr_kick_vcpu_timer)) {
266
+ timer_mod(rr_kick_vcpu_timer, rr_next_kick_time());
267
}
268
}
269
270
-static void stop_tcg_kick_timer(void)
271
+static void rr_stop_kick_timer(void)
272
{
273
- if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
274
- timer_del(tcg_kick_vcpu_timer);
275
+ if (rr_kick_vcpu_timer && timer_pending(rr_kick_vcpu_timer)) {
276
+ timer_del(rr_kick_vcpu_timer);
277
}
278
}
279
280
-static void qemu_tcg_rr_wait_io_event(void)
281
+static void rr_wait_io_event(void)
282
{
283
CPUState *cpu;
284
285
while (all_cpu_threads_idle()) {
286
- stop_tcg_kick_timer();
287
+ rr_stop_kick_timer();
288
qemu_cond_wait_iothread(first_cpu->halt_cond);
289
}
290
291
- start_tcg_kick_timer();
292
+ rr_start_kick_timer();
293
294
CPU_FOREACH(cpu) {
295
qemu_wait_io_event_common(cpu);
296
@@ -XXX,XX +XXX,XX @@ static void qemu_tcg_rr_wait_io_event(void)
297
* Destroy any remaining vCPUs which have been unplugged and have
298
* finished running
299
*/
300
-static void deal_with_unplugged_cpus(void)
301
+static void rr_deal_with_unplugged_cpus(void)
302
{
303
CPUState *cpu;
304
305
CPU_FOREACH(cpu) {
306
if (cpu->unplug && !cpu_can_run(cpu)) {
307
- qemu_tcg_destroy_vcpu(cpu);
308
+ tcg_cpus_destroy(cpu);
309
break;
310
}
311
}
312
@@ -XXX,XX +XXX,XX @@ static void deal_with_unplugged_cpus(void)
313
* elsewhere.
314
*/
315
316
-static void *tcg_rr_cpu_thread_fn(void *arg)
317
+static void *rr_cpu_thread_fn(void *arg)
318
{
319
CPUState *cpu = arg;
320
321
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
322
}
323
}
324
325
- start_tcg_kick_timer();
326
+ rr_start_kick_timer();
327
328
cpu = first_cpu;
329
330
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
331
* Run the timers here. This is much more efficient than
332
* waking up the I/O thread and waiting for completion.
333
*/
334
- handle_icount_deadline();
335
+ icount_handle_deadline();
336
}
337
338
replay_mutex_unlock();
339
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
340
341
while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
342
343
- qatomic_mb_set(&tcg_current_rr_cpu, cpu);
344
+ qatomic_mb_set(&rr_current_cpu, cpu);
345
current_cpu = cpu;
346
347
qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
348
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
349
350
qemu_mutex_unlock_iothread();
351
if (icount_enabled()) {
352
- prepare_icount_for_run(cpu);
353
+ icount_prepare_for_run(cpu);
354
}
355
- r = tcg_cpu_exec(cpu);
356
+ r = tcg_cpus_exec(cpu);
357
if (icount_enabled()) {
358
- process_icount_data(cpu);
359
+ icount_process_data(cpu);
360
}
361
qemu_mutex_lock_iothread();
362
363
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
364
} /* while (cpu && !cpu->exit_request).. */
365
366
/* Does not need qatomic_mb_set because a spurious wakeup is okay. */
367
- qatomic_set(&tcg_current_rr_cpu, NULL);
368
+ qatomic_set(&rr_current_cpu, NULL);
369
370
if (cpu && cpu->exit_request) {
371
qatomic_mb_set(&cpu->exit_request, 0);
372
@@ -XXX,XX +XXX,XX @@ static void *tcg_rr_cpu_thread_fn(void *arg)
373
qemu_notify_event();
374
}
375
376
- qemu_tcg_rr_wait_io_event();
377
- deal_with_unplugged_cpus();
378
+ rr_wait_io_event();
379
+ rr_deal_with_unplugged_cpus();
380
}
381
382
rcu_unregister_thread();
383
@@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu)
384
/* share a single thread for all cpus with TCG */
385
snprintf(thread_name, VCPU_THREAD_NAME_SIZE, "ALL CPUs/TCG");
386
qemu_thread_create(cpu->thread, thread_name,
387
- tcg_rr_cpu_thread_fn,
388
+ rr_cpu_thread_fn,
389
cpu, QEMU_THREAD_JOINABLE);
390
391
single_tcg_halt_cond = cpu->halt_cond;
392
@@ -XXX,XX +XXX,XX @@ void rr_start_vcpu_thread(CPUState *cpu)
393
394
const CpusAccel tcg_cpus_rr = {
395
.create_vcpu_thread = rr_start_vcpu_thread,
396
- .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
397
+ .kick_vcpu_thread = rr_kick_vcpu_thread,
398
399
- .handle_interrupt = tcg_handle_interrupt,
400
+ .handle_interrupt = tcg_cpus_handle_interrupt,
401
};
402
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
403
index XXXXXXX..XXXXXXX 100644
404
--- a/accel/tcg/tcg-cpus.c
405
+++ b/accel/tcg/tcg-cpus.c
406
@@ -XXX,XX +XXX,XX @@
407
408
/* common functionality among all TCG variants */
409
410
-void qemu_tcg_destroy_vcpu(CPUState *cpu)
411
+void tcg_cpus_destroy(CPUState *cpu)
412
{
413
cpu_thread_signal_destroyed(cpu);
414
}
415
416
-int tcg_cpu_exec(CPUState *cpu)
417
+int tcg_cpus_exec(CPUState *cpu)
418
{
419
int ret;
420
#ifdef CONFIG_PROFILER
421
@@ -XXX,XX +XXX,XX @@ int tcg_cpu_exec(CPUState *cpu)
422
}
423
424
/* mask must never be zero, except for A20 change call */
425
-void tcg_handle_interrupt(CPUState *cpu, int mask)
426
+void tcg_cpus_handle_interrupt(CPUState *cpu, int mask)
427
{
428
g_assert(qemu_mutex_iothread_locked());
429
430
--
201
--
431
2.25.1
202
2.25.1
432
203
433
204
diff view generated by jsdifflib
New patch
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/ppc/tcg-target.h | 2 -
5
tcg/ppc/tcg-target.c.inc | 98 ++++++++++++++++++++++++++++++++++++----
6
2 files changed, 90 insertions(+), 10 deletions(-)
1
7
8
diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h
9
index XXXXXXX..XXXXXXX 100644
10
--- a/tcg/ppc/tcg-target.h
11
+++ b/tcg/ppc/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
13
#define TCG_TARGET_DEFAULT_MO (0)
14
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
15
16
-#ifdef CONFIG_SOFTMMU
17
#define TCG_TARGET_NEED_LDST_LABELS
18
-#endif
19
#define TCG_TARGET_NEED_POOL_LABELS
20
21
#endif
22
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/ppc/tcg-target.c.inc
25
+++ b/tcg/ppc/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@
27
28
#include "elf.h"
29
#include "../tcg-pool.c.inc"
30
+#include "../tcg-ldst.c.inc"
31
32
/*
33
* Standardize on the _CALL_FOO symbols used by GCC:
34
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
35
}
36
}
37
38
-static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
39
+static void tcg_out_call_int(TCGContext *s, int lk,
40
+ const tcg_insn_unit *target)
41
{
42
#ifdef _CALL_AIX
43
/* Look through the descriptor. If the branch is in range, and we
44
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
45
46
if (in_range_b(diff) && toc == (uint32_t)toc) {
47
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP1, toc);
48
- tcg_out_b(s, LK, tgt);
49
+ tcg_out_b(s, lk, tgt);
50
} else {
51
/* Fold the low bits of the constant into the addresses below. */
52
intptr_t arg = (intptr_t)target;
53
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
54
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_TMP1, ofs);
55
tcg_out32(s, MTSPR | RA(TCG_REG_R0) | CTR);
56
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_REG_TMP1, ofs + SZP);
57
- tcg_out32(s, BCCTR | BO_ALWAYS | LK);
58
+ tcg_out32(s, BCCTR | BO_ALWAYS | lk);
59
}
60
#elif defined(_CALL_ELF) && _CALL_ELF == 2
61
intptr_t diff;
62
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
63
64
diff = tcg_pcrel_diff(s, target);
65
if (in_range_b(diff)) {
66
- tcg_out_b(s, LK, target);
67
+ tcg_out_b(s, lk, target);
68
} else {
69
tcg_out32(s, MTSPR | RS(TCG_REG_R12) | CTR);
70
- tcg_out32(s, BCCTR | BO_ALWAYS | LK);
71
+ tcg_out32(s, BCCTR | BO_ALWAYS | lk);
72
}
73
#else
74
- tcg_out_b(s, LK, target);
75
+ tcg_out_b(s, lk, target);
76
#endif
77
}
78
79
+static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
80
+{
81
+ tcg_out_call_int(s, LK, target);
82
+}
83
+
84
static const uint32_t qemu_ldx_opc[(MO_SSIZE + MO_BSWAP) + 1] = {
85
[MO_UB] = LBZX,
86
[MO_UW] = LHZX,
87
@@ -XXX,XX +XXX,XX @@ static const uint32_t qemu_exts_opc[4] = {
88
};
89
90
#if defined (CONFIG_SOFTMMU)
91
-#include "../tcg-ldst.c.inc"
92
-
93
/* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
94
* int mmu_idx, uintptr_t ra)
95
*/
96
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
97
tcg_out_b(s, 0, lb->raddr);
98
return true;
99
}
100
+#else
101
+
102
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
103
+ TCGReg addrhi, unsigned a_bits)
104
+{
105
+ unsigned a_mask = (1 << a_bits) - 1;
106
+ TCGLabelQemuLdst *label = new_ldst_label(s);
107
+
108
+ label->is_ld = is_ld;
109
+ label->addrlo_reg = addrlo;
110
+ label->addrhi_reg = addrhi;
111
+
112
+ /* We are expecting a_bits to max out at 7, much lower than ANDI. */
113
+ tcg_debug_assert(a_bits < 16);
114
+ tcg_out32(s, ANDI | SAI(addrlo, TCG_REG_R0, a_mask));
115
+
116
+ label->label_ptr[0] = s->code_ptr;
117
+ tcg_out32(s, BC | BI(0, CR_EQ) | BO_COND_FALSE | LK);
118
+
119
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr);
120
+}
121
+
122
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
123
+{
124
+ if (!reloc_pc14(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
125
+ return false;
126
+ }
127
+
128
+ if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
129
+ TCGReg arg = TCG_REG_R4;
130
+#ifdef TCG_TARGET_CALL_ALIGN_ARGS
131
+ arg |= 1;
132
+#endif
133
+ if (l->addrlo_reg != arg) {
134
+ tcg_out_mov(s, TCG_TYPE_I32, arg, l->addrhi_reg);
135
+ tcg_out_mov(s, TCG_TYPE_I32, arg + 1, l->addrlo_reg);
136
+ } else if (l->addrhi_reg != arg + 1) {
137
+ tcg_out_mov(s, TCG_TYPE_I32, arg + 1, l->addrlo_reg);
138
+ tcg_out_mov(s, TCG_TYPE_I32, arg, l->addrhi_reg);
139
+ } else {
140
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R0, arg);
141
+ tcg_out_mov(s, TCG_TYPE_I32, arg, arg + 1);
142
+ tcg_out_mov(s, TCG_TYPE_I32, arg + 1, TCG_REG_R0);
143
+ }
144
+ } else {
145
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_R4, l->addrlo_reg);
146
+ }
147
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_R3, TCG_AREG0);
148
+
149
+ /* "Tail call" to the helper, with the return address back inline. */
150
+ tcg_out_call_int(s, 0, (const void *)(l->is_ld ? helper_unaligned_ld
151
+ : helper_unaligned_st));
152
+ return true;
153
+}
154
+
155
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
156
+{
157
+ return tcg_out_fail_alignment(s, l);
158
+}
159
+
160
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
161
+{
162
+ return tcg_out_fail_alignment(s, l);
163
+}
164
+
165
#endif /* SOFTMMU */
166
167
static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
168
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
169
#ifdef CONFIG_SOFTMMU
170
int mem_index;
171
tcg_insn_unit *label_ptr;
172
+#else
173
+ unsigned a_bits;
174
#endif
175
176
datalo = *args++;
177
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
178
179
rbase = TCG_REG_R3;
180
#else /* !CONFIG_SOFTMMU */
181
+ a_bits = get_alignment_bits(opc);
182
+ if (a_bits) {
183
+ tcg_out_test_alignment(s, true, addrlo, addrhi, a_bits);
184
+ }
185
rbase = guest_base ? TCG_GUEST_BASE_REG : 0;
186
if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
187
tcg_out_ext32u(s, TCG_REG_TMP1, addrlo);
188
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
189
#ifdef CONFIG_SOFTMMU
190
int mem_index;
191
tcg_insn_unit *label_ptr;
192
+#else
193
+ unsigned a_bits;
194
#endif
195
196
datalo = *args++;
197
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
198
199
rbase = TCG_REG_R3;
200
#else /* !CONFIG_SOFTMMU */
201
+ a_bits = get_alignment_bits(opc);
202
+ if (a_bits) {
203
+ tcg_out_test_alignment(s, false, addrlo, addrhi, a_bits);
204
+ }
205
rbase = guest_base ? TCG_GUEST_BASE_REG : 0;
206
if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
207
tcg_out_ext32u(s, TCG_REG_TMP1, addrlo);
208
--
209
2.25.1
210
211
diff view generated by jsdifflib
New patch
1
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
---
3
tcg/riscv/tcg-target.h | 2 --
4
tcg/riscv/tcg-target.c.inc | 63 ++++++++++++++++++++++++++++++++++++--
5
2 files changed, 61 insertions(+), 4 deletions(-)
1
6
7
diff --git a/tcg/riscv/tcg-target.h b/tcg/riscv/tcg-target.h
8
index XXXXXXX..XXXXXXX 100644
9
--- a/tcg/riscv/tcg-target.h
10
+++ b/tcg/riscv/tcg-target.h
11
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
12
13
#define TCG_TARGET_DEFAULT_MO (0)
14
15
-#ifdef CONFIG_SOFTMMU
16
#define TCG_TARGET_NEED_LDST_LABELS
17
-#endif
18
#define TCG_TARGET_NEED_POOL_LABELS
19
20
#define TCG_TARGET_HAS_MEMORY_BSWAP 0
21
diff --git a/tcg/riscv/tcg-target.c.inc b/tcg/riscv/tcg-target.c.inc
22
index XXXXXXX..XXXXXXX 100644
23
--- a/tcg/riscv/tcg-target.c.inc
24
+++ b/tcg/riscv/tcg-target.c.inc
25
@@ -XXX,XX +XXX,XX @@
26
* THE SOFTWARE.
27
*/
28
29
+#include "../tcg-ldst.c.inc"
30
#include "../tcg-pool.c.inc"
31
32
#ifdef CONFIG_DEBUG_TCG
33
@@ -XXX,XX +XXX,XX @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
34
*/
35
36
#if defined(CONFIG_SOFTMMU)
37
-#include "../tcg-ldst.c.inc"
38
-
39
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
40
* MemOpIdx oi, uintptr_t ra)
41
*/
42
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
43
tcg_out_goto(s, l->raddr);
44
return true;
45
}
46
+#else
47
+
48
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addr_reg,
49
+ unsigned a_bits)
50
+{
51
+ unsigned a_mask = (1 << a_bits) - 1;
52
+ TCGLabelQemuLdst *l = new_ldst_label(s);
53
+
54
+ l->is_ld = is_ld;
55
+ l->addrlo_reg = addr_reg;
56
+
57
+ /* We are expecting a_bits to max out at 7, so we can always use andi. */
58
+ tcg_debug_assert(a_bits < 12);
59
+ tcg_out_opc_imm(s, OPC_ANDI, TCG_REG_TMP1, addr_reg, a_mask);
60
+
61
+ l->label_ptr[0] = s->code_ptr;
62
+ tcg_out_opc_branch(s, OPC_BNE, TCG_REG_TMP1, TCG_REG_ZERO, 0);
63
+
64
+ l->raddr = tcg_splitwx_to_rx(s->code_ptr);
65
+}
66
+
67
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
68
+{
69
+ /* resolve label address */
70
+ if (!reloc_sbimm12(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
71
+ return false;
72
+ }
73
+
74
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_A1, l->addrlo_reg);
75
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_A0, TCG_AREG0);
76
+
77
+ /* tail call, with the return address back inline. */
78
+ tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RA, (uintptr_t)l->raddr);
79
+ tcg_out_call_int(s, (const void *)(l->is_ld ? helper_unaligned_ld
80
+ : helper_unaligned_st), true);
81
+ return true;
82
+}
83
+
84
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
85
+{
86
+ return tcg_out_fail_alignment(s, l);
87
+}
88
+
89
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
90
+{
91
+ return tcg_out_fail_alignment(s, l);
92
+}
93
+
94
#endif /* CONFIG_SOFTMMU */
95
96
static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg lo, TCGReg hi,
97
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
98
MemOp opc;
99
#if defined(CONFIG_SOFTMMU)
100
tcg_insn_unit *label_ptr[1];
101
+#else
102
+ unsigned a_bits;
103
#endif
104
TCGReg base = TCG_REG_TMP0;
105
106
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
107
tcg_out_ext32u(s, base, addr_regl);
108
addr_regl = base;
109
}
110
+ a_bits = get_alignment_bits(opc);
111
+ if (a_bits) {
112
+ tcg_out_test_alignment(s, true, addr_regl, a_bits);
113
+ }
114
if (guest_base != 0) {
115
tcg_out_opc_reg(s, OPC_ADD, base, TCG_GUEST_BASE_REG, addr_regl);
116
}
117
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
118
MemOp opc;
119
#if defined(CONFIG_SOFTMMU)
120
tcg_insn_unit *label_ptr[1];
121
+#else
122
+ unsigned a_bits;
123
#endif
124
TCGReg base = TCG_REG_TMP0;
125
126
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
127
tcg_out_ext32u(s, base, addr_regl);
128
addr_regl = base;
129
}
130
+ a_bits = get_alignment_bits(opc);
131
+ if (a_bits) {
132
+ tcg_out_test_alignment(s, false, addr_regl, a_bits);
133
+ }
134
if (guest_base != 0) {
135
tcg_out_opc_reg(s, OPC_ADD, base, TCG_GUEST_BASE_REG, addr_regl);
136
}
137
--
138
2.25.1
139
140
diff view generated by jsdifflib
New patch
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/s390x/tcg-target.h | 2 --
5
tcg/s390x/tcg-target.c.inc | 59 ++++++++++++++++++++++++++++++++++++--
6
2 files changed, 57 insertions(+), 4 deletions(-)
1
7
8
diff --git a/tcg/s390x/tcg-target.h b/tcg/s390x/tcg-target.h
9
index XXXXXXX..XXXXXXX 100644
10
--- a/tcg/s390x/tcg-target.h
11
+++ b/tcg/s390x/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
13
/* no need to flush icache explicitly */
14
}
15
16
-#ifdef CONFIG_SOFTMMU
17
#define TCG_TARGET_NEED_LDST_LABELS
18
-#endif
19
#define TCG_TARGET_NEED_POOL_LABELS
20
21
#endif
22
diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/s390x/tcg-target.c.inc
25
+++ b/tcg/s390x/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@
27
#error "unsupported code generation mode"
28
#endif
29
30
+#include "../tcg-ldst.c.inc"
31
#include "../tcg-pool.c.inc"
32
#include "elf.h"
33
34
@@ -XXX,XX +XXX,XX @@ typedef enum S390Opcode {
35
RI_OIHL = 0xa509,
36
RI_OILH = 0xa50a,
37
RI_OILL = 0xa50b,
38
+ RI_TMLL = 0xa701,
39
40
RIE_CGIJ = 0xec7c,
41
RIE_CGRJ = 0xec64,
42
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, MemOp opc, TCGReg data,
43
}
44
45
#if defined(CONFIG_SOFTMMU)
46
-#include "../tcg-ldst.c.inc"
47
-
48
/* We're expecting to use a 20-bit negative offset on the tlb memory ops. */
49
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0);
50
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 19));
51
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
52
return true;
53
}
54
#else
55
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld,
56
+ TCGReg addrlo, unsigned a_bits)
57
+{
58
+ unsigned a_mask = (1 << a_bits) - 1;
59
+ TCGLabelQemuLdst *l = new_ldst_label(s);
60
+
61
+ l->is_ld = is_ld;
62
+ l->addrlo_reg = addrlo;
63
+
64
+ /* We are expecting a_bits to max out at 7, much lower than TMLL. */
65
+ tcg_debug_assert(a_bits < 16);
66
+ tcg_out_insn(s, RI, TMLL, addrlo, a_mask);
67
+
68
+ tcg_out16(s, RI_BRC | (7 << 4)); /* CC in {1,2,3} */
69
+ l->label_ptr[0] = s->code_ptr;
70
+ s->code_ptr += 1;
71
+
72
+ l->raddr = tcg_splitwx_to_rx(s->code_ptr);
73
+}
74
+
75
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
76
+{
77
+ if (!patch_reloc(l->label_ptr[0], R_390_PC16DBL,
78
+ (intptr_t)tcg_splitwx_to_rx(s->code_ptr), 2)) {
79
+ return false;
80
+ }
81
+
82
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_R3, l->addrlo_reg);
83
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_AREG0);
84
+
85
+ /* "Tail call" to the helper, with the return address back inline. */
86
+ tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_R14, (uintptr_t)l->raddr);
87
+ tgen_gotoi(s, S390_CC_ALWAYS, (const void *)(l->is_ld ? helper_unaligned_ld
88
+ : helper_unaligned_st));
89
+ return true;
90
+}
91
+
92
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
93
+{
94
+ return tcg_out_fail_alignment(s, l);
95
+}
96
+
97
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
98
+{
99
+ return tcg_out_fail_alignment(s, l);
100
+}
101
+
102
static void tcg_prepare_user_ldst(TCGContext *s, TCGReg *addr_reg,
103
TCGReg *index_reg, tcg_target_long *disp)
104
{
105
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext* s, TCGReg data_reg, TCGReg addr_reg,
106
#else
107
TCGReg index_reg;
108
tcg_target_long disp;
109
+ unsigned a_bits = get_alignment_bits(opc);
110
111
+ if (a_bits) {
112
+ tcg_out_test_alignment(s, true, addr_reg, a_bits);
113
+ }
114
tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp);
115
tcg_out_qemu_ld_direct(s, opc, data_reg, addr_reg, index_reg, disp);
116
#endif
117
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext* s, TCGReg data_reg, TCGReg addr_reg,
118
#else
119
TCGReg index_reg;
120
tcg_target_long disp;
121
+ unsigned a_bits = get_alignment_bits(opc);
122
123
+ if (a_bits) {
124
+ tcg_out_test_alignment(s, false, addr_reg, a_bits);
125
+ }
126
tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp);
127
tcg_out_qemu_st_direct(s, opc, data_reg, addr_reg, index_reg, disp);
128
#endif
129
--
130
2.25.1
131
132
diff view generated by jsdifflib
New patch
1
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/tci.c | 20 ++++++++++++++------
5
1 file changed, 14 insertions(+), 6 deletions(-)
1
6
7
diff --git a/tcg/tci.c b/tcg/tci.c
8
index XXXXXXX..XXXXXXX 100644
9
--- a/tcg/tci.c
10
+++ b/tcg/tci.c
11
@@ -XXX,XX +XXX,XX @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
12
static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
13
MemOpIdx oi, const void *tb_ptr)
14
{
15
- MemOp mop = get_memop(oi) & (MO_BSWAP | MO_SSIZE);
16
+ MemOp mop = get_memop(oi);
17
uintptr_t ra = (uintptr_t)tb_ptr;
18
19
#ifdef CONFIG_SOFTMMU
20
- switch (mop) {
21
+ switch (mop & (MO_BSWAP | MO_SSIZE)) {
22
case MO_UB:
23
return helper_ret_ldub_mmu(env, taddr, oi, ra);
24
case MO_SB:
25
@@ -XXX,XX +XXX,XX @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
26
}
27
#else
28
void *haddr = g2h(env_cpu(env), taddr);
29
+ unsigned a_mask = (1u << get_alignment_bits(mop)) - 1;
30
uint64_t ret;
31
32
set_helper_retaddr(ra);
33
- switch (mop) {
34
+ if (taddr & a_mask) {
35
+ helper_unaligned_ld(env, taddr);
36
+ }
37
+ switch (mop & (MO_BSWAP | MO_SSIZE)) {
38
case MO_UB:
39
ret = ldub_p(haddr);
40
break;
41
@@ -XXX,XX +XXX,XX @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
42
static void tci_qemu_st(CPUArchState *env, target_ulong taddr, uint64_t val,
43
MemOpIdx oi, const void *tb_ptr)
44
{
45
- MemOp mop = get_memop(oi) & (MO_BSWAP | MO_SSIZE);
46
+ MemOp mop = get_memop(oi);
47
uintptr_t ra = (uintptr_t)tb_ptr;
48
49
#ifdef CONFIG_SOFTMMU
50
- switch (mop) {
51
+ switch (mop & (MO_BSWAP | MO_SIZE)) {
52
case MO_UB:
53
helper_ret_stb_mmu(env, taddr, val, oi, ra);
54
break;
55
@@ -XXX,XX +XXX,XX @@ static void tci_qemu_st(CPUArchState *env, target_ulong taddr, uint64_t val,
56
}
57
#else
58
void *haddr = g2h(env_cpu(env), taddr);
59
+ unsigned a_mask = (1u << get_alignment_bits(mop)) - 1;
60
61
set_helper_retaddr(ra);
62
- switch (mop) {
63
+ if (taddr & a_mask) {
64
+ helper_unaligned_st(env, taddr);
65
+ }
66
+ switch (mop & (MO_BSWAP | MO_SIZE)) {
67
case MO_UB:
68
stb_p(haddr, val);
69
break;
70
--
71
2.25.1
72
73
diff view generated by jsdifflib
New patch
1
From: WANG Xuerui <git@xen0n.name>
1
2
3
Signed-off-by: WANG Xuerui <git@xen0n.name>
4
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
5
Message-Id: <20220106134238.3936163-1-git@xen0n.name>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
tcg/loongarch64/tcg-target.h | 2 -
9
tcg/loongarch64/tcg-target.c.inc | 71 +++++++++++++++++++++++++++++++-
10
2 files changed, 69 insertions(+), 4 deletions(-)
11
12
diff --git a/tcg/loongarch64/tcg-target.h b/tcg/loongarch64/tcg-target.h
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tcg/loongarch64/tcg-target.h
15
+++ b/tcg/loongarch64/tcg-target.h
16
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
17
18
#define TCG_TARGET_DEFAULT_MO (0)
19
20
-#ifdef CONFIG_SOFTMMU
21
#define TCG_TARGET_NEED_LDST_LABELS
22
-#endif
23
24
#define TCG_TARGET_HAS_MEMORY_BSWAP 0
25
26
diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
27
index XXXXXXX..XXXXXXX 100644
28
--- a/tcg/loongarch64/tcg-target.c.inc
29
+++ b/tcg/loongarch64/tcg-target.c.inc
30
@@ -XXX,XX +XXX,XX @@
31
* THE SOFTWARE.
32
*/
33
34
+#include "../tcg-ldst.c.inc"
35
+
36
#ifdef CONFIG_DEBUG_TCG
37
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
38
"zero",
39
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_sti(TCGContext *s, TCGType type, TCGArg val,
40
*/
41
42
#if defined(CONFIG_SOFTMMU)
43
-#include "../tcg-ldst.c.inc"
44
-
45
/*
46
* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
47
* MemOpIdx oi, uintptr_t ra)
48
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
49
50
return tcg_out_goto(s, l->raddr);
51
}
52
+#else
53
+
54
+/*
55
+ * Alignment helpers for user-mode emulation
56
+ */
57
+
58
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addr_reg,
59
+ unsigned a_bits)
60
+{
61
+ TCGLabelQemuLdst *l = new_ldst_label(s);
62
+
63
+ l->is_ld = is_ld;
64
+ l->addrlo_reg = addr_reg;
65
+
66
+ /*
67
+ * Without micro-architecture details, we don't know which of bstrpick or
68
+ * andi is faster, so use bstrpick as it's not constrained by imm field
69
+ * width. (Not to say alignments >= 2^12 are going to happen any time
70
+ * soon, though)
71
+ */
72
+ tcg_out_opc_bstrpick_d(s, TCG_REG_TMP1, addr_reg, 0, a_bits - 1);
73
+
74
+ l->label_ptr[0] = s->code_ptr;
75
+ tcg_out_opc_bne(s, TCG_REG_TMP1, TCG_REG_ZERO, 0);
76
+
77
+ l->raddr = tcg_splitwx_to_rx(s->code_ptr);
78
+}
79
+
80
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
81
+{
82
+ /* resolve label address */
83
+ if (!reloc_br_sk16(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
84
+ return false;
85
+ }
86
+
87
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_A1, l->addrlo_reg);
88
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_A0, TCG_AREG0);
89
+
90
+ /* tail call, with the return address back inline. */
91
+ tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_RA, (uintptr_t)l->raddr);
92
+ tcg_out_call_int(s, (const void *)(l->is_ld ? helper_unaligned_ld
93
+ : helper_unaligned_st), true);
94
+ return true;
95
+}
96
+
97
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
98
+{
99
+ return tcg_out_fail_alignment(s, l);
100
+}
101
+
102
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
103
+{
104
+ return tcg_out_fail_alignment(s, l);
105
+}
106
+
107
#endif /* CONFIG_SOFTMMU */
108
109
/*
110
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, TCGType type)
111
MemOp opc;
112
#if defined(CONFIG_SOFTMMU)
113
tcg_insn_unit *label_ptr[1];
114
+#else
115
+ unsigned a_bits;
116
#endif
117
TCGReg base;
118
119
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, TCGType type)
120
data_regl, addr_regl,
121
s->code_ptr, label_ptr);
122
#else
123
+ a_bits = get_alignment_bits(opc);
124
+ if (a_bits) {
125
+ tcg_out_test_alignment(s, true, addr_regl, a_bits);
126
+ }
127
base = tcg_out_zext_addr_if_32_bit(s, addr_regl, TCG_REG_TMP0);
128
TCGReg guest_base_reg = USE_GUEST_BASE ? TCG_GUEST_BASE_REG : TCG_REG_ZERO;
129
tcg_out_qemu_ld_indexed(s, data_regl, base, guest_base_reg, opc, type);
130
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args)
131
MemOp opc;
132
#if defined(CONFIG_SOFTMMU)
133
tcg_insn_unit *label_ptr[1];
134
+#else
135
+ unsigned a_bits;
136
#endif
137
TCGReg base;
138
139
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args)
140
data_regl, addr_regl,
141
s->code_ptr, label_ptr);
142
#else
143
+ a_bits = get_alignment_bits(opc);
144
+ if (a_bits) {
145
+ tcg_out_test_alignment(s, false, addr_regl, a_bits);
146
+ }
147
base = tcg_out_zext_addr_if_32_bit(s, addr_regl, TCG_REG_TMP0);
148
TCGReg guest_base_reg = USE_GUEST_BASE ? TCG_GUEST_BASE_REG : TCG_REG_ZERO;
149
tcg_out_qemu_st_indexed(s, data_regl, base, guest_base_reg, opc);
150
--
151
2.25.1
152
153
diff view generated by jsdifflib
New patch
1
Support for unaligned accesses is difficult for pre-v6 hosts.
2
While debian still builds for armv4, we cannot use a compile
3
time test, so test the architecture at runtime and error out.
1
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
tcg/arm/tcg-target.c.inc | 5 +++++
9
1 file changed, 5 insertions(+)
10
11
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
12
index XXXXXXX..XXXXXXX 100644
13
--- a/tcg/arm/tcg-target.c.inc
14
+++ b/tcg/arm/tcg-target.c.inc
15
@@ -XXX,XX +XXX,XX @@ static void tcg_target_init(TCGContext *s)
16
if (pl != NULL && pl[0] == 'v' && pl[1] >= '4' && pl[1] <= '9') {
17
arm_arch = pl[1] - '0';
18
}
19
+
20
+ if (arm_arch < 6) {
21
+ error_report("TCG: ARMv%d is unsupported; exiting", arm_arch);
22
+ exit(EXIT_FAILURE);
23
+ }
24
}
25
26
tcg_target_available_regs[TCG_TYPE_I32] = ALL_GENERAL_REGS;
27
--
28
2.25.1
29
30
diff view generated by jsdifflib
New patch
1
This is now always true, since we require armv6.
1
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
tcg/arm/tcg-target.h | 3 +--
7
tcg/arm/tcg-target.c.inc | 35 ++++++-----------------------------
8
2 files changed, 7 insertions(+), 31 deletions(-)
9
10
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
11
index XXXXXXX..XXXXXXX 100644
12
--- a/tcg/arm/tcg-target.h
13
+++ b/tcg/arm/tcg-target.h
14
@@ -XXX,XX +XXX,XX @@
15
16
extern int arm_arch;
17
18
-#define use_armv5t_instructions (__ARM_ARCH >= 5 || arm_arch >= 5)
19
#define use_armv6_instructions (__ARM_ARCH >= 6 || arm_arch >= 6)
20
#define use_armv7_instructions (__ARM_ARCH >= 7 || arm_arch >= 7)
21
22
@@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions;
23
#define TCG_TARGET_HAS_eqv_i32 0
24
#define TCG_TARGET_HAS_nand_i32 0
25
#define TCG_TARGET_HAS_nor_i32 0
26
-#define TCG_TARGET_HAS_clz_i32 use_armv5t_instructions
27
+#define TCG_TARGET_HAS_clz_i32 1
28
#define TCG_TARGET_HAS_ctz_i32 use_armv7_instructions
29
#define TCG_TARGET_HAS_ctpop_i32 0
30
#define TCG_TARGET_HAS_deposit_i32 use_armv7_instructions
31
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
32
index XXXXXXX..XXXXXXX 100644
33
--- a/tcg/arm/tcg-target.c.inc
34
+++ b/tcg/arm/tcg-target.c.inc
35
@@ -XXX,XX +XXX,XX @@ static void tcg_out_b_reg(TCGContext *s, ARMCond cond, TCGReg rn)
36
* Unless the C portion of QEMU is compiled as thumb, we don't need
37
* true BX semantics; merely a branch to an address held in a register.
38
*/
39
- if (use_armv5t_instructions) {
40
- tcg_out_bx_reg(s, cond, rn);
41
- } else {
42
- tcg_out_mov_reg(s, cond, TCG_REG_PC, rn);
43
- }
44
+ tcg_out_bx_reg(s, cond, rn);
45
}
46
47
static void tcg_out_dat_imm(TCGContext *s, ARMCond cond, ARMInsn opc,
48
@@ -XXX,XX +XXX,XX @@ static void tcg_out_goto(TCGContext *s, ARMCond cond, const tcg_insn_unit *addr)
49
}
50
51
/* LDR is interworking from v5t. */
52
- if (arm_mode || use_armv5t_instructions) {
53
- tcg_out_movi_pool(s, cond, TCG_REG_PC, addri);
54
- return;
55
- }
56
-
57
- /* else v4t */
58
- tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri);
59
- tcg_out_bx_reg(s, COND_AL, TCG_REG_TMP);
60
+ tcg_out_movi_pool(s, cond, TCG_REG_PC, addri);
61
}
62
63
/*
64
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr)
65
if (disp - 8 < 0x02000000 && disp - 8 >= -0x02000000) {
66
if (arm_mode) {
67
tcg_out_bl_imm(s, COND_AL, disp);
68
- return;
69
- }
70
- if (use_armv5t_instructions) {
71
+ } else {
72
tcg_out_blx_imm(s, disp);
73
- return;
74
}
75
+ return;
76
}
77
78
- if (use_armv5t_instructions) {
79
- tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri);
80
- tcg_out_blx_reg(s, COND_AL, TCG_REG_TMP);
81
- } else if (arm_mode) {
82
- /* ??? Know that movi_pool emits exactly 1 insn. */
83
- tcg_out_mov_reg(s, COND_AL, TCG_REG_R14, TCG_REG_PC);
84
- tcg_out_movi_pool(s, COND_AL, TCG_REG_PC, addri);
85
- } else {
86
- tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri);
87
- tcg_out_mov_reg(s, COND_AL, TCG_REG_R14, TCG_REG_PC);
88
- tcg_out_bx_reg(s, COND_AL, TCG_REG_TMP);
89
- }
90
+ tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri);
91
+ tcg_out_blx_reg(s, COND_AL, TCG_REG_TMP);
92
}
93
94
static void tcg_out_goto_label(TCGContext *s, ARMCond cond, TCGLabel *l)
95
--
96
2.25.1
97
98
diff view generated by jsdifflib
New patch
1
This is now always true, since we require armv6.
1
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
tcg/arm/tcg-target.h | 1 -
7
tcg/arm/tcg-target.c.inc | 192 ++++++---------------------------------
8
2 files changed, 27 insertions(+), 166 deletions(-)
9
10
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
11
index XXXXXXX..XXXXXXX 100644
12
--- a/tcg/arm/tcg-target.h
13
+++ b/tcg/arm/tcg-target.h
14
@@ -XXX,XX +XXX,XX @@
15
16
extern int arm_arch;
17
18
-#define use_armv6_instructions (__ARM_ARCH >= 6 || arm_arch >= 6)
19
#define use_armv7_instructions (__ARM_ARCH >= 7 || arm_arch >= 7)
20
21
#undef TCG_TARGET_STACK_GROWSUP
22
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/arm/tcg-target.c.inc
25
+++ b/tcg/arm/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@ static void tcg_out_dat_rIN(TCGContext *s, ARMCond cond, ARMInsn opc,
27
static void tcg_out_mul32(TCGContext *s, ARMCond cond, TCGReg rd,
28
TCGReg rn, TCGReg rm)
29
{
30
- /* if ArchVersion() < 6 && d == n then UNPREDICTABLE; */
31
- if (!use_armv6_instructions && rd == rn) {
32
- if (rd == rm) {
33
- /* rd == rn == rm; copy an input to tmp first. */
34
- tcg_out_mov_reg(s, cond, TCG_REG_TMP, rn);
35
- rm = rn = TCG_REG_TMP;
36
- } else {
37
- rn = rm;
38
- rm = rd;
39
- }
40
- }
41
/* mul */
42
tcg_out32(s, (cond << 28) | 0x90 | (rd << 16) | (rm << 8) | rn);
43
}
44
@@ -XXX,XX +XXX,XX @@ static void tcg_out_mul32(TCGContext *s, ARMCond cond, TCGReg rd,
45
static void tcg_out_umull32(TCGContext *s, ARMCond cond, TCGReg rd0,
46
TCGReg rd1, TCGReg rn, TCGReg rm)
47
{
48
- /* if ArchVersion() < 6 && (dHi == n || dLo == n) then UNPREDICTABLE; */
49
- if (!use_armv6_instructions && (rd0 == rn || rd1 == rn)) {
50
- if (rd0 == rm || rd1 == rm) {
51
- tcg_out_mov_reg(s, cond, TCG_REG_TMP, rn);
52
- rn = TCG_REG_TMP;
53
- } else {
54
- TCGReg t = rn;
55
- rn = rm;
56
- rm = t;
57
- }
58
- }
59
/* umull */
60
tcg_out32(s, (cond << 28) | 0x00800090 |
61
(rd1 << 16) | (rd0 << 12) | (rm << 8) | rn);
62
@@ -XXX,XX +XXX,XX @@ static void tcg_out_umull32(TCGContext *s, ARMCond cond, TCGReg rd0,
63
static void tcg_out_smull32(TCGContext *s, ARMCond cond, TCGReg rd0,
64
TCGReg rd1, TCGReg rn, TCGReg rm)
65
{
66
- /* if ArchVersion() < 6 && (dHi == n || dLo == n) then UNPREDICTABLE; */
67
- if (!use_armv6_instructions && (rd0 == rn || rd1 == rn)) {
68
- if (rd0 == rm || rd1 == rm) {
69
- tcg_out_mov_reg(s, cond, TCG_REG_TMP, rn);
70
- rn = TCG_REG_TMP;
71
- } else {
72
- TCGReg t = rn;
73
- rn = rm;
74
- rm = t;
75
- }
76
- }
77
/* smull */
78
tcg_out32(s, (cond << 28) | 0x00c00090 |
79
(rd1 << 16) | (rd0 << 12) | (rm << 8) | rn);
80
@@ -XXX,XX +XXX,XX @@ static void tcg_out_udiv(TCGContext *s, ARMCond cond,
81
82
static void tcg_out_ext8s(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn)
83
{
84
- if (use_armv6_instructions) {
85
- /* sxtb */
86
- tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | rn);
87
- } else {
88
- tcg_out_dat_reg(s, cond, ARITH_MOV,
89
- rd, 0, rn, SHIFT_IMM_LSL(24));
90
- tcg_out_dat_reg(s, cond, ARITH_MOV,
91
- rd, 0, rd, SHIFT_IMM_ASR(24));
92
- }
93
+ /* sxtb */
94
+ tcg_out32(s, 0x06af0070 | (cond << 28) | (rd << 12) | rn);
95
}
96
97
static void __attribute__((unused))
98
@@ -XXX,XX +XXX,XX @@ tcg_out_ext8u(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn)
99
100
static void tcg_out_ext16s(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn)
101
{
102
- if (use_armv6_instructions) {
103
- /* sxth */
104
- tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | rn);
105
- } else {
106
- tcg_out_dat_reg(s, cond, ARITH_MOV,
107
- rd, 0, rn, SHIFT_IMM_LSL(16));
108
- tcg_out_dat_reg(s, cond, ARITH_MOV,
109
- rd, 0, rd, SHIFT_IMM_ASR(16));
110
- }
111
+ /* sxth */
112
+ tcg_out32(s, 0x06bf0070 | (cond << 28) | (rd << 12) | rn);
113
}
114
115
static void tcg_out_ext16u(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn)
116
{
117
- if (use_armv6_instructions) {
118
- /* uxth */
119
- tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | rn);
120
- } else {
121
- tcg_out_dat_reg(s, cond, ARITH_MOV,
122
- rd, 0, rn, SHIFT_IMM_LSL(16));
123
- tcg_out_dat_reg(s, cond, ARITH_MOV,
124
- rd, 0, rd, SHIFT_IMM_LSR(16));
125
- }
126
+ /* uxth */
127
+ tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | rn);
128
}
129
130
static void tcg_out_bswap16(TCGContext *s, ARMCond cond,
131
TCGReg rd, TCGReg rn, int flags)
132
{
133
- if (use_armv6_instructions) {
134
- if (flags & TCG_BSWAP_OS) {
135
- /* revsh */
136
- tcg_out32(s, 0x06ff0fb0 | (cond << 28) | (rd << 12) | rn);
137
- return;
138
- }
139
-
140
- /* rev16 */
141
- tcg_out32(s, 0x06bf0fb0 | (cond << 28) | (rd << 12) | rn);
142
- if ((flags & (TCG_BSWAP_IZ | TCG_BSWAP_OZ)) == TCG_BSWAP_OZ) {
143
- /* uxth */
144
- tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | rd);
145
- }
146
+ if (flags & TCG_BSWAP_OS) {
147
+ /* revsh */
148
+ tcg_out32(s, 0x06ff0fb0 | (cond << 28) | (rd << 12) | rn);
149
return;
150
}
151
152
- if (flags == 0) {
153
- /*
154
- * For stores, no input or output extension:
155
- * rn = xxAB
156
- * lsr tmp, rn, #8 tmp = 0xxA
157
- * and tmp, tmp, #0xff tmp = 000A
158
- * orr rd, tmp, rn, lsl #8 rd = xABA
159
- */
160
- tcg_out_dat_reg(s, cond, ARITH_MOV,
161
- TCG_REG_TMP, 0, rn, SHIFT_IMM_LSR(8));
162
- tcg_out_dat_imm(s, cond, ARITH_AND, TCG_REG_TMP, TCG_REG_TMP, 0xff);
163
- tcg_out_dat_reg(s, cond, ARITH_ORR,
164
- rd, TCG_REG_TMP, rn, SHIFT_IMM_LSL(8));
165
- return;
166
+ /* rev16 */
167
+ tcg_out32(s, 0x06bf0fb0 | (cond << 28) | (rd << 12) | rn);
168
+ if ((flags & (TCG_BSWAP_IZ | TCG_BSWAP_OZ)) == TCG_BSWAP_OZ) {
169
+ /* uxth */
170
+ tcg_out32(s, 0x06ff0070 | (cond << 28) | (rd << 12) | rd);
171
}
172
-
173
- /*
174
- * Byte swap, leaving the result at the top of the register.
175
- * We will then shift down, zero or sign-extending.
176
- */
177
- if (flags & TCG_BSWAP_IZ) {
178
- /*
179
- * rn = 00AB
180
- * ror tmp, rn, #8 tmp = B00A
181
- * orr tmp, tmp, tmp, lsl #16 tmp = BA00
182
- */
183
- tcg_out_dat_reg(s, cond, ARITH_MOV,
184
- TCG_REG_TMP, 0, rn, SHIFT_IMM_ROR(8));
185
- tcg_out_dat_reg(s, cond, ARITH_ORR,
186
- TCG_REG_TMP, TCG_REG_TMP, TCG_REG_TMP,
187
- SHIFT_IMM_LSL(16));
188
- } else {
189
- /*
190
- * rn = xxAB
191
- * and tmp, rn, #0xff00 tmp = 00A0
192
- * lsl tmp, tmp, #8 tmp = 0A00
193
- * orr tmp, tmp, rn, lsl #24 tmp = BA00
194
- */
195
- tcg_out_dat_rI(s, cond, ARITH_AND, TCG_REG_TMP, rn, 0xff00, 1);
196
- tcg_out_dat_reg(s, cond, ARITH_MOV,
197
- TCG_REG_TMP, 0, TCG_REG_TMP, SHIFT_IMM_LSL(8));
198
- tcg_out_dat_reg(s, cond, ARITH_ORR,
199
- TCG_REG_TMP, TCG_REG_TMP, rn, SHIFT_IMM_LSL(24));
200
- }
201
- tcg_out_dat_reg(s, cond, ARITH_MOV, rd, 0, TCG_REG_TMP,
202
- (flags & TCG_BSWAP_OS
203
- ? SHIFT_IMM_ASR(8) : SHIFT_IMM_LSR(8)));
204
}
205
206
static void tcg_out_bswap32(TCGContext *s, ARMCond cond, TCGReg rd, TCGReg rn)
207
{
208
- if (use_armv6_instructions) {
209
- /* rev */
210
- tcg_out32(s, 0x06bf0f30 | (cond << 28) | (rd << 12) | rn);
211
- } else {
212
- tcg_out_dat_reg(s, cond, ARITH_EOR,
213
- TCG_REG_TMP, rn, rn, SHIFT_IMM_ROR(16));
214
- tcg_out_dat_imm(s, cond, ARITH_BIC,
215
- TCG_REG_TMP, TCG_REG_TMP, 0xff | 0x800);
216
- tcg_out_dat_reg(s, cond, ARITH_MOV,
217
- rd, 0, rn, SHIFT_IMM_ROR(8));
218
- tcg_out_dat_reg(s, cond, ARITH_EOR,
219
- rd, rd, TCG_REG_TMP, SHIFT_IMM_LSR(8));
220
- }
221
+ /* rev */
222
+ tcg_out32(s, 0x06bf0f30 | (cond << 28) | (rd << 12) | rn);
223
}
224
225
static void tcg_out_deposit(TCGContext *s, ARMCond cond, TCGReg rd,
226
@@ -XXX,XX +XXX,XX @@ static void tcg_out_mb(TCGContext *s, TCGArg a0)
227
{
228
if (use_armv7_instructions) {
229
tcg_out32(s, INSN_DMB_ISH);
230
- } else if (use_armv6_instructions) {
231
+ } else {
232
tcg_out32(s, INSN_DMB_MCR);
233
}
234
}
235
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_arg_reg64(TCGContext *s, TCGReg argreg,
236
if (argreg & 1) {
237
argreg++;
238
}
239
- if (use_armv6_instructions && argreg >= 4
240
- && (arglo & 1) == 0 && arghi == arglo + 1) {
241
+ if (argreg >= 4 && (arglo & 1) == 0 && arghi == arglo + 1) {
242
tcg_out_strd_8(s, COND_AL, arglo,
243
TCG_REG_CALL_STACK, (argreg - 4) * 4);
244
return argreg + 2;
245
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
246
int cmp_off = (is_load ? offsetof(CPUTLBEntry, addr_read)
247
: offsetof(CPUTLBEntry, addr_write));
248
int fast_off = TLB_MASK_TABLE_OFS(mem_index);
249
- int mask_off = fast_off + offsetof(CPUTLBDescFast, mask);
250
- int table_off = fast_off + offsetof(CPUTLBDescFast, table);
251
unsigned s_bits = opc & MO_SIZE;
252
unsigned a_bits = get_alignment_bits(opc);
253
254
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
255
}
256
257
/* Load env_tlb(env)->f[mmu_idx].{mask,table} into {r0,r1}. */
258
- if (use_armv6_instructions) {
259
- tcg_out_ldrd_8(s, COND_AL, TCG_REG_R0, TCG_AREG0, fast_off);
260
- } else {
261
- tcg_out_ld(s, TCG_TYPE_I32, TCG_REG_R0, TCG_AREG0, mask_off);
262
- tcg_out_ld(s, TCG_TYPE_I32, TCG_REG_R1, TCG_AREG0, table_off);
263
- }
264
+ tcg_out_ldrd_8(s, COND_AL, TCG_REG_R0, TCG_AREG0, fast_off);
265
266
/* Extract the tlb index from the address into R0. */
267
tcg_out_dat_reg(s, COND_AL, ARITH_AND, TCG_REG_R0, TCG_REG_R0, addrlo,
268
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
269
* Load the tlb comparator into R2/R3 and the fast path addend into R1.
270
*/
271
if (cmp_off == 0) {
272
- if (use_armv6_instructions && TARGET_LONG_BITS == 64) {
273
+ if (TARGET_LONG_BITS == 64) {
274
tcg_out_ldrd_rwb(s, COND_AL, TCG_REG_R2, TCG_REG_R1, TCG_REG_R0);
275
} else {
276
tcg_out_ld32_rwb(s, COND_AL, TCG_REG_R2, TCG_REG_R1, TCG_REG_R0);
277
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
278
} else {
279
tcg_out_dat_reg(s, COND_AL, ARITH_ADD,
280
TCG_REG_R1, TCG_REG_R1, TCG_REG_R0, 0);
281
- if (use_armv6_instructions && TARGET_LONG_BITS == 64) {
282
+ if (TARGET_LONG_BITS == 64) {
283
tcg_out_ldrd_8(s, COND_AL, TCG_REG_R2, TCG_REG_R1, cmp_off);
284
} else {
285
tcg_out_ld32_12(s, COND_AL, TCG_REG_R2, TCG_REG_R1, cmp_off);
286
}
287
}
288
- if (!use_armv6_instructions && TARGET_LONG_BITS == 64) {
289
- tcg_out_ld32_12(s, COND_AL, TCG_REG_R3, TCG_REG_R1, cmp_off + 4);
290
- }
291
292
/* Load the tlb addend. */
293
tcg_out_ld32_12(s, COND_AL, TCG_REG_R1, TCG_REG_R1,
294
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
295
TCGReg argreg, datalo, datahi;
296
MemOpIdx oi = lb->oi;
297
MemOp opc = get_memop(oi);
298
- void *func;
299
300
if (!reloc_pc24(lb->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
301
return false;
302
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
303
argreg = tcg_out_arg_imm32(s, argreg, oi);
304
argreg = tcg_out_arg_reg32(s, argreg, TCG_REG_R14);
305
306
- /* For armv6 we can use the canonical unsigned helpers and minimize
307
- icache usage. For pre-armv6, use the signed helpers since we do
308
- not have a single insn sign-extend. */
309
- if (use_armv6_instructions) {
310
- func = qemu_ld_helpers[opc & MO_SIZE];
311
- } else {
312
- func = qemu_ld_helpers[opc & MO_SSIZE];
313
- if (opc & MO_SIGN) {
314
- opc = MO_UL;
315
- }
316
- }
317
- tcg_out_call(s, func);
318
+ /* Use the canonical unsigned helpers and minimize icache usage. */
319
+ tcg_out_call(s, qemu_ld_helpers[opc & MO_SIZE]);
320
321
datalo = lb->datalo_reg;
322
datahi = lb->datahi_reg;
323
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc,
324
break;
325
case MO_UQ:
326
/* Avoid ldrd for user-only emulation, to handle unaligned. */
327
- if (USING_SOFTMMU && use_armv6_instructions
328
+ if (USING_SOFTMMU
329
&& (datalo & 1) == 0 && datahi == datalo + 1) {
330
tcg_out_ldrd_r(s, COND_AL, datalo, addrlo, addend);
331
} else if (datalo != addend) {
332
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_direct(TCGContext *s, MemOp opc, TCGReg datalo,
333
break;
334
case MO_UQ:
335
/* Avoid ldrd for user-only emulation, to handle unaligned. */
336
- if (USING_SOFTMMU && use_armv6_instructions
337
+ if (USING_SOFTMMU
338
&& (datalo & 1) == 0 && datahi == datalo + 1) {
339
tcg_out_ldrd_8(s, COND_AL, datalo, addrlo, 0);
340
} else if (datalo == addrlo) {
341
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
342
break;
343
case MO_64:
344
/* Avoid strd for user-only emulation, to handle unaligned. */
345
- if (USING_SOFTMMU && use_armv6_instructions
346
+ if (USING_SOFTMMU
347
&& (datalo & 1) == 0 && datahi == datalo + 1) {
348
tcg_out_strd_r(s, cond, datalo, addrlo, addend);
349
} else {
350
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, MemOp opc, TCGReg datalo,
351
break;
352
case MO_64:
353
/* Avoid strd for user-only emulation, to handle unaligned. */
354
- if (USING_SOFTMMU && use_armv6_instructions
355
+ if (USING_SOFTMMU
356
&& (datalo & 1) == 0 && datahi == datalo + 1) {
357
tcg_out_strd_8(s, COND_AL, datalo, addrlo, 0);
358
} else {
359
--
360
2.25.1
361
362
diff view generated by jsdifflib
New patch
1
We will shortly allow the use of unaligned memory accesses,
2
and these require proper alignment. Use get_alignment_bits
3
to verify and remove USING_SOFTMMU.
1
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
tcg/arm/tcg-target.c.inc | 23 ++++++++---------------
9
1 file changed, 8 insertions(+), 15 deletions(-)
10
11
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
12
index XXXXXXX..XXXXXXX 100644
13
--- a/tcg/arm/tcg-target.c.inc
14
+++ b/tcg/arm/tcg-target.c.inc
15
@@ -XXX,XX +XXX,XX @@ bool use_idiv_instructions;
16
bool use_neon_instructions;
17
#endif
18
19
-/* ??? Ought to think about changing CONFIG_SOFTMMU to always defined. */
20
-#ifdef CONFIG_SOFTMMU
21
-# define USING_SOFTMMU 1
22
-#else
23
-# define USING_SOFTMMU 0
24
-#endif
25
-
26
#ifdef CONFIG_DEBUG_TCG
27
static const char * const tcg_target_reg_names[TCG_TARGET_NB_REGS] = {
28
"%r0", "%r1", "%r2", "%r3", "%r4", "%r5", "%r6", "%r7",
29
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc,
30
tcg_out_ld32_r(s, COND_AL, datalo, addrlo, addend);
31
break;
32
case MO_UQ:
33
- /* Avoid ldrd for user-only emulation, to handle unaligned. */
34
- if (USING_SOFTMMU
35
+ /* LDRD requires alignment; double-check that. */
36
+ if (get_alignment_bits(opc) >= MO_64
37
&& (datalo & 1) == 0 && datahi == datalo + 1) {
38
tcg_out_ldrd_r(s, COND_AL, datalo, addrlo, addend);
39
} else if (datalo != addend) {
40
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_direct(TCGContext *s, MemOp opc, TCGReg datalo,
41
tcg_out_ld32_12(s, COND_AL, datalo, addrlo, 0);
42
break;
43
case MO_UQ:
44
- /* Avoid ldrd for user-only emulation, to handle unaligned. */
45
- if (USING_SOFTMMU
46
+ /* LDRD requires alignment; double-check that. */
47
+ if (get_alignment_bits(opc) >= MO_64
48
&& (datalo & 1) == 0 && datahi == datalo + 1) {
49
tcg_out_ldrd_8(s, COND_AL, datalo, addrlo, 0);
50
} else if (datalo == addrlo) {
51
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
52
tcg_out_st32_r(s, cond, datalo, addrlo, addend);
53
break;
54
case MO_64:
55
- /* Avoid strd for user-only emulation, to handle unaligned. */
56
- if (USING_SOFTMMU
57
+ /* STRD requires alignment; double-check that. */
58
+ if (get_alignment_bits(opc) >= MO_64
59
&& (datalo & 1) == 0 && datahi == datalo + 1) {
60
tcg_out_strd_r(s, cond, datalo, addrlo, addend);
61
} else {
62
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, MemOp opc, TCGReg datalo,
63
tcg_out_st32_12(s, COND_AL, datalo, addrlo, 0);
64
break;
65
case MO_64:
66
- /* Avoid strd for user-only emulation, to handle unaligned. */
67
- if (USING_SOFTMMU
68
+ /* STRD requires alignment; double-check that. */
69
+ if (get_alignment_bits(opc) >= MO_64
70
&& (datalo & 1) == 0 && datahi == datalo + 1) {
71
tcg_out_strd_8(s, COND_AL, datalo, addrlo, 0);
72
} else {
73
--
74
2.25.1
75
76
diff view generated by jsdifflib
New patch
1
From armv6, the architecture supports unaligned accesses.
2
All we need to do is perform the correct alignment check
3
in tcg_out_tlb_read.
1
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
tcg/arm/tcg-target.c.inc | 41 ++++++++++++++++++++--------------------
9
1 file changed, 21 insertions(+), 20 deletions(-)
10
11
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
12
index XXXXXXX..XXXXXXX 100644
13
--- a/tcg/arm/tcg-target.c.inc
14
+++ b/tcg/arm/tcg-target.c.inc
15
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
16
int cmp_off = (is_load ? offsetof(CPUTLBEntry, addr_read)
17
: offsetof(CPUTLBEntry, addr_write));
18
int fast_off = TLB_MASK_TABLE_OFS(mem_index);
19
- unsigned s_bits = opc & MO_SIZE;
20
- unsigned a_bits = get_alignment_bits(opc);
21
-
22
- /*
23
- * We don't support inline unaligned acceses, but we can easily
24
- * support overalignment checks.
25
- */
26
- if (a_bits < s_bits) {
27
- a_bits = s_bits;
28
- }
29
+ unsigned s_mask = (1 << (opc & MO_SIZE)) - 1;
30
+ unsigned a_mask = (1 << get_alignment_bits(opc)) - 1;
31
+ TCGReg t_addr;
32
33
/* Load env_tlb(env)->f[mmu_idx].{mask,table} into {r0,r1}. */
34
tcg_out_ldrd_8(s, COND_AL, TCG_REG_R0, TCG_AREG0, fast_off);
35
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_read(TCGContext *s, TCGReg addrlo, TCGReg addrhi,
36
37
/*
38
* Check alignment, check comparators.
39
- * Do this in no more than 3 insns. Use MOVW for v7, if possible,
40
+ * Do this in 2-4 insns. Use MOVW for v7, if possible,
41
* to reduce the number of sequential conditional instructions.
42
* Almost all guests have at least 4k pages, which means that we need
43
* to clear at least 9 bits even for an 8-byte memory, which means it
44
* isn't worth checking for an immediate operand for BIC.
45
+ *
46
+ * For unaligned accesses, test the page of the last unit of alignment.
47
+ * This leaves the least significant alignment bits unchanged, and of
48
+ * course must be zero.
49
*/
50
+ t_addr = addrlo;
51
+ if (a_mask < s_mask) {
52
+ t_addr = TCG_REG_R0;
53
+ tcg_out_dat_imm(s, COND_AL, ARITH_ADD, t_addr,
54
+ addrlo, s_mask - a_mask);
55
+ }
56
if (use_armv7_instructions && TARGET_PAGE_BITS <= 16) {
57
- tcg_target_ulong mask = ~(TARGET_PAGE_MASK | ((1 << a_bits) - 1));
58
-
59
- tcg_out_movi32(s, COND_AL, TCG_REG_TMP, mask);
60
+ tcg_out_movi32(s, COND_AL, TCG_REG_TMP, ~(TARGET_PAGE_MASK | a_mask));
61
tcg_out_dat_reg(s, COND_AL, ARITH_BIC, TCG_REG_TMP,
62
- addrlo, TCG_REG_TMP, 0);
63
+ t_addr, TCG_REG_TMP, 0);
64
tcg_out_dat_reg(s, COND_AL, ARITH_CMP, 0, TCG_REG_R2, TCG_REG_TMP, 0);
65
} else {
66
- if (a_bits) {
67
- tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo,
68
- (1 << a_bits) - 1);
69
+ if (a_mask) {
70
+ tcg_debug_assert(a_mask <= 0xff);
71
+ tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, a_mask);
72
}
73
- tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, 0, addrlo,
74
+ tcg_out_dat_reg(s, COND_AL, ARITH_MOV, TCG_REG_TMP, 0, t_addr,
75
SHIFT_IMM_LSR(TARGET_PAGE_BITS));
76
- tcg_out_dat_reg(s, (a_bits ? COND_EQ : COND_AL), ARITH_CMP,
77
+ tcg_out_dat_reg(s, (a_mask ? COND_EQ : COND_AL), ARITH_CMP,
78
0, TCG_REG_R2, TCG_REG_TMP,
79
SHIFT_IMM_LSL(TARGET_PAGE_BITS));
80
}
81
--
82
2.25.1
83
84
diff view generated by jsdifflib
New patch
1
Reserve a register for the guest_base using aarch64 for reference.
2
By doing so, we do not have to recompute it for every memory load.
1
3
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
7
tcg/arm/tcg-target.c.inc | 39 ++++++++++++++++++++++++++++-----------
8
1 file changed, 28 insertions(+), 11 deletions(-)
9
10
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
11
index XXXXXXX..XXXXXXX 100644
12
--- a/tcg/arm/tcg-target.c.inc
13
+++ b/tcg/arm/tcg-target.c.inc
14
@@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_oarg_regs[2] = {
15
16
#define TCG_REG_TMP TCG_REG_R12
17
#define TCG_VEC_TMP TCG_REG_Q15
18
+#ifndef CONFIG_SOFTMMU
19
+#define TCG_REG_GUEST_BASE TCG_REG_R11
20
+#endif
21
22
typedef enum {
23
COND_EQ = 0x0,
24
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
25
26
static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc,
27
TCGReg datalo, TCGReg datahi,
28
- TCGReg addrlo, TCGReg addend)
29
+ TCGReg addrlo, TCGReg addend,
30
+ bool scratch_addend)
31
{
32
/* Byte swapping is left to middle-end expansion. */
33
tcg_debug_assert((opc & MO_BSWAP) == 0);
34
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc,
35
if (get_alignment_bits(opc) >= MO_64
36
&& (datalo & 1) == 0 && datahi == datalo + 1) {
37
tcg_out_ldrd_r(s, COND_AL, datalo, addrlo, addend);
38
- } else if (datalo != addend) {
39
+ } else if (scratch_addend) {
40
tcg_out_ld32_rwb(s, COND_AL, datalo, addend, addrlo);
41
tcg_out_ld32_12(s, COND_AL, datahi, addend, 4);
42
} else {
43
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
44
label_ptr = s->code_ptr;
45
tcg_out_bl_imm(s, COND_NE, 0);
46
47
- tcg_out_qemu_ld_index(s, opc, datalo, datahi, addrlo, addend);
48
+ tcg_out_qemu_ld_index(s, opc, datalo, datahi, addrlo, addend, true);
49
50
add_qemu_ldst_label(s, true, oi, datalo, datahi, addrlo, addrhi,
51
s->code_ptr, label_ptr);
52
#else /* !CONFIG_SOFTMMU */
53
if (guest_base) {
54
- tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP, guest_base);
55
- tcg_out_qemu_ld_index(s, opc, datalo, datahi, addrlo, TCG_REG_TMP);
56
+ tcg_out_qemu_ld_index(s, opc, datalo, datahi,
57
+ addrlo, TCG_REG_GUEST_BASE, false);
58
} else {
59
tcg_out_qemu_ld_direct(s, opc, datalo, datahi, addrlo);
60
}
61
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
62
63
static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
64
TCGReg datalo, TCGReg datahi,
65
- TCGReg addrlo, TCGReg addend)
66
+ TCGReg addrlo, TCGReg addend,
67
+ bool scratch_addend)
68
{
69
/* Byte swapping is left to middle-end expansion. */
70
tcg_debug_assert((opc & MO_BSWAP) == 0);
71
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
72
if (get_alignment_bits(opc) >= MO_64
73
&& (datalo & 1) == 0 && datahi == datalo + 1) {
74
tcg_out_strd_r(s, cond, datalo, addrlo, addend);
75
- } else {
76
+ } else if (scratch_addend) {
77
tcg_out_st32_rwb(s, cond, datalo, addend, addrlo);
78
tcg_out_st32_12(s, cond, datahi, addend, 4);
79
+ } else {
80
+ tcg_out_dat_reg(s, cond, ARITH_ADD, TCG_REG_TMP,
81
+ addend, addrlo, SHIFT_IMM_LSL(0));
82
+ tcg_out_st32_12(s, cond, datalo, TCG_REG_TMP, 0);
83
+ tcg_out_st32_12(s, cond, datahi, TCG_REG_TMP, 4);
84
}
85
break;
86
default:
87
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
88
mem_index = get_mmuidx(oi);
89
addend = tcg_out_tlb_read(s, addrlo, addrhi, opc, mem_index, 0);
90
91
- tcg_out_qemu_st_index(s, COND_EQ, opc, datalo, datahi, addrlo, addend);
92
+ tcg_out_qemu_st_index(s, COND_EQ, opc, datalo, datahi,
93
+ addrlo, addend, true);
94
95
/* The conditional call must come last, as we're going to return here. */
96
label_ptr = s->code_ptr;
97
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
98
s->code_ptr, label_ptr);
99
#else /* !CONFIG_SOFTMMU */
100
if (guest_base) {
101
- tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP, guest_base);
102
- tcg_out_qemu_st_index(s, COND_AL, opc, datalo,
103
- datahi, addrlo, TCG_REG_TMP);
104
+ tcg_out_qemu_st_index(s, COND_AL, opc, datalo, datahi,
105
+ addrlo, TCG_REG_GUEST_BASE, false);
106
} else {
107
tcg_out_qemu_st_direct(s, opc, datalo, datahi, addrlo);
108
}
109
@@ -XXX,XX +XXX,XX @@ static void tcg_target_qemu_prologue(TCGContext *s)
110
111
tcg_out_mov(s, TCG_TYPE_PTR, TCG_AREG0, tcg_target_call_iarg_regs[0]);
112
113
+#ifndef CONFIG_SOFTMMU
114
+ if (guest_base) {
115
+ tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_GUEST_BASE, guest_base);
116
+ tcg_regset_set_reg(s->reserved_regs, TCG_REG_GUEST_BASE);
117
+ }
118
+#endif
119
+
120
tcg_out_b_reg(s, COND_AL, tcg_target_call_iarg_regs[1]);
121
122
/*
123
--
124
2.25.1
125
126
diff view generated by jsdifflib
New patch
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/arm/tcg-target.h | 2 -
5
tcg/arm/tcg-target.c.inc | 83 +++++++++++++++++++++++++++++++++++++++-
6
2 files changed, 81 insertions(+), 4 deletions(-)
1
7
8
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
9
index XXXXXXX..XXXXXXX 100644
10
--- a/tcg/arm/tcg-target.h
11
+++ b/tcg/arm/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions;
13
/* not defined -- call should be eliminated at compile time */
14
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
15
16
-#ifdef CONFIG_SOFTMMU
17
#define TCG_TARGET_NEED_LDST_LABELS
18
-#endif
19
#define TCG_TARGET_NEED_POOL_LABELS
20
21
#endif
22
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
23
index XXXXXXX..XXXXXXX 100644
24
--- a/tcg/arm/tcg-target.c.inc
25
+++ b/tcg/arm/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@
27
*/
28
29
#include "elf.h"
30
+#include "../tcg-ldst.c.inc"
31
#include "../tcg-pool.c.inc"
32
33
int arm_arch = __ARM_ARCH;
34
@@ -XXX,XX +XXX,XX @@ static void tcg_out_vldst(TCGContext *s, ARMInsn insn,
35
}
36
37
#ifdef CONFIG_SOFTMMU
38
-#include "../tcg-ldst.c.inc"
39
-
40
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
41
* int mmu_idx, uintptr_t ra)
42
*/
43
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
44
tcg_out_goto(s, COND_AL, qemu_st_helpers[opc & MO_SIZE]);
45
return true;
46
}
47
+#else
48
+
49
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
50
+ TCGReg addrhi, unsigned a_bits)
51
+{
52
+ unsigned a_mask = (1 << a_bits) - 1;
53
+ TCGLabelQemuLdst *label = new_ldst_label(s);
54
+
55
+ label->is_ld = is_ld;
56
+ label->addrlo_reg = addrlo;
57
+ label->addrhi_reg = addrhi;
58
+
59
+ /* We are expecting a_bits to max out at 7, and can easily support 8. */
60
+ tcg_debug_assert(a_mask <= 0xff);
61
+ /* tst addr, #mask */
62
+ tcg_out_dat_imm(s, COND_AL, ARITH_TST, 0, addrlo, a_mask);
63
+
64
+ /* blne slow_path */
65
+ label->label_ptr[0] = s->code_ptr;
66
+ tcg_out_bl_imm(s, COND_NE, 0);
67
+
68
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr);
69
+}
70
+
71
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
72
+{
73
+ if (!reloc_pc24(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
74
+ return false;
75
+ }
76
+
77
+ if (TARGET_LONG_BITS == 64) {
78
+ /* 64-bit target address is aligned into R2:R3. */
79
+ if (l->addrhi_reg != TCG_REG_R2) {
80
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, l->addrlo_reg);
81
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, l->addrhi_reg);
82
+ } else if (l->addrlo_reg != TCG_REG_R3) {
83
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, l->addrhi_reg);
84
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, l->addrlo_reg);
85
+ } else {
86
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R1, TCG_REG_R2);
87
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R2, TCG_REG_R3);
88
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R3, TCG_REG_R1);
89
+ }
90
+ } else {
91
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_R1, l->addrlo_reg);
92
+ }
93
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_AREG0);
94
+
95
+ /*
96
+ * Tail call to the helper, with the return address back inline,
97
+ * just for the clarity of the debugging traceback -- the helper
98
+ * cannot return. We have used BLNE to arrive here, so LR is
99
+ * already set.
100
+ */
101
+ tcg_out_goto(s, COND_AL, (const void *)
102
+ (l->is_ld ? helper_unaligned_ld : helper_unaligned_st));
103
+ return true;
104
+}
105
+
106
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
107
+{
108
+ return tcg_out_fail_alignment(s, l);
109
+}
110
+
111
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
112
+{
113
+ return tcg_out_fail_alignment(s, l);
114
+}
115
#endif /* SOFTMMU */
116
117
static void tcg_out_qemu_ld_index(TCGContext *s, MemOp opc,
118
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
119
int mem_index;
120
TCGReg addend;
121
tcg_insn_unit *label_ptr;
122
+#else
123
+ unsigned a_bits;
124
#endif
125
126
datalo = *args++;
127
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
128
add_qemu_ldst_label(s, true, oi, datalo, datahi, addrlo, addrhi,
129
s->code_ptr, label_ptr);
130
#else /* !CONFIG_SOFTMMU */
131
+ a_bits = get_alignment_bits(opc);
132
+ if (a_bits) {
133
+ tcg_out_test_alignment(s, true, addrlo, addrhi, a_bits);
134
+ }
135
if (guest_base) {
136
tcg_out_qemu_ld_index(s, opc, datalo, datahi,
137
addrlo, TCG_REG_GUEST_BASE, false);
138
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
139
int mem_index;
140
TCGReg addend;
141
tcg_insn_unit *label_ptr;
142
+#else
143
+ unsigned a_bits;
144
#endif
145
146
datalo = *args++;
147
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is64)
148
add_qemu_ldst_label(s, false, oi, datalo, datahi, addrlo, addrhi,
149
s->code_ptr, label_ptr);
150
#else /* !CONFIG_SOFTMMU */
151
+ a_bits = get_alignment_bits(opc);
152
+ if (a_bits) {
153
+ tcg_out_test_alignment(s, false, addrlo, addrhi, a_bits);
154
+ }
155
if (guest_base) {
156
tcg_out_qemu_st_index(s, COND_AL, opc, datalo, datahi,
157
addrlo, TCG_REG_GUEST_BASE, false);
158
--
159
2.25.1
160
161
diff view generated by jsdifflib
New patch
1
This is kinda sorta the opposite of the other tcg hosts, where
2
we get (normal) alignment checks for free with host SIGBUS and
3
need to add code to support unaligned accesses.
1
4
5
Fortunately, the ISA contains pairs of instructions that are
6
used to implement unaligned memory accesses. Use them.
7
8
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
9
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
12
---
13
tcg/mips/tcg-target.h | 2 -
14
tcg/mips/tcg-target.c.inc | 334 +++++++++++++++++++++++++++++++++++++-
15
2 files changed, 328 insertions(+), 8 deletions(-)
16
17
diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/tcg/mips/tcg-target.h
20
+++ b/tcg/mips/tcg-target.h
21
@@ -XXX,XX +XXX,XX @@ extern bool use_mips32r2_instructions;
22
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t)
23
QEMU_ERROR("code path is reachable");
24
25
-#ifdef CONFIG_SOFTMMU
26
#define TCG_TARGET_NEED_LDST_LABELS
27
-#endif
28
29
#endif
30
diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc
31
index XXXXXXX..XXXXXXX 100644
32
--- a/tcg/mips/tcg-target.c.inc
33
+++ b/tcg/mips/tcg-target.c.inc
34
@@ -XXX,XX +XXX,XX @@
35
* THE SOFTWARE.
36
*/
37
38
+#include "../tcg-ldst.c.inc"
39
+
40
#ifdef HOST_WORDS_BIGENDIAN
41
# define MIPS_BE 1
42
#else
43
@@ -XXX,XX +XXX,XX @@ typedef enum {
44
OPC_ORI = 015 << 26,
45
OPC_XORI = 016 << 26,
46
OPC_LUI = 017 << 26,
47
+ OPC_BNEL = 025 << 26,
48
+ OPC_BNEZALC_R6 = 030 << 26,
49
OPC_DADDIU = 031 << 26,
50
+ OPC_LDL = 032 << 26,
51
+ OPC_LDR = 033 << 26,
52
OPC_LB = 040 << 26,
53
OPC_LH = 041 << 26,
54
+ OPC_LWL = 042 << 26,
55
OPC_LW = 043 << 26,
56
OPC_LBU = 044 << 26,
57
OPC_LHU = 045 << 26,
58
+ OPC_LWR = 046 << 26,
59
OPC_LWU = 047 << 26,
60
OPC_SB = 050 << 26,
61
OPC_SH = 051 << 26,
62
+ OPC_SWL = 052 << 26,
63
OPC_SW = 053 << 26,
64
+ OPC_SDL = 054 << 26,
65
+ OPC_SDR = 055 << 26,
66
+ OPC_SWR = 056 << 26,
67
OPC_LD = 067 << 26,
68
OPC_SD = 077 << 26,
69
70
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *arg)
71
}
72
73
#if defined(CONFIG_SOFTMMU)
74
-#include "../tcg-ldst.c.inc"
75
-
76
static void * const qemu_ld_helpers[(MO_SSIZE | MO_BSWAP) + 1] = {
77
[MO_UB] = helper_ret_ldub_mmu,
78
[MO_SB] = helper_ret_ldsb_mmu,
79
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
80
tcg_out_mov(s, TCG_TYPE_PTR, tcg_target_call_iarg_regs[0], TCG_AREG0);
81
return true;
82
}
83
-#endif
84
+
85
+#else
86
+
87
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
88
+ TCGReg addrhi, unsigned a_bits)
89
+{
90
+ unsigned a_mask = (1 << a_bits) - 1;
91
+ TCGLabelQemuLdst *l = new_ldst_label(s);
92
+
93
+ l->is_ld = is_ld;
94
+ l->addrlo_reg = addrlo;
95
+ l->addrhi_reg = addrhi;
96
+
97
+ /* We are expecting a_bits to max out at 7, much lower than ANDI. */
98
+ tcg_debug_assert(a_bits < 16);
99
+ tcg_out_opc_imm(s, OPC_ANDI, TCG_TMP0, addrlo, a_mask);
100
+
101
+ l->label_ptr[0] = s->code_ptr;
102
+ if (use_mips32r6_instructions) {
103
+ tcg_out_opc_br(s, OPC_BNEZALC_R6, TCG_REG_ZERO, TCG_TMP0);
104
+ } else {
105
+ tcg_out_opc_br(s, OPC_BNEL, TCG_TMP0, TCG_REG_ZERO);
106
+ tcg_out_nop(s);
107
+ }
108
+
109
+ l->raddr = tcg_splitwx_to_rx(s->code_ptr);
110
+}
111
+
112
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
113
+{
114
+ void *target;
115
+
116
+ if (!reloc_pc16(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
117
+ return false;
118
+ }
119
+
120
+ if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
121
+ /* A0 is env, A1 is skipped, A2:A3 is the uint64_t address. */
122
+ TCGReg a2 = MIPS_BE ? l->addrhi_reg : l->addrlo_reg;
123
+ TCGReg a3 = MIPS_BE ? l->addrlo_reg : l->addrhi_reg;
124
+
125
+ if (a3 != TCG_REG_A2) {
126
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A2, a2);
127
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A3, a3);
128
+ } else if (a2 != TCG_REG_A3) {
129
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A3, a3);
130
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A2, a2);
131
+ } else {
132
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_TMP0, TCG_REG_A2);
133
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A2, TCG_REG_A3);
134
+ tcg_out_mov(s, TCG_TYPE_I32, TCG_REG_A3, TCG_TMP0);
135
+ }
136
+ } else {
137
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_A1, l->addrlo_reg);
138
+ }
139
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_A0, TCG_AREG0);
140
+
141
+ /*
142
+ * Tail call to the helper, with the return address back inline.
143
+ * We have arrived here via BNEL, so $31 is already set.
144
+ */
145
+ target = (l->is_ld ? helper_unaligned_ld : helper_unaligned_st);
146
+ tcg_out_call_int(s, target, true);
147
+ return true;
148
+}
149
+
150
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
151
+{
152
+ return tcg_out_fail_alignment(s, l);
153
+}
154
+
155
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
156
+{
157
+ return tcg_out_fail_alignment(s, l);
158
+}
159
+#endif /* SOFTMMU */
160
161
static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg lo, TCGReg hi,
162
TCGReg base, MemOp opc, bool is_64)
163
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg lo, TCGReg hi,
164
}
165
}
166
167
+static void __attribute__((unused))
168
+tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
169
+ TCGReg base, MemOp opc, bool is_64)
170
+{
171
+ const MIPSInsn lw1 = MIPS_BE ? OPC_LWL : OPC_LWR;
172
+ const MIPSInsn lw2 = MIPS_BE ? OPC_LWR : OPC_LWL;
173
+ const MIPSInsn ld1 = MIPS_BE ? OPC_LDL : OPC_LDR;
174
+ const MIPSInsn ld2 = MIPS_BE ? OPC_LDR : OPC_LDL;
175
+
176
+ bool sgn = (opc & MO_SIGN);
177
+
178
+ switch (opc & (MO_SSIZE | MO_BSWAP)) {
179
+ case MO_SW | MO_BE:
180
+ case MO_UW | MO_BE:
181
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 0);
182
+ tcg_out_opc_imm(s, OPC_LBU, lo, base, 1);
183
+ if (use_mips32r2_instructions) {
184
+ tcg_out_opc_bf(s, OPC_INS, lo, TCG_TMP0, 31, 8);
185
+ } else {
186
+ tcg_out_opc_sa(s, OPC_SLL, TCG_TMP0, TCG_TMP0, 8);
187
+ tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1);
188
+ }
189
+ break;
190
+
191
+ case MO_SW | MO_LE:
192
+ case MO_UW | MO_LE:
193
+ if (use_mips32r2_instructions && lo != base) {
194
+ tcg_out_opc_imm(s, OPC_LBU, lo, base, 0);
195
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 1);
196
+ tcg_out_opc_bf(s, OPC_INS, lo, TCG_TMP0, 31, 8);
197
+ } else {
198
+ tcg_out_opc_imm(s, OPC_LBU, TCG_TMP0, base, 0);
199
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP1, base, 1);
200
+ tcg_out_opc_sa(s, OPC_SLL, TCG_TMP1, TCG_TMP1, 8);
201
+ tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1);
202
+ }
203
+ break;
204
+
205
+ case MO_SL:
206
+ case MO_UL:
207
+ tcg_out_opc_imm(s, lw1, lo, base, 0);
208
+ tcg_out_opc_imm(s, lw2, lo, base, 3);
209
+ if (TCG_TARGET_REG_BITS == 64 && is_64 && !sgn) {
210
+ tcg_out_ext32u(s, lo, lo);
211
+ }
212
+ break;
213
+
214
+ case MO_UL | MO_BSWAP:
215
+ case MO_SL | MO_BSWAP:
216
+ if (use_mips32r2_instructions) {
217
+ tcg_out_opc_imm(s, lw1, lo, base, 0);
218
+ tcg_out_opc_imm(s, lw2, lo, base, 3);
219
+ tcg_out_bswap32(s, lo, lo,
220
+ TCG_TARGET_REG_BITS == 64 && is_64
221
+ ? (sgn ? TCG_BSWAP_OS : TCG_BSWAP_OZ) : 0);
222
+ } else {
223
+ const tcg_insn_unit *subr =
224
+ (TCG_TARGET_REG_BITS == 64 && is_64 && !sgn
225
+ ? bswap32u_addr : bswap32_addr);
226
+
227
+ tcg_out_opc_imm(s, lw1, TCG_TMP0, base, 0);
228
+ tcg_out_bswap_subr(s, subr);
229
+ /* delay slot */
230
+ tcg_out_opc_imm(s, lw2, TCG_TMP0, base, 3);
231
+ tcg_out_mov(s, is_64 ? TCG_TYPE_I64 : TCG_TYPE_I32, lo, TCG_TMP3);
232
+ }
233
+ break;
234
+
235
+ case MO_UQ:
236
+ if (TCG_TARGET_REG_BITS == 64) {
237
+ tcg_out_opc_imm(s, ld1, lo, base, 0);
238
+ tcg_out_opc_imm(s, ld2, lo, base, 7);
239
+ } else {
240
+ tcg_out_opc_imm(s, lw1, MIPS_BE ? hi : lo, base, 0 + 0);
241
+ tcg_out_opc_imm(s, lw2, MIPS_BE ? hi : lo, base, 0 + 3);
242
+ tcg_out_opc_imm(s, lw1, MIPS_BE ? lo : hi, base, 4 + 0);
243
+ tcg_out_opc_imm(s, lw2, MIPS_BE ? lo : hi, base, 4 + 3);
244
+ }
245
+ break;
246
+
247
+ case MO_UQ | MO_BSWAP:
248
+ if (TCG_TARGET_REG_BITS == 64) {
249
+ if (use_mips32r2_instructions) {
250
+ tcg_out_opc_imm(s, ld1, lo, base, 0);
251
+ tcg_out_opc_imm(s, ld2, lo, base, 7);
252
+ tcg_out_bswap64(s, lo, lo);
253
+ } else {
254
+ tcg_out_opc_imm(s, ld1, TCG_TMP0, base, 0);
255
+ tcg_out_bswap_subr(s, bswap64_addr);
256
+ /* delay slot */
257
+ tcg_out_opc_imm(s, ld2, TCG_TMP0, base, 7);
258
+ tcg_out_mov(s, TCG_TYPE_I64, lo, TCG_TMP3);
259
+ }
260
+ } else if (use_mips32r2_instructions) {
261
+ tcg_out_opc_imm(s, lw1, TCG_TMP0, base, 0 + 0);
262
+ tcg_out_opc_imm(s, lw2, TCG_TMP0, base, 0 + 3);
263
+ tcg_out_opc_imm(s, lw1, TCG_TMP1, base, 4 + 0);
264
+ tcg_out_opc_imm(s, lw2, TCG_TMP1, base, 4 + 3);
265
+ tcg_out_opc_reg(s, OPC_WSBH, TCG_TMP0, 0, TCG_TMP0);
266
+ tcg_out_opc_reg(s, OPC_WSBH, TCG_TMP1, 0, TCG_TMP1);
267
+ tcg_out_opc_sa(s, OPC_ROTR, MIPS_BE ? lo : hi, TCG_TMP0, 16);
268
+ tcg_out_opc_sa(s, OPC_ROTR, MIPS_BE ? hi : lo, TCG_TMP1, 16);
269
+ } else {
270
+ tcg_out_opc_imm(s, lw1, TCG_TMP0, base, 0 + 0);
271
+ tcg_out_bswap_subr(s, bswap32_addr);
272
+ /* delay slot */
273
+ tcg_out_opc_imm(s, lw2, TCG_TMP0, base, 0 + 3);
274
+ tcg_out_opc_imm(s, lw1, TCG_TMP0, base, 4 + 0);
275
+ tcg_out_mov(s, TCG_TYPE_I32, MIPS_BE ? lo : hi, TCG_TMP3);
276
+ tcg_out_bswap_subr(s, bswap32_addr);
277
+ /* delay slot */
278
+ tcg_out_opc_imm(s, lw2, TCG_TMP0, base, 4 + 3);
279
+ tcg_out_mov(s, TCG_TYPE_I32, MIPS_BE ? hi : lo, TCG_TMP3);
280
+ }
281
+ break;
282
+
283
+ default:
284
+ g_assert_not_reached();
285
+ }
286
+}
287
+
288
static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
289
{
290
TCGReg addr_regl, addr_regh __attribute__((unused));
291
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
292
MemOp opc;
293
#if defined(CONFIG_SOFTMMU)
294
tcg_insn_unit *label_ptr[2];
295
+#else
296
+ unsigned a_bits, s_bits;
297
#endif
298
TCGReg base = TCG_REG_A0;
299
300
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
301
} else {
302
tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_GUEST_BASE_REG, addr_regl);
303
}
304
- tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
305
+ a_bits = get_alignment_bits(opc);
306
+ s_bits = opc & MO_SIZE;
307
+ /*
308
+ * R6 removes the left/right instructions but requires the
309
+ * system to support misaligned memory accesses.
310
+ */
311
+ if (use_mips32r6_instructions) {
312
+ if (a_bits) {
313
+ tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
314
+ }
315
+ tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
316
+ } else {
317
+ if (a_bits && a_bits != s_bits) {
318
+ tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
319
+ }
320
+ if (a_bits >= s_bits) {
321
+ tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
322
+ } else {
323
+ tcg_out_qemu_ld_unalign(s, data_regl, data_regh, base, opc, is_64);
324
+ }
325
+ }
326
#endif
327
}
328
329
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg lo, TCGReg hi,
330
}
331
}
332
333
+static void __attribute__((unused))
334
+tcg_out_qemu_st_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
335
+ TCGReg base, MemOp opc)
336
+{
337
+ const MIPSInsn sw1 = MIPS_BE ? OPC_SWL : OPC_SWR;
338
+ const MIPSInsn sw2 = MIPS_BE ? OPC_SWR : OPC_SWL;
339
+ const MIPSInsn sd1 = MIPS_BE ? OPC_SDL : OPC_SDR;
340
+ const MIPSInsn sd2 = MIPS_BE ? OPC_SDR : OPC_SDL;
341
+
342
+ /* Don't clutter the code below with checks to avoid bswapping ZERO. */
343
+ if ((lo | hi) == 0) {
344
+ opc &= ~MO_BSWAP;
345
+ }
346
+
347
+ switch (opc & (MO_SIZE | MO_BSWAP)) {
348
+ case MO_16 | MO_BE:
349
+ tcg_out_opc_sa(s, OPC_SRL, TCG_TMP0, lo, 8);
350
+ tcg_out_opc_imm(s, OPC_SB, TCG_TMP0, base, 0);
351
+ tcg_out_opc_imm(s, OPC_SB, lo, base, 1);
352
+ break;
353
+
354
+ case MO_16 | MO_LE:
355
+ tcg_out_opc_sa(s, OPC_SRL, TCG_TMP0, lo, 8);
356
+ tcg_out_opc_imm(s, OPC_SB, lo, base, 0);
357
+ tcg_out_opc_imm(s, OPC_SB, TCG_TMP0, base, 1);
358
+ break;
359
+
360
+ case MO_32 | MO_BSWAP:
361
+ tcg_out_bswap32(s, TCG_TMP3, lo, 0);
362
+ lo = TCG_TMP3;
363
+ /* fall through */
364
+ case MO_32:
365
+ tcg_out_opc_imm(s, sw1, lo, base, 0);
366
+ tcg_out_opc_imm(s, sw2, lo, base, 3);
367
+ break;
368
+
369
+ case MO_64 | MO_BSWAP:
370
+ if (TCG_TARGET_REG_BITS == 64) {
371
+ tcg_out_bswap64(s, TCG_TMP3, lo);
372
+ lo = TCG_TMP3;
373
+ } else if (use_mips32r2_instructions) {
374
+ tcg_out_opc_reg(s, OPC_WSBH, TCG_TMP0, 0, MIPS_BE ? hi : lo);
375
+ tcg_out_opc_reg(s, OPC_WSBH, TCG_TMP1, 0, MIPS_BE ? lo : hi);
376
+ tcg_out_opc_sa(s, OPC_ROTR, TCG_TMP0, TCG_TMP0, 16);
377
+ tcg_out_opc_sa(s, OPC_ROTR, TCG_TMP1, TCG_TMP1, 16);
378
+ hi = MIPS_BE ? TCG_TMP0 : TCG_TMP1;
379
+ lo = MIPS_BE ? TCG_TMP1 : TCG_TMP0;
380
+ } else {
381
+ tcg_out_bswap32(s, TCG_TMP3, MIPS_BE ? lo : hi, 0);
382
+ tcg_out_opc_imm(s, sw1, TCG_TMP3, base, 0 + 0);
383
+ tcg_out_opc_imm(s, sw2, TCG_TMP3, base, 0 + 3);
384
+ tcg_out_bswap32(s, TCG_TMP3, MIPS_BE ? hi : lo, 0);
385
+ tcg_out_opc_imm(s, sw1, TCG_TMP3, base, 4 + 0);
386
+ tcg_out_opc_imm(s, sw2, TCG_TMP3, base, 4 + 3);
387
+ break;
388
+ }
389
+ /* fall through */
390
+ case MO_64:
391
+ if (TCG_TARGET_REG_BITS == 64) {
392
+ tcg_out_opc_imm(s, sd1, lo, base, 0);
393
+ tcg_out_opc_imm(s, sd2, lo, base, 7);
394
+ } else {
395
+ tcg_out_opc_imm(s, sw1, MIPS_BE ? hi : lo, base, 0 + 0);
396
+ tcg_out_opc_imm(s, sw2, MIPS_BE ? hi : lo, base, 0 + 3);
397
+ tcg_out_opc_imm(s, sw1, MIPS_BE ? lo : hi, base, 4 + 0);
398
+ tcg_out_opc_imm(s, sw2, MIPS_BE ? lo : hi, base, 4 + 3);
399
+ }
400
+ break;
401
+
402
+ default:
403
+ tcg_abort();
404
+ }
405
+}
406
static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
407
{
408
TCGReg addr_regl, addr_regh __attribute__((unused));
409
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
410
MemOp opc;
411
#if defined(CONFIG_SOFTMMU)
412
tcg_insn_unit *label_ptr[2];
413
+#else
414
+ unsigned a_bits, s_bits;
415
#endif
416
TCGReg base = TCG_REG_A0;
417
418
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
419
data_regl, data_regh, addr_regl, addr_regh,
420
s->code_ptr, label_ptr);
421
#else
422
- base = TCG_REG_A0;
423
if (TCG_TARGET_REG_BITS > TARGET_LONG_BITS) {
424
tcg_out_ext32u(s, base, addr_regl);
425
addr_regl = base;
426
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
427
} else {
428
tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_GUEST_BASE_REG, addr_regl);
429
}
430
- tcg_out_qemu_st_direct(s, data_regl, data_regh, base, opc);
431
+ a_bits = get_alignment_bits(opc);
432
+ s_bits = opc & MO_SIZE;
433
+ /*
434
+ * R6 removes the left/right instructions but requires the
435
+ * system to support misaligned memory accesses.
436
+ */
437
+ if (use_mips32r6_instructions) {
438
+ if (a_bits) {
439
+ tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
440
+ }
441
+ tcg_out_qemu_st_direct(s, data_regl, data_regh, base, opc);
442
+ } else {
443
+ if (a_bits && a_bits != s_bits) {
444
+ tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
445
+ }
446
+ if (a_bits >= s_bits) {
447
+ tcg_out_qemu_st_direct(s, data_regl, data_regh, base, opc);
448
+ } else {
449
+ tcg_out_qemu_st_unalign(s, data_regl, data_regh, base, opc);
450
+ }
451
+ }
452
#endif
453
}
454
455
--
456
2.25.1
457
458
diff view generated by jsdifflib
New patch
1
1
We can use the routines just added for user-only to emit
2
unaligned accesses in softmmu mode too.
3
4
Tested-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
5
Reviewed-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
---
9
tcg/mips/tcg-target.c.inc | 91 ++++++++++++++++++++++-----------------
10
1 file changed, 51 insertions(+), 40 deletions(-)
11
12
diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tcg/mips/tcg-target.c.inc
15
+++ b/tcg/mips/tcg-target.c.inc
16
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
17
tcg_insn_unit *label_ptr[2], bool is_load)
18
{
19
MemOp opc = get_memop(oi);
20
- unsigned s_bits = opc & MO_SIZE;
21
unsigned a_bits = get_alignment_bits(opc);
22
+ unsigned s_bits = opc & MO_SIZE;
23
+ unsigned a_mask = (1 << a_bits) - 1;
24
+ unsigned s_mask = (1 << s_bits) - 1;
25
int mem_index = get_mmuidx(oi);
26
int fast_off = TLB_MASK_TABLE_OFS(mem_index);
27
int mask_off = fast_off + offsetof(CPUTLBDescFast, mask);
28
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
29
int add_off = offsetof(CPUTLBEntry, addend);
30
int cmp_off = (is_load ? offsetof(CPUTLBEntry, addr_read)
31
: offsetof(CPUTLBEntry, addr_write));
32
- target_ulong mask;
33
+ target_ulong tlb_mask;
34
35
/* Load tlb_mask[mmu_idx] and tlb_table[mmu_idx]. */
36
tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP0, TCG_AREG0, mask_off);
37
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
38
/* Add the tlb_table pointer, creating the CPUTLBEntry address in TMP3. */
39
tcg_out_opc_reg(s, ALIAS_PADD, TCG_TMP3, TCG_TMP3, TCG_TMP1);
40
41
- /* We don't currently support unaligned accesses.
42
- We could do so with mips32r6. */
43
- if (a_bits < s_bits) {
44
- a_bits = s_bits;
45
- }
46
-
47
- /* Mask the page bits, keeping the alignment bits to compare against. */
48
- mask = (target_ulong)TARGET_PAGE_MASK | ((1 << a_bits) - 1);
49
-
50
/* Load the (low-half) tlb comparator. */
51
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
52
- tcg_out_ld(s, TCG_TYPE_I32, TCG_TMP0, TCG_TMP3, cmp_off + LO_OFF);
53
- tcg_out_movi(s, TCG_TYPE_I32, TCG_TMP1, mask);
54
+ tcg_out_ldst(s, OPC_LW, TCG_TMP0, TCG_TMP3, cmp_off + LO_OFF);
55
} else {
56
tcg_out_ldst(s, (TARGET_LONG_BITS == 64 ? OPC_LD
57
: TCG_TARGET_REG_BITS == 64 ? OPC_LWU : OPC_LW),
58
TCG_TMP0, TCG_TMP3, cmp_off);
59
- tcg_out_movi(s, TCG_TYPE_TL, TCG_TMP1, mask);
60
- /* No second compare is required here;
61
- load the tlb addend for the fast path. */
62
- tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off);
63
}
64
65
/* Zero extend a 32-bit guest address for a 64-bit host. */
66
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
67
tcg_out_ext32u(s, base, addrl);
68
addrl = base;
69
}
70
- tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, addrl);
71
+
72
+ /*
73
+ * Mask the page bits, keeping the alignment bits to compare against.
74
+ * For unaligned accesses, compare against the end of the access to
75
+ * verify that it does not cross a page boundary.
76
+ */
77
+ tlb_mask = (target_ulong)TARGET_PAGE_MASK | a_mask;
78
+ tcg_out_movi(s, TCG_TYPE_I32, TCG_TMP1, tlb_mask);
79
+ if (a_mask >= s_mask) {
80
+ tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, addrl);
81
+ } else {
82
+ tcg_out_opc_imm(s, ALIAS_PADDI, TCG_TMP2, addrl, s_mask - a_mask);
83
+ tcg_out_opc_reg(s, OPC_AND, TCG_TMP1, TCG_TMP1, TCG_TMP2);
84
+ }
85
+
86
+ if (TCG_TARGET_REG_BITS >= TARGET_LONG_BITS) {
87
+ /* Load the tlb addend for the fast path. */
88
+ tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off);
89
+ }
90
91
label_ptr[0] = s->code_ptr;
92
tcg_out_opc_br(s, OPC_BNE, TCG_TMP1, TCG_TMP0);
93
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_load(TCGContext *s, TCGReg base, TCGReg addrl,
94
/* Load and test the high half tlb comparator. */
95
if (TCG_TARGET_REG_BITS < TARGET_LONG_BITS) {
96
/* delay slot */
97
- tcg_out_ld(s, TCG_TYPE_I32, TCG_TMP0, TCG_TMP3, cmp_off + HI_OFF);
98
+ tcg_out_ldst(s, OPC_LW, TCG_TMP0, TCG_TMP3, cmp_off + HI_OFF);
99
100
/* Load the tlb addend for the fast path. */
101
tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off);
102
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_direct(TCGContext *s, TCGReg lo, TCGReg hi,
103
}
104
}
105
106
-static void __attribute__((unused))
107
-tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
108
+static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
109
TCGReg base, MemOp opc, bool is_64)
110
{
111
const MIPSInsn lw1 = MIPS_BE ? OPC_LWL : OPC_LWR;
112
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
113
#if defined(CONFIG_SOFTMMU)
114
tcg_insn_unit *label_ptr[2];
115
#else
116
- unsigned a_bits, s_bits;
117
#endif
118
+ unsigned a_bits, s_bits;
119
TCGReg base = TCG_REG_A0;
120
121
data_regl = *args++;
122
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
123
addr_regh = (TCG_TARGET_REG_BITS < TARGET_LONG_BITS ? *args++ : 0);
124
oi = *args++;
125
opc = get_memop(oi);
126
+ a_bits = get_alignment_bits(opc);
127
+ s_bits = opc & MO_SIZE;
128
129
+ /*
130
+ * R6 removes the left/right instructions but requires the
131
+ * system to support misaligned memory accesses.
132
+ */
133
#if defined(CONFIG_SOFTMMU)
134
tcg_out_tlb_load(s, base, addr_regl, addr_regh, oi, label_ptr, 1);
135
- tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
136
+ if (use_mips32r6_instructions || a_bits >= s_bits) {
137
+ tcg_out_qemu_ld_direct(s, data_regl, data_regh, base, opc, is_64);
138
+ } else {
139
+ tcg_out_qemu_ld_unalign(s, data_regl, data_regh, base, opc, is_64);
140
+ }
141
add_qemu_ldst_label(s, 1, oi,
142
(is_64 ? TCG_TYPE_I64 : TCG_TYPE_I32),
143
data_regl, data_regh, addr_regl, addr_regh,
144
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
145
} else {
146
tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_GUEST_BASE_REG, addr_regl);
147
}
148
- a_bits = get_alignment_bits(opc);
149
- s_bits = opc & MO_SIZE;
150
- /*
151
- * R6 removes the left/right instructions but requires the
152
- * system to support misaligned memory accesses.
153
- */
154
if (use_mips32r6_instructions) {
155
if (a_bits) {
156
tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
157
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, TCGReg lo, TCGReg hi,
158
}
159
}
160
161
-static void __attribute__((unused))
162
-tcg_out_qemu_st_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
163
+static void tcg_out_qemu_st_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
164
TCGReg base, MemOp opc)
165
{
166
const MIPSInsn sw1 = MIPS_BE ? OPC_SWL : OPC_SWR;
167
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
168
MemOp opc;
169
#if defined(CONFIG_SOFTMMU)
170
tcg_insn_unit *label_ptr[2];
171
-#else
172
- unsigned a_bits, s_bits;
173
#endif
174
+ unsigned a_bits, s_bits;
175
TCGReg base = TCG_REG_A0;
176
177
data_regl = *args++;
178
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
179
addr_regh = (TCG_TARGET_REG_BITS < TARGET_LONG_BITS ? *args++ : 0);
180
oi = *args++;
181
opc = get_memop(oi);
182
+ a_bits = get_alignment_bits(opc);
183
+ s_bits = opc & MO_SIZE;
184
185
+ /*
186
+ * R6 removes the left/right instructions but requires the
187
+ * system to support misaligned memory accesses.
188
+ */
189
#if defined(CONFIG_SOFTMMU)
190
tcg_out_tlb_load(s, base, addr_regl, addr_regh, oi, label_ptr, 0);
191
- tcg_out_qemu_st_direct(s, data_regl, data_regh, base, opc);
192
+ if (use_mips32r6_instructions || a_bits >= s_bits) {
193
+ tcg_out_qemu_st_direct(s, data_regl, data_regh, base, opc);
194
+ } else {
195
+ tcg_out_qemu_st_unalign(s, data_regl, data_regh, base, opc);
196
+ }
197
add_qemu_ldst_label(s, 0, oi,
198
(is_64 ? TCG_TYPE_I64 : TCG_TYPE_I32),
199
data_regl, data_regh, addr_regl, addr_regh,
200
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, const TCGArg *args, bool is_64)
201
} else {
202
tcg_out_opc_reg(s, ALIAS_PADD, base, TCG_GUEST_BASE_REG, addr_regl);
203
}
204
- a_bits = get_alignment_bits(opc);
205
- s_bits = opc & MO_SIZE;
206
- /*
207
- * R6 removes the left/right instructions but requires the
208
- * system to support misaligned memory accesses.
209
- */
210
if (use_mips32r6_instructions) {
211
if (a_bits) {
212
tcg_out_test_alignment(s, true, addr_regl, addr_regh, a_bits);
213
--
214
2.25.1
215
216
diff view generated by jsdifflib
New patch
1
When BH is constant, it is constrained to 11 bits for use in MOVCC.
2
For the cases in which we must load the constant BH into a register,
3
we do not need the full logic of tcg_out_movi; we can use the simpler
4
function for emitting a 13 bit constant.
1
5
6
This eliminates the only case in which TCG_REG_T2 was passed to
7
tcg_out_movi, which will shortly become invalid.
8
9
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
10
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
---
12
tcg/sparc/tcg-target.c.inc | 10 +++++++---
13
1 file changed, 7 insertions(+), 3 deletions(-)
14
15
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
16
index XXXXXXX..XXXXXXX 100644
17
--- a/tcg/sparc/tcg-target.c.inc
18
+++ b/tcg/sparc/tcg-target.c.inc
19
@@ -XXX,XX +XXX,XX @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
20
if (use_vis3_instructions && !is_sub) {
21
/* Note that ADDXC doesn't accept immediates. */
22
if (bhconst && bh != 0) {
23
- tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_T2, bh);
24
+ tcg_out_movi_imm13(s, TCG_REG_T2, bh);
25
bh = TCG_REG_T2;
26
}
27
tcg_out_arith(s, rh, ah, bh, ARITH_ADDXC);
28
@@ -XXX,XX +XXX,XX @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
29
     tcg_out_movcc(s, TCG_COND_GEU, MOVCC_XCC, rh, ah, 0);
30
    }
31
} else {
32
- /* Otherwise adjust BH as if there is carry into T2 ... */
33
+ /*
34
+ * Otherwise adjust BH as if there is carry into T2.
35
+ * Note that constant BH is constrained to 11 bits for the MOVCC,
36
+ * so the adjustment fits 12 bits.
37
+ */
38
if (bhconst) {
39
- tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_T2, bh + (is_sub ? -1 : 1));
40
+ tcg_out_movi_imm13(s, TCG_REG_T2, bh + (is_sub ? -1 : 1));
41
} else {
42
tcg_out_arithi(s, TCG_REG_T2, bh, 1,
43
is_sub ? ARITH_SUB : ARITH_ADD);
44
--
45
2.25.1
46
47
diff view generated by jsdifflib
New patch
1
Handle 32-bit constants with a separate function, so that
2
tcg_out_movi_int does not need to recurse. This slightly
3
rearranges the order of tests for small constants, but
4
produces the same output.
1
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
---
9
tcg/sparc/tcg-target.c.inc | 36 +++++++++++++++++++++---------------
10
1 file changed, 21 insertions(+), 15 deletions(-)
11
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tcg/sparc/tcg-target.c.inc
15
+++ b/tcg/sparc/tcg-target.c.inc
16
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_imm13(TCGContext *s, TCGReg ret, int32_t arg)
17
tcg_out_arithi(s, ret, TCG_REG_G0, arg, ARITH_OR);
18
}
19
20
+static void tcg_out_movi_imm32(TCGContext *s, TCGReg ret, int32_t arg)
21
+{
22
+ if (check_fit_i32(arg, 13)) {
23
+ /* A 13-bit constant sign-extended to 64-bits. */
24
+ tcg_out_movi_imm13(s, ret, arg);
25
+ } else {
26
+ /* A 32-bit constant zero-extended to 64 bits. */
27
+ tcg_out_sethi(s, ret, arg);
28
+ if (arg & 0x3ff) {
29
+ tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
30
+ }
31
+ }
32
+}
33
+
34
static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
35
tcg_target_long arg, bool in_prologue)
36
{
37
tcg_target_long hi, lo = (int32_t)arg;
38
tcg_target_long test, lsb;
39
40
- /* Make sure we test 32-bit constants for imm13 properly. */
41
- if (type == TCG_TYPE_I32) {
42
- arg = lo;
43
+ /* A 32-bit constant, or 32-bit zero-extended to 64-bits. */
44
+ if (type == TCG_TYPE_I32 || arg == (uint32_t)arg) {
45
+ tcg_out_movi_imm32(s, ret, arg);
46
+ return;
47
}
48
49
/* A 13-bit constant sign-extended to 64-bits. */
50
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
51
}
52
}
53
54
- /* A 32-bit constant, or 32-bit zero-extended to 64-bits. */
55
- if (type == TCG_TYPE_I32 || arg == (uint32_t)arg) {
56
- tcg_out_sethi(s, ret, arg);
57
- if (arg & 0x3ff) {
58
- tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
59
- }
60
- return;
61
- }
62
-
63
/* A 32-bit constant sign-extended to 64-bits. */
64
if (arg == lo) {
65
tcg_out_sethi(s, ret, ~arg);
66
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
67
/* A 64-bit constant decomposed into 2 32-bit pieces. */
68
if (check_fit_i32(lo, 13)) {
69
hi = (arg - lo) >> 32;
70
- tcg_out_movi(s, TCG_TYPE_I32, ret, hi);
71
+ tcg_out_movi_imm32(s, ret, hi);
72
tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX);
73
tcg_out_arithi(s, ret, ret, lo, ARITH_ADD);
74
} else {
75
hi = arg >> 32;
76
- tcg_out_movi(s, TCG_TYPE_I32, ret, hi);
77
- tcg_out_movi(s, TCG_TYPE_I32, TCG_REG_T2, lo);
78
+ tcg_out_movi_imm32(s, ret, hi);
79
+ tcg_out_movi_imm32(s, TCG_REG_T2, lo);
80
tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX);
81
tcg_out_arith(s, ret, ret, TCG_REG_T2, ARITH_OR);
82
}
83
--
84
2.25.1
85
86
diff view generated by jsdifflib
1
From: Claudio Fontana <cfontana@suse.de>
1
This will allow us to control exactly what scratch register is
2
used for loading the constant.
2
3
3
split up the CpusAccel tcg_cpus into three TCG variants:
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
5
tcg_cpus_rr (single threaded, round robin cpus)
6
tcg_cpus_icount (same as rr, but with instruction counting enabled)
7
tcg_cpus_mttcg (multi-threaded cpus)
8
9
Suggested-by: Richard Henderson <richard.henderson@linaro.org>
10
Signed-off-by: Claudio Fontana <cfontana@suse.de>
11
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
12
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
13
Message-Id: <20201015143217.29337-2-cfontana@suse.de>
14
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
15
---
6
---
16
accel/tcg/tcg-cpus-icount.h | 17 ++
7
tcg/sparc/tcg-target.c.inc | 15 +++++++++------
17
accel/tcg/tcg-cpus-mttcg.h | 21 ++
8
1 file changed, 9 insertions(+), 6 deletions(-)
18
accel/tcg/tcg-cpus-rr.h | 20 ++
19
accel/tcg/tcg-cpus.h | 13 +-
20
accel/tcg/tcg-all.c | 8 +-
21
accel/tcg/tcg-cpus-icount.c | 147 +++++++++++
22
accel/tcg/tcg-cpus-mttcg.c | 117 +++++++++
23
accel/tcg/tcg-cpus-rr.c | 270 ++++++++++++++++++++
24
accel/tcg/tcg-cpus.c | 484 ++----------------------------------
25
softmmu/icount.c | 2 +-
26
accel/tcg/meson.build | 9 +-
27
11 files changed, 646 insertions(+), 462 deletions(-)
28
create mode 100644 accel/tcg/tcg-cpus-icount.h
29
create mode 100644 accel/tcg/tcg-cpus-mttcg.h
30
create mode 100644 accel/tcg/tcg-cpus-rr.h
31
create mode 100644 accel/tcg/tcg-cpus-icount.c
32
create mode 100644 accel/tcg/tcg-cpus-mttcg.c
33
create mode 100644 accel/tcg/tcg-cpus-rr.c
34
9
35
diff --git a/accel/tcg/tcg-cpus-icount.h b/accel/tcg/tcg-cpus-icount.h
10
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
36
new file mode 100644
37
index XXXXXXX..XXXXXXX
38
--- /dev/null
39
+++ b/accel/tcg/tcg-cpus-icount.h
40
@@ -XXX,XX +XXX,XX @@
41
+/*
42
+ * QEMU TCG Single Threaded vCPUs implementation using instruction counting
43
+ *
44
+ * Copyright 2020 SUSE LLC
45
+ *
46
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
47
+ * See the COPYING file in the top-level directory.
48
+ */
49
+
50
+#ifndef TCG_CPUS_ICOUNT_H
51
+#define TCG_CPUS_ICOUNT_H
52
+
53
+void handle_icount_deadline(void);
54
+void prepare_icount_for_run(CPUState *cpu);
55
+void process_icount_data(CPUState *cpu);
56
+
57
+#endif /* TCG_CPUS_ICOUNT_H */
58
diff --git a/accel/tcg/tcg-cpus-mttcg.h b/accel/tcg/tcg-cpus-mttcg.h
59
new file mode 100644
60
index XXXXXXX..XXXXXXX
61
--- /dev/null
62
+++ b/accel/tcg/tcg-cpus-mttcg.h
63
@@ -XXX,XX +XXX,XX @@
64
+/*
65
+ * QEMU TCG Multi Threaded vCPUs implementation
66
+ *
67
+ * Copyright 2020 SUSE LLC
68
+ *
69
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
70
+ * See the COPYING file in the top-level directory.
71
+ */
72
+
73
+#ifndef TCG_CPUS_MTTCG_H
74
+#define TCG_CPUS_MTTCG_H
75
+
76
+/*
77
+ * In the multi-threaded case each vCPU has its own thread. The TLS
78
+ * variable current_cpu can be used deep in the code to find the
79
+ * current CPUState for a given thread.
80
+ */
81
+
82
+void *tcg_cpu_thread_fn(void *arg);
83
+
84
+#endif /* TCG_CPUS_MTTCG_H */
85
diff --git a/accel/tcg/tcg-cpus-rr.h b/accel/tcg/tcg-cpus-rr.h
86
new file mode 100644
87
index XXXXXXX..XXXXXXX
88
--- /dev/null
89
+++ b/accel/tcg/tcg-cpus-rr.h
90
@@ -XXX,XX +XXX,XX @@
91
+/*
92
+ * QEMU TCG Single Threaded vCPUs implementation
93
+ *
94
+ * Copyright 2020 SUSE LLC
95
+ *
96
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
97
+ * See the COPYING file in the top-level directory.
98
+ */
99
+
100
+#ifndef TCG_CPUS_RR_H
101
+#define TCG_CPUS_RR_H
102
+
103
+#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
104
+
105
+/* Kick all RR vCPUs. */
106
+void qemu_cpu_kick_rr_cpus(CPUState *unused);
107
+
108
+void *tcg_rr_cpu_thread_fn(void *arg);
109
+
110
+#endif /* TCG_CPUS_RR_H */
111
diff --git a/accel/tcg/tcg-cpus.h b/accel/tcg/tcg-cpus.h
112
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
113
--- a/accel/tcg/tcg-cpus.h
12
--- a/tcg/sparc/tcg-target.c.inc
114
+++ b/accel/tcg/tcg-cpus.h
13
+++ b/tcg/sparc/tcg-target.c.inc
115
@@ -XXX,XX +XXX,XX @@
14
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_imm32(TCGContext *s, TCGReg ret, int32_t arg)
116
/*
117
- * Accelerator CPUS Interface
118
+ * QEMU TCG vCPU common functionality
119
+ *
120
+ * Functionality common to all TCG vcpu variants: mttcg, rr and icount.
121
*
122
* Copyright 2020 SUSE LLC
123
*
124
@@ -XXX,XX +XXX,XX @@
125
126
#include "sysemu/cpus.h"
127
128
-extern const CpusAccel tcg_cpus;
129
+extern const CpusAccel tcg_cpus_mttcg;
130
+extern const CpusAccel tcg_cpus_icount;
131
+extern const CpusAccel tcg_cpus_rr;
132
+
133
+void tcg_start_vcpu_thread(CPUState *cpu);
134
+void qemu_tcg_destroy_vcpu(CPUState *cpu);
135
+int tcg_cpu_exec(CPUState *cpu);
136
+void tcg_handle_interrupt(CPUState *cpu, int mask);
137
138
#endif /* TCG_CPUS_H */
139
diff --git a/accel/tcg/tcg-all.c b/accel/tcg/tcg-all.c
140
index XXXXXXX..XXXXXXX 100644
141
--- a/accel/tcg/tcg-all.c
142
+++ b/accel/tcg/tcg-all.c
143
@@ -XXX,XX +XXX,XX @@ static int tcg_init(MachineState *ms)
144
145
tcg_exec_init(s->tb_size * 1024 * 1024);
146
mttcg_enabled = s->mttcg_enabled;
147
- cpus_register_accel(&tcg_cpus);
148
149
+ if (mttcg_enabled) {
150
+ cpus_register_accel(&tcg_cpus_mttcg);
151
+ } else if (icount_enabled()) {
152
+ cpus_register_accel(&tcg_cpus_icount);
153
+ } else {
154
+ cpus_register_accel(&tcg_cpus_rr);
155
+ }
156
return 0;
157
}
15
}
158
16
159
diff --git a/accel/tcg/tcg-cpus-icount.c b/accel/tcg/tcg-cpus-icount.c
17
static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
160
new file mode 100644
18
- tcg_target_long arg, bool in_prologue)
161
index XXXXXXX..XXXXXXX
19
+ tcg_target_long arg, bool in_prologue,
162
--- /dev/null
20
+ TCGReg scratch)
163
+++ b/accel/tcg/tcg-cpus-icount.c
164
@@ -XXX,XX +XXX,XX @@
165
+/*
166
+ * QEMU TCG Single Threaded vCPUs implementation using instruction counting
167
+ *
168
+ * Copyright (c) 2003-2008 Fabrice Bellard
169
+ * Copyright (c) 2014 Red Hat Inc.
170
+ *
171
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
172
+ * of this software and associated documentation files (the "Software"), to deal
173
+ * in the Software without restriction, including without limitation the rights
174
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
175
+ * copies of the Software, and to permit persons to whom the Software is
176
+ * furnished to do so, subject to the following conditions:
177
+ *
178
+ * The above copyright notice and this permission notice shall be included in
179
+ * all copies or substantial portions of the Software.
180
+ *
181
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
182
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
183
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
184
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
185
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
186
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
187
+ * THE SOFTWARE.
188
+ */
189
+
190
+#include "qemu/osdep.h"
191
+#include "qemu-common.h"
192
+#include "sysemu/tcg.h"
193
+#include "sysemu/replay.h"
194
+#include "qemu/main-loop.h"
195
+#include "qemu/guest-random.h"
196
+#include "exec/exec-all.h"
197
+#include "hw/boards.h"
198
+
199
+#include "tcg-cpus.h"
200
+#include "tcg-cpus-icount.h"
201
+#include "tcg-cpus-rr.h"
202
+
203
+static int64_t tcg_get_icount_limit(void)
204
+{
205
+ int64_t deadline;
206
+
207
+ if (replay_mode != REPLAY_MODE_PLAY) {
208
+ /*
209
+ * Include all the timers, because they may need an attention.
210
+ * Too long CPU execution may create unnecessary delay in UI.
211
+ */
212
+ deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
213
+ QEMU_TIMER_ATTR_ALL);
214
+ /* Check realtime timers, because they help with input processing */
215
+ deadline = qemu_soonest_timeout(deadline,
216
+ qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME,
217
+ QEMU_TIMER_ATTR_ALL));
218
+
219
+ /*
220
+ * Maintain prior (possibly buggy) behaviour where if no deadline
221
+ * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
222
+ * INT32_MAX nanoseconds ahead, we still use INT32_MAX
223
+ * nanoseconds.
224
+ */
225
+ if ((deadline < 0) || (deadline > INT32_MAX)) {
226
+ deadline = INT32_MAX;
227
+ }
228
+
229
+ return icount_round(deadline);
230
+ } else {
231
+ return replay_get_instructions();
232
+ }
233
+}
234
+
235
+static void notify_aio_contexts(void)
236
+{
237
+ /* Wake up other AioContexts. */
238
+ qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
239
+ qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
240
+}
241
+
242
+void handle_icount_deadline(void)
243
+{
244
+ assert(qemu_in_vcpu_thread());
245
+ int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
246
+ QEMU_TIMER_ATTR_ALL);
247
+
248
+ if (deadline == 0) {
249
+ notify_aio_contexts();
250
+ }
251
+}
252
+
253
+void prepare_icount_for_run(CPUState *cpu)
254
+{
255
+ int insns_left;
256
+
257
+ /*
258
+ * These should always be cleared by process_icount_data after
259
+ * each vCPU execution. However u16.high can be raised
260
+ * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
261
+ */
262
+ g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
263
+ g_assert(cpu->icount_extra == 0);
264
+
265
+ cpu->icount_budget = tcg_get_icount_limit();
266
+ insns_left = MIN(0xffff, cpu->icount_budget);
267
+ cpu_neg(cpu)->icount_decr.u16.low = insns_left;
268
+ cpu->icount_extra = cpu->icount_budget - insns_left;
269
+
270
+ replay_mutex_lock();
271
+
272
+ if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
273
+ notify_aio_contexts();
274
+ }
275
+}
276
+
277
+void process_icount_data(CPUState *cpu)
278
+{
279
+ /* Account for executed instructions */
280
+ icount_update(cpu);
281
+
282
+ /* Reset the counters */
283
+ cpu_neg(cpu)->icount_decr.u16.low = 0;
284
+ cpu->icount_extra = 0;
285
+ cpu->icount_budget = 0;
286
+
287
+ replay_account_executed_instructions();
288
+
289
+ replay_mutex_unlock();
290
+}
291
+
292
+static void icount_handle_interrupt(CPUState *cpu, int mask)
293
+{
294
+ int old_mask = cpu->interrupt_request;
295
+
296
+ tcg_handle_interrupt(cpu, mask);
297
+ if (qemu_cpu_is_self(cpu) &&
298
+ !cpu->can_do_io
299
+ && (mask & ~old_mask) != 0) {
300
+ cpu_abort(cpu, "Raised interrupt while not in I/O function");
301
+ }
302
+}
303
+
304
+const CpusAccel tcg_cpus_icount = {
305
+ .create_vcpu_thread = tcg_start_vcpu_thread,
306
+ .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
307
+
308
+ .handle_interrupt = icount_handle_interrupt,
309
+ .get_virtual_clock = icount_get,
310
+ .get_elapsed_ticks = icount_get,
311
+};
312
diff --git a/accel/tcg/tcg-cpus-mttcg.c b/accel/tcg/tcg-cpus-mttcg.c
313
new file mode 100644
314
index XXXXXXX..XXXXXXX
315
--- /dev/null
316
+++ b/accel/tcg/tcg-cpus-mttcg.c
317
@@ -XXX,XX +XXX,XX @@
318
+/*
319
+ * QEMU TCG Multi Threaded vCPUs implementation
320
+ *
321
+ * Copyright (c) 2003-2008 Fabrice Bellard
322
+ * Copyright (c) 2014 Red Hat Inc.
323
+ *
324
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
325
+ * of this software and associated documentation files (the "Software"), to deal
326
+ * in the Software without restriction, including without limitation the rights
327
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
328
+ * copies of the Software, and to permit persons to whom the Software is
329
+ * furnished to do so, subject to the following conditions:
330
+ *
331
+ * The above copyright notice and this permission notice shall be included in
332
+ * all copies or substantial portions of the Software.
333
+ *
334
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
335
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
336
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
337
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
338
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
339
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
340
+ * THE SOFTWARE.
341
+ */
342
+
343
+#include "qemu/osdep.h"
344
+#include "qemu-common.h"
345
+#include "sysemu/tcg.h"
346
+#include "sysemu/replay.h"
347
+#include "qemu/main-loop.h"
348
+#include "qemu/guest-random.h"
349
+#include "exec/exec-all.h"
350
+#include "hw/boards.h"
351
+
352
+#include "tcg-cpus.h"
353
+#include "tcg-cpus-mttcg.h"
354
+
355
+/*
356
+ * In the multi-threaded case each vCPU has its own thread. The TLS
357
+ * variable current_cpu can be used deep in the code to find the
358
+ * current CPUState for a given thread.
359
+ */
360
+
361
+void *tcg_cpu_thread_fn(void *arg)
362
+{
363
+ CPUState *cpu = arg;
364
+
365
+ assert(tcg_enabled());
366
+ g_assert(!icount_enabled());
367
+
368
+ rcu_register_thread();
369
+ tcg_register_thread();
370
+
371
+ qemu_mutex_lock_iothread();
372
+ qemu_thread_get_self(cpu->thread);
373
+
374
+ cpu->thread_id = qemu_get_thread_id();
375
+ cpu->can_do_io = 1;
376
+ current_cpu = cpu;
377
+ cpu_thread_signal_created(cpu);
378
+ qemu_guest_random_seed_thread_part2(cpu->random_seed);
379
+
380
+ /* process any pending work */
381
+ cpu->exit_request = 1;
382
+
383
+ do {
384
+ if (cpu_can_run(cpu)) {
385
+ int r;
386
+ qemu_mutex_unlock_iothread();
387
+ r = tcg_cpu_exec(cpu);
388
+ qemu_mutex_lock_iothread();
389
+ switch (r) {
390
+ case EXCP_DEBUG:
391
+ cpu_handle_guest_debug(cpu);
392
+ break;
393
+ case EXCP_HALTED:
394
+ /*
395
+ * during start-up the vCPU is reset and the thread is
396
+ * kicked several times. If we don't ensure we go back
397
+ * to sleep in the halted state we won't cleanly
398
+ * start-up when the vCPU is enabled.
399
+ *
400
+ * cpu->halted should ensure we sleep in wait_io_event
401
+ */
402
+ g_assert(cpu->halted);
403
+ break;
404
+ case EXCP_ATOMIC:
405
+ qemu_mutex_unlock_iothread();
406
+ cpu_exec_step_atomic(cpu);
407
+ qemu_mutex_lock_iothread();
408
+ default:
409
+ /* Ignore everything else? */
410
+ break;
411
+ }
412
+ }
413
+
414
+ qatomic_mb_set(&cpu->exit_request, 0);
415
+ qemu_wait_io_event(cpu);
416
+ } while (!cpu->unplug || cpu_can_run(cpu));
417
+
418
+ qemu_tcg_destroy_vcpu(cpu);
419
+ qemu_mutex_unlock_iothread();
420
+ rcu_unregister_thread();
421
+ return NULL;
422
+}
423
+
424
+static void mttcg_kick_vcpu_thread(CPUState *cpu)
425
+{
426
+ cpu_exit(cpu);
427
+}
428
+
429
+const CpusAccel tcg_cpus_mttcg = {
430
+ .create_vcpu_thread = tcg_start_vcpu_thread,
431
+ .kick_vcpu_thread = mttcg_kick_vcpu_thread,
432
+
433
+ .handle_interrupt = tcg_handle_interrupt,
434
+};
435
diff --git a/accel/tcg/tcg-cpus-rr.c b/accel/tcg/tcg-cpus-rr.c
436
new file mode 100644
437
index XXXXXXX..XXXXXXX
438
--- /dev/null
439
+++ b/accel/tcg/tcg-cpus-rr.c
440
@@ -XXX,XX +XXX,XX @@
441
+/*
442
+ * QEMU TCG Single Threaded vCPUs implementation
443
+ *
444
+ * Copyright (c) 2003-2008 Fabrice Bellard
445
+ * Copyright (c) 2014 Red Hat Inc.
446
+ *
447
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
448
+ * of this software and associated documentation files (the "Software"), to deal
449
+ * in the Software without restriction, including without limitation the rights
450
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
451
+ * copies of the Software, and to permit persons to whom the Software is
452
+ * furnished to do so, subject to the following conditions:
453
+ *
454
+ * The above copyright notice and this permission notice shall be included in
455
+ * all copies or substantial portions of the Software.
456
+ *
457
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
458
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
459
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
460
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
461
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
462
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
463
+ * THE SOFTWARE.
464
+ */
465
+
466
+#include "qemu/osdep.h"
467
+#include "qemu-common.h"
468
+#include "sysemu/tcg.h"
469
+#include "sysemu/replay.h"
470
+#include "qemu/main-loop.h"
471
+#include "qemu/guest-random.h"
472
+#include "exec/exec-all.h"
473
+#include "hw/boards.h"
474
+
475
+#include "tcg-cpus.h"
476
+#include "tcg-cpus-rr.h"
477
+#include "tcg-cpus-icount.h"
478
+
479
+/* Kick all RR vCPUs */
480
+void qemu_cpu_kick_rr_cpus(CPUState *unused)
481
+{
482
+ CPUState *cpu;
483
+
484
+ CPU_FOREACH(cpu) {
485
+ cpu_exit(cpu);
486
+ };
487
+}
488
+
489
+/*
490
+ * TCG vCPU kick timer
491
+ *
492
+ * The kick timer is responsible for moving single threaded vCPU
493
+ * emulation on to the next vCPU. If more than one vCPU is running a
494
+ * timer event with force a cpu->exit so the next vCPU can get
495
+ * scheduled.
496
+ *
497
+ * The timer is removed if all vCPUs are idle and restarted again once
498
+ * idleness is complete.
499
+ */
500
+
501
+static QEMUTimer *tcg_kick_vcpu_timer;
502
+static CPUState *tcg_current_rr_cpu;
503
+
504
+#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
505
+
506
+static inline int64_t qemu_tcg_next_kick(void)
507
+{
508
+ return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
509
+}
510
+
511
+/* Kick the currently round-robin scheduled vCPU to next */
512
+static void qemu_cpu_kick_rr_next_cpu(void)
513
+{
514
+ CPUState *cpu;
515
+ do {
516
+ cpu = qatomic_mb_read(&tcg_current_rr_cpu);
517
+ if (cpu) {
518
+ cpu_exit(cpu);
519
+ }
520
+ } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
521
+}
522
+
523
+static void kick_tcg_thread(void *opaque)
524
+{
525
+ timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
526
+ qemu_cpu_kick_rr_next_cpu();
527
+}
528
+
529
+static void start_tcg_kick_timer(void)
530
+{
531
+ if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
532
+ tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
533
+ kick_tcg_thread, NULL);
534
+ }
535
+ if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
536
+ timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
537
+ }
538
+}
539
+
540
+static void stop_tcg_kick_timer(void)
541
+{
542
+ if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
543
+ timer_del(tcg_kick_vcpu_timer);
544
+ }
545
+}
546
+
547
+static void qemu_tcg_rr_wait_io_event(void)
548
+{
549
+ CPUState *cpu;
550
+
551
+ while (all_cpu_threads_idle()) {
552
+ stop_tcg_kick_timer();
553
+ qemu_cond_wait_iothread(first_cpu->halt_cond);
554
+ }
555
+
556
+ start_tcg_kick_timer();
557
+
558
+ CPU_FOREACH(cpu) {
559
+ qemu_wait_io_event_common(cpu);
560
+ }
561
+}
562
+
563
+/*
564
+ * Destroy any remaining vCPUs which have been unplugged and have
565
+ * finished running
566
+ */
567
+static void deal_with_unplugged_cpus(void)
568
+{
569
+ CPUState *cpu;
570
+
571
+ CPU_FOREACH(cpu) {
572
+ if (cpu->unplug && !cpu_can_run(cpu)) {
573
+ qemu_tcg_destroy_vcpu(cpu);
574
+ break;
575
+ }
576
+ }
577
+}
578
+
579
+/*
580
+ * In the single-threaded case each vCPU is simulated in turn. If
581
+ * there is more than a single vCPU we create a simple timer to kick
582
+ * the vCPU and ensure we don't get stuck in a tight loop in one vCPU.
583
+ * This is done explicitly rather than relying on side-effects
584
+ * elsewhere.
585
+ */
586
+
587
+void *tcg_rr_cpu_thread_fn(void *arg)
588
+{
589
+ CPUState *cpu = arg;
590
+
591
+ assert(tcg_enabled());
592
+ rcu_register_thread();
593
+ tcg_register_thread();
594
+
595
+ qemu_mutex_lock_iothread();
596
+ qemu_thread_get_self(cpu->thread);
597
+
598
+ cpu->thread_id = qemu_get_thread_id();
599
+ cpu->can_do_io = 1;
600
+ cpu_thread_signal_created(cpu);
601
+ qemu_guest_random_seed_thread_part2(cpu->random_seed);
602
+
603
+ /* wait for initial kick-off after machine start */
604
+ while (first_cpu->stopped) {
605
+ qemu_cond_wait_iothread(first_cpu->halt_cond);
606
+
607
+ /* process any pending work */
608
+ CPU_FOREACH(cpu) {
609
+ current_cpu = cpu;
610
+ qemu_wait_io_event_common(cpu);
611
+ }
612
+ }
613
+
614
+ start_tcg_kick_timer();
615
+
616
+ cpu = first_cpu;
617
+
618
+ /* process any pending work */
619
+ cpu->exit_request = 1;
620
+
621
+ while (1) {
622
+ qemu_mutex_unlock_iothread();
623
+ replay_mutex_lock();
624
+ qemu_mutex_lock_iothread();
625
+
626
+ if (icount_enabled()) {
627
+ /* Account partial waits to QEMU_CLOCK_VIRTUAL. */
628
+ icount_account_warp_timer();
629
+ /*
630
+ * Run the timers here. This is much more efficient than
631
+ * waking up the I/O thread and waiting for completion.
632
+ */
633
+ handle_icount_deadline();
634
+ }
635
+
636
+ replay_mutex_unlock();
637
+
638
+ if (!cpu) {
639
+ cpu = first_cpu;
640
+ }
641
+
642
+ while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
643
+
644
+ qatomic_mb_set(&tcg_current_rr_cpu, cpu);
645
+ current_cpu = cpu;
646
+
647
+ qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
648
+ (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
649
+
650
+ if (cpu_can_run(cpu)) {
651
+ int r;
652
+
653
+ qemu_mutex_unlock_iothread();
654
+ if (icount_enabled()) {
655
+ prepare_icount_for_run(cpu);
656
+ }
657
+ r = tcg_cpu_exec(cpu);
658
+ if (icount_enabled()) {
659
+ process_icount_data(cpu);
660
+ }
661
+ qemu_mutex_lock_iothread();
662
+
663
+ if (r == EXCP_DEBUG) {
664
+ cpu_handle_guest_debug(cpu);
665
+ break;
666
+ } else if (r == EXCP_ATOMIC) {
667
+ qemu_mutex_unlock_iothread();
668
+ cpu_exec_step_atomic(cpu);
669
+ qemu_mutex_lock_iothread();
670
+ break;
671
+ }
672
+ } else if (cpu->stop) {
673
+ if (cpu->unplug) {
674
+ cpu = CPU_NEXT(cpu);
675
+ }
676
+ break;
677
+ }
678
+
679
+ cpu = CPU_NEXT(cpu);
680
+ } /* while (cpu && !cpu->exit_request).. */
681
+
682
+ /* Does not need qatomic_mb_set because a spurious wakeup is okay. */
683
+ qatomic_set(&tcg_current_rr_cpu, NULL);
684
+
685
+ if (cpu && cpu->exit_request) {
686
+ qatomic_mb_set(&cpu->exit_request, 0);
687
+ }
688
+
689
+ if (icount_enabled() && all_cpu_threads_idle()) {
690
+ /*
691
+ * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
692
+ * in the main_loop, wake it up in order to start the warp timer.
693
+ */
694
+ qemu_notify_event();
695
+ }
696
+
697
+ qemu_tcg_rr_wait_io_event();
698
+ deal_with_unplugged_cpus();
699
+ }
700
+
701
+ rcu_unregister_thread();
702
+ return NULL;
703
+}
704
+
705
+const CpusAccel tcg_cpus_rr = {
706
+ .create_vcpu_thread = tcg_start_vcpu_thread,
707
+ .kick_vcpu_thread = qemu_cpu_kick_rr_cpus,
708
+
709
+ .handle_interrupt = tcg_handle_interrupt,
710
+};
711
diff --git a/accel/tcg/tcg-cpus.c b/accel/tcg/tcg-cpus.c
712
index XXXXXXX..XXXXXXX 100644
713
--- a/accel/tcg/tcg-cpus.c
714
+++ b/accel/tcg/tcg-cpus.c
715
@@ -XXX,XX +XXX,XX @@
716
/*
717
- * QEMU System Emulator
718
+ * QEMU TCG vCPU common functionality
719
+ *
720
+ * Functionality common to all TCG vCPU variants: mttcg, rr and icount.
721
*
722
* Copyright (c) 2003-2008 Fabrice Bellard
723
* Copyright (c) 2014 Red Hat Inc.
724
@@ -XXX,XX +XXX,XX @@
725
#include "hw/boards.h"
726
727
#include "tcg-cpus.h"
728
+#include "tcg-cpus-mttcg.h"
729
+#include "tcg-cpus-rr.h"
730
731
-/* Kick all RR vCPUs */
732
-static void qemu_cpu_kick_rr_cpus(void)
733
-{
734
- CPUState *cpu;
735
+/* common functionality among all TCG variants */
736
737
- CPU_FOREACH(cpu) {
738
- cpu_exit(cpu);
739
- };
740
-}
741
-
742
-static void tcg_kick_vcpu_thread(CPUState *cpu)
743
-{
744
- if (qemu_tcg_mttcg_enabled()) {
745
- cpu_exit(cpu);
746
- } else {
747
- qemu_cpu_kick_rr_cpus();
748
- }
749
-}
750
-
751
-/*
752
- * TCG vCPU kick timer
753
- *
754
- * The kick timer is responsible for moving single threaded vCPU
755
- * emulation on to the next vCPU. If more than one vCPU is running a
756
- * timer event with force a cpu->exit so the next vCPU can get
757
- * scheduled.
758
- *
759
- * The timer is removed if all vCPUs are idle and restarted again once
760
- * idleness is complete.
761
- */
762
-
763
-static QEMUTimer *tcg_kick_vcpu_timer;
764
-static CPUState *tcg_current_rr_cpu;
765
-
766
-#define TCG_KICK_PERIOD (NANOSECONDS_PER_SECOND / 10)
767
-
768
-static inline int64_t qemu_tcg_next_kick(void)
769
-{
770
- return qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + TCG_KICK_PERIOD;
771
-}
772
-
773
-/* Kick the currently round-robin scheduled vCPU to next */
774
-static void qemu_cpu_kick_rr_next_cpu(void)
775
-{
776
- CPUState *cpu;
777
- do {
778
- cpu = qatomic_mb_read(&tcg_current_rr_cpu);
779
- if (cpu) {
780
- cpu_exit(cpu);
781
- }
782
- } while (cpu != qatomic_mb_read(&tcg_current_rr_cpu));
783
-}
784
-
785
-static void kick_tcg_thread(void *opaque)
786
-{
787
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
788
- qemu_cpu_kick_rr_next_cpu();
789
-}
790
-
791
-static void start_tcg_kick_timer(void)
792
-{
793
- assert(!mttcg_enabled);
794
- if (!tcg_kick_vcpu_timer && CPU_NEXT(first_cpu)) {
795
- tcg_kick_vcpu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
796
- kick_tcg_thread, NULL);
797
- }
798
- if (tcg_kick_vcpu_timer && !timer_pending(tcg_kick_vcpu_timer)) {
799
- timer_mod(tcg_kick_vcpu_timer, qemu_tcg_next_kick());
800
- }
801
-}
802
-
803
-static void stop_tcg_kick_timer(void)
804
-{
805
- assert(!mttcg_enabled);
806
- if (tcg_kick_vcpu_timer && timer_pending(tcg_kick_vcpu_timer)) {
807
- timer_del(tcg_kick_vcpu_timer);
808
- }
809
-}
810
-
811
-static void qemu_tcg_destroy_vcpu(CPUState *cpu)
812
-{
813
-}
814
-
815
-static void qemu_tcg_rr_wait_io_event(void)
816
-{
817
- CPUState *cpu;
818
-
819
- while (all_cpu_threads_idle()) {
820
- stop_tcg_kick_timer();
821
- qemu_cond_wait_iothread(first_cpu->halt_cond);
822
- }
823
-
824
- start_tcg_kick_timer();
825
-
826
- CPU_FOREACH(cpu) {
827
- qemu_wait_io_event_common(cpu);
828
- }
829
-}
830
-
831
-static int64_t tcg_get_icount_limit(void)
832
-{
833
- int64_t deadline;
834
-
835
- if (replay_mode != REPLAY_MODE_PLAY) {
836
- /*
837
- * Include all the timers, because they may need an attention.
838
- * Too long CPU execution may create unnecessary delay in UI.
839
- */
840
- deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
841
- QEMU_TIMER_ATTR_ALL);
842
- /* Check realtime timers, because they help with input processing */
843
- deadline = qemu_soonest_timeout(deadline,
844
- qemu_clock_deadline_ns_all(QEMU_CLOCK_REALTIME,
845
- QEMU_TIMER_ATTR_ALL));
846
-
847
- /*
848
- * Maintain prior (possibly buggy) behaviour where if no deadline
849
- * was set (as there is no QEMU_CLOCK_VIRTUAL timer) or it is more than
850
- * INT32_MAX nanoseconds ahead, we still use INT32_MAX
851
- * nanoseconds.
852
- */
853
- if ((deadline < 0) || (deadline > INT32_MAX)) {
854
- deadline = INT32_MAX;
855
- }
856
-
857
- return icount_round(deadline);
858
- } else {
859
- return replay_get_instructions();
860
- }
861
-}
862
-
863
-static void notify_aio_contexts(void)
864
-{
865
- /* Wake up other AioContexts. */
866
- qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
867
- qemu_clock_run_timers(QEMU_CLOCK_VIRTUAL);
868
-}
869
-
870
-static void handle_icount_deadline(void)
871
-{
872
- assert(qemu_in_vcpu_thread());
873
- if (icount_enabled()) {
874
- int64_t deadline = qemu_clock_deadline_ns_all(QEMU_CLOCK_VIRTUAL,
875
- QEMU_TIMER_ATTR_ALL);
876
-
877
- if (deadline == 0) {
878
- notify_aio_contexts();
879
- }
880
- }
881
-}
882
-
883
-static void prepare_icount_for_run(CPUState *cpu)
884
-{
885
- if (icount_enabled()) {
886
- int insns_left;
887
-
888
- /*
889
- * These should always be cleared by process_icount_data after
890
- * each vCPU execution. However u16.high can be raised
891
- * asynchronously by cpu_exit/cpu_interrupt/tcg_handle_interrupt
892
- */
893
- g_assert(cpu_neg(cpu)->icount_decr.u16.low == 0);
894
- g_assert(cpu->icount_extra == 0);
895
-
896
- cpu->icount_budget = tcg_get_icount_limit();
897
- insns_left = MIN(0xffff, cpu->icount_budget);
898
- cpu_neg(cpu)->icount_decr.u16.low = insns_left;
899
- cpu->icount_extra = cpu->icount_budget - insns_left;
900
-
901
- replay_mutex_lock();
902
-
903
- if (cpu->icount_budget == 0 && replay_has_checkpoint()) {
904
- notify_aio_contexts();
905
- }
906
- }
907
-}
908
-
909
-static void process_icount_data(CPUState *cpu)
910
-{
911
- if (icount_enabled()) {
912
- /* Account for executed instructions */
913
- icount_update(cpu);
914
-
915
- /* Reset the counters */
916
- cpu_neg(cpu)->icount_decr.u16.low = 0;
917
- cpu->icount_extra = 0;
918
- cpu->icount_budget = 0;
919
-
920
- replay_account_executed_instructions();
921
-
922
- replay_mutex_unlock();
923
- }
924
-}
925
-
926
-static int tcg_cpu_exec(CPUState *cpu)
927
-{
928
- int ret;
929
-#ifdef CONFIG_PROFILER
930
- int64_t ti;
931
-#endif
932
-
933
- assert(tcg_enabled());
934
-#ifdef CONFIG_PROFILER
935
- ti = profile_getclock();
936
-#endif
937
- cpu_exec_start(cpu);
938
- ret = cpu_exec(cpu);
939
- cpu_exec_end(cpu);
940
-#ifdef CONFIG_PROFILER
941
- qatomic_set(&tcg_ctx->prof.cpu_exec_time,
942
- tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti);
943
-#endif
944
- return ret;
945
-}
946
-
947
-/*
948
- * Destroy any remaining vCPUs which have been unplugged and have
949
- * finished running
950
- */
951
-static void deal_with_unplugged_cpus(void)
952
-{
953
- CPUState *cpu;
954
-
955
- CPU_FOREACH(cpu) {
956
- if (cpu->unplug && !cpu_can_run(cpu)) {
957
- qemu_tcg_destroy_vcpu(cpu);
958
- cpu_thread_signal_destroyed(cpu);
959
- break;
960
- }
961
- }
962
-}
963
-
964
-/*
965
- * Single-threaded TCG
966
- *
967
- * In the single-threaded case each vCPU is simulated in turn. If
968
- * there is more than a single vCPU we create a simple timer to kick
969
- * the vCPU and ensure we don't get stuck in a tight loop in one vCPU.
970
- * This is done explicitly rather than relying on side-effects
971
- * elsewhere.
972
- */
973
-
974
-static void *tcg_rr_cpu_thread_fn(void *arg)
975
-{
976
- CPUState *cpu = arg;
977
-
978
- assert(tcg_enabled());
979
- rcu_register_thread();
980
- tcg_register_thread();
981
-
982
- qemu_mutex_lock_iothread();
983
- qemu_thread_get_self(cpu->thread);
984
-
985
- cpu->thread_id = qemu_get_thread_id();
986
- cpu->can_do_io = 1;
987
- cpu_thread_signal_created(cpu);
988
- qemu_guest_random_seed_thread_part2(cpu->random_seed);
989
-
990
- /* wait for initial kick-off after machine start */
991
- while (first_cpu->stopped) {
992
- qemu_cond_wait_iothread(first_cpu->halt_cond);
993
-
994
- /* process any pending work */
995
- CPU_FOREACH(cpu) {
996
- current_cpu = cpu;
997
- qemu_wait_io_event_common(cpu);
998
- }
999
- }
1000
-
1001
- start_tcg_kick_timer();
1002
-
1003
- cpu = first_cpu;
1004
-
1005
- /* process any pending work */
1006
- cpu->exit_request = 1;
1007
-
1008
- while (1) {
1009
- qemu_mutex_unlock_iothread();
1010
- replay_mutex_lock();
1011
- qemu_mutex_lock_iothread();
1012
- /* Account partial waits to QEMU_CLOCK_VIRTUAL. */
1013
- icount_account_warp_timer();
1014
-
1015
- /*
1016
- * Run the timers here. This is much more efficient than
1017
- * waking up the I/O thread and waiting for completion.
1018
- */
1019
- handle_icount_deadline();
1020
-
1021
- replay_mutex_unlock();
1022
-
1023
- if (!cpu) {
1024
- cpu = first_cpu;
1025
- }
1026
-
1027
- while (cpu && cpu_work_list_empty(cpu) && !cpu->exit_request) {
1028
-
1029
- qatomic_mb_set(&tcg_current_rr_cpu, cpu);
1030
- current_cpu = cpu;
1031
-
1032
- qemu_clock_enable(QEMU_CLOCK_VIRTUAL,
1033
- (cpu->singlestep_enabled & SSTEP_NOTIMER) == 0);
1034
-
1035
- if (cpu_can_run(cpu)) {
1036
- int r;
1037
-
1038
- qemu_mutex_unlock_iothread();
1039
- prepare_icount_for_run(cpu);
1040
-
1041
- r = tcg_cpu_exec(cpu);
1042
-
1043
- process_icount_data(cpu);
1044
- qemu_mutex_lock_iothread();
1045
-
1046
- if (r == EXCP_DEBUG) {
1047
- cpu_handle_guest_debug(cpu);
1048
- break;
1049
- } else if (r == EXCP_ATOMIC) {
1050
- qemu_mutex_unlock_iothread();
1051
- cpu_exec_step_atomic(cpu);
1052
- qemu_mutex_lock_iothread();
1053
- break;
1054
- }
1055
- } else if (cpu->stop) {
1056
- if (cpu->unplug) {
1057
- cpu = CPU_NEXT(cpu);
1058
- }
1059
- break;
1060
- }
1061
-
1062
- cpu = CPU_NEXT(cpu);
1063
- } /* while (cpu && !cpu->exit_request).. */
1064
-
1065
- /* Does not need qatomic_mb_set because a spurious wakeup is okay. */
1066
- qatomic_set(&tcg_current_rr_cpu, NULL);
1067
-
1068
- if (cpu && cpu->exit_request) {
1069
- qatomic_mb_set(&cpu->exit_request, 0);
1070
- }
1071
-
1072
- if (icount_enabled() && all_cpu_threads_idle()) {
1073
- /*
1074
- * When all cpus are sleeping (e.g in WFI), to avoid a deadlock
1075
- * in the main_loop, wake it up in order to start the warp timer.
1076
- */
1077
- qemu_notify_event();
1078
- }
1079
-
1080
- qemu_tcg_rr_wait_io_event();
1081
- deal_with_unplugged_cpus();
1082
- }
1083
-
1084
- rcu_unregister_thread();
1085
- return NULL;
1086
-}
1087
-
1088
-/*
1089
- * Multi-threaded TCG
1090
- *
1091
- * In the multi-threaded case each vCPU has its own thread. The TLS
1092
- * variable current_cpu can be used deep in the code to find the
1093
- * current CPUState for a given thread.
1094
- */
1095
-
1096
-static void *tcg_cpu_thread_fn(void *arg)
1097
-{
1098
- CPUState *cpu = arg;
1099
-
1100
- assert(tcg_enabled());
1101
- g_assert(!icount_enabled());
1102
-
1103
- rcu_register_thread();
1104
- tcg_register_thread();
1105
-
1106
- qemu_mutex_lock_iothread();
1107
- qemu_thread_get_self(cpu->thread);
1108
-
1109
- cpu->thread_id = qemu_get_thread_id();
1110
- cpu->can_do_io = 1;
1111
- current_cpu = cpu;
1112
- cpu_thread_signal_created(cpu);
1113
- qemu_guest_random_seed_thread_part2(cpu->random_seed);
1114
-
1115
- /* process any pending work */
1116
- cpu->exit_request = 1;
1117
-
1118
- do {
1119
- if (cpu_can_run(cpu)) {
1120
- int r;
1121
- qemu_mutex_unlock_iothread();
1122
- r = tcg_cpu_exec(cpu);
1123
- qemu_mutex_lock_iothread();
1124
- switch (r) {
1125
- case EXCP_DEBUG:
1126
- cpu_handle_guest_debug(cpu);
1127
- break;
1128
- case EXCP_HALTED:
1129
- /*
1130
- * during start-up the vCPU is reset and the thread is
1131
- * kicked several times. If we don't ensure we go back
1132
- * to sleep in the halted state we won't cleanly
1133
- * start-up when the vCPU is enabled.
1134
- *
1135
- * cpu->halted should ensure we sleep in wait_io_event
1136
- */
1137
- g_assert(cpu->halted);
1138
- break;
1139
- case EXCP_ATOMIC:
1140
- qemu_mutex_unlock_iothread();
1141
- cpu_exec_step_atomic(cpu);
1142
- qemu_mutex_lock_iothread();
1143
- default:
1144
- /* Ignore everything else? */
1145
- break;
1146
- }
1147
- }
1148
-
1149
- qatomic_mb_set(&cpu->exit_request, 0);
1150
- qemu_wait_io_event(cpu);
1151
- } while (!cpu->unplug || cpu_can_run(cpu));
1152
-
1153
- qemu_tcg_destroy_vcpu(cpu);
1154
- cpu_thread_signal_destroyed(cpu);
1155
- qemu_mutex_unlock_iothread();
1156
- rcu_unregister_thread();
1157
- return NULL;
1158
-}
1159
-
1160
-static void tcg_start_vcpu_thread(CPUState *cpu)
1161
+void tcg_start_vcpu_thread(CPUState *cpu)
1162
{
21
{
1163
char thread_name[VCPU_THREAD_NAME_SIZE];
22
tcg_target_long hi, lo = (int32_t)arg;
1164
static QemuCond *single_tcg_halt_cond;
23
tcg_target_long test, lsb;
1165
@@ -XXX,XX +XXX,XX @@ static void tcg_start_vcpu_thread(CPUState *cpu)
24
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
25
} else {
26
hi = arg >> 32;
27
tcg_out_movi_imm32(s, ret, hi);
28
- tcg_out_movi_imm32(s, TCG_REG_T2, lo);
29
+ tcg_out_movi_imm32(s, scratch, lo);
30
tcg_out_arithi(s, ret, ret, 32, SHIFT_SLLX);
31
- tcg_out_arith(s, ret, ret, TCG_REG_T2, ARITH_OR);
32
+ tcg_out_arith(s, ret, ret, scratch, ARITH_OR);
1166
}
33
}
1167
}
34
}
1168
35
1169
-static int64_t tcg_get_virtual_clock(void)
36
static void tcg_out_movi(TCGContext *s, TCGType type,
1170
+void qemu_tcg_destroy_vcpu(CPUState *cpu)
37
TCGReg ret, tcg_target_long arg)
1171
{
38
{
1172
- if (icount_enabled()) {
39
- tcg_out_movi_int(s, type, ret, arg, false);
1173
- return icount_get();
40
+ tcg_debug_assert(ret != TCG_REG_T2);
1174
- }
41
+ tcg_out_movi_int(s, type, ret, arg, false, TCG_REG_T2);
1175
- return cpu_get_clock();
1176
+ cpu_thread_signal_destroyed(cpu);
1177
}
42
}
1178
43
1179
-static int64_t tcg_get_elapsed_ticks(void)
44
static void tcg_out_ldst_rr(TCGContext *s, TCGReg data, TCGReg a1,
1180
+int tcg_cpu_exec(CPUState *cpu)
45
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
1181
{
1182
- if (icount_enabled()) {
1183
- return icount_get();
1184
- }
1185
- return cpu_get_ticks();
1186
+ int ret;
1187
+#ifdef CONFIG_PROFILER
1188
+ int64_t ti;
1189
+#endif
1190
+ assert(tcg_enabled());
1191
+#ifdef CONFIG_PROFILER
1192
+ ti = profile_getclock();
1193
+#endif
1194
+ cpu_exec_start(cpu);
1195
+ ret = cpu_exec(cpu);
1196
+ cpu_exec_end(cpu);
1197
+#ifdef CONFIG_PROFILER
1198
+ qatomic_set(&tcg_ctx->prof.cpu_exec_time,
1199
+ tcg_ctx->prof.cpu_exec_time + profile_getclock() - ti);
1200
+#endif
1201
+ return ret;
1202
}
1203
1204
/* mask must never be zero, except for A20 change call */
1205
-static void tcg_handle_interrupt(CPUState *cpu, int mask)
1206
+void tcg_handle_interrupt(CPUState *cpu, int mask)
1207
{
1208
- int old_mask;
1209
g_assert(qemu_mutex_iothread_locked());
1210
1211
- old_mask = cpu->interrupt_request;
1212
cpu->interrupt_request |= mask;
1213
1214
/*
1215
@@ -XXX,XX +XXX,XX @@ static void tcg_handle_interrupt(CPUState *cpu, int mask)
1216
qemu_cpu_kick(cpu);
1217
} else {
46
} else {
1218
qatomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
47
uintptr_t desti = (uintptr_t)dest;
1219
- if (icount_enabled() &&
48
tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
1220
- !cpu->can_do_io
49
- desti & ~0xfff, in_prologue);
1221
- && (mask & ~old_mask) != 0) {
50
+ desti & ~0xfff, in_prologue, TCG_REG_O7);
1222
- cpu_abort(cpu, "Raised interrupt while not in I/O function");
51
tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL);
1223
- }
1224
}
52
}
1225
}
53
}
1226
-
54
@@ -XXX,XX +XXX,XX @@ static void tcg_target_qemu_prologue(TCGContext *s)
1227
-const CpusAccel tcg_cpus = {
55
1228
- .create_vcpu_thread = tcg_start_vcpu_thread,
56
#ifndef CONFIG_SOFTMMU
1229
- .kick_vcpu_thread = tcg_kick_vcpu_thread,
57
if (guest_base != 0) {
1230
-
58
- tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true);
1231
- .handle_interrupt = tcg_handle_interrupt,
59
+ tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG,
1232
-
60
+ guest_base, true, TCG_REG_T1);
1233
- .get_virtual_clock = tcg_get_virtual_clock,
61
tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
1234
- .get_elapsed_ticks = tcg_get_elapsed_ticks,
1235
-};
1236
diff --git a/softmmu/icount.c b/softmmu/icount.c
1237
index XXXXXXX..XXXXXXX 100644
1238
--- a/softmmu/icount.c
1239
+++ b/softmmu/icount.c
1240
@@ -XXX,XX +XXX,XX @@ void icount_start_warp_timer(void)
1241
1242
void icount_account_warp_timer(void)
1243
{
1244
- if (!icount_enabled() || !icount_sleep) {
1245
+ if (!icount_sleep) {
1246
return;
1247
}
62
}
1248
63
#endif
1249
diff --git a/accel/tcg/meson.build b/accel/tcg/meson.build
1250
index XXXXXXX..XXXXXXX 100644
1251
--- a/accel/tcg/meson.build
1252
+++ b/accel/tcg/meson.build
1253
@@ -XXX,XX +XXX,XX @@ tcg_ss.add(when: 'CONFIG_SOFTMMU', if_false: files('user-exec-stub.c'))
1254
tcg_ss.add(when: 'CONFIG_PLUGIN', if_true: [files('plugin-gen.c'), libdl])
1255
specific_ss.add_all(when: 'CONFIG_TCG', if_true: tcg_ss)
1256
1257
-specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files('tcg-all.c', 'cputlb.c', 'tcg-cpus.c'))
1258
+specific_ss.add(when: ['CONFIG_SOFTMMU', 'CONFIG_TCG'], if_true: files(
1259
+ 'tcg-all.c',
1260
+ 'cputlb.c',
1261
+ 'tcg-cpus.c',
1262
+ 'tcg-cpus-mttcg.c',
1263
+ 'tcg-cpus-icount.c',
1264
+ 'tcg-cpus-rr.c'
1265
+))
1266
--
64
--
1267
2.25.1
65
2.25.1
1268
66
1269
67
diff view generated by jsdifflib
New patch
1
We had code for checking for 13 and 21-bit shifted constants,
2
but we can do better and allow 32-bit shifted constants.
3
This is still 2 insns shorter than the full 64-bit sequence.
1
4
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
---
9
tcg/sparc/tcg-target.c.inc | 12 ++++++------
10
1 file changed, 6 insertions(+), 6 deletions(-)
11
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tcg/sparc/tcg-target.c.inc
15
+++ b/tcg/sparc/tcg-target.c.inc
16
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
17
return;
18
}
19
20
- /* A 21-bit constant, shifted. */
21
+ /* A 32-bit constant, shifted. */
22
lsb = ctz64(arg);
23
test = (tcg_target_long)arg >> lsb;
24
- if (check_fit_tl(test, 13)) {
25
- tcg_out_movi_imm13(s, ret, test);
26
- tcg_out_arithi(s, ret, ret, lsb, SHIFT_SLLX);
27
- return;
28
- } else if (lsb > 10 && test == extract64(test, 0, 21)) {
29
+ if (lsb > 10 && test == extract64(test, 0, 21)) {
30
tcg_out_sethi(s, ret, test << 10);
31
tcg_out_arithi(s, ret, ret, lsb - 10, SHIFT_SLLX);
32
return;
33
+ } else if (test == (uint32_t)test || test == (int32_t)test) {
34
+ tcg_out_movi_int(s, TCG_TYPE_I64, ret, test, in_prologue, scratch);
35
+ tcg_out_arithi(s, ret, ret, lsb, SHIFT_SLLX);
36
+ return;
37
}
38
39
/* A 64-bit constant decomposed into 2 32-bit pieces. */
40
--
41
2.25.1
42
43
diff view generated by jsdifflib
New patch
1
Since 7ecd02a06f8, if patch_reloc fails we restart translation
2
with a smaller TB. SPARC had its function signature changed,
3
but not the logic. Replace assert with return false.
1
4
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
---
9
tcg/sparc/tcg-target.c.inc | 8 ++++++--
10
1 file changed, 6 insertions(+), 2 deletions(-)
11
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
13
index XXXXXXX..XXXXXXX 100644
14
--- a/tcg/sparc/tcg-target.c.inc
15
+++ b/tcg/sparc/tcg-target.c.inc
16
@@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type,
17
18
switch (type) {
19
case R_SPARC_WDISP16:
20
- assert(check_fit_ptr(pcrel >> 2, 16));
21
+ if (!check_fit_ptr(pcrel >> 2, 16)) {
22
+ return false;
23
+ }
24
insn &= ~INSN_OFF16(-1);
25
insn |= INSN_OFF16(pcrel);
26
break;
27
case R_SPARC_WDISP19:
28
- assert(check_fit_ptr(pcrel >> 2, 19));
29
+ if (!check_fit_ptr(pcrel >> 2, 19)) {
30
+ return false;
31
+ }
32
insn &= ~INSN_OFF19(-1);
33
insn |= INSN_OFF19(pcrel);
34
break;
35
--
36
2.25.1
37
38
diff view generated by jsdifflib
New patch
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
3
---
4
tcg/sparc/tcg-target.c.inc | 15 +++++++++++++++
5
1 file changed, 15 insertions(+)
1
6
7
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
8
index XXXXXXX..XXXXXXX 100644
9
--- a/tcg/sparc/tcg-target.c.inc
10
+++ b/tcg/sparc/tcg-target.c.inc
11
@@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type,
12
insn &= ~INSN_OFF19(-1);
13
insn |= INSN_OFF19(pcrel);
14
break;
15
+ case R_SPARC_13:
16
+ if (!check_fit_ptr(value, 13)) {
17
+ return false;
18
+ }
19
+ insn &= ~INSN_IMM13(-1);
20
+ insn |= INSN_IMM13(value);
21
+ break;
22
default:
23
g_assert_not_reached();
24
}
25
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
26
return;
27
}
28
29
+ /* Use the constant pool, if possible. */
30
+ if (!in_prologue && USE_REG_TB) {
31
+ new_pool_label(s, arg, R_SPARC_13, s->code_ptr,
32
+ tcg_tbrel_diff(s, NULL));
33
+ tcg_out32(s, LDX | INSN_RD(ret) | INSN_RS1(TCG_REG_TB));
34
+ return;
35
+ }
36
+
37
/* A 64-bit constant decomposed into 2 32-bit pieces. */
38
if (check_fit_i32(lo, 13)) {
39
hi = (arg - lo) >> 32;
40
--
41
2.25.1
42
43
diff view generated by jsdifflib
New patch
1
Due to mapping changes, we now rarely place the code_gen_buffer
2
near the main executable. Which means that direct calls will
3
now rarely be in range.
1
4
5
So, always use indirect calls for tail calls, which allows us to
6
avoid clobbering %o7, and therefore we need not save and restore it.
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
---
11
tcg/sparc/tcg-target.c.inc | 37 +++++++++++++++++++++++--------------
12
1 file changed, 23 insertions(+), 14 deletions(-)
13
14
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
15
index XXXXXXX..XXXXXXX 100644
16
--- a/tcg/sparc/tcg-target.c.inc
17
+++ b/tcg/sparc/tcg-target.c.inc
18
@@ -XXX,XX +XXX,XX @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
19
tcg_out_mov(s, TCG_TYPE_I64, rl, tmp);
20
}
21
22
+static void tcg_out_jmpl_const(TCGContext *s, const tcg_insn_unit *dest,
23
+ bool in_prologue, bool tail_call)
24
+{
25
+ uintptr_t desti = (uintptr_t)dest;
26
+
27
+ /* Be careful not to clobber %o7 for a tail call. */
28
+ tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
29
+ desti & ~0xfff, in_prologue,
30
+ tail_call ? TCG_REG_G2 : TCG_REG_O7);
31
+ tcg_out_arithi(s, tail_call ? TCG_REG_G0 : TCG_REG_O7,
32
+ TCG_REG_T1, desti & 0xfff, JMPL);
33
+}
34
+
35
static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
36
bool in_prologue)
37
{
38
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
39
if (disp == (int32_t)disp) {
40
tcg_out32(s, CALL | (uint32_t)disp >> 2);
41
} else {
42
- uintptr_t desti = (uintptr_t)dest;
43
- tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
44
- desti & ~0xfff, in_prologue, TCG_REG_O7);
45
- tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL);
46
+ tcg_out_jmpl_const(s, dest, in_prologue, false);
47
}
48
}
49
50
@@ -XXX,XX +XXX,XX @@ static void build_trampolines(TCGContext *s)
51
52
/* Set the retaddr operand. */
53
tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
54
- /* Set the env operand. */
55
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
56
/* Tail call. */
57
- tcg_out_call_nodelay(s, qemu_ld_helpers[i], true);
58
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra);
59
+ tcg_out_jmpl_const(s, qemu_ld_helpers[i], true, true);
60
+ /* delay slot -- set the env argument */
61
+ tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0);
62
}
63
64
for (i = 0; i < ARRAY_SIZE(qemu_st_helpers); ++i) {
65
@@ -XXX,XX +XXX,XX @@ static void build_trampolines(TCGContext *s)
66
if (ra >= TCG_REG_O6) {
67
tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_O7, TCG_REG_CALL_STACK,
68
TCG_TARGET_CALL_STACK_OFFSET);
69
- ra = TCG_REG_G1;
70
+ } else {
71
+ tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
72
}
73
- tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
74
- /* Set the env operand. */
75
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
76
+
77
/* Tail call. */
78
- tcg_out_call_nodelay(s, qemu_st_helpers[i], true);
79
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra);
80
+ tcg_out_jmpl_const(s, qemu_st_helpers[i], true, true);
81
+ /* delay slot -- set the env argument */
82
+ tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0);
83
}
84
}
85
#endif
86
--
87
2.25.1
88
89
diff view generated by jsdifflib
New patch
1
1
This is kinda sorta the opposite of the other tcg hosts, where
2
we get (normal) alignment checks for free with host SIGBUS and
3
need to add code to support unaligned accesses.
4
5
This inline code expansion is somewhat large, but it takes quite
6
a few instructions to make a function call to a helper anyway.
7
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
10
---
11
tcg/sparc/tcg-target.c.inc | 219 +++++++++++++++++++++++++++++++++++--
12
1 file changed, 211 insertions(+), 8 deletions(-)
13
14
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
15
index XXXXXXX..XXXXXXX 100644
16
--- a/tcg/sparc/tcg-target.c.inc
17
+++ b/tcg/sparc/tcg-target.c.inc
18
@@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_oarg_regs[] = {
19
#define ARITH_ADD (INSN_OP(2) | INSN_OP3(0x00))
20
#define ARITH_ADDCC (INSN_OP(2) | INSN_OP3(0x10))
21
#define ARITH_AND (INSN_OP(2) | INSN_OP3(0x01))
22
+#define ARITH_ANDCC (INSN_OP(2) | INSN_OP3(0x11))
23
#define ARITH_ANDN (INSN_OP(2) | INSN_OP3(0x05))
24
#define ARITH_OR (INSN_OP(2) | INSN_OP3(0x02))
25
#define ARITH_ORCC (INSN_OP(2) | INSN_OP3(0x12))
26
@@ -XXX,XX +XXX,XX @@ static void build_trampolines(TCGContext *s)
27
tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0);
28
}
29
}
30
+#else
31
+static const tcg_insn_unit *qemu_unalign_ld_trampoline;
32
+static const tcg_insn_unit *qemu_unalign_st_trampoline;
33
+
34
+static void build_trampolines(TCGContext *s)
35
+{
36
+ for (int ld = 0; ld < 2; ++ld) {
37
+ void *helper;
38
+
39
+ while ((uintptr_t)s->code_ptr & 15) {
40
+ tcg_out_nop(s);
41
+ }
42
+
43
+ if (ld) {
44
+ helper = helper_unaligned_ld;
45
+ qemu_unalign_ld_trampoline = tcg_splitwx_to_rx(s->code_ptr);
46
+ } else {
47
+ helper = helper_unaligned_st;
48
+ qemu_unalign_st_trampoline = tcg_splitwx_to_rx(s->code_ptr);
49
+ }
50
+
51
+ if (!SPARC64 && TARGET_LONG_BITS == 64) {
52
+ /* Install the high part of the address. */
53
+ tcg_out_arithi(s, TCG_REG_O1, TCG_REG_O2, 32, SHIFT_SRLX);
54
+ }
55
+
56
+ /* Tail call. */
57
+ tcg_out_jmpl_const(s, helper, true, true);
58
+ /* delay slot -- set the env argument */
59
+ tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0);
60
+ }
61
+}
62
#endif
63
64
/* Generate global QEMU prologue and epilogue code */
65
@@ -XXX,XX +XXX,XX @@ static void tcg_target_qemu_prologue(TCGContext *s)
66
/* delay slot */
67
tcg_out_movi_imm13(s, TCG_REG_O0, 0);
68
69
-#ifdef CONFIG_SOFTMMU
70
build_trampolines(s);
71
-#endif
72
}
73
74
static void tcg_out_nop_fill(tcg_insn_unit *p, int count)
75
@@ -XXX,XX +XXX,XX @@ static TCGReg tcg_out_tlb_load(TCGContext *s, TCGReg addr, int mem_index,
76
static const int qemu_ld_opc[(MO_SSIZE | MO_BSWAP) + 1] = {
77
[MO_UB] = LDUB,
78
[MO_SB] = LDSB,
79
+ [MO_UB | MO_LE] = LDUB,
80
+ [MO_SB | MO_LE] = LDSB,
81
82
[MO_BEUW] = LDUH,
83
[MO_BESW] = LDSH,
84
[MO_BEUL] = LDUW,
85
[MO_BESL] = LDSW,
86
[MO_BEUQ] = LDX,
87
+ [MO_BESQ] = LDX,
88
89
[MO_LEUW] = LDUH_LE,
90
[MO_LESW] = LDSH_LE,
91
[MO_LEUL] = LDUW_LE,
92
[MO_LESL] = LDSW_LE,
93
[MO_LEUQ] = LDX_LE,
94
+ [MO_LESQ] = LDX_LE,
95
};
96
97
static const int qemu_st_opc[(MO_SIZE | MO_BSWAP) + 1] = {
98
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
99
MemOpIdx oi, bool is_64)
100
{
101
MemOp memop = get_memop(oi);
102
+ tcg_insn_unit *label_ptr;
103
+
104
#ifdef CONFIG_SOFTMMU
105
unsigned memi = get_mmuidx(oi);
106
TCGReg addrz, param;
107
const tcg_insn_unit *func;
108
- tcg_insn_unit *label_ptr;
109
110
addrz = tcg_out_tlb_load(s, addr, memi, memop,
111
offsetof(CPUTLBEntry, addr_read));
112
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data, TCGReg addr,
113
114
*label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
115
#else
116
+ TCGReg index = (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0);
117
+ unsigned a_bits = get_alignment_bits(memop);
118
+ unsigned s_bits = memop & MO_SIZE;
119
+ unsigned t_bits;
120
+
121
if (SPARC64 && TARGET_LONG_BITS == 32) {
122
tcg_out_arithi(s, TCG_REG_T1, addr, 0, SHIFT_SRL);
123
addr = TCG_REG_T1;
124
}
125
- tcg_out_ldst_rr(s, data, addr,
126
- (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0),
127
+
128
+ /*
129
+ * Normal case: alignment equal to access size.
130
+ */
131
+ if (a_bits == s_bits) {
132
+ tcg_out_ldst_rr(s, data, addr, index,
133
+ qemu_ld_opc[memop & (MO_BSWAP | MO_SSIZE)]);
134
+ return;
135
+ }
136
+
137
+ /*
138
+ * Test for at least natural alignment, and assume most accesses
139
+ * will be aligned -- perform a straight load in the delay slot.
140
+ * This is required to preserve atomicity for aligned accesses.
141
+ */
142
+ t_bits = MAX(a_bits, s_bits);
143
+ tcg_debug_assert(t_bits < 13);
144
+ tcg_out_arithi(s, TCG_REG_G0, addr, (1u << t_bits) - 1, ARITH_ANDCC);
145
+
146
+ /* beq,a,pt %icc, label */
147
+ label_ptr = s->code_ptr;
148
+ tcg_out_bpcc0(s, COND_E, BPCC_A | BPCC_PT | BPCC_ICC, 0);
149
+ /* delay slot */
150
+ tcg_out_ldst_rr(s, data, addr, index,
151
qemu_ld_opc[memop & (MO_BSWAP | MO_SSIZE)]);
152
+
153
+ if (a_bits >= s_bits) {
154
+ /*
155
+ * Overalignment: A successful alignment test will perform the memory
156
+ * operation in the delay slot, and failure need only invoke the
157
+ * handler for SIGBUS.
158
+ */
159
+ TCGReg arg_low = TCG_REG_O1 + (!SPARC64 && TARGET_LONG_BITS == 64);
160
+ tcg_out_call_nodelay(s, qemu_unalign_ld_trampoline, false);
161
+ /* delay slot -- move to low part of argument reg */
162
+ tcg_out_mov_delay(s, arg_low, addr);
163
+ } else {
164
+ /* Underalignment: load by pieces of minimum alignment. */
165
+ int ld_opc, a_size, s_size, i;
166
+
167
+ /*
168
+ * Force full address into T1 early; avoids problems with
169
+ * overlap between @addr and @data.
170
+ */
171
+ tcg_out_arith(s, TCG_REG_T1, addr, index, ARITH_ADD);
172
+
173
+ a_size = 1 << a_bits;
174
+ s_size = 1 << s_bits;
175
+ if ((memop & MO_BSWAP) == MO_BE) {
176
+ ld_opc = qemu_ld_opc[a_bits | MO_BE | (memop & MO_SIGN)];
177
+ tcg_out_ldst(s, data, TCG_REG_T1, 0, ld_opc);
178
+ ld_opc = qemu_ld_opc[a_bits | MO_BE];
179
+ for (i = a_size; i < s_size; i += a_size) {
180
+ tcg_out_ldst(s, TCG_REG_T2, TCG_REG_T1, i, ld_opc);
181
+ tcg_out_arithi(s, data, data, a_size, SHIFT_SLLX);
182
+ tcg_out_arith(s, data, data, TCG_REG_T2, ARITH_OR);
183
+ }
184
+ } else if (a_bits == 0) {
185
+ ld_opc = LDUB;
186
+ tcg_out_ldst(s, data, TCG_REG_T1, 0, ld_opc);
187
+ for (i = a_size; i < s_size; i += a_size) {
188
+ if ((memop & MO_SIGN) && i == s_size - a_size) {
189
+ ld_opc = LDSB;
190
+ }
191
+ tcg_out_ldst(s, TCG_REG_T2, TCG_REG_T1, i, ld_opc);
192
+ tcg_out_arithi(s, TCG_REG_T2, TCG_REG_T2, i * 8, SHIFT_SLLX);
193
+ tcg_out_arith(s, data, data, TCG_REG_T2, ARITH_OR);
194
+ }
195
+ } else {
196
+ ld_opc = qemu_ld_opc[a_bits | MO_LE];
197
+ tcg_out_ldst_rr(s, data, TCG_REG_T1, TCG_REG_G0, ld_opc);
198
+ for (i = a_size; i < s_size; i += a_size) {
199
+ tcg_out_arithi(s, TCG_REG_T1, TCG_REG_T1, a_size, ARITH_ADD);
200
+ if ((memop & MO_SIGN) && i == s_size - a_size) {
201
+ ld_opc = qemu_ld_opc[a_bits | MO_LE | MO_SIGN];
202
+ }
203
+ tcg_out_ldst_rr(s, TCG_REG_T2, TCG_REG_T1, TCG_REG_G0, ld_opc);
204
+ tcg_out_arithi(s, TCG_REG_T2, TCG_REG_T2, i * 8, SHIFT_SLLX);
205
+ tcg_out_arith(s, data, data, TCG_REG_T2, ARITH_OR);
206
+ }
207
+ }
208
+ }
209
+
210
+ *label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
211
#endif /* CONFIG_SOFTMMU */
212
}
213
214
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
215
MemOpIdx oi)
216
{
217
MemOp memop = get_memop(oi);
218
+ tcg_insn_unit *label_ptr;
219
+
220
#ifdef CONFIG_SOFTMMU
221
unsigned memi = get_mmuidx(oi);
222
TCGReg addrz, param;
223
const tcg_insn_unit *func;
224
- tcg_insn_unit *label_ptr;
225
226
addrz = tcg_out_tlb_load(s, addr, memi, memop,
227
offsetof(CPUTLBEntry, addr_write));
228
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
229
230
*label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
231
#else
232
+ TCGReg index = (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0);
233
+ unsigned a_bits = get_alignment_bits(memop);
234
+ unsigned s_bits = memop & MO_SIZE;
235
+ unsigned t_bits;
236
+
237
if (SPARC64 && TARGET_LONG_BITS == 32) {
238
tcg_out_arithi(s, TCG_REG_T1, addr, 0, SHIFT_SRL);
239
addr = TCG_REG_T1;
240
}
241
- tcg_out_ldst_rr(s, data, addr,
242
- (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0),
243
+
244
+ /*
245
+ * Normal case: alignment equal to access size.
246
+ */
247
+ if (a_bits == s_bits) {
248
+ tcg_out_ldst_rr(s, data, addr, index,
249
+ qemu_st_opc[memop & (MO_BSWAP | MO_SIZE)]);
250
+ return;
251
+ }
252
+
253
+ /*
254
+ * Test for at least natural alignment, and assume most accesses
255
+ * will be aligned -- perform a straight store in the delay slot.
256
+ * This is required to preserve atomicity for aligned accesses.
257
+ */
258
+ t_bits = MAX(a_bits, s_bits);
259
+ tcg_debug_assert(t_bits < 13);
260
+ tcg_out_arithi(s, TCG_REG_G0, addr, (1u << t_bits) - 1, ARITH_ANDCC);
261
+
262
+ /* beq,a,pt %icc, label */
263
+ label_ptr = s->code_ptr;
264
+ tcg_out_bpcc0(s, COND_E, BPCC_A | BPCC_PT | BPCC_ICC, 0);
265
+ /* delay slot */
266
+ tcg_out_ldst_rr(s, data, addr, index,
267
qemu_st_opc[memop & (MO_BSWAP | MO_SIZE)]);
268
+
269
+ if (a_bits >= s_bits) {
270
+ /*
271
+ * Overalignment: A successful alignment test will perform the memory
272
+ * operation in the delay slot, and failure need only invoke the
273
+ * handler for SIGBUS.
274
+ */
275
+ TCGReg arg_low = TCG_REG_O1 + (!SPARC64 && TARGET_LONG_BITS == 64);
276
+ tcg_out_call_nodelay(s, qemu_unalign_st_trampoline, false);
277
+ /* delay slot -- move to low part of argument reg */
278
+ tcg_out_mov_delay(s, arg_low, addr);
279
+ } else {
280
+ /* Underalignment: store by pieces of minimum alignment. */
281
+ int st_opc, a_size, s_size, i;
282
+
283
+ /*
284
+ * Force full address into T1 early; avoids problems with
285
+ * overlap between @addr and @data.
286
+ */
287
+ tcg_out_arith(s, TCG_REG_T1, addr, index, ARITH_ADD);
288
+
289
+ a_size = 1 << a_bits;
290
+ s_size = 1 << s_bits;
291
+ if ((memop & MO_BSWAP) == MO_BE) {
292
+ st_opc = qemu_st_opc[a_bits | MO_BE];
293
+ for (i = 0; i < s_size; i += a_size) {
294
+ TCGReg d = data;
295
+ int shift = (s_size - a_size - i) * 8;
296
+ if (shift) {
297
+ d = TCG_REG_T2;
298
+ tcg_out_arithi(s, d, data, shift, SHIFT_SRLX);
299
+ }
300
+ tcg_out_ldst(s, d, TCG_REG_T1, i, st_opc);
301
+ }
302
+ } else if (a_bits == 0) {
303
+ tcg_out_ldst(s, data, TCG_REG_T1, 0, STB);
304
+ for (i = 1; i < s_size; i++) {
305
+ tcg_out_arithi(s, TCG_REG_T2, data, i * 8, SHIFT_SRLX);
306
+ tcg_out_ldst(s, TCG_REG_T2, TCG_REG_T1, i, STB);
307
+ }
308
+ } else {
309
+ /* Note that ST*A with immediate asi must use indexed address. */
310
+ st_opc = qemu_st_opc[a_bits + MO_LE];
311
+ tcg_out_ldst_rr(s, data, TCG_REG_T1, TCG_REG_G0, st_opc);
312
+ for (i = a_size; i < s_size; i += a_size) {
313
+ tcg_out_arithi(s, TCG_REG_T2, data, i * 8, SHIFT_SRLX);
314
+ tcg_out_arithi(s, TCG_REG_T1, TCG_REG_T1, a_size, ARITH_ADD);
315
+ tcg_out_ldst_rr(s, TCG_REG_T2, TCG_REG_T1, TCG_REG_G0, st_opc);
316
+ }
317
+ }
318
+ }
319
+
320
+ *label_ptr |= INSN_OFF19(tcg_ptr_byte_diff(s->code_ptr, label_ptr));
321
#endif /* CONFIG_SOFTMMU */
322
}
323
324
--
325
2.25.1
326
327
diff view generated by jsdifflib
New patch
1
A mostly generic test for unaligned access raising SIGBUS.
1
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
tests/tcg/multiarch/sigbus.c | 68 ++++++++++++++++++++++++++++++++++++
7
1 file changed, 68 insertions(+)
8
create mode 100644 tests/tcg/multiarch/sigbus.c
9
10
diff --git a/tests/tcg/multiarch/sigbus.c b/tests/tcg/multiarch/sigbus.c
11
new file mode 100644
12
index XXXXXXX..XXXXXXX
13
--- /dev/null
14
+++ b/tests/tcg/multiarch/sigbus.c
15
@@ -XXX,XX +XXX,XX @@
16
+#define _GNU_SOURCE 1
17
+
18
+#include <assert.h>
19
+#include <stdlib.h>
20
+#include <signal.h>
21
+#include <endian.h>
22
+
23
+
24
+unsigned long long x = 0x8877665544332211ull;
25
+void * volatile p = (void *)&x + 1;
26
+
27
+void sigbus(int sig, siginfo_t *info, void *uc)
28
+{
29
+ assert(sig == SIGBUS);
30
+ assert(info->si_signo == SIGBUS);
31
+#ifdef BUS_ADRALN
32
+ assert(info->si_code == BUS_ADRALN);
33
+#endif
34
+ assert(info->si_addr == p);
35
+ exit(EXIT_SUCCESS);
36
+}
37
+
38
+int main()
39
+{
40
+ struct sigaction sa = {
41
+ .sa_sigaction = sigbus,
42
+ .sa_flags = SA_SIGINFO
43
+ };
44
+ int allow_fail = 0;
45
+ int tmp;
46
+
47
+ tmp = sigaction(SIGBUS, &sa, NULL);
48
+ assert(tmp == 0);
49
+
50
+ /*
51
+ * Select an operation that's likely to enforce alignment.
52
+ * On many guests that support unaligned accesses by default,
53
+ * this is often an atomic operation.
54
+ */
55
+#if defined(__aarch64__)
56
+ asm volatile("ldxr %w0,[%1]" : "=r"(tmp) : "r"(p) : "memory");
57
+#elif defined(__alpha__)
58
+ asm volatile("ldl_l %0,0(%1)" : "=r"(tmp) : "r"(p) : "memory");
59
+#elif defined(__arm__)
60
+ asm volatile("ldrex %0,[%1]" : "=r"(tmp) : "r"(p) : "memory");
61
+#elif defined(__powerpc__)
62
+ asm volatile("lwarx %0,0,%1" : "=r"(tmp) : "r"(p) : "memory");
63
+#elif defined(__riscv_atomic)
64
+ asm volatile("lr.w %0,(%1)" : "=r"(tmp) : "r"(p) : "memory");
65
+#else
66
+ /* No insn known to fault unaligned -- try for a straight load. */
67
+ allow_fail = 1;
68
+ tmp = *(volatile int *)p;
69
+#endif
70
+
71
+ assert(allow_fail);
72
+
73
+ /*
74
+ * We didn't see a signal.
75
+ * We might as well validate the unaligned load worked.
76
+ */
77
+ if (BYTE_ORDER == LITTLE_ENDIAN) {
78
+ assert(tmp == 0x55443322);
79
+ } else {
80
+ assert(tmp == 0x77665544);
81
+ }
82
+ return EXIT_SUCCESS;
83
+}
84
--
85
2.25.1
86
87
diff view generated by jsdifflib