summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick Williams <iawillia@us.ibm.com>2011-01-10 19:44:39 -0600
committerPatrick Williams <iawillia@us.ibm.com>2011-01-10 19:44:39 -0600
commitfaa71280d086246c685a23f2acb2330981253f8c (patch)
tree3a4a6a05ff5e4e962267155edcd6025a52aa0b3e /src
parent9fb915bfdc1165bd645c25619623c677b00432b4 (diff)
downloadtalos-hostboot-faa71280d086246c685a23f2acb2330981253f8c.tar.gz
talos-hostboot-faa71280d086246c685a23f2acb2330981253f8c.zip
Importing trace header files from FSP trace and integrating into build.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/build/trace/tracepp397
-rwxr-xr-xsrc/build/trace/trexhashbin0 -> 11316 bytes
-rw-r--r--src/include/trace_adal.h249
-rw-r--r--src/include/tracinterface.H315
-rw-r--r--src/kernel/makefile2
-rw-r--r--src/lib/makefile2
-rw-r--r--src/libc++/makefile2
-rw-r--r--src/sys/init/makefile2
-rw-r--r--src/sys/vfs/makefile2
-rw-r--r--src/usr/example/example.C2
-rw-r--r--src/usr/example/makefile2
11 files changed, 969 insertions, 6 deletions
diff --git a/src/build/trace/tracepp b/src/build/trace/tracepp
new file mode 100755
index 000000000..6922a4216
--- /dev/null
+++ b/src/build/trace/tracepp
@@ -0,0 +1,397 @@
+#!/usr/bin/perl -w
+use strict;
+use File::Basename;
+
+# *** tracepp - a fsp/common Linux trace pre processor
+# this one replaces the trace strings by the corresponding hash value
+# (i.e. the complete call to trace_adal_hash is replaced)
+
+# *** Usage
+#
+# prepend compiler call with the call of this pre processor, i.e if you have
+# $(CC) $(CFLAGS) -o $@ $<
+# in your Makefile change it to this:
+# tracepp $(CC) $(CFLAGS) -o $@ $<
+# tracepp will use "$(CC) -E" to call the C pre processor "cpp".
+# you can set a env var "REALCPP" to the name of a program to select
+# a different programm as cpp
+#
+# tracepp creates a file "$target.hash" with the trace strings and the hash values.
+#
+# to enable debug mode set envvar TRACEPPDEBUG to 1 or give '-d' as first arg
+
+# *** Change History
+#
+# 2003-02-26 RBa created from scratch
+# 2003-02-28 RBa add C++ support (C++ interface uses own type for the hash)
+# 2003-05-28 RBa if cc should link instead of compile just call compiler
+# 2003-07-11 AGe Change search alg. slightly and put just format back
+# 2003-07-25 RBa just call gcc if called to link instead to compile
+# eat argument for option -x
+# 2003-11-26 RBa fix c/c++ algo: compile as c++ if realcc=*g++
+# 2004-02-02 RBa remove explicit test whether source file is readable
+# it is obsolete and might lead to an error if afs is used
+# 2004-02-13 RBa add support for dependency generation (-MD/-MG, -MF)
+# don't prepend './' to object filename
+# 2006-04-19 RBa rewrite trace_adal_write_all support, handle C and C++ the same
+# 2006-05-24 RBa fix handling of missing -o ; add TRAC_PPVER for macro/API version
+# 2006-09-15 RBa add handling of \" in trace format strings ; reduce non-error output
+# put object file in current dir if no -o given
+# 2007-03-22 RBa handle more gcc options (-i) ; protect " in call to shell
+# store output of cpp as "unmodified" output for debug
+# only write string/hash file if strings found
+
+my $debug = 0;
+if (exists $ENV{TRACEPPDEBUG}) {
+ $debug = $ENV{TRACEPPDEBUG};
+}
+
+my $version = '$Id: tracepp,v 1.8 2007/06/22 13:37:17 fldbuild Exp $';
+$version =~ s/^.*(\d+(\.\d+)+).*$/$1/;
+# api/macro version. to #error if macro and tracepp doesn't fit
+my $macro_version = '1';
+
+sub parse_line($$);
+sub get_has($$);
+
+if (@ARGV == 0 || (@ARGV == 1 && lc($ARGV[0]) eq '-h') ) {
+ print STDERR "usage: $0 realcompiler compileroptions -o target source\n";
+ exit 127;
+}
+my $realcc = shift @ARGV;
+my $cctype = 'c++';
+my $optx_found = 0;
+
+if ($realcc eq '-d') {
+ $debug = 1;
+ $realcc = shift @ARGV;
+}
+
+# wait until -d options is handled before checking $debug
+print STDERR "tracepp version $version - API/macro version $macro_version\n" if $debug;
+
+my $realcpp = $ENV{REALCPP};
+if (!$realcpp) {
+ print STDERR "cannot find cpp, using \<realcompiler\> -E'\n" if $debug;
+ $realcpp = "$realcc -E";
+}
+print "realcpp is $realcpp\n" if $debug;
+
+my $opt;
+my ($source, $object, @ccopts, @cppopts);
+my $dodeps = 0;
+my $depfile;
+my @origargs = @ARGV;
+while(defined($opt = shift @ARGV)) {
+ if ($opt =~ m/^-o(.*)$/) {
+ if (defined $object) {
+ print STDERR "two -o options, aborting\n";
+ exit 1;
+ }
+ if ($1) {
+ $object = $1;
+ } else {
+ $object = shift @ARGV;
+ }
+ print "object is now $object\n" if $debug;
+ } elsif ($opt eq '-c') {
+ # don't call cpp with -c, this is for the compiler
+ #push @cppopts, $opt;
+ push @ccopts, $opt;
+ print "found -c option\n" if $debug;
+ } elsif ($opt =~ m/^-l/) {
+ # cpp doesn't need library arguments
+ push @ccopts, $opt;
+ } elsif ($opt =~ m/^-i./) {
+ # option takes an argument, handle it too
+ my$optarg = shift @ARGV;
+ push @ccopts, $opt, $optarg;
+ push @cppopts, $opt, $optarg;
+ print "found option '$opt $optarg'\n" if $debug;
+ } elsif ($opt =~ m/^-[LIxbBVD]$/ || $opt eq '--param' || $opt =~ m/^-M[QT]$/) {
+ # option takes an argument, handle it too
+ my $optarg = shift @ARGV;
+ push @ccopts, $opt, $optarg;
+ push @cppopts, $opt, $optarg;
+ print "found option '$opt $optarg'\n" if $debug;
+ if ($opt eq '-x') {
+ # option x sets the language - c or c++
+ if ($optarg ne 'c' and $optarg ne 'c++') {
+ print STDERR "cannot process language '$optarg', aborting\n";
+ exit 1;
+ }
+ $cctype = $optarg;
+ $optx_found = 1;
+ }
+ } elsif ($opt eq '-MD' or $opt eq '-MG') {
+ # gen deps
+ $dodeps = 1;
+ print "found $opt, creating dependencies\n" if $debug;
+ } elsif ($opt eq '-MF') {
+ # set dependencies file
+ $depfile = shift @ARGV;
+ print "set dependencies file to '$depfile'\n" if $debug;
+ } elsif ($opt =~ m/^-/) {
+ # arg starts with - so it's an option
+ push @ccopts, $opt;
+ push @cppopts, $opt;
+ print "found option '$opt'\n" if $debug;
+ } elsif ($opt =~ m/\.[ao]$/) {
+ # an object or archive, ignore this but give it to cc
+ push @ccopts, $opt;
+ print "found object/archive '$opt'\n" if $debug;
+ } elsif ($opt =~ m/\.c[xp]*$/i) {
+ # the source file(s). we should only get one
+ if (defined $source) {
+ print STDERR "don't know to handle two source files, aborting\n";
+ exit 1;
+ }
+ $source = $opt;
+ # put the - (for read-from-stdin) where the source file was
+ # (order is important!)
+ push @ccopts, "-";
+ print "found source file $source\n" if $debug;
+ } elsif (!-f $opt) {
+ # option but not a file, an unknown option?
+ push @ccopts, $opt;
+ push @cppopts, $opt;
+ print "found unknown option '$opt'\n" if $debug;
+ }
+}
+
+if (!defined $source) {
+ # this might be a call to link a program instead of compile a source (or asm source)
+ print "NOTME: starting as cc '$realcc @origargs'\n" if $debug;
+ exec($realcc, @origargs) || die "cannot exec $realcc\n";
+}
+if (!defined $object) {
+ print STDERR "no object file given, default to source name\n" if $debug;
+ # gcc builds object name from source name if no -o given, replacing
+ # suffix with .o. The file is placed in the current directory,
+ # not in the source directory!
+ my ($n,$d,$s) = fileparse($source, qr{\.[^.]+});
+ if ($n && $s) {
+ $object = "$n.o";
+ print "tracpp: guessing object name $object\n",
+ " from source name $source\n" if $debug;
+ } else {
+ print STDERR "Unable to determine Source File Name\n";
+ exit 1;
+ }
+}
+my $hashtype;
+# set value of trace hash according to language
+# check source file extension if no explicit -x option given
+if (!$optx_found) {
+ if ($realcc =~ m/g\+\+/) {
+ print "compiler language: C++ (from compiler name)\n" if $debug;
+ $cctype = 'c++';
+ } else {
+ if ($source =~ m/\.c$/) {
+ print "compiler language: C (from source file extension)\n"
+ if $debug;
+ $cctype = 'c';
+ } else {
+ print "compiler language: C++ (default)\n" if $debug;
+ $cctype = 'c++';
+ }
+ }
+} else {
+ print "compiler language: $cctype (from option '-x')\n" if $debug;
+}
+
+if ($cctype eq 'c') {
+ $hashtype = 'unsigned long';
+} else {
+ $hashtype = 'trace_hash_val';
+}
+# define TRAC_TRACEPP for macros
+push(@cppopts,"-DTRAC_TRACEPP -DTRAC_PPVER=$macro_version");
+if ($dodeps) {
+ if (!defined $depfile) {
+ if (exists $ENV{DEPENDENCIES_OUTPUT}) {
+ $depfile = $ENV{DEPENDENCIES_OUTPUT};
+ } elsif (exists $ENV{SUNPRO_DEPENDENCIES}) {
+ $depfile = $ENV{SUNPRO_DEPENDENCIES};
+ } else {
+ ($depfile = $object) =~ s/.o$/.d/;
+ }
+ }
+ push @cppopts, "-MD -MF $depfile";
+}
+# start cpp.
+print "starting as cpp '$realcpp @cppopts $source -o-'\n" if $debug;
+if (!open(CPP, "$realcpp @cppopts $source -o-|")) {
+ print STDERR "cannot start cpp '$realcpp'\n";
+ perror("");
+ exit 1;
+}
+# start cc. manually set language as source file extension not available to cc
+my $type_str = '';
+if ($optx_found == 0) {
+ # no option -x given by caller, set manually
+ $type_str = "-x $cctype";
+}
+print "starting as cc '$realcc $type_str @ccopts -o $object'\n" if $debug;
+if (!open(CC, "| $realcc $type_str @ccopts -o $object")) {
+ print STDERR "cannot start cc '$realcc'\n";
+ perror("");
+ exit 1;
+}
+
+my $modifiedfile = 0;
+my $unmodifiedfile = 0;
+if ($debug) {
+ $modifiedfile = $object . ".debug";
+ if (!open(DEBUG, ">$modifiedfile")) {
+ perror("cannot open file $modifiedfile");
+ $modifiedfile = 0;
+ } else {
+ print STDERR "writing preprocessed source to $modifiedfile\n";
+ }
+ $unmodifiedfile = $object . ".debug_in";
+ if (!open(DEBUGIN, ">$unmodifiedfile")) {
+ perror("cannot open file $unmodifiedfile");
+ $unmodifiedfile = 0;
+ } else {
+ print STDERR "writing unprocessed source to $unmodifiedfile\n";
+ }
+}
+
+my %hashtab;
+my $oldline;
+while(defined($oldline = <CPP>)) {
+ print DEBUGIN $oldline if $unmodifiedfile;
+ my $newline = parse_line(\%hashtab, $oldline);
+ #print "oldline = $oldline";
+ #print "newline = $newline";
+ if (!defined $newline) {
+ print STDERR "hash error in/with file $source\n";
+ exit 1;
+ }
+ #print "newline = $newline\n";
+ print CC $newline;
+ print DEBUG $newline if $modifiedfile;
+}
+if ($modifiedfile) {
+ close DEBUG;
+}
+if ($unmodifiedfile) {
+ close DEBUGIN;
+}
+if (!close(CPP) || ($? >> 8 != 0)) {
+ print STDERR "error from cpp\n";
+ if ($? & 127) {
+ print STDERR "cpp got signal ",$? & 127,"\n";
+ exit 1;
+ } elsif ($? >> 8) {
+ print STDERR "cpp returned ",$? >> 8,"\n";
+ exit $? >> 8;
+ }
+}
+if (!close(CC) || ($? >> 8 != 0)) {
+ print STDERR "error from cc\n";
+ if ($? & 127) {
+ print STDERR "cc got signal ",$? & 127,"\n";
+ exit 1;
+ } elsif ($? >> 8) {
+ print STDERR "cc returned ",$? >> 8,"\n";
+ exit $? >> 8;
+ }
+}
+if (%hashtab) {
+ my $stringfile = "$object.hash";
+ # open trace string file
+ if (!open(TRC, ">$stringfile")) {
+ print STDERR "cannot write trace string file '$stringfile'\n";
+ exit 1;
+ }
+ print "Writing to file $stringfile\n" if $debug;
+
+ printf TRC "#FSP_TRACE_v2|||%s|||BUILD:%s",scalar(localtime()),`pwd`;
+ foreach my $key (keys %hashtab) {
+ if ($hashtab{$key} =~ m/\|\|$source$/) {
+ # source file name is already part of the string
+ print TRC "$key||$hashtab{$key}\n";
+ } else {
+ print TRC "$key||$hashtab{$key}||$source\n";
+ }
+ #print TRC "$key||$source||$hashtab{$key}\n";
+ }
+ close TRC;
+} else {
+ print "No trace calls/strings found, not writing hash file\n" if $debug;
+}
+exit 0;
+
+sub parse_line($$)
+{
+ my ($rhash, $line) = @_;
+ my $format;
+ my $tmp_strng;
+ my @format_param = ();
+ my $data;
+ my $hash;
+ my $newline = '';
+ my $write_all_suffix;
+ my ($prefix, $strings, $salt, $suffix);
+ # trace_adal_hash ( "..." ".." "..." , 2 )
+ # regex: PREFIX 'trace_adal_hash' space '(' space STRINGS space ',' space NUMBER space ')' SUFFIX
+ # STRINGS: '"' .* '"' space? +
+ while($line =~ m/^(.*?)trace_adal_hash\s*\(\s*((".*?(?<!\\)"\s*)+),\s*(-?\d+)\s*\)(.*)$/) {
+ ($prefix, $strings, $salt, $suffix) = ($1, $2, $4, $5);
+ print "\n\nprefix = $prefix\nstrings = $strings\nsalt = $salt\nsuffix = $suffix\n" if $debug;
+ $strings =~ s/^"//;
+ $strings =~ s/"\s*$//;
+ $strings =~ s/"\s*"//g;
+ $strings =~ s/\\"/"/g; # remove \ from \"
+ # is this a trace_adal_write_all call?
+ if ($prefix =~ m/trace_adal_write_all\s*\(/) {
+ # yes. replace trace_adal_hash with hash value and reduced format string
+ (@format_param) = ($strings =~ /(%[#0\- +'I]*\d*(?:\.\d*)?[hlLqjzt]*[diouxXeEfFgGaAcsCSpn])/g);
+ $format = join(',', @format_param);
+ # reduced format string will be added after hash value
+ $write_all_suffix = '," ' . $format . '"';
+ if ($salt == -1) {
+ $salt = scalar(@format_param);
+ } elsif ($salt != scalar(@format_param)) {
+ print STDERR ("printf % mismatch in '$line': TRACE says $salt, format says ",
+ scalar(@format_param), " args\n");
+ }
+ } else {
+ $write_all_suffix = '';
+ }
+ $hash = get_hash($strings, $salt);
+ if (exists $$rhash{$hash} && $$rhash{$hash} ne $strings) {
+ print STDERR "hash collision: two different strings give the same hash value '$hash'\n",
+ $strings, "\n", $$rhash{$hash}, "\n";
+ return undef;
+ }
+ $$rhash{$hash} = $strings;
+ $newline .= $prefix . "(($hashtype) ${hash}U)$write_all_suffix";
+ print "changed call: $prefix(($hashtype) ${hash}U)$write_all_suffix...\n" if $debug;
+ $line = $suffix;
+ }
+ $newline .= $line if $line;
+ $newline .= "\n" unless $newline =~ m/\n$/;
+ return $newline;
+}
+
+sub get_hash($$)
+{
+ my ($string, $salt) = @_;
+ $string =~ s/([\\"])/\\$1/g;
+ my $hash = `trexhash "$string" $salt`;
+ chomp $hash;
+ if ($hash !~ m/^\d+$/) {
+ print STDERR "trexhash error: $hash\n";
+ print STDERR "for call <<trexhash \"$string\" $salt>>\n";
+ die "$!";
+ }
+ if (!$hash) {
+ for (my $i=0; $i < length($string); $i++) {
+ $hash += ord(substr($string, $i, 1));
+ }
+ }
+ return $hash;
+}
diff --git a/src/build/trace/trexhash b/src/build/trace/trexhash
new file mode 100755
index 000000000..9fd2cae77
--- /dev/null
+++ b/src/build/trace/trexhash
Binary files differ
diff --git a/src/include/trace_adal.h b/src/include/trace_adal.h
new file mode 100644
index 000000000..481393bd2
--- /dev/null
+++ b/src/include/trace_adal.h
@@ -0,0 +1,249 @@
+/******************************************************************************
+ * IBM Confidential
+ *
+ * Licensed Internal Code Source Materials
+ *
+ * IBM Flexible Support Processor Licensed Internal Code
+ *
+ * (c) Copyright IBM Corp. 2004, 2009
+ *
+ * The source code is for this program is not published or otherwise divested
+ * of its trade secrets, irrespective of what has been deposited with the
+ * U.S. Copyright Office.
+ *****************************************************************************
+ * \file trace_adal.h
+ * \brief Contains header data for trace component..
+ *
+ * The trace component allows an application to trace its execution into
+ * circular buffers (like a flight recorder) with low performance and
+ * memory usage impact. This implementation focuses on the Linux operating
+ * system running on embedded controllers.
+ *
+ * \note Please see the document trace_doc.lyx for full documentation on this
+ * \note component.
+ *****************************************************************************/
+
+
+#ifndef _TRACE_ADAL_H
+#define _TRACE_ADAL_H
+
+#include <stdint.h>
+
+/**
+ * @brief Maximum size of component name
+ * @note Make sure to also change in include/linux/trac.h -
+ * TRACER_FSP_TRACE_NAME_SIZE
+*/
+#define TRACE_MAX_COMP_NAME_SIZE 16
+
+#define TRACE_DEBUG_ON 1 //Set to this when debug trace on
+#define TRACE_DEBUG_OFF 0 //Set to this when debug trace off
+#define TRACE_DEBUG 1 //Pass this when trace is debug
+#define TRACE_FIELD 0 //Pass this when trace is field
+
+#define TRACE_COMP_TRACE 0x434F //Identifies trace as a component trace (printf)
+#define TRACE_BINARY_TRACE 0x4249 //Identifies trace as a binary trace
+#define TRACE_INTERNAL_BLOCKED 0xFF42 //Identifies trace as an dd internal trace
+
+#define TRACE_BUFFER_VERSION 1 //Trace buffer version
+#define TRACE_BUFFER_BINARY_VERSION 2 //Trace buffer version when collected by fsp-trace from pipe
+
+#define TRACE_DEFAULT_TD 0 //Default trace descriptor
+
+
+/*
+ * Parsing and output modifier flags
+ */
+
+/* When multiple buffers are given the traces of all buffers are sorted by timestamp and printed as one list.
+ * If this flag is not given the traces are printed separatly for each trace buffers (i.e. grouped by buffer).
+ */
+#define TRACE_MIX_BUFFERS 1
+
+/* Show the name of a trace buffer for each trace. The buffer name will be inserted between timestamp and trace text.
+ * Only one of TRACE_APPEND_BUFFERNAME and TRACE_PREPEND_BUFFERNAME can be given.
+ */
+#define TRACE_PREPEND_BUFFERNAME 2
+
+/* Show the name of a trace buffer for each trace. The buffer name will be appended at the end of the line
+ * (after trace text). Only one of TRACE_APPEND_BUFFERNAME and TRACE_PREPEND_BUFFERNAME can be given.
+ */
+#define TRACE_APPEND_BUFFERNAME 4
+
+/* When set timestamps are translated to timeofday values (date/time). This needs "timeref" to be given.
+ * If timeref is not given the timestamps are treated as if the PPC timebase counter was started at epoch time
+ * (i.e. the printed timestamp will be the time since FSP boot time).
+ */
+#define TRACE_TIMEOFDAY 8
+
+/* If a TIMEREF trace is found in a trace buffer and timeref is a valid
+ * pointer the values from the TIMEREF trace are written to timeref. This flag is independent of TRACE_TIMEOFDAY.
+ */
+#define TRACE_SET_TIMEOFDAY 16
+
+/* Show the name of the source file that contains the trace statement for each trace.
+ * (at the end of the line, after buffer name if this is printed too).
+ */
+#define TRACE_FILENAME 32
+#define TRACE_VERBOSE 64 //some messages are printed to STDERR.
+#define TRACE_IGNORE_VERSION 128
+#define TRACE_OVERWRITE 256
+#define TRACE_BINARY 512
+
+/* When this is set trace pipe isn't turned off after pipe read
+ */
+#define TRACE_DONTSTOP 1024
+
+
+/* MSB of tid field is used as trace-in-irq flag
+ */
+#define TRACE_TID_IRQ (1<<31)
+#define TRACE_TID_TID(tid) ((tid) & ~(TRACE_TID_IRQ))
+
+/*!
+ * @brief Device driver fills in this structure for each trace entry.
+ * It will put this data first in the trace buffer.
+ */
+typedef struct trace_entry_stamp {
+ uint32_t tbh; /*!< timestamp upper part */
+ uint32_t tbl; /*!< timestamp lower part */
+ uint32_t tid; /*!< process/thread id */
+} trace_entry_stamp_t;
+
+
+/*
+ * @brief Structure is used by adal app. layer to fill in trace info.
+ */
+typedef struct trace_entry_head {
+ uint16_t length; /*!< size of trace entry */
+ uint16_t tag; /*!< type of entry: xTRACE xDUMP, (un)packed */
+ uint32_t hash; /*!< a value for the (format) string */
+ uint32_t line; /*!< source file line number of trace call */
+ uint32_t args[0]; /*!< trace args or data of binary trace */
+} trace_entry_head_t;
+
+
+/*
+ * @brief Structure is used to return current components tracing
+ */
+typedef struct trace_buf_list {
+ char name[TRACE_MAX_COMP_NAME_SIZE]; /*!< component name */
+ size_t size; /*!< size of component trace buffer */
+} trace_buf_list_t;
+
+
+typedef int trace_desc_t; //Type definition for users trace descriptor data type
+typedef int tracDesc_t; //Type definition for older trace descriptor type
+typedef unsigned long trace_strings_t; /* type for trace strings */
+
+
+/*
+ * @brief Will use this to hold hash value.
+ *
+ */
+enum trace_hash_val { trace_hash };
+
+/* struct for time */
+struct trace_tbtime {
+ uint32_t high;
+ uint32_t low;
+};
+
+
+/*----------------------------------------------------------------------------*/
+/* Constants */
+/*----------------------------------------------------------------------------*/
+/* only define if not defined by trace_dd.h (make different versions of
+ * these files compatible). check only for one define instead of all */
+#ifndef TRACE_FIELDTRACE
+
+/* a component trace of type field (non-debug): x4654 = "FT" */
+#define TRACE_FIELDTRACE 0x4654
+/* a component trace of type debug: x4454 = "DT" */
+#define TRACE_DEBUGTRACE 0x4454
+/* a binary trace of type field (non-debug): x4644 = "FD" */
+#define TRACE_FIELDBIN 0x4644
+/* a binary trace of type debug: x4644 = "DD" */
+#define TRACE_DEBUGBIN 0x4444
+/* a string trace of type field (non-debug): x4653 = "FS" */
+#define TRACE_FIELDSTRING 0x4653
+/* a string trace of type debug: x4453 = "DS" */
+#define TRACE_DEBUGSTRING 0x4453
+
+#endif
+
+/*----------------------------------------------------------------------------*/
+/* Function Prototypes */
+/*----------------------------------------------------------------------------*/
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*!
+ * @brief Initialize a trace buffer for a component.
+ *
+ * @param td Device driver will assign caller a trace descriptor.
+ * @param comp Pointer to 16 character null terminated string.
+ * @param size Requested buffer size.
+ *
+ * @return 0 for success, negative value for failure.
+ * @retval #TRACE_INIT_BUFF_IOCTL_ERR device driver refused to create buffer
+ * @retval #TRACE_INIT_BUFF_NAME_ERR buffer name was too long, a buffer with the
+ name "BADN" was created instead
+ * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
+ */
+int32_t trace_adal_init_buffer(trace_desc_t *,const char *,const size_t);
+
+/*!
+ * @brief Set trace debug level
+ *
+ * @param td Assigned trace descriptor.
+ * @param level If 0 only field traces will be active. If > 0 debug traces
+ * with level <= 'level' will be active.
+ *
+ * @return 0 for success, negative value for failure.
+ * @retval #TRACE_SETDEBUG_IOCTL_ERR error from device driver, errno set
+ * @retval #TRACE_SETDEBUG_INV_PARM_ERR second parm must be TRACE_DEBUG_ON or TRACE_DEBUG_OFF
+ * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
+ */
+int32_t trace_adal_setdebug(const trace_desc_t, const int32_t);
+
+/*!
+ * @brief Write some data to trace buffer.
+ *
+ * @param td Assigned trace descriptor.
+ * @param debug Is it a debug trace or field.
+ * @param size Size of data.
+ * @param data Data to write to buffer.
+ * @param size2 Size of second data block.
+ * @param data2 Second data block to write to buffer.
+ *
+ * @return 0 for success, negative value for failure.
+ * @retval #TRACE_WRITE_IOCTL_ERR error from device driver, errno set
+ * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
+ */
+int32_t trace_adal_write2(const trace_desc_t, const int32_t,
+ const size_t,const void *,const size_t,const void *);
+
+/*!
+ * @brief Write trace data (can handle all data types)
+ *
+ * @return 0 for success, negative value for failure.
+ * @retval #TRACE_WRITE_ALL_IOCTL_ERR error from device driver, errno set
+ * @retval #TRACE_WRITE_NOT_INIT trying to trace without device driver
+ * @retval #TRACE_THREAD_LOCK_FAIL error locking thread lock
+ * @retval #TRACE_THREAD_UNLOCK_FAIL error unlocking thread lock
+ * @retval #TRACE_INIT_FD_ERR cannot open trace device (module not loaded?), errno set
+ * @retval #TRACE_WRITE_ALL_BAD_TD bad trace descriptor
+ */
+int32_t trace_adal_write_all(const trace_desc_t i_td,const enum trace_hash_val i_hash,
+ const char *i_fmt,
+ const uint32_t i_line, const int32_t i_type,...)
+ __attribute__ ((format (printf, 3, 6)));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/include/tracinterface.H b/src/include/tracinterface.H
new file mode 100644
index 000000000..a6d885314
--- /dev/null
+++ b/src/include/tracinterface.H
@@ -0,0 +1,315 @@
+/******************************************************************************
+ * IBM Confidential
+ *
+ * Licensed Internal Code Source Materials
+ *
+ * IBM Flexible Support Processor Licensed Internal Code
+ *
+ * (c) Copyright IBM Corp. 2004, 2010
+ *
+ * The source code is for this program is not published or otherwise divested
+ * of its trade secrets, irrespective of what has been deposited with the
+ * U.S. Copyright Office.
+ *****************************************************************************/
+
+#ifndef TRACINTERFACE_H
+#define TRACINTERFACE_H
+
+/*!@file tracinterface.H
+ * @brief Contains macros for trace interface
+ *
+ * This header file provides a common interface for the Trace
+ * mechanism. Trace is a way for developers to debug their code. They
+ * can use the trace Macro's to write to standar out, to wraparound files and
+ * to a wraparound buffer which will be stored in shared memory.
+ *
+ * There are two types of trace, debug and field, that you can use when tracing.
+ * Debug traces will be compiled out of the code when the system is released to the field.
+ * Field traces will be remain in the code permenantly.
+ *
+ * TRACxSYSn calls will always go to syslog
+ *
+ * There are three different environments trace will operate in.
+ *
+ * Unit Test / Simulation: All component traces (debug and field) are sent to standard out by default.
+ * The developer has the option to do define an evironmental variable:
+ * 'export FIPS_TRACE_PATH="<path>"' where path is the location to write the files (ex. "./").
+ *
+ * Lab: All component traces will, by default, follow the same implementation as the
+ * Unit Test / Simulation env. However, drivers flashed onto the system (built by the
+ * build team) will use the memory wrapping implementation. Code built in a local
+ * sandbox will continue to use the file wrapping implementation. This will give
+ * the developer the speed of the memory wrapping trace (for code they don't really
+ * care about) and ease of debug with the file wrapping code (for their own code).
+ *
+ * Field: Only component traces of type field will be sent to the shared memory wraparound
+ * buffer. Debug traces will be compiled out of the code.
+ *
+ * In Unit Test / Simulation, The file will have the name "trac" + 'component name'.
+ * For example the error logger component would be <path>/tracERRL
+*/
+/* Change Log *****************************************************************/
+/* */
+/* ch# Feat/def# Userid Date Description */
+/* --- ---------- -------- -------- ----------------------------------------*/
+/* 00 N/A andrewg 08/27/01 Created */
+/* 01 N/A andrewg 10/03/01 Removed duplicate copyright and other housekeeping */
+/* 02 N/A andrewg 10/17/01 Added deallocateBuffer flag to TRAC_FREE_BUFFER */
+/* 03 N/A andrewg 10/19/01 Added 'using namespace std;', vector.h -> vector */
+/* included iostream.h, printf bug. */
+/* 04 354052 andrewg 11/09/01 Took out file writing portion, only go to printf */
+/* ag05 354388 andrewg 11/14/01 Changed binary macro name and added typedef */
+/* ag06 354696 andrewg 11/19/01 Removed ag05 change flags, causing errors */
+/* n/a 355095 andrewg 11/28/01 Put common.h include first */
+/* ag07 354971 andrewg 11/28/01 Added file wrapping code */
+/* ag08 359225 andrewg 02/11/01 Added memory wrapping code, removed USE_PRINTF defined flag */
+/* ag09 360869 andrewg 03/04/02 Added persistant writing macro */
+/* ag10 361649 andrewg 03/08/02 Added the constants */
+/* n/a 363697 andrewg 03/28/02 Modified to use new file object */
+/* n/a 376324 andrewg 07/24/02 Fixed bad define of TRACDCOMP9 */
+/* ag11 382759 andrewg 09/09/02 Support compile flag to remove debug trace */
+/* n/a 385314 andrewg 09/27/02 Remove use of STL */
+/* n/a 388981 andrewg 11/12/02 Add new static variable constructor */
+/* n/a HBIBASE iawilllia 10/05/10 Removed a lot of stuff for HBI trace base. */
+/* End Change Log *************************************************************/
+
+//--------------------------------------------------------------------//
+// Constants //
+//--------------------------------------------------------------------//
+#define ENTER_MRK ">>" // -- ag10
+#define EXIT_MRK "<<" // -- ag10
+#define ERR_MRK "E>" // -- ag10
+#define INFO_MRK "I>" // -- ag10
+#define ARG_MRK "A>" // -- ag10
+
+#ifndef NFP_CLIENT // dc99
+#include <stdint.h>
+#include <trace_adal.h>
+#else
+typedef int tracDesc_t;
+typedef int trace_desc_t;
+#endif
+
+#if( defined(NFP_LIBRARY) || defined(NFP_CLIENT) ) // dc99
+
+#define TRACSCOMP(des,printf_string,args...) do {} while(0)
+#define TRACDCOMP(des,printf_string,args...) do {} while(0)
+#define TRACDBIN(des,descString,address,length) do {} while(0)
+
+#define TRACFCOMP(des,printf_string,args...) \
+ printf(printf_string "\n", ##args)
+#define TRACFBIN(des,descString,address,length) \
+ printf("%s pointer:%p size:%d\n",descString,address,length)
+
+#define TRAC_INIT_BUFFER(des,comp_name, bufferSize) \
+ *(des) = 1
+
+#define TRAC_INIT(des,comp_name, bufferSize)
+
+#define TRAC_FREE_BUFFER(des,deallocateBuff) do {} while(0)
+
+#else
+
+// check compatibility of header file/macros and preprocessor tracepp
+// if tracepp was used
+#define TRAC_MACROVER 1
+#ifdef TRAC_TRACEPP
+#if !defined(TRAC_PPVER)
+#warning fsptrace preprocessor version unknown, might be incompatible with header file
+#elif TRAC_PPVER < TRAC_MACROVER
+#error fsptrace header file version and preprocessor version dont fit
+#endif
+#endif
+
+//------------------------------------------------------------------------------
+// INCLUDES
+//------------------------------------------------------------------------------
+
+#include <trace_adal.h>
+
+/* for any trace_adal_write_all call we need the printf_string in addition to
+ * the hash value. if tracepp is used it will add a (shortened) printf string,
+ * otherwise the macros has to add it
+ */
+
+#ifdef TRAC_TRACEPP
+#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num)
+#else
+#define __ALL_HASH(printf_string,num) trace_adal_hash(printf_string,num),printf_string
+#endif
+
+#ifdef TRAC_DEBUG_OUT /* compile out everyones debug traces */
+
+#define TRACDCOMP(des,printf_string,args...) do {} while(0)
+#define TRACDBIN(des,descString,address,length) do {} while(0)
+
+#else /* direct them to real function calls */
+
+/**
+ @fn void TRACDCOMP0(des, printf_string)
+ @brief Defines all Debug Component Traces
+
+ The user can pass 0 to 9 parameters to the macro. In the field environment,
+ these trace calls will be compiled out of the code. Use these for early bringup
+ needs. These trace calls are written to a memory buffer.
+ @note If you are passing parameters then make sure 'printf_string' has the
+ @note necessary parameter formatting i.e. 'p1' = "hello" make sure
+ @note 'printf_string' has "%s" somewhere in it to corretcly format p1.
+ @return void The user will not be impacted by the failure of this function
+ @param des This is assigned by TRAC_INIT_BUFFER
+ @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
+ @param p1,p2... Optional parameters
+*/
+
+/* a macro w/o the param number suffix. number is calculated from printf string */
+#define TRACDCOMP(des,printf_string,args...) \
+ trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_DEBUG, ##args)
+
+/**
+ @fn void TRACDBIN(des,descString,address,length)
+ @brief Defines debug binary trace
+
+ The binary trace should be used to write out a section of memory. The debug
+ binary trace will be compiled out in the field environment so only use for early
+ bringup debug. When this is being written to a file, it will be displayed in
+ hexidecimal.
+ @return void The user will not be impacted by the failure of this function
+ @param des This is assigned by TRAC_INIT_BUFFER
+ @param descString A string that will be put in front of the binary dump, developer assigns anything they want.
+ @param address Address of beginning of data to dump.
+ @param length lenght of the binary data.
+*/
+#define TRACDBIN(des,descString,address,len) \
+ do{ trace_entry_head_t __e; \
+ __e.tag = TRACE_DEBUGBIN; \
+ __e.line = __LINE__; \
+ __e.length = (len); \
+ __e.hash = trace_adal_hash(descString, 0); \
+ trace_adal_write2((des), TRACE_DEBUG, sizeof(trace_entry_head_t), &__e, \
+ (uint32_t) (__e.length), (uint32_t *) (address)); \
+ } while(0)
+
+#endif /* TRAC_DEBUG_OUT */
+
+/**
+ @fn void TRACFCOMP0(des, printf_string)
+ @brief Defines all Field Component Traces
+
+ The user can pass 0 to 9 parameters to the macro. These trace calls will
+ always be written to the trace memory buffer.
+ @note If you are passing parameters then make sure 'printf_string' has the
+ @note necessary parameter formatting
+ @note i.e. 'p1' = "hello" make sure 'printf_string' has "%s" somewhere in
+ @note it to corretcly format p1.
+ @return void The user will not be impacted by the failure of this function
+ @param des This is assigned by TRAC_INIT_BUFFER
+ @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
+ @param p1,p2... Optional parameters
+*/
+
+/* a macro w/o the param number suffix. number is calculated from printf string */
+#define TRACFCOMP(des,printf_string,args...) \
+ trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_FIELD, ##args)
+
+/**
+ @fn void TRACSCOMP0(des, printf_string)
+ @brief Defines all Strace Component Traces
+
+ The user can pass 0 to 9 parameters to the macro. These traces will be treated
+ as debug traces but will never be compiled out of the code so that they can always be
+ dynamically turned on/off.
+
+ @note If you are passing parameters then make sure 'printf_string' has the
+ @note necessary parameter formatting i.e. 'p1' = "hello" make sure
+ @note 'printf_string' has '%s' somewhere in it to corretcly format p1.
+ @return void The user will not be impacted by the failure of this function
+ @param des This is assigned by TRAC_INIT_BUFFER
+ @param printf_string string describing the trace entry and providing the formatting flags for any parameters passed.
+ @param p1,p2... Optional parameters
+
+ tracepp replaces trace_adal_hash() with hash value and reduced format string
+*/
+
+/* a macro w/o the param number suffix. number is calculated from printf string */
+#define TRACSCOMP(des,printf_string,args...) \
+ trace_adal_write_all((des),__ALL_HASH(printf_string,-1),__LINE__,TRACE_DEBUG, ##args)
+
+/**
+ @fn void TRACFBIN(des,descString,address,length)
+ @brief Defines field binary trace
+
+ The binary trace should be used to write out a section of memory. The field
+ binary trace will always be logged so use for important information.
+ When this is being written to a file, it will be displayed in hexidecimal.
+ @return void The user will not be impacted by the failure of this function
+ @param des This is assigned by TRAC_INIT_BUFFER
+ @param descString A string that will be put in front of the binary dump, developer assigns anything they want.
+ @param address Address of beginning of data to dump.
+ @param length lenght of the binary data.
+*/
+#define TRACFBIN(des,descString,address,len) \
+ do{ trace_entry_head_t __e; \
+ __e.tag = TRACE_FIELDBIN; \
+ __e.line = __LINE__; \
+ __e.length = (len); \
+ __e.hash = trace_adal_hash(descString, 0); \
+ trace_adal_write2((des), TRACE_FIELD, sizeof(trace_entry_head_t), &__e, \
+ (uint32_t) (__e.length), (uint32_t *) (address)); \
+ } while(0)
+
+
+/**
+ @fn void TRAC_INIT_BUFFER(des,comp_name, bufferSize)
+ @brief Initializes trace buffer for component
+
+ This function must be called before any other trace calls. It
+ initializes a file for the calling component and returns a trace
+ descriptor which is used by the trace calls to find the correct file to write to.
+ @return void The user will not be impacted by the failure of this function. If des is a positive value, success.
+ @param des This is assigned by this function.
+ @param comp_name This is the four character name of the component requesting the trace buffer.
+ @param bufferSize Requested length of the buffer, if 0 is entered the user will get default buffer size.
+*/
+#define TRAC_INIT_BUFFER(des,comp_name, bufferSize) \
+ trace_adal_init_buffer((des), (comp_name), (bufferSize))
+
+
+class TracInit
+{
+ public:
+
+ /*------------------------------------------------------------------------*/
+ /* Constructor */
+ /*------------------------------------------------------------------------*/
+
+ TracInit(tracDesc_t *o_td, const char *i_comp,const size_t i_size)
+ {
+ // printf("TracInit constructor called for %s, size %u\n",i_comp,i_size);
+ TRAC_INIT_BUFFER(o_td,i_comp,i_size);
+ }
+
+ ~TracInit()
+ {
+ // printf("in the TracInit destructor\n");
+ }
+
+};
+
+/*******************************************************************************
+ TRAC_INIT: Class for creating trace descriptor object.
+
+ About the macros.
+ TRAC_INIT -- Called by users, adds __LINE__ for uniqueness.
+ TRAC_INIT_LINE -- Translates __LINE__ into the line number. Using
+ macro expansion in this statement would result in
+ tracInit static g_trac_"__LINE__"
+ TRAC_INIT_UNIQ -- With line number translated, use the '##' operator to
+ append number in variable name.
+*******************************************************************************/
+
+#define TRAC_INIT_UNIQ(des, name, sz, ln) TracInit static g_trac_##ln(des, name, sz)
+#define TRAC_INIT_LINE(des, name, sz, ln) TRAC_INIT_UNIQ(des, name, sz, ln)
+#define TRAC_INIT(des, name, sz) TRAC_INIT_LINE(des, name, sz, __LINE__)
+
+#endif //! -- NFP Library
+#endif //! -- !defined TRACINTERFACE_H
diff --git a/src/kernel/makefile b/src/kernel/makefile
index bb44a690f..807fdd894 100644
--- a/src/kernel/makefile
+++ b/src/kernel/makefile
@@ -8,7 +8,7 @@ OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
clean:
- (rm -f ${OBJECTS} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}) )
include ${ROOTPATH}/config.mk
diff --git a/src/lib/makefile b/src/lib/makefile
index 447149e48..a2deef3a7 100644
--- a/src/lib/makefile
+++ b/src/lib/makefile
@@ -9,6 +9,6 @@ OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
clean:
- (rm -f ${OBJECTS} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}))
include ${ROOTPATH}/config.mk
diff --git a/src/libc++/makefile b/src/libc++/makefile
index 8483c15ed..41263326f 100644
--- a/src/libc++/makefile
+++ b/src/libc++/makefile
@@ -7,6 +7,6 @@ OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
clean:
- (rm -f ${OBJECTS} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}))
include ${ROOTPATH}/config.mk
diff --git a/src/sys/init/makefile b/src/sys/init/makefile
index 8dbde1b7c..64c2c1af9 100644
--- a/src/sys/init/makefile
+++ b/src/sys/init/makefile
@@ -7,6 +7,6 @@ OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
clean:
- (rm -f ${OBJECTS} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}) )
include ${ROOTPATH}/config.mk
diff --git a/src/sys/vfs/makefile b/src/sys/vfs/makefile
index 883e001e3..05d3b8774 100644
--- a/src/sys/vfs/makefile
+++ b/src/sys/vfs/makefile
@@ -7,6 +7,6 @@ OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
all: ${OBJECTS}
clean:
- (rm -f ${OBJECTS} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}) )
include ${ROOTPATH}/config.mk
diff --git a/src/usr/example/example.C b/src/usr/example/example.C
index 873291be2..0965bcfd2 100644
--- a/src/usr/example/example.C
+++ b/src/usr/example/example.C
@@ -2,6 +2,7 @@
#include <sys/mutex.h>
#include <sys/vfs.h>
#include <sys/task.h>
+#include <tracinterface.H>
static mutex_t value = mutex_create();
@@ -19,6 +20,7 @@ void _init(void*)
}
printk("Here! %lx, %s\n", (uint64_t) value, VFS_ROOT);
+ TRACFCOMP(NULL, "This is a test %lx, %s", (uint64_t) value, VFS_ROOT);
}
extern "C"
diff --git a/src/usr/example/makefile b/src/usr/example/makefile
index 608aacc87..73642a088 100644
--- a/src/usr/example/makefile
+++ b/src/usr/example/makefile
@@ -11,6 +11,6 @@ LIBRARIES = $(addprefix ${IMGDIR}/, ${LIBS})
all: ${OBJECTS} ${LIBRARIES}
clean:
- (rm -f ${OBJECTS} ${LIBRARIES} )
+ (rm -f ${OBJECTS} $(addsuffix .hash, ${OBJECTS}) ${LIBRARIES} )
include ${ROOTPATH}/config.mk
OpenPOWER on IntegriCloud