improved API between MSP430 and MSP430Core and fixed debug-printouts

This commit is contained in:
Joakim Eriksson 2011-08-31 17:48:15 +02:00
parent e53500c3e2
commit d0d6c86bd2
2 changed files with 40 additions and 35 deletions

View File

@ -101,7 +101,8 @@ public class MSP430 extends MSP430Core {
}
private void run() throws EmulationException {
while (isRunning()) {
int pc;
while (isRunning()) {
// -------------------------------------------------------------------
// Debug information
// -------------------------------------------------------------------
@ -118,14 +119,14 @@ public class MSP430 extends MSP430Core {
nextOut = cycles + 20000007;
}
if (emulateOP(-1)) {
if ((pc = emulateOP(-1)) >= 0) {
instCtr++;
if (execCounter != null) {
execCounter[reg[PC]]++;
execCounter[pc]++;
}
if (trace != null) {
trace[tracePos++] = reg[PC];
trace[tracePos++] = pc;
if (tracePos >= trace.length)
tracePos = 0;
}
@ -163,25 +164,25 @@ public class MSP430 extends MSP430Core {
while (count-- > 0 && isRunning()) {
if (debug) {
if (servicedInterrupt >= 0) {
disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt);
} else {
disAsm.disassemble(reg[PC], memory, reg);
}
}
boolean emuOP = emulateOP(-1);
if (emuOP) {
int pc = emulateOP(-1);
if (pc >= 0) {
if (execCounter != null) {
execCounter[reg[PC]]++;
execCounter[pc]++;
}
if (trace != null) {
trace[tracePos++] = reg[PC];
trace[tracePos++] = pc;
if (tracePos > trace.length)
tracePos = 0;
}
}
if (debug) {
if (servicedInterrupt >= 0) {
disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt);
} else {
disAsm.disassemble(reg[PC], memory, reg);
}
}
}
setRunning(false);
return cycles;
@ -206,6 +207,7 @@ public class MSP430 extends MSP430Core {
*/
long maxCycles = 0;
public long stepMicros(long jumpMicros, long executeMicros) throws EmulationException {
int pc;
if (isRunning()) {
throw new IllegalStateException("step not possible when CPU is running");
}
@ -249,20 +251,9 @@ public class MSP430 extends MSP430Core {
/*System.out.println("Current cycles: " + cycles + " additional micros: " + (jumpMicros) +
" exec micros: " + executeMicros + " => Execute until cycles: " + maxCycles);*/
// -------------------------------------------------------------------
// Debug information
// -------------------------------------------------------------------
if (debug) {
if (servicedInterrupt >= 0) {
disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt);
} else {
disAsm.disassemble(reg[PC], memory, reg);
}
}
while (cycles < maxCycles || (cpuOff && (nextEventCycles < cycles))) {
if (emulateOP(maxCycles)) {
if ((pc = emulateOP(maxCycles)) >= 0) {
if (execCounter != null) {
execCounter[reg[PC]]++;
}
@ -270,7 +261,17 @@ public class MSP430 extends MSP430Core {
if (tracePos > trace.length) {
tracePos = 0;
}
trace[tracePos++] = reg[PC];
trace[tracePos++] = pc;
}
// -------------------------------------------------------------------
// Debug information
// -------------------------------------------------------------------
if (debug) {
if (servicedInterrupt >= 0) {
disAsm.disassemble(pc, memory, reg, servicedInterrupt);
} else {
disAsm.disassemble(pc, memory, reg);
}
}
}
}

View File

@ -167,6 +167,8 @@ public class MSP430Core extends Chip implements MSP430Constants {
memory = new int[MAX_MEM];
breakPoints = new CPUMonitor[MAX_MEM];
System.out.println("Set up MSP430 Core with " + MAX_MEM + " bytes memory");
/* this is for detecting writes/read to/from non-existing IO */
IOUnit voidIO = new IOUnit(id, memory, 0) {
@ -614,7 +616,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
}
private void internalReset() {
for (int i = 0, n = 16; i < n; i++) {
for (int i = 0, n = 64; i < n; i++) {
interruptSource[i] = null;
}
servicedInterruptUnit = null;
@ -896,7 +898,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
}
/* returns true if any instruction was emulated - false if CpuOff */
public boolean emulateOP(long maxCycles) throws EmulationException {
public int emulateOP(long maxCycles) throws EmulationException {
//System.out.println("CYCLES BEFORE: " + cycles);
int pc = readRegister(PC);
long startCycles = cycles;
@ -926,7 +928,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
if (interruptsEnabled && interruptMax > 0) {
/* can not allow for jumping to nextEventCycles since that would jump too far */
return false;
return -1;
}
if (maxCycles >= 0 && maxCycles < nextEventCycles) {
@ -935,7 +937,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
} else {
cycles = nextEventCycles;
}
return false;
return -1;
}
// This is quite costly... should probably be made more
@ -944,7 +946,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
if (breakpointActive) {
breakPoints[pc].cpuAction(CPUMonitor.EXECUTE, pc, 0);
breakpointActive = false;
return false;
return -1;
}
// Execute this instruction - this is second call...
breakpointActive = true;
@ -953,6 +955,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
globalMonitor.cpuAction(CPUMonitor.EXECUTE, pc, 0);
}
int pcBefore = pc;
instruction = read(pc, MODE_WORD);
/* check for extension words */
@ -1275,7 +1278,7 @@ public class MSP430Core extends Chip implements MSP430Constants {
jump = true;
break;
default:
logw("Not implemented instruction: " + Utils.binary16(instruction));
logw("Not implemented instruction: #" + Utils.binary16(instruction));
}
// Perform the Jump
if (jump) {
@ -1569,7 +1572,8 @@ public class MSP430Core extends Chip implements MSP430Constants {
cpuCycles += cycles - startCycles;
return true;
/* return the address that was executed */
return pcBefore;
}
public int getModeMax() {