-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
499 lines (419 loc) · 15 KB
/
Makefile
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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
# $Id: Makefile,v 1.72 2019/10/21 10:03:39 albert Exp $
# Copyright(2000): Albert van der Horst, HCC FIG Holland by GNU Public License
#
# This defines the usage of ciforth to build assemblers and reverse
# engineering tools.
# Conventions:
# testset<arc> : a comprehensive set of opcodes plus addressing modes.
# testas<arc> : the outcome of a partical test on testset<arc>
# - it is assembled, and the code dumped
# - the result is disassembled
# Outcome:
# - the difference with testset<arc> should only be the code
# - the code should agree with what is stored.
# The mere presence of an opcode in the set, implies that the binary
# code has been checked, manually or against other assemblers.
# gset<arc> : The outcome of a SHOW-ALL.
# It must be the same than in the archive, except after a
# fix of a defect. Then it must be updated.
# It can be checked against testset<arc>. Any additions must
# be incorporated into testset<arc> and checked.
#
# This is lifted from the ciforth makefile. Some non-valid
# targets may still not be removed.
#.SUFFIXES:
#.SUFFIXES:.bin.asm.v.o.c
# Applicable suffixes : * are generated files
# + are generated files if they are mentionned on the next line
#
#* .ps : as usual (See TeX)
# .frt : text file containing Forth code
#* .bin : a binary image without header
FORTH=./lina
DIFF_TXT=diff -bBw testcmp
DIFF_BIN=diff -bBw testcmp
# The following directory are supposedly in line with the
# Debian FHS directory philosophy.
INSTALLDIR=/
INSTALLED_LAB=$(INSTALLDIR)/usr/lib/ciasdis.lab
INSTALLED_BIN=$(INSTALLDIR)/usr/bin/ciasdis
MISC_DOC= \
RCS_changelog \
README.assembler.txt \
# That's all folks!
ASTARGETS= cias cidis ciasdis test.bin test2.bin test2.asm
TESTTARGETS= test.bin lina405.asm lina405 rf751.asm rf751.cul rf751
# Generic source for assembler
# Include two pass, reverse engineering.
ASSRC= \
access.frt \
aswrap.frt \
asgen.frt \
ciasdis.frt \
crawl.frt \
labelas.frt \
labeldis.frt \
tools.frt \
# That's all folks!
# Extra source for MS os.
ASSRCCLUDGE= \
cias.frt \
cidis.frt \
# That's all folks!
# Plug ins for generic assembler
PGSRC= \
as6809.frt \
as80.frt \
asi86.frt \
asi386.frt \
asipentium.frt \
asalpha.frt \
# That's all folks!
# Test files for assemblers.
TESTSETS= \
testset386 \
testset386a \
testset6809 \
testset8080 \
testset8086 \
testsetalpha \
testsetpentium \
# That's all folks!
# asm386endtest is burned down, very early test.
# Output of running testsets, they should be the same
# as the testset itself, except for the binary code.
TESTAS= \
testas386 \
testas386a \
testas6809 \
testas80 \
testas86 \
testasalpha \
testaspentium \
# That's all folks!
# Complete small, stand alone assemblers without error detection
# for export to SBC or .lab files.
PGSRC= \
as6809s.frt \
as8086s.frt \
# That's all folks!
# Other Forth source.
# Quick reference sheet generator
UNPSRC= \
ps.frt \
# That's all folks!
# Consult files for general use
CUL= \
elf.cul \
exeheader.cul \
# That's all folks!
# Documentation files and archives
# Formally forth.lab is for error messages, but
# you can load debug tools from it too.
DOC = \
COPYING \
forth.lab \
cul.5 \
ciasdis.1 \
README.assembler \
assembler.txt \
p0.asi386.ps \
p0F.asi386.ps \
qr8086.ps \
qr8080.ps \
# That's all folks!
# Test files for reverse engineering and two pass.
TESTRV= \
test.asm \
test.cul \
lina405 \
linacrawl.cul \
lina405equ.cul \
lina405.cul \
# That's all folks!
RELEASEASSEMBLER= \
Makefile \
$(ASSRC) \
$(PGSRC) \
$(UNPSRC) \
$(CUL) \
$(DOC) \
$(TESTRV) \
# That's all folks!
RELEASECONTENT = \
COPYING \
README.assembler \
ciasdis.1 \
cul.5 \
$(ASSRC) \
# That's all folks!
BINRELEASE = \
COPYING \
README.assembler \
ciasdis.1 \
cul.5 \
ciasdis \
ciasdis.lab \
# That's all folks!
# 4.0 ### Version : an official release 4.0
# Left out : beta, revision number is taken from rcs e.g. 3.154
VERSION= # Because normally VERSION is passed via the command line.
TEMPFILE=/tmp/ciforthscratch
MASK=FF
PREFIX=0
TITLE=QUICK REFERENCE PAGE FOR 80386 ASSEMBLER
DEBIANFILES=control
# How to check out, anything
%:RCS/%,v
co -r$(RCSVERSION) $<
# Generate an opcode sheet for the mnemonics present in one
# assembler file, possibly a second sheet for e.g. OFxx .
%.ps : %.frt ; \
( \
echo \"INCLUDE\" WANTED \"DUMP\" WANTED ;\
cat asgen.frt $+ ps.frt ;\
echo 'PRELUDE' ;\
echo 'HEX $(MASK) MASK ! $(PREFIX) PREFIX ! DECIMAL ' ;\
echo ' "$(TITLE)" TITLE $$!' ;\
echo ' QUICK-REFERENCE BYE' \
)|\
$(FORTH) -a |\
sed '1,/SNIP TILL HERE/d' |\
cat >p$(PREFIX).$@
# sed '/SI[MB]/d' |\
# sed '/OK/d' |\
# Default target for convenience
default : ciasdis ciasdis.lab
# Install a configured binary.
# Burn in the address where the library resides in a special copy.
install_bin: ciasdis_tbi
mkdir -p $(INSTALLDIR)/usr/bin
cp $< $(INSTALLED_BIN)
install: default $(MISC_DOC) ciasdis.1 cul.5 install_bin
mkdir -p $(INSTALLDIR)/usr/lib
cp ciasdis.lab $(INSTALLED_LAB)
mkdir -p $(INSTALLDIR)/DEBIAN
cp -f control $(INSTALLDIR)/DEBIAN
mkdir -p $(INSTALLDIR)/usr/share/man/man1
mkdir -p $(INSTALLDIR)/usr/share/man/man5
cp -f ciasdis.1 $(INSTALLDIR)/usr/share/man/man1
cp -f cul.5 $(INSTALLDIR)/usr/share/man/man5
mkdir -p $(INSTALLDIR)/usr/share/doc/ciasdis
cp -f $(MISC_DOC) $(INSTALLDIR)/usr/share/doc/ciasdis
find $(INSTALLDIR) -type d | xargs chmod 755
find $(INSTALLDIR) -type f | xargs chmod 644
chmod 755 $(INSTALLDIR)/usr/bin/ciasdis
gzip -9 -r $(INSTALLDIR)/usr/share
cp -f copyright $(INSTALLDIR)/usr/share/doc/ciasdis
# If tests fails, test targets must be inspected.
.PRECIOUS: $(TESTTARGETS)
.PRECIOUS: $(TESTAS)
.PHONY: RELEASE default all clean releaseproof zip \
regressiontest regressiontest64 testexamples debian
all: regressiontest
clean: testclean install_clean
rm -f ciasdis.lab
rm -f *.bin
rm -f ciasdis_tbi*
rm -f *.ps
rm -f $(TESTTARGETS)
# How to get rid of the Debian test directory
install_clean: ; # TBS
# Get the library file to be used, trim it.
ciasdis.lab :
echo 'BLOCK-FILE $$@ GET-FILE TYPE' |\
$(FORTH) -a | sed -e '/ciforth examples \**)/,$$d' >$@
echo '( *************** ciforth examples etc. trimmed ************* )'>>$@
# Get the binary to be used, burn in the correct library.
ciasdis_tbi : $(ASSRC) asi386.frt asipentium.frt
sed -e /BLOCK-FILE/s?forth.lab?/usr/lib/ciasdis.lab? ciasdis.frt >$@.frt
$(FORTH) -c $@.frt
# Make a source distribution.
srczip : $(RELEASECONTENT) ; echo ciasdis-dev-$(VERSION).tar.gz $+ | xargs tar -cvzf
# Make a normal, binary distribution.
zip : $(BINRELEASE) ; echo ciasdis-$(VERSION).tar.gz $+ | xargs tar -cvzf
testclean: ; rm -f $(TESTAS) $(TESTTARGETS) $(ASTARGETS) gset* *.diff
# WARNING : the generation of postscript and pdf use the same files
# for indices, but with different content.
qr8080.ps :asgen.frt ps.frt as80.frt; make as80.ps TITLE='QUICK REFERENCE PAGE FOR 8080 ASSEMBLER'; mv p0.as80.ps $@
qr8086.ps :asgen.frt ps.frt asi86.frt ; make asi86.ps TITLE='QUICK REFERENCE PAGE FOR 8086 ASSEMBLER'; mv p0.asi86.ps $@
p0.asi386.ps :asgen.frt ps.frt asi386.frt; make asi386.ps PREFIX=0 MASK=FF
p0F.asi386.ps :asgen.frt ps.frt asi386.frt; make asi386.ps PREFIX=0F MASK=FFFF
p0.asipentium.ps :asgen.frt ps.frt asipentium.frt ; make asipentium.ps PREFIX=0 MASK=FF TITLE='QUICK REFERENCE PAGE FOR PENTIUM ASSEMBLER'
pD8.asipentium.ps :asgen.frt ps.frt asipentium.frt ; make asipentium.ps PREFIX=D8 MASK=FFFF TITLE='QUICK REFERENCE PAGE FOR PENTIUM ASSEMBLER'
p0F.asipentium.ps :asgen.frt ps.frt asipentium.frt ; make asipentium.ps PREFIX=0F MASK=FFFF TITLE='QUICK REFERENCE PAGE FOR PENTIUM ASSEMBLER'
pDF.asipentium.ps :asgen.frt ps.frt asipentium.frt ; make asipentium.ps PREFIX=DF MASK=FFFF TITLE='QUICK REFERENCE PAGE FOR PENTIUM ASSEMBLER'
p0.as6809.ps ::asgen.frt ps.frt as6809.frt; make as6809.ps PREFIX=00 MASK=FF
# Prototype
#p0F.asiP.ps ::asgen.frt ps.frt asiP.frt; make asiP.ps PREFIX=00 MASK=FF
showcontent : ; echo $(RELEASECONTENT)
# ------------------- TARGET TESTS ---------------------------------
# All the test<target> assemble a testset<target> with virtually
# all combinations of instructions, then disassemble then compared.
# A previous diff file is in RCS
testasalpha: asgen.frt asalpha.frt testsetalpha ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asalpha.frt INCLUDE testsetalpha |\
$(FORTH) -a |\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testsetalpha >$@.diff ;\
$(DIFF_TXT) $@.diff
testas6809: asgen.frt as6809.frt testset6809 ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE as6809.frt INCLUDE testset6809 |\
$(FORTH) -a |\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testset6809 >$@.diff ;\
$(DIFF_TXT) $@.diff
testas80: asgen.frt as80.frt testset8080 ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE as80.frt INCLUDE testset8080 |\
$(FORTH) -a|\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testset8080 >$@.diff ;\
$(DIFF_TXT) $@.diff
testas86: asgen.frt asi86.frt testset8086 ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asi86.frt INCLUDE testset8086 |\
$(FORTH) -a|\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testset8086 >$@.diff ;\
$(DIFF_TXT) $@.diff
testas386: asgen.frt asi386.frt testset386 ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asi386.frt INCLUDE testset386 |\
$(FORTH) -a|\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testset386 >$@.diff ;\
$(DIFF_TXT) $@.diff
# This is limited to pentium instructions common to all pemtiums,
# excluded those tested by testas386
testaspentium: asgen.frt asi386.frt asipentium.frt testsetpentium ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asi386.frt INCLUDE asipentium.frt INCLUDE testsetpentium | \
$(FORTH) -a|\
sed '1,/TEST STARTS HERE/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testsetpentium >$@.diff ;\
$(DIFF_TXT) $@.diff
# Special test to exercise otherwise hidden instructions.
testas386a: asgen.frt asi386.frt testset386a ; \
rm -f $@.diff ;\
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asi386.frt INCLUDE testset386a | \
$(FORTH) -a|\
sed '1,/TEST STARTS HERE/d' |\
sed '/^OK$$/d' |\
sed 's/^[0-9A-F \.,]*://' >$@ ;\
diff -w $@ testset386a >$@.diff ;\
$(DIFF_TXT) $@.diff
testasses : testasalpha testas6809 testas80 testas86 testallpentium
testallpentium : testas386 testas386a testaspentium
# ---------------------------------------
# Extra test for the precious 386 subset
gset386.diff: gset386 ; \
diff -w $+ testset386 >$@ ;\
$(DIFF_TXT) $@;\
# ------------------- generating testsets --------------------------
# Testsets are generated by the SHOW-ALL command.
# Once testsets are present, they can be used to test SHOW-ALL
gsetallpentium : gset386 gsetpentium
gsetall : gsetalpha gset6809 gset80 gset86 gset386-16 gsetallpentium
# gsetxxx contains all instruction that can be accepted.
# This can be checked against expectation. Once that is done
# it can be used as a testsetxxx.
gset386: asgen.frt asi386.frt ; \
(echo CR; cat $+;echo ASSEMBLER HEX BITS-32 SHOW-ALL)|\
$(FORTH) -a|\
sed 's/~SIB| 10 SIB,,/[DX +1* DX]/' |\
sed 's/~SIB| 18 SIB,,/[DX +1* BX]/' |\
sed 's/~SIB| 1C SIB,,/[AX +1* 0]/' |\
sed 's/~SIB| 14 SIB,,/[AX +1* BX]/'|\
grep -v ciforth >$@;\
$(DIFF_TXT) $@
gset386-16: asgen.frt asi386.frt ; \
(cat $+;echo ASSEMBLER HEX BITS-16 SHOW-ALL)|\
$(FORTH) -a >$@ ; \
$(DIFF_TXT) $@
gset6809: asgen.frt as6809.frt ; \
(cat $+;echo ASSEMBLER HEX SHOW-ALL)|\
$(FORTH) -a >$@ ;\
$(DIFF_TXT) $@
gsetalpha: asgen.frt asalpha.frt ; \
echo CR \"INCLUDE\" WANTED \"DUMP\" WANTED INCLUDE asgen.frt INCLUDE asalpha.frt ASSEMBLER HEX SHOW-ALL |\
$(FORTH) -a >$@ ; \
$(DIFF_TXT) $@
# (cat $+;echo ASSEMBLER HEX SHOW-ALL)|\
gset80: asgen.frt as80.frt ; \
(cat $+;echo ASSEMBLER HEX SHOW-ALL)|\
$(FORTH) -a >$@ ; \
$(DIFF_TXT) $@
gset86: asgen.frt asi86.frt ; \
(cat $+;echo ASSEMBLER HEX SHOW-ALL)|\
$(FORTH) -a >$@ ; \
$(DIFF_TXT) $@
gsetpentium: asgen.frt asi386.frt asipentium.frt ; \
(cat $+;echo ASSEMBLER HEX SHOW-ALL)|\
$(FORTH) -a >$@ ; \
$(DIFF_TXT) $@
# ---------------------------------------
# As by : make RELEASE VERSION=1-0-0
RELEASE: $(RELEASEASSEMBLER) cias ciasdis cidis $(ASSRCCLUDGE) ;\
echo ciasdis-$(VERSION).tgz $+ | xargs tar cfz
# Preliminary until it is clear whether we want other disassemblers.
# Note: this will use a copy of forth.lab to the local directory as ciasdis.lab
ciasdis : $(ASSRC) asi386.frt asipentium.frt version.frt; $(FORTH) -c $@.frt
cias : ciasdis ; ln -f ciasdis cias
cidis : ciasdis ; ln -f ciasdis cidis
version.frt: ; touch $@
test.bin : ciasdis cidis cias test.asm test.cul
ciasdis -a test.asm test.bin
ciasdis -d test.bin test.cul > test2.asm
ciasdis -a test2.asm test2.bin
diff test2.bin test.bin
$(DIFF_BIN) test.bin
# Cosmetic difference in 64 bit.
$(DIFF_TXT) test2.asm || true
cias test.asm test.bin
cidis test.bin test.cul > test2.asm
cias test2.asm test2.bin
diff test2.bin test.bin
$(DIFF_BIN) test.bin
# Cosmetic difference in 64 bit.
$(DIFF_TXT) test2.asm || true
lina405.asm : ciasdis lina405equ.cul lina405.cul testcmp/lina405
cp testcmp/lina405 .
ciasdis -d lina405 lina405.cul >$@
ciasdis -a $@ lina405
$(DIFF_BIN) lina405
$(DIFF_TXT) $@
# Test case, reverse engineer retroforth version 7.5.1.
rf751.cul : ciasdis rf751equ.cul rfcrawl.cul elf.cul testcmp/rf751
cp testcmp/rf751 .
echo FETCH rf751 INCLUDE rfcrawl.cul | ciasdis >$@
$(DIFF_TXT) $@
rm rf751
rf751.asm : ciasdis rf751equ.cul rf751.cul testcmp/rf751
cp testcmp/rf751 .
ciasdis -d rf751 rf751.cul >$@
$(DIFF_TXT) $@
ciasdis -a $@ rf751
$(DIFF_BIN) rf751
# The crawling fails for 64 bits, test only disassembly/assembly.
rf751-64.asm : ciasdis rf751equ.cul testcmp/rf751.cul testcmp/rf751
ciasdis -d testcmp/rf751 testcmp/rf751.cul >rf751.asm
$(DIFF_TXT) rf751.asm || true
ciasdis -a rf751.asm rf751
$(DIFF_BIN) rf751
%.bin : %.asm ; ciasdis -a $< $@
cidis386.zip : $(ASSRC) asi386.frt asipentium.frt ; zip $@ $+
testexamples : test.bin lina405.asm rf751.asm
testexamples64 : test.bin lina405.asm rf751-64.asm
# -----------------
regressiontest64 : testasses testexamples64 gsetall gset386.diff
# The real test, 64 bits misses rf751
regressiontest : testasses testexamples gsetall gset386.diff