You can subscribe to this list here.
| 2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
| 2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
| 2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
| 2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
| 2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
| 2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: Carolina L. M. <cle...@ho...> - 2014-05-07 16:03:18
|
Hi everyone. Im a new using cooja, im using the powertrace in my code trying to see the consumption of energy in a part of the code. I getting this error after 1 min running cooja, somebody can tell me what happens? Executing MSP430X instruction but MCU is not a MSP430X Stack Trace: number of calls: 7 PC: $08bd2 print_field (local in ./stdlib/vuprintf.c) called from PC: $09d82 (elapsed: 1139) vuprintf (./stdlib/vuprintf.c) called from PC: $09620 (elapsed: 111883) printf (./stdlib/printf.c) called from PC: $076a0 (elapsed: 111894) powertrace_print (memset.c) called from PC: $07998 (elapsed: 120143) process_thread_powertrace_process (local in powertrace.c) called from PC: $05e6e (elapsed: 120471) call_process (local in process.c) called from PC: $06012 (elapsed: 120506) process_run (memset.c) called from PC: $04252 (elapsed: 121584) The cooja crash after 1minute of running, giving me some stadistisc of the powertrace but not enough for my research. 00:00.520 ID:2 Rime started with address 2.0 00:00.528 ID:2 MAC 02:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 2. 00:00.537 ID:2 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:00.541 ID:2 Starting 'Broadcast process' 'Unicast process' 00:00.667 ID:1 Rime started with address 1.0 00:00.674 ID:1 MAC 01:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 1. 00:00.683 ID:1 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:00.687 ID:1 Starting 'Broadcast process' 'Unicast process' 00:01.184 ID:3 Rime started with address 3.0 00:01.192 ID:3 MAC 03:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 3. 00:01.200 ID:3 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:01.204 ID:3 Starting 'Broadcast process' 'Unicast process' 00:25.736 ID:2 Serv solicitado: 1 00:25.739 ID:2 Solicitando (S1) al nodo 3, tl 1. 00:25.742 ID:2 Conteo confianza [3, 2] = 10 00:25.822 ID:3 unicast ping received from 2 00:30.567 ID:2 3844 P 2.0 0 44343 128133 2316 7597 0 5844 4434 937330 2316 7597 0 5844 (radko 1.00% / 1.00% tx 0.23% / 0.23% listen 0.77% / 0.77%) 00:30.713 ID:1 3844 P 1.0 0 41779 128824 1384 6098 0 5906 4177 940244 1384 6098 0 5906 (radko 0.76% / 0.76% tx 0.14% / 0.14% listen 0.62% / 0.62%) 00:31.230 ID:3 3844 P 3.0 0 44410 128129 2403 7772 0 5843 4441 937299 2403 7772 0 5843 (radko 1.03% / 1.03% tx 0.24% / 0.24% listen 0.79% / 0.79%) 00:33.547 ID:3 Serv solicitado: 1 00:33.550 ID:3 Solicitando (S1) al nodo 2, tl 2. 00:33.553 ID:3 Conteo confianza [2, 3] = 10 00:33.659 ID:2 unicast ping received from 3 00:34.124 ID:1 Serv solicitado: 1 00:34.127 ID:1 Solicitando (S1) al nodo 2, tl 1. 00:34.130 ID:1 Conteo confianza [2, 1] = 10 00:34.159 ID:2 unicast ping received from 1 00:34.712 ID:2 Serv solicitado: 1 00:34.715 ID:2 Solicitando (S1) al nodo 1, tl 2. 00:34.718 ID:2 Conteo confianza [1, 2] = 10 00:43.108 ID:1 Serv solicitado: 2 00:43.111 ID:1 Solicitando (S2) al nodo 2, tl 1. 00:43.114 ID:1 Conteo confianza [2, 1] = 15 00:43.160 ID:2 unicast ping received from 1 00:43.720 ID:2 Serv solicitado: 3 00:43.723 ID:2 Solicitando (S3) al nodo 1, tl 2. 00:43.726 ID:2 Conteo confianza [1, 2] = 12 00:43.807 ID:1 unicast ping received from 2 00:46.735 ID:3 Serv solicitado: 2 00:46.738 ID:3 Solicitando (S2) al nodo 2, tl 2. 00:46.740 ID:3 Conteo confianza [2, 3] = 15 00:46.785 ID:2 unicast ping received from 3 00:53.023 ID:1 Serv solicitado: 2 00:53.025 ID:1 Solicitando (S2) al nodo 2, tl 1. 00:53.028 ID:1 Conteo confianza [2, 1] = 20 00:53.752 ID:2 Serv solicitado: 1 00:53.754 ID:2 Solicitando (S1) al nodo 3, tl 2. 00:53.757 ID:2 Conteo confianza [3, 2] = 20 00:53.822 ID:3 unicast ping received from 2 00:55.266 ID:3 Serv solicitado: 1 00:55.269 ID:3 Solicitando (S1) al nodo 2, tl 2. 00:55.272 ID:3 Conteo confianza [2, 3] = 25 01:00.585 ID:2 7684 P 2.0 1 80091 12801 948213240 48331 65538451 3676712 35745 395001858 948210924 40734 94896123 3670868 (radio 333.-29709% / 1242.1876% tx 329.-29788% / 12275.1906% listen 4.79% / 150.69%) 01:00.731 ID:1 7684 P 1.0 1 80158 12879 948213423 48286 65538544 3350520 38376 395009565 948212039 42188 94830592 3344614 (radio 333.-29708% / 1257.-10505% tx 329.-29786% / 12417.-10587% listen 4.78% / 157.82%) Thanks in advance. Carolina |
|
From: Carolina L. M. <cle...@ho...> - 2014-05-07 15:41:41
|
Hi everyone. Im a new using cooja, im using the powertrace in my code trying to see the consumption of energy in a part of the code. I getting this error after 1 min running cooja, somebody can tell me what happens? Executing MSP430X instruction but MCU is not a MSP430X Stack Trace: number of calls: 7 PC: $08bd2 print_field (local in ./stdlib/vuprintf.c) called from PC: $09d82 (elapsed: 1139) vuprintf (./stdlib/vuprintf.c) called from PC: $09620 (elapsed: 111883) printf (./stdlib/printf.c) called from PC: $076a0 (elapsed: 111894) powertrace_print (memset.c) called from PC: $07998 (elapsed: 120143) process_thread_powertrace_process (local in powertrace.c) called from PC: $05e6e (elapsed: 120471) call_process (local in process.c) called from PC: $06012 (elapsed: 120506) process_run (memset.c) called from PC: $04252 (elapsed: 121584) The cooja crash after 1minute of running, giving me some stadistisc of the powertrace but not enough for my research. 00:00.520 ID:2 Rime started with address 2.0 00:00.528 ID:2 MAC 02:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 2. 00:00.537 ID:2 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:00.541 ID:2 Starting 'Broadcast process' 'Unicast process' 00:00.667 ID:1 Rime started with address 1.0 00:00.674 ID:1 MAC 01:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 1. 00:00.683 ID:1 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:00.687 ID:1 Starting 'Broadcast process' 'Unicast process' 00:01.184 ID:3 Rime started with address 3.0 00:01.192 ID:3 MAC 03:00:00:00:00:00:00:00 Contiki 2.7 started. Node id is set to 3. 00:01.200 ID:3 CSMA ContikiMAC, channel check rate 8 Hz, radio channel 26 00:01.204 ID:3 Starting 'Broadcast process' 'Unicast process' 00:25.736 ID:2 Serv solicitado: 1 00:25.739 ID:2 Solicitando (S1) al nodo 3, tl 1. 00:25.742 ID:2 Conteo confianza [3, 2] = 10 00:25.822 ID:3 unicast ping received from 2 00:30.567 ID:2 3844 P 2.0 0 44343 128133 2316 7597 0 5844 4434 937330 2316 7597 0 5844 (radko 1.00% / 1.00% tx 0.23% / 0.23% listen 0.77% / 0.77%) 00:30.713 ID:1 3844 P 1.0 0 41779 128824 1384 6098 0 5906 4177 940244 1384 6098 0 5906 (radko 0.76% / 0.76% tx 0.14% / 0.14% listen 0.62% / 0.62%) 00:31.230 ID:3 3844 P 3.0 0 44410 128129 2403 7772 0 5843 4441 937299 2403 7772 0 5843 (radko 1.03% / 1.03% tx 0.24% / 0.24% listen 0.79% / 0.79%) 00:33.547 ID:3 Serv solicitado: 1 00:33.550 ID:3 Solicitando (S1) al nodo 2, tl 2. 00:33.553 ID:3 Conteo confianza [2, 3] = 10 00:33.659 ID:2 unicast ping received from 3 00:34.124 ID:1 Serv solicitado: 1 00:34.127 ID:1 Solicitando (S1) al nodo 2, tl 1. 00:34.130 ID:1 Conteo confianza [2, 1] = 10 00:34.159 ID:2 unicast ping received from 1 00:34.712 ID:2 Serv solicitado: 1 00:34.715 ID:2 Solicitando (S1) al nodo 1, tl 2. 00:34.718 ID:2 Conteo confianza [1, 2] = 10 00:43.108 ID:1 Serv solicitado: 2 00:43.111 ID:1 Solicitando (S2) al nodo 2, tl 1. 00:43.114 ID:1 Conteo confianza [2, 1] = 15 00:43.160 ID:2 unicast ping received from 1 00:43.720 ID:2 Serv solicitado: 3 00:43.723 ID:2 Solicitando (S3) al nodo 1, tl 2. 00:43.726 ID:2 Conteo confianza [1, 2] = 12 00:43.807 ID:1 unicast ping received from 2 00:46.735 ID:3 Serv solicitado: 2 00:46.738 ID:3 Solicitando (S2) al nodo 2, tl 2. 00:46.740 ID:3 Conteo confianza [2, 3] = 15 00:46.785 ID:2 unicast ping received from 3 00:53.023 ID:1 Serv solicitado: 2 00:53.025 ID:1 Solicitando (S2) al nodo 2, tl 1. 00:53.028 ID:1 Conteo confianza [2, 1] = 20 00:53.752 ID:2 Serv solicitado: 1 00:53.754 ID:2 Solicitando (S1) al nodo 3, tl 2. 00:53.757 ID:2 Conteo confianza [3, 2] = 20 00:53.822 ID:3 unicast ping received from 2 00:55.266 ID:3 Serv solicitado: 1 00:55.269 ID:3 Solicitando (S1) al nodo 2, tl 2. 00:55.272 ID:3 Conteo confianza [2, 3] = 25 01:00.585 ID:2 7684 P 2.0 1 80091 12801 948213240 48331 65538451 3676712 35745 395001858 948210924 40734 94896123 3670868 (radio 333.-29709% / 1242.1876% tx 329.-29788% / 12275.1906% listen 4.79% / 150.69%) 01:00.731 ID:1 7684 P 1.0 1 80158 12879 948213423 48286 65538544 3350520 38376 395009565 948212039 42188 94830592 3344614 (radio 333.-29708% / 1257.-10505% tx 329.-29786% / 12417.-10587% listen 4.78% / 157.82%) Thanks in advance. Carolina |
|
From: Niclas F. <ni...@us...> - 2013-01-30 12:38:48
|
The branch "master" has been updated
via 1c77ffca729bdea92adb8c044d27c053f7e72d03 (commit)
via 5b84bc09f1f12a4971250c728386b5d6550f21fa (commit)
via 25855fe2fea58e9f6ef0d80a4d251d8d5dacaa67 (commit)
via 5df8763ecfbef2969ea4d0fbdc41c3b585b85448 (commit)
via db6af9d926cc89fb7df21c52c67a9206a910987a (commit)
via cd42caa3cda1c5d977c004fd1ac1da6c992d1bce (commit)
via fecc20d65f1e41face7d655f90ab2c763ac2c403 (commit)
via 6875efd8ffdf8bfdb00ebf4c9aea4301967f40be (commit)
via 0c4af5cd75e62486c87fecc8bb20ddb488d2196c (commit)
via 51ebaf7636218e78e6fc2d920d59bdc23be1512a (commit)
via 2c4feabac4e310b30646c1308b4957c1ff2223a1 (commit)
via 488d7b6cdeb06774773c4e5214e082d0086f6ee6 (commit)
from eec0f2cd0493729c9de75aa739b2cb416f6b0eb5 (commit)
Changed paths:
M se/sics/mspsim/chip/CC2520.java
M se/sics/mspsim/config/MSP430f5437Config.java
M se/sics/mspsim/core/DisAsm.java
M se/sics/mspsim/core/MSP430Core.java
M se/sics/mspsim/core/Multiplier32.java
A se/sics/mspsim/core/PMM.java
A se/sics/mspsim/core/StatusRegister.java
C053 se/sics/mspsim/core/StateChangeListener.java se/sics/mspsim/core/SysReg.java
M se/sics/mspsim/core/Watchdog.java
M se/sics/mspsim/ui/StackUI.java
M se/sics/mspsim/util/ComponentRegistry.java
M se/sics/mspsim/util/ELF.java
M se/sics/mspsim/util/SimpleProfiler.java
- Log -----------------------------------------------------------------
commit 1c77ffca729bdea92adb8c044d27c053f7e72d03
Merge: 2c4feab 5b84bc0
Author: mspsim <joa...@si...>
Date: Wed Jan 9 06:48:48 2013 -0800
Merge pull request #3 from adamdunkels/thingsquare-msp430x-additions
MSP430x patches
commit 5b84bc09f1f12a4971250c728386b5d6550f21fa
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:38:34 2013 +0100
A removeComponent() method, used in Cooja to avoid poping up an additional window for the stack UI
diff --git a/se/sics/mspsim/util/ComponentRegistry.java b/se/sics/mspsim/util/ComponentRegistry.java
index 781aad8..96899db 100644
--- a/se/sics/mspsim/util/ComponentRegistry.java
+++ b/se/sics/mspsim/util/ComponentRegistry.java
@@ -71,6 +71,21 @@ public synchronized Object getComponent(String name) {
return null;
}
+ public synchronized boolean removeComponent(String name) {
+ ComponentEntry rem = null;
+ for (ComponentEntry entry : components) {
+ if (name.equals(entry.name)) {
+ rem = entry;
+ break;
+ }
+ }
+ if (rem == null) {
+ return false;
+ }
+ components.remove(rem);
+ return true;
+ }
+
public synchronized Object[] getAllComponents(String name) {
ArrayList<Object> list = new ArrayList<Object>();
for (ComponentEntry entry : components) {
commit 25855fe2fea58e9f6ef0d80a4d251d8d5dacaa67
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:38:05 2013 +0100
Code for searching for the _end symbol to facilitate stack monitoring ui
diff --git a/se/sics/mspsim/util/ELF.java b/se/sics/mspsim/util/ELF.java
index 1faddc9..4909eff 100644
--- a/se/sics/mspsim/util/ELF.java
+++ b/se/sics/mspsim/util/ELF.java
@@ -383,6 +383,7 @@ public String lookupFile(int address) {
public MapTable getMap() {
MapTable map = new MapTable();
+ int sAddrHighest = -1;
ELFSection name = sections[symTable.link];
int len = symTable.size;
@@ -426,6 +427,10 @@ public MapTable getMap() {
if (sAddr > 0 && sAddr < 0x100000) {
String symbolName = sn;
+
+ if (sAddr < 0x5c00 && sAddr > sAddrHighest) {
+ sAddrHighest = sAddr;
+ }
// if (bind == ELFSection.SYMBIND_LOCAL) {
// symbolName += " (" + currentFile + ')';
// }
@@ -460,6 +465,11 @@ public MapTable getMap() {
addr += symTable.getEntrySize();
}
+ if (sAddrHighest > 0) {
+ System.out.printf("Warning: Unable to parse _end symbol. I'm guessing that heap starts at 0x%05x\n", sAddrHighest);
+ map.setHeapStart(sAddrHighest);
+ }
+
return map;
}
commit 5df8763ecfbef2969ea4d0fbdc41c3b585b85448
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:37:33 2013 +0100
Print out 24 bit addresses instead of 16 bit addresses
diff --git a/se/sics/mspsim/util/SimpleProfiler.java b/se/sics/mspsim/util/SimpleProfiler.java
index aadc57a..f08b46f 100644
--- a/se/sics/mspsim/util/SimpleProfiler.java
+++ b/se/sics/mspsim/util/SimpleProfiler.java
@@ -381,14 +381,14 @@ private void printSpace(PrintStream out, int len) {
public void printStackTrace(PrintStream out) {
int stackCount = cSP;
out.println("Stack Trace: number of calls: " + stackCount
- + " PC: $" + Utils.hex(cpu.getPC(), 4));
+ + " PC: $" + Utils.hex(cpu.getPC(), 5));
for (int i = 0; i < stackCount; i++) {
CallEntry call = callStack[stackCount - i - 1];
out.println(" " + call.function.getInfo()
- + " called from PC: $" + Utils.hex(call.fromPC, 4)
+ + " called from PC: $" + Utils.hex(call.fromPC, 5)
+ " (elapsed: " + (cpu.cpuCycles - call.cycles) + ')');
if (stackCount - i - 1 == interruptLevel && servicedInterrupt != -1) {
- out.println(" *** Interrupt " + servicedInterrupt + " from PC: $" + Utils.hex(interruptFrom, 4));
+ out.println(" *** Interrupt " + servicedInterrupt + " from PC: $" + Utils.hex(interruptFrom, 5));
}
}
}
commit db6af9d926cc89fb7df21c52c67a9206a910987a
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:27:57 2013 +0100
A large number of bugfixes and additions to make MSP430x emulation work better with both IAR and mspgcc. In particular, many bugfixes are related to running code in +64k memory. The changes have been verified against real hardware with mspdebug single step instructions.
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index a20aa55..6a9b06e 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -94,7 +94,7 @@
// From the possible interrupt sources - to be able to indicate is serviced.
// NOTE: 64 since more modern MSP430's have more than 16 vectors (5xxx has 64).
private InterruptHandler interruptSource[] = new InterruptHandler[64];
- private final int MAX_INTERRUPT;
+ public int MAX_INTERRUPT;
protected int interruptMax = -1;
// Op/instruction represents the last executed OP / instruction
@@ -271,7 +271,7 @@ public int read(int address, boolean word, long cycles) {
ioUnits.add(timers[i]);
}
- watchdog = new Watchdog(this);
+ watchdog = new Watchdog(this, config.watchdogOffset);
ioSegment.setIORange(config.watchdogOffset, 1, watchdog);
ioUnits.add(watchdog);
@@ -447,11 +447,27 @@ public synchronized void removeRegisterReadMonitor(int r, RegisterMonitor mon) {
}
public void writeRegister(int r, int value) {
+ value &= 0xfffff;
+
+ /* PC must never be odd */
+ if (r == PC && (value % 2) != 0) {
+ /* With a solid compiler, this should never happen.
+ * Yet, this has been observed at least once with msp430-gcc 4.6.3. */
+ System.out.println("Warning: tried to write odd PC, not allowed! PC=0x" + Integer.toHexString(value));
+ value -= 1;
+ }
+
+ /* SR can never take values above 0xfff */
+ if (r == SR) {
+ value &= 0xfff;
+ }
+
// Before the write!
// if (value >= MAX_MEM) {
// System.out.println("Writing larger than MAX_MEM to " + r + " value:" + value);
// new Throwable().printStackTrace();
// }
+
RegisterMonitor rwm = regWriteMonitors[r];
if (rwm != null) {
// TODO Add register access mode
@@ -795,6 +811,7 @@ public void flagInterrupt(int interrupt, InterruptHandler source,
if (interruptMax == MAX_INTERRUPT) {
// This can not be masked at all!
interruptsEnabled = true;
+ servicedInterrupt = -1; /* Make sure this interrupt will be executed immediately */
}
} else {
if (interruptSource[interrupt] == source) {
@@ -1003,6 +1020,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
extSrc = ext10_7 << 16;
extDst = ext3_0 << 16;
pc += 2;
+
// Bit 7 in the extension word indicates that the number of
// repeats is found in the register pointed to by ext3_0. If
// the bit is 0, ext3_0 contains the number of repeats. If the
@@ -1018,9 +1036,10 @@ public int emulateOP(long maxCycles) throws EmulationException {
// that follows the extension word also has a zero bit data
// length mode.)
wordx20 = (instruction & 0x40) == 0;
+
instruction = currentSegment.read(pc, AccessMode.WORD, AccessType.EXECUTE);
-// System.out.println("*** Extension word!!! " + Utils.hex16(extWord) +
-// " read the instruction too: " + Utils.hex16(instruction) + " at " + Utils.hex16(pc - 2));
+ /*System.out.println("*** Extension word!!! " + Utils.hex16(extWord) +
+ " read the instruction too: " + Utils.hex16(instruction) + " at " + Utils.hex16(pc - 2));*/
} else {
extWord = 0;
}
@@ -1036,6 +1055,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
/* NOTE: there is a mode when wordx20 = true & word = true that is resereved */
AccessMode mode = wordx20 ? AccessMode.WORD20 : (word ? AccessMode.WORD : AccessMode.BYTE);
+ //if (mode == AccessMode.WORD20) System.out.println("WORD20 not really supported...");
+
// Destination vars
int dstRegister = 0;
int dstAddress = -1;
@@ -1047,6 +1068,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
// When is PC increased probably immediately (e.g. here)?
pc += 2;
+
writeRegister(PC, pc);
switch (op) {
@@ -1068,7 +1090,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
// 20 bit register write
case MOVA_IND:
/* Read from address in src register (20-bit?), move to destination register (=20 bit). */
- writeRegister(dstData, currentSegment.read(readRegister(srcData), AccessMode.WORD20, AccessType.READ));
+ writeRegister(dstData, currentSegment.read(readRegister(srcData), mode, AccessType.READ));
updateStatus = false;
cycles += 3;
break;
@@ -1081,7 +1103,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
src = readRegister(srcData);
// System.out.println("Reading $" + getAddressAsString(src) +
// " from register: " + srcData);
- dst = currentSegment.read(src, AccessMode.WORD20, AccessType.READ);
+ dst = currentSegment.read(src, mode, AccessType.READ);
// System.out.println("Reading from mem: $" + getAddressAsString(dst));
writeRegister(srcData, src + 4);
// System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData);
@@ -1094,7 +1116,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(PC, pc += 2);
dst = src + (srcData << 16);
//System.out.println(Utils.hex20(pc) + " MOVA &ABS Reading from $" + getAddressAsString(dst) + " to reg: " + dstData);
- dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
+ dst = currentSegment.read(dst, mode, AccessType.READ);
//System.out.println(" => $" + getAddressAsString(dst));
writeRegister(dstData, dst);
updateStatus = false;
@@ -1105,10 +1127,11 @@ public int emulateOP(long maxCycles) throws EmulationException {
* register, and place into destination register. */
int index = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
int indexModifier = readRegister(srcData);
- if(index > 0x8000) {
- index = -(0x10000 - index);
- }
- writeRegister(dstData, currentSegment.read(indexModifier + index, AccessMode.WORD20, AccessType.READ));
+
+ index = convertTwoComplement16(index);
+ indexModifier = convertTwoComplement20(indexModifier);
+
+ writeRegister(dstData, currentSegment.read(indexModifier + index, mode, AccessType.READ));
writeRegister(PC, pc += 2);
updateStatus = false;
cycles += 4;
@@ -1117,7 +1140,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
case MOVA_REG2ABS:
dst = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
writeRegister(PC, pc += 2);
- currentSegment.write(dst + (dstData << 16), readRegister(srcData), AccessMode.WORD20);
+ currentSegment.write(dst + (dstData << 16), readRegister(srcData), mode);
updateStatus = false;
cycles += 4;
break;
@@ -1127,10 +1150,11 @@ public int emulateOP(long maxCycles) throws EmulationException {
* indexed by source register. */
index = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
indexModifier = readRegister(dstData);
- if(index > 0x8000) {
- index = -(0x10000 - index);
- }
- currentSegment.write(indexModifier + index, readRegister(srcData), AccessMode.WORD20);
+
+ index = convertTwoComplement16(index);
+ indexModifier = convertTwoComplement20(indexModifier);
+
+ currentSegment.write(indexModifier + index, readRegister(srcData), mode);
writeRegister(PC, pc += 2);
updateStatus = false;
cycles += 4;
@@ -1155,7 +1179,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
// masked out as srcData.
int immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16);
writeRegister(PC, pc += 2);
- dst = readRegister(dstData) + immData;
+ int dstArg = readRegister(dstData);
+ dst = dstArg + immData;
+
+ sr = StatusRegister.updateSR(readRegister(SR), immData, dstArg, dst);
+ writeRegister(SR, sr);
+ updateStatus = false;
dst &= 0xfffff;
writeRegister(dstData, dst);
@@ -1211,6 +1240,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
cycles += 1;
/* as = 0 since register mode */
writeRegister(dstData, readRegisterCG(srcData, 0));
+ updateStatus = false;
break;
case CMPA_REG: {
@@ -1246,6 +1276,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
// Assume AS = 2
dst = readRegister(dstData) + readRegisterCG(srcData, 2);
writeRegister(dstData, dst);
+ sr = StatusRegister.updateSR(readRegister(SR), readRegisterCG(srcData, 2), dstData, dst);
+ writeRegister(SR, sr);
+ updateStatus = false;
cycles += 1;
break;
case SUBA_REG:
@@ -1293,6 +1326,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
}
break;
case RRAM:
+// System.out.println("RRAM executing");
/* roll in MSB from above */
/* 1 11 111 1111 needs to get in if MSB is 1 */
if ((dst & (rrword ? 0x8000 : 0x80000)) > 0) {
@@ -1304,12 +1338,14 @@ public int emulateOP(long maxCycles) throws EmulationException {
dst = dst >> 1;
break;
case RLAM:
+ // System.out.println("RLAM executing at " + pc);
/* just roll in "zeroes" from left */
dst = dst << (count - 1);
nxtCarry = (dst & (rrword ? 0x8000 : 0x80000)) > 0 ? CARRY : 0;
dst = dst << 1;
break;
case RRUM:
+ //System.out.println("RRUM executing");
/* just roll in "zeroes" from right */
dst = dst >> (count - 1);
nxtCarry = (dst & 1) > 0 ? CARRY : 0;
@@ -1325,9 +1361,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
System.out.println("MSP430X instruction not yet supported: " +
Utils.hex16(instruction) +
" op " + Utils.hex16(op));
- throw new EmulationException("Unsupported MSP430X instruction: 0x" +
+ throw new EmulationException("Found unsupported MSP430X instruction " +
Utils.hex16(instruction) +
- " op: 0x" + Utils.hex16(op));
+ " op " + Utils.hex16(op));
}
break;
case 1:
@@ -1342,6 +1378,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
/* check if this is a MSP430X CALLA instruction */
if ((op = instruction & CALLA_MASK) > RETI) {
pc = readRegister(PC);
+
dst = -1; /* will be -1 if not a call! */
/* do not update status after these instructions!!! */
updateStatus = false;
@@ -1354,6 +1391,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SP, sp);
dst = readRegister(dstRegister);
+ /*System.out.println("CALLA REG => " + Utils.hex20(dst));*/
cycles += 5;
break;
case CALLA_INDEX:
@@ -1361,21 +1399,25 @@ public int emulateOP(long maxCycles) throws EmulationException {
sp = readRegister(SP) - 2;
writeRegister(SP, sp);
+// System.out.println("CALLA INDX: R" + dstRegister);
dst = readRegister(dstRegister);
/* what happens if wrapping here??? */
/* read the index which is from -15 bit - +15 bit. - so extend sign to 20-bit */
- int v = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
- if ((v & 0x8000) != 0) {
- v |= 0xf0000;
- }
+ int index = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ index = convertTwoComplement16(index);
- dst += v;
+// System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " INDX: " + index);
+
+ dst += index;
dst &= 0xfffff;
+// System.out.println("CALLA INDX => " + Utils.hex20(dst));
dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
+// System.out.println("CALLA Read from INDX => " + Utils.hex20(dst));
cycles += 5;
pc += 2;
+// System.exit(0);
break;
case CALLA_IMM:
sp = readRegister(SP) - 2;
@@ -1392,7 +1434,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
dstAddress = readRegister(dstRegister);
dst = currentSegment.read(dstAddress, AccessMode.WORD20, AccessType.READ);
- pc += 2;
cycles += 5;
break;
case CALLA_ABS:
@@ -1419,11 +1460,16 @@ public int emulateOP(long maxCycles) throws EmulationException {
int n = 1 + ((instruction >> 4) & 0x0f);
int regNo = instruction & 0x0f;
+ // System.out.println("PUSHM " + (type == AccessMode.WORD20 ? "A" : "W") +
+ // " n: " + n + " " + regNo + " at " + Utils.hex16(pcBefore));
+
/* decrease stack pointer and write n times */
for(int i = 0; i < n; i++) {
sp -= size;
cycles += 2;
- currentSegment.write(sp, this.reg[regNo--], type);
+ currentSegment.write(sp, this.reg[regNo], type);
+ /*System.out.println("Saved reg: " + (regNo) + " was " + reg[regNo]);*/
+ regNo--;
/* what happens if regNo is wrapped ??? */
if (regNo < 0) regNo = 15;
@@ -1438,9 +1484,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
n = 1 + ((instruction >> 4) & 0x0f);
regNo = instruction & 0x0f;
/* read and increase stack pointer n times */
+
for(int i = 0; i < n; i++) {
cycles += 2;
- this.reg[regNo++] = currentSegment.read(sp, type, AccessType.READ);
+ this.reg[regNo] = currentSegment.read(sp, type, AccessType.READ);
+ regNo++;
+ // System.out.println("Restored reg: " + (regNo - 1) + " to " + reg[regNo - 1]);
sp += size;
/* what happens if regNo is wrapped ??? */
if (regNo > 15) regNo = 0;
@@ -1449,8 +1498,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SP, sp);
break;
default:
- throw new EmulationException("CALLA: mode not implemented 0x"
- + Utils.hex(instruction, 4) + " => 0x" + Utils.hex(op, 4));
+ System.out.println("CALLA/PUSH/POP: mode not implemented");
+ throw new EmulationException("CALLA: mode not implemented "
+ + Utils.hex16(instruction) + " => " + Utils.hex16(op));
}
}
// store current PC on stack. (current PC points to next instr.)
@@ -1493,22 +1543,42 @@ public int emulateOP(long maxCycles) throws EmulationException {
// TODO: needs to handle if SR is used!
rval = readRegisterCG(dstRegister, ad);
- /* Support for MSP430X and below / above 64 KB */
- /* if register is pointing to <64KB then it needs to be truncated to below 64 */
if (extWord != 0) {
- dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + extDst;
+ /* MSP430X Instruction With Indexed Mode */
+ /*
+ * TODO XXX There are MSP430X instructions without extension
+ * words!
+ */
+ /*
+ * "The operand address is the sum of the 20-bit CPU register
+ * content and the 20-bit index."
+ */
+ dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ dstAddress += extDst;
dstAddress += rval;
dstAddress &= 0xfffff;
- } else if (rval <= 0xffff) {
- dstAddress = (rval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff;
} else {
- dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
- if ((dstAddress & 0x8000) > 0) {
- dstAddress |= 0xf0000;
- }
+ if (rval <= 0xffff) {
+ /* Indexed Mode in Lower 64-KB Memory */
+ /*
+ * ".. the calculated memory address bits 19:16 are cleared
+ * after the addition of the CPU register Rn and the signed
+ * 16-bit index."
+ */
+ dstAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
+ dstAddress += rval;
+ dstAddress &= 0xffff;
+ } else {
+ /* MSP430 Instruction With Indexed Mode in Upper Memory */
+ /*
+ * "The operand may be located in memory in the range Rn +-32
+ * KB, because the index, X, is a signed 16-bit value"
+ */
+ dstAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
dstAddress += rval;
dstAddress &= 0xfffff;
}
+ }
// When is PC incremented - assuming immediately after "read"?
pc += 2;
@@ -1517,19 +1587,22 @@ public int emulateOP(long maxCycles) throws EmulationException {
break;
// Indirect register
case AM_IND_REG:
- dstAddress = readRegister(dstRegister);
+ dstAddress = readRegister(dstRegister) + extDst;
+
cycles += 3;
break;
// Bugfix suggested by Matt Thompson
case AM_IND_AUTOINC:
if (dstRegister == PC) {
dstAddress = pc;
+
dst = currentSegment.read(dstAddress, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+
dst += extDst;
pc += 2;
writeRegister(PC, pc);
} else {
- dstAddress = readRegister(dstRegister);
+ dstAddress = readRegister(dstRegister) + extDst;
writeRegister(dstRegister, dstAddress + mode.bytes); // XXX (word ? 2 : 1));
}
cycles += 3;
@@ -1584,6 +1657,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
int tmp = dst;
dst = ((tmp >> 8) & 0xff) + ((tmp << 8) & 0xff00);
write = true;
+ updateStatus = false;
break;
case RRA:
nxtCarry = (dst & 1) > 0 ? CARRY : 0;
@@ -1616,6 +1690,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
case CALL:
// store current PC on stack. (current PC points to next instr.)
pc = readRegister(PC);
+
// memory[sp] = pc & 0xff;
// memory[sp + 1] = pc >> 8;
currentSegment.write(sp, pc, AccessMode.WORD);
@@ -1766,24 +1841,42 @@ public int emulateOP(long maxCycles) throws EmulationException {
// Indexed if reg != PC & CG1/CG2 - will PC be incremented?
int sval = readRegisterCG(srcRegister, as);
- /* Support for MSP430X and below / above 64 KB */
- /* if register is pointing to <64KB then it needs to be truncated to below 64 */
if (extWord != 0) {
- srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + extSrc;
+ /* MSP430X Instruction With Indexed Mode */
+ /*
+ * TODO XXX There are MSP430X instructions without extension
+ * words!
+ */
+ /*
+ * "The operand address is the sum of the 20-bit CPU register
+ * content and the 20-bit index."
+ */
+ srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ srcAddress += extSrc;
srcAddress += sval;
srcAddress &= 0xfffff;
- } else if (sval <= 0xffff) {
- srcAddress = (sval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff;
} else {
- srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
- if ((srcAddress & 0x8000) > 0) {
- // Negative index
- srcAddress |= 0xf0000;
- }
+ if (sval <= 0xffff) {
+ /* Indexed Mode in Lower 64-KB Memory */
+ /*
+ * ".. the calculated memory address bits 19:16 are cleared
+ * after the addition of the CPU register Rn and the signed
+ * 16-bit index."
+ */
+ srcAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
+ srcAddress += sval;
+ srcAddress &= 0xffff;
+ } else {
+ /* MSP430 Instruction With Indexed Mode in Upper Memory */
+ /*
+ * "The operand may be located in memory in the range Rn +-32
+ * KB, because the index, X, is a signed 16-bit value"
+ */
+ srcAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
srcAddress += sval;
srcAddress &= 0xfffff;
}
- // When is PC incremented - assuming immediately after "read"?
+ }
pc += 2;
writeRegister(PC, pc);
@@ -1798,16 +1891,24 @@ public int emulateOP(long maxCycles) throws EmulationException {
case AM_IND_AUTOINC:
if (srcRegister == PC) {
/* PC is always handled as word */
- src = currentSegment.read(pc, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ if (mode == AccessMode.BYTE) {
+ src = currentSegment.read(pc, AccessMode.BYTE,
+ AccessType.READ);
+ } else {
+ src = currentSegment.read(pc, AccessMode.WORD,
+ AccessType.READ);
+ }
src += extSrc;
+
pc += 2;
writeRegister(PC, pc);
cycles += dstRegMode ? 2 : 5;
} else {
srcAddress = readRegister(srcRegister);
- incRegister(srcRegister, mode.bytes);//XXX word ? 2 : 1);
+ incRegister(srcRegister, mode.bytes);
cycles += dstRegMode ? 2 : 5;
}
+
/* If destination register is PC another cycle is consumed */
if (dstRegister == PC) {
cycles++;
@@ -1825,28 +1926,55 @@ public int emulateOP(long maxCycles) throws EmulationException {
} else {
// PC Could have changed above!
pc = readRegister(PC);
+
if (dstRegister == 2) {
/* absolute mode */
dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); //memory[pc] + (memory[pc + 1] << 8);
+ dstAddress += extDst;
} else {
// CG here - probably not!???
rval = readRegister(dstRegister);
- /* Support for MSP430X and below / above 64 KB */
- /* if register is pointing to <64KB then it needs to be truncated to below 64 */
+
+ if (extWord != 0) {
+ /* MSP430X Instruction With Indexed Mode */
+ /*
+ * TODO XXX There are MSP430X instructions without extension
+ * words!
+ */
+ /*
+ * "The operand address is the sum of the 20-bit CPU register
+ * content and the 20-bit index."
+ */
+ dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ dstAddress += extDst;
+ dstAddress += rval;
+ dstAddress &= 0xfffff;
+ } else {
if (rval <= 0xffff) {
- dstAddress = (rval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff;
+ /* Indexed Mode in Lower 64-KB Memory */
+ /*
+ * ".. the calculated memory address bits 19:16 are cleared
+ * after the addition of the CPU register Rn and the signed
+ * 16-bit index."
+ */
+ dstAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
+ dstAddress += rval;
+ dstAddress &= 0xffff;
} else {
- dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
- if ((dstAddress & 0x8000) > 0) {
- dstAddress |= 0xf0000;
- }
+ /* MSP430 Instruction With Indexed Mode in Upper Memory */
+ /*
+ * "The operand may be located in memory in the range Rn +-32
+ * KB, because the index, X, is a signed 16-bit value"
+ */
+ dstAddress = convertTwoComplement16(currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
dstAddress += rval;
dstAddress &= 0xfffff;
}
}
+ }
if (op != MOV) {
- dst = currentSegment.read(dstAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ dst = currentSegment.read(dstAddress, mode, AccessType.READ);
}
pc += 2;
incRegister(PC, 2);
@@ -2014,6 +2142,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (repeats > 0 && srcRegister == dstRegister) {
src = dst;
src &= mode.mask;
+ dst &= mode.mask;
}
}
}
@@ -2024,7 +2153,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (dstRegMode) {
writeRegister(dstRegister, dst);
} else {
- dstAddress &= 0xffff;
currentSegment.write(dstAddress, dst, mode);
}
}
@@ -2052,6 +2180,19 @@ public int emulateOP(long maxCycles) throws EmulationException {
return pcBefore;
}
+ private static int convertTwoComplement16(int index) {
+ if(index > 0x8000) {
+ return -(0x10000 - index);
+ }
+ return index;
+ }
+ private static int convertTwoComplement20(int index) {
+ if(index > 0x80000) {
+ return -(0x100000 - index);
+ }
+ return index;
+ }
+
public int getModeMax() {
return MODE_MAX;
}
diff --git a/se/sics/mspsim/core/StatusRegister.java b/se/sics/mspsim/core/StatusRegister.java
new file mode 100644
index 0000000..bc675de
--- /dev/null
+++ b/se/sics/mspsim/core/StatusRegister.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2012, Thingsquare, http://www.thingsquare.com/.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * 3. Neither the name of the copyright holder nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+package se.sics.mspsim.core;
+
+public class StatusRegister {
+ static final int NEGATIVE = MSP430Constants.NEGATIVE;
+ static final int ZERO = MSP430Constants.ZERO;
+ static final int CARRY = MSP430Constants.CARRY;
+ static final int OVERFLOW = MSP430Constants.OVERFLOW;
+
+ static final boolean DEBUG = false;
+
+ /* Tested with ADDA_IMM, ADDA_REG */
+ public static int updateSR(int sr, int src, int dstArg, int dstResult) {
+ sr &= ~(NEGATIVE | ZERO | CARRY | OVERFLOW);
+
+ int dst20 = dstResult & 0xfffff;
+ boolean srcNegative = (dstArg & (1 << 19)) != 0;
+ boolean oldDstNegative = (dstArg & (1 << 19)) != 0;
+ boolean dstNegative = (dst20 & (1 << 19)) != 0;
+
+ if (dstNegative) {
+ /* negative */
+ sr |= NEGATIVE;
+ if (DEBUG) {
+ System.out.println("sr: negative");
+ }
+ }
+ if (dst20 == 0) {
+ /* zero */
+ sr |= ZERO;
+ if (DEBUG) {
+ System.out.println("sr: zero");
+ }
+ }
+ if (dstResult > dst20) {
+ /* carry */
+ sr |= CARRY;
+ if (DEBUG) {
+ System.out.println("sr: carry");
+ }
+ }
+ if (srcNegative && oldDstNegative && !dstNegative) {
+ /* overflow */
+ sr |= OVERFLOW;
+ if (DEBUG) {
+ System.out.println("sr: overflow (--+)");
+ }
+ }
+ if (!srcNegative && !oldDstNegative && dstNegative) {
+ sr |= OVERFLOW;
+ if (DEBUG) {
+ System.out.println("sr: overflow (++-)");
+ }
+ }
+
+ if (DEBUG) {
+ System.out.printf("sr: updated sr 0x%02x\n", sr);
+ }
+ return sr;
+ }
+}
commit cd42caa3cda1c5d977c004fd1ac1da6c992d1bce
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:26:04 2013 +0100
Bugfix for 32x32 bit multiplications
diff --git a/se/sics/mspsim/core/Multiplier32.java b/se/sics/mspsim/core/Multiplier32.java
index f61d79e..01f3864 100644
--- a/se/sics/mspsim/core/Multiplier32.java
+++ b/se/sics/mspsim/core/Multiplier32.java
@@ -321,8 +321,8 @@ public void write(int address, int data, boolean word, long cycles) {
}
/* FIXME: Ignore accumulate. */
- res0 = (int) res64 & 0xffff;
- res1 = (int) (res64 >> 16) & 0xffff;
+ resLo = res0 = (int) res64 & 0xffff;
+ resHi = res1 = (int) (res64 >> 16) & 0xffff;
res2 = (int) (res64 >> 32) & 0xffff;
res3 = (int) (res64 >> 48) & 0xffff;
commit fecc20d65f1e41face7d655f90ab2c763ac2c403
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:25:17 2013 +0100
Minor bugfixes for disassembly: take care of the length of certain instructions
diff --git a/se/sics/mspsim/core/DisAsm.java b/se/sics/mspsim/core/DisAsm.java
index b05e649..2682902 100644
--- a/se/sics/mspsim/core/DisAsm.java
+++ b/se/sics/mspsim/core/DisAsm.java
@@ -445,6 +445,7 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg,
srcadr = "$" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8)) + "(R" + srcRegister + ")";
size += 2;
}
+ pc += 2;
break;
// Indirect register
case AM_IND_REG:
@@ -630,7 +631,7 @@ private static String dumpSR(int sr) {
private static String dumpMem(int pc, int size, int[] memory) {
String output = "";
- for (int i = 0, n = 4; i < n; i++) {
+ for (int i = 0, n = size; i < n; i++) {
if (size > i) {
output += Utils.hex8(memory[pc + i]) + " ";
} else {
commit 6875efd8ffdf8bfdb00ebf4c9aea4301967f40be
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:24:36 2013 +0100
Allow the watchdog to reside on different addresses
diff --git a/se/sics/mspsim/core/Watchdog.java b/se/sics/mspsim/core/Watchdog.java
index ec6b66c..48ba424 100644
--- a/se/sics/mspsim/core/Watchdog.java
+++ b/se/sics/mspsim/core/Watchdog.java
@@ -49,8 +49,6 @@
*/
public class Watchdog extends IOUnit implements SFRModule {
- private static final int WDTCTL = 0x120;
-
private static final int WDTHOLD = 0x80;
private static final int WDTCNTCL = 0x08;
private static final int WDTMSEL = 0x10;
@@ -60,13 +58,16 @@
private static final int WATCHDOG_VECTOR = 10;
private static final int WATCHDOG_INTERRUPT_BIT = 0;
private static final int WATCHDOG_INTERRUPT_VALUE = 1 << WATCHDOG_INTERRUPT_BIT;
- private static final int RESET_VECTOR = 15;
private static final int[] DELAY = {
32768, 8192, 512, 64
};
- private int wdtctl;
+ private int resetVector = 15;
+
+ private int wdtctl = 0x4;
+ private int offset;
+
public boolean wdtOn = true;
private boolean hold = false;
@@ -87,8 +88,12 @@ public void execute(long t) {
}
};
- public Watchdog(MSP430Core cpu) {
- super("Watchdog", cpu, cpu.memory, 0x120);
+ public Watchdog(MSP430Core cpu, int address) {
+ super("Watchdog", cpu, cpu.memory, address);
+
+ resetVector = cpu.MAX_INTERRUPT;
+
+ this.offset = address;
cpu.getSFR().registerSFDModule(0, WATCHDOG_INTERRUPT_BIT, this, WATCHDOG_VECTOR);
}
@@ -96,6 +101,11 @@ public void interruptServiced(int vector) {
cpu.flagInterrupt(vector, this, false);
}
+ public void reset(int type) {
+ super.reset(type);
+ wdtctl = 0x4;
+ }
+
private void triggerWDT(long time) {
// Here the WDT triggered!!!
if (timerMode) {
@@ -107,17 +117,16 @@ private void triggerWDT(long time) {
} else {
System.out.println("WDT trigger - will reset node!");
cpu.generateTrace(System.out);
- cpu.flagInterrupt(RESET_VECTOR, this, true);
+ cpu.flagInterrupt(resetVector, this, true);
}
}
public int read(int address, boolean word, long cycles) {
- if (address == WDTCTL) return wdtctl | 0x6900;
- return 0;
+ return wdtctl | 0x6900;
}
public void write(int address, int value, boolean word, long cycles) {
- if (address == WDTCTL) {
+ if (address == offset) {
if ((value >> 8) == 0x5a) {
wdtctl = value & 0xff;
if (DEBUG) log("Wrote to WDTCTL: " + Utils.hex8(wdtctl) + " from $" + Utils.hex(cpu.getPC(), 4));
@@ -143,7 +152,7 @@ public void write(int address, int value, boolean word, long cycles) {
// Trigger reset!!
logw(WarningType.EXECUTION, "illegal write to WDTCTL (" + value + ") from $" + Utils.hex(cpu.getPC(), 4)
+ " - reset!!!!");
- cpu.flagInterrupt(RESET_VECTOR, this, true);
+ cpu.flagInterrupt(resetVector, this, true);
}
}
}
commit 0c4af5cd75e62486c87fecc8bb20ddb488d2196c
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:10:04 2013 +0100
Stubs for PMM and SysReg components, enough stubs to make newest mspgcc/Contiki and IAR/Contiki happy
diff --git a/se/sics/mspsim/config/MSP430f5437Config.java b/se/sics/mspsim/config/MSP430f5437Config.java
index 15570ee..b34ff8d 100644
--- a/se/sics/mspsim/config/MSP430f5437Config.java
+++ b/se/sics/mspsim/config/MSP430f5437Config.java
@@ -43,6 +43,8 @@
import se.sics.mspsim.core.MSP430Config;
import se.sics.mspsim.core.MSP430Core;
import se.sics.mspsim.core.Multiplier32;
+import se.sics.mspsim.core.PMM;
+import se.sics.mspsim.core.SysReg;
import se.sics.mspsim.core.Timer;
import se.sics.mspsim.core.UnifiedClockSystem;
import se.sics.mspsim.util.Utils;
@@ -123,6 +125,15 @@ public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) {
ioUnits.add(last = IOPort.parseIOPort(cpu, 0, portConfig[i], last));
}
+ /* XXX: Stub IO units: Sysreg and PMM */
+ SysReg sysreg = new SysReg(cpu, cpu.memory);
+ cpu.setIORange(SysReg.ADDRESS, SysReg.SIZE, sysreg);
+ ioUnits.add(sysreg);
+
+ PMM pmm = new PMM(cpu, cpu.memory, 0x120);
+ cpu.setIORange(0x120, PMM.SIZE, pmm);
+ ioUnits.add(pmm);
+
return portConfig.length + uartConfig.length;
}
diff --git a/se/sics/mspsim/core/PMM.java b/se/sics/mspsim/core/PMM.java
new file mode 100644
index 0000000..2b0c5e6
--- /dev/null
+++ b/se/sics/mspsim/core/PMM.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2012, Thingsquare.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+package se.sics.mspsim.core;
+
+public class PMM extends IOUnit {
+ public static int SIZE = 32;
+
+ /*
+ * This is only a stub to avoid immediate Mspsim exceptions. TODO XXX:
+ * Implement me!
+ */
+
+ private int baseAddress;
+
+ public PMM(MSP430Core cpu, int[] memory, int address) {
+ super("PMM", "PMM", cpu, memory, address);
+ baseAddress = address;
+ reset(0);
+ }
+
+ public void reset(int type) {
+ /* Initial values */
+ memory[baseAddress + 0x0] = 0x9600; /* PMMCTL0 */
+ memory[baseAddress + 0x2] = 0x0000; /* PMMCTL1 */
+ memory[baseAddress + 0x4] = 0x4400; /* SVSMHCTL */
+ memory[baseAddress + 0x6] = 0x4400; /* SVSMLCTL */
+ memory[baseAddress + 0x8] = 0x0020; /* SVSMIO */
+ memory[baseAddress + 0xc] = 0x0000; /* PMMIFG */
+ memory[baseAddress + 0xe] = 0x1100; /* PMMRIE */
+ }
+
+ public void write(int address, int value, boolean word, long cycles) {
+ if (DEBUG)
+ log(this.getName() + ": Write to: "
+ + String.format("0x%05x = 0x%05x", address, value));
+
+ memory[address] = value;
+ }
+
+ public int read(int address, boolean word, long cycles) {
+ if (address == baseAddress + 0xc) {
+ /* PMMIFG always settled */
+ int SVSMLDLYIFG = 0x01;
+ int SVSMHDLYIFG = 0x10;
+ int SVMHVLRIFG = 0x40;
+ memory[address] |= SVSMLDLYIFG | SVSMHDLYIFG | SVMHVLRIFG;
+ }
+
+ if (DEBUG) {
+ log(this.getName()
+ + ": Read from: "
+ + String.format("0x%05x = 0x%05x", address, memory[address]));
+ }
+
+ return memory[address];
+ }
+
+ public void interruptServiced(int vector) {
+ if (DEBUG) {
+ log(this.getName() + ": Interrupt services vector: " + vector);
+ }
+ }
+}
diff --git a/se/sics/mspsim/core/SysReg.java b/se/sics/mspsim/core/SysReg.java
new file mode 100644
index 0000000..9f62af1
--- /dev/null
+++ b/se/sics/mspsim/core/SysReg.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2012, Thingsquare.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+package se.sics.mspsim.core;
+
+public class SysReg extends IOUnit {
+ public static int ADDRESS = 0x180;
+ public static int SIZE = 0x1f;
+
+ /*
+ * This is only a stub to avoid immediate Mspsim exceptions.
+ * TODO XXX: Implement me!
+ *
+System control SYSCTL 00h
+Bootstrap loader configuration area SYSBSLC 02h
+JTAG mailbox control SYSJMBC 06h
+JTAG mailbox input 0 SYSJMBI0 08h
+JTAG mailbox input 1 SYSJMBI1 0Ah
+JTAG mailbox output 0 SYSJMBO0 0Ch
+JTAG mailbox output 1 SYSJMBO1 0Eh
+Bus Error vector generator SYSBERRIV 18h
+User NMI vector generator SYSUNIV 1Ah
+System NMI vector generator SYSSNIV 1Ch
+Reset vector generator SYSRSTIV 1Eh
+ */
+
+ public SysReg(MSP430Core cpu, int[] memory) {
+ super("SysReg", "System registers", cpu, memory, SysReg.ADDRESS);
+ reset(0);
+ }
+
+ public void reset(int type) {
+ }
+
+ public void write(int address, int value, boolean word, long cycles) {
+ if (DEBUG)
+ log(this.getName() + ": Write to: "
+ + String.format("0x%05x = 0x%05x", address, value));
+ memory[address] = value;
+ }
+
+ public int read(int address, boolean word, long cycles) {
+ if (DEBUG)
+ log(this.getName()
+ + ": Read from: "
+ + String.format("0x%05x = 0x%05x", address, memory[address]));
+ return memory[address];
+ }
+
+ public void interruptServiced(int vector) {
+ if (DEBUG)
+ log(this.getName() + ": Interrupt services vector: " + vector);
+ }
+}
commit 51ebaf7636218e78e6fc2d920d59bdc23be1512a
Author: Adam Dunkels <ad...@th...>
Date: Mon Jan 7 14:08:05 2013 +0100
Draw the maximum stack usage in the stackui window
diff --git a/se/sics/mspsim/ui/StackUI.java b/se/sics/mspsim/ui/StackUI.java
index 366b22d..bbe94bc 100644
--- a/se/sics/mspsim/ui/StackUI.java
+++ b/se/sics/mspsim/ui/StackUI.java
@@ -63,12 +63,15 @@
private ChartPanel chartPanel;
private LineChart minStackChart;
private LineChart maxStackChart;
+ private LineChart maxUsageStackChart;
// private DotDiagram diagram;
private int[] minData = new int[STACK_FRAME];
private int[] maxData = new int[STACK_FRAME];
+ private int[] maxUsageData = new int[STACK_FRAME];
private int[] minCache = new int[STACK_FRAME];
private int[] maxCache = new int[STACK_FRAME];
+ private int[] maxUsageCache = new int[STACK_FRAME];
// private String[] notes = new String[STACK_FRAME];
private long lastCycles = 0;
@@ -85,6 +88,8 @@
private String name;
+ private boolean increasePos = false;
+
public StackUI(MSP430 cpu) {
this(cpu, 2500);
}
@@ -103,6 +108,10 @@ public StackUI(MSP430 cpu, int updateCyclePeriod) {
// add(diagram, BorderLayout.CENTER);
}
+ public void requestIncreasePos() {
+ increasePos = true;
+ }
+
private void setup() {
if (chartPanel != null) return;
@@ -133,6 +142,11 @@ private void setup() {
maxStackChart = new LineChart("Max Stack");
maxStackChart.setConfig("color", Color.green);
chartPanel.addChart(maxStackChart);
+
+ maxUsageStackChart = new LineChart("Max usage");
+ maxUsageStackChart.setConfig("color", Color.blue);
+ chartPanel.addChart(maxUsageStackChart);
+
chartPanel.setAxisChart(maxStackChart);
add(chartPanel, BorderLayout.CENTER);
@@ -148,20 +162,27 @@ private void setup() {
}
registerMonitor = new RegisterMonitor.Adapter() {
- @Override
+ private int m = 0;
public void notifyWriteBefore(int register, int data, AccessMode mode) {
int size = stackStartAddress - data;
if (minData[pos] > size) {
minData[pos] = size;
}
+ if (m < size) {
+ m = size;
+ }
if (maxData[pos] < size) {
maxData[pos] = size;
}
- if (cpu.cpuCycles - lastCycles > updateCyclePeriod) {
+ if ((updateCyclePeriod > 0 && cpu.cpuCycles - lastCycles > updateCyclePeriod)
+ || increasePos) {
+ increasePos = false;
lastCycles = cpu.cpuCycles;
// System.out.println("STACK UPDATE: " + type + "," + adr + "," + data + "," + pos);
+
pos = (pos + 1) % minData.length;
minData[pos] = Integer.MAX_VALUE;
+ maxUsageData[pos] = m;
maxData[pos] = 0;
update = true;
repaint();
@@ -180,8 +201,10 @@ public void paint(Graphics g) {
int p = pos;
copy(this.minData, this.minCache, p);
copy(this.maxData, this.maxCache, p);
+ copy(this.maxUsageData, this.maxUsageCache, p);
minStackChart.setData(this.minCache);
maxStackChart.setData(this.maxCache);
+ maxUsageStackChart.setData(this.maxUsageCache);
}
super.paint(g);
}
@@ -220,7 +243,7 @@ public void stop() {
status = Status.STOPPED;
window.setVisible(false);
if (registerMonitor != null) {
- cpu.addRegisterWriteMonitor(MSP430.SP, registerMonitor);
+ cpu.removeRegisterWriteMonitor(MSP430.SP, registerMonitor);
}
}
commit 2c4feabac4e310b30646c1308b4957c1ff2223a1
Merge: eec0f2c 488d7b6
Author: mspsim <joa...@si...>
Date: Fri Jan 4 12:38:58 2013 -0800
Merge pull request #2 from nfi/cc2520
Added support for frame filter in CC2520
commit 488d7b6cdeb06774773c4e5214e082d0086f6ee6
Author: Niclas Finne <nf...@si...>
Date: Wed Dec 5 16:37:05 2012 +0100
Added support for frame filter
diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java
index ba84bd1..69c49aa 100644
--- a/se/sics/mspsim/chip/CC2520.java
+++ b/se/sics/mspsim/chip/CC2520.java
@@ -260,11 +260,17 @@ public void setPolarity(boolean polarity) {
// public static final int CCAMUX_CCA = 0;
// public static final int CCAMUX_XOSC16M_STABLE = 24;
- // MDMCTRO0 values
- public static final int ADR_DECODE = (1 << 11);
- public static final int ADR_AUTOCRC = (1 << 5);
- public static final int AUTOACK = (1 << 4);
- public static final int PREAMBLE_LENGTH = 0x0f;
+ // FRMFILT0/FRMCTRL0 values
+ public static final int FRAME_FILTER = (1 << 0);
+ public static final int AUTOCRC = (1 << 6);
+ public static final int AUTOACK = (1 << 5);
+
+ // FRMFILT1
+ public static final int ACCEPT_FT_4TO7_RESERVED = (1 << 7);
+ public static final int ACCEPT_FT_3_MAC_CMD = (1 << 6);
+ public static final int ACCEPT_FT_2_ACK = (1 << 5);
+ public static final int ACCEPT_FT_1_DATA = (1 << 4);
+ public static final int ACCEPT_FT_0_BEACON = (1 << 3);
public static final int SHORT_ADDRESS = 2;
public static final int LONG_ADDRESS = 3;
@@ -353,10 +359,10 @@ public int getFSMState() {
/* FIFOP Threshold */
private int fifopThr = 0x40;
- /* if autoack is configured or if */
+ /* Configuration for frame filtering and auto acknowledgments */
+ private boolean frameFilter = false;
private boolean autoAck = false;
private boolean shouldAck = false;
- private boolean addressDecode = false;
private boolean ackRequest = false;
private boolean autoCRC = false;
@@ -462,6 +468,10 @@ public void execute(long t) {
case TX_ACK_CALIBRATE:
setState(RadioState.TX_ACK_PREAMBLE);
break;
+
+ default:
+ // Ignore other states
+ break;
}
}
};
@@ -477,10 +487,6 @@ public void execute(long t) {
private final ArrayFIFO rxFIFO = new ArrayFIFO("RXFIFO", memory, 128, 128);
- public RadioState getState() {
- return stateMachine;
- }
-
public CC2520(MSP430Core cpu) {
super("CC2520", "Radio", cpu);
@@ -495,15 +501,39 @@ public CC2520(MSP430Core cpu) {
reset();
}
+ public RadioState getState() {
+ return stateMachine;
+ }
+
+ private int getFCFReservedMask() {
+ return (memory[REG_FRMFILT0] >> 4) & 7;
+ }
+
+ private int getFCFMaxFrameVersion() {
+ return (memory[REG_FRMFILT0] >> 2) & 3;
+ }
+
private void updateGPIOConfig() {
int bit = 1;
- for (int i = 0; i < gpio.length; i++) {
- gpio[i].setPolarity((memory[REG_GPIOPOLARITY] & bit) > 0);
+ for (GPIO io : gpio) {
+ io.setPolarity((memory[REG_GPIOPOLARITY] & bit) > 0);
bit = bit << 1;
}
}
private void reset() {
+ // FCF max fram version = 3 and frame filtering enabled
+ memory[REG_FRMFILT0] = 0x0d;
+ frameFilter = true;
+ memory[REG_FRMFILT1] = 0x78;
+ // autocrc enabled, autoack disabled
+ memory[REG_FRMCTRL0] = 0x40;
+ autoCRC = true;
+ autoAck = false;
+
+ memory[REG_MDMCTRL0] = 0x45;
+ memory[REG_MDMCTRL1] = 0x3e;
+ memory[REG_FSMSTAT0] = 0;
memory[REG_FSMSTAT1] = 0;
memory[REG_RSSISTAT] = 0;
memory[REG_TXPOWER] = 0x06;
@@ -640,6 +670,13 @@ private boolean setState(RadioState state) {
shouldAck = false;
crcOk = false;
break;
+
+ case RX_OVERFLOW:
+ break;
+
+ case TX_UNDERFLOW:
+ // TODO handle TX underflow
+ break;
}
/* Notify state listener */
@@ -699,7 +736,7 @@ public void receivedByte(byte data) {
rxCrc.setCRC(0);
rxlen = data & 0xff;
//System.out.println("Starting to get packet at: " + rxfifoWritePos + " len = " + rxlen);
- decodeAddress = addressDecode;
+ decodeAddress = frameFilter;
if (DEBUG) log("RX: Start frame length " + rxlen);
// FIFO pin goes high after length byte is written to RXFIFO
setFIFO(true);
@@ -711,19 +748,44 @@ public void receivedByte(byte data) {
frameType = fcf0 & FRAME_TYPE;
} else if (rxread == 2) {
fcf1 = data & 0xff;
- if (frameType == TYPE_DATA_FRAME) {
+
+ if (frameFilter
+ && (((getFCFReservedMask() & (((fcf0 & 3) << 1) | (fcf1 & 1))) != 0)
+ || (getFCFMaxFrameVersion() < ((fcf0 >> 2) & 3)))) {
+ // Illegal frame version or reserved bits set
+ rejectFrame();
+ } else if (frameType == TYPE_DATA_FRAME) {
ackRequest = (fcf0 & ACK_REQUEST) > 0;
destinationAddressMode = (fcf1 >> 2) & 3;
/* check this !!! */
- if (addressDecode && destinationAddressMode != LONG_ADDRESS &&
- destinationAddressMode != SHORT_ADDRESS) {
+ if (frameFilter) {
+ if ((destinationAddressMode != LONG_ADDRESS
+ && destinationAddressMode != SHORT_ADDRESS)
+ || (memory[REG_FRMFILT1] & ACCEPT_FT_1_DATA) == 0) {
rejectFrame();
}
- } else if (frameType == TYPE_BEACON_FRAME ||
- frameType == TYPE_ACK_FRAME){
+ }
+ } else if (frameType == TYPE_ACK_FRAME) {
+ decodeAddress = false;
+ ackRequest = false;
+ if (frameFilter) {
+ if (rxlen != 5
+ || (memory[REG_FRMFILT1] & ACCEPT_FT_2_ACK) == 0) {
+ rejectFrame();
+ }
+ }
+ } else if (frameType == TYPE_BEACON_...
[truncated message content] |
|
From: Niclas F. <ni...@us...> - 2012-12-04 14:54:12
|
The branch "master" has been updated
via eec0f2cd0493729c9de75aa739b2cb416f6b0eb5 (commit)
via fe77a837cafced2a43b95f97c57d010f2b53b67e (commit)
via b4c02ee3eca4e7ef38692e2b4ebc51f214b245a0 (commit)
from 9173f6d8e128f5debd29dfef4ba09d26687afd17 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit eec0f2cd0493729c9de75aa739b2cb416f6b0eb5
Merge: 9173f6d fe77a83
Author: mspsim <joa...@si...>
Date: Tue Dec 4 06:49:12 2012 -0800
Merge pull request #1 from nfi/mova
Mova
commit fe77a837cafced2a43b95f97c57d010f2b53b67e
Author: Niclas Finne <nf...@si...>
Date: Tue Dec 4 15:41:31 2012 +0100
Removed some debug output and code
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index 0eb1d35..a20aa55 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1036,8 +1036,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
/* NOTE: there is a mode when wordx20 = true & word = true that is resereved */
AccessMode mode = wordx20 ? AccessMode.WORD20 : (word ? AccessMode.WORD : AccessMode.BYTE);
- if (mode == AccessMode.WORD20) System.out.println("WORD20 not really supported...");
-
// Destination vars
int dstRegister = 0;
int dstAddress = -1;
@@ -1158,7 +1156,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
int immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16);
writeRegister(PC, pc += 2);
dst = readRegister(dstData) + immData;
-// System.out.println("ADDA #" + Utils.hex20(immData) + " => " + Utils.hex20(dst));
dst &= 0xfffff;
writeRegister(dstData, dst);
@@ -1296,7 +1293,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
}
break;
case RRAM:
-// System.out.println("RRAM executing");
/* roll in MSB from above */
/* 1 11 111 1111 needs to get in if MSB is 1 */
if ((dst & (rrword ? 0x8000 : 0x80000)) > 0) {
@@ -1308,14 +1304,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
dst = dst >> 1;
break;
case RLAM:
- // System.out.println("RLAM executing at " + pc);
/* just roll in "zeroes" from left */
dst = dst << (count - 1);
nxtCarry = (dst & (rrword ? 0x8000 : 0x80000)) > 0 ? CARRY : 0;
dst = dst << 1;
break;
case RRUM:
- //System.out.println("RRUM executing");
/* just roll in "zeroes" from right */
dst = dst >> (count - 1);
nxtCarry = (dst & 1) > 0 ? CARRY : 0;
@@ -1331,9 +1325,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
System.out.println("MSP430X instruction not yet supported: " +
Utils.hex16(instruction) +
" op " + Utils.hex16(op));
- throw new EmulationException("Found unsupported MSP430X instruction " +
+ throw new EmulationException("Unsupported MSP430X instruction: 0x" +
Utils.hex16(instruction) +
- " op " + Utils.hex16(op));
+ " op: 0x" + Utils.hex16(op));
}
break;
case 1:
@@ -1360,7 +1354,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SP, sp);
dst = readRegister(dstRegister);
- System.out.println("CALLA REG => " + Utils.hex20(dst));
cycles += 5;
break;
case CALLA_INDEX:
@@ -1368,7 +1361,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
sp = readRegister(SP) - 2;
writeRegister(SP, sp);
- System.out.println("CALLA INDX: R" + dstRegister);
dst = readRegister(dstRegister);
/* what happens if wrapping here??? */
@@ -1378,17 +1370,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
v |= 0xf0000;
}
- System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " INDX: " + v);
-
dst += v;
dst &= 0xfffff;
- System.out.println("CALLA INDX => " + Utils.hex20(dst));
dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
- System.out.println("CALLA Read from INDX => " + Utils.hex20(dst));
cycles += 5;
pc += 2;
-// System.exit(0);
break;
case CALLA_IMM:
sp = readRegister(SP) - 2;
@@ -1432,15 +1419,11 @@ public int emulateOP(long maxCycles) throws EmulationException {
int n = 1 + ((instruction >> 4) & 0x0f);
int regNo = instruction & 0x0f;
-// System.out.println("PUSHM " + (type == AccessMode.WORD20 ? "A" : "W") +
-// " n: " + n + " " + regNo + " at " + Utils.hex16(pcBefore));
-
/* decrease stack pointer and write n times */
for(int i = 0; i < n; i++) {
sp -= size;
cycles += 2;
currentSegment.write(sp, this.reg[regNo--], type);
-// System.out.println("Saved reg: " + (regNo + 1) + " was " + reg[regNo + 1]);
/* what happens if regNo is wrapped ??? */
if (regNo < 0) regNo = 15;
@@ -1454,13 +1437,10 @@ public int emulateOP(long maxCycles) throws EmulationException {
case POPM_W:
n = 1 + ((instruction >> 4) & 0x0f);
regNo = instruction & 0x0f;
-// System.out.println("POPM W " + (type == AccessMode.WORD20 ? "A" : "W") + " n: " +
-// n + " " + regNo + " at " + Utils.hex16(pcBefore));
/* read and increase stack pointer n times */
for(int i = 0; i < n; i++) {
cycles += 2;
this.reg[regNo++] = currentSegment.read(sp, type, AccessType.READ);
-// System.out.println("Restored reg: " + (regNo - 1) + " to " + reg[regNo - 1]);
sp += size;
/* what happens if regNo is wrapped ??? */
if (regNo > 15) regNo = 0;
@@ -1469,9 +1449,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SP, sp);
break;
default:
- System.out.println("CALLA/PUSH/POP: mode not implemented");
- throw new EmulationException("CALLA: mode not implemented "
- + Utils.hex16(instruction) + " => " + Utils.hex16(op));
+ throw new EmulationException("CALLA: mode not implemented 0x"
+ + Utils.hex(instruction, 4) + " => 0x" + Utils.hex(op, 4));
}
}
// store current PC on stack. (current PC points to next instr.)
@@ -1595,13 +1574,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
nxtCarry = (dst & 1) > 0 ? CARRY : 0;
dst = dst >> 1;
dst |= (sr & CARRY) > 0 ? mode.msb : 0;
-//XXX if (word) {
-// dst |= (sr & CARRY) > 0 ? 0x8000 : 0;
-// } else if (wordx20) {
-// dst |= (sr & CARRY) > 0 ? 0x80000 : 0;
-// } else {
-// dst |= (sr & CARRY) > 0 ? 0x80 : 0;
-// }
// Indicate write to memory!!
write = true;
@@ -1616,13 +1588,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
case RRA:
nxtCarry = (dst & 1) > 0 ? CARRY : 0;
dst = (dst & mode.msb) | dst >> 1;
-//XXX if (word) {
-// dst = (dst & 0x8000) | (dst >> 1);
-// } else if (wordx20) {
-// dst = (dst & 0x80000) | (dst >> 1);
-// } else {
-// dst = (dst & 0x80) | (dst >> 1);
-// }
write = true;
writeRegister(SR, (sr & ~(CARRY | OVERFLOW)) | nxtCarry);
break;
@@ -1702,13 +1667,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
Utils.hex16(instruction));
}
if (repeats > 0) {
-//XXX if (word) {
-// dst &= 0xffff;
-// } else if (wordx20) {
-// dst &= 0xfffff;
-// } else {
-// dst &= 0xff;
-// }
dst &= mode.mask;
}
}
@@ -1779,13 +1737,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if ((srcRegister == CG1 && as > AM_INDEX) || srcRegister == CG2) {
src = CREG_VALUES[srcRegister - 2][as];
src &= mode.mask;
-//XXX if (word) {
-// src &= 0xffff;
-// } else if (wordx20) {
-// src &= 0xfffff;
-// } else {
-// src &= 0xff;
-// }
cycles += dstRegMode ? 1 : 4;
} else {
switch(as) {
@@ -1794,13 +1745,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
// CG handled above!
src = readRegister(srcRegister);
src &= mode.mask;
-//XXX if (word) {
-// src &= 0xffff;
-// } else if (wordx20) {
-// src &= 0xfffff;
-// } else {
-// src &= 0xff;
-// }
cycles += dstRegMode ? 1 : 4;
/* add cycle if destination register = PC */
if (dstRegister == PC) cycles++;
@@ -2070,26 +2014,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (repeats > 0 && srcRegister == dstRegister) {
src = dst;
src &= mode.mask;
-//XXX if (word) {
-// src &= 0xffff;
-// } else if (wordx20) {
-// src &= 0xfffff;
-// } else {
-// src &= 0xff;
-// }
}
}
}
/* Processing after each instruction */
dst &= mode.mask;
-//XXX if (word) {
-// dst &= 0xffff;
-// } else if (wordx20) {
-// dst &= 0xfffff;
-// } else {
-// dst &= 0xff;
-// }
if (write) {
if (dstRegMode) {
writeRegister(dstRegister, dst);
@@ -2104,9 +2034,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
sr = readRegister(SR);
sr = (sr & ~(ZERO | NEGATIVE)) |
((dst == 0) ? ZERO : 0) | ((dst & mode.msb) > 0 ? NEGATIVE : 0);
-//XXX (word ? ((dst & 0x8000) > 0 ? NEGATIVE : 0) :
-// (wordx20 ? ((dst & 0x80000) > 0 ? NEGATIVE : 0) :
-// ((dst & 0x80) > 0 ? NEGATIVE : 0)));
writeRegister(SR, sr);
}
commit b4c02ee3eca4e7ef38692e2b4ebc51f214b245a0
Author: Niclas Finne <nf...@si...>
Date: Tue Dec 4 15:35:28 2012 +0100
Bug fix in mova index2reg and reg2index
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index 7f56f5a..0eb1d35 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1110,9 +1110,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if(index > 0x8000) {
index = -(0x10000 - index);
}
- if(indexModifier > 0x8000) {
- indexModifier = -(0x10000 - indexModifier);
- }
writeRegister(dstData, currentSegment.read(indexModifier + index, AccessMode.WORD20, AccessType.READ));
writeRegister(PC, pc += 2);
updateStatus = false;
@@ -1135,9 +1132,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if(index > 0x8000) {
index = -(0x10000 - index);
}
- if(indexModifier > 0x8000) {
- indexModifier = -(0x10000 - indexModifier);
- }
currentSegment.write(indexModifier + index, readRegister(srcData), AccessMode.WORD20);
writeRegister(PC, pc += 2);
updateStatus = false;
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 93 +++--------------------------------
1 files changed, 7 insertions(+), 86 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-11-06 19:52:29
|
The branch "master" has been updated
via 9173f6d8e128f5debd29dfef4ba09d26687afd17 (commit)
from 98a2fc2d17cab6dd125f785414a89dda9f0f9452 (commit)
Changed paths:
M se/sics/mspsim/cli/NetCommands.java
M se/sics/mspsim/core/PortListenerProxy.java
M se/sics/mspsim/debug/StabType.java
M se/sics/mspsim/platform/ti/Exp5438Node.java
M se/sics/mspsim/util/ArgumentManager.java
M se/sics/mspsim/util/DebugInfo.java
M se/sics/mspsim/util/ELFException.java
M se/sics/mspsim/util/IHexReader.java
M se/sics/mspsim/util/MapEntry.java
M se/sics/mspsim/util/MapTable.java
M se/sics/mspsim/util/NetworkPacket.java
M se/sics/mspsim/util/PluginRepository.java
- Log -----------------------------------------------------------------
commit 9173f6d8e128f5debd29dfef4ba09d26687afd17
Author: Niclas Finne <nf...@si...>
Date: Tue Nov 6 15:07:41 2012 +0100
Minor cleanup (fixed some compiler warnings)
diff --git a/se/sics/mspsim/cli/NetCommands.java b/se/sics/mspsim/cli/NetCommands.java
index 1cbf12c..afdce6f 100644
--- a/se/sics/mspsim/cli/NetCommands.java
+++ b/se/sics/mspsim/cli/NetCommands.java
@@ -22,10 +22,8 @@
public void setupCommands(final ComponentRegistry registry, CommandHandler handler) {
handler.registerCommand("ipstack", new BasicLineCommand("setup 802.15.4/IP stack", "") {
CC2420PacketHandler listener;
- CommandContext context;
public int executeCommand(CommandContext context) {
- this.context = context;
- MSP430 cpu = (MSP430) registry.getComponent(MSP430.class);
+ MSP430 cpu = registry.getComponent(MSP430.class);
listener = new CC2420PacketHandler(cpu);
listener.setOutput(context.out);
IEEE802154Handler ieeeHandler = new IEEE802154Handler();
@@ -48,8 +46,7 @@ public void lineRead(String line) {
if (listener != null) {
byte[] data = Utils.hexconv(line);
for (int i = 0; i < data.length; i++) {
- //context.out.println("Byte " + i + " = " + ((int) data[i] & 0xff));
- // Currently it will autoprint when packet is ready...
+ // Currently it will auto print when packet is ready...
listener.receivedByte(data[i]);
}
}
diff --git a/se/sics/mspsim/core/PortListenerProxy.java b/se/sics/mspsim/core/PortListenerProxy.java
index 5a6f6eb..235f8ae 100644
--- a/se/sics/mspsim/core/PortListenerProxy.java
+++ b/se/sics/mspsim/core/PortListenerProxy.java
@@ -68,12 +68,12 @@ public static PortListener removePortListener(PortListener portListener, PortLis
}
public PortListener add(PortListener mon) {
- portListeners = (PortListener[]) ArrayUtils.add(PortListener.class, portListeners, mon);
+ portListeners = ArrayUtils.add(PortListener.class, portListeners, mon);
return this;
}
public PortListener remove(PortListener listener) {
- PortListener[] listeners = (PortListener[]) ArrayUtils.remove(portListeners, listener);
+ PortListener[] listeners = ArrayUtils.remove(portListeners, listener);
if (listeners == null) {
return null;
}
diff --git a/se/sics/mspsim/debug/StabType.java b/se/sics/mspsim/debug/StabType.java
index b78ff7d..f45151c 100644
--- a/se/sics/mspsim/debug/StabType.java
+++ b/se/sics/mspsim/debug/StabType.java
@@ -76,7 +76,7 @@ private boolean handleKnown(String name) {
* */
private void handleTypeDef(String def) {
if (def.startsWith("(")) {
- StabType tDef = (StabType) types.get("t" + def);
+ StabType tDef = types.get("t" + def);
if (tDef != null) {
typeDef = tDef;
} else {
diff --git a/se/sics/mspsim/platform/ti/Exp5438Node.java b/se/sics/mspsim/platform/ti/Exp5438Node.java
index 3cbeb35..60f3f72 100644
--- a/se/sics/mspsim/platform/ti/Exp5438Node.java
+++ b/se/sics/mspsim/platform/ti/Exp5438Node.java
@@ -1,14 +1,12 @@
package se.sics.mspsim.platform.ti;
import java.io.IOException;
-
import se.sics.mspsim.chip.CC2420;
import se.sics.mspsim.config.MSP430f5437Config;
import se.sics.mspsim.core.EmulationException;
import se.sics.mspsim.core.IOPort;
import se.sics.mspsim.core.IOUnit;
import se.sics.mspsim.core.PortListener;
-import se.sics.mspsim.core.USART;
import se.sics.mspsim.core.USARTListener;
import se.sics.mspsim.core.USARTSource;
import se.sics.mspsim.platform.GenericNode;
diff --git a/se/sics/mspsim/util/ArgumentManager.java b/se/sics/mspsim/util/ArgumentManager.java
index 25e92ef..6623852 100644
--- a/se/sics/mspsim/util/ArgumentManager.java
+++ b/se/sics/mspsim/util/ArgumentManager.java
@@ -39,7 +39,6 @@
* $Revision$
*/
package se.sics.mspsim.util;
-import java.io.PrintStream;
import java.util.ArrayList;
/**
diff --gi |
|
From: Niclas F. <ni...@us...> - 2012-11-05 20:18:54
|
The branch "master" has been updated
via 98a2fc2d17cab6dd125f785414a89dda9f0f9452 (commit)
from ad8bd6a6ea6cc022b55ddd12eee7923fd8871848 (commit)
Changed paths:
M se/sics/mspsim/chip/CC2420.java
M se/sics/mspsim/cli/DebugCommands.java
M se/sics/mspsim/core/Chip.java
M se/sics/mspsim/core/EmulationLogger.java
M se/sics/mspsim/core/IOUnit.java
M se/sics/mspsim/util/DefaultEmulationLogger.java
- Log -----------------------------------------------------------------
commit 98a2fc2d17cab6dd125f785414a89dda9f0f9452
Author: Niclas Finne <nf...@si...>
Date: Mon Nov 5 21:20:06 2012 +0100
reimplemented log command
diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java
index 3ab7a84..d51b624 100644
--- a/se/sics/mspsim/chip/CC2420.java
+++ b/se/sics/mspsim/chip/CC2420.java
@@ -318,19 +318,19 @@ public int getFSMState() {
private TimeEvent oscillatorEvent = new TimeEvent(0, "CC2420 OSC") {
public void execute(long t) {
status |= STATUS_XOSC16M_STABLE;
- if(DEBUG) log("Oscillator Stable Event.");
+ if (logLevel > INFO) log("Oscillator Stable Event.");
setState(RadioState.IDLE);
if( (registers[REG_IOCFG1] & CCAMUX) == CCAMUX_XOSC16M_STABLE) {
updateCCA();
} else {
- if(DEBUG) log("CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA");
+ if(logLevel > INFO) log("CCAMUX != CCA_XOSC16M_STABLE! Not raising CCA");
}
}
};
private TimeEvent vregEvent = new TimeEvent(0, "CC2420 VREG") {
public void execute(long t) {
- if(DEBUG) log("VREG Started at: " + t + " cyc: " +
+ if(logLevel > INFO) log("VREG Started at: " + t + " cyc: " +
cpu.cycles + " " + getTime());
on = true;
setState(RadioState.POWER_DOWN);
@@ -430,7 +430,7 @@ private void reset() {
}
private boolean setState(RadioState state) {
- if(DEBUG) log("State transition from " + stateMachine + " to " + state);
+ if(logLevel > INFO) log("State transition from " + stateMachine + " to " + state);
stateMachine = state;
/* write to FSM state register */
registers[REG_FSMSTATE] = state.getFSMState();
@@ -438,7 +438,7 @@ private boolean setState(RadioState state) {
switch(stateMachine) {
case VREG_OFF:
- if (DEBUG) log("VREG Off.");
+ if (logLevel > INFO) log("VREG Off.");
flushRX();
flushTX();
status &= ~(STATUS_RSSI_VALID | STATUS_XOSC16M_STABLE);
@@ -569,7 +569,7 @@ private void rejectFrame() {
public void receivedByte(byte data) {
// Received a byte from the "air"
- if (DEBUG)
+ if (logLevel > INFO)
log("RF Byte received: " + Utils.hex8(data) + " state: " + stateMachine + " noZeroes: " + zeroSymbols +
((stateMachine == RadioState.RX_SFD_SEARCH || stateMachine == RadioState.RX_FRAME) ? "" : " *** Ignored"));
@@ -583,7 +583,7 @@ public void receivedByte(byte data) {
// and the current received byte == 0x7A (SFD), we're in sync.
// In RX mode, SFD goes high when the SFD is received
setSFD(true);
- if (DEBUG) log("RX: Preamble/SFD Synchronized.");
+ if (logLevel > INFO) log("RX: Preamble/SFD Synchronized.");
setState(RadioState.RX_FRAME);
} else {
/* if not four zeros and 0x7A then no zeroes... */
@@ -603,7 +603,7 @@ public void receivedByte(byte data) {
rxlen = data & 0xff;
//System.out.println("Starting to get packet at: " + rxfifoWritePos + " len = " + rxlen);
decodeAddress = addressDecode;
- if (DEBUG) log("RX: Start frame length " + rxlen);
+ if (logLevel > INFO) log("RX: Start frame length " + rxlen);
// FIFO pin goes high after length byte is written to RXFIFO
setFIFO(true);
} else if (rxread < rxlen - 1) {
@@ -663,13 +663,13 @@ public void receivedByte(byte data) {
&& !decodeAddress && !frameRejected
&& rxFIFO.length() > fifopThr) {
setFIFOP(true);
- if (DEBUG) log("RX: FIFOP Threshold reached - setting FIFOP");
+ if (logLevel > INFO) log("RX: FIFOP Threshold reached - setting FIFOP");
}
}
if (rxread++ == rxlen) {
if (frameRejected) {
- if (DEBUG) log("Frame rejected - setting SFD to false and RXWAIT\n");
+ if (logLevel > INFO) log("Frame rejected - setting SFD to false and RXWAIT\n");
setSFD(false);
setState(RadioState.RX_WAIT);
return;
@@ -682,7 +682,7 @@ public void receivedByte(byte data) {
crc += rxFIFO.get(-1); //memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)];
crcOk = crc == rxCrc.getCRCBitrev();
- if (DEBUG && !crcOk) {
+ if (logLevel > INFO && !crcOk) {
log("CRC not OK: recv:" + Utils.hex16(crc) + " calc: " + Utils.hex16(rxCrc.getCRCBitrev()));
}
// Should take a RSSI value as input or use a set-RSSI value...
@@ -698,10 +698,10 @@ public void receivedByte(byte data) {
if (rxFIFO.length() <= rxlen + 1) {
setFIFOP(true);
} else {
- if (DEBUG) log("Did not set FIFOP rxfifoLen: " + rxFIFO.length() + " rxlen: " + rxlen);
+ if (logLevel > INFO) log("Did not set FIFOP rxfifoLen: " + rxFIFO.length() + " rxlen: " + rxlen);
}
setSFD(false);
- if (DEBUG) log("RX: Complete: packetStart: " + rxFIFO.stateToString());
+ if (logLevel > INFO) log("RX: Complete: packetStart: " + rxFIFO.stateToString());
/* if either manual ack request (shouldAck) or autoack + ACK_REQ on package do ack! */
/* Autoack-mode + good CRC => autoack */
@@ -721,7 +721,7 @@ private void setReg(int address, int data) {
switch(address) {
case REG_IOCFG0:
fifopThr = data & FIFOP_THR;
- if (DEBUG) log("IOCFG0: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data));
+ if (logLevel > INFO) log("IOCFG0: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data));
if ((oldValue & POLARITY_MASK) != (data & POLARITY_MASK)) {
// Polarity has changed - must update pins
setFIFOP(currentFIFOP);
@@ -731,7 +731,7 @@ private void setReg(int address, int data) {
}
break;
case REG_IOCFG1:
- if (DEBUG)
+ if (logLevel > INFO)
log("IOCFG1: SFDMUX "
+ ((registers[address] & SFDMUX) >> SFDMUX)
+ " CCAMUX: " + (registers[address] & CCAMUX));
@@ -759,7 +759,7 @@ private void setReg(int address, int data) {
public void dataReceived(USARTSource source, int data) {
int oldStatus = status;
- if (DEBUG) {
+ if (logLevel > INFO) {
log("byte received: " + Utils.hex8(data) +
" (" + ((data >= ' ' && data <= 'Z') ? (char) data : '.') + ')' +
" CS: " + chipSelect + " SPI state: " + state + " StateMachine: " + stateMachine);
@@ -813,7 +813,7 @@ public void dataReceived(USARTSource source, int data) {
usartDataValue |= data;
// registers[usartDataAddress] = (registers[usartDataAddress] & 0xff00) | data;
- if (DEBUG) {
+ if (logLevel > INFO) {
log("wrote to " + Utils.hex8(usartDataAddress) + " = " + usartDataValue);
}
setReg(usartDataAddress, usartDataValue);
@@ -827,7 +827,7 @@ public void dataReceived(USARTSource source, int data) {
usartDataPos = 1;
} else {
source.byteReceived(registers[usartDataAddress] & 0xff);
- if (DEBUG) {
+ if (logLevel > INFO) {
log("read from " + Utils.hex8(usartDataAddress) + " = "
+ registers[usartDataAddress]);
}
@@ -837,14 +837,14 @@ public void dataReceived(USARTSource source, int data) {
//break;
case READ_RXFIFO: {
int fifoData = rxFIFO.read();
- if (DEBUG) log("RXFIFO READ: " + rxFIFO.stateToString());
+ if (logLevel > INFO) log("RXFIFO READ: " + rxFIFO.stateToString());
source.byteReceived(fifoData);
/* first check and clear FIFOP - since we now have read a byte! */
if (currentFIFOP && !overflow) {
/* FIFOP is lowered when rxFIFO is lower than or equal to fifopThr */
if(rxFIFO.length() <= fifopThr) {
- if (DEBUG) log("*** FIFOP cleared at: " + rxFIFO.stateToString());
+ if (logLevel > INFO) log("*** FIFOP cleared at: " + rxFIFO.stateToString());
setFIFOP(false);
}
}
@@ -852,7 +852,7 @@ public void dataReceived(USARTSource source, int data) {
/* initiate read of another packet - update some variables to keep track of packet reading... */
if (rxfifoReadLeft == 0) {
rxfifoReadLeft = fifoData;
- if (DEBUG) log("Init read of packet - len: " + rxfifoReadLeft +
+ if (logLevel > INFO) log("Init read of packet - len: " + rxfifoReadLeft +
" fifo: " + rxFIFO.stateToString());
} else if (--rxfifoReadLeft == 0) {
/* check if we have another packet in buffer */
@@ -860,14 +860,14 @@ public void dataReceived(USARTSource source, int data) {
/* check if the packet is complete or longer than fifopThr */
if (rxFIFO.length() > rxFIFO.peek(0) ||
(rxFIFO.length() > fifopThr && !decodeAddress && !frameRejected)) {
- if (DEBUG) log("More in FIFO - FIFOP = 1! plen: " + rxFIFO.stateToString());
+ if (logLevel > INFO) log("More in FIFO - FIFOP = 1! plen: " + rxFIFO.stateToString());
if (!overflow) setFIFOP(true);
}
}
}
// Set the FIFO pin low if there are no more bytes available in the RXFIFO.
if (rxFIFO.length() == 0) {
- if (DEBUG) log("Setting FIFO to low (buffer empty)");
+ if (logLevel > INFO) log("Setting FIFO to low (buffer empty)");
setFIFO(false);
}
}
@@ -877,7 +877,7 @@ public void dataReceived(USARTSource source, int data) {
txCursor = 0;
txfifoFlush = false;
}
- if (DEBUG) log("Writing data: " + data + " to tx: " + txCursor);
+ if (logLevel > INFO) log("Writing data: " + data + " to tx: " + txCursor);
if(txCursor == 0) {
if ((data & 0xff) > 127) {
@@ -897,7 +897,7 @@ public void dataReceived(USARTSource source, int data) {
if (usartDataPos == 0) {
usartDataAddress |= (data << 1) & 0x180;
ramRead = (data & FLAG_RAM_READ) != 0;
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Address: " + Utils.hex16(usartDataAddress) + " read: " + ramRead);
}
usartDataPos++;
@@ -908,7 +908,7 @@ public void dataReceived(USARTSource source, int data) {
logger.logw(this, WarningType.EXECUTION, "CC2420: Warning - RAM position too big - wrapping!");
usartDataAddress = 0;
}
- if (DEBUG && usartDataAddress == RAM_PANID + 2) {
+ if (logLevel > INFO && usartDataAddress == RAM_PANID + 2) {
log("Pan ID set to: 0x" +
Utils.hex8(memory[RAM_PANID]) +
Utils.hex8(memory[RAM_PANID + 1]));
@@ -937,33 +937,33 @@ public void dataReceived(USARTSource source, int data) {
// next data...
private void strobe(int data) {
// Resets, on/off of different things...
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Strobe on: " + Utils.hex8(data) + " => " + Reg.values()[data]);
}
if( (stateMachine == RadioState.POWER_DOWN) && (data != REG_SXOSCON) ) {
- if (DEBUG) log("Got command strobe: " + data + " in POWER_DOWN. Ignoring.");
+ if (logLevel > INFO) log("Got command strobe: " + data + " in POWER_DOWN. Ignoring.");
return;
}
switch (data) {
case REG_SNOP:
- if (DEBUG) log("SNOP => " + Utils.hex8(status) + " at " + cpu.cycles);
+ if (logLevel > INFO) log("SNOP => " + Utils.hex8(status) + " at " + cpu.cycles);
break;
case REG_SRXON:
if(stateMachine == RadioState.IDLE) {
setState(RadioState.RX_CALIBRATE);
//updateActiveFrequency();
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Strobe RX-ON!!!");
}
} else {
- if (DEBUG) log("WARNING: SRXON when not IDLE");
+ if (logLevel > INFO) log("WARNING: SRXON when not IDLE");
}
break;
case REG_SRFOFF:
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Strobe RXTX-OFF!!! at " + cpu.cycles);
if (stateMachine == RadioState.TX_ACK ||
stateMachine == RadioState.TX_FRAME ||
@@ -987,7 +987,7 @@ private void strobe(int data) {
sendEvent("STXON", null);
}
// Starting up TX subsystem - indicate that we are in TX mode!
- if (DEBUG) log("Strobe STXON - transmit on! at " + cpu.cycles);
+ if (logLevel > INFO) log("Strobe STXON - transmit on! at " + cpu.cycles);
}
break;
case REG_STXONCCA:
@@ -1006,9 +1006,9 @@ private void strobe(int data) {
if(cca) {
status |= STATUS_TX_ACTIVE;
setState(RadioState.TX_CALIBRATE);
- if (DEBUG) log("Strobe STXONCCA - transmit on! at " + cpu.cycles);
+ if (logLevel > INFO) log("Strobe STXONCCA - transmit on! at " + cpu.cycles);
}else{
- if (DEBUG) log("STXONCCA Ignored, CCA false");
+ if (logLevel > INFO) log("STXONCCA Ignored, CCA false");
}
}
break;
@@ -1016,7 +1016,7 @@ private void strobe(int data) {
flushRX();
break;
case REG_SFLUSHTX:
- if (DEBUG) log("Flushing TXFIFO");
+ if (logLevel > INFO) log("Flushing TXFIFO");
flushTX();
break;
case REG_SXOSCON:
@@ -1038,7 +1038,7 @@ private void strobe(int data) {
}
break;
default:
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Unknown strobe command: " + data);
}
break;
@@ -1055,12 +1055,13 @@ private void shrNext() {
} else if (stateMachine == RadioState.TX_ACK_PREAMBLE) {
setState(RadioState.TX_ACK);
} else {
- log("Can not move to TX_FRAME or TX_ACK after preamble since radio is in wrong mode: " +
+ logw(WarningType.EMULATION_ERROR,
+ "Can not move to TX_FRAME or TX_ACK after preamble since radio is in wrong mode: " +
stateMachine);
}
} else {
if (rfListener != null) {
- if (DEBUG) log("transmitting byte: " + Utils.hex8(SHR[shrPos]));
+ if (logLevel > INFO) log("transmitting byte: " + Utils.hex8(SHR[shrPos]));
rfListener.receivedByte(SHR[shrPos]);
}
shrPos++;
@@ -1083,14 +1084,14 @@ private void txNext() {
logw(WarningType.EXECUTION, "**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos);
}
if (rfListener != null) {
- if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
+ if (logLevel > INFO) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
rfListener.receivedByte((byte)(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
}
txfifoPos++;
// Two symbol periods to send a byte...
cpu.scheduleTimeEventMillis(sendEvent, SYMBOL_PERIOD * 2);
} else {
- if (DEBUG) log("Completed Transmission.");
+ if (logLevel > INFO) log("Completed Transmission.");
status &= ~STATUS_TX_ACTIVE;
setSFD(false);
if (overflow) {
@@ -1124,7 +1125,7 @@ private void ackNext() {
ackBuf[5] = txCrc.getCRCLow();
}
if (rfListener != null) {
- if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
+ if (logLevel > INFO) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
rfListener.receivedByte((byte)(ackBuf[ackPos] & 0xFF));
}
@@ -1132,7 +1133,7 @@ private void ackNext() {
// Two symbol periods to send a byte...
cpu.scheduleTimeEventMillis(ackEvent, SYMBOL_PERIOD * 2);
} else {
- if (DEBUG) log("Completed Transmission of ACK.");
+ if (logLevel > INFO) log("Completed Transmission of ACK.");
status &= ~STATUS_TX_ACTIVE;
setSFD(false);
setState(RadioState.RX_CALIBRATE);
@@ -1156,13 +1157,13 @@ private void startOscillator() {
private void stopOscillator() {
status &= ~STATUS_XOSC16M_STABLE;
setState(RadioState.POWER_DOWN);
- if (DEBUG) log("Oscillator Off.");
+ if (logLevel > INFO) log("Oscillator Off.");
// Reset state
setFIFOP(false);
}
private void flushRX() {
- if (DEBUG) {
+ if (logLevel > INFO) {
log("Flushing RX len = " + rxFIFO.length());
}
rxFIFO.reset();
@@ -1203,7 +1204,7 @@ private void updateCCA() {
private void setInternalCCA(boolean clear) {
setCCA(clear);
- if (DEBUG) log("Internal CCA: " + clear);
+ if (logLevel > INFO) log("Internal CCA: " + clear);
}
private void setSFD(boolean sfd) {
@@ -1212,12 +1213,12 @@ private void setSFD(boolean sfd) {
sfdPort.setPinState(sfdPin, sfd ? IOPort.PinState.LOW : IOPort.PinState.HI);
else
sfdPort.setPinState(sfdPin, sfd ? IOPort.PinState.HI : IOPort.PinState.LOW);
- if (DEBUG) log("SFD: " + sfd + " " + cpu.cycles);
+ if (logLevel > INFO) log("SFD: " + sfd + " " + cpu.cycles);
}
private void setCCA(boolean cca) {
currentCCA = cca;
- if (DEBUG) log("Setting CCA to: " + cca);
+ if (logLevel > INFO) log("Setting CCA to: " + cca);
if( (registers[REG_IOCFG0] & CCA_POLARITY) == CCA_POLARITY)
ccaPort.setPinState(ccaPin, cca ? IOPort.PinState.LOW : IOPort.PinState.HI);
else
@@ -1226,7 +1227,7 @@ private void setCCA(boolean cca) {
private void setFIFOP(boolean fifop) {
currentFIFOP = fifop;
- if (DEBUG) log("Setting FIFOP to " + fifop);
+ if (logLevel > INFO) log("Setting FIFOP to " + fifop);
if( (registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY) {
fifopPort.setPinState(fifopPin, fifop ? IOPort.PinState.LOW : IOPort.PinState.HI);
} else {
@@ -1236,7 +1237,7 @@ private void setFIFOP(boolean fifop) {
private void setFIFO(boolean fifo) {
currentFIFO = fifo;
- if (DEBUG) log("Setting FIFO to " + fifo);
+ if (logLevel > INFO) log("Setting FIFO to " + fifo);
if((registers[REG_IOCFG0] & FIFO_POLARITY) == FIFO_POLARITY) {
fifoPort.setPinState(fifoPin, fifo ? IOPort.PinState.LOW : IOPort.PinState.HI);
} else {
@@ -1245,7 +1246,7 @@ private void setFIFO(boolean fifo) {
}
private void setRxOverflow() {
- if (DEBUG) log("RXFIFO Overflow! Read Pos: " + rxFIFO.stateToString());
+ if (logLevel > INFO) log("RXFIFO Overflow! Read Pos: " + rxFIFO.stateToString());
setFIFOP(true);
setFIFO(false);
setSFD(false);
@@ -1313,7 +1314,7 @@ public void setRSSI(int power) {
power = maxp;
}
- if (DEBUG) log("external setRSSI to: " + power);
+ if (logLevel > INFO) log("external setRSSI to: " + power);
rssi = power;
registers[REG_RSSI] = power - RSSI_OFFSET;
@@ -1368,7 +1369,7 @@ public void setVRegOn(boolean newOn) {
// 0.6ms maximum vreg startup from datasheet pg 13
// but Z1 platform does not work with 0.1 so trying with lower...
cpu.scheduleTimeEventMillis(vregEvent, 0.05);
- if (DEBUG) log("Scheduling vregEvent at: cyc = " + cpu.cycles +
+ if (logLevel > INFO) log("Scheduling vregEvent at: cyc = " + cpu.cycles +
" target: " + vregEvent.getTime() + " current: " + cpu.getTime());
} else {
on = false;
@@ -1382,7 +1383,7 @@ public void setChipSelect(boolean select) {
if (state == SpiState.WRITE_REGISTER && usartDataPos == 1) {
// Register write incomplete. Do a 8 bit register write.
usartDataValue = (registers[usartDataAddress] & 0xff) | (usartDataValue & 0xff00);
- if (DEBUG) {
+ if (logLevel > INFO) {
log("wrote 8 MSB to 0x" + Utils.hex8(usartDataAddress) + " = " + usartDataValue);
}
setReg(usartDataAddress, usartDataValue);
@@ -1390,7 +1391,7 @@ public void setChipSelect(boolean select) {
state = SpiState.WAITING;
}
- if (DEBUG) {
+ if (logLevel > INFO) {
log("setting chipSelect: " + chipSelect);
}
}
diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java
index df0ac3c..c052c03 100644
--- a/se/sics/mspsim/cli/DebugCommands.java
+++ b/se/sics/mspsim/cli/DebugCommands.java
@@ -36,6 +36,8 @@
import se.sics.mspsim.core.DbgInstruction;
import se.sics.mspsim.core.DisAsm;
import se.sics.mspsim.core.EmulationException;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
+import se.sics.mspsim.core.LogListener;
import se.sics.mspsim.core.Loggable;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.MSP430Constants;
@@ -595,10 +597,12 @@ public int executeCommand(CommandContext context) {
});
ch.registerCommand("log", new BasicAsyncCommand("log a loggable object", "[loggable...]" ) {
- private Loggable[] loggables = null;
+ private Loggable[] logs;
+ private int[] logLevels;
+ private LogListener logListener;
@Override
- public int executeCommand(CommandContext context) {
+ public int executeCommand(final CommandContext context) {
if (context.getArgumentCount() == 0) {
Loggable[] loggable = cpu.getLoggables();
for (Loggable unit : loggable) {
@@ -614,7 +618,7 @@ public int executeCommand(CommandContext context) {
return 0;
}
- Loggable[] logs = new Loggable[context.getArgumentCount()];
+ final Loggable[] logs = new Loggable[context.getArgumentCount()];
for(int i = 0, n = context.getArgumentCount(); i < n; i++) {
logs[i] = cpu.getLoggable(context.getArgument(i));
if (logs[i] == null) {
@@ -622,18 +626,56 @@ public int executeCommand(CommandContext context) {
return 1;
}
}
-// TODO: fix this in emulation logger - so that it can be added as listener and handle filtering
-// for(Loggable l : logs) {
-// l.setLogStream(context.out);
-// }
- this.loggables = logs;
+ logListener = new LogListener() {
+
+ boolean isLogging(Loggable source) {
+ for(Loggable log : logs) {
+ if (source == log) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void log(Loggable source, String message) {
+ if (isLogging(source)) {
+ context.out.println(source.getID() + ": " + message);
+ }
+ }
+
+ @Override
+ public void logw(Loggable source, WarningType type,
+ String message) throws EmulationException {
+ if (isLogging(source)) {
+ context.out.println("# " + source.getID() + "[" + type + "]: " + message);
+ }
+ }
+
+ };
+ this.log |
|
From: Joakim E. <jo...@us...> - 2012-11-05 15:46:47
|
The branch "master" has been updated
via ad8bd6a6ea6cc022b55ddd12eee7923fd8871848 (commit)
from 108721194897315717b41870cff9264ac3c923b6 (commit)
Changed paths:
M se/sics/mspsim/chip/AT45DB.java
M se/sics/mspsim/chip/Beeper.java
M se/sics/mspsim/chip/CC2420.java
M se/sics/mspsim/chip/CC2520.java
M se/sics/mspsim/chip/DS2411.java
M se/sics/mspsim/chip/M25P80.java
M se/sics/mspsim/cli/DebugCommands.java
M se/sics/mspsim/core/Chip.java
M se/sics/mspsim/core/DMA.java
M se/sics/mspsim/core/EmulationLogger.java
M se/sics/mspsim/core/Flash.java
M se/sics/mspsim/core/FlashSegment.java
M se/sics/mspsim/core/IOPort.java
M se/sics/mspsim/core/IOUnit.java
A se/sics/mspsim/core/LogListener.java
M se/sics/mspsim/core/Loggable.java
M se/sics/mspsim/core/MSP430Constants.java
M se/sics/mspsim/core/MSP430Core.java
M se/sics/mspsim/core/Multiplier.java
M se/sics/mspsim/core/Multiplier32.java
M se/sics/mspsim/core/RAMOffsetSegment.java
M se/sics/mspsim/core/RAMSegment.java
M se/sics/mspsim/core/Timer.java
M se/sics/mspsim/core/USART.java
M se/sics/mspsim/core/USCI.java
M se/sics/mspsim/core/Watchdog.java
M se/sics/mspsim/platform/GenericNode.java
M se/sics/mspsim/util/DefaultEmulationLogger.java
- Log -----------------------------------------------------------------
commit ad8bd6a6ea6cc022b55ddd12eee7923fd8871848
Author: Joakim Eriksson <jo...@si...>
Date: Mon Nov 5 16:45:31 2012 +0100
refactored logging
diff --git a/se/sics/mspsim/chip/AT45DB.java b/se/sics/mspsim/chip/AT45DB.java
index 3f7135e..175da2f 100644
--- a/se/sics/mspsim/chip/AT45DB.java
+++ b/se/sics/mspsim/chip/AT45DB.java
@@ -42,6 +42,7 @@
package se.sics.mspsim.chip;
import java.io.IOException;
import se.sics.mspsim.core.*;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
public class AT45DB extends ExternalFlash implements USARTListener {
@@ -183,7 +184,7 @@ public void dataReceived(USARTSource source, int data) {
buf_num = (state == BUFFER1_READ ? 1 : 2);
source.byteReceived(readBuffer(buf_num, bufferAddress++));
if(bufferAddress >= PAGE_SIZE)
- logw("ERROR: Buffer Read past buffer size: " + bufferAddress);
+ logw(WarningType.EXECUTION, "ERROR: Buffer Read past buffer size: " + bufferAddress);
break;
case BUFFER1_WRITE:
@@ -191,7 +192,7 @@ public void dataReceived(USARTSource source, int data) {
buf_num = (state == BUFFER1_WRITE ? 1 : 2);
writeBuffer(buf_num, bufferAddress++, data);
if(bufferAddress >= PAGE_SIZE)
- logw("ERROR: Buffer Write past buffer size: " + bufferAddress);
+ logw(WarningType.EXECUTION, "ERROR: Buffer Write past buffer size: " + bufferAddress);
source.byteReceived(0);
break;
@@ -260,7 +261,7 @@ public void dataReceived(USARTSource source, int data) {
source.byteReceived(0);
break;
default:
- logw("WARNING: Command not implemented: " + data);
+ logw(WarningType.EMULATION_ERROR, "WARNING: Command not implemented: " + data);
source.byteReceived(0);
break;
}
diff --git a/se/sics/mspsim/chip/Beeper.java b/se/sics/mspsim/chip/Beeper.java
index d916d21..15016f6 100644
--- a/se/sics/mspsim/chip/Beeper.java
+++ b/se/sics/mspsim/chip/Beeper.java
@@ -47,6 +47,7 @@
import javax.sound.sampled.SourceDataLine;
import se.sics.mspsim.core.Chip;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.core.MSP430Core;
import se.sics.mspsim.core.TimeEvent;
@@ -110,13 +111,13 @@ public void execute(long t) {
try {
dataLine = (SourceDataLine) AudioSystem.getLine(dli);
if (dataLine == null) {
- logw("No audio data line available");
+ logw(WarningType.EMULATION_ERROR, "No audio data line available");
} else {
dataLine.open(dataLine.getFormat(), 16384);
volume = (FloatControl) dataLine.getControl(FloatControl.Type.MASTER_GAIN);
}
} catch (Exception e) {
- logw("Could not get audio data line: " + e);
+ logw(WarningType.EMULATION_ERROR, "Could not get audio data line: " + e);
}
if (dataLine != null) {
isSoundEnabled = true;
diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java
index 8e0b015..3ab7a84 100644
--- a/se/sics/mspsim/chip/CC2420.java
+++ b/se/sics/mspsim/chip/CC2420.java
@@ -37,6 +37,7 @@
*/
package se.sics.mspsim.chip;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.core.IOPort;
import se.sics.mspsim.core.MSP430Core;
import se.sics.mspsim.core.TimeEvent;
@@ -880,10 +881,10 @@ public void dataReceived(USARTSource source, int data) {
if(txCursor == 0) {
if ((data & 0xff) > 127) {
- logger.warning(this, "CC2420: Warning - packet size too large: " + (data & 0xff));
+ logger.logw(this, WarningType.EXECUTION, "CC2420: Warning - packet size too large: " + (data & 0xff));
}
} else if (txCursor > 127) {
- logger.warning(this, "CC2420: Warning - TX Cursor wrapped");
+ logger.logw(this, WarningType.EXECUTION, "CC2420: Warning - TX Cursor wrapped");
txCursor = 0;
}
memory[RAM_TXFIFO + txCursor] = data & 0xff;
@@ -904,7 +905,7 @@ public void dataReceived(USARTSource source, int data) {
if (!ramRead) {
memory[usartDataAddress++] = data;
if (usartDataAddress >= 0x180) {
- logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!");
+ logger.logw(this, WarningType.EXECUTION, "CC2420: Warning - RAM position too big - wrapping!");
usartDataAddress = 0;
}
if (DEBUG && usartDataAddress == RAM_PANID + 2) {
@@ -916,7 +917,7 @@ public void dataReceived(USARTSource source, int data) {
//log("Read RAM Addr: " + address + " Data: " + memory[address]);
source.byteReceived(memory[usartDataAddress++]);
if (usartDataAddress >= 0x180) {
- logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!");
+ logger.logw(this, WarningType.EXECUTION, "CC2420: Warning - RAM position too big - wrapping!");
usartDataAddress = 0;
}
return;
@@ -928,7 +929,7 @@ public void dataReceived(USARTSource source, int data) {
} else {
/* No VREG but chip select */
source.byteReceived(0);
- logw("**** Warning - writing to CC2420 when VREG is off!!!");
+ logw(WarningType.EXECUTION, "**** Warning - writing to CC2420 when VREG is off!!!");
}
}
@@ -1079,7 +1080,7 @@ private void txNext() {
memory[RAM_TXFIFO + len] = txCrc.getCRCLow();
}
if (txfifoPos > 0x7f) {
- logw("**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos);
+ logw(WarningType.EXECUTION, "**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos);
}
if (rfListener != null) {
if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
diff --git a/se/sics/mspsim/chip/CC2520.java b/se/sics/mspsim/chip/CC2520.java
index 925f441..ba84bd1 100644
--- a/se/sics/mspsim/chip/CC2520.java
+++ b/se/sics/mspsim/chip/CC2520.java
@@ -36,6 +36,7 @@
package se.sics.mspsim.chip;
import se.sics.mspsim.core.*;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.ArrayFIFO;
import se.sics.mspsim.util.CCITT_CRC;
import se.sics.mspsim.util.Utils;
@@ -819,7 +820,7 @@ void writeMemory(int address, int data) {
switch(address) {
case REG_TXPOWER:
if (!isDefinedTxPower(data)) {
- logw("*** Warning - writing an undefined TXPOWER value (0x"
+ logw(WarningType.EXECUTION, "*** Warning - writing an undefined TXPOWER value (0x"
+ Utils.hex8(data) + ") to CC2520!!!");
}
break;
@@ -882,14 +883,14 @@ public void dataReceived(USARTSource source, int data) {
if (stateMachine == RadioState.VREG_OFF) {
/* No VREG but chip select */
source.byteReceived(0);
- logw("**** Warning - writing to CC2520 when VREG is off!!!");
+ logw(WarningType.EXECUTION, "**** Warning - writing to CC2520 when VREG is off!!!");
return;
}
if (command == null) {
command = cc2520SPI.getCommand(data);
if (command == null) {
- logw("**** Warning - not implemented command on SPI: " + data);
+ logw(WarningType.EMULATION_ERROR, "**** Warning - not implemented command on SPI: " + data);
} else if (DEBUG) {
if (!"SNOP".equals(command.name)) {
log("SPI command: " + command.name);
@@ -1028,7 +1029,7 @@ private void txNext() {
memory[RAM_TXFIFO + len] = txCrc.getCRCLow();
}
if (txfifoPos > 0x7f) {
- logw("**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos);
+ logw(WarningType.EXECUTION, "**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos);
}
if (rfListener != null) {
if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF));
@@ -1139,10 +1140,10 @@ void writeTXFIFO(int data) {
if(txCursor == 0) {
if ((data & 0xff) > 127) {
- logger.warning(this, "CC2420: Warning - packet size too large: " + (data & 0xff));
+ logger.logw(this, WarningType.EXECUTION, "CC2520: Warning - packet size too large: " + (data & 0xff));
}
} else if (txCursor > 127) {
- logger.warning(this, "CC2420: Warning - TX Cursor wrapped");
+ logger.logw(this, WarningType.EXECUTION, "CC2520: Warning - TX Cursor wrapped");
txCursor = 0;
}
memory[RAM_TXFIFO + txCursor] = data & 0xff;
diff --git a/se/sics/mspsim/chip/DS2411.java b/se/sics/mspsim/chip/DS2411.java
index ddcd58b..57027ab 100644
--- a/se/sics/mspsim/chip/DS2411.java
+++ b/se/sics/mspsim/chip/DS2411.java
@@ -49,8 +49,6 @@
public class DS2411 extends Chip {
- private static final boolean DEBUG_DS2411 = false;
-
private enum STATE {
IDLE, WAIT_FOR_RESET, RESETTING, SIGNAL_READY, READY, WAIT_SENDING, SENDING
}
@@ -111,9 +109,6 @@ public void execute(long t) {
public DS2411(MSP430Core cpu) {
super("DS2411", "Silicon Serial Number", cpu);
- if (DEBUG_DS2411) {
- setLogStream(System.out);
- }
}
private int crcAdd(int acc, int data) {
diff --git a/se/sics/mspsim/chip/M25P80.java b/se/sics/mspsim/chip/M25P80.java
index 191d6c2..abef6e8 100644
--- a/se/sics/mspsim/chip/M25P80.java
+++ b/se/sics/mspsim/chip/M25P80.java
@@ -42,6 +42,7 @@
package se.sics.mspsim.chip;
import java.io.IOException;
import se.sics.mspsim.core.*;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.Utils;
public class M25P80 extends ExternalFlash implements USARTListener, PortListener, Memory {
@@ -342,7 +343,7 @@ private void writeStatus(double time) {
}
private void programPage() {
- if (writing) logw("Can not set program page while already writing... from $" + Utils.hex(cpu.getPC(), 4));
+ if (writing) logw(WarningType.EXECUTION, "Can not set program page while already writing... from $" + Utils.hex(cpu.getPC(), 4));
writeStatus(PROGRAM_PAGE_MILLIS);
ensureLoaded(blockWriteAddress);
for (int i = 0; i < readMemory.length; i++) {
diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java
index 91a0d71..df0ac3c 100644
--- a/se/sics/mspsim/cli/DebugCommands.java
+++ b/se/sics/mspsim/cli/DebugCommands.java
@@ -622,9 +622,10 @@ public int executeCommand(CommandContext context) {
return 1;
}
}
- for(Loggable l : logs) {
- l.setLogStream(context.out);
- }
+// TODO: fix this in emulation logger - so that it can be added as listener and handle filtering
+// for(Loggable l : logs) {
+// l.setLogStream(context.out);
+// }
this.loggables = logs;
return 0;
}
@@ -632,7 +633,7 @@ public int executeCommand(CommandContext context) {
public void stopCommand(CommandContext context) {
if (loggables != null) {
for(Loggable l : loggables) {
- l.clearLogStream();
+// l.clearLogStream();
}
}
}
diff --git a/se/sics/mspsim/core/Chip.java b/se/sics/mspsim/core/Chip.java
index cd9ccc3..c3d6307 100644
--- a/se/sics/mspsim/core/Chip.java
+++ b/se/sics/mspsim/core/Chip.java
@@ -37,6 +37,7 @@
package se.sics.mspsim.core;
import java.io.PrintStream;
+import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.ArrayUtils;
/ |
|
From: Niclas F. <ni...@us...> - 2012-11-01 16:30:49
|
The branch "master" has been updated
via 108721194897315717b41870cff9264ac3c923b6 (commit)
from 995a336e365abc0b7d35099675e562b3bc9fb055 (commit)
Changed paths:
M se/sics/mspsim/config/MSP430f149Config.java
M se/sics/mspsim/config/MSP430f1611Config.java
M se/sics/mspsim/config/MSP430f2617Config.java
M se/sics/mspsim/core/MSP430Config.java
M se/sics/mspsim/core/MSP430Core.java
A se/sics/mspsim/core/RAMOffsetSegment.java
- Log -----------------------------------------------------------------
commit 108721194897315717b41870cff9264ac3c923b6
Author: Niclas Finne <nf...@si...>
Date: Thu Nov 1 15:53:14 2012 +0100
Added support for mirrored RAM segments
diff --git a/se/sics/mspsim/config/MSP430f149Config.java b/se/sics/mspsim/config/MSP430f149Config.java
index 83231d2..0b5cfe7 100644
--- a/se/sics/mspsim/config/MSP430f149Config.java
+++ b/se/sics/mspsim/config/MSP430f149Config.java
@@ -38,9 +38,11 @@
public MSP430f149Config() {
/* MSP430f149 is similar to MSP430f1611 but the memory map is different */
+ infoMemConfig(0x1000, 128 * 2);
mainFlashConfig(0x1100, 60 * 1024);
ramConfig(0x0200, 2 * 1024);
- System.out.println("*** Setting up MSP430f149");
+ // No mirrored RAM
+ ramMirrorConfig(0, 0, 0);
}
}
diff --git a/se/sics/mspsim/config/MSP430f1611Config.java b/se/sics/mspsim/config/MSP430f1611Config.java
index 410dfaa..99e4dfc 100644
--- a/se/sics/mspsim/config/MSP430f1611Config.java
+++ b/se/sics/mspsim/config/MSP430f1611Config.java
@@ -64,12 +64,11 @@ public MSP430f1611Config() {
infoMemConfig(0x1000, 128 * 2);
mainFlashConfig(0x4000, 48 * 1024);
ramConfig(0x1100, 10 * 1024);
+ ramMirrorConfig(0x200, 2 * 1024, 0x1100);
}
public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) {
- System.out.println("*** Setting up f1611 IO!");
-
USART usart0 = new USART(cpu, 0, cpu.memory, 0x70);
USART usart1 = new USART(cpu, 1, cpu.memory, 0x78);
cpu.setIORange(0x70, 8, usart0);
diff --git a/se/sics/mspsim/config/MSP430f2617Config.java b/se/sics/mspsim/config/MSP430f2617Config.java
index 5d4670c..6f450e9 100644
--- a/se/sics/mspsim/config/MSP430f2617Config.java
+++ b/se/sics/mspsim/config/MSP430f2617Config.java
@@ -81,6 +81,7 @@ public MSP430f2617Config() {
infoMemConfig(0x1000, 128 * 2);
mainFlashConfig(0x3100, 92 * 1024);
ramConfig(0x1100, 8 * 1024);
+ ramMirrorConfig(0x200, 2 * 1024, 0x1100);
}
public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) {
diff --git a/se/sics/mspsim/core/MSP430Config.java b/se/sics/mspsim/core/MSP430Config.java
index 3cb67d1..158cb32 100644
--- a/se/sics/mspsim/core/MSP430Config.java
+++ b/se/sics/mspsim/core/MSP430Config.java
@@ -87,6 +87,9 @@ public UARTConfig(int txVector, int rxVector, int txBit, int rxBit, int sftAddr,
public int ramStart = 0x2000;
public int ramSize = 2048;
+ public int ramMirrorStart = 0x0;
+ public int ramMirrorSize = 0x0;
+ public int ramMirrorAddress = 0x0;
public int flashControllerOffset = 0x128;
@@ -103,6 +106,10 @@ public boolean isRAM(int address) {
return address >= ramStart && address < ramStart + ramSize;
}
+ public boolean isRAMMirror(int address) {
+ return ramMirrorSize > 0 && address >= ramMirrorStart && address < ramMirrorStart + ramMirrorSize;
+ }
+
public boolean isFlash(int address) {
return address >= mainFlashStart && address < mainFlashStart + mainFlashSize;
}
@@ -139,6 +146,12 @@ public void ramConfig(int start, int size) {
ramSize = size;
}
+ public void ramMirrorConfig(int start, int size, int address) {
+ ramMirrorStart = start;
+ ramMirrorSize = size;
+ ramMirrorAddress = address;
+ }
+
public void ioMemSize(int size) {
maxMemIO = size;
}
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index a726064..3742a3d 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -194,6 +194,7 @@ public int read(int address, boolean word, long cycles) {
/* setup memory segments */
int maxSeg = MAX_MEM >> 8;
Memory ramSegment = new RAMSegment(this);
+ RAMOffsetSegment ramMirrorSegment = null;
Memory flashSegment = new FlashSegment(this, flash);
IOSegment ioSegment = new IOSegment(this, MAX_MEM_IO, voidIO);
Memory noMemorySegment = new NoMemSegment(this);
@@ -201,6 +202,13 @@ public int read(int address, boolean word, long cycles) {
if (config.isRAM(i << 8)) {
// System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8));
memorySegments[i] = ramSegment;
+ } else if (config.isRAMMirror(i << 8)) {
+ if (ramMirrorSegment == null) {
+ ramMirrorSegment = new RAMOffsetSegment(this, config.ramMirrorAddress - config.ramMirrorStart);
+ }
+// System.out.println("Setting RAM mirror segment at: " + Utils.hex(i << 8, 4)
+// + " => " + Utils.hex((i << 8) + ramMirrorSegment.getOffset()));
+ memorySegments[i] = ramMirrorSegment;
} else if (config.isFlash(i << 8) || config.isInfoMem(i << 8)) {
// System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8));
memorySegments[i] = flashSegment;
diff --git a/se/sics/mspsim/core/RAMOffsetSegment.java b/se/sics/mspsim/core/RAMOffsetSegment.java
new file mode 100644
index 0000000..1b79849
--- /dev/null
+++ b/se/sics/mspsim/core/RAMOffsetSegment.java
@@ -0,0 +1,93 @@
+/**
+ * Copyright (c) 2012, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of MSPSim.
+ *
+ * -----------------------------------------------------------------
+ *
+ * RAMOffsetMemory
+ *
+ * Author : Niclas Finne
+ * Created : Oct 24 21:47:42 2012
+ */
+
+package se.sics.mspsim.core;
+
+class RAMOffsetSegment implements Memory {
+
+ private final MSP430Core core;
+ private final int memory[];
+ private final int offset;
+
+ RAMOffsetSegment(MSP430Core core, int offset) {
+ this.core = core;
+ this.memory = core.memory;
+ this.offset = offset;
+ }
+
+ @Override public int read(int address, AccessMode mode, AccessType type)
+ throws EmulationException {
+ address += offset;
+ int val = memory[address] & 0xff;
+ if (mode != AccessMode.BYTE) {
+ val |= (memory[address + 1] << 8);
+ if ((address & 1) != 0) {
+ core.printWarning(MSP430Constants.MISALIGNED_READ, address);
+ }
+ if (mode == AccessMode.WORD20) {
+ val |= (memory[address + 2] << 16) | (memory[address + 3] << 24);
+ }
+ val &= mode.mask;
+ }
+ return val;
+ }
+
+ @Override public void write(int dstAddress, int dst, AccessMode mode)
+ throws EmulationException {
+ dstAddress += offset;
+ memory[dstAddress] = dst & 0xff;
+ if (mode != AccessMode.BYTE) {
+ memory[dstAddress + 1] = (dst >> 8) & 0xff;
+ if ((dstAddress & 1) != 0) {
+ core.printWarning(MSP430Constants.MISALIGNED_WRITE, dstAddress);
+ }
+ if (mode != AccessMode.WORD) {
+ memory[dstAddress + 2] = (dst >> 16) & 0xff;
+ memory[dstAddress + 3] = (dst >> 24) & 0xff;
+ }
+ }
+ }
+
+ @Override public int get(int address, AccessMode mode) {
+ return read(address, mode, AccessType.READ);
+ }
+
+ @Override public void set(int address, int data, AccessMode mode) {
+ write(address, data, mode);
+ }
+
+}
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/config/MSP430f149Config.java | 4 +-
se/sics/mspsim/config/MSP430f1611Config.java | 3 +-
se/sics/mspsim/config/MSP430f2617Config.java | 1 +
se/sics/mspsim/core/MSP430Config.java | 15 ++++-
se/sics/mspsim/core/MSP430Core.java | 8 ++
se/sics/mspsim/core/RAMOffsetSegment.java | 93 ++++++++++++++++++++++++++
6 files changed, 120 insertions(+), 4 deletions(-)
create mode 100644 se/sics/mspsim/core/RAMOffsetSegment.java
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-17 23:35:23
|
The branch "master" has been updated
via 995a336e365abc0b7d35099675e562b3bc9fb055 (commit)
from dbbc771224c8b00f12f5bd560272bcfcee95a631 (commit)
Changed paths:
M se/sics/mspsim/cli/DebugCommands.java
M se/sics/mspsim/core/MSP430Core.java
M se/sics/mspsim/core/RegisterMonitor.java
M se/sics/mspsim/ui/StackUI.java
M se/sics/mspsim/util/StackMonitor.java
- Log -----------------------------------------------------------------
commit 995a336e365abc0b7d35099675e562b3bc9fb055
Author: Niclas Finne <nf...@si...>
Date: Wed Oct 17 21:54:34 2012 +0200
Updated RegisterMonitor to use same access modes as Memory
diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java
index d95c936..91a0d71 100644
--- a/se/sics/mspsim/cli/DebugCommands.java
+++ b/se/sics/mspsim/cli/DebugCommands.java
@@ -206,7 +206,7 @@ public int executeCommand(final CommandContext context) {
}
monitor = new RegisterMonitor.Adapter() {
@Override
- public void notifyWriteBefore(int register, int data, int mode) {
+ public void notifyWriteBefore(int register, int data, AccessMode mode) {
if (watchMode == 0) {
int pc = cpu.getPC();
String adrStr = getRegisterName(register);
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index c62fdd0..a726064 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -438,9 +438,9 @@ public void writeRegister(int r, int value) {
RegisterMonitor rwm = regWriteMonitors[r];
if (rwm != null) {
// TODO Add register access mode
- rwm.notifyWriteBefore(r, value, 0);
+ rwm.notifyWriteBefore(r, value, AccessMode.WORD);
reg[r] = value;
- rwm.notifyWriteAfter(r, value, 0);
+ rwm.notifyWriteAfter(r, value, AccessMode.WORD);
} else {
reg[r] = value;
}
@@ -493,9 +493,9 @@ public int readRegister(int r) {
RegisterMonitor rrm = regReadMonitors[r];
if (rrm != null) {
// TODO Register access mode
- rrm.notifyReadBefore(r, 0);
+ rrm.notifyReadBefore(r, AccessMode.WORD);
value = reg[r];
- rrm.notifyReadAfter(r, 0);
+ rrm.notifyReadAfter(r, AccessMode.WORD);
} else {
value = reg[r];
}
@@ -512,9 +512,9 @@ public int readRegisterCG(int r, int m) {
RegisterMonitor rrm = regReadMonitors[r];
if (rrm != null) {
// TODO Register access mode
- rrm.notifyReadBefore(r, 0);
+ rrm.notifyReadBefore(r, AccessMode.WORD);
value = reg[r];
- rrm.notifyReadAfter(r, 0);
+ rrm.notifyReadAfter(r, AccessMode.WORD);
} else {
value = reg[r];
}
@@ -525,18 +525,18 @@ public int incRegister(int r, int value) {
int registerValue;
RegisterMonitor rm = regReadMonitors[r];
if (rm != null) {
- rm.notifyReadBefore(r, 0);
+ rm.notifyReadBefore(r, AccessMode.WORD);
registerValue = reg[r];
- rm.notifyReadAfter(r, 0);
+ rm.notifyReadAfter(r, AccessMode.WORD);
} else {
registerValue = reg[r];
}
rm = regWriteMonitors[r];
registerValue += value;
if (rm != null) {
- rm.notifyWriteBefore(r, registerValue, 0);
+ rm.notifyWriteBefore(r, registerValue, AccessMode.WORD);
reg[r] = registerValue;
- rm.notifyWriteAfter(r, registerValue, 0);
+ rm.notifyWriteAfter(r, registerValue, AccessMode.WORD);
} else {
reg[r] = registerValue;
}
diff --git a/se/sics/mspsim/core/RegisterMonitor.java b/se/sics/mspsim/core/RegisterMonitor.java
index 9d44ce9..b49fc3c 100644
--- a/se/sics/mspsim/core/RegisterMonitor.java
+++ b/se/sics/mspsim/core/RegisterMonitor.java
@@ -4,28 +4,28 @@
public interface RegisterMonitor {
- public void notifyReadBefore(int reg, int mode);
- public void notifyReadAfter(int reg, int mode);
+ public void notifyReadBefore(int reg, Memory.AccessMode mode);
+ public void notifyReadAfter(int reg, Memory.AccessMode mode);
- public void notifyWriteBefore(int reg, int data, int mode);
- public void notifyWriteAfter(int reg, int data, int mode);
+ public void notifyWriteBefore(int reg, int data, Memory.AccessMode mode);
+ public void notifyWriteAfter(int reg, int data, Memory.AccessMode mode);
public static class Adapter implements RegisterMonitor {
@Override
- public void notifyReadBefore(int reg, int mode) {
+ public void notifyReadBefore(int reg, Memory.AccessMode mode) {
}
@Override
- public void notifyReadAfter(int reg, int mode) {
+ public void notifyReadAfter(int reg, Memory.AccessMode mode) {
}
@Override
- public void notifyWriteBefore(int reg, int data, int mode) {
+ public void notifyWriteBefore(int reg, int data, Memory.AccessMode mode) {
}
@Override
- public void notifyWriteAfter(int reg, int data, int mode) {
+ public void notifyWriteAfter(int reg, int data, Memory.AccessMode mode) {
}
}
@@ -34,7 +34,7 @@ public void notifyWriteAfter(int reg, int data, int mode) {
public static final Proxy INSTANCE = new Proxy();
@Override
- public void notifyReadBefore(int reg, int mode) {
+ public void notifyReadBefore(int reg, Memory.AccessMode mode) {
RegisterMonitor[] listeners = this.listeners;
for(RegisterMonitor listener : listeners) {
listener.notifyReadBefore(reg, mode);
@@ -42,7 +42,7 @@ public void notifyReadBefore(int reg, int mode) {
}
@Override
- public void notifyReadAfter(int reg, int mode) {
+ public void notifyReadAfter(int reg, Memory.AccessMode mode) {
RegisterMonitor[] listeners = this.listeners;
for(RegisterMonitor listener : listeners) {
listener.notifyReadAfter(reg, mode);
@@ -50,7 +50,7 @@ public void notifyReadAfter(int reg, int mode) {
}
@Override
- public void notifyWriteBefore(int reg, int data, int mode) {
+ public void notifyWriteBefore(int reg, int data, Memory.AccessMode mode) {
RegisterMonitor[] listeners = this.listeners;
for(RegisterMonitor listener : listeners) {
listener.notifyWriteBefore(reg, data, mode);
@@ -58,7 +58,7 @@ public void notifyWriteBefore(int reg, int data, int mode) {
}
@Override
- public void notifyWriteAfter(int reg, int data, int mode) {
+ public void notifyWriteAfter(int reg, int data, Memory.AccessMode mode) {
RegisterMonitor[] listeners = this.listeners;
for(RegisterMonitor listener : listeners) {
listener.notifyWriteAfter(reg, data, mode);
diff --git a/se/sics/mspsim/ui/StackUI.java b/se/sics/mspsim/ui/StackUI.java
index 2bd6324..366b22d 100644
--- a/se/sics/mspsim/ui/StackUI.java
+++ b/se/sics/mspsim/ui/StackUI.java
@@ -45,6 +45,7 @@
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.RegisterMonitor;
+import se.sics.mspsim.core.Memory.AccessMode;
import se.sics.mspsim.util.ComponentRegistry;
import se.sics.mspsim.util.MapTable;
import se.sics.mspsim.util.ServiceComponent;
@@ -148,7 +149,7 @@ private void setup() {
registerMonitor = new RegisterMonitor.Adapter() {
@Override
- public void notifyWriteBefore(int register, int data, int mode) {
+ public void notifyWriteBefore(int register, int data, AccessMode mode) {
int size = stackStartAddress - data;
if (minData[pos] > size) {
minData[pos] = size;
diff --git a/se/sics/mspsim/util/StackMonitor.java b/se/sics/mspsim/util/StackMonitor.java
index bc3d445..bc01294 100644
--- a/se/sics/mspsim/util/StackMonitor.java
+++ b/se/sics/mspsim/util/StackMonitor.java
@@ -1,6 +1,7 @@
package se.sics.mspsim.util;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.RegisterMonitor;
+import se.sics.mspsim.core.Memory.AccessMode;
public class StackMonitor {
@@ -61,7 +62,7 @@ public StackMonitor(MSP430 cpu) {
cpu.addRegisterWriteMonitor(MSP430.SP, new RegisterMonitor.Adapter() {
@Override
- public void notifyWriteBefore(int reg, int data, int mode) {
+ public void notifyWriteBefore(int reg, int data, AccessMode mode) {
// TODO add support for 20 bit addresses
stack = ((stackStartAddress - data) + 0xffff) & 0xffff;
if (stack > stackMax) {
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/cli/DebugCommands.java | 2 +-
se/sics/mspsim/core/MSP430Core.java | 20 ++++++++++----------
se/sics/mspsim/core/RegisterMonitor.java | 24 ++++++++++++------------
se/sics/mspsim/ui/StackUI.java | 3 ++-
se/sics/mspsim/util/StackMonitor.java | 3 ++-
5 files changed, 27 insertions(+), 25 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-17 13:30:17
|
The branch "master" has been updated
via dbbc771224c8b00f12f5bd560272bcfcee95a631 (commit)
from 5d39de63c60008868a933fa5d0d90ba0f242b2c5 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit dbbc771224c8b00f12f5bd560272bcfcee95a631
Author: Niclas Finne <nf...@si...>
Date: Wed Oct 17 15:28:52 2012 +0200
Fixed immediate mode for 20 bit instructions
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index b343028..c62fdd0 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1830,7 +1830,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
}
// When is PC incremented - assuming immediately after "read"?
- incRegister(PC, 2);
+ pc += 2;
+ writeRegister(PC, pc);
cycles += dstRegMode ? 3 : 6;
break;
}
@@ -1842,9 +1843,10 @@ public int emulateOP(long maxCycles) throws EmulationException {
case AM_IND_AUTOINC:
if (srcRegister == PC) {
/* PC is always handled as word */
- srcAddress = readRegister(PC);
+ src = currentSegment.read(pc, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ src += extSrc;
pc += 2;
- incRegister(PC, 2);
+ writeRegister(PC, pc);
cycles += dstRegMode ? 2 : 5;
} else {
srcAddress = readRegister(srcRegister);
@@ -1864,13 +1866,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (op != MOV) {
dst = readRegister(dstRegister);
dst &= mode.mask;
-//XXX if (word) {
-// dst &= 0xffff;
-// } else if (wordx20) {
-// dst &= 0xfffff;
-// } else {
-// dst &= 0xff;
-// }
}
} else {
// PC Could have changed above!
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 17 ++++++-----------
1 files changed, 6 insertions(+), 11 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-16 17:04:03
|
The branch "master" has been updated
via 5d39de63c60008868a933fa5d0d90ba0f242b2c5 (commit)
from 0dff1e14b990fedb6ed6ef63397fe605b77d2694 (commit)
Changed paths:
M se/sics/mspsim/ui/ChartPanel.java
M se/sics/mspsim/ui/StackUI.java
- Log -----------------------------------------------------------------
commit 5d39de63c60008868a933fa5d0d90ba0f242b2c5
Author: Niclas Finne <nf...@si...>
Date: Tue Oct 16 19:03:13 2012 +0200
Bug fix: Stack UI was not correctly updated for latest core
diff --git a/se/sics/mspsim/ui/ChartPanel.java b/se/sics/mspsim/ui/ChartPanel.java
index 69a3964..adc69bc 100644
--- a/se/sics/mspsim/ui/ChartPanel.java
+++ b/se/sics/mspsim/ui/ChartPanel.java
@@ -96,11 +96,11 @@ public void setAxisChart(Chart chart) {
}
public synchronized void addChart(Chart chart) {
- charts = (Chart[]) ArrayUtils.add(Chart.class, charts, chart);
+ charts = ArrayUtils.add(Chart.class, charts, chart);
}
public synchronized void removeChart(Chart chart) {
- charts = (Chart[]) ArrayUtils.remove(charts, chart);
+ charts = ArrayUtils.remove(charts, chart);
}
public Chart getChart(String name) {
diff --git a/se/sics/mspsim/ui/StackUI.java b/se/sics/mspsim/ui/StackUI.java
index c6c0200..2bd6324 100644
--- a/se/sics/mspsim/ui/StackUI.java
+++ b/se/sics/mspsim/ui/StackUI.java
@@ -57,8 +57,8 @@
private int updateCyclePeriod = 2500;
private final MSP430 cpu;
- private int heapStartAddress;
- private int stackStartAddress = 0xa00;
+ private int heapStartAddress = -1;
+ private int stackStartAddress = -1;
private ChartPanel chartPanel;
private LineChart minStackChart;
private LineChart maxStackChart;
@@ -93,14 +93,6 @@ public StackUI(MSP430 cpu, int updateCyclePeriod) {
this.updateCyclePeriod = updateCyclePeriod;
this.cpu = cpu;
- if (cpu.getDisAsm() != null) {
- MapTable mapTable = cpu.getDisAsm().getMap();
- if (mapTable != null) {
- this.heapStartAddress = mapTable.heapStartAddress;
- this.stackStartAddress = mapTable.stackStartAddress;
- }
- }
-
// diagram = new DotDiagram(2);
// diagram.setDotColor(0, Color.green);
// diagram.setDotColor(1, Color.green);
@@ -112,11 +104,26 @@ public StackUI(MSP430 cpu, int updateCyclePeriod) {
private void setup() {
if (chartPanel != null) return;
+
+ if (this.heapStartAddress < 0 && cpu.getDisAsm() != null) {
+ MapTable mapTable = cpu.getDisAsm().getMap();
+ if (mapTable != null) {
+ this.heapStartAddress = mapTable.heapStartAddress;
+ this.stackStartAddress = mapTable.stackStartAddress;
+ }
+ }
+ if (this.stackStartAddress < 0) {
+ // Did not find stack information in the firmware. Use CPU RAM
+ // boundary as most compilers will use this as stack.
+ this.stackStartAddress = cpu.config.ramStart + cpu.config.ramSize;
+ }
chartPanel = new ChartPanel();
+ if (this.stackStartAddress > 0 && this.heapStartAddress > 0) {
ConstantLineChart maxChart = new ConstantLineChart("Max", this.stackStartAddress - this.heapStartAddress);
maxChart.setConfig("color", Color.red);
chartPanel.addChart(maxChart);
+ }
minStackChart = new LineChart("Min Stack");
minStackChart.setConfig("color", Color.green);
@@ -141,8 +148,8 @@ private void setup() {
registerMonitor = new RegisterMonitor.Adapter() {
@Override
- public void notifyWriteBefore(int type, int adr, int data) {
- int size = ((stackStartAddress - data) + 0xffff) % 0xffff;
+ public void notifyWriteBefore(int register, int data, int mode) {
+ int size = stackStartAddress - data;
if (minData[pos] > size) {
minData[pos] = size;
}
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/ui/ChartPanel.java | 4 ++--
se/sics/mspsim/ui/StackUI.java | 37 ++++++++++++++++++++++---------------
2 files changed, 24 insertions(+), 17 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-12 17:19:23
|
The branch "master" has been updated
via 0dff1e14b990fedb6ed6ef63397fe605b77d2694 (commit)
from f38aa1f48724b97cbf5d7e0494ea668fe13c0f23 (commit)
Changed paths:
M se/sics/mspsim/emulink/EmuLink.java
M se/sics/mspsim/platform/GenericNode.java
- Log -----------------------------------------------------------------
commit 0dff1e14b990fedb6ed6ef63397fe605b77d2694
Author: Niclas Finne <nf...@si...>
Date: Fri Oct 12 19:18:28 2012 +0200
added support for write event (ELF file) and start/stop to step the node emulations
diff --git a/se/sics/mspsim/emulink/EmuLink.java b/se/sics/mspsim/emulink/EmuLink.java
index ece1f38..2dd042f 100755
--- a/se/sics/mspsim/emulink/EmuLink.java
+++ b/se/sics/mspsim/emulink/EmuLink.java
@@ -39,6 +39,7 @@
package se.sics.mspsim.emulink;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
@@ -51,7 +52,9 @@
import se.sics.json.JSONObject;
import se.sics.json.ParseException;
import se.sics.mspsim.Main;
+import se.sics.mspsim.core.MSP430Constants;
import se.sics.mspsim.platform.GenericNode;
+import se.sics.mspsim.util.Utils;
public class EmuLink {
@@ -59,12 +62,10 @@
private BufferedReader in;
private PrintWriter out;
private boolean isConnected = false;
+ private long globalEtime = 0L;
+ private long globalLastTime = 0L;
- int mode;
- int json = 0;
- StringBuilder buffer = new StringBuilder();
-
- Hashtable<String, GenericNode> nodes = new Hashtable<String, GenericNode>();
+ private final Hashtable<String, GenericNode> nodes = new Hashtable<String, GenericNode>();
public boolean isConnected() {
return !isConnected;
@@ -89,8 +90,12 @@ public boolean isConnected() {
private boolean createNode(String type, String id) {
String nt = Main.getNodeTypeByPlatform(type);
- System.out.println("Creating node: " + id + " type: " + type + " => " + nt);
+ System.out.println("EmuLink: Creating node '" + id + "' of type '" + type + "' => " + nt);
GenericNode node = Main.createNode(nt);
+ if (node == null) {
+ System.err.println("EmuLink: failed to create node '" + id + "' of type '" + type + "'");
+ return false;
+ }
nodes.put(id, node);
return true;
}
@@ -150,17 +155,113 @@ protected boolean handleMessage(JSONObject json) {
System.out.println("EmuLink: RECV " + json.toJSONString());
String event = json.getAsString("event");
if ("emulation_control".equals(event)) {
- // TODO control emulation
+ String command = json.getAsString("data");
+ if ("start".equals(command)) {
+ String[] nodes = getNodes(json);
+ long etime = json.getAsLong("etime", 0);
+
+ if (etime == 0) {
+ if (nodes == null) {
+ for (GenericNode node : this.nodes.values()) {
+ node.start();
+ }
+ } else {
+ for(String id : nodes) {
+ GenericNode node = this.nodes.get(id);
+ if (node != null) {
+ node.start();
+ } else {
+ System.err.println("EmuLink: could not find node '" + id + "'");
+ }
+ }
+ }
+ } else {
+ // Execute for specified time
+ globalEtime += etime;
+ if (nodes == null) {
+ for (GenericNode node : this.nodes.values()) {
+ long t0 = System.nanoTime(), t1;
+ node.getCPU().stepMicros(globalLastTime, etime);
+ t1 = System.nanoTime();
+ System.out.println("EmuLink: node " + node.getID()
+ + " is now at $" + Utils.hex(node.getCPU().getRegister(MSP430Constants.PC), 4)
+ + " " + (long)(node.getCPU().getTimeMillis() + 0.5) + "/" + (globalEtime / 1000)
+ + " (elapsed " + (t1 - t0) + " ns)");
+ }
+
+ } else {
+ for(String id : nodes) {
+ GenericNode node = this.nodes.get(id);
+ if (node != null) {
+ long t0 = System.nanoTime(), t1;
+ node.getCPU().stepMicros(globalLastTime, etime);
+ t1 = System.nanoTime();
+ System.out.println("EmuLink: node " + node.getID()
+ + " is now at $" + Utils.hex(node.getCPU().getRegister(MSP430Constants.PC), 4)
+ + " " + (long)(node.getCPU().getTimeMillis() + 0.5) + "/" + (globalEtime / 1000)
+ + " (elapsed " + (t1 - t0) + " ns)");
+ } else {
+ System.err.println("EmuLink: could not find node '" + id + "'");
+ }
+ }
+ }
+ globalLastTime = etime;
+ }
+ } else if ("stop".equals(command)) {
+ String[] nodes = getNodes(json);
+ if (nodes == null) {
+ for (GenericNode node : this.nodes.values()) {
+ node.stop();
+ }
+ } else {
+ for(String id : nodes) {
+ GenericNode node = this.nodes.get(id);
+ if (node != null) {
+ node.stop();
+ } else {
+ System.err.println("EmuLink: could not find node '" + id + "'");
+ }
+ }
+ }
+ } else if ("close".equals(command)) {
sendToSimulator("{\"response\":\"emulation_control\",\"data\":1}");
- if ("close".equals(json.getAsString("data"))) {
// Time to close the connection
return false;
}
+ sendToSimulator("{\"response\":\"emulation_control\",\"data\":1}");
+
} else if ("create".equals(event)) {
- // TODO setup emulated node
createNodes(json);
sendToSimulator("{\"response\":\"create\",\"data\":1}");
+ } else if ("write".equals(event)) {
+ String[] nodes = getNodes(json);
+ String file = json.getAsString("file");
+ if (nodes == null) {
+ System.err.println("EmuLink: no node specified for write");
+ } else if (file == null) {
+ System.err.println("EmuLink: no file specified for write");
+ } else if (!new File(file).isFile()) {
+ System.err.println("EmuLink: could not find file '" + file + "' for write");
+ } else {
+ for(String id : nodes) {
+ GenericNode node = this.nodes.get(id);
+ if (node == null) {
+ System.err.println("EmuLink: could not find node '" + id + "'");
+ continue;
+ }
+ try {
+ node.loadFirmware(file);
+ node.getCPU().reset();
+ } catch (IOException e) {
+ System.err.println("EmuLink: failed to load firmware '" + file + "'");
+ e.printStackTrace();
+ }
+ }
+ }
+ sendToSimulator("{\"response\":\"write\",\"data\":1}");
+ } else if ("remove".equals(event)) {
+ // TODO remove nodes
} else if ("serial".equals(event)) {
int data = json.getAsInt("data", -1);
JSONArray nodes;
@@ -196,10 +297,10 @@ protected void sendSerialToNode(String node, int data) {
}
protected void disconnect() {
- boolean wasConnected = isConnected;
+ boolean isDisconnecting = isConnected;
isConnected = false;
try {
- if (wasConnected) {
+ if (isDisconnecting) {
System.err.println("EmuLink: disconnecting...");
}
if (out != null) {
@@ -214,7 +315,7 @@ protected void disconnect() {
socket.close();
socket = null;
}
- if (wasConnected) {
+ if (isDisconnecting) {
System.err.println("EmuLink: disconnected");
}
} catch (IOException e) {
@@ -259,4 +360,5 @@ public static void main(String[] args) throws IOException {
EmuLink el = new EmuLink();
el.run();
}
+
}
diff --git a/se/sics/mspsim/platform/GenericNode.java b/se/sics/mspsim/platform/GenericNode.java
index 4bdfdcf..5270cb5 100644
--- a/se/sics/mspsim/platform/GenericNode.java
+++ b/se/sics/mspsim/platform/GenericNode.java
@@ -202,7 +202,7 @@ public void setupArgs(ArgumentManager config) throws IOException {
public void setup(ConfigManager config) {
this.config = config;
- EmulationLogger logger = (EmulationLogger) registry.getComponent("logger");
+ EmulationLogger logger = registry.getComponent(EmulationLogger.class, "logger");
if (logger == null) {
logger= new DefaultEmulationLogger(cpu, System.out);
registry.registerComponent("logger", logger);
@@ -212,7 +212,7 @@ public void setup(ConfigManager config) {
registry.registerComponent("config", config);
cpu.setEmulationLogger(logger);
- CommandHandler ch = (CommandHandler) registry.getComponent("commandHandler");
+ CommandHandler ch = registry.getComponent(CommandHandler.class, "commandHandler");
if (ch == null) {
if (config.getPropertyAsBoolean("jconsole", false)) {
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/emulink/EmuLink.java | 128 +++++++++++++++++++++++++++---
se/sics/mspsim/platform/GenericNode.java | 4 +-
2 files changed, 117 insertions(+), 15 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-12 00:57:59
|
The branch "master" has been updated
via f38aa1f48724b97cbf5d7e0494ea668fe13c0f23 (commit)
via a9077b69cd869134c79fc03751836df23dc7f831 (commit)
via 89e7c13489a9244889a1fd52bdc7a4fbd2e240f4 (commit)
via 9763b0a18eaf0d95f5a182f2b3853bb7987c9477 (commit)
from 2d9d82486c3124907a854af0d9189818cc9a6193 (commit)
Changed paths:
M se/sics/mspsim/Main.java
M se/sics/mspsim/cli/DebugCommands.java
M se/sics/mspsim/core/MSP430.java
M se/sics/mspsim/util/Utils.java
- Log -----------------------------------------------------------------
commit f38aa1f48724b97cbf5d7e0494ea668fe13c0f23
Author: Niclas Finne <nf...@si...>
Date: Fri Oct 12 02:55:46 2012 +0200
start trace at first position
diff --git a/se/sics/mspsim/core/MSP430.java b/se/sics/mspsim/core/MSP430.java
index 498b817..6c4d635 100644
--- a/se/sics/mspsim/core/MSP430.java
+++ b/se/sics/mspsim/core/MSP430.java
@@ -343,7 +343,7 @@ public void setTrace(int size) {
}
public int getBackTrace(int pos) {
- int tPos = tracePos - pos;
+ int tPos = tracePos - pos - 1;
if (tPos < 0) {
tPos += trace.length;
}
commit a9077b69cd869134c79fc03751836df23dc7f831
Author: Niclas Finne <nf...@si...>
Date: Fri Oct 12 02:49:04 2012 +0200
added hex method
diff --git a/se/sics/mspsim/util/Utils.java b/se/sics/mspsim/util/Utils.java
index 071fa33..8ab14ff 100644
--- a/se/sics/mspsim/util/Utils.java
+++ b/se/sics/mspsim/util/Utils.java
@@ -91,6 +91,10 @@ public static String binary16(int data) {
return s;
}
+ public static String hex(int data) {
+ return Integer.toString(data, 16);
+ }
+
public static String hex(int data, int len) {
String s = Integer.toString(data, 16);
if (s.length() < len) {
commit 89e7c13489a9244889a1fd52bdc7a4fbd2e240f4
Author: Niclas Finne <nf...@si...>
Date: Fri Oct 12 02:47:56 2012 +0200
made getNodeTypeByPlatform method public
diff --git a/se/sics/mspsim/Main.java b/se/sics/mspsim/Main.java
index d626a66..f532245 100644
--- a/se/sics/mspsim/Main.java
+++ b/se/sics/mspsim/Main.java
@@ -66,7 +66,7 @@ public static GenericNode createNode(String className) {
return null;
}
- private static String getNodeTypeByPlatform(String platform) {
+ public static String getNodeTypeByPlatform(String platform) {
if ("jcreate".equals(platform)) {
return "se.sics.mspsim.platform.jcreate.JCreateNode";
}
commit 9763b0a18eaf0d95f5a182f2b3853bb7987c9477
Author: Niclas Finne <nf...@si...>
Date: Fri Oct 12 02:47:25 2012 +0200
updated printreg command to show multiple registers, cleaned up trace command
diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java
index 50843bb..d95c936 100644
--- a/se/sics/mspsim/cli/DebugCommands.java
+++ b/se/sics/mspsim/cli/DebugCommands.java
@@ -374,14 +374,30 @@ public int executeCommand(CommandContext context) {
return 1;
}
});
- ch.registerCommand("printreg", new BasicCommand("print value of an register", "<register>") {
+ ch.registerCommand("printreg", new BasicCommand("print value of an register", "[register]") {
public int executeCommand(CommandContext context) {
- int register = context.getArgumentAsRegister(0);
+ if (context.getArgumentCount() > 0) {
+ for (int i = 0, n = context.getArgumentCount(); i < n; i++) {
+ int register = context.getArgumentAsRegister(i);
+ if (i > 0) {
+ context.out.print((i % 6) == 0 ? "\n" : " ");
+ }
if (register >= 0) {
- context.out.println(context.getArgument(0) + " = $" + Utils.hex(cpu.getRegister(register), 4));
- return 0;
+ context.out.print(getRegisterName(i) + "=$" + Utils.hex(cpu.getRegister(register), 4));
+ } else {
+ context.out.print(context.getArgument(i) + "=<not a register>");
+ }
+ }
+ } else {
+ for (int i = 0; i < 16; i++) {
+ if (i > 0) {
+ context.out.print((i % 6) == 0 ? "\n" : " ");
+ }
+ context.out.print(getRegisterName(i) + "=$" + Utils.hex(cpu.getRegister(i), 4));
}
- return -1;
+ }
+ context.out.println();
+ return 0;
}
});
ch.registerCommand("reset", new BasicCommand("reset the CPU", "") {
@@ -393,7 +409,7 @@ public int executeCommand(CommandContext context) {
ch.registerCommand("time", new BasicCommand("print the elapse time and cycles", "") {
public int executeCommand(CommandContext context) {
- long time = ((long)(cpu.getTimeMillis()));
+ long time = (long)cpu.getTimeMillis();
long wallDiff = System.currentTimeMillis() - lastWall;
context.out.println("Emulated time elapsed: " + time + "(ms) since last: " + (time - lastCall) + " ms" + " wallTime: " +
wallDiff + " ms speed factor: " +
@@ -622,25 +638,31 @@ public void stopCommand(CommandContext context) {
}
});
- ch.registerCommand("trace", new BasicCommand("store a trace of execution positions.", "<trace size | show>") {
+ ch.registerCommand("trace", new BasicCommand("store a trace of execution positions.", "[trace size | show]") {
@Override
public int executeCommand(CommandContext context) {
+ if (context.getArgumentCount() > 0) {
if ("show".equals(context.getArgument(0))) {
int size = cpu.getTraceSize();
- if (size == 0) {
- context.err.println("trace size is set to 0");
- } else {
+ if (size > 0) {
DisAsm disAsm = cpu.getDisAsm();
for (int i = 0; i < size; i++) {
int pc = cpu.getBackTrace(size - 1 - i);
DbgInstruction inst = disAsm.getDbgInstruction(pc, cpu);
inst.setPos(pc);
- context.out.println(inst);
+ context.out.println(inst.getASMLine(false));
}
+ return 0;
}
} else {
- cpu.setTrace(context.getArgumentAsInt(0));
+ int newSize = context.getArgumentAsInt(0, -1);
+ if (newSize < 0) {
+ return 1;
+ }
+ cpu.setTrace(newSize);
+ }
}
+ context.out.println("Trace size is set to " + cpu.getTraceSize() + " positions.");
return 0;
}
});
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/Main.java | 2 +-
se/sics/mspsim/cli/DebugCommands.java | 68 ++++++++++++++++++++++-----------
se/sics/mspsim/core/MSP430.java | 2 +-
se/sics/mspsim/util/Utils.java | 4 ++
4 files changed, 51 insertions(+), 25 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-11 21:12:52
|
The branch "master" has been updated
via 2d9d82486c3124907a854af0d9189818cc9a6193 (commit)
from 862780607857cf3b658c4815c50aaa5497ea43e2 (commit)
Changed paths:
M se/sics/mspsim/emulink/EmuLink.java
- Log -----------------------------------------------------------------
commit 2d9d82486c3124907a854af0d9189818cc9a6193
Author: Joakim Eriksson <jo...@si...>
Date: Thu Oct 11 23:11:59 2012 +0200
made it possible to create node via emulink
diff --git a/se/sics/mspsim/emulink/EmuLink.java b/se/sics/mspsim/emulink/EmuLink.java
index d125a5e..ece1f38 100755
--- a/se/sics/mspsim/emulink/EmuLink.java
+++ b/se/sics/mspsim/emulink/EmuLink.java
@@ -45,9 +45,13 @@
import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;
+import java.util.Hashtable;
+
import se.sics.json.JSONArray;
import se.sics.json.JSONObject;
import se.sics.json.ParseException;
+import se.sics.mspsim.Main;
+import se.sics.mspsim.platform.GenericNode;
public class EmuLink {
@@ -60,10 +64,50 @@
int json = 0;
StringBuilder buffer = new StringBuilder();
+ Hashtable<String, GenericNode> nodes = new Hashtable<String, GenericNode>();
+
public boolean isConnected() {
return !isConnected;
}
+ String[] getNodes(JSONObject json) {
+ JSONArray nodes;
+ String node;
+ String[] nString = null;
+ if ((nodes = json.getJSONArray("node")) != null) {
+ nString = new String[nodes.size()];
+ for(int i = 0, n = nodes.size(); i < n; i++) {
+ node = nodes.getAsString(i);
+ nString[i] = node;
+ }
+ } else if ((node = json.getAsString("node")) != null) {
+ nString = new String[1];
+ nString[0] = node;
+ }
+ return nString;
+ }
+
+ private boolean createNode(String type, String id) {
+ String nt = Main.getNodeTypeByPlatform(type);
+ System.out.println("Creating node: " + id + " type: " + type + " => " + nt);
+ GenericNode node = Main.createNode(nt);
+ nodes.put(id, node);
+ return true;
+ }
+
+ private boolean createNodes(JSONObject json) {
+ String type = json.getAsString("type");
+ System.out.println("Should create: " + type);
+
+ String[] nodes = getNodes(json);
+ if (nodes != null) {
+ for (int i = 0; i < nodes.length; i++) {
+ createNode(type, nodes[i]);
+ }
+ }
+ return true;
+ }
+
protected void processInput(Reader input) throws IOException, ParseException {
StringBuilder sb = new StringBuilder();
int brackets = 0;
@@ -115,6 +159,7 @@ protected boolean handleMessage(JSONObject json) {
}
} else if ("create".equals(event)) {
// TODO setup emulated node
+ createNodes(json);
sendToSimulator("{\"response\":\"create\",\"data\":1}");
} else if ("serial".equals(event)) {
int data = json.getAsInt("data", -1);
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/emulink/EmuLink.java | 45 +++++++++++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-11 16:37:15
|
The branch "master" has been updated
via 862780607857cf3b658c4815c50aaa5497ea43e2 (commit)
from 406a5e339bfe62298b95d4727295a26286acc2fb (commit)
Changed paths:
A lib/JSON-SIMPLE-LICENSE
A lib/json-simple-1.1.1.jar
M se/sics/mspsim/emulink/EmuLink.java
- Log -----------------------------------------------------------------
commit 862780607857cf3b658c4815c50aaa5497ea43e2
Author: Niclas Finne <nf...@si...>
Date: Thu Oct 11 18:36:28 2012 +0200
added JSON read for EmuLink
diff --git a/lib/JSON-SIMPLE-LICENSE b/lib/JSON-SIMPLE-LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/lib/JSON-SIMPLE-LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/lib/json-simple-1.1.1.jar b/lib/json-simple-1.1.1.jar
new file mode 100644
index 0000000..66347a6
Binary files /dev/null and b/lib/json-simple-1.1.1.jar differ
diff --git a/se/sics/mspsim/emulink/EmuLink.java b/se/sics/mspsim/emulink/EmuLink.java
index f6bda39..d125a5e 100755
--- a/se/sics/mspsim/emulink/EmuLink.java
+++ b/se/sics/mspsim/emulink/EmuLink.java
@@ -1,61 +1,210 @@
+/*
+ * Copyright (c) 2012, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of MSPSim.
+ *
+ * -----------------------------------------------------------------
+ *
+ * EmuLink
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 11 oct 2012
+ */
+
package se.sics.mspsim.emulink;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.io.Reader;
import java.net.ServerSocket;
import java.net.Socket;
+import se.sics.json.JSONArray;
+import se.sics.json.JSONObject;
+import se.sics.json.ParseException;
public class EmuLink {
-
- PrintWriter out;
- boolean close = false;
-
+ private Socket socket;
+ private BufferedReader in;
+ private PrintWriter out;
+ private boolean isConnected = false;
int mode;
int json = 0;
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
- void processInput(int data) {
- System.out.println("Data: " + data);
- /* create JSON here */
+ public boolean isConnected() {
+ return !isConnected;
+ }
+
+ protected void processInput(Reader input) throws IOException, ParseException {
+ StringBuilder sb = new StringBuilder();
+ int brackets = 0;
+ boolean stuffed = false;
+ boolean quoted = false;
+ while (isConnected()) {
+ int c = input.read();
+ if (c < 0) {
+ disconnect();
+ break;
+ }
+ sb.append((char)c);
+ if (stuffed) {
+ stuffed = false;
+ } else if (c == '\\') {
+ stuffed = true;
+ } else if (quoted) {
+ if (c == '"') {
+ quoted = false;
+ }
+ } else if (c == '"') {
+ quoted = true;
+ } else if (c == '{') {
+ brackets++;
+ } else if (c == '}') {
+ brackets--;
+ if (brackets == 0) {
+ JSONObject json = JSONObject.parseJSONObject(sb.toString());
+ sb.setLength(0);
+ if (!handleMessage(json)) {
+ // This connection should no longer be kept alive
+ break;
+ }
+ }
+ }
+ }
};
+ protected boolean handleMessage(JSONObject json) {
+ System.out.println("EmuLink: RECV " + json.toJSONString());
+ String event = json.getAsString("event");
+ if ("emulation_control".equals(event)) {
+ // TODO control emulation
+ sendToSimulator("{\"response\":\"emulation_control\",\"data\":1}");
+
+ if ("close".equals(json.getAsString("data"))) {
+ // Time to close the connection
+ return false;
+ }
+ } else if ("create".equals(event)) {
+ // TODO setup emulated node
+ sendToSimulator("{\"response\":\"create\",\"data\":1}");
+ } else if ("serial".equals(event)) {
+ int data = json.getAsInt("data", -1);
+ JSONArray nodes;
+ String node;
+ if (data < 0) {
+ // No data - ignore serial event
+ } else if ((nodes = json.getJSONArray("node")) != null) {
+ for(int i = 0, n = nodes.size(); i < n; i++) {
+ node = nodes.getAsString(i);
+ if (node != null) {
+ sendSerialToNode(node, data);
+ }
+ }
+ } else if ((node = json.getAsString("node")) != null) {
+ sendSerialToNode(node, data);
+ } else {
+ // No target node specified
+ }
+ } else {
+ System.err.println("EmuLink: ignoring unhandled event '" + event + "'");
+ }
+ return true;
+ }
+
+ protected void sendToSimulator(String message) {
+ if (out != null) {
+ out.write(message);
+ out.flush();
+ }
+ }
+
+ protected void sendSerialToNode(String node, int data) {
+ }
+
+ protected void disconnect() {
+ boolean wasConnected = isConnected;
+ isConnected = false;
+ try {
+ if (wasConnected) {
+ System.err.println("EmuLink: disconnecting...");
+ }
+ if (out != null) {
+ out.close();
+ out = null;
+ }
+ if (in != null) {
+ in.close();
+ in = null;
+ }
+ if (socket != null) {
+ socket.close();
+ socket = null;
+ }
+ if (wasConnected) {
+ System.err.println("EmuLink: disconnected");
+ }
+ } catch (IOException e) {
+ System.err.println("EmuLink: failed to close emulation link connection");
+ e.printStackTrace();
+ }
+ }
+
public void run() throws IOException {
try {
- ServerSocket serverSocket = null;
- serverSocket = new ServerSocket(8000);
+ ServerSocket serverSocket = new ServerSocket(8000);
while(true) {
System.out.println("EmuLink: Waiting for connection...");
- Socket socket = null;
try {
socket = serverSocket.accept();
- }
- catch (IOException e) {
+ } catch (IOException e) {
System.out.println("Accept failed: 8000");
System.exit(-1);
}
System.out.println("EmuLink: Connection accepted...");
+ try {
out = new PrintWriter(socket.getOutputStream(), true);
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- int c;
- out.println("EmuLink - mspsim");
- while (!close && (c = in.read()) != -1) {
- processInput(c);
- }
-
- in.close();
- out.close();
- socket.close();
- close = false;
+ in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ processInput(in);
+ } catch (Exception e) {
+ System.err.println("EmuLink: emulator link connection failed");
+ e.printStackTrace();
+ } finally {
+ disconnect();
}
}
- catch (IOException e) {
+ } catch (IOException e) {
System.out.println("Could not listen on port: 8000");
System.exit(-1);
}
-----------------------------------------------------------------------
Summary of changes:
lib/JSON-SIMPLE-LICENSE | 202 ++++++++++++++++++++++++++++++++++
lib/json-simple-1.1.1.jar | Bin 0 -> 23737 bytes
se/sics/mspsim/emulink/EmuLink.java | 207 ++++++++++++++++++++++++++++++-----
3 files changed, 380 insertions(+), 29 deletions(-)
create mode 100644 lib/JSON-SIMPLE-LICENSE
create mode 100644 lib/json-simple-1.1.1.jar
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-11 14:01:17
|
The branch "master" has been updated
via 406a5e339bfe62298b95d4727295a26286acc2fb (commit)
from 8954bd75a9f191c73eb28927dbff869e87ba124e (commit)
Changed paths:
M Makefile
A se/sics/json/JSONArray.java
C083 se/sics/mspsim/core/SimEventListener.java se/sics/json/JSONAware.java
A se/sics/json/JSONObject.java
C082 se/sics/mspsim/core/SimEventListener.java se/sics/json/JSONStreamAware.java
C074 se/sics/mspsim/core/SimEvent.java se/sics/json/ParseException.java
A se/sics/mspsim/emulink/EmuLink.java
- Log -----------------------------------------------------------------
commit 406a5e339bfe62298b95d4727295a26286acc2fb
Author: Joakim Eriksson <jo...@si...>
Date: Thu Oct 11 16:00:50 2012 +0200
added initial empty implementation of emulink
diff --git a/Makefile b/Makefile
index 1c9a044..8bbeb07 100644
--- a/Makefile
+++ b/Makefile
@@ -77,7 +77,7 @@ TIMERTEST := tests/timertest.firmware
SCRIPTS := ${addprefix scripts/,autorun.sc duty.sc}
BINARY := README.txt license.txt CHANGE_LOG.txt images/*.jpg images/*.png firmware/*/*.firmware ${SCRIPTS}
-PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli config debug platform ${addprefix platform/,esb sky jcreate sentillausb z1 tyndall ti wismote} plugin profiler net ui util extutil/highlight extutil/jfreechart}
+PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli config debug platform ${addprefix platform/,esb sky jcreate sentillausb z1 tyndall ti wismote} plugin profiler emulink net ui util extutil/highlight extutil/jfreechart}
SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))}
diff --git a/se/sics/json/JSONArray.java b/se/sics/json/JSONArray.java
new file mode 100755
index 0000000..05ca0ea
--- /dev/null
+++ b/se/sics/json/JSONArray.java
@@ -0,0 +1,284 @@
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: JSONArray.java 95 2011-04-19 13:29:41Z nfi $
+ *
+ * -----------------------------------------------------------------
+ *
+ * JSONArray
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 18 apr 2011
+ * Updated : $Date: 2011-04-19 15:29:41 +0200 (Tue, 19 Apr 2011) $
+ * $Revision: 95 $
+ */
+
+package se.sics.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ *
+ */
+public class JSONArray extends ArrayList<Object> implements JSONAware, JSONStreamAware {
+
+ private static final long serialVersionUID = 396701954050866614L;
+
+ private void checkForCycles(Object value) {
+ if (this == value) {
+ throw new IllegalArgumentException("cycle detected");
+ }
+ if (value instanceof JSONObject) {
+ JSONObject object = (JSONObject) value;
+ for (Object v : object.values()) {
+ checkForCycles(v);
+ }
+ } else if (value instanceof JSONArray) {
+ JSONArray list = (JSONArray) value;
+ for (Object v : list) {
+ checkForCycles(v);
+ }
+ }
+ }
+
+ private void checkAllForCycles(Collection<? extends Object> c) {
+ for(Object v : c) {
+ checkForCycles(v);
+ }
+ }
+
+ @Override
+ public boolean add(Object e) {
+ checkForCycles(e);
+ return super.add(e);
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return super.remove(o);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Object> c) {
+ checkAllForCycles(c);
+ return super.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends Object> c) {
+ checkAllForCycles(c);
+ return super.addAll(index, c);
+ }
+
+ @Override
+ public boolean removeAll(Collection<?> c) {
+ return super.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection<?> c) {
+ return super.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ }
+
+ @Override
+ public Object set(int index, Object element) {
+ checkForCycles(element);
+ return super.set(index, element);
+ }
+
+ @Override
+ public void add(int index, Object element) {
+ checkForCycles(element);
+ super.add(index, element);
+ }
+
+ @Override
+ public Object remove(int index) {
+ return super.remove(index);
+ }
+
+ public String getAsString(int index) {
+ Object v = get(index);
+ return v != null ? v.toString() : null;
+ }
+
+ public int getAsInt(int index, int defaultValue) {
+ Object v = get(index);
+ if (v instanceof Number) {
+ return ((Number)v).intValue();
+ }
+ return defaultValue;
+ }
+
+ public long getAsLong(int index, long defaultValue) {
+ Object v = get(index);
+ if (v instanceof Number) {
+ return ((Number)v).longValue();
+ }
+ return defaultValue;
+ }
+
+ public float getAsFloat(int index, float defaultValue) {
+ Object v = get(index);
+ if (v instanceof Number) {
+ return ((Number)v).floatValue();
+ }
+ return defaultValue;
+ }
+
+ public double getAsDouble(int index, double defaultValue) {
+ Object v = get(index);
+ if (v instanceof Number) {
+ return ((Number)v).doubleValue();
+ }
+ return defaultValue;
+ }
+
+ public boolean getAsBoolean(int index, boolean defaultValue) {
+ Object v = get(index);
+ if (v instanceof Boolean) {
+ return ((Boolean)v).booleanValue();
+ }
+ return defaultValue;
+ }
+
+ public JSONObject getJSONObject(int index) {
+ Object v = get(index);
+ if (v instanceof JSONObject) {
+ return (JSONObject)v;
+ }
+ return null;
+ }
+
+ public JSONArray getJSONArray(int index) {
+ Object v = get(index);
+ if (v instanceof JSONArray) {
+ return (JSONArray)v;
+ }
+ return null;
+ }
+
+ public void update(JSONArray v) {
+ int count = v.size();
+ if (size() < count) {
+ count = size();
+ }
+ for(int i = 0; i < count; i++) {
+ Object target = get(i);
+ Object source = v.get(i);
+ if (source instanceof JSONObject) {
+ if (target instanceof JSONObject) {
+ ((JSONObject) target).update((JSONObject) source);
+ }
+ } else if (source instanceof JSONArray) {
+ if (target instanceof JSONArray) {
+ ((JSONArray) target).update((JSONArray) source);
+ }
+ } else if (target instanceof JSONObject || target instanceof JSONArray) {
+ // Compound values can not be replaced by primitive values
+ } else {
+ set(i, source);
+ }
+ }
+ }
+
+ public void merge(JSONArray v) {
+ int count = v.size();
+ if (size() < count) {
+ count = size();
+ }
+ for(int i = 0; i < count; i++) {
+ Object target = get(i);
+ Object source = v.get(i);
+ if (source instanceof JSONObject) {
+ if (target instanceof JSONObject) {
+ ((JSONObject) target).merge((JSONObject) source);
+ }
+ } else if (source instanceof JSONArray) {
+ if (target instanceof JSONArray) {
+ ((JSONArray) target).merge((JSONArray) source);
+ }
+ } else if (target instanceof JSONObject || target instanceof JSONArray) {
+ // Compound values can not be replaced by primitive values
+ } else {
+ set(i, source);
+ }
+ }
+ if (v.size() > size()) {
+ for(int i = size(), n = v.size(); i < n; i++) {
+ Object source = v.get(i);
+ if (source instanceof JSONObject) {
+ add(((JSONObject) source).clone());
+ } else if (source instanceof JSONArray) {
+ add(((JSONArray) source).clone());
+ } else {
+ add(source);
+ }
+ }
+ }
+ }
+
+ @Override
+ public JSONArray clone() {
+ JSONArray clone = (JSONArray) super.clone();
+ // Create deep copy
+ for(int i = 0, n = clone.size(); i < n; i++) {
+ Object value = clone.get(i);
+ if (value instanceof JSONObject) {
+ clone.set(i, ((JSONObject)value).clone());
+ } else if (value instanceof JSONArray) {
+ clone.set(i, ((JSONArray)value).clone());
+ }
+ }
+ return clone;
+ }
+
+ @Override
+ public String toString() {
+ return toJSONString();
+ }
+
+ @Override
+ public String toJSONString() {
+ return org.json.simple.JSONArray.toJSONString(this);
+ }
+
+ @Override
+ public void writeJSONString(Writer out) throws IOException {
+ org.json.simple.JSONArray.writeJSONString(this, out);
+ }
+
+}
diff --git a/se/sics/json/JSONAware.java b/se/sics/json/JSONAware.java
new file mode 100755
index 0000000..79807e3
--- /dev/null
+++ b/se/sics/json/JSONAware.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: JSONAware.java 95 2011-04-19 13:29:41Z nfi $
+ *
+ * -----------------------------------------------------------------
+ *
+ * JSONAware
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 18 apr 2011
+ * Updated : $Date: 2011-04-19 15:29:41 +0200 (Tue, 19 Apr 2011) $
+ * $Revision: 95 $
+ */
+
+package se.sics.json;
+
+/**
+ *
+ */
+public interface JSONAware extends org.json.simple.JSONAware {
+
+}
diff --git a/se/sics/json/JSONObject.java b/se/sics/json/JSONObject.java
new file mode 100755
index 0000000..3eaccdc
--- /dev/null
+++ b/se/sics/json/JSONObject.java
@@ -0,0 +1,410 @@
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: JSONObject.java 95 2011-04-19 13:29:41Z nfi $
+ *
+ * -----------------------------------------------------------------
+ *
+ * JSONObject
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 18 apr 2011
+ * Updated : $Date: 2011-04-19 15:29:41 +0200 (Tue, 19 Apr 2011) $
+ * $Revision: 95 $
+ */
+
+package se.sics.json;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Stack;
+
+import org.json.simple.parser.ContainerFactory;
+import org.json.simple.parser.ContentHandler;
+import org.json.simple.parser.JSONParser;
+
+/**
+ *
+ */
+public class JSONObject extends HashMap<String,Object> implements JSONAware, JSONStreamAware {
+
+ private static final long serialVersionUID = -4565653621517131043L;
+
+ private void checkForCycles(Object value) {
+ if (this == value) {
+ throw new IllegalArgumentException("cycle detected");
+ }
+ if (value instanceof JSONObject) {
+ JSONObject object = (JSONObject) value;
+ for (Object v : object.values()) {
+ checkForCycles(v);
+ }
+ } else if (value instanceof JSONArray) {
+ JSONArray list = (JSONArray) value;
+ for (Object v : list) {
+ checkForCycles(v);
+ }
+ }
+ }
+
+ @Override
+ public Object put(String key, Object value) {
+ checkForCycles(value);
+ return super.put(key, value);
+ }
+
+ @Override
+ public void putAll(Map<? extends String,? extends Object> map) {
+ for (Object v : map.values()) {
+ checkForCycles(v);
+ }
+ super.putAll(map);
+ }
+
+ @Override
+ public Object remove(Object key) {
+ return super.remove(key);
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+ }
+
+ public boolean has(String key) {
+ return containsKey(key);
+ }
+
+ public JSONObject set(String key, Object value) {
+ put(key, value);
+ return this;
+ }
+
+ public String[] getKeys() {
+ return keySet().toArray(new String[0]);
+ }
+
+ public String getAsString(String key) {
+ return getAsString(key, null);
+ }
+
+ public String getAsString(String key, String defaultValue) {
+ Object v = get(key);
+ return v != null ? v.toString() : defaultValue;
+ }
+
+ public int getAsInt(String key, int defaultValue) {
+ Object v = get(key);
+ if (v instanceof Number) {
+ return ((Number) v).intValue();
+ }
+ return defaultValue;
+ }
+
+ public long getAsLong(String key, long defaultValue) {
+ Object v = get(key);
+ if (v instanceof Number) {
+ return ((Number) v).longValue();
+ }
+ return defaultValue;
+ }
+
+ public float getAsFloat(String key, float defaultValue) {
+ Object v = get(key);
+ if (v instanceof Number) {
+ return ((Number) v).floatValue();
+ }
+ return defaultValue;
+ }
+
+ public double getAsDouble(String key, double defaultValue) {
+ Object v = get(key);
+ if (v instanceof Number) {
+ return ((Number) v).doubleValue();
+ }
+ return defaultValue;
+ }
+
+ public boolean getAsBoolean(String key, boolean defaultValue) {
+ Object v = get(key);
+ if (v instanceof Boolean) {
+ return ((Boolean) v).booleanValue();
+ }
+ return defaultValue;
+ }
+
+ public JSONObject getJSONObject(String key) {
+ Object v = get(key);
+ if (v instanceof JSONObject) {
+ return (JSONObject) v;
+ }
+ return null;
+ }
+
+ public JSONArray getJSONArray(String key) {
+ Object v = get(key);
+ if (v instanceof JSONArray) {
+ return (JSONArray) v;
+ }
+ return null;
+ }
+
+ public void update(JSONObject source) {
+ for(Map.Entry<String,Object> entry : source.entrySet()) {
+ if (containsKey(entry.getKey())) {
+ Object target = get(entry.getKey());
+ Object v = entry.getValue();
+ if (v instanceof JSONObject) {
+ if (target instanceof JSONObject) {
+ ((JSONObject) target).update((JSONObject) v);
+ }
+ } else if (v instanceof JSONArray) {
+ if (target instanceof JSONArray) {
+ ((JSONArray) target).update((JSONArray) v);
+ }
+ } else if (target instanceof JSONObject || target instanceof JSONArray) {
+ // Compound values can not be replaced by primitive values
+ } else {
+ put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
+
+ public void merge(JSONObject source) {
+ for(Map.Entry<String,Object> entry : source.entrySet()) {
+ Object target = get(entry.getKey());
+ Object v = entry.getValue();
+ if (target != null) {
+ if (v instanceof JSONObject) {
+ if (target instanceof JSONObject) {
+ ((JSONObject) target).merge((JSONObject) v);
+ }
+ } else if (v instanceof JSONArray) {
+ if (target instanceof JSONArray) {
+ ((JSONArray) target).merge((JSONArray) v);
+ }
+ } else if (target instanceof JSONObject || target instanceof JSONArray) {
+ // Compound values can not be replaced by primitive values
+ } else {
+ put(entry.getKey(), entry.getValue());
+ }
+ } else {
+ /* New value */
+ if (v instanceof JSONObject) {
+ v = ((JSONObject) v).clone();
+ } else if (v instanceof JSONArray) {
+ v = ((JSONArray) v).clone();
+ }
+ put(entry.getKey(), v);
+ }
+ }
+ }
+
+ @Override
+ public JSONObject clone() {
+ JSONObject clone = (JSONObject) super.clone();
+ // Create deep copy
+ for (String key : clone.getKeys()) {
+ Object value = clone.get(key);
+ if (value instanceof JSONObject) {
+ clone.put(key, ((JSONObject) value).clone());
+ } else if (value instanceof JSONArray) {
+ clone.put(key, ((JSONArray) value).clone());
+ }
+ }
+ return clone;
+ }
+
+ @Override
+ public String toString() {
+ return toJSONString();
+ }
+
+ @Override
+ public String toJSONString() {
+ return org.json.simple.JSONObject.toJSONString(this);
+ }
+
+ @Override
+ public void writeJSONString(Writer out) throws IOException {
+ org.json.simple.JSONObject.writeJSONString(this, out);
+ }
+
+ public static Object parseJSON(String input) throws ParseException {
+ try {
+ JSONParser parser = new JSONParser();
+ return parser.parse(input, jsonObjectFactory);
+ } catch (org.json.simple.parser.ParseException e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
+
+ public static Object parseJSON(Reader input) throws IOException, ParseException {
+ try {
+ JSONParser parser = new JSONParser();
+ JSONObjectHandler doh = new JSONObjectHandler();
+ parser.parse(input, doh);
+ return doh.getResult();
+ } catch (org.json.simple.parser.ParseException e) {
+ throw new ParseException(e.getMessage(), e);
+ }
+ }
+
+ public static JSONObject parseJSONObject(String input) throws ParseException {
+ Object value = parseJSON(input);
+ if (value instanceof JSONObject) {
+ return (JSONObject) value;
+ }
+ throw new ParseException("not a JSON object: " + input);
+ }
+
+ public static JSONObject parseJSONObject(Reader input) throws ParseException, IOException {
+ Object value = parseJSON(input);
+ if (value instanceof JSONObject) {
+ return (JSONObject) value;
+ }
+ throw new ParseException("not a JSON object: " + input);
+ }
+
+ private static ContainerFactory jsonObjectFactory = new ContainerFactory() {
+
+ @Override
+ public List<Object> creatArrayContainer() {
+ return new JSONArray();
+ }
+
+ @Override
+ public Map<String,Object> createObjectContainer() {
+ return new JSONObject();
+ }
+
+ };
+
+ private static class JSONObjectHandler implements ContentHandler {
+
+ private Stack<Object> valueStack = new Stack<Object>();
+
+ public Object getResult() {
+ if (this.valueStack.size() == 0) {
+ return null;
+ }
+ return this.valueStack.peek();
+ }
+
+ @Override
+ public boolean endArray() throws IOException {
+ trackBack();
+ return true;
+ }
+
+ @Override
+ public void endJSON() throws IOException {
+ }
+
+ @Override
+ public boolean endObject() throws IOException {
+ trackBack();
+ // System.out.println("End JSON Object: " + getResult() + " Stack: "
+ // + valueStack.size());
+ /* we are finished if value stack is 1 */
+ return this.valueStack.size() > 1;
+ }
+
+ @Override
+ public boolean endObjectEntry() throws IOException {
+ Object value = this.valueStack.pop();
+ Object key = this.valueStack.pop();
+ JSONObject parent = (JSONObject) this.valueStack.peek();
+ parent.put((String) key, value);
+ return true;
+ }
+
+ private void trackBack() {
+ if (this.valueStack.size() > 1) {
+ Object value = this.valueStack.pop();
+ Object prev = this.valueStack.peek();
+ if (prev instanceof String) {
+ this.valueStack.push(value);
+ }
+ }
+ }
+
+ private void consumeValue(Object value) {
+ if (this.valueStack.size() == 0) {
+ this.valueStack.push(value);
+ } else {
+ Object prev = this.valueStack.peek();
+ if (prev instanceof JSONArray) {
+ JSONArray array = (JSONArray) prev;
+ array.add(value);
+ } else {
+ this.valueStack.push(value);
+ }
+ }
+ }
+
+ @Override
+ public boolean primitive(Object value) throws IOException {
+ consumeValue(value);
+ return true;
+ }
+
+ @Override
+ public boolean startArray() throws IOException {
+ JSONArray array = new JSONArray();
+ consumeValue(array);
+ this.valueStack.push(array);
+ return true;
+ }
+
+ @Override
+ public void startJSON() throws IOException {
+ this.valueStack.clear();
+ }
+
+ @Override
+ public boolean startObject() throws IOException {
+ JSONObject object = new JSONObject();
+ consumeValue(object);
+ this.valueStack.push(object);
+ return true;
+ }
+
+ @Override
+ public boolean startObjectEntry(String key) throws IOException {
+ this.valueStack.push(key);
+ return true;
+ }
+ }
+
+}
diff --git a/se/sics/json/JSONStreamAware.java b/se/sics/json/JSONStreamAware.java
new file mode 100755
index 0000000..0b5ac31
--- /dev/null
+++ b/se/sics/json/JSONStreamAware.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: JSONStreamAware.java 95 2011-04-19 13:29:41Z nfi $
+ *
+ * -----------------------------------------------------------------
+ *
+ * JSONStreamAware
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 18 apr 2011
+ * Updated : $Date: 2011-04-19 15:29:41 +0200 (Tue, 19 Apr 2011) $
+ * $Revision: 95 $
+ */
+
+package se.sics.json;
+
+/**
+ *
+ */
+public interface JSONStreamAware extends org.json.simple.JSONStreamAware {
+
+}
diff --git a/se/sics/json/ParseException.java b/se/sics/json/ParseException.java
new file mode 100755
index 0000000..c4b096a
--- /dev/null
+++ b/se/sics/json/ParseException.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id: ParseException.java 95 2011-04-19 13:29:41Z nfi $
+ *
+ * -----------------------------------------------------------------
+ *
+ * ParseException
+ *
+ * Authors : Joakim Eriksson, Niclas Finne
+ * Created : 18 apr 2011
+ * Updated : $Date: 2011-04-19 15:29:41 +0200 (Tue, 19 Apr 2011) $
+ * $Revision: 95 $
+ */
+
+package se.sics.json;
+
+/**
+ *
+ */
+public class ParseException extends Exception {
+
+ private static final long serialVersionUID = -7187769778260624049L;
+
+ public ParseException(String message) {
+ super(message);
+ }
+
+ public ParseException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/se/sics/mspsim/emulink/EmuLink.java b/se/sics/mspsim/emulink/EmuLink.java
new file mode 100755
index 0000000..f6bda39
--- /dev/null
+++ b/se/sics/mspsim/emulink/EmuLink.java
@@ -0,0 +1,68 @@
+package se.sics.mspsim.emulink;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class EmuLink {
+
+
+ PrintWriter out;
+ boolean close = false;
+
+
+ int mode;
+ int json = 0;
+ StringBuffer buffer = new StringBuffer();
+
+ void processInput(int data) {
+ System.out.println("Data: " + data);
+ /* create JSON here */
+ };
+
+ public void run() throws IOException {
+ try {
+ ServerSocket serverSocket = null;
+ serverSocket = new ServerSocket(8000);
+
+ while(true) {
+
+ System.out.println("EmuLink: Waiting for connection...");
+ Socket socket = null;
+ try {
+ socket = serverSocket.accept();
+ }
+ catch (IOException e) {
+ System.out.println("Accept failed: 8000");
+ System.exit(-1);
+ }
+ System.out.println("EmuLink: Connection accepted...");
+
+ out = new PrintWriter(socket.getOutputStream(), true);
+ BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ int c;
+ out.println("EmuLink - mspsim");
+ while (!close && (c = in.read()) != -1) {
+ processInput(c);
+ }
+
+ in.close();
+ out.close();
+ socket.close();
+ close = false;
+ }
+ }
+ catch (IOException e) {
+ System.out.println("Could not listen on port: 8000");
+ System.exit(-1);
+ }
+ }
+
+ public static void main(String[] args) throws IOException {
+ EmuLink el = new EmuLink();
+ el.run();
+ }
+}
-----------------------------------------------------------------------
Summary of changes:
Makefile | 2 +-
se/sics/json/JSONArray.java | 284 ++++++++++++++
.../SimEventListener.java => json/JSONAware.java} | 20 +-
se/sics/json/JSONObject.java | 410 ++++++++++++++++++++
.../JSONStreamAware.java} | 20 +-
.../SimEvent.java => json/ParseException.java} | 37 +-
se/sics/mspsim/emulink/EmuLink.java | 68 ++++
7 files changed, 794 insertions(+), 47 deletions(-)
create mode 100755 se/sics/json/JSONArray.java
copy se/sics/{mspsim/core/SimEventListener.java => json/JSONAware.java} (83%)
mode change 100644 => 100755
create mode 100755 se/sics/json/JSONObject.java
copy se/sics/{mspsim/core/SimEventListener.java => json/JSONStreamAware.java} (82%)
mode change 100644 => 100755
copy se/sics/{mspsim/core/SimEvent.java => json/ParseException.java} (74%)
mode change 100644 => 100755
create mode 100755 se/sics/mspsim/emulink/EmuLink.java
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-11 08:41:37
|
The branch "master" has been updated
via 8954bd75a9f191c73eb28927dbff869e87ba124e (commit)
from 2e46eed2ee244ee190cf766f9f1ab19d9d491304 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit 8954bd75a9f191c73eb28927dbff869e87ba124e
Author: Joakim Eriksson <jo...@si...>
Date: Thu Oct 11 10:41:18 2012 +0200
fixed CALLA INDX
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index ce38185..b343028 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1361,9 +1361,17 @@ public int emulateOP(long maxCycles) throws EmulationException {
dst = readRegister(dstRegister);
/* what happens if wrapping here??? */
- System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " Mem: " +
- currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
- dst += currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ /* read the index which is from -15 bit - +15 bit. - so extend sign to 20-bit */
+ int v = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
+ if ((v & 0x8000) != 0) {
+ v |= 0xf0000;
+ }
+
+ System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " INDX: " + v);
+
+ dst += v;
+ dst &= 0xfffff;
+
System.out.println("CALLA INDX => " + Utils.hex20(dst));
dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
System.out.println("CALLA Read from INDX => " + Utils.hex20(dst));
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 14 +++++++++++---
1 files changed, 11 insertions(+), 3 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-10 20:54:40
|
The branch "master" has been updated
via 2e46eed2ee244ee190cf766f9f1ab19d9d491304 (commit)
from 029c96c53b2a86e5748fd7244fbf99a8a4768cc8 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit 2e46eed2ee244ee190cf766f9f1ab19d9d491304
Author: Joakim Eriksson <jo...@si...>
Date: Wed Oct 10 22:54:17 2012 +0200
added CALLA_IND
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index c1144bb..ce38185 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1379,6 +1379,16 @@ public int emulateOP(long maxCycles) throws EmulationException {
pc += 2;
cycles += 5;
break;
+ case CALLA_IND:
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
+
+ dstAddress = readRegister(dstRegister);
+
+ dst = currentSegment.read(dstAddress, AccessMode.WORD20, AccessType.READ);
+ pc += 2;
+ cycles += 5;
+ break;
case CALLA_ABS:
sp = readRegister(SP) - 2;
writeRegister(SP, sp);
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-10 19:22:30
|
The branch "master" has been updated
via 029c96c53b2a86e5748fd7244fbf99a8a4768cc8 (commit)
from 836e9abeba504fd20dde377d031903d60e7a39f7 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit 029c96c53b2a86e5748fd7244fbf99a8a4768cc8
Author: Niclas Finne <nf...@si...>
Date: Wed Oct 10 21:21:46 2012 +0200
Fixed immediate address mode for 20 bit instructions
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index 868764d..c1144bb 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1025,7 +1025,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
int dstRegister = 0;
int dstAddress = -1;
boolean dstRegMode = false;
- int dst = 0;
+ int dst = -1;
boolean write = false;
boolean updateStatus = true;
@@ -1515,7 +1515,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
// Bugfix suggested by Matt Thompson
case AM_IND_AUTOINC:
if (dstRegister == PC) {
- dstAddress = readRegister(PC);
+ dstAddress = pc;
+ dst = currentSegment.read(dstAddress, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ dst += extDst;
pc += 2;
writeRegister(PC, pc);
} else {
@@ -1531,14 +1533,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (dstRegMode) {
dst = readRegisterCG(dstRegister, ad);
-//XXX if (word) {
-// dst &= 0xffff;
-// } else if (wordx20) {
-// dst &= 0xfffff;
-// } else {
-// dst &= 0xff;
-// }
-
dst &= mode.mask;
/* set the repeat here! */
@@ -1552,8 +1546,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
// if (repeats > 1) {
// System.out.println("*** Repeat " + repeats + " ZeroCarry: " + zeroCarry);
// }
- } else {
- dst = currentSegment.read(dstAddress, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ } else if (dst == -1) {
+ dst = currentSegment.read(dstAddress, mode, AccessType.READ);
}
/* TODO: test add the loop here! */
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 18 ++++++------------
1 files changed, 6 insertions(+), 12 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-10 12:58:17
|
The branch "master" has been updated
via 836e9abeba504fd20dde377d031903d60e7a39f7 (commit)
from ffa35e5619d42a38861ca8cbaf956396c65041ad (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit 836e9abeba504fd20dde377d031903d60e7a39f7
Author: Niclas Finne <nf...@si...>
Date: Wed Oct 10 14:57:59 2012 +0200
Fixed handling of bit 16-19 for format 2 indexed instructions
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index d8be889..868764d 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -973,6 +973,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
}
int ext3_0 = 0;
int ext10_7 = 0;
+ int extSrc = 0;
+ int extDst = 0;
boolean repeatsInDstReg = false;
boolean wordx20 = false;
@@ -981,6 +983,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
extWord = instruction;
ext3_0 = instruction & 0xf; /* bit 3 - 0 - either repeat count or dest 19-16 */
ext10_7 = (instruction >> 7) & 0xf; /* bit 10 - 7 - src 19-16 */
+ extSrc = ext10_7 << 16;
+ extDst = ext3_0 << 16;
pc += 2;
// Bit 7 in the extension word indicates that the number of
// repeats is found in the register pointed to by ext3_0. If
@@ -1483,7 +1487,11 @@ public int emulateOP(long maxCycles) throws EmulationException {
/* Support for MSP430X and below / above 64 KB */
/* if register is pointing to <64KB then it needs to be truncated to below 64 */
- if (rval <= 0xffff) {
+ if (extWord != 0) {
+ dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + extDst;
+ dstAddress += rval;
+ dstAddress &= 0xfffff;
+ } else if (rval <= 0xffff) {
dstAddress = (rval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff;
} else {
dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
@@ -1793,7 +1801,11 @@ public int emulateOP(long maxCycles) throws EmulationException {
/* Support for MSP430X and below / above 64 KB */
/* if register is pointing to <64KB then it needs to be truncated to below 64 */
- if (sval <= 0xffff) {
+ if (extWord != 0) {
+ srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + extSrc;
+ srcAddress += sval;
+ srcAddress &= 0xfffff;
+ } else if (sval <= 0xffff) {
srcAddress = (sval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff;
} else {
srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-10 10:08:34
|
The branch "master" has been updated
via ffa35e5619d42a38861ca8cbaf956396c65041ad (commit)
from e2aa07a8acdd76d88e7e6d914784e0f707615a5f (commit)
Changed paths:
M se/sics/mspsim/core/DisAsm.java
- Log -----------------------------------------------------------------
commit ffa35e5619d42a38861ca8cbaf956396c65041ad
Author: Joakim Eriksson <jo...@si...>
Date: Wed Oct 10 12:08:02 2012 +0200
fixe disassembly of PUSH/POPM instr
diff --git a/se/sics/mspsim/core/DisAsm.java b/se/sics/mspsim/core/DisAsm.java
index dda6689..b05e649 100644
--- a/se/sics/mspsim/core/DisAsm.java
+++ b/se/sics/mspsim/core/DisAsm.java
@@ -249,16 +249,16 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg,
default:
switch (instruction & 0xff00) {
case PUSHM_A:
- opstr = "PUSHM.A #" + ((instruction >> 4) & 0x0f) + ", R" + (instruction & 0x0f);
+ opstr = "PUSHM.A #" + (1 + ((instruction >> 4) & 0x0f)) + ", R" + (instruction & 0x0f);
break;
case PUSHM_W:
- opstr = "PUSHM.W #" + ((instruction >> 4) & 0x0f) + ", R" + (instruction & 0x0f);
+ opstr = "PUSHM.W #" + (1 + ((instruction >> 4) & 0x0f)) + ", R" + (instruction & 0x0f);
break;
case POPM_A:
- opstr = "POPM.A #" + ((instruction >> 4) & 0x0f) + ", R" + (instruction & 0x0f);
+ opstr = "POPM.A #" + (1 + ((instruction >> 4) & 0x0f)) + ", R" + (instruction & 0x0f);
break;
case POPM_W:
- opstr = "POPM.W #" + ((instruction >> 4) & 0x0f) + ", R" + (instruction & 0x0f);
+ opstr = "POPM.W #" + (1 + ((instruction >> 4) & 0x0f)) + ", R" + (instruction & 0x0f);
break;
}
}
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/DisAsm.java | 8 ++++----
1 files changed, 4 insertions(+), 4 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-09 14:41:10
|
The branch "master" has been updated
via e2aa07a8acdd76d88e7e6d914784e0f707615a5f (commit)
from c65a363ac20ce4211e86e85a6da7c5da83acc649 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit e2aa07a8acdd76d88e7e6d914784e0f707615a5f
Author: Niclas Finne <nf...@si...>
Date: Tue Oct 9 16:40:57 2012 +0200
Another fix for PUSH, update for CG registers for 20 bit operations
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index b0a1c47..d8be889 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1143,7 +1143,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
int immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16);
writeRegister(PC, pc += 2);
dst = readRegister(dstData) + immData;
- System.out.println("ADDA #" + Utils.hex20(immData) + " => " + Utils.hex20(dst));
+// System.out.println("ADDA #" + Utils.hex20(immData) + " => " + Utils.hex20(dst));
dst &= 0xfffff;
writeRegister(dstData, dst);
@@ -1197,14 +1197,15 @@ public int emulateOP(long maxCycles) throws EmulationException {
case MOVA_REG:
cycles += 1;
- writeRegister(dstData, readRegister(srcData));
+ /* as = 0 since register mode */
+ writeRegister(dstData, readRegisterCG(srcData, 0));
break;
case CMPA_REG: {
sr = readRegister(SR);
sr &= ~(NEGATIVE | ZERO | CARRY | OVERFLOW);
int destRegValue = readRegister(dstData);
- int srcRegValue = readRegister(srcData);
+ int srcRegValue = readRegisterCG(srcData, 0);
if (destRegValue >= srcRegValue) {
sr |= CARRY;
}
@@ -1230,12 +1231,14 @@ public int emulateOP(long maxCycles) throws EmulationException {
}
case ADDA_REG:
- dst = readRegister(dstData) + readRegister(srcData);
+ // Assume AS = 2
+ dst = readRegister(dstData) + readRegisterCG(srcData, 2);
writeRegister(dstData, dst);
cycles += 1;
break;
case SUBA_REG:
- dst = readRegister(dstData) - readRegister(srcData);
+ // Assume AS = 2
+ dst = readRegister(dstData) - readRegisterCG(srcData, 2);
writeRegister(dstData, dst);
cycles += 1;
break;
@@ -1542,7 +1545,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
// System.out.println("*** Repeat " + repeats + " ZeroCarry: " + zeroCarry);
// }
} else {
- dst = currentSegment.read(dstAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
+ dst = currentSegment.read(dstAddress, mode != AccessMode.BYTE ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ);
}
/* TODO: test add the loop here! */
@@ -1603,17 +1606,12 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SR, sr);
break;
case PUSH:
- if (mode == AccessMode.WORD) {
- // Put lo & hi on stack!
- // memory[sp] = dst & 0xff;
- // memory[sp + 1] = dst >> 8;
- currentSegment.write(sp, dst, AccessMode.WORD);
- } else {
- // Byte => only lo byte
- // memory[sp] = dst & 0xff;
- // memory[sp + 1] = 0;
- currentSegment.write(sp, dst & 0xff, AccessMode.WORD);
+ if (mode == AccessMode.WORD20) {
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
}
+ currentSegment.write(sp, dst, mode);
+
/* if REG or INDIRECT AUTOINC then add 2 cycles, otherwise 1 */
cycles += (ad == AM_REG || ad == AM_IND_AUTOINC) ? 2 : 1;
write = false;
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 30 ++++++++++++++----------------
1 files changed, 14 insertions(+), 16 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Niclas F. <ni...@us...> - 2012-10-09 11:42:08
|
The branch "master" has been updated
via c65a363ac20ce4211e86e85a6da7c5da83acc649 (commit)
via 81b77226be4cbc63b029015fc8ed8b3c75591f0e (commit)
from 7d4d97c5d30d649109fc3cdac7611073122cba6d (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
M se/sics/mspsim/core/Memory.java
- Log -----------------------------------------------------------------
commit c65a363ac20ce4211e86e85a6da7c5da83acc649
Author: Niclas Finne <nf...@si...>
Date: Tue Oct 9 13:28:06 2012 +0200
Fixed PUSH. Show full address in memory error output.
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index 99845a6..b0a1c47 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -149,28 +149,28 @@ public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) {
@Override
public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
if (address >= MAX_MEM) {
- throw new EmulationException("Reading outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address));
+ throw new EmulationException("Reading outside memory: 0x" + Utils.hex(address, 4));
}
return memorySegments[address >> 8].read(address, mode, type);
}
@Override
- public void write(int dstAddress, int data, AccessMode mode) throws EmulationException {
- if (dstAddress >= MAX_MEM) {
- throw new EmulationException("Writing outside memory: 0x" + MSP430Core.this.config.getAddressAsString(dstAddress));
+ public void write(int address, int data, AccessMode mode) throws EmulationException {
+ if (address >= MAX_MEM) {
+ throw new EmulationException("Writing outside memory: 0x" + Utils.hex(address, 4));
}
- memorySegments[dstAddress >> 8].write(dstAddress, data, mode);
+ memorySegments[address >> 8].write(address, data, mode);
}
@Override
public int get(int address, AccessMode mode) {
if (address >= MAX_MEM) {
- throw new EmulationException("Reading outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address));
+ throw new EmulationException("Reading outside memory: 0x" + Utils.hex(address, 4));
}
return memorySegments[address >> 8].get(address, mode);
}
@Override
public void set(int address, int data, AccessMode mode) {
if (address >= MAX_MEM) {
- throw new EmulationException("Writing outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address));
+ throw new EmulationException("Writing outside memory: 0x" + Utils.hex(address, 4));
}
memorySegments[address >> 8].set(address, data, mode);
}
@@ -1603,7 +1603,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(SR, sr);
break;
case PUSH:
- if (word) {
+ if (mode == AccessMode.WORD) {
// Put lo & hi on stack!
// memory[sp] = dst & 0xff;
// memory[sp + 1] = dst >> 8;
commit 81b77226be4cbc63b029015fc8ed8b3c75591f0e
Author: Niclas Finne <nf...@si...>
Date: Tue Oct 9 13:23:34 2012 +0200
Fixed byte size of 20 bit address word
diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/Memory.java
index 37ed95d..5ae7906 100644
--- a/se/sics/mspsim/core/Memory.java
+++ b/se/sics/mspsim/core/Memory.java
@@ -50,7 +50,7 @@
public enum AccessMode {
BYTE(1, 8, 0xff),
WORD(2, 16, 0xffff),
- WORD20(3, 20, 0xfffff);
+ WORD20(4, 20, 0xfffff);
public final int bytes;
public final int bitSize;
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 16 ++++++++--------
se/sics/mspsim/core/Memory.java | 2 +-
2 files changed, 9 insertions(+), 9 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-08 19:08:17
|
The branch "master" has been updated
via 7d4d97c5d30d649109fc3cdac7611073122cba6d (commit)
from c00d795d5cc36f596a3a4d0aa371d844dd0f8212 (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit 7d4d97c5d30d649109fc3cdac7611073122cba6d
Author: Joakim Eriksson <jo...@si...>
Date: Mon Oct 8 21:07:39 2012 +0200
some fixes to CALLA - update SP early
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index 932d1d3..99845a6 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1043,6 +1043,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
int srcData = (instruction & 0x0f00) >> 8;
int dstData = (instruction & 0x000f);
boolean rrword = true;
+ mode = AccessMode.WORD20;
switch(op) {
// 20 bit register write
@@ -1127,6 +1128,7 @@ public int emulateOP(long maxCycles) throws EmulationException {
writeRegister(PC, pc += 2);
dst = src + (srcData << 16);
// System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData);
+ dst &= 0xfffff;
writeRegister(dstData, dst);
updateStatus = false;
cycles += 2;
@@ -1141,6 +1143,9 @@ public int emulateOP(long maxCycles) throws EmulationException {
int immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16);
writeRegister(PC, pc += 2);
dst = readRegister(dstData) + immData;
+ System.out.println("ADDA #" + Utils.hex20(immData) + " => " + Utils.hex20(dst));
+
+ dst &= 0xfffff;
writeRegister(dstData, dst);
cycles += 3;
break;
@@ -1246,8 +1251,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
if (rrword) {
mode = AccessMode.WORD;
dst = dst & 0xffff;
- } else {
- mode = AccessMode.WORD20; /* address */
}
cycles += 1 + count;
switch(instruction & RRMASK) {
@@ -1332,14 +1335,24 @@ public int emulateOP(long maxCycles) throws EmulationException {
updateStatus = false;
switch(op) {
case CALLA_REG:
+ // The CALLA operations increase the SP before
+ // address resolution!
+ // store on stack - always move 2 steps before resolution
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
+
dst = readRegister(dstRegister);
System.out.println("CALLA REG => " + Utils.hex20(dst));
cycles += 5;
break;
case CALLA_INDEX:
/* CALLA X(REG) => REG + X is the address*/
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
+
System.out.println("CALLA INDX: R" + dstRegister);
dst = readRegister(dstRegister);
+
/* what happens if wrapping here??? */
System.out.println("CALLA INDX: Reg = " + Utils.hex20(dst) + " Mem: " +
currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
@@ -1352,11 +1365,17 @@ public int emulateOP(long maxCycles) throws EmulationException {
// System.exit(0);
break;
case CALLA_IMM:
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
+
dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
pc += 2;
cycles += 5;
break;
case CALLA_ABS:
+ sp = readRegister(SP) - 2;
+ writeRegister(SP, sp);
+
/* read the address of where the address to call is */
dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
@@ -1422,7 +1441,6 @@ public int emulateOP(long maxCycles) throws EmulationException {
// store current PC on stack. (current PC points to next instr.)
/* store 20 bits on stack (costs two words) */
if (dst != -1) {
- sp = readRegister(SP) - 2;
currentSegment.write(sp, (pc >> 16) & 0xf, AccessMode.WORD);
sp = sp - 2;
currentSegment.write(sp, pc & 0xffff, AccessMode.WORD);
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 26 ++++++++++++++++++++++----
1 files changed, 22 insertions(+), 4 deletions(-)
hooks/post-receive
--
mspsim
|
|
From: Joakim E. <jo...@us...> - 2012-10-06 13:35:14
|
The branch "master" has been updated
via c00d795d5cc36f596a3a4d0aa371d844dd0f8212 (commit)
from 47321ce6164a56d2ca478d0719dec4f3ee1437ec (commit)
Changed paths:
M se/sics/mspsim/core/MSP430Core.java
- Log -----------------------------------------------------------------
commit c00d795d5cc36f596a3a4d0aa371d844dd0f8212
Author: Joakim Eriksson <jo...@si...>
Date: Sat Oct 6 15:32:39 2012 +0200
fixed CALLA INDX
diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java
index c09d87e..932d1d3 100644
--- a/se/sics/mspsim/core/MSP430Core.java
+++ b/se/sics/mspsim/core/MSP430Core.java
@@ -1244,7 +1244,10 @@ public int emulateOP(long maxCycles) throws EmulationException {
int nxtCarry = 0;
int carry = (sr & CARRY) > 0? 1: 0;
if (rrword) {
+ mode = AccessMode.WORD;
dst = dst & 0xffff;
+ } else {
+ mode = AccessMode.WORD20; /* address */
}
cycles += 1 + count;
switch(instruction & RRMASK) {
@@ -1342,6 +1345,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
currentSegment.read(pc, AccessMode.WORD, AccessType.READ));
dst += currentSegment.read(pc, AccessMode.WORD, AccessType.READ);
System.out.println("CALLA INDX => " + Utils.hex20(dst));
+ dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ);
+ System.out.println("CALLA Read from INDX => " + Utils.hex20(dst));
cycles += 5;
pc += 2;
// System.exit(0);
-----------------------------------------------------------------------
Summary of changes:
se/sics/mspsim/core/MSP430Core.java | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
hooks/post-receive
--
mspsim
|