Lines Matching +full:byte +full:- +full:len
1 // SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (c) 2013-2014, Intel Corporation.
15 #include "intel-pt-pkt-decoder.h"
73 static int intel_pt_get_long_tnt(const unsigned char *buf, size_t len, in intel_pt_get_long_tnt() argument
79 if (len < 8) in intel_pt_get_long_tnt()
84 for (count = 47; count; count--) { in intel_pt_get_long_tnt()
90 packet->type = INTEL_PT_TNT; in intel_pt_get_long_tnt()
91 packet->count = count; in intel_pt_get_long_tnt()
92 packet->payload = payload << 1; in intel_pt_get_long_tnt()
96 static int intel_pt_get_pip(const unsigned char *buf, size_t len, in intel_pt_get_pip() argument
101 if (len < 8) in intel_pt_get_pip()
104 packet->type = INTEL_PT_PIP; in intel_pt_get_pip()
106 packet->payload = payload; in intel_pt_get_pip()
113 packet->type = INTEL_PT_TRACESTOP; in intel_pt_get_tracestop()
117 static int intel_pt_get_cbr(const unsigned char *buf, size_t len, in intel_pt_get_cbr() argument
120 if (len < 4) in intel_pt_get_cbr()
122 packet->type = INTEL_PT_CBR; in intel_pt_get_cbr()
123 packet->payload = get_unaligned_le16(buf + 2); in intel_pt_get_cbr()
127 static int intel_pt_get_vmcs(const unsigned char *buf, size_t len, in intel_pt_get_vmcs() argument
130 if (len < 7) in intel_pt_get_vmcs()
133 packet->type = INTEL_PT_VMCS; in intel_pt_get_vmcs()
134 packet->count = 5; in intel_pt_get_vmcs()
135 memcpy_le64(&packet->payload, buf + 2, 5); in intel_pt_get_vmcs()
142 packet->type = INTEL_PT_OVF; in intel_pt_get_ovf()
146 static int intel_pt_get_psb(const unsigned char *buf, size_t len, in intel_pt_get_psb() argument
151 if (len < 16) in intel_pt_get_psb()
159 packet->type = INTEL_PT_PSB; in intel_pt_get_psb()
165 packet->type = INTEL_PT_PSBEND; in intel_pt_get_psbend()
169 static int intel_pt_get_tma(const unsigned char *buf, size_t len, in intel_pt_get_tma() argument
172 if (len < 7) in intel_pt_get_tma()
175 packet->type = INTEL_PT_TMA; in intel_pt_get_tma()
176 packet->payload = buf[2] | (buf[3] << 8); in intel_pt_get_tma()
177 packet->count = buf[5] | ((buf[6] & BIT(0)) << 8); in intel_pt_get_tma()
183 packet->type = INTEL_PT_PAD; in intel_pt_get_pad()
187 static int intel_pt_get_mnt(const unsigned char *buf, size_t len, in intel_pt_get_mnt() argument
190 if (len < 11) in intel_pt_get_mnt()
192 packet->type = INTEL_PT_MNT; in intel_pt_get_mnt()
193 packet->payload = get_unaligned_le64(buf + 3); in intel_pt_get_mnt()
197 static int intel_pt_get_3byte(const unsigned char *buf, size_t len, in intel_pt_get_3byte() argument
200 if (len < 3) in intel_pt_get_3byte()
205 return intel_pt_get_mnt(buf, len, packet); in intel_pt_get_3byte()
211 static int intel_pt_get_ptwrite(const unsigned char *buf, size_t len, in intel_pt_get_ptwrite() argument
214 packet->count = (buf[1] >> 5) & 0x3; in intel_pt_get_ptwrite()
215 packet->type = buf[1] & BIT(7) ? INTEL_PT_PTWRITE_IP : in intel_pt_get_ptwrite()
218 switch (packet->count) { in intel_pt_get_ptwrite()
220 if (len < 6) in intel_pt_get_ptwrite()
222 packet->payload = get_unaligned_le32(buf + 2); in intel_pt_get_ptwrite()
225 if (len < 10) in intel_pt_get_ptwrite()
227 packet->payload = get_unaligned_le64(buf + 2); in intel_pt_get_ptwrite()
236 packet->type = INTEL_PT_EXSTOP; in intel_pt_get_exstop()
242 packet->type = INTEL_PT_EXSTOP_IP; in intel_pt_get_exstop_ip()
246 static int intel_pt_get_mwait(const unsigned char *buf, size_t len, in intel_pt_get_mwait() argument
249 if (len < 10) in intel_pt_get_mwait()
251 packet->type = INTEL_PT_MWAIT; in intel_pt_get_mwait()
252 packet->payload = get_unaligned_le64(buf + 2); in intel_pt_get_mwait()
256 static int intel_pt_get_pwre(const unsigned char *buf, size_t len, in intel_pt_get_pwre() argument
259 if (len < 4) in intel_pt_get_pwre()
261 packet->type = INTEL_PT_PWRE; in intel_pt_get_pwre()
262 memcpy_le64(&packet->payload, buf + 2, 2); in intel_pt_get_pwre()
266 static int intel_pt_get_pwrx(const unsigned char *buf, size_t len, in intel_pt_get_pwrx() argument
269 if (len < 7) in intel_pt_get_pwrx()
271 packet->type = INTEL_PT_PWRX; in intel_pt_get_pwrx()
272 memcpy_le64(&packet->payload, buf + 2, 5); in intel_pt_get_pwrx()
276 static int intel_pt_get_bbp(const unsigned char *buf, size_t len, in intel_pt_get_bbp() argument
279 if (len < 3) in intel_pt_get_bbp()
281 packet->type = INTEL_PT_BBP; in intel_pt_get_bbp()
282 packet->count = buf[2] >> 7; in intel_pt_get_bbp()
283 packet->payload = buf[2] & 0x1f; in intel_pt_get_bbp()
287 static int intel_pt_get_bip_4(const unsigned char *buf, size_t len, in intel_pt_get_bip_4() argument
290 if (len < 5) in intel_pt_get_bip_4()
292 packet->type = INTEL_PT_BIP; in intel_pt_get_bip_4()
293 packet->count = buf[0] >> 3; in intel_pt_get_bip_4()
294 memcpy_le64(&packet->payload, buf + 1, 4); in intel_pt_get_bip_4()
298 static int intel_pt_get_bip_8(const unsigned char *buf, size_t len, in intel_pt_get_bip_8() argument
301 if (len < 9) in intel_pt_get_bip_8()
303 packet->type = INTEL_PT_BIP; in intel_pt_get_bip_8()
304 packet->count = buf[0] >> 3; in intel_pt_get_bip_8()
305 packet->payload = get_unaligned_le64(buf + 1); in intel_pt_get_bip_8()
309 static int intel_pt_get_bep(size_t len, struct intel_pt_pkt *packet) in intel_pt_get_bep() argument
311 if (len < 2) in intel_pt_get_bep()
313 packet->type = INTEL_PT_BEP; in intel_pt_get_bep()
317 static int intel_pt_get_bep_ip(size_t len, struct intel_pt_pkt *packet) in intel_pt_get_bep_ip() argument
319 if (len < 2) in intel_pt_get_bep_ip()
321 packet->type = INTEL_PT_BEP_IP; in intel_pt_get_bep_ip()
325 static int intel_pt_get_cfe(const unsigned char *buf, size_t len, in intel_pt_get_cfe() argument
328 if (len < 4) in intel_pt_get_cfe()
330 packet->type = buf[2] & 0x80 ? INTEL_PT_CFE_IP : INTEL_PT_CFE; in intel_pt_get_cfe()
331 packet->count = buf[2] & 0x1f; in intel_pt_get_cfe()
332 packet->payload = buf[3]; in intel_pt_get_cfe()
336 static int intel_pt_get_evd(const unsigned char *buf, size_t len, in intel_pt_get_evd() argument
339 if (len < 11) in intel_pt_get_evd()
341 packet->type = INTEL_PT_EVD; in intel_pt_get_evd()
342 packet->count = buf[2] & 0x3f; in intel_pt_get_evd()
343 packet->payload = buf[3]; in intel_pt_get_evd()
344 packet->payload = get_unaligned_le64(buf + 3); in intel_pt_get_evd()
348 static int intel_pt_get_ext(const unsigned char *buf, size_t len, in intel_pt_get_ext() argument
351 if (len < 2) in intel_pt_get_ext()
355 return intel_pt_get_ptwrite(buf, len, packet); in intel_pt_get_ext()
359 return intel_pt_get_long_tnt(buf, len, packet); in intel_pt_get_ext()
361 return intel_pt_get_pip(buf, len, packet); in intel_pt_get_ext()
365 return intel_pt_get_cbr(buf, len, packet); in intel_pt_get_ext()
367 return intel_pt_get_vmcs(buf, len, packet); in intel_pt_get_ext()
371 return intel_pt_get_psb(buf, len, packet); in intel_pt_get_ext()
375 return intel_pt_get_tma(buf, len, packet); in intel_pt_get_ext()
376 case 0xC3: /* 3-byte header */ in intel_pt_get_ext()
377 return intel_pt_get_3byte(buf, len, packet); in intel_pt_get_ext()
383 return intel_pt_get_mwait(buf, len, packet); in intel_pt_get_ext()
385 return intel_pt_get_pwre(buf, len, packet); in intel_pt_get_ext()
387 return intel_pt_get_pwrx(buf, len, packet); in intel_pt_get_ext()
389 return intel_pt_get_bbp(buf, len, packet); in intel_pt_get_ext()
391 return intel_pt_get_bep(len, packet); in intel_pt_get_ext()
393 return intel_pt_get_bep_ip(len, packet); in intel_pt_get_ext()
395 return intel_pt_get_cfe(buf, len, packet); in intel_pt_get_ext()
397 return intel_pt_get_evd(buf, len, packet); in intel_pt_get_ext()
403 static int intel_pt_get_short_tnt(unsigned int byte, in intel_pt_get_short_tnt() argument
408 for (count = 6; count; count--) { in intel_pt_get_short_tnt()
409 if (byte & BIT(7)) in intel_pt_get_short_tnt()
411 byte <<= 1; in intel_pt_get_short_tnt()
414 packet->type = INTEL_PT_TNT; in intel_pt_get_short_tnt()
415 packet->count = count; in intel_pt_get_short_tnt()
416 packet->payload = (uint64_t)byte << 57; in intel_pt_get_short_tnt()
421 static int intel_pt_get_cyc(unsigned int byte, const unsigned char *buf, in intel_pt_get_cyc() argument
422 size_t len, struct intel_pt_pkt *packet) in intel_pt_get_cyc() argument
425 uint64_t payload = byte >> 3; in intel_pt_get_cyc()
427 byte >>= 2; in intel_pt_get_cyc()
428 len -= 1; in intel_pt_get_cyc()
429 for (shift = 5; byte & 1; shift += 7) { in intel_pt_get_cyc()
432 if (len < offs) in intel_pt_get_cyc()
434 byte = buf[offs++]; in intel_pt_get_cyc()
435 payload |= ((uint64_t)byte >> 1) << shift; in intel_pt_get_cyc()
438 packet->type = INTEL_PT_CYC; in intel_pt_get_cyc()
439 packet->payload = payload; in intel_pt_get_cyc()
443 static int intel_pt_get_ip(enum intel_pt_pkt_type type, unsigned int byte, in intel_pt_get_ip() argument
444 const unsigned char *buf, size_t len, in intel_pt_get_ip() argument
449 packet->count = byte >> 5; in intel_pt_get_ip()
451 switch (packet->count) { in intel_pt_get_ip()
456 if (len < 3) in intel_pt_get_ip()
459 packet->payload = get_unaligned_le16(buf + 1); in intel_pt_get_ip()
462 if (len < 5) in intel_pt_get_ip()
465 packet->payload = get_unaligned_le32(buf + 1); in intel_pt_get_ip()
469 if (len < 7) in intel_pt_get_ip()
472 memcpy_le64(&packet->payload, buf + 1, 6); in intel_pt_get_ip()
475 if (len < 9) in intel_pt_get_ip()
478 packet->payload = get_unaligned_le64(buf + 1); in intel_pt_get_ip()
484 packet->type = type; in intel_pt_get_ip()
489 static int intel_pt_get_mode(const unsigned char *buf, size_t len, in intel_pt_get_mode() argument
492 if (len < 2) in intel_pt_get_mode()
497 packet->type = INTEL_PT_MODE_EXEC; in intel_pt_get_mode()
498 packet->count = buf[1]; in intel_pt_get_mode()
501 packet->payload = 16; in intel_pt_get_mode()
504 packet->payload = 64; in intel_pt_get_mode()
507 packet->payload = 32; in intel_pt_get_mode()
514 packet->type = INTEL_PT_MODE_TSX; in intel_pt_get_mode()
517 packet->payload = buf[1] & 3; in intel_pt_get_mode()
526 static int intel_pt_get_tsc(const unsigned char *buf, size_t len, in intel_pt_get_tsc() argument
529 if (len < 8) in intel_pt_get_tsc()
531 packet->type = INTEL_PT_TSC; in intel_pt_get_tsc()
532 memcpy_le64(&packet->payload, buf + 1, 7); in intel_pt_get_tsc()
536 static int intel_pt_get_mtc(const unsigned char *buf, size_t len, in intel_pt_get_mtc() argument
539 if (len < 2) in intel_pt_get_mtc()
541 packet->type = INTEL_PT_MTC; in intel_pt_get_mtc()
542 packet->payload = buf[1]; in intel_pt_get_mtc()
546 static int intel_pt_do_get_packet(const unsigned char *buf, size_t len, in intel_pt_do_get_packet() argument
550 unsigned int byte; in intel_pt_do_get_packet() local
554 if (!len) in intel_pt_do_get_packet()
557 byte = buf[0]; in intel_pt_do_get_packet()
563 if ((byte & 0x7) == 4) in intel_pt_do_get_packet()
564 return intel_pt_get_bip_4(buf, len, packet); in intel_pt_do_get_packet()
567 if ((byte & 0x7) == 4) in intel_pt_do_get_packet()
568 return intel_pt_get_bip_8(buf, len, packet); in intel_pt_do_get_packet()
574 if (!(byte & BIT(0))) { in intel_pt_do_get_packet()
575 if (byte == 0) in intel_pt_do_get_packet()
577 if (byte == 2) in intel_pt_do_get_packet()
578 return intel_pt_get_ext(buf, len, packet); in intel_pt_do_get_packet()
579 return intel_pt_get_short_tnt(byte, packet); in intel_pt_do_get_packet()
582 if ((byte & 2)) in intel_pt_do_get_packet()
583 return intel_pt_get_cyc(byte, buf, len, packet); in intel_pt_do_get_packet()
585 switch (byte & 0x1f) { in intel_pt_do_get_packet()
587 return intel_pt_get_ip(INTEL_PT_TIP, byte, buf, len, packet); in intel_pt_do_get_packet()
589 return intel_pt_get_ip(INTEL_PT_TIP_PGE, byte, buf, len, in intel_pt_do_get_packet()
592 return intel_pt_get_ip(INTEL_PT_TIP_PGD, byte, buf, len, in intel_pt_do_get_packet()
595 return intel_pt_get_ip(INTEL_PT_FUP, byte, buf, len, packet); in intel_pt_do_get_packet()
597 switch (byte) { in intel_pt_do_get_packet()
599 return intel_pt_get_mode(buf, len, packet); in intel_pt_do_get_packet()
601 return intel_pt_get_tsc(buf, len, packet); in intel_pt_do_get_packet()
603 return intel_pt_get_mtc(buf, len, packet); in intel_pt_do_get_packet()
615 switch (packet->type) { in intel_pt_upd_pkt_ctx()
654 if (packet->count) in intel_pt_upd_pkt_ctx()
664 int intel_pt_get_packet(const unsigned char *buf, size_t len, in intel_pt_get_packet() argument
669 ret = intel_pt_do_get_packet(buf, len, packet, *ctx); in intel_pt_get_packet()
671 while (ret < 8 && len > (size_t)ret && !buf[ret]) in intel_pt_get_packet()
682 unsigned long long payload = packet->payload; in intel_pt_pkt_desc()
683 const char *name = intel_pt_pkt_name(packet->type); in intel_pt_pkt_desc()
685 switch (packet->type) { in intel_pt_pkt_desc()
700 blen -= ret; in intel_pt_pkt_desc()
701 for (i = 0; i < packet->count; i++) { in intel_pt_pkt_desc()
709 blen -= ret; in intel_pt_pkt_desc()
712 ret = snprintf(buf, blen, " (%d)", packet->count); in intel_pt_pkt_desc()
715 blen -= ret; in intel_pt_pkt_desc()
716 return buf_len - blen; in intel_pt_pkt_desc()
722 if (!(packet->count)) in intel_pt_pkt_desc()
734 (unsigned)payload, packet->count); in intel_pt_pkt_desc()
737 name, !!(packet->count & 4), payload); in intel_pt_pkt_desc()
743 nr = packet->payload & INTEL_PT_VMX_NR_FLAG ? 1 : 0; in intel_pt_pkt_desc()
763 return snprintf(buf, buf_len, "%s 0x%llx HW:%u CState:%u Sub-CState:%u", in intel_pt_pkt_desc()
774 return snprintf(buf, buf_len, "%s SZ %s-byte Type 0x%llx", in intel_pt_pkt_desc()
775 name, packet->count ? "4" : "8", payload); in intel_pt_pkt_desc()
778 name, packet->count, payload); in intel_pt_pkt_desc()
782 name, packet->type == INTEL_PT_CFE_IP, packet->count, payload); in intel_pt_pkt_desc()
785 name, packet->count, payload); in intel_pt_pkt_desc()
790 name, payload, packet->count); in intel_pt_pkt_desc()