[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: qemu_plugin_insn_disas() versus -cpu

From: Marc Hacin
Subject: Re: qemu_plugin_insn_disas() versus -cpu
Date: Tue, 31 Mar 2020 17:39:03 +0200
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1

Le 31/03/2020 à 16:52, Peter Maydell a écrit :
On Tue, 31 Mar 2020 at 14:35, Marc Hacin <address@hidden> wrote:
I am using qemu_plugin_insn_disas() in a TCG plugin.
Some floating point instructions are properly translated to host code,
as it works in the emulator, but are translated to ".byte " by

It seems that the capstone library behind qemu_plugin_insn_disas does
not support that PowerPC core.

But as the emulator translates right the guest code, I wonder why
capstone is required.

The code for emulation does "take these bytes, and generate
QEMU TCG intermediate representation opcodes that implement
the meaning of the insns". The code for disassembly does
"take these bytes, and generate a human-readable string".

OK, seen from my couch I though it was nearly the same tasks.

Within QEMU they're entirely separate (we call one the
"translator" and the other the "disassembler"), and the
disassembler is usually a bit of 3rd party code (we have
some in-tree code from an old binutils, and we use capstone).

Isn't it possible for the translator to also build
a string, disassembling of any guest instruction ? So as to be
conformant with configure'd selected targets.

This would be a fair bit of extra work: the structure of the
two pieces of code is similar in some ways but adding in
support for disassemble-to-string to the translator code
would be awkward. We use third party disassembly
libraries because we don't want to have to reinvent that
wheel, and the only thing we use a disassembler for is
tracing output for debug purposes, so it's not critical
if it doesn't correctly handle some insns on some targets.

It is not solely for debug purposes now as it is part of an API available to TCG plugins.

Plus as a bonus, having the disassembly be from 3rd party code
means you don't get confused by having a bug in the translator
which mis-decodes something but looks correct in the dissasembly
because it has the identical bug.

Or else, use of the GNU binutils code ?

We do that where we can, but the problem is that newer versions
of GNU binutils are GPL v3-only, which is not compatible with
QEMU's GPL-v2 license. So we use binutils code from the last
GPLv2 release, but obviously this is missing handling for
anything added to the target architecture after that date.
You're right that ideally we'd be able to use binutils code
here, but unfortunately the licensing doesn't allow it.
Capstone is the best compromise we've found between
"license is compatible" and "covers architectures we want"
but it's turned out not to be kept as up-to-date as we'd
first hoped it would be when we started using it.

Ah yes, licenses.

-- PMM

reply via email to

[Prev in Thread] Current Thread [Next in Thread]