RubySlicc_Util.hh revision 10956
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"
397039Snate@binkert.org#include "mem/ruby/common/Address.hh"
4010086Snilay@cs.wisc.edu#include "mem/ruby/common/DataBlock.hh"
419499Snilay@cs.wisc.edu#include "mem/packet.hh"
426145Snate@binkert.org
439507Snilay@cs.wisc.eduinline Cycles zero_time() { return Cycles(0); }
449499Snilay@cs.wisc.edu
457039Snate@binkert.orginline NodeID
467039Snate@binkert.orgintToID(int nodenum)
476145Snate@binkert.org{
487039Snate@binkert.org    NodeID id = nodenum;
497039Snate@binkert.org    return id;
506145Snate@binkert.org}
516145Snate@binkert.org
527039Snate@binkert.orginline int
537039Snate@binkert.orgIDToInt(NodeID id)
546145Snate@binkert.org{
557039Snate@binkert.org    int nodenum = id;
567039Snate@binkert.org    return nodenum;
576145Snate@binkert.org}
586145Snate@binkert.org
5910956SBrad.Beckmann@amd.cominline int
6010956SBrad.Beckmann@amd.comaddressToInt(Address addr)
6110956SBrad.Beckmann@amd.com{
6210956SBrad.Beckmann@amd.com    assert(!(addr.getAddress() & 0xffffffff00000000));
6310956SBrad.Beckmann@amd.com
6410956SBrad.Beckmann@amd.com    return (int)addr.getAddress();
6510956SBrad.Beckmann@amd.com}
6610956SBrad.Beckmann@amd.com
676145Snate@binkert.org// Appends an offset to an address
687039Snate@binkert.orginline Address
697039Snate@binkert.orgsetOffset(Address addr, int offset)
706145Snate@binkert.org{
717039Snate@binkert.org    Address result = addr;
727039Snate@binkert.org    result.setOffset(offset);
737039Snate@binkert.org    return result;
746145Snate@binkert.org}
756145Snate@binkert.org
766145Snate@binkert.org// Makes an address into a line address
777039Snate@binkert.orginline Address
787039Snate@binkert.orgmakeLineAddress(Address addr)
796145Snate@binkert.org{
807039Snate@binkert.org    Address result = addr;
817039Snate@binkert.org    result.makeLineAddress();
827039Snate@binkert.org    return result;
836145Snate@binkert.org}
846145Snate@binkert.org
857039Snate@binkert.orginline int
867039Snate@binkert.orgaddressOffset(Address addr)
876467Sdrh5@cs.wisc.edu{
887039Snate@binkert.org    return addr.getOffset();
896467Sdrh5@cs.wisc.edu}
906467Sdrh5@cs.wisc.edu
918131SLisa.Hsu@amd.cominline int
928131SLisa.Hsu@amd.commod(int val, int mod)
938131SLisa.Hsu@amd.com{
948131SLisa.Hsu@amd.com    return val % mod;
958131SLisa.Hsu@amd.com}
968131SLisa.Hsu@amd.com
979466Snilay@cs.wisc.eduinline int max_tokens()
989466Snilay@cs.wisc.edu{
999466Snilay@cs.wisc.edu  return 1024;
1009466Snilay@cs.wisc.edu}
1019466Snilay@cs.wisc.edu
1029302Snilay@cs.wisc.edu/**
1039302Snilay@cs.wisc.edu * This function accepts an address, a data block and a packet. If the address
1049302Snilay@cs.wisc.edu * range for the data block contains the address which the packet needs to
1059302Snilay@cs.wisc.edu * read, then the data from the data block is written to the packet. True is
1069302Snilay@cs.wisc.edu * returned if the data block was read, otherwise false is returned.
1079302Snilay@cs.wisc.edu */
1089302Snilay@cs.wisc.eduinline bool
1099302Snilay@cs.wisc.edutestAndRead(Address addr, DataBlock& blk, Packet *pkt)
1109302Snilay@cs.wisc.edu{
1119302Snilay@cs.wisc.edu    Address pktLineAddr(pkt->getAddr());
1129302Snilay@cs.wisc.edu    pktLineAddr.makeLineAddress();
1139302Snilay@cs.wisc.edu
1149302Snilay@cs.wisc.edu    Address lineAddr = addr;
1159302Snilay@cs.wisc.edu    lineAddr.makeLineAddress();
1169302Snilay@cs.wisc.edu
1179302Snilay@cs.wisc.edu    if (pktLineAddr == lineAddr) {
11810562Sandreas.hansson@arm.com        uint8_t *data = pkt->getPtr<uint8_t>();
1199302Snilay@cs.wisc.edu        unsigned int size_in_bytes = pkt->getSize();
1209302Snilay@cs.wisc.edu        unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
1219302Snilay@cs.wisc.edu
1229302Snilay@cs.wisc.edu        for (unsigned i = 0; i < size_in_bytes; ++i) {
1239302Snilay@cs.wisc.edu            data[i] = blk.getByte(i + startByte);
1249302Snilay@cs.wisc.edu        }
1259302Snilay@cs.wisc.edu        return true;
1269302Snilay@cs.wisc.edu    }
1279302Snilay@cs.wisc.edu    return false;
1289302Snilay@cs.wisc.edu}
1299302Snilay@cs.wisc.edu
1309302Snilay@cs.wisc.edu/**
1319302Snilay@cs.wisc.edu * This function accepts an address, a data block and a packet. If the address
1329302Snilay@cs.wisc.edu * range for the data block contains the address which the packet needs to
1339302Snilay@cs.wisc.edu * write, then the data from the packet is written to the data block. True is
1349302Snilay@cs.wisc.edu * returned if the data block was written, otherwise false is returned.
1359302Snilay@cs.wisc.edu */
1369302Snilay@cs.wisc.eduinline bool
1379302Snilay@cs.wisc.edutestAndWrite(Address addr, DataBlock& blk, Packet *pkt)
1389302Snilay@cs.wisc.edu{
1399302Snilay@cs.wisc.edu    Address pktLineAddr(pkt->getAddr());
1409302Snilay@cs.wisc.edu    pktLineAddr.makeLineAddress();
1419302Snilay@cs.wisc.edu
1429302Snilay@cs.wisc.edu    Address lineAddr = addr;
1439302Snilay@cs.wisc.edu    lineAddr.makeLineAddress();
1449302Snilay@cs.wisc.edu
1459302Snilay@cs.wisc.edu    if (pktLineAddr == lineAddr) {
14610563Sandreas.hansson@arm.com        const uint8_t *data = pkt->getConstPtr<uint8_t>();
1479302Snilay@cs.wisc.edu        unsigned int size_in_bytes = pkt->getSize();
1489302Snilay@cs.wisc.edu        unsigned startByte = pkt->getAddr() - lineAddr.getAddress();
1499302Snilay@cs.wisc.edu
1509302Snilay@cs.wisc.edu        for (unsigned i = 0; i < size_in_bytes; ++i) {
1519302Snilay@cs.wisc.edu            blk.setByte(i + startByte, data[i]);
1529302Snilay@cs.wisc.edu        }
1539302Snilay@cs.wisc.edu        return true;
1549302Snilay@cs.wisc.edu    }
1559302Snilay@cs.wisc.edu    return false;
1569302Snilay@cs.wisc.edu}
1579302Snilay@cs.wisc.edu
1587039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_RUBYSLICCUTIL_HH__
159