Patchwork arm-linux-user, i386-linux-user: Make QEMU act as TCG compiler

login
register
mail settings
Submitter Rajat Goyal
Date Feb. 22, 2012, 11:16 p.m.
Message ID <CAOSa+Cvesk2fRpeht8pPb5JROkBTtm7Po5mgbqPKNwVru+zhTw@mail.gmail.com>
Download mbox | patch
Permalink /patch/142549/
State New
Headers show

Comments

Rajat Goyal - Feb. 22, 2012, 11:16 p.m.
QEMU can be made to act as a TCG compiler for x86 and ARM user-level linux
binaries. The -tcg configure option is to be used to specify the file into
which the compilation has to be dumped. Compilation only works in
conjunction with in_asm,op logging.

On ARM, there is the burden of using the -thumb and -arm configure options
to force THUMB and ARM instruction set interpretation respectively and then
merge the correct portions from both the .tcg files to obtain the perfect
TCG compilation for the ARM binary.

The exact command to use QEMU as a TCG compiler is ${path to QEMU binary}
-D {log file name} -tcg {.tcg file name} -d in_asm,op {binary to compile}.

This patch breaks QEMU as a dynamic emulator. QEMU can only be used as a
TCG compiler after applying this patch.

Signed-off-by: Rajat Goyal <Rajat.Goyal@cl.cam.ac.uk>
陳韋任 - Feb. 23, 2012, 3:57 a.m.
Hi Rajat,

  Great work! It seems this is a kind of like static compilation, right? I think
people are more interested in using QEMU as a dynamic translator as a library.
Would you mind to tell me what scenario your work aims to?

Regards,
chenwj
Rajat Goyal - Feb. 23, 2012, 11:44 a.m.
QEMU as a dynamic translator is already available. This adds extra
functionality to QEMU. I needed to do this since I wanted to explore the
ARM memory model over TCG micro-operations; so I needed translation of the
whole binary and not just the parts which QEMU needs to execute. Don't know
if others would find this feature useful.

Rajat.

On Thu, Feb 23, 2012 at 3:57 AM, 陳韋任 <chenwj@iis.sinica.edu.tw> wrote:

> Hi Rajat,
>
>  Great work! It seems this is a kind of like static compilation, right? I
> think
> people are more interested in using QEMU as a dynamic translator as a
> library.
> Would you mind to tell me what scenario your work aims to?
>
> Regards,
> chenwj
>
> --
> Wei-Ren Chen (陳韋任)
> Computer Systems Lab, Institute of Information Science,
> Academia Sinica, Taiwan (R.O.C.)
> Tel:886-2-2788-3799 #1667
> Homepage: http://people.cs.nctu.edu.tw/~chenwj
>
Rajat Goyal - Feb. 23, 2012, 7:53 p.m.
Hi Peter,

Would QEMU developers be interested in integrating this TCG compilation
functionality that I have been working on into later releases of QEMU? The
patch I have right now breaks the original emulation but if there is some
interest in supporting static compilation into TCG in the future, I can
submit a clean patch which does not break emulation but instead adds a
run-time option to generate TCG compilation. I would be grateful if you
could let me know.

Many thanks in anticipation.

With warm regards,
Rajat.

2012/2/23 Rajat Goyal <Rajat.Goyal@cl.cam.ac.uk>

> QEMU as a dynamic translator is already available. This adds extra
> functionality to QEMU. I needed to do this since I wanted to explore the
> ARM memory model over TCG micro-operations; so I needed translation of the
> whole binary and not just the parts which QEMU needs to execute. Don't know
> if others would find this feature useful.
>
> Rajat.
>
>
> On Thu, Feb 23, 2012 at 3:57 AM, 陳韋任 <chenwj@iis.sinica.edu.tw> wrote:
>
>> Hi Rajat,
>>
>>  Great work! It seems this is a kind of like static compilation, right? I
>> think
>> people are more interested in using QEMU as a dynamic translator as a
>> library.
>> Would you mind to tell me what scenario your work aims to?
>>
>> Regards,
>> chenwj
>>
>> --
>> Wei-Ren Chen (陳韋任)
>> Computer Systems Lab, Institute of Information Science,
>> Academia Sinica, Taiwan (R.O.C.)
>> Tel:886-2-2788-3799 #1667
>> Homepage: http://people.cs.nctu.edu.tw/~chenwj
>>
>
>
Peter Maydell - Feb. 23, 2012, 10:37 p.m.
2012/2/23 Rajat Goyal <Rajat.Goyal@cl.cam.ac.uk>:
> Would QEMU developers be interested in integrating this TCG compilation
> functionality that I have been working on into later releases of QEMU? The
> patch I have right now breaks the original emulation but if there is some
> interest in supporting static compilation into TCG in the future, I can
> submit a clean patch which does not break emulation but instead adds a
> run-time option to generate TCG compilation. I would be grateful if you
> could let me know.

To be honest I don't see any general utility in it, and refactoring
everything to be able to do anything resembling this cleanly would
be an enormously painful upheaval.

-- PMM

Patch

diff --git arm-dis.c arm-dis.c
index 6bc4d71..cf92dc3 100644
--- arm-dis.c
+++ arm-dis.c
@@ -1587,10 +1587,11 @@  arm_decode_bitfield (const char *ptr, unsigned long
insn,
 }

 static void
-arm_decode_shift (long given, fprintf_function func, void *stream,
-          int print_shift)
+arm_decode_shift(long given, fprintf_function func, void *stream,
+                 void *dottcg_stream, int print_shift)
 {
   func (stream, "%s", arm_regnames[given & 0xf]);
+  func(dottcg_stream, "%s", arm_regnames[given & 0xf]);

   if ((given & 0xff0) != 0)
     {
@@ -1604,22 +1605,30 @@  arm_decode_shift (long given, fprintf_function
func, void *stream,
           if (shift == 3)
         {
           func (stream, ", rrx");
+                  func(dottcg_stream, ", rrx");
           return;
         }

           amount = 32;
         }

-      if (print_shift)
+         if (print_shift) {
         func (stream, ", %s #%d", arm_shift[shift], amount);
-      else
+            func(dottcg_stream, ", %s #%d", arm_shift[shift], amount);
+         } else {
         func (stream, ", #%d", amount);
+            func(dottcg_stream, ", #%d", amount);
+         }
     }
-      else if (print_shift)
+      else if (print_shift) {
     func (stream, ", %s %s", arm_shift[(given & 0x60) >> 5],
           arm_regnames[(given & 0xf00) >> 8]);
-      else
+        func(dottcg_stream, ", %s %s", arm_shift[(given & 0x60) >> 5],
+              arm_regnames[(given & 0xf00) >> 8]);
+      } else {
     func (stream, ", %s", arm_regnames[(given & 0xf00) >> 8]);
+        func(dottcg_stream, ", %s", arm_regnames[(given & 0xf00) >> 8]);
+      }
     }
 }

@@ -1688,38 +1697,53 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             {
             case '%':
               func (stream, "%%");
+                      func(info->dottcg_stream, "%%");
               break;

             case 'A':
               func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+                      func(info->dottcg_stream, "[%s", arm_regnames[(given
>> 16) & 0xf]);

               if ((given & (1 << 24)) != 0)
             {
               int offset = given & 0xff;

-              if (offset)
+                          if (offset) {
                 func (stream, ", #%s%d]%s",
                   ((given & 0x00800000) == 0 ? "-" : ""),
                   offset * 4,
                   ((given & 0x00200000) != 0 ? "!" : ""));
-              else
+                            func(info->dottcg_stream, ", #%s%d]%s",
+                                  ((given & 0x00800000) == 0 ? "-" : ""),
+                                  offset * 4,
+                                  ((given & 0x00200000) != 0 ? "!" : ""));
+                          } else {
                 func (stream, "]");
+                            func(info->dottcg_stream, "]");
+                          }
             }
               else
             {
               int offset = given & 0xff;

               func (stream, "]");
+                          func(info->dottcg_stream, "]");

               if (given & (1 << 21))
                 {
-                  if (offset)
+                             if (offset) {
                 func (stream, ", #%s%d",
                       ((given & 0x00800000) == 0 ? "-" : ""),
                       offset * 4);
+                                func(info->dottcg_stream, ", #%s%d",
+                                      ((given & 0x00800000) == 0 ? "-" :
""),
+                                      offset * 4);
+                             }
                 }
-              else
+                         else {
                 func (stream, ", {%d}", offset);
+                            func(info->dottcg_stream, ", {%d}", offset);
+                         }
             }
               break;

@@ -1728,12 +1752,16 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             int regno = ((given >> 12) & 0xf) | ((given >> (22 - 4)) &
0x10);
             int offset = (given >> 1) & 0x3f;

-            if (offset == 1)
+                        if (offset == 1) {
               func (stream, "{d%d}", regno);
-            else if (regno + offset > 32)
+                          func(info->dottcg_stream, "{d%d}", regno);
+                        } else if (regno + offset > 32) {
               func (stream, "{d%d-<overflow reg d%d>}", regno, regno +
offset - 1);
-            else
+                          func(info->dottcg_stream, "{d%d-<overflow reg
d%d>}", regno, regno + offset - 1);
+                        } else {
               func (stream, "{d%d-d%d}", regno, regno + offset - 1);
+                          func(info->dottcg_stream, "{d%d-d%d}", regno,
regno + offset - 1);
+                        }
               }
               break;

@@ -1744,17 +1772,21 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             int add = (given >> 23) & 1;

             func (stream, "[%s", arm_regnames[rn]);
+                        func(info->dottcg_stream, "[%s", arm_regnames[rn]);

             if (offset)
               {
                 if (!add)
                   offset = -offset;
                 func (stream, ", #%d", offset);
+                            func(info->dottcg_stream, ", #%d", offset);
               }
             func (stream, "]");
+                        func(info->dottcg_stream, "]");
             if (rn == 15)
               {
                 func (stream, "\t; ");
+                            func(info->dottcg_stream, "\t; ");
                             /* FIXME: Unsure if info->bytes_per_chunk is
the
                                right thing to use here.  */
                 info->print_address_func (offset + pc
@@ -1765,6 +1797,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,

             case 'c':
               func (stream, "%s", arm_conditional[cond]);
+                      func(info->dottcg_stream, "%s",
arm_conditional[cond]);
               break;

             case 'I':
@@ -1782,6 +1815,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               imm |= (-1 << 7);

             func (stream, "%d", imm);
+                        func(info->dottcg_stream, "%d", imm);
               }

               break;
@@ -1791,15 +1825,19 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             {
             case 0:
               func (stream, "4");
+                          func(info->dottcg_stream, "4");
               break;
             case 0x8000:
               func (stream, "1");
+                          func(info->dottcg_stream, "1");
               break;
             case 0x00400000:
               func (stream, "2");
+                          func(info->dottcg_stream, "2");
               break;
             default:
               func (stream, "3");
+                          func(info->dottcg_stream, "3");
             }
               break;

@@ -1808,15 +1846,19 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             {
             case 0:
               func (stream, "s");
+                          func(info->dottcg_stream, "s");
               break;
             case 0x80:
               func (stream, "d");
+                          func(info->dottcg_stream, "d");
               break;
             case 0x00080000:
               func (stream, "e");
+                          func(info->dottcg_stream, "e");
               break;
             default:
               func (stream, _("<illegal precision>"));
+                          func(info->dottcg_stream, _("<illegal
precision>"));
               break;
             }
               break;
@@ -1825,15 +1867,19 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
             {
             case 0:
               func (stream, "s");
+                          func(info->dottcg_stream, "s");
               break;
             case 0x8000:
               func (stream, "d");
+                          func(info->dottcg_stream, "d");
               break;
             case 0x00400000:
               func (stream, "e");
+                          func(info->dottcg_stream, "e");
               break;
             default:
               func (stream, "p");
+                          func(info->dottcg_stream, "p");
               break;
             }
               break;
@@ -1844,12 +1890,15 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               break;
             case 0x20:
               func (stream, "p");
+                          func(info->dottcg_stream, "p");
               break;
             case 0x40:
               func (stream, "m");
+                          func(info->dottcg_stream, "m");
               break;
             default:
               func (stream, "z");
+                          func(info->dottcg_stream, "z");
               break;
             }
               break;
@@ -1866,63 +1915,84 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               {
               case 'r':
                 func (stream, "%s", arm_regnames[value]);
+                            func(info->dottcg_stream, "%s",
arm_regnames[value]);
                 break;
               case 'D':
                 func (stream, "d%ld", value);
+                            func(info->dottcg_stream, "d%ld", value);
                 break;
               case 'Q':
-                if (value & 1)
+                            if (value & 1) {
                   func (stream, "<illegal reg q%ld.5>", value >> 1);
-                else
+                              func(info->dottcg_stream, "<illegal reg
q%ld.5>", value >> 1);
+                            } else {
                   func (stream, "q%ld", value >> 1);
+                              func(info->dottcg_stream, "q%ld", value >>
1);
+                            }
                 break;
               case 'd':
                 func (stream, "%ld", value);
+                            func(info->dottcg_stream, "%ld", value);
                 break;
                           case 'k':
                             {
                               int from = (given & (1 << 7)) ? 32 : 16;
                               func (stream, "%ld", from - value);
+                              func(info->dottcg_stream, "%ld", from -
value);
                             }
                             break;

               case 'f':
-                if (value > 7)
+                            if (value > 7) {
                   func (stream, "#%s", arm_fp_const[value & 7]);
-                else
+                              func(info->dottcg_stream, "#%s",
arm_fp_const[value & 7]);
+                            } else {
                   func (stream, "f%ld", value);
+                              func(info->dottcg_stream, "f%ld", value);
+                            }
                 break;

               case 'w':
-                if (width == 2)
+                            if (width == 2) {
                   func (stream, "%s", iwmmxt_wwnames[value]);
-                else
+                              func(info->dottcg_stream, "%s",
iwmmxt_wwnames[value]);
+                            } else {
                   func (stream, "%s", iwmmxt_wwssnames[value]);
+                              func(info->dottcg_stream, "%s",
iwmmxt_wwssnames[value]);
+                            }
                 break;

               case 'g':
                 func (stream, "%s", iwmmxt_regnames[value]);
+                            func(info->dottcg_stream, "%s",
iwmmxt_regnames[value]);
                 break;
               case 'G':
                 func (stream, "%s", iwmmxt_cregnames[value]);
+                            func(info->dottcg_stream, "%s",
iwmmxt_cregnames[value]);
                 break;

               case 'x':
                 func (stream, "0x%lx", value);
+                            func(info->dottcg_stream, "0x%lx", value);
                 break;

               case '`':
                 c++;
-                if (value == 0)
+                            if (value == 0) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '\'':
                 c++;
-                if (value == ((1ul << width) - 1))
+                            if (value == ((1ul << width) - 1)) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '?':
                 func (stream, "%c", c[(1 << width) - (int)value]);
+                            func(info->dottcg_stream, "%c", c[(1 << width)
- (int)value]);
                 c += 1 << width;
                 break;
               default:
@@ -1940,6 +2010,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
                 {
                 case '4': /* Sm pair */
                   func (stream, "{");
+                              func(info->dottcg_stream, "{");
                   /* Fall through.  */
                 case '0': /* Sm, Dm */
                   regno = given & 0x0000000f;
@@ -1976,6 +2047,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,

                 case '3': /* List */
                   func (stream, "{");
+                              func(info->dottcg_stream, "{");
                   regno = (given >> 12) & 0x0000000f;
                   if (single)
                 {
@@ -1991,6 +2063,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
                 }

               func (stream, "%c%d", single ? 's' : 'd', regno);
+                          func(info->dottcg_stream, "%c%d", single ? 's' :
'd', regno);

               if (*c == '3')
                 {
@@ -2004,23 +2077,42 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
                   func (stream, "-%c%d",
                     single ? 's' : 'd',
                     regno + count);
+                                  func(info->dottcg_stream, "-%c%d",
+                                        single ? 's' : 'd',
+                                        regno + count);
                 }

                   func (stream, "}");
+                              func(info->dottcg_stream, "}");
                 }
-              else if (*c == '4')
+                         else if (*c == '4') {
                 func (stream, ", %c%d}", single ? 's' : 'd',
                   regno + 1);
+                            func(info->dottcg_stream, ", %c%d}", single ?
's' : 'd',
+                                 regno + 1);
+                         }
             }
             break;

               case 'L':
             switch (given & 0x00400100)
               {
-              case 0x00000000: func (stream, "b"); break;
-              case 0x00400000: func (stream, "h"); break;
-              case 0x00000100: func (stream, "w"); break;
-              case 0x00400100: func (stream, "d"); break;
+                          case 0x00000000:
+                            func(stream, "b");
+                            func(info->dottcg_stream, "b");
+                            break;
+                          case 0x00400000:
+                            func(stream, "h");
+                            func(info->dottcg_stream, "h");
+                            break;
+                          case 0x00000100:
+                            func(stream, "w");
+                            func(info->dottcg_stream, "w");
+                            break;
+                          case 0x00400100:
+                            func(stream, "d");
+                            func(info->dottcg_stream, "d");
+                            break;
               default:
                 break;
               }
@@ -2032,6 +2124,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               /* given (20, 23) | given (0, 3) */
               value = ((given >> 16) & 0xf0) | (given & 0xf);
               func (stream, "%d", value);
+                          func(info->dottcg_stream, "%d", value);
             }
             break;

@@ -2044,21 +2137,32 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               int multiplier = (given & 0x00000100) ? 4 : 1;

               func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+                          func(info->dottcg_stream, "[%s",
arm_regnames[(given >> 16) & 0xf]);

               if (offset)
                 {
-                  if ((given & 0x01000000) != 0)
+                             if ((given & 0x01000000) != 0) {
                 func (stream, ", #%s%d]%s",
                       ((given & 0x00800000) == 0 ? "-" : ""),
                       offset * multiplier,
                       ((given & 0x00200000) != 0 ? "!" : ""));
-                  else
+                                func(info->dottcg_stream, ", #%s%d]%s",
+                                      ((given & 0x00800000) == 0 ? "-" :
""),
+                                      offset * multiplier,
+                                      ((given & 0x00200000) != 0 ? "!" :
""));
+                             } else {
                 func (stream, "], #%s%d",
                       ((given & 0x00800000) == 0 ? "-" : ""),
                       offset * multiplier);
+                                func(info->dottcg_stream, "], #%s%d",
+                                      ((given & 0x00800000) == 0 ? "-" :
""),
+                                      offset * multiplier);
+                             }
                 }
-              else
+                         else {
                 func (stream, "]");
+                            func(info->dottcg_stream, "]");
+                         }
             }
             break;

@@ -2076,8 +2180,11 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
                   /* fall through */
                 case 3:
                   func (stream, "[%s], %c%s", rn, ubit ? '+' : '-', rm);
-                  if (imm4)
+                              func(info->dottcg_stream, "[%s], %c%s", rn,
ubit ? '+' : '-', rm);
+                              if (imm4) {
                 func (stream, ", lsl #%d", imm4);
+                                func(info->dottcg_stream, ", lsl #%d",
imm4);
+                              }
                   break;

                 case 4:
@@ -2088,15 +2195,22 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
                   /* fall through */
                 case 7:
                   func (stream, "[%s, %c%s", rn, ubit ? '+' : '-', rm);
-                  if (imm4 > 0)
+                              func(info->dottcg_stream, "[%s, %c%s", rn,
ubit ? '+' : '-', rm);
+                              if (imm4 > 0) {
                 func (stream, ", lsl #%d", imm4);
+                                func(info->dottcg_stream, ", lsl #%d",
imm4);
+                              }
                   func (stream, "]");
-                  if (puw_bits == 5 || puw_bits == 7)
+                              func(info->dottcg_stream, "]");
+                              if (puw_bits == 5 || puw_bits == 7) {
                 func (stream, "!");
+                                func(info->dottcg_stream, "!");
+                              }
                   break;

                 default:
                   func (stream, "INVALID");
+                              func(info->dottcg_stream, "INVALID");
                 }
             }
             break;
