nppcld.pas 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate ppc assembler for nodes that handle loads and assignments
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nppcld;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncgld;
  23. type
  24. tppcloadnode = class(tcgloadnode)
  25. procedure pass_2; override;
  26. procedure generate_picvaraccess;override;
  27. end;
  28. implementation
  29. uses
  30. verbose,
  31. systems,
  32. cpubase,
  33. cgutils,cgobj,
  34. aasmbase,aasmtai,
  35. symconst,symsym,
  36. procinfo,
  37. nld;
  38. procedure tppcloadnode.pass_2;
  39. var
  40. l : tasmsymbol;
  41. ref : treference;
  42. begin
  43. case target_info.system of
  44. system_powerpc_darwin:
  45. begin
  46. if (symtableentry.typ = procsym) and
  47. not assigned(left) and
  48. ((tprocsym(symtableentry).owner.unitid<>0) or
  49. (po_external in tprocsym(symtableentry).procdef[1].procoptions)) then
  50. begin
  51. l:=objectlibrary.getasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr');
  52. if not(assigned(l)) then
  53. begin
  54. l:=objectlibrary.newasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  55. picdata.concat(tai_symbol.create(l,0));
  56. picdata.concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tprocsym(symtableentry).procdef[1].mangledname,AB_EXTERNAL,AT_DATA)));
  57. picdata.concat(tai_const.create_32bit(0));
  58. end;
  59. reference_reset_symbol(ref,l,0);
  60. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  61. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  62. end
  63. else
  64. inherited pass_2;
  65. end;
  66. else
  67. inherited pass_2;
  68. end;
  69. end;
  70. procedure tppcloadnode.generate_picvaraccess;
  71. var
  72. l : tasmsymbol;
  73. ref : treference;
  74. begin
  75. case target_info.system of
  76. system_powerpc_darwin:
  77. begin
  78. if (tglobalvarsym(symtableentry).owner.unitid<>0) or
  79. (vo_is_dll_var in tglobalvarsym(symtableentry).varoptions) then
  80. begin
  81. l:=objectlibrary.getasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr');
  82. if not(assigned(l)) then
  83. begin
  84. l:=objectlibrary.newasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  85. picdata.concat(tai_symbol.create(l,0));
  86. picdata.concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA)));
  87. picdata.concat(tai_const.create_32bit(0));
  88. end;
  89. reference_reset_symbol(ref,l,0);
  90. { ref.base:=current_procinfo.got;
  91. ref.relsymbol:=current_procinfo.gotlabel;}
  92. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  93. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  94. end
  95. else
  96. internalerror(200403021);
  97. end
  98. else
  99. internalerror(200402291);
  100. end;
  101. end;
  102. begin
  103. cloadnode:=tppcloadnode;
  104. end.
  105. {
  106. $Log$
  107. Revision 1.5 2004-11-11 19:31:33 peter
  108. * fixed compile of powerpc,sparc,arm
  109. Revision 1.4 2004/07/19 12:45:43 jonas
  110. * fixed loading external procedure addresses
  111. Revision 1.3 2004/06/17 16:55:46 peter
  112. * powerpc compiles again
  113. Revision 1.2 2004/03/05 22:17:11 jonas
  114. * fixed importing of variables from shared libraries, but disabled
  115. PIC support for now. You have to save/restore r31 when you us it! :)
  116. Also, it's not necessary to support the imported variables
  117. Revision 1.1 2004/03/02 17:32:12 florian
  118. * make cycle fixed
  119. + pic support for darwin
  120. + support of importing vars from shared libs on darwin implemented
  121. }