0
|
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\arm\ncutils.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#include <arm.h>
|
|
19 |
#include "../../include/kernel/kernboot.h"
|
|
20 |
|
|
21 |
extern "C" {
|
|
22 |
SFullArmRegSet ArmRegs;
|
|
23 |
}
|
|
24 |
|
|
25 |
#ifdef _DEBUG
|
|
26 |
void FastMutexNestAttempt()
|
|
27 |
{
|
|
28 |
FAULT();
|
|
29 |
}
|
|
30 |
|
|
31 |
void FastMutexSignalError()
|
|
32 |
{
|
|
33 |
FAULT();
|
|
34 |
}
|
|
35 |
#endif
|
|
36 |
|
|
37 |
void NKern::Init0(TAny*)
|
|
38 |
{
|
|
39 |
ArmRegs.iExcCode = -1;
|
|
40 |
TheScheduler.i_Regs = &ArmRegs;
|
|
41 |
}
|
|
42 |
|
|
43 |
GLDEF_C TUint32 IrqReturnAddress()
|
|
44 |
{
|
|
45 |
TStackInfo& stackInfo = ((SSuperPageBase*)::SuperPageAddress)->iStackInfo;
|
|
46 |
return ((TUint32)stackInfo.iIrqStackBase) + stackInfo.iIrqStackSize - sizeof(TUint32);
|
|
47 |
}
|
|
48 |
|
|
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.
|
|
52 |
|
|
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.
|
|
60 |
|
|
61 |
@param aHandler The address of the top level IRQ dispatcher routine
|
|
62 |
*/
|
|
63 |
EXPORT_C void Arm::SetIrqHandler(TLinAddr aHandler)
|
|
64 |
{
|
|
65 |
ArmInterruptInfo.iIrqHandler=aHandler;
|
|
66 |
}
|
|
67 |
|
|
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.
|
|
71 |
|
|
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.
|
|
79 |
|
|
80 |
@param aHandler The address of the top level FIQ dispatcher routine
|
|
81 |
*/
|
|
82 |
EXPORT_C void Arm::SetFiqHandler(TLinAddr aHandler)
|
|
83 |
{
|
|
84 |
ArmInterruptInfo.iFiqHandler=aHandler;
|
|
85 |
}
|
|
86 |
|
|
87 |
extern void initialiseState();
|
|
88 |
void Arm::Init1Interrupts()
|
|
89 |
//
|
|
90 |
// Initialise the interrupt and exception vector handlers.
|
|
91 |
//
|
|
92 |
{
|
|
93 |
// TheIrqHandler=0; // done by placing TheIrqHandler, TheFiqHandler in .bss
|
|
94 |
// TheFiqHandler=0;
|
|
95 |
|
|
96 |
initialiseState();
|
|
97 |
}
|
|
98 |
|
|
99 |
extern "C" void __ArmVectorReset()
|
|
100 |
//
|
|
101 |
// Reset
|
|
102 |
//
|
|
103 |
{
|
|
104 |
|
|
105 |
FAULT();
|
|
106 |
}
|
|
107 |
|
|
108 |
extern "C" void __ArmVectorReserved()
|
|
109 |
//
|
|
110 |
// Reserved
|
|
111 |
//
|
|
112 |
{
|
|
113 |
|
|
114 |
FAULT();
|
|
115 |
}
|
|
116 |
|
|
117 |
|
|
118 |
TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/)
|
|
119 |
{
|
|
120 |
return KErrNotSupported;
|
|
121 |
}
|
|
122 |
|
|
123 |
|
|
124 |
EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl)
|
|
125 |
{
|
|
126 |
TUint irq = NKern::DisableAllInterrupts();
|
|
127 |
|
|
128 |
aOldHandler = BTraceData.iHandler;
|
|
129 |
BTraceData.iHandler = aNewHandler;
|
|
130 |
ArmInterruptInfo.iBTraceHandler = aNewHandler;
|
|
131 |
TheScheduler.iBTraceHandler = aNewHandler;
|
|
132 |
|
|
133 |
aOldControl = BTraceData.iControl;
|
|
134 |
BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl;
|
|
135 |
|
|
136 |
NKern::RestoreInterrupts(irq);
|
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue)
|
|
141 |
{
|
|
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)
|
|
148 |
{
|
|
149 |
*filter = (TUint8)aValue;
|
|
150 |
BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8));
|
|
151 |
if(aCategory==ECpuUsage)
|
|
152 |
{
|
|
153 |
ArmInterruptInfo.iCpuUsageFilter = aValue;
|
|
154 |
TheScheduler.iCpuUsageFilter = aValue;
|
|
155 |
}
|
|
156 |
if (aCategory == EFastMutex)
|
|
157 |
{
|
|
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;
|
|
161 |
}
|
|
162 |
}
|
|
163 |
NKern::RestoreInterrupts(irq);
|
|
164 |
return oldValue;
|
|
165 |
}
|
|
166 |
|
|
167 |
EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler()
|
|
168 |
{
|
|
169 |
return &ArmInterruptInfo.iCpuIdleHandler;
|
|
170 |
}
|
|
171 |
|
|
172 |
EXPORT_C TUint32 NKern::CpuTimeMeasFreq()
|
|
173 |
{
|
|
174 |
#ifdef MONITOR_THREAD_CPU_TIME
|
|
175 |
return NKern::FastCounterFrequency();
|
|
176 |
#else
|
|
177 |
return 0;
|
|
178 |
#endif
|
|
179 |
}
|