agarmvasm.pas 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. {
  2. Copyright (c) 2016 by the Free Pascal development team
  3. This unit is the VASM assembler writer for ARM
  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 agarmvasm;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. aasmbase,systems,
  22. aasmtai,aasmdata,
  23. assemble,aggas,agarmgas,
  24. cpubase,cgutils,
  25. globtype;
  26. type
  27. TARMVASM = class(TARMGNUAssembler)
  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 TARMVASM.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
  45. begin
  46. inherited;
  47. InstrWriter := TARMInstrWriter.create(self);
  48. end;
  49. function TARMVASM.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. const
  69. cputype_to_vasm_march : array[tcputype] of string = (
  70. '', // cpu_none
  71. 'a2',
  72. 'a3',
  73. 'a4',
  74. 'a4t',
  75. '',
  76. '',
  77. '',
  78. '',
  79. '',
  80. '',
  81. '',
  82. '',
  83. '',
  84. '',
  85. '',
  86. '',
  87. '');
  88. function TARMVASM.MakeCmdLine: TCmdStr;
  89. var
  90. objtype: string;
  91. begin
  92. result:=asminfo^.asmcmd;
  93. case target_info.system of
  94. { a.out doesn't support named sections, lets use ELF for interoperability }
  95. system_arm_linux: objtype:='-Felf';
  96. else
  97. internalerror(2016052601);
  98. end;
  99. Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
  100. Replace(result,'$OBJ',maybequoted(ScriptFixFileName(ObjFileName)));
  101. Replace(result,'$ARCH','-'+cputype_to_vasm_march[current_settings.cputype]);
  102. Replace(result,'$OTYPE',objtype);
  103. Replace(result,'$EXTRAOPT',asmextraopt);
  104. end;
  105. {*****************************************************************************
  106. Initialize
  107. *****************************************************************************}
  108. const
  109. as_arm_vasm_info : tasminfo =
  110. (
  111. id : as_arm_vasm;
  112. idtxt : 'VASM';
  113. asmbin : 'vasmarm_std';
  114. asmcmd: '-quiet -elfregs -gas $OTYPE $ARCH -o $OBJ $EXTRAOPT $ASM';
  115. supported_targets : [system_arm_linux];
  116. flags : [af_needar,af_smartlink_sections];
  117. labelprefix : '.L';
  118. labelmaxlen : -1;
  119. comment : '# ';
  120. dollarsign: '$';
  121. );
  122. begin
  123. RegisterAssembler(as_arm_vasm_info,TARMVASM);
  124. end.