[374] | 1 | # coding: utf-8
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2008-2018 by TOPPERS Project
|
---|
| 7 | #--
|
---|
| 8 | # ä¸è¨èä½æ¨©è
|
---|
| 9 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 10 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 11 | # å¤ã»åé
|
---|
| 12 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 13 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 14 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 15 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 16 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 17 | # ç¨ã§ããå½¢ã§åé
|
---|
| 18 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 19 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 20 | # è
|
---|
| 21 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 22 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 23 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 24 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 25 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 26 | # ã¨ï¼
|
---|
| 27 | # (a) åé
|
---|
| 28 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 30 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 31 | # (b) åé
|
---|
| 32 | å¸ã®å½¢æ
|
---|
| 33 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 34 | # å ±åãããã¨ï¼
|
---|
| 35 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 36 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 37 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 38 | 責ãããã¨ï¼
|
---|
| 39 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 40 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 42 | # å
|
---|
| 43 | 責ãããã¨ï¼
|
---|
| 44 | #
|
---|
| 45 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 46 | ã
|
---|
| 47 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 48 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 49 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 50 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 51 | #
|
---|
| 52 | # $Id$
|
---|
| 53 | #++
|
---|
| 54 |
|
---|
| 55 | # mikan through plugin: namespace ãèæ
|
---|
| 56 | ®ããã¦ããªã
|
---|
| 57 | # ãããå©ç¨ããå ´åã以ä¸ã®ããã« toppers_jsp.cdl sChannel.cdl ãæå®ããå¿
|
---|
| 58 | è¦ããã
|
---|
| 59 | # tecsgen toppers_jsp.cdl sChannel.cdl your_description.cdl
|
---|
| 60 |
|
---|
| 61 | # 以ä¸ãä»®å®ï¼å¶éäºé
|
---|
| 62 | ï¼
|
---|
| 63 | # å¼ã³å
|
---|
| 64 | ãå¼ã³å
|
---|
| 65 | ã®ã¨ã³ãã£ã¢ã³ãchar, short, int_t, long_t, intptr_t ã®ãµã¤ãºãåã
|
---|
| 66 | # æ符å·ãç¡ç¬¦å·ã§ãµã¤ãºãåã
|
---|
| 67 |
|
---|
| 68 | class SVCManage
|
---|
| 69 | #
|
---|
| 70 | # @@id: TECSã®ãã©ã°ã¤ã³ã§çæããæ¡å¼µãµã¼ãã¹ã³ã¼ã«ã«å²ãå½ã¦ãid
|
---|
| 71 | # å®éã®æ¡å¼µãµã¼ãã¹ã³ã¼ã«IDã¯ï¼TFN_TECSGEN_ORIGINã§ä¸é§ã
|
---|
| 72 | # å±¥ãããå¤ã¨ãªã
|
---|
| 73 | # TFN_TECSGEN_ORIGINã¯ï¼hrp3/include/extsvc_fncode.h ã§å®ç¾©
|
---|
| 74 | # ããã
|
---|
| 75 | # @@func_ids: æ¡å¼µãµã¼ãã¹ã³ã¼ã«ã®é¢æ°åã¨æ¡å¼µãµã¼ãã¹ã³ã¼ã«IDã
|
---|
| 76 | # ããã対å¿ã¥ããããã·ã¥
|
---|
| 77 | #
|
---|
| 78 | @@id = 0
|
---|
| 79 | @@func_ids = {}
|
---|
| 80 | def initialize()
|
---|
| 81 | #
|
---|
| 82 | # æ¬ã¯ã©ã¹ã¯ã¤ã³ã¹ã¿ã³ã¹ãæããªãä»®æ³çãªã¯ã©ã¹ã§ãã
|
---|
| 83 | #
|
---|
| 84 | raise "class #{self.class.name} shall not have instances"
|
---|
| 85 | end
|
---|
| 86 | def self.get_func_id func_name
|
---|
| 87 | return @@func_ids[ func_name ]
|
---|
| 88 | end
|
---|
| 89 | def self.set_func_id func_name
|
---|
| 90 | @@func_ids[ func_name ] = self.assign_id
|
---|
| 91 | # puts @@func_ids[ func_name ]
|
---|
| 92 | end
|
---|
| 93 | def self.get_id
|
---|
| 94 | return @@id
|
---|
| 95 | end
|
---|
| 96 | def self.set_id id
|
---|
| 97 | @@id = id
|
---|
| 98 | end
|
---|
| 99 | def self.assign_id
|
---|
| 100 | assignedId = @@id
|
---|
| 101 | @@id += 1
|
---|
| 102 | return assignedId
|
---|
| 103 | end
|
---|
| 104 | end
|
---|
| 105 |
|
---|
| 106 | #
|
---|
| 107 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«ãç¨ãããã¡ã¤ã³ééä¿¡ã®
|
---|
| 108 | # throughãã©ã°ã¤ã³
|
---|
| 109 | # HRPãã¡ã¤ã³ãã©ã°ã¤ã³ã«ãã£ã¦æ¿å
|
---|
| 110 | ¥ããã
|
---|
| 111 | # åææ¡ä»¶: å¼åºãå
|
---|
| 112 | ãã«ã¼ãã«ãªãã¸ã§ã¯ããã©ããã®å¤å®ã¯HRPãã¡ã¤ã³ãã©ã°ã¤ã³
|
---|
| 113 | # ãããããã§å®æ½ãããããï¼ããã§ã¯å¤å®ããªããã¨ã¨ãã
|
---|
| 114 | #
|
---|
| 115 | class HRPSVCPlugin < ThroughPlugin
|
---|
| 116 |
|
---|
| 117 | NUM_SVC_ARG_MAX = 5 # HRP3 ã®æ¡å¼µãµã¼ãã¹ã³ã¼ã«ã§æ±ããã¨ã®ã§ããå¼æ°ã®æ大åæ°
|
---|
| 118 |
|
---|
| 119 | @@generated_celltype ={} # ã»ã«ã¿ã¤ãã®éè¤æé¤ç¨
|
---|
| 120 | @@generated_cell = {} # ã»ã«ã®éè¤æé¤ç¨
|
---|
| 121 |
|
---|
| 122 | def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
|
---|
| 123 | super
|
---|
| 124 |
|
---|
| 125 | # åãå£é
|
---|
| 126 | åã®å ´åãé
|
---|
| 127 | åæ·»æ°ãã¨ã«å¥ã®ã»ã«ã¿ã¤ãã¨ãã
|
---|
| 128 | # ã»ã«ã¿ã¤ããã·ã³ã°ã«ãã³åãããããã
|
---|
| 129 | # ãããªãã¨ãã»ã«ãèå¥ããå¼æ°ã渡ãå¿
|
---|
| 130 | è¦ããããNUM_SVC_ARG_MAX(5) ã¤ãã渡ããªãå¼æ°ã®ä¸ã¤ãæ¶è²»ãããã¨ã«ãªãããã
|
---|
| 131 | if @next_cell_port_subscript then
|
---|
| 132 | subscript = "__" + @next_cell_port_subscript.to_s
|
---|
| 133 | else
|
---|
| 134 | subscript = ""
|
---|
| 135 | end
|
---|
| 136 | @ct_name_body = "#{@ct_name}SVCBody_#{@next_cell.get_name}_#{@next_cell_port_name}#{subscript}".to_sym
|
---|
| 137 | @ct_name = "#{@ct_name}SVCCaller_#{@next_cell.get_name}_#{@next_cell_port_name}#{subscript}".to_sym
|
---|
| 138 | @cell_name_body = "#{@cell_name}SVCBody".to_sym
|
---|
| 139 | @cell_name = "#{@cell_name}SVCCaller".to_sym
|
---|
| 140 | # puts "%%%% "
|
---|
| 141 | # p @next_cell.get_name
|
---|
| 142 | # p @caller_cell.get_name
|
---|
| 143 | @b_printed_include_stdint = false
|
---|
| 144 | check_signature signature
|
---|
| 145 | end
|
---|
| 146 |
|
---|
| 147 | #=== NamespacePath ãå¾ã
|
---|
| 148 | # çæããã»ã«ã® namespace path ãçæãã
|
---|
| 149 | def get_cell_namespace_path
|
---|
| 150 | # nsp = @region.get_namespace.get_namespace_path
|
---|
| 151 | nsp = @start_region.get_namespace_path
|
---|
| 152 | return nsp.append( @cell_name )
|
---|
| 153 | end
|
---|
| 154 |
|
---|
| 155 | def gen_plugin_decl_code( file )
|
---|
| 156 |
|
---|
| 157 | # ãã®ã»ã«ã¿ã¤ãï¼åãã·ã°ããã£ï¼ã¯æ¢ã«çæããã¦ãããï¼
|
---|
| 158 | if @@generated_celltype[ @ct_name_body ] == nil then
|
---|
| 159 | @@generated_celltype[ @ct_name_body ] = [ self ]
|
---|
| 160 | file2 = CFile.open( "#{$gen}/#{@ct_name_body}.cdl", "w" )
|
---|
| 161 | file2.print <<EOT
|
---|
| 162 | import_C( "t_stdlib.h" );
|
---|
| 163 |
|
---|
| 164 | /* HRPSVC0001 */
|
---|
| 165 | [active,singleton]
|
---|
| 166 | celltype #{@ct_name_body} {
|
---|
| 167 | call #{@signature.get_name} #{@call_port_name};
|
---|
| 168 | FACTORY {
|
---|
| 169 | write("$ct$_tecsgen.h", "#include \\"kernel_cfg.h\\"");
|
---|
| 170 | };
|
---|
| 171 | };
|
---|
| 172 | EOT
|
---|
| 173 | file2.close
|
---|
| 174 | else
|
---|
| 175 | @@generated_celltype[ @ct_name_body ] << self
|
---|
| 176 | end
|
---|
| 177 | file.print "import( \"#{$gen}/#{@ct_name_body}.cdl\" );\n"
|
---|
| 178 |
|
---|
| 179 | # ãã®ã»ã«ã¿ã¤ãï¼åãã·ã°ããã£ï¼ã¯æ¢ã«çæããã¦ãããï¼
|
---|
| 180 | if @@generated_celltype[ @ct_name ] == nil then
|
---|
| 181 | @@generated_celltype[ @ct_name ] = [ self ]
|
---|
| 182 | file2 = CFile.open( "#{$gen}/#{@ct_name}.cdl", "w" )
|
---|
| 183 | file2.print <<EOT
|
---|
| 184 | /* HRPSVC0002 */
|
---|
| 185 | celltype #{@ct_name} {
|
---|
| 186 | entry #{@signature.get_name} #{@entry_port_name};
|
---|
| 187 | FACTORY {
|
---|
| 188 | write("$ct$_tecsgen.h", "#include \\"extsvc_fncode.h\\"");
|
---|
| 189 | };
|
---|
| 190 | };
|
---|
| 191 | EOT
|
---|
| 192 | file2.close
|
---|
| 193 | else
|
---|
| 194 | @@generated_celltype[ @ct_name ] << self
|
---|
| 195 | end
|
---|
| 196 | file.print "import( \"#{$gen}/#{@ct_name}.cdl\" );\n"
|
---|
| 197 |
|
---|
| 198 | =begin
|
---|
| 199 | # TODO: send. receive 対å¿
|
---|
| 200 | send_receive = []
|
---|
| 201 | if @signature != nil then
|
---|
| 202 | @signature.each_param{ |fd,param|
|
---|
| 203 | dir =param.get_direction
|
---|
| 204 | case dir
|
---|
| 205 | when :SEND, :RECEIVE
|
---|
| 206 | send_receive << [ dir, fd, param ]
|
---|
| 207 | end
|
---|
| 208 | }
|
---|
| 209 | end
|
---|
| 210 | =end
|
---|
| 211 |
|
---|
| 212 | =begin
|
---|
| 213 | composite #{@ct_name} {
|
---|
| 214 | entry #{@signature.get_name} #{@entry_port_name};
|
---|
| 215 | call #{@signature.get_name} #{@call_port_name};
|
---|
| 216 |
|
---|
| 217 | cell #{@ct_name}Client #{@cell_name}Client{
|
---|
| 218 | };
|
---|
| 219 |
|
---|
| 220 | [active]
|
---|
| 221 | cell #{@ct_name}Server #{@cell_name}Server{
|
---|
| 222 | #{@call_port_name} => composite.#{@call_port_name};
|
---|
| 223 | };
|
---|
| 224 |
|
---|
| 225 | composite.#{@entry_port_name} => #{@cell_name}.#{@entry_port_name};
|
---|
| 226 | };
|
---|
| 227 | =end
|
---|
| 228 |
|
---|
| 229 | end
|
---|
| 230 |
|
---|
| 231 | #=== through cell ã³ã¼ããçæ
|
---|
| 232 | #
|
---|
| 233 | #
|
---|
| 234 | def gen_through_cell_code( file )
|
---|
| 235 |
|
---|
| 236 | # gen_plugin_decl_code( file ) this is called from super.
|
---|
| 237 |
|
---|
| 238 | # ã»ã«ãæ¢ã
|
---|
| 239 | # path =["::",@next_cell.get_name] # mikan namespace
|
---|
| 240 | # cell = Namespace.find( path )
|
---|
| 241 | # cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
| 242 |
|
---|
| 243 | ##### ã¯ã©ã¤ã¢ã³ãå´ã®ã»ã«ã®çæ #####
|
---|
| 244 | # file.print "[domain(HRP, \"kernel\")]"
|
---|
| 245 | nest = @start_region.gen_region_str_pre file
|
---|
| 246 | nest_str = " " * nest
|
---|
| 247 |
|
---|
| 248 | # ã¯ã©ã¤ã¢ã³ãå´ãã£ã³ãã«ã®çæ
|
---|
| 249 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«å¼åºã
|
---|
| 250 | file.print <<EOT
|
---|
| 251 | /* HRPSVC0003 */
|
---|
| 252 | #{nest_str} // Client Side Channel
|
---|
| 253 | #{nest_str} cell #{@ct_name} #{@cell_name}{
|
---|
| 254 | #{nest_str} };
|
---|
| 255 |
|
---|
| 256 | EOT
|
---|
| 257 |
|
---|
| 258 | @start_region.gen_region_str_post file
|
---|
| 259 | file.print "\n\n"
|
---|
| 260 |
|
---|
| 261 | ##### ãµã¼ãã¼å´ã®ã»ã«ã®çæ #####
|
---|
| 262 | # print "###### #{@cell_name_body} ... #{@ct_name_body} #{@@generated_cell[ @ct_name_body ].class} #####\n"
|
---|
| 263 |
|
---|
| 264 | if @@generated_cell[ @ct_name_body ] then
|
---|
| 265 | file.print "/* cell #{@ct_name_body} #{@@generated_cell[ @ct_name_body ]}: already generated. */\n"
|
---|
| 266 | else
|
---|
| 267 | @@generated_cell[ @ct_name_body ] = @cell_name_body
|
---|
| 268 | nest = @end_region.gen_region_str_pre file
|
---|
| 269 | nest_str = " " * nest
|
---|
| 270 | if @next_cell_port_subscript then
|
---|
| 271 | subscript = '[' + @next_cell_port_subscript.to_s + ']'
|
---|
| 272 | else
|
---|
| 273 | subscript = ""
|
---|
| 274 | end
|
---|
| 275 |
|
---|
| 276 | # ãµã¼ãã¼å´ãã£ã³ãã«ã®çæ
|
---|
| 277 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«æ¬ä½
|
---|
| 278 | file.print <<EOT
|
---|
| 279 |
|
---|
| 280 | /* HRPSVC0004 */
|
---|
| 281 | #{nest_str} // Server Side Channel
|
---|
| 282 | #{nest_str} cell #{@ct_name_body} #{@cell_name_body}{
|
---|
| 283 | #{nest_str} #{@call_port_name} = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
|
---|
| 284 | #{nest_str} };
|
---|
| 285 | EOT
|
---|
| 286 |
|
---|
| 287 | @end_region.gen_region_str_post file
|
---|
| 288 |
|
---|
| 289 | file2 = AppFile.open( "#{$gen}/tecsgen.cfg" )
|
---|
| 290 | file2.print "\n/* Generated by HRPSVCPlugin */\n\n"
|
---|
| 291 | file2.print <<EOT
|
---|
| 292 | /* HRPSVC0005 */
|
---|
| 293 | #include "#{@ct_name_body}_factory.h"
|
---|
| 294 | EOT
|
---|
| 295 | file2.close
|
---|
| 296 |
|
---|
| 297 | # callee_cell ã®get_restricted_regions ãå¼ã³åºãã¦ãã
|
---|
| 298 | # restrict ãåç
|
---|
| 299 | §ãããå°ãã¤ãããã
|
---|
| 300 | @callee_cell.get_restricted_regions( :dummy_entry_name, :dummy_func_name )
|
---|
| 301 | end
|
---|
| 302 | end
|
---|
| 303 |
|
---|
| 304 | #=== åãå£é¢æ°ã®æ¬ä½(Cè¨èª)ãçæãã
|
---|
| 305 | # é常ã§ããã°ãã¸ã§ãã¬ã¼ã¿ã¯åãå£é¢æ°ã®ãã³ãã¬ã¼ããçæãã
|
---|
| 306 | # ãã©ã°ã¤ã³ã®å ´åãå¤æ´ããå¿
|
---|
| 307 | è¦ã®ãªãã»ã«ã¿ã¤ãã³ã¼ããçæãã
|
---|
| 308 | #file:: FILE åºåå
|
---|
| 309 | ãã¡ã¤ã«
|
---|
| 310 | #b_singleton:: bool true if singleton
|
---|
| 311 | #ct_name:: Symbol
|
---|
| 312 | #global_ct_name:: string
|
---|
| 313 | #sig_name:: string
|
---|
| 314 | #ep_name:: string
|
---|
| 315 | #func_name:: string
|
---|
| 316 | #func_global_name:: string
|
---|
| 317 | #func_type:: class derived from Type
|
---|
| 318 | def gen_ep_func_body( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
| 319 | # puts "generate ep_func for #{ct_name}"
|
---|
| 320 |
|
---|
| 321 | #
|
---|
| 322 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«å¼åºãå´ã®é¢æ°çæ
|
---|
| 323 | #
|
---|
| 324 | # å®æå½¢ã®ã¤ã¡ã¼ã¸
|
---|
| 325 | #
|
---|
| 326 | # ER_UINT
|
---|
| 327 | # eThroughEntry_write(CELLIDX idx, const char* buffer, uint_t length)
|
---|
| 328 | # {
|
---|
| 329 | # ER_UINT retval;
|
---|
| 330 | # tHRPSVCPlugin_<Sig>SVCCaller_<Cell>_<Entry>_CB *p_cellcb;
|
---|
| 331 | # if( VALID_IDX( idx ) ){
|
---|
| 332 | # p_cellcb = tHRPSVCPlugin_<Sig>SVCBody_<Cell>_<Entry>_GET_CELLCB(idx);
|
---|
| 333 | # }else{
|
---|
| 334 | # /* ã¨ã©ã¼å¦çã³ã¼ããããã«è¨è¿° */
|
---|
| 335 | # }
|
---|
| 336 | #
|
---|
| 337 | # retval = (ER_UINT)cal_svc( TFN_TECSGEN_ORIGIN + svcid,
|
---|
| 338 | # (intptr_t)par1, (intptr_t)par2, 0, 0, 0 );
|
---|
| 339 | #
|
---|
| 340 | # return retval;
|
---|
| 341 | # }
|
---|
| 342 |
|
---|
| 343 | if ! func_type.get_type.kind_of?( VoidType ) then
|
---|
| 344 | file.print( " #{func_type.get_type_str} retval;\n" )
|
---|
| 345 | end
|
---|
| 346 |
|
---|
| 347 | # p "celltype_name, sig_name, func_name, func_global_name"
|
---|
| 348 | # p "#{ct_name}, #{sig_name}, #{func_name}, #{func_global_name}"
|
---|
| 349 |
|
---|
| 350 | delim = ""
|
---|
| 351 | if ! func_type.get_type.kind_of?( VoidType ) then
|
---|
| 352 | file.print( " retval = (#{func_type.get_type_str})" )
|
---|
| 353 | else
|
---|
| 354 | file.print( " " )
|
---|
| 355 | end
|
---|
| 356 |
|
---|
| 357 | #file.print( "#{@call_port_name}_#{func_name}(" )
|
---|
| 358 | SVCManage.set_func_id( "#{@ct_name_body}_#{func_name}" )
|
---|
| 359 | svcid = SVCManage.get_func_id( "#{@ct_name_body}_#{func_name}" )
|
---|
| 360 | #file.print( "cal_svc( #{@ct_name_body}_#{func_name}" )
|
---|
| 361 | file.print( "cal_svc( TFN_TECSGEN_ORIGIN + #{svcid.to_s}" )
|
---|
| 362 |
|
---|
| 363 | # if ( ! b_singleton ) then
|
---|
| 364 | # file.print( " tecs_this" )
|
---|
| 365 | # delim = ","
|
---|
| 366 | # end
|
---|
| 367 |
|
---|
| 368 | i = 0
|
---|
| 369 | passed_param = {}
|
---|
| 370 | params.each{ |param|
|
---|
| 371 | delim = ","
|
---|
| 372 | file.printf( "#{delim} (intptr_t)#{param.get_name}" )
|
---|
| 373 | passed_param[i] = param.get_name
|
---|
| 374 | i += 1
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 | while(i < NUM_SVC_ARG_MAX) do
|
---|
| 378 | delim = ","
|
---|
| 379 | file.printf( "#{delim} 0" )
|
---|
| 380 | passed_param[i] = "par#{i+1}"
|
---|
| 381 | i += 1
|
---|
| 382 | end
|
---|
| 383 |
|
---|
| 384 | file.print( " );\n\n" )
|
---|
| 385 |
|
---|
| 386 | if ! func_type.get_type.kind_of?( VoidType ) then
|
---|
| 387 | file.print( " return retval;\n" )
|
---|
| 388 | end
|
---|
| 389 |
|
---|
| 390 | #
|
---|
| 391 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«æ¬ä½å´ã®é¢æ°çæ
|
---|
| 392 | #
|
---|
| 393 | # å®æå½¢ã®ã¤ã¡ã¼ã¸
|
---|
| 394 | #
|
---|
| 395 | # ER_UINT
|
---|
| 396 | # eThroughEntry_write(CELLIDX idx, const char* buffer, uint_t length)
|
---|
| 397 | # {
|
---|
| 398 | # ER_UINT retval;
|
---|
| 399 | # tHRPSVCPlugin_<Sig>SVCBody_<Cell>_<Entry>_CB *p_cellcb;
|
---|
| 400 | # if( VALID_IDX( idx ) ){
|
---|
| 401 | # p_cellcb = tHRPSVCPlugin_<Sig>SVCBody_<Cell>_<Entry>_GET_CELLCB(idx);
|
---|
| 402 | # }else{
|
---|
| 403 | # /* ã¨ã©ã¼å¦çã³ã¼ããããã«è¨è¿° */
|
---|
| 404 | # }
|
---|
| 405 | #
|
---|
| 406 | # retval = (ER_UINT)cal_svc( TFN_TECSGEN_ORIGIN + svcid,
|
---|
| 407 | # (intptr_t)par1, (intptr_t)par2, 0, 0, 0 );
|
---|
| 408 | #
|
---|
| 409 | # return retval;
|
---|
| 410 | # }
|
---|
| 411 | file2 = AppFile.open( "#{$gen}/#{@ct_name_body}.c" )
|
---|
| 412 | if @b_printed_include_stdint == false then
|
---|
| 413 | file2.print <<EOT
|
---|
| 414 | #ifndef SIZE_MAX
|
---|
| 415 | #define SIZE_MAX (~0UL)
|
---|
| 416 | #endif
|
---|
| 417 |
|
---|
| 418 | EOT
|
---|
| 419 | @b_printed_include_stdint = true
|
---|
| 420 | end
|
---|
| 421 |
|
---|
| 422 | if func_type.get_type.kind_of?( VoidType ) then
|
---|
| 423 | retval_assign = ""
|
---|
| 424 | else
|
---|
| 425 | retval_assign = "retval = (ER_UINT)"
|
---|
| 426 | end
|
---|
| 427 |
|
---|
| 428 | file2.print <<EOT
|
---|
| 429 | /* HRPSVC0006 */
|
---|
| 430 | ER_UINT
|
---|
| 431 | #{@ct_name_body}_#{func_name}(intptr_t #{passed_param[0]}, intptr_t #{passed_param[1]}, intptr_t #{passed_param[2]}, intptr_t #{passed_param[3]}, intptr_t #{passed_param[4]}, ID cdmid)
|
---|
| 432 | {
|
---|
| 433 | ER_UINT retval = E_OK;
|
---|
| 434 |
|
---|
| 435 | EOT
|
---|
| 436 |
|
---|
| 437 | #
|
---|
| 438 | # ã¨ã©ã¼ãã§ãã¯å¦çã®çæ
|
---|
| 439 | #
|
---|
| 440 |
|
---|
| 441 | #
|
---|
| 442 | # å¼åºãå
|
---|
| 443 | ãã¡ã¤ã³ã®ãã§ãã¯
|
---|
| 444 | # * private method: gen_caller_check_codeåç
|
---|
| 445 | §
|
---|
| 446 | #
|
---|
| 447 | generated_check_code = gen_caller_check_code(func_name)
|
---|
| 448 | check_code = generated_check_code["check_code"]
|
---|
| 449 | user_cannot_callable = generated_check_code["user_cannot_callable"]
|
---|
| 450 |
|
---|
| 451 | #
|
---|
| 452 | # ãã©ã¡ã¼ã¿ã«ãã¤ã³ã¿ãåå¨ããå ´åï¼å¼åºãå
|
---|
| 453 | ã¿ã¹ã¯ã«å¯¾ãã
|
---|
| 454 | # ã¢ã¯ã»ã¹æ¨©ã®ãã§ãã¯å¦çãåºåãã
|
---|
| 455 | # â» cdmidãã«ã¼ãã«ãã¡ã¤ã³(æ¡å¼µãµã¼ãã¹ã³ã¼ã«å¼åºãä¸ã®ã¦ã¼ã¶
|
---|
| 456 | # ãã¡ã¤ã³ãå«ã)ã§ããã°prb_memã®å¦çãã¹ããããï¼å段ã®
|
---|
| 457 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«ã®ã¿prb_memãå¼åºãå
|
---|
| 458 | ã¿ã¹ã¯ã«çºè¡ãã
|
---|
| 459 | #
|
---|
| 460 | num = 0
|
---|
| 461 | params.each{ |param|
|
---|
| 462 | if param.get_declarator.get_ptr_level > 0 then
|
---|
| 463 | align_check_str = "!ALIGN_TYPE(#{passed_param[num]}, #{param.get_type.get_referto.get_type_str}) || "
|
---|
| 464 |
|
---|
| 465 | if param.get_type.get_referto.kind_of?(IntType) then
|
---|
| 466 | case param.get_type.get_referto.get_bit_size
|
---|
| 467 | when -11, -1, 8 # char, char_t, int8_t (ç¡ç¬¦å·å«ã)
|
---|
| 468 | #
|
---|
| 469 | # charãã¼ã¿ã®å ´åï¼ALIGN_TYPEã¯å¿
|
---|
| 470 | ãTRUE
|
---|
| 471 | # ã¨ãªãã®ã§ï¼ã¨ã©ã¼ãã§ãã¯ãçç¥
|
---|
| 472 | # charåã®@bit_sizeã¯-11
|
---|
| 473 | # tecsgen/tecslib/core/types.rbãåç
|
---|
| 474 | §
|
---|
| 475 | #
|
---|
| 476 | align_check_str = ""
|
---|
| 477 | end
|
---|
| 478 | end
|
---|
| 479 | if param.get_direction == :IN then
|
---|
| 480 | #
|
---|
| 481 | # å
|
---|
| 482 | ¥å([in])ã®ãã¤ã³ã¿ãã©ã¡ã¼ã¿ã¯ï¼å¼åºãå
|
---|
| 483 | ã¿ã¹ã¯ã«
|
---|
| 484 | # TPM_READ(èªåºãå¯è½)ã®ã¢ã¯ã»ã¹æ¨©ãå¿
|
---|
| 485 | è¦
|
---|
| 486 | #
|
---|
| 487 | # äºéãã¤ã³ã¿ãä¸å¯ã®ãããsize_is 㨠string ãåæã«è¨å®ããããã¨ã¯ãªã
|
---|
| 488 | prb_func = "prb_mem"
|
---|
| 489 | if param.get_size then
|
---|
| 490 | size_str = param.get_size.to_s
|
---|
| 491 | elsif param.get_string == -1 then
|
---|
| 492 | size_str = "SIZE_MAX"
|
---|
| 493 | prb_func = "prb_str"
|
---|
| 494 | elsif param.get_string then
|
---|
| 495 | size_str = param.get_string.to_s
|
---|
| 496 | prb_func = "prb_str"
|
---|
| 497 | else
|
---|
| 498 | size_str = "1"
|
---|
| 499 | end
|
---|
| 500 | check_code.concat <<EOT
|
---|
| 501 | /* HRPSVC0007 */
|
---|
| 502 | if (#{align_check_str}#{prb_func}((void *)#{passed_param[num]}, sizeof(#{param.get_type.get_referto.get_type_str}) * (#{size_str}), TSK_SELF, TPM_READ) != E_OK) {
|
---|
| 503 | return E_MACV;
|
---|
| 504 | }
|
---|
| 505 | EOT
|
---|
| 506 |
|
---|
| 507 | elsif param.get_direction == :OUT || param.get_direction == :INOUT then
|
---|
| 508 | #
|
---|
| 509 | # åºå([out])ã®ãã¤ã³ã¿ãã©ã¡ã¼ã¿ã¯ï¼å¼åºãå
|
---|
| 510 | ã¿ã¹ã¯ã«
|
---|
| 511 | # TPM_WRITE(æ¸è¾¼ã¿å¯è½)ã®ã¢ã¯ã»ã¹æ¨©ãå¿
|
---|
| 512 | è¦
|
---|
| 513 | #
|
---|
| 514 | prb_func = "prb_mem"
|
---|
| 515 | if param.get_size then
|
---|
| 516 | size_str = param.get_size.to_s
|
---|
| 517 | elsif param.get_string then # å¼æ°ãªãã® string ã¯ãªã
|
---|
| 518 | size_str = param.get_string.to_s
|
---|
| 519 | # prb_func = "prb_str" # out, inout ã®å ´åãå¿
|
---|
| 520 | ãé åã確ä¿ãã. prb_mem ãç¨ãã
|
---|
| 521 | else
|
---|
| 522 | size_str = "1"
|
---|
| 523 | end
|
---|
| 524 | check_code.concat <<EOT
|
---|
| 525 | /* HRPSVC0008 */
|
---|
| 526 | if (#{align_check_str}#{prb_func}((void *)#{passed_param[num]}, sizeof(#{param.get_type.get_referto.get_type_str}) * (#{size_str}), TSK_SELF, TPM_WRITE) != E_OK) {
|
---|
| 527 | return E_MACV;
|
---|
| 528 | }
|
---|
| 529 | EOT
|
---|
| 530 |
|
---|
| 531 | end
|
---|
| 532 | end
|
---|
| 533 | num += 1
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | #
|
---|
| 537 | # å¼åºãå
|
---|
| 538 | ãã«ã¼ãã«ãã¡ã¤ã³ã®ã¿è¨±å¯ããã¦ããå ´åï¼
|
---|
| 539 | # ãã¹ã¦ã®ã¦ã¼ã¶ãã¡ã¤ã³ããã®å¼åºãã«å¯¾ãï¼E_OACVãè¿ã
|
---|
| 540 | #
|
---|
| 541 | if user_cannot_callable
|
---|
| 542 | check_code = "\t\treturn E_OACV;"
|
---|
| 543 | end
|
---|
| 544 |
|
---|
| 545 | if check_code != ""
|
---|
| 546 | #
|
---|
| 547 | # å¼åºãå
|
---|
| 548 | ãã«ã¼ãã«ãã¡ã¤ã³ã®å ´åï¼ã¢ã¯ã»ã¹æ¨©ã®ãã§ãã¯
|
---|
| 549 | # å¦çãã¹ãããããã
|
---|
| 550 | #
|
---|
| 551 | file2.print <<eot
|
---|
| 552 | if (cdmid != TDOM_KERNEL) {
|
---|
| 553 | #{check_code}
|
---|
| 554 | }
|
---|
| 555 | eot
|
---|
| 556 | end
|
---|
| 557 |
|
---|
| 558 | #
|
---|
| 559 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«æ¬ä½(æ¬æ¥ã®åãå£é¢æ°)ãå¼ã³åºã
|
---|
| 560 | #
|
---|
| 561 | file2.print" #{retval_assign}#{@call_port_name}_#{func_name}("
|
---|
| 562 |
|
---|
| 563 | delim = ""
|
---|
| 564 | num = 0
|
---|
| 565 | params.each{ |param|
|
---|
| 566 | file2.print "#{delim}"
|
---|
| 567 | delim = ", "
|
---|
| 568 | file2.print "(#{param.get_type.get_type_str})"
|
---|
| 569 | file2.print passed_param[num]
|
---|
| 570 | file2.print param.get_type.get_type_str_post
|
---|
| 571 | num += 1
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | file2.print ");\n"
|
---|
| 575 |
|
---|
| 576 | file2.print "\n return retval;\n"
|
---|
| 577 | file2.print "}\n\n"
|
---|
| 578 |
|
---|
| 579 | file2.close
|
---|
| 580 |
|
---|
| 581 | #
|
---|
| 582 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«ã®ç»é²
|
---|
| 583 | #
|
---|
| 584 | file2 = AppFile.open( "#{$gen}/tecsgen.cfg" )
|
---|
| 585 | file2.print "\n/* Generated by HRPSVCPlugin */\n\n"
|
---|
| 586 | file2.print <<EOT
|
---|
| 587 | /* HRPSVC0009 */
|
---|
| 588 | KERNEL_DOMAIN{
|
---|
| 589 | DEF_SVC( TFN_TECSGEN_ORIGIN + #{svcid.to_s}, { TA_NULL, #{@ct_name_body}_#{func_name}, SSZ_#{func_global_name} } );
|
---|
| 590 | }
|
---|
| 591 | EOT
|
---|
| 592 | file2.close
|
---|
| 593 |
|
---|
| 594 | #
|
---|
| 595 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«ç»é²ã«å¿
|
---|
| 596 | è¦ãªæ
|
---|
| 597 | å ±ããããã«åºå
|
---|
| 598 | # - æ¡å¼µãµã¼ãã¹ã³ã¼ã«å¼åºãæã®ãã§ãã¯ã§ä½¿ç¨ããã¹ã¿ãã¯ãµã¤ãºãåºå
|
---|
| 599 | # - æ¡å¼µãµã¼ãã¹ã³ã¼ã«ã¨ãã¦ç»é²ããé¢æ°åã®extern宣è¨ãåºå
|
---|
| 600 | #
|
---|
| 601 | file2 = AppFile.open( "#{$gen}/#{@ct_name_body}_factory.h" )
|
---|
| 602 | file2.print "\n/* Generated by HRPSVCPlugin */\n\n"
|
---|
| 603 | file2.print <<EOT
|
---|
| 604 | /* HRPSVC0010 */
|
---|
| 605 | #ifndef SSZ_#{func_global_name}
|
---|
| 606 | #define SSZ_#{func_global_name} DefaultExtsvcStackSize
|
---|
| 607 | #endif /* SSZ_#{func_global_name} */
|
---|
| 608 |
|
---|
| 609 | /* HRPSVC0011 */
|
---|
| 610 | extern ER_UINT #{@ct_name_body}_#{func_name}(intptr_t par1, intptr_t par2, intptr_t par3, intptr_t par4, intptr_t par5, ID cdmid);
|
---|
| 611 | EOT
|
---|
| 612 | file2.close
|
---|
| 613 | end
|
---|
| 614 |
|
---|
| 615 | def get_callee_cell
|
---|
| 616 | return @callee_cell
|
---|
| 617 | end
|
---|
| 618 |
|
---|
| 619 | def get_caller_cell
|
---|
| 620 | return @caller_cell
|
---|
| 621 | end
|
---|
| 622 |
|
---|
| 623 | def get_callee_ep_name
|
---|
| 624 | return @join.get_port_name
|
---|
| 625 | end
|
---|
| 626 |
|
---|
| 627 | private
|
---|
| 628 | #
|
---|
| 629 | # æ¡å¼µãµã¼ãã¹ã³ã¼ã«æ¬ä½ã«ãããï¼å¼åºãå
|
---|
| 630 | ãã§ãã¯ã®ã³ã¼ãã
|
---|
| 631 | # åºåãã
|
---|
| 632 | # gen_ep_func_body ããã®ã¿å¼ã³åºããã
|
---|
| 633 | # å¼æ°: 対象ã®é¢æ°å
|
---|
| 634 | # è¿ãå¤: ä¸è¨ã®ããã·ã¥
|
---|
| 635 | # {"check_code"=>åºåããã¨ã©ã¼ãã§ãã¯ã³ã¼ã,
|
---|
| 636 | # "user_cannot_callable"=>ã¦ã¼ã¶ãã¡ã¤ã³ãå¼åºãä¸å¯è½ãã©ããã®ãã©ã°}
|
---|
| 637 | #
|
---|
| 638 | def gen_caller_check_code(func_name)
|
---|
| 639 | dbgPrint "gen_caller_check_code(func_name): #{@callee_cell.get_name}\n"
|
---|
| 640 | #
|
---|
| 641 | # ã¨ã©ã¼ãã§ãã¯å¦ç
|
---|
| 642 | #
|
---|
| 643 | check_code = ""
|
---|
| 644 | user_cannot_callable = false
|
---|
| 645 | all_domain_callable = false
|
---|
| 646 | caller_unrestricted = false
|
---|
| 647 |
|
---|
| 648 | #
|
---|
| 649 | # å¼åºãå
|
---|
| 650 | ãã¡ã¤ã³ã®ãã§ãã¯å¦ç
|
---|
| 651 | # callable_domains: æ¡å¼µãµã¼ãã¹ã³ã¼ã«ãå¼åºãå¯è½ãªãã¡ã¤ã³ã®ãªã¹ã
|
---|
| 652 | # - ç¡æå±ã®ã»ã«ããçµåããã¦ããå ´åï¼ãã¹ã¦ã®ã»ã«ã«å¯¾ãã¦ï¼
|
---|
| 653 | # ãcallable?ããã§ãã¯ãï¼å¼åºãå¯è½ãªãã¹ã¦ã®ãã¡ã¤ã³ãè¿ã
|
---|
| 654 | # - ç¡æå±ä»¥å¤ã®ã»ã«ããçµåããã¦ããå ´åï¼ãã®ã»ã«ã«å¯¾ãã¦
|
---|
| 655 | # callable?ããã§ãã¯ãï¼å¼åºãå¯è½ã§ããã°ï¼ãã®ãã¡ã¤ã³ãè¿ã
|
---|
| 656 | #
|
---|
| 657 | callable_domains = []
|
---|
| 658 | @@generated_celltype[ @ct_name_body ].each { |svcplugin|
|
---|
| 659 | if svcplugin.get_caller_cell.get_region.get_domain_root.get_domain_type.get_option == "OutOfDomain"
|
---|
| 660 | # ç¡æå±ã㤠active ãªå ´åããrestrict ã«å¾ã
|
---|
| 661 | # if svcplugin.get_caller_cell.get_celltype.is_active?
|
---|
| 662 | # #
|
---|
| 663 | # # ç¡æå±ãã¤activeãªã»ã«ã¯ãTECSããåå¨ãèªèããã¦ããªãã®ã
|
---|
| 664 | # # å«ãä»»æã®ãã¡ã¤ã³ããå¼ã³åºãããå¯è½æ§ãåå¨ãã
|
---|
| 665 | # #
|
---|
| 666 | # caller_unrestricted = true
|
---|
| 667 | # else
|
---|
| 668 | # #
|
---|
| 669 | # # ç¡æå±ããæ¥ç¶ããã¦ããå ´åã¯ï¼ãã¹ã¦ã®ã»ã«ã®
|
---|
| 670 | # # restrictããã§ãã¯
|
---|
| 671 | # #
|
---|
| 672 | # Cell.get_cell_list2.each { |cell|
|
---|
| 673 | # if cell.callable?(svcplugin.get_callee_cell, svcplugin.get_callee_ep_name, func_name)
|
---|
| 674 | # callable_domains << cell.get_region.get_domain_root
|
---|
| 675 | # end
|
---|
| 676 | # }
|
---|
| 677 | # print "callable_domains: "
|
---|
| 678 | # callable_domains.each{ |dm| print dm.get_name, " " }
|
---|
| 679 | # print "\n"
|
---|
| 680 | # end
|
---|
| 681 |
|
---|
| 682 | # restrict æå®ãããå ´åã«ã¯ãããã«å¾ãããããªããã°ããã§ãã¯ããªã
|
---|
| 683 | callable_domains = @callee_cell.get_restricted_regions( get_callee_ep_name, func_name )
|
---|
| 684 | if callable_domains == nil then
|
---|
| 685 | caller_unrestricted = true
|
---|
| 686 | end
|
---|
| 687 | # print "restrict_list: "
|
---|
| 688 | # delim = ""
|
---|
| 689 | # callable_domains.each{ |domain|
|
---|
| 690 | # print delim, domain
|
---|
| 691 | # delim = ", "
|
---|
| 692 | # }
|
---|
| 693 | # print "\n"
|
---|
| 694 |
|
---|
| 695 | elsif svcplugin.get_caller_cell.callable?( svcplugin.get_callee_cell, svcplugin.get_callee_ep_name, func_name )
|
---|
| 696 | #
|
---|
| 697 | # ç¹å®ã®ãã¡ã¤ã³ããæ¥ç¶ããã¦ããå ´åã¯ï¼å¼åºãå
|
---|
| 698 | ã»ã«ã®
|
---|
| 699 | # restrictããã§ãã¯
|
---|
| 700 | #
|
---|
| 701 | callable_domains << svcplugin.get_caller_cell.get_region.get_domain_root
|
---|
| 702 | else
|
---|
| 703 | #
|
---|
| 704 | # ç¡æå±ããçµåããã¦ãããï¼ç¹å®ã®å¼åºãå
|
---|
| 705 | ãã¡ã¤ã³ã«ã¢ã¯ã»ã¹æ¨©
|
---|
| 706 | # ããªãå ´åï¼callable_domainsã¯ç©ºã¨ãªã
|
---|
| 707 | #
|
---|
| 708 | # pp "#{svcplugin.get_caller_cell.get_name} cannot call #{svcplugin.get_callee_cell.get_name}_#{svcplugin.get_callee_ep_name}_#{func_name}"
|
---|
| 709 | end
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | if caller_unrestricted
|
---|
| 713 | # pp "caller_unrestricted: #{@ct_name_body}"
|
---|
| 714 | return {"check_code"=>"", "user_cannot_callable"=>false}
|
---|
| 715 | end
|
---|
| 716 |
|
---|
| 717 | #
|
---|
| 718 | # éè¤ãåé¤
|
---|
| 719 | #
|
---|
| 720 | callable_domains.uniq!
|
---|
| 721 | #
|
---|
| 722 | # ç¡æå±ã«å¯¾ãããã¡ã¤ã³ãã§ãã¯ã¯å®æ½ããªã
|
---|
| 723 | # ã«ã¼ãã«ãã¡ã¤ã³ã«å¯¾ãããã¡ã¤ã³ãã§ãã¯ã¯å®æ½ããªã
|
---|
| 724 | #
|
---|
| 725 | callable_domains = callable_domains.select { |domain|
|
---|
| 726 | ((domain.get_domain_type.get_option != "OutOfDomain") && \
|
---|
| 727 | (domain.get_domain_type.get_option != "kernel"))
|
---|
| 728 | }
|
---|
| 729 | # pp "callable_domains"
|
---|
| 730 | # pp callable_domains.map{|domain| domain.get_name }
|
---|
| 731 | #
|
---|
| 732 | # ãã¹ã¦ã®ã¦ã¼ã¶ãã¡ã¤ã³ããå¼åºãå¯è½ãªå ´åï¼ãã¡ã¤ã³ãã§ãã¯ã¯
|
---|
| 733 | # å®æ½ããªã
|
---|
| 734 | #
|
---|
| 735 | all_domain_regions = DomainType.get_domain_regions[:HRP].select { |reg|
|
---|
| 736 | ((reg.get_domain_type.get_option != "OutOfDomain") && \
|
---|
| 737 | (reg.get_domain_type.get_option != "kernel"))
|
---|
| 738 |
|
---|
| 739 | }
|
---|
| 740 | # pp "all domains"
|
---|
| 741 | # pp all_domain_regions.map {|reg| reg.get_name}
|
---|
| 742 | if all_domain_regions.all? {|reg| callable_domains.include?(reg)}
|
---|
| 743 | all_domain_callable = true
|
---|
| 744 | end
|
---|
| 745 |
|
---|
| 746 | #
|
---|
| 747 | # å¼åºãå
|
---|
| 748 | ãã¡ã¤ã³ã®ãã§ãã¯å¦çæ¬ä½ã®çæ
|
---|
| 749 | #
|
---|
| 750 | if callable_domains.length == 0
|
---|
| 751 | dbgPrint "callable_domain.length = 0\n"
|
---|
| 752 | #
|
---|
| 753 | # ã¦ã¼ã¶ãã¡ã¤ã³ããå¼åºãä¸å¯è½ãªå ´åã¯
|
---|
| 754 | # åå¥ã®ã¨ã©ã¼ãã§ãã¯ã¯ããï¼åçç¡ç¨ã§E_OACVãè¿ã
|
---|
| 755 | #
|
---|
| 756 | user_cannot_callable = true
|
---|
| 757 | elsif callable_domains.length == 1
|
---|
| 758 | dbgPrint "callable_domain.length = 1\n"
|
---|
| 759 | #
|
---|
| 760 | # å¼åºãå¯è½ãªã¦ã¼ã¶ãã¡ã¤ã³ãåä¸ã®å ´åã¯
|
---|
| 761 | # cdmid != <domainå> ã®å½¢å¼ã§ãã§ãã¯ãã
|
---|
| 762 | #
|
---|
| 763 | check_code += "\t/* HRPSVC0012.1 */\n"
|
---|
| 764 | check_code += "\tif (cdmid != #{callable_domains[0].get_name}) {\n"
|
---|
| 765 | elsif callable_domains.length > 1 && !all_domain_callable
|
---|
| 766 | dbgPrint "callable_domain.length > 1 && not all_domains \n"
|
---|
| 767 | #
|
---|
| 768 | # å¼åºãå¯è½ãªã¦ã¼ã¶ãã¡ã¤ã³ãè¤æ°ã®å ´åã¯
|
---|
| 769 | # TACP(cdmid) & (TACP(<domainå>) | ...) != 0U
|
---|
| 770 | # ã®å½¢å¼ã§ãã§ãã¯ãã
|
---|
| 771 | #
|
---|
| 772 | check_code += "\t/* HRPSVC0012.2 */\n"
|
---|
| 773 | check_code += "\tif((TACP(cdmid) & ("
|
---|
| 774 | check_code += (callable_domains.map { |domain| "TACP(#{domain.get_name})"}).join("|")
|
---|
| 775 | check_code += ")) != 0U) {\n"
|
---|
| 776 | else
|
---|
| 777 | dbgPrint "callable_all_domains\n"
|
---|
| 778 | end
|
---|
| 779 | if check_code != ""
|
---|
| 780 | #
|
---|
| 781 | # å¼åºãå¯è½ãªã¦ã¼ã¶ãã¡ã¤ã³ã®ãã§ãã¯ãããå ´åã¯
|
---|
| 782 | # ã¨ã©ã¼ã³ã¼ããè¿ãããã®ã³ã¼ããåºåãã
|
---|
| 783 | #
|
---|
| 784 | check_code += <<EOS
|
---|
| 785 | /* HRPSVC0013 */
|
---|
| 786 | return E_OACV;
|
---|
| 787 | }
|
---|
| 788 | EOS
|
---|
| 789 | end
|
---|
| 790 |
|
---|
| 791 | return {"check_code"=>check_code, "user_cannot_callable"=>user_cannot_callable}
|
---|
| 792 | end
|
---|
| 793 |
|
---|
| 794 | #---------------------------------------------------------#
|
---|
| 795 | #=== ã·ã°ããã£ã®ãã§ãã¯
|
---|
| 796 | def check_signature signature
|
---|
| 797 | signature.get_function_head_array.each{ |fh|
|
---|
| 798 | type = fh.get_return_type
|
---|
| 799 | check_return_type signature, fh, type
|
---|
| 800 | if fh.get_paramlist.get_items.length > NUM_SVC_ARG_MAX then
|
---|
| 801 | cdl_error( "HSV0005 $1.$2: # of parameter more than #{NUM_SVC_ARG_MAX}", signature.get_name, fh.get_name )
|
---|
| 802 | end
|
---|
| 803 | fh.get_paramlist.get_items.each{ |param|
|
---|
| 804 | check_param signature, fh, param
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
| 807 | end
|
---|
| 808 | #=== æ»ãå¤ã®åã®ãã§ãã¯
|
---|
| 809 | # ER, ER_UINT ã¯æ¨å¥¨ãããå
|
---|
| 810 | # æ´æ°ããã¼ã«ãvoid ã¯å¯è½ãä»ã¯ä¸å¯
|
---|
| 811 | def check_return_type signature, fh, type
|
---|
| 812 | ot = type.get_original_type
|
---|
| 813 | if( type.get_type_str == "ER" || type.get_type_str == "ER_UINT" ) then
|
---|
| 814 | # OK!
|
---|
| 815 | elsif ot.kind_of?( IntType ) || ot.kind_of?( VoidType ) || ot.kind_of?( BoolType ) then
|
---|
| 816 | cdl_warning( "HSW0001 $1.$2: $3 return type cannot get access violation error", signature.get_name, fh.get_name, type.get_type_str.downcase )
|
---|
| 817 | check_intptr "#{signature.get_name}.#{fh.get_name} return type", type
|
---|
| 818 | else
|
---|
| 819 | cdl_error( "HSV0001 $1.$2 return type $3 cannot be used", signature.get_name, fh.get_name, type.get_type_str.to_s+type.get_type_str_post.to_s )
|
---|
| 820 | end
|
---|
| 821 | end
|
---|
| 822 | #=== å¼æ°ã®åã®ãã§ãã¯
|
---|
| 823 | def check_param signature, fh, param
|
---|
| 824 | type = param.get_type
|
---|
| 825 | ot = type.get_original_type
|
---|
| 826 | dir = param.get_direction
|
---|
| 827 | case dir
|
---|
| 828 | when :IN
|
---|
| 829 | if ot.kind_of?( IntType ) || ot.kind_of?( BoolType ) then
|
---|
| 830 | # OK!
|
---|
| 831 | check_intptr "#{signature.get_name}.#{fh.get_name}.#{param.get_name}", type
|
---|
| 832 | elsif ot.kind_of? PtrType then
|
---|
| 833 | check_ptr signature, fh, param, dir
|
---|
| 834 | else
|
---|
| 835 | cdl_error( "HSV0002 $1.$2.$3 $4 param type cannot be used", signature.get_name, fh.get_name, param.get_name, type.get_type_str.to_s+type.get_type_str_post.to_s )
|
---|
| 836 | end
|
---|
| 837 | when :OUT, :INOUT
|
---|
| 838 | if ot.kind_of? PtrType then
|
---|
| 839 | check_ptr signature, fh, param, dir
|
---|
| 840 | else
|
---|
| 841 | # error
|
---|
| 842 | end
|
---|
| 843 | when :SEND, :RECEIVE
|
---|
| 844 | cdl_error( "HSV0008 $1.$2.$3 param direction '$4' cannot be used", signature.get_name, fh.get_name, param.get_name, param.get_direction.to_s.downcase )
|
---|
| 845 | end
|
---|
| 846 | end
|
---|
| 847 | def check_ptr signature, fh, param, dir
|
---|
| 848 | type = param.get_type.get_referto
|
---|
| 849 | ot = type.get_original_type
|
---|
| 850 | if ot.kind_of?( IntType ) || ot.kind_of?( BoolType ) || ot.kind_of?( FloatType ) then
|
---|
| 851 | # OK!
|
---|
| 852 | check_intptr "#{signature.get_name}.#{fh.get_name}.#{param.get_name}", type
|
---|
| 853 | elsif ot.kind_of? PtrType then
|
---|
| 854 | cdl_error( "HSV0003 $1.$2.$3 multi-pointer type cannot be used", signature.get_name, fh.get_name, param.get_name, type.get_type_str.to_s+type.get_type_str_post.to_s )
|
---|
| 855 | elsif ot.kind_of? StructType then
|
---|
| 856 | check_struct signature, fh, param
|
---|
| 857 | else
|
---|
| 858 | cdl_error( "HSV0004 $1.$2.$3 $4 type cannot be used", signature.get_name, fh.get_name, param.get_name, type.get_type_str.to_s+type.get_type_str_post.to_s )
|
---|
| 859 | end
|
---|
| 860 | if ( dir == :OUT || dir == :INOUT) && param.get_string == -1 then
|
---|
| 861 | cdl_error( "HSV0009 $1.$2.$3 string argment is necessary for out/inout parameter", signature.get_name, fh.get_name, param.get_name )
|
---|
| 862 | end
|
---|
| 863 | end
|
---|
| 864 | def check_struct signature, fh, param
|
---|
| 865 | type = param.get_type.get_referto
|
---|
| 866 | ot = type.get_original_type
|
---|
| 867 | ot.get_members_decl.get_items.each{ |decl|
|
---|
| 868 | type = decl.get_type
|
---|
| 869 | ot = type.get_original_type
|
---|
| 870 | if ot.kind_of?( IntType ) || ot.kind_of?( BoolType ) || ot.kind_of?( FloatType ) then
|
---|
| 871 | # OK!
|
---|
| 872 | check_intptr "#{signature.get_name}.#{fh.get_name}.#{param.get_name}.#{decl.get_name} member", type
|
---|
| 873 | else
|
---|
| 874 | dbgPrint "struct member #{decl.get_name} #{type} #{decl.get_type} #{decl.get_type.get_original_type}\n"
|
---|
| 875 | if( decl.get_type.get_original_type.kind_of? ArrayType ) then
|
---|
| 876 | dbgPrint "member array type #{decl.get_type.get_original_type.get_type} #{decl.get_type.get_original_type.get_type.get_original_type}\n"
|
---|
| 877 | check_struct_member_array signature, fh, param, decl
|
---|
| 878 | else
|
---|
| 879 | cdl_error( "HSV0006 $1.$2.$3 $4 type cannot be used as struct member", signature.get_name, fh.get_name, param.get_name, type.get_type_str.to_s+type.get_type_str_post.to_s )
|
---|
| 880 | end
|
---|
| 881 | end
|
---|
| 882 | }
|
---|
| 883 | end
|
---|
| 884 | def check_struct_member_array signature, fh, param, member_decl
|
---|
| 885 | # p "check_struct_member_array: #{member_decl.get_type.get_type_str}"
|
---|
| 886 | type = member_decl.get_type.get_type
|
---|
| 887 | ot = type.get_original_type
|
---|
| 888 | if ot.kind_of?( IntType ) || ot.kind_of?( BoolType ) || ot.kind_of?( FloatType ) then
|
---|
| 889 | # OK!
|
---|
| 890 | check_intptr "#{signature.get_name}.#{fh.get_name}.#{param.get_name}.#{member_decl.get_name} member", type
|
---|
| 891 | else
|
---|
| 892 | cdl_error( "HSV0007 $1.$2.$3 $4 type cannot be used as struct member", signature.get_name, fh.get_name, param.get_name, type.get_type_str.to_s+type.get_type_str_post )
|
---|
| 893 | end
|
---|
| 894 | end
|
---|
| 895 | def check_intptr msg, type
|
---|
| 896 | dbgPrint "check_intptr IN\n"
|
---|
| 897 | t = type
|
---|
| 898 | while( t.kind_of? DefinedType )
|
---|
| 899 | dbgPrint "check_intptr #{msg} #{t.get_type_str} #{t.get_original_type.get_type_str}\n"
|
---|
| 900 | tstr = t.get_type_str
|
---|
| 901 | tstr.sub!( /const /, "" )
|
---|
| 902 | tstr.sub!( /volatile /, "" )
|
---|
| 903 | if tstr == "intptr_t" || tstr == "uintptr_t" then
|
---|
| 904 | cdl_info( "HSI0001 $1 type '$2' not checked by plugin", msg, type.get_type_str )
|
---|
| 905 | end
|
---|
| 906 | t = t.get_type
|
---|
| 907 | end
|
---|
| 908 | end
|
---|
| 909 | end
|
---|
| 910 |
|
---|