nppccal.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 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 nppccal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,node,ncal,ncgcal;
  22. type
  23. tppccallnode = class(tcgcallnode)
  24. protected
  25. procedure gen_syscall_para(para: tcallparanode); override;
  26. public
  27. procedure extra_call_code;override;
  28. procedure do_syscall;override;
  29. end;
  30. implementation
  31. uses
  32. globtype,systems,
  33. cutils,verbose,globals,
  34. symconst,symbase,symsym,symcpu,symtable,defutil,paramgr,parabase,
  35. cgbase,pass_2,
  36. cpuinfo,cpubase,aasmbase,aasmtai,aasmdata,aasmcpu,
  37. nmem,nld,ncnv,
  38. ncgutil,cgutils,cgobj,tgobj,regvars,rgobj,rgcpu,
  39. cg64f32,cgcpu,cpupi,procinfo;
  40. procedure tppccallnode.gen_syscall_para(para: tcallparanode);
  41. begin
  42. { lib parameter has no special type but proccalloptions must be a syscall }
  43. para.left:=cloadnode.create(tcpuprocdef(procdefinition).libsym,tcpuprocdef(procdefinition).libsym.owner);
  44. end;
  45. procedure tppccallnode.extra_call_code;
  46. begin
  47. if assigned(varargsparas) then
  48. begin
  49. if (target_info.abi = abi_powerpc_sysv) then
  50. begin
  51. if va_uses_float_reg in varargsparas.varargsinfo then
  52. current_asmdata.CurrAsmList.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  53. else
  54. current_asmdata.CurrAsmList.concat(taicpu.op_const_const_const(A_CRXOR,6,6,6));
  55. end;
  56. end;
  57. end;
  58. procedure tppccallnode.do_syscall;
  59. var
  60. tmpref: treference;
  61. begin
  62. case target_info.system of
  63. system_powerpc_amiga:
  64. begin
  65. // one syscall convention for Amiga/PowerPC
  66. // which is very similar to basesysv on MorphOS
  67. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  68. reference_reset_base(tmpref,NR_R3,tprocdef(procdefinition).extnumber,sizeof(pint));
  69. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  70. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  71. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  72. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  73. end;
  74. system_powerpc_morphos:
  75. begin
  76. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  77. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  78. begin
  79. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  80. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  81. reference_reset(tmpref,sizeof(pint));
  82. tmpref.symbol:=current_asmdata.RefAsmSymbol(tstaticvarsym(tcpuprocdef(procdefinition).libsym).mangledname);
  83. tmpref.refaddr:=addr_higha;
  84. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LIS,NR_R12,tmpref));
  85. tmpref.base:=NR_R12;
  86. tmpref.refaddr:=addr_low;
  87. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R12,tmpref));
  88. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber,sizeof(pint));
  89. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  90. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  91. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  92. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  93. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  94. end
  95. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  96. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  97. begin
  98. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  99. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  100. reference_reset_base(tmpref,NR_R3,-tprocdef(procdefinition).extnumber,sizeof(pint))
  101. else
  102. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber,sizeof(pint));
  103. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  104. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  105. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BCTRL));
  106. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  107. end
  108. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  109. begin
  110. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  111. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R3);
  112. { store call offset into R3 }
  113. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  114. { prepare LR, and call function }
  115. reference_reset_base(tmpref,NR_R2,100,4); { 100 ($64) is EmulDirectCallOS offset }
  116. current_asmdata.CurrAsmList.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  117. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_MTLR,NR_R0));
  118. current_asmdata.CurrAsmList.concat(taicpu.op_none(A_BLRL));
  119. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R3);
  120. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  121. end
  122. else
  123. internalerror(2005010403);
  124. end;
  125. else
  126. internalerror(2004042901);
  127. end;
  128. end;
  129. begin
  130. ccallnode:=tppccallnode;
  131. end.