@@ -2106,6 +2220,7 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               long imm5;
               imm5 = ((given & 0x100) >> 4) | (given & 0xf);
               func (stream, "%ld", (imm5 == 0) ? 32 : imm5);
+                          func(info->dottcg_stream, "%ld", (imm5 == 0) ?
32 : imm5);
             }
             break;

@@ -2114,8 +2229,10 @@  print_insn_coprocessor (bfd_vma pc, struct
disassemble_info *info, long given,
               }
             }
         }
-          else
+             else {
         func (stream, "%c", *c);
+                func(info->dottcg_stream, "%c", *c);
+             }
         }
       return true;
     }
@@ -2135,6 +2252,7 @@  print_arm_address (bfd_vma pc, struct
disassemble_info *info, long given)
       int offset = given & 0xfff;

       func (stream, "[pc");
+      func(info->dottcg_stream, "[pc");

       if (given & 0x01000000)
     {
@@ -2143,6 +2261,7 @@  print_arm_address (bfd_vma pc, struct
disassemble_info *info, long given)

       /* Pre-indexed.  */
       func (stream, ", #%d]", offset);
+          func(info->dottcg_stream, ", #%d]", offset);

       offset += pc + 8;

@@ -2150,64 +2269,87 @@  print_arm_address (bfd_vma pc, struct
disassemble_info *info, long given)
          being used.  Probably a very dangerous thing
          for the programmer to do, but who are we to
          argue ?  */
-      if (given & 0x00200000)
+          if (given & 0x00200000) {
         func (stream, "!");
+            func(info->dottcg_stream, "!");
+          }
     }
       else
     {
       /* Post indexed.  */
       func (stream, "], #%d", offset);
+          func(info->dottcg_stream, "], #%d", offset);

       /* ie ignore the offset.  */
       offset = pc + 8;
     }

       func (stream, "\t; ");
+      func(info->dottcg_stream, "\t; ");
       info->print_address_func (offset, info);
     }
   else
     {
       func (stream, "[%s",
         arm_regnames[(given >> 16) & 0xf]);
+      func(info->dottcg_stream, "[%s",
+            arm_regnames[(given >> 16) & 0xf]);
       if ((given & 0x01000000) != 0)
     {
       if ((given & 0x02000000) == 0)
         {
           int offset = given & 0xfff;
-          if (offset)
+              if (offset) {
         func (stream, ", #%s%d",
               (((given & 0x00800000) == 0)
                ? "-" : ""), offset);
+                func(info->dottcg_stream, ", #%s%d",
+                      (((given & 0x00800000) == 0)
+                       ? "-" : ""), offset);
+              }
         }
       else
         {
           func (stream, ", %s",
             (((given & 0x00800000) == 0)
              ? "-" : ""));
-          arm_decode_shift (given, func, stream, 1);
+              func(info->dottcg_stream, ", %s",
+                    (((given & 0x00800000) == 0)
+                     ? "-" : ""));
+             arm_decode_shift(given, func, stream, info->dottcg_stream, 1);
         }

       func (stream, "]%s",
         ((given & 0x00200000) != 0) ? "!" : "");
+          func(info->dottcg_stream, "]%s",
+                ((given & 0x00200000) != 0) ? "!" : "");
     }
       else
     {
       if ((given & 0x02000000) == 0)
         {
           int offset = given & 0xfff;
-          if (offset)
+              if (offset) {
         func (stream, "], #%s%d",
               (((given & 0x00800000) == 0)
                ? "-" : ""), offset);
-          else
+                func(info->dottcg_stream, "], #%s%d",
+                      (((given & 0x00800000) == 0)
+                       ? "-" : ""), offset);
+              } else {
         func (stream, "]");
+                func(info->dottcg_stream, "]");
+              }
         }
       else
         {
           func (stream, "], %s",
             (((given & 0x00800000) == 0)
              ? "-" : ""));
-          arm_decode_shift (given, func, stream, 1);
+              func(info->dottcg_stream, "], %s",
+                    (((given & 0x00800000) == 0)
+                     ? "-" : ""));
+             arm_decode_shift(given, func, stream, info->dottcg_stream, 1);
         }
     }
     }
@@ -2257,11 +2399,14 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
             {
             case '%':
               func (stream, "%%");
+                      func(info->dottcg_stream, "%%");
               break;

             case 'c':
-              if (thumb && ifthen_state)
-            func (stream, "%s", arm_conditional[IFTHEN_COND]);
+                      if (thumb && ifthen_state) {
+                        func (stream, "%s", arm_conditional[IFTHEN_COND]);
+                        func(info->dottcg_stream, "%s",
arm_conditional[IFTHEN_COND]);
+                      }
               break;

             case 'A':
@@ -2290,21 +2435,34 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
             int ix;

             func (stream, "{");
-            if (stride > 1)
-              for (ix = 0; ix != n; ix++)
+                        func(info->dottcg_stream, "{");
+                        if (stride > 1) {
+                          for (ix = 0; ix != n; ix++) {
                 func (stream, "%sd%d", ix ? "," : "", rd + ix * stride);
-            else if (n == 1)
+                            func(info->dottcg_stream, "%sd%d", ix ? "," :
"", rd + ix * stride);
+                          }
+                        } else if (n == 1) {
               func (stream, "d%d", rd);
-            else
+                          func(info->dottcg_stream, "d%d", rd);
+                        } else {
               func (stream, "d%d-d%d", rd, rd + n - 1);
+                          func(info->dottcg_stream, "d%d-d%d", rd, rd + n
- 1);
+                        }
             func (stream, "}, [%s", arm_regnames[rn]);
-            if (align)
+                        func(info->dottcg_stream, "}, [%s",
arm_regnames[rn]);
+                        if (align) {
               func (stream, ", :%d", 32 << align);
+                          func(info->dottcg_stream, ", :%d", 32 << align);
+                        }
             func (stream, "]");
-            if (rm == 0xd)
+                        func(info->dottcg_stream, "]");
+                        if (rm == 0xd) {
               func (stream, "!");
-            else if (rm != 0xf)
+                          func(info->dottcg_stream, "!");
+                        } else if (rm != 0xf) {
               func (stream, ", %s", arm_regnames[rm]);
+                          func(info->dottcg_stream, ", %s",
arm_regnames[rm]);
+                        }
               }
               break;

@@ -2369,17 +2527,28 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
                           }

             func (stream, "{");
-                        for (i = 0; i < length; i++)
+                        func(info->dottcg_stream, "{");
+                        for (i = 0; i < length; i++) {
                           func (stream, "%sd%d[%d]", (i == 0) ? "" : ",",
                             rd + i * stride, idx);
+                          func(info->dottcg_stream, "%sd%d[%d]", (i == 0)
? "" : ",",
+                            rd + i * stride, idx);
+                     }
                         func (stream, "}, [%s", arm_regnames[rn]);
-            if (align)
+                        func(info->dottcg_stream, "}, [%s",
arm_regnames[rn]);
+                        if (align) {
               func (stream, ", :%d", align);
+                          func(info->dottcg_stream, ", :%d", align);
+                        }
             func (stream, "]");
-            if (rm == 0xd)
+                        func(info->dottcg_stream, "]");
+                        if (rm == 0xd) {
               func (stream, "!");
-            else if (rm != 0xf)
+                          func(info->dottcg_stream, "]");
+                        } else if (rm != 0xf) {
               func (stream, ", %s", arm_regnames[rm]);
+                          func(info->dottcg_stream, ", %s",
arm_regnames[rm]);
+                        }
               }
               break;

@@ -2401,29 +2570,43 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
               stride++;

             func (stream, "{");
-            if (stride > 1)
-              for (ix = 0; ix != n; ix++)
+                        func(info->dottcg_stream, "{");
+                        if (stride > 1) {
+                          for (ix = 0; ix != n; ix++) {
                 func (stream, "%sd%d[]", ix ? "," : "", rd + ix * stride);
-            else if (n == 1)
+                            func(info->dottcg_stream, "%sd%d[]", ix ? ","
: "", rd + ix * stride);
+                          }
+                        } else if (n == 1) {
               func (stream, "d%d[]", rd);
-            else
+                          func(info->dottcg_stream, "d%d[]", rd);
+                        } else {
               func (stream, "d%d[]-d%d[]", rd, rd + n - 1);
+                          func(info->dottcg_stream, "d%d[]-d%d[]", rd, rd
+ n - 1);
+                        }
             func (stream, "}, [%s", arm_regnames[rn]);
+                        func(info->dottcg_stream, "}, [%s",
arm_regnames[rn]);
             if (align)
               {
                             int align = (8 * (type + 1)) << size;
                             if (type == 3)
                               align = (size > 1) ? align >> 1 : align;
-                if (type == 2 || (type == 0 && !size))
+                            if (type == 2 || (type == 0 && !size)) {
                   func (stream, ", :<bad align %d>", align);
-                else
+                              func(info->dottcg_stream, ", :<bad align
%d>", align);
+                            } else {
                   func (stream, ", :%d", align);
+                              func(info->dottcg_stream, ", :%d", align);
+                            }
               }
             func (stream, "]");
-            if (rm == 0xd)
+                        func(info->dottcg_stream, "]");
+                        if (rm == 0xd) {
               func (stream, "!");
-            else if (rm != 0xf)
+                          func(info->dottcg_stream, "!");
+                        } else if (rm != 0xf) {
               func (stream, ", %s", arm_regnames[rm]);
+                          func(info->dottcg_stream, ", %s",
arm_regnames[rm]);
+                        }
               }
               break;

@@ -2435,6 +2618,7 @@  print_insn_neon (struct disassemble_info *info, long
given, bfd_boolean thumb)
             int ix = raw_reg >> size >> 2;

             func (stream, "d%d[%d]", reg, ix);
+                        func(info->dottcg_stream, "d%d[%d]", reg, ix);
               }
               break;

@@ -2515,16 +2699,20 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
               {
                 func (stream, "<illegal constant %.8x:%x:%x>",
                                   bits, cmode, op);
+                            func(info->dottcg_stream, "<illegal constant
%.8x:%x:%x>",
+                                  bits, cmode, op);
                 break;
               }
                         switch (size)
                           {
                           case 8:
                 func (stream, "#%ld\t; 0x%.2lx", value, value);
+                            func(info->dottcg_stream, "#%ld\t; 0x%.2lx",
value, value);
                             break;

                           case 16:
                             func (stream, "#%ld\t; 0x%.4lx", value, value);
+                            func(info->dottcg_stream, "#%ld\t; 0x%.4lx",
value, value);
                             break;

                           case 32:
@@ -2544,15 +2732,22 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)

                                 func (stream, "#%.7g\t; 0x%.8lx", fvalue,
                                       value);
+                                func(info->dottcg_stream, "#%.7g\t;
0x%.8lx", fvalue,
+                                      value);
                               }
-                            else
+                            else {
                               func (stream, "#%ld\t; 0x%.8lx",
                 (long) ((value & 0x80000000)
                     ? value | ~0xffffffffl : value), value);
+                              func(info->dottcg_stream, "#%ld\t; 0x%.8lx",
+                                (long) ((value & 0x80000000)
+                                        ? value | ~0xffffffffl : value),
value);
+                         }
                             break;

                           case 64:
                             func (stream, "#0x%.8lx%.8lx", hival, value);
+                            func(info->dottcg_stream, "#0x%.8lx%.8lx",
hival, value);
                             break;

                           default:
@@ -2566,12 +2761,16 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
             int regno = ((given >> 16) & 0xf) | ((given >> (7 - 4)) &
0x10);
             int num = (given >> 8) & 0x3;

-            if (!num)
+                        if (!num) {
               func (stream, "{d%d}", regno);
-            else if (num + regno >= 32)
+                          func(info->dottcg_stream, "{d%d}", regno);
+                        } else if (num + regno >= 32) {
               func (stream, "{d%d-<overflow reg d%d}", regno, regno + num);
-            else
+                          func(info->dottcg_stream, "{d%d-<overflow reg
d%d}", regno, regno + num);
+                        } else {
               func (stream, "{d%d-d%d}", regno, regno + num);
+                          func(info->dottcg_stream, "{d%d-d%d}", regno,
regno + num);
+                        }
               }
               break;

