1 TCG Interpreter (TCI) - Copyright (c) 2011 Stefan Weil.
3 This file is released under the BSD license.
7 TCG (Tiny Code Generator) is a code generator which translates
8 code fragments ("basic blocks") from target code (any of the
9 targets supported by QEMU) to a code representation which
12 QEMU can create native code for some hosts (arm, i386, ia64, ppc, ppc64,
13 s390, sparc, x86_64). For others, unofficial host support was written.
15 By adding a code generator for a virtual machine and using an
16 interpreter for the generated bytecode, it is possible to
17 support (almost) any host.
19 This is what TCI (Tiny Code Interpreter) does.
23 Like each TCG host frontend, TCI implements the code generator in
24 tcg-target.c.inc, tcg-target.h. Both files are in directory tcg/tci.
26 The additional file tcg/tci.c adds the interpreter and disassembler.
28 The bytecode consists of opcodes (with only a few exceptions, with
29 the same same numeric values and semantics as used by TCG), and up
30 to six arguments packed into a 32-bit integer. See comments in tci.c
31 for details on the encoding.
35 For hosts without native TCG, the interpreter TCI must be enabled by
37 configure --enable-tcg-interpreter
39 If configure is called without --enable-tcg-interpreter, it will
40 suggest using this option. Setting it automatically would need
41 additional code in configure which must be fixed when new native TCG
42 implementations are added.
44 For hosts with native TCG, the interpreter TCI can be enabled by
46 configure --enable-tcg-interpreter
48 The only difference from running QEMU with TCI to running without TCI
49 should be speed. Especially during development of TCI, it was very
50 useful to compare runs with and without TCI. Create /tmp/qemu.log by
52 qemu-system-i386 -d in_asm,op_opt,cpu -D /tmp/qemu.log -singlestep
54 once with interpreter and once without interpreter and compare the resulting
55 qemu.log files. This is also useful to see the effects of additional
56 registers or additional opcodes (it is easy to modify the virtual machine).
57 It can also be used to verify native TCGs.
59 Hosts with native TCG can also enable TCI by claiming to be unsupported:
61 configure --cpu=unknown --enable-tcg-interpreter
63 configure then no longer uses the native linker script (*.ld) for
69 TCI needs special implementation for 32 and 64 bit host, 32 and 64 bit target,
70 host and target with same or different endianness.
74 ------------+------------------------------------------------------------
75 target (le) | s0, u0 s1, u1 s?, u? s?, u?
78 target (le) | sc, uc s1, u1 s?, u? s?, u?
81 target (be) | sc, u0 sc, uc s?, u? s?, u?
84 target (be) | sc, uc sc, uc s?, u? s?, u?
95 Linux user mode emulation
98 u0 = static hello works
99 u1 = linux-user-test works
103 * TCI is not widely tested. It was written and tested on a x86_64 host
104 running i386 and x86_64 system emulation and Linux user mode.
105 A cross compiled QEMU for i386 host also works with the same basic tests.
106 A cross compiled QEMU for mipsel host works, too. It is terribly slow
107 because I run it in a mips malta emulation, so it is an interpreted
108 emulation in an emulation.
109 A cross compiled QEMU for arm host works (tested with pc bios).
110 A cross compiled QEMU for ppc host works at least partially:
111 i386-linux-user/qemu-i386 can run a simple hello-world program
112 (tested in a ppc emulation).
114 * Some TCG opcodes are either missing in the code generator and/or
115 in the interpreter. These opcodes raise a runtime exception, so it is
116 possible to see where code must be added.
118 * It might be useful to have a runtime option which selects the native TCG
119 or TCI, so QEMU would have to include two TCGs. Today, selecting TCI
120 is a configure option, so you need two compilations of QEMU.