os/kernelhwsrv/kernel/eka/nkern/win32/ncutils.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\nkern\win32\ncutils.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "nk_priv.h"
sl@0
    19
sl@0
    20
void NKern::Init0(TAny*)
sl@0
    21
	{
sl@0
    22
	}
sl@0
    23
sl@0
    24
TUint32 ContextId()
sl@0
    25
	{
sl@0
    26
	switch(NKern::CurrentContext())
sl@0
    27
		{
sl@0
    28
	case NKern::EThread:
sl@0
    29
		return (TUint32)NKern::CurrentThread();
sl@0
    30
	case NKern::EIDFC:
sl@0
    31
		return 3;
sl@0
    32
	case NKern::EInterrupt:
sl@0
    33
		return 2;
sl@0
    34
	default:
sl@0
    35
		return 0;
sl@0
    36
		}
sl@0
    37
	}
sl@0
    38
sl@0
    39
EXPORT_C TBool BTrace::Out(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
    40
	{
sl@0
    41
	SBTraceData& traceData = BTraceData;
sl@0
    42
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
    43
		return FALSE;
sl@0
    44
sl@0
    45
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
    46
	return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
sl@0
    47
	}
sl@0
    48
sl@0
    49
EXPORT_C TBool BTrace::OutX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
    50
	{
sl@0
    51
	SBTraceData& traceData = BTraceData;
sl@0
    52
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
    53
		return FALSE;
sl@0
    54
sl@0
    55
	TUint32 context = ContextId();
sl@0
    56
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
    57
	return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
sl@0
    58
	}
sl@0
    59
sl@0
    60
EXPORT_C TBool BTrace::OutN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
    61
	{
sl@0
    62
	SBTraceData& traceData = BTraceData;
sl@0
    63
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
    64
		return FALSE;
sl@0
    65
sl@0
    66
	if(TUint(aDataSize)>KMaxBTraceDataArray)
sl@0
    67
		{
sl@0
    68
		aDataSize = KMaxBTraceDataArray;
sl@0
    69
		a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
sl@0
    70
		}
sl@0
    71
	a0 += aDataSize<<(BTrace::ESizeIndex*8);
sl@0
    72
sl@0
    73
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
    74
	if(!aDataSize)
sl@0
    75
		return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
sl@0
    76
	else if(aDataSize<=4)
sl@0
    77
		return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
sl@0
    78
	else
sl@0
    79
		return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
sl@0
    80
	}
sl@0
    81
sl@0
    82
EXPORT_C TBool BTrace::OutNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
    83
	{
sl@0
    84
	SBTraceData& traceData = BTraceData;
sl@0
    85
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
    86
		return FALSE;
sl@0
    87
sl@0
    88
	if(TUint(aDataSize)>KMaxBTraceDataArray)
sl@0
    89
		{
sl@0
    90
		aDataSize = KMaxBTraceDataArray;
sl@0
    91
		a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
sl@0
    92
		}
sl@0
    93
	a0 += aDataSize<<(BTrace::ESizeIndex*8);
sl@0
    94
sl@0
    95
	TUint32 context = ContextId();
sl@0
    96
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
    97
	if(!aDataSize)
sl@0
    98
		return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
sl@0
    99
	else if(aDataSize<=4)
sl@0
   100
		return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
sl@0
   101
	else
sl@0
   102
		return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
sl@0
   103
	}
sl@0
   104
sl@0
   105
EXPORT_C TBool BTrace::OutBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
sl@0
   106
	{
sl@0
   107
	TUint32 context = ContextId();
sl@0
   108
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   109
	SBTraceData& traceData = BTraceData;
sl@0
   110
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   111
		return FALSE;
sl@0
   112
	return DoOutBig(a0,a1,aData,aDataSize,context,pc);
sl@0
   113
	}
sl@0
   114
sl@0
   115
EXPORT_C TBool BTrace::OutFiltered(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   116
	{
sl@0
   117
	SBTraceData& traceData = BTraceData;
sl@0
   118
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   119
		return FALSE;
sl@0
   120
	if(!traceData.CheckFilter2(a1))
sl@0
   121
		return FALSE;
sl@0
   122
sl@0
   123
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   124
	return traceData.iHandler(a0,0,0,a1,a2,a3,0,pc);
sl@0
   125
	}
sl@0
   126
sl@0
   127
EXPORT_C TBool BTrace::OutFilteredX(TUint32 a0, TUint32 a1, TUint32 a2, TUint32 a3)
sl@0
   128
	{
sl@0
   129
	SBTraceData& traceData = BTraceData;
sl@0
   130
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   131
		return FALSE;
sl@0
   132
	if(!traceData.CheckFilter2(a1))
sl@0
   133
		return FALSE;
sl@0
   134
sl@0
   135
	TUint32 context = ContextId();
sl@0
   136
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   137
	return traceData.iHandler(a0,0,context,a1,a2,a3,0,pc);
sl@0
   138
	}
sl@0
   139
sl@0
   140
EXPORT_C TBool BTrace::OutFilteredN(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   141
	{
sl@0
   142
	SBTraceData& traceData = BTraceData;
sl@0
   143
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   144
		return FALSE;
sl@0
   145
	if(!traceData.CheckFilter2(a1))
sl@0
   146
		return FALSE;
sl@0
   147
sl@0
   148
	if(TUint(aDataSize)>KMaxBTraceDataArray)
sl@0
   149
		{
sl@0
   150
		aDataSize = KMaxBTraceDataArray;
sl@0
   151
		a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
sl@0
   152
		}
sl@0
   153
	a0 += aDataSize<<(BTrace::ESizeIndex*8);
sl@0
   154
sl@0
   155
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   156
	if(!aDataSize)
sl@0
   157
		return traceData.iHandler(a0,0,0,a1,a2,0,0,pc);
sl@0
   158
	else if(aDataSize<=4)
sl@0
   159
		return traceData.iHandler(a0,0,0,a1,a2,*(TUint32*)aData,0,pc);
sl@0
   160
	else
sl@0
   161
		return traceData.iHandler(a0,0,0,a1,a2,(TUint32)aData,0,pc);
sl@0
   162
	}
sl@0
   163
sl@0
   164
EXPORT_C TBool BTrace::OutFilteredNX(TUint32 a0, TUint32 a1, TUint32 a2, const TAny* aData, TInt aDataSize)
sl@0
   165
	{
sl@0
   166
	SBTraceData& traceData = BTraceData;
sl@0
   167
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   168
		return FALSE;
sl@0
   169
	if(!traceData.CheckFilter2(a1))
sl@0
   170
		return FALSE;
sl@0
   171
sl@0
   172
	if(TUint(aDataSize)>KMaxBTraceDataArray)
sl@0
   173
		{
sl@0
   174
		aDataSize = KMaxBTraceDataArray;
sl@0
   175
		a0 |= BTrace::ERecordTruncated<<(BTrace::EFlagsIndex*8);
sl@0
   176
		}
sl@0
   177
	a0 += aDataSize<<(BTrace::ESizeIndex*8);
sl@0
   178
sl@0
   179
	TUint32 context = ContextId();
sl@0
   180
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   181
	if(!aDataSize)
sl@0
   182
		return traceData.iHandler(a0,0,context,a1,a2,0,0,pc);
sl@0
   183
	else if(aDataSize<=4)
sl@0
   184
		return traceData.iHandler(a0,0,context,a1,a2,*(TUint32*)aData,0,pc);
sl@0
   185
	else
sl@0
   186
		return traceData.iHandler(a0,0,context,a1,a2,(TUint32)aData,0,pc);
sl@0
   187
	}
sl@0
   188
sl@0
   189
EXPORT_C TBool BTrace::OutFilteredBig(TUint32 a0, TUint32 a1, const TAny* aData, TInt aDataSize)
sl@0
   190
	{
sl@0
   191
	TUint32 context = ContextId();
sl@0
   192
	TUint32 pc = (&a0)[-1]; // return address on X86
sl@0
   193
	SBTraceData& traceData = BTraceData;
sl@0
   194
	if(!traceData.iFilter[(a0>>BTrace::ECategoryIndex*8)&0xff])
sl@0
   195
		return FALSE;
sl@0
   196
	if(!traceData.CheckFilter2(a1))
sl@0
   197
		return FALSE;
sl@0
   198
	return DoOutBig(a0,a1,aData,aDataSize,context,pc);
sl@0
   199
	}
sl@0
   200
sl@0
   201
sl@0
   202
EXPORT_C TBool BTrace::OutFilteredPcFormatBig(TUint32 /*aHeader*/, TUint32 /*aModuleUid*/, TUint32 /*aPc*/, TUint16 /*aFormatId*/, const TAny* /*aData*/, TInt /*aDataSize*/)
sl@0
   203
	{
sl@0
   204
	return FALSE; //kernel side not implemented yet
sl@0
   205
	}
sl@0
   206
sl@0
   207
TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
sl@0
   208
	{
sl@0
   209
	return KErrNotSupported;
sl@0
   210
	}
sl@0
   211
sl@0
   212
sl@0
   213
EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
sl@0
   214
	{
sl@0
   215
	TUint irq = NKern::DisableAllInterrupts();
sl@0
   216
sl@0
   217
	aOldHandler = BTraceData.iHandler;
sl@0
   218
	BTraceData.iHandler = aNewHandler;
sl@0
   219
	TheScheduler.iBTraceHandler = aNewHandler;
sl@0
   220
sl@0
   221
	aOldControl = BTraceData.iControl;
sl@0
   222
	BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
sl@0
   223
sl@0
   224
	NKern::RestoreInterrupts(irq);
sl@0
   225
	}
sl@0
   226
sl@0
   227
sl@0
   228
EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
sl@0
   229
	{
sl@0
   230
	if(!IsSupported(aCategory))
sl@0
   231
		return KErrNotSupported;
sl@0
   232
	TUint8* filter = BTraceData.iFilter+aCategory;
sl@0
   233
	TUint oldValue = *filter;
sl@0
   234
	if(TUint(aValue)<=1u)
sl@0
   235
		{
sl@0
   236
		*filter = (TUint8)aValue;
sl@0
   237
		BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
sl@0
   238
		if(aCategory==ECpuUsage)
sl@0
   239
			{
sl@0
   240
			TheScheduler.iCpuUsageFilter = (TUint8)aValue;
sl@0
   241
			}
sl@0
   242
		}
sl@0
   243
	return oldValue;
sl@0
   244
	}
sl@0
   245
sl@0
   246
EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
sl@0
   247
	{
sl@0
   248
	return 0;
sl@0
   249
	}
sl@0
   250
sl@0
   251
EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
sl@0
   252
	{
sl@0
   253
#ifdef MONITOR_THREAD_CPU_TIME
sl@0
   254
	return NKern::FastCounterFrequency();
sl@0
   255
#else
sl@0
   256
	return 0;
sl@0
   257
#endif
sl@0
   258
	}
sl@0
   259
sl@0
   260
sl@0
   261
/** @internalTechnology
sl@0
   262
sl@0
   263
	Called to indicate that the system has crashed and all CPUs should be
sl@0
   264
	halted and should dump their registers.
sl@0
   265
sl@0
   266
	Doesn't return
sl@0
   267
*/
sl@0
   268
void NKern::NotifyCrash(const TAny* a0, TInt a1)
sl@0
   269
	{
sl@0
   270
	NKern::DisableAllInterrupts();
sl@0
   271
	CrashState = 1;
sl@0
   272
	NKCrashHandler(0,0,0);
sl@0
   273
	NKCrashHandler(1,a0,a1);
sl@0
   274
	// Interrupts are disabled here, so we can't be suspended while exiting the process
sl@0
   275
	ExitProcess(101);
sl@0
   276
	}