Check-in [3d58c78266]

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

Overview
Comment:Add unaligned memory access when decoding operations (since those are the only ones technically able to be unaligned).
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3d58c782668037fd489133402e60057da8eacd57
User & Date: stephanie.gawroriski 2019-06-16 19:15:58
Context
2019-06-16
19:44
Add debug points for at-end generated handlers; If the JPC is invalid do not throw an exception in SXS. check-in: 3ce5be8da6 user: stephanie.gawroriski tags: trunk
19:15
Add unaligned memory access when decoding operations (since those are the only ones technically able to be unaligned). check-in: 3d58c78266 user: stephanie.gawroriski tags: trunk
18:47
Do check for exception before doing the return value copy (so it does not get copied, check exception first). check-in: 2264af4f54 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ratufacoat/sjmerc.c.

875
876
877
878
879
880
881
882
883












































884
885

886
887
888
889
890
891
892
....
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
....
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
....
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
....
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
....
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
{
	/* Write pointer value. */
	sjme_memjwrite(jvm, size, *ptr, 0, value);
	
	/* Increment pointer. */
	*ptr = SJME_POINTER_OFFSET_LONG(*ptr, size);
}

/**












































 * Decodes a variable unsigned int operation argument.
 *

 * @param ptr The pointer to read from.
 * @return The resulting decoded value.
 * @since 2019/06/09
 */
