31 #ifndef LEGO_SIMULATION
43 gValidateInstance= _Instance;
48 return gValidateInstance;
67 if (OpCodes[OpCode].Name)
71 Length =
snprintf(&Buf[Size],Lng - Size,
" %s,",OpCodes[OpCode].Name);
76 Pars = OpCodes[OpCode].Pars;
80 ParType = Pars & 0x0F;
90 if (SubCodes[Tab][Sub].Name !=
NULL)
98 Size +=
snprintf(&Buf[Size],Lng - Size,
"\r\n");
99 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s",TmpBuf);
102 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s, ",SubCodes[Tab][Sub].Name);
103 Pars = SubCodes[Tab][Sub].Pars;
105 while ((Pars & 0x0F) >=
PAR)
108 if (((Pars >> 4) & 0x0F) !=
SUBP)
110 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s, ",ParTypeNames[(Pars & 0x0F) -
PAR]);
118 if (ParType ==
PARNO)
121 if (((Pars >> 4) & 0x0F) !=
SUBP)
123 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s, ",ParTypeNames[DATA_8]);
132 if (((Pars >> 4) & 0x0F) !=
SUBP)
134 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s, ",ParTypeNames[DATA_8]);
149 if (((Pars >> 4) & 0x0F) !=
SUBP)
151 Size +=
snprintf(&Buf[Size],Lng - Size,
"%s, ",ParTypeNames[(Pars & 0x0F) -
PAR]);
159 Size +=
snprintf(&Buf[Size],Lng - Size,
"\r\n");
166 RESULT Result = FAIL;
172 pFile = fopen(
"../../../bytecodeassembler/o.c",
"w");
173 fprintf(pFile,
"//******************************************************************************\r\n");
174 fprintf(pFile,
"//Test Supported Opcodes in V%4.2f\r\n",VERS);
175 fprintf(pFile,
"//******************************************************************************\r\n\n");
176 fprintf(pFile,
"#define DATA8 LC0(0) \r\n");
177 fprintf(pFile,
"#define DATA16 GV0(0) \r\n");
178 fprintf(pFile,
"#define DATA32 LV0(0) \r\n");
179 fprintf(pFile,
"#define DATAF LC0(0) \r\n");
180 fprintf(pFile,
"#define UNKNOWN LV0(0) \r\n");
181 fprintf(pFile,
"#define STRING LCS,'T','E','S','T',0 \r\n");
182 fprintf(pFile,
"\r\n");
183 fprintf(pFile,
"UBYTE prg[] =\r\n");
184 fprintf(pFile,
"{\r\n");
185 fprintf(pFile,
" PROGRAMHeader(0,2,4),\r\n");
186 fprintf(pFile,
" VMTHREADHeader(0,4),\r\n");
187 fprintf(pFile,
" VMTHREADHeader(0,4),\r\n");
188 fprintf(pFile,
"\r\n");
189 for (OpCode = 0;OpCode < 256;OpCode++)
191 if ((OpCode != opERROR) && (OpCode != opNOP))
194 fprintf(pFile,
"%s",Buffer);
202 fprintf(pFile,
"%s",Buffer);
203 fprintf(pFile,
"\r\n");
204 fprintf(pFile,
"};\r\n\n");
205 fprintf(pFile,
"//******************************************************************************\r\n");
208 if (system(
"~/projects/lms2012/bytecodeassembler/oasm") >= 0)
210 printf(
"Compiling\r\n");
224 RESULT Result = FAIL;
253 RESULT Result = FAIL;
274 OpCode = pI[*pIndex] & 0xFF;
277 if (OpCodes[OpCode].Name)
283 LineLength = printf(
" /* %4d */ %s,",*pIndex,OpCodes[OpCode].Name);
289 if ((OpCode == opOBJECT_END) || (OpCode == opERROR))
298 Pars = OpCodes[OpCode].Pars;
303 ParType = Pars & 0x0F;
309 Sub = *(
DATA8*)pParValue;
321 if (SubCodes[Tab][Sub].Name !=
NULL)
329 LineLength += printf(
"LC1(%s),",SubCodes[Tab][Sub].Name);
333 LineLength += printf(
"LC2(%s),",SubCodes[Tab][Sub].Name);
337 LineLength += printf(
"LC4(%s),",SubCodes[Tab][Sub].Name);
342 LineLength += printf(
"LC0(%s),",SubCodes[Tab][Sub].Name);
346 Pars = SubCodes[Tab][Sub].Pars;
353 Bytes = *(
DATA32*)pParValue;
361 if ((LineLength + 10) >= 80)
363 printf(
"\r\n%*.*s",Indent,Indent,
"");
367 pParValue = (
void*)&Value;
368 ParCode = (
UBYTE)pI[(*pIndex)++] & 0xFF;
377 LineLength += printf(
"HND(");
383 LineLength += printf(
"ADR(");
392 LineLength += printf(
"GV");
397 LineLength += printf(
"LV");
403 Value = (
ULONG)pI[(*pIndex)++];
405 LineLength += printf(
"1(%d)",(
int)Value);
411 Value = (
ULONG)pI[(*pIndex)++];
412 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
414 LineLength += printf(
"2(%d)",(
int)Value);
420 Value = (
ULONG)pI[(*pIndex)++];
421 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
422 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
423 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
425 LineLength += printf(
"4(%d)",(
int)Value);
434 if (ParCode & PRIMPAR_HANDLE)
436 LineLength += printf(
"HND(");
442 LineLength += printf(
"ADR(");
448 Value = (
ULONG)pI[(*pIndex)++];
449 if (Value & 0x00000080)
455 LineLength += printf(
"LAB1(%d)",(
int)(Value & 0xFF));
466 LineLength += printf(
"LCS,");
468 while (pI[(*pIndex)])
471 if ((LineLength + 5) >= 80)
473 printf(
"\r\n%*.*s",Indent,Indent,
"");
477 switch (pI[(*pIndex)])
481 LineLength += printf(
"'\\r',");
487 LineLength += printf(
"'\\n',");
493 LineLength += printf(
"'%c',",pI[(*pIndex)]);
503 if ((LineLength + 2) >= 80)
505 printf(
"\r\n%*.*s",Indent,Indent,
"");
508 LineLength += printf(
"0");
514 Value = (
ULONG)pI[(*pIndex)++];
515 if (Value & 0x00000080)
520 if ((Pars & 0x0f) !=
SUBP)
522 LineLength += printf(
"LC1(%d)",(
int)Value);
529 Value = (
ULONG)pI[(*pIndex)++];
530 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
531 if (Value & 0x00008000)
536 if ((Pars & 0x0f) !=
SUBP)
538 LineLength += printf(
"LC2(%d)",(
int)Value);
545 Value = (
ULONG)pI[(*pIndex)++];
546 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
547 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
548 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
549 if ((Pars & 0x0f) !=
SUBP)
551 LineLength += printf(
"LC4(%ld)",(
long)Value);
559 if (ParCode & PRIMPAR_HANDLE)
561 LineLength += printf(
"),");
567 LineLength += printf(
"),");
571 LineLength += printf(
",");
584 LineLength += printf(
"GV0(%u)",(
unsigned int)(ParCode &
PRIMPAR_INDEX));
589 LineLength += printf(
"LV0(%u)",(
unsigned int)(ParCode &
PRIMPAR_INDEX));
600 Value |= ~(
ULONG)(PRIMPAR_VALUE);
602 LineLength += printf(
"LC0(%d)",(
int)Value);
605 LineLength += printf(
",");
607 if (ParType ==
PARNO)
626 if ((ParType >=
PAR) || (ParType ==
PARNO) || (ParType ==
PARLAB))
629 if ((LineLength + 10) >= 80)
631 printf(
"\r\n%*.*s",Indent,Indent,
"");
635 pParValue = (
void*)&Value;
636 ParCode = (
UBYTE)pI[(*pIndex)++] & 0xFF;
648 LineLength += printf(
"HND(");
654 LineLength += printf(
"ADR(");
663 LineLength += printf(
"GV");
668 LineLength += printf(
"LV");
674 Value = (
ULONG)pI[(*pIndex)++];
676 LineLength += printf(
"1(%d)",(
int)Value);
682 Value = (
ULONG)pI[(*pIndex)++];
683 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
685 LineLength += printf(
"2(%d)",(
int)Value);
691 Value = (
ULONG)pI[(*pIndex)++];
692 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
693 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
694 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
696 LineLength += printf(
"4(%d)",(
int)Value);
705 if (ParCode & PRIMPAR_HANDLE)
707 LineLength += printf(
"HND(");
713 LineLength += printf(
"ADR(");
719 Value = (
ULONG)pI[(*pIndex)++];
720 if (Value & 0x00000080)
726 LineLength += printf(
"LAB1(%d)",(
int)(Value & 0xFF));
737 LineLength += printf(
"LCS,");
739 while (pI[(*pIndex)])
742 if ((LineLength + 5) >= 80)
744 printf(
"\r\n%*.*s",Indent,Indent,
"");
748 switch (pI[(*pIndex)])
752 LineLength += printf(
"'\\r',");
758 LineLength += printf(
"'\\n',");
764 LineLength += printf(
"'%c',",pI[(*pIndex)]);
774 if ((LineLength + 2) >= 80)
776 printf(
"\r\n%*.*s",Indent,Indent,
"");
779 LineLength += printf(
"0");
785 Value = (
ULONG)pI[(*pIndex)++];
786 if (Value & 0x00000080)
791 if ((Pars & 0x0f) !=
SUBP)
793 LineLength += printf(
"LC1(%d)",(
int)Value);
800 Value = (
ULONG)pI[(*pIndex)++];
801 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
802 if (Value & 0x00008000)
807 if ((Pars & 0x0f) !=
SUBP)
809 LineLength += printf(
"LC2(%d)",(
int)Value);
816 Value = (
ULONG)pI[(*pIndex)++];
817 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
818 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
819 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
820 if ((Pars & 0x0f) !=
SUBP)
822 LineLength += printf(
"LC4(%ld)",(
long)Value);
830 if (ParCode & PRIMPAR_HANDLE)
832 LineLength += printf(
"),");
838 LineLength += printf(
"),");
842 LineLength += printf(
",");
855 LineLength += printf(
"GV0(%u)",(
unsigned int)(ParCode &
PRIMPAR_INDEX));
860 LineLength += printf(
"LV0(%u)",(
unsigned int)(ParCode &
PRIMPAR_INDEX));
871 Value |= ~(
ULONG)(PRIMPAR_VALUE);
873 if ((Pars & 0x0f) !=
SUBP)
875 LineLength += printf(
"LC0(%d)",(
int)Value);
879 if ((Pars & 0x0f) !=
SUBP)
881 LineLength += printf(
",");
884 if (ParType ==
PARNO)
907 while (ParType || Parameters);
938 Objects = (*(
IMGHEAD*)pI).NumberOfObjects;
939 Size = (*(
IMGHEAD*)pI).ImageSize;
941 printf(
"\r\n//****************************************************************************");
942 printf(
"\r\n// Disassembler Listing");
943 printf(
"\r\n//****************************************************************************");
944 printf(
"\r\n\nUBYTE prg[] =\r\n{\r\n");
954 printf(
" /* %4u */ PROGRAMHeader(%.2f,%d,%d),\r\n",Addr,(
float)(*pIH).VersionInfo / (
float)100,(*pIH).NumberOfObjects,(*pIH).GlobalBytes);
957 for (ObjIndex = 1;ObjIndex <= Objects;ObjIndex++)
963 if (pOH[ObjIndex].OwnerObjectId)
966 ValidateInstance.
Row = printf(
" /* %4u */ BLOCKHeader(%u,%u,%u),",Addr,(
ULONG)pOH[ObjIndex].OffsetToInstructions,pOH[ObjIndex].OwnerObjectId,pOH[ObjIndex].TriggerCount);
970 if (pOH[ObjIndex].TriggerCount == 1)
973 if (LastOffset == (
ULONG)pOH[ObjIndex].OffsetToInstructions)
976 ValidateInstance.
Row = printf(
" /* %4u */ SUBCALLHeader(%u,%u),",Addr,(
ULONG)pOH[ObjIndex].OffsetToInstructions,pOH[ObjIndex].LocalBytes);
980 ValidateInstance.
Row = printf(
" /* %4u */ SUBCALLHeader(%u,%u),",Addr,(
ULONG)pOH[ObjIndex].OffsetToInstructions,pOH[ObjIndex].LocalBytes);
986 ValidateInstance.
Row = printf(
" /* %4u */ VMTHREADHeader(%u,%u),",Addr,(
ULONG)pOH[ObjIndex].OffsetToInstructions,pOH[ObjIndex].LocalBytes);
989 ValidateInstance.
Row = 41 - ValidateInstance.
Row;
990 if (LastOffset == (
ULONG)pOH[ObjIndex].OffsetToInstructions)
992 printf(
"%*.*s// Object %-3u (Alias for object %u)\r\n",ValidateInstance.
Row,ValidateInstance.
Row,
" ",ObjIndex,LastObject);
996 printf(
"%*.*s// Object %-3u\r\n",ValidateInstance.
Row,ValidateInstance.
Row,
" ",ObjIndex);
998 ValidateInstance.
Row = 0;
999 LastOffset = (
ULONG)pOH[ObjIndex].OffsetToInstructions;
1000 LastObject = ObjIndex;
1004 for (ObjIndex = 1;ObjIndex <= Objects;ObjIndex++)
1007 MinIndex = (
IMINDEX)pOH[ObjIndex].OffsetToInstructions;
1009 if (ObjIndex == Objects)
1015 MaxIndex = (
IMINDEX)pOH[ObjIndex + 1].OffsetToInstructions;
1018 if (pOH[ObjIndex].OwnerObjectId)
1021 printf(
"\r\n /* Object %2d (BLOCK) [%lu..%lu] */\r\n\n",ObjIndex,(
long unsigned int)MinIndex,(
long unsigned int)MaxIndex);
1025 if (pOH[ObjIndex].TriggerCount == 1)
1028 printf(
"\r\n /* Object %2d (SUBCALL) [%lu..%lu] */\r\n\n",ObjIndex,(
long unsigned int)MinIndex,(
long unsigned int)MaxIndex);
1030 ValidateInstance.
Row += printf(
" /* %4d */ ",MinIndex);
1031 TmpIndex = (
IMINDEX)pI[MinIndex++];
1032 printf(
"%u,",TmpIndex);
1035 Type = pI[MinIndex++];
1072 Lng = (
DATA32)pI[MinIndex++];
1073 printf(
"(%d),",Lng);
1086 printf(
"\r\n /* Object %2d (VMTHREAD) [%lu..%lu] */\r\n\n",ObjIndex,(
long unsigned int)MinIndex,(
long unsigned int)MaxIndex);
1091 ValidateInstance.
Row = 0;
1093 for (Index = MinIndex;((MaxIndex == 0) || (Index < MaxIndex)) && (Stop == OK);)
1103 printf(
"\r\n//****************************************************************************\r\n\n");
1157 RESULT Result = FAIL;
1158 RESULT Aligned = OK;
1171 OpCode = pI[*pIndex] & 0xFF;
1173 if (OpCodes[OpCode].Name)
1181 if ((OpCode == opERROR) || (OpCode == opOBJECT_END))
1183 if (OpCode == opOBJECT_END)
1192 if (OpCode == opJR_TRUE)
1197 Pars = OpCodes[OpCode].Pars;
1201 ParType = Pars & 0x0F;
1207 if (ParType ==
SUBP)
1210 Sub = *(
DATA8*)pParValue;
1217 if (SubCodes[Tab][Sub].Name !=
NULL)
1219 Pars = SubCodes[Tab][Sub].Pars;
1228 Bytes = *(
DATA32*)pParValue;
1237 pParValue = (
void*)&Value;
1238 ParCode = (
UBYTE)pI[(*pIndex)++] & 0xFF;
1252 Value = (
ULONG)pI[(*pIndex)++];
1258 Value = (
ULONG)pI[(*pIndex)++];
1259 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1265 Value = (
ULONG)pI[(*pIndex)++];
1266 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1267 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
1268 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
1280 Value = (
ULONG)pI[(*pIndex)++];
1281 if (Value & 0x00000080)
1284 Value |= 0xFFFFFF00;
1295 while (pI[(*pIndex)])
1305 Value = (
ULONG)pI[(*pIndex)++];
1306 if (Value & 0x00000080)
1309 Value |= 0xFFFFFF00;
1316 Value = (
ULONG)pI[(*pIndex)++];
1317 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1318 if (Value & 0x00008000)
1321 Value |= 0xFFFF0000;
1328 Value = (
ULONG)pI[(*pIndex)++];
1329 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1330 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
1331 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
1355 Value |= ~(
ULONG)(PRIMPAR_VALUE);
1363 if (((*(
DATA32*)pParValue) >= ParMin[ParType -
PAR]) && ((*(
DATA32*)pParValue) <= ParMax[ParType -
PAR]))
1385 if ((ParType >=
PAR) || (ParType ==
PARNO) || (ParType ==
PARLAB))
1389 pParValue = (
void*)&Value;
1390 ParCode = (
UBYTE)pI[(*pIndex)++] & 0xFF;
1407 Value = (
ULONG)pI[(*pIndex)++];
1413 Value = (
ULONG)pI[(*pIndex)++];
1414 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1420 Value = (
ULONG)pI[(*pIndex)++];
1421 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1422 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
1423 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
1435 Value = (
ULONG)pI[(*pIndex)++];
1436 if (Value & 0x00000080)
1439 Value |= 0xFFFFFF00;
1450 while (pI[(*pIndex)])
1460 Value = (
ULONG)pI[(*pIndex)++];
1461 if (Value & 0x00000080)
1464 Value |= 0xFFFFFF00;
1471 Value = (
ULONG)pI[(*pIndex)++];
1472 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1473 if (Value & 0x00008000)
1476 Value |= 0xFFFF0000;
1483 Value = (
ULONG)pI[(*pIndex)++];
1484 Value |= ((
ULONG)pI[(*pIndex)++] << 8);
1485 Value |= ((
ULONG)pI[(*pIndex)++] << 16);
1486 Value |= ((
ULONG)pI[(*pIndex)++] << 24);
1510 Value |= ~(
ULONG)(PRIMPAR_VALUE);
1522 if ((ParType >=
PAR8) && (ParType <=
PAR32))
1524 if (((*(
DATA32*)pParValue) >= ParMin[ParType -
PAR]) && ((*(
DATA32*)pParValue) <= ParMax[ParType -
PAR]))
1529 if ((ParType ==
PARF))
1534 if (ParType ==
PARV)
1538 if (ParType ==
PARNO)
1542 if (!(ParCode & PRIMPAR_VARIABEL))
1556 if (!(ParCode & PRIMPAR_VARIABEL))
1563 pLabel[Value].
Addr = *pIndex;
1574 if (ParCode & PRIMPAR_LONG)
1577 if (ParCode & PRIMPAR_VARIABEL)
1613 if (ParCode & PRIMPAR_VARIABEL)
1641 while ((ParType) && (Result == OK));
1665 printf(
"Validation started\r\n");
1671 Objects = (*(
IMGHEAD*)pI).NumberOfObjects;
1676 if ((TotalSize < ImageIndex) || (Objects == 0))
1687 for (ObjIndex = 1;ObjIndex <= Objects;ObjIndex++)
1689 TmpSize += (
IMINDEX)pOH[ObjIndex].OffsetToInstructions;
1694 for (ObjIndex = 1;(ObjIndex <= Objects) && (Result == OK);ObjIndex++)
1696 if (pOH[ObjIndex].OffsetToInstructions == 0)
1702 if ((pOH[ObjIndex].OwnerObjectId == 0) && (pOH[ObjIndex].
TriggerCount == 1))
1705 if (pOH[ObjIndex].OffsetToInstructions >= (
IP)ImageIndex)
1708 ParIndex = (
IMINDEX)pI[ImageIndex++];
1711 Type = pI[ImageIndex++];
1726 while ((Result == OK) && (ImageIndex < TotalSize))
1728 TmpIndex = ImageIndex;
1740 if (ImageIndex != TotalSize)
1743 printf(
"%d %d\r\n",ImageIndex,TotalSize);
1756 printf(
"Validation ended\r\n");
#define PARNO
Defines no of following parameters.
RESULT cValidateDisassemble(IP pI, IMINDEX *pIndex, LABEL *pLabel)
#define PAR8
DATA8 parameter.
ULONG IMINDEX
ImageData index type.
RESULT cValidateExit(void)
RESULT cValidateBytecode(IP pI, IMINDEX *pIndex, LABEL *pLabel)
#define PARF
DATAF parameter.
SLONG DATA32
VM Type for 4 byte signed value.
VALIDATE_GLOBALS ValidateInstance
UWORD OBJID
Object id type.
void ShowOpcode(UBYTE OpCode, char *Buf, int Lng)
#define PAR32
DATA32 parameter.
IMGDATA * IP
Instruction pointer type.
unsigned int ULONG
Basic Type used to symbolise 32 bit unsigned values.
IMINDEX ValidateErrorIndex
RESULT cValidateCheckAlignment(ULONG Value, DATA8 Type)
#define PRIMPAR_CONST_SIGN
#define PAR16
DATA16 parameter.
#define PRIMPAR_STRING_OLD
RESULT cValidateInit(void)
#define MAX_SUBCODES
Max number of sub codes.
#define OPCODE_NAMESIZE
Opcode and sub code name length.
TRIGGER TriggerCount
Used to determine how many triggers needed before the BLOCK object is activated.
void cValidateSetErrorIndex(IMINDEX Index)
IMINDEX ImageSize
Image size.
unsigned char UBYTE
Basic Type used to symbolise 8 bit unsigned values.
#define SUBP
Next nibble is sub parameter table no.
FLOAT DATAF
VM Type for 4 byte floating point value.
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
UBYTE IMGDATA
Image base type.
IMINDEX Addr
Offset to breakpoint address from image start.
#define PARV
Parameter type variable.
IMINDEX cValidateGetErrorIndex(void)
UWORD PRGID
Program id type.
SBYTE DATA8
VM Type for 1 byte signed value.
#define PARVALUES
Last parameter defines number of values to follow.
#define PAR
Plain parameter as below:
#define MAX_LABELS
Max number of labels per program.
#define PARLAB
Defines label no.
RESULT cValidateProgram(PRGID PrgId, IP pI, LABEL *pLabel, DATA8 Disassemble)
RESULT cValidateDisassembleProgram(PRGID PrgId, IP pI, LABEL *pLabel)
IP OffsetToInstructions
Offset to instructions from image start.