packet_access.hh revision 6658
12810SN/A/*
22810SN/A * Copyright (c) 2006 The Regents of The University of Michigan
32810SN/A * All rights reserved.
42810SN/A *
52810SN/A * Redistribution and use in source and binary forms, with or without
62810SN/A * modification, are permitted provided that the following conditions are
72810SN/A * met: redistributions of source code must retain the above copyright
82810SN/A * notice, this list of conditions and the following disclaimer;
92810SN/A * redistributions in binary form must reproduce the above copyright
102810SN/A * notice, this list of conditions and the following disclaimer in the
112810SN/A * documentation and/or other materials provided with the distribution;
122810SN/A * neither the name of the copyright holders nor the names of its
132810SN/A * contributors may be used to endorse or promote products derived from
142810SN/A * this software without specific prior written permission.
152810SN/A *
162810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272810SN/A *
282810SN/A * Authors: Ali Saidi
292810SN/A *          Nathan Binkert
302810SN/A */
312810SN/A
322810SN/A#include "arch/isa_traits.hh"
332810SN/A#include "base/bigint.hh"
342810SN/A#include "config/the_isa.hh"
352810SN/A#include "mem/packet.hh"
362810SN/A#include "sim/byteswap.hh"
372810SN/A
382810SN/A#ifndef __MEM_PACKET_ACCESS_HH__
392810SN/A#define __MEM_PACKET_ACCESS_HH__
404666SN/A// The memory system needs to have an endianness. This is the easiest
412810SN/A// way to deal with it for now. At some point, we will have to remove
425338Sstever@gmail.com// these functions and make the users do their own byte swapping since
434167SN/A// the memory system does not in fact have an endianness.
442810SN/A
452810SN/A/** return the value of what is pointed to in the packet. */
462810SN/Atemplate <typename T>
472810SN/Ainline T
482810SN/APacket::get()
492810SN/A{
502810SN/A    assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
512810SN/A    assert(sizeof(T) <= size);
522810SN/A    return TheISA::gtoh(*(T*)data);
532810SN/A}
542813SN/A
554903SN/A/** set the value in the data pointer to v. */
564903SN/Atemplate <typename T>
572810SN/Ainline void
582810SN/APacket::set(T v)
594903SN/A{
604903SN/A    assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA));
614903SN/A    assert(sizeof(T) <= size);
624903SN/A    *(T*)data = TheISA::htog(v);
634903SN/A}
644903SN/A
654903SN/A#endif //__MEM_PACKET_ACCESS_HH__
664908SN/A