nx86ld.pas 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. {
  2. Copyright (c) 1998-2002,2015 by Florian Klaempfl
  3. Generate x86 assembler for in load 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 nx86ld;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. symtype,symsym,
  23. node,nld,ncgld;
  24. type
  25. tx86loadnode = class(tcgloadnode)
  26. protected
  27. procedure generate_threadvar_access(gvs: tstaticvarsym); override;
  28. end;
  29. implementation
  30. uses
  31. cutils,verbose,systems,
  32. aasmbase,aasmtai,aasmdata,
  33. cgutils,cgobj,
  34. symconst,symdef,symtable,
  35. cgbase,cpubase,parabase,paramgr;
  36. {*****************************************************************************
  37. TX86LOADNODE
  38. *****************************************************************************}
  39. procedure tx86loadnode.generate_threadvar_access(gvs: tstaticvarsym);
  40. var
  41. paraloc1 : tcgpara;
  42. pd: tprocdef;
  43. href: treference;
  44. hregister : tregister;
  45. handled: boolean;
  46. begin
  47. handled:=false;
  48. if (tf_section_threadvars in target_info.flags) then
  49. begin
  50. if target_info.system in [system_i386_win32,system_x86_64_win64] then
  51. begin
  52. paraloc1.init;
  53. pd:=search_system_proc('fpc_tls_add');
  54. paramanager.getintparaloc(current_asmdata.CurrAsmList,pd,1,paraloc1);
  55. if not(vo_is_weak_external in gvs.varoptions) then
  56. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(gvs.mangledname,AT_DATA,use_indirect_symbol(gvs)),0,sizeof(pint),[])
  57. else
  58. reference_reset_symbol(href,current_asmdata.WeakRefAsmSymbol(gvs.mangledname,AT_DATA),0,sizeof(pint),[]);
  59. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,href,paraloc1);
  60. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  61. paraloc1.done;
  62. cg.g_call(current_asmdata.CurrAsmList,'FPC_TLS_ADD');
  63. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  64. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  65. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,hregister);
  66. location.reference.base:=hregister;
  67. handled:=true;
  68. end;
  69. end;
  70. if not handled then
  71. inherited;
  72. if (tf_section_threadvars in target_info.flags) then
  73. begin
  74. case target_info.system of
  75. system_i386_linux,system_i386_android:
  76. location.reference.segment:=NR_GS;
  77. end;
  78. end;
  79. end;
  80. begin
  81. cloadnode:=tx86loadnode;
  82. end.