2
0

n386cal.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i386 assembler for in call nodes
  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 n386cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. { $define AnsiStrRef}
  21. uses
  22. ncgcal;
  23. type
  24. ti386callnode = class(tcgcallnode)
  25. protected
  26. procedure pop_parasize(pop_size:longint);override;
  27. procedure extra_interrupt_code;override;
  28. end;
  29. implementation
  30. uses
  31. globtype,systems,
  32. cutils,verbose,globals,
  33. cgbase,cgutils,
  34. cpubase,paramgr,
  35. aasmtai,aasmdata,aasmcpu,
  36. ncal,nbas,nmem,nld,ncnv,
  37. cga,cgobj,cpuinfo;
  38. {*****************************************************************************
  39. TI386CALLNODE
  40. *****************************************************************************}
  41. procedure ti386callnode.extra_interrupt_code;
  42. begin
  43. if (target_info.system <> system_i386_darwin) then
  44. begin
  45. emit_none(A_PUSHF,S_L);
  46. emit_reg(A_PUSH,S_L,NR_CS);
  47. end;
  48. end;
  49. procedure ti386callnode.pop_parasize(pop_size:longint);
  50. var
  51. hreg : tregister;
  52. begin
  53. if (use_fixed_stack) then
  54. begin
  55. { very weird: in this case the callee does a "ret $4" and the }
  56. { caller immediately a "subl $4,%esp". Possibly this is for }
  57. { use_fixed_stack code to be able to transparently call }
  58. { old-style code (JM) }
  59. dec(pop_size,pushedparasize);
  60. if (pop_size < 0) then
  61. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_SUB,S_L,-pop_size,NR_ESP));
  62. exit;
  63. end;
  64. { on win32, the caller is responsible for removing the funcret }
  65. { pointer from the stack, unlike on Linux. Don't know about }
  66. { elsewhere (except Darwin, handled above), but since the default }
  67. { was "callee removes funcret pointer from stack" until now, we'll }
  68. { keep that default for everyone else (ncgcal decreases popsize by }
  69. { sizeof(aint) in case of ret_in_param()) }
  70. if (target_info.system = system_i386_win32) and
  71. paramanager.ret_in_param(procdefinition.returndef,procdefinition.proccalloption) then
  72. inc(pop_size,sizeof(aint));
  73. { Safecall generates a hidden return value, which is always passed }
  74. { in eax. So there is nothing to remove from the stack. }
  75. if (tf_safecall_exceptions in target_info.flags) and
  76. (procdefinition.proccalloption=pocall_safecall) then
  77. inc(pop_size,sizeof(aint));
  78. { better than an add on all processors }
  79. if pop_size=4 then
  80. begin
  81. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  82. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_POP,S_L,hreg));
  83. end
  84. { the pentium has two pipes and pop reg is pairable }
  85. { but the registers must be different! }
  86. else
  87. if (pop_size=8) and
  88. not(cs_opt_size in current_settings.optimizerswitches) and
  89. (current_settings.optimizecputype=cpu_Pentium) then
  90. begin
  91. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  92. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_POP,S_L,hreg));
  93. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  94. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_POP,S_L,hreg));
  95. end
  96. else
  97. if pop_size<>0 then
  98. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_ADD,S_L,pop_size,NR_ESP));
  99. end;
  100. begin
  101. ccallnode:=ti386callnode;
  102. end.