nppcld.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. (tprocsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  48. (
  49. (not tprocsym(symtableentry).owner.iscurrentunit) or
  50. (po_external in tprocsym(symtableentry).procdef[1].procoptions)
  51. ) then
  52. begin
  53. l:=objectlibrary.getasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr');
  54. if not(assigned(l)) then
  55. begin
  56. l:=objectlibrary.newasmsymbol('L'+tprocsym(symtableentry).procdef[1].mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  57. picdata.concat(tai_symbol.create(l,0));
  58. picdata.concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tprocsym(symtableentry).procdef[1].mangledname,AB_EXTERNAL,AT_DATA)));
  59. picdata.concat(tai_const.create_32bit(0));
  60. end;
  61. reference_reset_symbol(ref,l,0);
  62. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  63. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  64. end
  65. else
  66. inherited pass_2;
  67. end;
  68. else
  69. inherited pass_2;
  70. end;
  71. end;
  72. procedure tppcloadnode.generate_picvaraccess;
  73. var
  74. l : tasmsymbol;
  75. ref : treference;
  76. begin
  77. case target_info.system of
  78. system_powerpc_darwin:
  79. begin
  80. if (vo_is_dll_var in tglobalvarsym(symtableentry).varoptions) or
  81. ((tglobalvarsym(symtableentry).owner.symtabletype in [staticsymtable,globalsymtable]) and
  82. not(tglobalvarsym(symtableentry).owner.iscurrentunit)) then
  83. begin
  84. l:=objectlibrary.getasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr');
  85. if not(assigned(l)) then
  86. begin
  87. l:=objectlibrary.newasmsymbol('L'+tglobalvarsym(symtableentry).mangledname+'$non_lazy_ptr',AB_COMMON,AT_DATA);
  88. picdata.concat(tai_symbol.create(l,0));
  89. picdata.concat(tai_const.create_indirect_sym(objectlibrary.newasmsymbol(tglobalvarsym(symtableentry).mangledname,AB_EXTERNAL,AT_DATA)));
  90. picdata.concat(tai_const.create_32bit(0));
  91. end;
  92. reference_reset_symbol(ref,l,0);
  93. { ref.base:=current_procinfo.got;
  94. ref.relsymbol:=current_procinfo.gotlabel;}
  95. reference_reset_base(location.reference,cg.getaddressregister(exprasmlist),0);
  96. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,ref,location.reference.base);
  97. end
  98. else
  99. internalerror(200403021);
  100. end
  101. else
  102. internalerror(200402291);
  103. end;
  104. end;
  105. begin
  106. cloadnode:=tppcloadnode;
  107. end.
  108. {
  109. $Log$
  110. Revision 1.8 2005-01-24 18:13:46 jonas
  111. * fixed bug introduced in revision 1.6
  112. Revision 1.7 2005/01/20 17:47:01 peter
  113. * remove copy_value_on_stack and a_param_copy_ref
  114. Revision 1.6 2005/01/19 22:19:41 peter
  115. * unit mapping rewrite
  116. * new derefmap added
  117. Revision 1.5 2004/11/11 19:31:33 peter
  118. * fixed compile of powerpc,sparc,arm
  119. Revision 1.4 2004/07/19 12:45:43 jonas
  120. * fixed loading external procedure addresses
  121. Revision 1.3 2004/06/17 16:55:46 peter
  122. * powerpc compiles again
  123. Revision 1.2 2004/03/05 22:17:11 jonas
  124. * fixed importing of variables from shared libraries, but disabled
  125. PIC support for now. You have to save/restore r31 when you us it! :)
  126. Also, it's not necessary to support the imported variables
  127. Revision 1.1 2004/03/02 17:32:12 florian
  128. * make cycle fixed
  129. + pic support for darwin
  130. + support of importing vars from shared libs on darwin implemented
  131. }