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