-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvms.c
3087 lines (2947 loc) · 69 KB
/
vms.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
/* vms.c -- Write out a VAX/VMS object file
Copyright (C) 1987, 1988 Free Software Foundation, Inc.
This file is part of GAS, the GNU Assembler.
GAS 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 1, or (at your option)
any later version.
GAS 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 GAS; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
/* Written by David L. Kashtan */
#include <ctype.h>
#include <stdio.h>
#include "as.h"
#include "md.h"
#include "subsegs.h"
#include "obstack.h"
#include "struc-symbol.h"
#include "write.h"
#include "symbols.h"
#ifdef VMS /* THIS MODULE IS FOR VMS ONLY */
#include <stab.h>
#include "objrecdef.h" /* Define VMS Object record lang. */
#include <vms/fabdef.h> /* Define File Access Block */
#include <vms/namdef.h> /* Define NAM Block */
#include <vms/xabdef.h> /* Define XAB */
#include <vms/xabdatdef.h> /* Define Date XAB */
#include <vms/xabfhcdef.h> /* Define File Header XAB */
/*
* Version string of the compiler that produced the code we are
* assembling. (And this assembler, if we do not have compiler info.)
*/
extern char version_string[];
char *compiler_version_string;
extern char *myname;
static symbolS *Entry_Point_Symbol = 0; /* Pointer to "_main" */
/*
* We augment the "gas" symbol structure with this
*/
struct VMS_Symbol {
struct VMS_Symbol *Next;
struct symbol *Symbol;
int Size;
int Psect_Index;
int Psect_Offset;
};
struct VMS_Symbol *VMS_Symbols = 0;
/* we need this to keep track of the various input files, so that we can
* give the debugger the correct source line
*/
struct input_file{
struct input_file* next;
struct input_file* same_file_fpnt;
int file_number;
int max_line;
int min_line;
int offset;
char flag;
char * name;
symbolS * spnt;
};
static struct input_file * file_root = (struct input_file*)NULL;
struct input_file * find_file(symbolS *);
/*
* If the procedure "main()" exists we have to add the instruction
* "jsb c$main_args" at the beginning to be compatible with VAX-11 "C".
*/
VMS_Check_For_Main()
{
register symbolS *symbolP;
#ifdef HACK_DEC_C_STARTUP /* JF */
register struct frchain *frchainP;
register fragS *fragP;
register fragS **prev_fragPP;
register struct fix *fixP;
register fragS *New_Frag;
int i;
#endif HACK_DEC_C_STARTUP
symbolP = (struct symbol *)symbol_find("_main");
if (symbolP && (symbolP->sy_nlist.n_type == (N_TEXT | N_EXT))) {
#ifdef HACK_DEC_C_STARTUP
if( !flagseen['+']) {
#endif
/*
* Remember the entry point symbol
*/
Entry_Point_Symbol = symbolP;
#ifdef HACK_DEC_C_STARTUP
} else {
/*
* Scan all the fragment chains for the one with "_main"
* (Actually we know the fragment from the symbol, but we need
* the previous fragment so we can change its pointer)
*/
frchainP = frchain_root;
while(frchainP) {
/*
* Scan all the fragments in this chain, remembering
* the "previous fragment"
*/
prev_fragPP = &frchainP->frch_root;
fragP = frchainP->frch_root;
while(fragP && (fragP != frchainP->frch_last)) {
/*
* Is this the fragment?
*/
if (fragP == symbolP->sy_frag) {
/*
* Yes: Modify the fragment by replacing
* it with a new fragment.
*/
New_Frag = (fragS *)
xmalloc(sizeof(*New_Frag) +
fragP->fr_fix +
fragP->fr_var +
5);
/*
* The fragments are the same except
* that the "fixed" area is larger
*/
*New_Frag = *fragP;
New_Frag->fr_fix += 6;
/*
* Copy the literal data opening a hole
* 2 bytes after "_main" (i.e. just after
* the entry mask). Into which we place
* the JSB instruction.
*/
New_Frag->fr_literal[0] = fragP->fr_literal[0];
New_Frag->fr_literal[1] = fragP->fr_literal[1];
New_Frag->fr_literal[2] = 0x16; /* Jsb */
New_Frag->fr_literal[3] = 0xef;
New_Frag->fr_literal[4] = 0;
New_Frag->fr_literal[5] = 0;
New_Frag->fr_literal[6] = 0;
New_Frag->fr_literal[7] = 0;
for(i = 2; i < fragP->fr_fix + fragP->fr_var; i++)
New_Frag->fr_literal[i+6] =
fragP->fr_literal[i];
/*
* Now replace the old fragment with the
* newly generated one.
*/
*prev_fragPP = New_Frag;
/*
* Remember the entry point symbol
*/
Entry_Point_Symbol = symbolP;
/*
* Scan the text area fixup structures
* as offsets in the fragment may have
* changed
*/
for(fixP = text_fix_root; fixP; fixP = fixP->fx_next) {
/*
* Look for references to this
* fragment.
*/
if (fixP->fx_frag == fragP) {
/*
* Change the fragment
* pointer
*/
fixP->fx_frag = New_Frag;
/*
* If the offset is after
* the entry mask we need
* to account for the JSB
* instruction we just
* inserted.
*/
if (fixP->fx_where >= 2)
fixP->fx_where += 6;
}
}
/*
* Scan the symbols as offsets in the
* fragment may have changed
*/
for(symbolP = symbol_rootP;
symbolP;
symbolP = symbolP->sy_next) {
/*
* Look for references to this
* fragment.
*/
if (symbolP->sy_frag == fragP) {
/*
* Change the fragment
* pointer
*/
symbolP->sy_frag = New_Frag;
/*
* If the offset is after
* the entry mask we need
* to account for the JSB
* instruction we just
* inserted.
*/
if (symbolP->sy_nlist.n_value >= 2)
symbolP->sy_nlist.n_value += 6;
}
}
/*
* Make a symbol reference to
* "_c$main_args" so we can get
* its address inserted into the
* JSB instruction.
*/
symbolP = (symbolS *)xmalloc(sizeof(*symbolP));
symbolP->sy_nlist.n_un.n_name = "_c$main_args";
symbolP->sy_nlist.n_type = N_UNDF;
symbolP->sy_nlist.n_other = 0;
symbolP->sy_nlist.n_desc = 0;
symbolP->sy_nlist.n_value = 0;
symbolP->sy_name_offset = 0;
symbolP->sy_number = 0;
symbolP->sy_frag = New_Frag;
symbolP->sy_forward = 0;
symbolP->sy_next = symbol_rootP;
symbol_rootP = symbolP;
/*
* Generate a text fixup structure
* to get "_c$main_args" stored into the
* JSB instruction.
*/
fixP = (struct fix *)xmalloc(sizeof(*fixP));
fixP->fx_frag = New_Frag;
fixP->fx_where = 4;
fixP->fx_addsy = symbolP;
fixP->fx_subsy = 0;
fixP->fx_offset = 0;
fixP->fx_size = sizeof(long);
fixP->fx_pcrel = 1;
fixP->fx_next = text_fix_root;
text_fix_root = fixP;
/*
* Now make sure we exit from the loop
*/
frchainP = 0;
break;
}
/*
* Try the next fragment
*/
prev_fragPP = &fragP->fr_next;
fragP = fragP->fr_next;
}
/*
* Try the next fragment chain
*/
if (frchainP) frchainP=frchainP->frch_next;
}
}
#endif /* HACK_DEC_C_STARTUP */
}
}
/*
* Write a VAX/VMS object file (everything else has been done!)
*/
VMS_write_object_file(text_siz, data_siz, text_frag_root, data_frag_root)
unsigned text_siz;
unsigned data_siz;
struct frag *text_frag_root;
struct frag *data_frag_root;
{
register fragS * fragP;
register symbolS * symbolP;
register symbolS * sp;
register struct fix * fixP;
register struct VMS_Symbol * vsp;
int Local_Initialized_Data_Size = 0;
int Psect_Number = 0; /* Psect Index Number */
int Text_Psect = -1; /* Text Psect Index */
int Data_Psect = -2; /* Data Psect Index JF: Was -1 */
int Bss_Psect = -3; /* Bss Psect Index JF: Was -1 */
/*
* Create the VMS object file
*/
Create_VMS_Object_File();
/*
* Write the module header records
*/
Write_VMS_MHD_Records();
/*
* Generate the VMS object file records
* 1st GSD then TIR records
*/
/******* Global Symbol Dictionary *******/
/*
* Define the Text Psect
*/
if (text_siz > 0) {
Text_Psect = Psect_Number++;
VMS_Psect_Spec("$code",text_siz,"TEXT");
}
/*
* Define the BSS Psect
*/
if (local_bss_counter > 0) {
Bss_Psect = Psect_Number++;
VMS_Psect_Spec("$uninitialized_data",local_bss_counter,"DATA");
}
/*
* Now scan the symbols and emit the appropriate GSD records
*/
for (sp = symbol_rootP; sp; sp = sp->sy_next) {
/*
* Dispatch on symbol type
*/
switch(sp->sy_type) {
/*
* Global uninitialized data
*/
case N_UNDF | N_EXT:
/*
* Make a VMS data symbol entry
*/
vsp = (struct VMS_Symbol *)
xmalloc(sizeof(*vsp));
vsp->Symbol = sp;
vsp->Size = sp->sy_nlist.n_value;
vsp->Psect_Index = Psect_Number++;
vsp->Psect_Offset = 0;
vsp->Next = VMS_Symbols;
VMS_Symbols = vsp;
sp->sy_number = (int)vsp;
/*
* Make the psect for this data
*/
if(sp->sy_nlist.n_other)
VMS_Psect_Spec(sp->sy_nlist.n_un.n_name,
vsp->Size,
"CONST");
else
VMS_Psect_Spec(sp->sy_nlist.n_un.n_name,
vsp->Size,
"COMMON");
#ifdef NOT_VAX_11_C_COMPATIBLE
/*
* Place a global symbol at the
* beginning of the Psect
*/
VMS_Global_Symbol_Spec(sp->sy_nlist.n_un.n_name,
vsp->Psect_Index,
0,
1);
#endif NOT_VAX_11_C_COMPATIBLE
break;
/*
* Local uninitialized data
*/
case N_BSS:
/*
* Make a VMS data symbol entry
*/
vsp = (struct VMS_Symbol *)
xmalloc(sizeof(*vsp));
vsp->Symbol = sp;
vsp->Size = 0;
vsp->Psect_Index = Bss_Psect;
vsp->Psect_Offset =
sp->sy_nlist.n_value -
bss_address_frag . fr_address;
vsp->Next = VMS_Symbols;
VMS_Symbols = vsp;
sp->sy_number = (int)vsp;
break;
/*
* Global initialized data
*/
case N_DATA | N_EXT:
/*
* Make a VMS data symbol entry
*/
vsp = (struct VMS_Symbol *)
xmalloc(sizeof(*vsp));
vsp->Symbol = sp;
vsp->Size = VMS_Initialized_Data_Size(sp,
text_siz + data_siz);
vsp->Psect_Index = Psect_Number++;
vsp->Psect_Offset = 0;
vsp->Next = VMS_Symbols;
VMS_Symbols = vsp;
sp->sy_number = (int)vsp;
/*
* Make its psect
*/
if(sp->sy_nlist.n_other)
VMS_Psect_Spec(sp->sy_nlist.n_un.n_name,
vsp->Size,
"CONST");
else
VMS_Psect_Spec(sp->sy_nlist.n_un.n_name,
vsp->Size,
"COMMON");
#ifdef NOT_VAX_11_C_COMPATIBLE
/*
* Place a global symbol at the
* beginning of the Psect
*/
VMS_Global_Symbol_Spec(sp->sy_nlist.n_un.n_name,
vsp->Psect_Index,
0,
1);
#endif NOT_VAX_11_C_COMPATIBLE
break;
/*
* Local initialized data
*/
case N_DATA:
/*
* Make a VMS data symbol entry
*/
vsp = (struct VMS_Symbol *)
xmalloc(sizeof(*vsp));
vsp->Symbol = sp;
vsp->Size =
VMS_Initialized_Data_Size(sp,
text_siz + data_siz);
vsp->Psect_Index = Data_Psect;
vsp->Psect_Offset =
Local_Initialized_Data_Size;
Local_Initialized_Data_Size += vsp->Size;
vsp->Next = VMS_Symbols;
VMS_Symbols = vsp;
sp->sy_number = (int)vsp;
break;
/*
* Global Text definition
*/
case N_TEXT | N_EXT: {
unsigned short Entry_Mask;
/*
* Get the entry mask
*/
fragP = sp->sy_frag;
Entry_Mask = (fragP->fr_literal[0] & 0xff) +
((fragP->fr_literal[1] & 0xff)
<< 8);
/*
* Define the Procedure entry pt.
*/
VMS_Procedure_Entry_Pt(sp->sy_nlist.n_un.n_name,
Text_Psect,
sp->sy_nlist.n_value,
Entry_Mask);
break;
}
/*
* Local Text definition
*/
case N_TEXT:
/*
* Make a VMS data symbol entry
*/
if(Text_Psect != -1) {
vsp = (struct VMS_Symbol *)
xmalloc(sizeof(*vsp));
vsp->Symbol = sp;
vsp->Size = 0;
vsp->Psect_Index = Text_Psect;
vsp->Psect_Offset = sp->sy_nlist.n_value;
vsp->Next = VMS_Symbols;
VMS_Symbols = vsp;
sp->sy_number = (int)vsp;
}
break;
/*
* Global Reference
*/
case N_UNDF:
/*
* Make a GSD global symbol reference
* record.
*/
VMS_Global_Symbol_Spec(sp->sy_nlist.n_un.n_name,
0,
0,
0);
break;
/*
* Anything else
*/
default:
/*
* Ignore STAB symbols
* Including .stabs emitted by g++
*/
if ((sp->sy_type & N_STAB) != 0 || sp->sy_nlist.n_type==22)
break;
/*
* Error
*/
if(sp->sy_nlist.n_type !=22)
printf(" ERROR, unknown type (%d)\n",
sp->sy_nlist.n_type);
break;
}
}
/*
* Define the Data Psect
*/
if ((data_siz > 0) && (Local_Initialized_Data_Size > 0)) {
/*
* Do it
*/
Data_Psect = Psect_Number++;
VMS_Psect_Spec("$data",
Local_Initialized_Data_Size,
"DATA");
/*
* Scan the VMS symbols and fill in the data psect
*/
for (vsp = VMS_Symbols; vsp; vsp = vsp->Next) {
/*
* Only look for undefined psects
*/
if (vsp->Psect_Index < 0) {
/*
* And only initialized data
*/
if (vsp->Symbol->sy_nlist.n_type == N_DATA)
vsp->Psect_Index = Data_Psect;
}
}
}
/******* Text Information and Relocation Records *******/
/*
* Write the text segment data
*/
if (text_siz > 0) {
/*
* Scan the text fragments
*/
for(fragP = text_frag_root; fragP; fragP = fragP->fr_next) {
/*
* Stop if we get to the data fragments
*/
if (fragP == data_frag_root) break;
/*
* Ignore fragments with no data
*/
if ((fragP->fr_fix == 0) && (fragP->fr_var == 0))
continue;
/*
* Go the the appropriate offset in the
* Text Psect.
*/
VMS_Set_Psect(Text_Psect,fragP->fr_address,OBJ$C_TIR);
/*
* Store the "fixed" part
*/
if (fragP->fr_fix)
VMS_Store_Immediate_Data(fragP->fr_literal,
fragP->fr_fix,
OBJ$C_TIR);
/*
* Store the "variable" part
*/
if (fragP->fr_var && fragP->fr_offset)
VMS_Store_Repeated_Data(fragP->fr_offset,
fragP->fr_literal+
fragP->fr_fix,
fragP->fr_var,
OBJ$C_TIR);
}
/*
* Now we go through the text segment fixups and
* generate TIR records to fix up addresses within
* the Text Psect
*/
for(fixP = text_fix_root; fixP; fixP = fixP->fx_next) {
/*
* We DO handle the case of "Symbol - Symbol" as
* long as it is in the same segment.
*/
if (fixP->fx_subsy && fixP->fx_addsy) {
int i;
/*
* They need to be in the same segment
*/
if (fixP->fx_subsy->sy_type !=
fixP->fx_addsy->sy_type)
error("Fixup data addsy and subsy didn't have the same type");
/*
* And they need to be in one that we
* can check the psect on
*/
if (((fixP->fx_addsy->sy_type & ~N_EXT) != N_DATA) &&
((fixP->fx_addsy->sy_type & ~N_EXT) != N_TEXT))
error("Fixup data addsy and subsy didn't have an appropriate type");
/*
* This had better not be PC relative!
*/
if (fixP->fx_pcrel)
error("Fixup data was erroneously \"pcrel\"");
/*
* Subtract their values to get the
* difference.
*/
i = fixP->fx_addsy->sy_value -
fixP->fx_subsy->sy_value;
/*
* Now generate the fixup object records
* Set the psect and store the data
*/
VMS_Set_Psect(Text_Psect,
fixP->fx_where +
fixP->fx_frag->fr_address,
OBJ$C_TIR);
VMS_Store_Immediate_Data(&i,
fixP->fx_size,
OBJ$C_TIR);
/*
* Done
*/
continue;
}
/*
* Size will HAVE to be "long"
*/
if (fixP->fx_size != sizeof(long))
error("Fixup datum was not a longword");
/*
* Symbol must be "added" (if it is ever
* subtracted we can
* fix this assumption)
*/
if (fixP->fx_addsy == 0)
error("Fixup datum was not \"fixP->fx_addsy\"");
/*
* Store the symbol value in a PIC fashion
*/
VMS_Store_PIC_Symbol_Reference(fixP->fx_addsy,
fixP->fx_offset,
fixP->fx_pcrel,
Text_Psect,
fixP->fx_where +
fixP->fx_frag->fr_address,
OBJ$C_TIR);
/*
* Check for indirect address reference,
* which has to be fixed up (as the linker
* will screw it up with TIR$C_STO_PICR).
*/
if (fixP->fx_pcrel)
VMS_Fix_Indirect_Reference(Text_Psect,
fixP->fx_where +
fixP->fx_frag->fr_address,
fixP->fx_frag,
text_frag_root);
}
}
/*
* Store the Data segment:
*
* Since this is REALLY hard to do any other way,
* we actually manufacture the data segment and
* the store the appropriate values out of it.
*/
if (data_siz > 0) {
char *Data_Segment;
/*
* Allocate the data segment
*/
Data_Segment = (char *)xmalloc(data_siz);
/*
* Run through the data fragments, filling in the segment
*/
for(fragP = data_frag_root; fragP; fragP = fragP->fr_next) {
register long int count;
register char * fill_literal;
register long int fill_size;
int i;
i = fragP->fr_address - text_siz;
if (fragP->fr_fix)
bcopy(fragP->fr_literal,
Data_Segment + i,
fragP->fr_fix);
i += fragP->fr_fix;
fill_literal= fragP -> fr_literal + fragP -> fr_fix;
fill_size = fragP -> fr_var;
for (count = fragP -> fr_offset; count; count --) {
if (fill_size)
bcopy(fill_literal,
Data_Segment + i,
fill_size);
i += fill_size;
}
}
/*
* Now we can run through all the data symbols
* and store the data
*/
for(vsp = VMS_Symbols; vsp; vsp = vsp->Next) {
/*
* Ignore anything other than data symbols
*/
if ((vsp->Symbol->sy_nlist.n_type & ~N_EXT) != N_DATA)
continue;
/*
* Set the Psect + Offset
*/
VMS_Set_Psect(vsp->Psect_Index,
vsp->Psect_Offset,
OBJ$C_TIR);
/*
* Store the data
*/
VMS_Store_Immediate_Data(Data_Segment +
vsp->Symbol->sy_nlist.n_value -
text_siz,
vsp->Size,
OBJ$C_TIR);
}
/*
* Now we go through the data segment fixups and
* generate TIR records to fix up addresses within
* the Data Psects
*/
for(fixP = data_fix_root; fixP; fixP = fixP->fx_next) {
/*
* Find the symbol for the containing datum
*/
for(vsp = VMS_Symbols; vsp; vsp = vsp->Next) {
/*
* Only bother with Data symbols
*/
sp = vsp->Symbol;
if ((sp->sy_nlist.n_type & ~N_EXT) != N_DATA)
continue;
/*
* Ignore symbol if After fixup
*/
if (sp->sy_nlist.n_value >
(fixP->fx_where +
fixP->fx_frag->fr_address))
continue;
/*
* See if the datum is here
*/
if ((sp->sy_nlist.n_value + vsp->Size) <=
(fixP->fx_where +
fixP->fx_frag->fr_address))
continue;
/*
* We DO handle the case of "Symbol - Symbol" as
* long as it is in the same segment.
*/
if (fixP->fx_subsy && fixP->fx_addsy) {
int i;
/*
* They need to be in the same segment
*/
if (fixP->fx_subsy->sy_type !=
fixP->fx_addsy->sy_type)
error("Fixup data addsy and subsy didn't have the same type");
/*
* And they need to be in one that we
* can check the psect on
*/
if (((fixP->fx_addsy->sy_type & ~N_EXT) != N_DATA) &&
((fixP->fx_addsy->sy_type & ~N_EXT) != N_TEXT))
error("Fixup data addsy and subsy didn't have an appropriate type");
/*
* This had better not be PC relative!
*/
if (fixP->fx_pcrel)
error("Fixup data was erroneously \"pcrel\"");
/*
* Subtract their values to get the
* difference.
*/
i = fixP->fx_addsy->sy_value -
fixP->fx_subsy->sy_value;
/*
* Now generate the fixup object records
* Set the psect and store the data
*/
VMS_Set_Psect(vsp->Psect_Index,
fixP->fx_frag->fr_address +
fixP->fx_where -
vsp->Symbol->sy_value +
vsp->Psect_Offset,
OBJ$C_TIR);
VMS_Store_Immediate_Data(&i,
fixP->fx_size,
OBJ$C_TIR);
/*
* Done
*/
break;
}
/*
* Size will HAVE to be "long"
*/
if (fixP->fx_size != sizeof(long))
error("Fixup datum was not a longword");
/*
* Symbol must be "added" (if it is ever
* subtracted we can
* fix this assumption)
*/
if (fixP->fx_addsy == 0)
error("Fixup datum was not \"fixP->fx_addsy\"");
/*
* Store the symbol value in a PIC fashion
*/
VMS_Store_PIC_Symbol_Reference(
fixP->fx_addsy,
fixP->fx_offset,
fixP->fx_pcrel,
vsp->Psect_Index,
fixP->fx_frag->fr_address +
fixP->fx_where -
vsp->Symbol->sy_value +
vsp->Psect_Offset,
OBJ$C_TIR);
/*
* Done
*/
break;
}
}
}
/*
* Write the Traceback Begin Module record
*/
VMS_TBT_Module_Begin();
/*
* Scan the symbols and write out the routines
* (this makes the assumption that symbols are in
* order of ascending text segment offset)
*/
{
struct symbol *Current_Routine = 0;
int Current_Line_Number = 0;
int Current_Offset = -1;
struct input_file * Current_File;
/* Output debugging info for global variables and static variables that are not
* specific to one routine. We also need to examine all stabs directives, to
* find the definitions to all of the advanced data types, and this is done by
* VMS_LSYM_Parse. This needs to be done before any definitions are output to
* the object file, since there can be forward references in the stabs
* directives. When through with parsing, the text of the stabs directive
* is altered, with the definitions removed, so that later passes will see
* directives as they would be written if the type were already defined.
*
* We also look for files and include files, and make a list of them. We
* examine the source file numbers to establish the actual lines that code was
* generated from, and then generate offsets.
*/
VMS_LSYM_Parse();
for(symbolP = symbol_rootP; symbolP; symbolP = symbolP->sy_next) {
/*
* Deal with STAB symbols
*/
if ((symbolP->sy_nlist.n_type & N_STAB) != 0) {
/*
* Dispatch on STAB type
*/
switch((unsigned char)symbolP->sy_nlist.n_type) {
case N_SLINE:
if(symbolP->sy_nlist.n_desc > Current_File->max_line)
Current_File->max_line = symbolP->sy_nlist.n_desc;
if(symbolP->sy_nlist.n_desc < Current_File->min_line)
Current_File->min_line = symbolP->sy_nlist.n_desc;
break;
case N_SO:
Current_File =find_file(symbolP);
Current_File->flag = 1;
Current_File->min_line = 1;
break;
case N_SOL:
Current_File = find_file(symbolP);
break;
case N_GSYM:
VMS_GSYM_Parse(symbolP,Text_Psect);
break;
case N_LCSYM:
VMS_LCSYM_Parse(symbolP,Text_Psect);
break;
case N_FUN: /* For static constant symbols */
case N_STSYM:
VMS_STSYM_Parse(symbolP,Text_Psect);
break;
}
}
}
/* now we take a quick sweep through the files and assign offsets
to each one. This will essentially be the starting line number to the
debugger for each file. Output the info for the debugger to specify the
files, and then tell it how many lines to use */
{
int File_Number = 0;
int Debugger_Offset = 0;
int file_available;
Current_File = file_root;
for(Current_File = file_root; Current_File; Current_File = Current_File->next){
if(Current_File == (struct input_file*) NULL) break;
if(Current_File->max_line == 0) continue;
if((strncmp(Current_File->name,"GNU_GXX_INCLUDE:",16) == 0) &&
!flagseen['D']) continue;
if((strncmp(Current_File->name,"GNU_CC_INCLUDE:",15) == 0) &&
!flagseen['D']) continue;
/* show a few extra lines at the start of the region selected */
if(Current_File->min_line > 2) Current_File->min_line -= 2;
Current_File->offset = Debugger_Offset - Current_File->min_line + 1;
Debugger_Offset += Current_File->max_line - Current_File->min_line + 1;
if(Current_File->same_file_fpnt != (struct input_file *) NULL)
Current_File->file_number =Current_File->same_file_fpnt->file_number;
else {
Current_File->file_number = ++File_Number;
file_available = VMS_TBT_Source_File(Current_File->name,
Current_File->file_number);
if(!file_available) {Current_File->file_number = 0;
File_Number--;
continue;};
};
VMS_TBT_Source_Lines(Current_File->file_number,
Current_File->min_line,
Current_File->max_line-Current_File->min_line+1);
}; /* for */
}; /* scope */
Current_File = (struct input_file*) NULL;
for(symbolP = symbol_rootP; symbolP; symbolP = symbolP->sy_next) {
/*
* Deal with text symbols
*/
if ((symbolP->sy_nlist.n_type & ~N_EXT) == N_TEXT) {
/*
* Ignore symbols starting with "L",
* as they are local symbols
*/
if (symbolP->sy_nlist.n_un.n_name[0] == 'L') continue;
/*
* If there is a routine start defined,
* terminate it.
*/
if (Current_Routine) {
/*
* End the routine
*/
VMS_TBT_Routine_End(text_siz,Current_Routine);
}
/*
* Store the routine begin traceback info
*/
if(Text_Psect != -1) {
VMS_TBT_Routine_Begin(symbolP,Text_Psect);
Current_Routine = symbolP;
}
/* Output local symbols, i.e. all symbols that are associated with a specific
* routine. We output them now so the debugger recognizes them as local to
* this routine.
*/
{ symbolS * symbolP1;
char* pnt;
char* pnt1;
for(symbolP1 = Current_Routine; symbolP1; symbolP1 = symbolP1->sy_next) {
if ((symbolP1->sy_nlist.n_type & N_STAB) == 0) continue;
if (symbolP1->sy_nlist.n_type != N_FUN) continue;