1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/nkern/x86/ncutils.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,267 @@
1.4 +// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// e32\nkern\x86\ncutils.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include <x86.h>
1.22 +
1.23 +//#define __DBG_MON_FAULT__
1.24 +//#define __RAM_LOADED_CODE__
1.25 +//#define __EARLY_DEBUG__
1.26 +
1.27 +
1.28 +void InitFpu();
1.29 +
1.30 +TUint32 ContextId()
1.31 + {
1.32 + switch(NKern::CurrentContext())
1.33 + {
1.34 + case NKern::EThread:
1.35 + return (TUint32)NKern::CurrentThread();
1.36 + case NKern::EIDFC:
1.37 + return 3;
1.38 + case NKern::EInterrupt:
1.39 + return 2;
1.40 + default:
1.41 + return 0;
1.42 + }
1.43 + }
1.44 +
1.45 +EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
1.46 + {
1.47 + SBTraceData& traceData = BTraceData;
1.48 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.49 + return FALSE;
1.50 +
1.51 + TUint32 pc = (&a0)[-1]; // return address on X86
1.52 + return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
1.53 + }
1.54 +
1.55 +EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
1.56 + {
1.57 + SBTraceData& traceData = BTraceData;
1.58 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.59 + return FALSE;
1.60 +
1.61 + TUint32 context = ContextId();
1.62 + TUint32 pc = (&a0)[-1]; // return address on X86
1.63 + return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
1.64 + }
1.65 +
1.66 +EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
1.67 + {
1.68 + SBTraceData& traceData = BTraceData;
1.69 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.70 + return FALSE;
1.71 +
1.72 + if(TUint(aDataSize)>KMaxBTraceDataArray)
1.73 + {
1.74 + aDataSize = KMaxBTraceDataArray;
1.75 + a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
1.76 + }
1.77 + a0 += aDataSize<<(BTrace::ESizeIndex*8);
1.78 +
1.79 + TUint32 pc = (&a0)[-1]; // return address on X86
1.80 + if(!aDataSize)
1.81 + return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
1.82 + else if(aDataSize<=4)
1.83 + return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
1.84 + else
1.85 + return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
1.86 + }
1.87 +
1.88 +EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
1.89 + {
1.90 + SBTraceData& traceData = BTraceData;
1.91 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.92 + return FALSE;
1.93 +
1.94 + if(TUint(aDataSize)>KMaxBTraceDataArray)
1.95 + {
1.96 + aDataSize = KMaxBTraceDataArray;
1.97 + a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
1.98 + }
1.99 + a0 += aDataSize<<(BTrace::ESizeIndex*8);
1.100 +
1.101 + TUint32 context = ContextId();
1.102 + TUint32 pc = (&a0)[-1]; // return address on X86
1.103 + if(!aDataSize)
1.104 + return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
1.105 + else if(aDataSize<=4)
1.106 + return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
1.107 + else
1.108 + return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
1.109 + }
1.110 +
1.111 +EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
1.112 + {
1.113 + TUint32 context = ContextId();
1.114 + TUint32 pc = (&a0)[-1]; // return address on X86
1.115 + SBTraceData& traceData = BTraceData;
1.116 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.117 + return FALSE;
1.118 + return DoOutBig(a0,a1,aData,aDataSize,context,pc);
1.119 + }
1.120 +
1.121 +EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
1.122 + {
1.123 + SBTraceData& traceData = BTraceData;
1.124 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.125 + return FALSE;
1.126 + if(!traceData.CheckFilter2(a1))
1.127 + return FALSE;
1.128 +
1.129 + TUint32 pc = (&a0)[-1]; // return address on X86
1.130 + return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
1.131 + }
1.132 +
1.133 +EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
1.134 + {
1.135 + SBTraceData& traceData = BTraceData;
1.136 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.137 + return FALSE;
1.138 + if(!traceData.CheckFilter2(a1))
1.139 + return FALSE;
1.140 +
1.141 + TUint32 context = ContextId();
1.142 + TUint32 pc = (&a0)[-1]; // return address on X86
1.143 + return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
1.144 + }
1.145 +
1.146 +EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
1.147 + {
1.148 + SBTraceData& traceData = BTraceData;
1.149 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.150 + return FALSE;
1.151 + if(!traceData.CheckFilter2(a1))
1.152 + return FALSE;
1.153 +
1.154 + if(TUint(aDataSize)>KMaxBTraceDataArray)
1.155 + {
1.156 + aDataSize = KMaxBTraceDataArray;
1.157 + a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
1.158 + }
1.159 + a0 += aDataSize<<(BTrace::ESizeIndex*8);
1.160 +
1.161 + TUint32 pc = (&a0)[-1]; // return address on X86
1.162 + if(!aDataSize)
1.163 + return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
1.164 + else if(aDataSize<=4)
1.165 + return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
1.166 + else
1.167 + return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
1.168 + }
1.169 +
1.170 +EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
1.171 + {
1.172 + SBTraceData& traceData = BTraceData;
1.173 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.174 + return FALSE;
1.175 + if(!traceData.CheckFilter2(a1))
1.176 + return FALSE;
1.177 +
1.178 + if(TUint(aDataSize)>KMaxBTraceDataArray)
1.179 + {
1.180 + aDataSize = KMaxBTraceDataArray;
1.181 + a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
1.182 + }
1.183 + a0 += aDataSize<<(BTrace::ESizeIndex*8);
1.184 +
1.185 + TUint32 context = ContextId();
1.186 + TUint32 pc = (&a0)[-1]; // return address on X86
1.187 + if(!aDataSize)
1.188 + return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
1.189 + else if(aDataSize<=4)
1.190 + return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
1.191 + else
1.192 + return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
1.193 + }
1.194 +
1.195 +EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
1.196 + {
1.197 + TUint32 context = ContextId();
1.198 + TUint32 pc = (&a0)[-1]; // return address on X86
1.199 + SBTraceData& traceData = BTraceData;
1.200 + if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
1.201 + return FALSE;
1.202 + if(!traceData.CheckFilter2(a1))
1.203 + return FALSE;
1.204 + return DoOutBig(a0,a1,aData,aDataSize,context,pc);
1.205 + }
1.206 +
1.207 +EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 aHeader, TUint32 aModuleUid, TUint32 aPc, TUint16 aFormatId, const TAny* aData, TInt aDataSize)
1.208 + {
1.209 + return EFalse; //kernel side not implemented yet
1.210 + }
1.211 +
1.212 +
1.213 +TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
1.214 + {
1.215 + return KErrNotSupported;
1.216 + }
1.217 +
1.218 +
1.219 +EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
1.220 + {
1.221 + TUint irq = NKern::DisableAllInterrupts();
1.222 +
1.223 + aOldHandler = BTraceData.iHandler;
1.224 + BTraceData.iHandler = aNewHandler;
1.225 + TheScheduler.iBTraceHandler = aNewHandler;
1.226 +
1.227 + aOldControl = BTraceData.iControl;
1.228 + BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
1.229 +
1.230 + NKern::RestoreInterrupts(irq);
1.231 + }
1.232 +
1.233 +
1.234 +EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
1.235 + {
1.236 + if(!IsSupported(aCategory))
1.237 + return KErrNotSupported;
1.238 + TUint8* filter = BTraceData.iFilter+aCategory;
1.239 + TUint oldValue = *filter;
1.240 + if(TUint(aValue)<=1u)
1.241 + {
1.242 + *filter = (TUint8)aValue;
1.243 + BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
1.244 + if(aCategory==ECpuUsage)
1.245 + {
1.246 + TheScheduler.iCpuUsageFilter = (TUint8)aValue;
1.247 + }
1.248 + }
1.249 + return oldValue;
1.250 + }
1.251 +
1.252 +EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
1.253 + {
1.254 + return &::CpuIdleHandler;
1.255 + }
1.256 +
1.257 +void NKern::Init0(TAny*)
1.258 + {
1.259 + InitFpu();
1.260 + }
1.261 +
1.262 +EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
1.263 + {
1.264 +#ifdef MONITOR_THREAD_CPU_TIME
1.265 + return 1862000000; // FIXME!!!!
1.266 +#else
1.267 + return 0;
1.268 +#endif
1.269 + }
1.270 +