?? reformat.c
字號:
case EI: /* EI B */
case DI:
case HALT:
case NOP:
{
DBG_FMT1("opcode %s\n\n",I_Set[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case DIV: /* DIV $r1, $r2, $r3, $r4 */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",R_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",R_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",R_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",R_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_IF: /* CAST_IF $r, $f */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",R_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_ID: /* CAST_ID $r, $d */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",R_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_FI: /* CAST_FI $f, $r */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",R_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_FD: /* CAST_FD $f, $d */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_DI: /* CAST_DI $d, $r */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badIntReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",R_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case CAST_DF: /* CAST_DF $d, $f */
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case FADD: /* FADD $f1, $f2, $f3 BBBB */
case FSUB:
case FMULT:
case FDIV:
case FSLT:
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badFltReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rf_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
case DADD: /* DADD $d1, $d2, $d3 BBBB */
case DSUB:
case DMULT:
case DDIV:
case DSLT:
{
DBG_FMT1("opcode %s\n",I_Set[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkCurrentByte(current_byte,stop);
badDblReg(RAM[current_byte],current_byte);
DBG_FMT1("operand %s\n\n",Rd_STR[RAM[current_byte]]);
current_byte++;
checkEndCurrentByte(current_byte,stop);
}break;
default:
{
ERROR1_LVL2("reformat(): bad opcode %d",
RAM[current_byte]);
return(FALSE);
}
}/*end switch*/
}/*end while*/
DBG_FMT0("reformatting complete\n");
return(TRUE);
}/*end reformat*/
/*-----------------------------------------------------------------*/
/*
some registers are read-only ( used by runtime system only )
*/
void badIntReg(U1 arg, U8 currentbyte)
{
if(arg>$R24)
{
ERROR1_LVL2("badIntReg(): (%d) not integer register",arg);
xmlBegin();
fprintf(errPtr,"badIntReg(): bad register at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badIntReg*/
/*-----------------------------------------------------------------*/
void badFltReg(U1 arg, U8 currentbyte)
{
if(arg>$F10)
{
ERROR1_LVL2("badFltReg(): (%d) not float register",arg);
xmlBegin();
fprintf(errPtr,"badFltReg(): bad register at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badFltReg*/
/*-----------------------------------------------------------------*/
void badDblReg(U1 arg, U8 currentbyte)
{
if(arg>$D10)
{
ERROR1_LVL2("badDblReg(): (%d) not double register",arg);
xmlBegin();
fprintf(errPtr,"badDblReg(): bad register at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badDblReg*/
/*-----------------------------------------------------------------*/
void checkAddress(U1 *arr, U8 cb)
{
U8* addr;
addr = (U8*)&arr[cb];
if(*addr > R[$TOP])
{
ERROR0_LVL2("checkAddress(): address out of bounds");
xmlBegin();
fprintf(errPtr,"checkAddress(): invalid address literal ");
fpU8(errPtr,*addr);
fprintf(errPtr," at memory location ");
fpU8(errPtr,cb);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end checkAddress*/
/*-----------------------------------------------------------------*/
/*
don't want incomplete instruction (hit end bytecode before end
of instruction)
*/
void checkCurrentByte(U8 cb, U8 end)
{
if(cb>=end)
{
ERROR0_LVL2("checkCurrentByte(): incomplete instruction");
xmlBegin();
fprintf(errPtr,"checkCurrentByte(): ");
fprintf(errPtr,"incomplete instruction at address ");
fpU8(errPtr,cb);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end checkCurrentByte*/
/*-----------------------------------------------------------------*/
/*
last byte of an instruction is allowed to be at end of bytecode, so
use checkEndCurrentByte
*/
void checkEndCurrentByte(U8 cb, U8 end)
{
if(cb>end)
{
ERROR0_LVL2("checkEndCurrentByte(): incomplete instruction");
xmlBegin();
fprintf(errPtr,"checkEndCurrentByte(): ");
fprintf(errPtr,"incomplete instruction at address ");
fpU8(errPtr,cb);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end checkEndCurrentByte*/
/*-----------------------------------------------------------------*/
void badAddress(U8 arg, U8 currentbyte)
{
if(arg>R[$TOP])
{
ERROR0_LVL2("badAddress(): invalid address literal");
xmlBegin();
fprintf(errPtr,"badAddress(): invalid address literal ");
fpU8(errPtr,arg);
fprintf(errPtr," at memory location ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badAddress*/
/*-----------------------------------------------------------------*/
void badStack(U8 arg, U8 currentbyte)
{
if(arg<=R[$HE])
{
ERROR0_LVL2("badStack(): stack overflow into heap");
xmlBegin();
fprintf(errPtr,"badStack(): ");
fpU8(errPtr,arg);
fprintf(errPtr," stack overflow into heap ");
fprintf(errPtr,"at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
else if(arg>R[$TOP])
{
ERROR0_LVL2("badStack(): stack underflow beyond $TOP");
xmlBegin();
fprintf(errPtr,"badStack(): ");
fpU8(errPtr,arg);
fprintf(errPtr," stack underflow beyond $TOP ");
fprintf(errPtr,"at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badStack*/
/*-----------------------------------------------------------------*/
void badHeap(U8 arg, U8 currentbyte)
{
if(arg<R[$HS])
{
ERROR0_LVL2("badHeap(): below heap");
xmlBegin();
fprintf(errPtr,"badHeap(): ");
fpU8(errPtr,arg);
fprintf(errPtr," below start of heap ");
fprintf(errPtr,"at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
else if(arg>R[$HE])
{
ERROR0_LVL2("badHeap(): beyond end of heap");
xmlBegin();
fprintf(errPtr,"badHeap(): ");
fpU8(errPtr,arg);
fprintf(errPtr," beyond end of heap ");
fprintf(errPtr,"at address ");
fpU8(errPtr,currentbyte);
xmlEnd();
FATAL_ERROR();
}
return;
}/*end badHeap*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -