sbsv1/abld/platform/sym_lkup_util.pl
author kelvzhu
Thu, 08 Jul 2010 11:07:48 +0800
changeset 611 75fabbc53db5
parent 606 30b30f9da0b7
child 633 a4eca1f021ac
permissions -rw-r--r--
Release-Update
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;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    47
my $PatchVersion = 0;
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
{
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    51
	unless (GetOptions(\%Options, 'sym=s', 'o=s', 'map=s', 'ignore_export_dir')) {
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
606
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    59
	unless($ImportSymFile)
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    60
	{
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",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    66
			 " -sym symbol file\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    67
			 " -o   output file\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    68
			 " -map  map file\n",
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    69
			 "\n"
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    70
		);
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    71
		exit 1;
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    72
	}
30b30f9da0b7 Add ..\dev\.. to path
jjkang
parents: 599
diff changeset
    73
599
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    74
	ReadSymFile() if $ImportSymFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    75
	ReadMapFile() if $mapFile;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    76
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    77
	GenNamedSegment();
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    78
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    79
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    80
sub ReadMapFile() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    81
	open FILE, $mapFile or die "Error :SymLookup: Cannot open map file $mapFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    82
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    83
	my $GlbSyms = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    84
	while(<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    85
		if($_ =~ /Public Symbols/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    86
			$GlbSyms = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    87
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    88
		elsif( !$GlbSyms ) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    89
			next;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    90
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    91
		if($_ =~ /([0-9a-fA-F]{8})\s+(\S+)\s+_?(\S+)\s/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    92
			$addr = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    93
			$module = $2;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    94
			$name = $3;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    95
			if( defined $Symbols{$name} ) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    96
				$Symbols{$name} = $addr;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
    97
			}
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
#	Remove symbols not found in map file
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   101
	foreach my $sym (keys %Symbols){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   102
		if( !$Symbols{$sym} ){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   103
			delete $Symbols{$sym};
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   104
		}
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
sub ReadSymFile() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   110
	open FILE, $ImportSymFile or die "Error :SymLookup: Cannot open file $ImportSymFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   111
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   112
	my $ImportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   113
	my $ExportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   114
	my $ExportNameTblSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   115
	my $numOfExportNames = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   116
	my $nameCount = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   117
	while (<FILE>) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   118
# 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
   119
# 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
   120
# are filtered out and then looked up in the map file for their addresses.
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   121
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   122
		if($_ =~ /\*\*\* EXPORT DIRECTORY \*\*\*/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   123
			next if($IgnoreExportDir);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   124
			$ExportDirSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   125
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   126
		elsif($_ =~ /\*\*\* Export Name Pointer Table \*\*\*/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   127
			next if($IgnoreExportDir);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   128
			$ExportNameTblSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   129
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   130
		elsif($_ =~ /\*\*\* IMPORT DIRECTORY \*\*\*/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   131
			$ImportDirSeen = 1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   132
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   133
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   134
		if($ExportDirSeen){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   135
			if($_ =~ /numberofnames\s+=\s+0x(\S+)/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   136
				$numOfExportNames = hex($1);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   137
# Reset the flag once done with the export table
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   138
				$ExportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   139
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   140
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   141
		elsif($ExportNameTblSeen && $numOfExportNames){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   142
			if($_ =~ /\d+\s+0x[0-9a-fA-F]+\s+(\S+)/){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   143
				$Symbols{$1}=0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   144
# Keep track of the symbols seen in "Export Name Pointer Table"
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   145
				$nameCount++;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   146
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   147
			if($nameCount == $numOfExportNames){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   148
# Reset the flag once done with the name table
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   149
				$ExportNameTblSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   150
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   151
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   152
		elsif($ImportDirSeen) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   153
			if($_ =~ /^DLL name\s+=\s+\S+\s+\((\S+)\)/) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   154
				my $dllname = $1;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   155
				push @Imports, $dllname;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   156
				$ImportDirSeen = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   157
			}
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
sub GenNamedSegment() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   163
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   164
	my $SegContents = "";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   165
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   166
	&Header(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   167
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   168
	&SymAddrTbl(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   169
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   170
	&SymNames(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   171
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   172
	&Footer(\$SegContents);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   173
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   174
	open OUTFILE, ">$CppFile" or die "Error :SymLookup:Cannot open file $CppFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   175
	print OUTFILE $SegContents;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   176
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   177
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   178
sub Header(){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   179
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   180
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   181
	$$SegContentsRef .= "\/\* $CppFile\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   182
	$$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
   183
	$$SegContentsRef .= " \* Makmake-generated source file for named symbol lookup\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   184
	$$SegContentsRef .= " \*\/\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   185
	$$SegContentsRef .= "#pragma data_seg(\".expdata\")";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   186
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   187
	$$SegContentsRef .= "\n\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   188
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   189
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   190
sub Footer() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   191
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   192
	$$SegContentsRef .= "\n#pragma data_seg()\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   193
	$$SegContentsRef .= "\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   194
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   195
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   196
sub SymAddrTbl(){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   197
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   198
	$nSyms = keys %Symbols;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   199
	$nImports = @Imports;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   200
	$$SegContentsRef .= "int NSymbols = $nSyms;\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   201
	$$SegContentsRef .= "int NImports = $nImports;\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   202
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   203
	if(!$nSyms) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   204
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   205
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   206
	$$SegContentsRef .= "int addresses[] = {\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   207
	
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   208
	foreach $key (sort keys %Symbols) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   209
		if($Symbols{$key}){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   210
			$$SegContentsRef .= "\t0x".$Symbols{$key}.",\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   211
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   212
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   213
	$$SegContentsRef .= "};\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   214
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   215
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   216
sub SymNames() {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   217
	if(!$nImports && !$nSyms){
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   218
		return;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   219
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   220
	my $SegContentsRef = shift @_;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   221
	$$SegContentsRef .= "\nchar data[] = {\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   222
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   223
	my $symnames ;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   224
	my $colCnt ;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   225
	foreach $symnames (sort keys %Symbols) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   226
		next if( $Symbols{$symnames} == 0);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   227
		my @chars = split(//,$symnames);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   228
		$$SegContentsRef .= "\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   229
		$colCnt =0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   230
		foreach $aChar (@chars) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   231
			if($colCnt >= 80) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   232
				$$SegContentsRef .= "\\\n\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   233
				$colCnt = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   234
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   235
			$$SegContentsRef .= "\'$aChar\',";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   236
			$colCnt += 4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   237
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   238
		$$SegContentsRef .= "0,\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   239
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   240
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   241
	foreach my $dll (@Imports) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   242
		my @chars = split(//,$dll);
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   243
		$$SegContentsRef .= "\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   244
		$colCnt =0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   245
		foreach $aChar (@chars) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   246
			if($colCnt >= 80) {
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   247
				$$SegContentsRef .= "\\\n\t";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   248
				$colCnt = 0;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   249
			}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   250
			$$SegContentsRef .= "\'$aChar\',";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   251
			$colCnt += 4;
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   252
		}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   253
		$$SegContentsRef .= "0,\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   254
	}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   255
	$$SegContentsRef .= "\n};\n";
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   256
}
fa7a3cc6effd Add sbsv1 to new structure
jjkang
parents:
diff changeset
   257