First public contribution.
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\arm\ncutils.cpp
19 #include "../../include/kernel/kernboot.h"
22 SFullArmRegSet ArmRegs;
26 void FastMutexNestAttempt()
31 void FastMutexSignalError()
37 void NKern::Init0(TAny*)
39 ArmRegs.iExcCode = -1;
40 TheScheduler.i_Regs = &ArmRegs;
43 GLDEF_C TUint32 IrqReturnAddress()
45 TStackInfo& stackInfo = ((SSuperPageBase*)::SuperPageAddress)->iStackInfo;
46 return ((TUint32)stackInfo.iIrqStackBase) + stackInfo.iIrqStackSize - sizeof(TUint32);
49 /** Register the global IRQ handler
50 Called by the base port at boot time to bind the top level IRQ dispatcher
51 to the ARM IRQ vector. Should not be called at any other time.
53 The handler specified will be called in mode_irq with IRQs disabled and
54 FIQs enabled. R0-R3, R12 and the return address from the interrupt will
55 be on the top of the mode_irq stack. R14_irq will point to the kernel's
56 IRQ postamble routine, which will run IDFCs and reschedule if necessary.
57 R13_irq will point to the top of the mode_irq stack and will be 8-byte aligned.
58 The handler should preserve all registers other than R0-R3, R12, R14_irq
59 and should return to the address in R14_irq.
61 @param aHandler The address of the top level IRQ dispatcher routine
63 EXPORT_C void Arm::SetIrqHandler(TLinAddr aHandler)
65 ArmInterruptInfo.iIrqHandler=aHandler;
68 /** Register the global FIQ handler
69 Called by the base port at boot time to bind the top level FIQ dispatcher
70 to the ARM FIQ vector. Should not be called at any other time.
72 The handler specified will be called in mode_fiq with both IRQs and FIQs
73 disabled. The return address from the interrupt will be on the top of the
74 mode_fiq stack. R14_fiq will point to the kernel's FIQ postamble routine,
75 which will run IDFCs and reschedule if necessary.
76 R13_fiq will point to the top of the mode_fiq stack and will be 4 modulo 8.
77 The handler should preserve all registers other than R8_fiq-R12_fiq and
78 R14_fiq and should return to the address in R14_fiq.
80 @param aHandler The address of the top level FIQ dispatcher routine
82 EXPORT_C void Arm::SetFiqHandler(TLinAddr aHandler)
84 ArmInterruptInfo.iFiqHandler=aHandler;
87 extern void initialiseState();
88 void Arm::Init1Interrupts()
90 // Initialise the interrupt and exception vector handlers.
93 // TheIrqHandler=0; // done by placing TheIrqHandler, TheFiqHandler in .bss
99 extern "C" void __ArmVectorReset()
108 extern "C" void __ArmVectorReserved()
118 TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
120 return KErrNotSupported;
124 EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
126 TUint irq = NKern::DisableAllInterrupts();
128 aOldHandler = BTraceData.iHandler;
129 BTraceData.iHandler = aNewHandler;
130 ArmInterruptInfo.iBTraceHandler = aNewHandler;
131 TheScheduler.iBTraceHandler = aNewHandler;
133 aOldControl = BTraceData.iControl;
134 BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
136 NKern::RestoreInterrupts(irq);
140 EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
142 if(!IsSupported(aCategory))
143 return KErrNotSupported;
144 TUint irq = NKern::DisableAllInterrupts();
145 TUint8* filter = BTraceData.iFilter+aCategory;
146 TUint oldValue = *filter;
147 if(TUint(aValue)<=1u)
149 *filter = (TUint8)aValue;
150 BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
151 if(aCategory==ECpuUsage)
153 ArmInterruptInfo.iCpuUsageFilter = aValue;
154 TheScheduler.iCpuUsageFilter = aValue;
156 if (aCategory == EFastMutex)
158 // This is done because of the optimization in ncsched.cia for
159 // ARMv5 (check if lock is free (cmp) && filter is enabled (cmpeq))
160 TheScheduler.iFastMutexFilter = aValue ? 1 : 0;
163 NKern::RestoreInterrupts(irq);
167 EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
169 return &ArmInterruptInfo.iCpuIdleHandler;
172 EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
174 #ifdef MONITOR_THREAD_CPU_TIME
175 return NKern::FastCounterFrequency();