cpupi.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. This unit contains the CPU specific part of tprocinfo
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. { This unit contains the CPU specific part of tprocinfo. }
  19. unit cpupi;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. cutils,
  24. procinfo,cpuinfo,psub;
  25. type
  26. tarmprocinfo = class(tcgprocinfo)
  27. floatregstart : aword;
  28. constructor create(aparent:tprocinfo);override;
  29. // procedure handle_body_start;override;
  30. // procedure after_pass1;override;
  31. procedure set_first_temp_offset;override;
  32. procedure allocate_push_parasize(size: longint);override;
  33. function calc_stackframe_size:longint;override;
  34. end;
  35. implementation
  36. uses
  37. globtype,globals,systems,
  38. cpubase,
  39. aasmtai,
  40. tgobj,
  41. symconst,symsym,paramgr,
  42. cgbase,
  43. cgobj;
  44. constructor tarmprocinfo.create(aparent:tprocinfo);
  45. begin
  46. inherited create(aparent);
  47. maxpushedparasize:=0;
  48. end;
  49. (*
  50. procedure tarmprocinfo.handle_body_start;
  51. var
  52. ofs : aword;
  53. begin
  54. if not(po_assembler in procdef.procoptions) then
  55. begin
  56. {!!!!!!!!
  57. case target_info.abi of
  58. abi_powerpc_aix:
  59. ofs:=align(maxpushedparasize+LinkageAreaSizeAIX,16);
  60. abi_powerpc_sysv:
  61. ofs:=align(maxpushedparasize+LinkageAreaSizeSYSV,16);
  62. end;
  63. }
  64. inc(procdef.parast.address_fixup,ofs);
  65. procdef.localst.address_fixup:=procdef.parast.address_fixup+procdef.parast.datasize;
  66. end;
  67. inherited handle_body_start;
  68. end;
  69. procedure tarmprocinfo.after_pass1;
  70. begin
  71. if not(po_assembler in procdef.procoptions) then
  72. begin
  73. if cs_asm_source in aktglobalswitches then
  74. aktproccode.insert(Tai_comment.Create(strpnew('Parameter copies start at: r1+'+tostr(procdef.parast.address_fixup))));
  75. if cs_asm_source in aktglobalswitches then
  76. aktproccode.insert(Tai_comment.Create(strpnew('Locals start at: r1+'+tostr(procdef.localst.address_fixup))));
  77. firsttemp_offset:=align(procdef.localst.address_fixup+procdef.localst.datasize,16);
  78. if cs_asm_source in aktglobalswitches then
  79. aktproccode.insert(Tai_comment.Create(strpnew('Temp. space start: r1+'+tostr(firsttemp_offset))));
  80. //!!!! tg.setfirsttemp(firsttemp_offset);
  81. tg.firsttemp:=firsttemp_offset;
  82. tg.lasttemp:=firsttemp_offset;
  83. inherited after_pass1;
  84. end;
  85. end;
  86. *)
  87. procedure tarmprocinfo.set_first_temp_offset;
  88. begin
  89. { We allocate enough space to save all registers because we can't determine
  90. the necessary space because the used registers aren't known before
  91. secondpass is run. Even worse, patching
  92. the local offsets after generating the code could cause trouble because
  93. "shifter" constants could change to non-"shifter" constants. This
  94. is especially a problem when taking the address of a local. For now,
  95. this extra memory should hurt less than generating all local contants with offsets
  96. >256 as non shifter constants }
  97. tg.setfirsttemp(-12-28);
  98. end;
  99. procedure tarmprocinfo.allocate_push_parasize(size:longint);
  100. begin
  101. if size>maxpushedparasize then
  102. maxpushedparasize:=size;
  103. end;
  104. function tarmprocinfo.calc_stackframe_size:longint;
  105. var
  106. firstfloatreg,lastfloatreg,
  107. r : byte;
  108. floatsavesize : aword;
  109. begin
  110. maxpushedparasize:=align(maxpushedparasize,max(aktalignment.localalignmin,4));
  111. firstfloatreg:=RS_NO;
  112. { save floating point registers? }
  113. for r:=RS_F0 to RS_F7 do
  114. if r in cg.rg[R_FPUREGISTER].used_in_proc-paramanager.get_volatile_registers_fpu(pocall_stdcall) then
  115. begin
  116. if firstfloatreg=RS_NO then
  117. firstfloatreg:=r;
  118. lastfloatreg:=r;
  119. end;
  120. if firstfloatreg<>RS_NO then
  121. floatsavesize:=(lastfloatreg-firstfloatreg+1)*12
  122. else
  123. floatsavesize:=0;
  124. floatsavesize:=align(floatsavesize,max(aktalignment.localalignmin,4));
  125. result:=Align(tg.direction*tg.lasttemp,max(aktalignment.localalignmin,4))+maxpushedparasize+floatsavesize;
  126. floatregstart:=-result+maxpushedparasize;
  127. end;
  128. begin
  129. cprocinfo:=tarmprocinfo;
  130. end.
  131. {
  132. $Log$
  133. Revision 1.7 2004-03-29 19:19:35 florian
  134. + arm floating point register saving implemented
  135. * hopefully stabs generation for MacOSX fixed
  136. + some defines for arm added
  137. Revision 1.6 2004/03/06 20:35:20 florian
  138. * fixed arm compilation
  139. * cleaned up code generation for exported linux procedures
  140. Revision 1.5 2003/12/03 17:39:05 florian
  141. * fixed several arm calling conventions issues
  142. * fixed reference reading in the assembler reader
  143. * fixed a_loadaddr_ref_reg
  144. Revision 1.4 2003/11/30 19:35:29 florian
  145. * fixed several arm related problems
  146. Revision 1.3 2003/11/24 15:17:37 florian
  147. * changed some types to prevend range check errors
  148. Revision 1.2 2003/11/02 14:30:03 florian
  149. * fixed ARM for new reg. allocation scheme
  150. Revision 1.1 2003/08/20 15:50:13 florian
  151. * more arm stuff
  152. }