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.

378 lines
12 KiB

  1. #!/usr/local/bin/perl5
  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. require "EM_perl.h";
  25. require "hard_coded_fields_h.perl";
  26. $GenDir = shift(@ARGV);
  27. $EmdbDir = shift(@ARGV);
  28. ################################################
  29. # CONSTANTS
  30. ################################################
  31. $Inst_id_cln = 0;
  32. $Trole_cln = 10;
  33. $Oper_first_cln = 11;
  34. $Format_cln = 9;
  35. $Flag_cln = 23;
  36. $Dec_flag_cln = 25;
  37. $Cpu_flag = 26;
  38. ################################################
  39. # VARIABLES
  40. ################################################
  41. $func_no=0;
  42. ################################################################
  43. ### build data structures for hard-coded predicates and fields #
  44. ################################################################
  45. &add_hard_coded_fields(\@Hard_coded_predicates_basic, \%Format_hc_pred_inst_pattern, \%format_hc_pred_inst_fields);
  46. &add_hard_coded_fields(\@Hard_coded_predicates_merced, \%Format_hc_pred_inst_pattern, \%format_hc_pred_inst_fields);
  47. &add_hard_coded_fields(\@Hard_coded_fields_basic, \%Format_hc_fld_inst_pattern, \%format_hc_fld_inst_fields);
  48. &add_hard_coded_fields(\@Hard_coded_fields_merced, \%Format_hc_fld_inst_pattern, \%format_hc_fld_inst_fields);
  49. ################################################
  50. # dec_emdb.h->decfn_emdb.h
  51. ################################################
  52. if (open(EMDB_H,"$GenDir/deccpu_emdb.h")!=1)
  53. {
  54. die "\nBuilder error - can't open deccpu_emdb.h\n";
  55. };
  56. if (open(NEW_EMDB_H,">$GenDir/decfn_emdb.h")!=1)
  57. {
  58. die "\nBuilder error - can't open decfn_emdb.h\n";
  59. };
  60. while (<EMDB_H>)
  61. {
  62. if (/format/)
  63. {
  64. print NEW_EMDB_H "\tDecErr *format_function;\n";
  65. }
  66. elsif (!(/Operand_t/ || /template_role/ || /Flags_t/ || /dec_flags/))
  67. {
  68. print NEW_EMDB_H $_;
  69. }
  70. }
  71. close(EMDB_H);
  72. close(NEW_EMDB_H);
  73. ################################################
  74. # read extended EMDB.c
  75. ################################################
  76. if (open(EMDB_C,"$GenDir/deccpu_emdb.c")!=1)
  77. {
  78. die "\nBuilder error - can't open deccpu_emdb.c\n";
  79. };
  80. if (open(NEW_EMDB_C,">$GenDir/decfn_emdb.c")!=1)
  81. {
  82. die "\nBuilder error - can't open decfn_emdb.c\n";
  83. };
  84. if (open(OP_INFO,">$GenDir/dec_frmt.txt")!=1)
  85. {
  86. die "\nBuilder error - can't open dec_frmt.txt\n";
  87. };
  88. &Types_to_strings;
  89. LINE:
  90. while(<EMDB_C>)
  91. {
  92. if (!/{(.*)}/ || /version/)
  93. {
  94. s/deccpu_emdb\.h/decfn_emdb\.h/;
  95. print NEW_EMDB_C $_;
  96. next LINE;
  97. }
  98. else
  99. {
  100. $line = $1;
  101. $line =~ s/\{//g;
  102. $line =~ s/\}//g;
  103. @columns = split(/,/,$line);
  104. $inst_id = $columns[$Inst_id_cln];
  105. $format = $columns[$Format_cln];
  106. $flags = $columns[$Flag_cln];
  107. $is_long = hex($flags) & $EM_FLAG_TWO_SLOT; ### indicates that the instruction is LONG (movl)
  108. $dec_flags = $columns[$Dec_flag_cln];
  109. $flags = sprintf("0x%x",($dec_flags<<$EMDB_MAX_FLAG)|hex($flags));
  110. $func_name = "format_decode_".$format;
  111. $func_name =~ s/EM_FORMAT//;
  112. $cpu_flag = $columns[$Cpu_flag];
  113. $op_types_str = "\{ ";
  114. for($op_no=0; $op_no<$MAX_OPERAND; $op_no++)
  115. {
  116. $op_role[$op_no] = $columns[$Oper_first_cln+$op_no*2];
  117. $op_type[$op_no] = $columns[$Oper_first_cln+$op_no*2+1];
  118. if (!$Str{$op_type[$op_no]} && ($op_type[$op_no] ne EM_OPTYPE_NONE))
  119. {
  120. print "WARNING! ".$op_type[$op_no]." is not covered\n";
  121. }
  122. $func_name .= $Str{$op_type[$op_no]};
  123. if ($is_long && ($op_type[$op_no] eq "EM_OPTYPE_UIMM"))
  124. {
  125. $op_types_str .= $Str{$op_role[$op_no]}.$op_type[$op_no]."64"." ";
  126. }
  127. elsif ($is_long && ($op_type[$op_no] eq "EM_OPTYPE_SSHIFT_REL"))
  128. {
  129. $op_types_str .= $Str{$op_role[$op_no]}.$op_type[$op_no]."64"." ";
  130. }
  131. else
  132. {
  133. $op_types_str .= $Str{$op_role[$op_no]}.$op_type[$op_no]." ";
  134. }
  135. }
  136. $op_types_str .= "\}";
  137. $func_name =~ s/@/_/g;
  138. $func_name .= "_NP" if (!(hex($flags) & $EM_FLAG_PRED)); ### non-predicatable instr
  139. $hc_fields = "";
  140. &find_hard_coded_fields(\$func_name, \%Format_hc_pred_inst_pattern, \%format_hc_pred_inst_fields, "HCPRED", \$hc_fields);
  141. &find_hard_coded_fields(\$func_name, \%Format_hc_fld_inst_pattern, \%format_hc_fld_inst_fields, "HCFLD", \$hc_fields);
  142. $hc_fields_out{$func_name} = $hc_fields;
  143. s/EM_FORMAT_\w+/$func_name/;
  144. ###print only inst_id, extensions, format_function and mem_size
  145. ($out1, $out2, $out3) = $_ =~ /(^\s*{EM_\S+,{\S+},format_decode_\S+,)EM_TROLE_\S+,{\S+},0x\S+,(\d+),\d+(,\S+\},?$)/;
  146. print NEW_EMDB_C "$out1$out2$out3\n";
  147. if (!$all_functions{$func_name})
  148. {
  149. $all_functions{$func_name} = $func_no+1; ### assign numbers starting from 1 (first TRUE value)
  150. $Format_oper_types{$func_name} = $op_types_str;
  151. $Format_Flags{$func_name,0} = $flags;
  152. $Func_array[$func_no] = $func_name;
  153. $func_no++;
  154. $output_str{$func_name} = $format.":".$func_name.":".$op_types_str;
  155. }
  156. else
  157. {
  158. $match=0;
  159. $ntype=0;
  160. while(($Format_Flags{$func_name,$ntype}) && ($match==0))
  161. {
  162. if ($flags eq $Format_Flags{$func_name,$ntype})
  163. {
  164. $match=1;
  165. }
  166. $ntype++;
  167. }
  168. if ($match==0)
  169. {
  170. $Format_Flags{$func_name,$ntype} = $flags;
  171. }
  172. }
  173. }
  174. }
  175. if (open(FUNC_H,">$GenDir/func.h")!=1)
  176. {
  177. die "\nBuilder error - can't open func.h\n";
  178. };
  179. for ($i=0;$i<$func_no;$i++)
  180. {
  181. $func_name = $Func_array[$i];
  182. print OP_INFO $output_str{$func_name}."\{ ";
  183. $ntype=0;
  184. while($Format_Flags{$func_name,$ntype})
  185. {
  186. print OP_INFO $Format_Flags{$func_name,$ntype}." ";
  187. $ntype++;
  188. }
  189. print OP_INFO "\}";
  190. print OP_INFO ":\{".$hc_fields_out{$func_name}." \}\n";
  191. print FUNC_H "extern DecErr ".$func_name.";\n";
  192. }
  193. sub Types_to_strings
  194. {
  195. $Str{EM_OPROLE_NONE} = "NONE@";
  196. $Str{EM_OPROLE_DST} = "DST@";
  197. $Str{EM_OPROLE_SRC} = "SRC@";
  198. $Str{EM_OPTYPE_IREG} = "\@Ir";
  199. $Str{EM_OPTYPE_IREG_NUM} = "\@Irn";
  200. $Str{EM_OPTYPE_IREG_R0_3} = "\@Ir03";
  201. $Str{EM_OPTYPE_IREG_R0} = "\@Ir0";
  202. $Str{EM_OPTYPE_IREG_R1_127} = "\@Ir1_127";
  203. $Str{EM_OPTYPE_FREG} = "\@Fr";
  204. $Str{EM_OPTYPE_FREG_F2_127} = "\@Fr2_127";
  205. $Str{EM_OPTYPE_FREG_NUM} = "\@Frn";
  206. $Str{EM_OPTYPE_BR} = "\@Br";
  207. $Str{EM_OPTYPE_IP} = "\@Ip";
  208. $Str{EM_OPTYPE_PREG} = "\@Pr";
  209. $Str{EM_OPTYPE_APP_REG} = "\@Ar";
  210. $Str{EM_OPTYPE_CR} = "\@Cr";
  211. $Str{EM_OPTYPE_CR_GRP_HIGH} = "\@Crgh";
  212. $Str{EM_OPTYPE_CR_GRP_LOW} = "\@Cglr";
  213. $Str{EM_OPTYPE_SIMM} = "\@Simm";
  214. $Str{EM_OPTYPE_SDEC} = "\@Sdec";
  215. $Str{EM_OPTYPE_UIMM} = "\@Uimm";
  216. $Str{EM_OPTYPE_ONE} = "\@Nc1";
  217. $Str{EM_OPTYPE_EIGHT} = "\@Nc8";
  218. $Str{EM_OPTYPE_SIXTEEN} = "\@Nc16";
  219. $Str{EM_OPTYPE_PREG_INV} = "\@Prinv";
  220. $Str{EM_OPTYPE_MEM} = "\@Mem";
  221. $Str{EM_OPTYPE_BR_NUM} ="\@Brn";
  222. $Str{EM_OPTYPE_BR_VEC} ="\@Brv";
  223. $Str{EM_OPTYPE_FCLASS} = "\@Fcl";
  224. $Str{EM_OPTYPE_SREL} = "\@Srl";
  225. $Str{EM_OPTYPE_SSHIFT_REL} = "\@Sshrl";
  226. $Str{EM_OPTYPE_COUNT_1234} = "\@C14";
  227. $Str{EM_OPTYPE_COUNT_123} = "\@C13";
  228. $Str{EM_OPTYPE_COUNT_PACK} = "\@Cp";
  229. $Str{EM_OPTYPE_CCOUNT} = "\@Cc";
  230. $Str{EM_OPTYPE_PREGS_ALL} = "\@Prall";
  231. $Str{EM_OPTYPE_PREGS_ROT} = "\@Prrot";
  232. $Str{EM_OPTYPE_LEN} = "\@Len";
  233. $Str{EM_OPTYPE_CPOS} = "\@Cpos";
  234. $Str{EM_OPTYPE_APP_REG_GRP_HIGH} = "\@Argh";
  235. $Str{EM_OPTYPE_APP_REG_GRP_LOW} = "\@Argl";
  236. $Str{EM_OPTYPE_MUX1} = "\@Mux1";
  237. $Str{EM_OPTYPE_MUX2} = "\@Mux2";
  238. $Str{EM_OPTYPE_ALLOC_IOL} = "\@Ali";
  239. $Str{EM_OPTYPE_ALLOC_ROT} = "\@Alr";
  240. $Str{EM_OPTYPE_CR_IFS} = "\@Cri";
  241. $Str{EM_OPTYPE_APP_CCV} ="\@Ar";
  242. $Str{EM_OPTYPE_APP_PFS} ="\@Ar";
  243. $Str{EM_OPTYPE_SEMAPHORE_INC} = "\@Sem";
  244. $Str{EM_OPTYPE_PSR_L} = "\@Psrl";
  245. $Str{EM_OPTYPE_PSR_UM} = "\@Psrum";
  246. $Str{EM_OPTYPE_PSR} = "\@Psr";
  247. $Str{EM_OPTYPE_DBR} ="\@Rfdbr";
  248. $Str{EM_OPTYPE_IBR} ="\@Rfibr";
  249. $Str{EM_OPTYPE_PKR} ="\@Rfpkr";
  250. $Str{EM_OPTYPE_PMC} ="\@Rfpmc";
  251. $Str{EM_OPTYPE_PMD} ="\@Rfpmd";
  252. $Str{EM_OPTYPE_DTR} ="\@Rfdtr";
  253. $Str{EM_OPTYPE_ITR} ="\@Rfitr";
  254. $Str{EM_OPTYPE_RR} ="\@Rfrr";
  255. $Str{EM_OPTYPE_MSR} ="\@Rfmsr";
  256. $Str{EM_OPTYPE_CPUID} ="\@Rfcpuid";
  257. $Str{EM_OPTYPE_CR_MINUS_IFS} ="\@Crmi";
  258. $Str{EM_OPTYPE_CMP_UIMM} = "\@CUimm";
  259. $Str{EM_OPTYPE_CMP_UIMM_DEC} = "\@CUimmd";
  260. $Str{EM_OPTYPE_CMP4_UIMM} = "\@C4Uimm";
  261. $Str{EM_OPTYPE_CMP4_UIMM_DEC} = "\@C4Uimmd";
  262. $Str{EM_OPTYPE_UDEC} = "\@Udec";
  263. $Str{EM_OPTYPE_USHIFT_16} = "\@Ush16";
  264. $Str{EM_OPTYPE_SSHIFT_16} = "\@Ssh16";
  265. $Str{EM_OPTYPE_SSHIFT_1} = "\@Ssh1";
  266. $Str{EM_OPTYPE_TAG} = "\@Tag";
  267. }
  268. sub add_hard_coded_fields
  269. {
  270. local ($Hard_coded_fields, $Format_hard_coded_inst_pattern, $Format_hard_coded_inst_fields) = @_;
  271. for ($i=0; $i<=$#$Hard_coded_fields; $i++)
  272. {
  273. $hard_coded_line = $$Hard_coded_fields[$i];
  274. $hard_coded_line =~ s/\s+//g;
  275. ($format, $hc_pattern, $fields) = $hard_coded_line =~ /^(\S+),\/(\S+)\/,\{(.*)\}$/;
  276. @hc_fields = split(/\|/, $fields);
  277. ### find number of format lines already met for this format
  278. for ($frmt_line_no=0; $$Format_hard_coded_inst_pattern{$format,$frmt_line_no}; $frmt_line_no++)
  279. {
  280. }
  281. ### assign instructions pattern for this format line
  282. $$Format_hard_coded_inst_pattern{$format,$frmt_line_no} = $hc_pattern;
  283. ### assign instructions hard-coded fields for this format line
  284. for ($field_no=0; $field_no<=$#hc_fields; $field_no++)
  285. {
  286. $$Format_hard_coded_inst_fields{$format, $frmt_line_no, $field_no} = $hc_fields[$field_no];
  287. }
  288. }
  289. }
  290. sub find_hard_coded_fields
  291. {
  292. local ($func_name, $Format_hard_coded_inst_pattern, $Format_hard_coded_inst_fields, $fld_name, $hc_fields) = @_;
  293. local($format) = $format;
  294. $format =~ s/EM_FORMAT_//;
  295. $found_line = 0;
  296. for ($frmt_line_no=0; $$Format_hard_coded_inst_pattern{$format, $frmt_line_no}; $frmt_line_no++)
  297. {
  298. if ($inst_id =~ /$$Format_hard_coded_inst_pattern{$format,$frmt_line_no}/)
  299. {
  300. die "Error: more then one hard-coded format line correspond to $inst_id\n" if ($found_line);
  301. $found_line = 1;
  302. die "Error: Hard-coded predicate for predicatable instruction $inst_id\n"
  303. if (($fld_name =~ /PRED/) && (hex($flags) & $EM_FLAG_PRED) && ($format !~ /B4/));
  304. $$func_name .= "_".$fld_name;
  305. for ($fld_no=0; $$Format_hard_coded_inst_fields{$format, $frmt_line_no, $fld_no}; $fld_no++)
  306. {
  307. $hc_field = $$Format_hard_coded_inst_fields{$format, $frmt_line_no, $fld_no};
  308. ($pos, $val) = split(/,/, $hc_field);
  309. $pos_out = $pos;
  310. $pos_out =~ s/:/_/;
  311. $$func_name .= "__".$pos_out."_".$val;
  312. $pos_out = $pos;
  313. $pos_out =~ s/:/-/;
  314. $$hc_fields .= " $pos_out,$val";
  315. }
  316. }
  317. }
  318. }