nppccal.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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,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. exprasmlist.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  45. else
  46. exprasmlist.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_morphos:
  56. begin
  57. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  58. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  59. begin
  60. cg.getcpuregister(exprasmlist,NR_R0);
  61. cg.getcpuregister(exprasmlist,NR_R31);
  62. reference_reset(tmpref);
  63. tmpref.symbol:=objectlibrary.newasmsymbol(tglobalvarsym(tprocdef(procdefinition).libsym).mangledname,AB_EXTERNAL,AT_DATA);
  64. tmpref.refaddr:=addr_hi;
  65. exprasmlist.concat(taicpu.op_reg_ref(A_LIS,NR_R31,tmpref));
  66. tmpref.base:=NR_R31;
  67. tmpref.refaddr:=addr_lo;
  68. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R31,tmpref));
  69. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R31,-tprocdef(procdefinition).extnumber));
  70. reference_reset_base(tmpref,NR_R31,0);
  71. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  72. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  73. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  74. cg.ungetcpuregister(exprasmlist,NR_R31);
  75. cg.ungetcpuregister(exprasmlist,NR_R0);
  76. end
  77. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  78. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  79. begin
  80. cg.getcpuregister(exprasmlist,NR_R0);
  81. cg.getcpuregister(exprasmlist,NR_R31);
  82. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  83. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R3,-tprocdef(procdefinition).extnumber))
  84. else
  85. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R12,-tprocdef(procdefinition).extnumber));
  86. reference_reset_base(tmpref,NR_R31,0);
  87. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  88. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  89. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  90. cg.ungetcpuregister(exprasmlist,NR_R31);
  91. cg.ungetcpuregister(exprasmlist,NR_R0);
  92. end
  93. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  94. begin
  95. cg.getcpuregister(exprasmlist,NR_R0);
  96. cg.getcpuregister(exprasmlist,NR_R3);
  97. { store call offset into R3 }
  98. exprasmlist.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  99. { prepare LR, and call function }
  100. reference_reset_base(tmpref,NR_R2,100); { 100 ($64) is EmulDirectCallOS offset }
  101. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  102. exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0));
  103. exprasmlist.concat(taicpu.op_none(A_BLRL));
  104. cg.ungetcpuregister(exprasmlist,NR_R0);
  105. cg.ungetcpuregister(exprasmlist,NR_R3);
  106. end
  107. else
  108. internalerror(2005010403);
  109. end;
  110. else
  111. internalerror(2004042901);
  112. end;
  113. end;
  114. begin
  115. ccallnode:=tppccallnode;
  116. end.