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.

269 lines
7.4 KiB

  1. #!/usr/local/bin/perl5 -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. require "EM_perl.h";
  25. $GenDir = shift(@ARGV);
  26. $EmdbDir = shift(@ARGV);
  27. ################################################
  28. # CONSTANTS
  29. ################################################
  30. #decoder operand flags
  31. $DECODER_OPER_2ND_ROLE_SRC_BIT = 0x00000001; # Oper second role: src
  32. $DECODER_OPER_2ND_ROLE_DST_BIT = 0x00000002; # Oper second role: dest
  33. $DECODER_OPER_NOT_TRUE_SRC_BIT = 0x00000004; # Oper value is ignored
  34. $DECODER_OPER_IMP_ENCODED_BIT = 0x00000008; # Oper is imp encoded
  35. $DECODER_OPER_IMM_IREG_BIT = 0x00000040; # Operand type is IREG_NUM
  36. $DECODER_OPER_IMM_FREG_BIT = 0x00000080; # Operand type is FREG_NUM
  37. #instructin flags
  38. $EM_FLAG_SPECULATION = $EMDB_LAST_FLAG << 1;
  39. $EM_FLAG_POSTINCREMENT = $EMDB_LAST_FLAG << 2;
  40. $EM_FLAG_FALSE_PRED_EXEC = $EMDB_LAST_FLAG << 3;
  41. $EM_BR_HINT_FLAG = $EMDB_LAST_FLAG << 4;
  42. $EM_BR_FLAG = $EMDB_LAST_FLAG << 5;
  43. $EM_ADV_LOAD_FLAG = $EMDB_LAST_FLAG << 6;
  44. $EM_CONTROL_TRANSFER_FLAG = $EMDB_LAST_FLAG << 7;
  45. $dst_op_num = 2;
  46. $src_op_num = 5;
  47. $op_role[$MAX_OPERAND] = "EM_OPROLE_NONE"; #dummy values, since the number of
  48. $op_type[$MAX_OPERAND] = "EM_OPTYPE_NONE"; #decoder operands is greater by 1 than
  49. $op_flags[$MAX_OPERAND] = 0; # the number of emdb operands
  50. ################################################
  51. # open output "C" file
  52. ################################################
  53. if (open(DEC_PRIV_TAB,">$GenDir/dec_static.c")!=1)
  54. {
  55. die "\nBuilder error - can't open dec_static.c\n";
  56. };
  57. ################################################
  58. # read DECODER EMDB information
  59. ################################################
  60. if (open(EMDB_DEC_INFO,"$GenDir/dec1_emdb.c")!=1)
  61. {
  62. die "\nBuilder error - can't open dec1_emdb.c\n";
  63. };
  64. while(<EMDB_DEC_INFO>)
  65. {
  66. if (/^\s*\{\"\S+\"/) #"
  67. {
  68. $work_line = $_;
  69. ($mnemonic,$_2nd_role,$trole,$op[0],$op[1],$op[2],$op[3],$op[4],$op[5],$modifiers,$inst_flags,$specul_flag,$false_pred_flag,$imp_ops, $br_hint_flag, $br_flag, $adv_load_flag, $control_transfer_flag) = $work_line =~ /^\s*{(\S+),(.),(EM_TROLE\S+),{(EM_OPROLE\S+)},{(EM_OPROLE\S+)},{(EM_OPROLE\S+)},{(EM_OPROLE\S+)},{(EM_OPROLE\S+)},{(EM_OPROLE\S+)},{(\S+)},(0x\S+),(.),(.),({\(EM_Decoder_imp_oper_t\)EM_DECODER_IMP_OPERAND.+}),(.),(.),(.),(.)},?$/;
  70. for($i=0; $i<$MAX_OPERAND; $i++)
  71. {
  72. ($op_role[$i],$op_type[$i],$op_flags[$i])=split(/,/,$op[$i],3);
  73. $op_flags[$i] = 0;
  74. }
  75. &Check_src_dst_flag();
  76. &Set_op_flags();
  77. &Set_inst_flags();
  78. &Output_inst_info();
  79. }
  80. else
  81. {
  82. if (/\#include/ || /version/)
  83. {
  84. next;
  85. }
  86. if (/^dec1_EMDB_info_t/)
  87. {
  88. print DEC_PRIV_TAB "#include \"decem.h\"\n";
  89. print DEC_PRIV_TAB "#include \"EM_hints.h\"\n\n\n";
  90. s/^dec1_EMDB_info_t/const EM_Decoder_static_info_t/;
  91. }
  92. s/ EMDB INSTRUCTION / DECODER STATIC /g;
  93. s/dec1_EMDB_/em_decoder_static_/;
  94. print DEC_PRIV_TAB $_;
  95. }
  96. }
  97. close(DEC_PRIV_TAB);
  98. close(EMDB_DEC_INFO);
  99. sub Set_inst_flags
  100. {
  101. $inst_flags = hex($inst_flags);
  102. if ($specul_flag == 1)
  103. {
  104. $inst_flags = $inst_flags | $EM_FLAG_SPECULATION;
  105. }
  106. if ($false_pred_flag == 1)
  107. {
  108. $inst_flags = $inst_flags | $EM_FLAG_FALSE_PRED_EXEC;
  109. }
  110. if ($_2nd_role != 0)
  111. {
  112. $inst_flags = $inst_flags | $EM_FLAG_POSTINCREMENT;
  113. }
  114. if ($br_hint_flag == 1)
  115. {
  116. $inst_flags = $inst_flags | $EM_BR_HINT_FLAG;
  117. }
  118. if ($br_flag == 1)
  119. {
  120. $inst_flags = $inst_flags | $EM_BR_FLAG;
  121. }
  122. if ($adv_load_flag == 1)
  123. {
  124. $inst_flags = $inst_flags | $EM_ADV_LOAD_FLAG;
  125. }
  126. if ($control_transfer_flag == 1)
  127. {
  128. $inst_flags = $inst_flags | $EM_CONTROL_TRANSFER_FLAG;
  129. }
  130. }
  131. sub Set_op_flags
  132. {
  133. for($i=0; $i<$MAX_OPERAND; $i++)
  134. {
  135. if ($op_type[$i] eq "EM_OPTYPE_IREG_NUM")
  136. {
  137. $op_flags[$i] |= $DECODER_OPER_IMM_IREG_BIT;
  138. }
  139. elsif ($op_type[$i] eq "EM_OPTYPE_FREG_NUM")
  140. {
  141. $op_flags[$i] |= $DECODER_OPER_IMM_FREG_BIT;
  142. }
  143. }
  144. }
  145. sub Check_src_dst_flag
  146. {
  147. if ($_2nd_role == 2) ###2nd role - source
  148. {
  149. if ($op_role[0] ne "EM_OPROLE_DST")
  150. {
  151. print "WARNING ! NO destination operand in $mnemonic\n";
  152. }
  153. $op_role[0] .= "_SRC";
  154. $op_flags[0] |= $DECODER_OPER_2ND_ROLE_SRC_BIT;
  155. }
  156. elsif ($_2nd_role == 1) ###2nd role - destination
  157. {
  158. for($i=0; $op_role[$i] ne "EM_OPROLE_SRC" && $i<$MAX_OPERAND; $i++)
  159. {
  160. }
  161. $op_role[$i] .= "_DST"; ###find first source operand
  162. $op_flags[$i] |= $DECODER_OPER_2ND_ROLE_DST_BIT;
  163. if ($i >= $MAX_OPERAND)
  164. {
  165. print "WARNING ! NO source operand in instruction\n";
  166. }
  167. }
  168. }
  169. sub Output_inst_info
  170. {
  171. if ($mnemonic ne "\"ILLEGAL_OP\"")
  172. {
  173. printf DEC_PRIV_TAB ",\n";
  174. }
  175. ###print mnemonic and template role
  176. printf(DEC_PRIV_TAB "{$mnemonic,$trole,{");
  177. ###print dst operands
  178. for($i=0; $i<$dst_op_num && ($op_role[$i] ne "EM_OPROLE_SRC" &&
  179. $op_role[$i] ne "EM_OPROLE_SRC_DST");)
  180. {
  181. printf(DEC_PRIV_TAB "{$op_role[$i],$op_type[$i],$op_flags[$i]}");
  182. if (++$i != $dst_op_num)
  183. {
  184. print DEC_PRIV_TAB ",";
  185. }
  186. }
  187. for($j=$i; $j<$dst_op_num;)
  188. {
  189. printf(DEC_PRIV_TAB "{EM_OPROLE_NONE,EM_OPTYPE_NONE,0}");
  190. if (++$j != $dst_op_num)
  191. {
  192. print DEC_PRIV_TAB ",";
  193. }
  194. }
  195. print DEC_PRIV_TAB "},{";
  196. ###print src operands
  197. for($j=0; $j<$src_op_num; $i++)
  198. {
  199. printf(DEC_PRIV_TAB "{$op_role[$i],$op_type[$i],$op_flags[$i]}");
  200. if (++$j != $src_op_num)
  201. {
  202. print DEC_PRIV_TAB ",";
  203. }
  204. }
  205. print DEC_PRIV_TAB "},";
  206. ###print implicit operands, modifiers and instruction flags
  207. printf(DEC_PRIV_TAB "$imp_ops,{$modifiers},0x%x}\n",$inst_flags);
  208. }