xref: /openbmc/qemu/tcg/tci/README (revision 139c1837db7eaee53e1c441629b5bcc159e1deb0)
17316329aSStefan WeilTCG Interpreter (TCI) - Copyright (c) 2011 Stefan Weil.
27316329aSStefan Weil
37316329aSStefan WeilThis file is released under the BSD license.
47316329aSStefan Weil
57316329aSStefan Weil1) Introduction
67316329aSStefan Weil
77316329aSStefan WeilTCG (Tiny Code Generator) is a code generator which translates
87316329aSStefan Weilcode fragments ("basic blocks") from target code (any of the
97316329aSStefan Weiltargets supported by QEMU) to a code representation which
107316329aSStefan Weilcan be run on a host.
117316329aSStefan Weil
12d41f3c3cSThomas HuthQEMU can create native code for some hosts (arm, i386, ia64, ppc, ppc64,
137316329aSStefan Weils390, sparc, x86_64). For others, unofficial host support was written.
147316329aSStefan Weil
157316329aSStefan WeilBy adding a code generator for a virtual machine and using an
167316329aSStefan Weilinterpreter for the generated bytecode, it is possible to
177316329aSStefan Weilsupport (almost) any host.
187316329aSStefan Weil
197316329aSStefan WeilThis is what TCI (Tiny Code Interpreter) does.
207316329aSStefan Weil
217316329aSStefan Weil2) Implementation
227316329aSStefan Weil
237316329aSStefan WeilLike each TCG host frontend, TCI implements the code generator in
24*139c1837SPaolo Bonzinitcg-target.c.inc, tcg-target.h. Both files are in directory tcg/tci.
257316329aSStefan Weil
267316329aSStefan WeilThe additional file tcg/tci.c adds the interpreter.
277316329aSStefan Weil
287316329aSStefan WeilThe bytecode consists of opcodes (same numeric values as those used by
297316329aSStefan WeilTCG), command length and arguments of variable size and number.
307316329aSStefan Weil
317316329aSStefan Weil3) Usage
327316329aSStefan Weil
337316329aSStefan WeilFor hosts without native TCG, the interpreter TCI must be enabled by
347316329aSStefan Weil
357316329aSStefan Weil        configure --enable-tcg-interpreter
367316329aSStefan Weil
377316329aSStefan WeilIf configure is called without --enable-tcg-interpreter, it will
387316329aSStefan Weilsuggest using this option. Setting it automatically would need
397316329aSStefan Weiladditional code in configure which must be fixed when new native TCG
407316329aSStefan Weilimplementations are added.
417316329aSStefan Weil
427316329aSStefan WeilSystem emulation should work on any 32 or 64 bit host.
437316329aSStefan WeilUser mode emulation might work. Maybe a new linker script (*.ld)
447316329aSStefan Weilis needed. Byte order might be wrong (on big endian hosts)
457316329aSStefan Weiland need fixes in configure.
467316329aSStefan Weil
477316329aSStefan WeilFor hosts with native TCG, the interpreter TCI can be enabled by
487316329aSStefan Weil
497316329aSStefan Weil        configure --enable-tcg-interpreter
507316329aSStefan Weil
517316329aSStefan WeilThe only difference from running QEMU with TCI to running without TCI
527316329aSStefan Weilshould be speed. Especially during development of TCI, it was very
537316329aSStefan Weiluseful to compare runs with and without TCI. Create /tmp/qemu.log by
547316329aSStefan Weil
55989b697dSPeter Maydell        qemu-system-i386 -d in_asm,op_opt,cpu -D /tmp/qemu.log -singlestep
567316329aSStefan Weil
577316329aSStefan Weilonce with interpreter and once without interpreter and compare the resulting
587316329aSStefan Weilqemu.log files. This is also useful to see the effects of additional
597316329aSStefan Weilregisters or additional opcodes (it is easy to modify the virtual machine).
607316329aSStefan WeilIt can also be used to verify native TCGs.
617316329aSStefan Weil
627316329aSStefan WeilHosts with native TCG can also enable TCI by claiming to be unsupported:
637316329aSStefan Weil
647316329aSStefan Weil        configure --cpu=unknown --enable-tcg-interpreter
657316329aSStefan Weil
667316329aSStefan Weilconfigure then no longer uses the native linker script (*.ld) for
677316329aSStefan Weiluser mode emulation.
687316329aSStefan Weil
697316329aSStefan Weil
707316329aSStefan Weil4) Status
717316329aSStefan Weil
727316329aSStefan WeilTCI needs special implementation for 32 and 64 bit host, 32 and 64 bit target,
737316329aSStefan Weilhost and target with same or different endianness.
747316329aSStefan Weil
757316329aSStefan Weil            | host (le)                     host (be)
767316329aSStefan Weil            | 32             64             32             64
777316329aSStefan Weil------------+------------------------------------------------------------
787316329aSStefan Weiltarget (le) | s0, u0         s1, u1         s?, u?         s?, u?
797316329aSStefan Weil32 bit      |
807316329aSStefan Weil            |
817316329aSStefan Weiltarget (le) | sc, uc         s1, u1         s?, u?         s?, u?
827316329aSStefan Weil64 bit      |
837316329aSStefan Weil            |
847316329aSStefan Weiltarget (be) | sc, u0         sc, uc         s?, u?         s?, u?
857316329aSStefan Weil32 bit      |
867316329aSStefan Weil            |
877316329aSStefan Weiltarget (be) | sc, uc         sc, uc         s?, u?         s?, u?
887316329aSStefan Weil64 bit      |
897316329aSStefan Weil            |
907316329aSStefan Weil
917316329aSStefan WeilSystem emulation
927316329aSStefan Weils? = untested
937316329aSStefan Weilsc = compiles
947316329aSStefan Weils0 = bios works
957316329aSStefan Weils1 = grub works
967316329aSStefan Weils2 = Linux boots
977316329aSStefan Weil
987316329aSStefan WeilLinux user mode emulation
997316329aSStefan Weilu? = untested
1007316329aSStefan Weiluc = compiles
1017316329aSStefan Weilu0 = static hello works
1027316329aSStefan Weilu1 = linux-user-test works
1037316329aSStefan Weil
1047316329aSStefan Weil5) Todo list
1057316329aSStefan Weil
1067316329aSStefan Weil* TCI is not widely tested. It was written and tested on a x86_64 host
1077316329aSStefan Weil  running i386 and x86_64 system emulation and Linux user mode.
1087316329aSStefan Weil  A cross compiled QEMU for i386 host also works with the same basic tests.
1097316329aSStefan Weil  A cross compiled QEMU for mipsel host works, too. It is terribly slow
1107316329aSStefan Weil  because I run it in a mips malta emulation, so it is an interpreted
1117316329aSStefan Weil  emulation in an emulation.
1127316329aSStefan Weil  A cross compiled QEMU for arm host works (tested with pc bios).
1137316329aSStefan Weil  A cross compiled QEMU for ppc host works at least partially:
1147316329aSStefan Weil  i386-linux-user/qemu-i386 can run a simple hello-world program
1157316329aSStefan Weil  (tested in a ppc emulation).
1167316329aSStefan Weil
1177316329aSStefan Weil* Some TCG opcodes are either missing in the code generator and/or
1187316329aSStefan Weil  in the interpreter. These opcodes raise a runtime exception, so it is
1197316329aSStefan Weil  possible to see where code must be added.
1207316329aSStefan Weil
1217316329aSStefan Weil* The pseudo code is not optimized and still ugly. For hosts with special
1227316329aSStefan Weil  alignment requirements, it needs some fixes (maybe aligned bytecode
1237316329aSStefan Weil  would also improve speed for hosts which support byte alignment).
1247316329aSStefan Weil
1257316329aSStefan Weil* A better disassembler for the pseudo code would be nice (a very primitive
126*139c1837SPaolo Bonzini  disassembler is included in tcg-target.c.inc).
1277316329aSStefan Weil
1287316329aSStefan Weil* It might be useful to have a runtime option which selects the native TCG
1297316329aSStefan Weil  or TCI, so QEMU would have to include two TCGs. Today, selecting TCI
1307316329aSStefan Weil  is a configure option, so you need two compilations of QEMU.
131