filename | src/tools/insparse.c |
changeset | 736:a02d1475ccfd |
prev | 561:533f6b478071 |
author | nkeynes |
date | Sat Jan 03 03:30:26 2009 +0000 (15 years ago) |
branch | lxdream-mem |
permissions | -rw-r--r-- |
last change | MMU work-in-progress * Move SDRAM out into separate sdram.c * Move all page-table management into mmu.c * Convert UTLB management to use the new page-tables * Rip out all calls to mmu_vma_to_phys_* and replace with direct access |
file | annotate | diff | log | raw |
1.1 --- a/src/tools/insparse.c Tue Jan 01 05:08:38 2008 +00001.2 +++ b/src/tools/insparse.c Sat Jan 03 03:30:26 2009 +00001.3 @@ -49,28 +49,28 @@1.4 rules->rule_count = 0;1.5 yyline = 0;1.6 while( fgets( buf, sizeof(buf), f ) != NULL ) {1.7 - yyline++;1.8 - if( strncasecmp(buf, "registers", 9) == 0 ) {1.9 - parse_registers_block(buf, sizeof(buf), f);1.10 - } else if( buf[0] != '\0' && buf[0] != '#' && buf[0] != '\n' ) {1.11 - struct rule *rule;1.12 - char *p = buf;1.13 - rule = new_rule();1.14 - if( parse_rule( &p, rule ) != 0 ) {1.15 - free( rule );1.16 - } else {1.17 - rules->rules[rules->rule_count++] = rule;1.18 - }1.19 - }1.20 + yyline++;1.21 + if( strncasecmp(buf, "registers", 9) == 0 ) {1.22 + parse_registers_block(buf, sizeof(buf), f);1.23 + } else if( buf[0] != '\0' && buf[0] != '#' && buf[0] != '\n' ) {1.24 + struct rule *rule;1.25 + char *p = buf;1.26 + rule = new_rule();1.27 + if( parse_rule( &p, rule ) != 0 ) {1.28 + free( rule );1.29 + } else {1.30 + rules->rules[rules->rule_count++] = rule;1.31 + }1.32 + }1.33 }1.34 return rules;1.35 }1.37 int parse_registers_block( char *buf, int buflen, FILE *f ) {1.38 do {1.39 - if( strchr(buf, '}') != NULL ) {1.40 - break;1.41 - }1.42 + if( strchr(buf, '}') != NULL ) {1.43 + break;1.44 + }1.45 } while( fgets( buf, buflen, f ) != NULL );1.46 return 0;1.47 }1.48 @@ -82,28 +82,28 @@1.49 int parse_rule( char **str, struct rule *rule )1.50 {1.51 if( parse_bitstring( str, rule ) != 0 ) {1.52 - return -1;1.53 + return -1;1.54 }1.56 /* consume whitespace in between */1.57 while( isspace(**str) ) (*str)++;1.58 if( **str == '\0' ) {1.59 - fprintf( stderr, "Unexpected end of file in rule on line %d\n", yyline );1.60 - return -1;1.61 + fprintf( stderr, "Unexpected end of file in rule on line %d\n", yyline );1.62 + return -1;1.63 }1.64 -1.65 +1.66 int result = parse_rule_format( str, rule );1.67 if( result == 0 ) {1.68 - /* Reverse operand bit shifts */1.69 - int j;1.70 - for( j=0; j<rule->operand_count; j++ ) {1.71 - rule->operands[j].bit_shift =1.72 - rule->bit_count - rule->operands[j].bit_shift - rule->operands[j].bit_count;1.73 - }1.74 - if( **str == '!' ) {1.75 - (*str)++;1.76 - result = parse_operand_uses( str, rule );1.77 - }1.78 + /* Reverse operand bit shifts */1.79 + int j;1.80 + for( j=0; j<rule->operand_count; j++ ) {1.81 + rule->operands[j].bit_shift =1.82 + rule->bit_count - rule->operands[j].bit_shift - rule->operands[j].bit_count;1.83 + }1.84 + if( **str == '!' ) {1.85 + (*str)++;1.86 + result = parse_operand_uses( str, rule );1.87 + }1.88 }1.90 return 0;1.91 @@ -112,29 +112,29 @@1.92 int parse_bitstring( char **str, struct rule *rule )1.93 {1.94 while( !isspace(**str) ) {1.95 - int ch = **str;1.96 - (*str)++;1.97 - switch( ch ) {1.98 - case '0':1.99 - rule->bits = rule->bits << 1;1.100 - rule->mask = (rule->mask << 1) | 1;1.101 - rule->bit_count++;1.102 - break;1.103 - case '1':1.104 - rule->bits = (rule->bits << 1) | 1;1.105 - rule->mask = (rule->mask << 1) | 1;1.106 - rule->bit_count++;1.107 - break;1.108 - case '(':1.109 - if( parse_bitoperand( str, rule ) != 0 ) {1.110 - return -1 ;1.111 - }1.112 - break;1.113 - default:1.114 - (*str)--;1.115 - fprintf( stderr, "Unexpected character '%c' in bitstring at line %d\n", ch, yyline );1.116 - return -1;1.117 - }1.118 + int ch = **str;1.119 + (*str)++;1.120 + switch( ch ) {1.121 + case '0':1.122 + rule->bits = rule->bits << 1;1.123 + rule->mask = (rule->mask << 1) | 1;1.124 + rule->bit_count++;1.125 + break;1.126 + case '1':1.127 + rule->bits = (rule->bits << 1) | 1;1.128 + rule->mask = (rule->mask << 1) | 1;1.129 + rule->bit_count++;1.130 + break;1.131 + case '(':1.132 + if( parse_bitoperand( str, rule ) != 0 ) {1.133 + return -1 ;1.134 + }1.135 + break;1.136 + default:1.137 + (*str)--;1.138 + fprintf( stderr, "Unexpected character '%c' in bitstring at line %d\n", ch, yyline );1.139 + return -1;1.140 + }1.141 }1.142 return 0;1.143 }1.144 @@ -144,36 +144,36 @@1.145 char *p = rule->operands[rule->operand_count].name;1.147 if( rule->operand_count == MAX_OPERANDS ) {1.148 - fprintf( stderr, "Maximum operands/rule exceeded (%d) at line %d\n", MAX_OPERANDS, yyline );1.149 - return -1;1.150 + fprintf( stderr, "Maximum operands/rule exceeded (%d) at line %d\n", MAX_OPERANDS, yyline );1.151 + return -1;1.152 }1.154 while( isalnum(**str) || **str == '_' ) {1.155 - *p++ = *(*str)++;1.156 + *p++ = *(*str)++;1.157 }1.158 *p = '\0';1.159 CONSUME_CHAR(':');1.160 -1.161 +1.162 int size = parse_integer( str );1.163 if( size == -1 ) {1.164 - return -1;1.165 + return -1;1.166 }1.167 rule->operands[rule->operand_count].bit_count = size;1.168 if( **str == 's' || **str == 'S' ) {1.169 - (*str)++;1.170 - rule->operands[rule->operand_count].is_signed = 1;1.171 + (*str)++;1.172 + rule->operands[rule->operand_count].is_signed = 1;1.173 } else if( **str == 'u' || **str == 'U' ) {1.174 - (*str)++;1.175 - rule->operands[rule->operand_count].is_signed = 0;1.176 + (*str)++;1.177 + rule->operands[rule->operand_count].is_signed = 0;1.178 }1.179 if( **str == '<' ) {1.180 - (*str)++;1.181 - CONSUME_CHAR('<');1.182 - int lsl = parse_integer(str);1.183 - if( lsl == -1 ) {1.184 - return -1;1.185 - }1.186 - rule->operands[rule->operand_count].left_shift = lsl;1.187 + (*str)++;1.188 + CONSUME_CHAR('<');1.189 + int lsl = parse_integer(str);1.190 + if( lsl == -1 ) {1.191 + return -1;1.192 + }1.193 + rule->operands[rule->operand_count].left_shift = lsl;1.194 }1.195 CONSUME_CHAR(')');1.197 @@ -189,12 +189,12 @@1.198 {1.199 uint32_t val = 0;1.200 if( !isdigit(**str) ) {1.201 - fprintf(stderr, "Expected digit (0-9) but was '%c' at line %d\n", **str, yyline );1.202 - return -1;1.203 + fprintf(stderr, "Expected digit (0-9) but was '%c' at line %d\n", **str, yyline );1.204 + return -1;1.205 }1.206 do {1.207 - val = val * 10 + (**str - '0');1.208 - (*str)++;1.209 + val = val * 10 + (**str - '0');1.210 + (*str)++;1.211 } while( isdigit(**str) );1.212 return val;1.213 }1.214 @@ -205,7 +205,7 @@1.215 char tmp[64];1.216 char *p = tmp;1.217 while( **str != '\n' && **str != '\0' && **str != '!' ) {1.218 - *p++ = *(*str)++;1.219 + *p++ = *(*str)++;1.220 }1.221 *p = '\0';1.222 strcpy( rule->format, tmp );1.223 @@ -223,15 +223,15 @@1.224 int i, j;1.225 fprintf( f, "Rulset: %d rules\n", rules->rule_count );1.226 for( i=0; i<rules->rule_count; i++ ) {1.227 - struct rule *rule = rules->rules[i];1.228 - fprintf( f, "Match: %08X/%08X %s: ", rule->bits, rule->mask, rule->format );1.229 - for( j=0; j<rule->operand_count; j++ ) {1.230 - fprintf( f, "%s = (%s)(ir>>%d)&0x%X ", rule->operands[j].name,1.231 - rule->operands[j].is_signed ? "signed" : "unsigned",1.232 - rule->operands[j].bit_shift,1.233 - (1<<rule->operands[j].bit_count)-1 );1.234 - }1.235 - fprintf( f, "\n" );1.236 + struct rule *rule = rules->rules[i];1.237 + fprintf( f, "Match: %08X/%08X %s: ", rule->bits, rule->mask, rule->format );1.238 + for( j=0; j<rule->operand_count; j++ ) {1.239 + fprintf( f, "%s = (%s)(ir>>%d)&0x%X ", rule->operands[j].name,1.240 + rule->operands[j].is_signed ? "signed" : "unsigned",1.241 + rule->operands[j].bit_shift,1.242 + (1<<rule->operands[j].bit_count)-1 );1.243 + }1.244 + fprintf( f, "\n" );1.245 }1.246 }1.248 @@ -239,14 +239,14 @@1.249 {1.250 int i,j;1.251 for( i=0; i<rule_count; i++ ) {1.252 - struct rule *rule = rules->rules[ruleidx[i]];1.253 - fprintf( f, "Match: %08X/%08X %s: ", rule->bits, rule->mask, rule->format );1.254 - for( j=0; j<rule->operand_count; j++ ) {1.255 - fprintf( f, "%s = (%s)(ir>>%d)&0x%X ", rule->operands[j].name,1.256 - rule->operands[j].is_signed ? "signed" : "unsigned",1.257 - rule->operands[j].bit_shift,1.258 - (1<<rule->operands[j].bit_count)-1 );1.259 - }1.260 - fprintf( f, "\n" );1.261 + struct rule *rule = rules->rules[ruleidx[i]];1.262 + fprintf( f, "Match: %08X/%08X %s: ", rule->bits, rule->mask, rule->format );1.263 + for( j=0; j<rule->operand_count; j++ ) {1.264 + fprintf( f, "%s = (%s)(ir>>%d)&0x%X ", rule->operands[j].name,1.265 + rule->operands[j].is_signed ? "signed" : "unsigned",1.266 + rule->operands[j].bit_shift,1.267 + (1<<rule->operands[j].bit_count)-1 );1.268 + }1.269 + fprintf( f, "\n" );1.270 }1.271 }
.