-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathobject.c
More file actions
1755 lines (1715 loc) · 76.1 KB
/
object.c
File metadata and controls
1755 lines (1715 loc) · 76.1 KB
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
/*
object.c - Part of llf, a cross linker. Part of the macxx tool chain.
Copyright (C) 2008 David Shepperd
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/>.
*/
/*************************************************************************
*
* OBJ.C - RT-11/RSX/VLDA object file handler
*
*************************************************************************/
/*************************************************************************
* The RT11/RSX object file format is as follows:
*
* The first byte of the first word in the record contains the record
* type code. The allowable codes are as follows:
* 1 - Global Symbol Directory (GSD)
* 2 - End of GSD (ignored in this routine)
* 3 - Text record (TXT, contains binary image data)
* 4 - Relocation Directory (RLD) (patches bytes/words in TXT)
* 5 - Internal Symbol Directory (ISD, ignored in this routine)
* 6 - End of Module record
* The second byte of the first word is always 0, but it is ignored in
* this routine anyway.
*
* Subsequent bytes/words in the record are interpreted depending on the
* record type. All GSD items are the same length; RLD items are variable
* length; TXT is raw binary data which is passed straight through to the
* output. ISD records are currently ignored; End GSD and End Module
* records have no additional data in them. See gsdstruct for layout of
* the GSD item(s) but various fields may not be used in all GSD item
* types. An RLD item consists of a minimum of 16 bits where the 6 least
* significant bits express the type, bit 6 indicates Motorola 6800 mode
* addressing (increasing addresses=decreasing significance), bit 7
* specifies that the RLD applies to a byte quantity and the remaining
* 8 bits specify a displacement (+4) from the start of a previous
* TXT record (hence, backpatching is the name of the game with this
* scheme).
*/
#include "version.h"
#ifdef VMS
#include <file.h>
#define lib_ediv lib$ediv
#else
#define lib_ediv(a,b,c,d) 1
#endif
#include <stdio.h> /* get standard I/O definitions */
#include <ctype.h> /* get standard string type macros */
#include <string.h>
#include <unistd.h>
#include "token.h" /* define compile time constants */
#include "structs.h" /* define structures */
#include "header.h" /* get our standard stuff */
#include "vlda_structs.h"
#include "exproper.h"
#ifndef VMS
static uint16_t rsize;
static int even_odd;
#endif
#if 0
extern char emsg[]; /* space to build error messages */
extern char *inp_str; /* place to hold input text */
extern char *tkn_ptr; /* pointer to start of token */
extern int32_t token_value; /* value of converted token */
extern int token_type; /* token type */
extern char token_end; /* terminator char for string tokens */
extern char *token_pool; /* pointer to free token memory */
extern int token_pool_size; /* size of remaining free token memory */
extern int cmd_code; /* command code */
extern struct seg_spec_struct *seg_spec_pool; /* pointer to free segment space */
extern int seg_spec_size; /* size of segment pool */
extern int debug; /* debug options */
extern char *null_string; /* pointer to null ascii string */
extern int32_t misc_pool_used;
#endif
struct
{
struct ss_struct *ps_ptr; /* array of pointers to segments */
uint32_t ps_name; /* rad50 name of segment */
} psects[256];
static int free_psect; /* index into psects array */
static int file_fd; /* file descriptor */
SS_struct *base_page_nam=0;
GRP_struct *base_page_grp=0;
struct ss_struct *abs_group_nam=0;
struct grp_struct *abs_group=0;
static int inp_major,inp_minor;
#if defined(RT11_RSX) /* obsolete stuff */
/*************************************************
* gsdstruct is the structure of a GSD entry *
*************************************************/
struct gsdstruct
{
uint16_t gsdnm1; /* msb of name field */
uint16_t gsdnm0; /* lsb of name field */
unsigned int gflg_weak:1; /* weak/strong bit */
unsigned int gflg_shr:1; /* refers to shared region (not used) */
unsigned int gflg_ovr:1; /* section to be overlaid */
unsigned int gflg_def:1; /* symbol defined */
unsigned int gflg_base:1; /* section is base page */
unsigned int gflg_rel:1; /* relative symbol/section */
unsigned int gflg_scp:1; /* global section (not used) */
unsigned int gflg_dta:1; /* data section */
uint8_t gsdtyp; /* gsd type */
int16_t gsdvalue; /* gsd value */
};
struct gsdtime
{ /* gsd time/date structure */
uint16_t gsdtim1; /* msb of time longword */
uint16_t gsdtim0; /* lsb of time longword */
unsigned fill1:16; /* skip a short */
unsigned int gsdyr:5; /* bits 0:4 is the year since 1972 */
unsigned int gsday:5; /* bits 5:9 is the day */
unsigned int gsdmn:4; /* bits 10:13 is the month */
unsigned fill2:2; /* fill out to 16 bits */
};
struct gsdxlate
{ /* gsd xlator name */
uint32_t gsdxn; /* name */
unsigned filler:16; /* filler */
uint8_t gsderrors; /* error counter */
uint8_t gsdwarns; /* warnings */
};
/*****************************************************************
* An alternate GSD entry layout in order to get flags as a byte *
*****************************************************************/
struct gsdflags
{
uint32_t gsdlong;
char flags;
unsigned fill1:8;
unsigned fill2:16;
};
struct r50name
{
uint16_t r50msbs;
uint16_t r50lsbs;
};
struct rldstruct
{
unsigned int rldtyp:6; /* rld type code */
unsigned int rldmode:2; /* 6800 mode (6) and byte mode (7) bits */
uint8_t rlddsp; /* displacement */
};
/*******************************************************************
* The following is a union of pointers to various types of object *
* file structures. This allows for obj to be auto-incremented *
* automagically after the correseponding item(s) have been *
* processed. *
*******************************************************************/
static union
{
uint16_t *rectyp; /* object record type */
struct gsdstruct *gsd; /* followed by a GSD */
struct rldstruct *rld; /* and an RLD */
struct r50name *rldnam; /* pointer to rad50 name */
int32_t *rldlong; /* pointer to a long */
int16_t *rldval; /* rld value or constant */
char *complex; /* pointer to complex relocation string */
uint16_t *txtlda; /* text load address */
char *txt; /* text */
/* struct isdstruct *isd; there may be an ISD too */
} obj;
#endif
static union
{
struct vlda_abs *vldaabs; /* abs and text record */
struct vlda_id *vldaid; /* id record */
struct vlda_sym *vldasym; /* symbol pointer */
struct vlda_seg *vldaseg; /* segment pointer */
struct vlda_test *vldatst; /* test expression */
struct vlda_dbgdfile *vldadbgdfile;
union vexp vldaexp; /* expression pointer(s) */
Sentinel *vldatype; /* record sentinel */
char *vldarp;
} vlda;
#define vabs vlda.vldaabs
#define vid vlda.vldaid
#define vsym vlda.vldasym
#define vseg vlda.vldaseg
#define vexpr vlda.vldaexp
#define vtst vlda.vldatst
#define vtype vlda.vldatype
#define vrp vlda.vldarp
#define vdbgfile vlda.vldadbgdfile
int32_t object_count;
/*******************************************************************
* get_obj reads a record from the input file. If the input file *
* is RT-11 format, it de-blocks a record from a serial byte *
* stream using single character file reads. The record is *
* in standard LDA file format: 1,0,cl,ch,data...,cs *
* where each item is a byte, cl=low byte of 16 bit byte count, *
* ch=high byte of the count, data=data bytes and cs=checksum *
* which is the 2's compliment of all the previous bytes including *
* the 1 and 0. *
*/
static int get_obj( void )
/*
* At entry:
* current_fnd points to current input file
* file_fd = current file descriptor
* At exit:
* inp_str is filled with record
* returns length in bytes of record or EOF
*/
{
int i=0;
#ifdef VMS
char c,*d=inp_str;
int j,cnt,cs;
#endif
object_count++;
#if !defined(VMS)
i = read(file_fd,&rsize,sizeof(int16_t));
even_odd = rsize&1;
#else
i = read(file_fd,inp_str,MAX_TOKEN);
#endif
if (i >= MAX_TOKEN)
{
sprintf(emsg,"Record size of %d > max of %d in \"%s\"",
i,MAX_TOKEN,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
return(EOF);
}
if (i == 0)
return(EOF);
#if defined(VMS)
if (i > 0)
return i;
#else
if (read(file_fd,inp_str,(int)rsize+even_odd) == (int)rsize+even_odd)
{
return((int)rsize);
}
#endif
sprintf(emsg,"Error reading input \"%s\"",current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
return(EOF);
}
#if defined(VMS) && defined(RT11_RSX)
static int dividend[2] = {0,0}; /* 64 bit dividend */
static int remainder,quotient; /* 32 bit quotient and 32 bit remainder */
static char *r50_lc=0; /* pointer to last non-blank character */
static char *ediv_char=0;
static char r50toa[] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ$.*0123456789";
static int d5050=050*050,d50=050;
/****************************************************************************
* r50div - convert a short containing rad50 code to an ASCII stream
*/
static void r50div( uint16_t r50 )
/*
* At entry:
* r50 - is the short containing the rad50 code
* ediv_char - pointer to ascii buffer
* At exit:
* 3 character string located at *ediv_char
* ediv_char incremented by 3
* r50_lc = position+1 of last non-blank character
*/
{
dividend[0] = r50;
if (!lib_ediv(&d5050,÷nd[0],"ient,&remainder)&1)
{
sprintf(emsg,"Error converting rad50 to ASCII in \"%s\"",current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
}
dividend[0] = remainder;
*ediv_char++ = r50toa[quotient]; /* write the character */
if (quotient) r50_lc = ediv_char; /* record location + 1 of non-blank */
if (!lib_ediv(&d50,÷nd[0],"ient,&remainder)&1)
{
sprintf(emsg,"Error converting rad50 to ASCII in \"%s\"",current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
}
*ediv_char++ = r50toa[quotient]; /* write the character */
if (quotient) r50_lc = ediv_char; /* record location + 1 of non-blank */
*ediv_char++ = r50toa[remainder]; /* write the character */
if (remainder) r50_lc = ediv_char; /* record location + 1 of non-blank */
}
/*********************************************************************
* rad50_to_ascii - converts a longword rad50 value to an ASCII string
* trimmed of trailing spaces and null terminated.
*/
static void rad50_to_ascii( struct r50name *ptr )
/*
* At entry:
* ptr - points to gsdstruct containing longword rad50
* At exit:
* ASCII string inserted in *token_pool
* token_value contains length of ASCII string
*/
{
r50_lc = ediv_char = token_pool;
r50div(ptr->r50msbs); /* unpack msb rad50 word */
r50div(ptr->r50lsbs); /* unpack lsb rad50 word */
*r50_lc = 0; /* null terminate */
token_value = r50_lc - token_pool; /* compute length of string */
return;
}
#endif
#if defined(VMS) && defined(RT11_RSX)
static struct ss_struct *no_name_seg=0; /* pointer to un-named segment */
static struct ss_struct *last_txt_seg=0; /* segment ptr of last txt rcd */
static int rsx_pass=0; /* Have to pass through RSX files twice */
static int rsx_fd; /* file desc for rsx input */
static char *months[] =
{"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
#endif
static struct ss_struct *curr_seg=0; /* pointer to curent segment */
static int curr_pc; /* current pc */
static int last_txt_org; /* org of last txt rcd */
static int last_txt_end; /* pc after load of txt */
/****************************************************************************
* new_sym - insert a new symbol into the symbol table and initialise the
* symbol block.
*/
static struct ss_struct *new_sym( int flag )
/*
* At entry:
* flag = 0 if not to insert symbol into symbol table
* " = 1 if to insert only if one not already there
* " = 2 if to insert whether one is already there or not
* *token_pool points to ASCII string to insert
* token_value has length of string
* At exit:
* returns pointer to symbol block
* new_symbol contains status about symbol insert
* token_pool may have been updated in order to keep symbol
*/
{
struct ss_struct *sym_ptr;
sym_ptr = sym_lookup(token_pool,++token_value,flag);
switch (new_symbol)
{
case 5: {
sym_ptr->ss_string = first_symbol->ss_string;
sym_ptr->ss_fnd = current_fnd;
break;
}
case 1:
case 3: {
sym_ptr->ss_fnd = current_fnd;
if (token_value > 1)
{
token_pool += token_value; /* update the free mem pointer */
token_pool_size -= token_value; /* and size */
}
}
case 0: break;
default: {
sprintf(emsg,
"Internal error. {new_symbol} invalid (%d)\n\t%s%s%s\"%s\"",
new_symbol,"while processing {",sym_ptr->ss_string,
"} in file ",current_fnd->fn_buff);
err_msg(MSG_FATAL,emsg);
}
}
return(sym_ptr);
}
#if defined(VMS) && defined(RT11_RSX)
/*********************************************************************
* do_gsd - process all the GSD items found in the object record. Note
* that the record will contain all the same type of items.
*/
static void do_gsd( int len, struct gsdstruct *gsdptr )
/*
* At entry:
* len - number of bytes remaining in record
* gsdptr - pointer to first byte in record (as a gsdstruct)
* At exit:
* all items in the record will have been processed.
* The definition file may have been updated if there were
* definitions in the GSD. Symbols and sections may have been
* inserted into the symbol table.
*/
{
char *s;
int noname,i;
unsigned int mn,sec,mon;
struct ss_struct *sym_ptr;
struct seg_spec_struct *seg_ptr,*fseg_ptr;
len = len/sizeof(struct gsdstruct);
if (token_pool_size < len*7)
{
int tsiz = MAX_TOKEN*8;
if (len*7 > tsiz) tsiz += len*7;
token_pool_size = tsiz;
token_pool = MEM_alloc(tsiz);
misc_pool_used += token_pool_size;
}
for (; len > 0; --len,gsdptr++)
{
switch (gsdptr->gsdtyp)
{
case 0: { /* module name */
rad50_to_ascii((struct r50name *)gsdptr); /* put ascii in token_pool */
current_fnd->fn_target = token_pool;
if (target == 0) target = token_pool;
token_pool += ++token_value;
token_pool_size -= token_value;
continue;
}
case 1: { /* CSECT name */
s = &((struct gsdflags *)gsdptr)->flags;
if (gsdptr->gsdnm0)
{
if (((struct gsdflags *)gsdptr)->gsdlong == 0x0F94AF01)
{
*s = 0x04; /* . ABS. section */
}
else
{
*s = 0x64; /* normal named .CSECT */
}
}
else
{
*s = 0x20; /* unnamed .CSECT */
}
} /* fall through to case 5 */
case 5: { /* PSECT name */
if ((noname = ((struct gsdflags *)gsdptr)->gsdlong) == 0)
{
strcpy(token_pool,"unnamed_");
token_value = 9;
}
else
{
rad50_to_ascii((struct r50name *)gsdptr); /* put ascii in token_pool */
*r50_lc++ = '_'; /* psect names are followed with an _ */
*r50_lc++ = ' '; /* and a trailing space */
*r50_lc = 0; /* so move the null */
token_value += 2; /* and add 2 to length */
if (gsdptr->gsdnm1 - gsdptr->gsdnm1 % 050 == 0xAF00)
{
*(token_pool+1) = '_'; /* ". x" changes to "._x" */
gsdptr->gflg_base = gsdptr->gflg_rel;
}
}
if (rsx_fd || output_mode == OUTPUT_OL) gsdptr->gflg_base = 0;
curr_seg = sym_ptr = new_sym(2);
curr_pc = 0;
if (noname == 0) no_name_seg = sym_ptr;
last_txt_org = last_txt_end = 0; /* reset the offset */
if (!chk_mdf(0,sym_ptr,0))
{
continue;
}
if ((seg_ptr=sym_ptr->seg_spec) == 0)
{
if ((seg_ptr=get_seg_spec_mem(sym_ptr)) == 0) continue;
}
sym_ptr->flg_defined = 1; /* .seg defines the segment */
sym_ptr->flg_segment = 1; /* signal its a segment */
sym_ptr->flg_ovr = gsdptr->gflg_ovr;
sym_ptr->flg_abs = ~gsdptr->gflg_rel;
seg_ptr->seg_salign = !gsdptr->gflg_dta; /* set the alignment factor */
seg_ptr->seg_dalign = 0; /* set data alignment factor */
seg_ptr->seg_len = (uint16_t)gsdptr->gsdvalue;
if (!(new_symbol & 4) && /* if not a duplicate symbol */
!sym_ptr->flg_member)
{ /* and not already a group member */
if (!gsdptr->gflg_rel)
{
if (abs_group == 0)
{
abs_group_nam = get_symbol_block(1);
abs_group_nam->ss_string = "Absolute_sections";
abs_group = get_grp_ptr(abs_group_nam,(int32_t)0,(int32_t)0);
abs_group_nam->ss_fnd = current_fnd;
abs_group_nam->flg_based = 1;
abs_group_nam->seg_spec->sflg_absolute = 1;
}
insert_intogroup(abs_group,sym_ptr,abs_group_nam);
}
if (gsdptr->gflg_base)
{
if (base_page_grp == 0)
{
base_page_nam = get_symbol_block(1);
base_page_nam->ss_string = "Zero_page_sections";
base_page_nam->ss_fnd = current_fnd;
base_page_grp = get_grp_ptr(base_page_nam,(int32_t)0,(int32_t)0);
base_page_nam->flg_based = 1;
base_page_nam->seg_spec->seg_maxlen = 256;
base_page_nam->seg_spec->sflg_zeropage = 1;
}
insert_intogroup(base_page_grp,sym_ptr,base_page_nam);
}
if (gsdptr->gflg_rel && !gsdptr->gflg_base)
{ /* else default */
insert_intogroup(group_list_top,sym_ptr,group_list_default);
}
}
if (new_symbol & 4)
{ /* if duplicate symbol */
fseg_ptr = first_symbol->seg_spec;
#if 0
if (!current_fnd->fn_rt11 &&
(!gsdptr->gflg_dta != fseg_ptr->seg_salign))
{
sprintf(emsg,
"Segment {%s} declared in %s with alignment of %d\n\t%s%s%s%d",
sym_ptr->ss_string,current_fnd->fn_buff,!gsdptr->gflg_dta,
"and is declared in ",first_symbol->ss_fnd->fn_buff,
" with alignment of ",fseg_ptr->seg_salign);
err_msg(MSG_WARN,emsg);
}
if (seg_ptr->seg_dalign != 0)
{
sprintf(emsg,
"Segment {%s} declared in %s with combin of %d\n\t%s%s%s%d",
sym_ptr->ss_string,current_fnd->fn_buff,0,"and is declared in ",
first_symbol->ss_fnd->fn_buff," with combin of ",
fseg_ptr->seg_dalign);
err_msg(MSG_WARN,emsg);
}
#endif
seg_ptr->seg_group = fseg_ptr->seg_group; /* same group */
}
psects[free_psect].ps_name = ((struct gsdflags *)gsdptr)->gsdlong;
psects[free_psect++].ps_ptr = sym_ptr;
continue;
}
case 2: { /* ISD is actually... */
if (current_fnd->fn_credate == null_string)
{ /* time/date if not already in */
i = ((((struct gsdtime *)gsdptr)->gsdtim1 << 16) +
((struct gsdtime *)gsdptr)->gsdtim0)/60;
sec = i % 60; /* get the seconds */
i /= 60; /* toss the seconds */
mn = i % 60; /* get the minutes */
mon = ((struct gsdtime *)gsdptr)->gsdmn-1;
sprintf(token_pool,"%02d-%s-%04d %02d:%02d:%02d",
((struct gsdtime *)gsdptr)->gsday,
months[mon],
((struct gsdtime *)gsdptr)->gsdyr+1972,
i/60,mn,sec);
current_fnd->fn_credate = token_pool;
i = strlen(token_pool) + 1;
token_pool += i;
token_pool_size -= i;
continue;
}
if (current_fnd->fn_xlator == null_string)
{ /* or xlator if not already in */
rad50_to_ascii((struct r50name *)gsdptr);
if ((i=((struct gsdxlate *)gsdptr)->gsderrors) != 0)
{
sprintf(token_pool+token_value," err=%d",i);
}
if ((i=((struct gsdxlate *)gsdptr)->gsdwarns) != 0)
{
sprintf(token_pool+token_value," wrn=%d",i);
}
i = strlen(token_pool) + 1;
current_fnd->fn_xlator = token_pool;
token_pool += i;
token_pool_size -= i;
continue;
}
continue;
}
case 3: continue; /* transfer address,ignore for now */
case 4: { /* Global symbol name */
rad50_to_ascii((struct r50name *)gsdptr); /* put ascii in token_pool */
sym_ptr = new_sym(1);
insert_id((int32_t)current_fnd->fn_max_id++,sym_ptr);
if (qual_tbl[QUAL_CROSS].preesnt)
do_xref_symbol(sym_ptr,gsdptr->gflg_def);
if (gsdptr->gflg_def)
{ /* if symbol being defined */
if (current_fnd->fn_stb)
{ /* symbol file? */
if (sym_ptr->flg_defined && /* old symbol must be defined */
sym_ptr->flg_abs && /* and absolute */
!gsdptr->gflg_rel && /* and new symbol must be abs */
sym_ptr->ss_value == gsdptr->gsdvalue)
{ /* and equal */
continue; /* ignore multiple defs if values == */
}
}
if (!chk_mdf(1,sym_ptr,0))
{
continue; /* nfg */
}
sym_ptr->flg_symbol = 1; /* its a symbol */
expr_stack[0].expr_code = EXPR_SYM; /* build an expression */
expr_stack[0].expr_value = gsdptr->gsdvalue;
if ((expr_stack[0].expr_ptr = curr_seg) == 0)
{ /* curr_seg offset + */
sprintf(emsg,"Bad object format. Unable to define {%s} in \"%s\"",
sym_ptr->ss_string,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
continue; /* don't define the symbol */
}
expr_stack_ptr = 1; /* stack is 1 item deep */
sym_ptr->flg_exprs = 1; /* defined with an expression */
write_to_symdef(sym_ptr); /* write symbol stuff */
sym_ptr->flg_defined = 1; /* set defined bit */
sym_ptr->flg_nosym = current_fnd->fn_nosym;
}
continue;
}
case 6: continue; /* GSD ident */
case 7: continue; /* Mapped array declaration */
case 8: continue; /* completion routine declaration */
default: {
sprintf(emsg,"Illegal GSD type: %d in file \"%s\"",
gsdptr->gsdtyp,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
} /* default */
} /* switch */
} /* for */
} /* do_gsd */
struct ss_struct *get_psect( char *strng )
{
uint32_t psname;
struct ss_struct *sym_ptr;
int i;
if ((psname = *obj.rldlong++) == 0)
{ /* pick up the rad50 name */
sym_ptr = no_name_seg;
}
else
{
sym_ptr = 0; /* assume failure */
for (i=0;i<free_psect;i++)
{
if (psname == psects[i].ps_name)
{
sym_ptr = psects[i].ps_ptr;
break;
}
}
if (sym_ptr == 0)
{
rad50_to_ascii(obj.rldnam-1);
sprintf(emsg,"%s to undefined segment {%s} in file \"%s\"",
strng,token_pool,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
}
}
return(sym_ptr);
}
static void back_patch( int disp )
{
expr_stack[0].expr_code = EXPR_SYM; /* insert expression "curr_seg const +" */
expr_stack[0].expr_ptr = curr_seg;
expr_stack[0].expr_value = curr_pc = disp + last_txt_org;
write_to_tmp(TMP_ORG,1l,(char *)expr_stack,sizeof(struct expr_token));
return;
}
static char mode_chars[] = "wWbb"; /* storage modes */
static void do_rld( int len )
{
int mode = 0,disp,type,cnst;
struct ss_struct *sym_ptr;
struct expr_token *exp;
for (;len > 0;len -= 2)
{
exp = expr_stack;
type = obj.rld->rldtyp;
mode = obj.rld->rldmode; /* 0:tag w; 1=tag W; 2=tag b; 3=tag b */
disp = (obj.rld++)->rlddsp - 4;
if (type < 7 || type > 9)
{
back_patch(disp);
curr_pc += (mode > 1)? 1 : 2;
}
switch (type)
{
case 1: { /* internal relocation (.word addr) */
if ((mode & 1) != 0)
{
char t;
t = *obj.complex; /* bug in MACxx, swap the bytes in value */
*obj.complex = *(obj.complex+1);
*(obj.complex+1) = t;
}
if (mode & 2) *obj.rldval = *obj.complex; /* sign extend */
expr_stack[0].expr_code = EXPR_SYM;
expr_stack[0].expr_ptr = curr_seg; /* compute "curr_seg constant +" */
expr_stack[0].expr_value = *obj.rldval++;
write_to_tmp(TMP_EXPR,1l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 2; /* adjust for constant */
break; /* done */
}
case 10: { /* psect relocation (same as global) */
if ((sym_ptr = get_psect("Psect relocation")) == 0)
{
len -= 4;
break;
}
}
case 2: { /* Global relocation ".word global" */
if (type == 2)
{
rad50_to_ascii(obj.rldnam++);
if ((sym_ptr = sym_lookup(token_pool,++token_value,0)) == 0)
{
sprintf(emsg,"Undefined symbol {%s} found in file \"%s\"",
token_pool,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
len -= 4; /* adjust for symbol */
break; /* done */
}
}
expr_stack[0].expr_code = EXPR_SYM;
expr_stack[0].expr_ptr = sym_ptr; /* compute "symbol 0 +" */
expr_stack[0].expr_value = 0;
write_to_tmp(TMP_EXPR,1l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 4; /* adjust for symbol */
break; /* done */
}
case 3: { /* internal displaced "clr abs_address" */
if ((mode & 1) != 0)
{
char t;
t = *obj.complex; /* bug in MACxx, swap the bytes in value */
*obj.complex = *(obj.complex+1);
*(obj.complex+1) = t;
}
if (mode & 2) *obj.rldval = *obj.complex; /* sign extend */
expr_stack[0].expr_code = EXPR_SYM;
expr_stack[0].expr_ptr = curr_seg; /* compute "constant curr_seg 2 + -" */
expr_stack[0].expr_value = -(*obj.rldval++ - 2); /* absolute address */
expr_stack[1].expr_code = EXPR_OPER;
expr_stack[1].expr_value = EXPROPER_NEG;
write_to_tmp(TMP_EXPR,2l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 2; /* adjust for constant */
break; /* done */
}
case 12: { /* psect displaced (same as global) */
if ((sym_ptr = get_psect("Psect displaced relocation")) == 0)
{
len -= 4;
break;
}
}
case 4: { /* global displaced "clr global" */
if (type == 4)
{
rad50_to_ascii(obj.rldnam++);
if ((sym_ptr = sym_lookup(token_pool,++token_value,0)) == 0)
{
sprintf(emsg,"Undefined symbol {%s} found in file \"%s\"",
token_pool,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
len -= 4; /* adjust for symbol */
break; /* done */
}
}
exp->expr_code = EXPR_SYM;
exp->expr_ptr = sym_ptr; /* compute "symbol curr_seg n + -" */
exp->expr_value = 0;
(++exp)->expr_code = EXPR_SYM;
exp->expr_ptr = curr_seg;
exp->expr_value = 1 + (mode < 2);
(++exp)->expr_code = EXPR_OPER;
exp->expr_value = '-';
write_to_tmp(TMP_EXPR,3l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 4; /* adjust for symbol */
break; /* done */
}
case 13: { /* psect additive (same as global) */
if ((sym_ptr = get_psect("Psect additive relocation")) == 0)
{
len -= 6;
obj.rldval++; /* skip the value */
break;
}
}
case 5: { /* global additive ".word global+n" */
if (type == 5)
{
rad50_to_ascii(obj.rldnam++);
if ((sym_ptr = sym_lookup(token_pool,++token_value,0)) == 0)
{
sprintf(emsg,"Undefined symbol {%s} found in file \"%s\"",
token_pool,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
obj.rldval++; /* skip the value */
len -= 6; /* adjust for symbol */
break; /* done */
}
}
if ((mode & 1) != 0)
{
char t;
t = *obj.complex; /* bug in MACxx, swap the bytes in value */
*obj.complex = *(obj.complex+1);
*(obj.complex+1) = t;
}
if (mode & 2) *obj.rldval = *obj.complex; /* sign extend */
cnst = *obj.rldval++; /* pick up the constant */
exp->expr_code = EXPR_SYM;
exp->expr_ptr = sym_ptr; /* compute "symbol const +" */
exp->expr_value = cnst;
write_to_tmp(TMP_EXPR,1l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 6; /* adjust for symbol */
break; /* done */
}
case 14: { /* psect additive displaced (same as global) */
if ((sym_ptr = get_psect("Psect additive displaced relocation")) == 0)
{
len -= 6;
obj.rldval++; /* skip the value */
break;
}
}
case 6: { /* global additive displaced "clr global+n" */
if (type == 6)
{
rad50_to_ascii(obj.rldnam++);
if ((sym_ptr = sym_lookup(token_pool,++token_value,0)) == 0)
{
sprintf(emsg,"Undefined symbol {%s} found in file \"%s\"",
token_pool,current_fnd->fn_buff);
err_msg(MSG_ERROR,emsg);
obj.rldval++; /* skip the value */
len -= 6; /* adjust for symbol and constant */
break; /* done */
}
}
if ((mode & 1) != 0)
{
char t;
t = *obj.complex; /* bug in MACxx, swap the bytes in value */
*obj.complex = *(obj.complex+1);
*(obj.complex+1) = t;
}
if (mode & 2) *obj.rldval = *obj.complex; /* sign extend */
cnst = *obj.rldval++; /* pick up the constant */
exp->expr_code = EXPR_SYM;
exp->expr_ptr = sym_ptr; /* compute "symbol curr_seg 2 + -" */
exp->expr_value = cnst - ((mode > 2) ? 2 : 1);
(++exp)->expr_code = EXPR_SYM;
exp->expr_ptr = curr_seg;
exp->expr_value = 0;
(++exp)->expr_code = EXPR_OPER;
exp->expr_value = '-';
write_to_tmp(TMP_EXPR,3l,(char *)expr_stack,sizeof(struct expr_token));
write_to_tmp(TMP_TAG,1l,&mode_chars[mode],1);
len -= 6; /* adjust for symbol and constant */
break; /* done */
}
case 7: { /* location counter definition */
if ((sym_ptr = get_psect("Attempt to set PC")) == 0)
{
len -= 6;
obj.rldval++; /* skip the value */
break;
}
cnst = *obj.rldval++; /* pick up the constant */
exp->expr_code = EXPR_SYM;
exp->expr_ptr = curr_seg = sym_ptr; /* compute "seg const +" */
exp->expr_value = curr_pc = cnst & 65535;
write_to_tmp(TMP_ORG,1l,(char *)expr_stack,sizeof(struct expr_token));
len -= 6; /* adjust for symbol */
break; /* done */
}
case 8: { /* pc modification ".blkb n" */
exp->expr_code = EXPR_SYM;
exp->expr_ptr = curr_seg; /* compute "curr_seg constant +" */
exp->expr_value = curr_pc = *obj.rldval++ & 65535;
write_to_tmp(TMP_ORG,1l,(char *)expr_stack,sizeof(struct expr_token));
len -= 2; /* adjust for constant */
break;
}
case 9: break; /* program limits ".LIMIT" */
case 11: { /* .vctrs */
if ((sym_ptr = get_psect(".VCTRS set PC")) == 0)
{
len -= 6;
obj.rldval++; /* skip the value */
break;
}
if ((mode & 1) != 0)
{
char t;
t = *obj.complex; /* bug in MACxx, swap the bytes in value */
*obj.complex = *(obj.complex+1);
*(obj.complex+1) = t;
}
cnst = *obj.rldval++; /* pick up the constant */
exp->expr_code = EXPR_SYM;
exp->expr_ptr = curr_seg = sym_ptr; /* compute "seg const +" */
exp->expr_value = curr_pc = cnst & 65535;
write_to_tmp(TMP_ORG,1l,(char *)expr_stack,sizeof(struct expr_token));
len -= 6; /* adjust for symbol */
break; /* done */
}
case 15: { /* complex */
for (type=0;--len >= 2;)
{
int tc;
tc = *obj.complex;
switch (tc)
{
case 0: continue; /* nop */
case 1: /* + (addition) */
tc = EXPROPER_ADD;
goto common_complex;
case 2: /* - (subtraction) */
tc = EXPROPER_SUB;
goto common_complex;
case 3: /* * (multiplication) */
tc = EXPROPER_MUL;
goto common_complex;
case 4: /* / (division) */
tc = EXPROPER_DIV;
goto common_complex;
case 5: /* & (logical and) */
tc = EXPROPER_AND;
goto common_complex;
case 6: /* | (logical or) */
tc = EXPROPER_OR;
goto common_complex;
case 7: /* ^ (exclusive or) */
tc = EXPROPER_XOR;
goto common_complex;
case 8: /* _ (negate) */
tc = EXPROPER_NEG;
goto common_complex;
case 9: /* ~ (compliment) */
tc = EXPROPER_COM;
goto common_complex;
case 12: /* ? (unsigned divide */
tc = EXPROPER_USD;
goto common_complex;
case 13: /* = (swap bytes) */
tc = EXPROPER_SWAP;
goto common_complex;
case 19: /* \ (modulo) */
tc = EXPROPER_MOD;
goto common_complex;
case 21: /* < (shift left) */
tc = EXPROPER_SHL;
goto common_complex;
case 22: { /* > (shift right) */
tc = EXPROPER_SHR;
goto common_complex;
common_complex:
type++; /* record 1 item on the stack */
exp->expr_value = tc;
(exp++)->expr_code = EXPR_OPER;
continue;
}
case 10: { /* store immediate */
if (!type) break; /* nothing to write */