From: Stefan Hajnoczi <stefanha@gmail.com>
To: Julia Suvorova <jusual@mail.ru>
Cc: Alistair Francis <alistair23@gmail.com>,
Peter Maydell <peter.maydell@linaro.org>,
Alistair Francis <alistair@alistair23.me>,
"qemu-devel@nongnu.org Developers" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] hw/core/generic-loader: Fix PC overwriting
Date: Thu, 17 Jan 2019 10:13:09 +0000 [thread overview]
Message-ID: <20190117101309.GA27840@stefanha-x1.localdomain> (raw)
In-Reply-To: <797be79d-7ffc-222a-6acd-b01ff7269a63@mail.ru>
[-- Attachment #1: Type: text/plain, Size: 1946 bytes --]
On Wed, Jan 16, 2019 at 10:05:58PM +0300, Julia Suvorova via Qemu-devel wrote:
> On 16.01.2019 0:51, Alistair Francis wrote:
> > On Tue, Jan 15, 2019 at 7:04 AM Julia Suvorova via Qemu-devel
> > <qemu-devel@nongnu.org> wrote:
> > >
> > > If the memory is set using a file, and PC is specified on the command
> > > line, it will be overwritten with the value 'entry'. This is not only
> > > illogical, but also incorrect, because the load_ * functions do not take
> > > into account the specifics of the ARM-M PC.
> >
> > How does this come up?
> > I see that the value of entry will force overwrite the PC addr, but
> > doesn't force_raw fix that? Is there a common use case of loading an
> > ELF/uimage but having to manually specify a start address?
>
> generic_loader_reset() is called after arm_cpu_reset() and damages PC
> (it is wrong to call arm_cpu_set_pc() with entry to set ARM PC reset
> value). Therefore, I tried to configure PC manually and ran into this
> problem.
>
> By the way, I do not know the right way to fix the original issue. Try
> to replace generic_loader_reset() with the device reset function or
> change the reset order or transfer PC reset value setting to a separate
> function and associate it with cpu. What do you think about it?
generic_loader_reset() calls cpu_reset(s->cpu) followed by
CPUClass->set_pc(s->cpu, s->addr).
ARM's arm_cpu_set_pc() doesn't special-case the Thumb bit (that's only
done in arm_cpu_reset()) so we end up with an invalid PC for Thumb mode
addresses.
Maybe the following arm_cpu_reset() code should be moved to
arm_cpu_set_pc():
env->regs[15] = initial_pc & ~1;
env->thumb = initial_pc & 1;
Then arm_cpu_reset() can call arm_cpu_set_pc() instead of duplicating
this code.
I haven't checked whether more special logic is needed in
arm_cpu_set_pc() aside from setting Thumb mode, but I think this should
do the trick?
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]
next prev parent reply other threads:[~2019-01-17 10:13 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 14:36 [Qemu-devel] [PATCH] hw/core/generic-loader: Fix PC overwriting Julia Suvorova
2019-01-15 21:51 ` Alistair Francis
2019-01-16 19:05 ` Julia Suvorova
2019-01-17 10:13 ` Stefan Hajnoczi [this message]
2019-01-17 10:58 ` Julia Suvorova
2019-01-17 19:27 ` Peter Maydell
2019-01-17 19:55 ` Peter Maydell
2019-01-21 17:24 ` Peter Maydell
2019-01-22 13:59 ` Julia Suvorova
2019-01-22 14:58 ` Peter Maydell
2019-01-21 3:11 ` no-reply
2019-01-21 3:22 ` no-reply
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=20190117101309.GA27840@stefanha-x1.localdomain \
--to=stefanha@gmail.com \
--cc=alistair23@gmail.com \
--cc=alistair@alistair23.me \
--cc=jusual@mail.ru \
--cc=peter.maydell@linaro.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).