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
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 | BITW_OR line_terminator
79 section_switch : SECTION_TEXT {
80 section = SECTION_TEXT;
82 | SECTION_IVALS PAREN_OPEN identifier PAREN_CLOSE {
83 const char *sectname = $3;
84 struct initvals_sect *s;
85 cur_initvals_sect = NULL;
86 /* Search if there already is a section by that name. */
87 list_for_each_entry(s, &infile.ivals, list) {
88 if (strcmp(sectname, s->name) == 0)
89 cur_initvals_sect = s;
91 if (!cur_initvals_sect) {
92 /* Not found, create a new one. */
93 s = xmalloc(sizeof(struct initvals_sect));
95 INIT_LIST_HEAD(&s->ops);
96 INIT_LIST_HEAD(&s->list);
97 list_add_tail(&s->list, &infile.ivals);
98 cur_initvals_sect = s;
100 section = SECTION_IVALS;
104 ivals_write : IVAL_MMIO16 hexnum_decnum COMMA hexnum_decnum {
105 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
106 iop->type = IVAL_W_MMIO16;
107 iop->args[0] = (unsigned int)(unsigned long)$2;
108 iop->args[1] = (unsigned int)(unsigned long)$4;
111 | IVAL_MMIO32 hexnum_decnum COMMA hexnum_decnum {
112 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
113 iop->type = IVAL_W_MMIO32;
114 iop->args[0] = (unsigned int)(unsigned long)$2;
115 iop->args[1] = (unsigned int)(unsigned long)$4;
118 | IVAL_PHY hexnum_decnum COMMA hexnum_decnum {
119 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
120 iop->type = IVAL_W_PHY;
121 iop->args[0] = (unsigned int)(unsigned long)$2;
122 iop->args[1] = (unsigned int)(unsigned long)$4;
125 | IVAL_RADIO hexnum_decnum COMMA hexnum_decnum {
126 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
127 iop->type = IVAL_W_RADIO;
128 iop->args[0] = (unsigned int)(unsigned long)$2;
129 iop->args[1] = (unsigned int)(unsigned long)$4;
132 | IVAL_SHM16 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum {
133 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
134 iop->type = IVAL_W_SHM16;
135 iop->args[0] = (unsigned int)(unsigned long)$2;
136 iop->args[1] = (unsigned int)(unsigned long)$4;
137 iop->args[2] = (unsigned int)(unsigned long)$6;
140 | IVAL_SHM32 hexnum_decnum COMMA hexnum_decnum COMMA hexnum_decnum {
141 struct initval_op *iop = xmalloc(sizeof(struct initval_op));
142 iop->type = IVAL_W_SHM32;
143 iop->args[0] = (unsigned int)(unsigned long)$2;
144 iop->args[1] = (unsigned int)(unsigned long)$4;
145 iop->args[2] = (unsigned int)(unsigned long)$6;
151 struct statement *s = xmalloc(sizeof(struct statement));
152 INIT_LIST_HEAD(&s->list);
153 s->type = STMT_ASMDIR;
158 struct statement *s = xmalloc(sizeof(struct statement));
159 INIT_LIST_HEAD(&s->list);
160 s->type = STMT_LABEL;
165 struct statement *s = xmalloc(sizeof(struct statement));
166 INIT_LIST_HEAD(&s->list);
172 struct statement *s = xmalloc(sizeof(struct statement));
173 INIT_LIST_HEAD(&s->list);
179 struct statement *s = xmalloc(sizeof(struct statement));
180 INIT_LIST_HEAD(&s->list);
186 struct statement *s = xmalloc(sizeof(struct statement));
187 INIT_LIST_HEAD(&s->list);
193 struct statement *s = xmalloc(sizeof(struct statement));
194 INIT_LIST_HEAD(&s->list);
200 struct statement *s = xmalloc(sizeof(struct statement));
201 INIT_LIST_HEAD(&s->list);
207 struct statement *s = xmalloc(sizeof(struct statement));
208 INIT_LIST_HEAD(&s->list);
214 struct statement *s = xmalloc(sizeof(struct statement));
215 INIT_LIST_HEAD(&s->list);
221 struct statement *s = xmalloc(sizeof(struct statement));
222 INIT_LIST_HEAD(&s->list);
228 struct statement *s = xmalloc(sizeof(struct statement));
229 INIT_LIST_HEAD(&s->list);
235 struct statement *s = xmalloc(sizeof(struct statement));
236 INIT_LIST_HEAD(&s->list);
242 struct statement *s = xmalloc(sizeof(struct statement));
243 INIT_LIST_HEAD(&s->list);
249 struct statement *s = xmalloc(sizeof(struct statement));
250 INIT_LIST_HEAD(&s->list);
256 struct statement *s = xmalloc(sizeof(struct statement));
257 INIT_LIST_HEAD(&s->list);
263 struct statement *s = xmalloc(sizeof(struct statement));
264 INIT_LIST_HEAD(&s->list);
270 struct statement *s = xmalloc(sizeof(struct statement));
271 INIT_LIST_HEAD(&s->list);
277 struct statement *s = xmalloc(sizeof(struct statement));
278 INIT_LIST_HEAD(&s->list);
284 struct statement *s = xmalloc(sizeof(struct statement));
285 INIT_LIST_HEAD(&s->list);
291 struct statement *s = xmalloc(sizeof(struct statement));
292 INIT_LIST_HEAD(&s->list);
298 struct statement *s = xmalloc(sizeof(struct statement));
299 INIT_LIST_HEAD(&s->list);
305 struct statement *s = xmalloc(sizeof(struct statement));
306 INIT_LIST_HEAD(&s->list);
312 struct statement *s = xmalloc(sizeof(struct statement));
313 INIT_LIST_HEAD(&s->list);
319 struct statement *s = xmalloc(sizeof(struct statement));
320 INIT_LIST_HEAD(&s->list);
326 struct statement *s = xmalloc(sizeof(struct statement));
327 INIT_LIST_HEAD(&s->list);
333 struct statement *s = xmalloc(sizeof(struct statement));
334 INIT_LIST_HEAD(&s->list);
340 struct statement *s = xmalloc(sizeof(struct statement));
341 INIT_LIST_HEAD(&s->list);
347 struct statement *s = xmalloc(sizeof(struct statement));
348 INIT_LIST_HEAD(&s->list);
354 struct statement *s = xmalloc(sizeof(struct statement));
355 INIT_LIST_HEAD(&s->list);
361 struct statement *s = xmalloc(sizeof(struct statement));
362 INIT_LIST_HEAD(&s->list);
368 struct statement *s = xmalloc(sizeof(struct statement));
369 INIT_LIST_HEAD(&s->list);
375 struct statement *s = xmalloc(sizeof(struct statement));
376 INIT_LIST_HEAD(&s->list);
382 struct statement *s = xmalloc(sizeof(struct statement));
383 INIT_LIST_HEAD(&s->list);
389 struct statement *s = xmalloc(sizeof(struct statement));
390 INIT_LIST_HEAD(&s->list);
396 struct statement *s = xmalloc(sizeof(struct statement));
397 INIT_LIST_HEAD(&s->list);
403 struct statement *s = xmalloc(sizeof(struct statement));
404 INIT_LIST_HEAD(&s->list);
410 struct statement *s = xmalloc(sizeof(struct statement));
411 INIT_LIST_HEAD(&s->list);
417 struct statement *s = xmalloc(sizeof(struct statement));
418 INIT_LIST_HEAD(&s->list);
424 struct statement *s = xmalloc(sizeof(struct statement));
425 INIT_LIST_HEAD(&s->list);
431 struct statement *s = xmalloc(sizeof(struct statement));
432 INIT_LIST_HEAD(&s->list);
438 struct statement *s = xmalloc(sizeof(struct statement));
439 INIT_LIST_HEAD(&s->list);
445 struct statement *s = xmalloc(sizeof(struct statement));
446 INIT_LIST_HEAD(&s->list);
452 struct statement *s = xmalloc(sizeof(struct statement));
453 INIT_LIST_HEAD(&s->list);
459 struct statement *s = xmalloc(sizeof(struct statement));
460 INIT_LIST_HEAD(&s->list);
466 struct statement *s = xmalloc(sizeof(struct statement));
467 INIT_LIST_HEAD(&s->list);
473 struct statement *s = xmalloc(sizeof(struct statement));
474 INIT_LIST_HEAD(&s->list);
480 struct statement *s = xmalloc(sizeof(struct statement));
481 INIT_LIST_HEAD(&s->list);
487 struct statement *s = xmalloc(sizeof(struct statement));
488 INIT_LIST_HEAD(&s->list);
496 asmdir : ASM_ARCH hexnum_decnum {
497 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
498 ad->type = ADIR_ARCH;
499 ad->u.arch = (unsigned int)(unsigned long)$2;
502 | ASM_START identifier {
503 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
504 struct label *label = xmalloc(sizeof(struct label));
506 label->direction = LABELREF_ABSOLUTE;
507 ad->type = ADIR_START;
514 struct label *label = xmalloc(sizeof(struct label));
517 l[strlen(l) - 1] = '\0';
524 insn_add : OP_ADD operlist_3 {
525 struct instruction *insn = xmalloc(sizeof(struct instruction));
533 insn_addsc : OP_ADDSC operlist_3 {
534 struct instruction *insn = xmalloc(sizeof(struct instruction));
542 insn_addc : OP_ADDC operlist_3 {
543 struct instruction *insn = xmalloc(sizeof(struct instruction));
551 insn_addscc : OP_ADDSCC operlist_3 {
552 struct instruction *insn = xmalloc(sizeof(struct instruction));
553 insn->op = OP_ADDSCC;
560 insn_sub : OP_SUB operlist_3 {
561 struct instruction *insn = xmalloc(sizeof(struct instruction));
569 insn_subsc : OP_SUBSC operlist_3 {
570 struct instruction *insn = xmalloc(sizeof(struct instruction));
578 insn_subc : OP_SUBC operlist_3 {
579 struct instruction *insn = xmalloc(sizeof(struct instruction));
587 insn_subscc : OP_SUBSCC operlist_3 {
588 struct instruction *insn = xmalloc(sizeof(struct instruction));
589 insn->op = OP_SUBSCC;
595 insn_sra : OP_SRA operlist_3 {
596 struct instruction *insn = xmalloc(sizeof(struct instruction));
603 insn_or : OP_OR operlist_3 {
604 struct instruction *insn = xmalloc(sizeof(struct instruction));
611 insn_and : OP_AND operlist_3 {
612 struct instruction *insn = xmalloc(sizeof(struct instruction));
619 insn_xor : OP_XOR operlist_3 {
620 struct instruction *insn = xmalloc(sizeof(struct instruction));
627 insn_sr : OP_SR operlist_3 {
628 struct instruction *insn = xmalloc(sizeof(struct instruction));
635 insn_srx : OP_SRX extended_operlist {
636 struct instruction *insn = xmalloc(sizeof(struct instruction));
643 insn_sl : OP_SL operlist_3 {
644 struct instruction *insn = xmalloc(sizeof(struct instruction));
651 insn_rl : OP_RL operlist_3 {
652 struct instruction *insn = xmalloc(sizeof(struct instruction));
659 insn_rr : OP_RR operlist_3 {
660 struct instruction *insn = xmalloc(sizeof(struct instruction));
667 insn_nand : OP_NAND operlist_3 {
668 struct instruction *insn = xmalloc(sizeof(struct instruction));
675 insn_orx : OP_ORX extended_operlist {
676 struct instruction *insn = xmalloc(sizeof(struct instruction));
683 insn_mov : OP_MOV operlist_2 {
684 struct instruction *insn = xmalloc(sizeof(struct instruction));
691 insn_jmp : OP_JMP labelref {
692 struct instruction *insn = xmalloc(sizeof(struct instruction));
693 struct operlist *ol = xmalloc(sizeof(struct operlist));
701 insn_jand : OP_JAND operlist_3 {
702 struct instruction *insn = xmalloc(sizeof(struct instruction));
709 insn_jnand : OP_JNAND operlist_3 {
710 struct instruction *insn = xmalloc(sizeof(struct instruction));
717 insn_js : OP_JS operlist_3 {
718 struct instruction *insn = xmalloc(sizeof(struct instruction));
725 insn_jns : OP_JNS operlist_3 {
726 struct instruction *insn = xmalloc(sizeof(struct instruction));
733 insn_je : OP_JE operlist_3 {
734 struct instruction *insn = xmalloc(sizeof(struct instruction));
741 insn_jne : OP_JNE operlist_3 {
742 struct instruction *insn = xmalloc(sizeof(struct instruction));
749 insn_jls : OP_JLS operlist_3 {
750 struct instruction *insn = xmalloc(sizeof(struct instruction));
757 insn_jges : OP_JGES operlist_3 {
758 struct instruction *insn = xmalloc(sizeof(struct instruction));
765 insn_jgs : OP_JGS operlist_3 {
766 struct instruction *insn = xmalloc(sizeof(struct instruction));
773 insn_jles : OP_JLES operlist_3 {
774 struct instruction *insn = xmalloc(sizeof(struct instruction));
781 insn_jl : OP_JL operlist_3 {
782 struct instruction *insn = xmalloc(sizeof(struct instruction));
789 insn_jge : OP_JGE operlist_3 {
790 struct instruction *insn = xmalloc(sizeof(struct instruction));
797 insn_jg : OP_JG operlist_3 {
798 struct instruction *insn = xmalloc(sizeof(struct instruction));
805 insn_jle : OP_JLE operlist_3 {
806 struct instruction *insn = xmalloc(sizeof(struct instruction));
813 insn_jzx : OP_JZX extended_operlist {
814 struct instruction *insn = xmalloc(sizeof(struct instruction));
821 insn_jnzx : OP_JNZX extended_operlist {
822 struct instruction *insn = xmalloc(sizeof(struct instruction));
829 insn_jext : OP_JEXT external_jump_operands {
830 struct instruction *insn = xmalloc(sizeof(struct instruction));
837 insn_jnext : OP_JNEXT external_jump_operands {
838 struct instruction *insn = xmalloc(sizeof(struct instruction));
850 insn_call : OP_CALL linkreg COMMA labelref {
851 struct instruction *insn = xmalloc(sizeof(struct instruction));
852 struct operlist *ol = xmalloc(sizeof(struct operlist));
853 struct operand *oper_lr = xmalloc(sizeof(struct operand));
854 struct operand *oper_zero = xmalloc(sizeof(struct operand));
855 oper_zero->type = OPER_RAW;
856 oper_zero->u.raw = 0;
857 oper_lr->type = OPER_RAW;
858 oper_lr->u.raw = (unsigned long)$2;
859 ol->oper[0] = oper_lr;
860 ol->oper[1] = oper_zero;
868 insn_ret : OP_RET linkreg COMMA linkreg {
869 struct instruction *insn = xmalloc(sizeof(struct instruction));
870 struct operlist *ol = xmalloc(sizeof(struct operlist));
871 struct operand *oper_lr0 = xmalloc(sizeof(struct operand));
872 struct operand *oper_lr1 = xmalloc(sizeof(struct operand));
873 struct operand *oper_zero = xmalloc(sizeof(struct operand));
874 oper_zero->type = OPER_RAW;
875 oper_zero->u.raw = 0;
876 oper_lr0->type = OPER_RAW;
877 oper_lr0->u.raw = (unsigned long)$2;
878 oper_lr1->type = OPER_RAW;
879 oper_lr1->u.raw = (unsigned long)$4;
880 ol->oper[0] = oper_lr0;
881 ol->oper[1] = oper_zero;
882 ol->oper[2] = oper_lr1;
889 insn_tkiph : OP_TKIPH operlist_2 {
890 struct instruction *insn = xmalloc(sizeof(struct instruction));
891 struct operlist *ol = $2;
892 struct operand *flags = xmalloc(sizeof(struct operand));
893 struct immediate *imm = xmalloc(sizeof(struct immediate));
895 flags->type = OPER_IMM;
897 ol->oper[2] = ol->oper[1];
905 insn_tkiphs : OP_TKIPHS operlist_2 {
906 struct instruction *insn = xmalloc(sizeof(struct instruction));
907 struct operlist *ol = $2;
908 struct operand *flags = xmalloc(sizeof(struct operand));
909 struct immediate *imm = xmalloc(sizeof(struct immediate));
910 imm->imm = 0x1 | 0x2;
911 flags->type = OPER_IMM;
913 ol->oper[2] = ol->oper[1];
921 insn_tkipl : OP_TKIPL operlist_2 {
922 struct instruction *insn = xmalloc(sizeof(struct instruction));
923 struct operlist *ol = $2;
924 struct operand *flags = xmalloc(sizeof(struct operand));
925 struct immediate *imm = xmalloc(sizeof(struct immediate));
927 flags->type = OPER_IMM;
929 ol->oper[2] = ol->oper[1];
937 insn_tkipls : OP_TKIPLS operlist_2 {
938 struct instruction *insn = xmalloc(sizeof(struct instruction));
939 struct operlist *ol = $2;
940 struct operand *flags = xmalloc(sizeof(struct operand));
941 struct immediate *imm = xmalloc(sizeof(struct immediate));
942 imm->imm = 0x0 | 0x2;
943 flags->type = OPER_IMM;
945 ol->oper[2] = ol->oper[1];
954 struct instruction *insn = xmalloc(sizeof(struct instruction));
955 struct operlist *ol = xmalloc(sizeof(struct operlist));
956 struct operand *regop = xmalloc(sizeof(struct operand));
957 struct operand *zeroop = xmalloc(sizeof(struct operand));
958 struct registr *r0 = xmalloc(sizeof(struct registr));
961 regop->type = OPER_REG;
963 zeroop->type = OPER_RAW;
964 zeroop->u.raw = 0x000;
967 ol->oper[2] = zeroop;
974 insn_raw : raw_code operlist_3 {
975 struct instruction *insn = xmalloc(sizeof(struct instruction));
978 insn->opcode = (unsigned long)$1;
983 raw_code : RAW_CODE {
984 yytext++; /* skip @ */
985 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
989 extended_operlist : decnum COMMA decnum COMMA operand COMMA operand COMMA operand {
990 struct operlist *ol = xmalloc(sizeof(struct operlist));
991 struct operand *mask_oper = xmalloc(sizeof(struct operand));
992 struct operand *shift_oper = xmalloc(sizeof(struct operand));
993 mask_oper->type = OPER_RAW;
994 mask_oper->u.raw = (unsigned long)$1;
995 shift_oper->type = OPER_RAW;
996 shift_oper->u.raw = (unsigned long)$3;
997 ol->oper[0] = mask_oper;
998 ol->oper[1] = shift_oper;
1001 ol->oper[4] = store_oper_sanity($9);
1006 external_jump_operands : imm COMMA operand COMMA operand COMMA labelref {
1007 struct operlist *ol = xmalloc(sizeof(struct operlist));
1008 struct operand *cond = xmalloc(sizeof(struct operand));
1009 cond->type = OPER_IMM;
1019 operlist_2 : operand COMMA operand {
1020 struct operlist *ol = xmalloc(sizeof(struct operlist));
1022 ol->oper[1] = store_oper_sanity($3);
1027 operlist_3 : operand COMMA operand COMMA operand {
1028 struct operlist *ol = xmalloc(sizeof(struct operlist));
1031 ol->oper[2] = store_oper_sanity($5);
1037 struct operand *oper = xmalloc(sizeof(struct operand));
1038 oper->type = OPER_REG;
1043 struct operand *oper = xmalloc(sizeof(struct operand));
1044 oper->type = OPER_MEM;
1049 struct operand *oper = xmalloc(sizeof(struct operand));
1050 oper->type = OPER_RAW;
1051 oper->u.raw = (unsigned long)$1;
1055 struct operand *oper = xmalloc(sizeof(struct operand));
1056 oper->type = OPER_IMM;
1066 struct registr *reg = xmalloc(sizeof(struct registr));
1068 reg->nr = (unsigned long)$2;
1072 struct registr *reg = xmalloc(sizeof(struct registr));
1074 yytext += 3; /* skip "spr" */
1075 reg->nr = strtoul(yytext, NULL, 16);
1079 struct registr *reg = xmalloc(sizeof(struct registr));
1081 reg->nr = (unsigned long)$2;
1086 mem : BRACK_OPEN hexnum_decnum BRACK_CLOSE {
1087 struct memory *mem = xmalloc(sizeof(struct memory));
1088 mem->type = MEM_DIRECT;
1089 mem->offset = (unsigned long)$2;
1092 | BRACK_OPEN hexnum_decnum COMMA OFFR regnr BRACK_CLOSE {
1093 struct memory *mem = xmalloc(sizeof(struct memory));
1094 mem->type = MEM_INDIRECT;
1095 mem->offset = (unsigned long)$2;
1096 mem->offr_nr = (unsigned long)$5;
1102 struct immediate *imm = xmalloc(sizeof(struct immediate));
1103 imm->imm = (unsigned long)$1;
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;
1118 complex_imm : PAREN_OPEN complex_imm_arg complex_imm_oper complex_imm_arg PAREN_CLOSE {
1119 unsigned long a = (unsigned long)$2;
1120 unsigned long b = (unsigned long)$4;
1121 unsigned long operation = (unsigned long)$3;
1122 unsigned long res = 31337;
1123 switch (operation) {
1152 yyerror("Internal parser BUG. complex_imm oper unknown");
1156 | PAREN_OPEN complex_imm PAREN_CLOSE {
1159 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1160 unsigned long n = (unsigned long)$3;
1164 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1169 complex_imm_oper : PLUS {
1170 $$ = (void *)(unsigned long)PLUS;
1173 $$ = (void *)(unsigned long)MINUS;
1176 $$ = (void *)(unsigned long)MULTIPLY;
1179 $$ = (void *)(unsigned long)DIVIDE;
1182 $$ = (void *)(unsigned long)BITW_OR;
1185 $$ = (void *)(unsigned long)BITW_AND;
1188 $$ = (void *)(unsigned long)BITW_XOR;
1191 $$ = (void *)(unsigned long)LEFTSHIFT;
1194 $$ = (void *)(unsigned long)RIGHTSHIFT;
1198 complex_imm_arg : complex_imm_const {
1206 complex_imm_const : hexnum_decnum {
1209 | BITW_NOT hexnum_decnum {
1210 unsigned long n = (unsigned long)$2;
1217 while (yytext[0] != 'x') {
1218 if (yytext[0] == '\0')
1219 yyerror("Internal HEXNUM parser error");
1223 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1228 $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1232 hexnum_decnum : hexnum {
1240 labelref : identifier {
1241 struct operand *oper = xmalloc(sizeof(struct operand));
1242 struct label *label = xmalloc(sizeof(struct label));
1244 label->direction = LABELREF_ABSOLUTE;
1245 oper->type = OPER_LABEL;
1246 oper->u.label = label;
1249 | identifier MINUS {
1250 struct operand *oper = xmalloc(sizeof(struct operand));
1251 struct label *label = xmalloc(sizeof(struct label));
1253 label->direction = LABELREF_RELATIVE_BACK;
1254 oper->type = OPER_LABEL;
1255 oper->u.label = label;
1259 struct operand *oper = xmalloc(sizeof(struct operand));
1260 struct label *label = xmalloc(sizeof(struct label));
1262 label->direction = LABELREF_RELATIVE_FORWARD;
1263 oper->type = OPER_LABEL;
1264 oper->u.label = label;
1270 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1274 identifier : IDENT {
1275 $$ = xstrdup(yytext);
1281 int section = SECTION_TEXT; /* default to .text section */
1282 struct initvals_sect *cur_initvals_sect;
1284 void yyerror(char *str)
1289 "Parser ERROR (file \"%s\", line %u, col %u):\n",
1291 cur_lineinfo.lineno,
1292 cur_lineinfo.column);
1293 fprintf(stderr, "%s\n", cur_lineinfo.linecopy);
1294 for (i = 0; i < cur_lineinfo.column - 1; i++)
1295 fprintf(stderr, " ");
1296 fprintf(stderr, "^\n");
1297 fprintf(stderr, "%s\n", str);
1301 static struct operand * store_oper_sanity(struct operand *oper)
1303 if (oper->type == OPER_IMM &&
1304 oper->u.imm->imm != 0) {
1305 yyerror("Only 0x000 Immediate is allowed for "