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_c.py (2386B)


      1# -*- coding: utf-8 -*-
      2
      3"""
      4Generate trace/generated-helpers.c.
      5"""
      6
      7__author__     = "Lluís Vilanova <vilanova@ac.upc.edu>"
      8__copyright__  = "Copyright 2012-2017, 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 Arguments, out
     16from tracetool.transform import *
     17import tracetool.vcpu
     18
     19
     20def vcpu_transform_args(args, mode):
     21    assert len(args) == 1
     22    # NOTE: this name must be kept in sync with the one in "tcg_h"
     23    args = Arguments([(args.types()[0], "__tcg_" + args.names()[0])])
     24    if mode == "code":
     25        return Arguments([
     26            # Does cast from helper requirements to tracing types
     27            ("CPUState *", "env_cpu(%s)" % args.names()[0]),
     28        ])
     29    else:
     30        args = Arguments([
     31            # NOTE: Current helper code uses TCGv_env (CPUArchState*)
     32            ("CPUArchState *", args.names()[0]),
     33        ])
     34        if mode == "header":
     35            return args
     36        elif mode == "wrapper":
     37            return args.transform(HOST_2_TCG)
     38        else:
     39            assert False
     40
     41
     42def generate(events, backend, group):
     43    if group == "root":
     44        header = "trace/trace-root.h"
     45    else:
     46        header = "trace.h"
     47
     48    events = [e for e in events
     49              if "disable" not in e.properties]
     50
     51    out('/* This file is autogenerated by tracetool, do not edit. */',
     52        '',
     53        '#include "qemu/osdep.h"',
     54        '#include "cpu.h"',
     55        '#include "exec/helper-proto.h"',
     56        '#include "%s"' % header,
     57        '',
     58        )
     59
     60    for e in events:
     61        if "tcg-exec" not in e.properties:
     62            continue
     63
     64        e_args_api = tracetool.vcpu.transform_args(
     65            "tcg_helper_c", e.original, "header").transform(
     66                HOST_2_TCG_COMPAT, TCG_2_TCG_HELPER_DEF)
     67        e_args_call = tracetool.vcpu.transform_args(
     68            "tcg_helper_c", e, "code")
     69
     70        out('void %(name_tcg)s(%(args_api)s)',
     71            '{',
     72            # NOTE: the check was already performed at TCG-generation time
     73            '    %(name)s(%(args_call)s);',
     74            '}',
     75            name_tcg="helper_%s_proxy" % e.api(),
     76            name=e.api(e.QEMU_TRACE_NOCHECK),
     77            args_api=e_args_api,
     78            args_call=", ".join(e_args_call.casted()),
     79            )