2
$Id: agcpugas.pas,v 1.11 2004/05/01 23:29:01 florian Exp $
3
Copyright (c) 1998-2002 by Florian Klaempfl
5
This unit implements an asmoutput class for m68k GAS syntax
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21
****************************************************************************
23
{ This unit implements an asmoutput class for i386 AT&T syntax
34
aasmbase,aasmtai,aasmcpu,assemble,aggas;
37
TM68kAssembler=class(TGNUassembler)
39
procedure WriteInstruction(hp: tai);override;
43
gas_opsize2str : array[topsize] of string[2] =
44
('','.b','.w','.l','.s','.d','.x',''
55
function getreferencestring(var ref : treference) : string;
57
s,basestr,indexstr : string;
63
basestr:=gas_regname(base);
64
indexstr:=gas_regname(index);
65
if assigned(symbol) then
68
if offset<0 then s:=s+tostr(offset)
69
else if (offset>0) then
71
if (symbol=nil) then s:=tostr(offset)
72
else s:=s+'+'+tostr(offset);
74
else if (index=NR_NO) and (base=NR_NO) and not assigned(symbol) then
77
if (index<>NR_NO) and (base=NR_NO) and (direction=dir_none) then
79
if (scalefactor = 1) or (scalefactor = 0) then
80
s:=s+'(,'+indexstr+'.l)'
82
s:=s+'(,'+indexstr+'.l*'+tostr(scalefactor)+')'
84
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_inc) then
86
if (scalefactor = 1) or (scalefactor = 0) then
91
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_dec) then
93
if (scalefactor = 1) or (scalefactor = 0) then
98
else if (index=NR_NO) and (base<>NR_NO) and (direction=dir_none) then
102
else if (index<>NR_NO) and (base<>NR_NO) and (direction=dir_none) then
104
if (scalefactor = 1) or (scalefactor = 0) then
105
s:=s+'('+basestr+','+indexstr+'.l)'
107
s:=s+'('+basestr+','+indexstr+'.l*'+tostr(scalefactor)+')';
110
getreferencestring:=s;
114
function getopstr(const o:toper) : string;
121
getopstr:=gas_regname(o.reg);
123
if o.ref^.refaddr=addr_full then
125
if assigned(o.ref^.symbol) then
126
hs:='#'+o.ref^.symbol.name
129
if o.ref^.offset>0 then
130
hs:=hs+'+'+tostr(o.ref^.offset)
132
if o.ref^.offset<0 then
133
hs:=hs+tostr(o.ref^.offset)
135
if not(assigned(o.ref^.symbol)) then
140
getopstr:=getreferencestring(o.ref^);
144
for i:=RS_D0 to RS_D7 do
146
if i in o.regset^ then
147
hs:=hs+gas_regname(newreg(R_INTREGISTER,i,R_SUBWHOLE))+'/';
149
for i:=RS_A0 to RS_SP do
151
if i in o.regset^ then
152
hs:=hs+gas_regname(newreg(R_INTREGISTER,i,R_SUBWHOLE))+'/';
154
delete(hs,length(hs),1);
158
getopstr:='#'+tostr(longint(o.val));
159
else internalerror(200405021);
164
function getopstr_jmp(const o:toper) : string;
170
getopstr_jmp:=gas_regname(o.reg);
172
if o.ref^.refaddr=addr_no then
173
getopstr_jmp:=getreferencestring(o.ref^)
176
if assigned(o.ref^.symbol) then
177
hs:=o.ref^.symbol.name
180
if o.ref^.offset>0 then
181
hs:=hs+'+'+tostr(o.ref^.offset)
183
if o.ref^.offset<0 then
184
hs:=hs+tostr(o.ref^.offset)
186
if not(assigned(o.ref^.symbol)) then
191
getopstr_jmp:=tostr(o.val);
192
else internalerror(200405022);
196
{****************************************************************************
198
****************************************************************************}
200
{ returns the opcode string }
201
function getopcodestring(hp : tai) : string;
206
op:=taicpu(hp).opcode;
207
{ old versions of GAS don't like PEA.L and LEA.L }
209
A_LEA,A_PEA,A_ABCD,A_BCHG,A_BCLR,A_BSET,A_BTST,
210
A_EXG,A_NBCD,A_SBCD,A_SWAP,A_TAS,A_SCC,A_SCS,
211
A_SEQ,A_SGE,A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,
212
A_SNE,A_SPL,A_ST,A_SVC,A_SVS,A_SF]) then
216
s:=gas_op2str[op]+cond2str[taicpu(hp).condition]
218
if op in [a_dbxx,a_bxx,a_fbxx] then
219
s:=gas_op2str[op]+cond2str[taicpu(hp).condition]+gas_opsize2str[taicpu(hp).opsize]
221
s:=gas_op2str[op]+gas_opsize2str[taicpu(hp).opsize];
226
procedure TM68kAssembler.WriteInstruction(hp: tai);
234
if hp.typ <> ait_instruction then exit;
235
op:=taicpu(hp).opcode;
236
calljmp:=is_calljmp(op);
237
{ call maybe not translated to call }
238
s:=#9+getopcodestring(hp);
240
if taicpu(hp).ops<>0 then
242
{ call and jmp need an extra handling }
243
{ this code is only called if jmp isn't a labeled instruction }
244
{ quick hack to overcome a problem with manglednames=255 chars }
248
s:=getopstr_jmp(taicpu(hp).oper[0]^);
252
for i:=0 to taicpu(hp).ops-1 do
257
if ((op = A_DIVSL) or
262
(op = A_DIVU)) and (i=1) then
266
s:=s+sep+getopstr(taicpu(hp).oper[i]^)
274
{*****************************************************************************
276
*****************************************************************************}
279
as_m68k_as_info : tasminfo =
284
asmcmd : '-o $OBJ $ASM';
285
supported_target : system_any;
289
labelprefix_only_inside_procedure : false;
293
'.text','.data','.bss',
295
'.stab','.stabstr','COMMON')
299
RegisterAssembler(as_m68k_as_info,TM68kAssembler);
302
$Log: agcpugas.pas,v $
303
Revision 1.11 2004/05/01 23:29:01 florian
304
* continued to fix m68k compiler compilation
306
Revision 1.10 2004/04/27 15:46:01 florian
307
* several updates for compilation
309
Revision 1.9 2004/04/27 15:00:37 florian
310
- removed offsetfixup reference
312
Revision 1.8 2004/04/25 21:26:16 florian
313
* some m68k stuff fixed
315
Revision 1.7 2003/02/19 22:00:16 daniel
316
* Code generator converted to new register notation
317
- Horribily outdated todo.txt removed
319
Revision 1.6 2003/02/15 22:19:40 carl
320
* bugfix of emissions of jmp instructions
322
Revision 1.5 2003/01/08 18:43:57 daniel
323
* Tregister changed into a record
325
Revision 1.4 2002/11/30 23:33:02 carl
326
* merges from Pierre's fixes in m68k fixes branch
328
Revision 1.3 2002/09/07 15:25:11 peter
329
* old logs removed and tabs fixed
331
Revision 1.2 2002/08/13 18:58:54 carl
332
+ m68k problems with cvs fixed?()!