/*Writes coresponing code to file, or throws appropriate error */ void processOpcode( int code, int * steer, char * pArg1, char * pArg2, char * pArg3, char * pArg4) { int output = 0; int DR = -1; int SR = -1; int SR1 = -1; int SR2 = -1; int BR = -1; int num = -1; Symbol* temp = NULL; if(code <= 15 && code >= 0) output = code<<12; switch (code) { case 0: /* BR if steering is 1-7 and NOP if 0 */ if(*pArg2 != '\0' || *pArg3 != '\0' || *pArg4 !='\0'){ printf("Error: invalid argument\n"); closeFiles(); exit(4); } if(*steer==0 && *pArg1 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } if(*steer != 0) { /* br with nzp bits specified by steering */ output += *steer<<9; temp = searchSymbol(pArg1); if(temp == NULL) /*Label not found in symbol tabel */ { printf("Error: Unidentified Label\n"); closeFiles(); exit(1); } num = genOffset(temp->location,9); /*genOffset will throw out of bounds error if necisarry */ output += (num&511); } break; case 1: /*ADD */ DR = RegNum(pArg1); SR1 = RegNum(pArg2); /*Too many arguments, or invalid */ if(*pArg4 != '\0'||SR1 == -1 || DR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (DR<<9)+(SR1<<6); /*Common to all implementations */ SR2=RegNum(pArg3); if(SR2 == -1) /*Immediate Value */ { num = toNum(pArg3); if(num>15 || num < -16) /*5 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output+= (1<<5) + (num&31); } else /*Register value */ { output+=SR2; } break; case 2: /*LDB*/ DR = RegNum(pArg1); BR = RegNum(pArg2); if(*pArg4 != '\0'|| BR == -1 || DR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (DR<<9)+(BR<<6); num = toNum(pArg3); if(num>31 || num < -32) /* 6 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output += (num&63); break; case 3: /*STB*/ SR = RegNum(pArg1); BR = RegNum(pArg2); if(*pArg4 != '\0'|| BR == -1 || SR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (SR<<9)+(BR<<6); num = toNum(pArg3); if(num>31 || num < -32) /* 6 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output += (num&63); break; case 4: /* JSR & JSRR */ if(*pArg2 != '\0' || *pArg3 != '\0' || *pArg4 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += *steer << 11; if(*steer == 1) { /* JSR */ temp = searchSymbol(pArg1); if(temp == NULL) { /*Label not found in symbol tabel */ printf("Error: Unidentified Label\n"); closeFiles(); exit(1); } num = genOffset(temp->location,11); /*genOffset will throw out of bounds error if necisarry */ output += (num&2047); } else { /* JSRR */ BR = RegNum(pArg1); output += BR<<6; } break; case 5: /*AND */ DR = RegNum(pArg1); SR1 = RegNum(pArg2); /*Too many arguments, or invalid */ if(*pArg4 != '\0'||SR1 == -1 || DR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (DR<<9)+(SR1<<6); /*Common to all implementations */ SR2=RegNum(pArg3); if(SR2 == -1) /*Immediate Value */ { num = toNum(pArg3); if(num>15 || num < -16) /*5 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output+= (1<<5) + (num & 31); } else /*Register value */ { output+=SR2; } break; case 6: /*LDW*/ DR = RegNum(pArg1); BR = RegNum(pArg2); if(*pArg4 != '\0'|| BR == -1 || DR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (DR<<9)+(BR<<6); num = toNum(pArg3); if(num>31 || num < -32) /* 6 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output += (num&63); break; case 7: /*STW*/ SR = RegNum(pArg1); BR = RegNum(pArg2); if(*pArg4 != '\0'|| BR == -1 || SR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (SR<<9)+(BR<<6); num = toNum(pArg3); if(num>31 || num < -32) /* 6 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output += (num&63); break; case 8: /* RTI */ /* do nothing: bits 11-0 all 0 */ break; case 9: /*XOR and NOT */ DR = RegNum(pArg1); SR1 = RegNum(pArg2); /*Too many arguments, or invalid */ if(*pArg4 != '\0'||SR1 == -1 || DR == -1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += (DR<<9)+(SR1<<6); /*Common to all implementations */ if(*steer == 0) /*XOR*/ { SR2=RegNum(pArg3); if(SR2 == -1) /*Immediate Value */ { num = toNum(pArg3); if(num>15 || num < -16) /*5 Bits */ { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } output+= (1<<5) + (num&31); } else /*Register value */ { output+=SR2; } } else /*NOT function */ { if(*pArg3 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output += 63; } break; /*Opcodes 10 and 11 are invalid */ case 12: /*JMP */ if(*pArg2 != '\0' ||*pArg3 != '\0' || *pArg4 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } if(*steer == 0) { SR1 = RegNum(pArg1); if(SR1==-1) /*Must be valid register */ { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output+=SR1<<6; } else /*RET */ { if(*pArg1 != '\0') /*Should not have anything here */ { printf("Error: invalid argument\n"); closeFiles(); exit(4); } output+=7<<6; } break; case 13: /*Shift */ DR = RegNum(pArg1); SR1 = RegNum(pArg2); num = toNum(pArg3); if(*pArg4 != '\0' || DR==-1||SR1==-1) { printf("Error: invalid argument\n"); closeFiles(); exit(4); } if(num>15||num<0) { printf("Error: Immediate Value Out of Bounds\n"); closeFiles(); exit(3); } /*Steering integer also acts as steering bits */ output += (DR<<9)+(SR1<<6)+((*steer)<<4)+num; break; case 14: /*LEA */ DR = RegNum(pArg1); temp = searchSymbol(pArg2); if(temp == NULL) /*Label not found in symbol tabel */ { printf("Error: Unidentified Label\n"); closeFiles(); exit(1); } if(DR==-1 || *pArg3 != '\0' || *pArg4 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } num = genOffset(temp->location,9); /*genOffset will throw out of bounds error if necisarry */ output+=(DR<<9)+(num&511); break; case 15: /*TRAP */ /*Must be hex */ if(*pArg2 != '\0' || *pArg3 != '\0' || *pArg4 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } if(*steer == 1) /*HALT */ { if(*pArg1 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } num= 37; } else { if(*pArg1 != 'x') /*Must be a hex value */ { printf("Error: TRAP must be a hex value\n"); closeFiles(); exit(3); } num = toNum(pArg1); if(num>255||num<0) /*>0 and no more than 8 digits */ { printf("Error: TRAP Value Out of Bounds\n"); closeFiles(); exit(3); } } output+=num; break; case 16: /*.FILL */ if(*pArg2 != '\0' || *pArg3 != '\0' || *pArg4 != '\0') { printf("Error: invalid argument\n"); closeFiles(); exit(4); } num = toNum(pArg1); if(num>65535|| num< -32768) /*Can be signed or unsigned */ { printf("Error: TRAP Value Out of Bounds\n"); closeFiles(); exit(3); } output = num; break; default: printf("Error: invalid opcode\n"); closeFiles(); exit(2); } fprintf( outfile, "0x%0.4X\n", output ); /*Prints out formated Hex version of code */ }
static irqreturn_t cirrus_interrupt(int irq, void *id) { struct net_device *dev = (struct net_device *) id; cirrus_t *priv; u16 status; if (dev->priv == NULL) { return IRQ_NONE; } priv = (cirrus_t *) dev->priv; while ((status = cirrus_read (dev,PP_ISQ))) { switch (RegNum (status)) { case RxEvent: cirrus_receive (dev); break; case TxEvent: priv->stats.collisions += ColCount (cirrus_read (dev,PP_TxCOL)); if (!(RegContent (status) & TxOK)) { priv->stats.tx_errors++; if ((RegContent (status) & Out_of_window)) priv->stats.tx_window_errors++; if ((RegContent (status) & Jabber)) priv->stats.tx_aborted_errors++; break; } else if (priv->txlen) { priv->stats.tx_packets++; priv->stats.tx_bytes += priv->txlen; } priv->txlen = 0; netif_wake_queue (dev); break; case BufEvent: if ((RegContent (status) & RxMiss)) { u16 missed = MissCount (cirrus_read (dev,PP_RxMISS)); priv->stats.rx_errors += missed; priv->stats.rx_missed_errors += missed; } if ((RegContent (status) & TxUnderrun)) { priv->stats.tx_errors++; priv->stats.tx_fifo_errors++; } /* FIXME: if Rdy4Tx, transmit last sent packet (if any) */ priv->txlen = 0; netif_wake_queue (dev); break; case TxCOL: priv->stats.collisions += ColCount (cirrus_read (dev,PP_TxCOL)); break; case RxMISS: status = MissCount (cirrus_read (dev,PP_RxMISS)); priv->stats.rx_errors += status; priv->stats.rx_missed_errors += status; break; default: return IRQ_HANDLED; } } return IRQ_HANDLED; }
/*Throws error if invalid label */ void addLabel(char** label) { int size; int k; char* labelLoc; if(numSymbols>=MAX_SYMBOLS) { printf("Error: Too many symbols\n",label); closeFiles(); exit(4); } size = strlen(*label); if(size > 20) /*Oversized Label */ { printf("Error: The Label %s is too long; Must be less than 20 characters\n",label); closeFiles(); exit(4); } if(searchSymbol(*label) != NULL) /*Label is opcode */ { printf("Error: The Label %s is used multiple times\n",label); closeFiles(); exit(4); } for(k = 0; k<numIllegal;k++) /*Label is illegal */ { if(strcmp(*label, illegalLabel[k])==0) { printf("Error: The Label %s is an illegal label\n",label); closeFiles(); exit(4); } } if(**label == 'x' || !isalpha(**label)) /*First letter of label not a letter, or is x */ { if(strcmp(*label, illegalLabel[k])==0) { printf("Error: The Label %s is an illegal label\n",label); closeFiles(); exit(4); } } for(k=1; k<size;k++) /*Checks for non-alphanumeric label */ { if(!isalnum(*(*label + k))) { printf("Error: The Label %s is an illegal label\n",label); closeFiles(); exit(4); } } if(RegNum(*label)!= -1) { printf("Error: The Label %s is a register name\n",label); closeFiles(); exit(4); } labelLoc=(char*)malloc((size+1)*sizeof(char)); /*Allocate memory for label */ strcpy(labelLoc,*label); table[numSymbols].label=labelLoc; /*Add label to symbol tabel */ table[numSymbols].location=PC; numSymbols++; }