2
0

itcpugas.pas 5.0 KB

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