n8086inl.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i8086 inline 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 n8086inl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. nx86inl,node;
  22. type
  23. { ti8086inlinenode }
  24. ti8086inlinenode = class(tx86inlinenode)
  25. function typecheck_seg: tnode; override;
  26. function first_seg: tnode; override;
  27. procedure second_seg; override;
  28. procedure second_get_frame;override;
  29. end;
  30. implementation
  31. uses
  32. ninl,
  33. systems,
  34. globtype,globals,
  35. cutils,verbose,
  36. symconst,
  37. defutil,
  38. aasmbase,aasmtai,aasmdata,aasmcpu,
  39. symtype,symdef,
  40. cgbase,pass_2,
  41. cpuinfo,cpubase,paramgr,
  42. nbas,ncon,ncal,ncnv,nld,ncgutil,
  43. tgobj,
  44. cga,cgutils,cgx86,cgobj,hlcgobj,
  45. htypechk,procinfo;
  46. function ti8086inlinenode.typecheck_seg: tnode;
  47. begin
  48. result := nil;
  49. resultdef:=u16inttype;
  50. { don't allow constants }
  51. if is_constnode(left) then
  52. begin
  53. CGMessagePos(left.fileinfo,type_e_no_addr_of_constant);
  54. exit;
  55. end;
  56. end;
  57. function ti8086inlinenode.first_seg: tnode;
  58. begin
  59. expectloc:=LOC_REGISTER;
  60. result:=nil;
  61. end;
  62. procedure ti8086inlinenode.second_seg;
  63. var
  64. segref: treference;
  65. begin
  66. secondpass(left);
  67. if not(left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) then
  68. internalerror(2013040101);
  69. { if a segment register is specified in ref, we use that }
  70. if left.location.reference.segment<>NR_NO then
  71. begin
  72. location_reset(location,LOC_REGISTER,OS_16);
  73. if is_segment_reg(left.location.reference.segment) then
  74. begin
  75. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  76. current_asmdata.CurrAsmList.Concat(Taicpu.op_reg_reg(A_MOV,S_W,left.location.reference.segment,location.register));
  77. end
  78. else
  79. location.register:=left.location.reference.segment;
  80. end
  81. { references relative to a symbol use the segment of the symbol,
  82. which can be obtained by the SEG directive }
  83. else if assigned(left.location.reference.symbol) then
  84. begin
  85. location_reset(location,LOC_REGISTER,OS_16);
  86. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  87. reference_reset_symbol(segref,left.location.reference.symbol,0,0);
  88. segref.refaddr:=addr_seg;
  89. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_16,OS_16,segref,location.register);
  90. end
  91. else if left.location.reference.base=NR_BP then
  92. begin
  93. location_reset(location,LOC_REGISTER,OS_16);
  94. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  95. current_asmdata.CurrAsmList.concat(Taicpu.op_reg_reg(A_MOV,S_W,NR_SS,location.register));
  96. end
  97. else
  98. begin
  99. location_reset(location,LOC_REGISTER,OS_16);
  100. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_16);
  101. current_asmdata.CurrAsmList.Concat(Taicpu.op_reg_reg(A_MOV,S_W,NR_DS,location.register));
  102. end;
  103. end;
  104. procedure ti8086inlinenode.second_get_frame;
  105. begin
  106. if current_settings.x86memorymodel in x86_far_data_models then
  107. begin
  108. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  109. internalerror(2014030201);
  110. location_reset(location,LOC_REGISTER,OS_32);
  111. location.register:=cg.getintregister(current_asmdata.CurrAsmList,OS_32);
  112. emit_reg_reg(A_MOV,S_W,current_procinfo.framepointer,location.register);
  113. current_asmdata.CurrAsmList.Concat(Taicpu.op_reg_reg(A_MOV,S_W,NR_SS,GetNextReg(location.register)));
  114. end
  115. else
  116. inherited second_get_frame;
  117. end;
  118. begin
  119. cinlinenode:=ti8086inlinenode;
  120. end.