ag68kvasm.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. {
  2. Copyright (c) 2016 by the Free Pascal development team
  3. This unit is the VASM assembler writer for 68k
  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 ag68kvasm;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmbase,systems,
  22. aasmtai,aasmdata,
  23. assemble,aggas,ag68kgas,
  24. cpubase,cgutils,
  25. globtype;
  26. type
  27. tm68kvasm = class(Tm68kGNUassembler)
  28. protected
  29. function sectionattrs(atype:TAsmSectiontype):string; override;
  30. public
  31. constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
  32. function MakeCmdLine: TCmdStr; override;
  33. end;
  34. implementation
  35. uses
  36. cutils,cfileutl,globals,verbose,
  37. cgbase,
  38. cscript,
  39. itcpugas,cpuinfo,
  40. aasmcpu;
  41. {****************************************************************************}
  42. { VASM m68k Assembler writer }
  43. {****************************************************************************}
  44. constructor tm68kvasm.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
  45. begin
  46. inherited;
  47. InstrWriter := Tm68kInstrWriter.create(self);
  48. end;
  49. function tm68kvasm.sectionattrs(atype:TAsmSectiontype):string;
  50. begin
  51. case atype of
  52. sec_code, sec_fpc, sec_init, sec_fini:
  53. result:='acrx';
  54. { map sec_rodata as read-write, otherwise the linker (vlink) complains if it
  55. has to write into the relocations in a rodata section. (KB) }
  56. sec_data, sec_rodata:
  57. result:='adrw';
  58. sec_rodata_norel:
  59. case target_info.system of
  60. { stop vlink from complaining when it merges ro sections into rw ones (KB) }
  61. system_m68k_atari: result:='adrw';
  62. else
  63. result:='adr';
  64. end;
  65. sec_bss, sec_threadvar:
  66. result:='aurw';
  67. sec_stab, sec_stabstr:
  68. result:='dr';
  69. else
  70. result:='';
  71. end;
  72. end;
  73. function tm68kvasm.MakeCmdLine: TCmdStr;
  74. var
  75. objtype: string;
  76. begin
  77. result:=asminfo^.asmcmd;
  78. case target_info.system of
  79. { a.out doesn't support named sections, a.out is limited
  80. (no named sections) lets use ELF for interoperability }
  81. system_m68k_amiga,
  82. system_m68k_atari: objtype:='-Felf';
  83. else
  84. internalerror(2016052601);
  85. end;
  86. if (target_info.system = system_m68k_amiga) then
  87. begin
  88. Replace(result,'$ASM',maybequoted(ScriptFixFileName(Unix2AmigaPath(AsmFileName))));
  89. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(Unix2AmigaPath(ObjFileName))));
  90. end
  91. else
  92. begin
  93. Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
  94. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(ObjFileName)));
  95. end;
  96. Replace(result,'$ARCH','-m'+GasCpuTypeStr[current_settings.cputype]);
  97. Replace(result,'$OTYPE',objtype);
  98. Replace(result,'$EXTRAOPT',asmextraopt);
  99. end;
  100. {*****************************************************************************
  101. Initialize
  102. *****************************************************************************}
  103. const
  104. as_m68k_vasm_info : tasminfo =
  105. (
  106. id : as_m68k_vasm;
  107. idtxt : 'VASM';
  108. asmbin : 'vasmm68k_std';
  109. asmcmd: '-quiet -elfregs -gas $OTYPE $ARCH -o $OBJ $EXTRAOPT $ASM';
  110. supported_targets : [system_m68k_amiga,system_m68k_atari];
  111. flags : [af_needar,af_smartlink_sections];
  112. labelprefix : '.L';
  113. comment : '# ';
  114. dollarsign: '$';
  115. );
  116. begin
  117. RegisterAssembler(as_m68k_vasm_info,tm68kvasm);
  118. end.