Pristine Ack-5.5
[Ack-5.5.git] / mach / i86 / as / mach4.c
1 #define RCSID4 "$Id: mach4.c,v 3.7 1994/06/23 16:08:49 ceriel Exp $"
2
3 /*
4  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
5  * See the copyright notice in the ACK home directory, in the file "Copyright".
6  *
7  */
8
9 operation
10         :       prefix oper
11         ;
12 prefix  :       /* empty */
13         |       prefix PREFIX
14                         {       emit1($2);}
15         ;
16 oper    :       NOOP_1
17                         {       emit1($1);}
18         |       NOOP_2
19                         {       emit2($1);}
20         |       JOP expr
21                         {       branch($1,$2);}
22         |       PUSHOP ea_1
23                         {       pushop($1);}
24         |       IOOP expr
25                         {       emit1($1);
26 #ifdef RELOCATION
27                                 newrelo($2.typ, RELO1);
28 #endif
29                                 emit1($2.val);
30                         }
31         |       IOOP R16
32                         {       if ($2!=2) serror("register error");
33                                 emit1($1+010);
34                         }
35         |       ADDOP ea_ea
36                         {       addop($1);}
37         |       ROLOP ea_ea
38                         {       rolop($1);}
39         |       INCOP ea_1
40                         {       incop($1);}
41         |       IMUL ea_ea
42                         {       imul($1);}
43         |       IMUL ea_1
44                         {       regsize($1); emit1(0366|($1&1)); ea_1($1&070);}
45         |       NOTOP ea_1
46                         {       regsize($1); emit1(0366|($1&1)); ea_1($1&070);}
47         |       CALLOP ea_1
48                         {       callop($1&0xFFFF);}
49         |       CALFOP expr ':' expr
50                         {       emit1($1>>8);
51 #ifdef RELOCATION
52                                 newrelo($4.typ, RELO2);
53 #endif
54                                 emit2($4.val);
55 #ifdef RELOCATION
56                                 newrelo($2.typ, RELO2);
57 #endif
58                                 emit2($2.val);
59                         }
60         |       CALFOP mem
61                         {       emit1(0377); ea_2($1&0xFF);}
62         |       ENTER absexp ',' absexp
63                         {       fit(fitw($2)); fit(fitb($4));
64                                 emit1($1); emit2((int)$2); emit1((int)$4);
65                         }
66         |       LEAOP R16 ',' mem
67                         {       emit1($1); ea_2($2<<3);}
68         |       ARPLOP mem ',' R16
69                         {       emit1($1); ea_2($4<<3);}
70         |       EXTOP   R16 ',' ea_2
71                         {       emit1(0xF); emit1($1);
72                                 ea_2($2<<3);
73                         }
74         |       EXTOP1  ea_1
75                         {       regsize(1); emit1(0xF); emit1($1&07); 
76                                 ea_1($1&070);
77                         }
78         |       ESC absexp ',' mem
79                         {       fit(fit6($2));
80                                 emit1(0330 | $2>>3);
81                                 ea_2(($2&7)<<3);
82                         }
83         |       INT absexp
84                         {       if ($2==3)
85                                         emit1(0314);
86                                 else {
87                                         emit1(0315); emit1($2);
88                                 }
89                         }
90         |       RET
91                         {       emit1($1);}
92         |       RET expr
93                         {       emit1($1-1);
94 #ifdef RELOCATION
95                                 newrelo($2.typ, RELO2);
96 #endif
97                                 emit2($2.val);
98                         }
99         |       XCHG ea_ea
100                         {       xchg($1);}
101         |       TEST ea_ea
102                         {       test($1);}
103         |       MOV ea_ea
104                         {       mov($1);}
105 /* Intel 8087 coprocessor instructions */
106         |       FNOOP
107                         {       emit1($1); emit1($1>>8);}
108         |       FMEM mem
109                         {       emit1($1); ea_2(($1>>8)&070);}
110         |       FST_I st_i
111                         {       emit1($1); emit1(($1>>8)|$2); }
112         |       FST_I ST
113                         {       emit1($1); emit1($1>>8); }
114         |       FST_ST ST ',' st_i
115                         {       emit1($1); emit1(($1>>8)|$4); }
116         |       FST_ST2 ST ',' st_i
117                         {       emit1($1); emit1(($1>>8)|$4); }
118         |       FST_ST st_i ',' ST
119                         {       emit1($1|4); emit1((($1>>8)|$2)); }
120         |       FST_ST2 st_i ',' ST
121                         {       emit1($1|4); emit1((($1>>8)|$2)^010); }
122         ;
123
124 st_i    :       ST '(' absexp ')'
125                         {       if (!fit3($3)) {
126                                         serror("illegal index in FP stack");
127                                 }
128                                 $$ = $3;
129                         }
130         ;
131 mem     :       '(' expr ')'
132                         {       mrg_2 = 6; exp_2 = $2;
133                                 RELOMOVE(rel_2, relonami);
134                         }
135         |       bases
136                         {       exp_2.val = 0; exp_2.typ = S_ABS; indexed();}
137         |       expr bases
138                         {       exp_2 = $1; indexed();
139                                 RELOMOVE(rel_2, relonami);
140                         }
141         ;
142 bases   :       '(' R16 ')'
143                         {       mrg_2 = sr_m[$2];}
144         |       '(' R16 ')' '(' R16 ')'
145                         {       mrg_2 = dr_m[$2][$5];}
146         ;
147 ea_2    :       mem
148         |       R8
149                         {       mrg_2 = $1 | 0300;}
150         |       R16
151                         {       mrg_2 = $1 | 0310;}
152         |       RSEG
153                         {       mrg_2 = $1 | 020;}
154         |       expr
155                         {       mrg_2 = 040; exp_2 = $1;
156                                 RELOMOVE(rel_2, relonami);
157                         }
158         ;
159 ea_1    :       ea_2
160                         {       mrg_1 = mrg_2; exp_1 = exp_2;
161                                 RELOMOVE(rel_1, rel_2);
162                         }
163         ;
164 ea_ea   :       ea_1 ',' ea_2
165         ;