Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / lib / cpu / src / SS_SnapShot.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: SS_SnapShot.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 <string.h>
#include "SS_SnapShot.h"
// The list here describes which class uses a particular
// SS_SnapShot::VERSION, e.g. where and what fix/change
// the version.
//
// 1 First version
// 2 SS_Message - pending interrupt
// 3 Rk_Strand - imu qd_reverse_map fix
// 4 SS_Cpu - strand_stepping grows to 128 bits for xx
SS_SnapShot::SS_SnapShot( FILE* f, bool _load )/*{{{*/
:
VERSION(4), // When bumped add line above to keep track
file(f),
load(_load),
status(OK)
{}
/*}}}*/
void SS_SnapShot::val( uint8_t* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
uint32_t _val;
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%x",_tag,&_val) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
else
*ptr = _val;
}
else
{
fprintf(file,"%s\t%x\n",tag,*ptr);
}
}
}
/*}}}*/
void SS_SnapShot::val( uint16_t* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
uint32_t _val;
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%x",_tag,&_val) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
else
*ptr = _val;
}
else
{
fprintf(file,"%s\t%x\n",tag,*ptr);
}
}
}
/*}}}*/
void SS_SnapShot::val( uint32_t* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
uint32_t _val;
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%x",_tag,&_val) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
else
*ptr = _val;
}
else
{
fprintf(file,"%s\t%x\n",tag,*ptr);
}
}
}
/*}}}*/
void SS_SnapShot::val( uint64_t* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
uint64_t _val;
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%llx",_tag,&_val) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
else
*ptr = _val;
}
else
{
fprintf(file,"%s\t%llx\n",tag,*ptr);
}
}
}
/*}}}*/
void SS_SnapShot::val( char* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%s",_tag,ptr) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
}
else
{
fprintf(file,"%s\t%s\n",tag,ptr);
}
}
}
/*}}}*/
void SS_SnapShot::val( bool* ptr )/*{{{*/
{
if (status == OK)
{
if (load)
{
char line[LINE_SIZE];
char _tag[LINE_SIZE];
int _val;
if (fgets(line,LINE_SIZE,file) == 0)
status = FILE_ERROR;
else if (sscanf(line,"%s%x",_tag,&_val) != 2)
status = LINE_ERROR;
else if (strcmp(tag,_tag) != 0)
status = TAG_ERROR;
else
*ptr = _val;
}
else
{
fprintf(file,"%s\t%x\n",tag,*ptr);
}
}
}
/*}}}*/