cpupi.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. This unit contains the CPU specific part of tprocinfo
  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. { This unit contains the CPU specific part of tprocinfo. }
  18. unit cpupi;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. psub,procinfo,aasmdata;
  23. type
  24. tcpuprocinfo = class(tcgprocinfo)
  25. private
  26. procedure insert_8087_fwaits(list : TAsmList);
  27. public
  28. constructor create(aparent:tprocinfo);override;
  29. procedure set_first_temp_offset;override;
  30. function calc_stackframe_size:longint;override;
  31. procedure generate_parameter_info;override;
  32. procedure postprocess_code;override;
  33. end;
  34. implementation
  35. uses
  36. cutils,
  37. systems,globals,globtype,
  38. aasmtai,aasmcpu,
  39. cgobj,tgobj,paramgr,
  40. cpubase,cpuinfo,
  41. cgutils,
  42. symconst;
  43. constructor tcpuprocinfo.create(aparent:tprocinfo);
  44. begin
  45. inherited create(aparent);
  46. got:=NR_EBX;
  47. end;
  48. procedure tcpuprocinfo.set_first_temp_offset;
  49. begin
  50. if paramanager.use_fixed_stack then
  51. begin
  52. if not(po_assembler in procdef.procoptions) and
  53. (tg.direction > 0) then
  54. tg.setfirsttemp(tg.direction*maxpushedparasize);
  55. if (tg.direction < 0) and
  56. not(po_nostackframe in procdef.procoptions) then
  57. { compensate for the return address and the "pushl %ebp" }
  58. tg.setalignmentmismatch(sizeof(pint)*2);
  59. end;
  60. end;
  61. function tcpuprocinfo.calc_stackframe_size:longint;
  62. begin
  63. { ???:
  64. align to 4 bytes at least
  65. otherwise all those subl $2,%esp are meaningless PM }
  66. if target_info.stackalign<=2 then
  67. result:=Align(tg.direction*tg.lasttemp,min(current_settings.alignment.localalignmax,2))
  68. else
  69. { aligned during stack frame allocation, because also depends number
  70. of saved registers }
  71. result:=tg.direction*tg.lasttemp+maxpushedparasize;
  72. end;
  73. procedure tcpuprocinfo.generate_parameter_info;
  74. begin
  75. inherited generate_parameter_info;
  76. { Para_stack_size is only used to determine how many bytes to remove }
  77. { from the stack at the end of the procedure (in the "ret $xx"). }
  78. { If the stack is fixed, nothing has to be removed by the callee }
  79. if paramanager.use_fixed_stack then
  80. para_stack_size := 0;
  81. end;
  82. procedure tcpuprocinfo.insert_8087_fwaits(list : TAsmList);
  83. var
  84. curtai: tai;
  85. begin
  86. curtai:=tai(list.First);
  87. while assigned(curtai) do
  88. begin
  89. if (curtai.typ=ait_instruction)
  90. and requires_fwait_on_8087(taicpu(curtai).opcode) then
  91. list.InsertBefore(taicpu.op_none(A_FWAIT),curtai);
  92. curtai:=tai(curtai.Next);
  93. end;
  94. end;
  95. procedure tcpuprocinfo.postprocess_code;
  96. begin
  97. { nickysn note: I don't know if the 187 requires FWAIT before
  98. every instruction like the 8087, so I'm including it just in case }
  99. if current_settings.cputype<=cpu_186 then
  100. insert_8087_fwaits(aktproccode);
  101. end;
  102. begin
  103. cprocinfo:=tcpuprocinfo;
  104. end.