2
Copyright (c) 1998-2002 by Florian Klaempfl
4
This unit implements an asmoutput class for i386 AT&T syntax
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
****************************************************************************
22
{ This unit implements an asmoutput class for i386 AT&T syntax
33
aasmbase,aasmtai,aasmdata,assemble,aggas;
36
Tx86ATTAssembler=class(TGNUassembler)
37
constructor create(smart: boolean); override;
40
Tx86AppleGNUAssembler=class(TAppleGNUassembler)
41
constructor create(smart: boolean); override;
45
Tx86InstrWriter=class(TCPUInstrWriter)
47
procedure WriteReference(var ref : treference);
48
procedure WriteOper(const o:toper);
49
procedure WriteOper_jmp(const o:toper);
51
procedure WriteInstruction(hp: tai);override;
66
{****************************************************************************
68
****************************************************************************}
70
constructor Tx86ATTAssembler.create(smart: boolean);
72
inherited create(smart);
73
InstrWriter := Tx86InstrWriter.create(self);
76
{****************************************************************************
78
****************************************************************************}
80
constructor Tx86AppleGNUAssembler.create(smart: boolean);
82
inherited create(smart);
83
InstrWriter := Tx86InstrWriter.create(self);
86
{****************************************************************************
88
****************************************************************************}
90
procedure Tx86InstrWriter.WriteReference(var ref : treference);
94
{ do we have a segment prefix ? }
95
{ These are probably not correctly handled under GAS }
96
{ should be replaced by coding the segment override }
97
{ directly! - DJGPP FAQ }
98
if segment<>NR_NO then
99
owner.AsmWrite(gas_regname(segment)+':');
100
if assigned(symbol) then
101
owner.AsmWrite(symbol.name);
102
if ref.refaddr=addr_pic then
104
owner.AsmWrite('@GOTPCREL');
106
owner.AsmWrite('@GOT');
109
owner.AsmWrite(tostr(offset))
113
if assigned(symbol) then
114
owner.AsmWrite('+'+tostr(offset))
116
owner.AsmWrite(tostr(offset));
118
else if (index=NR_NO) and (base=NR_NO) and (not assigned(symbol)) then
120
if (index<>NR_NO) and (base=NR_NO) then
122
owner.AsmWrite('(,'+gas_regname(index));
123
if scalefactor<>0 then
124
owner.AsmWrite(','+tostr(scalefactor)+')')
129
if (index=NR_NO) and (base<>NR_NO) then
130
owner.AsmWrite('('+gas_regname(base)+')')
132
if (index<>NR_NO) and (base<>NR_NO) then
134
owner.AsmWrite('('+gas_regname(base)+','+gas_regname(index));
135
if scalefactor<>0 then
136
owner.AsmWrite(','+tostr(scalefactor));
143
procedure Tx86InstrWriter.WriteOper(const o:toper);
147
owner.AsmWrite(gas_regname(o.reg));
149
if o.ref^.refaddr in [addr_no,addr_pic] then
150
WriteReference(o.ref^)
154
if assigned(o.ref^.symbol) then
155
owner.AsmWrite(o.ref^.symbol.name);
156
if o.ref^.offset>0 then
157
owner.AsmWrite('+'+tostr(o.ref^.offset))
159
if o.ref^.offset<0 then
160
owner.AsmWrite(tostr(o.ref^.offset))
162
if not(assigned(o.ref^.symbol)) then
166
owner.AsmWrite('$'+tostr(o.val));
168
internalerror(10001);
173
procedure Tx86InstrWriter.WriteOper_jmp(const o:toper);
177
owner.AsmWrite('*'+gas_regname(o.reg));
180
if o.ref^.refaddr=addr_no then
183
WriteReference(o.ref^);
187
owner.AsmWrite(o.ref^.symbol.name);
188
if o.ref^.refaddr=addr_pic then
189
owner.AsmWrite('@PLT');
190
if o.ref^.offset>0 then
191
owner.AsmWrite('+'+tostr(o.ref^.offset))
193
if o.ref^.offset<0 then
194
owner.AsmWrite(tostr(o.ref^.offset));
198
owner.AsmWrite(tostr(o.val));
200
internalerror(10001);
205
procedure Tx86InstrWriter.WriteInstruction(hp: tai);
211
if hp.typ <> ait_instruction then
213
taicpu(hp).SetOperandOrder(op_att);
214
op:=taicpu(hp).opcode;
215
calljmp:=is_calljmp(op);
217
{ movsd should not be translated to movsl when there
218
are (xmm) arguments }
219
if (op=A_MOVSD) and (taicpu(hp).ops>0) then
220
owner.AsmWrite('movsd')
222
owner.AsmWrite(gas_op2str[op]);
223
owner.AsmWrite(cond2str[taicpu(hp).condition]);
224
{ suffix needed ? fnstsw,fldcw don't support suffixes
225
with binutils 2.9.5 under linux }
226
{ if (Taicpu(hp).oper[0]^.typ=top_reg) and
227
(Taicpu(hp).oper[0]^.reg.enum>lastreg) then
228
internalerror(200301081);}
231
(gas_needsuffix[op]<>AttSufNONE) and
238
(taicpu(hp).ops<>0) and
239
(taicpu(hp).oper[0]^.typ=top_reg) and
240
(getregtype(taicpu(hp).oper[0]^.reg)=R_FPUREGISTER)
242
owner.AsmWrite(gas_opsize2str[taicpu(hp).opsize]);
244
if taicpu(hp).ops<>0 then
249
WriteOper_jmp(taicpu(hp).oper[0]^);
253
for i:=0 to taicpu(hp).ops-1 do
259
WriteOper(taicpu(hp).oper[i]^);
266
{*****************************************************************************
268
*****************************************************************************}
272
as_x86_64_as_info : tasminfo =
277
asmcmd : '--64 -o $OBJ $ASM';
278
supported_target : system_any;
279
flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
284
as_i386_as_info : tasminfo =
289
asmcmd : '--32 -o $OBJ $ASM';
290
supported_target : system_any;
291
flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
297
as_i386_as_aout_info : tasminfo =
299
id : as_i386_as_aout;
302
asmcmd : '-o $OBJ $ASM';
303
supported_target : system_any;
304
flags : [af_allowdirect,af_needar];
310
as_i386_gas_darwin_info : tasminfo =
315
asmcmd : '-o $OBJ $ASM -arch i386';
316
supported_target : system_any;
317
flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
322
as_i386_gas_info : tasminfo =
327
asmcmd : '--32 -o $OBJ $ASM';
328
supported_target : system_any;
329
flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf];
337
RegisterAssembler(as_x86_64_as_info,Tx86ATTAssembler);
339
RegisterAssembler(as_i386_as_info,Tx86ATTAssembler);
340
RegisterAssembler(as_i386_gas_info,Tx86ATTAssembler);
341
RegisterAssembler(as_i386_gas_darwin_info,Tx86AppleGNUAssembler);
342
RegisterAssembler(as_i386_as_aout_info,Tx86ATTAssembler);