0
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32\nkern\win32\ncutils.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include "nk_priv.h"
|
|
19 |
|
|
20 |
void NKern::Init0(TAny*)
|
|
21 |
{
|
|
22 |
}
|
|
23 |
|
|
24 |
TUint32 ContextId()
|
|
25 |
{
|
|
26 |
switch(NKern::CurrentContext())
|
|
27 |
{
|
|
28 |
case NKern::EThread:
|
|
29 |
return (TUint32)NKern::CurrentThread();
|
|
30 |
case NKern::EIDFC:
|
|
31 |
return 3;
|
|
32 |
case NKern::EInterrupt:
|
|
33 |
return 2;
|
|
34 |
default:
|
|
35 |
return 0;
|
|
36 |
}
|
|
37 |
}
|
|
38 |
|
|
39 |
EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
|
|
40 |
{
|
|
41 |
SBTraceData& traceData = BTraceData;
|
|
42 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
43 |
return FALSE;
|
|
44 |
|
|
45 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
46 |
return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
|
|
47 |
}
|
|
48 |
|
|
49 |
EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
|
|
50 |
{
|
|
51 |
SBTraceData& traceData = BTraceData;
|
|
52 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
53 |
return FALSE;
|
|
54 |
|
|
55 |
TUint32 context = ContextId();
|
|
56 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
57 |
return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
|
|
58 |
}
|
|
59 |
|
|
60 |
EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
|
|
61 |
{
|
|
62 |
SBTraceData& traceData = BTraceData;
|
|
63 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
64 |
return FALSE;
|
|
65 |
|
|
66 |
if(TUint(aDataSize)>KMaxBTraceDataArray)
|
|
67 |
{
|
|
68 |
aDataSize = KMaxBTraceDataArray;
|
|
69 |
a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
|
|
70 |
}
|
|
71 |
a0 += aDataSize<<(BTrace::ESizeIndex*8);
|
|
72 |
|
|
73 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
74 |
if(!aDataSize)
|
|
75 |
return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
|
|
76 |
else if(aDataSize<=4)
|
|
77 |
return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
|
|
78 |
else
|
|
79 |
return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
|
|
80 |
}
|
|
81 |
|
|
82 |
EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
|
|
83 |
{
|
|
84 |
SBTraceData& traceData = BTraceData;
|
|
85 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
86 |
return FALSE;
|
|
87 |
|
|
88 |
if(TUint(aDataSize)>KMaxBTraceDataArray)
|
|
89 |
{
|
|
90 |
aDataSize = KMaxBTraceDataArray;
|
|
91 |
a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
|
|
92 |
}
|
|
93 |
a0 += aDataSize<<(BTrace::ESizeIndex*8);
|
|
94 |
|
|
95 |
TUint32 context = ContextId();
|
|
96 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
97 |
if(!aDataSize)
|
|
98 |
return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
|
|
99 |
else if(aDataSize<=4)
|
|
100 |
return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
|
|
101 |
else
|
|
102 |
return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
|
|
103 |
}
|
|
104 |
|
|
105 |
EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
|
|
106 |
{
|
|
107 |
TUint32 context = ContextId();
|
|
108 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
109 |
SBTraceData& traceData = BTraceData;
|
|
110 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
111 |
return FALSE;
|
|
112 |
return DoOutBig(a0,a1,aData,aDataSize,context,pc);
|
|
113 |
}
|
|
114 |
|
|
115 |
EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
|
|
116 |
{
|
|
117 |
SBTraceData& traceData = BTraceData;
|
|
118 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
119 |
return FALSE;
|
|
120 |
if(!traceData.CheckFilter2(a1))
|
|
121 |
return FALSE;
|
|
122 |
|
|
123 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
124 |
return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
|
|
125 |
}
|
|
126 |
|
|
127 |
EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
|
|
128 |
{
|
|
129 |
SBTraceData& traceData = BTraceData;
|
|
130 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
131 |
return FALSE;
|
|
132 |
if(!traceData.CheckFilter2(a1))
|
|
133 |
return FALSE;
|
|
134 |
|
|
135 |
TUint32 context = ContextId();
|
|
136 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
137 |
return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
|
|
138 |
}
|
|
139 |
|
|
140 |
EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
|
|
141 |
{
|
|
142 |
SBTraceData& traceData = BTraceData;
|
|
143 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
144 |
return FALSE;
|
|
145 |
if(!traceData.CheckFilter2(a1))
|
|
146 |
return FALSE;
|
|
147 |
|
|
148 |
if(TUint(aDataSize)>KMaxBTraceDataArray)
|
|
149 |
{
|
|
150 |
aDataSize = KMaxBTraceDataArray;
|
|
151 |
a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
|
|
152 |
}
|
|
153 |
a0 += aDataSize<<(BTrace::ESizeIndex*8);
|
|
154 |
|
|
155 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
156 |
if(!aDataSize)
|
|
157 |
return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
|
|
158 |
else if(aDataSize<=4)
|
|
159 |
return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
|
|
160 |
else
|
|
161 |
return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
|
|
162 |
}
|
|
163 |
|
|
164 |
EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
|
|
165 |
{
|
|
166 |
SBTraceData& traceData = BTraceData;
|
|
167 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
168 |
return FALSE;
|
|
169 |
if(!traceData.CheckFilter2(a1))
|
|
170 |
return FALSE;
|
|
171 |
|
|
172 |
if(TUint(aDataSize)>KMaxBTraceDataArray)
|
|
173 |
{
|
|
174 |
aDataSize = KMaxBTraceDataArray;
|
|
175 |
a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
|
|
176 |
}
|
|
177 |
a0 += aDataSize<<(BTrace::ESizeIndex*8);
|
|
178 |
|
|
179 |
TUint32 context = ContextId();
|
|
180 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
181 |
if(!aDataSize)
|
|
182 |
return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
|
|
183 |
else if(aDataSize<=4)
|
|
184 |
return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
|
|
185 |
else
|
|
186 |
return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
|
|
187 |
}
|
|
188 |
|
|
189 |
EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
|
|
190 |
{
|
|
191 |
TUint32 context = ContextId();
|
|
192 |
TUint32 pc = (&a0)[-1]; // return address on X86
|
|
193 |
SBTraceData& traceData = BTraceData;
|
|
194 |
if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
|
|
195 |
return FALSE;
|
|
196 |
if(!traceData.CheckFilter2(a1))
|
|
197 |
return FALSE;
|
|
198 |
return DoOutBig(a0,a1,aData,aDataSize,context,pc);
|
|
199 |
}
|
|
200 |
|
|
201 |
|
|
202 |
EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 /*aHeader*/, TUint32 /*aModuleUid*/, TUint32 /*aPc*/, TUint16 /*aFormatId*/, const TAny* /*aData*/, TInt /*aDataSize*/)
|
|
203 |
{
|
|
204 |
return FALSE; //kernel side not implemented yet
|
|
205 |
}
|
|
206 |
|
|
207 |
TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
|
|
208 |
{
|
|
209 |
return KErrNotSupported;
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
213 |
EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
|
|
214 |
{
|
|
215 |
TUint irq = NKern::DisableAllInterrupts();
|
|
216 |
|
|
217 |
aOldHandler = BTraceData.iHandler;
|
|
218 |
BTraceData.iHandler = aNewHandler;
|
|
219 |
TheScheduler.iBTraceHandler = aNewHandler;
|
|
220 |
|
|
221 |
aOldControl = BTraceData.iControl;
|
|
222 |
BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
|
|
223 |
|
|
224 |
NKern::RestoreInterrupts(irq);
|
|
225 |
}
|
|
226 |
|
|
227 |
|
|
228 |
EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
|
|
229 |
{
|
|
230 |
if(!IsSupported(aCategory))
|
|
231 |
return KErrNotSupported;
|
|
232 |
TUint8* filter = BTraceData.iFilter+aCategory;
|
|
233 |
TUint oldValue = *filter;
|
|
234 |
if(TUint(aValue)<=1u)
|
|
235 |
{
|
|
236 |
*filter = (TUint8)aValue;
|
|
237 |
BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
|
|
238 |
if(aCategory==ECpuUsage)
|
|
239 |
{
|
|
240 |
TheScheduler.iCpuUsageFilter = (TUint8)aValue;
|
|
241 |
}
|
|
242 |
}
|
|
243 |
return oldValue;
|
|
244 |
}
|
|
245 |
|
|
246 |
EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
|
|
247 |
{
|
|
248 |
return 0;
|
|
249 |
}
|
|
250 |
|
|
251 |
EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
|
|
252 |
{
|
|
253 |
#ifdef MONITOR_THREAD_CPU_TIME
|
|
254 |
return NKern::FastCounterFrequency();
|
|
255 |
#else
|
|
256 |
return 0;
|
|
257 |
#endif
|
|
258 |
}
|
|
259 |
|
|
260 |
|
|
261 |
/** @internalTechnology
|
|
262 |
|
|
263 |
Called to indicate that the system has crashed and all CPUs should be
|
|
264 |
halted and should dump their registers.
|
|
265 |
|
|
266 |
Doesn't return
|
|
267 |
*/
|
|
268 |
void NKern::NotifyCrash(const TAny* a0, TInt a1)
|
|
269 |
{
|
|
270 |
NKern::DisableAllInterrupts();
|
|
271 |
CrashState = 1;
|
|
272 |
NKCrashHandler(0,0,0);
|
|
273 |
NKCrashHandler(1,a0,a1);
|
|
274 |
// Interrupts are disabled here, so we can't be suspended while exiting the process
|
|
275 |
ExitProcess(101);
|
|
276 |
}
|