@@ -2588,12 +2787,15 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
               {
               case 'r':
                 func (stream, "%s", arm_regnames[value]);
+                            func(info->dottcg_stream, "%s",
arm_regnames[value]);
                 break;
               case 'd':
                 func (stream, "%ld", value);
+                            func(info->dottcg_stream, "%ld", value);
                 break;
               case 'e':
                 func (stream, "%ld", (1ul << width) - value);
+                            func(info->dottcg_stream, "%ld", (1ul <<
width) - value);
                 break;

               case 'S':
@@ -2615,10 +2817,13 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
                   low = limit >> 2;
                   high = limit & 3;

-                  if (value < low || value > high)
+                              if (value < low || value > high) {
                 func (stream, "<illegal width %d>", base << value);
-                  else
+                                func(info->dottcg_stream, "<illegal width
%d>", base << value);
+                              } else {
                 func (stream, "%d", base << value);
+                                func(info->dottcg_stream, "%d", base <<
value);
+                              }
                 }
                 break;
               case 'R':
@@ -2627,27 +2832,36 @@  print_insn_neon (struct disassemble_info *info,
long given, bfd_boolean thumb)
                 /* FALLTHROUGH */
               case 'D':
                 func (stream, "d%ld", value);
+                            func(info->dottcg_stream, "d%ld", value);
                 break;
               case 'Q':
               Q:
-                if (value & 1)
+                            if (value & 1) {
                   func (stream, "<illegal reg q%ld.5>", value >> 1);
-                else
+                              func(info->dottcg_stream, "<illegal reg
q%ld.5>", value >> 1);
+                            } else {
                   func (stream, "q%ld", value >> 1);
+                              func(info->dottcg_stream, "q%ld", value >>
1);
+                            }
                 break;

               case '`':
                 c++;
-                if (value == 0)
+                            if (value == 0) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '\'':
                 c++;
-                if (value == ((1ul << width) - 1))
+                            if (value == ((1ul << width) - 1)) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '?':
                 func (stream, "%c", c[(1 << width) - (int)value]);
+                            func(info->dottcg_stream, "%c", c[(1 << width)
- (int)value]);
                 c += 1 << width;
                 break;
               default:
@@ -2660,8 +2874,10 @@  print_insn_neon (struct disassemble_info *info, long
given, bfd_boolean thumb)
               }
             }
         }
-          else
+             else {
         func (stream, "%c", *c);
+                func(info->dottcg_stream, "%c", *c);
+             }
         }
       return true;
     }
@@ -2709,6 +2925,7 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
             {
             case '%':
               func (stream, "%%");
+                      func(info->dottcg_stream, "%%");
               break;

             case 'a':
@@ -2731,12 +2948,15 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
                 offset = -offset;

               func (stream, "[pc, #%d]\t; ", offset);
+                          func(info->dottcg_stream, "[pc, #%d]\t; ",
offset);
               info->print_address_func (offset + pc + 8, info);
             }
               else
             {
               func (stream, "[%s",
                 arm_regnames[(given >> 16) & 0xf]);
+                          func(info->dottcg_stream, "[%s",
+                                arm_regnames[(given >> 16) & 0xf]);
               if ((given & 0x01000000) != 0)
                 {
                               /* Pre-indexed.  */
@@ -2744,10 +2964,14 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
                 {
                                   /* Immediate.  */
                                   int offset = ((given & 0xf00) >> 4) |
(given & 0xf);
-                  if (offset)
+                                  if (offset) {
                     func (stream, ", #%s%d",
                       (((given & 0x00800000) == 0)
                        ? "-" : ""), offset);
+                                    func(info->dottcg_stream, ", #%s%d",
+                                          (((given & 0x00800000) == 0)
+                                           ? "-" : ""), offset);
+                                  }
                 }
                   else
                 {
@@ -2756,10 +2980,16 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
                     (((given & 0x00800000) == 0)
                      ? "-" : ""),
                                         arm_regnames[given & 0xf]);
+                                  func(info->dottcg_stream, ", %s%s",
+                                        (((given & 0x00800000) == 0)
+                                         ? "-" : ""),
+                                        arm_regnames[given & 0xf]);
                 }

                   func (stream, "]%s",
                     ((given & 0x00200000) != 0) ? "!" : "");
+                              func(info->dottcg_stream, "]%s",
+                                    ((given & 0x00200000) != 0) ? "!" :
"");
                 }
               else
                 {
@@ -2768,12 +2998,17 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
                 {
                                   /* Immediate.  */
                                   int offset = ((given & 0xf00) >> 4) |
(given & 0xf);
-                  if (offset)
+                                  if (offset) {
                     func (stream, "], #%s%d",
                       (((given & 0x00800000) == 0)
                        ? "-" : ""), offset);
-                  else
+                                    func(info->dottcg_stream, "], #%s%d",
+                                          (((given & 0x00800000) == 0)
+                                           ? "-" : ""), offset);
+                                  } else {
                     func (stream, "]");
+                                    func(info->dottcg_stream, "]");
+                                  }
                 }
                   else
                 {
@@ -2782,6 +3017,10 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
                     (((given & 0x00800000) == 0)
                      ? "-" : ""),
                                         arm_regnames[given & 0xf]);
+                                  func(info->dottcg_stream, "], %s%s",
+                                        (((given & 0x00800000) == 0)
+                                         ? "-" : ""),
+                                        arm_regnames[given & 0xf]);
                 }
                 }
             }
@@ -2795,9 +3034,12 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               break;

             case 'c':
-              if (((given >> 28) & 0xf) != 0xe)
+                      if (((given >> 28) & 0xf) != 0xe) {
             func (stream, "%s",
                   arm_conditional [(given >> 28) & 0xf]);
+                        func(info->dottcg_stream, "%s",
+                              arm_conditional[(given >> 28) & 0xf]);
+                      }
               break;

             case 'm':
@@ -2806,20 +3048,25 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
             int reg;

             func (stream, "{");
+                        func(info->dottcg_stream, "{");
             for (reg = 0; reg < 16; reg++)
               if ((given & (1 << reg)) != 0)
                 {
-                  if (started)
+                              if (started) {
                 func (stream, ", ");
+                                func(info->dottcg_stream, ", ");
+                              }
                   started = 1;
                   func (stream, "%s", arm_regnames[reg]);
+                              func(info->dottcg_stream, "%s",
arm_regnames[reg]);
                 }
             func (stream, "}");
+                        func(info->dottcg_stream, "}");
               }
               break;

             case 'q':
-              arm_decode_shift (given, func, stream, 0);
+                    arm_decode_shift (given, func, stream,
info->dottcg_stream, 0);
               break;

             case 'o':
@@ -2830,51 +3077,70 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               immed = (((immed << (32 - rotate))
                     | (immed >> rotate)) & 0xffffffff);
               func (stream, "#%d\t; 0x%x", immed, immed);
+                          func(info->dottcg_stream, "#%d\t; 0x%x", immed,
immed);
             }
               else
-            arm_decode_shift (given, func, stream, 1);
+                     arm_decode_shift (given, func, stream,
info->dottcg_stream, 1);
               break;

             case 'p':
-              if ((given & 0x0000f000) == 0x0000f000)
+                      if ((given & 0x0000f000) == 0x0000f000) {
             func (stream, "p");
+                        func(info->dottcg_stream, "p");
+                      }
               break;

             case 't':
-              if ((given & 0x01200000) == 0x00200000)
+                      if ((given & 0x01200000) == 0x00200000) {
             func (stream, "t");
+                        func(info->dottcg_stream, "t");
+                      }
               break;

             case 'A':
               func (stream, "[%s", arm_regnames [(given >> 16) & 0xf]);
+                      func(info->dottcg_stream, "[%s", arm_regnames[(given
>> 16) & 0xf]);

               if ((given & (1 << 24)) != 0)
             {
               int offset = given & 0xff;

-              if (offset)
+                          if (offset) {
                 func (stream, ", #%s%d]%s",
                   ((given & 0x00800000) == 0 ? "-" : ""),
                   offset * 4,
                   ((given & 0x00200000) != 0 ? "!" : ""));
-              else
+                            func(info->dottcg_stream, ", #%s%d]%s",
+                                  ((given & 0x00800000) == 0 ? "-" : ""),
+                                  offset * 4,
+                                  ((given & 0x00200000) != 0 ? "!" : ""));
+                          } else {
                 func (stream, "]");
+                            func(info->dottcg_stream, "]");
+                          }
             }
               else
             {
               int offset = given & 0xff;

               func (stream, "]");
+                          func(info->dottcg_stream, "]");

               if (given & (1 << 21))
                 {
-                  if (offset)
+                              if (offset) {
                 func (stream, ", #%s%d",
                       ((given & 0x00800000) == 0 ? "-" : ""),
                       offset * 4);
+                                func(info->dottcg_stream, ", #%s%d",
+                                      ((given & 0x00800000) == 0 ? "-" :
""),
+                                      offset * 4);
+                              }
                 }
-              else
+                          else {
                 func (stream, ", {%d}", offset);
+                            func(info->dottcg_stream, ", {%d}", offset);
+                          }
             }
               break;

@@ -2903,27 +3169,66 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)

             case 'C':
               func (stream, "_");
-              if (given & 0x80000)
+                      func(info->dottcg_stream, "_");
+                      if (given & 0x80000) {
             func (stream, "f");
-              if (given & 0x40000)
+                        func(info->dottcg_stream, "f");
+                      }
+                      if (given & 0x40000) {
             func (stream, "s");
-              if (given & 0x20000)
+                        func(info->dottcg_stream, "s");
+                      }
+                      if (given & 0x20000) {
             func (stream, "x");
-              if (given & 0x10000)
+                        func(info->dottcg_stream, "x");
+                      }
+                      if (given & 0x10000) {
             func (stream, "c");
+                        func(info->dottcg_stream, "c");
+                      }
               break;

             case 'U':
               switch (given & 0xf)
             {
-            case 0xf: func(stream, "sy"); break;
-            case 0x7: func(stream, "un"); break;
-            case 0xe: func(stream, "st"); break;
-            case 0x6: func(stream, "unst"); break;
-            default:
-              func(stream, "#%d", (int)given & 0xf);
-              break;
-            }
+                        case 0x2:
+                          func(stream, "oshst");
+                          func(info->dottcg_stream, "oshst");
+                          break;
+                        case 0x3:
+                          func(stream, "osh");
+                          func(info->dottcg_stream, "osh");
+                          break;
+                        case 0xa:
+                          func(stream, "ishst");
+                          func(info->dottcg_stream, "ishst");
+                          break;
+                        case 0xb:
+                          func(stream, "ish");
+                          func(info->dottcg_stream, "ish");
+                          break;
+                        case 0xf: case 0x1: case 0x4: case 0x5:
+                        case 0x8: case 0x9: case 0xc: case 0xd:
+                          func(stream, "sy");
+                          func(info->dottcg_stream, "sy");
+                          break;
+                        case 0x7:
+                          func(stream, "nsh");
+                          func(info->dottcg_stream, "nsh");
+                          break;
+                        case 0xe:
+                          func(stream, "st");
+                          func(info->dottcg_stream, "st");
+                          break;
+                        case 0x6:
+                          func(stream, "nshst");
+                          func(info->dottcg_stream, "nshst");
+                          break;
+                        default:
+                          func(stream, "#%d", (int)given & 0xf);
+                          func(info->dottcg_stream, "#%d", (int)given &
0xf);
+                          break;
+                       }
               break;

             case '0': case '1': case '2': case '3': case '4':
@@ -2938,41 +3243,55 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               {
               case 'r':
                 func (stream, "%s", arm_regnames[value]);
+                            func(info->dottcg_stream, "%s",
arm_regnames[value]);
                 break;
               case 'd':
                 func (stream, "%ld", value);
+                            func(info->dottcg_stream, "%ld", value);
                 break;
               case 'b':
                 func (stream, "%ld", value * 8);
+                            func(info->dottcg_stream, "%ld", value * 8);
                 break;
               case 'W':
                 func (stream, "%ld", value + 1);
+                            func(info->dottcg_stream, "%ld", value + 1);
                 break;
               case 'x':
                 func (stream, "0x%08lx", value);
+                            func(info->dottcg_stream, "0x%08lx", value);

                 /* Some SWI instructions have special
                    meanings.  */
-                if ((given & 0x0fffffff) == 0x0FF00000)
+                            if ((given & 0x0fffffff) == 0x0FF00000) {
                   func (stream, "\t; IMB");
-                else if ((given & 0x0fffffff) == 0x0FF00001)
+                              func(info->dottcg_stream, "\t; IMB");
+                            } else if ((given & 0x0fffffff) == 0x0FF00001)
{
                   func (stream, "\t; IMBRange");
+                              func(info->dottcg_stream, "\t; IMBRange");
+                            }
                 break;
               case 'X':
                 func (stream, "%01lx", value & 0xf);
+                            func(info->dottcg_stream, "%01lx", value &
0xf);
                 break;
               case '`':
                 c++;
-                if (value == 0)
+                            if (value == 0) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '\'':
                 c++;
-                if (value == ((1ul << width) - 1))
+                            if (value == ((1ul << width) - 1)) {
                   func (stream, "%c", *c);
+                              func(info->dottcg_stream, "%c", *c);
+                            }
                 break;
               case '?':
                 func (stream, "%c", c[(1 << width) - (int)value]);
+                            func(info->dottcg_stream, "%c", c[(1 << width)
- (int)value]);
                 c += 1 << width;
                 break;
               default:
@@ -2986,6 +3305,7 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)

               imm = (given & 0xf) | ((given & 0xfff00) >> 4);
               func (stream, "%d", imm);
+                          func(info->dottcg_stream, "%d", imm);
             }
             break;

@@ -2997,10 +3317,13 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               long lsb = (given & 0x00000f80) >> 7;

               long width = msb - lsb + 1;
-              if (width > 0)
+                          if (width > 0) {
                 func (stream, "#%lu, #%lu", lsb, width);
-              else
+                            func(info->dottcg_stream, "#%lu, #%lu", lsb,
width);
+                          } else {
                 func (stream, "(invalid: %lu:%lu)", lsb, msb);
+                            func(info->dottcg_stream, "(invalid:
%lu:%lu)", lsb, msb);
+                          }
             }
             break;

@@ -3012,6 +3335,7 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               long lo = (given & 0x00000fff);
               long imm16 = hi | lo;
               func (stream, "#%lu\t; 0x%lx", imm16, imm16);
+                          func(info->dottcg_stream, "#%lu\t; 0x%lx",
imm16, imm16);
             }
             break;

@@ -3020,8 +3344,10 @@  print_insn_arm_internal (bfd_vma pc, struct
disassemble_info *info, long given)
               }
             }
         }
-          else
+             else {
         func (stream, "%c", *c);
+                func(info->dottcg_stream, "%c", *c);
+             }
         }
       return;
     }
@@ -3050,6 +3376,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
         if (*c != '%')
           {
         func (stream, "%c", *c);
+                func(info->dottcg_stream, "%c", *c);
         continue;
           }

@@ -3057,18 +3384,24 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
           {
           case '%':
         func (stream, "%%");
+                func(info->dottcg_stream, "%%");
         break;

           case 'c':
-        if (ifthen_state)
+                if (ifthen_state) {
           func (stream, "%s", arm_conditional[IFTHEN_COND]);
+                  func(info->dottcg_stream, "%s",
arm_conditional[IFTHEN_COND]);
+                }
         break;

           case 'C':
-        if (ifthen_state)
+                if (ifthen_state) {
           func (stream, "%s", arm_conditional[IFTHEN_COND]);
-        else
+                  func(info->dottcg_stream, "%s",
arm_conditional[IFTHEN_COND]);
+                } else {
           func (stream, "s");
+                  func(info->dottcg_stream, "s");
+                }
         break;

           case 'I':
@@ -3076,21 +3409,29 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
           unsigned int tmp;

           ifthen_next_state = given & 0xff;
-          for (tmp = given << 1; tmp & 0xf; tmp <<= 1)
+                  for (tmp = given << 1; tmp & 0xf; tmp <<= 1) {
             func (stream, ((given ^ tmp) & 0x10) ? "e" : "t");
+                    func(info->dottcg_stream, ((given ^ tmp) & 0x10) ? "e"
: "t");
+                  }
           func (stream, "\t%s", arm_conditional[(given >> 4) & 0xf]);
+                  func(info->dottcg_stream, "\t%s", arm_conditional[(given
>> 4) & 0xf]);
         }
         break;

           case 'x':
-        if (ifthen_next_state)
+                if (ifthen_next_state) {
           func (stream, "\t; unpredictable branch in IT block\n");
+                  func(info->dottcg_stream, "\t; unpredictable branch in
IT block\n");
+                }
         break;

           case 'X':
-        if (ifthen_state)
+                if (ifthen_state) {
           func (stream, "\t; unpredictable <IT:%s>",
             arm_conditional[IFTHEN_COND]);
+                  func(info->dottcg_stream, "\t; unpredictable <IT:%s>",
+                        arm_conditional[IFTHEN_COND]);
+                }
         break;

           case 'S':
@@ -3102,6 +3443,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
             reg += 8;

           func (stream, "%s", arm_regnames[reg]);
+                  func(info->dottcg_stream, "%s", arm_regnames[reg]);
         }
         break;

@@ -3114,6 +3456,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
             reg += 8;

           func (stream, "%s", arm_regnames[reg]);
+                  func(info->dottcg_stream, "%s", arm_regnames[reg]);
         }
         break;

@@ -3131,34 +3474,45 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
           int reg;

           func (stream, "{");
