| 1 | #!/usr/bin/perl |
|---|
| 2 | ############################################################################# |
|---|
| 3 | # |
|---|
| 4 | # Copyright (c) 2007, Broadcom Corporation. |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # Confidential Property of Broadcom Corporation. |
|---|
| 7 | # |
|---|
| 8 | # THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 9 | # AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 10 | # EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 11 | # |
|---|
| 12 | # $brcm_Workfile: bapi_thunks.pm $ |
|---|
| 13 | # $brcm_Revision: 1 $ |
|---|
| 14 | # $brcm_Date: 7/9/07 1:30p $ |
|---|
| 15 | # |
|---|
| 16 | # File Description: |
|---|
| 17 | # |
|---|
| 18 | # Revision History: |
|---|
| 19 | # |
|---|
| 20 | # $brcm_Log: /BSEAV/api/build/proxy/bapi_thunks.pm $ |
|---|
| 21 | # |
|---|
| 22 | # 1 7/9/07 1:30p erickson |
|---|
| 23 | # PR32377: autogen the thunk layer |
|---|
| 24 | # |
|---|
| 25 | # |
|---|
| 26 | ############################################################################# |
|---|
| 27 | use strict; |
|---|
| 28 | use bapi_callbacks; |
|---|
| 29 | |
|---|
| 30 | package bapi_thunks; |
|---|
| 31 | |
|---|
| 32 | sub build_thunks |
|---|
| 33 | { |
|---|
| 34 | my ($filename, @funcs) = @_; |
|---|
| 35 | my $func; |
|---|
| 36 | open FILE, ">$filename"; |
|---|
| 37 | |
|---|
| 38 | print FILE "/*********************************\n"; |
|---|
| 39 | print FILE "*\n"; |
|---|
| 40 | print FILE "* This file is autogenerated. Rebuild with BSEAV/api/build/proxy/autogen.\n"; |
|---|
| 41 | print FILE "*\n"; |
|---|
| 42 | print FILE "* This file acquires b_lock for every function call into the Settop API. The actual impl of each function is remapped to _impl.\n"; |
|---|
| 43 | print FILE "*\n"; |
|---|
| 44 | print FILE "*********************************/\n"; |
|---|
| 45 | print FILE "#define BSETTOP_NO_API_THUNKS\n"; |
|---|
| 46 | print FILE "#include \"bsettop_impl.h\"\n\n"; |
|---|
| 47 | |
|---|
| 48 | # generate prototypes for all the _impl functions |
|---|
| 49 | for $func (@funcs) { |
|---|
| 50 | # NOTE: If there's an exception and a function does not belong in the thunk layer, add it here. |
|---|
| 51 | |
|---|
| 52 | my $impl = $func->{PROTOTYPE}; |
|---|
| 53 | $impl =~ s/$func->{FUNCNAME}/$func->{FUNCNAME}_impl/; |
|---|
| 54 | print FILE "$impl;\n"; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | # generate the actual thunk layer functions which call the impl functions |
|---|
| 58 | for $func (@funcs) { |
|---|
| 59 | my $params = $func->{PARAMS}; |
|---|
| 60 | my $param; |
|---|
| 61 | |
|---|
| 62 | # NOTE: If there's an exception and a function does not belong in the thunk layer, add it here. |
|---|
| 63 | |
|---|
| 64 | print FILE "$func->{PROTOTYPE}\n\{\n"; |
|---|
| 65 | if ($func->{RETTYPE} eq "void") { |
|---|
| 66 | print FILE " b_lock();\n"; |
|---|
| 67 | print FILE " $func->{FUNCNAME}_impl("; |
|---|
| 68 | } |
|---|
| 69 | else { |
|---|
| 70 | print FILE " $func->{RETTYPE} result;\n"; |
|---|
| 71 | print FILE " b_lock();\n"; |
|---|
| 72 | print FILE " result = $func->{FUNCNAME}_impl("; |
|---|
| 73 | } |
|---|
| 74 | for $param (@$params) { |
|---|
| 75 | print FILE "$param->{NAME}"; |
|---|
| 76 | if ($param != $params->[-1]) |
|---|
| 77 | { |
|---|
| 78 | print FILE ", "; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | print FILE ");\n"; |
|---|
| 82 | print FILE " b_unlock();\n"; |
|---|
| 83 | if ($func->{RETTYPE} eq "void") { |
|---|
| 84 | print FILE " return;\n"; |
|---|
| 85 | } |
|---|
| 86 | else { |
|---|
| 87 | print FILE " return result;\n"; |
|---|
| 88 | } |
|---|
| 89 | print FILE "}\n\n"; |
|---|
| 90 | } |
|---|
| 91 | close FILE; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | sub build_remapping |
|---|
| 95 | { |
|---|
| 96 | my ($filename, @funcs) = @_; |
|---|
| 97 | my $func; |
|---|
| 98 | open FILE, ">$filename"; |
|---|
| 99 | |
|---|
| 100 | print FILE "/*********************************\n"; |
|---|
| 101 | print FILE "*\n"; |
|---|
| 102 | print FILE "* This file is autogenerated. Rebuild with BSEAV/api/build/proxy/autogen.\n"; |
|---|
| 103 | print FILE "*\n"; |
|---|
| 104 | print FILE "* This file remaps every public Settop API function to _impl. This allows the Settop API to call its own public API without reacquiring b_lock.\n"; |
|---|
| 105 | print FILE "*\n"; |
|---|
| 106 | print FILE "*********************************/\n"; |
|---|
| 107 | |
|---|
| 108 | for $func (@funcs) { |
|---|
| 109 | # NOTE: If there's an exception and a function does not belong in the thunk layer, add it here. |
|---|
| 110 | print FILE "#define $func->{FUNCNAME} $func->{FUNCNAME}_impl\n"; |
|---|
| 111 | } |
|---|
| 112 | print FILE "\n"; |
|---|
| 113 | close FILE; |
|---|
| 114 | } |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | sub build_kernel_export |
|---|
| 118 | { |
|---|
| 119 | my ($filename, @funcs) = @_; |
|---|
| 120 | my $func; |
|---|
| 121 | open FILE, ">$filename"; |
|---|
| 122 | |
|---|
| 123 | print FILE "/*********************************\n"; |
|---|
| 124 | print FILE "*\n"; |
|---|
| 125 | print FILE "* This file is autogenerated. Rebuild with BSEAV/api/build/proxy/autogen.\n"; |
|---|
| 126 | print FILE "*\n"; |
|---|
| 127 | print FILE "*********************************/\n"; |
|---|
| 128 | print FILE "#include \"bsettop.h\"\n"; |
|---|
| 129 | print FILE "#include <linux/config.h>\n"; |
|---|
| 130 | print FILE "#include <linux/module.h>\n"; |
|---|
| 131 | |
|---|
| 132 | for $func (@funcs) { |
|---|
| 133 | # NOTE: If there's an exception and a function does not belong in the thunk layer, add it here. |
|---|
| 134 | print FILE "EXPORT_SYMBOL($func->{FUNCNAME});\n"; |
|---|
| 135 | } |
|---|
| 136 | print FILE "\n"; |
|---|
| 137 | close FILE; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | 1; |
|---|