disas: add libvixl to support A64 disassembly
cover disas: add libvixl to support A64 disassembly
Hi. This is a rebased and mildly cleaned up version of Claudio's RFC patchset from last year to add libvixl to QEMU and use it for A64 disassembly.
NOTE NOTE NOTE
* we now link with g++, not gcc (even if the target doesn't happen to need the A64 disassembler, since it's a bit hard to tell whether there's a C++-source .o file in the link)
* I've tested Linux (including static link of linux-user) and MacOS hosts, but not Windows
* if you have a visceral dislike of the idea of C++ in the QEMU binary now would be a good time to say OMG WTF BBQ
Changes since the RFC:
* some support for C++ compilation is already in master, so the rules.mak changes are smaller and simpler
* I've fixed the output to better fit in a qemu debug log trace
* I simplified the interface between aarch64-cxx.cc and aarch64.c a little bit
* correctly handle the "no C++ compiler, so no A64 disassembler" build case
* added support for using this as a disassembler for A64 targets as well as hosts
This patchset sits on top of target-arm.next.
You can find a git tree here:
git://git.linaro.org/people/peter.maydell/qemu-arm.git a64-vixl
web UI:
https://git.linaro.org/people/peter.maydell/qemu-arm.git/shortlog/refs/heads/a64-vixl
Sample output:
IN: _dl_start
0x0000004000805304: d11183ff sub sp, sp, #0x460 (1120) 0x0000004000805308: a9ba7bfd stp x29, x30, [sp, #-96]! 0x000000400080530c: 910003fd mov x29, sp 0x0000004000805310: a90363f7 stp x23, x24, [sp, #48] 0x0000004000805314: a90153f3 stp x19, x20, [sp, #16] 0x0000004000805318: a9025bf5 stp x21, x22, [sp, #32] 0x000000400080531c: a9046bf9 stp x25, x26, [sp, #64] 0x0000004000805320: f9002bfb str x27, [sp, #80] 0x0000004000805324: aa0003f7 mov x23, x0 0x0000004000805328: 910263a1 add x1, x29, #0x98 (152) 0x000000400080532c: 910be3a2 add x2, x29, #0x2f8 (760) 0x0000004000805330: f8008c3f str xzr, [x1, #8]! 0x0000004000805334: eb02003f cmp x1, x2 0x0000004000805338: 54ffffc1 b.ne #-0x8
Claudio Fontana (2):
disas: add libvixl source code for AArch64 A64 disassembler
disas: Implement disassembly output for A64
Peter Maydell (2):
rules.mak: Support .cc as a C++ source file suffix rules.mak: Link with C++ if we have a C++ compiler
configure | 4 + disas.c | 14 +- disas/Makefile.objs | 7 + disas/aarch64-cxx.cc | 80 + disas/aarch64.c | 39 + disas/libvixl/LICENCE | 30 + disas/libvixl/Makefile.objs | 6 + disas/libvixl/README.md | 128 ++ disas/libvixl/doc/changelog.md | 12 + disas/libvixl/doc/supported-instructions.md | 1133 ++++++++++++++ disas/libvixl/src/a64/assembler-a64.cc | 2172 ++++++++++++++++++++++++++ disas/libvixl/src/a64/assembler-a64.h | 1784 +++++++++++++++++++++ disas/libvixl/src/a64/constants-a64.h | 1104 +++++++++++++ disas/libvixl/src/a64/cpu-a64.cc | 148 ++ disas/libvixl/src/a64/cpu-a64.h | 56 + disas/libvixl/src/a64/debugger-a64.cc | 1511 ++++++++++++++++++ disas/libvixl/src/a64/debugger-a64.h | 188 +++ disas/libvixl/src/a64/decoder-a64.cc | 712 +++++++++ disas/libvixl/src/a64/decoder-a64.h | 198 +++ disas/libvixl/src/a64/disasm-a64.cc | 1678 ++++++++++++++++++++ disas/libvixl/src/a64/disasm-a64.h | 109 ++ disas/libvixl/src/a64/instructions-a64.cc | 238 +++ disas/libvixl/src/a64/instructions-a64.h | 344 ++++ disas/libvixl/src/a64/instrument-a64.cc | 638 ++++++++ disas/libvixl/src/a64/instrument-a64.h | 108 ++ disas/libvixl/src/a64/macro-assembler-a64.cc | 1108 +++++++++++++ disas/libvixl/src/a64/macro-assembler-a64.h | 1175 ++++++++++++++ disas/libvixl/src/a64/simulator-a64.cc | 2077 ++++++++++++++++++++++++ disas/libvixl/src/a64/simulator-a64.h | 576 +++++++ disas/libvixl/src/globals.h | 66 + disas/libvixl/src/platform.h | 43 + disas/libvixl/src/utils.cc | 120 ++ disas/libvixl/src/utils.h | 126 ++ include/disas/bfd.h | 1 + rules.mak | 14 +- target-arm/translate-a64.c | 2 +- 36 files changed, 17743 insertions(+), 6 deletions(-) create mode 100644 disas/aarch64-cxx.cc create mode 100644 disas/aarch64.c create mode 100644 disas/libvixl/LICENCE create mode 100644 disas/libvixl/Makefile.objs create mode 100644 disas/libvixl/README.md create mode 100644 disas/libvixl/doc/changelog.md create mode 100644 disas/libvixl/doc/supported-instructions.md create mode 100644 disas/libvixl/src/a64/assembler-a64.cc create mode 100644 disas/libvixl/src/a64/assembler-a64.h create mode 100644 disas/libvixl/src/a64/constants-a64.h create mode 100644 disas/libvixl/src/a64/cpu-a64.cc create mode 100644 disas/libvixl/src/a64/cpu-a64.h create mode 100644 disas/libvixl/src/a64/debugger-a64.cc create mode 100644 disas/libvixl/src/a64/debugger-a64.h create mode 100644 disas/libvixl/src/a64/decoder-a64.cc create mode 100644 disas/libvixl/src/a64/decoder-a64.h create mode 100644 disas/libvixl/src/a64/disasm-a64.cc create mode 100644 disas/libvixl/src/a64/disasm-a64.h create mode 100644 disas/libvixl/src/a64/instructions-a64.cc create mode 100644 disas/libvixl/src/a64/instructions-a64.h create mode 100644 disas/libvixl/src/a64/instrument-a64.cc create mode 100644 disas/libvixl/src/a64/instrument-a64.h create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.cc create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.h create mode 100644 disas/libvixl/src/a64/simulator-a64.cc create mode 100644 disas/libvixl/src/a64/simulator-a64.h create mode 100644 disas/libvixl/src/globals.h create mode 100644 disas/libvixl/src/platform.h create mode 100644 disas/libvixl/src/utils.cc create mode 100644 disas/libvixl/src/utils.h
Signature · 1 line
1.8.5
PATCH 1/4 rules.mak: Support .cc as a C++ source file suffix
The A64 disassembler libvixl uses .cc as its suffix for C++ source files, so add support for it (we already support .cpp).
--- rules.mak | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
rules.mak +5 -1
@@ -8,6 +8,7 @@ MAKEFLAGS += -rR %.d: %.h: %.c: +%.cc: %.cpp: %.m: %.mak:
@@ -54,6 +55,9 @@ endif %.o: %.asm $(call quiet-command,$(AS) $(ASFLAGS) -o $@ $<," AS $(TARGET_DIR)$@") +%.o: %.cc + $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@") + %.o: %.cpp $(call quiet-command,$(CXX) $(QEMU_INCLUDES) $(QEMU_CXXFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) -c -o $@ $<," CXX $(TARGET_DIR)$@")
@@ -77,7 +81,7 @@ quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1)) cc-option = $(if $(shell $(CC) $1 $2 -S -o /dev/null -xc /dev/null \ >/dev/null 2>&1 && echo OK), $2, $3) -VPATH_SUFFIXES = %.c %.h %.S %.cpp %.m %.mak %.texi %.sh %.rc +VPATH_SUFFIXES = %.c %.h %.S %.cc %.cpp %.m %.mak %.texi %.sh %.rc set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1))) # find-in-path
Signature · 1 line
1.8.5
PATCH 2/4 rules.mak: Link with C++ if we have a C++ compiler
In reply to Peter MaydellIf we have a C++ compiler available, link with it, because we might be linking some C++ files in. This allows us to include C++ object files in the QEMU binary proper.
--- rules.mak | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
rules.mak +6 -2
@@ -27,8 +27,12 @@ QEMU_INCLUDES += -I$(<D) -I$(@D) %.o: %.rc $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@") +# If we have a CXX we might have some C++ objects, in which case we +# must link with the C++ compiler, not the plain C compiler. +LINKPROG = $(or $(CXX),$(CC)) + ifeq ($(LIBTOOL),) -LINK = $(call quiet-command,$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ +LINK = $(call quiet-command,$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \ $(LIBS)," LINK $(TARGET_DIR)$@") else
@@ -42,7 +46,7 @@ LIBTOOL += $(if $(V),,--quiet) LINK = $(call quiet-command,\ $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \ - )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ + )$(LINKPROG) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \ $(sort $(filter %.o, $1)) $(filter-out %.o, $1) \ $(if $(filter %.lo %.la,$^),$(version-lobj-y),$(version-obj-y)) \ $(if $(filter %.lo %.la,$^),$(LIBTOOLFLAGS)) \
Signature · 1 line
1.8.5
PATCH 3/4 disas: add libvixl source code for AArch64 A64 disassembler
In reply to Peter MaydellFrom: Claudio Fontana <[email protected]>
This commit adds the sources for the libvixl AArch64 A64 disassembler library, verbatim from upstream. We include the source code itself (src/), license and README files. Examples, the scons build system etc, are excluded.
--- disas/libvixl/LICENCE | 30 + disas/libvixl/README.md | 128 ++ disas/libvixl/doc/changelog.md | 12 + disas/libvixl/doc/supported-instructions.md | 1133 ++++++++++++++ disas/libvixl/src/a64/assembler-a64.cc | 2172 ++++++++++++++++++++++++++ disas/libvixl/src/a64/assembler-a64.h | 1784 +++++++++++++++++++++ disas/libvixl/src/a64/constants-a64.h | 1104 +++++++++++++ disas/libvixl/src/a64/cpu-a64.cc | 148 ++ disas/libvixl/src/a64/cpu-a64.h | 56 + disas/libvixl/src/a64/debugger-a64.cc | 1511 ++++++++++++++++++ disas/libvixl/src/a64/debugger-a64.h | 188 +++ disas/libvixl/src/a64/decoder-a64.cc | 712 +++++++++ disas/libvixl/src/a64/decoder-a64.h | 198 +++ disas/libvixl/src/a64/disasm-a64.cc | 1678 ++++++++++++++++++++ disas/libvixl/src/a64/disasm-a64.h | 109 ++ disas/libvixl/src/a64/instructions-a64.cc | 238 +++ disas/libvixl/src/a64/instructions-a64.h | 344 ++++ disas/libvixl/src/a64/instrument-a64.cc | 638 ++++++++ disas/libvixl/src/a64/instrument-a64.h | 108 ++ disas/libvixl/src/a64/macro-assembler-a64.cc | 1108 +++++++++++++ disas/libvixl/src/a64/macro-assembler-a64.h | 1175 ++++++++++++++ disas/libvixl/src/a64/simulator-a64.cc | 2077 ++++++++++++++++++++++++ disas/libvixl/src/a64/simulator-a64.h | 576 +++++++ disas/libvixl/src/globals.h | 66 + disas/libvixl/src/platform.h | 43 + disas/libvixl/src/utils.cc | 120 ++ disas/libvixl/src/utils.h | 126 ++ 27 files changed, 17582 insertions(+) create mode 100644 disas/libvixl/LICENCE create mode 100644 disas/libvixl/README.md create mode 100644 disas/libvixl/doc/changelog.md create mode 100644 disas/libvixl/doc/supported-instructions.md create mode 100644 disas/libvixl/src/a64/assembler-a64.cc create mode 100644 disas/libvixl/src/a64/assembler-a64.h create mode 100644 disas/libvixl/src/a64/constants-a64.h create mode 100644 disas/libvixl/src/a64/cpu-a64.cc create mode 100644 disas/libvixl/src/a64/cpu-a64.h create mode 100644 disas/libvixl/src/a64/debugger-a64.cc create mode 100644 disas/libvixl/src/a64/debugger-a64.h create mode 100644 disas/libvixl/src/a64/decoder-a64.cc create mode 100644 disas/libvixl/src/a64/decoder-a64.h create mode 100644 disas/libvixl/src/a64/disasm-a64.cc create mode 100644 disas/libvixl/src/a64/disasm-a64.h create mode 100644 disas/libvixl/src/a64/instructions-a64.cc create mode 100644 disas/libvixl/src/a64/instructions-a64.h create mode 100644 disas/libvixl/src/a64/instrument-a64.cc create mode 100644 disas/libvixl/src/a64/instrument-a64.h create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.cc create mode 100644 disas/libvixl/src/a64/macro-assembler-a64.h create mode 100644 disas/libvixl/src/a64/simulator-a64.cc create mode 100644 disas/libvixl/src/a64/simulator-a64.h create mode 100644 disas/libvixl/src/globals.h create mode 100644 disas/libvixl/src/platform.h create mode 100644 disas/libvixl/src/utils.cc create mode 100644 disas/libvixl/src/utils.h
disas/libvixl/LICENCE new file +30 -0
@@ -0,0 +1,30 @@ +LICENCE +======= + +The software in this repository is covered by the following licence. + +// Copyright 2013, ARM Limited +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of ARM Limited nor the names of its contributors may be +// used to endorse or promote products derived from this software without +// specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
disas/libvixl/README.md new file +128 -0
128 lines not on this page · raw message
disas/libvixl/doc/changelog.md new file +12 -0
@@ -0,0 +1,12 @@ +VIXL Change Log +=============== + +* 1.1 + + Improved robustness of instruction decoder and disassembler. + + Added support for double-to-float conversions using `fcvt`. + + Added support for more fixed-point to floating-point conversions (`ucvtf` + and `scvtf`). + + Added instruction statistics collection class `instrument-a64.cc`. + +* 1.0 + + Initial release.
disas/libvixl/doc/supported-instructions.md new file +1133 -0
1,133 lines not on this page · raw message
disas/libvixl/src/a64/assembler-a64.cc new file +2172 -0
1,697 lines not on this page · raw message
disas/libvixl/src/a64/assembler-a64.h new file +1784 -0
1,784 lines not on this page · raw message
disas/libvixl/src/a64/constants-a64.h new file +1104 -0
1,104 lines not on this page · raw message
disas/libvixl/src/a64/cpu-a64.cc new file +148 -0
148 lines not on this page · raw message
disas/libvixl/src/a64/cpu-a64.h new file +56 -0
56 lines not on this page · raw message
disas/libvixl/src/a64/debugger-a64.cc new file +1511 -0
1,511 lines not on this page · raw message
disas/libvixl/src/a64/debugger-a64.h new file +188 -0
188 lines not on this page · raw message
disas/libvixl/src/a64/decoder-a64.cc new file +712 -0
712 lines not on this page · raw message
disas/libvixl/src/a64/decoder-a64.h new file +198 -0
198 lines not on this page · raw message
disas/libvixl/src/a64/disasm-a64.cc new file +1678 -0
1,678 lines not on this page · raw message
disas/libvixl/src/a64/disasm-a64.h new file +109 -0
109 lines not on this page · raw message
disas/libvixl/src/a64/instructions-a64.cc new file +238 -0
238 lines not on this page · raw message
disas/libvixl/src/a64/instructions-a64.h new file +344 -0
344 lines not on this page · raw message
disas/libvixl/src/a64/instrument-a64.cc new file +638 -0
638 lines not on this page · raw message
disas/libvixl/src/a64/instrument-a64.h new file +108 -0
108 lines not on this page · raw message
disas/libvixl/src/a64/macro-assembler-a64.cc new file +1108 -0
1,108 lines not on this page · raw message
disas/libvixl/src/a64/macro-assembler-a64.h new file +1175 -0
1,175 lines not on this page · raw message
disas/libvixl/src/a64/simulator-a64.cc new file +2077 -0
2,077 lines not on this page · raw message
disas/libvixl/src/a64/simulator-a64.h new file +576 -0
576 lines not on this page · raw message
disas/libvixl/src/globals.h new file +66 -0
66 lines not on this page · raw message
disas/libvixl/src/platform.h new file +43 -0
43 lines not on this page · raw message
disas/libvixl/src/utils.cc new file +120 -0
120 lines not on this page · raw message
disas/libvixl/src/utils.h new file +126 -0
126 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.5
Part of the diff is not shown here. View the raw message.
PATCH 4/4 disas: Implement disassembly output for A64
In reply to Peter MaydellFrom: Claudio Fontana <[email protected]>
Use libvixl to implement disassembly output in debug logs for A64, for both AArch64 hosts and targets.
[PMM:
* added support for target disassembly
* switched to custom QEMUDisassembler so the output format matches what QEMU expects
* make sure we correctly fall back to "just print hex" if we didn't build the AArch64 disassembler because of lack of a C++ compiler
* simplify the aarch64.c<->aarch64-cxx.cc interface]
--- configure | 4 +++ disas.c | 14 ++++++-- disas/Makefile.objs | 7 ++++ disas/aarch64-cxx.cc | 80 +++++++++++++++++++++++++++++++++++++++++++++ disas/aarch64.c | 39 ++++++++++++++++++++++ disas/libvixl/Makefile.objs | 6 ++++ include/disas/bfd.h | 1 + target-arm/translate-a64.c | 2 +- 8 files changed, 150 insertions(+), 3 deletions(-) create mode 100644 disas/aarch64-cxx.cc create mode 100644 disas/aarch64.c create mode 100644 disas/libvixl/Makefile.objs
configure +4 -0
@@ -4611,6 +4611,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; do arm) echo "CONFIG_ARM_DIS=y" >> $config_target_mak echo "CONFIG_ARM_DIS=y" >> config-all-disas.mak + if test -n "${cxx}"; then + echo "CONFIG_AARCH64_DIS=y" >> $config_target_mak + echo "CONFIG_AARCH64_DIS=y" >> config-all-disas.mak + fi ;; cris) echo "CONFIG_CRIS_DIS=y" >> $config_target_mak
disas.c +12 -2
@@ -190,7 +190,7 @@ static int print_insn_od_target(bfd_vma pc, disassemble_info *info)/* Disassemble this for me please... (debugging). 'flags' has the following values: i386 - 1 means 16 bit code, 2 means 64 bit code -arm - bit 0 = thumb, bit 1 = reverse endian +arm - bit 0 = thumb, bit 1 = reverse endian, bit 2 = AArch64 ppc - nonzero means little endian other targets - unused */
@@ -225,7 +225,15 @@ void target_disas(FILE *out, CPUArchState *env, target_ulong code, } print_insn = print_insn_i386;#elif defined(TARGET_ARM) -if (flags &1 ) { +if (flags &4 ) { +/* We might not be compiled with the AArch64 disassembler +* because it needs a C++ compiler; in that case we will +* fall through to the default print_insn_od case. +*/ +#if defined(TARGET_AARCH64 ) && defined(CONFIG_AARCH64_DIS ) + print_insn = print_insn_aarch64; +#endif + }else if (flags &1 ) { print_insn = print_insn_thumb1; }else { print_insn = print_insn_arm;
@@ -356,6 +364,8 @@ void disas(FILE *out, void *code, unsigned long size)#elif defined(_ARCH_PPC) s.info.disassembler_options = (char *)"any" ; print_insn = print_insn_ppc; +#elif defined(__aarch64__) && defined(CONFIG_AARCH64_DIS ) + print_insn = print_insn_aarch64;#elif defined(__alpha__) print_insn = print_insn_alpha;#elif defined(__sparc__)
disas/Makefile.objs +7 -0
@@ -1,3 +1,10 @@ +ifeq ($(CONFIG_AARCH64_DIS),y) +libvixldir = $(SRC_PATH)/disas/libvixl/src +QEMU_CFLAGS += -I$(libvixldir) -Wno-undef +common-obj-$(CONFIG_AARCH64_DIS) += libvixl/ +common-obj-$(CONFIG_AARCH64_DIS) += aarch64.o aarch64-cxx.o +endif + common-obj-$(CONFIG_ALPHA_DIS) += alpha.o common-obj-$(CONFIG_ARM_DIS) += arm.o common-obj-$(CONFIG_CRIS_DIS) += cris.o
disas/aarch64-cxx.cc new file +80 -0
80 lines not on this page · raw message
disas/aarch64.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* AArch64 disassembly output wrapper to libvixl - C part +* Copyright (c) 2013 Linaro Limited +* Written by Claudio Fontana +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "disas/bfd.h" +#define INSN_SIZE 4 + +extern int vixl_decode_insn (FILE *stream,uint8_t *); + +/* Disassemble Aarch64 bytecode. */ +int print_insn_aarch64 (uint64_t addr,disassemble_info *info) +{ +uint8_t bytes[INSN_SIZE ]; +int status; + + status = info->read_memory_func (addr, bytes,INSN_SIZE , info); +if (status !=0 ) { + info->memory_error_func (status, addr, info); +return -1 ; + } + +vixl_decode_insn (info->stream, bytes); +return INSN_SIZE ; +}
disas/libvixl/Makefile.objs new file +6 -0
@@ -0,0 +1,6 @@ +libvixl_OBJS = src/utils.o \ + src/a64/instructions-a64.o \ + src/a64/decoder-a64.o \ + src/a64/disasm-a64.o + +common-obj-$(CONFIG_AARCH64_DIS) += $(libvixl_OBJS)
include/disas/bfd.h +1 -0
@@ -379,6 +379,7 @@ int print_insn_h8300 (bfd_vma, disassemble_info*);int print_insn_h8300h (bfd_vma ,disassemble_info *);int print_insn_h8300s (bfd_vma ,disassemble_info *);int print_insn_h8500 (bfd_vma ,disassemble_info *); +int print_insn_aarch64 (bfd_vma ,disassemble_info *);int print_insn_alpha (bfd_vma ,disassemble_info *);disassembler_ftype arc_get_disassembler (int ,int );int print_insn_arm (bfd_vma ,disassemble_info *);
target-arm/translate-a64.c +1 -1
@@ -4029,7 +4029,7 @@ done_generating:qemu_log ("----------------\n" );qemu_log ("IN: %s\n" ,lookup_symbol (pc_start));log_target_disas (env, pc_start, dc->pc - pc_start, - dc->thumb | (dc->bswap_code <<1 )); +4 | (dc->bswap_code <<1 )); qemu_log("\n"); }#endif
Signature · 1 line
1.8.5
Am 07.01.2014 17:51, schrieb Peter Maydell:
Quoted 10 lines
Hi. This is a rebased and mildly cleaned up version of Claudio's RFC patchset from last year to add libvixl to QEMU and use it for A64 disassembly.
NOTE NOTE NOTE
* we now link with g++, not gcc (even if the target doesn't happen to need the A64 disassembler, since it's a bit hard to tell whether there's a C++-source .o file in the link)
* I've tested Linux (including static link of linux-user) and MacOS hosts, but not Windows
Hi,
here are some first annotations.
---
Git complains because patch 3 adds blank lines at EOF:
Applying: disas: add libvixl source code for AArch64 A64 disassembler /home/stefan/src/qemu/qemu.org/a64-vixl/.git/rebase-apply/patch:1382:
new blank line at EOF.
+ /home/stefan/src/qemu/qemu.org/a64-vixl/.git/rebase-apply/patch:11354:
new blank line at EOF.
+
warning: 2 lines add whitespace errors.
---
I'd prefer one file disas/aarch64.cc instead of these two files:
disas/aarch64-cxx.cc | 80 +++++++++++++++++++++++++++++++++++++++++++ disas/aarch64.c | 39 +++++++++++++++++++++
This would also allow removing the extern statement in the C++ code (and use a local function).
---
Spelling bugs:
disas/libvixl/src/a64/constants-a64.h:/* Add/substract extend */
substract ==> subtract
---
Compiler warnings (w32, w64):
CXX disas/aarch64-cxx.o
In file included from /home/stefan/src/qemu/qemu.org/a64-vixl/disas/libvixl/src/a64/simulator-a64.h:32:0,
from/home/stefan/src/qemu/qemu.org/a64-vixl/disas/aarch64-cxx.cc:25:/home/stefan/src/qemu/qemu.org/a64-vixl/disas/libvixl/src/a64/instructions-a64.h:60:36:
warning: left shift coun
t >= width of type [enabled by default]
(more of that kind for disas/libvixl/src/a64/instructions-a64.o)
These warnings are caused by Windows sizeof(long) == 4, so 1L has to be replaced by 1LL or 1ULL to represent a 64 bit value, or use a type cast like (int64_t)1.
---
I tested cross compilation for w32 and w64 (see comments below) and started the w32 executable (wine bin/debug/i686-w64-mingw32/aarch64-softmmu/qemu-system-aarch64 -L pc-bios --sdl).
Regards
Stefan
Quoted 6 lines · Stefan Weil
here are some first annotations.
---
Git complains because patch 3 adds blank lines at EOF:
Quoted 8 lines
Applying: disas: add libvixl source code for AArch64 A64 disassembler
/home/stefan/src/qemu/qemu.org/a64-vixl/.git/rebase-apply/patch:1382:
new blank line at EOF.
+/home/stefan/src/qemu/qemu.org/a64-vixl/.git/rebase-apply/patch:11354:
new blank line at EOF.
+
warning: 2 lines add whitespace errors.
Doh. I saw those as I applied the patches and then forgot to investigate and fix them.
Quoted 8 lines
I'd prefer one file disas/aarch64.cc instead of these two files:
disas/aarch64-cxx.cc | 80 +++++++++++++++++++++++++++++++++++++++++++ disas/aarch64.c | 39 +++++++++++++++++++++This would also allow removing the extern statement in the C++ code (and use a local function).
See the comment in aarch64-cxx.cc -- to do that we'd need to make sure bfd.h was valid for C++ as well as C compilation. This came up when Andreas reviewed the RFC and that was Claudio's explanation for the split, which is why I added the comment.
Claudio -- do you recall what the exact issue here is?
Specifically, I think the problem is that if we put print_insn_aarch64() in the C++ file then we need to have its prototype in bfd.h guarded with "extern C {}" if (and only if) we're compiling a C++ file. If you care about restricting the C++-isms to the C++ files that's a bit ugly. But we could do that if people prefer.
Some experimentation suggests it would also be possible to just do
extern "C" {
#include "disas/bfd.h"
}
in the C++ file. If that doesn't have any hidden gotchas I don't know about it looks like the nicest solution.
Quoted 5 lines
Spelling bugs:
disas/libvixl/src/a64/constants-a64.h:/* Add/substract extend */
substract ==> subtract
I don't really want to mess with the upstream libvixl code too much for preference. Unlike the binutils disassemblers, we still have the option in future for pulling in updated versions.
Quoted 11 lines
Compiler warnings (w32, w64):
CXX
disas/aarch64-cxx.o
In file included from/home/stefan/src/qemu/qemu.org/a64-vixl/disas/libvixl/src/a64/simulator-a64.h:32:0,
from/home/stefan/src/qemu/qemu.org/a64-vixl/disas/aarch64-cxx.cc:25:/home/stefan/src/qemu/qemu.org/a64-vixl/disas/libvixl/src/a64/instructions-a64.h:60:36:
warning: left shift coun
t >= width of type [enabled by default]
Quoted 5 lines
(more of that kind for
disas/libvixl/src/a64/instructions-a64.o)These warnings are caused by Windows sizeof(long) == 4, so 1L has to be replaced by 1LL or 1ULL to represent a 64 bit value, or use a type cast like (int64_t)1.
Those I think we really do need to fix, though, since they're bugs.
Quoted 4 lines
I tested cross compilation for w32 and w64 (see comments below) and started the w32 executable (wine bin/debug/i686-w64-mingw32/aarch64-softmmu/qemu-system-aarch64 -L pc-bios --sdl).
Thanks for testing this.
thanks
-- PMM
Am 08.01.2014 00:00, schrieb Peter Maydell:
Quoted 26 lines · Stefan Weil
Quoted 9 lines
I'd prefer one file disas/aarch64.cc instead of these two files:
disas/aarch64-cxx.cc | 80 +++++++++++++++++++++++++++++++++++++++++++ disas/aarch64.c | 39 +++++++++++++++++++++This would also allow removing the extern statement in the C++ code (and use a local function).
See the comment in aarch64-cxx.cc -- to do that we'd need to make sure
bfd.hwas valid for C++ as well as C compilation. This came up when Andreas reviewed the RFC and that was Claudio's explanation for the split, which is why I added the comment.Claudio -- do you recall what the exact issue here is?
Specifically, I think the problem is that if we put
print_insn_aarch64()in the C++ file then we need to have its prototype inbfd.hguarded with "extern C {}" if (and only if) we're compiling a C++ file. If you care about restricting the C++-isms to the C++ files that's a bit ugly. But we could do that if people prefer.Some experimentation suggests it would also be possible to just do
Quoted 7 lines
extern "C" {
#include "disas/bfd.h"
}in the C++ file. If that doesn't have any hidden gotchas I don't know about it looks like the nicest solution.
Adding the extern "C" to include/disas/bfd.h would be even better. It might be possible to use the glib macros G_BEGIN_DECLS and G_END_DECLSor __BEGIN_DECLS and __END_DECLS from the C library for this purpose.
Stefan
Quoted 8 lines · Stefan Weil
Am 08.01.2014 00:00, schrieb Peter Maydell:
Quoted 7 lines
Some experimentation suggests it would also be possible to just do
extern "C" {
#include "disas/bfd.h"
}
Quoted 7 lines
Quoted 3 lines
in the C++ file. If that doesn't have any hidden gotchas I don't know about it looks like the nicest solution.
Adding the extern "C" to
include/disas/bfd.hwould be even better. It might be possible to use the glib macrosG_BEGIN_DECLSandG_END_DECLSor__BEGIN_DECLSand__END_DECLSfrom the C library for this purpose.
Depends on your point of view. I'd rather keep the C++ in the C++ files, and have QEMU's general header files be C. After all, every prototype in that header should have C linkage: it's the definition of print_insn_aarch64() that's the odd one out, not its declaration.
-- PMM
Am 07.01.2014 17:51, schrieb Peter Maydell:
Quoted 4 lines
Hi. This is a rebased and mildly cleaned up version of Claudio's RFC patchset from last year to add libvixl to QEMU and use it for A64 disassembly.
Quoted 8 lines
NOTE NOTE NOTE
* we now link with g++, not gcc (even if the target doesn't happen to need the A64 disassembler, since it's a bit hard to tell whether there's a C++-source .o file in the link)
* I've tested Linux (including static link of linux-user) and MacOS hosts, but not Windows
* if you have a visceral dislike of the idea of C++ in the QEMU binary now would be a good time to say OMG WTF BBQ
For w32, C++ (currently only aarch64 executables) means loading additional DLL files:
text data bss dec hex filename
91453 1636 1012 94101 16f95/usr/lib/gcc/i686-w64-mingw32/4.6/libgcc_s_sjlj-1.dll
796376 29784 3744 829904 ca9d0/usr/lib/gcc/i686-w64-mingw32/4.6/libstdc++-6.dll
They slightly increase the load time and the memory footprint (reducing the meory which is available for QEMU system emulation), but I think this can be neglected. The Windows installers will get larger of course, too.
For Linux, QEMU will have new dependencies (libstdc++, maybe more) for the aarch64 executables. CC'ing Aurelien therefore.
Regards
Stefan
Quoted 23 lines · [email protected] writes:
Am 07.01.2014 17:51, schrieb Peter Maydell:
Quoted 4 lines
Hi. This is a rebased and mildly cleaned up version of Claudio's RFC patchset from last year to add libvixl to QEMU and use it for A64 disassembly.
Quoted 8 lines
NOTE NOTE NOTE
* we now link with g++, not gcc (even if the target doesn't happen to need the A64 disassembler, since it's a bit hard to tell whether there's a C++-source .o file in the link)
* I've tested Linux (including static link of linux-user) and MacOS hosts, but not Windows
* if you have a visceral dislike of the idea of C++ in the QEMU binary now would be a good time to say OMG WTF BBQFor w32, C++ (currently only aarch64 executables) means loading additional DLL files:
text data bss dec hex filename
91453 1636 1012 94101 16f95/usr/lib/gcc/i686-w64-mingw32/4.6/libgcc_s_sjlj-1.dll
796376 29784 3744 829904 ca9d0/usr/lib/gcc/i686-w64-mingw32/4.6/libstdc++-6.dll
Quoted 7 lines
They slightly increase the load time and the memory footprint (reducing the meory which is available for QEMU system emulation), but I think this can be neglected. The Windows installers will get larger of course, too.
For Linux, QEMU will have new dependencies (libstdc++, maybe more) for the aarch64 executables. CC'ing Aurelien therefore.
Is there an argument for making this an optional component. It would be useful to know how many users care about having access to the target assembly. Certainly I'm only looking at it while developing TCG code.
Cheers,
--
Alex Bennée
QEMU/KVM Hacker for Linaro
Quoted 3 lines · Alex Bennée
Is there an argument for making this an optional component. It would be useful to know how many users care about having access to the target assembly. Certainly I'm only looking at it while developing TCG code.
If you really don't want the dep you can configure with '--cxx=', and then we'll fall back to "no C++ compiler, don't build C++-only bits".
One of my aims here is that I don't particularly want the A64 translator to be a second class citizen in terms of what features it supports. Debug logs are generally useful (which is why they're present) and being able to have end users grab a debug log is nice for tracking down issues sometimes.
thanks
-- PMM
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Alex Bennée
Is there an argument for making this an optional component. It would be useful to know how many users care about having access to the target assembly. Certainly I'm only looking at it while developing TCG code.
Quoted 8 lines
If you really don't want the dep you can configure with '--cxx=', and then we'll fall back to "no C++ compiler, don't build C++-only bits".
One of my aims here is that I don't particularly want the A64 translator to be a second class citizen in terms of what features it supports. Debug logs are generally useful (which is why they're present) and being able to have end users grab a debug log is nice for tracking down issues sometimes.
It's also very useful to just be able to do "x /i $pc" on the qemu monitor. So yes, a working disassembler is defintiely a must have.
Alex
Quoted 29 lines · Peter Maydell
configure | 4 + disas.c | 14 +- disas/Makefile.objs | 7 + disas/aarch64-cxx.cc | 80 + disas/aarch64.c | 39 + disas/libvixl/LICENCE | 30 + disas/libvixl/Makefile.objs | 6 + disas/libvixl/README.md | 128 ++ disas/libvixl/doc/changelog.md | 12 + disas/libvixl/doc/supported-instructions.md | 1133 ++++++++++++++ disas/libvixl/src/a64/assembler-a64.cc | 2172 ++++++++++++++++++++++++++ disas/libvixl/src/a64/assembler-a64.h | 1784 +++++++++++++++++++++ disas/libvixl/src/a64/constants-a64.h | 1104 +++++++++++++ disas/libvixl/src/a64/cpu-a64.cc | 148 ++ disas/libvixl/src/a64/cpu-a64.h | 56 + disas/libvixl/src/a64/debugger-a64.cc | 1511 ++++++++++++++++++ disas/libvixl/src/a64/debugger-a64.h | 188 +++ disas/libvixl/src/a64/decoder-a64.cc | 712 +++++++++ disas/libvixl/src/a64/decoder-a64.h | 198 +++ disas/libvixl/src/a64/disasm-a64.cc | 1678 ++++++++++++++++++++ disas/libvixl/src/a64/disasm-a64.h | 109 ++ disas/libvixl/src/a64/instructions-a64.cc | 238 +++ disas/libvixl/src/a64/instructions-a64.h | 344 ++++ disas/libvixl/src/a64/instrument-a64.cc | 638 ++++++++ disas/libvixl/src/a64/instrument-a64.h | 108 ++ disas/libvixl/src/a64/macro-assembler-a64.cc | 1108 +++++++++++++ disas/libvixl/src/a64/macro-assembler-a64.h | 1175 ++++++++++++++ disas/libvixl/src/a64/simulator-a64.cc | 2077 ++++++++++++++++++++++++ disas/libvixl/src/a64/simulator-a64.h | 576 +++++++
Quoted 8 lines
disas/libvixl/src/globals.h | 66 + disas/libvixl/src/platform.h | 43 + disas/libvixl/src/utils.cc | 120 ++ disas/libvixl/src/utils.h | 126 ++ include/disas/bfd.h | 1 + rules.mak | 14 +- target-arm/translate-a64.c | 2 +- 36 files changed, 17743 insertions(+), 6 deletions(-)
Another option we could consider here is only pulling in the set of source files we compile plus the headers they require, not the whole library. That's
126 disas/libvixl/src/utils.h
712 disas/libvixl/src/a64/decoder-a64.cc
198 disas/libvixl/src/a64/decoder-a64.h
1678 disas/libvixl/src/a64/disasm-a64.cc
344 disas/libvixl/src/a64/instructions-a64.h
1104 disas/libvixl/src/a64/constants-a64.h
109 disas/libvixl/src/a64/disasm-a64.h
56 disas/libvixl/src/a64/cpu-a64.h
1784 disas/libvixl/src/a64/assembler-a64.h
238 disas/libvixl/src/a64/instructions-a64.cc
43 disas/libvixl/src/platform.h
66 disas/libvixl/src/globals.h
120 disas/libvixl/src/utils.cc
for about 6600 lines total. That's a significant reduction in the amount of code we're carrying around; the tradeoff is that if/when we have to update to a new libvixl it's not quite such a simple drop-in replacement as it might otherwise be, since you'd need to do the trimming down of files again. On balance I think only taking the files we use is probably the best thing.
thanks
-- PMM
Quoted 1 line · [email protected] writes:
On 7 January 2014 16:51, Peter Maydell <[email protected]> wrote:
<snip>
Quoted 3 lines
Another option we could consider here is only pulling in the set of source files we compile plus the headers they require, not the whole library. That's
<snip>
Quoted 6 lines
for about 6600 lines total. That's a significant reduction in the amount of code we're carrying around; the tradeoff is that if/when we have to update to a new libvixl it's not quite such a simple drop-in replacement as it might otherwise be, since you'd need to do the trimming down of files again. On balance I think only taking the files we use is probably the best thing.
It also raises the question of our policy of embedding 3rd party code. Are there any other examples other than softfloat? AFAIK thinks like the roms use git sub-modules rather than importing things.
There is another philosophical question of why have two decoders when we already have one (which doesn't generate assembler atm) but I suspect have a working dis-assembler is better than none.
Cheers,
--
Alex Bennée
QEMU/KVM Hacker for Linaro