+                  func(info->dottcg_stream, "{");

           /* It would be nice if we could spot
              ranges, and generate the rS-rE format: */
           for (reg = 0; (reg < 8); reg++)
             if ((given & (1 << reg)) != 0)
               {
-            if (started)
+                        if (started) {
               func (stream, ", ");
+                          func(info->dottcg_stream, ", ");
+                        }
             started = 1;
             func (stream, "%s", arm_regnames[reg]);
+                        func(info->dottcg_stream, "%s", arm_regnames[reg]);
               }

           if (domasklr)
             {
-              if (started)
+                      if (started) {
             func (stream, ", ");
+                        func(info->dottcg_stream, ", ");
+                      }
               started = 1;
               func (stream, "%s", arm_regnames[14] /* "lr" */);
+                      func(info->dottcg_stream, "%s", arm_regnames[14] /*
"lr" */);
             }

           if (domaskpc)
             {
-              if (started)
+                      if (started) {
             func (stream, ", ");
+                        func(info->dottcg_stream, ", ");
+                      }
               func (stream, "%s", arm_regnames[15] /* "pc" */);
+                      func(info->dottcg_stream, "%s", arm_regnames[15] /*
"pc" */);
             }

           func (stream, "}");
+                  func(info->dottcg_stream, "}");
         }
         break;

@@ -3180,6 +3534,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
           if (imm == 0)
             imm = 32;
           func (stream, "#%ld", imm);
+                  func(info->dottcg_stream, "#%ld", imm);
         }
         break;

@@ -3209,18 +3564,22 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)
               {
               case 'r':
                 func (stream, "%s", arm_regnames[reg]);
+                            func(info->dottcg_stream, "%s",
arm_regnames[reg]);
                 break;

               case 'd':
                 func (stream, "%ld", reg);
+                            func(info->dottcg_stream, "%ld", reg);
                 break;

               case 'H':
                 func (stream, "%ld", reg << 1);
+                            func(info->dottcg_stream, "%ld", reg << 1);
                 break;

               case 'W':
                 func (stream, "%ld", reg << 2);
+                            func(info->dottcg_stream, "%ld", reg << 2);
                 break;

               case 'a':
@@ -3233,6 +3592,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)

               case 'x':
                 func (stream, "0x%04lx", reg);
+                            func(info->dottcg_stream, "0x%04lx", reg);
                 break;

               case 'B':
@@ -3242,6 +3602,7 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)

               case 'c':
                 func (stream, "%s", arm_conditional [reg]);
+                            func(info->dottcg_stream, "%s",
arm_conditional[reg]);
                 break;

               default:
@@ -3252,16 +3613,21 @@  print_insn_thumb16 (bfd_vma pc, struct
disassemble_info *info, long given)

             case '\'':
               c++;
-              if ((given & (1 << bitstart)) != 0)
+                      if ((given & (1 << bitstart)) != 0) {
             func (stream, "%c", *c);
+                        func(info->dottcg_stream, "%c", *c);
+                      }
               break;

             case '?':
               ++c;
-              if ((given & (1 << bitstart)) != 0)
+                      if ((given & (1 << bitstart)) != 0) {
             func (stream, "%c", *c++);
-              else
+                        func(info->dottcg_stream, "%c", *(c-1));
+                      } else {
             func (stream, "%c", *++c);
+                        func(info->dottcg_stream, "%c", *c);
+                      }
               break;

             default:
@@ -3329,6 +3695,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
         if (*c != '%')
           {
         func (stream, "%c", *c);
+                func(info->dottcg_stream, "%c", *c);
         continue;
           }

@@ -3336,22 +3703,30 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           {
           case '%':
         func (stream, "%%");
+                func(info->dottcg_stream, "%%");
         break;

           case 'c':
-        if (ifthen_state)
+                if (ifthen_state) {
           func (stream, "%s", arm_conditional[IFTHEN_COND]);
+                  func(info->dottcg_stream, "%s",
arm_conditional[IFTHEN_COND]);
+                }
         break;

           case 'x':
-        if (ifthen_next_state)
+                if (ifthen_next_state) {
           func (stream, "\t; unpredictable branch in IT block\n");
+                  func(info->dottcg_stream, "\t; unpredictable branch in
IT block\n");
+                }
         break;

           case 'X':
-        if (ifthen_state)
+                if (ifthen_state) {
           func (stream, "\t; unpredictable <IT:%s>",
             arm_conditional[IFTHEN_COND]);
+                  func(info->dottcg_stream, "\t; unpredictable <IT:%s>",
+                        arm_conditional[IFTHEN_COND]);
+                }
         break;

           case 'I':
@@ -3361,6 +3736,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           imm12 |= (given & 0x00007000u) >> 4;
           imm12 |= (given & 0x04000000u) >> 15;
           func (stream, "#%u\t; 0x%x", imm12, imm12);
+                  func(info->dottcg_stream, "#%u\t; 0x%x", imm12, imm12);
         }
         break;

@@ -3384,6 +3760,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
               imm  = (((imm8 << (32 - mod)) | (imm8 >> mod)) & 0xffffffff);
             }
           func (stream, "#%u\t; 0x%x", imm, imm);
+                  func(info->dottcg_stream, "#%u\t; 0x%x", imm, imm);
         }
         break;

@@ -3395,6 +3772,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           imm |= (given & 0x04000000u) >> 15;
           imm |= (given & 0x000f0000u) >> 4;
           func (stream, "#%u\t; 0x%x", imm, imm);
+                  func(info->dottcg_stream, "#%u\t; 0x%x", imm, imm);
         }
         break;

@@ -3405,6 +3783,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           imm |= (given & 0x00000ff0u) >> 0;
           imm |= (given & 0x0000000fu) << 12;
           func (stream, "#%u\t; 0x%x", imm, imm);
+                  func(info->dottcg_stream, "#%u\t; 0x%x", imm, imm);
         }
         break;

@@ -3417,30 +3796,38 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           imm |= (given & 0x00007000u) >> 10;

           func (stream, "%s", arm_regnames[reg]);
+                  func(info->dottcg_stream, "%s", arm_regnames[reg]);
           switch (stp)
             {
             case 0:
-              if (imm > 0)
+                      if (imm > 0) {
             func (stream, ", lsl #%u", imm);
+                        func(info->dottcg_stream, ", lsl #%u", imm);
+                      }
               break;

             case 1:
               if (imm == 0)
             imm = 32;
               func (stream, ", lsr #%u", imm);
+                      func(info->dottcg_stream, ", lsr #%u", imm);
               break;

             case 2:
               if (imm == 0)
             imm = 32;
               func (stream, ", asr #%u", imm);
+                      func(info->dottcg_stream, ", asr #%u", imm);
               break;

             case 3:
-              if (imm == 0)
+                      if (imm == 0) {
             func (stream, ", rrx");
-              else
+                        func(info->dottcg_stream, ", rrx");
+                      } else {
             func (stream, ", ror #%u", imm);
+                        func(info->dottcg_stream, ", ror #%u", imm);
+                      }
             }
         }
         break;
@@ -3456,6 +3843,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           int offset = 0;

           func (stream, "[%s", arm_regnames[Rn]);
+                  func(info->dottcg_stream, "[%s", arm_regnames[Rn]);
           if (U) /* 12-bit positive immediate offset */
             offset = i12;
           else if (Rn == 15) /* 12-bit negative immediate offset */
@@ -3465,9 +3853,13 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
               unsigned int Rm = (i8 & 0x0f);
               unsigned int sh = (i8 & 0x30) >> 4;
               func (stream, ", %s", arm_regnames[Rm]);
-              if (sh)
+                      func(info->dottcg_stream, ", %s", arm_regnames[Rm]);
+                      if (sh) {
             func (stream, ", lsl #%u", sh);
+                        func(info->dottcg_stream, ", lsl #%u", sh);
+                      }
               func (stream, "]");
+                      func(info->dottcg_stream, "]");
               break;
             }
           else switch (op)
@@ -3502,21 +3894,28 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)

             default:
               func (stream, ", <undefined>]");
+                      func(info->dottcg_stream, ", <undefined>]");
               goto skip;
             }

-          if (postind)
+                  if (postind) {
             func (stream, "], #%d", offset);
+                    func(info->dottcg_stream, "], #%d", offset);
+                  }
           else
             {
-              if (offset)
+                      if (offset) {
             func (stream, ", #%d", offset);
+                        func(info->dottcg_stream, ", #%d", offset);
+                      }
               func (stream, writeback ? "]!" : "]");
+                      func(info->dottcg_stream, writeback ? "]!" : "]");
             }

           if (Rn == 15)
             {
               func (stream, "\t; ");
+                      func(info->dottcg_stream, "\t; ");
               info->print_address_func (((pc + 4) & ~3) + offset, info);
             }
         }
@@ -3532,21 +3931,31 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           unsigned int off = (given & 0x000000ff);

           func (stream, "[%s", arm_regnames[Rn]);
+                  func(info->dottcg_stream, "[%s", arm_regnames[Rn]);
           if (P)
             {
-              if (off || !U)
+                      if (off || !U) {
             func (stream, ", #%c%u", U ? '+' : '-', off * 4);
+                        func(info->dottcg_stream, ", #%c%u", U ? '+' :
'-', off * 4);
+                      }
               func (stream, "]");
-              if (W)
+                      func(info->dottcg_stream, "]");
+                      if (W) {
             func (stream, "!");
+                        func(info->dottcg_stream, "!");
+                      }
             }
           else
             {
               func (stream, "], ");
-              if (W)
+                      func(info->dottcg_stream, "], ");
+                      if (W) {
             func (stream, "#%c%u", U ? '+' : '-', off * 4);
-              else
+                        func(info->dottcg_stream, "#%c%u", U ? '+' : '-',
off * 4);
+                      } else {
             func (stream, "{%u}", off);
+                        func(info->dottcg_stream, "{%u}", off);
+                      }
             }
         }
         break;
@@ -3557,14 +3966,23 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           unsigned int type = (given & 0x00600000) >> 21;
           switch (type)
             {
-            case 0: func (stream, Sbit ? "sb" : "b"); break;
-            case 1: func (stream, Sbit ? "sh" : "h"); break;
+                    case 0:
+                      func (stream, Sbit ? "sb" : "b");
+                      func(info->dottcg_stream, Sbit ? "sb" : "b");
+                      break;
+                    case 1:
+                      func (stream, Sbit ? "sh" : "h");
+                      func(info->dottcg_stream, Sbit ? "sh" : "h");
+                      break;
             case 2:
-              if (Sbit)
+                      if (Sbit) {
             func (stream, "??");
+                        func(info->dottcg_stream, "??");
+                      }
               break;
             case 3:
               func (stream, "??");
+                      func(info->dottcg_stream, "??");
               break;
             }
         }
@@ -3576,15 +3994,20 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           int reg;

           func (stream, "{");
+                  func(info->dottcg_stream, "{");
           for (reg = 0; reg < 16; reg++)
             if ((given & (1 << reg)) != 0)
               {
-            if (started)
+                        if (started) {
               func (stream, ", ");
+                          func(info->dottcg_stream, ", ");
+                        }
             started = 1;
             func (stream, "%s", arm_regnames[reg]);
+                        func(info->dottcg_stream, "%s", arm_regnames[reg]);
               }
           func (stream, "}");
+                  func(info->dottcg_stream, "}");
         }
         break;

@@ -3595,6 +4018,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           lsb |= (given & 0x000000c0u) >> 6;
           lsb |= (given & 0x00007000u) >> 10;
           func (stream, "#%u, #%u", lsb, msb - lsb + 1);
+                  func(info->dottcg_stream, "#%u, #%u", lsb, msb - lsb +
1);
         }
         break;

@@ -3605,6 +4029,7 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           lsb |= (given & 0x000000c0u) >> 6;
           lsb |= (given & 0x00007000u) >> 10;
           func (stream, "#%u, #%u", lsb, width);
+                  func(info->dottcg_stream, "#%u, #%u", lsb, width);
         }
         break;

@@ -3654,10 +4079,13 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           unsigned int shift = 0;
           shift |= (given & 0x000000c0u) >> 6;
           shift |= (given & 0x00007000u) >> 10;
-          if (given & 0x00200000u)
+                  if (given & 0x00200000u) {
             func (stream, ", asr #%u", shift);
-          else if (shift)
+                    func(info->dottcg_stream, ", asr #%u", shift);
+                  } else if (shift) {
             func (stream, ", lsl #%u", shift);
+                    func(info->dottcg_stream, ", lsl #%u", shift);
+                  }
           /* else print nothing - lsl #0 */
         }
         break;
@@ -3665,20 +4093,52 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
           case 'R':
         {
           unsigned int rot = (given & 0x00000030) >> 4;
-          if (rot)
+                  if (rot) {
             func (stream, ", ror #%u", rot * 8);
+                    func(info->dottcg_stream, ", ror #%u", rot * 8);
+                  }
         }
         break;

           case 'U':
         switch (given & 0xf)
           {
-          case 0xf: func(stream, "sy"); break;
-          case 0x7: func(stream, "un"); break;
-          case 0xe: func(stream, "st"); break;
-          case 0x6: func(stream, "unst"); break;
+                  case 0x2:
+                    func (stream, "oshst");
+                    func(info->dottcg_stream, "oshst");
+                    break;
+                  case 0x3:
+                    func (stream, "osh");
+                    func(info->dottcg_stream, "osh");
+                    break;
+                  case 0xa:
+                    func (stream, "ishst");
+                    func(info->dottcg_stream, "ishst");
+                    break;
+                  case 0xb:
+                    func (stream, "ish");
+                    func(info->dottcg_stream, "ish");
+                    break;
+                  case 0xf: case 0x1: case 0x4: case 0x5:
+                  case 0x8: case 0x9: case 0xc: case 0xd:
+                    func (stream, "sy");
+                    func(info->dottcg_stream, "sy");
+                    break;
+                  case 0x7:
+                    func (stream, "nsh");
+                    func(info->dottcg_stream, "nsh");
+                    break;
+                  case 0xe:
+                    func (stream, "st");
+                    func(info->dottcg_stream, "st");
+                    break;
+                  case 0x6:
+                    func (stream, "nshst");
+                    func(info->dottcg_stream, "nshst");
+                    break;
           default:
             func(stream, "#%d", (int)given & 0xf);
+                    func(info->dottcg_stream, "#%d", (int)given & 0xf);
             break;
           }
         break;
@@ -3687,26 +4147,39 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)
         if ((given & 0xff) == 0)
           {
             func (stream, "%cPSR_", (given & 0x100000) ? 'S' : 'C');
-            if (given & 0x800)
+                    func(info->dottcg_stream, "%cPSR_", (given & 0x100000)
? 'S' : 'C');
+                    if (given & 0x800) {
               func (stream, "f");
-            if (given & 0x400)
+                      func(info->dottcg_stream, "f");
+                    }
+                    if (given & 0x400) {
               func (stream, "s");
-            if (given & 0x200)
+                      func(info->dottcg_stream, "s");
+                    }
+                    if (given & 0x200) {
               func (stream, "x");
-            if (given & 0x100)
+                      func(info->dottcg_stream, "x");
+                    }
+                    if (given & 0x100) {
               func (stream, "c");
+                      func(info->dottcg_stream, "c");
+                    }
           }
         else
           {
             func (stream, "%s", psr_name (given & 0xff));
+                    func(info->dottcg_stream, "%s", psr_name (given &
0xff));
           }
         break;

           case 'D':
-        if ((given & 0xff) == 0)
+                if ((given & 0xff) == 0) {
           func (stream, "%cPSR", (given & 0x100000) ? 'S' : 'C');
-        else
+                  func(info->dottcg_stream, "%cPSR", (given & 0x100000) ?
'S' : 'C');
+                } else {
           func (stream, "%s", psr_name (given & 0xff));
+                  func(info->dottcg_stream, "%s", psr_name (given & 0xff));
+                }
         break;

           case '0': case '1': case '2': case '3': case '4':
