n8086mem.pas 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i8086 assembler for in memory related 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 n8086mem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cgbase,cpuinfo,cpubase,
  23. node,nmem,ncgmem,nx86mem;
  24. type
  25. ti8086derefnode = class(tx86derefnode)
  26. procedure pass_generate_code;override;
  27. end;
  28. implementation
  29. uses
  30. systems,globals,
  31. cutils,verbose,
  32. symbase,symconst,symdef,symtable,symtype,symsym,
  33. parabase,paramgr,
  34. aasmtai,aasmdata,
  35. nld,ncon,nadd,
  36. cgutils,cgobj,
  37. defutil,hlcgobj,
  38. pass_2,ncgutil;
  39. {*****************************************************************************
  40. TI8086DEREFNODE
  41. *****************************************************************************}
  42. procedure ti8086derefnode.pass_generate_code;
  43. var
  44. paraloc1 : tcgpara;
  45. pd : tprocdef;
  46. sym : tsym;
  47. st : tsymtable;
  48. tmpref: treference;
  49. begin
  50. if tpointerdef(left.resultdef).x86pointertyp in [x86pt_far,x86pt_huge] then
  51. begin
  52. secondpass(left);
  53. { assume natural alignment, except for packed records }
  54. if not(resultdef.typ in [recorddef,objectdef]) or
  55. (tabstractrecordsymtable(tabstractrecorddef(resultdef).symtable).usefieldalignment<>1) then
  56. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),resultdef.alignment)
  57. else
  58. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),1);
  59. if not(left.location.loc in [LOC_CREGISTER,LOC_REGISTER,LOC_CREFERENCE,LOC_REFERENCE,LOC_CONSTANT]) then
  60. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  61. case left.location.loc of
  62. LOC_CREGISTER,
  63. LOC_REGISTER:
  64. begin
  65. maybechangeloadnodereg(current_asmdata.CurrAsmList,left,true);
  66. location.reference.base := left.location.register;
  67. location.reference.segment := GetNextReg(left.location.register);
  68. end;
  69. LOC_CREFERENCE,
  70. LOC_REFERENCE:
  71. begin
  72. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  73. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,left.location.reference,location.reference.base);
  74. location.reference.segment:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  75. tmpref:=left.location.reference;
  76. inc(tmpref.offset,2);
  77. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,tmpref,location.reference.segment);
  78. end;
  79. LOC_CONSTANT:
  80. begin
  81. location.reference.offset:=left.location.value and $FFFF;
  82. location.reference.segment:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  83. cg.a_load_const_reg(current_asmdata.CurrAsmList,OS_16,(left.location.value shr 16) and $FFFF,location.reference.segment);
  84. end;
  85. else
  86. internalerror(200507031);
  87. end;
  88. if (cs_use_heaptrc in current_settings.globalswitches) and
  89. (cs_checkpointer in current_settings.localswitches) and
  90. not(cs_compilesystem in current_settings.moduleswitches) and
  91. {$ifdef x86}
  92. (tpointerdef(left.resultdef).x86pointertyp = default_x86_data_pointer_type) and
  93. {$endif x86}
  94. not(nf_no_checkpointer in flags) and
  95. { can be NR_NO in case of LOC_CONSTANT }
  96. (location.reference.base<>NR_NO) then
  97. begin
  98. if not searchsym_in_named_module('HEAPTRC','CHECKPOINTER',sym,st) or
  99. (sym.typ<>procsym) then
  100. internalerror(2012010601);
  101. pd:=tprocdef(tprocsym(sym).ProcdefList[0]);
  102. paraloc1.init;
  103. paramanager.getintparaloc(pd,1,paraloc1);
  104. hlcg.a_load_reg_cgpara(current_asmdata.CurrAsmList,resultdef,location.reference.base,paraloc1);
  105. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  106. paraloc1.done;
  107. hlcg.allocallcpuregisters(current_asmdata.CurrAsmList);
  108. hlcg.a_call_name(current_asmdata.CurrAsmList,pd,'FPC_CHECKPOINTER',nil,false);
  109. hlcg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  110. end;
  111. end
  112. else
  113. inherited pass_generate_code;
  114. end;
  115. begin
  116. cderefnode:=ti8086derefnode;
  117. end.