packet_access.hh revision 5764
13348Sbinkertn@umich.edu/* 23348Sbinkertn@umich.edu * Copyright (c) 2006 The Regents of The University of Michigan 33348Sbinkertn@umich.edu * All rights reserved. 43348Sbinkertn@umich.edu * 53348Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without 63348Sbinkertn@umich.edu * modification, are permitted provided that the following conditions are 73348Sbinkertn@umich.edu * met: redistributions of source code must retain the above copyright 83348Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer; 93348Sbinkertn@umich.edu * redistributions in binary form must reproduce the above copyright 103348Sbinkertn@umich.edu * notice, this list of conditions and the following disclaimer in the 113348Sbinkertn@umich.edu * documentation and/or other materials provided with the distribution; 123348Sbinkertn@umich.edu * neither the name of the copyright holders nor the names of its 133348Sbinkertn@umich.edu * contributors may be used to endorse or promote products derived from 143348Sbinkertn@umich.edu * this software without specific prior written permission. 153348Sbinkertn@umich.edu * 163348Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 173348Sbinkertn@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 183348Sbinkertn@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 193348Sbinkertn@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 203348Sbinkertn@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 213348Sbinkertn@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 223348Sbinkertn@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 233348Sbinkertn@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 243348Sbinkertn@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 253348Sbinkertn@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 263348Sbinkertn@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 273348Sbinkertn@umich.edu * 283348Sbinkertn@umich.edu * Authors: Ali Saidi 293348Sbinkertn@umich.edu * Nathan Binkert 303348Sbinkertn@umich.edu */ 313348Sbinkertn@umich.edu 323348Sbinkertn@umich.edu#include "arch/isa_traits.hh" 334040Ssaidi@eecs.umich.edu#include "base/bigint.hh" 343348Sbinkertn@umich.edu#include "mem/packet.hh" 353348Sbinkertn@umich.edu#include "sim/byteswap.hh" 363348Sbinkertn@umich.edu 373348Sbinkertn@umich.edu#ifndef __MEM_PACKET_ACCESS_HH__ 383348Sbinkertn@umich.edu#define __MEM_PACKET_ACCESS_HH__ 393348Sbinkertn@umich.edu// The memory system needs to have an endianness. This is the easiest 403348Sbinkertn@umich.edu// way to deal with it for now. At some point, we will have to remove 413348Sbinkertn@umich.edu// these functions and make the users do their own byte swapping since 423348Sbinkertn@umich.edu// the memory system does not in fact have an endianness. 433348Sbinkertn@umich.edu 443348Sbinkertn@umich.edu/** return the value of what is pointed to in the packet. */ 453348Sbinkertn@umich.edutemplate <typename T> 463348Sbinkertn@umich.eduinline T 473348Sbinkertn@umich.eduPacket::get() 483348Sbinkertn@umich.edu{ 495764Snate@binkert.org assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 503348Sbinkertn@umich.edu assert(sizeof(T) <= size); 513348Sbinkertn@umich.edu return TheISA::gtoh(*(T*)data); 523348Sbinkertn@umich.edu} 533348Sbinkertn@umich.edu 543348Sbinkertn@umich.edu/** set the value in the data pointer to v. */ 553348Sbinkertn@umich.edutemplate <typename T> 563348Sbinkertn@umich.eduinline void 573348Sbinkertn@umich.eduPacket::set(T v) 583348Sbinkertn@umich.edu{ 595764Snate@binkert.org assert(flags.isSet(STATIC_DATA|DYNAMIC_DATA)); 603348Sbinkertn@umich.edu assert(sizeof(T) <= size); 613348Sbinkertn@umich.edu *(T*)data = TheISA::htog(v); 623348Sbinkertn@umich.edu} 633348Sbinkertn@umich.edu 643348Sbinkertn@umich.edu#endif //__MEM_PACKET_ACCESS_HH__ 65