@@ -3719,28 +4192,43 @@  print_insn_thumb32 (bfd_vma pc, struct
disassemble_info *info, long given)

           switch (*c)
             {
-            case 'd': func (stream, "%lu", val); break;
-            case 'W': func (stream, "%lu", val * 4); break;
-            case 'r': func (stream, "%s", arm_regnames[val]); break;
+                    case 'd':
+                      func (stream, "%lu", val);
+                      func(info->dottcg_stream, "%lu", val);
+                      break;
+                    case 'W':
+                      func (stream, "%lu", val * 4);
+                      func(info->dottcg_stream, "%lu", val * 4);
+                      break;
+                    case 'r':
+                      func (stream, "%s", arm_regnames[val]);
+                      func(info->dottcg_stream, "%s", arm_regnames[val]);
+                      break;

             case 'c':
               func (stream, "%s", arm_conditional[val]);
+                      func(info->dottcg_stream, "%s",
arm_conditional[val]);
               break;

             case '\'':
               c++;
-              if (val == ((1ul << width) - 1))
+                      if (val == ((1ul << width) - 1)) {
             func (stream, "%c", *c);
+                        func(info->dottcg_stream, "%c", *c);
+                      }
               break;

             case '`':
               c++;
-              if (val == 0)
+                      if (val == 0) {
             func (stream, "%c", *c);
+                        func(info->dottcg_stream, "%c", *c);
+                      }
               break;

             case '?':
               func (stream, "%c", c[(1 << width) - (int)val]);
+                      func(info->dottcg_stream, "%c", c[(1 << width) -
(int)val]);
               c += 1 << width;
               break;

@@ -3771,12 +4259,15 @@  print_insn_data (bfd_vma pc ATTRIBUTE_UNUSED,
struct disassemble_info *info,
     {
     case 1:
       info->fprintf_func (info->stream, ".byte\t0x%02lx", given);
+      info->fprintf_func(info->dottcg_stream, ".byte\t0x%02lx", given);
       break;
     case 2:
       info->fprintf_func (info->stream, ".short\t0x%04lx", given);
+      info->fprintf_func(info->dottcg_stream, ".short\t0x%04lx", given);
       break;
     case 4:
       info->fprintf_func (info->stream, ".word\t0x%08lx", given);
+      info->fprintf_func(info->dottcg_stream, ".word\t0x%08lx", given);
       break;
     default:
       abort ();
@@ -4111,18 +4602,25 @@  print_insn_arm (bfd_vma pc, struct disassemble_info
*info)
     {
       info->fprintf_func(info->stream, "%04lx       ",
                  ((unsigned long)given) & 0xffff);
+          info->fprintf_func(info->dottcg_stream, "%04lx       ",
+                            ((unsigned long)given) & 0xffff);
     }
       else
     {
       info->fprintf_func(info->stream, "%04lx %04lx  ",
                  (((unsigned long)given) >> 16) & 0xffff,
                  ((unsigned long)given) & 0xffff);
+          info->fprintf_func(info->dottcg_stream, "%04lx %04lx  ",
+                            (((unsigned long)given) >> 16) & 0xffff,
+                            ((unsigned long)given) & 0xffff);
     }
     }
   else
     {
       info->fprintf_func(info->stream, "%08lx      ",
              ((unsigned long)given) & 0xffffffff);
+      info->fprintf_func(info->dottcg_stream, "%08lx      ",
+                        ((unsigned long)given) & 0xffffffff);
     }

   printer (pc, info, given);
diff --git cpu-all.h cpu-all.h
index e2c3c49..bb3b861 100644
--- cpu-all.h
+++ cpu-all.h
@@ -456,6 +456,8 @@  typedef struct CPULogItem {

 extern const CPULogItem cpu_log_items[];

+void cpu_set_dottcg(void);
+void cpu_set_dottcg_filename(const char *dottcg_filename);
 void cpu_set_log(int log_flags);
 void cpu_set_log_filename(const char *filename);
 int cpu_str_to_log_mask(const char *str);
diff --git cpu-exec.c cpu-exec.c
index 2c2d24e..6a23efb 100644
--- cpu-exec.c
+++ cpu-exec.c
@@ -177,461 +177,53 @@  static void cpu_handle_debug_exception(CPUState *env)
     }
 }

-/* main execution loop */
-
-volatile sig_atomic_t exit_request;
+/* main execution loop: makes QEMU act as TCG compiler */
+target_ulong *start_addrs;
+target_ulong *end_addrs;
+int num_exec_secs;
+unsigned int size_of_code;
+target_ulong load_addr_global;
+#if defined(TARGET_ARM)
+int thumb;
+#endif

 int cpu_exec(CPUState *env)
 {
-    int ret, interrupt_request;
-    TranslationBlock *tb;
-    uint8_t *tc_ptr;
-    unsigned long next_tb;
-
-    if (env->halted) {
-        if (!cpu_has_work(env)) {
-            return EXCP_HALTED;
-        }
-
-        env->halted = 0;
-    }
-
-    cpu_single_env = env;
-
-    if (unlikely(exit_request)) {
-        env->exit_request = 1;
-    }
-
-#if defined(TARGET_I386)
-    /* put eflags in CPU temporary format */
-    CC_SRC = env->eflags & (CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-    DF = 1 - (2 * ((env->eflags >> 10) & 1));
-    CC_OP = CC_OP_EFLAGS;
-    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
-#elif defined(TARGET_SPARC)
-#elif defined(TARGET_M68K)
-    env->cc_op = CC_OP_FLAGS;
-    env->cc_dest = env->sr & 0xf;
-    env->cc_x = (env->sr >> 4) & 1;
-#elif defined(TARGET_ALPHA)
-#elif defined(TARGET_ARM)
-#elif defined(TARGET_UNICORE32)
-#elif defined(TARGET_PPC)
-    env->reserve_addr = -1;
-#elif defined(TARGET_LM32)
-#elif defined(TARGET_MICROBLAZE)
-#elif defined(TARGET_MIPS)
-#elif defined(TARGET_SH4)
-#elif defined(TARGET_CRIS)
-#elif defined(TARGET_S390X)
-#elif defined(TARGET_XTENSA)
-    /* XXXXX */
-#else
-#error unsupported target CPU
-#endif
-    env->exception_index = -1;
-
-    /* prepare setjmp context for exception handling */
-    for(;;) {
-        if (setjmp(env->jmp_env) == 0) {
-            /* if an exception is pending, we execute it here */
-            if (env->exception_index >= 0) {
-                if (env->exception_index >= EXCP_INTERRUPT) {
-                    /* exit request from the cpu execution loop */
-                    ret = env->exception_index;
-                    if (ret == EXCP_DEBUG) {
-                        cpu_handle_debug_exception(env);
-                    }
-                    break;
-                } else {
-#if defined(CONFIG_USER_ONLY)
-                    /* if user mode only, we simulate a fake exception
-                       which will be handled outside the cpu execution
-                       loop */
-#if defined(TARGET_I386)
-                    do_interrupt(env);
-#endif
-                    ret = env->exception_index;
-                    break;
-#else
-                    do_interrupt(env);
-                    env->exception_index = -1;
-#endif
-                }
-            }
-
-            next_tb = 0; /* force lookup of first TB */
-            for(;;) {
-                interrupt_request = env->interrupt_request;
-                if (unlikely(interrupt_request)) {
-                    if (unlikely(env->singlestep_enabled & SSTEP_NOIRQ)) {
-                        /* Mask out external interrupts for this step. */
-                        interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK;
-                    }
-                    if (interrupt_request & CPU_INTERRUPT_DEBUG) {
-                        env->interrupt_request &= ~CPU_INTERRUPT_DEBUG;
-                        env->exception_index = EXCP_DEBUG;
-                        cpu_loop_exit(env);
-                    }
-#if defined(TARGET_ARM) || defined(TARGET_SPARC) || defined(TARGET_MIPS)
|| \
-    defined(TARGET_PPC) || defined(TARGET_ALPHA) || defined(TARGET_CRIS)
|| \
-    defined(TARGET_MICROBLAZE) || defined(TARGET_LM32) ||
defined(TARGET_UNICORE32)
-                    if (interrupt_request & CPU_INTERRUPT_HALT) {
-                        env->interrupt_request &= ~CPU_INTERRUPT_HALT;
-                        env->halted = 1;
-                        env->exception_index = EXCP_HLT;
-                        cpu_loop_exit(env);
-                    }
-#endif
-#if defined(TARGET_I386)
-                    if (interrupt_request & CPU_INTERRUPT_INIT) {
-                            svm_check_intercept(env, SVM_EXIT_INIT);
-                            do_cpu_init(env);
-                            env->exception_index = EXCP_HALTED;
-                            cpu_loop_exit(env);
-                    } else if (interrupt_request & CPU_INTERRUPT_SIPI) {
-                            do_cpu_sipi(env);
-                    } else if (env->hflags2 & HF2_GIF_MASK) {
-                        if ((interrupt_request & CPU_INTERRUPT_SMI) &&
-                            !(env->hflags & HF_SMM_MASK)) {
-                            svm_check_intercept(env, SVM_EXIT_SMI);
-                            env->interrupt_request &= ~CPU_INTERRUPT_SMI;
-                            do_smm_enter(env);
-                            next_tb = 0;
-                        } else if ((interrupt_request & CPU_INTERRUPT_NMI)
&&
-                                   !(env->hflags2 & HF2_NMI_MASK)) {
-                            env->interrupt_request &= ~CPU_INTERRUPT_NMI;
-                            env->hflags2 |= HF2_NMI_MASK;
-                            do_interrupt_x86_hardirq(env, EXCP02_NMI, 1);
-                            next_tb = 0;
-                        } else if (interrupt_request & CPU_INTERRUPT_MCE) {
-                            env->interrupt_request &= ~CPU_INTERRUPT_MCE;
-                            do_interrupt_x86_hardirq(env, EXCP12_MCHK, 0);
-                            next_tb = 0;
-                        } else if ((interrupt_request &
CPU_INTERRUPT_HARD) &&
-                                   (((env->hflags2 & HF2_VINTR_MASK) &&
-                                     (env->hflags2 & HF2_HIF_MASK)) ||
-                                    (!(env->hflags2 & HF2_VINTR_MASK) &&
-                                     (env->eflags & IF_MASK &&
-                                      !(env->hflags &
HF_INHIBIT_IRQ_MASK))))) {
-                            int intno;
-                            svm_check_intercept(env, SVM_EXIT_INTR);
-                            env->interrupt_request &= ~(CPU_INTERRUPT_HARD
| CPU_INTERRUPT_VIRQ);
-                            intno = cpu_get_pic_interrupt(env);
-                            qemu_log_mask(CPU_LOG_TB_IN_ASM, "Servicing
hardware INT=0x%02x\n", intno);
-                            do_interrupt_x86_hardirq(env, intno, 1);
-                            /* ensure that no TB jump will be modified as
-                               the program flow was changed */
-                            next_tb = 0;
-#if !defined(CONFIG_USER_ONLY)
-                        } else if ((interrupt_request &
CPU_INTERRUPT_VIRQ) &&
-                                   (env->eflags & IF_MASK) &&
-                                   !(env->hflags & HF_INHIBIT_IRQ_MASK)) {
-                            int intno;
-                            /* FIXME: this should respect TPR */
-                            svm_check_intercept(env, SVM_EXIT_VINTR);
-                            intno = ldl_phys(env->vm_vmcb +
offsetof(struct vmcb, control.int_vector));
-                            qemu_log_mask(CPU_LOG_TB_IN_ASM, "Servicing
virtual hardware INT=0x%02x\n", intno);
-                            do_interrupt_x86_hardirq(env, intno, 1);
-                            env->interrupt_request &= ~CPU_INTERRUPT_VIRQ;
-                            next_tb = 0;
+       target_ulong pc, pc_last = 0, cs_base;
+       int flags;
+       TranslationBlock *tb;
+       target_ulong start_addr, end_addr;
+#if defined(TARGET_ARM)
+       env->thumb = thumb;
 #endif
-                        }
-                    }
-#elif defined(TARGET_PPC)
-#if 0
-                    if ((interrupt_request & CPU_INTERRUPT_RESET)) {
-                        cpu_reset(env);
-                    }
-#endif
-                    if (interrupt_request & CPU_INTERRUPT_HARD) {
-                        ppc_hw_interrupt(env);
-                        if (env->pending_interrupts == 0)
-                            env->interrupt_request &= ~CPU_INTERRUPT_HARD;
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_LM32)
-                    if ((interrupt_request & CPU_INTERRUPT_HARD)
-                        && (env->ie & IE_IE)) {
-                        env->exception_index = EXCP_IRQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_MICROBLAZE)
-                    if ((interrupt_request & CPU_INTERRUPT_HARD)
-                        && (env->sregs[SR_MSR] & MSR_IE)
-                        && !(env->sregs[SR_MSR] & (MSR_EIP | MSR_BIP))
-                        && !(env->iflags & (D_FLAG | IMM_FLAG))) {
-                        env->exception_index = EXCP_IRQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_MIPS)
-                    if ((interrupt_request & CPU_INTERRUPT_HARD) &&
-                        cpu_mips_hw_interrupts_pending(env)) {
-                        /* Raise it */
-                        env->exception_index = EXCP_EXT_INTERRUPT;
-                        env->error_code = 0;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_SPARC)
-                    if (interrupt_request & CPU_INTERRUPT_HARD) {
-                        if (cpu_interrupts_enabled(env) &&
-                            env->interrupt_index > 0) {
-                            int pil = env->interrupt_index & 0xf;
-                            int type = env->interrupt_index & 0xf0;
-
-                            if (((type == TT_EXTINT) &&
-                                  cpu_pil_allowed(env, pil)) ||
-                                  type != TT_EXTINT) {
-                                env->exception_index =
env->interrupt_index;
-                                do_interrupt(env);
-                                next_tb = 0;
-                            }
-                        }
-                    }
-#elif defined(TARGET_ARM)
-                    if (interrupt_request & CPU_INTERRUPT_FIQ
-                        && !(env->uncached_cpsr & CPSR_F)) {
-                        env->exception_index = EXCP_FIQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-                    /* ARMv7-M interrupt return works by loading a magic
value
-                       into the PC.  On real hardware the load causes the
-                       return to occur.  The qemu implementation performs
the
-                       jump normally, then does the exception return when
the
-                       CPU tries to execute code at the magic address.
-                       This will cause the magic PC value to be pushed to
-                       the stack if an interrupt occurred at the wrong
time.
-                       We avoid this by disabling interrupts when
-                       pc contains a magic address.  */
-                    if (interrupt_request & CPU_INTERRUPT_HARD
-                        && ((IS_M(env) && env->regs[15] < 0xfffffff0)
-                            || !(env->uncached_cpsr & CPSR_I))) {
-                        env->exception_index = EXCP_IRQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_UNICORE32)
-                    if (interrupt_request & CPU_INTERRUPT_HARD
-                        && !(env->uncached_asr & ASR_I)) {
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_SH4)
-                    if (interrupt_request & CPU_INTERRUPT_HARD) {
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_ALPHA)
-                    {
-                        int idx = -1;
-                        /* ??? This hard-codes the OSF/1 interrupt
levels.  */
-                        switch (env->pal_mode ? 7 : env->ps & PS_INT_MASK)
{
-                        case 0 ... 3:
-                            if (interrupt_request & CPU_INTERRUPT_HARD) {
-                                idx = EXCP_DEV_INTERRUPT;
-                            }
-                            /* FALLTHRU */
-                        case 4:
-                            if (interrupt_request & CPU_INTERRUPT_TIMER) {
-                                idx = EXCP_CLK_INTERRUPT;
-                            }
-                            /* FALLTHRU */
-                        case 5:
-                            if (interrupt_request & CPU_INTERRUPT_SMP) {
-                                idx = EXCP_SMP_INTERRUPT;
-                            }
-                            /* FALLTHRU */
-                        case 6:
-                            if (interrupt_request & CPU_INTERRUPT_MCHK) {
-                                idx = EXCP_MCHK;
-                            }
-                        }
-                        if (idx >= 0) {
-                            env->exception_index = idx;
-                            env->error_code = 0;
-                            do_interrupt(env);
-                            next_tb = 0;
-                        }
-                    }
-#elif defined(TARGET_CRIS)
-                    if (interrupt_request & CPU_INTERRUPT_HARD
-                        && (env->pregs[PR_CCS] & I_FLAG)
-                        && !env->locked_irq) {
-                        env->exception_index = EXCP_IRQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-                    if (interrupt_request & CPU_INTERRUPT_NMI
-                        && (env->pregs[PR_CCS] & M_FLAG)) {
-                        env->exception_index = EXCP_NMI;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_M68K)
-                    if (interrupt_request & CPU_INTERRUPT_HARD
-                        && ((env->sr & SR_I) >> SR_I_SHIFT)
-                            < env->pending_level) {
-                        /* Real hardware gets the interrupt vector via an
-                           IACK cycle at this point.  Current emulated
-                           hardware doesn't rely on this, so we
-                           provide/save the vector when the interrupt is
-                           first signalled.  */
-                        env->exception_index = env->pending_vector;
-                        do_interrupt_m68k_hardirq(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_S390X) && !defined(CONFIG_USER_ONLY)
-                    if ((interrupt_request & CPU_INTERRUPT_HARD) &&
-                        (env->psw.mask & PSW_MASK_EXT)) {
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
-#elif defined(TARGET_XTENSA)
-                    if (interrupt_request & CPU_INTERRUPT_HARD) {
-                        env->exception_index = EXC_IRQ;
-                        do_interrupt(env);
-                        next_tb = 0;
-                    }
+       int i;
+       for (i = 0; i < num_exec_secs; i++) {
+              start_addr = start_addrs[i];
+              end_addr = end_addrs[i];
+#if defined(TARGET_ARM)
+              env->regs[15] = load_addr_global + start_addr;
+              if (env->regs[15] < pc_last)
+                     env->regs[15] = pc_last;
+#elif defined(TARGET_I386)
+              env->eip = load_addr_global + start_addr;
+              if (env->eip < pc_last)
+                     env->eip = pc_last;
 #endif
-                   /* Don't use the cached interrupt_request value,
-                      do_interrupt may have updated the EXITTB flag. */
-                    if (env->interrupt_request & CPU_INTERRUPT_EXITTB) {
-                        env->interrupt_request &= ~CPU_INTERRUPT_EXITTB;
-                        /* ensure that no TB jump will be modified as
-                           the program flow was changed */
-                        next_tb = 0;
-                    }
-                }
-                if (unlikely(env->exit_request)) {
-                    env->exit_request = 0;
-                    env->exception_index = EXCP_INTERRUPT;
-                    cpu_loop_exit(env);
-                }
-#if defined(DEBUG_DISAS) || defined(CONFIG_DEBUG_EXEC)
-                if (qemu_loglevel_mask(CPU_LOG_TB_CPU)) {
-                    /* restore flags in standard format */
-#if defined(TARGET_I386)
-                    env->eflags = env->eflags | cpu_cc_compute_all(env,
CC_OP)
-                        | (DF & DF_MASK);
-                    log_cpu_state(env, X86_DUMP_CCOP);
-                    env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A |
CC_P | CC_C);
-#elif defined(TARGET_M68K)
-                    cpu_m68k_flush_flags(env, env->cc_op);
-                    env->cc_op = CC_OP_FLAGS;
-                    env->sr = (env->sr & 0xffe0)
-                              | env->cc_dest | (env->cc_x << 4);
-                    log_cpu_state(env, 0);
-#else
-                    log_cpu_state(env, 0);
+              for (;;) {
+                     cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags);
+                     tb = tb_gen_code(env, pc, cs_base, flags, 0);
+#if defined(TARGET_ARM)
+                     env->regs[15] += size_of_code;
+                     if (env->regs[15] > load_addr_global + end_addr) {
+                            pc_last = env->regs[15];
+#elif defined(TARGET_I386)
+                     env->eip += size_of_code;
+                     if (env->eip > load_addr_global + end_addr) {
+                            pc_last = env->eip;
 #endif
-                }
-#endif /* DEBUG_DISAS || CONFIG_DEBUG_EXEC */
-                spin_lock(&tb_lock);
-                tb = tb_find_fast(env);
-                /* Note: we do it here to avoid a gcc bug on Mac OS X when
-                   doing it in tb_find_slow */
-                if (tb_invalidated_flag) {
-                    /* as some TB could have been invalidated because
-                       of memory exceptions while generating the code, we
-                       must recompute the hash index here */
-                    next_tb = 0;
-                    tb_invalidated_flag = 0;
-                }
-#ifdef CONFIG_DEBUG_EXEC
-                qemu_log_mask(CPU_LOG_EXEC, "Trace 0x%08lx ["
TARGET_FMT_lx "] %s\n",
-                             (long)tb->tc_ptr, tb->pc,
-                             lookup_symbol(tb->pc));
-#endif
-                /* see if we can patch the calling TB. When the TB
-                   spans two pages, we cannot safely do a direct
-                   jump. */
-                if (next_tb != 0 && tb->page_addr[1] == -1) {
-                    tb_add_jump((TranslationBlock *)(next_tb & ~3),
next_tb & 3, tb);
-                }
-                spin_unlock(&tb_lock);
-
-                /* cpu_interrupt might be called while translating the
-                   TB, but before it is linked into a potentially
-                   infinite loop and becomes env->current_tb. Avoid
-                   starting execution if there is a pending interrupt. */
-                env->current_tb = tb;
-                barrier();
-                if (likely(!env->exit_request)) {
-                    tc_ptr = tb->tc_ptr;
-                    /* execute the generated code */
-                    next_tb = tcg_qemu_tb_exec(env, tc_ptr);
-                    if ((next_tb & 3) == 2) {
-                        /* Instruction counter expired.  */
-                        int insns_left;
-                        tb = (TranslationBlock *)(long)(next_tb & ~3);
-                        /* Restore PC.  */
-                        cpu_pc_from_tb(env, tb);
-                        insns_left = env->icount_decr.u32;
-                        if (env->icount_extra && insns_left >= 0) {
-                            /* Refill decrementer and continue execution.
*/
-                            env->icount_extra += insns_left;
-                            if (env->icount_extra > 0xffff) {
-                                insns_left = 0xffff;
-                            } else {
-                                insns_left = env->icount_extra;
-                            }
-                            env->icount_extra -= insns_left;
-                            env->icount_decr.u16.low = insns_left;
-                        } else {
-                            if (insns_left > 0) {
-                                /* Execute remaining instructions.  */
-                                cpu_exec_nocache(env, insns_left, tb);
-                            }
-                            env->exception_index = EXCP_INTERRUPT;
-                            next_tb = 0;
-                            cpu_loop_exit(env);
-                        }
-                    }
-                }
-                env->current_tb = NULL;
-                /* reset soft MMU for next block (it can currently
-                   only be set by a memory fault) */
-            } /* for(;;) */
-        } else {
-            /* Reload env after longjmp - the compiler may have smashed all
-             * local variables as longjmp is marked 'noreturn'. */
-            env = cpu_single_env;
-        }
-    } /* for(;;) */
-
-
-#if defined(TARGET_I386)
-    /* restore flags in standard format */
-    env->eflags = env->eflags | cpu_cc_compute_all(env, CC_OP)
-        | (DF & DF_MASK);
-#elif defined(TARGET_ARM)
-    /* XXX: Save/restore host fpu exception state?.  */
-#elif defined(TARGET_UNICORE32)
-#elif defined(TARGET_SPARC)
-#elif defined(TARGET_PPC)
-#elif defined(TARGET_LM32)
-#elif defined(TARGET_M68K)
-    cpu_m68k_flush_flags(env, env->cc_op);
-    env->cc_op = CC_OP_FLAGS;
-    env->sr = (env->sr & 0xffe0)
-              | env->cc_dest | (env->cc_x << 4);
-#elif defined(TARGET_MICROBLAZE)
-#elif defined(TARGET_MIPS)
-#elif defined(TARGET_SH4)
-#elif defined(TARGET_ALPHA)
-#elif defined(TARGET_CRIS)
-#elif defined(TARGET_S390X)
-#elif defined(TARGET_XTENSA)
-    /* XXXXX */
-#else
-#error unsupported target CPU
-#endif
-
-    /* fail safe : never use cpu_single_env outside cpu_exec() */
-    cpu_single_env = NULL;
-    return ret;
+                            break;
+                     }
+              }
+       }
+       return env->exception_index;
 }
diff --git dis-asm.h dis-asm.h
index 4f15fad..6f92fed 100644
--- dis-asm.h
+++ dis-asm.h
@@ -260,6 +260,7 @@  enum dis_insn_type {
 typedef struct disassemble_info {
   fprintf_function fprintf_func;
   FILE *stream;
+  FILE *dottcg_stream;
   PTR application_data;

   /* Target description.  We could replace this with a pointer to the bfd,
@@ -440,6 +441,13 @@  int generic_symbol_at_address(bfd_vma, struct
disassemble_info *);
   (INFO).endian = BFD_ENDIAN_UNKNOWN, \
   INIT_DISASSEMBLE_INFO_NO_ARCH(INFO, STREAM, FPRINTF_FUNC)

+#define INIT_DISASSEMBLE_INFO_DOTTCG(INFO, STREAM, DOTTCG_STREAM,
FPRINTF_FUNC) \
+  (INFO).flavour = bfd_target_unknown_flavour, \
+  (INFO).arch = bfd_arch_unknown, \
+  (INFO).mach = 0, \
+  (INFO).endian = BFD_ENDIAN_UNKNOWN, \
+  INIT_DISASSEMBLE_INFO_NO_ARCH_DOTTCG(INFO, STREAM, DOTTCG_STREAM,
FPRINTF_FUNC)
+
 /* Call this macro to initialize only the internal variables for the
    disassembler.  Architecture dependent things such as byte order, or
machine
    variant are not touched by this macro.  This makes things much easier
for
@@ -465,6 +473,10 @@  int generic_symbol_at_address(bfd_vma, struct
disassemble_info *);
   (INFO).disassembler_options = NULL, \
   (INFO).insn_info_valid = 0

+#define INIT_DISASSEMBLE_INFO_NO_ARCH_DOTTCG(INFO, STREAM, DOTTCG_STREAM,
FPRINTF_FUNC) \
+  (INFO).dottcg_stream = (DOTTCG_STREAM), \
+  INIT_DISASSEMBLE_INFO_NO_ARCH((INFO), (STREAM), (FPRINTF_FUNC))
+
 #define _(x) x
 #define ATTRIBUTE_UNUSED __attribute__((unused))

diff --git disas.c disas.c
index 3b1fd97..eb3f651 100644
--- disas.c
+++ disas.c
@@ -62,6 +62,7 @@  void
 generic_print_address (bfd_vma addr, struct disassemble_info *info)
 {
     (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr);
+    (*info->fprintf_func) (info->dottcg_stream, "0x%" PRIx64, addr);
 }

 /* Just return the given address.  */
@@ -142,14 +143,14 @@  print_insn_thumb1(bfd_vma pc, disassemble_info *info)
     ppc  - nonzero means little endian
     other targets - unused
  */
-void target_disas(FILE *out, target_ulong code, target_ulong size, int
flags)
+void target_disas(FILE *out, FILE *dottcg_out, target_ulong code,
target_ulong size, int flags)
 {
     target_ulong pc;
     int count;
     struct disassemble_info disasm_info;
     int (*print_insn)(bfd_vma pc, disassemble_info *info);

-    INIT_DISASSEMBLE_INFO(disasm_info, out, fprintf);
+    INIT_DISASSEMBLE_INFO_DOTTCG(disasm_info, out, dottcg_out, fprintf);

     disasm_info.read_memory_func = target_read_memory;
     disasm_info.buffer_vma = code;
@@ -228,6 +229,8 @@  void target_disas(FILE *out, target_ulong code,
target_ulong size, int flags)

     for (pc = code; size > 0; pc += count, size -= count) {
     fprintf(out, "0x" TARGET_FMT_lx ":  ", pc);
+       fprintf(dottcg_out, "// ");
+       fprintf(dottcg_out, "0x" TARGET_FMT_lx ":  ", pc);
     count = print_insn(pc, &disasm_info);
 #if 0
         {
@@ -242,6 +245,7 @@  void target_disas(FILE *out, target_ulong code,
target_ulong size, int flags)
         }
 #endif
     fprintf(out, "\n");
+       fprintf(dottcg_out, "\n");
     if (count < 0)
         break;
         if (size < count) {
diff --git disas.h disas.h
index f9287f7..df7ef0d 100644
--- disas.h
+++ disas.h
@@ -6,7 +6,7 @@ 
 #ifdef NEED_CPU_H
 /* Disassemble this for me please... (debugging). */
 void disas(FILE *out, void *code, unsigned long size);
-void target_disas(FILE *out, target_ulong code, target_ulong size, int
flags);
+void target_disas(FILE *out, FILE *dottcg_out, target_ulong code,
target_ulong size, int flags);

 void monitor_disas(Monitor *mon, CPUState *env,
                    target_ulong pc, int nb_insn, int is_physical, int
flags);
diff --git exec.c exec.c
index b81677a..7257e18 100644
--- exec.c
+++ exec.c
@@ -219,7 +219,9 @@  static const char *logfilename = "qemu.log";
 #else
 static const char *logfilename = "/tmp/qemu.log";
 #endif
+static const char *dottcgfilename;
 FILE *logfile;
+FILE *dottcgfile;
 int loglevel;
 static int log_append = 0;

@@ -999,6 +1001,8 @@  TranslationBlock *tb_gen_code(CPUState *env,
     int code_gen_size;

     phys_pc = get_page_addr_code(env, pc);
+    /* clear the translation code buffer of the TCG code it contains for
the last target instruction */
+    code_gen_ptr = code_gen_buffer;
     tb = tb_alloc(pc);
     if (!tb) {
         /* flush must be done */
@@ -1595,6 +1599,29 @@  void cpu_single_step(CPUState *env, int enabled)
 #endif
 }

+void cpu_set_dottcg_filename(const char *dottcg_filename)
+{
+       dottcgfilename = strdup(dottcg_filename);
+       cpu_set_dottcg();
+}
+
+void cpu_set_dottcg(void)
+{
+       dottcgfile = fopen(dottcgfilename, "w");
+       if (!dottcgfile) {
+              perror(dottcgfilename);
+              _exit(1);
+       }
+#if !defined(CONFIG_SOFTMMU)
+       {
+              static char dottcgfile_buf[4096];
+              setvbuf(dottcgfile, dottcgfile_buf, _IOLBF,
sizeof(dottcgfile_buf));
+       }
+#elif !defined(_WIN32)
+       setvbuf(dottcgfile, NULL, _IOLBF, 0);
+#endif
+}
+
 /* enable or disable low levels log */
 void cpu_set_log(int log_flags)
 {
@@ -1804,6 +1831,8 @@  void cpu_abort(CPUState *env, const char *fmt, ...)
 #endif
         qemu_log_flush();
         qemu_log_close();
+       qemu_dottcg_flush();
+       qemu_dottcg_close();
     }
     va_end(ap2);
     va_end(ap);
diff --git i386-dis.c i386-dis.c
index c4a81c9..a2c8586 100644
--- i386-dis.c
+++ i386-dis.c
@@ -3671,13 +3671,16 @@  print_insn (bfd_vma pc, disassemble_info *info)
       if (codep > priv.the_buffer)
     {
       name = prefix_name (priv.the_buffer[0], priv.orig_sizeflag);
-      if (name != NULL)
+         if (name != NULL) {
         (*info->fprintf_func) (info->stream, "%s", name);
-      else
+           (*info->fprintf_func) (info->dottcg_stream, "%s", name);
+         } else
         {
           /* Just print the first byte as a .byte instruction.  */
           (*info->fprintf_func) (info->stream, ".byte 0x%x",
                      (unsigned int) priv.the_buffer[0]);
+             (*info->fprintf_func) (info->dottcg_stream, ".byte 0x%x",
+                                     (unsigned int) priv.the_buffer[0]);
         }

       return 1;
@@ -3707,6 +3710,7 @@  print_insn (bfd_vma pc, disassemble_info *info)
       if (name == NULL)
     name = INTERNAL_DISASSEMBLER_ERROR;
       (*info->fprintf_func) (info->stream, "%s", name);
+      (*info->fprintf_func) (info->dottcg_stream, "%s", name);
       return 1;
     }

@@ -3888,6 +3892,7 @@  print_insn (bfd_vma pc, disassemble_info *info)
       if (name == NULL)
     name = INTERNAL_DISASSEMBLER_ERROR;
       (*info->fprintf_func) (info->stream, "%s", name);
+      (*info->fprintf_func) (info->dottcg_stream, "%s", name);
       return 1;
     }
   if (rex & ~rex_used)
@@ -3897,6 +3902,7 @@  print_insn (bfd_vma pc, disassemble_info *info)
       if (name == NULL)
     name = INTERNAL_DISASSEMBLER_ERROR;
       (*info->fprintf_func) (info->stream, "%s ", name);
+      (*info->fprintf_func) (info->dottcg_stream, "%s", name);
     }

   obufp = obuf + strlen (obuf);
@@ -3904,6 +3910,7 @@  print_insn (bfd_vma pc, disassemble_info *info)
     oappend (" ");
   oappend (" ");
   (*info->fprintf_func) (info->stream, "%s", obuf);
+  (*info->fprintf_func) (info->dottcg_stream, "%s", obuf);

   /* The enter and bound instructions are printed with operands in the same
      order as the intel book; everything else is printed in reverse
order.  */
@@ -3934,12 +3941,16 @@  print_insn (bfd_vma pc, disassemble_info *info)
   for (i = 0; i < MAX_OPERANDS; ++i)
     if (*op_txt[i])
       {
-    if (needcomma)
+       if (needcomma) {
       (*info->fprintf_func) (info->stream, ",");
+         (*info->fprintf_func) (info->dottcg_stream, ",");
+       }
     if (op_index[i] != -1 && !op_riprel[i])
       (*info->print_address_func) ((bfd_vma) op_address[op_index[i]],
info);
-    else
+       else {
       (*info->fprintf_func) (info->stream, "%s", op_txt[i]);
+         (*info->fprintf_func) (info->dottcg_stream, "%s", op_txt[i]);
+       }
     needcomma = 1;
       }

@@ -3947,6 +3958,7 @@  print_insn (bfd_vma pc, disassemble_info *info)
     if (op_index[i] != -1 && op_riprel[i])
       {
     (*info->fprintf_func) (info->stream, "        # ");
+       (*info->fprintf_func) (info->dottcg_stream, "        # ");
     (*info->print_address_func) ((bfd_vma) (start_pc + codep - start_codep
                         + op_address[op_index[i]]), info);
     break;
diff --git linux-user/elfload.c linux-user/elfload.c
index 2fd4a93..d66fce4 100644
--- linux-user/elfload.c
+++ linux-user/elfload.c
@@ -1434,6 +1434,8 @@  exit_errmsg:
 #endif
 }

+extern target_ulong load_addr_global;
+int is_target_binary;

 /* Load an ELF image into the address space.

@@ -1513,6 +1515,8 @@  static void load_elf_image(const char *image_name,
int image_fd,
         load_addr = target_mmap(loaddr, hiaddr - loaddr, PROT_NONE,
                                 MAP_PRIVATE | MAP_ANON | MAP_NORESERVE,
                                 -1, 0);
+        if (is_target_binary)
+            load_addr_global = load_addr;
         if (load_addr == -1) {
             goto exit_perror;
         }
@@ -1520,6 +1524,7 @@  static void load_elf_image(const char *image_name,
int image_fd,
         /* This is the main executable.  Make sure that the low
            address does not conflict with MMAP_MIN_ADDR or the
            QEMU application itself.  */
+        load_addr_global = 0;
         probe_guest_base(image_name, loaddr, hiaddr);
     }
     load_bias = load_addr - loaddr;
@@ -1726,6 +1731,37 @@  static int symcmp(const void *s0, const void *s1)
         : ((sym0->st_value > sym1->st_value) ? 1 : 0);
 }

+extern target_ulong *start_addrs;
+extern target_ulong *end_addrs;
+extern int num_exec_secs;
+
+static void dottcg_print_shdr(struct elf_shdr *shdr)
+{
+#if ELF_CLASS == ELFCLASS32
+       fprintf(dottcgfile, "name: 0x%x; ", shdr->sh_name);
+       fprintf(dottcgfile, "type: 0x%x; ", shdr->sh_type);
+       fprintf(dottcgfile, "flags: 0x%x; ", shdr->sh_flags);
+       fprintf(dottcgfile, "addr: 0x%x; ", shdr->sh_addr);
+       fprintf(dottcgfile, "offset: 0x%x; ", shdr->sh_offset);
+       fprintf(dottcgfile, "size: 0x%x; ", shdr->sh_size);
+       fprintf(dottcgfile, "link: 0x%x; ", shdr->sh_link);
+       fprintf(dottcgfile, "info: 0x%x; ", shdr->sh_info);
+       fprintf(dottcgfile, "addralign: 0x%x; ", shdr->sh_addralign);
+       fprintf(dottcgfile, "entsize: 0x%x\n", shdr->sh_entsize);
+#else
+       fprintf(dottcgfile, "name: 0x%lx; ", shdr->sh_name);
+       fprintf(dottcgfile, "type: 0x%lx; ", shdr->sh_type);
+       fprintf(dottcgfile, "flags: 0x%x; ", shdr->sh_flags);
+       fprintf(dottcgfile, "addr: 0x%lx; ", shdr->sh_addr);
+       fprintf(dottcgfile, "offset: 0x%lx; ", shdr->sh_offset);
+       fprintf(dottcgfile, "size: 0x%lx; ", shdr->sh_size);
+       fprintf(dottcgfile, "link: 0x%x; ", shdr->sh_link);
+       fprintf(dottcgfile, "info: 0x%x; ", shdr->sh_info);
+       fprintf(dottcgfile, "addralign: 0x%lx; ", shdr->sh_addralign);
+       fprintf(dottcgfile, "entsize: 0x%lx\n", shdr->sh_entsize);
+#endif
+}
+
 /* Best attempt to load symbols from this ELF object. */
 static void load_symbols(struct elfhdr *hdr, int fd, abi_ulong load_bias)
 {
@@ -1743,6 +1779,25 @@  static void load_symbols(struct elfhdr *hdr, int fd,
abi_ulong load_bias)
     }

     bswap_shdr(shdr, shnum);
+
+    /* code to fill start_addrs, end_addrs and num_exec_secs */
+    if (is_target_binary) {
+       is_target_binary = false;
+       start_addrs = malloc(shnum * sizeof(target_ulong));
+       end_addrs = malloc(shnum * sizeof(target_ulong));
+       int count = 0;
+       for (i = 0; i < shnum; i++) {
+          if (shdr[i].sh_flags & SHF_EXECINSTR) {
+            start_addrs[count] = shdr[i].sh_addr;
+            end_addrs[count] = start_addrs[count] + shdr[i].sh_size;
+            count++;
+          }
+          dottcg_print_shdr(&shdr[i]);
+       }
+       fprintf(dottcgfile, "\n");
+       num_exec_secs = count;
+    }
+
     for (i = 0; i < shnum; ++i) {
         if (shdr[i].sh_type == SHT_SYMTAB) {
             sym_idx = i;
@@ -1839,6 +1894,7 @@  int load_elf_binary(struct linux_binprm * bprm,
struct target_pt_regs * regs,
     info->mmap = 0;
     info->rss = 0;

+    is_target_binary = true;
     load_elf_image(bprm->filename, bprm->fd, info,
                    &elf_interpreter, bprm->buf);

diff --git linux-user/main.c linux-user/main.c
index 14bf5f0..974e15c 100644
--- linux-user/main.c
+++ linux-user/main.c
@@ -2950,6 +2950,11 @@  static void handle_arg_log_filename(const char *arg)
     cpu_set_log_filename(arg);
 }

+static void handle_arg_dottcg_filename(const char *arg)
+{
+    cpu_set_dottcg_filename(arg);
+}
+
 static void handle_arg_set_env(const char *arg)
 {
     char *r, *p, *token;
@@ -3077,6 +3082,17 @@  static void handle_arg_reserved_va(const char *arg)
 }
 #endif

+#if defined(TARGET_ARM)
+extern int thumb;
+static void handle_arg_setthumb(const char *arg)
+{
+       thumb = 1;
+}
+static void handle_arg_setarm(const char *arg)
+{
+       thumb = 0;
+}
+#endif
 static void handle_arg_singlestep(const char *arg)
 {
     singlestep = 1;
@@ -3132,6 +3148,14 @@  struct qemu_argument arg_table[] = {
      "options",    "activate log"},
     {"D",          "QEMU_LOG_FILENAME", true, handle_arg_log_filename,
      "logfile",     "override default logfile location"},
+    {"tcg",        "",             true,  handle_arg_dottcg_filename,
+     "file",       "specify file name where .tcg output will be
generated"},
+#if defined(TARGET_ARM)
+    {"thumb",      "",             false, handle_arg_setthumb,
+     "",           "TCG compile assuming thumb mode"},
+    {"arm",        "",             false, handle_arg_setarm,
+     "",           "TCG compile assuming arm mode"},
+#endif
     {"p",          "QEMU_PAGESIZE",    true,  handle_arg_pagesize,
      "pagesize",   "set the host page size to 'pagesize'"},
     {"singlestep", "QEMU_SINGLESTEP",  false, handle_arg_singlestep,
@@ -3149,6 +3173,12 @@  static void usage(void)
     int maxarglen;
     int maxenvlen;

+    printf("\nThe command of our interest should look exactly like the
following:\n"
+          "$(path_to_QEMU_installation)/bin/qemu-" TARGET_ARCH " -D
qemu.log -tcg $(test_binary).tcg"
+          " -d in_asm,op $(test_binary)\n"
+          "Trying any other monkey tricks would most likely result in
something breaking. Thanks!\n"
+          "\n");
+
     printf("usage: qemu-" TARGET_ARCH " [options] program [arguments...]\n"
            "Linux CPU emulator (compiled for " TARGET_ARCH " emulation)\n"
            "\n"
diff --git qemu-log.h qemu-log.h
index fccfb110..f8d93ca 100644
--- qemu-log.h
+++ qemu-log.h
@@ -3,6 +3,7 @@ 

 /* The deprecated global variables: */
 extern FILE *logfile;
+extern FILE *dottcgfile;
 extern int loglevel;


@@ -31,6 +32,11 @@  extern int loglevel;
             fprintf(logfile, ## __VA_ARGS__); \
     } while (0)

+#define qemu_dottcg(...) do {                 \
+        if (dottcgfile)                       \
+            fprintf(dottcgfile, ## __VA_ARGS__); \
+    } while (0)
+
 /* vfprintf-like logging function
  */
 #define qemu_log_vprintf(fmt, va) do {     \
@@ -58,7 +64,7 @@  extern int loglevel;

 /* disas() and target_disas() to logfile: */
 #define log_target_disas(start, len, flags) \
-        target_disas(logfile, (start), (len), (flags))
+        target_disas(logfile, dottcgfile, (start), (len), (flags))
 #define log_disas(start, len) \
         disas(logfile, (start), (len))

@@ -71,6 +77,7 @@  extern int loglevel;

 /* fflush() the log file */
 #define qemu_log_flush() fflush(logfile)
+#define qemu_dottcg_flush() fflush(dottcgfile)

 /* Close the log file */
 #define qemu_log_close() do { \
@@ -78,6 +85,11 @@  extern int loglevel;
         logfile = NULL;       \
     } while (0)

+#define qemu_dottcg_close() do { \
+        fclose(dottcgfile);     \
+        dottcgfile = NULL;      \
+    } while (0)
+
 /* Set up a new log file */
 #define qemu_log_set_file(f) do { \
         logfile = (f);            \
diff --git target-arm/translate.c target-arm/translate.c
index 280bfca..e0a40d4 100644
--- target-arm/translate.c
+++ target-arm/translate.c
@@ -6698,7 +6698,7 @@  static void gen_store_exclusive(DisasContext *s, int
rd, int rt, int rt2,

 static void disas_arm_insn(CPUState * env, DisasContext *s)
 {
-    unsigned int cond, insn, val, op1, i, shift, rm, rs, rn, rd, sh;
+    unsigned int cond, insn, val, op1, i, shift, rm, rs, rn, rd, sh,
barrier_type;
     TCGv tmp;
     TCGv tmp2;
     TCGv tmp3;
@@ -6778,13 +6778,35 @@  static void disas_arm_insn(CPUState * env,
DisasContext *s)
                 gen_clrex(s);
                 return;
             case 4: /* dsb */
+              ARCH(7);
+              barrier_type = insn & 0xf;
+              if (barrier_type == 0xc || barrier_type == 0xd ||
barrier_type == 0x9 ||
+                  barrier_type == 0x8 || barrier_type == 0x5 ||
barrier_type == 0x4 ||
+                  barrier_type == 0x1 || barrier_type == 0x0) {
+                     goto illegal_op;
+              }
+              tcg_gen_barrier(1, barrier_type);
+              break;
             case 5: /* dmb */
+              ARCH(7);
+              barrier_type = insn & 0xf;
+              if (barrier_type == 0xc || barrier_type == 0xd ||
barrier_type == 0x9 ||
+                    barrier_type == 0x8 || barrier_type == 0x5 ||
barrier_type == 0x4 ||
+                    barrier_type == 0x1 || barrier_type == 0x0) {
+                        goto illegal_op;
+              }
+              tcg_gen_barrier(0, barrier_type);
+              break;
             case 6: /* isb */
-                ARCH(7);
-                /* We don't emulate caches so these are a no-op.  */
-                return;
+              ARCH(7);
+              barrier_type = insn & 0xf;
+              if (barrier_type != 0xf) {
+                       goto illegal_op;
+              }
+              tcg_gen_barrier(2, barrier_type);
+              break;
             default:
-                goto illegal_op;
+              goto illegal_op;
             }
         } else if ((insn & 0x0e5fffe0) == 0x084d0500) {
             /* srs */
@@ -8090,6 +8112,7 @@  static int disas_thumb2_insn(CPUState *env,
DisasContext *s, uint16_t insn_hw1)
     int shiftop;
     int conds;
     int logic_cc;
+    int barrier_type;

     if (!(arm_feature(env, ARM_FEATURE_THUMB2)
           || arm_feature (env, ARM_FEATURE_M))) {
@@ -8772,9 +8795,29 @@  static int disas_thumb2_insn(CPUState *env,
DisasContext *s, uint16_t insn_hw1)
                             gen_clrex(s);
                             break;
                         case 4: /* dsb */
+                            barrier_type = insn & 0xf;
+                            if (barrier_type == 0xc || barrier_type == 0xd
|| barrier_type == 0x9 ||
+                                barrier_type == 0x8 || barrier_type == 0x5
|| barrier_type == 0x4 ||
+                                barrier_type == 0x1 || barrier_type ==
0x0) {
+                                    goto illegal_op;
+                            }
+                            tcg_gen_barrier(1, barrier_type);
+                            break;
                         case 5: /* dmb */
+                            barrier_type = insn & 0xf;
+                            if (barrier_type == 0xc || barrier_type == 0xd
|| barrier_type == 0x9 ||
+                                barrier_type == 0x8 || barrier_type == 0x5
|| barrier_type == 0x4 ||
+                                barrier_type == 0x1 || barrier_type ==
0x0) {
+                                    goto illegal_op;
+                            }
+                            tcg_gen_barrier(0, barrier_type);
+                            break;
                         case 6: /* isb */
-                            /* These execute as NOPs.  */
+                            barrier_type = insn & 0xf;
+                            if (barrier_type != 0xf) {
+                                    goto illegal_op;
+                            }
+                            tcg_gen_barrier(2, barrier_type);
                             break;
                         default:
                             goto illegal_op;
@@ -9827,6 +9870,8 @@  undef:
     gen_exception_insn(s, 2, EXCP_UDEF);
 }

+extern unsigned int size_of_code;
+
 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
    basic block 'tb'. If search_pc is TRUE, also generate PC
    information for each intermediate instruction. */
@@ -10088,7 +10133,10 @@  done_generating:
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         qemu_log("----------------\n");
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
+       qemu_dottcg("\n");
+       size_of_code = dc->pc - pc_start;
         log_target_disas(pc_start, dc->pc - pc_start, dc->thumb);
+       qemu_dottcg("\n");
         qemu_log("\n");
     }
 #endif
diff --git target-i386/translate.c target-i386/translate.c
index 860b4a3..8b1752f 100644
--- target-i386/translate.c
+++ target-i386/translate.c
@@ -7710,6 +7710,8 @@  void optimize_flags_init(void)
 #include "helper.h"
 }

+extern unsigned int size_of_code;
+
 /* generate intermediate code in gen_opc_buf and gen_opparam_buf for
    basic block 'tb'. If search_pc is TRUE, also generate PC
    information for each intermediate instruction. */
@@ -7872,6 +7874,7 @@  static inline void
gen_intermediate_code_internal(CPUState *env,
     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
         int disas_flags;
         qemu_log("----------------\n");
+        qemu_dottcg("\n");
         qemu_log("IN: %s\n", lookup_symbol(pc_start));
 #ifdef TARGET_X86_64
         if (dc->code64)
@@ -7879,7 +7882,9 @@  static inline void
gen_intermediate_code_internal(CPUState *env,
         else
 #endif
             disas_flags = !dc->code32;
+        size_of_code = pc_ptr - pc_start;
         log_target_disas(pc_start, pc_ptr - pc_start, disas_flags);
+        qemu_dottcg("\n");
         qemu_log("\n");
     }
 #endif
diff --git tcg/tcg-op.h tcg/tcg-op.h
index 169d3b2..1496cc0 100644
--- tcg/tcg-op.h
+++ tcg/tcg-op.h
@@ -356,6 +356,11 @@  static inline void tcg_gen_op6ii_i64(TCGOpcode opc,
TCGv_i64 arg1,
     *gen_opparam_ptr++ = arg6;
 }

+static inline void tcg_gen_barrier(int bartype, int type)
+{
+   tcg_gen_op2ii(INDEX_op_barrier, bartype, type);
+}
+
 static inline void gen_set_label(int n)
 {
     tcg_gen_op1i(INDEX_op_set_label, n);
diff --git tcg/tcg-opc.h tcg/tcg-opc.h
index 8e06d03..5a09d02 100644
--- tcg/tcg-opc.h
+++ tcg/tcg-opc.h
@@ -239,6 +239,9 @@  DEF(qemu_st64, 0, 2, 1, TCG_OPF_CALL_CLOBBER |
TCG_OPF_SIDE_EFFECTS)

 #endif /* TCG_TARGET_REG_BITS != 32 */

+/* 0 = dmb, 1 = dsb, 2 = isb */
+DEF(barrier, 0, 0, 2, 0)
+
 #undef IMPL
 #undef IMPL64
 #undef DEF
diff --git tcg/tcg.c tcg/tcg.c
index d43fa4a..470ce18 100644
--- tcg/tcg.c
+++ tcg/tcg.c
@@ -809,6 +809,19 @@  static char *tcg_get_arg_str_idx(TCGContext *s, char
*buf, int buf_size,
     return buf;
 }

+static int tcg_get_arg_type_idx(TCGContext *s, int idx)
+{
+       TCGTemp *ts;
+       assert(idx >= 0 && idx < s->nb_temps);
+       ts = &s->temps[idx];
+       assert(ts);
+       if (ts->base_type == TCG_TYPE_I32) {
+         return 32;
+       } else { /* ts->base_type == TCG_TYPE_I64 */
+         return 64;
+       }
+}
+
 char *tcg_get_arg_str_i32(TCGContext *s, char *buf, int buf_size, TCGv_i32
arg)
 {
     return tcg_get_arg_str_idx(s, buf, buf_size, GET_TCGV_I32(arg));
@@ -876,7 +889,7 @@  static const char * const cond_name[] =
     [TCG_COND_GTU] = "gtu"
 };

-void tcg_dump_ops(TCGContext *s, FILE *outfile)
+void tcg_dump_ops(TCGContext *s, FILE *outfile, FILE *dottcgoutfile)
 {
     const uint16_t *opc_ptr;
     const TCGArg *args;
@@ -899,9 +912,12 @@  void tcg_dump_ops(TCGContext *s, FILE *outfile)
 #else
             pc = args[0];
 #endif
-            if (!first_insn)
+            if (!first_insn) {
                 fprintf(outfile, "\n");
+                fprintf(dottcgoutfile, "\n");
+            }
             fprintf(outfile, " ---- 0x%" PRIx64, pc);
+            fprintf(dottcgoutfile, "0x%" PRIx64 ":", pc);
             first_insn = 0;
             nb_oargs = def->nb_oargs;
             nb_iargs = def->nb_iargs;
@@ -916,27 +932,46 @@  void tcg_dump_ops(TCGContext *s, FILE *outfile)
             nb_cargs = def->nb_cargs;

             fprintf(outfile, " %s ", def->name);
+            fprintf(dottcgoutfile, " %s ", def->name);

             /* function name */
             fprintf(outfile, "%s",
                     tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs
+ nb_iargs - 1]));
+            fprintf(dottcgoutfile, "%s_%d(%d)",
+                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[nb_oargs
+ nb_iargs - 1]),
+                    args[nb_oargs + nb_iargs - 1],
+                    tcg_get_arg_type_idx(s, args[nb_oargs + nb_iargs -
1]));
+
             /* flags */
             fprintf(outfile, ",$0x%" TCG_PRIlx,
                     args[nb_oargs + nb_iargs]);
+            fprintf(dottcgoutfile, ",$0x%" TCG_PRIlx,
+                    args[nb_oargs + nb_iargs]);
             /* nb out args */
             fprintf(outfile, ",$%d", nb_oargs);
+            fprintf(dottcgoutfile, ",$%d", nb_oargs);
             for(i = 0; i < nb_oargs; i++) {
                 fprintf(outfile, ",");
+               fprintf(dottcgoutfile, ",");
                 fprintf(outfile, "%s",
                         tcg_get_arg_str_idx(s, buf, sizeof(buf), args[i]));
+                fprintf(dottcgoutfile, "%s_%d(%d)",
+                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[i]),
args[i],
+                        tcg_get_arg_type_idx(s, args[i]));
             }
             for(i = 0; i < (nb_iargs - 1); i++) {
                 fprintf(outfile, ",");
+                fprintf(dottcgoutfile, ",");
                 if (args[nb_oargs + i] == TCG_CALL_DUMMY_ARG) {
                     fprintf(outfile, "<dummy>");
+                    fprintf(dottcgoutfile, "<dummy>");
                 } else {
                     fprintf(outfile, "%s",
                             tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[nb_oargs + i]));
+                    fprintf(dottcgoutfile, "%s_%d(%d)",
+                            tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[nb_oargs + i]),
+                            args[nb_oargs + i],
+                            tcg_get_arg_type_idx(s, args[nb_oargs + i]));
                 }
             }
         } else if (c == INDEX_op_movi_i32
@@ -952,18 +987,26 @@  void tcg_dump_ops(TCGContext *s, FILE *outfile)
             nb_cargs = def->nb_cargs;
             fprintf(outfile, " %s %s,$", def->name,
                     tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]));
+            fprintf(dottcgoutfile, " %s %s_%d(%d),$", def->name,
+                    tcg_get_arg_str_idx(s, buf, sizeof(buf), args[0]),
+                    args[0], tcg_get_arg_type_idx(s, args[0]));
             val = args[1];
             th = tcg_find_helper(s, val);
             if (th) {
                 fprintf(outfile, "%s", th->name);
+                fprintf(dottcgoutfile, "%s", th->name);
             } else {
-                if (c == INDEX_op_movi_i32)
+                if (c == INDEX_op_movi_i32) {
                     fprintf(outfile, "0x%x", (uint32_t)val);
-                else
+                    fprintf(dottcgoutfile, "0x%x", (uint32_t)val);
+                } else {
                     fprintf(outfile, "0x%" PRIx64 , (uint64_t)val);
+                    fprintf(dottcgoutfile, "0x%" PRIx64 , (uint64_t)val);
+                }
             }
         } else {
             fprintf(outfile, " %s ", def->name);
+            fprintf(dottcgoutfile, " %s ", def->name);
             if (c == INDEX_op_nopn) {
                 /* variable number of arguments */
                 nb_cargs = *args;
@@ -977,16 +1020,28 @@  void tcg_dump_ops(TCGContext *s, FILE *outfile)

             k = 0;
             for(i = 0; i < nb_oargs; i++) {
-                if (k != 0)
+                if (k != 0) {
                     fprintf(outfile, ",");
+                    fprintf(dottcgoutfile, ",");
+                }
                 fprintf(outfile, "%s",
-                        tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[k++]));
+                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k]));
+                fprintf(dottcgoutfile, "%s_%d(%d)",
+                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k]),
+                        args[k], tcg_get_arg_type_idx(s, args[k]));
+                k++;
             }
             for(i = 0; i < nb_iargs; i++) {
-                if (k != 0)
+                if (k != 0) {
                     fprintf(outfile, ",");
+                    fprintf(dottcgoutfile, ",");
+                }
                 fprintf(outfile, "%s",
-                        tcg_get_arg_str_idx(s, buf, sizeof(buf),
args[k++]));
+                        tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k]));
+                fprintf(dottcgoutfile, "%s_%d(%d)",
+                       tcg_get_arg_str_idx(s, buf, sizeof(buf), args[k]),
+                       args[k], tcg_get_arg_type_idx(s, args[k]));
+                k++;
             }
             switch (c) {
             case INDEX_op_brcond_i32:
@@ -1001,24 +1056,84 @@  void tcg_dump_ops(TCGContext *s, FILE *outfile)
 #elif TCG_TARGET_REG_BITS == 64
             case INDEX_op_setcond_i64:
 #endif
-                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]])
+                if (args[k] < ARRAY_SIZE(cond_name) && cond_name[args[k]])
{
                     fprintf(outfile, ",%s", cond_name[args[k++]]);
-                else
+                   fprintf(dottcgoutfile, ",%s", cond_name[args[k-1]]);
+                } else {
                     fprintf(outfile, ",$0x%" TCG_PRIlx, args[k++]);
+                   fprintf(dottcgoutfile, ",$0x%" TCG_PRIlx, args[k-1]);
+                }
                 i = 1;
                 break;
