cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

tcg_helper_wrapper_h.py (2137B)


      1# -*- coding: utf-8 -*-
      2
      3"""
      4Generate trace/generated-helpers-wrappers.h.
      5"""
      6
      7__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
      8__copyright__  = "Copyright 2012-2016, Lluís Vilanova <vilanova@ac.upc.edu>"
      9__license__    = "GPL version 2 or (at your option) any later version"
     10
     11__maintainer__ = "Stefan Hajnoczi"
     12__email__      = "stefanha@redhat.com"
     13
     14
     15from tracetool import out
     16from tracetool.transform import *
     17import tracetool.vcpu
     18
     19
     20def generate(events, backend, group):
     21    events = [e for e in events
     22              if "disable" not in e.properties]
     23
     24    out('/* This file is autogenerated by tracetool, do not edit. */',
     25        '',
     26        '#define tcg_temp_new_nop(v) (v)',
     27        '#define tcg_temp_free_nop(v)',
     28        '',
     29        )
     30
     31    for e in events:
     32        if "tcg-exec" not in e.properties:
     33            continue
     34
     35        # tracetool.generate always transforms types to host
     36        e_args = tracetool.vcpu.transform_args("tcg_helper_c", e.original, "wrapper")
     37
     38        # mixed-type to TCG helper bridge
     39        args_tcg_compat = e_args.transform(HOST_2_TCG_COMPAT)
     40
     41        code_new = [
     42            "%(tcg_type)s __%(name)s = %(tcg_func)s(%(name)s);" %
     43            {"tcg_type": transform_type(type_, HOST_2_TCG),
     44             "tcg_func": transform_type(type_, HOST_2_TCG_TMP_NEW),
     45             "name": name}
     46            for (type_, name) in args_tcg_compat
     47        ]
     48
     49        code_free = [
     50            "%(tcg_func)s(__%(name)s);" %
     51            {"tcg_func": transform_type(type_, HOST_2_TCG_TMP_FREE),
     52             "name": name}
     53            for (type_, name) in args_tcg_compat
     54        ]
     55
     56        gen_name = "gen_helper_" + e.api()
     57
     58        out('static inline void %(name)s(%(args)s)',
     59            '{',
     60            '    %(code_new)s',
     61            '    %(proxy_name)s(%(tmp_names)s);',
     62            '    %(code_free)s',
     63            '}',
     64            name=gen_name,
     65            args=e_args,
     66            proxy_name=gen_name + "_proxy",
     67            code_new="\n    ".join(code_new),
     68            code_free="\n    ".join(code_free),
     69            tmp_names=", ".join(["__%s" % name for _, name in e_args]),
     70            )