Blame doc/howto_pttc.md

Packit b1f7ae
Testing the Intel(R) Processor Trace (Intel PT) Decoder Library and Samples {#pttc}
Packit b1f7ae
===========================================================================
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
 ! Copyright (c) 2013-2017, Intel Corporation
Packit b1f7ae
 !
Packit b1f7ae
 ! Redistribution and use in source and binary forms, with or without
Packit b1f7ae
 ! modification, are permitted provided that the following conditions are met:
Packit b1f7ae
 !
Packit b1f7ae
 !  * Redistributions of source code must retain the above copyright notice,
Packit b1f7ae
 !    this list of conditions and the following disclaimer.
Packit b1f7ae
 !  * Redistributions in binary form must reproduce the above copyright notice,
Packit b1f7ae
 !    this list of conditions and the following disclaimer in the documentation
Packit b1f7ae
 !    and/or other materials provided with the distribution.
Packit b1f7ae
 !  * Neither the name of Intel Corporation nor the names of its contributors
Packit b1f7ae
 !    may be used to endorse or promote products derived from this software
Packit b1f7ae
 !    without specific prior written permission.
Packit b1f7ae
 !
Packit b1f7ae
 ! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit b1f7ae
 ! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit b1f7ae
 ! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit b1f7ae
 ! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit b1f7ae
 ! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit b1f7ae
 ! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit b1f7ae
 ! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit b1f7ae
 ! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit b1f7ae
 ! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit b1f7ae
 ! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit b1f7ae
 ! POSSIBILITY OF SUCH DAMAGE.
Packit b1f7ae
 !-->
Packit b1f7ae
Packit b1f7ae
This chapter documents how to use the pttc tool to generate and run tests.
Packit b1f7ae
Pttc takes a yasm assembly file and creates a Processor Trace stream from
Packit b1f7ae
special directives in its input.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
Usage
Packit b1f7ae
-----
Packit b1f7ae
Packit b1f7ae
	$ pttc path/to/file.ptt
Packit b1f7ae
Packit b1f7ae
If no error occurs, the following files will be generated in the current working
Packit b1f7ae
directory:
Packit b1f7ae
Packit b1f7ae
	file.lst
Packit b1f7ae
	file.bin
Packit b1f7ae
	file.pt
Packit b1f7ae
	file.exp
Packit b1f7ae
Packit b1f7ae
The `.lst` and `.bin` files are generated by a call to yasm. The `.pt` file
Packit b1f7ae
contains the Processor Trace and the `.exp` file contains the content of the
Packit b1f7ae
comments after the `.exp` directive.
Packit b1f7ae
Packit b1f7ae
Pttc prints the filenames of the generated `.exp` files to stdout.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
Syntax
Packit b1f7ae
------
Packit b1f7ae
Packit b1f7ae
Pttc allows annotations in the comments of yasm assembler source files.  The
Packit b1f7ae
parser recognizes all comments that contain the `@pt` directive marker.
Packit b1f7ae
Packit b1f7ae
Every pt directive can be preceded by a label name followed by a colon (`:`).
Packit b1f7ae
Refer to the description of the `.exp()` directive below on how to use these
Packit b1f7ae
labels.
Packit b1f7ae
Packit b1f7ae
The general syntax for pt directives is as follows:
Packit b1f7ae
Packit b1f7ae
	@pt [label:]directive([arguments])
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
### Directives
Packit b1f7ae
Packit b1f7ae
This section lists the directives that are understood by pttc.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### psb, psbend, pad, ovf, stop
Packit b1f7ae
Packit b1f7ae
	@pt psb()
Packit b1f7ae
	@pt psbend()
Packit b1f7ae
	@pt pad()
Packit b1f7ae
	@pt ovf()
Packit b1f7ae
	@pt stop()
Packit b1f7ae
Packit b1f7ae
These packets do not have any arguments and correspond to the packets from the
Packit b1f7ae
specification.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### tnt, tnt64
Packit b1f7ae
Packit b1f7ae
	@pt tnt(args)
Packit b1f7ae
	@pt tnt64(args)
Packit b1f7ae
Packit b1f7ae
The arguments of the tnt and tnt64 packets is a list of Takens `t` and
Packit b1f7ae
Not-Takens `n`. For better readability an arbitrary number of blanks and dots
Packit b1f7ae
can be intervened.
Packit b1f7ae
Packit b1f7ae
It is an error if no characters, only blanks or dots, or other characters are in
Packit b1f7ae
the payload. Additionally for the TNT packet and the TNT64 packet it is an error
Packit b1f7ae
to have more than 6 and more than 47 t's or n's in the payload, respectively.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### tip, tip.pge, tip.pgd, fup
Packit b1f7ae
Packit b1f7ae
	@pt tip(ipc: addr)
Packit b1f7ae
	@pt tip.pge(ipc: addr)
Packit b1f7ae
	@pt tip.pgd(ipc: addr)
Packit b1f7ae
	@pt fup(ipc: addr)
Packit b1f7ae
Packit b1f7ae
These packets accept arbitrary addresses. `Addr` must be a parsable integer or a
Packit b1f7ae
valid label name. `Ipc` specifies the IP compression bits as integer number.
Packit b1f7ae
Packit b1f7ae
If `addr` is given as a label, the address is truncated according to the IP
Packit b1f7ae
bytes value given in `ipc`.  Otherwise the address needs to be a zero-extended
Packit b1f7ae
integer no bigger than specified in `ipc`.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### mode.exec, mode.tsx
Packit b1f7ae
Packit b1f7ae
	@pt mode.exec(mode)
Packit b1f7ae
	@pt mode.tsx(state)
Packit b1f7ae
Packit b1f7ae
`Mode` must be either `16bit` or `32bit` or `64bit`; `state` must be `begin` or
Packit b1f7ae
`abort` or `commit`.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### pip
Packit b1f7ae
Packit b1f7ae
	@pt pip(addr[, nr])
Packit b1f7ae
Packit b1f7ae
Addr is the value that was written to CR3.
Packit b1f7ae
Packit b1f7ae
If nr is specified after addr, the non-root bit is set.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### tsc
Packit b1f7ae
Packit b1f7ae
	@pt tsc(value)
Packit b1f7ae
Packit b1f7ae
Value is the timestamp.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### cbr
Packit b1f7ae
Packit b1f7ae
	@pt cbr(value)
Packit b1f7ae
Packit b1f7ae
Value is the core/bus ratio.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### tma
Packit b1f7ae
Packit b1f7ae
    @pt tma(ctc, fc)
Packit b1f7ae
Packit b1f7ae
Ctc is the 16bit crystal clock component.
Packit b1f7ae
Fc is the 9bit fast counter component.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### mtc
Packit b1f7ae
Packit b1f7ae
    @pt mtc(value)
Packit b1f7ae
Packit b1f7ae
Value is the 8bit crystal clock component.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### cyc
Packit b1f7ae
Packit b1f7ae
    @pt cyc(value)
Packit b1f7ae
Packit b1f7ae
Value is the cycle count.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### vmcs
Packit b1f7ae
Packit b1f7ae
    @pt vmcs(value)
Packit b1f7ae
Packit b1f7ae
Value is the VMCS base address.  Beware that only bits 12 to 51 will be used.
Packit b1f7ae
The rest will be silently ignored.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### mnt
Packit b1f7ae
Packit b1f7ae
    @pt mnt(value)
Packit b1f7ae
Packit b1f7ae
Value is the 8-byte packet payload represented as 64-bit little-endian number.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
#### .exp
Packit b1f7ae
Packit b1f7ae
	@pt .exp([extra])
Packit b1f7ae
Packit b1f7ae
Every occurrence of this directive prints all the lines, following this
Packit b1f7ae
directive, to a `file[-extra].exp`.
Packit b1f7ae
Packit b1f7ae
The first occurrence of this directive stops processing of other directives.
Packit b1f7ae
Packit b1f7ae
In order to have a valid yasm file, it is necessary to put the expected output
Packit b1f7ae
into yasm comments (with the semi-colon character (`;`)). Any character up to
Packit b1f7ae
(and including) the semi-colon is not printed to the `.exp` file. Trailing white
Packit b1f7ae
space is removed from each line.
Packit b1f7ae
Packit b1f7ae
Comments are made with the `#` character and go to the end of line.  Comments
Packit b1f7ae
and whitespace before comments are not printed in the `.exp` file.
Packit b1f7ae
Packit b1f7ae
Each line that contains no yasm comment at all is not printed to the exp file.
Packit b1f7ae
Empty lines can be used to structure the expected output text.
Packit b1f7ae
Packit b1f7ae
In `.exp` files, the address of a yasm label can be substituted using:
Packit b1f7ae
Packit b1f7ae
	%[?0]label[.<number>].
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
Labels are prefixed with `%`, for example, `%%label`.  A label name can consist
Packit b1f7ae
of alphanumeric characters and underscores.  Labels must be unique.  The address
Packit b1f7ae
of label will be substituted with a hex number including leading `0x`.
Packit b1f7ae
Packit b1f7ae
Prefixing the label with `0`, for example `%0label`, prints the address with
Packit b1f7ae
leading zeroes using 16 hex digits plus the leading `0x`.
Packit b1f7ae
Packit b1f7ae
The least significant `n` bytes of an address can be masked by appending `.n` to
Packit b1f7ae
the label.  For example, `%%label.2` with `label` = `0xffffff004c` is printed as
Packit b1f7ae
`0x4c`.
Packit b1f7ae
Packit b1f7ae
Prefixing the label with `?` in combination with masking replaces the masked out
Packit b1f7ae
parts with `?` using 16 digits for the address plus the leading `0x`.  The
Packit b1f7ae
remaining number is zero extended.  For example, `%?label.2` with `label` =
Packit b1f7ae
`0xc0001` is printed as `0x????????????0001`.
Packit b1f7ae
Packit b1f7ae
The packet number of pt directives can also be substituted in the output. These
Packit b1f7ae
numbers are printed in decimal. The syntax is as follows:
Packit b1f7ae
Packit b1f7ae
	%label
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
### Special Labels
Packit b1f7ae
Packit b1f7ae
There is a special label for the byte offset after the last packet: `%%eos`.
Packit b1f7ae
Packit b1f7ae
Packit b1f7ae
Labels in sections are relative to the section's vstart address.  PTTC also adds
Packit b1f7ae
the following special section labels:
Packit b1f7ae
Packit b1f7ae
 * *section_<name>_start*   gives the section's offset in the binary file
Packit b1f7ae
 * *section_<name>_vstart*  gives the virtual base address of the mapped section
Packit b1f7ae
 * *section_<name>_length*  gives the size of the section in bytes
Packit b1f7ae
Packit b1f7ae
Beware that PTTC does not support switching back and forth between sections.