1 /* Copyright (C) 2021 Free Software Foundation, Inc.
2    Contributed by Oracle.
3 
4    This file is part of GNU Binutils.
5 
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3, or (at your option)
9    any later version.
10 
11    This program 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
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, 51 Franklin Street - Fifth Floor, Boston,
19    MA 02110-1301, USA.  */
20 
21 #ifndef _HWPROFILE_H
22 #define _HWPROFILE_H
23 
24 #include <data_pckts.h>
25 
26 typedef struct Hwcntr_packet
27 { /* HW counter profiling packet */
28   Common_packet comm;
29   uint32_t tag;         /* hw counter index, register */
30   uint64_t interval;    /* overflow value */
31 } Hwcntr_packet;
32 
33 typedef struct MHwcntr_packet
34 { /* extended (superset) Hwcntr_packet */
35   Common_packet comm;
36   uint32_t   tag;           /* hw counter index, register */
37   uint64_t   interval;      /* overflow value */
38   Vaddr_type ea_vaddr;      /* virtual addr causing HWC event */
39   Vaddr_type pc_vaddr;      /* candidate eventPC  */
40   uint64_t   ea_paddr;      /* physical address for ea_vaddr */
41   uint64_t   pc_paddr;      /* physical address for pc_vaddr */
42   uint64_t   ea_pagesz;     /* pagesz (bytes) for ea_paddr */
43   uint64_t   pc_pagesz;     /* pagesz (bytes) for pc_paddr */
44   uint32_t   ea_lgrp;       /* latency group of ea_paddr */
45   uint32_t   pc_lgrp;       /* latency group of pc_paddr */
46   uint32_t   lgrp_lwp;      /* locality group of lwp */
47   uint32_t   lgrp_ps;       /* locality group of process */
48   uint64_t   latency;       /* latency in cycles (sampling only) */
49   uint64_t   data_source;   /* data source (sampling only) */
50 } MHwcntr_packet;
51 
52 #if ARCH(SPARC)
53 #define CONTEXT_PC MC_PC
54 #define CONTEXT_SP MC_O6
55 #define CONTEXT_FP MC_O7
56 #define SETFUNCTIONCONTEXT(ucp,funcp) \
57     (ucp)->uc_mcontext.gregs[CONTEXT_PC] = (greg_t)(funcp); \
58     (ucp)->uc_mcontext.gregs[CONTEXT_SP] = 0; \
59     (ucp)->uc_mcontext.gregs[CONTEXT_FP] = 0;
60 
61 #elif ARCH(Intel)
62 #include <sys/reg.h>
63 
64 #if WSIZE(64)
65 #define CONTEXT_PC REG_RIP
66 #define CONTEXT_FP REG_RBP
67 #define CONTEXT_SP REG_RSP
68 
69 #elif WSIZE(32)
70 #define CONTEXT_PC REG_EIP
71 #define CONTEXT_FP REG_EBP
72 #define CONTEXT_SP REG_ESP
73 #endif /* WSIZE() */
74 #define SETFUNCTIONCONTEXT(ucp,funcp) \
75     (ucp)->uc_mcontext.gregs[CONTEXT_PC] = (intptr_t)(funcp); \
76     (ucp)->uc_mcontext.gregs[CONTEXT_SP] = 0; \
77     (ucp)->uc_mcontext.gregs[CONTEXT_FP] = 0;
78 
79 #elif ARCH(Aarch64)
80 #define CONTEXT_PC 15
81 #define CONTEXT_FP 14
82 #define CONTEXT_SP 13
83 #define SETFUNCTIONCONTEXT(ucp,funcp) \
84     (ucp)->uc_mcontext.regs[CONTEXT_PC] = (greg_t)(funcp); \
85     (ucp)->uc_mcontext.regs[CONTEXT_SP] = 0; \
86     (ucp)->uc_mcontext.regs[CONTEXT_FP] = 0;
87 #endif /* ARCH() */
88 
89 #endif
90