+            case INDEX_op_barrier:
+              switch (args[k]) {
+              case 0:
+                fprintf(outfile, "dmb, ");
+                fprintf(dottcgoutfile, "dmb, ");
+                break;
+              case 1:
+                fprintf(outfile, "dsb, ");
+                fprintf(dottcgoutfile, "dsb, ");
+                break;
+              case 2:
+                fprintf(outfile, "isb, ");
+                fprintf(dottcgoutfile, "isb, ");
+                break;
+              }
+              k++;
+              switch (args[k]) {
+              case 0xf:
+                fprintf(outfile, "sy");
+                fprintf(dottcgoutfile, "sy");
+                break;
+              case 0xe:
+                fprintf(outfile, "st");
+                fprintf(dottcgoutfile, "st");
+                break;
+              case 0xb:
+                fprintf(outfile, "ish");
+                fprintf(dottcgoutfile, "ish");
+                break;
+              case 0xa:
+                fprintf(outfile, "ishst");
+                fprintf(dottcgoutfile, "ishst");
+                break;
+              case 0x7:
+                fprintf(outfile, "nsh");
+                fprintf(dottcgoutfile, "nsh");
+                break;
+              case 0x6:
+                fprintf(outfile, "nshst");
+                fprintf(dottcgoutfile, "nshst");
+                break;
+              case 0x3:
+                fprintf(outfile, "osh");
+                fprintf(dottcgoutfile, "osh");
+                break;
+              case 0x2:
+                fprintf(outfile, "oshst");
+                fprintf(dottcgoutfile, "oshst");
+                break;
+              }
+              k++;
+              i = 2;
+              break;
             default:
                 i = 0;
                 break;
             }
             for(; i < nb_cargs; i++) {
-                if (k != 0)
+                if (k != 0) {
                     fprintf(outfile, ",");
+                    fprintf(dottcgoutfile, ",");
+                }
                 arg = args[k++];
                 fprintf(outfile, "$0x%" TCG_PRIlx, arg);
+                fprintf(dottcgoutfile, "$0x%" TCG_PRIlx, arg);
             }
         }
         fprintf(outfile, "\n");
