nppccal.pas 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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,symtype,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. procedure do_call_ref(constref ref: treference);
  60. begin
  61. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R0);
  62. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,ref,NR_R0);
  63. cg.a_call_reg(current_asmdata.CurrAsmList,NR_R0);
  64. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R0);
  65. end;
  66. var
  67. tmpref: treference;
  68. libparaloc: pcgparalocation;
  69. hsym: tsym;
  70. begin
  71. case target_info.system of
  72. system_powerpc_amiga:
  73. begin
  74. { one syscall convention for AmigaOS/PowerPC
  75. which is very similar to basesysv (a.k.a basefirst) on MorphOS }
  76. reference_reset_base(tmpref,NR_R3,tprocdef(procdefinition).extnumber,sizeof(pint));
  77. do_call_ref(tmpref);
  78. end;
  79. system_powerpc_morphos:
  80. begin
  81. { all conventions but legacy }
  82. if ([po_syscall_basefirst,po_syscall_basenone,
  83. po_syscall_baselast,po_syscall_basereg] * tprocdef(procdefinition).procoptions) <> [] then
  84. begin
  85. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  86. hsym:=tsym(procdefinition.parast.Find('syscalllib'));
  87. if not assigned(hsym) then
  88. internalerror(2016090501);
  89. libparaloc:=tparavarsym(hsym).paraloc[callerside].location;
  90. if not assigned(libparaloc) then
  91. internalerror(2016090502);
  92. case libparaloc^.loc of
  93. LOC_REGISTER:
  94. reference_reset_base(tmpref,libparaloc^.register,-tprocdef(procdefinition).extnumber,sizeof(pint));
  95. LOC_REFERENCE:
  96. begin
  97. { this can happen for sysvbase; if we run out of regs, the libbase will be passed on the stack }
  98. reference_reset_base(tmpref,libparaloc^.reference.index,libparaloc^.reference.offset,sizeof(pint));
  99. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,tmpref,NR_R12);
  100. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber,sizeof(pint));
  101. end;
  102. else
  103. internalerror(2016090202);
  104. end;
  105. do_call_ref(tmpref);
  106. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  107. end
  108. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  109. begin
  110. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R3);
  111. { R3 must contain the call offset }
  112. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  113. reference_reset_base(tmpref,NR_R2,100,4); { 100 ($64) is EmulDirectCallOS offset }
  114. do_call_ref(tmpref);
  115. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R3);
  116. end
  117. else
  118. internalerror(2005010403);
  119. end;
  120. else
  121. internalerror(2004042901);
  122. end;
  123. end;
  124. begin
  125. ccallnode:=tppccallnode;
  126. end.