nppccal.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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,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. begin
  69. case target_info.system of
  70. system_powerpc_amiga:
  71. begin
  72. { one syscall convention for AmigaOS/PowerPC
  73. which is very similar to basesysv (a.k.a basefirst) on MorphOS }
  74. reference_reset_base(tmpref,NR_R3,tprocdef(procdefinition).extnumber,ctempposinvalid,sizeof(pint),[]);
  75. do_call_ref(tmpref);
  76. end;
  77. system_powerpc_morphos:
  78. begin
  79. { all conventions but legacy }
  80. if ([po_syscall_basefirst,po_syscall_basenone,
  81. po_syscall_baselast,po_syscall_basereg] * tprocdef(procdefinition).procoptions) <> [] then
  82. begin
  83. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  84. get_syscall_call_ref(tmpref,NR_R12);
  85. do_call_ref(tmpref);
  86. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  87. end
  88. else if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  89. begin
  90. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R3);
  91. { R3 must contain the call offset }
  92. current_asmdata.CurrAsmList.concat(taicpu.op_reg_const(A_LI,NR_R3,-tprocdef(procdefinition).extnumber));
  93. reference_reset_base(tmpref,NR_R2,100,ctempposinvalid,4,[]); { 100 ($64) is EmulDirectCallOS offset }
  94. do_call_ref(tmpref);
  95. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R3);
  96. end
  97. else
  98. internalerror(2005010403);
  99. end;
  100. else
  101. internalerror(2004042901);
  102. end;
  103. end;
  104. begin
  105. ccallnode:=tppccallnode;
  106. end.