e75d9f4d371873ae1d0ab2e7d3f3c757e313ad5f
[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 assertion {
520                         unsigned int ok = (unsigned int)(unsigned long)$2;
521                         if (!ok)
522                                 assembler_assertion_failed();
523                         $$ = NULL;
524                   }
525                 ;
526
527 assertion       : PAREN_OPEN assert_expr PAREN_CLOSE {
528                         $$ = $2;
529                   }
530                 | PAREN_OPEN assertion LOGICAL_OR assertion PAREN_CLOSE {
531                         unsigned int a = (unsigned int)(unsigned long)$2;
532                         unsigned int b = (unsigned int)(unsigned long)$4;
533                         unsigned int result = (a || b);
534                         $$ = (void *)(unsigned long)result;
535                   }
536                 | PAREN_OPEN assertion LOGICAL_AND assertion PAREN_CLOSE {
537                         unsigned int a = (unsigned int)(unsigned long)$2;
538                         unsigned int b = (unsigned int)(unsigned long)$4;
539                         unsigned int result = (a && b);
540                         $$ = (void *)(unsigned long)result;
541                   }
542                 ;
543
544 assert_expr     : imm_value EQUAL imm_value {
545                         unsigned int a = (unsigned int)(unsigned long)$1;
546                         unsigned int b = (unsigned int)(unsigned long)$3;
547                         unsigned int result = (a == b);
548                         $$ = (void *)(unsigned long)result;
549                   }
550                 | imm_value NOT_EQUAL imm_value {
551                         unsigned int a = (unsigned int)(unsigned long)$1;
552                         unsigned int b = (unsigned int)(unsigned long)$3;
553                         unsigned int result = (a != b);
554                         $$ = (void *)(unsigned long)result;
555                   }
556                 ;
557
558 label           : LABEL {
559                         struct label *label = xmalloc(sizeof(struct label));
560                         char *l;
561                         l = xstrdup(yytext);
562                         l[strlen(l) - 1] = '\0';
563                         label->name = l;
564                         $$ = label;
565                   }
566                 ;
567
568 /* add */
569 insn_add        : OP_ADD operlist_3 {
570                         struct instruction *insn = xmalloc(sizeof(struct instruction));
571                         insn->op = OP_ADD;
572                         insn->operands = $2;
573                         $$ = insn;
574                   }
575                 ;
576
577 /* add. */
578 insn_addsc      : OP_ADDSC operlist_3 {
579                         struct instruction *insn = xmalloc(sizeof(struct instruction));
580                         insn->op = OP_ADDSC;
581                         insn->operands = $2;
582                         $$ = insn;
583                   }
584                 ;
585
586 /* addc */
587 insn_addc       : OP_ADDC operlist_3 {
588                         struct instruction *insn = xmalloc(sizeof(struct instruction));
589                         insn->op = OP_ADDC;
590                         insn->operands = $2;
591                         $$ = insn;
592                   }
593                 ;
594
595 /* addc. */
596 insn_addscc     : OP_ADDSCC operlist_3 {
597                         struct instruction *insn = xmalloc(sizeof(struct instruction));
598                         insn->op = OP_ADDSCC;
599                         insn->operands = $2;
600                         $$ = insn;
601                   }
602                 ;
603
604 /* sub */
605 insn_sub        : OP_SUB operlist_3 {
606                         struct instruction *insn = xmalloc(sizeof(struct instruction));
607                         insn->op = OP_SUB;
608                         insn->operands = $2;
609                         $$ = insn;
610                   }
611                 ;
612
613 /* sub. */
614 insn_subsc      : OP_SUBSC operlist_3 {
615                         struct instruction *insn = xmalloc(sizeof(struct instruction));
616                         insn->op = OP_SUBSC;
617                         insn->operands = $2;
618                         $$ = insn;
619                   }
620                 ;
621
622 /* subc */
623 insn_subc       : OP_SUBC operlist_3 {
624                         struct instruction *insn = xmalloc(sizeof(struct instruction));
625                         insn->op = OP_SUBC;
626                         insn->operands = $2;
627                         $$ = insn;
628                   }
629                 ;
630
631 /* subc. */
632 insn_subscc     : OP_SUBSCC operlist_3 {
633                         struct instruction *insn = xmalloc(sizeof(struct instruction));
634                         insn->op = OP_SUBSCC;
635                         insn->operands = $2;
636                         $$ = insn;
637                   }
638                 ;
639
640 insn_sra        : OP_SRA operlist_3 {
641                         struct instruction *insn = xmalloc(sizeof(struct instruction));
642                         insn->op = OP_SRA;
643                         insn->operands = $2;
644                         $$ = insn;
645                   }
646                 ;
647
648 insn_or         : OP_OR operlist_3 {
649                         struct instruction *insn = xmalloc(sizeof(struct instruction));
650                         insn->op = OP_OR;
651                         insn->operands = $2;
652                         $$ = insn;
653                   }
654                 ;
655
656 insn_and        : OP_AND operlist_3 {
657                         struct instruction *insn = xmalloc(sizeof(struct instruction));
658                         insn->op = OP_AND;
659                         insn->operands = $2;
660                         $$ = insn;
661                   }
662                 ;
663
664 insn_xor        : OP_XOR operlist_3 {
665                         struct instruction *insn = xmalloc(sizeof(struct instruction));
666                         insn->op = OP_XOR;
667                         insn->operands = $2;
668                         $$ = insn;
669                   }
670                 ;
671
672 insn_sr         : OP_SR operlist_3 {
673                         struct instruction *insn = xmalloc(sizeof(struct instruction));
674                         insn->op = OP_SR;
675                         insn->operands = $2;
676                         $$ = insn;
677                   }
678                 ;
679
680 insn_srx        : OP_SRX extended_operlist {
681                         struct instruction *insn = xmalloc(sizeof(struct instruction));
682                         insn->op = OP_SRX;
683                         insn->operands = $2;
684                         $$ = insn;
685                   }
686                 ;
687
688 insn_sl         : OP_SL operlist_3 {
689                         struct instruction *insn = xmalloc(sizeof(struct instruction));
690                         insn->op = OP_SL;
691                         insn->operands = $2;
692                         $$ = insn;
693                   }
694                 ;
695
696 insn_rl         : OP_RL operlist_3 {
697                         struct instruction *insn = xmalloc(sizeof(struct instruction));
698                         insn->op = OP_RL;
699                         insn->operands = $2;
700                         $$ = insn;
701                   }
702                 ;
703
704 insn_rr         : OP_RR operlist_3 {
705                         struct instruction *insn = xmalloc(sizeof(struct instruction));
706                         insn->op = OP_RR;
707                         insn->operands = $2;
708                         $$ = insn;
709                   }
710                 ;
711
712 insn_nand       : OP_NAND operlist_3 {
713                         struct instruction *insn = xmalloc(sizeof(struct instruction));
714                         insn->op = OP_NAND;
715                         insn->operands = $2;
716                         $$ = insn;
717                   }
718                 ;
719
720 insn_orx        : OP_ORX extended_operlist {
721                         struct instruction *insn = xmalloc(sizeof(struct instruction));
722                         insn->op = OP_ORX;
723                         insn->operands = $2;
724                         $$ = insn;
725                   }
726                 ;
727
728 insn_mov        : OP_MOV operlist_2 {
729                         struct instruction *insn = xmalloc(sizeof(struct instruction));
730                         insn->op = OP_MOV;
731                         insn->operands = $2;
732                         $$ = insn;
733                   }
734                 ;
735
736 insn_jmp        : OP_JMP labelref {
737                         struct instruction *insn = xmalloc(sizeof(struct instruction));
738                         struct operlist *ol = xmalloc(sizeof(struct operlist));
739                         ol->oper[0] = $2;
740                         insn->op = OP_JMP;
741                         insn->operands = ol;
742                         $$ = insn;
743                   }
744                 ;
745
746 insn_jand       : OP_JAND operlist_3 {
747                         struct instruction *insn = xmalloc(sizeof(struct instruction));
748                         insn->op = OP_JAND;
749                         insn->operands = $2;
750                         $$ = insn;
751                   }
752                 ;
753
754 insn_jnand      : OP_JNAND operlist_3 {
755                         struct instruction *insn = xmalloc(sizeof(struct instruction));
756                         insn->op = OP_JNAND;
757                         insn->operands = $2;
758                         $$ = insn;
759                   }
760                 ;
761
762 insn_js         : OP_JS operlist_3 {
763                         struct instruction *insn = xmalloc(sizeof(struct instruction));
764                         insn->op = OP_JS;
765                         insn->operands = $2;
766                         $$ = insn;
767                   }
768                 ;
769
770 insn_jns        : OP_JNS operlist_3 {
771                         struct instruction *insn = xmalloc(sizeof(struct instruction));
772                         insn->op = OP_JNS;
773                         insn->operands = $2;
774                         $$ = insn;
775                   }
776                 ;
777
778 insn_je         : OP_JE operlist_3 {
779                         struct instruction *insn = xmalloc(sizeof(struct instruction));
780                         insn->op = OP_JE;
781                         insn->operands = $2;
782                         $$ = insn;
783                   }
784                 ;
785
786 insn_jne        : OP_JNE operlist_3 {
787                         struct instruction *insn = xmalloc(sizeof(struct instruction));
788                         insn->op = OP_JNE;
789                         insn->operands = $2;
790                         $$ = insn;
791                   }
792                 ;
793
794 insn_jls        : OP_JLS operlist_3 {
795                         struct instruction *insn = xmalloc(sizeof(struct instruction));
796                         insn->op = OP_JLS;
797                         insn->operands = $2;
798                         $$ = insn;
799                   }
800                 ;
801
802 insn_jges       : OP_JGES operlist_3 {
803                         struct instruction *insn = xmalloc(sizeof(struct instruction));
804                         insn->op = OP_JGES;
805                         insn->operands = $2;
806                         $$ = insn;
807                   }
808                 ;
809
810 insn_jgs        : OP_JGS operlist_3 {
811                         struct instruction *insn = xmalloc(sizeof(struct instruction));
812                         insn->op = OP_JGS;
813                         insn->operands = $2;
814                         $$ = insn;
815                   }
816                 ;
817
818 insn_jles       : OP_JLES operlist_3 {
819                         struct instruction *insn = xmalloc(sizeof(struct instruction));
820                         insn->op = OP_JLES;
821                         insn->operands = $2;
822                         $$ = insn;
823                   }
824                 ;
825
826 insn_jl         : OP_JL operlist_3 {
827                         struct instruction *insn = xmalloc(sizeof(struct instruction));
828                         insn->op = OP_JL;
829                         insn->operands = $2;
830                         $$ = insn;
831                   }
832                 ;
833
834 insn_jge        : OP_JGE operlist_3 {
835                         struct instruction *insn = xmalloc(sizeof(struct instruction));
836                         insn->op = OP_JGE;
837                         insn->operands = $2;
838                         $$ = insn;
839                   }
840                 ;
841
842 insn_jg         : OP_JG operlist_3 {
843                         struct instruction *insn = xmalloc(sizeof(struct instruction));
844                         insn->op = OP_JG;
845                         insn->operands = $2;
846                         $$ = insn;
847                   }
848                 ;
849
850 insn_jle        : OP_JLE operlist_3 {
851                         struct instruction *insn = xmalloc(sizeof(struct instruction));
852                         insn->op = OP_JLE;
853                         insn->operands = $2;
854                         $$ = insn;
855                   }
856                 ;
857
858 insn_jzx        : OP_JZX extended_operlist {
859                         struct instruction *insn = xmalloc(sizeof(struct instruction));
860                         insn->op = OP_JZX;
861                         insn->operands = $2;
862                         $$ = insn;
863                   }
864                 ;
865
866 insn_jnzx       : OP_JNZX extended_operlist {
867                         struct instruction *insn = xmalloc(sizeof(struct instruction));
868                         insn->op = OP_JNZX;
869                         insn->operands = $2;
870                         $$ = insn;
871                   }
872                 ;
873
874 insn_jext       : OP_JEXT external_jump_operands {
875                         struct instruction *insn = xmalloc(sizeof(struct instruction));
876                         insn->op = OP_JEXT;
877                         insn->operands = $2;
878                         $$ = insn;
879                   }
880                 ;
881
882 insn_jnext      : OP_JNEXT external_jump_operands {
883                         struct instruction *insn = xmalloc(sizeof(struct instruction));
884                         insn->op = OP_JNEXT;
885                         insn->operands = $2;
886                         $$ = insn;
887                   }
888                 ;
889
890 linkreg         : LR regnr {
891                         $$ = $2;
892                   }
893                 ;
894
895 insn_call       : OP_CALL linkreg COMMA labelref {
896                         struct instruction *insn = xmalloc(sizeof(struct instruction));
897                         struct operlist *ol = xmalloc(sizeof(struct operlist));
898                         struct operand *oper_lr = xmalloc(sizeof(struct operand));
899                         struct operand *oper_zero = xmalloc(sizeof(struct operand));
900                         oper_zero->type = OPER_RAW;
901                         oper_zero->u.raw = 0;
902                         oper_lr->type = OPER_RAW;
903                         oper_lr->u.raw = (unsigned long)$2;
904                         ol->oper[0] = oper_lr;
905                         ol->oper[1] = oper_zero;
906                         ol->oper[2] = $4;
907                         insn->op = OP_CALL;
908                         insn->operands = ol;
909                         $$ = insn;
910                   }
911                 ;
912
913 insn_ret        : OP_RET linkreg COMMA linkreg {
914                         struct instruction *insn = xmalloc(sizeof(struct instruction));
915                         struct operlist *ol = xmalloc(sizeof(struct operlist));
916                         struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
917                         struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
918                         struct operand *oper_zero = xmalloc(sizeof(struct operand));
919                         oper_zero->type = OPER_RAW;
920                         oper_zero->u.raw = 0;
921                         oper_lr0->type = OPER_RAW;
922                         oper_lr0->u.raw = (unsigned long)$2;
923                         oper_lr1->type = OPER_RAW;
924                         oper_lr1->u.raw = (unsigned long)$4;
925                         ol->oper[0] = oper_lr0;
926                         ol->oper[1] = oper_zero;
927                         ol->oper[2] = oper_lr1;
928                         insn->op = OP_RET;
929                         insn->operands = ol;
930                         $$ = insn;
931                   }
932                 ;
933
934 insn_tkiph      : OP_TKIPH operlist_2 {
935                         struct instruction *insn = xmalloc(sizeof(struct instruction));
936                         struct operlist *ol = $2;
937                         struct operand *flags = xmalloc(sizeof(struct operand));
938                         struct immediate *imm = xmalloc(sizeof(struct immediate));
939                         imm->imm = 0x1;
940                         flags->type = OPER_IMM;
941                         flags->u.imm = imm;
942                         ol->oper[2] = ol->oper[1];
943                         ol->oper[1] = flags;
944                         insn->op = OP_TKIPH;
945                         insn->operands = ol;
946                         $$ = insn;
947                   }
948                 ;
949
950 insn_tkiphs     : OP_TKIPHS operlist_2 {
951                         struct instruction *insn = xmalloc(sizeof(struct instruction));
952                         struct operlist *ol = $2;
953                         struct operand *flags = xmalloc(sizeof(struct operand));
954                         struct immediate *imm = xmalloc(sizeof(struct immediate));
955                         imm->imm = 0x1 | 0x2;
956                         flags->type = OPER_IMM;
957                         flags->u.imm = imm;
958                         ol->oper[2] = ol->oper[1];
959                         ol->oper[1] = flags;
960                         insn->op = OP_TKIPH;
961                         insn->operands = ol;
962                         $$ = insn;
963                   }
964                 ;
965
966 insn_tkipl      : OP_TKIPL operlist_2 {
967                         struct instruction *insn = xmalloc(sizeof(struct instruction));
968                         struct operlist *ol = $2;
969                         struct operand *flags = xmalloc(sizeof(struct operand));
970                         struct immediate *imm = xmalloc(sizeof(struct immediate));
971                         imm->imm = 0x0;
972                         flags->type = OPER_IMM;
973                         flags->u.imm = imm;
974                         ol->oper[2] = ol->oper[1];
975                         ol->oper[1] = flags;
976                         insn->op = OP_TKIPH;
977                         insn->operands = ol;
978                         $$ = insn;
979                   }
980                 ;
981
982 insn_tkipls     : OP_TKIPLS operlist_2 {
983                         struct instruction *insn = xmalloc(sizeof(struct instruction));
984                         struct operlist *ol = $2;
985                         struct operand *flags = xmalloc(sizeof(struct operand));
986                         struct immediate *imm = xmalloc(sizeof(struct immediate));
987                         imm->imm = 0x0 | 0x2;
988                         flags->type = OPER_IMM;
989                         flags->u.imm = imm;
990                         ol->oper[2] = ol->oper[1];
991                         ol->oper[1] = flags;
992                         insn->op = OP_TKIPH;
993                         insn->operands = ol;
994                         $$ = insn;
995                   }
996                 ;
997
998 insn_nap        : OP_NAP {
999                         struct instruction *insn = xmalloc(sizeof(struct instruction));
1000                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1001                         struct operand *regop = xmalloc(sizeof(struct operand));
1002                         struct operand *zeroop = xmalloc(sizeof(struct operand));
1003                         struct registr *r0 = xmalloc(sizeof(struct registr));
1004                         r0->type = GPR;
1005                         r0->nr = 0;
1006                         regop->type = OPER_REG;
1007                         regop->u.reg = r0;
1008                         zeroop->type = OPER_RAW;
1009                         zeroop->u.raw = 0x000;
1010                         ol->oper[0] = regop;
1011                         ol->oper[1] = regop;
1012                         ol->oper[2] = zeroop;
1013                         insn->op = OP_NAP;
1014                         insn->operands = ol;
1015                         $$ = insn;
1016                   }
1017                 ;
1018
1019 insn_raw        : raw_code operlist_3 {
1020                         struct instruction *insn = xmalloc(sizeof(struct instruction));
1021                         insn->op = RAW_CODE;
1022                         insn->operands = $2;
1023                         insn->opcode = (unsigned long)$1;
1024                         $$ = insn;
1025                   }
1026                 ;
1027
1028 raw_code        : RAW_CODE {
1029                         yytext++; /* skip @ */
1030                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1031                   }
1032                 ;
1033
1034 extended_operlist : imm_value COMMA imm_value COMMA operand COMMA operand COMMA operand {
1035                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1036                         struct operand *mask_oper = xmalloc(sizeof(struct operand));
1037                         struct operand *shift_oper = xmalloc(sizeof(struct operand));
1038                         mask_oper->type = OPER_RAW;
1039                         mask_oper->u.raw = (unsigned long)$1;
1040                         shift_oper->type = OPER_RAW;
1041                         shift_oper->u.raw = (unsigned long)$3;
1042                         ol->oper[0] = mask_oper;
1043                         ol->oper[1] = shift_oper;
1044                         ol->oper[2] = $5;
1045                         ol->oper[3] = $7;
1046                         ol->oper[4] = store_oper_sanity($9);
1047                         $$ = ol;
1048                   }
1049                 ;
1050
1051 external_jump_operands : imm COMMA labelref {
1052                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1053                         struct operand *cond = xmalloc(sizeof(struct operand));
1054                         cond->type = OPER_IMM;
1055                         cond->u.imm = $1;
1056                         ol->oper[0] = cond;
1057                         ol->oper[1] = $3;
1058                         $$ = ol;
1059                   }
1060                 ;
1061
1062 operlist_2      : operand COMMA operand {
1063                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1064                         ol->oper[0] = $1;
1065                         ol->oper[1] = store_oper_sanity($3);
1066                         $$ = ol;
1067                   }
1068                 ;
1069
1070 operlist_3      : operand COMMA operand COMMA operand {
1071                         struct operlist *ol = xmalloc(sizeof(struct operlist));
1072                         ol->oper[0] = $1;
1073                         ol->oper[1] = $3;
1074                         ol->oper[2] = store_oper_sanity($5);
1075                         $$ = ol;
1076                   }
1077                 ;
1078
1079 operand         : reg {
1080                         struct operand *oper = xmalloc(sizeof(struct operand));
1081                         oper->type = OPER_REG;
1082                         oper->u.reg = $1;
1083                         $$ = oper;
1084                   }
1085                 | mem {
1086                         struct operand *oper = xmalloc(sizeof(struct operand));
1087                         oper->type = OPER_MEM;
1088                         oper->u.mem = $1;
1089                         $$ = oper;
1090                   }
1091                 | raw_code {
1092                         struct operand *oper = xmalloc(sizeof(struct operand));
1093                         oper->type = OPER_RAW;
1094                         oper->u.raw = (unsigned long)$1;
1095                         $$ = oper;
1096                   }
1097                 | imm {
1098                         struct operand *oper = xmalloc(sizeof(struct operand));
1099                         oper->type = OPER_IMM;
1100                         oper->u.imm = $1;
1101                         $$ = oper;
1102                   }
1103                 | labelref {
1104                         $$ = $1;
1105                   }
1106                 ;
1107
1108 reg             : GPR regnr {
1109                         struct registr *reg = xmalloc(sizeof(struct registr));
1110                         reg->type = GPR;
1111                         reg->nr = (unsigned long)$2;
1112                         $$ = reg;
1113                   }
1114                 | SPR {
1115                         struct registr *reg = xmalloc(sizeof(struct registr));
1116                         reg->type = SPR;
1117                         yytext += 3; /* skip "spr" */
1118                         reg->nr = strtoul(yytext, NULL, 16);
1119                         $$ = reg;
1120                   }
1121                 | OFFR regnr {
1122                         struct registr *reg = xmalloc(sizeof(struct registr));
1123                         reg->type = OFFR;
1124                         reg->nr = (unsigned long)$2;
1125                         $$ = reg;
1126                   }
1127                 ;
1128
1129 mem             : BRACK_OPEN imm BRACK_CLOSE {
1130                         struct memory *mem = xmalloc(sizeof(struct memory));
1131                         struct immediate *offset_imm = $2;
1132                         mem->type = MEM_DIRECT;
1133                         mem->offset = offset_imm->imm;
1134                         free(offset_imm);
1135                         $$ = mem;
1136                   }
1137                 | BRACK_OPEN imm COMMA OFFR regnr BRACK_CLOSE {
1138                         struct memory *mem = xmalloc(sizeof(struct memory));
1139                         struct immediate *offset_imm = $2;
1140                         mem->type = MEM_INDIRECT;
1141                         mem->offset = offset_imm->imm;
1142                         free(offset_imm);
1143                         mem->offr_nr = (unsigned long)$5;
1144                         $$ = mem;
1145                   }
1146                 ;
1147
1148 imm             : imm_value {
1149                         struct immediate *imm = xmalloc(sizeof(struct immediate));
1150                         imm->imm = (unsigned long)$1;
1151                         $$ = imm;
1152                   }
1153                 ;
1154
1155 imm_value       : hexnum_decnum {
1156                         $$ = $1;
1157                   }
1158                 | complex_imm {
1159                         $$ = $1;
1160                   }
1161                 ;
1162
1163 complex_imm     : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1164                         unsigned long a = (unsigned long)$2;
1165                         unsigned long b = (unsigned long)$4;
1166                         unsigned long operation = (unsigned long)$3;
1167                         unsigned long res = 31337;
1168                         switch (operation) {
1169                         case PLUS:
1170                                 res = a + b;
1171                                 break;
1172                         case MINUS:
1173                                 res = a - b;
1174                                 break;
1175                         case MULTIPLY:
1176                                 res = a * b;
1177                                 break;
1178                         case DIVIDE:
1179                                 res = a / b;
1180                                 break;
1181                         case BITW_OR:
1182                                 res = a | b;
1183                                 break;
1184                         case BITW_AND:
1185                                 res = a & b;
1186                                 break;
1187                         case BITW_XOR:
1188                                 res = a ^ b;
1189                                 break;
1190                         case LEFTSHIFT:
1191                                 res = a << b;
1192                                 break;
1193                         case RIGHTSHIFT:
1194                                 res = a >> b;
1195                                 break;
1196                         default:
1197                                 yyerror("Internal parser BUG. complex_imm oper unknown");
1198                         }
1199                         $$ = (void *)res;
1200                   }
1201                 | PAREN_OPEN complex_imm PAREN_CLOSE {
1202                         $$ = $2;
1203                   }
1204                 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1205                         unsigned long n = (unsigned long)$3;
1206                         n = ~n;
1207                         $$ = (void *)n;
1208                   }
1209                 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1210                         $$ = $2;
1211                   }
1212                 ;
1213
1214 complex_imm_oper : PLUS {
1215                         $$ = (void *)(unsigned long)PLUS;
1216                   }
1217                 | MINUS {
1218                         $$ = (void *)(unsigned long)MINUS;
1219                   }
1220                 | MULTIPLY {
1221                         $$ = (void *)(unsigned long)MULTIPLY;
1222                   }
1223                 | DIVIDE {
1224                         $$ = (void *)(unsigned long)DIVIDE;
1225                   }
1226                 | BITW_OR {
1227                         $$ = (void *)(unsigned long)BITW_OR;
1228                   }
1229                 | BITW_AND {
1230                         $$ = (void *)(unsigned long)BITW_AND;
1231                   }
1232                 | BITW_XOR {
1233                         $$ = (void *)(unsigned long)BITW_XOR;
1234                   }
1235                 | LEFTSHIFT {
1236                         $$ = (void *)(unsigned long)LEFTSHIFT;
1237                   }
1238                 | RIGHTSHIFT {
1239                         $$ = (void *)(unsigned long)RIGHTSHIFT;
1240                   }
1241                 ;
1242
1243 complex_imm_arg : complex_imm_const {
1244                         $$ = $1;
1245                   }
1246                 | complex_imm {
1247                         $$ = $1;
1248                   }
1249                 ;
1250
1251 complex_imm_const : hexnum_decnum {
1252                         $$ = $1;
1253                   }
1254                 | BITW_NOT hexnum_decnum {
1255                         unsigned long n = (unsigned long)$2;
1256                         n = ~n;
1257                         $$ = (void *)n;
1258                   }
1259                 ;
1260
1261 hexnum          : HEXNUM {
1262                         while (yytext[0] != 'x') {
1263                                 if (yytext[0] == '\0')
1264                                         yyerror("Internal HEXNUM parser error");
1265                                 yytext++;
1266                         }
1267                         yytext++;
1268                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1269                   }
1270                 ;
1271
1272 decnum          : DECNUM {
1273                         $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1274                   }
1275                 ;
1276
1277 hexnum_decnum   : hexnum {
1278                         $$ = $1;
1279                   }
1280                 | decnum {
1281                         $$ = $1;
1282                   }
1283                 ;
1284
1285 labelref        : identifier {
1286                         struct operand *oper = xmalloc(sizeof(struct operand));
1287                         struct label *label = xmalloc(sizeof(struct label));
1288                         label->name = $1;
1289                         label->direction = LABELREF_ABSOLUTE;
1290                         oper->type = OPER_LABEL;
1291                         oper->u.label = label;
1292                         $$ = oper;
1293                   }
1294                 | identifier MINUS {
1295                         struct operand *oper = xmalloc(sizeof(struct operand));
1296                         struct label *label = xmalloc(sizeof(struct label));
1297                         label->name = $1;
1298                         label->direction = LABELREF_RELATIVE_BACK;
1299                         oper->type = OPER_LABEL;
1300                         oper->u.label = label;
1301                         $$ = oper;
1302                   }
1303                 | identifier PLUS {
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_FORWARD;
1308                         oper->type = OPER_LABEL;
1309                         oper->u.label = label;
1310                         $$ = oper;
1311                   }
1312                 ;
1313
1314 regnr           : DECNUM {
1315                         $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1316                   }
1317                 ;
1318
1319 identifier      : IDENT {
1320                         $$ = xstrdup(yytext);
1321                   }
1322                 ;
1323
1324 %%
1325
1326 int section = SECTION_TEXT; /* default to .text section */
1327 struct initvals_sect *cur_initvals_sect;
1328
1329 void yyerror(char *str)
1330 {
1331         unsigned int i;
1332
1333         fprintf(stderr,
1334                 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1335                 cur_lineinfo.file,
1336                 cur_lineinfo.lineno,
1337                 cur_lineinfo.column);
1338         fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1339         for (i = 0; i < cur_lineinfo.column - 1; i++)
1340                 fprintf(stderr, " ");
1341         fprintf(stderr, "^\n");
1342         fprintf(stderr, "%s\n", str);
1343         exit(1);
1344 }
1345
1346 static struct operand * store_oper_sanity(struct operand *oper)
1347 {
1348         if (oper->type == OPER_IMM &&
1349             oper->u.imm->imm != 0) {
1350                 yyerror("Only 0x000 Immediate is allowed for "
1351                         "Output operands");
1352         }
1353         return oper;
1354 }
1355
1356 static void assembler_assertion_failed(void)
1357 {
1358         yyerror("Assembler %assert failed");
1359 }