URL
https://opencores.org/ocsvn/socgen/socgen/trunk
Subversion Repositories socgen
[/] [socgen/] [trunk/] [tools/] [verilog/] [trace_bus] - Rev 131
Go to most recent revision | Compare with Previous | Blame | View Log
eval 'exec `which perl` -S $0 ${1+"$@"}'
if 0;
#/**********************************************************************/
#/* */
#/* ------- */
#/* / SOC \ */
#/* / GEN \ */
#/* / TOOL \ */
#/* ============== */
#/* | | */
#/* |____________| */
#/* */
#/* */
#/* */
#/* */
#/* Author(s): */
#/* - John Eaton, jt_eaton@opencores.org */
#/* */
#/**********************************************************************/
#/* */
#/* Copyright (C) <2010-2011> <Ouabache Design Works> */
#/* */
#/* This source file may be used and distributed without */
#/* restriction provided that this copyright statement is not */
#/* removed from the file and that any derivative work contains */
#/* the original copyright notice and the associated disclaimer. */
#/* */
#/* This source file is free software; you can redistribute it */
#/* and/or modify it under the terms of the GNU Lesser General */
#/* Public License as published by the Free Software Foundation; */
#/* either version 2.1 of the License, or (at your option) any */
#/* later version. */
#/* */
#/* This source 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 Lesser General Public License for more */
#/* details. */
#/* */
#/* You should have received a copy of the GNU Lesser General */
#/* Public License along with this source; if not, download it */
#/* from http://www.opencores.org/lgpl.shtml */
#/* */
#/**********************************************************************/
############################################################################
# General PERL config
############################################################################
use Getopt::Long;
use English;
use File::Basename;
use Cwd;
use Scalar::Util qw(looks_like_number);
use XML::LibXML;
use lib './tools';
use sys::lib;
use yp::lib;
use BerkeleyDB;
$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.
############################################################################
### Process the options
############################################################################
Getopt::Long::config("require_order", "prefix=-");
GetOptions("h","help",
"envidentifier=s" => \$envidentifier,
"prefix=s" => \$prefix,
"vendor=s" => \$vendor,
"library=s" => \$library,
"component=s" => \$component,
"version=s" => \$version,
"path=s" => \$path,
"bus_name=s" => \$bus_name,
"test_name=s" => \$test_name
) || die "(use '$program_name -h' for help)";
##############################################################################
## Help option
##############################################################################
if ( $opt_h or $opt_help )
{ print "\n trace_bus -envidentifier {sim/syn} -prefix /work -vendor vendor_name -library library_name -component component_name -version version_name -path root.dut.core.cpu -bus_name cpu \n";
exit 1;
}
#############################################################################
##
##
#############################################################################
$home = cwd();
unless ($prefix)
{
$prefix = yp::lib::get_workspace();
$prefix = "/${prefix}";
}
unless ($path)
{
$path = "root";
}
my $variant;
my $dest_dir = "elab";
my $destination = "${component}_${version}";
if($test_name){ $destination = "${component}_${version}_${test_name}";}
my @reg_list ="";
my @param_list ="";
my $root = "root";
if($version) {$variant = "${component}_${version}";}
else {$variant = "${component}";}
print "trace_bus -prefix $prefix -vendor $vendor -library $library -component $component -version $version -path $path -bus_name $bus_name -test_name $test_name \n";
my $parser = XML::LibXML->new();
my $socgen_file = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));
#unless ($socgen_file) { print "No socgen ip file \n";};
my $comp_xml_sep = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
my $lib_comp_sep = yp::lib::find_lib_comp_sep($vendor,$library,$component);
my $root_path = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/../${dest_dir}/${destination}";
my $sw_dir = "${root_path}/sw";
mkdir $sw_dir,0755 unless( -e $sw_dir );
my $output_file = "${sw_dir}/${path}_${bus_name}.v";
$output_file =~s/root.dut.//;
open PARAM_FILE,">$output_file" or die "unable to open $output_file";
my $output_file = "${sw_dir}/${path}_${bus_name}.h";
$output_file =~s/root.dut.//;
open PARAMH_FILE,">$output_file" or die "unable to open $output_file";
my $report_dir = "${root_path}/memmaps";
mkdir $report_dir,0755 unless( -e $report_dir );
$output_file = "${report_dir}/${path}_${bus_name}.txt";
$output_file =~s/root.dut.//;
open DEST_FILE,">$output_file" or die "unable to open $output_file";
my $data_db_file = "${root_path}/root.db";
unless(-e $data_db_file )
{
print "$data_db_file root file does not exist \n";
}
my $root_db = new BerkeleyDB::Hash( -Filename => "$data_db_file", -Flags => DB_CREATE ) or die "Cannot open $data_db_file: $!";
my $comp_data;
my $bd_vendor;
my $bd_library;
my $bd_component;
my $bd_version;
#print "STARTING $path :: $bus_name \n";
$root_db->db_get("component___${path}", $comp_data );
( $vendor,$library,$component,$version) = split( /\:/ , $comp_data);
#print "XXXXX $path $vendor $library $component $version $bus_name \n";
my $instance_path = yp::lib::get_io_ports;
my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version);
my $instance_db_file = "${instance_path}/${vendor}__${library}/${component}/${main_module_name}_BUSSES.dbm";
unless(-e $instance_db_file )
{
print "$instance_db_file instance file does not exist \n";
}
my $instance_db = new BerkeleyDB::Hash( -Filename => "$instance_db_file", -Flags => DB_CREATE ) or die "Cannot open $instance_db_file: $!";
my $base_addr = hex(0x0000);
my $repo_data;
$instance_db->db_get("AbsDef.${bus_name}.master", $repo_data );
if($repo_data)
{
( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
# print "MASTER $bd_vendor $bd_library $bd_component $bd_version \n";
$repo_data = "";
$_ = "$path";
if(/(\S+)\.(\S+)/)
{
$path = $1;
}
follow_bus("${path}",$bus_name,$base_addr);
}
$instance_db->db_get("AbsDef.${bus_name}.slave", $repo_data );
$instance_db->db_close();
if($repo_data)
{
( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
# print "SLAVE $bd_vendor $bd_library $bd_component $bd_version \n";
$repo_data = "";
follow_bus("${path}",$bus_name,$base_addr);
}
$root_db->db_close();
@reg_list = sys::lib::trim_sort(@reg_list);
foreach my $reg_line (@reg_list)
{
print DEST_FILE "$reg_line \n";
}
@param_list = sys::lib::trim_sort(@param_list);
foreach my $param_line (@param_list)
{
( $address,$parameter) = split( /\:/ , $param_line);
if($parameter)
{
print PARAM_FILE "parameter $parameter = $address ; \n";
print PARAMH_FILE "$parameter = $address ; \n";
}
}
#print "FINISHED \n";
sub follow_bus
{
my @params = @_;
my $base_addr = pop(@params);
my $bus_name = pop(@params);
my $path = pop(@params);
my $vendor;
my $library;
my $component;
my $version;
my $comp_data;
my $bd_vendor;
my $bd_library;
my $bd_component;
my $bd_version;
my $repo_data;
# print "START_FOLLOW $path == $bus_name \n";
$root_db->db_get("component___${path}", $comp_data );
( $vendor,$library,$component,$version) = split( /\:/ , $comp_data);
# print "QQQQQQ $path || $vendor $library $component $version == $bus_name \n";
my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version);
my $instance_path = yp::lib::get_io_ports;
my $instance_db_file = "${instance_path}/${vendor}__${library}/${component}/${main_module_name}_BUSSES.dbm";
unless(-e $instance_db_file )
{
print "$instance_db_file instance file does not exist \n";
}
my $instance_db = new BerkeleyDB::Hash( -Filename => "$instance_db_file", -Flags => DB_CREATE ) or die "Cannot open $instance_db_file: $!";
$instance_db->db_get("AbsDef.${bus_name}.master", $repo_data );
if($repo_data)
{
( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
# print "MASTER $bd_vendor $bd_library $bd_component $bd_version \n";
$repo_data = "";
}
$instance_db->db_get("AbsDef.${bus_name}.interconnect", $repo_data );
if($repo_data)
{
my @couples = split( /\:/ , $repo_data);
foreach my $pair (@couples)
{
my $new_instance;
my $new_bus_name;
($new_instance,$new_bus_name) = split( /\.\./ , $pair);
# print "INTC $path $new_instance == $new_bus_name \n";
follow_bus("${path}.${new_instance}",$new_bus_name,$base_addr);
return(1);
}
$repo_data = "";
}
$instance_db->db_get("AbsDef.${bus_name}.slave", $repo_data );
if($repo_data)
{
( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
# print "SLAVE $bd_vendor $bd_library $bd_component $bd_version \n";
$repo_data = "";
$instance_db->db_get("AbsDef.${bus_name}.bridge", $repo_data );
if($repo_data)
{
$_ = "$path";
if(/(\S+)\.(\S+)/)
{
$path = $1;
}
my @couples = split( /\::/ , $repo_data);
foreach my $pair (@couples)
{
my $new_bus_name;
my $new_base_addr;
($new_bus_name,$new_base_addr) = split( /\.\./ , $pair);
my $mapped_addr = $base_addr + $new_base_addr;
# print "BRIDGE $path == ${bus_name} $new_bus_name $mapped_addr \n";
$instance_db->db_get("BlkDef.${bus_name}.${new_bus_name}", $Repo_data );
# print "BlkDef.${bus_name}.${new_bus_name} $Repo_data \n";
( $Base,$Range) = split( /\::/ , $Repo_data);
$Saddr = $Base + $base_addr;
$Eaddr = $Base + $base_addr + $Range-1;
# print "FRRRRRRRR $base_addr $Base $Range $Saddr $Eaddr \n";
my $hex = sprintf("0x%04x",$Saddr);
push @reg_list ,"$hex ${component}.${path} ($component) ${bus_name} Start " ;
$hex = sprintf("0x%04x",$Eaddr);
push @reg_list ,"$hex ${bus_name} End " ;
follow_bus( "${path}",$new_bus_name,$mapped_addr);
}
$repo_data = "";
}
else
{
# print "Now dump registers for $path $bus_name $base_addr\n";
my $hex = sprintf("0x%04x",$base_addr);
my $key;
my $value;
my $RegDef;
my $reg_bus;
my $reg_name;
my $cursor = $instance_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0)
{
($RegDef,$reg_bus,$reg_name) = split( /\./ , $key);
# print " $key $value \n";
if( ($RegDef eq "RegDef") && ($reg_bus eq $bus_name))
{
( $Xoffset,$Xname,$Xsize,$Xaccess) = split( /\::/ , $value);
$addr = $base_addr + $Xoffset;
my $hex = sprintf("0x%04x %16s ",$addr, $Xname);
push @reg_list ,"$hex $Xsize $Xaccess";
my $temp = "${path}_${Xname}";
$temp =~s/root.dut.//;
$temp =~s/\./_/g;
$hex = sprintf("'h%04x:%16s ",$addr, $temp);
if($hex) {push @param_list ,"$hex";}
# print " $addr $Xname $Xsize $Xaccess \n";
}
if( ($RegDef eq "BlkDef") && ($reg_bus eq $bus_name))
{
( $Base,$Range) = split( /\::/ , $value);
$Saddr = $Base + $base_addr;
$Eaddr = $Base + $base_addr + $Range-1;
#print "FRRRRRRRR $base_addr $Base $Range $Saddr $Eaddr \n";
my $hex = sprintf("0x%04x",$Saddr);
push @reg_list ,"$hex ${component}.${path} ($component) ${bus_name} Start " ;
$hex = sprintf("0x%04x",$Eaddr);
push @reg_list ,"$hex ${bus_name} End " ;
}
}
my $status = $cursor->c_close() ;
}
}
$instance_db->db_get("AbsDef.${bus_name}.node", $repo_data );
if($repo_data)
{
( $bd_vendor,$bd_library,$bd_component,$bd_version) = split( /\:/ , $repo_data);
# print "NODE $bd_vendor $bd_library $bd_component $bd_version \n";
$repo_data = "";
$instance_db->db_get("AbsDef.${bus_name}.interconnect", $repo_data );
if($repo_data)
{
# print "INTC $repo_data \n";
my @couples = split( /\:/ , $repo_data);
foreach my $pair (@couples)
{
my $new_instance;
my $new_bus_name;
($new_instance,$new_bus_name) = split( /\.\./ , $pair);
# print "NODE $path $new_instance == $new_bus_name \n";
follow_bus("${path}.${new_instance}",$new_bus_name,$base_addr);
return(1);
}
}
}
$instance_db->db_close();
return(0);
}
1
Go to most recent revision | Compare with Previous | Blame | View Log