itcpugas.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. { include mnemonic strings }
  26. {$if defined(x86_64)}
  27. gas_op2str:op2strtable={$i x8664att.inc}
  28. gas_needsuffix:array[tasmop] of TAttSuffix={$i x8664ats.inc}
  29. {$elseif defined(i386)}
  30. gas_op2str:op2strtable={$i i386att.inc}
  31. gas_needsuffix:array[tasmop] of TAttSuffix={$i i386atts.inc}
  32. {$elseif defined(i8086)}
  33. gas_op2str:op2strtable={$i i8086att.inc}
  34. gas_needsuffix:array[tasmop] of TAttSuffix={$i i8086atts.inc}
  35. {$endif}
  36. {$ifdef x86_64}
  37. gas_opsize2str : array[topsize] of string[2] = ('',
  38. 'b','w','l','q','bw','bl','wl','bq','wq','lq',
  39. 's','l','q',
  40. 's','l','t','v','x',
  41. 'd',
  42. '','','',
  43. 't',
  44. 'x',
  45. 'y'
  46. );
  47. { suffix-to-opsize conversion tables, used in asmreadrer }
  48. { !! S_LQ excluded: movzlq does not exist, movslq is processed
  49. as a separate instruction w/o suffix (aka movsxd), and there are
  50. no more instructions needing it. }
  51. att_sizesuffixstr : array[0..13] of string[2] = (
  52. '','BW','BL','WL','BQ','WQ',{'LQ',}'B','W','L','S','Q','T','X','Y'
  53. );
  54. att_sizesuffix : array[0..13] of topsize = (
  55. 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
  56. );
  57. att_sizefpusuffix : array[0..13] of topsize = (
  58. 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
  59. );
  60. att_sizefpuintsuffix : array[0..13] of topsize = (
  61. 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
  62. );
  63. {$else x86_64}
  64. gas_opsize2str : array[topsize] of string[2] = ('',
  65. 'b','w','l','q','bw','bl','wl',
  66. 's','l','q',
  67. 's','l','t','v','',
  68. 'd',
  69. '','','',
  70. 't',
  71. 'x',
  72. 'y'
  73. );
  74. { suffix-to-opsize conversion tables, used in asmreadrer }
  75. att_sizesuffixstr : array[0..11] of string[2] = (
  76. '','BW','BL','WL','B','W','L','S','Q','T','X','Y'
  77. );
  78. att_sizesuffix : array[0..11] of topsize = (
  79. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_NO,S_NO,S_NO,S_XMM,S_YMM
  80. );
  81. att_sizefpusuffix : array[0..11] of topsize = (
  82. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_NO,S_FX,S_NO,S_NO
  83. );
  84. att_sizefpuintsuffix : array[0..11] of topsize = (
  85. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO,S_NO,S_NO
  86. );
  87. {$endif x86_64}
  88. function gas_regnum_search(const s:string):Tregister;
  89. function gas_regname(r:Tregister):string;
  90. implementation
  91. uses
  92. cutils,verbose;
  93. const
  94. {$if defined(x86_64)}
  95. att_regname_table : array[tregisterindex] of string[7] = (
  96. {r8664att.inc contains the AT&T name of each register.}
  97. {$i r8664att.inc}
  98. );
  99. att_regname_index : array[tregisterindex] of tregisterindex = (
  100. {r8664ari.inc contains an index which sorts att_regname_table by
  101. ATT name.}
  102. {$i r8664ari.inc}
  103. );
  104. {$elseif defined(i386)}
  105. att_regname_table : array[tregisterindex] of string[7] = (
  106. {r386att.inc contains the AT&T name of each register.}
  107. {$i r386att.inc}
  108. );
  109. att_regname_index : array[tregisterindex] of tregisterindex = (
  110. {r386ari.inc contains an index which sorts att_regname_table by
  111. ATT name.}
  112. {$i r386ari.inc}
  113. );
  114. {$elseif defined(i8086)}
  115. att_regname_table : array[tregisterindex] of string[7] = (
  116. {r8086att.inc contains the AT&T name of each register.}
  117. {$i r8086att.inc}
  118. );
  119. att_regname_index : array[tregisterindex] of tregisterindex = (
  120. {r8086ari.inc contains an index which sorts att_regname_table by
  121. ATT name.}
  122. {$i r8086ari.inc}
  123. );
  124. {$endif}
  125. function findreg_by_attname(const s:string):byte;
  126. var
  127. i,p : tregisterindex;
  128. begin
  129. {Binary search.}
  130. p:=0;
  131. i:=regnumber_count_bsstart;
  132. repeat
  133. if (p+i<=high(tregisterindex)) and (att_regname_table[att_regname_index[p+i]]<=s) then
  134. p:=p+i;
  135. i:=i shr 1;
  136. until i=0;
  137. if att_regname_table[att_regname_index[p]]=s then
  138. findreg_by_attname:=att_regname_index[p]
  139. else
  140. findreg_by_attname:=0;
  141. end;
  142. function gas_regnum_search(const s:string):Tregister;
  143. begin
  144. result:=regnumber_table[findreg_by_attname(s)];
  145. end;
  146. function gas_regname(r:Tregister):string;
  147. var
  148. p : tregisterindex;
  149. begin
  150. p:=findreg_by_number(r);
  151. if p<>0 then
  152. result:=att_regname_table[p]
  153. else
  154. result:='%'+generic_regname(r);
  155. end;
  156. end.