2
0

nppccal.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 very similar to basesysv on MorphOS
  59. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  60. reference_reset_base(tmpref,NR_R3,tprocdef(procdefinition).extnumber);
  61. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  62. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  63. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  64. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  65. end;
  66. system_powerpc_morphos:
  67. begin
  68. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  69. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  70. begin
  71. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  72. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  73. reference_reset(tmpref);
  74. tmpref.symbol:=current_asmdata.RefAsmSymbol(tstaticvarsym(tprocdef(procdefinition).libsym).mangledname);
  75. tmpref.refaddr:=addr_hi;
  76. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LIS,NR_R12,tmpref));
  77. tmpref.base:=NR_R12;
  78. tmpref.refaddr:=addr_lo;
  79. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R12,tmpref));
  80. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber);
  81. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  82. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  83. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  84. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  85. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  86. end
  87. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  88. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  89. begin
  90. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  91. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  92. reference_reset_base(tmpref,NR_R3,-tprocdef(procdefinition).extnumber)
  93. else
  94. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber);
  95. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  96. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  97. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  98. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  99. end
  100. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  101. begin
  102. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  103. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R3);
  104. { store call offset into R3 }
  105. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  106. { prepare LR, and call function }
  107. reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset }
  108. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  109. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTLR,NR_R0));
  110. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BLRL));
  111. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R3);
  112. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  113. end
  114. else
  115. internalerror(2005010403);
  116. end;
  117. else
  118. internalerror(2004042901);
  119. end;
  120. end;
  121. begin
  122. ccallnode:=tppccallnode;
  123. end.