Add Freescale Nexus decoder implementation
[babeltrace.git] / converter / nexus / NxPacketDecoder.cpp
1 /*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
21 */
22
23 #include "NxPacketDecoder.h"
24 #include <iostream>
25 using std::cout;
26 using std::endl;
27
28 void NxPacketDecoder::decodeICT_(uint32_t tcode, uint32_t source_id,
29 NxMessage* &msg)
30 {
31 // allocate the correct NxInCircuitTraceMessage
32 // based on the source_id.
33 if ((source_id & 0x1) == 0) {
34 // all cores have source ids where LSB = 0
35 msg = new NxCoreInCircuitTraceMessage(tcode);
36 } else {
37 switch (source_id) {
38 case 0xb:
39 // "Data Path Queueing Message";
40 msg = new NxDPQMInCircuitTraceMessage(tcode);
41 break;
42 case 0x1b:
43 // "Data Path Frame Message";
44 msg = new NxDPFMInCircuitTraceMessage(tcode);
45 break;
46 case 0x3b:
47 // "Data Path Cycle Trace Message";
48 msg = new NxInCircuitTraceMessage(tcode);
49 break;
50 case 0x0d:
51 // "DDR Terse/Verbose Message";
52 msg = new NxDAMInCircuitTraceMessage(tcode);
53 break;
54 case 0x1d:
55 // "Ocean Terse Address/Verbose Address/Header/Data";
56 msg = new NxInCircuitTraceMessage(tcode);
57 break;
58 case 0x2d:
59 // "CCSR IPM Address/IPM Data DCSR IPM Address/IPM Data";
60 msg = new NxInCircuitTraceMessage(tcode);
61 break;
62 case 0x3d:
63 // "EPU Counter Trace Message";
64 msg = new NxInCircuitTraceMessage(tcode);
65 break;
66 default:
67 // "Reserved";
68 msg = new NxInCircuitTraceMessage(tcode);
69 break;
70 };
71 }
72 }
73
74 // decode the packet set into a NxMessage
75 bool NxPacketDecoder::decode(NxPacketSet &pkt_set, NxMessage* &msg)
76 {
77 bool ret = true;
78
79 // get the tcode from the packet since its needed
80 // to create the correct NxMessage
81 uint32_t tcode = pkt_set.tcode();
82
83 // allocate the correct NxMessage from the tcode.
84 NxMessage *m;
85 switch (tcode) {
86
87 case 0:
88 m = new NxDebugStatusMessage();
89 break;
90
91 case 1:
92 m = new NxDeviceIDMessage();
93 break;
94
95 case 2:
96 m = new NxOwnershipTraceMessage();
97 break;
98
99 case 5:
100 m = new NxDataTraceWrite();
101 break;
102
103 case 6:
104 m = new NxDataTraceRead();
105 break;
106
107 case 7:
108 m = new NxDataAcquisitionMessage();
109 break;
110
111 case 8:
112 m = new NxErrorMessage();
113 break;
114
115 case 9:
116 m = new NxProgramTraceSync();
117 break;
118
119 case 13:
120 m = new NxDataTraceWriteSync();
121 break;
122
123 case 14:
124 m = new NxDataTraceReadSync();
125 break;
126
127 case 15:
128 m = new NxWatchpointMessage();
129 break;
130
131 case 27:
132 m = new NxResourceFullMessage();
133 break;
134
135 case 28:
136 m = new NxProgramTraceIndirectBranch();
137 break;
138
139 case 29:
140 m = new NxProgramTraceIndirectBranchSync();
141 break;
142
143 case 33:
144 m = new NxProgramTraceCorrelation();
145 break;
146
147 case 34: {
148 uint32_t src = pkt_set.src();
149 decodeICT_(tcode, src, m);
150 break;
151 }
152 case 35: {
153 uint32_t src = pkt_set.src();
154 decodeICT_(tcode, src, m);
155 break;
156 }
157 case 56:
158 m = new NxTimeStampCorrelation();
159 break;
160 default:
161 m = new NxDefaultMessage(tcode);
162 break;
163 };
164
165 // decode the rest of the data
166 ret = m->decode(pkt_set);
167
168 if (ret) {
169 // Assign and return the message
170 // The caller will take ownership of the memory
171 msg = m;
172 } else {
173 // error
174 cout << "Failed to decode NxPacketSet data into NxMessage with TCODE: "
175 << tcode << endl;
176 delete m;
177 }
178
179 return ret;
180 }
This page took 0.032617 seconds and 4 git commands to generate.