nx64cal.pas 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Implements the x86-64 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 nx64cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,
  22. ncal,nx86cal;
  23. type
  24. tx8664callnode = class(tx86callnode)
  25. protected
  26. procedure gen_syscall_para(para: tcallparanode); override;
  27. procedure extra_call_code;override;
  28. procedure set_result_location(realresdef: tstoreddef);override;
  29. public
  30. procedure do_syscall;override;
  31. end;
  32. implementation
  33. uses
  34. globtype,
  35. systems,verbose,cutils,
  36. cpubase,cgbase,cgutils,cgobj,
  37. symconst,symcpu,nld,
  38. aasmtai,aasmdata,aasmcpu,
  39. cpupi;
  40. procedure tx8664callnode.do_syscall;
  41. var
  42. tmpref: treference;
  43. begin
  44. case target_info.system of
  45. system_x86_64_aros:
  46. begin
  47. if ([po_syscall_baselast,po_syscall_basereg] * tprocdef(procdefinition).procoptions) <> [] then
  48. begin
  49. current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('AROS SysCall')));
  50. cg.getcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  51. get_syscall_call_ref(tmpref,NR_RAX);
  52. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_CALL,S_NO,tmpref));
  53. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_RAX);
  54. exit;
  55. end;
  56. internalerror(2016120101);
  57. end;
  58. else
  59. internalerror(2015062801);
  60. end;
  61. end;
  62. procedure tx8664callnode.gen_syscall_para(para: tcallparanode);
  63. begin
  64. { lib parameter has no special type but proccalloptions must be a syscall }
  65. para.left:=cloadnode.create(tcpuprocdef(procdefinition).libsym,tcpuprocdef(procdefinition).libsym.owner);
  66. end;
  67. procedure tx8664callnode.extra_call_code;
  68. var
  69. mmregs : aint;
  70. begin
  71. { x86_64 requires %al to contain the no. SSE regs passed }
  72. if (cnf_uses_varargs in callnodeflags) and not x86_64_use_ms_abi(procdefinition.proccalloption) then
  73. begin
  74. if assigned(varargsparas) then
  75. mmregs:=varargsparas.mmregsused
  76. else
  77. mmregs:=0;
  78. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_MOV,S_Q,mmregs,NR_RAX))
  79. end;
  80. end;
  81. procedure tx8664callnode.set_result_location(realresdef: tstoreddef);
  82. begin
  83. { avoid useless "movq %xmm0,%rax" and "movq %rax,%xmm0" instructions
  84. (which moreover for some reason are not supported by the Darwin
  85. x86-64 assembler) }
  86. if assigned(retloc.location) and
  87. not assigned(retloc.location^.next) and
  88. (retloc.location^.loc in [LOC_MMREGISTER,LOC_CMMREGISTER]) then
  89. begin
  90. location_reset(location,LOC_MMREGISTER,retloc.location^.size);
  91. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,retloc.location^.size);
  92. end
  93. else
  94. inherited
  95. end;
  96. begin
  97. ccallnode:=tx8664callnode;
  98. end.