| 1 | #!/usr/bin/perl |
|---|
| 2 | # (c)2003-2011 Broadcom Corporation |
|---|
| 3 | # |
|---|
| 4 | # This program is the proprietary software of Broadcom Corporation and/or its licensors, |
|---|
| 5 | # and may only be used, duplicated, modified or distributed pursuant to the terms and |
|---|
| 6 | # conditions of a separate, written license agreement executed between you and Broadcom |
|---|
| 7 | # (an "Authorized License"). Except as set forth in an Authorized License, Broadcom grants |
|---|
| 8 | # no license (express or implied), right to use, or waiver of any kind with respect to the |
|---|
| 9 | # Software, and Broadcom expressly reserves all rights in and to the Software and all |
|---|
| 10 | # intellectual property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU |
|---|
| 11 | # HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY |
|---|
| 12 | # NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
|---|
| 13 | # |
|---|
| 14 | # Except as expressly set forth in the Authorized License, |
|---|
| 15 | # |
|---|
| 16 | # 1. This program, including its structure, sequence and organization, constitutes the valuable trade |
|---|
| 17 | # secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof, |
|---|
| 18 | # and to use this information only in connection with your use of Broadcom integrated circuit products. |
|---|
| 19 | # |
|---|
| 20 | # 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
|---|
| 21 | # AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
|---|
| 22 | # WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO |
|---|
| 23 | # THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES |
|---|
| 24 | # OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, |
|---|
| 25 | # LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION |
|---|
| 26 | # OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF |
|---|
| 27 | # USE OR PERFORMANCE OF THE SOFTWARE. |
|---|
| 28 | # |
|---|
| 29 | # 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS |
|---|
| 30 | # LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR |
|---|
| 31 | # EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR |
|---|
| 32 | # USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF |
|---|
| 33 | # THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT |
|---|
| 34 | # ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE |
|---|
| 35 | # LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF |
|---|
| 36 | # ANY LIMITED REMEDY. |
|---|
| 37 | # |
|---|
| 38 | # $brcm_Workfile: bapi_build.pl $ |
|---|
| 39 | # $brcm_Revision: 6 $ |
|---|
| 40 | # $brcm_Date: 12/7/11 10:41a $ |
|---|
| 41 | # |
|---|
| 42 | # File Description: |
|---|
| 43 | # |
|---|
| 44 | # Revision History: |
|---|
| 45 | # |
|---|
| 46 | # $brcm_Log: /nexus/build/tools/ipcthunk/bapi_build.pl $ |
|---|
| 47 | # |
|---|
| 48 | # 6 12/7/11 10:41a erickson |
|---|
| 49 | # SW7420-2141: merge as much duplicated kernelmode proxy/usermode ipc |
|---|
| 50 | # perl code as possible |
|---|
| 51 | # |
|---|
| 52 | # 5 8/8/11 5:10p erickson |
|---|
| 53 | # SW7420-1689: add untrusted client api enforcement |
|---|
| 54 | # |
|---|
| 55 | # 4 3/1/11 9:34a erickson |
|---|
| 56 | # SW7420-1123: use bapi_common::skip_thunk |
|---|
| 57 | # |
|---|
| 58 | # 3 1/19/11 2:03p erickson |
|---|
| 59 | # SW7420-1123: socket-based usermode IPC |
|---|
| 60 | # |
|---|
| 61 | # 2 11/3/10 5:32p erickson |
|---|
| 62 | # SW7420-1223: exclude nexus_base_mmap.h from thunks |
|---|
| 63 | # |
|---|
| 64 | # 1 9/29/10 9:34a erickson |
|---|
| 65 | # SW7420-1123: add linux usermode IPC |
|---|
| 66 | # |
|---|
| 67 | ############################################################################# |
|---|
| 68 | use strict; |
|---|
| 69 | |
|---|
| 70 | use lib "../common"; |
|---|
| 71 | use bapi_parse_c; |
|---|
| 72 | use bapi_ipc_apidef; |
|---|
| 73 | use bapi_ipc_client; |
|---|
| 74 | use bapi_ipc_server; |
|---|
| 75 | use bapi_untrusted_api; |
|---|
| 76 | use Getopt::Long; |
|---|
| 77 | |
|---|
| 78 | my $file; |
|---|
| 79 | my @funcs; |
|---|
| 80 | my %structs; |
|---|
| 81 | my $source_file; |
|---|
| 82 | my $file_headers; |
|---|
| 83 | my @file_list; |
|---|
| 84 | |
|---|
| 85 | if ($#ARGV == -1) { |
|---|
| 86 | print "Usage: perl bapi_build.pl [--source listfile] module destdir class_handles file1.h file2.h ...\n"; |
|---|
| 87 | exit; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | #check presence of a sources file and process if present |
|---|
| 91 | GetOptions ('source=s' => \$source_file); |
|---|
| 92 | if($source_file) { |
|---|
| 93 | open(HEADERS, $source_file) || die("Could not open source file: $source_file"); |
|---|
| 94 | $file_headers=<HEADERS>; |
|---|
| 95 | close(HEADERS); |
|---|
| 96 | |
|---|
| 97 | chomp($file_headers); |
|---|
| 98 | @file_list = split(/\s+/,$file_headers); |
|---|
| 99 | my $count; |
|---|
| 100 | $count = @file_list; |
|---|
| 101 | print "Sources file $source_file contains $count headers\n"; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | # Process all files on the command line |
|---|
| 105 | my $module = lc shift @ARGV; |
|---|
| 106 | my $destdir = shift @ARGV; |
|---|
| 107 | |
|---|
| 108 | # read class_handles.inc file into a list |
|---|
| 109 | my $class_list_file = shift @ARGV; |
|---|
| 110 | open FILE, $class_list_file; |
|---|
| 111 | my @class_handles = <FILE>; |
|---|
| 112 | close FILE; |
|---|
| 113 | chomp @class_handles; |
|---|
| 114 | |
|---|
| 115 | for $file (@file_list,@ARGV) { |
|---|
| 116 | next if (bapi_classes::skip_thunk($file)); |
|---|
| 117 | #print "ipcthunk/bapi_build.pl parsing $file\n"; |
|---|
| 118 | |
|---|
| 119 | push @funcs, bapi_parse_c::get_func_prototypes $file; |
|---|
| 120 | |
|---|
| 121 | my $file_structs = bapi_parse_c::parse_struct $file; |
|---|
| 122 | my $name; |
|---|
| 123 | my $members; |
|---|
| 124 | while (($name, $members) = each %$file_structs) { |
|---|
| 125 | $structs{$name} = $members; |
|---|
| 126 | } |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | # Build the perl datastructure |
|---|
| 130 | my @funcrefs = bapi_parse_c::parse_funcs @funcs; |
|---|
| 131 | |
|---|
| 132 | # Print out the perl datastructure |
|---|
| 133 | #bapi_parse_c::print_api @funcrefs; |
|---|
| 134 | #bapi_parse_c::print_struct \%structs; |
|---|
| 135 | |
|---|
| 136 | my $version = bapi_parse_c::version_api @funcrefs; |
|---|
| 137 | $version = ($version * 0x10000) + bapi_parse_c::version_struct \%structs; |
|---|
| 138 | |
|---|
| 139 | my $untrusted_api = bapi_untrusted_api::parse "../common/nexus_untrusted_api.txt"; |
|---|
| 140 | |
|---|
| 141 | # Build thunk layer |
|---|
| 142 | bapi_ipc_apidef::generate "${destdir}/" . (bapi_common::ipc_header $module) , $module, $version, @funcrefs; |
|---|
| 143 | bapi_ipc_client::generate "${destdir}/nexus_${module}_ipc_client.c", $module, $version, \%structs, @funcrefs; |
|---|
| 144 | bapi_ipc_server::generate "${destdir}/nexus_${module}_ipc_server.c", $module, $version, \%structs, \@funcrefs, \@class_handles, $untrusted_api; |
|---|