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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
|
/* lkmain.c */
/*
* Copyright (C) 1989-2009 Alan R. Baldwin
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*
* Alan R. Baldwin
* 721 Berkeley St.
* Kent, Ohio 44240
*/
#include "aslink.h"
/*)Module lkmain.c
*
* The module lkmain.c contains the functions which
* (1) input the linker options, parameters, and specifications
* (2) perform a two pass link
* (3) produce the appropriate linked data output and/or
* link map file and/or relocated listing files.
*
* lkmain.c contains the following functions:
* FILE * afile()
* VOID bassav()
* VOID gblsav()
* int intsiz()
* VOID link_main()
* VOID lkexit()
* int fndext()
* int fndidx()
* int main()
* VOID map()
* int parse()
* VOID doparse()
* VOID setgbl()
* VOID usage()
*
* lkmain.c contains the following local variables:
* char * usetext[] array of pointers to the
* command option tect lines
*
*/
/* sdld 8051 specific */
/*JCF: Creates some of the default areas so they are allocated in the right order.*/
void Areas51 (void)
{
char * rel[] = {
"XH",
"H 7 areas 0 global symbols",
"A _CODE size 0 flags 0", /*Each .rel has one, so...*/
"A REG_BANK_0 size 0 flags 4", /*Register banks are overlayable*/
"A REG_BANK_1 size 0 flags 4",
"A REG_BANK_2 size 0 flags 4",
"A REG_BANK_3 size 0 flags 4",
"A BSEG size 0 flags 80", /*BSEG must be just before BITS*/
"A BSEG_BYTES size 0 flags 0", /*Size will be obtained from BSEG in lnkarea()*/
""
};
char * rel2[] = {
"XH",
"H C areas 0 global symbols",
"A _CODE size 0 flags 0", /*Each .rel has one, so...*/
"A REG_BANK_0 size 0 flags 4", /*Register banks are overlayable*/
"A REG_BANK_1 size 0 flags 4",
"A REG_BANK_2 size 0 flags 4",
"A REG_BANK_3 size 0 flags 4",
"A BSEG size 0 flags 80", /*BSEG must be just before BITS*/
"A BSEG_BYTES size 0 flags 0", /*Size will be obtained from BSEG in lnkarea()*/
"A BIT_BANK size 0 flags 4", /*Bit register bank is overlayable*/
"A DSEG size 0 flags 0",
"A OSEG size 0 flags 4",
"A ISEG size 0 flags 0",
"A SSEG size 0 flags 4",
""
};
int j;
struct sym * sp;
if (packflag) {
for (j = 0; rel2[j][0] != 0; j++) {
ip = rel2[j];
link_main();
}
}
else {
for (j = 0; rel[j][0] != 0; j++) {
ip = rel[j];
link_main();
}
}
/*Set the start address of the default areas:*/
for (ap = areap; ap; ap = ap->a_ap) {
/**/ if (!strcmp(ap->a_id, "REG_BANK_0")) { ap->a_addr = 0x00; ap->a_bset = 1; }
else if (!strcmp(ap->a_id, "REG_BANK_1")) { ap->a_addr = 0x08; ap->a_bset = 1; }
else if (!strcmp(ap->a_id, "REG_BANK_2")) { ap->a_addr = 0x10; ap->a_bset = 1; }
else if (!strcmp(ap->a_id, "REG_BANK_3")) { ap->a_addr = 0x18; ap->a_bset = 1; }
else if (!strcmp(ap->a_id, "BSEG_BYTES")) { ap->a_addr = 0x20; ap->a_bset = 1; }
else if (TARGET_IS_8051 && !strcmp(ap->a_id, "SSEG")) {
if (stacksize) ap->a_axp->a_size = stacksize;
}
}
sp = lkpsym("l_IRAM", 1);
sp->s_addr = ((iram_size>0) && (iram_size<=0x100)) ? iram_size : 0x0100;
sp->s_axp = NULL;
sp->s_type |= S_DEF;
}
/* end sdld 8051 specific */
/*)Function int main(argc,argv)
*
* int argc number of command line arguments + 1
* char * argv[] array of pointers to the command line
* arguments
*
* The function main() evaluates the command line arguments to
* determine if the linker parameters are to input through 'stdin'
* or read from a command file. The functions nxtline() and parse()
* are to input and evaluate the linker parameters. The linking process
* proceeds by making the first pass through each .rel file in the order
* presented to the linker. At the end of the first pass the setarea(),
* lnkarea(), setgbl(), and symdef() functions are called to evaluate
* the base address terms, link all areas, define global variables,
* and look for undefined symbols. Following these routines a linker
* map file may be produced and the linker output files may be opened.
* The second pass through the .rel files will output the linked data
* in one of the supported formats.
*
* local variables:
* int c character from argument string
* int i loop counter
* int j loop counter
* int k loop counter
*
* global variables:
* text line in ib[]
* lfile *cfp The pointer *cfp points to the
* current lfile structure
* char ctype[] array of character types, one per
* ASCII character
* lfile *filep The pointer *filep points to the
* beginning of a linked list of
* lfile structures.
* head *hp Pointer to the current
* head structure
* char ib[NINPUT] .rel file text line
* char *ip pointer into the .rel file
* lfile *linkp pointer to first lfile structure
* containing an input .rel file
* specification
* int lkerr error flag
* int oflag Output file type flag
* int objflg Linked file/library output object flag
* int pass linker pass number
* int pflag print linker command file flag
* int radix current number conversion radix
* FILE *sfp The file handle sfp points to the
* currently open file
* lfile *startp aslink startup file structure
* FILE * stdout c_library
*
* functions called:
* VOID chkbank() lkbank.c
* int fclose() c_library
* int fprintf() c_library
* VOID library() lklibr.c
* VOID link_main() lkmain.c
* VOID lkexit() lkmain.c
* VOID lkfopen() lkbank.c
* VOID lnkarea() lkarea.c
* VOID map() lkmain.c
* VOID new() lksym.c
* int nxtline() lklex.c
* int parse() lkmain.c
* VOID reloc() lkreloc.c
* VOID search() lklibr.c
* VOID setarea() lkarea.c
* VOID setbank() lkbank.c
* VOID setgbl() lkmain.c
* char * sprintf() c_library
* VOID symdef() lksym.c
* VOID usage() lkmain.c
* int fndidx() lkmain.c
*
* side effects:
* Completion of main() completes the linking process
* and may produce a map file (.map) and/or a linked
* data files (.ihx or .s19) and/or one or more
* relocated listing files (.rst).
*/
int
main(int argc, char *argv[])
{
int c, i, j, k;
if (intsiz() < 4) {
fprintf(stderr, "?ASlink-Error-Size of INT32 is not 32 bits or larger.\n\n");
exit(ER_FATAL);
}
/* sdas specific */
/* sdas initialization */
sdld_init(argv[0]);
/* use these defaults for parsing the .lnk script */
a_bytes = 4;
a_mask = 0xFFFFFFFF;
s_mask = 0x80000000;
v_mask = 0x7FFFFFFF;
/* end sdas specific */
if (!is_sdld())
fprintf(stdout, "\n");
startp = (struct lfile *) new (sizeof (struct lfile));
startp->f_idp = "";
pflag = 1;
for(i=1; i<argc; i++) {
ip = ib;
if(argv[i][0] == '-') {
j = i;
k = 1;
while((c = argv[j][k]) != '\0') {
ip = ib;
sprintf(ip, "-%c", c);
switch(c) {
/*
* Options with arguments
*/
case 'b':
case 'B':
case 'g':
case 'G':
case 'k':
case 'K':
case 'l':
case 'L':
case 'f':
case 'F':
case 'I':
case 'X':
case 'C':
case 'S':
strcat(ip, " ");
if (i < argc - 1)
strcat(ip, argv[++i]);
else
strcpy(ip, "");
break;
/*
* Preprocess these commands
*/
case 'n':
case 'N':
pflag = 0;
break;
case 'p':
case 'P':
pflag = 1;
break;
/*
* Options without arguments
*/
default:
break;
}
if(pflag)
fprintf(stdout, "ASlink >> %s\n", ip);
parse();
k++;
}
} else {
strcpy(ip, argv[i]);
if(pflag)
fprintf(stdout, "ASlink >> %s\n", ip);
parse();
}
}
if (linkp == NULL)
usage(ER_FATAL);
/*
* If no input file is specified
* then assume a single file with
* the same name as the output file.
*/
if (lfp == linkp) {
lfp->f_flp = (struct lfile *) new (sizeof (struct lfile));
lfp = lfp->f_flp;
lfp->f_idp = strsto(linkp->f_idp);
lfp->f_idx = fndidx(linkp->f_idp);
lfp->f_obj = objflg;
lfp->f_type = F_REL;
}
syminit();
#if SDCDB
/*
* Open SDCC Debug output file
*/
SDCDBfopen();
#endif
for (pass=0; pass<2; ++pass) {
cfp = NULL;
sfp = NULL;
filep = linkp->f_flp;
hp = NULL;
radix = 10;
/* sdld specific */
if (TARGET_IS_8051)
Areas51(); /*JCF: Create the default 8051 areas in the right order*/
/* end sdld specific */
while (nxtline()) {
ip = ib;
link_main();
}
if (pass == 0) {
/*
* Search libraries for global symbols
*/
search();
/* sdas specific */
/* use these defaults for parsing the .lk script */
a_bytes = 4;
a_mask = 0xFFFFFFFF;
s_mask = 0x80000000;
v_mask = 0x7FFFFFFF;
/* end sdas specific */
/*
* Set area base addresses.
*/
setarea();
/*
* Set bank base addresses.
*/
setbank();
/*
* Link all area addresses.
*/
if (!packflag)
lnkarea();
else {
/* sdld 8051 specific */
lnkarea2();
/* end sdld 8051 specific */
}
/*
* Check bank size limits.
*/
chkbank(stderr);
/*
* Process global definitions.
*/
setgbl();
/*
* Check for undefined globals.
*/
symdef(stderr);
#if NOICE
/*
* Open NoICE output file
*/
NoICEfopen();
#endif
/*
* Output Link Map.
*/
map();
/* sdld specific */
if (sflag) { /*JCF: memory usage summary output*/
if (!packflag) {
if (summary(areap)) lkexit(1);
}
else {
/* sdld 8051 specific */
if (summary2(areap)) lkexit(1);
/* end sdld 8051 specific */
}
}
if ((iram_size) && (!packflag))
iramcheck();
/* end sdld specific */
/*
* Open output file(s)
*/
lkfopen();
} else {
/*
* Link in library files
*/
library();
/*
* Complete Processing
*/
reloc('E');
}
}
if (TARGET_IS_PDK && get_sdld_target() != TARGET_ID_PDK) {
unsigned ram = 0;
unsigned rom = 0;
for (struct area *it = areap; it; it = it->a_ap) {
if (!strcmp(it->a_id, "DATA") ||
!strcmp(it->a_id, "OSEG")) {
if (it->a_addr + it->a_size > ram) {
ram = it->a_addr + it->a_size;
}
} else if (!strcmp(it->a_id, "CODE") ||
!strcmp(it->a_id, "CONST")) {
if (it->a_addr + it->a_size > rom) {
rom = it->a_addr + it->a_size;
}
}
}
enum sdld_target_e target = get_sdld_target();
const unsigned max_ram =
target == TARGET_ID_PDK13 ? 64 :
target == TARGET_ID_PDK14 ? 128 : 256;
const unsigned max_rom =
target == TARGET_ID_PDK13 ? 2048 :
target == TARGET_ID_PDK14 ? 4096 : 8192;
if (ram > max_ram) {
fprintf(stderr,
"?ASlink-Warning-"
"RAM value %u too large "
"(%uB max)\n", ram, max_ram);
}
if (rom > max_rom) {
fprintf(stderr,
"?ASlink-Warning-"
"ROM value %u too large "
"(%uW max)\n", rom / 2, max_rom / 2);
}
}
if (TARGET_IS_8051) {
//JCF:
CreateAOMF51();
}
lkexit(lkerr ? ER_ERROR : ER_NONE);
return(0);
}
/*)Function int intsiz()
*
* The function intsiz() returns the size of INT32
*
* local variables:
* none
*
* global variables:
* none
*
* functions called:
* none
*
* side effects:
* none
*/
int
intsiz()
{
return(sizeof(a_uint));
}
/*)Function VOID lkexit(i)
*
* int i exit code
*
* The function lkexit() explicitly closes all open
* files and then terminates the program.
*
* local variables:
* none
*
* global variables:
* FILE * jfp file handle for .noi
* FILE * mfp file handle for .map
* FILE * rfp file hanlde for .rst
* FILE * sfp file handle for .rel
* FILE * tfp file handle for .lst
*
* functions called:
* int fclose() c_library
* VOID exit() c_library
* VOID lkfclose() lkbank.c
*
* side effects:
* All files closed. Program terminates.
*/
VOID
lkexit(i)
int i;
{
lkfclose();
#if NOICE
if (jfp != NULL) fclose(jfp);
#endif
if (mfp != NULL) fclose(mfp);
if (rfp != NULL) fclose(rfp);
if (sfp != NULL) { if (sfp != stdin) fclose(sfp); }
if (tfp != NULL) fclose(tfp);
#if SDCDB
if (yfp != NULL) fclose(yfp);
#endif
exit(i);
}
/*)Function link_main()
*
* The function link_main() evaluates the directives for each line of
* text read from the .rel file(s). The valid directives processed
* are:
* X, D, Q, H, M, A, S, T, R, and P.
*
* local variables:
* int c first non blank character of a line
*
* global variables:
* head *headp The pointer to the first
* head structure of a linked list
* head *hp Pointer to the current
* head structure
* int a_bytes T Line address bytes
* int hilo Byte ordering
* int pass linker pass number
* int radix current number conversion radix
*
* functions called:
* char endline() lklex.c
* VOID module() lkhead.c
* VOID newarea() lkarea.c
* VOID newhead() lkhead.c
* sym * newsym() lksym.c
* VOID NoICEmagic() lknoice.c
* VOID reloc() lkreloc.c
*
* side effects:
* Head, area, and symbol structures are created and
* the radix is set as the .rel file(s) are read.
*/
VOID
link_main()
{
char c;
if ((c=endline()) == 0) { return; }
switch (c) {
/* sdld specific */
case 'O': /* For some important sdcc options */
if (is_sdld() && pass == 0) {
if (NULL == optsdcc) {
optsdcc = strsto(&ip[1]);
optsdcc_module = hp->m_id;
}
else {
if (strcmp(optsdcc, &ip[1]) != 0) {
fprintf(stderr,
"?ASlink-Warning-Conflicting sdcc options:\n"
" \"%s\" in module \"%s\" and\n"
" \"%s\" in module \"%s\".\n",
optsdcc, optsdcc_module, &ip[1], hp->m_id);
lkerr++;
}
}
}
break;
/* end sdld specific */
case 'X':
case 'D':
case 'Q':
ASxxxx_VERSION = 3;
a_bytes = 2; /* use default if unspecified */
hilo = 0; /* use default if unspecified */
if (c == 'X') { radix = 16; } else
if (c == 'D') { radix = 10; } else
if (c == 'Q') { radix = 8; }
while ((c = get()) != 0) {
switch(c) {
case 'H':
hilo = 1;
break;
case 'L':
hilo = 0;
break;
case '2':
a_bytes = 2;
break;
case '3':
a_bytes = 3;
break;
case '4':
a_bytes = 4;
break;
default:
break;
}
}
#ifdef LONGINT
switch(a_bytes) {
default:
a_bytes = 2;
case 2:
a_mask = 0x0000FFFFl;
s_mask = 0x00008000l;
v_mask = 0x00007FFFl;
break;
case 3:
a_mask = 0x00FFFFFFl;
s_mask = 0x00800000l;
v_mask = 0x007FFFFFl;
break;
case 4:
a_mask = 0xFFFFFFFFl;
s_mask = 0x80000000l;
v_mask = 0x7FFFFFFFl;
break;
}
#else
switch(a_bytes) {
default:
a_bytes = 2;
case 2:
a_mask = 0x0000FFFF;
s_mask = 0x00008000;
v_mask = 0x00007FFF;
break;
case 3:
a_mask = 0x00FFFFFF;
s_mask = 0x00800000;
v_mask = 0x007FFFFF;
break;
case 4:
a_mask = 0xFFFFFFFF;
s_mask = 0x80000000;
v_mask = 0x7FFFFFFF;
break;
}
#endif
break;
case 'H':
if (pass == 0) {
newhead();
} else {
if (hp == 0) {
hp = headp;
} else {
hp = hp->h_hp;
}
}
sdp.s_area = NULL;
sdp.s_areax = NULL;
sdp.s_addr = 0;
break;
case 'M':
if (pass == 0)
module();
break;
case 'A':
if (pass == 0)
newarea();
if (sdp.s_area == NULL) {
sdp.s_area = areap;
sdp.s_areax = areap->a_axp;
sdp.s_addr = 0;
}
break;
case 'S':
if (pass == 0)
newsym();
break;
case 'T':
case 'R':
case 'P':
if (pass == 0)
break;
reloc(c);
break;
#if NOICE
case ';':
unget(c);
NoICEmagic();
break;
#endif
default:
break;
}
}
/*)Function VOID map()
*
* The function map() opens the output map file and calls the various
* routines to
* (1) output the variables in each area,
* (2) list the files processed with module names,
* (3) list the libraries file processed,
* (4) list base address definitions,
* (5) list global variable definitions, and
* (6) list any undefined variables.
*
* local variables:
* int i counter
* head * hdp pointer to head structure
* lbfile *lbfh pointer to library file structure
*
* global variables:
* area *ap Pointer to the current
* area structure
* area *areap The pointer to the first
* area structure of a linked list
* base *basep The pointer to the first
* base structure
* base *bsp Pointer to the current
* base structure
* lfile *filep The pointer *filep points to the
* beginning of a linked list of
* lfile structures.
* globl *globlp The pointer to the first
* globl structure
* globl *gsp Pointer to the current
* globl structure
* head *headp The pointer to the first
* head structure of a linked list
* lbfile *lbfhead The pointer to the first
* lbfile structure of a linked list
* lfile *linkp pointer to first lfile structure
* containing an input REL file
* specification
* int lop current line number on page
* int mflag Map output flag
* FILE *mfp Map output file handle
* int page current page number
*
* functions called:
* FILE * afile() lkmain.c
* int fprintf() c_library
* VOID lkexit() lkmain.c
* VOID lstarea() lklist.c
* VOID newpag() lklist.c
* VOID chkbank() lkbank.c
* VOID symdef() lksym.c
*
* side effects:
* The map file is created.
*/
VOID
map(void)
{
int i;
struct head *hdp;
struct lbfile *lbfh;
if (mflag == 0) return;
/*
* Open Map File
*/
mfp = afile(linkp->f_idp, "map", 1);
if (mfp == NULL) {
lkexit(ER_FATAL);
}
/*
* Output Map Bank/Area Lists
*/
page = 0;
lop = NLPP;
for (bp = bankp; bp != NULL; bp = bp->b_bp) {
for (ap = areap; ap != NULL; ap = ap->a_ap) {
if (ap->a_bp == bp)
lstarea(ap, bp);
}
}
/*
* List Linked Files
*/
newpag(mfp);
fprintf(mfp, "\nFiles Linked [ module(s) ]\n\n");
hdp = headp;
filep = linkp->f_flp;
while (filep) {
if (strlen (filep->f_idp) > 40)
fprintf(mfp, "%s\n%40s [ ", filep->f_idp, "");
else
fprintf(mfp, "%-40.40s [ ", filep->f_idp);
i = 0;
while ((hdp != NULL) && (hdp->h_lfile == filep)) {
if (i)
fprintf(mfp, ",\n%44s", "");
fprintf(mfp, "%-.32s", hdp->m_id);
hdp = hdp->h_hp;
i++;
}
fprintf(mfp, " ]\n");
filep = filep->f_flp;
}
fprintf(mfp, "\n");
/*
* List Linked Libraries
*/
if (lbfhead != NULL) {
fprintf(mfp, "\nLibraries Linked [ object file ]\n\n");
for (lbfh=lbfhead; lbfh; lbfh=lbfh->next) {
if (strlen (lbfh->libspc) > 40)
fprintf(mfp, "%s\n%40s [ %-.32s ]\n",
lbfh->libspc, "", lbfh->relfil);
else
fprintf(mfp, "%-40.40s [ %-.32s ]\n",
lbfh->libspc, lbfh->relfil);
}
fprintf(mfp, "\n");
}
/*
* List Base Address Definitions
*/
if (basep) {
newpag(mfp);
fprintf(mfp, "\nUser Base Address Definitions\n\n");
bsp = basep;
while (bsp) {
fprintf(mfp, "%s\n", bsp->b_strp);
bsp = bsp->b_base;
}
}
/*
* List Global Definitions
*/
if (globlp) {
newpag(mfp);
fprintf(mfp, "\nUser Global Definitions\n\n");
gsp = globlp;
while (gsp) {
fprintf(mfp, "%s\n", gsp->g_strp);
gsp = gsp->g_globl;
}
}
fprintf(mfp, "\n\f");
chkbank(mfp);
symdef(mfp);
}
/*)Function int parse()
*
* The function parse() evaluates all command line or file input
* linker directives and updates the appropriate variables.
*
* local variables:
* int c character value
* int sv_type save type of processing
* char fid[] file id string
*
* global variables:
* char ctype[] array of character types, one per
* ASCII character
* lfile *lfp pointer to current lfile structure
* being processed by parse()
* lfile *linkp pointer to first lfile structure
* containing an input REL file
* specification
* int mflag Map output flag
* int oflag Output file type flag
* int objflg Linked file/library output object flag
* int pflag print linker command file flag
* FILE * stderr c_library
* int uflag Relocated listing flag
* int xflag Map file radix type flag
* int wflag Wide listing format
* int zflag Disable symbol case sensitivity
*
* Functions called:
* VOID addlib() lklibr.c
* VOID addpath() lklibr.c
* VOID bassav() lkmain.c
* VOID doparse() lkmain.c
* int fprintf() c_library
* VOID gblsav() lkmain.c
* VOID getfid() lklex.c
* int get() lklex.c
* int getnb() lklex.c
* VOID lkexit() lkmain.c
* char * strsto() lksym.c
* int strlen() c_library
* int fndidx() lkmain.c
*
* side effects:
* Various linker flags are updated and the linked
* structure lfile is created.
*/
int
parse()
{
int c;
int sv_type;
char fid[NINPUT];
while ((c = getnb()) != 0) {
/* sdld specific */
if ( c == ';')
return(0);
/* end sdld specific */
if ( c == '-') {
while (ctype[c=get()] & LETTER) {
switch(c) {
case 'C':
if (is_sdld() && !(TARGET_IS_Z80 || TARGET_IS_GB)) {
codesav();
return(0);
}
// else fall through
case 'c':
if (startp->f_type != 0)
break;
startp->f_type = F_STD;
doparse();
return(0);
case 'f':
case 'F':
if (startp->f_type == F_LNK)
return(0);
unget(getnb());
if (*ip == 0)
usage(ER_FATAL);
sv_type = startp->f_type;
startp->f_idp = strsto(ip);
startp->f_idx = fndidx(ip);
startp->f_type = F_LNK;
doparse();
if (sv_type == F_STD) {
cfp = NULL;
sfp = NULL;
startp->f_type = F_STD;
filep = startp;
}
return(0);
case 'I':
if (is_sdld() && !(TARGET_IS_Z80 || TARGET_IS_GB)) {
iramsav();
return(0);
}
// else fall through
case 'i':
oflag = 1;
break;
case 'S':
if (TARGET_IS_8051) {
unget(getnb());
if (ip && *ip)
{
stacksize = expr(0);
if (stacksize > 256) stacksize = 256;
else if (stacksize < 0) stacksize = 0;
}
return(0);
}
// else fall through
case 's':
oflag = 2;
break;
case 't':
case 'T':
oflag = 3;
break;
case 'o':
case 'O':
objflg = 0;
break;
case 'v':
case 'V':
objflg = 1;
break;
case 'M':
/*JCF: memory usage summary output*/
if (is_sdld()) {
sflag = 1;
break;
}
// else fall through
case 'm':
mflag = 1;
break;
#if NOICE
case 'j':
case 'J':
jflag = 1;
break;
#endif
case 'r':
case 'R':
if (is_sdld() && !(TARGET_IS_Z80 || TARGET_IS_GB))
rflag = 1;
else
goto err;
break;
case 'u':
case 'U':
uflag = 1;
break;
case 'X':
if (is_sdld() && !(TARGET_IS_Z80 || TARGET_IS_GB)) {
xramsav();
return(0);
}
// else fall through
case 'x':
xflag = 0;
break;
case 'q':
case 'Q':
xflag = 1;
break;
case 'd':
case 'D':
xflag = 2;
break;
case 'E':
if (TARGET_IS_6808 || TARGET_IS_STM8) {
oflag = 4;
break;
}
// else fall through
case 'e':
return(1);
case 'n':
case 'N':
pflag = 0;
break;
case 'p':
case 'P':
pflag = 1;
break;
case 'b':
case 'B':
bassav();
return(0);
case 'g':
case 'G':
gblsav();
return(0);
case 'k':
case 'K':
addpath();
return(0);
case 'l':
case 'L':
addlib();
return(0);
case 'w':
case 'W':
wflag = 1;
break;
#if SDCDB
case 'Y':
if (TARGET_IS_8051) {
unget(getnb());
packflag=1;
break;
}
// else fall through
case 'y':
yflag = 1;
break;
#endif
case 'z':
case 'Z':
zflag = 1;
break;
default:
err:
fprintf(stderr,
"Unknown option -%c ignored\n", c);
break;
}
}
/* sdld specific */
if ( c == ';')
return(0);
/* end sdld specific */
} else
if (!(ctype[c] & ILL)) {
if (linkp == NULL) {
linkp = (struct lfile *)
new (sizeof (struct lfile));
lfp = linkp;
lfp->f_type = F_OUT;
} else {
lfp->f_flp = (struct lfile *)
new (sizeof (struct lfile));
lfp = lfp->f_flp;
lfp->f_type = F_REL;
}
getfid(fid, c);
lfp->f_idp = strsto(fid);
lfp->f_obj = objflg;
} else {
fprintf(stderr, "Invalid input\n");
lkexit(ER_FATAL);
}
}
return(0);
}
/*)Function VOID doparse()
*
* The function doparse() evaluates all interactive
* command line or file input linker directives and
* updates the appropriate variables.
*
* local variables:
* none
*
* global variables:
* FILE * stdin standard input
* FILE * stdout standard output
* lfile *cfp The pointer *cfp points to the
* current lfile structure
* FILE *sfp The file handle sfp points to the
* currently open file
* char ib[NINPUT] .rel file text line
* char *ip pointer into the .rel file
* lfile *filep The pointer *filep points to the
* beginning of a linked list of
* lfile structures.
* lfile *startp asmlnk startup file structure
* int pflag print linker command file flag
*
* Functions called:
* int fclose() c_library
* int fprintf() c_library
* VOID getfid() lklex.c
* int nxtline() lklex.c
* int parse() lkmain.c
*
* side effects:
* Various linker flags are updated and the linked
* structure lfile may be updated.
*/
VOID
doparse()
{
cfp = NULL;
sfp = NULL;
filep = startp;
while (1) {
ip = ib;
if (nxtline() == 0)
break;
if (pflag && cfp->f_type != F_STD)
fprintf(stdout, "ASlink >> %s\n", ip);
if (*ip == 0 || parse())
break;
}
if((sfp != NULL) && (sfp != stdin)) {
fclose(sfp);
}
sfp = NULL;
startp->f_idp = "";
startp->f_idx = 0;
startp->f_type = 0;
}
/*)Function VOID bassav()
*
* The function bassav() creates a linked structure containing
* the base address strings input to the linker.
*
* local variables:
* none
*
* global variables:
* base *basep The pointer to the first
* base structure
* base *bsp Pointer to the current
* base structure
* char *ip pointer into the REL file
* text line in ib[]
*
* functions called:
* int getnb() lklex.c
* VOID * new() lksym.c
* int strlen() c_library
* char * strcpy() c_library
* VOID unget() lklex.c
*
* side effects:
* The basep structure is created.
*/
VOID
bassav()
{
if (basep == NULL) {
basep = (struct base *)
new (sizeof (struct base));
bsp = basep;
} else {
bsp->b_base = (struct base *)
new (sizeof (struct base));
bsp = bsp->b_base;
}
unget(getnb());
bsp->b_strp = (char *) new (strlen(ip)+1);
strcpy(bsp->b_strp, ip);
}
/*)Function VOID gblsav()
*
* The function gblsav() creates a linked structure containing
* the global variable strings input to the linker.
*
* local variable:
* none
*
* global variables:
* globl *globlp The pointer to the first
* globl structure
* globl *gsp Pointer to the current
* globl structure
* char *ip pointer into the REL file
* text line in ib[]
* int lkerr error flag
*
* functions called:
* int getnb() lklex.c
* VOID * new() lksym.c
* int strlen() c_library
* char * strcpy() c_library
* VOID unget() lklex.c
*
* side effects:
* The globlp structure is created.
*/
VOID
gblsav()
{
if (globlp == NULL) {
globlp = (struct globl *)
new (sizeof (struct globl));
gsp = globlp;
} else {
gsp->g_globl = (struct globl *)
new (sizeof (struct globl));
gsp = gsp->g_globl;
}
unget(getnb());
gsp->g_strp = (char *) new (strlen(ip)+1);
strcpy(gsp->g_strp, ip);
}
/*)Function VOID setgbl()
*
* The function setgbl() scans the global variable lines in the
* globlp structure, evaluates the arguments, and sets a variable
* to this value.
*
* local variables:
* int v expression value
* char id[] base id string
* sym * sp pointer to a symbol structure
*
* global variables:
* char *ip pointer into the REL file
* text line in ib[]
* globl *globlp The pointer to the first
* globl structure
* globl *gsp Pointer to the current
* globl structure
* FILE * stderr c_library
* int lkerr error flag
*
* functions called:
* a_uint expr() lkeval.c
* int fprintf() c_library
* VOID getid() lklex.c
* int getnb() lklex.c
* sym * lkpsym() lksym.c
*
* side effects:
* The value of a variable is set.
*/
VOID
setgbl()
{
int v;
struct sym *sp;
char id[NCPS];
gsp = globlp;
while (gsp) {
ip = gsp->g_strp;
getid(id, -1);
if (getnb() == '=') {
v = (int) expr(0);
sp = lkpsym(id, 0);
if (sp == NULL) {
fprintf(stderr,
"No definition of symbol %s\n", id);
lkerr++;
} else {
if (sp->s_type & S_DEF) {
fprintf(stderr,
"Redefinition of symbol %s\n", id);
lkerr++;
sp->s_axp = NULL;
}
sp->s_addr = v;
sp->s_type |= S_DEF;
}
} else {
fprintf(stderr, "No '=' in global expression");
lkerr++;
}
gsp = gsp->g_globl;
}
}
/*)Function FILE * afile(fn, ft, wf)
*
* char * fn file specification string
* char * ft file type string
* int wf 0 ==>> read
* 1 ==>> write
* 2 ==>> binary write
*
* The function afile() opens a file for reading or writing.
* (1) If the file type specification string ft
* is not NULL then a file specification is
* constructed with the file path\name in fn
* and the extension in ft.
* (2) If the file type specification string ft
* is NULL then the file specification is
* constructed from fn. If fn does not have
* a file type then the default .rel file
* type is appended to the file specification.
*
* afile() returns a file handle for the opened file or aborts
* the assembler on an open error.
*
* local variables:
* int c character value
* FILE * fp filehandle for opened file
* char * p1 pointer to filespec string fn
* char * p2 pointer to filespec string fb
* char * p3 pointer to filetype string ft
*
* global variables:
* char afspec[] constructed file specification string
* int lkerr error flag
*
* functions called:
* int fndidx() lkmain.c
* FILE * fopen() c_library
* int fprintf() c_library
*
* side effects:
* File is opened for read or write.
*/
FILE *
afile(char *fn, char *ft, int wf)
{
char *p1, *p2;
int c;
char * frmt;
FILE *fp;
if (strlen(fn) > (FILSPC-7)) {
fprintf(stderr, "?ASlink-Error-<filspc too long> : \"%s\"\n", fn);
lkerr++;
return(NULL);
}
/*
* Skip The Path
*/
strcpy(afspec, fn);
c = fndidx(afspec);
/*
* Skip to File Extension separator
*/
p1 = strrchr(&afspec[c], FSEPX);
/*
* Copy File Extension
*/
p2 = ft ? ft : "";
if (*p2 == 0) {
if (p1 == NULL) {
p2 = LKOBJEXT;
} else {
p2 = strrchr(&fn[c], FSEPX) + 1;
}
}
if (p1 == NULL) {
p1 = &afspec[strlen(afspec)];
}
*p1++ = FSEPX;
while ((c = *p2++) != 0) {
if (p1 < &afspec[FILSPC-1])
*p1++ = c;
}
*p1++ = 0;
/*
* Select Read/Write/Binary Write
*/
switch(wf) {
default:
case 0: frmt = "r"; break;
case 1: frmt = "w"; break;
#ifdef DECUS
case 2: frmt = "wn"; break;
#else
case 2: frmt = "wb"; break;
#endif
}
if ((fp = fopen(afspec, frmt)) == NULL && strcmp(ft,"adb") != 0) { /* Do not complain for optional adb files */
fprintf(stderr, "?ASlink-Error-<cannot %s> : \"%s\"\n", wf?"create":"open", afspec);
lkerr++;
}
return (fp);
}
/*)Function int fndidx(str)
*
* char * str file specification string
*
* The function fndidx() scans the file specification string
* to find the index to the file name. If the file
* specification contains a 'path' then the index will
* be non zero.
*
* fndidx() returns the index value.
*
* local variables:
* char * p1 temporary pointer
* char * p2 temporary pointer
*
* global variables:
* none
*
* functions called:
* char * strrchr() c_library
*
* side effects:
* none
*/
int
fndidx(str)
char *str;
{
char *p1, *p2;
/*
* Skip Path Delimiters
*/
p1 = str;
if ((p2 = strrchr(p1, ':')) != NULL) { p1 = p2 + 1; }
if ((p2 = strrchr(p1, '/')) != NULL) { p1 = p2 + 1; }
if ((p2 = strrchr(p1, '\\')) != NULL) { p1 = p2 + 1; }
return((int) (p1 - str));
}
/*)Function int fndext(str)
*
* char * str file specification string
*
* The function fndext() scans the file specification string
* to find the file.ext separater.
*
* fndext() returns the index to FSEPX or the end of the string.
*
* local variables:
* char * p1 temporary pointer
* char * p2 temporary pointer
*
* global variables:
* none
*
* functions called:
* char * strrchr() c_library
*
* side effects:
* none
*/
int
fndext(str)
char * str;
{
char *p1, *p2;
/*
* Find the file separator
*/
p1 = str + strlen(str);
if ((p2 = strrchr(str, FSEPX)) != NULL) { p1 = p2; }
return((int) (p1 - str));
}
/* sdld specific */
/*)Function VOID iramsav()
*
* The function iramsav() stores the size of the chip's internal RAM.
* This is used after linking to check that variable assignment to this
* dataspace didn't overflow into adjoining segments. Variables in the
* DSEG, OSEG, and ISEG are assigned to this dataspace.
*
* local variables:
* none
*
* global variables:
* char *ip pointer into the REL file
* text line in ib[]
* unsigned int size of chip's internal
* iram_size RAM segment
*
* functions called:
* int getnb() lklex.c
* VOID unget() lklex.c
* a_uint expr() lkeval.c
*
* side effects:
* The iram_size may be modified.
*/
VOID
iramsav()
{
unget(getnb());
if (ip && *ip)
iram_size = expr(0); /* evaluate size expression */
else
iram_size = 128; /* Default is 128 (0x80) bytes */
if ((iram_size<=0) || (iram_size>256))
iram_size = 128; /* Default is 128 (0x80) bytes */
}
/*Similar to iramsav but for xram memory*/
VOID
xramsav()
{
unget(getnb());
if (ip && *ip)
xram_size = expr(0); /* evaluate size expression */
else
xram_size = rflag?0x1000000:0x10000;
}
/*Similar to iramsav but for code memory*/
VOID
codesav()
{
unget(getnb());
if (ip && *ip)
code_size = expr(0); /* evaluate size expression */
else
code_size = rflag?0x1000000:0x10000;
}
/*)Function VOID iramcheck()
*
* The function iramcheck() is used at the end of linking to check that
* the internal RAM area wasn't overflowed by too many variable
* assignments. Variables in the DSEG, ISEG, and OSEG are assigned to
* the chip's internal RAM.
*
* local variables:
* none
*
* global variables:
* unsigned int size of chip's internal
* iram_size RAM segment
* struct area linked list of memory
* *areap areas
*
* functions called:
*
* side effects:
*/
VOID
iramcheck()
{
register unsigned int last_addr;
register struct area *ap;
for (ap = areap; ap; ap=ap->a_ap) {
if ((ap->a_size != 0) &&
(!strcmp(ap->a_id, "DSEG") ||
!strcmp(ap->a_id, "OSEG") ||
!strcmp(ap->a_id, "ISEG")
)
)
{
last_addr = ap->a_addr + ap->a_size - 1;
if (last_addr >= iram_size)
fprintf(stderr,
"\nWARNING! Segment %s extends past the end\n"
" of internal RAM. Check map file.\n",
ap->a_id);
}
}
}
/* end sdld specific */
char *usetxt[] = {
"Usage: [-Options] [-Option with arg] file",
"Usage: [-Options] [-Option with arg] outfile file1 [file2 ...]",
"Startup:",
" -p Echo commands to stdout (default)",
" -n No echo of commands to stdout",
"Alternates to Command Line Input:",
" -c ASlink >> prompt input",
" -f file[.lk] Command File input",
"Libraries:",
" -k Library path specification, one per -k",
" -l Library file specification, one per -l",
"Relocation:",
" -b area base address = expression",
" -g global symbol = expression",
"Map format:",
" -m Map output generated as (out)file[.map]",
" -w Wide listing format for map file",
" -x Hexadecimal (default)",
" -d Decimal",
" -q Octal",
"Output:",
" -i Intel Hex as (out)file[.ihx]",
" -s Motorola S Record as (out)file[.s19]",
// " -t Tandy CoCo Disk BASIC binary as (out)file[.bi-]",
#if NOICE
" -j NoICE Debug output as (out)file[.noi]",
#endif
#if SDCDB
" -y SDCDB Debug output as (out)file[.cdb]",
#endif
// " -o Linked file/library object output enable (default)",
// " -v Linked file/library object output disable",
"List:",
" -u Update listing file(s) with link data as file(s)[.rst]",
"Case Sensitivity:",
" -z Disable Case Sensitivity for Symbols",
"End:",
" -e or null line terminates input",
"",
0
};
char *usetxt_8051[] = {
"Usage: [-Options] [-Option with arg] file",
"Usage: [-Options] [-Option with arg] outfile file1 [file2 ...]",
"Startup:",
" -p Echo commands to stdout (default)",
" -n No echo of commands to stdout",
"Alternates to Command Line Input:",
" -c ASlink >> prompt input",
" -f file[.lk] Command File input",
"Libraries:",
" -k Library path specification, one per -k",
" -l Library file specification, one per -l",
"Relocation:",
" -b area base address = expression",
" -g global symbol = expression",
"Map format:",
" -m Map output generated as (out)file[.map]",
" -w Wide listing format for map file",
" -x Hexadecimal (default)",
" -d Decimal",
" -q Octal",
"Output:",
" -i Intel Hex as (out)file[.ihx]",
" -s Motorola S Record as (out)file[.s19]",
#if NOICE
" -j NoICE Debug output as (out)file[.noi]",
#endif
#if SDCDB
" -y SDCDB Debug output as (out)file[.cdb]",
#endif
"List:",
" -u Update listing file(s) with link data as file(s)[.rst]",
"Case Sensitivity:",
" -z Disable Case Sensitivity for Symbols",
"Miscellaneous:\n"
" -I [iram-size] Check for internal RAM overflow",
" -X [xram-size] Check for external RAM overflow",
" -C [code-size] Check for code overflow",
" -M Generate memory usage summary file[.mem]",
" -Y Pack internal ram",
" -S [stack-size] Allocate space for stack",
"End:",
" -e or null line terminates input",
"",
0
};
char *usetxt_6808[] = {
"Usage: [-Options] [-Option with arg] file",
"Usage: [-Options] [-Option with arg] outfile file1 [file2 ...]",
"Startup:",
" -p Echo commands to stdout (default)",
" -n No echo of commands to stdout",
"Alternates to Command Line Input:",
" -c ASlink >> prompt input",
" -f file[.lk] Command File input",
"Libraries:",
" -k Library path specification, one per -k",
" -l Library file specification, one per -l",
"Relocation:",
" -b area base address = expression",
" -g global symbol = expression",
"Map format:",
" -m Map output generated as (out)file[.map]",
" -w Wide listing format for map file",
" -x Hexadecimal (default)",
" -d Decimal",
" -q Octal",
"Output:",
" -i Intel Hex as (out)file[.ihx]",
" -s Motorola S Record as (out)file[.s19]",
" -E ELF executable as file[.elf]",
#if NOICE
" -j NoICE Debug output as (out)file[.noi]",
#endif
#if SDCDB
" -y SDCDB Debug output as (out)file[.cdb]",
#endif
"List:",
" -u Update listing file(s) with link data as file(s)[.rst]",
"Case Sensitivity:",
" -z Disable Case Sensitivity for Symbols",
"Miscellaneous:\n"
" -I [iram-size] Check for internal RAM overflow",
" -X [xram-size] Check for external RAM overflow",
" -C [code-size] Check for code overflow",
" -M Generate memory usage summary file[.mem]",
"End:",
" -e or null line terminates input",
"",
0
};
char *usetxt_z80_gb[] = {
"Usage: [-Options] [-Option with arg] file",
"Usage: [-Options] [-Option with arg] outfile file1 [file2 ...]",
"Startup:",
" -p Echo commands to stdout (default)",
" -n No echo of commands to stdout",
"Alternates to Command Line Input:",
" -c ASlink >> prompt input",
" -f file[.lk] Command File input",
"Libraries:",
" -k Library path specification, one per -k",
" -l Library file specification, one per -l",
"Relocation:",
" -b area base address = expression",
" -g global symbol = expression",
"Map format:",
" -m Map output generated as (out)file[.map]",
" -w Wide listing format for map file",
" -x Hexadecimal (default)",
" -d Decimal",
" -q Octal",
"Output:",
" -i Intel Hex as (out)file[.ihx]",
" -s Motorola S Record as (out)file[.s19]",
#if SDCDB
" -y SDCDB Debug output as (out)file[.cdb]",
#endif
"List:",
" -u Update listing file(s) with link data as file(s)[.rst]",
"Case Sensitivity:",
" -z Disable Case Sensitivity for Symbols",
"End:",
" -e or null line terminates input",
"",
0
};
/*)Function VOID usage(n)
*
* int n exit code
*
* The function usage() outputs to the stderr device the
* linker name and version and a list of valid linker options.
*
* local variables:
* char ** dp pointer to an array of
* text string pointers.
*
* global variables:
* FILE * stderr c_library
*
* functions called:
* int fprintf() c_library
*
* side effects:
* none
*/
VOID
usage(int n)
{
char **dp;
/* sdld specific */
fprintf(stderr, "\n%s Linker %s\n\n", is_sdld() ? "sdld" : "ASxxxx", VERSION);
for (dp = TARGET_IS_8051 ? usetxt_8051 : (TARGET_IS_6808 ? usetxt_6808 : ((TARGET_IS_Z80 || TARGET_IS_GB) ? usetxt_z80_gb : usetxt)); *dp; dp++)
fprintf(stderr, "%s\n", *dp);
/* end sdld specific */
lkexit(n);
}
/*)Function VOID copyfile()
*
* FILE *dest destination file
* FILE *src source file
*
* function will copy source file to destination file
*
*
* functions called:
* int fgetc() c_library
* int fputc() c_library
*
* side effects:
* none
*/
VOID
copyfile (FILE *dest, FILE *src)
{
int ch;
while ((ch = fgetc(src)) != EOF) {
fputc(ch,dest);
}
}
|