Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / ss / api / pli / src / SS_GoodBadTrap.cc
// ========== Copyright Header Begin ==========================================
//
// OpenSPARC T2 Processor File: SS_GoodBadTrap.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_GoodBadTrap.h"
SS_GoodBadTrap::SS_GoodBadTrap( )/*{{{*/
:
good_trap_count(0),
bad_trap_count(0)
{}
/*}}}*/
void SS_GoodBadTrap::read_good_bad_trap( int va_bits )/*{{{*/
{
// extract good/bad trap addresses from symbol.tbl
// N2 sample:
// .HTRAPS.HT0_GoodTrap_0x100 0000000000082000 X 0000082000
// .HTRAPS.HT0_GoodTrap_0x1a0 0000000000083400 X 0000083400
// .HTRAPS.old_good_trap 0000000000083400 X 0000083400
// .HTRAPS.good_trap 0000000000083400 X 0000083400
// .TRAPS.T0_GoodTrap_0x100 0000000000122000 0000122000 0200122000
// .TRAPS.T1_GoodTrap_0x100 0000000000126000 0000126000 0200126000
// .HTRAPS.HT0_BadTrap_0x101 0000000000082020 X 0000082020
// .HTRAPS.HT0_BadTrap_0x1a1 0000000000083420 X 0000083420
// .HTRAPS.bad_trap 0000000000083420 X 0000083420
// .TRAPS.T0_BadTrap_0x101 0000000000122020 0000122020 0200122020
// .TRAPS.T1_BadTrap_0x101 0000000000126020 0000126020 0200126020
// N3 sample:
// .RED_SEC.good_trap fffffffff000013c X fff000013c
// .RED_SEC.bad_trap fffffffff0000140 X fff0000140
// N3 sample, of a different diag
// .RED_SEC.good_trap fffffffff0005138 X fff0005138
// .RED_SEC.bad_trap fffffffff000514c X fff000514c
char l[256];
char *s1, *s2;
SS_Vaddr n;
FILE *f = fopen("symbol.tbl", "r");
if (f == NULL)
{
// file is not available for read
fprintf(stderr, "WARNING: symbol.tbl is not loaded\n");
return;
}
while (fgets(l, sizeof(l), f))
{
s1 = strtok(l, " \t\n");
while (s1)
{
if (strstr(s1, "GoodTrap") ||
strstr(s1, "good_trap"))
{
s2 = strtok(NULL, " \t\n");
if (s2) {
n = strtoull(s2, NULL, 16);
//fprintf(stderr, "GOOD %s %llx\n", s1, n);
// sign extends the given virtual address from VA_BITS to 64 bits
n = (n << (64 - va_bits)) >> (64 - va_bits);
int match = 0;
for (int i = 0; i < good_trap_count; i++)
{
if (n == good_traps[i])
{
match = 1;
break;
}
}
if (match == 0)
{
good_traps[good_trap_count] = n;
good_trap_count++;
}
// done with this line, go read the next line
break;
}
}
else if (strstr(s1, "BadTrap") ||
strstr(s1, "bad_trap"))
{
s2 = strtok(NULL, " \t\n");
if (s2) {
n = strtoull(s2, NULL, 16);
//fprintf(stderr, "BAD %s %llx\n", s1, n);
// sign extends the given virtual address from VA_BITS to 64 bits
n = (n << (64 - va_bits)) >> (64 - va_bits);
int match = 0;
for (int i = 0; i < bad_trap_count; i++)
{
if (n == bad_traps[i])
{
match = 1;
break;
}
}
if (match == 0)
{
bad_traps[bad_trap_count] = n;
bad_trap_count++;
}
// done with this line, go read the next line
break;
}
}
s1 = strtok(NULL, " \t\n");
}
}
fclose(f);
}
/*}}}*/
int SS_GoodBadTrap::hit_good_bad_trap( SS_Vaddr pc )/*{{{*/
{
for (int i = 0; i < good_trap_count; i++)
{
if (pc == good_traps[i])
{
fflush(stdout);
fprintf(stdout, "\nHit good trap %#llx\n\n", pc);
return -1;
}
}
for (int i = 0; i < bad_trap_count; i++)
{
if (pc == bad_traps[i])
{
// .RED_SEC.bad_trap fffffffff0000140 X fff0000140
fflush(stdout);
fprintf(stdout, "\nHit bad trap %#llx\n\n", pc);
return -1;
}
}
// no match
return 0;
}
/*}}}*/