FreeCalypso > hg > freecalypso-sw
annotate rvinterf/tmsh/etmbasic.c @ 815:15cf4a8961d0
aci: sap_dti.c and sap_em.c done
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Sun, 05 Apr 2015 08:17:09 +0000 |
parents | 577291a2ad76 |
children | ebdf5afa9fb5 |
rev | line source |
---|---|
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * Basic ETM interaction |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 */ |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 #include <sys/types.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <stdio.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <string.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <strings.h> |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <stdlib.h> |
260
c146f38d2b5f
rvinterf subdir structure made a little more sensible
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
257
diff
changeset
|
10 #include "pktmux.h" |
c146f38d2b5f
rvinterf subdir structure made a little more sensible
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
257
diff
changeset
|
11 #include "limits.h" |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
12 #include "etm.h" |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 extern u_char rvi_msg[]; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 extern int rvi_msg_len; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 void |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
18 print_etm_pkt_raw(err) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
19 char *err; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
20 { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
21 char buf[MAX_PKT_FROM_TARGET*3+80], *dp; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
22 int i; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
23 |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
24 sprintf(buf, "%s:", err); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
25 dp = index(buf, '\0'); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
26 for (i = 2; i < rvi_msg_len; i++) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
27 sprintf(dp, " %02X", rvi_msg[i]); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
28 dp += 3; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
29 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
30 async_msg_output(buf); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
31 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
32 |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
33 void |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 etm_packet_rx() |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 { |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 int i, c; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 if (rvi_msg_len < 4) { |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
39 runt: print_etm_pkt_raw("ETM Runt"); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
40 return; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
41 } |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
42 c = 0; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
43 for (i = 2; i < rvi_msg_len; i++) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
44 c ^= rvi_msg[i]; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
45 if (c) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
46 print_etm_pkt_raw("BAD CKSUM"); |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
47 return; |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
48 } |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
49 switch (rvi_msg[2]) { |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
50 case ETM_CORE: |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
51 if (rvi_msg_len < 6) |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
52 goto runt; |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
53 tmcore_msg_rx(); |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
54 return; |
257
c413e791595a
fc-tmsh: added check-ffs1 command, getting ready to begin ffs2 implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
55 case ETM_FFS1: |
c413e791595a
fc-tmsh: added check-ffs1 command, getting ready to begin ffs2 implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
56 print_etm_pkt_raw("FFS1"); |
c413e791595a
fc-tmsh: added check-ffs1 command, getting ready to begin ffs2 implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
57 return; |
c413e791595a
fc-tmsh: added check-ffs1 command, getting ready to begin ffs2 implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
58 case ETM_FFS2: |
262
577291a2ad76
fc-tmsh ffs2 basic response handling implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
260
diff
changeset
|
59 if (rvi_msg_len < 5) |
577291a2ad76
fc-tmsh ffs2 basic response handling implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
260
diff
changeset
|
60 goto runt; |
577291a2ad76
fc-tmsh ffs2 basic response handling implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
260
diff
changeset
|
61 handle_ffs2_response(); |
257
c413e791595a
fc-tmsh: added check-ffs1 command, getting ready to begin ffs2 implementation
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
256
diff
changeset
|
62 return; |
188
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
63 default: |
9f4f331ac24d
fc-tmsh: implemented handling of ETM_CORE responses
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
184
diff
changeset
|
64 print_etm_pkt_raw("ETM Unknown"); |
183
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
65 } |
85222710dc92
rvinterf/etm: implemented everything except the packet sending command
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
66 } |
184
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
67 |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
68 void |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
69 cmd_etmpkt(argc, argv) |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
70 char **argv; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
71 { |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
72 u_char pkt[MAX_PKT_TO_TARGET]; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
73 int di, c, b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
74 char **ap; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
75 |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
76 pkt[0] = RVT_TM_HEADER; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
77 di = 1; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
78 c = 0; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
79 for (ap = argv + 1; *ap; ap++) { |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
80 b = strtoul(*ap, 0, 16); |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
81 pkt[di++] = b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
82 c ^= b; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
83 } |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
84 pkt[di++] = c; |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
85 send_pkt_to_target(pkt, di); |
4714fdfca39c
fc-tmsh compiles!
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
183
diff
changeset
|
86 } |
189
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
87 |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
88 void |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
89 send_etm_cmd(buf, len) |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
90 u_char *buf; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
91 { |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
92 int i, c; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
93 |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
94 buf[0] = RVT_TM_HEADER; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
95 c = 0; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
96 for (i = 1; i <= len; i++) |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
97 c ^= buf[i]; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
98 buf[i] = c; |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
99 send_pkt_to_target(buf, len + 2); |
a95d253ef952
fc-tmsh: some basic tmcore commands implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
188
diff
changeset
|
100 } |