cpupi.pas 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. cutils,globtype,
  23. cpubase,
  24. cgbase,aasmdata,
  25. procinfo,cpuinfo,psub;
  26. type
  27. txtensaprocinfo = class(tcgprocinfo)
  28. callins,callxins : TAsmOp;
  29. stackframesize,
  30. stackpaddingreg: TSuperRegister;
  31. needs_frame_pointer: boolean;
  32. { highest N used in a call instruction }
  33. maxcall : Byte;
  34. // procedure handle_body_start;override;
  35. // procedure after_pass1;override;
  36. constructor create(aparent: tprocinfo); override;
  37. procedure set_first_temp_offset;override;
  38. function calc_stackframe_size:longint;override;
  39. procedure init_framepointer;override;
  40. end;
  41. implementation
  42. uses
  43. globals,systems,
  44. tgobj,
  45. symconst,symtype,symsym,symcpu,paramgr,
  46. cgutils,
  47. cgobj,
  48. defutil,
  49. aasmcpu;
  50. constructor txtensaprocinfo.create(aparent: tprocinfo);
  51. begin
  52. inherited create(aparent);
  53. maxpushedparasize:=0;
  54. if target_info.abi=abi_xtensa_windowed then
  55. begin
  56. callins:=A_CALL8;
  57. callxins:=A_CALLX8;
  58. { set properly }
  59. maxcall:=8;
  60. { we do not use a frame pointer for the windowed abi }
  61. include(flags,pi_estimatestacksize);
  62. framepointer:=NR_STACK_POINTER_REG;
  63. end
  64. else
  65. begin
  66. callins:=A_CALL0;
  67. callxins:=A_CALLX0;
  68. maxcall:=0;
  69. framepointer:=NR_FRAME_POINTER_REG;
  70. end;
  71. end;
  72. procedure txtensaprocinfo.set_first_temp_offset;
  73. var
  74. localsize : aint;
  75. i : longint;
  76. begin
  77. maxpushedparasize:=Align(maxpushedparasize,4);
  78. tg.setfirsttemp(maxpushedparasize);
  79. if po_nostackframe in procdef.procoptions then
  80. exit;
  81. { estimate stack frame size }
  82. if pi_estimatestacksize in flags then
  83. begin
  84. stackframesize:=maxpushedparasize;
  85. localsize:=0;
  86. for i:=0 to procdef.localst.SymList.Count-1 do
  87. if tsym(procdef.localst.SymList[i]).typ=localvarsym then
  88. inc(localsize,tabstractnormalvarsym(procdef.localst.SymList[i]).getsize);
  89. inc(stackframesize,localsize);
  90. localsize:=0;
  91. for i:=0 to procdef.parast.SymList.Count-1 do
  92. if tsym(procdef.parast.SymList[i]).typ=paravarsym then
  93. begin
  94. if tabstractnormalvarsym(procdef.parast.SymList[i]).varspez in [vs_var,vs_out,vs_constref] then
  95. inc(localsize,4)
  96. else if is_open_string(tabstractnormalvarsym(procdef.parast.SymList[i]).vardef) then
  97. inc(localsize,256)
  98. else
  99. inc(localsize,tabstractnormalvarsym(procdef.parast.SymList[i]).getsize);
  100. end;
  101. inc(stackframesize,localsize);
  102. if pi_needs_implicit_finally in flags then
  103. inc(stackframesize,40);
  104. if pi_uses_exceptions in flags then
  105. inc(stackframesize,40);
  106. if procdef.proctypeoption in [potype_constructor] then
  107. inc(stackframesize,40*2);
  108. inc(stackframesize,estimatedtempsize);
  109. stackframesize:=Align(stackframesize,target_info.alignment.localalignmax);
  110. end;
  111. end;
  112. function txtensaprocinfo.calc_stackframe_size:longint;
  113. var
  114. r : byte;
  115. regs: tcpuregisterset;
  116. begin
  117. if pi_estimatestacksize in flags then
  118. result:=stackframesize
  119. else
  120. begin
  121. maxpushedparasize:=align(maxpushedparasize,max(current_settings.alignment.localalignmin,4));
  122. result:=Align(tg.direction*tg.lasttemp,max(current_settings.alignment.localalignmin,4))+maxpushedparasize;
  123. end;
  124. end;
  125. procedure txtensaprocinfo.init_framepointer;
  126. begin
  127. if target_info.abi=abi_xtensa_call0 then
  128. begin
  129. RS_FRAME_POINTER_REG:=RS_A15;
  130. NR_FRAME_POINTER_REG:=NR_A15;
  131. end
  132. else
  133. begin
  134. RS_FRAME_POINTER_REG:=RS_A7;
  135. NR_FRAME_POINTER_REG:=NR_A7;
  136. end;
  137. end;
  138. begin
  139. cprocinfo:=txtensaprocinfo;
  140. end.