Allow inline %assert inside of complex immediates.
[b43-tools.git] / assembler / parser.y
1 %{
2
3 /*
4  *   Copyright (C) 2006-2007  Michael Buesch <mb@bu3sch.de>
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License version 2
8  *   as published by the Free Software Foundation.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *   GNU General Public License for more details.
14  */
15
16 #include "main.h"
17 #include "initvals.h"
18 #include "util.h"
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <stdint.h>
24
25 extern char *yytext;
26 extern void yyerror(char *);
27 extern int yyparse(void);
28 extern int yylex(void);
29
30 static struct operand * store_oper_sanity(struct operand *oper);
31 static void assembler_assertion_failed(void);
32
33 /* The current .section */
34 extern int section;
35 /* Pointer to the current initvals section data structure. */
36 extern struct initvals_sect *cur_initvals_sect;
37
38 %}
39
40 %token SECTION_TEXT SECTION_IVALS
41
42 %token ASM_ARCH ASM_START ASM_ASSERT SPR GPR OFFR LR COMMA SEMICOLON BRACK_OPEN BRACK_CLOSE PAREN_OPEN PAREN_CLOSE HEXNUM DECNUM ARCH_NEWWORLD ARCH_OLDWORLD LABEL IDENT LABELREF
43
44 %token EQUAL NOT_EQUAL LOGICAL_OR LOGICAL_AND PLUS MINUS MULTIPLY DIVIDE BITW_OR BITW_AND BITW_XOR BITW_NOT LEFTSHIFT RIGHTSHIFT
45
46 %token OP_ADD OP_ADDSC OP_ADDC OP_ADDSCC OP_SUB OP_SUBSC OP_SUBC OP_SUBSCC OP_SRA OP_OR OP_AND OP_XOR OP_SR OP_SRX OP_SL OP_RL OP_RR OP_NAND OP_ORX OP_MOV OP_JMP OP_JAND OP_JNAND OP_JS OP_JNS OP_JE OP_JNE OP_JLS OP_JGES OP_JGS OP_JLES OP_JL OP_JGE OP_JG OP_JLE OP_JZX OP_JNZX OP_JEXT OP_JNEXT OP_CALL OP_RET OP_TKIPH OP_TKIPHS OP_TKIPL OP_TKIPLS OP_NAP RAW_CODE
47
48 %token IVAL_MMIO16 IVAL_MMIO32 IVAL_PHY IVAL_RADIO IVAL_SHM16 IVAL_SHM32
49
50 %start line
51
52 %%
53
54 line    : line_terminator {
55                 /* empty */
56           }
57         | line statement line_terminator {
58                 struct statement *s = $2;
59                 if (s) {
60                         if (section != SECTION_TEXT)
61                                 yyerror("Microcode text instruction in non .text section");
62                         memcpy(&s->info, &cur_lineinfo, sizeof(struct lineinfo));
63                         list_add_tail(&s->list, &infile.sl);
64                 }
65           }
66         | line section_switch line_terminator {
67           }
68         | line ivals_write line_terminator {
69                 struct initval_op *io = $2;
70                 if (section != SECTION_IVALS)
71                         yyerror("InitVals write in non .initvals section");
72                 memcpy(&io->info, &cur_lineinfo, sizeof(struct lineinfo));
73                 INIT_LIST_HEAD(&io->list);
74                 list_add_tail(&io->list, &cur_initvals_sect->ops);
75           }
76         ;
77
78 /* Allow terminating lines with the ";" char */
79 line_terminator : /* Nothing */
80                 | SEMICOLON line_terminator
81                 ;
82
83 section_switch  : SECTION_TEXT {
84                         section = SECTION_TEXT;
85                   }
86                 | SECTION_IVALS PAREN_OPEN identifier PAREN_CLOSE {
87                         const char *sectname = $3;
88                         struct initvals_sect *s;
89                         cur_initvals_sect = NULL;
90                         /* Search if there already is a section by that name. */
91                         list_for_each_entry(s, &infile.ivals, list) {
92                                 if (strcmp(sectname, s->name) == 0)
93                                         cur_initvals_sect = s;
94                         }
95                         if (!cur_initvals_sect) {
96                                 /* Not found, create a new one. */
97                                 s = xmalloc(sizeof(struct initvals_sect));
98                                 s->name = sectname;
99                                 INIT_LIST_HEAD(&s->ops);
100                                 INIT_LIST_HEAD(&s->list);
101                                 list_add_tail(&s->list, &infile.ivals);
102                                 cur_initvals_sect = s;
103                         }
104                         section = SECTION_IVALS;
105                   }
106                 ;
107
108 ivals_write     : IVAL_MMIO16 imm_value COMMA imm_value {
109                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
110                         iop->type = IVAL_W_MMIO16;
111                         iop->args[0] = (unsigned int)(unsigned long)$2;
112                         iop->args[1] = (unsigned int)(unsigned long)$4;
113                         $$ = iop;
114                   }
115                 | IVAL_MMIO32 imm_value COMMA imm_value {
116                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
117                         iop->type = IVAL_W_MMIO32;
118                         iop->args[0] = (unsigned int)(unsigned long)$2;
119                         iop->args[1] = (unsigned int)(unsigned long)$4;
120                         $$ = iop;
121                   }
122                 | IVAL_PHY imm_value COMMA imm_value {
123                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
124                         iop->type = IVAL_W_PHY;
125                         iop->args[0] = (unsigned int)(unsigned long)$2;
126                         iop->args[1] = (unsigned int)(unsigned long)$4;
127                         $$ = iop;
128                   }
129                 | IVAL_RADIO imm_value COMMA imm_value {
130                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
131                         iop->type = IVAL_W_RADIO;
132                         iop->args[0] = (unsigned int)(unsigned long)$2;
133                         iop->args[1] = (unsigned int)(unsigned long)$4;
134                         $$ = iop;
135                   }
136                 | IVAL_SHM16 imm_value COMMA imm_value COMMA imm_value {
137                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
138                         iop->type = IVAL_W_SHM16;
139                         iop->args[0] = (unsigned int)(unsigned long)$2;
140                         iop->args[1] = (unsigned int)(unsigned long)$4;
141                         iop->args[2] = (unsigned int)(unsigned long)$6;
142                         $$ = iop;
143                   }
144                 | IVAL_SHM32 imm_value COMMA imm_value COMMA imm_value {
145                         struct initval_op *iop = xmalloc(sizeof(struct initval_op));
146                         iop->type = IVAL_W_SHM32;
147                         iop->args[0] = (unsigned int)(unsigned long)$2;
148                         iop->args[1] = (unsigned int)(unsigned long)$4;
149                         iop->args[2] = (unsigned int)(unsigned long)$6;
150                         $$ = iop;
151                   }
152                 ;
153
154 statement       : asmdir {
155                         struct asmdir *ad = $1;
156                         if (ad) {
157                                 struct statement *s = xmalloc(sizeof(struct statement));
158                                 INIT_LIST_HEAD(&s->list);
159                                 s->type = STMT_ASMDIR;
160                                 s->u.asmdir = $1;
161                                 $$ = s;
162                         } else
163                                 $$ = NULL;
164                   }
165                 | label {
166                         struct statement *s = xmalloc(sizeof(struct statement));
167                         INIT_LIST_HEAD(&s->list);
168                         s->type = STMT_LABEL;
169                         s->u.label = $1;
170                         $$ = s;
171                   }
172                 | insn_add {
173                         struct statement *s = xmalloc(sizeof(struct statement));
174                         INIT_LIST_HEAD(&s->list);
175                         s->type = STMT_INSN;
176                         s->u.insn = $1;
177                         $$ = s;
178                   }
179                 | insn_addsc {
180                         struct statement *s = xmalloc(sizeof(struct statement));
181                         INIT_LIST_HEAD(&s->list);
182                         s->type = STMT_INSN;
183                         s->u.insn = $1;
184                         $$ = s;
185                   }
186                 | insn_addc {
187                         struct statement *s = xmalloc(sizeof(struct statement));
188                         INIT_LIST_HEAD(&s->list);
189                         s->type = STMT_INSN;
190                         s->u.insn = $1;
191                         $$ = s;
192                   }
193                 | insn_addscc {
194                         struct statement *s = xmalloc(sizeof(struct statement));
195                         INIT_LIST_HEAD(&s->list);
196                         s->type = STMT_INSN;
197                         s->u.insn = $1;
198                         $$ = s;
199                   }
200                 | insn_sub {
201                         struct statement *s = xmalloc(sizeof(struct statement));
202                         INIT_LIST_HEAD(&s->list);
203                         s->type = STMT_INSN;
204                         s->u.insn = $1;
205                         $$ = s;
206                   }
207                 | insn_subsc {
208                         struct statement *s = xmalloc(sizeof(struct statement));
209                         INIT_LIST_HEAD(&s->list);
210                         s->type = STMT_INSN;
211                         s->u.insn = $1;
212                         $$ = s;
213                   }
214                 | insn_subc {
215                         struct statement *s = xmalloc(sizeof(struct statement));
216                         INIT_LIST_HEAD(&s->list);
217                         s->type = STMT_INSN;
218                         s->u.insn = $1;
219                         $$ = s;
220                   }
221                 | insn_subscc {
222                         struct statement *s = xmalloc(sizeof(struct statement));
223                         INIT_LIST_HEAD(&s->list);
224                         s->type = STMT_INSN;
225                         s->u.insn = $1;
226                         $$ = s;
227                   }
228                 | insn_sra {
229                         struct statement *s = xmalloc(sizeof(struct statement));
230                         INIT_LIST_HEAD(&s->list);
231                         s->type = STMT_INSN;
232                         s->u.insn = $1;
233                         $$ = s;
234                   }
235                 | insn_or {
236                         struct statement *s = xmalloc(sizeof(struct statement));
237                         INIT_LIST_HEAD(&s->list);
238                         s->type = STMT_INSN;
239                         s->u.insn = $1;
240                         $$ = s;
241                   }
242                 | insn_and {
243                         struct statement *s = xmalloc(sizeof(struct statement));
244                         INIT_LIST_HEAD(&s->list);
245                         s->type = STMT_INSN;
246                         s->u.insn = $1;
247                         $$ = s;
248                   }
249                 | insn_xor {
250                         struct statement *s = xmalloc(sizeof(struct statement));
251                         INIT_LIST_HEAD(&s->list);
252                         s->type = STMT_INSN;
253                         s->u.insn = $1;
254                         $$ = s;
255                   }
256                 | insn_sr {
257                         struct statement *s = xmalloc(sizeof(struct statement));
258                         INIT_LIST_HEAD(&s->list);
259                         s->type = STMT_INSN;
260                         s->u.insn = $1;
261                         $$ = s;
262                   }
263                 | insn_srx {
264                         struct statement *s = xmalloc(sizeof(struct statement));
265                         INIT_LIST_HEAD(&s->list);
266                         s->type = STMT_INSN;
267                         s->u.insn = $1;
268                         $$ = s;
269                   }
270                 | insn_sl {
271                         struct statement *s = xmalloc(sizeof(struct statement));
272                         INIT_LIST_HEAD(&s->list);
273                         s->type = STMT_INSN;
274                         s->u.insn = $1;
275                         $$ = s;
276                   }
277                 | insn_rl {
278                         struct statement *s = xmalloc(sizeof(struct statement));
279                         INIT_LIST_HEAD(&s->list);
280                         s->type = STMT_INSN;
281                         s->u.insn = $1;
282                         $$ = s;
283                   }
284                 | insn_rr {
285                         struct statement *s = xmalloc(sizeof(struct statement));
286                         INIT_LIST_HEAD(&s->list);
287                         s->type = STMT_INSN;
288                         s->u.insn = $1;
289                         $$ = s;
290                   }
291                 | insn_nand {
292                         struct statement *s = xmalloc(sizeof(struct statement));
293                         INIT_LIST_HEAD(&s->list);
294                         s->type = STMT_INSN;
295                         s->u.insn = $1;
296                         $$ = s;
297                   }
298                 | insn_orx {
299                         struct statement *s = xmalloc(sizeof(struct statement));
300                         INIT_LIST_HEAD(&s->list);
301                         s->type = STMT_INSN;
302                         s->u.insn = $1;
303                         $$ = s;
304                   }
305                 | insn_mov {
306                         struct statement *s = xmalloc(sizeof(struct statement));
307                         INIT_LIST_HEAD(&s->list);
308                         s->type = STMT_INSN;
309                         s->u.insn = $1;
310                         $$ = s;
311                   }
312                 | insn_jmp {
313                         struct statement *s = xmalloc(sizeof(struct statement));
314                         INIT_LIST_HEAD(&s->list);
315                         s->type = STMT_INSN;
316                         s->u.insn = $1;
317                         $$ = s;
318                   }
319                 | insn_jand {
320                         struct statement *s = xmalloc(sizeof(struct statement));
321                         INIT_LIST_HEAD(&s->list);
322                         s->type = STMT_INSN;
323                         s->u.insn = $1;
324                         $$ = s;
325                   }
326                 | insn_jnand {
327                         struct statement *s = xmalloc(sizeof(struct statement));
328                         INIT_LIST_HEAD(&s->list);
329                         s->type = STMT_INSN;
330                         s->u.insn = $1;
331                         $$ = s;
332                   }
333                 | insn_js {
334                         struct statement *s = xmalloc(sizeof(struct statement));
335                         INIT_LIST_HEAD(&s->list);
336                         s->type = STMT_INSN;
337                         s->u.insn = $1;
338                         $$ = s;
339                   }
340                 | insn_jns {
341                         struct statement *s = xmalloc(sizeof(struct statement));
342                         INIT_LIST_HEAD(&s->list);
343                         s->type = STMT_INSN;
344                         s->u.insn = $1;
345                         $$ = s;
346                   }
347                 | insn_je {
348                         struct statement *s = xmalloc(sizeof(struct statement));
349                         INIT_LIST_HEAD(&s->list);
350                         s->type = STMT_INSN;
351                         s->u.insn = $1;
352                         $$ = s;
353                   }
354                 | insn_jne {
355                         struct statement *s = xmalloc(sizeof(struct statement));
356                         INIT_LIST_HEAD(&s->list);
357                         s->type = STMT_INSN;
358                         s->u.insn = $1;
359                         $$ = s;
360                   }
361                 | insn_jls {
362                         struct statement *s = xmalloc(sizeof(struct statement));
363                         INIT_LIST_HEAD(&s->list);
364                         s->type = STMT_INSN;
365                         s->u.insn = $1;
366                         $$ = s;
367                   }
368                 | insn_jges {
369                         struct statement *s = xmalloc(sizeof(struct statement));
370                         INIT_LIST_HEAD(&s->list);
371                         s->type = STMT_INSN;
372                         s->u.insn = $1;
373                         $$ = s;
374                   }
375                 | insn_jgs {
376                         struct statement *s = xmalloc(sizeof(struct statement));
377                         INIT_LIST_HEAD(&s->list);
378                         s->type = STMT_INSN;
379                         s->u.insn = $1;
380                         $$ = s;
381                   }
382                 | insn_jles {
383                         struct statement *s = xmalloc(sizeof(struct statement));
384                         INIT_LIST_HEAD(&s->list);
385                         s->type = STMT_INSN;
386                         s->u.insn = $1;
387                         $$ = s;
388                   }
389                 | insn_jl {
390                         struct statement *s = xmalloc(sizeof(struct statement));
391                         INIT_LIST_HEAD(&s->list);
392                         s->type = STMT_INSN;
393                         s->u.insn = $1;
394                         $$ = s;
395                   }
396                 | insn_jge {
397                         struct statement *s = xmalloc(sizeof(struct statement));
398                         INIT_LIST_HEAD(&s->list);
399                         s->type = STMT_INSN;
400                         s->u.insn = $1;
401                         $$ = s;
402                   }
403                 | insn_jg {
404                         struct statement *s = xmalloc(sizeof(struct statement));
405                         INIT_LIST_HEAD(&s->list);
406                         s->type = STMT_INSN;
407                         s->u.insn = $1;
408                         $$ = s;
409                   }
410                 | insn_jle {
411                         struct statement *s = xmalloc(sizeof(struct statement));
412                         INIT_LIST_HEAD(&s->list);
413                         s->type = STMT_INSN;
414                         s->u.insn = $1;
415                         $$ = s;
416                   }
417                 | insn_jzx {
418                         struct statement *s = xmalloc(sizeof(struct statement));
419                         INIT_LIST_HEAD(&s->list);
420                         s->type = STMT_INSN;
421                         s->u.insn = $1;
422                         $$ = s;
423                   }
424                 | insn_jnzx {
425                         struct statement *s = xmalloc(sizeof(struct statement));
426                         INIT_LIST_HEAD(&s->list);
427                         s->type = STMT_INSN;
428                         s->u.insn = $1;
429                         $$ = s;
430                   }
431                 | insn_jext {
432                         struct statement *s = xmalloc(sizeof(struct statement));
433                         INIT_LIST_HEAD(&s->list);
434                         s->type = STMT_INSN;
435                         s->u.insn = $1;
436                         $$ = s;
437                   }
438                 | insn_jnext {
439                         struct statement *s = xmalloc(sizeof(struct statement));
440                         INIT_LIST_HEAD(&s->list);
441                         s->type = STMT_INSN;
442                         s->u.insn = $1;
443                         $$ = s;
444                   }
445                 | insn_call {
446                         struct statement *s = xmalloc(sizeof(struct statement));
447                         INIT_LIST_HEAD(&s->list);
448                         s->type = STMT_INSN;
449                         s->u.insn = $1;
450                         $$ = s;
451                   }
452                 | insn_ret {
453                         struct statement *s = xmalloc(sizeof(struct statement));
454                         INIT_LIST_HEAD(&s->list);
455                         s->type = STMT_INSN;
456                         s->u.insn = $1;
457                         $$ = s;
458                   }
459                 | insn_tkiph {
460                         struct statement *s = xmalloc(sizeof(struct statement));
461                         INIT_LIST_HEAD(&s->list);
462                         s->type = STMT_INSN;
463                         s->u.insn = $1;
464                         $$ = s;
465                   }
466                 | insn_tkiphs {
467                         struct statement *s = xmalloc(sizeof(struct statement));
468                         INIT_LIST_HEAD(&s->list);
469                         s->type = STMT_INSN;
470                         s->u.insn = $1;
471                         $$ = s;
472                   }
473                 | insn_tkipl {
474                         struct statement *s = xmalloc(sizeof(struct statement));
475                         INIT_LIST_HEAD(&s->list);
476                         s->type = STMT_INSN;
477                         s->u.insn = $1;
478                         $$ = s;
479                   }
480                 | insn_tkipls {
481                         struct statement *s = xmalloc(sizeof(struct statement));
482                         INIT_LIST_HEAD(&s->list);
483                         s->type = STMT_INSN;
484                         s->u.insn = $1;
485                         $$ = s;
486                   }
487                 | insn_nap {
488                         struct statement *s = xmalloc(sizeof(struct statement));
489                         INIT_LIST_HEAD(&s->list);
490                         s->type = STMT_INSN;
491                         s->u.insn = $1;
492                         $$ = s;
493                   }
494                 | insn_raw {
495                         struct statement *s = xmalloc(sizeof(struct statement));
496                         INIT_LIST_HEAD(&s->list);
497                         s->type = STMT_INSN;
498                         s->u.insn = $1;
499                         $$ = s;
500                   }
501                 ;
502
503 /* ASM directives */
504 asmdir          : ASM_ARCH hexnum_decnum {
505                         struct asmdir *ad = xmalloc(sizeof(struct asmdir));
506                         ad->type = ADIR_ARCH;
507                         ad->u.arch = (unsigned int)(unsigned long)$2;
508                         $$ = ad;
509                   }
510                 | ASM_START identifier {
511                         struct asmdir *ad = xmalloc(sizeof(struct asmdir));
512                         struct label *label = xmalloc(sizeof(struct label));
513                         label->name = $2;
514                         label->direction = LABELREF_ABSOLUTE;
515                         ad->type = ADIR_START;
516                         ad->u.start = label;
517                         $$ = ad;
518                   }
519                 | asm_assert {
520                         $$ = NULL;
521                   }
522                 ;
523
524 asm_assert      : ASM_ASSERT assertion {
525                         unsigned int ok = (unsigned int)(unsigned long)$2;
526                         if (!ok)
527                                 assembler_assertion_failed();
528                         $$ = NULL;
529                   }
530                 ;
531
532 assertion       : PAREN_OPEN assert_expr PAREN_CLOSE {
533                         $$ = $2;
534                   }
535                 | PAREN_OPEN assertion LOGICAL_OR assertion PAREN_CLOSE {
536                         unsigned int a = (unsigned int)(unsigned long)$2;
537                         unsigned int b = (unsigned int)(unsigned long)$4;
538                         unsigned int result = (a || b);
539                         $$ = (void *)(unsigned long)result;
540                   }
541                 | PAREN_OPEN assertion LOGICAL_AND assertion PAREN_CLOSE {
542                         unsigned int a = (unsigned int)(unsigned long)$2;
543                         unsigned int b = (unsigned int)(unsigned long)$4;
544                         unsigned int result = (a && b);
545                         $$ = (void *)(unsigned long)result;
546                   }
547                 ;
548
549 assert_expr     : imm_value EQUAL imm_value {
550                         unsigned int a = (unsigned int)(unsigned long)$1;
551                         unsigned int b = (unsigned int)(unsigned long)$3;
552                         unsigned int result = (a == b);
553                         $$ = (void *)(unsigned long)result;
554                   }
555                 | imm_value NOT_EQUAL imm_value {
556                         unsigned int a = (unsigned int)(unsigned long)$1;
557                         unsigned int b = (unsigned int)(unsigned long)$3;
558                         unsigned int result = (a != b);
559                         $$ = (void *)(unsigned long)result;
560                   }
561                 ;
562
563 label           : LABEL {
564                         struct label *label = xmalloc(sizeof(struct label));
565                         char *l;
566                         l = xstrdup(yytext);
567                         l[strlen(l) - 1] = '\0';
568                         label->name = l;
569                         $$ = label;
570                   }
571                 ;
572
573 /* add */
574 insn_add        : OP_ADD operlist_3 {
575                         struct instruction *insn = xmalloc(sizeof(struct instruction));
576                         insn->op = OP_ADD;
577                         insn->operands = $2;
578                         $$ = insn;
579                   }
580                 ;
581
582 /* add. */
583 insn_addsc      : OP_ADDSC operlist_3 {
584                         struct instruction *insn = xmalloc(sizeof(struct instruction));
585                         insn->op = OP_ADDSC;
586                         insn->operands = $2;
587                         $$ = insn;
588                   }
589                 ;
590
591 /* addc */
592 insn_addc       : OP_ADDC operlist_3 {
593                         struct instruction *insn = xmalloc(sizeof(struct instruction));
594                         insn->op = OP_ADDC;
595                         insn->operands = $2;
596                         $$ = insn;
597                   }
598                 ;
599
600 /* addc. */
601 insn_addscc     : OP_ADDSCC operlist_3 {
602                         struct instruction *insn = xmalloc(sizeof(struct instruction));
603                         insn->op = OP_ADDSCC;
604                         insn->operands = $2;
605                         $$ = insn;
606                   }
607                 ;
608
609 /* sub */
610 insn_sub        : OP_SUB operlist_3 {
611                         struct instruction *insn = xmalloc(sizeof(struct instruction));
612                         insn->op = OP_SUB;
613                         insn->operands = $2;
614                         $$ = insn;
615                   }
616                 ;
617
618 /* sub. */
619 insn_subsc      : OP_SUBSC operlist_3 {
620                         struct instruction *insn = xmalloc(sizeof(struct instruction));
621                         insn->op = OP_SUBSC;
622                         insn->operands = $2;
623                         $$ = insn;
624                   }
625                 ;
626
627 /* subc */
628 insn_subc       : OP_SUBC operlist_3 {
629                         struct instruction *insn = xmalloc(sizeof(struct instruction));
630                         insn->op = OP_SUBC;
631                         insn->operands = $2;
632                         $$ = insn;
633                   }
634                 ;
635
636 /* subc. */
637 insn_subscc     : OP_SUBSCC operlist_3 {
638                         struct instruction *insn = xmalloc(sizeof(struct instruction));
639                         insn->op = OP_SUBSCC;
640                         insn->operands = $2;
641                         $$ = insn;
642                   }
643                 ;
644
645 insn_sra        : OP_SRA operlist_3 {
646                         struct instruction *insn = xmalloc(sizeof(struct instruction));
647                         insn->op = OP_SRA;
648                         insn->operands = $2;
649                         $$ = insn;
650                   }
651                 ;
652
653 insn_or         : OP_OR operlist_3 {
654                         struct instruction *insn = xmalloc(sizeof(struct instruction));
655                         insn->op = OP_OR;
656                         insn->operands = $2;
657                         $$ = insn;
658                   }
659                 ;
660
661 insn_and        : OP_AND operlist_3 {
662                         struct instruction *insn = xmalloc(sizeof(struct instruction));
663                         insn->op = OP_AND;
664                         insn->operands = $2;
665                         $$ = insn;
666                   }
667                 ;
668
669 insn_xor        : OP_XOR operlist_3 {
670                         struct instruction *insn = xmalloc(sizeof(struct instruction));
671                         insn->op = OP_XOR;
672                         insn->operands = $2;
673                         $$ = insn;
674                   }
675                 ;
676
677 insn_sr         : OP_SR operlist_3 {
678                         struct instruction *insn = xmalloc(sizeof(struct instruction));
679                         insn->op = OP_SR;
680                         insn->operands = $2;
681                         $$ = insn;
682                   }
683                 ;
684
685 insn_srx        : OP_SRX extended_operlist {
686                         struct instruction *insn = xmalloc(sizeof(struct instruction));
687                         insn->op = OP_SRX;
688                         insn->operands = $2;
689                         $$ = insn;
690                   }
691                 ;
692
693 insn_sl         : OP_SL operlist_3 {
694                         struct instruction *insn = xmalloc(sizeof(struct instruction));
695                         insn->op = OP_SL;
696                         insn->operands = $2;
697                         $$ = insn;
698                   }
699                 ;
700
701 insn_rl         : OP_RL operlist_3 {
702                         struct instruction *insn = xmalloc(sizeof(struct instruction));
703                         insn->op = OP_RL;
704                         insn->operands = $2;
705                         $$ = insn;
706                   }
707                 ;
708
709 insn_rr         : OP_RR operlist_3 {
710                         struct instruction *insn = xmalloc(sizeof(struct instruction));
711                         insn->op = OP_RR;
712                         insn->operands = $2;
713                         $$ = insn;
714                   }
715                 ;
716
717 insn_nand       : OP_NAND operlist_3 {
718                         struct instruction *insn = xmalloc(sizeof(struct instruction));
719                         insn->op = OP_NAND;
720                         insn->operands = $2;
721                         $$ = insn;
722                   }
723                 ;
724
725 insn_orx        : OP_ORX extended_operlist {
726                         struct instruction *insn = xmalloc(sizeof(struct instruction));
727                         insn->op = OP_ORX;
728                         insn->operands = $2;
729                         $$ = insn;
730                   }
731                 ;
732
733 insn_mov        : OP_MOV operlist_2 {
734                         struct instruction *insn = xmalloc(sizeof(struct instruction));
735                         insn->op = OP_MOV;
736                         insn->operands = $2;
737                         $$ = insn;
738                   }
739                 ;
740
741 insn_jmp        : OP_JMP labelref {
742                         struct instruction *insn = xmalloc(sizeof(struct instruction));
743                         struct operlist *ol = xmalloc(sizeof(struct operlist));
744                         ol->oper[0] = $2;
745                         insn->op = OP_JMP;
746                         insn->operands = ol;
747                         $$ = insn;
748                   }
749                 ;
750
751 insn_jand       : OP_JAND operlist_3 {
752                         struct instruction *insn = xmalloc(sizeof(struct instruction));
753                         insn->op = OP_JAND;
754                         insn->operands = $2;
755                         $$ = insn;
756                   }
757                 ;
758
759 insn_jnand      : OP_JNAND operlist_3 {
760                         struct instruction *insn = xmalloc(sizeof(struct instruction));
761                         insn->op = OP_JNAND;
762                         insn->operands = $2;
763                         $$ = insn;
764                   }
765                 ;
766
767 insn_js         : OP_JS operlist_3 {
768                         struct instruction *insn = xmalloc(sizeof(struct instruction));
769                         insn->op = OP_JS;
770                         insn->operands = $2;
771                         $$ = insn;
772                   }
773                 ;
774
775 insn_jns        : OP_JNS operlist_3 {
776                         struct instruction *insn = xmalloc(sizeof(struct instruction));
777                         insn->op = OP_JNS;
778                         insn->operands = $2;
779                         $$ = insn;
780                   }
781                 ;
782
783 insn_je         : OP_JE operlist_3 {
784                         struct instruction *insn = xmalloc(sizeof(struct instruction));
785                         insn->op = OP_JE;
786                         insn->operands = $2;
787                         $$ = insn;
788                   }
789                 ;
790
791 insn_jne        : OP_JNE operlist_3 {
792                         struct instruction *insn = xmalloc(sizeof(struct instruction));
793                         insn->op = OP_JNE;
794                         insn->operands = $2;
795                         $$ = insn;
796                   }
797                 ;
798
799 insn_jls        : OP_JLS operlist_3 {
800                         struct instruction *insn = xmalloc(sizeof(struct instruction));
801                         insn->op = OP_JLS;
802                         insn->operands = $2;
803                         $$ = insn;
804                   }
805                 ;
806
807 insn_jges       : OP_JGES operlist_3 {
808                         struct instruction *insn = xmalloc(sizeof(struct instruction));
809                         insn->op = OP_JGES;
810                         insn->operands = $2;
811                         $$ = insn;
812                   }
813                 ;
814
815 insn_jgs        : OP_JGS operlist_3 {
816                         struct instruction *insn = xmalloc(sizeof(struct instruction));
817                         insn->op = OP_JGS;
818                         insn->operands = $2;
819                         $$ = insn;
820                   }
821                 ;
822
823 insn_jles       : OP_JLES operlist_3 {
824                         struct instruction *insn = xmalloc(sizeof(struct instruction));
825                         insn->op = OP_JLES;
826                         insn->operands = $2;
827                         $$ = insn;
828                   }
829                 ;
830
831 insn_jl         : OP_JL operlist_3 {
832                         struct instruction *insn = xmalloc(sizeof(struct instruction));
833                         insn->op = OP_JL;
834                         insn->operands = $2;
835                         $$ = insn;
836                   }
837                 ;
838
839 insn_jge        : OP_JGE operlist_3 {
840                         struct instruction *insn = xmalloc(sizeof(struct instruction));
841                         insn->op = OP_JGE;
842                         insn->operands = $2;
843                         $$ = insn;
844                   }
845                 ;
846
847 insn_jg         : OP_JG operlist_3 {
848                         struct instruction *insn = xmalloc(sizeof(struct instruction));
849                         insn->op = OP_JG;
850                         insn->operands = $2;
851                         $$ = insn;
852                   }
853                 ;
854
855 insn_jle        : OP_JLE operlist_3 {
856                         struct instruction *insn = xmalloc(sizeof(struct instruction));
857                         insn->op = OP_JLE;
858                         insn->operands = $2;
859                         $$ = insn;
860                   }
861                 ;
862
863 insn_jzx        : OP_JZX extended_operlist {
864                         struct instruction *insn = xmalloc(sizeof(struct instruction));
865                         insn->op = OP_JZX;
866                         insn->operands = $2;
867                         $$ = insn;
868                   }
869                 ;
870
871 insn_jnzx       : OP_JNZX extended_operlist {
872                         struct instruction *insn = xmalloc(sizeof(struct instruction));
873                         insn->op = OP_JNZX;
874                         insn->operands = $2;
875                         $$ = insn;
876                   }
877                 ;
878
879 insn_jext       : OP_JEXT external_jump_operands {
880                         struct instruction *insn = xmalloc(sizeof(struct instruction));
881                         insn->op = OP_JEXT;
882                         insn->operands = $2;
883                         $$ = insn;
884                   }
885                 ;
886
887 insn_jnext      : OP_JNEXT external_jump_operands {
888                         struct instruction *insn = xmalloc(sizeof(struct instruction));
889                         insn->op = OP_JNEXT;
890                         insn->operands = $2;
891                         $$ = insn;
892                   }
893                 ;
894
895 linkreg         : LR regnr {
896                         $$ = $2;
897                   }
898                 ;
899
900 insn_call       : OP_CALL linkreg COMMA labelref {
901                         struct instruction *insn = xmalloc(sizeof(struct instruction));
902                         struct operlist *ol = xmalloc(sizeof(struct operlist));
903                         struct operand *oper_lr = xmalloc(sizeof(struct operand));
904                         struct operand *oper_zero = xmalloc(sizeof(struct operand));
905                         oper_zero->type = OPER_RAW;
906                         oper_zero->u.raw = 0;
907                         oper_lr->type = OPER_RAW;
908                         oper_lr->u.raw = (unsigned long)$2;
909                         ol->oper[0] = oper_lr;
910                         ol->oper[1] = oper_zero;
911                         ol->oper[2] = $4;
912                         insn->op = OP_CALL;
913                         insn->operands = ol;
914                         $$ = insn;
915                   }
916                 ;
917
918 insn_ret        : OP_RET linkreg COMMA linkreg {
919                         struct instruction *insn = xmalloc(sizeof(struct instruction));
920                         struct operlist *ol = xmalloc(sizeof(struct operlist));
921                         struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
922                         struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
923                         struct operand *oper_zero = xmalloc(sizeof(struct operand));
924                         oper_zero->type = OPER_RAW;
925                         oper_zero->u.raw = 0;
926                         oper_lr0->type = OPER_RAW;
927                         oper_lr0->u.raw = (unsigned long)$2;
928                         oper_lr1->type = OPER_RAW;
929                         oper_lr1->u.raw = (unsigned long)$4;
930                         ol->oper[0] = oper_lr0;
931                         ol->oper[1] = oper_zero;
932                         ol->oper[2] = oper_lr1;
933                         insn->op = OP_RET;
934                         insn->operands = ol;
935                         $$ = insn;
936                   }
937                 ;
938
939 insn_tkiph      : OP_TKIPH operlist_2 {
940                         struct instruction *insn = xmalloc(sizeof(struct instruction));
941                         struct operlist *ol = $2;
942                         struct operand *flags = xmalloc(sizeof(struct operand));
943                         struct immediate *imm = xmalloc(sizeof(struct immediate));
944                         imm->imm = 0x1;
945                         flags->type = OPER_IMM;
946                         flags->u.imm = imm;
947                         ol->oper[2] = ol->oper[1];
948                         ol->oper[1] = flags;
949                         insn->op = OP_TKIPH;
950                         insn->operands = ol;
951                         $$ = insn;
952                   }
953                 ;
954
955 insn_tkiphs     : OP_TKIPHS operlist_2 {
956                         struct instruction *insn = xmalloc(sizeof(struct instruction));
957                         struct operlist *ol = $2;
958                         struct operand *flags = xmalloc(sizeof(struct operand));
959                         struct immediate *imm = xmalloc(sizeof(struct immediate));
960                         imm->imm = 0x1 | 0x2;
961                         flags->type = OPER_IMM;
962                         flags->u.imm = imm;
963                         ol->oper[2] = ol->oper[1];
964                         ol->oper[1] = flags;
965                         insn->op = OP_TKIPH;
966                         insn->operands = ol;
967                         $$ = insn;
968                   }
969                 ;
970
971 insn_tkipl      : OP_TKIPL operlist_2 {
972                         struct instruction *insn = xmalloc(sizeof(struct instruction));
973                         struct operlist *ol = $2;
974                         struct operand *flags = xmalloc(sizeof(struct operand));
975                         struct immediate *imm = xmalloc(sizeof(struct immediate));
976                         imm->imm = 0x0;
977                         flags->type = OPER_IMM;
978                         flags->u.imm = imm;
979                         ol->oper[2] = ol->oper[1];
980                         ol->oper[1] = flags;
981                         insn->op = OP_TKIPH;
982                         insn->operands = ol;
983                         $$ = insn;
984                   }
985                 ;
986
987 insn_tkipls     : OP_TKIPLS operlist_2 {
988                         struct instruction *insn = xmalloc(sizeof(struct instruction));
989                         struct operlist *ol = $2;
990                         struct operand *flags = xmalloc(sizeof(struct operand));
991                         struct immediate *imm = xmalloc(sizeof(struct immediate));
992                         imm->imm = 0x0 | 0x2;
993                         flags->type = OPER_IMM;
994                         flags->u.imm = imm;
995                         ol->oper[2] = ol->oper[1];
996                         ol->oper[1] = flags;
997                         insn->op = OP_TKIPH;
998                         insn->operands = ol;
999                         $$ = insn;
1000                   }
1001                 ;
1002
1003 insn_nap        : OP_NAP {
1004                         struct instruction *insn = xmalloc(sizeof(struct instruction));
1005                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1006                         struct operand *regop = xmalloc(sizeof(struct operand));
1007                         struct operand *zeroop = xmalloc(sizeof(struct operand));
1008                         struct registr *r0 = xmalloc(sizeof(struct registr));
1009                         r0->type = GPR;
1010                         r0->nr = 0;
1011                         regop->type = OPER_REG;
1012                         regop->u.reg = r0;
1013                         zeroop->type = OPER_RAW;
1014                         zeroop->u.raw = 0x000;
1015                         ol->oper[0] = regop;
1016                         ol->oper[1] = regop;
1017                         ol->oper[2] = zeroop;
1018                         insn->op = OP_NAP;
1019                         insn->operands = ol;
1020                         $$ = insn;
1021                   }
1022                 ;
1023
1024 insn_raw        : raw_code operlist_3 {
1025                         struct instruction *insn = xmalloc(sizeof(struct instruction));
1026                         insn->op = RAW_CODE;
1027                         insn->operands = $2;
1028                         insn->opcode = (unsigned long)$1;
1029                         $$ = insn;
1030                   }
1031                 ;
1032
1033 raw_code        : RAW_CODE {
1034                         yytext++; /* skip @ */
1035                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1036                   }
1037                 ;
1038
1039 extended_operlist : imm_value COMMA imm_value COMMA operand COMMA operand COMMA operand {
1040                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1041                         struct operand *mask_oper = xmalloc(sizeof(struct operand));
1042                         struct operand *shift_oper = xmalloc(sizeof(struct operand));
1043                         mask_oper->type = OPER_RAW;
1044                         mask_oper->u.raw = (unsigned long)$1;
1045                         shift_oper->type = OPER_RAW;
1046                         shift_oper->u.raw = (unsigned long)$3;
1047                         ol->oper[0] = mask_oper;
1048                         ol->oper[1] = shift_oper;
1049                         ol->oper[2] = $5;
1050                         ol->oper[3] = $7;
1051                         ol->oper[4] = store_oper_sanity($9);
1052                         $$ = ol;
1053                   }
1054                 ;
1055
1056 external_jump_operands : imm COMMA labelref {
1057                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1058                         struct operand *cond = xmalloc(sizeof(struct operand));
1059                         cond->type = OPER_IMM;
1060                         cond->u.imm = $1;
1061                         ol->oper[0] = cond;
1062                         ol->oper[1] = $3;
1063                         $$ = ol;
1064                   }
1065                 ;
1066
1067 operlist_2      : operand COMMA operand {
1068                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1069                         ol->oper[0] = $1;
1070                         ol->oper[1] = store_oper_sanity($3);
1071                         $$ = ol;
1072                   }
1073                 ;
1074
1075 operlist_3      : operand COMMA operand COMMA operand {
1076                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1077                         ol->oper[0] = $1;
1078                         ol->oper[1] = $3;
1079                         ol->oper[2] = store_oper_sanity($5);
1080                         $$ = ol;
1081                   }
1082                 ;
1083
1084 operand         : reg {
1085                         struct operand *oper = xmalloc(sizeof(struct operand));
1086                         oper->type = OPER_REG;
1087                         oper->u.reg = $1;
1088                         $$ = oper;
1089                   }
1090                 | mem {
1091                         struct operand *oper = xmalloc(sizeof(struct operand));
1092                         oper->type = OPER_MEM;
1093                         oper->u.mem = $1;
1094                         $$ = oper;
1095                   }
1096                 | raw_code {
1097                         struct operand *oper = xmalloc(sizeof(struct operand));
1098                         oper->type = OPER_RAW;
1099                         oper->u.raw = (unsigned long)$1;
1100                         $$ = oper;
1101                   }
1102                 | imm {
1103                         struct operand *oper = xmalloc(sizeof(struct operand));
1104                         oper->type = OPER_IMM;
1105                         oper->u.imm = $1;
1106                         $$ = oper;
1107                   }
1108                 | labelref {
1109                         $$ = $1;
1110                   }
1111                 ;
1112
1113 reg             : GPR regnr {
1114                         struct registr *reg = xmalloc(sizeof(struct registr));
1115                         reg->type = GPR;
1116                         reg->nr = (unsigned long)$2;
1117                         $$ = reg;
1118                   }
1119                 | SPR {
1120                         struct registr *reg = xmalloc(sizeof(struct registr));
1121                         reg->type = SPR;
1122                         yytext += 3; /* skip "spr" */
1123                         reg->nr = strtoul(yytext, NULL, 16);
1124                         $$ = reg;
1125                   }
1126                 | OFFR regnr {
1127                         struct registr *reg = xmalloc(sizeof(struct registr));
1128                         reg->type = OFFR;
1129                         reg->nr = (unsigned long)$2;
1130                         $$ = reg;
1131                   }
1132                 ;
1133
1134 mem             : BRACK_OPEN imm BRACK_CLOSE {
1135                         struct memory *mem = xmalloc(sizeof(struct memory));
1136                         struct immediate *offset_imm = $2;
1137                         mem->type = MEM_DIRECT;
1138                         mem->offset = offset_imm->imm;
1139                         free(offset_imm);
1140                         $$ = mem;
1141                   }
1142                 | BRACK_OPEN imm COMMA OFFR regnr BRACK_CLOSE {
1143                         struct memory *mem = xmalloc(sizeof(struct memory));
1144                         struct immediate *offset_imm = $2;
1145                         mem->type = MEM_INDIRECT;
1146                         mem->offset = offset_imm->imm;
1147                         free(offset_imm);
1148                         mem->offr_nr = (unsigned long)$5;
1149                         $$ = mem;
1150                   }
1151                 ;
1152
1153 imm             : imm_value {
1154                         struct immediate *imm = xmalloc(sizeof(struct immediate));
1155                         imm->imm = (unsigned long)$1;
1156                         $$ = imm;
1157                   }
1158                 ;
1159
1160 imm_value       : hexnum_decnum {
1161                         $$ = $1;
1162                   }
1163                 | complex_imm {
1164                         $$ = $1;
1165                   }
1166                 ;
1167
1168 complex_imm     : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1169                         unsigned long a = (unsigned long)$2;
1170                         unsigned long b = (unsigned long)$4;
1171                         unsigned long operation = (unsigned long)$3;
1172                         unsigned long res = 31337;
1173                         switch (operation) {
1174                         case PLUS:
1175                                 res = a + b;
1176                                 break;
1177                         case MINUS:
1178                                 res = a - b;
1179                                 break;
1180                         case MULTIPLY:
1181                                 res = a * b;
1182                                 break;
1183                         case DIVIDE:
1184                                 res = a / b;
1185                                 break;
1186                         case BITW_OR:
1187                                 res = a | b;
1188                                 break;
1189                         case BITW_AND:
1190                                 res = a & b;
1191                                 break;
1192                         case BITW_XOR:
1193                                 res = a ^ b;
1194                                 break;
1195                         case LEFTSHIFT:
1196                                 res = a << b;
1197                                 break;
1198                         case RIGHTSHIFT:
1199                                 res = a >> b;
1200                                 break;
1201                         default:
1202                                 yyerror("Internal parser BUG. complex_imm oper unknown");
1203                         }
1204                         $$ = (void *)res;
1205                   }
1206                 | PAREN_OPEN complex_imm PAREN_CLOSE {
1207                         $$ = $2;
1208                   }
1209                 | PAREN_OPEN asm_assert PAREN_CLOSE {
1210                         /* Inline assertion. Always return zero */
1211                         $$ = (void *)(unsigned long)(unsigned int)0;
1212                   }
1213                 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1214                         unsigned long n = (unsigned long)$3;
1215                         n = ~n;
1216                         $$ = (void *)n;
1217                   }
1218                 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1219                         $$ = $2;
1220                   }
1221                 ;
1222
1223 complex_imm_oper : PLUS {
1224                         $$ = (void *)(unsigned long)PLUS;
1225                   }
1226                 | MINUS {
1227                         $$ = (void *)(unsigned long)MINUS;
1228                   }
1229                 | MULTIPLY {
1230                         $$ = (void *)(unsigned long)MULTIPLY;
1231                   }
1232                 | DIVIDE {
1233                         $$ = (void *)(unsigned long)DIVIDE;
1234                   }
1235                 | BITW_OR {
1236                         $$ = (void *)(unsigned long)BITW_OR;
1237                   }
1238                 | BITW_AND {
1239                         $$ = (void *)(unsigned long)BITW_AND;
1240                   }
1241                 | BITW_XOR {
1242                         $$ = (void *)(unsigned long)BITW_XOR;
1243                   }
1244                 | LEFTSHIFT {
1245                         $$ = (void *)(unsigned long)LEFTSHIFT;
1246                   }
1247                 | RIGHTSHIFT {
1248                         $$ = (void *)(unsigned long)RIGHTSHIFT;
1249                   }
1250                 ;
1251
1252 complex_imm_arg : complex_imm_const {
1253                         $$ = $1;
1254                   }
1255                 | complex_imm {
1256                         $$ = $1;
1257                   }
1258                 ;
1259
1260 complex_imm_const : hexnum_decnum {
1261                         $$ = $1;
1262                   }
1263                 | BITW_NOT hexnum_decnum {
1264                         unsigned long n = (unsigned long)$2;
1265                         n = ~n;
1266                         $$ = (void *)n;
1267                   }
1268                 ;
1269
1270 hexnum          : HEXNUM {
1271                         while (yytext[0] != 'x') {
1272                                 if (yytext[0] == '\0')
1273                                         yyerror("Internal HEXNUM parser error");
1274                                 yytext++;
1275                         }
1276                         yytext++;
1277                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1278                   }
1279                 ;
1280
1281 decnum          : DECNUM {
1282                         $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1283                   }
1284                 ;
1285
1286 hexnum_decnum   : hexnum {
1287                         $$ = $1;
1288                   }
1289                 | decnum {
1290                         $$ = $1;
1291                   }
1292                 ;
1293
1294 labelref        : identifier {
1295                         struct operand *oper = xmalloc(sizeof(struct operand));
1296                         struct label *label = xmalloc(sizeof(struct label));
1297                         label->name = $1;
1298                         label->direction = LABELREF_ABSOLUTE;
1299                         oper->type = OPER_LABEL;
1300                         oper->u.label = label;
1301                         $$ = oper;
1302                   }
1303                 | identifier MINUS {
1304                         struct operand *oper = xmalloc(sizeof(struct operand));
1305                         struct label *label = xmalloc(sizeof(struct label));
1306                         label->name = $1;
1307                         label->direction = LABELREF_RELATIVE_BACK;
1308                         oper->type = OPER_LABEL;
1309                         oper->u.label = label;
1310                         $$ = oper;
1311                   }
1312                 | identifier PLUS {
1313                         struct operand *oper = xmalloc(sizeof(struct operand));
1314                         struct label *label = xmalloc(sizeof(struct label));
1315                         label->name = $1;
1316                         label->direction = LABELREF_RELATIVE_FORWARD;
1317                         oper->type = OPER_LABEL;
1318                         oper->u.label = label;
1319                         $$ = oper;
1320                   }
1321                 ;
1322
1323 regnr           : DECNUM {
1324                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1325                   }
1326                 ;
1327
1328 identifier      : IDENT {
1329                         $$ = xstrdup(yytext);
1330                   }
1331                 ;
1332
1333 %%
1334
1335 int section = SECTION_TEXT; /* default to .text section */
1336 struct initvals_sect *cur_initvals_sect;
1337
1338 void yyerror(char *str)
1339 {
1340         unsigned int i;
1341
1342         fprintf(stderr,
1343                 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1344                 cur_lineinfo.file,
1345                 cur_lineinfo.lineno,
1346                 cur_lineinfo.column);
1347         fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1348         for (i = 0; i < cur_lineinfo.column - 1; i++)
1349                 fprintf(stderr, " ");
1350         fprintf(stderr, "^\n");
1351         fprintf(stderr, "%s\n", str);
1352         exit(1);
1353 }
1354
1355 static struct operand * store_oper_sanity(struct operand *oper)
1356 {
1357         if (oper->type == OPER_IMM &&
1358             oper->u.imm->imm != 0) {
1359                 yyerror("Only 0x000 Immediate is allowed for "
1360                         "Output operands");
1361         }
1362         return oper;
1363 }
1364
1365 static void assembler_assertion_failed(void)
1366 {
1367         yyerror("Assembler %assert failed");
1368 }