From 6c5075bc99ba07f46562f7f10db14e153d7a93ec Mon Sep 17 00:00:00 2001 From: jhansen Date: Mon, 26 Apr 2010 21:49:44 +0000 Subject: git-svn-id: https://mindboards.svn.sourceforge.net/svnroot/mindboards/lms_nbcnxc_128/trunk@6 c9361245-7fe8-9947-84e8-057757c4e366 --- AT91SAM7S256/Source/c_cmd_bytecodes.h | 76 +++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 8 deletions(-) (limited to 'AT91SAM7S256/Source/c_cmd_bytecodes.h') diff --git a/AT91SAM7S256/Source/c_cmd_bytecodes.h b/AT91SAM7S256/Source/c_cmd_bytecodes.h index 5cd9dfd..36a9084 100644 --- a/AT91SAM7S256/Source/c_cmd_bytecodes.h +++ b/AT91SAM7S256/Source/c_cmd_bytecodes.h @@ -4,7 +4,7 @@ // opcode definitions // symbol, bits, arg format // -#define OPCODE_COUNT 0x38 +#define OPCODE_COUNT 0x51 //Family: Math #define OP_ADD 0x00 // dest, src1, src2 @@ -21,13 +21,13 @@ #define OP_NOT 0x09 // dest, src //Family: Bit manipulation -#define OP_CMNT 0x0A // dest, src -#define OP_LSL 0x0B // dest, src -#define OP_LSR 0x0C // dest, src -#define OP_ASL 0x0D // dest, src -#define OP_ASR 0x0E // dest, src -#define OP_ROTL 0x0F // dest, src -#define OP_ROTR 0x10 // dest, src +#define OP_CMNT 0x0A // dest, src +#define OP_LSL 0x0B // dest, src, bits +#define OP_LSR 0x0C // dest, src, bits +#define OP_ASL 0x0D // dest, src, bits +#define OP_ASR 0x0E // dest, src, bits +#define OP_ROTL 0x0F // dest, src, bits +#define OP_ROTR 0x10 // dest, src, bits //Family: Comparison #define OP_CMP 0x11 // dest, src1, src2 @@ -86,6 +86,66 @@ #define OP_SQRT 0x36 // dest, src #define OP_ABS 0x37 // dest, src +// JCH ADDS +#define OP_WAITI 0x64 // immed +#define OP_WAITV 0x65 // var +#define OP_SIGN 0x66 // dest, src +#define OP_STOPCLUMPIMMED 0x67 // clumpID +#define OP_STARTCLUMPIMMED 0x68 // clumpID +#define OP_PRIORITY 0x69 // clumpID, pri +#define OP_FMTNUM 0x6a // dest, fmt, src1 +#define OP_ARROP 0x6b // cmd, dest, src, idx, len + +// math ops (float) +#define OP_ACOS 0x6c // dest, src +#define OP_ASIN 0x6d // dest, src +#define OP_ATAN 0x6e // dest, src +#define OP_CEIL 0x6f // dest, src +#define OP_EXP 0x70 // dest, src +#define OP_FLOOR 0x71 // dest, src +#define OP_TAN 0x72 // dest, src +#define OP_COS 0x74 // dest, src +#define OP_LOG 0x76 // dest, src +#define OP_LOG10 0x77 // dest, src +#define OP_SIN 0x78 // dest, src +#define OP_TRUNC 0x7a // dest, src +#define OP_FRAC 0x7b // dest, src + +#define OP_ATAN2 0x7c // dest, src1, src2 +#define OP_POW 0x7d // dest, src1, src2 + +#define OP_MULDIV 0x7e // dest, src1, src2, src3 + +// transcendental opcodes that use degrees instead of radians +#define OP_ACOSD 0x7f // dest, src +#define OP_ASIND 0x80 // dest, src +#define OP_ATAND 0x81 // dest, src +#define OP_TAND 0x82 // dest, src +#define OP_COSD 0x84 // dest, src +#define OP_SIND 0x86 // dest, src +#define OP_ATAN2D 0x88 // dest, src1, src2 + + +// hyperbolic transcendental functions +#define OP_TANH 0x73 // dest, src +#define OP_COSH 0x75 // dest, src +#define OP_SINH 0x79 // dest, src +#define OP_TANHD 0x83 // dest, src +#define OP_COSHD 0x85 // dest, src +#define OP_SINHD 0x87 // dest, src + +// additional string opcodes + + +// array operation definitions +#define OPARR_SUM 0x00 +#define OPARR_MEAN 0x01 +#define OPARR_SUMSQR 0x02 +#define OPARR_STD 0x03 +#define OPARR_MIN 0x04 +#define OPARR_MAX 0x05 +#define OPARR_SORT 0x06 + // condition code definitions #define OPCC1_LT 0x00 #define OPCC1_GT 0x01 -- cgit v1.2.3 From 8882cc8fb00439dd0d132a676981bd34301c6a24 Mon Sep 17 00:00:00 2001 From: jhansen Date: Tue, 27 Apr 2010 23:24:06 +0000 Subject: fixed stringtonum bugs added addrof opcode changes that will hopefully fix stopclumpimmed opcode bugs git-svn-id: https://mindboards.svn.sourceforge.net/svnroot/mindboards/lms_nbcnxc_128/trunk@13 c9361245-7fe8-9947-84e8-057757c4e366 --- AT91SAM7S256/Source/c_cmd.c | 100 +++++++++++++++++++++++++--------- AT91SAM7S256/Source/c_cmd.h | 1 + AT91SAM7S256/Source/c_cmd_bytecodes.h | 3 + 3 files changed, 79 insertions(+), 25 deletions(-) (limited to 'AT91SAM7S256/Source/c_cmd_bytecodes.h') diff --git a/AT91SAM7S256/Source/c_cmd.c b/AT91SAM7S256/Source/c_cmd.c index 7e48993..9a81076 100644 --- a/AT91SAM7S256/Source/c_cmd.c +++ b/AT91SAM7S256/Source/c_cmd.c @@ -1921,6 +1921,7 @@ NXT_STATUS cCmdActivateProgram(UBYTE * pFileName) clumpPtr->PC = clumpPtr->CodeStart; clumpPtr->Link = NOT_A_CLUMP; clumpPtr->Priority = INSTR_MAX_COUNT; + clumpPtr->CalledClump = NOT_A_CLUMP; CLUMP_BREAK_REC* pBreakpoints = clumpPtr->Breakpoints; for (j = 0; j < MAX_BREAKPOINTS; j++) @@ -2457,6 +2458,7 @@ NXT_STATUS cCmdReleaseAllMutexes(CLUMP_ID Clump) NXT_ASSERT(cCmdIsClumpIDSane(Clump)); DATA_ARG Arg1; MUTEX_Q * Mutex; + UBYTE bFoundWaitingMutex = FALSE; for (Arg1=0; Arg1 < VarsCmd.DataspaceCount; Arg1++) { if (VarsCmd.pDataspaceTOC[Arg1].TypeCode == TC_MUTEX) @@ -2466,8 +2468,11 @@ NXT_STATUS cCmdReleaseAllMutexes(CLUMP_ID Clump) if (Mutex->Owner == Clump) cCmdReleaseMutex(Mutex); // also make sure that this Clump is not waiting in this mutex's wait queue - if (cCmdIsClumpOnQ(&(Mutex->WaitQ), Clump)) + if (!bFoundWaitingMutex && cCmdIsClumpOnQ(&(Mutex->WaitQ), Clump)) { + bFoundWaitingMutex = TRUE; cCmdDeQClump(&(Mutex->WaitQ), Clump); + cCmdEnQClump(&(VarsCmd.RunQ), Clump); + } } } return (NO_ERR); @@ -2498,6 +2503,39 @@ NXT_STATUS cCmdReleaseMutex(MUTEX_Q * Mutex) return (NO_ERR); } +NXT_STATUS cCmdStopClump(CLUMP_ID Clump) +{ + // first check whether this clump has called another clump + CLUMP_REC* pClumpRec = &(VarsCmd.pAllClumps[Clump]); + if (pClumpRec->CalledClump != NOT_A_CLUMP) { + // in this situation we know that this clump + // is not on any queues of any kind (run, rest, or wait) + // so instead of trying to stop THIS clump we will + // try to stop the clump it called instead + cCmdStopClump(pClumpRec->CalledClump); + } + else + { + // release any mutexes owned by this clump + // and remove it from any wait queues that it might be on + cCmdReleaseAllMutexes(Clump); + if (cCmdIsClumpOnQ(&(VarsCmd.RunQ), Clump)) { + // remove the specified clump from the run queue if it is on it + cCmdDeQClump(&(VarsCmd.RunQ), Clump); + } + else if (cCmdIsClumpOnQ(&(VarsCmd.RestQ), Clump)) { + // if the specified clump happened to be sleeping then + // remove it from the rest queue + cCmdDeQClump(&(VarsCmd.RestQ), Clump); + } + // since we have stopped that clump we should reset its clump rec values. + pClumpRec->PC = pClumpRec->CodeStart; + pClumpRec->CurrFireCount = pClumpRec->InitFireCount; + pClumpRec->awakenTime = 0; + } + return (NO_ERR); +} + // No instruction to do this yet, but put current clump to sleep until awakeTime occurs NXT_STATUS cCmdSleepClump(ULONG time) { @@ -4620,12 +4658,16 @@ NXT_STATUS cCmdInterpUnop1(CODE_WORD * const pCode) case OP_SUBRET: { NXT_ASSERT(cCmdIsDSElementIDSane(Arg1)); - + CLUMP_ID clump = *((CLUMP_ID *)cCmdDSScalarPtr(Arg1, 0)); + //Take Subroutine off RunQ //Add Subroutine's caller to RunQ cCmdDeQClump(&(VarsCmd.RunQ), VarsCmd.RunQ.Head); - cCmdEnQClump(&(VarsCmd.RunQ), *((CLUMP_ID *)cCmdDSScalarPtr(Arg1, 0))); + cCmdEnQClump(&(VarsCmd.RunQ), clump); + CLUMP_REC* pClumpRec = &(VarsCmd.pAllClumps[clump]); + pClumpRec->CalledClump = NOT_A_CLUMP; + Status = CLUMP_DONE; } break; @@ -4676,23 +4718,7 @@ NXT_STATUS cCmdInterpUnop1(CODE_WORD * const pCode) { // Release any mutexes that the clump we are stopping owns CLUMP_ID Clump = (CLUMP_ID)Arg1; - // release any mutexes owned by this clump - // and remove it from any wait queues that it might be on - cCmdReleaseAllMutexes(Clump); - if (cCmdIsClumpOnQ(&(VarsCmd.RunQ), Clump)) { - // remove the specified clump from the run queue if it is on it - cCmdDeQClump(&(VarsCmd.RunQ), Clump); - } - else if (cCmdIsClumpOnQ(&(VarsCmd.RestQ), Clump)) { - // if the specified clump happened to be sleeping then - // remove it from the rest queue - cCmdDeQClump(&(VarsCmd.RestQ), Clump); - } - // since we have stopped that clump we should reset its clump rec values. - CLUMP_REC* pClumpRec = &(VarsCmd.pAllClumps[Clump]); - pClumpRec->PC = pClumpRec->CodeStart; - pClumpRec->CurrFireCount = pClumpRec->InitFireCount; - pClumpRec->awakenTime = 0; + cCmdStopClump(Clump); } break; @@ -4911,10 +4937,14 @@ NXT_STATUS cCmdInterpUnop2(CODE_WORD * const pCode) NXT_ASSERT(!cCmdIsClumpOnQ(&(VarsCmd.RunQ), (CLUMP_ID)Arg1)); NXT_ASSERT(cCmdIsDSElementIDSane(Arg2)); + + CLUMP_ID clump = VarsCmd.RunQ.Head; + CLUMP_REC* pClumpRec = &(VarsCmd.pAllClumps[clump]); + pClumpRec->CalledClump = (CLUMP_ID)Arg1; - *((CLUMP_ID *)(cCmdDSScalarPtr(Arg2, 0))) = VarsCmd.RunQ.Head; + *((CLUMP_ID *)(cCmdDSScalarPtr(Arg2, 0))) = clump; - cCmdDeQClump(&(VarsCmd.RunQ), VarsCmd.RunQ.Head); //Take caller off RunQ + cCmdDeQClump(&(VarsCmd.RunQ), clump); //Take caller off RunQ cCmdEnQClump(&(VarsCmd.RunQ), (CLUMP_ID)Arg1); //Add callee to RunQ Status = CLUMP_SUSPEND; @@ -5123,6 +5153,18 @@ NXT_STATUS cCmdInterpUnop2(CODE_WORD * const pCode) } break; + case OP_ADDROF: + { + pArg1 = cCmdResolveDataArg(Arg1, 0, &TypeCode1); + if (TypeCode1 == TC_ULONG) { + pArg2 = cCmdResolveDataArg(Arg2, 0, NULL); + *(ULONG*)pArg1 = (ULONG)pArg2; + } + else + Status = ERR_INSTR; // output argument MUST be an unsigned long type + } + break; + default: { //Fatal error: Unrecognized instruction @@ -7039,6 +7081,7 @@ NXT_STATUS cCmdInterpOther(CODE_WORD * const pCode) ULONG ArgVal1; float ArgValF; SLONG decimals= 0; + UBYTE exponent=FALSE; UBYTE cont= TRUE; // Arg1 - Dst number (output) // Arg2 - Offset past match (output) @@ -7090,13 +7133,20 @@ NXT_STATUS cCmdInterpOther(CODE_WORD * const pCode) if (TypeCode1 == TC_FLOAT) { //Scan until we get past the number and no more than one decimal + // optionally there can also be a single "e" or "E" followed by + // one or more digits (but the decimal cannot come after this) while (cont) { - if ((((UBYTE *)pArg3)[i] >= '0') && (((UBYTE *)pArg3)[i] <= '9')) + UBYTE ch = ((UBYTE *)pArg3)[i]; + if ((ch >= '0') && (ch <= '9')) i++; - else if(((UBYTE *)pArg3)[i] == '.' && !decimals) { + else if(ch == '.' && !decimals && !exponent) { i++; decimals++; - } + } + else if (((ch == 'E') || (ch == 'e')) && !exponent) { + i++; + exponent = TRUE; + } else cont= FALSE; } diff --git a/AT91SAM7S256/Source/c_cmd.h b/AT91SAM7S256/Source/c_cmd.h index 729e14b..5f9caa6 100644 --- a/AT91SAM7S256/Source/c_cmd.h +++ b/AT91SAM7S256/Source/c_cmd.h @@ -439,6 +439,7 @@ typedef struct CLUMP_ID* pDependents; ULONG awakenTime; UBYTE DependentCount; + CLUMP_ID CalledClump; CLUMP_BREAK_REC Breakpoints[MAX_BREAKPOINTS]; } CLUMP_REC; diff --git a/AT91SAM7S256/Source/c_cmd_bytecodes.h b/AT91SAM7S256/Source/c_cmd_bytecodes.h index 36a9084..434aeff 100644 --- a/AT91SAM7S256/Source/c_cmd_bytecodes.h +++ b/AT91SAM7S256/Source/c_cmd_bytecodes.h @@ -134,6 +134,9 @@ #define OP_COSHD 0x85 // dest, src #define OP_SINHD 0x87 // dest, src +// misc other JCH additions +#define OP_ADDROF 0x89 // dest, src + // additional string opcodes -- cgit v1.2.3 From 2d194ca30a8b1b15749098a1a1aa7f6a47fe6299 Mon Sep 17 00:00:00 2001 From: tcsadmin Date: Fri, 20 Aug 2010 22:05:58 +0000 Subject: opcode changes/fixes git-svn-id: https://mindboards.svn.sourceforge.net/svnroot/mindboards/lms_nbcnxc_128/trunk@15 c9361245-7fe8-9947-84e8-057757c4e366 --- AT91SAM7S256/Source/c_cmd.c | 30 +++++++++++++++++------------- AT91SAM7S256/Source/c_cmd_bytecodes.h | 2 +- 2 files changed, 18 insertions(+), 14 deletions(-) (limited to 'AT91SAM7S256/Source/c_cmd_bytecodes.h') diff --git a/AT91SAM7S256/Source/c_cmd.c b/AT91SAM7S256/Source/c_cmd.c index 9a81076..f4b1a31 100644 --- a/AT91SAM7S256/Source/c_cmd.c +++ b/AT91SAM7S256/Source/c_cmd.c @@ -5153,18 +5153,6 @@ NXT_STATUS cCmdInterpUnop2(CODE_WORD * const pCode) } break; - case OP_ADDROF: - { - pArg1 = cCmdResolveDataArg(Arg1, 0, &TypeCode1); - if (TypeCode1 == TC_ULONG) { - pArg2 = cCmdResolveDataArg(Arg2, 0, NULL); - *(ULONG*)pArg1 = (ULONG)pArg2; - } - else - Status = ERR_INSTR; // output argument MUST be an unsigned long type - } - break; - default: { //Fatal error: Unrecognized instruction @@ -5579,6 +5567,7 @@ NXT_STATUS cCmdInterpBinop(CODE_WORD * const pCode) UWORD i; void *pArg1 = NULL, *pArg2 = NULL; UWORD Count; + TYPE_CODE TypeCode1; polyBinopDispatch ++; gPCDelta= 4; @@ -5744,6 +5733,21 @@ NXT_STATUS cCmdInterpBinop(CODE_WORD * const pCode) } break; + case OP_ADDROF: + { + pArg1 = cCmdResolveDataArg(Arg1, 0, &TypeCode1); + if (TypeCode1 == TC_ULONG) { + pArg2 = cCmdResolveDataArg(Arg2, 0, NULL); + if ((UBYTE)Arg3) // relative address requested + *(ULONG*)pArg1 = (ULONG)pArg2 - (ULONG)(IOMapCmd.MemoryPool); + else + *(ULONG*)pArg1 = (ULONG)pArg2; + } + else + Status = ERR_INSTR; // output argument MUST be an unsigned long type + } + break; + default: { //Fatal error: Unrecognized instruction @@ -6130,7 +6134,7 @@ float cCmdBinopFlt(CODE_WORD const Code, float LeftOp, float RightOp, TYPE_CODE case OP_POW: { float intpart, fracpart; - fracpart = modff(LeftOp, &intpart); + fracpart = modff(RightOp, &intpart); if (LeftOp < 0 && fracpart != 0) return 0; // make the result zero if you try to raise a negative number to a fractional exponent else diff --git a/AT91SAM7S256/Source/c_cmd_bytecodes.h b/AT91SAM7S256/Source/c_cmd_bytecodes.h index 434aeff..5c24472 100644 --- a/AT91SAM7S256/Source/c_cmd_bytecodes.h +++ b/AT91SAM7S256/Source/c_cmd_bytecodes.h @@ -135,7 +135,7 @@ #define OP_SINHD 0x87 // dest, src // misc other JCH additions -#define OP_ADDROF 0x89 // dest, src +#define OP_ADDROF 0x89 // dest, src, rel // additional string opcodes -- cgit v1.2.3