packet_access.hh revision 4040
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 444040Ssaidi@eecs.umich.edutemplate<> 454040Ssaidi@eecs.umich.eduinline Twin64_t 464040Ssaidi@eecs.umich.eduPacket::get() 474040Ssaidi@eecs.umich.edu{ 484040Ssaidi@eecs.umich.edu Twin64_t d; 494040Ssaidi@eecs.umich.edu assert(staticData || dynamicData); 504040Ssaidi@eecs.umich.edu assert(sizeof(Twin64_t) <= size); 514040Ssaidi@eecs.umich.edu d.a = TheISA::gtoh(*(uint64_t*)data); 524040Ssaidi@eecs.umich.edu d.b = TheISA::gtoh(*((uint64_t*)data + 1)); 534040Ssaidi@eecs.umich.edu return d; 544040Ssaidi@eecs.umich.edu} 554040Ssaidi@eecs.umich.edu 564040Ssaidi@eecs.umich.edu 573348Sbinkertn@umich.edu/** return the value of what is pointed to in the packet. */ 583348Sbinkertn@umich.edutemplate <typename T> 593348Sbinkertn@umich.eduinline T 603348Sbinkertn@umich.eduPacket::get() 613348Sbinkertn@umich.edu{ 623348Sbinkertn@umich.edu assert(staticData || dynamicData); 633348Sbinkertn@umich.edu assert(sizeof(T) <= size); 643348Sbinkertn@umich.edu return TheISA::gtoh(*(T*)data); 653348Sbinkertn@umich.edu} 663348Sbinkertn@umich.edu 673348Sbinkertn@umich.edu/** set the value in the data pointer to v. */ 683348Sbinkertn@umich.edutemplate <typename T> 693348Sbinkertn@umich.eduinline void 703348Sbinkertn@umich.eduPacket::set(T v) 713348Sbinkertn@umich.edu{ 723348Sbinkertn@umich.edu assert(sizeof(T) <= size); 733348Sbinkertn@umich.edu *(T*)data = TheISA::htog(v); 743348Sbinkertn@umich.edu} 753348Sbinkertn@umich.edu 763348Sbinkertn@umich.edu#endif //__MEM_PACKET_ACCESS_HH__ 77