author | Chetan Kapoor <chetank@symbian.org> |
Tue, 04 May 2010 16:57:20 +0100 | |
changeset 104 | 466a0df5c15a |
parent 90 | 947f0dc9f7a8 |
child 257 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
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 |
||
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
/** Register the global Idle handler |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
Called by the base port at boot time to register a handler containing a pointer to |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
89 |
a function that is called by the Kernel when each core reaches idle. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
90 |
Should not be called at any other time. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
92 |
@param aHandler Pointer to idle handler function |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
93 |
@param aPtr Idle handler function argument |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
*/ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
EXPORT_C void Arm::SetIdleHandler(TCpuIdleHandlerFn aHandler, TAny* aPtr) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
96 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
ArmInterruptInfo.iCpuIdleHandler.iHandler = aHandler; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
ArmInterruptInfo.iCpuIdleHandler.iPtr = aPtr; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
99 |
ArmInterruptInfo.iCpuIdleHandler.iPostambleRequired = EFalse; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
101 |
|
0 | 102 |
extern void initialiseState(); |
103 |
void Arm::Init1Interrupts() |
|
104 |
// |
|
105 |
// Initialise the interrupt and exception vector handlers. |
|
106 |
// |
|
107 |
{ |
|
108 |
// TheIrqHandler=0; // done by placing TheIrqHandler, TheFiqHandler in .bss |
|
109 |
// TheFiqHandler=0; |
|
110 |
||
111 |
initialiseState(); |
|
112 |
} |
|
113 |
||
114 |
extern "C" void __ArmVectorReset() |
|
115 |
// |
|
116 |
// Reset |
|
117 |
// |
|
118 |
{ |
|
119 |
||
120 |
FAULT(); |
|
121 |
} |
|
122 |
||
123 |
extern "C" void __ArmVectorReserved() |
|
124 |
// |
|
125 |
// Reserved |
|
126 |
// |
|
127 |
{ |
|
128 |
||
129 |
FAULT(); |
|
130 |
} |
|
131 |
||
132 |
||
133 |
TInt BTraceDefaultControl(BTrace::TControl /*aFunction*/, TAny* /*aArg1*/, TAny* /*aArg2*/) |
|
134 |
{ |
|
135 |
return KErrNotSupported; |
|
136 |
} |
|
137 |
||
138 |
||
139 |
EXPORT_C void BTrace::SetHandlers(BTrace::THandler aNewHandler, BTrace::TControlFunction aNewControl, BTrace::THandler& aOldHandler, BTrace::TControlFunction& aOldControl) |
|
140 |
{ |
|
141 |
TUint irq = NKern::DisableAllInterrupts(); |
|
142 |
||
143 |
aOldHandler = BTraceData.iHandler; |
|
144 |
BTraceData.iHandler = aNewHandler; |
|
145 |
ArmInterruptInfo.iBTraceHandler = aNewHandler; |
|
146 |
TheScheduler.iBTraceHandler = aNewHandler; |
|
147 |
||
148 |
aOldControl = BTraceData.iControl; |
|
149 |
BTraceData.iControl = aNewControl ? aNewControl : BTraceDefaultControl; |
|
150 |
||
151 |
NKern::RestoreInterrupts(irq); |
|
152 |
} |
|
153 |
||
154 |
||
155 |
EXPORT_C TInt BTrace::SetFilter(TUint aCategory, TInt aValue) |
|
156 |
{ |
|
157 |
if(!IsSupported(aCategory)) |
|
158 |
return KErrNotSupported; |
|
159 |
TUint irq = NKern::DisableAllInterrupts(); |
|
160 |
TUint8* filter = BTraceData.iFilter+aCategory; |
|
161 |
TUint oldValue = *filter; |
|
162 |
if(TUint(aValue)<=1u) |
|
163 |
{ |
|
164 |
*filter = (TUint8)aValue; |
|
165 |
BTraceContext4(BTrace::EMetaTrace, BTrace::EMetaTraceFilterChange, (TUint8)aCategory | (aValue<<8)); |
|
166 |
if(aCategory==ECpuUsage) |
|
167 |
{ |
|
168 |
ArmInterruptInfo.iCpuUsageFilter = aValue; |
|
169 |
TheScheduler.iCpuUsageFilter = aValue; |
|
170 |
} |
|
171 |
if (aCategory == EFastMutex) |
|
172 |
{ |
|
173 |
// This is done because of the optimization in ncsched.cia for |
|
174 |
// ARMv5 (check if lock is free (cmp) && filter is enabled (cmpeq)) |
|
175 |
TheScheduler.iFastMutexFilter = aValue ? 1 : 0; |
|
176 |
} |
|
177 |
} |
|
178 |
NKern::RestoreInterrupts(irq); |
|
179 |
return oldValue; |
|
180 |
} |
|
181 |
||
182 |
EXPORT_C SCpuIdleHandler* NKern::CpuIdleHandler() |
|
183 |
{ |
|
184 |
return &ArmInterruptInfo.iCpuIdleHandler; |
|
185 |
} |
|
186 |
||
187 |
EXPORT_C TUint32 NKern::CpuTimeMeasFreq() |
|
188 |
{ |
|
189 |
#ifdef MONITOR_THREAD_CPU_TIME |
|
190 |
return NKern::FastCounterFrequency(); |
|
191 |
#else |
|
192 |
return 0; |
|
193 |
#endif |
|
194 |
} |