n68kcal.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. {
  2. Copyright (c) 2002 by Florian Klaempfl
  3. Implements the M68K specific part of 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 n68kcal;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symdef,node,ncal,ncgcal;
  22. type
  23. tm68kcallnode = class(tcgcallnode)
  24. protected
  25. procedure gen_syscall_para(para: tcallparanode); override;
  26. public
  27. procedure do_syscall;override;
  28. procedure pop_parasize(pop_size: longint);override;
  29. end;
  30. implementation
  31. uses
  32. globtype,systems,
  33. cutils,verbose,globals,
  34. symconst,symbase,symsym,symcpu,symtable,defutil,paramgr,parabase,
  35. cgbase,pass_2,
  36. cpuinfo,cpubase,aasmbase,aasmtai,aasmdata,aasmcpu,
  37. nmem,nld,ncnv,
  38. ncgutil,cgutils,cgobj,tgobj,rgobj,rgcpu,
  39. cg64f32,cgcpu,cpupi,procinfo;
  40. procedure tm68kcallnode.pop_parasize(pop_size: longint);
  41. begin
  42. if pop_size<>0 then
  43. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_ADD,S_L,pop_size,NR_SP));
  44. end;
  45. procedure tm68kcallnode.gen_syscall_para(para: tcallparanode);
  46. begin
  47. { lib parameter has no special type but proccalloptions must be a syscall }
  48. para.left:=cloadnode.create(tcpuprocdef(procdefinition).libsym,tcpuprocdef(procdefinition).libsym.owner);
  49. end;
  50. procedure tm68kcallnode.do_syscall;
  51. var
  52. tmpref: treference;
  53. begin
  54. case target_info.system of
  55. system_m68k_atari:
  56. begin
  57. if po_syscall in tprocdef(procdefinition).procoptions then
  58. begin
  59. reference_reset_base(tmpref,NR_SP,0,ctempposinvalid,2,[]);
  60. tmpref.direction:=dir_dec;
  61. current_asmdata.CurrAsmList.concat(taicpu.op_const_ref(A_MOVE,S_W,tprocdef(procdefinition).import_nr,tmpref));
  62. current_asmdata.CurrAsmList.concat(taicpu.op_const(A_TRAP,S_NO,tprocdef(procdefinition).extnumber));
  63. inc(pushedparasize,2); { kludge, trap code should be a hidden para instead... }
  64. end
  65. else
  66. internalerror(2016100301);
  67. end;
  68. system_m68k_amiga:
  69. begin
  70. if po_syscall_legacy in tprocdef(procdefinition).procoptions then
  71. begin
  72. { according to Amiga Developer CD 2.1, system functions destroy the
  73. scratch regs D0-D1 and A0-A1, but preserve all other regs. A6 is
  74. not used as FP on Amiga any more (we use A5), so we don't need to
  75. save it. (KB)
  76. http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0290.html }
  77. reference_reset_base(tmpref,NR_A6,-tprocdef(procdefinition).extnumber,ctempposinvalid,4,[]);
  78. current_asmdata.CurrAsmList.concat(taicpu.op_ref(A_JSR,S_NO,tmpref));
  79. end
  80. else
  81. internalerror(2005010403);
  82. end;
  83. system_m68k_palmos:
  84. begin
  85. if po_syscall in tprocdef(procdefinition).procoptions then
  86. begin
  87. if po_syscall_has_importnr in tprocdef(procdefinition).procoptions then
  88. begin
  89. cg.getcpuregister(current_asmdata.CurrAsmList,NR_D2);
  90. current_asmdata.CurrAsmList.concat(taicpu.op_const_reg(A_MOVE,S_L,tprocdef(procdefinition).import_nr,NR_D2));
  91. end;
  92. current_asmdata.CurrAsmList.concat(taicpu.op_const(A_TRAP,S_NO,15));
  93. current_asmdata.CurrAsmList.concat(tai_const.create_16bit(tprocdef(procdefinition).extnumber));
  94. if po_syscall_has_importnr in tprocdef(procdefinition).procoptions then
  95. cg.ungetcpuregister(current_asmdata.CurrAsmList,NR_D2);
  96. end
  97. else
  98. internalerror(2017081201);
  99. end;
  100. else
  101. internalerror(2004042901);
  102. end;
  103. end;
  104. begin
  105. ccallnode:=tm68kcallnode;
  106. end.