|
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 |
#ifndef PARSE_H
|
|
Packit |
b1f7ae |
#define PARSE_H
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
#include "yasm.h"
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
#include "intel-pt.h"
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
#include <inttypes.h>
|
|
Packit |
b1f7ae |
#include <stdio.h>
|
|
Packit |
b1f7ae |
#include <stdlib.h>
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Represents the parser. */
|
|
Packit |
b1f7ae |
struct parser {
|
|
Packit |
b1f7ae |
/* File pointer to the trace output file. */
|
|
Packit |
b1f7ae |
FILE *ptfile;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Filename of the trace output file. The filename is
|
|
Packit |
b1f7ae |
* determined from the .asm file given during p_alloc.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
char *ptfilename;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* The yasm structure, initialized with pttfile in p_alloc. */
|
|
Packit |
b1f7ae |
struct yasm *y;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Current pt directive. */
|
|
Packit |
b1f7ae |
struct pt_directive *pd;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* The encoder configuration, passed during p_alloc. */
|
|
Packit |
b1f7ae |
const struct pt_config *conf;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Labels for @pt directives. */
|
|
Packit |
b1f7ae |
struct label *pt_labels;
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Number of bytes written to pt file. */
|
|
Packit |
b1f7ae |
int pt_bytes_written;
|
|
Packit |
b1f7ae |
};
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Instantiates a parser and starts parsing of @pttfile and writes PT
|
|
Packit |
b1f7ae |
* stream using @conf.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse(const char *pttfile, const struct pt_config *conf);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses an empty payload.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode othewise.
|
|
Packit |
b1f7ae |
* Returns -err_parse_trailing_tokens if @payload has non whitespace
|
|
Packit |
b1f7ae |
* characters.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_empty(char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses tnt @payload. Takens are expressed with 't' and Not-Takens
|
|
Packit |
b1f7ae |
* with 'n'. The t's and n's can be separated with spaces, periods or
|
|
Packit |
b1f7ae |
* directly concatenated.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* On success the TNT bitfield will be stored in the location of @tnt; the
|
|
Packit |
b1f7ae |
* number of T's and N's is stored in the location of @size.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @payload or @tnt or @size is the NULL
|
|
Packit |
b1f7ae |
* pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_unknown_char if there is an unrecognized character
|
|
Packit |
b1f7ae |
* in the payload.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_tnt(uint64_t *tnt, uint8_t *size, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses an address and a ipc from @payload and stores it in the
|
|
Packit |
b1f7ae |
* location of @ip and @ipc respectively. The ipc is separated from the
|
|
Packit |
b1f7ae |
* address with space or comma.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @p or @ip or @ipc is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if ip or ipc in the @payload could not be
|
|
Packit |
b1f7ae |
* parsed as integer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_ipc if the ipc argument is missing or malformed.
|
|
Packit |
b1f7ae |
* Returns -err_parse_trailing_tokens if the @payload contains more than
|
|
Packit |
b1f7ae |
* 2 arguments.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_ip(struct parser *p, uint64_t *ip,
|
|
Packit |
b1f7ae |
enum pt_ip_compression *ipc, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses a uint64_t value from @payload and stores it in the memory
|
|
Packit |
b1f7ae |
* location where @x points to.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @x is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_no_args if @payload contains no arguments.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if @payload cannot be parsed as integer.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_uint64(uint64_t *x, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses a uint8_t value from @payload and stores it in the memory
|
|
Packit |
b1f7ae |
* location where @x points to.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @x is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_no_args if @payload contains no arguments.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if @payload cannot be parsed as integer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int_too_big if the integer parsed from @payload
|
|
Packit |
b1f7ae |
* cannot be represented in uint8_t.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_uint8(uint8_t *x, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses a uint16_t value from @payload and stores it in the memory
|
|
Packit |
b1f7ae |
* location where @x points to.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @x is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_no_args if @payload contains no arguments.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if @payload cannot be parsed as integer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int_too_big if the integer parsed from @payload
|
|
Packit |
b1f7ae |
* cannot be represented in uint16_t.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_uint16(uint16_t *x, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses a uint32_t value from @payload and stores it in the memory
|
|
Packit |
b1f7ae |
* location where @x points to.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @x is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_no_args if @payload contains no arguments.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if @payload cannot be parsed as integer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int_too_big if the integer parsed from @payload
|
|
Packit |
b1f7ae |
* cannot be represented in uint32_t.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_uint32(uint32_t *x, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
/* Parses the comma-separated ctc and fc arguments of a tma packet.
|
|
Packit |
b1f7ae |
*
|
|
Packit |
b1f7ae |
* Returns 0 on success; a negative enum errcode otherwise.
|
|
Packit |
b1f7ae |
* Returns -err_internal if @ctc or @fc is the NULL pointer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_int if ctc or fc in the @payload could not be
|
|
Packit |
b1f7ae |
* parsed as integer.
|
|
Packit |
b1f7ae |
* Returns -err_parse_trailing_tokens if the @payload contains more than
|
|
Packit |
b1f7ae |
* 2 arguments.
|
|
Packit |
b1f7ae |
*/
|
|
Packit |
b1f7ae |
extern int parse_tma(uint16_t *ctc, uint16_t *fc, char *payload);
|
|
Packit |
b1f7ae |
|
|
Packit |
b1f7ae |
#endif /* PARSE_H */
|