RubySlicc_Util.hh revision 11209
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 296145Snate@binkert.org/* 307039Snate@binkert.org * These are the functions that exported to slicc from ruby. 316145Snate@binkert.org */ 326145Snate@binkert.org 337039Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 347039Snate@binkert.org#define __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 356145Snate@binkert.org 367832Snate@binkert.org#include <cassert> 377832Snate@binkert.org 389302Snilay@cs.wisc.edu#include "debug/RubySlicc.hh" 3911025Snilay@cs.wisc.edu#include "mem/packet.hh" 407039Snate@binkert.org#include "mem/ruby/common/Address.hh" 4111208Sjoseph.gross@amd.com#include "mem/ruby/common/BoolVec.hh" 4210086Snilay@cs.wisc.edu#include "mem/ruby/common/DataBlock.hh" 4311025Snilay@cs.wisc.edu#include "mem/ruby/common/TypeDefines.hh" 446145Snate@binkert.org 459507Snilay@cs.wisc.eduinline Cycles zero_time() { return Cycles(0); } 469499Snilay@cs.wisc.edu 477039Snate@binkert.orginline NodeID 487039Snate@binkert.orgintToID(int nodenum) 496145Snate@binkert.org{ 507039Snate@binkert.org NodeID id = nodenum; 517039Snate@binkert.org return id; 526145Snate@binkert.org} 536145Snate@binkert.org 547039Snate@binkert.orginline int 557039Snate@binkert.orgIDToInt(NodeID id) 566145Snate@binkert.org{ 577039Snate@binkert.org int nodenum = id; 587039Snate@binkert.org return nodenum; 596145Snate@binkert.org} 606145Snate@binkert.org 6110956SBrad.Beckmann@amd.cominline int 6211025Snilay@cs.wisc.eduaddressToInt(Addr addr) 6310956SBrad.Beckmann@amd.com{ 6411025Snilay@cs.wisc.edu assert(!(addr & 0xffffffff00000000)); 6511025Snilay@cs.wisc.edu return addr; 666467Sdrh5@cs.wisc.edu} 676467Sdrh5@cs.wisc.edu 6811209Santhony.gutierrez@amd.cominline Addr 6911209Santhony.gutierrez@amd.comintToAddress(int addr) 7011209Santhony.gutierrez@amd.com{ 7111209Santhony.gutierrez@amd.com assert(!(addr & 0xffffffff00000000)); 7211209Santhony.gutierrez@amd.com return addr; 7311209Santhony.gutierrez@amd.com} 7411209Santhony.gutierrez@amd.com 758131SLisa.Hsu@amd.cominline int 768131SLisa.Hsu@amd.commod(int val, int mod) 778131SLisa.Hsu@amd.com{ 788131SLisa.Hsu@amd.com return val % mod; 798131SLisa.Hsu@amd.com} 808131SLisa.Hsu@amd.com 819466Snilay@cs.wisc.eduinline int max_tokens() 829466Snilay@cs.wisc.edu{ 839466Snilay@cs.wisc.edu return 1024; 849466Snilay@cs.wisc.edu} 859466Snilay@cs.wisc.edu 869302Snilay@cs.wisc.edu/** 879302Snilay@cs.wisc.edu * This function accepts an address, a data block and a packet. If the address 889302Snilay@cs.wisc.edu * range for the data block contains the address which the packet needs to 899302Snilay@cs.wisc.edu * read, then the data from the data block is written to the packet. True is 909302Snilay@cs.wisc.edu * returned if the data block was read, otherwise false is returned. 919302Snilay@cs.wisc.edu */ 929302Snilay@cs.wisc.eduinline bool 9311025Snilay@cs.wisc.edutestAndRead(Addr addr, DataBlock& blk, Packet *pkt) 949302Snilay@cs.wisc.edu{ 9511025Snilay@cs.wisc.edu Addr pktLineAddr = makeLineAddress(pkt->getAddr()); 9611025Snilay@cs.wisc.edu Addr lineAddr = makeLineAddress(addr); 979302Snilay@cs.wisc.edu 989302Snilay@cs.wisc.edu if (pktLineAddr == lineAddr) { 9910562Sandreas.hansson@arm.com uint8_t *data = pkt->getPtr<uint8_t>(); 1009302Snilay@cs.wisc.edu unsigned int size_in_bytes = pkt->getSize(); 10111025Snilay@cs.wisc.edu unsigned startByte = pkt->getAddr() - lineAddr; 1029302Snilay@cs.wisc.edu 1039302Snilay@cs.wisc.edu for (unsigned i = 0; i < size_in_bytes; ++i) { 1049302Snilay@cs.wisc.edu data[i] = blk.getByte(i + startByte); 1059302Snilay@cs.wisc.edu } 1069302Snilay@cs.wisc.edu return true; 1079302Snilay@cs.wisc.edu } 1089302Snilay@cs.wisc.edu return false; 1099302Snilay@cs.wisc.edu} 1109302Snilay@cs.wisc.edu 1119302Snilay@cs.wisc.edu/** 1129302Snilay@cs.wisc.edu * This function accepts an address, a data block and a packet. If the address 1139302Snilay@cs.wisc.edu * range for the data block contains the address which the packet needs to 1149302Snilay@cs.wisc.edu * write, then the data from the packet is written to the data block. True is 1159302Snilay@cs.wisc.edu * returned if the data block was written, otherwise false is returned. 1169302Snilay@cs.wisc.edu */ 1179302Snilay@cs.wisc.eduinline bool 11811025Snilay@cs.wisc.edutestAndWrite(Addr addr, DataBlock& blk, Packet *pkt) 1199302Snilay@cs.wisc.edu{ 12011025Snilay@cs.wisc.edu Addr pktLineAddr = makeLineAddress(pkt->getAddr()); 12111025Snilay@cs.wisc.edu Addr lineAddr = makeLineAddress(addr); 1229302Snilay@cs.wisc.edu 1239302Snilay@cs.wisc.edu if (pktLineAddr == lineAddr) { 12410563Sandreas.hansson@arm.com const uint8_t *data = pkt->getConstPtr<uint8_t>(); 1259302Snilay@cs.wisc.edu unsigned int size_in_bytes = pkt->getSize(); 12611025Snilay@cs.wisc.edu unsigned startByte = pkt->getAddr() - lineAddr; 1279302Snilay@cs.wisc.edu 1289302Snilay@cs.wisc.edu for (unsigned i = 0; i < size_in_bytes; ++i) { 1299302Snilay@cs.wisc.edu blk.setByte(i + startByte, data[i]); 1309302Snilay@cs.wisc.edu } 1319302Snilay@cs.wisc.edu return true; 1329302Snilay@cs.wisc.edu } 1339302Snilay@cs.wisc.edu return false; 1349302Snilay@cs.wisc.edu} 1359302Snilay@cs.wisc.edu 13611208Sjoseph.gross@amd.cominline int 13711208Sjoseph.gross@amd.comcountBoolVec(BoolVec bVec) 13811208Sjoseph.gross@amd.com{ 13911208Sjoseph.gross@amd.com int count = 0; 14011208Sjoseph.gross@amd.com for (const auto &it: bVec) { 14111208Sjoseph.gross@amd.com if (it) { 14211208Sjoseph.gross@amd.com count++; 14311208Sjoseph.gross@amd.com } 14411208Sjoseph.gross@amd.com } 14511208Sjoseph.gross@amd.com return count; 14611208Sjoseph.gross@amd.com} 14711208Sjoseph.gross@amd.com 1487039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__ 149