-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvax.c
3364 lines (3116 loc) · 93.7 KB
/
vax.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
/* vax.c - vax-specific -
Copyright (C) 1987 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. */
/* JF I moved almost all the vax specific stuff into this one file 'cuz RMS
seems to think its a good idea. I hope I managed to get all the VAX-isms */
#include "as.h"
#include "read.h"
#include "flonum.h"
#include "vax-inst.h"
#include "md.h"
#include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
#include "frags.h"
#include "struc-symbol.h"
#include "expr.h"
#include "symbols.h"
/* This is the number to put at the beginning of the a.out file */
long omagic = OMAGIC;
/* These chars start a comment anywhere in a source file (except inside
another comment */
const char comment_chars[] = "#";
/* These chars only start a comment at the beginning of a line. */
/* Note that for the VAX the are the same as comment_chars above. */
const char line_comment_chars[] = "#";
/* Chars that can be used to separate mant from exp in floating point nums */
const char EXP_CHARS[] = "eE";
/* Chars that mean this number is a floating point constant */
/* as in 0f123.456 */
/* or 0H1.234E-12 (see exp chars above) */
const char FLT_CHARS[] = "dDfFgGhH";
/* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
changed in read.c . Ideally it shouldn't have to know about it at all,
but nothing is ideal around here.
*/
static expressionS /* Hold details of an operand expression */
exp_of_operand[VIT_MAX_OPERANDS];
static struct vit
v; /* A vax instruction after decoding. */
LITTLENUM_TYPE big_operand_bits[VIT_MAX_OPERANDS][SIZE_OF_LARGE_NUMBER];
/* Hold details of big operands. */
FLONUM_TYPE float_operand[VIT_MAX_OPERANDS];
/* Above is made to point into */
/* big_operand_bits by md_begin(). */
/*
* For VAX, relative addresses of "just the right length" are easy.
* The branch displacement is always the last operand, even in
* synthetic instructions.
* For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
*
* 4 3 2 1 0 bit number
* ---/ /--+-------+-------+-------+-------+-------+
* | what state ? | how long ? |
* ---/ /--+-------+-------+-------+-------+-------+
*
* The "how long" bits are 00=byte, 01=word, 10=long.
* This is a Un*x convention.
* Not all lengths are legit for a given value of (what state).
* The "how long" refers merely to the displacement length.
* The address usually has some constant bytes in it as well.
*
groups for VAX address relaxing.
1. "foo" pc-relative.
length of byte, word, long
2a. J<cond> where <cond> is a simple flag test.
length of byte, word, long.
VAX opcodes are: (Hex)
bneq/bnequ 12
beql/beqlu 13
bgtr 14
bleq 15
bgeq 18
blss 19
bgtru 1a
blequ 1b
bvc 1c
bvs 1d
bgequ/bcc 1e
blssu/bcs 1f
Always, you complement 0th bit to reverse condition.
Always, 1-byte opcode, then 1-byte displacement.
2b. J<cond> where cond tests a memory bit.
length of byte, word, long.
Vax opcodes are: (Hex)
bbs e0
bbc e1
bbss e2
bbcs e3
bbsc e4
bbcc e5
bbssi e6
bbcci e7
Always, you complement 0th bit to reverse condition.
Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
2c. J<cond> where cond tests low-order memory bit
length of byte,word,long.
Vax opcodes are: (Hex)
blbs e8
blbc e9
Always, you complement 0th bit to reverse condition.
Always, 1-byte opcode, longword-address, 1-byte displacement.
3. Jbs/Jbr.
length of byte,word,long.
Vax opcodes are: (Hex)
bsbb 10
brb 11
These are like (2) but there is no condition to reverse.
Always, 1 byte opcode, then displacement/absolute.
4a. JacbX
length of word, long.
Vax opcodes are: (Hex)
acbw 3d
acbf 4f
acbd 6f
abcb 9d
acbl f1
acbg 4ffd
acbh 6ffd
Always, we cannot reverse the sense of the branch; we have a word
displacement.
The double-byte op-codes don't hurt: we never want to modify the
opcode, so we don't care how many bytes are between the opcode and
the operand.
4b. JXobXXX
length of long, long, byte.
Vax opcodes are: (Hex)
aoblss f2
aobleq f3
sobgeq f4
sobgtr f5
Always, we cannot reverse the sense of the branch; we have a byte
displacement.
The only time we need to modify the opcode is for class 2 instructions.
After relax() we may complement the lowest order bit of such instruction
to reverse sense of branch.
For class 2 instructions, we store context of "where is the opcode literal".
We can change an opcode's lowest order bit without breaking anything else.
We sometimes store context in the operand literal. This way we can figure out
after relax() what the original addressing mode was.
*/
/* These displacements are relative to */
/* the start address of the displacement. */
/* The first letter is Byte, Word. */
/* 2nd letter is Forward, Backward. */
#define BF (1+ 127)
#define BB (1+-128)
#define WF (2+ 32767)
#define WB (2+-32768)
/* Dont need LF, LB because they always */
/* reach. [They are coded as 0.] */
#define C(a,b) ENCODE_RELAX(a,b)
/* This macro has no side-effects. */
#define ENCODE_RELAX(what,length) (((what) << 2) + (length))
const relax_typeS
md_relax_table[] =
{
{
1, 1, 0, 0
}, /* error sentinel 0,0 */
{
1, 1, 0, 0
}, /* unused 0,1 */
{
1, 1, 0, 0
}, /* unused 0,2 */
{
1, 1, 0, 0
}, /* unused 0,3 */
{
BF + 1, BB + 1, 2, C (1, 1)
}, /* B^"foo" 1,0 */
{
WF + 1, WB + 1, 3, C (1, 2)
}, /* W^"foo" 1,1 */
{
0, 0, 5, 0
}, /* L^"foo" 1,2 */
{
1, 1, 0, 0
}, /* unused 1,3 */
{
BF, BB, 1, C (2, 1)
}, /* b<cond> B^"foo" 2,0 */
{
WF + 2, WB + 2, 4, C (2, 2)
}, /* br.+? brw X 2,1 */
{
0, 0, 7, 0
}, /* br.+? jmp X 2,2 */
{
1, 1, 0, 0
}, /* unused 2,3 */
{
BF, BB, 1, C (3, 1)
}, /* brb B^foo 3,0 */
{
WF, WB, 2, C (3, 2)
}, /* brw W^foo 3,1 */
{
0, 0, 5, 0
}, /* Jmp L^foo 3,2 */
{
1, 1, 0, 0
}, /* unused 3,3 */
{
1, 1, 0, 0
}, /* unused 4,0 */
{
WF, WB, 2, C (4, 2)
}, /* acb_ ^Wfoo 4,1 */
{
0, 0, 10, 0
}, /* acb_,br,jmp L^foo4,2 */
{
1, 1, 0, 0
}, /* unused 4,3 */
{
BF, BB, 1, C (5, 1)
}, /* Xob___,,foo 5,0 */
{
WF + 4, WB + 4, 6, C (5, 2)
}, /* Xob.+2,brb.+3,brw5,1 */
{
0, 0, 9, 0
}, /* Xob.+2,brb.+6,jmp5,2 */
};
#undef C
#undef BF
#undef BB
#undef WF
#undef WB
void float_cons ();
const pseudo_typeS md_pseudo_table[] =
{
{"dfloat", float_cons, 'd'},
{"ffloat", float_cons, 'f'},
{"gfloat", float_cons, 'g'},
{"hfloat", float_cons, 'h'},
{0}
};
#define STATE_PC_RELATIVE (1)
#define STATE_CONDITIONAL_BRANCH (2)
#define STATE_ALWAYS_BRANCH (3) /* includes BSB... */
#define STATE_COMPLEX_BRANCH (4)
#define STATE_COMPLEX_HOP (5)
#define STATE_BYTE (0)
#define STATE_WORD (1)
#define STATE_LONG (2)
#define STATE_UNDF (3) /* Symbol undefined in pass1 */
#define min(a, b) ((a) < (b) ? (a) : (b))
void
md_begin ()
{
char *vip_begin ();
char *errtxt;
FLONUM_TYPE *fP;
int i;
if (*(errtxt = vip_begin (TRUE, "$", "*", "`")))
{
as_fatal ("VIP_BEGIN error:%s", errtxt);
}
for (i = 0, fP = float_operand;
fP < float_operand + VIT_MAX_OPERANDS;
i++, fP++)
{
fP->low = &big_operand_bits[i][0];
fP->high = &big_operand_bits[i][SIZE_OF_LARGE_NUMBER - 1];
}
}
void
md_end ()
{
vip_end ();
}
void /* Knows about order of bytes in address. */
md_number_to_chars (con, value, nbytes)
char con[]; /* Return 'nbytes' of chars here. */
long int value; /* The value of the bits. */
int nbytes; /* Number of bytes in the output. */
{
int n;
long v;
n = nbytes;
v = value;
while (nbytes--)
{
*con++ = value; /* Lint wants & MASK_CHAR. */
value >>= BITS_PER_CHAR;
}
/* XXX line number probably botched for this warning message. */
if (value != 0 && value != -1)
as_warn ("Displacement (%ld) long for instruction field length (%d).", v, n);
}
void /* Knows about order of bytes in address. */
md_number_to_imm (con, value, nbytes)
char con[]; /* Return 'nbytes' of chars here. */
long int value; /* The value of the bits. */
int nbytes; /* Number of bytes in the output. */
{
int n;
long v;
n = nbytes;
v = value;
while (nbytes--)
{
*con++ = value; /* Lint wants & MASK_CHAR. */
value >>= BITS_PER_CHAR;
}
/* XXX line number probably botched for this warning message. */
if (value != 0 && value != -1)
as_warn ("Displacement (%ld) too long for instruction field length (%d).", v, n);
}
void /* Knows about order of bytes in address. */
md_number_to_disp (con, value, nbytes)
char con[]; /* Return 'nbytes' of chars here. */
long int value; /* The value of the bits. */
int nbytes; /* Number of bytes in the output. */
{
abort ();
while (nbytes--)
{
*con++ = value; /* Lint wants & MASK_CHAR. */
value >>= BITS_PER_CHAR;
}
/* XXX line number probably botched for this warning message. */
if (value != 0 && value != -1)
as_warn ("Displacement too long for instruction field length.");
}
void /* Knows about order of bytes in address. */
md_number_to_field (con, value, nbytes)
char con[]; /* Return 'nbytes' of chars here. */
long int value; /* The value of the bits. */
int nbytes; /* Number of bytes in the output. */
{
abort ();
while (nbytes--)
{
*con++ = value; /* Lint wants & MASK_CHAR. */
value >>= BITS_PER_CHAR;
}
/* XXX line number probably botched for this warning message. */
if (value != 0 && value != -1)
as_warn ("Displacement too long for instruction field length.");
}
long int /* Knows about the byte order in a word. */
md_chars_to_number (con, nbytes)
unsigned char con[]; /* Low order byte 1st. */
int nbytes; /* Number of bytes in the input. */
{
long int retval;
for (retval = 0, con += nbytes - 1; nbytes--; con--)
{
retval <<= BITS_PER_CHAR;
retval |= *con;
}
return retval;
}
/* vax:md_assemble() emit frags for 1 instruction */
void
md_assemble (instruction_string)
char *instruction_string; /* A string: assemble 1 instruction. */
{
char *p;
register struct vop *operandP;/* An operand. Scans all operands. */
char *save_input_line_pointer;
char c_save; /* What used to live after an expression. */
struct frag *fragP; /* Fragment of code we just made. */
register int goofed; /* TRUE: instruction_string bad for all passes. */
register struct vop *end_operandP; /* -> slot just after last operand */
/* Limit of the for (each operand). */
register expressionS *expP; /* -> expression values for this operand */
/* These refer to an instruction operand expression. */
segT to_seg; /* Target segment of the address. */
register valueT this_add_number;
register struct symbol *this_add_symbol; /* +ve (minuend) symbol. */
register struct symbol *this_subtract_symbol; /* -ve(subtrahend) symbol. */
long int opcode_as_number; /* As a number. */
char *opcode_as_chars; /* Least significant byte 1st. */
/* As an array of characters. */
char *opcode_low_byteP; /* Least significant byte 1st */
struct details *detP; /* The details of an ADxxx frag. */
int length; /* length (bytes) meant by vop_short. */
int at; /* 0, or 1 if '@' is in addressing mode. */
int nbytes; /* From vop_nbytes: vax_operand_width (in bytes) */
FLONUM_TYPE *floatP;
char *vip ();
LITTLENUM_TYPE literal_float[8];
/* Big enough for any floating point literal. */
if (*(p = vip (&v, instruction_string)))
{
as_fatal ("vax_assemble\"%s\" in=\"%s\"", p, instruction_string);
}
/*
* Now we try to find as many as_warn()s as we can. If we do any as_warn()s
* then goofed=TRUE. Notice that we don't make any frags yet.
* Should goofed be TRUE, then this instruction will wedge in any pass,
* and we can safely flush it, without causing interpass symbol phase
* errors. That is, without changing label values in different passes.
*/
if (goofed = (*v.vit_error))
{
as_warn ("Ignoring statement due to \"%s\"", v.vit_error);
}
/*
* We need to use expression() and friends, which require us to diddle
* input_line_pointer. So we save it and restore it later.
*/
save_input_line_pointer = input_line_pointer;
for (operandP = v.vit_operand,
expP = exp_of_operand,
floatP = float_operand,
end_operandP = v.vit_operand + v.vit_operands;
operandP < end_operandP;
operandP++,
expP++,
floatP++
) /* for each operand */
{
if (*(operandP->vop_error))
{
as_warn ("Ignoring statement because \"%s\"", (operandP->vop_error));
goofed = TRUE;
}
else
{ /* statement has no syntax goofs: lets sniff the expression */
int can_be_short; /* TRUE if a bignum can be reduced to a short literal. */
input_line_pointer = operandP->vop_expr_begin;
c_save = operandP->vop_expr_end[1];
operandP->vop_expr_end[1] = '\0';
/* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = TRUE. */
switch (to_seg = expression (expP))
{
case SEG_NONE:
/* for BSD4.2 compatibility, missing expression is absolute 0 */
to_seg = expP->X_seg = SEG_ABSOLUTE;
expP->X_add_number = 0;
/* for SEG_ABSOLUTE, we shouldnt need to set X_subtract_symbol, X_add_symbol to any particular value. */
/* But, we will program defensively. Since this situation occurs */
/* rarely so it costs us little to do, and stops Dean */
/* worrying about the origin of random bits in expressionS's. */
expP->X_add_symbol = NULL;
expP->X_subtract_symbol = NULL;
case SEG_TEXT:
case SEG_DATA:
case SEG_BSS:
case SEG_ABSOLUTE:
case SEG_UNKNOWN:
break;
case SEG_DIFFERENCE:
case SEG_PASS1:
/*
* Major bug. We can't handle the case of a
* SEG_DIFFERENCE expression in a VIT_OPCODE_SYNTHETIC
* variable-length instruction.
* We don't have a frag type that is smart enough to
* relax a SEG_DIFFERENCE, and so we just force all
* SEG_DIFFERENCEs to behave like SEG_PASS1s.
* Clearly, if there is a demand we can invent a new or
* modified frag type and then coding up a frag for this
* case will be easy. SEG_DIFFERENCE was invented for the
* .words after a CASE opcode, and was never intended for
* instruction operands.
*/
need_pass_2 = TRUE;
as_warn("Can't relocate expression");
break;
case SEG_BIG:
/* Preserve the bits. */
if (expP->X_add_number > 0)
{
bignum_copy (generic_bignum, expP->X_add_number,
floatP->low, SIZE_OF_LARGE_NUMBER);
}
else
{
know (expP->X_add_number < 0);
flonum_copy (&generic_floating_point_number,
floatP);
if (index ("s i", operandP->vop_short))
{ /* Could possibly become S^# */
flonum_gen2vax (-expP->X_add_number, floatP, literal_float);
switch (-expP->X_add_number)
{
case 'f':
can_be_short =
(literal_float[0] & 0xFC0F) == 0x4000
&& literal_float[1] == 0;
break;
case 'd':
can_be_short =
(literal_float[0] & 0xFC0F) == 0x4000
&& literal_float[1] == 0
&& literal_float[2] == 0
&& literal_float[3] == 0;
break;
case 'g':
can_be_short =
(literal_float[0] & 0xFF81) == 0x4000
&& literal_float[1] == 0
&& literal_float[2] == 0
&& literal_float[3] == 0;
break;
case 'h':
can_be_short =
(literal_float[0] & 0xFFF8) == 0x4000
&& (literal_float[1] & 0xE000) == 0
&& literal_float[2] == 0
&& literal_float[3] == 0
&& literal_float[4] == 0
&& literal_float[5] == 0
&& literal_float[6] == 0
&& literal_float[7] == 0;
break;
default:
BAD_CASE (-expP->X_add_number);
break;
} /* switch (float type) */
} /* if (could want to become S^#...) */
} /* bignum or flonum ? */
if (operandP->vop_short == 's'
|| operandP->vop_short == 'i'
|| (operandP->vop_short == ' '
&& operandP->vop_reg == 0xF
&& (operandP->vop_mode & 0xE) == 0x8))
{
/* Saw a '#'. */
if (operandP->vop_short == ' ')
{ /* We must chose S^ or I^. */
if (expP->X_add_number > 0)
{ /* Bignum: Short literal impossible. */
operandP->vop_short = 'i';
operandP->vop_mode = 8;
operandP->vop_reg = 0xF; /* VAX PC. */
}
else
{ /* Flonum: Try to do it. */
if (can_be_short)
{
operandP->vop_short = 's';
operandP->vop_mode = 0;
operandP->vop_ndx = -1;
operandP->vop_reg = -1;
/* JF hope this is the right thing */
expP->X_seg = SEG_ABSOLUTE;
}
else
{
operandP->vop_short = 'i';
operandP->vop_mode = 8;
operandP->vop_reg = 0xF; /* VAX PC */
}
} /* bignum or flonum ? */
} /* if #, but no S^ or I^ seen. */
/* No more ' ' case: either 's' or 'i'. */
if (operandP->vop_short == 's')
{
/* Wants to be a short literal. */
if (expP->X_add_number > 0)
{
as_warn ("Bignum not permitted in short literal. Immediate mode assumed.");
operandP->vop_short = 'i';
operandP->vop_mode = 8;
operandP->vop_reg = 0xF; /* VAX PC. */
}
else
{
if (!can_be_short)
{
as_warn ("Can't do flonum short literal: immediate mode used.");
operandP->vop_short = 'i';
operandP->vop_mode = 8;
operandP->vop_reg = 0xF; /* VAX PC. */
}
else
{ /* Encode short literal now. */
register int temp;
switch (-expP->X_add_number)
{
case 'f':
case 'd':
temp = literal_float[0] >> 4;
break;
case 'g':
temp = literal_float[0] >> 1;
break;
case 'h':
temp = ((literal_float[0] << 3) & 070)
| ((literal_float[1] >> 13) & 07);
break;
default:
BAD_CASE (-expP->X_add_number);
break;
}
floatP->low[0] = temp & 077;
floatP->low[1] = 0;
} /* if can be short literal float */
} /* flonum or bignum ? */
}
else
{ /* I^# seen: set it up if float. */
if (expP->X_add_number < 0)
{
bcopy (literal_float, floatP->low, sizeof (literal_float));
}
} /* if S^# seen. */
}
else
{
as_warn ("A bignum/flonum may not be a displacement: 0x%x used",
expP->X_add_number = 0x80000000);
/* Chosen so luser gets the most offset bits to patch later. */
}
expP->X_add_number = floatP->low[0]
| ((LITTLENUM_MASK & (floatP->low[1])) << LITTLENUM_NUMBER_OF_BITS);
/*
* For the SEG_BIG case we have:
* If vop_short == 's' then a short floating literal is in the
* lowest 6 bits of floatP -> low [0], which is
* big_operand_bits [---] [0].
* If vop_short == 'i' then the appropriate number of elements
* of big_operand_bits [---] [...] are set up with the correct
* bits.
* Also, just in case width is byte word or long, we copy the lowest
* 32 bits of the number to X_add_number.
*/
break;
default:
BAD_CASE (to_seg);
break;
}
if (input_line_pointer != operandP->vop_expr_end + 1)
{
as_warn ("Junk at end of expression \"%s\"", input_line_pointer);
goofed = TRUE;
}
operandP->vop_expr_end[1] = c_save;
}
} /* for(each operand) */
input_line_pointer = save_input_line_pointer;
if (!need_pass_2 && !goofed)
{
/* We saw no errors in any operands - try to make frag(s) */
int is_undefined; /* True if operand expression's */
/* segment not known yet. */
int length_code;
/* Emit op-code. */
/* Remember where it is, in case we want to modify the op-code later. */
opcode_low_byteP = frag_more (v.vit_opcode_nbytes);
bcopy (v.vit_opcode, opcode_low_byteP, v.vit_opcode_nbytes);
opcode_as_number = md_chars_to_number (opcode_as_chars = v.vit_opcode, 4);
for (operandP = v.vit_operand,
expP = exp_of_operand,
floatP = float_operand,
end_operandP = v.vit_operand + v.vit_operands;
operandP < end_operandP;
operandP++,
floatP++,
expP++
) /* for each operand */
{
if (operandP->vop_ndx >= 0)
{
/* indexed addressing byte */
/* Legality of indexed mode already checked: it is OK */
FRAG_APPEND_1_CHAR (0x40 + operandP->vop_ndx);
} /* if(vop_ndx>=0) */
/* Here to make main operand frag(s). */
this_add_number = expP->X_add_number;
this_add_symbol = expP->X_add_symbol;
this_subtract_symbol = expP->X_subtract_symbol;
to_seg = expP->X_seg;
is_undefined = (to_seg == SEG_UNKNOWN);
know (to_seg == SEG_UNKNOWN \
||to_seg == SEG_ABSOLUTE \
||to_seg == SEG_DATA \
||to_seg == SEG_TEXT \
||to_seg == SEG_BSS \
||to_seg == SEG_BIG \
);
at = operandP->vop_mode & 1;
length = operandP->vop_short == 'b' ? 1 : operandP->vop_short == 'w' ? 2 : operandP->vop_short == 'l' ? 4 : 0;
nbytes = operandP->vop_nbytes;
if (operandP->vop_access == 'b')
{
if (to_seg == now_seg || is_undefined)
{ /* If is_undefined, then it might BECOME now_seg. */
if (nbytes)
{
p = frag_more (nbytes);
fix_new (frag_now, p - frag_now->fr_literal, nbytes,
this_add_symbol, 0, this_add_number, 1);
}
else
{ /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
/* nbytes==0 */
length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
if (opcode_as_number & VIT_OPCODE_SPECIAL)
{
if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
{
/* br or jsb */
frag_var (rs_machine_dependent, 5, 1,
ENCODE_RELAX (STATE_ALWAYS_BRANCH, length_code),
this_add_symbol, this_add_number,
opcode_low_byteP);
}
else
{
if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
{
length_code = STATE_WORD; /* JF: There is no state_byte for this one! */
frag_var (rs_machine_dependent, 10, 2,
ENCODE_RELAX (STATE_COMPLEX_BRANCH, length_code),
this_add_symbol, this_add_number,
opcode_low_byteP);
}
else
{
know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
frag_var (rs_machine_dependent, 9, 1,
ENCODE_RELAX (STATE_COMPLEX_HOP, length_code),
this_add_symbol, this_add_number,
opcode_low_byteP);
}
}
}
else
{
know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
frag_var (rs_machine_dependent, 7, 1,
ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code),
this_add_symbol, this_add_number,
opcode_low_byteP);
}
}
}
else
{ /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
/*
* --- SEG FLOAT MAY APPEAR HERE ----
*/
if (to_seg == SEG_ABSOLUTE)
{
if (nbytes)
{
know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
p = frag_more (nbytes);
/* Conventional relocation. */
fix_new (frag_now, p - frag_now->fr_literal,
nbytes, &abs_symbol, 0, this_add_number, 1);
}
else
{
know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
if (opcode_as_number & VIT_OPCODE_SPECIAL)
{
if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
{
/* br or jsb */
*opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
know (opcode_as_chars[1] == 0);
p = frag_more (5);
p[0] = VAX_ABSOLUTE_MODE; /* @#... */
md_number_to_chars (p + 1, this_add_number, 4);
/* Now (eg) JMP @#foo or JSB @#foo. */
}
else
{
if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
{
p = frag_more (10);
p[0] = 2;
p[1] = 0;
p[2] = VAX_BRB;
p[3] = 6;
p[4] = VAX_JMP;
p[5] = VAX_ABSOLUTE_MODE; /* @#... */
md_number_to_chars (p + 6, this_add_number, 4);
/*
* Now (eg) ACBx 1f
* BRB 2f
* 1: JMP @#foo
* 2:
*/
}
else
{
know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
p = frag_more (9);
p[0] = 2;
p[1] = VAX_BRB;
p[2] = 6;
p[3] = VAX_JMP;
p[4] = VAX_PC_RELATIVE_MODE + 1; /* @#... */
md_number_to_chars (p + 5, this_add_number, 4);
/*
* Now (eg) xOBxxx 1f
* BRB 2f
* 1: JMP @#foo
* 2:
*/
}
}
}
else
{
/* b<cond> */
*opcode_low_byteP ^= 1; /* To reverse the condition in a VAX branch, complement the lowest order bit. */
p = frag_more (7);
p[0] = 6;
p[1] = VAX_JMP;
p[2] = VAX_ABSOLUTE_MODE; /* @#... */
md_number_to_chars (p + 3, this_add_number, 4);
/*
* Now (eg) BLEQ 1f
* JMP @#foo
* 1:
*/
}
}
}
else
{ /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */
if (nbytes > 0)
{
/* Pc-relative. Conventional relocation. */
know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
p = frag_more (nbytes);
fix_new (frag_now, p - frag_now->fr_literal,
nbytes, &abs_symbol, 0, this_add_number, 1);
}
else
{
know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
if (opcode_as_number & VIT_OPCODE_SPECIAL)
{
if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
{
/* br or jsb */
know (opcode_as_chars[1] == 0);
*opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
p = frag_more (5);
p[0] = VAX_PC_RELATIVE_MODE;
fix_new (frag_now,
p + 1 - frag_now->fr_literal, 4,
this_add_symbol, 0,
this_add_number, 1);
/* Now eg JMP foo or JSB foo. */
}
else
{
if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
{
p = frag_more (10);
p[0] = 0;
p[1] = 2;
p[2] = VAX_BRB;
p[3] = 6;
p[4] = VAX_JMP;
p[5] = VAX_PC_RELATIVE_MODE;
fix_new (frag_now,
p + 6 - frag_now->fr_literal, 4,
this_add_symbol, 0,
this_add_number, 1);
/*
* Now (eg) ACBx 1f
* BRB 2f
* 1: JMP foo
* 2:
*/
}
else
{
know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
p = frag_more (10);
p[0] = 2;
p[1] = VAX_BRB;
p[2] = 6;
p[3] = VAX_JMP;
p[4] = VAX_PC_RELATIVE_MODE;
fix_new (frag_now,
p + 5 - frag_now->fr_literal,
4, this_add_symbol, 0,
this_add_number, 1);
/*
* Now (eg) xOBxxx 1f
* BRB 2f
* 1: JMP foo
* 2:
*/
}
}
}
else
{
know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
*opcode_low_byteP ^= 1; /* Reverse branch condition. */
p = frag_more (7);
p[0] = 6;
p[1] = VAX_JMP;
p[2] = VAX_PC_RELATIVE_MODE;
fix_new (frag_now, p + 3 - frag_now->fr_literal,
4, this_add_symbol, 0,
this_add_number, 1);
}
}
}
}
}
else
{
know (operandP->vop_access != 'b'); /* So it is ordinary operand. */
know (operandP->vop_access != ' '); /* ' ' target-independent: elsewhere. */
know (operandP->vop_access == 'a' || operandP->vop_access == 'm' || operandP->vop_access == 'r' || operandP->vop_access == 'v' || operandP->vop_access == 'w');