3 * Parser for the Aic7xxx SCSI Host adapter sequencer assembler.
5 * Copyright (c) 1997-1998 Justin T. Gibbs.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions, and the following disclaimer,
13 * without modification, immediately at the beginning of the file.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/types.h>
38 #include <sys/queue.h>
41 #include "aicasm_symbol.h"
42 #include "sequencer.h"
46 static symbol_t *cur_symbol;
47 static symtype cur_symtype;
48 static symbol_t *accumulator;
49 static symbol_ref_t allones;
50 static symbol_ref_t allzeros;
51 static symbol_ref_t none;
52 static symbol_ref_t sindex;
53 static int instruction_ptr;
54 static int sram_or_scb_offset;
55 static int download_constant_count;
57 static void process_bitmask __P((int mask_type, symbol_t *sym, int mask));
58 static void initialize_symbol __P((symbol_t *symbol));
59 static void process_register __P((symbol_t **p_symbol));
60 static void format_1_instr __P((int opcode, symbol_ref_t *dest,
61 expression_t *immed, symbol_ref_t *src,
63 static void format_2_instr __P((int opcode, symbol_ref_t *dest,
64 expression_t *places, symbol_ref_t *src,
66 static void format_3_instr __P((int opcode, symbol_ref_t *src,
67 expression_t *immed, symbol_ref_t *address));
68 static void test_readable_symbol __P((symbol_t *symbol));
69 static void test_writable_symbol __P((symbol_t *symbol));
70 static void type_check __P((symbol_t *symbol, expression_t *expression,
72 static void make_expression __P((expression_t *immed, int value));
73 static void add_conditional __P((symbol_t *symbol));
74 static int is_download_const __P((expression_t *immed));
77 #define SRAM_SYMNAME "SRAM_BASE"
78 #define SCB_SYMNAME "SCB_BASE"
86 expression_t expression;
91 %token <value> T_CONST
103 %token <value> T_ADDRESS
107 %token <value> T_MODE
113 %token <value> T_NUMBER
119 %token T_EOF T_INCLUDE
121 %token <value> T_SHR T_SHL T_ROR T_ROL
123 %token <value> T_MVI T_MOV T_CLR T_BMOV
125 %token <value> T_JMP T_JC T_JNC T_JE T_JNE T_JNZ T_JZ T_CALL
127 %token <value> T_ADD T_ADC
129 %token <value> T_INC T_DEC
131 %token <value> T_STC T_CLC
133 %token <value> T_CMP T_XOR
135 %token <value> T_TEST T_AND
143 %token T_ACCUM T_ALLONES T_ALLZEROS T_NONE T_SINDEX
147 %token <sym> T_SYMBOL
151 %token T_IF T_ELSE T_ELSE_IF T_ENDIF
153 %type <sym_ref> reg_symbol address destination source opt_source
155 %type <expression> expression immediate immediate_or_a
157 %type <value> ret f1_opcode f2_opcode jmp_jc_jnc_call jz_jnz je_jne
159 %type <value> numerical_value
176 | program scratch_ram
182 | program conditional
188 T_INCLUDE '<' T_PATH '>'
189 { include_file($3, BRACKETED_INCLUDE); }
190 | T_INCLUDE '"' T_PATH '"'
191 { include_file($3, QUOTED_INCLUDE); }
195 T_REGISTER { cur_symtype = REGISTER; } reg_definition
201 if ($1->type != UNINITIALIZED) {
202 stop("Register multiply defined", EX_DATAERR);
206 cur_symbol->type = cur_symtype;
207 initialize_symbol(cur_symbol);
213 * Default to allowing everything in for registers
214 * with no bit or mask definitions.
216 if (cur_symbol->info.rinfo->valid_bitmask == 0)
217 cur_symbol->info.rinfo->valid_bitmask = 0xFF;
219 if (cur_symbol->info.rinfo->size == 0)
220 cur_symbol->info.rinfo->size = 1;
223 * This might be useful for registers too.
225 if (cur_symbol->type != REGISTER) {
226 if (cur_symbol->info.rinfo->address == 0)
227 cur_symbol->info.rinfo->address =
229 sram_or_scb_offset +=
230 cur_symbol->info.rinfo->size;
238 | reg_attribute_list reg_attribute
258 cur_symbol->info.rinfo->address = $2;
265 cur_symbol->info.rinfo->size = $2;
272 cur_symbol->info.rinfo->mode = $2;
277 T_BIT T_SYMBOL T_NUMBER
279 process_bitmask(BIT, $2, $3);
284 T_MASK T_SYMBOL expression
286 process_bitmask(MASK, $2, $3.value);
293 if ($2->type != UNINITIALIZED) {
294 stop("Re-definition of register alias",
299 initialize_symbol($2);
300 $2->info.ainfo->parent = cur_symbol;
307 if (accumulator != NULL) {
308 stop("Only one accumulator definition allowed",
312 accumulator = cur_symbol;
319 if (allones.symbol != NULL) {
320 stop("Only one definition of allones allowed",
324 allones.symbol = cur_symbol;
331 if (allzeros.symbol != NULL) {
332 stop("Only one definition of allzeros allowed",
336 allzeros.symbol = cur_symbol;
343 if (none.symbol != NULL) {
344 stop("Only one definition of none allowed",
348 none.symbol = cur_symbol;
355 if (sindex.symbol != NULL) {
356 stop("Only one definition of sindex allowed",
360 sindex.symbol = cur_symbol;
365 expression '|' expression
367 $$.value = $1.value | $3.value;
368 symlist_merge(&$$.referenced_syms,
370 &$3.referenced_syms);
372 | expression '&' expression
374 $$.value = $1.value & $3.value;
375 symlist_merge(&$$.referenced_syms,
377 &$3.referenced_syms);
379 | expression '+' expression
381 $$.value = $1.value + $3.value;
382 symlist_merge(&$$.referenced_syms,
384 &$3.referenced_syms);
386 | expression '-' expression
388 $$.value = $1.value - $3.value;
389 symlist_merge(&($$.referenced_syms),
390 &($1.referenced_syms),
391 &($3.referenced_syms));
400 $$.value = (~$$.value) & 0xFF;
402 | '-' expression %prec UMINUS
405 $$.value = -$$.value;
410 SLIST_INIT(&$$.referenced_syms);
417 switch (symbol->type) {
419 symbol = $1->info.ainfo->parent;
423 $$.value = symbol->info.rinfo->address;
427 $$.value = symbol->info.minfo->mask;
431 $$.value = symbol->info.cinfo->value;
438 snprintf(buf, sizeof(buf),
439 "Undefined symbol %s referenced",
441 stop(buf, EX_DATAERR);
446 SLIST_INIT(&$$.referenced_syms);
447 symlist_add(&$$.referenced_syms, symbol, SYMLIST_INSERT_HEAD);
452 T_CONST T_SYMBOL numerical_value
454 if ($2->type != UNINITIALIZED) {
455 stop("Re-definition of symbol as a constant",
460 initialize_symbol($2);
461 $2->info.cinfo->value = $3;
462 $2->info.cinfo->define = $1;
464 | T_CONST T_SYMBOL T_DOWNLOAD
467 stop("Invalid downloaded constant declaration",
471 if ($2->type != UNINITIALIZED) {
472 stop("Re-definition of symbol as a downloaded constant",
476 $2->type = DOWNLOAD_CONST;
477 initialize_symbol($2);
478 $2->info.cinfo->value = download_constant_count++;
479 $2->info.cinfo->define = FALSE;
497 cur_symbol = symtable_get(SRAM_SYMNAME);
498 cur_symtype = SRAMLOC;
499 if (cur_symbol->type != UNINITIALIZED) {
500 stop("Only one SRAM definition allowed",
504 cur_symbol->type = SRAMLOC;
505 initialize_symbol(cur_symbol);
509 sram_or_scb_offset = cur_symbol->info.rinfo->address;
521 cur_symbol = symtable_get(SCB_SYMNAME);
522 cur_symtype = SCBLOC;
523 if (cur_symbol->type != UNINITIALIZED) {
524 stop("Only one SRAM definition allowed",
528 cur_symbol->type = SCBLOC;
529 initialize_symbol(cur_symbol);
533 sram_or_scb_offset = cur_symbol->info.rinfo->address;
542 scb_or_sram_reg_list:
544 | scb_or_sram_reg_list reg_definition
550 process_register(&$1);
554 | T_SYMBOL '[' T_NUMBER ']'
556 process_register(&$1);
557 if (($3 + 1) > $1->info.rinfo->size) {
558 stop("Accessing offset beyond range of register",
567 if (accumulator == NULL) {
568 stop("No accumulator has been defined", EX_DATAERR);
571 $$.symbol = accumulator;
579 test_writable_symbol($1.symbol);
596 SLIST_INIT(&$$.referenced_syms);
604 test_readable_symbol($1.symbol);
627 if ($1->type != UNINITIALIZED) {
628 stop("Program label multiply defined", EX_DATAERR);
632 initialize_symbol($1);
633 $1->info.linfo->address = instruction_ptr;
643 | T_SYMBOL '+' T_NUMBER
648 | T_SYMBOL '-' T_NUMBER
676 new_scope = scope_alloc();
677 new_scope->type = SCOPE_IF;
678 new_scope->begin_addr = instruction_ptr;
679 new_scope->func_num = $2->info.condinfo->func_num;
681 | T_ELSE T_IF T_CEXPR '{'
684 scope_t *scope_context;
688 * Ensure that the previous scope is either an
691 scope_context = SLIST_FIRST(&scope_stack);
692 last_scope = TAILQ_LAST(&scope_context->inner_scope,
694 if (last_scope == NULL
695 || last_scope->type == T_ELSE) {
697 stop("'else if' without leading 'if'", EX_DATAERR);
701 new_scope = scope_alloc();
702 new_scope->type = SCOPE_ELSE_IF;
703 new_scope->begin_addr = instruction_ptr;
704 new_scope->func_num = $3->info.condinfo->func_num;
709 scope_t *scope_context;
713 * Ensure that the previous scope is either an
716 scope_context = SLIST_FIRST(&scope_stack);
717 last_scope = TAILQ_LAST(&scope_context->inner_scope,
719 if (last_scope == NULL
720 || last_scope->type == SCOPE_ELSE) {
722 stop("'else' without leading 'if'", EX_DATAERR);
725 new_scope = scope_alloc();
726 new_scope->type = SCOPE_ELSE;
727 new_scope->begin_addr = instruction_ptr;
734 scope_t *scope_context;
737 scope_context = SLIST_FIRST(&scope_stack);
738 if (scope_context->type == SCOPE_ROOT) {
739 stop("Unexpected '}' encountered", EX_DATAERR);
743 scope_context->end_addr = instruction_ptr;
746 SLIST_REMOVE_HEAD(&scope_stack, scope_stack_links);
748 process_scope(scope_context);
750 if (SLIST_FIRST(&scope_stack) == NULL) {
751 stop("Unexpected '}' encountered", EX_DATAERR);
758 T_AND { $$ = AIC_OP_AND; }
759 | T_XOR { $$ = AIC_OP_XOR; }
760 | T_ADD { $$ = AIC_OP_ADD; }
761 | T_ADC { $$ = AIC_OP_ADC; }
765 f1_opcode destination ',' immediate_or_a opt_source ret ';'
767 format_1_instr($1, &$2, &$4, &$5, $6);
772 T_OR reg_symbol ',' immediate_or_a opt_source ret ';'
774 format_1_instr(AIC_OP_OR, &$2, &$4, &$5, $6);
779 T_INC destination opt_source ret ';'
783 make_expression(&immed, 1);
784 format_1_instr(AIC_OP_ADD, &$2, &immed, &$3, $4);
789 T_DEC destination opt_source ret ';'
793 make_expression(&immed, -1);
794 format_1_instr(AIC_OP_ADD, &$2, &immed, &$3, $4);
803 make_expression(&immed, -1);
804 format_1_instr(AIC_OP_ADD, &none, &immed, &allzeros, $2);
806 | T_CLC T_MVI destination ',' immediate_or_a ret ';'
808 format_1_instr(AIC_OP_ADD, &$3, &$5, &allzeros, $6);
817 make_expression(&immed, 1);
818 format_1_instr(AIC_OP_ADD, &none, &immed, &allones, $2);
820 | T_STC destination ret ';'
824 make_expression(&immed, 1);
825 format_1_instr(AIC_OP_ADD, &$2, &immed, &allones, $3);
830 T_BMOV destination ',' source ',' immediate ret ';'
832 format_1_instr(AIC_OP_BMOV, &$2, &$6, &$4, $7);
837 T_MOV destination ',' source ret ';'
841 make_expression(&immed, 0xff);
842 format_1_instr(AIC_OP_AND, &$2, &immed, &$4, $5);
847 T_MVI destination ',' immediate_or_a ret ';'
849 format_1_instr(AIC_OP_OR, &$2, &$4, &allzeros, $5);
854 T_CLR destination ret ';'
858 make_expression(&immed, 0xff);
859 format_1_instr(AIC_OP_AND, &$2, &immed, &allzeros, $3);
868 make_expression(&immed, 0xff);
869 format_1_instr(AIC_OP_AND, &none, &immed, &allzeros, $2);
878 make_expression(&immed, 0xff);
879 format_1_instr(AIC_OP_AND, &none, &immed, &allzeros, TRUE);
884 * This grammer differs from the one in the aic7xxx
885 * reference manual since the grammer listed there is
886 * ambiguous and causes a shift/reduce conflict.
887 * It also seems more logical as the "immediate"
888 * argument is listed as the second arg like the
893 T_SHL { $$ = AIC_OP_SHL; }
894 | T_SHR { $$ = AIC_OP_SHR; }
895 | T_ROL { $$ = AIC_OP_ROL; }
896 | T_ROR { $$ = AIC_OP_ROR; }
900 f2_opcode destination ',' expression opt_source ret ';'
902 format_2_instr($1, &$2, &$4, &$5, $6);
907 T_JMP { $$ = AIC_OP_JMP; }
908 | T_JC { $$ = AIC_OP_JC; }
909 | T_JNC { $$ = AIC_OP_JNC; }
910 | T_CALL { $$ = AIC_OP_CALL; }
914 T_JZ { $$ = AIC_OP_JZ; }
915 | T_JNZ { $$ = AIC_OP_JNZ; }
919 T_JE { $$ = AIC_OP_JE; }
920 | T_JNE { $$ = AIC_OP_JNE; }
924 jmp_jc_jnc_call address ';'
928 make_expression(&immed, 0);
929 format_3_instr($1, &sindex, &immed, &$2);
934 T_OR reg_symbol ',' immediate jmp_jc_jnc_call address ';'
936 format_3_instr($5, &$2, &$4, &$6);
941 T_TEST source ',' immediate_or_a jz_jnz address ';'
943 format_3_instr($5, &$2, &$4, &$6);
948 T_CMP source ',' immediate_or_a je_jne address ';'
950 format_3_instr($5, &$2, &$4, &$6);
955 T_MOV source jmp_jc_jnc_call address ';'
959 make_expression(&immed, 0);
960 format_3_instr($3, &$2, &immed, &$4);
965 T_MVI immediate jmp_jc_jnc_call address ';'
967 format_3_instr($3, &allzeros, &$2, &$4);
974 process_bitmask(mask_type, sym, mask)
980 * Add the current register to its
981 * symbol list, if it already exists,
982 * warn if we are setting it to a
983 * different value, or in the bit to
984 * the "allowed bits" of this register.
986 if (sym->type == UNINITIALIZED) {
987 sym->type = mask_type;
988 initialize_symbol(sym);
989 if (mask_type == BIT) {
991 stop("Bitmask with no bits set", EX_DATAERR);
994 if ((mask & ~(0x01 << (ffs(mask) - 1))) != 0) {
995 stop("Bitmask with more than one bit set",
1000 sym->info.minfo->mask = mask;
1001 } else if (sym->type != mask_type) {
1002 stop("Bit definition mirrors a definition of the same "
1003 " name, but a different type", EX_DATAERR);
1005 } else if (mask != sym->info.minfo->mask) {
1006 stop("Bitmask redefined with a conflicting value", EX_DATAERR);
1009 /* Fail if this symbol is already listed */
1010 if (symlist_search(&(sym->info.minfo->symrefs),
1011 cur_symbol->name) != NULL) {
1012 stop("Bitmask defined multiple times for register", EX_DATAERR);
1015 symlist_add(&(sym->info.minfo->symrefs), cur_symbol,
1016 SYMLIST_INSERT_HEAD);
1017 cur_symbol->info.rinfo->valid_bitmask |= mask;
1018 cur_symbol->info.rinfo->typecheck_masks = TRUE;
1022 initialize_symbol(symbol)
1025 switch (symbol->type) {
1027 stop("Call to initialize_symbol with type field unset",
1034 symbol->info.rinfo =
1035 (struct reg_info *)malloc(sizeof(struct reg_info));
1036 if (symbol->info.rinfo == NULL) {
1037 stop("Can't create register info", EX_SOFTWARE);
1040 memset(symbol->info.rinfo, 0,
1041 sizeof(struct reg_info));
1044 symbol->info.ainfo =
1045 (struct alias_info *)malloc(sizeof(struct alias_info));
1046 if (symbol->info.ainfo == NULL) {
1047 stop("Can't create alias info", EX_SOFTWARE);
1050 memset(symbol->info.ainfo, 0,
1051 sizeof(struct alias_info));
1055 symbol->info.minfo =
1056 (struct mask_info *)malloc(sizeof(struct mask_info));
1057 if (symbol->info.minfo == NULL) {
1058 stop("Can't create bitmask info", EX_SOFTWARE);
1061 memset(symbol->info.minfo, 0, sizeof(struct mask_info));
1062 SLIST_INIT(&(symbol->info.minfo->symrefs));
1065 case DOWNLOAD_CONST:
1066 symbol->info.cinfo =
1067 (struct const_info *)malloc(sizeof(struct const_info));
1068 if (symbol->info.cinfo == NULL) {
1069 stop("Can't create alias info", EX_SOFTWARE);
1072 memset(symbol->info.cinfo, 0,
1073 sizeof(struct const_info));
1076 symbol->info.linfo =
1077 (struct label_info *)malloc(sizeof(struct label_info));
1078 if (symbol->info.linfo == NULL) {
1079 stop("Can't create label info", EX_SOFTWARE);
1082 memset(symbol->info.linfo, 0,
1083 sizeof(struct label_info));
1086 symbol->info.condinfo =
1087 (struct cond_info *)malloc(sizeof(struct cond_info));
1088 if (symbol->info.condinfo == NULL) {
1089 stop("Can't create conditional info", EX_SOFTWARE);
1092 memset(symbol->info.condinfo, 0,
1093 sizeof(struct cond_info));
1096 stop("Call to initialize_symbol with invalid symbol type",
1104 process_register(p_symbol)
1105 symbol_t **p_symbol;
1108 symbol_t *symbol = *p_symbol;
1110 if (symbol->type == UNINITIALIZED) {
1111 snprintf(buf, sizeof(buf), "Undefined register %s",
1113 stop(buf, EX_DATAERR);
1115 } else if (symbol->type == ALIAS) {
1116 *p_symbol = symbol->info.ainfo->parent;
1117 } else if ((symbol->type != REGISTER)
1118 && (symbol->type != SCBLOC)
1119 && (symbol->type != SRAMLOC)) {
1120 snprintf(buf, sizeof(buf),
1121 "Specified symbol %s is not a register",
1123 stop(buf, EX_DATAERR);
1128 format_1_instr(opcode, dest, immed, src, ret)
1131 expression_t *immed;
1135 struct instruction *instr;
1136 struct ins_format1 *f1_instr;
1138 if (src->symbol == NULL)
1141 /* Test register permissions */
1142 test_writable_symbol(dest->symbol);
1143 test_readable_symbol(src->symbol);
1145 /* Ensure that immediate makes sense for this destination */
1146 type_check(dest->symbol, immed, opcode);
1148 /* Allocate sequencer space for the instruction and fill it out */
1149 instr = seq_alloc();
1150 f1_instr = &instr->format.format1;
1151 f1_instr->ret = ret ? 1 : 0;
1152 f1_instr->opcode = opcode;
1153 f1_instr->destination = dest->symbol->info.rinfo->address
1155 f1_instr->source = src->symbol->info.rinfo->address
1157 f1_instr->immediate = immed->value;
1159 if (is_download_const(immed))
1160 f1_instr->parity = 1;
1162 symlist_free(&immed->referenced_syms);
1167 format_2_instr(opcode, dest, places, src, ret)
1170 expression_t *places;
1174 struct instruction *instr;
1175 struct ins_format2 *f2_instr;
1176 u_int8_t shift_control;
1178 if (src->symbol == NULL)
1181 /* Test register permissions */
1182 test_writable_symbol(dest->symbol);
1183 test_readable_symbol(src->symbol);
1185 /* Allocate sequencer space for the instruction and fill it out */
1186 instr = seq_alloc();
1187 f2_instr = &instr->format.format2;
1188 f2_instr->ret = ret ? 1 : 0;
1189 f2_instr->opcode = AIC_OP_ROL;
1190 f2_instr->destination = dest->symbol->info.rinfo->address
1192 f2_instr->source = src->symbol->info.rinfo->address
1194 if (places->value > 8 || places->value <= 0) {
1195 stop("illegal shift value", EX_DATAERR);
1200 if (places->value == 8)
1201 shift_control = 0xf0;
1203 shift_control = (places->value << 4) | places->value;
1206 if (places->value == 8) {
1207 shift_control = 0xf8;
1209 shift_control = (places->value << 4)
1210 | (8 - places->value)
1215 shift_control = places->value & 0x7;
1218 shift_control = (8 - places->value) | 0x08;
1221 shift_control = 0; /* Quiet Compiler */
1222 stop("Invalid shift operation specified", EX_SOFTWARE);
1226 f2_instr->shift_control = shift_control;
1227 symlist_free(&places->referenced_syms);
1232 format_3_instr(opcode, src, immed, address)
1235 expression_t *immed;
1236 symbol_ref_t *address;
1238 struct instruction *instr;
1239 struct ins_format3 *f3_instr;
1242 /* Test register permissions */
1243 test_readable_symbol(src->symbol);
1245 /* Ensure that immediate makes sense for this source */
1246 type_check(src->symbol, immed, opcode);
1248 /* Allocate sequencer space for the instruction and fill it out */
1249 instr = seq_alloc();
1250 f3_instr = &instr->format.format3;
1251 if (address->symbol == NULL) {
1252 /* 'dot' referrence. Use the current instruction pointer */
1253 addr = instruction_ptr + address->offset;
1254 } else if (address->symbol->type == UNINITIALIZED) {
1255 /* forward reference */
1256 addr = address->offset;
1257 instr->patch_label = address->symbol;
1259 addr = address->symbol->info.linfo->address + address->offset;
1260 f3_instr->opcode = opcode;
1261 f3_instr->address = addr;
1262 f3_instr->source = src->symbol->info.rinfo->address
1264 f3_instr->immediate = immed->value;
1266 if (is_download_const(immed))
1267 f3_instr->parity = 1;
1269 symlist_free(&immed->referenced_syms);
1274 test_readable_symbol(symbol)
1277 if (symbol->info.rinfo->mode == WO) {
1278 stop("Write Only register specified as source",
1285 test_writable_symbol(symbol)
1288 if (symbol->info.rinfo->mode == RO) {
1289 stop("Read Only register specified as destination",
1296 type_check(symbol, expression, opcode)
1298 expression_t *expression;
1301 symbol_node_t *node;
1306 if (opcode == AIC_OP_AND || opcode == AIC_OP_JNZ || AIC_OP_JZ)
1310 * Make sure that we aren't attempting to write something
1311 * that hasn't been defined. If this is an and operation,
1312 * this is a mask, so "undefined" bits are okay.
1315 && (expression->value & ~symbol->info.rinfo->valid_bitmask) != 0) {
1316 snprintf(buf, sizeof(buf),
1317 "Invalid bit(s) 0x%x in immediate written to %s",
1318 expression->value & ~symbol->info.rinfo->valid_bitmask,
1320 stop(buf, EX_DATAERR);
1325 * Now make sure that all of the symbols referenced by the
1326 * expression are defined for this register.
1328 if(symbol->info.rinfo->typecheck_masks != FALSE) {
1329 for(node = expression->referenced_syms.slh_first;
1331 node = node->links.sle_next) {
1332 if ((node->symbol->type == MASK
1333 || node->symbol->type == BIT)
1334 && symlist_search(&node->symbol->info.minfo->symrefs,
1335 symbol->name) == NULL) {
1336 snprintf(buf, sizeof(buf),
1337 "Invalid bit or mask %s "
1339 node->symbol->name, symbol->name);
1340 stop(buf, EX_DATAERR);
1348 make_expression(immed, value)
1349 expression_t *immed;
1352 SLIST_INIT(&immed->referenced_syms);
1353 immed->value = value & 0xff;
1357 add_conditional(symbol)
1360 static int numfuncs;
1362 if (numfuncs == 0) {
1363 /* add a special conditional, "0" */
1364 symbol_t *false_func;
1366 false_func = symtable_get("0");
1367 if (false_func->type != UNINITIALIZED) {
1368 stop("Conditional expression '0' "
1369 "conflicts with a symbol", EX_DATAERR);
1372 false_func->type = CONDITIONAL;
1373 initialize_symbol(false_func);
1374 false_func->info.condinfo->func_num = numfuncs++;
1375 symlist_add(&patch_functions, false_func, SYMLIST_INSERT_HEAD);
1378 /* This condition has occurred before */
1379 if (symbol->type == CONDITIONAL)
1382 if (symbol->type != UNINITIALIZED) {
1383 stop("Conditional expression conflicts with a symbol",
1388 symbol->type = CONDITIONAL;
1389 initialize_symbol(symbol);
1390 symbol->info.condinfo->func_num = numfuncs++;
1391 symlist_add(&patch_functions, symbol, SYMLIST_INSERT_HEAD);
1398 stop(string, EX_DATAERR);
1402 is_download_const(immed)
1403 expression_t *immed;
1405 if ((immed->referenced_syms.slh_first != NULL)
1406 && (immed->referenced_syms.slh_first->symbol->type == DOWNLOAD_CONST))