cpupi.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. constructor create(aparent:tprocinfo);override;
  26. procedure set_first_temp_offset;override;
  27. function calc_stackframe_size:longint;override;
  28. procedure generate_parameter_info;override;
  29. procedure allocate_got_register(list: tasmlist);override;
  30. end;
  31. implementation
  32. uses
  33. cutils,
  34. systems,globals,globtype,
  35. cgobj,tgobj,paramgr,
  36. cpubase,
  37. cgutils,
  38. symconst;
  39. constructor tcpuprocinfo.create(aparent:tprocinfo);
  40. begin
  41. inherited create(aparent);
  42. got:=NR_EBX;
  43. end;
  44. procedure tcpuprocinfo.set_first_temp_offset;
  45. begin
  46. if paramanager.use_fixed_stack then
  47. begin
  48. if not(po_assembler in procdef.procoptions) and
  49. (tg.direction > 0) then
  50. tg.setfirsttemp(tg.direction*maxpushedparasize);
  51. if (tg.direction < 0) and
  52. not(po_nostackframe in procdef.procoptions) then
  53. { compensate for the return address and the "pushl %ebp" }
  54. tg.setalignmentmismatch(sizeof(pint)*2);
  55. end;
  56. end;
  57. function tcpuprocinfo.calc_stackframe_size:longint;
  58. begin
  59. { align to 4 bytes at least
  60. otherwise all those subl $2,%esp are meaningless PM }
  61. if target_info.stackalign<=4 then
  62. result:=Align(tg.direction*tg.lasttemp,min(current_settings.alignment.localalignmax,4))
  63. else
  64. { aligned during stack frame allocation, because also depends number
  65. of saved registers }
  66. result:=tg.direction*tg.lasttemp+maxpushedparasize;
  67. end;
  68. procedure tcpuprocinfo.generate_parameter_info;
  69. begin
  70. inherited generate_parameter_info;
  71. { Para_stack_size is only used to determine how many bytes to remove }
  72. { from the stack at the end of the procedure (in the "ret $xx"). }
  73. { If the stack is fixed, nothing has to be removed by the callee }
  74. if paramanager.use_fixed_stack then
  75. para_stack_size := 0;
  76. end;
  77. procedure tcpuprocinfo.allocate_got_register(list: tasmlist);
  78. begin
  79. if (cs_create_pic in current_settings.moduleswitches) then
  80. begin
  81. if (pi_uses_threadvar in flags) and (tf_section_threadvars in target_info.flags) then
  82. begin
  83. { FIXME: It is better to use an imaginary register for GOT and
  84. if EBX is needed for some reason just allocate EBX and
  85. copy GOT into it before its usage. }
  86. cg.getcpuregister(list,NR_EBX);
  87. got := NR_EBX;
  88. end
  89. else
  90. got := cg.getaddressregister(list);
  91. end;
  92. end;
  93. begin
  94. cprocinfo:=tcpuprocinfo;
  95. end.