tcg1.pp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. { %CPU=i386 }
  2. {$R-}
  3. program test_register_pushing;
  4. var
  5. before, after : longint;
  6. wpush,lpush : longint;
  7. const
  8. haserror : boolean = false;
  9. begin
  10. {$ifdef CPUI386}
  11. {$asmmode att}
  12. asm
  13. {$ifndef FPC_PIC}
  14. movl %esp,before
  15. pushw %es
  16. movl %esp,after
  17. popw %es
  18. {$else not FPC_PIC}
  19. call .LPIC
  20. .LPIC:
  21. popl %ecx
  22. {$ifdef darwin}
  23. movl %esp,before-.LPIC(%ecx)
  24. pushw %es
  25. movl %esp,after-.LPIC(%ecx)
  26. popw %es
  27. {$else darwin}
  28. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  29. movl %esp,before@GOT(%ecx)
  30. pushw %es
  31. movl %esp,after@GOT(%ecx)
  32. popw %es
  33. {$endif darwin}
  34. {$endif not FPC_PIC}
  35. end;
  36. wpush:=before-after;
  37. if wpush<>2 then
  38. begin
  39. Writeln('Compiler does not push "pushw %es" into 2 bytes');
  40. haserror:=true;
  41. end;
  42. asm
  43. {$ifndef FPC_PIC}
  44. movl %esp,before
  45. pushl %es
  46. movl %esp,after
  47. popl %es
  48. {$else not FPC_PIC}
  49. call .LPIC
  50. .LPIC:
  51. popl %ecx
  52. {$ifdef darwin}
  53. movl %esp,before-.LPIC(%ecx)
  54. pushl %es
  55. movl %esp,after-.LPIC(%ecx)
  56. popl %es
  57. {$else darwin}
  58. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  59. movl %esp,before@GOT(%ecx)
  60. pushl %es
  61. movl %esp,after@GOT(%ecx)
  62. popl %es
  63. {$endif darwin}
  64. {$endif not FPC_PIC}
  65. end;
  66. lpush:=before-after;
  67. if lpush<>4 then
  68. begin
  69. Writeln('Compiler does not push "pushl %es" into 4 bytes');
  70. haserror:=true;
  71. end;
  72. asm
  73. {$ifndef FPC_PIC}
  74. movl %esp,before
  75. pushw %gs
  76. movl %esp,after
  77. popw %gs
  78. {$else not FPC_PIC}
  79. call .LPIC
  80. .LPIC:
  81. popl %ecx
  82. {$ifdef darwin}
  83. movl %esp,before-.LPIC(%ecx)
  84. pushw %gs
  85. movl %esp,after-.LPIC(%ecx)
  86. popw %gs
  87. {$else darwin}
  88. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  89. movl %esp,before@GOT(%ecx)
  90. pushw %gs
  91. movl %esp,after@GOT(%ecx)
  92. popw %gs
  93. {$endif darwin}
  94. {$endif not FPC_PIC}
  95. end;
  96. wpush:=before-after;
  97. if wpush<>2 then
  98. begin
  99. Writeln('Compiler does not push "pushw %gs" into 2 bytes');
  100. haserror:=true;
  101. end;
  102. asm
  103. {$ifndef FPC_PIC}
  104. movl %esp,before
  105. pushl %gs
  106. movl %esp,after
  107. popl %gs
  108. {$else not FPC_PIC}
  109. call .LPIC
  110. .LPIC:
  111. popl %ecx
  112. {$ifdef darwin}
  113. movl %esp,before-.LPIC(%ecx)
  114. pushl %gs
  115. movl %esp,after-.LPIC(%ecx)
  116. popl %gs
  117. {$else darwin}
  118. addl $_GLOBAL_OFFSET_TABLE_,%ecx
  119. movl %esp,before@GOT(%ecx)
  120. pushl %gs
  121. movl %esp,after@GOT(%ecx)
  122. popl %gs
  123. {$endif darwin}
  124. {$endif not FPC_PIC}
  125. end;
  126. lpush:=before-after;
  127. if lpush<>4 then
  128. begin
  129. Writeln('Compiler does not push "pushl %gs" into 4 bytes');
  130. haserror:=true;
  131. end;
  132. {$asmmode intel}
  133. asm
  134. {$ifndef FPC_PIC}
  135. mov before,esp
  136. push es
  137. mov after,esp
  138. pop es
  139. {$else not FPC_PIC}
  140. call @@LPIC
  141. @@LPIC:
  142. pop ecx
  143. {$ifdef darwin}
  144. mov [before-@@LPIC+ecx],esp
  145. push es
  146. mov [after-@@LPIC+ecx],esp
  147. pop es
  148. {$else darwin}
  149. add ecx,@_GLOBAL_OFFSET_TABLE_
  150. mov [ecx].OFFSET before,esp
  151. push es
  152. mov [ecx].OFFSET after,esp
  153. pop es
  154. {$endif darwin}
  155. {$endif not FPC_PIC}
  156. end;
  157. Writeln('Intel "push es" uses ',before-after,' bytes');
  158. {$endif CPUI386}
  159. if haserror then
  160. Halt(1);
  161. end.