n8086cal.pas 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate i8086 assembler for in call 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 n8086cal;
  18. {$i fpcdefs.inc}
  19. interface
  20. { $define AnsiStrRef}
  21. uses
  22. nx86cal;
  23. type
  24. ti8086callnode = class(tx86callnode)
  25. protected
  26. procedure pop_parasize(pop_size:longint);override;
  27. procedure extra_interrupt_code;override;
  28. end;
  29. implementation
  30. uses
  31. globtype,systems,
  32. cutils,verbose,globals,
  33. cgbase,cgutils,
  34. cpubase,paramgr,
  35. aasmtai,aasmdata,aasmcpu,
  36. ncal,nbas,nmem,nld,ncnv,
  37. cga,cgobj,cpuinfo;
  38. {*****************************************************************************
  39. TI8086CALLNODE
  40. *****************************************************************************}
  41. procedure ti8086callnode.extra_interrupt_code;
  42. begin
  43. emit_none(A_PUSHF,S_W);
  44. emit_reg(A_PUSH,S_W,NR_CS);
  45. end;
  46. procedure ti8086callnode.pop_parasize(pop_size:longint);
  47. var
  48. hreg : tregister;
  49. begin
  50. if (paramanager.use_fixed_stack) then
  51. begin
  52. { very weird: in this case the callee does a "ret $4" and the }
  53. { caller immediately a "subl $4,%esp". Possibly this is for }
  54. { use_fixed_stack code to be able to transparently call }
  55. { old-style code (JM) }
  56. dec(pop_size,pushedparasize);
  57. if (pop_size < 0) then
  58. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_SUB,S_W,-pop_size,NR_SP));
  59. exit;
  60. end;
  61. { better than an add on all processors }
  62. if pop_size=2 then
  63. begin
  64. hreg:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  65. current_asmdata.CurrAsmList.concat(taicpu.op_reg(A_POP,S_W,hreg));
  66. end
  67. { the pentium has two pipes and pop reg is pairable }
  68. { but the registers must be different! }
  69. else
  70. if pop_size<>0 then
  71. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_ADD,S_W,pop_size,NR_SP));
  72. end;
  73. begin
  74. ccallnode:=ti8086callnode;
  75. end.