Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / system / tracemod / tm_impl.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: tm_impl.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 ============================================
/*
* Copyright (C) 1991, 2001 Sun Microsystems, Inc.
* All rights reserved.
*/
#pragma ident "@(#)1.4 01/11/06 tm_impl.cc"
/*
* Copyright (c) 1989, Sun Microsystems, Inc. All Rights Reserved. Sun
* considers its source code as an unpublished, proprietary trade secret, and
* it is available only under strict license provisions. This copyright
* notice is placed here only to protect Sun in the event the source is
* deemed a published work. Disassembly, decompilation, or other means of
* reducing the object code to human readable form is prohibited by the
* license agreement under which this code is provided to the user or company
* in possession of this copy
*
* RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
* Government is subject to restrictions as set forth in subparagraph
* (c) (1) (ii) of the Rights in Technical Data and Computer Software clause
* at DFARS 52.227-7013 and in similar clauses in the FAR and NASA FAR
* Supplement
*/
//
// tm_impl.c
// ---------
// This module contains an implementation of TRACING in blaze v4
//
#include <sys/types.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <synch.h>
#include <dlfcn.h>
#include "types.h"
#include "blaze_globals.h"
#include "ui.h"
//#include "cpu.h"
#include "cpu_interface.h"
#include "dr.h"
#include "schizo_module.h"
#include "system.h"
typedef void* TM_OPAQUE_DATA;
#include "tracemod.h"
#include "tm_impl.h"
#include <set>
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
void TM_time_interval (uint64_t time)
{
LdmNode *pnode;
for (pnode=head_ldm; pnode != NULL; pnode=pnode->Next()) {
Ldm * pldm = pnode->GetData();
if (pldm->ti_action) {
pldm->ti_action ((TM_OPAQUE_DATA)pldm->client_data, time);
}
}
tm_time_target += tm_time_interval;
}
void TM_context (cpuT *sp)
{
}
//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
typedef struct {
void *obj;
mmi_access access;
uint64_t base, size, end;
} PhysioMap;
typedef List1Node<PhysioMap> PhysioMapNode;
PhysioMapNode* headPhysioMap;
static std::set<uint64_t> unmapped_addresses;
int SYSTEM_physio_access(uint32_t cpu_id, void* /* obj */, uint64_t paddr, bool_t wr, uint32_t size, uint64_t* buf, uint8_t bytemask)
{PhysioMap* pmap;
uint64_t end = paddr+size;
for (PhysioMapNode *pnode = headPhysioMap; pnode; pnode = pnode->Next()) {
pmap = pnode->GetData();
if (pmap->base <= paddr && end <= pmap->end)
return pmap->access(cpu_id, pmap->obj, paddr, (mmi_bool_t)wr, size, buf, bytemask);
}
if (unmapped_addresses.find(paddr) == unmapped_addresses.end())
{
ui->warning("unmapped SYSTEM_physio_access: [%llx %llx], %s \n", paddr, end,wr?"write":"read" );
unmapped_addresses.insert(paddr);
}
if(!wr)
*buf = 0;
return 0;
}
int mmi_map_physio(uint64_t base, uint64_t size, void* obj, mmi_access access)
{
PhysioMapNode *pnode = PhysioMapNode::CreateInstance("physio map");
PhysioMap *ph;
if (pnode == NULL) {
ui->error("%s(L%d): Unable to create physio map\n", __FILE__, __LINE__);
} else {
ph = pnode->GetData ();
ph->base = base;
ph->size = size;
ph->end = base + size;
ph->obj = obj;
ph->access = access;
PhysioMapNode::AddHead (&headPhysioMap, pnode);
}
return pnode ? 0 : -1;
}
void mmi_unmap_physio(uint64_t base, uint64_t size, void* obj)
{
PhysioMapNode *pnode, *prev;
for (prev = NULL, pnode = headPhysioMap; pnode; pnode = pnode->Next()) {
PhysioMap* pmap = pnode->GetData();
if (pmap->obj == obj && pmap->base == base && pmap->size == size) {
PhysioMapNode::DeleteNode(&headPhysioMap, prev);
break;
}
prev = pnode;
}
}