This repository has been archived by the owner on Nov 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
assemble.c
1502 lines (1248 loc) · 58.7 KB
/
assemble.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
#define ASSEMBLE__C
#include <stdlib.h>
#include <string.h>
#include "assemble.h" /* my own definitions */
#include "assemble_globals.h"
#include "assemble_aux.h"
#include "util.h"
#include "mlb.h"
#include "object.h"
#include "listing.h"
#include "parse.h"
#include "symbols.h"
#include "extree.h"
#include "macros.h"
#include "rept_irpc.h"
#include "rad50.h"
/* assemble - read a line from the input stack, assemble it. */
/* This function is way way too large, because I just coded most of
the operation code and pseudo-op handling right in line. */
static int assemble(
STACK *stack,
TEXT_RLD *tr)
{
char *cp; /* Parse character pointer */
char *opcp; /* Points to operation mnemonic text */
char *ncp; /* "next" cp */
char *label; /* A label */
char *line; /* The whole line */
SYMBOL *op; /* The operation SYMBOL */
int local; /* Whether a label is a local label or
not */
line = stack_gets(stack);
if (line == NULL)
return -1; /* Return code for EOF. */
cp = line;
/* Frankly, I don't need to keep "line." But I found it quite
handy during debugging, to see what the whole operation was,
when I'm down to parsing the second operand and things aren't
going right. */
stmtno++; /* Increment statement number */
list_source(stack->top, line); /* List source */
if (suppressed) {
/* Assembly is suppressed by unsatisfied conditional. Look
for ending and enabling statements. */
op = get_op(cp, &cp); /* Look at operation code */
/* FIXME: this code will blindly look into .REM commentary and
find operation codes. Incidentally, so will read_body. */
if (op == NULL)
return 1; /* Not found. Don't care. */
if (op->section->type != SECTION_PSEUDO)
return 1; /* Not a pseudo-op. */
switch (op->value) {
case P_IF:
case P_IFDF:
suppressed++; /* Nested. Suppressed. */
break;
case P_IFTF:
if (suppressed == 1) /* Reduce suppression from 1 to 0. */
suppressed = 0;
break;
case P_IFF:
if (suppressed == 1) { /* Can reduce suppression from 1 to 0. */
if (!conds[last_cond].ok)
suppressed = 0;
}
break;
case P_IFT:
if (suppressed == 1) { /* Can reduce suppression from 1 to 0. */
if (conds[last_cond].ok)
suppressed = 0;
}
break;
case P_ENDC:
suppressed--; /* Un-nested. */
if (suppressed == 0)
pop_cond(last_cond - 1); /* Re-enabled. */
break;
}
return 1;
}
/* The line may begin with "label<ws>:[:]" */
opcp = cp;
if ((label = get_symbol(cp, &ncp, &local)) != NULL) {
int flag = SYMBOLFLAG_PERMANENT | SYMBOLFLAG_DEFINITION | local;
SYMBOL *sym;
ncp = skipwhite(ncp);
if (*ncp == ':') { /* Colon, for symbol definition? */
ncp++;
/* maybe it's a global definition */
if (*ncp == ':') {
flag |= SYMBOLFLAG_GLOBAL; /* Yes, include global flag */
ncp++;
}
sym = add_sym(label, DOT, flag, current_pc->section, &symbol_st);
cp = ncp;
if (sym == NULL)
report(stack->top, "Illegal symbol definition %s\n", label);
free(label);
/* See if local symbol block should be incremented */
if (!enabl_lsb && !local)
lsb++;
cp = skipwhite(ncp);
opcp = cp;
label = get_symbol(cp, &ncp, NULL); /* Now, get what follows */
}
}
/* PSEUDO P_IIF jumps here. */
reassemble:
cp = skipwhite(cp);
if (EOL(*cp))
return 1; /* It's commentary. All done. */
if (label) { /* Something looks like a label. */
/* detect assignment */
ncp = skipwhite(ncp); /* The pointer to the text that
follows the symbol */
if (*ncp == '=') {
unsigned flags;
EX_TREE *value;
SYMBOL *sym;
cp = ncp;
/* Symbol assignment. */
flags = SYMBOLFLAG_DEFINITION | local;
cp++;
if (*cp == '=') {
flags |= SYMBOLFLAG_GLOBAL; /* Global definition */
cp++;
}
if (*cp == ':') {
flags |= SYMBOLFLAG_PERMANENT;
cp++;
}
cp = skipwhite(cp);
value = parse_expr(cp, 0);
/* Special code: if the symbol is the program counter,
this is harder. */
if (strcmp(label, ".") == 0) {
if (current_pc->section->flags & PSECT_REL) {
SYMBOL *sym;
unsigned offset;
/* Express the given expression as a symbol and an
offset. The symbol must not be global, the
section must = current. */
if (!express_sym_offset(value, &sym, &offset)) {
report(stack->top, "Illegal ORG\n");
} else if ((sym->flags & (SYMBOLFLAG_GLOBAL | SYMBOLFLAG_DEFINITION)) == SYMBOLFLAG_GLOBAL) {
report(stack->top, "Can't ORG to external location\n");
} else if (sym->flags & SYMBOLFLAG_UNDEFINED) {
report(stack->top, "Can't ORG to undefined sym\n");
} else if (sym->section != current_pc->section) {
report(stack->top, "Can't ORG to alternate section " "(use PSECT)\n");
} else {
DOT = sym->value + offset;
list_value(stack->top, DOT);
change_dot(tr, 0);
}
} else {
/* If the current section is absolute, the value
must be a literal */
if (value->type != EX_LIT) {
report(stack->top, "Can't ORG to non-absolute location\n");
free_tree(value);
free(label);
return 0;
}
DOT = value->data.lit;
list_value(stack->top, DOT);
change_dot(tr, 0);
}
free_tree(value);
free(label);
return 1;
}
/* regular symbols */
if (value->type == EX_LIT) {
sym = add_sym(label, value->data.lit, flags, &absolute_section, &symbol_st);
} else if (value->type == EX_SYM || value->type == EX_TEMP_SYM) {
sym = add_sym(label, value->data.symbol->value, flags, value->data.symbol->section, &symbol_st);
} else {
report(stack->top, "Complex expression cannot be assigned " "to a symbol\n");
if (!pass) {
/* This may work better in pass 2 - something in
RT-11 monitor needs the symbol to apear to be
defined even if I can't resolve its value. */
sym = add_sym(label, 0, SYMBOLFLAG_UNDEFINED, &absolute_section, &symbol_st);
} else
sym = NULL;
}
if (sym != NULL)
list_value(stack->top, sym->value);
free_tree(value);
free(label);
return sym != NULL;
}
/* Try to resolve macro */
op = lookup_sym(label, ¯o_st);
if (op && op->stmtno < stmtno) {
STREAM *macstr;
free(label);
macstr = expandmacro(stack->top, (MACRO *) op, ncp);
stack_push(stack, macstr); /* Push macro expansion
onto input stream */
return 1;
}
/* Try to resolve instruction or pseudo */
op = lookup_sym(label, &system_st);
if (op) {
cp = ncp;
free(label); /* Don't need this hanging around anymore */
switch (op->section->type) {
case SECTION_PSEUDO:
switch (op->value) {
case P_ENDR:
case P_ENDM:
case P_SBTTL:
case P_LIST:
case P_NLIST:
case P_PRINT:
return 1; /* Accepted, ignored. (An obvious
need: get assembly listing
controls working. ) */
case P_IDENT:
{
char endc[6];
int len;
cp = skipwhite(cp);
endc[0] = *cp++;
endc[1] = '\n';
endc[2] = 0;
len = (int) strcspn(cp, endc);
if (len > 6)
len = 6;
if (ident) /* An existing ident? */
free(ident); /* Discard it. */
ident = memcheck(malloc(len + 1));
memcpy(ident, cp, len);
ident[len] = 0;
upcase(ident);
return 1;
}
case P_RADIX:
{
int old_radix = radix;
radix = strtoul(cp, &cp, 10);
if (radix != 8 && radix != 10 && radix != 16 && radix != 2) {
radix = old_radix;
report(stack->top, "Illegal radix\n");
return 0;
}
return 1;
}
case P_FLT4:
case P_FLT2:
{
int ok = 1;
while (!EOL(*cp)) {
unsigned flt[4];
if (parse_float(cp, &cp, (op->value == P_FLT4 ? 4 : 2), flt)) {
/* Store the word values */
store_word(stack->top, tr, 2, flt[0]);
store_word(stack->top, tr, 2, flt[1]);
if (op->value == P_FLT4) {
store_word(stack->top, tr, 2, flt[2]);
store_word(stack->top, tr, 2, flt[3]);
}
} else {
report(stack->top, "Bad floating point format\n");
ok = 0;
}
cp = skipdelim(cp);
}
return ok;
}
case P_ERROR:
report(stack->top, "%.*s\n", strcspn(cp, "\n"), cp);
return 0;
case P_SAVE:
sect_sp++;
sect_stack[sect_sp] = current_pc->section;
return 1;
case P_RESTORE:
if (sect_sp < 0) {
report(stack->top, "No saved section for .RESTORE\n");
return 0;
} else {
go_section(tr, sect_stack[sect_sp]);
sect_sp++;
}
return 1;
case P_NARG:
{
STREAM *str;
MACRO_STREAM *mstr;
int local;
label = get_symbol(cp, &cp, &local);
if (label == NULL) {
report(stack->top, "Bad .NARG syntax\n");
return 0;
}
/* Walk up the stream stack to find the
topmost macro stream */
for (str = stack->top; str != NULL && str->vtbl != ¯o_stream_vtbl;
str = str->next) ;
if (!str) {
report(str, ".NARG not within macro expansion\n");
free(label);
return 0;
}
mstr = (MACRO_STREAM *) str;
add_sym(label, mstr->nargs, SYMBOLFLAG_DEFINITION | local, &absolute_section,
&symbol_st);
free(label);
return 1;
}
case P_NCHR:
{
char *string;
int local;
label = get_symbol(cp, &cp, &local);
if (label == NULL) {
report(stack->top, "Bad .NCHR syntax\n");
return 0;
}
cp = skipdelim(cp);
string = getstring(cp, &cp);
add_sym(label, strlen(string), SYMBOLFLAG_DEFINITION | local, &absolute_section,
&symbol_st);
free(label);
free(string);
return 1;
}
case P_NTYPE:
{
ADDR_MODE mode;
int local;
label = get_symbol(cp, &cp, &local);
if (label == NULL) {
report(stack->top, "Bad .NTYPE syntax\n");
return 0;
}
cp = skipdelim(cp);
if (!get_mode(cp, &cp, &mode)) {
report(stack->top, "Bad .NTYPE addressing mode\n");
free(label);
return 0;
}
add_sym(label, mode.type, SYMBOLFLAG_DEFINITION | local, &absolute_section, &symbol_st);
free_addr_mode(&mode);
free(label);
return 1;
}
case P_INCLUDE:
{
char *name = getstring(cp, &cp);
STREAM *incl;
if (name == NULL) {
report(stack->top, "Bad .INCLUDE file name\n");
return 0;
}
incl = new_file_stream(name);
if (incl == NULL) {
report(stack->top, "Unable to open .INCLUDE file %s\n", name);
free(name);
return 0;
}
free(name);
stack_push(stack, incl);
return 1;
}
case P_REM:
{
char quote[4];
/* Read and discard lines until one with a
closing quote */
cp = skipwhite(cp);
quote[0] = *cp++;
quote[1] = '\n';
quote[2] = 0;
for (;;) {
cp += strcspn(cp, quote);
if (*cp == quote[0])
break; /* Found closing quote */
cp = stack_gets(stack); /* Read next input line */
if (cp == NULL)
break; /* EOF */
}
}
return 1;
case P_IRP:
{
STREAM *str = expand_irp(stack, cp);
if (str)
stack_push(stack, str);
return str != NULL;
}
case P_IRPC:
{
STREAM *str = expand_irpc(stack, cp);
if (str)
stack_push(stack, str);
return str != NULL;
}
case P_MCALL:
{
STREAM *macstr;
BUFFER *macbuf;
char *maccp;
int saveline;
MACRO *mac;
int i;
char macfile[FILENAME_MAX];
char hitfile[FILENAME_MAX];
for (;;) {
cp = skipdelim(cp);
if (EOL(*cp))
return 1;
label = get_symbol(cp, &cp, NULL);
if (!label) {
report(stack->top, "Illegal .MCALL format\n");
return 0;
}
/* See if that macro's already defined */
if (lookup_sym(label, ¯o_st)) {
free(label); /* Macro already
registered. No
prob. */
cp = skipdelim(cp);
continue;
}
/* Find the macro in the list of included
macro libraries */
macbuf = NULL;
for (i = 0; i < nr_mlbs; i++)
if ((macbuf = mlb_entry(mlbs[i], label)) != NULL)
break;
if (macbuf != NULL) {
macstr = new_buffer_stream(macbuf, label);
buffer_free(macbuf);
} else {
strncpy(macfile, label, sizeof(macfile));
strncat(macfile, ".MAC", sizeof(macfile) - strlen(macfile) - 1);
my_searchenv(macfile, "MCALL", hitfile, sizeof(hitfile));
if (hitfile[0])
macstr = new_file_stream(hitfile);
else
macstr = NULL;
}
if (macstr != NULL) {
for (;;) {
char *mlabel;
maccp = macstr->vtbl->gets(macstr);
if (maccp == NULL)
break;
mlabel = get_symbol(maccp, &maccp, NULL);
if (mlabel == NULL)
continue;
op = lookup_sym(mlabel, &system_st);
free(mlabel);
if (op == NULL)
continue;
if (op->value == P_MACRO)
break;
}
if (maccp != NULL) {
STACK macstack = {
macstr
};
int savelist = list_level;
saveline = stmtno;
list_level = -1;
mac = defmacro(maccp, &macstack, TRUE);
if (mac == NULL) {
report(stack->top, "Failed to define macro " "called %s\n", label);
}
stmtno = saveline;
list_level = savelist;
}
macstr->vtbl->delete(macstr);
} else
report(stack->top, "MACRO %s not found\n", label);
free(label);
}
}
return 1;
case P_MACRO:
{
MACRO *mac = defmacro(cp, stack, FALSE);
return mac != NULL;
}
case P_MEXIT:
{
STREAM *macstr;
/* Pop a stream from the input. */
/* It must be the first stream, and it must be */
/* a macro, rept, irp, or irpc. */
macstr = stack->top;
if (macstr->vtbl != ¯o_stream_vtbl && macstr->vtbl != &rept_stream_vtbl
&& macstr->vtbl != &irp_stream_vtbl && macstr->vtbl != &irpc_stream_vtbl) {
report(stack->top, ".MEXIT not within a macro\n");
return 0;
}
/* and finally, pop the macro */
stack_pop(stack);
return 1;
}
case P_REPT:
{
STREAM *reptstr = expand_rept(stack, cp);
if (reptstr)
stack_push(stack, reptstr);
return reptstr != NULL;
}
case P_ENABL:
/* FIXME - add all the rest of the options. */
while (!EOL(*cp)) {
label = get_symbol(cp, &cp, NULL);
if (strcmp(label, "AMA") == 0)
enabl_ama = 1;
else if (strcmp(label, "LSB") == 0) {
enabl_lsb = 1;
lsb++;
} else if (strcmp(label, "GBL") == 0)
enabl_gbl = 1;
free(label);
cp = skipdelim(cp);
}
return 1;
case P_DSABL:
/* FIXME Ditto as for .ENABL */
while (!EOL(*cp)) {
label = get_symbol(cp, &cp, NULL);
if (strcmp(label, "AMA") == 0)
enabl_ama = 0;
else if (strcmp(label, "LSB") == 0)
enabl_lsb = 0;
else if (strcmp(label, "GBL") == 0)
enabl_gbl = 0;
free(label);
cp = skipdelim(cp);
}
return 1;
case P_LIMIT:
store_limits(stack->top, tr);
return 1;
case P_TITLE:
/* accquire module name */
if (module_name != NULL) {
free(module_name);
}
module_name = get_symbol(cp, &cp, NULL);
return 1;
case P_END:
/* Accquire transfer address */
cp = skipwhite(cp);
if (!EOL(*cp)) {
if (xfer_address)
free_tree(xfer_address);
xfer_address = parse_expr(cp, 0);
}
return 1;
case P_IFDF:
opcp = skipwhite(opcp);
cp = opcp + 3; /* Point cp at the "DF" or
"NDF" part */
/* Falls into... */
case P_IIF:
case P_IF:
{
EX_TREE *value;
int ok;
label = get_symbol(cp, &cp, NULL); /* Get condition */
cp = skipdelim(cp);
if (strcmp(label, "DF") == 0) {
value = parse_expr(cp, 1);
cp = value->cp;
ok = eval_defined(value);
free_tree(value);
} else if (strcmp(label, "NDF") == 0) {
value = parse_expr(cp, 1);
cp = value->cp;
ok = eval_undefined(value);
free_tree(value);
} else if (strcmp(label, "B") == 0) {
char *thing;
cp = skipwhite(cp);
if (!EOL(*cp))
thing = getstring(cp, &cp);
else
thing = memcheck(strdup(""));
ok = (*thing == 0);
free(thing);
} else if (strcmp(label, "NB") == 0) {
char *thing;
cp = skipwhite(cp);
if (!EOL(*cp))
thing = getstring(cp, &cp);
else
thing = memcheck(strdup(""));
ok = (*thing != 0);
free(thing);
} else if (strcmp(label, "IDN") == 0) {
char *thing1,
*thing2;
thing1 = getstring(cp, &cp);
cp = skipdelim(cp);
if (!EOL(*cp))
thing2 = getstring(cp, &cp);
else
thing2 = memcheck(strdup(""));
ok = (strcmp(thing1, thing2) == 0);
free(thing1);
free(thing2);
} else if (strcmp(label, "DIF") == 0) {
char *thing1,
*thing2;
thing1 = getstring(cp, &cp);
cp = skipdelim(cp);
if (!EOL(*cp))
thing2 = getstring(cp, &cp);
else
thing2 = memcheck(strdup(""));
ok = (strcmp(thing1, thing2) != 0);
free(thing1);
free(thing2);
} else {
int sword;
unsigned uword;
EX_TREE *value = parse_expr(cp, 0);
cp = value->cp;
if (value->type != EX_LIT) {
report(stack->top, "Bad .IF expression\n");
list_value(stack->top, 0);
free_tree(value);
ok = FALSE; /* Pick something. */
} else {
unsigned word;
/* Convert to signed and unsigned words */
sword = value->data.lit & 0x7fff;
/* FIXME I don't know if the following
is portable enough. */
if (value->data.lit & 0x8000)
sword |= ~0xFFFF; /* Render negative */
/* Reduce unsigned value to 16 bits */
uword = value->data.lit & 0xffff;
if (strcmp(label, "EQ") == 0 || strcmp(label, "Z") == 0)
ok = (uword == 0), word = uword;
else if (strcmp(label, "NE") == 0 || strcmp(label, "NZ") == 0)
ok = (uword != 0), word = uword;
else if (strcmp(label, "GT") == 0 || strcmp(label, "G") == 0)
ok = (sword > 0), word = sword;
else if (strcmp(label, "GE") == 0)
ok = (sword >= 0), word = sword;
else if (strcmp(label, "LT") == 0 || strcmp(label, "L") == 0)
ok = (sword < 0), word = sword;
else if (strcmp(label, "LE") == 0)
ok = (sword <= 0), word = sword;
list_value(stack->top, word);
free_tree(value);
}
}
free(label);
if (op->value == P_IIF) {
stmtno++; /* the second half is a
separate statement */
if (ok) {
/* The "immediate if" */
/* Only slightly tricky. */
cp = skipdelim(cp);
label = get_symbol(cp, &ncp, &local);
goto reassemble;
}
return 1;
}
push_cond(ok, stack->top);
if (!ok)
suppressed++; /* Assembly
suppressed
until .ENDC */
}
return 1;
case P_IFF:
if (last_cond < 0) {
report(stack->top, "No conditional block active\n");
return 0;
}
if (conds[last_cond].ok) /* Suppress if last cond
is true */
suppressed++;
return 1;
case P_IFT:
if (last_cond < 0) {
report(stack->top, "No conditional block active\n");
return 0;
}
if (!conds[last_cond].ok) /* Suppress if last cond
is false */
suppressed++;
return 1;
case P_IFTF:
if (last_cond < 0) {
report(stack->top, "No conditional block active\n");
return 0;
}
return 1; /* Don't suppress. */
case P_ENDC:
if (last_cond < 0) {
report(stack->top, "No conditional block active\n");
return 0;
}
pop_cond(last_cond - 1);
return 1;
case P_EVEN:
if (DOT & 1) {
list_word(stack->top, DOT, 0, 1, "");
DOT++;
}
return 1;
case P_ODD:
if (!(DOT & 1)) {
list_word(stack->top, DOT, 0, 1, "");
DOT++;
}
return 1;
case P_ASECT:
go_section(tr, &absolute_section);
return 1;
case P_CSECT:
case P_PSECT:
{
SYMBOL *sectsym;
SECTION *sect;
label = get_symbol(cp, &cp, NULL);
if (label == NULL)
label = memcheck(strdup("")); /* Allow blank */
sectsym = lookup_sym(label, §ion_st);
if (sectsym) {
sect = sectsym->section;
free(label);
} else {
sect = new_section();
sect->label = label;
sect->flags = 0;
sect->pc = 0;
sect->size = 0;
sect->type = SECTION_USER;
sections[sector++] = sect;
sectsym = add_sym(label, 0, 0, sect, §ion_st);
}
if (op->value == P_PSECT)
sect->flags |= PSECT_REL;
else if (op->value == P_CSECT)
sect->flags |= PSECT_REL | PSECT_COM | PSECT_GBL;
while (cp = skipdelim(cp), !EOL(*cp)) {
/* Parse section options */
label = get_symbol(cp, &cp, NULL);
if (strcmp(label, "ABS") == 0) {
sect->flags &= ~PSECT_REL; /* Not relative */
sect->flags |= PSECT_COM; /* implies common */
} else if (strcmp(label, "REL") == 0) {
sect->flags |= PSECT_REL; /* Is relative */
} else if (strcmp(label, "SAV") == 0) {
sect->flags |= PSECT_SAV; /* Is root */
} else if (strcmp(label, "OVR") == 0) {
sect->flags |= PSECT_COM; /* Is common */
} else if (strcmp(label, "RW") == 0) {
sect->flags &= ~PSECT_RO; /* Not read-only */
} else if (strcmp(label, "RO") == 0) {
sect->flags |= PSECT_RO; /* Is read-only */
} else if (strcmp(label, "I") == 0) {
sect->flags &= ~PSECT_DATA; /* Not data */
} else if (strcmp(label, "D") == 0) {
sect->flags |= PSECT_DATA; /* data */
} else if (strcmp(label, "GBL") == 0) {
sect->flags |= PSECT_GBL; /* Global */
} else if (strcmp(label, "LCL") == 0) {
sect->flags &= ~PSECT_GBL; /* Local */
} else {
report(stack->top, "Unknown flag %s given to " ".PSECT directive\n", label);
free(label);
return 0;
}
free(label);
}
go_section(tr, sect);
return 1;
} /* end PSECT code */
break;
case P_WEAK:
case P_GLOBL:
{
SYMBOL *sym;
while (!EOL(*cp)) {
/* Loop and make definitions for
comma-separated symbols */
label = get_symbol(cp, &ncp, NULL);
if (label == NULL) {
report(stack->top, "Illegal .GLOBL/.WEAK " "syntax\n");
return 0;
}
sym = lookup_sym(label, &symbol_st);
if (sym) {
sym->flags |= SYMBOLFLAG_GLOBAL | (op->value == P_WEAK ? SYMBOLFLAG_WEAK : 0);
} else
sym = add_sym(label, 0,
SYMBOLFLAG_GLOBAL | (op->value == P_WEAK ? SYMBOLFLAG_WEAK : 0),
&absolute_section, &symbol_st);
free(label);
cp = skipdelim(ncp);
}
}
return 1;
case P_WORD:
{
/* .WORD might be followed by nothing, which
is an implicit .WORD 0 */
if (EOL(*cp)) {
if (DOT & 1) {
report(stack->top, ".WORD on odd " "boundary\n");
DOT++; /* Fix it, too */
}
store_word(stack->top, tr, 2, 0);
return 1;
} else
return do_word(stack, tr, cp, 2);
}
case P_BYTE:
if (EOL(*cp)) {
/* Blank .BYTE. Same as .BYTE 0 */
store_word(stack->top, tr, 1, 0);
return 1;