-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathendlin.c
More file actions
1469 lines (1433 loc) · 41.9 KB
/
Copy pathendlin.c
File metadata and controls
1469 lines (1433 loc) · 41.9 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
/*
endlin.c - Part of macxx, a cross assembler family for various micro-processors
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/>.
*/
#include "outx.h"
#include "listctrl.h"
#include "memmgt.h"
#include <stdlib.h> /* Get proto for abort() */
#include "header.h"
#if !defined(M_UNIX)
#define MISER (options[QUAL_MISER])
#define NOT_MISER (!options[QUAL_MISER])
#else
#define MISER (0)
#define NOT_MISER (1)
#endif
static char out_buf[72]; /* place to hold tmp data */
SEG_struct *out_seg; /* segment in which data is placed */
int32_t out_pc; /* expected PC of data */
static char *out_indx = out_buf; /* pointer to next spot in out_buf */
static int out_remaining; /* # of bytes remaining in buffer */
static short tmp_length;
static TMP_struct rtmp;
TMP_struct *tmp_next=NULL,*tmp_top=NULL,*tmp_pool=NULL,*tmp_ptr=NULL;
static int tmp_pool_size;
int32_t tmp_pool_used;
EXPR_struct tmp_org;
EXP_stk tmp_org_exp;
void clear_outbuf(void)
{
out_pc = 0;
out_seg = NULL;
out_indx = out_buf;
out_remaining = sizeof(out_buf);
tmp_org_exp.stack = &tmp_org;
tmp_org_exp.ptr = 1;
tmp_org.expr_code = EXPR_SEG;
tmp_org.expr_value = 0;
}
#if defined(DEBUG)
static struct
{
int typ;
char *name;
} tmp_types[] = {
{TMP_NUM,"TMP_NUM"},
{TMP_NNUM,"TMP_NNUM"},
{TMP_SIZE,"TMP_SIZE"},
{TMP_ZERO,"TMP_ZERO"},
{TMP_B8,"TMP_B8"},
{TMP_B16,"TMP_B16"},
{TMP_B32,"TMP_B32"},
{TMP_EOF,"TMP_EOF"},
{TMP_EXPR,"TMP_EXPR"},
{TMP_ASTNG,"TMP_ASTNG"},
{TMP_TEST,"TMP_TEST"},
{TMP_BOFF,"TMP_BOFF"},
{TMP_OOR,"TMP_OOR"},
{TMP_FILE,"TMP_FILE"},
{TMP_ORG,"TMP_ORG"},
{TMP_START,"TMP_START"},
{TMP_BSTNG,"TMP_BSTNG"},
{TMP_SCOPE,"TMP_SCOPE"},
{TMP_STAB,"TMP_STAB"},
{TMP_LINK,"TMP_LINK"},
{EXPR_RELMD,"EXPR_RELMD"},
{EXPR_SYM,"EXPR_SYM"},
{EXPR_VALUE,"EXPR_VALUE"},
{EXPR_OPER,"EXPR_OPER"},
{EXPR_L,"EXPR_L"},
{EXPR_B,"EXPR_B"},
{EXPR_TAG,"EXPR_TAG"},
{EXPR_IDENT,"EXPR_IDENT"},
{EXPR_SEG,"EXPR_SEG"},
{EXPR_LINK,"EXPR_LINK"},
{0,0}};
static char *sho_type(int typ)
{
int i;
for (i=0;tmp_types[i].name;++i)
{
if (tmp_types[i].typ == typ) return tmp_types[i].name;
}
return "undefined";
}
#endif
static char *sqz_it( char *src, int typ, int cnt, int siz)
{
#if !defined(M_UNIX)
union
{
char *b8;
short *b16;
int32_t *b32;
EXP_stk **stkp;
SEG_struct **segp;
FN_struct **fnp;
int32_t l;
} sqz;
register int32_t value;
register int itz;
#ifdef DEBUG
fprintf(stderr,"SQZ'ing typ %s(0x%0X) having %d items with a size of %d from %08X\n",
sho_type(typ),typ,cnt,siz,src);
#endif
sqz.b8 = ((char *)tmp_pool)+1; /* leave room for type code */
ADJ_ALIGN(sqz.b8)
*sqz.b16++ = current_fnd->fn_line; /* insert the current line number */
switch (typ)
{ /* and test for type */
case TMP_FILE: {
*sqz.fnp++ = *(FN_struct **)src;
break;
}
case TMP_SCOPE: {
*sqz.b16++ = *src;
break;
}
case TMP_EOF: break; /* this is easy */
case TMP_ASTNG: /* these are strings */
case TMP_BSTNG: {
itz = cnt*siz;
if ((value = itz) != 0)
{
if (itz < 0) value = -itz;
if (value < 128)
{
*sqz.b8++ = value;
typ |= TMP_B8;
}
else
{
ADJ_ALIGN(sqz.b8)
*sqz.b16++ = value;
typ |= TMP_B16;
}
}
memcpy(sqz.b8,src,itz); /* move the items */
sqz.b8 += itz; /* adjust the pointer */
break; /* done */
}
case TMP_EXPR:
case TMP_ORG:
case TMP_TEST:
case TMP_BOFF:
case TMP_OOR:
case TMP_START: {
register EXPR_struct *texp;
register EXP_stk *eps;
eps = (EXP_stk *)src;
*sqz.b8++ = eps->ptr; /* stack pointer */
*sqz.b8++ = (eps->base_page_reference<<2) |
(eps->forward_reference<1) |
(eps->register_reference);
ADJ_ALIGN(sqz.b8)
*sqz.b16++ = eps->tag;
if (eps->tag != 0) *sqz.b16++ = eps->tag_len;
texp = eps->stack;
while (cnt--)
{ /* do all the elements */
#if defined(DEBUG)
fprintf(stderr,"\tsqzing item %s(0x%0X) at %p\n",sho_type(texp->expr_code),texp->expr_code,sqz.b8);
#endif
switch (texp->expr_code)
{
case EXPR_OPER: {
*sqz.b8++ = EXPR_OPER | TMP_NNUM;
*sqz.b8++ = (char)texp->expr_value;
if ((texp->expr_value&255) == EXPROPER_TST)
{
*sqz.b8++ = texp->expr_value >> 8;
}
break;
}
case EXPR_VALUE: {
uint32_t val;
if (texp->expr_value >= 0)
{
val = texp->expr_value;
}
else
{
val = -texp->expr_value;
}
if (val < 64)
{
*sqz.b8++ = (char)(texp->expr_value & TMP_NUM);
break;
}
if (val < 128)
{
*sqz.b8++ = EXPR_VALUE|TMP_B8|TMP_NNUM;
*sqz.b8++ = (char)texp->expr_value;
break;
}
if (val < 32768)
{
*sqz.b8++ = EXPR_VALUE|TMP_B16|TMP_NNUM;
ADJ_ALIGN(sqz.b8)
*sqz.b16++ = (short)texp->expr_value;
break;
}
*sqz.b8++ = EXPR_VALUE|TMP_B32|TMP_NNUM;
ADJ_ALIGN(sqz.b8)
*sqz.b32++ = texp->expr_value;
break;
}
case EXPR_IDENT: {
*sqz.b8++ = texp->expr_code|TMP_NNUM|TMP_B32;
ADJ_ALIGN(sqz.b8)
*sqz.b32++ = texp->expr_value;
break;
}
case EXPR_LINK: {
*sqz.b8++ = texp->expr_code|TMP_NNUM|TMP_B32;
ADJ_ALIGN(sqz.b8)
*sqz.segp++ = texp->expr_seg;
break;
}
case EXPR_L:
case EXPR_B:
case EXPR_SEG:
case EXPR_SYM: {
int t = TMP_B32|TMP_NNUM;
if (texp->expr_expr != (EXP_stk *)0)
{
t = TMP_B32|TMP_NNUM|EXPR_RELMD;
}
t |= texp->expr_code;
*sqz.b8++ = t;
ADJ_ALIGN(sqz.b8)
*sqz.b32++ = texp->expr_value;
if ((t & EXPR_RELMD) != 0)
{
ADJ_ALIGN(sqz.b8)
*sqz.b32++ = texp->expr_count;
} /* -- RELMD */
} /* -- case */
default: break;
} /* -- switch expr_code */
++texp;
} /* -- while expr */
} /* -- case TMP_EXPR */
} /* -- switch TMP_TYPE */
tmp_pool->tf_type = typ; /* stuff in the typ code */
#ifdef DEBUG
fprintf(stderr,"\tSquoze from %08X to %08X\n",tmp_pool,sqz.b8);
#endif
return(sqz.b8);
#else
fprintf(stderr,"\tSqzit not configured\n");
abort();
return 0;
#endif
}
static char *unsqz_it( char *src )
{
#if !defined(M_UNIX)
union
{
char *b8;
short *b16;
int32_t *b32;
unsigned char *u8;
uint16_t *u16;
uint32_t *u32;
TMP_struct *tsp;
EXP_stk **expp;
SS_struct **symp;
FN_struct **fnp;
int32_t l;
} sqz;
int typ,i;
#ifdef DEBUG
fprintf(stderr,"UNSQZ'ing from %08X\n",src);
#endif
tmp_ptr = &rtmp; /* point to local tmp_struct */
rtmp.tf_length = 0; /* assume a length of 0 */
sqz.b8 = src; /* setup the squeezer */
rtmp.tf_type = (typ = *sqz.b8++) & ~TMP_SIZE;
ADJ_ALIGN(sqz.b8)
rtmp.line_no = *sqz.b16++; /* pickup the line number */
#if defined(DEBUG)
fprintf(stderr,"\ttype %s(0x%0X) from line %d\n",sho_type(rtmp.tf_type),rtmp.tf_type,rtmp.line_no);
#endif
switch (rtmp.tf_type)
{ /* and test for type */
default: {
sprintf(emsg,"Illegal 'sqz' code of %02X",rtmp.tf_type);
err_msg(MSG_FATAL,emsg);
EXIT_FALSE;
}
case TMP_FILE: { /* change of file */
current_fnd = *sqz.fnp++;
break;
}
case TMP_SCOPE: { /* change of scope */
current_scope = *sqz.b16++;
current_procblk = current_scope&SCOPE_PROC;
current_scopblk = current_scope&~SCOPE_PROC;
break;
}
case TMP_EOF: {
#ifdef DEBUG
fprintf(stderr,"\tUNSQUOZE eof message at location %08X\n",
src);
#endif
break;
}
case TMP_ASTNG: /* these are strings */
case TMP_BSTNG: {
typ &= TMP_SIZE;
switch (typ)
{
case TMP_ZERO: break;
case TMP_B8: {
rtmp.tf_length = *sqz.b8++;
break;
}
case TMP_B16: {
ADJ_ALIGN(sqz.b8)
rtmp.tf_length = *sqz.b16++;
break;
}
case TMP_B32: {
ADJ_ALIGN(sqz.b8)
rtmp.tf_length = *sqz.b32++;
break;
}
}
tmp_pool = sqz.tsp;
#ifdef DEBUG
fprintf(stderr,"\tUNSQUOZE %d byte string. type = %0X, from %p to %p\n",
rtmp.tf_length,rtmp.tf_type,src,sqz.b8+rtmp.tf_length);
#endif
sqz.b8 += rtmp.tf_length;
break;
}
case TMP_EXPR:
case TMP_ORG:
case TMP_BOFF:
case TMP_OOR:
case TMP_TEST:
case TMP_START: {
register EXPR_struct *texp;
int cnt;
EXP0.ptr = *sqz.u8++;
cnt = *sqz.b8++;
EXP0.base_page_reference = (cnt>>2) & 1;
EXP0.forward_reference = (cnt>1) & 1;
EXP0.register_reference = cnt &1;
ADJ_ALIGN(sqz.b8)
if ((EXP0.tag = *sqz.u16++) != 0) EXP0.tag_len = *sqz.u16++;
texp = EXP0.stack; /* point to expression stack 0 */
cnt = EXP0.ptr;
#if defined(DEBUG)
fprintf(stderr,"\tunsqzing %d items into exprs stack from %p\n",cnt,sqz.b8);
#endif
for (;cnt;--cnt,++texp)
{ /* do all the elements */
int relmod;
i = *sqz.b8++ & 0xFF; /* pickup the type code */
#if defined(DEBUG)
fprintf(stderr,"\t\tunsqzing item %d: %s(0x%0X) at %p\n",cnt,sho_type(i),i,sqz.b8);
#endif
if ((i & TMP_NNUM) == 0)
{
texp->expr_code = EXPR_VALUE; /* type is abs value */
if (i & (TMP_NNUM/2)) i |= -TMP_NNUM; /* sign extend */
texp->expr_value = i;
continue;
}
texp->expr_code = i & ~(TMP_SIZE|EXPR_RELMD|TMP_NNUM);
texp->expr_seg = (SEG_struct *)0;
relmod = i & EXPR_RELMD;
i &= TMP_SIZE;
switch (texp->expr_code)
{
case EXPR_OPER: {
texp->expr_value = *sqz.b8++; /* get the operator character */
if ((texp->expr_value&255) == EXPROPER_TST)
{
texp->expr_value |= *sqz.b8++ << 8;
}
continue;
}
case EXPR_IDENT:
case EXPR_VALUE: {
switch (i)
{
case TMP_ZERO: {
texp->expr_value = 0;
continue;
}
case TMP_B8: {
texp->expr_value = *sqz.b8++;
continue;
}
case TMP_B16: {
ADJ_ALIGN(sqz.b8)
texp->expr_value = *sqz.b16++;
continue;
}
case TMP_B32: {
ADJ_ALIGN(sqz.b8)
texp->expr_value = *sqz.b32++;
continue;
}
}
}
case EXPR_L:
case EXPR_B:
case EXPR_SEG:
case EXPR_SYM: {
ADJ_ALIGN(sqz.b8)
texp->expr_value = *sqz.b32++;
if (relmod)
{
ADJ_ALIGN(sqz.b8)
texp->expr_sym = *sqz.symp++;
}
continue;
} /* -- case */
case EXPR_LINK: {
ADJ_ALIGN(sqz.b8)
texp->expr_expr = *sqz.expp++;
texp->expr_value = 0;
continue;
} /* -- case */
default: continue; /* this keeps gcc happy */
} /* -- switch expr_code */
} /* -- for() expr */
} /* -- case TMP_EXPR */
} /* -- switch TMP_TYPE */
#ifdef DEBUG
fprintf(stderr,"\tUNSQUOZE %d items into exprs_stack[0] from %p to %p\n",
exprs_stack[0].ptr,src,sqz.b8);
#endif
current_fnd->fn_line = rtmp.line_no;
return(sqz.b8);
#else
fprintf(stderr,"\nUnsqzit not configured\n");
abort();
return 0;
#endif
}
/********************************************************************
* Write a bunch of data to the temp file
*/
void write_to_tmp(int typ, int itm_cnt, void *itm_ptr, int itm_siz)
/*
* At entry:
* typ - TMP_xxx value id'ing the block data
* itm_cnt - number of items to write
* itm_ptr - pointer to items to write (or tag character)
* itm_siz - size in bytes of each item (or tag number)
* At exit:
* data written to temp file (exits to VMS if error)
*/
{
union
{
void *v;
char *c;
int32_t *l;
TMP_struct *t;
EXP_stk *txp;
int32_t lng;
} src,dst,tmp; /* mem pointers */
int itz;
int class = 0;
if (!pass || !output_files[OUT_FN_OBJ].fn_present)
return; /* nuthin' to do if no output */
if (tmp_pool_size == 0)
{
tmp_pool_size = max_token*8; /* get some memory */
tmp_pool_used += max_token*8;
tmp_pool = (TMP_struct *)MEM_alloc(tmp_pool_size);
tmp_top = tmp_pool; /* remember where the top starts */
}
src.v = itm_ptr;
tmp.t = tmp_pool;
ADJ_ALIGN(tmp.c)
if (typ == TMP_EXPR || typ == TMP_START || typ == TMP_ORG ||
typ == TMP_TEST || typ == TMP_BOFF || typ == TMP_OOR) class = 1;
if (class != 0)
{
itm_cnt = src.txp->ptr;
itm_siz = sizeof(EXPR_struct);
itz = itm_cnt*sizeof(EXPR_struct) + sizeof(EXP_stk);
}
else
{
itz = itm_cnt*itm_siz;
}
if (tmp_fp == 0 )
{
int tsiz;
tsiz = 2*sizeof(TMP_struct) + itz;
if (tmp_pool_size < tsiz)
{
if (tsiz < max_token*8) tsiz = max_token*8;
tmp.t->tf_type = TMP_LINK; /* link to a new area */
tmp.t->tf_link = (TMP_struct *)MEM_alloc(tsiz);
tmp_pool_used += tsiz;
tmp_pool_size = tsiz;
tmp_pool = tmp.t->tf_link;
tmp.t = tmp_pool;
}
if NOT_MISER
{
dst.t = tmp.t+1;
tmp.t->tf_type = typ; /* set the type */
tmp.t->line_no = current_fnd->fn_line;
if (class != 0)
{
tmp.t->tf_length = itz+sizeof(TMP_struct);
dst.txp->ptr = src.txp->ptr;
dst.txp->tag = src.txp->tag;
dst.txp->tag_len = src.txp->tag_len;
dst.txp->base_page_reference = src.txp->base_page_reference;
dst.txp->forward_reference = src.txp->forward_reference;
dst.txp->register_reference = src.txp->register_reference;
dst.txp->stack = (EXPR_struct *)(dst.txp+1);
++dst.txp;
src.c = (char *)src.txp->stack;
itz -= sizeof(EXP_stk);
}
else
{
tmp.t->tf_length = itm_cnt; /* set the item count */
}
if (itz != 0) memcpy(dst.c,src.c,itz);
dst.c += itz;
ADJ_ALIGN(dst.c)
}
else
{
dst.c = sqz_it((char *)itm_ptr,typ,itm_cnt,itm_siz);
ADJ_ALIGN(dst.c)
}
tmp_pool_size -= dst.c - tmp.c;
tmp_pool = dst.t; /* update pointer */
}
else
{
int t;
dst.c = sqz_it((char *)itm_ptr,typ,itm_cnt,itm_siz);
tmp_length = dst.c - (char *)tmp_top;
t = fwrite(&tmp_length,sizeof(tmp_length),1,tmp_fp);
if (t != 1)
{
sprintf(emsg,"%%%s-F-FATAL, Tried to fwrite " FMT_SZ " bytes (1 elem) to tmp_file, wrote " FMT_SZ ".\n\t",
macxx_name,sizeof(tmp_length),t*sizeof(tmp_length));
perror(emsg);
EXIT_FALSE;
}
t = fwrite(tmp_top,(int)tmp_length,1,tmp_fp);
if (t != 1)
{
sprintf(emsg,"%%%s-F-FATAL, Tried to fwrite %d bytes (1 elem) to tmp_file, wrote %d.\n\t",
macxx_name,tmp_length,t*tmp_length);
perror(emsg);
EXIT_FALSE;
}
}
return;
}
/**********************************************************************
* Read a bunch of data from tmp file
*/
int read_from_tmp( void )
/*
* At entry:
* At exit:
*/
{
TMP_struct *ts;
char *tmps;
int code;
if (tmp_fp != 0)
{
int t;
t = fread(&tmp_length,sizeof(tmp_length),1,tmp_fp);
if (t != 1)
{
sprintf(emsg,"%%%s-F-FATAL, Tried to fread " FMT_SZ " bytes (1 elem) from tmp_file, actually read " FMT_SZ ".\n\t",
macxx_name,sizeof(tmp_length),t*sizeof(tmp_length));
perror(emsg);
EXIT_FALSE;
}
t = fread(tmp_top,(int)tmp_length,1,tmp_fp);
tmp_next = (TMP_struct *)unsqz_it( (char *)tmp_top ); /* unpack the text */
return( rtmp.tf_type );
}
else
{
#if ALIGNMENT
tmps = (char *)tmp_next;
ADJ_ALIGN(tmps)
ts = (TMP_struct *)tmps;
#else
ts = tmp_next; /* point to next tmp element */
#endif
if (ts->tf_type == TMP_LINK)
{
int ferr;
ts = tmp_next = ts->tf_link;
ferr = MEM_free((char *)tmp_top);
#if !defined(SUN)
if (ferr)
{ /* give back the memory */
sprintf(emsg,"Error (%08X) free'ing %d bytes at %p from tmp_pool",
ferr, max_token*8, (void *)tmp_top);
err_msg(MSG_WARN,emsg);
}
#endif
tmp_top = ts; /* point to next top */
}
tmp_ptr = ts; /* point to tmp pointer */
if MISER
{
#if ALIGNMENT
tmps = unsqz_it(tmp_ptr); /* unpack the text */
ADJ_ALIGN(tmps)
tmp_next = (TMP_struct *)tmps;
#else
tmp_next = (TMP_struct *)unsqz_it( (char*)tmp_ptr); /* unpack the text */
#endif
return(rtmp.tf_type);
}
else
{
++ts;
tmps = (char *)ts;
tmp_pool = ts;
code = tmp_ptr->tf_type;
switch (code)
{
case TMP_FILE: {
union
{
uint32_t lng;
char *cp;
FN_struct **fnp;
TMP_struct *tp;
} src;
src.tp = tmp_ptr+1;
current_fnd = *src.fnp++;
tmp_next = src.tp;
break;
}
case TMP_SCOPE: {
union
{
uint16_t *scope;
TMP_struct *tp;
} src;
src.tp = tmp_ptr+1;
current_scope = *src.scope++;
current_procblk = current_scope&SCOPE_PROC;
current_scopblk = current_scope&~SCOPE_PROC;
tmp_next = src.tp;
break;
}
case TMP_START:
case TMP_EXPR:
case TMP_BOFF:
case TMP_OOR:
case TMP_TEST:
case TMP_ORG: {
union
{
EXP_stk *eps;
TMP_struct *tp;
unsigned char *cp;
uint32_t lng;
} src;
int l;
src.tp = tmp_ptr+1;
EXP0.ptr = src.eps->ptr;
EXP0.tag = src.eps->tag;
EXP0.tag_len = src.eps->tag_len;
EXP0.register_reference = src.eps->register_reference;
EXP0.base_page_reference = src.eps->base_page_reference;
EXP0.forward_reference = src.eps->forward_reference;
l = src.eps->ptr*sizeof(EXPR_struct);
memcpy(EXP0.stack,src.eps->stack,l);
src.eps += 1;
src.cp += l;
ADJ_ALIGN(src.cp)
tmp_next = src.tp;
break;
}
case TMP_BSTNG:
case TMP_ASTNG: {
tmps += tmp_ptr->tf_length;
ADJ_ALIGN(tmps)
tmp_next = (TMP_struct *)tmps;
break;
} /* -- case */
} /* -- switch */
current_fnd->fn_line = tmp_ptr->line_no;
} /* -- if miser */
} /* -- if fp */
return(code);
}
void rewind_tmp()
{
if (tmp_fp)
{
#ifdef VMS
if (fseek(tmp_fp,0,0))
{ /* rewind temp file */
perror("Unable to rewind tmp file");
EXIT_FALSE;
}
#else
fclose(tmp_fp); /* close the temp file */
if ((tmp_fp = fopen(output_files[OUT_FN_TMP].fn_buff,"rb")) == 0)
{
sprintf(emsg,"%%%s-F-FATAL, Unable to open %s for input\n\t",
macxx_name,output_files[OUT_FN_TMP].fn_buff);
perror (emsg);
EXIT_FALSE;
}
#endif
}
else
{
tmp_next = tmp_top;
}
return;
}
static void ide_trunc_err( int32_t mask, int32_t tv)
{
int tsiz,sev=MSG_WARN;
int32_t toofar=0;
char lclTxt[256];
int lclTxtLen;
char *fm,*em="%s:%d: ";
if ( options[QUAL_OCTAL] )
{
if (mask > 255)
{
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt), "Truncation at {%s}+0%06o. Wanted: 0%010o, output: 0%06o",
current_section->seg_string,current_offset,
tv,
tv&mask);
}
else
{
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt),"Truncation at {%s}+0%06o. Wanted: 0%010o, output: 0%03o",
current_section->seg_string,current_offset,
tv,
tv&mask);
}
}
else
{
if (mask > 255 && mask != 65534)
{
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt),"Truncation at {%s}+0x%04X. Wanted: 0x%08X, output: 0x%04X",
current_section->seg_string,current_offset,
tv,
tv&mask);
}
else
{
int range = 127;
if (mask == 254 || mask == 65534)
{
toofar = tv;
if (toofar == 0)
{
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt),"Branch offset of 0x%02X is illegal at {%s}+0x%04X",
toofar,
current_section->seg_string,current_offset
);
}
else
{
if (mask == 65534)
range = 65535;
if (toofar > 0)
{
toofar -= range;
}
else
{
toofar = -toofar-(range+1);
}
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt),"Branch offset 0x%02X out of range at {%s}+0x%04X",
toofar,
current_section->seg_string,current_offset
);
}
sev = MSG_ERROR; /* branch fail is ERROR */
}
else
{
lclTxtLen = snprintf(lclTxt,sizeof(lclTxt),"Truncation at {%s}+0x%04X. Wanted: 0x%08X, output: 0x%02X",
current_section->seg_string,current_offset,
tv,
tv&mask
);
}
}
}
tsiz = strlen(current_fnd->fn_buff)+10+lclTxtLen+strlen(em)+1;
fm = MEM_alloc(tsiz);
if ( fm )
{
snprintf(fm,tsiz,"%s:%d: %s: %s\n",
current_fnd->fn_nam->relative_name,
current_fnd->fn_line,
sev == MSG_ERROR ? "error":"warn",
lclTxt
);
if (pass > 1)
{
err_msg(sev|MSG_NO_EXTRA,fm);
}
else
{
show_bad_token((char *)0,fm,sev|MSG_NO_EXTRA);
}
MEM_free(fm);
}
return;
}
/**********************************************************************
* Display truncation error
*/
void trunc_err( int32_t mask, int32_t tv)
/*
* At entry:
* mask - mask to compare against
* tv - requested value to write
* current_pc - current location counter
*/
{
char *fmt,*terr;
int tsiz,sev;
int32_t toofar=0;
if ( !pass )
{
return;
}
if ( pass > 1 && options[QUAL_IDE_SYNTAX] )
{
ide_trunc_err(mask,tv);
return;
}
if ( options[QUAL_OCTAL] )
{
if (mask > 255)
{
fmt = "Truncation 0%06o bytes offset from segment {%s}.\n\tDesired: 0%010o, output a: 0%06o";
}
else
{
fmt = "Truncation 0%06o bytes offset from segment {%s}.\n\tDesired: 0%010o, output a: 0%03o";
}
}
else
{
if (mask > 255 && mask != 65534)
{
fmt = "Truncation 0x%04X bytes offset from segment {%s}.\n\tDesired: 0x%08X, output a: 0x%04X";
}
else
{
int range = 127;
if (mask == 254 || mask == 65534)
{
toofar = tv;
if (toofar == 0)
{
fmt = "Branch offset of 0x%02X is illegal at 0x%04X bytes from segment {%s}";
}
else
{
if (mask == 65534) range = 65535;
if (toofar > 0)
{
toofar -= range;
}
else
{
toofar = -toofar-(range+1);
}
fmt = "Branch offset 0x%02X byte(s) out of range at 0x%04X bytes from segment {%s}";
}
}
else
{
fmt = "Truncation 0x%04X bytes offset from segment {%s}\n\tDesired: 0x%08X, written: 0x%02X";
}
}
}
if (pass > 1)
{
char *fm,*em="\n\tAt %s:%d";
fm = MEM_alloc(strlen(fmt)+strlen(em)+1);
strcpy(fm,fmt);
strcat(fm,em);
fmt = fm;
}
tsiz = strlen(fmt)+strlen(current_section->seg_string)+40;
if (pass > 1)
{
tsiz += strlen(current_fnd->fn_name_only);
}
terr = MEM_alloc(tsiz);
if (mask == 254 || mask == 65534)
{
if (pass > 1)
{
snprintf(terr, tsiz, fmt, toofar, current_offset, current_section->seg_string, current_fnd->fn_nam->relative_name, current_fnd->fn_line);
}
else
{
snprintf(terr, tsiz, fmt, toofar, current_offset, current_section->seg_string);
}
sev = MSG_ERROR; /* branch fail is ERROR */
}
else
{
if (pass > 1)
{
snprintf(terr, tsiz, fmt, current_offset, current_section->seg_string, tv, tv & mask, current_fnd->fn_nam->relative_name, current_fnd->fn_line);
}
else
{
snprintf(terr, tsiz, fmt, current_offset, current_section->seg_string, tv, tv&mask);
}
sev = MSG_WARN; /* others are light weight errors */
}
if (pass > 1)
{
err_msg(sev,terr);
}
else
{
show_bad_token((char *)0,terr,sev);
}
MEM_free(terr);
return;
}
static void flush_outbuf(void)
{
if (out_indx - out_buf != 0)
{
int dbg;
dbg = options[QUAL_DEBUG];
options[QUAL_DEBUG] = 0;
write_to_tmp(TMP_BSTNG,(int)(out_indx-out_buf),out_buf,1);
options[QUAL_DEBUG] = dbg;
}
out_indx = out_buf;
out_remaining = sizeof(out_buf);
}
void move_pc( void )
{
flush_outbuf();
#if defined(PC_DEBUG)