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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
|
/* m68k.y -- bison grammar for m68k operand parsing
Copyright 1995, 1996, 1997, 1998, 2001, 2003, 2004, 2005, 2007
Free Software Foundation, Inc.
Written by Ken Raeburn and Ian Lance Taylor, Cygnus Support
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 3, 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, 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
/* This file holds a bison grammar to parse m68k operands. The m68k
has a complicated operand syntax, and gas supports two main
variations of it. Using a grammar is probably overkill, but at
least it makes clear exactly what we do support. */
%{
#include "as.h"
#include "tc-m68k.h"
#include "m68k-parse.h"
#include "safe-ctype.h"
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror,
etc), as well as gratuitously global symbol names If other parser
generators (bison, byacc, etc) produce additional global names that
conflict at link time, then those parser generators need to be
fixed instead of adding those names to this list. */
#define yymaxdepth m68k_maxdepth
#define yyparse m68k_parse
#define yylex m68k_lex
#define yyerror m68k_error
#define yylval m68k_lval
#define yychar m68k_char
#define yydebug m68k_debug
#define yypact m68k_pact
#define yyr1 m68k_r1
#define yyr2 m68k_r2
#define yydef m68k_def
#define yychk m68k_chk
#define yypgo m68k_pgo
#define yyact m68k_act
#define yyexca m68k_exca
#define yyerrflag m68k_errflag
#define yynerrs m68k_nerrs
#define yyps m68k_ps
#define yypv m68k_pv
#define yys m68k_s
#define yy_yys m68k_yys
#define yystate m68k_state
#define yytmp m68k_tmp
#define yyv m68k_v
#define yy_yyv m68k_yyv
#define yyval m68k_val
#define yylloc m68k_lloc
#define yyreds m68k_reds /* With YYDEBUG defined */
#define yytoks m68k_toks /* With YYDEBUG defined */
#define yylhs m68k_yylhs
#define yylen m68k_yylen
#define yydefred m68k_yydefred
#define yydgoto m68k_yydgoto
#define yysindex m68k_yysindex
#define yyrindex m68k_yyrindex
#define yygindex m68k_yygindex
#define yytable m68k_yytable
#define yycheck m68k_yycheck
#ifndef YYDEBUG
#define YYDEBUG 1
#endif
/* Internal functions. */
static enum m68k_register m68k_reg_parse (char **);
static int yylex (void);
static void yyerror (const char *);
/* The parser sets fields pointed to by this global variable. */
static struct m68k_op *op;
%}
%union
{
struct m68k_indexreg indexreg;
enum m68k_register reg;
struct m68k_exp exp;
unsigned long mask;
int onereg;
int trailing_ampersand;
}
%token <reg> DR AR FPR FPCR LPC ZAR ZDR LZPC CREG
%token <indexreg> INDEXREG
%token <exp> EXPR
%type <indexreg> zireg zdireg
%type <reg> zadr zdr apc zapc zpc optzapc optczapc
%type <exp> optcexpr optexprc
%type <mask> reglist ireglist reglistpair
%type <onereg> reglistreg
%type <trailing_ampersand> optional_ampersand
%%
/* An operand. */
operand:
generic_operand
| motorola_operand optional_ampersand
{
op->trailing_ampersand = $2;
}
| mit_operand optional_ampersand
{
op->trailing_ampersand = $2;
}
;
/* A trailing ampersand(for MAC/EMAC mask addressing). */
optional_ampersand:
/* empty */
{ $$ = 0; }
| '&'
{ $$ = 1; }
;
/* A generic operand. */
generic_operand:
'<' '<'
{
op->mode = LSH;
}
| '>' '>'
{
op->mode = RSH;
}
| DR
{
op->mode = DREG;
op->reg = $1;
}
| AR
{
op->mode = AREG;
op->reg = $1;
}
| FPR
{
op->mode = FPREG;
op->reg = $1;
}
| FPCR
{
op->mode = CONTROL;
op->reg = $1;
}
| CREG
{
op->mode = CONTROL;
op->reg = $1;
}
| EXPR
{
op->mode = ABSL;
op->disp = $1;
}
| '#' EXPR
{
op->mode = IMMED;
op->disp = $2;
}
| '&' EXPR
{
op->mode = IMMED;
op->disp = $2;
}
| reglist
{
op->mode = REGLST;
op->mask = $1;
}
;
/* An operand in Motorola syntax. This includes MRI syntax as well,
which may or may not be different in that it permits commutativity
of index and base registers, and permits an offset expression to
appear inside or outside of the parentheses. */
motorola_operand:
'(' AR ')'
{
op->mode = AINDR;
op->reg = $2;
}
| '(' AR ')' '+'
{
op->mode = AINC;
op->reg = $2;
}
| '-' '(' AR ')'
{
op->mode = ADEC;
op->reg = $3;
}
| '(' EXPR ',' zapc ')'
{
op->reg = $4;
op->disp = $2;
if (($4 >= ZADDR0 && $4 <= ZADDR7)
|| $4 == ZPC)
op->mode = BASE;
else
op->mode = DISP;
}
| '(' zapc ',' EXPR ')'
{
op->reg = $2;
op->disp = $4;
if (($2 >= ZADDR0 && $2 <= ZADDR7)
|| $2 == ZPC)
op->mode = BASE;
else
op->mode = DISP;
}
| EXPR '(' zapc ')'
{
op->reg = $3;
op->disp = $1;
if (($3 >= ZADDR0 && $3 <= ZADDR7)
|| $3 == ZPC)
op->mode = BASE;
else
op->mode = DISP;
}
| '(' LPC ')'
{
op->mode = DISP;
op->reg = $2;
}
| '(' ZAR ')'
{
op->mode = BASE;
op->reg = $2;
}
| '(' LZPC ')'
{
op->mode = BASE;
op->reg = $2;
}
| '(' EXPR ',' zapc ',' zireg ')'
{
op->mode = BASE;
op->reg = $4;
op->disp = $2;
op->index = $6;
}
| '(' EXPR ',' zapc ',' zpc ')'
{
if ($4 == PC || $4 == ZPC)
yyerror (_("syntax error"));
op->mode = BASE;
op->reg = $6;
op->disp = $2;
op->index.reg = $4;
op->index.size = SIZE_UNSPEC;
op->index.scale = 1;
}
| '(' EXPR ',' zdireg optczapc ')'
{
op->mode = BASE;
op->reg = $5;
op->disp = $2;
op->index = $4;
}
| '(' zdireg ',' EXPR ')'
{
op->mode = BASE;
op->disp = $4;
op->index = $2;
}
| EXPR '(' zapc ',' zireg ')'
{
op->mode = BASE;
op->reg = $3;
op->disp = $1;
op->index = $5;
}
| '(' zapc ',' zireg ')'
{
op->mode = BASE;
op->reg = $2;
op->index = $4;
}
| EXPR '(' zapc ',' zpc ')'
{
if ($3 == PC || $3 == ZPC)
yyerror (_("syntax error"));
op->mode = BASE;
op->reg = $5;
op->disp = $1;
op->index.reg = $3;
op->index.size = SIZE_UNSPEC;
op->index.scale = 1;
}
| '(' zapc ',' zpc ')'
{
if ($2 == PC || $2 == ZPC)
yyerror (_("syntax error"));
op->mode = BASE;
op->reg = $4;
op->index.reg = $2;
op->index.size = SIZE_UNSPEC;
op->index.scale = 1;
}
| EXPR '(' zdireg optczapc ')'
{
op->mode = BASE;
op->reg = $4;
op->disp = $1;
op->index = $3;
}
| '(' zdireg optczapc ')'
{
op->mode = BASE;
op->reg = $3;
op->index = $2;
}
| '(' '[' EXPR optczapc ']' ',' zireg optcexpr ')'
{
op->mode = POST;
op->reg = $4;
op->disp = $3;
op->index = $7;
op->odisp = $8;
}
| '(' '[' EXPR optczapc ']' optcexpr ')'
{
op->mode = POST;
op->reg = $4;
op->disp = $3;
op->odisp = $6;
}
| '(' '[' zapc ']' ',' zireg optcexpr ')'
{
op->mode = POST;
op->reg = $3;
op->index = $6;
op->odisp = $7;
}
| '(' '[' zapc ']' optcexpr ')'
{
op->mode = POST;
op->reg = $3;
op->odisp = $5;
}
| '(' '[' EXPR ',' zapc ',' zireg ']' optcexpr ')'
{
op->mode = PRE;
op->reg = $5;
op->disp = $3;
op->index = $7;
op->odisp = $9;
}
| '(' '[' zapc ',' zireg ']' optcexpr ')'
{
op->mode = PRE;
op->reg = $3;
op->index = $5;
op->odisp = $7;
}
| '(' '[' EXPR ',' zapc ',' zpc ']' optcexpr ')'
{
if ($5 == PC || $5 == ZPC)
yyerror (_("syntax error"));
op->mode = PRE;
op->reg = $7;
op->disp = $3;
op->index.reg = $5;
op->index.size = SIZE_UNSPEC;
op->index.scale = 1;
op->odisp = $9;
}
| '(' '[' zapc ',' zpc ']' optcexpr ')'
{
if ($3 == PC || $3 == ZPC)
yyerror (_("syntax error"));
op->mode = PRE;
op->reg = $5;
op->index.reg = $3;
op->index.size = SIZE_UNSPEC;
op->index.scale = 1;
op->odisp = $7;
}
| '(' '[' optexprc zdireg optczapc ']' optcexpr ')'
{
op->mode = PRE;
op->reg = $5;
op->disp = $3;
op->index = $4;
op->odisp = $7;
}
;
/* An operand in MIT syntax. */
mit_operand:
optzapc '@'
{
/* We use optzapc to avoid a shift/reduce conflict. */
if ($1 < ADDR0 || $1 > ADDR7)
yyerror (_("syntax error"));
op->mode = AINDR;
op->reg = $1;
}
| optzapc '@' '+'
{
/* We use optzapc to avoid a shift/reduce conflict. */
if ($1 < ADDR0 || $1 > ADDR7)
yyerror (_("syntax error"));
op->mode = AINC;
op->reg = $1;
}
| optzapc '@' '-'
{
/* We use optzapc to avoid a shift/reduce conflict. */
if ($1 < ADDR0 || $1 > ADDR7)
yyerror (_("syntax error"));
op->mode = ADEC;
op->reg = $1;
}
| optzapc '@' '(' EXPR ')'
{
op->reg = $1;
op->disp = $4;
if (($1 >= ZADDR0 && $1 <= ZADDR7)
|| $1 == ZPC)
op->mode = BASE;
else
op->mode = DISP;
}
| optzapc '@' '(' optexprc zireg ')'
{
op->mode = BASE;
op->reg = $1;
op->disp = $4;
op->index = $5;
}
| optzapc '@' '(' EXPR ')' '@' '(' optexprc zireg ')'
{
op->mode = POST;
op->reg = $1;
op->disp = $4;
op->index = $9;
op->odisp = $8;
}
| optzapc '@' '(' EXPR ')' '@' '(' EXPR ')'
{
op->mode = POST;
op->reg = $1;
op->disp = $4;
op->odisp = $8;
}
| optzapc '@' '(' optexprc zireg ')' '@' '(' EXPR ')'
{
op->mode = PRE;
op->reg = $1;
op->disp = $4;
op->index = $5;
op->odisp = $9;
}
;
/* An index register, possibly suppressed, which need not have a size
or scale. */
zireg:
INDEXREG
| zadr
{
$$.reg = $1;
$$.size = SIZE_UNSPEC;
$$.scale = 1;
}
;
/* A register which may be an index register, but which may not be an
address register. This nonterminal is used to avoid ambiguity when
trying to parse something like (0,d5,a6) as compared to (0,a6,d5). */
zdireg:
INDEXREG
| zdr
{
$$.reg = $1;
$$.size = SIZE_UNSPEC;
$$.scale = 1;
}
;
/* An address or data register, or a suppressed address or data
register. */
zadr:
zdr
| AR
| ZAR
;
/* A data register which may be suppressed. */
zdr:
DR
| ZDR
;
/* Either an address register or the PC. */
apc:
AR
| LPC
;
/* Either an address register, or the PC, or a suppressed address
register, or a suppressed PC. */
zapc:
apc
| LZPC
| ZAR
;
/* An optional zapc. */
optzapc:
/* empty */
{
$$ = ZADDR0;
}
| zapc
;
/* The PC, optionally suppressed. */
zpc:
LPC
| LZPC
;
/* ',' zapc when it may be omitted. */
optczapc:
/* empty */
{
$$ = ZADDR0;
}
| ',' zapc
{
$$ = $2;
}
;
/* ',' EXPR when it may be omitted. */
optcexpr:
/* empty */
{
$$.exp.X_op = O_absent;
$$.size = SIZE_UNSPEC;
}
| ',' EXPR
{
$$ = $2;
}
;
/* EXPR ',' when it may be omitted. */
optexprc:
/* empty */
{
$$.exp.X_op = O_absent;
$$.size = SIZE_UNSPEC;
}
| EXPR ','
{
$$ = $1;
}
;
/* A register list for the movem instruction. */
reglist:
reglistpair
| reglistpair '/' ireglist
{
$$ = $1 | $3;
}
| reglistreg '/' ireglist
{
$$ = (1 << $1) | $3;
}
;
/* We use ireglist when we know we are looking at a reglist, and we
can safely reduce a simple register to reglistreg. If we permitted
reglist to reduce to reglistreg, it would be ambiguous whether a
plain register were a DREG/AREG/FPREG or a REGLST. */
ireglist:
reglistreg
{
$$ = 1 << $1;
}
| reglistpair
| reglistpair '/' ireglist
{
$$ = $1 | $3;
}
| reglistreg '/' ireglist
{
$$ = (1 << $1) | $3;
}
;
reglistpair:
reglistreg '-' reglistreg
{
if ($1 <= $3)
$$ = (1 << ($3 + 1)) - 1 - ((1 << $1) - 1);
else
$$ = (1 << ($1 + 1)) - 1 - ((1 << $3) - 1);
}
;
reglistreg:
DR
{
$$ = $1 - DATA0;
}
| AR
{
$$ = $1 - ADDR0 + 8;
}
| FPR
{
$$ = $1 - FP0 + 16;
}
| FPCR
{
if ($1 == FPI)
$$ = 24;
else if ($1 == FPS)
$$ = 25;
else
$$ = 26;
}
;
%%
/* The string to parse is stored here, and modified by yylex. */
static char *str;
/* The original string pointer. */
static char *strorig;
/* If *CCP could be a register, return the register number and advance
*CCP. Otherwise don't change *CCP, and return 0. */
static enum m68k_register
m68k_reg_parse (ccp)
register char **ccp;
{
char *start = *ccp;
char c;
char *p;
symbolS *symbolp;
if (flag_reg_prefix_optional)
{
if (*start == REGISTER_PREFIX)
start++;
p = start;
}
else
{
if (*start != REGISTER_PREFIX)
return 0;
p = start + 1;
}
if (! is_name_beginner (*p))
return 0;
p++;
while (is_part_of_name (*p) && *p != '.' && *p != ':' && *p != '*')
p++;
c = *p;
*p = 0;
symbolp = symbol_find (start);
*p = c;
if (symbolp != NULL && S_GET_SEGMENT (symbolp) == reg_section)
{
*ccp = p;
return S_GET_VALUE (symbolp);
}
/* In MRI mode, something like foo.bar can be equated to a register
name. */
while (flag_mri && c == '.')
{
++p;
while (is_part_of_name (*p) && *p != '.' && *p != ':' && *p != '*')
p++;
c = *p;
*p = '\0';
symbolp = symbol_find (start);
*p = c;
if (symbolp != NULL && S_GET_SEGMENT (symbolp) == reg_section)
{
*ccp = p;
return S_GET_VALUE (symbolp);
}
}
return 0;
}
/* The lexer. */
static int
yylex ()
{
enum m68k_register reg;
char *s;
int parens;
int c = 0;
int tail = 0;
char *hold;
if (*str == ' ')
++str;
if (*str == '\0')
return 0;
/* Various special characters are just returned directly. */
switch (*str)
{
case '@':
/* In MRI mode, this can be the start of an octal number. */
if (flag_mri)
{
if (ISDIGIT (str[1])
|| ((str[1] == '+' || str[1] == '-')
&& ISDIGIT (str[2])))
break;
}
/* Fall through. */
case '#':
case '&':
case ',':
case ')':
case '/':
case '[':
case ']':
case '<':
case '>':
return *str++;
case '+':
/* It so happens that a '+' can only appear at the end of an
operand, or if it is trailed by an '&'(see mac load insn).
If it appears anywhere else, it must be a unary. */
if (str[1] == '\0' || (str[1] == '&' && str[2] == '\0'))
return *str++;
break;
case '-':
/* A '-' can only appear in -(ar), rn-rn, or ar@-. If it
appears anywhere else, it must be a unary minus on an
expression, unless it it trailed by a '&'(see mac load insn). */
if (str[1] == '\0' || (str[1] == '&' && str[2] == '\0'))
return *str++;
s = str + 1;
if (*s == '(')
++s;
if (m68k_reg_parse (&s) != 0)
return *str++;
break;
case '(':
/* A '(' can only appear in `(reg)', `(expr,...', `([', `@(', or
`)('. If it appears anywhere else, it must be starting an
expression. */
if (str[1] == '['
|| (str > strorig
&& (str[-1] == '@'
|| str[-1] == ')')))
return *str++;
s = str + 1;
if (m68k_reg_parse (&s) != 0)
return *str++;
/* Check for the case of '(expr,...' by scanning ahead. If we
find a comma outside of balanced parentheses, we return '('.
If we find an unbalanced right parenthesis, then presumably
the '(' really starts an expression. */
parens = 0;
for (s = str + 1; *s != '\0'; s++)
{
if (*s == '(')
++parens;
else if (*s == ')')
{
if (parens == 0)
break;
--parens;
}
else if (*s == ',' && parens == 0)
{
/* A comma can not normally appear in an expression, so
this is a case of '(expr,...'. */
return *str++;
}
}
}
/* See if it's a register. */
reg = m68k_reg_parse (&str);
if (reg != 0)
{
int ret;
yylval.reg = reg;
if (reg >= DATA0 && reg <= DATA7)
ret = DR;
else if (reg >= ADDR0 && reg <= ADDR7)
ret = AR;
else if (reg >= FP0 && reg <= FP7)
return FPR;
else if (reg == FPI
|| reg == FPS
|| reg == FPC)
return FPCR;
else if (reg == PC)
return LPC;
else if (reg >= ZDATA0 && reg <= ZDATA7)
ret = ZDR;
else if (reg >= ZADDR0 && reg <= ZADDR7)
ret = ZAR;
else if (reg == ZPC)
return LZPC;
else
return CREG;
/* If we get here, we have a data or address register. We
must check for a size or scale; if we find one, we must
return INDEXREG. */
s = str;
if (*s != '.' && *s != ':' && *s != '*')
return ret;
yylval.indexreg.reg = reg;
if (*s != '.' && *s != ':')
yylval.indexreg.size = SIZE_UNSPEC;
else
{
++s;
switch (*s)
{
case 'w':
case 'W':
yylval.indexreg.size = SIZE_WORD;
++s;
break;
case 'l':
case 'L':
yylval.indexreg.size = SIZE_LONG;
++s;
break;
default:
yyerror (_("illegal size specification"));
yylval.indexreg.size = SIZE_UNSPEC;
break;
}
}
yylval.indexreg.scale = 1;
if (*s == '*' || *s == ':')
{
expressionS scale;
++s;
hold = input_line_pointer;
input_line_pointer = s;
expression (&scale);
s = input_line_pointer;
input_line_pointer = hold;
if (scale.X_op != O_constant)
yyerror (_("scale specification must resolve to a number"));
else
{
switch (scale.X_add_number)
{
case 1:
case 2:
case 4:
case 8:
yylval.indexreg.scale = scale.X_add_number;
break;
default:
yyerror (_("invalid scale value"));
break;
}
}
}
str = s;
return INDEXREG;
}
/* It must be an expression. Before we call expression, we need to
look ahead to see if there is a size specification. We must do
that first, because otherwise foo.l will be treated as the symbol
foo.l, rather than as the symbol foo with a long size
specification. The grammar requires that all expressions end at
the end of the operand, or with ',', '(', ']', ')'. */
parens = 0;
for (s = str; *s != '\0'; s++)
{
if (*s == '(')
{
if (parens == 0
&& s > str
&& (s[-1] == ')' || ISALNUM (s[-1])))
break;
++parens;
}
else if (*s == ')')
{
if (parens == 0)
break;
--parens;
}
else if (parens == 0
&& (*s == ',' || *s == ']'))
break;
}
yylval.exp.size = SIZE_UNSPEC;
if (s <= str + 2
|| (s[-2] != '.' && s[-2] != ':'))
tail = 0;
else
{
switch (s[-1])
{
case 's':
case 'S':
case 'b':
case 'B':
yylval.exp.size = SIZE_BYTE;
break;
case 'w':
case 'W':
yylval.exp.size = SIZE_WORD;
break;
case 'l':
case 'L':
yylval.exp.size = SIZE_LONG;
break;
default:
break;
}
if (yylval.exp.size != SIZE_UNSPEC)
tail = 2;
}
#ifdef OBJ_ELF
{
/* Look for @PLTPC, etc. */
char *cp;
yylval.exp.pic_reloc = pic_none;
cp = s - tail;
if (cp - 7 > str && cp[-7] == '@')
{
if (strncmp (cp - 7, "@TLSLDM", 7) == 0)
{
yylval.exp.pic_reloc = pic_tls_ldm;
tail += 7;
}
else if (strncmp (cp - 7, "@TLSLDO", 7) == 0)
{
yylval.exp.pic_reloc = pic_tls_ldo;
tail += 7;
}
}
else if (cp - 6 > str && cp[-6] == '@')
{
if (strncmp (cp - 6, "@PLTPC", 6) == 0)
{
yylval.exp.pic_reloc = pic_plt_pcrel;
tail += 6;
}
else if (strncmp (cp - 6, "@GOTPC", 6) == 0)
{
yylval.exp.pic_reloc = pic_got_pcrel;
tail += 6;
}
else if (strncmp (cp - 6, "@TLSGD", 6) == 0)
{
yylval.exp.pic_reloc = pic_tls_gd;
tail += 6;
}
else if (strncmp (cp - 6, "@TLSIE", 6) == 0)
{
yylval.exp.pic_reloc = pic_tls_ie;
tail += 6;
}
else if (strncmp (cp - 6, "@TLSLE", 6) == 0)
{
yylval.exp.pic_reloc = pic_tls_le;
tail += 6;
}
}
else if (cp - 4 > str && cp[-4] == '@')
{
if (strncmp (cp - 4, "@PLT", 4) == 0)
{
yylval.exp.pic_reloc = pic_plt_off;
tail += 4;
}
else if (strncmp (cp - 4, "@GOT", 4) == 0)
{
yylval.exp.pic_reloc = pic_got_off;
tail += 4;
}
}
}
#endif
if (tail != 0)
{
c = s[-tail];
s[-tail] = 0;
}
hold = input_line_pointer;
input_line_pointer = str;
expression (&yylval.exp.exp);
str = input_line_pointer;
input_line_pointer = hold;
if (tail != 0)
{
s[-tail] = c;
str = s;
}
return EXPR;
}
/* Parse an m68k operand. This is the only function which is called
from outside this file. */
int
m68k_ip_op (s, oparg)
char *s;
struct m68k_op *oparg;
{
memset (oparg, 0, sizeof *oparg);
oparg->error = NULL;
oparg->index.reg = ZDATA0;
oparg->index.scale = 1;
oparg->disp.exp.X_op = O_absent;
oparg->odisp.exp.X_op = O_absent;
str = strorig = s;
op = oparg;
return yyparse ();
}
/* The error handler. */
static void
yyerror (s)
const char *s;
{
op->error = s;
}
|