blob: 17ca9b56d72f853c5bf87031cd14077fa7be3ac6 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001/* SPDX-License-Identifier: GPL-2.0-only */
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
3 * intel_pt_pkt_decoder.h: Intel Processor Trace support
4 * Copyright (c) 2013-2014, Intel Corporation.
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00005 */
6
7#ifndef INCLUDE__INTEL_PT_PKT_DECODER_H__
8#define INCLUDE__INTEL_PT_PKT_DECODER_H__
9
10#include <stddef.h>
11#include <stdint.h>
12
13#define INTEL_PT_PKT_DESC_MAX 256
14
15#define INTEL_PT_NEED_MORE_BYTES -1
16#define INTEL_PT_BAD_PACKET -2
17
18#define INTEL_PT_PSB_STR "\002\202\002\202\002\202\002\202" \
19 "\002\202\002\202\002\202\002\202"
20#define INTEL_PT_PSB_LEN 16
21
22#define INTEL_PT_PKT_MAX_SZ 16
23
24enum intel_pt_pkt_type {
25 INTEL_PT_BAD,
26 INTEL_PT_PAD,
27 INTEL_PT_TNT,
28 INTEL_PT_TIP_PGD,
29 INTEL_PT_TIP_PGE,
30 INTEL_PT_TSC,
31 INTEL_PT_TMA,
32 INTEL_PT_MODE_EXEC,
33 INTEL_PT_MODE_TSX,
34 INTEL_PT_MTC,
35 INTEL_PT_TIP,
36 INTEL_PT_FUP,
37 INTEL_PT_CYC,
38 INTEL_PT_VMCS,
39 INTEL_PT_PSB,
40 INTEL_PT_PSBEND,
41 INTEL_PT_CBR,
42 INTEL_PT_TRACESTOP,
43 INTEL_PT_PIP,
44 INTEL_PT_OVF,
45 INTEL_PT_MNT,
46 INTEL_PT_PTWRITE,
47 INTEL_PT_PTWRITE_IP,
48 INTEL_PT_EXSTOP,
49 INTEL_PT_EXSTOP_IP,
50 INTEL_PT_MWAIT,
51 INTEL_PT_PWRE,
52 INTEL_PT_PWRX,
David Brazdil0f672f62019-12-10 10:32:29 +000053 INTEL_PT_BBP,
54 INTEL_PT_BIP,
55 INTEL_PT_BEP,
56 INTEL_PT_BEP_IP,
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000057};
58
59struct intel_pt_pkt {
60 enum intel_pt_pkt_type type;
61 int count;
62 uint64_t payload;
63};
64
David Brazdil0f672f62019-12-10 10:32:29 +000065/*
66 * Decoding of BIP packets conflicts with single-byte TNT packets. Since BIP
67 * packets only occur in the context of a block (i.e. between BBP and BEP), that
68 * context must be recorded and passed to the packet decoder.
69 */
70enum intel_pt_pkt_ctx {
71 INTEL_PT_NO_CTX, /* BIP packets are invalid */
72 INTEL_PT_BLK_4_CTX, /* 4-byte BIP packets */
73 INTEL_PT_BLK_8_CTX, /* 8-byte BIP packets */
74};
75
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000076const char *intel_pt_pkt_name(enum intel_pt_pkt_type);
77
78int intel_pt_get_packet(const unsigned char *buf, size_t len,
David Brazdil0f672f62019-12-10 10:32:29 +000079 struct intel_pt_pkt *packet,
80 enum intel_pt_pkt_ctx *ctx);
81
82void intel_pt_upd_pkt_ctx(const struct intel_pt_pkt *packet,
83 enum intel_pt_pkt_ctx *ctx);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000084
85int intel_pt_pkt_desc(const struct intel_pt_pkt *packet, char *buf, size_t len);
86
87#endif