itcpugas.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit contains the i386 AT&T instruction tables
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit itcpugas;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cgbase,cpubase;
  22. type
  23. TAttSuffix = (AttSufNONE,AttSufINT,AttSufFPU,AttSufFPUint,AttSufINTdual,AttSufMM);
  24. const
  25. {$ifdef x86_64}
  26. {x86att.inc contains the name for each x86-64 mnemonic}
  27. gas_op2str:op2strtable={$i x8664att.inc}
  28. gas_needsuffix:array[tasmop] of TAttSuffix={$i x8664ats.inc}
  29. {$else x86_64}
  30. {x86att.inc contains the name for each i386 mnemonic}
  31. gas_op2str:op2strtable={$i i386att.inc}
  32. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  33. {$endif x86_64}
  34. {$ifdef x86_64}
  35. gas_opsize2str : array[topsize] of string[2] = ('',
  36. 'b','w','l','q','bw','bl','wl','bq','wq','lq',
  37. 's','l','q',
  38. 's','l','t','v','x',
  39. 'd',
  40. '','','',
  41. 't',
  42. 'x',
  43. 'y'
  44. );
  45. { suffix-to-opsize conversion tables, used in asmreadrer }
  46. { !! S_LQ excluded: movzlq does not exist, movslq is processed
  47. as a separate instruction w/o suffix (aka movsxd), and there are
  48. no more instructions needing it. }
  49. att_sizesuffixstr : array[0..13] of string[2] = (
  50. '','BW','BL','WL','BQ','WQ',{'LQ',}'B','W','L','S','Q','T','X','Y'
  51. );
  52. att_sizesuffix : array[0..13] of topsize = (
  53. S_NO,S_BW,S_BL,S_WL,S_BQ,S_WQ,{S_LQ,}S_B,S_W,S_L,S_NO,S_Q,S_NO,S_XMM,S_YMM
  54. );
  55. att_sizefpusuffix : array[0..13] of topsize = (
  56. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,{S_NO,}S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO
  57. );
  58. att_sizefpuintsuffix : array[0..13] of topsize = (
  59. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,{S_NO,}S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO
  60. );
  61. {$else x86_64}
  62. gas_opsize2str : array[topsize] of string[2] = ('',
  63. 'b','w','l','q','bw','bl','wl',
  64. 's','l','q',
  65. 's','l','t','v','',
  66. 'd',
  67. '','','',
  68. 't',
  69. 'x',
  70. 'y'
  71. );
  72. { suffix-to-opsize conversion tables, used in asmreadrer }
  73. att_sizesuffixstr : array[0..11] of string[2] = (
  74. '','BW','BL','WL','B','W','L','S','Q','T','X','Y'
  75. );
  76. att_sizesuffix : array[0..11] of topsize = (
  77. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_NO,S_NO,S_NO,S_XMM,S_YMM
  78. );
  79. att_sizefpusuffix : array[0..11] of topsize = (
  80. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO
  81. );
  82. att_sizefpuintsuffix : array[0..11] of topsize = (
  83. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO
  84. );
  85. {$endif x86_64}
  86. function gas_regnum_search(const s:string):Tregister;
  87. function gas_regname(r:Tregister):string;
  88. implementation
  89. uses
  90. cutils,verbose;
  91. const
  92. {$ifdef x86_64}
  93. att_regname_table : array[tregisterindex] of string[7] = (
  94. {r8664att.inc contains the AT&T name of each register.}
  95. {$i r8664att.inc}
  96. );
  97. att_regname_index : array[tregisterindex] of tregisterindex = (
  98. {r8664ari.inc contains an index which sorts att_regname_table by
  99. ATT name.}
  100. {$i r8664ari.inc}
  101. );
  102. {$else x86_64}
  103. att_regname_table : array[tregisterindex] of string[7] = (
  104. {r386att.inc contains the AT&T name of each register.}
  105. {$i r386att.inc}
  106. );
  107. att_regname_index : array[tregisterindex] of tregisterindex = (
  108. {r386ari.inc contains an index which sorts att_regname_table by
  109. ATT name.}
  110. {$i r386ari.inc}
  111. );
  112. {$endif x86_64}
  113. function findreg_by_attname(const s:string):byte;
  114. var
  115. i,p : tregisterindex;
  116. begin
  117. {Binary search.}
  118. p:=0;
  119. i:=regnumber_count_bsstart;
  120. repeat
  121. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  122. p:=p+i;
  123. i:=i shr 1;
  124. until i=0;
  125. if att_regname_table[att_regname_index[p]]=s then
  126. findreg_by_attname:=att_regname_index[p]
  127. else
  128. findreg_by_attname:=0;
  129. end;
  130. function gas_regnum_search(const s:string):Tregister;
  131. begin
  132. result:=regnumber_table[findreg_by_attname(s)];
  133. end;
  134. function gas_regname(r:Tregister):string;
  135. var
  136. p : tregisterindex;
  137. begin
  138. p:=findreg_by_number(r);
  139. if p<>0 then
  140. result:=att_regname_table[p]
  141. else
  142. result:='%'+generic_regname(r);
  143. end;
  144. end.