ag68kvasm.pas 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. sec_data:
  55. result:='adrw';
  56. sec_rodata,
  57. sec_rodata_norel:
  58. { map sec_rodata and sec_nodata_norel as read-write, otherwise the linker
  59. (vlink) complains if it has to write into the relocations in a rodata,
  60. and if it has to merge rodata and data sections on Amiga/Atari. (KB) }
  61. case target_info.system of
  62. system_m68k_atari,
  63. system_m68k_amiga:
  64. result:='adrw';
  65. else
  66. result:='adr';
  67. end;
  68. sec_bss, sec_threadvar:
  69. result:='aurw';
  70. sec_stab, sec_stabstr:
  71. result:='dr';
  72. else
  73. result:='';
  74. end;
  75. end;
  76. function tm68kvasm.MakeCmdLine: TCmdStr;
  77. var
  78. objtype: string;
  79. begin
  80. result:=asminfo^.asmcmd;
  81. case target_info.system of
  82. { a.out doesn't support named sections, lets use ELF for interoperability }
  83. system_m68k_amiga,
  84. system_m68k_atari,
  85. system_m68k_embedded,
  86. system_m68k_sinclairql,
  87. system_m68k_human68k: objtype:='-Felf';
  88. else
  89. internalerror(2016052601);
  90. end;
  91. if (target_info.system = system_m68k_amiga) then
  92. begin
  93. Replace(result,'$ASM',maybequoted(ScriptFixFileName(Unix2AmigaPath(AsmFileName))));
  94. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(Unix2AmigaPath(ObjFileName))));
  95. end
  96. else
  97. begin
  98. Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
  99. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(ObjFileName)));
  100. end;
  101. Replace(result,'$ARCH','-m'+GasCpuTypeStr[current_settings.cputype]);
  102. Replace(result,'$OTYPE',objtype);
  103. Replace(result,'$EXTRAOPT',asmextraopt);
  104. end;
  105. {*****************************************************************************
  106. Initialize
  107. *****************************************************************************}
  108. const
  109. as_m68k_vasm_info : tasminfo =
  110. (
  111. id : as_m68k_vasm;
  112. idtxt : 'VASM';
  113. asmbin : 'vasmm68k_std';
  114. asmcmd: '-quiet -elfregs -gas $OTYPE $ARCH -o $OBJ $EXTRAOPT $ASM';
  115. supported_targets : [system_m68k_amiga,system_m68k_atari,system_m68k_sinclairql,system_m68k_human68k,system_m68k_embedded];
  116. flags : [af_needar,af_smartlink_sections];
  117. labelprefix : '.L';
  118. labelmaxlen : -1;
  119. comment : '# ';
  120. dollarsign: '$';
  121. );
  122. begin
  123. RegisterAssembler(as_m68k_vasm_info,tm68kvasm);
  124. end.