-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
linker.c
1942 lines (1601 loc) · 38.7 KB
/
linker.c
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
/*8:*/
#line 192 "linker.w"
/*117:*/
#line 1936 "linker.w"
#include <string.h>
#include <stdlib.h>
#ifdef __linux__
#include <stdint.h>
#endif
#include <argp.h>
/*:117*/
#line 193 "linker.w"
#define GSD_MODULE_NAME 0
#define GSD_CSECT_NAME 1
#define GSD_INTERNAL_SYMBOL_NAME 2
#define GSD_TRANFER_ADDRESS 3
#define GSD_GLOBAL_SYMBOL_NAME 4
#define GSD_PSECT_NAME 5
#define GDS_IDENT 6
#define GSD_MAPPED_ARRAY 7
#define MAX_GLOBALS 1024
#define GLOBAL_WEAK_MASK 001
#define GLOBAL_DEFINITION_MASK 010
#define GLOBAL_RELOCATION_MASK 040
#define MAX_PROG_SECTIONS 254
#define PSECT_SAVE_MASK 0001
#define PSECT_ALLOCATION_MASK 0004
#define PSECT_ACCESS_MASK 0020
#define PSECT_RELOCATION_MASK 0040
#define PSECT_SCOPE_MASK 0100
#define PSECT_TYPE_MASK 0200
#define DEFAULT_SECTION_LEN 65536
#define INITIAL_SIMPLE_REF_LIST_SIZE 100
#define INITIAL_LIMIT_LIST_SIZE 5
#define RLD_CMD_INTERNAL_RELOCATION 01
#define RLD_CMD_GLOBAL_RELOCATION 02
#define RLD_CMD_INTERNAL_DISPLACED_RELOCATION 03
#define RLD_CMD_GLOBAL_DISPLACED_RELOCATION 04
#define RLD_CMD_GLOBAL_ADDITIVE_RELOCATION 05
#define RLD_CMD_GLOBAL_ADDITIVE_DISPLACED_RELOCATION 06
#define RLD_CMD_LOCATION_COUNTER_DEFINITION 07
#define RLD_CMD_LOCATION_COUNTER_MODIFICATION 010
#define RLD_CMD_PROGRAM_LIMITS 011
#define RLD_CMD_PSECT_RELOCATION 012
#define RLD_CMD_PSECT_DISPLACED_RELOCATION 014
#define RLD_CMD_PSECT_ADDITIVE_RELOCATION 015
#define RLD_CMD_PSECT_ADDITIVE_DISPLACED_RELOCATION 016
#define RLD_CMD_COMPLEX_RELOCATION 017
#define MAX_COMPLEX_TERMS 20
#define INITIAL_COMPLEX_EXPR_LIST_SIZE 10
#define CREL_OP_NONE 000
#define CREL_OP_ADDITION 001
#define CREL_OP_SUBSTRACTION 002
#define CREL_OP_MULTIPLICATION 003
#define CREL_OP_DIVISION 004
#define CREL_OP_AND 005
#define CREL_OP_OR 006
#define CREL_OP_XOR 007
#define CREL_OP_NEG 010
#define CREL_OP_COM 011
#define CREL_OP_STORE_RESULT 012
#define CREL_OP_STORE_RESULT_DISP 013
#define CREL_OP_FETCH_GLOBAL 016
#define CREL_OP_FETCH_RELOCABLE 017
#define CREL_OP_FETCH_CONSTANT 020
#define VERSION "0.6" \
#define ERR_SYNTAX 1
#define ERR_CANTOPEN 2
#define ERR_CANTCREATE 3
#line 194 "linker.w"
/*110:*/
#line 1844 "linker.w"
const char*argp_program_version= "linkbk, "VERSION;
const char*argp_program_bug_address= "<[email protected]>";
/*:110*/
#line 195 "linker.w"
/*15:*/
#line 354 "linker.w"
typedef struct _BinaryBlock{
uint8_t one;
uint8_t zero;
uint16_t len;
}BinaryBlock;
/*:15*//*20:*/
#line 473 "linker.w"
typedef struct _GSD_Entry{
uint16_t name[2];
uint8_t flags;
uint8_t type;
uint16_t value;
}GSD_Entry;
/*:20*//*24:*/
#line 548 "linker.w"
typedef struct _GSymDefEntry{
uint16_t name[2];
uint8_t flags;
uint8_t sect;
uint16_t addr;
uint8_t obj_file;
}GSymDefEntry;
/*:24*//*32:*/
#line 649 "linker.w"
typedef struct _SectionDirEntry{
uint16_t name[2];
uint8_t flags;
uint16_t start;
int32_t min_addr;
uint16_t len;
uint16_t transfer_addr;
uint16_t last_load_addr;
uint8_t*text;
}SectionDirEntry;
/*:32*//*47:*/
#line 841 "linker.w"
typedef struct _SimpleRefEntry{
uint16_t link;
uint8_t type;
uint8_t sect;
uint16_t disp;
uint16_t constant;
uint16_t name[2];
uint8_t obj_file;
}SimpleRefEntry;
typedef struct _SimpleRefList{
uint16_t avail;
uint16_t poolmin;
SimpleRefEntry*pool;
int num_allocations;
}SimpleRefList;
/*:47*//*61:*/
#line 1057 "linker.w"
typedef struct _LimListEntry{
uint16_t link;
uint8_t sect;
uint16_t disp;
}LimListEntry;
typedef struct _LimList{
LimListEntry*pool;
int num_limits;
int num_allocations;
}LimList;
/*:61*//*69:*/
#line 1146 "linker.w"
typedef struct _RLD_Entry{
struct{
uint8_t type:7;
uint8_t b:1;
}cmd;
uint8_t disp;
uint16_t value[2];
}RLD_Entry;
typedef struct _RLD_Const_Entry{
RLD_Entry ent;
uint16_t constant;
}RLD_Const_Entry;
/*:69*//*83:*/
#line 1368 "linker.w"
typedef struct _CurSectEntry{
uint16_t name[2];
uint8_t global_sect;
}CurSectEntry;
/*:83*//*88:*/
#line 1398 "linker.w"
typedef struct _ComplexTerm{
uint8_t code;
union{
uint16_t name[2];
struct{
uint8_t sect;
uint16_t disp;
}inter;
uint16_t constant;
}un;
}ComplexTerm;
typedef struct _ComplexExprEntry{
uint16_t link;
uint16_t disp;
uint8_t sect;
uint8_t obj_file;
uint8_t result_type;
uint8_t NumTerms;
ComplexTerm terms[MAX_COMPLEX_TERMS];
}ComplexExprEntry;
typedef struct _ComplexExpressionList{
uint16_t avail;
uint16_t poolmin;
uint16_t num_allocations;
ComplexExprEntry*pool;
}ComplexExpressionList;
/*:88*//*113:*/
#line 1871 "linker.w"
typedef struct _Arguments{
int verbosity;
char output_filename[FILENAME_MAX];
int max_filename_len;
char**objnames;
}Arguments;
/*:113*/
#line 196 "linker.w"
/*9:*/
#line 245 "linker.w"
static int cur_input;
static int num_start_addresses;
/*:9*//*17:*/
#line 417 "linker.w"
static uint8_t block_body[65536+1];
/*:17*//*25:*/
#line 558 "linker.w"
static GSymDefEntry GSymDef[MAX_GLOBALS];
static int NumGlobalDefs;
/*:25*//*29:*/
#line 630 "linker.w"
static int findGlobalSym(uint16_t*);
/*:29*//*33:*/
#line 660 "linker.w"
static SectionDirEntry SectDir[MAX_PROG_SECTIONS];
static int NumSections;
/*:33*//*35:*/
#line 695 "linker.w"
static int CurSect;
/*:35*//*44:*/
#line 791 "linker.w"
static int findSection(uint16_t*);
/*:44*//*48:*/
#line 859 "linker.w"
static SimpleRefList SRefList;
static int simpleRefIsEmpty(void);
/*:48*//*54:*/
#line 956 "linker.w"
static void addSimpleRef(RLD_Entry*);
static uint16_t delSimpleRef(uint16_t);
/*:54*//*60:*/
#line 1050 "linker.w"
static int resolveGlobals(void);
/*:60*//*62:*/
#line 1070 "linker.w"
static LimList LimitList;
static void addLimit(RLD_Entry*);
static void resolveLimit(void);
/*:62*//*84:*/
#line 1374 "linker.w"
static CurSectEntry curSections[MAX_PROG_SECTIONS];
static int NumCurSections;
/*:84*//*89:*/
#line 1428 "linker.w"
static ComplexExpressionList CExprList;
static int complexRefIsEmpty(void);
static void addComplexExpr(RLD_Entry*);
static uint16_t delComplexExpr(uint16_t);
/*:89*//*94:*/
#line 1503 "linker.w"
static uint16_t CurComplexExpr;
static void addComplexTerm(uint8_t,uint16_t*,uint8_t,uint16_t,uint16_t);
/*:94*//*100:*/
#line 1687 "linker.w"
static int resolveComplex(void);
static int resolveTerms(ComplexExprEntry*);
static uint16_t calcTerms(ComplexExprEntry*);
/*:100*//*106:*/
#line 1799 "linker.w"
static void handleGlobalSymbol(GSD_Entry*);
static void handleProgramSection(GSD_Entry*);
static void handleTextSection(uint8_t*,unsigned int);
static void handleRelocationDirectory(uint8_t*,int);
/*:106*//*108:*/
#line 1833 "linker.w"
static void handleOneFile(FILE*);
static void handleGSD(int);
static void fromRadix50(int,char*);
/*:108*//*111:*/
#line 1848 "linker.w"
static char argp_program_doc[]= "Link MACRO-11 object files";
static char args_doc[]= "file [...]";
/*:111*//*112:*/
#line 1860 "linker.w"
static struct argp_option options[]= {
{"output",'o',"FILENAME",0,"Output filename"},
{"verbose",'v',NULL,0,"Verbose output"},
{"length",'l',"LENGTH",0,"Max overlay file name length"},
{0}
};
static error_t parse_opt(int,char*,struct argp_state*);
static struct argp argp= {options,parse_opt,args_doc,argp_program_doc};
/*:112*//*114:*/
#line 1882 "linker.w"
static Arguments config= {0,{0},14,NULL,};
/*:114*//*118:*/
#line 1947 "linker.w"
#define PRINTVERB(level, fmt, a...) (((config.verbosity) >= level) ? printf(\
(fmt), ## a) : 0)
#define PRINTERR(fmt, a...) fprintf(stderr, (fmt), ## a)
/*:118*/
#line 197 "linker.w"
int
main(int argc,char*argv[])
{
/*10:*/
#line 249 "linker.w"
FILE*fobj,*fresult;
char ovrname[200];
/*:10*//*30:*/
#line 633 "linker.w"
char name[7];
/*:30*//*40:*/
#line 741 "linker.w"
char sect_name[7];
/*:40*/
#line 201 "linker.w"
const char*objname;
int i,j,not_resolved;
/*116:*/
#line 1924 "linker.w"
argp_parse(&argp,argc,argv,0,0,&config);
if(strlen(config.output_filename)==0){
PRINTERR("No output filename specified\n");
return(ERR_SYNTAX);
}
if(config.objnames==NULL){
PRINTERR("No input filenames specified\n");
return(ERR_SYNTAX);
}
/*:116*/
#line 205 "linker.w"
/*39:*/
#line 737 "linker.w"
NumSections= 0;
memset(SectDir,0,sizeof(SectDir));
/*:39*/
#line 206 "linker.w"
/*26:*/
#line 562 "linker.w"
NumGlobalDefs= 0;
/*:26*/
#line 207 "linker.w"
/*52:*/
#line 933 "linker.w"
SRefList.pool= (SimpleRefEntry*)malloc(sizeof(SimpleRefEntry)*
INITIAL_SIMPLE_REF_LIST_SIZE);
SRefList.num_allocations= 1;
SRefList.pool[0].link= 0;
SRefList.avail= 0;
SRefList.poolmin= 1;
/*:52*/
#line 208 "linker.w"
/*91:*/
#line 1441 "linker.w"
CExprList.pool= (ComplexExprEntry*)malloc(sizeof(ComplexExprEntry)*
INITIAL_COMPLEX_EXPR_LIST_SIZE);
CExprList.num_allocations= 1;
CExprList.pool[0].link= 0;
CExprList.avail= 0;
CExprList.poolmin= 1;
/*:91*/
#line 209 "linker.w"
/*64:*/
#line 1103 "linker.w"
LimitList.pool= (LimListEntry*)malloc(sizeof(LimListEntry)*
INITIAL_LIMIT_LIST_SIZE);
LimitList.num_allocations= 1;
LimitList.num_limits= 0;
/*:64*/
#line 210 "linker.w"
cur_input= 0;
not_resolved= 1;
num_start_addresses= 0;
while((objname= config.objnames[cur_input])!=NULL){
/*11:*/
#line 253 "linker.w"
fobj= fopen(objname,"r");
if(fobj==NULL){
PRINTERR("Can't open %s\n",objname);
return(ERR_CANTOPEN);
}
/*:11*/
#line 217 "linker.w"
handleOneFile(fobj);
not_resolved= resolveGlobals();
not_resolved+= resolveComplex();
fclose(fobj);
++cur_input;
if(num_start_addresses>=2){
PRINTERR("Too many start addresses.\n");
return(1);
}
}
if(not_resolved==0){
/*31:*/
#line 635 "linker.w"
if(config.verbosity>=1){
PRINTVERB(1,"=Global Definitions:\n");
for(i= 0;i<NumGlobalDefs;++i){
fromRadix50(GSymDef[i].name[0],name);
fromRadix50(GSymDef[i].name[1],name+3);
fromRadix50(SectDir[GSymDef[i].sect].name[0],sect_name);
fromRadix50(SectDir[GSymDef[i].sect].name[1],sect_name+3);
PRINTVERB(1,"%s: %s/%o\n",name,sect_name,
GSymDef[i].addr);
}
}
/*:31*/
#line 231 "linker.w"
/*66:*/
#line 1122 "linker.w"
resolveLimit();
/*:66*/
#line 232 "linker.w"
/*13:*/
#line 292 "linker.w"
for(i= 0;i<NumSections;++i){
if(SectDir[i].len!=0&&SectDir[i].min_addr!=-1&&
SectDir[i].transfer_addr==1&&
!(SectDir[i].flags&PSECT_SAVE_MASK)){
fromRadix50(SectDir[i].name[0],sect_name);
fromRadix50(SectDir[i].name[1],sect_name+3);
for(j= 5;j>=0;--j){
if(sect_name[j]!=' '){
sect_name[j+1]= 0;
break;
}
}
strncpy(ovrname,config.output_filename,
config.max_filename_len-strlen(sect_name)-3);
ovrname[config.max_filename_len-strlen(sect_name)-3]= '\0';
strcat(ovrname,"-");strcat(ovrname,sect_name);strcat(ovrname,".v");
fresult= fopen(ovrname,"w");
if(fresult==NULL){
PRINTERR("Can't create %s\n",ovrname);
return(ERR_CANTCREATE);
}
fwrite(SectDir[i].text+SectDir[i].min_addr,
SectDir[i].len-SectDir[i].min_addr,1,fresult);
fclose(fresult);
continue;
}
if(SectDir[i].transfer_addr!=1&&SectDir[i].len!=0){
fresult= fopen(config.output_filename,"w");
if(fresult==NULL){
PRINTERR("Can't create %s\n",config.output_filename);
return(ERR_CANTCREATE);
}
fwrite(SectDir[i].text+SectDir[i].min_addr,
SectDir[i].len-SectDir[i].min_addr,1,fresult);
fclose(fresult);
continue;
}
}
for(i= 0;i<NumSections;++i){
if(SectDir[i].flags&PSECT_SAVE_MASK){
fresult= fopen(config.output_filename,"a");
if(fresult==NULL){
PRINTERR("Can't create %s\n",config.output_filename);
return(ERR_CANTCREATE);
}
fwrite(SectDir[i].text+SectDir[i].min_addr,
SectDir[i].len-SectDir[i].min_addr,1,fresult);
fclose(fresult);
}
}
/*:13*/
#line 233 "linker.w"
}else{
/*12:*/
#line 259 "linker.w"
if(!simpleRefIsEmpty()){
printf("Unresolved simple refs:\n");
for(i= SRefList.pool[0].link;i!=0;i= SRefList.pool[i].link){
fromRadix50(SRefList.pool[i].name[0],name);
fromRadix50(SRefList.pool[i].name[1],name+3);
fromRadix50(SectDir[SRefList.pool[i].sect].name[0],sect_name);
fromRadix50(SectDir[SRefList.pool[i].sect].name[1],sect_name+3);
printf("i: %4d, name: %s, disp: %s/%o, file: %s\n",i,name,sect_name,
SRefList.pool[i].disp,config.objnames[SRefList.pool[i].obj_file]);
}
}
if(!complexRefIsEmpty()){
printf("Unresolved complex refs:\n");
for(i= CExprList.pool[0].link;i!=0;i= CExprList.pool[i].link){
for(j= 0;j<CExprList.pool[i].NumTerms;++j){
if(CExprList.pool[i].terms[j].code==
CREL_OP_FETCH_GLOBAL){
fromRadix50(CExprList.pool[i].terms[j].un.name[0],name);
fromRadix50(CExprList.pool[i].terms[j].un.name[1],
name+3);
printf("i: %4d, j: %2d, name: %s, file:"
" %s\n",i,j,name,
config.objnames[CExprList.pool[i].obj_file]);
}
}
}
}
/*:12*/
#line 235 "linker.w"
}
/*41:*/
#line 743 "linker.w"
PRINTVERB(1,"=Sections:\n");
for(i= 0;i<NumSections;++i){
fromRadix50(SectDir[i].name[0],sect_name);
fromRadix50(SectDir[i].name[1],sect_name+3);
PRINTVERB(1,"%s, addr: %p, len: %o, min addr: %o,"
" current start: %o\n",sect_name,
SectDir[i].text,SectDir[i].len,SectDir[i].min_addr,
SectDir[i].start);
if(SectDir[i].text!=NULL)
free(SectDir[i].text);
}
/*:41*/
#line 237 "linker.w"
/*92:*/
#line 1449 "linker.w"
if(config.verbosity>=2){
PRINTVERB(2,"=Complex Refs:\n avail: %d, poolmin: %d\n",
CExprList.avail,CExprList.poolmin);
for(i= CExprList.pool[0].link;i!=0;i= CExprList.pool[i].link){
fromRadix50(SectDir[CExprList.pool[i].sect].name[0],sect_name);
fromRadix50(SectDir[CExprList.pool[i].sect].name[1],sect_name+3);
PRINTVERB(2,"i: %4d, disp: %s/%o, file: %s\n",i,sect_name,
CExprList.pool[i].disp,config.objnames[CExprList.pool[i].obj_file]);
}
}
free(CExprList.pool);
/*:92*/
#line 238 "linker.w"
/*53:*/
#line 941 "linker.w"
if(config.verbosity>=2){
PRINTVERB(2,"=Simple Refs:\n avail: %d, poolmin: %d\n",
SRefList.avail,SRefList.poolmin);
for(i= SRefList.pool[0].link;i!=0;i= SRefList.pool[i].link){
fromRadix50(SRefList.pool[i].name[0],name);
fromRadix50(SRefList.pool[i].name[1],name+3);
fromRadix50(SectDir[SRefList.pool[i].sect].name[0],sect_name);
fromRadix50(SectDir[SRefList.pool[i].sect].name[1],sect_name+3);
PRINTVERB(2,"i: %4d, name: %s, disp: %s/%o, file: %s\n",i,name,sect_name,
SRefList.pool[i].disp,config.objnames[SRefList.pool[i].obj_file]);
}
}
free(SRefList.pool);
/*:53*/
#line 239 "linker.w"
/*65:*/
#line 1109 "linker.w"
if(config.verbosity>=2){
PRINTVERB(2,"=Limit Refs:\n num_limits: %d\n",
LimitList.num_limits);
for(i= 0;i<LimitList.num_limits;++i){
fromRadix50(SectDir[LimitList.pool[i].sect].name[0],sect_name);
fromRadix50(SectDir[LimitList.pool[i].sect].name[1],sect_name+3);
PRINTVERB(2,"i: %4d, disp: %s/%o\n",i,sect_name,
LimitList.pool[i].disp);
}
}
free(LimitList.pool);
/*:65*/
#line 240 "linker.w"
return(not_resolved);
}
/*:8*//*16:*/
#line 363 "linker.w"
static void
handleOneFile(FILE*fobj){
BinaryBlock obj_header;
int first_byte,i;
int crc;
unsigned int block_len;
char name[7];
/*85:*/
#line 1378 "linker.w"
NumCurSections= 0;
/*:85*/
#line 372 "linker.w"
while(!feof(fobj)){
do{
first_byte= fgetc(fobj);
if(first_byte==EOF)goto end;
}while(first_byte!=1);
ungetc(first_byte,fobj);
if(fread(&obj_header,sizeof(BinaryBlock),1,fobj)!=1){
PRINTERR("IO error while read header: %s\n",config.objnames[cur_input]);
exit(EXIT_FAILURE);
}
if(obj_header.zero!=0)continue;
block_len= obj_header.len-4;
PRINTVERB(2,"Binary block found. Length:%o\n",block_len);
if(obj_header.len==0){
PRINTERR("Block len = 0: %s\n",config.objnames[cur_input]);
exit(EXIT_FAILURE);
}
if(fread(block_body,block_len+1,1,fobj)!=1){
PRINTERR("IO error while read block: %s\n",config.objnames[cur_input]);
exit(EXIT_FAILURE);
}
crc= -obj_header.one-obj_header.zero-obj_header.len%256
-obj_header.len/256;
for(i= 0;(uint16_t)i<block_len;++i){
crc-= block_body[i];
}
crc&= 0xff;
if(crc!=block_body[block_len]){
PRINTERR("Bad block checksum: %s\n",config.objnames[cur_input]);
exit(EXIT_FAILURE);
}
/*18:*/
#line 421 "linker.w"
PRINTVERB(2," Block type: %o, ",block_body[0]);
switch(block_body[0]){
case 1:
PRINTVERB(2,"GSD\n");
/*19:*/
#line 471 "linker.w"
handleGSD(block_len);
/*:19*/
#line 426 "linker.w"
break;
case 2:
PRINTVERB(2,"ENDGSD\n");
/*87:*/
#line 1384 "linker.w"
PRINTVERB(2,"=Sections recoding.\n");
for(i= 0;i<NumCurSections;++i){
fromRadix50(curSections[i].name[0],name);
fromRadix50(curSections[i].name[1],name+3);
PRINTVERB(2,"sect: %3d, %s, global sect: %d\n",i,name,
curSections[i].global_sect);
}
/*:87*/
#line 430 "linker.w"
break;
case 3:
PRINTVERB(2,"TXT\n");
/*104:*/
#line 1793 "linker.w"
handleTextSection(block_body,block_len);
/*:104*/
#line 434 "linker.w"
break;
case 4:
PRINTVERB(2,"RLD\n");
/*105:*/
#line 1796 "linker.w"
handleRelocationDirectory(block_body,block_len);
/*:105*/
#line 438 "linker.w"
break;
case 5:
PRINTVERB(2,"ISD\n");
break;
case 6:
PRINTVERB(2,"ENDMOD\n");
break;
case 7:
PRINTVERB(2,"Librarian header\n");
break;
case 8:
PRINTVERB(2,"Librarian end\n");
break;
default:
PRINTERR("Bad block type: %o : %s\n",
block_body[0],config.objnames[cur_input]);
}
/*:18*/
#line 411 "linker.w"
}
end:;
}
/*:16*//*21:*/
#line 481 "linker.w"
static void
handleGSD(int len){
int i,sect;
GSD_Entry*entry;
char name[7];
for(i= 2;i<len;i+= 8){
entry= (GSD_Entry*)(block_body+i);
/*22:*/
#line 540 "linker.w"
fromRadix50(entry->name[0],name);
fromRadix50(entry->name[1],name+3);
/*:22*/
#line 490 "linker.w"
PRINTVERB(2," Entry name: '%s', type: %o --- ",name,entry->type);
switch(entry->type){
case GSD_MODULE_NAME:
PRINTVERB(2,"ModuleName.\n");
PRINTVERB(1,"Module:%s\n",name);
break;
case GSD_CSECT_NAME:
PRINTVERB(2,"CSectName, flags:%o, length:%o.\n",
entry->flags,entry->value);
break;
case GSD_INTERNAL_SYMBOL_NAME:
PRINTVERB(2,"InternalSymbolName\n");
break;
case GSD_TRANFER_ADDRESS:
PRINTVERB(2,"TransferAddress, offset:%o.\n",entry->value);
/*37:*/
#line 715 "linker.w"
sect= findSection(entry->name);
SectDir[sect].transfer_addr= entry->value;
if(entry->value!=1)++num_start_addresses;
/*:37*/
#line 510 "linker.w"
break;
case GSD_GLOBAL_SYMBOL_NAME:
PRINTVERB(2,"GlobalSymbolName, flags:%o, value:%o.\n",
entry->flags,entry->value);
/*102:*/
#line 1787 "linker.w"
handleGlobalSymbol(entry);
/*:102*/
#line 516 "linker.w"
break;
case GSD_PSECT_NAME:
PRINTVERB(2,"PSectName, flags:%o, max length:%o.\n",
entry->flags,entry->value);
/*103:*/
#line 1790 "linker.w"
handleProgramSection(entry);
/*:103*/
#line 522 "linker.w"
break;
case GDS_IDENT:
PRINTVERB(2,"Ident.\n");
PRINTVERB(1," Ident: %s\n",name);
break;
case GSD_MAPPED_ARRAY:
PRINTVERB(2,"MappedArray, length:%o.\n",entry->value);
break;
default:
PRINTERR("Bad entry type: %o : %s\n",
entry->type,config.objnames[cur_input]);
}
}
}
/*:21*//*27:*/
#line 569 "linker.w"
static void
handleGlobalSymbol(GSD_Entry*entry){
char name[7];
int found_sym;
if(entry->flags&GLOBAL_DEFINITION_MASK){
if((found_sym= findGlobalSym(entry->name))!=-1){
fromRadix50(entry->name[0],name);
fromRadix50(entry->name[1],name+3);
PRINTERR("Global definition conflict: %s in %s"
" conflicts with %s.\n",name,
config.objnames[cur_input],
config.objnames[GSymDef[found_sym].obj_file]);
exit(EXIT_FAILURE);
}
GSymDef[NumGlobalDefs].name[0]= entry->name[0];
GSymDef[NumGlobalDefs].name[1]= entry->name[1];
GSymDef[NumGlobalDefs].flags= entry->flags;
GSymDef[NumGlobalDefs].sect= CurSect;
GSymDef[NumGlobalDefs].addr= SectDir[CurSect].start+entry->value;
GSymDef[NumGlobalDefs].obj_file= cur_input;
++NumGlobalDefs;
}
if(config.verbosity>=2){
PRINTVERB(2," Flags: ");
if(entry->flags&GLOBAL_WEAK_MASK){
PRINTVERB(2,"Weak,");
}else{
PRINTVERB(2,"Strong,");
}
if(entry->flags&GLOBAL_DEFINITION_MASK){
PRINTVERB(2,"Definition,");
}else{
PRINTVERB(2,"Reference,");
}
if(entry->flags&GLOBAL_WEAK_MASK){
PRINTVERB(2,"Relative.\n");
}else{
PRINTVERB(2,"Absolute.\n");
}
}
}
/*:27*//*28:*/
#line 615 "linker.w"
static int findGlobalSym(uint16_t*name){
int found,i;
found= -1;
for(i= 0;i<NumGlobalDefs;++i){
if(name[0]==GSymDef[i].name[0]&&name[1]==GSymDef[i].name[1]){
found= i;
break;
}
}
return(found);
}
/*:28*//*34:*/
#line 670 "linker.w"
static void
handleProgramSection(GSD_Entry*entry){
char name[7];
/*45:*/
#line 795 "linker.w"
if(config.verbosity>=2){
PRINTVERB(2," Flags: ");
if(entry->flags&PSECT_SAVE_MASK){
PRINTVERB(2,"RootScope,");