nppccal.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. {$ifdef GDB}
  33. strings,
  34. gdb,
  35. {$endif GDB}
  36. cgbase,pass_2,
  37. cpuinfo,cpubase,aasmbase,aasmtai,aasmcpu,
  38. nmem,nld,ncnv,
  39. ncgutil,cgutils,cgobj,tgobj,regvars,rgobj,rgcpu,
  40. cg64f32,cgcpu,cpupi,procinfo;
  41. procedure tppccallnode.extra_call_code;
  42. begin
  43. if assigned(varargsparas) then
  44. begin
  45. if (target_info.abi = abi_powerpc_sysv) then
  46. begin
  47. if va_uses_float_reg in varargsparas.varargsinfo then
  48. exprasmlist.concat(taicpu.op_const_const_const(A_CREQV,6,6,6))
  49. else
  50. exprasmlist.concat(taicpu.op_const_const_const(A_CRXOR,6,6,6));
  51. end;
  52. end;
  53. end;
  54. procedure tppccallnode.do_syscall;
  55. var
  56. tmpref: treference;
  57. begin
  58. case target_info.system of
  59. system_powerpc_morphos:
  60. begin
  61. if (po_syscall_sysv in tprocdef(procdefinition).procoptions) or
  62. (po_syscall_sysvbase in tprocdef(procdefinition).procoptions) then
  63. begin
  64. cg.getcpuregister(exprasmlist,NR_R0);
  65. cg.getcpuregister(exprasmlist,NR_R31);
  66. reference_reset(tmpref);
  67. tmpref.symbol:=objectlibrary.newasmsymbol(tglobalvarsym(tprocdef(procdefinition).libsym).mangledname,AB_EXTERNAL,AT_DATA);
  68. tmpref.refaddr:=addr_hi;
  69. exprasmlist.concat(taicpu.op_reg_ref(A_LIS,NR_R31,tmpref));
  70. tmpref.base:=NR_R31;
  71. tmpref.refaddr:=addr_lo;
  72. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R31,tmpref));
  73. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R31,-tprocdef(procdefinition).extnumber));
  74. reference_reset_base(tmpref,NR_R31,0);
  75. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  76. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  77. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  78. cg.ungetcpuregister(exprasmlist,NR_R31);
  79. cg.ungetcpuregister(exprasmlist,NR_R0);
  80. end
  81. else if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) or
  82. (po_syscall_r12base in tprocdef(procdefinition).procoptions) then
  83. begin
  84. cg.getcpuregister(exprasmlist,NR_R0);
  85. cg.getcpuregister(exprasmlist,NR_R31);
  86. if (po_syscall_basesysv in tprocdef(procdefinition).procoptions) then
  87. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R3,-tprocdef(procdefinition).extnumber))
  88. else
  89. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,NR_R31,NR_R12,-tprocdef(procdefinition).extnumber));
  90. reference_reset_base(tmpref,NR_R31,0);
  91. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  92. exprasmlist.concat(taicpu.op_reg(A_MTCTR,NR_R0));
  93. exprasmlist.concat(taicpu.op_none(A_BCTRL));
  94. cg.ungetcpuregister(exprasmlist,NR_R31);
  95. cg.ungetcpuregister(exprasmlist,NR_R0);
  96. end
  97. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  98. begin
  99. cg.getcpuregister(exprasmlist,NR_R0);
  100. cg.getcpuregister(exprasmlist,NR_R3);
  101. { store call offset into R3 }
  102. exprasmlist.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. exprasmlist.concat(taicpu.op_reg_ref(A_LWZ,NR_R0,tmpref));
  106. exprasmlist.concat(taicpu.op_reg(A_MTLR,NR_R0));
  107. exprasmlist.concat(taicpu.op_none(A_BLRL));
  108. cg.ungetcpuregister(exprasmlist,NR_R0);
  109. cg.ungetcpuregister(exprasmlist,NR_R3);
  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.