nppccal.pas 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Implements the PowerPC specific part of call nodes
  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 bymethodpointer
  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 nppccal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,node,ncal,ncgcal;
  22. type
  23. tppccallnode = class(tcgcallnode)
  24. procedure extra_call_code;override;
  25. procedure do_syscall;override;
  26. end;
  27. implementation
  28. uses
  29. globtype,systems,
  30. cutils,verbose,globals,
  31. symconst,symbase,symsym,symtable,defutil,paramgr,parabase,
  32. cgbase,pass_2,
  33. cpuinfo,cpubase,aasmbase,aasmtai,aasmdata,aasmcpu,
  34. nmem,nld,ncnv,
  35. ncgutil,cgutils,cgobj,tgobj,regvars,rgobj,rgcpu,
  36. cg64f32,cgcpu,cpupi,procinfo;
  37. procedure tppccallnode.extra_call_code;
  38. begin
  39. if assigned(varargsparas) then
  40. begin
  41. if (target_info.abi = abi_powerpc_sysv) then
  42. begin
  43. if va_uses_float_reg in varargsparas.varargsinfo then
  44. current_asmdata.CurrAsmList.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  45. else
  46. current_asmdata.CurrAsmList.concat(taicpu.op_const_const_const(A_CRXOR,6,6,6));
  47. end;
  48. end;
  49. end;
  50. procedure tppccallnode.do_syscall;
  51. var
  52. tmpref: treference;
  53. begin
  54. case target_info.system of
  55. system_powerpc_amiga:
  56. begin
  57. // one syscall convention for Amiga/PowerPC
  58. // which is quite standard
  59. extra_call_code;
  60. cg.a_call_name(current_asmdata.CurrAsmList,tprocdef(procdefinition).mangledname);
  61. extra_post_call_code;
  62. end;
  63. system_powerpc_morphos:
  64. begin
  65. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  66. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  67. begin
  68. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  69. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  70. reference_reset(tmpref);
  71. tmpref.symbol:=current_asmdata.RefAsmSymbol(tglobalvarsym(tprocdef(procdefinition).libsym).mangledname);
  72. tmpref.refaddr:=addr_hi;
  73. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LIS,NR_R12,tmpref));
  74. tmpref.base:=NR_R12;
  75. tmpref.refaddr:=addr_lo;
  76. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R12,tmpref));
  77. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber);
  78. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  79. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  80. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  81. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  82. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  83. end
  84. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  85. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  86. begin
  87. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  88. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  89. reference_reset_base(tmpref,NR_R3,-tprocdef(procdefinition).extnumber)
  90. else
  91. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber);
  92. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  93. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  94. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  95. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  96. end
  97. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  98. begin
  99. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  100. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R3);
  101. { store call offset into R3 }
  102. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  103. { prepare LR, and call function }
  104. reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset }
  105. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  106. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTLR,NR_R0));
  107. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BLRL));
  108. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R3);
  109. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  110. end
  111. else
  112. internalerror(2005010403);
  113. end;
  114. else
  115. internalerror(2004042901);
  116. end;
  117. end;
  118. begin
  119. ccallnode:=tppccallnode;
  120. end.