xref: /openbmc/qemu/tcg/tci/README (revision c586691e676214eb7edf6a468e84e7ce3b314d43)
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
24139c1837SPaolo Bonzinitcg-target.c.inc, tcg-target.h. Both files are in directory tcg/tci.
257316329aSStefan Weil
2665089889SRichard HendersonThe additional file tcg/tci.c adds the interpreter and disassembler.
277316329aSStefan Weil
2865089889SRichard HendersonThe bytecode consists of opcodes (with only a few exceptions, with
2965089889SRichard Hendersonthe same same numeric values and semantics as used by TCG), and up
3065089889SRichard Hendersonto six arguments packed into a 32-bit integer.  See comments in tci.c
3165089889SRichard Hendersonfor details on the encoding.
327316329aSStefan Weil
337316329aSStefan Weil3) Usage
347316329aSStefan Weil
357316329aSStefan WeilFor hosts without native TCG, the interpreter TCI must be enabled by
367316329aSStefan Weil
377316329aSStefan Weil        configure --enable-tcg-interpreter
387316329aSStefan Weil
397316329aSStefan WeilIf configure is called without --enable-tcg-interpreter, it will
407316329aSStefan Weilsuggest using this option. Setting it automatically would need
417316329aSStefan Weiladditional code in configure which must be fixed when new native TCG
427316329aSStefan Weilimplementations are added.
437316329aSStefan Weil
447316329aSStefan WeilFor hosts with native TCG, the interpreter TCI can be enabled by
457316329aSStefan Weil
467316329aSStefan Weil        configure --enable-tcg-interpreter
477316329aSStefan Weil
487316329aSStefan WeilThe only difference from running QEMU with TCI to running without TCI
497316329aSStefan Weilshould be speed. Especially during development of TCI, it was very
507316329aSStefan Weiluseful to compare runs with and without TCI. Create /tmp/qemu.log by
517316329aSStefan Weil
52*12fd0f41SPeter Maydell        qemu-system-i386 -d in_asm,op_opt,cpu -D /tmp/qemu.log -accel tcg,one-insn-per-tb=on
537316329aSStefan Weil
547316329aSStefan Weilonce with interpreter and once without interpreter and compare the resulting
557316329aSStefan Weilqemu.log files. This is also useful to see the effects of additional
567316329aSStefan Weilregisters or additional opcodes (it is easy to modify the virtual machine).
577316329aSStefan WeilIt can also be used to verify native TCGs.
587316329aSStefan Weil
597316329aSStefan WeilHosts with native TCG can also enable TCI by claiming to be unsupported:
607316329aSStefan Weil
617316329aSStefan Weil        configure --cpu=unknown --enable-tcg-interpreter
627316329aSStefan Weil
637316329aSStefan Weilconfigure then no longer uses the native linker script (*.ld) for
647316329aSStefan Weiluser mode emulation.
657316329aSStefan Weil
667316329aSStefan Weil
677316329aSStefan Weil4) Status
687316329aSStefan Weil
697316329aSStefan WeilTCI needs special implementation for 32 and 64 bit host, 32 and 64 bit target,
707316329aSStefan Weilhost and target with same or different endianness.
717316329aSStefan Weil
727316329aSStefan Weil            | host (le)                     host (be)
737316329aSStefan Weil            | 32             64             32             64
747316329aSStefan Weil------------+------------------------------------------------------------
757316329aSStefan Weiltarget (le) | s0, u0         s1, u1         s?, u?         s?, u?
767316329aSStefan Weil32 bit      |
777316329aSStefan Weil            |
787316329aSStefan Weiltarget (le) | sc, uc         s1, u1         s?, u?         s?, u?
797316329aSStefan Weil64 bit      |
807316329aSStefan Weil            |
817316329aSStefan Weiltarget (be) | sc, u0         sc, uc         s?, u?         s?, u?
827316329aSStefan Weil32 bit      |
837316329aSStefan Weil            |
847316329aSStefan Weiltarget (be) | sc, uc         sc, uc         s?, u?         s?, u?
857316329aSStefan Weil64 bit      |
867316329aSStefan Weil            |
877316329aSStefan Weil
887316329aSStefan WeilSystem emulation
897316329aSStefan Weils? = untested
907316329aSStefan Weilsc = compiles
917316329aSStefan Weils0 = bios works
927316329aSStefan Weils1 = grub works
937316329aSStefan Weils2 = Linux boots
947316329aSStefan Weil
957316329aSStefan WeilLinux user mode emulation
967316329aSStefan Weilu? = untested
977316329aSStefan Weiluc = compiles
987316329aSStefan Weilu0 = static hello works
997316329aSStefan Weilu1 = linux-user-test works
1007316329aSStefan Weil
1017316329aSStefan Weil5) Todo list
1027316329aSStefan Weil
1037316329aSStefan Weil* TCI is not widely tested. It was written and tested on a x86_64 host
1047316329aSStefan Weil  running i386 and x86_64 system emulation and Linux user mode.
1057316329aSStefan Weil  A cross compiled QEMU for i386 host also works with the same basic tests.
1067316329aSStefan Weil  A cross compiled QEMU for mipsel host works, too. It is terribly slow
1077316329aSStefan Weil  because I run it in a mips malta emulation, so it is an interpreted
1087316329aSStefan Weil  emulation in an emulation.
1097316329aSStefan Weil  A cross compiled QEMU for arm host works (tested with pc bios).
1107316329aSStefan Weil  A cross compiled QEMU for ppc host works at least partially:
1117316329aSStefan Weil  i386-linux-user/qemu-i386 can run a simple hello-world program
1127316329aSStefan Weil  (tested in a ppc emulation).
1137316329aSStefan Weil
1147316329aSStefan Weil* Some TCG opcodes are either missing in the code generator and/or
1157316329aSStefan Weil  in the interpreter. These opcodes raise a runtime exception, so it is
1167316329aSStefan Weil  possible to see where code must be added.
1177316329aSStefan Weil
1187316329aSStefan Weil* It might be useful to have a runtime option which selects the native TCG
1197316329aSStefan Weil  or TCI, so QEMU would have to include two TCGs. Today, selecting TCI
1207316329aSStefan Weil  is a configure option, so you need two compilations of QEMU.
121