sbsv1/abld/platform/sym_lkup_util.pl
author Zheng Shen <zheng.shen@nokia.com>
Wed, 27 Oct 2010 19:35:19 +0800
changeset 664 44b0e894b7ab
parent 633 a4eca1f021ac
permissions -rw-r--r--
Merge again
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     1
#!/usr/bin/perl
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     2
# Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     3
# All rights reserved.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     5
# under the terms of "Eclipse Public License v1.0"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     8
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
     9
# Initial Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    11
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    12
# Contributors:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    13
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    14
# Description:
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    15
#
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    16
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    17
use FindBin;		# for FindBin::Bin
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    18
use Getopt::Long;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    19
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    20
BEGIN {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    21
# check user has a version of perl that will cope
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    22
	require 5.005_03;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    23
# establish the path to the Perl libraries: currently the same directory as this script
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    24
	$PerlLibPath = $FindBin::Bin;	# X:/epoc32/tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    25
	if ($^O eq "MSWin32")
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    26
	{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    27
		$PerlLibPath =~ s/\//\\/g;	# X:\epoc32\tools
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    28
		$PerlLibPath .= "\\";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    29
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    30
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    31
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    32
use lib $PerlLibPath;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    33
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    34
my $IgnoreExportDir = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    35
my $ImportSymFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    36
my $CppFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    37
my $mapFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    38
my $SegmentContentSz = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    39
my $nSyms = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    40
my $nImports = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    41
my %Symbols = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    42
my @Imports = ();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    43
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    44
# Version
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    45
my $MajorVersion = 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    46
my $MinorVersion = 1;
633
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    47
my $PatchVersion = 1;
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    48
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    49
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    50
{
633
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    51
	unless (GetOptions(\%Options, 'sym=s', 'o=s', 'map=s', 'ignore_export_dir','h')) {
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    52
		exit 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    53
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    54
	$ImportSymFile = $Options{sym};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    55
	$CppFile = $Options{o};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    56
	$mapFile = $Options{map};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    57
	$IgnoreExportDir = $Options{ignore_export_dir};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    58
633
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    59
	my $help = $Options{h};
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    60
	if($help) {
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    61
		print(
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    62
			 "\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    63
			 "SYM_LKUP_UTIL symbol process tool V$MajorVersion.$MinorVersion.$PatchVersion\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    64
			 "\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    65
			 "options:\n",
633
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    66
			 " -sym\tsymbol file\n",
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    67
			 " -o\toutput file\n",
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    68
			 " -map\tmap file\n",
a4eca1f021ac ROMTools-13.1.0.2
Zheng Shen <zheng.shen@nokia.com>
parents: 606
diff changeset
    69
			 " -h\tprint this message\n",
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    70
			 "\n"
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    71
		);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    72
		exit 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    73
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    74
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	ReadSymFile() if $ImportSymFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	ReadMapFile() if $mapFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
	GenNamedSegment();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
sub ReadMapFile() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
	open FILE, $mapFile or die "Error :SymLookup: Cannot open map file $mapFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	my $GlbSyms = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
	while(<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
		if($_ =~ /Public Symbols/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
			$GlbSyms = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
		elsif( !$GlbSyms ) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
		if($_ =~ /([0-9a-fA-F]{8})\s+(\S+)\s+_?(\S+)\s/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
			$addr = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
			$module = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
			$name = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
			if( defined $Symbols{$name} ) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
				$Symbols{$name} = $addr;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    98
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    99
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   100
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
#	Remove symbols not found in map file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
	foreach my $sym (keys %Symbols){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
		if( !$Symbols{$sym} ){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
			delete $Symbols{$sym};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   105
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   106
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   107
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   108
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   109
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
sub ReadSymFile() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
	open FILE, $ImportSymFile or die "Error :SymLookup: Cannot open file $ImportSymFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
	my $ImportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
	my $ExportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
	my $ExportNameTblSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
	my $numOfExportNames = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
	my $nameCount = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
	while (<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   119
# Ignore export table(s) if the flag '$IgnoreExportDir' is set. This flag is set for stddlls, as symbol listing 
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   120
# is not required for them. The windows API GetProcAddr can be used directly. While for stdexe, the symbol names
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
# are filtered out and then looked up in the map file for their addresses.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
		if($_ =~ /\*\*\* EXPORT DIRECTORY \*\*\*/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
			next if($IgnoreExportDir);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
			$ExportDirSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
		elsif($_ =~ /\*\*\* Export Name Pointer Table \*\*\*/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
			next if($IgnoreExportDir);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
			$ExportNameTblSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
		elsif($_ =~ /\*\*\* IMPORT DIRECTORY \*\*\*/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
			$ImportDirSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
		if($ExportDirSeen){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
			if($_ =~ /numberofnames\s+=\s+0x(\S+)/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
				$numOfExportNames = hex($1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
# Reset the flag once done with the export table
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
				$ExportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
		elsif($ExportNameTblSeen && $numOfExportNames){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
			if($_ =~ /\d+\s+0x[0-9a-fA-F]+\s+(\S+)/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
				$Symbols{$1}=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
# Keep track of the symbols seen in "Export Name Pointer Table"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
				$nameCount++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
			if($nameCount == $numOfExportNames){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
# Reset the flag once done with the name table
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
				$ExportNameTblSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
		elsif($ImportDirSeen) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
			if($_ =~ /^DLL name\s+=\s+\S+\s+\((\S+)\)/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
				my $dllname = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
				push @Imports, $dllname;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
				$ImportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   158
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   159
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   160
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   161
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   162
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
sub GenNamedSegment() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
	my $SegContents = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
	&Header(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
	&SymAddrTbl(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
	&SymNames(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
	&Footer(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
	open OUTFILE, ">$CppFile" or die "Error :SymLookup:Cannot open file $CppFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
	print OUTFILE $SegContents;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
sub Header(){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
	$$SegContentsRef .= "\/\* $CppFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   183
	$$SegContentsRef .= " \* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).  All rights reserved.\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
	$$SegContentsRef .= " \* Makmake-generated source file for named symbol lookup\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
	$$SegContentsRef .= " \*\/\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
	$$SegContentsRef .= "#pragma data_seg(\".expdata\")";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
	$$SegContentsRef .= "\n\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
sub Footer() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
	$$SegContentsRef .= "\n#pragma data_seg()\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
	$$SegContentsRef .= "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
sub SymAddrTbl(){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
	$nSyms = keys %Symbols;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
	$nImports = @Imports;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
	$$SegContentsRef .= "int NSymbols = $nSyms;\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
	$$SegContentsRef .= "int NImports = $nImports;\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
	if(!$nSyms) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
	$$SegContentsRef .= "int addresses[] = {\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
	foreach $key (sort keys %Symbols) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
		if($Symbols{$key}){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
			$$SegContentsRef .= "\t0x".$Symbols{$key}.",\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
	$$SegContentsRef .= "};\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
sub SymNames() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
	if(!$nImports && !$nSyms){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
	$$SegContentsRef .= "\nchar data[] = {\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
	my $symnames ;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
	my $colCnt ;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
	foreach $symnames (sort keys %Symbols) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
		next if( $Symbols{$symnames} == 0);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
		my @chars = split(//,$symnames);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
		$$SegContentsRef .= "\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
		$colCnt =0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
		foreach $aChar (@chars) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
			if($colCnt >= 80) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
				$$SegContentsRef .= "\\\n\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
				$colCnt = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
			$$SegContentsRef .= "\'$aChar\',";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
			$colCnt += 4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
		$$SegContentsRef .= "0,\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
	foreach my $dll (@Imports) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
		my @chars = split(//,$dll);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
		$$SegContentsRef .= "\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
		$colCnt =0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
		foreach $aChar (@chars) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
			if($colCnt >= 80) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
				$$SegContentsRef .= "\\\n\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
				$colCnt = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
			$$SegContentsRef .= "\'$aChar\',";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
			$colCnt += 4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
		$$SegContentsRef .= "0,\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
	$$SegContentsRef .= "\n};\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   258