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 SEMICOLON 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
53 line : line_terminator {
56 | line statement line_terminator {
57 struct statement *s = $2;
58 if (section != SECTION_TEXT)
59 yyerror("Microcode text instruction in non .text section");
60 memcpy(&s->info, &cur_lineinfo, sizeof(struct lineinfo));
61 list_add_tail(&s->list, &infile.sl);
63 | line section_switch line_terminator {
65 | line ivals_write line_terminator {
66 struct initval_op *io = $2;
67 if (section != SECTION_IVALS)
68 yyerror("InitVals write in non .initvals section");
69 memcpy(&io->info, &cur_lineinfo, sizeof(struct lineinfo));
70 INIT_LIST_HEAD(&io->list);
71 list_add_tail(&io->list, &cur_initvals_sect->ops);
75 /* Allow terminating lines with the ";" char */
76 line_terminator : /* Nothing */
77 | SEMICOLON line_terminator
80 section_switch : SECTION_TEXT {
81 section = SECTION_TEXT;
83 | SECTION_IVALS PAREN_OPEN identifier PAREN_CLOSE {
84 const char *sectname = $3;
85 struct initvals_sect *s;
86 cur_initvals_sect = NULL;
87 /* Search if there already is a section by that name. */
88 list_for_each_entry(s, &infile.ivals, list) {
89 if (strcmp(sectname, s->name) == 0)
90 cur_initvals_sect = s;
92 if (!cur_initvals_sect) {
93 /* Not found, create a new one. */
94 s = xmalloc(sizeof(struct initvals_sect));
96 INIT_LIST_HEAD(&s->ops);
97 INIT_LIST_HEAD(&s->list);
98 list_add_tail(&s->list, &infile.ivals);
99 cur_initvals_sect = s;
101 section = SECTION_IVALS;
105 ivals_write : IVAL_MMIO16 imm_value COMMA imm_value {
106 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
107 iop->type = IVAL_W_MMIO16;
108 iop->args[0] = (unsigned int)(unsigned long)$2;
109 iop->args[1] = (unsigned int)(unsigned long)$4;
112 | IVAL_MMIO32 imm_value COMMA imm_value {
113 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
114 iop->type = IVAL_W_MMIO32;
115 iop->args[0] = (unsigned int)(unsigned long)$2;
116 iop->args[1] = (unsigned int)(unsigned long)$4;
119 | IVAL_PHY imm_value COMMA imm_value {
120 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
121 iop->type = IVAL_W_PHY;
122 iop->args[0] = (unsigned int)(unsigned long)$2;
123 iop->args[1] = (unsigned int)(unsigned long)$4;
126 | IVAL_RADIO imm_value COMMA imm_value {
127 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
128 iop->type = IVAL_W_RADIO;
129 iop->args[0] = (unsigned int)(unsigned long)$2;
130 iop->args[1] = (unsigned int)(unsigned long)$4;
133 | IVAL_SHM16 imm_value COMMA imm_value COMMA imm_value {
134 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
135 iop->type = IVAL_W_SHM16;
136 iop->args[0] = (unsigned int)(unsigned long)$2;
137 iop->args[1] = (unsigned int)(unsigned long)$4;
138 iop->args[2] = (unsigned int)(unsigned long)$6;
141 | IVAL_SHM32 imm_value COMMA imm_value COMMA imm_value {
142 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
143 iop->type = IVAL_W_SHM32;
144 iop->args[0] = (unsigned int)(unsigned long)$2;
145 iop->args[1] = (unsigned int)(unsigned long)$4;
146 iop->args[2] = (unsigned int)(unsigned long)$6;
152 struct statement *s = xmalloc(sizeof(struct statement));
153 INIT_LIST_HEAD(&s->list);
154 s->type = STMT_ASMDIR;
159 struct statement *s = xmalloc(sizeof(struct statement));
160 INIT_LIST_HEAD(&s->list);
161 s->type = STMT_LABEL;
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);
488 struct statement *s = xmalloc(sizeof(struct statement));
489 INIT_LIST_HEAD(&s->list);
497 asmdir : ASM_ARCH hexnum_decnum {
498 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
499 ad->type = ADIR_ARCH;
500 ad->u.arch = (unsigned int)(unsigned long)$2;
503 | ASM_START identifier {
504 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
505 struct label *label = xmalloc(sizeof(struct label));
507 label->direction = LABELREF_ABSOLUTE;
508 ad->type = ADIR_START;
515 struct label *label = xmalloc(sizeof(struct label));
518 l[strlen(l) - 1] = '\0';
525 insn_add : OP_ADD operlist_3 {
526 struct instruction *insn = xmalloc(sizeof(struct instruction));
534 insn_addsc : OP_ADDSC operlist_3 {
535 struct instruction *insn = xmalloc(sizeof(struct instruction));
543 insn_addc : OP_ADDC operlist_3 {
544 struct instruction *insn = xmalloc(sizeof(struct instruction));
552 insn_addscc : OP_ADDSCC operlist_3 {
553 struct instruction *insn = xmalloc(sizeof(struct instruction));
554 insn->op = OP_ADDSCC;
561 insn_sub : OP_SUB operlist_3 {
562 struct instruction *insn = xmalloc(sizeof(struct instruction));
570 insn_subsc : OP_SUBSC operlist_3 {
571 struct instruction *insn = xmalloc(sizeof(struct instruction));
579 insn_subc : OP_SUBC operlist_3 {
580 struct instruction *insn = xmalloc(sizeof(struct instruction));
588 insn_subscc : OP_SUBSCC operlist_3 {
589 struct instruction *insn = xmalloc(sizeof(struct instruction));
590 insn->op = OP_SUBSCC;
596 insn_sra : OP_SRA operlist_3 {
597 struct instruction *insn = xmalloc(sizeof(struct instruction));
604 insn_or : OP_OR operlist_3 {
605 struct instruction *insn = xmalloc(sizeof(struct instruction));
612 insn_and : OP_AND operlist_3 {
613 struct instruction *insn = xmalloc(sizeof(struct instruction));
620 insn_xor : OP_XOR operlist_3 {
621 struct instruction *insn = xmalloc(sizeof(struct instruction));
628 insn_sr : OP_SR operlist_3 {
629 struct instruction *insn = xmalloc(sizeof(struct instruction));
636 insn_srx : OP_SRX extended_operlist {
637 struct instruction *insn = xmalloc(sizeof(struct instruction));
644 insn_sl : OP_SL operlist_3 {
645 struct instruction *insn = xmalloc(sizeof(struct instruction));
652 insn_rl : OP_RL operlist_3 {
653 struct instruction *insn = xmalloc(sizeof(struct instruction));
660 insn_rr : OP_RR operlist_3 {
661 struct instruction *insn = xmalloc(sizeof(struct instruction));
668 insn_nand : OP_NAND operlist_3 {
669 struct instruction *insn = xmalloc(sizeof(struct instruction));
676 insn_orx : OP_ORX extended_operlist {
677 struct instruction *insn = xmalloc(sizeof(struct instruction));
684 insn_mov : OP_MOV operlist_2 {
685 struct instruction *insn = xmalloc(sizeof(struct instruction));
692 insn_jmp : OP_JMP labelref {
693 struct instruction *insn = xmalloc(sizeof(struct instruction));
694 struct operlist *ol = xmalloc(sizeof(struct operlist));
702 insn_jand : OP_JAND operlist_3 {
703 struct instruction *insn = xmalloc(sizeof(struct instruction));
710 insn_jnand : OP_JNAND operlist_3 {
711 struct instruction *insn = xmalloc(sizeof(struct instruction));
718 insn_js : OP_JS operlist_3 {
719 struct instruction *insn = xmalloc(sizeof(struct instruction));
726 insn_jns : OP_JNS operlist_3 {
727 struct instruction *insn = xmalloc(sizeof(struct instruction));
734 insn_je : OP_JE operlist_3 {
735 struct instruction *insn = xmalloc(sizeof(struct instruction));
742 insn_jne : OP_JNE operlist_3 {
743 struct instruction *insn = xmalloc(sizeof(struct instruction));
750 insn_jls : OP_JLS operlist_3 {
751 struct instruction *insn = xmalloc(sizeof(struct instruction));
758 insn_jges : OP_JGES operlist_3 {
759 struct instruction *insn = xmalloc(sizeof(struct instruction));
766 insn_jgs : OP_JGS operlist_3 {
767 struct instruction *insn = xmalloc(sizeof(struct instruction));
774 insn_jles : OP_JLES operlist_3 {
775 struct instruction *insn = xmalloc(sizeof(struct instruction));
782 insn_jl : OP_JL operlist_3 {
783 struct instruction *insn = xmalloc(sizeof(struct instruction));
790 insn_jge : OP_JGE operlist_3 {
791 struct instruction *insn = xmalloc(sizeof(struct instruction));
798 insn_jg : OP_JG operlist_3 {
799 struct instruction *insn = xmalloc(sizeof(struct instruction));
806 insn_jle : OP_JLE operlist_3 {
807 struct instruction *insn = xmalloc(sizeof(struct instruction));
814 insn_jzx : OP_JZX extended_operlist {
815 struct instruction *insn = xmalloc(sizeof(struct instruction));
822 insn_jnzx : OP_JNZX extended_operlist {
823 struct instruction *insn = xmalloc(sizeof(struct instruction));
830 insn_jext : OP_JEXT external_jump_operands {
831 struct instruction *insn = xmalloc(sizeof(struct instruction));
838 insn_jnext : OP_JNEXT external_jump_operands {
839 struct instruction *insn = xmalloc(sizeof(struct instruction));
851 insn_call : OP_CALL linkreg COMMA labelref {
852 struct instruction *insn = xmalloc(sizeof(struct instruction));
853 struct operlist *ol = xmalloc(sizeof(struct operlist));
854 struct operand *oper_lr = xmalloc(sizeof(struct operand));
855 struct operand *oper_zero = xmalloc(sizeof(struct operand));
856 oper_zero->type = OPER_RAW;
857 oper_zero->u.raw = 0;
858 oper_lr->type = OPER_RAW;
859 oper_lr->u.raw = (unsigned long)$2;
860 ol->oper[0] = oper_lr;
861 ol->oper[1] = oper_zero;
869 insn_ret : OP_RET linkreg COMMA linkreg {
870 struct instruction *insn = xmalloc(sizeof(struct instruction));
871 struct operlist *ol = xmalloc(sizeof(struct operlist));
872 struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
873 struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
874 struct operand *oper_zero = xmalloc(sizeof(struct operand));
875 oper_zero->type = OPER_RAW;
876 oper_zero->u.raw = 0;
877 oper_lr0->type = OPER_RAW;
878 oper_lr0->u.raw = (unsigned long)$2;
879 oper_lr1->type = OPER_RAW;
880 oper_lr1->u.raw = (unsigned long)$4;
881 ol->oper[0] = oper_lr0;
882 ol->oper[1] = oper_zero;
883 ol->oper[2] = oper_lr1;
890 insn_tkiph : OP_TKIPH operlist_2 {
891 struct instruction *insn = xmalloc(sizeof(struct instruction));
892 struct operlist *ol = $2;
893 struct operand *flags = xmalloc(sizeof(struct operand));
894 struct immediate *imm = xmalloc(sizeof(struct immediate));
896 flags->type = OPER_IMM;
898 ol->oper[2] = ol->oper[1];
906 insn_tkiphs : OP_TKIPHS operlist_2 {
907 struct instruction *insn = xmalloc(sizeof(struct instruction));
908 struct operlist *ol = $2;
909 struct operand *flags = xmalloc(sizeof(struct operand));
910 struct immediate *imm = xmalloc(sizeof(struct immediate));
911 imm->imm = 0x1 | 0x2;
912 flags->type = OPER_IMM;
914 ol->oper[2] = ol->oper[1];
922 insn_tkipl : OP_TKIPL operlist_2 {
923 struct instruction *insn = xmalloc(sizeof(struct instruction));
924 struct operlist *ol = $2;
925 struct operand *flags = xmalloc(sizeof(struct operand));
926 struct immediate *imm = xmalloc(sizeof(struct immediate));
928 flags->type = OPER_IMM;
930 ol->oper[2] = ol->oper[1];
938 insn_tkipls : OP_TKIPLS operlist_2 {
939 struct instruction *insn = xmalloc(sizeof(struct instruction));
940 struct operlist *ol = $2;
941 struct operand *flags = xmalloc(sizeof(struct operand));
942 struct immediate *imm = xmalloc(sizeof(struct immediate));
943 imm->imm = 0x0 | 0x2;
944 flags->type = OPER_IMM;
946 ol->oper[2] = ol->oper[1];
955 struct instruction *insn = xmalloc(sizeof(struct instruction));
956 struct operlist *ol = xmalloc(sizeof(struct operlist));
957 struct operand *regop = xmalloc(sizeof(struct operand));
958 struct operand *zeroop = xmalloc(sizeof(struct operand));
959 struct registr *r0 = xmalloc(sizeof(struct registr));
962 regop->type = OPER_REG;
964 zeroop->type = OPER_RAW;
965 zeroop->u.raw = 0x000;
968 ol->oper[2] = zeroop;
975 insn_raw : raw_code operlist_3 {
976 struct instruction *insn = xmalloc(sizeof(struct instruction));
979 insn->opcode = (unsigned long)$1;
984 raw_code : RAW_CODE {
985 yytext++; /* skip @ */
986 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
990 extended_operlist : decnum COMMA decnum COMMA operand COMMA operand COMMA operand {
991 struct operlist *ol = xmalloc(sizeof(struct operlist));
992 struct operand *mask_oper = xmalloc(sizeof(struct operand));
993 struct operand *shift_oper = xmalloc(sizeof(struct operand));
994 mask_oper->type = OPER_RAW;
995 mask_oper->u.raw = (unsigned long)$1;
996 shift_oper->type = OPER_RAW;
997 shift_oper->u.raw = (unsigned long)$3;
998 ol->oper[0] = mask_oper;
999 ol->oper[1] = shift_oper;
1002 ol->oper[4] = store_oper_sanity($9);
1007 external_jump_operands : imm COMMA labelref {
1008 struct operlist *ol = xmalloc(sizeof(struct operlist));
1009 struct operand *cond = xmalloc(sizeof(struct operand));
1010 cond->type = OPER_IMM;
1018 operlist_2 : operand COMMA operand {
1019 struct operlist *ol = xmalloc(sizeof(struct operlist));
1021 ol->oper[1] = store_oper_sanity($3);
1026 operlist_3 : operand COMMA operand COMMA operand {
1027 struct operlist *ol = xmalloc(sizeof(struct operlist));
1030 ol->oper[2] = store_oper_sanity($5);
1036 struct operand *oper = xmalloc(sizeof(struct operand));
1037 oper->type = OPER_REG;
1042 struct operand *oper = xmalloc(sizeof(struct operand));
1043 oper->type = OPER_MEM;
1048 struct operand *oper = xmalloc(sizeof(struct operand));
1049 oper->type = OPER_RAW;
1050 oper->u.raw = (unsigned long)$1;
1054 struct operand *oper = xmalloc(sizeof(struct operand));
1055 oper->type = OPER_IMM;
1065 struct registr *reg = xmalloc(sizeof(struct registr));
1067 reg->nr = (unsigned long)$2;
1071 struct registr *reg = xmalloc(sizeof(struct registr));
1073 yytext += 3; /* skip "spr" */
1074 reg->nr = strtoul(yytext, NULL, 16);
1078 struct registr *reg = xmalloc(sizeof(struct registr));
1080 reg->nr = (unsigned long)$2;
1085 mem : BRACK_OPEN imm BRACK_CLOSE {
1086 struct memory *mem = xmalloc(sizeof(struct memory));
1087 struct immediate *offset_imm = $2;
1088 mem->type = MEM_DIRECT;
1089 mem->offset = offset_imm->imm;
1093 | BRACK_OPEN imm COMMA OFFR regnr BRACK_CLOSE {
1094 struct memory *mem = xmalloc(sizeof(struct memory));
1095 struct immediate *offset_imm = $2;
1096 mem->type = MEM_INDIRECT;
1097 mem->offset = offset_imm->imm;
1099 mem->offr_nr = (unsigned long)$5;
1105 struct immediate *imm = xmalloc(sizeof(struct immediate));
1106 imm->imm = (unsigned long)$1;
1111 imm_value : hexnum_decnum {
1119 complex_imm : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1120 unsigned long a = (unsigned long)$2;
1121 unsigned long b = (unsigned long)$4;
1122 unsigned long operation = (unsigned long)$3;
1123 unsigned long res = 31337;
1124 switch (operation) {
1153 yyerror("Internal parser BUG. complex_imm oper unknown");
1157 | PAREN_OPEN complex_imm PAREN_CLOSE {
1160 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1161 unsigned long n = (unsigned long)$3;
1165 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1170 complex_imm_oper : PLUS {
1171 $$ = (void *)(unsigned long)PLUS;
1174 $$ = (void *)(unsigned long)MINUS;
1177 $$ = (void *)(unsigned long)MULTIPLY;
1180 $$ = (void *)(unsigned long)DIVIDE;
1183 $$ = (void *)(unsigned long)BITW_OR;
1186 $$ = (void *)(unsigned long)BITW_AND;
1189 $$ = (void *)(unsigned long)BITW_XOR;
1192 $$ = (void *)(unsigned long)LEFTSHIFT;
1195 $$ = (void *)(unsigned long)RIGHTSHIFT;
1199 complex_imm_arg : complex_imm_const {
1207 complex_imm_const : hexnum_decnum {
1210 | BITW_NOT hexnum_decnum {
1211 unsigned long n = (unsigned long)$2;
1218 while (yytext[0] != 'x') {
1219 if (yytext[0] == '\0')
1220 yyerror("Internal HEXNUM parser error");
1224 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1229 $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1233 hexnum_decnum : hexnum {
1241 labelref : identifier {
1242 struct operand *oper = xmalloc(sizeof(struct operand));
1243 struct label *label = xmalloc(sizeof(struct label));
1245 label->direction = LABELREF_ABSOLUTE;
1246 oper->type = OPER_LABEL;
1247 oper->u.label = label;
1250 | identifier MINUS {
1251 struct operand *oper = xmalloc(sizeof(struct operand));
1252 struct label *label = xmalloc(sizeof(struct label));
1254 label->direction = LABELREF_RELATIVE_BACK;
1255 oper->type = OPER_LABEL;
1256 oper->u.label = label;
1260 struct operand *oper = xmalloc(sizeof(struct operand));
1261 struct label *label = xmalloc(sizeof(struct label));
1263 label->direction = LABELREF_RELATIVE_FORWARD;
1264 oper->type = OPER_LABEL;
1265 oper->u.label = label;
1271 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1275 identifier : IDENT {
1276 $$ = xstrdup(yytext);
1282 int section = SECTION_TEXT; /* default to .text section */
1283 struct initvals_sect *cur_initvals_sect;
1285 void yyerror(char *str)
1290 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1292 cur_lineinfo.lineno,
1293 cur_lineinfo.column);
1294 fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1295 for (i = 0; i < cur_lineinfo.column - 1; i++)
1296 fprintf(stderr, " ");
1297 fprintf(stderr, "^\n");
1298 fprintf(stderr, "%s\n", str);
1302 static struct operand * store_oper_sanity(struct operand *oper)
1304 if (oper->type == OPER_IMM &&
1305 oper->u.imm->imm != 0) {
1306 yyerror("Only 0x000 Immediate is allowed for "