1
The following changes since commit 6587b0c1331d427b0939c37e763842550ed581db:
1
The following changes since commit 0a301624c2f4ced3331ffd5bce85b4274fe132af:
2
2
3
Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2021-10-15' into staging (2021-10-15 14:16:28 -0700)
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-20211016
7
https://gitlab.com/rth7680/qemu.git tags/pull-tcg-20220211
8
8
9
for you to fetch changes up to 995b87dedc78b0467f5f18bbc3546072ba97516a:
9
for you to fetch changes up to 5c1a101ef6b85537a4ade93c39ea81cadd5c246e:
10
10
11
Revert "cpu: Move cpu_common_props to hw/core/cpu.c" (2021-10-15 16:39:15 -0700)
11
tests/tcg/multiarch: Add sigbus.c (2022-02-09 09:00:01 +1100)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
Move gdb singlestep to generic code
14
Fix safe_syscall_base for sparc64.
15
Fix cpu_common_props
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.
16
19
17
----------------------------------------------------------------
20
----------------------------------------------------------------
18
Richard Henderson (24):
21
Idan Horowitz (2):
19
accel/tcg: Handle gdb singlestep in cpu_tb_exec
22
accel/tcg: Optimize jump cache flush during tlb range flush
20
target/alpha: Drop checks for singlestep_enabled
23
softmmu/cpus: Check if the cpu work list is empty atomically
21
target/avr: Drop checks for singlestep_enabled
22
target/cris: Drop checks for singlestep_enabled
23
target/hexagon: Drop checks for singlestep_enabled
24
target/arm: Drop checks for singlestep_enabled
25
target/hppa: Drop checks for singlestep_enabled
26
target/i386: Check CF_NO_GOTO_TB for dc->jmp_opt
27
target/i386: Drop check for singlestep_enabled
28
target/m68k: Drop checks for singlestep_enabled
29
target/microblaze: Check CF_NO_GOTO_TB for DISAS_JUMP
30
target/microblaze: Drop checks for singlestep_enabled
31
target/mips: Fix single stepping
32
target/mips: Drop exit checks for singlestep_enabled
33
target/openrisc: Drop checks for singlestep_enabled
34
target/ppc: Drop exit checks for singlestep_enabled
35
target/riscv: Remove dead code after exception
36
target/riscv: Remove exit_tb and lookup_and_goto_ptr
37
target/rx: Drop checks for singlestep_enabled
38
target/s390x: Drop check for singlestep_enabled
39
target/sh4: Drop check for singlestep_enabled
40
target/tricore: Drop check for singlestep_enabled
41
target/xtensa: Drop check for singlestep_enabled
42
Revert "cpu: Move cpu_common_props to hw/core/cpu.c"
43
24
44
include/hw/core/cpu.h | 1 +
25
Pavel Dovgalyuk (1):
45
target/i386/helper.h | 1 -
26
replay: use CF_NOIRQ for special exception-replaying TB
46
target/rx/helper.h | 1 -
47
target/sh4/helper.h | 1 -
48
target/tricore/helper.h | 1 -
49
accel/tcg/cpu-exec.c | 11 ++++
50
cpu.c | 21 ++++++++
51
hw/core/cpu-common.c | 17 +-----
52
target/alpha/translate.c | 13 ++---
53
target/arm/translate-a64.c | 10 +---
54
target/arm/translate.c | 36 +++----------
55
target/avr/translate.c | 19 ++-----
56
target/cris/translate.c | 16 ------
57
target/hexagon/translate.c | 12 +----
58
target/hppa/translate.c | 17 ++----
59
target/i386/tcg/misc_helper.c | 8 ---
60
target/i386/tcg/translate.c | 9 ++--
61
target/m68k/translate.c | 44 ++++-----------
62
target/microblaze/translate.c | 18 ++-----
63
target/mips/tcg/translate.c | 75 ++++++++++++--------------
64
target/openrisc/translate.c | 18 ++-----
65
target/ppc/translate.c | 38 +++----------
66
target/riscv/translate.c | 27 +---------
67
target/rx/op_helper.c | 8 ---
68
target/rx/translate.c | 12 +----
69
target/s390x/tcg/translate.c | 8 +--
70
target/sh4/op_helper.c | 5 --
71
target/sh4/translate.c | 14 ++---
72
target/tricore/op_helper.c | 7 ---
73
target/tricore/translate.c | 14 +----
74
target/xtensa/translate.c | 25 +++------
75
target/riscv/insn_trans/trans_privileged.c.inc | 10 ++--
76
target/riscv/insn_trans/trans_rvi.c.inc | 8 ++-
77
target/riscv/insn_trans/trans_rvv.c.inc | 2 +-
78
34 files changed, 141 insertions(+), 386 deletions(-)
79
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
1
We were using singlestep_enabled as a proxy for whether
1
Use the "retl" instead of "ret" instruction alias, since we
2
translator_use_goto_tb would always return false.
2
do not allocate a register window in this function.
3
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")
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
9
---
6
target/i386/tcg/translate.c | 5 +++--
10
common-user/host/sparc64/safe-syscall.inc.S | 5 +++--
7
1 file changed, 3 insertions(+), 2 deletions(-)
11
1 file changed, 3 insertions(+), 2 deletions(-)
8
12
9
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
13
diff --git a/common-user/host/sparc64/safe-syscall.inc.S b/common-user/host/sparc64/safe-syscall.inc.S
10
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
11
--- a/target/i386/tcg/translate.c
15
--- a/common-user/host/sparc64/safe-syscall.inc.S
12
+++ b/target/i386/tcg/translate.c
16
+++ b/common-user/host/sparc64/safe-syscall.inc.S
13
@@ -XXX,XX +XXX,XX @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
17
@@ -XXX,XX +XXX,XX @@
14
DisasContext *dc = container_of(dcbase, DisasContext, base);
18
.type safe_syscall_end, @function
15
CPUX86State *env = cpu->env_ptr;
19
16
uint32_t flags = dc->base.tb->flags;
20
#define STACK_BIAS 2047
17
+ uint32_t cflags = tb_cflags(dc->base.tb);
21
-#define PARAM(N) STACK_BIAS + N*8
18
int cpl = (flags >> HF_CPL_SHIFT) & 3;
22
+#define WINDOW_SIZE 16 * 8
19
int iopl = (flags >> IOPL_SHIFT) & 3;
23
+#define PARAM(N) STACK_BIAS + WINDOW_SIZE + N * 8
20
24
21
@@ -XXX,XX +XXX,XX @@ static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
25
/*
22
dc->cpuid_ext3_features = env->features[FEAT_8000_0001_ECX];
26
* This is the entry point for making a system call. The calling
23
dc->cpuid_7_0_ebx_features = env->features[FEAT_7_0_EBX];
27
@@ -XXX,XX +XXX,XX @@ safe_syscall_end:
24
dc->cpuid_xsave_features = env->features[FEAT_XSAVE];
28
/* code path for having successfully executed the syscall */
25
- dc->jmp_opt = !(dc->base.singlestep_enabled ||
29
bcs,pn %xcc, 1f
26
+ dc->jmp_opt = !((cflags & CF_NO_GOTO_TB) ||
30
nop
27
(flags & (HF_TF_MASK | HF_INHIBIT_IRQ_MASK)));
31
- ret
28
/*
32
+ retl
29
* If jmp_opt, we want to handle each string instruction individually.
33
nop
30
* For icount also disable repz optimization so that each iteration
34
31
* is accounted separately.
35
/* code path when we didn't execute the syscall */
32
*/
33
- dc->repz_opt = !dc->jmp_opt && !(tb_cflags(dc->base.tb) & CF_USE_ICOUNT);
34
+ dc->repz_opt = !dc->jmp_opt && !(cflags & CF_USE_ICOUNT);
35
36
dc->T0 = tcg_temp_new();
37
dc->T1 = tcg_temp_new();
38
--
36
--
39
2.25.1
37
2.25.1
40
38
41
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
GDB single-stepping is now handled generically.
1
We do not support sparc32 as a host, so there's no point in
2
sparc64 redirecting to sparc.
2
3
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
---
6
target/sh4/helper.h | 1 -
7
linux-user/include/host/sparc/host-signal.h | 71 -------------------
7
target/sh4/op_helper.c | 5 -----
8
linux-user/include/host/sparc64/host-signal.h | 64 ++++++++++++++++-
8
target/sh4/translate.c | 14 +++-----------
9
2 files changed, 63 insertions(+), 72 deletions(-)
9
3 files changed, 3 insertions(+), 17 deletions(-)
10
delete mode 100644 linux-user/include/host/sparc/host-signal.h
10
11
11
diff --git a/target/sh4/helper.h b/target/sh4/helper.h
12
diff --git a/linux-user/include/host/sparc/host-signal.h b/linux-user/include/host/sparc/host-signal.h
12
index XXXXXXX..XXXXXXX 100644
13
deleted file mode 100644
13
--- a/target/sh4/helper.h
14
index XXXXXXX..XXXXXXX
14
+++ b/target/sh4/helper.h
15
--- a/linux-user/include/host/sparc/host-signal.h
15
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env)
16
+++ /dev/null
16
DEF_HELPER_1(raise_slot_illegal_instruction, noreturn, env)
17
@@ -XXX,XX +XXX,XX @@
17
DEF_HELPER_1(raise_fpu_disable, noreturn, env)
18
-/*
18
DEF_HELPER_1(raise_slot_fpu_disable, noreturn, env)
19
- * host-signal.h: signal info dependent on the host architecture
19
-DEF_HELPER_1(debug, noreturn, env)
20
- *
20
DEF_HELPER_1(sleep, noreturn, env)
21
- * Copyright (c) 2003-2005 Fabrice Bellard
21
DEF_HELPER_2(trapa, noreturn, env, i32)
22
- * Copyright (c) 2021 Linaro Limited
22
DEF_HELPER_1(exclusive, noreturn, env)
23
- *
23
diff --git a/target/sh4/op_helper.c b/target/sh4/op_helper.c
24
- * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
24
index XXXXXXX..XXXXXXX 100644
25
- * See the COPYING file in the top-level directory.
25
--- a/target/sh4/op_helper.c
26
- */
26
+++ b/target/sh4/op_helper.c
27
-
27
@@ -XXX,XX +XXX,XX @@ void helper_raise_slot_fpu_disable(CPUSH4State *env)
28
-#ifndef SPARC_HOST_SIGNAL_H
28
raise_exception(env, 0x820, 0);
29
-#define SPARC_HOST_SIGNAL_H
29
}
30
-
30
31
-/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
31
-void helper_debug(CPUSH4State *env)
32
-typedef ucontext_t host_sigcontext;
33
-
34
-static inline uintptr_t host_signal_pc(host_sigcontext *uc)
32
-{
35
-{
33
- raise_exception(env, EXCP_DEBUG, 0);
36
-#ifdef __arch64__
37
- return uc->uc_mcontext.mc_gregs[MC_PC];
38
-#else
39
- return uc->uc_mcontext.gregs[REG_PC];
40
-#endif
34
-}
41
-}
35
-
42
-
36
void helper_sleep(CPUSH4State *env)
43
-static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
37
{
44
-{
38
CPUState *cs = env_cpu(env);
45
-#ifdef __arch64__
39
diff --git a/target/sh4/translate.c b/target/sh4/translate.c
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
40
index XXXXXXX..XXXXXXX 100644
90
index XXXXXXX..XXXXXXX 100644
41
--- a/target/sh4/translate.c
91
--- a/linux-user/include/host/sparc64/host-signal.h
42
+++ b/target/sh4/translate.c
92
+++ b/linux-user/include/host/sparc64/host-signal.h
43
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
93
@@ -1 +1,63 @@
44
tcg_gen_exit_tb(ctx->base.tb, n);
94
-#include "../sparc/host-signal.h"
45
} else {
95
+/*
46
tcg_gen_movi_i32(cpu_pc, dest);
96
+ * host-signal.h: signal info dependent on the host architecture
47
- if (ctx->base.singlestep_enabled) {
97
+ *
48
- gen_helper_debug(cpu_env);
98
+ * Copyright (c) 2003-2005 Fabrice Bellard
49
- } else if (use_exit_tb(ctx)) {
99
+ * Copyright (c) 2021 Linaro Limited
50
+ if (use_exit_tb(ctx)) {
100
+ *
51
tcg_gen_exit_tb(NULL, 0);
101
+ * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
52
} else {
102
+ * See the COPYING file in the top-level directory.
53
tcg_gen_lookup_and_goto_ptr();
103
+ */
54
@@ -XXX,XX +XXX,XX @@ static void gen_jump(DisasContext * ctx)
104
+
55
     delayed jump as immediate jump are conditinal jumps */
105
+#ifndef SPARC64_HOST_SIGNAL_H
56
    tcg_gen_mov_i32(cpu_pc, cpu_delayed_pc);
106
+#define SPARC64_HOST_SIGNAL_H
57
tcg_gen_discard_i32(cpu_delayed_pc);
107
+
58
- if (ctx->base.singlestep_enabled) {
108
+/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
59
- gen_helper_debug(cpu_env);
109
+typedef ucontext_t host_sigcontext;
60
- } else if (use_exit_tb(ctx)) {
110
+
61
+ if (use_exit_tb(ctx)) {
111
+static inline uintptr_t host_signal_pc(host_sigcontext *uc)
62
tcg_gen_exit_tb(NULL, 0);
112
+{
63
} else {
113
+ return uc->uc_mcontext.mc_gregs[MC_PC];
64
tcg_gen_lookup_and_goto_ptr();
114
+}
65
@@ -XXX,XX +XXX,XX @@ static void sh4_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
115
+
66
switch (ctx->base.is_jmp) {
116
+static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
67
case DISAS_STOP:
117
+{
68
gen_save_cpu_state(ctx, true);
118
+ uc->uc_mcontext.mc_gregs[MC_PC] = pc;
69
- if (ctx->base.singlestep_enabled) {
119
+}
70
- gen_helper_debug(cpu_env);
120
+
71
- } else {
121
+static inline void *host_signal_mask(host_sigcontext *uc)
72
- tcg_gen_exit_tb(NULL, 0);
122
+{
73
- }
123
+ return &uc->uc_sigmask;
74
+ tcg_gen_exit_tb(NULL, 0);
124
+}
75
break;
125
+
76
case DISAS_NEXT:
126
+static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
77
case DISAS_TOO_MANY:
127
+{
128
+ uint32_t insn = *(uint32_t *)host_signal_pc(uc);
129
+
130
+ if ((insn >> 30) == 3) {
131
+ switch ((insn >> 19) & 0x3f) {
132
+ case 0x05: /* stb */
133
+ case 0x15: /* stba */
134
+ case 0x06: /* sth */
135
+ case 0x16: /* stha */
136
+ case 0x04: /* st */
137
+ case 0x14: /* sta */
138
+ case 0x07: /* std */
139
+ case 0x17: /* stda */
140
+ case 0x0e: /* stx */
141
+ case 0x1e: /* stxa */
142
+ case 0x24: /* stf */
143
+ case 0x34: /* stfa */
144
+ case 0x27: /* stdf */
145
+ case 0x37: /* stdfa */
146
+ case 0x26: /* stqf */
147
+ case 0x36: /* stqfa */
148
+ case 0x25: /* stfsr */
149
+ case 0x3c: /* casa */
150
+ case 0x3e: /* casxa */
151
+ return true;
152
+ }
153
+ }
154
+ return false;
155
+}
156
+
157
+#endif
78
--
158
--
79
2.25.1
159
2.25.1
80
160
81
161
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
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.
2
4
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
10
---
6
target/tricore/helper.h | 1 -
11
linux-user/include/host/sparc64/host-signal.h | 17 +++++++++--------
7
target/tricore/op_helper.c | 7 -------
12
1 file changed, 9 insertions(+), 8 deletions(-)
8
target/tricore/translate.c | 14 +-------------
9
3 files changed, 1 insertion(+), 21 deletions(-)
10
13
11
diff --git a/target/tricore/helper.h b/target/tricore/helper.h
14
diff --git a/linux-user/include/host/sparc64/host-signal.h b/linux-user/include/host/sparc64/host-signal.h
12
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
13
--- a/target/tricore/helper.h
16
--- a/linux-user/include/host/sparc64/host-signal.h
14
+++ b/target/tricore/helper.h
17
+++ b/linux-user/include/host/sparc64/host-signal.h
15
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(psw_write, void, env, i32)
18
@@ -XXX,XX +XXX,XX @@
16
DEF_HELPER_1(psw_read, i32, env)
19
#ifndef SPARC64_HOST_SIGNAL_H
17
/* Exceptions */
20
#define SPARC64_HOST_SIGNAL_H
18
DEF_HELPER_3(raise_exception_sync, noreturn, env, i32, i32)
21
19
-DEF_HELPER_2(qemu_excp, noreturn, env, i32)
22
-/* FIXME: the third argument to a SA_SIGINFO handler is *not* ucontext_t. */
20
diff --git a/target/tricore/op_helper.c b/target/tricore/op_helper.c
23
-typedef ucontext_t host_sigcontext;
21
index XXXXXXX..XXXXXXX 100644
24
+/* The third argument to a SA_SIGINFO handler is struct sigcontext. */
22
--- a/target/tricore/op_helper.c
25
+typedef struct sigcontext host_sigcontext;
23
+++ b/target/tricore/op_helper.c
26
24
@@ -XXX,XX +XXX,XX @@ static void raise_exception_sync_helper(CPUTriCoreState *env, uint32_t class,
27
-static inline uintptr_t host_signal_pc(host_sigcontext *uc)
25
raise_exception_sync_internal(env, class, tin, pc, 0);
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;
26
}
32
}
27
33
28
-void helper_qemu_excp(CPUTriCoreState *env, uint32_t excp)
34
-static inline void host_signal_set_pc(host_sigcontext *uc, uintptr_t pc)
29
-{
35
+static inline void host_signal_set_pc(host_sigcontext *sc, uintptr_t pc)
30
- CPUState *cs = env_cpu(env);
36
{
31
- cs->exception_index = excp;
37
- uc->uc_mcontext.mc_gregs[MC_PC] = pc;
32
- cpu_loop_exit(cs);
38
+ sc->sigc_regs.tpc = pc;
33
-}
39
+ sc->sigc_regs.tnpc = pc + 4;
34
-
35
/* Addressing mode helper */
36
37
static uint16_t reverse16(uint16_t val)
38
diff --git a/target/tricore/translate.c b/target/tricore/translate.c
39
index XXXXXXX..XXXXXXX 100644
40
--- a/target/tricore/translate.c
41
+++ b/target/tricore/translate.c
42
@@ -XXX,XX +XXX,XX @@ static inline void gen_save_pc(target_ulong pc)
43
tcg_gen_movi_tl(cpu_PC, pc);
44
}
40
}
45
41
46
-static void generate_qemu_excp(DisasContext *ctx, int excp)
42
-static inline void *host_signal_mask(host_sigcontext *uc)
47
-{
43
+static inline void *host_signal_mask(host_sigcontext *sc)
48
- TCGv_i32 tmp = tcg_const_i32(excp);
49
- gen_helper_qemu_excp(cpu_env, tmp);
50
- ctx->base.is_jmp = DISAS_NORETURN;
51
- tcg_temp_free(tmp);
52
-}
53
-
54
static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
55
{
44
{
56
if (translator_use_goto_tb(&ctx->base, dest)) {
45
- return &uc->uc_sigmask;
57
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
46
+ return &sc->sigc_mask;
58
tcg_gen_exit_tb(ctx->base.tb, n);
59
} else {
60
gen_save_pc(dest);
61
- if (ctx->base.singlestep_enabled) {
62
- generate_qemu_excp(ctx, EXCP_DEBUG);
63
- } else {
64
- tcg_gen_lookup_and_goto_ptr();
65
- }
66
+ tcg_gen_lookup_and_goto_ptr();
67
}
68
}
47
}
69
48
49
static inline bool host_signal_write(siginfo_t *info, host_sigcontext *uc)
70
--
50
--
71
2.25.1
51
2.25.1
72
52
73
53
diff view generated by jsdifflib
1
As per an ancient comment in mips_tr_translate_insn about the
1
From: Idan Horowitz <idan.horowitz@gmail.com>
2
expectations of gdb, when restarting the insn in a delay slot
3
we also re-execute the branch. Which means that we are
4
expected to execute two insns in this case.
5
2
6
This has been broken since 8b86d6d2580, where we forced max_insns
3
When the length of the range is large enough, clearing the whole cache is
7
to 1 while single-stepping. This resulted in an exit from the
4
faster than iterating over the (possibly extremely large) set of pages
8
translator loop after the branch but before the delay slot is
5
contained in the range.
9
translated.
10
6
11
Increase the max_insns to 2 for this case. In addition, bypass
7
This mimics the pre-existing similar optimization done on the flush of the
12
the end-of-page check, for when the branch itself ends the page.
8
tlb itself.
13
9
14
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
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>
15
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
16
---
14
---
17
target/mips/tcg/translate.c | 25 ++++++++++++++++---------
15
accel/tcg/cputlb.c | 9 +++++++++
18
1 file changed, 16 insertions(+), 9 deletions(-)
16
1 file changed, 9 insertions(+)
19
17
20
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
18
diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c
21
index XXXXXXX..XXXXXXX 100644
19
index XXXXXXX..XXXXXXX 100644
22
--- a/target/mips/tcg/translate.c
20
--- a/accel/tcg/cputlb.c
23
+++ b/target/mips/tcg/translate.c
21
+++ b/accel/tcg/cputlb.c
24
@@ -XXX,XX +XXX,XX @@ static void mips_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
22
@@ -XXX,XX +XXX,XX @@ static void tlb_flush_range_by_mmuidx_async_0(CPUState *cpu,
25
ctx->default_tcg_memop_mask = (ctx->insn_flags & (ISA_MIPS_R6 |
23
}
26
INSN_LOONGSON3A)) ? MO_UNALN : MO_ALIGN;
24
qemu_spin_unlock(&env_tlb(env)->c.lock);
27
25
28
+ /*
26
+ /*
29
+ * Execute a branch and its delay slot as a single instruction.
27
+ * If the length is larger than the jump cache size, then it will take
30
+ * This is what GDB expects and is consistent with what the
28
+ * longer to clear each entry individually than it will to clear it all.
31
+ * hardware does (e.g. if a delay slot instruction faults, the
32
+ * reported PC is the PC of the branch).
33
+ */
29
+ */
34
+ if (ctx->base.singlestep_enabled && (ctx->hflags & MIPS_HFLAG_BMASK)) {
30
+ if (d.len >= (TARGET_PAGE_SIZE * TB_JMP_CACHE_SIZE)) {
35
+ ctx->base.max_insns = 2;
31
+ cpu_tb_jmp_cache_clear(cpu);
32
+ return;
36
+ }
33
+ }
37
+
34
+
38
LOG_DISAS("\ntb %p idx %d hflags %04x\n", ctx->base.tb, ctx->mem_idx,
35
for (target_ulong i = 0; i < d.len; i += TARGET_PAGE_SIZE) {
39
ctx->hflags);
36
tb_flush_jmp_cache(cpu, d.addr + i);
40
}
41
@@ -XXX,XX +XXX,XX @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
42
if (ctx->base.is_jmp != DISAS_NEXT) {
43
return;
44
}
37
}
45
+
46
/*
47
- * Execute a branch and its delay slot as a single instruction.
48
- * This is what GDB expects and is consistent with what the
49
- * hardware does (e.g. if a delay slot instruction faults, the
50
- * reported PC is the PC of the branch).
51
+ * End the TB on (most) page crossings.
52
+ * See mips_tr_init_disas_context about single-stepping a branch
53
+ * together with its delay slot.
54
*/
55
- if (ctx->base.singlestep_enabled &&
56
- (ctx->hflags & MIPS_HFLAG_BMASK) == 0) {
57
- ctx->base.is_jmp = DISAS_TOO_MANY;
58
- }
59
- if (ctx->base.pc_next - ctx->page_start >= TARGET_PAGE_SIZE) {
60
+ if (ctx->base.pc_next - ctx->page_start >= TARGET_PAGE_SIZE
61
+ && !ctx->base.singlestep_enabled) {
62
ctx->base.is_jmp = DISAS_TOO_MANY;
63
}
64
}
65
--
38
--
66
2.25.1
39
2.25.1
67
40
68
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
1
Currently the change in cpu_tb_exec is masked by the debug exception
1
From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru>
2
being raised by the translators. But this allows us to remove that code.
3
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>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
12
---
6
accel/tcg/cpu-exec.c | 11 +++++++++++
13
accel/tcg/cpu-exec.c | 3 ++-
7
1 file changed, 11 insertions(+)
14
1 file changed, 2 insertions(+), 1 deletion(-)
8
15
9
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
16
diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c
10
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
11
--- a/accel/tcg/cpu-exec.c
18
--- a/accel/tcg/cpu-exec.c
12
+++ b/accel/tcg/cpu-exec.c
19
+++ b/accel/tcg/cpu-exec.c
13
@@ -XXX,XX +XXX,XX @@ cpu_tb_exec(CPUState *cpu, TranslationBlock *itb, int *tb_exit)
20
@@ -XXX,XX +XXX,XX @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
14
cc->set_pc(cpu, last_tb->pc);
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;
15
}
27
}
16
}
28
#endif
17
+
29
return false;
18
+ /*
19
+ * If gdb single-step, and we haven't raised another exception,
20
+ * raise a debug exception. Single-step with another exception
21
+ * is handled in cpu_handle_exception.
22
+ */
23
+ if (unlikely(cpu->singlestep_enabled) && cpu->exception_index == -1) {
24
+ cpu->exception_index = EXCP_DEBUG;
25
+ cpu_loop_exit(cpu);
26
+ }
27
+
28
return last_tb;
29
}
30
31
--
30
--
32
2.25.1
31
2.25.1
33
32
34
33
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
From: WANG Xuerui <git@xen0n.name>
2
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>
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
8
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
9
---
5
target/microblaze/translate.c | 14 ++------------
10
tcg/loongarch64/tcg-target.c.inc | 2 +-
6
1 file changed, 2 insertions(+), 12 deletions(-)
11
1 file changed, 1 insertion(+), 1 deletion(-)
7
12
8
diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
13
diff --git a/tcg/loongarch64/tcg-target.c.inc b/tcg/loongarch64/tcg-target.c.inc
9
index XXXXXXX..XXXXXXX 100644
14
index XXXXXXX..XXXXXXX 100644
10
--- a/target/microblaze/translate.c
15
--- a/tcg/loongarch64/tcg-target.c.inc
11
+++ b/target/microblaze/translate.c
16
+++ b/tcg/loongarch64/tcg-target.c.inc
12
@@ -XXX,XX +XXX,XX @@ static void gen_raise_hw_excp(DisasContext *dc, uint32_t esr_ec)
17
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld_indexed(TCGContext *s, TCGReg rd, TCGReg rj,
13
18
case MO_SL:
14
static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest)
19
tcg_out_opc_ldx_w(s, rd, rj, rk);
15
{
20
break;
16
- if (dc->base.singlestep_enabled) {
21
- case MO_Q:
17
- TCGv_i32 tmp = tcg_const_i32(EXCP_DEBUG);
22
+ case MO_UQ:
18
- tcg_gen_movi_i32(cpu_pc, dest);
23
tcg_out_opc_ldx_d(s, rd, rj, rk);
19
- gen_helper_raise_exception(cpu_env, tmp);
24
break;
20
- tcg_temp_free_i32(tmp);
21
- } else if (translator_use_goto_tb(&dc->base, dest)) {
22
+ if (translator_use_goto_tb(&dc->base, dest)) {
23
tcg_gen_goto_tb(n);
24
tcg_gen_movi_i32(cpu_pc, dest);
25
tcg_gen_exit_tb(dc->base.tb, n);
26
@@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs)
27
/* Indirect jump (or direct jump w/ goto_tb disabled) */
28
tcg_gen_mov_i32(cpu_pc, cpu_btarget);
29
tcg_gen_discard_i32(cpu_btarget);
30
-
31
- if (unlikely(cs->singlestep_enabled)) {
32
- gen_raise_exception(dc, EXCP_DEBUG);
33
- } else {
34
- tcg_gen_lookup_and_goto_ptr();
35
- }
36
+ tcg_gen_lookup_and_goto_ptr();
37
return;
38
39
default:
25
default:
40
--
26
--
41
2.25.1
27
2.25.1
42
28
43
29
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
3
---
5
target/s390x/tcg/translate.c | 8 ++------
4
tcg/i386/tcg-target.h | 2 -
6
1 file changed, 2 insertions(+), 6 deletions(-)
5
tcg/i386/tcg-target.c.inc | 103 ++++++++++++++++++++++++++++++++++++--
6
2 files changed, 98 insertions(+), 7 deletions(-)
7
7
8
diff --git a/target/s390x/tcg/translate.c b/target/s390x/tcg/translate.c
8
diff --git a/tcg/i386/tcg-target.h b/tcg/i386/tcg-target.h
9
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
10
--- a/target/s390x/tcg/translate.c
10
--- a/tcg/i386/tcg-target.h
11
+++ b/target/s390x/tcg/translate.c
11
+++ b/tcg/i386/tcg-target.h
12
@@ -XXX,XX +XXX,XX @@ struct DisasContext {
12
@@ -XXX,XX +XXX,XX @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
13
uint64_t pc_tmp;
13
14
uint32_t ilen;
14
#define TCG_TARGET_HAS_MEMORY_BSWAP have_movbe
15
enum cc_op cc_op;
15
16
- bool do_debug;
16
-#ifdef CONFIG_SOFTMMU
17
};
17
#define TCG_TARGET_NEED_LDST_LABELS
18
18
-#endif
19
/* Information carried about a condition to be evaluated. */
19
#define TCG_TARGET_NEED_POOL_LABELS
20
@@ -XXX,XX +XXX,XX @@ static void s390x_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
20
21
21
#endif
22
dc->cc_op = CC_OP_DYNAMIC;
22
diff --git a/tcg/i386/tcg-target.c.inc b/tcg/i386/tcg-target.c.inc
23
dc->ex_value = dc->base.tb->cs_base;
23
index XXXXXXX..XXXXXXX 100644
24
- dc->do_debug = dc->base.singlestep_enabled;
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)
25
}
55
}
26
56
27
static void s390x_tr_tb_start(DisasContextBase *db, CPUState *cs)
57
#if defined(CONFIG_SOFTMMU)
28
@@ -XXX,XX +XXX,XX @@ static void s390x_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
58
-#include "../tcg-ldst.c.inc"
29
/* FALLTHRU */
59
-
30
case DISAS_PC_CC_UPDATED:
60
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
31
/* Exit the TB, either by raising a debug exception or by return. */
61
* int mmu_idx, uintptr_t ra)
32
- if (dc->do_debug) {
62
*/
33
- gen_exception(EXCP_DEBUG);
63
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
34
- } else if ((dc->base.tb->flags & FLAG_MASK_PER) ||
64
tcg_out_jmp(s, qemu_st_helpers[opc & (MO_BSWAP | MO_SIZE)]);
35
- dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) {
65
return true;
36
+ if ((dc->base.tb->flags & FLAG_MASK_PER) ||
66
}
37
+ dc->base.is_jmp == DISAS_PC_STALE_NOCHAIN) {
67
-#elif TCG_TARGET_REG_BITS == 32
38
tcg_gen_exit_tb(NULL, 0);
68
+#else
39
} else {
69
+
40
tcg_gen_lookup_and_goto_ptr();
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
41
--
199
--
42
2.25.1
200
2.25.1
43
201
44
202
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
3
---
5
target/arm/translate-a64.c | 10 ++--------
4
tcg/aarch64/tcg-target.h | 2 -
6
target/arm/translate.c | 36 ++++++------------------------------
5
tcg/aarch64/tcg-target.c.inc | 91 +++++++++++++++++++++++++++++-------
7
2 files changed, 8 insertions(+), 38 deletions(-)
6
2 files changed, 74 insertions(+), 19 deletions(-)
8
7
9
diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c
8
diff --git a/tcg/aarch64/tcg-target.h b/tcg/aarch64/tcg-target.h
10
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
11
--- a/target/arm/translate-a64.c
10
--- a/tcg/aarch64/tcg-target.h
12
+++ b/target/arm/translate-a64.c
11
+++ b/tcg/aarch64/tcg-target.h
13
@@ -XXX,XX +XXX,XX @@ static inline void gen_goto_tb(DisasContext *s, int n, uint64_t dest)
12
@@ -XXX,XX +XXX,XX @@ typedef enum {
14
gen_a64_set_pc_im(dest);
13
15
if (s->ss_active) {
14
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
16
gen_step_complete_exception(s);
15
17
- } else if (s->base.singlestep_enabled) {
16
-#ifdef CONFIG_SOFTMMU
18
- gen_exception_internal(EXCP_DEBUG);
17
#define TCG_TARGET_NEED_LDST_LABELS
19
} else {
18
-#endif
20
tcg_gen_lookup_and_goto_ptr();
19
#define TCG_TARGET_NEED_POOL_LABELS
21
s->base.is_jmp = DISAS_NORETURN;
20
22
@@ -XXX,XX +XXX,XX @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
21
#endif /* AARCH64_TCG_TARGET_H */
23
{
22
diff --git a/tcg/aarch64/tcg-target.c.inc b/tcg/aarch64/tcg-target.c.inc
24
DisasContext *dc = container_of(dcbase, DisasContext, base);
25
26
- if (unlikely(dc->base.singlestep_enabled || dc->ss_active)) {
27
+ if (unlikely(dc->ss_active)) {
28
/* Note that this means single stepping WFI doesn't halt the CPU.
29
* For conditional branch insns this is harmless unreachable code as
30
* gen_goto_tb() has already handled emitting the debug exception
31
@@ -XXX,XX +XXX,XX @@ static void aarch64_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
32
/* fall through */
33
case DISAS_EXIT:
34
case DISAS_JUMP:
35
- if (dc->base.singlestep_enabled) {
36
- gen_exception_internal(EXCP_DEBUG);
37
- } else {
38
- gen_step_complete_exception(dc);
39
- }
40
+ gen_step_complete_exception(dc);
41
break;
42
case DISAS_NORETURN:
43
break;
44
diff --git a/target/arm/translate.c b/target/arm/translate.c
45
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
46
--- a/target/arm/translate.c
24
--- a/tcg/aarch64/tcg-target.c.inc
47
+++ b/target/arm/translate.c
25
+++ b/tcg/aarch64/tcg-target.c.inc
48
@@ -XXX,XX +XXX,XX @@ static void gen_exception_internal(int excp)
26
@@ -XXX,XX +XXX,XX @@
49
tcg_temp_free_i32(tcg_excp);
27
* See the COPYING file in the top-level directory for details.
28
*/
29
30
+#include "../tcg-ldst.c.inc"
31
#include "../tcg-pool.c.inc"
32
#include "qemu/bitops.h"
33
34
@@ -XXX,XX +XXX,XX @@ typedef enum {
35
I3404_ANDI = 0x12000000,
36
I3404_ORRI = 0x32000000,
37
I3404_EORI = 0x52000000,
38
+ I3404_ANDSI = 0x72000000,
39
40
/* Move wide immediate instructions. */
41
I3405_MOVN = 0x12800000,
42
@@ -XXX,XX +XXX,XX @@ static void tcg_out_goto_long(TCGContext *s, const tcg_insn_unit *target)
43
if (offset == sextract64(offset, 0, 26)) {
44
tcg_out_insn(s, 3206, B, offset);
45
} else {
46
- tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_TMP, (intptr_t)target);
47
- tcg_out_insn(s, 3207, BR, TCG_REG_TMP);
48
+ /* Choose X9 as a call-clobbered non-LR temporary. */
49
+ tcg_out_movi(s, TCG_TYPE_I64, TCG_REG_X9, (intptr_t)target);
50
+ tcg_out_insn(s, 3207, BR, TCG_REG_X9);
51
}
50
}
52
}
51
53
52
-static void gen_step_complete_exception(DisasContext *s)
54
@@ -XXX,XX +XXX,XX @@ static void tcg_out_cltz(TCGContext *s, TCGType ext, TCGReg d,
53
+static void gen_singlestep_exception(DisasContext *s)
55
}
54
{
55
/* We just completed step of an insn. Move from Active-not-pending
56
* to Active-pending, and then also take the swstep exception.
57
@@ -XXX,XX +XXX,XX @@ static void gen_step_complete_exception(DisasContext *s)
58
s->base.is_jmp = DISAS_NORETURN;
59
}
56
}
60
57
61
-static void gen_singlestep_exception(DisasContext *s)
58
-#ifdef CONFIG_SOFTMMU
59
-#include "../tcg-ldst.c.inc"
60
+static void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
61
+{
62
+ ptrdiff_t offset = tcg_pcrel_diff(s, target);
63
+ tcg_debug_assert(offset == sextract64(offset, 0, 21));
64
+ tcg_out_insn(s, 3406, ADR, rd, offset);
65
+}
66
67
+#ifdef CONFIG_SOFTMMU
68
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
69
* MemOpIdx oi, uintptr_t ra)
70
*/
71
@@ -XXX,XX +XXX,XX @@ static void * const qemu_st_helpers[MO_SIZE + 1] = {
72
#endif
73
};
74
75
-static inline void tcg_out_adr(TCGContext *s, TCGReg rd, const void *target)
62
-{
76
-{
63
- /* Generate the right kind of exception for singlestep, which is
77
- ptrdiff_t offset = tcg_pcrel_diff(s, target);
64
- * either the architectural singlestep or EXCP_DEBUG for QEMU's
78
- tcg_debug_assert(offset == sextract64(offset, 0, 21));
65
- * gdb singlestepping.
79
- tcg_out_insn(s, 3406, ADR, rd, offset);
66
- */
67
- if (s->ss_active) {
68
- gen_step_complete_exception(s);
69
- } else {
70
- gen_exception_internal(EXCP_DEBUG);
71
- }
72
-}
80
-}
73
-
81
-
74
-static inline bool is_singlestepping(DisasContext *s)
82
static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
75
-{
83
{
76
- /* Return true if we are singlestepping either because of
84
MemOpIdx oi = lb->oi;
77
- * architectural singlestep or QEMU gdbstub singlestep. This does
85
@@ -XXX,XX +XXX,XX @@ static void tcg_out_tlb_read(TCGContext *s, TCGReg addr_reg, MemOp opc,
78
- * not include the command line '-singlestep' mode which is rather
86
tcg_out_insn(s, 3202, B_C, TCG_COND_NE, 0);
79
- * misnamed as it only means "one instruction per TB" and doesn't
87
}
80
- * affect the code we generate.
88
81
- */
89
+#else
82
- return s->base.singlestep_enabled || s->ss_active;
90
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addr_reg,
83
-}
91
+ unsigned a_bits)
92
+{
93
+ unsigned a_mask = (1 << a_bits) - 1;
94
+ TCGLabelQemuLdst *label = new_ldst_label(s);
95
+
96
+ label->is_ld = is_ld;
97
+ label->addrlo_reg = addr_reg;
98
+
99
+ /* tst addr, #mask */
100
+ tcg_out_logicali(s, I3404_ANDSI, 0, TCG_REG_XZR, addr_reg, a_mask);
101
+
102
+ label->label_ptr[0] = s->code_ptr;
103
+
104
+ /* b.ne slow_path */
105
+ tcg_out_insn(s, 3202, B_C, TCG_COND_NE, 0);
106
+
107
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr);
108
+}
109
+
110
+static bool tcg_out_fail_alignment(TCGContext *s, TCGLabelQemuLdst *l)
111
+{
112
+ if (!reloc_pc19(l->label_ptr[0], tcg_splitwx_to_rx(s->code_ptr))) {
113
+ return false;
114
+ }
115
+
116
+ tcg_out_mov(s, TCG_TYPE_TL, TCG_REG_X1, l->addrlo_reg);
117
+ tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_X0, TCG_AREG0);
118
+
119
+ /* "Tail call" to the helper, with the return address back inline. */
120
+ tcg_out_adr(s, TCG_REG_LR, l->raddr);
121
+ tcg_out_goto_long(s, (const void *)(l->is_ld ? helper_unaligned_ld
122
+ : helper_unaligned_st));
123
+ return true;
124
+}
125
+
126
+static bool tcg_out_qemu_ld_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
127
+{
128
+ return tcg_out_fail_alignment(s, l);
129
+}
130
+
131
+static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *l)
132
+{
133
+ return tcg_out_fail_alignment(s, l);
134
+}
135
#endif /* CONFIG_SOFTMMU */
136
137
static void tcg_out_qemu_ld_direct(TCGContext *s, MemOp memop, TCGType ext,
138
TCGReg data_r, TCGReg addr_r,
139
TCGType otype, TCGReg off_r)
140
{
141
- /* Byte swapping is left to middle-end expansion. */
142
- tcg_debug_assert((memop & MO_BSWAP) == 0);
84
-
143
-
85
void clear_eci_state(DisasContext *s)
144
switch (memop & MO_SSIZE) {
86
{
145
case MO_UB:
87
/*
146
tcg_out_ldst_r(s, I3312_LDRB, data_r, addr_r, otype, off_r);
88
@@ -XXX,XX +XXX,XX @@ static inline void gen_bx_excret_final_code(DisasContext *s)
147
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_direct(TCGContext *s, MemOp memop,
89
/* Is the new PC value in the magic range indicating exception return? */
148
TCGReg data_r, TCGReg addr_r,
90
tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], min_magic, excret_label);
149
TCGType otype, TCGReg off_r)
91
/* No: end the TB as we would for a DISAS_JMP */
150
{
92
- if (is_singlestepping(s)) {
151
- /* Byte swapping is left to middle-end expansion. */
93
+ if (s->ss_active) {
152
- tcg_debug_assert((memop & MO_BSWAP) == 0);
94
gen_singlestep_exception(s);
153
-
95
} else {
154
switch (memop & MO_SIZE) {
96
tcg_gen_exit_tb(NULL, 0);
155
case MO_8:
97
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *s, int n, target_ulong dest)
156
tcg_out_ldst_r(s, I3312_STRB, data_r, addr_r, otype, off_r);
98
/* Jump, specifying which TB number to use if we gen_goto_tb() */
157
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
99
static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno)
158
{
100
{
159
MemOp memop = get_memop(oi);
101
- if (unlikely(is_singlestepping(s))) {
160
const TCGType otype = TARGET_LONG_BITS == 64 ? TCG_TYPE_I64 : TCG_TYPE_I32;
102
+ if (unlikely(s->ss_active)) {
161
+
103
/* An indirect jump so that we still trigger the debug exception. */
162
+ /* Byte swapping is left to middle-end expansion. */
104
gen_set_pc_im(s, dest);
163
+ tcg_debug_assert((memop & MO_BSWAP) == 0);
105
s->base.is_jmp = DISAS_JUMP;
164
+
106
@@ -XXX,XX +XXX,XX @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
165
#ifdef CONFIG_SOFTMMU
107
dc->page_start = dc->base.pc_first & TARGET_PAGE_MASK;
166
unsigned mem_index = get_mmuidx(oi);
108
167
tcg_insn_unit *label_ptr;
109
/* If architectural single step active, limit to 1. */
168
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
110
- if (is_singlestepping(dc)) {
169
add_qemu_ldst_label(s, true, oi, ext, data_reg, addr_reg,
111
+ if (dc->ss_active) {
170
s->code_ptr, label_ptr);
112
dc->base.max_insns = 1;
171
#else /* !CONFIG_SOFTMMU */
113
}
172
+ unsigned a_bits = get_alignment_bits(memop);
114
173
+ if (a_bits) {
115
@@ -XXX,XX +XXX,XX @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
174
+ tcg_out_test_alignment(s, true, addr_reg, a_bits);
116
* insn codepath itself.
175
+ }
117
*/
176
if (USE_GUEST_BASE) {
118
gen_bx_excret_final_code(dc);
177
tcg_out_qemu_ld_direct(s, memop, ext, data_reg,
119
- } else if (unlikely(is_singlestepping(dc))) {
178
TCG_REG_GUEST_BASE, otype, addr_reg);
120
+ } else if (unlikely(dc->ss_active)) {
179
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
121
/* Unconditional and "condition passed" instruction codepath. */
180
{
122
switch (dc->base.is_jmp) {
181
MemOp memop = get_memop(oi);
123
case DISAS_SWI:
182
const TCGType otype = TARGET_LONG_BITS == 64 ? TCG_TYPE_I64 : TCG_TYPE_I32;
124
@@ -XXX,XX +XXX,XX @@ static void arm_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
183
+
125
/* "Condition failed" instruction codepath for the branch/trap insn */
184
+ /* Byte swapping is left to middle-end expansion. */
126
gen_set_label(dc->condlabel);
185
+ tcg_debug_assert((memop & MO_BSWAP) == 0);
127
gen_set_condexec(dc);
186
+
128
- if (unlikely(is_singlestepping(dc))) {
187
#ifdef CONFIG_SOFTMMU
129
+ if (unlikely(dc->ss_active)) {
188
unsigned mem_index = get_mmuidx(oi);
130
gen_set_pc_im(dc, dc->base.pc_next);
189
tcg_insn_unit *label_ptr;
131
gen_singlestep_exception(dc);
190
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data_reg, TCGReg addr_reg,
132
} else {
191
add_qemu_ldst_label(s, false, oi, (memop & MO_SIZE)== MO_64,
192
data_reg, addr_reg, s->code_ptr, label_ptr);
193
#else /* !CONFIG_SOFTMMU */
194
+ unsigned a_bits = get_alignment_bits(memop);
195
+ if (a_bits) {
196
+ tcg_out_test_alignment(s, false, addr_reg, a_bits);
197
+ }
198
if (USE_GUEST_BASE) {
199
tcg_out_qemu_st_direct(s, memop, data_reg,
200
TCG_REG_GUEST_BASE, otype, addr_reg);
133
--
201
--
134
2.25.1
202
2.25.1
135
203
136
204
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically, which means
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
we don't need to do anything in the wrappers.
3
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
3
---
7
target/riscv/translate.c | 27 +------------------
4
tcg/ppc/tcg-target.h | 2 -
8
.../riscv/insn_trans/trans_privileged.c.inc | 4 +--
5
tcg/ppc/tcg-target.c.inc | 98 ++++++++++++++++++++++++++++++++++++----
9
target/riscv/insn_trans/trans_rvi.c.inc | 8 +++---
6
2 files changed, 90 insertions(+), 10 deletions(-)
10
target/riscv/insn_trans/trans_rvv.c.inc | 2 +-
11
4 files changed, 7 insertions(+), 34 deletions(-)
12
7
13
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
8
diff --git a/tcg/ppc/tcg-target.h b/tcg/ppc/tcg-target.h
14
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
15
--- a/target/riscv/translate.c
10
--- a/tcg/ppc/tcg-target.h
16
+++ b/target/riscv/translate.c
11
+++ b/tcg/ppc/tcg-target.h
17
@@ -XXX,XX +XXX,XX @@ static void generate_exception_mtval(DisasContext *ctx, int excp)
12
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t);
18
ctx->base.is_jmp = DISAS_NORETURN;
13
#define TCG_TARGET_DEFAULT_MO (0)
19
}
14
#define TCG_TARGET_HAS_MEMORY_BSWAP 1
20
15
21
-static void gen_exception_debug(void)
16
-#ifdef CONFIG_SOFTMMU
22
-{
17
#define TCG_TARGET_NEED_LDST_LABELS
23
- gen_helper_raise_exception(cpu_env, tcg_constant_i32(EXCP_DEBUG));
18
-#endif
24
-}
19
#define TCG_TARGET_NEED_POOL_LABELS
25
-
20
26
-/* Wrapper around tcg_gen_exit_tb that handles single stepping */
21
#endif
27
-static void exit_tb(DisasContext *ctx)
22
diff --git a/tcg/ppc/tcg-target.c.inc b/tcg/ppc/tcg-target.c.inc
28
-{
23
index XXXXXXX..XXXXXXX 100644
29
- if (ctx->base.singlestep_enabled) {
24
--- a/tcg/ppc/tcg-target.c.inc
30
- gen_exception_debug();
25
+++ b/tcg/ppc/tcg-target.c.inc
31
- } else {
26
@@ -XXX,XX +XXX,XX @@
32
- tcg_gen_exit_tb(NULL, 0);
27
33
- }
28
#include "elf.h"
34
-}
29
#include "../tcg-pool.c.inc"
35
-
30
+#include "../tcg-ldst.c.inc"
36
-/* Wrapper around tcg_gen_lookup_and_goto_ptr that handles single stepping */
31
37
-static void lookup_and_goto_ptr(DisasContext *ctx)
32
/*
38
-{
33
* Standardize on the _CALL_FOO symbols used by GCC:
39
- if (ctx->base.singlestep_enabled) {
34
@@ -XXX,XX +XXX,XX @@ void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
40
- gen_exception_debug();
41
- } else {
42
- tcg_gen_lookup_and_goto_ptr();
43
- }
44
-}
45
-
46
static void gen_exception_illegal(DisasContext *ctx)
47
{
48
generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST);
49
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
50
tcg_gen_exit_tb(ctx->base.tb, n);
51
} else {
52
tcg_gen_movi_tl(cpu_pc, dest);
53
- lookup_and_goto_ptr(ctx);
54
+ tcg_gen_lookup_and_goto_ptr();
55
}
35
}
56
}
36
}
57
37
58
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
38
-static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
59
index XXXXXXX..XXXXXXX 100644
39
+static void tcg_out_call_int(TCGContext *s, int lk,
60
--- a/target/riscv/insn_trans/trans_privileged.c.inc
40
+ const tcg_insn_unit *target)
61
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
41
{
62
@@ -XXX,XX +XXX,XX @@ static bool trans_sret(DisasContext *ctx, arg_sret *a)
42
#ifdef _CALL_AIX
63
43
/* Look through the descriptor. If the branch is in range, and we
64
if (has_ext(ctx, RVS)) {
44
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
65
gen_helper_sret(cpu_pc, cpu_env, cpu_pc);
45
66
- exit_tb(ctx); /* no chaining */
46
if (in_range_b(diff) && toc == (uint32_t)toc) {
67
+ tcg_gen_exit_tb(NULL, 0); /* no chaining */
47
tcg_out_movi(s, TCG_TYPE_PTR, TCG_REG_TMP1, toc);
68
ctx->base.is_jmp = DISAS_NORETURN;
48
- tcg_out_b(s, LK, tgt);
49
+ tcg_out_b(s, lk, tgt);
69
} else {
50
} else {
70
return false;
51
/* Fold the low bits of the constant into the addresses below. */
71
@@ -XXX,XX +XXX,XX @@ static bool trans_mret(DisasContext *ctx, arg_mret *a)
52
intptr_t arg = (intptr_t)target;
72
#ifndef CONFIG_USER_ONLY
53
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
73
tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
54
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R0, TCG_REG_TMP1, ofs);
74
gen_helper_mret(cpu_pc, cpu_env, cpu_pc);
55
tcg_out32(s, MTSPR | RA(TCG_REG_R0) | CTR);
75
- exit_tb(ctx); /* no chaining */
56
tcg_out_ld(s, TCG_TYPE_PTR, TCG_REG_R2, TCG_REG_TMP1, ofs + SZP);
76
+ tcg_gen_exit_tb(NULL, 0); /* no chaining */
57
- tcg_out32(s, BCCTR | BO_ALWAYS | LK);
77
ctx->base.is_jmp = DISAS_NORETURN;
58
+ tcg_out32(s, BCCTR | BO_ALWAYS | lk);
78
return true;
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
}
79
#else
73
#else
80
diff --git a/target/riscv/insn_trans/trans_rvi.c.inc b/target/riscv/insn_trans/trans_rvi.c.inc
74
- tcg_out_b(s, LK, target);
81
index XXXXXXX..XXXXXXX 100644
75
+ tcg_out_b(s, lk, target);
82
--- a/target/riscv/insn_trans/trans_rvi.c.inc
76
#endif
83
+++ b/target/riscv/insn_trans/trans_rvi.c.inc
77
}
84
@@ -XXX,XX +XXX,XX @@ static bool trans_jalr(DisasContext *ctx, arg_jalr *a)
78
85
if (a->rd != 0) {
79
+static void tcg_out_call(TCGContext *s, const tcg_insn_unit *target)
86
tcg_gen_movi_tl(cpu_gpr[a->rd], ctx->pc_succ_insn);
80
+{
87
}
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"
88
-
92
-
89
- /* No chaining with JALR. */
93
/* helper signature: helper_ld_mmu(CPUState *env, target_ulong addr,
90
- lookup_and_goto_ptr(ctx);
94
* int mmu_idx, uintptr_t ra)
91
+ tcg_gen_lookup_and_goto_ptr();
95
*/
92
96
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
93
if (misaligned) {
97
tcg_out_b(s, 0, lb->raddr);
94
gen_set_label(misaligned);
95
@@ -XXX,XX +XXX,XX @@ static bool trans_fence_i(DisasContext *ctx, arg_fence_i *a)
96
* however we need to end the translation block
97
*/
98
tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn);
99
- exit_tb(ctx);
100
+ tcg_gen_exit_tb(NULL, 0);
101
ctx->base.is_jmp = DISAS_NORETURN;
102
return true;
98
return true;
103
}
99
}
104
@@ -XXX,XX +XXX,XX @@ static bool do_csr_post(DisasContext *ctx)
100
+#else
105
{
101
+
106
/* We may have changed important cpu state -- exit to main loop. */
102
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
107
tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn);
103
+ TCGReg addrhi, unsigned a_bits)
108
- exit_tb(ctx);
104
+{
109
+ tcg_gen_exit_tb(NULL, 0);
105
+ unsigned a_mask = (1 << a_bits) - 1;
110
ctx->base.is_jmp = DISAS_NORETURN;
106
+ TCGLabelQemuLdst *label = new_ldst_label(s);
111
return true;
107
+
112
}
108
+ label->is_ld = is_ld;
113
diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc
109
+ label->addrlo_reg = addrlo;
114
index XXXXXXX..XXXXXXX 100644
110
+ label->addrhi_reg = addrhi;
115
--- a/target/riscv/insn_trans/trans_rvv.c.inc
111
+
116
+++ b/target/riscv/insn_trans/trans_rvv.c.inc
112
+ /* We are expecting a_bits to max out at 7, much lower than ANDI. */
117
@@ -XXX,XX +XXX,XX @@ static bool trans_vsetvl(DisasContext *ctx, arg_vsetvl *a)
113
+ tcg_debug_assert(a_bits < 16);
118
gen_set_gpr(ctx, a->rd, dst);
114
+ tcg_out32(s, ANDI | SAI(addrlo, TCG_REG_R0, a_mask));
119
115
+
120
tcg_gen_movi_tl(cpu_pc, ctx->pc_succ_insn);
116
+ label->label_ptr[0] = s->code_ptr;
121
- lookup_and_goto_ptr(ctx);
117
+ tcg_out32(s, BC | BI(0, CR_EQ) | BO_COND_FALSE | LK);
122
+ tcg_gen_lookup_and_goto_ptr();
118
+
123
ctx->base.is_jmp = DISAS_NORETURN;
119
+ label->raddr = tcg_splitwx_to_rx(s->code_ptr);
124
return true;
120
+}
125
}
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);
126
--
208
--
127
2.25.1
209
2.25.1
128
210
129
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
1
GDB single-stepping is now handled generically.
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
3
---
6
target/rx/helper.h | 1 -
4
tcg/s390x/tcg-target.h | 2 --
7
target/rx/op_helper.c | 8 --------
5
tcg/s390x/tcg-target.c.inc | 59 ++++++++++++++++++++++++++++++++++++--
8
target/rx/translate.c | 12 ++----------
6
2 files changed, 57 insertions(+), 4 deletions(-)
9
3 files changed, 2 insertions(+), 19 deletions(-)
10
7
11
diff --git a/target/rx/helper.h b/target/rx/helper.h
8
diff --git a/tcg/s390x/tcg-target.h b/tcg/s390x/tcg-target.h
12
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
13
--- a/target/rx/helper.h
10
--- a/tcg/s390x/tcg-target.h
14
+++ b/target/rx/helper.h
11
+++ b/tcg/s390x/tcg-target.h
15
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(raise_illegal_instruction, noreturn, env)
12
@@ -XXX,XX +XXX,XX @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr, uintptr_t jmp_rx,
16
DEF_HELPER_1(raise_access_fault, noreturn, env)
13
/* no need to flush icache explicitly */
17
DEF_HELPER_1(raise_privilege_violation, noreturn, env)
14
}
18
DEF_HELPER_1(wait, noreturn, env)
15
19
-DEF_HELPER_1(debug, noreturn, env)
16
-#ifdef CONFIG_SOFTMMU
20
DEF_HELPER_2(rxint, noreturn, env, i32)
17
#define TCG_TARGET_NEED_LDST_LABELS
21
DEF_HELPER_1(rxbrk, noreturn, env)
18
-#endif
22
DEF_HELPER_FLAGS_3(fadd, TCG_CALL_NO_WG, f32, env, f32, f32)
19
#define TCG_TARGET_NEED_POOL_LABELS
23
diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c
20
21
#endif
22
diff --git a/tcg/s390x/tcg-target.c.inc b/tcg/s390x/tcg-target.c.inc
24
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
25
--- a/target/rx/op_helper.c
24
--- a/tcg/s390x/tcg-target.c.inc
26
+++ b/target/rx/op_helper.c
25
+++ b/tcg/s390x/tcg-target.c.inc
27
@@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN helper_wait(CPURXState *env)
26
@@ -XXX,XX +XXX,XX @@
28
raise_exception(env, EXCP_HLT, 0);
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,
29
}
43
}
30
44
31
-void QEMU_NORETURN helper_debug(CPURXState *env)
45
#if defined(CONFIG_SOFTMMU)
32
-{
46
-#include "../tcg-ldst.c.inc"
33
- CPUState *cs = env_cpu(env);
34
-
47
-
35
- cs->exception_index = EXCP_DEBUG;
48
/* We're expecting to use a 20-bit negative offset on the tlb memory ops. */
36
- cpu_loop_exit(cs);
49
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) > 0);
37
-}
50
QEMU_BUILD_BUG_ON(TLB_MASK_TABLE_OFS(0) < -(1 << 19));
38
-
51
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
39
void QEMU_NORETURN helper_rxint(CPURXState *env, uint32_t vec)
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)
40
{
104
{
41
raise_exception(env, 0x100 + vec, 0);
105
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext* s, TCGReg data_reg, TCGReg addr_reg,
42
diff --git a/target/rx/translate.c b/target/rx/translate.c
106
#else
43
index XXXXXXX..XXXXXXX 100644
107
TCGReg index_reg;
44
--- a/target/rx/translate.c
108
tcg_target_long disp;
45
+++ b/target/rx/translate.c
109
+ unsigned a_bits = get_alignment_bits(opc);
46
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest)
110
47
tcg_gen_exit_tb(dc->base.tb, n);
111
+ if (a_bits) {
48
} else {
112
+ tcg_out_test_alignment(s, true, addr_reg, a_bits);
49
tcg_gen_movi_i32(cpu_pc, dest);
113
+ }
50
- if (dc->base.singlestep_enabled) {
114
tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp);
51
- gen_helper_debug(cpu_env);
115
tcg_out_qemu_ld_direct(s, opc, data_reg, addr_reg, index_reg, disp);
52
- } else {
116
#endif
53
- tcg_gen_lookup_and_goto_ptr();
117
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext* s, TCGReg data_reg, TCGReg addr_reg,
54
- }
118
#else
55
+ tcg_gen_lookup_and_goto_ptr();
119
TCGReg index_reg;
56
}
120
tcg_target_long disp;
57
dc->base.is_jmp = DISAS_NORETURN;
121
+ unsigned a_bits = get_alignment_bits(opc);
58
}
122
59
@@ -XXX,XX +XXX,XX @@ static void rx_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
123
+ if (a_bits) {
60
gen_goto_tb(ctx, 0, dcbase->pc_next);
124
+ tcg_out_test_alignment(s, false, addr_reg, a_bits);
61
break;
125
+ }
62
case DISAS_JUMP:
126
tcg_prepare_user_ldst(s, &addr_reg, &index_reg, &disp);
63
- if (ctx->base.singlestep_enabled) {
127
tcg_out_qemu_st_direct(s, opc, data_reg, addr_reg, index_reg, disp);
64
- gen_helper_debug(cpu_env);
128
#endif
65
- } else {
66
- tcg_gen_lookup_and_goto_ptr();
67
- }
68
+ tcg_gen_lookup_and_goto_ptr();
69
break;
70
case DISAS_UPDATE:
71
tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next);
72
--
129
--
73
2.25.1
130
2.25.1
74
131
75
132
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
2
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
3
---
6
target/openrisc/translate.c | 18 +++---------------
4
tcg/tci.c | 20 ++++++++++++++------
7
1 file changed, 3 insertions(+), 15 deletions(-)
5
1 file changed, 14 insertions(+), 6 deletions(-)
8
6
9
diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c
7
diff --git a/tcg/tci.c b/tcg/tci.c
10
index XXXXXXX..XXXXXXX 100644
8
index XXXXXXX..XXXXXXX 100644
11
--- a/target/openrisc/translate.c
9
--- a/tcg/tci.c
12
+++ b/target/openrisc/translate.c
10
+++ b/tcg/tci.c
13
@@ -XXX,XX +XXX,XX @@ static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
11
@@ -XXX,XX +XXX,XX @@ static bool tci_compare64(uint64_t u0, uint64_t u1, TCGCond condition)
14
/* The jump destination is indirect/computed; use jmp_pc. */
12
static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
15
tcg_gen_mov_tl(cpu_pc, jmp_pc);
13
MemOpIdx oi, const void *tb_ptr)
16
tcg_gen_discard_tl(jmp_pc);
14
{
17
- if (unlikely(dc->base.singlestep_enabled)) {
15
- MemOp mop = get_memop(oi) & (MO_BSWAP | MO_SSIZE);
18
- gen_exception(dc, EXCP_DEBUG);
16
+ MemOp mop = get_memop(oi);
19
- } else {
17
uintptr_t ra = (uintptr_t)tb_ptr;
20
- tcg_gen_lookup_and_goto_ptr();
18
21
- }
19
#ifdef CONFIG_SOFTMMU
22
+ tcg_gen_lookup_and_goto_ptr();
20
- switch (mop) {
23
break;
21
+ switch (mop & (MO_BSWAP | MO_SSIZE)) {
24
}
22
case MO_UB:
25
/* The jump destination is direct; use jmp_pc_imm.
23
return helper_ret_ldub_mmu(env, taddr, oi, ra);
26
@@ -XXX,XX +XXX,XX @@ static void openrisc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
24
case MO_SB:
27
break;
25
@@ -XXX,XX +XXX,XX @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
28
}
26
}
29
tcg_gen_movi_tl(cpu_pc, jmp_dest);
27
#else
30
- if (unlikely(dc->base.singlestep_enabled)) {
28
void *haddr = g2h(env_cpu(env), taddr);
31
- gen_exception(dc, EXCP_DEBUG);
29
+ unsigned a_mask = (1u << get_alignment_bits(mop)) - 1;
32
- } else {
30
uint64_t ret;
33
- tcg_gen_lookup_and_goto_ptr();
31
34
- }
32
set_helper_retaddr(ra);
35
+ tcg_gen_lookup_and_goto_ptr();
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);
36
break;
40
break;
37
41
@@ -XXX,XX +XXX,XX @@ static uint64_t tci_qemu_ld(CPUArchState *env, target_ulong taddr,
38
case DISAS_EXIT:
42
static void tci_qemu_st(CPUArchState *env, target_ulong taddr, uint64_t val,
39
- if (unlikely(dc->base.singlestep_enabled)) {
43
MemOpIdx oi, const void *tb_ptr)
40
- gen_exception(dc, EXCP_DEBUG);
44
{
41
- } else {
45
- MemOp mop = get_memop(oi) & (MO_BSWAP | MO_SSIZE);
42
- tcg_gen_exit_tb(NULL, 0);
46
+ MemOp mop = get_memop(oi);
43
- }
47
uintptr_t ra = (uintptr_t)tb_ptr;
44
+ tcg_gen_exit_tb(NULL, 0);
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);
45
break;
54
break;
46
default:
55
@@ -XXX,XX +XXX,XX @@ static void tci_qemu_st(CPUArchState *env, target_ulong taddr, uint64_t val,
47
g_assert_not_reached();
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;
48
--
70
--
49
2.25.1
71
2.25.1
50
72
51
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
1
GDB single-stepping is now handled generically.
1
This is now always true, since we require armv6.
2
Reuse gen_debug_exception to handle architectural debug exceptions.
3
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
5
---
6
target/ppc/translate.c | 38 ++++++++------------------------------
6
tcg/arm/tcg-target.h | 3 +--
7
1 file changed, 8 insertions(+), 30 deletions(-)
7
tcg/arm/tcg-target.c.inc | 35 ++++++-----------------------------
8
2 files changed, 7 insertions(+), 31 deletions(-)
8
9
9
diff --git a/target/ppc/translate.c b/target/ppc/translate.c
10
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
10
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
11
--- a/target/ppc/translate.c
12
--- a/tcg/arm/tcg-target.h
12
+++ b/target/ppc/translate.c
13
+++ b/tcg/arm/tcg-target.h
13
@@ -XXX,XX +XXX,XX @@
14
@@ -XXX,XX +XXX,XX @@
14
15
15
#define CPU_SINGLE_STEP 0x1
16
extern int arm_arch;
16
#define CPU_BRANCH_STEP 0x2
17
17
-#define GDBSTUB_SINGLE_STEP 0x4
18
-#define use_armv5t_instructions (__ARM_ARCH >= 5 || arm_arch >= 5)
18
19
#define use_armv6_instructions (__ARM_ARCH >= 6 || arm_arch >= 6)
19
/* Include definitions for instructions classes and implementations flags */
20
#define use_armv7_instructions (__ARM_ARCH >= 7 || arm_arch >= 7)
20
/* #define PPC_DEBUG_DISAS */
21
21
@@ -XXX,XX +XXX,XX @@ static uint32_t gen_prep_dbgex(DisasContext *ctx)
22
@@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions;
22
23
#define TCG_TARGET_HAS_eqv_i32 0
23
static void gen_debug_exception(DisasContext *ctx)
24
#define TCG_TARGET_HAS_nand_i32 0
24
{
25
#define TCG_TARGET_HAS_nor_i32 0
25
- gen_helper_raise_exception(cpu_env, tcg_constant_i32(EXCP_DEBUG));
26
-#define TCG_TARGET_HAS_clz_i32 use_armv5t_instructions
26
+ gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx)));
27
+#define TCG_TARGET_HAS_clz_i32 1
27
ctx->base.is_jmp = DISAS_NORETURN;
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);
28
}
45
}
29
46
30
@@ -XXX,XX +XXX,XX @@ static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest)
47
static void tcg_out_dat_imm(TCGContext *s, ARMCond cond, ARMInsn opc,
31
48
@@ -XXX,XX +XXX,XX @@ static void tcg_out_goto(TCGContext *s, ARMCond cond, const tcg_insn_unit *addr)
32
static void gen_lookup_and_goto_ptr(DisasContext *ctx)
33
{
34
- int sse = ctx->singlestep_enabled;
35
- if (unlikely(sse)) {
36
- if (sse & GDBSTUB_SINGLE_STEP) {
37
- gen_debug_exception(ctx);
38
- } else if (sse & (CPU_SINGLE_STEP | CPU_BRANCH_STEP)) {
39
- gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx)));
40
- } else {
41
- tcg_gen_exit_tb(NULL, 0);
42
- }
43
+ if (unlikely(ctx->singlestep_enabled)) {
44
+ gen_debug_exception(ctx);
45
} else {
46
tcg_gen_lookup_and_goto_ptr();
47
}
49
}
48
@@ -XXX,XX +XXX,XX @@ static void ppc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
50
49
ctx->singlestep_enabled = 0;
51
/* LDR is interworking from v5t. */
50
if ((hflags >> HFLAGS_SE) & 1) {
52
- if (arm_mode || use_armv5t_instructions) {
51
ctx->singlestep_enabled |= CPU_SINGLE_STEP;
53
- tcg_out_movi_pool(s, cond, TCG_REG_PC, addri);
52
+ ctx->base.max_insns = 1;
54
- return;
53
}
54
if ((hflags >> HFLAGS_BE) & 1) {
55
ctx->singlestep_enabled |= CPU_BRANCH_STEP;
56
}
57
- if (unlikely(ctx->base.singlestep_enabled)) {
58
- ctx->singlestep_enabled |= GDBSTUB_SINGLE_STEP;
59
- }
55
- }
60
-
56
-
61
- if (ctx->singlestep_enabled & (CPU_SINGLE_STEP | GDBSTUB_SINGLE_STEP)) {
57
- /* else v4t */
62
- ctx->base.max_insns = 1;
58
- tcg_out_movi32(s, COND_AL, TCG_REG_TMP, addri);
63
- }
59
- tcg_out_bx_reg(s, COND_AL, TCG_REG_TMP);
60
+ tcg_out_movi_pool(s, cond, TCG_REG_PC, addri);
64
}
61
}
65
62
66
static void ppc_tr_tb_start(DisasContextBase *db, CPUState *cs)
63
/*
67
@@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
64
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call(TCGContext *s, const tcg_insn_unit *addr)
68
DisasContext *ctx = container_of(dcbase, DisasContext, base);
65
if (disp - 8 < 0x02000000 && disp - 8 >= -0x02000000) {
69
DisasJumpType is_jmp = ctx->base.is_jmp;
66
if (arm_mode) {
70
target_ulong nip = ctx->base.pc_next;
67
tcg_out_bl_imm(s, COND_AL, disp);
71
- int sse;
72
73
if (is_jmp == DISAS_NORETURN) {
74
/* We have already exited the TB. */
75
@@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
76
}
77
78
/* Honor single stepping. */
79
- sse = ctx->singlestep_enabled & (CPU_SINGLE_STEP | GDBSTUB_SINGLE_STEP);
80
- if (unlikely(sse)) {
81
+ if (unlikely(ctx->singlestep_enabled & CPU_SINGLE_STEP)
82
+ && (nip <= 0x100 || nip > 0xf00)) {
83
switch (is_jmp) {
84
case DISAS_TOO_MANY:
85
case DISAS_EXIT_UPDATE:
86
@@ -XXX,XX +XXX,XX @@ static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
87
g_assert_not_reached();
88
}
89
90
- if (sse & GDBSTUB_SINGLE_STEP) {
91
- gen_debug_exception(ctx);
92
- return;
68
- return;
93
- }
69
- }
94
- /* else CPU_SINGLE_STEP... */
70
- if (use_armv5t_instructions) {
95
- if (nip <= 0x100 || nip > 0xf00) {
71
+ } else {
96
- gen_helper_raise_exception(cpu_env, tcg_constant_i32(gen_prep_dbgex(ctx)));
72
tcg_out_blx_imm(s, disp);
97
- return;
73
- return;
98
- }
74
}
99
+ gen_debug_exception(ctx);
100
+ return;
75
+ return;
101
}
76
}
102
77
103
switch (is_jmp) {
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)
104
--
95
--
105
2.25.1
96
2.25.1
106
97
107
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
1
GDB single-stepping is now handled generically.
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.
2
3
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
6
---
5
target/xtensa/translate.c | 25 ++++++++-----------------
7
tcg/arm/tcg-target.c.inc | 39 ++++++++++++++++++++++++++++-----------
6
1 file changed, 8 insertions(+), 17 deletions(-)
8
1 file changed, 28 insertions(+), 11 deletions(-)
7
9
8
diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c
10
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
9
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
10
--- a/target/xtensa/translate.c
12
--- a/tcg/arm/tcg-target.c.inc
11
+++ b/target/xtensa/translate.c
13
+++ b/tcg/arm/tcg-target.c.inc
12
@@ -XXX,XX +XXX,XX @@ static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot)
14
@@ -XXX,XX +XXX,XX @@ static const int tcg_target_call_oarg_regs[2] = {
13
if (dc->icount) {
15
14
tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount);
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);
15
}
60
}
16
- if (dc->base.singlestep_enabled) {
61
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is64)
17
- gen_exception(dc, EXCP_DEBUG);
62
18
+ if (dc->op_flags & XTENSA_OP_POSTPROCESS) {
63
static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
19
+ slot = gen_postprocess(dc, slot);
64
TCGReg datalo, TCGReg datahi,
20
+ }
65
- TCGReg addrlo, TCGReg addend)
21
+ if (slot >= 0) {
66
+ TCGReg addrlo, TCGReg addend,
22
+ tcg_gen_goto_tb(slot);
67
+ bool scratch_addend)
23
+ tcg_gen_exit_tb(dc->base.tb, slot);
68
{
24
} else {
69
/* Byte swapping is left to middle-end expansion. */
25
- if (dc->op_flags & XTENSA_OP_POSTPROCESS) {
70
tcg_debug_assert((opc & MO_BSWAP) == 0);
26
- slot = gen_postprocess(dc, slot);
71
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st_index(TCGContext *s, ARMCond cond, MemOp opc,
27
- }
72
if (get_alignment_bits(opc) >= MO_64
28
- if (slot >= 0) {
73
&& (datalo & 1) == 0 && datahi == datalo + 1) {
29
- tcg_gen_goto_tb(slot);
74
tcg_out_strd_r(s, cond, datalo, addrlo, addend);
30
- tcg_gen_exit_tb(dc->base.tb, slot);
31
- } else {
75
- } else {
32
- tcg_gen_exit_tb(NULL, 0);
76
+ } else if (scratch_addend) {
33
- }
77
tcg_out_st32_rwb(s, cond, datalo, addend, addrlo);
34
+ tcg_gen_exit_tb(NULL, 0);
78
tcg_out_st32_12(s, cond, datahi, addend, 4);
35
}
79
+ } else {
36
dc->base.is_jmp = DISAS_NORETURN;
80
+ tcg_out_dat_reg(s, cond, ARITH_ADD, TCG_REG_TMP,
37
}
81
+ addend, addrlo, SHIFT_IMM_LSL(0));
38
@@ -XXX,XX +XXX,XX @@ static void xtensa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
82
+ tcg_out_st32_12(s, cond, datalo, TCG_REG_TMP, 0);
39
case DISAS_NORETURN:
83
+ tcg_out_st32_12(s, cond, datahi, TCG_REG_TMP, 4);
40
break;
84
}
41
case DISAS_TOO_MANY:
42
- if (dc->base.singlestep_enabled) {
43
- tcg_gen_movi_i32(cpu_pc, dc->pc);
44
- gen_exception(dc, EXCP_DEBUG);
45
- } else {
46
- gen_jumpi(dc, dc->pc, 0);
47
- }
48
+ gen_jumpi(dc, dc->pc, 0);
49
break;
85
break;
50
default:
86
default:
51
g_assert_not_reached();
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
/*
52
--
123
--
53
2.25.1
124
2.25.1
54
125
55
126
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
3
---
5
target/i386/helper.h | 1 -
4
tcg/arm/tcg-target.h | 2 -
6
target/i386/tcg/misc_helper.c | 8 --------
5
tcg/arm/tcg-target.c.inc | 83 +++++++++++++++++++++++++++++++++++++++-
7
target/i386/tcg/translate.c | 4 +---
6
2 files changed, 81 insertions(+), 4 deletions(-)
8
3 files changed, 1 insertion(+), 12 deletions(-)
9
7
10
diff --git a/target/i386/helper.h b/target/i386/helper.h
8
diff --git a/tcg/arm/tcg-target.h b/tcg/arm/tcg-target.h
11
index XXXXXXX..XXXXXXX 100644
9
index XXXXXXX..XXXXXXX 100644
12
--- a/target/i386/helper.h
10
--- a/tcg/arm/tcg-target.h
13
+++ b/target/i386/helper.h
11
+++ b/tcg/arm/tcg-target.h
14
@@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(syscall, void, env, int)
12
@@ -XXX,XX +XXX,XX @@ extern bool use_neon_instructions;
15
DEF_HELPER_2(sysret, void, env, int)
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
16
#endif
21
#endif
17
DEF_HELPER_FLAGS_2(pause, TCG_CALL_NO_WG, noreturn, env, int)
22
diff --git a/tcg/arm/tcg-target.c.inc b/tcg/arm/tcg-target.c.inc
18
-DEF_HELPER_FLAGS_1(debug, TCG_CALL_NO_WG, noreturn, env)
19
DEF_HELPER_1(reset_rf, void, env)
20
DEF_HELPER_FLAGS_3(raise_interrupt, TCG_CALL_NO_WG, noreturn, env, int, int)
21
DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, int)
22
diff --git a/target/i386/tcg/misc_helper.c b/target/i386/tcg/misc_helper.c
23
index XXXXXXX..XXXXXXX 100644
23
index XXXXXXX..XXXXXXX 100644
24
--- a/target/i386/tcg/misc_helper.c
24
--- a/tcg/arm/tcg-target.c.inc
25
+++ b/target/i386/tcg/misc_helper.c
25
+++ b/tcg/arm/tcg-target.c.inc
26
@@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN helper_pause(CPUX86State *env, int next_eip_addend)
26
@@ -XXX,XX +XXX,XX @@
27
do_pause(env);
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,
28
}
35
}
29
36
30
-void QEMU_NORETURN helper_debug(CPUX86State *env)
37
#ifdef CONFIG_SOFTMMU
31
-{
38
-#include "../tcg-ldst.c.inc"
32
- CPUState *cs = env_cpu(env);
33
-
39
-
34
- cs->exception_index = EXCP_DEBUG;
40
/* helper signature: helper_ret_ld_mmu(CPUState *env, target_ulong addr,
35
- cpu_loop_exit(cs);
41
* int mmu_idx, uintptr_t ra)
36
-}
42
*/
37
-
43
@@ -XXX,XX +XXX,XX @@ static bool tcg_out_qemu_st_slow_path(TCGContext *s, TCGLabelQemuLdst *lb)
38
uint64_t helper_rdpkru(CPUX86State *env, uint32_t ecx)
44
tcg_out_goto(s, COND_AL, qemu_st_helpers[opc & MO_SIZE]);
39
{
45
return true;
40
if ((env->cr[4] & CR4_PKE_MASK) == 0) {
46
}
41
diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
47
+#else
42
index XXXXXXX..XXXXXXX 100644
48
+
43
--- a/target/i386/tcg/translate.c
49
+static void tcg_out_test_alignment(TCGContext *s, bool is_ld, TCGReg addrlo,
44
+++ b/target/i386/tcg/translate.c
50
+ TCGReg addrhi, unsigned a_bits)
45
@@ -XXX,XX +XXX,XX @@ do_gen_eob_worker(DisasContext *s, bool inhibit, bool recheck_tf, bool jr)
51
+{
46
if (s->base.tb->flags & HF_RF_MASK) {
52
+ unsigned a_mask = (1 << a_bits) - 1;
47
gen_helper_reset_rf(cpu_env);
53
+ TCGLabelQemuLdst *label = new_ldst_label(s);
48
}
54
+
49
- if (s->base.singlestep_enabled) {
55
+ label->is_ld = is_ld;
50
- gen_helper_debug(cpu_env);
56
+ label->addrlo_reg = addrlo;
51
- } else if (recheck_tf) {
57
+ label->addrhi_reg = addrhi;
52
+ if (recheck_tf) {
58
+
53
gen_helper_rechecking_single_step(cpu_env);
59
+ /* We are expecting a_bits to max out at 7, and can easily support 8. */
54
tcg_gen_exit_tb(NULL, 0);
60
+ tcg_debug_assert(a_mask <= 0xff);
55
} else if (s->flags & HF_TF_MASK) {
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);
56
--
158
--
57
2.25.1
159
2.25.1
58
160
59
161
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
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.
2
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>
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
11
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
12
---
6
target/mips/tcg/translate.c | 50 +++++++++++++------------------------
13
tcg/mips/tcg-target.h | 2 -
7
1 file changed, 18 insertions(+), 32 deletions(-)
14
tcg/mips/tcg-target.c.inc | 334 +++++++++++++++++++++++++++++++++++++-
15
2 files changed, 328 insertions(+), 8 deletions(-)
8
16
9
diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c
17
diff --git a/tcg/mips/tcg-target.h b/tcg/mips/tcg-target.h
10
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
11
--- a/target/mips/tcg/translate.c
19
--- a/tcg/mips/tcg-target.h
12
+++ b/target/mips/tcg/translate.c
20
+++ b/tcg/mips/tcg-target.h
13
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
21
@@ -XXX,XX +XXX,XX @@ extern bool use_mips32r2_instructions;
14
tcg_gen_exit_tb(ctx->base.tb, n);
22
void tb_target_set_jmp_target(uintptr_t, uintptr_t, uintptr_t, uintptr_t)
15
} else {
23
QEMU_ERROR("code path is reachable");
16
gen_save_pc(dest);
24
17
- if (ctx->base.singlestep_enabled) {
25
-#ifdef CONFIG_SOFTMMU
18
- save_cpu_state(ctx, 0);
26
#define TCG_TARGET_NEED_LDST_LABELS
19
- gen_helper_raise_exception_debug(cpu_env);
27
-#endif
20
- } else {
28
21
- tcg_gen_lookup_and_goto_ptr();
29
#endif
22
- }
30
diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc
23
+ tcg_gen_lookup_and_goto_ptr();
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,
24
}
164
}
25
}
165
}
26
166
27
@@ -XXX,XX +XXX,XX @@ static void gen_branch(DisasContext *ctx, int insn_bytes)
167
+static void __attribute__((unused))
28
} else {
168
+tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
29
tcg_gen_mov_tl(cpu_PC, btarget);
169
+ TCGReg base, MemOp opc, bool is_64)
30
}
170
+{
31
- if (ctx->base.singlestep_enabled) {
171
+ const MIPSInsn lw1 = MIPS_BE ? OPC_LWL : OPC_LWR;
32
- save_cpu_state(ctx, 0);
172
+ const MIPSInsn lw2 = MIPS_BE ? OPC_LWR : OPC_LWL;
33
- gen_helper_raise_exception_debug(cpu_env);
173
+ const MIPSInsn ld1 = MIPS_BE ? OPC_LDL : OPC_LDR;
34
- }
174
+ const MIPSInsn ld2 = MIPS_BE ? OPC_LDR : OPC_LDL;
35
tcg_gen_lookup_and_goto_ptr();
175
+
36
break;
176
+ bool sgn = (opc & MO_SIGN);
37
default:
177
+
38
@@ -XXX,XX +XXX,XX @@ static void mips_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
178
+ switch (opc & (MO_SSIZE | MO_BSWAP)) {
39
{
179
+ case MO_SW | MO_BE:
40
DisasContext *ctx = container_of(dcbase, DisasContext, base);
180
+ case MO_UW | MO_BE:
41
181
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 0);
42
- if (ctx->base.singlestep_enabled && ctx->base.is_jmp != DISAS_NORETURN) {
182
+ tcg_out_opc_imm(s, OPC_LBU, lo, base, 1);
43
- save_cpu_state(ctx, ctx->base.is_jmp != DISAS_EXIT);
183
+ if (use_mips32r2_instructions) {
44
- gen_helper_raise_exception_debug(cpu_env);
184
+ tcg_out_opc_bf(s, OPC_INS, lo, TCG_TMP0, 31, 8);
45
- } else {
185
+ } else {
46
- switch (ctx->base.is_jmp) {
186
+ tcg_out_opc_sa(s, OPC_SLL, TCG_TMP0, TCG_TMP0, 8);
47
- case DISAS_STOP:
187
+ tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1);
48
- gen_save_pc(ctx->base.pc_next);
188
+ }
49
- tcg_gen_lookup_and_goto_ptr();
189
+ break;
50
- break;
190
+
51
- case DISAS_NEXT:
191
+ case MO_SW | MO_LE:
52
- case DISAS_TOO_MANY:
192
+ case MO_UW | MO_LE:
53
- save_cpu_state(ctx, 0);
193
+ if (use_mips32r2_instructions && lo != base) {
54
- gen_goto_tb(ctx, 0, ctx->base.pc_next);
194
+ tcg_out_opc_imm(s, OPC_LBU, lo, base, 0);
55
- break;
195
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP0, base, 1);
56
- case DISAS_EXIT:
196
+ tcg_out_opc_bf(s, OPC_INS, lo, TCG_TMP0, 31, 8);
57
- tcg_gen_exit_tb(NULL, 0);
197
+ } else {
58
- break;
198
+ tcg_out_opc_imm(s, OPC_LBU, TCG_TMP0, base, 0);
59
- case DISAS_NORETURN:
199
+ tcg_out_opc_imm(s, sgn ? OPC_LB : OPC_LBU, TCG_TMP1, base, 1);
60
- break;
200
+ tcg_out_opc_sa(s, OPC_SLL, TCG_TMP1, TCG_TMP1, 8);
61
- default:
201
+ tcg_out_opc_reg(s, OPC_OR, lo, TCG_TMP0, TCG_TMP1);
62
- g_assert_not_reached();
202
+ }
63
- }
203
+ break;
64
+ switch (ctx->base.is_jmp) {
204
+
65
+ case DISAS_STOP:
205
+ case MO_SL:
66
+ gen_save_pc(ctx->base.pc_next);
206
+ case MO_UL:
67
+ tcg_gen_lookup_and_goto_ptr();
207
+ tcg_out_opc_imm(s, lw1, lo, base, 0);
68
+ break;
208
+ tcg_out_opc_imm(s, lw2, lo, base, 3);
69
+ case DISAS_NEXT:
209
+ if (TCG_TARGET_REG_BITS == 64 && is_64 && !sgn) {
70
+ case DISAS_TOO_MANY:
210
+ tcg_out_ext32u(s, lo, lo);
71
+ save_cpu_state(ctx, 0);
211
+ }
72
+ gen_goto_tb(ctx, 0, ctx->base.pc_next);
212
+ break;
73
+ break;
213
+
74
+ case DISAS_EXIT:
214
+ case MO_UL | MO_BSWAP:
75
+ tcg_gen_exit_tb(NULL, 0);
215
+ case MO_SL | MO_BSWAP:
76
+ break;
216
+ if (use_mips32r2_instructions) {
77
+ case DISAS_NORETURN:
217
+ tcg_out_opc_imm(s, lw1, lo, base, 0);
78
+ break;
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
+
79
+ default:
283
+ default:
80
+ g_assert_not_reached();
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);
81
}
303
}
82
}
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
}
83
454
84
--
455
--
85
2.25.1
456
2.25.1
86
457
87
458
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
We can use the routines just added for user-only to emit
2
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>
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
8
---
6
target/hppa/translate.c | 17 ++++-------------
9
tcg/mips/tcg-target.c.inc | 91 ++++++++++++++++++++++-----------------
7
1 file changed, 4 insertions(+), 13 deletions(-)
10
1 file changed, 51 insertions(+), 40 deletions(-)
8
11
9
diff --git a/target/hppa/translate.c b/target/hppa/translate.c
12
diff --git a/tcg/mips/tcg-target.c.inc b/tcg/mips/tcg-target.c.inc
10
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
11
--- a/target/hppa/translate.c
14
--- a/tcg/mips/tcg-target.c.inc
12
+++ b/target/hppa/translate.c
15
+++ b/tcg/mips/tcg-target.c.inc
13
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int which,
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);
14
} else {
55
} else {
15
copy_iaoq_entry(cpu_iaoq_f, f, cpu_iaoq_b);
56
tcg_out_ldst(s, (TARGET_LONG_BITS == 64 ? OPC_LD
16
copy_iaoq_entry(cpu_iaoq_b, b, ctx->iaoq_n_var);
57
: TCG_TARGET_REG_BITS == 64 ? OPC_LWU : OPC_LW),
17
- if (ctx->base.singlestep_enabled) {
58
TCG_TMP0, TCG_TMP3, cmp_off);
18
- gen_excp_1(EXCP_DEBUG);
59
- tcg_out_movi(s, TCG_TYPE_TL, TCG_TMP1, mask);
19
- } else {
60
- /* No second compare is required here;
20
- tcg_gen_lookup_and_goto_ptr();
61
- load the tlb addend for the fast path. */
21
- }
62
- tcg_out_ld(s, TCG_TYPE_PTR, TCG_TMP2, TCG_TMP3, add_off);
22
+ tcg_gen_lookup_and_goto_ptr();
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,
23
}
103
}
24
}
104
}
25
105
26
@@ -XXX,XX +XXX,XX @@ static bool do_rfi(DisasContext *ctx, bool rfi_r)
106
-static void __attribute__((unused))
27
gen_helper_rfi(cpu_env);
107
-tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
28
}
108
+static void tcg_out_qemu_ld_unalign(TCGContext *s, TCGReg lo, TCGReg hi,
29
/* Exit the TB to recognize new interrupts. */
109
TCGReg base, MemOp opc, bool is_64)
30
- if (ctx->base.singlestep_enabled) {
110
{
31
- gen_excp_1(EXCP_DEBUG);
111
const MIPSInsn lw1 = MIPS_BE ? OPC_LWL : OPC_LWR;
32
- } else {
112
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
33
- tcg_gen_exit_tb(NULL, 0);
113
#if defined(CONFIG_SOFTMMU)
34
- }
114
tcg_insn_unit *label_ptr[2];
35
+ tcg_gen_exit_tb(NULL, 0);
115
#else
36
ctx->base.is_jmp = DISAS_NORETURN;
116
- unsigned a_bits, s_bits;
37
117
#endif
38
return nullify_end(ctx);
118
+ unsigned a_bits, s_bits;
39
@@ -XXX,XX +XXX,XX @@ static void hppa_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
119
TCGReg base = TCG_REG_A0;
40
nullify_save(ctx);
120
41
/* FALLTHRU */
121
data_regl = *args++;
42
case DISAS_IAQ_N_UPDATED:
122
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_ld(TCGContext *s, const TCGArg *args, bool is_64)
43
- if (ctx->base.singlestep_enabled) {
123
addr_regh = (TCG_TARGET_REG_BITS < TARGET_LONG_BITS ? *args++ : 0);
44
- gen_excp_1(EXCP_DEBUG);
124
oi = *args++;
45
- } else if (is_jmp != DISAS_IAQ_N_STALE_EXIT) {
125
opc = get_memop(oi);
46
+ if (is_jmp != DISAS_IAQ_N_STALE_EXIT) {
126
+ a_bits = get_alignment_bits(opc);
47
tcg_gen_lookup_and_goto_ptr();
127
+ s_bits = opc & MO_SIZE;
48
+ break;
128
49
}
129
+ /*
50
/* FALLTHRU */
130
+ * R6 removes the left/right instructions but requires the
51
case DISAS_EXIT:
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);
52
--
213
--
53
2.25.1
214
2.25.1
54
215
55
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
1
GDB single-stepping is now handled generically.
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.
2
5
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
3
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
---
8
---
5
target/cris/translate.c | 16 ----------------
9
tcg/sparc/tcg-target.c.inc | 36 +++++++++++++++++++++---------------
6
1 file changed, 16 deletions(-)
10
1 file changed, 21 insertions(+), 15 deletions(-)
7
11
8
diff --git a/target/cris/translate.c b/target/cris/translate.c
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
9
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
10
--- a/target/cris/translate.c
14
--- a/tcg/sparc/tcg-target.c.inc
11
+++ b/target/cris/translate.c
15
+++ b/tcg/sparc/tcg-target.c.inc
12
@@ -XXX,XX +XXX,XX @@ static void cris_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
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,
13
}
51
}
14
}
52
}
15
53
16
- if (unlikely(dc->base.singlestep_enabled)) {
54
- /* A 32-bit constant, or 32-bit zero-extended to 64-bits. */
17
- switch (is_jmp) {
55
- if (type == TCG_TYPE_I32 || arg == (uint32_t)arg) {
18
- case DISAS_TOO_MANY:
56
- tcg_out_sethi(s, ret, arg);
19
- case DISAS_UPDATE_NEXT:
57
- if (arg & 0x3ff) {
20
- tcg_gen_movi_tl(env_pc, npc);
58
- tcg_out_arithi(s, ret, ret, arg & 0x3ff, ARITH_OR);
21
- /* fall through */
22
- case DISAS_JUMP:
23
- case DISAS_UPDATE:
24
- t_gen_raise_exception(EXCP_DEBUG);
25
- return;
26
- default:
27
- break;
28
- }
59
- }
29
- g_assert_not_reached();
60
- return;
30
- }
61
- }
31
-
62
-
32
switch (is_jmp) {
63
/* A 32-bit constant sign-extended to 64-bits. */
33
case DISAS_TOO_MANY:
64
if (arg == lo) {
34
gen_goto_tb(dc, 0, npc);
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
}
35
--
83
--
36
2.25.1
84
2.25.1
37
85
38
86
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
This will allow us to control exactly what scratch register is
2
used for loading the constant.
2
3
3
Acked-by: Laurent Vivier <laurent@vivier.eu>
4
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
6
---
6
target/m68k/translate.c | 44 +++++++++--------------------------------
7
tcg/sparc/tcg-target.c.inc | 15 +++++++++------
7
1 file changed, 9 insertions(+), 35 deletions(-)
8
1 file changed, 9 insertions(+), 6 deletions(-)
8
9
9
diff --git a/target/m68k/translate.c b/target/m68k/translate.c
10
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
10
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
11
--- a/target/m68k/translate.c
12
--- a/tcg/sparc/tcg-target.c.inc
12
+++ b/target/m68k/translate.c
13
+++ b/tcg/sparc/tcg-target.c.inc
13
@@ -XXX,XX +XXX,XX @@ static void do_writebacks(DisasContext *s)
14
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_imm32(TCGContext *s, TCGReg ret, int32_t arg)
15
}
16
17
static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
18
- tcg_target_long arg, bool in_prologue)
19
+ tcg_target_long arg, bool in_prologue,
20
+ TCGReg scratch)
21
{
22
tcg_target_long hi, lo = (int32_t)arg;
23
tcg_target_long test, lsb;
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);
14
}
33
}
15
}
34
}
16
35
17
-static bool is_singlestepping(DisasContext *s)
36
static void tcg_out_movi(TCGContext *s, TCGType type,
18
-{
37
TCGReg ret, tcg_target_long arg)
19
- /*
38
{
20
- * Return true if we are singlestepping either because of
39
- tcg_out_movi_int(s, type, ret, arg, false);
21
- * architectural singlestep or QEMU gdbstub singlestep. This does
40
+ tcg_debug_assert(ret != TCG_REG_T2);
22
- * not include the command line '-singlestep' mode which is rather
41
+ tcg_out_movi_int(s, type, ret, arg, false, TCG_REG_T2);
23
- * misnamed as it only means "one instruction per TB" and doesn't
24
- * affect the code we generate.
25
- */
26
- return s->base.singlestep_enabled || s->ss_active;
27
-}
28
-
29
/* is_jmp field values */
30
#define DISAS_JUMP DISAS_TARGET_0 /* only pc was modified dynamically */
31
#define DISAS_EXIT DISAS_TARGET_1 /* cpu state was modified dynamically */
32
@@ -XXX,XX +XXX,XX @@ static void gen_exception(DisasContext *s, uint32_t dest, int nr)
33
s->base.is_jmp = DISAS_NORETURN;
34
}
42
}
35
43
36
-static void gen_singlestep_exception(DisasContext *s)
44
static void tcg_out_ldst_rr(TCGContext *s, TCGReg data, TCGReg a1,
37
-{
45
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
38
- /*
46
} else {
39
- * Generate the right kind of exception for singlestep, which is
47
uintptr_t desti = (uintptr_t)dest;
40
- * either the architectural singlestep or EXCP_DEBUG for QEMU's
48
tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
41
- * gdb singlestepping.
49
- desti & ~0xfff, in_prologue);
42
- */
50
+ desti & ~0xfff, in_prologue, TCG_REG_O7);
43
- if (s->ss_active) {
51
tcg_out_arithi(s, TCG_REG_O7, TCG_REG_T1, desti & 0xfff, JMPL);
44
- gen_raise_exception(EXCP_TRACE);
45
- } else {
46
- gen_raise_exception(EXCP_DEBUG);
47
- }
48
-}
49
-
50
static inline void gen_addr_fault(DisasContext *s)
51
{
52
gen_exception(s, s->base.pc_next, EXCP_ADDRESS);
53
@@ -XXX,XX +XXX,XX @@ static void gen_exit_tb(DisasContext *s)
54
/* Generate a jump to an immediate address. */
55
static void gen_jmp_tb(DisasContext *s, int n, uint32_t dest)
56
{
57
- if (unlikely(is_singlestepping(s))) {
58
+ if (unlikely(s->ss_active)) {
59
update_cc_op(s);
60
tcg_gen_movi_i32(QREG_PC, dest);
61
- gen_singlestep_exception(s);
62
+ gen_raise_exception(EXCP_TRACE);
63
} else if (translator_use_goto_tb(&s->base, dest)) {
64
tcg_gen_goto_tb(n);
65
tcg_gen_movi_i32(QREG_PC, dest);
66
@@ -XXX,XX +XXX,XX @@ static void m68k_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
67
68
dc->ss_active = (M68K_SR_TRACE(env->sr) == M68K_SR_TRACE_ANY_INS);
69
/* If architectural single step active, limit to 1 */
70
- if (is_singlestepping(dc)) {
71
+ if (dc->ss_active) {
72
dc->base.max_insns = 1;
73
}
52
}
74
}
53
}
75
@@ -XXX,XX +XXX,XX @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
54
@@ -XXX,XX +XXX,XX @@ static void tcg_target_qemu_prologue(TCGContext *s)
76
break;
55
77
case DISAS_TOO_MANY:
56
#ifndef CONFIG_SOFTMMU
78
update_cc_op(dc);
57
if (guest_base != 0) {
79
- if (is_singlestepping(dc)) {
58
- tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG, guest_base, true);
80
+ if (dc->ss_active) {
59
+ tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_GUEST_BASE_REG,
81
tcg_gen_movi_i32(QREG_PC, dc->pc);
60
+ guest_base, true, TCG_REG_T1);
82
- gen_singlestep_exception(dc);
61
tcg_regset_set_reg(s->reserved_regs, TCG_GUEST_BASE_REG);
83
+ gen_raise_exception(EXCP_TRACE);
62
}
84
} else {
63
#endif
85
gen_jmp_tb(dc, 0, dc->pc);
86
}
87
break;
88
case DISAS_JUMP:
89
/* We updated CC_OP and PC in gen_jmp/gen_jmp_im. */
90
- if (is_singlestepping(dc)) {
91
- gen_singlestep_exception(dc);
92
+ if (dc->ss_active) {
93
+ gen_raise_exception(EXCP_TRACE);
94
} else {
95
tcg_gen_lookup_and_goto_ptr();
96
}
97
@@ -XXX,XX +XXX,XX @@ static void m68k_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
98
* We updated CC_OP and PC in gen_exit_tb, but also modified
99
* other state that may require returning to the main loop.
100
*/
101
- if (is_singlestepping(dc)) {
102
- gen_singlestep_exception(dc);
103
+ if (dc->ss_active) {
104
+ gen_raise_exception(EXCP_TRACE);
105
} else {
106
tcg_gen_exit_tb(NULL, 0);
107
}
108
--
64
--
109
2.25.1
65
2.25.1
110
66
111
67
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
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.
2
4
3
Tested-by: Michael Rolnik <mrolnik@gmail.com>
5
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Reviewed-by: Michael Rolnik <mrolnik@gmail.com>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
---
8
---
8
target/avr/translate.c | 19 ++++---------------
9
tcg/sparc/tcg-target.c.inc | 12 ++++++------
9
1 file changed, 4 insertions(+), 15 deletions(-)
10
1 file changed, 6 insertions(+), 6 deletions(-)
10
11
11
diff --git a/target/avr/translate.c b/target/avr/translate.c
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
12
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
13
--- a/target/avr/translate.c
14
--- a/tcg/sparc/tcg-target.c.inc
14
+++ b/target/avr/translate.c
15
+++ b/tcg/sparc/tcg-target.c.inc
15
@@ -XXX,XX +XXX,XX @@ static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest)
16
@@ -XXX,XX +XXX,XX @@ static void tcg_out_movi_int(TCGContext *s, TCGType type, TCGReg ret,
16
tcg_gen_exit_tb(tb, n);
17
return;
17
} else {
18
tcg_gen_movi_i32(cpu_pc, dest);
19
- if (ctx->base.singlestep_enabled) {
20
- gen_helper_debug(cpu_env);
21
- } else {
22
- tcg_gen_lookup_and_goto_ptr();
23
- }
24
+ tcg_gen_lookup_and_goto_ptr();
25
}
18
}
26
ctx->base.is_jmp = DISAS_NORETURN;
19
27
}
20
- /* A 21-bit constant, shifted. */
28
@@ -XXX,XX +XXX,XX @@ static void avr_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs)
21
+ /* A 32-bit constant, shifted. */
29
tcg_gen_movi_tl(cpu_pc, ctx->npc);
22
lsb = ctz64(arg);
30
/* fall through */
23
test = (tcg_target_long)arg >> lsb;
31
case DISAS_LOOKUP:
24
- if (check_fit_tl(test, 13)) {
32
- if (!ctx->base.singlestep_enabled) {
25
- tcg_out_movi_imm13(s, ret, test);
33
- tcg_gen_lookup_and_goto_ptr();
26
- tcg_out_arithi(s, ret, ret, lsb, SHIFT_SLLX);
34
- break;
27
- return;
35
- }
28
- } else if (lsb > 10 && test == extract64(test, 0, 21)) {
36
- /* fall through */
29
+ if (lsb > 10 && test == extract64(test, 0, 21)) {
37
+ tcg_gen_lookup_and_goto_ptr();
30
tcg_out_sethi(s, ret, test << 10);
38
+ break;
31
tcg_out_arithi(s, ret, ret, lsb - 10, SHIFT_SLLX);
39
case DISAS_EXIT:
32
return;
40
- if (ctx->base.singlestep_enabled) {
33
+ } else if (test == (uint32_t)test || test == (int32_t)test) {
41
- gen_helper_debug(cpu_env);
34
+ tcg_out_movi_int(s, TCG_TYPE_I64, ret, test, in_prologue, scratch);
42
- } else {
35
+ tcg_out_arithi(s, ret, ret, lsb, SHIFT_SLLX);
43
- tcg_gen_exit_tb(NULL, 0);
36
+ return;
44
- }
37
}
45
+ tcg_gen_exit_tb(NULL, 0);
38
46
break;
39
/* A 64-bit constant decomposed into 2 32-bit pieces. */
47
default:
48
g_assert_not_reached();
49
--
40
--
50
2.25.1
41
2.25.1
51
42
52
43
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
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.
2
4
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
5
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
6
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
7
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
8
---
6
target/hexagon/translate.c | 12 ++----------
9
tcg/sparc/tcg-target.c.inc | 8 ++++++--
7
1 file changed, 2 insertions(+), 10 deletions(-)
10
1 file changed, 6 insertions(+), 2 deletions(-)
8
11
9
diff --git a/target/hexagon/translate.c b/target/hexagon/translate.c
12
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
10
index XXXXXXX..XXXXXXX 100644
13
index XXXXXXX..XXXXXXX 100644
11
--- a/target/hexagon/translate.c
14
--- a/tcg/sparc/tcg-target.c.inc
12
+++ b/target/hexagon/translate.c
15
+++ b/tcg/sparc/tcg-target.c.inc
13
@@ -XXX,XX +XXX,XX @@ static void gen_end_tb(DisasContext *ctx)
16
@@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type,
14
{
17
15
gen_exec_counters(ctx);
18
switch (type) {
16
tcg_gen_mov_tl(hex_gpr[HEX_REG_PC], hex_next_PC);
19
case R_SPARC_WDISP16:
17
- if (ctx->base.singlestep_enabled) {
20
- assert(check_fit_ptr(pcrel >> 2, 16));
18
- gen_exception_raw(EXCP_DEBUG);
21
+ if (!check_fit_ptr(pcrel >> 2, 16)) {
19
- } else {
22
+ return false;
20
- tcg_gen_exit_tb(NULL, 0);
23
+ }
21
- }
24
insn &= ~INSN_OFF16(-1);
22
+ tcg_gen_exit_tb(NULL, 0);
25
insn |= INSN_OFF16(pcrel);
23
ctx->base.is_jmp = DISAS_NORETURN;
24
}
25
26
@@ -XXX,XX +XXX,XX @@ static void hexagon_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
27
case DISAS_TOO_MANY:
28
gen_exec_counters(ctx);
29
tcg_gen_movi_tl(hex_gpr[HEX_REG_PC], ctx->base.pc_next);
30
- if (ctx->base.singlestep_enabled) {
31
- gen_exception_raw(EXCP_DEBUG);
32
- } else {
33
- tcg_gen_exit_tb(NULL, 0);
34
- }
35
+ tcg_gen_exit_tb(NULL, 0);
36
break;
26
break;
37
case DISAS_NORETURN:
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);
38
break;
34
break;
39
--
35
--
40
2.25.1
36
2.25.1
41
37
42
38
diff view generated by jsdifflib
1
GDB single-stepping is now handled generically.
1
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2
3
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
2
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
3
---
6
target/alpha/translate.c | 13 +++----------
4
tcg/sparc/tcg-target.c.inc | 15 +++++++++++++++
7
1 file changed, 3 insertions(+), 10 deletions(-)
5
1 file changed, 15 insertions(+)
8
6
9
diff --git a/target/alpha/translate.c b/target/alpha/translate.c
7
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
10
index XXXXXXX..XXXXXXX 100644
8
index XXXXXXX..XXXXXXX 100644
11
--- a/target/alpha/translate.c
9
--- a/tcg/sparc/tcg-target.c.inc
12
+++ b/target/alpha/translate.c
10
+++ b/tcg/sparc/tcg-target.c.inc
13
@@ -XXX,XX +XXX,XX @@ static void alpha_tr_tb_stop(DisasContextBase *dcbase, CPUState *cpu)
11
@@ -XXX,XX +XXX,XX @@ static bool patch_reloc(tcg_insn_unit *src_rw, int type,
14
tcg_gen_movi_i64(cpu_pc, ctx->base.pc_next);
12
insn &= ~INSN_OFF19(-1);
15
/* FALLTHRU */
13
insn |= INSN_OFF19(pcrel);
16
case DISAS_PC_UPDATED:
14
break;
17
- if (!ctx->base.singlestep_enabled) {
15
+ case R_SPARC_13:
18
- tcg_gen_lookup_and_goto_ptr();
16
+ if (!check_fit_ptr(value, 13)) {
19
- break;
17
+ return false;
20
- }
18
+ }
21
- /* FALLTHRU */
19
+ insn &= ~INSN_IMM13(-1);
22
+ tcg_gen_lookup_and_goto_ptr();
20
+ insn |= INSN_IMM13(value);
23
+ break;
21
+ break;
24
case DISAS_PC_UPDATED_NOCHAIN:
25
- if (ctx->base.singlestep_enabled) {
26
- gen_excp_1(EXCP_DEBUG, 0);
27
- } else {
28
- tcg_gen_exit_tb(NULL, 0);
29
- }
30
+ tcg_gen_exit_tb(NULL, 0);
31
break;
32
default:
22
default:
33
g_assert_not_reached();
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;
34
--
40
--
35
2.25.1
41
2.25.1
36
42
37
43
diff view generated by jsdifflib
1
This reverts commit 1b36e4f5a5de585210ea95f2257839c2312be28f.
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.
2
4
3
Despite a comment saying why cpu_common_props cannot be placed in
5
So, always use indirect calls for tail calls, which allows us to
4
a file that is compiled once, it was moved anyway. Revert that.
6
avoid clobbering %o7, and therefore we need not save and restore it.
5
7
6
Since then, Property is not defined in hw/core/cpu.h, so it is now
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
7
easier to declare a function to install the properties rather than
8
the Property array itself.
9
10
Cc: Eduardo Habkost <ehabkost@redhat.com>
11
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
12
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
13
---
10
---
14
include/hw/core/cpu.h | 1 +
11
tcg/sparc/tcg-target.c.inc | 37 +++++++++++++++++++++++--------------
15
cpu.c | 21 +++++++++++++++++++++
12
1 file changed, 23 insertions(+), 14 deletions(-)
16
hw/core/cpu-common.c | 17 +----------------
17
3 files changed, 23 insertions(+), 16 deletions(-)
18
13
19
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
14
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/include/hw/core/cpu.h
16
--- a/tcg/sparc/tcg-target.c.inc
22
+++ b/include/hw/core/cpu.h
17
+++ b/tcg/sparc/tcg-target.c.inc
23
@@ -XXX,XX +XXX,XX @@ void QEMU_NORETURN cpu_abort(CPUState *cpu, const char *fmt, ...)
18
@@ -XXX,XX +XXX,XX @@ static void tcg_out_addsub2_i64(TCGContext *s, TCGReg rl, TCGReg rh,
24
GCC_FMT_ATTR(2, 3);
19
tcg_out_mov(s, TCG_TYPE_I64, rl, tmp);
25
26
/* $(top_srcdir)/cpu.c */
27
+void cpu_class_init_props(DeviceClass *dc);
28
void cpu_exec_initfn(CPUState *cpu);
29
void cpu_exec_realizefn(CPUState *cpu, Error **errp);
30
void cpu_exec_unrealizefn(CPUState *cpu);
31
diff --git a/cpu.c b/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/cpu.c
34
+++ b/cpu.c
35
@@ -XXX,XX +XXX,XX @@ void cpu_exec_unrealizefn(CPUState *cpu)
36
cpu_list_remove(cpu);
37
}
20
}
38
21
39
+static Property cpu_common_props[] = {
22
+static void tcg_out_jmpl_const(TCGContext *s, const tcg_insn_unit *dest,
40
+#ifndef CONFIG_USER_ONLY
23
+ bool in_prologue, bool tail_call)
41
+ /*
24
+{
42
+ * Create a memory property for softmmu CPU object,
25
+ uintptr_t desti = (uintptr_t)dest;
43
+ * so users can wire up its memory. (This can't go in hw/core/cpu.c
44
+ * because that file is compiled only once for both user-mode
45
+ * and system builds.) The default if no link is set up is to use
46
+ * the system address space.
47
+ */
48
+ DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
49
+ MemoryRegion *),
50
+#endif
51
+ DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
52
+ DEFINE_PROP_END_OF_LIST(),
53
+};
54
+
26
+
55
+void cpu_class_init_props(DeviceClass *dc)
27
+ /* Be careful not to clobber %o7 for a tail call. */
56
+{
28
+ tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
57
+ device_class_set_props(dc, cpu_common_props);
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);
58
+}
33
+}
59
+
34
+
60
void cpu_exec_initfn(CPUState *cpu)
35
static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
36
bool in_prologue)
61
{
37
{
62
cpu->as = NULL;
38
@@ -XXX,XX +XXX,XX @@ static void tcg_out_call_nodelay(TCGContext *s, const tcg_insn_unit *dest,
63
diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c
39
if (disp == (int32_t)disp) {
64
index XXXXXXX..XXXXXXX 100644
40
tcg_out32(s, CALL | (uint32_t)disp >> 2);
65
--- a/hw/core/cpu-common.c
41
} else {
66
+++ b/hw/core/cpu-common.c
42
- uintptr_t desti = (uintptr_t)dest;
67
@@ -XXX,XX +XXX,XX @@ static int64_t cpu_common_get_arch_id(CPUState *cpu)
43
- tcg_out_movi_int(s, TCG_TYPE_PTR, TCG_REG_T1,
68
return cpu->cpu_index;
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
}
69
}
48
}
70
49
71
-static Property cpu_common_props[] = {
50
@@ -XXX,XX +XXX,XX @@ static void build_trampolines(TCGContext *s)
72
-#ifndef CONFIG_USER_ONLY
51
73
- /* Create a memory property for softmmu CPU object,
52
/* Set the retaddr operand. */
74
- * so users can wire up its memory. (This can't go in hw/core/cpu.c
53
tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
75
- * because that file is compiled only once for both user-mode
54
- /* Set the env operand. */
76
- * and system builds.) The default if no link is set up is to use
55
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
77
- * the system address space.
56
/* Tail call. */
78
- */
57
- tcg_out_call_nodelay(s, qemu_ld_helpers[i], true);
79
- DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION,
58
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O7, ra);
80
- MemoryRegion *),
59
+ tcg_out_jmpl_const(s, qemu_ld_helpers[i], true, true);
81
-#endif
60
+ /* delay slot -- set the env argument */
82
- DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false),
61
+ tcg_out_mov_delay(s, TCG_REG_O0, TCG_AREG0);
83
- DEFINE_PROP_END_OF_LIST(),
62
}
84
-};
63
85
-
64
for (i = 0; i < ARRAY_SIZE(qemu_st_helpers); ++i) {
86
static void cpu_class_init(ObjectClass *klass, void *data)
65
@@ -XXX,XX +XXX,XX @@ static void build_trampolines(TCGContext *s)
87
{
66
if (ra >= TCG_REG_O6) {
88
DeviceClass *dc = DEVICE_CLASS(klass);
67
tcg_out_st(s, TCG_TYPE_PTR, TCG_REG_O7, TCG_REG_CALL_STACK,
89
@@ -XXX,XX +XXX,XX @@ static void cpu_class_init(ObjectClass *klass, void *data)
68
TCG_TARGET_CALL_STACK_OFFSET);
90
dc->realize = cpu_common_realizefn;
69
- ra = TCG_REG_G1;
91
dc->unrealize = cpu_common_unrealizefn;
70
+ } else {
92
dc->reset = cpu_common_reset;
71
+ tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
93
- device_class_set_props(dc, cpu_common_props);
72
}
94
+ cpu_class_init_props(dc);
73
- tcg_out_mov(s, TCG_TYPE_PTR, ra, TCG_REG_O7);
95
/*
74
- /* Set the env operand. */
96
* Reason: CPUs still need special care by board code: wiring up
75
- tcg_out_mov(s, TCG_TYPE_PTR, TCG_REG_O0, TCG_AREG0);
97
* IRQs, adding reset handlers, halting non-first CPUs, ...
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
98
--
86
--
99
2.25.1
87
2.25.1
100
88
101
89
diff view generated by jsdifflib
1
We have already set DISAS_NORETURN in generate_exception,
1
This is kinda sorta the opposite of the other tcg hosts, where
2
which makes the exit_tb unreachable.
2
we get (normal) alignment checks for free with host SIGBUS and
3
3
need to add code to support unaligned accesses.
4
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
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>
5
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
9
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
6
---
10
---
7
target/riscv/insn_trans/trans_privileged.c.inc | 6 +-----
11
tcg/sparc/tcg-target.c.inc | 219 +++++++++++++++++++++++++++++++++++--
8
1 file changed, 1 insertion(+), 5 deletions(-)
12
1 file changed, 211 insertions(+), 8 deletions(-)
9
13
10
diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc
14
diff --git a/tcg/sparc/tcg-target.c.inc b/tcg/sparc/tcg-target.c.inc
11
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
12
--- a/target/riscv/insn_trans/trans_privileged.c.inc
16
--- a/tcg/sparc/tcg-target.c.inc
13
+++ b/target/riscv/insn_trans/trans_privileged.c.inc
17
+++ b/tcg/sparc/tcg-target.c.inc
14
@@ -XXX,XX +XXX,XX @@ static bool trans_ecall(DisasContext *ctx, arg_ecall *a)
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)
15
{
100
{
16
/* always generates U-level ECALL, fixed in do_interrupt handler */
101
MemOp memop = get_memop(oi);
17
generate_exception(ctx, RISCV_EXCP_U_ECALL);
102
+ tcg_insn_unit *label_ptr;
18
- exit_tb(ctx); /* no chaining */
103
+
19
- ctx->base.is_jmp = DISAS_NORETURN;
104
#ifdef CONFIG_SOFTMMU
20
return true;
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 */
21
}
212
}
22
213
23
@@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a)
214
@@ -XXX,XX +XXX,XX @@ static void tcg_out_qemu_st(TCGContext *s, TCGReg data, TCGReg addr,
24
post = opcode_at(&ctx->base, post_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;
25
}
240
}
26
241
- tcg_out_ldst_rr(s, data, addr,
27
- if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
242
- (guest_base ? TCG_GUEST_BASE_REG : TCG_REG_G0),
28
+ if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) {
243
+
29
generate_exception(ctx, RISCV_EXCP_SEMIHOST);
244
+ /*
30
} else {
245
+ * Normal case: alignment equal to access size.
31
generate_exception(ctx, RISCV_EXCP_BREAKPOINT);
246
+ */
32
}
247
+ if (a_bits == s_bits) {
33
- exit_tb(ctx); /* no chaining */
248
+ tcg_out_ldst_rr(s, data, addr, index,
34
- ctx->base.is_jmp = DISAS_NORETURN;
249
+ qemu_st_opc[memop & (MO_BSWAP | MO_SIZE)]);
35
return true;
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 */
36
}
322
}
37
323
38
--
324
--
39
2.25.1
325
2.25.1
40
326
41
327
diff view generated by jsdifflib
1
We were using singlestep_enabled as a proxy for whether
1
A mostly generic test for unaligned access raising SIGBUS.
2
translator_use_goto_tb would always return false.
3
2
3
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
4
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
5
---
5
---
6
target/microblaze/translate.c | 4 ++--
6
tests/tcg/multiarch/sigbus.c | 68 ++++++++++++++++++++++++++++++++++++
7
1 file changed, 2 insertions(+), 2 deletions(-)
7
1 file changed, 68 insertions(+)
8
create mode 100644 tests/tcg/multiarch/sigbus.c
8
9
9
diff --git a/target/microblaze/translate.c b/target/microblaze/translate.c
10
diff --git a/tests/tcg/multiarch/sigbus.c b/tests/tcg/multiarch/sigbus.c
10
index XXXXXXX..XXXXXXX 100644
11
new file mode 100644
11
--- a/target/microblaze/translate.c
12
index XXXXXXX..XXXXXXX
12
+++ b/target/microblaze/translate.c
13
--- /dev/null
13
@@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs)
14
+++ b/tests/tcg/multiarch/sigbus.c
14
break;
15
@@ -XXX,XX +XXX,XX @@
15
16
+#define _GNU_SOURCE 1
16
case DISAS_JUMP:
17
+
17
- if (dc->jmp_dest != -1 && !cs->singlestep_enabled) {
18
+#include <assert.h>
18
+ if (dc->jmp_dest != -1 && !(tb_cflags(dc->base.tb) & CF_NO_GOTO_TB)) {
19
+#include <stdlib.h>
19
/* Direct jump. */
20
+#include <signal.h>
20
tcg_gen_discard_i32(cpu_btarget);
21
+#include <endian.h>
21
22
+
22
@@ -XXX,XX +XXX,XX @@ static void mb_tr_tb_stop(DisasContextBase *dcb, CPUState *cs)
23
+
23
return;
24
+unsigned long long x = 0x8877665544332211ull;
24
}
25
+void * volatile p = (void *)&x + 1;
25
26
+
26
- /* Indirect jump (or direct jump w/ singlestep) */
27
+void sigbus(int sig, siginfo_t *info, void *uc)
27
+ /* Indirect jump (or direct jump w/ goto_tb disabled) */
28
+{
28
tcg_gen_mov_i32(cpu_pc, cpu_btarget);
29
+ assert(sig == SIGBUS);
29
tcg_gen_discard_i32(cpu_btarget);
30
+ assert(info->si_signo == SIGBUS);
30
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
+}
31
--
84
--
32
2.25.1
85
2.25.1
33
86
34
87
diff view generated by jsdifflib