4 * Copyright (C) 2006-2007 Michael Buesch <mb@bu3sch.de>
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.
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.
26 extern void yyerror(char *);
27 extern int yyparse(void);
28 extern int yylex(void);
30 static struct operand * store_oper_sanity(struct operand *oper);
32 /* The current .section */
34 /* Pointer to the current initvals section data structure. */
35 extern struct initvals_sect *cur_initvals_sect;
39 %token SECTION_TEXT SECTION_IVALS
41 %token ASM_ARCH ASM_START SPR GPR OFFR LR COMMA BRACK_OPEN BRACK_CLOSE PAREN_OPEN PAREN_CLOSE HEXNUM DECNUM ARCH_NEWWORLD ARCH_OLDWORLD LABEL IDENT LABELREF
43 %token PLUS MINUS MULTIPLY DIVIDE BITW_OR BITW_AND BITW_XOR BITW_NOT LEFTSHIFT RIGHTSHIFT
45 %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 %token IVAL_MMIO16 IVAL_MMIO32 IVAL_PHY IVAL_RADIO IVAL_SHM16 IVAL_SHM32
55 struct statement *s = $2;
56 if (section != SECTION_TEXT)
57 yyerror("Microcode text instruction in non .text section");
58 memcpy(&s->info, &cur_lineinfo, sizeof(struct lineinfo));
59 list_add_tail(&s->list, &infile.sl);
61 | line section_switch {
64 struct initval_op *io = $2;
65 if (section != SECTION_IVALS)
66 yyerror("InitVals write in non .initvals section");
67 memcpy(&io->info, &cur_lineinfo, sizeof(struct lineinfo));
68 INIT_LIST_HEAD(&io->list);
69 list_add_tail(&io->list, &cur_initvals_sect->ops);
73 section_switch : SECTION_TEXT {
74 section = SECTION_TEXT;
76 | SECTION_IVALS PAREN_OPEN identifier PAREN_CLOSE {
77 const char *sectname = $3;
78 struct initvals_sect *s;
79 cur_initvals_sect = NULL;
80 /* Search if there already is a section by that name. */
81 list_for_each_entry(s, &infile.ivals, list) {
82 if (strcmp(sectname, s->name) == 0)
83 cur_initvals_sect = s;
85 if (!cur_initvals_sect) {
86 /* Not found, create a new one. */
87 s = xmalloc(sizeof(struct initvals_sect));
89 INIT_LIST_HEAD(&s->ops);
90 INIT_LIST_HEAD(&s->list);
91 list_add_tail(&s->list, &infile.ivals);
92 cur_initvals_sect = s;
94 section = SECTION_IVALS;
98 ivals_write : IVAL_MMIO16 hexnum_decnum COMMA hexnum_decnum {
99 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
100 iop->type = IVAL_W_MMIO16;
101 iop->args[0] = (unsigned int)(unsigned long)$2;
102 iop->args[1] = (unsigned int)(unsigned long)$4;
105 | IVAL_MMIO32 hexnum_decnum COMMA hexnum_decnum {
106 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
107 iop->type = IVAL_W_MMIO32;
108 iop->args[0] = (unsigned int)(unsigned long)$2;
109 iop->args[1] = (unsigned int)(unsigned long)$4;
112 | IVAL_PHY hexnum_decnum COMMA hexnum_decnum {
113 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
114 iop->type = IVAL_W_PHY;
115 iop->args[0] = (unsigned int)(unsigned long)$2;
116 iop->args[1] = (unsigned int)(unsigned long)$4;
119 | IVAL_RADIO hexnum_decnum COMMA hexnum_decnum {
120 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
121 iop->type = IVAL_W_RADIO;
122 iop->args[0] = (unsigned int)(unsigned long)$2;
123 iop->args[1] = (unsigned int)(unsigned long)$4;
126 | IVAL_SHM16 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum {
127 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
128 iop->type = IVAL_W_SHM16;
129 iop->args[0] = (unsigned int)(unsigned long)$2;
130 iop->args[1] = (unsigned int)(unsigned long)$4;
131 iop->args[2] = (unsigned int)(unsigned long)$6;
134 | IVAL_SHM32 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum {
135 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
136 iop->type = IVAL_W_SHM32;
137 iop->args[0] = (unsigned int)(unsigned long)$2;
138 iop->args[1] = (unsigned int)(unsigned long)$4;
139 iop->args[2] = (unsigned int)(unsigned long)$6;
145 struct statement *s = xmalloc(sizeof(struct statement));
146 INIT_LIST_HEAD(&s->list);
147 s->type = STMT_ASMDIR;
152 struct statement *s = xmalloc(sizeof(struct statement));
153 INIT_LIST_HEAD(&s->list);
154 s->type = STMT_LABEL;
159 struct statement *s = xmalloc(sizeof(struct statement));
160 INIT_LIST_HEAD(&s->list);
166 struct statement *s = xmalloc(sizeof(struct statement));
167 INIT_LIST_HEAD(&s->list);
173 struct statement *s = xmalloc(sizeof(struct statement));
174 INIT_LIST_HEAD(&s->list);
180 struct statement *s = xmalloc(sizeof(struct statement));
181 INIT_LIST_HEAD(&s->list);
187 struct statement *s = xmalloc(sizeof(struct statement));
188 INIT_LIST_HEAD(&s->list);
194 struct statement *s = xmalloc(sizeof(struct statement));
195 INIT_LIST_HEAD(&s->list);
201 struct statement *s = xmalloc(sizeof(struct statement));
202 INIT_LIST_HEAD(&s->list);
208 struct statement *s = xmalloc(sizeof(struct statement));
209 INIT_LIST_HEAD(&s->list);
215 struct statement *s = xmalloc(sizeof(struct statement));
216 INIT_LIST_HEAD(&s->list);
222 struct statement *s = xmalloc(sizeof(struct statement));
223 INIT_LIST_HEAD(&s->list);
229 struct statement *s = xmalloc(sizeof(struct statement));
230 INIT_LIST_HEAD(&s->list);
236 struct statement *s = xmalloc(sizeof(struct statement));
237 INIT_LIST_HEAD(&s->list);
243 struct statement *s = xmalloc(sizeof(struct statement));
244 INIT_LIST_HEAD(&s->list);
250 struct statement *s = xmalloc(sizeof(struct statement));
251 INIT_LIST_HEAD(&s->list);
257 struct statement *s = xmalloc(sizeof(struct statement));
258 INIT_LIST_HEAD(&s->list);
264 struct statement *s = xmalloc(sizeof(struct statement));
265 INIT_LIST_HEAD(&s->list);
271 struct statement *s = xmalloc(sizeof(struct statement));
272 INIT_LIST_HEAD(&s->list);
278 struct statement *s = xmalloc(sizeof(struct statement));
279 INIT_LIST_HEAD(&s->list);
285 struct statement *s = xmalloc(sizeof(struct statement));
286 INIT_LIST_HEAD(&s->list);
292 struct statement *s = xmalloc(sizeof(struct statement));
293 INIT_LIST_HEAD(&s->list);
299 struct statement *s = xmalloc(sizeof(struct statement));
300 INIT_LIST_HEAD(&s->list);
306 struct statement *s = xmalloc(sizeof(struct statement));
307 INIT_LIST_HEAD(&s->list);
313 struct statement *s = xmalloc(sizeof(struct statement));
314 INIT_LIST_HEAD(&s->list);
320 struct statement *s = xmalloc(sizeof(struct statement));
321 INIT_LIST_HEAD(&s->list);
327 struct statement *s = xmalloc(sizeof(struct statement));
328 INIT_LIST_HEAD(&s->list);
334 struct statement *s = xmalloc(sizeof(struct statement));
335 INIT_LIST_HEAD(&s->list);
341 struct statement *s = xmalloc(sizeof(struct statement));
342 INIT_LIST_HEAD(&s->list);
348 struct statement *s = xmalloc(sizeof(struct statement));
349 INIT_LIST_HEAD(&s->list);
355 struct statement *s = xmalloc(sizeof(struct statement));
356 INIT_LIST_HEAD(&s->list);
362 struct statement *s = xmalloc(sizeof(struct statement));
363 INIT_LIST_HEAD(&s->list);
369 struct statement *s = xmalloc(sizeof(struct statement));
370 INIT_LIST_HEAD(&s->list);
376 struct statement *s = xmalloc(sizeof(struct statement));
377 INIT_LIST_HEAD(&s->list);
383 struct statement *s = xmalloc(sizeof(struct statement));
384 INIT_LIST_HEAD(&s->list);
390 struct statement *s = xmalloc(sizeof(struct statement));
391 INIT_LIST_HEAD(&s->list);
397 struct statement *s = xmalloc(sizeof(struct statement));
398 INIT_LIST_HEAD(&s->list);
404 struct statement *s = xmalloc(sizeof(struct statement));
405 INIT_LIST_HEAD(&s->list);
411 struct statement *s = xmalloc(sizeof(struct statement));
412 INIT_LIST_HEAD(&s->list);
418 struct statement *s = xmalloc(sizeof(struct statement));
419 INIT_LIST_HEAD(&s->list);
425 struct statement *s = xmalloc(sizeof(struct statement));
426 INIT_LIST_HEAD(&s->list);
432 struct statement *s = xmalloc(sizeof(struct statement));
433 INIT_LIST_HEAD(&s->list);
439 struct statement *s = xmalloc(sizeof(struct statement));
440 INIT_LIST_HEAD(&s->list);
446 struct statement *s = xmalloc(sizeof(struct statement));
447 INIT_LIST_HEAD(&s->list);
453 struct statement *s = xmalloc(sizeof(struct statement));
454 INIT_LIST_HEAD(&s->list);
460 struct statement *s = xmalloc(sizeof(struct statement));
461 INIT_LIST_HEAD(&s->list);
467 struct statement *s = xmalloc(sizeof(struct statement));
468 INIT_LIST_HEAD(&s->list);
474 struct statement *s = xmalloc(sizeof(struct statement));
475 INIT_LIST_HEAD(&s->list);
481 struct statement *s = xmalloc(sizeof(struct statement));
482 INIT_LIST_HEAD(&s->list);
490 asmdir : ASM_ARCH hexnum_decnum {
491 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
492 ad->type = ADIR_ARCH;
493 ad->u.arch = (unsigned int)(unsigned long)$2;
496 | ASM_START identifier {
497 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
498 struct label *label = xmalloc(sizeof(struct label));
500 label->direction = LABELREF_ABSOLUTE;
501 ad->type = ADIR_START;
508 struct label *label = xmalloc(sizeof(struct label));
511 l[strlen(l) - 1] = '\0';
518 insn_add : OP_ADD operlist_3 {
519 struct instruction *insn = xmalloc(sizeof(struct instruction));
527 insn_addsc : OP_ADDSC operlist_3 {
528 struct instruction *insn = xmalloc(sizeof(struct instruction));
536 insn_addc : OP_ADDC operlist_3 {
537 struct instruction *insn = xmalloc(sizeof(struct instruction));
545 insn_addscc : OP_ADDSCC operlist_3 {
546 struct instruction *insn = xmalloc(sizeof(struct instruction));
547 insn->op = OP_ADDSCC;
554 insn_sub : OP_SUB operlist_3 {
555 struct instruction *insn = xmalloc(sizeof(struct instruction));
563 insn_subsc : OP_SUBSC operlist_3 {
564 struct instruction *insn = xmalloc(sizeof(struct instruction));
572 insn_subc : OP_SUBC operlist_3 {
573 struct instruction *insn = xmalloc(sizeof(struct instruction));
581 insn_subscc : OP_SUBSCC operlist_3 {
582 struct instruction *insn = xmalloc(sizeof(struct instruction));
583 insn->op = OP_SUBSCC;
589 insn_sra : OP_SRA operlist_3 {
590 struct instruction *insn = xmalloc(sizeof(struct instruction));
597 insn_or : OP_OR operlist_3 {
598 struct instruction *insn = xmalloc(sizeof(struct instruction));
605 insn_and : OP_AND operlist_3 {
606 struct instruction *insn = xmalloc(sizeof(struct instruction));
613 insn_xor : OP_XOR operlist_3 {
614 struct instruction *insn = xmalloc(sizeof(struct instruction));
621 insn_sr : OP_SR operlist_3 {
622 struct instruction *insn = xmalloc(sizeof(struct instruction));
629 insn_srx : OP_SRX extended_operlist {
630 struct instruction *insn = xmalloc(sizeof(struct instruction));
637 insn_sl : OP_SL operlist_3 {
638 struct instruction *insn = xmalloc(sizeof(struct instruction));
645 insn_rl : OP_RL operlist_3 {
646 struct instruction *insn = xmalloc(sizeof(struct instruction));
653 insn_rr : OP_RR operlist_3 {
654 struct instruction *insn = xmalloc(sizeof(struct instruction));
661 insn_nand : OP_NAND operlist_3 {
662 struct instruction *insn = xmalloc(sizeof(struct instruction));
669 insn_orx : OP_ORX extended_operlist {
670 struct instruction *insn = xmalloc(sizeof(struct instruction));
677 insn_mov : OP_MOV operlist_2 {
678 struct instruction *insn = xmalloc(sizeof(struct instruction));
685 insn_jmp : OP_JMP labelref {
686 struct instruction *insn = xmalloc(sizeof(struct instruction));
687 struct operlist *ol = xmalloc(sizeof(struct operlist));
695 insn_jand : OP_JAND operlist_3 {
696 struct instruction *insn = xmalloc(sizeof(struct instruction));
703 insn_jnand : OP_JNAND operlist_3 {
704 struct instruction *insn = xmalloc(sizeof(struct instruction));
711 insn_js : OP_JS operlist_3 {
712 struct instruction *insn = xmalloc(sizeof(struct instruction));
719 insn_jns : OP_JNS operlist_3 {
720 struct instruction *insn = xmalloc(sizeof(struct instruction));
727 insn_je : OP_JE operlist_3 {
728 struct instruction *insn = xmalloc(sizeof(struct instruction));
735 insn_jne : OP_JNE operlist_3 {
736 struct instruction *insn = xmalloc(sizeof(struct instruction));
743 insn_jls : OP_JLS operlist_3 {
744 struct instruction *insn = xmalloc(sizeof(struct instruction));
751 insn_jges : OP_JGES operlist_3 {
752 struct instruction *insn = xmalloc(sizeof(struct instruction));
759 insn_jgs : OP_JGS operlist_3 {
760 struct instruction *insn = xmalloc(sizeof(struct instruction));
767 insn_jles : OP_JLES operlist_3 {
768 struct instruction *insn = xmalloc(sizeof(struct instruction));
775 insn_jl : OP_JL operlist_3 {
776 struct instruction *insn = xmalloc(sizeof(struct instruction));
783 insn_jge : OP_JGE operlist_3 {
784 struct instruction *insn = xmalloc(sizeof(struct instruction));
791 insn_jg : OP_JG operlist_3 {
792 struct instruction *insn = xmalloc(sizeof(struct instruction));
799 insn_jle : OP_JLE operlist_3 {
800 struct instruction *insn = xmalloc(sizeof(struct instruction));
807 insn_jzx : OP_JZX extended_operlist {
808 struct instruction *insn = xmalloc(sizeof(struct instruction));
815 insn_jnzx : OP_JNZX extended_operlist {
816 struct instruction *insn = xmalloc(sizeof(struct instruction));
823 insn_jext : OP_JEXT external_jump_operands {
824 struct instruction *insn = xmalloc(sizeof(struct instruction));
831 insn_jnext : OP_JNEXT external_jump_operands {
832 struct instruction *insn = xmalloc(sizeof(struct instruction));
844 insn_call : OP_CALL linkreg COMMA labelref {
845 struct instruction *insn = xmalloc(sizeof(struct instruction));
846 struct operlist *ol = xmalloc(sizeof(struct operlist));
847 struct operand *oper_lr = xmalloc(sizeof(struct operand));
848 struct operand *oper_zero = xmalloc(sizeof(struct operand));
849 oper_zero->type = OPER_RAW;
850 oper_zero->u.raw = 0;
851 oper_lr->type = OPER_RAW;
852 oper_lr->u.raw = (unsigned long)$2;
853 ol->oper[0] = oper_lr;
854 ol->oper[1] = oper_zero;
862 insn_ret : OP_RET linkreg COMMA linkreg {
863 struct instruction *insn = xmalloc(sizeof(struct instruction));
864 struct operlist *ol = xmalloc(sizeof(struct operlist));
865 struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
866 struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
867 struct operand *oper_zero = xmalloc(sizeof(struct operand));
868 oper_zero->type = OPER_RAW;
869 oper_zero->u.raw = 0;
870 oper_lr0->type = OPER_RAW;
871 oper_lr0->u.raw = (unsigned long)$2;
872 oper_lr1->type = OPER_RAW;
873 oper_lr1->u.raw = (unsigned long)$4;
874 ol->oper[0] = oper_lr0;
875 ol->oper[1] = oper_zero;
876 ol->oper[2] = oper_lr1;
883 insn_tkiph : OP_TKIPH operlist_2 {
884 struct instruction *insn = xmalloc(sizeof(struct instruction));
885 struct operlist *ol = $2;
886 struct operand *flags = xmalloc(sizeof(struct operand));
887 struct immediate *imm = xmalloc(sizeof(struct immediate));
889 flags->type = OPER_IMM;
891 ol->oper[2] = ol->oper[1];
899 insn_tkiphs : OP_TKIPHS operlist_2 {
900 struct instruction *insn = xmalloc(sizeof(struct instruction));
901 struct operlist *ol = $2;
902 struct operand *flags = xmalloc(sizeof(struct operand));
903 struct immediate *imm = xmalloc(sizeof(struct immediate));
904 imm->imm = 0x1 | 0x2;
905 flags->type = OPER_IMM;
907 ol->oper[2] = ol->oper[1];
915 insn_tkipl : OP_TKIPL operlist_2 {
916 struct instruction *insn = xmalloc(sizeof(struct instruction));
917 struct operlist *ol = $2;
918 struct operand *flags = xmalloc(sizeof(struct operand));
919 struct immediate *imm = xmalloc(sizeof(struct immediate));
921 flags->type = OPER_IMM;
923 ol->oper[2] = ol->oper[1];
931 insn_tkipls : OP_TKIPLS operlist_2 {
932 struct instruction *insn = xmalloc(sizeof(struct instruction));
933 struct operlist *ol = $2;
934 struct operand *flags = xmalloc(sizeof(struct operand));
935 struct immediate *imm = xmalloc(sizeof(struct immediate));
936 imm->imm = 0x0 | 0x2;
937 flags->type = OPER_IMM;
939 ol->oper[2] = ol->oper[1];
948 struct instruction *insn = xmalloc(sizeof(struct instruction));
949 struct operlist *ol = xmalloc(sizeof(struct operlist));
950 struct operand *regop = xmalloc(sizeof(struct operand));
951 struct operand *zeroop = xmalloc(sizeof(struct operand));
952 struct registr *r0 = xmalloc(sizeof(struct registr));
955 regop->type = OPER_REG;
957 zeroop->type = OPER_RAW;
958 zeroop->u.raw = 0x000;
961 ol->oper[2] = zeroop;
968 insn_raw : raw_code operlist_3 {
969 struct instruction *insn = xmalloc(sizeof(struct instruction));
972 insn->opcode = (unsigned long)$1;
977 raw_code : RAW_CODE {
978 yytext++; /* skip @ */
979 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
983 extended_operlist : decnum COMMA decnum COMMA operand COMMA operand COMMA operand {
984 struct operlist *ol = xmalloc(sizeof(struct operlist));
985 struct operand *mask_oper = xmalloc(sizeof(struct operand));
986 struct operand *shift_oper = xmalloc(sizeof(struct operand));
987 mask_oper->type = OPER_RAW;
988 mask_oper->u.raw = (unsigned long)$1;
989 shift_oper->type = OPER_RAW;
990 shift_oper->u.raw = (unsigned long)$3;
991 ol->oper[0] = mask_oper;
992 ol->oper[1] = shift_oper;
995 ol->oper[4] = store_oper_sanity($9);
1000 external_jump_operands : hexnum COMMA operand COMMA operand COMMA labelref {
1001 struct operlist *ol = xmalloc(sizeof(struct operlist));
1002 struct operand *cond = xmalloc(sizeof(struct operand));
1003 cond->type = OPER_RAW;
1004 cond->u.raw = (unsigned long)$1;
1013 operlist_2 : operand COMMA operand {
1014 struct operlist *ol = xmalloc(sizeof(struct operlist));
1016 ol->oper[1] = store_oper_sanity($3);
1021 operlist_3 : operand COMMA operand COMMA operand {
1022 struct operlist *ol = xmalloc(sizeof(struct operlist));
1025 ol->oper[2] = store_oper_sanity($5);
1031 struct operand *oper = xmalloc(sizeof(struct operand));
1032 oper->type = OPER_REG;
1037 struct operand *oper = xmalloc(sizeof(struct operand));
1038 oper->type = OPER_MEM;
1043 struct operand *oper = xmalloc(sizeof(struct operand));
1044 oper->type = OPER_RAW;
1045 oper->u.raw = (unsigned long)$1;
1049 struct operand *oper = xmalloc(sizeof(struct operand));
1050 oper->type = OPER_IMM;
1060 struct registr *reg = xmalloc(sizeof(struct registr));
1062 reg->nr = (unsigned long)$2;
1066 struct registr *reg = xmalloc(sizeof(struct registr));
1068 yytext += 3; /* skip "spr" */
1069 reg->nr = strtoul(yytext, NULL, 16);
1073 struct registr *reg = xmalloc(sizeof(struct registr));
1075 reg->nr = (unsigned long)$2;
1080 mem : BRACK_OPEN hexnum_decnum BRACK_CLOSE {
1081 struct memory *mem = xmalloc(sizeof(struct memory));
1082 mem->type = MEM_DIRECT;
1083 mem->offset = (unsigned long)$2;
1086 | BRACK_OPEN hexnum_decnum COMMA OFFR regnr BRACK_CLOSE {
1087 struct memory *mem = xmalloc(sizeof(struct memory));
1088 mem->type = MEM_INDIRECT;
1089 mem->offset = (unsigned long)$2;
1090 mem->offr_nr = (unsigned long)$5;
1096 struct immediate *imm = xmalloc(sizeof(struct immediate));
1097 imm->imm = (unsigned long)$1;
1101 struct immediate *imm = xmalloc(sizeof(struct immediate));
1102 imm->imm = (unsigned long)$1;
1106 struct immediate *imm = xmalloc(sizeof(struct immediate));
1107 imm->imm = (unsigned long)$1;
1112 complex_imm : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1113 unsigned long a = (unsigned long)$2;
1114 unsigned long b = (unsigned long)$4;
1115 unsigned long operation = (unsigned long)$3;
1116 unsigned long res = 31337;
1117 switch (operation) {
1146 yyerror("Internal parser BUG. complex_imm oper unknown");
1150 | PAREN_OPEN complex_imm PAREN_CLOSE {
1153 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1154 unsigned long n = (unsigned long)$3;
1158 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1163 complex_imm_oper : PLUS {
1164 $$ = (void *)(unsigned long)PLUS;
1167 $$ = (void *)(unsigned long)MINUS;
1170 $$ = (void *)(unsigned long)MULTIPLY;
1173 $$ = (void *)(unsigned long)DIVIDE;
1176 $$ = (void *)(unsigned long)BITW_OR;
1179 $$ = (void *)(unsigned long)BITW_AND;
1182 $$ = (void *)(unsigned long)BITW_XOR;
1185 $$ = (void *)(unsigned long)LEFTSHIFT;
1188 $$ = (void *)(unsigned long)RIGHTSHIFT;
1192 complex_imm_arg : complex_imm_const {
1200 complex_imm_const : hexnum_decnum {
1203 | BITW_NOT hexnum_decnum {
1204 unsigned long n = (unsigned long)$2;
1211 while (yytext[0] != 'x') {
1212 if (yytext[0] == '\0')
1213 yyerror("Internal HEXNUM parser error");
1217 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1222 $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1226 hexnum_decnum : hexnum {
1234 labelref : identifier {
1235 struct operand *oper = xmalloc(sizeof(struct operand));
1236 struct label *label = xmalloc(sizeof(struct label));
1238 label->direction = LABELREF_ABSOLUTE;
1239 oper->type = OPER_LABEL;
1240 oper->u.label = label;
1243 | identifier MINUS {
1244 struct operand *oper = xmalloc(sizeof(struct operand));
1245 struct label *label = xmalloc(sizeof(struct label));
1247 label->direction = LABELREF_RELATIVE_BACK;
1248 oper->type = OPER_LABEL;
1249 oper->u.label = label;
1253 struct operand *oper = xmalloc(sizeof(struct operand));
1254 struct label *label = xmalloc(sizeof(struct label));
1256 label->direction = LABELREF_RELATIVE_FORWARD;
1257 oper->type = OPER_LABEL;
1258 oper->u.label = label;
1264 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1268 identifier : IDENT {
1269 $$ = xstrdup(yytext);
1275 int section = SECTION_TEXT; /* default to .text section */
1276 struct initvals_sect *cur_initvals_sect;
1278 void yyerror(char *str)
1283 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1285 cur_lineinfo.lineno,
1286 cur_lineinfo.column);
1287 fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1288 for (i = 0; i < cur_lineinfo.column - 1; i++)
1289 fprintf(stderr, " ");
1290 fprintf(stderr, "^\n");
1291 fprintf(stderr, "%s\n", str);
1295 static struct operand * store_oper_sanity(struct operand *oper)
1297 if (oper->type == OPER_IMM &&
1298 oper->u.imm->imm != 0) {
1299 yyerror("Only 0x000 Immediate is allowed for "