source: svn/trunk/newcon3bcm2_21bu/nexus/build/tools/jumptable/jumptable.pl @ 2

Last change on this file since 2 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 5.6 KB
Line 
1#!/usr/bin/perl
2#############################################################################
3#    (c)2010 Broadcom Corporation
4#
5# This program is the proprietary software of Broadcom Corporation and/or its licensors,
6# and may only be used, duplicated, modified or distributed pursuant to the terms and
7# conditions of a separate, written license agreement executed between you and Broadcom
8# (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
9# no license (express or implied), right to use, or waiver of any kind with respect to the
10# Software, and Broadcom expressly reserves all rights in and to the Software and all
11# intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
12# HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
13# NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
14#
15# Except as expressly set forth in the Authorized License,
16#
17# 1.     This program, including its structure, sequence and organization, constitutes the valuable trade
18# secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
19# and to use this information only in connection with your use of Broadcom integrated circuit products.
20#
21# 2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
22# AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
23# WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
24# THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
25# OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
26# LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
27# OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
28# USE OR PERFORMANCE OF THE SOFTWARE.
29#
30# 3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
31# LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
32# EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
33# USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
34# THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
35# ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
36# LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
37# ANY LIMITED REMEDY.
38#
39# $brcm_Workfile: jumptable.pl $
40# $brcm_Revision: 2 $
41# $brcm_Date: 9/21/10 2:47p $
42#
43# Module Description:
44# This perl script generates a file that contains all of the asm stubs for either
45# the forward or the reverse APIs. That is to say it is used twice, one for each.
46#
47# Revision History:
48#
49# $brcm_Log: /nexus/build/tools/jumptable/jumptable.pl $
50#
51# 2   9/21/10 2:47p erickson
52# SW7420-943: replace (void*) with jumptable entry type to clean up
53#  warning
54#
55# 1   8/12/10 1:49p ttrammel
56# SW7420-943: Merge NFE to main branch.
57#
58# NFE/3   5/21/10 1:19p ttrammel
59# SW7405-4364: Only remove symbol strings from firmware blob.
60#
61# NFE/2   5/18/10 3:30p ttrammel
62# SW7405-4315: Initial NFE check-in. Remove FEXPORT of syms.
63#
64#############################################################################
65use strict;
66
67my $i;
68my $index;
69my @funcs;
70my $varname;
71
72$index = 0;
73
74if ( $#ARGV < 2 )
75{
76   die "usage: jumptable.pl <jumptable source filename> <stub library filename> <input text file1> ... <input text file n>";
77}
78
79# First arg is the  unique variable tag so we can build multiple tables
80$varname = @ARGV[0];
81
82# Second arg is the name of the static library.  Remaining args are input text files for global function names.
83for ($i=3;$i<=$#ARGV;$i++)
84{
85   open INFILE, "< @ARGV[$i]" or die $!;
86
87   while (<INFILE>)
88   {
89      my $line = $_;
90      # Strip comments
91      $line =~ s/#.*?\n//g;
92      # Strip newline
93      chomp $line;
94      if ( length $line > 0 )
95      {
96         $funcs[$index] = $line;
97         $index++;
98      }
99   }
100
101   close INFILE
102}
103
104# Write jumptable itself to a file
105open OUTFILE, "> @ARGV[1]" or die $!;
106# Write banner
107print OUTFILE "/****************************************************\n";
108print OUTFILE "* This file is automatically generated.  Do not edit.\n";
109print OUTFILE "****************************************************/\n";
110print OUTFILE "\n";
111
112# First write prototypes to avoid warnings
113$i = 0;
114while ($i < $index)
115{
116   print OUTFILE "extern int $funcs[$i](void);\n";
117   $i++;
118}
119
120my $table_entry_type = "B_$varname\_Jumptable_Entry";
121# Write table itself
122print OUTFILE "\ntypedef int (*$table_entry_type)(void); \n";
123print OUTFILE "\n$table_entry_type B_$varname\_Jumptable[] = \n{\n";
124$i = 0;
125while ($i < $index)
126{
127   print OUTFILE "$funcs[$i],\n";
128   $i++;
129}
130print OUTFILE "($table_entry_type)-1\n};\n";
131print OUTFILE "\n$table_entry_type *p$varname\_Jumptable = B_$varname\_Jumptable;\n";
132
133close OUTFILE;
134
135# The kernel will place the jumptable address in $gp by convention.  Write stub .s file to call the function from the table.
136$i = 0;
137open OUTFILE, "> @ARGV[2]" or die $!;
138# Write banner
139print OUTFILE "/****************************************************\n";
140print OUTFILE "* This file is automatically generated.  Do not edit.\n";
141print OUTFILE "****************************************************/\n";
142print OUTFILE "\n";
143
144# For the reverse case, put our table pointer in this file as well
145if ($varname eq "Reverse") {
146print OUTFILE ".data\n.align 4\n.globl p$varname\_Jumptable\np$varname\_Jumptable: .space 4\n";
147}
148
149print OUTFILE ".text\n";
150
151while ($i < $index)
152{
153   my $offset = $i*4;
154   print OUTFILE ".globl $funcs[$i]\n.set noreorder\n$funcs[$i]:\nlw \$9,p$varname\_Jumptable\nlw \$8,$offset(\$9)\n";
155   print OUTFILE "j \$8\nnop\n.set reorder\n\n";
156
157   $i++;
158}
159close OUTFILE;
160
Note: See TracBrowser for help on using the repository browser.