refactor code for the packet, get rid of packet_impl.hh

and call it packet_access.hh and fix the #includes so
things compile right.

--HG--
extra : convert_revision : d3626c9715b9f7e51bb3ab8d97e971fad4e0b724
This commit is contained in:
Nathan Binkert
2006-10-19 23:38:45 -07:00
parent 5b246a0567
commit 7245d4530d
30 changed files with 174 additions and 57 deletions

View File

@@ -33,11 +33,10 @@
* Definition of BaseCache functions.
*/
#include "cpu/base.hh"
#include "cpu/smt.hh"
#include "mem/cache/base_cache.hh"
#include "mem/cache/miss/mshr.hh"
#include "mem/packet_impl.hh"
#include "cpu/smt.hh"
#include "cpu/base.hh"
using namespace std;

View File

@@ -36,9 +36,10 @@
*/
#include <iostream>
#include "base/misc.hh"
#include "mem/packet.hh"
#include "base/trace.hh"
#include "mem/packet.hh"
static const std::string ReadReqString("ReadReq");
static const std::string WriteReqString("WriteReq");

View File

@@ -38,11 +38,12 @@
#ifndef __MEM_PACKET_HH__
#define __MEM_PACKET_HH__
#include <cassert>
#include <list>
#include "mem/request.hh"
#include "sim/host.hh"
#include "sim/root.hh"
#include <list>
#include <cassert>
struct Packet;
typedef Packet* PacketPtr;
@@ -342,10 +343,12 @@ class Packet
srcValid = false;
}
/** Take a request packet and modify it in place to be suitable
* for returning as a response to that request.
/**
* Take a request packet and modify it in place to be suitable for
* returning as a response to that request.
*/
void makeAtomicResponse() {
void makeAtomicResponse()
{
assert(needsResponse());
assert(isRequest());
int icmd = (int)cmd;
@@ -358,43 +361,83 @@ class Packet
cmd = (Command)icmd;
}
/** Take a request packet that has been returned as NACKED and modify it so
* that it can be sent out again. Only packets that need a response can be
* NACKED, so verify that that is true. */
void reinitNacked() {
/**
* Take a request packet that has been returned as NACKED and
* modify it so that it can be sent out again. Only packets that
* need a response can be NACKED, so verify that that is true.
*/
void
reinitNacked()
{
assert(needsResponse() && result == Nacked);
dest = Broadcast;
result = Unknown;
}
/** Set the data pointer to the following value that should not be freed. */
template <typename T>
void dataStatic(T *p);
/** Set the data pointer to a value that should have delete [] called on it.
/**
* Set the data pointer to the following value that should not be
* freed.
*/
template <typename T>
void dataDynamicArray(T *p);
void
dataStatic(T *p)
{
if(dynamicData)
dynamicData = false;
data = (PacketDataPtr)p;
staticData = true;
}
/** set the data pointer to a value that should have delete called on it. */
/**
* Set the data pointer to a value that should have delete []
* called on it.
*/
template <typename T>
void dataDynamic(T *p);
void
dataDynamicArray(T *p)
{
assert(!staticData && !dynamicData);
data = (PacketDataPtr)p;
dynamicData = true;
arrayData = true;
}
/**
* set the data pointer to a value that should have delete called
* on it.
*/
template <typename T>
void
dataDynamic(T *p)
{
assert(!staticData && !dynamicData);
data = (PacketDataPtr)p;
dynamicData = true;
arrayData = false;
}
/** get a pointer to the data ptr. */
template <typename T>
T*
getPtr()
{
assert(staticData || dynamicData);
return (T*)data;
}
/** return the value of what is pointed to in the packet. */
template <typename T>
T get();
/** get a pointer to the data ptr. */
template <typename T>
T* getPtr();
/** set the value in the data pointer to v. */
template <typename T>
void set(T v);
/** delete the data pointed to in the data pointer. Ok to call to matter how
* data was allocted. */
/**
* delete the data pointed to in the data pointer. Ok to call to
* matter how data was allocted.
*/
void deleteData();
/** If there isn't data in the packet, allocate some. */

62
src/mem/packet_access.hh Normal file
View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2006 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Ali Saidi
* Nathan Binkert
*/
#include "arch/isa_traits.hh"
#include "mem/packet.hh"
#include "sim/byteswap.hh"
#ifndef __MEM_PACKET_ACCESS_HH__
#define __MEM_PACKET_ACCESS_HH__
// The memory system needs to have an endianness. This is the easiest
// way to deal with it for now. At some point, we will have to remove
// these functions and make the users do their own byte swapping since
// the memory system does not in fact have an endianness.
/** return the value of what is pointed to in the packet. */
template <typename T>
inline T
Packet::get()
{
assert(staticData || dynamicData);
assert(sizeof(T) <= size);
return TheISA::gtoh(*(T*)data);
}
/** set the value in the data pointer to v. */
template <typename T>
inline void
Packet::set(T v)
{
assert(sizeof(T) <= size);
*(T*)data = TheISA::htog(v);
}
#endif //__MEM_PACKET_ACCESS_HH__

View File

@@ -39,21 +39,17 @@
#include <iostream>
#include <string>
#include "arch/isa_traits.hh"
#include "base/misc.hh"
#include "config/full_system.hh"
#include "mem/packet_impl.hh"
#include "mem/physical.hh"
#include "sim/host.hh"
#include "sim/builder.hh"
#include "sim/eventq.hh"
#include "arch/isa_traits.hh"
#include "sim/host.hh"
using namespace std;
using namespace TheISA;
PhysicalMemory::PhysicalMemory(Params *p)
: MemObject(p->name), pmemAddr(NULL), port(NULL), lat(p->latency), _params(p)
{

View File

@@ -35,7 +35,6 @@
#include "base/chunk_generator.hh"
#include "base/trace.hh"
#include "mem/packet_impl.hh"
#include "mem/port.hh"
void