nppccal.pas 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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,parabase,
  33. {$ifdef GDB}
  34. strings,
  35. gdb,
  36. {$endif GDB}
  37. cgbase,pass_2,
  38. cpuinfo,cpubase,aasmbase,aasmtai,aasmcpu,
  39. nmem,nld,ncnv,
  40. ncgutil,cgutils,cgobj,tgobj,regvars,rgobj,rgcpu,
  41. cg64f32,cgcpu,cpupi,procinfo;
  42. procedure tppccallnode.extra_call_code;
  43. begin
  44. if assigned(varargsparas) then
  45. begin
  46. if (target_info.abi = abi_powerpc_sysv) then
  47. begin
  48. if va_uses_float_reg in varargsparas.varargsinfo then
  49. exprasmlist.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  50. else
  51. exprasmlist.concat(taicpu.op_const_const_const(A_CRXOR,6,6,6));
  52. end;
  53. end;
  54. end;
  55. procedure tppccallnode.do_syscall;
  56. var
  57. tmpref: treference;
  58. begin
  59. case target_info.system of
  60. system_powerpc_morphos:
  61. begin
  62. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  63. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  64. begin
  65. cg.getcpuregister(exprasmlist,NR_R0);
  66. cg.getcpuregister(exprasmlist,NR_R31);
  67. reference_reset(tmpref);
  68. tmpref.symbol:=objectlibrary.newasmsymbol(tglobalvarsym(tprocdef(procdefinition).libsym).mangledname,AB_EXTERNAL,AT_DATA);
  69. tmpref.refaddr:=addr_hi;
  70. exprasmlist.concat(taicpu.op_reg_ref(A_LIS,NR_R31,tmpref));
  71. tmpref.base:=NR_R31;
  72. tmpref.refaddr:=addr_lo;
  73. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R31,tmpref));
  74. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R31,-tprocdef(procdefinition).extnumber));
  75. reference_reset_base(tmpref,NR_R31,0);
  76. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  77. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  78. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  79. cg.ungetcpuregister(exprasmlist,NR_R31);
  80. cg.ungetcpuregister(exprasmlist,NR_R0);
  81. end
  82. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  83. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  84. begin
  85. cg.getcpuregister(exprasmlist,NR_R0);
  86. cg.getcpuregister(exprasmlist,NR_R31);
  87. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  88. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R3,-tprocdef(procdefinition).extnumber))
  89. else
  90. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R12,-tprocdef(procdefinition).extnumber));
  91. reference_reset_base(tmpref,NR_R31,0);
  92. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  93. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  94. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  95. cg.ungetcpuregister(exprasmlist,NR_R31);
  96. cg.ungetcpuregister(exprasmlist,NR_R0);
  97. end
  98. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  99. begin
  100. cg.getcpuregister(exprasmlist,NR_R0);
  101. cg.getcpuregister(exprasmlist,NR_R3);
  102. { store call offset into R3 }
  103. exprasmlist.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  104. { prepare LR, and call function }
  105. reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset }
  106. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  107. exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0));
  108. exprasmlist.concat(taicpu.op_none(A_BLRL));
  109. cg.ungetcpuregister(exprasmlist,NR_R0);
  110. cg.ungetcpuregister(exprasmlist,NR_R3);
  111. end
  112. else
  113. internalerror(2005010403);
  114. end;
  115. else
  116. internalerror(2004042901);
  117. end;
  118. end;
  119. begin
  120. ccallnode:=tppccallnode;
  121. end.
  122. {
  123. $Log$
  124. Revision 1.34 2005-01-06 02:13:03 karoly
  125. * more SysV call support stuff for MorphOS
  126. Revision 1.33 2005/01/05 02:31:06 karoly
  127. * fixed SysV syscall support (MorphOS)
  128. Revision 1.32 2005/01/04 17:40:33 karoly
  129. + sysv style syscalls added for MorphOS
  130. Revision 1.31 2004/12/06 18:06:37 jonas
  131. * only set/clear bit 6 of cr in case of varargs for the sysv abi
  132. Revision 1.30 2004/10/15 09:30:13 mazen
  133. - remove $IFDEF DELPHI and related code
  134. - remove $IFDEF FPCPROCVAR and related code
  135. Revision 1.29 2004/09/25 14:23:54 peter
  136. * ungetregister is now only used for cpuregisters, renamed to
  137. ungetcpuregister
  138. * renamed (get|unget)explicitregister(s) to ..cpuregister
  139. * removed location-release/reference_release
  140. Revision 1.28 2004/09/21 17:25:13 peter
  141. * paraloc branch merged
  142. Revision 1.27.4.1 2004/09/18 20:21:08 jonas
  143. * fixed ppc, but still needs fix in tgobj
  144. Revision 1.27 2004/06/20 08:55:32 florian
  145. * logs truncated
  146. Revision 1.26 2004/04/29 22:18:37 karoly
  147. * removed some unneeded parts of do_syscall
  148. Revision 1.25 2004/04/29 14:36:42 karoly
  149. * little cleanup of the previous commit
  150. Revision 1.24 2004/04/29 14:01:23 karoly
  151. + first implementation of PowerPC/MorphOS do_syscall
  152. }