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);
31 static void assembler_assertion_failed(void);
33 /* The current .section */
35 /* Pointer to the current initvals section data structure. */
36 extern struct initvals_sect *cur_initvals_sect;
40 %token SECTION_TEXT SECTION_IVALS
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
44 %token EQUAL NOT_EQUAL LOGICAL_OR LOGICAL_AND PLUS MINUS MULTIPLY DIVIDE BITW_OR BITW_AND BITW_XOR BITW_NOT LEFTSHIFT RIGHTSHIFT
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
48 %token IVAL_MMIO16 IVAL_MMIO32 IVAL_PHY IVAL_RADIO IVAL_SHM16 IVAL_SHM32
54 line : line_terminator {
57 | line statement line_terminator {
58 struct statement *s = $2;
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);
66 | line section_switch line_terminator {
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);
78 /* Allow terminating lines with the ";" char */
79 line_terminator : /* Nothing */
80 | SEMICOLON line_terminator
83 section_switch : SECTION_TEXT {
84 section = SECTION_TEXT;
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;
95 if (!cur_initvals_sect) {
96 /* Not found, create a new one. */
97 s = xmalloc(sizeof(struct initvals_sect));
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;
104 section = SECTION_IVALS;
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;
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;
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;
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;
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;
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;
155 struct asmdir *ad = $1;
157 struct statement *s = xmalloc(sizeof(struct statement));
158 INIT_LIST_HEAD(&s->list);
159 s->type = STMT_ASMDIR;
166 struct statement *s = xmalloc(sizeof(struct statement));
167 INIT_LIST_HEAD(&s->list);
168 s->type = STMT_LABEL;
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);
495 struct statement *s = xmalloc(sizeof(struct statement));
496 INIT_LIST_HEAD(&s->list);
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;
510 | ASM_START identifier {
511 struct asmdir *ad = xmalloc(sizeof(struct asmdir));
512 struct label *label = xmalloc(sizeof(struct label));
514 label->direction = LABELREF_ABSOLUTE;
515 ad->type = ADIR_START;
519 | ASM_ASSERT assertion {
520 unsigned int ok = (unsigned int)(unsigned long)$2;
522 assembler_assertion_failed();
527 assertion : PAREN_OPEN assert_expr PAREN_CLOSE {
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;
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;
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;
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;
559 struct label *label = xmalloc(sizeof(struct label));
562 l[strlen(l) - 1] = '\0';
569 insn_add : OP_ADD operlist_3 {
570 struct instruction *insn = xmalloc(sizeof(struct instruction));
578 insn_addsc : OP_ADDSC operlist_3 {
579 struct instruction *insn = xmalloc(sizeof(struct instruction));
587 insn_addc : OP_ADDC operlist_3 {
588 struct instruction *insn = xmalloc(sizeof(struct instruction));
596 insn_addscc : OP_ADDSCC operlist_3 {
597 struct instruction *insn = xmalloc(sizeof(struct instruction));
598 insn->op = OP_ADDSCC;
605 insn_sub : OP_SUB operlist_3 {
606 struct instruction *insn = xmalloc(sizeof(struct instruction));
614 insn_subsc : OP_SUBSC operlist_3 {
615 struct instruction *insn = xmalloc(sizeof(struct instruction));
623 insn_subc : OP_SUBC operlist_3 {
624 struct instruction *insn = xmalloc(sizeof(struct instruction));
632 insn_subscc : OP_SUBSCC operlist_3 {
633 struct instruction *insn = xmalloc(sizeof(struct instruction));
634 insn->op = OP_SUBSCC;
640 insn_sra : OP_SRA operlist_3 {
641 struct instruction *insn = xmalloc(sizeof(struct instruction));
648 insn_or : OP_OR operlist_3 {
649 struct instruction *insn = xmalloc(sizeof(struct instruction));
656 insn_and : OP_AND operlist_3 {
657 struct instruction *insn = xmalloc(sizeof(struct instruction));
664 insn_xor : OP_XOR operlist_3 {
665 struct instruction *insn = xmalloc(sizeof(struct instruction));
672 insn_sr : OP_SR operlist_3 {
673 struct instruction *insn = xmalloc(sizeof(struct instruction));
680 insn_srx : OP_SRX extended_operlist {
681 struct instruction *insn = xmalloc(sizeof(struct instruction));
688 insn_sl : OP_SL operlist_3 {
689 struct instruction *insn = xmalloc(sizeof(struct instruction));
696 insn_rl : OP_RL operlist_3 {
697 struct instruction *insn = xmalloc(sizeof(struct instruction));
704 insn_rr : OP_RR operlist_3 {
705 struct instruction *insn = xmalloc(sizeof(struct instruction));
712 insn_nand : OP_NAND operlist_3 {
713 struct instruction *insn = xmalloc(sizeof(struct instruction));
720 insn_orx : OP_ORX extended_operlist {
721 struct instruction *insn = xmalloc(sizeof(struct instruction));
728 insn_mov : OP_MOV operlist_2 {
729 struct instruction *insn = xmalloc(sizeof(struct instruction));
736 insn_jmp : OP_JMP labelref {
737 struct instruction *insn = xmalloc(sizeof(struct instruction));
738 struct operlist *ol = xmalloc(sizeof(struct operlist));
746 insn_jand : OP_JAND operlist_3 {
747 struct instruction *insn = xmalloc(sizeof(struct instruction));
754 insn_jnand : OP_JNAND operlist_3 {
755 struct instruction *insn = xmalloc(sizeof(struct instruction));
762 insn_js : OP_JS operlist_3 {
763 struct instruction *insn = xmalloc(sizeof(struct instruction));
770 insn_jns : OP_JNS operlist_3 {
771 struct instruction *insn = xmalloc(sizeof(struct instruction));
778 insn_je : OP_JE operlist_3 {
779 struct instruction *insn = xmalloc(sizeof(struct instruction));
786 insn_jne : OP_JNE operlist_3 {
787 struct instruction *insn = xmalloc(sizeof(struct instruction));
794 insn_jls : OP_JLS operlist_3 {
795 struct instruction *insn = xmalloc(sizeof(struct instruction));
802 insn_jges : OP_JGES operlist_3 {
803 struct instruction *insn = xmalloc(sizeof(struct instruction));
810 insn_jgs : OP_JGS operlist_3 {
811 struct instruction *insn = xmalloc(sizeof(struct instruction));
818 insn_jles : OP_JLES operlist_3 {
819 struct instruction *insn = xmalloc(sizeof(struct instruction));
826 insn_jl : OP_JL operlist_3 {
827 struct instruction *insn = xmalloc(sizeof(struct instruction));
834 insn_jge : OP_JGE operlist_3 {
835 struct instruction *insn = xmalloc(sizeof(struct instruction));
842 insn_jg : OP_JG operlist_3 {
843 struct instruction *insn = xmalloc(sizeof(struct instruction));
850 insn_jle : OP_JLE operlist_3 {
851 struct instruction *insn = xmalloc(sizeof(struct instruction));
858 insn_jzx : OP_JZX extended_operlist {
859 struct instruction *insn = xmalloc(sizeof(struct instruction));
866 insn_jnzx : OP_JNZX extended_operlist {
867 struct instruction *insn = xmalloc(sizeof(struct instruction));
874 insn_jext : OP_JEXT external_jump_operands {
875 struct instruction *insn = xmalloc(sizeof(struct instruction));
882 insn_jnext : OP_JNEXT external_jump_operands {
883 struct instruction *insn = xmalloc(sizeof(struct instruction));
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;
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;
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));
940 flags->type = OPER_IMM;
942 ol->oper[2] = ol->oper[1];
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;
958 ol->oper[2] = ol->oper[1];
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));
972 flags->type = OPER_IMM;
974 ol->oper[2] = ol->oper[1];
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;
990 ol->oper[2] = ol->oper[1];
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));
1006 regop->type = OPER_REG;
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;
1014 insn->operands = ol;
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;
1028 raw_code : RAW_CODE {
1029 yytext++; /* skip @ */
1030 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
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;
1046 ol->oper[4] = store_oper_sanity($9);
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;
1062 operlist_2 : operand COMMA operand {
1063 struct operlist *ol = xmalloc(sizeof(struct operlist));
1065 ol->oper[1] = store_oper_sanity($3);
1070 operlist_3 : operand COMMA operand COMMA operand {
1071 struct operlist *ol = xmalloc(sizeof(struct operlist));
1074 ol->oper[2] = store_oper_sanity($5);
1080 struct operand *oper = xmalloc(sizeof(struct operand));
1081 oper->type = OPER_REG;
1086 struct operand *oper = xmalloc(sizeof(struct operand));
1087 oper->type = OPER_MEM;
1092 struct operand *oper = xmalloc(sizeof(struct operand));
1093 oper->type = OPER_RAW;
1094 oper->u.raw = (unsigned long)$1;
1098 struct operand *oper = xmalloc(sizeof(struct operand));
1099 oper->type = OPER_IMM;
1109 struct registr *reg = xmalloc(sizeof(struct registr));
1111 reg->nr = (unsigned long)$2;
1115 struct registr *reg = xmalloc(sizeof(struct registr));
1117 yytext += 3; /* skip "spr" */
1118 reg->nr = strtoul(yytext, NULL, 16);
1122 struct registr *reg = xmalloc(sizeof(struct registr));
1124 reg->nr = (unsigned long)$2;
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;
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;
1143 mem->offr_nr = (unsigned long)$5;
1149 struct immediate *imm = xmalloc(sizeof(struct immediate));
1150 imm->imm = (unsigned long)$1;
1155 imm_value : hexnum_decnum {
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) {
1197 yyerror("Internal parser BUG. complex_imm oper unknown");
1201 | PAREN_OPEN complex_imm PAREN_CLOSE {
1204 | PAREN_OPEN BITW_NOT complex_imm PAREN_CLOSE {
1205 unsigned long n = (unsigned long)$3;
1209 | PAREN_OPEN complex_imm_const PAREN_CLOSE {
1214 complex_imm_oper : PLUS {
1215 $$ = (void *)(unsigned long)PLUS;
1218 $$ = (void *)(unsigned long)MINUS;
1221 $$ = (void *)(unsigned long)MULTIPLY;
1224 $$ = (void *)(unsigned long)DIVIDE;
1227 $$ = (void *)(unsigned long)BITW_OR;
1230 $$ = (void *)(unsigned long)BITW_AND;
1233 $$ = (void *)(unsigned long)BITW_XOR;
1236 $$ = (void *)(unsigned long)LEFTSHIFT;
1239 $$ = (void *)(unsigned long)RIGHTSHIFT;
1243 complex_imm_arg : complex_imm_const {
1251 complex_imm_const : hexnum_decnum {
1254 | BITW_NOT hexnum_decnum {
1255 unsigned long n = (unsigned long)$2;
1262 while (yytext[0] != 'x') {
1263 if (yytext[0] == '\0')
1264 yyerror("Internal HEXNUM parser error");
1268 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 16);
1273 $$ = (void *)(unsigned long)strtol(yytext, NULL, 10);
1277 hexnum_decnum : hexnum {
1285 labelref : identifier {
1286 struct operand *oper = xmalloc(sizeof(struct operand));
1287 struct label *label = xmalloc(sizeof(struct label));
1289 label->direction = LABELREF_ABSOLUTE;
1290 oper->type = OPER_LABEL;
1291 oper->u.label = label;
1294 | identifier MINUS {
1295 struct operand *oper = xmalloc(sizeof(struct operand));
1296 struct label *label = xmalloc(sizeof(struct label));
1298 label->direction = LABELREF_RELATIVE_BACK;
1299 oper->type = OPER_LABEL;
1300 oper->u.label = label;
1304 struct operand *oper = xmalloc(sizeof(struct operand));
1305 struct label *label = xmalloc(sizeof(struct label));
1307 label->direction = LABELREF_RELATIVE_FORWARD;
1308 oper->type = OPER_LABEL;
1309 oper->u.label = label;
1315 $$ = (void *)(unsigned long)strtoul(yytext, NULL, 10);
1319 identifier : IDENT {
1320 $$ = xstrdup(yytext);
1326 int section = SECTION_TEXT; /* default to .text section */
1327 struct initvals_sect *cur_initvals_sect;
1329 void yyerror(char *str)
1334 "Parser ERROR (file \"%s\", line %u, col %u):\n",
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);
1346 static struct operand * store_oper_sanity(struct operand *oper)
1348 if (oper->type == OPER_IMM &&
1349 oper->u.imm->imm != 0) {
1350 yyerror("Only 0x000 Immediate is allowed for "
1356 static void assembler_assertion_failed(void)
1358 yyerror("Assembler %assert failed");