Update contrib.
1 // Copyright (c) 1994-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\x86\ncutils.cpp
20 //#define __DBG_MON_FAULT__
21 //#define __RAM_LOADED_CODE__
22 //#define __EARLY_DEBUG__
29 switch(NKern::CurrentContext())
32 return (TUint32)NKern::CurrentThread();
35 case NKern::EInterrupt:
42 EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
44 SBTraceData& traceData = BTraceData;
45 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
48 TUint32 pc = (&a0)[-1]; // return address on X86
49 return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
52 EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
54 SBTraceData& traceData = BTraceData;
55 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
58 TUint32 context = ContextId();
59 TUint32 pc = (&a0)[-1]; // return address on X86
60 return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
63 EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
65 SBTraceData& traceData = BTraceData;
66 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
69 if(TUint(aDataSize)>KMaxBTraceDataArray)
71 aDataSize = KMaxBTraceDataArray;
72 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
74 a0 += aDataSize<<(BTrace::ESizeIndex*8);
76 TUint32 pc = (&a0)[-1]; // return address on X86
78 return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
80 return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
82 return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
85 EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
87 SBTraceData& traceData = BTraceData;
88 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
91 if(TUint(aDataSize)>KMaxBTraceDataArray)
93 aDataSize = KMaxBTraceDataArray;
94 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
96 a0 += aDataSize<<(BTrace::ESizeIndex*8);
98 TUint32 context = ContextId();
99 TUint32 pc = (&a0)[-1]; // return address on X86
101 return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
102 else if(aDataSize<=4)
103 return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
105 return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
108 EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
110 TUint32 context = ContextId();
111 TUint32 pc = (&a0)[-1]; // return address on X86
112 SBTraceData& traceData = BTraceData;
113 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
115 return DoOutBig(a0,a1,aData,aDataSize,context,pc);
118 EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
120 SBTraceData& traceData = BTraceData;
121 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
123 if(!traceData.CheckFilter2(a1))
126 TUint32 pc = (&a0)[-1]; // return address on X86
127 return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
130 EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
132 SBTraceData& traceData = BTraceData;
133 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
135 if(!traceData.CheckFilter2(a1))
138 TUint32 context = ContextId();
139 TUint32 pc = (&a0)[-1]; // return address on X86
140 return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
143 EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
145 SBTraceData& traceData = BTraceData;
146 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
148 if(!traceData.CheckFilter2(a1))
151 if(TUint(aDataSize)>KMaxBTraceDataArray)
153 aDataSize = KMaxBTraceDataArray;
154 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
156 a0 += aDataSize<<(BTrace::ESizeIndex*8);
158 TUint32 pc = (&a0)[-1]; // return address on X86
160 return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
161 else if(aDataSize<=4)
162 return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
164 return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
167 EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
169 SBTraceData& traceData = BTraceData;
170 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
172 if(!traceData.CheckFilter2(a1))
175 if(TUint(aDataSize)>KMaxBTraceDataArray)
177 aDataSize = KMaxBTraceDataArray;
178 a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
180 a0 += aDataSize<<(BTrace::ESizeIndex*8);
182 TUint32 context = ContextId();
183 TUint32 pc = (&a0)[-1]; // return address on X86
185 return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
186 else if(aDataSize<=4)
187 return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
189 return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
192 EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
194 TUint32 context = ContextId();
195 TUint32 pc = (&a0)[-1]; // return address on X86
196 SBTraceData& traceData = BTraceData;
197 if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
199 if(!traceData.CheckFilter2(a1))
201 return DoOutBig(a0,a1,aData,aDataSize,context,pc);
204 EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 aHeader, TUint32 aModuleUid, TUint32 aPc, TUint16 aFormatId, const TAny* aData, TInt aDataSize)
206 return EFalse; //kernel side not implemented yet
210 TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
212 return KErrNotSupported;
216 EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
218 TUint irq = NKern::DisableAllInterrupts();
220 aOldHandler = BTraceData.iHandler;
221 BTraceData.iHandler = aNewHandler;
222 TheScheduler.iBTraceHandler = aNewHandler;
224 aOldControl = BTraceData.iControl;
225 BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
227 NKern::RestoreInterrupts(irq);
231 EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
233 if(!IsSupported(aCategory))
234 return KErrNotSupported;
235 TUint8* filter = BTraceData.iFilter+aCategory;
236 TUint oldValue = *filter;
237 if(TUint(aValue)<=1u)
239 *filter = (TUint8)aValue;
240 BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
241 if(aCategory==ECpuUsage)
243 TheScheduler.iCpuUsageFilter = (TUint8)aValue;
249 EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
251 return &::CpuIdleHandler;
254 void NKern::Init0(TAny*)
259 EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
261 #ifdef MONITOR_THREAD_CPU_TIME
262 return 1862000000; // FIXME!!!!