cpupi.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {
  2. Copyright (c) 2002-2009 by Florian Klaempfl and David Zhang
  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. unit cpupi;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,
  22. globtype,symdef,
  23. procinfo,cpuinfo,cpupara,
  24. psub;
  25. type
  26. { TMIPSProcInfo }
  27. TMIPSProcInfo=class(tcgprocinfo)
  28. intregstart,
  29. floatregstart : aint;
  30. intregssave,
  31. floatregssave : byte;
  32. needs_frame_pointer: boolean;
  33. register_used : tparasupregsused;
  34. register_size : tparasupregsize;
  35. register_name : tparasuprename;
  36. register_offset : tparasupregsoffset;
  37. computed_local_size : longint;
  38. //intparareg,
  39. //parasize : longint;
  40. constructor create(aparent:tprocinfo);override;
  41. function calc_stackframe_size:longint;override;
  42. procedure set_first_temp_offset;override;
  43. end;
  44. { Used by Stabs debug info generator }
  45. function mips_extra_offset(procdef : tprocdef) : longint;
  46. implementation
  47. uses
  48. systems,globals,verbose,
  49. cpubase,cgbase,cgutils,cgobj,
  50. tgobj,paramgr,symconst;
  51. constructor TMIPSProcInfo.create(aparent: tprocinfo);
  52. var
  53. i : longint;
  54. begin
  55. inherited create(aparent);
  56. for i:=low(tparasupregs) to high(tparasupregs) do
  57. begin
  58. register_used[i]:=false;
  59. register_size[i]:=OS_NO;
  60. register_name[i]:='invalid';
  61. register_offset[i]:=-1;
  62. end;
  63. floatregssave:=12; { f20-f31 }
  64. intregssave:=12; { r16-r23,r28-r31 }
  65. { for testing }
  66. needs_frame_pointer := true;//false;
  67. computed_local_size:=-1;
  68. { pi_needs_got is not yet set correctly
  69. so include it always if creating PIC code }
  70. if (cs_create_pic in current_settings.moduleswitches) then
  71. begin
  72. include(flags, pi_needs_got);
  73. got:=NR_GP;
  74. end
  75. else
  76. got:=NR_NO;
  77. end;
  78. procedure TMIPSProcInfo.set_first_temp_offset;
  79. begin
  80. { We allocate enough space to save all registers because we can't determine
  81. the necessary space because the used registers aren't known before
  82. secondpass is run. }
  83. if tg.direction = -1 then
  84. tg.setfirsttemp(0)
  85. else
  86. begin
  87. if not (po_nostackframe in procdef.procoptions) then
  88. tg.setfirsttemp(Align(maxpushedparasize+
  89. floatregssave*sizeof(aint)+intregssave*sizeof(aint)
  90. ,max(current_settings.alignment.localalignmin,8)))
  91. else
  92. tg.setfirsttemp(align(maxpushedparasize,max(current_settings.alignment.localalignmin,8)));
  93. end;
  94. end;
  95. function TMIPSProcInfo.calc_stackframe_size:longint;
  96. var
  97. r : byte;
  98. regs: tcpuregisterset;
  99. begin
  100. result:=maxpushedparasize;
  101. floatregstart:=result;
  102. inc(result,floatregssave*4);
  103. intregstart:=result;
  104. //inc(result,intregssave*4);
  105. result:=Align(tg.lasttemp,max(current_settings.alignment.localalignmin,8));
  106. if computed_local_size=-1 then
  107. begin
  108. computed_local_size:=result;
  109. procdef.total_local_size:=result;
  110. end
  111. else if computed_local_size <> result then
  112. Comment(V_Error,'TMIPSProcInfo.calc_stackframe_size result changed');
  113. end;
  114. function mips_extra_offset(procdef : tprocdef) : longint;
  115. begin
  116. if procdef=nil then
  117. mips_extra_offset:=0
  118. else
  119. mips_extra_offset:=procdef.total_local_size;
  120. end;
  121. begin
  122. cprocinfo:=TMIPSProcInfo;
  123. end.