sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\nkern\win32\ncutils.cpp sl@0: // sl@0: // sl@0: sl@0: #include "nk_priv.h" sl@0: sl@0: void NKern::Init0(TAny*) sl@0: { sl@0: } sl@0: sl@0: TUint32 ContextId() sl@0: { sl@0: switch(NKern::CurrentContext()) sl@0: { sl@0: case NKern::EThread: sl@0: return (TUint32)NKern::CurrentThread(); sl@0: case NKern::EIDFC: sl@0: return 3; sl@0: case NKern::EInterrupt: sl@0: return 2; sl@0: default: sl@0: return 0; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: sl@0: if(TUint(aDataSize)>KMaxBTraceDataArray) sl@0: { sl@0: aDataSize = KMaxBTraceDataArray; sl@0: a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8); sl@0: } sl@0: a0 += aDataSize<<(BTrace::ESizeIndex*8); sl@0: sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: if(!aDataSize) sl@0: return traceData.iHandler(a0,0,0,a1,a2,0,0,pc); sl@0: else if(aDataSize<=4) sl@0: return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc); sl@0: else sl@0: return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: sl@0: if(TUint(aDataSize)>KMaxBTraceDataArray) sl@0: { sl@0: aDataSize = KMaxBTraceDataArray; sl@0: a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8); sl@0: } sl@0: a0 += aDataSize<<(BTrace::ESizeIndex*8); sl@0: sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: if(!aDataSize) sl@0: return traceData.iHandler(a0,0,context,a1,a2,0,0,pc); sl@0: else if(aDataSize<=4) sl@0: return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc); sl@0: else sl@0: return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize) sl@0: { sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: return DoOutBig(a0,a1,aData,aDataSize,context,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: if(!traceData.CheckFilter2(a1)) sl@0: return FALSE; sl@0: sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: if(!traceData.CheckFilter2(a1)) sl@0: return FALSE; sl@0: sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: if(!traceData.CheckFilter2(a1)) sl@0: return FALSE; sl@0: sl@0: if(TUint(aDataSize)>KMaxBTraceDataArray) sl@0: { sl@0: aDataSize = KMaxBTraceDataArray; sl@0: a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8); sl@0: } sl@0: a0 += aDataSize<<(BTrace::ESizeIndex*8); sl@0: sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: if(!aDataSize) sl@0: return traceData.iHandler(a0,0,0,a1,a2,0,0,pc); sl@0: else if(aDataSize<=4) sl@0: return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc); sl@0: else sl@0: return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize) sl@0: { sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: if(!traceData.CheckFilter2(a1)) sl@0: return FALSE; sl@0: sl@0: if(TUint(aDataSize)>KMaxBTraceDataArray) sl@0: { sl@0: aDataSize = KMaxBTraceDataArray; sl@0: a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8); sl@0: } sl@0: a0 += aDataSize<<(BTrace::ESizeIndex*8); sl@0: sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: if(!aDataSize) sl@0: return traceData.iHandler(a0,0,context,a1,a2,0,0,pc); sl@0: else if(aDataSize<=4) sl@0: return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc); sl@0: else sl@0: return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc); sl@0: } sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize) sl@0: { sl@0: TUint32 context = ContextId(); sl@0: TUint32 pc = (&a0)[-1]; // return address on X86 sl@0: SBTraceData& traceData = BTraceData; sl@0: if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff]) sl@0: return FALSE; sl@0: if(!traceData.CheckFilter2(a1)) sl@0: return FALSE; sl@0: return DoOutBig(a0,a1,aData,aDataSize,context,pc); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 /*aHeader*/, TUint32 /*aModuleUid*/, TUint32 /*aPc*/, TUint16 /*aFormatId*/, const TAny* /*aData*/, TInt /*aDataSize*/) sl@0: { sl@0: return FALSE; //kernel side not implemented yet sl@0: } sl@0: sl@0: TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: sl@0: EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl) sl@0: { sl@0: TUint irq = NKern::DisableAllInterrupts(); sl@0: sl@0: aOldHandler = BTraceData.iHandler; sl@0: BTraceData.iHandler = aNewHandler; sl@0: TheScheduler.iBTraceHandler = aNewHandler; sl@0: sl@0: aOldControl = BTraceData.iControl; sl@0: BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl; sl@0: sl@0: NKern::RestoreInterrupts(irq); sl@0: } sl@0: sl@0: sl@0: EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue) sl@0: { sl@0: if(!IsSupported(aCategory)) sl@0: return KErrNotSupported; sl@0: TUint8* filter = BTraceData.iFilter+aCategory; sl@0: TUint oldValue = *filter; sl@0: if(TUint(aValue)<=1u) sl@0: { sl@0: *filter = (TUint8)aValue; sl@0: BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8)); sl@0: if(aCategory==ECpuUsage) sl@0: { sl@0: TheScheduler.iCpuUsageFilter = (TUint8)aValue; sl@0: } sl@0: } sl@0: return oldValue; sl@0: } sl@0: sl@0: EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler() sl@0: { sl@0: return 0; sl@0: } sl@0: sl@0: EXPORT_C TUint32 NKern::CpuTimeMeasFreq() sl@0: { sl@0: #ifdef MONITOR_THREAD_CPU_TIME sl@0: return NKern::FastCounterFrequency(); sl@0: #else sl@0: return 0; sl@0: #endif sl@0: } sl@0: sl@0: sl@0: /** @internalTechnology sl@0: sl@0: Called to indicate that the system has crashed and all CPUs should be sl@0: halted and should dump their registers. sl@0: sl@0: Doesn't return sl@0: */ sl@0: void NKern::NotifyCrash(const TAny* a0, TInt a1) sl@0: { sl@0: NKern::DisableAllInterrupts(); sl@0: CrashState = 1; sl@0: NKCrashHandler(0,0,0); sl@0: NKCrashHandler(1,a0,a1); sl@0: // Interrupts are disabled here, so we can't be suspended while exiting the process sl@0: ExitProcess(101); sl@0: }