Check-in [6599dc94ff]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Remove long stuff in SummerCoat's NativeCPU; Make some adjustments to RatufaCoat (endianess issue still remains)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 6599dc94ffb234937725588f65b0f68aaa80c339
User & Date: stephanie.gawroriski 2019-06-13 13:02:04
Context
2019-06-13
15:45
Add tests for MIPS EB and MIPS EL. check-in: 3fc66ec256 user: stephanie.gawroriski tags: trunk
13:02
Remove long stuff in SummerCoat's NativeCPU; Make some adjustments to RatufaCoat (endianess issue still remains) check-in: 6599dc94ff user: stephanie.gawroriski tags: trunk
07:02
Backup developer notes. check-in: 4e02fc749f user: squirreljme tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ratufacoat/sjmerc.c.

   737    737   	
   738    738   	/* Read single byte value from pointer. */
   739    739   	rv = (sjme_memjreadp(1, ptr) & SJME_JINT_C(0xFF));
   740    740   	
   741    741   	/* Encoded as a 15-bit value? */
   742    742   	if ((rv & SJME_JINT_C(0x80)) != 0)
   743    743   	{
   744         -		rv &= SJME_JINT_C(0x7F);
   745         -		rv <<= SJME_JINT_C(8);
          744  +		rv = (rv & SJME_JINT_C(0x7F)) << SJME_JINT_C(8);
   746    745   		rv |= (sjme_memjreadp(1, ptr) & SJME_JINT_C(0xFF));
   747    746   	}
          747  +
          748  +#if 0
          749  +	fprintf(stderr, "Decode: %d 0x%X\n", (int)rv, (unsigned)rv);
          750  +#endif
   748    751   	
   749    752   	/* Use read value. */
   750    753   	return rv;
   751    754   }
          755  +
          756  +/**
          757  + * Decodes a relative jump offset.
          758  + *
          759  + * @param ptr The pointer to read from.
          760  + * @return The resulting relative jump.
          761  + * @since 2019/06/13
          762  + */
          763  +sjme_jint sjme_opdecodejmp(void** ptr)
          764  +{
          765  +	sjme_jint rv;
          766  +	
          767  +	/* Decode value. */
          768  +	rv = sjme_opdecodeui(ptr);
          769  +	
          770  +	/* Negative branch? */
          771  +	if ((rv & SJME_JINT_C(0x00004000)) != 0)
          772  +		return rv | SJME_JINT_C(0xFFFF8000);
          773  +	return rv;
          774  +}
   752    775   
   753    776   /**
   754    777    * Handles system calls.
   755    778    *
   756    779    * @param jvm The JVM.
   757    780    * @param cpu The CPU.
   758    781    * @param error Error state.
................................................................................
   950    973   			case SJME_ENC_IF_ICMP:
   951    974   				{
   952    975   					/* Values to compare. */
   953    976   					ia = r[sjme_opdecodeui(&nextpc)];
   954    977   					ib = r[sjme_opdecodeui(&nextpc)];
   955    978   					
   956    979   					/* Target PC address. */
   957         -					ic = sjme_opdecodeui(&nextpc);
   958         -					if ((ic & SJME_JINT_C(0x00004000)) != 0)
   959         -						ic |= SJME_JINT_C(0xFFFF8000);
          980  +					ic = sjme_opdecodejmp(&nextpc);
   960    981   					tempp = SJME_POINTER_OFFSET(cpu->pc, ic);
   961    982   					
   962    983   					/* Check depends. */
   963    984   					ic = 0;
   964    985   					switch (op & SJME_ENC_COMPARE_MASK)
   965    986   					{
   966    987   						case SJME_COMPARETYPE_EQUALS:
................................................................................
  1012   1033   			case SJME_ENC_MATH_REG_INT:
  1013   1034   			case SJME_ENC_MATH_CONST_INT:
  1014   1035   				{
  1015   1036   					/* A Value. */
  1016   1037   					ia = r[sjme_opdecodeui(&nextpc)];
  1017   1038   					
  1018   1039   					/* B value. */
  1019         -					ib = (enc == SJME_ENC_MATH_CONST_INT ?
  1020         -						sjme_memjreadp(4, &nextpc) :
  1021         -						r[sjme_opdecodeui(&nextpc)]);
         1040  +					if (enc == SJME_ENC_MATH_CONST_INT)
         1041  +						ib = sjme_memjreadp(4, &nextpc);
         1042  +					else
         1043  +						ib = r[sjme_opdecodeui(&nextpc)];
  1022   1044   					
  1023   1045   					/* Perform the math. */
  1024   1046   					switch (op & SJME_ENC_MATH_MASK)
  1025   1047   					{
  1026   1048   						case SJME_MATH_ADD:
  1027   1049   							ic = ia + ib;
  1028   1050   							break;
................................................................................
  1122   1144   				/* Memory (native byte order). */
  1123   1145   			case SJME_ENC_MEMORY_OFF_REG:
  1124   1146   			case SJME_ENC_MEMORY_OFF_ICONST:
  1125   1147   				{
  1126   1148   					/* Destination/source register. */
  1127   1149   					ic = sjme_opdecodeui(&nextpc);
  1128   1150   					
  1129         -					/* The address to access. */
         1151  +					/* The address and offset to access. */
  1130   1152   					ia = r[sjme_opdecodeui(&nextpc)];
  1131         -					ib = (enc >= SJME_ENC_MEMORY_OFF_ICONST ?
  1132         -						sjme_memjreadp(4, &nextpc) :
  1133         -						r[sjme_opdecodeui(&nextpc)]);
         1153  +					if (enc == SJME_ENC_MEMORY_OFF_ICONST)
         1154  +						ib = sjme_memjreadp(4, &nextpc);
         1155  +					else
         1156  +						ib = r[sjme_opdecodeui(&nextpc)];
  1134   1157   					tempp = SJME_JINT_TO_POINTER(ia);
  1135   1158   					
  1136   1159   					/* Load value */
  1137   1160   					if ((op & SJME_MEM_LOAD_MASK) != 0)
  1138   1161   					{
  1139   1162   						switch (op & SJME_MEM_DATATYPE_MASK)
  1140   1163   						{
................................................................................
  1190   1213   			case SJME_ENC_MEMORY_OFF_ICONST_JAVA:
  1191   1214   				{
  1192   1215   					/* Destination/source register. */
  1193   1216   					ic = sjme_opdecodeui(&nextpc);
  1194   1217   					
  1195   1218   					/* The address to access. */
  1196   1219   					ia = r[sjme_opdecodeui(&nextpc)];
  1197         -					ib = (enc >= SJME_ENC_MEMORY_OFF_ICONST ?
  1198         -						sjme_memjreadp(4, &nextpc) :
  1199         -						r[sjme_opdecodeui(&nextpc)]);
         1220  +					if (enc == SJME_ENC_MEMORY_OFF_ICONST_JAVA)
         1221  +						ib = sjme_memjreadp(4, &nextpc);
         1222  +					else
         1223  +						ib = r[sjme_opdecodeui(&nextpc)];
  1200   1224   					tempp = SJME_JINT_TO_POINTER(ia);
  1201   1225   					
  1202   1226   					/* Load value */
  1203   1227   					if ((op & SJME_MEM_LOAD_MASK) != 0)
  1204   1228   					{
  1205   1229   						switch (op & SJME_MEM_DATATYPE_MASK)
  1206   1230   						{
................................................................................
  1311   1335   			case SJME_OP_DEBUG_EXIT:
  1312   1336   				break;
  1313   1337   				
  1314   1338   				/* Debug point. */
  1315   1339   			case SJME_OP_DEBUG_POINT:
  1316   1340   				{
  1317   1341   					cpu->debugline = sjme_opdecodeui(&nextpc);
  1318         -					cpu->debugjop = sjme_opdecodeui(&nextpc);
         1342  +					cpu->debugjop = (sjme_opdecodeui(&nextpc) &
         1343  +						SJME_JINT_C(0xFF));
  1319   1344   					cpu->debugjpc = sjme_opdecodeui(&nextpc);
  1320   1345   				}
  1321   1346   				break;
  1322   1347   				
  1323   1348   				/* If equal to constant? */
  1324   1349   			case SJME_OP_IFEQ_CONST:
  1325   1350   				{
................................................................................
  1326   1351   					/* A value. */
  1327   1352   					ia = r[sjme_opdecodeui(&nextpc)];
  1328   1353   					
  1329   1354   					/* B value. */
  1330   1355   					ib = sjme_memjreadp(4, &nextpc);
  1331   1356   					
  1332   1357   					/* Target PC address. */
  1333         -					ic = sjme_opdecodeui(&nextpc);
  1334         -					if ((ic & SJME_JINT_C(0x00004000)) != 0)
  1335         -						ic |= SJME_JINT_C(0xFFFF8000);
         1358  +					ic = sjme_opdecodejmp(&nextpc);
  1336   1359   					tempp = SJME_POINTER_OFFSET(cpu->pc, ic);
  1337   1360   					
  1338   1361   					/* Jump on equals? */
  1339   1362   					if (ia == ib)
  1340   1363   						nextpc = tempp;
  1341   1364   				}
  1342   1365   				break;
................................................................................
  1355   1378   					}
  1356   1379   					
  1357   1380   					/* Copy and store state. */
  1358   1381   					*oldcpu = *cpu;
  1359   1382   					cpu->parent = oldcpu;
  1360   1383   					
  1361   1384   					/* Setup CPU state for invoke run, move pool up. */
  1362         -					for (ia = SJME_ARGBASE_REGISTER;
         1385  +					for (ia = SJME_LOCAL_REGISTER_BASE;
  1363   1386   						ia < SJME_MAX_REGISTERS; ia++)
  1364   1387   						r[ia] = 0;
  1365         -					r[SJME_POOL_REGISTER] = r[SJME_NEXT_POOL_REGISTER];
         1388  +					r[SJME_POOL_REGISTER] =
         1389  +						oldcpu->r[SJME_NEXT_POOL_REGISTER];
         1390  +					r[SJME_NEXT_POOL_REGISTER] = 0;
  1366   1391   					
  1367   1392   					/* The address to execute. */
  1368   1393   					ia = oldcpu->r[sjme_opdecodeui(&nextpc)];
  1369   1394   					
  1370   1395   					/* Load in register list (wide). */
  1371   1396   					ib = sjme_memjreadp(1, &nextpc);
  1372   1397   					if ((ib & SJME_JINT_C(0x80)) != 0)
................................................................................
  1387   1412   					{
  1388   1413   						/* Read values. */
  1389   1414   						for (ic = 0; ic < ib; ic++)
  1390   1415   							r[SJME_ARGBASE_REGISTER + ic] =
  1391   1416   								oldcpu->r[sjme_memjreadp(1, &nextpc)];
  1392   1417   					}
  1393   1418   					
         1419  +#if 0
         1420  +					fprintf(stderr, "Invoke: %08lx\n", (long)ia);
         1421  +					for (ic = 0; ic < ib; ic++)
         1422  +						fprintf(stderr, "A%d: %d\n",
         1423  +							(int)ic, (int)r[SJME_ARGBASE_REGISTER + ic]);
         1424  +#endif
         1425  +					
  1394   1426   					/* Old PC address resumes where this read ended. */
  1395   1427   					oldcpu->pc = nextpc;
  1396   1428   					
  1397   1429   					/* Our next PC becomes the target address. */
  1398   1430   					nextpc = SJME_JINT_TO_POINTER(ia);
  1399   1431   					cpu->pc = nextpc;
  1400   1432   				}

Changes to runt/libs/summercoat-vm/cc/squirreljme/vm/summercoat/NativeCPU.java.

   170    170   		Frame nowframe = null;
   171    171   		int[] lr = null;
   172    172   		int pc = -1,
   173    173   			rp = -1;
   174    174   		
   175    175   		// Per operation handling
   176    176   		final int[] args = new int[6];
   177         -		final long[] largs = new long[6];
   178    177   		
   179    178   		// Method cache to reduce tons of method reads
   180    179   		final byte[] icache = new byte[METHOD_CACHE];
   181    180   		int lasticache = -(METHOD_CACHE_SPILL + 1);
   182    181   		
   183    182   		// Execution is effectively an infinite loop
   184    183   		LinkedList<Frame> frames = this._frames;
................................................................................
   232    231   			
   233    232   			// Read operation
   234    233   			nowframe._lastpc = pc;
   235    234   			int op = icache[bpc] & 0xFF;
   236    235   			
   237    236   			// Reset all input arguments
   238    237   			for (int i = 0, n = args.length; i < n; i++)
   239         -			{
   240    238   				args[i] = 0;
   241         -				largs[i] = 0;
   242         -			}
   243    239   			
   244    240   			// Register list, just one is used everywhere
   245    241   			int[] reglist = null;
   246    242   			
   247    243   			// Load arguments for this instruction
   248    244   			ArgumentFormat[] af = NativeInstruction.argumentFormat(op);
   249    245   			int rargp = bpc + 1;
................................................................................
   307    303   					case FLOAT32:
   308    304   						args[i] = ((icache[rargp++] & 0xFF) << 24) |
   309    305   							((icache[rargp++] & 0xFF) << 16) |
   310    306   							((icache[rargp++] & 0xFF) << 8) |
   311    307   							((icache[rargp++] & 0xFF));
   312    308   						break;
   313    309   					
   314         -					// 64-bit long/double
   315         -					case INT64:
   316         -					case FLOAT64:
   317         -						largs[i] = ((icache[rargp++] & 0xFFL) << 56L) |
   318         -							((icache[rargp++] & 0xFFL) << 48L) |
   319         -							((icache[rargp++] & 0xFFL) << 40L) |
   320         -							((icache[rargp++] & 0xFFL) << 32L) |
   321         -							((icache[rargp++] & 0xFFL) << 24L) |
   322         -							((icache[rargp++] & 0xFFL) << 16L) |
   323         -							((icache[rargp++] & 0xFFL) << 8L) |
   324         -							((icache[rargp++] & 0xFFL));
   325         -						break;
   326         -					
   327    310   					default:
   328    311   						throw new todo.OOPS(af[i].name());
   329    312   				}
   330    313   			
   331    314   			// Print CPU debug info
   332    315   			int encoding = NativeInstruction.encoding(op);
   333    316   			if (ENABLE_DEBUG &&
   334    317   				encoding != NativeInstructionType.DEBUG_ENTRY &&
   335    318   				encoding != NativeInstructionType.DEBUG_EXIT &&
   336    319   				encoding != NativeInstructionType.DEBUG_POINT)
   337         -				this.__cpuDebugPrint(nowframe, op, af, args, largs, reglist);
          320  +				this.__cpuDebugPrint(nowframe, op, af, args, reglist);
   338    321   			
   339    322   			// By default the next instruction is the address after all
   340    323   			// arguments have been read
   341    324   			int nextpc = lasticache + rargp;
   342    325   			
   343    326   			// Handle the operation
   344    327   			switch (encoding)
   345    328   			{
   346    329   					// CPU Breakpoint
   347    330   				case NativeInstructionType.BREAKPOINT:
   348         -					this.__cpuDebugPrint(nowframe, op, af, args, largs,
   349         -						reglist);
          331  +					this.__cpuDebugPrint(nowframe, op, af, args, reglist);
   350    332   					
   351    333   					// {@squirreljme.error AE04 CPU breakpoint hit.}
   352    334   					throw new VMException("AE04");
   353    335   				
   354    336   					// Debug entry point of method
   355    337   				case NativeInstructionType.DEBUG_ENTRY:
   356    338   					this.__debugEntry(nowframe, args[0], args[1], args[2]);
   357    339   					
   358    340   					// Trace it!
   359    341   					if (ENABLE_DEBUG)
   360         -						this.__cpuDebugPrint(nowframe, op, af, args, largs,
   361         -							reglist);
          342  +						this.__cpuDebugPrint(nowframe, op, af, args, reglist);
   362    343   					break;
   363    344   					
   364    345   					// Debug exit of method
   365    346   				case NativeInstructionType.DEBUG_EXIT:
   366    347   					break;
   367    348   					
   368    349   					// Debug point in method.
................................................................................
   736    717   	/**
   737    718   	 * Performs some nice printing of CPU information.
   738    719   	 *
   739    720   	 * @param __nf The current frame.
   740    721   	 * @param __op The operation.
   741    722   	 * @param __af The argument format.
   742    723   	 * @param __args Argument values.
   743         -	 * @param __largs Long argument values.
   744    724   	 * @param __reglist The register list.
   745    725   	 * @since 2019/04/23
   746    726   	 */
   747    727   	private final void __cpuDebugPrint(Frame __nf, int __op,
   748         -		ArgumentFormat[] __af, int[] __args, long[] __largs, int[] __reglist)
          728  +		ArgumentFormat[] __af, int[] __args, int[] __reglist)
   749    729   	{
   750    730   		PrintStream out = System.err;
   751    731   		
   752    732   		// Limit class name
   753    733   		CallTraceElement trace = this.trace(__nf);
   754    734   		String cname = "" + trace.className();
   755    735   		int nl;