nppccal.pas 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. aasmdata, cgbase,
  22. symdef, node, ncal, ncgcal;
  23. type
  24. tppccallparanode = class(tcgcallparanode)
  25. end;
  26. tppccallnode = class(tcgcallnode)
  27. protected
  28. function get_call_reg(list: TAsmList): tregister; override;
  29. procedure unget_call_reg(list: TAsmList; reg: tregister); override;
  30. public
  31. function pass_1: tnode; override;
  32. procedure do_syscall; override;
  33. end;
  34. implementation
  35. uses
  36. globtype, systems,
  37. cutils, verbose, globals,
  38. symconst, symbase, symsym, symtable, defutil, paramgr, parabase,
  39. pass_2,
  40. cpuinfo, cpubase, aasmbase, aasmtai, aasmcpu,
  41. nmem, nld, ncnv,
  42. ncgutil, cgutils, cgobj, tgobj, rgobj, rgcpu,
  43. cgcpu, cpupi, procinfo;
  44. function tppccallnode.get_call_reg(list: TAsmList): tregister;
  45. begin
  46. { on the ppc64/ELFv2 abi, all indirect calls must go via R12, so that the
  47. called function can use R12 as PIC base register }
  48. cg.getcpuregister(list,NR_R12);
  49. result:=NR_R12;
  50. end;
  51. procedure tppccallnode.unget_call_reg(list: TAsmList; reg: tregister);
  52. begin
  53. cg.ungetcpuregister(list,NR_R12);
  54. end;
  55. function tppccallnode.pass_1: tnode;
  56. begin
  57. result:=inherited;
  58. if assigned(result) then
  59. exit;
  60. { for ELFv2, we must load the TOC/GOT register in case this routine may
  61. call an external routine (because the lookup of the target address is
  62. TOC-based). Maybe needs to be extended to non-ELFv2 too }
  63. if target_info.abi=abi_powerpc_elfv2 then
  64. include(current_procinfo.flags,pi_needs_got);
  65. end;
  66. procedure tppccallnode.do_syscall;
  67. begin
  68. { no MorphOS style syscalls supported. Only implemented to avoid abstract
  69. method not implemented compiler warning. }
  70. internalerror(2005120401);
  71. end;
  72. begin
  73. ccallparanode:=tppccallparanode;
  74. ccallnode := tppccallnode;
  75. end.