14776Sgblack@eecs.umich.edu/*
26365Sgblack@eecs.umich.edu * Copyright (c) 2006-2009 The Regents of The University of Michigan
34776Sgblack@eecs.umich.edu * All rights reserved.
44776Sgblack@eecs.umich.edu *
54776Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
64776Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
74776Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
84776Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
94776Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
104776Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
114776Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
124776Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
134776Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
144776Sgblack@eecs.umich.edu * this software without specific prior written permission.
154776Sgblack@eecs.umich.edu *
164776Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
174776Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
184776Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
194776Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
204776Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
214776Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
224776Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
234776Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
244776Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
254776Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
264776Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
274776Sgblack@eecs.umich.edu *
286365Sgblack@eecs.umich.edu * Authors: Gabe Black
294776Sgblack@eecs.umich.edu */
304776Sgblack@eecs.umich.edu
316216Snate@binkert.org#ifndef __CPU_NATIVETRACE_HH__
326216Snate@binkert.org#define __CPU_NATIVETRACE_HH__
334776Sgblack@eecs.umich.edu
346365Sgblack@eecs.umich.edu#include <unistd.h>
356365Sgblack@eecs.umich.edu
368229Snate@binkert.org#include <cerrno>
378229Snate@binkert.org
386365Sgblack@eecs.umich.edu#include "base/socket.hh"
394776Sgblack@eecs.umich.edu#include "base/trace.hh"
406216Snate@binkert.org#include "base/types.hh"
416409Sgblack@eecs.umich.edu#include "cpu/exetrace.hh"
424776Sgblack@eecs.umich.edu#include "cpu/static_inst.hh"
434776Sgblack@eecs.umich.edu
444776Sgblack@eecs.umich.educlass ThreadContext;
454776Sgblack@eecs.umich.edu
464776Sgblack@eecs.umich.edunamespace Trace {
474776Sgblack@eecs.umich.edu
484776Sgblack@eecs.umich.educlass NativeTrace;
494776Sgblack@eecs.umich.edu
506409Sgblack@eecs.umich.educlass NativeTraceRecord : public ExeTracerRecord
514776Sgblack@eecs.umich.edu{
524776Sgblack@eecs.umich.edu  protected:
534776Sgblack@eecs.umich.edu    NativeTrace * parent;
544776Sgblack@eecs.umich.edu
554776Sgblack@eecs.umich.edu  public:
564776Sgblack@eecs.umich.edu    NativeTraceRecord(NativeTrace * _parent,
574776Sgblack@eecs.umich.edu               Tick _when, ThreadContext *_thread,
587720Sgblack@eecs.umich.edu               const StaticInstPtr _staticInst, TheISA::PCState _pc,
5910664SAli.Saidi@ARM.com               const StaticInstPtr _macroStaticInst = NULL)
6010664SAli.Saidi@ARM.com        : ExeTracerRecord(_when, _thread, _staticInst, _pc, _macroStaticInst),
615784Sgblack@eecs.umich.edu        parent(_parent)
624776Sgblack@eecs.umich.edu    {
634776Sgblack@eecs.umich.edu    }
644776Sgblack@eecs.umich.edu
654776Sgblack@eecs.umich.edu    void dump();
664776Sgblack@eecs.umich.edu};
674776Sgblack@eecs.umich.edu
686409Sgblack@eecs.umich.educlass NativeTrace : public ExeTracer
694776Sgblack@eecs.umich.edu{
704776Sgblack@eecs.umich.edu  protected:
714776Sgblack@eecs.umich.edu    int fd;
724776Sgblack@eecs.umich.edu
734776Sgblack@eecs.umich.edu    ListenSocket native_listener;
744776Sgblack@eecs.umich.edu
756365Sgblack@eecs.umich.edu  public:
764830Sgblack@eecs.umich.edu
776365Sgblack@eecs.umich.edu    NativeTrace(const Params *p);
786365Sgblack@eecs.umich.edu    virtual ~NativeTrace() {}
794830Sgblack@eecs.umich.edu
806365Sgblack@eecs.umich.edu    NativeTraceRecord *
816365Sgblack@eecs.umich.edu    getInstRecord(Tick when, ThreadContext *tc,
827720Sgblack@eecs.umich.edu            const StaticInstPtr staticInst, TheISA::PCState pc,
837720Sgblack@eecs.umich.edu            const StaticInstPtr macroStaticInst = NULL)
846365Sgblack@eecs.umich.edu    {
856365Sgblack@eecs.umich.edu        return new NativeTraceRecord(this, when, tc,
8610664SAli.Saidi@ARM.com                staticInst, pc, macroStaticInst);
876365Sgblack@eecs.umich.edu    }
884776Sgblack@eecs.umich.edu
894830Sgblack@eecs.umich.edu    template<class T>
904830Sgblack@eecs.umich.edu    bool
914830Sgblack@eecs.umich.edu    checkReg(const char * regName, T &val, T &realVal)
924830Sgblack@eecs.umich.edu    {
9311321Ssteve.reinhardt@amd.com        if (val != realVal)
944830Sgblack@eecs.umich.edu        {
954830Sgblack@eecs.umich.edu            DPRINTFN("Register %s should be %#x but is %#x.\n",
964830Sgblack@eecs.umich.edu                    regName, realVal, val);
974830Sgblack@eecs.umich.edu            return false;
984830Sgblack@eecs.umich.edu        }
994830Sgblack@eecs.umich.edu        return true;
1004830Sgblack@eecs.umich.edu    }
1014830Sgblack@eecs.umich.edu
1026365Sgblack@eecs.umich.edu    void
1036365Sgblack@eecs.umich.edu    read(void *ptr, size_t size)
1044776Sgblack@eecs.umich.edu    {
1056365Sgblack@eecs.umich.edu        size_t soFar = 0;
1066365Sgblack@eecs.umich.edu        while (soFar < size) {
1078737Skoansin.tan@gmail.com            ssize_t res = ::read(fd, (uint8_t *)ptr + soFar, size - soFar);
1086365Sgblack@eecs.umich.edu            if (res < 0)
1096365Sgblack@eecs.umich.edu                panic("Read call failed! %s\n", strerror(errno));
1106365Sgblack@eecs.umich.edu            else
1116365Sgblack@eecs.umich.edu                soFar += res;
1126365Sgblack@eecs.umich.edu        }
1134776Sgblack@eecs.umich.edu    }
1144776Sgblack@eecs.umich.edu
1156365Sgblack@eecs.umich.edu    virtual void
1166365Sgblack@eecs.umich.edu    check(NativeTraceRecord *record) = 0;
1174776Sgblack@eecs.umich.edu};
1184776Sgblack@eecs.umich.edu
1197811Ssteve.reinhardt@amd.com} // namespace Trace
1204776Sgblack@eecs.umich.edu
1216216Snate@binkert.org#endif // __CPU_NATIVETRACE_HH__
122