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);
493 | ASM_START identifier {
494 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
495 struct label *label = xmalloc(sizeof(struct label));
497 label->direction = LABELREF_ABSOLUTE;
498 ad->type = ADIR_START;
504 asmarch : ASM_ARCH ARCH_NEWWORLD {
505 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
506 ad->type = ADIR_ARCH;
507 ad->u.arch = NEWWORLD;
510 | ASM_ARCH ARCH_OLDWORLD {
511 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
512 ad->type = ADIR_ARCH;
513 ad->u.arch = OLDWORLD;
519 struct label *label = xmalloc(sizeof(struct label));
522 l[strlen(l) - 1] = '\0';
529 insn_add : OP_ADD operlist_3 {
530 struct instruction *insn = xmalloc(sizeof(struct instruction));
538 insn_addsc : OP_ADDSC operlist_3 {
539 struct instruction *insn = xmalloc(sizeof(struct instruction));
547 insn_addc : OP_ADDC operlist_3 {
548 struct instruction *insn = xmalloc(sizeof(struct instruction));
556 insn_addscc : OP_ADDSCC operlist_3 {
557 struct instruction *insn = xmalloc(sizeof(struct instruction));
558 insn->op = OP_ADDSCC;
565 insn_sub : OP_SUB operlist_3 {
566 struct instruction *insn = xmalloc(sizeof(struct instruction));
574 insn_subsc : OP_SUBSC operlist_3 {
575 struct instruction *insn = xmalloc(sizeof(struct instruction));
583 insn_subc : OP_SUBC operlist_3 {
584 struct instruction *insn = xmalloc(sizeof(struct instruction));
592 insn_subscc : OP_SUBSCC operlist_3 {
593 struct instruction *insn = xmalloc(sizeof(struct instruction));
594 insn->op = OP_SUBSCC;
600 insn_sra : OP_SRA operlist_3 {
601 struct instruction *insn = xmalloc(sizeof(struct instruction));
608 insn_or : OP_OR operlist_3 {
609 struct instruction *insn = xmalloc(sizeof(struct instruction));
616 insn_and : OP_AND operlist_3 {
617 struct instruction *insn = xmalloc(sizeof(struct instruction));
624 insn_xor : OP_XOR operlist_3 {
625 struct instruction *insn = xmalloc(sizeof(struct instruction));
632 insn_sr : OP_SR operlist_3 {
633 struct instruction *insn = xmalloc(sizeof(struct instruction));
640 insn_srx : OP_SRX extended_operlist {
641 struct instruction *insn = xmalloc(sizeof(struct instruction));
648 insn_sl : OP_SL operlist_3 {
649 struct instruction *insn = xmalloc(sizeof(struct instruction));
656 insn_rl : OP_RL operlist_3 {
657 struct instruction *insn = xmalloc(sizeof(struct instruction));
664 insn_rr : OP_RR operlist_3 {
665 struct instruction *insn = xmalloc(sizeof(struct instruction));
672 insn_nand : OP_NAND operlist_3 {
673 struct instruction *insn = xmalloc(sizeof(struct instruction));
680 insn_orx : OP_ORX extended_operlist {
681 struct instruction *insn = xmalloc(sizeof(struct instruction));
688 insn_mov : OP_MOV operlist_2 {
689 struct instruction *insn = xmalloc(sizeof(struct instruction));
696 insn_jmp : OP_JMP labelref {
697 struct instruction *insn = xmalloc(sizeof(struct instruction));
698 struct operlist *ol = xmalloc(sizeof(struct operlist));
706 insn_jand : OP_JAND operlist_3 {
707 struct instruction *insn = xmalloc(sizeof(struct instruction));
714 insn_jnand : OP_JNAND operlist_3 {
715 struct instruction *insn = xmalloc(sizeof(struct instruction));
722 insn_js : OP_JS operlist_3 {
723 struct instruction *insn = xmalloc(sizeof(struct instruction));
730 insn_jns : OP_JNS operlist_3 {
731 struct instruction *insn = xmalloc(sizeof(struct instruction));
738 insn_je : OP_JE operlist_3 {
739 struct instruction *insn = xmalloc(sizeof(struct instruction));
746 insn_jne : OP_JNE operlist_3 {
747 struct instruction *insn = xmalloc(sizeof(struct instruction));
754 insn_jls : OP_JLS operlist_3 {
755 struct instruction *insn = xmalloc(sizeof(struct instruction));
762 insn_jges : OP_JGES operlist_3 {
763 struct instruction *insn = xmalloc(sizeof(struct instruction));
770 insn_jgs : OP_JGS operlist_3 {
771 struct instruction *insn = xmalloc(sizeof(struct instruction));
778 insn_jles : OP_JLES operlist_3 {
779 struct instruction *insn = xmalloc(sizeof(struct instruction));
786 insn_jl : OP_JL operlist_3 {
787 struct instruction *insn = xmalloc(sizeof(struct instruction));
794 insn_jge : OP_JGE operlist_3 {
795 struct instruction *insn = xmalloc(sizeof(struct instruction));
802 insn_jg : OP_JG operlist_3 {
803 struct instruction *insn = xmalloc(sizeof(struct instruction));
810 insn_jle : OP_JLE operlist_3 {
811 struct instruction *insn = xmalloc(sizeof(struct instruction));
818 insn_jzx : OP_JZX extended_operlist {
819 struct instruction *insn = xmalloc(sizeof(struct instruction));
826 insn_jnzx : OP_JNZX extended_operlist {
827 struct instruction *insn = xmalloc(sizeof(struct instruction));
834 insn_jext : OP_JEXT external_jump_operands {
835 struct instruction *insn = xmalloc(sizeof(struct instruction));
842 insn_jnext : OP_JNEXT external_jump_operands {
843 struct instruction *insn = xmalloc(sizeof(struct instruction));
855 insn_call : OP_CALL linkreg COMMA labelref {
856 struct instruction *insn = xmalloc(sizeof(struct instruction));
857 struct operlist *ol = xmalloc(sizeof(struct operlist));
858 struct operand *oper_lr = xmalloc(sizeof(struct operand));
859 struct operand *oper_zero = xmalloc(sizeof(struct operand));
860 oper_zero->type = OPER_RAW;
861 oper_zero->u.raw = 0;
862 oper_lr->type = OPER_RAW;
863 oper_lr->u.raw = (unsigned long)$2;
864 ol->oper[0] = oper_lr;
865 ol->oper[1] = oper_zero;
873 insn_ret : OP_RET linkreg COMMA linkreg {
874 struct instruction *insn = xmalloc(sizeof(struct instruction));
875 struct operlist *ol = xmalloc(sizeof(struct operlist));
876 struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
877 struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
878 struct operand *oper_zero = xmalloc(sizeof(struct operand));
879 oper_zero->type = OPER_RAW;
880 oper_zero->u.raw = 0;
881 oper_lr0->type = OPER_RAW;
882 oper_lr0->u.raw = (unsigned long)$2;
883 oper_lr1->type = OPER_RAW;
884 oper_lr1->u.raw = (unsigned long)$4;
885 ol->oper[0] = oper_lr0;
886 ol->oper[1] = oper_zero;
887 ol->oper[2] = oper_lr1;
894 insn_tkiph : OP_TKIPH operlist_2 {
895 struct instruction *insn = xmalloc(sizeof(struct instruction));
896 struct operlist *ol = $2;
897 struct operand *flags = xmalloc(sizeof(struct operand));
898 struct immediate *imm = xmalloc(sizeof(struct immediate));
900 flags->type = OPER_IMM;
902 ol->oper[2] = ol->oper[1];
910 insn_tkiphs : OP_TKIPHS operlist_2 {
911 struct instruction *insn = xmalloc(sizeof(struct instruction));
912 struct operlist *ol = $2;
913 struct operand *flags = xmalloc(sizeof(struct operand));
914 struct immediate *imm = xmalloc(sizeof(struct immediate));
915 imm->imm = 0x1 | 0x2;
916 flags->type = OPER_IMM;
918 ol->oper[2] = ol->oper[1];
926 insn_tkipl : OP_TKIPL operlist_2 {
927 struct instruction *insn = xmalloc(sizeof(struct instruction));
928 struct operlist *ol = $2;
929 struct operand *flags = xmalloc(sizeof(struct operand));
930 struct immediate *imm = xmalloc(sizeof(struct immediate));
932 flags->type = OPER_IMM;
934 ol->oper[2] = ol->oper[1];
942 insn_tkipls : OP_TKIPLS operlist_2 {
943 struct instruction *insn = xmalloc(sizeof(struct instruction));
944 struct operlist *ol = $2;
945 struct operand *flags = xmalloc(sizeof(struct operand));
946 struct immediate *imm = xmalloc(sizeof(struct immediate));
947 imm->imm = 0x0 | 0x2;
948 flags->type = OPER_IMM;
950 ol->oper[2] = ol->oper[1];
959 struct instruction *insn = xmalloc(sizeof(struct instruction));
960 struct operlist *ol = xmalloc(sizeof(struct operlist));
961 struct operand *regop = xmalloc(sizeof(struct operand));
962 struct operand *zeroop = xmalloc(sizeof(struct operand));
963 struct registr *r0 = xmalloc(sizeof(struct registr));
966 regop->type = OPER_REG;
968 zeroop->type = OPER_RAW;
969 zeroop->u.raw = 0x000;
972 ol->oper[2] = zeroop;
979 insn_raw : raw_code operlist_3 {
980 struct instruction *insn = xmalloc(sizeof(struct instruction));
983 insn->opcode = (unsigned long)$1;
988 raw_code : RAW_CODE {
989 yytext++; /* skip @ */
990 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
994 extended_operlist : decnum COMMA decnum COMMA operand COMMA operand COMMA operand {
995 struct operlist *ol = xmalloc(sizeof(struct operlist));
996 struct operand *mask_oper = xmalloc(sizeof(struct operand));
997 struct operand *shift_oper = xmalloc(sizeof(struct operand));
998 mask_oper->type = OPER_RAW;
999 mask_oper->u.raw = (unsigned long)$1;
1000 shift_oper->type = OPER_RAW;
1001 shift_oper->u.raw = (unsigned long)$3;
1002 ol->oper[0] = mask_oper;
1003 ol->oper[1] = shift_oper;
1006 ol->oper[4] = store_oper_sanity($9);
1011 external_jump_operands : hexnum COMMA operand COMMA operand COMMA labelref {
1012 struct operlist *ol = xmalloc(sizeof(struct operlist));
1013 struct operand *cond = xmalloc(sizeof(struct operand));
1014 cond->type = OPER_RAW;
1015 cond->u.raw = (unsigned long)$1;
1024 operlist_2 : operand COMMA operand {
1025 struct operlist *ol = xmalloc(sizeof(struct operlist));
1027 ol->oper[1] = store_oper_sanity($3);
1032 operlist_3 : operand COMMA operand COMMA operand {
1033 struct operlist *ol = xmalloc(sizeof(struct operlist));
1036 ol->oper[2] = store_oper_sanity($5);
1042 struct operand *oper = xmalloc(sizeof(struct operand));
1043 oper->type = OPER_REG;
1048 struct operand *oper = xmalloc(sizeof(struct operand));
1049 oper->type = OPER_MEM;
1054 struct operand *oper = xmalloc(sizeof(struct operand));
1055 oper->type = OPER_RAW;
1056 oper->u.raw = (unsigned long)$1;
1060 struct operand *oper = xmalloc(sizeof(struct operand));
1061 oper->type = OPER_IMM;
1071 struct registr *reg = xmalloc(sizeof(struct registr));
1073 reg->nr = (unsigned long)$2;
1077 struct registr *reg = xmalloc(sizeof(struct registr));
1079 yytext += 3; /* skip "spr" */
1080 reg->nr = strtoul(yytext, NULL, 16);
1084 struct registr *reg = xmalloc(sizeof(struct registr));
1086 reg->nr = (unsigned long)$2;
1091 mem : BRACK_OPEN hexnum_decnum BRACK_CLOSE {
1092 struct memory *mem = xmalloc(sizeof(struct memory));
1093 mem->type = MEM_DIRECT;
1094 mem->offset = (unsigned long)$2;
1097 | BRACK_OPEN hexnum_decnum COMMA OFFR regnr BRACK_CLOSE {
1098 struct memory *mem = xmalloc(sizeof(struct memory));
1099 mem->type = MEM_INDIRECT;
1100 mem->offset = (unsigned long)$2;
1101 mem->offr_nr = (unsigned long)$5;
1107 struct immediate *imm = xmalloc(sizeof(struct immediate));
1108 imm->imm = (unsigned long)$1;
1112 struct immediate *imm = xmalloc(sizeof(struct immediate));
1113 imm->imm = (unsigned long)$1;
1117 struct immediate *imm = xmalloc(sizeof(struct immediate));
1118 imm->imm = (unsigned long)$1;
1123 complex_imm : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1124 unsigned long a = (unsigned long)$2;
1125 unsigned long b = (unsigned long)$4;
1126 unsigned long operation = (unsigned long)$3;
1127 unsigned long res = 31337;
1128 switch (operation) {
1157 yyerror("Internal parser BUG. complex_imm oper unknown");
1161 | PAREN_OPEN complex_imm PAREN_CLOSE {
1164 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1165 unsigned long n = (unsigned long)$3;
1169 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1174 complex_imm_oper : PLUS {
1175 $$ = (void *)(unsigned long)PLUS;
1178 $$ = (void *)(unsigned long)MINUS;
1181 $$ = (void *)(unsigned long)MULTIPLY;
1184 $$ = (void *)(unsigned long)DIVIDE;
1187 $$ = (void *)(unsigned long)BITW_OR;
1190 $$ = (void *)(unsigned long)BITW_AND;
1193 $$ = (void *)(unsigned long)BITW_XOR;
1196 $$ = (void *)(unsigned long)LEFTSHIFT;
1199 $$ = (void *)(unsigned long)RIGHTSHIFT;
1203 complex_imm_arg : complex_imm_const {
1211 complex_imm_const : hexnum_decnum {
1214 | BITW_NOT hexnum_decnum {
1215 unsigned long n = (unsigned long)$2;
1222 while (yytext[0] != 'x') {
1223 if (yytext[0] == '\0')
1224 yyerror("Internal HEXNUM parser error");
1228 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1233 $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1237 hexnum_decnum : hexnum {
1245 labelref : identifier {
1246 struct operand *oper = xmalloc(sizeof(struct operand));
1247 struct label *label = xmalloc(sizeof(struct label));
1249 label->direction = LABELREF_ABSOLUTE;
1250 oper->type = OPER_LABEL;
1251 oper->u.label = label;
1254 | identifier MINUS {
1255 struct operand *oper = xmalloc(sizeof(struct operand));
1256 struct label *label = xmalloc(sizeof(struct label));
1258 label->direction = LABELREF_RELATIVE_BACK;
1259 oper->type = OPER_LABEL;
1260 oper->u.label = label;
1264 struct operand *oper = xmalloc(sizeof(struct operand));
1265 struct label *label = xmalloc(sizeof(struct label));
1267 label->direction = LABELREF_RELATIVE_FORWARD;
1268 oper->type = OPER_LABEL;
1269 oper->u.label = label;
1275 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1279 identifier : IDENT {
1280 $$ = xstrdup(yytext);
1286 int section = SECTION_TEXT; /* default to .text section */
1287 struct initvals_sect *cur_initvals_sect;
1289 void yyerror(char *str)
1294 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1296 cur_lineinfo.lineno,
1297 cur_lineinfo.column);
1298 fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1299 for (i = 0; i < cur_lineinfo.column - 1; i++)
1300 fprintf(stderr, " ");
1301 fprintf(stderr, "^\n");
1302 fprintf(stderr, "%s\n", str);
1306 static struct operand * store_oper_sanity(struct operand *oper)
1308 if (oper->type == OPER_IMM &&
1309 oper->u.imm->imm != 0) {
1310 yyerror("Only 0x000 Immediate is allowed for "