Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

474 lines
13 KiB

  1. #!/usr/local/bin/perl -w
  2. ##
  3. ## Copyright (c) 2000, Intel Corporation
  4. ## All rights reserved.
  5. ##
  6. ## WARRANTY DISCLAIMER
  7. ##
  8. ## THESE MATERIALS ARE PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  9. ## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  10. ## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  11. ## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR ITS
  12. ## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  13. ## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  14. ## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  15. ## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  16. ## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY OR TORT (INCLUDING
  17. ## NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THESE
  18. ## MATERIALS, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19. ##
  20. ## Intel Corporation is the author of the Materials, and requests that all
  21. ## problem reports or change requests be submitted to it directly at
  22. ## http://developer.intel.com/opensource.
  23. ##
  24. $GenDir = shift(@ARGV);
  25. $EmdbDir = shift(@ARGV);
  26. ### This script reads dec_emdb.tab, which holds for each inst_id its format,
  27. ### major opcode, and template_role. It creates builder_info.c which contains
  28. ### two initialized arrays:
  29. ### - square_formats[] - the list of formats in each square
  30. ### - square_emdb_lines[] - the list of inst_id's in each square
  31. ### - format_emdb_lines[] - the list of inst_id's in each format
  32. ### - format_extension_masks[] - extension mask from each format
  33. ### - LOG2[] - an array which hold the log2 value foreach number
  34. ### between 0 and 2^11-1
  35. ### It also creates builder_info.h which contains the relevant typedefs.
  36. open(EMDB, "$GenDir/dec_ign_emdb.tab") || die "Can't open dec_ign_emdb.tab\n";
  37. open(OUT_C, ">$GenDir/builder_info.c") || die "Can't open builder_info.c\n";
  38. open(OUT_H, ">$GenDir/builder_info.h") || die "Can't open builder_info.h\n";
  39. #if ($ENV{HOSTTYPE} eq "WINNT")
  40. #{
  41. # open(FORMAT, "$EmdbDir/emdb_formats.txt") ||
  42. # die "Can't open emdb_formats.txt\n";
  43. #}
  44. #else
  45. {
  46. open(FORMAT, "$EmdbDir/emdb_formats.txt") ||
  47. die "Can't open emdb_formats.txt\n";
  48. }
  49. require "EM_perl.h";
  50. $MAX_FORMATS_IN_SQUARE = 1;
  51. $MAX_EMDB_LINES_IN_SQUARE = 1;
  52. $MAX_EMDB_LINES_IN_FORMAT = 1;
  53. ### create all 64 initial squares
  54. @template_roles = ("INT", "MEM", "FP", "BR", "LONG");
  55. for ($i = 0; $i < $EM_NUM_OF_MAJOR_OPCODES; $i++)
  56. {
  57. for ($j = 0; $j <= $#template_roles; $j++)
  58. {
  59. $square = sprintf("0x%x_%s", $i, $template_roles[$j]);
  60. $square =~ tr/[a-z]/[A-Z]/;
  61. push (@square_enum, $square);
  62. }
  63. }
  64. ### major opcodes 0x3 and 0x6 of BRANCH instructions are ignored
  65. $emdb_lines_in_square{"0X3_BR"} = 1;
  66. $square_emdb_lines{"0X3_BR"} = "EM_IGNOP";
  67. $emdb_lines_in_square{"0X6_BR"} = 1;
  68. $square_emdb_lines{"0X6_BR"} = "EM_IGNOP";
  69. ### add each emdb line to calculated square and format
  70. while (<EMDB>)
  71. {
  72. if (/^EM/)
  73. {
  74. /(EM_\w+),(\w+),(\w+),(\w+),/;
  75. $inst_id = $1;
  76. $format = $2;
  77. $major_opcode = $3;
  78. $template_role[0] = $4;
  79. $template_role[1] = "";
  80. # if ($template_role[0] eq "LONG")
  81. # {
  82. # $template_role[0] = "INT";
  83. # }
  84. # if ($template_role[0] eq "BR2")
  85. # {
  86. # $template_role[0] = "BR";
  87. # }
  88. if ($template_role[0] eq "ALU")
  89. {
  90. $template_role[0] = "INT";
  91. $template_role[1] = "MEM";
  92. }
  93. # if ($inst_id =~ /EM_MOVL_/) ### movl case
  94. # {
  95. # $template_role[0] = "LONG";
  96. # }
  97. $tr_no = 0;
  98. while ($template_role[$tr_no])
  99. {
  100. $square = $major_opcode . "_" . $template_role[$tr_no];
  101. $square =~ tr/[a-z]/[A-Z]/;
  102. if ($format ne "NONE")
  103. {
  104. $index = -1;
  105. for ($i = 0; $i <= $#square_enum; $i++)
  106. {
  107. if ($square eq $square_enum[$i])
  108. {
  109. $index = $i;
  110. }
  111. }
  112. if ($index == -1)
  113. {
  114. die "$square not known\n";
  115. }
  116. $format = "EM_FORMAT_" . $format;
  117. if (!defined $square_formats{$square})
  118. {
  119. $square_formats{$square} = $format;
  120. $formats_in_square{$square} = 1;
  121. }
  122. else
  123. {
  124. if (!defined $format_emdb_lines{$format})
  125. {
  126. $formats_in_square{$square} += 1;
  127. if ($formats_in_square{$square} > $MAX_FORMATS_IN_SQUARE)
  128. {
  129. $MAX_FORMATS_IN_SQUARE = $formats_in_square{$square};
  130. }
  131. $square_formats{$square} .= "," . $format;
  132. }
  133. }
  134. if (!defined $format_emdb_lines{$format})
  135. {
  136. $emdb_lines_in_format{$format} = 1;
  137. $format_emdb_lines{$format} = $inst_id;
  138. }
  139. else
  140. {
  141. $format_emdb_lines{$format} .= "," . $inst_id;
  142. $emdb_lines_in_format{$format} += 1;
  143. if ($emdb_lines_in_format{$format} >
  144. $MAX_EMDB_LINES_IN_FORMAT)
  145. {
  146. $MAX_EMDB_LINES_IN_FORMAT =
  147. $emdb_lines_in_format{$format};
  148. }
  149. }
  150. if (!defined $square_emdb_lines{$square})
  151. {
  152. $emdb_lines_in_square{$square} = 1;
  153. $square_emdb_lines{$square} = $inst_id;
  154. }
  155. else
  156. {
  157. $emdb_lines_in_square{$square} += 1;
  158. if ($emdb_lines_in_square{$square} >
  159. $MAX_EMDB_LINES_IN_SQUARE)
  160. {
  161. $MAX_EMDB_LINES_IN_SQUARE =
  162. $emdb_lines_in_square{$square};
  163. }
  164. $square_emdb_lines{$square} .= "," . $inst_id;
  165. }
  166. }
  167. $tr_no++;
  168. }
  169. }
  170. }
  171. ### check that there are no instructions with ignored major opcodes
  172. if ($emdb_lines_in_square{"0X3_BR"} != 1 || $emdb_lines_in_square{"0X6_BR"} != 1)
  173. {
  174. print STDERR "ERROR: Exist EM_OPROLE_BR instructions with
  175. ignored major opcode (0x3 or 0x6) !!!\n";
  176. }
  177. ################################################
  178. ### Calculate extension bit mask for each format
  179. ################################################
  180. push(@format_enum, "EM_FORMAT_NONE");
  181. $mask{"EM_FORMAT_NONE"} = "IEL_CONST64(0, 0)";
  182. $ext{"EM_FORMAT_NONE"} = "{0,0}";
  183. for ($i=1; $i < $MAX_EXTENSION; $i++)
  184. {
  185. $ext{"EM_FORMAT_NONE"} .= ",{0,0}";
  186. }
  187. while(<FORMAT>)
  188. {
  189. if (/^(EM_FORMAT_\w+)/)
  190. {
  191. @format_line = split(/\s+/, $_);
  192. $format_name = $1;
  193. push (@format_enum, $format_name);
  194. # $mask{$format_name} = 0;
  195. $mask_low = 0;
  196. $mask_high = 0;
  197. $ext{$format_name} = "";
  198. for ($i = 1; $i <= $MAX_EXTENSION; $i++)
  199. {
  200. $format_line[$i] =~ /(\d+).(\d+)/;
  201. $pos = $1;
  202. $size = $2;
  203. $ext{$format_name} .= "\{$pos,$size\}";
  204. $ext{$format_name} .= "," unless ($i == $MAX_EXTENSION);
  205. if ($size != 0)
  206. {
  207. $pos -= $EM_PREDICATE_BITS; #position relative to the end of qp field
  208. if ($pos < 0) #bit mask contribution in bits 0-5
  209. {
  210. $mask_low |= ((1 << $size) - 1) << ($pos + $EM_PREDICATE_BITS);
  211. }
  212. else #bit mask contribution in bits 6-36
  213. {
  214. $mask_high |= ((1 << $size) - 1) << $pos;
  215. }
  216. }
  217. }
  218. ###combine low and high masks into U64 integer
  219. $mask_low |= ($mask_high << $EM_PREDICATE_BITS);
  220. $mask_high >>= (32 - $EM_PREDICATE_BITS);
  221. $mask{$format_name} = sprintf("IEL_CONST64(0x%x, 0x%x)", $mask_low, $mask_high);
  222. }
  223. }
  224. ########################
  225. ### Write builder_info.h
  226. ########################
  227. select (OUT_H);
  228. print ("#ifndef _BUILDER_INFO_H\n");
  229. print ("#define _BUILDER_INFO_H\n\n");
  230. print ("#include \"emdb_types.h\"\n\n");
  231. print ("#include \"inst_ids.h\"\n\n");
  232. print ("#include \"inst_ign_ids.h\"\n\n");
  233. print ("#include \"iel.h\"\n\n");
  234. ### print constants
  235. print ("#define MAX_FORMATS_IN_SQUARE $MAX_FORMATS_IN_SQUARE\n\n");
  236. if ($MAX_EMDB_LINES_IN_SQUARE > $MAX_EMDB_LINES_IN_FORMAT)
  237. {
  238. $MAX_EMDB_LINES = $MAX_EMDB_LINES_IN_SQUARE;
  239. print ("#define MAX_EMDB_LINES $MAX_EMDB_LINES\n\n");
  240. }
  241. else
  242. {
  243. $MAX_EMDB_LINES = $MAX_EMDB_LINES_IN_FORMAT;
  244. print ("#define MAX_EMDB_LINES $MAX_EMDB_LINES\n\n");
  245. }
  246. print("#define MAX_NUM_OF_EXT $MAX_EXTENSION\n\n");
  247. ### print square enumeration
  248. printf("\n\ntypedef enum {\n");
  249. printf(" EM_SQUARE_FIRST = 0,\n");
  250. for ($i = 0; $i <= $#square_enum; $i++)
  251. {
  252. if ($i == 0)
  253. {
  254. printf(" EM_SQUARE_$square_enum[0] = EM_SQUARE_FIRST,\n");
  255. }
  256. else
  257. {
  258. printf(" EM_SQUARE_$square_enum[$i],\n");
  259. }
  260. }
  261. printf(" EM_SQUARE_LAST\n");
  262. print("} Square_t;\n\n");
  263. print("typedef struct Ext_s\n");
  264. print("{\n");
  265. print(" int pos;\n");
  266. print(" int size;\n");
  267. print("} Ext_t;\n\n");
  268. print("typedef Ext_t Ex_t[MAX_NUM_OF_EXT];\n\n");
  269. #print("typedef struct Format_list_s\n");
  270. #print("{\n");
  271. #print(" int num_of_formats;\n");
  272. #print(" Format_t formats[MAX_FORMATS_IN_SQUARE];\n");
  273. #print("} Format_list_t;\n\n");
  274. print("typedef struct Inst_id_list_s\n");
  275. print("{\n");
  276. print(" int num_of_lines;\n");
  277. print(" Inst_id_t inst_ids[MAX_EMDB_LINES];\n");
  278. print("} Inst_id_list_t;\n\n");
  279. print "extern Ex_t format_extensions\[\];\n";
  280. #print "extern Format_list_t square_formats\[\];\n";
  281. print "extern Inst_id_list_t square_emdb_lines\[\];\n";
  282. #print "extern Inst_id_list_t format_emdb_lines\[\];\n";
  283. print "extern U64 format_extension_masks[];\n";
  284. print "extern int LOG2[];\n\n";
  285. print("#endif /* _BUILDER_INFO_H */\n");
  286. ########################
  287. ### Write builder_info.c
  288. ########################
  289. select(OUT_C);
  290. print ("/***************************************/\n");
  291. print ("/***** BUILDER INFO *****/\n");
  292. print ("/***************************************/\n");
  293. print ("\n\n#include \"builder_info.h\"\n");
  294. ### Print info arrays
  295. ### format_extensions[]
  296. printf("\n\nEx_t format_extensions[] = {\n");
  297. for ($i = 0; $i <= $#format_enum; $i++)
  298. {
  299. printf ("\/\* $format_enum[$i] \*\/ \{$ext{$format_enum[$i]}\}");
  300. print "," unless ($i == $#format_enum);
  301. print "\n";
  302. }
  303. print "};\n";
  304. ### square_formats[]
  305. #printf("\n\nFormat_list_t square_formats[] = {\n");
  306. #for ($i = 0; $i <= $#square_enum; $i++)
  307. #{
  308. # if (defined $square_formats{$square_enum[$i]})
  309. # {
  310. # $formats_line = $square_formats{$square_enum[$i]};
  311. # for ($j = $formats_in_square{$square_enum[$i]};
  312. # $j < $MAX_FORMATS_IN_SQUARE; $j++)
  313. # {
  314. # $formats_line .= "," . "EM_FORMAT_NONE";
  315. # }
  316. # }
  317. # else
  318. # {
  319. # $formats_in_square{$square_enum[$i]} = 0;
  320. # $formats_line = "EM_FORMAT_NONE";
  321. # for ($j = 1; $j < $MAX_FORMATS_IN_SQUARE; $j++)
  322. # {
  323. # $formats_line .= "," . "EM_FORMAT_NONE";
  324. # }
  325. # }
  326. # print "\/\* $square_enum[$i] \*\/ \{$formats_in_square{$square_enum[$i]}, \{$formats_line\}\}";
  327. # print "," unless ($i == $#square_enum);
  328. # print "\n";
  329. #}
  330. #print "};\n";
  331. ### square_emdb_lines[]
  332. printf("\n\nInst_id_list_t square_emdb_lines[] = {\n");
  333. for ($i = 0; $i <= $#square_enum; $i++)
  334. {
  335. if (defined $square_emdb_lines{$square_enum[$i]})
  336. {
  337. $emdb_line = $square_emdb_lines{$square_enum[$i]};
  338. for ($j = $emdb_lines_in_square{$square_enum[$i]};
  339. $j < $MAX_EMDB_LINES; $j++)
  340. {
  341. $emdb_line .= "," . "EM_INST_NONE";
  342. }
  343. }
  344. else
  345. {
  346. $emdb_lines_in_square{$square_enum[$i]} = 0;
  347. $emdb_line = "EM_INST_NONE";
  348. for ($j = 1; $j < $MAX_EMDB_LINES; $j++)
  349. {
  350. $emdb_line .= "," . "EM_INST_NONE";
  351. }
  352. }
  353. print "\/\* $square_enum[$i] \*\/ \{$emdb_lines_in_square{$square_enum[$i]}, \{$emdb_line\}\}";
  354. print "," unless ($i == $#square_enum);
  355. print "\n";
  356. }
  357. print "};\n";
  358. ### format_extension_masks[]
  359. printf("\n\nU64 format_extension_masks[] = {\n");
  360. for ($i = 0; $i <= $#format_enum; $i++)
  361. {
  362. printf ("\/\* $format_enum[$i] \*\/ $mask{$format_enum[$i]}");
  363. print "," unless ($i == $#format_enum);
  364. print "\n";
  365. }
  366. print "};\n";
  367. ### format_emdb_lines[]
  368. #printf("\n\nInst_id_list_t format_emdb_lines[] = {\n");
  369. #for ($i = 0; $i <= $#format_enum; $i++)
  370. #{
  371. # $emdb_line = $format_emdb_lines{$format_enum[$i]};
  372. # if (!defined $emdb_lines_in_format{$format_enum[$i]})
  373. # {
  374. # $emdb_lines_in_format{$format_enum[$i]} = 0;
  375. # $emdb_line = "EM_INST_NONE";
  376. # for ($j = 1; $j < $MAX_EMDB_LINES; $j++)
  377. # {
  378. # $emdb_line .= "," . "EM_INST_NONE";
  379. # }
  380. # }
  381. # else
  382. # {
  383. # for ($j = $emdb_lines_in_format{$format_enum[$i]};
  384. # $j < $MAX_EMDB_LINES; $j++)
  385. # {
  386. # $emdb_line .= "," . "EM_INST_NONE";
  387. # }
  388. # }
  389. # print "\/\* $format_enum[$i] \*\/ \{$emdb_lines_in_format{$format_enum[$i]}, \{$emdb_line\}\}";
  390. # print "," unless ($i == $#format_enum);
  391. # print "\n";
  392. #}
  393. #print "};\n";
  394. ### LOG2[]
  395. printf("\n\nint LOG2[] = {\n");
  396. print " -1,\n"; # LOG2[0] == -1
  397. for ($i = 0; $i <= 10; $i++)
  398. {
  399. print " ";
  400. for ($j = 1; $j <= 2 ** $i; $j++)
  401. {
  402. print $i;
  403. print "," unless ($i == 10 && $j == 2 ** $i);
  404. }
  405. print "\n";
  406. }
  407. print "};\n";