Home | History | Annotate | Download | only in hw
      1 /* Copyright (C) 2007-2008 The Android Open Source Project
      2 **
      3 ** This software is licensed under the terms of the GNU General Public
      4 ** License version 2, as published by the Free Software Foundation, and
      5 ** may be copied, distributed, and modified under those terms.
      6 **
      7 ** This program is distributed in the hope that it will be useful,
      8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     10 ** GNU General Public License for more details.
     11 */
     12 #ifndef _TRACE_DEV_H_
     13 #define _TRACE_DEV_H_
     14 
     15 #include "goldfish_device.h"
     16 
     17 #define CLIENT_PAGE_SIZE        4096
     18 
     19 /* trace device registers */
     20 
     21 /* The indices below all corresponds to slots that can only be accessed
     22  * by the guest kernel. See below for indices reachable from the guest
     23  * user-land.
     24  */
     25 #define TRACE_DEV_REG_SWITCH            0
     26 #define TRACE_DEV_REG_FORK              1
     27 #define TRACE_DEV_REG_EXECVE_PID        2
     28 #define TRACE_DEV_REG_EXECVE_VMSTART    3
     29 #define TRACE_DEV_REG_EXECVE_VMEND      4
     30 #define TRACE_DEV_REG_EXECVE_OFFSET     5
     31 #define TRACE_DEV_REG_EXECVE_EXEPATH    6
     32 #define TRACE_DEV_REG_EXIT              7
     33 #define TRACE_DEV_REG_CMDLINE           8
     34 #define TRACE_DEV_REG_CMDLINE_LEN       9
     35 #define TRACE_DEV_REG_MMAP_EXEPATH      10
     36 #define TRACE_DEV_REG_INIT_PID          11
     37 #define TRACE_DEV_REG_INIT_NAME         12
     38 #define TRACE_DEV_REG_CLONE             13
     39 #define TRACE_DEV_REG_UNMAP_START       14
     40 #define TRACE_DEV_REG_UNMAP_END         15
     41 #define TRACE_DEV_REG_NAME              16
     42 #define TRACE_DEV_REG_TGID              17
     43 #define TRACE_DEV_REG_DYN_SYM           50
     44 #define TRACE_DEV_REG_DYN_SYM_ADDR      51
     45 #define TRACE_DEV_REG_REMOVE_ADDR       52
     46 #define TRACE_DEV_REG_PRINT_STR         60
     47 #define TRACE_DEV_REG_PRINT_NUM_DEC     61
     48 #define TRACE_DEV_REG_PRINT_NUM_HEX     62
     49 #define TRACE_DEV_REG_STOP_EMU          90
     50 #define TRACE_DEV_REG_ENABLE            100
     51 
     52 /* NOTE: The device's second physical page is mapped to /dev/qemu_trace
     53  *        This means that if you do the following:
     54  *
     55  *           magicPage = my_mmap("/dev/qemu_trace", ...);
     56  *           *(uint32_t*)magicPage[index] = value;
     57  *
     58  *        The write at address magicPage+index*4 here will be seen
     59  *        by the device as a write to the i/o offset 4096 + index*4,
     60  *        i.e. (1024 + index)*4.
     61  *
     62  *        As a consequence, any index defined below corresponds to
     63  *        location (index-1024)*4 in the mmapped page in the guest.
     64  */
     65 
     66 /* The first 64 entries are reserved for VM instrumentation */
     67 #define TRACE_DEV_REG_METHOD_ENTRY      1024
     68 #define TRACE_DEV_REG_METHOD_EXIT       1025
     69 #define TRACE_DEV_REG_METHOD_EXCEPTION  1026
     70 #define TRACE_DEV_REG_NATIVE_ENTRY      1028
     71 #define TRACE_DEV_REG_NATIVE_EXIT       1029
     72 #define TRACE_DEV_REG_NATIVE_EXCEPTION  1030
     73 
     74 /* Next, QEMUD fast pipes */
     75 #define TRACE_DEV_PIPE_BASE             1280    /* 1024 + (64*4) */
     76 #define TRACE_DEV_PIPE_COMMAND          (TRACE_DEV_PIPE_BASE + 0)
     77 #define TRACE_DEV_PIPE_STATUS           (TRACE_DEV_PIPE_BASE + 0)
     78 #define TRACE_DEV_PIPE_ADDRESS          (TRACE_DEV_PIPE_BASE + 1)
     79 #define TRACE_DEV_PIPE_SIZE             (TRACE_DEV_PIPE_BASE + 2)
     80 #define TRACE_DEV_PIPE_CHANNEL          (TRACE_DEV_PIPE_BASE + 3)
     81 
     82 /* These entries are reserved for libc instrumentation, i.e. memcheck */
     83 #if 0  /* see memcheck_common.h */
     84 #define TRACE_DEV_REG_MEMCHECK              1536  /* 1024 + (128*4) */
     85 #define TRACE_DEV_REG_LIBC_INIT             (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_LIBC_INIT)
     86 #define TRACE_DEV_REG_MALLOC                (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_MALLOC)
     87 #define TRACE_DEV_REG_FREE_PTR              (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_FREE_PTR)
     88 #define TRACE_DEV_REG_QUERY_MALLOC          (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_QUERY_MALLOC)
     89 #define TRACE_DEV_REG_PRINT_USER_STR        (TRACE_DEV_REG_MEMCHECK + MEMCHECK_EVENT_PRINT_USER_STR)
     90 #endif
     91 
     92 /* the virtual trace device state */
     93 typedef struct {
     94     struct goldfish_device dev;
     95 } trace_dev_state;
     96 
     97 /*
     98  * interfaces for copy from virtual space
     99  * from target-arm/op_helper.c
    100  */
    101 extern void vstrcpy(target_ulong ptr, char *buf, int max);
    102 
    103 /*
    104  * interfaces to trace module to signal kernel events
    105  */
    106 extern void trace_switch(int pid);
    107 extern void trace_fork(int tgid, int pid);
    108 extern void trace_clone(int tgid, int pid);
    109 extern void trace_execve(const char *arg, int len);
    110 extern void trace_exit(int exitcode);
    111 extern void trace_mmap(unsigned long vstart, unsigned long vend,
    112                        unsigned long offset, const char *path);
    113 extern void trace_munmap(unsigned long vstart, unsigned long vend);
    114 extern void trace_dynamic_symbol_add(unsigned long vaddr, const char *name);
    115 extern void trace_dynamic_symbol_remove(unsigned long vaddr);
    116 extern void trace_init_name(int tgid, int pid, const char *name);
    117 extern void trace_init_exec(unsigned long start, unsigned long end,
    118                             unsigned long offset, const char *exe);
    119 extern void start_tracing(void);
    120 extern void stop_tracing(void);
    121 extern void trace_exception(uint32 target_pc);
    122 
    123 #endif
    124