2 * Copyright (c) 2013-2018, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include "pt_last_ip.h"
34 void pt_last_ip_init(struct pt_last_ip *last_ip)
41 last_ip->suppressed = 0;
44 int pt_last_ip_query(uint64_t *ip, const struct pt_last_ip *last_ip)
49 if (!last_ip->have_ip) {
55 if (last_ip->suppressed) {
58 return -pte_ip_suppressed;
67 /* Sign-extend a uint64_t value. */
68 static uint64_t sext(uint64_t val, uint8_t sign)
70 uint64_t signbit, mask;
72 signbit = 1ull << (sign - 1);
75 return val & signbit ? val | mask : val & ~mask;
78 int pt_last_ip_update_ip(struct pt_last_ip *last_ip,
79 const struct pt_packet_ip *packet,
80 const struct pt_config *config)
84 if (!last_ip || !packet)
87 switch (packet->ipc) {
88 case pt_ipc_suppressed:
89 last_ip->suppressed = 1;
93 last_ip->ip = sext(packet->ip, 48);
95 last_ip->suppressed = 0;
98 case pt_ipc_update_16:
99 last_ip->ip = (last_ip->ip & ~0xffffull)
100 | (packet->ip & 0xffffull);
101 last_ip->have_ip = 1;
102 last_ip->suppressed = 0;
105 case pt_ipc_update_32:
106 last_ip->ip = (last_ip->ip & ~0xffffffffull)
107 | (packet->ip & 0xffffffffull);
108 last_ip->have_ip = 1;
109 last_ip->suppressed = 0;
112 case pt_ipc_update_48:
113 last_ip->ip = (last_ip->ip & ~0xffffffffffffull)
114 | (packet->ip & 0xffffffffffffull);
115 last_ip->have_ip = 1;
116 last_ip->suppressed = 0;
120 last_ip->ip = packet->ip;
121 last_ip->have_ip = 1;
122 last_ip->suppressed = 0;
126 return -pte_bad_packet;