qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-s390x@nongnu.org, qemu-devel@nongnu.org,
	Richard Henderson <richard.henderson@linaro.org>,
	Ilya Leoshkevich <iii@linux.ibm.com>,
	David Hildenbrand <david@redhat.com>
Subject: Re: [risu PATCH v2 1/4] s390x: Add basic s390x support to the C code
Date: Wed, 13 Sep 2023 10:50:06 +0200	[thread overview]
Message-ID: <d17c56f3-c177-58ce-559e-cc514c70af4d@redhat.com> (raw)
In-Reply-To: <CAFEAcA8pKuFso_boUxzAsAktegT4DJ9U2q26RmiqYK5TWKTinw@mail.gmail.com>

On 12/09/2023 18.50, Peter Maydell wrote:
> On Tue, 5 Sept 2023 at 12:50, Thomas Huth <thuth@redhat.com> wrote:
>>
>> With these changes, it is now possible to compile the "risu" binary
>> for s390x hosts.
>>
>> Acked-by: Ilya Leoshkevich <iii@linux.ibm.com>
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
> 
> 
> 
>> +/* reginfo_init: initialize with a ucontext */
>> +void reginfo_init(struct reginfo *ri, ucontext_t *uc)
>> +{
>> +    int i;
>> +
>> +    memset(ri, 0, sizeof(*ri));
>> +
>> +    ri->faulting_insn = *((uint32_t *) uc->uc_mcontext.psw.addr);
> 
> Here we extract the faulting instruction, assuming it to
> be a 32-bit insn starting at uc_mcontext.psw.addr...
> 
>> +    ri->psw_mask = uc->uc_mcontext.psw.mask;
>> +    ri->psw_addr = uc->uc_mcontext.psw.addr - image_start_address;
>> +
>> +    for (i = 0; i < 16; i++) {
>> +        ri->gregs[i] = uc->uc_mcontext.gregs[i];
>> +    }
>> +
>> +    memcpy(&ri->fpregs, &uc->uc_mcontext.fpregs, sizeof(fpregset_t));
>> +}
> 
>> +void advance_pc(void *vuc)
>> +{
>> +    /*
>> +     * Note: The PSW address already points to the next instruction
>> +     * after we get a SIGILL, so we must not advance it here!
>> +     */
>> +    // ucontext_t *uc = (ucontext_t *) vuc;
>> +    // uc->uc_mcontext.psw.addr += 4;
> 
> ...but here we say that psw.addr points to the instruction
> *after* the faulting one.
> 
> These don't seem like they can both be correct?

Drat, you're right, thanks for the hint! The code in reginfo_init() is 
wrong, it takes the instruction after the illegal one. It was just working 
(wrongly, but without crashing) by accident here since the OP_TESTEND 
instruction was preceeded by an OP_COMPARE instruction :-/

To get the address (and thus opcode) of the faulting instruction, I have to 
use siginfo_t->si_addr instead of using the ucontext_t structure. I will fix 
it in the next version.

  Thomas



  reply	other threads:[~2023-09-13  8:50 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-05 11:49 [risu PATCH v2 0/4] Add support for s390x to RISU Thomas Huth
2023-09-05 11:49 ` [risu PATCH v2 1/4] s390x: Add basic s390x support to the C code Thomas Huth
2023-09-12 16:50   ` Peter Maydell
2023-09-13  8:50     ` Thomas Huth [this message]
2023-09-05 11:49 ` [risu PATCH v2 2/4] s390x: Add simple s390x.risu file Thomas Huth
2023-09-05 11:49 ` [risu PATCH v2 3/4] s390x: Add basic risugen perl module for s390x Thomas Huth
2023-09-05 11:50 ` [risu PATCH v2 4/4] s390x: Update the configure script for s390x support Thomas Huth
2023-09-12 17:02   ` 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=d17c56f3-c177-58ce-559e-cc514c70af4d@redhat.com \
    --to=thuth@redhat.com \
    --cc=david@redhat.com \
    --cc=iii@linux.ibm.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=richard.henderson@linaro.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).