From: Richard Henderson <richard.henderson@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org
Subject: Re: [PATCH v5 9/9] target/arm: Enable TARGET_TB_PCREL
Date: Tue, 4 Oct 2022 14:09:43 -0700 [thread overview]
Message-ID: <7a2c6a64-87f7-fd8f-d406-6a0b50164f0b@linaro.org> (raw)
In-Reply-To: <d1196e9c-c983-0b74-9141-ac10154429cd@linaro.org>
On 10/4/22 12:27, Richard Henderson wrote:
> On 10/4/22 09:23, Peter Maydell wrote:
>>> void arm_cpu_synchronize_from_tb(CPUState *cs,
>>> const TranslationBlock *tb)
>>> {
>>> - ARMCPU *cpu = ARM_CPU(cs);
>>> - CPUARMState *env = &cpu->env;
>>> -
>>> - /*
>>> - * It's OK to look at env for the current mode here, because it's
>>> - * never possible for an AArch64 TB to chain to an AArch32 TB.
>>> - */
>>> - if (is_a64(env)) {
>>> - env->pc = tb_pc(tb);
>>> - } else {
>>> - env->regs[15] = tb_pc(tb);
>>> + /* The program counter is always up to date with TARGET_TB_PCREL. */
>>
>> I was confused for a bit about this, but it works because
>> although the synchronize_from_tb hook has a name that implies
>> it's comparatively general purpose, in fact we use it only
>> in the special case of "we abandoned execution at the start of
>> this TB without executing any of it".
>
> Correct.
>
>>> @@ -347,16 +354,22 @@ static void gen_exception_internal(int excp)
>>>
>>> static void gen_exception_internal_insn(DisasContext *s, int excp)
>>> {
>>> + target_ulong pc_save = s->pc_save;
>>> +
>>> gen_a64_update_pc(s, 0);
>>> gen_exception_internal(excp);
>>> s->base.is_jmp = DISAS_NORETURN;
>>> + s->pc_save = pc_save;
>>
>> What is trashing s->pc_save that we have to work around like this,
>> here and in the other similar changes ?
>
> gen_a64_update_pc trashes pc_save.
>
> Off of the top of my head, I can't remember what conditionally uses exceptions (single
> step?).
Oh, duh, any conditional a32 instruction.
To some extent this instance duplicates s->pc_cond_save, but the usage pattern there is
brcond(..., s->condlabel);
s->pc_cond_save = s->pc_save;
gen_update_pc(s, 0); /* pc_save = pc_curr */
raise_exception;
if (s->pc_cond_save != s->pc_save) {
gen_update_pc(s->pc_save - s->pc_cond_save);
}
/* s->pc_save now matches the state at brcond */
condlabel:
So, we have exited the TB via exception, and the second gen_update_pc would be deleted as
dead code, it's just as easy to keep s->pc_save unchanged so that the second gen_update_pc
is not emitted. We certainly *must* update s->pc_save around indirect branches, so that
we don't wind up with an assert on s->pc_save != -1.
r~
next prev parent reply other threads:[~2022-10-04 21:12 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-30 22:03 [PATCH v5 0/9] target/arm: pc-relative translation blocks Richard Henderson
2022-09-30 22:03 ` [PATCH v5 1/9] target/arm: Introduce curr_insn_len Richard Henderson
2022-09-30 22:03 ` [PATCH v5 2/9] target/arm: Change gen_goto_tb to work on displacements Richard Henderson
2022-09-30 22:03 ` [PATCH v5 3/9] target/arm: Change gen_*set_pc_im to gen_*update_pc Richard Henderson
2022-10-03 14:18 ` Philippe Mathieu-Daudé via
2022-09-30 22:03 ` [PATCH v5 4/9] target/arm: Change gen_exception_insn* to work on displacements Richard Henderson
2022-10-03 14:21 ` Philippe Mathieu-Daudé via
2022-09-30 22:03 ` [PATCH v5 5/9] target/arm: Remove gen_exception_internal_insn pc argument Richard Henderson
2022-10-03 14:22 ` Philippe Mathieu-Daudé via
2022-09-30 22:03 ` [PATCH v5 6/9] target/arm: Change gen_jmp* to work on displacements Richard Henderson
2022-10-04 15:58 ` Peter Maydell
2022-10-04 20:57 ` Richard Henderson
2022-10-05 14:15 ` Peter Maydell
2022-09-30 22:03 ` [PATCH v5 7/9] target/arm: Introduce gen_pc_plus_diff for aarch64 Richard Henderson
2022-10-04 16:10 ` Peter Maydell
2022-09-30 22:03 ` [PATCH v5 8/9] target/arm: Introduce gen_pc_plus_diff for aarch32 Richard Henderson
2022-10-11 14:51 ` Peter Maydell
2022-10-11 15:52 ` Richard Henderson
2022-09-30 22:03 ` [PATCH v5 9/9] target/arm: Enable TARGET_TB_PCREL Richard Henderson
2022-10-04 16:23 ` Peter Maydell
2022-10-04 19:27 ` Richard Henderson
2022-10-04 21:09 ` Richard Henderson [this message]
2022-10-14 17:49 ` Peter Maydell
2022-10-14 19:01 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7a2c6a64-87f7-fd8f-d406-6a0b50164f0b@linaro.org \
--to=richard.henderson@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).