[304] | 1 | #!/usr/bin/env ruby
|
---|
| 2 | # -*- coding: utf-8 -*-
|
---|
| 3 | #
|
---|
| 4 | # TOPPERS Configurator by Ruby
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2015 by FUJI SOFT INCORPORATED, JAPAN
|
---|
| 7 | # Copyright (C) 2015,2016 by Embedded and Real-Time Systems Laboratory
|
---|
| 8 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
| 9 | #
|
---|
| 10 | # ä¸è¨èä½æ¨©è
|
---|
| 11 | ã¯ï¼ä»¥ä¸ã®(1)ã(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 12 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 13 | # å¤ã»åé
|
---|
| 14 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 15 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 16 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 17 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 18 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 19 | # ç¨ã§ããå½¢ã§åé
|
---|
| 20 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 21 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 22 | # è
|
---|
| 23 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 24 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 25 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 26 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 27 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 28 | # ã¨ï¼
|
---|
| 29 | # (a) åé
|
---|
| 30 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 31 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 32 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 33 | # (b) åé
|
---|
| 34 | å¸ã®å½¢æ
|
---|
| 35 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 36 | # å ±åãããã¨ï¼
|
---|
| 37 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 38 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 39 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 40 | 責ãããã¨ï¼
|
---|
| 41 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 42 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 43 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 44 | # å
|
---|
| 45 | 責ãããã¨ï¼
|
---|
| 46 | #
|
---|
| 47 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 48 | ã
|
---|
| 49 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 50 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 51 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 52 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 53 | #
|
---|
| 54 | # $Id: cfg.rb 32 2016-01-31 14:45:59Z ertl-hiro $
|
---|
| 55 | #
|
---|
| 56 |
|
---|
| 57 | if ($0 == __FILE__)
|
---|
| 58 | TOOL_ROOT = File.expand_path(File.dirname(__FILE__)) + "/"
|
---|
| 59 | $LOAD_PATH.unshift(TOOL_ROOT)
|
---|
| 60 | end
|
---|
| 61 |
|
---|
| 62 | require "pp"
|
---|
| 63 | require "csv"
|
---|
| 64 | require "optparse"
|
---|
| 65 | require "pstore"
|
---|
| 66 | require "common/GenFile.rb"
|
---|
| 67 | require "common/StrVal.rb"
|
---|
| 68 | require "common/SRecord.rb"
|
---|
| 69 |
|
---|
| 70 | #
|
---|
| 71 | # å®æ°å®ç¾©
|
---|
| 72 | #
|
---|
| 73 | # å
|
---|
| 74 | ±é
|
---|
| 75 | VERSION = "1.0.0"
|
---|
| 76 |
|
---|
| 77 | # cfg1_outé¢ä¿
|
---|
| 78 | CFG1_PREFIX = "TOPPERS_cfg_"
|
---|
| 79 | CFG1_MAGIC_NUM = "TOPPERS_magic_number"
|
---|
| 80 | CFG1_SIZEOF_SIGNED = "TOPPERS_sizeof_signed_t"
|
---|
| 81 | CFG1_OUT_C = "cfg1_out.c"
|
---|
| 82 | CFG1_OUT_DB = "cfg1_out.db"
|
---|
| 83 | CFG1_OUT_SREC = "cfg1_out.srec"
|
---|
| 84 | CFG1_OUT_SYMS = "cfg1_out.syms"
|
---|
| 85 | CFG1_OUT_TIMESTAMP = "cfg1_out.timestamp"
|
---|
| 86 |
|
---|
| 87 | # cfg2_outé¢ä¿
|
---|
| 88 | CFG2_OUT_DB = "cfg2_out.db"
|
---|
| 89 |
|
---|
| 90 | #
|
---|
| 91 | # ã¨ã©ã¼çºçæç¡ãã©ã°
|
---|
| 92 | #
|
---|
| 93 | $errorFlag = false
|
---|
| 94 |
|
---|
| 95 | #
|
---|
| 96 | # ã¨ã©ã¼ï¼è¦å表示é¢æ°
|
---|
| 97 | #
|
---|
| 98 | # ä¸è¬çãªã¨ã©ã¼è¡¨ç¤ºï¼å¦çãä¸æï¼
|
---|
| 99 | def error_exit(message, location = "")
|
---|
| 100 | location += " " if location != ""
|
---|
| 101 | abort("#{location}error: #{message}")
|
---|
| 102 | end
|
---|
| 103 |
|
---|
| 104 | # ä¸è¬çãªã¨ã©ã¼è¡¨ç¤ºï¼å¦çãç¶ç¶ï¼
|
---|
| 105 | def error(message, location = "")
|
---|
| 106 | location += " " if location != ""
|
---|
| 107 | STDERR.puts("#{location}error: #{message}")
|
---|
| 108 | $errorFlag = true
|
---|
| 109 | end
|
---|
| 110 |
|
---|
| 111 | # ä¸è¬çãªè¦å表示
|
---|
| 112 | def warning(message, location = "")
|
---|
| 113 | location += " " if location != ""
|
---|
| 114 | STDERR.puts("#{location}warning: #{message}")
|
---|
| 115 | end
|
---|
| 116 |
|
---|
| 117 | # ã·ã¹ãã ã³ã³ãã£ã®ã¥ã¬ã¼ã·ã§ã³ãã¡ã¤ã«ã®æ§æ解ææã®ã¨ã©ã¼
|
---|
| 118 | $no_parse_error = 0
|
---|
| 119 | def parse_error(cfgFile, message)
|
---|
| 120 | error(message, "#{cfgFile.getFileName()}:#{cfgFile.getLineNo}:")
|
---|
| 121 | if ($no_parse_error += 1) >= 10
|
---|
| 122 | error_exit("too many errors emitted, stopping now")
|
---|
| 123 | end
|
---|
| 124 | end
|
---|
| 125 |
|
---|
| 126 | # éçAPIå¦çæã®ã¨ã©ã¼
|
---|
| 127 | def error_api(params, message)
|
---|
| 128 | error(message, "#{params[:_file_]}:#{params[:_line_]}:")
|
---|
| 129 | end
|
---|
| 130 |
|
---|
| 131 | # éçAPIå¦çæã®ã¨ã©ã¼ï¼ã¨ã©ã¼ã³ã¼ãä»ãï¼
|
---|
| 132 | def error_ercd(errorCode, params, message)
|
---|
| 133 | error_api(params, "#{errorCode}: #{message}")
|
---|
| 134 | end
|
---|
| 135 |
|
---|
| 136 | # éçAPIå¦çæã®è¦å
|
---|
| 137 | def warning_api(params, message)
|
---|
| 138 | warning(message, "#{params[:_file_]}:#{params[:_line_]}:")
|
---|
| 139 | end
|
---|
| 140 |
|
---|
| 141 | # ãã©ã¡ã¼ã¿ã®ã¨ã©ã¼
|
---|
| 142 | def error_wrong(errorCode, params, symbol, wrong)
|
---|
| 143 | error_ercd(errorCode, params, "#{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 144 | " is #{wrong} in #{params[:apiname]}")
|
---|
| 145 | end
|
---|
| 146 |
|
---|
| 147 | def error_wrong_id(errorCode, params, symbol, objid, wrong)
|
---|
| 148 | error_ercd(errorCode, params, "#{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 149 | " is #{wrong} in #{params[:apiname]} of #{params[objid]}")
|
---|
| 150 | end
|
---|
| 151 |
|
---|
| 152 | def error_wrong_sym(errorCode, params, symbol, symbol2, wrong)
|
---|
| 153 | error_ercd(errorCode, params, "#{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 154 | " is #{wrong} in #{params[:apiname]}" \
|
---|
| 155 | " of #{symbol2.to_s} `#{params[symbol2]}'")
|
---|
| 156 | end
|
---|
| 157 |
|
---|
| 158 | # ãã©ã¡ã¼ã¿ä¸æ£ã®ã¨ã©ã¼
|
---|
| 159 | def error_illegal(errorCode, params, symbol)
|
---|
| 160 | error_ercd(errorCode, params, "illegal #{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 161 | " in #{params[:apiname]}")
|
---|
| 162 | end
|
---|
| 163 |
|
---|
| 164 | def error_illegal_id(errorCode, params, symbol, objid)
|
---|
| 165 | error_ercd(errorCode, params, "illegal #{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 166 | " in #{params[:apiname]} of #{params[objid]}")
|
---|
| 167 | end
|
---|
| 168 |
|
---|
| 169 | def error_illegal_sym(errorCode, params, symbol, symbol2)
|
---|
| 170 | error_ercd(errorCode, params, "illegal #{symbol.to_s} `#{params[symbol]}'" \
|
---|
| 171 | " in #{params[:apiname]} of #{symbol2.to_s} `#{params[symbol2]}'")
|
---|
| 172 | end
|
---|
| 173 |
|
---|
| 174 | #
|
---|
| 175 | # Stringã¯ã©ã¹ã®æ¡å¼µï¼äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®ä½æï¼å±éï¼
|
---|
| 176 | #
|
---|
| 177 | class String
|
---|
| 178 | #
|
---|
| 179 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®ä½æ
|
---|
| 180 | #
|
---|
| 181 | def quote
|
---|
| 182 | result = ""
|
---|
| 183 | self.chars do |c|
|
---|
| 184 | case c
|
---|
| 185 | when "'"
|
---|
| 186 | result += "\\\'"
|
---|
| 187 | when "\""
|
---|
| 188 | result += "\\\""
|
---|
| 189 | when "\0"
|
---|
| 190 | result += "\\0"
|
---|
| 191 | when "\a"
|
---|
| 192 | result += "\\a"
|
---|
| 193 | when "\b"
|
---|
| 194 | result += "\\b"
|
---|
| 195 | when "\f"
|
---|
| 196 | result += "\\f"
|
---|
| 197 | when "\n"
|
---|
| 198 | result += "\\n"
|
---|
| 199 | when "\r"
|
---|
| 200 | result += "\\r"
|
---|
| 201 | when "\t"
|
---|
| 202 | result += "\\t"
|
---|
| 203 | when "\v"
|
---|
| 204 | result += "\\v"
|
---|
| 205 | when "\\"
|
---|
| 206 | result += "\\\\"
|
---|
| 207 | else
|
---|
| 208 | result += c
|
---|
| 209 | end
|
---|
| 210 | end
|
---|
| 211 | return("\"" + result + "\"")
|
---|
| 212 | end
|
---|
| 213 |
|
---|
| 214 | #
|
---|
| 215 | # äºéå¼ç¨ç¬¦ã§å²ã¾ããæååã®å±é
|
---|
| 216 | #
|
---|
| 217 | def unquote
|
---|
| 218 | if /^\"(.*)\"$/m =~ self
|
---|
| 219 | str = $1
|
---|
| 220 | result = ""
|
---|
| 221 | while (/^(.*)\\(.*)$/m =~ str)
|
---|
| 222 | result += $1
|
---|
| 223 | str = $2
|
---|
| 224 | case str
|
---|
| 225 | when /^[aA](.*)$/m
|
---|
| 226 | result += "\a"
|
---|
| 227 | str = $1
|
---|
| 228 | when /^[bB](.*)$/m
|
---|
| 229 | result += "\b"
|
---|
| 230 | str = $1
|
---|
| 231 | when /^[fF](.*)$/m
|
---|
| 232 | result += "\f"
|
---|
| 233 | str = $1
|
---|
| 234 | when /^[nN](.*)$/m
|
---|
| 235 | result += "\n"
|
---|
| 236 | str = $1
|
---|
| 237 | when /^[rR](.*)$/m
|
---|
| 238 | result += "\r"
|
---|
| 239 | str = $1
|
---|
| 240 | when /^[tT](.*)$/m
|
---|
| 241 | result += "\t"
|
---|
| 242 | str = $1
|
---|
| 243 | when /^[vV](.*)$/m
|
---|
| 244 | result += "\v"
|
---|
| 245 | str = $1
|
---|
| 246 | when /^[xX]([0-9a-fA-F][0-9a-fA-F]?)(.*)$/m
|
---|
| 247 | result += $1.hex
|
---|
| 248 | str = $2
|
---|
| 249 | when /^([0-7][0-7]?[0-7]?)(.*)$/m
|
---|
| 250 | result += $1.oct
|
---|
| 251 | str = $2
|
---|
| 252 | when /^\\(.*)$/m
|
---|
| 253 | result += "\\"
|
---|
| 254 | str = $1
|
---|
| 255 | end
|
---|
| 256 | end
|
---|
| 257 | return(result + str)
|
---|
| 258 | else
|
---|
| 259 | return(self.dup)
|
---|
| 260 | end
|
---|
| 261 | end
|
---|
| 262 | end
|
---|
| 263 |
|
---|
| 264 | #
|
---|
| 265 | # ã·ã³ãã«ãã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
| 266 | #
|
---|
| 267 | # 以ä¸ã®ã¡ã½ããã¯ï¼GNUã®nmãçæããã·ã³ãã«ãã¡ã¤ã«ã«å¯¾å¿ãã¦ããï¼
|
---|
| 268 | # å¥ã®ãã¼ã«ã«å¯¾å¿ããå ´åã«ã¯ï¼ãã®ã¡ã½ãããæ¸ãæããã°ããï¼
|
---|
| 269 | #
|
---|
| 270 | def ReadSymbolFile(symbolFileName)
|
---|
| 271 | begin
|
---|
| 272 | symbolFile = File.open(symbolFileName)
|
---|
| 273 | rescue Errno::ENOENT, Errno::EACCES => ex
|
---|
| 274 | abort(ex.message)
|
---|
| 275 | end
|
---|
| 276 |
|
---|
| 277 | symbolAddress = {}
|
---|
| 278 | symbolFile.each do |line|
|
---|
| 279 | # ã¹ãã¼ã¹åºåãã§å解
|
---|
| 280 | fields = line.split(/\s+/)
|
---|
| 281 |
|
---|
| 282 | # 3åã«ãªã£ã¦ããªãè¡ã¯é¤å¤
|
---|
| 283 | if (fields.size == 3)
|
---|
| 284 | symbolAddress[fields[2]] = fields[0].hex
|
---|
| 285 | end
|
---|
| 286 | end
|
---|
| 287 | symbolFile.close
|
---|
| 288 | return(symbolAddress)
|
---|
| 289 | end
|
---|
| 290 |
|
---|
| 291 | #
|
---|
| 292 | # å¤åå¾ã·ã³ãã«ãã°ãã¼ãã«å¤æ°ã¨ãã¦å®ç¾©ãã
|
---|
| 293 | #
|
---|
| 294 | def DefineSymbolValue
|
---|
| 295 | $symbolValueTable.each do |symbolName, symbolData|
|
---|
| 296 | if symbolData.has_key?(:VALUE)
|
---|
| 297 | eval("$#{symbolName} = " \
|
---|
| 298 | "StrVal.new(\"#{symbolName}\", #{symbolData[:VALUE]})")
|
---|
| 299 | end
|
---|
| 300 | end
|
---|
| 301 | end
|
---|
| 302 |
|
---|
| 303 | #
|
---|
| 304 | # ã¤ã³ã¯ã«ã¼ããã¹ãããã¡ã¤ã«ãæ¢ã
|
---|
| 305 | #
|
---|
| 306 | def SearchFilePath(fileName)
|
---|
| 307 | if File.exist?(fileName)
|
---|
| 308 | # æå®ãããã¡ã¤ã«ãã¹ã«åå¨ãã
|
---|
| 309 | return fileName
|
---|
| 310 | elsif /^\./ =~ fileName
|
---|
| 311 | # ç¸å¯¾ãã¹ãæå®ãã¦ãã¦è¦ã¤ãããªãã£ãå ´åï¼åå¨ããªããã®ã¨ãã
|
---|
| 312 | #ï¼æå³ããªããã¡ã¤ã«ã対象ã¨ãªããã¨ãé²æ¢ï¼
|
---|
| 313 | return nil
|
---|
| 314 | else
|
---|
| 315 | # åã¤ã³ã¯ã«ã¼ããã¹ãããã¡ã¤ã«åå¨ãã§ãã¯
|
---|
| 316 | $includePaths.each do |includePath|
|
---|
| 317 | path = includePath + "/" + fileName
|
---|
| 318 | # è¦ã¤ãã£ããç¸å¯¾ãã¹ãè¿ã
|
---|
| 319 | if File.exist?(path)
|
---|
| 320 | return path
|
---|
| 321 | end
|
---|
| 322 | end
|
---|
| 323 | return nil
|
---|
| 324 | end
|
---|
| 325 | end
|
---|
| 326 |
|
---|
| 327 | #
|
---|
| 328 | # æå®ããçæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãæ¤ç´¢ãã¦loadãã
|
---|
| 329 | #
|
---|
| 330 | def IncludeTrb(fileName)
|
---|
| 331 | filePath = SearchFilePath(fileName)
|
---|
| 332 | if filePath.nil?
|
---|
| 333 | error_exit("`#{fileName}' not found")
|
---|
| 334 | else
|
---|
| 335 | load(filePath)
|
---|
| 336 | end
|
---|
| 337 | end
|
---|
| 338 |
|
---|
| 339 | #
|
---|
| 340 | # ãã¹3ã®å¦ç
|
---|
| 341 | #
|
---|
| 342 | def Pass3
|
---|
| 343 | #
|
---|
| 344 | # ãã¹2ããå¼ã渡ãããæ
|
---|
| 345 | å ±ããã¡ã¤ã«ããèªã¿è¾¼ã
|
---|
| 346 | #
|
---|
| 347 | db = PStore.new(CFG2_OUT_DB)
|
---|
| 348 | db.transaction(true) do
|
---|
| 349 | $apiDefinition = db[:apiDefinition]
|
---|
| 350 | $symbolValueTable = db[:symbolValueTable]
|
---|
| 351 | $cfgFileInfo = db[:cfgFileInfo]
|
---|
| 352 | $includeFiles = db[:includeFiles]
|
---|
| 353 | $cfgData = db[:cfgData]
|
---|
| 354 | $asmLabel = db[:asmLabel]
|
---|
| 355 | $bLittleEndian = db[:bLittleEndian]
|
---|
| 356 | end
|
---|
| 357 |
|
---|
| 358 | #
|
---|
| 359 | # å¤åå¾ã·ã³ãã«ãã°ãã¼ãã«å¤æ°ã¨ãã¦å®ç¾©ãã
|
---|
| 360 | #
|
---|
| 361 | DefineSymbolValue()
|
---|
| 362 |
|
---|
| 363 | #
|
---|
| 364 | # çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãå®è¡ãã
|
---|
| 365 | #
|
---|
| 366 | $trbFileNames.each do |trbFileName|
|
---|
| 367 | IncludeTrb(trbFileName)
|
---|
| 368 | end
|
---|
| 369 | end
|
---|
| 370 |
|
---|
| 371 | #
|
---|
| 372 | # çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼åãã®é¢æ°
|
---|
| 373 | #
|
---|
| 374 | def SYMBOL(symbol)
|
---|
| 375 | if !$romSymbol.nil? && $romSymbol.has_key?($asmLabel + symbol)
|
---|
| 376 | return $romSymbol[$asmLabel + symbol]
|
---|
| 377 | else
|
---|
| 378 | return nil
|
---|
| 379 | end
|
---|
| 380 | end
|
---|
| 381 |
|
---|
| 382 | def BCOPY(startIData, startData, size)
|
---|
| 383 | if !$romImage.nil?
|
---|
| 384 | copyData = $romImage.get_data(startIData, size)
|
---|
| 385 | $romImage.set_data(startData, copyData)
|
---|
| 386 | end
|
---|
| 387 | end
|
---|
| 388 |
|
---|
| 389 | def PEEK(address, size)
|
---|
| 390 | if !$romImage.nil?
|
---|
| 391 | return $romImage.get_value(address, size, false)
|
---|
| 392 | else
|
---|
| 393 | return nil
|
---|
| 394 | end
|
---|
| 395 | end
|
---|
| 396 |
|
---|
| 397 | #
|
---|
| 398 | # ã°ãã¼ãã«å¤æ°ã®åæå
|
---|
| 399 | #
|
---|
| 400 | $kernel = nil
|
---|
| 401 | $pass = nil
|
---|
| 402 | $includePaths = []
|
---|
| 403 | $trbFileNames = []
|
---|
| 404 | $apiTableFileNames = []
|
---|
| 405 | $symvalTableFileNames = []
|
---|
| 406 | $romImageFileName = nil
|
---|
| 407 | $romSymbolFileName = nil
|
---|
| 408 | $dependencyFileName = nil
|
---|
| 409 | $idInputFileName = nil
|
---|
| 410 | $idOutputFileName = nil
|
---|
| 411 |
|
---|
| 412 | #
|
---|
| 413 | # ãªãã·ã§ã³ã®å¦ç
|
---|
| 414 | #
|
---|
| 415 | opt = OptionParser.new(banner="Usage: cfg.rb [options] CONFIG-FILE", 40)
|
---|
| 416 | opt.version = VERSION
|
---|
| 417 | opt.on("-k KERNEL", "--kernel KERNEL", "kernel profile name") do |val|
|
---|
| 418 | $kernel = val
|
---|
| 419 | end
|
---|
| 420 | opt.on("-p NUM", "--pass NUM", "processing pass number") do |val|
|
---|
| 421 | $pass = val
|
---|
| 422 | end
|
---|
| 423 | opt.on("-I PATH", "--include-path PATH", "include directory path") do |val|
|
---|
| 424 | $includePaths.push(val)
|
---|
| 425 | end
|
---|
| 426 | opt.on("-T TRB-FILE", "--trb-file TRB-FILE",
|
---|
| 427 | "generation script (trb file)") do |val|
|
---|
| 428 | $trbFileNames.push(val)
|
---|
| 429 | end
|
---|
| 430 | opt.on("--api-table API-TABLE-FILE", "static API table file") do |val|
|
---|
| 431 | $apiTableFileNames.push(val)
|
---|
| 432 | end
|
---|
| 433 | opt.on("--symval-table SYMVAL-TABLE-FILE", "symbol-value table file") do |val|
|
---|
| 434 | $symvalTableFileNames.push(val)
|
---|
| 435 | end
|
---|
| 436 | opt.on("--rom-image SREC-FILE", "rom image file (s-record)") do |val|
|
---|
| 437 | $romImageFileName = val
|
---|
| 438 | end
|
---|
| 439 | opt.on("--rom-symbol SYMS-FILE", "rom symbol table file (nm)") do |val|
|
---|
| 440 | $romSymbolFileName = val
|
---|
| 441 | end
|
---|
| 442 | opt.on("--id-input-file ID-FILE", "ID input file") do |val|
|
---|
| 443 | $idInputFileName = val
|
---|
| 444 | end
|
---|
| 445 | opt.on("--id-output-file ID-FILE", "ID output file") do |val|
|
---|
| 446 | $idOutputFileName = val
|
---|
| 447 | end
|
---|
| 448 | opt.on("--external-id", "generate object ID variables") do
|
---|
| 449 | $USE_EXTERNAL_ID = true
|
---|
| 450 | end
|
---|
| 451 | opt.on("-M [DEPEND-FILE]", "--print-dependencies [DEPEND-FILE]",
|
---|
| 452 | "dependency file") do |val|
|
---|
| 453 | $dependencyFileName = val.nil? ? "" : val
|
---|
| 454 | end
|
---|
| 455 | opt.on("-O", "--omit-output-db", "omit DB file output") do
|
---|
| 456 | $omitOutputDb = true
|
---|
| 457 | end
|
---|
| 458 | opt.on("-v", "--version", "show version number") do
|
---|
| 459 | abort(opt.ver)
|
---|
| 460 | end
|
---|
| 461 | opt.on("-h", "--help", "show help (this)") do
|
---|
| 462 | abort(opt.help)
|
---|
| 463 | end
|
---|
| 464 |
|
---|
| 465 | begin
|
---|
| 466 | $configFileNames = opt.parse(ARGV)
|
---|
| 467 | rescue OptionParser::ParseError
|
---|
| 468 | abort(opt.help)
|
---|
| 469 | end
|
---|
| 470 |
|
---|
| 471 | #
|
---|
| 472 | # ãªãã·ã§ã³ã®ãã§ãã¯
|
---|
| 473 | #
|
---|
| 474 | # ä¾åé¢ä¿åºåã¢ã¼ã
|
---|
| 475 | if $pass.nil?
|
---|
| 476 | # ãã¹ã®æå®ã¯å¿
|
---|
| 477 | é
|
---|
| 478 | STDERR.puts("`--pass' option is mandatory")
|
---|
| 479 | abort(opt.help)
|
---|
| 480 | elsif /^[123]$/ !~ $pass
|
---|
| 481 | STDERR.puts("pass number `#{$pass}' is not valid")
|
---|
| 482 | abort(opt.help)
|
---|
| 483 | end
|
---|
| 484 |
|
---|
| 485 | # ãã¹1ã§ã¯ï¼éçAPIãã¼ãã«ã¯å¿
|
---|
| 486 | é
|
---|
| 487 | if ($pass == "1" && $apiTableFileNames.empty?)
|
---|
| 488 | STDERR.puts("`--api-table' option must be specified in pass 1")
|
---|
| 489 | abort(opt.help)
|
---|
| 490 | end
|
---|
| 491 |
|
---|
| 492 | # ãã¹1以å¤ã§ã¯ï¼çæã¹ã¯ãªããï¼trbãã¡ã¤ã«ï¼ãå¿
|
---|
| 493 | é
|
---|
| 494 | if ($pass != "1" && $trbFileNames.empty?)
|
---|
| 495 | STDERR.puts("`--trb-file' must be specified except in pass 1")
|
---|
| 496 | abort(opt.help)
|
---|
| 497 | end
|
---|
| 498 |
|
---|
| 499 | #
|
---|
| 500 | # æå®ãããã·ã³ãã«ãã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
| 501 | #
|
---|
| 502 | if !$romSymbolFileName.nil?
|
---|
| 503 | if File.exist?($romSymbolFileName)
|
---|
| 504 | $romSymbol = ReadSymbolFile($romSymbolFileName)
|
---|
| 505 | else
|
---|
| 506 | error_exit("`#{$romSymbolFileName}' not found")
|
---|
| 507 | end
|
---|
| 508 | end
|
---|
| 509 |
|
---|
| 510 | #
|
---|
| 511 | # æå®ãããSã¬ã³ã¼ããã¡ã¤ã«ã®èªã¿è¾¼ã¿
|
---|
| 512 | #
|
---|
| 513 | if !$romImageFileName.nil?
|
---|
| 514 | if File.exist?($romImageFileName)
|
---|
| 515 | $romImage = SRecord.new($romImageFileName)
|
---|
| 516 | else
|
---|
| 517 | error_exit("`#{$romImageFileName}' not found")
|
---|
| 518 | end
|
---|
| 519 | end
|
---|
| 520 |
|
---|
| 521 | #
|
---|
| 522 | # ãã¹ã«å¾ã£ã¦åå¦çãå®è¡
|
---|
| 523 | #
|
---|
| 524 | case $pass
|
---|
| 525 | when "1"
|
---|
| 526 | load("pass1.rb")
|
---|
| 527 | Pass1()
|
---|
| 528 | when "2"
|
---|
| 529 | load("pass2.rb")
|
---|
| 530 | Pass2()
|
---|
| 531 | when "3"
|
---|
| 532 | Pass3()
|
---|
| 533 | else
|
---|
| 534 | error_exit("invalid pass: #{$pass}")
|
---|
| 535 | end
|
---|
| 536 |
|
---|
| 537 | # ã¨ã©ã¼çºçæã¯abortãã
|
---|
| 538 | if $errorFlag
|
---|
| 539 | if ($0 == __FILE__)
|
---|
| 540 | abort()
|
---|
| 541 | else
|
---|
| 542 | # simplecov対å¿
|
---|
| 543 | raise()
|
---|
| 544 | end
|
---|
| 545 | end
|
---|
| 546 |
|
---|
| 547 | #
|
---|
| 548 | # ä½æãããã¹ã¦ã®ãã¡ã¤ã«ãåºåãã
|
---|
| 549 | #
|
---|
| 550 | GenFile.output
|
---|
| 551 |
|
---|
| 552 | #
|
---|
| 553 | # ã¿ã¤ã ã¹ã¿ã³ããã¡ã¤ã«ã®çæ
|
---|
| 554 | #
|
---|
| 555 | if !$timeStampFileName.nil?
|
---|
| 556 | File.open($timeStampFileName, "w").close
|
---|
| 557 | end
|
---|