From: Richard Henderson <rth@twiddle.net>
To: Martin Galvan <martin.galvan@tallertechnologies.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Anthony Liguori" <aliguori@amazon.com>,
"Andreas Färber" <afaerber@suse.de>
Subject: Re: [Qemu-devel] [PATCH] cpu-exec: Don't mask out external interrupts when single-stepping an invalid instruction.
Date: Fri, 12 Sep 2014 08:37:45 -0700 [thread overview]
Message-ID: <54131349.7010406@twiddle.net> (raw)
In-Reply-To: <CAOKbPbYCEc6q56MGQ+rLcy8PyQQzYGKdLMPPfFn9JyXhVO3O7A@mail.gmail.com>
On 09/12/2014 07:33 AM, Martin Galvan wrote:
> On Thu, Sep 11, 2014 at 8:52 PM, Richard Henderson <rth@twiddle.net> wrote:
>> On 09/11/2014 03:13 PM, Peter Maydell wrote:
>> In particular, I'd expect the invalid exception to be recognized, and then the
>> cpu loop exited, before the single-step exception could overwrite it. E.g. how
>> things work on alpha:
>>
>> $ cat z.s
>> .globl _start
>> _start:
>> nop
>> .long (1 << 26)
>> nop
>> $ alphaev67-linux-as -o z.o z.s
>> $ alphaev67-linux-ld -Ttext-segment 0xfffffc0000100000 -o z z.o
>> $ ./run/bin/qemu-system-alpha -kernel z -S -gdb tcp::12345 &
>> $ alphaev67-linux-gdb ./z
>
> Can't test this myself since I don't have an alpha cross-toolchain at
> hand right now.
It's pretty simple to build a cross binutils; much easier and quicker than
building a cross gcc. And you'd need the cross gdb that gets built in the
process anyway...
> So if I understood right, what you do in Alpha is:
>
> - With your PC pointing to the invalid instruction, single-step once.
> - The generated assembly will contain a call to excp with EXCP_OPCDEC.
> - On excp, it sets cs->exception_index to EXCP_OPCDEC and then does a
> cpu_loop_exit.
> - As it advances through the loop again, it'll notice exception_index
> is greater than 0, thus calling do_interrupt.
> - Inside do_interrupt it sets the PC to point to the exception handler
> entry point.
All true and correct so far.
> - It sets cpu->exception_index to EXCP_DEBUG somehow, thus returning
> control back to gdb.
Ah, well, no. Certainly target-alpha does no such thing.
I admit I have no idea exactly what happens here, because...
> - The net result is that single-stepping with the PC pointing to an
> invalid instruction
> immediately leads us to the exception handler.
... it just worked, yes.
> That's exactly what I'm trying to achieve. However, in target-arm we
> end up calling do_interrupt twice:
> the first time in the outer for(;;) to set cpu->interrupt_request to
> CPU_INTERRUPT_HARD,
> and the second time inside the inner for(;;) to actually set the PC to
> point to the exception handler.
Ah, well, that's where we begin to differ.
Alpha do_interrupt doesn't mess with cpu->interrupt_request at all, and doesn't
generate two calls to do_interrupt. The one call finds the vector for the
given interrupt, modifies the PC, and swaps to the shadow register bank.
Fin.
(Which reminds me, we really, Really, need to get those ifdefs in cpu_exec
factored out into a nice single cpu callback. Every time I read this code, I
feel I've missed something.)
> How do you set cpu->exception_index in to EXCP_DEBUG after calling
> do_interrupt with EXCP_OPCDEC?
I still don't know, but I know that _I_ don't do it. I tried stepping through
qemu itself here, but I managed to crash the guest gdb in the process; dunno
what happened there.
r~
next prev parent reply other threads:[~2014-09-12 15:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-11 21:02 [Qemu-devel] [PATCH] cpu-exec: Don't mask out external interrupts when single-stepping an invalid instruction Martin Galvan
2014-09-11 22:13 ` Peter Maydell
2014-09-11 23:52 ` Richard Henderson
2014-09-12 14:33 ` Martin Galvan
2014-09-12 15:37 ` Richard Henderson [this message]
2014-09-12 15:50 ` Martin Galvan
2014-09-15 16:02 ` Martin Galvan
2014-09-15 16:10 ` Peter Maydell
2014-09-15 16:17 ` Andreas Färber
2014-09-15 16:22 ` Peter Maydell
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=54131349.7010406@twiddle.net \
--to=rth@twiddle.net \
--cc=afaerber@suse.de \
--cc=aliguori@amazon.com \
--cc=martin.galvan@tallertechnologies.com \
--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).