sjme_jint sjme_opdecodeui(sjme_jvm* jvm, void** ptr)
{
	sjme_jint rv;
................................................................................
			case SJME_ENC_MATH_CONST_INT:
				{
					/* A Value. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* B value. */
					if (enc == SJME_ENC_MATH_CONST_INT)
						ib = sjme_memjreadp(jvm, 4, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* Perform the math. */
					switch (op & SJME_ENC_MATH_MASK)
					{
						case SJME_MATH_ADD:
................................................................................
				{
					/* Destination/source register. */
					ic = sjme_opdecodeui(jvm, &nextpc);
					
					/* The address and offset to access. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					if (enc == SJME_ENC_MEMORY_OFF_ICONST)
						ib = sjme_memjreadp(jvm, 4, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					tempp = SJME_JINT_TO_POINTER(ia);
					
					/* Load value */
					if ((op & SJME_MEM_LOAD_MASK) != 0)
					{
................................................................................
				{
					/* Destination/source register. */
					ic = sjme_opdecodeui(jvm, &nextpc);
					
					/* The address to access. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					if (enc == SJME_ENC_MEMORY_OFF_ICONST_JAVA)
						ib = sjme_memjreadp(jvm, 4, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					tempp = SJME_JINT_TO_POINTER(ia);
					
					/* Load value */
					if ((op & SJME_MEM_LOAD_MASK) != 0)
					{
................................................................................
				/* If equal to constant? */
			case SJME_OP_IFEQ_CONST:
				{
					/* A value. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* B value. */
					ib = sjme_memjreadp(jvm, 4, &nextpc);
					
					/* Target PC address. */
					ic = sjme_opdecodejmp(jvm, &nextpc);
					tempp = SJME_POINTER_OFFSET(cpu->pc, ic);
					
					/* Jump on equals? */
					if (ia == ib)
................................................................................
						ib <<= 8;
						ib |= (sjme_memjreadp(jvm, 1, &nextpc) &
							SJME_JINT_C(0xFF));
						
						/* Read values. */
						for (ic = 0; ic < ib; ic++)
							r[SJME_ARGBASE_REGISTER + ic] =
								oldcpu->r[sjme_memjreadp(jvm, 2, &nextpc)];
					}
					
					/* Narrow format list. */
					else
					{
						/* Read values. */
						for (ic = 0; ic < ib; ic++)









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>







 







|







 







|







 







|







 







|







 







|







875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
....
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
....
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
....
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
....
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
....
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
{
	/* Write pointer value. */
	sjme_memjwrite(jvm, size, *ptr, 0, value);
	
	/* Increment pointer. */
	*ptr = SJME_POINTER_OFFSET_LONG(*ptr, size);
}

/**
 * Decodes an integer value from operations which could be unaligned.
 *
 * @param jvm The JVM.
 * @param ptr The pointer to read from.
 * @return The resulting read value.
 * @since 2019/06/16
 */
sjme_jint sjme_opdecodejint(sjme_jvm* jvm, void** ptr)
{
	sjme_jint rv;
	
	/* Read all values. */
	rv = (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF)) << 24;
	rv |= (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF)) << 16;
	rv |= (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF)) << 8;
	rv |= (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF));
	
	return rv;
}

/**
 * Decodes a short value from operations which could be unaligned.
 *
 * @param jvm The JVM.
 * @param ptr The pointer to read from.
 * @return The resulting read value.
 * @since 2019/06/16
 */
sjme_jint sjme_opdecodejshort(sjme_jvm* jvm, void** ptr)
{
	sjme_jint rv;
	
	/* Read all values. */
	rv = (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF)) << 8;
	rv |= (sjme_memjreadp(jvm, 1, ptr) & SJME_JINT_C(0xFF));
	
	/* Sign extend? */
	if (rv & SJME_JINT_C(0x8000))
		rv |= SJME_JINT_C(0xFFFF0000);
	
	return rv;
}

/**
 * Decodes a variable unsigned int operation argument.
 *
 * @param jvm The JVM.
 * @param ptr The pointer to read from.
 * @return The resulting decoded value.
 * @since 2019/06/09
 */
sjme_jint sjme_opdecodeui(sjme_jvm* jvm, void** ptr)
{
	sjme_jint rv;
................................................................................
			case SJME_ENC_MATH_CONST_INT:
				{
					/* A Value. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* B value. */
					if (enc == SJME_ENC_MATH_CONST_INT)
						ib = sjme_opdecodejint(jvm, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* Perform the math. */
					switch (op & SJME_ENC_MATH_MASK)
					{
						case SJME_MATH_ADD:
................................................................................
				{
					/* Destination/source register. */
					ic = sjme_opdecodeui(jvm, &nextpc);
					
					/* The address and offset to access. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					if (enc == SJME_ENC_MEMORY_OFF_ICONST)
						ib = sjme_opdecodejint(jvm, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					tempp = SJME_JINT_TO_POINTER(ia);
					
					/* Load value */
					if ((op & SJME_MEM_LOAD_MASK) != 0)
					{
................................................................................
				{
					/* Destination/source register. */
					ic = sjme_opdecodeui(jvm, &nextpc);
					
					/* The address to access. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					if (enc == SJME_ENC_MEMORY_OFF_ICONST_JAVA)
						ib = sjme_opdecodejint(jvm, &nextpc);
					else
						ib = r[sjme_opdecodeui(jvm, &nextpc)];
					tempp = SJME_JINT_TO_POINTER(ia);
					
					/* Load value */
					if ((op & SJME_MEM_LOAD_MASK) != 0)
					{
................................................................................
				/* If equal to constant? */
			case SJME_OP_IFEQ_CONST:
				{
					/* A value. */
					ia = r[sjme_opdecodeui(jvm, &nextpc)];
					
					/* B value. */
					ib = sjme_opdecodejint(jvm, &nextpc);
					
					/* Target PC address. */
					ic = sjme_opdecodejmp(jvm, &nextpc);
					tempp = SJME_POINTER_OFFSET(cpu->pc, ic);
					
					/* Jump on equals? */
					if (ia == ib)
................................................................................
						ib <<= 8;
						ib |= (sjme_memjreadp(jvm, 1, &nextpc) &
							SJME_JINT_C(0xFF));
						
						/* Read values. */
						for (ic = 0; ic < ib; ic++)
							r[SJME_ARGBASE_REGISTER + ic] =
								oldcpu->r[sjme_opdecodejshort(jvm, &nextpc)];
					}
					
					/* Narrow format list. */
					else
					{
						/* Read values. */
						for (ic = 0; ic < ib; ic++)