aicasm_gram.y (29050) | aicasm_gram.y (29897) |
---|---|
1%{ 2/* 3 * Parser for the Aic7xxx SCSI Host adapter sequencer assembler. 4 * 5 * Copyright (c) 1997 Justin T. Gibbs. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * | 1%{ 2/* 3 * Parser for the Aic7xxx SCSI Host adapter sequencer assembler. 4 * 5 * Copyright (c) 1997 Justin T. Gibbs. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 15 unchanged lines hidden (view full) --- 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
32 * $Id: aicasm_gram.y,v 1.2 1997/06/27 19:38:49 gibbs Exp $ | 32 * $Id: aicasm_gram.y,v 1.3 1997/09/03 03:44:40 gibbs Exp $ |
33 */ 34 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <sysexits.h> 39 40#include <sys/types.h> --- 9 unchanged lines hidden (view full) --- 50static symtype cur_symtype; 51static symbol_t *accumulator; 52static symbol_ref_t allones; 53static symbol_ref_t allzeros; 54static symbol_ref_t none; 55static symbol_ref_t sindex; 56static int instruction_ptr; 57static int sram_or_scb_offset; | 33 */ 34 35#include <stdio.h> 36#include <stdlib.h> 37#include <string.h> 38#include <sysexits.h> 39 40#include <sys/types.h> --- 9 unchanged lines hidden (view full) --- 50static symtype cur_symtype; 51static symbol_t *accumulator; 52static symbol_ref_t allones; 53static symbol_ref_t allzeros; 54static symbol_ref_t none; 55static symbol_ref_t sindex; 56static int instruction_ptr; 57static int sram_or_scb_offset; |
58static int download_constant_count; |
|
58static patch_t *cur_patch; 59 60static void process_bitmask __P((int mask_type, symbol_t *sym, int mask)); 61static void initialize_symbol __P((symbol_t *symbol)); 62static void process_register __P((symbol_t **p_symbol)); 63static void format_1_instr __P((int opcode, symbol_ref_t *dest, 64 expression_t *immed, symbol_ref_t *src, 65 int ret)); 66static void format_2_instr __P((int opcode, symbol_ref_t *dest, 67 expression_t *places, symbol_ref_t *src, 68 int ret)); 69static void format_3_instr __P((int opcode, symbol_ref_t *src, 70 expression_t *immed, symbol_ref_t *address)); 71static void test_readable_symbol __P((symbol_t *symbol)); 72static void test_writable_symbol __P((symbol_t *symbol)); 73static void type_check __P((symbol_t *symbol, expression_t *expression, 74 int and_op)); 75static void make_expression __P((expression_t *immed, int value)); 76static void add_conditional __P((symbol_t *symbol)); | 59static patch_t *cur_patch; 60 61static void process_bitmask __P((int mask_type, symbol_t *sym, int mask)); 62static void initialize_symbol __P((symbol_t *symbol)); 63static void process_register __P((symbol_t **p_symbol)); 64static void format_1_instr __P((int opcode, symbol_ref_t *dest, 65 expression_t *immed, symbol_ref_t *src, 66 int ret)); 67static void format_2_instr __P((int opcode, symbol_ref_t *dest, 68 expression_t *places, symbol_ref_t *src, 69 int ret)); 70static void format_3_instr __P((int opcode, symbol_ref_t *src, 71 expression_t *immed, symbol_ref_t *address)); 72static void test_readable_symbol __P((symbol_t *symbol)); 73static void test_writable_symbol __P((symbol_t *symbol)); 74static void type_check __P((symbol_t *symbol, expression_t *expression, 75 int and_op)); 76static void make_expression __P((expression_t *immed, int value)); 77static void add_conditional __P((symbol_t *symbol)); |
78static int is_download_const __P((expression_t *immed)); |
|
77 78#define YYDEBUG 1 79#define SRAM_SYMNAME "SRAM_BASE" 80#define SCB_SYMNAME "SCB_BASE" 81%} 82 83%union { 84 int value; 85 char *str; 86 symbol_t *sym; 87 symbol_ref_t sym_ref; 88 expression_t expression; 89} 90 91%token T_REGISTER 92 93%token <value> T_CONST 94 | 79 80#define YYDEBUG 1 81#define SRAM_SYMNAME "SRAM_BASE" 82#define SCB_SYMNAME "SCB_BASE" 83%} 84 85%union { 86 int value; 87 char *str; 88 symbol_t *sym; 89 symbol_ref_t sym_ref; 90 expression_t expression; 91} 92 93%token T_REGISTER 94 95%token <value> T_CONST 96 |
97%token T_DOWNLOAD 98 |
|
95%token T_SCB 96 97%token T_SRAM 98 99%token T_ALIAS 100 101%token T_SIZE 102 --- 46 unchanged lines hidden (view full) --- 149%token T_IF T_ELSE T_ENDIF 150 151%type <sym_ref> reg_symbol address destination source opt_source 152 153%type <expression> expression immediate immediate_or_a 154 155%type <value> ret f1_opcode f2_opcode jmp_jc_jnc_call jz_jnz je_jne 156 | 99%token T_SCB 100 101%token T_SRAM 102 103%token T_ALIAS 104 105%token T_SIZE 106 --- 46 unchanged lines hidden (view full) --- 153%token T_IF T_ELSE T_ENDIF 154 155%type <sym_ref> reg_symbol address destination source opt_source 156 157%type <expression> expression immediate immediate_or_a 158 159%type <value> ret f1_opcode f2_opcode jmp_jc_jnc_call jz_jnz je_jne 160 |
161%type <value> numerical_value 162 |
|
157%left '|' 158%left '&' 159%left '+' '-' 160%right '~' 161%nonassoc UMINUS 162%% 163 164program: --- 252 unchanged lines hidden (view full) --- 417 case SCBLOC: 418 case SRAMLOC: 419 $$.value = symbol->info.rinfo->address; 420 break; 421 case MASK: 422 case BIT: 423 $$.value = symbol->info.minfo->mask; 424 break; | 163%left '|' 164%left '&' 165%left '+' '-' 166%right '~' 167%nonassoc UMINUS 168%% 169 170program: --- 252 unchanged lines hidden (view full) --- 423 case SCBLOC: 424 case SRAMLOC: 425 $$.value = symbol->info.rinfo->address; 426 break; 427 case MASK: 428 case BIT: 429 $$.value = symbol->info.minfo->mask; 430 break; |
431 case DOWNLOAD_CONST: |
|
425 case CONST: 426 $$.value = symbol->info.cinfo->value; 427 break; 428 case UNINITIALIZED: 429 default: 430 { 431 char buf[255]; 432 --- 6 unchanged lines hidden (view full) --- 439 } 440 } 441 SLIST_INIT(&$$.referenced_syms); 442 symlist_add(&$$.referenced_syms, symbol, SYMLIST_INSERT_HEAD); 443 } 444; 445 446constant: | 432 case CONST: 433 $$.value = symbol->info.cinfo->value; 434 break; 435 case UNINITIALIZED: 436 default: 437 { 438 char buf[255]; 439 --- 6 unchanged lines hidden (view full) --- 446 } 447 } 448 SLIST_INIT(&$$.referenced_syms); 449 symlist_add(&$$.referenced_syms, symbol, SYMLIST_INSERT_HEAD); 450 } 451; 452 453constant: |
447 T_CONST T_SYMBOL T_NUMBER | 454 T_CONST T_SYMBOL numerical_value |
448 { 449 if ($2->type != UNINITIALIZED) { | 455 { 456 if ($2->type != UNINITIALIZED) { |
450 stop("Re-definition of constant variable", | 457 stop("Re-definition of symbol as a constant", |
451 EX_DATAERR); 452 /* NOTREACHED */ 453 } 454 $2->type = CONST; 455 initialize_symbol($2); 456 $2->info.cinfo->value = $3; 457 $2->info.cinfo->define = $1; 458 } | 458 EX_DATAERR); 459 /* NOTREACHED */ 460 } 461 $2->type = CONST; 462 initialize_symbol($2); 463 $2->info.cinfo->value = $3; 464 $2->info.cinfo->define = $1; 465 } |
466| T_CONST T_SYMBOL T_DOWNLOAD 467 { 468 if ($1) { 469 stop("Invalid downloaded constant declaration", 470 EX_DATAERR); 471 /* NOTREACHED */ 472 } 473 if ($2->type != UNINITIALIZED) { 474 stop("Re-definition of symbol as a downloaded constant", 475 EX_DATAERR); 476 /* NOTREACHED */ 477 } 478 $2->type = DOWNLOAD_CONST; 479 initialize_symbol($2); 480 $2->info.cinfo->value = download_constant_count++; 481 $2->info.cinfo->define = FALSE; 482 } |
|
459; 460 | 483; 484 |
485numerical_value: 486 T_NUMBER 487 { 488 $$ = $1; 489 } 490| '-' T_NUMBER 491 { 492 $$ = -$2; 493 } 494; 495 |
|
461scratch_ram: 462 T_SRAM '{' 463 { 464 cur_symbol = symtable_get(SRAM_SYMNAME); 465 cur_symtype = SRAMLOC; 466 if (cur_symbol->type != UNINITIALIZED) { 467 stop("Only one SRAM definition allowed", 468 EX_DATAERR); --- 523 unchanged lines hidden (view full) --- 992 if (symbol->info.minfo == NULL) { 993 stop("Can't create bitmask info", EX_SOFTWARE); 994 /* NOTREACHED */ 995 } 996 memset(symbol->info.minfo, 0, sizeof(struct mask_info)); 997 SLIST_INIT(&(symbol->info.minfo->symrefs)); 998 break; 999 case CONST: | 496scratch_ram: 497 T_SRAM '{' 498 { 499 cur_symbol = symtable_get(SRAM_SYMNAME); 500 cur_symtype = SRAMLOC; 501 if (cur_symbol->type != UNINITIALIZED) { 502 stop("Only one SRAM definition allowed", 503 EX_DATAERR); --- 523 unchanged lines hidden (view full) --- 1027 if (symbol->info.minfo == NULL) { 1028 stop("Can't create bitmask info", EX_SOFTWARE); 1029 /* NOTREACHED */ 1030 } 1031 memset(symbol->info.minfo, 0, sizeof(struct mask_info)); 1032 SLIST_INIT(&(symbol->info.minfo->symrefs)); 1033 break; 1034 case CONST: |
1035 case DOWNLOAD_CONST: |
|
1000 symbol->info.cinfo = 1001 (struct const_info *)malloc(sizeof(struct const_info)); 1002 if (symbol->info.cinfo == NULL) { 1003 stop("Can't create alias info", EX_SOFTWARE); 1004 /* NOTREACHED */ 1005 } 1006 memset(symbol->info.cinfo, 0, 1007 sizeof(struct const_info)); --- 75 unchanged lines hidden (view full) --- 1083 instr = seq_alloc(); 1084 f1_instr = &instr->format.format1; 1085 f1_instr->opcode_ret = (opcode << 1) | (ret ? RETURN_BIT : 0); 1086 f1_instr->destination = dest->symbol->info.rinfo->address 1087 + dest->offset; 1088 f1_instr->source = src->symbol->info.rinfo->address 1089 + src->offset; 1090 f1_instr->immediate = immed->value; | 1036 symbol->info.cinfo = 1037 (struct const_info *)malloc(sizeof(struct const_info)); 1038 if (symbol->info.cinfo == NULL) { 1039 stop("Can't create alias info", EX_SOFTWARE); 1040 /* NOTREACHED */ 1041 } 1042 memset(symbol->info.cinfo, 0, 1043 sizeof(struct const_info)); --- 75 unchanged lines hidden (view full) --- 1119 instr = seq_alloc(); 1120 f1_instr = &instr->format.format1; 1121 f1_instr->opcode_ret = (opcode << 1) | (ret ? RETURN_BIT : 0); 1122 f1_instr->destination = dest->symbol->info.rinfo->address 1123 + dest->offset; 1124 f1_instr->source = src->symbol->info.rinfo->address 1125 + src->offset; 1126 f1_instr->immediate = immed->value; |
1127 1128 if (is_download_const(immed)) 1129 f1_instr->opcode_ret |= DOWNLOAD_CONST_IMMEDIATE; 1130 |
|
1091 symlist_free(&immed->referenced_syms); 1092 instruction_ptr++; 1093} 1094 1095static void 1096format_2_instr(opcode, dest, places, src, ret) 1097 int opcode; 1098 symbol_ref_t *dest; --- 87 unchanged lines hidden (view full) --- 1186 } else 1187 addr = address->symbol->info.linfo->address + address->offset; 1188 f3_instr->opcode_addr = (opcode << 1) 1189 | ((addr >> 8) & 0x01); 1190 f3_instr->address = addr & 0xff; 1191 f3_instr->source = src->symbol->info.rinfo->address 1192 + src->offset; 1193 f3_instr->immediate = immed->value; | 1131 symlist_free(&immed->referenced_syms); 1132 instruction_ptr++; 1133} 1134 1135static void 1136format_2_instr(opcode, dest, places, src, ret) 1137 int opcode; 1138 symbol_ref_t *dest; --- 87 unchanged lines hidden (view full) --- 1226 } else 1227 addr = address->symbol->info.linfo->address + address->offset; 1228 f3_instr->opcode_addr = (opcode << 1) 1229 | ((addr >> 8) & 0x01); 1230 f3_instr->address = addr & 0xff; 1231 f3_instr->source = src->symbol->info.rinfo->address 1232 + src->offset; 1233 f3_instr->immediate = immed->value; |
1234 1235 if (is_download_const(immed)) 1236 f3_instr->opcode_addr |= DOWNLOAD_CONST_IMMEDIATE; 1237 |
|
1194 symlist_free(&immed->referenced_syms); 1195 instruction_ptr++; 1196} 1197 1198static void 1199test_readable_symbol(symbol) 1200 symbol_t *symbol; 1201{ --- 23 unchanged lines hidden (view full) --- 1225{ 1226 symbol_node_t *node; 1227 int and_op; 1228 char buf[255]; 1229 1230 and_op = FALSE; 1231 if (opcode == AIC_OP_AND || opcode == AIC_OP_JNZ || AIC_OP_JZ) 1232 and_op = TRUE; | 1238 symlist_free(&immed->referenced_syms); 1239 instruction_ptr++; 1240} 1241 1242static void 1243test_readable_symbol(symbol) 1244 symbol_t *symbol; 1245{ --- 23 unchanged lines hidden (view full) --- 1269{ 1270 symbol_node_t *node; 1271 int and_op; 1272 char buf[255]; 1273 1274 and_op = FALSE; 1275 if (opcode == AIC_OP_AND || opcode == AIC_OP_JNZ || AIC_OP_JZ) 1276 and_op = TRUE; |
1277 |
|
1233 /* 1234 * Make sure that we aren't attempting to write something 1235 * that hasn't been defined. If this is an and operation, 1236 * this is a mask, so "undefined" bits are okay. 1237 */ 1238 if (and_op == FALSE 1239 && (expression->value & ~symbol->info.rinfo->valid_bitmask) != 0) { 1240 snprintf(buf, sizeof(buf), --- 56 unchanged lines hidden (view full) --- 1297} 1298 1299void 1300yyerror(string) 1301 const char *string; 1302{ 1303 stop(string, EX_DATAERR); 1304} | 1278 /* 1279 * Make sure that we aren't attempting to write something 1280 * that hasn't been defined. If this is an and operation, 1281 * this is a mask, so "undefined" bits are okay. 1282 */ 1283 if (and_op == FALSE 1284 && (expression->value & ~symbol->info.rinfo->valid_bitmask) != 0) { 1285 snprintf(buf, sizeof(buf), --- 56 unchanged lines hidden (view full) --- 1342} 1343 1344void 1345yyerror(string) 1346 const char *string; 1347{ 1348 stop(string, EX_DATAERR); 1349} |
1350 1351static int 1352is_download_const(immed) 1353 expression_t *immed; 1354{ 1355 if ((immed->referenced_syms.slh_first != NULL) 1356 && (immed->referenced_syms.slh_first->symbol->type == DOWNLOAD_CONST)) 1357 return (TRUE); 1358 1359 return (FALSE); 1360} |
|