narmcal.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Implements the ARM 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 narmcal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,ncal,ncgcal;
  22. type
  23. tarmcallnode = class(tcgcallnode)
  24. procedure gen_syscall_para(para: tcallparanode); override;
  25. procedure set_result_location(realresdef: tstoreddef);override;
  26. public
  27. procedure do_syscall;override;
  28. end;
  29. implementation
  30. uses
  31. verbose,globtype,globals,aasmdata,aasmtai,
  32. symconst,symtype,symbase,symsym,symcpu,parabase,paramgr,
  33. cgbase,cgobj,cgutils,cpuinfo,cpubase,cutils,
  34. ncgutil,tgobj,nld,
  35. systems;
  36. procedure tarmcallnode.gen_syscall_para(para: tcallparanode);
  37. begin
  38. { lib parameter has no special type but proccalloptions must be a syscall }
  39. para.left:=cloadnode.create(tcpuprocdef(procdefinition).libsym,tcpuprocdef(procdefinition).libsym.owner);
  40. end;
  41. procedure tarmcallnode.do_syscall;
  42. var
  43. tmpref: treference;
  44. libparaloc: pcgparalocation;
  45. hsym: tsym;
  46. begin
  47. case target_info.system of
  48. system_arm_aros:
  49. begin
  50. if (po_syscall_baselast in tprocdef(procdefinition).procoptions) then
  51. begin
  52. current_asmdata.CurrAsmList.concat(tai_comment.create(strpnew('AROS SysCall - BaseLast')));
  53. cg.getcpuregister(current_asmdata.CurrAsmList,NR_R12);
  54. hsym:=tsym(procdefinition.parast.Find('syscalllib'));
  55. if not assigned(hsym) then
  56. internalerror(2016110605);
  57. libparaloc:=tparavarsym(hsym).paraloc[callerside].location;
  58. if not assigned(libparaloc) then
  59. internalerror(2016110604);
  60. case libparaloc^.loc of
  61. LOC_REGISTER:
  62. reference_reset_base(tmpref,libparaloc^.register,-tprocdef(procdefinition).extnumber,sizeof(pint),[]);
  63. LOC_REFERENCE:
  64. begin
  65. reference_reset_base(tmpref,libparaloc^.reference.index,libparaloc^.reference.offset,sizeof(pint),[]);
  66. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,tmpref,NR_R12);
  67. reference_reset_base(tmpref,NR_R12,-tprocdef(procdefinition).extnumber,sizeof(pint),[]);
  68. end;
  69. else
  70. internalerror(2016110603);
  71. end;
  72. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,tmpref,NR_R12);
  73. cg.a_call_reg(current_asmdata.CurrAsmList,NR_R12);
  74. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_R12);
  75. exit;
  76. end;
  77. internalerror(2016110601);
  78. end;
  79. else
  80. internalerror(2016110602);
  81. end;
  82. end;
  83. procedure tarmcallnode.set_result_location(realresdef: tstoreddef);
  84. begin
  85. if (realresdef.typ=floatdef) and
  86. (target_info.abi<>abi_eabihf) and
  87. (procdefinition.proccalloption<>pocall_hardfloat) and
  88. ((cs_fp_emulation in current_settings.moduleswitches) or
  89. (current_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv4,fpu_vfpv3_d16,fpu_fpv4_s16])) then
  90. begin
  91. { keep the fpu values in integer registers for now, the code
  92. generator will move them to memory or an mmregister when necessary
  93. (avoids double moves in case a function result is assigned to
  94. another function result, or passed as a parameter) }
  95. case retloc.size of
  96. OS_32,
  97. OS_F32:
  98. location_allocate_register(current_asmdata.CurrAsmList,location,s32inttype,false);
  99. OS_64,
  100. OS_F64:
  101. location_allocate_register(current_asmdata.CurrAsmList,location,s64inttype,false);
  102. else
  103. internalerror(2010053008);
  104. end
  105. end
  106. else if (resultdef.typ=floatdef) and
  107. (location.loc=LOC_REGISTER) and
  108. (current_settings.fputype in [fpu_fpa,fpu_fpa10,fpu_fpa11]) then
  109. begin
  110. location_reset_ref(location,LOC_REFERENCE,location.size,resultdef.alignment,[]);
  111. tg.gethltemp(current_asmdata.CurrAsmList,resultdef,resultdef.size,tt_normal,location.reference);
  112. end
  113. else
  114. inherited;
  115. end;
  116. begin
  117. ccallnode:=tarmcallnode;
  118. end.