+        fprintf(dottcgoutfile, "\n");
         args += nb_iargs + nb_oargs + nb_cargs;
     }
 }
@@ -2038,8 +2153,8 @@  static void dump_op_count(void)
 }
 #endif

-
-static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
+/* removed 'static inline' from here so that function could be used in
translate-all.c */
+int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
                                       long search_pc)
 {
     TCGOpcode opc;
@@ -2051,7 +2166,7 @@  static inline int tcg_gen_code_common(TCGContext *s,
uint8_t *gen_code_buf,
 #ifdef DEBUG_DISAS
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP))) {
         qemu_log("OP:\n");
-        tcg_dump_ops(s, logfile);
+        tcg_dump_ops(s, logfile, dottcgfile);
         qemu_log("\n");
     }
 #endif
@@ -2072,100 +2187,11 @@  static inline int tcg_gen_code_common(TCGContext
*s, uint8_t *gen_code_buf,
 #ifdef DEBUG_DISAS
     if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP_OPT))) {
         qemu_log("OP after liveness analysis:\n");
-        tcg_dump_ops(s, logfile);
+        tcg_dump_ops(s, logfile, dottcgfile);
         qemu_log("\n");
     }
 #endif

-    tcg_reg_alloc_start(s);
-
-    s->code_buf = gen_code_buf;
-    s->code_ptr = gen_code_buf;
-
-    args = gen_opparam_buf;
-    op_index = 0;
-
-    for(;;) {
-        opc = gen_opc_buf[op_index];
-#ifdef CONFIG_PROFILER
-        tcg_table_op_count[opc]++;
-#endif
-        def = &tcg_op_defs[opc];
-#if 0
-        printf("%s: %d %d %d\n", def->name,
-               def->nb_oargs, def->nb_iargs, def->nb_cargs);
-        //        dump_regs(s);
-#endif
-        switch(opc) {
-        case INDEX_op_mov_i32:
-#if TCG_TARGET_REG_BITS == 64
-        case INDEX_op_mov_i64:
-#endif
-            dead_args = s->op_dead_args[op_index];
-            tcg_reg_alloc_mov(s, def, args, dead_args);
-            break;
-        case INDEX_op_movi_i32:
-#if TCG_TARGET_REG_BITS == 64
-        case INDEX_op_movi_i64:
-#endif
-            tcg_reg_alloc_movi(s, args);
-            break;
-        case INDEX_op_debug_insn_start:
-            /* debug instruction */
-            break;
-        case INDEX_op_nop:
-        case INDEX_op_nop1:
-        case INDEX_op_nop2:
-        case INDEX_op_nop3:
-            break;
-        case INDEX_op_nopn:
-            args += args[0];
-            goto next;
-        case INDEX_op_discard:
-            {
-                TCGTemp *ts;
-                ts = &s->temps[args[0]];
-                /* mark the temporary as dead */
-                if (!ts->fixed_reg) {
-                    if (ts->val_type == TEMP_VAL_REG)
-                        s->reg_to_temp[ts->reg] = -1;
-                    ts->val_type = TEMP_VAL_DEAD;
-                }
-            }
-            break;
-        case INDEX_op_set_label:
-            tcg_reg_alloc_bb_end(s, s->reserved_regs);
-            tcg_out_label(s, args[0], (long)s->code_ptr);
-            break;
-        case INDEX_op_call:
-            dead_args = s->op_dead_args[op_index];
-            args += tcg_reg_alloc_call(s, def, opc, args, dead_args);
-            goto next;
-        case INDEX_op_end:
-            goto the_end;
-        default:
-            /* Sanity check that we've not introduced any unhandled
opcodes. */
-            if (def->flags & TCG_OPF_NOT_PRESENT) {
-                tcg_abort();
-            }
-            /* Note: in order to speed up the code, it would be much
-               faster to have specialized register allocator functions for
-               some common argument patterns */
-            dead_args = s->op_dead_args[op_index];
-            tcg_reg_alloc_op(s, def, opc, args, dead_args);
-            break;
-        }
-        args += def->nb_args;
-    next:
-        if (search_pc >= 0 && search_pc < s->code_ptr - gen_code_buf) {
-            return op_index;
-        }
-        op_index++;
-#ifndef NDEBUG
-        check_regs(s);
-#endif
-    }
- the_end:
     return -1;
 }

