Pristine Ack-5.5
[Ack-5.5.git] / mach / 6500 / as / mach4.c
1 #define RCSID4 "$Id: mach4.c,v 3.5 1994/06/24 12:54:07 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 /*
10  * Mostek 6500 parsing tables.
11  */
12
13
14 /* From the READ_ME file - translation by Albert Koelmans:
15  * ________________
16  *
17  * De .h en .l extensions van expressies zijn hard nodig.
18  * Ze zorgen er echter ook voor dat er geen relocatable code geproduceerd
19  * kan worden. Beschouw het volgende voorbeeld:
20  *
21  * The .h and .l extensions of expressions are vital.  However, they prevent
22  * relocatable code from being generated.  Consider the following example:
23  *
24  * (file 1)
25  * .sect .text          ! 1
26  * lda #[endbss].l              ! 2
27  * ldx #[endbss].h              ! 3
28  *
29  * (file 2)
30  * .sect .bss           ! 4
31  * endbss:                      ! 5
32  *
33  * Wat voor relocation struct moet er nu voor de instructie in regel 3
34  * worden geproduceerd?
35  * 
36  * What kind of relocation structure needs to be generated for the instruction
37  * in line 3?
38  */
39
40 expr
41         :       expr    EXTENSION
42                         { $$.val = ($1.val >> $2) & 0xFF;
43 #ifdef RELOCATION
44                           $$.typ = combine($1.typ, S_ABS, '&');
45                                             /* This will generate an 'invalid operator'      */
46                                             /* error if $1.typ is not absolute after pass 1. */
47 #else
48                           $$.typ = $1.typ;  /* Even if $1.typ is relocatable, it should be   */
49                                             /* absolute by the final pass.                   */
50 #endif /* RELOCATION */
51                         }
52         ;
53 operation
54         :       NOPOP
55                         { emit1($1); }
56         |       BITOP   expr
57                         { code($2,$1,$1+8); }
58         |       JMPOP   expr
59                         { emit1($1);
60 #ifdef RELOCATION
61                           newrelo($2.typ, RELO2);
62 #endif
63                           emit2($2.val);
64                         }
65         |       JMPOP   '(' expr ')'
66                         { emit1($1+0x20);
67 #ifdef RELOCATION
68                           newrelo($3.typ, RELO2);
69 #endif
70                           emit2($3.val);
71                         }
72         |       JSROP   expr
73                         { emit1($1);
74 #ifdef RELOCATION
75                           newrelo($2.typ, RELO2);
76 #endif
77                           emit2($2.val);
78                         }
79         |       LDXOP   '#' expr
80                         { emit1(0xA2);
81 #ifdef RELOCATION
82                           newrelo($3.typ, RELO1);
83 #endif
84                           emit1($3.val);
85                         }
86         |       LDXOP   expr
87                         { code($2,0xA6,0xAE); }
88         |       LDXOP   expr ',' Y
89                         { code($2,0xB6,0xBE); }
90         |       LDYOP   '#' expr
91                         { emit1(0xA0);
92 #ifdef RELOCATION
93                           newrelo($3.typ, RELO1);
94 #endif
95                           emit1($3.val);
96                         }
97         |       LDYOP   expr
98                         { code($2,0xA4,0xAC); }
99         |       LDYOP   expr ',' X
100                         { code($2,0xB4,0xBC); }
101         |       STXOP   expr
102                         { code($2,$1+0x06,$1+0x0E); }
103         |       STXOP   expr ',' Y
104                         { emit1($1+0x16);
105 #ifdef RELOCATION
106                           newrelo($2.typ, RELO1);
107 #endif
108                           emit1(lowb($2.val));
109                         }
110         |       STYOP   expr
111                         { code($2,$1+0x04,$1+0x0C); }
112         |       STYOP   expr ',' X
113                         { emit1($1+0x14);
114 #ifdef RELOCATION
115                           newrelo($2.typ, RELO1);
116 #endif
117                           emit1(lowb($2.val));
118                         }
119         |       addop   '#' expr
120                         { if ($1==0x80) serror("no store immediate");
121                           emit1($1+0x09);
122 #ifdef RELOCATION
123                           newrelo($3.typ, RELO1);
124 #endif
125                           emit1($3.val);
126                         }
127         |       addop   expr
128                         { code($2,$1+0x05,$1+0x0D); }
129         |       addop   expr ',' X
130                         { code($2,$1+0x15,$1+0x1D); }
131         |       addop   expr ',' Y
132                         { emit1($1+0x19);
133 #ifdef RELOCATION
134                           newrelo($2.typ, RELO2);
135 #endif
136                           emit2($2.val);
137                         }
138         |       addop   '(' expr ',' X ')'
139                         { emit1($1+0x01);
140 #ifdef RELOCATION
141                           newrelo($3.typ, RELO1);
142 #endif
143                           emit1(lowb($3.val));
144                         }
145         |       addop   '(' expr ')' ',' Y
146                         { emit1($1+0x11);
147 #ifdef RELOCATION
148                           newrelo($3.typ, RELO1);
149 #endif
150                           emit1(lowb($3.val));
151                         }
152         |       ROLOP   /* Default is A. */
153                         { emit1($1+0x0A); }
154         |       ROLOP   A
155                         { emit1($1+0x0A); }
156         |       ROLOP   expr
157                         { code($2,$1+0x06,$1+0x0E); }
158         |       ROLOP   expr ',' X
159                         { code($2,$1+0x16,$1+0x1E); }
160         |       BRAOP   expr
161                         { branch($1,$2); }
162         |       CPXOP   '#' expr
163                         { emit1($1+0x00);
164 #ifdef RELOCATION
165                           newrelo($3.typ, RELO1);
166 #endif
167                           emit1($3.val);
168                         }
169         |       CPXOP   expr
170                         { code($2,$1+0x04,$1+0x0C); }
171         |       INCOP   expr
172                         { code($2,$1+0x06,$1+0x0E); }
173         |       INCOP   expr ',' X
174                         { code($2,$1+0x16,$1+0x1E); }
175         ;
176 addop
177         :       ADDOP
178         |       PSEU
179                         { emit1($1>>8); $$ = $1 & 0xFF; }
180         ;