Home     Blog    News    Twitter    Google+    Contact

jState - Javascript Examples

Display Cortex-M3 Core Registers after each Simulated Instruction Step

console.clear();

var afterstep = function(event)
{
	for (var i = 0; i < 16; i++)
	{
        // output registers R0 to R15
		var property = "R" + i;
		console.log(property, ": 0X", jState.core[property].toString(16));
		if (((i + 1) % 4) == 0)
			console.log("\n");
		else
			console.log("\t");
	}
	console.log("xPSR: 0X", jState.core.xPSR.toString(16));
	console.log("MSP: 0X", jState.core.MSP.toString(16));
	console.log("PSP: 0X", jState.core.PSP.toString(16));
	console.log("CONTROL: 0X", jState.core.CONTROL.toString(16), "\n");
	console.log("PRIMASK: 0X", jState.core.PRIMASK.toString(16));
	console.log("FAULTMASK: 0X", jState.core.FAULTMASK.toString(16));
	console.log("BASEPRI: 0X", jState.core.BASEPRI.toString(16), "\n");
	console.log("Machine Cycles:", event.machinecycles, "\n");
}

jState.core.addEventListener("afterstep", afterstep, false);

Check every 500 machine cycles, halt simulation every ~4000 machine cycles

console.clear();

var interval = function(event)
{
	console.log("Interval counter called\n");
	console.log("Trip Counter:", event.tripcounter, "\n");
	console.log("Last Command Counter:", event.lastcommandcounter, "\n");
	console.log("Machine Cycles:", event.machinecycles, "\n");
	if (event.lastcommandcounter > 4000)
		jState.core.halt = true;
}

var hInterval = jState.core.setInterval(interval, 500);