diff --git tcg/tcg.h tcg/tcg.h
index 5c28239..fb8b5b5 100644
--- tcg/tcg.h
+++ tcg/tcg.h
@@ -430,6 +430,9 @@  void tcg_func_start(TCGContext *s);
 int tcg_gen_code(TCGContext *s, uint8_t *gen_code_buf);
 int tcg_gen_code_search_pc(TCGContext *s, uint8_t *gen_code_buf, long
offset);

+/* this function is used to log OP code */
+int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf, long
search_pc);
+
 void tcg_set_frame(TCGContext *s, int reg,
                    tcg_target_long start, tcg_target_long size);

@@ -576,7 +579,7 @@  TCGArg *tcg_optimize(TCGContext *s, uint16_t
*tcg_opc_ptr, TCGArg *args,
 /* only used for debugging purposes */
 void tcg_register_helper(void *func, const char *name);
 const char *tcg_helper_get_name(TCGContext *s, void *func);
-void tcg_dump_ops(TCGContext *s, FILE *outfile);
+void tcg_dump_ops(TCGContext *s, FILE *outfile, FILE *dottcgoutfile);

 void dump_ops(const uint16_t *opc_buf, const TCGArg *opparam_buf);
 TCGv_i32 tcg_const_i32(int32_t val);
diff --git translate-all.c translate-all.c
index 041c108..7a5785e 100644
--- translate-all.c
+++ translate-all.c
@@ -87,22 +87,8 @@  int cpu_gen_code(CPUState *env, TranslationBlock *tb,
int *gen_code_size_ptr)
     s->interm_time += profile_getclock() - ti;
     s->code_time -= profile_getclock();
 #endif
-    gen_code_size = tcg_gen_code(s, gen_code_buf);
-    *gen_code_size_ptr = gen_code_size;
-#ifdef CONFIG_PROFILER
-    s->code_time += profile_getclock();
-    s->code_in_len += tb->size;
-    s->code_out_len += gen_code_size;
-#endif
-
-#ifdef DEBUG_DISAS
-    if (qemu_loglevel_mask(CPU_LOG_TB_OUT_ASM)) {
-        qemu_log("OUT: [size=%d]\n", *gen_code_size_ptr);
-        log_disas(tb->tc_ptr, *gen_code_size_ptr);
-        qemu_log("\n");
-        qemu_log_flush();
-    }
-#endif
+    /* call this function to print the OP code */
+    tcg_gen_code_common(s, gen_code_buf, -1);
     return 0;
 }