#!/usr/bin/perl -w
|
#!/usr/bin/perl -w
|
#
|
#
|
# ############################################################################
|
# ############################################################################
|
#
|
#
|
# vec2dump.pl
|
# vec2dump.pl
|
#
|
#
|
# $Id: vec2dump.pl,v 1.1 2004-04-09 19:16:00 arniml Exp $
|
# $Id: vec2dump.pl,v 1.1 2004-04-09 19:16:00 arniml Exp $
|
#
|
#
|
# Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
|
# Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
|
#
|
#
|
# All rights reserved
|
# All rights reserved
|
#
|
#
|
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
# (at your option) any later version. See also the file COPYING which
|
# (at your option) any later version. See also the file COPYING which
|
# came with this application.
|
# came with this application.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
#
|
#
|
# ############################################################################
|
# ############################################################################
|
#
|
#
|
# Purpose:
|
# Purpose:
|
# ========
|
# ========
|
#
|
#
|
# Converts a vector file into the dump format for dump_compare.
|
# Converts a vector file into the dump format for dump_compare.
|
#
|
#
|
# A vector stream is read from STDIN and the resulting dump is written
|
# A vector stream is read from STDIN and the resulting dump is written
|
# to STDOUT.
|
# to STDOUT.
|
#
|
#
|
|
|
|
|
use strict;
|
use strict;
|
|
|
|
|
sub bin2hex {
|
sub bin2hex {
|
my $string = shift;
|
my $string = shift;
|
my ($bit, $hex);
|
my ($bit, $hex);
|
|
|
$hex = 0;
|
$hex = 0;
|
foreach $bit (split(//, $string)) {
|
foreach $bit (split(//, $string)) {
|
$hex <<= 1;
|
$hex <<= 1;
|
$hex |= $bit;
|
$hex |= $bit;
|
}
|
}
|
|
|
return(sprintf("%02X", $hex));
|
return(sprintf("%02X", $hex));
|
}
|
}
|
|
|
sub hex8 {
|
sub hex8 {
|
my $uint = shift;
|
my $uint = shift;
|
|
|
if ($uint =~ /^b(.+)$/) {
|
if ($uint =~ /^b(.+)$/) {
|
return(bin2hex($1));
|
return(bin2hex($1));
|
} else {
|
} else {
|
return('??');
|
return('??');
|
}
|
}
|
}
|
}
|
|
|
sub hex16 {
|
sub hex16 {
|
my $uint = shift;
|
my $uint = shift;
|
|
|
if ($uint =~ /^b(.+)(........)$/) {
|
if ($uint =~ /^b(.+)(........)$/) {
|
return(bin2hex($1).bin2hex($2));
|
return(bin2hex($1).bin2hex($2));
|
} else {
|
} else {
|
return('????');
|
return('????');
|
}
|
}
|
}
|
}
|
|
|
sub dump_ram {
|
sub dump_ram {
|
my $ram = shift;
|
my $ram = shift;
|
my $elem;
|
my $elem;
|
|
|
foreach $elem (@{$ram}) {
|
foreach $elem (@{$ram}) {
|
print($elem.' ');
|
print($elem.' ');
|
}
|
}
|
}
|
}
|
|
|
|
|
my (@signals, %index, @vector);
|
my (@signals, %index, @vector);
|
my $i;
|
my $i;
|
my $value;
|
my $value;
|
my $line;
|
my $line;
|
my $istrobe;
|
my $istrobe;
|
my @ram;
|
my @ram;
|
|
|
|
|
# initialize RAM
|
# initialize RAM
|
for ($i = 0; $i < 256; $i++) {
|
for ($i = 0; $i < 256; $i++) {
|
$ram[$i] = '00';
|
$ram[$i] = '00';
|
}
|
}
|
|
|
|
|
# scan for signal names
|
# scan for signal names
|
while (<STDIN>) {
|
while (<STDIN>) {
|
if (/^(\S+):/) {
|
if (/^(\S+):/) {
|
chomp($_);
|
chomp($_);
|
@signals = split(/ +/);
|
@signals = split(/ +/);
|
|
|
# remove time information
|
# remove time information
|
shift(@signals);
|
shift(@signals);
|
last;
|
last;
|
}
|
}
|
}
|
}
|
|
|
# build index
|
# build index
|
for ($i = 0; $i < scalar(@signals); $i++) {
|
for ($i = 0; $i < scalar(@signals); $i++) {
|
# strip off hierarchical path
|
# strip off hierarchical path
|
$signals[$i] =~ s/.*\.//;
|
$signals[$i] =~ s/.*\.//;
|
$index{$signals[$i]} = $i;
|
$index{$signals[$i]} = $i;
|
}
|
}
|
|
|
$istrobe = 0;
|
$istrobe = 0;
|
# read vectors
|
# read vectors
|
while (<STDIN>) {
|
while (<STDIN>) {
|
if (/^\d+> /) {
|
if (/^\d+> /) {
|
chop($_);
|
chop($_);
|
@vector = split(/ +/);
|
@vector = split(/ +/);
|
|
|
# remove time information
|
# remove time information
|
shift(@vector);
|
shift(@vector);
|
|
|
# process write operation to RAM
|
# process write operation to RAM
|
if ($vector[$index{'we_tmp'}] eq '1') {
|
if ($vector[$index{'we_tmp'}] eq '1') {
|
$ram[hex(hex8($vector[$index{'address_tmp[7:0]'}]))] = hex8($vector[$index{'data_tmp[7:0]'}]);
|
$ram[hex(hex8($vector[$index{'address_tmp[7:0]'}]))] = hex8($vector[$index{'data_tmp[7:0]'}]);
|
}
|
}
|
|
|
# find falling instruction strobe
|
# find falling instruction strobe
|
if ($istrobe == 0) {
|
if ($istrobe == 0) {
|
$istrobe = $vector[0];
|
$istrobe = $vector[0];
|
next;
|
next;
|
} else {
|
} else {
|
$istrobe = $vector[0];
|
$istrobe = $vector[0];
|
if ($vector[0] == 0) {
|
if ($vector[0] == 0) {
|
# falling edge detected
|
# falling edge detected
|
} else {
|
} else {
|
next;
|
next;
|
}
|
}
|
}
|
}
|
|
|
# process each signal
|
# process each signal
|
for ($i = 1; $i < scalar(@vector); $i++) {
|
for ($i = 1; $i < scalar(@vector); $i++) {
|
$_ = $signals[$i];
|
$_ = $signals[$i];
|
$line = '';
|
$line = '';
|
|
|
SWITCH: {
|
SWITCH: {
|
if (/^program_counter/) { print(hex16($vector[$i]).' '); last; }
|
if (/^program_counter/) { print(hex16($vector[$i]).' '); last; }
|
if (/^accumulator/) { print(hex8($vector[$i]).' '); last; }
|
if (/^accumulator/) { print(hex8($vector[$i]).' '); last; }
|
if (/^sp/) { print(hex8($vector[$i]).' '); last; }
|
if (/^sp/) { print(hex8($vector[$i]).' '); last; }
|
if (/^psw/) { print(hex8($vector[$i]).' '); last; }
|
if (/^psw/) { print(hex8($vector[$i]).' '); last; }
|
if (/^bus/) { print(hex8($vector[$i]).' '); last; }
|
if (/^bus/) { print(hex8($vector[$i]).' '); last; }
|
if (/^f1/) { print($vector[$i].' '); last; }
|
if (/^f1/) { print($vector[$i].' '); last; }
|
if (/^p1/) { print(hex8($vector[$i]).' '); last; }
|
if (/^p1/) { print(hex8($vector[$i]).' '); last; }
|
if (/^p2/) { print(hex8($vector[$i]).' '); last; }
|
if (/^p2/) { print(hex8($vector[$i]).' '); last; }
|
if (/^mb/) { print($vector[$i].' '); last; }
|
if (/^mb/) { print($vector[$i].' '); last; }
|
if (/^we_tmp/) { dump_ram(\@ram); last; }
|
if (/^we_tmp/) { dump_ram(\@ram); last; }
|
}
|
}
|
}
|
}
|
print("\n");
|
print("\n");
|
}
|
}
|
}
|
}
|
|
|