1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
{
Copyright (c) 1998-2003 by Carl Eric Codere and Peter Vreman
Handles the common 68k assembler reader routines
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
unit ra68k;
{$i fpcdefs.inc}
interface
uses
aasmbase,aasmtai,aasmdata,aasmcpu,
cpubase,rautils,cclasses;
type
Tm68kOperand=class(TOperand)
end;
Tm68kInstruction=class(TInstruction)
opsize : topsize;
function ConcatInstruction(p : TAsmList):tai;override;
function ConcatLabeledInstr(p : TAsmList):tai;
end;
implementation
uses
verbose,cgbase;
{*****************************************************************************
TM68kInstruction
*****************************************************************************}
function TM68kInstruction.ConcatInstruction(p : TAsmList):tai;
begin
result:=inherited ConcatInstruction(p);
if assigned(result) then
taicpu(result).opsize:=opsize;
end;
{
function TM68kInstruction.ConcatInstruction(p : TAsmList):tai;
var
fits : boolean;
begin
writeln('jaj mami');
result:=nil;
fits := FALSE;
{ setup specific opcodetions for first pass }
{ Setup special operands }
{ Convert to general form as to conform to the m68k opcode table }
if (opcode = A_ADDA) or (opcode = A_ADDI)
then opcode := A_ADD
else
{ CMPM excluded because of GAS v1.34 BUG }
if (opcode = A_CMPA) or
(opcode = A_CMPI) then
opcode := A_CMP
else
if opcode = A_EORI then
opcode := A_EOR
else
if opcode = A_MOVEA then
opcode := A_MOVE
else
if opcode = A_ORI then
opcode := A_OR
else
if (opcode = A_SUBA) or (opcode = A_SUBI) then
opcode := A_SUB;
{ Setup operand types }
(*
in opcode <> A_MOVEM then
begin
while not(fits) do
begin
{ set the opcodetion cache, if the opcodetion }
{ occurs the first time }
if (it[i].i=opcode) and (ins_cache[opcode]=-1) then
ins_cache[opcode]:=i;
if (it[i].i=opcode) and (instr.ops=it[i].ops) then
begin
{ first fit }
case instr.ops of
0 : begin
fits:=true;
break;
end;
1 :
begin
if (optyp1 and it[i].o1)<>0 then
begin
fits:=true;
break;
end;
end;
2 : if ((optyp1 and it[i].o1)<>0) and
((optyp2 and it[i].o2)<>0) then
begin
fits:=true;
break;
end
3 : if ((optyp1 and it[i].o1)<>0) and
((optyp2 and it[i].o2)<>0) and
((optyp3 and it[i].o3)<>0) then
begin
fits:=true;
break;
end;
end; { end case }
end; { endif }
if it[i].i=A_NONE then
begin
{ NO MATCH! }
Message(asmr_e_invalid_combination_opcode_and_operand);
exit;
end;
inc(i);
end; { end while }
*)
fits:=TRUE;
{ We add the opcode to the opcode linked list }
if fits then
begin
case ops of
0:
if opsize <> S_NO then
result:=(taicpu.op_none(opcode,opsize))
else
result:=(taicpu.op_none(opcode,S_NO));
1: begin
case operands[1].opr.typ of
OPR_SYMBOL:
begin
result:=(taicpu.op_sym_ofs(opcode,
opsize, operands[1].opr.symbol,operands[1].opr.symofs));
end;
OPR_CONSTANT:
begin
result:=(taicpu.op_const(opcode,
opsize, operands[1].opr.val));
end;
OPR_REGISTER:
result:=(taicpu.op_reg(opcode,opsize,operands[1].opr.reg));
OPR_REFERENCE:
if opsize <> S_NO then
begin
result:=(taicpu.op_ref(opcode,
opsize,operands[1].opr.ref));
end
else
begin
{ special jmp and call case with }
{ symbolic references. }
if opcode in [A_BSR,A_JMP,A_JSR,A_BRA,A_PEA] then
begin
result:=(taicpu.op_ref(opcode,
S_NO,operands[1].opr.ref));
end
else
Message(asmr_e_invalid_opcode_and_operand);
end;
OPR_NONE:
Message(asmr_e_invalid_opcode_and_operand);
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end;
end;
2: begin
{ source }
case operands[1].opr.typ of
{ reg,reg }
{ reg,ref }
OPR_REGISTER:
begin
case operands[2].opr.typ of
OPR_REGISTER:
begin
result:=(taicpu.op_reg_reg(opcode,
opsize,operands[1].opr.reg,operands[2].opr.reg));
end;
OPR_REFERENCE:
result:=(taicpu.op_reg_ref(opcode,
opsize,operands[1].opr.reg,operands[2].opr.ref));
else { else case }
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end second operand case for OPR_REGISTER }
end;
{ regset, ref }
OPR_regset:
begin
case operands[2].opr.typ of
OPR_REFERENCE :
result:=(taicpu.op_regset_ref(opcode,
opsize,operands[1].opr.regset,operands[2].opr.ref));
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end second operand case for OPR_regset }
end;
{ const,reg }
{ const,const }
{ const,ref }
OPR_CONSTANT:
case operands[2].opr.typ of
{ constant, constant does not have a specific size. }
OPR_CONSTANT:
result:=(taicpu.op_const_const(opcode,
S_NO,operands[1].opr.val,operands[2].opr.val));
OPR_REFERENCE:
begin
result:=(taicpu.op_const_ref(opcode,
opsize,operands[1].opr.val,
operands[2].opr.ref))
end;
OPR_REGISTER:
begin
result:=(taicpu.op_const_reg(opcode,
opsize,operands[1].opr.val,
operands[2].opr.reg))
end;
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end second operand case for OPR_CONSTANT }
{ ref,reg }
{ ref,ref }
OPR_REFERENCE:
case operands[2].opr.typ of
OPR_REGISTER:
begin
result:=(taicpu.op_ref_reg(opcode,
opsize,operands[1].opr.ref,
operands[2].opr.reg));
end;
OPR_regset:
begin
result:=(taicpu.op_ref_regset(opcode,
opsize,operands[1].opr.ref,
operands[2].opr.regset));
end;
OPR_REFERENCE: { special opcodes }
result:=(taicpu.op_ref_ref(opcode,
opsize,operands[1].opr.ref,
operands[2].opr.ref));
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end second operand case for OPR_REFERENCE }
OPR_SYMBOL: case operands[2].opr.typ of
OPR_REFERENCE:
begin
result:=(taicpu.op_sym_ofs_ref(opcode,
opsize,operands[1].opr.symbol,operands[1].opr.symofs,
operands[2].opr.ref))
end;
OPR_REGISTER:
begin
result:=(taicpu.op_sym_ofs_reg(opcode,
opsize,operands[1].opr.symbol,operands[1].opr.symofs,
operands[2].opr.reg))
end;
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end second operand case for OPR_SYMBOL }
else
begin
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end first operand case }
end;
3: begin
if (opcode = A_DIVSL) or (opcode = A_DIVUL) or (opcode = A_MULU)
or (opcode = A_MULS) or (opcode = A_DIVS) or (opcode = A_DIVU) then
begin
if (operands[1].opr.typ <> OPR_REGISTER)
or (operands[2].opr.typ <> OPR_REGISTER)
or (operands[3].opr.typ <> OPR_REGISTER) then
begin
Message(asmr_e_invalid_opcode_and_operand);
end
else
begin
result:=(taicpu. op_reg_reg_reg(opcode,opsize,
operands[1].opr.reg,operands[2].opr.reg,operands[3].opr.reg));
end;
end
else
Message(asmr_e_invalid_opcode_and_operand);
end;
end; { end case }
end;
if assigned(result) then
p.concat(result);
end;
}
function TM68kInstruction.ConcatLabeledInstr(p : TAsmList):tai;
begin
if ((opcode >= A_BCC) and (opcode <= A_BVS)) or
(opcode = A_BRA) or (opcode = A_BSR) or
(opcode = A_JMP) or (opcode = A_JSR) or
((opcode >= A_FBEQ) and (opcode <= A_FBNGLE)) then
begin
if ops > 2 then
Message(asmr_e_invalid_opcode_and_operand)
else if operands[1].opr.typ <> OPR_SYMBOL then
Message(asmr_e_invalid_opcode_and_operand)
else if (operands[1].opr.typ = OPR_SYMBOL) and
(ops = 1) then
if assigned(operands[1].opr.symbol) and
(operands[1].opr.symofs=0) then
result:=taicpu.op_sym(opcode,S_NO,
operands[1].opr.symbol)
else
Message(asmr_e_invalid_opcode_and_operand);
end
else if ((opcode >= A_DBCC) and (opcode <= A_DBF))
or ((opcode >= A_FDBEQ) and (opcode <= A_FDBNGLE)) then
begin
if (ops<>2) or
(operands[1].opr.typ <> OPR_REGISTER) or
(operands[2].opr.typ <> OPR_SYMBOL) or
(operands[2].opr.symofs <> 0) then
Message(asmr_e_invalid_opcode_and_operand)
else
result:=taicpu.op_reg_sym(opcode,opsize,operands[1].opr.reg,
operands[2].opr.symbol);
end
else
Message(asmr_e_invalid_opcode_and_operand);
if assigned(result) then
p.concat(result);
end;
end.
|