Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\nkern\win32\ncutils.cpp
20 void NKern::Init0(TAny*)
26 switch(NKern::CurrentContext())
29 return (TUint32)NKern::CurrentThread();
32 case NKern::EInterrupt:
39 EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
41 SBTraceData& traceData = BTraceData;
42 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
45 TUint32 pc = (&a0)[-1]; // return address on X86
46 return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
49 EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
51 SBTraceData& traceData = BTraceData;
52 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
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);
60 EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
62 SBTraceData& traceData = BTraceData;
63 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
66 if(TUint(aDataSize)>KMaxBTraceDataArray)
68 aDataSize = KMaxBTraceDataArray;
69 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
71 a0 += aDataSize<<(BTrace::ESizeIndex*8);
73 TUint32 pc = (&a0)[-1]; // return address on X86
75 return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
77 return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
79 return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
82 EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
84 SBTraceData& traceData = BTraceData;
85 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
88 if(TUint(aDataSize)>KMaxBTraceDataArray)
90 aDataSize = KMaxBTraceDataArray;
91 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
93 a0 += aDataSize<<(BTrace::ESizeIndex*8);
95 TUint32 context = ContextId();
96 TUint32 pc = (&a0)[-1]; // return address on X86
98 return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
100 return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
102 return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
105 EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
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])
112 return DoOutBig(a0,a1,aData,aDataSize,context,pc);
115 EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
117 SBTraceData& traceData = BTraceData;
118 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
120 if(!traceData.CheckFilter2(a1))
123 TUint32 pc = (&a0)[-1]; // return address on X86
124 return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
127 EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
129 SBTraceData& traceData = BTraceData;
130 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
132 if(!traceData.CheckFilter2(a1))
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);
140 EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
142 SBTraceData& traceData = BTraceData;
143 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
145 if(!traceData.CheckFilter2(a1))
148 if(TUint(aDataSize)>KMaxBTraceDataArray)
150 aDataSize = KMaxBTraceDataArray;
151 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
153 a0 += aDataSize<<(BTrace::ESizeIndex*8);
155 TUint32 pc = (&a0)[-1]; // return address on X86
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);
161 return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
164 EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
166 SBTraceData& traceData = BTraceData;
167 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
169 if(!traceData.CheckFilter2(a1))
172 if(TUint(aDataSize)>KMaxBTraceDataArray)
174 aDataSize = KMaxBTraceDataArray;
175 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
177 a0 += aDataSize<<(BTrace::ESizeIndex*8);
179 TUint32 context = ContextId();
180 TUint32 pc = (&a0)[-1]; // return address on X86
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);
186 return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
189 EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
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])
196 if(!traceData.CheckFilter2(a1))
198 return DoOutBig(a0,a1,aData,aDataSize,context,pc);
202 EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 /*aHeader*/, TUint32 /*aModuleUid*/, TUint32 /*aPc*/, TUint16 /*aFormatId*/, const TAny* /*aData*/, TInt /*aDataSize*/)
204 return FALSE; //kernel side not implemented yet
207 TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
209 return KErrNotSupported;
213 EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
215 TUint irq = NKern::DisableAllInterrupts();
217 aOldHandler = BTraceData.iHandler;
218 BTraceData.iHandler = aNewHandler;
219 TheScheduler.iBTraceHandler = aNewHandler;
221 aOldControl = BTraceData.iControl;
222 BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
224 NKern::RestoreInterrupts(irq);
228 EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
230 if(!IsSupported(aCategory))
231 return KErrNotSupported;
232 TUint8* filter = BTraceData.iFilter+aCategory;
233 TUint oldValue = *filter;
234 if(TUint(aValue)<=1u)
236 *filter = (TUint8)aValue;
237 BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
238 if(aCategory==ECpuUsage)
240 TheScheduler.iCpuUsageFilter = (TUint8)aValue;
246 EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
251 EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
253 #ifdef MONITOR_THREAD_CPU_TIME
254 return NKern::FastCounterFrequency();
261 /** @internalTechnology
263 Called to indicate that the system has crashed and all CPUs should be
264 halted and should dump their registers.
268 void NKern::NotifyCrash(const TAny* a0, TInt a1)
270 NKern::DisableAllInterrupts();
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