nppccal.pas 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Implements the PowerPC specific part of call nodes
  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 bymethodpointer
  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. unit nppccal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symdef,node,ncal,ncgcal;
  23. type
  24. tppccallnode = class(tcgcallnode)
  25. procedure extra_call_code;override;
  26. procedure do_syscall;override;
  27. end;
  28. implementation
  29. uses
  30. globtype,systems,
  31. cutils,verbose,globals,
  32. symconst,symbase,symsym,symtable,defutil,paramgr,
  33. {$ifdef GDB}
  34. {$ifdef delphi}
  35. sysutils,
  36. {$else}
  37. strings,
  38. {$endif}
  39. gdb,
  40. {$endif GDB}
  41. cgbase,pass_2,
  42. cpuinfo,cpubase,aasmbase,aasmtai,aasmcpu,
  43. nmem,nld,ncnv,
  44. ncgutil,cgutils,cgobj,tgobj,regvars,rgobj,rgcpu,
  45. cg64f32,cgcpu,cpupi,procinfo;
  46. procedure tppccallnode.extra_call_code;
  47. begin
  48. if assigned(varargsparas) then
  49. begin
  50. if va_uses_float_reg in varargsparas.varargsinfo then
  51. exprasmlist.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  52. else
  53. exprasmlist.concat(taicpu.op_const_const_const(A_CRXOR,6,6,6));
  54. end;
  55. end;
  56. procedure tppccallnode.do_syscall;
  57. var
  58. tmpref: treference;
  59. begin
  60. case target_info.system of
  61. system_powerpc_morphos:
  62. begin
  63. cg.a_reg_alloc(exprasmlist,NR_STACK_POINTER_REG);
  64. cg.a_reg_alloc(exprasmlist,NR_R0);
  65. cg.a_reg_alloc(exprasmlist,NR_R3);
  66. { save link register }
  67. exprasmlist.concat(taicpu.op_reg(A_MFLR,NR_R0));
  68. reference_reset_base(tmpref,NR_STACK_POINTER_REG,LA_LR_SYSV);
  69. exprasmlist.concat(taicpu.op_reg_ref(A_STW,NR_R0,tmpref));
  70. { adjust stack ptr }
  71. reference_reset_base(tmpref,NR_STACK_POINTER_REG,-8); { ??? }
  72. exprasmlist.concat(taicpu.op_reg_ref(A_STWU,NR_STACK_POINTER_REG,tmpref));
  73. { store call offset into R3 }
  74. exprasmlist.concat(taicpu.op_reg_const(A_LI,NR_R3,tprocdef(procdefinition).extnumber));
  75. { prepare LR, and call function }
  76. reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset }
  77. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  78. exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0));
  79. exprasmlist.concat(taicpu.op_none(A_BLRL));
  80. { adjust back stack ptr }
  81. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R1,NR_R1,8)); { ??? }
  82. { restore link register }
  83. reference_reset_base(tmpref,NR_STACK_POINTER_REG,LA_LR_SYSV);
  84. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  85. exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0));
  86. cg.a_reg_dealloc(exprasmlist,NR_STACK_POINTER_REG);
  87. cg.a_reg_dealloc(exprasmlist,NR_R0);
  88. cg.a_reg_dealloc(exprasmlist,NR_R3);
  89. end;
  90. else
  91. internalerror(2004042901);
  92. end;
  93. end;
  94. begin
  95. ccallnode:=tppccallnode;
  96. end.
  97. {
  98. $Log$
  99. Revision 1.25 2004-04-29 14:36:42 karoly
  100. * little cleanup of the previous commit
  101. Revision 1.24 2004/04/29 14:01:23 karoly
  102. + first implementation of PowerPC/MorphOS do_syscall
  103. Revision 1.23 2003/12/28 22:09:12 florian
  104. + setting of bit 6 of cr for c var args on ppc implemented
  105. Revision 1.22 2003/10/01 20:34:49 peter
  106. * procinfo unit contains tprocinfo
  107. * cginfo renamed to cgbase
  108. * moved cgmessage to verbose
  109. * fixed ppc and sparc compiles
  110. Revision 1.21 2003/09/03 19:35:24 peter
  111. * powerpc compiles again
  112. Revision 1.20 2003/07/08 21:24:59 peter
  113. * sparc fixes
  114. Revision 1.19 2003/07/06 20:25:03 jonas
  115. * fixed ppc compiler
  116. Revision 1.18 2003/06/13 21:19:32 peter
  117. * current_procdef removed, use current_procinfo.procdef instead
  118. Revision 1.17 2003/06/04 11:58:58 jonas
  119. * calculate localsize also in g_return_from_proc since it's now called
  120. before g_stackframe_entry (still have to fix macos)
  121. * compilation fixes (cycle doesn't work yet though)
  122. Revision 1.16 2003/05/25 14:32:42 jonas
  123. * fixed register numbering bug
  124. Revision 1.15 2003/05/24 11:47:27 jonas
  125. * fixed framepointer storage: it's now always stored at r1+12, which is
  126. a place in the link area reserved for compiler use.
  127. Revision 1.14 2003/05/23 18:51:26 jonas
  128. * fixed support for nested procedures and more parameters than those
  129. which fit in registers (untested/probably not working: calling a
  130. nested procedure from a deeper nested procedure)
  131. Revision 1.13 2003/05/18 15:15:59 florian
  132. + added abi field to tsysteminfo
  133. Revision 1.12 2003/05/16 23:15:51 jonas
  134. * workaround for nested procedures until Peter fixes it properly :)
  135. Revision 1.11 2003/05/16 20:00:39 jonas
  136. * powerpc nested procedure fixes, should work completely now if all
  137. local variables of the parent procedure are declared before the
  138. nested procedures are declared
  139. Revision 1.10 2003/04/27 11:21:36 peter
  140. * aktprocdef renamed to current_procinfo.procdef
  141. * procinfo renamed to current_procinfo
  142. * procinfo will now be stored in current_module so it can be
  143. cleaned up properly
  144. * gen_main_procsym changed to create_main_proc and release_main_proc
  145. to also generate a tprocinfo structure
  146. * fixed unit implicit initfinal
  147. Revision 1.9 2003/04/27 10:41:47 florian
  148. * fixed nested procedures to get them working as before
  149. Revision 1.8 2003/04/27 07:48:05 peter
  150. * updated for removed lexlevel
  151. Revision 1.7 2003/04/24 11:24:00 florian
  152. * fixed several issues with nested procedures
  153. Revision 1.6 2003/04/23 12:35:35 florian
  154. * fixed several issues with powerpc
  155. + applied a patch from Jonas for nested function calls (PowerPC only)
  156. * ...
  157. Revision 1.5 2003/04/04 15:38:56 peter
  158. * moved generic code from n386cal to ncgcal, i386 now also
  159. uses the generic ncgcal
  160. Revision 1.4 2002/12/05 14:28:12 florian
  161. * some variant <-> dyn. array stuff
  162. Revision 1.3 2002/11/25 17:43:28 peter
  163. * splitted defbase in defutil,symutil,defcmp
  164. * merged isconvertable and is_equal into compare_defs(_ext)
  165. * made operator search faster by walking the list only once
  166. Revision 1.2 2002/08/17 09:23:49 florian
  167. * first part of procinfo rewrite
  168. Revision 1.1 2002/08/13 21:40:59 florian
  169. * more fixes for ppc calling conventions
  170. }