author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 31 Aug 2010 16:34:26 +0300 | |
branch | RCL_3 |
changeset 43 | c1f20ce4abcf |
parent 0 | a41df078684a |
child 44 | 3e88ff8f41d5 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 2007-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\nkernsmp\arm\ncutilf.cia |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
#include <e32cia.h> |
|
19 |
#include <arm.h> |
|
20 |
#include <arm_gic.h> |
|
21 |
#include <arm_tmr.h> |
|
22 |
||
23 |
||
24 |
__NAKED__ void Arm::GetUserSpAndLr(TAny*) |
|
25 |
{ |
|
26 |
asm("stmia r0, {r13, r14}^ "); |
|
27 |
asm("mov r0, r0"); // NOP needed between stm^ and banked register access |
|
28 |
__JUMP(, lr); |
|
29 |
} |
|
30 |
||
31 |
__NAKED__ void Arm::SetUserSpAndLr(TAny*) |
|
32 |
{ |
|
33 |
asm("ldmia r0, {r13, r14}^ "); |
|
34 |
asm("mov r0, r0"); // NOP needed between ldm^ and banked register access |
|
35 |
__JUMP(, lr); |
|
36 |
} |
|
37 |
||
38 |
__NAKED__ TUint32 Arm::Dacr() |
|
39 |
{ |
|
40 |
asm("mrc p15, 0, r0, c3, c0, 0 "); |
|
41 |
__JUMP(, lr); |
|
42 |
} |
|
43 |
||
44 |
__NAKED__ void Arm::SetDacr(TUint32) |
|
45 |
{ |
|
46 |
asm("mcr p15, 0, r0, c3, c0, 0 "); |
|
47 |
__INST_SYNC_BARRIER_Z__(r1); |
|
48 |
__JUMP(, lr); |
|
49 |
} |
|
50 |
||
51 |
__NAKED__ TUint32 Arm::ModifyDacr(TUint32, TUint32) |
|
52 |
{ |
|
53 |
asm("mrc p15, 0, r2, c3, c0, 0 "); |
|
54 |
asm("bic r2, r2, r0 "); |
|
55 |
asm("orr r2, r2, r1 "); |
|
56 |
asm("mcr p15, 0, r2, c3, c0, 0 "); |
|
57 |
__INST_SYNC_BARRIER_Z__(r3); |
|
58 |
asm("mov r0, r2 "); |
|
59 |
__JUMP(, lr); |
|
60 |
} |
|
61 |
||
62 |
__NAKED__ void Arm::SetCar(TUint32) |
|
63 |
{ |
|
64 |
SET_CAR(, r0); |
|
65 |
__JUMP(, lr); |
|
66 |
} |
|
67 |
||
68 |
||
69 |
||
70 |
/** Get the CPU's coprocessor access register value |
|
71 |
||
72 |
@return The value of the CAR, 0 if CPU doesn't have CAR |
|
73 |
||
74 |
@publishedPartner |
|
75 |
@released |
|
76 |
*/ |
|
77 |
EXPORT_C __NAKED__ TUint32 Arm::Car() |
|
78 |
{ |
|
79 |
GET_CAR(, r0); |
|
80 |
__JUMP(, lr); |
|
81 |
} |
|
82 |
||
83 |
||
84 |
||
85 |
/** Modify the CPU's coprocessor access register value |
|
86 |
Does nothing if CPU does not have CAR. |
|
87 |
||
88 |
@param aClearMask Mask of bits to clear (1 = clear this bit) |
|
89 |
@param aSetMask Mask of bits to set (1 = set this bit) |
|
90 |
@return The original value of the CAR, 0 if CPU doesn't have CAR |
|
91 |
||
92 |
@publishedPartner |
|
93 |
@released |
|
94 |
*/ |
|
95 |
EXPORT_C __NAKED__ TUint32 Arm::ModifyCar(TUint32 /*aClearMask*/, TUint32 /*aSetMask*/) |
|
96 |
{ |
|
97 |
GET_CAR(, r2); |
|
98 |
asm("bic r0, r2, r0 "); |
|
99 |
asm("orr r0, r0, r1 "); |
|
100 |
SET_CAR(, r0); |
|
101 |
asm("mov r0, r2 "); |
|
102 |
__JUMP(, lr); |
|
103 |
} |
|
104 |
||
105 |
||
106 |
#ifdef __CPU_HAS_VFP |
|
107 |
__NAKED__ void Arm::SetFpExc(TUint32) |
|
108 |
{ |
|
109 |
#if defined(__CPU_ARM1136__) && !defined(__CPU_ARM1136_ERRATUM_351912_FIXED) |
|
110 |
// If we are about to enable VFP, disable dynamic branch prediction |
|
111 |
// If we are about to disable VFP, enable dynamic branch prediction if return stack prediction is enabled |
|
112 |
asm("mrs r3, cpsr "); |
|
113 |
__ASM_CLI(); |
|
114 |
asm("mrc p15, 0, r1, c1, c0, 1 "); |
|
115 |
asm("tst r0, #%a0" : : "i" ((TInt)VFP_FPEXC_EN) ); |
|
116 |
asm("bic r1, r1, #2 "); // clear DB bit (disable dynamic prediction) |
|
117 |
asm("and r2, r1, #1 "); // r2 bit 0 = RS bit (1 if return stack enabled) |
|
118 |
asm("orreq r1, r1, r2, lsl #1 "); // if VFP is being disabled set DB = RS |
|
119 |
asm("mcr p15, 0, r1, c1, c0, 1 "); |
|
120 |
asm("mcr p15, 0, r2, c7, c5, 6 "); // flush BTAC |
|
121 |
VFP_FMXR(, VFP_XREG_FPEXC,0); |
|
122 |
__INST_SYNC_BARRIER_Z__(r12); |
|
123 |
asm("msr cpsr, r3 "); |
|
124 |
__JUMP(, lr); |
|
125 |
#else |
|
126 |
VFP_FMXR(, VFP_XREG_FPEXC,0); |
|
127 |
__JUMP(, lr); |
|
128 |
#endif |
|
129 |
} |
|
130 |
#endif |
|
131 |
||
132 |
||
133 |
||
134 |
/** Get the value of the VFP FPEXC register |
|
135 |
||
136 |
@return The value of FPEXC, 0 if there is no VFP |
|
137 |
||
138 |
@publishedPartner |
|
139 |
@released |
|
140 |
*/ |
|
141 |
EXPORT_C __NAKED__ TUint32 Arm::FpExc() |
|
142 |
{ |
|
143 |
#ifdef __CPU_HAS_VFP |
|
144 |
VFP_FMRX(, 0,VFP_XREG_FPEXC); |
|
145 |
#else |
|
146 |
asm("mov r0, #0 "); |
|
147 |
#endif |
|
148 |
__JUMP(, lr); |
|
149 |
} |
|
150 |
||
151 |
||
152 |
||
153 |
/** Modify the VFP FPEXC register |
|
154 |
Does nothing if there is no VFP |
|
155 |
||
156 |
@param aClearMask Mask of bits to clear (1 = clear this bit) |
|
157 |
@param aSetMask Mask of bits to set (1 = set this bit) |
|
158 |
@return The original value of FPEXC, 0 if no VFP present |
|
159 |
||
160 |
@publishedPartner |
|
161 |
@released |
|
162 |
*/ |
|
163 |
EXPORT_C __NAKED__ TUint32 Arm::ModifyFpExc(TUint32 /*aClearMask*/, TUint32 /*aSetMask*/) |
|
164 |
{ |
|
165 |
#ifdef __CPU_HAS_VFP |
|
166 |
VFP_FMRX(, 12,VFP_XREG_FPEXC); |
|
167 |
asm("bic r0, r12, r0 "); |
|
168 |
asm("orr r0, r0, r1 "); |
|
169 |
||
170 |
#if defined(__CPU_ARM1136__) && !defined(__CPU_ARM1136_ERRATUM_351912_FIXED) |
|
171 |
// If we are about to enable VFP, disable dynamic branch prediction |
|
172 |
// If we are about to disable VFP, enable dynamic branch prediction if return stack prediction is enabled |
|
173 |
asm("mrs r3, cpsr "); |
|
174 |
__ASM_CLI(); |
|
175 |
asm("mrc p15, 0, r1, c1, c0, 1 "); |
|
176 |
asm("tst r0, #%a0" : : "i" ((TInt)VFP_FPEXC_EN) ); |
|
177 |
asm("bic r1, r1, #2 "); // clear DB bit (disable dynamic prediction) |
|
178 |
asm("and r2, r1, #1 "); // r2 bit 0 = RS bit (1 if return stack enabled) |
|
179 |
asm("orreq r1, r1, r2, lsl #1 "); // if VFP is being disabled set DB = RS |
|
180 |
asm("mcr p15, 0, r1, c1, c0, 1 "); |
|
181 |
asm("mcr p15, 0, r2, c7, c5, 6 "); // flush BTAC |
|
182 |
VFP_FMXR(, VFP_XREG_FPEXC,0); |
|
183 |
__INST_SYNC_BARRIER_Z__(r12); |
|
184 |
asm("msr cpsr, r3 "); |
|
185 |
#else |
|
186 |
VFP_FMXR(, VFP_XREG_FPEXC,0); |
|
187 |
#endif // erratum 351912 |
|
188 |
||
189 |
asm("mov r0, r12 "); |
|
190 |
#else // no vfp |
|
191 |
asm("mov r0, #0 "); |
|
192 |
#endif |
|
193 |
__JUMP(, lr); |
|
194 |
} |
|
195 |
||
196 |
/** Get the value of the VFP FPSCR register |
|
197 |
||
198 |
@return The value of FPSCR, 0 if there is no VFP |
|
199 |
||
200 |
@publishedPartner |
|
201 |
@released |
|
202 |
*/ |
|
203 |
EXPORT_C __NAKED__ TUint32 Arm::FpScr() |
|
204 |
{ |
|
205 |
#ifdef __CPU_HAS_VFP |
|
206 |
VFP_FMRX(, 0,VFP_XREG_FPSCR); |
|
207 |
#else |
|
208 |
asm("mov r0, #0 "); |
|
209 |
#endif |
|
210 |
__JUMP(, lr); |
|
211 |
} |
|
212 |
||
213 |
||
214 |
||
215 |
/** Modify the VFP FPSCR register |
|
216 |
Does nothing if there is no VFP |
|
217 |
||
218 |
@param aClearMask Mask of bits to clear (1 = clear this bit) |
|
219 |
@param aSetMask Mask of bits to set (1 = set this bit) |
|
220 |
@return The original value of FPSCR, 0 if no VFP present |
|
221 |
||
222 |
@publishedPartner |
|
223 |
@released |
|
224 |
*/ |
|
225 |
EXPORT_C __NAKED__ TUint32 Arm::ModifyFpScr(TUint32 /*aClearMask*/, TUint32 /*aSetMask*/) |
|
226 |
{ |
|
227 |
#ifdef __CPU_HAS_VFP |
|
228 |
VFP_FMRX(, 2,VFP_XREG_FPSCR); |
|
229 |
asm("bic r0, r2, r0 "); |
|
230 |
asm("orr r0, r0, r1 "); |
|
231 |
VFP_FMXR(, VFP_XREG_FPSCR,0); |
|
232 |
asm("mov r0, r2 "); |
|
233 |
#else |
|
234 |
asm("mov r0, #0 "); |
|
235 |
#endif |
|
236 |
__JUMP(, lr); |
|
237 |
} |
|
238 |
||
239 |
||
240 |
/** Detect whether NEON is present |
|
241 |
||
242 |
@return ETrue if present, EFalse if not |
|
243 |
||
244 |
@internalTechnology |
|
245 |
@released |
|
246 |
*/ |
|
247 |
#if defined(__CPU_HAS_VFP) && defined(__VFP_V3) |
|
248 |
__NAKED__ TBool Arm::NeonPresent() |
|
249 |
{ |
|
250 |
asm("mov r0, #0 "); // Not present |
|
251 |
VFP_FMRX(, 1,VFP_XREG_FPEXC); // Save VFP state |
|
252 |
asm("orr r2, r1, #%a0" : : "i" ((TInt)VFP_FPEXC_EN)); |
|
253 |
VFP_FMXR(, VFP_XREG_FPEXC,1); // Enable VFP |
|
254 |
||
255 |
VFP_FMRX(, 2,VFP_XREG_MVFR0); // Read MVFR0 |
|
256 |
asm("tst r2, #%a0" : : "i" ((TInt)VFP_MVFR0_ASIMD32)); // Check to see if all 32 Advanced SIMD registers are present |
|
257 |
asm("beq 0f "); // Skip ahead if not |
|
258 |
GET_CAR(, r2); |
|
259 |
asm("tst r2, #%a0" : : "i" ((TInt)VFP_CPACR_ASEDIS)); // Check to see if ASIMD is disabled |
|
260 |
asm("bne 0f "); // Skip ahead if so |
|
261 |
asm("tst r2, #%a0" : : "i" ((TInt)VFP_CPACR_D32DIS)); // Check to see if the upper 16 registers are disabled |
|
262 |
asm("moveq r0, #1" ); // If not then eport NEON present |
|
263 |
||
264 |
asm("0: "); |
|
265 |
VFP_FMXR(,VFP_XREG_FPEXC,1); // Restore VFP state |
|
266 |
__JUMP(, lr); |
|
267 |
} |
|
268 |
#endif |
|
269 |
||
270 |
||
271 |
#ifdef __CPU_HAS_MMU |
|
272 |
__NAKED__ TBool Arm::MmuActive() |
|
273 |
{ |
|
274 |
asm("mrc p15, 0, r0, c1, c0, 0 "); |
|
275 |
asm("and r0, r0, #1 "); |
|
276 |
__JUMP(, lr); |
|
277 |
} |
|
278 |
||
279 |
// Returns the content of Translate Table Base Register 0. |
|
280 |
// To get physical address of the level 1 table, on some platforms this must be orred with 0xffff8000 (to get rid of table walk cache attributes) |
|
281 |
__NAKED__ TUint32 Arm::MmuTTBR0() |
|
282 |
{ |
|
283 |
asm("mrc p15, 0, r0, c2, c0, 0 "); |
|
284 |
__JUMP(, lr); |
|
285 |
} |
|
286 |
#endif |
|
287 |
||
288 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
289 |
#if defined(__NKERN_TIMESTAMP_USE_LOCAL_TIMER__) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
290 |
#error Use of local timer for NKern::Timestamp() no longer supported |
0 | 291 |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
292 |
#elif defined(__NKERN_TIMESTAMP_USE_SCU_GLOBAL_TIMER__) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
293 |
// Code to access global timer in Cortex A9 r1p0 |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
294 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
295 |
#ifndef __CPU_ARM_HAS_GLOBAL_TIMER_BLOCK |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
296 |
#error NKern::Timestamp() wants global timer, but global timer not present. |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
297 |
#endif |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
298 |
|
0 | 299 |
EXPORT_C __NAKED__ TUint64 NKern::Timestamp() |
300 |
{ |
|
301 |
asm("ldr r3, __TheScheduler "); |
|
302 |
asm("mrs r12, cpsr "); // r12 = saved interrupt mask |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
303 |
asm("stmfd sp!, {r4-r7} "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
304 |
asm("ldr r4, [r3, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGlobalTimerAddr)); // r4 points to global timer |
0 | 305 |
__ASM_CLI(); // disable all interrupts |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
306 |
asm("ldr r6, [r3, #%a0]" : : "i" _FOFF(TScheduler,iSX.iCount0)); // r6 = count value of last frequency change (low) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
307 |
asm("ldr r7, [r3, #%a0]" : : "i" (_FOFF(TScheduler,iSX.iCount0)+4)); // r7 = count value of last frequency change (high) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
308 |
asm("ldr r2, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountHigh)); // r2 = current timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
309 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
310 |
// To read 64 bit timer value, read high, low, high |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
311 |
// If two high values match -> OK, else repeat |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
312 |
asm("1: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
313 |
asm("mov r1, r2 "); // r1 = previous value of timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
314 |
asm("ldr r0, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountLow)); // r0 = current timer counter low word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
315 |
asm("ldr r2, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountHigh)); // r2 = current timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
316 |
asm("mov r5, r3 "); // r5 = &TheScheduler |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
317 |
asm("cmp r1, r2 "); // high word changed? |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
318 |
asm("bne 1b "); // if so, retry |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
319 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
320 |
// Now have R1:R0 = 64 bit global timer count |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
321 |
asm("ldr r3, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iM)); // r3 = period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
322 |
asm("ldrsh r4, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iX)); // r4 = period multiplier shift |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
323 |
asm("subs r6, r0, r6 "); // r7:r6 = ticks from last frequency change |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
324 |
asm("sbcs r7, r1, r7 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
325 |
asm("umull r0, r1, r6, r3 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
326 |
asm("mov r2, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
327 |
asm("umlal r1, r2, r7, r3 "); // r2:r1:r0 = delta * period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
328 |
asm("ldr r6, [r5, #%a0]!" : : "i" _FOFF(TScheduler,iSX.iTimestamp0)); // r6 = timestamp at last freq change (low) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
329 |
asm("ldr r7, [r5, #4] "); // r7 = timestamp at last freq change (high) |
0 | 330 |
asm("msr cpsr, r12 "); // restore interrupts |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
331 |
asm("rsb r4, r4, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
332 |
asm("rsb r3, r4, #32 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
333 |
asm("movs r0, r0, lsr r4 "); // rounding bit into C |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
334 |
asm("orr r0, r0, r1, lsl r3 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
335 |
asm("mov r1, r1, lsr r4 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
336 |
asm("orr r1, r1, r2, lsl r3 "); // r1:r0 = (delta * period multiplier) >> period multiplier shift |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
337 |
asm("adcs r0, r0, r6 "); // scaled delta + timestamp at last freq change |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
338 |
asm("adcs r1, r1, r7 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
339 |
asm("ldmfd sp!, {r4-r7} "); |
0 | 340 |
__JUMP(,lr); |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
341 |
|
0 | 342 |
asm("__TheScheduler: "); |
343 |
asm(".word %a0" : : "i" ((TInt)&TheScheduler)); |
|
344 |
} |
|
345 |
||
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
346 |
// Compensate for a change of frequency of the clocking driving the ARM Global Timer |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
347 |
// Call with interrupts disabled |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
348 |
__NAKED__ void ArmGlobalTimerFreqChg(const SRatioInv* /*aNewGTimerFreqRI*/) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
349 |
{ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
350 |
asm("ldr r3, __TheScheduler "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
351 |
asm("stmfd sp!, {r4-r7} "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
352 |
asm("ldr r4, [r3, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGlobalTimerAddr)); // r4 points to global timer |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
353 |
asm("ldr r6, [r3, #%a0]" : : "i" _FOFF(TScheduler,iSX.iCount0)); // r6 = count value of last frequency change (low) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
354 |
asm("ldr r7, [r3, #%a0]" : : "i" (_FOFF(TScheduler,iSX.iCount0)+4)); // r7 = count value of last frequency change (high) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
355 |
asm("ldr r12, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountHigh)); // r12 = current timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
356 |
asm("mov r5, r3 "); // r5 = &TheScheduler |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
357 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
358 |
// To read 64 bit timer value, read high, low, high |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
359 |
// If two high values match -> OK, else repeat |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
asm("1: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
361 |
asm("mov r3, r12 "); // r3 = previous value of timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
362 |
asm("ldr r2, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountLow)); // r0 = current timer counter low word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
363 |
asm("ldr r12, [r4, #%a0]" : : "i" _FOFF(ArmGlobalTimer,iTimerCountHigh)); // r12 = current timer counter high word |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
364 |
asm("cmp r3, r12 "); // high word changed? |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
365 |
asm("bne 1b "); // if so, retry |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
366 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
// Now have R3:R2 = 64 bit global timer count |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
asm("str r2, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iCount0)); // update count value at last frequency change |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
asm("str r3, [r5, #%a0]" : : "i" (_FOFF(TScheduler,iSX.iCount0)+4)); // to be equal to current count value |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
370 |
asm("subs r6, r2, r6 "); // r7:r6 = ticks (at old frequency) from last frequency change |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
asm("sbcs r7, r3, r7 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
asm("ldr r3, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iM)); // r3 = old period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
asm("ldrsh r4, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iX)); // r4 = old period multiplier shift |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
asm("ldmia r0, {r0,r1,r2,r12} "); // r1:r0=new frequency multiplier, r12:r2=new period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
asm("str r0, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iR.iM)); // update frequency multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
asm("str r1, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iR.iX)); // update frequency multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
asm("str r2, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iM)); // update period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
asm("str r12, [r5, #%a0]" : : "i" _FOFF(TScheduler,iSX.iGTimerFreqRI.iI.iX)); // update period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
asm("umull r0, r1, r6, r3 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
asm("mov r2, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
asm("umlal r1, r2, r7, r3 "); // r2:r1:r0 = delta * old period multiplier |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
asm("ldr r6, [r5, #%a0]!" : : "i" _FOFF(TScheduler,iSX.iTimestamp0)); // r6 = timestamp at last freq change (low) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
asm("ldr r7, [r5, #4] "); // r7 = timestamp at last freq change (high) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
384 |
asm("rsb r4, r4, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
asm("rsb r3, r4, #32 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
asm("movs r0, r0, lsr r4 "); // rounding bit into C |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
asm("orr r0, r0, r1, lsl r3 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
asm("mov r1, r1, lsr r4 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
asm("orr r1, r1, r2, lsl r3 "); // r1:r0 = (delta * old period multiplier) >> old period multiplier shift |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
asm("adcs r0, r0, r6 "); // scaled delta + timestamp at last freq change |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
asm("adcs r1, r1, r7 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
asm("stmia r5, {r0,r1} "); // timestamp at last freq change = now |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
__DATA_MEMORY_BARRIER_Z__(r12); /* Ensure all updates visible */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
asm("ldmfd sp!, {r4-r7} "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
__JUMP(,lr); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
} |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
397 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
#elif defined(__NKERN_TIMESTAMP_USE_INLINE_BSP_CODE__) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
#define __DEFINE_NKERN_TIMESTAMP_ASM__ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
#include <variant_timestamp.h> |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
#undef __DEFINE_NKERN_TIMESTAMP_ASM__ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
#elif defined(__NKERN_TIMESTAMP_USE_BSP_CALLOUT__) |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
// Code to call function defined in variant |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
#else |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
405 |
#error No definition for NKern::Timestamp() |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
406 |
#endif |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
407 |
|
0 | 408 |
|
409 |
extern "C" __NAKED__ TLinAddr get_sp_svc() |
|
410 |
{ |
|
411 |
asm("mrs r1, cpsr "); |
|
412 |
__ASM_CLI_MODE(MODE_SVC); |
|
413 |
asm("mov r0, sp "); |
|
414 |
asm("msr cpsr, r1 "); |
|
415 |
__JUMP(, lr); |
|
416 |
} |
|
417 |
||
418 |
extern "C" __NAKED__ TLinAddr get_lr_svc() |
|
419 |
{ |
|
420 |
asm("mrs r1, cpsr "); |
|
421 |
__ASM_CLI_MODE(MODE_SVC); |
|
422 |
asm("mov r0, lr "); |
|
423 |
asm("msr cpsr, r1 "); |
|
424 |
__JUMP(, lr); |
|
425 |
} |
|
426 |
||
427 |
||
428 |
/** Get the return address from an ISR |
|
429 |
||
430 |
Call only from an ISR |
|
431 |
||
432 |
@internalTechnology |
|
433 |
*/ |
|
434 |
EXPORT_C __NAKED__ TLinAddr Arm::IrqReturnAddress() |
|
435 |
{ |
|
436 |
asm("mrs r1, cpsr "); |
|
437 |
__ASM_CLI(); |
|
438 |
asm("and r0, r1, #0x1f "); |
|
439 |
asm("cmp r0, #0x11 "); // mode_fiq ? |
|
440 |
asm("beq 1f "); |
|
441 |
__ASM_CLI_MODE(MODE_SVC); |
|
442 |
asm("ldr r0, [sp, #%a0]" : : "i" _FOFF(SThreadExcStack,iR15)); |
|
443 |
asm("msr cpsr, r1 "); |
|
444 |
__JUMP(, lr); |
|
445 |
||
446 |
asm("1: "); |
|
447 |
GET_RWNO_TID(,r3); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
448 |
asm("ldr r2, [r3, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iFiqStackTop)); // if so, r2->top of FIQ stack |
0 | 449 |
asm("ldr r0, [r2, #-4] "); // get return address |
450 |
asm("msr cpsr, r1 "); |
|
451 |
__JUMP(, lr); |
|
452 |
} |
|
453 |
||
454 |
#if defined(__INCLUDE_SPIN_LOCK_CHECKS__) |
|
455 |
#define __ASM_CALL(func) \ |
|
456 |
asm("str lr, [sp, #-4]! "); \ |
|
457 |
asm("bl " CSM_CFUNC(func)); \ |
|
458 |
asm("ldr lr, [sp], #4 "); |
|
459 |
||
460 |
#define SPIN_LOCK_ENTRY_CHECK() __ASM_CALL(spin_lock_entry_check) |
|
461 |
#define SPIN_LOCK_MARK_ACQ() __ASM_CALL(spin_lock_mark_acq) |
|
462 |
#define SPIN_UNLOCK_ENTRY_CHECK() __ASM_CALL(spin_unlock_entry_check) |
|
463 |
||
464 |
#define RWSPIN_RLOCK_ENTRY_CHECK() __ASM_CALL(rwspin_rlock_entry_check) |
|
465 |
#define RWSPIN_RLOCK_MARK_ACQ() __ASM_CALL(rwspin_rlock_mark_acq) |
|
466 |
#define RWSPIN_RUNLOCK_ENTRY_CHECK() __ASM_CALL(rwspin_runlock_entry_check) |
|
467 |
||
468 |
#define RWSPIN_WLOCK_ENTRY_CHECK() __ASM_CALL(rwspin_wlock_entry_check) |
|
469 |
#define RWSPIN_WLOCK_MARK_ACQ() __ASM_CALL(rwspin_wlock_mark_acq) |
|
470 |
#define RWSPIN_WUNLOCK_ENTRY_CHECK() __ASM_CALL(rwspin_wunlock_entry_check) |
|
471 |
||
472 |
#else |
|
473 |
#define SPIN_LOCK_ENTRY_CHECK() |
|
474 |
#define SPIN_LOCK_MARK_ACQ() |
|
475 |
#define SPIN_UNLOCK_ENTRY_CHECK() |
|
476 |
||
477 |
#define RWSPIN_RLOCK_ENTRY_CHECK() |
|
478 |
#define RWSPIN_RLOCK_MARK_ACQ() |
|
479 |
#define RWSPIN_RUNLOCK_ENTRY_CHECK() |
|
480 |
||
481 |
#define RWSPIN_WLOCK_ENTRY_CHECK() |
|
482 |
#define RWSPIN_WLOCK_MARK_ACQ() |
|
483 |
#define RWSPIN_WUNLOCK_ENTRY_CHECK() |
|
484 |
||
485 |
#endif |
|
486 |
||
487 |
||
488 |
/****************************************************************************** |
|
489 |
* Spin locks |
|
490 |
* |
|
491 |
* [this+0] in count (byte) |
|
492 |
* [this+1] out count (byte) |
|
493 |
* [this+6] order (byte) |
|
494 |
* [this+7] holding CPU (byte) |
|
495 |
******************************************************************************/ |
|
496 |
||
497 |
#if defined(__INCLUDE_SPIN_LOCK_CHECKS__) |
|
498 |
extern "C" __NAKED__ void spin_lock_entry_check() |
|
499 |
{ |
|
500 |
/* R0 points to lock */ |
|
501 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
502 |
asm("mrs r12, cpsr "); |
|
503 |
__ASM_CLI(); |
|
504 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
505 |
asm("cmp r1, #0 "); |
|
506 |
asm("beq slec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
507 |
asm("ldrh r2, [r0, #6] "); /* R2[8:15]=holding CPU, R2[0:7]=order */ |
|
508 |
asm("tst r2, #0xE0 "); |
|
509 |
asm("bne slec_preemption "); /* This lock requires preemption to be disabled */ |
|
510 |
||
511 |
/* check interrupts disabled, if interrupts/preemption is not disabled |
|
512 |
there is a risk of same core deadlock occuring, hence this check and |
|
513 |
run-time assert to ensure code stays safe */ |
|
514 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
515 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
516 |
asm("beq slec_1 "); /* Yes - OK */ |
|
517 |
__ASM_CRASH(); /* No - die */ |
|
518 |
||
519 |
asm("slec_preemption: "); |
|
520 |
asm("and r3, r2, #0xFF "); |
|
521 |
asm("cmp r3, #0xFF "); /* check for EOrderNone */ |
|
522 |
asm("beq slec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
523 |
asm("and r3, r12, #0x1F "); |
|
524 |
asm("cmp r3, #0x13 "); /* Make sure we're in mode_svc */ |
|
525 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
526 |
asm("bne slec_preemption_die "); /* If not, die */ |
|
527 |
asm("cmp r3, #0 "); |
|
528 |
asm("bne slec_1 "); /* Preemption disabled - OK */ |
|
529 |
asm("slec_preemption_die: "); |
|
530 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
531 |
||
532 |
asm("slec_1: "); |
|
533 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
534 |
asm("cmp r3, r2, lsr #8 "); /* Test if held by current CPU */ |
|
535 |
asm("bne slec_2 "); /* Not already held by this CPU - OK */ |
|
536 |
__ASM_CRASH(); /* Already held by this CPU - die */ |
|
537 |
||
538 |
asm("slec_2: "); |
|
539 |
asm("ldr r3, [r1, #%a0]!" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
540 |
asm("ldr r1, [r1, #4] "); /* r3=low word of iSpinLockOrderCheck, r1=high word */ |
|
541 |
asm("cmp r3, #0 "); |
|
542 |
asm("addeq r2, r2, #0x20000000 "); /* if low word zero, add 32 to LS1 index ... */ |
|
543 |
asm("moveq r3, r1 "); /* ... and r3=high word ... */ |
|
544 |
asm("subs r1, r3, #1 "); /* R1 = R3 with all bits up to and including LS1 flipped */ |
|
545 |
asm("beq slec_ok "); /* If all bits zero, no locks held so OK */ |
|
546 |
asm("eor r3, r3, r1 "); /* Clear all bits above LS1 */ |
|
547 |
CLZ(1,3); /* R1 = 31 - bit number of LS1 */ |
|
548 |
asm("rsb r1, r1, #31 "); /* R1 = bit number of LS1 */ |
|
549 |
asm("add r1, r1, r2, lsr #24 "); /* add 32 if we were looking at high word */ |
|
550 |
asm("mov r2, r2, lsl #24 "); /* this lock's order value into R2 high byte */ |
|
551 |
asm("cmp r1, r2, asr #24 "); /* compare current lowest order lock to sign-extended order value */ |
|
552 |
asm("bgt slec_ok "); /* if this lock's order < current lowest, OK */ |
|
553 |
__ASM_CRASH(); /* otherwise die */ |
|
554 |
||
555 |
asm("slec_ok: "); |
|
556 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
557 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
558 |
__JUMP(,lr); |
|
559 |
} |
|
560 |
||
561 |
extern "C" __NAKED__ void spin_lock_mark_acq() |
|
562 |
{ |
|
563 |
/* R0 points to lock */ |
|
564 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
565 |
asm("mrs r12, cpsr "); |
|
566 |
__ASM_CLI(); |
|
567 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
568 |
asm("cmp r1, #0 "); |
|
569 |
asm("beq slma_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
570 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
571 |
asm("ldrb r2, [r0, #6] "); /* R2 = lock order value */ |
|
572 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
573 |
asm("strb r3, [r0, #7] "); /* set byte 7 to holding CPU number */ |
|
574 |
asm("cmp r2, #0x40 "); |
|
575 |
asm("bhs slma_ok "); /* if EOrderNone, done */ |
|
576 |
asm("cmp r2, #0x20 "); |
|
577 |
asm("addhs r1, r1, #4 "); |
|
578 |
asm("and r2, r2, #0x1f "); |
|
579 |
asm("mov r3, #1 "); |
|
580 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to set */ |
|
581 |
asm("ldr r2, [r1] "); |
|
582 |
asm("orr r2, r2, r3 "); |
|
583 |
asm("str r2, [r1] "); /* set bit in iSpinLockOrderCheck corresponding to lock order */ |
|
584 |
||
585 |
asm("slma_ok: "); |
|
586 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
587 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
588 |
__JUMP(,lr); |
|
589 |
} |
|
590 |
||
591 |
extern "C" __NAKED__ void spin_unlock_entry_check() |
|
592 |
{ |
|
593 |
/* R0 points to lock */ |
|
594 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
595 |
asm("mrs r12, cpsr "); |
|
596 |
__ASM_CLI(); |
|
597 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
598 |
asm("cmp r1, #0 "); |
|
599 |
asm("beq suec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
600 |
asm("ldrh r2, [r0, #6] "); /* R2[8:15]=holding CPU, R2[0:7]=order */ |
|
601 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
602 |
asm("eor r2, r2, r3, lsl #8 "); /* R2[8:15]=holding CPU^current CPU, R2[0:7]=order */ |
|
603 |
asm("tst r2, #0xE0 "); |
|
604 |
asm("bne suec_preemption "); /* This lock requires preemption to be disabled */ |
|
605 |
||
606 |
/* check interrupts disabled */ |
|
607 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
608 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
609 |
asm("beq suec_1 "); /* Yes - OK */ |
|
610 |
__ASM_CRASH(); /* No - die */ |
|
611 |
||
612 |
asm("suec_preemption: "); |
|
613 |
asm("and r3, r2, #0xFF "); |
|
614 |
asm("cmp r3, #0xFF "); /* check for EOrderNone */ |
|
615 |
asm("ldrne r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
616 |
asm("beq suec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
617 |
asm("cmp r3, #0 "); |
|
618 |
asm("bne suec_1 "); /* Preemption disabled - OK */ |
|
619 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
620 |
||
621 |
asm("suec_1: "); |
|
622 |
asm("tst r2, #0xFF00 "); /* Check if holding CPU ^ current CPU number == 0 */ |
|
623 |
asm("beq suec_2 "); /* Held by this CPU - OK */ |
|
624 |
__ASM_CRASH(); /* Not held by this CPU - die */ |
|
625 |
||
626 |
asm("suec_2: "); |
|
627 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
628 |
asm("mov r3, #0xFF "); |
|
629 |
asm("strb r3, [r0, #7] "); /* reset holding CPU */ |
|
630 |
asm("cmp r2, #0x40 "); |
|
631 |
asm("bhs suec_ok "); /* if EOrderNone, done */ |
|
632 |
asm("cmp r2, #0x20 "); |
|
633 |
asm("addhs r1, r1, #4 "); |
|
634 |
asm("and r2, r2, #0x1F "); |
|
635 |
asm("mov r3, #1 "); |
|
636 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to clear */ |
|
637 |
asm("ldr r2, [r1] "); |
|
638 |
asm("tst r2, r3 "); /* test bit originally set */ |
|
639 |
asm("bic r2, r2, r3 "); |
|
640 |
asm("str r2, [r1] "); /* clear bit in iSpinLockOrderCheck corresponding to lock order */ |
|
641 |
asm("bne suec_ok "); /* if originally set, OK */ |
|
642 |
__ASM_CRASH(); /* if not, die - something must have got corrupted */ |
|
643 |
||
644 |
asm("suec_ok: "); |
|
645 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
646 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
647 |
__JUMP(,lr); |
|
648 |
} |
|
649 |
#endif |
|
650 |
||
651 |
||
652 |
/****************************************************************************** |
|
653 |
* Plain old spin lock |
|
654 |
* |
|
655 |
* Fundamental algorithm: |
|
656 |
* lock() { old_in = in++; while(out!=old_in) __chill(); } |
|
657 |
* unlock() { ++out; } |
|
658 |
* |
|
659 |
* [this+0] out count (byte) |
|
660 |
* [this+1] in count (byte) |
|
661 |
* |
|
662 |
******************************************************************************/ |
|
663 |
__NAKED__ EXPORT_C void TSpinLock::LockIrq() |
|
664 |
{ |
|
665 |
__ASM_CLI(); /* Disable interrupts */ |
|
666 |
SPIN_LOCK_ENTRY_CHECK() |
|
667 |
asm("1: "); |
|
668 |
LDREXH(1,0); |
|
669 |
asm("mov r2, r1, lsr #8 "); /* R2 = original in count */ |
|
670 |
asm("add r1, r1, #0x100 "); |
|
671 |
STREXH(3,1,0); |
|
672 |
asm("cmp r3, #0 "); |
|
673 |
asm("bne 1b "); |
|
674 |
asm("and r1, r1, #0xFF "); /* R1 = out count */ |
|
675 |
asm("3: "); |
|
676 |
asm("cmp r2, r1 "); /* out = original in ? */ |
|
677 |
asm("bne 2f "); /* no - must wait */ |
|
678 |
SPIN_LOCK_MARK_ACQ() |
|
679 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
680 |
__JUMP(,lr); |
|
681 |
||
682 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
asm("ldr r1, __CrashState "); |
0 | 684 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
asm("ldrb r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 692 |
} |
693 |
||
694 |
__NAKED__ EXPORT_C void TSpinLock::UnlockIrq() |
|
695 |
{ |
|
696 |
SPIN_UNLOCK_ENTRY_CHECK() |
|
697 |
__DATA_MEMORY_BARRIER_Z__(r1); /* Ensure accesses don't move outside locked section */ |
|
698 |
asm("ldrb r2, [r0, #0] "); |
|
699 |
asm("add r2, r2, #1 "); |
|
700 |
asm("strb r2, [r0, #0] "); /* ++out */ |
|
701 |
__DATA_SYNC_BARRIER__(r1); /* Ensure write to out completes before SEV */ |
|
702 |
ARM_SEV; /* Wake up any waiting processors */ |
|
703 |
__ASM_STI(); /* Enable interrupts */ |
|
704 |
__JUMP(,lr); |
|
705 |
} |
|
706 |
||
707 |
__NAKED__ EXPORT_C TBool TSpinLock::FlashIrq() |
|
708 |
{ |
|
709 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
710 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 711 |
asm("ldrh r1, [r0, #0] "); |
712 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
713 |
asm("sub r1, r1, r1, lsr #8 "); /* r1 low byte = (out - in) mod 256 */ |
|
714 |
asm("and r1, r1, #0xFF "); |
|
715 |
asm("cmp r1, #0xFF "); /* if out - in = -1, no-one else waiting */ |
|
716 |
asm("addeq r3, r3, #1 "); |
|
717 |
asm("cmpeq r3, #1024 "); /* if no-one waiting for lock, check for pending interrupt */ |
|
718 |
asm("bne 1f "); /* branch if someone else waiting */ |
|
719 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
720 |
__JUMP(,lr); |
|
721 |
||
722 |
asm("1: "); |
|
723 |
asm("str lr, [sp, #-4]! "); |
|
724 |
asm("bl " CSM_ZN9TSpinLock9UnlockIrqEv); |
|
725 |
asm("bl " CSM_ZN9TSpinLock7LockIrqEv); |
|
726 |
asm("mov r0, #1 "); |
|
727 |
asm("ldr pc, [sp], #4 "); |
|
728 |
} |
|
729 |
||
730 |
||
731 |
__NAKED__ EXPORT_C void TSpinLock::LockOnly() |
|
732 |
{ |
|
733 |
SPIN_LOCK_ENTRY_CHECK() |
|
734 |
asm("1: "); |
|
735 |
LDREXH(1,0); |
|
736 |
asm("mov r2, r1, lsr #8 "); /* R2 = original in count */ |
|
737 |
asm("add r1, r1, #0x100 "); |
|
738 |
STREXH(3,1,0); |
|
739 |
asm("cmp r3, #0 "); |
|
740 |
asm("bne 1b "); |
|
741 |
asm("and r1, r1, #0xFF "); /* R1 = out count */ |
|
742 |
asm("3: "); |
|
743 |
asm("cmp r2, r1 "); /* out = original in ? */ |
|
744 |
asm("bne 2f "); /* no - must wait */ |
|
745 |
SPIN_LOCK_MARK_ACQ() |
|
746 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
747 |
__JUMP(,lr); |
|
748 |
||
749 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
750 |
asm("ldr r1, __CrashState "); |
0 | 751 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
752 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
asm("ldrb r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
758 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 759 |
} |
760 |
||
761 |
__NAKED__ EXPORT_C void TSpinLock::UnlockOnly() |
|
762 |
{ |
|
763 |
SPIN_UNLOCK_ENTRY_CHECK() |
|
764 |
__DATA_MEMORY_BARRIER_Z__(r1); /* Ensure accesses don't move outside locked section */ |
|
765 |
asm("ldrb r2, [r0, #0] "); |
|
766 |
asm("add r2, r2, #1 "); |
|
767 |
asm("strb r2, [r0, #0] "); /* ++out */ |
|
768 |
__DATA_SYNC_BARRIER__(r1); /* Ensure write to out completes before SEV */ |
|
769 |
ARM_SEV; /* Wake up any waiting processors */ |
|
770 |
__JUMP(,lr); |
|
771 |
} |
|
772 |
||
773 |
__NAKED__ EXPORT_C TBool TSpinLock::FlashOnly() |
|
774 |
{ |
|
775 |
asm("ldrh r1, [r0, #0] "); |
|
776 |
asm("sub r1, r1, r1, lsr #8 "); /* r1 low byte = (out - in) mod 256 */ |
|
777 |
asm("and r1, r1, #0xFF "); |
|
778 |
asm("cmp r1, #0xFF "); /* if out - in = -1, no-one else waiting */ |
|
779 |
asm("bne 1f "); /* branch if someone else waiting */ |
|
780 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
781 |
__JUMP(,lr); |
|
782 |
||
783 |
asm("1: "); |
|
784 |
asm("str lr, [sp, #-4]! "); |
|
785 |
asm("bl " CSM_ZN9TSpinLock10UnlockOnlyEv); |
|
786 |
asm("bl " CSM_ZN9TSpinLock8LockOnlyEv); |
|
787 |
asm("mov r0, #1 "); |
|
788 |
asm("ldr pc, [sp], #4 "); |
|
789 |
} |
|
790 |
||
791 |
||
792 |
__NAKED__ EXPORT_C TInt TSpinLock::LockIrqSave() |
|
793 |
{ |
|
794 |
asm("mrs r12, cpsr "); |
|
795 |
__ASM_CLI(); /* Disable interrupts */ |
|
796 |
SPIN_LOCK_ENTRY_CHECK() |
|
797 |
asm("1: "); |
|
798 |
LDREXH(1,0); |
|
799 |
asm("mov r2, r1, lsr #8 "); /* R2 = original in count */ |
|
800 |
asm("add r1, r1, #0x100 "); |
|
801 |
STREXH(3,1,0); |
|
802 |
asm("cmp r3, #0 "); |
|
803 |
asm("bne 1b "); |
|
804 |
asm("and r1, r1, #0xFF "); /* R1 = out count */ |
|
805 |
asm("3: "); |
|
806 |
asm("cmp r2, r1 "); /* out = original in ? */ |
|
807 |
asm("bne 2f "); /* no - must wait */ |
|
808 |
SPIN_LOCK_MARK_ACQ() |
|
809 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
810 |
asm("and r0, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* return original CPSR I and F bits */ |
|
811 |
__JUMP(,lr); |
|
812 |
||
813 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
814 |
asm("ldr r1, __CrashState "); |
0 | 815 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
816 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
817 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
818 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
819 |
asm("ldrb r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
820 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
821 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 823 |
} |
824 |
||
825 |
__NAKED__ EXPORT_C void TSpinLock::UnlockIrqRestore(TInt) |
|
826 |
{ |
|
827 |
SPIN_UNLOCK_ENTRY_CHECK() |
|
828 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
829 |
asm("ldrb r2, [r0, #0] "); |
|
830 |
asm("mrs r12, cpsr "); |
|
831 |
asm("add r2, r2, #1 "); |
|
832 |
asm("bic r12, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
833 |
asm("strb r2, [r0, #0] "); /* ++out */ |
|
834 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out completes before SEV */ |
|
835 |
ARM_SEV; /* Wake up any waiting processors */ |
|
836 |
asm("orr r1, r1, r12 "); |
|
837 |
asm("msr cpsr, r1 "); /* restore interrupts */ |
|
838 |
__JUMP(,lr); |
|
839 |
} |
|
840 |
||
841 |
__NAKED__ EXPORT_C TBool TSpinLock::FlashIrqRestore(TInt) |
|
842 |
{ |
|
843 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
844 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 845 |
asm("ldrh r2, [r0, #0] "); |
846 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
847 |
asm("sub r2, r2, r2, lsr #8 "); /* r2 low byte = (out - in) mod 256 */ |
|
848 |
asm("and r2, r2, #0xFF "); |
|
849 |
asm("cmp r2, #0xFF "); /* if out - in = -1, no-one else waiting */ |
|
850 |
asm("addeq r3, r3, #1 "); |
|
851 |
asm("cmpeq r3, #1024 "); /* if no-one waiting for lock, check for pending interrupt */ |
|
852 |
asm("bne 1f "); /* branch if someone else waiting */ |
|
853 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
854 |
__JUMP(,lr); |
|
855 |
||
856 |
asm("1: "); |
|
857 |
asm("str lr, [sp, #-4]! "); |
|
858 |
asm("bl " CSM_ZN9TSpinLock16UnlockIrqRestoreEi); |
|
859 |
asm("bl " CSM_ZN9TSpinLock7LockIrqEv); |
|
860 |
asm("mov r0, #1 "); |
|
861 |
asm("ldr pc, [sp], #4 "); |
|
862 |
} |
|
863 |
||
864 |
||
865 |
__NAKED__ EXPORT_C TBool TSpinLock::FlashPreempt() |
|
866 |
{ |
|
867 |
asm("ldrh r2, [r0, #0] "); |
|
868 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
869 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iRescheduleNeededFlag)); |
|
870 |
asm("sub r2, r2, r2, lsr #8 "); /* r2 low byte = (out - in) mod 256 */ |
|
871 |
asm("and r2, r2, #0xFF "); |
|
872 |
asm("cmp r2, #0xFF "); /* if out - in = -1, no-one else waiting */ |
|
873 |
asm("cmpeq r3, #0 "); /* if no-one else waiting, check if reschedule or IDFCs pending */ |
|
874 |
asm("bne 1f "); /* if so or someone else waiting, branch to release lock */ |
|
875 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
876 |
__JUMP(,lr); |
|
877 |
||
878 |
asm("1: "); |
|
879 |
asm("stmfd sp!, {r0,lr} "); |
|
880 |
asm("bl " CSM_ZN9TSpinLock10UnlockOnlyEv); |
|
881 |
asm("bl " CSM_ZN5NKern15PreemptionPointEv); |
|
882 |
asm("ldr r0, [sp], #4 "); |
|
883 |
asm("bl " CSM_ZN9TSpinLock8LockOnlyEv); |
|
884 |
asm("mov r0, #1 "); |
|
885 |
asm("ldr pc, [sp], #4 "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
886 |
|
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
887 |
asm("__CrashState: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
888 |
asm(".word %a0" : : "i" ((TInt)&CrashState)); |
0 | 889 |
} |
890 |
||
891 |
||
892 |
/****************************************************************************** |
|
893 |
* Read/Write Spin lock |
|
894 |
* |
|
895 |
* Structure ( (in.r,in.w) , (out.r,out.w) ) |
|
896 |
* Fundamental algorithm: |
|
897 |
* lockr() { old_in = (in.r++,in.w); while(out.w!=old_in.w) __chill(); } |
|
898 |
* unlockr() { ++out.r; } |
|
899 |
* lockw() { old_in = (in.r,in.w++); while(out!=old_in) __chill(); } |
|
900 |
* unlockw() { ++out.w; } |
|
901 |
* |
|
902 |
* [this+0] in.w |
|
903 |
* [this+1] in.r |
|
904 |
* [this+2] out.w |
|
905 |
* [this+3] out.r |
|
906 |
* [this+4] Bit mask of CPUs which hold read locks |
|
907 |
* [this+6] order value |
|
908 |
* [this+7] CPU number which holds write lock, 0xFF if none |
|
909 |
* |
|
910 |
******************************************************************************/ |
|
911 |
||
912 |
#if defined(__INCLUDE_SPIN_LOCK_CHECKS__) |
|
913 |
extern "C" __NAKED__ void rwspin_rlock_entry_check() |
|
914 |
{ |
|
915 |
/* R0 points to lock */ |
|
916 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
917 |
asm("mrs r12, cpsr "); |
|
918 |
__ASM_CLI(); /* Disable interrupts */ |
|
919 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
920 |
asm("cmp r1, #0 "); |
|
921 |
asm("beq rwrlec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
922 |
asm("ldr r2, [r0, #4] "); /* R2[24:31]=wcpu, R2[16:23]=order, R2[0:7]=rcpu mask */ |
|
923 |
asm("tst r2, #0x00E00000 "); |
|
924 |
asm("bne rwrlec_preemption "); /* This lock requires preemption to be disabled */ |
|
925 |
||
926 |
/* check interrupts disabled */ |
|
927 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
928 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
929 |
asm("beq rwrlec_1 "); /* Yes - OK */ |
|
930 |
__ASM_CRASH(); /* No - die */ |
|
931 |
||
932 |
asm("rwrlec_preemption: "); |
|
933 |
asm("and r3, r2, #0x00FF0000 "); |
|
934 |
asm("cmp r3, #0x00FF0000 "); /* check for EOrderNone */ |
|
935 |
asm("beq rwrlec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
936 |
asm("and r3, r12, #0x1F "); |
|
937 |
asm("cmp r3, #0x13 "); /* Make sure we're in mode_svc */ |
|
938 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
939 |
asm("bne rwrlec_preemption_die "); /* If not, die */ |
|
940 |
asm("cmp r3, #0 "); |
|
941 |
asm("bne rwrlec_1 "); /* Preemption disabled - OK */ |
|
942 |
asm("rwrlec_preemption_die: "); |
|
943 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
944 |
||
945 |
asm("rwrlec_1: "); |
|
946 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
947 |
asm("eor r3, r2, r3, lsl #24 "); |
|
948 |
asm("cmp r3, #0x01000000 "); /* Held by current CPU for write ? */ |
|
949 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask)); |
|
950 |
asm("bhs rwrlec_2 "); /* No - OK */ |
|
951 |
__ASM_CRASH(); /* Already held by this CPU for write - die */ |
|
952 |
||
953 |
asm("rwrlec_2: "); |
|
954 |
asm("tst r2, r3 "); /* Held by current CPU for read ? */ |
|
955 |
asm("beq rwrlec_3 "); /* No - OK */ |
|
956 |
__ASM_CRASH(); /* Already held by this CPU for read - die */ |
|
957 |
||
958 |
asm("rwrlec_3: "); |
|
959 |
asm("ldr r3, [r1, #%a0]!" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
960 |
asm("mov r2, r2, lsr #16 "); |
|
961 |
asm("and r2, r2, #0xFF "); /* r2 = lock order */ |
|
962 |
asm("ldr r1, [r1, #4] "); /* r3=low word of iSpinLockOrderCheck, r1=high word */ |
|
963 |
asm("cmp r3, #0 "); |
|
964 |
asm("addeq r2, r2, #0x20000000 "); /* if low word zero, add 32 to LS1 index ... */ |
|
965 |
asm("moveq r3, r1 "); /* ... and r3=high word ... */ |
|
966 |
asm("subs r1, r3, #1 "); /* R1 = R3 with all bits up to and including LS1 flipped */ |
|
967 |
asm("beq rwrlec_ok "); /* If all bits zero, no locks held so OK */ |
|
968 |
asm("eor r3, r3, r1 "); /* Clear all bits above LS1 */ |
|
969 |
CLZ(1,3); /* R1 = 31 - bit number of LS1 */ |
|
970 |
asm("rsb r1, r1, #31 "); /* R1 = bit number of LS1 */ |
|
971 |
asm("add r1, r1, r2, lsr #24 "); /* add 32 if we were looking at high word */ |
|
972 |
asm("mov r2, r2, lsl #24 "); /* this lock's order value into R2 high byte */ |
|
973 |
asm("cmp r1, r2, asr #24 "); /* compare current lowest order lock to sign-extended order value */ |
|
974 |
asm("bgt rwrlec_ok "); /* if this lock's order < current lowest, OK */ |
|
975 |
__ASM_CRASH(); /* otherwise die */ |
|
976 |
||
977 |
asm("rwrlec_ok: "); |
|
978 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
979 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
980 |
__JUMP(,lr); |
|
981 |
} |
|
982 |
||
983 |
extern "C" __NAKED__ void rwspin_rlock_mark_acq() |
|
984 |
{ |
|
985 |
/* R0 points to lock */ |
|
986 |
asm("stmfd sp!, {r1-r4,r12} "); |
|
987 |
asm("mrs r12, cpsr "); |
|
988 |
__ASM_CLI(); /* Disable interrupts */ |
|
989 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
990 |
asm("cmp r1, #0 "); |
|
991 |
asm("beq rwrlma_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
992 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask)); |
|
993 |
asm("add r0, r0, #4 "); |
|
994 |
asm("1: "); |
|
995 |
LDREXB(2,0); /* rcpu mask */ |
|
996 |
asm("orr r2, r2, r3 "); /* set bit corresponding to current CPU */ |
|
997 |
STREXB(4,2,0); |
|
998 |
asm("cmp r4, #0 "); |
|
999 |
asm("bne 1b "); |
|
1000 |
asm("ldrb r2, [r0, #2] "); /* R2 = lock order value */ |
|
1001 |
asm("sub r0, r0, #4 "); |
|
1002 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
1003 |
asm("cmp r2, #0x40 "); |
|
1004 |
asm("bhs rwrlma_ok "); /* if EOrderNone, done */ |
|
1005 |
asm("cmp r2, #0x20 "); |
|
1006 |
asm("addhs r1, r1, #4 "); |
|
1007 |
asm("and r2, r2, #0x1f "); |
|
1008 |
asm("mov r3, #1 "); |
|
1009 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to set */ |
|
1010 |
asm("ldr r2, [r1] "); |
|
1011 |
asm("orr r2, r2, r3 "); |
|
1012 |
asm("str r2, [r1] "); /* set bit in iSpinLockOrderCheck corresponding to lock order */ |
|
1013 |
||
1014 |
asm("rwrlma_ok: "); |
|
1015 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
1016 |
asm("ldmfd sp!, {r1-r4,r12} "); |
|
1017 |
__JUMP(,lr); |
|
1018 |
} |
|
1019 |
||
1020 |
extern "C" __NAKED__ void rwspin_runlock_entry_check() |
|
1021 |
{ |
|
1022 |
/* R0 points to lock */ |
|
1023 |
asm("stmfd sp!, {r1-r4,r12} "); |
|
1024 |
asm("mrs r12, cpsr "); |
|
1025 |
__ASM_CLI(); /* Disable interrupts */ |
|
1026 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
1027 |
asm("cmp r1, #0 "); |
|
1028 |
asm("beq rwruec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
1029 |
asm("ldr r2, [r0, #4] "); /* R2[24:31]=wcpu, R2[16:23]=order, R2[0:7]=rcpu mask */ |
|
1030 |
asm("tst r2, #0x00E00000 "); |
|
1031 |
asm("bne rwruec_preemption "); /* This lock requires preemption to be disabled */ |
|
1032 |
||
1033 |
/* check interrupts disabled */ |
|
1034 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
1035 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
1036 |
asm("beq rwruec_1 "); /* Yes - OK */ |
|
1037 |
__ASM_CRASH(); /* No - die */ |
|
1038 |
||
1039 |
asm("rwruec_preemption: "); |
|
1040 |
asm("and r3, r2, #0x00FF0000 "); |
|
1041 |
asm("cmp r3, #0x00FF0000 "); /* check for EOrderNone */ |
|
1042 |
asm("ldrne r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
1043 |
asm("beq rwruec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
1044 |
asm("cmp r3, #0 "); |
|
1045 |
asm("bne rwruec_1 "); /* Preemption disabled - OK */ |
|
1046 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
1047 |
||
1048 |
asm("rwruec_1: "); |
|
1049 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask)); |
|
1050 |
asm("tst r2, r3 "); /* Check if current CPU holds read lock */ |
|
1051 |
asm("bne rwruec_2 "); /* Read lock held by this CPU - OK */ |
|
1052 |
__ASM_CRASH(); /* Not held by this CPU - die */ |
|
1053 |
||
1054 |
asm("rwruec_2: "); |
|
1055 |
asm("add r0, r0, #4 "); |
|
1056 |
asm("1: "); |
|
1057 |
LDREX(2,0); /* rcpu mask */ |
|
1058 |
asm("bic r2, r2, r3 "); /* clear bit corresponding to current CPU */ |
|
1059 |
STREX(4,2,0); |
|
1060 |
asm("cmp r4, #0 "); |
|
1061 |
asm("bne 1b "); |
|
1062 |
asm("sub r0, r0, #4 "); |
|
1063 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
1064 |
asm("tst r2, #0x00C00000 "); |
|
1065 |
asm("bne rwruec_ok "); /* if EOrderNone, done */ |
|
1066 |
asm("tst r2, #0x00200000 "); |
|
1067 |
asm("addne r1, r1, #4 "); |
|
1068 |
asm("mov r2, r2, lsr #16 "); |
|
1069 |
asm("and r2, r2, #0x1F "); |
|
1070 |
asm("mov r3, #1 "); |
|
1071 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to clear */ |
|
1072 |
asm("ldr r2, [r1] "); |
|
1073 |
asm("tst r2, r3 "); /* test bit originally set */ |
|
1074 |
asm("bic r2, r2, r3 "); |
|
1075 |
asm("str r2, [r1] "); /* clear bit in iSpinLockOrderCheck corresponding to lock order */ |
|
1076 |
asm("bne rwruec_ok "); /* if originally set, OK */ |
|
1077 |
__ASM_CRASH(); /* if not, die - something must have got corrupted */ |
|
1078 |
||
1079 |
asm("rwruec_ok: "); |
|
1080 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
1081 |
asm("ldmfd sp!, {r1-r4,r12} "); |
|
1082 |
__JUMP(,lr); |
|
1083 |
} |
|
1084 |
||
1085 |
||
1086 |
extern "C" __NAKED__ void rwspin_wlock_entry_check() |
|
1087 |
{ |
|
1088 |
/* R0 points to lock */ |
|
1089 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
1090 |
asm("mrs r12, cpsr "); |
|
1091 |
__ASM_CLI(); /* Disable interrupts */ |
|
1092 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
1093 |
asm("cmp r1, #0 "); |
|
1094 |
asm("beq rwwlec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
1095 |
asm("ldr r2, [r0, #4] "); /* R2[24:31]=wcpu, R2[16:23]=order, R2[0:7]=rcpu mask */ |
|
1096 |
asm("tst r2, #0x00E00000 "); |
|
1097 |
asm("bne rwwlec_preemption "); /* This lock requires preemption to be disabled */ |
|
1098 |
||
1099 |
/* check interrupts disabled */ |
|
1100 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
1101 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
1102 |
asm("beq rwwlec_1 "); /* Yes - OK */ |
|
1103 |
__ASM_CRASH(); /* No - die */ |
|
1104 |
||
1105 |
asm("rwwlec_preemption: "); |
|
1106 |
asm("and r3, r2, #0x00FF0000 "); |
|
1107 |
asm("cmp r3, #0x00FF0000 "); /* check for EOrderNone */ |
|
1108 |
asm("beq rwwlec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
1109 |
asm("and r3, r12, #0x1F "); |
|
1110 |
asm("cmp r3, #0x13 "); /* Make sure we're in mode_svc */ |
|
1111 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
1112 |
asm("bne rwwlec_preemption_die "); /* If not, die */ |
|
1113 |
asm("cmp r3, #0 "); |
|
1114 |
asm("bne rwwlec_1 "); /* Preemption disabled - OK */ |
|
1115 |
asm("rwwlec_preemption_die: "); |
|
1116 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
1117 |
||
1118 |
asm("rwwlec_1: "); |
|
1119 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuMask)); |
|
1120 |
asm("tst r2, r3 "); /* Test if held by current CPU for read */ |
|
1121 |
asm("beq rwwlec_2 "); /* No - OK */ |
|
1122 |
__ASM_CRASH(); /* Yes - die */ |
|
1123 |
||
1124 |
asm("rwwlec_2: "); |
|
1125 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
1126 |
asm("cmp r3, r2, lsr #24 "); /* Test if held by current CPU for write */ |
|
1127 |
asm("bne rwwlec_3 "); /* No - OK */ |
|
1128 |
__ASM_CRASH(); /* Yes - die */ |
|
1129 |
||
1130 |
asm("rwwlec_3: "); |
|
1131 |
asm("ldr r3, [r1, #%a0]!" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
1132 |
asm("mov r2, r2, lsr #16 "); |
|
1133 |
asm("and r2, r2, #0xFF "); /* r2 = lock order */ |
|
1134 |
asm("ldr r1, [r1, #4] "); /* r3=low word of iSpinLockOrderCheck, r1=high word */ |
|
1135 |
asm("cmp r3, #0 "); |
|
1136 |
asm("addeq r2, r2, #0x20000000 "); /* if low word zero, add 32 to LS1 index ... */ |
|
1137 |
asm("moveq r3, r1 "); /* ... and r3=high word ... */ |
|
1138 |
asm("subs r1, r3, #1 "); /* R1 = R3 with all bits up to and including LS1 flipped */ |
|
1139 |
asm("beq rwwlec_ok "); /* If all bits zero, no locks held so OK */ |
|
1140 |
asm("eor r3, r3, r1 "); /* Clear all bits above LS1 */ |
|
1141 |
CLZ(1,3); /* R1 = 31 - bit number of LS1 */ |
|
1142 |
asm("rsb r1, r1, #31 "); /* R1 = bit number of LS1 */ |
|
1143 |
asm("add r1, r1, r2, lsr #24 "); /* add 32 if we were looking at high word */ |
|
1144 |
asm("mov r2, r2, lsl #24 "); /* this lock's order value into R2 high byte */ |
|
1145 |
asm("cmp r1, r2, asr #24 "); /* compare current lowest order lock to sign-extended order value */ |
|
1146 |
asm("bgt rwwlec_ok "); /* if this lock's order < current lowest, OK */ |
|
1147 |
__ASM_CRASH(); /* otherwise die */ |
|
1148 |
||
1149 |
asm("rwwlec_ok: "); |
|
1150 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
1151 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
1152 |
__JUMP(,lr); |
|
1153 |
} |
|
1154 |
||
1155 |
extern "C" __NAKED__ void rwspin_wlock_mark_acq() |
|
1156 |
{ |
|
1157 |
/* R0 points to lock */ |
|
1158 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
1159 |
asm("mrs r12, cpsr "); |
|
1160 |
__ASM_CLI(); /* Disable interrupts */ |
|
1161 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
1162 |
asm("cmp r1, #0 "); |
|
1163 |
asm("beq rwwlma_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
1164 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
1165 |
asm("ldrb r2, [r0, #6] "); /* R2 = lock order value */ |
|
1166 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
1167 |
asm("strb r3, [r0, #7] "); /* set byte 7 to holding CPU number */ |
|
1168 |
asm("cmp r2, #0x40 "); |
|
1169 |
asm("bhs rwwlma_ok "); /* if EOrderNone, done */ |
|
1170 |
asm("cmp r2, #0x20 "); |
|
1171 |
asm("addhs r1, r1, #4 "); |
|
1172 |
asm("and r2, r2, #0x1f "); |
|
1173 |
asm("mov r3, #1 "); |
|
1174 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to set */ |
|
1175 |
asm("ldr r2, [r1] "); |
|
1176 |
asm("orr r2, r2, r3 "); |
|
1177 |
asm("str r2, [r1] "); /* set bit in iSpinLockOrderCheck corresponding to lock order */ |
|
1178 |
||
1179 |
asm("rwwlma_ok: "); |
|
1180 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
1181 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
1182 |
__JUMP(,lr); |
|
1183 |
} |
|
1184 |
||
1185 |
extern "C" __NAKED__ void rwspin_wunlock_entry_check() |
|
1186 |
{ |
|
1187 |
/* R0 points to lock */ |
|
1188 |
asm("stmfd sp!, {r1,r2,r3,r12} "); |
|
1189 |
asm("mrs r12, cpsr "); |
|
1190 |
__ASM_CLI(); /* Disable interrupts */ |
|
1191 |
GET_RWNO_TID(, r1); /* R1->SubScheduler */ |
|
1192 |
asm("cmp r1, #0 "); |
|
1193 |
asm("beq rwwuec_ok "); /* Skip checks if subscheduler not yet initialised */ |
|
1194 |
asm("ldrh r2, [r0, #6] "); /* R2[8:15]=holding CPU, R2[0:7]=order */ |
|
1195 |
asm("ldr r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iCpuNum)); |
|
1196 |
asm("eor r2, r2, r3, lsl #8 "); /* R2[8:15]=holding CPU^current CPU, R2[0:7]=order */ |
|
1197 |
asm("tst r2, #0xE0 "); |
|
1198 |
asm("bne rwwuec_preemption "); /* This lock requires preemption to be disabled */ |
|
1199 |
||
1200 |
/* check interrupts disabled */ |
|
1201 |
asm("and r3, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
1202 |
asm("cmp r3, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* Check interrupts masked */ |
|
1203 |
asm("beq rwwuec_1 "); /* Yes - OK */ |
|
1204 |
__ASM_CRASH(); /* No - die */ |
|
1205 |
||
1206 |
asm("rwwuec_preemption: "); |
|
1207 |
asm("and r3, r2, #0xFF "); |
|
1208 |
asm("cmp r3, #0xFF "); /* check for EOrderNone */ |
|
1209 |
asm("ldrne r3, [r1, #%a0]" : : "i" _FOFF(TSubScheduler, iKernLockCount)); |
|
1210 |
asm("beq rwwuec_1 "); /* EOrderNone - don't check interrupts or preemption */ |
|
1211 |
asm("cmp r3, #0 "); |
|
1212 |
asm("bne rwwuec_1 "); /* Preemption disabled - OK */ |
|
1213 |
__ASM_CRASH(); /* Preemption enabled - die */ |
|
1214 |
||
1215 |
asm("rwwuec_1: "); |
|
1216 |
asm("tst r2, #0xFF00 "); /* Check if holding CPU ^ current CPU number == 0 */ |
|
1217 |
asm("beq rwwuec_2 "); /* Held by this CPU - OK */ |
|
1218 |
__ASM_CRASH(); /* Not held by this CPU - die */ |
|
1219 |
||
1220 |
asm("rwwuec_2: "); |
|
1221 |
asm("add r1, r1, #%a0" : : "i" _FOFF(TSubScheduler, iSpinLockOrderCheck)); |
|
1222 |
asm("mov r3, #0xFF "); |
|
1223 |
asm("strb r3, [r0, #7] "); /* reset holding CPU */ |
|
1224 |
asm("cmp r2, #0x40 "); |
|
1225 |
asm("bhs rwwuec_ok "); /* if EOrderNone, done */ |
|
1226 |
asm("cmp r2, #0x20 "); |
|
1227 |
asm("addhs r1, r1, #4 "); |
|
1228 |
asm("and r2, r2, #0x1F "); |
|
1229 |
asm("mov r3, #1 "); |
|
1230 |
asm("mov r3, r3, lsl r2 "); /* r3 = bit to clear */ |
|
1231 |
asm("ldr r2, [r1] "); |
|
1232 |
asm("tst r2, r3 "); /* test bit originally set */ |
|
1233 |
asm("bic r2, r2, r3 "); |
|
1234 |
asm("str r2, [r1] "); /* clear bit in iSpinLockOrderCheck corresponding to lock order */ |
|
1235 |
asm("bne rwwuec_ok "); /* if originally set, OK */ |
|
1236 |
__ASM_CRASH(); /* if not, die - something must have got corrupted */ |
|
1237 |
||
1238 |
asm("rwwuec_ok: "); |
|
1239 |
asm("msr cpsr, r12 "); /* restore interrupts */ |
|
1240 |
asm("ldmfd sp!, {r1,r2,r3,r12} "); |
|
1241 |
__JUMP(,lr); |
|
1242 |
} |
|
1243 |
#endif |
|
1244 |
||
1245 |
||
1246 |
/*----------------------------------------------------------------------------- |
|
1247 |
- Read locks disabling IRQ |
|
1248 |
-----------------------------------------------------------------------------*/ |
|
1249 |
__NAKED__ EXPORT_C void TRWSpinLock::LockIrqR() |
|
1250 |
{ |
|
1251 |
__ASM_CLI(); /* Disable interrupts */ |
|
1252 |
RWSPIN_RLOCK_ENTRY_CHECK() |
|
1253 |
asm("1: "); |
|
1254 |
LDREX(1,0); |
|
1255 |
asm("and r2, r1, #0xFF "); /* R2 = original in.w */ |
|
1256 |
asm("add r1, r1, #0x100 "); /* increment in.r */ |
|
1257 |
asm("tst r1, #0xFF00 "); /* if wraparound ... */ |
|
1258 |
asm("subeq r1, r1, #0x10000 "); /* ... revert carry into out.w */ |
|
1259 |
STREX(3,1,0); |
|
1260 |
asm("cmp r3, #0 "); |
|
1261 |
asm("bne 1b "); |
|
1262 |
asm("3: "); |
|
1263 |
asm("and r1, r1, #0xFF0000 "); /* R1 = out.w << 16 */ |
|
1264 |
asm("cmp r1, r2, lsl #16 "); /* out.w = original in.w ? */ |
|
1265 |
asm("bne 2f "); /* no - must wait */ |
|
1266 |
RWSPIN_RLOCK_MARK_ACQ() |
|
1267 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1268 |
__JUMP(,lr); |
|
1269 |
||
1270 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1271 |
asm("ldr r1, __CrashState "); |
0 | 1272 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1273 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1274 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1275 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1276 |
asm("ldr r1, [r0, #0] "); /* read out.w count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1277 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1278 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1279 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1280 |
} |
1281 |
||
1282 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockIrqR() |
|
1283 |
{ |
|
1284 |
RWSPIN_RUNLOCK_ENTRY_CHECK() |
|
1285 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1286 |
asm("1: "); |
|
1287 |
LDREX(2,0); |
|
1288 |
asm("add r2, r2, #0x01000000 "); /* increment out.r */ |
|
1289 |
STREX(3,2,0); |
|
1290 |
asm("cmp r3, #0 "); |
|
1291 |
asm("bne 1b "); |
|
1292 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.r completes before SEV */ |
|
1293 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1294 |
__ASM_STI(); /* Enable interrupts */ |
|
1295 |
__JUMP(,lr); |
|
1296 |
} |
|
1297 |
||
1298 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashIrqR() |
|
1299 |
{ |
|
1300 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1301 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 1302 |
asm("ldr r2, [r0, #0] "); |
1303 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
1304 |
asm("eor r2, r2, r2, lsr #16 "); /* r2 low byte = out.w ^ in.w = 0 if no writers waiting */ |
|
1305 |
asm("tst r2, #0xFF "); |
|
1306 |
asm("addeq r3, r3, #1 "); |
|
1307 |
asm("cmpeq r3, #1024 "); /* if no writers waiting for lock, check for pending interrupt */ |
|
1308 |
asm("bne 1f "); /* branch if writers waiting or pending interrupt */ |
|
1309 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1310 |
__JUMP(,lr); |
|
1311 |
||
1312 |
asm("1: "); |
|
1313 |
asm("str lr, [sp, #-4]! "); |
|
1314 |
asm("bl " CSM_ZN11TRWSpinLock10UnlockIrqREv); |
|
1315 |
asm("bl " CSM_ZN11TRWSpinLock8LockIrqREv); |
|
1316 |
asm("mov r0, #1 "); |
|
1317 |
asm("ldr pc, [sp], #4 "); |
|
1318 |
} |
|
1319 |
||
1320 |
||
1321 |
/*----------------------------------------------------------------------------- |
|
1322 |
- Write locks disabling IRQ |
|
1323 |
-----------------------------------------------------------------------------*/ |
|
1324 |
__NAKED__ EXPORT_C void TRWSpinLock::LockIrqW() |
|
1325 |
{ |
|
1326 |
__ASM_CLI(); /* Disable interrupts */ |
|
1327 |
RWSPIN_WLOCK_ENTRY_CHECK() |
|
1328 |
asm("1: "); |
|
1329 |
LDREX(1,0); |
|
1330 |
asm("mov r2, r1, lsl #16 "); /* R2 = original in << 16 */ |
|
1331 |
asm("add r1, r1, #1 "); /* increment in.w */ |
|
1332 |
asm("tst r1, #0xFF "); /* if wraparound ... */ |
|
1333 |
asm("subeq r1, r1, #0x100 "); /* ... revert carry into in.r */ |
|
1334 |
STREX(3,1,0); |
|
1335 |
asm("cmp r3, #0 "); |
|
1336 |
asm("bne 1b "); |
|
1337 |
asm("3: "); |
|
1338 |
asm("mov r1, r1, lsr #16 "); /* r1 = out */ |
|
1339 |
asm("cmp r1, r2, lsr #16 "); /* out = original in ? */ |
|
1340 |
asm("bne 2f "); /* no - must wait */ |
|
1341 |
RWSPIN_WLOCK_MARK_ACQ() |
|
1342 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1343 |
__JUMP(,lr); |
|
1344 |
||
1345 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1346 |
asm("ldr r1, __CrashState "); |
0 | 1347 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1348 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1349 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1350 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1351 |
asm("ldr r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1352 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1353 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1354 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1355 |
} |
1356 |
||
1357 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockIrqW() |
|
1358 |
{ |
|
1359 |
RWSPIN_WUNLOCK_ENTRY_CHECK() |
|
1360 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1361 |
asm("ldrb r2, [r0, #2] "); |
|
1362 |
asm("add r2, r2, #1 "); |
|
1363 |
asm("strb r2, [r0, #2] "); /* increment out.w */ |
|
1364 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.w completes before SEV */ |
|
1365 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1366 |
__ASM_STI(); /* Enable interrupts */ |
|
1367 |
__JUMP(,lr); |
|
1368 |
} |
|
1369 |
||
1370 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashIrqW() |
|
1371 |
{ |
|
1372 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1373 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 1374 |
asm("ldr r2, [r0, #0] "); |
1375 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
1376 |
asm("add r2, r2, #0x00010000 "); /* increment out.w */ |
|
1377 |
asm("tst r2, #0x00FF0000 "); /* if wraparound, revert carry */ |
|
1378 |
asm("subeq r2, r2, #0x01000000 "); |
|
1379 |
asm("eor r2, r2, r2, lsl #16 "); /* test if (out.w+1,out.r) == (in.w,in.r) */ |
|
1380 |
asm("cmp r2, #0x00010000 "); |
|
1381 |
asm("bhs 1f "); /* if not, someone else is waiting */ |
|
1382 |
asm("add r3, r3, #1 "); |
|
1383 |
asm("cmp r3, #1024 "); /* if no-one waiting for lock, check for pending interrupt */ |
|
1384 |
asm("bne 1f "); /* branch if pending interrupt */ |
|
1385 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1386 |
__JUMP(,lr); |
|
1387 |
||
1388 |
asm("1: "); |
|
1389 |
asm("str lr, [sp, #-4]! "); |
|
1390 |
asm("bl " CSM_ZN11TRWSpinLock10UnlockIrqWEv); |
|
1391 |
asm("bl " CSM_ZN11TRWSpinLock8LockIrqWEv); |
|
1392 |
asm("mov r0, #1 "); |
|
1393 |
asm("ldr pc, [sp], #4 "); |
|
1394 |
} |
|
1395 |
||
1396 |
||
1397 |
||
1398 |
/*----------------------------------------------------------------------------- |
|
1399 |
- Read locks leaving IRQ alone |
|
1400 |
-----------------------------------------------------------------------------*/ |
|
1401 |
__NAKED__ EXPORT_C void TRWSpinLock::LockOnlyR() |
|
1402 |
{ |
|
1403 |
RWSPIN_RLOCK_ENTRY_CHECK() |
|
1404 |
asm("1: "); |
|
1405 |
LDREX(1,0); |
|
1406 |
asm("and r2, r1, #0xFF "); /* R2 = original in.w */ |
|
1407 |
asm("add r1, r1, #0x100 "); /* increment in.r */ |
|
1408 |
asm("tst r1, #0xFF00 "); /* if wraparound ... */ |
|
1409 |
asm("subeq r1, r1, #0x10000 "); /* ... revert carry into out.w */ |
|
1410 |
STREX(3,1,0); |
|
1411 |
asm("cmp r3, #0 "); |
|
1412 |
asm("bne 1b "); |
|
1413 |
asm("3: "); |
|
1414 |
asm("and r1, r1, #0xFF0000 "); /* R1 = out.w << 16 */ |
|
1415 |
asm("cmp r1, r2, lsl #16 "); /* out.w = original in.w ? */ |
|
1416 |
asm("bne 2f "); /* no - must wait */ |
|
1417 |
RWSPIN_RLOCK_MARK_ACQ() |
|
1418 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1419 |
__JUMP(,lr); |
|
1420 |
||
1421 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1422 |
asm("ldr r1, __CrashState "); |
0 | 1423 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1424 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1425 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1426 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1427 |
asm("ldr r1, [r0, #0] "); /* read out.w count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1428 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1429 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1430 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1431 |
} |
1432 |
||
1433 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockOnlyR() |
|
1434 |
{ |
|
1435 |
RWSPIN_RUNLOCK_ENTRY_CHECK() |
|
1436 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1437 |
asm("1: "); |
|
1438 |
LDREX(2,0); |
|
1439 |
asm("add r2, r2, #0x01000000 "); /* increment out.r */ |
|
1440 |
STREX(3,2,0); |
|
1441 |
asm("cmp r3, #0 "); |
|
1442 |
asm("bne 1b "); |
|
1443 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.r completes before SEV */ |
|
1444 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1445 |
__JUMP(,lr); |
|
1446 |
} |
|
1447 |
||
1448 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashOnlyR() |
|
1449 |
{ |
|
1450 |
asm("ldr r2, [r0, #0] "); |
|
1451 |
asm("eor r2, r2, r2, lsr #16 "); /* r2 low byte = out.w ^ in.w = 0 if no writers waiting */ |
|
1452 |
asm("tst r2, #0xFF "); |
|
1453 |
asm("bne 1f "); /* branch if writers waiting */ |
|
1454 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1455 |
__JUMP(,lr); |
|
1456 |
||
1457 |
asm("1: "); |
|
1458 |
asm("str lr, [sp, #-4]! "); |
|
1459 |
asm("bl " CSM_ZN11TRWSpinLock11UnlockOnlyREv); |
|
1460 |
asm("bl " CSM_ZN11TRWSpinLock9LockOnlyREv); |
|
1461 |
asm("mov r0, #1 "); |
|
1462 |
asm("ldr pc, [sp], #4 "); |
|
1463 |
} |
|
1464 |
||
1465 |
||
1466 |
/*----------------------------------------------------------------------------- |
|
1467 |
- Write locks leaving IRQ alone |
|
1468 |
-----------------------------------------------------------------------------*/ |
|
1469 |
__NAKED__ EXPORT_C void TRWSpinLock::LockOnlyW() |
|
1470 |
{ |
|
1471 |
RWSPIN_WLOCK_ENTRY_CHECK() |
|
1472 |
asm("1: "); |
|
1473 |
LDREX(1,0); |
|
1474 |
asm("mov r2, r1, lsl #16 "); /* R2 = original in << 16 */ |
|
1475 |
asm("add r1, r1, #1 "); /* increment in.w */ |
|
1476 |
asm("tst r1, #0xFF "); /* if wraparound ... */ |
|
1477 |
asm("subeq r1, r1, #0x100 "); /* ... revert carry into in.r */ |
|
1478 |
STREX(3,1,0); |
|
1479 |
asm("cmp r3, #0 "); |
|
1480 |
asm("bne 1b "); |
|
1481 |
asm("3: "); |
|
1482 |
asm("mov r1, r1, lsr #16 "); /* r1 = out */ |
|
1483 |
asm("cmp r1, r2, lsr #16 "); /* out = original in ? */ |
|
1484 |
asm("bne 2f "); /* no - must wait */ |
|
1485 |
RWSPIN_WLOCK_MARK_ACQ() |
|
1486 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1487 |
__JUMP(,lr); |
|
1488 |
||
1489 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1490 |
asm("ldr r1, __CrashState "); |
0 | 1491 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1492 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1493 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1494 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1495 |
asm("ldr r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1496 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1497 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1498 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1499 |
} |
1500 |
||
1501 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockOnlyW() |
|
1502 |
{ |
|
1503 |
RWSPIN_WUNLOCK_ENTRY_CHECK() |
|
1504 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1505 |
asm("ldrb r2, [r0, #2] "); |
|
1506 |
asm("add r2, r2, #1 "); |
|
1507 |
asm("strb r2, [r0, #2] "); /* increment out.w */ |
|
1508 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.w completes before SEV */ |
|
1509 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1510 |
__JUMP(,lr); |
|
1511 |
} |
|
1512 |
||
1513 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashOnlyW() |
|
1514 |
{ |
|
1515 |
asm("ldr r2, [r0, #0] "); |
|
1516 |
asm("add r2, r2, #0x00010000 "); /* increment out.w */ |
|
1517 |
asm("tst r2, #0x00FF0000 "); /* if wraparound, revert carry */ |
|
1518 |
asm("subeq r2, r2, #0x01000000 "); |
|
1519 |
asm("eor r2, r2, r2, lsl #16 "); /* test if (out.w+1,out.r) == (in.w,in.r) */ |
|
1520 |
asm("cmp r2, #0x00010000 "); |
|
1521 |
asm("bhs 1f "); /* if not, someone else is waiting */ |
|
1522 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1523 |
__JUMP(,lr); |
|
1524 |
||
1525 |
asm("1: "); |
|
1526 |
asm("str lr, [sp, #-4]! "); |
|
1527 |
asm("bl " CSM_ZN11TRWSpinLock11UnlockOnlyWEv); |
|
1528 |
asm("bl " CSM_ZN11TRWSpinLock9LockOnlyWEv); |
|
1529 |
asm("mov r0, #1 "); |
|
1530 |
asm("ldr pc, [sp], #4 "); |
|
1531 |
} |
|
1532 |
||
1533 |
||
1534 |
||
1535 |
/*----------------------------------------------------------------------------- |
|
1536 |
- Read locks disabling IRQ with save/restore IRQ state |
|
1537 |
-----------------------------------------------------------------------------*/ |
|
1538 |
__NAKED__ EXPORT_C TInt TRWSpinLock::LockIrqSaveR() |
|
1539 |
{ |
|
1540 |
asm("mrs r12, cpsr "); |
|
1541 |
__ASM_CLI(); /* Disable interrupts */ |
|
1542 |
RWSPIN_RLOCK_ENTRY_CHECK() |
|
1543 |
asm("1: "); |
|
1544 |
LDREX(1,0); |
|
1545 |
asm("and r2, r1, #0xFF "); /* R2 = original in.w */ |
|
1546 |
asm("add r1, r1, #0x100 "); /* increment in.r */ |
|
1547 |
asm("tst r1, #0xFF00 "); /* if wraparound ... */ |
|
1548 |
asm("subeq r1, r1, #0x10000 "); /* ... revert carry into out.w */ |
|
1549 |
STREX(3,1,0); |
|
1550 |
asm("cmp r3, #0 "); |
|
1551 |
asm("bne 1b "); |
|
1552 |
asm("3: "); |
|
1553 |
asm("and r1, r1, #0xFF0000 "); /* R1 = out.w << 16 */ |
|
1554 |
asm("cmp r1, r2, lsl #16 "); /* out.w = original in.w ? */ |
|
1555 |
asm("bne 2f "); /* no - must wait */ |
|
1556 |
RWSPIN_RLOCK_MARK_ACQ() |
|
1557 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1558 |
asm("and r0, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* return original CPSR I and F bits */ |
|
1559 |
__JUMP(,lr); |
|
1560 |
||
1561 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1562 |
asm("ldr r1, __CrashState "); |
0 | 1563 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1564 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1565 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1566 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1567 |
asm("ldr r1, [r0, #0] "); /* read out.w count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1568 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1569 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1570 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1571 |
} |
1572 |
||
1573 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockIrqRestoreR(TInt) |
|
1574 |
{ |
|
1575 |
RWSPIN_RUNLOCK_ENTRY_CHECK() |
|
1576 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1577 |
asm("1: "); |
|
1578 |
LDREX(2,0); |
|
1579 |
asm("add r2, r2, #0x01000000 "); /* increment out.r */ |
|
1580 |
STREX(3,2,0); |
|
1581 |
asm("cmp r3, #0 "); |
|
1582 |
asm("bne 1b "); |
|
1583 |
asm("mrs r12, cpsr "); |
|
1584 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.r completes before SEV */ |
|
1585 |
asm("bic r12, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
1586 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1587 |
asm("orr r1, r1, r12 "); |
|
1588 |
asm("msr cpsr, r1 "); /* restore interrupts */ |
|
1589 |
__JUMP(,lr); |
|
1590 |
} |
|
1591 |
||
1592 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashIrqRestoreR(TInt) |
|
1593 |
{ |
|
1594 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1595 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 1596 |
asm("ldr r2, [r0, #0] "); |
1597 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
1598 |
asm("eor r2, r2, r2, lsr #16 "); /* r2 low byte = out.w ^ in.w = 0 if no writers waiting */ |
|
1599 |
asm("tst r2, #0xFF "); |
|
1600 |
asm("addeq r3, r3, #1 "); |
|
1601 |
asm("cmpeq r3, #1024 "); /* if no writers waiting for lock, check for pending interrupt */ |
|
1602 |
asm("bne 1f "); /* branch if writers waiting or pending interrupt */ |
|
1603 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1604 |
__JUMP(,lr); |
|
1605 |
||
1606 |
asm("1: "); |
|
1607 |
asm("str lr, [sp, #-4]! "); |
|
1608 |
asm("bl " CSM_ZN11TRWSpinLock17UnlockIrqRestoreREi); |
|
1609 |
asm("bl " CSM_ZN11TRWSpinLock8LockIrqREv); |
|
1610 |
asm("mov r0, #1 "); |
|
1611 |
asm("ldr pc, [sp], #4 "); |
|
1612 |
} |
|
1613 |
||
1614 |
||
1615 |
/*----------------------------------------------------------------------------- |
|
1616 |
- Write locks disabling IRQ with save/restore IRQ state |
|
1617 |
-----------------------------------------------------------------------------*/ |
|
1618 |
__NAKED__ EXPORT_C TInt TRWSpinLock::LockIrqSaveW() |
|
1619 |
{ |
|
1620 |
asm("mrs r12, cpsr "); |
|
1621 |
__ASM_CLI(); /* Disable interrupts */ |
|
1622 |
RWSPIN_WLOCK_ENTRY_CHECK() |
|
1623 |
asm("1: "); |
|
1624 |
LDREX(1,0); |
|
1625 |
asm("mov r2, r1, lsl #16 "); /* R2 = original in << 16 */ |
|
1626 |
asm("add r1, r1, #1 "); /* increment in.w */ |
|
1627 |
asm("tst r1, #0xFF "); /* if wraparound ... */ |
|
1628 |
asm("subeq r1, r1, #0x100 "); /* ... revert carry into in.r */ |
|
1629 |
STREX(3,1,0); |
|
1630 |
asm("cmp r3, #0 "); |
|
1631 |
asm("bne 1b "); |
|
1632 |
asm("3: "); |
|
1633 |
asm("mov r1, r1, lsr #16 "); /* r1 = out */ |
|
1634 |
asm("cmp r1, r2, lsr #16 "); /* out = original in ? */ |
|
1635 |
asm("bne 2f "); /* no - must wait */ |
|
1636 |
RWSPIN_WLOCK_MARK_ACQ() |
|
1637 |
__DATA_MEMORY_BARRIER__(r3); /* we have got the lock */ |
|
1638 |
asm("and r0, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); /* return original CPSR I and F bits */ |
|
1639 |
__JUMP(,lr); |
|
1640 |
||
1641 |
asm("2: "); |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1642 |
asm("ldr r1, __CrashState "); |
0 | 1643 |
ARM_WFE; |
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1644 |
asm("ldr r1, [r1] "); /* check for system crash while we were waiting */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1645 |
asm("cmp r1, #0 "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1646 |
asm("bne 9f "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1647 |
asm("ldr r1, [r0, #0] "); /* read out count again */ |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1648 |
asm("b 3b "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1649 |
asm("9: "); |
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1650 |
__ASM_CRASH(); /* system crashed while we were waiting */ |
0 | 1651 |
} |
1652 |
||
1653 |
__NAKED__ EXPORT_C void TRWSpinLock::UnlockIrqRestoreW(TInt) |
|
1654 |
{ |
|
1655 |
RWSPIN_WUNLOCK_ENTRY_CHECK() |
|
1656 |
__DATA_MEMORY_BARRIER_Z__(r3); /* Ensure accesses don't move outside locked section */ |
|
1657 |
asm("ldrb r2, [r0, #2] "); |
|
1658 |
asm("mrs r12, cpsr "); |
|
1659 |
asm("add r2, r2, #1 "); |
|
1660 |
asm("bic r12, r12, #%a0" : : "i" ((TInt)KAllInterruptsMask)); |
|
1661 |
asm("strb r2, [r0, #2] "); /* increment out.w */ |
|
1662 |
__DATA_SYNC_BARRIER__(r3); /* Ensure write to out.w completes before SEV */ |
|
1663 |
ARM_SEV; /* Wake up any waiting processors */ |
|
1664 |
asm("orr r1, r1, r12 "); |
|
1665 |
asm("msr cpsr, r1 "); /* restore interrupts */ |
|
1666 |
__JUMP(,lr); |
|
1667 |
} |
|
1668 |
||
1669 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashIrqRestoreW(TInt) |
|
1670 |
{ |
|
1671 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
43
c1f20ce4abcf
Revision: 201035
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1672 |
asm("ldr r12, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iSSX.iGicCpuIfcAddr)); |
0 | 1673 |
asm("ldr r2, [r0, #0] "); |
1674 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(GicCpuIfc,iHighestPending)); |
|
1675 |
asm("add r2, r2, #0x00010000 "); /* increment out.w */ |
|
1676 |
asm("tst r2, #0x00FF0000 "); /* if wraparound, revert carry */ |
|
1677 |
asm("subeq r2, r2, #0x01000000 "); |
|
1678 |
asm("eor r2, r2, r2, lsl #16 "); /* test if (out.w+1,out.r) == (in.w,in.r) */ |
|
1679 |
asm("cmp r2, #0x00010000 "); |
|
1680 |
asm("bhs 1f "); /* if not, someone else is waiting */ |
|
1681 |
asm("add r3, r3, #1 "); |
|
1682 |
asm("cmp r3, #1024 "); /* if no-one else waiting for lock, check for pending interrupt */ |
|
1683 |
asm("bne 1f "); /* branch if pending interrupt */ |
|
1684 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1685 |
__JUMP(,lr); |
|
1686 |
||
1687 |
asm("1: "); |
|
1688 |
asm("str lr, [sp, #-4]! "); |
|
1689 |
asm("bl " CSM_ZN11TRWSpinLock17UnlockIrqRestoreWEi); |
|
1690 |
asm("bl " CSM_ZN11TRWSpinLock8LockIrqWEv); |
|
1691 |
asm("mov r0, #1 "); |
|
1692 |
asm("ldr pc, [sp], #4 "); |
|
1693 |
} |
|
1694 |
||
1695 |
||
1696 |
/*----------------------------------------------------------------------------- |
|
1697 |
- Read lock flash allowing preemption |
|
1698 |
-----------------------------------------------------------------------------*/ |
|
1699 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashPreemptR() |
|
1700 |
{ |
|
1701 |
asm("ldr r2, [r0, #0] "); |
|
1702 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
1703 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iRescheduleNeededFlag)); |
|
1704 |
asm("eor r2, r2, r2, lsr #16 "); /* r2 low byte = out.w ^ in.w = 0 if no writers waiting */ |
|
1705 |
asm("tst r2, #0xFF "); |
|
1706 |
asm("cmpeq r3, #0 "); /* if no writers waiting, check if reschedule or IDFCs pending */ |
|
1707 |
asm("bne 1f "); /* branch if so or if writers waiting */ |
|
1708 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1709 |
__JUMP(,lr); |
|
1710 |
||
1711 |
asm("1: "); |
|
1712 |
asm("stmfd sp!, {r0,lr} "); |
|
1713 |
asm("bl " CSM_ZN11TRWSpinLock11UnlockOnlyREv); |
|
1714 |
asm("bl " CSM_ZN5NKern15PreemptionPointEv); |
|
1715 |
asm("ldr r0, [sp], #4 "); |
|
1716 |
asm("bl " CSM_ZN11TRWSpinLock9LockOnlyREv); |
|
1717 |
asm("mov r0, #1 "); |
|
1718 |
asm("ldr pc, [sp], #4 "); |
|
1719 |
} |
|
1720 |
||
1721 |
||
1722 |
/*----------------------------------------------------------------------------- |
|
1723 |
- Write lock flash allowing preemption |
|
1724 |
-----------------------------------------------------------------------------*/ |
|
1725 |
__NAKED__ EXPORT_C TBool TRWSpinLock::FlashPreemptW() |
|
1726 |
{ |
|
1727 |
asm("ldr r2, [r0, #0] "); |
|
1728 |
GET_RWNO_TID(,r12); /* r12 -> TSubScheduler */ |
|
1729 |
asm("ldr r3, [r12, #%a0]" : : "i" _FOFF(TSubScheduler,iRescheduleNeededFlag)); |
|
1730 |
asm("add r2, r2, #0x00010000 "); /* increment out.w */ |
|
1731 |
asm("tst r2, #0x00FF0000 "); /* if wraparound, revert carry */ |
|
1732 |
asm("subeq r2, r2, #0x01000000 "); |
|
1733 |
asm("eor r2, r2, r2, lsl #16 "); /* test if (out.w+1,out.r) == (in.w,in.r) */ |
|
1734 |
asm("cmp r2, #0x00010000 "); |
|
1735 |
asm("bhs 1f "); /* if not, someone else is waiting */ |
|
1736 |
asm("cmp r3, #0 "); /* no-one else waiting, check if reschedule or IDFCs pending */ |
|
1737 |
asm("bne 1f "); /* if so, branch to release lock */ |
|
1738 |
asm("mov r0, #0 "); /* else return FALSE */ |
|
1739 |
__JUMP(,lr); |
|
1740 |
||
1741 |
asm("1: "); |
|
1742 |
asm("stmfd sp!, {r0,lr} "); |
|
1743 |
asm("bl " CSM_ZN11TRWSpinLock11UnlockOnlyWEv); |
|
1744 |
asm("bl " CSM_ZN5NKern15PreemptionPointEv); |
|
1745 |
asm("ldr r0, [sp], #4 "); |
|
1746 |
asm("bl " CSM_ZN11TRWSpinLock9LockOnlyWEv); |
|
1747 |
asm("mov r0, #1 "); |
|
1748 |
asm("ldr pc, [sp], #4 "); |
|
1749 |
} |
|
1750 |