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