ag68kvasm.pas 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. result:='adr';
  60. sec_bss, sec_threadvar:
  61. result:='aurw';
  62. sec_stab, sec_stabstr:
  63. result:='dr';
  64. else
  65. result:='';
  66. end;
  67. end;
  68. function tm68kvasm.MakeCmdLine: TCmdStr;
  69. var
  70. objtype: string;
  71. begin
  72. result:=asminfo^.asmcmd;
  73. case target_info.system of
  74. { a.out doesn't support named sections }
  75. system_m68k_amiga: objtype:='-Felf';
  76. { atari never had a standard object format, a.out is limited, vasm/vlink author recommends vobj }
  77. system_m68k_atari: objtype:='-Fvobj';
  78. system_m68k_linux: objtype:='-Felf';
  79. else
  80. internalerror(2016052601);
  81. end;
  82. if (target_info.system = system_m68k_amiga) then
  83. begin
  84. Replace(result,'$ASM',maybequoted(ScriptFixFileName(Unix2AmigaPath(AsmFileName))));
  85. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(Unix2AmigaPath(ObjFileName))));
  86. end
  87. else
  88. begin
  89. Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
  90. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(ObjFileName)));
  91. end;
  92. Replace(result,'$ARCH','-m'+GasCpuTypeStr[current_settings.cputype]);
  93. Replace(result,'$OTYPE',objtype);
  94. Replace(result,'$EXTRAOPT',asmextraopt);
  95. end;
  96. {*****************************************************************************
  97. Initialize
  98. *****************************************************************************}
  99. const
  100. as_m68k_vasm_info : tasminfo =
  101. (
  102. id : as_m68k_vasm;
  103. idtxt : 'VASM';
  104. asmbin : 'vasmm68k_std';
  105. asmcmd: '-quiet -elfregs -gas $OTYPE $ARCH -o $OBJ $EXTRAOPT $ASM';
  106. supported_targets : [system_m68k_amiga,system_m68k_atari,system_m68k_linux];
  107. flags : [af_needar,af_smartlink_sections];
  108. labelprefix : '.L';
  109. comment : '# ';
  110. dollarsign: '$';
  111. );
  112. begin
  113. RegisterAssembler(as_m68k_vasm_info,tm68kvasm);
  114. end.