qemu/include/qemu/etrace.h
<<
>>
Prefs
   1/*
   2 * Execution trace packager.
   3 * Copyright (c) 2013 Xilinx Inc.
   4 * Written by Edgar E. Iglesias
   5 *
   6 * This library is free software; you can redistribute it and/or
   7 * modify it under the terms of the GNU Lesser General Public
   8 * License as published by the Free Software Foundation; either
   9 * version 2 of the License, or (at your option) any later version.
  10 *
  11 * This library is distributed in the hope that it will be useful,
  12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14 * Lesser General Public License for more details.
  15 *
  16 * You should have received a copy of the GNU Lesser General Public
  17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  18 */
  19#ifndef __ETRACE_H__
  20#define __ETRACE_H__
  21
  22#include <stdio.h>
  23#include <stdbool.h>
  24
  25struct etrace_entry32 {
  26    uint32_t duration;
  27    uint32_t start, end;
  28};
  29
  30struct etrace_entry64 {
  31    uint32_t duration;
  32    uint64_t start, end;
  33};
  34
  35enum qemu_etrace_flag {
  36    ETRACE_F_NONE        = 0,
  37    ETRACE_F_EXEC        = (1 << 0),
  38    ETRACE_F_TRANSLATION = (1 << 1),
  39    ETRACE_F_MEM         = (1 << 2),
  40    ETRACE_F_CPU         = (1 << 3),
  41    ETRACE_F_GPIO         = (1 << 4),
  42};
  43
  44enum qemu_etrace_event_u64_flag {
  45    ETRACE_EVU64_F_NONE        = 0,
  46    ETRACE_EVU64_F_PREV_VAL    = (1 << 0),
  47};
  48
  49enum etrace_mem_attr {
  50    MEM_READ    = (0 << 0),
  51    MEM_WRITE   = (1 << 0),
  52};
  53
  54struct etracer {
  55    const char *filename;
  56    FILE *fp;
  57    unsigned int arch_bits;
  58    uint64_t flags;
  59
  60    /* FIXME: Removeme.  */
  61    unsigned int current_unit_id;
  62
  63#define EXEC_CACHE_SIZE (16 * 1024)
  64    uint64_t exec_start;
  65    bool exec_start_valid;
  66    int64_t exec_start_time;
  67    struct {
  68        union {
  69            struct etrace_entry64 t64[EXEC_CACHE_SIZE];
  70            struct etrace_entry32 t32[2 * EXEC_CACHE_SIZE];
  71        };
  72        uint64_t start_time;
  73        unsigned int pos;
  74        unsigned int unit_id;
  75    } exec_cache;
  76};
  77
  78bool etrace_init(struct etracer *t, const char *filename,
  79                 const char *opts,
  80                 unsigned int arch_id, unsigned int arch_bits);
  81void etrace_close(struct etracer *t);
  82void etrace_dump_exec(struct etracer *t, unsigned int unit_id,
  83                      uint64_t start, uint64_t end,
  84                      uint64_t start_time, uint32_t duration);
  85
  86/* Helpers.  */
  87void etrace_dump_exec_start(struct etracer *t,
  88                            unsigned int unit_id,
  89                            uint64_t start);
  90
  91void etrace_dump_exec_end(struct etracer *t,
  92                          unsigned int unit_id,
  93                          uint64_t end);
  94
  95void etrace_mem_access(struct etracer *t, uint16_t unit_id,
  96                       uint64_t guest_vaddr, uint64_t guest_paddr,
  97                       size_t size, uint64_t attr, uint64_t val);
  98
  99void etrace_dump_tb(struct etracer *t, AddressSpace *as, uint16_t unit_id,
 100                    uint64_t guest_vaddr, uint64_t guest_paddr,
 101                    size_t guest_len,
 102                    void *host_buf, size_t host_len);
 103
 104void etrace_note_write(struct etracer *t, unsigned int unit_id,
 105                       void *buf, size_t len);
 106
 107/* fp should point to an etracer object.  */
 108int etrace_note_fprintf(FILE *fp,
 109                        const char *fmt, ...);
 110
 111void etrace_event_u64(struct etracer *t, uint16_t unit_id,
 112                      uint32_t flags,
 113                      const char *dev_name,
 114                      const char *event_name,
 115                      uint64_t val, uint64_t prev_val);
 116
 117/* QEMU helpers to simplify integration into qemu.  */
 118extern const char *qemu_arg_etrace;
 119extern const char *qemu_arg_etrace_flags;
 120extern struct etracer qemu_etracer;
 121extern bool qemu_etrace_enabled;
 122void qemu_etrace_cleanup(void);
 123
 124static inline bool qemu_etrace_mask(uint64_t mask)
 125{
 126    if (qemu_etrace_enabled
 127        && (qemu_etracer.flags & mask)) {
 128        return true;
 129    }
 130    return false;
 131}
 132
 133void qemu_etrace_gpio_init(void);
 134#endif
 135