Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / lib / cpu / src / SS_AddressMap.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: SS_AddressMap.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
//
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
//
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
//
// ========== Copyright Header End ============================================
#include "SS_AddressMap.h"
#include <new>
SS_AddressMap::Range* SS_AddressMap::fail = new SS_AddressMap::Range(SS_Paddr(0),~SS_Paddr(0),0,SS_AddressMap::REL,no_access,no_access);
SS_AddressMap::SS_AddressMap()/*{{{*/
:
table(0),
alloc(0),
_size(0)
{}
/*}}}*/
SS_AddressMap::~SS_AddressMap()/*{{{*/
{
if (table)
free(table);
}
/*}}}*/
void SS_AddressMap::add( SS_Paddr lo, SS_Paddr hi, void* obj, SS_AddressMap::Addressing rel, SS_Access::Func cpu, SS_Access::Func usr )/*{{{*/
{
uint_t p;
if (usr == 0) usr = cpu;
if (_size == alloc)
{
alloc += ALLOC;
table = (Range*)realloc(table,sizeof(Range) * alloc);
}
if (_size == 0)
{
p = 0;
}
else
{
uint_t l = 0;
uint_t h = _size;
uint_t m = _size >> 1;
Range* r = &table[m];
while (l != m)
{
((hi < r->lo) ? h : l) = m;
m = l + ((h - l) >> 1);
r = &table[m];
}
if (hi < r->lo)
{
for (uint_t i=_size; i > m; i--)
table[i] = table[i-1];
p = m;
}
else if (r->hi < lo)
{
for (uint_t i=_size; i > (m + 1); i--)
table[i] = table[i-1];
p = m + 1;
}
else
{
fprintf(stderr,"SS_AddressMap: region with lo=0x%llx and hi=0x%llx overlaps with lo=0x%llx and hi=0x%llx\n",lo,hi,r->lo,r->hi);
fprintf(stderr,"SS_AddressMap: Dropping the region\n");
return;
}
}
new (&table[p]) Range(lo,hi,obj,rel,cpu,usr);
++_size;
}
/*}}}*/
void SS_AddressMap::no_access( void*, uint_t sid, SS_Access::Type type, SS_Paddr pa, uint_t size, uint64_t* )/*{{{*/
{
fprintf(stderr,"Access unmapped address 0x%llx\n",pa);
}
/*}}}*/